diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e4399c..dcf67e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,7 @@ find_package(ZLIB 1.2 REQUIRED) # find_package (GnuBarcode QUIET) find_package (LibQrencode QUIET) - +find_package (LibZint QUIET) #======================================= # Subdirectories @@ -90,6 +90,12 @@ else (LIBQRENCODE_FOUND) message (STATUS "qrencode (optional)...... No.") endif (LIBQRENCODE_FOUND) +if (LIBZINT_FOUND) + message (STATUS "libzint (optional)....... " ${LIBZINT_VERSION_STRING}) +else (LIBZINT_FOUND) + message (STATUS "libzint (optional)....... No.") +endif (LIBZINT_FOUND) + if (MINGW) message (STATUS "MinGW location .......... " ${MINGW_BASE_DIR}) message (STATUS "MinGW Qt location ....... " ${QT_BASE_DIR}) diff --git a/cmake/Modules/FindLibZint.cmake b/cmake/Modules/FindLibZint.cmake new file mode 100644 index 0000000..83bdb6b --- /dev/null +++ b/cmake/Modules/FindLibZint.cmake @@ -0,0 +1,32 @@ +# - Try to find the Zint barcode library +# Once done this will define +# +# LIBZINT_FOUND - System has Zint barcode +# LIBZINT_INCLUDE_DIR - The Zint barcode include directory +# LIBZINT_LIBRARIES - The libraries needed to use Zint barcode +# LIBZINT_VERSION_STRING - the version of Zint barcode found + +set (LIBZINT_DEFINITIONS "") + +find_path (LIBZINT_INCLUDE_DIR NAMES zint.h) + +find_library (LIBZINT_LIBRARIES NAMES zint ) + +if (LIBZINT_INCLUDE_DIR AND EXISTS "${LIBZINT_INCLUDE_DIR}/zint.h") + file (STRINGS "${LIBZINT_INCLUDE_DIR}/zint.h" ZINT_MAJOR_H REGEX "^#define ZINT_VERSION_MAJOR *[0-9]*") + file (STRINGS "${LIBZINT_INCLUDE_DIR}/zint.h" ZINT_MINOR_H REGEX "^#define ZINT_VERSION_MINOR *[0-9]*") + file (STRINGS "${LIBZINT_INCLUDE_DIR}/zint.h" ZINT_MICRO_H REGEX "^#define ZINT_VERSION_RELEASE *[0-9]*") + string (REGEX REPLACE "^.*VERSION_MAJOR *([0-9]*)" "\\1" ZINT_MAJOR ${ZINT_MAJOR_H}) + string (REGEX REPLACE "^.*VERSION_MINOR *([0-9]*)" "\\1" ZINT_MINOR ${ZINT_MINOR_H}) + string (REGEX REPLACE "^.*VERSION_RELEASE *([0-9]*)" "\\1" ZINT_MICRO ${ZINT_MICRO_H}) + set (LIBZINT_VERSION_STRING ${ZINT_MAJOR}.${ZINT_MINOR}.${ZINT_MICRO}) +endif() + +# handle the QUIETLY and REQUIRED arguments and set LIBZINT_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibZint + REQUIRED_VARS LIBZINT_LIBRARIES LIBZINT_INCLUDE_DIR + VERSION_VAR LIBZINT_VERSION_STRING) + +mark_as_advanced(LIBZINT_INCLUDE_DIR LIBZINT_LIBRARIES) diff --git a/glabels/BarcodeBackends.cpp b/glabels/BarcodeBackends.cpp index 7c615c0..e08251c 100644 --- a/glabels/BarcodeBackends.cpp +++ b/glabels/BarcodeBackends.cpp @@ -24,6 +24,7 @@ #include "BarcodeBackends/GnuBarcode.h" #include "BarcodeBackends/QrEncode.h" +#include "BarcodeBackends/Zint.h" namespace glabels @@ -169,6 +170,18 @@ namespace glabels false, false, true, false, "1234567890AB", false, 12 ); #endif // HAVE_QRENCODE +#if HAVE_ZINT + // + // Zint barcode backend + // + registerBackend( "zint", "Zint" ); + + glbarcode::Factory::registerType( "zint::ausp", Zint::AusP::create ); + + registerStyle( "ausp", "zint", tr("Austraila Post Standard"), + false, false, true, false, "12345678901234567890123", true, 23 ); +#endif // HAVE_ZINT + } diff --git a/glabels/BarcodeBackends/CMakeLists.txt b/glabels/BarcodeBackends/CMakeLists.txt index fe87034..16b8ccb 100644 --- a/glabels/BarcodeBackends/CMakeLists.txt +++ b/glabels/BarcodeBackends/CMakeLists.txt @@ -4,6 +4,7 @@ set (barcode_sources GnuBarcode.cpp QrEncode.cpp + Zint.cpp ) add_library (Barcode STATIC diff --git a/glabels/BarcodeBackends/Zint.cpp b/glabels/BarcodeBackends/Zint.cpp new file mode 100644 index 0000000..0a2af00 --- /dev/null +++ b/glabels/BarcodeBackends/Zint.cpp @@ -0,0 +1,147 @@ +/* Zint.cpp + * + * Copyright (C) 2017 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#if HAVE_GNU_BARCODE + +#include "Zint.h" + +#include +#include + + +namespace +{ + const int W_PTS_DEFAULT = 144; + const int H_PTS_DEFAULT = 72; +} + + +namespace glabels +{ + namespace Zint + { + + + // + // Zint barcode data validation method + // + bool Base::validate( const std::string& rawData ) + { + return rawData.size() != 0; + } + + + // + // Zint barcode data vectorization method + // + void Base::vectorize( const std::string& encodedData, + const std::string& displayText, + const std::string& cookedData, + double& w, + double& h ) + { + /* + * First encode using Zint barcode library. + */ + if ( w == 0 ) + { + w = W_PTS_DEFAULT; + } + if ( h == 0 ) + { + h = H_PTS_DEFAULT; + } + + zint_symbol* symbol = ZBarcode_Create();; + + symbol->symbology = symbology; + + if ( ZBarcode_Encode( symbol, (unsigned char*)(cookedData.c_str()), 0 ) != 0 ) + { + qDebug() << "Zint::ZBarcode_Encode: " << QString(symbol->errtxt); + setIsDataValid( false ); + return; + } + + symbol->show_hrt = showText(); + + if ( ZBarcode_Render( symbol, (float)w, (float)h ) == 0 ) + { + qDebug() << "Zint::ZBarcode_Render: " << QString(symbol->errtxt); + setIsDataValid( false ); + return; + } + + + /* + * Now do the actual vectorization. + */ + zint_render *render = symbol->rendered; + + setWidth( render->width ); + setHeight( render->height ); + + for ( zint_render_line *zline = render->lines; zline != nullptr; zline = zline->next ) + { + addBox( zline->x, zline->y, zline->width, zline->length ); + } + + for ( zint_render_ring *zring = render->rings; zring != nullptr; zring = zring->next ) + { + addRing( zring->x, zring->y, zring->radius, zring->line_width ); + } + + for ( zint_render_hexagon *zhexagon = render->hexagons; zhexagon != nullptr; zhexagon = zhexagon->next ) + { + addHexagon( zhexagon->x, zhexagon->y, 2.89 ); + } + + if( showText() ) + { + for ( zint_render_string *zstring = render->strings; zstring != nullptr; zstring = zstring->next ) + { + addText( zstring->x, zstring->y, zstring->fsize, QString((char*)(zstring->text)).toStdString() ); + } + } + + ZBarcode_Delete( symbol ); + } + + + ////////////////////////////////////////////////////// + // AusP Barcode + ////////////////////////////////////////////////////// + glbarcode::Barcode* AusP::create() + { + return new AusP(); + } + + + std::string AusP::encode( const std::string& cookedData ) + { + symbology = BARCODE_AUSPOST; + return ""; // Actual encoding is done in vectorize + } + + + } +} + +#endif // HAVE_GNU_BARCODE diff --git a/glabels/BarcodeBackends/Zint.h b/glabels/BarcodeBackends/Zint.h new file mode 100644 index 0000000..913e9ea --- /dev/null +++ b/glabels/BarcodeBackends/Zint.h @@ -0,0 +1,74 @@ +/* Zint.h + * + * Copyright (C) 2017 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#ifndef barcode_Zint_h +#define barcode_Zint_h + +#if HAVE_ZINT + +#include "glbarcode/Barcode1dBase.h" + + +namespace glabels +{ + namespace Zint + { + + /** + * Zint::Base base class for all Zint barcodes + * + * Implements glbarcode::Barcode1dBase. + */ + class Base : public glbarcode::Barcode1dBase + { + protected: + int symbology; + + + bool validate( const std::string& rawData ) override; + + void vectorize( const std::string& encodedData, + const std::string& displayText, + const std::string& cookedData, + double& w, + double& h ) override; + }; + + + /** + * AusP Barcode + */ + class AusP : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + + } +} + + +#endif // HAVE_ZINT + +#endif // barcode_Zint_h diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index 1fff271..200390e 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -26,6 +26,13 @@ else (${LIBQRENCODE_FOUND}) set (LIBQRENCODE_LIBRARIES "") endif (${LIBQRENCODE_FOUND}) +if (${LIBZINT_FOUND}) + add_definitions (-DHAVE_ZINT=1) +else (${LIBZINT_FOUND}) + set (LIBZINT_INCLUDE_DIR "") + set (LIBZINT_LIBRARIES "") +endif (${LIBZINT_FOUND}) + #======================================= # Auto-generate Version.h @@ -202,6 +209,7 @@ target_link_libraries (glabels-qt ${ZLIB_LIBRARIES} ${GNUBARCODE_LIBRARIES} ${LIBQRENCODE_LIBRARIES} + ${LIBZINT_LIBRARIES} ) @@ -217,6 +225,7 @@ include_directories ( ${Qt5Svg_INCLUDE_DIRS} ${GNUBARCODE_INCLUDE_DIR} ${LIBQRENCODE_INCLUDE_DIR} + ${LIBZINT_INCLUDE_DIR} ) link_directories ( diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 2f04cd6..6528167 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -744,175 +744,180 @@ glabels::BarcodeBackends - + POSTNET (any) - + POSTNET-5 (ZIP only) - + POSTNET-9 (ZIP+4) - + POSTNET-11 (DPBC) - + CEPNET - + USPS Intelligent Mail - + IEC16022 (DataMatrix) - + EAN (any) - + EAN-8 - + EAN-8+2 - + EAN-8+5 - + EAN-13+2 - + EAN-13+5 - + UPC (UPC-A or UPC-E) - + UPC-A +2 - + UPC-A +5 - + UPC-E - + UPC-E +2 - + UPC-E +5 - + ISBN - + ISBN +5 - + Code 128 - + Code 128C - + Code 128B - + Interleaved 2 of 5 - + Codabar - + MSI - + Plessey - + Code 93 - + IEC18004 (QRCode) - - + + Austraila Post Standard + + + + + Code 39 - + Code 39 Extended - - + + UPC-A - - + + EAN-13