diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2015-08-27 23:28:32 +0200 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2015-08-27 23:28:35 +0200 |
commit | 7cd218b920814322d002f915ed5c8bb0132cf40a (patch) | |
tree | 036e47fe41160825754220ab68725cf54c1bc71a | |
parent | e05c2e2c2f72788e63da7334e054fd887bd22e70 (diff) | |
download | luaotfload-7cd218b920814322d002f915ed5c8bb0132cf40a.tar.gz |
[main,loaders] regroup callback handling code with loaders
... 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.
-rw-r--r-- | src/luaotfload-loaders.lua | 147 | ||||
-rw-r--r-- | src/luaotfload-main.lua | 116 |
2 files changed, 134 insertions, 129 deletions
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), <phg@phi-gamma.net>, 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 "<nil>") + logreport ("both", 0, "main", " > fontname %q", result.fontname or "<nil>") + logreport ("both", 0, "main", " > fullname %q", result.fullname or "<nil>") + 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 diff --git a/src/luaotfload-main.lua b/src/luaotfload-main.lua index 36db2c3..fe27215 100644 --- a/src/luaotfload-main.lua +++ b/src/luaotfload-main.lua @@ -67,12 +67,6 @@ luaotfload.module = { local luatexbase = luatexbase local require = require local type = type -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 --- XXX this will be moved to the luaotfload namespace when we have the init module local error, warning, info, log = luatexbase.provides_module(luaotfload.module) @@ -165,110 +159,28 @@ end luaotfload.init.main (store) -load_luaotfload_module "loaders" --- Type1 font wrappers -load_luaotfload_module "database" --- Font management. -load_luaotfload_module "colors" --- Per-font colors. - -luaotfload.resolvers = load_luaotfload_module "resolvers" --- Font lookup - -luaotfload.resolvers.install () - -if not config.actions.reconfigure () then - logreport ("log", 0, "load", "Post-configuration hooks failed.") -end - ---[[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. - - The callbacks initially contain the empty function that we are going to - override below. - ---doc]]-- - -create_callback("luaotfload.patch_font", "simple", dummy_function) -create_callback("luaotfload.patch_font_unsafe", "simple", dummy_function) - ---[[doc-- - - \subsection{\CONTEXT override} - \label{define-font} - We provide a simplified version of the original font definition - callback. +luaotfload.main = function () + local starttime = os.gettimeofday () ---doc]]-- + luaotfload.loaders = load_luaotfload_module "loaders" --- Font loading; callbacks + luaotfload.loaders.install () + load_luaotfload_module "database" --- Font management. + load_luaotfload_module "colors" --- Per-font colors. -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 + luaotfload.resolvers = load_luaotfload_module "resolvers" --- Font lookup + luaotfload.resolvers.install () - 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 "<nil>") - logreport ("both", 0, "main", " > fontname %q", result.fontname or "<nil>") - logreport ("both", 0, "main", " > fullname %q", result.fullname or "<nil>") - return result - end + if not config.actions.reconfigure () then + logreport ("log", 0, "load", "Post-configuration hooks failed.") end - definers.patch = patch - definers.generic = read - definers.info_patch = mk_info "patch" - definers.info_generic = mk_info "generic" -end - -reset_callback "define_font" - ---[[doc-- + load_luaotfload_module "features" --- font request and feature handling + load_luaotfload_module "letterspace" --- extra character kerning + load_luaotfload_module "auxiliary" --- additional high-level functionality - Finally we register the callbacks. + luaotfload.aux.start_rewrite_fontname () --- to be migrated to fontspec ---doc]]-- - -local definer = config.luaotfload.run.definer -add_to_callback ("define_font", definers[definer], "luaotfload.define_font", 1) - -load_luaotfload_module "features" --- font request and feature handling -load_luaotfload_module "letterspace" --- extra character kerning -load_luaotfload_module "auxiliary" --- additional high-level functionality - -luaotfload.aux.start_rewrite_fontname () --- to be migrated to fontspec - -luaotfload.main = function () - local starttime = os.gettimeofday () - --- XXX stub logreport ("both", 0, "main", "initialization completed in %0.3f seconds", os.gettimeofday() - starttime) |