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

sile-typesetter / sile / 9304049654

30 May 2024 02:12PM UTC coverage: 60.021% (-14.7%) from 74.707%
9304049654

push

github

web-flow
Merge 1a26b4f22 into a1fd105f8

6743 of 12900 new or added lines in 186 files covered. (52.27%)

347 existing lines in 49 files now uncovered.

10311 of 17179 relevant lines covered (60.02%)

3307.34 hits per line

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

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

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

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

NEW
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, _)
NEW
31
            SILE.outputter:drawImage(
×
NEW
32
               node.value,
×
NEW
33
               typesetter.frame.state.cursorX,
×
NEW
34
               typesetter.frame.state.cursorY - node.height,
×
NEW
35
               node.width,
×
NEW
36
               node.height,
×
37
               pageno
38
            )
NEW
39
            typesetter.frame:advanceWritingDirection(node.width)
×
40
         end,
41
      })
NEW
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}
UNCOV
73
]]
×
74

UNCOV
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