📄 barcode.txt
字号:
/* All rights reserved. */
/* Redistribution and use of this code in source and/or binary */
/* forms, with or without modification, are permitted provided */
/* that: (1) all copies of the source code retain the above */
/* unmodified copyright notice and this entire unmodified */
/* section of text, (2) You or Your organization owns a valid */
/* Developer License to this product from IDAutomation.com */
/* and, (3) when any portion of this code is bundled in any */
/* form with an application, a valid notice must be provided */
/* within the user documentation, start-up screen or in the */
/* help-about section of the application that specifies */
/* IDAutomation.com as the provider of the Software bundled */
/* with the application. */
/*****************************************************************/
long IDAutomation_Postnet (char *DataToEncode, char *output, long iSize)
{
/* Enter all the numbers without dashes */
if(DataToEncode == NULL)
return 1;
if(strlen(DataToEncode) == 0)
return 1;
char OnlyCorrectData[512];
//OnlyCorrectData = new char[512];
char PrintableString[512];
//PrintableString = new char[512];
int BufferCounter = 0;
int I;
int weightedTotal;
int CheckDigit;
/* Check to make sure data is numeric and remove dashes, etc. */
for(I=1;I <= (int)strlen(DataToEncode);I++)
{
/* Add all numbers to OnlyCorrectData string */
if(isdigit(asc(mid(DataToEncode,I,1))))
BufferCounter += sprintf(OnlyCorrectData + BufferCounter,"%s", mid(DataToEncode,I,1));
}
/* <<<< Calculate Check Digit >>>>. which is just the sum of the numbers */
weightedTotal=0;
for(I = 1;I <= (int)strlen(OnlyCorrectData);I++)
{
weightedTotal += atoi(mid(OnlyCorrectData, I, 1));
}
/* Find the CheckDigit by finding the number + weightedTotal that = a multiple of 10 */
/* divide by 10, get the remainder and subtract from 10 */
I = (int)((weightedTotal % 10));
if( I!= 0)
CheckDigit=(10-I);
else
CheckDigit=0;
BufferCounter = 0;
BufferCounter += sprintf(PrintableString + BufferCounter,"(%s%i)", OnlyCorrectData, CheckDigit);
iSize = (long)strlen(PrintableString);
strncpy(output, PrintableString, strlen(PrintableString));
return 0;
}
/*****************************************************************/
/* ANSI C Functions for IDAutomation Barcode Fonts */
/* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
/* All rights reserved. */
/* Redistribution and use of this code in source and/or binary */
/* forms, with or without modification, are permitted provided */
/* that: (1) all copies of the source code retain the above */
/* unmodified copyright notice and this entire unmodified */
/* section of text, (2) You or Your organization owns a valid */
/* Developer License to this product from IDAutomation.com */
/* and, (3) when any portion of this code is bundled in any */
/* form with an application, a valid notice must be provided */
/* within the user documentation, start-up screen or in the */
/* help-about section of the application that specifies */
/* IDAutomation.com as the provider of the Software bundled */
/* with the application. */
/*****************************************************************/
long IDAutomation_EAN8 (char *DataToEncode, char *output, long iSize)
{
/* The purpose of this code is to calculate the EAN-8 barcode */
/* Enter all the numbers without dashes */
if(DataToEncode == NULL)
return 1;
if(strlen(DataToEncode) == 0)
return 1;
char DataToEncode2[512];
//DataToEncode2 = new char[512];
char DataToPrint[512];
//DataToPrint = new char[512];
char OnlyCorrectData[512];
//OnlyCorrectData = new char[512];
char PrintableString[512];
//PrintableString = new char[512];
int I;
int Factor;
int weightedTotal;
char CurrentChar;
int CheckDigit;
int PrintBuffer = 0;
sprintf(DataToEncode2,"%s",DataToEncode);
/* Check to make sure data is numeric and remove dashes, etc. */
for(I=1;I <= (int)strlen(DataToEncode2);I++)
{
/* Add all numbers to OnlyCorrectData string */
if(isdigit(asc(mid(DataToEncode2,I,1))))
{
PrintBuffer += sprintf(OnlyCorrectData + PrintBuffer,"%c", asc(mid(DataToEncode2,I,1)));
}
}
if(strlen(OnlyCorrectData) >= 7)
sprintf(DataToEncode2,"%s",mid(OnlyCorrectData, 1, 7));
else
sprintf(DataToEncode2,"%s","0005000");
/* <<<< Calculate Check Digit >>>> */
Factor=3;
weightedTotal=0;
for(I = (int)strlen(DataToEncode2);I >= 1;I = I +- 1)
{
/* Get the value of each number starting at the end */
CurrentChar=asc(mid(DataToEncode2,I,1));
/* multiply by the weighting factor which is 3,1,3,1... */
/* and add the sum together */
weightedTotal=weightedTotal+CurrentChar*Factor;
/* change factor for next calculation */
Factor=4-Factor;
}
/* Find the CheckDigit by finding the number + weightedTotal that = a multiple of 10 */
/* divide by 10, get the remainder and subtract from 10 */
I = (int)(weightedTotal % 10);
if(I!=0)
CheckDigit=(10-I);
else
CheckDigit=0;
sprintf(DataToEncode2,"%s%i", DataToEncode2, CheckDigit);
/* Now that have the total number including the check digit, determine character to print */
/* for proper barcoding */
PrintBuffer = 0;
for(I = 1;I <= (int)strlen(DataToEncode2);I++)
{
/* Get the ASCII value of each number */
CurrentChar = asc(mid(DataToEncode2,I,1));
/* Print different barcodes according to the location of the CurrentChar and CurrentEncoding */
if(I==1)
{
/* For the first character print the normal guard pattern */
/* and then the barcode without the human readable character */
PrintBuffer += sprintf(DataToPrint + PrintBuffer,"(%c",CurrentChar);
}
if(I==2)
{
PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentChar);
}
if(I==3)
{
PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentChar);
}
if(I==4)
{
/* Print the center guard pattern after the 6th character */
PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c*", CurrentChar);
}
if(I==5)
{
PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentChar+27);
}
if(I==6)
{
PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentChar+27);
}
if(I==7)
{
PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentChar+27);
}
if(I==8)
{
/* Print the check digit as 8th character + normal guard pattern */
PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c(", CurrentChar+27);
}
}
/* Get Printable String */
sprintf(PrintableString,"%s",DataToPrint);
iSize = (long)strlen(PrintableString);
strncpy(output, PrintableString, strlen(PrintableString));
return 0;
}
/*****************************************************************/
/* ANSI C Functions for IDAutomation Barcode Fonts */
/* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
/* All rights reserved. */
/* Redistribution and use of this code in source and/or binary */
/* forms, with or without modification, are permitted provided */
/* that: (1) all copies of the source code retain the above */
/* unmodified copyright notice and this entire unmodified */
/* section of text, (2) You or Your organization owns a valid */
/* Developer License to this product from IDAutomation.com */
/* and, (3) when any portion of this code is bundled in any */
/* form with an application, a valid notice must be provided */
/* within the user documentation, start-up screen or in the */
/* help-about section of the application that specifies */
/* IDAutomation.com as the provider of the Software bundled */
/* with the application. */
/*****************************************************************/
long IDAutomation_EAN13 (char *DataToEncode, char *output, long iSize)
{
if(DataToEncode == NULL)
return 1;
if(strlen(DataToEncode) == 0)
return 1;
int StringLength = 0;
int I = 0;
int Factor = 3;
int weightedTotal = 0;
int CurrentChar = 0;
int DataToPrintBuffer = 0;
int CheckDigit = 0;
int LeadingDigit = 0;
int CurrentEncoding = 0;
char LPrintableString[512];
//LPrintableString = new char[512];
char ActualDataToEncode[20];
//ActualDataToEncode = new char[20];
char DataToPrint[20];
//DataToPrint = new char[20];
char EAN2AddOn[3];
//EAN2AddOn = new char[3];
char OnlyCorrectData[20];
//OnlyCorrectData = new char[20];
char EAN5AddOn[6];
//EAN5AddOn = new char[6];
char EANAddOnToPrint[15];
//EANAddOnToPrint = new char[15];
char Encoding[20];
//Encoding = new char[20];
char Temp[512];
//Temp = new char[512];
StringLength = (int)strlen(DataToEncode);
for(I = 0;I < StringLength;I++)
{
if(isdigit((int)DataToEncode[I]))
{
DataToPrintBuffer += sprintf(OnlyCorrectData + DataToPrintBuffer, "%c", DataToEncode[I]);
}
}
DataToPrintBuffer = 0;
if(strlen(OnlyCorrectData) < 12 || strlen(OnlyCorrectData) == 16 || strlen(OnlyCorrectData) > 18)
{
sprintf(OnlyCorrectData, "%s", "0000000000000");
}
if(strlen(OnlyCorrectData) == 12 || strlen(OnlyCorrectData) == 13)
{
sprintf(LPrintableString, "%s", mid(OnlyCorrectData, 1, 12));
}
else if(strlen(OnlyCorrectData) == 14)
{
sprintf(LPrintableString,"%s", mid(OnlyCorrectData, 1, 12));
sprintf(EAN2AddOn,"%s", mid(OnlyCorrectData, 13, 2));
}
else if(strlen(OnlyCorrectData) == 15)
{
sprintf(LPrintableString,"%s", mid(OnlyCorrectData, 1, 12));
sprintf(EAN2AddOn,"%s", mid(OnlyCorrectData, 14, 2));
}
else if(strlen(OnlyCorrectData) == 17)
{
sprintf(LPrintableString,"%s", mid(OnlyCorrectData, 1, 12));
sprintf(EAN5AddOn,"%s", mid(OnlyCorrectData, 13, 5));
}
else if(strlen(OnlyCorrectData) == 18)
{
sprintf(LPrintableString,"%s", mid(OnlyCorrectData, 1, 12));
sprintf(EAN5AddOn,"%s", mid(OnlyCorrectData, 14, 5));
}
/* <<<< Calculate Check Digit >>>> */
for(I = (int)strlen(LPrintableString);I >= 1;I--)
{
/* Get the value of each number starting at the end */
CurrentChar = asc(mid(LPrintableString,I,1)) - 48;
/* multiply by the weighting factor which is 3,1,3,1... */
/* and add the sum together */
weightedTotal = weightedTotal + (CurrentChar * Factor);
/* change factor for next calculation */
Factor = 4 - Factor;
}
/* Find the CheckDigitValue by finding the number + weightedTotal that = a multiple of 10 */
/* divide by 10, get the remainder and subtract from 10 */
I = (int)(weightedTotal % 10);
if(I != 0)
CheckDigit=(10 - I);
else
CheckDigit = 0;
/* Now we must encode the leading digit into the left half of the EAN-13 symbol */
/* by using variable parity between character sets A and B */
LeadingDigit = (((asc(mid(LPrintableString, 1, 1))))-48);
if(LeadingDigit == 0)
sprintf(Encoding, "AAAAAACCCCCC");
else if(LeadingDigit == 1)
sprintf(Encoding, "AABABBCCCCCC");
else if(LeadingDigit == 2)
sprintf(Encoding, "AABBABCCCCCC");
else if(LeadingDigit == 3)
sprintf(Encoding, "AABBBACCCCCC");
else if(LeadingDigit == 4)
sprintf(Encoding, "ABAABBCCCCCC");
else if(LeadingDigit == 5)
sprintf(Encoding, "ABBAABCCCCCC");
else if(LeadingDigit == 6)
sprintf(Encoding, "ABBBAACCCCCC");
else if(LeadingDigit == 7)
sprintf(Encoding, "ABABABCCCCCC");
else if(LeadingDigit == 8)
sprintf(Encoding, "ABABBACCCCCC");
else if(LeadingDigit == 9)
sprintf(Encoding, "ABBABACCCCCC");
/* add the check digit to the end of the barcode & remove the leading digit */
sprintf(ActualDataToEncode, "%s%i", mid(LPrintableString, 2, 11), CheckDigit);
/* Now that we have the total number including the check digit, determine character to print */
/* for proper barcoding: */
for(I = 1;I <= (int)strlen(ActualDataToEncode);I++)
{
/* Get the ASCII value of each number excluding the first number because */
/* it is encoded with variable parity */
CurrentChar = asc(mid(ActualDataToEncode, I, 1));
CurrentEncoding = asc(mid(Encoding, I, 1));
/* Print different barcodes according to the location of the CurrentChar and CurrentEncoding */
if(CurrentEncoding == 'A')
DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer, "%c", CurrentChar);
else if(CurrentEncoding == 'B')
DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer, "%c", CurrentChar + 17);
else if(CurrentEncoding=='C')
DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer, "%c", CurrentChar + 27);
/* add in the 1st character along with guard patterns */
if(I == 1)
{
DataToPrintBuffer = 0;
/* For the LeadingDigit print the human readable character, */
/* the normal guard pattern and then the rest of the barcode */
sprintf(Temp,"%i",LeadingDigit);
if(LeadingDigit > 4)
{
sprintf(Temp,"%c(%s",asc(Temp) + 64, DataToPrint);
DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer, "%s", Temp);
}
else if(LeadingDigit < 5)
{
sprintf(Temp,"%c(%s",asc(Temp) + 37, DataToPrint);
DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer,"%s",Temp);
}
}
else if(I==6)
{
/* Print the center guard pattern after the 6th character */
DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer, "*");
}
else if(I==12)
{
/* For the last character (12) print the normal guard pattern */
/* after the barcode */
DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer, "(");
}
}
/* Process 5 digit add on if it exists */
if(strlen(EAN5AddOn) == 5)
{
/* Get check digit for add on */
Factor = 3;
weightedTotal=0;
for(I = (int)strlen(EAN5AddOn);I >= 1;I--)
{
/* Get the value of each number starting at the end */
CurrentChar = asc(mid(EAN5AddOn, I, 1)) - 48;
/* multiply by the weighting factor which is 3,9,3,9. */
/* and add the sum together */
if(Factor == 3)
weightedTotal = weightedTotal + (CurrentChar * 3);
else if(Factor == 1)
weightedTotal = weightedTotal + CurrentChar * 9;
/* change factor for next calculation */
Factor = 4 - Factor;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -