Initial implementation of Zint barcode backend.

This commit is contained in:
Jim Evins
2017-06-02 22:39:44 -04:00
parent cb9013cdd5
commit 3e2b40c000
8 changed files with 325 additions and 38 deletions
+7 -1
View File
@@ -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})
+32
View File
@@ -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)
+13
View File
@@ -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
}
+1
View File
@@ -4,6 +4,7 @@
set (barcode_sources
GnuBarcode.cpp
QrEncode.cpp
Zint.cpp
)
add_library (Barcode STATIC
+147
View File
@@ -0,0 +1,147 @@
/* Zint.cpp
*
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#if HAVE_GNU_BARCODE
#include "Zint.h"
#include <QtDebug>
#include <zint.h>
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
+74
View File
@@ -0,0 +1,74 @@
/* Zint.h
*
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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
+9
View File
@@ -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 (
+42 -37
View File
@@ -744,175 +744,180 @@
<context>
<name>glabels::BarcodeBackends</name>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="55"/>
<location filename="../glabels/BarcodeBackends.cpp" line="56"/>
<source>POSTNET (any)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="58"/>
<location filename="../glabels/BarcodeBackends.cpp" line="59"/>
<source>POSTNET-5 (ZIP only)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="61"/>
<location filename="../glabels/BarcodeBackends.cpp" line="62"/>
<source>POSTNET-9 (ZIP+4)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="64"/>
<location filename="../glabels/BarcodeBackends.cpp" line="65"/>
<source>POSTNET-11 (DPBC)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="67"/>
<location filename="../glabels/BarcodeBackends.cpp" line="68"/>
<source>CEPNET</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="70"/>
<location filename="../glabels/BarcodeBackends.cpp" line="71"/>
<source>USPS Intelligent Mail</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="73"/>
<location filename="../glabels/BarcodeBackends.cpp" line="74"/>
<source>IEC16022 (DataMatrix)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="108"/>
<location filename="../glabels/BarcodeBackends.cpp" line="109"/>
<source>EAN (any)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="110"/>
<location filename="../glabels/BarcodeBackends.cpp" line="111"/>
<source>EAN-8</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="112"/>
<location filename="../glabels/BarcodeBackends.cpp" line="113"/>
<source>EAN-8+2</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="114"/>
<location filename="../glabels/BarcodeBackends.cpp" line="115"/>
<source>EAN-8+5</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="118"/>
<location filename="../glabels/BarcodeBackends.cpp" line="119"/>
<source>EAN-13+2</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="120"/>
<location filename="../glabels/BarcodeBackends.cpp" line="121"/>
<source>EAN-13+5</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="122"/>
<location filename="../glabels/BarcodeBackends.cpp" line="123"/>
<source>UPC (UPC-A or UPC-E)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="126"/>
<location filename="../glabels/BarcodeBackends.cpp" line="127"/>
<source>UPC-A +2</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="128"/>
<location filename="../glabels/BarcodeBackends.cpp" line="129"/>
<source>UPC-A +5</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="130"/>
<location filename="../glabels/BarcodeBackends.cpp" line="131"/>
<source>UPC-E</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="132"/>
<location filename="../glabels/BarcodeBackends.cpp" line="133"/>
<source>UPC-E +2</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="134"/>
<location filename="../glabels/BarcodeBackends.cpp" line="135"/>
<source>UPC-E +5</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="136"/>
<location filename="../glabels/BarcodeBackends.cpp" line="137"/>
<source>ISBN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="138"/>
<location filename="../glabels/BarcodeBackends.cpp" line="139"/>
<source>ISBN +5</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="142"/>
<location filename="../glabels/BarcodeBackends.cpp" line="143"/>
<source>Code 128</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="144"/>
<location filename="../glabels/BarcodeBackends.cpp" line="145"/>
<source>Code 128C</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="146"/>
<location filename="../glabels/BarcodeBackends.cpp" line="147"/>
<source>Code 128B</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="148"/>
<location filename="../glabels/BarcodeBackends.cpp" line="149"/>
<source>Interleaved 2 of 5</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="150"/>
<location filename="../glabels/BarcodeBackends.cpp" line="151"/>
<source>Codabar</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="152"/>
<location filename="../glabels/BarcodeBackends.cpp" line="153"/>
<source>MSI</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="154"/>
<location filename="../glabels/BarcodeBackends.cpp" line="155"/>
<source>Plessey</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="156"/>
<location filename="../glabels/BarcodeBackends.cpp" line="157"/>
<source>Code 93</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="168"/>
<location filename="../glabels/BarcodeBackends.cpp" line="169"/>
<source>IEC18004 (QRCode)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="43"/>
<location filename="../glabels/BarcodeBackends.cpp" line="140"/>
<location filename="../glabels/BarcodeBackends.cpp" line="181"/>
<source>Austraila Post Standard</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="44"/>
<location filename="../glabels/BarcodeBackends.cpp" line="141"/>
<source>Code 39</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="46"/>
<location filename="../glabels/BarcodeBackends.cpp" line="47"/>
<source>Code 39 Extended</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="49"/>
<location filename="../glabels/BarcodeBackends.cpp" line="124"/>
<location filename="../glabels/BarcodeBackends.cpp" line="50"/>
<location filename="../glabels/BarcodeBackends.cpp" line="125"/>
<source>UPC-A</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../glabels/BarcodeBackends.cpp" line="52"/>
<location filename="../glabels/BarcodeBackends.cpp" line="116"/>
<location filename="../glabels/BarcodeBackends.cpp" line="53"/>
<location filename="../glabels/BarcodeBackends.cpp" line="117"/>
<source>EAN-13</source>
<translation type="unfinished"></translation>
</message>