Code 39code Function

Source: Internet
Author: User
Tags 0xc0 control characters

/**/
/*---------------------------------------------------------------------*/
/**/
/* Function: code39-applies to morovia code39 fontware */
/**/
/* Code39 (text) converts the input text into a code 39 barcode string. */
/**/
/* Function throws off characters not in the code 39 Character Set ,*/
/**/
/* And adds start/stop characters .*/
/**/
/*----------------------------------------------------------------------*/
Public String code39 (string szinpara)
{
Int I, NPOs;
String szbuffer = "";
String szcharset = "0123456789. +-/$ % abcdefghijklmnopqrstuvwxyz ";
I = 0;
While (I <szinpara. length)
{
NPOs = szcharset. indexof (szinpara [I]);
If (szinpara [I] = '')
Szbuffer + = "= ";
Else if (NPOs> = 0)
Szbuffer + = szinpara [I];
I = I + 1;
}
Return "*" + szbuffer + "*";

}
/**/
/* -------------------------- Code39mod43 ---------------------------------------*/
/**/
/* Converts the input text into a code39 extended symbol. This function */
/**/
/* Shocould be used to format morovia code39 font, not code39 full ASCII font .*/
/**/
/* The text can be any combinations of ASCII characters. Note that the symbol */
/**/
/* Generated is an extended code39, and the specified must be put in code39 */
/**/
/* Extended mode to read the symbol properly .*/
/**/
/*----------------------------------------------------------------------------*/
Public String code39mod43 (string szinpara)
{
Int I = 0, NPOs, nchecksum = 0;
String inpara = "";
String szbuffer = "";
String szswap = "";
String szcharset = "0123456789abcdefghijklmnopqrstuvwxyz-. $/+ % ";
String szmappingset = "0123456789abcdefghijklmnopqrstuvwxyz-. =$/+ % ";
I = 0;
Inpara = szinpara;
While (I <inpara. length)
{
NPOs = szcharset. indexof (inpara [I]);
If (NPOs> = 0)
{
Szbuffer + = szmappingset [NPOs];
Nchecksum = nchecksum + NPOs;
}
I = I + 1;
}
Nchecksum = nchecksum % 43;
Szswap = '*' + szbuffer + szmappingset [nchecksum] + '*';
Return szswap;
}
/**/
/* -------------------------------- Code39ascii ----------------------------------------------*/
/**/
/* Converts the input text into a code39 extended symbol. This function shocould be */
/**/
/* Used to format morovia code39 font, not code39 full ASCII font. The text can be */
/**/
/* Any combinations of ASCII characters. Note that the symbol generated is an extended */
/**/
/* Code39, and the specified must be put in code39 extended mode to read the symbol properly .*/
/**/
/* Optional /*-----------------------------------------------------------------------------------------*/
Public String code39ascii (string szinpara)
{
Int I = 0, NPOs;
String szbuffer = "";
String szspecial = "";
String szwap = "";
Szspecial = specialchar (szinpara );
Szinpara = szspecial;
String szcharset = "0123456789abcdefghijklmnopqrstuvwxyz-." + (char) 240;
String szmappingset = "0123456789abcdefghijklmnopqrstuvwxyz-. =" + (char) 240;
While (I <szinpara. length)
{
NPOs = szcharset. indexof (szinpara [I]);
If (NPOs> = 0)
Szbuffer + = szmappingset [NPOs];
Else if (szinpara [I] = 0)
Szbuffer + = "% u ";
Else if (szinpara [I] = '') // control characters
Szbuffer + = ';
Else if (szinpara [I] = '/')
Szbuffer + = "/o ";
Else if (szinpara [I] = ':')
Szbuffer + = "/z ";
Else if (szinpara [I] = 64)
Szbuffer + = "% v ";
Else if (szinpara [I] = 96)
Szbuffer + = "% W ";
Else if (szinpara [I]> 0 & szinpara [I] <= 26)
{
Szbuffer + = '$ ';
Szbuffer + = (char) (szinpara [I] + 'a'-1 );
}
Else if (szinpara [I]> 32 & szinpara [I] <= 46)
{
Szbuffer + = '/';
Szbuffer + = (char) (szinpara [I] % 32) + 'a'-1 );
}
Else if (szinpara [I]> = 97 & szinpara [I] <= 122)
{
Szbuffer + = '+ ';
Szbuffer + = (char) (szinpara [I] % 32) + 'a'-1 );
}
Else if (szinpara [I]> = 27 & szinpara [I] <= 31)
{
Szbuffer + = '% ';
Szbuffer + = (char) (szinpara [I]-27 + 'A ');
}
Else if (szinpara [I]> = 59 & szinpara [I] <= 63)
{
Szbuffer + = '% ';
Szbuffer + = (char) (szinpara [I]-59 + 'F ');
}
Else if (szinpara [I]> = 91 & szinpara [I] <= 95)
{
Szbuffer + = '% ';
Szbuffer + = (char) (szinpara [I]-91 + 'k ');
}
Else if (szinpara [I]> = 123 & szinpara [I] <= 127)
{
Szbuffer + = '% ';
Szbuffer + = (char) (szinpara [I]-123 + 'P ');
}
I = I + 1;
}

// Replace null char
I = 0;
While (I <szbuffer. length)
{
If (szbuffer [I] = 240)
Szwap + = "% u ";
Else
Szwap + = szbuffer [I];
I ++;
}

Return '[' + szwap + ']';
}
/**/
/* ----------------------------------- Code39extended ------------------------------------*/
/**/
/* Converts the input text into a code39 extended symbol. It accepts any ASCII */
/**/
/* Characters as input. The only difference from function code39ascii is the former */
/**/
/* Is designed to work with morovia code39 (full ASCII) font and the latter is designed */
/**/
/* To work with morovia code39 font .*/
/**/
/* Optional /*-----------------------------------------------------------------------------------*/
Public String code39extended (string szinpara)
{
Int I = 0; char ch;
String szswap = "";
String szspecial = "";
String szoutput = "";
Szspecial = specialchar (szinpara );
Szswap = szspecial;

For (I = 0; I <szswap. length; I ++)
{
Ch = szswap [I];
If (CH = 240)
Szoutput + = (char) 0xc0;
Else if (CH> 0 & Ch <= 0x1f)
Szoutput + = (char) (0xc0 + CH );
Else if (CH = '') // space is mapped to equal sign
Szoutput + = ';
Else if (CH = '*')
Szoutput + = (char) 0xf4;
Else if (CH = ')
Szoutput + = (char) 0xf0;
Else if (CH = '[')
Szoutput + = (char) 0xf1;
Else if (CH = ']')
Szoutput + = (char) 0xf2;
Else if (CH = 0x7f)
Szoutput + = (char) 0xe0;
Else
Szoutput + = CH;
}

Szoutput = '[' + szoutput + ']';
Return szoutput;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.