Skip to content

Commit

Permalink
refactor(class)!: Replace open-page with open-spread
Browse files Browse the repository at this point in the history
The open-page function had all sorts of edge case issues (both similar
to SILE's issues and unique to itself). This uses a completely different
mechanism with pagend hooks to track progress.

BREAKING CHANGE: The open-page function has been removed, but
open-spread is not a drop in replacement for all previous usage because
it will force an even page opening if odd is false.
  • Loading branch information
alerque committed Sep 30, 2021
1 parent ec2dda6 commit 0338f17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
22 changes: 12 additions & 10 deletions casile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,25 +208,27 @@ SILE.registerCommand("tocentry", function (options, content)
})
end)

-- This is the same as SILE's version but sets our no-headers variable on blank pages
-- ...and allows opening to an even page
SILE.registerCommand("open-page", function (options)
-- This is similar to SILE's open-double-page, but disables headers and folios
-- on blank pages and allows opening the even side (with or without a leading blank)
SILE.registerCommand("open-spread", function (options)
local odd = SU.boolean(options.odd, not CASILE.isScreenLayout())
local double = SU.boolean(options.double, not CASILE.isScreenLayout())
local class = SILE.documentState.documentClass
local count = 0
local pageHook = function () count = count + 1 end
SILE.typesetter:registerPageEndHook(pageHook)
repeat
SILE.typesetter:leaveHmode()
if count > 0 then
SILE.typesetter:typeset("")
SILE.call("hbox")
SILE.typesetter:leaveHmode()
SILE.scratch.headers.skipthispage = true
SILE.scratch.counters.folio.off = 2
end
SILE.typesetter:leaveHmode()
SILE.call("supereject")
count = count + 1
until (not double or count > 1) and (not odd or class:oddPage())
SILE.typesetter:leaveHmode()
SILE.typesetter:leaveHmode()
until (not double or count > 1) and (odd and class:oddPage()) or (not odd and not class:oddPage())
table.remove(SILE.typesetter.hooks.pageend)
end)

SILE.registerCommand("chaptertoc", function (_, _)
Expand Down Expand Up @@ -515,9 +517,9 @@ SILE.registerCommand("seriespage:series", function (_, content)
end)

SILE.registerCommand("seriespage:pre", function (_, _)
SILE.call("open-page")
SILE.call("open-spread", { odd = true, double = true })
SILE.scratch.headers.skipthispage = true
SILE.call("nofolios")
SILE.scratch.counters.folio.off = 2
SILE.call("topfill")
end)

Expand Down
1 change: 1 addition & 0 deletions upgrade-lua.sed
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ s#nodefactory\.zeroGlue#nodefactory.glue()#g
s#nodefactory\.zeroVglue#nodefactory.zerovglue()#g
s#nodefactory\.hfillGlue#nodefactory.hfillglue()#g
s#SILE\.length\.\(make\|new\|parse\)#SILE.length#g
s#\bopen-page\b#open-spread#g

0 comments on commit 0338f17

Please sign in to comment.