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

sile-typesetter / sile / 6713098919

31 Oct 2023 10:21PM UTC coverage: 52.831% (-21.8%) from 74.636%
6713098919

push

github

web-flow
Merge d0a2a1ee9 into b185d4972

45 of 45 new or added lines in 3 files covered. (100.0%)

8173 of 15470 relevant lines covered (52.83%)

6562.28 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

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

26
    SILE.typesetter:pushHbox({
×
27
      width = box_width / sx,
28
      height = box_height / sy,
29
      depth = 0,
30
      value = src,
31
      outputYourself = function (node, typesetter, _)
32
        SILE.outputter:drawImage(node.value, typesetter.frame.state.cursorX, typesetter.frame.state.cursorY-node.height, node.width, node.height, pageno)
×
33
        typesetter.frame:advanceWritingDirection(node.width)
×
34
    end})
×
35

36
  end, "Inserts the image specified with the <src> option in a box of size <width> by <height>")
×
37

38
end
39

40
package.documentation = [[
41
\begin{document}
42
Loading the \autodoc:package{image} package gives you the \autodoc:command{\img} command, fashioned after the HTML equivalent.
43
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.
44
If the size parameters are not given, then the image will be output at its “natural” size, honoring its resolution if available.
45
The command also supports a \autodoc:parameter{page=<number>} option, to specify the selected page in formats supporting
46
several pages (such as PDF).
47

48
\begin{autodoc:note}
49
With the libtexpdf backend (the default), the images can be in JPEG, PNG, EPS, or PDF formats.
50
\end{autodoc:note}
51

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

56
\raggedright{
57
Here it is with (respectively)
58
\autodoc:command{\img[src=documentation/gutenberg.png,width=120pt]},
59
\autodoc:command{\img[src=documentation/gutenberg.png,height=200pt]}, and
60
\autodoc:command{\img[src=documentation/gutenberg.png,width=120pt,height=200pt]}:}
61

62
\img[src=documentation/gutenberg.png,width=120pt]
63
\img[src=documentation/gutenberg.png,height=200pt]
64
\img[src=documentation/gutenberg.png,width=120pt,height=200pt]
65

66
Notice that images are typeset on the baseline of a line of text, rather like a very big letter.
67
\end{document}
68
]]
×
69

70
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

© 2025 Coveralls, Inc