<?
/*************************************** ********************************
Written by Caocao
Caocao@eastday.com
Http://nethermit.yeah.net
Display code39 barcode class
Usage:
$ Convert = new code39;
$ STR = $ convert-> decode ($ Str );
**************************************** *******************************/Class pattenclass
{
VaR $ color;
VaR $ width;
Function pattenclass ($ color, $ width)
{
$ This-> color = $ color;
$ This-> width = $ width;
}
}
Class code39
{
VaR $ zoom;
VaR $ height;
VaR $ Patten = array ();
Function code39 ($ zoom, $ height)
{
$ Zoom = intval ($ zoom );
$ This-> zoom = $ zoom <1 | $ zoom> 20? 3: $ zoom;
$ Height = intval ($ height );
$ This-> Height = $ height <1 | $ height> 80? 30: $ height;
$ This-> Patten [] = new pattenclass ("# ffffff", 1 * $ this-> zoom );
$ This-> Patten [] = new pattenclass ("# ffffff", 3 * $ this-> zoom );
$ This-> Patten [] = new pattenclass ("#000000", 1 * $ this-> zoom );
$ This-> Patten [] = new pattenclass ("#000000", 3 * $ this-> zoom );
}
Function makecode ($ code) // code39 Decoding
{
Switch ($ code)
{
Case "0": Return ("202130302 ");
Case "1": Return ("302120203 ");
Case "2": Return ("203120203 ");
Case "3": Return ("303120202 ");
Case "4": Return ("202130203 ");
Case "5": Return ("302130202 ");
Case "6": Return ("203130202 ");
Case "7": Return ("202120303 ");
Case "8": Return ("302120302 ");
Case "9": Return ("203120302 ");
Case "A": Return ("302021203 ");
Case "B": Return ("203021203 ");
Case "C": Return ("303021202 ");
Case "D": Return ("202031203 ");
Case "E": Return ("302031202 ");
Case "F": Return ("203031202 ");
Case "G": Return ("202021303 ");
Case "H": Return ("302021302 ");
Case "I": Return ("203021300 ");
Case "J": Return ("202031302 ");
Case "K": Return ("302020213 ");
Case "L": Return ("203020213 ");
Case "M": Return ("303020212 ");
Case "N": Return ("202030213 ");
Case "O": Return ("302030212 ");
Case "p": Return ("203030212 ");
Case "Q": Return ("202020313 ");
Case "R": Return ("302020312 ");
Case "S": Return ("203020312 ");
Case "T": Return ("202030312 ");
Case "U": Return ("312020203 ");
Case "v": Return ("213020203 ");
Case "W": Return ("313020202 ");
Case "X": Return ("212030203 ");
Case "Y": Return ("312030202 ");
Case "Z": Return ("213030202 ");
Case "-": Return ("212020303 ");
Case ".": Return ("312020302 ");
Case "": returned ("213020302 ");
Case "*": Return ("212030302 ");
Case "$": Return ("212121202 ");
Case "/": Return ("212120212 ");
Case "+": Return ("212021212 ");
Case "%": Return ("202121212 ");
}
Return ("212030302 ");
}
Function display ($ code) // outputs a single character
{
$ Output = "";
For ($ I = 0; $ I <9; $ I ++)
$ Output. = "<TD Height = ". $ this-> height. "bgcolor = ". $ this-> Patten [$ code [$ I]-> color. "width = ". $ this-> Patten [$ code [$ I]-> width. "> </TD> ";
Return $ output;
}
Function decode ($ code) // all outputs
{
$ Output = "<Table width = ". ($ this-> height/2 * (strlen ($ code) + 2) * $ this-> zoom ). "Height = ". $ this-> height. "Border = 0 cellspacing = 0 cellpadding = 0 align =/" center/"> <tr> ";
$ Output. = $ this-> display ($ this-> makecode ("*"));
$ Output. = "<TD Height = ". $ this-> height. "bgcolor = ". $ this-> Patten [0]-> color. "width = ". $ this-> Patten [0]-> width. "> </TD> ";
$ Length = strlen ($ Code );
For ($ I = 0; $ I <$ length; $ I ++)
{
$ Output. = $ this-> display ($ this-> makecode ($ code [$ I]);
$ Output. = "<TD Height = ". $ this-> height. "bgcolor = ". $ this-> Patten [0]-> color. "width = ". $ this-> Patten [0]-> width. "> </TD> ";
}
$ Output. = $ this-> display ($ this-> makecode ("*"));
$ Output. = "</tr> </table> ";
Return $ output;
}
}
?>