From 7cd218b920814322d002f915ed5c8bb0132cf40a Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 27 Aug 2015 23:28:32 +0200 Subject: [main,loaders] regroup callback handling code with loaders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... changing the meaning of the file’s designation instead of adding yet another file. All the callback manipulation is now contained inside that module which will inject most of its functionality only when its main ``.install()`` method is called. --- src/luaotfload-loaders.lua | 147 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 120 insertions(+), 27 deletions(-) (limited to 'src/luaotfload-loaders.lua') diff --git a/src/luaotfload-loaders.lua b/src/luaotfload-loaders.lua index 901d4d8..061789c 100644 --- a/src/luaotfload-loaders.lua +++ b/src/luaotfload-loaders.lua @@ -1,34 +1,127 @@ -if not modules then modules = { } end modules ["loaders"] = { - version = "2.5", - comment = "companion to luaotfload-main.lua", - author = "Hans Hagen, Khaled Hosny, Elie Roux, Philipp Gesang", - copyright = "PRAGMA ADE / ConTeXt Development Team", - license = "see context related readme files" -} +#!/usr/bin/env texlua +----------------------------------------------------------------------- +-- FILE: luaotfload-loaders.lua +-- DESCRIPTION: Luaotfload callback handling +-- REQUIREMENTS: luatex v.0.80 or later; packages lualibs, luatexbase +-- AUTHOR: Philipp Gesang (Phg), , Hans Hagen, Khaled Hosny, Elie Roux +-- VERSION: just consult Git, okay? +----------------------------------------------------------------------- +-- +--- Contains parts of the earlier main script. + +if not lualibs then error "this module requires Luaotfload" end +if not luaotfload then error "this module requires Luaotfload" end + +local logreport = luaotfload.log and luaotfload.log.report or print +local add_to_callback = luatexbase.add_to_callback +local create_callback = luatexbase.create_callback +local reset_callback = luatexbase.reset_callback +local call_callback = luatexbase.call_callback +local dummy_function = function () 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 + if not readers or not handlers or not formats then return false end + + local aux = function (which, reader) + if not which or type (which) ~= "string" then return false end + formats [which] = "type1" + readers [which] = reader + handlers [which] = { } + return true + end + + return 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 + +--[[doc-- -local fonts = fonts -local readers = fonts.readers -local handlers = fonts.handlers -local formats = fonts.formats - -local pfb_reader = function (specification) - return readers.opentype (specification, "pfb", "type1") -end - -local pfa_reader = function (specification) - return readers.opentype (specification, "pfa", "type1") + \subsection{\CONTEXT override} + \label{define-font} + We provide a simplified version of the original font definition + callback. + +--doc]]-- + + +local definers = { } --- (string, spec -> size -> id -> tmfdata) hash_t +do + local read = fonts.definers.read + + local patch = function (specification, size, id) + local fontdata = read (specification, size, id) + if type (fontdata) == "table" and fontdata.shared then + --- We need to test for the “shared” field here + --- or else the fontspec capheight callback will + --- operate on tfm fonts. + call_callback ("luaotfload.patch_font", fontdata, specification) + else + call_callback ("luaotfload.patch_font_unsafe", fontdata, specification) + end + return fontdata + end + + local mk_info = function (name) + local definer = name == "patch" and patch or read + return function (specification, size, id) + logreport ("both", 0, "main", "defining font no. %d", id) + logreport ("both", 0, "main", " > active font definer: %q", name) + logreport ("both", 0, "main", " > spec %q", specification) + logreport ("both", 0, "main", " > at size %.2f pt", size / 2^16) + local result = definer (specification, size, id) + if not result then + logreport ("both", 0, "main", " > font definition failed") + return + elseif type (result) == "number" then + logreport ("both", 0, "main", " > font definition yielded id %d", result) + return result + end + logreport ("both", 0, "main", " > font definition successful") + logreport ("both", 0, "main", " > name %q", result.name or "") + logreport ("both", 0, "main", " > fontname %q", result.fontname or "") + logreport ("both", 0, "main", " > fullname %q", result.fullname or "") + return result + end + end + + definers.patch = patch + definers.generic = read + definers.info_patch = mk_info "patch" + definers.info_generic = mk_info "generic" end -formats.pfa = "type1" -readers.pfa = pfa_reader -handlers.pfa = { } +--[[doc-- + + We create callbacks for patching fonts on the fly, to be used by + other packages. In addition to the regular \identifier{patch_font} + callback there is an unsafe variant \identifier{patch_font_unsafe} + that will be invoked even if the target font lacks certain essential + tfmdata tables. -formats.pfb = "type1" -readers.pfb = pfb_reader -handlers.pfb = { } + The callbacks initially contain the empty function that we are going + to override below. -formats.ofm = "type1" -readers.ofm = readers.tfm -handlers.ofm = { } +--doc]]-- +return { + install = function () + if not install_formats () then + logreport ("both", 0, "main", "error initializing OFM/PF{A,B} loaders") + end + create_callback("luaotfload.patch_font", "simple", dummy_function) + create_callback("luaotfload.patch_font_unsafe", "simple", dummy_function) + + reset_callback "define_font" + local definer = config.luaotfload.run.definer + add_to_callback ("define_font", definers[definer or "patch"], + "luaotfload.define_font", 1) + end +} -- vim:tw=71:sw=2:ts=2:expandtab -- cgit v1.2.3 From c6fdf62a060ad9e77c461d5eb7a55699fa6c7249 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 27 Aug 2015 23:39:46 +0200 Subject: [loaders] {re,un}-scope locals for economy --- src/luaotfload-loaders.lua | 57 +++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 21 deletions(-) (limited to 'src/luaotfload-loaders.lua') diff --git a/src/luaotfload-loaders.lua b/src/luaotfload-loaders.lua index 061789c..f722d85 100644 --- a/src/luaotfload-loaders.lua +++ b/src/luaotfload-loaders.lua @@ -12,12 +12,7 @@ if not lualibs then error "this module requires Luaotfload" end if not luaotfload then error "this module requires Luaotfload" end -local logreport = luaotfload.log and luaotfload.log.report or print -local add_to_callback = luatexbase.add_to_callback -local create_callback = luatexbase.create_callback -local reset_callback = luatexbase.reset_callback -local call_callback = luatexbase.call_callback -local dummy_function = function () end +local logreport = luaotfload.log and luaotfload.log.report or print local install_formats = function () local fonts = fonts @@ -29,7 +24,11 @@ local install_formats = function () if not readers or not handlers or not formats then return false end local aux = function (which, reader) - if not which or type (which) ~= "string" then return false end + if not which or type (which) ~= "string" + or not reader or type (reader) ~= "function" then + logreport ("both", 2, "main", "error installing reader for “%s”", which) + return false + end formats [which] = "type1" readers [which] = reader handlers [which] = { } @@ -51,7 +50,7 @@ end --doc]]-- -local definers = { } --- (string, spec -> size -> id -> tmfdata) hash_t +local definers --- (string, spec -> size -> id -> tmfdata) hash_t do local read = fonts.definers.read @@ -61,7 +60,7 @@ do --- We need to test for the “shared” field here --- or else the fontspec capheight callback will --- operate on tfm fonts. - call_callback ("luaotfload.patch_font", fontdata, specification) + luatexbase.call_callback ("luaotfload.patch_font", fontdata, specification) else call_callback ("luaotfload.patch_font_unsafe", fontdata, specification) end @@ -91,10 +90,12 @@ do end end - definers.patch = patch - definers.generic = read - definers.info_patch = mk_info "patch" - definers.info_generic = mk_info "generic" + definers = { + patch = patch, + generic = read, + info_patch = mk_info "patch", + info_generic = mk_info "generic", + } end --[[doc-- @@ -110,18 +111,32 @@ end --doc]]-- +local install_callbacks = function () + local create_callback = luatexbase.create_callback + local dummy_function = function () end + create_callback ("luaotfload.patch_font", "simple", dummy_function) + create_callback ("luaotfload.patch_font_unsafe", "simple", dummy_function) + luatexbase.reset_callback "define_font" + local definer = config.luaotfload.run.definer + luatexbase.add_to_callback ("define_font", + definers[definer or "patch"], + "luaotfload.define_font", + 1) + return true +end + return { install = function () + local ret = true if not install_formats () then logreport ("both", 0, "main", "error initializing OFM/PF{A,B} loaders") + ret = false end - create_callback("luaotfload.patch_font", "simple", dummy_function) - create_callback("luaotfload.patch_font_unsafe", "simple", dummy_function) - - reset_callback "define_font" - local definer = config.luaotfload.run.definer - add_to_callback ("define_font", definers[definer or "patch"], - "luaotfload.define_font", 1) + if not install_callbacks () then + logreport ("both", 0, "main", "error installing font loader callbacks") + ret = false + end + return ret end } --- vim:tw=71:sw=2:ts=2:expandtab +-- vim:tw=79:sw=2:ts=2:expandtab -- cgit v1.2.3 From c3db46b819beebb892698513bd51341b9a691786 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 27 Aug 2015 23:42:44 +0200 Subject: [main,loaders] adjust noise and check status of loader init --- src/luaotfload-loaders.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/luaotfload-loaders.lua') diff --git a/src/luaotfload-loaders.lua b/src/luaotfload-loaders.lua index f722d85..44216d7 100644 --- a/src/luaotfload-loaders.lua +++ b/src/luaotfload-loaders.lua @@ -26,7 +26,7 @@ local install_formats = function () local aux = function (which, reader) if not which or type (which) ~= "string" or not reader or type (reader) ~= "function" then - logreport ("both", 2, "main", "error installing reader for “%s”", which) + logreport ("both", 2, "loaders", "Error installing reader for “%s”.", which) return false end formats [which] = "type1" @@ -70,22 +70,22 @@ do local mk_info = function (name) local definer = name == "patch" and patch or read return function (specification, size, id) - logreport ("both", 0, "main", "defining font no. %d", id) - logreport ("both", 0, "main", " > active font definer: %q", name) - logreport ("both", 0, "main", " > spec %q", specification) - logreport ("both", 0, "main", " > at size %.2f pt", size / 2^16) + logreport ("both", 0, "loaders", "defining font no. %d", id) + logreport ("both", 0, "loaders", " > active font definer: %q", name) + logreport ("both", 0, "loaders", " > spec %q", specification) + logreport ("both", 0, "loaders", " > at size %.2f pt", size / 2^16) local result = definer (specification, size, id) if not result then - logreport ("both", 0, "main", " > font definition failed") + logreport ("both", 0, "loaders", " > font definition failed") return elseif type (result) == "number" then - logreport ("both", 0, "main", " > font definition yielded id %d", result) + logreport ("both", 0, "loaders", " > font definition yielded id %d", result) return result end - logreport ("both", 0, "main", " > font definition successful") - logreport ("both", 0, "main", " > name %q", result.name or "") - logreport ("both", 0, "main", " > fontname %q", result.fontname or "") - logreport ("both", 0, "main", " > fullname %q", result.fullname or "") + logreport ("both", 0, "loaders", " > font definition successful") + logreport ("both", 0, "loaders", " > name %q", result.name or "") + logreport ("both", 0, "loaders", " > fontname %q", result.fontname or "") + logreport ("both", 0, "loaders", " > fullname %q", result.fullname or "") return result end end @@ -129,11 +129,11 @@ return { install = function () local ret = true if not install_formats () then - logreport ("both", 0, "main", "error initializing OFM/PF{A,B} loaders") + logreport ("log", 0, "loaders", "Error initializing OFM/PF{A,B} loaders.") ret = false end if not install_callbacks () then - logreport ("both", 0, "main", "error installing font loader callbacks") + logreport ("log", 0, "loaders", "Error installing font loader callbacks.") ret = false end return ret -- cgit v1.2.3 From 780113609ffbb146c1b5a825cb25025246cdba2a Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 27 Sep 2015 20:17:02 +0200 Subject: [main, *] convert for centralized initialization routine --- src/luaotfload-loaders.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/luaotfload-loaders.lua') diff --git a/src/luaotfload-loaders.lua b/src/luaotfload-loaders.lua index 44216d7..89a9fff 100644 --- a/src/luaotfload-loaders.lua +++ b/src/luaotfload-loaders.lua @@ -126,7 +126,7 @@ local install_callbacks = function () end return { - install = function () + init = function () local ret = true if not install_formats () then logreport ("log", 0, "loaders", "Error initializing OFM/PF{A,B} loaders.") -- cgit v1.2.3 From 811d385a2c903f001ceb719ae1a29ce4586b16b4 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 28 Oct 2015 06:56:07 +0100 Subject: [loaders] fix call to missing local --- src/luaotfload-loaders.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/luaotfload-loaders.lua') diff --git a/src/luaotfload-loaders.lua b/src/luaotfload-loaders.lua index 89a9fff..b644266 100644 --- a/src/luaotfload-loaders.lua +++ b/src/luaotfload-loaders.lua @@ -62,7 +62,7 @@ do --- operate on tfm fonts. luatexbase.call_callback ("luaotfload.patch_font", fontdata, specification) else - call_callback ("luaotfload.patch_font_unsafe", fontdata, specification) + luatexbase.call_callback ("luaotfload.patch_font_unsafe", fontdata, specification) end return fontdata end -- cgit v1.2.3 From 8395eb8efec1ac9e311541d9834f1a939b91e710 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 5 Nov 2015 22:08:47 +0100 Subject: [*] kill off file headers We have the VCS info in the status file; these things are just silly. --- src/luaotfload-loaders.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'src/luaotfload-loaders.lua') diff --git a/src/luaotfload-loaders.lua b/src/luaotfload-loaders.lua index b644266..38062f6 100644 --- a/src/luaotfload-loaders.lua +++ b/src/luaotfload-loaders.lua @@ -4,7 +4,6 @@ -- DESCRIPTION: Luaotfload callback handling -- REQUIREMENTS: luatex v.0.80 or later; packages lualibs, luatexbase -- AUTHOR: Philipp Gesang (Phg), , Hans Hagen, Khaled Hosny, Elie Roux --- VERSION: just consult Git, okay? ----------------------------------------------------------------------- -- --- Contains parts of the earlier main script. -- cgit v1.2.3