diff options
Diffstat (limited to 'tex/context/base/mkiv/typo-tal.lua')
-rw-r--r-- | tex/context/base/mkiv/typo-tal.lua | 128 |
1 files changed, 73 insertions, 55 deletions
diff --git a/tex/context/base/mkiv/typo-tal.lua b/tex/context/base/mkiv/typo-tal.lua index 67380f24b..870d006cc 100644 --- a/tex/context/base/mkiv/typo-tal.lua +++ b/tex/context/base/mkiv/typo-tal.lua @@ -14,7 +14,7 @@ if not modules then modules = { } end modules ['typo-tal'] = { -- We can speed up by saving the current fontcharacters[font] + lastfont. -local next, type = next, type +local next, type, tonumber = next, type, tonumber local div = math.div local utfbyte = utf.byte @@ -38,6 +38,7 @@ local tonode = nuts.tonode local getnext = nuts.getnext local getprev = nuts.getprev +local getboth = nuts.getboth local getid = nuts.getid local getfont = nuts.getfont local getchar = nuts.getchar @@ -100,7 +101,7 @@ local validsigns = { -- If needed we can have more modes which then also means a faster simple handler -- for non numbers. -local function setcharacteralign(column,separator) +local function setcharacteralign(column,separator,before,after) if not enabled then enableaction("processors","typesetters.characteralign.handler") enabled = true @@ -123,11 +124,14 @@ local function setcharacteralign(column,separator) separator = comma method = v_number end + local before = tonumber(before) or 0 + local after = tonumber(after) or 0 dataset = { separator = separator, list = { }, - maxafter = 0, - maxbefore = 0, + maxbefore = before, + maxafter = after, + predefined = before > 0 or after > 0, collected = false, method = method, separators = validseparators, @@ -153,6 +157,12 @@ implement { } implement { + name = "setcharacteraligndetail", + actions = setcharacteralign, + arguments = { "integer", "string", "dimension", "dimension" } +} + +implement { name = "resetcharacteralign", actions = resetcharacteralign } @@ -257,10 +267,9 @@ function characteralign.handler(originalhead,where) elseif (b_start or a_start) and id == glue_code then -- maybe only in number mode -- somewhat inefficient - local next = getnext(current) - local prev = getprev(current) + local prev, next = getboth(current) if next and prev and getid(next) == glyph_code and getid(prev) == glyph_code then -- too much checking - local width = fontcharacters[getfont(b_start)][separator or period].width + local width = fontcharacters[getfont(b_start or a_start)][separator or period].width setglue(current,width) setattr(current,a_character,punctuationspace) if a_start then @@ -310,8 +319,25 @@ function characteralign.handler(originalhead,where) current = getnext(current) end end - local entry = list[row] - if entry then + local predefined = dataset.predefined + local before, after + if predefined then + before = b_start and list_dimensions(b_start,getnext(b_stop)) or 0 + after = a_start and list_dimensions(a_start,getnext(a_stop)) or 0 + else + local entry = list[row] + if entry then + before = entry.before or 0 + after = entry.after or 0 + else + before = b_start and list_dimensions(b_start,getnext(b_stop)) or 0 + after = a_start and list_dimensions(a_start,getnext(a_stop)) or 0 + list[row] = { + before = before, + after = after, + } + return tonode(head), true + end if not dataset.collected then -- print("[maxbefore] [maxafter]") local maxbefore = 0 @@ -330,61 +356,53 @@ function characteralign.handler(originalhead,where) dataset.maxafter = maxafter dataset.collected = true end - local maxbefore = dataset.maxbefore - local maxafter = dataset.maxafter - local before = entry.before or 0 - local after = entry.after or 0 - local new_kern = trace_split and traced_kern or new_kern - if b_start then - if before < maxbefore then - head = insert_node_before(head,b_start,new_kern(maxbefore-before)) - end - if not c then - -- print("[before]") - if dataset.hasseparator then - local width = fontcharacters[getfont(b_stop)][separator].width - insert_node_after(head,b_stop,new_kern(maxafter+width)) - end - elseif a_start then - -- print("[before] [separator] [after]") - if after < maxafter then - insert_node_after(head,a_stop,new_kern(maxafter-after)) - end - else - -- print("[before] [separator]") - if maxafter > 0 then - insert_node_after(head,c,new_kern(maxafter)) - end + end + local maxbefore = dataset.maxbefore + local maxafter = dataset.maxafter + local new_kern = trace_split and traced_kern or new_kern + if b_start then + if before < maxbefore then + head = insert_node_before(head,b_start,new_kern(maxbefore-before)) + end + if not c then + -- print("[before]") + if dataset.hasseparator then + local width = fontcharacters[getfont(b_start)][separator].width + insert_node_after(head,b_stop,new_kern(maxafter+width)) end elseif a_start then - if c then - -- print("[separator] [after]") - if maxbefore > 0 then - head = insert_node_before(head,c,new_kern(maxbefore)) - end - else - -- print("[after]") - local width = fontcharacters[getfont(b_stop)][separator].width - head = insert_node_before(head,a_start,new_kern(maxbefore+width)) - end + -- print("[before] [separator] [after]") if after < maxafter then insert_node_after(head,a_stop,new_kern(maxafter-after)) end - elseif c then - -- print("[separator]") - if maxbefore > 0 then - head = insert_node_before(head,c,new_kern(maxbefore)) - end + else + -- print("[before] [separator]") if maxafter > 0 then insert_node_after(head,c,new_kern(maxafter)) end end - else - entry = { - before = b_start and list_dimensions(b_start,getnext(b_stop)) or 0, - after = a_start and list_dimensions(a_start,getnext(a_stop)) or 0, - } - list[row] = entry + elseif a_start then + if c then + -- print("[separator] [after]") + if maxbefore > 0 then + head = insert_node_before(head,c,new_kern(maxbefore)) + end + else + -- print("[after]") + local width = fontcharacters[getfont(b_stop)][separator].width + head = insert_node_before(head,a_start,new_kern(maxbefore+width)) + end + if after < maxafter then + insert_node_after(head,a_stop,new_kern(maxafter-after)) + end + elseif c then + -- print("[separator]") + if maxbefore > 0 then + head = insert_node_before(head,c,new_kern(maxbefore)) + end + if maxafter > 0 then + insert_node_after(head,c,new_kern(maxafter)) + end end return tonode(head), true end |