diff options
author | Karl Berry <karl@freefriends.org> | 2015-04-18 22:52:45 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2015-04-18 22:52:45 +0000 |
commit | 16aa5a7c87f18a2483d0d61795899f886781b51c (patch) | |
tree | 1d72f00b2a4185425393598402fe055c61d1de58 /Master/texmf-dist/tex/context/base/font-nod.lua | |
parent | e68dc4d5506d46bf72823234f902bc76d1f70352 (diff) |
context, from www.pragma-ade.com/context/beta/cont-tmf.zip (18apr15)
git-svn-id: svn://tug.org/texlive/trunk@36923 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/font-nod.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/font-nod.lua | 169 |
1 files changed, 127 insertions, 42 deletions
diff --git a/Master/texmf-dist/tex/context/base/font-nod.lua b/Master/texmf-dist/tex/context/base/font-nod.lua index 8251dc58842..26c736582b1 100644 --- a/Master/texmf-dist/tex/context/base/font-nod.lua +++ b/Master/texmf-dist/tex/context/base/font-nod.lua @@ -11,10 +11,10 @@ if not modules then modules = { } end modules ['font-nod'] = { might become a runtime module instead. This module will be cleaned up!</p> --ldx]]-- -local tonumber, tostring = tonumber, tostring +local tonumber, tostring, rawget = tonumber, tostring, rawget local utfchar = utf.char -local concat = table.concat -local match, gmatch, concat, rep = string.match, string.gmatch, table.concat, string.rep +local concat, fastcopy = table.concat, table.fastcopy +local match, rep = string.match, string.rep local report_nodes = logs.reporter("fonts","tracing") @@ -75,6 +75,7 @@ local copy_node_list = nuts.copy_list local hpack_node_list = nuts.hpack local free_node_list = nuts.flush_list local traverse_nodes = nuts.traverse +local traverse_id = nuts.traverse_id local protect_glyphs = nuts.protect_glyphs local nodepool = nuts.pool @@ -91,6 +92,25 @@ local fontcharacters = hashes.characters local fontproperties = hashes.properties local fontparameters = hashes.parameters +local properties = nodes.properties.data + +-- direct.set_properties_mode(true,false) +-- direct.set_properties_mode(true,true) -- default + +local function freeze(h,where) + -- report_nodes("freezing %s",where) + for n in traverse_nodes(tonut(h)) do -- todo: disc but not traced anyway + local p = properties[n] + if p then + local i = p.injections if i then p.injections = fastcopy(i) end + -- local i = r.preinjections if i then p.preinjections = fastcopy(i) end + -- local i = r.postinjections if i then p.postinjections = fastcopy(i) end + -- local i = r.replaceinjections if i then p.replaceinjections = fastcopy(i) end + -- only injections + end + end +end + function char_tracers.collect(head,list,tag,n) head = tonut(head) n = n or 0 @@ -103,7 +123,7 @@ function char_tracers.collect(head,list,tag,n) ok, fn = false, f end local c = getchar(head) - local i = fontidentifiers[f].indices[c] or 0 + -- local i = fontidentifiers[f].indices[c] or 0 -- zero anyway as indices is nilled if not ok then ok = true n = n + 1 @@ -111,9 +131,28 @@ function char_tracers.collect(head,list,tag,n) list[n][tag] = { } end local l = list[n][tag] - l[#l+1] = { c, f, i } + -- l[#l+1] = { c, f, i } + l[#l+1] = { c, f } elseif id == disc_code then -- skip +-- local replace = getfield(head,"replace") +-- if replace then +-- for n in traverse_id(glyph_code,replace) do +-- l[#l+1] = { c, f } +-- end +-- end +-- local pre = getfield(head,"pre") +-- if pre then +-- for n in traverse_id(glyph_code,pre) do +-- l[#l+1] = { c, f } +-- end +-- end +-- local post = getfield(head,"post") +-- if post then +-- for n in traverse_id(glyph_code,post) do +-- l[#l+1] = { c, f } +-- end +-- end else ok = false end @@ -127,7 +166,8 @@ function char_tracers.equal(ta, tb) else for i=1,#ta do local a, b = ta[i], tb[i] - if a[1] ~= b[1] or a[2] ~= b[2] or a[3] ~= b[3] then + -- if a[1] ~= b[1] or a[2] ~= b[2] or a[3] ~= b[3] then + if a[1] ~= b[1] or a[2] ~= b[2] then return false end end @@ -160,20 +200,20 @@ function char_tracers.unicodes(t,decimal) return concat(tt," ") end -function char_tracers.indices(t,decimal) - local tt = { } - for i=1,#t do - local n = t[i][3] - if n == 0 then - tt[i] = "-" - elseif decimal then - tt[i] = n - else - tt[i] = f_unicode(n) - end - end - return concat(tt," ") -end +-- function char_tracers.indices(t,decimal) +-- local tt = { } +-- for i=1,#t do +-- local n = t[i][3] +-- if n == 0 then +-- tt[i] = "-" +-- elseif decimal then +-- tt[i] = n +-- else +-- tt[i] = f_unicode(n) +-- end +-- end +-- return concat(tt," ") +-- end function char_tracers.start() local npc = handlers.characters -- should accept nuts too @@ -248,7 +288,8 @@ end function step_tracers.glyphs(n,i) local c = collection[i] if c then - local b = hpack_node_list(copy_node_list(c)) -- multiple arguments + local c = copy_node_list(c) + local b = hpack_node_list(c) -- multiple arguments setbox(n,b) end end @@ -311,21 +352,59 @@ function step_tracers.font(command) end end -function step_tracers.codes(i,command) +local colors = { + pre = { "darkred" }, + post = { "darkgreen" }, + replace = { "darkblue" }, +} + +function step_tracers.codes(i,command,space) local c = collection[i] + + local function showchar(c) + if command then + local f, c = getfont(c), getchar(c) + local d = fontdescriptions[f] + local d = d and d[c] + context[command](f,c,d and d.class or "") + else + context("[%s:U+%04X]",getfont(c),getchar(c)) + end + end + + local function showdisc(d,w,what) + if w then + context.startcolor(colors[what]) + context("%s:",what) + for c in traverse_id(glyph_code,w) do + showchar(c) + end + context[space]() + context.stopcolor() + end + end + while c do local id = getid(c) if id == glyph_code then - if command then - local f, c = getfont(c), getchar(c) - local d = fontdescriptions[f] - local d = d and d[c] - context[command](f,c,d and d.class or "") - else - context("[%s:U+%04X]",getfont(c),getchar(c)) - end + showchar(c) elseif id == whatsit_code and (getsubtype(c) == localpar_code or getsubtype(c) == dir_code) then context("[%s]",getfield(c,"dir")) + elseif id == disc_code then + local pre = getfield(c,"pre") + local post = getfield(c,"post") + local replace = getfield(c,"replace") + if pre or post or replace then + context("[") + context[space]() + showdisc(c,pre,"pre") + showdisc(c,post,"post") + showdisc(c,replace,"replace") + context[space]() + context("]") + else + context("[disc]") + end else context("[%s]",nodecodes[id]) end @@ -355,9 +434,11 @@ end function step_tracers.check(head) if collecting then step_tracers.reset() - local n = copy_node_list(tonut(head)) - injections.handler(n,nil,"trace",true) - -- handlers.protectglyphs(n) -- can be option + local h = tonut(head) + local n = copy_node_list(h) + freeze(n,"check") + injections.keepcounts(n) -- one-time + injections.handler(n,"trace") protect_glyphs(n) collection[1] = n end @@ -367,9 +448,11 @@ function step_tracers.register(head) if collecting then local nc = #collection+1 if messages[nc] then - local n = copy_node_list(tonut(head)) - injections.handler(n,nil,"trace",true) - -- handlers.protectglyphs(n) -- can be option + local h = tonut(head) + local n = copy_node_list(h) + freeze(n,"register") + injections.keepcounts(n) -- one-time + injections.handler(n,"trace") protect_glyphs(n) collection[nc] = n end @@ -405,16 +488,18 @@ local function toutf(list,result,nofresult,stopcriterium) if fc then local fcc = fc[c] if fcc then - -- == fromunicode - local u = fcc.tounicode - if u then - for s in gmatch(u,"....") do + local u = fcc.unicode + if not u then + nofresult = nofresult + 1 + result[nofresult] = utfchar(c) + elseif type(u) == "table" then + for i=1,#u do nofresult = nofresult + 1 - result[nofresult] = utfchar(tonumber(s,16)) + result[nofresult] = utfchar(u[i]) end else nofresult = nofresult + 1 - result[nofresult] = utfchar(c) + result[nofresult] = utfchar(u) end else nofresult = nofresult + 1 |