summaryrefslogtreecommitdiff
path: root/tex/context/base/typo-spa.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/typo-spa.lua')
-rw-r--r--tex/context/base/typo-spa.lua86
1 files changed, 61 insertions, 25 deletions
diff --git a/tex/context/base/typo-spa.lua b/tex/context/base/typo-spa.lua
index c3f50fe98..519ba3f34 100644
--- a/tex/context/base/typo-spa.lua
+++ b/tex/context/base/typo-spa.lua
@@ -15,10 +15,7 @@ local report_spacing = logs.reporter("typesetting","spacing")
local nodes, fonts, node = nodes, fonts, node
-local insert_node_before = node.insert_before
-local insert_node_after = node.insert_after
-local remove_node = nodes.remove
-local end_of_math = node.end_of_math
+local tasks = nodes.tasks
local fonthashes = fonts.hashes
local fontdata = fonthashes.identifiers
@@ -29,6 +26,27 @@ local unsetvalue = attributes.unsetvalue
local v_reset = interfaces.variables.reset
+local nuts = nodes.nuts
+local tonut = nuts.tonut
+local tonode = nuts.tonode
+
+local getnext = nuts.getnext
+local getprev = nuts.getprev
+local getchar = nuts.getchar
+local getid = nuts.getid
+local getfont = nuts.getfont
+local getattr = nuts.getattr
+local setattr = nuts.setattr
+
+local insert_node_before = nuts.insert_before
+local insert_node_after = nuts.insert_after
+local remove_node = nuts.remove
+local end_of_math = nuts.end_of_math
+
+local nodepool = nuts.pool
+local new_penalty = nodepool.penalty
+local new_glue = nodepool.glue
+
local nodecodes = nodes.nodecodes
local glyph_code = nodecodes.glyph
local math_code = nodecodes.math
@@ -36,12 +54,6 @@ local math_code = nodecodes.math
local somespace = nodes.somespace
local somepenalty = nodes.somepenalty
-local nodepool = nodes.pool
-local tasks = nodes.tasks
-
-local new_penalty = nodepool.penalty
-local new_glue = nodepool.glue
-
typesetters = typesetters or { }
local typesetters = typesetters
@@ -52,7 +64,6 @@ spacings.mapping = spacings.mapping or { }
spacings.numbers = spacings.numbers or { }
local a_spacings = attributes.private("spacing")
-spacings.attribute = a_spacings
storage.register("typesetters/spacings/mapping", spacings.mapping, "typesetters.spacings.mapping")
@@ -67,29 +78,30 @@ end
-- todo cache lastattr
function spacings.handler(head)
+ head = tonut(head)
local done = false
local start = head
-- head is always begin of par (whatsit), so we have at least two prev nodes
-- penalty followed by glue
while start do
- local id = start.id
+ local id = getid(start)
if id == glyph_code then
- local attr = start[a_spacings]
+ local attr = getattr(start,a_spacings)
if attr and attr > 0 then
local data = mapping[attr]
if data then
- local char = start.char
+ local char = getchar(start)
local map = data.characters[char]
- start[a_spacings] = unsetvalue -- needed?
+ setattr(start,a_spacings,unsetvalue) -- needed?
if map then
local left = map.left
local right = map.right
local alternative = map.alternative
- local quad = quaddata[start.font]
- local prev = start.prev
+ local quad = quaddata[getfont(start)]
+ local prev = getprev(start)
if left and left ~= 0 and prev then
local ok = false
- local prevprev = prev.prev
+ local prevprev = getprev(prev)
if alternative == 1 then
local somespace = somespace(prev,true)
if somespace then
@@ -120,10 +132,10 @@ function spacings.handler(head)
done = true
end
end
- local next = start.next
+ local next = getnext(start)
if right and right ~= 0 and next then
local ok = false
- local nextnext = next.next
+ local nextnext = getnext(next)
if alternative == 1 then
local somepenalty = somepenalty(next,10000)
if somepenalty then
@@ -164,10 +176,10 @@ function spacings.handler(head)
start = end_of_math(start) -- weird, can return nil .. no math end?
end
if start then
- start = start.next
+ start = getnext(start)
end
end
- return head, done
+ return tonode(head), done
end
local enabled = false
@@ -218,6 +230,30 @@ end
-- interface
-commands.definecharacterspacing = spacings.define
-commands.setupcharacterspacing = spacings.setup
-commands.setcharacterspacing = spacings.set
+local implement = interfaces.implement
+
+implement {
+ name = "definecharacterspacing",
+ actions = spacings.define,
+ arguments = "string"
+}
+
+implement {
+ name = "setupcharacterspacing",
+ actions = spacings.setup,
+ arguments = {
+ "string",
+ "integer",
+ {
+ { "left", "number" },
+ { "right", "number" },
+ { "alternative", "integer" },
+ }
+ }
+}
+
+implement {
+ name = "setcharacterspacing",
+ actions = spacings.set,
+ arguments = "string"
+}