Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Compatibility upgrade with SILE 0.15 #5

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions packages/barcodes/ean13/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
-- 2022-2024 Omikhleia / Didier Willis
-- License: MIT
--
require("silex.types") -- Compatibility shims

local base = require("packages.base")

local package = pl.class(base)
Expand Down Expand Up @@ -209,9 +211,9 @@ function package:registerCommands ()
local module = SC[scale]
if not module then SU.error("Invalid EAN scale (SC0 to SC9): "..scale) end

local X = SILE.length(module.."mm")
local X = SILE.types.length(module.."mm")
local H = 69.242424242 -- As per the standard, a minimal 22.85mm at standard X
local offsetcorr = corr and SILE.length("0.020mm") or SILE.length()
local offsetcorr = corr and SILE.types.length("0.020mm") or SILE.types.length()

local pattern = ean13(code)

Expand Down Expand Up @@ -249,30 +251,30 @@ function package:registerCommands ()
SILE.call("kern", { width = -106 * X })
-- First digit, at the start of the Left Quiet Zone
local h = hbox({ code:sub(1,1) })
h.width = SILE.length()
h.width = SILE.types.length()
-- First 6-digit sequence is at 11X LQZ + 3X guard = 14X
-- We add a 0.5X displacement from the normal guard (a bar)
-- while the central bar starts with a space).
SILE.call("kern", { width = 14.5 * X })
SILE.call("kern", { width = deltaFontWidth * X })
h = hbox({ code:sub(2,7) }) -- first sequence
h.width = SILE.length()
h.width = SILE.types.length()
-- Second 6-digit sequence is further at 6*7X digits + 5X guard = 47X
-- to which we remove the previous 0.5X displacement.
-- Substract an additional 0.5X displacement from the central guard
-- (a space) so as to end at 0.5X from the ending guard (a bar),
-- hence 46X...
SILE.call("kern", { width = 46 * X })
h = hbox({ code:sub(8,13) }) -- last sequence
h.width = SILE.length()
h.width = SILE.types.length()
SILE.call("kern", { width = -deltaFontWidth * X })
-- End marker is at 6*7X + 3X guard + 7X RQZ = 52X
-- Corrected by the above displacement, hence 52.5X
local l = SILE.length((52.5 - SILE.scratch.ean13.computed.width) * X)
local l = SILE.types.length((52.5 - SILE.scratch.ean13.computed.width) * X)
SILE.call("kern", { width = l })
if not addon then
h = hbox({ ">" }) -- closing bracket, aligned to the end of the Right Quiet Zone
h.width = SILE.length()
h.width = SILE.types.length()
end
SILE.call("kern", { width = (SILE.scratch.ean13.computed.width - 7) * X })
end)
Expand Down Expand Up @@ -305,9 +307,9 @@ function package:registerCommands ()
local module = SC[scale]
if not module then SU.error("Invalid EAN scale (SC0 to SC9): "..scale) end

local X = SILE.length(module.."mm")
local X = SILE.types.length(module.."mm")
local H = 66.363636364 -- As per the standard, a minimal 21.90mm at standard X
local offsetcorr = corr and SILE.length("0.020mm") or SILE.length()
local offsetcorr = corr and SILE.types.length("0.020mm") or SILE.types.length()

local pattern
if #code == 5 then
Expand Down Expand Up @@ -347,13 +349,13 @@ function package:registerCommands ()
SILE.call("kern", { width = -9 * #code * X })
for i = 1, #code do
local h = hbox({ code:sub(i,i) }) -- Distribute the digits
h.width = SILE.length()
h.width = SILE.types.length()
SILE.call("kern", { width = 9 * X })
end
local l = SILE.length((5 - SILE.scratch.ean13.computed.width) * X)
local l = SILE.types.length((5 - SILE.scratch.ean13.computed.width) * X)
SILE.call("kern", { width = l })
local h = hbox({ ">" }) -- closing bracket, aligned to the end of the Add-on Right Quiet Zone
h.width = SILE.length()
h.width = SILE.types.length()
SILE.call("kern", { width = (SILE.scratch.ean13.computed.width - 5) * X })
end)
end)
Expand Down
32 changes: 32 additions & 0 deletions rockspecs/barcodes.sile-1.2.0-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
rockspec_format = "3.0"
package = "barcodes.sile"
version = "1.2.0-1"
source = {
url = "git+https://github.com/Omikhleia/barcodes.sile.git",
tag = "v1.2.0",
}
description = {
summary = "Barcodes package for the SILE typesetting system.",
detailed = [[
This package for the SILE typesetter allows printing out an EAN-13 barcode
suitable for an ISBN (or ISSN, etc.)
]],
homepage = "https://github.com/Omikhleia/barcodes.sile",
license = "MIT",
}
dependencies = {
"lua >= 5.1",
"silex.sile >= 0.6.0, < 1.0",
}
build = {
type = "builtin",
modules = {
["sile.packages.barcodes"] = "packages/barcodes/init.lua",
["sile.packages.barcodes.ean13"] = "packages/barcodes/ean13/init.lua",
},
install = {
lua = {
["sile.packages.barcodes.ean13.fonts.OCRB"] = "packages/barcodes/ean13/fonts/OCRB.otf",
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ description = {
}
dependencies = {
"lua >= 5.1",
"silex.sile",
}
build = {
type = "builtin",
Expand Down