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

sile-typesetter / sile / 5897172563

18 Aug 2023 12:08AM UTC coverage: 65.701% (-8.7%) from 74.359%
5897172563

push

github

web-flow
Merge e093e2956 into 83d142305

10300 of 15677 relevant lines covered (65.7%)

6629.59 hits per line

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

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

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

6
local outcounter = 1
×
7

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

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

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

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

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

59
function package:_init ()
×
60
  base._init(self)
×
61
  self:loadPackage("date")
×
62
end
63

64
function package:registerCommands ()
×
65

66
  self:registerCommand("crop:header", function (_, _)
×
67
    local info = SILE.masterFilename .. " - " .. self.class:date("%x %X") .. " -  " .. outcounter
×
68
    SILE.typesetter:typeset(info)
×
69
  end)
70

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

98
end
99

100
package.documentation = [[
101
\begin{document}
102
When preparing a document for printing, you may be asked by the printer to add crop marks.
103
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.
104
(This is to ensure that pages where the content “bleeds” off the side of the page are correctly cut.)
105

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

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

115
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