Skip to content

Commit

Permalink
Merge pull request #16 from Omikhleia/new-layout-system
Browse files Browse the repository at this point in the history
New layout system
  • Loading branch information
Omikhleia authored Mar 12, 2023
2 parents 0f61ff0 + fcd8228 commit d25cc41
Show file tree
Hide file tree
Showing 29 changed files with 2,066 additions and 363 deletions.
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,7 @@
[![Luarocks](https://img.shields.io/luarocks/v/Omikhleia/resilient.sile?label=Luarocks&logo=Lua)](https://luarocks.org/modules/Omikhleia/resilient.sile)

This collection of classes and packages for the [SILE](https://github.com/sile-typesetter/sile)
typesetting system provides advanced book classes and tools,

This is the successor of my previous “[Omikhleia’s classes & packages for SILE](https://github.com/Omikhleia/omikhleia-sile-packages)”,
fully redesigned for SILE v0.14 or upper, and provided as a separate installable module.

Besides all the changes from SILE v0.12 to v0.14 and its new package and class APIs, this redesign entails
many more things, with breaking changes (consider it as v2.0 of the former solution).

It therefore comes under a new name (also used as a namespace here and there), **resilient**.
The name is a pun on "SILE" (as, after all, the initial target was always on redoing a book class that would satisfy my
requirements), but there will be a bit more to it than that, which might become more visible when the collection
expands.
typesetting system provides advanced book classes and tools.

This collection offers:
- At its core, a challenging and interesting “styling” paradigm, allowing to configure many
Expand All @@ -35,7 +24,8 @@ These packages require SILE v0.14 or upper.

Installation relies on the **luarocks** package manager.

To install the latest development version and all its dependencies (see below), you may use the provided “rockspec”:
To install the latest development version and all its dependencies (see below),
you may use the provided “rockspec”:

```
luarocks --lua-version 5.4 install --server=https://luarocks.org/dev resilient.sile
Expand Down Expand Up @@ -68,6 +58,22 @@ This collection also imports several modules also provided separately, would you
When used with this collection, the Markdown packages and the fancy table of contents are
leveraged with additional capabilities.

## Historical note

This collection is the successor of the my “[Omikhleia’s classes & packages for SILE](https://github.com/Omikhleia/omikhleia-sile-packages)”,
fully redesigned for SILE v0.14 or upper, and provided as a separate installable module.

Besides all the changes from SILE v0.12 to v0.14, and its new package and class APIs,
the redesign entails many more things, with breaking changes
(consider it as v2.x of the former solution).

It therefore comes under a new name (also used as a namespace here and there),
**resilient**.
The name is a pun on "SILE" (as, after all, the initial target was always on
redoing a book class that would satisfy my requirements), but there will be a
bit more to it than that, which might become more visible when the collection
expands.

## License

All code is under the MIT License.
Expand Down
153 changes: 58 additions & 95 deletions classes/resilient/book.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,87 +8,7 @@ local class = pl.class(plain)
class._name = "resilient.book"

local utils = require("resilient.utils")

-- PAGE LAYOUT MASTERS

local layouts = {
-- Cannonical layout
canonical = function ()
local canonicalLayout = require("classes.resilient.layouts.canonical")
-- FIXME
-- https://github.com/sile-typesetter/sile/pull/1470 would define pageSize, maybe to
-- revisit at some point.
-- Also, passing the page dimensions is kind of a hack, see the function.
return canonicalLayout(SILE.documentState.paperSize[1], SILE.documentState.paperSize[2])
end,
-- Layout by division method
honnecourt = function ()
local divisionLayout = require("classes.resilient.layouts.division")
return divisionLayout(9, 2)
end,
vencentinus = function ()
local divisionLayout = require("classes.resilient.layouts.division")
return divisionLayout(6, 2)
end,
division = function ()
local divisionLayout = require("classes.resilient.layouts.division")
return divisionLayout(9)
end,
['division:6'] = function ()
local divisionLayout = require("classes.resilient.layouts.division")
return divisionLayout(6)
end,
['division:9'] = function ()
local divisionLayout = require("classes.resilient.layouts.division")
return divisionLayout(9)
end,
['division:12'] = function ()
local divisionLayout = require("classes.resilient.layouts.division")
return divisionLayout(12)
end,
-- Legacy (Omikhleia)
legacy = function ()
return {
content = {
left = "10%pw", -- was 8.3%pw
right = "87.7%pw", -- was 86%pw
top = "11.6%ph",
bottom = "top(footnotes)"
},
folio = {
left = "left(content)",
right = "right(content)",
top = "bottom(footnotes)+3%ph",
bottom = "bottom(footnotes)+5%ph"
},
header = {
left = "left(content)",
right = "right(content)",
top = "top(content)-5%ph", -- was -8%ph
bottom = "top(content)-2%ph" -- was -3%ph
},
footnotes = {
left = "left(content)",
right = "right(content)",
height = "0",
bottom = "86.3%ph" -- was 83.3%ph
}
}
end,
}

for m, n in pairs({ ateliers = 1/4, demiluxe = 1/3, deluxe = 3/8 }) do
layouts[m] = function ()
local frLayout = require("classes.resilient.layouts.frenchcanon")
return frLayout(n, 1)
end
for r = 1, 4 do
layouts[m..":"..r] = function ()
local frLayout = require("classes.resilient.layouts.frenchcanon")
return frLayout(n, r)
end
end
end
local layoutParser = require("resilient.layoutparser")

-- CLASS DEFINITION

Expand All @@ -98,12 +18,16 @@ function class:_init (options)
self:loadPackage("resilient.sectioning")
self:loadPackage("masters")
self:defineMaster({
id = "right",
firstContentFrame = self.firstContentFrame,
frames = self.defaultFrameset
})
id = "right",
firstContentFrame = self.firstContentFrame,
frames = self.oddFrameset
})
self:defineMaster({
id = "left",
firstContentFrame = self.firstContentFrame,
frames = self.evenFrameset
})
self:loadPackage("twoside", { oddPageMaster = "right", evenPageMaster = "left" })
self:mirrorMaster("right", "left")
self:loadPackage("resilient.tableofcontents")
if not SILE.scratch.headers then SILE.scratch.headers = {} end
self:loadPackage("resilient.footnotes", {
Expand Down Expand Up @@ -156,23 +80,38 @@ function class:declareOptions ()
end
return self.layout
end)

self:declareOption("offset", function(_, value)
if value then
self.offset = value
end
return self.offset
end)
end

function class:setOptions (options)
options = options or {}
options.layout = options.layout or "legacy"
options.layout = options.layout or "division"
plain:setOptions(options) -- so that papersize etc. get processed...

local layout = layouts[options.layout or "legacy"]
local layout = layoutParser:match(options.layout)
if not layout then
SU.warn("Unknown page layout '".. options.layout .. "', switching to legacy")
layout = layout.legacy
SU.warn("Unknown page layout '".. options.layout .. "', switching to division")
layout = layoutParser:match("division")
end

local offset = SU.cast("measurement", options.offset or "0")
layout:setOffset(offset)

-- Kind of a hack dues to restrictions with frame parsers.
layout:setPaperHack(SILE.documentState.paperSize[1], SILE.documentState.paperSize[2])

-- TRICKY, TO REMEMBER:
-- the default frameset has to be set before the completion of
-- the default frameset has to be set *before* the completion of
-- the base (plain) class init, or it isn't applied on the first
-- page...
self.defaultFrameset = layout(options)
self.oddFrameset, self.evenFrameset = layout:frameset()
self.defaultFrameset = self.oddFrameset
end

function class:registerStyles ()
Expand Down Expand Up @@ -327,7 +266,7 @@ function class:registerStyles ()

-- captioned elements
self:registerStyle("figure", {}, {
paragraph = { before = { skip = "smallskip" },
paragraph = { before = { skip = "smallskip", indent = false },
align = "center",
after = { vbreak = false } },
})
Expand Down Expand Up @@ -359,6 +298,7 @@ function class:registerStyles ()

self:registerStyle("table", {}, {
paragraph = { align = "center",
before = { indent = false },
after = { vbreak = false } },
})
self:registerStyle("table-caption", {}, {
Expand Down Expand Up @@ -417,7 +357,10 @@ function class:registerCommands ()
local closure = SILE.settings:wrap()
SILE.scratch.headers.even = function ()
closure(function ()
SILE.call("style:apply:paragraph", { name = "header-even" }, content)
SILE.call("style:apply:paragraph", { name = "header-even" }, function ()
SILE.call("strut", { method = "rule"})
SILE.process(content)
end)
end)
end
end, "Text to appear on the top of the even page(s).")
Expand All @@ -426,7 +369,10 @@ function class:registerCommands ()
local closure = SILE.settings:wrap()
SILE.scratch.headers.odd = function ()
closure(function ()
SILE.call("style:apply:paragraph", { name = "header-odd" }, content)
SILE.call("style:apply:paragraph", { name = "header-odd" }, function ()
SILE.call("strut", { method = "rule"})
SILE.process(content)
end)
end)
end
end, "Text to appear on the top of the odd page(s).")
Expand Down Expand Up @@ -574,6 +520,23 @@ function class:registerCommands ()

SILE.call("tableofcontents", { start = start, depth = 0 })
end, "Output the list of tables.")

-- Layouts

self:registerCommand("showlayout", function (options, _)
local spec = SU.required(options, "layout", "layout")
local papersize = SU.required(options, "papersize", "layout")
local parser = require("resilient.layoutparser")
local layout = parser:match(spec)
if not layout then
SU.error("Unrecognized layout '" .. spec .. "'")
end
local p = SILE.papersize(papersize)
local W = p[1]
local H = p[2]
layout:setPaperHack(W, H)
layout:draw(W, H, { ratio = options.ratio, rough = options.rough })
end, "Show a graphical representation of a page layout")
end

return class
57 changes: 0 additions & 57 deletions classes/resilient/layouts/canonical.lua

This file was deleted.

46 changes: 0 additions & 46 deletions classes/resilient/layouts/division.lua

This file was deleted.

Loading

0 comments on commit d25cc41

Please sign in to comment.