From 1e3f80d13d7bd10e4f3d62848b2df6a340f83fd4 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 9 Apr 2013 13:42:32 +0200 Subject: preliminarily add luaotfload.lua, luaotfload-deferred.lua (move to dtx later) --- luaotfload.lua | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 luaotfload.lua (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua new file mode 100644 index 0000000..f397633 --- /dev/null +++ b/luaotfload.lua @@ -0,0 +1,105 @@ +-- +-- This is file `luaotfload.lua', +-- generated with the docstrip utility. +-- +-- The original source files were: +-- +-- luaotfload.dtx (with options: `lua') +-- This is a generated file. +-- +-- Copyright (C) 2009-2010 by by Elie Roux +-- and Khaled Hosny +-- (Support: .) +-- +-- This work is under the CC0 license. +-- +-- This work consists of the main source file luaotfload.dtx +-- and the derived files +-- luaotfload.sty, luaotfload.lua +-- +module("luaotfload", package.seeall) + +luaotfload.module = { + name = "luaotfload", + version = 1.27, + date = "2012/05/28", + description = "OpenType layout system.", + author = "Elie Roux & Hans Hagen", + copyright = "Elie Roux", + license = "CC0" +} + +--- these will be overloaded later by luatexbase +local error = function(...) print("err", string.format(...)) end +local log = function(...) print("log", string.format(...)) end + +kpse.init_prog("", 600, "/") +local luatex_version = 60 + +if tex.luatexversion < luatex_version then + warning("LuaTeX v%.2f is old, v%.2f is recommended.", + tex.luatexversion/100, + luatex_version /100) +end +function luaotfload.loadmodule(name, prefix) + local prefix = prefix or "otfl" + local tofind = prefix .."-"..name + local found = kpse.find_file(tofind,"tex") + if found then + log("loading file %s.", found) + dofile(found) + else + --error("file %s not found.", tofind) + error("file %s not found.", tofind) + end +end + +--[[-- keep --]] +--- from Hans (all merged): + +--- file name modified include name +--- × basics-gen.lua t luat-basics-gen +--- × font-def -> fonts-def t luatex-font-def (there’s also the normal font-def!) +--- × fonts-enc f luatex-font-enc +--- × fonts-ext t luatex-fonts-ext +--- × fonts-lua f luatex-fonts-lua +--- fonts-tfm f luatex-fonts-tfm +--- × fonts-cbk f luatex-fonts-lua + +--- from luaotfload: +--- otfl-luat-ovr.lua -- override some luat-dum functions +--- otfl-font-clr.lua +--- otfl-font-ltx.lua +--- otfl-font-nms.lua +--- otfl-font-otc.lua +--- otfl-font-pfb.lua -- ? + +--[[-- new --]] +--- basics-nod (merged as fonts-nod !) +--- fonts-demo-vf-1.lua +--- fonts-syn (merged) + +--[[-- merged, to be dropped --]] +--- otfl-data-con.lua +--- otfl-font-cid.lua +--- otfl-font-con.lua +--- otfl-font-ini.lua +--- otfl-font-ota.lua +--- otfl-font-otb.lua +--- otfl-font-otf.lua +--- otfl-font-oti.lua +--- otfl-font-otn.lua + +--[[-- + it all boils down to this: we load otfl-fonts.lua + which takes care loading the merged file. + that’s it, go thank Hans! +--]]-- + +--luaotfload.loadmodule("fonts.lua", "luatex") +luaotfload.loadmodule("fonts.lua") + +--- now load luatexbase (from the TEX end) +--- then continue in luaotfload-deferred.lua + +-- End of File `luaotfload.lua'. -- cgit v1.2.3 From b4e51c838713797b8a1fbaffc6f104d7fc55bf40 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 9 Apr 2013 23:53:03 +0200 Subject: new font loader initialization code (thanks Hans) --- luaotfload.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index f397633..a73847c 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -92,11 +92,16 @@ end --[[-- it all boils down to this: we load otfl-fonts.lua - which takes care loading the merged file. + which takes care of loading the merged file. that’s it, go thank Hans! --]]-- ---luaotfload.loadmodule("fonts.lua", "luatex") +_G.non_generic_context = { luatex_fonts = { + load_before = "otfl-fonts-merged.lua", + -- load_after = nil, --- TODO, this is meant for callbacks + skip_loading = true, +}} + luaotfload.loadmodule("fonts.lua") --- now load luatexbase (from the TEX end) -- cgit v1.2.3 From 422263516bb273977c8dbc9a038868d6a0f8a6de Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 10 Apr 2013 10:41:12 +0200 Subject: description of loading procedure --- luaotfload.lua | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index a73847c..5550c79 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -29,6 +29,8 @@ luaotfload.module = { license = "CC0" } +local fl_prefix = "otfl" -- “luatex” for luatex-plain + --- these will be overloaded later by luatexbase local error = function(...) print("err", string.format(...)) end local log = function(...) print("log", string.format(...)) end @@ -41,9 +43,8 @@ if tex.luatexversion < luatex_version then tex.luatexversion/100, luatex_version /100) end -function luaotfload.loadmodule(name, prefix) - local prefix = prefix or "otfl" - local tofind = prefix .."-"..name +local loadmodule = function (name) + local tofind = fl_prefix .."-"..name local found = kpse.find_file(tofind,"tex") if found then log("loading file %s.", found) @@ -53,6 +54,7 @@ function luaotfload.loadmodule(name, prefix) error("file %s not found.", tofind) end end +luaotfload.loadmodule = loadmodule --- required in deferred code --[[-- keep --]] --- from Hans (all merged): @@ -96,15 +98,56 @@ end that’s it, go thank Hans! --]]-- +--[[doc +We treat the fontloader as a black box so behavior is consistent +between formats. +The wrapper file is |otfl-fonts.lua| which we imported from +\LUATEX-Plain. +It has roughly two purposes: +(\textit{1}) insert the functionality required for fontloader, and +(\textit{2}) put it in place via the respective callbacks. +How the first step is executed depends on the presence on the +\emph{merged font loader code}. +In \textsf{luaotfload} this is contained in the file +|otfl-fonts-merged.lua|. +If this file cannot be found, the original libraries from \CONTEXT of +which the merged code was composed are loaded instead. + +Hans provides two global tables to control the font loader: +\begin{tabular}{ll} + \texttt{generic\textunderscore context} & + encapsulation mechanism, callback functions + \\ + \texttt{non\textunderscore generic\textunderscore context} & + customized code insertion + \\ +\end{tabular} +With \verb|non_generic_context| we can tailor the font loader insertion +to our file naming habits (key \verb|load_before|). +Additionally, \verb|skip_loading| can be unset to force loading of +the original libraries as though the merged code was absent. +Another key, \verb|load_after| is called at the time when the font +loader is actually inserted. +In combination with the option \verb|no_callbacks_yet| in +\verb|generic_context|, we can insert our own, +\textsf{luatexbase}-style callback handling here. +--doc]]-- +if not _G. generic_context then _G. generic_context = { } end +if not _G.non_generic_context then _G.non_generic_context = { } end + +generic_context.no_callbacks_yet = true + _G.non_generic_context = { luatex_fonts = { load_before = "otfl-fonts-merged.lua", -- load_after = nil, --- TODO, this is meant for callbacks skip_loading = true, }} -luaotfload.loadmodule("fonts.lua") +loadmodule("fonts.lua") --- now load luatexbase (from the TEX end) --- then continue in luaotfload-deferred.lua +-- vim:tw=71:sw=2:ts=2:expandtab + -- End of File `luaotfload.lua'. -- cgit v1.2.3 From 82141b63af85b266f0304db468dc60f3d18a4793 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 10 Apr 2013 12:01:43 +0200 Subject: make font definition callback wrapper work with current tfm object structure --- luaotfload.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index 5550c79..1bfca79 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -29,9 +29,11 @@ luaotfload.module = { license = "CC0" } +luaotfload.old_font_definer = false --- toggle wrapper for font loader + local fl_prefix = "otfl" -- “luatex” for luatex-plain ---- these will be overloaded later by luatexbase +--- these will be provided by luatexbase some time local error = function(...) print("err", string.format(...)) end local log = function(...) print("log", string.format(...)) end @@ -98,7 +100,7 @@ luaotfload.loadmodule = loadmodule --- required in deferred code that’s it, go thank Hans! --]]-- ---[[doc +--[[doc-- We treat the fontloader as a black box so behavior is consistent between formats. The wrapper file is |otfl-fonts.lua| which we imported from @@ -145,7 +147,6 @@ _G.non_generic_context = { luatex_fonts = { loadmodule("fonts.lua") ---- now load luatexbase (from the TEX end) --- then continue in luaotfload-deferred.lua -- vim:tw=71:sw=2:ts=2:expandtab -- cgit v1.2.3 From 223c4fbc3201ce3bd6e5e7ab4ba666e350d97f35 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 10 Apr 2013 12:28:36 +0200 Subject: make font patching work again with font definition wrapper --- luaotfload.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index 1bfca79..0a3b398 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -29,7 +29,14 @@ luaotfload.module = { license = "CC0" } -luaotfload.old_font_definer = false --- toggle wrapper for font loader +--[[doc-- +No final decision has been made on how to handle font definition. +At the moment, there are three candidates: The \textsf{generic} +callback as hard-coded in the font loader, the \textsf{old} wrapper, +and a simplified version of the latter (\textsf{patch}) that does +nothing besides applying font patches. +--doc]]-- +luaotfload.font_definer = "patch" --- | “generic” | “old” local fl_prefix = "otfl" -- “luatex” for luatex-plain -- cgit v1.2.3 From b1db13ab10112f6d81522a3f0ab44a67754cf551 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 10 Apr 2013 16:20:41 +0200 Subject: circumvent the callback trap from luatexbase --- luaotfload.lua | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index 0a3b398..dd650fd 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -65,24 +65,35 @@ local loadmodule = function (name) end luaotfload.loadmodule = loadmodule --- required in deferred code +--[[doc-- +The imported font loader will call \verb|callback.register| once +(during \verb|font-def.lua|). +This is unavoidable but harmless, so we make it call a dummy instead. +--doc]]-- +local trapped_register = callback.register +local dummy_function = function () end +callback.register = dummy_function + --[[-- keep --]] --- from Hans (all merged): ---- file name modified include name ---- × basics-gen.lua t luat-basics-gen ---- × font-def -> fonts-def t luatex-font-def (there’s also the normal font-def!) ---- × fonts-enc f luatex-font-enc ---- × fonts-ext t luatex-fonts-ext ---- × fonts-lua f luatex-fonts-lua ---- fonts-tfm f luatex-fonts-tfm ---- × fonts-cbk f luatex-fonts-lua +--- file name modified include name +--- × basics-gen.lua t luat-basics-gen +--- × font-def -> fonts-def t luatex-font-def (there’s also the normal font-def!) +--- × fonts-enc f luatex-font-enc +--- × fonts-ext t luatex-fonts-ext +--- × fonts-lua f luatex-fonts-lua +--- fonts-tfm f luatex-fonts-tfm +--- × fonts-cbk f luatex-fonts-lua + +--- from Hans (unmerged): +--- font-otc.lua -> otfl-font-otc.lua --- from luaotfload: --- otfl-luat-ovr.lua -- override some luat-dum functions --- otfl-font-clr.lua --- otfl-font-ltx.lua --- otfl-font-nms.lua ---- otfl-font-otc.lua --- otfl-font-pfb.lua -- ? --[[-- new --]] @@ -154,6 +165,13 @@ _G.non_generic_context = { luatex_fonts = { loadmodule("fonts.lua") +--[[doc-- +After the fontloader is ready we can restore the callback trap from +\textsf{luatexbase}. +--doc]]-- + +callback.register = trapped_register + --- then continue in luaotfload-deferred.lua -- vim:tw=71:sw=2:ts=2:expandtab -- cgit v1.2.3 From 45527a77a2250494c7beecfb687d530b62281ba6 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 10 Apr 2013 17:01:54 +0200 Subject: merge deferred functionality back into luaotfload.lua --- luaotfload.lua | 228 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 216 insertions(+), 12 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index dd650fd..7266e47 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -29,6 +29,11 @@ luaotfload.module = { license = "CC0" } +local luatexbase = luatexbase + +local type, next = type, next +local stringfind = string.find + --[[doc-- No final decision has been made on how to handle font definition. At the moment, there are three candidates: The \textsf{generic} @@ -63,16 +68,6 @@ local loadmodule = function (name) error("file %s not found.", tofind) end end -luaotfload.loadmodule = loadmodule --- required in deferred code - ---[[doc-- -The imported font loader will call \verb|callback.register| once -(during \verb|font-def.lua|). -This is unavoidable but harmless, so we make it call a dummy instead. ---doc]]-- -local trapped_register = callback.register -local dummy_function = function () end -callback.register = dummy_function --[[-- keep --]] --- from Hans (all merged): @@ -155,6 +150,9 @@ In combination with the option \verb|no_callbacks_yet| in if not _G. generic_context then _G. generic_context = { } end if not _G.non_generic_context then _G.non_generic_context = { } end +local generic_context = generic_context +local non_generic_context =non_generic_context + generic_context.no_callbacks_yet = true _G.non_generic_context = { luatex_fonts = { @@ -163,7 +161,19 @@ _G.non_generic_context = { luatex_fonts = { skip_loading = true, }} -loadmodule("fonts.lua") +--[[doc-- +The imported font loader will call \verb|callback.register| once +(during \verb|font-def.lua|). +This is unavoidable but harmless, so we make it call a dummy instead. +--doc]]-- +local trapped_register = callback.register +local dummy_function = function () end +callback.register = dummy_function + +--[[doc-- +Now that things are sorted out we can load the fontloader. +--doc]]-- +loadmodule"fonts.lua" --[[doc-- After the fontloader is ready we can restore the callback trap from @@ -172,7 +182,201 @@ After the fontloader is ready we can restore the callback trap from callback.register = trapped_register ---- then continue in luaotfload-deferred.lua +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"font-otc.lua" + +loadmodule"lib-dir.lua" -- required by font-nms; will change with lualibs update +loadmodule"font-nms.lua" +loadmodule"font-clr.lua" +--loadmodule"font-ovr.lua" +loadmodule"font-ltx.lua" + +local dummy_function = function ( ) end --- upvalue more efficient than lambda +create_callback("luaotfload.patch_font", "simple", dummy_function) + +--[[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 + print(k,v) + mathconstants[k] = v + else + mathconstants[k] = v / units_per_em * size + end + end + --- 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 + call_callback("luaotfload.patch_font", tfmdata) + end + return tfmdata +end + +--[[doc-- +We provide a simplified version of the original font definition +callback. +--doc]]-- +local patch_defined_font = function (...) + local tfmdata = fonts.definers.read(...) + if type(tfmdata) == "table" and tfmdata.shared then + call_callback("luaotfload.patch_font", tfmdata) + end + --inspect(tfmdata.shared.features) + return tfmdata +end + +fonts.mode = "node" + +function attributes.private(name) + local attr = "otfl@" .. name + local number = luatexbase.attributes[attr] + if not number then + number = luatexbase.new_attribute(attr) + end + return number +end + +reset_callback("define_font") + +if luaotfload.font_definer == "old" then + add_to_callback("define_font", + old_define_font_wrapper, + "luaotfload.define_font", + 1) +elseif luaotfload.font_definer == "generic" then + add_to_callback("define_font", + generic_context.callback_define_font, + "luaotfload.define_font", + 1) +elseif luaotfload.font_definer == "patch" then + add_to_callback("define_font", + patch_defined_font, + "luaotfload.define_font", + 1) +end + +--[[doc-- +These vanished in 2011. +\url{http://repo.or.cz/w/context.git/commitdiff/1455dd60b68c9140db1b9977c9e5ce372b772ec8} + +The “ss” stuff is in tables.features in context (see font-ott.lua), but +commented. +I’ll get back at restoring it as soon as someone can tell me what those do. +/phg + +local register_base_sub = fonts.otf.features.register_base_substitution +local gsubs = { + "ss01", "ss02", "ss03", "ss04", "ss05", + "ss06", "ss07", "ss08", "ss09", "ss10", + "ss11", "ss12", "ss13", "ss14", "ss15", + "ss16", "ss17", "ss18", "ss19", "ss20", +} + +for _,v in next, gsubs do + register_base_sub(v) +end +--doc]]-- + +---TODO check for conflicts with lualibs +-- imported from "util-sto.lua" +--table.setmetatablenewindex = function (t,f) +-- if type(t) ~= "table" then +-- f, t = t, { } +-- end +-- local m = getmetatable(t) +-- if m then +-- if f == "ignore" then +-- m.__newindex = f_ignore +-- else +-- m.__newindex = f +-- end +-- else +-- if f == "ignore" then +-- setmetatable(t, t_ignore) +-- else +-- setmetatable(t,{ __newindex = f }) +-- end +-- end +-- return t +--end +---- this overloads fonts.handlers.features.normalize() +---- breakage ahead. +--loadmodule"font-ott.lua" + +--add_to_callback("find_vf_file", +-- fonts.vf.find, +-- "luaotfload.find_vf_file") + +local set_sscale_diments = function (tfmdata) + local mathconstants = tfmdata.MathConstants + if mathconstants then + local tfmparameters = tfmdata.parameters + if mathconstants.ScriptPercentScaleDown then + tfmparameters[10] = mathconstants.ScriptPercentScaleDown + else -- resort to plain TeX default + tfmparameters[10] = 70 + end + if mathconstants.ScriptScriptPercentScaleDown then + tfmparameters[11] = mathconstants.ScriptScriptPercentScaleDown + else -- resort to plain TeX default + tfmparameters[11] = 50 + end + end +end + +add_to_callback("luaotfload.patch_font", + set_sscale_diments, + "unicodemath.set_sscale_diments") -- vim:tw=71:sw=2:ts=2:expandtab -- cgit v1.2.3 From a9b52bd969d9285b9d74a80399a133b0c3f92739 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 10 Apr 2013 17:36:40 +0200 Subject: integrate changes from master; add otfl-features.lua --- luaotfload.lua | 69 +++++++++------------------------------------------------- 1 file changed, 10 insertions(+), 59 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index 7266e47..0fba16e 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -31,7 +31,7 @@ luaotfload.module = { local luatexbase = luatexbase -local type, next = type, next +local type, next, dofile = type, next, dofile local stringfind = string.find --[[doc-- @@ -45,12 +45,9 @@ luaotfload.font_definer = "patch" --- | “generic” | “old” local fl_prefix = "otfl" -- “luatex” for luatex-plain ---- these will be provided by luatexbase some time -local error = function(...) print("err", string.format(...)) end -local log = function(...) print("log", string.format(...)) end +local error, warning, info, log = luatexbase.provides_module(luaotfload.module) -kpse.init_prog("", 600, "/") -local luatex_version = 60 +local luatex_version = 75 if tex.luatexversion < luatex_version then warning("LuaTeX v%.2f is old, v%.2f is recommended.", @@ -203,7 +200,7 @@ add_to_callback("hpack_filter", "luaotfload.node_processor", 1) -loadmodule"font-otc.lua" +loadmodule"font-otc.lua" -- TODO check what we can drop from otfl-features loadmodule"lib-dir.lua" -- required by font-nms; will change with lualibs update loadmodule"font-nms.lua" @@ -268,7 +265,7 @@ callback. --doc]]-- local patch_defined_font = function (...) local tfmdata = fonts.definers.read(...) - if type(tfmdata) == "table" and tfmdata.shared then + if type(tfmdata) == "table" then call_callback("luaotfload.patch_font", tfmdata) end --inspect(tfmdata.shared.features) @@ -276,6 +273,7 @@ local patch_defined_font = function (...) end fonts.mode = "node" +caches.compilemethod = "both" function attributes.private(name) local attr = "otfl@" .. name @@ -305,58 +303,10 @@ elseif luaotfload.font_definer == "patch" then 1) end ---[[doc-- -These vanished in 2011. -\url{http://repo.or.cz/w/context.git/commitdiff/1455dd60b68c9140db1b9977c9e5ce372b772ec8} - -The “ss” stuff is in tables.features in context (see font-ott.lua), but -commented. -I’ll get back at restoring it as soon as someone can tell me what those do. -/phg - -local register_base_sub = fonts.otf.features.register_base_substitution -local gsubs = { - "ss01", "ss02", "ss03", "ss04", "ss05", - "ss06", "ss07", "ss08", "ss09", "ss10", - "ss11", "ss12", "ss13", "ss14", "ss15", - "ss16", "ss17", "ss18", "ss19", "ss20", -} - -for _,v in next, gsubs do - register_base_sub(v) -end ---doc]]-- - ----TODO check for conflicts with lualibs --- imported from "util-sto.lua" ---table.setmetatablenewindex = function (t,f) --- if type(t) ~= "table" then --- f, t = t, { } --- end --- local m = getmetatable(t) --- if m then --- if f == "ignore" then --- m.__newindex = f_ignore --- else --- m.__newindex = f --- end --- else --- if f == "ignore" then --- setmetatable(t, t_ignore) --- else --- setmetatable(t,{ __newindex = f }) --- end --- end --- return t ---end ----- this overloads fonts.handlers.features.normalize() ----- breakage ahead. ---loadmodule"font-ott.lua" - ---add_to_callback("find_vf_file", --- fonts.vf.find, --- "luaotfload.find_vf_file") +loadmodule"features.lua" +--[==[ +---- is this still necessary? local set_sscale_diments = function (tfmdata) local mathconstants = tfmdata.MathConstants if mathconstants then @@ -377,6 +327,7 @@ end add_to_callback("luaotfload.patch_font", set_sscale_diments, "unicodemath.set_sscale_diments") +]==] -- vim:tw=71:sw=2:ts=2:expandtab -- cgit v1.2.3 From cf25e2f185676223b565ab5e099fcc1b83fabfa8 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 10 Apr 2013 19:10:22 +0200 Subject: fallback for earlier lualibs; move locals up in luaotfload.lua --- luaotfload.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index 0fba16e..c90109d 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -34,6 +34,13 @@ local luatexbase = luatexbase local type, next, dofile = type, next, dofile local stringfind = string.find +local add_to_callback, create_callback = + luatexbase.add_to_callback, luatexbase.create_callback +local reset_callback, call_callback = + luatexbase.reset_callback, luatexbase.call_callback + +local dummy_function = function () end + --[[doc-- No final decision has been made on how to handle font definition. At the moment, there are three candidates: The \textsf{generic} @@ -164,7 +171,6 @@ The imported font loader will call \verb|callback.register| once This is unavoidable but harmless, so we make it call a dummy instead. --doc]]-- local trapped_register = callback.register -local dummy_function = function () end callback.register = dummy_function --[[doc-- @@ -179,11 +185,6 @@ After the fontloader is ready we can restore the callback trap from callback.register = trapped_register -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. @@ -208,7 +209,6 @@ loadmodule"font-clr.lua" --loadmodule"font-ovr.lua" loadmodule"font-ltx.lua" -local dummy_function = function ( ) end --- upvalue more efficient than lambda create_callback("luaotfload.patch_font", "simple", dummy_function) --[[doc-- -- cgit v1.2.3 From b85a3646ea13a26b2d8506531d2bdf072db81837 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 11 Apr 2013 00:18:13 +0200 Subject: enable overrides for Context loggers --- luaotfload.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index c90109d..10e3373 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -204,9 +204,9 @@ add_to_callback("hpack_filter", loadmodule"font-otc.lua" -- TODO check what we can drop from otfl-features loadmodule"lib-dir.lua" -- required by font-nms; will change with lualibs update +loadmodule"luat-ovr.lua" loadmodule"font-nms.lua" loadmodule"font-clr.lua" ---loadmodule"font-ovr.lua" loadmodule"font-ltx.lua" create_callback("luaotfload.patch_font", "simple", dummy_function) -- cgit v1.2.3 From 0266ebff82d4778f53c39787db23e9fa31837b32 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 13 Apr 2013 19:02:19 +0200 Subject: =?UTF-8?q?attempt=20at=20restoring=20KH=E2=80=99l=20OFM=20hack?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- luaotfload.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index 10e3373..cfe29a6 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -203,8 +203,21 @@ add_to_callback("hpack_filter", loadmodule"font-otc.lua" -- TODO check what we can drop from otfl-features -loadmodule"lib-dir.lua" -- required by font-nms; will change with lualibs update +loadmodule"lib-dir.lua" -- required by font-nms loadmodule"luat-ovr.lua" + +if fonts and fonts.readers.tfm then + -------------------------------------------------------------------- + --- OFM; read this first + -------------------------------------------------------------------- + --- I can’t quite make out whether this is still relevant + --- as those ofm fonts always fail, even in the 2011 version + --- (mktexpk: don't know how to create bitmap font for omarabb.ofm) + --- the font loader appears to read ofm like tfm so if this + --- hack was supposed achieve that, we should excise it anyways + fonts.readers.ofm = fonts.readers.tfm + -------------------------------------------------------------------- +end loadmodule"font-nms.lua" loadmodule"font-clr.lua" loadmodule"font-ltx.lua" -- cgit v1.2.3 From 9909991f8c403ef1119c44902de213695ae46318 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 14 Apr 2013 20:26:01 +0200 Subject: add virtual font file lookup --- luaotfload.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index cfe29a6..6e951dd 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -33,6 +33,7 @@ local luatexbase = luatexbase local type, next, dofile = type, next, dofile local stringfind = string.find +local find_file = kpse.find_file local add_to_callback, create_callback = luatexbase.add_to_callback, luatexbase.create_callback @@ -63,7 +64,7 @@ if tex.luatexversion < luatex_version then end local loadmodule = function (name) local tofind = fl_prefix .."-"..name - local found = kpse.find_file(tofind,"tex") + local found = find_file(tofind,"tex") if found then log("loading file %s.", found) dofile(found) @@ -73,6 +74,23 @@ local loadmodule = function (name) end end +--[[doc-- +Virtual fonts are resolved via a callback. +\verb|find_vf_file| derives the name of the virtual font file from the +filename. +(NB: \CONTEXT\ handles this likewise in \textsf{font-vf.lua}.) +--doc]]-- +local find_vf_file = function (name) + local fullname = find_file(name, "ovf") + if not fullname then + fullname = find_file(file.removesuffix(file.basename(name)), "ovf") + end + if fullname then + log("loading virtual font file %s.", fullname) + end + return fullname +end + --[[-- keep --]] --- from Hans (all merged): @@ -200,6 +218,8 @@ add_to_callback("hpack_filter", generic_context.callback_hpack_filter, "luaotfload.node_processor", 1) +add_to_callback("find_vf_file", + find_vf_file, "luaotfload.find_vf_file") loadmodule"font-otc.lua" -- TODO check what we can drop from otfl-features -- cgit v1.2.3 From ba7ad3c0cbede3e91fac9101b6f57f1849726725 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 15 Apr 2013 03:46:31 +0200 Subject: us TFM reader for OFM (needs testing) --- luaotfload.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index 6e951dd..1ca1fdc 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -83,10 +83,10 @@ filename. local find_vf_file = function (name) local fullname = find_file(name, "ovf") if not fullname then - fullname = find_file(file.removesuffix(file.basename(name)), "ovf") + fullname = find_file(file.removesuffix(file.basename(name)), "ovf") end if fullname then - log("loading virtual font file %s.", fullname) + log("loading virtual font file %s.", fullname) end return fullname end @@ -178,9 +178,9 @@ local non_generic_context =non_generic_context generic_context.no_callbacks_yet = true _G.non_generic_context = { luatex_fonts = { - load_before = "otfl-fonts-merged.lua", - -- load_after = nil, --- TODO, this is meant for callbacks - skip_loading = true, + load_before = "otfl-fonts-merged.lua", + -- load_after = nil, --- TODO, this is meant for callbacks + skip_loading = true, }} --[[doc-- @@ -235,7 +235,9 @@ if fonts and fonts.readers.tfm then --- (mktexpk: don't know how to create bitmap font for omarabb.ofm) --- the font loader appears to read ofm like tfm so if this --- hack was supposed achieve that, we should excise it anyways - fonts.readers.ofm = fonts.readers.tfm + fonts.readers.ofm = fonts.readers.tfm + fonts.handlers.ofm = fonts.handlers.tfm + fonts.formats.ofm = fonts.formats.tfm -------------------------------------------------------------------- end loadmodule"font-nms.lua" @@ -362,6 +364,6 @@ add_to_callback("luaotfload.patch_font", "unicodemath.set_sscale_diments") ]==] --- vim:tw=71:sw=2:ts=2:expandtab +-- vim:tw=71:sw=4:ts=4:expandtab -- End of File `luaotfload.lua'. -- cgit v1.2.3 From 690cd37becccf9e1f63c7c09054f82e54a50a13d Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 15 Apr 2013 13:13:18 +0200 Subject: avoid two calls to the file library --- luaotfload.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index 1ca1fdc..290bba7 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -80,10 +80,17 @@ Virtual fonts are resolved via a callback. filename. (NB: \CONTEXT\ handles this likewise in \textsf{font-vf.lua}.) --doc]]-- +local Cs, P, lpegmatch = lpeg.Cs, lpeg.P, lpeg.match + +local p_dot, p_slash = P".", P"/" +local p_suffix = (p_dot * (1 - p_dot - p_slash)^1 * P(-1)) / "" +local p_removesuffix = Cs((p_suffix + 1)^1) + local find_vf_file = function (name) local fullname = find_file(name, "ovf") if not fullname then - fullname = find_file(file.removesuffix(file.basename(name)), "ovf") + --fullname = find_file(file.removesuffix(name), "ovf") + fullname = find_file(lpegmatch(p_removesuffix, name), "ovf") end if fullname then log("loading virtual font file %s.", fullname) -- cgit v1.2.3 From f3d01d6407f3a8bd178a876a3a6228102618b986 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 15 Apr 2013 14:12:40 +0200 Subject: clean font-pfb --- luaotfload.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index 290bba7..34e5bdf 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -243,10 +243,12 @@ if fonts and fonts.readers.tfm then --- the font loader appears to read ofm like tfm so if this --- hack was supposed achieve that, we should excise it anyways fonts.readers.ofm = fonts.readers.tfm - fonts.handlers.ofm = fonts.handlers.tfm - fonts.formats.ofm = fonts.formats.tfm + fonts.handlers.ofm = fonts.handlers.tfm --- empty anyways + fonts.formats.ofm = fonts.formats.tfm --- “type1” -------------------------------------------------------------------- end +loadmodule"font-pfb.lua" + loadmodule"font-nms.lua" loadmodule"font-clr.lua" loadmodule"font-ltx.lua" -- cgit v1.2.3 From 3b5b837c46a39f20b90c978e34767c0abd5d1e75 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 15 Apr 2013 20:32:28 +0200 Subject: bump version; keep luaotfload well-formed for dtxtool --- luaotfload.lua | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index 34e5bdf..4373cfc 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -1,28 +1,9 @@ --- --- This is file `luaotfload.lua', --- generated with the docstrip utility. --- --- The original source files were: --- --- luaotfload.dtx (with options: `lua') --- This is a generated file. --- --- Copyright (C) 2009-2010 by by Elie Roux --- and Khaled Hosny --- (Support: .) --- --- This work is under the CC0 license. --- --- This work consists of the main source file luaotfload.dtx --- and the derived files --- luaotfload.sty, luaotfload.lua --- module("luaotfload", package.seeall) luaotfload.module = { name = "luaotfload", - version = 1.27, - date = "2012/05/28", + version = 2.2, + date = "2013/04/15", description = "OpenType layout system.", author = "Elie Roux & Hans Hagen", copyright = "Elie Roux", @@ -136,12 +117,6 @@ end --- otfl-font-oti.lua --- otfl-font-otn.lua ---[[-- - it all boils down to this: we load otfl-fonts.lua - which takes care of loading the merged file. - that’s it, go thank Hans! ---]]-- - --[[doc-- We treat the fontloader as a black box so behavior is consistent between formats. @@ -374,5 +349,3 @@ add_to_callback("luaotfload.patch_font", ]==] -- vim:tw=71:sw=4:ts=4:expandtab - --- End of File `luaotfload.lua'. -- cgit v1.2.3 From ad7e8482bf485c870e37792a8167d8f414e021a3 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 16 Apr 2013 15:38:44 +0200 Subject: integrate luaotfload.lua into luaotfload.dtx --- luaotfload.lua | 272 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 185 insertions(+), 87 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index 4373cfc..bdbae0e 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -21,28 +21,55 @@ local add_to_callback, create_callback = local reset_callback, call_callback = luatexbase.reset_callback, luatexbase.call_callback -local dummy_function = function () end +local dummy_function = function () end --[[doc-- -No final decision has been made on how to handle font definition. -At the moment, there are three candidates: The \textsf{generic} -callback as hard-coded in the font loader, the \textsf{old} wrapper, -and a simplified version of the latter (\textsf{patch}) that does -nothing besides applying font patches. +No final decision has been made on how to handle font definition. At +the moment, there are three candidates: The \identifier{generic} +callback as hard-coded in the font loader, the \identifier{old} +wrapper, and a simplified version of the latter (\identifier{patch}) +that does nothing besides applying font patches. --doc]]-- luaotfload.font_definer = "patch" --- | “generic” | “old” -local fl_prefix = "otfl" -- “luatex” for luatex-plain +local error, warning, info, log = + luatexbase.provides_module(luaotfload.module) + +--[[doc-- +This is a necessary initalization in order not to rebuild an existing +font. +Maybe 600 should be replaced by \texmacro{pdfpkresolution} %% (why?) +or \luafunction{texconfig.pk_dpi} (and it should be replaced +dynamically), but we don't have access (yet) to the +\identifier{texconfig} table, so we let it be 600. +Anyway, it does still work fine even if \texmacro{pdfpkresolution} is +changed. +--doc]]-- + +kpse.init_prog("", 600, "/") -local error, warning, info, log = luatexbase.provides_module(luaotfload.module) +--[[doc-- +We set the minimum version requirement for \LUATEX to v0.74, as it was +the first version to include version 5.2 of the \LUA interpreter. +--doc]]-- -local luatex_version = 75 +local luatex_version = 74 if tex.luatexversion < luatex_version then warning("LuaTeX v%.2f is old, v%.2f is recommended.", tex.luatexversion/100, luatex_version /100) end + +--[[doc-- +\subsection{Module loading} + +We load the files imported from \CONTEXT with this function. +It automatically prepends the prefix \fileent{otfl-} to its argument, +so we can refer to the files with their actual \CONTEXT name. +--doc]]-- + +local fl_prefix = "otfl" -- “luatex” for luatex-plain local loadmodule = function (name) local tofind = fl_prefix .."-"..name local found = find_file(tofind,"tex") @@ -50,16 +77,15 @@ local loadmodule = function (name) log("loading file %s.", found) dofile(found) else - --error("file %s not found.", tofind) error("file %s not found.", tofind) end end --[[doc-- Virtual fonts are resolved via a callback. -\verb|find_vf_file| derives the name of the virtual font file from the -filename. -(NB: \CONTEXT\ handles this likewise in \textsf{font-vf.lua}.) +\luafunction{find_vf_file} derives the name of the virtual font file +from the filename. +(NB: \CONTEXT handles this likewise in \fileent{font-vf.lua}.) --doc]]-- local Cs, P, lpegmatch = lpeg.Cs, lpeg.P, lpeg.match @@ -118,38 +144,48 @@ end --- otfl-font-otn.lua --[[doc-- + +\subsection{Preparing the Font Loader} We treat the fontloader as a black box so behavior is consistent between formats. -The wrapper file is |otfl-fonts.lua| which we imported from -\LUATEX-Plain. +The wrapper file is \fileent{otfl-fonts.lua} which we imported from +\href{http://standalone.contextgarden.net/current/context/experimental/tex/generic/context/luatex/}{\LUATEX-Plain}. It has roughly two purposes: -(\textit{1}) insert the functionality required for fontloader, and -(\textit{2}) put it in place via the respective callbacks. + +\begin{enumerate} + + \item insert the functionality required for fontloader; and + + \item put it in place via the respective callbacks. + +\end{enumerate} + How the first step is executed depends on the presence on the \emph{merged font loader code}. -In \textsf{luaotfload} this is contained in the file -|otfl-fonts-merged.lua|. +In \identifier{luaotfload} this is contained in the file +\fileent{otfl-fonts-merged.lua}. If this file cannot be found, the original libraries from \CONTEXT of which the merged code was composed are loaded instead. Hans provides two global tables to control the font loader: -\begin{tabular}{ll} - \texttt{generic\textunderscore context} & - encapsulation mechanism, callback functions - \\ - \texttt{non\textunderscore generic\textunderscore context} & - customized code insertion - \\ -\end{tabular} -With \verb|non_generic_context| we can tailor the font loader insertion -to our file naming habits (key \verb|load_before|). -Additionally, \verb|skip_loading| can be unset to force loading of -the original libraries as though the merged code was absent. -Another key, \verb|load_after| is called at the time when the font -loader is actually inserted. -In combination with the option \verb|no_callbacks_yet| in -\verb|generic_context|, we can insert our own, -\textsf{luatexbase}-style callback handling here. + + \begin{itemize} + \item \luafunction{generic_context}: + encapsulation mechanism, callback functions + \item \luafunction{non generic_context}: + customized code insertion + \end{itemize} + + +With \luafunction{non_generic_context} we can tailor the font loader +insertion to our file naming habits (key \luafunction{load_before}). +Additionally, \luafunction{skip_loading} can be unset to force loading +of the original libraries as though the merged code was absent. +Another key, \luafunction{load_after} is called at the time when the +font loader is actually inserted. +In combination with the option \luafunction{no_callbacks_yet} in +\luafunction{generic_context}, we can insert our own, +\identifier{luatexbase}-style callback handling here. --doc]]-- if not _G. generic_context then _G. generic_context = { } end if not _G.non_generic_context then _G.non_generic_context = { } end @@ -166,21 +202,91 @@ _G.non_generic_context = { luatex_fonts = { }} --[[doc-- -The imported font loader will call \verb|callback.register| once -(during \verb|font-def.lua|). -This is unavoidable but harmless, so we make it call a dummy instead. +The imported font loader will call \luafunction{callback.register} once +while reading \fileent{font-def.lua}. +This is unavoidable unless we modify the imported files, but harmless +if we make it call a dummy instead. --doc]]-- + local trapped_register = callback.register callback.register = dummy_function --[[doc-- -Now that things are sorted out we can load the fontloader. +Now that things are sorted out we can finally load the fontloader. --doc]]-- + loadmodule"fonts.lua" --[[doc-- +By default, the fontloader requires a number of \emph{private +attributes} for internal use. +These must be kept consistent with the attribute handling methods as +provided by \identifier{luatexbase}. +Previously, when \identifier{luaotfload} imported individual files from +\CONTEXT, the strategy was to override the function that allocates new +attributes at the appropriate time during initialization, making it a +wrapper around \luafunction{luatexbase.new_attribute}. + +\begin{verbatim} +attributes.private = function (name) + local attr = "otfl@" .. name + local number = luatexbase.attributes[attr] + if not number then + number = luatexbase.new_attribute(attr) + end + return number +end +\end{verbatim} + +Now that the fontloader comes as a package, this hack is no longer +applicable. +The attribute handler installed by \identifier{luatex-fonts} (see the +file \fileent{otfl-basics-nod.lua}) cannot be intercepted before the +first call to it takes place. +While it is not feasible to prevent insertion of attributes at the +wrong places, we can still retrieve them from the closure surrounding +the allocation function \luafunction{attributes.private} +using \LUA’s introspection features. + +The recovered attribute identifiers are prefixed “\fileent{otfl@}” to +avoid name clashes. +--doc]]-- + +do + local debug_getupvalue = debug.getupvalue + + local nups = debug.getinfo(attributes.private, "u").nups + local nup, numbers = 0 + while nup <= nups do + nup = nup + 1 + local upname, upvalue = debug_getupvalue(attributes.private, nup) + if upname == "numbers" then + numbers = upvalue + break + end + end + if numbers then + local luatexbase_attributes = luatexbase.attributes + local prefix = "otfl@" + --- re-register attributes from “numbers” + --- ... pull request for luatexbase pending + for name, num in next, numbers do + name = prefix .. name + luatexbase_attributes[name] = num + end + end + --- The definitions used by the fontloader are never + --- called again so it is safe to nil them, I suppose. + debug.setupvalue(attributes.private, nup, { }) + _G.attributes = nil --- needed for initialization only +end + +--[[doc-- + +\subsection{Callbacks} + After the fontloader is ready we can restore the callback trap from -\textsf{luatexbase}. +\identifier{luatexbase}. --doc]]-- callback.register = trapped_register @@ -188,8 +294,8 @@ callback.register = trapped_register --[[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}. +Note: \luafunction{pre_linebreak_filter} and \luafunction{hpack_filter} +are coupled in \CONTEXT in the concept of \emph{node processor}. --doc]]-- add_to_callback("pre_linebreak_filter", @@ -220,29 +326,46 @@ if fonts and fonts.readers.tfm then fonts.readers.ofm = fonts.readers.tfm fonts.handlers.ofm = fonts.handlers.tfm --- empty anyways fonts.formats.ofm = fonts.formats.tfm --- “type1” + --- fonts.readers.sequence[#fonts.readers.sequence+1] = "ofm" -------------------------------------------------------------------- end -loadmodule"font-pfb.lua" +--[[doc-- + +Now we load the modules written for \identifier{luaotfload}. + +--doc]]-- +loadmodule"font-pfb.lua" --- new in 2.0, added 2011 loadmodule"font-nms.lua" loadmodule"font-clr.lua" -loadmodule"font-ltx.lua" +loadmodule"font-ltx.lua" --- new in 2.0, added 2011 + +--[[doc-- + +We create a callback for patching fonts on the fly, to be used by other +packages. +It initially contains the empty function that we are going to override +below. + +--doc]]-- create_callback("luaotfload.patch_font", "simple", dummy_function) --[[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. +As of 2013, everything it does appear to be redundand, so we won’t use +it unless somebody points out a cogent reason. 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. +font data objects and will stay here for reference / until breakage is +reported. -TODO +\emphasis{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 @@ -279,35 +402,34 @@ local define_font_wrapper = function (...) end --[[doc-- + +\subsection{\CONTEXT override} + We provide a simplified version of the original font definition callback. + --doc]]-- + +local read_font_file = fonts.definers.read local patch_defined_font = function (...) - local tfmdata = fonts.definers.read(...) + local tfmdata = read_font_file(...)-- spec -> size -> id -> tmfdata if type(tfmdata) == "table" then call_callback("luaotfload.patch_font", tfmdata) end - --inspect(tfmdata.shared.features) return tfmdata end -fonts.mode = "node" caches.compilemethod = "both" -function attributes.private(name) - local attr = "otfl@" .. name - local number = luatexbase.attributes[attr] - if not number then - number = luatexbase.new_attribute(attr) - end - return number -end - reset_callback("define_font") +--[[doc-- +Finally we register the callbacks +--doc]]-- + if luaotfload.font_definer == "old" then add_to_callback("define_font", - old_define_font_wrapper, + define_font_wrapper, "luaotfload.define_font", 1) elseif luaotfload.font_definer == "generic" then @@ -324,28 +446,4 @@ end loadmodule"features.lua" ---[==[ ----- is this still necessary? -local set_sscale_diments = function (tfmdata) - local mathconstants = tfmdata.MathConstants - if mathconstants then - local tfmparameters = tfmdata.parameters - if mathconstants.ScriptPercentScaleDown then - tfmparameters[10] = mathconstants.ScriptPercentScaleDown - else -- resort to plain TeX default - tfmparameters[10] = 70 - end - if mathconstants.ScriptScriptPercentScaleDown then - tfmparameters[11] = mathconstants.ScriptScriptPercentScaleDown - else -- resort to plain TeX default - tfmparameters[11] = 50 - end - end -end - -add_to_callback("luaotfload.patch_font", - set_sscale_diments, - "unicodemath.set_sscale_diments") -]==] - -- vim:tw=71:sw=4:ts=4:expandtab -- cgit v1.2.3 From 71555eecef54adc6fee27c81afe20477c0dddea2 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 16 Apr 2013 23:48:08 +0200 Subject: remove attribute allocation hack --- luaotfload.lua | 71 ++++++++++++++++------------------------------------------ 1 file changed, 19 insertions(+), 52 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index bdbae0e..70d89a2 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -218,67 +218,34 @@ Now that things are sorted out we can finally load the fontloader. loadmodule"fonts.lua" --[[doc-- -By default, the fontloader requires a number of \emph{private +By default, the fontloader requires a number of \emphasis{private attributes} for internal use. These must be kept consistent with the attribute handling methods as provided by \identifier{luatexbase}. -Previously, when \identifier{luaotfload} imported individual files from -\CONTEXT, the strategy was to override the function that allocates new -attributes at the appropriate time during initialization, making it a -wrapper around \luafunction{luatexbase.new_attribute}. - -\begin{verbatim} -attributes.private = function (name) - local attr = "otfl@" .. name - local number = luatexbase.attributes[attr] - if not number then - number = luatexbase.new_attribute(attr) - end - return number -end -\end{verbatim} - -Now that the fontloader comes as a package, this hack is no longer -applicable. -The attribute handler installed by \identifier{luatex-fonts} (see the -file \fileent{otfl-basics-nod.lua}) cannot be intercepted before the -first call to it takes place. -While it is not feasible to prevent insertion of attributes at the -wrong places, we can still retrieve them from the closure surrounding -the allocation function \luafunction{attributes.private} -using \LUA’s introspection features. - -The recovered attribute identifiers are prefixed “\fileent{otfl@}” to +Our strategy is to override the function that allocates new attributes +before we initialize the font loader, making it a wrapper around +\luafunction{luatexbase.new_attribute}.\footnote{% + Many thanks, again, to Hans Hagen for making this part + configurable! +} +The attribute identifiers are prefixed “\fileent{otfl@}” to avoid name clashes. --doc]]-- do - local debug_getupvalue = debug.getupvalue - - local nups = debug.getinfo(attributes.private, "u").nups - local nup, numbers = 0 - while nup <= nups do - nup = nup + 1 - local upname, upvalue = debug_getupvalue(attributes.private, nup) - if upname == "numbers" then - numbers = upvalue - break - end - end - if numbers then - local luatexbase_attributes = luatexbase.attributes - local prefix = "otfl@" - --- re-register attributes from “numbers” - --- ... pull request for luatexbase pending - for name, num in next, numbers do - name = prefix .. name - luatexbase_attributes[name] = num + local new_attribute = luatexbase.new_attribute + local the_attributes = luatexbase.attributes + + _G.attributes = _G.attributes or { } + + _G.attributes.private = function (name) + local attr = "otfl@" .. name + local number = the_attributes[attr] + if not number then + number = new_attribute(attr) end + return number end - --- The definitions used by the fontloader are never - --- called again so it is safe to nil them, I suppose. - debug.setupvalue(attributes.private, nup, { }) - _G.attributes = nil --- needed for initialization only end --[[doc-- -- cgit v1.2.3 From 94bd394d1e2a0b08b2341927ad3fda09b78590a5 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 17 Apr 2013 22:25:49 +0200 Subject: avoid calling table.contains() --- luaotfload.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index 70d89a2..b815c19 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -161,7 +161,7 @@ It has roughly two purposes: \end{enumerate} How the first step is executed depends on the presence on the -\emph{merged font loader code}. +\emphasis{merged font loader code}. In \identifier{luaotfload} this is contained in the file \fileent{otfl-fonts-merged.lua}. If this file cannot be found, the original libraries from \CONTEXT of @@ -262,7 +262,7 @@ callback.register = trapped_register We do our own callback handling with the means provided by luatexbase. Note: \luafunction{pre_linebreak_filter} and \luafunction{hpack_filter} -are coupled in \CONTEXT in the concept of \emph{node processor}. +are coupled in \CONTEXT in the concept of \emphasis{node processor}. --doc]]-- add_to_callback("pre_linebreak_filter", -- cgit v1.2.3 From 341397fb11813b73506d3e76bdc7e69392da852a Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 18 Apr 2013 15:26:35 +0200 Subject: expand docs --- luaotfload.lua | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index b815c19..3c35150 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -12,9 +12,11 @@ luaotfload.module = { local luatexbase = luatexbase -local type, next, dofile = type, next, dofile -local stringfind = string.find -local find_file = kpse.find_file +local type, next = type, next +local stringfind = string.find +local stringsub = string.sub +local stringmatch = string.match +local find_file = kpse.find_file local add_to_callback, create_callback = luatexbase.add_to_callback, luatexbase.create_callback @@ -277,7 +279,6 @@ add_to_callback("find_vf_file", find_vf_file, "luaotfload.find_vf_file") loadmodule"font-otc.lua" -- TODO check what we can drop from otfl-features - loadmodule"lib-dir.lua" -- required by font-nms loadmodule"luat-ovr.lua" @@ -411,6 +412,38 @@ elseif luaotfload.font_definer == "patch" then 1) end +--[[todo-- +--- The manual promises coercion of the file: lookup if +--- the asked name is enclosed in brackets. +--- A couple things make me doubt that this is the case: +--- +--- 1) there doesn’t appear to be code for these cases +--- 2) the brackets remain part of the file name +--- 3) we still get calls to names.resolve which +--- ignores the “lookup” field of the spec it gets +--- +--- For this reason here is some code that a) coerces +--- file: lookups in these cases and b) strips the brackets +--- from the file name. As we *still* get name: lookups even +--- though this code is active I’ll just leave it here +--- for reference, ineffective as it is. +do + local getspecification, makespecification = + fonts.definers.getspecification, fonts.definers.makespecification + + local analyze = function (specification, size) + local lookup, name, sub, method, detail = getspecification(specification or "") + local filename = stringmatch(name, "^%[(.*)%]$") + if filename then + lookup = "file" --> coerce file: + name = filename --> remove brackets + end + return makespecification(specification, lookup, name, sub, method, detail, size) + end + fonts.definers.analyze = analyze +end +--]]-- + loadmodule"features.lua" -- vim:tw=71:sw=4:ts=4:expandtab -- cgit v1.2.3 From b0c22678d1f776f991ffef67694451b8bb5f9e20 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 18 Apr 2013 16:21:33 +0200 Subject: remove comments on dependencies (in dtx now) --- luaotfload.lua | 38 -------------------------------------- 1 file changed, 38 deletions(-) (limited to 'luaotfload.lua') diff --git a/luaotfload.lua b/luaotfload.lua index 3c35150..256c792 100644 --- a/luaotfload.lua +++ b/luaotfload.lua @@ -107,44 +107,6 @@ local find_vf_file = function (name) return fullname end ---[[-- keep --]] ---- from Hans (all merged): - ---- file name modified include name ---- × basics-gen.lua t luat-basics-gen ---- × font-def -> fonts-def t luatex-font-def (there’s also the normal font-def!) ---- × fonts-enc f luatex-font-enc ---- × fonts-ext t luatex-fonts-ext ---- × fonts-lua f luatex-fonts-lua ---- fonts-tfm f luatex-fonts-tfm ---- × fonts-cbk f luatex-fonts-lua - ---- from Hans (unmerged): ---- font-otc.lua -> otfl-font-otc.lua - ---- from luaotfload: ---- otfl-luat-ovr.lua -- override some luat-dum functions ---- otfl-font-clr.lua ---- otfl-font-ltx.lua ---- otfl-font-nms.lua ---- otfl-font-pfb.lua -- ? - ---[[-- new --]] ---- basics-nod (merged as fonts-nod !) ---- fonts-demo-vf-1.lua ---- fonts-syn (merged) - ---[[-- merged, to be dropped --]] ---- otfl-data-con.lua ---- otfl-font-cid.lua ---- otfl-font-con.lua ---- otfl-font-ini.lua ---- otfl-font-ota.lua ---- otfl-font-otb.lua ---- otfl-font-otf.lua ---- otfl-font-oti.lua ---- otfl-font-otn.lua - --[[doc-- \subsection{Preparing the Font Loader} -- cgit v1.2.3