diff options
Diffstat (limited to 'otfl-font-nms.lua')
-rw-r--r-- | otfl-font-nms.lua | 75 |
1 files changed, 41 insertions, 34 deletions
diff --git a/otfl-font-nms.lua b/otfl-font-nms.lua index 2e54028..cec2a54 100644 --- a/otfl-font-nms.lua +++ b/otfl-font-nms.lua @@ -21,6 +21,9 @@ local tonumber = tonumber 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 kpsereadable_file = kpse.readable_file local mathabs = math.abs local mathmin = math.min local stringfind = string.find @@ -40,10 +43,11 @@ local utf8lower = unicode.utf8.lower --- these come from Lualibs/Context local dirglob = dir.glob -local dirmkdirs = dir.mkdirds +local dirmkdirs = dir.mkdirs local filebasename = file.basename local filecollapsepath = file.collapsepath local fileextname = file.extname +local fileiswritable = file.iswritable local filejoin = file.join local filereplacesuffix = file.replacesuffix local filesplitpath = file.splitpath @@ -180,15 +184,15 @@ load_names = function ( ) local foundname, data = load_lua_file(names.path.path) if data then - report("info", 0, "Font names database loaded", "%s", foundname) + report("info", 1, "db", + "Font names database loaded", "%s", foundname) else - report("info", 0, + report("info", 0, "db", [[Font names database not found, generating new one. This can take several minutes; please be patient.]]) data = update_names(fontnames_init()) save_names(data) end - texiowrite_nl"" return data end @@ -251,7 +255,7 @@ font database created by the mkluatexfontdb script. --- --- the return value of “resolve” is the file name of the requested --- font ---- +--- --- 'a -> 'a -> table -> (string * string | bool * bool) --- --- note by phg: I added a third return value that indicates a @@ -358,8 +362,8 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con end end if #found == 1 then - if kpse.lookup(found[1].filename[1]) then - report("log", 0, "load font", + if kpselookup(found[1].filename[1]) then + report("log", 0, "resolve", "font family='%s', subfamily='%s' found: %s", name, style, found[1].filename[1] ) @@ -379,8 +383,8 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con least = difference end end - if kpse.lookup(closest.filename[1]) then - report("log", 0, "load font", + if kpselookup(closest.filename[1]) then + report("log", 0, "resolve", "font family='%s', subfamily='%s' found: %s", name, style, closest.filename[1] ) @@ -396,7 +400,7 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con else --- else, fallback to requested name --- specification.name is empty with absolute paths, looks - --- like a bug in the specification parser << is it still + --- like a bug in the specification parser <TODO< is it still --- relevant? looks not... return specification.name, false, false end @@ -569,7 +573,7 @@ font_fullinfo = function (filename, subfont, texmf) end else -- no names table, propably a broken font - report("log", 1, "broken font rejected", "%s", basefile) + report("log", 1, "db", "broken font rejected", "%s", basefile) return end tfmdata.fontname = metadata.fontname @@ -601,7 +605,7 @@ local load_font = function (filename, fontnames, newfontnames, texmf) if filename then if names.blacklist[filename] or names.blacklist[basename] then - report("log", 2, "ignoring font", "%s", filename) + report("log", 2, "db", "ignoring font", "%s", filename) return end local timestamp, db_timestamp @@ -624,7 +628,7 @@ local load_font = function (filename, fontnames, newfontnames, texmf) newmappings[#newmappings+1] = mappings[v] newstatus[basefile].index[index+1] = #newmappings end - report("log", 1, "font already indexed", "%s", basefile) + report("log", 1, "db", "font already indexed", "%s", basefile) return end local info = fontloader.info(filename) @@ -659,7 +663,7 @@ local load_font = function (filename, fontnames, newfontnames, texmf) newstatus[basefile].index[1] = index end else - report("log", 1, "failed to load", "%s", basefile) + report("log", 1, "db", "failed to load", "%s", basefile) end end end @@ -681,9 +685,9 @@ local function path_normalize(path) if os.type ~= "windows" and os.type ~= "msdos" then local dest = lfs.readlink(path) if dest then - if kpse.readable_file(dest) then + if kpsereadable_file(dest) then path = dest - elseif kpse.readable_file(filejoin(file.dirname(path), dest)) then + elseif kpsereadable_file(filejoin(file.dirname(path), dest)) then path = filejoin(file.dirname(path), dest) else -- broken symlink? @@ -700,7 +704,7 @@ names.blacklist = { } local function read_blacklist() local files = { - kpse.lookup("otfl-blacklist.cnf", {all=true, format="tex"}) + kpselookup("otfl-blacklist.cnf", {all=true, format="tex"}) } local blacklist = names.blacklist local whitelist = { } @@ -719,7 +723,7 @@ local function read_blacklist() if stringsub(line, 1, 1) == "-" then whitelist[stringsub(line, 2, -1)] = true else - report("log", 2, "blacklisted file", "%s", line) + report("log", 2, "db", "blacklisted file", "%s", line) blacklist[line] = true end end @@ -776,22 +780,25 @@ local function scan_dir(dirname, fontnames, newfontnames, texmf) ]] local list, found = { }, { } local nbfound = 0 - report("log", 2, "scanning", "%s", dirname) + report("log", 2, "db", "scanning", "%s", dirname) for _,i in next, font_extensions do for _,ext in next, { i, stringupper(i) } do found = dirglob(stringformat("%s/**.%s$", dirname, ext)) -- note that glob fails silently on broken symlinks, which happens -- sometimes in TeX Live. - report("log", 2, "fonts found", "%s '%s' fonts found", #found, ext) + report("log", 2, "db", + "fonts found", "%s '%s' fonts found", #found, ext) nbfound = nbfound + #found tableappend(list, found) end end - report("log", 2, "fonts found", "%d fonts found in '%s'", nbfound, dirname) + report("log", 2, "db", + "fonts found", "%d fonts found in '%s'", nbfound, dirname) for _,file in next, list do file = path_normalize(file) - report("log", 1, "loading font", "%s", file) + report("log", 1, "db", + "loading font", "%s", file) load_font(file, fontnames, newfontnames, texmf) end end @@ -802,9 +809,9 @@ local function scan_texmf_fonts(fontnames, newfontnames) variables OPENTYPEFONTS and TTFONTS of texmf.cnf ]] if stringis_empty(kpseexpand_path("$OSFONTDIR")) then - report("info", 0, "Scanning TEXMF fonts...") + report("info", 1, "db", "Scanning TEXMF fonts...") else - report("info", 0, "Scanning TEXMF and OS fonts...") + report("info", 1, "db", "Scanning TEXMF and OS fonts...") end local fontdirs = stringgsub(kpseexpand_path("$OPENTYPEFONTS"), "^%.", "") fontdirs = fontdirs .. stringgsub(kpseexpand_path("$TTFONTS"), "^%.", "") @@ -844,7 +851,7 @@ read_fonts_conf = function (path, results, passed_paths) passed_paths[#passed_paths+1] = path passed_paths_set = tabletohash(passed_paths, true) if not fh then - report("log", 2, "cannot open file", "%s", path) + report("log", 2, "db", "cannot open file", "%s", path) return results end local incomments = false @@ -895,7 +902,7 @@ read_fonts_conf = function (path, results, passed_paths) include = filejoin(file.dirname(path), include) end if lfs.isfile(include) - and kpse.readable_file(include) + and kpsereadable_file(include) and not passed_paths_set[include] then -- maybe we should prevent loops here? @@ -953,8 +960,8 @@ local function scan_os_fonts(fontnames, newfontnames) - fontcache for Unix (reads the fonts.conf file and scans the directories) - a static set of directories for Windows and MacOSX ]] - report("info", 0, "Scanning OS fonts...") - report("info", 2, "Searching in static system directories...") + report("info", 1, "db", "Scanning OS fonts...") + report("info", 2, "db", "Searching in static system directories...") for _,d in next, get_os_dirs() do scan_dir(d, fontnames, newfontnames, false) end @@ -966,7 +973,7 @@ update_names = function (fontnames, force) - fontnames is the final table to return - force is whether we rebuild it from scratch or not ]] - report("info", 0, "Updating the font names database") + report("info", 1, "db", "Updating the font names database") if force then fontnames = fontnames_init() @@ -976,8 +983,8 @@ update_names = function (fontnames, force) end if fontnames.version ~= names.version then fontnames = fontnames_init() - report("log", 0, "No font names database or old one found; " - .."generating new one") + report("log", 1, "db", "No font names database or old " + .. "one found; generating new one") end end local newfontnames = fontnames_init() @@ -1000,14 +1007,14 @@ save_names = function (fontnames) dirmkdirs(path) end path = filejoin(path, names.path.basename) - if file.iswritable(path) then + if fileiswritable(path) then local luaname, lucname = make_name(path) tabletofile(luaname, fontnames, true) caches.compile(fontnames,luaname,lucname) - report("info", 0, "Font names database saved") + report("info", 0, "db", "Font names database saved") return path else - report("info", 0, "Failed to save names database") + report("info", 0, "db", "Failed to save names database") return nil end end |