Skip to content

Commit

Permalink
refactor(packages): Re-organize sheet size logic so errors happen in …
Browse files Browse the repository at this point in the history
…a more related function
  • Loading branch information
alerque committed Dec 13, 2023
1 parent 6b9573e commit d7c491b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
32 changes: 13 additions & 19 deletions classes/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,29 +87,11 @@ function class:setOptions (options)
options.papersize = nil
self.options.bleed = options.bleed or "0"
options.bleed = nil
self.options.sheetsize = options.sheetsize or nil
self.options.sheetsize = options.sheetsize or self.options.papersize
options.sheetsize = nil
for option, value in pairs(options) do
self.options[option] = value
end
if not SILE.documentState.sheetSize then
SILE.documentState.sheetSize = {
SILE.documentState.paperSize[1],
SILE.documentState.paperSize[2]
}
end
if SILE.documentState.sheetSize[1] < SILE.documentState.paperSize[1]
or SILE.documentState.sheetSize[2] < SILE.documentState.paperSize[2] then
SU.error("Sheet size shall not be smaller than the paper size")
end
if SILE.documentState.sheetSize[1] < SILE.documentState.paperSize[1] + SILE.documentState.bleed then
SU.debug("frames", "Sheet size width augmented to take page bleed into account")
SILE.documentState.sheetSize[1] = SILE.documentState.paperSize[1] + SILE.documentState.bleed
end
if SILE.documentState.sheetSize[2] < SILE.documentState.paperSize[2] + SILE.documentState.bleed then
SU.debug("frames", "Sheet size height augmented to take page bleed into account")
SILE.documentState.sheetSize[2] = SILE.documentState.paperSize[2] + SILE.documentState.bleed
end
end

function class:declareOption (option, setter)
Expand Down Expand Up @@ -154,6 +136,18 @@ function class:declareOptions ()
self.sheetsize = size
SILE.documentState.sheetSize = SILE.papersize(size, self.options.landscape)
end
if SILE.documentState.sheetSize[1] < SILE.documentState.paperSize[1]
or SILE.documentState.sheetSize[2] < SILE.documentState.paperSize[2] then
SU.error("Sheet size shall not be smaller than the paper size")
end
if SILE.documentState.sheetSize[1] < SILE.documentState.paperSize[1] + SILE.documentState.bleed then
SU.debug("frames", "Sheet size width augmented to take page bleed into account")
SILE.documentState.sheetSize[1] = SILE.documentState.paperSize[1] + SILE.documentState.bleed
end
if SILE.documentState.sheetSize[2] < SILE.documentState.paperSize[2] + SILE.documentState.bleed then
SU.debug("frames", "Sheet size height augmented to take page bleed into account")
SILE.documentState.sheetSize[2] = SILE.documentState.paperSize[2] + SILE.documentState.bleed
end
return self.sheetsize
end)
self:declareOption("bleed", function (_, dimen)
Expand Down
20 changes: 11 additions & 9 deletions documentation/c03-input.sil
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ It is even less true now that 3rd party plugins can add their own input formats.

Hence this chanpter has been renamed.
The original chapter title was "SILE’s Input Language", as if there was only one.
The truth is there \em{is} an input syntax we call "SIL", but even that is perhaps best thought of as a structured data systax rather than a unique language.
The truth is there \em{is} an input syntax we call "SIL", but even that is perhaps best thought of as a structured data syntax rather than a unique language.
The input strings \code{\\em\{foo\}} in SIL input syntax is 100\% equivalent to \code{<em>foo</em>} in XML input syntax.
The SIL input syntax is provided as an easier to type alternative than XML which can be a bit verbose and tedious to work with by hand.
On the other hand if you're handling data written by some other program, XML might be a much better solution.
Expand Down Expand Up @@ -61,6 +61,16 @@ Once some of the basic document properties have been set up using these fixed si
For example, once the paper size is set, percentage of page width (\code{\%pw}) and height(\code{\%ph}) become valid units.
In Chapter 4 we will meet more of these relative units, and in Chapter 7 we will meet some other ways of specifying lengths to make them stretchable or shrinkable.

\subsection{Setting orientation as landscape}

The orientation of the page is defined as "portrait" by default, but if you want to set it as landscape there is an option for that:

\begin[type=autodoc:codeblock]{raw}
\begin[landscape=true]{document}
\end{raw}

\subsection{Full bleed printing}

When preparing a book for press printing, you may be asked by the professional printer to output the document on a larger sheet than your target paper, and to reserve a trim area around it.
This trick is often called “full bleed printing”.
Your document will be printed on an oversized sheet that will then be mechanically cut down to the target size.
Expand All @@ -80,14 +90,6 @@ Finally, there is also the case when the actual paper sheets available to you ar

For instance, \code{papersize=6in x 9in, sheetsize=a4} produces an A4-dimensioned document, but with you content formatted as a 6 per 9 inches US trade book. You may, obviously, combine these options and also specify a bleed area.

\subsection{Setting orientation as landscape}

The orientation of the page is defined as "portrait" by default, but if you want to set it as landscape there is an option for that:

\begin[type=autodoc:codeblock]{raw}
\begin[landscape=true]{document}
\end{raw}

\section{Ordinary text}

On the whole, ordinary text isn’t particularly interesting—it’s just typeset.
Expand Down

0 comments on commit d7c491b

Please sign in to comment.