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

sile-typesetter / sile / 8288578143

14 Mar 2024 09:39PM UTC coverage: 64.155% (-10.6%) from 74.718%
8288578143

Pull #1904

github

alerque
chore(core): Fixup ec6ed657 which didn't shim old pack styles properly
Pull Request #1904: Merge develop into master (commit to next release being breaking)

1648 of 2421 new or added lines in 107 files covered. (68.07%)

1843 existing lines in 77 files now uncovered.

10515 of 16390 relevant lines covered (64.15%)

3306.56 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

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

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

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

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

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

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

76
  end)
77

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

NEW
85
    SILE.outputter:setMetadata(key, value)
×
86
  end)
87

88
end
89

90
package.documentation = [[
91
\begin{document}
92
The \autodoc:package{pdf} package enables basic support for PDF links and table-of-contents entries.
93
It provides the four commands \autodoc:command{\pdf:destination}, \autodoc:command{\pdf:link}, \autodoc:command{\pdf:bookmark}, and \autodoc:command{\pdf:metadata}.
94

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

99
The \autodoc:command{\pdf:link} command accepts several options defining its border style:
100
   a \autodoc:parameter{borderwidth} length setting the border width (defaults to \code{0}, meaning no border),
101
   a \autodoc:parameter{borderstyle} string (can be set to \code{underline} or \code{dashed}, otherwise a solid box),
102
   a \autodoc:parameter{bordercolor} color specification for this border (defaults to \code{blue}),
103
   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}).
104
Note that PDF renderers may vary on how they honor these border styling features on link annotations.
105

106
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.
107

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

114
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