From 4272a26c49cbfee8917e5272fc0f964cbcfc4b03 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Mon, 14 Jun 2021 17:36:45 +0200 Subject: 2021-06-14 17:09:00 --- tex/context/base/mkii/cont-new.mkii | 2 +- tex/context/base/mkii/context.mkii | 2 +- tex/context/base/mkii/mult-it.mkii | 4 ++ tex/context/base/mkiv/cont-new.mkiv | 2 +- tex/context/base/mkiv/context.mkiv | 2 +- tex/context/base/mkiv/font-shp.lua | 2 +- tex/context/base/mkiv/font-ttf.lua | 10 +-- tex/context/base/mkiv/status-files.pdf | Bin 23967 -> 23588 bytes tex/context/base/mkiv/status-lua.pdf | Bin 230184 -> 246757 bytes tex/context/base/mkxl/cont-new.mkxl | 2 +- tex/context/base/mkxl/context.mkxl | 2 +- tex/context/base/mkxl/font-con.lmt | 3 + tex/context/base/mkxl/font-ogr.lmt | 42 +---------- tex/context/base/mkxl/lpdf-emb.lmt | 125 ++++++++++++++++++--------------- tex/context/base/mkxl/lpdf-lmt.lmt | 80 ++++++++++++++------- tex/context/interface/mkii/keys-it.xml | 4 ++ 16 files changed, 149 insertions(+), 133 deletions(-) (limited to 'tex/context') diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii index 473c0782c..090a16912 100644 --- a/tex/context/base/mkii/cont-new.mkii +++ b/tex/context/base/mkii/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2021.06.13 19:18} +\newcontextversion{2021.06.14 17:06} %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/mkii/context.mkii b/tex/context/base/mkii/context.mkii index a1679d905..96fe2716a 100644 --- a/tex/context/base/mkii/context.mkii +++ b/tex/context/base/mkii/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2021.06.13 19:18} +\edef\contextversion{2021.06.14 17:06} %D For those who want to use this: diff --git a/tex/context/base/mkii/mult-it.mkii b/tex/context/base/mkii/mult-it.mkii index 4a4676f68..a1f572ef5 100644 --- a/tex/context/base/mkii/mult-it.mkii +++ b/tex/context/base/mkii/mult-it.mkii @@ -141,6 +141,7 @@ \setinterfacevariable{chemistry}{chemistry} \setinterfacevariable{cite}{cite} \setinterfacevariable{closed}{closed} +\setinterfacevariable{collapsed}{collapsed} \setinterfacevariable{color}{colore} \setinterfacevariable{column}{colonna} \setinterfacevariable{columns}{colonne} @@ -392,6 +393,7 @@ \setinterfacevariable{nostopper}{nostopper} \setinterfacevariable{not}{non} \setinterfacevariable{notation}{notation} +\setinterfacevariable{notcollapsed}{notcollapsed} \setinterfacevariable{note}{note} \setinterfacevariable{nothanging}{nonsospeso} \setinterfacevariable{nothyphenated}{nonsillabato} @@ -761,6 +763,7 @@ \setinterfaceconstant{coupling}{accoppiamento} \setinterfaceconstant{couplingway}{modoaccoppiamento} \setinterfaceconstant{criterium}{criterio} +\setinterfaceconstant{crop}{crop} \setinterfaceconstant{cropoffset}{cropoffset} \setinterfaceconstant{crossreference}{crossreference} \setinterfaceconstant{cssfile}{cssfile} @@ -1262,6 +1265,7 @@ \setinterfaceconstant{symbolset}{setsimboli} \setinterfaceconstant{symcolor}{coloresimbolo} \setinterfaceconstant{symstyle}{stilesimbolo} +\setinterfaceconstant{synchronize}{synchronize} \setinterfaceconstant{synonym}{sinonimo} \setinterfaceconstant{synonymcolor}{coloresinonimi} \setinterfaceconstant{synonymcommand}{synonymcommand} diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index 7f44775d5..29bb55997 100644 --- a/tex/context/base/mkiv/cont-new.mkiv +++ b/tex/context/base/mkiv/cont-new.mkiv @@ -13,7 +13,7 @@ % \normalend % uncomment this to get the real base runtime -\newcontextversion{2021.06.13 19:18} +\newcontextversion{2021.06.14 17:06} %D This file is loaded at runtime, thereby providing an excellent place for hacks, %D patches, extensions and new features. There can be local overloads in cont-loc diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv index 72383f353..4e6e0dcb9 100644 --- a/tex/context/base/mkiv/context.mkiv +++ b/tex/context/base/mkiv/context.mkiv @@ -45,7 +45,7 @@ %D {YYYY.MM.DD HH:MM} format. \edef\contextformat {\jobname} -\edef\contextversion{2021.06.13 19:18} +\edef\contextversion{2021.06.14 17:06} %D Kind of special: diff --git a/tex/context/base/mkiv/font-shp.lua b/tex/context/base/mkiv/font-shp.lua index ecf0c9418..145c4e0e4 100644 --- a/tex/context/base/mkiv/font-shp.lua +++ b/tex/context/base/mkiv/font-shp.lua @@ -346,7 +346,7 @@ local function getstreamhash(fontid) local fontdata = identifiers[fontid] if fontdata then local properties = fontdata.properties - return makehash(properties.filename,properties.subfont,properties.instance) + return makehash(properties.filename,properties.subfont,properties.instance), fontdata end end diff --git a/tex/context/base/mkiv/font-ttf.lua b/tex/context/base/mkiv/font-ttf.lua index 8573d3a06..69b202b3c 100644 --- a/tex/context/base/mkiv/font-ttf.lua +++ b/tex/context/base/mkiv/font-ttf.lua @@ -136,10 +136,12 @@ local function mergecomposites(glyphs,shapes) local y = p[2] nofpoints = nofpoints + 1 points[nofpoints] = { --- xscale * x + xrotate * y + xoffset, --- yscale * y + yrotate * x + yoffset, - xscale * x + yrotate * y + xoffset, - xrotate * x + yscale * y + yoffset, + -- unifractur : u n + -- seguiemj : 0x270E 0x2710 + xscale * x + xrotate * y + xoffset, + yscale * y + yrotate * x + yoffset, +-- xscale * x + yrotate * y + xoffset, +-- xrotate * x + yscale * y + yoffset, p[3] } end diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf index 8916a3b56..2558e805e 100644 Binary files a/tex/context/base/mkiv/status-files.pdf and b/tex/context/base/mkiv/status-files.pdf differ diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf index 5c91aa4fe..dcbc15681 100644 Binary files a/tex/context/base/mkiv/status-lua.pdf and b/tex/context/base/mkiv/status-lua.pdf differ diff --git a/tex/context/base/mkxl/cont-new.mkxl b/tex/context/base/mkxl/cont-new.mkxl index afcb20d11..da3244da2 100644 --- a/tex/context/base/mkxl/cont-new.mkxl +++ b/tex/context/base/mkxl/cont-new.mkxl @@ -13,7 +13,7 @@ % \normalend % uncomment this to get the real base runtime -\newcontextversion{2021.06.13 19:18} +\newcontextversion{2021.06.14 17:06} %D This file is loaded at runtime, thereby providing an excellent place for hacks, %D patches, extensions and new features. There can be local overloads in cont-loc diff --git a/tex/context/base/mkxl/context.mkxl b/tex/context/base/mkxl/context.mkxl index ba4dc20e1..d51a92236 100644 --- a/tex/context/base/mkxl/context.mkxl +++ b/tex/context/base/mkxl/context.mkxl @@ -29,7 +29,7 @@ %D {YYYY.MM.DD HH:MM} format. \immutable\edef\contextformat {\jobname} -\immutable\edef\contextversion{2021.06.13 19:18} +\immutable\edef\contextversion{2021.06.14 17:06} %overloadmode 1 % check frozen / warning %overloadmode 2 % check frozen / error diff --git a/tex/context/base/mkxl/font-con.lmt b/tex/context/base/mkxl/font-con.lmt index bebc4e498..25aa9b1bc 100644 --- a/tex/context/base/mkxl/font-con.lmt +++ b/tex/context/base/mkxl/font-con.lmt @@ -557,6 +557,9 @@ function constructors.scale(tfmdata,specification) -- for unicode, character in next, characters do local chr, description, index + + -- todo: add description entry to char entry instead of index ... saves elsewhere too + if changed then local c = changed[unicode] if c and c ~= unicode then diff --git a/tex/context/base/mkxl/font-ogr.lmt b/tex/context/base/mkxl/font-ogr.lmt index 1f930c78d..ef0af904c 100644 --- a/tex/context/base/mkxl/font-ogr.lmt +++ b/tex/context/base/mkxl/font-ogr.lmt @@ -38,7 +38,7 @@ otf.pngenabled = true do - -- This is a prelude to something better but I'm still experimenting. + -- This is a prelude to something better but I'm still experimenting. We should delay more. local dropins = { } fonts.dropins = dropins @@ -122,46 +122,6 @@ do end end --- function dropins.swap(method,tfmdata,shapes,...) -- by unicode --- if method and shapes then --- local characters = tfmdata.characters --- local descriptions = tfmdata.descriptions --- local droppedin, tfmdrop, dropchars, dropdescs, colrshapes --- local idx = 255 --- local slot = 0 --- -- we can have a variant where shaped are by unicode and not by index --- for k, v in next, characters do --- local description = descriptions[k] --- if description then --- local shape = shapes[k] --- if shape then --- if idx >= 255 then --- idx = 1 --- colrshapes = setmetatableindex({ },shapes) --- slot, droppedin, tfmdrop = dropins.provide(method,tfmdata,colrshapes) --- dropchars = tfmdrop.characters --- dropdescs = tfmdrop.descriptions --- else --- idx = idx + 1 --- end --- colrshapes[idx] = shape -- so not: description --- -- todo: prepend --- v.commands = { { "slot", slot, idx } } --- -- hack to prevent that type 3 also gets 'use' flags .. todo --- local c = { commands = false, index = idx, dropin = tfmdrop } --- local d = { } -- index = idx, dropin = tfmdrop } --- setmetatableindex(c,v) --- setmetatableindex(d,description) --- dropchars[idx] = c --- dropdescs[idx] = d -- not needed --- end --- end --- end --- else --- -- error --- end --- end - function dropins.swap(method,tfmdata,shapes) -- by unicode if method and shapes then local characters = tfmdata.characters diff --git a/tex/context/base/mkxl/lpdf-emb.lmt b/tex/context/base/mkxl/lpdf-emb.lmt index f66753e9b..fd0f0cf6b 100644 --- a/tex/context/base/mkxl/lpdf-emb.lmt +++ b/tex/context/base/mkxl/lpdf-emb.lmt @@ -70,7 +70,8 @@ local dimenfactors = number.dimenfactors local bpfactor = dimenfactors.bp local ptfactor = dimenfactors.pt -trackers.register("backend.pdf.fonts",function(v) trace_fonts = v end) +trackers.register("backend.fonts", function(v) trace_fonts = v end) +trackers.register("backend.fonts.details",function(v) trace_details = v end) local readers = fonts.handlers.otf.readers local getinfo = readers.getinfo @@ -236,22 +237,19 @@ end return widths end - collectindices = function(descriptions,indices,used) + -- we need to go through indices because descriptions can be different (take + -- basemode remappings) + + collectindices = function(descriptions,indices,used,hash) local minindex = 0xFFFF local maxindex = 0 local reverse = { } local copies = { } - -- todo: already at definition time trigger copying streams - -- and add extra indices ... first i need a good example of - -- a clash - -- for unicode, data in next, descriptions do - -- local i = data.index or unicode - -- if reverse[i] then - -- print("CLASH") - -- else - -- reverse[i] = data - -- end - -- end + local include = { } + local resolved = { } + + setmetatable(used,nil) -- prevent more index allocations + for unicode, data in next, descriptions do local index = data.index reverse[index or unicode] = data @@ -259,22 +257,31 @@ end copies[index] = data.dupindex end end - for index in next, indices do - if index > maxindex then - maxindex = index + for index, usedindex in next, indices do + if usedindex > maxindex then + maxindex = usedindex end - if index < minindex then - minindex = index + if usedindex < minindex then + minindex = usedindex end - indices[index] = reverse[index] + include[usedindex] = copies[index] or index + resolved[usedindex] = reverse[index] end if minindex > maxindex then minindex = maxindex end - -- if next(copies) then - -- inspect(copies) - -- end - return indices, copies, minindex, maxindex + if trace_details then + report_fonts("embedded: hash %a, minindex %i, maxindex %i",hash,minindex,maxindex) + for k, v in sortedhash(include) do + local d = resolved[k] + if d.dupindex then + report_fonts(" 0x%04X : 0x%04X (duplicate 0x%05X)",k,v,d.index) + else + report_fonts(" 0x%04X : 0x%04X",k,v) + end + end + end + return resolved, include, minindex, maxindex end includecidset = false @@ -712,9 +719,9 @@ do local indices = details.indices local metabbox = { fontheader.xmin, fontheader.ymin, fontheader.xmax, fontheader.ymax } local indices, - copies, + include, minindex, - maxindex = collectindices(descriptions,indices,details.used) + maxindex = collectindices(descriptions,indices,details.used,details.hash) local glyphstreams = tablecreators.glyf(fontfile) local locations = tablecreators.loca(fontfile) local horizontals = tablecreators.hmtx(fontfile) @@ -747,7 +754,7 @@ do report_fonts("missing .notdef in font %a",basefontname) end -- todo: use a rep for h/v - for index=1,minindex-1 do + for index=1,minindex-1 do -- no needed in new low range locations[index] = lastoffset h = h + 1 ; horizontals[h] = zero4 if vertical then @@ -755,17 +762,12 @@ do end end end + for index=minindex,maxindex do locations[index] = lastoffset local data = indices[index] if data then - local blob = blobs[index] -- we assume padding - if not blob then - local copy = copies[index] - if copy then - blob = blobs[copy] - end - end + local blob = blobs[include[index]] -- we assume padding if blob and #blob > 0 then g = g + 1 ; glyphstreams[g] = blob h = h + 1 ; horizontals [h] = tocardinal2(data.width or 0) @@ -790,6 +792,7 @@ do end end end + locations[maxindex+1] = lastoffset -- cf spec -- local nofglyphs = maxindex + 1 -- include zero @@ -878,7 +881,7 @@ do StemV = scale(stemv), XHeight = scale(xheight), FontFile2 = pdfreference(pdfflushstreamobject(fontdata)), - CIDSet = tocidset, +-- CIDSet = tocidset, Metadata = fontmeta and pdfreference(pdfflushstreamobject(fontmeta)) or nil, } local parent = pdfdictionary { @@ -1278,7 +1281,7 @@ do .. tocardinal2(0) -- first gid .. tocardinal1(0) -- fd index -- entry 2 --- .. tocardinal2(fontfile.sparsemax-1) -- sentinel + -- .. tocardinal2(fontfile.sparsemax-1) -- sentinel .. tocardinal2(fontfile.sparsemax) -- sentinel -- fdselectoffset = todictoffset(offset) @@ -1338,7 +1341,7 @@ do local blobs = streams.streams local fontheader = streams.fontheader local maximumprofile = streams.maximumprofile - local names = streams.names + local names = streams.names -- not used local descriptions = details.rawdata.descriptions local metadata = details.rawdata.metadata local indices = details.indices @@ -1357,13 +1360,12 @@ do correction = correction * bpfactor / ptfactor metadata = { } end - -- - local indices, - copies, + include, minindex, - maxindex = collectindices(descriptions,indices,details.used) + maxindex = collectindices(descriptions,indices,details.used,details.hash) + local streamoffset = 0 local glyphstreams, charmappings = tablecreators.cff(fontfile) @@ -1383,15 +1385,11 @@ do if minindex == 0 then minindex = 1 end + -- for index=minindex,maxindex do - if indices[index] then - local blob = blobs[index] - if not blob then - local copy = copies[index] - if copy then - blob = blobs[copy] - end - end + local idx = include[index] + if idx then + local blob = blobs[idx] if not blob then blob = "\14" end @@ -1437,7 +1435,7 @@ do if stemv then stemv = (stemv/65)^2 + 50 else --- stemv = 2 + -- stemv = 2 end -- local function scale(n) @@ -1855,6 +1853,10 @@ do end end + -- we register way too much ... we can delay the t3 definition + + local usedcharacters = lpdf.usedcharacters + function methods.color(filename,details) local colrshapes = details.properties.indexdata[1] local colrvalues = details.properties.indexdata[2] @@ -1868,6 +1870,7 @@ do local dropunits = dropdata.parameters.units -- shared local descriptions = dropdata.descriptions local directcolors = registercolors(colrvalues) + local fontslots = usedcharacters[dropid] usedfonts[dropid] = dropid local w = description.width or 0 local s = #colorlist @@ -1888,10 +1891,14 @@ do end local e = descriptions[entry.slot] if e then - n = n + 1 ; t[n] = f_char(dropid,e.index) + n = n + 1 ; t[n] = f_char(dropid,fontslots[e.index]) end end - return concat(t," "), w / dropunits + -- we're not going to hash this ... could be done if needed (but who mixes different + -- color schemes ...) + t = concat(t," ") + -- print(t) + return t, w / dropunits end end local function getresources() @@ -1921,9 +1928,9 @@ do local factor = parameters.factor -- normally 1 local fontmatrix = pdfarray { scalefactor, 0, 0, scalefactor, 0, 0 } local indices, - copies, + include, minindex, - maxindex = collectindices(details.fontdata.characters,details.indices,details.used) + maxindex = collectindices(details.fontdata.characters,details.indices,details.used,details.hash) local widths = pdfarray() local differences = pdfarray() local charprocs = pdfdictionary() @@ -1953,7 +1960,7 @@ do for index, data in sortedhash(indices) do local name = f_index(index) - local glyph = glyphs[index] + local glyph = glyphs[include[index]] if glyph then local stream, width = glyphtopdf(glyph,data) if stream then @@ -2078,6 +2085,12 @@ function lpdf.flushfonts() statistics.starttiming(objects) + -- We loop over used characters (old approach, when we wanted to be equivalent wrt + -- indices with luatex) but can also decide to use usedindices. However, we then + -- don't have the id. + + -- we can combine the two for loops .. todo + for fontid, used in sortedhash(lpdf.usedcharacters) do -- for a bitmap we need a different hash unless we stick to a fixed high @@ -2132,8 +2145,8 @@ function lpdf.flushfonts() end if parent then local indices = parent.indices - for k in next, used do - indices[k] = true + for k, v in next, used do + indices[k] = v end end end diff --git a/tex/context/base/mkxl/lpdf-lmt.lmt b/tex/context/base/mkxl/lpdf-lmt.lmt index ca7e70945..3c9877008 100644 --- a/tex/context/base/mkxl/lpdf-lmt.lmt +++ b/tex/context/base/mkxl/lpdf-lmt.lmt @@ -7,17 +7,17 @@ if not modules then modules = { } end modules ['lpdf-lmt'] = { license = "see context related readme files" } --- The code below was originally in back-lpd.lua but it makes more sense in --- this namespace. I will rename variables. --- --- There is no way that a lua based backend can compete with the original one --- for relative simple text runs. And we're talking seconds here on say 500 --- pages with paragraphs alternativng between three fonts and colors. But such +-- The code below was originally in back-lpd.lua but it makes more sense in this +-- namespace. I will rename variables. + +-- There is no way that a lua based backend can compete performance wise with the +-- original one for relative simple text runs. And we're talking seconds here on say +-- 500 pages with paragraphs alternativng between three fonts and colors. But such -- documents are rare so in practice we are quite okay, especially because in --- ConTeXt we can gain quite a bit elsewhere. So, when we loose 30% on such --- simple documents, we break even on for instance the manual, and gain 30% on --- Thomas's turture test (also for other reasons). But .. who knows what magic --- I can cook up in due time. +-- ConTeXt we can gain quite a bit elsewhere. So, when we loose 30% on such simple +-- documents, we break even on for instance the manual, and gain 30% on Thomas's +-- turture test (also for other reasons). But .. who knows what magic I can cook up +-- in due time. -- If you consider this complex, watch: -- @@ -87,9 +87,11 @@ local properties = fonthashes.properties local report = logs.reporter("backend") local report_objects = logs.reporter("backend","objects") +local report_fonts = logs.reporter("backend","fonts") -local trace_objects = false trackers.register("backend.objects", function(v) trace_objects = v end) -local trace_details = false trackers.register("backend.details", function(v) trace_details = v end) +local trace_objects = false trackers.register("backend.objects", function(v) trace_objects = v end) +local trace_details = false trackers.register("backend.details", function(v) trace_details = v end) +local trace_indices = false trackers.register("backend.fonts.details", function(v) trace_indices = v end) -- experiment: @@ -186,17 +188,52 @@ local fontcharacters local fontdescriptions local fontparameters local fontproperties -local usedcharacters = setmetatableindex("table") local pdfcharacters +local getstreamhash = fonts.handlers.otf.getstreamhash + +local usedfontstreams = { } + +local usedindices = setmetatableindex(function(t,k) + local n = 0 + local v = setmetatableindex(function(tt,kk) + if n >= 0xFFFF then + report_fonts("registering character index: overflow in hash %a, todo: use overflow font") + else + n = n + 1 + end + if trace_indices then + report_fonts("registering character index: hash %a, charindex 0x%05X, slotindex 0x%04X",k,kk,n) + end + local vv = n + tt[kk] = vv + return vv + end) + t[k] = v + return v +end) + +local usedcharacters = setmetatableindex(function(t,k) + local h, d = getstreamhash(k) + if trace_indices then + report_fonts("registering index table: hash %a, fontid %i",h,k) + end + usedfontstreams[h] = d + local v = usedindices[h] + t[k] = v + return v +end) + +lpdf.usedfontstreams = usedfontstreams -- [streamhash] -> fontdata +lpdf.usedcharacters = usedcharacters -- [fontid] -> indices +lpdf.usedindices = usedindices -- [streamhash][index] -> realindex (can also be dupindex) + local horizontalmode = true local scalefactor = 1 local threshold = 655360 local thresfactor = 100 local tjfactor = 100 / 65536 -lpdf.usedcharacters = usedcharacters - function flushers.updatefontstate(font) fontcharacters = characters[font] fontdescriptions = descriptions[font] @@ -651,22 +688,15 @@ do cw = cw + naturalwidth[char] * tmef * f_x_scale - local index = data.index or char + local slot = pdfcharacters[data.index or char] -- registers usage - b = b + 1 ; buffer[b] = font > 0 and h_hex_4[index] or h_hex_2[index] - - if not pdfcharacters[index] then - pdfcharacters[index] = true - end + b = b + 1 ; buffer[b] = font > 0 and h_hex_4[slot] or h_hex_2[slot] end flushers.fontchar = function(font,char,data) local dummy = usedfonts[font] - local index = data.index or char - if not pdfcharacters[index] then - pdfcharacters[index] = true - end + local slot = pdfcharacters[data.index or char] -- registers usage return dummy end diff --git a/tex/context/interface/mkii/keys-it.xml b/tex/context/interface/mkii/keys-it.xml index f45b5a574..43db8cfc1 100644 --- a/tex/context/interface/mkii/keys-it.xml +++ b/tex/context/interface/mkii/keys-it.xml @@ -144,6 +144,7 @@ + @@ -395,6 +396,7 @@ + @@ -767,6 +769,7 @@ + @@ -1268,6 +1271,7 @@ + -- cgit v1.2.3