From 54269ef7c476dc4952ea2e6c08b6e2bfa9f68ba5 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 14 Feb 2014 22:41:20 +0100 Subject: [db,tool] support scanning local fonts into db --- src/luaotfload-database.lua | 67 +++++++++++++++++++++++++++++++++++---------- src/luaotfload-tool.lua | 20 ++++++++++---- 2 files changed, 66 insertions(+), 21 deletions(-) diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 54474e2..06a3dea 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -553,6 +553,10 @@ local save_lookups local update_names local get_font_filter local set_font_filter +local generate_filedata +local collect_families +local group_modifiers +local order_design_sizes --- state of the database local fonts_reloaded = false @@ -572,7 +576,7 @@ load_names = function (dry_run) report ("info", 3, "db", "Loading took %0.f ms.", 1000 * (osgettimeofday () - starttime)) - local db_version, nms_version + local db_version, names_version if data.meta then db_version = data.meta.version else @@ -581,11 +585,11 @@ load_names = function (dry_run) --- an earlier index version broke. db_version = data.version or -42 --- invalid end - nms_version = names.version - if db_version ~= nms_version then + names_version = names.version + if db_version ~= names_version then report ("both", 0, "db", [[Version mismatch; expected %4.3f, got %4.3f.]], - nms_version, db_version) + names_version, db_version) if not fonts_reloaded then report ("both", 0, "db", [[Force rebuild.]]) data = update_names ({ }, true, false) @@ -2211,7 +2215,7 @@ local scan_dir = function (dirname, currentnames, targetnames, --- ignore return 0, 0 end - local found = find_font_files (dirname, location ~= "texmf") + local found = find_font_files (dirname, location ~= "texmf" and location ~= "local") if not found then report ("both", 4, "db", "No such directory: %q; skipping.", dirname) @@ -2391,10 +2395,42 @@ flush_lookup_cache = function () return true end +--[[doc-- + + scan_local_fonts() -- Scan font files in $PWD (during a TeX run) + and add them to the database. + + This sets the “local” flag in the subtable “meta” to prevent the + merged table from being saved to disk. + + TODO the local tree could be cached in $PWD. + +--doc]]-- + +local scan_local_fonts = function () + local n_scanned, n_new = 0, 0 + local pwd = lfscurrentdir () + local name_index = name_index + report ("both", 1, "db", "Scanning fonts in $PWD (%q) ...", pwd) + + n_scanned, n_new = scan_dir (pwd, name_index, name_index, false, "local") + if n_new > 0 then + name_index.files = generate_filedata (name_index.mappings) + name_index.families = collect_families (name_index.mappings) + name_index.families = group_modifiers (name_index.mappings, + name_index.families) + name_index.families = order_design_sizes (name_index.families) + name_index.meta["local"] = true --- prevent saving to disk + end + + return n_scanned, n_new +end + +--- dbobj -> dbobj -> int * int --- fontentry list -> filemap -local generate_filedata = function (mappings) +generate_filedata = function (mappings) report ("both", 2, "db", "Creating filename map.") @@ -2672,7 +2708,7 @@ local get_subtable = function (families, entry) return subtable end -local collect_families = function (mappings) +collect_families = function (mappings) report ("info", 2, "db", "Analyzing families.") @@ -2769,7 +2805,7 @@ local bold_weight = 700 local style_categories = { "r", "b", "i", "bi" } local bold_categories = { "b", "bi" } -local group_modifiers = function (mappings, families) +group_modifiers = function (mappings, families) report ("info", 2, "db", "Analyzing shapes, weights, and styles.") for location, location_data in next, families do for format, format_data in next, location_data do @@ -2867,7 +2903,7 @@ local cmp_sizes = function (a, b) return a [1] < b [1] end -local order_design_sizes = function (families) +order_design_sizes = function (families) report ("info", 2, "db", "Ordering design sizes.") @@ -3127,11 +3163,11 @@ update_names = function (currentnames, force, dry_run) read_blacklist () - local n_raw, n_new= 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) @@ -3210,7 +3246,7 @@ save_lookups = function ( ) end --- save_names() is usually called without the argument ---- dbobj? -> bool +--- dbobj? -> bool * string option save_names = function (currentnames) if not currentnames then currentnames = name_index @@ -3430,6 +3466,7 @@ names.read_blacklist = read_blacklist names.sanitize_fontname = sanitize_fontname names.getfilename = resolve_fullpath names.set_location_precedence = set_location_precedence +names.scan_local_fonts = scan_local_fonts --- font cache names.purge_cache = purge_cache diff --git a/src/luaotfload-tool.lua b/src/luaotfload-tool.lua index 01d0361..9f00956 100755 --- a/src/luaotfload-tool.lua +++ b/src/luaotfload-tool.lua @@ -723,9 +723,9 @@ set. --]]-- local action_sequence = { - "loglevel", "help", "version", "diagnose", - "blacklist", "cache", "flush", "generate", - "list", "query", + "loglevel", "help", "version", "diagnose", + "blacklist", "cache", "flush", "generate", + "scan_local", "list", "query", } local action_pending = tabletohash(action_sequence, false) @@ -762,8 +762,7 @@ actions.blacklist = function (job) end actions.generate = function (job) - local fontnames, savedname - fontnames = names.update(fontnames, job.force_reload, job.dry_run) + local fontnames = names.update(fontnames, job.force_reload, job.dry_run) report ("info", 2, "db", "Fonts in the database: %i", #fontnames.mappings) if names.data() then return true, true @@ -771,6 +770,11 @@ actions.generate = function (job) return false, false end +actions.scan_local = function (job) + names.scan_local_fonts () + return true, true +end + actions.flush = function (job) local success = names.flush_lookup_cache() if success then @@ -1094,6 +1098,7 @@ local process_cmdline = function ( ) -- unit -> jobspec inspect = "I", limit = 1, list = 1, + ["local"] = "L", log = 1, ["max-fonts"] = 1, ["no-reload"] = "n", @@ -1109,7 +1114,7 @@ local process_cmdline = function ( ) -- unit -> jobspec warnings = "w", } - local short_options = "bcDfFiIlnpqRSuvVhw" + local short_options = "bcDfFiIlLnpqRSuvVhw" local options, _, optarg = alt_getopt.get_ordered_opts (arg, short_options, long_options) @@ -1167,6 +1172,9 @@ local process_cmdline = function ( ) -- unit -> jobspec result.full_info = true elseif v == "l" then action_pending["flush"] = true + elseif v == "L" then + action_pending["generate"] = true + action_pending["scan_local"] = true elseif v == "list" then action_pending["list"] = true result.criterion = optarg[n] -- cgit v1.2.3