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

sile-typesetter / sile / 9304060604

30 May 2024 02:07PM UTC coverage: 74.124% (-0.6%) from 74.707%
9304060604

push

github

alerque
style: Reformat Lua with stylua

8104 of 11995 new or added lines in 184 files covered. (67.56%)

15 existing lines in 11 files now uncovered.

12444 of 16788 relevant lines covered (74.12%)

7175.1 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 function _round (input)
12
   -- LuaJIT 2.1 betas (and inheritors such as OpenResty and Moonjit) are biased
13
   -- towards rounding 0.5 up to 1, all other Lua interpreters are biased
14
   -- towards rounding such floating point numbers down.  This hack shaves off
15
   -- just enough to fix the bias so our test suite works across interpreters.
16
   -- Note that even a true rounding function here will fail because the bias is
17
   -- inherent to the floating point type. Also note we are erroring in favor of
18
   -- the *less* common option because the LuaJIT VMS are hopelessly broken
19
   -- whereas normal LUA VMs can be cooerced.
NEW
20
   if input > 0 then
×
NEW
21
      input = input + 0.00000000000001
×
22
   end
NEW
23
   if input < 0 then
×
NEW
24
      input = input - 0.00000000000001
×
25
   end
NEW
26
   return string.format("%.4f", input)
×
27
end
28

29
local outputter = pl.class(base)
×
30
outputter._name = "debug"
×
31
outputter.extension = "debug"
×
32

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

37
function outputter:_ensureInit ()
×
NEW
38
   if not started then
×
NEW
39
      started = true -- keep this before self:_writeline or it will be a race condition!
×
NEW
40
      local fname = self:getOutputFilename()
×
NEW
41
      outfile = fname == "-" and io.stdout or io.open(fname, "w+")
×
NEW
42
      if SILE.documentState.paperSize then
×
NEW
43
         self:_writeline("Set paper size ", SILE.documentState.paperSize[1], SILE.documentState.paperSize[2])
×
44
      end
NEW
45
      self:_writeline("Begin page")
×
46
   end
47
end
48

49
function outputter:_writeline (...)
×
NEW
50
   self:_ensureInit()
×
NEW
51
   local args = pl.utils.pack(...)
×
NEW
52
   for i = 1, #args do
×
NEW
53
      outfile:write(args[i])
×
NEW
54
      if i < #args then
×
NEW
55
         outfile:write("\t")
×
56
      end
57
   end
NEW
58
   outfile:write("\n")
×
59
end
60

61
function outputter:newPage ()
×
NEW
62
   self:_writeline("New page")
×
63
end
64

65
function outputter:finish ()
×
NEW
66
   if SILE.status.unsupported then
×
NEW
67
      self:_writeline("UNSUPPORTED")
×
68
   end
NEW
69
   self:_writeline("End page")
×
NEW
70
   self:_writeline("Finish")
×
NEW
71
   outfile:close()
×
72
end
73

74
function outputter.getCursor (_)
×
NEW
75
   return cursorX, cursorY
×
76
end
77

78
function outputter:setCursor (x, y, relative)
×
NEW
79
   x = SU.cast("number", x)
×
NEW
80
   y = SU.cast("number", y)
×
NEW
81
   local oldx, oldy = self:getCursor()
×
NEW
82
   local offset = relative and { x = cursorX, y = cursorY } or { x = 0, y = 0 }
×
NEW
83
   cursorX = offset.x + x
×
NEW
84
   cursorY = offset.y - y
×
NEW
85
   if _round(oldx) ~= _round(cursorX) then
×
NEW
86
      self:_writeline("Mx ", _round(x))
×
87
   end
NEW
88
   if _round(oldy) ~= _round(cursorY) then
×
NEW
89
      self:_writeline("My ", _round(y))
×
90
   end
91
end
92

93
function outputter:setColor (color)
×
NEW
94
   if color.r then
×
NEW
95
      self:_writeline("Set color", _round(color.r), _round(color.g), _round(color.b))
×
NEW
96
   elseif color.c then
×
NEW
97
      self:_writeline("Set color", _round(color.c), _round(color.m), _round(color.y), _round(color.k))
×
NEW
98
   elseif color.l then
×
NEW
99
      self:_writeline("Set color", _round(color.l))
×
100
   end
101
end
102

103
function outputter:pushColor (color)
×
NEW
104
   if color.r then
×
NEW
105
      self:_writeline("Push color", _round(color.r), _round(color.g), _round(color.b))
×
NEW
106
   elseif color.c then
×
NEW
107
      self:_writeline("Push color (CMYK)", _round(color.c), _round(color.m), _round(color.y), _round(color.k))
×
NEW
108
   elseif color.l then
×
NEW
109
      self:_writeline("Push color (grayscale)", _round(color.l))
×
110
   end
111
end
112

113
function outputter:popColor ()
×
NEW
114
   self:_writeline("Pop color")
×
115
end
116

117
function outputter:drawHbox (value, width)
×
NEW
118
   if not value.glyphString then
×
NEW
119
      return
×
120
   end
NEW
121
   width = SU.cast("number", width)
×
122
   local buf
NEW
123
   if value.complex then
×
NEW
124
      local cluster = {}
×
NEW
125
      for i = 1, #value.items do
×
NEW
126
         local item = value.items[i]
×
NEW
127
         cluster[#cluster + 1] = item.gid
×
128
         -- For the sake of terseness we're only dumping non-zero values
NEW
129
         if item.glyphAdvance ~= 0 then
×
NEW
130
            cluster[#cluster + 1] = "a=" .. _round(item.glyphAdvance)
×
131
         end
NEW
132
         if item.x_offset then
×
NEW
133
            cluster[#cluster + 1] = "x=" .. _round(item.x_offset)
×
134
         end
NEW
135
         if item.y_offset then
×
NEW
136
            cluster[#cluster + 1] = "y=" .. _round(item.y_offset)
×
137
         end
NEW
138
         self:setCursor(item.width, 0, true)
×
139
      end
NEW
140
      buf = table.concat(cluster, " ")
×
141
   else
NEW
142
      buf = table.concat(value.glyphString, " ") .. " w=" .. _round(width)
×
143
   end
NEW
144
   self:_writeline("T", buf, "(" .. tostring(value.text) .. ")")
×
145
end
146

147
function outputter:setFont (options)
×
NEW
148
   local font = SILE.font._key(options)
×
NEW
149
   if lastFont ~= font then
×
NEW
150
      self:_writeline("Set font ", font)
×
NEW
151
      lastFont = font
×
152
   end
153
end
154

155
function outputter:drawImage (src, x, y, width, height)
×
NEW
156
   x = SU.cast("number", x)
×
NEW
157
   y = SU.cast("number", y)
×
NEW
158
   width = SU.cast("number", width)
×
NEW
159
   height = SU.cast("number", height)
×
NEW
160
   self:_writeline("Draw image", src, _round(x), _round(y), _round(width), _round(height))
×
161
end
162

163
function outputter.getImageSize (_, src, pageno)
×
NEW
164
   local pdf = require("justenoughlibtexpdf")
×
NEW
165
   local llx, lly, urx, ury, xresol, yresol = pdf.imagebbox(src, pageno)
×
NEW
166
   return (urx - llx), (ury - lly), xresol, yresol
×
167
end
168

169
function outputter:drawSVG (figure, _, x, y, width, height, scalefactor)
×
NEW
170
   x = SU.cast("number", x)
×
NEW
171
   y = SU.cast("number", y)
×
NEW
172
   width = SU.cast("number", width)
×
NEW
173
   height = SU.cast("number", height)
×
NEW
174
   self:_writeline("Draw SVG", _round(x), _round(y), _round(width), _round(height), figure, scalefactor)
×
175
end
176

177
function outputter:drawRule (x, y, width, depth)
×
NEW
178
   x = SU.cast("number", x)
×
NEW
179
   y = SU.cast("number", y)
×
NEW
180
   width = SU.cast("number", width)
×
NEW
181
   depth = SU.cast("number", depth)
×
NEW
182
   self:_writeline("Draw line", _round(x), _round(y), _round(width), _round(depth))
×
183
end
184

185
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