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

sile-typesetter / sile / 9304060604

30 May 2024 02:07PM UTC coverage: 74.124% (-0.6%) from 74.707%
9304060604

push

github

alerque
style: Reformat Lua with stylua

8104 of 11995 new or added lines in 184 files covered. (67.56%)

15 existing lines in 11 files now uncovered.

12444 of 16788 relevant lines covered (74.12%)

7175.1 hits per line

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

97.14
/packages/image/init.lua
1
local base = require("packages.base")
1✔
2

3
local package = pl.class(base)
1✔
4
package._name = "image"
1✔
5

6
function package:registerCommands ()
1✔
7
   self:registerCommand("img", function (options, _)
2✔
8
      SU.required(options, "src", "including image file")
2✔
9
      local width = SU.cast("measurement", options.width or 0):tonumber()
4✔
10
      local height = SU.cast("measurement", options.height or 0):tonumber()
4✔
11
      local pageno = SU.cast("integer", options.page or 1)
2✔
12
      local src = SILE.resolveFile(options.src) or SU.error("Couldn't find file " .. options.src)
4✔
13
      local box_width, box_height, _, _ = SILE.outputter:getImageSize(src, pageno)
2✔
14
      local sx, sy = 1, 1
2✔
15
      if width > 0 and height > 0 then
2✔
NEW
16
         sx, sy = box_width / width, box_height / height
×
17
      elseif width > 0 then
2✔
18
         sx = box_width / width
1✔
19
         sy = sx
1✔
20
      elseif height > 0 then
1✔
21
         sy = box_height / height
1✔
22
         sx = sy
1✔
23
      end
24

25
      SILE.typesetter:pushHbox({
4✔
26
         width = box_width / sx,
2✔
27
         height = box_height / sy,
2✔
28
         depth = 0,
29
         value = src,
2✔
30
         outputYourself = function (node, typesetter, _)
31
            SILE.outputter:drawImage(
4✔
32
               node.value,
2✔
33
               typesetter.frame.state.cursorX,
2✔
34
               typesetter.frame.state.cursorY - node.height,
2✔
35
               node.width,
2✔
36
               node.height,
2✔
37
               pageno
38
            )
2✔
39
            typesetter.frame:advanceWritingDirection(node.width)
2✔
40
         end,
41
      })
42
   end, "Inserts the image specified with the <src> option in a box of size <width> by <height>")
3✔
43
end
44

45
package.documentation = [[
46
\begin{document}
47
Loading the \autodoc:package{image} package gives you the \autodoc:command{\img} command, fashioned after the HTML equivalent.
48
It takes the following parameters: \autodoc:parameter{src=<file>} must be the path to an image file; you may also give \autodoc:parameter{height} and/or \autodoc:parameter{width} parameters to specify the output size of the image on the paper.
49
If the size parameters are not given, then the image will be output at its “natural” size, honoring its resolution if available.
50
The command also supports a \autodoc:parameter{page=<number>} option, to specify the selected page in formats supporting
51
several pages (such as PDF).
52

53
\begin{autodoc:note}
54
With the libtexpdf backend (the default), the images can be in JPEG, PNG, EPS, or PDF formats.
55
\end{autodoc:note}
56

57
Here is a 200x243 pixel image output with \autodoc:command{\img[src=documentation/gutenberg.png]}.
58
The image has a claimed resolution of 100 pixels per inch, so ends up being two inches (144pt) wide on the page:\par
59
\img[src=documentation/gutenberg.png]
60

61
\raggedright{
62
Here it is with (respectively)
63
\autodoc:command{\img[src=documentation/gutenberg.png,width=120pt]},
64
\autodoc:command{\img[src=documentation/gutenberg.png,height=200pt]}, and
65
\autodoc:command{\img[src=documentation/gutenberg.png,width=120pt,height=200pt]}:}
66

67
\img[src=documentation/gutenberg.png,width=120pt]
68
\img[src=documentation/gutenberg.png,height=200pt]
69
\img[src=documentation/gutenberg.png,width=120pt,height=200pt]
70

71
Notice that images are typeset on the baseline of a line of text, rather like a very big letter.
72
\end{document}
73
]]
1✔
74

75
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