-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Enhance parallel package with overflow frame alignment, footnote handling and improved documentation #2216
base: master
Are you sure you want to change the base?
Enhance parallel package with overflow frame alignment, footnote handling and improved documentation #2216
Changes from 1 commit
ab528f7
1b5ba3c
a112bb0
3c131aa
d4547e3
b43a94d
309d258
dc65468
6bdb280
76dbd72
822ab59
b39badd
c956df4
e62e758
87f5707
dbe9129
55c0d85
7d64213
e597937
2d399c2
12ea0eb
8784dc6
22018f9
1099151
1560349
c78bde3
9154935
24e6b6d
ccbb79b
50a5956
47e73c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ package._name = "parallel" | |
|
||
-- Helper function for logging | ||
local log = function(...) | ||
local args = {...} | ||
local args = { ... } | ||
SU.debug(package._name, unpack(args)) | ||
end | ||
|
||
|
@@ -63,43 +63,49 @@ end | |
-- The height calculation includes the glyph heights and the baseline skip setting. | ||
local calculateLineHeight = function(sampleText) | ||
local glyphs = SILE.shaper:shapeToken(sampleText, SILE.font.loadDefaults({})) | ||
local baselineSkip = SILE.settings:get("document.baselineskip").height | ||
return glyphs[1].height + glyphs[2].depth + baselineSkip:tonumber() | ||
local lineSkip = SILE.settings:get("document.lineskip").height | ||
return glyphs[1].height + glyphs[2].depth + lineSkip:tonumber() | ||
end | ||
|
||
-- Generate dummy content to fill overflowed frames up to the specified height. | ||
-- Create dummy content to fill up the overflowed frames. | ||
local createDummyContent = function(height, frame, offset) | ||
-- Retrieve the typesetter for the given frame. | ||
-- Get the typesetter for the frame | ||
local typesetter = typesetterPool[frame] | ||
|
||
-- Determine the line height using a sample line or fallback to baseline and line skip settings. | ||
-- local lineHeight = calculateLineHeight("hg") | ||
-- Calculate precise line height by typesetting a sample line | ||
-- local lineHeight = calculateLineHeight("hp") | ||
|
||
-- If lineHeight cannot be calculated, use document's baselineSkip and lineSkip as fallback. | ||
-- log("Precise lineHeight after simulation = ", lineHeight) | ||
|
||
-- If lineHeight could not be calculated, fall back to baselineSkip and lineSkip of the document | ||
if not lineHeight then | ||
local baselineSkip = SILE.settings:get("document.baselineskip").height or SILE.types.length({ length = 0 }) | ||
local lineSkip = SILE.settings:get("document.lineskip").height or SILE.types.length({ length = 0 }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem here is that depending on the linespacing algorithm (the default one is more or less the TeX one), the lineskip is used conditionally (when boxes are greater than the baselineskip and would collide vertically), not always. In most cases (i.e. regular text with decent settings for the baselineskip), the lineskip isn't applied. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, the default one doesn't work as expected and eliminating the |
||
lineHeight = baselineSkip:tonumber() + lineSkip:tonumber() | ||
-- log("Precise lineHeight based on document.baselineskip = ", lineHeight) | ||
end | ||
|
||
-- Calculate the number of lines required to fill the specified height. | ||
local numLines = math.floor(height:tonumber() / lineHeight) | ||
-- Calculate the number of lines needed | ||
local requiredLines = height:tonumber() / lineHeight | ||
local numLines = math.floor(requiredLines) | ||
local remainingHeight = requiredLines - numLines | ||
|
||
-- Ensure offset is valid; warn if it exceeds the number of lines. | ||
-- Validate offset | ||
offset = offset or 0 | ||
if offset >= numLines then | ||
if numLines <= offset then | ||
SU.warn("Offset is larger than the number of lines available; no dummy content will be generated.") | ||
return | ||
end | ||
|
||
-- Fill the frame with dummy content using white-colored text to avoid visible output. | ||
-- Add dummy content to fill the frame | ||
SILE.call("color", { color = "white" }, function() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understand what you are trying with this dummy content, but "white-colored" text is a dubious solution.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying for fun without much knowledge about how SILE handle things behind the scene. Dummy white coloured text was the only solution I could think of, but the dirty way works quite ok. I knew it would not be a proper way to handle overflow. I did not know that Very grateful for these tricks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Would you mind having a play with my Parallel Typesetting settings? I've found that using real dummy text or hard glue works best for me. I’ve tried all of your suggestions, and they work quite well with some manual adjustments in my document, such as adding My understanding of SILE is still a work in progress, so sometimes I don't know how or why something works when I mess around with it. You flagged it as dubious… 😉 For me, it was just a stroke of luck! |
||
typesetter:typeset("sile") | ||
for i = 1, numLines - offset do | ||
SILE.call("break") | ||
-- Add dummy content and a line break | ||
typesetter:typeset("sile") | ||
SILE.call("break") | ||
end | ||
end) | ||
typesetter:pushExplicitVglue(SILE.types.length(remainingHeight)) | ||
end | ||
|
||
-- Balance the heights of frames by adding dummy content to shorter frames. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SILE.types.length({ length = 0 })
-> you can just writeSILE.types.length()
(zero by default)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your tip. I will use that in the future. I can't find a manual for SILE's internals, and find it hard to get things right. I should come back to farming rather than diving into this crazy field ;)