zxing-cpp v3.0
Loading...
Searching...
No Matches
Barcode.h
Go to the documentation of this file.
1/*
2* Copyright 2016 Nu-book Inc.
3* Copyright 2016 ZXing authors
4* Copyright 2020 Axel Waggershauser
5*/
6// SPDX-License-Identifier: Apache-2.0
7
8#pragma once
9
10#include "BarcodeFormat.h"
11#include "ContentType.h"
12#include "Error.h"
13#include "ImageView.h"
14#include "Quadrilateral.h"
15#include "ReaderOptions.h" // for TextMode
16#include "Version.h" // ZXING_... macros
17
18#include <memory>
19#include <string>
20#include <vector>
21
22#ifdef ZXING_USE_ZINT
23extern "C" struct zint_symbol;
24#endif
25
26namespace ZXing {
27
28class CreatorOptions;
29class ReaderOptions;
30class WriterOptions;
31class Barcode;
32struct BarcodeData;
33
35using Barcodes = std::vector<Barcode>;
36
40namespace BarcodeExtra {
41 #define ZX_EXTRA(NAME) static constexpr auto NAME = #NAME
42 ZX_EXTRA(DataMask);
43 ZX_EXTRA(Version);
44 ZX_EXTRA(EanAddOn);
45 ZX_EXTRA(ECLevel);
46 ZX_EXTRA(UPCE);
47 ZX_EXTRA(ReaderInit);
48 #undef ZX_EXTRA
49} // namespace BarcodeExtra
50
64{
65 using Data = BarcodeData;
66
67 std::shared_ptr<Data> d;
68
69 Barcode& setReaderOptions(const ReaderOptions& opts);
70
73 friend Barcode CreateBarcode(const void*, int, int, const CreatorOptions&);
75 friend std::string WriteBarcodeToSVG(const Barcode&, const WriterOptions&);
76
77public:
79 Barcode(Barcode::Data&& data);
80
82 bool isValid() const;
83
85 const Error& error() const;
86
89
91 BarcodeFormat symbology() const { return Symbology(format()); }
92
94 const std::vector<uint8_t>& bytes() const;
95
97 std::vector<uint8_t> bytesECI() const;
98
100 std::string text(TextMode mode) const;
101
103 std::string text() const;
104
106 ContentType contentType() const;
107
109 bool hasECI() const;
110
113 const Position& position() const;
114
116 int orientation() const;
117
119 bool isMirrored() const;
121 bool isInverted() const;
122
124 std::string symbologyIdentifier() const;
125
131 int sequenceSize() const;
132
134 int sequenceIndex() const;
135
141 std::string sequenceId() const;
142
144 bool isLastInSequence() const { return sequenceSize() == sequenceIndex() + 1; }
145
147 bool isPartOfSequence() const { return sequenceSize() > -1 && sequenceIndex() > -1; }
148
150 int lineCount() const;
151
154
161 std::string extra(std::string_view key = "") const;
162
165 // [[deprecated ("use extra(BarcodeExtra::ECLevel) instead")]]
166 std::string ecLevel() const { return extra(BarcodeExtra::ECLevel); }
167
169 // [[deprecated ("use extra(BarcodeExtra::ReaderInit) instead")]]
170 bool readerInit() const { return !extra(BarcodeExtra::ReaderInit).empty(); }
171
173 // [[deprecated ("use extra(BarcodeExtra::Version) instead")]]
174 std::string version() const { return extra(BarcodeExtra::Version); }
176
177#if defined(ZXING_USE_ZINT) && defined(ZXING_EXPERIMENTAL_API)
178 zint_symbol* zint() const;
179#endif
180
181 bool operator==(const Barcode& o) const;
182};
183
186
189
190} // ZXing
The Barcode class encapsulates a decoded or created barcode symbol.
Definition Barcode.h:64
friend Barcodes ReadBarcodes(const ImageView &, const ReaderOptions &)
int sequenceIndex() const
Returns the 0-based index of this symbol in a structured append sequence.
bool isPartOfSequence() const
Returns whether this symbol is part of a structured append sequence.
Definition Barcode.h:147
const Error & error() const
Returns the error associated with the barcode, if any.
bool isInverted() const
Returns whether the symbol is inverted / has reversed reflectance (see ReaderOptions::tryInvert).
friend std::string WriteBarcodeToSVG(const Barcode &, const WriterOptions &)
Write barcode symbol to SVG.
std::vector< uint8_t > bytesECI() const
Returns the raw / standard content following the ECI protocol.
friend Barcode CreateBarcode(const void *, int, int, const CreatorOptions &)
bool operator==(const Barcode &o) const
ImageView symbol() const
Returns the bit matrix of the symbol as an ImageView.
std::string extra(std::string_view key="") const
Retrieve supplementary metadata associated with this barcode.
int orientation() const
Returns the orientation of the barcode in degrees, see also Position::orientation().
std::string text(TextMode mode) const
Returns the bytes() content rendered to unicode/utf8 text according to specified TextMode.
friend Image WriteBarcodeToImage(const Barcode &, const WriterOptions &)
Write barcode symbol to Image (Bitmap).
const std::vector< uint8_t > & bytes() const
Returns the raw / standard content without any modifications like character set conversions.
std::string symbologyIdentifier() const
Returns the symbology identifier "]cm" where "c" is symbology code character, "m" the modifier.
bool isValid() const
Returns whether the barcode is valid, i.e. it contains a successfully decoded or created symbol.
int sequenceSize() const
Returns the number of symbols in a structured append sequence.
std::string sequenceId() const
Returns the sequenceId to check if a set of symbols belongs to the same structured append sequence.
Barcode(Barcode::Data &&data)
ContentType contentType() const
Returns the content type, giving a hint to the type of content found (Text/Binary/GS1/etc....
bool hasECI() const
Returns whether or not an ECI tag was found.
BarcodeFormat format() const
Returns the BarcodeFormat of the barcode.
bool isMirrored() const
Returns whether the symbol is mirrored (currently only supported by QRCode and DataMatrix).
BarcodeFormat symbology() const
Returns the symbology of the barcode format (e.g. EAN/UPC for EAN13, EAN8, UPCA, etc....
Definition Barcode.h:91
bool isLastInSequence() const
Returns whether this symbol is the last in a structured append sequence.
Definition Barcode.h:144
int lineCount() const
Returns how many lines have been detected with this code (applies only to linear symbologies).
const Position & position() const
friend Barcode MergeStructuredAppendSequence(const Barcodes &)
Merge a list of Barcodes from one Structured Append sequence to a single barcode.
std::string text() const
Returns the bytes() content rendered to unicode/utf8 text according to the TextMode set in the Reader...
Configuration options for barcode creation.
Definition CreateBarcode.h:38
The Error class is a value type for the error() member of Barcode.
Definition Error.h:27
Simple class that inherits ImageView but owns the image data and frees it on destruction.
Definition ImageView.h:164
Simple class that stores a non-owning const pointer to image data plus layout and format information.
Definition ImageView.h:53
Configuration options for barcode reading and decoding behavior.
Definition ReaderOptions.h:74
Configuration options for barcode writing/generation.
Definition WriteBarcode.h:27
String keys for the extra() metadata of Barcode. The values depend on the symbology and may not be pr...
Definition Barcode.h:40
static constexpr auto Version
QRCodes, DataMatrix, MaxiCode (e.g. "12x12" for DataMatrix).
Definition Barcode.h:43
static constexpr auto DataMask
QRCodes.
Definition Barcode.h:42
static constexpr auto ECLevel
Error correction level (e.g. "L", "M", "Q", "H" for QRCode).
Definition Barcode.h:45
static constexpr auto ReaderInit
Definition Barcode.h:47
static constexpr auto UPCE
The original (non-normalized) UPC-E code if UPC-E is detected.
Definition Barcode.h:46
static constexpr auto EanAddOn
The EAN/UPC add-on content if detected.
Definition Barcode.h:44
Definition Barcode.h:26
Barcodes MergeStructuredAppendSequences(const Barcodes &barcodes)
Automatically merge all Structured Append sequences found in the given list of barcodes.
TextMode
Specify how the decoded byte content of a barcode should be transcoded to text.
Definition ReaderOptions.h:46
BarcodeFormat Symbology(BarcodeFormat format)
Returns the symbology (base type) of the given barcode format (e.g. EAN/UPC for EAN13,...
Quadrilateral< PointI > QuadrilateralI
Definition Quadrilateral.h:61
Barcode MergeStructuredAppendSequence(const Barcodes &barcodes)
Merge a list of Barcodes from one Structured Append sequence to a single barcode.
std::vector< Barcode > Barcodes
Definition Barcode.h:35
QuadrilateralI Position
Definition Barcode.h:34
BarcodeFormat
Enumerates barcode formats known to this package.
Definition BarcodeFormat.h:98