summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/typo-rub.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2017-02-17 10:31:56 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2017-02-17 10:31:56 +0100
commitb14f992ef5f4e868c9959b174278c86516d60dbc (patch)
tree28587bb46c025ea7b0d27ba93f09c93dcf53c73a /tex/context/base/mkiv/typo-rub.lua
parent95a1799032dc61dbca4a11e495be34b4397c8fec (diff)
downloadcontext-b14f992ef5f4e868c9959b174278c86516d60dbc.tar.gz
2017-02-17 10:23:00
Diffstat (limited to 'tex/context/base/mkiv/typo-rub.lua')
-rw-r--r--tex/context/base/mkiv/typo-rub.lua236
1 files changed, 125 insertions, 111 deletions
diff --git a/tex/context/base/mkiv/typo-rub.lua b/tex/context/base/mkiv/typo-rub.lua
index f101668b6..9621a6218 100644
--- a/tex/context/base/mkiv/typo-rub.lua
+++ b/tex/context/base/mkiv/typo-rub.lua
@@ -48,9 +48,14 @@ local setprev = nuts.setprev
local setlink = nuts.setlink
local getlist = nuts.getlist
local setlist = nuts.setlist
+local setshift = nuts.setshift
+local getwidth = nuts.getwidth
+local setwidth = nuts.setwidth
+
local hpack = nuts.hpack
local insert_after = nuts.insert_after
local takebox = nuts.takebox
+local traverse_id = nuts.traverse_id
local nodecodes = nodes.nodecodes
local glyph_code = nodecodes.glyph
@@ -70,12 +75,13 @@ local kerncodes = nodes.kerncodes
local font_code = kerncodes.font
local nodepool = nuts.pool
-local new_hlist = nodepool.hlist
local new_kern = nodepool.kern
local setprop = nuts.setprop
local getprop = nuts.getprop
+local enableaction = nodes.tasks.enableaction
+
local nofrubies = 0
local rubylist = { }
@@ -93,8 +99,8 @@ do
local splitter = lpeg.tsplitat("|")
local function enable()
- nodes.tasks.enableaction("processors","typesetters.rubies.check")
- nodes.tasks.enableaction("shipouts", "typesetters.rubies.attach")
+ enableaction("processors","typesetters.rubies.check")
+ enableaction("shipouts", "typesetters.rubies.attach")
enable = false
end
@@ -173,7 +179,7 @@ do
local r = takebox(n)
rubylist[nofrubies] = setmetatableindex({
text = r,
- width = getfield(r,"width"),
+ width = getwidth(r),
basewidth = 0,
start = false,
stop = false,
@@ -210,7 +216,7 @@ function rubies.check(head)
setlink(prev,h)
end
setlink(h,next)
- local bwidth = getfield(h,"width")
+ local bwidth = getwidth(h)
local rwidth = r.width
r.basewidth = bwidth
r.start = start
@@ -218,7 +224,7 @@ function rubies.check(head)
setprop(h,"ruby",found)
if rwidth > bwidth then
-- ruby is wider
- setfield(h,"width",rwidth)
+ setwidth(h,rwidth)
end
end
end
@@ -259,121 +265,129 @@ function rubies.check(head)
return tonode(head), true
end
-local function attach(head,parent)
- local current = head
- while current do
- local id = getid(current)
- if id == hlist_code then
- local a = getprop(current,"ruby")
- if a then
- local ruby = rubylist[a]
- local align = ruby.align or v_middle
- local stretch = ruby.stretch or v_no
- local hoffset = ruby.hoffset or 0
- local voffset = ruby.voffset or 0
- local start = ruby.start
- local stop = ruby.stop
- local text = ruby.text
- local rwidth = ruby.width
- local bwidth = ruby.basewidth
- local delta = rwidth - bwidth
- setfield(text,"width",0)
- if voffset ~= 0 then
- setfield(text,"shift",voffset)
+local attach
+
+local function whatever(current)
+ local a = getprop(current,"ruby")
+ if a then
+ local ruby = rubylist[a]
+ local align = ruby.align or v_middle
+ local stretch = ruby.stretch or v_no
+ local hoffset = ruby.hoffset or 0
+ local voffset = ruby.voffset or 0
+ local start = ruby.start
+ local stop = ruby.stop
+ local text = ruby.text
+ local rwidth = ruby.width
+ local bwidth = ruby.basewidth
+ local delta = rwidth - bwidth
+ setwidth(text,0)
+ if voffset ~= 0 then
+ setshift(text,voffset)
+ end
+ -- center them
+ if delta > 0 then
+ -- ruby is wider
+ if stretch == v_yes then
+ setlink(text,start)
+ while start and start ~= stop do
+ local s = nodepool.stretch()
+ local n = getnext(start)
+ setlink(start,s,n)
+ start = n
end
- -- center them
- if delta > 0 then
- -- ruby is wider
- if stretch == v_yes then
- setlink(text,start)
- while start and start ~= stop do
- local s = nodepool.stretch()
- local n = getnext(start)
- setlink(start,s)
- setlink(s,n)
- start = n
- end
- text = hpack(text,rwidth,"exactly")
+ text = hpack(text,rwidth,"exactly")
+ else
+ local left = new_kern(delta/2)
+ local right = new_kern(delta/2)
+-- setlink(left,start)
+-- setlink(stop,right)
+-- setlink(text,left)
+ setlink(text,left,start)
+ setlink(stop,right)
+ end
+ setlist(current,text)
+ elseif delta < 0 then
+ -- ruby is narrower
+ if align == v_auto then
+ local l = true
+ local c = getprev(current)
+ while c do
+ local id = getid(c)
+ if id == glue_code or id == penalty_code or id == kern_code or (id == whatsit_code and getsubtype(current,localpar_code)) then
+ -- go on
+ elseif id == hlist_code and getwidth(c) == 0 then
+ -- go on
+ elseif id == whatsit_code or id == localpar_code then
+ -- go on
else
- local left = new_kern(delta/2)
- local right = new_kern(delta/2)
- setlink(left,start)
- setlink(stop,right)
- setlink(text,left)
- end
- setlist(current,text)
- elseif delta < 0 then
- -- ruby is narrower
- if align == v_auto then
- local l = true
- local c = getprev(current)
- while c do
- local id = getid(c)
- if id == glue_code or id == penalty_code or id == kern_code or (id == whatsit_code and getsubtype(current,localpar_code)) then
- -- go on
- elseif id == hlist_code and getfield(c,"width") == 0 then
- -- go on
- elseif id == whatsit_code or id == localpar_code then
- -- go on
- else
- l = false
- break
- end
- c = getprev(c)
- end
- local r = true
- local c = getnext(current)
- while c do
- local id = getid(c)
- if id == glue_code or id == penalty_code or id == kern_code then
- -- go on
- elseif id == hlist_code and getfield(c,"width") == 0 then
- -- go on
- else
- r = false
- break
- end
- c = getnext(c)
- end
- if l and not r then
- align = v_flushleft
- elseif r and not l then
- align = v_flushright
- else
- align = v_middle
- end
+ l = false
+ break
end
- if align == v_flushleft then
- setlink(text,start)
- setlist(current,text)
- elseif align == v_flushright then
- local left = new_kern(-delta)
- local right = new_kern(delta)
- setlink(left,text)
- setlink(text,right)
- setlink(right,start)
- setlist(current,left)
+ c = getprev(c)
+ end
+ local r = true
+ local c = getnext(current)
+ while c do
+ local id = getid(c)
+ if id == glue_code or id == penalty_code or id == kern_code then
+ -- go on
+ elseif id == hlist_code and getwidth(c) == 0 then
+ -- go on
else
- local left = new_kern(-delta/2)
- local right = new_kern(delta/2)
- setlink(left,text)
- setlink(text,right)
- setlink(right,start)
- setlist(current,left)
+ r = false
+ break
end
+ c = getnext(c)
+ end
+ if l and not r then
+ align = v_flushleft
+ elseif r and not l then
+ align = v_flushright
else
- setlink(text,start)
- setlist(current,text)
+ align = v_middle
end
- setprop(current,"ruby",false)
- rubylist[a] = nil
+ end
+ if align == v_flushleft then
+ setlink(text,start)
+ setlist(current,text)
+ elseif align == v_flushright then
+ local left = new_kern(-delta)
+ local right = new_kern(delta)
+-- setlink(left,text)
+-- setlink(text,right)
+-- setlink(right,start)
+ setlink(left,text,right,start)
+ setlist(current,left)
else
- attach(getlist(current),current)
+ local left = new_kern(-delta/2)
+ local right = new_kern(delta/2)
+-- setlink(left,text)
+-- setlink(text,right)
+-- setlink(right,start)
+ setlink(left,text,right,start)
+ setlist(current,left)
end
- elseif id == vlist_code then
- attach(getlist(current),current)
+ else
+ setlink(text,start)
+ setlist(current,text)
+ end
+ setprop(current,"ruby",false)
+ rubylist[a] = nil
+ else
+ local list = getlist(current)
+ if list then
+ attach(list)
end
- current = getnext(current)
+ end
+end
+
+attach = function(head)
+ for current in traverse_id(hlist_code,head) do
+ whatever(current)
+ end
+ for current in traverse_id(vlist_code,head) do
+ whatever(current)
end
return head, true
end