From 551c89289d267c2d8901f3375e57ed1fe2508de5 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Tue, 2 Oct 2018 23:41:59 +0200 Subject: 2018-10-02 23:25:00 --- tex/generic/context/luatex/luatex-fonts-merged.lua | 467 +++++++++++++++------ 1 file changed, 336 insertions(+), 131 deletions(-) (limited to 'tex/generic') diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index ba46a517f..ccf6d3a7c 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 : c:/data/develop/context/sources/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/sources/luatex-fonts.lua --- merge date : 09/30/18 19:32:19 +-- merge date : 10/02/18 23:17:57 do -- begin closure to overcome local limits and interference @@ -9067,6 +9067,13 @@ if context then --removed end +fonts.privateoffsets={ + textbase=0xF0000, + textextrabase=0xFD000, + mathextrabase=0xFE000, + mathbase=0xFF000, + keepnames=false, +} end -- closure @@ -9137,7 +9144,7 @@ constructors.autocleanup=true constructors.namemode="fullpath" constructors.version=1.01 constructors.cache=containers.define("fonts","constructors",constructors.version,false) -constructors.privateoffset=0xF0000 +constructors.privateoffset=fonts.privateoffsets.textbase or 0xF0000 constructors.cacheintex=true local designsizes=allocate() constructors.designsizes=designsizes @@ -17159,7 +17166,7 @@ if not modules then modules={} end modules ['font-dsp']={ copyright="PRAGMA ADE / ConTeXt Development Team", license="see context related readme files" } -local next,type=next,type +local next,type,tonumber=next,type,tonumber local band=bit32.band local extract=bit32.extract local bor=bit32.bor @@ -17944,8 +17951,9 @@ local function unchainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,n rules=rules, } elseif subtype==3 then - local current=readarray(f) + local nofglyphs=readushort(f) local noflookups=readushort(f) + local current=readcardinaltable(f,nofglyphs,ushort) local lookups=readlookuparray(f,noflookups,#current) current=readcoveragearray(f,tableoffset,current,true) return { @@ -19025,7 +19033,6 @@ do if not rlookups then report_issue(i,what,sequence,"no") elseif not next(rlookups) then - report_issue(i,what,sequence,"empty") rule.lookups=nil else local length=#rlookups @@ -19214,7 +19221,7 @@ do elseif specification.globalkerns then name="globalkern" else - report("ignoring global kern table using gpos kern feature") + report("ignoring global kern table, using gpos kern feature") return end setposition(f,datatable.offset) @@ -20181,8 +20188,15 @@ local sortedkeys=table.sortedkeys local sortedhash=table.sortedhash local tohash=table.tohash local setmetatableindex=table.setmetatableindex -local report=logs.reporter("otf reader") +local report_error=logs.reporter("otf reader","error") +local report_markwidth=logs.reporter("otf reader","markwidth") +local report_cleanup=logs.reporter("otf reader","cleanup") +local report_optimizations=logs.reporter("otf reader","merges") +local report_unicodes=logs.reporter("otf reader","unicodes") local trace_markwidth=false trackers.register("otf.markwidth",function(v) trace_markwidth=v end) +local trace_cleanup=false trackers.register("otf.cleanups",function(v) trace_cleanups=v end) +local trace_optimizations=false trackers.register("otf.optimizations",function(v) trace_optimizations=v end) +local trace_unicodes=false trackers.register("otf.unicodes",function(v) trace_unicodes=v end) local readers=fonts.handlers.otf.readers local privateoffset=fonts.constructors and fonts.constructors.privateoffset or 0xF0000 local f_private=formatters["P%05X"] @@ -20223,6 +20237,7 @@ local function unifyresources(fontdata,indices) if not descriptions or not resources then return end + local nofindices=#indices local variants=fontdata.resources.variants if variants then for selector,unicodes in next,variants do @@ -20238,8 +20253,8 @@ local function unifyresources(fontdata,indices) local u=indices[k] if u then newmarks[u]=v - else - report("discarding mark %i",k) + elseif trace_optimizations then + report_optimizations("discarding mark %i",k) end end return newmarks @@ -20272,18 +20287,28 @@ local function unifyresources(fontdata,indices) if not done[c] then local t={} for k,v in next,c do - t[indices[k]]=v + local ug=indices[k] + if ug then + t[ug]=v + else + report_error("case %i, bad index in unifying %s: %s of %s",1,"coverage",k,nofindices) + end end cover[i]=t done[c]=d end end end - local function recursed(c) + local function recursed(c,kind) local t={} for g,d in next,c do if type(d)=="table" then - t[indices[g]]=recursed(d) + local ug=indices[g] + if ug then + t[ug]=recursed(d,kind) + else + report_error("case %i, bad index in unifying %s: %s of %s",1,kind,g,nofindices) + end else t[g]=indices[d] end @@ -20311,18 +20336,31 @@ local function unifyresources(fontdata,indices) if duplicates then for g1,d1 in next,c do local ug1=indices[g1] - local ud1=indices[d1] - t1[ug1]=ud1 - local dg1=duplicates[ug1] - if dg1 then - for u in next,dg1 do - t1[u]=ud1 + if ug1 then + local ud1=indices[d1] + if ud1 then + t1[ug1]=ud1 + local dg1=duplicates[ug1] + if dg1 then + for u in next,dg1 do + t1[u]=ud1 + end + end + else + report_error("case %i, bad index in unifying %s: %s of %s",3,kind,d1,nofindices) end + else + report_error("case %i, bad index in unifying %s: %s of %s",1,kind,g1,nofindices) end end else for g1,d1 in next,c do - t1[indices[g1]]=indices[d1] + local ug1=indices[g1] + if ug1 then + t1[ug1]=indices[d1] + else + report_error("fuzzy case %i in unifying %s: %i",2,kind,g1) + end end end done[c]=t1 @@ -20336,15 +20374,25 @@ local function unifyresources(fontdata,indices) if not t1 then t1={} for g1,d1 in next,c do - local t2=done[d1] - if not t2 then - t2={} - for g2,d2 in next,d1 do - t2[indices[g2]]=d2 + local ug1=indices[g1] + if ug1 then + local t2=done[d1] + if not t2 then + t2={} + for g2,d2 in next,d1 do + local ug2=indices[g2] + if ug2 then + t2[ug2]=d2 + else + report_error("case %i, bad index in unifying %s: %s of %s",1,kind,g2,nofindices,nofindices) + end + end + done[d1]=t2 end - done[d1]=t2 + t1[ug1]=t2 + else + report_error("case %i, bad index in unifying %s: %s of %s",2,kind,g1,nofindices) end - t1[indices[g1]]=t2 end done[c]=t1 end @@ -20353,7 +20401,7 @@ local function unifyresources(fontdata,indices) elseif kind=="gsub_ligature" then local c=step.coverage if c then - step.coverage=recursed(c) + step.coverage=recursed(c,kind) end elseif kind=="gsub_alternate" or kind=="gsub_multiple" then local c=step.coverage @@ -20364,21 +20412,37 @@ local function unifyresources(fontdata,indices) if duplicates then for g1,d1 in next,c do for i=1,#d1 do - d1[i]=indices[d1[i]] + local d1i=d1[i] + local d1u=indices[d1i] + if d1u then + d1[i]=d1u + else + report_error("case %i, bad index in unifying %s: %s of %s",1,kind,i,d1i,nofindices) + end end local ug1=indices[g1] - t1[ug1]=d1 - local dg1=duplicates[ug1] - if dg1 then - for u in next,dg1 do - t1[u]=copy(d1) + if ug1 then + t1[ug1]=d1 + local dg1=duplicates[ug1] + if dg1 then + for u in next,dg1 do + t1[u]=copy(d1) + end end + else + report_error("case %i, bad index in unifying %s: %s of %s",2,kind,g1,nofindices) end end else for g1,d1 in next,c do for i=1,#d1 do - d1[i]=indices[d1[i]] + local d1i=d1[i] + local d1u=indices[d1i] + if d1u then + d1[i]=d1u + else + report_error("case %i, bad index in unifying %s: %s of %s",2,kind,d1i,nofindices) + end end t1[indices[g1]]=d1 end @@ -20387,6 +20451,41 @@ local function unifyresources(fontdata,indices) end step.coverage=t1 end + elseif kind=="gpos_single" then + local c=step.coverage + if c then + local t1=done[c] + if not t1 then + t1={} + if duplicates then + for g1,d1 in next,c do + local ug1=indices[g1] + if ug1 then + t1[ug1]=d1 + local dg1=duplicates[ug1] + if dg1 then + for u in next,dg1 do + t1[u]=d1 + end + end + else + report_error("case %i, bad index in unifying %s: %s of %s",1,kind,g1,nofindices) + end + end + else + for g1,d1 in next,c do + local ug1=indices[g1] + if ug1 then + t1[ug1]=d1 + else + report_error("case %i, bad index in unifying %s: %s of %s",2,kind,g1,nofindices) + end + end + end + done[c]=t1 + end + step.coverage=t1 + end elseif kind=="gpos_mark2base" or kind=="gpos_mark2mark" or kind=="gpos_mark2ligature" then local c=step.coverage if c then @@ -20394,7 +20493,12 @@ local function unifyresources(fontdata,indices) if not t1 then t1={} for g1,d1 in next,c do - t1[indices[g1]]=d1 + local ug1=indices[g1] + if ug1 then + t1[ug1]=d1 + else + report_error("case %i, bad index in unifying %s: %s of %s",1,kind,g1,nofindices) + end end done[c]=t1 end @@ -20409,7 +20513,12 @@ local function unifyresources(fontdata,indices) if not t2 then t2={} for g2,d2 in next,d1 do - t2[indices[g2]]=d2 + local ug2=indices[g2] + if ug2 then + t2[ug2]=d2 + else + report_error("case %i, bad index in unifying %s: %s of %s",2,kind,g2,nofindices) + end end done[d1]=t2 end @@ -20418,7 +20527,7 @@ local function unifyresources(fontdata,indices) done[c]=c end end - elseif kind=="gpos_single" then + elseif kind=="gpos_cursive" then local c=step.coverage if c then local t1=done[c] @@ -20427,44 +20536,27 @@ local function unifyresources(fontdata,indices) if duplicates then for g1,d1 in next,c do local ug1=indices[g1] - t1[ug1]=d1 - local dg1=duplicates[ug1] - if dg1 then - for u in next,dg1 do - t1[u]=d1 + if ug1 then + t1[ug1]=d1 + local dg1=duplicates[ug1] + if dg1 then + for u in next,dg1 do + t1[u]=copy(d1) + end end + else + report_error("case %i, bad index in unifying %s: %s of %s",1,kind,g1,nofindices) end end else - for g1,d1 in next,c do - t1[indices[g1]]=d1 - end - end - done[c]=t1 - end - step.coverage=t1 - end - elseif kind=="gpos_cursive" then - local c=step.coverage - if c then - local t1=done[c] - if not t1 then - t1={} - if duplicates then for g1,d1 in next,c do local ug1=indices[g1] - t1[ug1]=d1 - local dg1=duplicates[ug1] - if dg1 then - for u in next,dg1 do - t1[u]=copy(d1) - end + if ug1 then + t1[ug1]=d1 + else + report_error("case %i, bad index in unifying %s: %s of %s",2,kind,g1,nofindices) end end - else - for g1,d1 in next,c do - t1[indices[g1]]=d1 - end end done[c]=t1 end @@ -20508,9 +20600,13 @@ local function copyduplicates(fontdata) if not ds or ds.width==0 then if ds then descriptions[0xAD]=nil - report("patching soft hyphen") + if trace_unicodes then + report_unicodes("patching soft hyphen") + end else - report("adding soft hyphen") + if trace_unicodes then + report_unicodes("adding soft hyphen") + end end if not duplicates then duplicates={} @@ -20546,10 +20642,12 @@ local function copyduplicates(fontdata) end n=n+1 end - if n<=m then - report("duplicates: %i : % t",n,t) - else - report("duplicates: %i : % t ...",n,t) + if trace_unicodes then + if n<=m then + report_unicodes("%i : % t",n,t) + else + report_unicodes("%i : % t ...",n,t) + end end else end @@ -20671,7 +20769,9 @@ local function checklookups(fontdata,missing,nofmissing) end end if nofmissing<=0 then - report("all done in %s loops",loops) + if trace_unicodes then + report_unicodes("all missings done in %s loops",loops) + end return elseif old==nofmissing then break @@ -20720,7 +20820,9 @@ local function checklookups(fontdata,missing,nofmissing) recursed(ligatures[i]) end if nofmissing<=0 then - report("all done in %s loops",loops) + if trace_unicodes then + report_unicodes("all missings done in %s loops",loops) + end return elseif old==nofmissing then break @@ -20729,7 +20831,7 @@ local function checklookups(fontdata,missing,nofmissing) t=nil n=0 end - if nofmissing>0 then + if trace_unicodes and nofmissing>0 then local done={} for i,r in next,missing do if r then @@ -20741,7 +20843,7 @@ local function checklookups(fontdata,missing,nofmissing) end end if next(done) then - report("not unicoded: % t",sortedkeys(done)) + report_unicode("not unicoded: % t",sortedkeys(done)) end end end @@ -20764,6 +20866,9 @@ local function unifymissing(fontdata) fonts.mappings.addtounicode(fontdata,fontdata.filename,checklookups) resources.unicodes=nil end +local firstprivate=fonts.privateoffsets.textbase or 0xF0000 +local puafirst=0xE000 +local pualast=0xF8FF local function unifyglyphs(fontdata,usenames) local private=fontdata.private or privateoffset local glyphs=fontdata.glyphs @@ -20786,40 +20891,106 @@ local function unifyglyphs(fontdata,usenames) else indices[0]=zerocode end - for index=1,#glyphs do - local glyph=glyphs[index] - local unicode=glyph.unicode - if not unicode or unicode>=private or (unicode>=0xE000 and unicode<=0xF8FF) or unicode==0xFFFE or unicode==0xFFFF then - unicode=private - if names then + if names then + for index=1,#glyphs do + local glyph=glyphs[index] + local unicode=glyph.unicode + if not unicode then + unicode=private local name=glyph.name or f_private(unicode) indices[index]=name names[name]=unicode - else - indices[index]=unicode - end - private=private+1 - elseif descriptions[unicode] then - report("assigning private unicode %U to glyph indexed %05X (%C)",private,index,unicode) - unicode=private - if names then + private=private+1 + elseif unicode>=firstprivate then + unicode=private + local name=glyph.name or f_private(unicode) + indices[index]=name + names[name]=unicode + private=private+1 + elseif unicode>=puafirst and unicode<=pualast then + local name=glyph.name or f_private(unicode) + indices[index]=name + names[name]=unicode + elseif descriptions[unicode] then + unicode=private local name=glyph.name or f_private(unicode) indices[index]=name names[name]=unicode + private=private+1 else - indices[index]=unicode - end - private=private+1 - else - if names then local name=glyph.name or f_unicode(unicode) indices[index]=name names[name]=unicode + end + descriptions[unicode]=glyph + end + elseif trace_unicodes then + for index=1,#glyphs do + local glyph=glyphs[index] + local unicode=glyph.unicode + if not unicode then + unicode=private + indices[index]=unicode + private=private+1 + elseif unicode>=firstprivate then + local name=glyph.name + if name then + report_unicodes("moving glyph %a indexed %05X from private %U to %U ",name,index,unicode,private) + else + report_unicodes("moving glyph indexed %05X from private %U to %U ",index,unicode,private) + end + unicode=private + indices[index]=unicode + private=private+1 + elseif unicode>=puafirst and unicode<=pualast then + local name=glyph.name + if name then + report_unicodes("keeping private unicode %U for glyph %a indexed %05X",unicode,name,index) + else + report_unicodes("keeping private unicode %U for glyph indexed %05X",unicode,index) + end + indices[index]=unicode + elseif descriptions[unicode] then + local name=glyph.name + if name then + report_unicodes("assigning duplicate unicode %U to %U for glyph %a indexed %05X ",unicode,private,name,index) + else + report_unicodes("assigning duplicate unicode %U to %U for glyph indexed %05X ",unicode,private,index) + end + unicode=private + indices[index]=unicode + private=private+1 else indices[index]=unicode end + descriptions[unicode]=glyph + end + else + for index=1,#glyphs do + local glyph=glyphs[index] + local unicode=glyph.unicode + if not unicode then + unicode=private + indices[index]=unicode + private=private+1 + elseif unicode>=firstprivate then + local name=glyph.name + unicode=private + indices[index]=unicode + private=private+1 + elseif unicode>=puafirst and unicode<=pualast then + local name=glyph.name + indices[index]=unicode + elseif descriptions[unicode] then + local name=glyph.name + unicode=private + indices[index]=unicode + private=private+1 + else + indices[index]=unicode + end + descriptions[unicode]=glyph end - descriptions[unicode]=glyph end for index=1,#glyphs do local math=glyphs[index].math @@ -20863,28 +21034,39 @@ local function unifyglyphs(fontdata,usenames) end local p_bogusname=( (P("uni")+P("UNI")+P("Uni")+P("U")+P("u"))*S("Xx")^0*R("09","AF")^1+(P("identity")+P("Identity")+P("IDENTITY"))*R("09","AF")^1+(P("index")+P("Index")+P("INDEX"))*R("09")^1 -)*P(-1) +)*(P(-1)+P(".")) local function stripredundant(fontdata) local descriptions=fontdata.descriptions if descriptions then local n=0 local c=0 - for unicode,d in next,descriptions do - local name=d.name - if name and lpegmatch(p_bogusname,name) then - d.name=nil - n=n+1 + if not context and fonts.privateoffsets.keepnames then + for unicode,d in next,descriptions do + if d.class=="base" then + d.class=nil + c=c+1 + end end - if d.class=="base" then - d.class=nil - c=c+1 + else + for unicode,d in next,descriptions do + local name=d.name + if name and lpegmatch(p_bogusname,name) then + d.name=nil + n=n+1 + end + if d.class=="base" then + d.class=nil + c=c+1 + end end end - if n>0 then - report("%s bogus names removed (verbose unicode)",n) - end - if c>0 then - report("%s base class tags removed (default is base)",c) + if trace_cleanup then + if n>0 then + report_cleanup("%s bogus names removed (verbose unicode)",n) + end + if c>0 then + report_cleanup("%s base class tags removed (default is base)",c) + end end end end @@ -21973,12 +22155,16 @@ local function mergesteps_1(lookup,strict) local f=first.format for i=2,nofsteps do if steps[i].format~=f then - report("not merging %a steps of %a lookup %a, different formats",nofsteps,lookup.type,lookup.name) + if trace_optimizations then + report_optimizations("not merging %a steps of %a lookup %a, different formats",nofsteps,lookup.type,lookup.name) + end return 0 end end end - report("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name) + if trace_optimizations then + report_optimizations("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name) + end local target=first.coverage for i=2,nofsteps do local c=steps[i].coverage @@ -22003,12 +22189,16 @@ local function mergesteps_2(lookup) local f=first.format for i=2,nofsteps do if steps[i].format~=f then - report("not merging %a steps of %a lookup %a, different formats",nofsteps,lookup.type,lookup.name) + if trace_optimizations then + report_optimizations("not merging %a steps of %a lookup %a, different formats",nofsteps,lookup.type,lookup.name) + end return 0 end end end - report("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name) + if trace_optimizations then + report_optimizations("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name) + end local target=first.coverage for i=2,nofsteps do local c=steps[i].coverage @@ -22035,7 +22225,9 @@ end local function mergesteps_3(lookup,strict) local steps=lookup.steps local nofsteps=lookup.nofsteps - report("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name) + if trace_optimizations then + report_optimizations("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name) + end local coverage={} for i=1,nofsteps do local c=steps[i].coverage @@ -22043,7 +22235,9 @@ local function mergesteps_3(lookup,strict) for k,v in next,c do local tk=coverage[k] if tk then - report("quitting merge due to multiple checks") + if trace_optimizations then + report_optimizations("quitting merge due to multiple checks") + end return nofsteps else coverage[k]=v @@ -22090,7 +22284,9 @@ local function mergesteps_4(lookup) local steps=lookup.steps local nofsteps=lookup.nofsteps local first=steps[1] - report("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name) + if trace_optimizations then + report_optimizations("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name) + end local target=first.coverage for i=2,nofsteps do local c=steps[i].coverage @@ -22113,7 +22309,9 @@ local function mergesteps_5(lookup) local steps=lookup.steps local nofsteps=lookup.nofsteps local first=steps[1] - report("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name) + if trace_optimizations then + report_optimizations("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name) + end local target=first.coverage local hash=nil for k,v in next,target do @@ -22162,7 +22360,9 @@ local function checkkerns(lookup) end end if kerns then - report("turning pairs of step %a of %a lookup %a into kerns",i,lookup.type,lookup.name) + if trace_optimizations then + report_optimizations("turning pairs of step %a of %a lookup %a into kerns",i,lookup.type,lookup.name) + end local c={} for g1,d1 in next,coverage do if d1 and d1~=true then @@ -22203,7 +22403,9 @@ local function checkpairs(lookup) if step.format=="pair" then local coverage=onlykerns(step) if coverage then - report("turning pairs of step %a of %a lookup %a into kerns",i,lookup.type,lookup.name) + if trace_optimizations then + report_optimizations("turning pairs of step %a of %a lookup %a into kerns",i,lookup.type,lookup.name) + end for g1,d1 in next,coverage do local d={} for g2,d2 in next,d1 do @@ -22319,17 +22521,19 @@ function readers.compact(data) end end end - else - report("no lookups in %a",what) + elseif trace_optimizations then + report_optimizations("no lookups in %a",what) end end compact("sequences") compact("sublookups") - if merged>0 then - report("%i steps of %i removed due to merging",merged,allsteps) - end - if kerned>0 then - report("%i steps of %i steps turned from pairs into kerns",kerned,allsteps) + if trace_optimizations then + if merged>0 then + report_optimizations("%i steps of %i removed due to merging",merged,allsteps) + end + if kerned>0 then + report_optimizations("%i steps of %i steps turned from pairs into kerns",kerned,allsteps) + end end end local function mergesteps(t,k) @@ -22420,7 +22624,7 @@ function readers.expand(data) if not wd then d.width=defaultwidth elseif trace_markwidth and wd~=0 and d.class=="mark" then - report("mark %a with width %b found in %a",d.name or "",wd,basename) + report_markwidth("mark %a with width %b found in %a",d.name or "",wd,basename) end if bb then local ht=bb[4] @@ -22600,7 +22804,7 @@ local trace_defining=false registertracker("fonts.defining",function(v) trace_de local report_otf=logs.reporter("fonts","otf loading") local fonts=fonts local otf=fonts.handlers.otf -otf.version=3.105 +otf.version=3.106 otf.cache=containers.define("fonts","otl",otf.version,true) otf.svgcache=containers.define("fonts","svg",otf.version,true) otf.sbixcache=containers.define("fonts","sbix",otf.version,true) @@ -22676,7 +22880,7 @@ function otf.load(filename,sub,instance) end if reload then report_otf("loading %a, hash %a",filename,hash) - starttiming(otfreaders) + starttiming(otfreaders,true) data=otfreaders.loadfont(filename,sub or 1,instance) if data then local used=checkmemory() @@ -22759,6 +22963,7 @@ function otf.load(filename,sub,instance) checkmemory(used,threshold,tracememory) end else + stoptiming(otfreaders) data=nil report_otf("loading failed due to read error") end -- cgit v1.2.3