From cb00087b99a02db296d51ca30cfb444f1e002d86 Mon Sep 17 00:00:00 2001 From: Omikhleia Date: Tue, 30 Jan 2024 21:26:42 +0100 Subject: [PATCH] fix(packages): PDF links can now span multiple lines --- packages/pdf/init.lua | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/packages/pdf/init.lua b/packages/pdf/init.lua index 1f6b3a349..fbe58658b 100644 --- a/packages/pdf/init.lua +++ b/packages/pdf/init.lua @@ -54,32 +54,23 @@ function package:registerCommands () borderwidth = borderwidth, borderoffset = borderoffset } - local x0, y0 - SILE.typesetter:pushHbox({ - value = nil, - height = 0, - width = 0, - depth = 0, - outputYourself = function (_, typesetter, _) - x0 = typesetter.frame.state.cursorX:tonumber() - y0 = (SILE.documentState.paperSize[2] - typesetter.frame.state.cursorY):tonumber() + + SILE.typesetter:liner("pdf:link", content, + function (box, typesetter, line) + local x0 = typesetter.frame.state.cursorX:tonumber() + local y0 = (SILE.documentState.paperSize[2] - typesetter.frame.state.cursorY):tonumber() SILE.outputter:beginLink(dest, opts) - end - }) - local hbox, hlist = SILE.typesetter:makeHbox(content) -- hack - SILE.typesetter:pushHbox(hbox) - SILE.typesetter:pushHbox({ - value = nil, - height = 0, - width = 0, - depth = 0, - outputYourself = function (_, typesetter, _) + + -- Build the content. + -- Cursor will be moved by the actual definitive size. + box:outputContent(typesetter, line) local x1 = typesetter.frame.state.cursorX:tonumber() - local y1 = (SILE.documentState.paperSize[2] - typesetter.frame.state.cursorY + hbox.height):tonumber() + local y1 = (SILE.documentState.paperSize[2] - typesetter.frame.state.cursorY + box.height):tonumber() + SILE.outputter:endLink(dest, opts, x0, y0, x1, y1) -- Unstable API end - }) - SILE.typesetter:pushHlist(hlist) + ) + end) self:registerCommand("pdf:metadata", function (options, _)