From 4ca02e7a40a531828afe7e26fe17a025eca66e5f Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Wed, 31 May 2017 23:16:47 -0400 Subject: [PATCH] Fleshed out GNU Barcode EAN barcodes. --- glabels/BarcodeBackends.cpp | 20 ++++- glabels/BarcodeBackends/GnuBarcode.cpp | 116 ++++++++++++++++++++++++- glabels/BarcodeBackends/GnuBarcode.h | 84 ++++++++++++++++++ translations/glabels_C.ts | 28 +++++- 4 files changed, 245 insertions(+), 3 deletions(-) diff --git a/glabels/BarcodeBackends.cpp b/glabels/BarcodeBackends.cpp index d279841..aef97b0 100644 --- a/glabels/BarcodeBackends.cpp +++ b/glabels/BarcodeBackends.cpp @@ -79,10 +79,28 @@ namespace glabels // registerBackend( "gnu-barcode", "GNU Barcode" ); - glbarcode::Factory::registerType( "gnu-barcode::ean", GnuBarcode::Ean::create ); + glbarcode::Factory::registerType( "gnu-barcode::ean", GnuBarcode::Ean::create ); + glbarcode::Factory::registerType( "gnu-barcode::ean-8", GnuBarcode::Ean8::create ); + glbarcode::Factory::registerType( "gnu-barcode::ean-8+2", GnuBarcode::Ean8_2::create ); + glbarcode::Factory::registerType( "gnu-barcode::ean-8+5", GnuBarcode::Ean8_5::create ); + glbarcode::Factory::registerType( "gnu-barcode::ean-13", GnuBarcode::Ean13::create ); + glbarcode::Factory::registerType( "gnu-barcode::ean-13+2", GnuBarcode::Ean13_2::create ); + glbarcode::Factory::registerType( "gnu-barcode::ean-13+5", GnuBarcode::Ean13_5::create ); registerStyle( "ean", "gnu-barcode", tr("EAN (any)"), true, true, true, false, "000000000000 00000", false, 17 ); + registerStyle( "ean-8", "gnu-barcode", tr("EAN-8"), + true, true, true, false, "0000000", false, 7 ); + registerStyle( "ean-8+2", "gnu-barcode", tr("EAN-8+2"), + true, true, true, false, "0000000 00", false, 9 ); + registerStyle( "ean-8+5", "gnu-barcode", tr("EAN-8+5"), + true, true, true, false, "0000000 00000", false, 12 ); + registerStyle( "ean-13", "gnu-barcode", tr("EAN-13"), + true, true, true, false, "000000000000", false, 12 ); + registerStyle( "ean-13+2", "gnu-barcode", tr("EAN-13+2"), + true, true, true, false, "000000000000 00", false, 14 ); + registerStyle( "ean-13+5", "gnu-barcode", tr("EAN-13+5"), + true, true, true, false, "000000000000 00000", false, 17 ); #endif // HAVE_GNU_BARCODE #if HAVE_QRENCODE diff --git a/glabels/BarcodeBackends/GnuBarcode.cpp b/glabels/BarcodeBackends/GnuBarcode.cpp index 8be3761..1df12fc 100644 --- a/glabels/BarcodeBackends/GnuBarcode.cpp +++ b/glabels/BarcodeBackends/GnuBarcode.cpp @@ -344,7 +344,6 @@ namespace glabels } - glbarcode::Barcode* Ean::create() { return new Ean(); @@ -368,6 +367,121 @@ namespace glabels return ""; // Actual encoding is done in vectorize } + + glbarcode::Barcode* Ean8::create() + { + return new Ean8(); + } + + + bool Ean8::validate( const std::string& rawData ) + { + return isNumericLengthValid( rawData, 7, 8 ); + } + + + std::string Ean8::encode( const std::string& cookedData ) + { + flags = BARCODE_EAN; + return ""; // Actual encoding is done in vectorize + } + + + glbarcode::Barcode* Ean8_2::create() + { + return new Ean8_2(); + } + + + bool Ean8_2::validate( const std::string& rawData ) + { + return isNumericLength1Valid( rawData, 7, 8 ) && isNumericLength2Valid( rawData, 2, 2 ); + } + + + std::string Ean8_2::encode( const std::string& cookedData ) + { + flags = BARCODE_EAN; + return ""; // Actual encoding is done in vectorize + } + + + glbarcode::Barcode* Ean8_5::create() + { + return new Ean8_5(); + } + + + bool Ean8_5::validate( const std::string& rawData ) + { + return isNumericLength1Valid( rawData, 7, 8 ) && isNumericLength2Valid( rawData, 5, 5 ); + } + + + std::string Ean8_5::encode( const std::string& cookedData ) + { + flags = BARCODE_EAN; + return ""; // Actual encoding is done in vectorize + } + + + glbarcode::Barcode* Ean13::create() + { + return new Ean13(); + } + + + bool Ean13::validate( const std::string& rawData ) + { + return isNumericLengthValid( rawData, 12, 13 ); + } + + + std::string Ean13::encode( const std::string& cookedData ) + { + flags = BARCODE_EAN; + return ""; // Actual encoding is done in vectorize + } + + + glbarcode::Barcode* Ean13_2::create() + { + return new Ean13_2(); + } + + + bool Ean13_2::validate( const std::string& rawData ) + { + return isNumericLength1Valid( rawData, 12, 13 ) && isNumericLength2Valid( rawData, 2, 2 ); + } + + + std::string Ean13_2::encode( const std::string& cookedData ) + { + flags = BARCODE_EAN; + return ""; // Actual encoding is done in vectorize + } + + + glbarcode::Barcode* Ean13_5::create() + { + return new Ean13_5(); + } + + + bool Ean13_5::validate( const std::string& rawData ) + { + return isNumericLength1Valid( rawData, 12, 13 ) && isNumericLength2Valid( rawData, 5, 5 ); + } + + + std::string Ean13_5::encode( const std::string& cookedData ) + { + flags = BARCODE_EAN; + return ""; // Actual encoding is done in vectorize + } + + } } diff --git a/glabels/BarcodeBackends/GnuBarcode.h b/glabels/BarcodeBackends/GnuBarcode.h index fd6783a..b92e5ad 100644 --- a/glabels/BarcodeBackends/GnuBarcode.h +++ b/glabels/BarcodeBackends/GnuBarcode.h @@ -76,6 +76,90 @@ namespace glabels std::string encode( const std::string& cookedData ) override; }; + + /** + * EAN-8 Barcode + */ + class Ean8 : public Base + { + public: + static Barcode* create(); + + protected: + bool validate( const std::string& rawData ) override; + std::string encode( const std::string& cookedData ) override; + }; + + + /** + * EAN-8+2 Barcode + */ + class Ean8_2 : public Base + { + public: + static Barcode* create(); + + protected: + bool validate( const std::string& rawData ) override; + std::string encode( const std::string& cookedData ) override; + }; + + + /** + * EAN-8+5 Barcode + */ + class Ean8_5 : public Base + { + public: + static Barcode* create(); + + protected: + bool validate( const std::string& rawData ) override; + std::string encode( const std::string& cookedData ) override; + }; + + + /** + * EAN-13 Barcode + */ + class Ean13 : public Base + { + public: + static Barcode* create(); + + protected: + bool validate( const std::string& rawData ) override; + std::string encode( const std::string& cookedData ) override; + }; + + + /** + * EAN-13+2 Barcode + */ + class Ean13_2 : public Base + { + public: + static Barcode* create(); + + protected: + bool validate( const std::string& rawData ) override; + std::string encode( const std::string& cookedData ) override; + }; + + + /** + * EAN-13+5 Barcode + */ + class Ean13_5 : public Base + { + public: + static Barcode* create(); + + protected: + bool validate( const std::string& rawData ) override; + std::string encode( const std::string& cookedData ) override; + }; + } } diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 76b1c2e..35844c4 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -779,12 +779,37 @@ - + EAN (any) + + + EAN-8 + + + + + EAN-8+2 + + + EAN-8+5 + + + + + EAN-13+2 + + + + + EAN-13+5 + + + + IEC18004 (QRCode) @@ -805,6 +830,7 @@ + EAN-13