<commit_before>local pdf = require("podofo");
if (not SILE.outputters) then SILE.outputters = {} end

local document
local page
local painter
local pagesize
local font

local cursorX = 0
local cursorY = 0
SILE.outputters.podofo = {
  init = function()
    document = pdf.PdfStreamedDocument(SILE.outputFilename)
    pagesize = pdf.PdfRect()
    pagesize:SetWidth(SILE.documentState.paperSize[1])
    pagesize:SetHeight(SILE.documentState.paperSize[2])
    page = document:CreatePage(pagesize)
    painter = podofo.PdfPainter();
    painter:SetPage(page)
  end,
  newPage = function()
    painter:FinishPage()
    page = document:CreatePage(pagesize)
    painter:SetPage(page)
  end,
  finish = function()
    painter:FinishPage()
    document:Close()
  end,
  setColor = function (self, color)
    painter:SetColor(color.r, color.g, color.b)
  end,
  outputHbox = function (value)
    if not value.glyphNames then return end
    for i = 1,#(value.glyphNames) do
      painter:DrawGlyph(document,cursorX, cursorY, value.glyphNames[i])
    end
  end,
  setFont = function (options)
    font = document:CreateFont(options.font, options.weight > 200, options.style == "italic")
    font:SetFontSize(options.size)
    painter:SetFont(font)
  end,<commit_msg>The reason this worked was grotesque typecasting hackery. Using MemDocuments means we can use the swig bindings without modification.<commit_after>local pdf = require("podofo");
if (not SILE.outputters) then SILE.outputters = {} end

local document
local page
local painter
local pagesize
local font

local cursorX = 0
local cursorY = 0
SILE.outputters.podofo = {
  init = function()
    document = pdf.PdfMemDocument()
    pagesize = pdf.PdfRect()
    pagesize:SetWidth(SILE.documentState.paperSize[1])
    pagesize:SetHeight(SILE.documentState.paperSize[2])
    page = document:CreatePage(pagesize)
    painter = podofo.PdfPainter();
    painter:SetPage(page)
  end,
  newPage = function()
    painter:FinishPage()
    page = document:CreatePage(pagesize)
    painter:SetPage(page)
  end,
  finish = function()
    painter:FinishPage()
    document:Write(SILE.outputFilename)
  end,
  setColor = function (self, color)
    painter:SetColor(color.r, color.g, color.b)
  end,
  outputHbox = function (value)
    if not value.glyphNames then return end
    for i = 1,#(value.glyphNames) do
      painter:DrawGlyph(document,cursorX, cursorY, value.glyphNames[i])
    end
  end,
  setFont = function (options)
    font = document:CreateFont(options.font, options.weight > 200, options.style == "italic")
    font:SetFontSize(options.size)
    painter:SetFont(font)
  end,
{'fraction_non_alphanumeric': 0.10988172453262114, 'fraction_numerical': 0.006104540251812286, 'mean_word_length': 4.21272365805169, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4973539', 'n_tokens_mistral': 876, 'n_tokens_neox': 862, 'n_words': 197}