00001 <?
00002 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00003 # @title
00004 # Barcode
00005 #
00006 # @description
00007 # Barcode generation classes
00008 #
00009 # @topics contributions
00010 #
00011 # @created
00012 # 2001/08/15
00013 #
00014 # @organisation
00015 # UNILASALLE
00016 #
00017 # @legal
00018 # UNILASALLE
00019 # CopyLeft (L) 2001-2002 UNILASALLE, Canoas/RS - Brasil
00020 # Licensed under GPL (see COPYING.TXT or FSF at www.fsf.org for
00021 # further details)
00022 #
00023 # @contributors
00024 # Rudinei Pereira Dias [author] [rudinei@lasalle.tche.br]
00025 #
00026 # @maintainers
00027 # Vilson Cristiano Gartner [author] [vgartner@univates.br]
00028 # Thomas Spriestersbach [author] [ts@interact2000.com.br]
00029 #
00030 # @history
00031 # $Log: barcode.class,v $
00032 # Revision 1.1 2002/10/03 19:14:05 vgartner
00033 # Added barcode class.
00034 #
00035 #
00036 # @id $Id: barcode.class,v 1.1 2002/10/03 19:14:05 vgartner Exp $
00037 #---------------------------------------------------------------------
00038
00039 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00040 # Rotina para a geração de Código de Barra
00041 # no padrão Interleved 2 of 5 (Intercalado 2 de 5)
00042 # utilizado para os documentos bancários conforme
00043 # padrão FEBRABAN.
00044 # UNILASALLE
00045 #---------------------------------------------------------------------
00046 class BarcodeI25
00047 {
00048
00049 var $codigo;
00050 var $ebf;
00051 var $ebg;
00052 var $altb;
00053 var $ipp;
00054 var $ipb;
00055 var $tamanhoTotal;
00056
00057
00058 var $mixed_code;
00059 var $bc = array(
00060 );
00061
00062 var $bc_string;
00063
00064 function BarcodeI25($code = '')
00065 {
00066
00067 $this->ebf = 1;
00068 $this->ebg = 3;
00069 $this->altb = 50;
00070 $this->ipp = "/images/ponto_preto.gif";
00071 $this->ipb = "/images/ponto_branco.gif";
00072 $this->mixed_code = "";
00073 $this->bc_string = "";
00074 $this->tamanhoTotal = 0;
00075
00076 if ($code !== '')
00077 {
00078 $this->SetCode($code);
00079 }
00080 }
00081
00082 function SetCode($code)
00083 {
00084 global $MIOLO;
00085
00086 $MIOLO->Assert(strlen($code) > 0, "Código de Barras não informado. (Barcode Undefined)");
00087
00088 $MIOLO->Assert(!(strlen($code) % 2), "Tamanho inválido de código. Deve ser múltiplo de 2.");
00089
00090 $this->codigo = $code;
00091 }
00092
00093 function GetCode()
00094 {
00095 return $this->codigo;
00096 }
00097
00098 function Generate()
00099 {
00100 $this->codigo = trim($this->codigo);
00101
00102 $th = "";
00103 $new_string = "";
00104 $lbc = 0;
00105 $xi = 0;
00106 $k = 0;
00107 $this->bc_string = $this->codigo;
00108
00109
00110
00111
00112
00113 $this->bc[0] = "00110";
00114 $this->bc[1] = "10001";
00115 $this->bc[2] = "01001";
00116 $this->bc[3] = "11000";
00117 $this->bc[4] = "00101";
00118 $this->bc[5] = "10100";
00119 $this->bc[6] = "01100";
00120 $this->bc[7] = "00011";
00121 $this->bc[8] = "10010";
00122 $this->bc[9] = "01010";
00123 $this->bc[10] = "0000";
00124 $this->bc[11] = "100";
00125
00126 $this->bc_string = strtoupper($this->bc_string);
00127
00128 $lbc = strlen($this->bc_string) - 1;
00129
00130
00131 for ($xi = 0; $xi <= $lbc; $xi++)
00132 {
00133 $k = (int)substr($this->bc_string, $xi, 1);
00134 $new_string = $new_string . $this->bc[$k];
00135 }
00136
00137 $this->bc_string = $new_string;
00138
00139
00140 $this->MixCode();
00141
00142 $this->bc_string = $this->bc[10] . $this->bc_string . $this->bc[11];
00143
00144 $lbc = strlen($this->bc_string) - 1;
00145
00146 $barra_html = "";
00147
00148 for ($xi = 0; $xi <= $lbc; $xi++)
00149 {
00150 $imgBar = "";
00151 $imgWid = 0;
00152
00153
00154
00155 $imgBar = ($xi % 2 == 0) ? $this->ipp : $this->ipb;
00156 $imgWid = ($this->bc_string[$xi] == "0") ? $this->ebf : $this->ebg;
00157
00158
00159 $barra_html = $barra_html . "<img src=\"" . $imgBar . "\" width=\"" . $imgWid . "\" height=\"" . $this->altb
00160 . "\" border=\"0\">";
00161
00162 $this->tamanhoTotal = $this->tamanhoTotal + $imgWid;
00163 }
00164
00165 $this->tamanhoTotal = (int)($this->tamanhoTotal * 1.1);
00166
00167
00168
00169 return $barra_html;
00170 }
00171
00172 function MixCode()
00173 {
00174
00175
00176 $i = 0;
00177 $l = 0;
00178 $k = 0;
00179 $s = "";
00180
00181 $l = strlen($this->bc_string);
00182
00183 if (($l % 5) != 0 || ($l % 2) != 0)
00184 {
00185 $this->barra_html = "<b> Código não pode ser intercalado: Comprimento inválido (mix).</b>";
00186 }
00187 else
00188 {
00189 $s = "";
00190
00191 for ($i = 0; $i <= $l; $i += 10)
00192 {
00193 $s = $s . $this->bc_string[$i] . $this->bc_string[$i + 5];
00194 $s = $s . $this->bc_string[$i + 1] . $this->bc_string[$i + 6];
00195 $s = $s . $this->bc_string[$i + 2] . $this->bc_string[$i + 7];
00196 $s = $s . $this->bc_string[$i + 3] . $this->bc_string[$i + 8];
00197 $s = $s . $this->bc_string[$i + 4] . $this->bc_string[$i + 9];
00198 }
00199
00200 $this->bc_string = $s;
00201 }
00202 }
00203 }
00204 ?>