Skip to content

Commit

Permalink
Merge dab0461 into a493c26
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia committed Feb 1, 2024
2 parents a493c26 + dab0461 commit 80d9fbb
Show file tree
Hide file tree
Showing 6 changed files with 318 additions and 62 deletions.
17 changes: 10 additions & 7 deletions packages/color/init.lua
Expand Up @@ -7,13 +7,16 @@ function package:registerCommands ()

self:registerCommand("color", function (options, content)
local color = SILE.color(options.color or "black")
SILE.typesetter:pushHbox({
outputYourself = function () SILE.outputter:pushColor(color) end
})
SILE.process(content)
SILE.typesetter:pushHbox({
outputYourself = function () SILE.outputter:popColor() end
})
-- This is a bit of a hack to use a liner.
-- (Due to how the color stack is currently handled)
-- If the content spans multiple lines, and a page break occurs in between,
-- this avoids the color being propagated to other page content.
-- (folio, footnotes, etc.)
SILE.typesetter:liner("color", content, function (box, typesetter, line)
SILE.outputter:pushColor(color)
box:outputContent(typesetter, line)
SILE.outputter:popColor()
end)
end, "Changes the active ink color to the color <color>.")

end
Expand Down
35 changes: 13 additions & 22 deletions packages/pdf/init.lua
Expand Up @@ -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, _)
Expand Down
42 changes: 14 additions & 28 deletions packages/rules/init.lua
Expand Up @@ -126,22 +126,14 @@ function package:registerCommands ()
self:registerCommand("underline", function (_, content)
local underlinePosition, underlineThickness = getUnderlineParameters()

local hbox, hlist = SILE.typesetter:makeHbox(content)
-- Re-wrap the hbox in another hbox responsible for boxing it at output
-- time, when we will know the line contribution and can compute the scaled width
-- of the box, taking into account possible stretching and shrinking.
SILE.typesetter:pushHbox({
inner = hbox,
width = hbox.width,
height = hbox.height,
depth = hbox.depth,
outputYourself = function (node, typesetter, line)
SILE.typesetter:liner("underline", content,
function (box, typesetter, line)
local oldX = typesetter.frame.state.cursorX
local Y = typesetter.frame.state.cursorY

-- Build the original hbox.
-- Build the content.
-- Cursor will be moved by the actual definitive size.
node.inner:outputYourself(SILE.typesetter, line)
box:outputContent(typesetter, line)
local newX = typesetter.frame.state.cursorX

-- Output a line.
Expand All @@ -150,36 +142,28 @@ function package:registerCommands ()
-- should expand downwards
SILE.outputter:drawRule(oldX, Y - underlinePosition, newX - oldX, underlineThickness)
end
})
SILE.typesetter:pushHlist(hlist)
)
end, "Underlines some content")

self:registerCommand("strikethrough", function (_, content)
local yStrikeoutPosition, yStrikeoutSize = getStrikethroughParameters()

local hbox, hlist = SILE.typesetter:makeHbox(content)
-- Re-wrap the hbox in another hbox responsible for boxing it at output
-- time, when we will know the line contribution and can compute the scaled width
-- of the box, taking into account possible stretching and shrinking.
SILE.typesetter:pushHbox({
inner = hbox,
width = hbox.width,
height = hbox.height,
depth = hbox.depth,
outputYourself = function (node, typesetter, line)
SILE.typesetter:liner("strikethrough", content,
function (box, typesetter, line)
local oldX = typesetter.frame.state.cursorX
local Y = typesetter.frame.state.cursorY
-- Build the original hbox.

-- Build the content.
-- Cursor will be moved by the actual definitive size.
node.inner:outputYourself(SILE.typesetter, line)
box:outputContent(typesetter, line)
local newX = typesetter.frame.state.cursorX

-- Output a line.
-- NOTE: The OpenType spec is not explicit regarding how the size
-- (thickness) affects the position. We opt to distribute evenly
SILE.outputter:drawRule(oldX, Y - yStrikeoutPosition - yStrikeoutSize / 2, newX - oldX, yStrikeoutSize)
end
})
SILE.typesetter:pushHlist(hlist)
)
end, "Strikes out some content")

self:registerCommand("boxaround", function (_, content)
Expand Down Expand Up @@ -237,6 +221,8 @@ The \autodoc:command{\underline} command \underline{underlines} its content.
The \autodoc:command{\strikethrough} command \strikethrough{strikes} its content.
Both commands support paragraph content spanning multiple lines.
\autodoc:note{The position and thickness of the underlines and strikethroughs are based on the metrics of the current font, honoring the values defined by the type designer.}
The \autodoc:command{\hrulefill} inserts an infinite horizontal rubber, similar to an \autodoc:command{\hfill}, but—as its name implies—filled with a rule (that is, a solid line).
Expand Down
29 changes: 29 additions & 0 deletions tests/feat-liner-spanning.expected
@@ -0,0 +1,29 @@
Set paper size 297.6377985 419.5275636
Begin page
Mx 14.8819
My 31.5721
Set font Gentium Plus;14;400;;normal;;;LTR
T 86 87 85 76 78 72 w=32.8604 (strike)
Mx 52.5440
T 86 87 85 76 78 72 w=32.8604 (strike)
Mx 90.2061
T 86 87 85 76 78 72 w=32.8604 (strike)
Mx 127.8682
T 86 87 85 76 78 72 w=32.8604 (strike)
Mx 165.5303
T 88 81 71 72 85 79 76 81 72 w=56.2119 (underline)
Mx 226.5440
T 88 81 71 72 85 79 76 81 72 w=56.2119 (underline)
Draw line 165.5303 33.2811 117.2256 0.6836
Draw line 14.8819 27.8123 267.8740 0.6836
Mx 14.8819
My 48.3721
T 88 81 71 72 85 79 76 81 72 w=56.2119 (underline)
Draw line 14.8819 50.0811 56.2119 0.6836
Mx 74.2034
T 86 87 85 76 78 72 w=32.8604 (strike)
Mx 107.0638
T 17 w=3.2061 (.)
Draw line 14.8819 44.6123 95.3879 0.6836
End page
Finish
13 changes: 13 additions & 0 deletions tests/feat-liner-spanning.sil
@@ -0,0 +1,13 @@
\begin[papersize=a6]{document}
\neverindent
\nofolios
\set[parameter=shaper.spaceenlargementfactor, value=1]
\script[src=packages/rules]
\font[size=14pt]
% strikethrough and underline can span multiple lines
% Here line-breaking (paragraphing) occurs in the underlined sequence.
\strikethrough{strike strike strike strike
\underline{underline underline underline} strike.}

\end{document}

0 comments on commit 80d9fbb

Please sign in to comment.