summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/context/lua/third/enigma/mtx-t-enigma.lua12
-rw-r--r--tex/context/third/enigma/enigma.lua50
-rw-r--r--tex/context/third/enigma/t-enigma.mkvi5
-rw-r--r--tex/plain/enigma/enigma.tex3
4 files changed, 54 insertions, 16 deletions
diff --git a/scripts/context/lua/third/enigma/mtx-t-enigma.lua b/scripts/context/lua/third/enigma/mtx-t-enigma.lua
index fb7adbd..818138e 100644
--- a/scripts/context/lua/third/enigma/mtx-t-enigma.lua
+++ b/scripts/context/lua/third/enigma/mtx-t-enigma.lua
@@ -47,9 +47,17 @@ local out = function (str)
io.write(str)
end
+local machine_id = "external"
if setup and text then
- local machine = enigma.new_machine(enigma.parse_args(setup))
- machine.name = "external"
+ local args = enigma.parse_args(setup)
+ if not args then
+ application.help()
+ io.write"\n\n[Error] Could not process enigma setup!\n\n"
+ end
+ enigma.save_raw_args(args, machine_id)
+ --local machine = enigma.new_machine(enigma.parse_args(setup))
+ local machine = enigma.new_machine(machine_id)
+ --machine.name = machine_id
local result = machine:encode_string(text)
if result then
out(result)
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)
}%
}
diff --git a/tex/plain/enigma/enigma.tex b/tex/plain/enigma/enigma.tex
index 1c7d83f..625a38d 100644
--- a/tex/plain/enigma/enigma.tex
+++ b/tex/plain/enigma/enigma.tex
@@ -51,8 +51,7 @@
local enigma = packagedata.enigma
local current_args = enigma.parse_args(\!!bs\detokenize{#1}\!!es)
enigma.save_raw_args(current_args, \!!bs\current_enigma_id\!!es)
- enigma.new_callback(enigma.new_machine(current_args,
- \!!bs\current_enigma_id\!!es),
+ enigma.new_callback(enigma.new_machine(\!!bs\current_enigma_id\!!es),
\!!bs\current_enigma_id\!!es)
}%
\egroup%