diff options
-rw-r--r-- | doc/filegraph.dot | 2 | ||||
-rw-r--r-- | doc/luaotfload-main.tex | 2 | ||||
-rwxr-xr-x | scripts/mkimport | 34 | ||||
-rwxr-xr-x | scripts/mkstatus | 2 | ||||
-rw-r--r-- | src/fontloader/misc/fontloader-font-one.lua (renamed from src/fontloader/misc/fontloader-font-afm.lua) | 336 | ||||
-rw-r--r-- | src/luaotfload-init.lua | 8 | ||||
-rwxr-xr-x | src/luaotfload-tool.lua | 4 |
7 files changed, 201 insertions, 187 deletions
diff --git a/doc/filegraph.dot b/doc/filegraph.dot index b274461..0c2dad1 100644 --- a/doc/filegraph.dot +++ b/doc/filegraph.dot @@ -356,7 +356,7 @@ strict digraph luaotfload_files { //looks weird with circo ... <td>font-tfm.lua</td> </tr> <tr> - <td>font-afm.lua</td> + <td>font-one.lua</td> <td>font-afk.lua</td> <td>font-oti.lua</td> </tr> diff --git a/doc/luaotfload-main.tex b/doc/luaotfload-main.tex index 05c3670..bebb7df 100644 --- a/doc/luaotfload-main.tex +++ b/doc/luaotfload-main.tex @@ -1279,7 +1279,7 @@ grouped twofold as below: \beginaltitem{font-cid.lua} \endaltitem \beginaltitem{font-map.lua} \endaltitem \beginaltitem{font-tfm.lua} \endaltitem - \beginaltitem{font-afm.lua} \endaltitem + \beginaltitem{font-one.lua} \endaltitem \beginaltitem{font-afk.lua} \endaltitem \beginaltitem{font-oti.lua} \endaltitem \beginaltitem{font-otr.lua} \endaltitem diff --git a/scripts/mkimport b/scripts/mkimport index 25d7560..e2b6f72 100755 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -228,7 +228,6 @@ local imports = { context = { --=> all merged { name = "data-con" , ours = "data-con" , kind = kind_merged }, { name = "font-afk" , ours = "font-afk" , kind = kind_merged }, - { name = "font-afm" , ours = "font-afm" , kind = kind_merged }, { name = "font-cff" , ours = "font-cff" , kind = kind_merged }, { name = "font-cid" , ours = "font-cid" , kind = kind_merged }, { name = "font-con" , ours = "font-con" , kind = kind_merged }, @@ -238,6 +237,7 @@ local imports = { { name = "font-ini" , ours = "font-ini" , kind = kind_merged }, { name = "font-lua" , ours = "font-lua" , kind = kind_merged }, { name = "font-map" , ours = "font-map" , kind = kind_merged }, + { name = "font-one" , ours = "font-one" , kind = kind_merged }, { name = "font-osd" , ours = "font-osd" , kind = kind_merged }, { name = "font-ota" , ours = "font-ota" , kind = kind_merged }, { name = "font-otd" , ours = "font-otd" , kind = kind_merged }, @@ -294,20 +294,20 @@ local package = { --- [20] font-map.lua --- [21] luatex-fonts-syn.lua --- [22] font-tfm.lua ---- [23] font-afm.lua ---- [24] font-afk.lua ---- [25] font-oti.lua ---- [26] font-otr.lua ---- [27] font-cff.lua ---- [28] font-ttf.lua ---- [29] font-dsp.lua ---- [30] font-oup.lua ---- [31] font-otl.lua ---- [32] font-oto.lua ---- [33] font-otj.lua ---- [34] font-ota.lua ---- [35] font-ots.lua ---- [36] font-osd.lua +--- [23] font-oti.lua +--- [24] font-otr.lua +--- [25] font-cff.lua +--- [26] font-ttf.lua +--- [27] font-dsp.lua +--- [28] font-oup.lua +--- [29] font-otl.lua +--- [30] font-oto.lua +--- [31] font-otj.lua +--- [32] font-ota.lua +--- [33] font-ots.lua +--- [34] font-osd.lua +--- [35] font-one.lua +--- [36] font-afk.lua --- [37] font-lua.lua --- [38] font-def.lua --- [39] font-xtx.lua @@ -358,8 +358,6 @@ local package = { "font-map", "fonts-syn", "font-tfm", - "font-afm", - "font-afk", "font-oti", "font-otr", "font-cff", @@ -372,6 +370,8 @@ local package = { "font-ota", "font-ots", "font-osd", + "font-one", + "font-afk", "font-lua", "font-def", "fonts-ext", diff --git a/scripts/mkstatus b/scripts/mkstatus index f9ff7eb..6a05833 100755 --- a/scripts/mkstatus +++ b/scripts/mkstatus @@ -84,7 +84,7 @@ local names = { { miscdir, "fontloader-basics-nod.lua", }, { miscdir, "fontloader-data-con.lua", }, { miscdir, "fontloader-font-afk.lua", }, - { miscdir, "fontloader-font-afm.lua", }, + { miscdir, "fontloader-font-one.lua", }, { miscdir, "fontloader-font-cid.lua", }, { miscdir, "fontloader-font-con.lua", }, { miscdir, "fontloader-font-def.lua", }, diff --git a/src/fontloader/misc/fontloader-font-afm.lua b/src/fontloader/misc/fontloader-font-one.lua index 0d6b7cb..3602fd4 100644 --- a/src/fontloader/misc/fontloader-font-afm.lua +++ b/src/fontloader/misc/fontloader-font-one.lua @@ -1,4 +1,4 @@ -if not modules then modules = { } end modules ['font-afm'] = { +if not modules then modules = { } end modules ['font-one'] = { version = 1.001, comment = "companion to font-ini.mkiv", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", @@ -7,22 +7,16 @@ if not modules then modules = { } end modules ['font-afm'] = { } --[[ldx-- -<p>Some code may look a bit obscure but this has to do with the -fact that we also use this code for testing and much code evolved -in the transition from <l n='tfm'/> to <l n='afm'/> to <l -n='otf'/>.</p> - -<p>The following code still has traces of intermediate font support -where we handles font encodings. Eventually font encoding goes -away.</p> - -<p>The embedding of a font involves creating temporary files and -depending on your system setup that can fail. It took more than a -day to figure out why sometimes embedding failed in mingw luatex -where running on a real path like c:\... failed while running on -say e:\... being a link worked well. The native windows binaries -don't have this issue.</p> +<p>Some code may look a bit obscure but this has to do with the fact that we also use +this code for testing and much code evolved in the transition from <l n='tfm'/> to +<l n='afm'/> to <l n='otf'/>.</p> +<p>The following code still has traces of intermediate font support where we handles +font encodings. Eventually font encoding went away but we kept some code around in +other modules.</p> + +<p>This version implements a node mode approach so that users can also more easily +add features.</p> --ldx]]-- local fonts, logs, trackers, containers, resolvers = fonts, logs, trackers, containers, resolvers @@ -52,39 +46,25 @@ local constructors = fonts.constructors local afm = constructors.newhandler("afm") local pfb = constructors.newhandler("pfb") +local otf = fonts.handlers.otf + +local otfreaders = otf.readers +local otfenhancers = otf.enhancers local afmfeatures = constructors.newfeatures("afm") local registerafmfeature = afmfeatures.register -afm.version = 1.501 -- incrementing this number one up will force a re-cache +afm.version = 1.505 -- incrementing this number one up will force a re-cache afm.cache = containers.define("fonts", "afm", afm.version, true) afm.autoprefixed = true -- this will become false some day (catches texnansi-blabla.*) afm.helpdata = { } -- set later on so no local for this afm.syncspace = true -- when true, nicer stretch values -afm.addligatures = true -- best leave this set to true -afm.addtexligatures = true -- best leave this set to true -afm.addkerns = true -- best leave this set to true local overloads = fonts.mappings.overloads local applyruntimefixes = fonts.treatments and fonts.treatments.applyfixes -local function setmode(tfmdata,value) - if value then - tfmdata.properties.mode = lower(value) - end -end - -registerafmfeature { - name = "mode", - description = "mode", - initializers = { - base = setmode, - node = setmode, - } -} - --[[ldx-- <p>We start with the basic reader which we give a name similar to the built in <l n='tfm'/> and <l n='otf'/> reader.</p> @@ -222,61 +202,13 @@ local function get_variables(data,fontmetrics) end end +-- new (unfinished) pfb loader but i see no differences between +-- old and new (one bad vector with old) + local get_indexes do - -- old font loader - - local fontloader = fontloader - local get_indexes_old = false - - if fontloader then - - local font_to_table = fontloader.to_table - local open_font = fontloader.open - local close_font = fontloader.close - - get_indexes_old = function(data,pfbname) - local pfbblob = open_font(pfbname) - if pfbblob then - local characters = data.characters - local pfbdata = font_to_table(pfbblob) - if pfbdata then - local glyphs = pfbdata.glyphs - if glyphs then - if trace_loading then - report_afm("getting index data from %a",pfbname) - end - for index, glyph in next, glyphs do - local name = glyph.name - if name then - local char = characters[name] - if char then - if trace_indexing then - report_afm("glyph %a has index %a",name,index) - end - char.index = index - end - end - end - elseif trace_loading then - report_afm("no glyph data in pfb file %a",pfbname) - end - elseif trace_loading then - report_afm("no data in pfb file %a",pfbname) - end - close_font(pfbblob) - elseif trace_loading then - report_afm("invalid pfb file %a",pfbname) - end - end - - end - - -- new (unfinished) font loader but i see no differences between - -- old and new (one bad vector with old) - local n, m local progress = function(str,position,name,size) @@ -395,21 +327,6 @@ do end end - if get_indexes_old then - - afm.use_new_indexer = true - get_indexes_new = get_indexes - - get_indexes = function(data,pfbname) - if afm.use_new_indexer then - return get_indexes_new(data,pfbname) - else - return get_indexes_old(data,pfbname) - end - end - - end - end local function readafm(filename) @@ -469,15 +386,17 @@ local function readafm(filename) end --[[ldx-- -<p>We cache files. Caching is taken care of in the loader. We cheat a bit -by adding ligatures and kern information to the afm derived data. That -way we can set them faster when defining a font.</p> +<p>We cache files. Caching is taken care of in the loader. We cheat a bit by adding +ligatures and kern information to the afm derived data. That way we can set them faster +when defining a font.</p> + +<p>We still keep the loading two phased: first we load the data in a traditional +fashion and later we transform it to sequences.</p> --ldx]]-- -local addkerns, addligatures, addtexligatures, unify, normalize, fixnames -- we will implement these later +local addkerns, unify, normalize, fixnames, addligatures, addtexligatures function afm.load(filename) - -- hm, for some reasons not resolved yet filename = resolvers.findfile(filename,'afm') or "" if filename ~= "" and not fonts.names.ignoredfile(filename) then local name = file.removesuffix(file.basename(filename)) @@ -503,38 +422,55 @@ function afm.load(filename) if pfbname ~= "" then data.resources.filename = resolvers.unresolve(pfbname) get_indexes(data,pfbname) - elseif trace_loading then + elseif trace_loading then report_afm("no pfb file for %a",filename) -- data.resources.filename = "unset" -- better than loading the afm file end - report_afm("unifying %a",filename) - unify(data,filename) - if afm.addligatures then - report_afm("add ligatures") - addligatures(data) + -- we now have all the data loaded + if trace_loading then + report_afm("unifying %a",filename) end - if afm.addtexligatures then - report_afm("add tex ligatures") - addtexligatures(data) + unify(data,filename) + if trace_loading then + report_afm("add ligatures") -- there can be missing ones end - if afm.addkerns then + addligatures(data) + if trace_loading then report_afm("add extra kerns") - addkerns(data) + end + addkerns(data) + if trace_loading then + report_afm("normalizing") end normalize(data) + if trace_loading then + report_afm("fixing names") + end fixnames(data) - report_afm("add tounicode data") + if trace_loading then + report_afm("add tounicode data") + end + -- otfreaders.addunicodetable(data) -- only when not done yet fonts.mappings.addtounicode(data,filename) + -- otfreaders.extend(data) + otfreaders.pack(data) data.size = size data.time = time data.pfbsize = pfbsize data.pfbtime = pfbtime report_afm("saving %a in cache",name) - data.resources.unicodes = nil -- consistent with otf but here we save not much + -- data.resources.unicodes = nil -- consistent with otf but here we save not much data = containers.write(afm.cache, name, data) data = containers.read(afm.cache,name) end - if applyruntimefixes and data then + end + if data then + -- constructors.addcoreunicodes(unicodes) + otfreaders.unpack(data) + otfreaders.expand(data) -- inline tables + otfreaders.addunicodetable(data) -- only when not done yet + otfenhancers.apply(data,filename,data) + if applyruntimefixes then applyruntimefixes(filename,data) end end @@ -602,12 +538,105 @@ end local everywhere = { ["*"] = { ["*"] = true } } -- or: { ["*"] = { "*" } } local noflags = { false, false, false, false } -afm.experimental_normalize = false - normalize = function(data) - if type(afm.experimental_normalize) == "function" then - afm.experimental_normalize(data) + local ligatures = setmetatableindex("table") + local kerns = setmetatableindex("table") + local extrakerns = setmetatableindex("table") + for u, c in next, data.descriptions do + local l = c.ligatures + local k = c.kerns + local e = c.extrakerns + if l then + ligatures[u] = l + for u, v in next, l do + l[u] = { ligature = v } + end + c.ligatures = nil + end + if k then + kerns[u] = k + for u, v in next, k do + k[u] = v -- { v, 0 } + end + c.kerns = nil + end + if e then + extrakerns[u] = e + for u, v in next, e do + e[u] = v -- { v, 0 } + end + c.extrakerns = nil + end + end + local features = { + gpos = { }, + gsub = { }, + } + local sequences = { + -- only filled ones + } + if next(ligatures) then + features.gsub.liga = everywhere + data.properties.hasligatures = true + sequences[#sequences+1] = { + features = { + liga = everywhere, + }, + flags = noflags, + name = "s_s_0", + nofsteps = 1, + order = { "liga" }, + type = "gsub_ligature", + steps = { + { + coverage = ligatures, + }, + }, + } + end + if next(kerns) then + features.gpos.kern = everywhere + data.properties.haskerns = true + sequences[#sequences+1] = { + features = { + kern = everywhere, + }, + flags = noflags, + name = "p_s_0", + nofsteps = 1, + order = { "kern" }, + type = "gpos_pair", + steps = { + { + format = "kern", + coverage = kerns, + }, + }, + } + end + if next(extrakerns) then + features.gpos.extrakerns = everywhere + data.properties.haskerns = true + sequences[#sequences+1] = { + features = { + extrakerns = everywhere, + }, + flags = noflags, + name = "p_s_1", + nofsteps = 1, + order = { "extrakerns" }, + type = "gpos_pair", + steps = { + { + format = "kern", + coverage = extrakerns, + }, + }, + } end + -- todo: compress kerns + data.resources.features = features + data.resources.sequences = sequences end fixnames = function(data) @@ -982,6 +1011,8 @@ local function afmtotfm(specification) tfmdata.shared = shared end shared.rawdata = rawdata + shared.dynamics = { } + tfmdata.changed = { } shared.features = features shared.processes = afm.setfeatures(tfmdata,features) end @@ -1089,53 +1120,36 @@ local function texreplacements(tfmdata,value) end end -local function ligatures (tfmdata,value) prepareligatures(tfmdata,'ligatures', value) end -local function texligatures(tfmdata,value) prepareligatures(tfmdata,'texligatures',value) end -local function kerns (tfmdata,value) preparekerns (tfmdata,'kerns', value) end +-- local function ligatures (tfmdata,value) prepareligatures(tfmdata,'ligatures', value) end +-- local function texligatures(tfmdata,value) prepareligatures(tfmdata,'texligatures',value) end +-- local function kerns (tfmdata,value) preparekerns (tfmdata,'kerns', value) end local function extrakerns (tfmdata,value) preparekerns (tfmdata,'extrakerns', value) end -registerafmfeature { - name = "liga", - description = "traditional ligatures", - initializers = { - base = ligatures, - node = ligatures, - } -} - -registerafmfeature { - name = "kern", - description = "intercharacter kerning", - initializers = { - base = kerns, - node = kerns, - } -} - -registerafmfeature { - name = "extrakerns", - description = "additional intercharacter kerning", - initializers = { - base = extrakerns, - node = extrakerns, - } -} +local function setmode(tfmdata,value) + if value then + tfmdata.properties.mode = lower(value) + end +end registerafmfeature { - name = 'tlig', - description = 'tex ligatures', + name = "mode", + description = "mode", initializers = { - base = texligatures, - node = texligatures, + base = setmode, + node = setmode, } } registerafmfeature { - name = 'trep', - description = 'tex replacements', + name = "features", + description = "features", + default = true, initializers = { - base = texreplacements, - node = texreplacements, + node = otf.nodemodeinitializer, + base = otf.basemodeinitializer, + }, + processors = { + node = otf.featuresprocessor, } } diff --git a/src/luaotfload-init.lua b/src/luaotfload-init.lua index bcc0e18..dfa4c56 100644 --- a/src/luaotfload-init.lua +++ b/src/luaotfload-init.lua @@ -251,8 +251,6 @@ local context_modules = { { ctx, "font-map" }, { ltx, "luatex-fonts-syn" }, { ctx, "font-tfm" }, - { ctx, "font-afm" }, - { ctx, "font-afk" }, { ctx, "font-oti" }, { ctx, "font-otr" }, { ctx, "font-cff" }, @@ -265,6 +263,8 @@ local context_modules = { { ctx, "font-ota" }, { ctx, "font-ots" }, { ctx, "font-osd" }, + { ctx, "font-one" }, + { ctx, "font-afk" }, { ctx, "font-lua" }, { ctx, "font-def" }, { ltx, "luatex-fonts-ext" }, @@ -509,8 +509,6 @@ local init_main = function () load_fontloader_module "font-map" load_fontloader_module "fonts-syn" load_fontloader_module "font-tfm" - load_fontloader_module "font-afm" - load_fontloader_module "font-afk" load_fontloader_module "font-oti" load_fontloader_module "font-otr" load_fontloader_module "font-cff" @@ -523,6 +521,8 @@ local init_main = function () load_fontloader_module "font-ota" load_fontloader_module "font-ots" load_fontloader_module "font-osd" + load_fontloader_module "font-one" + load_fontloader_module "font-afk" load_fontloader_module "font-lua" load_fontloader_module "font-def" load_fontloader_module "fonts-ext" diff --git a/src/luaotfload-tool.lua b/src/luaotfload-tool.lua index 35dc9b3..a24643c 100755 --- a/src/luaotfload-tool.lua +++ b/src/luaotfload-tool.lua @@ -145,8 +145,6 @@ require "fontloader-fonts-enc" require "fontloader-font-cid" require "fontloader-font-map" require "fontloader-font-tfm" -require "fontloader-font-afm" -require "fontloader-font-afk" require "fontloader-font-oti" require "fontloader-font-otr" require "fontloader-font-cff" @@ -159,6 +157,8 @@ require "fontloader-font-oto" ------- "fontloader-font-ota" ------- "fontloader-font-ots" ------- "fontloader-font-osd" +require "fontloader-font-one" +require "fontloader-font-afk" require "fontloader-font-lua" require "fontloader-font-def" require "fontloader-fonts-ext" |