summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2015-09-27 20:17:02 +0200
committerPhilipp Gesang <phg@phi-gamma.net>2015-09-27 20:17:02 +0200
commit780113609ffbb146c1b5a825cb25025246cdba2a (patch)
tree85e56e44170fe128e288de0031bdd60b1884ff3e
parent1497cfdbee7193ab84f87daa6229b54be3209cd4 (diff)
downloadluaotfload-780113609ffbb146c1b5a825cb25025246cdba2a.tar.gz
[main, *] convert for centralized initialization routine
-rw-r--r--src/luaotfload-colors.lua78
-rw-r--r--src/luaotfload-configuration.lua4
-rw-r--r--src/luaotfload-database.lua6
-rw-r--r--src/luaotfload-features.lua81
-rw-r--r--src/luaotfload-init.lua2
-rw-r--r--src/luaotfload-loaders.lua2
-rw-r--r--src/luaotfload-main.lua96
7 files changed, 157 insertions, 112 deletions
diff --git a/src/luaotfload-colors.lua b/src/luaotfload-colors.lua
index 89884b6..a0b80bd 100644
--- a/src/luaotfload-colors.lua
+++ b/src/luaotfload-colors.lua
@@ -19,8 +19,7 @@ explanation: http://tug.org/pipermail/luatex/2013-May/004305.html
--doc]]--
-local log = luaotfload.log
-local logreport = log.report
+local logreport = luaotfload and luaotfload.log.report or print
local nodedirect = node.direct
local newnode = nodedirect.new
@@ -44,10 +43,7 @@ local texsettoks = tex.settoks
local texgettoks = tex.gettoks
local stringformat = string.format
-
-local otffeatures = fonts.constructors.newfeatures("otf")
local identifiers = fonts.hashes.identifiers
-local registerotffeature = otffeatures.register
local add_color_callback --[[ this used to be a global‽ ]]
@@ -101,36 +97,6 @@ local sanitize_color_expression = function (digits)
return sanitized
end
---[[doc--
-``setcolor`` modifies tfmdata.properties.color in place
---doc]]--
-
---- fontobj -> string -> unit
----
---- (where “string” is a rgb value as three octet
---- hexadecimal, with an optional fourth transparency
---- value)
----
-local setcolor = function (tfmdata, value)
- local sanitized = sanitize_color_expression(value)
- local properties = tfmdata.properties
-
- if sanitized then
- properties.color = sanitized
- add_color_callback()
- end
-end
-
-registerotffeature {
- name = "color",
- description = "color",
- initializers = {
- base = setcolor,
- node = setcolor,
- }
-}
-
-
--- something is carried around in ``res``
--- for later use by color_handler() --- but what?
@@ -377,5 +343,47 @@ add_color_callback = function ( )
end
end
+--[[doc--
+``setcolor`` modifies tfmdata.properties.color in place
+--doc]]--
+
+--- fontobj -> string -> unit
+---
+--- (where “string” is a rgb value as three octet
+--- hexadecimal, with an optional fourth transparency
+--- value)
+---
+local setcolor = function (tfmdata, value)
+ local sanitized = sanitize_color_expression(value)
+ local properties = tfmdata.properties
+
+ if sanitized then
+ properties.color = sanitized
+ add_color_callback()
+ end
+end
+
+return {
+ init = function ()
+ logreport = luaotfload.log.report
+ if not fonts then
+ logreport ("log", 0, "color",
+ "OTF mechanisms missing -- did you forget to \z
+ load a font loader?")
+ return false
+ end
+ fonts.handlers.otf.features.register {
+ name = "color",
+ description = "color",
+ initializers = {
+ base = setcolor,
+ node = setcolor,
+ }
+ }
+ return true
+ end
+}
+
+
-- vim:tw=71:sw=4:ts=4:expandtab
diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua
index 263c8ad..86a302e 100644
--- a/src/luaotfload-configuration.lua
+++ b/src/luaotfload-configuration.lua
@@ -919,6 +919,10 @@ return {
reconfigure = reconfigure,
dump = dump,
}
+ if not apply_defaults () then
+ logreport ("log", 0, "load",
+ "Configuration unsuccessful: error loading default settings.")
+ end
return true
end
}
diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua
index d9d7594..4af2451 100644
--- a/src/luaotfload-database.lua
+++ b/src/luaotfload-database.lua
@@ -3491,9 +3491,8 @@ return {
--- the font loader namespace is “fonts”, same as in Context
--- we need to put some fallbacks into place for when running
--- as a script
- log = luaotfload.log
- logreport = log.report
- fonts = fonts or { }
+ if not fonts then return false end
+ logreport = luaotfload.log.report
local fonts = fonts
fonts.names = fonts.names or names
fonts.definers = fonts.definers or { }
@@ -3504,6 +3503,7 @@ return {
names.lookups = nil --- contains the lookup cache
for sym, ref in next, export do names[sym] = ref end
+ return true
end
}
diff --git a/src/luaotfload-features.lua b/src/luaotfload-features.lua
index 9b895ce..6fb2114 100644
--- a/src/luaotfload-features.lua
+++ b/src/luaotfload-features.lua
@@ -921,24 +921,13 @@ end
---[[ end included font-ltx.lua ]]
---[[doc--
-This uses the code from luatex-fonts-merged (<- font-otc.lua) instead
-of the removed luaotfload-font-otc.lua.
-
-TODO find out how far we get setting features without these lines,
-relying on luatex-fonts only (it *does* handle features somehow, after
-all).
---doc]]--
-
--- we assume that the other otf stuff is loaded already
+-- We assume that the other otf stuff is loaded already; though there’s
+-- another check below during the initialization phase.
---[[ begin snippet from font-otc.lua ]]
local trace_loading = false trackers.register("otf.loading", function(v) trace_loading = v end)
local report_otf = logs.reporter("fonts","otf loading")
-local otf = fonts.handlers.otf
-local registerotffeature = otf.features.register
-
--[[HH--
In the userdata interface we can not longer tweak the loaded font as
@@ -960,7 +949,7 @@ setmetatableindex(types, function(t,k) t[k] = k return k end) -- "key"
local everywhere = { ["*"] = { ["*"] = true } } -- or: { ["*"] = { "*" } }
local noflags = { }
-local function addfeature(data,feature,specifications)
+local function addfeature (data, feature, specifications)
local descriptions = data.descriptions
local resources = data.resources
local lookups = resources.lookups
@@ -1100,26 +1089,9 @@ local function addfeature(data,feature,specifications)
end
end
-
-otf.enhancers.addfeature = addfeature
-
-local extrafeatures = { }
-
-function otf.addfeature(name,specification)
- extrafeatures[name] = specification
-end
-
-local function enhance(data,filename,raw)
- for feature, specification in next, extrafeatures do
- addfeature(data,feature,specification)
- end
-end
-
-otf.enhancers.register("check extra features",enhance)
-
---[[ end snippet from font-otc.lua ]]
-local tlig = {
+local tlig_specification = {
{
type = "substitution",
features = everywhere,
@@ -1167,9 +1139,6 @@ local tlig = {
},
}
-otf.addfeature ("tlig", tlig)
-otf.addfeature ("trep", { })
-
local anum_arabic = { --- these are the same as in font-otc
[0x0030] = 0x0660,
[0x0031] = 0x0661,
@@ -1228,11 +1197,45 @@ local anum_specification = {
},
}
-otf.addfeature ("anum", anum_specification)
+return {
+ init = function ()
+
+ if not fonts and fonts.handlers then
+ logreport ("log", 0, "color",
+ "OTF mechanisms missing -- did you forget to \z
+ load a font loader?")
+ return false
+ end
+
+ local otf = fonts.handlers.otf
-registerotffeature {
- name = "anum",
- description = "arabic digits",
+ local extrafeatures = {
+ tlig = tlig_specification,
+ trep = { },
+ anum = anum_specification,
+ }
+
+ otf.enhancers.register ("check extra features",
+ function (data,filename, raw)
+ for feature, specification in next, extrafeatures do
+ addfeature (data, feature, specification)
+ end
+ end)
+
+ logreport = luaotfload.log.report
+ if not fonts then
+ logreport ("log", 0, "color",
+ "OTF mechanisms missing -- did you forget to \z
+ load a font loader?")
+ return false
+ end
+
+ otf.features.register {
+ name = "anum",
+ description = "arabic digits",
+ }
+ return true
+ end
}
-- vim:tw=71:sw=4:ts=4:expandtab
diff --git a/src/luaotfload-init.lua b/src/luaotfload-init.lua
index a5e5bec..af71cb2 100644
--- a/src/luaotfload-init.lua
+++ b/src/luaotfload-init.lua
@@ -431,6 +431,8 @@ return {
os.gettimeofday() - starttime)
local n = init_post ()
logreport ("both", 5, "init", "post hook terminated, %d actions performed", n)
+ return true
end
}
+-- vim:tw=79:sw=2:ts=2:expandtab
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.")
diff --git a/src/luaotfload-main.lua b/src/luaotfload-main.lua
index 9e57dbf..815a2f0 100644
--- a/src/luaotfload-main.lua
+++ b/src/luaotfload-main.lua
@@ -13,6 +13,9 @@
--- version 2.4 to 2.5. Thus, the comments are still in TeX (Latex)
--- markup.
+local os = os
+local osgettimeofday = os.gettimeofday
+
local initial_log_level = 0
luaotfload = luaotfload or { }
config = config or { }
@@ -125,70 +128,95 @@ local make_loader_name = function (prefix, name)
return name
end
+local timing_info = {
+ t_load = { },
+ t_init = { },
+}
+
local make_loader = function (prefix)
return function (name)
+ local t_0 = osgettimeofday ()
local modname = make_loader_name (prefix, name)
- return require (modname)
+ local data = require (modname)
+ local t_end = osgettimeofday ()
+ timing_info.t_load [name] = t_end - t_0
+ return data
end
end
-local load_luaotfload_module = make_loader "luaotfload"
------ load_luaotfload_module = make_loader "luatex" --=> for Luatex-Plain
-local load_fontloader_module = make_loader "fontloader"
+local install_loaders = function ()
+ local loaders = { }
+ local loadmodule = make_loader "luaotfload"
+ loaders.luaotfload = loadmodule
+ loaders.fontloader = make_loader "fontloader"
+----loaders.plaintex = make_loader "luatex" --=> for Luatex-Plain
+
+ loaders.initialize = function (name)
+ local tmp = loadmodule (name)
+ local logreport = luaotfload.log.report
+ if type (tmp) == "table" then
+ local init = tmp.init
+ if init and type (init) == "function" then
+ local t_0 = osgettimeofday ()
+ if not init () then
+ logreport ("log", 0, "load",
+ "Failed to load module “%s”.", name)
+ return
+ end
+ local t_end = osgettimeofday ()
+ local d_t = t_end - t_0
+ logreport ("log", 4, "load",
+ "Module “%s” loaded in %d ms.",
+ d_t)
+ timing_info.t_init [name] = d_t
+ end
+ end
+ end
-luaotfload.loaders.luaotfload = load_luaotfload_module
-luaotfload.loaders.fontloader = load_fontloader_module
+ return loaders
+end
---[[doc--
- Now we load the modules written for \identifier{luaotfload}.
+luaotfload.main = function ()
---doc]]--
+ luaotfload.loaders = install_loaders ()
+ local loaders = luaotfload.loaders
+ local loadmodule = loaders.luaotfload
+ local initialize = loaders.initialize
-luaotfload.main = function ()
- local starttime = os.gettimeofday ()
- local init = load_luaotfload_module "init" --- fontloader initialization
- local store = init.early () --- injects the log module too
+ local starttime = osgettimeofday ()
+ local init = loadmodule "init" --- fontloader initialization
+ local store = init.early () --- injects the log module too
local logreport = luaotfload.log.report
- local tmp = load_luaotfload_module "parsers" --- fonts.conf and syntax
- if not tmp.init () then
- logreport ("log", 0, "load", "Failed to install the parsers module.")
- end
-
- local tmp = load_luaotfload_module "configuration" --- configuration options
- if not tmp.init() or not config.actions.apply_defaults () then
- logreport ("log", 0, "load", "Configuration unsuccessful.")
- end
+ initialize "parsers" --- fonts.conf and syntax
+ initialize "configuration" --- configuration options
if not init.main (store) then
logreport ("log", 0, "load", "Main fontloader initialization failed.")
end
- luaotfload.loaders = load_luaotfload_module "loaders" --- Font loading; callbacks
- if not luaotfload.loaders.install () then
- logreport ("log", 0, "load", "Callback and loader initialization failed.")
- end
-
- load_luaotfload_module "database" --- Font management.
- load_luaotfload_module "colors" --- Per-font colors.
+ initialize "loaders" --- Font loading; callbacks
+ initialize "database" --- Font management.
+ initialize "colors" --- Per-font colors.
- luaotfload.resolvers = load_luaotfload_module "resolvers" --- Font lookup
+ luaotfload.resolvers = loadmodule "resolvers" --- Font lookup
luaotfload.resolvers.install ()
if not config.actions.reconfigure () then
logreport ("log", 0, "load", "Post-configuration hooks failed.")
end
- load_luaotfload_module "features" --- font request and feature handling
- load_luaotfload_module "letterspace" --- extra character kerning
- load_luaotfload_module "auxiliary" --- additional high-level functionality
+ initialize "features" --- font request and feature handling
+ loadmodule "letterspace" --- extra character kerning
+ loadmodule "auxiliary" --- additional high-level functionality
luaotfload.aux.start_rewrite_fontname () --- to be migrated to fontspec
logreport ("both", 0, "main",
"initialization completed in %0.3f seconds",
- os.gettimeofday() - starttime)
+ osgettimeofday() - starttime)
+----inspect (timing_info)
end
-- vim:tw=79:sw=4:ts=4:et