Support libzint >= 2.15 (#225,#222,#186))

- Update libzint support for 2.15 as new baseline version, removing support for earlier versions, avoiding '#ifdef'-hell
- Based on #186

---------

Co-authored-by: gitlost <burmartke@gmail.com>
This commit is contained in:
Jaye Evins
2025-08-16 17:00:14 -04:00
committed by GitHub
parent fa96cc5a17
commit 0e7049ed73
19 changed files with 957 additions and 162 deletions
+387 -28
View File
@@ -31,6 +31,7 @@ namespace
const double FONT_SCALE = 0.9;
const int W_PTS_DEFAULT = 144;
const int H_PTS_DEFAULT = 72;
const double TWO_DIVIDED_BY_SQRT3 = 1.15470053837925152902;
}
@@ -42,6 +43,14 @@ namespace glabels
{
//
// Base constructor
//
Base::Base() : symbology(0), option_2(0)
{
}
//
// Zint barcode data validation method
//
@@ -63,31 +72,24 @@ namespace glabels
/*
* 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();;
zint_symbol* symbol = ZBarcode_Create();
symbol->symbology = symbology;
symbol->input_mode = UNICODE_MODE;
symbol->scale = 0.5f; // Pixels
symbol->option_2 = option_2; // Currently just check digit
symbol->show_hrt = showText();
if ( ZBarcode_Encode( symbol, (unsigned char*)(cookedData.c_str()), 0 ) != 0 )
if ( ZBarcode_Encode( symbol, (unsigned char*)(cookedData.c_str()), 0 ) >= 5 /*ZINT_ERROR*/ )
{
qDebug() << "Zint::ZBarcode_Encode: " << QString(symbol->errtxt);
setIsDataValid( false );
return;
}
symbol->show_hrt = showText();
if ( ZBarcode_Render( symbol, (float)w, (float)h ) == 0 )
if ( ZBarcode_Buffer_Vector( symbol, 0 ) >= 5 /*ZINT_ERROR*/ )
{
qDebug() << "Zint::ZBarcode_Render: " << QString(symbol->errtxt);
qDebug() << "Zint::ZBarcode_Buffer_Vector: " << QString(symbol->errtxt);
setIsDataValid( false );
return;
}
@@ -96,32 +98,73 @@ namespace glabels
/*
* Now do the actual vectorization.
*/
zint_render *render = symbol->rendered;
zint_vector *vector = symbol->vector;
setWidth( render->width );
setHeight( render->height );
w = std::max( w, 5.0 ); // TODO: proper minimum
h = std::max( h, 5.0 ); // TODO: proper minimum
for ( zint_render_line *zline = render->lines; zline != nullptr; zline = zline->next )
if ( ZBarcode_Cap( symbol->symbology, ZINT_CAP_FIXED_RATIO ) & ZINT_CAP_FIXED_RATIO )
{
addBox( zline->x, zline->y, zline->width, zline->length );
if ( vector->width == vector->height )
{
w = h = std::min(w, h);
}
else
{
// Keep aspect ratio
if ( h < w )
{
w = h * vector->width / vector->height;
}
else
{
h = w * vector->height / vector->width;
}
}
}
for ( zint_render_ring *zring = render->rings; zring != nullptr; zring = zring->next )
double xscale = w / vector->width;
double yscale = h / vector->height;
setWidth( vector->width*xscale );
setHeight( vector->height*yscale );
for ( zint_vector_rect *zrect = vector->rectangles; zrect != nullptr; zrect = zrect->next )
{
addRing( zring->x, zring->y, zring->radius, zring->line_width );
addBox( zrect->x*xscale,
zrect->y*yscale,
zrect->width*xscale,
zrect->height*yscale );
}
for ( zint_render_hexagon *zhexagon = render->hexagons; zhexagon != nullptr; zhexagon = zhexagon->next )
for ( zint_vector_circle *zcircle = vector->circles; zcircle != nullptr; zcircle = zcircle->next )
{
addHexagon( zhexagon->x, zhexagon->y, 2.89 );
double line_width = zcircle->width*xscale;
addRing( zcircle->x*xscale,
zcircle->y*yscale,
zcircle->diameter*xscale/2,
line_width );
}
for ( zint_vector_hexagon *zhexagon = vector->hexagons; zhexagon != nullptr; zhexagon = zhexagon->next )
{
// Convert from Zint's horizontal short diameter (X) to vertical long diameter (V).
double h = TWO_DIVIDED_BY_SQRT3*zhexagon->diameter*yscale;
addHexagon( zhexagon->x*xscale, // Center x same as apex x
zhexagon->y*yscale - h/2, // Subtract radius to convert from center y to apex y
h );
}
if( showText() )
{
for ( zint_render_string *zstring = render->strings; zstring != nullptr; zstring = zstring->next )
for ( zint_vector_string *zstring = vector->strings; zstring != nullptr; zstring = zstring->next )
{
double fsize = FONT_SCALE*zstring->fsize;
addText( zstring->x, zstring->y+0.75*fsize, fsize, QString((char*)(zstring->text)).toStdString() );
auto halign = static_cast<glbarcode::HAlign>(zstring->halign); // zint values match glbarcode enum
addText( zstring->x*xscale,
zstring->y*yscale,
zstring->fsize*std::min( xscale, yscale ), // TODO: do something better here
std::string((const char*)zstring->text),
halign );
}
}
@@ -223,6 +266,22 @@ namespace glabels
symbology = BARCODE_AZRUNE;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// Channel Code Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Channel::create()
{
return new Channel();
}
std::string Channel::encode( const std::string& cookedData )
{
symbology = BARCODE_CHANNEL;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
@@ -237,6 +296,26 @@ namespace glabels
std::string Cbr::encode( const std::string& cookedData )
{
symbology = BARCODE_CODABAR;
if (checksum())
{
option_2 = 1;
}
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// Codablock-F Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Cblockf::create()
{
return new Cblockf();
}
std::string Cblockf::encode( const std::string& cookedData )
{
symbology = BARCODE_CODABLOCKF;
return ""; // Actual encoding is done in vectorize
}
@@ -269,6 +348,10 @@ namespace glabels
std::string Code11::encode( const std::string& cookedData )
{
symbology = BARCODE_CODE11;
if (!checksum()) // Note default is 2 visible check digits
{
option_2 = 2;
}
return ""; // Actual encoding is done in vectorize
}
@@ -300,7 +383,11 @@ namespace glabels
std::string C25m::encode( const std::string& cookedData )
{
symbology = BARCODE_C25MATRIX;
symbology = BARCODE_C25MATRIX; // BARCODE_C25STANDARD
if (checksum())
{
option_2 = 1;
}
return ""; // Actual encoding is done in vectorize
}
@@ -317,6 +404,30 @@ namespace glabels
std::string C25i::encode( const std::string& cookedData )
{
symbology = BARCODE_C25IATA;
if (checksum())
{
option_2 = 1;
}
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// Code 2 of 5 Industrial Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* C25ind::create()
{
return new C25ind();
}
std::string C25ind::encode( const std::string& cookedData )
{
symbology = BARCODE_C25IND;
if (checksum())
{
option_2 = 1;
}
return ""; // Actual encoding is done in vectorize
}
@@ -333,6 +444,10 @@ namespace glabels
std::string C25dl::encode( const std::string& cookedData )
{
symbology = BARCODE_C25LOGIC;
if (checksum())
{
option_2 = 1;
}
return ""; // Actual encoding is done in vectorize
}
@@ -365,6 +480,10 @@ namespace glabels
std::string Code39::encode( const std::string& cookedData )
{
symbology = BARCODE_CODE39;
if (checksum())
{
option_2 = 1;
}
return ""; // Actual encoding is done in vectorize
}
@@ -381,6 +500,10 @@ namespace glabels
std::string Code39e::encode( const std::string& cookedData )
{
symbology = BARCODE_EXCODE39;
if (checksum())
{
option_2 = 1;
}
return ""; // Actual encoding is done in vectorize
}
@@ -511,6 +634,38 @@ namespace glabels
symbology = BARCODE_DPIDENT;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// DotCode Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Dotcode::create()
{
return new Dotcode();
}
std::string Dotcode::encode( const std::string& cookedData )
{
symbology = BARCODE_DOTCODE;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// DPD Code Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Dpd::create()
{
return new Dpd();
}
std::string Dpd::encode( const std::string& cookedData )
{
symbology = BARCODE_DPD;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
@@ -543,6 +698,70 @@ namespace glabels
symbology = BARCODE_EANX;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// EAN-14 Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Ean14::create()
{
return new Ean14();
}
std::string Ean14::encode( const std::string& cookedData )
{
symbology = BARCODE_EAN14;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// Facing Identification Mark Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Fim::create()
{
return new Fim();
}
std::string Fim::encode( const std::string& cookedData )
{
symbology = BARCODE_FIM;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// Flattermarken Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Flat::create()
{
return new Flat();
}
std::string Flat::encode( const std::string& cookedData )
{
symbology = BARCODE_FLAT;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// Han Xin Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Hanxin::create()
{
return new Hanxin();
}
std::string Hanxin::encode( const std::string& cookedData )
{
symbology = BARCODE_HANXIN;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
@@ -639,6 +858,22 @@ namespace glabels
symbology = BARCODE_HIBC_MICPDF;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// HIBC Codablock-F Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Hibcblkf::create()
{
return new Hibcblkf();
}
std::string Hibcblkf::encode( const std::string& cookedData )
{
symbology = BARCODE_HIBC_BLOCKF;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
@@ -669,6 +904,10 @@ namespace glabels
std::string I25::encode( const std::string& cookedData )
{
symbology = BARCODE_C25INTER;
if (checksum())
{
option_2 = 1;
}
return ""; // Actual encoding is done in vectorize
}
@@ -749,6 +988,10 @@ namespace glabels
std::string Logm::encode( const std::string& cookedData )
{
symbology = BARCODE_LOGMARS;
if (checksum())
{
option_2 = 1;
}
return ""; // Actual encoding is done in vectorize
}
@@ -1005,6 +1248,10 @@ namespace glabels
std::string Msi::encode( const std::string& cookedData )
{
symbology = BARCODE_MSI_PLESSEY;
if (checksum())
{
option_2 = 1; // 1 visible mod-10 check digit
}
return ""; // Actual encoding is done in vectorize
}
@@ -1071,6 +1318,38 @@ namespace glabels
symbology = BARCODE_POSTNET;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// BC412 (SEMI T1-95) Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Bc412::create()
{
return new Bc412();
}
std::string Bc412::encode( const std::string& cookedData )
{
symbology = BARCODE_BC412;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// CEPNet Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Cepnet::create()
{
return new Cepnet();
}
std::string Cepnet::encode( const std::string& cookedData )
{
symbology = BARCODE_CEPNET;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
@@ -1119,6 +1398,22 @@ namespace glabels
symbology = BARCODE_QRCODE;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// rMQR Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Rmqr::create()
{
return new Rmqr();
}
std::string Rmqr::encode( const std::string& cookedData )
{
symbology = BARCODE_RMQR;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
@@ -1135,6 +1430,38 @@ namespace glabels
symbology = BARCODE_RM4SCC;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// Royal Mail 4-State Mailmark Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Rm4sm::create()
{
return new Rm4sm();
}
std::string Rm4sm::encode( const std::string& cookedData )
{
symbology = BARCODE_MAILMARK; // BARCODE_MAILMARK_4S
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// Royal Mail 2-D Mailmark Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Rm2dm::create()
{
return new Rm2dm();
}
std::string Rm2dm::encode( const std::string& cookedData )
{
symbology = BARCODE_MAILMARK_2D;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
@@ -1167,6 +1494,22 @@ namespace glabels
symbology = BARCODE_UPCE;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// UPU S10 Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* UpuS10::create()
{
return new UpuS10();
}
std::string UpuS10::encode( const std::string& cookedData )
{
symbology = BARCODE_UPU_S10;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
@@ -1199,6 +1542,22 @@ namespace glabels
symbology = BARCODE_PLESSEY;
return ""; // Actual encoding is done in vectorize
}
//////////////////////////////////////////////////////
// Vehicle Identification Number Barcode
//////////////////////////////////////////////////////
glbarcode::Barcode* Vin::create()
{
return new Vin();
}
std::string Vin::encode( const std::string& cookedData )
{
symbology = BARCODE_VIN;
return ""; // Actual encoding is done in vectorize
}
}