Skip to content

Commit

Permalink
fix(packages): Tests for bug #724
Browse files Browse the repository at this point in the history
Updates to the justification alternates support. Closes #724.
  • Loading branch information
simoncozens committed Dec 4, 2019
1 parent 3556320 commit 9ccdca2
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
Binary file modified examples/packages/gutenberg.pdf
Binary file not shown.
8 changes: 5 additions & 3 deletions examples/packages/gutenberg.sil
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
\script[src=packages/color]%
\script[src=packages/rules]%
\define[command=lig-ll]{\color[color=red]{\unichar{U+F4F9}}}%
\define[command=nolig-fi]{f{}i}
\define[command=lig-Th]{\color[color=red]{\font[features=+dlig]{Th}}}%
\define[command=nolig-fi]{\color[color=red]{f{}i}}
\define[command=ll]{\alt{{ll}{\lig-ll}}}
\define[command=fi]{\alt{{fi}{\nolig-fi}}}
\define[command=Th]{\alt{{Th}{\lig-Th}}}
\define[command=nil]{}
\define[command=and]{\alt{{and}{&}}}
\define[command=ospace]{\alt{{\nil}{\glue[width=0.16667em]}}}
\define[command=ospace]{\alt{{\nil}{\color[color=red]{\hrule[height=0.01em,width=0.16667em]}}}}
\font[family=EB Garamond,size=11pt]%

\par
It has to be added that of all Gutenberg’s 290 B42-types, there are many ligatures and abbreviations, while the number of single characters with varying widths is small. (See illustration here.) The use of ligatures and abbreviations was absolutely crucial for Gutenberg’s justification technique, which could not be realized by narrower types only.

\medskip\noindent\hrule[width=115mm,height=0.25mm]\medskip\indent\par

It has to be added that of a\ll Gutenberg’s 290 B42-types\ospace, there are many ligatures \and abbreviations\ospace, while the number of single characters with varying widths is sma\ll\ospace. (See i\ll{}ustration here\ospace.) The use of ligatures \and abbreviations was absolutely crucial for Gutenberg’s justi\fi{}cation technique\ospace, which could not be realized by narrower types only\ospace.
It has to be added that of all Gutenberg’s 290 B42-types\ospace, there are many ligatures \and abbreviations\ospace, while the number of single characters with varying widths is small\ospace. (See i\ll{}ustration here\ospace.) \Th{}e use of ligatures \and abbreviations was absolutely crucial for Gutenberg’s justi\fi{}cation technique\ospace, which could not be realized by narrower types only\ospace.

\end{document}
46 changes: 45 additions & 1 deletion packages/gutenberg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,50 @@ SILE.registerCommand("alt", function (_, content)
options=options,
selected=1
})
alt.width=nil
SILE.typesetter.state.nodes[#SILE.typesetter.state.nodes+1] = alt
end)

local bidi = require("packages/bidi")
SILE.registerCommand("process-jalt", function (_, content)
local pretty = require("pl.pretty")
-- Process normally
local saveTypesetter = SILE.typesetter
SILE.typesetter = SILE.defaultTypesetter {}
SILE.typesetter:init(saveTypesetter.frame)
SILE.process(content)
SILE.typesetter:shapeAllNodes(SILE.typesetter.state.nodes)
table.remove(SILE.typesetter.state.nodes,1)
table.remove(SILE.typesetter.state.nodes,1)
-- Do bidi
bidi.reorder(SILE.typesetter.state, SILE.typesetter)
local nodes1 = SILE.typesetter.state.nodes

-- Process with +JALT
SILE.typesetter = SILE.defaultTypesetter {}
SILE.typesetter:init(saveTypesetter.frame)
local nodes2
SILE.settings.temporarily(function ()
SILE.settings.set("font.features", "+jalt")
SILE.process(content)
SILE.typesetter:shapeAllNodes(SILE.typesetter.state.nodes)
table.remove(SILE.typesetter.state.nodes,1)
table.remove(SILE.typesetter.state.nodes,1)
bidi.reorder(SILE.typesetter.state, SILE.typesetter)
nodes2 = SILE.typesetter.state.nodes
end)

-- Check if lengths are different...
SILE.typesetter = saveTypesetter
for i = 1,#nodes1 do
if nodes1[i]:isGlue() or (nodes1[i].width == nodes2[i].width) then
SILE.typesetter:pushHorizontal(nodes1[i])
else
local alt = SILE.nodefactory.newAlternative({
options= { nodes1[i], nodes2[i] },
selected=1
})
alt.bidiDone = true
SILE.typesetter:pushHorizontal(alt)
end
end
end)
15 changes: 13 additions & 2 deletions tests/bug-724.expected
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@ Mx 368.0824
My 34.7638
Set font Gentium Plus;30;400;;normal;;LTR
T 69 69 (bb)
Draw line 20.9764 65.7638 50.0000 5.0000
Mx 70.9764
Draw line 20.9764 65.7638 330.0000 5.0000
Mx 350.9764
My 70.7638
T 17 (.)
Draw line 20.9764 101.7638 330.0000 5.0000
Mx 368.0824
My 106.7638
T 69 69 (bb)
Draw line 20.9764 137.7638 330.0000 5.0000
My 142.7638
T 69 69 (bb)
Draw line 20.9764 173.7638 50.0000 5.0000
Mx 70.9764
My 178.7638
T 17 (.)
End page
Finish
3 changes: 2 additions & 1 deletion tests/bug-724.sil
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
\nofolios%
\nohyphenation\noindent%
\font[size=30pt]%
\hrule[width=330pt,height=5pt] \alt{a}{bb} \hrule[width=50pt,height=5pt].
\hrule[width=330pt,height=5pt] \alt{a}{bb} \hrule[width=330pt,height=5pt].

\noindent\hrule[width=330pt,height=5pt] {\alt{a}{bb}} \hrule[width=330pt,height=5pt] \alt{a}{bb} \hrule[width=50pt,height=5pt].

\end{document}

0 comments on commit 9ccdca2

Please sign in to comment.