13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Barcode |
16 * @package Zend_Barcode |
17 * @subpackage Object |
17 * @subpackage Object |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: ObjectAbstract.php 24593 2012-01-05 20:35:02Z matthew $ |
20 * @version $Id$ |
21 */ |
21 */ |
22 |
22 |
23 /** |
23 /** |
24 * Class for generate Barcode |
24 * Class for generate Barcode |
25 * |
25 * |
26 * @category Zend |
26 * @category Zend |
27 * @package Zend_Barcode |
27 * @package Zend_Barcode |
28 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
28 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
29 * @license http://framework.zend.com/license/new-bsd New BSD License |
29 * @license http://framework.zend.com/license/new-bsd New BSD License |
30 */ |
30 */ |
31 abstract class Zend_Barcode_Object_ObjectAbstract |
31 abstract class Zend_Barcode_Object_ObjectAbstract |
32 { |
32 { |
33 /** |
33 /** |
34 * Namespace of the barcode for autoloading |
34 * Namespace of the barcode for autoloading |
|
35 * |
35 * @var string |
36 * @var string |
36 */ |
37 */ |
37 protected $_barcodeNamespace = 'Zend_Barcode_Object'; |
38 protected $_barcodeNamespace = 'Zend_Barcode_Object'; |
38 |
39 |
39 /** |
40 /** |
40 * Set of drawing instructions |
41 * Set of drawing instructions |
|
42 * |
41 * @var array |
43 * @var array |
42 */ |
44 */ |
43 protected $_instructions = array(); |
45 protected $_instructions = array(); |
44 |
46 |
45 /** |
47 /** |
46 * Barcode type |
48 * Barcode type |
|
49 * |
47 * @var string |
50 * @var string |
48 */ |
51 */ |
49 protected $_type = null; |
52 protected $_type = null; |
50 |
53 |
51 /** |
54 /** |
52 * Height of the object |
55 * Height of the object |
|
56 * |
53 * @var integer |
57 * @var integer |
54 */ |
58 */ |
55 protected $_height = null; |
59 protected $_height = null; |
56 |
60 |
57 /** |
61 /** |
58 * Width of the object |
62 * Width of the object |
|
63 * |
59 * @var integer |
64 * @var integer |
60 */ |
65 */ |
61 protected $_width = null; |
66 protected $_width = null; |
62 |
67 |
63 /** |
68 /** |
64 * Height of the bar |
69 * Height of the bar |
|
70 * |
65 * @var integer |
71 * @var integer |
66 */ |
72 */ |
67 protected $_barHeight = 50; |
73 protected $_barHeight = 50; |
68 |
74 |
69 /** |
75 /** |
70 * Width of a thin bar |
76 * Width of a thin bar |
|
77 * |
71 * @var integer |
78 * @var integer |
72 */ |
79 */ |
73 protected $_barThinWidth = 1; |
80 protected $_barThinWidth = 1; |
74 |
81 |
75 /** |
82 /** |
76 * Width of a thick bar |
83 * Width of a thick bar |
|
84 * |
77 * @var integer |
85 * @var integer |
78 */ |
86 */ |
79 protected $_barThickWidth = 3; |
87 protected $_barThickWidth = 3; |
80 |
88 |
81 /** |
89 /** |
82 * Factor to multiply bar and font measure |
90 * Factor to multiply bar and font measure |
83 * (barHeight, barThinWidth, barThickWidth & fontSize) |
91 * (barHeight, barThinWidth, barThickWidth & fontSize) |
|
92 * |
84 * @var integer |
93 * @var integer |
85 */ |
94 */ |
86 protected $_factor = 1; |
95 protected $_factor = 1; |
87 |
96 |
88 /** |
97 /** |
89 * Font and bars color of the object |
98 * Font and bars color of the object |
|
99 * |
90 * @var integer |
100 * @var integer |
91 */ |
101 */ |
92 protected $_foreColor = 0x000000; |
102 protected $_foreColor = 0x000000; |
93 |
103 |
94 /** |
104 /** |
95 * Background color of the object |
105 * Background color of the object |
|
106 * |
96 * @var integer |
107 * @var integer |
97 */ |
108 */ |
98 protected $_backgroundColor = 0xFFFFFF; |
109 protected $_backgroundColor = 0xFFFFFF; |
99 |
110 |
100 /** |
111 /** |
101 * Activate/deactivate border of the object |
112 * Activate/deactivate border of the object |
|
113 * |
102 * @var boolean |
114 * @var boolean |
103 */ |
115 */ |
104 protected $_withBorder = false; |
116 protected $_withBorder = false; |
105 |
117 |
106 /** |
118 /** |
107 * Activate/deactivate drawing of quiet zones |
119 * Activate/deactivate drawing of quiet zones |
|
120 * |
108 * @var boolean |
121 * @var boolean |
109 */ |
122 */ |
110 protected $_withQuietZones = true; |
123 protected $_withQuietZones = true; |
111 |
124 |
112 /** |
125 /** |
113 * Force quiet zones even if |
126 * Force quiet zones even if |
|
127 * |
114 * @var boolean |
128 * @var boolean |
115 */ |
129 */ |
116 protected $_mandatoryQuietZones = false; |
130 protected $_mandatoryQuietZones = false; |
117 |
131 |
118 /** |
132 /** |
119 * Orientation of the barcode in degrees |
133 * Orientation of the barcode in degrees |
|
134 * |
120 * @var float |
135 * @var float |
121 */ |
136 */ |
122 protected $_orientation = 0; |
137 protected $_orientation = 0; |
123 |
138 |
124 /** |
139 /** |
125 * Offset from the top the object |
140 * Offset from the top the object |
126 * (calculated from the orientation) |
141 * (calculated from the orientation) |
|
142 * |
127 * @var integer |
143 * @var integer |
128 */ |
144 */ |
129 protected $_offsetTop = null; |
145 protected $_offsetTop = null; |
130 |
146 |
131 /** |
147 /** |
132 * Offset from the left the object |
148 * Offset from the left the object |
133 * (calculated from the orientation) |
149 * (calculated from the orientation) |
|
150 * |
134 * @var integer |
151 * @var integer |
135 */ |
152 */ |
136 protected $_offsetLeft = null; |
153 protected $_offsetLeft = null; |
137 |
154 |
138 /** |
155 /** |
139 * Text to display |
156 * Text to display |
|
157 * |
140 * @var string |
158 * @var string |
141 */ |
159 */ |
142 protected $_text = null; |
160 protected $_text = null; |
143 |
161 |
144 /** |
162 /** |
145 * Display (or not) human readable text |
163 * Display (or not) human readable text |
|
164 * |
146 * @var boolean |
165 * @var boolean |
147 */ |
166 */ |
148 protected $_drawText = true; |
167 protected $_drawText = true; |
149 |
168 |
150 /** |
169 /** |
151 * Adjust (or not) position of human readable characters with barcode |
170 * Adjust (or not) position of human readable characters with barcode |
|
171 * |
152 * @var boolean |
172 * @var boolean |
153 */ |
173 */ |
154 protected $_stretchText = false; |
174 protected $_stretchText = false; |
155 |
175 |
156 /** |
176 /** |
157 * Font resource |
177 * Font resource |
158 * - integer (1 to 5): corresponds to GD included fonts |
178 * - integer (1 to 5): corresponds to GD included fonts |
159 * - string: corresponds to path of a TTF font |
179 * - string: corresponds to path of a TTF font |
|
180 * |
160 * @var integer|string |
181 * @var integer|string |
161 */ |
182 */ |
162 protected $_font = null; |
183 protected $_font = null; |
163 |
184 |
164 /** |
185 /** |
165 * Font size |
186 * Font size |
|
187 * |
166 * @var float |
188 * @var float |
167 */ |
189 */ |
168 protected $_fontSize = 10; |
190 protected $_fontSize = 10; |
169 |
191 |
170 /** |
192 /** |
171 * Drawing of checksum |
193 * Drawing of checksum |
|
194 * |
172 * @var boolean |
195 * @var boolean |
173 */ |
196 */ |
174 protected $_withChecksum = false; |
197 protected $_withChecksum = false; |
175 |
198 |
176 /** |
199 /** |
177 * Drawing of checksum inside text |
200 * Drawing of checksum inside text |
|
201 * |
178 * @var boolean |
202 * @var boolean |
179 */ |
203 */ |
180 protected $_withChecksumInText = false; |
204 protected $_withChecksumInText = false; |
181 |
205 |
182 /** |
206 /** |
183 * Fix barcode length (numeric or string like 'even') |
207 * Fix barcode length (numeric or string like 'even') |
|
208 * |
184 * @var $_barcodeLength integer | string |
209 * @var $_barcodeLength integer | string |
185 */ |
210 */ |
186 protected $_barcodeLength = null; |
211 protected $_barcodeLength = null; |
187 |
212 |
188 /** |
213 /** |
189 * Activate automatic addition of leading zeros |
214 * Activate automatic addition of leading zeros |
190 * if barcode length is fixed |
215 * if barcode length is fixed |
|
216 * |
191 * @var $_addLeadingZeros boolean |
217 * @var $_addLeadingZeros boolean |
192 */ |
218 */ |
193 protected $_addLeadingZeros = true; |
219 protected $_addLeadingZeros = true; |
194 |
220 |
195 /** |
221 /** |
196 * Activation of mandatory checksum |
222 * Activation of mandatory checksum |
197 * to deactivate unauthorized modification |
223 * to deactivate unauthorized modification |
|
224 * |
198 * @var $_mandatoryChecksum boolean |
225 * @var $_mandatoryChecksum boolean |
199 */ |
226 */ |
200 protected $_mandatoryChecksum = false; |
227 protected $_mandatoryChecksum = false; |
201 |
228 |
202 /** |
229 /** |
203 * Character used to substitute checksum character for validation |
230 * Character used to substitute checksum character for validation |
|
231 * |
204 * @var $_substituteChecksumCharacter mixed |
232 * @var $_substituteChecksumCharacter mixed |
205 */ |
233 */ |
206 protected $_substituteChecksumCharacter = 0; |
234 protected $_substituteChecksumCharacter = 0; |
207 |
235 |
208 /** |
236 /** |
209 * TTF font name: can be set before instanciation of the object |
237 * TTF font name: can be set before instanciation of the object |
|
238 * |
210 * @var string |
239 * @var string |
211 */ |
240 */ |
212 protected static $_staticFont = null; |
241 protected static $_staticFont = null; |
213 |
242 |
214 /** |
243 /** |
215 * Constructor |
244 * Constructor |
|
245 * |
216 * @param array|Zend_Config $options |
246 * @param array|Zend_Config $options |
217 * @return void |
|
218 */ |
247 */ |
219 public function __construct($options = null) |
248 public function __construct($options = null) |
220 { |
249 { |
221 $this->_getDefaultOptions(); |
250 $this->_getDefaultOptions(); |
222 if (self::$_staticFont !== null) { |
251 if (self::$_staticFont !== null) { |
461 return $this; |
505 return $this; |
462 } |
506 } |
463 |
507 |
464 /** |
508 /** |
465 * Retrieve background color of the image |
509 * Retrieve background color of the image |
|
510 * |
466 * @return integer |
511 * @return integer |
467 */ |
512 */ |
468 public function getBackgroundColor() |
513 public function getBackgroundColor() |
469 { |
514 { |
470 return $this->_backgroundColor; |
515 return $this->_backgroundColor; |
471 } |
516 } |
472 |
517 |
473 /** |
518 /** |
474 * Activate/deactivate drawing of the bar |
519 * Activate/deactivate drawing of the bar |
|
520 * |
475 * @param boolean $value |
521 * @param boolean $value |
476 * @return Zend_Barcode_Object |
522 * @return $this |
477 */ |
523 */ |
478 public function setWithBorder($value) |
524 public function setWithBorder($value) |
479 { |
525 { |
480 $this->_withBorder = (bool) $value; |
526 $this->_withBorder = (bool) $value; |
481 return $this; |
527 return $this; |
482 } |
528 } |
483 |
529 |
484 /** |
530 /** |
485 * Retrieve if border are draw or not |
531 * Retrieve if border are draw or not |
|
532 * |
486 * @return boolean |
533 * @return boolean |
487 */ |
534 */ |
488 public function getWithBorder() |
535 public function getWithBorder() |
489 { |
536 { |
490 return $this->_withBorder; |
537 return $this->_withBorder; |
491 } |
538 } |
492 |
539 |
493 /** |
540 /** |
494 * Activate/deactivate drawing of the quiet zones |
541 * Activate/deactivate drawing of the quiet zones |
|
542 * |
495 * @param boolean $value |
543 * @param boolean $value |
496 * @return Zend_Barcode_Object |
544 * @return $this |
497 */ |
545 */ |
498 public function setWithQuietZones($value) |
546 public function setWithQuietZones($value) |
499 { |
547 { |
500 $this->_withQuietZones = (bool) $value; |
548 $this->_withQuietZones = (bool) $value; |
501 return $this; |
549 return $this; |
502 } |
550 } |
503 |
551 |
504 /** |
552 /** |
505 * Retrieve if quiet zones are draw or not |
553 * Retrieve if quiet zones are draw or not |
|
554 * |
506 * @return boolean |
555 * @return boolean |
507 */ |
556 */ |
508 public function getWithQuietZones() |
557 public function getWithQuietZones() |
509 { |
558 { |
510 return $this->_withQuietZones; |
559 return $this->_withQuietZones; |
511 } |
560 } |
512 |
561 |
513 /** |
562 /** |
514 * Allow fast inversion of font/bars color and background color |
563 * Allow fast inversion of font/bars color and background color |
515 * @return Zend_Barcode_Object |
564 * |
|
565 * @return $this |
516 */ |
566 */ |
517 public function setReverseColor() |
567 public function setReverseColor() |
518 { |
568 { |
519 $tmp = $this->_foreColor; |
569 $tmp = $this->_foreColor; |
520 $this->_foreColor = $this->_backgroundColor; |
570 $this->_foreColor = $this->_backgroundColor; |
521 $this->_backgroundColor = $tmp; |
571 $this->_backgroundColor = $tmp; |
|
572 |
522 return $this; |
573 return $this; |
523 } |
574 } |
524 |
575 |
525 /** |
576 /** |
526 * Set orientation of barcode and text |
577 * Set orientation of barcode and text |
527 * @param float $value |
578 * |
528 * @return Zend_Barcode_Object |
579 * @param int|float|string|bool $value |
529 * @throw Zend_Barcode_Object_Exception |
580 * @return $this |
|
581 * @throws Zend_Barcode_Object_Exception |
530 */ |
582 */ |
531 public function setOrientation($value) |
583 public function setOrientation($value) |
532 { |
584 { |
533 $this->_orientation = floatval($value) - floor(floatval($value) / 360) * 360; |
585 $value = floatval($value); |
|
586 $this->_orientation = $value - floor($value / 360) * 360; |
534 return $this; |
587 return $this; |
535 } |
588 } |
536 |
589 |
537 /** |
590 /** |
538 * Retrieve orientation of barcode and text |
591 * Retrieve orientation of barcode and text |
|
592 * |
539 * @return float |
593 * @return float |
540 */ |
594 */ |
541 public function getOrientation() |
595 public function getOrientation() |
542 { |
596 { |
543 return $this->_orientation; |
597 return $this->_orientation; |
544 } |
598 } |
545 |
599 |
546 /** |
600 /** |
547 * Set text to encode |
601 * Set text to encode |
|
602 * |
548 * @param string $value |
603 * @param string $value |
549 * @return Zend_Barcode_Object |
604 * @return $this |
550 */ |
605 */ |
551 public function setText($value) |
606 public function setText($value) |
552 { |
607 { |
553 $this->_text = trim($value); |
608 $this->_text = trim($value); |
554 return $this; |
609 return $this; |
555 } |
610 } |
556 |
611 |
557 /** |
612 /** |
558 * Retrieve text to encode |
613 * Retrieve text to encode |
|
614 * |
559 * @return string |
615 * @return string |
560 */ |
616 */ |
561 public function getText() |
617 public function getText() |
562 { |
618 { |
563 $text = $this->_text; |
619 $text = $this->_text; |
612 } |
672 } |
613 } |
673 } |
614 |
674 |
615 /** |
675 /** |
616 * Activate/deactivate drawing of text to encode |
676 * Activate/deactivate drawing of text to encode |
|
677 * |
617 * @param boolean $value |
678 * @param boolean $value |
618 * @return Zend_Barcode_Object |
679 * @return $this |
619 */ |
680 */ |
620 public function setDrawText($value) |
681 public function setDrawText($value) |
621 { |
682 { |
622 $this->_drawText = (bool) $value; |
683 $this->_drawText = (bool) $value; |
623 return $this; |
684 return $this; |
624 } |
685 } |
625 |
686 |
626 /** |
687 /** |
627 * Retrieve if drawing of text to encode is enabled |
688 * Retrieve if drawing of text to encode is enabled |
|
689 * |
628 * @return boolean |
690 * @return boolean |
629 */ |
691 */ |
630 public function getDrawText() |
692 public function getDrawText() |
631 { |
693 { |
632 return $this->_drawText; |
694 return $this->_drawText; |
633 } |
695 } |
634 |
696 |
635 /** |
697 /** |
636 * Activate/deactivate the adjustment of the position |
698 * Activate/deactivate the adjustment of the position |
637 * of the characters to the position of the bars |
699 * of the characters to the position of the bars |
|
700 * |
638 * @param boolean $value |
701 * @param boolean $value |
639 * @return Zend_Barcode_Object |
702 * @return $this |
640 * @throw Zend_Barcode_Object_Exception |
703 * @throws Zend_Barcode_Object_Exception |
641 */ |
704 */ |
642 public function setStretchText($value) |
705 public function setStretchText($value) |
643 { |
706 { |
644 $this->_stretchText = (bool) $value; |
707 $this->_stretchText = (bool) $value; |
645 return $this; |
708 return $this; |
646 } |
709 } |
647 |
710 |
648 /** |
711 /** |
649 * Retrieve if the adjustment of the position of the characters |
712 * Retrieve if the adjustment of the position of the characters |
650 * to the position of the bars is enabled |
713 * to the position of the bars is enabled |
|
714 * |
651 * @return boolean |
715 * @return boolean |
652 */ |
716 */ |
653 public function getStretchText() |
717 public function getStretchText() |
654 { |
718 { |
655 return $this->_stretchText; |
719 return $this->_stretchText; |
682 |
748 |
683 /** |
749 /** |
684 * Activate/deactivate the automatic generation |
750 * Activate/deactivate the automatic generation |
685 * of the checksum character |
751 * of the checksum character |
686 * added to the barcode text |
752 * added to the barcode text |
|
753 * |
687 * @param boolean $value |
754 * @param boolean $value |
688 * @return Zend_Barcode_Object |
755 * @return $this |
689 * @throw Zend_Barcode_Object_Exception |
756 * @throws Zend_Barcode_Object_Exception |
690 */ |
757 */ |
691 public function setWithChecksumInText($value) |
758 public function setWithChecksumInText($value) |
692 { |
759 { |
693 if (!$this->_mandatoryChecksum) { |
760 if (!$this->_mandatoryChecksum) { |
694 $this->_withChecksumInText = (bool) $value; |
761 $this->_withChecksumInText = (bool) $value; |
695 } |
762 } |
|
763 |
696 return $this; |
764 return $this; |
697 } |
765 } |
698 |
766 |
699 /** |
767 /** |
700 * Retrieve if the checksum character is automatically |
768 * Retrieve if the checksum character is automatically |
701 * added to the barcode text |
769 * added to the barcode text |
|
770 * |
702 * @return boolean |
771 * @return boolean |
703 */ |
772 */ |
704 public function getWithChecksumInText() |
773 public function getWithChecksumInText() |
705 { |
774 { |
706 return $this->_withChecksumInText; |
775 return $this->_withChecksumInText; |
707 } |
776 } |
708 |
777 |
709 /** |
778 /** |
710 * Set the font for all instances of barcode |
779 * Set the font for all instances of barcode |
|
780 * |
711 * @param string $font |
781 * @param string $font |
712 * @return void |
|
713 */ |
782 */ |
714 public static function setBarcodeFont($font) |
783 public static function setBarcodeFont($font) |
715 { |
784 { |
716 if (is_string($font) || (is_int($font) && $font >= 1 && $font <= 5)) { |
785 if (is_string($font) || (is_int($font) && $font >= 1 && $font <= 5)) { |
717 self::$_staticFont = $font; |
786 self::$_staticFont = $font; |
809 } |
885 } |
810 } |
886 } |
811 |
887 |
812 /** |
888 /** |
813 * Add an instruction in the array of instructions |
889 * Add an instruction in the array of instructions |
|
890 * |
814 * @param array $instruction |
891 * @param array $instruction |
815 */ |
892 */ |
816 protected function _addInstruction(array $instruction) |
893 protected function _addInstruction(array $instruction) |
817 { |
894 { |
818 $this->_instructions[] = $instruction; |
895 $this->_instructions[] = $instruction; |
819 } |
896 } |
820 |
897 |
821 /** |
898 /** |
822 * Retrieve the set of drawing instructions |
899 * Retrieve the set of drawing instructions |
|
900 * |
823 * @return array |
901 * @return array |
824 */ |
902 */ |
825 public function getInstructions() |
903 public function getInstructions() |
826 { |
904 { |
827 return $this->_instructions; |
905 return $this->_instructions; |
828 } |
906 } |
829 |
907 |
830 /** |
908 /** |
831 * Add a polygon drawing instruction in the set of instructions |
909 * Add a polygon drawing instruction in the set of instructions |
832 * @param array $points |
910 * |
|
911 * @param array $points |
833 * @param integer $color |
912 * @param integer $color |
834 * @param boolean $filled |
913 * @param boolean $filled |
835 */ |
914 */ |
836 protected function _addPolygon(array $points, $color = null, $filled = true) |
915 protected function _addPolygon(array $points, $color = null, $filled = true) |
837 { |
916 { |
838 if ($color === null) { |
917 if ($color === null) { |
839 $color = $this->_foreColor; |
918 $color = $this->_foreColor; |
840 } |
919 } |
841 $this->_addInstruction(array( |
920 $this->_addInstruction( |
842 'type' => 'polygon', |
921 array( |
843 'points' => $points, |
922 'type' => 'polygon', |
844 'color' => $color, |
923 'points' => $points, |
845 'filled' => $filled, |
924 'color' => $color, |
846 )); |
925 'filled' => $filled, |
|
926 ) |
|
927 ); |
847 } |
928 } |
848 |
929 |
849 /** |
930 /** |
850 * Add a text drawing instruction in the set of instructions |
931 * Add a text drawing instruction in the set of instructions |
851 * @param string $text |
932 * |
852 * @param float $size |
933 * @param string $text |
853 * @param array $position |
934 * @param float $size |
854 * @param string $font |
935 * @param array $position |
855 * @param integer $color |
936 * @param string $font |
856 * @param string $alignment |
937 * @param integer $color |
857 * @param float $orientation |
938 * @param string $alignment |
|
939 * @param float|int $orientation |
858 */ |
940 */ |
859 protected function _addText( |
941 protected function _addText( |
860 $text, |
942 $text, |
861 $size, |
943 $size, |
862 $position, |
944 $position, |
911 $this->validateText($value); |
997 $this->validateText($value); |
912 } |
998 } |
913 |
999 |
914 /** |
1000 /** |
915 * Check the ratio between the thick and the thin bar |
1001 * Check the ratio between the thick and the thin bar |
916 * @param integer $min |
1002 * |
917 * @param integer $max |
1003 * @param int $min |
918 * @return void |
1004 * @param int $max |
919 * @throw Zend_Barcode_Object_Exception |
1005 * @throws Zend_Barcode_Object_Exception |
920 */ |
1006 */ |
921 protected function _checkRatio($min = 2, $max = 3) |
1007 protected function _checkRatio($min = 2, $max = 3) |
922 { |
1008 { |
923 $ratio = $this->_barThickWidth / $this->_barThinWidth; |
1009 $ratio = $this->_barThickWidth / $this->_barThinWidth; |
924 if (!($ratio >= $min && $ratio <= $max)) { |
1010 if (!($ratio >= $min && $ratio <= $max)) { |
925 require_once 'Zend/Barcode/Object/Exception.php'; |
1011 require_once 'Zend/Barcode/Object/Exception.php'; |
926 throw new Zend_Barcode_Object_Exception(sprintf( |
1012 throw new Zend_Barcode_Object_Exception( |
927 'Ratio thick/thin bar must be between %0.1f and %0.1f (actual %0.3f)', |
1013 sprintf( |
928 $min, |
1014 'Ratio thick/thin bar must be between %0.1f and %0.1f (actual %0.3f)', |
929 $max, |
1015 $min, |
930 $ratio |
1016 $max, |
931 )); |
1017 $ratio |
|
1018 ) |
|
1019 ); |
932 } |
1020 } |
933 } |
1021 } |
934 |
1022 |
935 /** |
1023 /** |
936 * Drawing with an angle is just allow TTF font |
1024 * Drawing with an angle is just allow TTF font |
937 * @return void |
1025 * |
938 * @throw Zend_Barcode_Object_Exception |
1026 * @throws Zend_Barcode_Object_Exception |
939 */ |
1027 */ |
940 protected function _checkFontAndOrientation() |
1028 protected function _checkFontAndOrientation() |
941 { |
1029 { |
942 if (is_numeric($this->_font) && $this->_orientation != 0) { |
1030 if (is_numeric($this->_font) && $this->_orientation != 0) { |
943 require_once 'Zend/Barcode/Object/Exception.php'; |
1031 require_once 'Zend/Barcode/Object/Exception.php'; |
959 + (int) $this->_withBorder; |
1047 + (int) $this->_withBorder; |
960 } |
1048 } |
961 |
1049 |
962 /** |
1050 /** |
963 * Calculate the width of the barcode |
1051 * Calculate the width of the barcode |
|
1052 * |
964 * @return integer |
1053 * @return integer |
965 */ |
1054 */ |
966 abstract protected function _calculateBarcodeWidth(); |
1055 abstract protected function _calculateBarcodeWidth(); |
967 |
1056 |
968 /** |
1057 /** |
969 * Height of the result object |
1058 * Height of the result object |
970 * @return integer |
1059 * |
|
1060 * @return int |
971 */ |
1061 */ |
972 protected function _calculateHeight() |
1062 protected function _calculateHeight() |
973 { |
1063 { |
974 return (int) $this->_withBorder * 2 |
1064 return (int) $this->_withBorder * 2 |
975 + $this->_calculateBarcodeHeight() |
1065 + $this->_calculateBarcodeHeight() |
976 + (int) $this->_withBorder * 2; |
1066 + (int) $this->_withBorder * 2; |
977 } |
1067 } |
978 |
1068 |
979 /** |
1069 /** |
980 * Height of the barcode |
1070 * Height of the barcode |
981 * @return integer |
1071 * |
|
1072 * @return int |
982 */ |
1073 */ |
983 protected function _calculateBarcodeHeight() |
1074 protected function _calculateBarcodeHeight() |
984 { |
1075 { |
985 $textHeight = 0; |
1076 $textHeight = 0; |
986 $extraHeight = 0; |
1077 $extraHeight = 0; |
987 if ($this->_drawText) { |
1078 if ($this->_drawText) { |
988 $textHeight += $this->_fontSize; |
1079 $textHeight += $this->_fontSize; |
989 $extraHeight = 2; |
1080 $extraHeight = 2; |
990 } |
1081 } |
991 return ($this->_barHeight + $textHeight) * $this->_factor + $extraHeight; |
1082 |
|
1083 return ($this->_barHeight + $textHeight) * $this->_factor |
|
1084 + $extraHeight; |
992 } |
1085 } |
993 |
1086 |
994 /** |
1087 /** |
995 * Get height of the result object |
1088 * Get height of the result object |
996 * @return integer |
1089 * |
|
1090 * @param bool $recalculate |
|
1091 * @return int |
997 */ |
1092 */ |
998 public function getHeight($recalculate = false) |
1093 public function getHeight($recalculate = false) |
999 { |
1094 { |
1000 if ($this->_height === null || $recalculate) { |
1095 if ($this->_height === null || $recalculate) { |
1001 $this->_height = |
1096 $this->_height = |
1002 abs($this->_calculateHeight() * cos($this->_orientation / 180 * pi())) |
1097 abs( |
1003 + abs($this->_calculateWidth() * sin($this->_orientation / 180 * pi())); |
1098 $this->_calculateHeight() * cos( |
|
1099 $this->_orientation / 180 * pi() |
|
1100 ) |
|
1101 ) |
|
1102 + abs( |
|
1103 $this->_calculateWidth() * sin( |
|
1104 $this->_orientation / 180 * pi() |
|
1105 ) |
|
1106 ); |
1004 } |
1107 } |
1005 return $this->_height; |
1108 return $this->_height; |
1006 } |
1109 } |
1007 |
1110 |
1008 /** |
1111 /** |
1009 * Get width of the result object |
1112 * Get width of the result object |
1010 * @return integer |
1113 * |
|
1114 * @param bool $recalculate |
|
1115 * @return int |
1011 */ |
1116 */ |
1012 public function getWidth($recalculate = false) |
1117 public function getWidth($recalculate = false) |
1013 { |
1118 { |
1014 if ($this->_width === null || $recalculate) { |
1119 if ($this->_width === null || $recalculate) { |
1015 $this->_width = |
1120 $this->_width = |
1016 abs($this->_calculateWidth() * cos($this->_orientation / 180 * pi())) |
1121 abs( |
1017 + abs($this->_calculateHeight() * sin($this->_orientation / 180 * pi())); |
1122 $this->_calculateWidth() * cos( |
|
1123 $this->_orientation / 180 * pi() |
|
1124 ) |
|
1125 ) |
|
1126 + abs( |
|
1127 $this->_calculateHeight() * sin( |
|
1128 $this->_orientation / 180 * pi() |
|
1129 ) |
|
1130 ); |
1018 } |
1131 } |
1019 return $this->_width; |
1132 return $this->_width; |
1020 } |
1133 } |
1021 |
1134 |
1022 /** |
1135 /** |
1023 * Calculate the offset from the left of the object |
1136 * Calculate the offset from the left of the object |
1024 * if an orientation is activated |
1137 * if an orientation is activated |
1025 * @param boolean $recalculate |
1138 * |
|
1139 * @param bool $recalculate |
1026 * @return float |
1140 * @return float |
1027 */ |
1141 */ |
1028 public function getOffsetLeft($recalculate = false) |
1142 public function getOffsetLeft($recalculate = false) |
1029 { |
1143 { |
1030 if ($this->_offsetLeft === null || $recalculate) { |
1144 if ($this->_offsetLeft === null || $recalculate) { |
1073 return $this->_offsetTop; |
1188 return $this->_offsetTop; |
1074 } |
1189 } |
1075 |
1190 |
1076 /** |
1191 /** |
1077 * Apply rotation on a point in X/Y dimensions |
1192 * Apply rotation on a point in X/Y dimensions |
1078 * @param float $x1 x-position before rotation |
1193 * |
1079 * @param float $y1 y-position before rotation |
1194 * @param float $x1 x-position before rotation |
1080 * @return array Array of two elements corresponding to the new XY point |
1195 * @param float $y1 y-position before rotation |
|
1196 * @return array Array of two elements corresponding to the new XY point |
1081 */ |
1197 */ |
1082 protected function _rotate($x1, $y1) |
1198 protected function _rotate($x1, $y1) |
1083 { |
1199 { |
1084 $x2 = $x1 * cos($this->_orientation / 180 * pi()) |
1200 $x2 = $x1 * cos($this->_orientation / 180 * pi()) |
1085 - $y1 * sin($this->_orientation / 180 * pi()) |
1201 - $y1 * sin($this->_orientation / 180 * pi()) |
1086 + $this->getOffsetLeft(); |
1202 + $this->getOffsetLeft(); |
1087 $y2 = $y1 * cos($this->_orientation / 180 * pi()) |
1203 $y2 = $y1 * cos($this->_orientation / 180 * pi()) |
1088 + $x1 * sin($this->_orientation / 180 * pi()) |
1204 + $x1 * sin($this->_orientation / 180 * pi()) |
1089 + $this->getOffsetTop(); |
1205 + $this->getOffsetTop(); |
1090 return array(intval($x2) , intval($y2)); |
1206 |
|
1207 return array( |
|
1208 intval($x2), |
|
1209 intval($y2) |
|
1210 ); |
1091 } |
1211 } |
1092 |
1212 |
1093 /** |
1213 /** |
1094 * Complete drawing of the barcode |
1214 * Complete drawing of the barcode |
|
1215 * |
1095 * @return array Table of instructions |
1216 * @return array Table of instructions |
1096 */ |
1217 */ |
1097 public function draw() |
1218 public function draw() |
1098 { |
1219 { |
1099 $this->checkParams(); |
1220 $this->checkParams(); |
1229 } |
1353 } |
1230 } |
1354 } |
1231 |
1355 |
1232 /** |
1356 /** |
1233 * Check for invalid characters |
1357 * Check for invalid characters |
1234 * @param string $value Text to be ckecked |
1358 * |
1235 * @return void |
1359 * @param string $value Text to be ckecked |
1236 */ |
1360 */ |
1237 public function validateText($value) |
1361 public function validateText($value) |
1238 { |
1362 { |
1239 $this->_validateText($value); |
1363 $this->_validateText($value); |
1240 } |
1364 } |
1241 |
1365 |
1242 /** |
1366 /** |
1243 * Standard validation for most of barcode objects |
1367 * Standard validation for most of barcode objects |
|
1368 * |
1244 * @param string $value |
1369 * @param string $value |
1245 * @param array $options |
1370 * @param array $options |
|
1371 * @throws Zend_Barcode_Object_Exception |
1246 */ |
1372 */ |
1247 protected function _validateText($value, $options = array()) |
1373 protected function _validateText($value, $options = array()) |
1248 { |
1374 { |
1249 $validatorName = (isset($options['validator'])) ? $options['validator'] : $this->getType(); |
1375 $validatorName = (isset($options['validator'])) ? $options['validator'] : $this->getType(); |
1250 |
1376 |
1251 $validator = new Zend_Validate_Barcode(array( |
1377 $validator = new Zend_Validate_Barcode( |
1252 'adapter' => $validatorName, |
1378 array( |
1253 'checksum' => false, |
1379 'adapter' => $validatorName, |
1254 )); |
1380 'checksum' => false, |
|
1381 ) |
|
1382 ); |
1255 |
1383 |
1256 $checksumCharacter = ''; |
1384 $checksumCharacter = ''; |
1257 $withChecksum = false; |
1385 $withChecksum = false; |
1258 if ($this->_mandatoryChecksum) { |
1386 if ($this->_mandatoryChecksum) { |
1259 $checksumCharacter = $this->_substituteChecksumCharacter; |
1387 $checksumCharacter = $this->_substituteChecksumCharacter; |
1260 $withChecksum = true; |
1388 $withChecksum = true; |
1261 } |
1389 } |
1262 |
1390 |
1263 $value = $this->_addLeadingZeros($value, $withChecksum) . $checksumCharacter; |
1391 $value = $this->_addLeadingZeros($value, $withChecksum) |
|
1392 . $checksumCharacter; |
1264 |
1393 |
1265 if (!$validator->isValid($value)) { |
1394 if (!$validator->isValid($value)) { |
1266 $message = implode("\n", $validator->getMessages()); |
1395 $message = implode("\n", $validator->getMessages()); |
1267 |
1396 |
1268 /** |
1397 /** |