Skip to content

Commit

Permalink
feat(backends): Modify setCursor() to handle relative movements
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Aug 20, 2020
1 parent 02cce40 commit 7caa9c8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
7 changes: 5 additions & 2 deletions core/cairo-output.lua
Expand Up @@ -59,9 +59,12 @@ SILE.outputters.cairo = {
return self:setCursor(x, y)
end,

setCursor = function (self, x, y)
setCursor = function (self, x, y, relative)
_deprecationCheck(self)
move(cr, x, y)
local offset = relative and { x = cursorX, y = cursorY } or { x = 0, y = 0 }
cursorX = offset.x + x
cursorY = offset.y - y
move(cr, cursorX, cursorY)
end,

setColor = function (self, color)
Expand Down
10 changes: 7 additions & 3 deletions core/debug-output.lua
Expand Up @@ -60,12 +60,16 @@ SILE.outputters.debug = {
return self:setCursor(x, y)
end,

setCursor = function (self, x, y)
setCursor = function (self, x, y, relative)
_deprecationCheck(self)
x = SU.cast("number", x)
y = SU.cast("number", y)
if string.format("%.4f", x) ~= string.format("%.4f", cursorX) then writeline("Mx ", string.format("%.4f", x)); cursorX = x end
if string.format("%.4f", y) ~= string.format("%.4f", cursorY) then writeline("My ", string.format("%.4f", y)); cursorY = y end
local oldx, oldy = self:getCursor()
local offset = relative and { x = cursorX, y = cursorY } or { x = 0, y = 0 }
cursorX = offset.x + x
cursorY = offset.y - y
if string.format("%.4f", oldx) ~= string.format("%.4f", cursorX) then writeline("Mx ", string.format("%.4f", x)) end
if string.format("%.4f", oldy) ~= string.format("%.4f", cursorY) then writeline("My ", string.format("%.4f", y)) end
end,

setColor = function (self, color)
Expand Down
7 changes: 4 additions & 3 deletions core/libtexpdf-output.lua
Expand Up @@ -70,12 +70,13 @@ SILE.outputters.libtexpdf = {
return self:setCursor(x, y)
end,

setCursor = function (self, x, y)
setCursor = function (self, x, y, relative)
_deprecationCheck(self)
x = SU.cast("number", x)
y = SU.cast("number", y)
cursorX = x
cursorY = SILE.documentState.paperSize[2] - y
local offset = relative and { x = cursorX, y = cursorY } or { x = 0, y = 0 }
cursorX = offset.x + x
cursorY = offset.y + (relative and 0 or SILE.documentState.paperSize[2]) - y
end,

setColor = function (self, color)
Expand Down
7 changes: 4 additions & 3 deletions core/podofo-output.lua
Expand Up @@ -65,10 +65,11 @@ SILE.outputters.podofo = {
return self:setCursor(x, y)
end,

setCursor = function (self, x, y)
setCursor = function (self, x, y, relative)
_deprecationCheck(self)
cursorX = x
cursorY = SILE.documentState.paperSize[2] - y
local offset = relative and { x = cursorX, y = cursorY } or { x = 0, y = 0 }
cursorX = offset.x + x
cursorY = offset.y + SILE.documentState.paperSize[2] - y
end,

setColor = function (self, color)
Expand Down
18 changes: 10 additions & 8 deletions core/text-output.lua
Expand Up @@ -53,29 +53,31 @@ cursor = function (self)
return self:setCursor(x, y)
end,

setCursor = function (self, x, y)
setCursor = function (self, x, y, relative)
_deprecationCheck(self)
local bs = SILE.measurement("0.8bs"):tonumber()
local spc = SILE.measurement("0.8spc"):tonumber()
local offset = relative and { x = cursorX, y = cursorY } or { x = 0, y = 0 }
local newx, newy = offset.x + x, offset.y - y
if started then
if x < cursorX then
if newx < cursorX then
outfile:write("\n")
elseif y > cursorY then
if y - cursorY > bs then
elseif newy > cursorY then
if newy - cursorY > bs then
outfile:write("\n")
else
outfile:write("")
end
elseif x > cursorX then
if x - cursorX > spc then
elseif newx > cursorX then
if newx - cursorX > spc then
outfile:write(" ")
else
outfile:write("")
end
end
end
cursorY = y
cursorX = x
cursorY = newy
cursorX = newx
end,

setColor = function(self)
Expand Down

0 comments on commit 7caa9c8

Please sign in to comment.