From d16a93579dfec03a0dab4281b45f63d877fc4c88 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 26 Apr 2013 22:33:37 +0200 Subject: install the new file: lookup in luaotfload.lua --- luaotfload-database.lua | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 4980766..576971e 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -230,6 +230,8 @@ local load_lua_file = function (path) end --- define locals in scope +local crude_file_lookup +local crude_file_lookup_verbose local find_closest local flush_cache local font_fullinfo @@ -290,8 +292,12 @@ do end --- chain: barenames -> [fullnames ->] basenames -> findfile -local crude_file_lookup_verbose = function (data, filename) - local mappings = data.mappings + +--- string -> (string * bool | int) +crude_file_lookup_verbose = function (filename) + if not names.data then names.data = names_reload() end + local data = names.data + local mappings = data.mappings local found --- look up in db first ... @@ -336,7 +342,11 @@ local crude_file_lookup_verbose = function (data, filename) return false end -local crude_file_lookup = function (data, filename) +--- string -> (string * bool | int) +crude_file_lookup = function (filename) + if not names.data then names.data = names_reload() end + local data = names.data + local mappings = data.mappings local found = data.barenames[filename] -- or data.fullnames[filename] or data.basenames[filename] @@ -470,6 +480,7 @@ local resolvers = { fonts.definers.resolve = resolvers[config.luaotfload.resolver] --fonts.definers.resolve = resolvers.cached +fonts.definers.resolve = resolvers.dummy --[[doc-- @@ -513,12 +524,6 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con if not fonts_loaded then names.data = load_names() end local data = names.data - if specification.lookup == "file" then - local found = crude_file_lookup(data, specification.name) - --local found = crude_file_lookup_verbose(data, specification.name) - if found then return found[1], found[2], true end - end - local name = sanitize_string(specification.name) local style = sanitize_string(specification.style) or "regular" @@ -1380,11 +1385,13 @@ scan_external_dir = function (dir) end --- export functionality to the namespace “fonts.names” -names.flush_cache = flush_cache -names.load = load_names -names.save = save_names -names.scan = scan_external_dir -names.update = update_names +names.flush_cache = flush_cache +names.load = load_names +names.save = save_names +names.scan = scan_external_dir +names.update = update_names +names.crude_file_lookup = crude_file_lookup +names.crude_file_lookup_verbose = crude_file_lookup_verbose names.resolve = resolve --- replace the resolver from luatex-fonts names.resolvespec = resolve -- cgit v1.2.3 From a1ab3fe5a146cf741d517be62985b97268de624b Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 28 Apr 2013 12:59:51 +0200 Subject: add fallback for specification name --- luaotfload-database.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 576971e..b678f51 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -437,7 +437,7 @@ local cached_resolver = function (specification) if not names.data then names.data = load_names() end local request_cache = names.data.request_cache local request = specification.specification - report("info", 4, "cache", + report("log", 4, "cache", "looking for “%s” in cache ...", request) local found = names.data.request_cache[request] @@ -449,7 +449,7 @@ local cached_resolver = function (specification) end return specification end - report("info", 4, "cache", "not cached; resolving") + report("log", 4, "cache", "not cached; resolving") --- first we resolve normally ... local resolved_spec = normal_resolver(specification) @@ -459,7 +459,7 @@ local cached_resolver = function (specification) local f = cache_fields[i] entry[f] = resolved_spec[f] end - report("info", 4, "cache", "new entry: %s", request) + report("log", 4, "cache", "new entry: %s", request) names.data.request_cache[request] = entry --- obviously, the updated cache needs to be stored. @@ -467,7 +467,7 @@ local cached_resolver = function (specification) --- whenever the cache is updated. --- TODO this should trigger a save only once the --- document is compiled (finish_pdffile callback?) - report("info", 5, "cache", "saving updated cache") + report("log", 5, "cache", "saving updated cache") save_names() return resolved_spec end @@ -480,7 +480,7 @@ local resolvers = { fonts.definers.resolve = resolvers[config.luaotfload.resolver] --fonts.definers.resolve = resolvers.cached -fonts.definers.resolve = resolvers.dummy +--fonts.definers.resolve = resolvers.dummy --[[doc-- @@ -1268,7 +1268,7 @@ local function get_os_dirs() local os_dirs = {} for _,p in next, {"/usr/local/etc/fonts/fonts.conf", "/etc/fonts/fonts.conf"} do if lfs.isfile(p) then - read_fonts_conf(p, os_dirs, passed_paths) + paths = read_fonts_conf(p, os_dirs, passed_paths) end end return os_dirs -- cgit v1.2.3 From 74ebd14b94432c9de82614627454dfa3bfcb9de0 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 28 Apr 2013 16:39:26 +0200 Subject: add lookups ``file:``, ``path:``, ``name:``, and ``anon:`` --- luaotfload-database.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index b678f51..eb8271d 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -295,7 +295,7 @@ end --- string -> (string * bool | int) crude_file_lookup_verbose = function (filename) - if not names.data then names.data = names_reload() end + if not names.data then names.data = load_names() end local data = names.data local mappings = data.mappings local found @@ -344,7 +344,7 @@ end --- string -> (string * bool | int) crude_file_lookup = function (filename) - if not names.data then names.data = names_reload() end + if not names.data then names.data = load_names() end local data = names.data local mappings = data.mappings local found = data.barenames[filename] -- cgit v1.2.3 From 189085f9a7212320183d5fed0c4aa31df1602d5f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 28 Apr 2013 19:08:11 +0200 Subject: catch tfm/ofm before db update; remove ``kpse.lookup()`` as criterion for resolved font --- luaotfload-database.lua | 84 ++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 46 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index eb8271d..e5065bd 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -291,7 +291,7 @@ do end end ---- chain: barenames -> [fullnames ->] basenames -> findfile +local type1_formats = { "tfm", "ofm", } --- string -> (string * bool | int) crude_file_lookup_verbose = function (filename) @@ -320,26 +320,19 @@ crude_file_lookup_verbose = function (filename) if found and mappings[found] then found = mappings[found].filename report("info", 0, "db", - "crude file lookup: req=%s; hit=bare; ret=%s", + "crude file lookup: req=%s; hit=base; ret=%s", filename, found[1]) return found end - --- now look for tfm et al.; will be superseded by proper - --- format lookup - found = resolvers.findfile(filename, "tfm") - if found then - report("info", 0, "db", - "crude file lookup: req=tfm; hit=bare; ret=%s", found) - return { found, false } - end - found = resolvers.findfile(filename, "ofm") - if found then - report("info", 0, "db", - "crude file lookup: req=ofm; hit=bare; ret=%s", found) - return { found, false } + --- ofm and tfm + for i=1, #type1_formats do + local format = type1_formats[i] + if resolvers.findfile(filename, format) then + return { file.addsuffix(filename, format), false }, format + end end - return false + return { filename, false }, nil end --- string -> (string * bool | int) @@ -354,11 +347,13 @@ crude_file_lookup = function (filename) found = data.mappings[found] if found then return found.filename end end - found = resolvers.findfile(filename, "tfm") - if found then return { found, false } end - found = resolvers.findfile(filename, "ofm") - if found then return { found, false } end - return false + for i=1, #type1_formats do + local format = type1_formats[i] + if resolvers.findfile(filename, format) then + return { file.addsuffix(filename, format), false }, format + end + end + return { filename, false }, nil end --[[doc-- @@ -644,13 +639,14 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con end if #found == 1 then - if kpselookup(found[1].filename[1]) then - report("log", 0, "resolve", - "font family='%s', subfamily='%s' found: %s", - name, style, found[1].filename[1] - ) - return found[1].filename[1], found[1].filename[2], true - end + --- Since we do the file resolving ourselves, we don’t need the + --- kpathsea lookup here any longer. + --- “found” is really synonymous with “registered in the db”. + report("log", 0, "resolve", + "font family='%s', subfamily='%s' found: %s", + name, style, found[1].filename[1] + ) + return found[1].filename[1], found[1].filename[2], true elseif #found > 1 then -- we found matching font(s) but not in the requested optical -- sizes, so we loop through the matches to find the one with @@ -665,13 +661,11 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con least = difference end end - if kpselookup(closest.filename[1]) then - report("log", 0, "resolve", - "font family='%s', subfamily='%s' found: %s", - name, style, closest.filename[1] - ) - return closest.filename[1], closest.filename[2], true - end + report("log", 0, "resolve", + "font family='%s', subfamily='%s' found: %s", + name, style, closest.filename[1] + ) + return closest.filename[1], closest.filename[2], true elseif found.fallback then return found.fallback.filename[1], found.fallback.filename[2], true end @@ -680,7 +674,7 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con if not fonts_reloaded then --- last straw: try reloading the database return reload_db( - "unresoled font name: “" .. name .. "”", + "unresolved font name: “" .. name .. "”", resolve, nil, nil, specification ) end @@ -737,9 +731,7 @@ find_closest = function (name, limit) local name = sanitize_string(name) limit = limit or fuzzy_limit - if not fonts_loaded then - names.data = load_names() - end + if not fonts_loaded then names.data = load_names() end local data = names.data @@ -866,10 +858,10 @@ font_fullinfo = function (filename, subfont, texmf) tfmdata.fontname = metadata.fontname tfmdata.fullname = metadata.fullname tfmdata.familyname = metadata.familyname - tfmdata.filename = { - texmf and filebasename(filename) or filename, - subfont - } + if texmf then + filename = filebasename(filename) + end + tfmdata.filename = { filename, subfont } tfmdata.weight = metadata.pfminfo.weight tfmdata.width = metadata.pfminfo.width tfmdata.slant = metadata.italicangle @@ -1328,9 +1320,9 @@ update_names = function (fontnames, force) read_blacklist() local scanned, new - scanned, new = scan_texmf_fonts(fontnames, newfontnames) - n_scanned = n_scanned + scanned - n_new = n_new + new +-- scanned, new = scan_texmf_fonts(fontnames, newfontnames) +-- n_scanned = n_scanned + scanned +-- n_new = n_new + new scanned, new = scan_os_fonts(fontnames, newfontnames) n_scanned = n_scanned + scanned -- cgit v1.2.3 From 1c8a1d0a59de24f0d1f456c4fad29024e00ef23b Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 28 Apr 2013 19:13:56 +0200 Subject: test for file existence again, but try with ``lfs.isfile()`` first --- luaotfload-database.lua | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index e5065bd..8caa35b 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -25,6 +25,7 @@ local kpseexpand_path = kpse.expand_path local kpseexpand_var = kpse.expand_var local kpselookup = kpse.lookup local kpsereadable_file = kpse.readable_file +local lfsisfile = lfs.isfile local mathabs = math.abs local mathmin = math.min local stringfind = string.find @@ -639,14 +640,15 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con end if #found == 1 then - --- Since we do the file resolving ourselves, we don’t need the - --- kpathsea lookup here any longer. --- “found” is really synonymous with “registered in the db”. - report("log", 0, "resolve", - "font family='%s', subfamily='%s' found: %s", - name, style, found[1].filename[1] - ) - return found[1].filename[1], found[1].filename[2], true + local filename = found[1].filename[1] + if lfsisfile(filename) or kpselookup(filename) then + report("log", 0, "resolve", + "font family='%s', subfamily='%s' found: %s", + name, style, filename + ) + return filename, found[1].filename[2], true + end elseif #found > 1 then -- we found matching font(s) but not in the requested optical -- sizes, so we loop through the matches to find the one with @@ -661,13 +663,18 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con least = difference end end - report("log", 0, "resolve", - "font family='%s', subfamily='%s' found: %s", - name, style, closest.filename[1] - ) - return closest.filename[1], closest.filename[2], true + local filename = closest.filename[1] + if lfsisfile(filename) or kpselookup(filename) then + report("log", 0, "resolve", + "font family='%s', subfamily='%s' found: %s", + name, style, filename + ) + return filename, closest.filename[2], true + end elseif found.fallback then - return found.fallback.filename[1], found.fallback.filename[2], true + return found.fallback.filename[1], + found.fallback.filename[2], + true end --- no font found so far -- cgit v1.2.3 From 1a76cea6357f50d7dae752765173af335ba95beb Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 29 Apr 2013 13:57:35 +0200 Subject: add handler for XeTeX slashed notation --- luaotfload-database.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 8caa35b..4aa966a 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -562,8 +562,6 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con local found = { } local synonym_set = style_synonyms.set for _,face in next, data.mappings do - --- TODO we really should store those in dedicated - --- .sanitized field local family, subfamily, fullname, psname, fontname, pfullname local facenames = face.sanitized -- cgit v1.2.3 From e79f34d859d48be485589f19fc6905afa5872a53 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 29 Apr 2013 14:52:53 +0200 Subject: only cache ``name:`` lookups --- luaotfload-database.lua | 72 ++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 46 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 4aa966a..abf06a2 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -240,6 +240,7 @@ local load_names local read_fonts_conf local reload_db local resolve +local resolve_cached local save_names local scan_external_dir local update_names @@ -380,22 +381,6 @@ TODO: 9) ??? n) PROFIT!!! ---doc]]-- - ---- the resolver is called after the font request is parsed ---- this is where we insert the cache -local normal_resolver = fonts.definers.resolve -local dummy_resolver = function (specification) - --- this ensures that the db is always loaded - --- before a lookup occurs - if not names.data then names.data = load_names() end - --inspect(specification) - local resolved = normal_resolver(specification) - --inspect(resolved) - return resolved -end - ---[[doc-- The name lookup requires both the “name” and some other keys, so we’ll concatenate them. The spec is modified in place (ugh), so we’ll have to catalogue what @@ -428,33 +413,29 @@ We’ll just cache a deep copy of the entire spec as it leaves the resolver, lest we want to worry if we caught all the details. --doc]]-- ---- spec -> spec -local cached_resolver = function (specification) +--- 'a -> 'a -> table -> (string * int|boolean * boolean) +resolve_cached = function (_, _, specification) if not names.data then names.data = load_names() end local request_cache = names.data.request_cache local request = specification.specification - report("log", 4, "cache", - "looking for “%s” in cache ...", + report("log", 4, "cache", "looking for “%s” in cache ...", request) + local found = names.data.request_cache[request] + + --- case 1) cache positive ---------------------------------------- if found then --- replay fields from cache hit report("info", 4, "cache", "found!") - for i=1, #cache_fields do - local f = cache_fields[i] - if found[f] then specification[f] = found[f] end - end - return specification + return found[1], found[2], true end report("log", 4, "cache", "not cached; resolving") + --- case 2) cache negative ---------------------------------------- --- first we resolve normally ... - local resolved_spec = normal_resolver(specification) - --- ... then we add the fields to the cache - local entry = { } - for i=1, #cache_fields do - local f = cache_fields[i] - entry[f] = resolved_spec[f] - end + local filename, subfont, success = resolve(nil, nil, specification) + if not success then return filename, subfont, false end + --- ... then we add the fields to the cache ... ... + local entry = { filename, subfont } report("log", 4, "cache", "new entry: %s", request) names.data.request_cache[request] = entry @@ -463,21 +444,13 @@ local cached_resolver = function (specification) --- whenever the cache is updated. --- TODO this should trigger a save only once the --- document is compiled (finish_pdffile callback?) + --- TODO we should speed up writing by separating + --- the cache from the db report("log", 5, "cache", "saving updated cache") save_names() - return resolved_spec + return filename, subfont, true end -local resolvers = { - dummy = dummy_resolver, - normal = normal_resolver, - cached = cached_resolver, -} - -fonts.definers.resolve = resolvers[config.luaotfload.resolver] ---fonts.definers.resolve = resolvers.cached ---fonts.definers.resolve = resolvers.dummy - --[[doc-- Luatex-fonts, the font-loader package luaotfload imports, comes with @@ -1390,9 +1363,16 @@ names.update = update_names names.crude_file_lookup = crude_file_lookup names.crude_file_lookup_verbose = crude_file_lookup_verbose -names.resolve = resolve --- replace the resolver from luatex-fonts -names.resolvespec = resolve -names.find_closest = find_closest +--- replace the resolver from luatex-fonts +if config.luaotfload.resolver == "cached" then + report("info", 0, "cache", "caching of name: lookups active") + names.resolve = resolve_cached + names.resolvespec = resolve_cached +else + names.resolve = resolve + names.resolvespec = resolve +end +names.find_closest = find_closest --- dummy required by luatex-fonts (cf. luatex-fonts-syn.lua) -- cgit v1.2.3