From 619d652ec4e23339ed0db2c68dafcbfbcdf90b08 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 28 Apr 2016 21:22:58 +0200 Subject: [conf,resolvers] add config option to tweak anon lookup sequence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements #263 The resolvers have already been decoupled a while ago but the goal of allowing the sequence to be reordered at will was still outstanding. Add a config option “anon-sequence” that is parsed as a comma-delimited list of sequence components. --- src/luaotfload-configuration.lua | 31 +++++++++++++++++++++++++++++++ src/luaotfload-resolvers.lua | 10 +++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua index 92de432..a15474c 100644 --- a/src/luaotfload-configuration.lua +++ b/src/luaotfload-configuration.lua @@ -92,6 +92,10 @@ local valid_formats = tabletohash { "otf", "ttc", "ttf", "afm", "pfb" } +local default_anon_sequence = { + "tex", "path", "name", +} + local feature_presets = { arab = tabletohash { "ccmp", "locl", "isol", "fina", "fin2", @@ -198,6 +202,7 @@ local default_config = { use_fontforge = false, }, run = { + anon_sequence = default_anon_sequence, resolver = "cached", definer = "patch", log_level = 0, @@ -502,6 +507,22 @@ 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 + logreport ("both", 2, "conf", + "overriding anon lookup sequence %s.", + tableconcat (bits, ",")) + return bits + 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 +660,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 +723,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..f911101 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 @@ -226,7 +227,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-- -- cgit v1.2.3 From 2727f911e924b77af85c60aacff82517cf70ca84 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 28 Apr 2016 21:34:54 +0200 Subject: [conf] handle corner cases when assigning the lookup sequence --- src/luaotfload-configuration.lua | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua index a15474c..abc2657 100644 --- a/src/luaotfload-configuration.lua +++ b/src/luaotfload-configuration.lua @@ -96,6 +96,8 @@ local default_anon_sequence = { "tex", "path", "name", } +local valid_resolvers = tabletohash (default_anon_sequence) + local feature_presets = { arab = tabletohash { "ccmp", "locl", "isol", "fina", "fin2", @@ -514,10 +516,33 @@ local option_spec = { if s ~= "default" then local bits = { lpegmatch (commasplitter, s) } if next (bits) then - logreport ("both", 2, "conf", - "overriding anon lookup sequence %s.", - tableconcat (bits, ",")) - return bits + 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 -- cgit v1.2.3 From 2db9e17e57e306bde452c5d97f976b47b0bf9d78 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 28 Apr 2016 21:57:55 +0200 Subject: [tool,resolvers,conf] switch --find lookups to the actual resolvers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The arguments to “--find” on the command line avoided calling the real index API functions and used crude approximations instead. In order to make “--find” obey the new “anon-sequence” configuration item, it needs to access the normal resolvers instead. This requires certain adaptations to allow for a fallback on the “file:” lookup. --- src/luaotfload-configuration.lua | 6 ++++-- src/luaotfload-resolvers.lua | 22 ++++++++++++++-------- src/luaotfload-tool.lua | 19 ++++++++++++------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua index abc2657..17aee85 100644 --- a/src/luaotfload-configuration.lua +++ b/src/luaotfload-configuration.lua @@ -93,10 +93,12 @@ local valid_formats = tabletohash { } local default_anon_sequence = { - "tex", "path", "name", + "tex", "path", "name" } -local valid_resolvers = tabletohash (default_anon_sequence) +local valid_resolvers = tabletohash { + "tex", "path", "name", "file" +} local feature_presets = { arab = tabletohash { diff --git a/src/luaotfload-resolvers.lua b/src/luaotfload-resolvers.lua index f911101..6fc6ffe 100644 --- a/src/luaotfload-resolvers.lua +++ b/src/luaotfload-resolvers.lua @@ -200,20 +200,26 @@ local resolve_methods = { tex = resolve_tex_format, path = resolve_path_if_exists, name = resolve_name, + file = resolve_file, } 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", 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 -- cgit v1.2.3 From 44973c92caed597ede12de0367947037523d3e65 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 28 Apr 2016 22:10:15 +0200 Subject: =?UTF-8?q?[doc]=20document=20new=20=E2=80=9Canon-sequence?= =?UTF-8?q?=E2=80=9D=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/luaotfload-main.tex | 13 +++++++++---- doc/luaotfload.conf.rst | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/doc/luaotfload-main.tex b/doc/luaotfload-main.tex index 90738de..05c3670 100644 --- a/doc/luaotfload-main.tex +++ b/doc/luaotfload-main.tex @@ -32,7 +32,7 @@ \beginfrontmatter \setdocumenttitle {The \identifier{luaotfload} package} - \setdocumentdate {2016/04/21 v2.7} + \setdocumentdate {2016/04/28 v2.7} \setdocumentauthor {Elie Roux · Khaled Hosny · Philipp Gesang\\ Home: \hyperlink {https://github.com/lualatex/luaotfload}\\ Support: \email {lualatex-dev@tug.org}} @@ -363,9 +363,14 @@ However, they have a broader spectrum of possible interpretations: before anything else, \identifier{luaotfload} attempts to load a traditional \TEX Font Metric (\abbrev{tfm} or \abbrev{ofm}). % -If this fails, it performs a \inlinecode {name:} lookup, which itself will -fall back to a \inlinecode {file:} lookup if no database entry matches -\meta{font name}. +If this fails, it performs a \inlinecode {path:} lookup, which itself will +fall back to a \inlinecode {file:} lookup. +% +Lastly, if none of the above succeeded, attempt to resolve the request as a +\inlinecode {name:} lookup by searching the font index for \meta{font name}. +% +The behavior of this “anonymous” lookup is configurable, see the configuation +manpage for details. Furthermore, \identifier{luaotfload} supports the slashed (shorthand) font style notation from \XETEX. diff --git a/doc/luaotfload.conf.rst b/doc/luaotfload.conf.rst index e7cbccb..3568909 100644 --- a/doc/luaotfload.conf.rst +++ b/doc/luaotfload.conf.rst @@ -6,7 +6,7 @@ Luaotfload configuration file ----------------------------------------------------------------------- -:Date: 2016-04-21 +:Date: 2016-04-28 :Copyright: GPL v2.0 :Version: 2.7 :Manual section: 5 @@ -271,6 +271,8 @@ Section ``run`` +------------------+--------+------------------------------+ | variable | type | default | +------------------+--------+------------------------------+ +| anon-sequence | s | ``"tex,path,name"`` | ++------------------+--------+------------------------------+ | color-callback | s | ``"post_linebreak_filter"`` | +------------------+--------+------------------------------+ | definer | s | ``"patch"`` | @@ -282,6 +284,19 @@ Section ``run`` | fontloader | s | ``"default"`` | +------------------+--------+------------------------------+ +Unqualified font lookups are treated with the flexible “anonymous” +mechanism. This involves a chain of lookups applied successively until +the first one yields a match. By default, the lookup will first search +for TFM fonts using the Kpathsea library. If this wasn’t successful, an +attempt is made at interpreting the request as an absolute path (like +the ``[/path/to/font/foo.ttf]`` syntax) or a file name +(``file:foo.ttf``). Finally, the request is interpreted as a font name +and retrieved from the index (``name:Foo Regular``). This behavior can +be configured by specifying a list as the value to ``anon-sequence``. +Available items are ``tex``, ``path``, ``name`` -- representing the +lookups described above, respectively --, and ``file`` for searching a +filename but not an absolute path. + The ``color-callback`` option determines the stage at which fonts that defined with a ``color=xxyyzz`` feature will be colorized. By default this happens in a ``post_linebreak_filter`` but alternatively the -- cgit v1.2.3 From c306db980b59c03875acebf8a948efe7b7d51b98 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 28 Apr 2016 22:49:58 +0200 Subject: =?UTF-8?q?[resolvers,conf]=20allow=20=E2=80=9Cmy:=E2=80=9D=20look?= =?UTF-8?q?ups=20in=20anon=20sequences?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows to domesticate packages that quite disrespectfully only use “anon:” lookups. Example from the test repo: \documentclass{scrartcl} \usepackage{fontspec} \directlua{ config.luaotfload = config.actions.apply (config.luaotfload, { run = { anon_sequence = { "my" } } }) } \directlua{ luatexbase.add_to_callback( "luaotfload.resolve_font", function (spec) spec.name = "comic.ttf" end, "user.openbsd_style") } \setmainfont{Adobe Premier Deluxe Overpriced} \begin{document} There is no escape. \end{document} --- src/luaotfload-configuration.lua | 2 +- src/luaotfload-resolvers.lua | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua index 17aee85..8cdebe0 100644 --- a/src/luaotfload-configuration.lua +++ b/src/luaotfload-configuration.lua @@ -97,7 +97,7 @@ local default_anon_sequence = { } local valid_resolvers = tabletohash { - "tex", "path", "name", "file" + "tex", "path", "name", "file", "my" } local feature_presets = { diff --git a/src/luaotfload-resolvers.lua b/src/luaotfload-resolvers.lua index 6fc6ffe..a1e702b 100644 --- a/src/luaotfload-resolvers.lua +++ b/src/luaotfload-resolvers.lua @@ -196,11 +196,20 @@ 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) @@ -273,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 -- cgit v1.2.3 From e8e069a3020df59046a38c2de18c589de928bbbc Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 28 Apr 2016 22:54:43 +0200 Subject: =?UTF-8?q?[doc]=20extend=20conf=20manpage=20for=20the=20inclusion?= =?UTF-8?q?=20of=20=E2=80=9Cmy:=E2=80=9D=20lookups?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/luaotfload.conf.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/luaotfload.conf.rst b/doc/luaotfload.conf.rst index 3568909..7b7f342 100644 --- a/doc/luaotfload.conf.rst +++ b/doc/luaotfload.conf.rst @@ -295,7 +295,9 @@ and retrieved from the index (``name:Foo Regular``). This behavior can be configured by specifying a list as the value to ``anon-sequence``. Available items are ``tex``, ``path``, ``name`` -- representing the lookups described above, respectively --, and ``file`` for searching a -filename but not an absolute path. +filename but not an absolute path. Also, ``my`` lookups are valid +values but they should only be used from within TeX documents, because +there is no means of customizing a ``my`` lookups on the command line. The ``color-callback`` option determines the stage at which fonts that defined with a ``color=xxyyzz`` feature will be colorized. By default -- cgit v1.2.3