summaryrefslogtreecommitdiff
path: root/luaotfload-database.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-06-22 07:34:29 -0700
committerPhilipp Gesang <phg42.2a@gmail.com>2013-06-22 07:34:29 -0700
commit1caf2aa7b019b687e9b97e3a7a2d6ab55070f577 (patch)
tree8e8cc079a4b9b235df95344a30873de969f497fa /luaotfload-database.lua
parent5aa54f3169985d0457b3517f49da961a51b2f1cc (diff)
parentbd0a8039e89b9403b58ac5a9827a333276a6fbf6 (diff)
downloadluaotfload-1caf2aa7b019b687e9b97e3a7a2d6ab55070f577.tar.gz
Merge pull request #99 from phi-gamma/master
fixes
Diffstat (limited to 'luaotfload-database.lua')
-rw-r--r--luaotfload-database.lua88
1 files changed, 62 insertions, 26 deletions
diff --git a/luaotfload-database.lua b/luaotfload-database.lua
index 8106898..4c45d21 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
@@ -325,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",
@@ -425,6 +428,52 @@ crude_file_lookup = function (filename)
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
user compiles Eir document E will have to stand through the delay
@@ -496,9 +545,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 ...
@@ -542,26 +598,6 @@ local add_to_match = function (
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
basic file location facilities (see luatex-fonts-syn.lua).