Skip to content

Commit

Permalink
fix(backends): Implement cursor tracking to roughly simulate glues
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Jan 14, 2020
1 parent 4f24d4a commit 26afcec
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions core/text-output.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ if (not SILE.outputters) then SILE.outputters = {} end
local outfile
local cursorX = 0
local cursorY = 0
local hboxCount = 0
local started = false

local writeline = function (...)
local args = table.pack(...)
if hboxCount >= 1 then outfile:write(" ") end
for i=1, #args do
outfile:write(args[i])
if i < #args then outfile:write(" ") end
hboxCount = hboxCount + 1
end
end

Expand All @@ -28,16 +25,24 @@ SILE.outputters.text = {
setColor = function() end,
pushColor = function () end,
popColor = function () end,
outputHbox = function (value)
writeline(value.text)
outputHbox = function (value, width)
width = SU.cast("number", width)
if width > 0 then
writeline(value.text)
started = true
cursorX = cursorX + width
end
end,
setFont = function () end,
drawImage = function () end,
imageSize = function () end,
moveTo = function (x, y)
if y > cursorY or x <= cursorX then
outfile:write("\n")
hboxCount = 0
if started then
if y > cursorY or x < cursorX then
outfile:write("\n")
elseif x > cursorX then
outfile:write(" ")
end
end
cursorY = y
cursorX = x
Expand Down

0 comments on commit 26afcec

Please sign in to comment.