• 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
/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

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

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

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

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

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

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

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

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

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

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

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

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

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

154
function outputter:drawSVG (figure, _, x, y, width, height, scalefactor)
×
NEW
155
   x = SU.cast("number", x)
×
NEW
156
   y = SU.cast("number", y)
×
NEW
157
   width = SU.cast("number", width)
×
NEW
158
   height = SU.cast("number", height)
×
NEW
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)
×
NEW
163
   x = SU.cast("number", x)
×
NEW
164
   y = SU.cast("number", y)
×
NEW
165
   width = SU.cast("number", width)
×
NEW
166
   depth = SU.cast("number", depth)
×
NEW
167
   self:_writeline("Draw line", _round(x), _round(y), _round(width), _round(depth))
×
168
end
169

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

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

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

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

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

NEW
190
function outputter:drawRaw (literal)
×
NEW
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

© 2026 Coveralls, Inc