diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/font-otp.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/font-otp.lua | 156 |
1 files changed, 120 insertions, 36 deletions
diff --git a/Master/texmf-dist/tex/context/base/font-otp.lua b/Master/texmf-dist/tex/context/base/font-otp.lua index 3cdc8073720..a80c515ad6e 100644 --- a/Master/texmf-dist/tex/context/base/font-otp.lua +++ b/Master/texmf-dist/tex/context/base/font-otp.lua @@ -8,7 +8,8 @@ if not modules then modules = { } end modules ['font-otp'] = { -- todo: pack math (but not that much to share) -local next = next +local next, type, tostring = next, type, tostring +local sort, concat = table.sort, table.concat local trace_loading = false trackers.register("otf.loading", function(v) trace_loading = v end) @@ -19,6 +20,19 @@ fonts.otf.glists = fonts.otf.glists or { "gsub", "gpos" } local criterium, threshold, tabstr = 1, 0, table.serialize +local function tabstr(t) -- hashed from core-uti / experiment + local s = { } + for k, v in next, t do + if type(v) == "table" then + s[#s+1] = k.."={"..tabstr(v).."}" + else + s[#s+1] = k.."="..tostring(v) + end + end + sort(s) + return concat(s,",") +end + function fonts.otf.enhancers.pack(data) if data then local h, t, c = { }, { }, { } @@ -98,7 +112,13 @@ function fonts.otf.enhancers.pack(data) local pack = (pass == 1 and pack_1) or pack_2 for k, v in next, data.glyphs do v.boundingbox = pack(v.boundingbox) - local l = v.lookups + local l = v.slookups + if l then + for k,v in next, l do + l[k] = pack(v) + end + end + local l = v.mlookups if l then for k,v in next, l do for kk=1,#v do @@ -156,15 +176,21 @@ function fonts.otf.enhancers.pack(data) end local c = vv.coverage if c then - c.before = c.before and pack(c.before ) - c.after = c.after and pack(c.after ) - c.current = c.current and pack(c.current) + local cc = c.before if cc then c.before = pack(cc) end + local cc = c.after if cc then c.after = pack(cc) end + local cc = c.current if cc then c.current = pack(cc) end end local c = vv.reversecoverage if c then - c.before = c.before and pack(c.before ) - c.after = c.after and pack(c.after ) - c.current = c.current and pack(c.current) + local cc = c.before if cc then c.before = pack(cc) end + local cc = c.after if cc then c.after = pack(cc) end + local cc = c.current if cc then c.current = pack(cc) end + end + -- no need to pack vv.glyphs + local c = vv.glyphs + if c then + if c.fore == "" then c.fore = nil end + if c.back == "" then c.back = nil end end end end @@ -250,7 +276,7 @@ function fonts.otf.enhancers.pack(data) if a then v.anchors = pack(a) end - local l = v.lookups + local l = v.mlookups if l then for k,v in next, l do for kk=1,#v do @@ -277,54 +303,101 @@ function fonts.otf.enhancers.unpack(data) if data then local t = data.tables if t then + local unpacked = { } for k, v in next, data.glyphs do local tv = t[v.boundingbox] if tv then v.boundingbox = tv end - local l = v.lookups + local l = v.slookups + if l then + for k,v in next, l do + local tv = t[v] if tv then l[k] = tv end + end + end + local l = v.mlookups if l then for k,v in next, l do for i=1,#v do - local tv = t[v[i]] if tv then v[i] = tv end local vi = v[i] - local what = vi[1] - if what == "pair" then - local tv = t[vi[3]] if tv then vi[3] = tv end - local tv = t[vi[4]] if tv then vi[4] = tv end - elseif what == "position" then - local tv = t[vi[2]] if tv then vi[2] = tv end + local tv = t[vi] + if tv then + v[i] = tv + if unpacked[tv] then + vi = false + else + unpacked[tv], vi = true, tv + end + end + if vi then + local what = vi[1] + if what == "pair" then + local tv = t[vi[3]] if tv then vi[3] = tv end + local tv = t[vi[4]] if tv then vi[4] = tv end + elseif what == "position" then + local tv = t[vi[2]] if tv then vi[2] = tv end + end end end end end local m = v.mykerns if m then - local tv = t[m] if tv then m = tv v.mykerns = m end -- secondary optimization - for k,v in next, m do - local tv = t[v] if tv then m[k] = tv end + local tm = t[m] + if tm then + v.mykerns = tm + if unpacked[tm] then + m = false + else + unpacked[tm], m = true, tm + end + end + if m then + for k,v in next, m do + local tv = t[v] if tv then m[k] = tv end + end end end local m = v.math if m then local mk = m.kerns if mk then - local tv = t[mk] if tv then mk = tv m.kerns = mk end -- secondary optimization - for k,v in next, mk do - local tv = t[v] if tv then mk[k] = tv end + local tm = t[mk] + if tm then + m.kerns = tm + if unpacked[tm] then + mk = false + else + unpacked[tm], mk = true, tm + end + end + if mk then + for k,v in next, mk do + local tv = t[v] if tv then mk[k] = tv end + end end end end local a = v.anchors if a then - local tv = t[a] if tv then a = tv v.anchors = a end -- secondary optimization - for k,v in next, a do - if k == "baselig" then - for kk, vv in next, v do - for kkk=1,#vv do - local tv = t[vv[kkk]] if tv then vv[kkk] = tv end - end - end + local ta = t[a] + if ta then + v.anchors = ta + if not unpacked[ta] then + unpacked[ta], a = true, ta else - for kk, vv in next, v do - local tv = t[vv] if tv then v[kk] = tv end + a = false + end + end + if a then + for k,v in next, a do + if k == "baselig" then + for kk, vv in next, v do + for kkk=1,#vv do + local tv = t[vv[kkk]] if tv then vv[kkk] = tv end + end + end + else + for kk, vv in next, v do + local tv = t[vv] if tv then v[kk] = tv end + end end end end @@ -351,6 +424,7 @@ function fonts.otf.enhancers.unpack(data) cc = c.after if cc then local tv = t[cc] if tv then c.after = tv end end cc = c.current if cc then local tv = t[cc] if tv then c.current = tv end end end + -- no need to unpack vv.glyphs end end end @@ -382,9 +456,19 @@ function fonts.otf.enhancers.unpack(data) end local features = fdata.features if features then - local tv = t[features] if tv then fdata.features = tv features = tv end -- secondary pack - for script, sdata in next, features do - local tv = t[sdata] if tv then features[script] = tv end + local tv = t[features] + if tv then + fdata.features = tv + if not unpacked[tv] then + unpacked[tv], features = true, tv + else + features = false + end + end + if features then + for script, sdata in next, features do + local tv = t[sdata] if tv then features[script] = tv end + end end end end |