diff --git a/composer.json b/composer.json index d0de475..bb87c7c 100644 --- a/composer.json +++ b/composer.json @@ -13,26 +13,27 @@ } }, "require": { - "php": ">=5.3.3", + "php": ">=5.3.23", "zendframework/zend-stdlib": "self.version", "zendframework/zend-validator": "self.version" }, "require-dev": { "zendframework/zend-servicemanager": "self.version", "zendframework/zendpdf": "*", + "zendframework/zend-validator": "self.version", "fabpot/php-cs-fixer": "1.7.*", "satooshi/php-coveralls": "dev-master", "phpunit/PHPUnit": "~4.0" }, "suggest": { - "zendframework/zend-servicemanager": "Zend\\ServiceManager component, required when using the factory methods of Zend\\Barcode.", + "zendframework/zend-servicemanager": "Zend\\ServiceManager component", "zendframework/zendpdf": "ZendPdf component", "zendframework/zend-validator": "Zend\\Validator component" }, "extra": { "branch-alias": { - "dev-master": "2.2-dev", - "dev-develop": "2.3-dev" + "dev-master": "2.3-dev", + "dev-develop": "2.4-dev" } }, "autoload-dev": { diff --git a/src/Barcode.php b/src/Barcode.php index 20516db..de4d9c5 100644 --- a/src/Barcode.php +++ b/src/Barcode.php @@ -182,7 +182,7 @@ public static function makeBarcode($barcode, $barcodeConfig = array()) } /* - * Verify that an barcode name has been specified. + * Verify that a barcode name has been specified. */ if (!is_string($barcode) || empty($barcode)) { throw new Exception\InvalidArgumentException( @@ -234,7 +234,7 @@ public static function makeRenderer($renderer = 'image', $rendererConfig = array } /* - * Verify that an barcode name has been specified. + * Verify that a barcode name has been specified. */ if (!is_string($renderer) || empty($renderer)) { throw new Exception\RendererCreationException( diff --git a/src/Object/AbstractObject.php b/src/Object/AbstractObject.php index 0fcf772..497108e 100644 --- a/src/Object/AbstractObject.php +++ b/src/Object/AbstractObject.php @@ -800,7 +800,7 @@ protected function addPolygon(array $points, $color = null, $filled = true) * Add a text drawing instruction in the set of instructions * @param string $text * @param float $size - * @param array $position + * @param int[] $position * @param string $font * @param int $color * @param string $alignment @@ -844,6 +844,7 @@ public function checkParams() /** * Check if a text is really provided to barcode + * @param string|null $value * @return void * @throws \Zend\Barcode\Object\Exception\ExceptionInterface */ @@ -1026,7 +1027,7 @@ public function getOffsetTop($recalculate = false) * Apply rotation on a point in X/Y dimensions * @param float $x1 x-position before rotation * @param float $y1 y-position before rotation - * @return array Array of two elements corresponding to the new XY point + * @return int[] Array of two elements corresponding to the new XY point */ protected function rotate($x1, $y1) { diff --git a/src/Object/Codabar.php b/src/Object/Codabar.php index 56a2b9e..351dcc8 100644 --- a/src/Object/Codabar.php +++ b/src/Object/Codabar.php @@ -62,6 +62,7 @@ protected function checkSpecificParams() protected function prepareBarcode() { $text = str_split($this->getText()); + $barcodeTable = array(); foreach ($text as $char) { $barcodeChar = str_split($this->codingMap[$char]); foreach ($barcodeChar as $c) { diff --git a/src/Object/Code128.php b/src/Object/Code128.php index 9e83d81..182bedd 100644 --- a/src/Object/Code128.php +++ b/src/Object/Code128.php @@ -208,9 +208,9 @@ protected function convertToBarcodeChars($string) $currentCharset = null; $result = array(); - for ($pos = 0; $pos < strlen($string); $pos++) { + $strlen = strlen($string); + for ($pos = 0; $pos < $strlen; $pos++) { $char = $string[$pos]; - $code = null; if (static::_isDigit($string, $pos, 4) && $currentCharset != 'C' || static::_isDigit($string, $pos, 2) && $currentCharset == 'C') { @@ -247,7 +247,7 @@ protected function convertToBarcodeChars($string) if ($pos == 0) { $code = array_search("START A", $this->charSets['A']); } else { - $code =array_search("Code A", $this->charSets[$currentCharset]); + $code = array_search("Code A", $this->charSets[$currentCharset]); } $result[] = $code; $currentCharset = 'A'; diff --git a/src/Object/Code25interleaved.php b/src/Object/Code25interleaved.php index ec8624d..0fb3ec3 100644 --- a/src/Object/Code25interleaved.php +++ b/src/Object/Code25interleaved.php @@ -73,6 +73,8 @@ protected function prepareBarcode() $this->withBorder = false; } + $barcodeTable = array(); + // Start character (0000) $barcodeTable[] = array(1, $this->barThinWidth, 0, 1); $barcodeTable[] = array(0, $this->barThinWidth, 0, 1); diff --git a/src/Object/Ean5.php b/src/Object/Ean5.php index a285ef5..5828c20 100644 --- a/src/Object/Ean5.php +++ b/src/Object/Ean5.php @@ -104,6 +104,10 @@ public function getChecksum($text) return ($checksum % 10); } + /** + * @param int $i + * @return string + */ protected function getParity($i) { $checksum = $this->getChecksum($this->getText()); diff --git a/src/Object/Identcode.php b/src/Object/Identcode.php index 14d50e6..a2b7fd3 100644 --- a/src/Object/Identcode.php +++ b/src/Object/Identcode.php @@ -40,7 +40,7 @@ public function getTextToDisplay() * Check allowed characters * @param string $value * @return string - * @throws Exception + * @throws Exception\BarcodeValidationException */ public function validateText($value) { diff --git a/src/Renderer/AbstractRenderer.php b/src/Renderer/AbstractRenderer.php index d70f04e..df65748 100644 --- a/src/Renderer/AbstractRenderer.php +++ b/src/Renderer/AbstractRenderer.php @@ -79,6 +79,12 @@ abstract class AbstractRenderer implements RendererInterface */ protected $resource; + /** + * Show a transparent background + * @var Boolean + */ + protected $transparentBackground = false; + /** * Constructor * @param array|Traversable $options @@ -135,6 +141,28 @@ public function getRendererNamespace() return $this->rendererNamespace; } + /** + * Set whether background should be transparent + * Will work for SVG and Image (png and gif only) + * + * @param $bool + * @return $this + */ + public function setTransparentBackground($bool) + { + $this->transparentBackground = $bool; + + return $this; + } + + /** + * @return bool + */ + public function getTransparentBackground() + { + return $this->transparentBackground; + } + /** * Retrieve renderer type * @return string diff --git a/src/Renderer/Image.php b/src/Renderer/Image.php index c59be39..f00b5f3 100644 --- a/src/Renderer/Image.php +++ b/src/Renderer/Image.php @@ -22,8 +22,8 @@ class Image extends AbstractRenderer * @var array */ protected $allowedImageType = array('png', - 'jpeg', - 'gif' ); + 'jpeg', + 'gif' ); /** * Image format @@ -194,22 +194,7 @@ protected function initRenderer() $barcodeWidth = $this->barcode->getWidth(true); $barcodeHeight = $this->barcode->getHeight(true); - if ($this->resource !== null) { - $foreColor = $this->barcode->getForeColor(); - $backgroundColor = $this->barcode->getBackgroundColor(); - $this->imageBackgroundColor = imagecolorallocate( - $this->resource, - ($backgroundColor & 0xFF0000) >> 16, - ($backgroundColor & 0x00FF00) >> 8, - $backgroundColor & 0x0000FF - ); - $this->imageForeColor = imagecolorallocate( - $this->resource, - ($foreColor & 0xFF0000) >> 16, - ($foreColor & 0x00FF00) >> 8, - $foreColor & 0x0000FF - ); - } else { + if (null === $this->resource) { $width = $barcodeWidth; $height = $barcodeHeight; if ($this->userWidth && $this->barcode->getType() != 'error') { @@ -219,32 +204,44 @@ protected function initRenderer() $height = $this->userHeight; } - $foreColor = $this->barcode->getForeColor(); - $backgroundColor = $this->barcode->getBackgroundColor(); $this->resource = imagecreatetruecolor($width, $height); - $this->imageBackgroundColor = imagecolorallocate( - $this->resource, - ($backgroundColor & 0xFF0000) >> 16, - ($backgroundColor & 0x00FF00) >> 8, - $backgroundColor & 0x0000FF - ); - $this->imageForeColor = imagecolorallocate( - $this->resource, - ($foreColor & 0xFF0000) >> 16, - ($foreColor & 0x00FF00) >> 8, - $foreColor & 0x0000FF - ); $white = imagecolorallocate($this->resource, 255, 255, 255); imagefilledrectangle($this->resource, 0, 0, $width - 1, $height - 1, $white); } + + $foreColor = $this->barcode->getForeColor(); + $this->imageForeColor = imagecolorallocate( + $this->resource, + ($foreColor & 0xFF0000) >> 16, + ($foreColor & 0x00FF00) >> 8, + $foreColor & 0x0000FF + ); + + $backgroundColor = $this->barcode->getBackgroundColor(); + $this->imageBackgroundColor = imagecolorallocate( + $this->resource, + ($backgroundColor & 0xFF0000) >> 16, + ($backgroundColor & 0x00FF00) >> 8, + $backgroundColor & 0x0000FF + ); + + // JPEG does not support transparency, if transparentBackground is true and + // image type is JPEG, ignore transparency + if($this->getImageType() != "jpeg" && $this->transparentBackground) { + imagecolortransparent($this->resource, $this->imageBackgroundColor); + } + $this->adjustPosition(imagesy($this->resource), imagesx($this->resource)); - imagefilledrectangle($this->resource, - $this->leftOffset, - $this->topOffset, - $this->leftOffset + $barcodeWidth - 1, - $this->topOffset + $barcodeHeight - 1, - $this->imageBackgroundColor); + + imagefilledrectangle( + $this->resource, + $this->leftOffset, + $this->topOffset, + $this->leftOffset + $barcodeWidth - 1, + $this->topOffset + $barcodeHeight - 1, + $this->imageBackgroundColor + ); } /** @@ -330,18 +327,18 @@ public function render() protected function drawPolygon($points, $color, $filled = true) { $newPoints = array($points[0][0] + $this->leftOffset, - $points[0][1] + $this->topOffset, - $points[1][0] + $this->leftOffset, - $points[1][1] + $this->topOffset, - $points[2][0] + $this->leftOffset, - $points[2][1] + $this->topOffset, - $points[3][0] + $this->leftOffset, - $points[3][1] + $this->topOffset, ); + $points[0][1] + $this->topOffset, + $points[1][0] + $this->leftOffset, + $points[1][1] + $this->topOffset, + $points[2][0] + $this->leftOffset, + $points[2][1] + $this->topOffset, + $points[3][0] + $this->leftOffset, + $points[3][1] + $this->topOffset, ); $allocatedColor = imagecolorallocate($this->resource, - ($color & 0xFF0000) >> 16, - ($color & 0x00FF00) >> 8, - $color & 0x0000FF ); + ($color & 0xFF0000) >> 16, + ($color & 0x00FF00) >> 8, + $color & 0x0000FF ); if ($filled) { imagefilledpolygon($this->resource, $newPoints, 4, $allocatedColor); @@ -365,9 +362,9 @@ protected function drawPolygon($points, $color, $filled = true) protected function drawText($text, $size, $position, $font, $color, $alignment = 'center', $orientation = 0) { $allocatedColor = imagecolorallocate($this->resource, - ($color & 0xFF0000) >> 16, - ($color & 0x00FF00) >> 8, - $color & 0x0000FF ); + ($color & 0xFF0000) >> 16, + ($color & 0x00FF00) >> 8, + $color & 0x0000FF ); if ($font == null) { $font = 3; @@ -422,13 +419,13 @@ protected function drawText($text, $size, $position, $font, $color, $alignment = break; } imagettftext($this->resource, - $size, - $orientation, - $position[0] - ($width * cos(pi() * $orientation / 180)), - $position[1] + ($width * sin(pi() * $orientation / 180)), - $allocatedColor, - $font, - $text); + $size, + $orientation, + $position[0] - ($width * cos(pi() * $orientation / 180)), + $position[1] + ($width * sin(pi() * $orientation / 180)), + $allocatedColor, + $font, + $text); } } } diff --git a/src/Renderer/Pdf.php b/src/Renderer/Pdf.php index b44cadf..e4e084d 100644 --- a/src/Renderer/Pdf.php +++ b/src/Renderer/Pdf.php @@ -104,6 +104,8 @@ protected function initRenderer() protected function drawPolygon($points, $color, $filled = true) { $page = $this->resource->pages[$this->page]; + $x = array(); + $y = array(); foreach ($points as $point) { $x[] = $point[0] * $this->moduleSize + $this->leftOffset; $y[] = $page->getHeight() - $point[1] * $this->moduleSize - $this->topOffset; diff --git a/src/Renderer/RendererInterface.php b/src/Renderer/RendererInterface.php index db162df..795654f 100644 --- a/src/Renderer/RendererInterface.php +++ b/src/Renderer/RendererInterface.php @@ -79,6 +79,7 @@ public function getLeftOffset(); /** * Activate/Deactivate the automatic rendering of exception * @param bool $value + * @return self */ public function setAutomaticRenderError($value); diff --git a/src/Renderer/Svg.php b/src/Renderer/Svg.php index b05d140..301eaa1 100644 --- a/src/Renderer/Svg.php +++ b/src/Renderer/Svg.php @@ -43,6 +43,13 @@ class Svg extends AbstractRenderer */ protected $userWidth = 0; + + /** + * Flag to determime if drawPolygon has been run once already + * @var bool + */ + protected $drawPolygonExecuted = false; + /** * Set height of the result image * @param null|int $value @@ -152,12 +159,17 @@ protected function initRenderer() } $this->adjustPosition($height, $width); - $this->appendRootElement('rect', - array('x' => $this->leftOffset, - 'y' => $this->topOffset, - 'width' => ($this->leftOffset + $barcodeWidth - 1), - 'height' => ($this->topOffset + $barcodeHeight - 1), - 'fill' => $imageBackgroundColor)); + $rect = array('x' => $this->leftOffset, + 'y' => $this->topOffset, + 'width' => ($this->leftOffset + $barcodeWidth - 1), + 'height' => ($this->topOffset + $barcodeHeight - 1), + 'fill' => $imageBackgroundColor); + + if($this->transparentBackground) { + $rect['fill-opacity'] = 0; + } + + $this->appendRootElement('rect', $rect); } protected function readRootElement() @@ -262,7 +274,7 @@ protected function checkDimensions() /** * Draw the barcode in the rendering resource - * @return mixed + * @return DOMDocument */ public function draw() { @@ -307,8 +319,19 @@ protected function drawPolygon($points, $color, $filled = true) $points[3][1] + $this->topOffset - sin($orientation), ); $newPoints = implode(' ', $newPoints); + $attributes = array(); $attributes['points'] = $newPoints; $attributes['fill'] = $color; + + // SVG passes a rect in as the first call to drawPolygon, we'll need to intercept + // this and set transparency if necessary. + if(!$this->drawPolygonExecuted) { + if($this->transparentBackground) { + $attributes['fill-opacity'] = '0'; + } + $this->drawPolygonExecuted = true; + } + $this->appendRootElement('polygon', $attributes); } @@ -328,6 +351,7 @@ protected function drawText($text, $size, $position, $font, $color, $alignment = $color = 'rgb(' . implode(', ', array(($color & 0xFF0000) >> 16, ($color & 0x00FF00) >> 8, ($color & 0x0000FF))) . ')'; + $attributes = array(); $attributes['x'] = $position[0] + $this->leftOffset; $attributes['y'] = $position[1] + $this->topOffset; //$attributes['font-family'] = $font; diff --git a/test/FactoryTest.php b/test/FactoryTest.php index 107fcd9..092767f 100644 --- a/test/FactoryTest.php +++ b/test/FactoryTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/CodabarTest.php b/test/Object/CodabarTest.php index 5c58894..884abf7 100644 --- a/test/Object/CodabarTest.php +++ b/test/Object/CodabarTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/Code128Test.php b/test/Object/Code128Test.php index 5a2eb0e..29a8d64 100644 --- a/test/Object/Code128Test.php +++ b/test/Object/Code128Test.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/Code25Test.php b/test/Object/Code25Test.php index 72fe750..5631cbf 100644 --- a/test/Object/Code25Test.php +++ b/test/Object/Code25Test.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/Code25interleavedTest.php b/test/Object/Code25interleavedTest.php index c360635..e4b3cde 100644 --- a/test/Object/Code25interleavedTest.php +++ b/test/Object/Code25interleavedTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/Code39Test.php b/test/Object/Code39Test.php index afde3e4..d4f8770 100644 --- a/test/Object/Code39Test.php +++ b/test/Object/Code39Test.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/Ean13Test.php b/test/Object/Ean13Test.php index c785f53..73d36bc 100644 --- a/test/Object/Ean13Test.php +++ b/test/Object/Ean13Test.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/Ean2Test.php b/test/Object/Ean2Test.php index 4de362e..091d132 100644 --- a/test/Object/Ean2Test.php +++ b/test/Object/Ean2Test.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/Ean5Test.php b/test/Object/Ean5Test.php index b41358d..03bfe38 100644 --- a/test/Object/Ean5Test.php +++ b/test/Object/Ean5Test.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/Ean8Test.php b/test/Object/Ean8Test.php index c598df5..6a9251e 100644 --- a/test/Object/Ean8Test.php +++ b/test/Object/Ean8Test.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/ErrorTest.php b/test/Object/ErrorTest.php index c83af9f..ceb3c12 100644 --- a/test/Object/ErrorTest.php +++ b/test/Object/ErrorTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/IdentcodeTest.php b/test/Object/IdentcodeTest.php index 5a205eb..6e71449 100644 --- a/test/Object/IdentcodeTest.php +++ b/test/Object/IdentcodeTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/Itf14Test.php b/test/Object/Itf14Test.php index 81347d7..ad6591c 100644 --- a/test/Object/Itf14Test.php +++ b/test/Object/Itf14Test.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/LeitcodeTest.php b/test/Object/LeitcodeTest.php index bfef457..24727f1 100644 --- a/test/Object/LeitcodeTest.php +++ b/test/Object/LeitcodeTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/PlanetTest.php b/test/Object/PlanetTest.php index bb06e77..5aab3e7 100644 --- a/test/Object/PlanetTest.php +++ b/test/Object/PlanetTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/PostnetTest.php b/test/Object/PostnetTest.php index 1955b46..43d69cc 100644 --- a/test/Object/PostnetTest.php +++ b/test/Object/PostnetTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/RoyalmailTest.php b/test/Object/RoyalmailTest.php index aff754c..16958c1 100644 --- a/test/Object/RoyalmailTest.php +++ b/test/Object/RoyalmailTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/TestAsset/BarcodeNamespace.php b/test/Object/TestAsset/BarcodeNamespace.php index eb59ac7..f519cc8 100644 --- a/test/Object/TestAsset/BarcodeNamespace.php +++ b/test/Object/TestAsset/BarcodeNamespace.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/TestAsset/BarcodeNamespaceWithoutExtendingObjectAbstract.php b/test/Object/TestAsset/BarcodeNamespaceWithoutExtendingObjectAbstract.php index e095def..5968728 100644 --- a/test/Object/TestAsset/BarcodeNamespaceWithoutExtendingObjectAbstract.php +++ b/test/Object/TestAsset/BarcodeNamespaceWithoutExtendingObjectAbstract.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/TestAsset/BarcodeTest.php b/test/Object/TestAsset/BarcodeTest.php index c960d5c..1e28543 100644 --- a/test/Object/TestAsset/BarcodeTest.php +++ b/test/Object/TestAsset/BarcodeTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/TestAsset/Code128Test.php b/test/Object/TestAsset/Code128Test.php index 32ffb67..312768d 100644 --- a/test/Object/TestAsset/Code128Test.php +++ b/test/Object/TestAsset/Code128Test.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/TestAsset/Error.php b/test/Object/TestAsset/Error.php index 6c30e22..eeec998 100644 --- a/test/Object/TestAsset/Error.php +++ b/test/Object/TestAsset/Error.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/TestCommon.php b/test/Object/TestCommon.php index 9b82aec..a3f83e1 100644 --- a/test/Object/TestCommon.php +++ b/test/Object/TestCommon.php @@ -3,20 +3,19 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Barcode\Object; -use ZendTest\Barcode\Object\TestAsset; use Zend\Barcode; use Zend\Config; abstract class TestCommon extends \PHPUnit_Framework_TestCase { /** - * @var \Zend\Barcode\BarcodeObject + * @var \Zend\Barcode\Object\AbstractObject */ protected $object = null; diff --git a/test/Object/UpcaTest.php b/test/Object/UpcaTest.php index 14e62e3..95e7bbb 100644 --- a/test/Object/UpcaTest.php +++ b/test/Object/UpcaTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Object/UpceTest.php b/test/Object/UpceTest.php index 34c0e73..7ce3aa3 100644 --- a/test/Object/UpceTest.php +++ b/test/Object/UpceTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Renderer/ImageTest.php b/test/Renderer/ImageTest.php index 0f1ecca..99a4e75 100644 --- a/test/Renderer/ImageTest.php +++ b/test/Renderer/ImageTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -276,6 +276,78 @@ public function testTopOffsetOverrideVerticalPosition() parent::testTopOffsetOverrideVerticalPosition(); } + /** + * @group 4708 + */ + public function testImageGifWithNoTransparency() + { + $barcode = new Object\Code39(array('text' => '0123456789')); + $this->renderer->setBarcode($barcode); + + $this->renderer->setTransparentBackground(false); + $this->assertFalse($this->renderer->getTransparentBackground()); + + //Test Gif output + $this->renderer->setImageType('gif'); + $image = $this->renderer->draw(); + $index = imagecolortransparent($image); + $this->assertEquals($index, -1); + } + + /** + * @group 4708 + */ + public function testImagePngWithNoTransparency() + { + $barcode = new Object\Code39(array('text' => '0123456789')); + $this->renderer->setBarcode($barcode); + + $this->renderer->setTransparentBackground(false); + $this->assertFalse($this->renderer->getTransparentBackground()); + + //Test PNG output + $this->renderer->setImageType('png'); + $image = $this->renderer->draw(); + $index = imagecolortransparent($image); + $this->assertEquals($index, -1); + } + + /** + * @group 4708 + */ + public function testImageGifWithTransparency() + { + $barcode = new Object\Code39(array('text' => '0123456789')); + $this->renderer->setBarcode($barcode); + + $this->renderer->setTransparentBackground(true); + $this->assertTrue($this->renderer->getTransparentBackground()); + + //Test Gif output + $this->renderer->setImageType('gif'); + $image = $this->renderer->draw(); + $index = imagecolortransparent($image); + $this->assertTrue($index !== -1); + } + + /** + * @group 4708 + */ + public function testImagePngWithTransparency() + { + $barcode = new Object\Code39(array('text' => '0123456789')); + $this->renderer->setBarcode($barcode); + + $this->renderer->setTransparentBackground(true); + $this->assertTrue($this->renderer->getTransparentBackground()); + + //Test PNG output + $this->renderer->setImageType('png'); + $image = $this->renderer->draw(); + $index = imagecolortransparent($image); + $this->assertTrue($index !== -1); + } + protected function checkTTFRequirement() { if (!function_exists('imagettfbbox')) { diff --git a/test/Renderer/PdfTest.php b/test/Renderer/PdfTest.php index 51349e1..c870891 100644 --- a/test/Renderer/PdfTest.php +++ b/test/Renderer/PdfTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Renderer/SvgTest.php b/test/Renderer/SvgTest.php index 4d7fa6c..30fc344 100644 --- a/test/Renderer/SvgTest.php +++ b/test/Renderer/SvgTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -24,6 +24,42 @@ protected function getRendererObject($options = null) return new Svg($options); } + /** + * @group 4708 + * + * Needs to be run first due to runOnce static on drawPolygon + */ + public function testSvgNoTransparency() + { + $svgCompare = file_get_contents(__DIR__ . '/_files/svg_transparency.xml'); + + Barcode\Barcode::setBarcodeFont(__DIR__ . '/../Object/_fonts/Vera.ttf'); + $barcode = new Code39(array('text' => '0123456789')); + $this->renderer->setBarcode($barcode); + + $this->assertFalse($this->renderer->getTransparentBackground()); + $svgOutput = $this->renderer->draw()->saveXML(); + $this->assertNotEquals($svgCompare, $svgOutput); + } + + /** + * @group 4708 + * + * Needs to be run first due to runOnce static on drawPolygon + */ + public function testSvgTransparency() + { + $svgCompare = file_get_contents(__DIR__ . '/_files/svg_transparency.xml'); + + Barcode\Barcode::setBarcodeFont(__DIR__ . '/../Object/_fonts/Vera.ttf'); + $barcode = new Code39(array('text' => '0123456789')); + $this->renderer->setBarcode($barcode); + $this->renderer->setTransparentBackground(true); + $this->assertTrue($this->renderer->getTransparentBackground()); + $svgOutput = $this->renderer->draw()->saveXML(); + $this->assertEquals($svgCompare, $svgOutput); + } + public function testType() { $this->assertSame('svg', $this->renderer->getType()); @@ -105,4 +141,5 @@ protected function getRendererWithWidth500AndHeight300() $svg->appendChild($rootElement); return $this->renderer->setResource($svg); } + } diff --git a/test/Renderer/TestAsset/RendererNamespace.php b/test/Renderer/TestAsset/RendererNamespace.php index 1284024..be8cfc3 100644 --- a/test/Renderer/TestAsset/RendererNamespace.php +++ b/test/Renderer/TestAsset/RendererNamespace.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Renderer/TestAsset/RendererNamespaceWithoutExtendingRendererAbstract.php b/test/Renderer/TestAsset/RendererNamespaceWithoutExtendingRendererAbstract.php index 71e72c4..9873257 100644 --- a/test/Renderer/TestAsset/RendererNamespaceWithoutExtendingRendererAbstract.php +++ b/test/Renderer/TestAsset/RendererNamespaceWithoutExtendingRendererAbstract.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Renderer/TestCommon.php b/test/Renderer/TestCommon.php index bdf50c5..e6fc654 100644 --- a/test/Renderer/TestCommon.php +++ b/test/Renderer/TestCommon.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Renderer/_files/svg_transparency.xml b/test/Renderer/_files/svg_transparency.xml new file mode 100644 index 0000000..ce946b7 --- /dev/null +++ b/test/Renderer/_files/svg_transparency.xml @@ -0,0 +1,67 @@ + + + Barcode CODE39 *0123456789* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + *0123456789* +