• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 14284237390

05 Apr 2025 05:33PM UTC coverage: 63.158% (+31.8%) from 31.375%
14284237390

push

github

web-flow
Merge pull request #2248 from alerque/class-warfare

Normalize module layout across all module types

257 of 350 new or added lines in 14 files covered. (73.43%)

71 existing lines in 11 files now uncovered.

13670 of 21644 relevant lines covered (63.16%)

3070.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/background/init.lua
1
local base = require("packages.base")
×
2

3
local package = pl.class(base)
×
4
package._name = "background"
×
5

6
local background = {}
×
7

8
local outputBackground = function ()
9
   local pagea = SILE.getFrame("page")
×
10
   local offset = SILE.documentState.bleed / 2
×
11
   if type(background.bg) == "string" then
×
12
      SILE.outputter:drawImage(
×
13
         background.bg,
×
14
         pagea:left() - offset,
×
15
         pagea:top() - offset,
×
16
         pagea:width() + 2 * offset,
×
17
         pagea:height() + 2 * offset
×
18
      )
19
   elseif background.bg then
×
20
      SILE.outputter:pushColor(background.bg)
×
21
      SILE.outputter:drawRule(
×
22
         pagea:left() - offset,
×
23
         pagea:top() - offset,
×
24
         pagea:width() + 2 * offset,
×
25
         pagea:height() + 2 * offset
×
26
      )
27
      SILE.outputter:popColor()
×
28
   end
29
   if not background.allpages then
×
30
      background.bg = nil
×
31
   end
32
end
33

34
function package:_init ()
×
35
   base._init(self)
×
36
   self.class:registerHook("newpage", outputBackground)
×
37
end
38

39
function package:registerCommands ()
×
40
   self:registerCommand("background", function (options, _)
×
41
      if SU.boolean(options.disable, false) then
×
42
         -- This option is certainly better than enforcing a white color.
43
         background.bg = nil
×
44
         return
×
45
      end
UNCOV
46
      local allpages = SU.boolean(options.allpages, true)
×
47
      background.allpages = allpages
×
48
      local color = options.color and SILE.types.color(options.color)
×
49
      local src = options.src
×
50
      if src then
×
51
         background.bg = src and SILE.resolveFile(src) or SU.error("Couldn't find file " .. src)
×
52
      elseif color then
×
53
         background.bg = color
×
54
      else
55
         SU.error("background requires a color or an image src parameter")
×
56
      end
57
      outputBackground()
×
58
   end, "Output a solid background color <color> or an image <src> on pages after initialization.")
×
59
end
60

61
package.documentation = [[
62
\begin{document}
63
\use[module=packages.background]
64
As its name implies, the \autodoc:package{background} package allows you to set the color of the page canvas background or to use a background image extending to the full page width and height.
65

66
The package provides a \autodoc:command{\background} command which requires one of the following parameters:
67
\begin{itemize}
68
\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.}
69
\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.}
70
\end{itemize}
71

72
The background extends to the page trim area (“page bleed”) if the latter is defined.
73
This is to ensure that it indeed “bleeds” off the sides of the page, so as to avoid thin white lignes on an otherwise full color page when the paper sheet is cut to dimension but some pages are trimmed slightly more than others.
74
If setting only the current page background different from the default is desired, an extra parameter \autodoc:parameter{allpages=false} can be passed.
75

76
\background[color=#e9d8ba,allpages=false]
77

78
So, for example, \autodoc:command{\background[color=#e9d8ba,allpages=false]} will set a sepia tone background on the current page.
79
The \autodoc:parameter{disable=true} parameter allows disabling the background on the following pages.
80
It may be useful when \autodoc:parameter{allpages} is active from a previous invocation.
81
\end{document}
82
]]
×
83

84
return package
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc