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

sile-typesetter / sile / 9304060604

30 May 2024 02:07PM UTC coverage: 74.124% (-0.6%) from 74.707%
9304060604

push

github

alerque
style: Reformat Lua with stylua

8104 of 11995 new or added lines in 184 files covered. (67.56%)

15 existing lines in 11 files now uncovered.

12444 of 16788 relevant lines covered (74.12%)

7175.1 hits per line

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

94.2
/packages/cropmarks/init.lua
1
local base = require("packages.base")
1✔
2

3
local package = pl.class(base)
1✔
4
package._name = "cropmarks"
1✔
5

6
local outcounter = 1
1✔
7

8
local function outputMarks ()
9
   local page = SILE.getFrame("page")
2✔
10
   SILE.outputter:drawRule(page:left() - 10, page:top(), -10, 0.5)
8✔
11
   SILE.outputter:drawRule(page:left(), page:top() - 10, 0.5, -10)
8✔
12
   SILE.outputter:drawRule(page:right() + 10, page:top(), 10, 0.5)
8✔
13
   SILE.outputter:drawRule(page:right(), page:top() - 10, 0.5, -10)
8✔
14
   SILE.outputter:drawRule(page:left() - 10, page:bottom(), -10, 0.5)
8✔
15
   SILE.outputter:drawRule(page:left(), page:bottom() + 10, 0.5, 10)
8✔
16
   SILE.outputter:drawRule(page:right() + 10, page:bottom(), 10, 0.5)
8✔
17
   SILE.outputter:drawRule(page:right(), page:bottom() + 10, 0.5, 10)
8✔
18

19
   local hbox, hlist = SILE.typesetter:makeHbox(function ()
4✔
20
      SILE.settings:temporarily(function ()
4✔
21
         SILE.call("noindent")
2✔
22
         SILE.call("font", { size = "6pt" })
2✔
23
         SILE.call("crop:header")
2✔
24
      end)
25
   end)
26
   if #hlist > 0 then
2✔
NEW
27
      SU.error("Forbidden migrating content in crop header")
×
28
   end
29

30
   SILE.typesetter.frame.state.cursorX = page:left() + 10
6✔
31
   SILE.typesetter.frame.state.cursorY = page:top() - 13
6✔
32
   outcounter = outcounter + 1
2✔
33

34
   if hbox then
2✔
35
      for i = 1, #hbox.value do
18✔
36
         hbox.value[i]:outputYourself(SILE.typesetter, { ratio = 1 })
16✔
37
      end
38
   end
39
end
40

41
local function reconstrainFrameset (fs)
42
   for n, f in pairs(fs) do
6✔
43
      if n ~= "page" then
4✔
44
         if f:isAbsoluteConstraint("right") then
8✔
45
            f.constraints.right = "left(page) + (" .. f.constraints.right .. ")"
2✔
46
         end
47
         if f:isAbsoluteConstraint("left") then
8✔
48
            f.constraints.left = "left(page) + (" .. f.constraints.left .. ")"
2✔
49
         end
50
         if f:isAbsoluteConstraint("top") then
8✔
51
            f.constraints.top = "top(page) + (" .. f.constraints.top .. ")"
2✔
52
         end
53
         if f:isAbsoluteConstraint("bottom") then
8✔
54
            f.constraints.bottom = "top(page) + (" .. f.constraints.bottom .. ")"
2✔
55
         end
56
         f:invalidate()
4✔
57
      end
58
   end
59
end
60

61
function package:_init ()
1✔
62
   base._init(self)
1✔
63
   self:loadPackage("date")
1✔
64
end
65

66
function package:registerCommands ()
1✔
67
   self:registerCommand("crop:header", function (_, _)
2✔
NEW
68
      local info = SILE.input.filenames[1] .. " - " .. self.class:date("%x %X") .. " -  " .. outcounter
×
NEW
69
      SILE.typesetter:typeset(info)
×
70
   end)
71

72
   self:registerCommand("crop:setup", function (options, _)
2✔
73
      local papersize = SU.required(options, "papersize", "setting up crop marks")
1✔
74
      local landscape = SU.boolean(options.landscape, self.class.options.landscape)
2✔
75
      local size = SILE.papersize(papersize, landscape)
1✔
76
      local oldsize = SILE.documentState.paperSize
1✔
77
      SILE.documentState.paperSize = size
1✔
78
      local offsetx = (SILE.documentState.paperSize[1] - oldsize[1]) / 2
1✔
79
      local offsety = (SILE.documentState.paperSize[2] - oldsize[2]) / 2
1✔
80
      local page = SILE.getFrame("page")
1✔
81
      page:constrain("right", page:right() + offsetx)
3✔
82
      page:constrain("left", offsetx)
1✔
83
      page:constrain("bottom", page:bottom() + offsety)
3✔
84
      page:constrain("top", offsety)
1✔
85
      if SILE.scratch.masters then
1✔
86
         for _, v in pairs(SILE.scratch.masters) do
3✔
87
            reconstrainFrameset(v.frames)
2✔
88
         end
89
      else
NEW
90
         reconstrainFrameset(SILE.documentState.documentClass.pageTemplate.frames)
×
91
      end
92
      if SILE.typesetter.frame then
1✔
93
         SILE.typesetter.frame:init()
1✔
94
      end
95
      local oldEndPage = SILE.documentState.documentClass.endPage
1✔
96
      SILE.documentState.documentClass.endPage = function (self_)
1✔
97
         oldEndPage(self_)
2✔
98
         outputMarks()
2✔
99
      end
100
   end)
101
end
102

103
package.documentation = [[
104
\begin{document}
105
When preparing a document for printing, you may be asked by the printer to add crop marks.
106
This means that you need to output the document on a slightly larger page size than your target paper and add printer’s crop marks to show where the paper should be trimmed down to the correct size.
107
(This is to ensure that pages where the content “bleeds” off the side of the page are correctly cut.)
108

109
This package provides the \autodoc:command{\crop:setup} command which should be run early in your document file.
110
It takes one argument, \autodoc:parameter{papersize}, which is the true target paper size.
111
It place cropmarks around the true page content.
112

113
It also adds a header at the top of the page with the filename, date and output sheet number.
114
You can customize this header by redefining \autodoc:command{\crop:header}.
115
\end{document}
116
]]
1✔
117

118
return package
1✔
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