/usr/local/miolo2/classes/contrib/barcode.class

Go to the documentation of this file.
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     //Public properties
00049     var $codigo;       //SET: Código a converter em código de barras
00050     var $ebf;          //SET: Espessura da barra fina: usar 1 até 2.
00051     var $ebg;          //SET: Espessura da barra grossa: usar 2x a 3x da esp_barra_fn.
00052     var $altb;         //SET: altura do código de barras
00053     var $ipp;          //SET: Endereço completo da imagem do ponto PRETO p/compor o código de barras
00054     var $ipb;          //SET: Endereço completo da imagem do ponto BRANCO p/compor o código de barras
00055     var $tamanhoTotal; //Propriedade de RETORNO do tamanho total da imagem do código de barras
00056 
00057     //Private properties
00058     var $mixed_code;
00059     var $bc = array(
00060         );
00061 
00062     var $bc_string;
00063 
00064     function BarcodeI25($code = '')
00065     {
00066         //Construtor da classe
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         //define barcode patterns
00110         //0 - Estreita    1 - Larga
00111         //Dim bc(60) As String   Obj.DrawWidth = 1
00112 
00113         $this->bc[0] = "00110"; //0 digit
00114         $this->bc[1] = "10001"; //1 digit
00115         $this->bc[2] = "01001"; //2 digit
00116         $this->bc[3] = "11000"; //3 digit
00117         $this->bc[4] = "00101"; //4 digit
00118         $this->bc[5] = "10100"; //5 digit
00119         $this->bc[6] = "01100"; //6 digit
00120         $this->bc[7] = "00011"; //7 digit
00121         $this->bc[8] = "10010"; //8 digit
00122         $this->bc[9] = "01010"; //9 digit
00123         $this->bc[10] = "0000"; //pre-amble
00124         $this->bc[11] = "100";  //post-amble
00125 
00126         $this->bc_string = strtoupper($this->bc_string);
00127 
00128         $lbc = strlen($this->bc_string) - 1;
00129 
00130         //Gera o código com os patterns
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         //Faz a mixagem do Código
00140         $this->MixCode();
00141 
00142         $this->bc_string = $this->bc[10] . $this->bc_string . $this->bc[11]; //Adding Start and Stop Pattern
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             //barra preta, barra branca
00154 
00155             $imgBar = ($xi % 2 == 0) ? $this->ipp : $this->ipb;
00156             $imgWid = ($this->bc_string[$xi] == "0") ? $this->ebf : $this->ebg;
00157 
00158             //criando as barras
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         //        echo "<div align=\"center\">$barra_html</div>\n";
00168         //        return "<div class=\"barcode\">$barra_html</div>\n";
00169         return $barra_html;
00170     } //End of drawBrar
00171 
00172     function MixCode()
00173     {
00174         //Faz a mixagem do valor a ser codificado pelo Código de Barras I25
00175         //Declaração de Variaveis
00176         $i = 0;
00177         $l = 0;
00178         $k = 0;  //inteiro, inteiro, longo
00179         $s = ""; //String
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     } //End of mixCode
00203 }     //End of Class
00204 ?>
CopyLeft (L) 2001-2006 - [MIOLO Development Team] SOLIS - Cooperativa de Soluções Livres - Lajeado/RS - Brasil