From 7ea0b17a6a82fdba69a1cd98b42b0e8217e900ba Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 21 Feb 2016 14:17:06 +0100 Subject: [PATCH] Fixing C128c bug (checksum) and adding future member variables --- Utils/Barcode/C128Abstract.php | 5 +++++ Utils/Barcode/C128c.php | 10 ++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Utils/Barcode/C128Abstract.php b/Utils/Barcode/C128Abstract.php index 58b238c68..e9af78240 100644 --- a/Utils/Barcode/C128Abstract.php +++ b/Utils/Barcode/C128Abstract.php @@ -15,7 +15,12 @@ abstract class C128Abstract protected $orientation = 0; protected $size = 0; + protected $dimension = ['width' => 0, 'height' => 0]; protected $content = 0; + protected $showText = true; + protected $margin = ['top' => 0.0, 'right' => 0.0, 'bottom' => 0.0, 'left' => 0.0]; + protected $background = ['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]; + protected $front = ['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]; public function __construct(string $content = '', int $size = 20, int $orientation = 0) { diff --git a/Utils/Barcode/C128c.php b/Utils/Barcode/C128c.php index 1668671e3..fe86d835d 100644 --- a/Utils/Barcode/C128c.php +++ b/Utils/Barcode/C128c.php @@ -2,10 +2,6 @@ namespace phpOMS\Utils\Barcode; -/** - * Class C128c - * @fixme: here is still a small error. It has a minor deviation to a correct 128c code. WHY? - */ class C128c extends C128Abstract { protected static $CHECKSUM = 105; @@ -34,7 +30,7 @@ class C128c extends C128Abstract protected static $CODE_START = '211232'; - protected static $CODE_END = '2331112'; + protected static $CODE_END = '2331112'; protected function generateCodeString() { @@ -43,6 +39,7 @@ class C128c extends C128Abstract $codeString = ''; $length = strlen($this->content); $checksum = self::$CHECKSUM; + $checkPos = 1; for ($pos = 1; $pos <= $length; $pos += 2) { if ($pos + 1 <= $length) { @@ -52,7 +49,8 @@ class C128c extends C128Abstract } $codeString .= self::$CODEARRAY[$activeKey]; - $checksum = ($checksum + ($values[$activeKey] * $pos)); + $checksum = ($checksum + ($values[$activeKey] * $checkPos)); + $checkPos++; } $codeString .= self::$CODEARRAY[$keys[($checksum - (intval($checksum / 103) * 103))]];