Skip to content

Commit

Permalink
Reach the translation glyph node by traverse_id()
Browse files Browse the repository at this point in the history
LuaTeX-ja prepends custom whatsit nodes to store e.g. text direction,
breaking hard-coded paths like startnode.head.next.head.next.head
in the center_translation() function.

This patch uses node.travese_id() to find our desired nodes instead.

Fixes #1180
  • Loading branch information
anthonyfok committed Aug 8, 2016
1 parent 5f3023b commit 01646ba
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions tex/gregoriotex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ local function dump_nodes(head)
log('--end dump--')
end

-- helper function for center_translation()
local function get_first_node_by_id(id, head)
for n in traverse_id(id, head) do
return n
end
end

local function center_translation(startnode, endnode, ratio, sign, order)
-- total width between beginning the two centering points
local total_width = node.dimensions(ratio, sign, order, startnode, endnode)
Expand All @@ -321,12 +328,23 @@ local function center_translation(startnode, endnode, ratio, sign, order)
-- \kern 0pt
-- }
--
-- While normally we could use startnode.head.next.head.next.head
-- to reach the translation (glyph node), packages such as LuaTeX-ja
-- may have, for example, prepended a whatsit node to each list
-- to store e.g. text direction, moving our translation glyph node to
-- startnode.head.next.next.head.next.next.head.next instead.
--
-- To avoid unpleasant surprises, let's search for each desired node
-- by its type:
local vlistnode = get_first_node_by_id(vlist, startnode.head)
local hlistnode = get_first_node_by_id(hlist, vlistnode.head)
local glyphnode = get_first_node_by_id(glyph, hlistnode.head)
-- hence translation width is:
local trans_width = node.dimensions(startnode.head.next.head.next.head)
local trans_width = node.dimensions(glyphnode)
-- now we must transform the kern 0pt into kern Xpt and kern -Xpt where X is:
local X = (total_width - trans_width) / 2
startnode.head.kern = X
startnode.head.next.next.kern = -X
vlistnode.prev.kern = X
vlistnode.next.kern = -X
end

local debug_types_activated = {['linesglues'] = false}
Expand Down

0 comments on commit 01646ba

Please sign in to comment.