⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 barcode.txt

📁 VC++开源条形码代码。自动生成条形码和打印功能
💻 TXT
📖 第 1 页 / 共 5 页
字号:
**********************
C++实现
**********************
/*****************************************************************/
/* 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.                                         */
/*****************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>

/* ------------------------ */
/*     System Variables     */
/* ------------------------ */

static  int  StrCnt;
static  char StrFunction [64][257];

/* ---------------------- */
/*  Standard Prototypes   */
/* ---------------------- */

extern int  asc (char *);
extern char *mid (char *, int, int);
char FindMod10Digit(char *);
char *CalcMSICheckDigit(char *);

/* ------------------- */
/*  User's Prototypes  */ 
/* ------------------- */

static int TRUE	 = 1;
static int FALSE = 0;
  
long  IDAutomation_UPCe(char *pcDataToEncode, char *szReturnVal, long iSize);;
long  IDAutomation_Codabar(char *pcDataToEncode, char *szReturnVal, long iSize);;
long  IDAutomation_Code128a(char *pcDataToEncode, char *szReturnVal, long iSize);;
long  IDAutomation_Code128b(char *pcDataToEncode, char *szReturnVal, long iSize);
long  IDAutomation_Code128c(char *pcDataToEncode, char *szReturnVal, long iSize);
long  IDAutomation_Interleaved2of5(char *pcDataToEncode, char *szReturnVal, long iSize);
long  IDAutomation_Interleaved2of5Mod10(char *pcDataToEncode, char *szReturnVal, long iSize);
long  IDAutomation_Code39(char *pcDataToEncode, char *szReturnVal, long iSize);
long  IDAutomation_Code39Mod43(char *pcDataToEncode, char *szReturnVal, long iSize);
long  IDAutomation_EAN8(char *pcDataToEncode, char *szReturnVal, long iSize);
long  IDAutomation_EAN13(char *pcDataToEncode, char *szReturnVal, long iSize);
long  IDAutomation_UPCa(char *pcDataToEncode, char *szReturnVal, long iSize);
long  IDAutomation_MSI(char *pcDataToEncode, char *szReturnVal, long iSize);
long  IDAutomation_Postnet(char *pcDataToEncode, char *szReturnVal, long iSize);
long  IDAutomation_Code128(char *DataToEncode, int ApplyTilde, char *szReturnVal, long iSize);
long  IDAutomation_Code128HumanReadable(char *DataToEncode, int ApplyTilde, char *szReturnVal, long iSize);
long  IDAutomation_UCC128(char *DataToEncode, char *szReturnVal, long iSize);
long  IDAutomation_Code93(char *DataToEncode, char *szReturnVal, long iSize);


/* --------------------- */
/*  Run Time Functions   */
/* --------------------- */

//CMemLeadDetect memLeakDetect;///mem leak 
char* strupr(char* str)
{
	char returnString[512];
	
	/*//char *returnString = new char[512] ;*/
	int PrintBuffer=0;
	int x=0;
for (x=1;x<= (int)strlen(str);++x)
{
	int CurrentValue = asc(mid(str, x, 1));
  if (CurrentValue >= 97 && CurrentValue <= 122)
			PrintBuffer += sprintf(returnString + PrintBuffer ,"%c", CurrentValue - 32);
	 else 
	 		PrintBuffer += sprintf(returnString + PrintBuffer ,"%c", CurrentValue );

}
sprintf(str,"%s",returnString);
return (char*)str;
}
char* strrev(char* str)
{

if (NULL==str)return str; 
int l=strlen(str)-1;
if (1==l)return str;
int x=0;
for(x=0;x<l;x++,l--)
{
str[x]^=str[l];  
str[l]^=str[x];  
str[x]^=str[l];
}
l=0;
return (char*)str;
}

extern char *mid(char *S, int start, int length)
{
	if(++StrCnt==64) 
	{
		StrCnt = 0;
	}
	
	if (start > (int) strlen(S))
	{ 
		StrFunction[StrCnt][0]='\0'; 
	}
	else
	{
		strncpy (StrFunction[StrCnt], &S [start-1], length);
	}

	StrFunction[StrCnt][length]='\0';
	
	return StrFunction[StrCnt];
}




extern int asc(char *z)
{
static int q;
q = 0;
memmove(&q,z,1);
return q;
}


/* ---------------------- */
/*  User Subs/Functions   */
/* ---------------------- */


long  IDAutomation_Code128a(char *DataToEncode,  char *output, long iSize)
{
	if(DataToEncode == NULL)
		return 1;
	if(strlen(DataToEncode) == 0)
		return 1;
	
	char DataToPrint[512];
	//DataToPrint = new char[512];

	char PrintableString[512];
	//PrintableString = new char[512];

	int  C128Start;
	int  C128StartA;
	int  C128StartB;
	int  C128StartC;
	int  C128Stop;
	int  weightedTotal;
	int  I;
	int  CurrentChar;
	int  CurrentValue;
	int  CheckDigitValue;
	int  CheckDigit;
	char C128CheckDigit;
	//char C128CurrentChar;
	int C128CurrentChar;
	int BufferCounter = 0;

	C128StartA=203;
	C128StartB=204;
	C128StartC=205;
	C128Stop=206;

	/* Here we select character set A */
	C128Start=C128StartA;

	/* <<<< Calculate Modulo 103 Check Digit >>>> */
	/* Set WeightedTotal to the value of the start character */
	weightedTotal=C128Start-100;

	for(I=1;I <= (int)strlen(DataToEncode);I++)
	{
		/* Get the ASCII value of each character */
		CurrentChar=(asc(mid(DataToEncode,I,1)));

		/* Get the Code 128 value of CurrentChar according to chart */
  		if(CurrentChar<135) {CurrentValue=CurrentChar-32;}
  		if(CurrentChar>134) {CurrentValue=CurrentChar-100;}

		/* Multiply by the weighting character */
  		CurrentValue=CurrentValue*I;

		/* Add the values together to get the weighted total*/
  		weightedTotal=weightedTotal+CurrentValue;
	}

	/* divide the WeightedTotal by 103 and get the remainder, this is the CheckDigitValue*/
	CheckDigitValue = (int) (weightedTotal % 103);

	/* Now that we have the CheckDigitValue, find the corresponding ASCII character from the table */
	if(CheckDigitValue < 95 && CheckDigitValue > 0)
	{
		CheckDigit = CheckDigitValue + 32;
	}
	if(CheckDigitValue > 94)
	{ 
		CheckDigit = CheckDigitValue + 100;
	}
	if(CheckDigitValue == 0)
	{
		CheckDigit = 194;
	}
	C128CheckDigit=CheckDigit;
/*	for(I=1;I <= (int)strlen(DataToEncode);I++)
	{
		C128CurrentChar = asc((mid(DataToEncode,I,1)));
		//if(C128CurrentChar==' ') 
		if(C128CurrentChar==32) 
		{
			//C128CurrentChar=(char)194;
			C128CurrentChar=194;
		}
		//BufferCounter += sprintf(DataToPrint + BufferCounter, "%c", DataToEncode[I-1]);
		BufferCounter += sprintf(DataToPrint + BufferCounter, "%c", C128CurrentChar);
		//strcat(DataToPrint,&C128CurrentChar);
	}
*/
/* Check for spaces or "00" and print ASCII 194 instead */
	/* place changes in DataToPrint */
	BufferCounter = 0;
	for(I=1;I <= (int)strlen(DataToEncode);I++)
	{
		C128CurrentChar=DataToEncode[I-1];
		if(C128CurrentChar==' ') 
		{
			C128CurrentChar = (char)194;
		}
		BufferCounter += sprintf(DataToPrint + BufferCounter, "%c", C128CurrentChar);
	}
	/* Get PrintableString */
	sprintf(PrintableString,"%c%s%c%c",C128Start,DataToPrint,C128CheckDigit,C128Stop);


	iSize = (long)strlen(PrintableString); 
	strncpy(output, PrintableString, strlen(PrintableString)); 
	return 0;
}



long  IDAutomation_Code128b(char *DataToEncode, char *output, long iSize)
{
	if(DataToEncode == NULL)
		return 1;
	if(strlen(DataToEncode) == 0)
		return 1;
	
	char DataToPrint[512];
	//DataToPrint = new char;

	char PrintableString[512];
	//PrintableString = new char[512];

	int BufferCounter = 0;
	int  C128Start;
	int  C128StartA;
	int  C128StartB;
	int  C128StartC;
	int  C128Stop;
	int  weightedTotal;
	int  I;
	int  CurrentChar;
	int  CurrentValue;
	int  CheckDigitValue;
	int  CheckDigit;
	char C128CheckDigit;
	char C128CurrentChar;

	C128StartA=203;
	C128StartB=204;
	C128StartC=205;
	C128Stop=206;

	/* Here we select character set A */
	C128Start=C128StartB;

	/* <<<< Calculate Modulo 103 Check Digit >>>> */
	/* Set WeightedTotal to the value of the start character */
	weightedTotal=C128Start-100;

	for(I=1;I <= (int)strlen(DataToEncode);I++)
	{
		/* Get the ASCII value of each character */
		CurrentChar=(asc(mid(DataToEncode,I,1)));

		/* Get the Code 128 value of CurrentChar according to chart */
		if(CurrentChar<135) {CurrentValue=CurrentChar-32;}
		if(CurrentChar>134) {CurrentValue=CurrentChar-100;}

		/* Multiply by the weighting character */
		CurrentValue=CurrentValue*I;

		/* Add the values together */
		weightedTotal=weightedTotal+CurrentValue;
	}

	/* divide the WeightedTotal by 103 and get the remainder, this is the CheckDigitValue	*/
	CheckDigitValue = (int) (weightedTotal % 103);

	/* Now that we have the CheckDigitValue, find the corresponding ASCII character
	from the table */
	if(CheckDigitValue<95 && CheckDigitValue>0) {CheckDigit=CheckDigitValue+32;}
	if(CheckDigitValue>94) {CheckDigit=CheckDigitValue+100;}
	if(CheckDigitValue==0) {CheckDigit=194;}
	C128CheckDigit=CheckDigit;

	/* Check for spaces or "00" and print ASCII 194 instead */
	/* place changes in DataToPrint */
	BufferCounter = 0;
	for(I=1;I <= (int)strlen(DataToEncode);I++)
	{
		C128CurrentChar=DataToEncode[I-1];
		if(C128CurrentChar==' ') 
		{
			C128CurrentChar = (char)194;
		}
		BufferCounter += sprintf(DataToPrint + BufferCounter, "%c", C128CurrentChar);
	}

	/* Get PrintableString */
	sprintf(PrintableString,"%c%s%c%c",C128Start, DataToPrint,C128CheckDigit,C128Stop);

	iSize = (long)strlen(PrintableString); 
	strncpy(output, PrintableString, strlen(PrintableString)); 
	return 0;
} //end Code128B()


long  IDAutomation_Code128c(char *DataToEncode, char *output, long iSize)
{
	if(DataToEncode == NULL)
		return 1;
	if(strlen(DataToEncode) == 0)
		return 1;
	
	char DataToPrint[512];
	//DataToPrint = new char[512];

	char PrintableString[512];
	//PrintableString = new char[512];

	char OnlyCorrectData[512];
	//OnlyCorrectData = new char[512];

	char TempOnlyCorrectData[512];
	//TempOnlyCorrectData = new char[512];

	int  C128Start;
	int  C128Stop;
	int  weightedTotal;
	int  WeightValue;
	int  I;
	int  CurrentValue;
	int  CheckDigitValue;
	char C128CheckDigit;
	int PrintBuffer = 0;
	/* 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))) != 0) 
		{
			PrintBuffer += sprintf(TempOnlyCorrectData + PrintBuffer, "%s", mid(DataToEncode,I,1));
		}
	}

	

	/* Check for an even number of digits, add 0 if not even */
	int rem = (int) (strlen(TempOnlyCorrectData) % 2);
	if(rem == 1)	
	{
		sprintf(OnlyCorrectData, "0%s", TempOnlyCorrectData);
	}
	else
		sprintf(OnlyCorrectData, "%s", TempOnlyCorrectData);

	/* Assign start & stop codes */
	C128Start=205;
	C128Stop=206;

	/* <<<< Calculate Modulo 103 Check Digit and generate DataToPrint >>>> */
	/* Set WeightedTotal to the Code 128 value of the start character */
	weightedTotal=105;
	WeightValue = 1;
	PrintBuffer = 0;
	for(I=1;I <= (int)strlen(OnlyCorrectData);I = I + 2)
	{
		/* Get the value of each number pair */
		CurrentValue = atoi(mid(OnlyCorrectData, I, 2));

		/* Get the DataToPrint */
		if(CurrentValue < 95 && CurrentValue > 0) 
		{
			PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentValue + 32);
		}
		if(CurrentValue>94) 
		{
			PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentValue + 100);
		}
		if(CurrentValue==0) 
		{
			PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", (char)194);
		}

		/* Multiply by the weighting character */
		CurrentValue=CurrentValue * WeightValue;

		/* Add the values together to get the weighted total*/
		weightedTotal = weightedTotal + CurrentValue;
		WeightValue = WeightValue + 1;
	}

	/* Divide the weighted total by 103 and get the remainder, this is the CheckDigitValue
	*/
	CheckDigitValue = (int)(weightedTotal % 103);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -