From 8e08ea2343e9004eac924ab37ff99408cd48ca0f Mon Sep 17 00:00:00 2001 From: diogenes-souza-dev Date: Tue, 23 Aug 2022 16:16:55 -0300 Subject: [PATCH] Added Febraban Type --- Readme.md | 1 + src/BarcodeGenerator.php | 5 +++ src/Types/TypeFebraban.php | 91 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 src/Types/TypeFebraban.php diff --git a/Readme.md b/Readme.md index edb76f3..55b3463 100644 --- a/Readme.md +++ b/Readme.md @@ -76,6 +76,7 @@ Most used types are TYPE_CODE_128 and TYPE_CODE_39. Because of the best scanner - TYPE_STANDARD_2_5_CHECKSUM - TYPE_INTERLEAVED_2_5 - TYPE_INTERLEAVED_2_5_CHECKSUM +- TYPE_FEBRABAN - TYPE_CODE_128 - TYPE_CODE_128_A - TYPE_CODE_128_B diff --git a/src/BarcodeGenerator.php b/src/BarcodeGenerator.php index 69974e2..b6df310 100644 --- a/src/BarcodeGenerator.php +++ b/src/BarcodeGenerator.php @@ -44,6 +44,7 @@ use Picqer\Barcode\Types\TypeCode93; use Picqer\Barcode\Types\TypeEan13; use Picqer\Barcode\Types\TypeEan8; +use Picqer\Barcode\Types\TypeFebraban; use Picqer\Barcode\Types\TypeIntelligentMailBarcode; use Picqer\Barcode\Types\TypeInterleaved25; use Picqer\Barcode\Types\TypeInterleaved25Checksum; @@ -82,6 +83,7 @@ abstract class BarcodeGenerator const TYPE_EAN_5 = 'EAN5'; // 5-Digits UPC-Based Extention const TYPE_EAN_8 = 'EAN8'; const TYPE_EAN_13 = 'EAN13'; + const TYPE_FEBRABAN = 'FEBRABAN'; const TYPE_UPC_A = 'UPCA'; const TYPE_UPC_E = 'UPCE'; const TYPE_MSI = 'MSI'; // MSI (Variation of Plessey code) @@ -136,6 +138,9 @@ protected function createDataBuilderForType(string $type) case self::TYPE_INTERLEAVED_2_5_CHECKSUM: return new TypeInterleaved25Checksum(); + case self::TYPE_FEBRABAN: + return new TypeFebraban(); + case self::TYPE_CODE_128: return new TypeCode128(); diff --git a/src/Types/TypeFebraban.php b/src/Types/TypeFebraban.php new file mode 100644 index 0000000..d6ba6c7 --- /dev/null +++ b/src/Types/TypeFebraban.php @@ -0,0 +1,91 @@ +getChecksum($code); + + if ((strlen($code) % 2) != 0) { + // add leading zero if code-length is odd + $code = '0' . $code; + } + // add start and stop codes + $code = 'AA' . strtolower($code) . 'ZA'; + + $barcode = new Barcode($code); + for ($i = 0; $i < strlen($code); $i = ($i + 2)) { + $char_bar = $code[$i]; + $char_space = $code[$i + 1]; + if (! isset($chr[$char_bar]) || ! isset($chr[$char_space])) { + throw new InvalidCharacterException(); + } + + // create a bar-space sequence + $seq = ''; + $chrlen = strlen($chr[$char_bar]); + for ($s = 0; $s < $chrlen; $s++) { + $seq .= $chr[$char_bar][$s] . $chr[$char_space][$s]; + } + + for ($j = 0; $j < strlen($seq); ++$j) { + if (($j % 2) == 0) { + $t = true; // bar + } else { + $t = false; // space + } + $w = $seq[$j]; + $barcode->addBar(new BarcodeBar($w, 1, $t)); + } + } + + return $barcode; + } + + protected function getChecksum($code = "123"): string + { + + return ''; + } +}