summaryrefslogtreecommitdiff
path: root/tex/context/base/typo-brk.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2014-05-03 13:55:34 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2014-05-03 13:55:34 +0200
commit624cbb5da392e9403984dd1cf368c0d408b1c2a8 (patch)
tree489c049ac849bb5bbce7d32e4df477872c58373d /tex/context/base/typo-brk.lua
parent088de88944c1f2254250bb448c7371a87ff7ee39 (diff)
downloadcontext-624cbb5da392e9403984dd1cf368c0d408b1c2a8.tar.gz
2014-01-03 00:42:00
Diffstat (limited to 'tex/context/base/typo-brk.lua')
-rw-r--r--tex/context/base/typo-brk.lua122
1 files changed, 48 insertions, 74 deletions
diff --git a/tex/context/base/typo-brk.lua b/tex/context/base/typo-brk.lua
index be11da9c3..3558efa8e 100644
--- a/tex/context/base/typo-brk.lua
+++ b/tex/context/base/typo-brk.lua
@@ -20,36 +20,19 @@ local report_breakpoints = logs.reporter("typesetting","breakpoints")
local nodes, node = nodes, node
local settings_to_array = utilities.parsers.settings_to_array
+local copy_node = node.copy
+local copy_nodelist = node.copy_list
+local free_node = node.free
+local insert_node_before = node.insert_before
+local insert_node_after = node.insert_after
+local remove_node = nodes.remove -- ! nodes
-local nuts = nodes.nuts
-local tonut = nuts.tonut
-local tonode = nuts.tonode
-
-local getnext = nuts.getnext
-local getprev = nuts.getprev
-local getsubtype = nuts.getsubtype
-local getchar = nuts.getchar
-local getfont = nuts.getfont
-local getid = nuts.getid
-local getfield = nuts.getfield
-local getattr = nuts.getattr
-
-local setfield = nuts.setfield
-local setattr = nuts.setattr
-
-local copy_node = nuts.copy
-local copy_nodelist = nuts.copy_list
-local free_node = nuts.free
-local insert_node_before = nuts.insert_before
-local insert_node_after = nuts.insert_after
-local remove_node = nuts.remove
-
-local tonodes = nuts.tonodes
+local tonodes = nodes.tonodes
local texsetattribute = tex.setattribute
local unsetvalue = attributes.unsetvalue
-local nodepool = nuts.pool
+local nodepool = nodes.pool
local tasks = nodes.tasks
local v_reset = interfaces.variables.reset
@@ -97,82 +80,74 @@ local function insert_break(head,start,before,after)
end
methods[1] = function(head,start)
- if getprev(start) and getnext(start) then
+ if start.prev and start.next then
insert_break(head,start,10000,0)
end
return head, start
end
methods[2] = function(head,start) -- ( => (-
- if getprev(start) and getnext(start) then
+ if start.prev and start.next then
local tmp
head, start, tmp = remove_node(head,start)
head, start = insert_node_before(head,start,new_disc())
- setfield(start,"attr",copy_nodelist(getfield(tmp,"attr")))
- setfield(start,"replace",tmp)
- local tmp = copy_node(tmp)
- local hyphen = copy_node(tmp)
- setfield(hyphen,"char",languages.prehyphenchar(getfield(tmp,"lang")))
- setfield(tmp,"next",hyphen)
- setfield(hyphen,"prev",tmp)
- setfield(start,"post",tmp)
+ start.attr = copy_nodelist(tmp.attr) -- todo: critical only
+ start.replace = tmp
+ local tmp, hyphen = copy_node(tmp), copy_node(tmp)
+ hyphen.char = languages.prehyphenchar(tmp.lang)
+ tmp.next, hyphen.prev = hyphen, tmp
+ start.post = tmp
insert_break(head,start,10000,10000)
end
return head, start
end
methods[3] = function(head,start) -- ) => -)
- if getprev(start) and getnext(start) then
+ if start.prev and start.next then
local tmp
head, start, tmp = remove_node(head,start)
head, start = insert_node_before(head,start,new_disc())
- setfield(start,"attr",copy_nodelist(getfield(tmp,"attr")))
- setfield(start,"replace",tmp)
- local tmp = copy_node(tmp)
- local hyphen = copy_node(tmp)
- setfield(hyphen,"char",languages.prehyphenchar(getfield(tmp,"lang")))
- setfield(tmp,"prev",hyphen)
- setfield(hyphen,"next",tmp)
- setfield(start,"pre",hyphen)
+ start.attr = copy_nodelist(tmp.attr) -- todo: critical only
+ start.replace = tmp
+ local tmp, hyphen = copy_node(tmp), copy_node(tmp)
+ hyphen.char = languages.prehyphenchar(tmp.lang)
+ tmp.prev, hyphen.next = hyphen, tmp
+ start.pre = hyphen
insert_break(head,start,10000,10000)
end
return head, start
end
methods[4] = function(head,start) -- - => - - -
- if getprev(start) and getnext(start) then
+ if start.prev and start.next then
local tmp
head, start, tmp = remove_node(head,start)
head, start = insert_node_before(head,start,new_disc())
- setfield(start,"attr",copy_nodelist(getfield(tmp,"attr")))
- setfield(start,"pre",copy_node(tmp))
- setfield(start,"post",copy_node(tmp))
- setfield(start,"replace",tmp)
+ start.attr = copy_nodelist(tmp.attr) -- todo: critical only
+ start.pre, start.post, start.replace = copy_node(tmp), copy_node(tmp), tmp
insert_break(head,start,10000,10000)
end
return head, start
end
methods[5] = function(head,start,settings) -- x => p q r
- if getprev(start) and getnext(start) then
+ if start.prev and start.next then
local tmp
head, start, tmp = remove_node(head,start)
head, start = insert_node_before(head,start,new_disc())
- local attr = getfield(tmp,"attr")
- local font = getfont(tmp)
- local left = settings.left
- local right = settings.right
- local middle = settings.middle
+ local attr = tmp.attr
+ local font = tmp.font
+ start.attr = copy_nodelist(attr) -- todo: critical only
+ local left, right, middle = settings.left, settings.right, settings.middle
if left then
- setfield(start,"pre",(tonodes(tostring(left),font,attr))) -- was right
+ start.pre = tonodes(tostring(left),font,attr) -- was right
end
if right then
- setfield(start,"post",(tonodes(tostring(right),font,attr))) -- was left
+ start.post = tonodes(tostring(right),font,attr) -- was left
end
if middle then
- setfield(start,"replace",(tonodes(tostring(middle),font,attr)))
+ start.replace = tonodes(tostring(middle),font,attr)
end
- setfield(start,"attr",copy_nodelist(attr)) -- todo: critical only
free_node(tmp)
insert_break(head,start,10000,10000)
end
@@ -180,32 +155,31 @@ methods[5] = function(head,start,settings) -- x => p q r
end
function breakpoints.handler(head)
- head = tonut(head)
local done, numbers = false, languages.numbers
local start, n = head, 0
while start do
- local id = getid(start)
+ local id = start.id
if id == glyph_code then
- local attr = getattr(start,a_breakpoints)
+ local attr = start[a_breakpoints]
if attr and attr > 0 then
- setattr(start,a_breakpoints,unsetvalue) -- maybe test for subtype > 256 (faster)
+ start[a_breakpoints] = unsetvalue -- maybe test for subtype > 256 (faster)
-- look ahead and back n chars
local data = mapping[attr]
if data then
local map = data.characters
- local cmap = map[getchar(start)]
+ local cmap = map[start.char]
if cmap then
- local lang = getfield(start,"lang")
+ local lang = start.lang
-- we do a sanity check for language
local smap = lang and lang >= 0 and lang < 0x7FFF and (cmap[numbers[lang]] or cmap[""])
if smap then
if n >= smap.nleft then
local m = smap.nright
- local next = getnext(start)
+ local next = start.next
while next do -- gamble on same attribute (not that important actually)
- local id = getid(next)
+ local id = next.id
if id == glyph_code then -- gamble on same attribute (not that important actually)
- if map[getchar(next)] then
+ if map[next.char] then
break
elseif m == 1 then
local method = methods[smap.type]
@@ -216,10 +190,10 @@ function breakpoints.handler(head)
break
else
m = m - 1
- next = getnext(next)
+ next = next.next
end
- elseif id == kern_code and getsubtype(next) == kerning_code then
- next = getnext(next)
+ elseif id == kern_code and next.subtype == kerning_code then
+ next = next.next
-- ignore intercharacter kerning, will go way
else
-- we can do clever and set n and jump ahead but ... not now
@@ -240,14 +214,14 @@ function breakpoints.handler(head)
else
-- n = n + 1 -- if we want single char handling (|-|) then we will use grouping and then we need this
end
- elseif id == kern_code and getsubtype(start) == kerning_code then
+ elseif id == kern_code and start.subtype == kerning_code then
-- ignore intercharacter kerning, will go way
else
n = 0
end
- start = getnext(start)
+ start = start.next
end
- return tonode(head), done
+ return head, done
end
local enabled = false