summaryrefslogtreecommitdiff
path: root/luaotfload-deferred.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <megas.kapaneus@gmail.com>2013-04-10 12:01:43 +0200
committerPhilipp Gesang <megas.kapaneus@gmail.com>2013-04-10 12:01:43 +0200
commit82141b63af85b266f0304db468dc60f3d18a4793 (patch)
tree3ace23d66aa776dde692378141cee54beeb0dbb7 /luaotfload-deferred.lua
parent422263516bb273977c8dbc9a038868d6a0f8a6de (diff)
downloadluaotfload-82141b63af85b266f0304db468dc60f3d18a4793.tar.gz
make font definition callback wrapper work with current tfm object structure
Diffstat (limited to 'luaotfload-deferred.lua')
-rw-r--r--luaotfload-deferred.lua147
1 files changed, 87 insertions, 60 deletions
diff --git a/luaotfload-deferred.lua b/luaotfload-deferred.lua
index a3026c9..bfbf644 100644
--- a/luaotfload-deferred.lua
+++ b/luaotfload-deferred.lua
@@ -1,6 +1,33 @@
--- TODO integrate into luaotfload.dtx
+
+local type, next = type, next
+
+local stringfind = string.find
--- this part is loaded after luatexbase
-local loadmodule = luaotfload.loadmodule
+local loadmodule = luaotfload.loadmodule
+local luatexbase = luatexbase
+local generic_context = generic_context --- from fontloader
+
+local add_to_callback, create_callback =
+ luatexbase.add_to_callback, luatexbase.create_callback
+local reset_callback, call_callback =
+ luatexbase.reset_callback, luatexbase.call_callback
+
+--[[doc--
+We do our own callback handling with the means provided by luatexbase.
+
+Note: \verb|pre_linebreak_filter| and \verb|hpack_filter| are coupled
+in \CONTEXT\ in the concept of \emph{node processor}.
+--doc]]--
+
+add_to_callback("pre_linebreak_filter",
+ generic_context.callback_pre_linebreak_filter,
+ "luaotfload.node_processor",
+ 1)
+add_to_callback("hpack_filter",
+ generic_context.callback_hpack_filter,
+ "luaotfload.node_processor",
+ 1)
loadmodule("lib-dir.lua") -- required by font-nms; will change with lualibs update
loadmodule("font-nms.lua")
@@ -8,31 +35,55 @@ loadmodule("font-clr.lua")
--loadmodule("font-ovr.lua")
loadmodule("font-ltx.lua")
-luatexbase.create_callback("luaotfload.patch_font", "simple", function() end)
+local dummy_function = function ( ) end --- upvalue more efficient than lambda
+create_callback("luaotfload.patch_font", "simple", dummy_function)
-local function def_font(...)
- local fontdata = fonts.define.read(...)
- if type(fontdata) == "table" and fontdata.shared then
- local otfdata = fontdata.shared.otfdata
- if otfdata.metadata.math then
- local mc = { }
- for k,v in next, otfdata.metadata.math do
- if k:find("Percent") then
+--[[doc--
+This is a wrapper for the imported font loader.
+As of 2013, everything it does appears to be redundand, so we won’t use
+it.
+Nevertheless, it has been adapted to work with the current structure of
+font data objects and will stay here for reference / until somebody
+reports breakage.
+
+TODO
+This one also enables patching fonts.
+The current fontloader apparently comes with a dedicated mechanism for
+that already: enhancers.
+How those work remains to be figured out.
+--doc]]--
+local define_font_wrapper = function (...)
+ --- we use “tfmdata” (not “fontdata”) for consistency with the
+ --- font loader
+ local tfmdata = fonts.definers.read(...)
+ if type(tfmdata) == "table" and tfmdata.shared then
+ local metadata = tfmdata.shared.rawdata.metadata
+ local mathdata = metadata.math --- do all fonts have this field?
+ if mathdata then
+ local mathconstants = { } --- why new hash, not modify in place?
+ local units_per_em = metadata.units_per_em
+ local size = tfmdata.size
+ for k,v in next, mathdata do
+ --- afaics this is alread taken care of by
+ --- definers.read
+ if stringfind(k, "Percent") then
-- keep percent values as is
- mc[k] = v
+ print(k,v)
+ mathconstants[k] = v
else
- mc[k] = v / fontdata.units * fontdata.size
+ mathconstants[k] = v / units_per_em * size
end
end
- -- for \overwithdelims
- mc.FractionDelimiterSize = 1.01 * fontdata.size
- mc.FractionDelimiterDisplayStyleSize = 2.39 * fontdata.size
-
- fontdata.MathConstants = mc
+ --- for \overwithdelims
+ --- done by definers.read as well
+ mathconstants.FractionDelimiterSize = 1.01 * size
+ --- fontloader has 2.4 × size
+ mathconstants.FractionDelimiterDisplayStyleSize = 2.39 * size
+ tfmdata.MathConstants = mathconstants
end
- luatexbase.call_callback("luaotfload.patch_font", fontdata)
+ call_callback("luaotfload.patch_font", tfmdata)
end
- return fontdata
+ return tfmdata
end
fonts.mode = "node"
@@ -45,35 +96,21 @@ function attributes.private(name)
return number
end
---luaotfload.loadmodule("font-otc.lua") -- broken
+reset_callback("define_font")
---luatexbase.create_callback("luaotfload.patch_font", "simple", function() end)
-
---local function def_font(...)
- --local fontdata = fonts.define.read(...)
- --if type(fontdata) == "table" and fontdata.shared then
- --local otfdata = fontdata.shared.otfdata
- --if otfdata.metadata.math then
- --local mc = { }
- --for k,v in next, otfdata.metadata.math do
- --if k:find("Percent") then
- ---- keep percent values as is
- --mc[k] = v
- --else
- --mc[k] = v / fontdata.units * fontdata.size
- --end
- --end
- ---- for \overwithdelims
- --mc.FractionDelimiterSize = 1.01 * fontdata.size
- --mc.FractionDelimiterDisplayStyleSize = 2.39 * fontdata.size
-
- --fontdata.MathConstants = mc
- --end
- --luatexbase.call_callback("luaotfload.patch_font", fontdata)
- --end
- --return fontdata
---end
---fonts.mode = "node"
+if luaotfload.old_font_definer then
+ add_to_callback("define_font",
+ old_define_font_wrapper,
+ "luaotfload.define_font",
+ 1)
+else -- use default font loader
+ add_to_callback("define_font",
+ generic_context.callback_define_font,
+ "luaotfload.define_font",
+ 1)
+end
+
+--luaotfload.loadmodule("font-otc.lua") -- broken
--local register_base_sub = fonts.otf.features.register_base_substitution
--local gsubs = {
@@ -86,19 +123,9 @@ end
--for _,v in next, gsubs do
--register_base_sub(v)
--end
---luatexbase.add_to_callback("pre_linebreak_filter",
- --nodes.simple_font_handler,
- --"luaotfload.pre_linebreak_filter")
---luatexbase.add_to_callback("hpack_filter",
- --nodes.simple_font_handler,
- --"luaotfload.hpack_filter")
---luatexbase.reset_callback("define_font")
---luatexbase.add_to_callback("define_font",
- --def_font,
- --"luaotfload.define_font", 1)
---luatexbase.add_to_callback("find_vf_file",
- --fonts.vf.find,
- --"luaotfload.find_vf_file")
+--add_to_callback("find_vf_file",
+ --fonts.vf.find,
+ --"luaotfload.find_vf_file")
--local function set_sscale_diments(fontdata)
--local mc = fontdata.MathConstants
--if mc then