diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2014-04-22 23:46:48 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2014-04-22 23:46:48 +0200 |
commit | 2237a2bc833d46a1631112fb4c220e3f4941bcc3 (patch) | |
tree | 4da061edfc78ab741ff21506304245c137c0ca05 | |
parent | 3657b9c19c70eb0b52dfa1c67956776a6fd77d4a (diff) | |
download | luaotfload-2237a2bc833d46a1631112fb4c220e3f4941bcc3.tar.gz |
[db,conf,main,tool] move primary configuration table to new configuration model (ignore those initialization stubs for now)
-rw-r--r-- | src/luaotfload-configuration.lua | 160 | ||||
-rw-r--r-- | src/luaotfload-database.lua | 131 | ||||
-rw-r--r-- | src/luaotfload-main.lua | 10 | ||||
-rwxr-xr-x | src/luaotfload-tool.lua | 44 |
4 files changed, 211 insertions, 134 deletions
diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua index d05a48b..aa91b27 100644 --- a/src/luaotfload-configuration.lua +++ b/src/luaotfload-configuration.lua @@ -28,6 +28,9 @@ local table = table local tableappend = table.append local tablecopy = table.copy +local math = math +local mathfloor = math.floor + local io = io local ioloaddata = io.loaddata @@ -76,39 +79,146 @@ local config_paths = { local luaotfload_defaults = { misc = { - bisect = false, - version = luaotfload.version, + bisect = false, + version = luaotfload.version, + termwidth = nil, + statistics = false, }, paths = { - names_dir = "names", - cache_dir = "fonts", - index_file = "luaotfload-names.lua", + names_dir = "names", + cache_dir = "fonts", + index_file = "luaotfload-names.lua", + lookups_file = "luaotfload-lookup-cache.lua", }, db = { - formats = "otf,ttf,ttc,dfont", - reload = false, - strip = true, + formats = "otf,ttf,ttc,dfont", + reload = false, + strip = true, + update_live = true, + compress = true, + scan_local = false, + skip_read = false, }, } ------------------------------------------------------------------------------- +--- RECONFIGURATION TASKS +------------------------------------------------------------------------------- + +--[[doc-- + + Procedures to be executed in order to put the new configuration into effect. + +--doc]]-- + +local reconf_tasks = { } + +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 () + if config.luaotfload.misc.termwidth == nil then + local tw = 79 + if not ( os.type == "windows" --- Assume broken terminal. + or osgetenv "TERM" == "dumb") + then + local p = iopopen "tput cols" + if p then + result = tonumber (p:read "*all") + p:close () + if result then + tw = result + else + logreport ("log", 2, "db", "tput returned non-number.") + end + else + logreport ("log", 2, "db", "Shell escape disabled or tput executable missing.") + logreport ("log", 2, "db", "Assuming 79 cols terminal width.") + end + end + config.luaotfload.misc.termwidth = tw + end + return true +end + +reconf_tasks.set_font_filters = function () + fonts.names.set_font_filter (config.luaotfload.db.formats) + return true +end + +reconf_tasks.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 + end + return true +end + +------------------------------------------------------------------------------- --- OPTION SPECIFICATION ------------------------------------------------------------------------------- local string_t = "string" local table_t = "table" +local number_t = "number" local boolean_t = "boolean" local function_t = "function" +local tointeger = function (n) + n = tonumber (n) + if n then + return mathfloor (n + 0.5) + end +end + local option_spec = { db = { - formats = { in_t = string_t, }, - reload = { in_t = boolean_t, }, - strip = { in_t = boolean_t, }, + formats = { in_t = string_t, }, + reload = { in_t = boolean_t, }, + scan_local = { in_t = boolean_t, }, + skip_read = { in_t = boolean_t, }, + strip = { in_t = boolean_t, }, + update_live = { in_t = boolean_t, }, + compress = { in_t = boolean_t, }, + max_fonts = { + in_t = number_t, + out_t = number_t, --- TODO int_t from 5.3.x on + transform = tointeger, + }, + resolver = { + in_t = string_t, + out_t = string_t, + transform = function (r) + if r == "normal" then + return "normal" + end + return "cached" + end, + } }, misc = { - bisect = { in_t = boolean_t, }, - version = { in_t = string_t, }, + 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) + w = tointeger (w) + if w < min_terminal_width then + return min_terminal_width + end + return w + end, + }, }, paths = { names_dir = { in_t = string_t, }, @@ -248,7 +358,12 @@ local process_options = function (opts) end local apply = function (old, new) - if not old then + if not new then + if not old then + return false + end + return tablecopy (old) + elseif not old then return tablecopy (new) end local result = tablecopy (old) @@ -258,6 +373,16 @@ local apply = function (old, new) return result end +local reconfigure = function () + for i = 1, #reconf_tasks do + local task = reconf_tasks[i] + if not task () then + return false + end + end + return true +end + local read = function (extra) if extra then add_config_paths (extra) @@ -294,7 +419,8 @@ end --- EXPORTS ------------------------------------------------------------------------------- -config.defaults = luaotfload_defaults -config.read = read -config.apply = apply +config.defaults = luaotfload_defaults +config.read = read +config.apply = apply +config.reconfigure = reconfigure diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 013e6e8..3a4b8b4 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -127,16 +127,6 @@ fonts = fonts or { } fonts.names = fonts.names or { } fonts.definers = fonts.definers or { } -local luaotfloadconfig = config.luaotfload --- always present -luaotfloadconfig.resolver = luaotfloadconfig.resolver or "normal" -luaotfloadconfig.formats = luaotfloadconfig.formats or "otf,ttf,ttc,dfont" -luaotfloadconfig.strip = luaotfloadconfig.strip == true - ---- this option allows for disabling updates ---- during a TeX run -luaotfloadconfig.update_live = luaotfloadconfig.update_live ~= false -luaotfloadconfig.compress = luaotfloadconfig.compress ~= false - local names = fonts.names local name_index = nil --> upvalue for names.data local lookup_cache = nil --> for names.lookups @@ -145,13 +135,6 @@ names.data = nil --- contains the loaded database names.lookups = nil --- contains the lookup cache names.path = { index = { }, lookups = { } } -names.path.globals = { - prefix = "", --- writable_path/names_dir - names_dir = luaotfloadconfig.names_dir or "names", - index_file = luaotfloadconfig.index_file - or "luaotfload-names.lua", - lookups_file = "luaotfload-lookup-cache.lua", -} --- string -> (string * string) local make_luanames = function (path) @@ -159,31 +142,6 @@ local make_luanames = function (path) filereplacesuffix(path, "luc") end ---- The “termwidth” value is only considered when printing ---- short status messages, e.g. when building the database ---- online. -if not luaotfloadconfig.termwidth then - local tw = 79 - if not ( os.type == "windows" --- Assume broken terminal. - or osgetenv "TERM" == "dumb") - then - local p = iopopen "tput cols" - if p then - result = tonumber (p:read "*all") - p:close () - if result then - tw = result - else - report ("log", 2, "db", "tput returned non-number.") - end - else - report ("log", 2, "db", "Shell escape disabled or tput executable missing.") - report ("log", 2, "db", "Assuming 79 cols terminal width.") - end - end - luaotfloadconfig.termwidth = tw -end - local format_precedence = { "otf", "ttc", "ttf", "dfont", "afm", "pfb", @@ -211,34 +169,35 @@ end created by different user. --doc]]-- -if not runasscript then - local globals = names.path.globals - local names_dir = globals.names_dir +--- XXX this belongs into the initialization file! +local initialize_env = function () + if not runasscript then + local paths = config.luaotfload.paths - prefix = getwritablepath (names_dir, "") - if not prefix then - luaotfload.error - ("Impossible to find a suitable writeable cache...") - else - prefix = lpegmatch (stripslashes, prefix) - report ("log", 0, "db", - "Root cache directory is %s.", prefix) - end + local prefix = getwritablepath (paths.names_dir, "") + if not prefix then + luaotfload.error + ("Impossible to find a suitable writeable cache...") + else + prefix = lpegmatch (stripslashes, prefix) + report ("log", 0, "db", + "Root cache directory is %s.", prefix) + end - globals.prefix = prefix - local lookup_path = names.path.lookups - local index = names.path.index - local lookups_file = filejoin (prefix, globals.lookups_file) - local index_file = filejoin (prefix, globals.index_file) - lookup_path.lua, lookup_path.luc = make_luanames (lookups_file) - index.lua, index.luc = make_luanames (index_file) -else --- running as script, inject some dummies - caches = { } - local dummy_function = function () end - log = { report = dummy_function, - report_status = dummy_function, - report_status_start = dummy_function, - report_status_stop = dummy_function, } + local lookup_path = names.path.lookups + local index = names.path.index + 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) + else --- running as script, inject some dummies + caches = { } + local dummy_function = function () end + log = { report = dummy_function, + report_status = dummy_function, + report_status_start = dummy_function, + report_status_stop = dummy_function, } + end end @@ -2072,9 +2031,6 @@ do get_font_filter = function (formats) return tablefastcopy (current_formats) end - - --- initialize - set_font_filter (luaotfloadconfig.formats) end local process_dir_tree @@ -2177,7 +2133,7 @@ end --- indicates the number of characters already consumed on the --- line. local truncate_string = function (str, restrict) - local tw = luaotfloadconfig.termwidth + local tw = config.luaotfload.misc.termwidth local wd = tw - restrict local len = utf8len (str) if wd - len < 0 then @@ -2670,7 +2626,7 @@ local pull_values = function (entry) entry.splitstyle = style.split entry.weight = style.weight - if luaotfloadconfig.strip == true then + if config.luaotfload.db.strip == true then entry.file = nil entry.names = nil entry.style = nil @@ -2931,12 +2887,12 @@ local collect_font_filenames = function () report ("info", 4, "db", "Scanning the filesystem for font files.") local filenames = { } - local bisect = luaotfloadconfig.bisect - local max_fonts = luaotfloadconfig.max_fonts or 2^51 --- XXX revisit for lua 5.3 wrt integers + 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 tableappend (filenames, collect_font_filenames_texmf ()) tableappend (filenames, collect_font_filenames_system ()) - if luaotfloadconfig.scan_local == true then + if config.luaotfload.db.scan_local == true then tableappend (filenames, collect_font_filenames_local ()) end --- Now drop everything above max_fonts. @@ -3175,7 +3131,7 @@ end update_names = function (currentnames, force, dry_run) local targetnames - if luaotfloadconfig.update_live == false then + if config.luaotfload.db.update_live == false then report ("info", 2, "db", "Skipping database update.") --- skip all db updates @@ -3192,7 +3148,7 @@ update_names = function (currentnames, force, dry_run) report("both", 1, "db", "Updating the font names database" .. (force and " forcefully." or ".")) - if luaotfloadconfig.skip_read == true then + if config.luaotfload.db.skip_read == true then --- the difference to a “dry run” is that we don’t search --- for font files entirely. we also ignore the “force” --- parameter since it concerns only the font files. @@ -3234,7 +3190,7 @@ update_names = function (currentnames, force, dry_run) end --- pass 3 (optional): collect some stats about the raw font info - if luaotfloadconfig.statistics == true then + if config.luaotfload.misc.statistics == true then targetnames.meta.statistics = collect_statistics (targetnames.mappings) end @@ -3325,7 +3281,7 @@ save_names = function (currentnames) if fileiswritable (luaname) and fileiswritable (lucname) then osremove (lucname) local gzname = luaname .. ".gz" - if luaotfloadconfig.compress then + if config.luaotfload.db.compress then local serialized = tableserialize (currentnames, true) save_gzipped (gzname, serialized) caches.compile (currentnames, "", lucname) @@ -3443,7 +3399,7 @@ end local getwritablecachepath = function ( ) --- fonts.handlers.otf doesn’t exist outside a Luatex run, --- so we have to improvise - local writable = getwritablepath (luaotfloadconfig.cache_dir) + local writable = getwritablepath (config.luaotfload.paths.cache_dir) if writable then return writable end @@ -3451,7 +3407,7 @@ end local getreadablecachepaths = function ( ) local readables = caches.getreadablepaths - (luaotfloadconfig.cache_dir) + (config.luaotfload.paths.cache_dir) local result = { } if readables then for i=1, #readables do @@ -3516,6 +3472,7 @@ end --- export functionality to the namespace “fonts.names” ----------------------------------------------------------------------- +names.initialize_env = initialize_env names.set_font_filter = set_font_filter names.flush_lookup_cache = flush_lookup_cache names.save_lookups = save_lookups @@ -3538,16 +3495,6 @@ names.purge_cache = purge_cache names.erase_cache = erase_cache names.show_cache = show_cache ---- replace the resolver from luatex-fonts -if luaotfloadconfig.resolver == "cached" then - report("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 -end - names.find_closest = find_closest -- for testing purpose diff --git a/src/luaotfload-main.lua b/src/luaotfload-main.lua index fe4e792..495001b 100644 --- a/src/luaotfload-main.lua +++ b/src/luaotfload-main.lua @@ -431,10 +431,12 @@ 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 "database.lua" --- “font-nms” -loadmodule "colors.lua" --- “font-clr” +loadmodule "parsers.lua" --- new in 2.5; fonts.conf and syntax +loadmodule "loaders.lua" --- “font-pfb” new in 2.0, added 2011 +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” --[[doc-- diff --git a/src/luaotfload-tool.lua b/src/luaotfload-tool.lua index 9b06ba9..04fa67d 100755 --- a/src/luaotfload-tool.lua +++ b/src/luaotfload-tool.lua @@ -93,8 +93,7 @@ require(loader_path) config = config or { } local config = config -local luaotfloadconfig = config.luaotfload or { } -config.luaotfload = luaotfloadconfig +config.luaotfload = config.luaotfload or { } config.lualibs = config.lualibs or { } config.lualibs.verbose = false @@ -144,17 +143,12 @@ require "alt_getopt" local names = fonts.names local status_file = "luaotfload-status" local luaotfloadstatus = require (status_file) -luaotfloadconfig.status = luaotfloadstatus +config.luaotfload.status = luaotfloadstatus local sanitize_fontname = names.sanitize_fontname local log = luaotfload.log local report = log.report -local pathdata = names.path -local names_plain = pathdata.index.lua -local names_gzip = names_plain .. ".gz" -local names_bin = pathdata.index.luc - local help_messages = { ["luaotfload-tool"] = [[ @@ -249,14 +243,19 @@ Enter 'luaotfload-tool --help' for a larger list of options. } local help_msg = function (version) - local template = help_messages[version] + local template = help_messages[version] + local pathdata = names.path + local paths = config.luaotfload.paths + local names_plain = paths.index.lua + local names_gzip = names_plain .. ".gz" + local names_bin = paths.index.luc + iowrite(stringformat(template, luaotfload.self, -- names_plain, names_gzip, names_bin, - caches.getwritablepath ( - luaotfloadconfig.cache_dir))) + caches.getwritablepath (config.luaotfload.cache_dir))) end local about = [[ @@ -748,12 +747,15 @@ actions.config = function (job) local defaults = luaotfload.config.defaults local vars = luaotfload.config.read (job.extra_config) config.luaotfload = luaotfload.config.apply (defaults, vars) - --if job.print_config == true then - if true then + + if luaotfload.config.reconfigure () then --inspect (vars) inspect (config.luaotfload) return true, false + else + return false, false end + names.initialize_env () return true, true end @@ -1056,7 +1058,7 @@ local bisect_run = function () nsteps, lo, hi, pivot) report ("info", 1, "bisect", "Step %d: Testing fonts from %d to %d.", currentstep, lo, pivot) - luaotfloadconfig.bisect = { lo, pivot } + config.luaotfload.misc.bisect = { lo, pivot } return true, true end @@ -1482,7 +1484,7 @@ local process_cmdline = function ( ) -- unit -> jobspec action_pending["flush"] = true elseif v == "L" then action_pending["generate"] = true - luaotfloadconfig.scan_local = true + config.luaotfload.db.scan_local = true elseif v == "list" then action_pending["list"] = true result.criterion = optarg[n] @@ -1505,22 +1507,22 @@ local process_cmdline = function ( ) -- unit -> jobspec elseif v == "formats" then names.set_font_filter (optarg[n]) elseif v == "n" then - luaotfloadconfig.update_live = false + config.luaotfload.db.update_live = false elseif v == "S" then - luaotfloadconfig.statistics = true + config.luaotfload.misc.statistics = true elseif v == "R" then --- dev only, undocumented - luaotfloadconfig.skip_read = true + config.luaotfload.db.skip_read = true elseif v == "c" then - luaotfloadconfig.compress = false + config.luaotfload.db.compress = false elseif v == "no-strip" then - luaotfloadconfig.strip = false + config.luaotfload.db.strip = false elseif v == "max-fonts" then local n = optarg[n] if n then n = tonumber(n) if n and n > 0 then - luaotfloadconfig.max_fonts = n + config.luaotfload.db.max_fonts = n end end elseif v == "bisect" then |