diff options
author | Philipp Gesang <gesang@stud.uni-heidelberg.de> | 2012-06-06 11:58:57 +0200 |
---|---|---|
committer | Philipp Gesang <gesang@stud.uni-heidelberg.de> | 2012-06-06 11:58:57 +0200 |
commit | 691fb4c826067d0ed47420cd44901206216a00ee (patch) | |
tree | 474b91c236941fc64e0a7f3c028ff5c994afbb19 /tex/context/third | |
parent | 74cd9772dbebb7ad43760a72a9d096a3c431a956 (diff) | |
download | enigma-691fb4c826067d0ed47420cd44901206216a00ee.tar.gz |
group output to five-character chunks
Diffstat (limited to 'tex/context/third')
-rw-r--r-- | tex/context/third/enigma/enigma.lua | 50 | ||||
-rw-r--r-- | tex/context/third/enigma/t-enigma.mkvi | 5 |
2 files changed, 43 insertions, 12 deletions
diff --git a/tex/context/third/enigma/enigma.lua b/tex/context/third/enigma/enigma.lua index a34e669..3222bd6 100644 --- a/tex/context/third/enigma/enigma.lua +++ b/tex/context/third/enigma/enigma.lua @@ -75,8 +75,10 @@ local next = next local nodecopy = node and node.copy local nodeid = node and node.id local nodeinsert_before = node and node.insert_before +local nodeinsert_after = node and node.insert_after local nodenew = node and node.new local noderemove = node and node.remove +local nodeslide = node and node.slide local nodetraverse = node and node.traverse local nodesinstallattributehandler = format_is_context_p and nodes.installattributehandler local nodestasksappendaction = format_is_context_p and nodes.tasks.appendaction @@ -114,8 +116,17 @@ else end end -local glyph_node = node and nodeid"glyph" -local glue_node = node and nodeid"glue" +local GLYPH_NODE = node and nodeid"glyph" +local GLUE_NODE = node and nodeid"glue" +local GLUE_SPEC_NODE = node and nodeid"glue_spec" +local KERN_NODE = node and nodeid"kern" +local DISC_NODE = node and nodeid"disc" + +local IGNORE_NODES = { + [GLUE_NODE] = true, + [KERN_NODE] = true, + [DISC_NODE] = true, +} --[[ichd-- \startparagraph @@ -1314,13 +1325,32 @@ on \dots\ many thanks to Khaled Hosny, who posted an answer to local new_callback = function (machine, name) enigma.machines [name] = machine + local mod_5 = 0 + local current_fontparms = font.getfont(font.current()).parameters + local space_node = nodenew(GLUE_NODE) + space_node.spec = nodenew(GLUE_SPEC_NODE) + space_node.spec.width = current_fontparms.space + space_node.spec.shrink = current_fontparms.space_shrink + space_node.spec.stretch = current_fontparms.space_stretch + local insert_with_spacing = function (head, n, insertion) + nodeinsert_before(head, n, insertion) + mod_5 = mod_5 + 1 + if mod_5 >= 5 then + mod_5 = 0 + nodeinsert_after(head, insertion, nodecopy(space_node)) + end + noderemove(head, n) + return head + end local format_is_context_p = format_is_context_p local cbk = function (a, _, c) local head = format_is_context_p and c or a + mod_5 = 0 for n in nodetraverse(head) do --print(node, node.id) - if n.id == glyph_node then + if n.id == GLYPH_NODE then local chr = utf8char(n.char) + --print(chr, n) local replacement = machine:encode(chr) --if replacement == false then if not replacement then @@ -1330,21 +1360,23 @@ local new_callback = function (machine, name) elseif type(replacement) == "string" then local insertion = nodecopy(n) insertion.char = utf8byte(replacement) - nodeinsert_before(head, n, insertion) - noderemove(head, n) + insert_with_spacing(head, n, insertion) elseif type(replacement) == "table" then for i=1, #replacement do local insertion = nodecopy(n) insertion.char = utf8byte(replacement[i]) - nodeinsert_before(head, n, insertion) + insert_with_spacing(head, n, insertion) end noderemove(head, n) end - elseif n.id == glue_node then - -- spaces are dropped + elseif IGNORE_NODES[n.id] then + -- spaces, ligatures and kerns are dropped noderemove(head, n) + else + print(n) end end + nodeslide(head) return head end if format_is_context_p then @@ -1406,7 +1438,7 @@ specification of any machine can be inherited by some new setup later on. \stopparagraph --ichd]]-- -local new_machine = function (_, name) +local new_machine = function (name) local args = configurations[name] --table.print(configurations) verbose_level = args and args.verbose or verbose_level diff --git a/tex/context/third/enigma/t-enigma.mkvi b/tex/context/third/enigma/t-enigma.mkvi index 8bf0797..fbe48dc 100644 --- a/tex/context/third/enigma/t-enigma.mkvi +++ b/tex/context/third/enigma/t-enigma.mkvi @@ -88,7 +88,7 @@ thirddata = thirddata or { } local enigma = thirddata.enigma local current_args = enigma.retrieve_raw_args(\!!bs#from\!!es) enigma.save_raw_args(current_args, \!!bs#to\!!es) - enigma.new_callback(enigma.new_machine(current_args, \!!bs#to\!!es), + enigma.new_callback(enigma.new_machine(\!!bs#to\!!es), \!!bs#to\!!es) }% \do_do_define_enigma{#to}% @@ -122,8 +122,7 @@ thirddata = thirddata or { } enigma.parse_args(\!!bs\detokenize{#args}\!!es) enigma.save_raw_args(current_args, \!!bs\currentenigmaid\!!es) enigma.new_callback( - enigma.new_machine(current_args, - \!!bs\currentenigmaid\!!es), + enigma.new_machine(\!!bs\currentenigmaid\!!es), \!!bs\currentenigmaid\!!es) }% } |