diff options
author | Marius <mariausol@gmail.com> | 2010-07-04 15:35:28 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2010-07-04 15:35:28 +0300 |
commit | b0f61c557fa27bddb54ad085c9dc9beefc851a30 (patch) | |
tree | a69dff7e9ee8d0022554603e8715fd482d4ac01c /tex/context/base/typo-dig.lua | |
parent | 85b7bc695629926641c7cb752fd478adfdf374f3 (diff) | |
download | context-b0f61c557fa27bddb54ad085c9dc9beefc851a30.tar.gz |
beta 2010-06-23 12:49
Diffstat (limited to 'tex/context/base/typo-dig.lua')
-rw-r--r-- | tex/context/base/typo-dig.lua | 94 |
1 files changed, 63 insertions, 31 deletions
diff --git a/tex/context/base/typo-dig.lua b/tex/context/base/typo-dig.lua index c1b44e39f..9ee57a794 100644 --- a/tex/context/base/typo-dig.lua +++ b/tex/context/base/typo-dig.lua @@ -6,11 +6,16 @@ if not modules then modules = { } end modules ['typo-dig'] = { license = "see context related readme files" } +-- we might consider doing this after the otf pass because now osf do not work +-- out well in node mode. + local next, type = next, type local format, insert = string.format, table.insert -local round = math.round +local round, div = math.round, math.div + +local trace_digits = false trackers.register("typesetting.digits", function(v) trace_digits = v end) -local trace_digits = false trackers.register("nodes.digits", function(v) trace_digits = v end) +local report_digits = logs.new("digits") local has_attribute = node.has_attribute local unset_attribute = node.unset_attribute @@ -30,24 +35,30 @@ local chardata = fonts.characters local quaddata = fonts.quads local charbase = characters.data -digits = digits or { } +typesetting = typesetting or { } +typesetting.digits = typesetting.digits or { } + +local digits = typesetting.digits + digits.actions = { } digits.attribute = attributes.private("digits") +local a_digits = digits.attribute + local actions = digits.actions -- at some point we can manipulate the glyph node so then i need --- to rewrite this +-- to rewrite this then -function nodes.aligned(start,stop,width,how) - local prv, nxt, head = start.prev, stop.next, nil - start.prev, stop.next = nil, nil +function nodes.aligned(head,start,stop,width,how) if how == "flushright" or how == "middle" then - head, start = insert_before(start,start,new_glue(0,65536,65536)) + head, start = insert_before(head,start,new_glue(0,65536,65536)) end if how == "flushleft" or how == "middle" then - head, stop = insert_after(start,stop,new_glue(0,65536,65536)) + head, stop = insert_after(head,stop,new_glue(0,65536,65536)) end + local prv, nxt = start.prev, stop.next + start.prev, stop.next = nil, nil local packed = hpack_node(start,width,"exactly") -- no directional mess here, just lr if prv then prv.next, packed.prev = packed, prv @@ -55,38 +66,45 @@ function nodes.aligned(start,stop,width,how) if nxt then nxt.prev, packed.next = packed, nxt end - return packed, prv, nxt + if packed.prev then + return head, packed + else + return packed, packed + end end -actions[1] = function(start,attribute) +actions[1] = function(head,start,attribute,attr) + local font = start.font local char = start.char - if charbase[char].category == "nd" then - local font = start.font + local unic = chardata[font][char].tounicode + local what = unic and tonumber(unic,16) or char + if charbase[what].category == "nd" then local oldwidth, newwidth = start.width, fonts.get_digit_width(font) if newwidth ~= oldwidth then - local start = nodes.aligned(start,start,newwidth,"middle") -- return three node pointers - return start, true + if trace_digits then + report_digits("digit trigger %s, instance %s, char 0x%05X, unicode 0x%05X, delta %s", + attr%100,div(attr,100),char,what,newwidth-oldwidth) + end + head, start = nodes.aligned(head,start,start,newwidth,"middle") + return head, start, true end end - return start, false + return head, start, false end -function digits.process(namespace,attribute,head) +local function process(namespace,attribute,head) local done, current, ok = false, head, false while current do if current.id == glyph then local attr = has_attribute(current,attribute) if attr and attr > 0 then unset_attribute(current,attribute) - local action = actions[attr] + local action = actions[attr%100] -- map back to low number if action then - if current == head then - head, ok = action(current,attribute) - current = head - else - current, ok = action(current,attribute) - end + head, current, ok = action(head,current,attribute,attr) done = done and ok + elseif trace_digits then + report_digits("unknown digit trigger %s",attr) end end end @@ -95,12 +113,26 @@ function digits.process(namespace,attribute,head) return head, done end -chars.handle_digits = nodes.install_attribute_handler { - name = "digits", - namespace = digits, - processor = digits.process, -} +local m = 0 -- a trick to make neighbouring ranges work -function digits.enable() - tasks.enableaction("processors","chars.handle_digits") +function digits.set(n) + if trace_digits then + report_digits("enabling digit handler") + end + tasks.enableaction("processors","typesetting.digits.handler") + function digits.set(n) + if m == 100 then + m = 1 + else + m = m + 1 + end + tex.attribute[a_digits] = m * 100 + n + end + digits.set(n) end + +digits.handler = nodes.install_attribute_handler { + name = "digits", + namespace = digits, + processor = process, +} |