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

sile-typesetter / sile / 10621606353

29 Aug 2024 07:43PM UTC coverage: 66.23% (+3.6%) from 62.644%
10621606353

push

github

alerque
Merge tag 'v0.15.5' into develop

13 of 289 new or added lines in 17 files covered. (4.5%)

403 existing lines in 59 files now uncovered.

11585 of 17492 relevant lines covered (66.23%)

5713.06 hits per line

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

0.0
/outputters/debug.lua
1
local base = require("outputters.base")
×
2

3
local cursorX = 0
×
4
local cursorY = 0
×
5

6
local started = false
×
7

8
local lastFont
9
local outfile
10

11
local _round = SU.debug_round
×
12

13
local outputter = pl.class(base)
×
14
outputter._name = "debug"
×
15
outputter.extension = "debug"
×
16

17
-- The outputter init can't actually initialize output (as logical as it might
18
-- have seemed) because that requires a page size which we don't know yet.
19
-- function outputter:_init () end
20

21
function outputter:_ensureInit ()
×
22
   if not started then
×
23
      started = true -- keep this before self:_writeline or it will be a race condition!
×
24
      local fname = self:getOutputFilename()
×
25
      outfile = fname == "-" and io.stdout or io.open(fname, "w+")
×
26
      if SILE.documentState.paperSize then
×
27
         self:_writeline("Set paper size ", SILE.documentState.paperSize[1], SILE.documentState.paperSize[2])
×
28
      end
29
      self:_writeline("Begin page")
×
30
   end
31
end
32

33
function outputter:_writeline (...)
×
34
   self:_ensureInit()
×
35
   local args = pl.utils.pack(...)
×
36
   for i = 1, #args do
×
37
      outfile:write(args[i])
×
38
      if i < #args then
×
39
         outfile:write("\t")
×
40
      end
41
   end
42
   outfile:write("\n")
×
43
end
44

45
function outputter:newPage ()
×
46
   self:_writeline("New page")
×
47
end
48

49
function outputter:finish ()
×
50
   if SILE.status.unsupported then
×
51
      self:_writeline("UNSUPPORTED")
×
52
   end
53
   self:_writeline("End page")
×
54
   self:runHooks("prefinish")
×
55
   self:_writeline("Finish")
×
56
   outfile:close()
×
57
end
58

59
function outputter.getCursor (_)
×
60
   return cursorX, cursorY
×
61
end
62

63
function outputter:setCursor (x, y, relative)
×
64
   x = SU.cast("number", x)
×
65
   y = SU.cast("number", y)
×
66
   local oldx, oldy = self:getCursor()
×
67
   local offset = relative and { x = cursorX, y = cursorY } or { x = 0, y = 0 }
×
68
   cursorX = offset.x + x
×
69
   cursorY = offset.y - y
×
70
   if _round(oldx) ~= _round(cursorX) then
×
71
      self:_writeline("Mx ", _round(x))
×
72
   end
73
   if _round(oldy) ~= _round(cursorY) then
×
74
      self:_writeline("My ", _round(y))
×
75
   end
76
end
77

78
function outputter:setColor (color)
×
79
   if color.r then
×
80
      self:_writeline("Set color", tostring(color))
×
81
   elseif color.c then
×
82
      self:_writeline("Set color", tostring(color))
×
83
   elseif color.l then
×
84
      self:_writeline("Set color", tostring(color))
×
85
   end
86
end
87

88
function outputter:pushColor (color)
×
89
   if color.r then
×
90
      self:_writeline("Push color", tostring(color))
×
91
   elseif color.c then
×
92
      self:_writeline("Push color (CMYK)", tostring(color))
×
93
   elseif color.l then
×
94
      self:_writeline("Push color (grayscale)", tostring(color))
×
95
   end
96
end
97

98
function outputter:popColor ()
×
99
   self:_writeline("Pop color")
×
100
end
101

102
function outputter:drawHbox (value, width)
×
103
   if not value.glyphString then
×
104
      return
×
105
   end
106
   width = SU.cast("number", width)
×
107
   local buf
108
   if value.complex then
×
109
      local cluster = {}
×
110
      for i = 1, #value.items do
×
111
         local item = value.items[i]
×
112
         cluster[#cluster + 1] = item.gid
×
113
         -- For the sake of terseness we're only dumping non-zero values
114
         if item.glyphAdvance ~= 0 then
×
115
            cluster[#cluster + 1] = "a=" .. _round(item.glyphAdvance)
×
116
         end
117
         if item.x_offset then
×
118
            cluster[#cluster + 1] = "x=" .. _round(item.x_offset)
×
119
         end
120
         if item.y_offset then
×
121
            cluster[#cluster + 1] = "y=" .. _round(item.y_offset)
×
122
         end
123
         self:setCursor(item.width, 0, true)
×
124
      end
125
      buf = table.concat(cluster, " ")
×
126
   else
127
      buf = table.concat(value.glyphString, " ") .. " w=" .. _round(width)
×
128
   end
129
   self:_writeline("T", buf, "(" .. tostring(value.text) .. ")")
×
130
end
131

132
function outputter:setFont (options)
×
133
   local font = SILE.font._key(options)
×
134
   if lastFont ~= font then
×
135
      self:_writeline("Set font ", font)
×
136
      lastFont = font
×
137
   end
138
end
139

140
function outputter:drawImage (src, x, y, width, height)
×
141
   x = SU.cast("number", x)
×
142
   y = SU.cast("number", y)
×
143
   width = SU.cast("number", width)
×
144
   height = SU.cast("number", height)
×
145
   self:_writeline("Draw image", src, _round(x), _round(y), _round(width), _round(height))
×
146
end
147

148
function outputter.getImageSize (_, src, pageno)
×
149
   local pdf = require("justenoughlibtexpdf")
×
150
   local llx, lly, urx, ury, xresol, yresol = pdf.imagebbox(src, pageno)
×
151
   return (urx - llx), (ury - lly), xresol, yresol
×
152
end
153

154
function outputter:drawSVG (figure, _, x, y, width, height, scalefactor)
×
155
   x = SU.cast("number", x)
×
156
   y = SU.cast("number", y)
×
157
   width = SU.cast("number", width)
×
158
   height = SU.cast("number", height)
×
159
   self:_writeline("Draw SVG", _round(x), _round(y), _round(width), _round(height), figure, scalefactor)
×
160
end
161

162
function outputter:drawRule (x, y, width, depth)
×
163
   x = SU.cast("number", x)
×
164
   y = SU.cast("number", y)
×
165
   width = SU.cast("number", width)
×
166
   depth = SU.cast("number", depth)
×
167
   self:_writeline("Draw line", _round(x), _round(y), _round(width), _round(depth))
×
168
end
169

170
function outputter:setLinkAnchor (name, x, y)
×
171
   self:_writeline("Setting link anchor", name, x, y)
×
172
end
173

174
function outputter:beginLink (dest, opts)
×
NEW
175
   self:_writeline("Beginning a link", dest, opts)
×
176
end
177

178
function outputter:endLink (dest, opts, x0, y0, x1, y1)
×
179
   self:_writeline("Ending a link", dest, opts, x0, y0, x1, y1)
×
180
end
181

182
function outputter:setBookmark (dest, title, level)
×
183
   self:_writeline("Setting bookmark", dest, title, level)
×
184
end
185

186
function outputter:setMetadata (key, value)
×
187
   self:_writeline("Set metadata", key, value)
×
188
end
189

190
function outputter:drawRaw (literal)
×
191
   self:_writeline("Draw raw", literal)
×
192
end
193

194
return outputter
×
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