From 669810faca6f3fc870b206fff143a716986604d7 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 28 Jul 2013 14:24:52 +0200 Subject: update news --- NEWS | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS b/NEWS index 0875cfa..2cd2ade 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,11 @@ Change History -------------- +2013/XX/XX, luaotfload v2.4 + * additional self-tests, now in separate file (luaotfload-diagnostics.lua) + * better path and directory handling, especially on Windows + * test runner (script mktests) + 2013/07/10, luaotfload v2.3a * Detect LuaJIT interpreter (LuaJITTeX) * Self-test functionality for luaotfload-tool.lua (option ``--diagnose``) -- cgit v1.2.3 From 5c0a95b933cc0bcff531a4725f8170b2aec1726b Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 28 Jul 2013 14:48:20 +0200 Subject: [tool] work around ms compiler limitations --- luaotfload-diagnostics.lua | 8 +++++++- luaotfload-tool.lua | 13 +++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/luaotfload-diagnostics.lua b/luaotfload-diagnostics.lua index db807de..46ae412 100644 --- a/luaotfload-diagnostics.lua +++ b/luaotfload-diagnostics.lua @@ -312,7 +312,12 @@ else out ("%d of %d Github API requests left.", left, limit) if left == 0 then out ("Cannot make any more API requests.") - out ("Try again later at %s.", osdate ("%F %T", reset)) + if ostype == "unix" then + out ("Try again later at %s.", osdate ("%F %T", reset)) + else --- windows doesn’t C99 + out ("Try again later at %s.", + osdate ("%Y-%m-d %H:%M:%S", reset)) + end end return true end @@ -620,3 +625,4 @@ end return diagnose +-- vim:tw=71:sw=4:ts=4:expandtab diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 92483d6..3846700 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -46,6 +46,7 @@ local iowrite = io.write local kpsefind_file = kpse.find_file local next = next local osdate = os.date +local ostype = os.type local stringexplode = string.explode local stringformat = string.format local stringlower = string.lower @@ -507,7 +508,14 @@ local display_general = function (fullinfo) val = #fullinfo[key] end elseif mode == "d" then - val = osdate("%F %T", fullinfo[key]) + if ostype == "unix" then + val = osdate("%F %T", fullinfo[key]) + else + --- the MS compiler doesn’t support C99, so + --- strftime is missing some functionality; + --- see loslib.c for details. + val = osdate("%Y-%m-d %H:%M:%S", fullinfo[key]) + end end if not val then val = "" @@ -795,7 +803,8 @@ actions.query = function (job) "Resolved file name %q", foundname) end if job.show_info then - show_font_info(foundname, query, job.full_info, job.warnings) + show_font_info (foundname, query, job.full_info, job.warnings) + texiowrite_nl "" end else logs.names_report(false, 0, -- cgit v1.2.3 From 8b7adc199faee75515175e15b176ac168c09b467 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 31 Jul 2013 00:53:48 +0200 Subject: [db] include pfb in index --- luaotfload-database.lua | 150 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 131 insertions(+), 19 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index a0a532e..20ff1bf 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -28,7 +28,9 @@ local tonumber = tonumber local unpack = table.unpack local fontloaderinfo = fontloader.info +local fontloaderclose = fontloader.close local fontloaderopen = fontloader.open +local fontloaderto_table = fontloader.to_table local iolines = io.lines local ioopen = io.open local kpseexpand_path = kpse.expand_path @@ -67,6 +69,7 @@ local filejoin = file.join local filenameonly = file.nameonly local filereplacesuffix = file.replacesuffix local filesplitpath = file.splitpath or file.split_path +local filesuffix = file.suffix local lfsisdir = lfs.isdir local lfsisfile = lfs.isfile local lfsmkdirs = lfs.mkdirs @@ -351,7 +354,8 @@ local crude_file_lookup local crude_file_lookup_verbose local find_closest local flush_lookup_cache -local font_fullinfo +local ot_fullinfo +local t1_fullinfo local load_names local load_lookups local read_blacklist @@ -1095,22 +1099,33 @@ local sanitize_names = function (names) return res end +local load_font_file = function (filename, subfont) + local rawfont, _msg = fontloaderopen (filename, subfont) + if not rawfont then + report ("log", 1, "db", "ERROR: failed to open %s", filename) + return + end + local metadata = fontloaderto_table (rawfont) + fontloaderclose (rawfont) + collectgarbage "collect" + return metadata +end + --[[doc-- The data inside an Opentype font file can be quite heterogeneous. Thus in order to get the relevant information, parts of the original table as returned by the font file reader need to be relocated. --doc]]-- + --- string -> int -> bool -> string -> fontentry -font_fullinfo = function (filename, subfont, texmf, basename) +ot_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) - return + + local metadata = load_font_file (filename, subfont) + if not metadata then + return nil end - local metadata = fontloader.to_table(rawfont) - fontloader.close(rawfont) - collectgarbage("collect") + -- see http://www.microsoft.com/typography/OTSPEC/features_pt.htm#size if metadata.fontstyle_name then for _, name in next, metadata.fontstyle_name do @@ -1119,6 +1134,7 @@ font_fullinfo = function (filename, subfont, texmf, basename) end end end + if metadata.names then for _, namedata in next, metadata.names do if namedata.lang == "English (US)" then @@ -1171,13 +1187,98 @@ font_fullinfo = function (filename, subfont, texmf, basename) return tfmdata end +--[[doc-- + + Type1 font inspector. PFB’s contain a good deal less name fields + which makes it tricky in some parts to find a meaningful representation + for the database. + +--doc]]-- + +--- string -> int -> bool -> string -> fontentry +t1_fullinfo = function (filename, _subfont, texmf, basename) + local namedata = { } + local metadata = load_font_file (filename) + + local fontname = metadata.fontname + local fullname = metadata.fullname + local familyname = metadata.familyname + local italicangle = metadata.italicangle + local weight = metadata.weight + + --- we have to improvise and detect whether we deal with + --- italics since pfb fonts don’t come with a “subfamily” + --- field + local style + if italicangle == 0 then + style = false + else + style = "italic" + end + + if weight then + weight = sanitize_string (weight) + if style then + if style_synonyms.set.bold[weight] then + style = "bold" .. style + end + else + if style_synonyms.set.regular[weight] then + style = "regular" + end + end + end + + if not style then + style = "regular" + end + + namedata.sanitized = sanitize_names ({ + fontname = fontname, + psname = fullname, + pfullname = fullname, + metafamily = family, + family = familyname, + subfamily = weight, + prefmodifiers = style, + }) + + namedata.fontname = fontname + namedata.fullname = fullname + namedata.familyname = familyname + + namedata.weight = 0 -- dummy + namedata.version = metadata.version + + namedata.size = { } + + namedata.filename = filename --> sys + namedata.basename = basename --> texmf + namedata.texmf = texmf or false + namedata.subfont = subfont + return namedata +end + +local loaders = { + otf = ot_fullinfo, + ttf = ot_fullinfo, + + afm = function (filename, _, texmf, basename) + --- TODO + local pfbname = filereplacesuffix (filename, "pfb") + if lfsisfile (pfbname) then + return t1_fullinfo (pfbname, nil, texmf, basename) + end + report ("both", 1, "db", + "Cannot find matching pfb for %s; skipping.", basename) + return false + end, + pfb = t1_fullinfo, +} + --- we return true if the fond is new or re-indexed --- string -> dbobj -> dbobj -> bool local load_font = function (fullname, fontnames, newfontnames, texmf) - if not fullname then - return false - end - local newmappings = newfontnames.mappings local newstatus = newfontnames.status --- by full path @@ -1187,6 +1288,8 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) local basename = filebasename(fullname) local barename = filenameonly(fullname) + local format = stringlower (filesuffix (basename)) + local entryname = fullname if texmf == true then entryname = basename @@ -1230,11 +1333,18 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) return false end + local loader = loaders[format] --- ot_fullinfo, t1_fullinfo + if not loader then + report ("both", 0, "db", + "Unknown format: %q, skipping.", format) + return false + end + local info = fontloaderinfo(fullname) if info then if type(info) == "table" and #info > 1 then --- ttc for n_font = 1, #info do - local fullinfo = font_fullinfo(fullname, n_font-1, texmf, basename) + local fullinfo = loader (fullname, n_font-1, texmf, basename) if not fullinfo then return false end @@ -1246,7 +1356,7 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) newentrystatus.index[n_font] = index end else - local fullinfo = font_fullinfo(fullname, false, texmf, basename) + local fullinfo = loader (fullname, false, texmf, basename) if not fullinfo then return false end @@ -1409,7 +1519,7 @@ read_blacklist = function () names.blacklist = create_blacklist(blacklist, whitelist) end -local font_extensions = { "otf", "ttf", "ttc", "dfont" } +local font_extensions = { "otf", "ttf", "ttc", "dfont", "pfb" } local font_extensions_set = tabletohash (font_extensions) local p_font_extensions do @@ -1596,6 +1706,8 @@ local scan_texmf_fonts = function (fontnames, newfontnames, dry_run) fontdirs = kpseexpand_path "$OPENTYPEFONTS" fontdirs = fontdirs .. (ostype == "windows" and ";" or ":") .. kpseexpand_path "$TTFONTS" + fontdirs = fontdirs .. (ostype == "windows" and ";" or ":") + .. kpseexpand_path "$T1FONTS" if not stringis_empty (fontdirs) then local tasks = filter_out_pwd (filesplitpath (fontdirs)) report ("info", 3, "db", @@ -2118,11 +2230,11 @@ local purge_from_cache = function (category, path, list, all) osremove(filename) n = n + 1 else - local suffix = file.suffix(filename) + local suffix = filesuffix(filename) if suffix == "lua" then local checkname = file.replacesuffix( filename, "lua", "luc") - if lfs.isfile(checkname) then + if lfsisfile(checkname) then report("info", 5, "cache", "Removing %s", filename) osremove(filename) n = n + 1 @@ -2148,7 +2260,7 @@ local collect_cache collect_cache = function (path, all, n, luanames, local filename = all[n] if filename then - local suffix = file.suffix(filename) + local suffix = filesuffix(filename) if suffix == "lua" then luanames[#luanames+1] = filename elseif suffix == "luc" then -- cgit v1.2.3 From e2ca2159f6952db10ad35dc961e0fa51832033bc Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 31 Jul 2013 00:59:22 +0200 Subject: avoid duplication when logging to file and stdout --- luaotfload-override.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/luaotfload-override.lua b/luaotfload-override.lua index 19cd505..8e467d5 100644 --- a/luaotfload-override.lua +++ b/luaotfload-override.lua @@ -99,8 +99,9 @@ end local set_logout = function (s, finalizers) if s == "stdout" then - logout = "term" + logout = "redirect" elseif s == "file" then --- inject custom logger + logout = "redirect" local chan = choose_logfile () chan:write (stringformat ("logging initiated at %s", osdate ("%F %T", ostime ()))) @@ -224,7 +225,7 @@ local names_report = function (mode, lvl, ...) if loglevel >= lvl then if mode == "log" then log (...) - elseif mode == "both" and log ~= "stdout" then + elseif mode == "both" and logout ~= "redirect" then log (...) stdout (...) else -- cgit v1.2.3 From f84c7341ed8f83c0624be6be2ea796d4bbb97ae9 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 31 Jul 2013 21:50:07 +0200 Subject: [db] make pfb scanning optional --- luaotfload-database.lua | 121 ++++++++++++++++++++++++++++++++---------------- luaotfload-tool.lua | 6 ++- luaotfload.dtx | 3 +- 3 files changed, 88 insertions(+), 42 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 20ff1bf..f53d19f 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -93,6 +93,8 @@ local names = fonts.names config = config or { } config.luaotfload = config.luaotfload or { } config.luaotfload.resolver = config.luaotfload.resolver or "normal" +config.luaotfload.include_t1 = config.luaotfload.include_t1 == true + if config.luaotfload.update_live ~= false then --- this option allows for disabling updates --- during a TeX run @@ -1519,26 +1521,43 @@ read_blacklist = function () names.blacklist = create_blacklist(blacklist, whitelist) end -local font_extensions = { "otf", "ttf", "ttc", "dfont", "pfb" } -local font_extensions_set = tabletohash (font_extensions) -local p_font_extensions +local ordinary_extensions = { "otf", "ttf", "ttc", "dfont" } +local type1_extensions = { "pfb", --[[afm]] } +----- font_extensions_set = tabletohash (font_extensions) +local get_font_filter + 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) + local luaotfloadconfig = config.luaotfload + + local extension_pattern = function (list) + local pat + for i=#list, 1, -1 do + local e = list[i] + if not pat then + pat = P(e) + else + pat = pat + P(e) + end + end + return pat * P(-1) + end + + local extns = extension_pattern (ordinary_extensions) + local t1extns = extns + extension_pattern (type1_extensions) + local ordinary = (1 - extns)^1 * extns + local with_t1 = (1 - t1extns)^1 * t1extns + + get_font_filter = function () + if luaotfloadconfig.include_t1 == true then + return with_t1 else - extns = extns + P(e) + return ordinary end end - extns = extns * P(-1) - p_font_extensions = (1 - extns)^1 * extns end local process_dir_tree -process_dir_tree = function (acc, dirs) +process_dir_tree = function (acc, dirs, criterium) if not next (dirs) then --- done return acc end @@ -1561,21 +1580,20 @@ process_dir_tree = function (acc, dirs) then dirs[#dirs+1] = fullpath elseif lfsisfile (fullpath) then - if lpegmatch (p_font_extensions, - stringlower (ent)) + if lpegmatch (criterium, stringlower (ent)) then newfiles[#newfiles+1] = fullpath end end end end - return process_dir_tree (tableappend (acc, newfiles), dirs) + return process_dir_tree (tableappend (acc, newfiles), dirs, criterium) end --- cannot cd; skip - return process_dir_tree (acc, dirs) + return process_dir_tree (acc, dirs, criterium) end -local process_dir = function (dir) +local process_dir = function (dir, criterium) local pwd = lfscurrentdir () if lfschdir (dir) then lfschdir (pwd) @@ -1586,8 +1604,7 @@ local process_dir = function (dir) if ent ~= "." and ent ~= ".." and not blacklist[ent] then local fullpath = dir .. "/" .. ent if lfsisfile (fullpath) then - if lpegmatch (p_font_extensions, - stringlower (ent)) + if lpegmatch (criterium, stringlower (ent)) then files[#files+1] = fullpath end @@ -1601,11 +1618,12 @@ end --- string -> bool -> string list local find_font_files = function (root, recurse) + local criterium = get_font_filter () if lfsisdir (root) then if recurse == true then - return process_dir_tree ({}, { root }) + return process_dir_tree ({}, { root }, criterium) else --- kpathsea already delivered the necessary subdirs - return process_dir (root) + return process_dir (root, criterium) end end end @@ -1679,6 +1697,8 @@ local filter_out_pwd = function (dirs) return result end +local path_separator = ostype == "windows" and ";" or ":" + --[[doc-- scan_texmf_fonts() scans all fonts in the texmf tree through the kpathsea variables OPENTYPEFONTS and TTFONTS of texmf.cnf. @@ -1688,8 +1708,10 @@ end --- dbobj -> dbobj -> bool? -> (int * int) local scan_texmf_fonts = function (fontnames, newfontnames, dry_run) + local n_scanned, n_new, fontdirs = 0, 0 local osfontdir = kpseexpand_path "$OSFONTDIR" + if stringis_empty (osfontdir) then report ("info", 2, "db", "Scanning TEXMF fonts...") else @@ -1703,11 +1725,11 @@ local scan_texmf_fonts = function (fontnames, newfontnames, dry_run) end end end + fontdirs = kpseexpand_path "$OPENTYPEFONTS" - fontdirs = fontdirs .. (ostype == "windows" and ";" or ":") - .. kpseexpand_path "$TTFONTS" - fontdirs = fontdirs .. (ostype == "windows" and ";" or ":") - .. kpseexpand_path "$T1FONTS" + fontdirs = fontdirs .. path_separator .. kpseexpand_path "$TTFONTS" + fontdirs = fontdirs .. path_separator .. kpseexpand_path "$T1FONTS" + if not stringis_empty (fontdirs) then local tasks = filter_out_pwd (filesplitpath (fontdirs)) report ("info", 3, "db", @@ -1719,6 +1741,7 @@ local scan_texmf_fonts = function (fontnames, newfontnames, dry_run) n_new = n_new + new end end + return n_scanned, n_new end @@ -1973,22 +1996,36 @@ local function get_os_dirs () return {} end ---- dbobj -> dbobj -> bool? -> (int * int) -local scan_os_fonts = function (fontnames, newfontnames, dry_run) - local n_scanned, n_new = 0, 0 - --[[ - This function scans the OS fonts through - - fontcache for Unix (reads the fonts.conf file and scans the +--[[doc-- + + scan_os_fonts() scans the OS fonts through + - fontconfig for Unix (reads the fonts.conf file[s] and scans the directories) - a static set of directories for Windows and MacOSX - ]] - report("info", 2, "db", "Scanning OS fonts...") - report("info", 3, "db", "Searching in static system directories...") - for _, d in next, get_os_dirs() do - local found, new = scan_dir(d, fontnames, newfontnames, dry_run) + + **NB**: If $OSFONTDIR is nonempty, as it appears to be by default + on Windows setups, the system fonts will have already been + processed while scanning the TEXMF. Thus, this function is + never called. + +--doc]]-- + +--- dbobj -> dbobj -> bool? -> (int * int) +local scan_os_fonts = function (fontnames, newfontnames, + dry_run) + + local n_scanned, n_new = 0, 0 + report ("info", 2, "db", "Scanning OS fonts...") + report ("info", 3, "db", + "Searching in static system directories...") + + for _, d in next, get_os_dirs () do + local found, new = scan_dir (d, fontnames, + newfontnames, dry_run) n_scanned = n_scanned + found n_new = n_new + new end + return n_scanned, n_new end @@ -2080,14 +2117,17 @@ end --- dbobj? -> bool? -> bool? -> dbobj update_names = function (fontnames, force, dry_run) + if config.luaotfload.update_live == false then report("info", 2, "db", "skipping database update") --- skip all db updates return fontnames or names.data end + local starttime = os.gettimeofday() local n_scanned, n_new = 0, 0 + --[[ The main function, scans everything - “newfontnames” is the final table to return @@ -2112,11 +2152,11 @@ update_names = function (fontnames, force, dry_run) read_blacklist() local scanned, new - scanned, new = scan_texmf_fonts(fontnames, newfontnames, dry_run) + scanned, new = scan_texmf_fonts (fontnames, newfontnames, dry_run) n_scanned = n_scanned + scanned n_new = n_new + new - scanned, new = scan_os_fonts(fontnames, newfontnames, dry_run) + scanned, new = scan_os_fonts (fontnames, newfontnames, dry_run) n_scanned = n_scanned + scanned n_new = n_new + new @@ -2375,7 +2415,8 @@ else names.resolve = resolve names.resolvespec = resolve end -names.find_closest = find_closest + +names.find_closest = find_closest -- for testing purpose names.read_fonts_conf = read_fonts_conf diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 3846700..1e88d4f 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -108,6 +108,7 @@ config.luaotfload.names_dir = config.luaotfload.names_dir or "names" config.luaotfload.cache_dir = config.luaotfload.cache_dir or "fonts" config.luaotfload.index_file = config.luaotfload.index_file or "luaotfload-names.lua" +config.luaotfload.include_t1 = config.luaotfload.include_t1 == true do -- we don’t have file.basename and the likes yet, so inline parser ftw local slash = P"/" @@ -1025,8 +1026,9 @@ local process_cmdline = function ( ) -- unit -> jobspec ["prefer-texmf"] = "p", quiet = "q", ["show-blacklist"] = "b", + type1 = 0, update = "u", - verbose = 1 , + verbose = 1, version = "V", warnings = "w", } @@ -1108,6 +1110,8 @@ local process_cmdline = function ( ) -- unit -> jobspec elseif v == "diagnose" then action_pending["diagnose"] = true result.asked_diagnostics = optarg[n] + elseif v == "type1" then + config.luaotfload.include_t1 = true end end diff --git a/luaotfload.dtx b/luaotfload.dtx index e42c14e..f23be81 100644 --- a/luaotfload.dtx +++ b/luaotfload.dtx @@ -1545,10 +1545,11 @@ config.luaotfload.prioritize = config.luaotfload.prioritize or "sys" config.luaotfload.names_dir = config.luaotfload.names_dir or "names" config.luaotfload.cache_dir = config.luaotfload.cache_dir or "fonts" config.luaotfload.index_file = config.luaotfload.index_file or "luaotfload-names.lua" +config.luaotfload.include_t1 = config.luaotfload.include_t1 or false luaotfload.module = { name = "luaotfload", - version = 2.40001, + version = 2.40002, date = "2013/07/28", description = "OpenType layout system.", author = "Elie Roux & Hans Hagen", -- cgit v1.2.3 From e8b9a15801b4d0cd52126d21d4ba262b472ba45c Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 31 Jul 2013 22:37:07 +0200 Subject: [db] remove --type1 option in favor of --formats, a configurable format set --- luaotfload-database.lua | 83 +++++++++++++++++++++++++++++++++++-------------- luaotfload-tool.lua | 8 ++--- 2 files changed, 63 insertions(+), 28 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index f53d19f..cfcd27c 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -93,7 +93,7 @@ local names = fonts.names config = config or { } config.luaotfload = config.luaotfload or { } config.luaotfload.resolver = config.luaotfload.resolver or "normal" -config.luaotfload.include_t1 = config.luaotfload.include_t1 == true +config.luaotfload.formats = config.luaotfload.formats or "otf,ttf,ttc,dfont" if config.luaotfload.update_live ~= false then --- this option allows for disabling updates @@ -369,6 +369,7 @@ local resolve_fullpath local save_names local save_lookups local update_names +local set_font_filter --- state of the database local fonts_loaded = false @@ -1263,6 +1264,7 @@ end local loaders = { otf = ot_fullinfo, + ttc = ot_fullinfo, ttf = ot_fullinfo, afm = function (filename, _, texmf, basename) @@ -1521,13 +1523,13 @@ read_blacklist = function () names.blacklist = create_blacklist(blacklist, whitelist) end -local ordinary_extensions = { "otf", "ttf", "ttc", "dfont" } -local type1_extensions = { "pfb", --[[afm]] } +----- ordinary_extensions = { "otf", "ttf", "ttc", "dfont" } +----- type1_extensions = { "pfb", --[[afm]] } ----- font_extensions_set = tabletohash (font_extensions) -local get_font_filter +local p_font_filter do - local luaotfloadconfig = config.luaotfload + local current_formats = { } local extension_pattern = function (list) local pat @@ -1539,25 +1541,58 @@ do pat = pat + P(e) end end - return pat * P(-1) + pat = pat * P(-1) + return (1 - pat)^1 * pat end - local extns = extension_pattern (ordinary_extensions) - local t1extns = extns + extension_pattern (type1_extensions) - local ordinary = (1 - extns)^1 * extns - local with_t1 = (1 - t1extns)^1 * t1extns + --- small helper to adjust the font filter pattern (--formats + --- option) - get_font_filter = function () - if luaotfloadconfig.include_t1 == true then - return with_t1 - else - return ordinary + set_font_filter = function (formats) + + if not formats and type (formats) == "string" then + return end + + if stringsub (formats, 1, 1) == "+" then -- add + formats = lpegmatch (splitcomma, stringsub (formats, 2)) + if formats then + current_formats = tableappend (current_formats, formats) + end + elseif stringsub (formats, 1, 1) == "-" then -- add + formats = lpegmatch (splitcomma, stringsub (formats, 2)) + if formats then + local newformats = { } + for i = 1, #current_formats do + local fmt = current_formats[i] + local include = true + for j = 1, #formats do + if current_formats[i] == formats[j] then + include = false + goto skip + end + end + newformats[#newformats+1] = fmt + ::skip:: + end + current_formats = newformats + end + else -- set + formats = lpegmatch (splitcomma, formats) + if formats then + current_formats = formats + end + end + + p_font_filter = extension_pattern (current_formats) end + + --- initialize + set_font_filter (config.luaotfload.formats) end local process_dir_tree -process_dir_tree = function (acc, dirs, criterium) +process_dir_tree = function (acc, dirs) if not next (dirs) then --- done return acc end @@ -1580,20 +1615,20 @@ process_dir_tree = function (acc, dirs, criterium) then dirs[#dirs+1] = fullpath elseif lfsisfile (fullpath) then - if lpegmatch (criterium, stringlower (ent)) + if lpegmatch (p_font_filter, stringlower (ent)) then newfiles[#newfiles+1] = fullpath end end end end - return process_dir_tree (tableappend (acc, newfiles), dirs, criterium) + return process_dir_tree (tableappend (acc, newfiles), dirs) end --- cannot cd; skip - return process_dir_tree (acc, dirs, criterium) + return process_dir_tree (acc, dirs) end -local process_dir = function (dir, criterium) +local process_dir = function (dir) local pwd = lfscurrentdir () if lfschdir (dir) then lfschdir (pwd) @@ -1604,7 +1639,7 @@ local process_dir = function (dir, criterium) if ent ~= "." and ent ~= ".." and not blacklist[ent] then local fullpath = dir .. "/" .. ent if lfsisfile (fullpath) then - if lpegmatch (criterium, stringlower (ent)) + if lpegmatch (p_font_filter, stringlower (ent)) then files[#files+1] = fullpath end @@ -1618,12 +1653,11 @@ end --- string -> bool -> string list local find_font_files = function (root, recurse) - local criterium = get_font_filter () if lfsisdir (root) then if recurse == true then - return process_dir_tree ({}, { root }, criterium) + return process_dir_tree ({}, { root }) else --- kpathsea already delivered the necessary subdirs - return process_dir (root, criterium) + return process_dir (root) end end end @@ -2390,6 +2424,7 @@ end ----------------------------------------------------------------------- names.scan_dir = scan_dir +names.set_font_filter = set_font_filter names.flush_lookup_cache = flush_lookup_cache names.save_lookups = save_lookups names.load = load_names diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 1e88d4f..8cac103 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -108,7 +108,7 @@ config.luaotfload.names_dir = config.luaotfload.names_dir or "names" config.luaotfload.cache_dir = config.luaotfload.cache_dir or "fonts" config.luaotfload.index_file = config.luaotfload.index_file or "luaotfload-names.lua" -config.luaotfload.include_t1 = config.luaotfload.include_t1 == true +config.luaotfload.formats = config.luaotfload.formats or "otf,ttf,ttc,dfont" do -- we don’t have file.basename and the likes yet, so inline parser ftw local slash = P"/" @@ -1026,7 +1026,7 @@ local process_cmdline = function ( ) -- unit -> jobspec ["prefer-texmf"] = "p", quiet = "q", ["show-blacklist"] = "b", - type1 = 0, + formats = 1, update = "u", verbose = 1, version = "V", @@ -1110,8 +1110,8 @@ local process_cmdline = function ( ) -- unit -> jobspec elseif v == "diagnose" then action_pending["diagnose"] = true result.asked_diagnostics = optarg[n] - elseif v == "type1" then - config.luaotfload.include_t1 = true + elseif v == "formats" then + names.set_font_filter (optarg[n]) end end -- cgit v1.2.3 From 6b230e2f951822095d9ea5b9fc12c4307b8581ea Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 31 Jul 2013 22:59:17 +0200 Subject: [doc] document --format and add it to usage message --- luaotfload-tool.lua | 2 ++ luaotfload-tool.rst | 29 +++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 8cac103..b5c7976 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -211,6 +211,7 @@ This tool is part of the luaotfload package. Valid options are: -f --force force re-indexing all fonts -l --flush-lookups empty lookup cache of font requests -D --dry-run skip loading of fonts, just scan + --formats=[+|-]EXTENSIONS set, add, or subtract formats to index -p --prefer-texmf prefer fonts in the TEXMF over system fonts --find="font name" query the database for a font name @@ -267,6 +268,7 @@ The font database will be saved to short = [[ Usage: luaotfload-tool [--help] [--version] [--verbose=] [--update] [--force] [--prefer-texmf] + [--dry-run] [--formats=] [--find=] [--fuzzy] [--info] [--inspect] [--list=] [--fields=] [--cache=] [--flush-lookups] diff --git a/luaotfload-tool.rst b/luaotfload-tool.rst index 2e95381..bd781dc 100644 --- a/luaotfload-tool.rst +++ b/luaotfload-tool.rst @@ -6,18 +6,20 @@ generate and query the Luaotfload font names database ----------------------------------------------------------------------- -:Date: 2013-07-10 +:Date: 2013-07-31 :Copyright: GPL v2.0 -:Version: 2.3a +:Version: 2.4 :Manual section: 1 :Manual group: text processing SYNOPSIS ======================================================================= -**luaotfload-tool** [ -bDcfFiIpquvVwh ] +**luaotfload-tool** [ -bDfFiIlpquvVhw ] -**luaotfload-tool** --update [ --force ] [ --quiet ] [ --verbose ] [ --prefer-texmf ] [ --dry-run ] +**luaotfload-tool** --update [ --force ] [ --quiet ] [ --verbose ] + [ --prefer-texmf ] [ --dry-run ] + [ --formats=[+|-]EXTENSIONS ] **luaotfload-tool** --find=FONTNAME [ --fuzzy ] [ --info ] [ --inspect ] @@ -60,6 +62,25 @@ update mode --prefer-texmf, -p Organize the file name database in a way so that it prefer fonts in the *TEXMF* tree over system fonts if they are installed in both. +--formats=EXTENSIONS Extensions of the font files to index. + Where *EXTENSIONS* is a comma-separated list of + supported file extensions (otf, ttf, ttc, + dfont, and pfb). If the list is prefixed with + a ``+`` sign, the given list is added to the + currently active one; ``-`` subtracts. + Default: *otf,ttf,ttc,dfont*. + Examples: + + 1) ``--formats=-ttc,ttf`` would skip + TrueType fonts and font collections; + 2) ``--formats=otf`` would scan only OpenType + files; + 3) ``--formats=+pfb`` includes binary + Postscript files. **Warning**: with a + standard TeX Live installation this will + grow the database considerably and slow down + font indexing. + --dry-run, -D Don’t load fonts, scan directories only. (For debugging file system related issues.) -- cgit v1.2.3 From 9865446898d33c24c2ca13a3fe4558f11d937d01 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 1 Aug 2013 13:30:07 +0200 Subject: [db] treat .pfa like .pfb --- luaotfload-database.lua | 3 ++- luaotfload.dtx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index cfcd27c..584e9ad 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -1278,6 +1278,7 @@ local loaders = { return false end, pfb = t1_fullinfo, + pfa = t1_fullinfo, } --- we return true if the fond is new or re-indexed @@ -1550,7 +1551,7 @@ do set_font_filter = function (formats) - if not formats and type (formats) == "string" then + if not formats or type (formats) ~= "string" then return end diff --git a/luaotfload.dtx b/luaotfload.dtx index f23be81..4802844 100644 --- a/luaotfload.dtx +++ b/luaotfload.dtx @@ -1545,7 +1545,7 @@ config.luaotfload.prioritize = config.luaotfload.prioritize or "sys" config.luaotfload.names_dir = config.luaotfload.names_dir or "names" config.luaotfload.cache_dir = config.luaotfload.cache_dir or "fonts" config.luaotfload.index_file = config.luaotfload.index_file or "luaotfload-names.lua" -config.luaotfload.include_t1 = config.luaotfload.include_t1 or false +config.luaotfload.formats = config.luaotfload.formats or "otf,ttf,ttc,dfont" luaotfload.module = { name = "luaotfload", -- cgit v1.2.3 From da188203818d08606620eb59ab3337a815126bb6 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 1 Aug 2013 15:36:31 +0200 Subject: [db] improve font name/style matching with type1 fonts (/{b,i,bi} switches) --- luaotfload-database.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 584e9ad..5b22892 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -1219,21 +1219,27 @@ t1_fullinfo = function (filename, _subfont, texmf, basename) style = "italic" end + local style_synonyms_set = style_synonyms.set if weight then weight = sanitize_string (weight) + local tmp = "" + if style_synonyms_set.bold[weight] then + tmp = "bold" + end if style then - if style_synonyms.set.bold[weight] then - style = "bold" .. style - end + style = tmp .. style else - if style_synonyms.set.regular[weight] then + if style_synonyms_set.regular[weight] then style = "regular" + else + style = tmp end end end if not style then style = "regular" + --- else italic end namedata.sanitized = sanitize_names ({ -- cgit v1.2.3 From 709a43ce2fd471502f587d99f3ca7527a3e76672 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 1 Aug 2013 15:40:52 +0200 Subject: update NEWS and man page --- NEWS | 2 ++ luaotfload-tool.rst | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 2cd2ade..960a8d5 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ Change History 2013/XX/XX, luaotfload v2.4 * additional self-tests, now in separate file (luaotfload-diagnostics.lua) * better path and directory handling, especially on Windows + * database now indexes Type1 fonts (PFA, PFB) and makes them accessible + with style modifiers (requires --format=+pfa,pfb option to luaotfload-tool) * test runner (script mktests) 2013/07/10, luaotfload v2.3a diff --git a/luaotfload-tool.rst b/luaotfload-tool.rst index bd781dc..80884cd 100644 --- a/luaotfload-tool.rst +++ b/luaotfload-tool.rst @@ -65,9 +65,9 @@ update mode --formats=EXTENSIONS Extensions of the font files to index. Where *EXTENSIONS* is a comma-separated list of supported file extensions (otf, ttf, ttc, - dfont, and pfb). If the list is prefixed with - a ``+`` sign, the given list is added to the - currently active one; ``-`` subtracts. + dfont, pfa, and pfb). If the list is prefixed + with a ``+`` sign, the given list is added to + the currently active one; ``-`` subtracts. Default: *otf,ttf,ttc,dfont*. Examples: -- cgit v1.2.3 From 29ed9fa93ab3877b5fcf1e49e99269e3a67334ac Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 1 Aug 2013 15:48:01 +0200 Subject: [db] strip useless parameter from fontnames_init() --- luaotfload-database.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 5b22892..2267b6c 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -313,7 +313,7 @@ mtx-fonts has in names.tma: --doc]]-- -local fontnames_init = function (keep_cache) --- returns dbobj +local fontnames_init = function () --- returns dbobj return { mappings = { }, status = { }, @@ -404,7 +404,7 @@ load_names = function (dry_run) [[Font names database not found, generating new one.]]) report("both", 0, "db", [[This can take several minutes; please be patient.]]) - data = update_names(fontnames_init(false), nil, dry_run) + data = update_names(fontnames_init(), nil, dry_run) local success = save_names(data) if not success then report("both", 0, "db", "Database creation unsuccessful.") @@ -2178,7 +2178,7 @@ update_names = function (fontnames, force, dry_run) .. (force and " forcefully" or "")) if force then - fontnames = fontnames_init(false) + fontnames = fontnames_init() else if not fontnames then fontnames = load_names(dry_run) @@ -2186,10 +2186,10 @@ update_names = function (fontnames, force, dry_run) if fontnames.version ~= names.version then report("both", 1, "db", "No font names database or old " .. "one found; generating new one") - fontnames = fontnames_init(true) + fontnames = fontnames_init() end end - local newfontnames = fontnames_init(true) + local newfontnames = fontnames_init() read_blacklist() local scanned, new -- cgit v1.2.3 From e82948605b7bf6a0f8911c820fdafbb01bafdab4 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 1 Aug 2013 15:53:02 +0200 Subject: [db] store indexed formats alongwith version --- luaotfload-database.lua | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 2267b6c..e6def1c 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -78,6 +78,7 @@ local stringsplit = string.split local stringstrip = string.strip local tableappend = table.append local tablecopy = table.copy +local tablefastcopy = table.fastcopy local tabletofile = table.tofile local tabletohash = table.tohash @@ -237,6 +238,7 @@ end This is a sketch of the luaotfload db: type dbobj = { + formats : string list; // { "otf", "ttf", "ttc", "dfont" } mappings : fontentry list; status : filestatus; version : float; @@ -313,12 +315,13 @@ mtx-fonts has in names.tma: --doc]]-- -local fontnames_init = function () --- returns dbobj +local fontnames_init = function (formats) --- returns dbobj return { mappings = { }, status = { }, -- filenames = { }, -- created later version = names.version, + formats = formats, } end @@ -369,6 +372,7 @@ local resolve_fullpath local save_names local save_lookups local update_names +local get_font_filter local set_font_filter --- state of the database @@ -404,7 +408,8 @@ load_names = function (dry_run) [[Font names database not found, generating new one.]]) report("both", 0, "db", [[This can take several minutes; please be patient.]]) - data = update_names(fontnames_init(), nil, dry_run) + data = update_names (fontnames_init (get_font_filter ()), + nil, dry_run) local success = save_names(data) if not success then report("both", 0, "db", "Database creation unsuccessful.") @@ -1530,9 +1535,6 @@ read_blacklist = function () names.blacklist = create_blacklist(blacklist, whitelist) end ------ ordinary_extensions = { "otf", "ttf", "ttc", "dfont" } ------ type1_extensions = { "pfb", --[[afm]] } ------ font_extensions_set = tabletohash (font_extensions) local p_font_filter do @@ -1594,6 +1596,10 @@ do p_font_filter = extension_pattern (current_formats) end + get_font_filter = function (formats) + return tablefastcopy (current_formats) + end + --- initialize set_font_filter (config.luaotfload.formats) end @@ -2178,19 +2184,19 @@ update_names = function (fontnames, force, dry_run) .. (force and " forcefully" or "")) if force then - fontnames = fontnames_init() + fontnames = fontnames_init (get_font_filter ()) else if not fontnames then - fontnames = load_names(dry_run) + fontnames = load_names (dry_run) end if fontnames.version ~= names.version then - report("both", 1, "db", "No font names database or old " - .. "one found; generating new one") - fontnames = fontnames_init() + report ("both", 1, "db", "No font names database or old " + .. "one found; generating new one") + fontnames = fontnames_init (get_font_filter ()) end end - local newfontnames = fontnames_init() - read_blacklist() + local newfontnames = fontnames_init (get_font_filter ()) + read_blacklist () local scanned, new scanned, new = scan_texmf_fonts (fontnames, newfontnames, dry_run) -- cgit v1.2.3 From c3e5006283891b494871128613a13ab40f8efc9a Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 1 Aug 2013 15:53:43 +0200 Subject: [db] bump names db version --- luaotfload-database.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luaotfload-database.lua b/luaotfload-database.lua index e6def1c..ac2d0db 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -102,7 +102,7 @@ if config.luaotfload.update_live ~= false then config.luaotfload.update_live = true end -names.version = 2.207 +names.version = 2.208 names.data = nil --- contains the loaded database names.lookups = nil --- contains the lookup cache -- cgit v1.2.3 From 898fa8861c06b41acd946a1de35a13c64e26d22c Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 1 Aug 2013 16:27:45 +0200 Subject: [diagnose] add diagnostics for font index --- luaotfload-diagnostics.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++++ luaotfload-tool.lua | 3 ++- luaotfload-tool.rst | 4 +++- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/luaotfload-diagnostics.lua b/luaotfload-diagnostics.lua index 46ae412..efb7e5e 100644 --- a/luaotfload-diagnostics.lua +++ b/luaotfload-diagnostics.lua @@ -29,14 +29,17 @@ local osname = os.name local osremove = os.remove local ostype = os.type local stringformat = string.format +local stringlower = string.lower local stringsub = string.sub local fileisreadable = file.isreadable local fileiswritable = file.iswritable local filesplitpath = file.splitpath +local filesuffix = file.suffix local ioloaddata = io.loaddata local lua_of_json = utilities.json.tolua local tableconcat = table.concat +local tablesortedkeys = table.sortedkeys local tabletohash = table.tohash local lpeg = require "lpeg" @@ -47,6 +50,47 @@ local out = function (...) logs.names_report (false, 0, "diagnose", ...) end +local check_index = function (errcnt) + + out "================= font names ==================" + + if not names.data then + names.data = names.load () + end + + local namedata = names.data + local mappings = namedata.mappings + + if not namedata and namedata.formats and namedata.version then + out "Database corrupt." + return errcnt + 1 + end + + out ("Database version: %.3f.", names.version) + out ("Font formats indexed: %s.", + tableconcat (namedata.formats, ", ")) + out ("%d font files indexed.", #mappings) + + local by_format = { } + for i = 1, #mappings do + local record = mappings[i] + local format = stringlower (filesuffix (record.filename)) + local count = by_format[format] + if count then + by_format[format] = count + 1 + else + by_format[format] = 1 + end + end + + local formats = tablesortedkeys (by_format) + for i = 1, #formats do + local format = formats[i] + out ("%20s: %5d", format, by_format[format]) + end + return errcnt +end + local verify_files = function (errcnt, status) out "================ verify files =================" local hashes = status.hashes @@ -553,6 +597,7 @@ end local anamneses = { "environment", "files", + "index", "repository", "permissions" } @@ -569,6 +614,11 @@ local diagnose = function (job) asked = tabletohash (asked, true) end + if asked.index == true then + errcnt = check_index (errcnt) + asked.index = nil + end + if asked.environment == true then errcnt = check_environment (errcnt) asked.environment = nil diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index b5c7976..3bec847 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -199,7 +199,8 @@ This tool is part of the luaotfload package. Valid options are: -V --version print version and exit -h --help print this message --diagnose=CHECK run a self test procedure; one of "files", - "permissions", or "repository" + "environment", "index", "permissions", or + "repository" --alias= force behavior of "luaotfload-tool" or legacy "mkluatexfontdb" diff --git a/luaotfload-tool.rst b/luaotfload-tool.rst index 80884cd..2d3ae2f 100644 --- a/luaotfload-tool.rst +++ b/luaotfload-tool.rst @@ -159,7 +159,9 @@ miscellaneous 3) ``environment`` -> print relevant environment and kpse variables; 4) ``repository`` -> check the git repository - for new releases. + for new releases, + 5) ``index`` -> check database, display + information about it. Procedures can be chained by concatenating with commas, e.g. ``--diagnose=files,permissions``. -- cgit v1.2.3