Skip to content

Commit

Permalink
feat: Include Skala's OCR B font in distribution and use it by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia authored and Didier Willis committed Jan 14, 2024
1 parent d92a24a commit 5c8a0b9
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 7 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ barcode, suitable for an ISBN (or ISSN, etc.)

![EAN-13 barcodes](ean13.png "ISBN examples")

The “human readable interpretation” in this example uses the “Hack” font. Any other
monospace font may be used, and a better result is obtained with an OCR-B font.
A good recommendation is [Matthew Skala's “OCR B” version](https://tsukurimashou.osdn.jp/ocr.php.en).
The “human readable interpretation” in this example uses the “Hack” font.
Any other monospace font may be used, and a better result is obtained with an OCR-B font.
A good recommendation is [Matthew Skala's “OCR B” version](https://tsukurimashou.osdn.jp/ocr.php.en),
which is considered public domain and is included in this package for mere convenience, see [details](packages/barcodes/ean13/fonts/README.md).

On a slightly related topic, you might also be interested in the [qrcode.sile](https://github.com/Omikhleia/qrcode.sile) package set.

Expand Down Expand Up @@ -44,4 +45,4 @@ of classes and packages.
## License

All SILE-related code and samples in this repository are released under the MIT license,
(c) 2022 Omikhleia.
(c) 2022-2023 Omikhleia.
31 changes: 31 additions & 0 deletions barcodes.sile-1.1.0-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
rockspec_format = "3.0"
package = "barcodes.sile"
version = "1.1.0-1"
source = {
url = "git+https://github.com/Omikhleia/barcodes.sile.git",
tag = "v1.1.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",
}
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",
}
}
}
5 changes: 5 additions & 0 deletions barcodes.sile-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@ build = {
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",
}
}
}
1 change: 0 additions & 1 deletion examples/ean13.sil
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
\nofolios
\use[module=packages.barcodes.ean13]
\font[family=Libertinus Serif, size=10]
\ean13:font[family=Hack]

\center{\font[weight=700, size=12]{EAN-13 barcodes}}

Expand Down
Binary file added packages/barcodes/ean13/fonts/OCRB.otf
Binary file not shown.
19 changes: 19 additions & 0 deletions packages/barcodes/ean13/fonts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This folder contains Matthew Skala's OCR B font version 0.3 (Matthew Skala 2011-2021, based on code by Norbert Schwarz 1986-2011).

Matthew Skala's fonts (OCR A and OCR B with variants, in several formats) used to be available from https://tsukurimashou.osdn.jp/ocr.php.en (and a number of possibly unofficial mirrors).

However, that site has been very slow for a while, and sometimes even unreachable (as of 2024).
When using other mirrors or font repositories, it is also not always clear which version is the latest, and whether it is the same as this one.

These fonts were released in the public domain.
We therefore decided to include the OCR B font in this repository, as a mere convenience, so users can use our package without having to install it separately.

We only include here the OpenType version of the OCR B font.

It is automatically used by our EAN-13 barcode package for SILE, in order to display the human-readable interpretation in barcodes, which only consists of digits.

That's a fairly limited subset, but commands are provided to change the font, if desired. As noted, this font is also available from other sources. There are also alternative OCR B fonts (whether free or sold for a fee). The original OCR B was designed in 1968 by Adrian Frutiger for Monotype, and derived into a number of variants, covering different character sets.

Despite EAN-13 being an international standard, the legal status of OCR fonts is apparently complicated.

We do not claim any rights on this font, and refer readers to the documents accompanying the original complete font distribution. We do not give any kind of binding legal opinion on the status of this font. If you require authoritative legal advice about your proposed use of this font, then you must retain a lawyer.
14 changes: 12 additions & 2 deletions packages/barcodes/ean13/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,19 @@ local function setupHumanReadableFont (options)
end)
end

-- Trick for ensuring we search resources from the folder containing the package,
-- wherever installed: get the debug location of a function just defined in
-- the current file, remove the initial @ and retrieve the dirname.
local function basepath ()
return pl.path.dirname(debug.getinfo(basepath, "S").source:sub(2))
end

if not SILE.scratch.ean13 then
SILE.scratch.ean13 = {}
setupHumanReadableFont({ family = "OCR B" })
local dirname = basepath()
local filename = pl.path.join(dirname, "fonts", "OCRB.otf")
SU.debug("barcodes.ean13", "OCRB font is", filename)
setupHumanReadableFont({ filename = filename })
end

local function hbox (content)
Expand Down Expand Up @@ -372,7 +382,6 @@ end
package.documentation = [[
\begin{document}
\use[module=packages.barcodes.ean13]
\ean13:font[family=Hack]% Not the best effect, but avoids hasardous substitutions when OCR B is not installed
The \autodoc:package{barcodes.ean13} package allows to print out an EAN-13 barcode, suitable
for an ISBN (or ISSN, etc.)
Expand All @@ -394,6 +403,7 @@ option.
The human readable interpretation below the barcode expects the font to be OCR-B.
A free public domain implementation of this font is Matthew Skala’s July 2021 version, at \url{https://tsukurimashou.osdn.jp/ocr.php.en}, recommended for use with this package.
The font is included in the package, for convenience, and is loaded automatically.
The \autodoc:command{\ean13:font[family=<family>]} (or \autodoc:command{\ean13:font[filename=<filename>]}) command allows setting the font family (or file name), would another choice be preferred.
Obviously, a monospace font is strongly advised.
The package does its best for decently sizing and positioning the text, but your mileage may vary depending on the chosen font.
Expand Down

0 comments on commit 5c8a0b9

Please sign in to comment.