diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2015-12-23 07:50:47 +0100 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2015-12-23 07:52:14 +0100 |
commit | d99f5611eb09923ce4107b64e50c9826aa4601b1 (patch) | |
tree | 76e788dc318a3be57acbc363cfa024a9f2790381 | |
parent | 34a02eaaaf87f6608fc7cb13d60f1217f36f6502 (diff) | |
download | luaotfload-d99f5611eb09923ce4107b64e50c9826aa4601b1.tar.gz |
[auxiliary] move callback handling to initialization
-rw-r--r-- | src/luaotfload-auxiliary.lua | 81 | ||||
-rw-r--r-- | src/luaotfload-main.lua | 2 |
2 files changed, 59 insertions, 24 deletions
diff --git a/src/luaotfload-auxiliary.lua b/src/luaotfload-auxiliary.lua index 11d3101..8292ddd 100644 --- a/src/luaotfload-auxiliary.lua +++ b/src/luaotfload-auxiliary.lua @@ -10,10 +10,7 @@ --- this file addresses issue #24 --- https://github.com/lualatex/luaotfload/issues/24# -luaotfload = luaotfload or {} -luaotfload.aux = luaotfload.aux or { } - -local aux = luaotfload.aux +luaotfload = luaotfload or { } local log = luaotfload.log local logreport = log.report local fonthashes = fonts.hashes @@ -35,6 +32,9 @@ local stringbyte = string.byte local stringfind = string.find local tablecopy = table.copy +local aux = { } +local luaotfload_callbacks = { } + ----------------------------------------------------------------------- --- font patches ----------------------------------------------------------------------- @@ -89,10 +89,9 @@ local set_sscale_dimens = function (fontdata) return fontdata end -luatexbase.add_to_callback( - "luaotfload.patch_font", - set_sscale_dimens, - "luaotfload.aux.set_sscale_dimens") +luaotfload_callbacks [#luaotfload_callbacks + 1] = { + "patch_font", set_sscale_dimens, "set_sscale_dimens", +} --- fontobj -> int local lookup_units = function (fontdata) @@ -124,11 +123,10 @@ local patch_cambria_domh = function (fontdata) end end -luatexbase.add_to_callback( - "luaotfload.patch_font", - patch_cambria_domh, - "luaotfload.aux.patch_cambria_domh") - +luaotfload_callbacks [#luaotfload_callbacks + 1] = { + "patch_font", patch_cambria_domh, "patch_cambria_domh", +} + --[[doc-- @@ -152,11 +150,10 @@ local fixup_fontdata = function (data) end -luatexbase.add_to_callback( - "luaotfload.patch_font_unsafe", - fixup_fontdata, - "luaotfload.aux.fixup_fontdata") - +luaotfload_callbacks [#luaotfload_callbacks + 1] = { + "patch_font_unsafe", fixup_fontdata, "fixup_fontdata", +} + --[[doc-- @@ -204,10 +201,9 @@ local set_capheight = function (fontdata) end end -luatexbase.add_to_callback( - "luaotfload.patch_font", - set_capheight, - "luaotfload.aux.set_capheight") +luaotfload_callbacks [#luaotfload_callbacks + 1] = { + "patch_font", set_capheight, "set_capheight", +} ----------------------------------------------------------------------- --- glyphs and characters @@ -843,4 +839,43 @@ end aux.get_quad = get_quad --- vim:tw=71:sw=2:ts=2:expandtab + +----------------------------------------------------------------------- +--- initialization +----------------------------------------------------------------------- + +local inject_callbacks = function (lst) + if not lst and next (lst) then return false end + + local inject = function (def) + local cb, fn, id = unpack (def) + cb = tostring (cb) + id = tostring (id) + if not cb or not fn or not id or not type (fn) == "function" then + logreport ("both", 0, "aux", "Invalid callback requested (%q, %s, %q).", + cb, tostring (fn), id) + return false + end + cb = stringformat ("luaotfload.%s", cb) + id = stringformat ("luaotfload.aux.%s", id) + logreport ("log", 5, "aux", "Installing callback %q->%q.", cb, id) + luatexbase.add_to_callback (cb, fn, id) + return true + end + + local ret = true + for i = 1, #lst do ret = inject (lst [i]) end + return ret +end + +return { + init = function () + local ret = true + luaotfload.aux = aux + ret = inject_callbacks (luaotfload_callbacks) + return ret + end +} + +-- vim:tw=79:sw=2:ts=8:et + diff --git a/src/luaotfload-main.lua b/src/luaotfload-main.lua index 9525ca4..c843f26 100644 --- a/src/luaotfload-main.lua +++ b/src/luaotfload-main.lua @@ -254,7 +254,7 @@ luaotfload.main = function () initialize "features" --- font request and feature handling loadmodule "letterspace" --- extra character kerning - loadmodule "auxiliary" --- additional high-level functionality + initialize "auxiliary" --- additional high-level functionality luaotfload.aux.start_rewrite_fontname () --- to be migrated to fontspec |