From dbe92b0e0e771352c4307ff3eb8f04f9cfd8ec02 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 22 Jun 2013 12:38:04 +0200 Subject: add unsafe fallback to character data lookup --- luaotfload-auxiliary.lua | 2 +- luaotfload-extralibs.lua | 12 +++++++++--- mkcharacters | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/luaotfload-auxiliary.lua b/luaotfload-auxiliary.lua index 0dfabe6..8fc8477 100644 --- a/luaotfload-auxiliary.lua +++ b/luaotfload-auxiliary.lua @@ -358,7 +358,7 @@ do local index = function (t, k) if chardata == nil then log("Loading character metadata from %s.", chardef) - chardata = dofile(kpse.find_file("luaotfload-characters.lua", "lua")) + chardata = dofile(kpse.find_file(chardef, "lua")) if chardata == nil then warning("Could not load %s; continuing with empty character table.", chardef) diff --git a/luaotfload-extralibs.lua b/luaotfload-extralibs.lua index 90dbf09..3204229 100644 --- a/luaotfload-extralibs.lua +++ b/luaotfload-extralibs.lua @@ -176,9 +176,15 @@ if not chardata then if k == true then return chardata[currentfont()] else - local characters = identifiers[k].characters - t[k] = characters - return characters + local tfmdata = identifiers[k] + if not tfmdata then --- unsafe + tfmdata = font.fonts[k] + end + if tfmdata then + local characters = tfmdata.characters + t[k] = characters + return characters + end end end) fonthashes.characters = chardata diff --git a/mkcharacters b/mkcharacters index a627ea9..a1c4204 100755 --- a/mkcharacters +++ b/mkcharacters @@ -5,7 +5,7 @@ -- DESCRIPTION: import parts of char-def.lua -- REQUIREMENTS: lua, ConTeXt, the lualibs package -- AUTHOR: Philipp Gesang (Phg), --- VERSION: 1.0 +-- VERSION: 1.1 -- CREATED: 2013-05-17 12:41:39+0200 ----------------------------------------------------------------------- -- we create a stripped-down version of char-def.lua @@ -16,7 +16,10 @@ ----------------------------------------------------------------------- local charfile = "./luaotfload-characters.lua" local chardef = "~phg/base/char-def.lua" -local import = { "direction", "mirror", } --> πολυγλωσσία/uax9 +local import = { + "direction", "mirror", --> πολυγλωσσία/uax9 + "category", --> https://gist.github.com/phi-gamma/5812290 +} ----------------------------------------------------------------------- -- includes -- cgit v1.2.3 From 5fa488d55de0b89708e6028491fffa5f43ca279d Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 22 Jun 2013 13:11:31 +0200 Subject: add extra safeguard against moved files to cached resolver --- luaotfload-database.lua | 78 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 22 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 8106898..41adf88 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -34,6 +34,7 @@ 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 kpsereadable_file = kpse.readable_file local lfsisdir = lfs.isdir local lfsisfile = lfs.isfile @@ -424,6 +425,52 @@ crude_file_lookup = function (filename) return filename, nil end +--[[doc-- +Existence of the resolved file name is verified differently depending +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 + if kpselookup(basename) then + return true, basename, entry.subfont + end + else + local fullname = fullnames[entry.index] + if lfsisfile(fullname) then + return true, basename, entry.subfont + end + end + return false +end + +--[[doc-- +We need to verify if the result of a cached lookup actually exists in +the texmf or filesystem. +--doc]]-- + +local verify_font_file = function (basename) + local filenames = names.data.filenames + local idx = filenames.base[basename] + if not idx then + return false + end + + --- firstly, check filesystem + local fullname = filenames.full[idx] + if fullname and lfsisfile(fullname) then + return true + end + + --- secondly, locate via kpathsea + if kpsefind_file(basename) then + return true + end + + return false +end + --[[doc-- Lookups can be quite costly, more so the less specific they are. Even if we find a matching font eventually, the next time the @@ -496,9 +543,16 @@ resolve_cached = function (_, _, specification) --- case 1) cache positive ---------------------------------------- if found then --- replay fields from cache hit report("info", 4, "cache", "found!") - return found[1], found[2], true + 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") + else + report("both", 4, "cache", "not cached; resolving") end - report("both", 4, "cache", "not cached; resolving") --- case 2) cache negative ---------------------------------------- --- first we resolve normally ... @@ -541,26 +595,6 @@ 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 get_font_file = function (fullnames, entry) - local basename = entry.basename - if entry.texmf == true then - if kpselookup(basename) then - return true, basename, entry.subfont - end - else - local fullname = fullnames[entry.index] - if lfsisfile(fullname) then - return true, basename, entry.subfont - end - end - return false -end - --[[doc-- Luatex-fonts, the font-loader package luaotfload imports, comes with -- cgit v1.2.3 From bd0a8039e89b9403b58ac5a9827a333276a6fbf6 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 22 Jun 2013 16:16:21 +0200 Subject: treat *medium* as a synonym for *bold* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit treating *medium* as *regular* weight leads to incorrect matches with Garamond Premier and likely other fonts as well. apparently, this also happened with other typographical programs, e. g. http://blogs.adobe.com/typblography/2008/05/indesign_font_conflicts.html note: the matching algorithm could be rewritten so as to resolve names in two passes: 1. collect a list of candidates. if there is a literal match, pick that one 2. test style synonyms against the candidates according to a precedence list so that “regular” always precedes “medium” to take this thought a bit further, the synonyms could also be ordered by weight according to some assumptions. then we could pick the closest weight present in the database. example: suppose *regular* is assigned a weight index of 3, *medium* gets *4* (i. e. just a tad heavier), and *bold* 7. then the synonym regular would be preferred for the request *regular* if present, but medium would be chosen over bold if there is no *regular* shape. this would probably be overkill, though. --- luaotfload-database.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 41adf88..4c45d21 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -326,12 +326,14 @@ end local style_synonyms = { set = { } } do + --- read this: http://blogs.adobe.com/typblography/2008/05/indesign_font_conflicts.html + --- tl;dr: font style synonyms are unreliable. style_synonyms.list = { - regular = { "normal", "roman", - "plain", "book", - "medium", }, + regular = { "normal", "roman", + "plain", "book", }, bold = { "demi", "demibold", - "semibold", "boldregular",}, + "semibold", "boldregular", + "medium" }, italic = { "regularitalic", "normalitalic", "oblique", "slanted", }, bolditalic = { "boldoblique", "boldslanted", -- cgit v1.2.3