imprimatur 0.3.0-aarch64-linux-gnu → 0.4.0-aarch64-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +41 -1
- data/lib/imprimatur/4.0/imprimatur_native.so +0 -0
- data/lib/imprimatur/barcode.rb +78 -0
- data/lib/imprimatur/document.rb +17 -1
- data/lib/imprimatur/version.rb +1 -1
- data/lib/imprimatur.rb +4 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 820b696bf9efd260711282d1ad700b843939f469797577f578db69490d90795c
|
|
4
|
+
data.tar.gz: a53d88596e77e76cfa13e967ff9a095f7f996d0d21ffb3aa2b1b6bf6bcfcba9a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0a0bec11ea0fe229a56b729d3c40f8ef8f397d4940780a0460d2772ef5cec8529f7ec97dfcd99759b7b5fd30fa6a026a62d97115a94c113857af06d563616800
|
|
7
|
+
data.tar.gz: a659697da26c4e7878a17f6d2442bc53403dbb926f91d930e026a9468f00437a4403b14325f00b3d9e6d63580074d8e83e1f4b22ef3a163b4797d80aa2ea9513
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.0](https://github.com/seuros/imprimatur/compare/v0.3.0...v0.4.0) (2026-10-18)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* barcodes: QR Code, Data Matrix, EAN-13, EAN-8, UPC-A and Code 128, GS1 forms included, as SVG, PNG and in documents ([ade7b68](https://github.com/seuros/imprimatur/commit/ade7b68f4c5adcab9d2ee0b935288eea7ec2eea6))
|
|
9
|
+
* **pdf:** add embedded TrueType font resources ([c0e3be4](https://github.com/seuros/imprimatur/commit/c0e3be4ef46ede94fcc840840e82d8ccb6679f3e))
|
|
10
|
+
* **pdf:** add embedded TrueType font resources ([313075f](https://github.com/seuros/imprimatur/commit/313075fe8ba1bedc9f4156060aeedcbb0e0a8bef))
|
|
11
|
+
|
|
3
12
|
## [0.3.0](https://github.com/seuros/imprimatur/compare/v0.2.0...v0.3.0) (2026-10-17)
|
|
4
13
|
|
|
5
14
|
|
data/README.md
CHANGED
|
@@ -9,7 +9,8 @@ a 40,000-character cell is refused at the door, not discovered by Excel's
|
|
|
9
9
|
as `imprimatur` on crates.io; the gem wraps it.
|
|
10
10
|
- **No third-party format stack.** The XML writer and the zip container are
|
|
11
11
|
written here, from ECMA-376 and the zip specification; only deflate
|
|
12
|
-
(`miniz_oxide`) and CRC-32 (`crc32fast`) come from crates
|
|
12
|
+
(`miniz_oxide`) and CRC-32 (`crc32fast`) come from crates, and QR Code and
|
|
13
|
+
Data Matrix encoding (`qrcode`, `datamatrix`) for barcodes.
|
|
13
14
|
- **Deterministic.** The same document always gives the same bytes.
|
|
14
15
|
- **Native only.** CRuby 4.0+. No pure Ruby fallback, no JRuby, no TruffleRuby.
|
|
15
16
|
|
|
@@ -223,6 +224,45 @@ dashes, the euro sign. Anything else (Arabic, Hebrew, Greek, CJK, emoji) raises
|
|
|
223
224
|
script. Embedded TrueType fonts, and with them every script and proper RTL in
|
|
224
225
|
PDF, are the next step.
|
|
225
226
|
|
|
227
|
+
## Barcodes
|
|
228
|
+
|
|
229
|
+
QR Code, Data Matrix, EAN-13, EAN-8, UPC-A and Code 128, and the GS1 forms of
|
|
230
|
+
QR Code, Data Matrix and Code 128 (GS1-128):
|
|
231
|
+
|
|
232
|
+
```ruby
|
|
233
|
+
qr = Imprimatur.barcode(:qr, "https://id.gs1.org/01/09506000134352", level: :m)
|
|
234
|
+
File.write("qr.svg", qr.svg(module_size: 4))
|
|
235
|
+
File.binwrite("qr.png", qr.png(module_size: 8, background: nil)) # transparent
|
|
236
|
+
|
|
237
|
+
ean = Imprimatur.barcode(:ean13, "950600013435")
|
|
238
|
+
ean.text # => "9506000134352", the check digit added (or checked when given)
|
|
239
|
+
|
|
240
|
+
label = Imprimatur.barcode(:code128, "(00)106141412345678908", gs1: true) # GS1-128
|
|
241
|
+
dpp = Imprimatur.barcode(:datamatrix, "(01)09506000134352(21)ABC123", gs1: true)
|
|
242
|
+
|
|
243
|
+
Imprimatur.pdf("label.pdf", page_size: [300, 200], margin: 10) do |doc|
|
|
244
|
+
doc.barcode label, width: 280
|
|
245
|
+
doc.barcode dpp, width: 72, align: :right
|
|
246
|
+
end
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
- `:qr` (`level:` `:l`, `:m`, `:q` or `:h`), `:datamatrix` (square),
|
|
250
|
+
`:ean13`, `:ean8`, `:upca` and `:code128`; `gs1: true` for the GS1 forms of
|
|
251
|
+
`:qr`, `:datamatrix` and `:code128`.
|
|
252
|
+
- GS1 element strings are written as people write them, AIs in parentheses,
|
|
253
|
+
and checked: AI syntax, GS1's character set, the AIs whose lengths are
|
|
254
|
+
predefined, and the check digits of SSCCs, GTINs and GLNs. Separators go in
|
|
255
|
+
only where a variable-length field needs one.
|
|
256
|
+
- `svg` and `png` take `module_size:`, `color:`, `background:` (nil for
|
|
257
|
+
none), `quiet_zone:` and, for linear codes, `bar_height:` in modules. PNGs
|
|
258
|
+
are one bit a pixel.
|
|
259
|
+
- In documents, barcodes are vector shapes in a PDF and a 300 dpi picture in
|
|
260
|
+
DOCX, at `width:` or `height:` points or else at their usual module size
|
|
261
|
+
(0.33 mm for EAN and UPC, 0.495 mm for GS1-128, 0.7 mm for QR Code and Data
|
|
262
|
+
Matrix), quiet zone included.
|
|
263
|
+
- `text`, `symbology`, `gs1?`, `width`, `height` (in modules), and `modules`
|
|
264
|
+
(rows of booleans) for drawing them some other way.
|
|
265
|
+
|
|
226
266
|
## Reading: documents as Markdown
|
|
227
267
|
|
|
228
268
|
The other direction: a PDF, a workbook (XLSX, legacy XLS, ODS) or a DOCX
|
|
Binary file
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Imprimatur
|
|
4
|
+
# A barcode: QR Code, Data Matrix, EAN-13, EAN-8, UPC-A or Code 128, and the
|
|
5
|
+
# GS1 forms of QR Code, Data Matrix and Code 128 (GS1-128). Built with
|
|
6
|
+
# {Imprimatur.barcode}; draw it with {#svg} or {#png}, or place it in a
|
|
7
|
+
# {Document} with {Document#barcode}. The class itself is native.
|
|
8
|
+
#
|
|
9
|
+
# qr = Imprimatur.barcode(:qr, 'https://id.gs1.org/01/09506000134352')
|
|
10
|
+
# File.write('qr.svg', qr.svg(module_size: 4))
|
|
11
|
+
#
|
|
12
|
+
# label = Imprimatur.barcode(:code128, '(00)106141412345678908', gs1: true)
|
|
13
|
+
# File.binwrite('label.png', label.png(module_size: 3))
|
|
14
|
+
#
|
|
15
|
+
# Imprimatur.barcode(:ean13, '950600013435').text # => "9506000134352"
|
|
16
|
+
class Barcode
|
|
17
|
+
SYMBOLOGIES = %i[qr datamatrix ean13 ean8 upca code128].freeze
|
|
18
|
+
|
|
19
|
+
# @param symbology [:qr, :datamatrix, :ean13, :ean8, :upca, :code128]
|
|
20
|
+
# @param data [String] text; a GTIN's digits for EAN and UPC, the check
|
|
21
|
+
# digit added when left out; with +gs1: true+, a GS1 element string
|
|
22
|
+
# such as "(01)09506000134352(17)251231(10)AB12"
|
|
23
|
+
# @param gs1 [Boolean] a GS1 QR Code, GS1 DataMatrix or GS1-128
|
|
24
|
+
# @param level [:l, :m, :q, :h, nil] a QR Code's error correction, :m unless set
|
|
25
|
+
# @return [Barcode]
|
|
26
|
+
# @raise [Imprimatur::Error] data the symbology cannot hold, an invalid
|
|
27
|
+
# element string, or a wrong check digit
|
|
28
|
+
# @raise [ArgumentError] an unknown symbology or level, or one that does not apply
|
|
29
|
+
def self.encode(symbology, data, gs1: false, level: nil)
|
|
30
|
+
__encode(symbology.to_s, String(data), gs1 ? true : false, level&.to_s)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private_class_method :__encode
|
|
34
|
+
|
|
35
|
+
# @param module_size [Numeric] user units (pixels) a module, 0.01 to 1000
|
|
36
|
+
# @param color [String] the bars, "#RRGGBB"
|
|
37
|
+
# @param background [String, nil] "#RRGGBB", or nil for none
|
|
38
|
+
# @param quiet_zone [Boolean] keep the blank margin scanners need
|
|
39
|
+
# @param bar_height [Integer, nil] a linear code's bar height in modules;
|
|
40
|
+
# the symbology's nominal height unless set
|
|
41
|
+
# @return [String] SVG markup
|
|
42
|
+
# @raise [Imprimatur::Error] a module size or color out of range
|
|
43
|
+
def svg(module_size: 4, color: '#000000', background: '#FFFFFF', quiet_zone: true, bar_height: nil)
|
|
44
|
+
__svg(Float(module_size), look(color, background, quiet_zone, bar_height))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @param module_size [Integer] pixels a module
|
|
48
|
+
# @param (see #svg)
|
|
49
|
+
# @return [String] the PNG bytes (binary): one bit a pixel, the background
|
|
50
|
+
# transparent when nil
|
|
51
|
+
# @raise [Imprimatur::Error] a size of 0, an image above 65 536 pixels a side,
|
|
52
|
+
# or an invalid color
|
|
53
|
+
def png(module_size: 4, color: '#000000', background: '#FFFFFF', quiet_zone: true, bar_height: nil)
|
|
54
|
+
__png(Integer(module_size), look(color, background, quiet_zone, bar_height))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# @!method symbology
|
|
58
|
+
# @return [Symbol] one of {SYMBOLOGIES}
|
|
59
|
+
# @!method text
|
|
60
|
+
# @return [String] what it encodes: the data given, or a GTIN with its check digit
|
|
61
|
+
# @!method gs1?
|
|
62
|
+
# @return [Boolean] whether it carries a GS1 element string
|
|
63
|
+
# @!method width
|
|
64
|
+
# @return [Integer] modules across, without the quiet zone
|
|
65
|
+
# @!method height
|
|
66
|
+
# @return [Integer] modules down; 1 for a linear code
|
|
67
|
+
# @!method modules
|
|
68
|
+
# @return [Array<Array<Boolean>>] rows of modules, true for dark
|
|
69
|
+
|
|
70
|
+
def inspect = "#<#{self.class} #{symbology}#{' gs1' if gs1?} #{text.inspect}>"
|
|
71
|
+
|
|
72
|
+
private
|
|
73
|
+
|
|
74
|
+
def look(color, background, quiet_zone, bar_height)
|
|
75
|
+
[color.to_s, background&.to_s, quiet_zone ? true : false, bar_height && Integer(bar_height)]
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
data/lib/imprimatur/document.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Imprimatur
|
|
4
|
-
# A flowing document (headings, paragraphs, tables, pictures, page breaks)
|
|
4
|
+
# A flowing document (headings, paragraphs, tables, pictures, barcodes, page breaks)
|
|
5
5
|
# that renders to PDF and DOCX from the same content.
|
|
6
6
|
#
|
|
7
7
|
# doc = Imprimatur::Document.new(page_numbers: true)
|
|
@@ -49,6 +49,22 @@ module Imprimatur
|
|
|
49
49
|
self
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
+
# A barcode in the flow: vector shapes in a PDF, a 300 dpi picture in DOCX.
|
|
53
|
+
# Drawn at +width+ or +height+ points (a QR Code or Data Matrix keeps
|
|
54
|
+
# square modules; a linear code's height is its bars'), or else at its
|
|
55
|
+
# symbology's usual module size; never larger than the page leaves room for.
|
|
56
|
+
# Its quiet zone is part of its size.
|
|
57
|
+
#
|
|
58
|
+
# @param barcode [Barcode] from {Imprimatur.barcode}
|
|
59
|
+
# @param align [:left, :center, :right, nil]
|
|
60
|
+
# @param color [String, nil] the bars, "#RRGGBB"; black unless set
|
|
61
|
+
# @return [self]
|
|
62
|
+
# @raise [Imprimatur::Error] a size out of range, or an invalid color
|
|
63
|
+
def barcode(barcode, width: nil, height: nil, align: nil, color: nil)
|
|
64
|
+
@native.barcode(barcode, [width && Float(width), height && Float(height)], align&.to_s, color&.to_s)
|
|
65
|
+
self
|
|
66
|
+
end
|
|
67
|
+
|
|
52
68
|
# @param text [String]
|
|
53
69
|
# @param level [Integer] 1 (the title) to 3
|
|
54
70
|
# @return [self]
|
data/lib/imprimatur/version.rb
CHANGED
data/lib/imprimatur.rb
CHANGED
|
@@ -6,6 +6,7 @@ require_relative 'imprimatur/formula'
|
|
|
6
6
|
require_relative 'imprimatur/native'
|
|
7
7
|
require_relative 'imprimatur/style'
|
|
8
8
|
require_relative 'imprimatur/validation'
|
|
9
|
+
require_relative 'imprimatur/barcode'
|
|
9
10
|
require_relative 'imprimatur/xlsx'
|
|
10
11
|
require_relative 'imprimatur/document'
|
|
11
12
|
require_relative 'imprimatur/reader'
|
|
@@ -38,6 +39,9 @@ module Imprimatur
|
|
|
38
39
|
# @see Validation.build
|
|
39
40
|
def validation(**) = Validation.build(**)
|
|
40
41
|
|
|
42
|
+
# @see Barcode.encode
|
|
43
|
+
def barcode(symbology, data, **) = Barcode.encode(symbology, data, **)
|
|
44
|
+
|
|
41
45
|
# Builds a {Document} and renders it as PDF. With a path, saves it there
|
|
42
46
|
# and returns the path; without, returns the bytes.
|
|
43
47
|
#
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: imprimatur
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: aarch64-linux-gnu
|
|
6
6
|
authors:
|
|
7
7
|
- Abdelkader Boudih
|
|
@@ -24,6 +24,7 @@ files:
|
|
|
24
24
|
- README.md
|
|
25
25
|
- lib/imprimatur.rb
|
|
26
26
|
- lib/imprimatur/4.0/imprimatur_native.so
|
|
27
|
+
- lib/imprimatur/barcode.rb
|
|
27
28
|
- lib/imprimatur/document.rb
|
|
28
29
|
- lib/imprimatur/error.rb
|
|
29
30
|
- lib/imprimatur/formula.rb
|