From 01646ba86ea5dc12418945a175f10f2cd8ececbf Mon Sep 17 00:00:00 2001 From: Anthony Fok Date: Sun, 7 Aug 2016 21:34:23 -0600 Subject: [PATCH] Reach the translation glyph node by traverse_id() 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 --- tex/gregoriotex.lua | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tex/gregoriotex.lua b/tex/gregoriotex.lua index 0685eae1d..ddeb62823 100644 --- a/tex/gregoriotex.lua +++ b/tex/gregoriotex.lua @@ -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) @@ -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}