Skip to content

Commit

Permalink
Merge pull request #1977 from Omikhleia/feat-liner-support
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Feb 2, 2024
2 parents f500be3 + 2fb363d commit bd0746e
Show file tree
Hide file tree
Showing 8 changed files with 335 additions and 79 deletions.
2 changes: 1 addition & 1 deletion languages/ja.lua
Expand Up @@ -149,7 +149,7 @@ function SILE.nodeMakers.ja:iterator (items)
intercharacterspace(lastcp, thiscp),
stretchability(lastcp, thiscp),
shrinkability(lastcp, thiscp)
)
):absolute()
if breakAllowed(lastcp, thiscp) then
db = db .." G ".. tostring(length)
coroutine.yield(SILE.nodefactory.glue(length))
Expand Down
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
32 changes: 16 additions & 16 deletions tests/bug-990.expected
Expand Up @@ -15,42 +15,42 @@ Mx 24.7039
My 124.9953
Set font Noto Sans CJK JP;22;800;;normal;;;LTR
T 29804 w=22.0000 (第)
Mx 46.7338
Mx 46.7477
T 19 w=12.2100 (2)
Mx 58.9737
Mx 59.0014
T 29653 w=22.0000 (章)
Mx 24.7039
My 151.1793
Mx 14.0360
T 44 a=14.2120 (K)
Mx 38.7475
Mx 38.7510
T 80 w=13.3320 (o)
Mx 52.0871
Mx 52.0941
T 79 w=13.4420 (n)
Mx 65.5366
Mx 65.5471
T 79 w=13.4420 (n)
Mx 78.9862
Mx 79.0002
T 74 w=6.0500 (i)
Mx 85.0437
Mx 85.0613
T 68 w=11.1980 (c)
Mx 96.2493
Mx 96.2703
T 73 w=13.3540 (h)
Mx 109.6109
Mx 109.6354
T 74 w=6.0500 (i)
Mx 121.5929
Mx 121.6209
T 41 w=16.0160 (H)
Mx 137.6165
Mx 137.6480
T 66 w=12.4080 (a)
Mx 155.9566
Mx 155.9916
T 52 w=13.1340 (S)
Mx 169.0981
Mx 169.1366
T 70 w=12.1880 (e)
Mx 181.2937
Mx 181.3357
Mx 11.9020
T 76 a=12.1440 (k)
Mx 193.2033
Mx 193.2488
T 66 w=12.4080 (a)
Mx 205.6188
Mx 205.6678
T 74 w=6.0500 (i)
Mx 24.7039
My 181.1157
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 bd0746e

Please sign in to comment.