Forráskód Böngészése

[ZF-9554]: add ability to produce barcode without quiet zones

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21667 44c647ce-9c0f-0410-b52a-842ac1e357ba
mikaelkael 16 éve
szülő
commit
b5a0c807be
28 módosított fájl, 119 hozzáadás és 22 törlés
  1. 7 0
      documentation/manual/en/module_specs/Zend_Barcode-Objects.xml
  2. 12 0
      documentation/manual/en/module_specs/Zend_Barcode-Objects_Details.xml
  3. 1 0
      library/Zend/Barcode/Object/Ean13.php
  4. 2 1
      library/Zend/Barcode/Object/Ean8.php
  5. 37 1
      library/Zend/Barcode/Object/ObjectAbstract.php
  6. 1 0
      library/Zend/Barcode/Object/Upca.php
  7. 1 0
      library/Zend/Barcode/Object/Upce.php
  8. 1 1
      library/Zend/Barcode/Renderer/Pdf.php
  9. 2 0
      tests/Zend/Barcode/Object/Code25Test.php
  10. 2 0
      tests/Zend/Barcode/Object/Code25interleavedTest.php
  11. 2 0
      tests/Zend/Barcode/Object/Code39Test.php
  12. 2 0
      tests/Zend/Barcode/Object/Ean13Test.php
  13. 2 0
      tests/Zend/Barcode/Object/Ean2Test.php
  14. 2 0
      tests/Zend/Barcode/Object/Ean5Test.php
  15. 3 1
      tests/Zend/Barcode/Object/Ean8Test.php
  16. 2 0
      tests/Zend/Barcode/Object/IdentcodeTest.php
  17. 2 0
      tests/Zend/Barcode/Object/Itf14Test.php
  18. 2 0
      tests/Zend/Barcode/Object/LeitcodeTest.php
  19. 2 0
      tests/Zend/Barcode/Object/PlanetTest.php
  20. 2 0
      tests/Zend/Barcode/Object/PostnetTest.php
  21. 2 0
      tests/Zend/Barcode/Object/RoyalmailTest.php
  22. 8 0
      tests/Zend/Barcode/Object/TestCommon.php
  23. 2 0
      tests/Zend/Barcode/Object/UpcaTest.php
  24. 2 0
      tests/Zend/Barcode/Object/UpceTest.php
  25. 4 4
      tests/Zend/Barcode/Object/_files/Ean8_123456_border_instructions.php
  26. 8 8
      tests/Zend/Barcode/Object/_files/Ean8_123456_border_oriented_instructions.php
  27. 2 2
      tests/Zend/Barcode/Object/_files/Ean8_123456_instructions.php
  28. 4 4
      tests/Zend/Barcode/Object/_files/Ean8_123456_oriented_instructions.php

+ 7 - 0
documentation/manual/en/module_specs/Zend_Barcode-Objects.xml

@@ -192,6 +192,13 @@ $barcode->setText('ZEND-FRAMEWORK')
                     </row>
 
                     <row>
+                        <entry><emphasis>withQuietZones</emphasis></entry>
+                        <entry><type>Boolean</type></entry>
+                        <entry><constant>TRUE</constant></entry>
+                        <entry>Leave a quiet zone before and after the barcode</entry>
+                    </row>
+
+                    <row>
                         <entry><emphasis>drawText</emphasis></entry>
                         <entry><type>Boolean</type></entry>
                         <entry><constant>TRUE</constant></entry>

+ 12 - 0
documentation/manual/en/module_specs/Zend_Barcode-Objects_Details.xml

@@ -340,6 +340,10 @@
                 <classname>Zend_Barcode_Object_Ean13</classname> will automatically
                 prepend the missing zero to the barcode text.
             </para>
+
+            <para>
+                The option <property>withQuietZones</property> has no effect with this barcode.
+            </para>
         </note>
     </sect3>
 
@@ -717,6 +721,10 @@
                 <classname>Zend_Barcode_Object_Upca</classname> will automatically
                 prepend missing zeros to the barcode text.
             </para>
+
+            <para>
+                The option <property>withQuietZones</property> has no effect with this barcode.
+            </para>
         </note>
     </sect3>
 
@@ -779,6 +787,10 @@
                 <classname>Zend_Barcode_Object_Upce</classname> will automatically
                 replace it by 0.
             </para>
+
+            <para>
+                The option <property>withQuietZones</property> has no effect with this barcode.
+            </para>
         </note>
     </sect3>
 </sect2>

+ 1 - 0
library/Zend/Barcode/Object/Ean13.php

@@ -82,6 +82,7 @@ class Zend_Barcode_Object_Ean13 extends Zend_Barcode_Object_ObjectAbstract
     {
         $this->_barcodeLength = 13;
         $this->_mandatoryChecksum = true;
+        $this->_mandatoryQuietZones = true;
     }
 
     /**

+ 2 - 1
library/Zend/Barcode/Object/Ean8.php

@@ -59,9 +59,10 @@ class Zend_Barcode_Object_Ean8 extends Zend_Barcode_Object_Ean13
     {
         $quietZone       = $this->getQuietZone();
         $startCharacter  = (3 * $this->_barThinWidth) * $this->_factor;
+        $middleCharacter = (5 * $this->_barThinWidth) * $this->_factor;
         $stopCharacter   = (3 * $this->_barThinWidth) * $this->_factor;
         $encodedData     = (7 * $this->_barThinWidth) * $this->_factor * 8;
-        return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
+        return $quietZone + $startCharacter + $middleCharacter + $encodedData + $stopCharacter + $quietZone;
     }
 
         /**

+ 37 - 1
library/Zend/Barcode/Object/ObjectAbstract.php

@@ -104,6 +104,18 @@ abstract class Zend_Barcode_Object_ObjectAbstract
     protected $_withBorder = false;
 
     /**
+     * Activate/deactivate drawing of quiet zones
+     * @var boolean
+     */
+    protected $_withQuietZones = true;
+
+    /**
+     * Force quiet zones even if
+     * @var boolean
+     */
+    protected $_mandatoryQuietZones = false;
+
+    /**
      * Orientation of the barcode in degrees
      * @var float
      */
@@ -479,6 +491,26 @@ abstract class Zend_Barcode_Object_ObjectAbstract
     }
 
     /**
+     * Activate/deactivate drawing of the quiet zones
+     * @param boolean $value
+     * @return Zend_Barcode_Object
+     */
+    public function setWithQuietZones($value)
+    {
+        $this->_withQuietZones = (bool) $value;
+        return $this;
+    }
+
+    /**
+     * Retrieve if quiet zones are draw or not
+     * @return boolean
+     */
+    public function getWithQuietZones()
+    {
+        return $this->_withQuietZones;
+    }
+
+    /**
      * Allow fast inversion of font/bars color and background color
      * @return Zend_Barcode_Object
      */
@@ -770,7 +802,11 @@ abstract class Zend_Barcode_Object_ObjectAbstract
      */
     public function getQuietZone()
     {
-        return 10 * $this->_barThinWidth * $this->_factor;
+        if ($this->_withQuietZones || $this->_mandatoryQuietZones) {
+            return 10 * $this->_barThinWidth * $this->_factor;
+        } else {
+            return 0;
+        }
     }
 
     /**

+ 1 - 0
library/Zend/Barcode/Object/Upca.php

@@ -49,6 +49,7 @@ class Zend_Barcode_Object_Upca extends Zend_Barcode_Object_Ean13
     {
         $this->_barcodeLength = 12;
         $this->_mandatoryChecksum = true;
+        $this->_mandatoryQuietZones = true;
     }
 
     /**

+ 1 - 0
library/Zend/Barcode/Object/Upce.php

@@ -74,6 +74,7 @@ class Zend_Barcode_Object_Upce extends Zend_Barcode_Object_Ean13
     {
         $this->_barcodeLength = 8;
         $this->_mandatoryChecksum = true;
+        $this->_mandatoryQuietZones = true;
     }
 
     /**

+ 1 - 1
library/Zend/Barcode/Renderer/Pdf.php

@@ -166,7 +166,7 @@ class Zend_Barcode_Renderer_Pdf extends Zend_Barcode_Renderer_RendererAbstract
     }
 
     /**
-     * Draw a polygon in the rendering resource
+     * Draw a text in the rendering resource
      * @param string $text
      * @param float $size
      * @param array $position

+ 2 - 0
tests/Zend/Barcode/Object/Code25Test.php

@@ -144,6 +144,8 @@ class Zend_Barcode_Object_Code25Test extends Zend_Barcode_Object_TestCommon
     {
         $this->_object->setText('0123456789');
         $this->assertEquals(180, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(160, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 2 - 0
tests/Zend/Barcode/Object/Code25interleavedTest.php

@@ -170,6 +170,8 @@ class Zend_Barcode_Object_Code25interleavedTest extends Zend_Barcode_Object_Test
     {
         $this->_object->setText('0123456789');
         $this->assertEquals(119, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(99, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 2 - 0
tests/Zend/Barcode/Object/Code39Test.php

@@ -137,6 +137,8 @@ class Zend_Barcode_Object_Code39Test extends Zend_Barcode_Object_TestCommon
     {
         $this->_object->setText('0123456789');
         $this->assertEquals(211, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(191, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 2 - 0
tests/Zend/Barcode/Object/Ean13Test.php

@@ -115,6 +115,8 @@ class Zend_Barcode_Object_Ean13Test extends Zend_Barcode_Object_TestCommon
     {
         $this->_object->setText('000123456789');
         $this->assertEquals(115, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(115, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 2 - 0
tests/Zend/Barcode/Object/Ean2Test.php

@@ -105,6 +105,8 @@ class Zend_Barcode_Object_Ean2Test extends Zend_Barcode_Object_TestCommon
     {
         $this->_object->setText('43');
         $this->assertEquals(41, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(21, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 2 - 0
tests/Zend/Barcode/Object/Ean5Test.php

@@ -105,6 +105,8 @@ class Zend_Barcode_Object_Ean5Test extends Zend_Barcode_Object_TestCommon
     {
         $this->_object->setText('45678');
         $this->assertEquals(68, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(48, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 3 - 1
tests/Zend/Barcode/Object/Ean8Test.php

@@ -114,7 +114,9 @@ class Zend_Barcode_Object_Ean8Test extends Zend_Barcode_Object_TestCommon
     public function testGetKnownWidthWithoutOrientation()
     {
         $this->_object->setText('123456');
-        $this->assertEquals(82, $this->_object->getWidth());
+        $this->assertEquals(87, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(67, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 2 - 0
tests/Zend/Barcode/Object/IdentcodeTest.php

@@ -115,6 +115,8 @@ class Zend_Barcode_Object_IdentcodeTest extends Zend_Barcode_Object_TestCommon
     {
         $this->_object->setText('00123456789');
         $this->assertEquals(137, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(117, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 2 - 0
tests/Zend/Barcode/Object/Itf14Test.php

@@ -136,6 +136,8 @@ class Zend_Barcode_Object_Itf14Test extends Zend_Barcode_Object_TestCommon
     {
         $this->_object->setText('0000123456789');
         $this->assertEquals(155, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(135, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 2 - 0
tests/Zend/Barcode/Object/LeitcodeTest.php

@@ -115,6 +115,8 @@ class Zend_Barcode_Object_LeitcodeTest extends Zend_Barcode_Object_TestCommon
     {
         $this->_object->setText('0000123456789');
         $this->assertEquals(155, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(135, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 2 - 0
tests/Zend/Barcode/Object/PlanetTest.php

@@ -117,6 +117,8 @@ class Zend_Barcode_Object_PlanetTest extends Zend_Barcode_Object_TestCommon
     {
         $this->_object->setText('00000012345');
         $this->assertEquals(286, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(246, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 2 - 0
tests/Zend/Barcode/Object/PostnetTest.php

@@ -117,6 +117,8 @@ class Zend_Barcode_Object_PostnetTest extends Zend_Barcode_Object_TestCommon
     {
         $this->_object->setText('012345');
         $this->assertEquals(186, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(146, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 2 - 0
tests/Zend/Barcode/Object/RoyalmailTest.php

@@ -109,6 +109,8 @@ class Zend_Barcode_Object_RoyalmailTest extends Zend_Barcode_Object_TestCommon
     {
         $this->_object->setText('012345');
         $this->assertEquals(158, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(118, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 8 - 0
tests/Zend/Barcode/Object/TestCommon.php

@@ -312,6 +312,14 @@ abstract class Zend_Barcode_Object_TestCommon extends PHPUnit_Framework_TestCase
         $this->assertSame(true, $this->_object->getWithChecksumInText());
     }
 
+    public function testWithoutQuietZones()
+    {
+        $this->_object->setWithQuietZones(0);
+        $this->assertSame(false, $this->_object->getWithQuietZones());
+        $this->_object->setWithQuietZones(false);
+        $this->assertSame(false, $this->_object->getWithQuietZones());
+    }
+
     public function testSetFontAsNumberForGdImage()
     {
         if (! extension_loaded('gd')) {

+ 2 - 0
tests/Zend/Barcode/Object/UpcaTest.php

@@ -115,6 +115,8 @@ class Zend_Barcode_Object_UpcaTest extends Zend_Barcode_Object_TestCommon
     {
         $this->_object->setText('00123456789');
         $this->assertEquals(115, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(115, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 2 - 0
tests/Zend/Barcode/Object/UpceTest.php

@@ -123,6 +123,8 @@ class Zend_Barcode_Object_UpceTest extends Zend_Barcode_Object_TestCommon
     {
         $this->_object->setText('1234567');
         $this->assertEquals(71, $this->_object->getWidth());
+        $this->_object->setWithQuietZones(false);
+        $this->assertEquals(71, $this->_object->getWidth(true));
     }
 
     public function testCompleteGeneration()

+ 4 - 4
tests/Zend/Barcode/Object/_files/Ean8_123456_border_instructions.php

@@ -18,12 +18,12 @@ array (
       ),
       2 => 
       array (
-        0 => 83,
+        0 => 88,
         1 => 65,
       ),
       3 => 
       array (
-        0 => 83,
+        0 => 88,
         1 => 0,
       ),
     ),
@@ -1028,12 +1028,12 @@ array (
       ),
       1 => 
       array (
-        0 => 83,
+        0 => 88,
         1 => 0,
       ),
       2 => 
       array (
-        0 => 83,
+        0 => 88,
         1 => 65,
       ),
       3 => 

+ 8 - 8
tests/Zend/Barcode/Object/_files/Ean8_123456_border_oriented_instructions.php

@@ -18,13 +18,13 @@ array (
       ),
       2 => 
       array (
-        0 => 38,
-        1 => 104,
+        0 => 41,
+        1 => 108,
       ),
       3 => 
       array (
-        0 => 95,
-        1 => 71,
+        0 => 97,
+        1 => 76,
       ),
     ),
     'color' => 16777215,
@@ -1028,13 +1028,13 @@ array (
       ),
       1 => 
       array (
-        0 => 95,
-        1 => 71,
+        0 => 97,
+        1 => 76,
       ),
       2 => 
       array (
-        0 => 38,
-        1 => 104,
+        0 => 41,
+        1 => 108,
       ),
       3 => 
       array (

+ 2 - 2
tests/Zend/Barcode/Object/_files/Ean8_123456_instructions.php

@@ -18,12 +18,12 @@ array (
       ),
       2 => 
       array (
-        0 => 81,
+        0 => 86,
         1 => 61,
       ),
       3 => 
       array (
-        0 => 81,
+        0 => 86,
         1 => 0,
       ),
     ),

+ 4 - 4
tests/Zend/Barcode/Object/_files/Ean8_123456_oriented_instructions.php

@@ -18,13 +18,13 @@ array (
       ),
       2 => 
       array (
-        0 => 41,
-        1 => 100,
+        0 => 43,
+        1 => 104,
       ),
       3 => 
       array (
-        0 => 94,
-        1 => 70,
+        0 => 96,
+        1 => 74,
       ),
     ),
     'color' => 16777215,