Skip to content

Commit

Permalink
chore(classes,packages): Styling and small updates from SILE 0.15.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia authored and Didier Willis committed Jan 10, 2025
1 parent 07b03f4 commit 4e2e5e0
Show file tree
Hide file tree
Showing 9 changed files with 1,195 additions and 1,129 deletions.
1,040 changes: 543 additions & 497 deletions silex/classes/base.lua

Large diffs are not rendered by default.

85 changes: 45 additions & 40 deletions silex/packages/background/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,57 @@ package._name = "background"
local background = {}

local outputBackground = function ()
local pagea = SILE.getFrame("page")
local offset = SILE.documentState.bleed / 2
if type(background.bg) == "string" then
SILE.outputter:drawImage(background.bg,
pagea:left() - offset, pagea:top() - offset,
pagea:width() + 2 * offset, pagea:height() + 2 * offset)
elseif background.bg then
SILE.outputter:pushColor(background.bg)
SILE.outputter:drawRule(
pagea:left() - offset, pagea:top() - offset,
pagea:width() + 2 * offset, pagea:height() + 2 * offset)
SILE.outputter:popColor()
end
if not background.allpages then
background.bg = nil
end
local pagea = SILE.getFrame("page")
local offset = SILE.documentState.bleed / 2
if type(background.bg) == "string" then
SILE.outputter:drawImage(
background.bg,
pagea:left() - offset,
pagea:top() - offset,
pagea:width() + 2 * offset,
pagea:height() + 2 * offset
)
elseif background.bg then
SILE.outputter:pushColor(background.bg)
SILE.outputter:drawRule(
pagea:left() - offset,
pagea:top() - offset,
pagea:width() + 2 * offset,
pagea:height() + 2 * offset
)
SILE.outputter:popColor()
end
if not background.allpages then
background.bg = nil
end
end

function package:_init ()
base._init(self)
self.class:registerHook("newpage", outputBackground)
base._init(self)
self.class:registerHook("newpage", outputBackground)
end

function package:registerCommands ()
self:registerCommand("background", function (options, _)
if SU.boolean(options.disable, false) then
-- This option is certainly better than enforcing a white color.
background.bg = nil
return
end

self:registerCommand("background", function (options, _)
if SU.boolean(options.disable, false) then
-- This option is certainly better than enforcing a white color.
background.bg = nil
return
end

local allpages = SU.boolean(options.allpages, true)
background.allpages = allpages
local color = options.color and SILE.types.color(options.color)
local src = options.src
if src then
background.bg = src and SILE.resolveFile(src) or SU.error("Couldn't find file "..src)
elseif color then
background.bg = color
else
SU.error("background requires a color or an image src parameter")
end
outputBackground(SILE.scratch.background)
end, "Output a solid background color <color> or an image <src> on pages after initialization.")

local allpages = SU.boolean(options.allpages, true)
background.allpages = allpages
local color = options.color and SILE.types.color(options.color)
local src = options.src
if src then
background.bg = src and SILE.resolveFile(src) or SU.error("Couldn't find file " .. src)
elseif color then
background.bg = color
else
SU.error("background requires a color or an image src parameter")
end
outputBackground()
end, "Output a solid background color <color> or an image <src> on pages after initialization.")
end

package.documentation = [[
Expand All @@ -62,7 +67,7 @@ As its name implies, the \autodoc:package{background} package allows you to set
The package provides a \autodoc:command{\background} command which requires one of the following parameters:
\begin{itemize}
\item{\autodoc:parameter{color=<color specification>} sets the background of the current and all following pages to that color. The color specification has the same syntax as specified in the \autodoc:package{color} package.}
\item{\autodoc:parameter{src=<file>} sets the backgound of the current and all following pages to the specified image. The latter will be scaled to the target dimension.}
\item{\autodoc:parameter{src=<file>} sets the background of the current and all following pages to the specified image. The latter will be scaled to the target dimension.}
\end{itemize}
The background extends to the page trim area (“page bleed”) if the latter is defined.
Expand Down
28 changes: 13 additions & 15 deletions silex/packages/color/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ local package = pl.class(base)
package._name = "color"

function package:registerCommands ()

self:registerCommand("color", function (options, content)
local color = SILE.types.color(options.color or "black")
-- This is a bit of a hack to use a liner.
-- (Due to how the color stack is currently handled)
-- If the content spans multiple lines, and a page break occurs in between,
-- this avoids the color being propagated to other page content.
-- (folio, footnotes, etc.)
SILE.typesetter:liner("color", content, function (box, typesetter, line)
SILE.outputter:pushColor(color)
box:outputContent(typesetter, line)
SILE.outputter:popColor()
end)
end, "Changes the active ink color to the color <color>.")

self:registerCommand("color", function (options, content)
local color = SILE.types.color(options.color or "black")
-- This is a bit of a hack to use a liner.
-- (Due to how the color stack is currently handled)
-- If the content spans multiple lines, and a page break occurs in between,
-- this avoids the color being propagated to other page content.
-- (folio, footnotes, etc.)
SILE.typesetter:liner("color", content, function (box, typesetter, line)
SILE.outputter:pushColor(color)
box:outputContent(typesetter, line)
SILE.outputter:popColor()
end)
end, "Changes the active ink color to the color <color>.")
end

package.documentation = [[
Expand Down
120 changes: 60 additions & 60 deletions silex/packages/cropmarks/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,73 @@ package._name = "cropmarks"
local outcounter = 1

local function outputMarks ()
local page = SILE.getFrame("page")
-- Length of crop mark bars
local cropsz = 20
-- Ensure the crop marks stay outside the bleed area
local offset = math.max(10, SILE.documentState.bleed / 2)

SILE.outputter:drawRule(page:left() - offset, page:top(), -cropsz, 0.5)
SILE.outputter:drawRule(page:left(), page:top() - offset, 0.5, -cropsz)
SILE.outputter:drawRule(page:right() + offset, page:top(), cropsz, 0.5)
SILE.outputter:drawRule(page:right(), page:top() - offset, 0.5, -cropsz)
SILE.outputter:drawRule(page:left() - offset, page:bottom(), -cropsz, 0.5)
SILE.outputter:drawRule(page:left() , page:bottom() + offset, 0.5, cropsz)
SILE.outputter:drawRule(page:right() + offset, page:bottom(), cropsz, 0.5)
SILE.outputter:drawRule(page:right(), page:bottom() + offset, 0.5, cropsz)

local hbox, hlist = SILE.typesetter:makeHbox(function ()
SILE.settings:temporarily(function ()
SILE.call("noindent")
SILE.call("font", { size="6pt" })
if SILE.Commands["crop:header"] then
-- Deprecation shim:
-- If user redefined this command, still use it with a warning...
SU.deprecated("crop:header", "cropmarks:header", "0.15.0", "0.16.0")
SILE.call("crop:header")
else
SILE.call("cropmarks:header")
local page = SILE.getFrame("page")
-- Length of crop mark bars
local cropsz = 20
-- Ensure the crop marks stay outside the bleed area
local offset = math.max(10, SILE.documentState.bleed / 2)

SILE.outputter:drawRule(page:left() - offset, page:top(), -cropsz, 0.5)
SILE.outputter:drawRule(page:left(), page:top() - offset, 0.5, -cropsz)
SILE.outputter:drawRule(page:right() + offset, page:top(), cropsz, 0.5)
SILE.outputter:drawRule(page:right(), page:top() - offset, 0.5, -cropsz)
SILE.outputter:drawRule(page:left() - offset, page:bottom(), -cropsz, 0.5)
SILE.outputter:drawRule(page:left(), page:bottom() + offset, 0.5, cropsz)
SILE.outputter:drawRule(page:right() + offset, page:bottom(), cropsz, 0.5)
SILE.outputter:drawRule(page:right(), page:bottom() + offset, 0.5, cropsz)

local hbox, hlist = SILE.typesetter:makeHbox(function ()
SILE.settings:temporarily(function ()
SILE.call("noindent")
SILE.call("font", { size = "6pt" })
if SILE.Commands["crop:header"] then
-- Deprecation shim:
-- If user redefined this command, still use it with a warning...
SU.deprecated("crop:header", "cropmarks:header", "0.15.0", "0.16.0")
SILE.call("crop:header")
else
SILE.call("cropmarks:header")
end
end)
end)
if #hlist > 0 then
SU.error("Migrating content is forbidden in crop header")
end

SILE.typesetter.frame.state.cursorX = page:left() + offset
SILE.typesetter.frame.state.cursorY = page:top() - offset - 4
outcounter = outcounter + 1

if hbox then
for i = 1, #hbox.value do
hbox.value[i]:outputYourself(SILE.typesetter, { ratio = 1 })
end
end)
end)
if #hlist > 0 then
SU.error("Migrating content is forbidden in crop header")
end

SILE.typesetter.frame.state.cursorX = page:left() + offset
SILE.typesetter.frame.state.cursorY = page:top() - offset - 4
outcounter = outcounter + 1

if hbox then
for i = 1, #(hbox.value) do
hbox.value[i]:outputYourself(SILE.typesetter, { ratio = 1 })
end
end
end
end

function package:_init ()
base._init(self)
self:loadPackage("date")
base._init(self)
self:loadPackage("date")
end

function package:registerCommands ()

self:registerCommand("cropmarks:header", function (_, _)
local info = SILE.input.filenames[1]
.. " - "
.. self.class.packages.date:date({ format = "%x %X" })
.. " - " .. outcounter
SILE.typesetter:typeset(info)
end)

self:registerCommand("cropmarks:setup", function (_, _)
self.class:registerHook("endpage", outputMarks)
end)

self:registerCommand("crop:setup", function (_, _)
SU.deprecated("crop:setup", "cropmarks:setup", "0.15.10", "0.17.0")
SILE.call("cropmarks:setup")
end)
self:registerCommand("cropmarks:header", function (_, _)
local info = SILE.input.filenames[1]
.. " - "
.. self.class.packages.date:date({ format = "%x %X" })
.. " - "
.. outcounter
SILE.typesetter:typeset(info)
end)

self:registerCommand("cropmarks:setup", function (_, _)
self.class:registerHook("endpage", outputMarks)
end)

self:registerCommand("crop:setup", function (_, _)
SU.deprecated("crop:setup", "cropmarks:setup", "0.15.10", "0.17.0")
SILE.call("cropmarks:setup")
end)
end

package.documentation = [[
Expand Down
Loading

0 comments on commit 4e2e5e0

Please sign in to comment.