From 73b4fc1146ada179e7783fd118aa7f1377a09e52 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 9 May 2016 08:04:13 +0200 Subject: [db] fix inclusion of AFM fonts The assumption that the AFM/PFB pair will reside in the same directory together is wrong for TeX Live. Hence the new lookup against kpse. --- src/luaotfload-database.lua | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 437091f..7434b72 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -207,8 +207,7 @@ local make_luanames = function (path) end local format_precedence = { - "otf", "ttc", "ttf", "afm", - -- "pfb" --- may come back before Luatex 1.0 + "otf", "ttc", "ttf", "afm", "pfb" } local location_precedence = { @@ -1664,7 +1663,8 @@ local loaders = { otf = ot_fullinfo, ttc = ot_fullinfo, ttf = ot_fullinfo, ---- pfb = t1_fullinfo, + afm = t1_fullinfo, + pfb = t1_fullinfo, } --- not side-effect free! @@ -2057,6 +2057,16 @@ do end end +local locate_matching_pfb = function (afmfile, dir) + local pfbname = filereplacesuffix (afmfile, "pfb") + local pfbpath = dir .. "/" .. pfbname + if lfsisfile (pfbpath) then + return pfbpath + end + --- Check for match in texmf too + return kpsefind_file (pfbname, "type1 fonts") +end + local process_dir_tree process_dir_tree = function (acc, dirs) if not next (dirs) then --- done @@ -2084,12 +2094,10 @@ process_dir_tree = function (acc, dirs) ent = stringlower (ent) if lpegmatch (p_font_filter, ent) then + newfiles[#newfiles+1] = fullpath if filesuffix (ent) == "afm" then - --- fontloader.open() will load the afm - --- iff both files are in the same directory - local pfbpath = filereplacesuffix - (fullpath, "pfb") - if lfsisfile (pfbpath) then + local pfbpath = locate_matching_pfb (ent, dir) + if pfbpath then newfiles[#newfiles+1] = pfbpath end else @@ -2121,12 +2129,8 @@ local process_dir = function (dir) if lpegmatch (p_font_filter, ent) then if filesuffix (ent) == "afm" then - --- fontloader.open() will load the afm - --- iff both files are in the same - --- directory - local pfbpath = filereplacesuffix - (fullpath, "pfb") - if lfsisfile (pfbpath) then + local pfbpath = locate_matching_pfb (ent, dir) + if pfbpath then files[#files+1] = pfbpath end else @@ -2261,6 +2265,7 @@ local collect_font_filenames_texmf = function () fontdirs = kpseexpand_path "$OPENTYPEFONTS" fontdirs = fontdirs .. path_separator .. kpseexpand_path "$TTFONTS" fontdirs = fontdirs .. path_separator .. kpseexpand_path "$T1FONTS" + fontdirs = fontdirs .. path_separator .. kpseexpand_path "$AFMFONTS" if stringis_empty (fontdirs) then return { } -- cgit v1.2.3 From 67ad1263d0328fc74928a9a1d06ea9aa0ee9a116 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 26 May 2016 13:40:58 +0200 Subject: [db] ditch fontforge compatibility code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove all the FF stuff and the config option. The transition is complete, no need to keep these things around any longer. Since we won’t be going back to the FF loader we might as well dispose of the junk identifiers and the translation layer as well. --- src/luaotfload-database.lua | 295 +++++++++++++++++--------------------------- 1 file changed, 116 insertions(+), 179 deletions(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 7434b72..96329f8 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -132,11 +132,6 @@ local fontshandlers = fonts.handlers or { } local otfhandler = fonts.handlers.otf or { } fonts.handlers = fontshandlers -local read_font_file = otfhandler.readers.loadfont -local read_font_info = read_font_file -local close_font_file = function () end -local get_english_names - local gzipload = gzip.load local gzipsave = gzip.save local iolines = io.lines @@ -354,25 +349,25 @@ This is a sketch of the luaotfload db: full : (int, string) hash; // idx -> full path } and fontentry = { // finalized by collect_families() - basename : string; // file name without path "foo.otf" - conflicts : { barename : int; basename : int }; // filename conflict with font at index; happens with subfonts - familyname : string; // sanitized name of the font family the font belongs to, usually from the names table - fontname : string; // sanitized name of the font - format : string; // "otf" | "ttf" | "afm" (* | "pfb" *) - fullname : string; // sanitized full name of the font including style modifiers - fullpath : string; // path to font in filesystem - index : int; // index in the mappings table - italicangle : float; // italic angle; non-zero with oblique faces - location : string; // "texmf" | "system" | "local" - metafamily : string; // alternative family identifier if appropriate, sanitized - plainname : string; // unsanitized font name - prefmodifiers : string; // sanitized preferred subfamily (names table 14) - psname : string; // PostScript name - size : (false | float * float * float); // if available, size info from the size table converted from decipoints - subfamily : string; // sanitized subfamily (names table 2) - subfont : (int | bool); // integer if font is part of a TrueType collection ("ttc") - version : string; // font version string - weight : int; // usWeightClass + basename : string; // file name without path "foo.otf" + conflicts : { barename : int; basename : int }; // filename conflict with font at index; happens with subfonts + familyname : string; // sanitized name of the font family the font belongs to, usually from the names table + fontname : string; // sanitized name of the font + format : string; // "otf" | "ttf" | "afm" (* | "pfb" *) + fullname : string; // sanitized full name of the font including style modifiers + fullpath : string; // path to font in filesystem + index : int; // index in the mappings table + italicangle : float; // italic angle; non-zero with oblique faces + location : string; // "texmf" | "system" | "local" + metafamily : string; // alternative family identifier if appropriate, sanitized + plainname : string; // unsanitized font name + typographicsubfamily : string; // sanitized preferred subfamily (names table 14) + psname : string; // PostScript name + size : (false | float * float * float); // if available, size info from the size table converted from decipoints + subfamily : string; // sanitized subfamily (names table 2) + subfont : (int | bool); // integer if font is part of a TrueType collection ("ttc") + version : string; // font version string + weight : int; // usWeightClass } and filestatus = (string, // fullname { index : int list; // pointer into mappings @@ -1015,7 +1010,7 @@ local lookup_fontname = function (specification, name, style) style = style_category [style] for i = 1, #mappings do local face = mappings [i] - local prefmodifiers = face.prefmodifiers + local typographicsubfamily = face.typographicsubfamily local subfamily = face.subfamily if face.fontname == name or face.fullname == name @@ -1023,17 +1018,17 @@ local lookup_fontname = function (specification, name, style) then return face.basename, face.subfont elseif face.familyname == name then - if prefmodifiers == style + if typographicsubfamily == style or subfamily == style then fallback = face - elseif regular_synonym [prefmodifiers] + elseif regular_synonym [typographicsubfamily] or regular_synonym [subfamily] then lastresort = face end elseif face.metafamily == name - and ( regular_synonym [prefmodifiers] + and ( regular_synonym [typographicsubfamily] or regular_synonym [subfamily]) then lastresort = face @@ -1081,12 +1076,12 @@ end size should that be? Xetex appears to pick the “normal” (unmarked) size: with Adobe fonts this would be the one that is neither “caption” nor “subhead” nor “display” &c ... For fonts by Adobe this - seems to be the one that does not receive a “prefmodifiers” field. - (IOW Adobe uses the “prefmodifiers” field to encode the design size - in more or less human readable format.) However, this is not true - of LM and EB Garamond. As this matters only where there are - multiple design sizes to a given font/style combination, we put a - workaround in place that chooses that unmarked version. + seems to be the one that does not receive a “typographicsubfamily” + field. (IOW Adobe uses the “typographicsubfamily” field to encode + the design size in more or less human readable format.) However, + this is not true of LM and EB Garamond. As this matters only where + there are multiple design sizes to a given font/style combination, + we put a workaround in place that chooses that unmarked version. The first return value of “lookup_font_name” is the file name of the requested font (string). It can be passed to the fullname resolver @@ -1303,8 +1298,18 @@ find_closest = function (name, limit) return false end --- find_closest() +local read_font_file = function (filename, subfont) + return otfhandler.readers.getinfo (filename, + { subfont = subfont + , details = false + , platformnames = true + , rawfamilynames = true + }) +end + local load_font_file = function (filename, subfont) - local rawfont, _msg = read_font_file (filename, subfont, true) + local rawfont, _msg = read_font_file (filename, subfont) + if not rawfont then logreport ("log", 1, "db", "ERROR: failed to open %s.", filename) return @@ -1335,29 +1340,6 @@ local get_size_info = function (rawinfo) return false end ---[[doc-- - get_english_names_from_ff -- For legacy Fontforge-style names - tables. Extracted from the actual names table, not the font item - itself. ---doc]]-- - -local get_english_names_from_ff = function (metadata) - local names = metadata.names - if names then - for _, raw_namedata in next, names do - if raw_namedata.lang == "English (US)" then - return raw_namedata.names - end - end - end - - -- no (English) names table, probably a broken font - logreport ("both", 3, "db", - "%s: missing or broken English names table.", basename) - return { fontname = metadata.fontname, - fullname = metadata.fullname, } -end - --[[doc-- map_enlish_names -- Names-table for Lua fontloader objects. This may vanish eventually once we ditch Fontforge completely. Only @@ -1365,17 +1347,7 @@ end stick to that part. --doc]]-- -local names_items = { - compatfull = "compatiblefullname", - fullname = "fullname", - postscriptname = "postscriptname", - preffamily = "typographicfamily", - prefmodifiers = "typographicsubfamily", - family = "family", - subfamily = "subfamily", -} - -local map_english_names = function (metadata) +local get_english_names = function (metadata) local namesource local platformnames = metadata.platformnames --[[-- @@ -1411,16 +1383,9 @@ local map_english_names = function (metadata) --namesource = platformnames.macintosh or platformnames.windows namesource = platformnames.windows or platformnames.macintosh end - namesource = namesource or metadata - local nameinfo = { } - for ours, theirs in next, names_items do - nameinfo [ours] = namesource [theirs] - end - return nameinfo + return namesource or metadata end -get_english_names = map_english_names - --[[-- In case of broken PS names we set some dummies. @@ -1461,46 +1426,46 @@ local organize_namedata = function (rawinfo, nametable, basename, info) - local default_name = nametable.compatfull + local default_name = nametable.compatiblefullname or nametable.fullname or nametable.postscriptname or rawinfo.fullname or rawinfo.fontname or info.fullname or info.fontname - local default_family = nametable.preffamily + local default_family = nametable.typographicfamily or nametable.family or rawinfo.familyname or info.familyname --- local default_modifier = nametable.prefmodifiers +-- local default_modifier = nametable.typographicsubfamily -- or nametable.subfamily local fontnames = { --- see --- https://developer.apple.com/fonts/TTRefMan/RM06/Chap6name.html --- http://www.microsoft.com/typography/OTSPEC/name.htm#NameIDs english = { - --- where a “compatfull” field is given, the value of “fullname” is - --- either identical or differs by separating the style - --- with a hyphen and omitting spaces. (According to the - --- spec, “compatfull” is “Macintosh only”.) - --- Of the three “fullname” fields, this one appears to be the one - --- with the entire name given in a legible, - --- non-abbreviated fashion, for most fonts at any rate. - --- However, in some fonts (e.g. CMU) all three fields are - --- identical. - fullname = --[[ 18 ]] nametable.compatfull + --- where a “compatiblefullname” field is given, the value + --- of “fullname” is either identical or differs by + --- separating the style with a hyphen and omitting spaces. + --- (According to the spec, “compatiblefullname” is + --- “Macintosh only”.) Of the three “fullname” fields, this + --- one appears to be the one with the entire name given in + --- a legible, non-abbreviated fashion, for most fonts at + --- any rate. However, in some fonts (e.g. CMU) all three + --- fields are identical. + fullname = --[[ 18 ]] nametable.compatiblefullname or --[[ 4 ]] nametable.fullname or default_name, --- we keep both the “preferred family” and the “family” --- values around since both are valid but can turn out --- quite differently, e.g. with Latin Modern: - --- preffamily: “Latin Modern Sans”, + --- typographicfamily: “Latin Modern Sans”, --- family: “LM Sans 10” - preffamily = --[[ 16 ]] nametable.preffamilyname, - family = --[[ 1 ]] nametable.family or default_family, - prefmodifiers = --[[ 17 ]] nametable.prefmodifiers, - subfamily = --[[ 2 ]] nametable.subfamily or rawinfo.subfamilyname, - psname = --[[ 6 ]] nametable.postscriptname, + family = --[[ 1 ]] nametable.family or default_family, + subfamily = --[[ 2 ]] nametable.subfamily or rawinfo.subfamilyname, + psname = --[[ 6 ]] nametable.postscriptname, + typographicfamily = --[[ 16 ]] nametable.typographicfamily, + typographicsubfamily = --[[ 17 ]] nametable.typographicsubfamily, }, metadata = { @@ -1595,7 +1560,6 @@ ot_fullinfo = function (filename, style = style, version = rawinfo.version, } - close_font_file (metadata) --> FF only return res end @@ -1622,12 +1586,12 @@ t1_fullinfo = function (filename, _subfont, location, basename, format) local weight sanitized = sanitize_fontnames ({ - fontname = fontname, - psname = fullname, - metafamily = familyname, - familyname = familyname, - weight = metadata.weight, --- string identifier - prefmodifiers = style, + fontname = fontname, + psname = fullname, + metafamily = familyname, + familyname = familyname, + weight = metadata.weight, --- string identifier + typographicsubfamily = style, }) weight = sanitized.weight @@ -1641,21 +1605,21 @@ t1_fullinfo = function (filename, _subfont, location, basename, format) end return { - basename = basename, - fullpath = filename, - subfont = false, - location = location or "system", - format = format, - fullname = sanitized.fullname, - fontname = sanitized.fontname, - familyname = sanitized.familyname, - plainname = fullname, - psname = sanitized.fontname, - version = metadata.version, - size = false, - prefmodifiers = style ~= "" and style or weight, - weight = metadata.pfminfo and pfminfo.weight or 400, - italicangle = italicangle, + basename = basename, + fullpath = filename, + subfont = false, + location = location or "system", + format = format, + fullname = sanitized.fullname, + fontname = sanitized.fontname, + familyname = sanitized.familyname, + plainname = fullname, + psname = sanitized.fontname, + version = metadata.version, + size = false, + typographicsubfamily = style ~= "" and style or weight, + weight = metadata.pfminfo and pfminfo.weight or 400, + italicangle = italicangle, } end @@ -2601,11 +2565,10 @@ do return false end - pick_style = function (prefmodifiers, - subfamily) + pick_style = function (typographicsubfamily, subfamily) local style - if prefmodifiers then - style = choose_exact (prefmodifiers) + if typographicsubfamily then + style = choose_exact (typographicsubfamily) elseif subfamily then style = choose_exact (subfamily) end @@ -2635,7 +2598,7 @@ do --- we use only exact matches here since there are constructs --- like “regularitalic” (Cabin, Bodoni Old Fashion) - check_regular = function (prefmodifiers, + check_regular = function (typographicsubfamily, subfamily, italicangle, weight, @@ -2643,7 +2606,7 @@ do local plausible_weight = false --[[-- This filters out undesirable candidates that specify their - prefmodifiers or subfamily as “regular” but are actually of + typographicsubfamily or subfamily as “regular” but are actually of “semibold” or other weight—another drawback of the oversimplifying classification into only three styles (r, i, b, bi). @@ -2655,8 +2618,8 @@ do end if plausible_weight then - if prefmodifiers and regular_synonym [prefmodifiers] - or subfamily and regular_synonym [subfamily] + if typographicsubfamily and regular_synonym [typographicsubfamily] + or subfamily and regular_synonym [subfamily] then return "r" end @@ -2681,13 +2644,13 @@ local pull_values = function (entry) entry.subfont = file.subfont --- pull name info ... - entry.psname = english.psname - entry.fontname = info.fontname or metadata.fontname - entry.fullname = english.fullname or info.fullname - entry.prefmodifiers = english.prefmodifiers - entry.familyname = metadata.familyname or english.preffamily or english.family - entry.plainname = names.fullname - entry.subfamily = english.subfamily + entry.psname = english.psname + entry.fontname = info.fontname or metadata.fontname + entry.fullname = english.fullname or info.fullname + entry.typographicsubfamily = english.typographicsubfamily + entry.familyname = metadata.familyname or english.typographicfamily or english.family + entry.plainname = names.fullname + entry.subfamily = english.subfamily --- pull style info ... entry.italicangle = style.italicangle @@ -2747,20 +2710,17 @@ local collect_families = function (mappings) pull_values (entry) end - local subtable = get_subtable (families, entry) - - local familyname = entry.familyname - local prefmodifiers = entry.prefmodifiers - local subfamily = entry.subfamily - - local weight = entry.weight - local pfmweight = entry.pfmweight - local italicangle = entry.italicangle - - local modifier = pick_style (prefmodifiers, subfamily) + local subtable = get_subtable (families, entry) + local familyname = entry.familyname + local typographicsubfamily = entry.typographicsubfamily + local subfamily = entry.subfamily + local weight = entry.weight + local pfmweight = entry.pfmweight + local italicangle = entry.italicangle + local modifier = pick_style (typographicsubfamily, subfamily) if not modifier then --- regular, exact only - modifier = check_regular (prefmodifiers, + modifier = check_regular (typographicsubfamily, subfamily, italicangle, weight, @@ -2999,7 +2959,7 @@ local collect_statistics = function (mappings) local sum_dsnsize, n_dsnsize = 0, 0 local fullname, family, families = { }, { }, { } - local subfamily, prefmodifiers = { }, { } + local subfamily, typographicsubfamily = { }, { } local addtohash = function (hash, item) if item then @@ -3055,10 +3015,10 @@ local collect_statistics = function (mappings) local names = entry.names.sanitized local englishnames = names.english - addtohash (fullname, englishnames.fullname) - addtohash (family, englishnames.family) - addtohash (subfamily, englishnames.subfamily) - addtohash (prefmodifiers, englishnames.prefmodifiers) + addtohash (fullname, englishnames.fullname) + addtohash (family, englishnames.family) + addtohash (subfamily, englishnames.subfamily) + addtohash (typographicsubfamily, englishnames.typographicsubfamily) addtoset (families, englishnames.family, englishnames.fullname) @@ -3129,9 +3089,9 @@ local collect_statistics = function (mappings) pprint_top (subfamily, 4) logreport ("both", 0, "db", - " · %d different “prefmodifiers” kinds.", - setsize (prefmodifiers)) - pprint_top (prefmodifiers, 4) + " · %d different “typographicsubfamily” kinds.", + setsize (typographicsubfamily)) + pprint_top (typographicsubfamily, 4) end @@ -3148,7 +3108,7 @@ local collect_statistics = function (mappings) }, -- style = { -- subfamily = subfamily, --- prefmodifiers = prefmodifiers, +-- typographicsubfamily = typographicsubfamily, -- }, } end @@ -3505,29 +3465,6 @@ local show_cache = function ( ) return true end -local use_fontforge = function (val) - if val == true then - local fontloader = fontloader - read_font_info = fontloader.info - read_font_file = fontloader.open - close_font_file = fontloader.close - get_english_names = get_english_names_from_ff - else - local wrapper = function (filename, subfont) - return otfhandler.readers.getinfo (filename, - { subfont = subfont - , details = false - , platformnames = true - , rawfamilynames = true - }) - end - read_font_file = wrapper - read_font_info = wrapper - close_font_file = function () end - get_english_names = map_english_names - end -end - ----------------------------------------------------------------------- --- export functionality to the namespace “fonts.names” ----------------------------------------------------------------------- @@ -3559,7 +3496,7 @@ local export = { show_cache = show_cache, find_closest = find_closest, --- transitionary - use_fontforge = use_fontforge, + use_fontforge = false, } return { @@ -3575,7 +3512,7 @@ return { fonts.definers = fonts.definers or { resolvers = { } } names.blacklist = blacklist - names.version = 2.7 + names.version = 2.8 names.data = nil --- contains the loaded database names.lookups = nil --- contains the lookup cache -- cgit v1.2.3 From 9bc8a2425b2608b8a93e91042191421ad81dc956 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 31 May 2016 08:20:22 +0200 Subject: [db] fix name assignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Address issue #356 The DejaVu Family needs stricter handling of fallback choices so we take the font’s avertised width into consideration. This used to be easier with the old loader since it had some decent heuristics in place for the more or less reliable “fontstyle_name”. --- src/luaotfload-database.lua | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 96329f8..00d14de 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -2537,6 +2537,7 @@ end local bold_spectrum_low = 501 --- 500 is medium, 900 heavy/black local bold_weight = 700 +local normal_width = 5 local pick_style local pick_fallback_style @@ -2569,13 +2570,15 @@ do local style if typographicsubfamily then style = choose_exact (typographicsubfamily) + if style then return style end elseif subfamily then style = choose_exact (subfamily) + if style then return style end end - return style + return false end - pick_fallback_style = function (italicangle, weight, pfmweight) + pick_fallback_style = function (italicangle, pfmweight, width) --[[-- More aggressive, but only to determine bold faces. Note: Before you make this test more inclusive, ensure @@ -2586,7 +2589,8 @@ do treating weights > 500 as bold or allowing synonyms like “heavy”, “black”. --]]-- - if pfmweight == bold_weight then --- bold spectrum matches + if width == normal_width and pfmweight == bold_weight then + --- bold spectrum matches if italicangle == 0 then return "b" end @@ -2602,6 +2606,7 @@ do subfamily, italicangle, weight, + width, pfmweight) local plausible_weight = false --[[-- @@ -2611,17 +2616,32 @@ do oversimplifying classification into only three styles (r, i, b, bi). --]]-- - if italicangle == 0 then - if pfmweight == 400 then plausible_weight = true - elseif weight and regular_synonym [weight] then plausible_weight = true end + if pfmweight == 400 then + --[[-- + Some fonts like Dejavu advertise an undistinguished + regular and a “condensed” version with the same + weight whilst also providing the style info in the + typographic subfamily instead of the subfamily (i. e. + the converse of what Adobe’s doing). The only way to + weed out the undesired pseudo-regular shape is to + peek at its advertised width (4 vs. 5). + --]]-- + if width then + plausible_weight = width == normal_width + else + plausible_weight = true + end + elseif weight and regular_synonym [weight] then + plausible_weight = true + end end if plausible_weight then - if typographicsubfamily and regular_synonym [typographicsubfamily] - or subfamily and regular_synonym [subfamily] - then - return "r" + if subfamily then + if regular_synonym [subfamily] then return "r" end + elseif typographicsubfamily then + if regular_synonym [typographicsubfamily] then return "r" end end end return false @@ -2656,6 +2676,7 @@ local pull_values = function (entry) entry.italicangle = style.italicangle entry.size = style.size entry.weight = style.weight + entry.width = style.width entry.pfmweight = style.pfmweight if config.luaotfload.db.strip == true then @@ -2715,6 +2736,7 @@ local collect_families = function (mappings) local typographicsubfamily = entry.typographicsubfamily local subfamily = entry.subfamily local weight = entry.weight + local width = entry.width local pfmweight = entry.pfmweight local italicangle = entry.italicangle local modifier = pick_style (typographicsubfamily, subfamily) @@ -2724,11 +2746,12 @@ local collect_families = function (mappings) subfamily, italicangle, weight, + width, pfmweight) end if not modifier then - modifier = pick_fallback_style (italicangle, weight, pfmweight) + modifier = pick_fallback_style (italicangle, pfmweight, width) end if modifier then -- cgit v1.2.3 From 68f523b6660baaabd4fee994d5be79a3a9afda37 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 7 Jun 2016 07:58:55 +0200 Subject: [db] include values of missing fields in diagnostic --- src/luaotfload-database.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 00d14de..da2d5d0 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -1402,8 +1402,9 @@ local get_raw_info = function (metadata, basename) --- we put some dummies in place like the fontloader --- (font-otf.lua) does. logreport ("both", 3, "db", - "invalid names table of font %s, using dummies.", - basename) + "Invalid names table of font %s, using dummies. \z + Reported: fontname=%q, fullname=%q.", + basename, fontname, fullname) fontname = "bad-fontname-" .. basename fullname = "bad-fullname-" .. basename end -- cgit v1.2.3 From 37f8c42a1b560df3f1bc1444405c772f00340f88 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 8 Jun 2016 08:23:38 +0200 Subject: [db] resolve symlinks when traversing the file system Addresses #359 and #325 To avoid duplicate entries, paths have to be resolved before collecting them. This necessitates loop detection of some sort, currently implemented naively as a flat table containing the directories already traversed. --- src/luaotfload-database.lua | 72 ++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 31 deletions(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index da2d5d0..5645b63 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -2033,7 +2033,7 @@ local locate_matching_pfb = function (afmfile, dir) end local process_dir_tree -process_dir_tree = function (acc, dirs) +process_dir_tree = function (acc, dirs, done) if not next (dirs) then --- done return acc end @@ -2042,46 +2042,56 @@ process_dir_tree = function (acc, dirs) local dir = dirs[#dirs] dirs[#dirs] = nil - if lfschdir (dir) then - lfschdir (pwd) - - local newfiles = { } - local blacklist = names.blacklist - for ent in lfsdir (dir) do - --- filter right away - if ent ~= "." and ent ~= ".." and not blacklist[ent] then - local fullpath = dir .. "/" .. ent - if lfsisdir (fullpath) - and not lpegmatch (p_blacklist, fullpath) - then - dirs[#dirs+1] = fullpath - elseif lfsisfile (fullpath) then - ent = stringlower (ent) - - if lpegmatch (p_font_filter, ent) then - newfiles[#newfiles+1] = fullpath - if filesuffix (ent) == "afm" then - local pfbpath = locate_matching_pfb (ent, dir) - if pfbpath then - newfiles[#newfiles+1] = pfbpath - end - else - newfiles[#newfiles+1] = fullpath + if not lfschdir (dir) then + --- Cannot cd; skip. + return process_dir_tree (acc, dirs, done) + end + + dir = lfscurrentdir () --- resolve symlinks + lfschdir (pwd) + if tablecontains (done, dir) then + --- Already traversed. Note that it’d be unsafe to rely on the + --- hash part above due to Lua only processing up to 32 bytes + --- of string data. The lookup shouldn’t impact performance too + --- much but we could check the performance of alternative data + --- structures at some point. + return process_dir_tree (acc, dirs, done) + end + + local newfiles = { } + local blacklist = names.blacklist + for ent in lfsdir (dir) do + --- filter right away + if ent ~= "." and ent ~= ".." and not blacklist[ent] then + local fullpath = dir .. "/" .. ent + if lfsisdir (fullpath) + and not lpegmatch (p_blacklist, fullpath) + then + dirs[#dirs+1] = fullpath + elseif lfsisfile (fullpath) then + ent = stringlower (ent) + if lpegmatch (p_font_filter, ent) then + newfiles[#newfiles+1] = fullpath + if filesuffix (ent) == "afm" then + local pfbpath = locate_matching_pfb (ent, dir) + if pfbpath then + newfiles[#newfiles+1] = pfbpath end + else + newfiles[#newfiles+1] = fullpath end - end end end - return process_dir_tree (tableappend (acc, newfiles), dirs) end - --- cannot cd; skip - return process_dir_tree (acc, dirs) + done [#done + 1] = dir + return process_dir_tree (tableappend (acc, newfiles), dirs, done) end local process_dir = function (dir) local pwd = lfscurrentdir () if lfschdir (dir) then + dir = lfscurrentdir () --- resolve symlinks lfschdir (pwd) local files = { } @@ -2114,7 +2124,7 @@ end local find_font_files = function (root, recurse) if lfsisdir (root) then if recurse == true then - return process_dir_tree ({}, { root }) + return process_dir_tree ({}, { root }, {}) else --- kpathsea already delivered the necessary subdirs return process_dir (root) end -- cgit v1.2.3 From 04f559ba1bc2caa232eded21d500d070142bfa1f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 12 Jun 2016 18:33:15 +0200 Subject: [db] fix crash with missing name data --- src/luaotfload-database.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 5645b63..b017340 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -1396,7 +1396,6 @@ local get_raw_info = function (metadata, basename) local fontname = metadata.fontname local fullname = metadata.fullname - local validation_state = metadata.validation_state if not fontname or not fullname then --- Broken names table, e.g. avkv.ttf with UTF-16 strings; --- we put some dummies in place like the fontloader @@ -1404,7 +1403,8 @@ local get_raw_info = function (metadata, basename) logreport ("both", 3, "db", "Invalid names table of font %s, using dummies. \z Reported: fontname=%q, fullname=%q.", - basename, fontname, fullname) + tostring (basename), tostring (fontname), + tostring (fullname)) fontname = "bad-fontname-" .. basename fullname = "bad-fullname-" .. basename end -- cgit v1.2.3 From e32722cb62bfe37116d3d97659040463bc381719 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 12 Jun 2016 18:43:11 +0200 Subject: [db] adapt error handling to new fontloader conventions --- src/luaotfload-database.lua | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index b017340..7495ff2 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -1298,23 +1298,29 @@ find_closest = function (name, limit) return false end --- find_closest() +--- string -> uint -> bool * (string | rawdata) local read_font_file = function (filename, subfont) - return otfhandler.readers.getinfo (filename, - { subfont = subfont - , details = false - , platformnames = true - , rawfamilynames = true - }) + local fontdata = otfhandler.readers.getinfo (filename, + { subfont = subfont + , details = false + , platformnames = true + , rawfamilynames = true + }) + local msg = fontdata.comment + if msg then + return false, msg + end + return true, fontdata end local load_font_file = function (filename, subfont) - local rawfont, _msg = read_font_file (filename, subfont) - - if not rawfont then - logreport ("log", 1, "db", "ERROR: failed to open %s.", filename) + local err, ret = read_font_file (filename, subfont) + if err == false then + logreport ("both", 1, "db", "ERROR: failed to open %q: %q.", + tostring (filename), tostring (ret)) return end - return rawfont + return ret end --- rawdata -> (int * int * int | bool) @@ -1773,11 +1779,12 @@ local read_font_names = function (fullname, --- 4) get basic info, abort if fontloader can’t read it - local info = read_font_file (fullname) + local err, info = read_font_file (fullname) - if not info then + if err == false then logreport ("log", 1, "db", - "Failed to read basic information from %q", basename) + "Failed to read basic information from %q: %q", + basename, tostring (info)) return false end -- cgit v1.2.3