1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! EAN/UPC (ISO/IEC 15420) encoder and structural decoder.
//!
//! Covers the whole retail linear family: EAN-13, EAN-8, UPC-A, UPC-E, and the
//! UPC/EAN 2- and 5-digit add-ons. Layout mirrors the QR module
//! ([`crate::codes::qr`]):
//! - `tables` — L/G/R element patterns, parity tables, guards, check digits and
//! the UPC-E ⟷ UPC-A expansion.
//! - `encode` — [`Symbol`] → [`LinearPattern`].
//! - `decode` — [`LinearPattern`] → [`Symbol`].
//!
//! ## Lossless representation
//!
//! The human-readable digits (including the check digit) live verbatim in a single
//! [`Segment::numeric`] on the [`Symbol`]. Everything else needed to reproduce the
//! exact module pattern lives in [`EanMeta`]:
//! - [`EanMeta::variant`] pins which member of the family the digits belong to. In
//! particular a scanned UPC-E keeps its compressed 8-digit form (number system +
//! six payload digits + check) so it re-encodes to the UPC-E pattern rather than
//! its expanded UPC-A equivalent.
//! - [`EanMeta::addon`] carries an optional 2- or 5-digit supplement attached to a
//! main symbol, so `main + add-on` round-trips as one [`LinearPattern`].
//!
//! Standalone add-ons are represented as their own [`Symbology::Ean2`] /
//! [`Symbology::Ean5`] symbols with the digits in the segment and `addon = None`.
//!
//! ## UPC-A vs. leading-zero EAN-13
//!
//! A UPC-A symbol is bit-for-bit identical to an EAN-13 whose leading digit is `0`.
//! The decoder resolves this unavoidable ambiguity by reporting a 95-module symbol
//! with an implied leading `0` as [`EanVariant::UpcA`] (12 digits) and any other
//! leading digit as [`EanVariant::Ean13`] (13 digits). Consequently an EAN-13 built
//! with an explicit leading `0` re-encodes to the identical pattern but is *labelled*
//! UPC-A after a decode round-trip; every other input is label-stable.
//!
//! [`Symbol`]: crate::Symbol
//! [`Segment::numeric`]: crate::Segment::numeric
//! [`LinearPattern`]: crate::output::LinearPattern
//! [`Symbology::Ean2`]: crate::Symbology::Ean2
//! [`Symbology::Ean5`]: crate::Symbology::Ean5
pub use EanDecoder;
pub use EanEncoder;
/// Which member of the EAN/UPC family a [`crate::Symbol`] represents.
/// Whether an add-on carries two or five digits.
/// A 2- or 5-digit supplemental add-on attached to a main EAN/UPC symbol.
/// EAN/UPC parameters needed to re-encode a symbol identically.