diff options
author | Marius <mariausol@gmail.com> | 2013-10-20 01:20:14 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2013-10-20 01:20:14 +0300 |
commit | 965214d981e6129b782c67adcaf3a81aedcb0bac (patch) | |
tree | 84f5945aae8efc9b6eb1898b873be5453cafe43d /tex/context/base/spac-chr.lua | |
parent | e7d0d90a434e5452ff9e86c8abab5a4cac35e2f1 (diff) | |
download | context-965214d981e6129b782c67adcaf3a81aedcb0bac.tar.gz |
stable 2013.05.28 00:36
Diffstat (limited to 'tex/context/base/spac-chr.lua')
-rw-r--r-- | tex/context/base/spac-chr.lua | 90 |
1 files changed, 17 insertions, 73 deletions
diff --git a/tex/context/base/spac-chr.lua b/tex/context/base/spac-chr.lua index db98b42a6..24364978a 100644 --- a/tex/context/base/spac-chr.lua +++ b/tex/context/base/spac-chr.lua @@ -14,22 +14,19 @@ local byte, lower = string.byte, string.lower -- to be redone: characters will become tagged spaces instead as then we keep track of -- spaceskip etc -local next = next - trace_characters = false trackers.register("typesetters.characters", function(v) trace_characters = v end) report_characters = logs.reporter("typesetting","characters") local nodes, node = nodes, node -local insert_node_after = nodes.insert_after -local remove_node = nodes.remove -local copy_node_list = nodes.copy_list -local traverse_id = nodes.traverse_id +local insert_node_after = node.insert_after +local remove_node = nodes.remove -- ! nodes +local copy_node_list = node.copy_list +local nodepool = nodes.pool local tasks = nodes.tasks -local nodepool = nodes.pool local new_penalty = nodepool.penalty local new_glue = nodepool.glue @@ -44,9 +41,7 @@ local chardata = characters.data local typesetters = typesetters -local unicodeblocks = characters.blocks - -local characters = typesetters.characters or { } -- can be predefined +local characters = { } typesetters.characters = characters local fonthashes = fonts.hashes @@ -54,8 +49,6 @@ local fontparameters = fonthashes.parameters local fontcharacters = fonthashes.characters local fontquads = fonthashes.quads -local setmetatableindex = table.setmetatableindex - local a_character = attributes.private("characters") local a_alignstate = attributes.private("alignstate") @@ -81,6 +74,7 @@ local function inject_char_space(unicode,head,current,parent) local font = current.font local char = fontcharacters[font][parent] local glue = new_glue(char and char.width or fontparameters[font].space) + -- glue.attr = copy_node_list(current.attr) glue.attr = current.attr current.attr = nil glue[a_character] = unicode @@ -92,78 +86,30 @@ local function inject_nobreak_space(unicode,head,current,space,spacestretch,spac local attr = current.attr local glue = new_glue(space,spacestretch,spaceshrink) local penalty = new_penalty(10000) + -- glue.attr = copy_node_list(attr) glue.attr = attr current.attr = nil + -- penalty.attr = attr glue[a_character] = unicode head, current = insert_node_after(head,current,penalty) head, current = insert_node_after(head,current,glue) return head, current end -local function nbsp(head,current) - local para = fontparameters[current.font] - if current[a_alignstate] == 1 then -- flushright - head, current = inject_nobreak_space(0x00A0,head,current,para.space,0,0) - current.subtype = space_skip_code - else - head, current = inject_nobreak_space(0x00A0,head,current,para.space,para.spacestretch,para.spaceshrink) - end - return head, current -end - --- assumes nuts or nodes, depending on callers .. so no tonuts here - -function characters.replacenbsp(head,original) - local head, current = nbsp(head,original) - head = remove_node(head,original,true) - return head, current -end - -function characters.replacenbspaces(head) - for current in traverse_id(glyph_code,head) do - if current.char == 0x00A0 then - local h = nbsp(head,current) - if h then - head = remove_node(h,current,true) - end - end - end - return head -end - --- This initialization might move someplace else if we need more of it. The problem is that --- this module depends on fonts so we have an order problem. - -local nbsphash = { } setmetatableindex(nbsphash,function(t,k) - for i=unicodeblocks.devanagari.first,unicodeblocks.devanagari.last do nbsphash[i] = true end - for i=unicodeblocks.kannada .first,unicodeblocks.kannada .last do nbsphash[i] = true end - setmetatableindex(nbsphash,nil) - return nbsphash[k] -end) - local methods = { -- The next one uses an attribute assigned to the character but still we -- don't have the 'local' value. [0x00A0] = function(head,current) -- nbsp - local next = current.next - if next and next.id == glyph_code then - local char = next.char - if char == 0x200C or char == 0x200D then -- nzwj zwj - next = next.next - if next and nbsphash[next.char] then - return false - end - elseif nbsphash[char] then - return false - end - end - local prev = current.prev - if prev and prev.id == glyph_code and nbsphash[prev.char] then - return false -- kannada + local para = fontparameters[current.font] + if current[a_alignstate] == 1 then -- flushright + head, current = inject_nobreak_space(0x00A0,head,current,para.space,0,0) + current.subtype = space_skip_code + else + head, current = inject_nobreak_space(0x00A0,head,current,para.space,para.spacestretch,para.spaceshrink) end - return nbsp(head,current) + return head, current end, [0x2000] = function(head,current) -- enquad @@ -241,10 +187,8 @@ function characters.handler(head) 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 + head = method(head,current) + head = remove_node(head,current,true) done = true end current = next |