diff options
44 files changed, 494 insertions, 356 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 56b1192a8..62293e867 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -160,6 +160,10 @@ end string.quote = string.quoted string.unquote = string.unquoted +-- handy fallback + +string.itself = function(s) return s end + end -- of closure diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 56b1192a8..62293e867 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -160,6 +160,10 @@ end string.quote = string.quoted string.unquote = string.unquoted +-- handy fallback + +string.itself = function(s) return s end + end -- of closure diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 56b1192a8..62293e867 100755 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -160,6 +160,10 @@ end string.quote = string.quoted string.unquote = string.unquoted +-- handy fallback + +string.itself = function(s) return s end + end -- of closure diff --git a/tex/context/base/buff-ini.lua b/tex/context/base/buff-ini.lua index e5763267f..11d7cc9f6 100644 --- a/tex/context/base/buff-ini.lua +++ b/tex/context/base/buff-ini.lua @@ -13,6 +13,8 @@ local trace_visualize = false trackers.register("buffers.visualize", function(v local report_buffers = logs.reporter("buffers","usage") local report_grabbing = logs.reporter("buffers","grabbing") +local context, commands = context, commands + local concat = table.concat local type, next = type, next local sub, format, match, find = string.sub, string.format, string.match, string.find @@ -26,10 +28,8 @@ local catcodenumbers = catcodes.numbers local ctxcatcodes = catcodenumbers.ctxcatcodes local txtcatcodes = catcodenumbers.txtcatcodes -buffers = { } - +buffers = buffers or { } local buffers = buffers -local context = context local cache = { } @@ -102,14 +102,17 @@ commands.assignbuffer = assign local P, patterns, lpegmatch = lpeg.P, lpeg.patterns, lpeg.match +local anything = patterns.anything +local alwaysmatched = patterns.alwaysmatched + local function countnesting(b,e) local n local g = P(b) / function() n = n + 1 end + P(e) / function() n = n - 1 end - + patterns.anything - local p = patterns.alwaysmatched / function() n = 0 end + + anything + local p = alwaysmatched / function() n = 0 end * g^0 - * patterns.alwaysmatched / function() return n end + * alwaysmatched / function() return n end return p end @@ -152,12 +155,10 @@ function commands.grabbuffer(name,begintag,endtag,bufferdata,catcodes) -- maybe else if continue then dn = dn .. sub(bufferdata,2,-2) -- no \r, \n is more generic + elseif dn == "" then + dn = sub(bufferdata,2,-2) else - if dn == "" then - dn = sub(bufferdata,2,-2) - else - dn = dn .. "\n" .. sub(bufferdata,2,-2) -- no \r, \n is more generic - end + dn = dn .. "\n" .. sub(bufferdata,2,-2) -- no \r, \n is more generic end local last = sub(dn,-1) if last == "\n" or last == "\r" then -- \n is unlikely as \r is the endlinechar diff --git a/tex/context/base/buff-par.lua b/tex/context/base/buff-par.lua index bcdcc851e..fbc622d6b 100644 --- a/tex/context/base/buff-par.lua +++ b/tex/context/base/buff-par.lua @@ -6,21 +6,26 @@ if not modules then modules = { } end modules ['buff-par'] = { license = "see context related readme files" } -local trace_parallel = false trackers.register("buffers.parallel", function(v) trace_parallel = v end) - -local report_parallel = logs.reporter("buffers","parallel") +local context, commands = context, commands local insert, remove, find, gmatch = table.insert, table.remove, string.find, string.gmatch local strip, format = string.strip, string.format -local variables = interfaces.variables +local trace_parallel = false trackers.register("buffers.parallel", function(v) trace_parallel = v end) + +local report_parallel = logs.reporter("buffers","parallel") + +local variables = interfaces.variables + +local parallel = buffers.parallel or { } +buffers.parallel = parallel -buffers.parallel = { } local parallel = buffers.parallel +local settings_to_array = utilities.parsers.settings_to_array -local data = { } +local data = { } function parallel.define(category,tags) - local tags = utilities.parsers.settings_to_array(tags) + local tags = settings_to_array(tags) local entries = { } data[category] = { tags = tags, @@ -38,7 +43,7 @@ function parallel.reset(category,tags) if not tags or tags == "" or tags == variables.all then tags = table.keys(entries) else - tags = utilities.parsers.settings_to_array(tags) + tags = settings_to_array(tags) end for i=1,#tags do entries[tags[i]] = { diff --git a/tex/context/base/buff-ver.lua b/tex/context/base/buff-ver.lua index 06adfe4a6..5748d9298 100644 --- a/tex/context/base/buff-ver.lua +++ b/tex/context/base/buff-ver.lua @@ -18,6 +18,8 @@ local concat = table.concat local C, P, R, S, V, Carg, Cc, Cs = lpeg.C, lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.Carg, lpeg.Cc, lpeg.Cs local patterns, lpegmatch, is_lpeg = lpeg.patterns, lpeg.match, lpeg.is_lpeg +local context, commands = context, commands + local trace_visualize = false trackers.register("buffers.visualize", function(v) trace_visualize = v end) local report_visualizers = logs.reporter("buffers","visualizers") @@ -30,7 +32,6 @@ visualizers.specifications = specifications local tabtospace = utilities.strings.tabtospace local variables = interfaces.variables local settings_to_array = utilities.parsers.settings_to_array -local verbatim = context.verbatim local variables = interfaces.variables local findfile = resolvers.findfile local addsuffix = file.addsuffix @@ -52,6 +53,7 @@ local dodisplayverbatimemptyline = context.dodisplayverbatimemptyline local dodisplayverbatimstart = context.dodisplayverbatimstart local dodisplayverbatimstop = context.dodisplayverbatimstop +local verbatim = context.verbatim local doverbatimspace = context.doverbatimspace local CargOne = Carg(1) diff --git a/tex/context/base/cont-new.mkii b/tex/context/base/cont-new.mkii index 0264366e6..02c30a865 100644 --- a/tex/context/base/cont-new.mkii +++ b/tex/context/base/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2012.07.24 15:58} +\newcontextversion{2012.07.27 16:41} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index 904539237..4be400862 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2012.07.24 15:58} +\newcontextversion{2012.07.27 16:41} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf Binary files differindex cab5577dc..d4fbee880 100644 --- a/tex/context/base/context-version.pdf +++ b/tex/context/base/context-version.pdf diff --git a/tex/context/base/context-version.png b/tex/context/base/context-version.png Binary files differindex 35f343c2c..14b3f7051 100644 --- a/tex/context/base/context-version.png +++ b/tex/context/base/context-version.png diff --git a/tex/context/base/context.mkii b/tex/context/base/context.mkii index 4ae4bbc2a..1c246e388 100644 --- a/tex/context/base/context.mkii +++ b/tex/context/base/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2012.07.24 15:57} +\edef\contextversion{2012.07.27 16:41} %D For those who want to use this: diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 3ba054e33..d38680c4e 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -25,7 +25,7 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2012.07.26 19:37} +\edef\contextversion{2012.07.27 16:41} %D For those who want to use this: diff --git a/tex/context/base/core-con.lua b/tex/context/base/core-con.lua index 1271c92a6..641aea4ba 100644 --- a/tex/context/base/core-con.lua +++ b/tex/context/base/core-con.lua @@ -24,30 +24,29 @@ local utfchar, utfbyte = utf.char, utf.byte local tonumber, tostring = tonumber, tostring local settings_to_array = utilities.parsers.settings_to_array -local allocate = utilities.storage.allocate +local allocate = utilities.storage.allocate -local context = context +local context = context -local variables = interfaces.variables +local variables = interfaces.variables -converters = converters or { } -local converters = converters +converters = converters or { } +local converters = converters -languages = languages or { } -local languages = languages +languages = languages or { } +local languages = languages -local function number(n) - return tonumber(n) -end - -converters.number = number +converters.number = tonumber +converters.numbers = tonumber function commands.number(n) context(n) end +commands.numbers = commands.number + -- to be reconsidered ... languages namespace here, might become local plus a register command local counters = allocate { - ['default'] = { + ['default'] = { -- no metatable as we do a test on keys 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, @@ -127,12 +126,6 @@ local counters = allocate { }, } -table.setmetatableindex(counters,function(t,k) - local v = t.default - t[k] = v - return v -end) - languages.counters = counters counters['ar'] = counters['arabic'] @@ -206,11 +199,11 @@ local function do_alphabetic(n,mapping,mapper,t) end function converters.alphabetic(n,code) - return do_alphabetic(n,counters[code],lowercharacter) + return do_alphabetic(n,counters[code] or counters.default,lowercharacter) end function converters.Alphabetic(n,code) - return do_alphabetic(n,counters[code],uppercharacter) + return do_alphabetic(n,counters[code] or counters.default,uppercharacter) end local lower_offset = 96 @@ -504,10 +497,9 @@ function commands.chinesecapnumerals(n) context(tochinese(n,"cap" )) end function commands.chineseallnumerals(n) context(tochinese(n,"all" )) end converters.sequences = converters.sequences or { } +local sequences = converters.sequences -storage.register("converters/sequences", converters.sequences, "converters.sequences") - -local sequences = converters.sequences +storage.register("converters/sequences", sequences, "converters.sequences") function converters.define(name,set) sequences[name] = settings_to_array(set) @@ -787,11 +779,12 @@ end function commands.currentdate(str,currentlanguage) -- second argument false : no label local list = utilities.parsers.settings_to_array(str) + local splitlabel = languages.labels.split or string.itself -- we need to get the loading order right local year, month, day = tex.year, tex.month, tex.day local auto = true for i=1,#list do local entry = list[i] - local tag, plus = languages.labels.split(entry) + local tag, plus = splitlabel(entry) local ordinal, mnemonic, whatordinal = false, false, nil if not tag then tag = entry diff --git a/tex/context/base/core-con.mkiv b/tex/context/base/core-con.mkiv index be173c293..cdc51eb23 100644 --- a/tex/context/base/core-con.mkiv +++ b/tex/context/base/core-con.mkiv @@ -535,7 +535,7 @@ {\ctxcommand{checkedconversion("#1",#2)}} %D If a conversion is just a font switch then we need to make sure that the -%D number is indeed end up as number in the input, so we need to handle the +%D number is indeed ends up as number in the input, so we need to handle the %D second argument. \def\convertnumber#1#2% expandable diff --git a/tex/context/base/font-afm.lua b/tex/context/base/font-afm.lua index a27a6a236..dab948b32 100644 --- a/tex/context/base/font-afm.lua +++ b/tex/context/base/font-afm.lua @@ -32,16 +32,17 @@ local trace_defining = false trackers.register("fonts.defining", function(v local report_afm = logs.reporter("fonts","afm loading") +local findbinfile = resolvers.findbinfile + local definers = fonts.definers local readers = fonts.readers local constructors = fonts.constructors -local handlers = fonts.handlers -local afm = { } -local pfb = { } +local afm = constructors.newhandler("afm") +local pfb = constructors.newhandler("pfb") -handlers.afm = afm -handlers.pfb = pfb +local afmfeatures = constructors.newfeatures("afm") +local registerafmfeature = afmfeatures.register afm.version = 1.410 -- incrementing this number one up will force a re-cache afm.cache = containers.define("fonts", "afm", afm.version, true) @@ -53,11 +54,6 @@ 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 findbinfile = resolvers.findbinfile - -local afmfeatures = constructors.newfeatures("afm") -local registerafmfeature = afmfeatures.register - local function setmode(tfmdata,value) if value then tfmdata.properties.mode = lower(value) diff --git a/tex/context/base/font-aux.lua b/tex/context/base/font-aux.lua index 0396554ad..5e938ceb9 100644 --- a/tex/context/base/font-aux.lua +++ b/tex/context/base/font-aux.lua @@ -6,7 +6,7 @@ if not modules then modules = { } end modules ['font-aux'] = { license = "see context related readme files" } -local number = tonumber +local tonumber, type = tonumber, type local wrap, yield = coroutine.wrap, coroutine.yield local fonts, font = fonts, font diff --git a/tex/context/base/font-col.lua b/tex/context/base/font-col.lua index 849ade5d8..4b96cca31 100644 --- a/tex/context/base/font-col.lua +++ b/tex/context/base/font-col.lua @@ -209,7 +209,7 @@ end function collections.process(head) -- this way we keep feature processing local done = false - for n in traverse_id(glyph,head) do + for n in traverse_id(glyph_code,head) do local v = vectors[n.font] if v then local id = v[n.char] diff --git a/tex/context/base/font-con.lua b/tex/context/base/font-con.lua index ba1906364..a0b1588c8 100644 --- a/tex/context/base/font-con.lua +++ b/tex/context/base/font-con.lua @@ -29,9 +29,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 @@ -1170,19 +1170,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 diff --git a/tex/context/base/font-ctx.lua b/tex/context/base/font-ctx.lua index 8fdb42c7d..1badc090d 100644 --- a/tex/context/base/font-ctx.lua +++ b/tex/context/base/font-ctx.lua @@ -9,6 +9,8 @@ if not modules then modules = { } end modules ['font-ctx'] = { -- At some point I will clean up the code here so that at the tex end -- the table interface is used. +local context, commands = context, commands + local texcount, texsetcount = tex.count, tex.setcount local format, gmatch, match, find, lower, gsub, byte = string.format, string.gmatch, string.match, string.find, string.lower, string.gsub, string.byte local concat, serialize, sort, fastcopy, mergedtable = table.concat, table.serialize, table.sort, table.fastcopy, table.merged @@ -53,7 +55,7 @@ local texattribute = tex.attribute local designsizefilename = fontgoodies.designsizes.filename -local otffeatures = fonts.constructors.newfeatures("otf") +local otffeatures = handlers.otf.features local registerotffeature = otffeatures.register local baseprocessors = otffeatures.processors.base local baseinitializers = otffeatures.initializers.base @@ -813,6 +815,7 @@ local setdefaultfontname = context.fntsetdefname local setsomefontname = context.fntsetsomename local setemptyfontsize = context.fntsetnopsize local setsomefontsize = context.fntsetsomesize +local letvaluerelax = context.letvaluerelax function commands.definefont_one(str) statistics.starttiming(fonts) @@ -962,7 +965,7 @@ function commands.definefont_two(global,cs,str,size,inheritancemode,classfeature if not tfmdata then report_defining("unable to define %s as [%s]",name,nice_cs(cs)) lastfontid = -1 - context.letvaluerelax(cs) -- otherwise the current definition takes the previous one + letvaluerelax(cs) -- otherwise the current definition takes the previous one elseif type(tfmdata) == "number" then if trace_defining then report_defining("reusing %s with id %s as [%s] (features: %s/%s, fallbacks: %s/%s, goodies: %s/%s, designsize: %s/%s)", diff --git a/tex/context/base/font-def.lua b/tex/context/base/font-def.lua index 96de480ac..e2ff7b355 100644 --- a/tex/context/base/font-def.lua +++ b/tex/context/base/font-def.lua @@ -6,6 +6,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 @@ -42,7 +44,6 @@ definers.methods = definers.methods or { } local internalized = allocate() -- internal tex numbers (private) - local loadedfonts = constructors.loadedfonts local designsizes = constructors.designsizes @@ -72,7 +73,7 @@ and prepares a table that will move along as we proceed.</p> -- 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 @@ -83,7 +84,7 @@ local space = P(" ") definers.defaultlookup = "file" -local prefixpattern = P(false) +local prefixpattern = P(false) local function addspecifier(symbol) splitspecifiers = splitspecifiers .. symbol @@ -119,12 +120,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 @@ -144,10 +145,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-- @@ -242,12 +246,13 @@ specification yet.</p> 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 diff --git a/tex/context/base/font-ext.lua b/tex/context/base/font-ext.lua index 331ffbdfa..560cf23ee 100644 --- a/tex/context/base/font-ext.lua +++ b/tex/context/base/font-ext.lua @@ -10,7 +10,9 @@ local utf = unicode.utf8 local next, type, byte = next, type, string.byte local gmatch, concat, format = string.gmatch, table.concat, string.format local utfchar = utf.char -local getparameters = utilities.parsers.getparameters + +local commands, context = commands, context +local fonts, utilities = fonts, utilities local trace_protrusion = false trackers.register("fonts.protrusion", function(v) trace_protrusion = v end) local trace_expansion = false trackers.register("fonts.expansion", function(v) trace_expansion = v end) @@ -26,17 +28,18 @@ will depend of the font format. Here we define the few that are kind of neutral.</p> --ldx]]-- -local fonts = fonts -local fontdata = fonts.hashes.identifiers +local handlers = fonts.handlers +local hashes = fonts.hashes -local otffeatures = fonts.constructors.newfeatures("otf") -local registerotffeature = otffeatures.register +local registerotffeature = handlers.otf.features.register +local registerafmfeature = handlers.afm.features.register -local afmfeatures = fonts.constructors.newfeatures("afm") -local registerafmfeature = afmfeatures.register +local fontdata = hashes.identifiers local allocate = utilities.storage.allocate local settings_to_array = utilities.parsers.settings_to_array +local getparameters = utilities.parsers.getparameters + local setmetatableindex = table.setmetatableindex -- -- -- -- -- -- @@ -62,14 +65,15 @@ end -- expansion (hz) -- -- -- -- -- -- -fonts.expansions = allocate() -local expansions = fonts.expansions +local expansions = fonts.expansions or allocate() -expansions.classes = allocate() -local classes = expansions.classes +fonts.expansions = expansions -expansions.vectors = allocate() -local vectors = expansions.vectors +local classes = expansions.classes or allocate() +local vectors = expansions.vectors or allocate() + +expansions.classes = classes +expansions.vectors = vectors -- beware, pdftex itself uses percentages * 10 @@ -880,8 +884,8 @@ local new_glyph = nodes.pool.glyph local hpack_node = node.hpack function fonts.helpers.addprivate(tfmdata,name,characterdata) - local properties = tfmdata.properties - local privates = properties.privates + local properties = tfmdata.properties + local privates = properties.privates local lastprivate = properties.lastprivate if lastprivate then lastprivate = lastprivate + 1 @@ -903,7 +907,7 @@ end function fonts.helpers.getprivatenode(tfmdata,name) local properties = tfmdata.properties - local privates = properties and properties.privates + local privates = properties and properties.privates if privates then local p = privates[name] if p then @@ -925,7 +929,7 @@ end function fonts.helpers.hasprivate(tfmdata,name) local properties = tfmdata.properties - local privates = properties and properties.privates + local privates = properties and properties.privates return privates and privates[name] or false end diff --git a/tex/context/base/font-fbk.lua b/tex/context/base/font-fbk.lua index 89831e7c2..69b45811a 100644 --- a/tex/context/base/font-fbk.lua +++ b/tex/context/base/font-fbk.lua @@ -9,40 +9,39 @@ if not modules then modules = { } end modules ['font-fbk'] = { local cos, tan, rad, format = math.cos, math.tan, math.rad, string.format local utfbyte, utfchar = utf.byte, utf.char +--[[ldx-- +<p>This is very experimental code!</p> +--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-- -<p>This is very experimental code!</p> ---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-- <p>Not much is happening here.</p> --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-- <p>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.</p> 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 Binary files differindex 851eb356f..1095db683 100644 --- a/tex/context/base/status-files.pdf +++ b/tex/context/base/status-files.pdf diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf Binary files differindex 83167d9d2..044cf11e6 100644 --- a/tex/context/base/status-lua.pdf +++ b/tex/context/base/status-lua.pdf 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-- <p>Not much is happening here.</p> --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-- <p>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.</p> -- 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.</p> 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 |