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

sile-typesetter / sile / 9428435077

08 Jun 2024 11:35AM UTC coverage: 64.56% (-9.9%) from 74.46%
9428435077

push

github

web-flow
Merge pull request #2047 from alerque/end-pars

23 of 46 new or added lines in 5 files covered. (50.0%)

1684 existing lines in 60 files now uncovered.

11145 of 17263 relevant lines covered (64.56%)

4562.45 hits per line

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

90.0
/packages/pdf/init.lua
1
--- pdf package
2
--- @use packages.pdf
3

4
-- This package and its commands are perhaps ill-named:
5
-- Exception made of the pdf:literal command below, the concepts of links
6
-- (anchor, target), bookmarks, and metadata are not specific to PDF.
7
--
8
local base = require("packages.base")
1✔
9

10
local package = pl.class(base)
1✔
11
package._name = "pdf"
1✔
12

13
function package:registerCommands ()
1✔
14
   self:registerCommand("pdf:destination", function (options, _)
2✔
15
      local name = SU.required(options, "name", "pdf:destination")
3✔
16
      SILE.typesetter:pushHbox({
6✔
17
         outputYourself = function (_, typesetter, line)
18
            local state = typesetter.frame.state
3✔
19
            typesetter.frame:advancePageDirection(-line.height)
6✔
20
            local x, y = state.cursorX, state.cursorY
3✔
21
            typesetter.frame:advancePageDirection(line.height)
3✔
22
            local _y = SILE.documentState.paperSize[2] - y
3✔
23
            SILE.outputter:setLinkAnchor(name, x, _y)
3✔
24
         end,
25
      })
26
   end)
27

28
   self:registerCommand("pdf:bookmark", function (options, _)
2✔
29
      local dest = SU.required(options, "dest", "pdf:bookmark")
3✔
30
      local title = SU.required(options, "title", "pdf:bookmark")
3✔
31
      local level = SU.cast("integer", options.level or 1)
3✔
32
      SILE.typesetter:pushHbox({
6✔
33
         value = nil,
34
         height = SILE.types.measurement(0),
6✔
35
         width = SILE.types.measurement(0),
6✔
36
         depth = SILE.types.measurement(0),
6✔
37
         outputYourself = function ()
38
            SILE.outputter:setBookmark(dest, title, level)
3✔
39
         end,
40
      })
41
   end)
42

43
   -- TODO: Shim to pdfannotations package
44
   -- self:registerCommand("pdf:literal", function (_, content)
45
   self:registerCommand("pdf:link", function (options, content)
2✔
46
      local dest = SU.required(options, "dest", "pdf:link")
1✔
47
      local external = SU.boolean(options.external, false)
1✔
48
      local borderwidth = options.borderwidth and SU.cast("measurement", options.borderwidth):tonumber() or 0
1✔
49
      local bordercolor = SILE.types.color(options.bordercolor or "blue")
2✔
50
      local borderoffset = SU.cast("measurement", options.borderoffset or "1pt"):tonumber()
2✔
51
      local opts = {
1✔
52
         external = external,
1✔
53
         borderstyle = options.borderstyle,
1✔
54
         bordercolor = bordercolor,
1✔
55
         borderwidth = borderwidth,
1✔
56
         borderoffset = borderoffset,
1✔
57
      }
58

59
      SILE.typesetter:liner("pdf:link", content, function (box, typesetter, line)
2✔
60
         local x0 = typesetter.frame.state.cursorX:tonumber()
1✔
61
         local y0 = (SILE.documentState.paperSize[2] - typesetter.frame.state.cursorY):tonumber()
2✔
62
         SILE.outputter:beginLink(dest, opts)
1✔
63

64
         -- Build the content.
65
         -- Cursor will be moved by the actual definitive size.
66
         box:outputContent(typesetter, line)
1✔
67
         local x1 = typesetter.frame.state.cursorX:tonumber()
1✔
68
         local y1 = (SILE.documentState.paperSize[2] - typesetter.frame.state.cursorY + box.height):tonumber()
3✔
69

70
         SILE.outputter:endLink(dest, opts, x0, y0, x1, y1) -- Unstable API
1✔
71
      end)
72
   end)
73

74
   self:registerCommand("pdf:metadata", function (options, _)
2✔
UNCOV
75
      local key = SU.required(options, "key", "pdf:metadata")
×
UNCOV
76
      if options.val ~= nil then
×
77
         SU.deprecated("\\pdf:metadata[…, val=…]", "\\pdf:metadata[…, value=…]", "0.12.0", "0.13.0")
×
78
      end
UNCOV
79
      local value = SU.required(options, "value", "pdf:metadata")
×
80

UNCOV
81
      SILE.outputter:setMetadata(key, value)
×
82
   end)
83
end
84

85
package.documentation = [[
86
\begin{document}
87
The \autodoc:package{pdf} package enables basic support for PDF links and table-of-contents entries.
88
It provides the four commands \autodoc:command{\pdf:destination}, \autodoc:command{\pdf:link}, \autodoc:command{\pdf:bookmark}, and \autodoc:command{\pdf:metadata}.
89

90
The \autodoc:command{\pdf:destination} parameter creates a link target;
91
   it expects a parameter called \autodoc:parameter{name} to uniquely identify the target.
92
To create a link to that location in the document, use \autodoc:command{\pdf:link[dest=<name>]{<content>}}.
93

94
The \autodoc:command{\pdf:link} command accepts several options defining its border style:
95
   a \autodoc:parameter{borderwidth} length setting the border width (defaults to \code{0}, meaning no border),
96
   a \autodoc:parameter{borderstyle} string (can be set to \code{underline} or \code{dashed}, otherwise a solid box),
97
   a \autodoc:parameter{bordercolor} color specification for this border (defaults to \code{blue}),
98
   and finally a \autodoc:parameter{borderoffset} length for adjusting the border with some vertical space above the content and below the baseline (defaults to \code{1pt}).
99
Note that PDF renderers may vary on how they honor these border styling features on link annotations.
100

101
It also has an \autodoc:parameter{external} option for URL links, which is not intended to be used directly—refer to the \autodoc:package{url} package for more flexibility typesetting external links.
102

103
To set arbitrary key-value metadata, use something like \autodoc:command{\pdf:metadata[key=Author, value=J. Smith]}.
104
The PDF metadata field names are case-sensitive.
105
Common keys include \code{Title}, \code{Author}, \code{Subject}, \code{Keywords}, \code{CreationDate}, and \code{ModDate}.
106
\end{document}
107
]]
1✔
108

109
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