Skip to content
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

Landscape option added to base class #1892

Merged
merged 12 commits into from
Oct 23, 2023
10 changes: 9 additions & 1 deletion classes/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ end

function class:setOptions (options)
options = options or {}
self.options.landscape = options.landscape or false
jodros marked this conversation as resolved.
Show resolved Hide resolved
options.papersize = options.papersize or "a4"
for option, value in pairs(options) do
self.options[option] = value
Expand All @@ -101,10 +102,17 @@ function class:declareOptions ()
end
return self._name
end)
self:declareOption("landscape", function(_, landscape)
if landscape then
self.landscape = landscape
end
SILE.documentState.landscape = self.landscape
jodros marked this conversation as resolved.
Show resolved Hide resolved
return self.landscape
end)
self:declareOption("papersize", function (_, size)
if size then
self.papersize = size
SILE.documentState.paperSize = SILE.papersize(size)
SILE.documentState.paperSize = SILE.papersize(size, self.options.landscape)
SILE.documentState.orgPaperSize = SILE.documentState.paperSize
SILE.newFrame({
id = "page",
Expand Down
5 changes: 4 additions & 1 deletion core/papersize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ local papersize = {
}

setmetatable(papersize, {
__call = function (self, size)
__call = function (self, size, landscape)
local _, _, x, y = string.find(size, "(.+)%s+x%s+(.+)")
if x and y then
return { SILE.measurement(x):tonumber(), SILE.measurement(y):tonumber() }
else
size = string.lower(size:gsub("[-%s]+", ""))
if self[size] then
if SU.boolean(landscape) then
jodros marked this conversation as resolved.
Show resolved Hide resolved
self[size][1], self[size][2] = self[size][2], self[size][1]
end
return self[size]
end
end
Expand Down
8 changes: 8 additions & 0 deletions documentation/c03-input.sil
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ 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}

\section{Ordinary text}

On the whole, ordinary text isn’t particularly interesting—it’s just typeset.
Expand Down
8 changes: 8 additions & 0 deletions tests/landscape.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Set paper size 841.8897729 595.275597
Begin page
Mx 418.5987
My 553.7327
Set font Gentium Plus;10;400;;normal;;;LTR
T 20 w=4.6924 (1)
End page
Finish
2 changes: 2 additions & 0 deletions tests/landscape.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\begin[landscape=true]{document}
\end{document}
Loading