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

sile-typesetter / sile / 8288578143

14 Mar 2024 09:39PM UTC coverage: 64.155% (-10.6%) from 74.718%
8288578143

Pull #1904

github

alerque
chore(core): Fixup ec6ed657 which didn't shim old pack styles properly
Pull Request #1904: Merge develop into master (commit to next release being breaking)

1648 of 2421 new or added lines in 107 files covered. (68.07%)

1843 existing lines in 77 files now uncovered.

10515 of 16390 relevant lines covered (64.15%)

3306.56 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 ()
×
7

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

UNCOV
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, _)
UNCOV
32
        SILE.outputter:drawImage(node.value, typesetter.frame.state.cursorX, typesetter.frame.state.cursorY-node.height, node.width, node.height, pageno)
×
UNCOV
33
        typesetter.frame:advanceWritingDirection(node.width)
×
UNCOV
34
    end})
×
35

UNCOV
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}
UNCOV
68
]]
×
69

UNCOV
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

© 2026 Coveralls, Inc