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

sile-typesetter / sile / 10881107806

16 Sep 2024 09:29AM UTC coverage: 61.663% (-7.2%) from 68.912%
10881107806

push

github

web-flow
chore(deps): Bump DeterminateSystems/nix-installer-action from 13 to 14 (#2110)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

10751 of 17435 relevant lines covered (61.66%)

2338.25 hits per line

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

0.0
/packages/image/init.lua
1
local base = require("packages.base")
×
2

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

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

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

75
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