summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--otfl-font-nms.lua38
1 files changed, 31 insertions, 7 deletions
diff --git a/otfl-font-nms.lua b/otfl-font-nms.lua
index 20e5fbd..1f9da96 100644
--- a/otfl-font-nms.lua
+++ b/otfl-font-nms.lua
@@ -67,15 +67,12 @@ function names.load()
else
logs.report("load font",
"no font names database found, generating new one")
- local savepath = names.path.localdir .. names.path.basename
data = names.update()
- io.savedata(savepath, table.serialize(data, true))
+ names.save(data)
end
return data
end
-local loaded = false
-
local synonyms = {
regular = {
normal = true,
@@ -96,6 +93,9 @@ local synonyms = {
},
}
+local loaded = false
+local reloaded = false
+
function names.resolve(specification)
local tfm = resolvers.find_file(specification.name, "ofm")
local name = sanitize(specification.name)
@@ -215,7 +215,25 @@ function names.resolve(specification)
return closest.filename[1], closest.filename[2]
end
end
- -- no font found so far, fallback to filename
+ -- no font found so far
+ if not reloaded then
+ -- try reloading the database
+ names.data = names.update(names.data)
+ names.save(names.data)
+ reloaded = true
+ return names.resolve(specification)
+ else
+ -- else, fallback to filename
+ return specification.name, false
+ end
+ end
+ else
+ if not reloaded then
+ names.data = names.update()
+ names.save(names.data)
+ reloaded = true
+ return names.resolve(specification)
+ else
return specification.name, false
end
end
@@ -523,7 +541,7 @@ local function scan_os_fonts(fontnames, newfontnames)
end
end
-local function update(fontnames, force)
+local function update_names(fontnames, force)
--[[
The main function, scans everything
- fontnames is the final table to return
@@ -548,5 +566,11 @@ local function update(fontnames, force)
return newfontnames
end
+local function save_names(fontnames)
+ local savepath = names.path.localdir .. names.path.basename
+ io.savedata(savepath, table.serialize(fontnames, true))
+end
+
names.scan = scan_dir
-names.update = update
+names.update = update_names
+names.save = save_names