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

sile-typesetter / sile / 11534409649

26 Oct 2024 07:27PM UTC coverage: 33.196% (-28.7%) from 61.897%
11534409649

push

github

alerque
chore(tooling): Update editor-config key for stylua as accepted upstream

Our setting addition is still not in a tagged release, but the PR was
accepted into the default branch of stylua. This means you no longer
need to run my fork of Stylua to get this project's style, you just nead
any build from the main development branch. However the config key was
renamed as part of the acceptance, so this is the relevant adjustment.

5810 of 17502 relevant lines covered (33.2%)

1300.57 hits per line

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

0.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")
×
9

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

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

28
   self:registerCommand("pdf:bookmark", function (options, _)
×
29
      local dest = SU.required(options, "dest", "pdf:bookmark")
×
30
      local title = SU.required(options, "title", "pdf:bookmark")
×
31
      local level = SU.cast("integer", options.level or 1)
×
32
      SILE.typesetter:pushHbox({
×
33
         value = nil,
34
         height = SILE.types.measurement(0),
35
         width = SILE.types.measurement(0),
36
         depth = SILE.types.measurement(0),
37
         outputYourself = function ()
38
            SILE.outputter:setBookmark(dest, title, level)
×
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)
×
46
      local dest = SU.required(options, "dest", "pdf:link")
×
47
      local external = SU.boolean(options.external, false)
×
48
      local borderwidth = options.borderwidth and SU.cast("measurement", options.borderwidth):tonumber() or 0
×
49
      local bordercolor = SILE.types.color(options.bordercolor or "blue")
×
50
      local borderoffset = SU.cast("measurement", options.borderoffset or "1pt"):tonumber()
×
51
      local opts = {
×
52
         external = external,
53
         borderstyle = options.borderstyle,
54
         bordercolor = bordercolor,
55
         borderwidth = borderwidth,
56
         borderoffset = borderoffset,
57
      }
58

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

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

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

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

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
]]
×
108

109
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