From 310fa29531fd6003ed840165b8041105827040cb Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 23 Jun 2013 00:38:44 +0200 Subject: refine list of style synonyms --- luaotfload-database.lua | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 4c45d21..f374617 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -326,22 +326,49 @@ end local style_synonyms = { set = { } } do + local combine = function (ta, tb) + local result = { } + for i=1, #ta do + for j=1, #tb do + result[#result+1] = ta[i] .. tb[j] + end + end + return result + end + --- read this: http://blogs.adobe.com/typblography/2008/05/indesign_font_conflicts.html --- tl;dr: font style synonyms are unreliable. - style_synonyms.list = { + --- + --- Context matches font names against lists of known identifiers + --- for weight, style, width, and variant, so that including + --- the family name there are five dimensions for choosing a + --- match. The sad thing is, while this is a decent heuristic it + --- makes no sense to imitate it in luaotfload because the user + --- interface must fit into the much more limited Xetex scheme that + --- distinguishes between merely four style categories: “regular”, + --- “italic”, “bold”, and “bolditalic”. As a result, some of the + --- styles are lumped together although they can differ + --- significantly (like “medium” and “bold”). + + local list = { regular = { "normal", "roman", - "plain", "book", }, + "plain", "book", + "light", "extralight", + "ultralight", }, bold = { "demi", "demibold", "semibold", "boldregular", - "medium" }, + "medium", "mediumbold", + "ultrabold", "extrabold", + "heavy", "black", + "bold", }, italic = { "regularitalic", "normalitalic", - "oblique", "slanted", }, - bolditalic = { "boldoblique", "boldslanted", - "demiitalic", "demioblique", - "demislanted", "demibolditalic", - "semibolditalic", }, + "oblique", "slanted", + "italic", }, } + list.bolditalic = combine(list.bold, list.italic) + style_synonyms.list = list + for category, synonyms in next, style_synonyms.list do style_synonyms.set[category] = tabletohash(synonyms, true) end -- cgit v1.2.3 From 79a75e8efc0d4df83f9ae73f7107e86d81147da9 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 23 Jun 2013 00:50:58 +0200 Subject: move db version check to load time --- luaotfload-database.lua | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index f374617..f8f9391 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -295,6 +295,17 @@ load_names = function (dry_run) "Font names database loaded", "%s", foundname) report("info", 3, "db", "Loading took %0.f ms", 1000*(os.gettimeofday()-starttime)) + + local db_version, nms_version = data.version, names.version + if db_version ~= nms_version then + report("log", 0, "db", + [[version mismatch; expected %4.3f, got %4.3f]], + nms_version, db_version) + if not fonts_reloaded then + report("log", 0, "db", [[force rebuild]]) + return update_names({ }, true, false) + end + end else report("both", 0, "db", [[Font names database not found, generating new one.]]) @@ -663,7 +674,7 @@ the font database created by the luaotfload-tool script. --- values. --- -resolve = function (_,_,specification) -- the 1st two parameters are used by ConTeXt +resolve = function (_, _, specification) -- the 1st two parameters are used by ConTeXt if not fonts_loaded then names.data = load_names() end local data = names.data @@ -691,18 +702,6 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con return specification.name, false, false end - local db_version, nms_version = data.version, names.version - if db_version ~= nms_version then - report("log", 0, "db", - [[version mismatch; expected %4.3f, got %4.3f]], - 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 if not fonts_reloaded then return reload_db("invalid database; missing font mapping", -- cgit v1.2.3 From 2938e7d63404f1d2e129b13f5bb69ddf0653a71e Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 23 Jun 2013 01:39:26 +0200 Subject: prioritize exact matches over style synonyms --- luaotfload-database.lua | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index f8f9391..8c9f42e 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -356,11 +356,13 @@ do --- match. The sad thing is, while this is a decent heuristic it --- makes no sense to imitate it in luaotfload because the user --- interface must fit into the much more limited Xetex scheme that - --- distinguishes between merely four style categories: “regular”, - --- “italic”, “bold”, and “bolditalic”. As a result, some of the - --- styles are lumped together although they can differ + --- distinguishes between merely four style categories (variants): + --- “regular”, “italic”, “bold”, and “bolditalic”. As a result, + --- some of the styles are lumped together although they can differ --- significantly (like “medium” and “bold”). + --- Xetex (XeTeXFontMgr.cpp) appears to recognize only “plain”, + --- “normal”, and “roman” as synonyms for “regular”. local list = { regular = { "normal", "roman", "plain", "book", @@ -710,7 +712,8 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C return specification.name, false, false end - local found = { } --> collect results + local exact = { } --> collect exact style matches + local synonymous = { } --> collect matching style synonyms local fallback --> e.g. non-matching style (fontspec is anal about this) local candidates = { } --> secondary results, incomplete matches @@ -747,21 +750,16 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C 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, + exact, continue = add_to_match( + exact, optsize, dsnsize, size, minsize, maxsize, face) if continue == false then break end elseif prefmodifiers == "regular" or subfamily == "regular" --- TODO this match should be performed when building the db - or synonym_set.regular[prefmodifiers] - or synonym_set.regular[subfamily] then fallback = face elseif name == fullname @@ -770,10 +768,19 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C or name == psname then local continue - found, continue = add_to_match( - found, optsize, dsnsize, size, + exact, continue = add_to_match( + exact, optsize, dsnsize, size, minsize, maxsize, face) if continue == false then break end + elseif synonym_set[style] and + (synonym_set[style][prefmodifiers] or + synonym_set[style][subfamily]) + or synonym_set.regular[prefmodifiers] + or synonym_set.regular[subfamily] + then + synonymous = add_to_match(synonymous, + optsize, dsnsize, size, + minsize, maxsize, face) else --- mark as last straw but continue candidates[#candidates+1] = face end @@ -783,14 +790,22 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C or name == fontname or name == psname then local continue - found, continue = add_to_match( - found, optsize, dsnsize, size, + exact, continue = add_to_match( + exact, optsize, dsnsize, size, minsize, maxsize, face) if continue == false then break end end end end + local found + if next(exact) then + found = exact + else + found = synonymous + end + + --- this is a monster if #found == 1 then --- “found” is really synonymous with “registered in the db”. -- cgit v1.2.3 From b20de3f5c45fc767e1a17c8dab12cae1aa4430b7 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 23 Jun 2013 21:29:38 +0200 Subject: treat subfamily style matches as second-rate --- luaotfload-database.lua | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 8c9f42e..22f9455 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -748,19 +748,14 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C if name == family or name == metafamily then - if style == prefmodifiers - or style == subfamily - then + if style == prefmodifiers then -- exact local continue exact, continue = add_to_match( exact, optsize, dsnsize, size, minsize, maxsize, face) if continue == false then break end - - elseif prefmodifiers == "regular" - or subfamily == "regular" + elseif prefmodifiers == "regular" then --- TODO this match should be performed when building the db - then fallback = face elseif name == fullname or name == pfullname @@ -772,7 +767,9 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C exact, optsize, dsnsize, size, minsize, maxsize, face) if continue == false then break end - elseif synonym_set[style] and + elseif style == subfamily --- unreliable (see Ad. Garm. Pro) + or subfamily == "regular" + or synonym_set[style] and (synonym_set[style][prefmodifiers] or synonym_set[style][subfamily]) or synonym_set.regular[prefmodifiers] -- cgit v1.2.3 From baaeef6616db498218f6269fac7a6ec6fb185878 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 23 Jun 2013 21:59:54 +0200 Subject: refactor optical size matching --- luaotfload-database.lua | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 22f9455..0903404 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -619,9 +619,16 @@ end --- this used to be inlined; with the lookup cache we don’t --- have to be parsimonious wrt function calls anymore --- “found” is the match accumulator -local add_to_match = function ( - found, optsize, dsnsize, size, - minsize, maxsize, face) +local add_to_match = function (found, size, face) + + local optsize, dsnsize, maxsize, minsize + if #face.size > 0 then + optsize = face.size + dsnsize = optsize[1] and optsize[1] / 10 + -- can be nil + maxsize = optsize[2] and optsize[2] / 10 or dsnsize + minsize = optsize[3] and optsize[3] / 10 or dsnsize + end local continue = true if optsize then if dsnsize == size or (size > minsize and size <= maxsize) then @@ -683,11 +690,11 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C local name = sanitize_string(specification.name) local style = sanitize_string(specification.style) or "regular" - local size + local askedsize if specification.optsize then - size = tonumber(specification.optsize) + askedsize = tonumber(specification.optsize) elseif specification.size then - size = specification.size / 65536 + askedsize = specification.size / 65536 end if type(data) ~= "table" then @@ -736,23 +743,13 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C fontname = fontname or sanitize_string(face.fontname) pfullname = pfullname or sanitize_string(face.fullname) - local optsize, dsnsize, maxsize, minsize - if #face.size > 0 then - optsize = face.size - dsnsize = optsize[1] and optsize[1] / 10 - -- can be nil - maxsize = optsize[2] and optsize[2] / 10 or dsnsize - minsize = optsize[3] and optsize[3] / 10 or dsnsize - end if name == family or name == metafamily then if style == prefmodifiers then -- exact local continue - exact, continue = add_to_match( - exact, optsize, dsnsize, size, - minsize, maxsize, face) + exact, continue = add_to_match(exact, askedsize, face) if continue == false then break end elseif prefmodifiers == "regular" then --- TODO this match should be performed when building the db @@ -763,9 +760,7 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C or name == psname then local continue - exact, continue = add_to_match( - exact, optsize, dsnsize, size, - minsize, maxsize, face) + exact, continue = add_to_match(exact, askedsize, face) if continue == false then break end elseif style == subfamily --- unreliable (see Ad. Garm. Pro) or subfamily == "regular" @@ -775,9 +770,7 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C or synonym_set.regular[prefmodifiers] or synonym_set.regular[subfamily] then - synonymous = add_to_match(synonymous, - optsize, dsnsize, size, - minsize, maxsize, face) + synonymous = add_to_match(synonymous, askedsize, face) else --- mark as last straw but continue candidates[#candidates+1] = face end @@ -787,9 +780,7 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C or name == fontname or name == psname then local continue - exact, continue = add_to_match( - exact, optsize, dsnsize, size, - minsize, maxsize, face) + exact, continue = add_to_match(exact, askedsize, face) if continue == false then break end end end @@ -824,7 +815,7 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C local least = math.huge -- initial value is infinity for i,face in next, found do local dsnsize = face.size[1]/10 - local difference = mathabs(dsnsize-size) + local difference = mathabs(dsnsize - askedsize) if difference < least then closest = face least = difference -- cgit v1.2.3 From 0e51cff12b24d264b8e17d8bd7f9a00763699963 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 23 Jun 2013 22:23:12 +0200 Subject: treat subfamily match as exact, but not final match --- luaotfload-database.lua | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 0903404..4554711 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -743,17 +743,15 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C fontname = fontname or sanitize_string(face.fontname) pfullname = pfullname or sanitize_string(face.fullname) - if name == family or name == metafamily then - if style == prefmodifiers then -- exact + if style == prefmodifiers then local continue exact, continue = add_to_match(exact, askedsize, face) if continue == false then break end - elseif prefmodifiers == "regular" then - --- TODO this match should be performed when building the db - fallback = face + elseif style == subfamily then + exact = add_to_match(exact, askedsize, face) elseif name == fullname or name == pfullname or name == fontname @@ -762,15 +760,16 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C local continue exact, continue = add_to_match(exact, askedsize, face) if continue == false then break end - elseif style == subfamily --- unreliable (see Ad. Garm. Pro) - or subfamily == "regular" - or synonym_set[style] and + elseif synonym_set[style] and (synonym_set[style][prefmodifiers] or synonym_set[style][subfamily]) or synonym_set.regular[prefmodifiers] or synonym_set.regular[subfamily] then synonymous = add_to_match(synonymous, askedsize, face) + elseif prefmodifiers == "regular" + or subfamily == "regular" then + fallback = face else --- mark as last straw but continue candidates[#candidates+1] = face end @@ -793,7 +792,6 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C found = synonymous end - --- this is a monster if #found == 1 then --- “found” is really synonymous with “registered in the db”. -- cgit v1.2.3 From ffdbaf60da4815f80f6254a35ec22b7da55fc44c Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 25 Jun 2013 10:50:13 +0200 Subject: fix font file verification (thanks, Kim!) the cached lookup did not load the database when verifying the presence of hashed files. addresses: https://github.com/lualatex/luaotfload/issues/100 --- luaotfload-database.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 4554711..12bceb5 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -493,6 +493,7 @@ the texmf or filesystem. --doc]]-- local verify_font_file = function (basename) + if not names.data then names.data = load_names() end local filenames = names.data.filenames local idx = filenames.base[basename] if not idx then -- cgit v1.2.3 From de200c1846690e75a33aeaef920d74af34e4b001 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 25 Jun 2013 15:48:14 +0200 Subject: add --inspect and --warnings flags to luaotfload-tool --- luaotfload-database.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 12bceb5..82f6c7c 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -1998,6 +1998,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.sanitize_string = sanitize_string names.getfilename = resolve_fullpath --- font cache -- cgit v1.2.3 From 488d5b61fdf466b660ca5c86652ee5c661377ce7 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 27 Jun 2013 00:37:08 +0200 Subject: add message about the location of the names db to ``luaotfload-tool --update`` also make log messages more consistent wrt casing --- luaotfload-database.lua | 74 +++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 36 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 82f6c7c..e0548ea 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -299,7 +299,7 @@ load_names = function (dry_run) local db_version, nms_version = data.version, names.version if db_version ~= nms_version then report("log", 0, "db", - [[version mismatch; expected %4.3f, got %4.3f]], + [[Version mismatch; expected %4.3f, got %4.3f]], nms_version, db_version) if not fonts_reloaded then report("log", 0, "db", [[force rebuild]]) @@ -398,12 +398,12 @@ local verbose_lookup = function (data, kind, filename) found = data.full[found] if found == nil then --> texmf report("info", 0, "db", - "crude file lookup: req=%s; hit=%s => kpse", + "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", + "Crude file lookup: req=%s; hit=%s; ret=%s", filename, kind, found) end return found @@ -578,23 +578,23 @@ end resolve_cached = function (_, _, specification) if not names.lookups then names.lookups = load_lookups() end local request = hash_request(specification) - report("both", 4, "cache", "looking for “%s” in cache ...", + report("both", 4, "cache", "Looking for “%s” in cache ...", request) local found = names.lookups[request] --- case 1) cache positive ---------------------------------------- if found then --- replay fields from cache hit - report("info", 4, "cache", "found!") + report("info", 4, "cache", "Found!") local basename = found[1] --- check the presence of the file in case it’s been removed local success = verify_font_file(basename) if success == true then return basename, found[2], true end - report("both", 4, "cache", "cached file not found; resolving again") + report("both", 4, "cache", "Cached file not found; resolving again") else - report("both", 4, "cache", "not cached; resolving") + report("both", 4, "cache", "Not cached; resolving") end --- case 2) cache negative ---------------------------------------- @@ -603,16 +603,16 @@ resolve_cached = function (_, _, specification) if not success then return filename, subfont, false end --- ... then we add the fields to the cache ... ... local entry = { filename, subfont } - report("both", 4, "cache", "new entry: %s", request) + report("both", 4, "cache", "New entry: %s", request) names.lookups[request] = entry --- obviously, the updated cache needs to be stored. --- TODO this should trigger a save only once the --- document is compiled (finish_pdffile callback?) - report("both", 5, "cache", "saving updated cache") + report("both", 5, "cache", "Saving updated cache") local success = save_lookups() if not success then --- sad, but not critical - report("both", 0, "cache", "could not write to cache") + report("both", 0, "cache", "Could not write to cache") end return filename, subfont, true end @@ -801,7 +801,7 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C = get_font_file(data.filenames.full, entry) if success == true then report("log", 0, "resolve", - "font family='%s', subfamily='%s' found: %s", + "Font family='%s', subfamily='%s' found: %s", name, style, filename ) return filename, subfont, true @@ -824,7 +824,7 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C = get_font_file(data.filenames.full, closest) if success == true then report("log", 0, "resolve", - "font family='%s', subfamily='%s' found: %s", + "Font family='%s', subfamily='%s' found: %s", name, style, filename ) return filename, subfont, true @@ -834,11 +834,11 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C = get_font_file(data.filenames.full, fallback) if success == true then report("log", 0, "resolve", - "no exact match for request %s; using fallback", + "No exact match for request %s; using fallback", specification.specification ) report("log", 0, "resolve", - "font family='%s', subfamily='%s' found: %s", + "Font family='%s', subfamily='%s' found: %s", name, style, filename ) return filename, subfont, true @@ -850,7 +850,7 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C = get_font_file(data.filenames.full, entry) if success == true then report("log", 0, "resolve", - "font family='%s', subfamily='%s' found: %s", + "Font family='%s', subfamily='%s' found: %s", name, style, filename ) return filename, subfont, true @@ -888,7 +888,7 @@ end --- string -> ('a -> 'a) -> 'a list -> 'a reload_db = function (why, caller, ...) - report("both", 1, "db", "reload initiated; reason: “%s”", why) + report("both", 1, "db", "Reload initiated; reason: “%s”", why) names.data = update_names(names.data, false, false) local success = save_names() if success then @@ -984,13 +984,13 @@ find_closest = function (name, limit) tablesort(distances) limit = mathmin(n_distances, limit) report(false, 1, "query", - "displaying %d distance levels", limit) + "Displaying %d distance levels", limit) for i = 1, limit do local dist = distances[i] local namelst = by_distance[dist] report(false, 0, "query", - "distance from “" .. name .. "”: " .. dist + "Distance from “" .. name .. "”: " .. dist .. "\n " .. tableconcat(namelst, "\n ") ) end @@ -1018,7 +1018,7 @@ font_fullinfo = function (filename, subfont, texmf, basename) local tfmdata = { } local rawfont = fontloaderopen(filename, subfont) if not rawfont then - report("log", 1, "error", "failed to open %s", filename) + report("log", 1, "error", "Failed to open %s", filename) return end local metadata = fontloader.to_table(rawfont) @@ -1056,7 +1056,7 @@ font_fullinfo = function (filename, subfont, texmf, basename) end else -- no names table, propably a broken font - report("log", 1, "db", "broken font rejected", "%s", basefile) + report("log", 1, "db", "Broken font rejected", "%s", basefile) return end tfmdata.fontname = metadata.fontname @@ -1108,7 +1108,7 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) if names.blacklist[fullname] or names.blacklist[basename] then report("log", 2, "db", - "ignoring blacklisted font “%s”", fullname) + "Ignoring blacklisted font “%s”", fullname) return false end @@ -1139,7 +1139,7 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) newmappings[location] = fullinfo --- keep newentrystatus.index[index+1] = location --- is this actually used anywhere? end - report("log", 2, "db", "font “%s” already indexed", basename) + report("log", 2, "db", "Font “%s” already indexed", basename) return false end @@ -1172,7 +1172,7 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) end else --- missing info - report("log", 1, "db", "failed to load “%s”", basename) + report("log", 1, "db", "Failed to load “%s”", basename) return false end return true @@ -1253,7 +1253,7 @@ local create_blacklist = function (blacklist, whitelist) local result = { } local dirs = { } - report("info", 2, "db", "blacklisting “%d” files and directories", + report("info", 2, "db", "Blacklisting “%d” files and directories", #blacklist) for i=1, #blacklist do local entry = blacklist[i] @@ -1264,7 +1264,7 @@ local create_blacklist = function (blacklist, whitelist) end end - report("info", 2, "db", "whitelisting “%d” files", #whitelist) + report("info", 2, "db", "Whitelisting “%d” files", #whitelist) for i=1, #whitelist do result[whitelist[i]] = nil end @@ -1313,7 +1313,7 @@ read_blacklist = function () line = stringsub(line, 1, cmt - 1) end line = stringstrip(line) - report("log", 2, "db", "blacklisted file “%s”", line) + report("log", 2, "db", "Blacklisted file “%s”", line) blacklist[#blacklist+1] = line end end @@ -1348,7 +1348,7 @@ local scan_dir = function (dirname, fontnames, newfontnames, dry_run, texmf) end local n_scanned, n_new = 0, 0 --- total of fonts collected - report("both", 3, "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)) @@ -1362,9 +1362,9 @@ local scan_dir = function (dirname, fontnames, newfontnames, dry_run, texmf) fullname = path_normalize(fullname) local new if dry_run == true then - report("both", 1, "db", "would have been loading “%s”", fullname) + report("both", 1, "db", "Would have been loading “%s”", fullname) else - report("both", 4, "db", "loading font “%s”", fullname) + report("both", 4, "db", "Loading font “%s”", fullname) local new = load_font(fullname, fontnames, newfontnames, texmf) if new == true then n_new = n_new + 1 @@ -1498,7 +1498,7 @@ do --- closure for read_fonts_conf() local fonts_conf_scanner = function (path) local fh = ioopen(path, "r") if not fh then - report("both", 3, "db", "cannot open fontconfig file %s", path) + report("both", 3, "db", "Cannot open fontconfig file %s", path) return end local raw = fh:read"*all" @@ -1506,7 +1506,7 @@ do --- closure for read_fonts_conf() local confdata = lpegmatch(p_cheapxml, raw) if not confdata then - report("both", 3, "db", "cannot scan fontconfig file %s", path) + report("both", 3, "db", "Cannot scan fontconfig file %s", path) return end return confdata @@ -1672,7 +1672,7 @@ end --- dbobj -> dbobj local gen_fast_lookups = function (fontnames) - report("both", 2, "db", "creating filename map") + report("both", 2, "db", "Creating filename map") local mappings = fontnames.mappings local nmappings = #mappings --- this is needlessly complicated due to texmf priorization @@ -1712,7 +1712,7 @@ local gen_fast_lookups = function (fontnames) local known = filenames.base[base] or filenames.bare[bare] if known then --- known report("both", 3, "db", - "font file “%s” already indexed (%d)", + "Font file “%s” already indexed (%d)", base, idx) report("both", 3, "db", "> old location: %s", (filenames.full[known] or "texmf")) @@ -1731,7 +1731,7 @@ local gen_fast_lookups = function (fontnames) end if config.luaotfload.prioritize == "texmf" then - report("both", 2, "db", "preferring texmf fonts") + report("both", 2, "db", "Preferring texmf fonts") addmap(sys) addmap(texmf) else --- sys @@ -1856,6 +1856,8 @@ save_names = function (fontnames) os.remove(lucname) caches.compile(fontnames, luaname, lucname) report("info", 1, "db", "Font names database saved") + report("info", 3, "db", "Text: " .. luaname) + report("info", 3, "db", "Byte: " .. lucname) return true end end @@ -1902,7 +1904,7 @@ local purge_from_cache = function (category, path, list, all) local checkname = file.replacesuffix( filename, "lua", "luc") if lfs.isfile(checkname) then - report("info", 5, "cache", "removing %s", filename) + report("info", 5, "cache", "Removing %s", filename) os.remove(filename) n = n + 1 end @@ -1910,7 +1912,7 @@ local purge_from_cache = function (category, path, list, all) end end end - report("info", 2, "cache", "removed lua files : %i", n) + report("info", 2, "cache", "Removed lua files : %i", n) return true end --- string -> string list -> int -> string list -> string list -> string list -> -- cgit v1.2.3 From 62493d4c3d4d3089f7a2ff30d811e8f035d98b8a Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 30 Jun 2013 14:10:04 +0200 Subject: add workaround for globbing of messy paths --- luaotfload-database.lua | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index e0548ea..1f8f34a 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -16,8 +16,8 @@ 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 +local C, Cc, Cf, Cg, Cs, Ct + = lpeg.C, lpeg.Cc, lpeg.Cf, lpeg.Cg, lpeg.Cs, lpeg.Ct --- Luatex builtins local load = load @@ -136,6 +136,17 @@ local sanitize_string = function (str) return nil end +local preescape_path --- working around funky characters +do + local escape = function (chr) return "%" .. chr end + local funkychar = S"()[]" + local pattern = Cs((funkychar/escape + 1)^0) + + preescape_path = function (str) + return lpegmatch (pattern, str) + end +end + --[[doc-- This is a sketch of the luaotfload db: @@ -1351,8 +1362,10 @@ local scan_dir = function (dirname, fontnames, newfontnames, dry_run, texmf) 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)) - local n_found = #found + local escapeddir = preescape_path (dirname) + local found = dirglob (stringformat("%s/**.%s$", + escapeddir, ext)) + local n_found = #found --- note that glob fails silently on broken symlinks, which --- happens sometimes in TeX Live. report("both", 4, "db", "%s '%s' fonts found", n_found, ext) @@ -1572,7 +1585,9 @@ do --- closure for read_fonts_conf() path, home, xdg_home, acc, done, dirs_done) elseif lfsisdir(path) then --- arrow code ahead - local config_files = dirglob(filejoin(path, "*.conf")) + local escapedpath = preescape_path (path) + local config_files = dirglob + (filejoin(escapedpath, "*.conf")) for _, filename in next, config_files do if not done[filename] then acc = read_fonts_conf_indeed( @@ -1920,7 +1935,8 @@ end local collect_cache collect_cache = function (path, all, n, luanames, lucnames, rest) if not all then - local all = dirglob(path .. "/**/*") + local escapedpath = preescape_path (path) + local all = dirglob (escapedpath .. "/**/*") local luanames, lucnames, rest = { }, { }, { } return collect_cache(nil, all, 1, luanames, lucnames, rest) end -- cgit v1.2.3 From 71eb6250e1971b7ead98f6d91a7d325597730ebe Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 2 Jul 2013 12:42:10 +0200 Subject: treat psname matches as second-tier (fixes cambria) --- luaotfload-database.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 1f8f34a..7baa92a 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -769,9 +769,7 @@ resolve = function (_, _, specification) -- the 1st two parameters are used by C or name == fontname or name == psname then - local continue - exact, continue = add_to_match(exact, askedsize, face) - if continue == false then break end + synonymous, continue = add_to_match(synonymous, askedsize, face) elseif synonym_set[style] and (synonym_set[style][prefmodifiers] or synonym_set[style][subfamily]) -- cgit v1.2.3 From b4fdea433f1949238fca34af9ba2a8b332e992a4 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 2 Jul 2013 14:38:16 +0200 Subject: replace globber in scan_dir() --- luaotfload-database.lua | 144 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 98 insertions(+), 46 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 7baa92a..9eb5b1f 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -33,12 +33,11 @@ local iolines = io.lines local ioopen = io.open local kpseexpand_path = kpse.expand_path local kpseexpand_var = kpse.expand_var -local kpselookup = kpse.lookup local kpsefind_file = kpse.find_file +local kpselookup = kpse.lookup local kpsereadable_file = kpse.readable_file -local lfsisdir = lfs.isdir -local lfsisfile = lfs.isfile local lfsattributes = lfs.attributes +local lfsdir = lfs.dir local mathabs = math.abs local mathmin = math.min local stringfind = string.find @@ -49,9 +48,7 @@ local stringlower = string.lower local stringsub = string.sub local stringupper = string.upper local tableconcat = table.concat -local tablecopy = table.copy local tablesort = table.sort -local tabletofile = table.tofile local texiowrite_nl = texio.write_nl local utf8gsub = unicode.utf8.gsub local utf8lower = unicode.utf8.lower @@ -60,18 +57,22 @@ local utf8lower = unicode.utf8.lower local dirglob = dir.glob local dirmkdirs = dir.mkdirs local filebasename = file.basename -local filenameonly = file.nameonly -local filedirname = file.dirname local filecollapsepath = file.collapsepath or file.collapse_path +local filedirname = file.dirname local fileextname = file.extname local fileiswritable = file.iswritable local filejoin = file.join +local filenameonly = file.nameonly local filereplacesuffix = file.replacesuffix local filesplitpath = file.splitpath or file.split_path +local lfsisdir = lfs.isdir +local lfsisfile = lfs.isfile local stringis_empty = string.is_empty local stringsplit = string.split local stringstrip = string.strip local tableappend = table.append +local tablecopy = table.copy +local tabletofile = table.tofile local tabletohash = table.tohash --- the font loader namespace is “fonts”, same as in Context @@ -1206,8 +1207,8 @@ do return path end --[[doc-- - Cygwin used to be treated different from windows and dos. This - special treatment was removed with a patch submitted by Ken Brown. + The special treatment for cygwin was removed with a patch submitted + by Ken Brown. Reference: http://cygwin.com/ml/cygwin/2013-05/msg00006.html --doc]]-- @@ -1301,12 +1302,12 @@ end --- unit -> unit read_blacklist = function () local files = { - kpselookup("luaotfload-blacklist.cnf", {all=true, format="tex"}) + kpselookup ("luaotfload-blacklist.cnf", + {all=true, format="tex"}) } 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 @@ -1331,10 +1332,59 @@ read_blacklist = function () names.blacklist = create_blacklist(blacklist, whitelist) end -local font_extensions = { "otf", "ttf", "ttc", "dfont" } -local font_extensions_set = {} -for key, value in next, font_extensions do - font_extensions_set[value] = true +local font_extensions = { "otf", "ttf", "ttc", "dfont" } +local font_extensions_set = tabletohash (font_extensions) +local p_font_extensions +do + local extns + --tablesort (font_extensions) --- safeguard + for i=#font_extensions, 1, -1 do + local e = font_extensions[i] + if not extns then + extns = P(e) + else + extns = extns + P(e) + end + end + extns = extns * P(-1) + p_font_extensions = (1 - extns)^1 * extns +end + +local process_dir_tree +process_dir_tree = function (acc, dirs) + if not next (dirs) then --- done + return acc + end + + local dir = dirs[#dirs] + dirs[#dirs] = nil + + local newdirs, newfiles = { }, { } + local blacklist = names.blacklist + for ent in lfsdir (dir) do + --- filter right away + if ent ~= "." and ent ~= ".." and not blacklist[ent] then + local fullpath = dir .. "/" .. ent + if lfsisdir (fullpath) + and not lpegmatch (p_blacklist, fullpath) + then + newdirs[#newdirs+1] = fullpath + elseif lfsisfile (fullpath) then + if lpegmatch (p_font_extensions, stringlower(ent)) then + newfiles[#newfiles+1] = fullpath + end + end + end + end + return process_dir_tree (tableappend (acc, newfiles), + tableappend (dirs, newdirs)) +end + +--- string -> string list +local find_font_files = function (root) + if lfsisdir (root) then + return process_dir_tree ({}, { root }) + end end --[[doc-- @@ -1350,42 +1400,45 @@ end --doc]]-- --- string -> dbobj -> dbobj -> bool -> bool -> (int * int) -local scan_dir = function (dirname, fontnames, newfontnames, dry_run, texmf) - if lpegmatch(p_blacklist, dirname) then +local scan_dir = function (dirname, fontnames, newfontnames, + dry_run, texmf) + if lpegmatch (p_blacklist, dirname) then + report ("both", 3, "db", + "Skipping blacklisted directory %s", dirname) --- ignore return 0, 0 end - - local n_scanned, n_new = 0, 0 --- total of fonts collected - report("both", 3, "db", "Scanning directory %s", dirname) - for _,i in next, font_extensions do - for _,ext in next, { i, stringupper(i) } do - local escapeddir = preescape_path (dirname) - local found = dirglob (stringformat("%s/**.%s$", - escapeddir, ext)) - local n_found = #found - --- note that glob fails silently on broken symlinks, which - --- happens sometimes in TeX Live. - report("both", 4, "db", "%s '%s' fonts found", n_found, ext) - n_scanned = n_scanned + n_found - for j=1, n_found do - local fullname = found[j] - fullname = path_normalize(fullname) - local new - if dry_run == true then - 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, texmf) - if new == true then - n_new = n_new + 1 - end - end + local found = find_font_files (dirname) + if not found then + report ("both", 3, "db", + "No such directory: “%s”; skipping.", dirname) + return 0, 0 + end + report ("both", 3, "db", "Scanning directory %s", dirname) + + local n_new = 0 --- total of fonts collected + local n_found = #found + report ("both", 4, "db", "%d font files detected", n_found) + for j=1, n_found do + local fullname = found[j] + fullname = path_normalize(fullname) + local new + if dry_run == true then + 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, texmf) + if new == true then + n_new = n_new + 1 end end end - report("both", 4, "db", "%d fonts found in '%s'", n_scanned, dirname) - return n_scanned, n_new + + report("both", 4, "db", "%d fonts found in '%s'", n_found, dirname) + return n_found, n_new end --- dbobj -> dbobj -> bool? -> (int * int) @@ -1404,7 +1457,6 @@ local scan_texmf_fonts = function (fontnames, newfontnames, dry_run) fontdirs = fontdirs .. stringgsub(kpseexpand_path("$TTFONTS"), "^%.", "") 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, true) n_scanned = n_scanned + found n_new = n_new + new -- cgit v1.2.3 From e46b1ade1a0b4cabec661aa0f505efd03b9bdc5a Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 2 Jul 2013 14:53:44 +0200 Subject: limit font cache controls to actual font cache dir --- luaotfload-database.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 9eb5b1f..4755396 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -2006,9 +2006,21 @@ local collect_cache collect_cache = function (path, all, n, luanames, return luanames, lucnames, rest, all end +local getfontcachepath = function ( ) + --- fonts.handlers.otf doesn’t exist outside a Luatex run, + --- so we have to improvise + local writable = caches.getwritablepath () + if writable then + writable = writable .. "/fonts" + if lfsisdir (writable) then + return writable + end + end +end + --- unit -> unit local purge_cache = function ( ) - local writable_path = caches.getwritablepath() + local writable_path = getfontcachepath () local luanames, lucnames, rest = collect_cache(writable_path) if logs.get_loglevel() > 1 then print_cache("writable path", writable_path, luanames, lucnames, rest) @@ -2019,7 +2031,7 @@ end --- unit -> unit local erase_cache = function ( ) - local writable_path = caches.getwritablepath() + local writable_path = getfontcachepath () local luanames, lucnames, rest, all = collect_cache(writable_path) if logs.get_loglevel() > 1 then print_cache("writable path", writable_path, luanames, lucnames, rest) @@ -2035,7 +2047,7 @@ end --- unit -> unit local show_cache = function ( ) local readable_paths = caches.getreadablepaths() - local writable_path = caches.getwritablepath() + local writable_path = getfontcachepath () local luanames, lucnames, rest = collect_cache(writable_path) separator() -- cgit v1.2.3 From 4a01814961fa764fc246f8f3976ccd830c54dadf Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 2 Jul 2013 15:01:00 +0200 Subject: restrict readable path stats to font cache --- luaotfload-database.lua | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 4755396..39c6ab5 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -2006,7 +2006,7 @@ local collect_cache collect_cache = function (path, all, n, luanames, return luanames, lucnames, rest, all end -local getfontcachepath = function ( ) +local getwritablecachepath = function ( ) --- fonts.handlers.otf doesn’t exist outside a Luatex run, --- so we have to improvise local writable = caches.getwritablepath () @@ -2018,9 +2018,23 @@ local getfontcachepath = function ( ) end end +local getreadablecachepaths = function ( ) + local readables = caches.getreadablepaths () + local result = { } + if readables then + for i=1, #readables do + local readable = readables[i] .. "/fonts" + if lfsisdir (readable) then + result[#result+1] = readable + end + end + end + return result +end + --- unit -> unit local purge_cache = function ( ) - local writable_path = getfontcachepath () + local writable_path = getwritablecachepath () local luanames, lucnames, rest = collect_cache(writable_path) if logs.get_loglevel() > 1 then print_cache("writable path", writable_path, luanames, lucnames, rest) @@ -2031,7 +2045,7 @@ end --- unit -> unit local erase_cache = function ( ) - local writable_path = getfontcachepath () + local writable_path = getwritablecachepath () local luanames, lucnames, rest, all = collect_cache(writable_path) if logs.get_loglevel() > 1 then print_cache("writable path", writable_path, luanames, lucnames, rest) @@ -2046,19 +2060,20 @@ end --- unit -> unit local show_cache = function ( ) - local readable_paths = caches.getreadablepaths() - local writable_path = getfontcachepath () + local readable_paths = getreadablecachepaths () + local writable_path = getwritablecachepath () local luanames, lucnames, rest = collect_cache(writable_path) - separator() - print_cache("writable path", writable_path, luanames, lucnames, rest) + separator () + print_cache ("writable path", writable_path, + luanames, lucnames, rest) texiowrite_nl"" for i=1,#readable_paths do local readable_path = readable_paths[i] if readable_path ~= writable_path then - local luanames, lucnames = collect_cache(readable_path) - print_cache("readable path", - readable_path,luanames,lucnames,rest) + local luanames, lucnames = collect_cache (readable_path) + print_cache ("readable path", + readable_path, luanames, lucnames, rest) end end separator() -- cgit v1.2.3 From 77531144a0d04d08527d44a9d6316a5d7a24020f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 2 Jul 2013 15:39:37 +0200 Subject: extend file locator with filtering (no references to dir.glob() anymore --- luaotfload-database.lua | 64 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 13 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 39c6ab5..04b8720 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -54,7 +54,6 @@ local utf8gsub = unicode.utf8.gsub local utf8lower = unicode.utf8.lower --- these come from Lualibs/Context -local dirglob = dir.glob local dirmkdirs = dir.mkdirs local filebasename = file.basename local filecollapsepath = file.collapsepath or file.collapse_path @@ -137,17 +136,47 @@ local sanitize_string = function (str) return nil end -local preescape_path --- working around funky characters -do - local escape = function (chr) return "%" .. chr end - local funkychar = S"()[]" - local pattern = Cs((funkychar/escape + 1)^0) +local find_files_indeed +find_files_indeed = function (acc, dirs, filter) + if not next (dirs) then --- done + return acc + end + + local dir = dirs[#dirs] + dirs[#dirs] = nil + + local newdirs, newfiles = { }, { } + for ent in lfsdir (dir) do + if ent ~= "." and ent ~= ".." then + local fullpath = dir .. "/" .. ent + if filter (fullpath) == true then + if lfsisdir (fullpath) then + newdirs[#newdirs+1] = fullpath + elseif lfsisfile (fullpath) then + newfiles[#newfiles+1] = fullpath + end + end + end + end + return find_files_indeed (tableappend (acc, newfiles), + tableappend (dirs, newdirs), + filter) +end + +local dummyfilter = function () return true end - preescape_path = function (str) - return lpegmatch (pattern, str) +--- the optional filter function receives the full path of a file +--- system entity. a filter applies if the first argument it returns is +--- true. + +--- string -> function? -> string list +local find_files = function (root, filter) + if lfsisdir (root) then + return find_files_indeed ({}, { root }, filter or dummyfilter) end end + --[[doc-- This is a sketch of the luaotfload db: @@ -1575,6 +1604,16 @@ do --- closure for read_fonts_conf() return confdata end + local p_conf = P".conf" * P(-1) + local p_filter = (1 - p_conf)^1 * p_conf + + local conf_filter = function (path) + if lpegmatch (p_filter, path) then + return true + end + return false + end + --[[doc-- read_fonts_conf_indeed() is called with six arguments; the latter three are tables that represent the state and are @@ -1635,9 +1674,7 @@ do --- closure for read_fonts_conf() path, home, xdg_home, acc, done, dirs_done) elseif lfsisdir(path) then --- arrow code ahead - local escapedpath = preescape_path (path) - local config_files = dirglob - (filejoin(escapedpath, "*.conf")) + local config_files = find_files (path, conf_filter) for _, filename in next, config_files do if not done[filename] then acc = read_fonts_conf_indeed( @@ -1980,13 +2017,14 @@ local purge_from_cache = function (category, path, list, all) report("info", 2, "cache", "Removed lua files : %i", n) return true end + --- string -> string list -> int -> string list -> string list -> string list -> --- (string list * string list * string list * string list) local collect_cache collect_cache = function (path, all, n, luanames, lucnames, rest) if not all then - local escapedpath = preescape_path (path) - local all = dirglob (escapedpath .. "/**/*") + local all = find_files (path) + local luanames, lucnames, rest = { }, { }, { } return collect_cache(nil, all, 1, luanames, lucnames, rest) end -- cgit v1.2.3 From 8a5db2c34e4146946f4674ea3e4caf63e08c8cc9 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 2 Jul 2013 15:48:14 +0200 Subject: replace dir.mkdirs() with lfs.mkdirs() --- luaotfload-database.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 04b8720..338ffa6 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -54,7 +54,6 @@ local utf8gsub = unicode.utf8.gsub local utf8lower = unicode.utf8.lower --- these come from Lualibs/Context -local dirmkdirs = dir.mkdirs local filebasename = file.basename local filecollapsepath = file.collapsepath or file.collapse_path local filedirname = file.dirname @@ -66,6 +65,7 @@ local filereplacesuffix = file.replacesuffix local filesplitpath = file.splitpath or file.split_path local lfsisdir = lfs.isdir local lfsisfile = lfs.isfile +local lfsmkdirs = lfs.mkdirs local stringis_empty = string.is_empty local stringsplit = string.split local stringstrip = string.strip @@ -83,6 +83,15 @@ fonts.definers = fonts.definers or { } local names = fonts.names +config = config or { } +config.luaotfload = config.luaotfload or { } +config.luaotfload.resolver = config.luaotfload.resolver or "normal" +if config.luaotfload.update_live ~= false then + --- this option allows for disabling updates + --- during a TeX run + config.luaotfload.update_live = true +end + names.version = 2.207 names.data = nil --- contains the loaded database names.lookups = nil --- contains the lookup cache @@ -94,15 +103,6 @@ names.path = { lookup_path = "", --- cache full path } -config = config or { } -config.luaotfload = config.luaotfload or { } -config.luaotfload.resolver = config.luaotfload.resolver or "normal" -if config.luaotfload.update_live ~= false then - --- this option allows for disabling updates - --- during a TeX run - config.luaotfload.update_live = true -end - -- We use the cache.* of ConTeXt (see luat-basics-gen), we can -- use it safely (all checks and directory creations are already done). It -- uses TEXMFCACHE or TEXMFVAR as starting points. @@ -1912,7 +1912,7 @@ end local ensure_names_path = function ( ) local path = names.path.dir if not lfsisdir(path) then - dirmkdirs(path) + lfsmkdirs(path) end return path end -- cgit v1.2.3 From 00fd07c628af41b0709d25fd00805385be561459 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 3 Jul 2013 11:04:52 +0200 Subject: add cache directory hint to luaotfload-tool; manage paths more consistently --- luaotfload-database.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 338ffa6..c0aadaf 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -97,7 +97,8 @@ names.data = nil --- contains the loaded database names.lookups = nil --- contains the lookup cache names.path = { dir = "", --- db and cache directory - basename = "luaotfload-names.lua", --- db file name + basename = config.luaotfload.names_file + or "luaotfload-names.lua", path = "", --- full path to db file lookup_basename = "luaotfload-lookup-cache.lua", --- cache file name lookup_path = "", --- cache full path @@ -108,7 +109,7 @@ names.path = { -- uses TEXMFCACHE or TEXMFVAR as starting points. local writable_path if caches then - writable_path = caches.getwritablepath("names","") + writable_path = caches.getwritablepath "names" if not writable_path then luaotfload.error("Impossible to find a suitable writeable cache...") end @@ -2047,21 +2048,20 @@ end local getwritablecachepath = function ( ) --- fonts.handlers.otf doesn’t exist outside a Luatex run, --- so we have to improvise - local writable = caches.getwritablepath () + local writable = caches.getwritablepath + (config.luaotfload.cache_dir) if writable then - writable = writable .. "/fonts" - if lfsisdir (writable) then - return writable - end + return writable end end local getreadablecachepaths = function ( ) - local readables = caches.getreadablepaths () + local readables = caches.getreadablepaths + (config.luaotfload.cache_dir) local result = { } if readables then for i=1, #readables do - local readable = readables[i] .. "/fonts" + local readable = readables[i] if lfsisdir (readable) then result[#result+1] = readable end -- cgit v1.2.3