From d7c491b8720d706cac68ef3a8b4353368bda5a30 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 13 Dec 2023 15:25:38 +0300 Subject: [PATCH] refactor(packages): Re-organize sheet size logic so errors happen in a more related function --- classes/base.lua | 32 +++++++++++++------------------- documentation/c03-input.sil | 20 +++++++++++--------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/classes/base.lua b/classes/base.lua index 090d5cdc8e..e85eca56d2 100644 --- a/classes/base.lua +++ b/classes/base.lua @@ -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) @@ -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) diff --git a/documentation/c03-input.sil b/documentation/c03-input.sil index 16edf8e545..a8a42f390c 100644 --- a/documentation/c03-input.sil +++ b/documentation/c03-input.sil @@ -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{foo} 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. @@ -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. @@ -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.