zxing-cpp v3.0
Loading...
Searching...
No Matches
CreateBarcode.h
Go to the documentation of this file.
1/*
2* Copyright 2024 Axel Waggershauser
3*/
4// SPDX-License-Identifier: Apache-2.0
5
6#pragma once
7
8#include "Barcode.h"
9
10#include <memory>
11#include <optional>
12#include <string_view>
13
14extern "C" struct zint_symbol;
15
16namespace ZXing {
17
38{
39 struct Data;
40
41 std::unique_ptr<Data> d;
42
43 friend Barcode CreateBarcode(const void* data, int size, int mode, const CreatorOptions& options);
44
45public:
49 CreatorOptions& operator=(CreatorOptions&&) noexcept;
50
51 zint_symbol* zint() const;
52
53#define ZX_PROPERTY(TYPE, NAME) \
54 const TYPE& NAME() const noexcept; \
55 CreatorOptions& NAME(TYPE v)&; \
56 CreatorOptions&& NAME(TYPE v)&&;
57
58 ZX_PROPERTY(BarcodeFormat, format)
59 ZX_PROPERTY(std::string, options)
60
61#undef ZX_PROPERTY
62
63#define ZX_RO_PROPERTY(TYPE, NAME) \
64 std::optional<TYPE> NAME() const noexcept;
65
67 ZX_RO_PROPERTY(std::string, ecLevel);
68
70 ZX_RO_PROPERTY(std::string, eci);
71
73 ZX_RO_PROPERTY(bool, gs1);
74
76 ZX_RO_PROPERTY(bool, readerInit);
77
79 ZX_RO_PROPERTY(bool, forceSquare);
80
82 ZX_RO_PROPERTY(int, columns);
83
85 ZX_RO_PROPERTY(int, rows);
86
88 ZX_RO_PROPERTY(int, version);
89
91 ZX_RO_PROPERTY(int, dataMask);
92
93#undef ZX_RO_PROPERTY
94};
95
102Barcode CreateBarcodeFromText(std::string_view contents, const CreatorOptions& options);
103
111Barcode CreateBarcodeFromBytes(const void* data, int size, const CreatorOptions& options);
112
113#if defined(__cpp_lib_char8_t)
114Barcode CreateBarcodeFromText(std::u8string_view contents, const CreatorOptions& options);
115#endif
116
117#if defined(__cpp_lib_ranges)
118template <typename R>
119requires std::ranges::contiguous_range<R> && std::ranges::sized_range<R> && (sizeof(std::ranges::range_value_t<R>) == 1)
120Barcode CreateBarcodeFromBytes(const R& contents, const CreatorOptions& options)
121{
122 return CreateBarcodeFromBytes(std::ranges::data(contents), std::ranges::size(contents), options);
123}
124#else
125template <typename R>
126Barcode CreateBarcodeFromBytes(const R& contents, const CreatorOptions& options)
127{
128 return CreateBarcodeFromBytes(std::data(contents), std::size(contents), options);
129}
130#endif
131
132} // ZXing
The Barcode class encapsulates a decoded or created barcode symbol.
Definition Barcode.h:64
Configuration options for barcode creation.
Definition CreateBarcode.h:38
friend Barcode CreateBarcode(const void *data, int size, int mode, const CreatorOptions &options)
std::optional< bool > readerInit() const noexcept
most 2D symbologies: set the "reader init" flag
std::optional< std::string > ecLevel() const noexcept
most 2D symbologies: ecLevel, e.g. "30%", see also libzint docs for supported values per symbology
std::optional< bool > forceSquare() const noexcept
DataMatrix: only consider square symbol versions.
zint_symbol * zint() const
std::optional< int > version() const noexcept
most 2D symbologies: specify the version/size of the symbol
std::optional< int > rows() const noexcept
specify number of rows (e.g. for DataBarExpStk, PDF417)
std::optional< std::string > eci() const noexcept
most 2D symbologies: specify ECI designator to use (e.g. "UTF-8" or "26" for UTF-8),...
const BarcodeFormat & format() const noexcept
const std::string & options() const noexcept
std::optional< int > columns() const noexcept
specify number of columns (e.g. for DataBarExpStk, PDF417)
std::optional< int > dataMask() const noexcept
QRCode/MicroQRCode: specify dataMask to use.
CreatorOptions(CreatorOptions &&) noexcept
std::optional< bool > gs1() const noexcept
GS1 mode.
CreatorOptions(BarcodeFormat format, std::string options={})
Definition Barcode.h:26
Barcode CreateBarcodeFromText(std::string_view contents, const CreatorOptions &options)
Generate Barcode from unicode text.
BarcodeFormat
Enumerates barcode formats known to this package.
Definition BarcodeFormat.h:98
Barcode CreateBarcodeFromBytes(const void *data, int size, const CreatorOptions &options)
Generate Barcode from raw binary data.