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

sile-typesetter / sile / 7141747182

08 Dec 2023 01:08PM UTC coverage: 72.188% (-2.4%) from 74.636%
7141747182

push

github

web-flow
Merge pull request #1924 from alerque/lint-fixes

4 of 10 new or added lines in 8 files covered. (40.0%)

376 existing lines in 13 files now uncovered.

11384 of 15770 relevant lines covered (72.19%)

6898.07 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.
20
  if input > 0 then input = input + .00000000000001 end
×
21
  if input < 0 then input = input - .00000000000001 end
×
22
  return string.format("%.4f", input)
×
23
end
24

25
local outputter = pl.class(base)
×
26
outputter._name = "debug"
×
27
outputter.extension = "debug"
×
28

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

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

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

55
function outputter:newPage ()
×
56
  self:_writeline("New page")
×
57
end
58

59
function outputter:finish ()
×
60
  if SILE.status.unsupported then self:_writeline("UNSUPPORTED") end
×
61
  self:_writeline("End page")
×
62
  self:_writeline("Finish")
×
63
  outfile:close()
×
64
end
65

66
function outputter.getCursor (_)
×
67
  return cursorX, cursorY
×
68
end
69

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

81
function outputter:setColor (color)
×
82
  if color.r then
×
83
    self:_writeline("Set color", _round(color.r), _round(color.g), _round(color.b))
×
84
  elseif color.c then
×
85
    self:_writeline("Set color", _round(color.c), _round(color.m), _round(color.y), _round(color.k))
×
86
  elseif color.l then
×
87
    self:_writeline("Set color", _round(color.l))
×
88
  end
89
end
90

91
function outputter:pushColor (color)
×
92
  if color.r then
×
93
    self:_writeline("Push color", _round(color.r), _round(color.g), _round(color.b))
×
94
  elseif color.c then
×
95
    self:_writeline("Push color (CMYK)", _round(color.c), _round(color.m), _round(color.y), _round(color.k))
×
96
  elseif color.l then
×
97
    self:_writeline("Push color (grayscale)", _round(color.l))
×
98
  end
99
end
100

101
function outputter:popColor ()
×
102
  self:_writeline("Pop color")
×
103
end
104

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

127
function outputter:setFont (options)
×
128
  local font = SILE.font._key(options)
×
129
  if lastFont ~= font then
×
130
    self:_writeline("Set font ", font)
×
131
    lastFont = font
×
132
  end
133
end
134

135
function outputter:drawImage (src, x, y, width, height)
×
136
  x = SU.cast("number", x)
×
137
  y = SU.cast("number", y)
×
138
  width = SU.cast("number", width)
×
139
  height = SU.cast("number", height)
×
140
  self:_writeline("Draw image", src, _round(x), _round(y), _round(width), _round(height))
×
141
end
142

143
function outputter.getImageSize (_, src, pageno)
×
144
  local pdf = require("justenoughlibtexpdf")
×
145
  local llx, lly, urx, ury, xresol, yresol = pdf.imagebbox(src, pageno)
×
146
  return (urx-llx), (ury-lly), xresol, yresol
×
147
end
148

149
function outputter:drawSVG (figure, _, x, y, width, height, scalefactor)
×
150
  x = SU.cast("number", x)
×
151
  y = SU.cast("number", y)
×
152
  width = SU.cast("number", width)
×
153
  height = SU.cast("number", height)
×
154
  self:_writeline("Draw SVG", _round(x), _round(y), _round(width), _round(height), figure, scalefactor)
×
155
end
156

157
function outputter:drawRule (x, y, width, depth)
×
158
  x = SU.cast("number", x)
×
159
  y = SU.cast("number", y)
×
160
  width = SU.cast("number", width)
×
161
  depth = SU.cast("number", depth)
×
162
  self:_writeline("Draw line", _round(x), _round(y), _round(width), _round(depth))
×
163
end
164

165
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