From 9ab1917e9b492abaef43a9d9a45ceba23391003f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 15 Sep 2013 22:46:21 +0200 Subject: [tool] add option to skip reading font files --- luaotfload-database.lua | 229 +++++++++++++++++++++++++----------------------- luaotfload-tool.lua | 43 +++++---- 2 files changed, 143 insertions(+), 129 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index d3f2f08..bb7f17e 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -20,101 +20,100 @@ local C, Cc, Cf, Cg, Cs, Ct = lpeg.C, lpeg.Cc, lpeg.Cf, lpeg.Cg, lpeg.Cs, lpeg.Ct --- Luatex builtins -local load = load -local next = next -local pcall = pcall -local require = require -local tonumber = tonumber -local unpack = table.unpack - -local fontloaderinfo = fontloader.info -local fontloaderclose = fontloader.close -local fontloaderopen = fontloader.open -local fontloaderto_table = fontloader.to_table -local iolines = io.lines -local ioopen = io.open -local kpseexpand_path = kpse.expand_path -local kpseexpand_var = kpse.expand_var -local kpsefind_file = kpse.find_file -local kpselookup = kpse.lookup -local kpsereadable_file = kpse.readable_file -local lfsattributes = lfs.attributes -local lfschdir = lfs.chdir -local lfscurrentdir = lfs.currentdir -local lfsdir = lfs.dir -local mathabs = math.abs -local mathmin = math.min -local osgettimeofday = os.gettimeofday -local osremove = os.remove -local stringfind = string.find -local stringformat = string.format -local stringgmatch = string.gmatch -local stringgsub = string.gsub -local stringlower = string.lower -local stringsub = string.sub -local stringupper = string.upper -local tableconcat = table.concat -local tablesort = table.sort -local texiowrite_nl = texio.write_nl -local utf8gsub = unicode.utf8.gsub -local utf8lower = unicode.utf8.lower +local load = load +local next = next +local pcall = pcall +local require = require +local tonumber = tonumber +local unpack = table.unpack + +local fontloaderinfo = fontloader.info +local fontloaderclose = fontloader.close +local fontloaderopen = fontloader.open +local fontloaderto_table = fontloader.to_table +local iolines = io.lines +local ioopen = io.open +local kpseexpand_path = kpse.expand_path +local kpseexpand_var = kpse.expand_var +local kpsefind_file = kpse.find_file +local kpselookup = kpse.lookup +local kpsereadable_file = kpse.readable_file +local lfsattributes = lfs.attributes +local lfschdir = lfs.chdir +local lfscurrentdir = lfs.currentdir +local lfsdir = lfs.dir +local mathabs = math.abs +local mathmin = math.min +local osgettimeofday = os.gettimeofday +local osremove = os.remove +local stringfind = string.find +local stringformat = string.format +local stringgmatch = string.gmatch +local stringgsub = string.gsub +local stringlower = string.lower +local stringsub = string.sub +local stringupper = string.upper +local tableconcat = table.concat +local tablesort = table.sort +local texiowrite_nl = texio.write_nl +local utf8gsub = unicode.utf8.gsub +local utf8lower = unicode.utf8.lower --- these come from Lualibs/Context -local filebasename = file.basename -local filecollapsepath = file.collapsepath or file.collapse_path -local filedirname = file.dirname -local fileextname = file.extname -local fileiswritable = file.iswritable -local filejoin = file.join -local filenameonly = file.nameonly -local filereplacesuffix = file.replacesuffix -local filesplitpath = file.splitpath or file.split_path -local filesuffix = file.suffix -local getwritablepath = caches.getwritablepath -local lfsisdir = lfs.isdir -local lfsisfile = lfs.isfile -local lfsmkdirs = lfs.mkdirs -local lpegsplitat = lpeg.splitat -local stringis_empty = string.is_empty -local stringsplit = string.split -local stringstrip = string.strip -local tableappend = table.append -local tablecopy = table.copy -local tablefastcopy = table.fastcopy -local tabletofile = table.tofile -local tabletohash = table.tohash +local filebasename = file.basename +local filecollapsepath = file.collapsepath or file.collapse_path +local filedirname = file.dirname +local fileextname = file.extname +local fileiswritable = file.iswritable +local filejoin = file.join +local filenameonly = file.nameonly +local filereplacesuffix = file.replacesuffix +local filesplitpath = file.splitpath or file.split_path +local filesuffix = file.suffix +local getwritablepath = caches.getwritablepath +local lfsisdir = lfs.isdir +local lfsisfile = lfs.isfile +local lfsmkdirs = lfs.mkdirs +local lpegsplitat = lpeg.splitat +local stringis_empty = string.is_empty +local stringsplit = string.split +local stringstrip = string.strip +local tableappend = table.append +local tablecopy = table.copy +local tablefastcopy = table.fastcopy +local tabletofile = table.tofile +local tabletohash = table.tohash --- the font loader namespace is “fonts”, same as in Context --- we need to put some fallbacks into place for when running --- as a script -fonts = fonts or { } -fonts.names = fonts.names or { } -fonts.definers = fonts.definers or { } +fonts = fonts or { } +fonts.names = fonts.names or { } +fonts.definers = fonts.definers or { } -local names = fonts.names +local names = fonts.names -config = config or { } -config.luaotfload = config.luaotfload or { } -config.luaotfload.resolver = config.luaotfload.resolver or "normal" -config.luaotfload.formats = config.luaotfload.formats or "otf,ttf,ttc,dfont" +local luaotfloadconfig = config.luaotfload --- always present +luaotfloadconfig.resolver = luaotfloadconfig.resolver or "normal" +luaotfloadconfig.formats = luaotfloadconfig.formats or "otf,ttf,ttc,dfont" -if config.luaotfload.update_live ~= false then +if luaotfloadconfig.update_live ~= false then --- this option allows for disabling updates --- during a TeX run - config.luaotfload.update_live = true + luaotfloadconfig.update_live = true end -names.version = 2.4 -names.data = nil --- contains the loaded database -names.lookups = nil --- contains the lookup cache +names.version = 2.4 +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 = config.luaotfload.names_dir or "names", - index_file = config.luaotfload.index_file - or "luaotfload-names.lua", - lookups_file = "luaotfload-lookup-cache.lua", +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) @@ -1937,7 +1936,7 @@ do end --- initialize - set_font_filter (config.luaotfload.formats) + set_font_filter (luaotfloadconfig.formats) end local process_dir_tree @@ -2565,7 +2564,7 @@ local generate_filedata = function (mappings) end --- TODO adapt to new mechanism! --- if config.luaotfload.prioritize == "texmf" then +-- if luaotfloadconfig.prioritize == "texmf" then -- report("both", 2, "db", "Preferring texmf fonts") -- addmap(sys) -- addmap(texmf) @@ -2986,7 +2985,9 @@ end --- dbobj? -> bool? -> bool? -> dbobj update_names = function (currentnames, force, dry_run) - if config.luaotfload.update_live == false then + local targetnames + + if luaotfloadconfig.update_live == false then report ("info", 2, "db", "Skipping database update") --- skip all db updates @@ -3004,30 +3005,43 @@ update_names = function (currentnames, force, dry_run) report ("both", 2, "db", "Updating the font names database" .. (force and " forcefully" or "")) - if force then - currentnames = initialize_namedata (get_font_filter ()) + if luaotfloadconfig.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. + report ("info", 2, "db", + "Ignoring font files, reusing old data.") + currentnames = load_names (false) + targetnames = currentnames else - if not currentnames then - currentnames = load_names (dry_run) - end - if currentnames.meta.version ~= names.version then - report ("both", 1, "db", "No font names database or old " - .. "one found; generating new one") + if force then currentnames = initialize_namedata (get_font_filter ()) + else + if not currentnames then + currentnames = load_names (dry_run) + end + if currentnames.meta.version ~= names.version then + report ("both", 1, "db", "No font names database or old " + .. "one found; generating new one") + currentnames = initialize_namedata (get_font_filter ()) + end end - end - local targetnames = initialize_namedata (get_font_filter ()) + targetnames = initialize_namedata (get_font_filter ()) - read_blacklist () + read_blacklist () - local n_rawnames, n_newnames = retrieve_namedata (currentnames, - targetnames, - dry_run, - n_rawnames, - n_newnames) + local n_raw, n_new= retrieve_namedata (currentnames, + targetnames, + dry_run, + n_rawnames, + n_newnames) + report ("info", 3, "db", + "Scanned %d font files; %d new entries.", + n_rawnames, n_newnames) + end - if config.luaotfload.statistics == true then + if luaotfloadconfig.statistics == true then targetnames.meta.statistics = collect_statistics (targetnames.mappings) end @@ -3039,13 +3053,6 @@ update_names = function (currentnames, force, dry_run) targetnames.files = generate_filedata (targetnames.mappings) targetnames.families = collect_families (targetnames.mappings) - --- stats: - --- before rewrite | after rewrite - --- partial: 804 ms | 701 ms - --- forced: 45384 ms | 44714 ms - report ("info", 3, "db", - "Scanned %d font files; %d new entries.", - n_rawnames, n_newnames) report ("info", 3, "db", "Rebuilt in %0.f ms.", 1000 * (osgettimeofday () - starttime)) @@ -3205,7 +3212,7 @@ end local getwritablecachepath = function ( ) --- fonts.handlers.otf doesn’t exist outside a Luatex run, --- so we have to improvise - local writable = getwritablepath (config.luaotfload.cache_dir) + local writable = getwritablepath (luaotfloadconfig.cache_dir) if writable then return writable end @@ -3213,7 +3220,7 @@ end local getreadablecachepaths = function ( ) local readables = caches.getreadablepaths - (config.luaotfload.cache_dir) + (luaotfloadconfig.cache_dir) local result = { } if readables then for i=1, #readables do @@ -3297,7 +3304,7 @@ names.erase_cache = erase_cache names.show_cache = show_cache --- replace the resolver from luatex-fonts -if config.luaotfload.resolver == "cached" then +if luaotfloadconfig.resolver == "cached" then report("both", 2, "cache", "caching of name: lookups active") names.resolve = resolve_cached names.resolvespec = resolve_cached diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 9739e17..e410d44 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -102,13 +102,16 @@ to be the more appropriate. config = config or { } local config = config -config.luaotfload = config.luaotfload or { } -config.luaotfload.version = config.luaotfload.version or version -config.luaotfload.names_dir = config.luaotfload.names_dir or "names" -config.luaotfload.cache_dir = config.luaotfload.cache_dir or "fonts" -config.luaotfload.index_file = config.luaotfload.index_file +local luaotfloadconfig = config.luaotfload or { } +config.luaotfload = luaotfloadconfig +luaotfloadconfig.version = luaotfloadconfig.version or version +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" -config.luaotfload.formats = config.luaotfload.formats or "otf,ttf,ttc,dfont" +luaotfloadconfig.formats = luaotfloadconfig.formats + or "otf,ttf,ttc,dfont" +luaotfloadconfig.reload = false do -- we don’t have file.basename and the likes yet, so inline parser ftw local slash = P"/" @@ -122,9 +125,9 @@ do -- we don’t have file.basename and the likes yet, so inline parser ftw local self = lpegmatch(p_basename, stringlower(arg[0])) if self == "luaotfload-tool" then - config.luaotfload.self = "luaotfload-tool" + luaotfloadconfig.self = "luaotfload-tool" else - config.luaotfload.self = "mkluatexfontdb" + luaotfloadconfig.self = "mkluatexfontdb" end end @@ -170,7 +173,7 @@ local names = fonts.names local status_file = "luaotfload-status" local luaotfloadstatus = require (status_file) -config.luaotfload.status = luaotfloadstatus +luaotfloadconfig.status = luaotfloadstatus local sanitize_fontname = names.sanitize_fontname @@ -283,16 +286,16 @@ Enter 'luaotfload-tool --help' for a larger list of options. local help_msg = function (version) local template = help_messages[version] iowrite(stringformat(template, - config.luaotfload.self, + luaotfloadconfig.self, names_plain, names_bin, caches.getwritablepath ( - config.luaotfload.cache_dir))) + luaotfloadconfig.cache_dir))) end local version_msg = function ( ) local out = function (...) texiowrite_nl (stringformat (...)) end - out ("%s version %q", config.luaotfload.self, version) + out ("%s version %q", luaotfloadconfig.self, version) out ("revision %q", luaotfloadstatus.notes.revision) out ("database version %q", names.version) out ("Lua interpreter: %s; version %q", runtime[1], runtime[2]) @@ -1077,6 +1080,7 @@ local process_cmdline = function ( ) -- unit -> jobspec list = 1, log = 1, ["no-reload"] = "n", + ["skip-read"] = "R", ["prefer-texmf"] = "p", quiet = "q", ["show-blacklist"] = "b", @@ -1087,7 +1091,7 @@ local process_cmdline = function ( ) -- unit -> jobspec warnings = "w", } - local short_options = "bDfFiIlnpqSuvVhw" + local short_options = "bDfFiIlnpqRSuvVhw" local options, _, optarg = alt_getopt.get_ordered_opts (arg, short_options, long_options) @@ -1144,7 +1148,7 @@ local process_cmdline = function ( ) -- unit -> jobspec result.show_info = true result.full_info = true elseif v == "alias" then - config.luaotfload.self = optarg[n] + luaotfloadconfig.self = optarg[n] elseif v == "l" then action_pending["flush"] = true elseif v == "list" then @@ -1158,7 +1162,7 @@ local process_cmdline = function ( ) -- unit -> jobspec elseif v == "D" then result.dry_run = true elseif v == "p" then --- TODO adapt to new db structure - config.luaotfload.prioritize = "texmf" + luaotfloadconfig.prioritize = "texmf" elseif v == "b" then action_pending["blacklist"] = true elseif v == "diagnose" then @@ -1167,13 +1171,16 @@ local process_cmdline = function ( ) -- unit -> jobspec elseif v == "formats" then names.set_font_filter (optarg[n]) elseif v == "n" then - config.luaotfload.update_live = false + luaotfloadconfig.update_live = false elseif v == "S" then - config.luaotfload.statistics = true + luaotfloadconfig.statistics = true + elseif v == "R" then + --- dev only, undocumented + luaotfloadconfig.skip_read = true end end - if config.luaotfload.self == "mkluatexfontdb" then + if luaotfloadconfig.self == "mkluatexfontdb" then --- TODO drop legacy ballast after 2.4 result.help_version = "mkluatexfontdb" action_pending["generate"] = true result.log_level = math.max(1, result.log_level) -- cgit v1.2.3