diff options
Diffstat (limited to 'tex/context/base/mkiv/spac-chr.lua')
-rw-r--r-- | tex/context/base/mkiv/spac-chr.lua | 116 |
1 files changed, 70 insertions, 46 deletions
diff --git a/tex/context/base/mkiv/spac-chr.lua b/tex/context/base/mkiv/spac-chr.lua index 0fa639f92..20b72e1b9 100644 --- a/tex/context/base/mkiv/spac-chr.lua +++ b/tex/context/base/mkiv/spac-chr.lua @@ -27,9 +27,6 @@ local nodes, node = nodes, node local nuts = nodes.nuts -local tonode = nuts.tonode -local tonut = nuts.tonut - local getnext = nuts.getnext local getprev = nuts.getprev local getattr = nuts.getattr @@ -48,13 +45,13 @@ local setcolor = nodes.tracers.colors.set local insert_node_before = nuts.insert_before local insert_node_after = nuts.insert_after local remove_node = nuts.remove -local traverse_id = nuts.traverse_id -local traverse_char = nuts.traverse_char +----- traverse_id = nuts.traverse_id +----- traverse_char = nuts.traverse_char +local nextchar = nuts.traversers.char +local nextglyph = nuts.traversers.glyph local copy_node = nuts.copy -local tasks = nodes.tasks - local nodepool = nuts.pool local new_penalty = nodepool.penalty local new_glue = nodepool.glue @@ -101,8 +98,7 @@ local function inject_quad_space(unicode,head,current,fraction) setattrlist(glue,current) setattrlist(current) -- why reset all setattr(glue,a_character,unicode) - head, current = insert_node_after(head,current,glue) - return head, current + return insert_node_after(head,current,glue) end local function inject_char_space(unicode,head,current,parent) @@ -112,8 +108,7 @@ local function inject_char_space(unicode,head,current,parent) setattrlist(glue,current) setattrlist(current) -- why reset all setattr(glue,a_character,unicode) - head, current = insert_node_after(head,current,glue) - return head, current + return insert_node_after(head,current,glue) end local function inject_nobreak_space(unicode,head,current,space,spacestretch,spaceshrink) @@ -132,8 +127,7 @@ local function inject_nobreak_space(unicode,head,current,space,spacestretch,spac head, current = insert_node_after(head,current,kern) head, current = insert_node_after(head,current,penalty) end - head, current = insert_node_after(head,current,glue) - return head, current + return insert_node_after(head,current,glue) end local function nbsp(head,current) @@ -152,26 +146,12 @@ end function characters.replacenbsp(head,original) local head, current = nbsp(head,original) - head = remove_node(head,original,true) - return head, current + return remove_node(head,original,true) end --- function characters.replacenbspaces(head) --- for current in traverse_id(glyph_code,head) do --- if getchar(current) == 0x00A0 then --- local h = nbsp(head,current) --- if h then --- head = remove_node(h,current,true) --- end --- end --- end --- return head --- end - function characters.replacenbspaces(head) - local head = tonut(head) local wipe = false - for current in traverse_id(glyph_code,head) do -- can be anytiem so no traverse_char + for current in nextglyph, head do -- can be anytime so no traverse_char if getchar(current) == 0x00A0 then if wipe then head = remove_node(h,current,true) @@ -184,15 +164,40 @@ function characters.replacenbspaces(head) end end if wipe then - head = remove_node(h,current,true) + head = remove_node(head,current,true) + end + return head +end + +if LUATEXVERSION >= 1.090 then + + function characters.replacenbspaces(head) + local wipe = false + for current, font, char in nextglyph, head do -- can be anytime so no traverse_char + if char == 0x00A0 then + if wipe then + head = remove_node(h,current,true) + wipe = false + end + local h = nbsp(head,current) + if h then + wipe = current + end + end + end + if wipe then + head = remove_node(head,current,true) + end + return head end - return tonode(head) + end -- This initialization might move someplace else if we need more of it. The problem is that -- this module depends on fonts so we have an order problem. local nbsphash = { } setmetatableindex(nbsphash,function(t,k) + -- this needs checking ! for i=unicodeblocks.devanagari.first,unicodeblocks.devanagari.last do nbsphash[i] = true end for i=unicodeblocks.kannada .first,unicodeblocks.kannada .last do nbsphash[i] = true end setmetatableindex(nbsphash,nil) @@ -319,9 +324,7 @@ local methods = { characters.methods = methods -- function characters.handler(head) -- todo: use traverse_id --- head = tonut(head) -- local current = head --- local done = false -- while current do -- local char, id = isglyph(current) -- if char then @@ -335,28 +338,49 @@ characters.methods = methods -- if h then -- head = remove_node(h,current,true) -- end --- done = true -- end -- current = next -- else -- current = getnext(current) -- end -- end --- return tonode(head), done +-- return head -- end --- for current, char, font in traverse_char_data(head) will save 0.015 on a 300 page doc - -- this also works ok in math as we run over glyphs and these stay glyphs ... not sure -- about scripts and such but that is not important anyway ... some day we can consider -- special definitions in math function characters.handler(head) - local head = tonut(head) local wipe = false - for current in traverse_char(head) do - local char = getchar(current) - if char then + for current in nextchar, head do + local char = getchar(current) + local method = methods[char] + if method then + if wipe then + head = remove_node(head,wipe,true) + wipe = false + end + if trace_characters then + report_characters("replacing character %C, description %a",char,lower(chardata[char].description)) + end + local h = method(head,current) + if h then + wipe = current + end + end + end + if wipe then + head = remove_node(head,wipe,true) + end + return head +end + +if LUATEXVERSION >= 1.090 then + + function characters.handler(head) + local wipe = false + for current, char in nextchar, head do local method = methods[char] if method then if wipe then @@ -370,12 +394,12 @@ function characters.handler(head) if h then wipe = current end - done = true end end + if wipe then + head = remove_node(head,wipe,true) + end + return head end - if wipe then - head = remove_node(head,wipe,true) - end - return tonode(head), done + end |