diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2016-04-28 22:54:55 +0200 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2016-04-28 22:54:55 +0200 |
commit | f502d52086e6d13fdf27eca02c3df0c13e6351a4 (patch) | |
tree | 61984b135f89e64517fdbce33bee5d0205d5dbc9 /src | |
parent | 6c52ede0dc26bf697e5cf2732dffab7bb8191473 (diff) | |
parent | e8e069a3020df59046a38c2de18c589de928bbbc (diff) | |
download | luaotfload-f502d52086e6d13fdf27eca02c3df0c13e6351a4.tar.gz |
Merge pull request #348 from phi-gamma/master
Implement #263
Diffstat (limited to 'src')
-rw-r--r-- | src/luaotfload-configuration.lua | 58 | ||||
-rw-r--r-- | src/luaotfload-resolvers.lua | 51 | ||||
-rwxr-xr-x | src/luaotfload-tool.lua | 19 |
3 files changed, 102 insertions, 26 deletions
diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua index 92de432..8cdebe0 100644 --- a/src/luaotfload-configuration.lua +++ b/src/luaotfload-configuration.lua @@ -92,6 +92,14 @@ local valid_formats = tabletohash { "otf", "ttc", "ttf", "afm", "pfb" } +local default_anon_sequence = { + "tex", "path", "name" +} + +local valid_resolvers = tabletohash { + "tex", "path", "name", "file", "my" +} + local feature_presets = { arab = tabletohash { "ccmp", "locl", "isol", "fina", "fin2", @@ -198,6 +206,7 @@ local default_config = { use_fontforge = false, }, run = { + anon_sequence = default_anon_sequence, resolver = "cached", definer = "patch", log_level = 0, @@ -502,6 +511,45 @@ local option_spec = { use_fontforge = { in_t = boolean_t, }, }, run = { + anon_sequence = { + in_t = string_t, + out_t = table_t, + transform = function (s) + if s ~= "default" then + local bits = { lpegmatch (commasplitter, s) } + if next (bits) then + local seq = { } + local done = { } + for i = 1, #bits do + local bit = bits [i] + if valid_resolvers [bit] then + if not done [bit] then + done [bit] = true + seq [#seq + 1] = bit + else + logreport ("both", 0, "conf", + "ignoring duplicate resolver %s at position %d \z + in lookup sequence", + bit, i) + end + else + logreport ("both", 0, "conf", + "lookup sequence contains invalid item %s \z + at position %d.", + bit, i) + end + end + if next (seq) then + logreport ("both", 2, "conf", + "overriding anon lookup sequence %s.", + tableconcat (seq, ",")) + return seq + end + end + end + return default_anon_sequence + end + }, live = { in_t = boolean_t, }, --- false for the tool, true for TeX run resolver = { in_t = string_t, @@ -639,6 +687,15 @@ local format_keyval = function (var, val) end end +local format_list = function (var, val) + local elts = { } + for i = 1, #val do elts [i] = val [i] end + if next (elts) then + return stringformat (indent .. "%s = %s", + var, tableconcat (elts, ",")) + end +end + local format_section = function (title) return stringformat ("[%s]", dashed (title)) end @@ -693,6 +750,7 @@ local formatters = { lookups_file = { false, format_string }, }, run = { + anon_sequence = { false, format_list }, color_callback = { false, format_string }, definer = { false, format_string }, fontloader = { false, format_string }, diff --git a/src/luaotfload-resolvers.lua b/src/luaotfload-resolvers.lua index ee3b597..a1e702b 100644 --- a/src/luaotfload-resolvers.lua +++ b/src/luaotfload-resolvers.lua @@ -29,6 +29,7 @@ if not luaotfload then error "this module requires Luaotfload" end --doc]]-- local next = next +local tableconcat = table.concat local kpsefind_file = kpse.find_file local lfsisfile = lfs.isfile local stringlower = string.lower @@ -195,24 +196,39 @@ local resolve_path_if_exists = function (specification) return false end +--[[doc-- + Custom file resolvers via callback. +--doc]]-- + +local resolve_my = function (specification) + luatexbase.call_callback ("luaotfload.resolve_font", specification) +end + local resolve_methods = { tex = resolve_tex_format, path = resolve_path_if_exists, name = resolve_name, + file = resolve_file, + my = resolve_my, } local resolve_sequence = function (seq, specification) for i = 1, #seq do local id = seq [i] local mth = resolve_methods [id] - logreport ("both", 3, "resolve", "step %d: apply method %q (%s)", i, id, mth) - if mth (specification) == true then - logreport ("both", 3, "resolve", - "%d: method %q resolved %q -> %s (%s).", - i, id, specification.specification, - specification.name, - specification.forcedname) - return true + if not mth then + logreport ("both", 0, "resolve", + "step %d: invalid lookup method %q", i, id) + else + logreport ("both", 3, "resolve", "step %d: apply method %q (%s)", i, id, mth) + if mth (specification) == true then + logreport ("both", 3, "resolve", + "%d: method %q resolved %q -> %s (%s).", + i, id, specification.specification, + specification.name, + specification.forcedname) + return true + end end end logreport ("both", 0, "resolve", @@ -226,7 +242,14 @@ local default_anon_sequence = { local resolve_anon resolve_anon = function (specification) - return resolve_sequence (default_anon_sequence, specification) + local seq = default_anon_sequence + if config and config.luaotfload then + local anonseq = config.luaotfload.run.anon_sequence + if anonseq and next (anonseq) then + seq = anonseq + end + end + return resolve_sequence (seq, specification) end --[[doc-- @@ -259,16 +282,6 @@ resolve_kpse = function (specification) return false end ---[[doc-- - - Also {\bfseries EXPERIMENTAL}: custom file resolvers via callback. - ---doc]]-- - -local resolve_my = function (specification) - luatexbase.call_callback ("luaotfload.resolve_font", specification) -end - return { init = function ( ) if luatexbase and luatexbase.create_callback then diff --git a/src/luaotfload-tool.lua b/src/luaotfload-tool.lua index 4b4dc50..376aa39 100755 --- a/src/luaotfload-tool.lua +++ b/src/luaotfload-tool.lua @@ -1160,16 +1160,21 @@ actions.query = function (job) tmpspec.size = 655360 --- assume 10pt end - local foundname, subfont, success + local foundname, subfont, success, needle - if tmpspec.lookup == "name" - or tmpspec.lookup == "anon" --- not *exactly* as resolvers.anon - then - foundname, _, success = fonts.names.lookup_font_name (tmpspec) - if foundname then - foundname, _, success = fonts.names.lookup_font_file (foundname) + if tmpspec.lookup == "name" then + if fonts.definers.resolvers.name (tmpspec) then + needle = tmpspec.resolved + end + elseif tmpspec.lookup == "anon" then + if fonts.definers.resolvers.anon (tmpspec) then + needle = tmpspec.resolved or tmpspec.name end elseif tmpspec.lookup == "file" then + needle = tmpspec.name + end + + if needle then foundname, _, success = fonts.names.lookup_font_file (tmpspec.name) end |