[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev, master: Allow converting database into aliases for XeTeX (56de3c4)
Marcel Fabian Krüger
tex at 2krueger.de
Fri May 21 01:14:03 CEST 2021
Repository : https://github.com/latex3/luaotfload
On branches: dev,master
Link : https://github.com/latex3/luaotfload/commit/56de3c4f489b3a84a8b763b0f62b6ea705d21e64
>---------------------------------------------------------------
commit 56de3c4f489b3a84a8b763b0f62b6ea705d21e64
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Fri May 21 01:03:54 2021 +0200
Allow converting database into aliases for XeTeX
>---------------------------------------------------------------
56de3c4f489b3a84a8b763b0f62b6ea705d21e64
doc/luaotfload-tool.rst | 4 ++++
src/luaotfload-tool.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/doc/luaotfload-tool.rst b/doc/luaotfload-tool.rst
index d69ce97..0b55ad1 100644
--- a/doc/luaotfload-tool.rst
+++ b/doc/luaotfload-tool.rst
@@ -281,6 +281,10 @@ miscellaneous
output can be saved to a file and used for
bootstrapping a custom configuration files.
+--aliases Dump the font name database as a kpathsea
+ aliases file. This option is experimental and
+ might go away.
+
FILES
=======================================================================
diff --git a/src/luaotfload-tool.lua b/src/luaotfload-tool.lua
old mode 100644
new mode 100755
index 15a15d8..e178b8d
--- a/src/luaotfload-tool.lua
+++ b/src/luaotfload-tool.lua
@@ -736,7 +736,7 @@ local action_sequence = {
"config" , "loglevel" , "help" , "version" ,
"dumpconf" , "diagnose" , "blacklist" , "cache" ,
"flush" , "bisect" , "generate" , "list" ,
- "query" ,
+ "query" , "aliases" ,
}
local action_pending = tabletohash(action_sequence, false)
@@ -1396,6 +1396,51 @@ function actions.diagnose (job)
return diagnose (job)
end
+function actions.aliases (job)
+ --- Help XeTeX find fonts
+ local name_index = fonts.names.data() or fonts.names.load()
+ local mappings = name_index.mappings
+ local fontnames = name_index.fontnames.texmf
+ local families = name_index.families.texmf
+ local formats = { 'ttf', 'otf', }
+ for _, format in ipairs(formats) do
+ for name, mapping in pairs(fontnames[format]) do
+ mapping = mappings[mapping]
+ print(string.format('%s %s', mapping.basename, name))
+ end
+ end
+ local function best_match(options, target)
+ if not options then return end
+ if options.default then return mappings[options.default] end
+ local best, best_diff = nil, math.huge
+ for _, option in ipairs(options) do
+ local diff = math.abs(option[1]-target)
+ if diff < best_diff then
+ best, best_diff = option[4], diff
+ end
+ end
+ return mappings[best]
+ end
+ for _, format in ipairs(formats) do
+ for name, family in pairs(families[format]) do
+ local r = best_match(family.r, 655360, mappings)
+ local b = best_match(family.b, 655360, mappings)
+ local i = best_match(family.i, 655360, mappings)
+ local bi = best_match(family.bi, 655360, mappings)
+ r = r or b or i or bi -- Not sure if this is still needed
+ if r then
+ b, i, bi = b or r, i or r, bi or r
+ print(string.format('%s %s\n%s %s-b\n%s %s-i\n%s %s-bi',
+ r.basename, name,
+ b.basename, name,
+ i.basename, name,
+ bi.basename, name))
+ end
+ end
+ end
+ return true
+end
+
--- stuff to be carried out prior to exit
local finalizers = { }
@@ -1434,6 +1479,7 @@ local function process_cmdline ( ) -- unit -> jobspec
}
local long_options = {
+ aliases = 0,
["bisect"] = 1,
cache = 1,
conf = 1,
@@ -1587,6 +1633,8 @@ local function process_cmdline ( ) -- unit -> jobspec
action_pending["dumpconf"] = true
elseif v == "print-conf" then
result.print_config = true
+ elseif v == "aliases" then
+ action_pending["aliases"] = true
end
end
More information about the latex3-commits
mailing list.