[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 * $Id: DolibarrPdfBarCode.class.php,v 1.4 2005/09/03 13:58:24 eldy Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/includes/fpdf/DolibarrPdfBarCode.class.php,v $ 20 * 21 */ 22 23 require_once(FPDF_PATH.'fpdf.php'); 24 25 class DolibarrPdfBarCode extends FPDF { 26 27 /* Author Olivier PLATHEY 28 * Licence Freeware see : http://fpdf.org/fr/script/script5.php 29 */ 30 function EAN13($x,$y,$barcode,$h=16,$w=.35) 31 { 32 $this->Barcode($x,$y,$barcode,$h,$w,13); 33 } 34 35 function UPC_A($x,$y,$barcode,$h=16,$w=.35) 36 { 37 $this->Barcode($x,$y,$barcode,$h,$w,12); 38 } 39 40 function GetCheckDigit($barcode) 41 { 42 //Calcule le chiffre de contrôle 43 $sum=0; 44 for($i=1;$i<=11;$i+=2) 45 $sum+=3*$barcode{$i}; 46 for($i=0;$i<=10;$i+=2) 47 $sum+=$barcode{$i}; 48 $r=$sum%10; 49 if($r>0) 50 $r=10-$r; 51 return $r; 52 } 53 54 function TestCheckDigit($barcode) 55 { 56 //Vérifie le chiffre de contrôle 57 $sum=0; 58 for($i=1;$i<=11;$i+=2) 59 $sum+=3*$barcode{$i}; 60 for($i=0;$i<=10;$i+=2) 61 $sum+=$barcode{$i}; 62 return ($sum+$barcode{12})%10==0; 63 } 64 65 function Barcode($x,$y,$barcode,$h,$w,$len) 66 { 67 //Ajoute des 0 si nécessaire 68 $barcode=str_pad($barcode,$len-1,'0',STR_PAD_LEFT); 69 if($len==12) 70 $barcode='0'.$barcode; 71 //Ajoute ou teste le chiffre de contrôle 72 if(strlen($barcode)==12) 73 $barcode.=$this->GetCheckDigit($barcode); 74 elseif(!$this->TestCheckDigit($barcode)) 75 $this->Error('Incorrect check digit'); 76 //Convertit les chiffres en barres 77 $codes=array( 78 'A'=>array( 79 '0'=>'0001101','1'=>'0011001','2'=>'0010011','3'=>'0111101','4'=>'0100011', 80 '5'=>'0110001','6'=>'0101111','7'=>'0111011','8'=>'0110111','9'=>'0001011'), 81 'B'=>array( 82 '0'=>'0100111','1'=>'0110011','2'=>'0011011','3'=>'0100001','4'=>'0011101', 83 '5'=>'0111001','6'=>'0000101','7'=>'0010001','8'=>'0001001','9'=>'0010111'), 84 'C'=>array( 85 '0'=>'1110010','1'=>'1100110','2'=>'1101100','3'=>'1000010','4'=>'1011100', 86 '5'=>'1001110','6'=>'1010000','7'=>'1000100','8'=>'1001000','9'=>'1110100') 87 ); 88 $parities=array( 89 '0'=>array('A','A','A','A','A','A'), 90 '1'=>array('A','A','B','A','B','B'), 91 '2'=>array('A','A','B','B','A','B'), 92 '3'=>array('A','A','B','B','B','A'), 93 '4'=>array('A','B','A','A','B','B'), 94 '5'=>array('A','B','B','A','A','B'), 95 '6'=>array('A','B','B','B','A','A'), 96 '7'=>array('A','B','A','B','A','B'), 97 '8'=>array('A','B','A','B','B','A'), 98 '9'=>array('A','B','B','A','B','A') 99 ); 100 $code='101'; 101 $p=$parities[$barcode{0}]; 102 for($i=1;$i<=6;$i++) 103 $code.=$codes[$p[$i-1]][$barcode{$i}]; 104 $code.='01010'; 105 for($i=7;$i<=12;$i++) 106 $code.=$codes['C'][$barcode{$i}]; 107 $code.='101'; 108 //Dessine les barres 109 for($i=0;$i<strlen($code);$i++) 110 { 111 if($code{$i}=='1') 112 $this->Rect($x+$i*$w,$y,$w,$h,'F'); 113 } 114 //Imprime le texte sous le code-barres 115 $this->SetFont('Arial','',12); 116 $this->Text($x,$y+$h+11/$this->k,substr($barcode,-$len)); 117 } 118 119 /* 120 * Licence See i25/info.htm 121 */ 122 123 function i25($xpos, $ypos, $code, $basewidth=1, $height=10){ 124 125 $wide = $basewidth; 126 $narrow = $basewidth / 3 ; 127 128 // wide/narrow codes for the digits 129 $barChar['0'] = 'nnwwn'; 130 $barChar['1'] = 'wnnnw'; 131 $barChar['2'] = 'nwnnw'; 132 $barChar['3'] = 'wwnnn'; 133 $barChar['4'] = 'nnwnw'; 134 $barChar['5'] = 'wnwnn'; 135 $barChar['6'] = 'nwwnn'; 136 $barChar['7'] = 'nnnww'; 137 $barChar['8'] = 'wnnwn'; 138 $barChar['9'] = 'nwnwn'; 139 $barChar['A'] = 'nn'; 140 $barChar['Z'] = 'wn'; 141 142 // add leading zero if code-length is odd 143 if(strlen($code) % 2 != 0){ 144 $code = '0' . $code; 145 } 146 147 $this->SetFont('Arial','',10); 148 $this->Text($xpos, $ypos + $height + 4, $code); 149 $this->SetFillColor(0); 150 151 // add start and stop codes 152 $code = 'AA'.strtolower($code).'ZA'; 153 154 for($i=0; $i<strlen($code); $i=$i+2) 155 { 156 // choose next pair of digits 157 $charBar = $code{$i}; 158 $charSpace = $code{$i+1}; 159 // check whether it is a valid digit 160 if(!isset($barChar[$charBar])) 161 { 162 $this->Error('Invalid character in barcode: '.$charBar); 163 } 164 if(!isset($barChar[$charSpace])) 165 { 166 $this->Error('Invalid character in barcode: '.$charSpace); 167 } 168 // create a wide/narrow-sequence (first digit=bars, second digit=spaces) 169 $seq = ''; 170 for($s=0; $s<strlen($barChar[$charBar]); $s++) 171 { 172 $seq .= $barChar[$charBar]{$s} . $barChar[$charSpace]{$s}; 173 } 174 for($bar=0; $bar<strlen($seq); $bar++){ 175 // set lineWidth depending on value 176 if($seq{$bar} == 'n') 177 { 178 $lineWidth = $narrow; 179 } 180 else 181 { 182 $lineWidth = $wide; 183 } 184 // draw every second value, because the second digit of the pair is represented by the spaces 185 if($bar % 2 == 0) 186 { 187 $this->Rect($xpos, $ypos, $lineWidth, $height, 'F'); 188 } 189 $xpos += $lineWidth; 190 } 191 } 192 } 193 194 195 /* 196 * Copyright ehavet@yahoo.fr 197 * Emmanuel Havet 198 * License: Freeware 199 * 200 */ 201 202 function Code39($x, $y, $code, $ext = true, $cks = false, $w = 0.4, $h = 20, $wide = true) 203 { 204 //Display code 205 $this->SetFont('Arial', '', 10); 206 $this->Text($x, $y+$h+4, $code); 207 $this->SetFillColor(0,0,0); 208 209 if($ext) 210 { 211 //Extended encoding 212 $code = $this->encode_code39_ext($code); 213 } 214 else 215 { 216 //Convert to upper case 217 $code = strtoupper($code); 218 //Check validity 219 if(!preg_match('|^[0-9A-Z. $/+%-]*$|', $code)) 220 $this->Error('Invalid barcode value: '.$code); 221 } 222 223 //Compute checksum 224 if ($cks) 225 $code .= $this->checksum_code39($code); 226 227 //Add start and stop characters 228 $code = '*'.$code.'*'; 229 230 //Conversion tables 231 $narrow_encoding = array ( 232 '0' => '101001101101', '1' => '110100101011', '2' => '101100101011', 233 '3' => '110110010101', '4' => '101001101011', '5' => '110100110101', 234 '6' => '101100110101', '7' => '101001011011', '8' => '110100101101', 235 '9' => '101100101101', 'A' => '110101001011', 'B' => '101101001011', 236 'C' => '110110100101', 'D' => '101011001011', 'E' => '110101100101', 237 'F' => '101101100101', 'G' => '101010011011', 'H' => '110101001101', 238 'I' => '101101001101', 'J' => '101011001101', 'K' => '110101010011', 239 'L' => '101101010011', 'M' => '110110101001', 'N' => '101011010011', 240 'O' => '110101101001', 'P' => '101101101001', 'Q' => '101010110011', 241 'R' => '110101011001', 'S' => '101101011001', 'T' => '101011011001', 242 'U' => '110010101011', 'V' => '100110101011', 'W' => '110011010101', 243 'X' => '100101101011', 'Y' => '110010110101', 'Z' => '100110110101', 244 '-' => '100101011011', '.' => '110010101101', ' ' => '100110101101', 245 '*' => '100101101101', '$' => '100100100101', '/' => '100100101001', 246 '+' => '100101001001', '%' => '101001001001' ); 247 248 $wide_encoding = array ( 249 '0' => '101000111011101', '1' => '111010001010111', '2' => '101110001010111', 250 '3' => '111011100010101', '4' => '101000111010111', '5' => '111010001110101', 251 '6' => '101110001110101', '7' => '101000101110111', '8' => '111010001011101', 252 '9' => '101110001011101', 'A' => '111010100010111', 'B' => '101110100010111', 253 'C' => '111011101000101', 'D' => '101011100010111', 'E' => '111010111000101', 254 'F' => '101110111000101', 'G' => '101010001110111', 'H' => '111010100011101', 255 'I' => '101110100011101', 'J' => '101011100011101', 'K' => '111010101000111', 256 'L' => '101110101000111', 'M' => '111011101010001', 'N' => '101011101000111', 257 'O' => '111010111010001', 'P' => '101110111010001', 'Q' => '101010111000111', 258 'R' => '111010101110001', 'S' => '101110101110001', 'T' => '101011101110001', 259 'U' => '111000101010111', 'V' => '100011101010111', 'W' => '111000111010101', 260 'X' => '100010111010111', 'Y' => '111000101110101', 'Z' => '100011101110101', 261 '-' => '100010101110111', '.' => '111000101011101', ' ' => '100011101011101', 262 '*' => '100010111011101', '$' => '100010001000101', '/' => '100010001010001', 263 '+' => '100010100010001', '%' => '101000100010001'); 264 265 $encoding = $wide ? $wide_encoding : $narrow_encoding; 266 267 //Inter-character spacing 268 $gap = ($w > 0.29) ? '00' : '0'; 269 270 //Convert to bars 271 $encode = ''; 272 for ($i = 0; $i< strlen($code); $i++) 273 $encode .= $encoding[$code{$i}].$gap; 274 275 //Draw bars 276 $this->draw_code39($encode, $x, $y, $w, $h); 277 } 278 279 function checksum_code39($code) { 280 281 //Compute the modulo 43 checksum 282 283 $chars = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 284 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 285 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 286 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%'); 287 $sum = 0; 288 for ($i=0 ; $i<strlen($code); $i++) 289 { 290 $a = array_keys($chars, $code{$i}); 291 $sum += $a[0]; 292 } 293 $r = $sum % 43; 294 return $chars[$r]; 295 } 296 297 function encode_code39_ext($code) { 298 299 //Encode characters in extended mode 300 301 $encode = array( 302 chr(0) => '%U', chr(1) => '$A', chr(2) => '$B', chr(3) => '$C', 303 chr(4) => '$D', chr(5) => '$E', chr(6) => '$F', chr(7) => '$G', 304 chr(8) => '$H', chr(9) => '$I', chr(10) => '$J', chr(11) => '£K', 305 chr(12) => '$L', chr(13) => '$M', chr(14) => '$N', chr(15) => '$O', 306 chr(16) => '$P', chr(17) => '$Q', chr(18) => '$R', chr(19) => '$S', 307 chr(20) => '$T', chr(21) => '$U', chr(22) => '$V', chr(23) => '$W', 308 chr(24) => '$X', chr(25) => '$Y', chr(26) => '$Z', chr(27) => '%A', 309 chr(28) => '%B', chr(29) => '%C', chr(30) => '%D', chr(31) => '%E', 310 chr(32) => ' ', chr(33) => '/A', chr(34) => '/B', chr(35) => '/C', 311 chr(36) => '/D', chr(37) => '/E', chr(38) => '/F', chr(39) => '/G', 312 chr(40) => '/H', chr(41) => '/I', chr(42) => '/J', chr(43) => '/K', 313 chr(44) => '/L', chr(45) => '-', chr(46) => '.', chr(47) => '/O', 314 chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3', 315 chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7', 316 chr(56) => '8', chr(57) => '9', chr(58) => '/Z', chr(59) => '%F', 317 chr(60) => '%G', chr(61) => '%H', chr(62) => '%I', chr(63) => '%J', 318 chr(64) => '%V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C', 319 chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G', 320 chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K', 321 chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O', 322 chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S', 323 chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W', 324 chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => '%K', 325 chr(92) => '%L', chr(93) => '%M', chr(94) => '%N', chr(95) => '%O', 326 chr(96) => '%W', chr(97) => '+A', chr(98) => '+B', chr(99) => '+C', 327 chr(100) => '+D', chr(101) => '+E', chr(102) => '+F', chr(103) => '+G', 328 chr(104) => '+H', chr(105) => '+I', chr(106) => '+J', chr(107) => '+K', 329 chr(108) => '+L', chr(109) => '+M', chr(110) => '+N', chr(111) => '+O', 330 chr(112) => '+P', chr(113) => '+Q', chr(114) => '+R', chr(115) => '+S', 331 chr(116) => '+T', chr(117) => '+U', chr(118) => '+V', chr(119) => '+W', 332 chr(120) => '+X', chr(121) => '+Y', chr(122) => '+Z', chr(123) => '%P', 333 chr(124) => '%Q', chr(125) => '%R', chr(126) => '%S', chr(127) => '%T'); 334 335 $code_ext = ''; 336 for ($i = 0 ; $i<strlen($code); $i++) { 337 if (ord($code{$i}) > 127) 338 $this->Error('Invalid character: '.$code{$i}); 339 $code_ext .= $encode[$code{$i}]; 340 } 341 return $code_ext; 342 } 343 344 function draw_code39($code, $x, $y, $w, $h) 345 { 346 //Draw bars 347 348 for($i=0; $i<strlen($code); $i++) 349 { 350 if($code{$i} == '1') 351 $this->Rect($x+$i*$w, $y, $w, $h, 'F'); 352 } 353 } 354 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |