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

sile-typesetter / sile / 9409557472

07 Jun 2024 12:09AM UTC coverage: 69.448% (-4.5%) from 73.988%
9409557472

push

github

alerque
fix(build): Distribute vendored compat-5.3.c source file

12025 of 17315 relevant lines covered (69.45%)

6023.46 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
46

47
      local allpages = SU.boolean(options.allpages, true)
×
48
      background.allpages = allpages
×
49
      local color = options.color and SILE.types.color(options.color)
×
50
      local src = options.src
×
51
      if src then
×
52
         background.bg = src and SILE.resolveFile(src) or SU.error("Couldn't find file " .. src)
×
53
      elseif color then
×
54
         background.bg = color
×
55
      else
56
         SU.error("background requires a color or an image src parameter")
×
57
      end
58
      outputBackground()
×
59
   end, "Output a solid background color <color> or an image <src> on pages after initialization.")
×
60
end
61

62
package.documentation = [[
63
\begin{document}
64
\use[module=packages.background]
65
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.
66

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

73
The background extends to the page trim area (“page bleed”) if the latter is defined.
74
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.
75
If setting only the current page background different from the default is desired, an extra parameter \autodoc:parameter{allpages=false} can be passed.
76

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

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

85
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

© 2025 Coveralls, Inc