Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nu-book/zxing-cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
markusfisch committed Jan 4, 2025
2 parents 62935c8 + 8f95431 commit 044a1ff
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let package = Package(
.target(
name: "ZXingCppCore",
path: "core/src",
exclude: ["libzint"],
exclude: ["libzint", "ZXingC.cpp", "ZXingCpp.cpp"],
publicHeadersPath: ".",
cxxSettings: [
.define("ZXING_READERS")
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Thanks a lot for your contribution!

[Note:]
* DataBar used to be called RSS.
* DataBar, DX Film Edge, MaxiCode, Micro QR Code and rMQR Code are not supported for writing.
* DataBar, DX Film Edge, MaxiCode, Micro QR Code and rMQR Code are not supported for writing (unless the library is configured `ZXING_WRITERS=NEW` and `ZING_EXPERIMENTAL_API=ON`).
* Building with only C++17 (see [CMakeLists.txt](https://github.com/zxing-cpp/zxing-cpp/blob/d4b0f502775857f257d13efd25fb840ece1bca3e/CMakeLists.txt#L45)) changes the behavior of the library: it then lacks support for DataBarLimited and multi-symbol and position independent detection for DataMatrix.

## Getting Started
Expand Down Expand Up @@ -86,7 +86,7 @@ To see the full capability of the API, have a look at [`ZXingReader.cpp`](exampl
2. Call `encode()` with text content and the image size. This returns a [`BitMatrix`](core/src/BitMatrix.h) which is a binary image of the barcode where `true` == visual black and `false` == visual white.
3. Convert the bit matrix to your native image format. See also the `ToMatrix<T>(BitMatrix&)` helper function.
As an example, have a look at [`ZXingWriter.cpp`](example/ZXingWriter.cpp).
As an example, have a look at [`ZXingWriter.cpp`](example/ZXingWriter.cpp). That file also contains example code showing the new `ZXING_EXPERIMENTAL_API` for writing barcodes.
## Web Demos
- [Read barcodes](https://zxing-cpp.github.io/zxing-cpp/demo_reader.html)
Expand Down
2 changes: 1 addition & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ if (ZXING_WRITERS_NEW)
target_include_directories (ZXing PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/libzint>")
else()
include(../zxing.cmake)
zxing_add_package(zint zint https://github.com/zint/zint.git 55a7369cd8c4a6b58bcd62f02a3a2d486952c897)
zxing_add_package(zint zint https://github.com/zint/zint.git 7a9fdd6cd00cd5bfd0082705d934c13ef84f25e1)
target_link_libraries (ZXing PRIVATE zint)
endif()
endif()
Expand Down
15 changes: 13 additions & 2 deletions core/src/ZXingC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@

#include "ZXingCpp.h"

#if __has_include("Version.h")
#include "Version.h"
#else // this is mainly a workaround for a missing autogenerated Version.h in the XCode/CocoaPods corner
#define ZXING_VERSION_STR "undefined"
#endif

#include <cstdlib>
#include <exception>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>

using namespace ZXing;
Expand Down Expand Up @@ -411,9 +416,15 @@ char* ZXing_LastErrorMsg()
return copy(std::exchange(lastErrorMsg, {}));
}

const char* ZXing_Version()
{
return ZXING_VERSION_STR;
}

void ZXing_free(void* ptr)
{
free(ptr);
if (ptr != ZXing_Version())
free(ptr);
}

} // extern "C"
2 changes: 2 additions & 0 deletions core/src/ZXingC.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ ZXing_Image* ZXing_WriteBarcodeToImage(const ZXing_Barcode* barcode, const ZXing
/* ZXing_LastErrorMsg() returns NULL in case there is no last error and a copy of the string otherwise. */
char* ZXing_LastErrorMsg();

const char* ZXing_Version();

void ZXing_free(void* ptr);

#ifdef __cplusplus
Expand Down
20 changes: 16 additions & 4 deletions core/src/ZXingCpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
*/
// SPDX-License-Identifier: Apache-2.0

#ifdef ZXING_EXPERIMENTAL_API

#include "ZXingCpp.h"

#if __has_include("Version.h")
#include "Version.h"
#else // this is mainly a workaround for a missing autogenerated Version.h in the XCode/CocoaPods corner
#define ZXING_VERSION_STR "undefined"
#endif

namespace ZXing {

const std::string& Version()
{
static std::string res = ZXING_VERSION_STR;
return res;
}

#ifdef ZXING_EXPERIMENTAL_API

BarcodeFormats SupportedBarcodeFormats(Operation op)
{
switch (op) {
Expand All @@ -31,6 +43,6 @@ BarcodeFormats SupportedBarcodeFormats(Operation op)
return {}; // unreachable code
}

} // namespace ZXing

#endif // ZXING_EXPERIMENTAL_API

} // namespace ZXing
10 changes: 6 additions & 4 deletions core/src/ZXingCpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#include "ReadBarcode.h"
#include "WriteBarcode.h"

#ifdef ZXING_EXPERIMENTAL_API

namespace ZXing {

const std::string& Version();

#ifdef ZXING_EXPERIMENTAL_API

enum class Operation
{
Create,
Expand All @@ -23,6 +25,6 @@ enum class Operation

BarcodeFormats SupportedBarcodeFormats(Operation op = Operation::CreateOrRead);

} // namespace ZXing

#endif // ZXING_EXPERIMENTAL_API

} // namespace ZXing
4 changes: 2 additions & 2 deletions wrappers/c/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# C bindings for zxing-cpp

This is a preview/proposal for a C-API to zxing-cpp. If you have any comments or feedback, please have a look at https://github.com/zxing-cpp/zxing-cpp/discussions/583.
This is about the C-API of zxing-cpp. If you have any comments or feedback, please have a look at https://github.com/zxing-cpp/zxing-cpp/discussions/583.

## Installation

It is currently included in the default build to be trivially accessible for everyone.
To enable the C-API, the library needs to be configured with `cmake -DZING_C_API=ON`.

Probably the easiest way to play with the C-API is to just modify the [ZXingCTest.c](https://github.com/zxing-cpp/zxing-cpp/blob/master/wrappers/c/ZXingCTest.c) file.

Expand Down
2 changes: 1 addition & 1 deletion wrappers/c/ZXingCTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

int usage(char* pname)
{
fprintf(stderr, "Usage: %s FILE [FORMATS]\n", pname);
fprintf(stderr, "ZXingCTest %s, usage: %s FILE [FORMATS]\n", ZXing_Version(), pname);
return 1;
}

Expand Down
4 changes: 1 addition & 3 deletions wrappers/winrt/nuget/ZXingWinRT.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
</metadata>
<files>
<file src="..\UAP\v0.8.0.0\ExtensionSDKs\ZXingWinRT\1.0.0.0\References\CommonConfiguration\Neutral\ZXing.winmd" target="lib\uap10.0"/>
<file src="..\UAP\v0.8.0.0\ExtensionSDKs\ZXingWinRT\1.0.0.0\References\CommonConfiguration\Neutral\ZXing.pri" target="runtimes\win10-arm\native"/>
<file src="..\UAP\v0.8.0.0\ExtensionSDKs\ZXingWinRT\1.0.0.0\Redist\Retail\ARM\ZXing.dll" target="runtimes\win10-arm\native"/>
<file src="..\UAP\v0.8.0.0\ExtensionSDKs\ZXingWinRT\1.0.0.0\References\CommonConfiguration\Neutral\ZXing.pri" target="runtimes\win10-arm64\native"/>
<file src="..\UAP\v0.8.0.0\ExtensionSDKs\ZXingWinRT\1.0.0.0\Redist\Retail\ARM64\ZXing.dll" target="runtimes\win10-arm64\native"/>
<file src="..\UAP\v0.8.0.0\ExtensionSDKs\ZXingWinRT\1.0.0.0\References\CommonConfiguration\Neutral\ZXing.pri" target="runtimes\win10-x64\native"/>
Expand All @@ -26,4 +24,4 @@
<file src="..\UAP\v0.8.0.0\ExtensionSDKs\ZXingWinRT\1.0.0.0\Redist\Retail\x86\ZXing.dll" target="runtimes\win10-x86\native"/>
<file src="ZXingWinRT.targets" target="build\native"/>
</files>
</package>
</package>

0 comments on commit 044a1ff

Please sign in to comment.