Mercurial > hg > soundsoftware-site
comparison vendor/plugins/rfpdf/lib/barcode/i25object.rb @ 441:cbce1fd3b1b7 redmine-1.2
Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author | Chris Cannam |
---|---|
date | Mon, 06 Jun 2011 14:24:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
245:051f544170fe | 441:cbce1fd3b1b7 |
---|---|
1 | |
2 #============================================================+ | |
3 # File name : i25aobject.rb | |
4 # Begin : 2002-07-31 | |
5 # Last Update : 2004-12-29 | |
6 # Author : Karim Mribti [barcode@mribti.com] | |
7 # : Nicola Asuni [info@tecnick.com] | |
8 # Version : 0.0.8a 2001-04-01 (original code) | |
9 # License : GNU LGPL (Lesser General Public License) 2.1 | |
10 # http://www.gnu.org/copyleft/lesser.txt | |
11 # Source Code : http://www.mribti.com/barcode/ | |
12 # | |
13 # Description : I25 Barcode Render Class for PHP using | |
14 # the GD graphics library. | |
15 # Interleaved 2 of 5 is a numeric only bar code | |
16 # with a optional check number. | |
17 # | |
18 # NOTE: | |
19 # This version contains changes by Nicola Asuni: | |
20 # - porting to Ruby | |
21 # - code style and formatting | |
22 # - automatic php documentation in PhpDocumentor Style | |
23 # (www.phpdoc.org) | |
24 # - minor bug fixing | |
25 #============================================================+ | |
26 | |
27 # | |
28 # I25 Barcode Render Class for PHP using the GD graphics library.<br< | |
29 # Interleaved 2 of 5 is a numeric only bar code with a optional check number. | |
30 # @author Karim Mribti, Nicola Asuni | |
31 # @name BarcodeObject | |
32 # @package com.tecnick.tcpdf | |
33 # @@version 0.0.8a 2001-04-01 (original code) | |
34 # @since 2001-03-25 | |
35 # @license http://www.gnu.org/copyleft/lesser.html LGPL | |
36 # | |
37 | |
38 # | |
39 # I25 Barcode Render Class for PHP using the GD graphics library.<br< | |
40 # Interleaved 2 of 5 is a numeric only bar code with a optional check number. | |
41 # @author Karim Mribti, Nicola Asuni | |
42 # @name BarcodeObject | |
43 # @package com.tecnick.tcpdf | |
44 # @@version 0.0.8a 2001-04-01 (original code) | |
45 # @since 2001-03-25 | |
46 # @license http://www.gnu.org/copyleft/lesser.html LGPL | |
47 # | |
48 class I25Object extends BarcodeObject { | |
49 | |
50 # | |
51 # Class Constructor. | |
52 # @param int $Width Image width in pixels. | |
53 # @param int $Height Image height in pixels. | |
54 # @param int $Style Barcode style. | |
55 # @param int $Value value to print on barcode. | |
56 # | |
57 def __construct($Width, $Height, $Style, $Value) | |
58 parent::__construct($Width, $Height, $Style); | |
59 @mValue = $Value; | |
60 @mCharSet = array ( | |
61 # 0# "00110", | |
62 # 1# "10001", | |
63 # 2# "01001", | |
64 # 3# "11000", | |
65 # 4# "00101", | |
66 # 5# "10100", | |
67 # 6# "01100", | |
68 # 7# "00011", | |
69 # 8# "10010", | |
70 # 9# "01010" | |
71 ); | |
72 end | |
73 | |
74 # | |
75 # Returns barcode size. | |
76 # @param int $xres Horizontal resolution. | |
77 # @return barcode size. | |
78 # @access private | |
79 # | |
80 def GetSize($xres) | |
81 $len = @mValue.length; | |
82 | |
83 if ($len == 0) { | |
84 @mError = "Null value"; | |
85 return false; | |
86 end | |
87 | |
88 for ($i=0;$i<$len;$i++) | |
89 if ((@mValue[$i][0] < 48) || (@mValue[$i][0] > 57)) | |
90 @mError = "I25 is numeric only"; | |
91 return false; | |
92 end | |
93 end | |
94 | |
95 if (($len%2) != 0) | |
96 @mError = "The length of barcode value must be even"; | |
97 return false; | |
98 end | |
99 $StartSize = BCD_I25_NARROW_BAR# 4 # $xres; | |
100 $StopSize = BCD_I25_WIDE_BAR# $xres + 2# BCD_I25_NARROW_BAR# $xres; | |
101 $cPos = 0; | |
102 $sPos = 0; | |
103 do { | |
104 $c1 = @mValue[$cPos]; | |
105 $c2 = @mValue[$cPos+1]; | |
106 $cset1 = @mCharSet[$c1]; | |
107 $cset2 = @mCharSet[$c2]; | |
108 | |
109 for ($i=0;$i<5;$i++) | |
110 $type1 = ($cset1[$i]==0) ? (BCD_I25_NARROW_BAR # $xres) : (BCD_I25_WIDE_BAR# $xres); | |
111 $type2 = ($cset2[$i]==0) ? (BCD_I25_NARROW_BAR # $xres) : (BCD_I25_WIDE_BAR# $xres); | |
112 $sPos += ($type1 + $type2); | |
113 end | |
114 $cPos+=2; | |
115 end while ($cPos<$len); | |
116 | |
117 return $sPos + $StartSize + $StopSize; | |
118 end | |
119 | |
120 # | |
121 # Draws the start code. | |
122 # @param int $DrawPos Drawing position. | |
123 # @param int $yPos Vertical position. | |
124 # @param int $ySize Vertical size. | |
125 # @param int $xres Horizontal resolution. | |
126 # @return int drawing position. | |
127 # @access private | |
128 # | |
129 def DrawStart($DrawPos, $yPos, $ySize, $xres) | |
130 # Start code is "0000"# | |
131 @DrawSingleBar($DrawPos, $yPos, BCD_I25_NARROW_BAR # $xres , $ySize); | |
132 $DrawPos += BCD_I25_NARROW_BAR # $xres; | |
133 $DrawPos += BCD_I25_NARROW_BAR # $xres; | |
134 @DrawSingleBar($DrawPos, $yPos, BCD_I25_NARROW_BAR # $xres , $ySize); | |
135 $DrawPos += BCD_I25_NARROW_BAR # $xres; | |
136 $DrawPos += BCD_I25_NARROW_BAR # $xres; | |
137 return $DrawPos; | |
138 end | |
139 | |
140 # | |
141 # Draws the stop code. | |
142 # @param int $DrawPos Drawing position. | |
143 # @param int $yPos Vertical position. | |
144 # @param int $ySize Vertical size. | |
145 # @param int $xres Horizontal resolution. | |
146 # @return int drawing position. | |
147 # @access private | |
148 # | |
149 def DrawStop($DrawPos, $yPos, $ySize, $xres) | |
150 # Stop code is "100"# | |
151 @DrawSingleBar($DrawPos, $yPos, BCD_I25_WIDE_BAR# $xres , $ySize); | |
152 $DrawPos += BCD_I25_WIDE_BAR # $xres; | |
153 $DrawPos += BCD_I25_NARROW_BAR # $xres; | |
154 @DrawSingleBar($DrawPos, $yPos, BCD_I25_NARROW_BAR # $xres , $ySize); | |
155 $DrawPos += BCD_I25_NARROW_BAR # $xres; | |
156 return $DrawPos; | |
157 end | |
158 | |
159 # | |
160 # Draws the barcode object. | |
161 # @param int $xres Horizontal resolution. | |
162 # @return bool true in case of success. | |
163 # | |
164 def DrawObject($xres) | |
165 $len = @mValue.length; | |
166 | |
167 if (($size = GetSize($xres))==0) | |
168 return false; | |
169 end | |
170 | |
171 $cPos = 0; | |
172 | |
173 if (@mStyle & BCS_DRAW_TEXT) $ysize = @mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2 - GetFontHeight(@mFont); | |
174 else $ysize = @mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2; | |
175 | |
176 if (@mStyle & BCS_ALIGN_CENTER) $sPos = (integer)((@mWidth - $size ) / 2); | |
177 elsif (@mStyle & BCS_ALIGN_RIGHT) $sPos = @mWidth - $size; | |
178 else $sPos = 0; | |
179 | |
180 if (@mStyle & BCS_DRAW_TEXT) | |
181 if (@mStyle & BCS_STRETCH_TEXT) | |
182 # Stretch# | |
183 for ($i=0;$i<$len;$i++) | |
184 @DrawChar(@mFont, $sPos+BCD_I25_NARROW_BAR*4*$xres+($size/$len)*$i, | |
185 $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET , @mValue[$i]); | |
186 end | |
187 endelse# Center# | |
188 $text_width = GetFontWidth(@mFont) * @mValue.length; | |
189 @DrawText(@mFont, $sPos+(($size-$text_width)/2)+(BCD_I25_NARROW_BAR*4*$xres), | |
190 $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET, @mValue); | |
191 end | |
192 end | |
193 | |
194 $sPos = @DrawStart($sPos, BCD_DEFAULT_MAR_Y1, $ysize, $xres); | |
195 do { | |
196 $c1 = @mValue[$cPos]; | |
197 $c2 = @mValue[$cPos+1]; | |
198 $cset1 = @mCharSet[$c1]; | |
199 $cset2 = @mCharSet[$c2]; | |
200 | |
201 for ($i=0;$i<5;$i++) | |
202 $type1 = ($cset1[$i]==0) ? (BCD_I25_NARROW_BAR# $xres) : (BCD_I25_WIDE_BAR# $xres); | |
203 $type2 = ($cset2[$i]==0) ? (BCD_I25_NARROW_BAR# $xres) : (BCD_I25_WIDE_BAR# $xres); | |
204 @DrawSingleBar($sPos, BCD_DEFAULT_MAR_Y1, $type1 , $ysize); | |
205 $sPos += ($type1 + $type2); | |
206 end | |
207 $cPos+=2; | |
208 end while ($cPos<$len); | |
209 $sPos = @DrawStop($sPos, BCD_DEFAULT_MAR_Y1, $ysize, $xres); | |
210 return true; | |
211 end | |
212 } | |
213 | |
214 #============================================================+ | |
215 # END OF FILE | |
216 #============================================================+ |