diff options
Diffstat (limited to 'tex/context/base/mkiv/font-oup.lua')
-rw-r--r-- | tex/context/base/mkiv/font-oup.lua | 291 |
1 files changed, 234 insertions, 57 deletions
diff --git a/tex/context/base/mkiv/font-oup.lua b/tex/context/base/mkiv/font-oup.lua index 5ee6df505..9f4ded5b5 100644 --- a/tex/context/base/mkiv/font-oup.lua +++ b/tex/context/base/mkiv/font-oup.lua @@ -622,7 +622,7 @@ local function checklookups(fontdata,missing,nofmissing) end end if next(done) then - report("not unicoded: % t",table.sortedkeys(done)) + report("not unicoded: % t",sortedkeys(done)) end end end @@ -1067,13 +1067,14 @@ function readers.pack(data) end end - local function pack_flat(v) - local tag = tabstr_flat(v) + local function pack_normal_cc(v) + local tag = tabstr_normal(v) local ht = h[tag] if ht then c[ht] = c[ht] + 1 return ht else + v[1] = 0 nt = nt + 1 t[nt] = v h[tag] = nt @@ -1082,8 +1083,8 @@ function readers.pack(data) end end - local function pack_boolean(v) - local tag = tabstr_boolean(v) + local function pack_flat(v) + local tag = tabstr_flat(v) local ht = h[tag] if ht then c[ht] = c[ht] + 1 @@ -1127,6 +1128,84 @@ function readers.pack(data) end end + -- saves a lot on noto sans + + -- can be made more clever + + local function pack_boolean(v) + local tag = tabstr_boolean(v) + local ht = h[tag] + if ht then + c[ht] = c[ht] + 1 + return ht + else + nt = nt + 1 + t[nt] = v + h[tag] = nt + c[nt] = 1 + return nt + end + end + + -- -- This was an experiment to see if we can bypass the luajit limits but loading is + -- -- still an issue due to other limits so we don't use this ... actually it can + -- -- prevent a luajittex crash but i don't care too much about that as we can't use + -- -- that engine anyway then. + -- + -- local function check(t) + -- if type(t) == "table" then + -- local s = sortedkeys(t) + -- local n = #s + -- if n <= 10 then + -- return + -- end + -- local ranges = { } + -- local first, last + -- for i=1,#s do + -- local ti = s[i] + -- if not first then + -- first = ti + -- last = ti + -- elseif ti == last + 1 then + -- last = ti + -- elseif last - first < 10 then + -- -- we could permits a few exceptions + -- return + -- else + -- ranges[#ranges+1] = { first, last } + -- first, last = nil, nil + -- end + -- end + -- if #ranges > 0 then + -- return { + -- ranges = ranges + -- } + -- end + -- end + -- end + -- + -- local function pack_boolean(v) + -- local tag + -- local r = check(v) + -- if r then + -- v = r + -- tag = tabstr_normal(v) + -- else + -- tag = tabstr_boolean(v) + -- end + -- local ht = h[tag] + -- if ht then + -- c[ht] = c[ht] + 1 + -- return ht + -- else + -- nt = nt + 1 + -- t[nt] = v + -- h[tag] = nt + -- c[nt] = 1 + -- return nt + -- end + -- end + local function pack_final(v) -- v == number if c[v] <= criterium then @@ -1146,6 +1225,25 @@ function readers.pack(data) end end + local function pack_final_cc(v) + -- v == number + if c[v] <= criterium then + return t[v] + else + -- compact hash + local hv = hh[v] + if hv then + return hv + else + ntt = ntt + 1 + tt[ntt] = t[v] + hh[v] = ntt + cc[ntt] = c[v] + return ntt + end + end + end + local function success(stage,pass) if nt == 0 then if trace_loading or trace_packing then @@ -1192,9 +1290,9 @@ function readers.pack(data) local function packers(pass) if pass == 1 then - return pack_normal, pack_indexed, pack_flat, pack_boolean, pack_mixed + return pack_normal, pack_indexed, pack_flat, pack_boolean, pack_mixed, pack_normal_cc else - return pack_final, pack_final, pack_final, pack_final, pack_final + return pack_final, pack_final, pack_final, pack_final, pack_final, pack_final_cc end end @@ -1212,15 +1310,13 @@ function readers.pack(data) return end - -- - for pass=1,2 do if trace_packing then report_otf("start packing: stage 1, pass %s",pass) end - local pack_normal, pack_indexed, pack_flat, pack_boolean, pack_mixed = packers(pass) + local pack_normal, pack_indexed, pack_flat, pack_boolean, pack_mixed, pack_normal_cc = packers(pass) for unicode, description in next, descriptions do local boundingbox = description.boundingbox @@ -1267,8 +1363,8 @@ function readers.pack(data) else for g1, d1 in next, c do for g2, d2 in next, d1 do - local f = d2[1] if f then d2[1] = pack_indexed(f) end - local s = d2[2] if s then d2[2] = pack_indexed(s) end + local f = d2[1] if f and f ~= true then d2[1] = pack_indexed(f) end + local s = d2[2] if s and s ~= true then d2[2] = pack_indexed(s) end end end end @@ -1280,7 +1376,9 @@ function readers.pack(data) step.coverage = pack_normal(c) else for g1, d1 in next, c do - c[g1] = pack_indexed(d1) + if d1 ~= true then + c[g1] = pack_indexed(d1) + end end end end @@ -1400,7 +1498,7 @@ function readers.pack(data) for i=1,#deltas do local di = deltas[i] local d = di.deltas - local r = di.regions + -- local r = di.regions for j=1,#d do d[j] = pack_indexed(d[j]) end @@ -1440,7 +1538,7 @@ function readers.pack(data) report_otf("start packing: stage 2, pass %s",pass) end - local pack_normal, pack_indexed, pack_flat, pack_boolean, pack_mixed = packers(pass) + local pack_normal, pack_indexed, pack_flat, pack_boolean, pack_mixed, pack_normal_cc = packers(pass) for unicode, description in next, descriptions do local math = description.math @@ -1464,9 +1562,7 @@ function readers.pack(data) if kind == "gpos_pair" then local c = step.coverage if c then - if step.format == "kern" then - -- todo ! - else + if step.format ~= "kern" then for g1, d1 in next, c do for g2, d2 in next, d1 do d1[g2] = pack_normal(d2) @@ -1474,11 +1570,22 @@ function readers.pack(data) end end end --- elseif kind == "gpos_mark2base" or kind == "gpos_mark2mark" or kind == "gpos_mark2ligature" then --- local c = step.baseclasses --- for k, v in next, c do --- c[k] = pack_normal(v) --- end + -- elseif kind == "gpos_cursive" then + -- local c = step.coverage -- new + -- if c then + -- for g1, d1 in next, c do + -- c[g1] = pack_normal_cc(d1) + -- end + -- end + elseif kind == "gpos_mark2ligature" then + local c = step.baseclasses -- new + if c then + for g1, d1 in next, c do + for g2, d2 in next, d1 do + d1[g2] = pack_normal(d2) + end + end + end end local rules = step.rules if rules then @@ -1526,7 +1633,7 @@ function readers.pack(data) report_otf("start packing: stage 3, pass %s",pass) end - local pack_normal, pack_indexed, pack_flat, pack_boolean, pack_mixed = packers(pass) + local pack_normal, pack_indexed, pack_flat, pack_boolean, pack_mixed, pack_normal_cc = packers(pass) local function packthem(sequences) for i=1,#sequences do @@ -1540,18 +1647,23 @@ function readers.pack(data) if kind == "gpos_pair" then local c = step.coverage if c then - if step.format == "kern" then - -- todo ! - else + if step.format ~= "kern" then for g1, d1 in next, c do c[g1] = pack_normal(d1) end end end + elseif kind == "gpos_cursive" then + local c = step.coverage + if c then + for g1, d1 in next, c do + c[g1] = pack_normal_cc(d1) + end + end end end end - end + end end if sequences then @@ -1627,6 +1739,15 @@ function readers.unpack(data) -- end end + -- local function expandranges(t,ranges) + -- for i=1,#ranges do + -- local r = ranges[i] + -- for k=r[1],r[2] do + -- t[k] = true + -- end + -- end + -- end + local function unpackthem(sequences) for i=1,#sequences do local sequence = sequences[i] @@ -1636,6 +1757,19 @@ function readers.unpack(data) local features = sequence.features local flags = sequence.flags local markclass = sequence.markclass + if features then + local tv = tables[features] + if tv then + sequence.features = tv + features = tv + end + for script, feature in next, features do + local tv = tables[feature] + if tv then + features[script] = tv + end + end + end if steps then for i=1,#steps do local step = steps[i] @@ -1689,6 +1823,11 @@ function readers.unpack(data) local c = step.coverage if c then for g1, d1 in next, c do + local tv = tables[d1] + if tv then + d1 = tv + c[g1] = d1 + end local f = tables[d1[2]] if f then d1[2] = f end local s = tables[d1[3]] if s then d1[3] = s end end @@ -1696,12 +1835,6 @@ function readers.unpack(data) elseif kind == "gpos_mark2base" or kind == "gpos_mark2mark" then local c = step.baseclasses if c then --- for k, v in next, c do --- local tv = tables[v] --- if tv then --- c[k] = tv --- end --- end for g1, d1 in next, c do for g2, d2 in next, d1 do local tv = tables[d2] @@ -1723,14 +1856,13 @@ function readers.unpack(data) elseif kind == "gpos_mark2ligature" then local c = step.baseclasses if c then --- for k, v in next, c do --- local tv = tables[v] --- if tv then --- c[k] = tv --- end --- end for g1, d1 in next, c do for g2, d2 in next, d1 do + local tv = tables[d2] -- new + if tv then + d2 = tv + d1[g2] = d2 + end for g3, d3 in next, d2 do local tv = tables[d2[g3]] if tv then @@ -1767,6 +1899,18 @@ function readers.unpack(data) before[i] = tv end end + -- for i=1,#before do + -- local bi = before[i] + -- local tv = tables[bi] + -- if tv then + -- bi = tv + -- before[i] = bi + -- end + -- local ranges = bi.ranges + -- if ranges then + -- expandranges(bi,ranges) + -- end + -- end end local after = rule.after if after then @@ -1781,6 +1925,18 @@ function readers.unpack(data) after[i] = tv end end + -- for i=1,#after do + -- local ai = after[i] + -- local tv = tables[ai] + -- if tv then + -- ai = tv + -- after[i] = ai + -- end + -- local ranges = ai.ranges + -- if ranges then + -- expandranges(ai,ranges) + -- end + -- end end local current = rule.current if current then @@ -1795,6 +1951,18 @@ function readers.unpack(data) current[i] = tv end end + -- for i=1,#current do + -- local ci = current[i] + -- local tv = tables[ci] + -- if tv then + -- ci = tv + -- current[i] = ci + -- end + -- local ranges = ci.ranges + -- if ranges then + -- expandranges(ci,ranges) + -- end + -- end end -- local lookups = rule.lookups -- if lookups then @@ -1814,19 +1982,6 @@ function readers.unpack(data) end end end - if features then - local tv = tables[features] - if tv then - sequence.features = tv - features = tv - end - for script, feature in next, features do - local tv = tables[feature] - if tv then - features[script] = tv - end - end - end if order then local tv = tables[order] if tv then @@ -2140,11 +2295,14 @@ local function checkpairs(lookup) for g1, d1 in next, coverage do for g2, d2 in next, d1 do if d2[2] then + --- true or { a, b, c, d } kerns = false break else local v = d2[1] - if v[1] ~= 0 or v[2] ~= 0 or v[4] ~= 0 then + if v == true then + -- all zero + elseif v and (v[1] ~= 0 or v[2] ~= 0 or v[4] ~= 0) then kerns = false break end @@ -2155,7 +2313,12 @@ local function checkpairs(lookup) report("turning pairs of step %a of %a lookup %a into kerns",i,lookup.type,lookup.name) for g1, d1 in next, coverage do for g2, d2 in next, d1 do - d1[g2] = d2[1][3] + local v = d2[1] + if v == true then + d1[g2] = nil + elseif v then + d1[g2] = v[3] + end end end step.format = "kern" @@ -2185,6 +2348,7 @@ function readers.compact(data) allsteps = allsteps + nofsteps if nofsteps > 1 then local kind = lookup.type + local merg = merged if kind == "gsub_single" or kind == "gsub_alternate" or kind == "gsub_multiple" then merged = merged + mergesteps_1(lookup) elseif kind == "gsub_ligature" then @@ -2200,6 +2364,9 @@ function readers.compact(data) elseif kind == "gpos_mark2mark" or kind == "gpos_mark2base" or kind == "gpos_mark2ligature" then merged = merged + mergesteps_3(lookup) end + if merg ~= merged then + lookup.merged = true + end end end else @@ -2268,7 +2435,7 @@ function readers.expand(data) for i=1,#t do local step = t[i] local coverage = step.coverage - for k, v in next, coverage do + for k in next, coverage do local m = merged[k] if m then m[2] = i @@ -2291,6 +2458,7 @@ function readers.expand(data) local sequence = sequences[i] local steps = sequence.steps if steps then + local nofsteps = sequence.nofsteps setmetatableindex(steps,mergesteps) @@ -2304,7 +2472,14 @@ function readers.expand(data) sequence.markclass = markclasses[markclass] end end - local nofsteps = sequence.nofsteps + local flags = sequence.flags + if flags then + flags[5] = flags[1] ~= false -- otherwise "mark" + or flags[2] ~= false -- otherwise "base" + or flags[3] ~= false -- otherwise "ligature" + or sequence.markclass + or false + end for i=1,nofsteps do local step = steps[i] local baseclasses = step.baseclasses @@ -2373,6 +2548,7 @@ function readers.expand(data) end end if sequence[1] then -- we merge coverage into one + sequence.n = #sequence -- tiny speedup rulesize = rulesize + 1 rulehash[rulesize] = { nofrules, -- 1 @@ -2393,6 +2569,7 @@ function readers.expand(data) end end end + rulehash.n = #rulehash -- tiny speedup end end end |