/**/
/*---------------------------------------------------------------------*/
/**/
/* Function: Code39 - applies to Morovia Code39 Fontware */
/**/
/* Code39(text) Converts the input text into a Code 39 barcode string. The */
/**/
/* 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 */
/**/
/*should 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 scanner 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 should 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 scanner must be put in Code39 extended mode to read the symbol properly.*/
/**/
/*-----------------------------------------------------------------------------------------*/
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.*/
/**/
/*-----------------------------------------------------------------------------------*/
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;
}