<commit_before>local plain = SILE.require("plain", "classes")
local pecha = plain { id = "pecha" }

local tibetanNumber = function (n)
  local out = ""
  local a = 0x0f20
  repeat
    out = luautf8.char(n%10 + a) .. out
    n = (n - n%10)/10
  until n < 1
  return out
end

pecha.defaultFrameset = {
  content = {
    left = "5%pw",
    right = "95%pw",
    top = "5%ph",
    bottom = "90%ph"
  },
  folio =   {
    left = "right(content)",
    rotate = -90,
    width = "2.5%pw",
    top = "top(content)",
    height = "height(content)"
  },
  runningHead = {
    width = "2.5%pw",
    rotate = -90,
    right = "left(content)",
    top = "top(content)",
    height = "height(content)"
  }
}

function pecha:init()
  self:loadPackage("rotate")
  return plain.init(self)
end

function pecha:endPage()
  local folioframe = SILE.getFrame("folio")
  SILE.typesetNaturally(folioframe, function ()
    SILE.settings.pushState()
    -- Restore the settings to the top of the queue, which should be the document #986
    SILE.settings.toplevelState()
    SILE.settings.set("typesetter.breakwidth", folioframe:height())
    SILE.typesetter:typeset(" ")
    SILE.call("vfill")
    SILE.call("pecha-folio-font")
    SILE.call("center", {}, function ()
        SILE.typesetter:typeset(tibetanNumber(SILE.scratch.counters.folio.value))
    end)
    SILE.call("vfill")
    SILE.typesetter:leaveHmode()
    SILE.settings.popState()
  end)
  return plain.endPage(self)
end

function pecha:newPage()
  SILE.outputter:newPage()
  SILE.outputter:debugFrame(SILE.getFrame("content"))
  return self:initialFrame()
end

function pecha:registerCommands()
  plain.registerCommands(self)
  SILE.call("language", { main = "bo" })
  SILE.settings.set("document.lskip", SILE.nodefactory.hfillglue())
  SILE.settings.set("typesetter.parfillskip", SILE.nodefactory.glue())
  SILE.settings.set("document.parindent", SILE.nodefactory.glue())
end

return pecha

-- \right-running-head{\font[size=15pt]{\center{ཤེས་རབ་སྙིང་པོ་ }}}<commit_msg>chore(classes): Redo pecha class with Penlight class model<commit_after>local plain = require("classes.plain")
local pecha = pl.class(plain)
pecha._name = "pecha"

local tibetanNumber = function (n)
  local out = ""
  local a = 0x0f20
  repeat
    out = luautf8.char(n%10 + a) .. out
    n = (n - n%10)/10
  until n < 1
  return out
end

pecha.defaultFrameset = {
  content = {
    left = "5%pw",
    right = "95%pw",
    top = "5%ph",
    bottom = "90%ph"
  },
  folio =   {
    left = "right(content)",
    rotate = -90,
    width = "2.5%pw",
    top = "top(content)",
    height = "height(content)"
  },
  runningHead = {
    width = "2.5%pw",
    rotate = -90,
    right = "left(content)",
    top = "top(content)",
    height = "height(content)"
  }
}

function pecha:_init(options)
  self._init(self, options)
  self:loadPackage("rotate")
  SILE.call("language", { main = "bo" })
  SILE.settings.set("document.lskip", SILE.nodefactory.hfillglue())
  SILE.settings.set("typesetter.parfillskip", SILE.nodefactory.glue())
  SILE.settings.set("document.parindent", SILE.nodefactory.glue())
  -- Avoid calling this (yet) if we're the parent of some child class
  if self._name == "pecha" then self:post_init() end
  return self
end

function pecha:endPage()
  local folioframe = SILE.getFrame("folio")
  SILE.typesetNaturally(folioframe, function ()
    SILE.settings.pushState()
    -- Restore the settings to the top of the queue, which should be the document #986
    SILE.settings.toplevelState()
    SILE.settings.set("typesetter.breakwidth", folioframe:height())
    SILE.typesetter:typeset(" ")
    SILE.call("vfill")
    SILE.call("pecha-folio-font")
    SILE.call("center", {}, function ()
        SILE.typesetter:typeset(tibetanNumber(SILE.scratch.counters.folio.value))
    end)
    SILE.call("vfill")
    SILE.typesetter:leaveHmode()
    SILE.settings.popState()
  end)
  return plain.endPage(self)
end

function pecha:newPage()
  SILE.outputter:newPage()
  SILE.outputter:debugFrame(SILE.getFrame("content"))
  return self:initialFrame()
end

return pecha

-- \right-running-head{\font[size=15pt]{\center{ཤེས་རབ་སྙིང་པོ་ }}}
{'fraction_non_alphanumeric': 0.15963346997829755, 'fraction_numerical': 0.014950566674704605, 'mean_word_length': 3.660674157303371, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '574295', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1557, 'n_words': 288}