summaryrefslogtreecommitdiff
path: root/src/luaotfload-loaders.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2016-02-18 08:35:22 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2016-02-18 08:35:30 +0100
commit1a6a253e85e609d37113585081b6cf9711757208 (patch)
tree836c3da8cdb9c2ce84c3f3950e06e629810225d9 /src/luaotfload-loaders.lua
parentde3abd3209745257c1fbb7bf08be6b189d5e3cdd (diff)
downloadluaotfload-1a6a253e85e609d37113585081b6cf9711757208.tar.gz
[features,loaders] allow for direct injection of tfmdata when defining fonts
Diffstat (limited to 'src/luaotfload-loaders.lua')
-rw-r--r--src/luaotfload-loaders.lua46
1 files changed, 42 insertions, 4 deletions
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