MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
barcode.class
Ir para a documentação deste ficheiro.
1<?php
2#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3# @title
4# Barcode
5#
6# @description
7# Barcode generation classes
8#
9# @topics contributions
10#
11# @created
12# 2001/08/15
13#
14# @organisation
15# UNILASALLE
16#
17# @legal
18# UNILASALLE
19# CopyLeft (L) 2001-2002 UNILASALLE, Canoas/RS - Brasil
20# Licensed under GPL (see COPYING.TXT or FSF at www.fsf.org for
21# further details)
22#
23# @contributors
24# Rudinei Pereira Dias [author] [rudinei@lasalle.tche.br]
25#
26# @maintainers
27# Vilson Cristiano Gartner [author] [vgartner@univates.br]
28# Thomas Spriestersbach [author] [ts@interact2000.com.br]
29#
30# @history
31# $Log: barcode.class,v $
32# Revision 1.1 2002/10/03 19:14:05 vgartner
33# Added barcode class.
34#
35#
36# @id $Id: barcode.class,v 1.1 2002/10/03 19:14:05 vgartner Exp $
37#---------------------------------------------------------------------
38
39#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
40# Rotina para a geração de Código de Barra
41# no padrão Interleved 2 of 5 (Intercalado 2 de 5)
42# utilizado para os documentos bancários conforme
43# padrão FEBRABAN.
44# UNILASALLE
45#---------------------------------------------------------------------
47{
48 //Public properties
49 var $codigo; //SET: Código a converter em código de barras
50 var $ebf; //SET: Espessura da barra fina: usar 1 até 2.
51 var $ebg; //SET: Espessura da barra grossa: usar 2x a 3x da esp_barra_fn.
52 var $altb; //SET: altura do código de barras
53 var $ipp; //SET: Endereço completo da imagem do ponto PRETO p/compor o código de barras
54 var $ipb; //SET: Endereço completo da imagem do ponto BRANCO p/compor o código de barras
55 var $tamanhoTotal; //Propriedade de RETORNO do tamanho total da imagem do código de barras
56
57 //Private properties
59 var $bc = array(
60 );
61
63
64 function BarcodeI25($code = '')
65 {
66 //Construtor da classe
67 $this->ebf = 1;
68 $this->ebg = 3;
69 $this->altb = 50;
70 $this->ipp = "images/ponto_preto.gif";
71 $this->ipb = "images/ponto_branco.gif";
72 $this->mixed_code = "";
73 $this->bc_string = "";
74 $this->tamanhoTotal = 0;
75
76 if ($code !== '')
77 {
78 $this->SetCode($code);
79 }
80 }
81
82 function SetCode($code)
83 {
84 global $MIOLO;
85
86 $MIOLO->Assert(strlen($code) > 0, "Código de Barras não informado. (Barcode Undefined)");
87
88 $MIOLO->Assert(!(strlen($code) % 2), "Tamanho inválido de código. Deve ser múltiplo de 2.");
89
90 $this->codigo = $code;
91 }
92
93 function GetCode()
94 {
95 return $this->codigo;
96 }
97
98 function Generate()
99 {
100 $this->codigo = trim($this->codigo);
101
102 $th = "";
103 $new_string = "";
104 $lbc = 0;
105 $xi = 0;
106 $k = 0;
107 $this->bc_string = $this->codigo;
108
109 //define barcode patterns
110 //0 - Estreita 1 - Larga
111 //Dim bc(60) As String Obj.DrawWidth = 1
112
113 $this->bc[0] = "00110"; //0 digit
114 $this->bc[1] = "10001"; //1 digit
115 $this->bc[2] = "01001"; //2 digit
116 $this->bc[3] = "11000"; //3 digit
117 $this->bc[4] = "00101"; //4 digit
118 $this->bc[5] = "10100"; //5 digit
119 $this->bc[6] = "01100"; //6 digit
120 $this->bc[7] = "00011"; //7 digit
121 $this->bc[8] = "10010"; //8 digit
122 $this->bc[9] = "01010"; //9 digit
123 $this->bc[10] = "0000"; //pre-amble
124 $this->bc[11] = "100"; //post-amble
125
126 $this->bc_string = strtoupper($this->bc_string);
127
128 $lbc = strlen($this->bc_string) - 1;
129
130 //Gera o código com os patterns
131 for ($xi = 0; $xi <= $lbc; $xi++)
132 {
133 $k = (int)substr($this->bc_string, $xi, 1);
134 $new_string = $new_string . $this->bc[$k];
135 }
136
137 $this->bc_string = $new_string;
138
139 //Faz a mixagem do Código
140 $this->MixCode();
141
142 $this->bc_string = $this->bc[10] . $this->bc_string . $this->bc[11]; //Adding Start and Stop Pattern
143
144 $lbc = strlen($this->bc_string) - 1;
145
146 $barra_html = "";
147
148 for ($xi = 0; $xi <= $lbc; $xi++)
149 {
150 $imgBar = "";
151 $imgWid = 0;
152
153 //barra preta, barra branca
154
155 $imgBar = ($xi % 2 == 0) ? $this->ipp : $this->ipb;
156 $imgWid = ($this->bc_string[$xi] == "0") ? $this->ebf : $this->ebg;
157
158 //criando as barras
159 $barra_html = $barra_html . "<img src=\"" . $imgBar . "\" width=\"" . $imgWid . "\" height=\"" . $this->altb
160 . "\" border=\"0\">";
161
162 $this->tamanhoTotal = $this->tamanhoTotal + $imgWid;
163 }
164
165 $this->tamanhoTotal = (int)($this->tamanhoTotal * 1.1);
166
167 // echo "<div align=\"center\">$barra_html</div>\n";
168 // return "<div class=\"barcode\">$barra_html</div>\n";
169 return $barra_html;
170 } //End of drawBrar
171
172 function MixCode()
173 {
174 //Faz a mixagem do valor a ser codificado pelo Código de Barras I25
175 //Declaração de Variaveis
176 $i = 0;
177 $l = 0;
178 $k = 0; //inteiro, inteiro, longo
179 $s = ""; //String
180
181 $l = strlen($this->bc_string);
182
183 if (($l % 5) != 0 || ($l % 2) != 0)
184 {
185 $this->barra_html = "<b> Código não pode ser intercalado: Comprimento inválido (mix).</b>";
186 }
187 else
188 {
189 $s = "";
190
191 for ($i = 0; $i <= $l; $i += 10)
192 {
193 $s = $s . $this->bc_string[$i] . $this->bc_string[$i + 5];
194 $s = $s . $this->bc_string[$i + 1] . $this->bc_string[$i + 6];
195 $s = $s . $this->bc_string[$i + 2] . $this->bc_string[$i + 7];
196 $s = $s . $this->bc_string[$i + 3] . $this->bc_string[$i + 8];
197 $s = $s . $this->bc_string[$i + 4] . $this->bc_string[$i + 9];
198 }
199
200 $this->bc_string = $s;
201 }
202 } //End of mixCode
203} //End of Class
204?>
SetCode($code)
Definição barcode.class:82
BarcodeI25($code='')
Definição barcode.class:64