Mercurial > hgrepos > Python2 > PyMuPDF
diff mupdf-source/thirdparty/zxing-cpp/core/src/WriteBarcode.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mupdf-source/thirdparty/zxing-cpp/core/src/WriteBarcode.h Mon Sep 15 11:43:07 2025 +0200 @@ -0,0 +1,144 @@ +/* +* Copyright 2022 Axel Waggershauser +*/ +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ZXING_EXPERIMENTAL_API + +#include "Barcode.h" +#include "ImageView.h" + +#include <memory> +#include <string_view> + +extern "C" struct zint_symbol; + +namespace ZXing { + +class CreatorOptions +{ + struct Data; + + std::unique_ptr<Data> d; + + friend Barcode CreateBarcode(const void* data, int size, int mode, const CreatorOptions& options); + +public: + CreatorOptions(BarcodeFormat format); + + ~CreatorOptions(); + CreatorOptions(CreatorOptions&&); + CreatorOptions& operator=(CreatorOptions&&); + + zint_symbol* zint() const; + +#define ZX_PROPERTY(TYPE, NAME) \ + TYPE NAME() const noexcept; \ + CreatorOptions& NAME(TYPE v)&; \ + CreatorOptions&& NAME(TYPE v)&&; + + ZX_PROPERTY(BarcodeFormat, format) + ZX_PROPERTY(bool, readerInit) + ZX_PROPERTY(bool, forceSquareDataMatrix) + ZX_PROPERTY(std::string, ecLevel) + +#undef ZX_PROPERTY +}; + +/** + * Generate barcode from unicode text + * + * @param contents UTF-8 string to encode into a barcode + * @param options CreatorOptions (including BarcodeFormat) + * @return #Barcode generated barcode + */ +Barcode CreateBarcodeFromText(std::string_view contents, const CreatorOptions& options); + +/** + * Generate barcode from raw binary data + * + * @param data array of bytes to encode into a barcode + * @param size size of byte array + * @param options CreatorOptions (including BarcodeFormat) + * @return #Barcode generated barcode + */ +Barcode CreateBarcodeFromBytes(const void* data, int size, const CreatorOptions& options); + +#if __cplusplus > 201703L +Barcode CreateBarcodeFromText(std::u8string_view contents, const CreatorOptions& options); + +template <typename R> +requires std::ranges::contiguous_range<R> && std::ranges::sized_range<R> && (sizeof(std::ranges::range_value_t<R>) == 1) +Barcode CreateBarcodeFromBytes(const R& contents, const CreatorOptions& options) +{ + return CreateBarcodeFromBytes(std::ranges::data(contents), std::ranges::size(contents), options); +} +#else +template <typename R> +Barcode CreateBarcodeFromBytes(const R& contents, const CreatorOptions& options) +{ + return CreateBarcodeFromBytes(std::data(contents), std::size(contents), options); +} +#endif + +// ================================================================================= + +class WriterOptions +{ + struct Data; + + std::unique_ptr<Data> d; + +public: + WriterOptions(); + ~WriterOptions(); + WriterOptions(WriterOptions&&); + WriterOptions& operator=(WriterOptions&&); + +#define ZX_PROPERTY(TYPE, NAME) \ + TYPE NAME() const noexcept; \ + WriterOptions& NAME(TYPE v)&; \ + WriterOptions&& NAME(TYPE v)&&; + + ZX_PROPERTY(int, scale) + ZX_PROPERTY(int, sizeHint) + ZX_PROPERTY(int, rotate) + ZX_PROPERTY(bool, withHRT) + ZX_PROPERTY(bool, withQuietZones) + +#undef ZX_PROPERTY +}; + + +/** + * Write barcode symbol to SVG + * + * @param barcode Barcode to write + * @param options WriterOptions to parameterize rendering + * @return std::string SVG representation of barcode symbol + */ +std::string WriteBarcodeToSVG(const Barcode& barcode, const WriterOptions& options = {}); + +/** + * Write barcode symbol to a utf8 string using graphical characters (e.g. '▀') + * + * @param barcode Barcode to write + * @param options WriterOptions to parameterize rendering + * @return std::string Utf8 string representation of barcode symbol + */ +std::string WriteBarcodeToUtf8(const Barcode& barcode, const WriterOptions& options = {}); + +/** + * Write barcode symbol to Image (Bitmap) + * + * @param barcode Barcode to write + * @param options WriterOptions to parameterize rendering + * @return Image Bitmap reprentation of barcode symbol + */ +Image WriteBarcodeToImage(const Barcode& barcode, const WriterOptions& options = {}); + +} // ZXing + +#endif // ZXING_EXPERIMENTAL_API
