From 1a6a253e85e609d37113585081b6cf9711757208 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 18 Feb 2016 08:35:22 +0100 Subject: [features,loaders] allow for direct injection of tfmdata when defining fonts --- src/luaotfload-loaders.lua | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'src/luaotfload-loaders.lua') diff --git a/src/luaotfload-loaders.lua b/src/luaotfload-loaders.lua index 0f22f46..8e5248b 100644 --- a/src/luaotfload-loaders.lua +++ b/src/luaotfload-loaders.lua @@ -14,13 +14,43 @@ if not luaotfload then error "this module requires Luaotfload" end local logreport = luaotfload.log and luaotfload.log.report or print +local lua_reader = function (specification) + local fullname = specification.filename or "" + if fullname == "" then + local forced = specification.forced or "" + if forced ~= "" then + fullname = specification.name .. "." .. forced + else + fullname = specification.name + end + end + local fullname = resolvers.findfile (fullname) or "" + if fullname ~= "" then + local loader = loadfile (fullname) + loader = loader and loader () + return loader and loader (specification) + end +end + +local data_reader = function (specification) + local data = specification.data + if data and type (data) == "function" then + logreport ("both", 0, "loaders", + "data: found tfmdata for ā€œ%sā€, injecting.", + specification.name) + return data () + end +end + local install_formats = function () local fonts = fonts if not fonts then return false end - local readers = fonts.readers - local handlers = fonts.handlers - local formats = fonts.formats + local readers = fonts.readers + local sequence = readers.sequence + local seqset = table.tohash (sequence) + local handlers = fonts.handlers + local formats = fonts.formats if not readers or not handlers or not formats then return false end local aux = function (which, reader) @@ -32,10 +62,18 @@ local install_formats = function () formats [which] = "type1" readers [which] = reader handlers [which] = { } + if not seqset [which] then + logreport ("both", 0, "loaders", + "Extending reader sequence for ā€œ%sā€.", which) + sequence [#sequence + 1] = which + seqset [which] = true + end return true end - return aux ("pfa", function (spec) return readers.opentype (spec, "pfa", "type1") end) + return aux ("dat", data_reader) + and aux ("lua", lua_reader) + and aux ("pfa", function (spec) return readers.opentype (spec, "pfa", "type1") end) and aux ("pfb", function (spec) return readers.opentype (spec, "pfb", "type1") end) and aux ("ofm", readers.tfm) end -- cgit v1.2.3