From a104fdb7da927564357bc14fad97b4bb136e348e Mon Sep 17 00:00:00 2001 From: Omikhleia Date: Thu, 1 Aug 2024 19:31:43 +0200 Subject: [PATCH] refactor: Compatibility upgrade with SILE 0.15 --- packages/framebox/init.lua | 36 +++++++++--------- packages/parbox/init.lua | 44 +++++++++++----------- packages/ptable/init.lua | 22 ++++++----- packages/struts/init.lua | 14 ++++--- rockspecs/ptable.sile-3.1.0-1.rockspec | 51 ++++++++++++++++++++++++++ rockspecs/ptable.sile-dev-1.rockspec | 1 + 6 files changed, 114 insertions(+), 54 deletions(-) create mode 100644 rockspecs/ptable.sile-3.1.0-1.rockspec diff --git a/packages/framebox/init.lua b/packages/framebox/init.lua index 89e6fee..559204c 100644 --- a/packages/framebox/init.lua +++ b/packages/framebox/init.lua @@ -5,6 +5,8 @@ -- -- KNOWN ISSUE: RTL and BTT writing directions are not officialy supported yet (untested) -- +require("silex.types") -- Compatibility shims + local base = require("packages.base") local package = pl.class(base) @@ -85,28 +87,28 @@ function package.declareSettings (_) SILE.settings:declare({ parameter = "framebox.padding", type = "measurement", - default = SILE.measurement("2pt"), + default = SILE.types.measurement("2pt"), help = "Padding applied to a framed box." }) SILE.settings:declare({ parameter = "framebox.borderwidth", type = "measurement", - default = SILE.measurement("0.4pt"), + default = SILE.types.measurement("0.4pt"), help = "Border width applied to a frame box." }) SILE.settings:declare({ parameter = "framebox.cornersize", type = "measurement", - default = SILE.measurement("5pt"), + default = SILE.types.measurement("5pt"), help = "Corner size (arc radius) for rounded boxes." }) SILE.settings:declare({ parameter = "framebox.shadowsize", type = "measurement", - default = SILE.measurement("3pt"), + default = SILE.types.measurement("3pt"), help = "Shadow width applied to a framed box when dropped shadow is enabled." }) end @@ -119,12 +121,12 @@ function package:registerCommands () local borderwidth = SU.cast("measurement", options.borderwidth or SILE.settings:get("framebox.borderwidth")):tonumber() local bordercolor if borderwidth ~= 0 then - bordercolor = options.bordercolor and SILE.color(options.bordercolor) + bordercolor = options.bordercolor and SILE.types.color(options.bordercolor) end - local fillcolor = options.fillcolor and SILE.color(options.fillcolor) or 'none' + local fillcolor = options.fillcolor and SILE.types.color(options.fillcolor) or 'none' local shadow = SU.boolean(options.shadow, false) local shadowsize = shadow and SU.cast("measurement", options.shadowsize or SILE.settings:get("framebox.shadowsize")):tonumber() or 0 - local shadowcolor = shadow and options.shadowcolor and SILE.color(options.shadowcolor) + local shadowcolor = shadow and options.shadowcolor and SILE.types.color(options.shadowcolor) local hbox, hlist = SILE.typesetter:makeHbox(content) hbox = adjustPaddingHbox(hbox, padding, padding + shadowsize, padding, padding + shadowsize) @@ -150,12 +152,12 @@ function package:registerCommands () local borderwidth = SU.cast("measurement", options.borderwidth or SILE.settings:get("framebox.borderwidth")):tonumber() local bordercolor if borderwidth ~= 0 then - bordercolor = options.bordercolor and SILE.color(options.bordercolor) + bordercolor = options.bordercolor and SILE.types.color(options.bordercolor) end - local fillcolor = options.fillcolor and SILE.color(options.fillcolor) or 'none' + local fillcolor = options.fillcolor and SILE.types.color(options.fillcolor) or 'none' local shadow = SU.boolean(options.shadow, false) local shadowsize = shadow and SU.cast("measurement", options.shadowsize or SILE.settings:get("framebox.shadowsize")):tonumber() or 0 - local shadowcolor = shadow and options.shadowcolor and SILE.color(options.shadowcolor) + local shadowcolor = shadow and options.shadowcolor and SILE.types.color(options.shadowcolor) local cornersize = SU.cast("measurement", options.cornersize or SILE.settings:get("framebox.cornersize")):tonumber() @@ -192,8 +194,8 @@ function package:registerCommands () -- (for hachures etc.) borderwidth = SILE.settings:get("framebox.borderwidth"):tonumber() end - local bordercolor = options.bordercolor and SILE.color(options.bordercolor) - local fillcolor = options.fillcolor and SILE.color(options.fillcolor) + local bordercolor = options.bordercolor and SILE.types.color(options.bordercolor) + local fillcolor = options.fillcolor and SILE.types.color(options.fillcolor) local enlarge = SU.boolean(options.enlarge, false) local hbox, hlist = SILE.typesetter:makeHbox(content) @@ -227,11 +229,11 @@ function package:registerCommands () end, "Frames content in a rough (sketchy) box.") self:registerCommand("bracebox", function(options, content) - local padding = SU.cast("measurement", options.padding or SILE.measurement("0.25em")):tonumber() - local strokewidth = SU.cast("measurement", options.strokewidth or SILE.measurement("0.033em")):tonumber() - local bracecolor = options.bracecolor and SILE.color(options.bracecolor) - local bracewidth = SU.cast("measurement", options.bracewidth or SILE.measurement("0.25em")):tonumber() - local bracethickness = SU.cast("measurement", options.bracethickness or SILE.measurement("0.05em")):tonumber() + local padding = SU.cast("measurement", options.padding or SILE.types.measurement("0.25em")):tonumber() + local strokewidth = SU.cast("measurement", options.strokewidth or SILE.types.measurement("0.033em")):tonumber() + local bracecolor = options.bracecolor and SILE.types.color(options.bracecolor) + local bracewidth = SU.cast("measurement", options.bracewidth or SILE.types.measurement("0.25em")):tonumber() + local bracethickness = SU.cast("measurement", options.bracethickness or SILE.types.measurement("0.05em")):tonumber() local curvyness = SU.cast("number", options.curvyness or 0.6) local left, right if options.side == "left" or not options.side then left = true diff --git a/packages/parbox/init.lua b/packages/parbox/init.lua index 60a68cc..e2b0e38 100644 --- a/packages/parbox/init.lua +++ b/packages/parbox/init.lua @@ -7,6 +7,8 @@ -- -- Known limitations: LTR-TTB writing direction is assumed. -- +require("silex.types") -- Compatibility shims + local base = require("packages.base") local package = pl.class(base) @@ -25,9 +27,9 @@ local function parboxTempFrame (options) id = id }) nb_ = nb_+1 - newFrame:constrain("top", SILE.length()) - newFrame:constrain("bottom", SILE.length()) - newFrame:constrain("left", SILE.length()) + newFrame:constrain("top", SILE.types.length()) + newFrame:constrain("bottom", SILE.types.length()) + newFrame:constrain("left", SILE.types.length()) newFrame:constrain("right", options.width) return newFrame end @@ -105,7 +107,7 @@ local function getBaselineExtents (vboxlist) -- depth of the last line, so we can use these to vertically align the parbox -- with the surrounding content. -- The way we do it likely assumes top-to-bottom writing... - local baseHeight, baseDepth = SILE.length(), SILE.length() + local baseHeight, baseDepth = SILE.types.length(), SILE.types.length() for i = 1, #vboxlist do if vboxlist[i].is_vbox and vboxlist[i].height then baseHeight = vboxlist[i].height @@ -174,10 +176,10 @@ function package.makeParbox(_, options, content) local border = options.border and parseBorderOrPadding(options.border, "border") or { 0, 0, 0, 0 } local valign = options.valign or "top" local padding = options.padding and parseBorderOrPadding(options.padding, "padding") or { 0, 0, 0, 0 } - local bordercolor = options.bordercolor and SILE.color(options.bordercolor) + local bordercolor = options.bordercolor and SILE.types.color(options.bordercolor) local minimize = SU.boolean(options.minimize, false) - width = SILE.length(SU.cast("measurement", width)):absolute() + width = SILE.types.length(SU.cast("measurement", width)):absolute() local vboxes, hlist = parboxFraming({ width = width }, content) @@ -187,13 +189,13 @@ function package.makeParbox(_, options, content) elseif strut == "character" then strutDimen = SILE.call("strut", { method = "character" }) else - strutDimen = { height = SILE.length(0), depth = SILE.length(0) } + strutDimen = { height = SILE.types.length(0), depth = SILE.types.length(0) } end local baseHeight, baseDepth = getBaselineExtents(vboxes) - local wmax = SILE.length() - local totalHeight = SILE.length() + local wmax = SILE.types.length() + local totalHeight = SILE.types.length() local vboxWidths = {} for i = 1, #vboxes do -- Try to cancel vertical stretching/shrinking @@ -202,13 +204,13 @@ function package.makeParbox(_, options, content) -- by the page builder. We cannot tweak directly their height or depth as we -- sometimes do with other boxes, as it would have a side effect. So we have -- to re-create a new vglue with the appropriate fixed dimension. - vboxes[i] = SILE.nodefactory.vglue(SILE.length(vboxes[i].height.length)) + vboxes[i] = SILE.types.node.vglue(SILE.types.length(vboxes[i].height.length)) end totalHeight = totalHeight + vboxes[i].height:absolute() + vboxes[i].depth:absolute() if minimize then -- We go through all lines to retrieve their natural line. - local w = SILE.length() + local w = SILE.types.length() if vboxes[i].nodes then w = naturalWidth(width, vboxes[i].nodes) if w > wmax then wmax = w end @@ -220,7 +222,7 @@ function package.makeParbox(_, options, content) if minimize then -- The max line width can actually be bigger than our target width, -- (i.e. notwithstanding its shrinkeability). - local wmaxlen = SILE.length(wmax.length) -- Lua5.1 doesn't like comparing appels and oranges + local wmaxlen = SILE.types.length(wmax.length) -- Lua5.1 doesn't like comparing appels and oranges width = SU.min(wmaxlen, width) -- We recompute all line ratios based on the new target width. for i = 1, #vboxes do @@ -233,30 +235,30 @@ function package.makeParbox(_, options, content) local adjustDepth = SU.max(baseDepth, strutDimen.depth) - baseDepth local adjustHeight = SU.max(baseHeight, strutDimen.height) - baseHeight - local z0 = SILE.length(0) + local z0 = SILE.types.length(0) local depth, height if valign == "bottom" then - depth = z0 + SILE.length(padding[2]) + SU.max(baseDepth, strutDimen.depth) - height = totalHeight + SILE.length(padding[1]) - baseDepth + adjustHeight + depth = z0 + SILE.types.length(padding[2]) + SU.max(baseDepth, strutDimen.depth) + height = totalHeight + SILE.types.length(padding[1]) - baseDepth + adjustHeight elseif valign == "middle" then - local padwidth = SILE.length(padding[2] + padding[1]) + local padwidth = SILE.types.length(padding[2] + padding[1]) local half = (totalHeight + adjustHeight + adjustDepth + padwidth) / 2 depth = half height = half else -- valign == top - depth = totalHeight + SILE.length(padding[2]) - baseHeight + adjustDepth - height = z0 + SILE.length(padding[1]) + SU.max(baseHeight, strutDimen.height) + depth = totalHeight + SILE.types.length(padding[2]) - baseHeight + adjustDepth + height = z0 + SILE.types.length(padding[1]) + SU.max(baseHeight, strutDimen.height) end - local parbox = SILE.nodefactory.hbox({ - width = width + SILE.length(padding[3] + padding[4]), + local parbox = SILE.types.node.hbox({ + width = width + SILE.types.length(padding[3] + padding[4]), depth = depth, height = height, inner = vboxes, valign = valign, padding = padding, yAdjust = adjustHeight, -- TTB is assumed - offset = SILE.measurement(), -- INTERNAL: See comment below. + offset = SILE.types.measurement(), -- INTERNAL: See comment below. border = border, bordercolor = bordercolor, outputYourself= function (node, typesetter, _) diff --git a/packages/ptable/init.lua b/packages/ptable/init.lua index 4c33901..cf5a1b5 100644 --- a/packages/ptable/init.lua +++ b/packages/ptable/init.lua @@ -4,6 +4,8 @@ -- 2021-2023 Didier Willis -- License: MIT -- +require("silex.types") -- Compatibility shims + local base = require("packages.base") local makeParbox -- assigned at package initialization @@ -75,12 +77,12 @@ end -- on top of that... In a heavy-handed way (this function -- might even be called where uneeded, strictly speaking). local function vglueNoStretch (vg) - return SILE.nodefactory.vglue(SILE.length(vg.height.length)) + return SILE.types.node.vglue(SILE.types.length(vg.height.length)) end local function temporarilyClearFragileSettings (callback) SILE.settings:pushState() -- Kill that small lineskip thing that may move rows a bit. - SILE.settings:set("document.lineskip", SILE.length()) + SILE.settings:set("document.lineskip", SILE.types.length()) -- Kill stretchability at baseline and paragraph level. SILE.settings:set("document.baselineskip", vglueNoStretch(SILE.settings:get("document.baselineskip"))) SILE.settings:set("document.parskip", vglueNoStretch(SILE.settings:get("document.parskip"))) @@ -195,7 +197,7 @@ local cellTableNode = pl.class({ temporarilyClearFragileSettings(function() for i = 1, #self.rows do -- Set up queue but avoid a newPar? Apparently not needed here. - -- SILE.typesetter.state.nodes[#SILE.typesetter.state.nodes+1] = SILE.nodefactory.zerohbox() + -- SILE.typesetter.state.nodes[#SILE.typesetter.state.nodes+1] = SILE.types.node.zerohbox() self.rows[i]:shipout() end end) @@ -212,9 +214,9 @@ local rowNode = pl.class({ self.color = color end, height = function (self) - local h = SILE.length() + local h = SILE.types.length() for i = 1, #self.cells do - h = SU.max(self.cells[i]:height(), SILE.length(h)) + h = SU.max(self.cells[i]:height(), SILE.types.length(h)) end return h end, @@ -229,7 +231,7 @@ local rowNode = pl.class({ -- Important hack or a parindent occurs sometimes: Set up queue but avoid a newPar. -- We had do to the same weird magic in the parbox package too at one step, see the -- comment there. - SILE.typesetter.state.nodes[#SILE.typesetter.state.nodes+1] = SILE.nodefactory.zerohbox() + SILE.typesetter.state.nodes[#SILE.typesetter.state.nodes+1] = SILE.types.node.zerohbox() local hbox, hlist = SILE.typesetter:makeHbox(function () for i = 1, #self.cells do self.cells[i]:shipout() @@ -247,7 +249,7 @@ local processTable = {} processTable["cell"] = function (content, args, tablespecs) local span = SU.cast("integer", content.options.span or 1) - local color = content.options.background and SILE.color(content.options.background) + local color = content.options.background and SILE.types.color(content.options.background) local pad = parsePadding(content.options.padding or tablespecs.cellpadding) local width = computeCellWidth(args.col, span, tablespecs.cols) @@ -284,9 +286,9 @@ processTable["celltable"] = function (content, args, tablespecs) end processTable["row"] = function (content, args, tablespecs) - local color = content.options.background and SILE.color(content.options.background) + local color = content.options.background and SILE.types.color(content.options.background) - SILE.settings:set("document.lineskip", SILE.length()) + SILE.settings:set("document.lineskip", SILE.types.length()) local iCell = args.col and args.col or 1 local cells = {} for i = 1, #content do @@ -380,7 +382,7 @@ function package:registerCommands () local headerVbox temporarilyClearFragileSettings(function() - SILE.settings:set("document.parindent", SILE.length()) + SILE.settings:set("document.parindent", SILE.types.length()) local iRow = 1 for i = 1, #content do if type(content[i]) == "table" then diff --git a/packages/struts/init.lua b/packages/struts/init.lua index 97b1754..2040867 100644 --- a/packages/struts/init.lua +++ b/packages/struts/init.lua @@ -3,6 +3,8 @@ -- 2021-2023 Didier Willis -- License: MIT -- +require("silex.types") -- Compatibility shims + local base = require("packages.base") local package = pl.class(base) @@ -24,14 +26,14 @@ function package.declareSettings (_) SILE.settings:declare({ parameter = "strut.ruledepth", type = "measurement", - default = SILE.measurement("0.3bs"), + default = SILE.types.measurement("0.3bs"), help = "Strut rule depth" }) SILE.settings:declare({ parameter = "strut.ruleheight", type = "measurement", - default = SILE.measurement("1bs"), + default = SILE.types.measurement("1bs"), help = "Strut rule height" }) end @@ -68,17 +70,17 @@ function package:registerCommands () local strut if method == "rule" then strut = { - height = SILE.length(SILE.settings:get("strut.ruleheight")):absolute(), - depth = SILE.length(SILE.settings:get("strut.ruledepth")):absolute(), + height = SILE.types.length(SILE.settings:get("strut.ruleheight")):absolute(), + depth = SILE.types.length(SILE.settings:get("strut.ruledepth")):absolute(), } if show then -- The content there could be anything, we just want to be sure we get a box - SILE.call("rebox", { phantom = true, height = strut.height, depth = strut.depth, width = SILE.length() }, {}) + SILE.call("rebox", { phantom = true, height = strut.height, depth = strut.depth, width = SILE.types.length() }, {}) end elseif method == "character" then strut = characterStrut() if show then - SILE.call("rebox", { phantom = true, width = SILE.length() }, { SILE.settings:get("strut.character") }) + SILE.call("rebox", { phantom = true, width = SILE.types.length() }, { SILE.settings:get("strut.character") }) end else SU.error("Unknown strut method '" .. method .. "'") diff --git a/rockspecs/ptable.sile-3.1.0-1.rockspec b/rockspecs/ptable.sile-3.1.0-1.rockspec new file mode 100644 index 0000000..609daac --- /dev/null +++ b/rockspecs/ptable.sile-3.1.0-1.rockspec @@ -0,0 +1,51 @@ +rockspec_format = "3.0" +package = "ptable.sile" +version = "3.1.0-1" +source = { + url = "git+https://github.com/Omikhleia/ptable.sile.git", + tag = "v3.1.0", +} +description = { + summary = "Paragraph boxes, framed boxes and table packages for the SILE typesetting system.", + detailed = [[ + This package for the SILE typesetter provides struts, paragraph boxes + (parbox), framed boxes (framebox) and tables (ptable). + ]], + homepage = "https://github.com/Omikhleia/ptable.sile", + license = "MIT", +} +dependencies = { + "lua >= 5.1", + "silex.sile >= 0.6.0, < 1.0", +} +build = { + type = "builtin", + modules = { + ["sile.packages.struts"] = "packages/struts/init.lua", + ["sile.packages.parbox"] = "packages/parbox/init.lua", + ["sile.packages.ptable"] = "packages/ptable/init.lua", + ["sile.packages.framebox"] = "packages/framebox/init.lua", + ["sile.packages.framebox.graphics.renderer"] = "packages/framebox/graphics/renderer.lua", + ["sile.packages.framebox.graphics.rough"] = "packages/framebox/graphics/rough.lua", + ["prng-prigarin"] = "prng-prigarin/init.lua", + ["rough-lua.rough.jsshims"] = "rough-lua/rough/jsshims.lua", + ["rough-lua.rough.generator"] = "rough-lua/rough/generator.lua", + ["rough-lua.rough.renderer"] = "rough-lua/rough/renderer.lua", + ["rough-lua.rough.fillers.hachure-filler"] = "rough-lua/rough/fillers/hachure-filler.lua", + ["rough-lua.rough.fillers.zigzag-filler"] = "rough-lua/rough/fillers/zigzag-filler.lua", + ["rough-lua.rough.fillers.zigzag-line-filler"] = "rough-lua/rough/fillers/zigzag-line-filler.lua", + ["rough-lua.rough.fillers.dot-filler"] = "rough-lua/rough/fillers/dot-filler.lua", + ["rough-lua.rough.fillers.dashed-filler"] = "rough-lua/rough/fillers/dashed-filler.lua", + ["rough-lua.rough.fillers.scan-line-hachure"] = "rough-lua/rough/fillers/scan-line-hachure.lua", + ["rough-lua.rough.fillers.hatch-filler"] = "rough-lua/rough/fillers/hatch-filler.lua", + ["rough-lua.rough.fillers.hachure-fill"] = "rough-lua/rough/fillers/hachure-fill.lua", + ["rough-lua.rough.fillers.filler"] = "rough-lua/rough/fillers/filler.lua", + ["rough-lua.rough.geometry"] = "rough-lua/rough/geometry.lua", + ["rough-lua.untested.path-data-parser"] = "rough-lua/untested/path-data-parser/init.lua", + ["rough-lua.untested.path-data-parser.parser"] = "rough-lua/untested/path-data-parser/parser.lua", + ["rough-lua.untested.path-data-parser.normalize"] = "rough-lua/untested/path-data-parser/normalize.lua", + ["rough-lua.untested.path-data-parser.absolutize"] = "rough-lua/untested/path-data-parser/absolutize.lua", + ["rough-lua.untested.points-on-curve"] = "rough-lua/untested/points-on-curve/init.lua", + ["rough-lua.untested.points-on-curve.curve-to-bezier"] = "rough-lua/untested/points-on-curve/curve-to-bezier.lua", + } +} diff --git a/rockspecs/ptable.sile-dev-1.rockspec b/rockspecs/ptable.sile-dev-1.rockspec index 9a24b55..a397a69 100644 --- a/rockspecs/ptable.sile-dev-1.rockspec +++ b/rockspecs/ptable.sile-dev-1.rockspec @@ -15,6 +15,7 @@ description = { } dependencies = { "lua >= 5.1", + "silex.sile", } build = { type = "builtin",