summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/spac-chr.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2017-07-14 21:22:10 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2017-07-14 21:22:10 +0200
commit23b495f46b4d2e9264d54095f43774ef47d3a656 (patch)
tree1b0131b93d92d4aa7e15b55c50ad1dfa3573a7e1 /tex/context/base/mkiv/spac-chr.lua
parent6ae40572e7643edcc29f8d5b071221dd1e04bdf3 (diff)
downloadcontext-23b495f46b4d2e9264d54095f43774ef47d3a656.tar.gz
2017-07-14 19:41:00
Diffstat (limited to 'tex/context/base/mkiv/spac-chr.lua')
-rw-r--r--tex/context/base/mkiv/spac-chr.lua81
1 files changed, 67 insertions, 14 deletions
diff --git a/tex/context/base/mkiv/spac-chr.lua b/tex/context/base/mkiv/spac-chr.lua
index fe402ed87..b8a53d2a1 100644
--- a/tex/context/base/mkiv/spac-chr.lua
+++ b/tex/context/base/mkiv/spac-chr.lua
@@ -48,6 +48,7 @@ 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
local tasks = nodes.tasks
@@ -148,16 +149,37 @@ function characters.replacenbsp(head,original)
return head, current
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)
- for current in traverse_id(glyph_code,head) do
+ local head = tonut(head)
+ local wipe = false
+ for current in traverse_id(glyph_code,head) do -- can be anytiem so no traverse_char
if getchar(current) == 0x00A0 then
+ if wipe then
+ head = remove_node(h,current,true)
+ wipe = false
+ end
local h = nbsp(head,current)
if h then
- head = remove_node(h,current,true)
+ wipe = current
end
end
end
- return head
+ if wipe then
+ head = remove_node(h,current,true)
+ end
+ return tonode(head)
end
-- This initialization might move someplace else if we need more of it. The problem is that
@@ -283,29 +305,60 @@ 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)
+-- 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
+-- local next = getnext(current)
+-- local method = methods[char]
+-- if method then
+-- 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
+-- head = remove_node(h,current,true)
+-- end
+-- done = true
+-- end
+-- current = next
+-- else
+-- current = getnext(current)
+-- end
+-- end
+-- return tonode(head), done
+-- end
+
+-- for current, char, font in traverse_char_data(head) will save 0.015 on a 300 page doc
+
+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
- local next = getnext(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
- head = remove_node(h,current,true)
+ wipe = current
end
done = true
end
- current = next
- else
- current = getnext(current)
end
end
+ if wipe then
+ head = remove_node(head,wipe,true)
+ end
return tonode(head), done
end