From a5bdb8782fc92ea930e1f09b60bab5c97f3d533c Mon Sep 17 00:00:00 2001
From: Marius
This is very experimental code!
+--ldx]]-- + local trace_combining = false trackers.register("fonts.combining", function(v) trace_combining = v end) local trace_combining_all = false trackers.register("fonts.combining.all", function(v) trace_combining = v trace_combining_all = v end) -local force_combining = false -- just for demo purposes (see mk) trackers.register("fonts.composing", "fonts.combining") trackers.register("fonts.composing.all", "fonts.combining.all") local report_combining = logs.reporter("fonts","combining") -local allocate = utilities.storage.allocate +local force_combining = false -- just for demo purposes (see mk) ---[[ldx-- -This is very experimental code!
---ldx]]-- +local allocate = utilities.storage.allocate local fonts = fonts local handlers = fonts.handlers local constructors = fonts.constructors -local vf = handlers.vf -local commands = vf.combiner.commands - -local otffeatures = constructors.newfeatures("otf") -local registerotffeature = otffeatures.register -local afmfeatures = constructors.newfeatures("afm") -local registerafmfeature = afmfeatures.register +local registerotffeature = handlers.otf.features.register +local registerafmfeature = handlers.afm.features.register local unicodecharacters = characters.data local unicodefallbacks = characters.fallbacks +local vf = handlers.vf +local commands = vf.combiner.commands local push = vf.predefined.push local pop = vf.predefined.pop + local force_composed = false local cache = { } -- we could make these weak local fraction = 0.15 -- 30 units for lucida diff --git a/tex/context/base/font-gds.lua b/tex/context/base/font-gds.lua index 3b87e4c77..ce26c66c5 100644 --- a/tex/context/base/font-gds.lua +++ b/tex/context/base/font-gds.lua @@ -8,44 +8,39 @@ if not modules then modules = { } end modules ['font-gds'] = { -- depends on ctx -local type, next = type, next +local type, next, tonumber = type, next, tonumber local gmatch, format, lower, find, splitup = string.gmatch, string.format, string.lower, string.find, string.splitup local texsp = tex.sp local fonts, nodes, attributes, node = fonts, nodes, attributes, node -local trace_goodies = false - -trackers.register("fonts.goodies", function(v) trace_goodies = v end) - +local trace_goodies = false trackers.register("fonts.goodies", function(v) trace_goodies = v end) local report_goodies = logs.reporter("fonts","goodies") local allocate = utilities.storage.allocate local otf = fonts.handlers.otf -local addotffeature = otf.enhancers.addfeature - -local otffeatures = fonts.constructors.newfeatures("otf") -local registerotffeature = otffeatures.register - -local afmfeatures = fonts.constructors.newfeatures("afm") -local registerafmfeature = afmfeatures.register +local afm = fonts.handlers.afm +local tfm = fonts.handlers.tfm -local tfmfeatures = fonts.constructors.newfeatures("tfm") -local registertfmfeature = tfmfeatures.register +local registerotffeature = otf.features.register +local registerafmfeature = afm.features.register +local registertfmfeature = tfm.features.register -local fontgoodies = { } +local fontgoodies = fonts.goodies or { } fonts.goodies = fontgoodies -local typefaces = allocate() +local typefaces = fonts.typefaces or allocate() fonts.typefaces = typefaces -local data = allocate() -fontgoodies.data = fontgoodies.data +local data = fontgoodies.data or allocate() +fontgoodies.data = data -local list = { } +local list = fontgoodies.list or { } fontgoodies.list = list -- no allocate as we want to see what is there +local addotffeature = otf.enhancers.addfeature + function fontgoodies.report(what,trace,goodies) if trace_goodies or trace then local whatever = goodies[what] @@ -141,7 +136,7 @@ end -- fonts.features.flattened = flattenedfeatures -function fontgoodies.prepare_features(goodies,name,set) +local function prepare_features(goodies,name,set) if set then local ff = flattenedfeatures(set) local fullname = goodies.name .. "::" .. name @@ -154,6 +149,8 @@ function fontgoodies.prepare_features(goodies,name,set) end end +fontgoodies.prepare_features = prepare_features + local function initialize(goodies,tfmdata) local featuresets = goodies.featuresets local goodiesname = goodies.name @@ -162,7 +159,7 @@ local function initialize(goodies,tfmdata) report_goodies("checking featuresets in '%s'",goodies.name) end for name, set in next, featuresets do - fontgoodies.prepare_features(goodies,name,set) + prepare_features(goodies,name,set) end end end @@ -177,7 +174,7 @@ local function setfeatureset(tfmdata,set,features) for i=1,#goodies do -- last one wins local g = goodies[i] - what = (g.featuresets and g.featuresets[set]) or what + what = g.featuresets and g.featuresets[set] or what end if what then for feature, value in next, what do @@ -193,12 +190,13 @@ end -- postprocessors (we could hash processor and share code) function fontgoodies.registerpostprocessor(tfmdata,f,prepend) - if not tfmdata.postprocessors then + local postprocessors = tfmdata.postprocessors + if not postprocessors then tfmdata.postprocessors = { f } elseif prepend then - table.insert(tfmdata.postprocessors,f,1) + table.insert(postprocessors,f,1) else - table.insert(tfmdata.postprocessors,f) + table.insert(postprocessors,f) end end @@ -236,9 +234,9 @@ end -- colorschemes -local colorschemes = { } +local colorschemes = fontgoodies.colorschemes or { } fontgoodies.colorschemes = colorschemes -colorschemes.data = { } +colorschemes.data = colorschemes.data or { } local function setcolorscheme(tfmdata,scheme) if type(scheme) == "string" then @@ -249,7 +247,7 @@ local function setcolorscheme(tfmdata,scheme) for i=1,#goodies do -- last one counts local g = goodies[i] - what = (g.colorschemes and g.colorschemes[scheme]) or what + what = g.colorschemes and g.colorschemes[scheme] or what end if type(what) == "table" then -- this is font bound but we can share them if needed @@ -605,9 +603,10 @@ end fontgoodies.register("compositions", initialize) -local designsizes = { } +local designsizes = fontgoodies.designsizes or { } fontgoodies.designsizes = designsizes -local designdata = allocate() + +local designdata = designsizes.data or allocate() designsizes.data = designdata local function initialize(goodies) -- design sizes are registered global diff --git a/tex/context/base/font-ini.lua b/tex/context/base/font-ini.lua index 8eeba0ce7..884b22474 100644 --- a/tex/context/base/font-ini.lua +++ b/tex/context/base/font-ini.lua @@ -6,33 +6,27 @@ if not modules then modules = { } end modules ['font-ini'] = { license = "see context related readme files" } --- basemethods -> can also be in list --- presetcontext -> defaults --- hashfeatures -> ctx version - --[[ldx--Not much is happening here.
--ldx]]-- -local lower = string.lower -local allocate, mark = utilities.storage.allocate, utilities.storage.mark +local allocate = utilities.storage.allocate local report_defining = logs.reporter("fonts","defining") -fontloader.totable = fontloader.to_table - -fonts = fonts or { } -- already defined in context +fonts = fonts or { } local fonts = fonts --- some of these might move to where they are used first: - fonts.hashes = { identifiers = allocate() } + +fonts.tables = fonts.tables or { } +fonts.helpers = fonts.helpers or { } +fonts.tracers = fonts.tracers or { } -- for the moment till we have move to moduledata +fonts.specifiers = fonts.specifiers or { } -- in format ! + fonts.analyzers = { } -- not needed here fonts.readers = { } -fonts.tables = { } fonts.definers = { methods = { } } -fonts.specifiers = fonts.specifiers or { } -- in format ! fonts.loggers = { register = function() end } -fonts.helpers = { } -fonts.tracers = { } -- for the moment till we have move to moduledata +fontloader.totable = fontloader.to_table diff --git a/tex/context/base/font-map.lua b/tex/context/base/font-map.lua index 7f5305f9a..685f9beea 100644 --- a/tex/context/base/font-map.lua +++ b/tex/context/base/font-map.lua @@ -6,18 +6,20 @@ if not modules then modules = { } end modules ['font-map'] = { license = "see context related readme files" } +local tonumber = tonumber + local match, format, find, concat, gsub, lower = string.match, string.format, string.find, table.concat, string.gsub, string.lower local P, R, S, C, Ct, Cc, lpegmatch = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cc, lpeg.match local utfbyte = utf.byte -local trace_loading = false trackers.register("fonts.loading", function(v) trace_loading = v end) +local trace_loading = false trackers.register("fonts.loading", function(v) trace_loading = v end) local trace_mapping = false trackers.register("fonts.mapping", function(v) trace_unimapping = v end) local report_fonts = logs.reporter("fonts","loading") -- not otf only -local fonts = fonts -local mappings = { } -fonts.mappings = mappings +local fonts = fonts +local mappings = fonts.mappings or { } +fonts.mappings = mappings --[[ldx--Eventually this code will disappear because map files are kind @@ -40,7 +42,7 @@ end local hex = R("AF","09") local hexfour = (hex*hex*hex*hex) / function(s) return tonumber(s,16) end local hexsix = (hex^1) / function(s) return tonumber(s,16) end -local dec = (R("09")^1) / tonumber +local dec = (R("09")^1) / tonumber local period = P(".") local unicode = P("uni") * (hexfour * (period + P(-1)) * Cc(false) + Ct(hexfour^1) * Cc(true)) local ucode = P("u") * (hexsix * (period + P(-1)) * Cc(false) + Ct(hexsix ^1) * Cc(true)) diff --git a/tex/context/base/font-otb.lua b/tex/context/base/font-otb.lua index 44639a80a..04e289ba9 100644 --- a/tex/context/base/font-otb.lua +++ b/tex/context/base/font-otb.lua @@ -11,26 +11,27 @@ local type, next, tonumber, tostring = type, next, tonumber, tostring local lpegmatch = lpeg.match local utfchar = utf.char -local trace_baseinit = false trackers.register("otf.baseinit", function(v) trace_baseinit = v end) -local trace_singles = false trackers.register("otf.singles", function(v) trace_singles = v end) -local trace_multiples = false trackers.register("otf.multiples", function(v) trace_multiples = v end) -local trace_alternatives = false trackers.register("otf.alternatives", function(v) trace_alternatives = v end) -local trace_ligatures = false trackers.register("otf.ligatures", function(v) trace_ligatures = v end) -local trace_kerns = false trackers.register("otf.kerns", function(v) trace_kerns = v end) -local trace_preparing = false trackers.register("otf.preparing", function(v) trace_preparing = v end) +local trace_baseinit = false trackers.register("otf.baseinit", function(v) trace_baseinit = v end) +local trace_singles = false trackers.register("otf.singles", function(v) trace_singles = v end) +local trace_multiples = false trackers.register("otf.multiples", function(v) trace_multiples = v end) +local trace_alternatives = false trackers.register("otf.alternatives", function(v) trace_alternatives = v end) +local trace_ligatures = false trackers.register("otf.ligatures", function(v) trace_ligatures = v end) +local trace_ligatures_detail = false trackers.register("otf.ligatures.detail", function(v) trace_ligatures_detail = v end) +local trace_kerns = false trackers.register("otf.kerns", function(v) trace_kerns = v end) +local trace_preparing = false trackers.register("otf.preparing", function(v) trace_preparing = v end) -local report_prepare = logs.reporter("fonts","otf prepare") +local report_prepare = logs.reporter("fonts","otf prepare") -local fonts = fonts -local otf = fonts.handlers.otf +local fonts = fonts +local otf = fonts.handlers.otf -local otffeatures = fonts.constructors.newfeatures("otf") -local registerotffeature = otffeatures.register +local otffeatures = otf.features +local registerotffeature = otffeatures.register -otf.defaultbasealternate = "none" -- first last +otf.defaultbasealternate = "none" -- first last -local wildcard = "*" -local default = "dflt" +local wildcard = "*" +local default = "dflt" local function gref(descriptions,n) if type(n) == "number" then @@ -165,7 +166,7 @@ local function finalize_ligatures(tfmdata,ligatures) if ligature then local unicode, lookupdata = ligature[1], ligature[2] if trace then - print("BUILDING",concat(lookupdata," "),unicode) + trace_ligatures_detail("building %q into %q",concat(lookupdata," "),unicode) end local size = #lookupdata local firstcode = lookupdata[1] -- [2] @@ -178,7 +179,7 @@ local function finalize_ligatures(tfmdata,ligatures) if not firstdata then firstcode = private if trace then - print(" DEFINING",firstname,firstcode) + trace_ligatures_detail("defining %q as %q",firstname,firstcode) end unicodes[firstname] = firstcode firstdata = { intermediate = true, ligatures = { } } @@ -202,7 +203,7 @@ local function finalize_ligatures(tfmdata,ligatures) end end if trace then - print("CODES",firstname,firstcode,secondname,secondcode,target) + trace_ligatures_detail("codes (%s,%s) + (%s,%s) -> %s",firstname,firstcode,secondname,secondcode,target) end local firstligs = firstdata.ligatures if firstligs then diff --git a/tex/context/base/font-otc.lua b/tex/context/base/font-otc.lua index ae463e750..777267254 100644 --- a/tex/context/base/font-otc.lua +++ b/tex/context/base/font-otc.lua @@ -17,8 +17,7 @@ local report_otf = logs.reporter("fonts","otf loading") local fonts = fonts local otf = fonts.handlers.otf -local otffeatures = fonts.constructors.newfeatures("otf") -local registerotffeature = otffeatures.register +local registerotffeature = otf.features.register local setmetatableindex = table.setmetatableindex -- In the userdata interface we can not longer tweak the loaded font as diff --git a/tex/context/base/font-oti.lua b/tex/context/base/font-oti.lua index d6853db31..06c2a42fa 100644 --- a/tex/context/base/font-oti.lua +++ b/tex/context/base/font-oti.lua @@ -8,15 +8,16 @@ if not modules then modules = { } end modules ['font-oti'] = { local lower = string.lower -local allocate = utilities.storage.allocate - local fonts = fonts -local otf = { } -fonts.handlers.otf = otf +local constructors = fonts.constructors -local otffeatures = fonts.constructors.newfeatures("otf") +local otf = constructors.newhandler("otf") +local otffeatures = constructors.newfeatures("otf") +local otftables = otf.tables local registerotffeature = otffeatures.register +local allocate = utilities.storage.allocate + registerotffeature { name = "features", description = "initialization of feature handler", @@ -25,8 +26,6 @@ registerotffeature { -- these are later hooked into node and base initializaters -local otftables = otf.tables -- not always defined - local function setmode(tfmdata,value) if value then tfmdata.properties.mode = lower(value) diff --git a/tex/context/base/font-otp.lua b/tex/context/base/font-otp.lua index f019ade7f..6c9827de8 100644 --- a/tex/context/base/font-otp.lua +++ b/tex/context/base/font-otp.lua @@ -17,14 +17,18 @@ local report_otf = logs.reporter("fonts","otf loading") -- also used in other scripts so we need to check some tables: fonts = fonts or { } -fonts.handlers = fonts.handlers or { } -local handlers = fonts.handlers -handlers.otf = handlers.otf or { } -local otf = handlers.otf -otf.enhancers = otf.enhancers or { } -local enhancers = otf.enhancers -otf.glists = otf.glists or { "gsub", "gpos" } -local glists = otf.glists + +local handlers = fonts.handlers or { } +fonts.handlers = handlers + +local otf = handlers.otf or { } +handlers.otf = otf + +local enhancers = otf.enhancers or { } +otf.enhancers = enhancers + +local glists = otf.glists or { "gsub", "gpos" } +otf.glists = glists local criterium = 1 local threshold = 0 @@ -43,12 +47,30 @@ local function tabstr(t) s[n] = k .. "=false" end end - sort(s) - return concat(s,",") + if n == 1 then + return s[1] + else + sort(s) + return concat(s,",") + end end + +-- -- saves only a few tens of bytes +-- +-- local function stripdata(data) +-- for k, v in next, data do +-- if not v or v == "" then +-- data[k] = nil +-- elseif type(v) == "table" then +-- stripdata(v) -- keep empty tables +-- end +-- end +-- end + local function packdata(data) if data then + -- stripdata(data) local h, t, c = { }, { }, { } local hh, tt, cc = { }, { }, { } local nt, ntt = 0, 0 @@ -202,21 +224,10 @@ local function packdata(data) if rules then for i=1,#rules do -- was next loop local rule = rules[i] ---~ local r = rule.before if r then for i=1,#r do r[i] = pack(r[i],true) end end ---~ local r = rule.after if r then for i=1,#r do r[i] = pack(r[i],true) end end ---~ local r = rule.current if r then for i=1,#r do r[i] = pack(r[i],true) end end ---~ local r = rule.replacements if r then rule.replacements = pack(r, true) end ---~ local r = rule.fore if r then rule.fore = pack(r, true) end ---~ local r = rule.back if r then rule.back = pack(r, true) end ---~ local r = rule.names if r then rule.names = pack(r, true) end ---~ local r = rule.lookups if r then rule.lookups = pack(r) end local r = rule.before if r then for i=1,#r do r[i] = pack(r[i]) end end local r = rule.after if r then for i=1,#r do r[i] = pack(r[i]) end end local r = rule.current if r then for i=1,#r do r[i] = pack(r[i]) end end local r = rule.replacements if r then rule.replacements = pack(r) end - -- local r = rule.fore if r then rule.fore = pack(r) end - -- local r = rule.back if r then rule.back = pack(r) end - -- local r = rule.names if r then rule.names = pack(r) end local r = rule.lookups if r then rule.lookups = pack(r) end end end diff --git a/tex/context/base/font-ott.lua b/tex/context/base/font-ott.lua index 1e0124ac5..1aeda273b 100644 --- a/tex/context/base/font-ott.lua +++ b/tex/context/base/font-ott.lua @@ -3,7 +3,8 @@ if not modules then modules = { } end modules ['font-ott'] = { comment = "companion to font-otf.lua (tables)", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", copyright = "PRAGMA ADE / ConTeXt Development Team", - license = "see context related readme files" + license = "see context related readme files", + -- dataonly = true, } local type, next, tonumber, tostring, rawget, rawset = type, next, tonumber, tostring, rawget, rawset @@ -16,11 +17,14 @@ local allocate = utilities.storage.allocate local fonts = fonts local otf = fonts.handlers.otf -local tables = { } +local otffeatures = otf.features +local registerotffeature = otffeatures.register + +local tables = otf.tables or { } otf.tables = tables -local otffeatures = fonts.constructors.newfeatures("otf") -local registerotffeature = otffeatures.register +local statistics = otf.statistics or { } +otf.statistics = statistics local scripts = allocate { ['arab'] = 'arabic', @@ -622,10 +626,6 @@ local features = allocate { ['trep'] = 'traditional tex replacements', ['tlig'] = 'traditional tex ligatures', - -- ['ss'] = 'stylistic set %s', - -- ['cv'] = 'character variant %s', - -- ['js'] = 'justification %s', - ['ss..'] = 'stylistic set ..', ['cv..'] = 'character variant ..', ['js..'] = 'justification ..', @@ -641,16 +641,16 @@ local baselines = allocate { ['romn'] = 'roman baseline' } -local acceptscripts = true directives.register("otf.acceptscripts", function(v) acceptscripts = v end) -local acceptlanguages = true directives.register("otf.acceptlanguages", function(v) acceptlanguages = v end) - -local report_checks = logs.reporter("fonts","checks") - tables.scripts = scripts tables.languages = languages tables.features = features tables.baselines = baselines +local acceptscripts = true directives.register("otf.acceptscripts", function(v) acceptscripts = v end) +local acceptlanguages = true directives.register("otf.acceptlanguages", function(v) acceptlanguages = v end) + +local report_checks = logs.reporter("fonts","checks") + -- hm, we overload the metatables if otffeatures.features then @@ -690,6 +690,10 @@ setmetatableindex(verboselanguages, resolve) setmetatableindex(verbosefeatures, resolve) setmetatableindex(verbosebaselines, resolve) +-- We could optimize the next lookups by using an extra metatable and storing +-- already found values but in practice there are not that many lookups so +-- it's never a bottleneck. + setmetatableindex(scripts, function(t,k) if k then k = lower(k) @@ -756,7 +760,7 @@ local function resolve(t,k) if tag and dd then local v = rawget(t,tag) if v then - return format(v,tonumber(dd)) -- old way + return v -- return format(v,tonumber(dd)) -- old way else local v = rawget(t,tag.."..") -- nicer in overview if v then @@ -786,31 +790,85 @@ local checkers = { end } -function otf.features.normalize(features) -- no longer 'lang' +-- Keep this: +-- +-- function otf.features.normalize(features) +-- if features then +-- local h = { } +-- for k, v in next, features do +-- k = lower(k) +-- if k == "language" then +-- v = gsub(lower(v),"[^a-z0-9]","") +-- h.language = rawget(verboselanguages,v) or (languages[v] and v) or "dflt" -- auto adds +-- elseif k == "script" then +-- v = gsub(lower(v),"[^a-z0-9]","") +-- h.script = rawget(verbosescripts,v) or (scripts[v] and v) or "dflt" -- auto adds +-- else +-- if type(v) == "string" then +-- local b = is_boolean(v) +-- if type(b) == "nil" then +-- v = tonumber(v) or lower(v) +-- else +-- v = b +-- end +-- end +-- if not rawget(features,k) then +-- k = rawget(verbosefeatures,k) or k +-- end +-- local c = checkers[k] +-- h[k] = c and c(v) or v +-- end +-- end +-- return h +-- end +-- end + +-- inspect(fonts.handlers.otf.statistics.usedfeatures) + +local usedfeatures = statistics.usedfeatures or { } +statistics.usedfeatures = usedfeatures + +table.setmetatableindex(usedfeatures, function(t,k) if k then local v = { } t[k] = v return v end end) -- table.autotable + +storage.register("fonts/otf/usedfeatures", usedfeatures, "fonts.handlers.otf.statistics.usedfeatures" ) + +function otf.features.normalize(features) if features then local h = { } - for k, v in next, features do - k = lower(k) + for key, value in next, features do + local k = lower(key) if k == "language" then - v = gsub(lower(v),"[^a-z0-9]","") + local v = gsub(lower(value),"[^a-z0-9]","") h.language = rawget(verboselanguages,v) or (languages[v] and v) or "dflt" -- auto adds elseif k == "script" then - v = gsub(lower(v),"[^a-z0-9]","") + local v = gsub(lower(value),"[^a-z0-9]","") h.script = rawget(verbosescripts,v) or (scripts[v] and v) or "dflt" -- auto adds else - if type(v) == "string" then - local b = is_boolean(v) - if type(b) == "nil" then - v = tonumber(v) or lower(v) + local uk = usedfeatures[key] + local uv = uk[value] + if uv then + -- report_checks("feature value %q first seen at %q",value,key) + else + if type(value) == "string" then + local b = is_boolean(value) + if type(b) == "nil" then + uv = tonumber(value) or lower(value) + else + uv = b + end else - v = b + uv = v end + if not rawget(features,k) then + k = rawget(verbosefeatures,k) or k + end + local c = checkers[k] + if c then + uv = c(uv) or vc + end + uk[value] = uv end - if not rawget(features,k) then - k = rawget(verbosefeatures,k) or k - end - local c = checkers[k] - h[k] = c and c(v) or v + h[k] = uv end end return h diff --git a/tex/context/base/font-pat.lua b/tex/context/base/font-pat.lua index b91502c74..50d99f668 100644 --- a/tex/context/base/font-pat.lua +++ b/tex/context/base/font-pat.lua @@ -6,11 +6,13 @@ if not modules then modules = { } end modules ['font-pat'] = { license = "see context related readme files" } +-- This functiononality is nowadays provided via lfg files so what you see here +-- is more an example. + local match, lower = string.match, string.lower --- older versions of latin modern didn't have the designsize set --- so for them we get it from the name --- reporter moved to elsewhere +-- Older versions of latin modern didn't have the designsize set so for them we +-- get it from the name reporter moved to elsewhere. local fonts = fonts local otf = fonts.handlers.otf @@ -32,9 +34,9 @@ register("after","migrate metadata","^lmroman", patch) register("after","migrate metadata","^lmsans", patch) register("after","migrate metadata","^lmtypewriter",patch) --- for some reason (either it's a bug in the font, or it's --- a problem in the library) the palatino arabic fonts don't --- have the mkmk features properly set up +-- For some reason (either it's a bug in the font, or it's a problem in the +-- library) the palatino arabic fonts don't have the mkmk features properly +-- set up. local function patch(data,filename) local gpos = data.gpos diff --git a/tex/context/base/font-syn.lua b/tex/context/base/font-syn.lua index c4f0e948b..31af73d97 100644 --- a/tex/context/base/font-syn.lua +++ b/tex/context/base/font-syn.lua @@ -34,11 +34,11 @@ using a table that has keys filtered from the font related files.
fonts = fonts or { } -- also used elsewhere -local names = { } +local names = font.names or { } fonts.names = names -names.filters = names.filters or { } -local filters = names.filters +local filters = names.filters or { } +names.filters = filters names.data = names.data or { } diff --git a/tex/context/base/font-tfm.lua b/tex/context/base/font-tfm.lua index b1ec7c1de..f394a2441 100644 --- a/tex/context/base/font-tfm.lua +++ b/tex/context/base/font-tfm.lua @@ -15,22 +15,21 @@ local trace_features = false trackers.register("tfm.features", func local report_defining = logs.reporter("fonts","defining") local report_tfm = logs.reporter("fonts","tfm loading") +local findbinfile = resolvers.findbinfile + local fonts = fonts local handlers = fonts.handlers local readers = fonts.readers local constructors = fonts.constructors local encodings = fonts.encodings -local tfm = { } -handlers.tfm = tfm - -constructors.resolvevirtualtoo = false -- wil be set in font-ctx.lua - -local findbinfile = resolvers.findbinfile +local tfm = constructors.newhandler("tfm") -local tfmfeatures = fonts.constructors.newfeatures("tfm") +local tfmfeatures = constructors.newfeatures("tfm") local registertfmfeature = tfmfeatures.register +constructors.resolvevirtualtoo = false -- wil be set in font-ctx.lua + fonts.formats.tfm = "type1" -- we need to have at least a value here --[[ldx-- diff --git a/tex/context/base/font-vf.lua b/tex/context/base/font-vf.lua index 287d073d6..01d5289f8 100644 --- a/tex/context/base/font-vf.lua +++ b/tex/context/base/font-vf.lua @@ -19,8 +19,7 @@ local fastcopy = table.fastcopy local fonts = fonts local constructors = fonts.constructors -local vf = { } -fonts.handlers.vf = vf +local vf = constructors.newhandler("vf") -- general code diff --git a/tex/context/base/l-string.lua b/tex/context/base/l-string.lua index e36ee0b4b..cdfa9b051 100644 --- a/tex/context/base/l-string.lua +++ b/tex/context/base/l-string.lua @@ -121,3 +121,7 @@ end string.quote = string.quoted string.unquote = string.unquoted + +-- handy fallback + +string.itself = function(s) return s end diff --git a/tex/context/base/lang-lab.lua b/tex/context/base/lang-lab.lua index 893e1554d..8d48a4988 100644 --- a/tex/context/base/lang-lab.lua +++ b/tex/context/base/lang-lab.lua @@ -68,6 +68,8 @@ local prtcatcodes = catcodes.numbers.prtcatcodes -- todo: use different method local trace_labels = false trackers.register("languages.labels", function(v) trace_labels = v end) local report_labels = logs.reporter("languages","labels") +-- trace_labels = true + languages.labels = languages.labels or { } local labels = languages.labels diff --git a/tex/context/base/lang-lab.mkiv b/tex/context/base/lang-lab.mkiv index 285a03315..c3c584beb 100644 --- a/tex/context/base/lang-lab.mkiv +++ b/tex/context/base/lang-lab.mkiv @@ -239,10 +239,10 @@ \definelabelclass [mathlabel] [0] % functions \definelabelclass [taglabel] [2] % tags -\ctxcommand{definelabels("head", "titles", true )} -\ctxcommand{definelabels("label","texts", true )} -\ctxcommand{definelabels("math", "functions",false)} -\ctxcommand{definelabels("tag", "tags", false)} +\ctxcommand{definelabels("head", "titles", true )} +\ctxcommand{definelabels("label", "texts", true )} +\ctxcommand{definelabels("mathlabel", "functions",false)} +\ctxcommand{definelabels("taglabel", "tags", false)} %D \macros %D {translate} diff --git a/tex/context/base/luat-sto.lua b/tex/context/base/luat-sto.lua index e9d0edfe4..fddf262c2 100644 --- a/tex/context/base/luat-sto.lua +++ b/tex/context/base/luat-sto.lua @@ -64,10 +64,12 @@ local function dump() end max = max + 1 if trace_storage then - report_storage('saving %s in slot %s',message,max) c = c + 1 ; code[c] = format("print('restoring %s from slot %s')",message,max) end c = c + 1 ; code[c] = serialize(original,name) + if trace_storage then + report_storage('saving %s in slot %s (%s bytes)',message,max,#code[c]) + end -- we don't need tracing in such tables bytecode[max] = strippedloadstring(concat(code,"\n"),true,format("slot %s",max)) collectgarbage("step") diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf index 851eb356f..1095db683 100644 Binary files a/tex/context/base/status-files.pdf and b/tex/context/base/status-files.pdf differ diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf index 83167d9d2..044cf11e6 100644 Binary files a/tex/context/base/status-lua.pdf and b/tex/context/base/status-lua.pdf differ diff --git a/tex/context/base/status-mkiv.lua b/tex/context/base/status-mkiv.lua index cdea874a6..ba4e87283 100644 --- a/tex/context/base/status-mkiv.lua +++ b/tex/context/base/status-mkiv.lua @@ -17,14 +17,14 @@ return { category = "tex", filename = "metatex", loading = "parent", - status = "todo", + status = "pending", }, { category = "lus", comment = "stub file for metatex", filename = "metatex", loading = "parent", - status = "todo", + status = "pending", }, { category = "mkiv", @@ -2554,12 +2554,14 @@ return { }, { category = "lua", + comment = "todo: colorization and nesting as in scite", filename = "buff-imp-lua", loading = "buff-imp-lua", status = "okay", }, { category = "lua", + comment = "todo: colorization and nesting as in scite", filename = "buff-imp-mp", loading = "buff-imp-mp", status = "okay", @@ -2578,12 +2580,14 @@ return { }, { category = "lua", + comment = "todo: colorization and nesting as in scite", filename = "buff-imp-tex", loading = "buff-imp-tex", status = "okay", }, { category = "lua", + comment = "todo: colorization and nesting as in scite", filename = "buff-imp-xml", loading = "buff-imp-xml", status = "okay", @@ -2591,17 +2595,18 @@ return { { category = "lua", filename = "buff-ini", - status = "todo", + status = "okay", }, { category = "lua", filename = "buff-par", - status = "todo", + status = "okay", }, { category = "lua", + comment = "maybe we will provide a few more (nesting) methods", filename = "buff-ver", - status = "todo", + status = "okay", }, { category = "lua", @@ -2979,9 +2984,10 @@ return { }, { category = "lua", + comment = "needs some documentation in usage", filename = "font-aux", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", @@ -3006,19 +3012,20 @@ return { category = "lua", filename = "font-con", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", + comment = "will be improved over time", filename = "font-ctx", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", filename = "font-def", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", @@ -3029,33 +3036,36 @@ return { }, { category = "lua", + comment = "needs documentation at the tex end", filename = "font-enh", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", + comment = "maybe some data tables can be be external", filename = "font-ext", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", + comment = "okay but can be improved", filename = "font-fbk", loading = "font-lib", - status = "todo", + status = "pending", }, { category = "lua", filename = "font-gds", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", filename = "font-ini", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", @@ -3067,19 +3077,21 @@ return { category = "lua", filename = "font-log", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", + comment = "currently rather minimalistic", filename = "font-lua", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", + comment = "the lum file support will be dropped / no map files anyway", filename = "font-map", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", @@ -3089,69 +3101,71 @@ return { }, { category = "lua", + comment = "when more scripts are supported we might end up with imp files", filename = "font-ota", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", filename = "font-otb", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", filename = "font-otc", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", filename = "font-otd", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", filename = "font-otf", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", filename = "font-oth", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", filename = "font-oti", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", filename = "font-otn", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", filename = "font-otp", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", filename = "font-ott", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", + comment = "is mostly replaced by lfg files", filename = "font-pat", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", @@ -3161,21 +3175,22 @@ return { }, { category = "lua", + comment = "also loaded on demand", filename = "font-syn", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", filename = "font-tfm", loading = "font-lib", - status = "todo", + status = "okay", }, { category = "lua", filename = "font-vf", loading = "font-lib", - status = "todo", + status = "pending", }, { category = "lua", diff --git a/tex/context/base/status-mkiv.tex b/tex/context/base/status-mkiv.tex index c221b1d55..48c36acfb 100644 --- a/tex/context/base/status-mkiv.tex +++ b/tex/context/base/status-mkiv.tex @@ -17,13 +17,15 @@ \setuphead [title] [style=\bfa, - page=yes] + page=yes, + after={\blank[line]}] \setuppagenumbering [location=] \setupheadertexts - [\currentdate][MkIV Status / Page \pagenumber] + [\currentdate] + [MkIV Status / Page \pagenumber] % \showmakeup % \showallmakeup @@ -78,6 +80,7 @@ \startitem environment and basic lua helpers are now spread over too many files \stopitem \startitem isolate tracers and showers \stopitem \startitem check all possible usage of ctxcommand \stopitem + \startitem there are more s-* modules, like s-fnt-41 \stopitem \stopitemize \stoptitle diff --git a/tex/context/base/type-imp-husayni.mkiv b/tex/context/base/type-imp-husayni.mkiv index b3c1af5b7..96999fd4e 100644 --- a/tex/context/base/type-imp-husayni.mkiv +++ b/tex/context/base/type-imp-husayni.mkiv @@ -65,7 +65,7 @@ % ss53=yes, % No Waslah % ss54=yes, % chopped finals % ss55=yes, % idgham-tanwin - ss60=yes, % + ss60=yes, % % js01=yes, % Raawide % js02=yes, % Yaawide % js03=yes, % Kaafwide @@ -122,16 +122,16 @@ init=yes,medi=yes,fina=yes,isol=yes, rlig=yes,liga=yes, mset=yes] - + \definedelimitedtext [ornatequote] [left={\char"FD3F\penalty10000}, - right={\char"FD3E\penalty10000}] - + right={\char"FD3E\penalty10000}] + \definedelimitedtext [arparenthesis] [left={\char"0028}, - right={\char"0029}] + right={\char"0029}] \definedelimitedtext [arquotation] @@ -143,4 +143,4 @@ [arquote] [left={\symbol[rightquote]}, right={\symbol[leftquote]}, - leftmargin=standard] \ No newline at end of file + leftmargin=standard] diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 47b6be3d1..38dee68f1 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 07/26/12 19:37:03 +-- merge date : 07/27/12 16:41:17 do -- begin closure to overcome local limits and interference @@ -128,6 +128,10 @@ end string.quote = string.quoted string.unquote = string.unquoted +-- handy fallback + +string.itself = function(s) return s end + end -- closure do -- begin closure to overcome local limits and interference @@ -3283,36 +3287,30 @@ if not modules then modules = { } end modules ['font-ini'] = { license = "see context related readme files" } --- basemethods -> can also be in list --- presetcontext -> defaults --- hashfeatures -> ctx version - --[[ldx--Not much is happening here.
--ldx]]-- -local lower = string.lower -local allocate, mark = utilities.storage.allocate, utilities.storage.mark +local allocate = utilities.storage.allocate local report_defining = logs.reporter("fonts","defining") -fontloader.totable = fontloader.to_table - -fonts = fonts or { } -- already defined in context +fonts = fonts or { } local fonts = fonts --- some of these might move to where they are used first: - fonts.hashes = { identifiers = allocate() } + +fonts.tables = fonts.tables or { } +fonts.helpers = fonts.helpers or { } +fonts.tracers = fonts.tracers or { } -- for the moment till we have move to moduledata +fonts.specifiers = fonts.specifiers or { } -- in format ! + fonts.analyzers = { } -- not needed here fonts.readers = { } -fonts.tables = { } fonts.definers = { methods = { } } -fonts.specifiers = fonts.specifiers or { } -- in format ! fonts.loggers = { register = function() end } -fonts.helpers = { } -fonts.tracers = { } -- for the moment till we have move to moduledata +fontloader.totable = fontloader.to_table end -- closure @@ -3349,9 +3347,9 @@ local report_defining = logs.reporter("fonts","defining") --ldx]]-- local fonts = fonts -local constructors = { } +local constructors = fonts.constructors or { } fonts.constructors = constructors -local handlers = { } +local handlers = fonts.handlers or { } -- can have preloaded tables fonts.handlers = handlers local specifiers = fonts.specifiers @@ -4490,19 +4488,31 @@ function constructors.getfeatureaction(what,where,mode,name) end end -function constructors.newfeatures(what) - local features = handlers[what].features +function constructors.newhandler(what) -- could be a metatable newindex + local handler = handlers[what] + if not handler then + handler = { } + handlers[what] = handler + end + return handler +end + +function constructors.newfeatures(what) -- could be a metatable newindex + local handler = handlers[what] + local features = handler.features if not features then - local tables = handlers[what].tables -- can be preloaded + local tables = handler.tables -- can be preloaded + local statistics = handler.statistics -- can be preloaded features = allocate { defaults = { }, descriptions = tables and tables.features or { }, + used = statistics and statistics.usedfeatures or { }, initializers = { base = { }, node = { } }, processors = { base = { }, node = { } }, manipulators = { base = { }, node = { } }, } features.register = function(specification) return register(features,specification) end - handlers[what].features = features -- will also become hidden + handler.features = features -- will also become hidden end return features end @@ -4869,18 +4879,20 @@ if not modules then modules = { } end modules ['font-map'] = { license = "see context related readme files" } +local tonumber = tonumber + local match, format, find, concat, gsub, lower = string.match, string.format, string.find, table.concat, string.gsub, string.lower local P, R, S, C, Ct, Cc, lpegmatch = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cc, lpeg.match local utfbyte = utf.byte -local trace_loading = false trackers.register("fonts.loading", function(v) trace_loading = v end) +local trace_loading = false trackers.register("fonts.loading", function(v) trace_loading = v end) local trace_mapping = false trackers.register("fonts.mapping", function(v) trace_unimapping = v end) local report_fonts = logs.reporter("fonts","loading") -- not otf only -local fonts = fonts -local mappings = { } -fonts.mappings = mappings +local fonts = fonts +local mappings = fonts.mappings or { } +fonts.mappings = mappings --[[ldx--Eventually this code will disappear because map files are kind @@ -4903,7 +4915,7 @@ end local hex = R("AF","09") local hexfour = (hex*hex*hex*hex) / function(s) return tonumber(s,16) end local hexsix = (hex^1) / function(s) return tonumber(s,16) end -local dec = (R("09")^1) / tonumber +local dec = (R("09")^1) / tonumber local period = P(".") local unicode = P("uni") * (hexfour * (period + P(-1)) * Cc(false) + Ct(hexfour^1) * Cc(true)) local ucode = P("u") * (hexsix * (period + P(-1)) * Cc(false) + Ct(hexsix ^1) * Cc(true)) @@ -5314,15 +5326,16 @@ if not modules then modules = { } end modules ['font-oti'] = { local lower = string.lower -local allocate = utilities.storage.allocate - local fonts = fonts -local otf = { } -fonts.handlers.otf = otf +local constructors = fonts.constructors -local otffeatures = fonts.constructors.newfeatures("otf") +local otf = constructors.newhandler("otf") +local otffeatures = constructors.newfeatures("otf") +local otftables = otf.tables local registerotffeature = otffeatures.register +local allocate = utilities.storage.allocate + registerotffeature { name = "features", description = "initialization of feature handler", @@ -5331,8 +5344,6 @@ registerotffeature { -- these are later hooked into node and base initializaters -local otftables = otf.tables -- not always defined - local function setmode(tfmdata,value) if value then tfmdata.properties.mode = lower(value) @@ -7503,26 +7514,27 @@ local type, next, tonumber, tostring = type, next, tonumber, tostring local lpegmatch = lpeg.match local utfchar = utf.char -local trace_baseinit = false trackers.register("otf.baseinit", function(v) trace_baseinit = v end) -local trace_singles = false trackers.register("otf.singles", function(v) trace_singles = v end) -local trace_multiples = false trackers.register("otf.multiples", function(v) trace_multiples = v end) -local trace_alternatives = false trackers.register("otf.alternatives", function(v) trace_alternatives = v end) -local trace_ligatures = false trackers.register("otf.ligatures", function(v) trace_ligatures = v end) -local trace_kerns = false trackers.register("otf.kerns", function(v) trace_kerns = v end) -local trace_preparing = false trackers.register("otf.preparing", function(v) trace_preparing = v end) +local trace_baseinit = false trackers.register("otf.baseinit", function(v) trace_baseinit = v end) +local trace_singles = false trackers.register("otf.singles", function(v) trace_singles = v end) +local trace_multiples = false trackers.register("otf.multiples", function(v) trace_multiples = v end) +local trace_alternatives = false trackers.register("otf.alternatives", function(v) trace_alternatives = v end) +local trace_ligatures = false trackers.register("otf.ligatures", function(v) trace_ligatures = v end) +local trace_ligatures_detail = false trackers.register("otf.ligatures.detail", function(v) trace_ligatures_detail = v end) +local trace_kerns = false trackers.register("otf.kerns", function(v) trace_kerns = v end) +local trace_preparing = false trackers.register("otf.preparing", function(v) trace_preparing = v end) -local report_prepare = logs.reporter("fonts","otf prepare") +local report_prepare = logs.reporter("fonts","otf prepare") -local fonts = fonts -local otf = fonts.handlers.otf +local fonts = fonts +local otf = fonts.handlers.otf -local otffeatures = fonts.constructors.newfeatures("otf") -local registerotffeature = otffeatures.register +local otffeatures = otf.features +local registerotffeature = otffeatures.register -otf.defaultbasealternate = "none" -- first last +otf.defaultbasealternate = "none" -- first last -local wildcard = "*" -local default = "dflt" +local wildcard = "*" +local default = "dflt" local function gref(descriptions,n) if type(n) == "number" then @@ -7657,7 +7669,7 @@ local function finalize_ligatures(tfmdata,ligatures) if ligature then local unicode, lookupdata = ligature[1], ligature[2] if trace then - print("BUILDING",concat(lookupdata," "),unicode) + trace_ligatures_detail("building %q into %q",concat(lookupdata," "),unicode) end local size = #lookupdata local firstcode = lookupdata[1] -- [2] @@ -7670,7 +7682,7 @@ local function finalize_ligatures(tfmdata,ligatures) if not firstdata then firstcode = private if trace then - print(" DEFINING",firstname,firstcode) + trace_ligatures_detail("defining %q as %q",firstname,firstcode) end unicodes[firstname] = firstcode firstdata = { intermediate = true, ligatures = { } } @@ -7694,7 +7706,7 @@ local function finalize_ligatures(tfmdata,ligatures) end end if trace then - print("CODES",firstname,firstcode,secondname,secondcode,target) + trace_ligatures_detail("codes (%s,%s) + (%s,%s) -> %s",firstname,firstcode,secondname,secondcode,target) end local firstligs = firstdata.ligatures if firstligs then @@ -12237,6 +12249,8 @@ if not modules then modules = { } end modules ['font-def'] = { license = "see context related readme files" } +-- We can overload some of the definers.functions so we don't local them. + local concat = table.concat local format, gmatch, match, find, lower, gsub = string.format, string.gmatch, string.match, string.find, string.lower, string.gsub local tostring, next = tostring, next @@ -12273,7 +12287,6 @@ definers.methods = definers.methods or { } local internalized = allocate() -- internal tex numbers (private) - local loadedfonts = constructors.loadedfonts local designsizes = constructors.designsizes @@ -12303,7 +12316,7 @@ and prepares a table that will move along as we proceed.
-- name name(sub) name(sub)*spec name*spec -- name@spec*oeps -local splitter, splitspecifiers = nil, "" +local splitter, splitspecifiers = nil, "" -- not so nice local P, C, S, Cc = lpeg.P, lpeg.C, lpeg.S, lpeg.Cc @@ -12314,7 +12327,7 @@ local space = P(" ") definers.defaultlookup = "file" -local prefixpattern = P(false) +local prefixpattern = P(false) local function addspecifier(symbol) splitspecifiers = splitspecifiers .. symbol @@ -12350,12 +12363,12 @@ function definers.registersplit(symbol,action,verbosename) end end -function definers.makespecification(specification,lookup,name,sub,method,detail,size) +local function makespecification(specification,lookup,name,sub,method,detail,size) size = size or 655360 if trace_defining then report_defining("%s -> lookup: %s, name: %s, sub: %s, method: %s, detail: %s", - specification, (lookup ~= "" and lookup) or "[file]", (name ~= "" and name) or "-", - (sub ~= "" and sub) or "-", (method ~= "" and method) or "-", (detail ~= "" and detail) or "-") + specification, lookup ~= "" and lookup or "[file]", name ~= "" and name or "-", + sub ~= "" and sub or "-", method ~= "" and method or "-", detail ~= "" and detail or "-") end if not lookup or lookup == "" then lookup = definers.defaultlookup @@ -12375,10 +12388,13 @@ function definers.makespecification(specification,lookup,name,sub,method,detail, return t end + +definers.makespecification = makespecification + function definers.analyze(specification, size) -- can be optimized with locals local lookup, name, sub, method, detail = getspecification(specification or "") - return definers.makespecification(specification, lookup, name, sub, method, detail, size) + return makespecification(specification, lookup, name, sub, method, detail, size) end --[[ldx-- @@ -12473,12 +12489,13 @@ specification yet. function definers.applypostprocessors(tfmdata) local postprocessors = tfmdata.postprocessors if postprocessors then + local properties = tfmdata.properties for i=1,#postprocessors do local extrahash = postprocessors[i](tfmdata) -- after scaling etc if type(extrahash) == "string" and extrahash ~= "" then -- e.g. a reencoding needs this extrahash = gsub(lower(extrahash),"[^a-z]","-") - tfmdata.properties.fullname = format("%s-%s",tfmdata.properties.fullname,extrahash) + properties.fullname = format("%s-%s",properties.fullname,extrahash) end end end -- cgit v1.2.3