Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reach the translation glyph node by traverse_id() #1201

Merged
merged 1 commit into from
Aug 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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