From 0e7049ed73b1809872dd0603a1c492375cbf0f34 Mon Sep 17 00:00:00 2001 From: Jaye Evins Date: Sat, 16 Aug 2025 17:00:14 -0400 Subject: [PATCH] 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 --- .travis.yml | 2 +- CMakeLists.txt | 4 +- backends/barcode/Backends.cpp | 154 ++++++++---- backends/barcode/CMakeLists.txt | 1 + backends/barcode/Zint.cpp | 415 ++++++++++++++++++++++++++++--- backends/barcode/Zint.h | 228 ++++++++++++++++- cmake/Modules/FindLibZint.cmake | 24 +- docs/BUILD-INSTRUCTIONS-LINUX.md | 10 +- glbarcode/Barcode.cpp | 4 +- glbarcode/Barcode.h | 12 +- glbarcode/DrawingPrimitives.cpp | 10 +- glbarcode/DrawingPrimitives.h | 19 +- glbarcode/Enums.h | 38 +++ glbarcode/QtRenderer.cpp | 17 +- glbarcode/QtRenderer.h | 2 +- glbarcode/Renderer.cpp | 2 +- glbarcode/Renderer.h | 2 +- model/ModelBarcodeObject.cpp | 3 +- translations/glabels_C.ts | 172 +++++++++---- 19 files changed, 957 insertions(+), 162 deletions(-) create mode 100644 glbarcode/Enums.h diff --git a/.travis.yml b/.travis.yml index d3e86b4..1738090 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ matrix: - sudo apt-get -y install pkgconf libqrencode-dev - sudo apt-get -y install barcode # Install zint from source - - wget https://downloads.sourceforge.net/project/zint/zint/2.6.5/zint-2.6.5.tar.gz && tar xzf zint-2.6.5.tar.gz && ( cd zint-2.6.5 && mkdir build && cd build && cmake .. && make && sudo make install ) + - wget https://downloads.sourceforge.net/project/zint/zint/2.12.0/zint-2.12.0-src.tar.gz && tar xzf zint-2.12.0-src.tar.gz && ( cd zint-2.12.0-src && mkdir build && cd build && cmake .. && make && sudo make install ) - export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH before_script: diff --git a/CMakeLists.txt b/CMakeLists.txt index cdafd6a..3bdba30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,7 +125,9 @@ endif () find_package (ZLIB 1.2 QUIET) find_package (GnuBarcode 0.98 QUIET) find_package (LibQrencode 3.4 QUIET) -find_package (LibZint 2.6 EXACT QUIET) +find_package (LibZint 2.15 QUIET) +# Unit testing support +find_package (Qt5Test 5.6 QUIET) #======================================= diff --git a/backends/barcode/Backends.cpp b/backends/barcode/Backends.cpp index 4834b6d..fb89c34 100644 --- a/backends/barcode/Backends.cpp +++ b/backends/barcode/Backends.cpp @@ -184,12 +184,17 @@ namespace glabels glbarcode::Factory::registerType( "zint::ausrd", Zint::AusRD::create ); glbarcode::Factory::registerType( "zint::aztec", Zint::Aztec::create ); glbarcode::Factory::registerType( "zint::azrun", Zint::Azrun::create ); + glbarcode::Factory::registerType( "zint::bc412", Zint::Bc412::create ); + glbarcode::Factory::registerType( "zint::cepnet", Zint::Cepnet::create ); glbarcode::Factory::registerType( "zint::cbr", Zint::Cbr::create ); + glbarcode::Factory::registerType( "zint::cblockf", Zint::Cblockf::create ); + glbarcode::Factory::registerType( "zint::channel", Zint::Channel::create ); glbarcode::Factory::registerType( "zint::code1", Zint::Code1::create ); glbarcode::Factory::registerType( "zint::code11", Zint::Code11::create ); glbarcode::Factory::registerType( "zint::c16k", Zint::C16k::create ); glbarcode::Factory::registerType( "zint::c25m", Zint::C25m::create ); glbarcode::Factory::registerType( "zint::c25i", Zint::C25i::create ); + glbarcode::Factory::registerType( "zint::c25ind", Zint::C25ind::create ); glbarcode::Factory::registerType( "zint::c25dl", Zint::C25dl::create ); glbarcode::Factory::registerType( "zint::code32", Zint::Code32::create ); glbarcode::Factory::registerType( "zint::code39", Zint::Code39::create ); @@ -202,10 +207,16 @@ namespace glabels glbarcode::Factory::registerType( "zint::dmtx", Zint::Dmtx::create ); glbarcode::Factory::registerType( "zint::dpl", Zint::Dpl::create ); glbarcode::Factory::registerType( "zint::dpi", Zint::Dpi::create ); + glbarcode::Factory::registerType( "zint::dotcode", Zint::Dotcode::create ); + glbarcode::Factory::registerType( "zint::dpd", Zint::Dpd::create ); glbarcode::Factory::registerType( "zint::kix", Zint::Kix::create ); glbarcode::Factory::registerType( "zint::ean", Zint::Ean::create ); + glbarcode::Factory::registerType( "zint::ean14", Zint::Ean14::create ); + glbarcode::Factory::registerType( "zint::fim", Zint::Fim::create ); + glbarcode::Factory::registerType( "zint::flat", Zint::Flat::create ); glbarcode::Factory::registerType( "zint::gmtx", Zint::Gmtx::create ); glbarcode::Factory::registerType( "zint::gs1-128", Zint::Gs1128::create ); + glbarcode::Factory::registerType( "zint::hanxin", Zint::Hanxin::create ); glbarcode::Factory::registerType( "zint::rss14", Zint::Rss14::create ); glbarcode::Factory::registerType( "zint::rssltd", Zint::Rssltd::create ); glbarcode::Factory::registerType( "zint::rssexp", Zint::Rssexp::create ); @@ -218,6 +229,7 @@ namespace glabels glbarcode::Factory::registerType( "zint::hibcqr", Zint::Hibcqr::create ); glbarcode::Factory::registerType( "zint::hibcpdf", Zint::Hibcpdf::create ); glbarcode::Factory::registerType( "zint::hibcmpdf", Zint::Hibcmpdf::create ); + glbarcode::Factory::registerType( "zint::hibcblkf", Zint::Hibcblkf::create ); glbarcode::Factory::registerType( "zint::hibcaz", Zint::Hibcaz::create ); glbarcode::Factory::registerType( "zint::i25", Zint::I25::create ); glbarcode::Factory::registerType( "zint::isbn", Zint::Isbn::create ); @@ -238,13 +250,18 @@ namespace glabels glbarcode::Factory::registerType( "zint::pharma2", Zint::Pharma2::create ); glbarcode::Factory::registerType( "zint::pzn", Zint::Pzn::create ); glbarcode::Factory::registerType( "zint::qr", Zint::Qr::create ); + glbarcode::Factory::registerType( "zint::rmqr", Zint::Rmqr::create ); glbarcode::Factory::registerType( "zint::rm4", Zint::Rm4::create ); + glbarcode::Factory::registerType( "zint::rm4sm", Zint::Rm4sm::create ); + glbarcode::Factory::registerType( "zint::rm2dm", Zint::Rm2dm::create ); glbarcode::Factory::registerType( "zint::tele", Zint::Tele::create ); glbarcode::Factory::registerType( "zint::telex", Zint::Telex::create ); glbarcode::Factory::registerType( "zint::upc-a", Zint::UpcA::create ); glbarcode::Factory::registerType( "zint::upc-e", Zint::UpcE::create ); + glbarcode::Factory::registerType( "zint::upus10", Zint::UpuS10::create ); glbarcode::Factory::registerType( "zint::usps", Zint::Usps::create ); glbarcode::Factory::registerType( "zint::pls", Zint::Pls::create ); + glbarcode::Factory::registerType( "zint::vin", Zint::Vin::create ); registerStyle( "ausp", "zint", tr("Australia Post Standard"), false, false, true, false, "12345678901234567890123", true, 23 ); @@ -261,38 +278,53 @@ namespace glabels registerStyle( "aztec", "zint", tr("Aztec Code"), false, false, true, false, "1234567890", true, 10 ); - registerStyle( "azrun", "zint", tr("Aztec Rune"), + registerStyle( "azrun", "zint", tr("Aztec Runes"), false, false, true, false, "255", true, 3 ); + registerStyle( "bc412", "zint", tr("BC412 (SEMI TI-95)"), + true, true, true, false, "12345678", true, 8 ); + + registerStyle( "cepnet", "zint", tr("CEPNet (Brazilian Post)"), + false, false, true, false, "12345678", true, 8 ); + + registerStyle( "channel", "zint", tr("Channel Code"), + true, true, false, false, "00", true, 2 ); + registerStyle( "cbr", "zint", tr("Codabar"), - true, true, true, false, "ABCDABCDAB", true, 10 ); + true, true, true, true, "A00000000B", true, 10 ); + + registerStyle( "cblockf", "zint", tr("Codablock-F"), + false, false, true, false, "0000000000", true, 10 ); registerStyle( "code1", "zint", tr("Code One"), false, false, true, false, "0000000000", true, 10 ); registerStyle( "code11", "zint", tr("Code 11"), - true, true, true, false, "0000000000", true, 10 ); + true, true, true, true, "0000000000", true, 10 ); registerStyle( "c16k", "zint", tr("Code 16K"), false, false, true, false, "0000000000", true, 10 ); - registerStyle( "c25m", "zint", tr("Code 2 of 5 Matrix"), - true, true, true, false, "0000000000", true, 10 ); + registerStyle( "c25m", "zint", tr("Code 2 of 5 Standard"), + true, true, true, true, "0000000000", true, 10 ); registerStyle( "c25i", "zint", tr("Code 2 of 5 IATA"), - true, true, true, false, "0000000000", true, 10 ); + true, true, true, true, "0000000000", true, 10 ); + + registerStyle( "c25ind", "zint", tr("Code 2 of 5 Industrial"), + true, true, true, true, "0000000000", true, 10 ); registerStyle( "c25dl", "zint", tr("Code 2 of 5 Data Logic"), - true, true, true, false, "0000000000", true, 10 ); + true, true, true, true, "0000000000", true, 10 ); registerStyle( "code32", "zint", tr("Code 32 (Italian Pharmacode)"), true, true, true, false, "12345678", true, 8 ); registerStyle( "code39", "zint", tr("Code 39"), - true, true, false, false, "0000000000", true, 10 ); + true, true, true, true, "0000000000", true, 10 ); registerStyle( "code39e", "zint", tr("Code 39 Extended"), - true, true, true, false, "0000000000", true, 10 ); + true, true, true, true, "0000000000", true, 10 ); registerStyle( "code49", "zint", tr("Code 49"), false, false, true, false, "0000000000", true, 10 ); @@ -317,36 +349,54 @@ namespace glabels registerStyle( "dpi", "zint", tr("Deutsche Post Identcode"), true, true, true, false, "12345678901", true, 11 ); - - registerStyle( "kix", "zint", tr("Dutch Post KIX Code"), + + registerStyle( "dotcode", "zint", tr("DotCode"), false, false, true, false, "0000000000", true, 10 ); + registerStyle( "dpd", "zint", tr("DPD Code"), + true, true, true, false, "000000000000000000000000000", true, 27 ); + + registerStyle( "kix", "zint", tr("Dutch Post KIX Code"), + false, false, false, false, "0000000000", true, 10 ); + registerStyle( "ean", "zint", tr("EAN"), + true, true, true, false, "123456789012", false, 12 ); + + registerStyle( "ean14", "zint", tr("EAN-14"), true, true, true, false, "1234567890123", false, 13 ); + registerStyle( "fim", "zint", tr("FIM (Facing ID Mark)"), + false, false, false, false, "A", false, 1 ); + + registerStyle( "flat", "zint", tr("Flattermarken"), + false, false, false, false, "11111111", false, 8 ); + registerStyle( "gmtx", "zint", tr("Grid Matrix"), false, false, true, false, "0000000000", true, 10 ); registerStyle( "gs1-128", "zint", tr("GS1-128"), - true, true, true, false, "[01]12345678901234", false, 18 ); + true, true, true, false, "[01]12345678901231", false, 18 ); - registerStyle( "rss14", "zint", tr("GS1 DataBar-14"), + registerStyle( "rss14", "zint", tr("GS1 DataBar Omnidirectional"), true, true, true, false, "1234567890123", true, 13 ); - registerStyle( "rssltd", "zint", "GS1 DataBar-14 Limited", + registerStyle( "rssltd", "zint", "GS1 DataBar Limited", true, true, true, false, "1234567890123", true, 13 ); - registerStyle( "rssexp", "zint", "GS1 DataBar Extended", - true, true, true, false, "[01]12345678901234", false, 18 ); + registerStyle( "rssexp", "zint", "GS1 DataBar Expanded", + true, true, true, false, "[01]12345678901231", false, 18 ); - registerStyle( "rsss", "zint", tr("GS1 DataBar-14 Stacked"), + registerStyle( "rsss", "zint", tr("GS1 DataBar Stacked"), false, false, true, false, "0000000000", true, 10 ); - registerStyle( "rssso", "zint", tr("GS1 DataBar-14 Stacked Omni."), + registerStyle( "rssso", "zint", tr("GS1 DataBar Stacked Omni."), false, false, true, false, "0000000000", true, 10 ); - registerStyle( "rssse", "zint", tr("GS1 DataBar Extended Stacked"), - false, false, true, false, "[01]12345678901234", false, 18 ); + registerStyle( "rssse", "zint", tr("GS1 DataBar Expanded Stacked"), + false, false, true, false, "[01]12345678901231", false, 18 ); + + registerStyle( "hanxin", "zint", tr("Han Xin"), + false, false, true, false, "0000000000", true, 10 ); registerStyle( "hibc128", "zint", tr("HIBC Code 128"), true, true, true, false, "0000000000", true, 10 ); @@ -363,14 +413,17 @@ namespace glabels registerStyle( "hibcpdf", "zint", tr("HIBC PDF417"), false, false, true, false, "0000000000", true, 10 ); - registerStyle( "hibcmpdf", "zint", tr("HIBC Micro PDF417"), + registerStyle( "hibcmpdf", "zint", tr("HIBC MicroPDF417"), + false, false, true, false, "0000000000", true, 10 ); + + registerStyle( "hibcblkf", "zint", tr("HIBC Codablock-F"), false, false, true, false, "0000000000", true, 10 ); registerStyle( "hibcaz", "zint", tr("HIBC Aztec Code"), - true, true, true, false, "0000000000", true, 10 ); + false, false, true, false, "0000000000", true, 10 ); registerStyle( "i25", "zint", tr("Interleaved 2 of 5"), - true, true, true, false, "0000000000", true, 10 ); + true, true, true, true, "0000000000", true, 10 ); registerStyle( "isbn", "zint", tr("ISBN"), true, true, true, false, "123456789", false, 9 ); @@ -385,67 +438,82 @@ namespace glabels true, true, true, false, "123456", false, 6 ); registerStyle( "logm", "zint", tr("LOGMARS"), - true, true, true, false, "0000000000", true, 10 ); + true, true, true, true, "0000000000", true, 10 ); registerStyle( "maxi", "zint", tr("Maxicode"), - false, false, false, false, "0000000000", true, 10 ); + false, false, true, false, "0000000000", true, 10 ); - registerStyle( "mpdf", "zint", tr("Micro PDF417"), + registerStyle( "mpdf", "zint", tr("MicroPDF417"), false, false, true, false, "0000000000", true, 10 ); registerStyle( "mqr", "zint", tr("Micro QR Code"), false, false, true, false, "0000000000", true, 10 ); registerStyle( "msi", "zint", tr("MSI Plessey"), - true, true, true, false, "0000000000", true, 10 ); + true, true, true, true, "0000000000", true, 10 ); - registerStyle( "nve", "zint", tr("NVE-18"), + registerStyle( "nve", "zint", tr("NVE-18 (SSCC-18)"), true, true, true, false, "12345678901234567", false, 17 ); registerStyle( "pdf", "zint", tr("PDF417"), false, false, true, false, "0000000000", true, 10 ); - registerStyle( "pdft", "zint", tr("PDF417 Truncated"), + registerStyle( "pdft", "zint", tr("PDF417 Compact"), false, false, true, false, "0000000000", true, 10 ); registerStyle( "plan", "zint", tr("PLANET"), - false, false, true, false, "0000000000", true, 10 ); + false, false, true, false, "00000000000", true, 11 ); - registerStyle( "postnet", "zint", tr("PostNet"), - true, true, true, false, "0000000000", true, 10 ); + registerStyle( "postnet", "zint", tr("POSTNET"), + false, false, true, false, "00000000000", true, 11 ); registerStyle( "pharma", "zint", tr("Pharmacode"), - false, false, true, false, "123456", false, 6 ); + false, false, false, false, "123456", false, 6 ); registerStyle( "pharma2", "zint", tr("Pharmacode 2-track"), - false, false, true, false, "12345678", false, 8 ); + false, false, false, false, "12345678", false, 8 ); - registerStyle( "pzn", "zint", tr("Pharmazentral Nummer (PZN)"), - true, true, true, false, "123456", false, 6 ); + registerStyle( "pzn", "zint", tr("Pharmazentralnummer (PZN)"), + true, true, true, false, "1234567", false, 7 ); registerStyle( "qr", "zint", tr("QR Code"), - true, true, true, false, "0000000000", true, 10 ); - - registerStyle( "rm4", "zint", tr("Royal Mail 4-State"), false, false, true, false, "0000000000", true, 10 ); + registerStyle( "rmqr", "zint", tr("rMQR (Rectangular Micro QR)"), + false, false, true, false, "0000000000", true, 10 ); + + registerStyle( "rm4", "zint", tr("Royal Mail 4-State Customer"), + false, false, true, false, "0000000000", true, 10 ); + + registerStyle( "rm4sm", "zint", tr("Royal Mail 4-State Mailmark"), + false, false, true, false, "01000000000000000AA00AA0A", true, 25 ); + + registerStyle( "rm2dm", "zint", tr("Royal Mail 2-D Mailmark"), + false, false, true, false, "012100123412345678AB19XY1A 0", true, 28 ); + registerStyle( "tele", "zint", tr("Telepen"), true, true, true, false, "0000000000", true, 10 ); registerStyle( "telex", "zint", tr("Telepen Numeric"), true, true, true, false, "0000000000", true, 10 ); + registerStyle( "pls", "zint", tr("UK Plessey"), + true, true, true, false, "0000000000", true, 10 ); + registerStyle( "upc-a", "zint", tr("UPC-A"), true, true, true, false, "12345678901", false, 11 ); registerStyle( "upc-e", "zint", tr("UPC-E"), true, true, true, false, "1234567", false, 7 ); - - registerStyle( "usps", "zint", tr("USPS One Code"), + + registerStyle( "upus10", "zint", tr("UPU S10"), + true, true, true, false, "EE876543216CA", false, 13 ); + + registerStyle( "usps", "zint", tr("USPS Intelligent Mail"), false, false, true, false, "12345678901234567890", true, 20 ); - registerStyle( "pls", "zint", tr("UK Plessey"), - true, true, true, false, "0000000000", true, 10 ); + registerStyle( "vin", "zint", tr("VIN (Vehicle ID Number)"), + true, true, true, false, "12345678701234567", false, 27 ); #endif // HAVE_ZINT } diff --git a/backends/barcode/CMakeLists.txt b/backends/barcode/CMakeLists.txt index daa6f31..0df7d83 100644 --- a/backends/barcode/CMakeLists.txt +++ b/backends/barcode/CMakeLists.txt @@ -19,6 +19,7 @@ endif () if (${LIBZINT_FOUND}) add_definitions (-DHAVE_ZINT=1) + add_definitions (-DHAVE_ZINT=1 -DLIBZINT_VERSION=${LIBZINT_VERSION}) set (OPTIONAL_ZINT ZINT::ZINT) else () set (OPTIONAL_ZINT "") diff --git a/backends/barcode/Zint.cpp b/backends/barcode/Zint.cpp index 90faa4d..bcfc62d 100644 --- a/backends/barcode/Zint.cpp +++ b/backends/barcode/Zint.cpp @@ -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(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 + } } diff --git a/backends/barcode/Zint.h b/backends/barcode/Zint.h index 68bbe85..bde8e5d 100644 --- a/backends/barcode/Zint.h +++ b/backends/barcode/Zint.h @@ -42,8 +42,11 @@ namespace glabels { protected: int symbology; - - + int option_2; + + + Base(); + bool validate( const std::string& rawData ) override; void vectorize( const std::string& encodedData, @@ -132,6 +135,19 @@ namespace glabels }; + /** + * Channel Barcode + */ + class Channel : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + /** * Cbr Barcode */ @@ -145,6 +161,19 @@ namespace glabels }; + /** + * Codeblock-F Barcode + */ + class Cblockf : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + /** * Code1 Barcode */ @@ -210,6 +239,19 @@ namespace glabels }; + /** + * Code 2 of 5 Industrial Barcode + */ + class C25ind : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + /** * C25dl Barcode */ @@ -366,6 +408,32 @@ namespace glabels }; + /** + * DotCode Barcode + */ + class Dotcode : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + + /** + * DPD Code Barcode + */ + class Dpd : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + /** * Kix Barcode */ @@ -392,6 +460,58 @@ namespace glabels }; + /** + * EAN-14 Barcode + */ + class Ean14 : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + + /** + * Facing Identification Mark Barcode + */ + class Fim : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + + /** + * Flattermarken Barcode + */ + class Flat : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + + /** + * Han Xin Barcode + */ + class Hanxin : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + /** * Hibc128 Barcode */ @@ -470,6 +590,19 @@ namespace glabels }; + /** + * HIBC Codablock-F Barcode + */ + class Hibcblkf : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + /** * Hibcaz Barcode */ @@ -821,6 +954,32 @@ namespace glabels }; + /** + * BC412 (SEMI T1-95) Barcode + */ + class Bc412 : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + + /** + * CEPNet Barcode + */ + class Cepnet : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + /** * Pdf Barcode */ @@ -860,6 +1019,19 @@ namespace glabels }; + /** + * rMQR Barcode + */ + class Rmqr : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + /** * Rm4 Barcode */ @@ -873,6 +1045,32 @@ namespace glabels }; + /** + * Royal Mail 4-State Mailmark Barcode + */ + class Rm4sm : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + + /** + * Royal Mail 2-D Mailmark Barcode + */ + class Rm2dm : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + /** * UpcA Barcode */ @@ -899,6 +1097,19 @@ namespace glabels }; + /** + * UPU S10 Barcode + */ + class UpuS10 : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + /** * Usps Barcode */ @@ -925,6 +1136,19 @@ namespace glabels }; + /** + * Vehicle Identification Number Barcode + */ + class Vin : public Base + { + public: + static Barcode* create(); + + protected: + std::string encode( const std::string& cookedData ) override; + }; + + } } } diff --git a/cmake/Modules/FindLibZint.cmake b/cmake/Modules/FindLibZint.cmake index 9f1a754..9cf532f 100644 --- a/cmake/Modules/FindLibZint.cmake +++ b/cmake/Modules/FindLibZint.cmake @@ -37,17 +37,29 @@ 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() + if (ZINT_MAJOR_H) # ZINT_MINOR_H and ZINT_MICRO_H may be zero so don't test + 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}) + math (EXPR LIBZINT_VERSION "${ZINT_MAJOR} * 10000 + ${ZINT_MINOR} * 100 + ${ZINT_MICRO}") + else () + execute_process(COMMAND "zint" "-h" OUTPUT_VARIABLE EXEC_ZINT_VERSION ERROR_QUIET) + if (EXEC_ZINT_VERSION) + string (REGEX REPLACE "^Zint version ([0-9.]+).*$" "\\1" LIBZINT_VERSION_STRING ${EXEC_ZINT_VERSION}) + string (REGEX REPLACE "^([0-9]+).*$" "\\1" ZINT_MAJOR ${LIBZINT_VERSION_STRING}) + string (REGEX REPLACE "^[0-9]+\.([0-9]+).*$" "\\1" ZINT_MINOR ${LIBZINT_VERSION_STRING}) + string (REGEX REPLACE "^[0-9]+\.[0-9]+\.([0-9]+).*$" "\\1" ZINT_MICRO ${LIBZINT_VERSION_STRING}) + math (EXPR LIBZINT_VERSION "${ZINT_MAJOR} * 10000 + ${ZINT_MINOR} * 100 + ${ZINT_MICRO}") + endif () + endif () +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_LIBRARY LIBZINT_INCLUDE_DIR + REQUIRED_VARS LIBZINT_LIBRARY LIBZINT_INCLUDE_DIR LIBZINT_VERSION VERSION_VAR LIBZINT_VERSION_STRING) mark_as_advanced(LIBZINT_INCLUDE_DIR LIBZINT_LIBRARY) diff --git a/docs/BUILD-INSTRUCTIONS-LINUX.md b/docs/BUILD-INSTRUCTIONS-LINUX.md index aa665a9..880ff5b 100644 --- a/docs/BUILD-INSTRUCTIONS-LINUX.md +++ b/docs/BUILD-INSTRUCTIONS-LINUX.md @@ -42,11 +42,11 @@ _Zint (Optional)_ Install zint from source: ``` -$ wget https://downloads.sourceforge.net/project/zint/zint/2.6.3/zint-2.6.3_final.tar.gz -$ tar xzf zint-2.6.3_final.tar.gz -$ cd zint-2.6.3.src/ -$ mkdir build && cd build && cmake .. && make -$ sudo make install +wget https://downloads.sourceforge.net/project/zint/zint/2.15.0/zint-2.15.0-src.tar.gz +tar xzf zint-2.15.0-src.tar.gz +cd zint-2.15.0-src/ +mkdir build && cd build && cmake .. && make +sudo make install ``` _GNU Barcode (Optional)_ diff --git a/glbarcode/Barcode.cpp b/glbarcode/Barcode.cpp index 2b632ea..8eb4e10 100644 --- a/glbarcode/Barcode.cpp +++ b/glbarcode/Barcode.cpp @@ -174,9 +174,9 @@ namespace glbarcode } - void Barcode::addText( double x, double y, double size, const std::string& text ) + void Barcode::addText( double x, double y, double size, const std::string& text, HAlign halign ) { - d->mPrimitives.push_back( new DrawingPrimitiveText( x, y, size, text ) ); + d->mPrimitives.push_back( new DrawingPrimitiveText( x, y, size, text, halign ) ); } diff --git a/glbarcode/Barcode.h b/glbarcode/Barcode.h index 7d87160..42c7af5 100644 --- a/glbarcode/Barcode.h +++ b/glbarcode/Barcode.h @@ -24,6 +24,7 @@ #include +#include "Enums.h" #include "Renderer.h" @@ -215,12 +216,13 @@ namespace glbarcode * * @image html figure-primitive-text.svg "Text primitive properties" * - * @param[in] x X coordinate of text's origin (points) - * @param[in] y Y coordinate of text's origin (points) - * @param[in] size Font size of text (points) - * @param[in] text Text + * @param[in] x X coordinate of text's origin (points) + * @param[in] y Y coordinate of text's origin (points) + * @param[in] size Font size of text (points) + * @param[in] text Text + * @param[in] halign Horizontal text alignment */ - void addText( double x, double y, double size, const std::string& text ); + void addText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER ); /** diff --git a/glbarcode/DrawingPrimitives.cpp b/glbarcode/DrawingPrimitives.cpp index 6d6c5b3..0a4837c 100644 --- a/glbarcode/DrawingPrimitives.cpp +++ b/glbarcode/DrawingPrimitives.cpp @@ -81,8 +81,8 @@ namespace glbarcode - DrawingPrimitiveText::DrawingPrimitiveText( double x, double y, double size, const std::string& text ) - : DrawingPrimitive( x, y ), mSize(size), mText(text) + DrawingPrimitiveText::DrawingPrimitiveText( double x, double y, double size, const std::string& text, HAlign halign ) + : DrawingPrimitive( x, y ), mSize(size), mText(text), mHalign(halign) { } @@ -99,6 +99,12 @@ namespace glbarcode } + HAlign DrawingPrimitiveText::halign() const + { + return mHalign; + } + + DrawingPrimitiveRing::DrawingPrimitiveRing( double x, double y, double r, double w ) : DrawingPrimitive( x, y ), mR(r), mW(w) diff --git a/glbarcode/DrawingPrimitives.h b/glbarcode/DrawingPrimitives.h index cfb86b4..ad8dab7 100644 --- a/glbarcode/DrawingPrimitives.h +++ b/glbarcode/DrawingPrimitives.h @@ -22,6 +22,8 @@ #define glbarcode_DrawingPrimitives_h +#include "Enums.h" + #include @@ -163,12 +165,13 @@ namespace glbarcode /** * Text constructor * - * @param[in] x X coordinate of text's origin (points) - * @param[in] y Y coordinate of text's origin (points) - * @param[in] size Font size of text (points) - * @param[in] text Text + * @param[in] x X coordinate of text's origin (points) + * @param[in] y Y coordinate of text's origin (points) + * @param[in] size Font size of text (points) + * @param[in] text Text + * @param[in] halign Horizontal text alignment */ - DrawingPrimitiveText( double x, double y, double size, const std::string& text ); + DrawingPrimitiveText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER ); /** * Get font size (points). @@ -180,9 +183,15 @@ namespace glbarcode */ const std::string& text() const; + /** + * Get horizontal alignment. + */ + HAlign halign() const; + private: double mSize; /**< Font size of text (points). */ std::string mText; /**< Text. */ + HAlign mHalign; /**< Horizontal alignment. */ }; diff --git a/glbarcode/Enums.h b/glbarcode/Enums.h new file mode 100644 index 0000000..8ddb78a --- /dev/null +++ b/glbarcode/Enums.h @@ -0,0 +1,38 @@ +/* Enums.h + * + * Copyright (C) 2013 Jaye Evins + * + * This file is part of glbarcode++. + * + * glbarcode++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * glbarcode++ 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with glbarcode++. If not, see . + */ + +#ifndef glbarcode_Enums_h +#define glbarcode_Enums_h + + +namespace glbarcode +{ + + enum HAlign + { + H_ALIGN_CENTER = 0, + H_ALIGN_LEFT = 1, + H_ALIGN_RIGHT = 2 + }; + +} + + +#endif // glbarcode_Enums_h diff --git a/glbarcode/QtRenderer.cpp b/glbarcode/QtRenderer.cpp index 63e8c2f..d0c1fad 100644 --- a/glbarcode/QtRenderer.cpp +++ b/glbarcode/QtRenderer.cpp @@ -30,6 +30,7 @@ namespace { const double FONT_SCALE = 0.75; + const double MIN_POINT_SIZE = 0.4; // Less than ~0.37 causes issues for QFontMetricsF } @@ -122,7 +123,7 @@ namespace glbarcode } - void QtRenderer::drawText( double x, double y, double size, const std::string& text ) + void QtRenderer::drawText( double x, double y, double size, const std::string& text, HAlign halign ) { if ( d->painter ) { @@ -131,10 +132,18 @@ namespace glbarcode QFont font; font.setStyleHint( QFont::Monospace ); font.setFamily( "monospace" ); - font.setPointSizeF( FONT_SCALE*size ); + font.setPointSizeF( std::max( FONT_SCALE*size, MIN_POINT_SIZE ) ); QFontMetricsF fm( font ); - double xCorner = x - fm.horizontalAdvance( QString::fromStdString(text) )/2.0; + double xCorner = x; + if ( halign == H_ALIGN_CENTER ) + { + xCorner -= fm.horizontalAdvance( QString::fromStdString(text) )/2.0; + } + else if ( halign == H_ALIGN_RIGHT ) + { + xCorner -= fm.horizontalAdvance( QString::fromStdString(text) ); + } double yCorner = y - fm.ascent(); QTextLayout layout( QString::fromStdString(text), font ); @@ -151,7 +160,7 @@ namespace glbarcode if ( d->painter ) { d->painter->setPen( QPen( d->color, w ) ); - d->painter->setBrush( Qt::NoBrush ); + d->painter->setBrush( w ? Qt::NoBrush : QBrush( d->color ) ); d->painter->drawEllipse( QPointF(x, y), r, r ); } diff --git a/glbarcode/QtRenderer.h b/glbarcode/QtRenderer.h index 56afa7b..39b58bd 100644 --- a/glbarcode/QtRenderer.h +++ b/glbarcode/QtRenderer.h @@ -76,7 +76,7 @@ namespace glbarcode void drawEnd() override; void drawLine( double x, double y, double w, double h ) override; void drawBox( double x, double y, double w, double h ) override; - void drawText( double x, double y, double size, const std::string& text ) override; + void drawText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER ) override; void drawRing( double x, double y, double r, double w ) override; void drawHexagon( double x, double y, double h ) override; diff --git a/glbarcode/Renderer.cpp b/glbarcode/Renderer.cpp index 867e0e3..1cec0a1 100644 --- a/glbarcode/Renderer.cpp +++ b/glbarcode/Renderer.cpp @@ -41,7 +41,7 @@ void glbarcode::Renderer::render( double w, double h, const std::list(*primitive) ) { - drawText( text->x(), text->y(), text->size(), text->text() ); + drawText( text->x(), text->y(), text->size(), text->text(), text->halign() ); } else if ( auto* ring = dynamic_cast(*primitive) ) { diff --git a/glbarcode/Renderer.h b/glbarcode/Renderer.h index 6bdb603..9fd6bca 100644 --- a/glbarcode/Renderer.h +++ b/glbarcode/Renderer.h @@ -132,7 +132,7 @@ namespace glbarcode * @param[in] size Font size of text (points) * @param[in] text Text */ - virtual void drawText( double x, double y, double size, const std::string& text ) = 0; + virtual void drawText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER ) = 0; /** diff --git a/model/ModelBarcodeObject.cpp b/model/ModelBarcodeObject.cpp index 07b8fa7..20b41f8 100644 --- a/model/ModelBarcodeObject.cpp +++ b/model/ModelBarcodeObject.cpp @@ -49,6 +49,7 @@ namespace glabels const Distance pad = Distance::pt(4); const Distance minW = Distance::pt(18); const Distance minH = Distance::pt(18); + const double MIN_POINT_SIZE = 0.4; // Less than ~0.37 causes issues for QFontMetricsF } @@ -508,7 +509,7 @@ namespace glabels { double scaleX = wPts / textRect.width(); double scaleY = hPts / textRect.height(); - font.setPointSizeF( 6 * std::min( scaleX, scaleY ) ); + font.setPointSizeF( std::max( 6 * std::min( scaleX, scaleY ), MIN_POINT_SIZE ) ); } // diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 62ddde6..10d1334 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -2555,10 +2555,6 @@ Aztec Code - - Aztec Rune - - Code One @@ -2571,10 +2567,6 @@ Code 16K - - Code 2 of 5 Matrix - - Code 2 of 5 IATA @@ -2627,22 +2619,6 @@ GS1-128 - - GS1 DataBar-14 - - - - GS1 DataBar-14 Stacked - - - - GS1 DataBar-14 Stacked Omni. - - - - GS1 DataBar Extended Stacked - - HIBC Code 128 @@ -2663,10 +2639,6 @@ HIBC PDF417 - - HIBC Micro PDF417 - - HIBC Aztec Code @@ -2691,10 +2663,6 @@ Maxicode - - Micro PDF417 - - Micro QR Code @@ -2703,26 +2671,14 @@ MSI Plessey - - NVE-18 - - PDF417 - - PDF417 Truncated - - PLANET - - PostNet - - Pharmacode @@ -2731,18 +2687,10 @@ Pharmacode 2-track - - Pharmazentral Nummer (PZN) - - QR Code - - Royal Mail 4-State - - Telepen @@ -2752,11 +2700,127 @@ - USPS One Code + UK Plessey - UK Plessey + Aztec Runes + + + + CEPNet (Brazilian Post) + + + + Codablock-F + + + + Code 2 of 5 Standard + + + + GS1 DataBar Stacked + + + + GS1 DataBar Stacked Omni. + + + + GS1 DataBar Expanded Stacked + + + + HIBC MicroPDF417 + + + + MicroPDF417 + + + + NVE-18 (SSCC-18) + + + + PDF417 Compact + + + + Pharmazentralnummer (PZN) + + + + Channel Code + + + + Code 2 of 5 Industrial + + + + DotCode + + + + EAN-14 + + + + GS1 DataBar Omnidirectional + + + + Han Xin + + + + Flattermarken + + + + DPD Code + + + + POSTNET + + + + Royal Mail 4-State Mailmark + + + + UPU S10 + + + + FIM (Facing ID Mark) + + + + rMQR (Rectangular Micro QR) + + + + Royal Mail 4-State Customer + + + + VIN (Vehicle ID Number) + + + + HIBC Codablock-F + + + + Royal Mail 2-D Mailmark + + + + BC412 (SEMI TI-95)