diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2014-04-24 23:29:52 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2014-04-24 23:29:52 +0200 |
commit | 226a72e66462faeaa5052cfd8aed6011d2545247 (patch) | |
tree | 3315f46d66a39bbcceef56263bd550ac5f9d3926 /src | |
parent | ff15eeb08a3148f961b0535ee2fea7ceea85bc1a (diff) | |
download | luaotfload-226a72e66462faeaa5052cfd8aed6011d2545247.tar.gz |
[colors,conf,db,main,tool] adapt the TeX run code to new configuration
Diffstat (limited to 'src')
-rw-r--r-- | src/luaotfload-colors.lua | 2 | ||||
-rw-r--r-- | src/luaotfload-configuration.lua | 155 | ||||
-rw-r--r-- | src/luaotfload-database.lua | 7 | ||||
-rw-r--r-- | src/luaotfload-main.lua | 100 | ||||
-rwxr-xr-x | src/luaotfload-tool.lua | 28 |
5 files changed, 168 insertions, 124 deletions
diff --git a/src/luaotfload-colors.lua b/src/luaotfload-colors.lua index d999df6..56acfee 100644 --- a/src/luaotfload-colors.lua +++ b/src/luaotfload-colors.lua @@ -20,7 +20,7 @@ explanation: http://tug.org/pipermail/luatex/2013-May/004305.html --doc]]-- -local color_callback = config.luaotfload.color_callback +local color_callback = config.luaotfload.run.color_callback if not color_callback then --- maybe this would be better as a method: "early" | "late" color_callback = "pre_linebreak_filter" diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua index fed003e..93a358f 100644 --- a/src/luaotfload-configuration.lua +++ b/src/luaotfload-configuration.lua @@ -18,7 +18,8 @@ if not modules then modules = { } end modules ["luaotfload-configuration"] = { } luaotfload = luaotfload or { } -luaotfload.config = luaotfload.config or { } +config = config or { } +config.luaotfload = { } local string = string local stringsub = string.sub @@ -33,6 +34,7 @@ local mathfloor = math.floor local io = io local ioloaddata = io.loaddata +local iopopen = io.popen local os = os local osgetenv = os.getenv @@ -51,7 +53,7 @@ local file = file local filejoin = file.join local parsers = luaotfload.parsers -local config = luaotfload.config + local log = luaotfload.log local logreport = log.report @@ -77,12 +79,28 @@ local config_paths = { --- DEFAULTS ------------------------------------------------------------------------------- -local luaotfload_defaults = { +local default_config = { + db = { + formats = "otf,ttf,ttc,dfont", + reload = false, + scan_local = false, + skip_read = false, + strip = true, + update_live = true, + compress = true, + max_fonts = 2^51, + }, + run = { + resolver = "cached", + definer = "patch", + log_level = 0, + color_callback = "pre_linebreak_filter", + }, misc = { - bisect = false, - version = luaotfload.version, - termwidth = nil, - statistics = false, + bisect = false, + version = luaotfload.version, + statistics = false, + termwidth = nil, }, paths = { names_dir = "names", @@ -90,15 +108,6 @@ local luaotfload_defaults = { index_file = "luaotfload-names.lua", lookups_file = "luaotfload-lookup-cache.lua", }, - db = { - formats = "otf,ttf,ttc,dfont", - reload = false, - strip = true, - update_live = true, - compress = true, - scan_local = false, - skip_read = false, - }, } ------------------------------------------------------------------------------- @@ -111,17 +120,17 @@ local luaotfload_defaults = { --doc]]-- -local reconf_tasks = { } +local reconf_tasks = nil local min_terminal_width = 40 --- The “termwidth” value is only considered when printing --- short status messages, e.g. when building the database --- online. -reconf_tasks.check_termwidth = function () +local check_termwidth = function () if config.luaotfload.misc.termwidth == nil then local tw = 79 - if not ( os.type == "windows" --- Assume broken terminal. + if not ( os.type == "windows" --- Assume broken terminal. or osgetenv "TERM" == "dumb") then local p = iopopen "tput cols" @@ -143,25 +152,42 @@ reconf_tasks.check_termwidth = function () return true end -reconf_tasks.set_font_filters = function () - fonts.names.set_font_filter (config.luaotfload.db.formats) +local set_font_filter = function () + local names = fonts.names + if names and names.set_font_filter then + names.set_font_filter (config.luaotfload.db.formats) + end return true end -reconf_tasks.set_name_resolver = function () +local set_name_resolver = function () local names = fonts.names - --- replace the resolver from luatex-fonts - if config.luaotfload.db.resolver == "cached" then - logreport("both", 2, "cache", "Caching of name: lookups active.") - names.resolvespec = resolve_cached - names.resolve_name = resolve_cached - else - names.resolvespec = resolve_name - names.resolve_name = resolve_name + if names and names.resolve_cached then + --- replace the resolver from luatex-fonts + if config.luaotfload.db.resolver == "cached" then + logreport ("both", 2, "cache", "Caching of name: lookups active.") + names.resolvespec = names.resolve_cached + names.resolve_name = names.resolve_cached + else + names.resolvespec = names.resolve_name + names.resolve_name = names.resolve_name + end end return true end +local set_loglevel = function () + log.set_loglevel (config.luaotfload.run.log_level) + return true +end + +reconf_tasks = { + { "Set the log level" , set_loglevel }, + { "Check terminal dimensions" , check_termwidth }, + { "Set the font filter" , set_font_filter }, + { "Install font name resolver", set_name_resolver }, +} + ------------------------------------------------------------------------------- --- OPTION SPECIFICATION ------------------------------------------------------------------------------- @@ -193,22 +219,37 @@ local option_spec = { out_t = number_t, --- TODO int_t from 5.3.x on transform = tointeger, }, - resolver = { + }, + run = { + resolver = { in_t = string_t, out_t = string_t, - transform = function (r) - if r == "normal" then - return "normal" - end - return "cached" + transform = function (r) return r == "normal" and r or "cached" end, + }, + definer = { + in_t = string_t, + out_t = string_t, + transform = function (d) return d == "generic" and d or "patch" end, + }, + log_level = { + in_t = number_t, + out_t = number_t, --- TODO int_t from 5.3.x on + transform = tointeger, + }, + color_callback = { + in_t = string_t, + out_t = string_t, + transform = function (cb) + --- These are the two that make sense. + return cb == "pre_output_filter" and cb or "pre_linebreak_filter" end, - } + }, }, misc = { - bisect = { in_t = boolean_t, }, --- doesn’t make sense in a config file - version = { in_t = string_t, }, - statistics = { in_t = boolean_t, }, - termwidth = { + bisect = { in_t = boolean_t, }, --- doesn’t make sense in a config file + version = { in_t = string_t, }, + statistics = { in_t = boolean_t, }, + termwidth = { in_t = number_t, out_t = number_t, transform = function (w) @@ -221,9 +262,10 @@ local option_spec = { }, }, paths = { - names_dir = { in_t = string_t, }, - cache_dir = { in_t = string_t, }, - index_file = { in_t = string_t, }, + names_dir = { in_t = string_t, }, + cache_dir = { in_t = string_t, }, + index_file = { in_t = string_t, }, + lookups_file = { in_t = string_t, }, }, } @@ -251,7 +293,6 @@ local tilde_expand = function (p) end local resolve_config_path = function () - inspect (config_paths) for i = 1, #config_paths do local t, p = unpack (config_paths[i]) local fullname @@ -387,8 +428,10 @@ end local reconfigure = function () for i = 1, #reconf_tasks do - local task = reconf_tasks[i] + local name, task = unpack (reconf_tasks[i]) + logreport ("both", 3, "conf", "Launch post-configuration task %q.", name) if not task () then + logreport ("both", 0, "conf", "Post-configuration task %q failed.", name) return false end end @@ -427,12 +470,24 @@ local read = function (extra) return ret end +local apply_defaults = function () + local defaults = default_config + local vars = read () + --- Side-effects galore ... + config.luaotfload = apply (defaults, vars) + return reconfigure () +end + ------------------------------------------------------------------------------- --- EXPORTS ------------------------------------------------------------------------------- -config.defaults = luaotfload_defaults -config.read = read -config.apply = apply -config.reconfigure = reconfigure +luaotfload.default_config = default_config + +config.actions = { + read = read, + apply = apply, + apply_defaults = apply_defaults, + reconfigure = reconfigure, +} diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 3a4b8b4..6b59aac 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -172,8 +172,7 @@ end --- XXX this belongs into the initialization file! local initialize_env = function () if not runasscript then - local paths = config.luaotfload.paths - + local paths = config.luaotfload.paths local prefix = getwritablepath (paths.names_dir, "") if not prefix then luaotfload.error @@ -189,7 +188,7 @@ local initialize_env = function () local lookups_file = filejoin (prefix, paths.lookups_file) local index_file = filejoin (prefix, paths.index_file) lookup_path.lua, lookup_path.luc = make_luanames (lookups_file) - index.lua, index.luc = make_luanames (index_file) + index.lua, index.luc = make_luanames (index_file) else --- running as script, inject some dummies caches = { } local dummy_function = function () end @@ -2888,7 +2887,7 @@ local collect_font_filenames = function () local filenames = { } local bisect = config.luaotfload.misc.bisect - local max_fonts = config.luaotfload.db.max_fonts or 2^51 --- XXX revisit for lua 5.3 wrt integers + local max_fonts = config.luaotfload.db.max_fonts --- XXX revisit for lua 5.3 wrt integers tableappend (filenames, collect_font_filenames_texmf ()) tableappend (filenames, collect_font_filenames_system ()) diff --git a/src/luaotfload-main.lua b/src/luaotfload-main.lua index 495001b..836768a 100644 --- a/src/luaotfload-main.lua +++ b/src/luaotfload-main.lua @@ -43,30 +43,12 @@ if not modules then modules = { } end modules ["luaotfload-main"] = { --doc]]-- +local initial_log_level = 0 + luaotfload = luaotfload or { } local luaotfload = luaotfload luaotfload.log = luaotfload.log or { } -config = config or { } -config.luaotfload = config.luaotfload or { } -local luaotfloadconfig = config.luaotfload -----------------.resolver = luaotfloadconfig.resolver or "normal" -luaotfloadconfig.resolver = luaotfloadconfig.resolver or "cached" -luaotfloadconfig.definer = luaotfloadconfig.definer or "patch" -luaotfloadconfig.bisect = false --- useless when running TeX -luaotfloadconfig.loglevel = luaotfloadconfig.loglevel or 2 -luaotfloadconfig.color_callback = luaotfloadconfig.color_callback or "pre_linebreak_filter" -luaotfloadconfig.prioritize = luaotfloadconfig.prioritize or "sys" -luaotfloadconfig.names_dir = luaotfloadconfig.names_dir or "names" -luaotfloadconfig.cache_dir = luaotfloadconfig.cache_dir or "fonts" -luaotfloadconfig.index_file = luaotfloadconfig.index_file or "luaotfload-names.lua" -luaotfloadconfig.formats = luaotfloadconfig.formats or "otf,ttf,ttc,dfont" -luaotfloadconfig.scan_local = luaotfloadconfig.scan_local == true - -if luaotfloadconfig.strip == nil then - luaotfloadconfig.strip = true -end - luaotfload.module = { name = "luaotfload", version = 2.50000, @@ -90,7 +72,7 @@ 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 --- 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) @@ -146,14 +128,17 @@ end local fl_prefix = "luaotfload" -- “luatex” for luatex-plain local loadmodule = function (name) - require(fl_prefix .."-"..name) + require (fl_prefix .."-"..name) end -loadmodule "log.lua" --- messages; used to be part of -override +loadmodule "log.lua" --- log messages +--loadmodule "parsers.lua" --- new in 2.5; fonts.conf and syntax +--loadmodule "configuration.lua" --- configuration options + local log = luaotfload.log local report = log.report -log.set_loglevel(luaotfloadconfig.loglevel) +log.set_loglevel (default_log_level) --[[doc-- @@ -216,8 +201,7 @@ end --doc]]-- -local starttime = os.gettimeofday() - +local starttime = os.gettimeofday () local trapped_register = callback.register callback.register = dummy_function @@ -431,12 +415,22 @@ loadmodule "override.lua" --- load glyphlist on demand Now we load the modules written for \identifier{luaotfload}. --doc]]-- -loadmodule "parsers.lua" --- new in 2.5; fonts.conf and syntax -loadmodule "loaders.lua" --- “font-pfb” new in 2.0, added 2011 + +loadmodule "parsers.lua" --- fonts.conf and syntax loadmodule "configuration.lua" --- configuration options -loadmodule "database.lua" --- “font-nms” -names.initialize_env () --- XXX hack hack hack; we need common initialization -loadmodule "colors.lua" --- “font-clr” + +if not config.actions.apply_defaults () then + report ("log", 0, "load", "Configuration unsuccessful.") +end + +loadmodule "loaders.lua" --- Type1 font wrappers +loadmodule "database.lua" --- Font management. +fonts.names.initialize_env () --- XXX hack hack hack; we need common initialization +loadmodule "colors.lua" --- Per-font colors. + +if not config.actions.reconfigure () then + report ("log", 0, "load", "Post-configuration hooks failed.") +end --[[doc-- @@ -673,17 +667,20 @@ create_callback("luaotfload.patch_font", "simple", dummy_function) local read_font_file = fonts.definers.read ---- spec -> size -> id -> tmfdata -local patch_defined_font = function (specification, size, id) - local tfmdata = read_font_file(specification, size, id) - if type(tfmdata) == "table" and tfmdata.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", tfmdata, specification) - end - return tfmdata -end +local definers = { + generic = read_font_file, + --- spec -> size -> id -> tmfdata + patch = function (specification, size, id) + local tfmdata = read_font_file (specification, size, id) + if type (tfmdata) == "table" and tfmdata.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", tfmdata, specification) + end + return tfmdata + end, +} reset_callback "define_font" @@ -693,23 +690,12 @@ reset_callback "define_font" --doc]]-- -local font_definer = luaotfloadconfig.definer - -if font_definer == "generic" then - add_to_callback("define_font", - fonts.definers.read, - "luaotfload.define_font", - 1) -elseif font_definer == "patch" then - add_to_callback("define_font", - patch_defined_font, - "luaotfload.define_font", - 1) -end +local definer = config.luaotfload.run.definer +add_to_callback ("define_font", definers[definer], "luaotfload.define_font", 1) -loadmodule "features.lua" --- contains what was “font-ltx” and “font-otc” +loadmodule "features.lua" --- font request and feature handling loadmodule "letterspace.lua" --- extra character kerning -loadmodule "auxiliary.lua" --- additionaly high-level functionality (new) +loadmodule "auxiliary.lua" --- additional high-level functionality luaotfload.aux.start_rewrite_fontname () --- to be migrated to fontspec diff --git a/src/luaotfload-tool.lua b/src/luaotfload-tool.lua index 04fa67d..f54c1ff 100755 --- a/src/luaotfload-tool.lua +++ b/src/luaotfload-tool.lua @@ -89,11 +89,19 @@ string.quoted = string.quoted or function (str) return string.format("%q",str) end -require(loader_path) +require (loader_path) -config = config or { } -local config = config -config.luaotfload = config.luaotfload or { } +--[[doc-- + + XXX: + Creating the config table will be moved to the common + initialization when the times comes. + +--doc]]-- + +config = config or { } +local config = config +config.luaotfload = config.luaotfload or { } config.lualibs = config.lualibs or { } config.lualibs.verbose = false @@ -744,15 +752,11 @@ actions.loglevel = function (job) end actions.config = function (job) - local defaults = luaotfload.config.defaults - local vars = luaotfload.config.read (job.extra_config) - config.luaotfload = luaotfload.config.apply (defaults, vars) + local defaults = luaotfload.default_config + local vars = config.actions.read (job.extra_config) + config.luaotfload = config.actions.apply (defaults, vars) - if luaotfload.config.reconfigure () then - --inspect (vars) - inspect (config.luaotfload) - return true, false - else + if not config.actions.reconfigure () then return false, false end names.initialize_env () |