From e20a16e95b45dde2dd0b65c6bda460c5c2fe0164 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 11 Aug 2013 11:34:12 +0200 Subject: [type1] install simple PFB reader after loading AFM support --- luaotfload-loaders.lua | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/luaotfload-loaders.lua b/luaotfload-loaders.lua index fd7c8c6..15a97e0 100644 --- a/luaotfload-loaders.lua +++ b/luaotfload-loaders.lua @@ -9,28 +9,6 @@ if not modules then modules = { } end modules ["loaders"] = { local fonts = fonts local readers = fonts.readers ---- ---- opentype reader (from font-otf.lua): ---- (spec : table) -> (suffix : string) -> (format : string) -> (font : table) ---- - -local pfb_reader = function (specification) - return readers.opentype(specification,"pfb","type1") -end - -local pfa_reader = function (specification) - return readers.opentype(specification,"pfa","type1") -end - -fonts.formats.pfb = "type1" -fonts.readers.pfb = pfb_reader -fonts.handlers.pfb = { } --- empty, as with tfm - -fonts.formats.pfa = "type1" -fonts.readers.pfa = pfa_reader -fonts.handlers.pfa = { } - - resolvers.openbinfile = function (filename) if filename and filename ~= "" then local f = io.open(filename,"rb") @@ -87,4 +65,21 @@ require "luaotfload-font-afk.lua" --[[ ]] +local pfb_reader = function (specification) + return readers.opentype(specification,"pfb","type1") +end + +local pfa_reader = function (specification) + return readers.opentype(specification,"pfa","type1") +end + +fonts.formats.pfa = "type1" +fonts.readers.pfa = pfa_reader +fonts.handlers.pfa = { } + + +fonts.formats.pfb = "type1" +fonts.readers.pfb = pfb_reader +fonts.handlers.pfb = { } --- empty, as with tfm + -- vim:tw=71:sw=2:ts=2:expandtab -- cgit v1.2.3 From 168ad92adb99764cf36e592cfdbd541c780a05b5 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 11 Aug 2013 12:18:04 +0200 Subject: [type1] improve PFB reader so it calls the AFM reader where necessary --- luaotfload-loaders.lua | 70 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/luaotfload-loaders.lua b/luaotfload-loaders.lua index 15a97e0..58b06aa 100644 --- a/luaotfload-loaders.lua +++ b/luaotfload-loaders.lua @@ -6,8 +6,19 @@ if not modules then modules = { } end modules ["loaders"] = { license = "see context related readme files" } -local fonts = fonts -local readers = fonts.readers +local fonts = fonts +local readers = fonts.readers +local handlers = fonts.handlers +local formats = fonts.formats + +local lfsisfile = lfs.isfile +local fileaddsuffix = file.addsuffix +local filebasename = file.basename +local stringsub = string.sub + +local lpeg = require "lpeg" +local lpegmatch = lpeg.match +local P, S, Cp = lpeg.P, lpeg.S, lpeg.Cp resolvers.openbinfile = function (filename) if filename and filename ~= "" then @@ -65,21 +76,56 @@ require "luaotfload-font-afk.lua" --[[ ]] -local pfb_reader = function (specification) - return readers.opentype(specification,"pfb","type1") -end - local pfa_reader = function (specification) return readers.opentype(specification,"pfa","type1") end -fonts.formats.pfa = "type1" -fonts.readers.pfa = pfa_reader -fonts.handlers.pfa = { } +--[[doc-- + + The PFB reader checks whether there is a corresponding AFM file and + hands the spec over to the AFM loader if appropriate. Context uses + string.gsub() to accomplish this but that can cause collateral + damage. + +--doc]]-- + +local p_pfb = P"." * S"pP" * S"fF" * S"bB" +--- we have to be careful here so we don’t affect harmless +--- substrings + * (P"(" --- subfont + + P":" --- feature list + + P(-1)) --- end of string +local no_pfb = 1 - p_pfb +local p_pfb_file = no_pfb^1 * Cp() * p_pfb * Cp() --- first occurrence + +local pfb_reader = function (specification, method) + + local afmfile = fileaddsuffix (specification.name, "afm") + + if lfsisfile (afmfile) then + --- switch to afm reader + logs.names_report ("log", 0, "type1", + "Found corresponding AFM file %s, using that.", + filebasename (afmfile)) + local oldspec = specification.specification + local before, after = lpegmatch (p_pfb_file, oldspec) + specification.specification = stringsub (oldspec, 1, before) + .. "afm" + .. stringsub (oldspec, after - 1) + specification.forced = "afm" + return readers.afm (specification, method) + end + + --- else read pfb via opentype mechanism + return readers.opentype (specification, "pfb", "type1") +end +formats.pfa = "type1" +readers.pfa = pfa_reader +handlers.pfa = { } -fonts.formats.pfb = "type1" -fonts.readers.pfb = pfb_reader -fonts.handlers.pfb = { } --- empty, as with tfm +formats.pfb = "type1" +readers.pfb = pfb_reader +handlers.pfb = { } --- empty, as with tfm -- vim:tw=71:sw=2:ts=2:expandtab -- cgit v1.2.3 From 7fa3aa1e45a84fcf08396546f74e3f0d58087050 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 11 Aug 2013 12:29:54 +0200 Subject: [type1] generalize PFB loader so we can derive a PFA one --- luaotfload-loaders.lua | 85 ++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/luaotfload-loaders.lua b/luaotfload-loaders.lua index 58b06aa..56bdf96 100644 --- a/luaotfload-loaders.lua +++ b/luaotfload-loaders.lua @@ -1,5 +1,5 @@ if not modules then modules = { } end modules ["loaders"] = { - version = "2.3a", + version = "2.4", comment = "companion to luaotfload.lua", author = "Hans Hagen, Khaled Hosny, Elie Roux, Philipp Gesang", copyright = "PRAGMA ADE / ConTeXt Development Team", @@ -15,6 +15,8 @@ local lfsisfile = lfs.isfile local fileaddsuffix = file.addsuffix local filebasename = file.basename local stringsub = string.sub +local stringlower = string.lower +local stringupper = string.upper local lpeg = require "lpeg" local lpegmatch = lpeg.match @@ -76,56 +78,65 @@ require "luaotfload-font-afk.lua" --[[ ]] -local pfa_reader = function (specification) - return readers.opentype(specification,"pfa","type1") -end - --[[doc-- - The PFB reader checks whether there is a corresponding AFM file and - hands the spec over to the AFM loader if appropriate. Context uses - string.gsub() to accomplish this but that can cause collateral + The PFB/PFA reader checks whether there is a corresponding AFM file + and hands the spec over to the AFM loader if appropriate. Context + uses string.gsub() to accomplish this but that can cause collateral damage. --doc]]-- -local p_pfb = P"." * S"pP" * S"fF" * S"bB" ---- we have to be careful here so we don’t affect harmless ---- substrings - * (P"(" --- subfont - + P":" --- feature list - + P(-1)) --- end of string -local no_pfb = 1 - p_pfb -local p_pfb_file = no_pfb^1 * Cp() * p_pfb * Cp() --- first occurrence - -local pfb_reader = function (specification, method) - - local afmfile = fileaddsuffix (specification.name, "afm") - - if lfsisfile (afmfile) then - --- switch to afm reader - logs.names_report ("log", 0, "type1", - "Found corresponding AFM file %s, using that.", - filebasename (afmfile)) - local oldspec = specification.specification - local before, after = lpegmatch (p_pfb_file, oldspec) - specification.specification = stringsub (oldspec, 1, before) - .. "afm" - .. stringsub (oldspec, after - 1) - specification.forced = "afm" - return readers.afm (specification, method) +local mk_type1_reader = function (format) + + format = stringlower (format) + local first = stringsub (format, 1, 1) + local second = stringsub (format, 2, 2) + local third = stringsub (format, 3, 3) + + local p_format = P"." + * (P(first) + P(stringupper (first))) + * (P(second) + P(stringupper (second))) + * (P(third) + P(stringupper (third))) + --- we have to be careful here so we don’t affect + --- harmless substrings + * (P"(" --- subfont + + P":" --- feature list + + P(-1)) --- end of string + local no_format = 1 - p_format + local p_format_file = no_format^1 * Cp() * p_format * Cp() + + local reader = function (specification, method) + + local afmfile = fileaddsuffix (specification.name, "afm") + + if lfsisfile (afmfile) then + --- switch to afm reader + logs.names_report ("log", 0, "type1", + "Found corresponding AFM file %s, using that.", + filebasename (afmfile)) + local oldspec = specification.specification + local before, after = lpegmatch (p_format_file, oldspec) + specification.specification = stringsub (oldspec, 1, before) + .. "afm" + .. stringsub (oldspec, after - 1) + specification.forced = "afm" + return readers.afm (specification, method) + end + + --- else read pfb via opentype mechanism + return readers.opentype (specification, format, "type1") end - --- else read pfb via opentype mechanism - return readers.opentype (specification, "pfb", "type1") + return reader end formats.pfa = "type1" -readers.pfa = pfa_reader +readers.pfa = mk_type1_reader "pfa" handlers.pfa = { } formats.pfb = "type1" -readers.pfb = pfb_reader +readers.pfb = mk_type1_reader "pfb" handlers.pfb = { } --- empty, as with tfm -- vim:tw=71:sw=2:ts=2:expandtab -- cgit v1.2.3 From d2bd693bb327ca12eb44a78d994105800b386521 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 11 Aug 2013 12:40:36 +0200 Subject: [doc] mention new files in manual --- luaotfload.dtx | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/luaotfload.dtx b/luaotfload.dtx index 4802844..56e9d4d 100644 --- a/luaotfload.dtx +++ b/luaotfload.dtx @@ -1178,7 +1178,7 @@ and the derived files % % Also, the merged file at some point % loads the Adobe Glyph List from a \LUA table that is contained in -% \fileent{luaotfload-glyphlist.lua}, which is automatically generated by the % +% \fileent{luaotfload-glyphlist.lua}, which is automatically generated by the % script \fileent{mkglyphlist}.\footnote{% % See \fileent{luaotfload-font-enc.lua}. % The hard-coded file name is why we have to replace the procedure @@ -1199,20 +1199,28 @@ and the derived files % \normalitem{\fileent{#1}}% % \space--\hskip1em % } -% \ouritem {luaotfload-features.lua} font feature handling; -% incorporates some of the code from -% \fileent{font-otc} from \CONTEXT; -% \ouritem {luaotfload-override.lua} overrides the \CONTEXT logging -% functionality. -% \ouritem {luaotfload-loaders.lua} registers the \OpenType -% font reader as handler for -% Postscript fonts -% (\abbrev{pfa}, \abbrev{pfb}). -% \ouritem {luaotfload-database.lua} font names database. -% \ouritem {luaotfload-colors.lua} color handling. -% \ouritem {luaotfload-auxiliary.lua} access to internal functionality -% for package authors -% (proposals for additions welcome). +% \ouritem {luaotfload-features.lua} font feature handling; +% incorporates some of the code from +% \fileent{font-otc} from \CONTEXT; +% \ouritem {luaotfload-override.lua} overrides the \CONTEXT logging +% functionality. +% \ouritem {luaotfload-loaders.lua} registers the \OpenType +% font reader as handler for +% Postscript fonts +% (\abbrev{pfa}, \abbrev{pfb}). +% \ouritem {luaotfload-database.lua} font names database. +% \ouritem {luaotfload-colors.lua} color handling. +% \ouritem {luaotfload-auxiliary.lua} access to internal functionality +% for package authors +% (proposals for additions welcome). +% \ouritem {luaotfload-extralibs.lua} layer for loading of further +% Context libraries. +% \ouritem {luaotfload-letterspace.lua} font-based letterspacing. +% \ouritem {luaotfload-typo-krn.lua} attribute-based letterspacing. +% \ouritem {luaotfload-font-afm.lua} \abbrev{afm} loading. +% \ouritem {luaotfload-font-afk.lua} supplementary glyph +% information for \abbrev{afm} +% fonts. % \end{itemize} % % \begin{figure}[b] -- cgit v1.2.3 From 030c5eb4e199acdc322c2df3c35c709cb80c1631 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 11 Aug 2013 12:41:03 +0200 Subject: [meta] include new files in status file --- mkstatus | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mkstatus b/mkstatus index 16d0b5d..5cd73d8 100755 --- a/mkstatus +++ b/mkstatus @@ -42,6 +42,8 @@ local names = { "luaotfload-diagnostics.lua", "luaotfload-extralibs.lua", "luaotfload-features.lua", + "luaotfload-font-afk.lua", + "luaotfload-font-afm.lua", "luaotfload-fonts-cbk.lua", "luaotfload-fonts-def.lua", "luaotfload-fonts-enc.lua", -- cgit v1.2.3 From f2934972c3a6e908624baf77833076cf2fa2f837 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 11 Aug 2013 13:10:41 +0200 Subject: [type1] resolve conflict between TFM and AFM loaders --- luaotfload-loaders.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/luaotfload-loaders.lua b/luaotfload-loaders.lua index 56bdf96..6d6f409 100644 --- a/luaotfload-loaders.lua +++ b/luaotfload-loaders.lua @@ -17,6 +17,7 @@ local filebasename = file.basename local stringsub = string.sub local stringlower = string.lower local stringupper = string.upper +local findbinfile = resolvers.findbinfile local lpeg = require "lpeg" local lpegmatch = lpeg.match @@ -52,6 +53,31 @@ resolvers.loadbinfile = function (filename, filetype) end +--- this function is required because AFM precedes TFM in the reader +--- chain (see definers.loadfont() in font-def.lua + +local check_tfm = function (specification, fullname) + + local foundname = findbinfile (fullname, "tfm") or "" + + if foundname == "" then + foundname = findbinfile (fullname, "ofm") or "" + end + + if foundname == "" then + foundname = fonts.names.getfilename (fullname,"tfm") or "" + end + + if foundname ~= "" then + specification.filename = foundname + specification.format = "ofm" + return font.read_tfm (specification.filename, + specification.size) + end +end + +readers.check_tfm = check_tfm + --[[ ]] --[[doc-- -- cgit v1.2.3 From 74f7e2976e65c04881ac16470c974ed052df125b Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 11 Aug 2013 13:20:17 +0200 Subject: [graph] list AFM support files --- filegraph.dot | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/filegraph.dot b/filegraph.dot index e412279..f69c751 100644 --- a/filegraph.dot +++ b/filegraph.dot @@ -63,6 +63,17 @@ strict digraph luaotfload_files { //looks weird with circo ... luaotfload_libs -> font_names [label="luaotfload-database.lua"] luaotfload_libs -> typo_krn [label="luaotfload-extralibs.lua"] + luaotfload_libs -> font_afm [label="luaotfload-loaders.lua"] + luaotfload_libs -> font_afk [label="luaotfload-loaders.lua"] + + subgraph cluster_afm { rank = same; + label = "AFM support"; + node [style=filled, color=white]; + style = "filled,rounded"; + color = "grey90:white"; + font_afm; + font_afk; } + mkstatus -> status [label="generates from distribution files", style=dashed] @@ -147,6 +158,22 @@ strict digraph luaotfload_files { //looks weird with circo ... style = "filled,rounded", penwidth=2] + font_afk [label = "luaotfload-font-afk.lua", + shape = rect, + width = "3.2cm", + height = "1.2cm", + color = "#01012222", + style = "filled,rounded", + penwidth=2] + + font_afm [label = "luaotfload-font-afm.lua", + shape = rect, + width = "3.2cm", + height = "1.2cm", + color = "#01012222", + style = "filled,rounded", + penwidth=2] + typo_krn [label = "luaotfload-typo-krn.lua", shape = rect, width = "3.2cm", -- cgit v1.2.3