From 15e03c1a52c4644ef421cddd57409cc90e793ad4 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 26 May 2013 09:32:51 +0200 Subject: use kpse for texmf lookups (again...) --- luaotfload-database.lua | 79 ++++++++++++++++++++++++++++--------------------- luaotfload.dtx | 2 +- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 60e321f..25c136b 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -19,6 +19,7 @@ local require = require local tonumber = tonumber local fontloaderinfo = fontloader.info +local fontloaderopen = fontloader.open local iolines = io.lines local ioopen = io.open local kpseexpand_path = kpse.expand_path @@ -71,7 +72,7 @@ fonts.definers = fonts.definers or { } local names = fonts.names -names.version = 2.204 +names.version = 2.205 names.data = nil --- contains the loaded database names.lookups = nil --- contains the lookup cache names.path = { @@ -356,13 +357,19 @@ crude_file_lookup_verbose = function (filename) return filename, nil end +local dummy_findfile = resolvers.findfile -- from basics-gen + --- string -> string crude_file_lookup = function (filename) + local found = dummy_findfile(filename) + if found then + return found + end if not names.data then names.data = load_names() end local data = names.data local mappings = data.mappings - local found = data.barenames[filename] - or data.basenames[filename] + found = data.barenames[filename] + or data.basenames[filename] if found then found = data.mappings[found] if found then return found.filename[1] end @@ -807,7 +814,7 @@ table as returned by the font file reader need to be relocated. --doc]]-- font_fullinfo = function (filename, subfont) local tfmdata = { } - local rawfont = fontloader.open(filename, subfont) + local rawfont = fontloaderopen(filename, subfont) if not rawfont then report("log", 1, "error", "failed to open %s", filename) return @@ -870,7 +877,7 @@ end --- we return true if the fond is new or re-indexed --- string -> dbobj -> dbobj -> bool -local load_font = function (fullname, fontnames, newfontnames) +local load_font = function (fullname, fontnames, newfontnames, texmf) if not fullname then return false end @@ -891,7 +898,10 @@ local load_font = function (fullname, fontnames, newfontnames) local basename = filebasename(fullname) local barename = filenameonly(fullname) - local entryname = basename + local entryname = fullname + if texmf == true then + entryname = basename + end if names.blacklist[fullname] or names.blacklist[basename] then @@ -901,36 +911,37 @@ local load_font = function (fullname, fontnames, newfontnames) end local timestamp, db_timestamp - db_timestamp = status[fullname] - and status[fullname].timestamp + db_timestamp = status[entryname] + and status[entryname].timestamp timestamp = lfs.attributes(fullname, "modification") - local index_status = newstatus[fullname] + local index_status = newstatus[entryname] --- index_status: nil | false | table if index_status and index_status.timestamp == timestamp then -- already indexed this run return false end - newstatus[fullname] = newstatus[fullname] or { } - newstatus[fullname].timestamp = timestamp - newstatus[fullname].index = newstatus[fullname].index or { } + newstatus[entryname] = newstatus[entryname] or { } + newstatus[entryname].timestamp = timestamp + newstatus[entryname].index = newstatus[entryname].index or { } --- this test compares the modification data registered --- in the database with the current one if db_timestamp == timestamp - and not newstatus[fullname].index[1] then - for _,v in next, status[fullname].index do - local index = #newstatus[fullname].index + and not newstatus[entryname].index[1] + then + for _, v in next, status[entryname].index do + local index = #newstatus[entryname].index local fullinfo = mappings[v] local location = #newmappings + 1 - newmappings[location] = fullinfo --- keep - newstatus[fullname].index[index+1] = location --- is this actually used anywhere? --- newfullnames[fullname] = location - newbasenames[basename] = location - newbarenames[barename] = location + newmappings[location] = fullinfo --- keep + newstatus[entryname].index[index+1] = location --- is this actually used anywhere? +-- newfullnames[fullname] = location + newbasenames[basename] = location + newbarenames[barename] = location end - report("log", 2, "db", "font “%s” already indexed", entryname) + report("log", 2, "db", "font “%s” already indexed", basename) return false end @@ -943,14 +954,14 @@ local load_font = function (fullname, fontnames, newfontnames) return false end local location = #newmappings+1 - local index = newstatus[fullname].index[n_font] + local index = newstatus[entryname].index[n_font] if not index then index = location end newmappings[index] = fullinfo -- newfullnames[fullname] = location newbasenames[basename] = location newbarenames[barename] = location - newstatus[fullname].index[n_font] = index + newstatus[entryname].index[n_font] = index end else local fullinfo = font_fullinfo(fullname, false) @@ -958,18 +969,18 @@ local load_font = function (fullname, fontnames, newfontnames) return false end local location = #newmappings+1 - local index = newstatus[fullname].index[1] + local index = newstatus[entryname].index[1] if not index then index = location end - newmappings[index] = fullinfo --- newfullnames[fullname] = location - newbasenames[basename] = location - newbarenames[barename] = location - newstatus[fullname].index[1] = index + newmappings[index] = fullinfo +-- newfullnames[fullname] = location + newbasenames[basename] = location + newbarenames[barename] = location + newstatus[entryname].index[1] = index end else --- missing info - report("log", 1, "db", "failed to load “%s”", entryname) + report("log", 1, "db", "failed to load “%s”", basename) return false end return true @@ -1073,7 +1084,7 @@ end --doc]]-- --- string -> dbobj -> dbobj -> bool -> (int * int) -local scan_dir = function (dirname, fontnames, newfontnames, dry_run) +local scan_dir = function (dirname, fontnames, newfontnames, dry_run, texmf) local n_scanned, n_new = 0, 0 --- total of fonts collected report("both", 2, "db", "scanning directory %s", dirname) for _,i in next, font_extensions do @@ -1092,7 +1103,7 @@ local scan_dir = function (dirname, fontnames, newfontnames, dry_run) report("both", 1, "db", "would have been loading “%s”", fullname) else report("both", 4, "db", "loading font “%s”", fullname) - local new = load_font(fullname, fontnames, newfontnames) + local new = load_font(fullname, fontnames, newfontnames, texmf) if new == true then n_new = n_new + 1 end @@ -1121,7 +1132,7 @@ local scan_texmf_fonts = function (fontnames, newfontnames, dry_run) if not stringis_empty(fontdirs) then for _,d in next, filesplitpath(fontdirs) do report("info", 4, "db", "Entering directory %s", d) - local found, new = scan_dir(d, fontnames, newfontnames, dry_run) + local found, new = scan_dir(d, fontnames, newfontnames, dry_run, true) n_scanned = n_scanned + found n_new = n_new + new end @@ -1356,7 +1367,7 @@ end --- read_fonts_conf closure --- TODO stuff those paths into some writable table --- unit -> string list -local function get_os_dirs() +local function get_os_dirs () if os.name == 'macosx' then return { filejoin(kpseexpand_path('~'), "Library/Fonts"), diff --git a/luaotfload.dtx b/luaotfload.dtx index e75a561..b4b7940 100644 --- a/luaotfload.dtx +++ b/luaotfload.dtx @@ -1948,7 +1948,7 @@ local patch_defined_font = function (specification, size, id) return tfmdata end -reset_callback("define_font") +reset_callback "define_font" % \end{macrocode} % Finally we register the callbacks. -- cgit v1.2.3 From cdc347c5136e1c6e330fb81af0912103361b0f3e Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 27 May 2013 14:26:44 +0200 Subject: sync with Context as of 2013-05-27 --- luaotfload-merged.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/luaotfload-merged.lua b/luaotfload-merged.lua index 5789db6..8a9e5fc 100644 --- a/luaotfload-merged.lua +++ b/luaotfload-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 05/22/13 19:28:51 +-- merge date : 05/27/13 11:01:26 do -- begin closure to overcome local limits and interference @@ -4691,9 +4691,9 @@ mappings.makenameparser=makenameparser mappings.tounicode16=tounicode16 mappings.tounicode16sequence=tounicode16sequence mappings.fromunicode16=fromunicode16 -local separator=S("_.") -local other=C((1-separator)^1) -local ligsplitter=Ct(other*(separator*other)^0) +local ligseparator=P("_") +local varseparator=P(".") +local namesplitter=Ct(C((1-ligseparator-varseparator)^1)*(ligseparator*C((1-ligseparator-varseparator)^1))^0) function mappings.addtounicode(data,filename) local resources=data.resources local properties=data.properties @@ -4778,11 +4778,11 @@ function mappings.addtounicode(data,filename) end end if not unicode or unicode=="" then - local split=lpegmatch(ligsplitter,name) - local nplit=split and #split or 0 - if nplit>=2 then + local split=lpegmatch(namesplitter,name) + local nsplit=split and #split or 0 + if nsplit>=2 then local t,n={},0 - for l=1,nplit do + for l=1,nsplit do local base=split[l] local u=unicodes[base] or unicodevector[base] if not u then -- cgit v1.2.3 From 1ef6591eecdbb9cd047b80992dc71beb287fa3e6 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 27 May 2013 15:10:21 +0200 Subject: implement kpse-only font resolver --- luaotfload.dtx | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/luaotfload.dtx b/luaotfload.dtx index b4b7940..83885a0 100644 --- a/luaotfload.dtx +++ b/luaotfload.dtx @@ -1797,7 +1797,7 @@ loadmodule"colors.lua" --- “font-clr” % \begin{macrocode} local request_resolvers = fonts.definers.resolvers -local formats = fonts.formats +local formats = fonts.formats -- nice table; does lowercasing ... formats.ofm = "type1" % \end{macrocode} @@ -1916,6 +1916,33 @@ request_resolvers.path = function (specification) end end +% \end{macrocode} +% {\bfseries EXPERIMENTAL} +% \identifier{kpse}-only resolver, for those who can do without system +% fonts. +% +% \begin{macrocode} + +request_resolvers.kpse = function (specification) + local name = specification.name + local suffix = file.suffix(name) + if suffix and formats[suffix] then + name = file.removesuffix(name) + if resolvers.findfile(name, suffix) then + specification.forced = suffix + specification.name = name + return + end + end + for t, format in next, formats do --- brute force + if kpse.find_file (name, format) then + specification.forced = t + specification.name = name + return + end + end +end + % \end{macrocode} % We create a callback for patching fonts on the fly, to be used by other % packages. -- cgit v1.2.3 From 2dd656af102316c8846acd095cb8eccdc8b41e53 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 27 May 2013 15:17:20 +0200 Subject: install kpse lookup --- luaotfload-features.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/luaotfload-features.lua b/luaotfload-features.lua index a68eb04..cbdc36b 100644 --- a/luaotfload-features.lua +++ b/luaotfload-features.lua @@ -1004,6 +1004,8 @@ local prefixed = P"name:" * ws * Cg(fontname, "name") --- we’ll emit a warning. + P"file:" * ws * Cg(unsupported, "path") + P"file:" * ws * Cg(fontname, "file") +--- EXPERIMENTAL: kpse lookup + + P"kpse:" * ws * Cg(fontname, "kpse") local unprefixed = Cg(fontname, "anon") local path_lookup = lbrk * Cg(C((1-rbrk)^1), "path") * rbrk @@ -1069,7 +1071,7 @@ local import_values = { { "mode", true }, } -local lookup_types = { "anon", "file", "name", "path" } +local lookup_types = { "anon", "file", "kpse", "name", "path" } local select_lookup = function (request) for i=1, #lookup_types do -- cgit v1.2.3 From ee9575c0015f06571d238a87e982595c9d996c54 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 27 May 2013 16:38:28 +0200 Subject: provide hook for custom font resolver --- luaotfload-features.lua | 8 +++++--- luaotfload.dtx | 13 ++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/luaotfload-features.lua b/luaotfload-features.lua index cbdc36b..c405ae5 100644 --- a/luaotfload-features.lua +++ b/luaotfload-features.lua @@ -1003,9 +1003,11 @@ local prefixed = P"name:" * ws * Cg(fontname, "name") --- with paths already, so we’ll add a less strict rule here. anyways, --- we’ll emit a warning. + P"file:" * ws * Cg(unsupported, "path") - + P"file:" * ws * Cg(fontname, "file") + + P"file:" * ws * Cg(fontname, "file") --- EXPERIMENTAL: kpse lookup - + P"kpse:" * ws * Cg(fontname, "kpse") + + P"kpse:" * ws * Cg(fontname, "kpse") +--- EXPERIMENTAL: custom lookup + + P"my:" * ws * Cg(fontname, "my") local unprefixed = Cg(fontname, "anon") local path_lookup = lbrk * Cg(C((1-rbrk)^1), "path") * rbrk @@ -1071,7 +1073,7 @@ local import_values = { { "mode", true }, } -local lookup_types = { "anon", "file", "kpse", "name", "path" } +local lookup_types = { "anon", "file", "kpse", "my", "name", "path" } local select_lookup = function (request) for i=1, #lookup_types do diff --git a/luaotfload.dtx b/luaotfload.dtx index 83885a0..7beca09 100644 --- a/luaotfload.dtx +++ b/luaotfload.dtx @@ -1917,7 +1917,7 @@ request_resolvers.path = function (specification) end % \end{macrocode} -% {\bfseries EXPERIMENTAL} +% {\bfseries EXPERIMENTAL}: % \identifier{kpse}-only resolver, for those who can do without system % fonts. % @@ -1943,6 +1943,17 @@ request_resolvers.kpse = function (specification) end end +% \end{macrocode} +% Also {\bfseries EXPERIMENTAL}: +% custom file resolvers via callback. +% +% \begin{macrocode} +create_callback("luaotfload.resolve_font", "simple", dummy_function) + +request_resolvers.my = function (specification) + call_callback("luaotfload.resolve_font", specification) +end + % \end{macrocode} % We create a callback for patching fonts on the fly, to be used by other % packages. -- cgit v1.2.3 From a537c457fa3490f6028c38374601689dce60fe86 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 27 May 2013 17:24:46 +0200 Subject: fix bug that erased the db when suppressing updates --- luaotfload-database.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 25c136b..0f2f8dd 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -1425,7 +1425,7 @@ update_names = function (fontnames, force, dry_run) report("info", 2, "db", "skipping database update") --- skip all db updates - return fontnames + return fontnames or names.data end local starttime = os.gettimeofday() local n_scanned, n_new = 0, 0 -- cgit v1.2.3 From 6eaf632495bcd4a22f3e1067e0f76b7b512a85f4 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 27 May 2013 17:24:46 +0200 Subject: fix bug that erased the db when suppressing updates --- luaotfload-database.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 60e321f..c160121 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -1414,7 +1414,7 @@ update_names = function (fontnames, force, dry_run) report("info", 2, "db", "skipping database update") --- skip all db updates - return fontnames + return fontnames or names.data end local starttime = os.gettimeofday() local n_scanned, n_new = 0, 0 -- cgit v1.2.3 From c13e7e963412412db7c1564e746080335e595049 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 27 May 2013 19:21:03 +0200 Subject: prepare db structure for texmf prioritization --- luaotfload-database.lua | 132 ++++++++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 55 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 0f2f8dd..29807fe 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -28,6 +28,7 @@ local kpselookup = kpse.lookup local kpsereadable_file = kpse.readable_file local lfsisdir = lfs.isdir local lfsisfile = lfs.isfile +local lfsattributes = lfs.attributes local mathabs = math.abs local mathmin = math.min local stringfind = string.find @@ -146,9 +147,16 @@ This is a sketch of the luaotfload db: fullname : string; psname : string; subfamily : string; - } + }; + sanitized : { + family : string; + fullname : string; + psname : string; + subfamily : string; + }; size : int list; slant : int; + texmf : bool; weight : int; width : int; units_per_em : int; // mainly 1000, but also 2048 or 256 @@ -482,6 +490,18 @@ local add_to_match = function ( return found, continue end +--[[doc-- +Existence of the resolved file name is verified differently depending +on whether the index entry has a texmf flag set. +--doc]]-- + +local is_file = function (filename, texmf) + if texmf == true then + return kpselookup(filename) + end + return lfsisfile(filename) +end + --[[doc-- Luatex-fonts, the font-loader package luaotfload imports, comes with @@ -553,15 +573,20 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con if db_version ~= nms_version then report("log", 0, "db", [[version mismatch; expected %4.3f, got %4.3f]], - nms_version, db_version - ) - return reload_db("version mismatch", resolve, nil, nil, specification) + nms_version, db_version) + if not fonts_reloaded then + return reload_db("version mismatch", + resolve, nil, nil, specification) + end + return specification.name, false, false end if not data.mappings then - return reload_db("invalid database; missing font mapping", - resolve, nil, nil, specification - ) + if not fonts_reloaded then + return reload_db("invalid database; missing font mapping", + resolve, nil, nil, specification) + end + return specification.name, false, false end local found = { } @@ -635,13 +660,14 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con if #found == 1 then --- “found” is really synonymous with “registered in the db”. - local filename = found[1].filename[1] - if lfsisfile(filename) or kpselookup(filename) then + local entry = found[1] + local filename = entry.filename[1] + if is_file(filename, entry.texmf) then report("log", 0, "resolve", "font family='%s', subfamily='%s' found: %s", name, style, filename ) - return filename, found[1].filename[2], true + return filename, entry.filename[2], true end elseif #found > 1 then -- we found matching font(s) but not in the requested optical @@ -658,7 +684,7 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con end end local filename = closest.filename[1] - if lfsisfile(filename) or kpselookup(filename) then + if is_file(filename, closest.texmf) then report("log", 0, "resolve", "font family='%s', subfamily='%s' found: %s", name, style, filename @@ -690,7 +716,7 @@ end --- resolve() --- string -> ('a -> 'a) -> 'a list -> 'a reload_db = function (why, caller, ...) report("both", 1, "db", "reload initiated; reason: “%s”", why) - names.data = update_names() + names.data = update_names(names.data, false, false) local success = save_names() if success then fonts_reloaded = true @@ -737,7 +763,10 @@ find_closest = function (name, limit) local data = names.data if type(data) ~= "table" then - return reload_db("no database", find_closest, name) + if not fonts_reloaded then + return reload_db("no database", find_closest, name) + end + return false end local by_distance = { } --- (int, string list) dict local distances = { } --- int list @@ -812,7 +841,8 @@ The data inside an Opentype font file can be quite heterogeneous. Thus in order to get the relevant information, parts of the original table as returned by the font file reader need to be relocated. --doc]]-- -font_fullinfo = function (filename, subfont) +--- string -> int -> bool -> string -> fontentry +font_fullinfo = function (filename, subfont, texmf, basename) local tfmdata = { } local rawfont = fontloaderopen(filename, subfont) if not rawfont then @@ -859,7 +889,13 @@ font_fullinfo = function (filename, subfont) tfmdata.fontname = metadata.fontname tfmdata.fullname = metadata.fullname tfmdata.familyname = metadata.familyname - tfmdata.filename = { filename, subfont } -- always store full path + if texmf == true then --- ugh, ugliness levels peaking here + tfmdata.filename = { barename, subfont } + tfmdata.texmf = true + else + tfmdata.filename = { filename, subfont } + tfmdata.texmf = false + end tfmdata.weight = metadata.pfminfo.weight tfmdata.width = metadata.pfminfo.width tfmdata.slant = metadata.italicangle @@ -885,15 +921,8 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) local newmappings = newfontnames.mappings local newstatus = newfontnames.status --- local newfullnames = newfontnames.fullnames - local newbasenames = newfontnames.basenames - local newbarenames = newfontnames.barenames - local mappings = fontnames.mappings local status = fontnames.status --- local fullnames = fontnames.fullnames - local basenames = fontnames.basenames - local barenames = fontnames.barenames local basename = filebasename(fullname) local barename = filenameonly(fullname) @@ -910,36 +939,34 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) return false end - local timestamp, db_timestamp - db_timestamp = status[entryname] - and status[entryname].timestamp - timestamp = lfs.attributes(fullname, "modification") + local new_timestamp, current_timestamp + current_timestamp = status[entryname] + and status[entryname].timestamp + new_timestamp = lfsattributes(fullname, "modification") - local index_status = newstatus[entryname] - --- index_status: nil | false | table - if index_status and index_status.timestamp == timestamp then + local newentrystatus = newstatus[entryname] + --- newentrystatus: nil | false | table + if newentrystatus and newentrystatus.timestamp == new_timestamp then -- already indexed this run return false end - newstatus[entryname] = newstatus[entryname] or { } - newstatus[entryname].timestamp = timestamp - newstatus[entryname].index = newstatus[entryname].index or { } + newstatus[entryname] = newentrystatus or { } + local newentrystatus = newstatus[entryname] + newentrystatus.timestamp = new_timestamp + newentrystatus.index = newentrystatus.index or { } - --- this test compares the modification data registered + --- this test compares the modification date registered --- in the database with the current one - if db_timestamp == timestamp - and not newstatus[entryname].index[1] + if current_timestamp == new_timestamp + and not newentrystatus.index[1] then for _, v in next, status[entryname].index do - local index = #newstatus[entryname].index + local index = #newentrystatus.index local fullinfo = mappings[v] local location = #newmappings + 1 - newmappings[location] = fullinfo --- keep - newstatus[entryname].index[index+1] = location --- is this actually used anywhere? --- newfullnames[fullname] = location - newbasenames[basename] = location - newbarenames[barename] = location + newmappings[location] = fullinfo --- keep + newentrystatus.index[index+1] = location --- is this actually used anywhere? end report("log", 2, "db", "font “%s” already indexed", basename) return false @@ -949,34 +976,29 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) if info then if type(info) == "table" and #info > 1 then --- ttc for n_font = 1, #info do - local fullinfo = font_fullinfo(fullname, n_font-1) + local fullinfo = font_fullinfo(fullname, n_font-1, texmf, barename) if not fullinfo then return false end + fullinfo.texmf = texmf --- flag for resolver local location = #newmappings+1 - local index = newstatus[entryname].index[n_font] + local index = newentrystatus.index[n_font] if not index then index = location end - newmappings[index] = fullinfo --- newfullnames[fullname] = location - newbasenames[basename] = location - newbarenames[barename] = location - newstatus[entryname].index[n_font] = index + newmappings[index] = fullinfo + newentrystatus.index[n_font] = index end else - local fullinfo = font_fullinfo(fullname, false) + local fullinfo = font_fullinfo(fullname, false, texmf, barename) if not fullinfo then return false end local location = #newmappings+1 - local index = newstatus[entryname].index[1] + local index = newentrystatus.index[1] if not index then index = location end - newmappings[index] = fullinfo --- newfullnames[fullname] = location - newbasenames[basename] = location - newbarenames[barename] = location - newstatus[entryname].index[1] = index + newmappings[index] = fullinfo + newentrystatus.index[1] = index end else --- missing info -- cgit v1.2.3 From 2fafd168d0cd3860e2ca699a6c3c24159cb826d1 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 27 May 2013 20:28:39 +0200 Subject: restructure db --- luaotfload-database.lua | 81 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 10 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 29807fe..bd35fbb 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -1,5 +1,5 @@ if not modules then modules = { } end modules ['luaotfload-database'] = { - version = 2.2, + version = 2.3, comment = "companion to luaotfload.lua", author = "Khaled Hosny, Elie Roux, Philipp Gesang", copyright = "Luaotfload Development Team", @@ -17,6 +17,7 @@ local next = next local pcall = pcall local require = require local tonumber = tonumber +local unpack = table.unpack local fontloaderinfo = fontloader.info local fontloaderopen = fontloader.open @@ -133,9 +134,13 @@ This is a sketch of the luaotfload db: mappings : fontentry list; status : filestatus; version : float; - // preliminary additions of v2.2: - basenames : (string, int) hash; // where int is the index in mappings - barenames : (string, int) hash; // where int is the index in mappings + // additions of v2.3; these supersede the basenames / barenames + // hashes from v2.2 + filenames : { + base : (string, int) hash; // basename -> idx + bare : (string, int) hash; // barename -> idx + full : (int, string) hash; // idx -> full path + } } and fontentry = { familyname : string; @@ -204,9 +209,7 @@ local fontnames_init = function (keep_cache) --- returns dbobj return { mappings = { }, status = { }, - barenames = { }, - basenames = { }, --- fullnames = { }, // -> status +-- filenames = { }, -- created later version = names.version, } end @@ -890,7 +893,7 @@ font_fullinfo = function (filename, subfont, texmf, basename) tfmdata.fullname = metadata.fullname tfmdata.familyname = metadata.familyname if texmf == true then --- ugh, ugliness levels peaking here - tfmdata.filename = { barename, subfont } + tfmdata.filename = { basename, subfont } tfmdata.texmf = true else tfmdata.filename = { filename, subfont } @@ -976,7 +979,7 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) if info then if type(info) == "table" and #info > 1 then --- ttc for n_font = 1, #info do - local fullinfo = font_fullinfo(fullname, n_font-1, texmf, barename) + local fullinfo = font_fullinfo(fullname, n_font-1, texmf, basename) if not fullinfo then return false end @@ -989,7 +992,7 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) newentrystatus.index[n_font] = index end else - local fullinfo = font_fullinfo(fullname, false, texmf, barename) + local fullinfo = font_fullinfo(fullname, false, texmf, basename) if not fullinfo then return false end @@ -1438,6 +1441,60 @@ flush_lookup_cache = function () return true, names.lookups end +--- dbobj -> dbobj +local gen_fast_lookups = function (fontnames) + report("both", 2, "db", "creating filename map") + local texmf_wins = config.luaotfload.texmf_wins + local mappings = fontnames.mappings + local nmappings = #mappings + --- this is needlessly complicated due to texmf priorization + local filenames = { + bare = { }, + base = { }, + full = { }, --- non-texmf + } + + local texmf, sys = { }, { } -- quintuple list + + for idx = 1, nmappings do + local entry = mappings[idx] + local filename = entry.filename[1] + if entry.texmf == true then + bare = filenameonly(filename) + texmf[#texmf+1] = { idx, filename, bare, true, nil } + else + --- filename contains full path + base = filebasename(filename) + bare = filenameonly(filename) + sys[#sys+1] = { idx, base, bare, false, filename } + end + end + + local addmap = function (lst) + --- this will overwrite existing entries + for i=1, #lst do + local idx, base, bare, texmf, full = unpack(lst[i]) + filenames.bare[bare] = idx + filenames.base[base] = idx + if texmf ~= true then + filenames.full[idx] = full + end + end + end + + if config.luaotfload.prioritize == "texmf" then + report("both", 2, "db", "preferring texmf fonts") + addmap(sys) + addmap(texmf) + else --- sys + addmap(texmf) + addmap(sys) + end + + fontnames.filenames = filenames + return fontnames +end + --- force: dictate rebuild from scratch --- dry_dun: don’t write to the db, just scan dirs @@ -1483,6 +1540,10 @@ update_names = function (fontnames, force, dry_run) n_scanned = n_scanned + scanned n_new = n_new + new + if n_new > 0 then + newfontnames = gen_fast_lookups(newfontnames) + end + --- stats: --- before rewrite | after rewrite --- partial: 804 ms | 701 ms -- cgit v1.2.3 From 687653fa50ee06c6a1de26231f56dc01ec25ef73 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 27 May 2013 21:21:41 +0200 Subject: adapt file lookups --- luaotfload-database.lua | 91 +++++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 34 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index bd35fbb..3a0d61e 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -134,13 +134,14 @@ This is a sketch of the luaotfload db: mappings : fontentry list; status : filestatus; version : float; - // additions of v2.3; these supersede the basenames / barenames + // new in v2.3; these supersede the basenames / barenames // hashes from v2.2 - filenames : { - base : (string, int) hash; // basename -> idx - bare : (string, int) hash; // barename -> idx - full : (int, string) hash; // idx -> full path - } + filenames : filemap; + } + and filemap = { + base : (string, int) hash; // basename -> idx + bare : (string, int) hash; // barename -> idx + full : (int, string) hash; // idx -> full path } and fontentry = { familyname : string; @@ -333,32 +334,47 @@ end local type1_formats = { "tfm", "ofm", } ---- string -> string +local dummy_findfile = resolvers.findfile -- from basics-gen + +--- filemap -> string -> string -> (string | bool) +local verbose_lookup = function (data, kind, filename) + local found = data[kind][filename] + if found ~= nil then + found = data.full[found] + if found == nil then --> texmf + report("info", 0, "db", + "crude file lookup: req=%s; hit=%s => kpse", + filename, kind) + found = dummy_findfile(filename) + else + report("info", 0, "db", + "crude file lookup: req=%s; hit=%s; ret=%s", + filename, kind, found) + end + return found + end + return false +end + +--- string -> (string | string * string) crude_file_lookup_verbose = function (filename) if not names.data then names.data = load_names() end local data = names.data local mappings = data.mappings + local filenames = data.filenames local found --- look up in db first ... - found = data.barenames[filename] - if found and mappings[found] then - found = mappings[found].filename[1] - report("info", 0, "db", - "crude file lookup: req=%s; hit=bare; ret=%s", - filename, found) + found = verbose_lookup(filenames, "bare", filename) + if found then return found end - found = data.basenames[filename] - if found and mappings[found] then - found = mappings[found].filename[1] - report("info", 0, "db", - "crude file lookup: req=%s; hit=base; ret=%s", - filename, found) + found = verbose_lookup(filenames, "base", filename) + if found then return found end - --- ofm and tfm + --- ofm and tfm, returns pair for i=1, #type1_formats do local format = type1_formats[i] if resolvers.findfile(filename, format) then @@ -368,22 +384,25 @@ crude_file_lookup_verbose = function (filename) return filename, nil end -local dummy_findfile = resolvers.findfile -- from basics-gen - ---- string -> string +--- string -> (string | string * string) crude_file_lookup = function (filename) - local found = dummy_findfile(filename) - if found then - return found - end if not names.data then names.data = load_names() end local data = names.data local mappings = data.mappings - found = data.barenames[filename] - or data.basenames[filename] + local filenames = data.filenames + + local found + + found = filenames.base[filename] + or filenames.bare[filename] + if found then - found = data.mappings[found] - if found then return found.filename[1] end + found = filenames.full[found] + if found == nil then + return dummy_findfile(filename) + else + return found + end end for i=1, #type1_formats do local format = type1_formats[i] @@ -1437,7 +1456,7 @@ end flush_lookup_cache = function () if not names.lookups then names.lookups = load_lookups() end names.lookups = { } - collectgarbage"collect" + collectgarbage "collect" return true, names.lookups end @@ -1473,10 +1492,12 @@ local gen_fast_lookups = function (fontnames) local addmap = function (lst) --- this will overwrite existing entries for i=1, #lst do - local idx, base, bare, texmf, full = unpack(lst[i]) + local idx, base, bare, intexmf, full = unpack(lst[i]) filenames.bare[bare] = idx filenames.base[base] = idx - if texmf ~= true then + if intexmf == true then + filenames.full[idx] = nil + else filenames.full[idx] = full end end @@ -1492,6 +1513,8 @@ local gen_fast_lookups = function (fontnames) end fontnames.filenames = filenames + texmf, sys = nil, nil + collectgarbage "collect" return fontnames end -- cgit v1.2.3 From c7d9945cbece75331c9342ce0a8eaa9c37a0a06b Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 27 May 2013 22:15:06 +0200 Subject: add option prefer-texmf to luaotfload-tool --- luaotfload-database.lua | 20 ++++++++------------ luaotfload-tool.lua | 6 +++++- luaotfload-tool.rst | 7 +++++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 3a0d61e..e7d4bf9 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -941,7 +941,7 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) end local newmappings = newfontnames.mappings - local newstatus = newfontnames.status + local newstatus = newfontnames.status --- by full path local mappings = fontnames.mappings local status = fontnames.status @@ -962,28 +962,26 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) end local new_timestamp, current_timestamp - current_timestamp = status[entryname] - and status[entryname].timestamp + current_timestamp = status[fullname] + and status[fullname].timestamp new_timestamp = lfsattributes(fullname, "modification") - local newentrystatus = newstatus[entryname] + local newentrystatus = newstatus[fullname] --- newentrystatus: nil | false | table if newentrystatus and newentrystatus.timestamp == new_timestamp then -- already indexed this run return false end - newstatus[entryname] = newentrystatus or { } - local newentrystatus = newstatus[entryname] + newstatus[fullname] = newentrystatus or { } + local newentrystatus = newstatus[fullname] newentrystatus.timestamp = new_timestamp newentrystatus.index = newentrystatus.index or { } - --- this test compares the modification date registered - --- in the database with the current one if current_timestamp == new_timestamp and not newentrystatus.index[1] then - for _, v in next, status[entryname].index do + for _, v in next, status[fullname].index do local index = #newentrystatus.index local fullinfo = mappings[v] local location = #newmappings + 1 @@ -1002,7 +1000,6 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) if not fullinfo then return false end - fullinfo.texmf = texmf --- flag for resolver local location = #newmappings+1 local index = newentrystatus.index[n_font] if not index then index = location end @@ -1127,7 +1124,7 @@ end --doc]]-- ---- string -> dbobj -> dbobj -> bool -> (int * int) +--- string -> dbobj -> dbobj -> bool -> bool -> (int * int) local scan_dir = function (dirname, fontnames, newfontnames, dry_run, texmf) local n_scanned, n_new = 0, 0 --- total of fonts collected report("both", 2, "db", "scanning directory %s", dirname) @@ -1463,7 +1460,6 @@ end --- dbobj -> dbobj local gen_fast_lookups = function (fontnames) report("both", 2, "db", "creating filename map") - local texmf_wins = config.luaotfload.texmf_wins local mappings = fontnames.mappings local nmappings = #mappings --- this is needlessly complicated due to texmf priorization diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 721e3cf..9479180 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -172,6 +172,7 @@ This tool is part of the luaotfload package. Valid options are: -f --force force re-indexing all fonts -l --flush-lookups empty lookup cache of font requests -D --dry-run skip loading of fonts, just scan + -p --prefer-texmf prefer fonts in the TEXMF over system fonts --find="font name" query the database for a font name -F --fuzzy look for approximate matches if --find fails @@ -562,13 +563,14 @@ local process_cmdline = function ( ) -- unit -> jobspec limit = 1, list = 1, log = 1, + ["prefer-texmf"] = "p", quiet = "q", update = "u", verbose = 1 , version = "V", } - local short_options = "DfFilquvVh" + local short_options = "DfFilpquvVh" local options, _, optarg = alt_getopt.get_ordered_opts (arg, short_options, long_options) @@ -629,6 +631,8 @@ local process_cmdline = function ( ) -- unit -> jobspec result.cache = optarg[n] elseif v == "D" then result.dry_run = true + elseif v == "p" then + config.luaotfload.prioritize = "texmf" end end diff --git a/luaotfload-tool.rst b/luaotfload-tool.rst index 9ea267b..a428375 100644 --- a/luaotfload-tool.rst +++ b/luaotfload-tool.rst @@ -15,9 +15,9 @@ SYNOPSIS ======================================================================= -**luaotfload** [ -cfFiquvVh ] +**luaotfload** [ -cfFipquvVh ] -**luaotfload** --update [ --force ] [ --quiet ] [ --verbose ] [ --dry-run ] +**luaotfload** --update [ --force ] [ --quiet ] [ --verbose ] [ --prefer-texmf ] [ --dry-run ] **luaotfload** --find=FONTNAME [ --fuzzy ] [ --info ] @@ -55,6 +55,9 @@ update mode --update, -u Update the database; indexes new fonts. --force, -f Force rebuilding of the database; re-indexes all fonts. +--prefer-texmf, -p Organize the file name database in a way so + that it prefer fonts in the *TEXMF* tree over + system fonts if they are installed in both. --dry-run, -D Don’t load fonts, scan directories only. (For debugging file system related issues.) -- cgit v1.2.3 From e263928dfb028952384103d1edc98cea467d4555 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 27 May 2013 22:38:01 +0200 Subject: log duplicate fonts --- luaotfload-database.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index e7d4bf9..65f2bf7 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -1489,6 +1489,18 @@ local gen_fast_lookups = function (fontnames) --- this will overwrite existing entries for i=1, #lst do local idx, base, bare, intexmf, full = unpack(lst[i]) + + local known = filenames.base[base] or filenames.bare[bare] + if known then --- known + report("both", 1, "db", + "font file “%s” already indexed (%d)", + base, idx) + report("both", 2, "db", "> old location: %s", + (filenames.full[known] or "texmf")) + report("both", 2, "db", "> new location: %s", + (intexmf and "texmf" or full)) + end + filenames.bare[bare] = idx filenames.base[base] = idx if intexmf == true then -- cgit v1.2.3 From acb76cca1c0bdedc811d7eeed1b2392b692cdf50 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 28 May 2013 22:26:14 +0200 Subject: have file locator return the filename when known fonts are specified without extension --- luaotfload-database.lua | 5 ++--- luaotfload-tool.lua | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 65f2bf7..aba1921 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -399,10 +399,9 @@ crude_file_lookup = function (filename) if found then found = filenames.full[found] if found == nil then - return dummy_findfile(filename) - else - return found + found = dummy_findfile(filename) end + return found or filename end for i=1, #type1_formats do local format = type1_formats[i] diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 9479180..a379633 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -546,7 +546,7 @@ local process_cmdline = function ( ) -- unit -> jobspec force_reload = nil, criterion = "", query = "", - log_level = 1, --- 2 is approx. the old behavior + log_level = 0, --- 2 is approx. the old behavior } local long_options = { -- cgit v1.2.3 From 6ad1f8f479da97b4cf7eb17b05050593883dde49 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 29 May 2013 19:50:30 +0200 Subject: use unbuffered stdout --- luaotfload-database.lua | 5 ++-- luaotfload-override.lua | 64 ++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index aba1921..813a471 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -285,8 +285,9 @@ load_names = function (dry_run) 1000*(os.gettimeofday()-starttime)) else report("both", 0, "db", - [[Font names database not found, generating new one. - This can take several minutes; please be patient.]]) + [[Font names database not found, generating new one.]]) + report("both", 0, "db", + [[This can take several minutes; please be patient.]]) data = update_names(fontnames_init(false), nil, dry_run) local success = save_names(data) if not success then diff --git a/luaotfload-override.lua b/luaotfload-override.lua index 5e642e4..caf3627 100644 --- a/luaotfload-override.lua +++ b/luaotfload-override.lua @@ -1,17 +1,30 @@ if not modules then modules = { } end modules ['luat-ovr'] = { - version = 2.2, + version = 2.3, comment = "companion to luatex-*.tex", author = "Khaled Hosny, Elie Roux, Philipp Gesang", copyright = "Luaotfload Development Team", license = "GNU GPL v2" } -local module_name = "luaotfload" +--[[doc-- +The logging system is slow in general, as we always have the function +call overhead even if we aren’t going to output anything. On the other +hand, the more efficient approach followed by Context isn’t an option +because we lack a user interface to toggle per-subsystem tracing. +--doc]]-- + +local module_name = "luaotfload" -local texiowrite_nl = texio.write_nl -local stringformat = string.format -local tableconcat = table.concat -local type = type +local select = select +local stringformat = string.format +local tableconcat = table.concat +local texiowrite_nl = texio.write_nl +local texiowrite = texio.write +local type = type + +local texio_write_nl = texio.write_nl +local texio_write = texio.write +local iowrite = io.write --[[doc-- We recreate the verbosity levels previously implemented in font-nms: @@ -65,11 +78,40 @@ local log = function (category, fmt, ...) texiowrite_nl(logout, tableconcat(res)) end -local stdout = function (category, fmt, ...) - local res = { module_name, " |" } - if category then res[#res+1] = " " .. category end - if fmt then res[#res+1] = ": " .. stringformat(fmt, ...) end - texiowrite_nl(tableconcat(res)) +--- with faux db update with maximum verbosity: +--- +--- --------- -------- +--- buffering time (s) +--- --------- -------- +--- full 4.12 +--- line 4.20 +--- none 4.39 +--- --------- -------- +--- + +io.stdout:setvbuf "no" +io.stderr:setvbuf "no" + +local writeln +if tex and (tex.jobname or tex.formatname) then + --- TeX + writeln = texiowrite_nl +else + --- Lua interpreter + writeln = function (str) + iowrite(str) + iowrite "\n" + end +end + +stdout = function (category, ...) + local res = { module_name, "|", category, ":" } + if select("#", ...) == 1 then + res[#res+1] = select(1, ...) -- around 30% faster than unpack() + else + res[#res+1] = stringformat(...) + end + writeln(tableconcat(res, " ")) end --- at default (zero), we aim to be quiet -- cgit v1.2.3 From dd88b90a7582a94f89db8c5f8a29178305497c0a Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 30 May 2013 01:54:03 +0200 Subject: rebuild filename lookup table upon --force --- luaotfload-database.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 813a471..d670322 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -1571,7 +1571,7 @@ update_names = function (fontnames, force, dry_run) n_scanned = n_scanned + scanned n_new = n_new + new - if n_new > 0 then + if force or n_new > 0 then newfontnames = gen_fast_lookups(newfontnames) end -- cgit v1.2.3 From 49ed6facc71c3db519d5baa3723090e086d832aa Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 30 May 2013 02:04:58 +0200 Subject: copy old filenames table if now new fonts were found --- luaotfload-database.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index d670322..4e7d5fb 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -1573,6 +1573,8 @@ update_names = function (fontnames, force, dry_run) if force or n_new > 0 then newfontnames = gen_fast_lookups(newfontnames) + else + newfontnames.filenames = fontnames.filenames end --- stats: -- cgit v1.2.3 From 54c49bfbc560fccaaf0330221e7af6d9153122cb Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 30 May 2013 02:33:21 +0200 Subject: collect second-tier candidates when matching fontnames --- luaotfload-database.lua | 20 ++++++++++++++++++-- luaotfload-tool.lua | 10 +++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 4e7d5fb..d5e2a7b 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -611,9 +611,11 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con return specification.name, false, false end - local found = { } + local found = { } --> collect results + local candidates = { } --> secondary results, incomplete matches + local synonym_set = style_synonyms.set - for _, face in next, data.mappings do + for n, face in next, data.mappings do local family, subfamily, fullname, psname, fontname, pfullname local facenames = face.sanitized @@ -653,6 +655,7 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con minsize, maxsize, face) if continue == false then break end elseif subfamily == "regular" or + --- TODO this match should be performed when building the db synonym_set.regular[subfamily] then found.fallback = face elseif name == fullname @@ -665,6 +668,8 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con found, optsize, dsnsize, size, minsize, maxsize, face) if continue == false then break end + else --- mark as last straw but continue + candidates[#candidates+1] = face end else if name == fullname @@ -717,6 +722,17 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con return found.fallback.filename[1], found.fallback.filename[2], true + elseif next(candidates) then + --- pick the first candidate encountered + local entry = candidates[1] + local filename = entry.filename[1] + if is_file(filename, entry.texmf) then + report("log", 0, "resolve", + "font family='%s', subfamily='%s' found: %s", + name, style, filename + ) + return filename, entry.filename[2], true + end end --- no font found so far diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index a379633..25cc9fa 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -354,24 +354,24 @@ actions.query = function (job) fonts.names.resolve(nil, nil, tmpspec) if success then - logs.names_report(false, 1, + logs.names_report(false, 0, "resolve", "Font “%s” found!", query) if subfont then - logs.names_report(false, 1, "resolve", + logs.names_report(false, 0, "resolve", "Resolved file name “%s”, subfont nr. “%s”", foundname, subfont) else - logs.names_report(false, 1, + logs.names_report(false, 0, "resolve", "Resolved file name “%s”", foundname) end if job.show_info then show_font_info(foundname) end else - logs.names_report(false, 1, + logs.names_report(false, 0, "resolve", "Cannot find “%s”.", query) if job.fuzzy == true then - logs.names_report(false, 1, + logs.names_report(false, 0, "resolve", "Looking for close matches, this may take a while ...") local success = fonts.names.find_closest(query, job.fuzzy_limit) end -- cgit v1.2.3 From 9010a8546ee30db8fb7ab61c0862105ab12c8c49 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 31 May 2013 14:23:29 +0200 Subject: reorganize db record structure --- luaotfload-database.lua | 85 +++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index d5e2a7b..150d30d 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -74,7 +74,7 @@ fonts.definers = fonts.definers or { } local names = fonts.names -names.version = 2.205 +names.version = 2.206 names.data = nil --- contains the loaded database names.lookups = nil --- contains the lookup cache names.path = { @@ -165,9 +165,10 @@ This is a sketch of the luaotfload db: texmf : bool; weight : int; width : int; - units_per_em : int; // mainly 1000, but also 2048 or 256 + units_per_em : int; // mainly 1000, but also 2048 or 256 } - and filestatus = (fullname, { index : int list; timestamp : int }) dict + and filestatus = (fullname, + { index : int list; timestamp : int }) dict beware that this is a reconstruction and may be incomplete. @@ -517,13 +518,22 @@ Existence of the resolved file name is verified differently depending on whether the index entry has a texmf flag set. --doc]]-- -local is_file = function (filename, texmf) - if texmf == true then - return kpselookup(filename) +local get_font_file = function (fullnames, entry) + if entry.texmf == true then + local basename = entry.basename + if kpselookup(basename) then + return true, basename, entry.subfont + end + else + local fullname = fullnames[entry.index] + if lfsisfile(fullname) then + return true, fullname, entry.subfont + end end - return lfsisfile(filename) + return false end + --[[doc-- Luatex-fonts, the font-loader package luaotfload imports, comes with @@ -688,13 +698,13 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con if #found == 1 then --- “found” is really synonymous with “registered in the db”. local entry = found[1] - local filename = entry.filename[1] - if is_file(filename, entry.texmf) then + local success, filename, subfont = get_font_file(data.filenames.full, entry) + if success == true then report("log", 0, "resolve", "font family='%s', subfamily='%s' found: %s", name, style, filename ) - return filename, entry.filename[2], true + return filename, subfont, true end elseif #found > 1 then -- we found matching font(s) but not in the requested optical @@ -710,13 +720,13 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con least = difference end end - local filename = closest.filename[1] - if is_file(filename, closest.texmf) then + local success, filename, subfont = get_font_file(data.filenames.full, closest) + if success == true then report("log", 0, "resolve", "font family='%s', subfamily='%s' found: %s", name, style, filename ) - return filename, closest.filename[2], true + return filename, subfont, true end elseif found.fallback then return found.fallback.filename[1], @@ -725,13 +735,13 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con elseif next(candidates) then --- pick the first candidate encountered local entry = candidates[1] - local filename = entry.filename[1] - if is_file(filename, entry.texmf) then + local success, filename, subfont = get_font_file(data.filenames.full, entry) + if success == true then report("log", 0, "resolve", "font family='%s', subfamily='%s' found: %s", name, style, filename ) - return filename, entry.filename[2], true + return filename, subfont, true end end @@ -927,13 +937,6 @@ font_fullinfo = function (filename, subfont, texmf, basename) tfmdata.fontname = metadata.fontname tfmdata.fullname = metadata.fullname tfmdata.familyname = metadata.familyname - if texmf == true then --- ugh, ugliness levels peaking here - tfmdata.filename = { basename, subfont } - tfmdata.texmf = true - else - tfmdata.filename = { filename, subfont } - tfmdata.texmf = false - end tfmdata.weight = metadata.pfminfo.weight tfmdata.width = metadata.pfminfo.width tfmdata.slant = metadata.italicangle @@ -946,6 +949,13 @@ font_fullinfo = function (filename, subfont, texmf, basename) metadata.design_range_top ~= 0 and metadata.design_range_top or nil, metadata.design_range_bottom ~= 0 and metadata.design_range_bottom or nil, } + + --- file location data (used to be filename field) + tfmdata.filename = filename --> sys + tfmdata.basename = basename --> texmf + tfmdata.texmf = texmf or false + tfmdata.subfont = subfont + return tfmdata end @@ -1489,15 +1499,21 @@ local gen_fast_lookups = function (fontnames) for idx = 1, nmappings do local entry = mappings[idx] - local filename = entry.filename[1] + local filename = entry.filename + local basename = entry.basename + local bare = filenameonly(filename) + local subfont = entry.subfont + + entry.index = idx +--- unfortunately, the sys/texmf schism prevents us from +--- doing away the full name, so we cannot avoid the +--- substantial duplication +-- entry.filename = nil + if entry.texmf == true then - bare = filenameonly(filename) - texmf[#texmf+1] = { idx, filename, bare, true, nil } + texmf[#texmf+1] = { idx, basename, bare, true, nil } else - --- filename contains full path - base = filebasename(filename) - bare = filenameonly(filename) - sys[#sys+1] = { idx, base, bare, false, filename } + sys[#sys+1] = { idx, basename, bare, false, filename } end end @@ -1587,11 +1603,10 @@ update_names = function (fontnames, force, dry_run) n_scanned = n_scanned + scanned n_new = n_new + new - if force or n_new > 0 then - newfontnames = gen_fast_lookups(newfontnames) - else - newfontnames.filenames = fontnames.filenames - end + --- we always generate the file lookup tables because + --- non-texmf entries are redirected there and the mapping + --- needs to be 100% consistent + newfontnames = gen_fast_lookups(newfontnames) --- stats: --- before rewrite | after rewrite -- cgit v1.2.3 From ea43a4d7744081f511cca8281e69b5a5f14c2238 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 31 May 2013 14:58:54 +0200 Subject: fix name fallback --- luaotfload-database.lua | 42 +++++++++++++++++++++++++++++------------- luaotfload-features.lua | 2 +- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 150d30d..ab0eacb 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -144,8 +144,9 @@ This is a sketch of the luaotfload db: full : (int, string) hash; // idx -> full path } and fontentry = { + barename : string; familyname : string; - filename : (string * int); // int: subfont + filename : string; fontname : string; fullname : string; names : { @@ -162,6 +163,7 @@ This is a sketch of the luaotfload db: }; size : int list; slant : int; + subfont : int; texmf : bool; weight : int; width : int; @@ -553,7 +555,7 @@ the font database created by the luaotfload-tool script. --- · normal: set of { ccmp clig itlc kern liga locl mark mkmk rlig } --- · ??? --- · forced: string ---- · lookup: "name" | "file" +--- · lookup: "name" --- · method: string --- · name: string --- · resolved: string @@ -622,6 +624,7 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con end local found = { } --> collect results + local fallback --> e.g. non-matching style (fontspec is anal about this) local candidates = { } --> secondary results, incomplete matches local synonym_set = style_synonyms.set @@ -667,7 +670,7 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con elseif subfamily == "regular" or --- TODO this match should be performed when building the db synonym_set.regular[subfamily] then - found.fallback = face + fallback = face elseif name == fullname or name == pfullname or name == fontname @@ -697,8 +700,9 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con if #found == 1 then --- “found” is really synonymous with “registered in the db”. - local entry = found[1] - local success, filename, subfont = get_font_file(data.filenames.full, entry) + local entry = found[1] + local success, filename, subfont + = get_font_file(data.filenames.full, entry) if success == true then report("log", 0, "resolve", "font family='%s', subfamily='%s' found: %s", @@ -720,7 +724,8 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con least = difference end end - local success, filename, subfont = get_font_file(data.filenames.full, closest) + local success, filename, subfont + = get_font_file(data.filenames.full, closest) if success == true then report("log", 0, "resolve", "font family='%s', subfamily='%s' found: %s", @@ -728,14 +733,25 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con ) return filename, subfont, true end - elseif found.fallback then - return found.fallback.filename[1], - found.fallback.filename[2], - true + elseif fallback then + local success, filename, subfont + = get_font_file(data.filenames.full, fallback) + if success == true then + report("log", 0, "resolve", + "no exact match for request %s; using fallback", + specification.specification + ) + report("log", 0, "resolve", + "font family='%s', subfamily='%s' found: %s", + name, style, filename + ) + return filename, subfont, true + end elseif next(candidates) then --- pick the first candidate encountered - local entry = candidates[1] - local success, filename, subfont = get_font_file(data.filenames.full, entry) + local entry = candidates[1] + local success, filename, subfont + = get_font_file(data.filenames.full, entry) if success == true then report("log", 0, "resolve", "font family='%s', subfamily='%s' found: %s", @@ -754,7 +770,7 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con ) end - --- else, fallback to requested name + --- else, default to requested name return specification.name, false, false end --- resolve() diff --git a/luaotfload-features.lua b/luaotfload-features.lua index c405ae5..a70dace 100644 --- a/luaotfload-features.lua +++ b/luaotfload-features.lua @@ -1175,7 +1175,7 @@ local handle_request = function (specification) local keep = import_values[n][2] local newvalue = request.features[feat] if newvalue then - specification[feat] = request.features[feat] + specification[feat] = request.features[feat] if not keep then request.features[feat] = nil end -- cgit v1.2.3 From 16f32963dc180fa9b495bfe27aadc26c51cff8f9 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 31 May 2013 16:20:59 +0200 Subject: differentiate more name fields when matching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit finally resolves “eb garamond 12” as *eb garamond 12 regular* --- luaotfload-database.lua | 92 ++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index ab0eacb..a19cbfd 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -74,7 +74,7 @@ fonts.definers = fonts.definers or { } local names = fonts.names -names.version = 2.206 +names.version = 2.207 names.data = nil --- contains the loaded database names.lookups = nil --- contains the lookup cache names.path = { @@ -147,23 +147,21 @@ This is a sketch of the luaotfload db: barename : string; familyname : string; filename : string; - fontname : string; - fullname : string; - names : { - family : string; - fullname : string; - psname : string; - subfamily : string; - }; + fontname : string; // <- metadata + fullname : string; // <- metadata sanitized : { - family : string; - fullname : string; - psname : string; - subfamily : string; + family : string; + fontname : string; // <- metadata + fullname : string; // <- namedata.names + metafamily : string; + pfullname : string; + prefmodifiers : string; + psname : string; + subfamily : string; }; size : int list; slant : int; - subfont : int; + subfont : int; texmf : bool; weight : int; width : int; @@ -629,16 +627,19 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con local synonym_set = style_synonyms.set for n, face in next, data.mappings do - local family, subfamily, fullname, psname, fontname, pfullname + local family, subfamily, fullname, prefmodifiers + local psname, fontname, pfullname, metafamily local facenames = face.sanitized if facenames then - family = facenames.family - subfamily = facenames.subfamily - fullname = facenames.fullname - psname = facenames.psname - fontname = facenames.fontname - pfullname = facenames.pfullname + family = facenames.family + subfamily = facenames.subfamily + prefmodifiers = facenames.prefmodifiers + fullname = facenames.fullname + psname = facenames.psname + fontname = facenames.fontname + pfullname = facenames.pfullname + metafamily = facenames.metafamily end fontname = fontname or sanitize_string(face.fontname) pfullname = pfullname or sanitize_string(face.fullname) @@ -652,24 +653,27 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con minsize = optsize[3] and optsize[3] / 10 or dsnsize end - if name == family then - if subfamily == style then - local continue - found, continue = add_to_match( - found, optsize, dsnsize, size, - minsize, maxsize, face) - if continue == false then break end - elseif synonym_set[style] and - synonym_set[style][subfamily] + if name == family + or name == metafamily + then + if style == prefmodifiers + or style == subfamily + or synonym_set[style] and + (synonym_set[style][prefmodifiers] or + synonym_set[style][subfamily]) then local continue found, continue = add_to_match( found, optsize, dsnsize, size, minsize, maxsize, face) if continue == false then break end - elseif subfamily == "regular" or + + elseif prefmodifiers == "regular" + or subfamily == "regular" --- TODO this match should be performed when building the db - synonym_set.regular[subfamily] then + or synonym_set.regular[prefmodifiers] + or synonym_set.regular[subfamily] + then fallback = face elseif name == fullname or name == pfullname @@ -852,7 +856,6 @@ find_closest = function (name, limit) --]] if cnames then local fullname, family = cnames.fullname, cnames.family - family = sanitize_string(family) local dist = cached[family]--- maybe already calculated if not dist then @@ -930,18 +933,19 @@ font_fullinfo = function (filename, subfont, texmf, basename) local names = { --- see --- https://developer.apple.com/fonts/TTRefMan/RM06/Chap6name.html - fullname = namedata.names.compatfull - or namedata.names.fullname, - family = namedata.names.preffamilyname - or namedata.names.family, - subfamily = tfmdata.fontstyle_name - or namedata.names.prefmodifiers - or namedata.names.subfamily, - psname = namedata.names.postscriptname, - pfullname = metadata.fullname, - fontname = metadata.fontname, + fullname = namedata.names.compatfull + or namedata.names.fullname, + family = namedata.names.preffamilyname + or namedata.names.family, + prefmodifiers = namedata.names.prefmodifiers, + subfamily = tfmdata.fontstyle_name + or namedata.names.subfamily, + psname = namedata.names.postscriptname, + pfullname = metadata.fullname, + fontname = metadata.fontname, + metafamily = metadata.familyname, } - tfmdata.names = names +-- tfmdata.names = names tfmdata.sanitized = sanitize_names(names) end end -- cgit v1.2.3 From 92e4b9568de9f5dad3a17ea2c890d6ca2b0a0d7d Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 31 May 2013 18:21:30 +0200 Subject: redo blacklist building allow blacklisting of directories --- luaotfload-database.lua | 120 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 95 insertions(+), 25 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index a19cbfd..d12c554 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -11,6 +11,14 @@ if not modules then modules = { } end modules ['luaotfload-database'] = { --- difficulty with the filenames of the TEXMF tree that are referenced as --- relative paths... +local lpeg = require "lpeg" + +local P, R, S, lpegmatch + = lpeg.P, lpeg.R, lpeg.S, lpeg.match + +local C, Cc, Cf, Cg, Ct + = lpeg.C, lpeg.Cc, lpeg.Cf, lpeg.Cg, lpeg.Ct + --- Luatex builtins local load = load local next = next @@ -1119,13 +1127,80 @@ fonts.path_normalize = path_normalize names.blacklist = { } -local function read_blacklist() +local blacklist = names.blacklist +local p_blacklist --- prefixes of dirs + +--- string list -> string list +local collapse_prefixes = function (lst) + --- avoid redundancies in blacklist + if #lst < 2 then + return lst + end + + tablesort(lst) + local cur = lst[1] + local result = { cur } + for i=2, #lst do + local elm = lst[i] + if stringsub(elm, 1, #cur) ~= cur then + --- different prefix + cur = elm + result[#result+1] = cur + end + end + return result +end + +--- string list -> string list -> (string, bool) hash_t +local create_blacklist = function (blacklist, whitelist) + local result = { } + local dirs = { } + + report("info", 2, "db", "blacklisting “%d” files and directories", + #blacklist) + for i=1, #blacklist do + local entry = blacklist[i] + if lfsisdir(entry) then + dirs[#dirs+1] = entry + else + result[blacklist[i]] = true + end + end + + report("info", 2, "db", "whitelisting “%d” files", #whitelist) + for i=1, #whitelist do + result[whitelist[i]] = nil + end + + dirs = collapse_prefixes(dirs) + + --- build the disjunction of the blacklisted directories + for i=1, #dirs do + local p_dir = P(dirs[i]) + if p_blacklist then + p_blacklist = p_blacklist + p_dir + else + p_blacklist = p_dir + end + end + + if p_blacklist == nil then + --- always return false + p_blacklist = Cc(false) + end + + return result +end + +--- unit -> unit +local read_blacklist = function () local files = { kpselookup("luaotfload-blacklist.cnf", {all=true, format="tex"}) } - local blacklist = names.blacklist + local blacklist = { } local whitelist = { } + --- TODO lpegify if files and type(files) == "table" then for _,v in next, files do for line in iolines(v) do @@ -1133,23 +1208,21 @@ local function read_blacklist() local first_chr = stringsub(line, 1, 1) --- faster than find if first_chr == "%" or stringis_empty(line) then -- comment or empty line + elseif first_chr == "-" then + whitelist[#whitelist+1] = stringsub(line, 2, -1) else - --- this is highly inefficient - line = stringsplit(line, "%")[1] - line = stringstrip(line) - if stringsub(line, 1, 1) == "-" then - whitelist[stringsub(line, 2, -1)] = true - else - report("log", 2, "db", "blacklisted file “%s”", line) - blacklist[line] = true + local cmt = stringfind(line, "%%") + if cmt then + line = stringsub(line, cmt - 1) end + line = stringstrip(line) + report("log", 2, "db", "blacklisted file “%s”", line) + blacklist[#blacklist+1] = line end end end end - for _,fontname in next, whitelist do - blacklist[fontname] = nil - end + names.blacklist = create_blacklist(blacklist, whitelist) end local font_extensions = { "otf", "ttf", "ttc", "dfont" } @@ -1172,8 +1245,13 @@ end --- string -> dbobj -> dbobj -> bool -> bool -> (int * int) local scan_dir = function (dirname, fontnames, newfontnames, dry_run, texmf) + if lpegmatch(p_blacklist, dirname) then + --- ignore + return 0, 0 + end + local n_scanned, n_new = 0, 0 --- total of fonts collected - report("both", 2, "db", "scanning directory %s", dirname) + report("both", 3, "db", "scanning directory %s", dirname) for _,i in next, font_extensions do for _,ext in next, { i, stringupper(i) } do local found = dirglob(stringformat("%s/**.%s$", dirname, ext)) @@ -1243,14 +1321,6 @@ end local read_fonts_conf do --- closure for read_fonts_conf() - local lpeg = require "lpeg" - - local C, Cc, Cf, Cg, Ct - = lpeg.C, lpeg.Cc, lpeg.Cf, lpeg.Cg, lpeg.Ct - - local P, R, S, lpegmatch - = lpeg.P, lpeg.R, lpeg.S, lpeg.match - local alpha = R("az", "AZ") local digit = R"09" local tag_name = C(alpha^1) @@ -1544,12 +1614,12 @@ local gen_fast_lookups = function (fontnames) local known = filenames.base[base] or filenames.bare[bare] if known then --- known - report("both", 1, "db", + report("both", 3, "db", "font file “%s” already indexed (%d)", base, idx) - report("both", 2, "db", "> old location: %s", + report("both", 3, "db", "> old location: %s", (filenames.full[known] or "texmf")) - report("both", 2, "db", "> new location: %s", + report("both", 3, "db", "> new location: %s", (intexmf and "texmf" or full)) end -- cgit v1.2.3 From 7663d687960b44e4f12f89f828752dc52688fc0b Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 31 May 2013 18:39:36 +0200 Subject: add option ``--show-blacklist`` to luaotfload-tool --- luaotfload-database.lua | 6 ++++-- luaotfload-tool.lua | 17 +++++++++++++++-- luaotfload-tool.rst | 5 ++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index d12c554..3d2b073 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -267,6 +267,7 @@ local flush_lookup_cache local font_fullinfo local load_names local load_lookups +local read_blacklist local read_fonts_conf local reload_db local resolve @@ -1193,7 +1194,7 @@ local create_blacklist = function (blacklist, whitelist) end --- unit -> unit -local read_blacklist = function () +read_blacklist = function () local files = { kpselookup("luaotfload-blacklist.cnf", {all=true, format="tex"}) } @@ -1213,7 +1214,7 @@ local read_blacklist = function () else local cmt = stringfind(line, "%%") if cmt then - line = stringsub(line, cmt - 1) + line = stringsub(line, 1, cmt - 1) end line = stringstrip(line) report("log", 2, "db", "blacklisted file “%s”", line) @@ -1900,6 +1901,7 @@ names.save = save_names names.update = update_names names.crude_file_lookup = crude_file_lookup names.crude_file_lookup_verbose = crude_file_lookup_verbose +names.read_blacklist = read_blacklist --- font cache names.purge_cache = purge_cache diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 25cc9fa..e3f5a93 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -183,6 +183,7 @@ This tool is part of the luaotfload package. Valid options are: --list= output list of entries by field --list=: restrict to entries with = --fields=,,…, which fields to print with --list + -b --show-blacklist show blacklisted files The font database will be saved to %s @@ -269,7 +270,7 @@ set. --]]-- local action_sequence = { - "loglevel", "help", "version", "cache", + "loglevel", "help", "version", "blacklist", "cache", "flush", "generate", "list", "query", } local action_pending = table.tohash(action_sequence, false) @@ -297,6 +298,15 @@ actions.help = function (job) return true, false end +actions.blacklist = function (job) + names.read_blacklist() + local n = 0 + for n, entry in next, table.sortedkeys(fonts.names.blacklist) do + texiowrite_nl(stringformat("(%d %s)", n, entry)) + end + return true, false +end + actions.generate = function (job) local fontnames, savedname fontnames = names.update(fontnames, job.force_reload, job.dry_run) @@ -565,12 +575,13 @@ local process_cmdline = function ( ) -- unit -> jobspec log = 1, ["prefer-texmf"] = "p", quiet = "q", + ["show-blacklist"] = "b", update = "u", verbose = 1 , version = "V", } - local short_options = "DfFilpquvVh" + local short_options = "bDfFilpquvVh" local options, _, optarg = alt_getopt.get_ordered_opts (arg, short_options, long_options) @@ -633,6 +644,8 @@ local process_cmdline = function ( ) -- unit -> jobspec result.dry_run = true elseif v == "p" then config.luaotfload.prioritize = "texmf" + elseif v == "b" then + action_pending["blacklist"] = true end end diff --git a/luaotfload-tool.rst b/luaotfload-tool.rst index a428375..06ab1cc 100644 --- a/luaotfload-tool.rst +++ b/luaotfload-tool.rst @@ -15,7 +15,7 @@ SYNOPSIS ======================================================================= -**luaotfload** [ -cfFipquvVh ] +**luaotfload** [ -bDcfFipquvVh ] **luaotfload** --update [ --force ] [ --quiet ] [ --verbose ] [ --prefer-texmf ] [ --dry-run ] @@ -31,6 +31,8 @@ SYNOPSIS **luaotfload** --version +**luaotfload** --show-blacklist + DESCRIPTION ======================================================================= @@ -71,6 +73,7 @@ query mode ``--find``). --info, -i Display basic information to a resolved font file (requires ``--find``). +--show-blacklist, -b Show blacklisted files (not directories). --list=CRITERION Show entries, where *CRITERION* is one of the following: -- cgit v1.2.3 From f9e9ce4aa37d7a30f217e92ba95cb8e2073d8309 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 2 Jun 2013 02:30:06 +0200 Subject: used names.getfilename() to resolve system paths --- luaotfload-database.lua | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 3d2b073..22de3fa 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -272,6 +272,7 @@ local read_fonts_conf local reload_db local resolve local resolve_cached +local resolve_fullpath local save_names local save_lookups local update_names @@ -528,21 +529,20 @@ on whether the index entry has a texmf flag set. --doc]]-- local get_font_file = function (fullnames, entry) + local basename = entry.basename if entry.texmf == true then - local basename = entry.basename if kpselookup(basename) then return true, basename, entry.subfont end else local fullname = fullnames[entry.index] if lfsisfile(fullname) then - return true, fullname, entry.subfont + return true, basename, entry.subfont end end return false end - --[[doc-- Luatex-fonts, the font-loader package luaotfload imports, comes with @@ -711,6 +711,7 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con end end + --- this is a monster if #found == 1 then --- “found” is really synonymous with “registered in the db”. local entry = found[1] @@ -787,6 +788,20 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con return specification.name, false, false end --- resolve() +--- dummy required by luatex-fonts (cf. luatex-fonts-syn.lua) + +resolve_fullpath = function (fontname, ext) --- getfilename() + if not fonts_loaded then + names.data = load_names() + end + local filenames = names.data.filenames + local idx = filenames.base[fontname] + if idx then + return filenames.full[idx] + end + return "" +end + --- when reload is triggered we update the database --- and then re-run the caller with the arg list @@ -1902,6 +1917,7 @@ names.update = update_names names.crude_file_lookup = crude_file_lookup names.crude_file_lookup_verbose = crude_file_lookup_verbose names.read_blacklist = read_blacklist +names.getfilename = resolve_fullpath --- font cache names.purge_cache = purge_cache @@ -1922,8 +1938,4 @@ names.find_closest = find_closest -- for testing purpose names.read_fonts_conf = read_fonts_conf ---- dummy required by luatex-fonts (cf. luatex-fonts-syn.lua) - -fonts.names.getfilename = function (askedname,suffix) return "" end - -- vim:tw=71:sw=4:ts=4:expandtab -- cgit v1.2.3 From 1c05b861741add6fbc4a3185ad49b812e4f5771e Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 2 Jun 2013 02:40:39 +0200 Subject: make compatibility hacks optional --- luaotfload-auxiliary.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/luaotfload-auxiliary.lua b/luaotfload-auxiliary.lua index bb1e8f9..5e5b121 100644 --- a/luaotfload-auxiliary.lua +++ b/luaotfload-auxiliary.lua @@ -42,6 +42,10 @@ local tablecopy = table.copy --- font patches ----------------------------------------------------------------------- +--- as of 2.3 the compatibility hacks for TL 2013 are made optional + +if config.luaotfload.compatibility == true then + --[[doc-- The font object (tfmdata) structure has changed since version 1.x, so @@ -101,13 +105,10 @@ local add_fontdata_fallbacks = function (fontdata) return fontdata end ---if config.luaotfload.compatibility == true then -if true then - luatexbase.add_to_callback( - "luaotfload.patch_font", - add_fontdata_fallbacks, - "luaotfload.fontdata_fallbacks") -end +luatexbase.add_to_callback( + "luaotfload.patch_font", + add_fontdata_fallbacks, + "luaotfload.fontdata_fallbacks") --[[doc-- @@ -124,6 +125,8 @@ font.getfont() since Hans made it a harmless wrapper [1].) fonts.identifiers = fonts.hashes.identifiers fonts.ids = fonts.hashes.identifiers +end + --[[doc-- This sets two dimensions apparently relied upon by the unicode-math package. -- cgit v1.2.3 From 9cdf846537280dc9661b1ed88a58eb763b237d1d Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 2 Jun 2013 03:19:19 +0200 Subject: replace tfmdata.name with the quoted spec --- luaotfload-auxiliary.lua | 11 +++++++++++ luaotfload-database.lua | 3 +-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/luaotfload-auxiliary.lua b/luaotfload-auxiliary.lua index 5e5b121..3597683 100644 --- a/luaotfload-auxiliary.lua +++ b/luaotfload-auxiliary.lua @@ -42,6 +42,17 @@ local tablecopy = table.copy --- font patches ----------------------------------------------------------------------- +--- https://github.com/khaledhosny/luaotfload/issues/54 + +local rewrite_fontname = function (tfmdata, specification) + tfmdata.name = [["]] .. specification .. [["]] +end + +luatexbase.add_to_callback( + "luaotfload.patch_font", + rewrite_fontname, + "luaotfload.rewrite_fontname") + --- as of 2.3 the compatibility hacks for TL 2013 are made optional if config.luaotfload.compatibility == true then diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 22de3fa..b9695ad 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -788,14 +788,13 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con return specification.name, false, false end --- resolve() ---- dummy required by luatex-fonts (cf. luatex-fonts-syn.lua) - resolve_fullpath = function (fontname, ext) --- getfilename() if not fonts_loaded then names.data = load_names() end local filenames = names.data.filenames local idx = filenames.base[fontname] + or filenames.bare[fontname] if idx then return filenames.full[idx] end -- cgit v1.2.3 From 7f3ff49d11203c81c8670e03bbb928478bb99cdc Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 2 Jun 2013 03:28:32 +0200 Subject: update dtx with current luaotfload.lua --- luaotfload.dtx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/luaotfload.dtx b/luaotfload.dtx index 7beca09..095ac23 100644 --- a/luaotfload.dtx +++ b/luaotfload.dtx @@ -1437,8 +1437,9 @@ config.luaotfload = config.luaotfload or { } config.luaotfload.resolver = config.luaotfload.resolver or "cached" config.luaotfload.definer = config.luaotfload.definer or "patch" config.luaotfload.compatibility = config.luaotfload.compatibility or false -config.luaotfload.loglevel = config.luaotfload.loglevel or 1 +config.luaotfload.loglevel = config.luaotfload.loglevel or 1 config.luaotfload.color_callback = config.luaotfload.color_callback or "pre_linebreak_filter" +config.luaotfload.prioritize = config.luaotfload.prioritize or "sys" --luaotfload.prefer_merge = config.luaotfload.prefer_merge or true luaotfload.module = { @@ -1821,7 +1822,7 @@ formats.ofm = "type1" local resolvefile = fonts.names.crude_file_lookup --local resolvefile = fonts.names.crude_file_lookup_verbose -function request_resolvers.file(specification) +request_resolvers.file = function (specification) local name = resolvefile(specification.name) local suffix = file.suffix(name) if formats[suffix] then @@ -1832,7 +1833,6 @@ function request_resolvers.file(specification) end end - % \end{macrocode} % We classify as \verb|anon:| those requests that have neither a % prefix nor brackets. According to Khaled\footnote{% @@ -1981,7 +1981,7 @@ local patch_defined_font = function (specification, size, id) --- We need to test for the “shared” field here --- or else the fontspec capheight callback will --- operate on tfm fonts. - call_callback("luaotfload.patch_font", tfmdata) + call_callback("luaotfload.patch_font", tfmdata, specification) end return tfmdata end -- cgit v1.2.3