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

sile-typesetter / sile / 7054606668

01 Dec 2023 01:43AM UTC coverage: 70.141% (-4.2%) from 74.329%
7054606668

push

github

web-flow
Merge 14837a0c3 into a6c229613

11050 of 15754 relevant lines covered (70.14%)

3938.65 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.input.filenames[1] .. " - " .. 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 landscape = SU.boolean(options.landscape, self.class.options.landscape)
×
74
    local size = SILE.papersize(papersize, landscape)
×
75
    local oldsize = SILE.documentState.paperSize
×
76
    SILE.documentState.paperSize = size
×
77
    local offsetx = ( SILE.documentState.paperSize[1] - oldsize[1] ) /2
×
78
    local offsety = ( SILE.documentState.paperSize[2] - oldsize[2] ) /2
×
79
    local page = SILE.getFrame("page")
×
80
    page:constrain("right", page:right() + offsetx)
×
81
    page:constrain("left", offsetx)
×
82
    page:constrain("bottom", page:bottom() + offsety)
×
83
    page:constrain("top", offsety)
×
84
    if SILE.scratch.masters then
×
85
      for _, v in pairs(SILE.scratch.masters) do
×
86
        reconstrainFrameset(v.frames)
×
87
      end
88
    else
89
      reconstrainFrameset(SILE.documentState.documentClass.pageTemplate.frames)
×
90
    end
91
    if SILE.typesetter.frame then SILE.typesetter.frame:init() end
×
92
    local oldEndPage = SILE.documentState.documentClass.endPage
×
93
    SILE.documentState.documentClass.endPage = function (self_)
×
94
      oldEndPage(self_)
×
95
      outputMarks()
×
96
    end
97
  end)
98

99
end
100

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

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

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

116
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