Skip to content

Commit

Permalink
refactor(outputters): Move backend specific functions to outputter
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Jan 6, 2024
1 parent c0f32a5 commit 23ef07e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions outputters/base.lua
Expand Up @@ -62,6 +62,8 @@ function outputter.setMetadata (_, _, _) end

function outputter.setBookmark (_, _, _) end

function outputter.drawRaw (_) end

function outputter:getOutputFilename ()
local fname
if SILE.outputFilename then
Expand Down
5 changes: 5 additions & 0 deletions outputters/cairo.lua
Expand Up @@ -120,4 +120,9 @@ function outputter:debugHbox (hbox, scaledWidth)
cr:move_to(x, y)
end

-- untested
function outputter.drawRaw (_, literal)
cr:show_text(literal)
end

return outputter
4 changes: 4 additions & 0 deletions outputters/debug.lua
Expand Up @@ -183,4 +183,8 @@ function outputter:setMetadata (key, value)
self:_writeline("Set metadata", key, value)
end

function outputter:drawRaw (literal)
self:_writeline("Draw raw", literal)
end

return outputter
6 changes: 6 additions & 0 deletions outputters/libtexpdf.lua
Expand Up @@ -386,4 +386,10 @@ function outputter:setBookmark (dest, title, level)
pdf.bookmark(d, level)
end

-- Assumes the caller known what they want to stuff in raw PDF format
function outputter:drawRaw (literal)
self:_ensureInit()
pdf.add_content(literal)
end

return outputter
6 changes: 6 additions & 0 deletions outputters/podofo.lua
Expand Up @@ -106,4 +106,10 @@ function outputter:debugHbox (hbox, scaledWidth)
--cr:move_to(x, y)
end

-- untested
function outputter:drawRaw (literal)
local x, y = self:getCursor()
painter:DrawText(x, y, literal, string.len(literal))
end

return outputter
5 changes: 5 additions & 0 deletions outputters/text.lua
Expand Up @@ -82,4 +82,9 @@ function outputter:drawHbox (value, width)
end
end

function outputter:drawRaw (literal)
self:_ensureInit()
outfile:write(literal)
end

return outputter
5 changes: 1 addition & 4 deletions packages/pdfstructure/init.lua
Expand Up @@ -126,16 +126,13 @@ function package:registerCommands ()
if SILE.outputter._name ~= "libtexpdf" then
SU.error("pdf package requires libtexpdf backend")
end
if type(SILE.outputter._ensureInit) == "function" then
SILE.outputter:_ensureInit()
end
SILE.typesetter:pushHbox({
value = nil,
height = SILE.measurement(0),
width = SILE.measurement(0),
depth = SILE.measurement(0),
outputYourself = function (_, _, _)
pdf.add_content(content[1])
SILE.outputter:drawRaw (content[1])
end
})
end)
Expand Down

0 comments on commit 23ef07e

Please sign in to comment.