From c1626b23e18db54b93d68585c69cf7bbaf504f1f Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Wed, 30 Oct 2013 10:10:05 -0700 Subject: [PATCH 01/10] removing alpha as it's not used --- src/Renderer/Image.php | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/Renderer/Image.php b/src/Renderer/Image.php index 8c6f42a..1acbdf7 100644 --- a/src/Renderer/Image.php +++ b/src/Renderer/Image.php @@ -61,12 +61,6 @@ class Image extends AbstractRenderer */ protected $userWidth = 0; - /** - * The alpha value of the background - * @var int - */ - protected $alpha = 100; - /** * Constructor * @@ -156,24 +150,6 @@ public function setResource($image) return $this; } - public function setAlpha($alpha) - { - $alpha = (int) $alpha; - if($alpha < 0 || $alpha > 100) { - throw new Exception\InvalidArgumentException( - 'Invalid alpha valueprovided to setAlpha(), value must be between 0 (transparent) and 100 (opaque)' - ); - } - $this->alpha = $alpha; - - return $this; - } - - public function getAlpha() - { - return $this->alpha; - } - /** * Set the image type to produce (png, jpeg, gif) * From 449776ff93f3b8cc89de58c37d7eb7472602941c Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Sat, 15 Feb 2014 12:56:58 -0800 Subject: [PATCH 02/10] Resolves zendframework/zf2#4708 - added unit tests --- test/Renderer/ImageTest.php | 36 ++++++++++ test/Renderer/SvgTest.php | 20 ++++++ test/Renderer/_files/svg_transparency.xml | 67 +++++++++++++++++++ test/Renderer/_files/transparent_barcode.gif | Bin 0 -> 2379 bytes test/Renderer/_files/transparent_barcode.png | Bin 0 -> 1868 bytes 5 files changed, 123 insertions(+) create mode 100644 test/Renderer/_files/svg_transparency.xml create mode 100644 test/Renderer/_files/transparent_barcode.gif create mode 100644 test/Renderer/_files/transparent_barcode.png diff --git a/test/Renderer/ImageTest.php b/test/Renderer/ImageTest.php index 0f1ecca..18a4b59 100644 --- a/test/Renderer/ImageTest.php +++ b/test/Renderer/ImageTest.php @@ -276,6 +276,42 @@ public function testTopOffsetOverrideVerticalPosition() parent::testTopOffsetOverrideVerticalPosition(); } + /** + * @group 4708 + */ + public function testImageTransparency() + { + $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(); + + ob_start(); + imagepng($image); + $imageData = ob_get_contents(); + ob_end_clean(); + + $this->assertEquals(md5($imageData), md5_file(__DIR__ . "/_files/transparent_barcode.png")); + + //Test GIF output + $this->renderer->setImageType('gif'); + $image = $this->renderer->draw(); + + ob_start(); + imagegif($image); + $imageData = ob_get_contents(); + ob_end_clean(); + + $this->assertEquals(md5($imageData), md5_file(__DIR__ . "/_files/transparent_barcode.gif")); + } + + + protected function checkTTFRequirement() { if (!function_exists('imagettfbbox')) { diff --git a/test/Renderer/SvgTest.php b/test/Renderer/SvgTest.php index 4d7fa6c..884b1fc 100644 --- a/test/Renderer/SvgTest.php +++ b/test/Renderer/SvgTest.php @@ -94,6 +94,25 @@ public function testDrawWithExistantResourceReturnResource() Barcode\Barcode::setBarcodeFont(''); } + /** + * @group 4708 + */ + public function testSvgTransparency() + { + Barcode\Barcode::setBarcodeFont(__DIR__ . '/../Object/_fonts/Vera.ttf'); + $barcode = new Code39(array('text' => '0123456789')); + $this->renderer->setBarcode($barcode); + $this->assertFalse($this->renderer->getTransparentBackground()); + + $this->renderer->setTransparentBackground(true); + $this->assertTrue($this->renderer->getTransparentBackground()); + + //test svg return value + $xml = $this->renderer->draw()->saveXML(); + $this->assertEquals(md5($xml), md5_file(__DIR__ . '/_files/svg_transparency.xml')); + } + + protected function getRendererWithWidth500AndHeight300() { $svg = new \DOMDocument(); @@ -105,4 +124,5 @@ protected function getRendererWithWidth500AndHeight300() $svg->appendChild($rootElement); return $this->renderer->setResource($svg); } + } 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* + diff --git a/test/Renderer/_files/transparent_barcode.gif b/test/Renderer/_files/transparent_barcode.gif new file mode 100644 index 0000000000000000000000000000000000000000..080b21e9c35845b1c607458555ee8480b4b4a036 GIT binary patch literal 2379 zcmdUti9gf-1IOQ=ZMM-`%bjDEq#Q|^0iUujPk^gwFk(!^z+h;}e}6oqD=@^mX+s zD=LEmf+SNCH5IkIoIHvLMKmI^+;7?3)Xa!vtSqgd&?r_c%g)|T*e=x4)+#P7_NDoX zzlr4)<p}FMIS2^ed|>gDwS0rX^}b zwY+q*`u#A(DR8*Fok^5H(?|x==605Q4X8k>G zMM+zIRe51+3h#;VQE6>nQC-8Us+#`Fcz$Ke)5q_d-*xwP2w&6=x3`Uty!j^j^l+wk zVEXCouTk;X*n^%CLHA&lwA$Na>bm|&hgHuqgPdljWNb?)+PSdx(n>q8U%AhN$7=10 z_AompYPyX#E=`!g-EqiRG?-$(`$=%f1dAD=S7i(9U>((Y;n3{~e*C767otP`pPss@ zfB!>dKIr|DvF~cBR>j=c4!XkqU90o|i2GTn!YS5ay4WpY&HW}(?08JGw|KhULnbhM z$J;Eo+iqc__&}HZ>!;U(&3TI6CnHU*>OJHQKGrdZWKRV)l!=6{?)HIB?=Fj5E@ZeR zN7hlk)vMaHTQ9hW`8Q7_nq-7WKAOti5iNV*#J2uktF8=V} zH{g3bNqfw9>C>rxcjBt)Sny2PX|L$I=q!yBV1IaFC~jWq6J4&>tuW+=I&G_e&!ow{ zIMtkS)eC|Le-6;M_DX43>FPRoC#bb@&pD;^Hn@kion4FD1`nLw`60d@njE|?evZ|Q z995ugOVgghUN~+&@=$?Uw1@vO?vS&?wp7o|g^^pAp|9_=4#bXYW*EvwY>#rU$Wpv^ zG&7<&%}S9=W73*B3vSrQpHWI({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cOubXQo*`x>lI&4)6TLB+ol)s5Wo!lYencgw%6ilnmh0-aHz>Ut%Ds z(6{(n-`{{XU(#fAkhy04t5+4be`bOqko1me&vLg+Dk_{vJVWONvfuw5mLtX(tE1*S zGt`agK2S<+%pja{(9IeKPD@L}M%n2wii`6y*#Sq4I<4i7(-AOFjjqqk0Xza_s!yXI zt&h>){%U+te#G3;a(wwtju>0@Ze^t={&_p#GzjE+A2fR0H=D#XS-*e2jbL|6*F^98 zuxtkhhm*P9RsQ2bp`r_FM9X|WUr#B)9Km9-GTc$ngKp6F=^D>+^7h()w?;=s@_NL= z$;m(Qwe}^;liYh)6Ol-CsO)q7<;xnEm`)2DJG`pQzS%q+=`UH5OQ}_1A5GtRgjlz? z=~QnZR|bOF0fx{af}KiQIGG&ud`cSo{_50qd;Y@O79dePYpAlCU^V~%6SQ=_ISUJm zAa+0{whCLN3-LOqTLAaC3|2|&=;)YvTFqrqsmg_Yf?>oUpilFv#9p&2=J9+MDA5TC w-*841<*64j`eyelDSK+*k1e Date: Sat, 15 Feb 2014 14:34:42 -0800 Subject: [PATCH 03/10] Resolves zendframework/zf2#4708 - updated tests for transparency to fix travis --- src/Renderer/Image.php | 2 +- test/Renderer/ImageTest.php | 91 +++++++++++++++---- test/Renderer/_files/transparent_barcode.gif | Bin 2379 -> 0 bytes test/Renderer/_files/transparent_barcode.png | Bin 1868 -> 0 bytes 4 files changed, 74 insertions(+), 19 deletions(-) delete mode 100644 test/Renderer/_files/transparent_barcode.gif delete mode 100644 test/Renderer/_files/transparent_barcode.png diff --git a/src/Renderer/Image.php b/src/Renderer/Image.php index 1acbdf7..ddaaf5a 100644 --- a/src/Renderer/Image.php +++ b/src/Renderer/Image.php @@ -426,4 +426,4 @@ protected function drawText($text, $size, $position, $font, $color, $alignment = $text); } } -} \ No newline at end of file +} diff --git a/test/Renderer/ImageTest.php b/test/Renderer/ImageTest.php index 18a4b59..98a6294 100644 --- a/test/Renderer/ImageTest.php +++ b/test/Renderer/ImageTest.php @@ -279,38 +279,74 @@ public function testTopOffsetOverrideVerticalPosition() /** * @group 4708 */ - public function testImageTransparency() + public function testImageGifWithNoTransparency() { $barcode = new Object\Code39(array('text' => '0123456789')); $this->renderer->setBarcode($barcode); - - $this->renderer->setTransparentBackground(true); - $this->assertTrue($this->renderer->getTransparentBackground()); + + $this->renderer->setTransparentBackground(false); + $this->assertFalse($this->renderer->getTransparentBackground()); //Test PNG output - $this->renderer->setImageType('png'); + $this->renderer->setImageType('gif'); $image = $this->renderer->draw(); - - ob_start(); - imagepng($image); - $imageData = ob_get_contents(); - ob_end_clean(); + $index = imagecolortransparent($image); + $this->assertEquals($index, -1); + } + + /** + * @group 4708 + */ + public function testImagePngWithNoTransparency() + { + $barcode = new Object\Code39(array('text' => '0123456789')); + $this->renderer->setBarcode($barcode); - $this->assertEquals(md5($imageData), md5_file(__DIR__ . "/_files/transparent_barcode.png")); + $this->renderer->setTransparentBackground(false); + $this->assertFalse($this->renderer->getTransparentBackground()); - //Test GIF output - $this->renderer->setImageType('gif'); + //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); - ob_start(); - imagegif($image); - $imageData = ob_get_contents(); - ob_end_clean(); + $this->renderer->setTransparentBackground(true); + $this->assertTrue($this->renderer->getTransparentBackground()); - $this->assertEquals(md5($imageData), md5_file(__DIR__ . "/_files/transparent_barcode.gif")); + //Test PNG 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() { @@ -318,4 +354,23 @@ protected function checkTTFRequirement() $this->markTestSkipped('TTF (FreeType) support is required in order to run this test'); } } + + protected function check_transparent($im) { + + $width = imagesx($im); // Get the width of the image + $height = imagesy($im); // Get the height of the image + + // We run the image pixel by pixel and as soon as we find a transparent pixel we stop and return true. + for($i = 0; $i < $width; $i++) { + for($j = 0; $j < $height; $j++) { + $rgba = imagecolorat($im, $i, $j); + if(($rgba & 0x7F000000) >> 24) { + return true; + } + } + } + + // If we dont find any pixel the function will return false. + return false; +} } diff --git a/test/Renderer/_files/transparent_barcode.gif b/test/Renderer/_files/transparent_barcode.gif deleted file mode 100644 index 080b21e9c35845b1c607458555ee8480b4b4a036..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2379 zcmdUti9gf-1IOQ=ZMM-`%bjDEq#Q|^0iUujPk^gwFk(!^z+h;}e}6oqD=@^mX+s zD=LEmf+SNCH5IkIoIHvLMKmI^+;7?3)Xa!vtSqgd&?r_c%g)|T*e=x4)+#P7_NDoX zzlr4)<p}FMIS2^ed|>gDwS0rX^}b zwY+q*`u#A(DR8*Fok^5H(?|x==605Q4X8k>G zMM+zIRe51+3h#;VQE6>nQC-8Us+#`Fcz$Ke)5q_d-*xwP2w&6=x3`Uty!j^j^l+wk zVEXCouTk;X*n^%CLHA&lwA$Na>bm|&hgHuqgPdljWNb?)+PSdx(n>q8U%AhN$7=10 z_AompYPyX#E=`!g-EqiRG?-$(`$=%f1dAD=S7i(9U>((Y;n3{~e*C767otP`pPss@ zfB!>dKIr|DvF~cBR>j=c4!XkqU90o|i2GTn!YS5ay4WpY&HW}(?08JGw|KhULnbhM z$J;Eo+iqc__&}HZ>!;U(&3TI6CnHU*>OJHQKGrdZWKRV)l!=6{?)HIB?=Fj5E@ZeR zN7hlk)vMaHTQ9hW`8Q7_nq-7WKAOti5iNV*#J2uktF8=V}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+qFyFJSGcvcrg;2jqg<^CIAkyGCO&8Ze63XXgCED}kyhT&skn!Hl?w(D>lEf2NG z57+H)*o#(IZ?ObKI~@c9Ar^~akxYpiNNB-)hX0e16B4Ym~9*$breW)5?;5@M+cb~gjtW-tj+cnNWYv} zG$jVG5=bOS{^4d;;5NFeEW@e_Dr7SHf9F+L%l{nl)76^!SZ>=%L^juRSj)jfu# z8%-hAdvh!H;p^r_j_cOubXQo*`x>lI&4)6TLB+ol)s5Wo!lYencgw%6ilnmh0-aHz>Ut%Ds z(6{(n-`{{XU(#fAkhy04t5+4be`bOqko1me&vLg+Dk_{vJVWONvfuw5mLtX(tE1*S zGt`agK2S<+%pja{(9IeKPD@L}M%n2wii`6y*#Sq4I<4i7(-AOFjjqqk0Xza_s!yXI zt&h>){%U+te#G3;a(wwtju>0@Ze^t={&_p#GzjE+A2fR0H=D#XS-*e2jbL|6*F^98 zuxtkhhm*P9RsQ2bp`r_FM9X|WUr#B)9Km9-GTc$ngKp6F=^D>+^7h()w?;=s@_NL= z$;m(Qwe}^;liYh)6Ol-CsO)q7<;xnEm`)2DJG`pQzS%q+=`UH5OQ}_1A5GtRgjlz? z=~QnZR|bOF0fx{af}KiQIGG&ud`cSo{_50qd;Y@O79dePYpAlCU^V~%6SQ=_ISUJm zAa+0{whCLN3-LOqTLAaC3|2|&=;)YvTFqrqsmg_Yf?>oUpilFv#9p&2=J9+MDA5TC w-*841<*64j`eyelDSK+*k1e Date: Sat, 15 Feb 2014 14:36:26 -0800 Subject: [PATCH 04/10] Resolves zendframework/zf2#4708 - remove method used for testing, different solution chosen. --- test/Renderer/ImageTest.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/test/Renderer/ImageTest.php b/test/Renderer/ImageTest.php index 98a6294..1cdcabd 100644 --- a/test/Renderer/ImageTest.php +++ b/test/Renderer/ImageTest.php @@ -354,23 +354,4 @@ protected function checkTTFRequirement() $this->markTestSkipped('TTF (FreeType) support is required in order to run this test'); } } - - protected function check_transparent($im) { - - $width = imagesx($im); // Get the width of the image - $height = imagesy($im); // Get the height of the image - - // We run the image pixel by pixel and as soon as we find a transparent pixel we stop and return true. - for($i = 0; $i < $width; $i++) { - for($j = 0; $j < $height; $j++) { - $rgba = imagecolorat($im, $i, $j); - if(($rgba & 0x7F000000) >> 24) { - return true; - } - } - } - - // If we dont find any pixel the function will return false. - return false; -} } From 2cd7e34a21e0c51b12d96c01f8ba5504cdb16368 Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Sat, 15 Feb 2014 14:54:01 -0800 Subject: [PATCH 05/10] Resolves zendframework/zf2#4708 - coding standards. --- test/Renderer/ImageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Renderer/ImageTest.php b/test/Renderer/ImageTest.php index 1cdcabd..c21a64b 100644 --- a/test/Renderer/ImageTest.php +++ b/test/Renderer/ImageTest.php @@ -346,7 +346,7 @@ public function testImagePngWithTransparency() $image = $this->renderer->draw(); $index = imagecolortransparent($image); $this->assertTrue($index !== -1); - } + } protected function checkTTFRequirement() { From b660ea6b5e931aad793e9559b662099b356cabac Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Sat, 15 Feb 2014 14:57:01 -0800 Subject: [PATCH 06/10] Resolves zendframework/zf2#4708 - change comparison for svg as well as this isn't working as intended. --- test/Renderer/SvgTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/Renderer/SvgTest.php b/test/Renderer/SvgTest.php index 884b1fc..6226258 100644 --- a/test/Renderer/SvgTest.php +++ b/test/Renderer/SvgTest.php @@ -108,8 +108,10 @@ public function testSvgTransparency() $this->assertTrue($this->renderer->getTransparentBackground()); //test svg return value - $xml = $this->renderer->draw()->saveXML(); - $this->assertEquals(md5($xml), md5_file(__DIR__ . '/_files/svg_transparency.xml')); + $svgCompare = $this->renderer->draw()->saveXML(); + + $svgGood = file_get_contents(__DIR__ . '/_files/svg_transparency.xml'); + $this->assertEquals($svgCompare, $svgGood); } From 4fc3b83f7d49dc11b13ecfad9a72638e0eea69d1 Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Sat, 15 Feb 2014 15:28:17 -0800 Subject: [PATCH 07/10] Resolves zendframework/zf2#4708 - static runOnce causing subsequent tests to fail, need to run transparency test first. --- test/Renderer/SvgTest.php | 44 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/test/Renderer/SvgTest.php b/test/Renderer/SvgTest.php index 6226258..5560f05 100644 --- a/test/Renderer/SvgTest.php +++ b/test/Renderer/SvgTest.php @@ -24,6 +24,29 @@ protected function getRendererObject($options = null) return new Svg($options); } + /** + * @group 4708 + * + * Needs to be run first due to runOnce static on drawPolygon + */ + public function testSvgTransparency() + { + Barcode\Barcode::setBarcodeFont(__DIR__ . '/../Object/_fonts/Vera.ttf'); + $barcode = new Code39(array('text' => '0123456789')); + $this->renderer->setBarcode($barcode); + + $this->assertFalse($this->renderer->getTransparentBackground()); + + $this->renderer->setTransparentBackground(true); + $this->assertTrue($this->renderer->getTransparentBackground()); + + //test svg return value + $svgCompare = $this->renderer->draw()->saveXML(); + + $svgGood = file_get_contents(__DIR__ . '/_files/svg_transparency.xml'); + $this->assertEquals($svgCompare, $svgGood); + } + public function testType() { $this->assertSame('svg', $this->renderer->getType()); @@ -94,27 +117,6 @@ public function testDrawWithExistantResourceReturnResource() Barcode\Barcode::setBarcodeFont(''); } - /** - * @group 4708 - */ - public function testSvgTransparency() - { - Barcode\Barcode::setBarcodeFont(__DIR__ . '/../Object/_fonts/Vera.ttf'); - $barcode = new Code39(array('text' => '0123456789')); - $this->renderer->setBarcode($barcode); - $this->assertFalse($this->renderer->getTransparentBackground()); - - $this->renderer->setTransparentBackground(true); - $this->assertTrue($this->renderer->getTransparentBackground()); - - //test svg return value - $svgCompare = $this->renderer->draw()->saveXML(); - - $svgGood = file_get_contents(__DIR__ . '/_files/svg_transparency.xml'); - $this->assertEquals($svgCompare, $svgGood); - } - - protected function getRendererWithWidth500AndHeight300() { $svg = new \DOMDocument(); From 2504bcf7cb4252e84c3e1f4d54760d1374134f89 Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Sat, 15 Feb 2014 22:42:50 -0800 Subject: [PATCH 08/10] Resolves zendframework/zf2#4708 - static runOnce causing subsequent tests to fail, additional refactor --- src/Renderer/Svg.php | 14 +++++++++++--- test/Renderer/SvgTest.php | 27 ++++++++++++++++++++------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/Renderer/Svg.php b/src/Renderer/Svg.php index 9d7fd4e..9221fd2 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 @@ -297,7 +304,6 @@ public function render() */ protected function drawPolygon($points, $color, $filled = true) { - static $runOnce = array(); $color = 'rgb(' . implode(', ', array(($color & 0xFF0000) >> 16, ($color & 0x00FF00) >> 8, ($color & 0x0000FF))) . ')'; @@ -318,12 +324,14 @@ protected function drawPolygon($points, $color, $filled = true) // SVG passes a rect in as the first call to drawPolygon, we'll need to intercept // this and set transparency if necessary. - if(empty($runOnce['hasRun'])) { + $objId = spl_object_hash($this); + if(!$this->drawPolygonExecuted) { if($this->transparentBackground) { $attributes['fill-opacity'] = '0'; } - $runOnce['hasRun'] = true; + $this->drawPolygonExecuted = true; } + $this->appendRootElement('polygon', $attributes); } diff --git a/test/Renderer/SvgTest.php b/test/Renderer/SvgTest.php index 5560f05..c6c1b9b 100644 --- a/test/Renderer/SvgTest.php +++ b/test/Renderer/SvgTest.php @@ -29,22 +29,35 @@ protected function getRendererObject($options = null) * * Needs to be run first due to runOnce static on drawPolygon */ - public function testSvgTransparency() + 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()); - - //test svg return value - $svgCompare = $this->renderer->draw()->saveXML(); - - $svgGood = file_get_contents(__DIR__ . '/_files/svg_transparency.xml'); - $this->assertEquals($svgCompare, $svgGood); + $svgOutput = $this->renderer->draw()->saveXML(); + $this->assertEquals($svgCompare, $svgOutput); } public function testType() From 9be8afe1f59b01ce2dbf5ca65ffd48e2e2900dff Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Fri, 21 Feb 2014 08:54:55 -0800 Subject: [PATCH 09/10] add comment to Image.php, fix comment in ImageTest.php --- src/Renderer/Image.php | 2 ++ test/Renderer/ImageTest.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Renderer/Image.php b/src/Renderer/Image.php index ddaaf5a..109206e 100644 --- a/src/Renderer/Image.php +++ b/src/Renderer/Image.php @@ -226,6 +226,8 @@ protected function initRenderer() $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); } diff --git a/test/Renderer/ImageTest.php b/test/Renderer/ImageTest.php index c21a64b..08d9120 100644 --- a/test/Renderer/ImageTest.php +++ b/test/Renderer/ImageTest.php @@ -287,7 +287,7 @@ public function testImageGifWithNoTransparency() $this->renderer->setTransparentBackground(false); $this->assertFalse($this->renderer->getTransparentBackground()); - //Test PNG output + //Test Gif output $this->renderer->setImageType('gif'); $image = $this->renderer->draw(); $index = imagecolortransparent($image); @@ -323,7 +323,7 @@ public function testImageGifWithTransparency() $this->renderer->setTransparentBackground(true); $this->assertTrue($this->renderer->getTransparentBackground()); - //Test PNG output + //Test Gif output $this->renderer->setImageType('gif'); $image = $this->renderer->draw(); $index = imagecolortransparent($image); From 9f95038e162cadb81e0ee054238031642bd30668 Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Sat, 22 Feb 2014 12:01:53 -0800 Subject: [PATCH 10/10] remove ending space character from comment --- src/Renderer/Image.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Renderer/Image.php b/src/Renderer/Image.php index 109206e..e940615 100644 --- a/src/Renderer/Image.php +++ b/src/Renderer/Image.php @@ -226,7 +226,7 @@ protected function initRenderer() $backgroundColor & 0x0000FF ); - // JPEG does not support transparency, if transparentBackground is true and + // 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);