From 9f3000ade19fda594cef0f5ee37cdb88eb638e87 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 21 Apr 2016 23:24:27 +0200 Subject: Revert "[db,conf] drop support for PS fonts" This reverts commit c4c250414a83cc8c4ae99d286ed69a3763510609. Partially, anyways: All mentions of the PFA format were stripped. Since the new loader adds back in support for PFB-flavored PS fonts without AFM we should support it from Luaotfload as well. --- src/luaotfload-database.lua | 70 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 6 deletions(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 135ab0e..f18875c 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", "pfa", + "otf", "ttc", "ttf", "afm", "pfb" } local location_precedence = { @@ -359,7 +358,7 @@ This is a sketch of the luaotfload db: 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" + 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 @@ -495,6 +494,7 @@ local lookup_fullpath local save_lookups local save_names local set_font_filter +local t1_fullinfo local update_names --- state of the database @@ -1617,13 +1617,71 @@ ot_fullinfo = function (filename, return res end +--[[doc-- + + Type1 font inspector. In comparison with OTF, PFB’s contain a good + deal less name fields which makes it tricky in some parts to find a + meaningful representation for the database. + + Good read: http://www.adobe.com/devnet/font/pdfs/5004.AFM_Spec.pdf + +--doc]]-- + +--- string -> int -> bool -> string -> fontentry + +t1_fullinfo = function (filename, _subfont, location, basename, format) + local sanitized + local metadata = load_font_file (filename) + local fontname = metadata.fontname + local fullname = metadata.fullname + local familyname = metadata.familyname + local italicangle = metadata.italicangle + local style = "" + local weight + + sanitized = sanitize_fontnames ({ + fontname = fontname, + psname = fullname, + metafamily = familyname, + familyname = familyname, + weight = metadata.weight, --- string identifier + prefmodifiers = style, + }) + + weight = sanitized.weight + + if weight == "bold" then + style = weight + end + + if italicangle ~= 0 then + style = style .. "italic" + 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, + fontstyle_name = style ~= "" and style or weight, + weight = metadata.pfminfo and pfminfo.weight or 400, + italicangle = italicangle, + } +end + local loaders = { otf = ot_fullinfo, ttc = ot_fullinfo, ttf = ot_fullinfo, - -----pfb = t1_fullinfo, --> may come back one day, so -----pfa = t1_fullinfo, --> we keep the indirection + pfb = t1_fullinfo, } --- not side-effect free! -- cgit v1.2.3 From 9e1efb4c32dc1ef8319e9fd7bb708aa7eaec43ec Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 24 Apr 2016 20:40:43 +0200 Subject: [db,loaders] clarify support for PFB The current PFB loader, although it is indeed completely independent of the FF libraries, is not yet feature complete. Only the loading of vectors is supported which suffices for font rendering given the AFM information. According to Hans, we have decent chance of it growing into a full-fledged reader for 1.0. --- src/luaotfload-database.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index f18875c..d59b7c8 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -207,7 +207,8 @@ local make_luanames = function (path) end local format_precedence = { - "otf", "ttc", "ttf", "afm", "pfb" + "otf", "ttc", "ttf", "afm", + -- "pfb" --- may come back before Luatex 1.0 } local location_precedence = { @@ -358,7 +359,7 @@ This is a sketch of the luaotfload db: 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" + 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 @@ -1681,7 +1682,7 @@ local loaders = { otf = ot_fullinfo, ttc = ot_fullinfo, ttf = ot_fullinfo, - pfb = t1_fullinfo, +--- pfb = t1_fullinfo, } --- not side-effect free! -- cgit v1.2.3 From cc59be4bd1d31b2bb7207dc60072d2090d045fef Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 24 Apr 2016 20:43:59 +0200 Subject: [db] fix version field Fix #337 This amends the apparent failure of luaotfload-tool as reported by @eg9 and others. --- src/luaotfload-database.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index d59b7c8..44786a5 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -3596,7 +3596,7 @@ return { fonts.definers = fonts.definers or { resolvers = { } } names.blacklist = blacklist - names.version = 2.6 + names.version = 2.7 names.data = nil --- contains the loaded database names.lookups = nil --- contains the lookup cache -- cgit v1.2.3 From e789cc0309f9d850e72dc724c0e686a9c03b7979 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 27 Apr 2016 07:42:49 +0200 Subject: [db] fix family / style matching Fix #342 Due to the reassigned fontname fields, certain values designating styles ended up being interpreted wrongly and members of the font families ended up in the wrong table. Thanks to @dohyunkim for spotting the issue. --- src/luaotfload-database.lua | 89 ++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 65 deletions(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 44786a5..b8a50d6 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -596,11 +596,11 @@ load_lookups = function ( ) end local regular_synonym = { - book = "r", - normal = "r", - plain = "r", - regular = "r", - roman = "r", + book = true, + normal = true, + plain = true, + regular = true, + roman = true, } local italic_synonym = { @@ -1035,7 +1035,7 @@ local lookup_fontname = function (specification, name, style) lastresort = face end elseif face.metafamily == name - and (regular_synonym [prefmodifiers] + and ( regular_synonym [prefmodifiers] or regular_synonym [subfamily]) then lastresort = face @@ -1449,7 +1449,6 @@ local get_raw_info = function (metadata, basename) return { familyname = metadata.familyname, fontname = fontname, - fontstyle_name = metadata.fontstyle_name, fullname = fullname, italicangle = metadata.italicangle, names = metadata.names, @@ -1520,21 +1519,6 @@ local organize_namedata = function (rawinfo, }, } - -- see http://www.microsoft.com/typography/OTSPEC/features_pt.htm#size - if rawinfo.fontstyle_name then - --- not present in all fonts, often differs from the preferred - --- subfamily as well as subfamily fields, e.g. with - --- LMSans10-BoldOblique: - --- subfamily: “Bold Italic” - --- prefmodifiers: “10 Bold Oblique” - --- fontstyle_name: “Bold Oblique” - for _, name in next, rawinfo.fontstyle_name do - if name.lang == 1033 then --- I hate magic numbers - fontnames.fontstyle_name = name.name - end - end - end - return { sanitized = sanitize_fontnames (fontnames), fontname = rawinfo.fontname, @@ -1672,7 +1656,7 @@ t1_fullinfo = function (filename, _subfont, location, basename, format) psname = sanitized.fontname, version = metadata.version, size = false, - fontstyle_name = style ~= "" and style or weight, + prefmodifiers = style ~= "" and style or weight, weight = metadata.pfminfo and pfminfo.weight or 400, italicangle = italicangle, } @@ -2611,19 +2595,13 @@ do return false end - pick_style = function (fontstyle_name, - prefmodifiers, + pick_style = function (prefmodifiers, subfamily) local style - if fontstyle_name --[[ff only]] then - style = choose_exact (fontstyle_name) - end - if not style then - if prefmodifiers then - style = choose_exact (prefmodifiers) - elseif subfamily then - style = choose_exact (subfamily) - end + if prefmodifiers then + style = choose_exact (prefmodifiers) + elseif subfamily then + style = choose_exact (subfamily) end return style end @@ -2632,10 +2610,9 @@ do --- more aggressive, but only to determine bold faces if pfmweight > 500 or bold_synonym [weight] then --- bold spectrum matches if italicangle == 0 then - return tostring (weight) - else - return tostring (weight) .. "i" + return "b" end + return "bi" end return false end @@ -2643,13 +2620,12 @@ do --- we use only exact matches here since there are constructs --- like “regularitalic” (Cabin, Bodoni Old Fashion) - check_regular = function (fontstyle_name, - prefmodifiers, + check_regular = function (prefmodifiers, subfamily, italicangle, weight, pfmweight) - local plausible_weight + local plausible_weight = false --[[-- This filters out undesirable candidates that specify their prefmodifiers or subfamily as “regular” but are actually of @@ -2664,9 +2640,11 @@ do end if plausible_weight then - return fontstyle_name and regular_synonym [fontstyle_name] - or prefmodifiers and regular_synonym [prefmodifiers] - or subfamily and regular_synonym [subfamily] + if prefmodifiers and regular_synonym [prefmodifiers] + or subfamily and regular_synonym [subfamily] + then + return "r" + end end return false end @@ -2693,7 +2671,6 @@ local pull_values = function (entry) entry.fullname = english.fullname or info.fullname entry.prefmodifiers = english.prefmodifiers entry.familyname = metadata.familyname or english.preffamily or english.family - entry.fontstyle_name = sanitized.fontstyle_name entry.plainname = names.fullname entry.subfamily = english.subfamily @@ -2758,7 +2735,6 @@ collect_families = function (mappings) local subtable = get_subtable (families, entry) local familyname = entry.familyname - local fontstyle_name = entry.fontstyle_name local prefmodifiers = entry.prefmodifiers local subfamily = entry.subfamily @@ -2766,26 +2742,15 @@ collect_families = function (mappings) local pfmweight = entry.pfmweight local italicangle = entry.italicangle - local modifier = pick_style (fontstyle_name, - prefmodifiers, - subfamily) + local modifier = pick_style (prefmodifiers, subfamily) if not modifier then --- regular, exact only - modifier = check_regular (fontstyle_name, - prefmodifiers, + modifier = check_regular (prefmodifiers, subfamily, italicangle, weight, pfmweight) end - --if familyname == "garamondpremierpro" then - --print(entry.fullname, "reg?",modifier, "->",fontstyle_name, - --prefmodifiers, - --subfamily, - --italicangle, - --pfmweight, - --weight) - --end if modifier then add_family (familyname, subtable, modifier, entry) @@ -3022,7 +2987,7 @@ local collect_statistics = function (mappings) local sum_dsnsize, n_dsnsize = 0, 0 local fullname, family, families = { }, { }, { } - local subfamily, prefmodifiers, fontstyle_name = { }, { }, { } + local subfamily, prefmodifiers = { }, { } local addtohash = function (hash, item) if item then @@ -3082,7 +3047,6 @@ local collect_statistics = function (mappings) addtohash (family, englishnames.family) addtohash (subfamily, englishnames.subfamily) addtohash (prefmodifiers, englishnames.prefmodifiers) - addtohash (fontstyle_name, names.fontstyle_name) addtoset (families, englishnames.family, englishnames.fullname) @@ -3157,10 +3121,6 @@ local collect_statistics = function (mappings) setsize (prefmodifiers)) pprint_top (prefmodifiers, 4) - logreport ("both", 0, "db", - " · %d different “fontstyle_name” kinds.", - setsize (fontstyle_name)) - pprint_top (fontstyle_name, 4) end local mean_dsnsize = 0 @@ -3177,7 +3137,6 @@ local collect_statistics = function (mappings) -- style = { -- subfamily = subfamily, -- prefmodifiers = prefmodifiers, --- fontstyle_name = fontstyle_name, -- }, } end -- cgit v1.2.3 From 08f6c022be4fca298df03fe5582647d5b8c9785e Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 27 Apr 2016 08:00:39 +0200 Subject: [db] adapt call to getinfo() for revised interface --- src/luaotfload-database.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index b8a50d6..e0f6e61 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -1410,7 +1410,6 @@ local map_english_names = function (metadata) certain. --]]-- if platformnames then - --inspect(metadata) --namesource = platformnames.macintosh or platformnames.windows namesource = platformnames.windows or platformnames.macintosh end @@ -3501,8 +3500,16 @@ local use_fontforge = function (val) close_font_file = fontloader.close get_english_names = get_english_names_from_ff else - read_font_file = otfhandler.readers.getinfo - read_font_info = read_font_file + 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 -- cgit v1.2.3 From 48a7f10116bcdbcfbf427e761c48df33713ba5e5 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 27 Apr 2016 08:20:15 +0200 Subject: [db] disarm fallback assignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When adapting to the new loader we repeated the mistake of classifying “bold” faces by too broad criteria, thereby sabotaging the recognition of large families from Adobe. Restore the old behavior by only treating those faces as bold fallback that advertise and exact weight of 700. --- src/luaotfload-database.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index e0f6e61..0c2fd40 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -478,7 +478,6 @@ end --- define locals in scope local access_font_index -local collect_families local find_closest local flush_lookup_cache local generate_filedata @@ -2567,6 +2566,9 @@ generate_filedata = function (mappings) return files end +local bold_spectrum_low = 501 --- 500 is medium, 900 heavy/black +local bold_weight = 700 + local pick_style local pick_fallback_style local check_regular @@ -2607,7 +2609,7 @@ do pick_fallback_style = function (italicangle, weight, pfmweight) --- more aggressive, but only to determine bold faces - if pfmweight > 500 or bold_synonym [weight] then --- bold spectrum matches + if pfmweight == bold_weight or bold_synonym [weight] then --- bold spectrum matches if italicangle == 0 then return "b" end @@ -2713,7 +2715,7 @@ local get_subtable = function (families, entry) return subtable end -collect_families = function (mappings) +local collect_families = function (mappings) logreport ("info", 2, "db", "Analyzing families.") @@ -2753,7 +2755,7 @@ collect_families = function (mappings) if modifier then add_family (familyname, subtable, modifier, entry) - elseif pfmweight > 500 then -- in bold spectrum + elseif pfmweight >= bold_spectrum_low then -- in bold spectrum modifier = pick_fallback_style (italicangle, weight, pfmweight) if modifier then add_family (familyname, subtable, modifier, entry) @@ -2776,8 +2778,6 @@ end --doc]]-- -local bold_spectrum_low = 501 --- 500 is medium, 900 heavy/black -local bold_weight = 700 local style_categories = { "r", "b", "i", "bi" } local bold_categories = { "b", "bi" } -- cgit v1.2.3 From d6b1caf014582edd216efab7ab47fd5193591ae3 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 27 Apr 2016 22:26:01 +0200 Subject: [db] restrict bold style fallback heuristic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @dohyunkim pointed out that due to the too broad criteria, secondary style variants like “heavy”, “black” ended up getting picked over the actual “bold”. --- src/luaotfload-database.lua | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/luaotfload-database.lua') diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 0c2fd40..437091f 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -2608,8 +2608,17 @@ do end pick_fallback_style = function (italicangle, weight, pfmweight) - --- more aggressive, but only to determine bold faces - if pfmweight == bold_weight or bold_synonym [weight] then --- bold spectrum matches + --[[-- + More aggressive, but only to determine bold faces. + Note: Before you make this test more inclusive, ensure + no fonts are matched in the bold synonym spectrum over + a literally “bold[italic]” one. In the past, heuristics + been tried but ultimately caused unwanted modifiers + polluting the lookup table. What doesn’t work is, e. g. + treating weights > 500 as bold or allowing synonyms like + “heavy”, “black”. + --]]-- + if pfmweight == bold_weight then --- bold spectrum matches if italicangle == 0 then return "b" end @@ -2753,13 +2762,12 @@ local collect_families = function (mappings) pfmweight) end + if not modifier then + modifier = pick_fallback_style (italicangle, weight, pfmweight) + end + if modifier then add_family (familyname, subtable, modifier, entry) - elseif pfmweight >= bold_spectrum_low then -- in bold spectrum - modifier = pick_fallback_style (italicangle, weight, pfmweight) - if modifier then - add_family (familyname, subtable, modifier, entry) - end end end -- cgit v1.2.3