예제 #1
0
파일: library.c 프로젝트: dwatson78/openrpt
int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename)
{
	FILE *file;
	uint8_t *buffer;
	unsigned long fileLen;
	unsigned int nRead = 0, n = 0;
	int ret;

	if (!strcmp(filename, "-")) {
		file = stdin;
		fileLen = 7100;
	} else {
		file = fopen(filename, "rb");
		if (!file) {
			strcpy(symbol->errtxt, "Unable to read input file");
			return ZERROR_INVALID_DATA;
		}

		/* Get file length */
		fseek(file, 0, SEEK_END);
		fileLen = ftell(file);
		fseek(file, 0, SEEK_SET);

		if(fileLen > 7100) {
			/* The largest amount of data that can be encoded is 7089 numeric digits in QR Code */
			strcpy(symbol->errtxt, "Input file too long");
			fclose(file);
			return ZERROR_INVALID_DATA;
		}
	}

	/* Allocate memory */
	buffer = (uint8_t *)malloc(fileLen * sizeof(uint8_t));
	if(!buffer) {
		strcpy(symbol->errtxt, "Internal memory error");
        if (strcmp(filename, "-"))
		    fclose(file);
		return ZERROR_MEMORY;
	}

	/* Read file contents into buffer */

	do
	{
		n = fread(buffer + nRead, 1, fileLen - nRead, file);
		if (ferror(file))
		{
			strcpy(symbol->errtxt, strerror(errno));
			nRead = 0;
			return ZERROR_INVALID_DATA;
		}
		nRead += n;
	} while (!feof(file) && (0 < n) && (nRead < fileLen));

	fclose(file);
	ret = ZBarcode_Encode(symbol, buffer, nRead);
	free(buffer);
	return ret;
}
예제 #2
0
void _ZINT(int n, unsigned char *s, C_LONGINT &Param2, C_LONGINT &Param3, C_TEXT &Param4, ARRAY_LONGINT &Param5, C_TEXT &returnValue)
{
	zint_symbol *sym = ZBarcode_Create();
	
	if(sym){
	
		sym->input_mode = UNICODE_MODE;
		
		sym->symbology = Param2.getIntValue();
		
		if(Param5.getSize() > 1)
			sym->option_1 = Param5.getIntValueAtIndex(1);
		
		if(Param5.getSize() > 2)
			sym->option_2 = Param5.getIntValueAtIndex(2);		
		
		if(Param5.getSize() > 3)
			sym->option_3 = Param5.getIntValueAtIndex(3);				
		
		sym->show_hrt = 0;	//no text
		
#ifdef DEBUG		
		sym->output_options = BARCODE_STDOUT;
		strncpy(sym->outfile, "dummy.txt", 10);
#endif		
		int err = ZBarcode_Encode(sym, s, n);
		
		if(!err){
#ifdef DEBUG			
			err = ZBarcode_Print(sym, 0);
#endif			
				
			err = ZBarcode_Buffer(sym, 0);
			
			if(!err){
				
				switch (Param3.getIntValue()) {
					case 1:
						_convertToSVG(sym, returnValue);				
						break;			
					default:
						_convertToText(sym, returnValue);		
						break;
				}
				
			}
			
		}else{
			CUTF8String err = (const uint8_t *)sym->errtxt;
			Param4.setUTF8String(&err);
		}
		
		ZBarcode_Delete(sym);
		
	}

}
예제 #3
0
파일: library.c 프로젝트: dwatson78/openrpt
int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, uint8_t *input, int length, int rotate_angle)
{
	int error_number;

	error_number = 0;

	error_number = ZBarcode_Encode(symbol, input, length);
	if(error_number != 0) {
		return error_number;
	}

	error_number = ZBarcode_Buffer(symbol, rotate_angle);
	return error_number;
}
int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle)
{
	int error_number;
	
	error_number = 0;
	
	error_number = ZBarcode_Encode(symbol, input, length);
	if(error_number != 0) {
		return error_number;
	}

	error_number = ZBarcode_Print(symbol, rotate_angle);
	return error_number;
}
예제 #5
0
bool QZint::save_to_file(QString filename)
{
	if (m_zintSymbol)
		ZBarcode_Delete(m_zintSymbol);
	
	QString fg_colour_hash = m_fgColor.name();
	QString bg_colour_hash = m_bgColor.name();

	m_lastError.clear();
	m_zintSymbol = ZBarcode_Create();
	m_zintSymbol->output_options=m_border;
	m_zintSymbol->symbology=m_symbol;
	m_zintSymbol->height=m_height;
	m_zintSymbol->whitespace_width=m_whitespace;
	m_zintSymbol->border_width=m_borderWidth;
	m_zintSymbol->option_1=m_securityLevel;
	m_zintSymbol->input_mode = m_input_mode;
	m_zintSymbol->option_2=m_width;
	if(m_hidetext) {
		m_zintSymbol->show_hrt = 0;
	} else {
		m_zintSymbol->show_hrt = 1;
	}
	if(m_symbol == BARCODE_PDF417) {
		m_zintSymbol->option_3=m_pdf417CodeWords;
	} else {
		m_zintSymbol->option_3 = m_option_3;
	}
	m_zintSymbol->scale=m_scale;
	QByteArray bstr=m_text.toUtf8();
    QByteArray pstr=m_primaryMessage.left(99).toLatin1();
    QByteArray fstr=filename.left(255).toLatin1();
	strcpy(m_zintSymbol->primary,pstr.data());
	strcpy(m_zintSymbol->outfile,fstr.data());
    QByteArray fgcol=fg_colour_hash.right(6).toLatin1();
    QByteArray bgcol=bg_colour_hash.right(6).toLatin1();
	strcpy(m_zintSymbol->fgcolour,fgcol.data());
	strcpy(m_zintSymbol->bgcolour,bgcol.data());
	int error = ZBarcode_Encode(m_zintSymbol, (unsigned char*)bstr.data(), bstr.length());
	if (error > WARN_INVALID_OPTION)
		m_lastError=m_zintSymbol->errtxt;
	error = ZBarcode_Print(m_zintSymbol, 0);
	if (error > WARN_INVALID_OPTION)
		m_lastError=m_zintSymbol->errtxt;
	if(error == 0) { return true; } else { return false; }
}
예제 #6
0
void QZint::encode()
{
	if (m_zintSymbol)
		ZBarcode_Delete(m_zintSymbol);

	m_lastError.clear();
	m_zintSymbol = ZBarcode_Create();
	m_zintSymbol->output_options=m_border;
	m_zintSymbol->symbology=m_symbol;
	m_zintSymbol->height=m_height;
	m_zintSymbol->whitespace_width=m_whitespace;
	m_zintSymbol->border_width=m_borderWidth;
	m_zintSymbol->option_1=m_securityLevel;
	m_zintSymbol->input_mode = m_input_mode;
	m_zintSymbol->option_2=m_width;
	if(m_hidetext) {
		m_zintSymbol->show_hrt = 0;
	} else {
		m_zintSymbol->show_hrt = 1;
	}
	if(m_symbol == BARCODE_PDF417) {
		m_zintSymbol->option_3=m_pdf417CodeWords;
	} else {
		m_zintSymbol->option_3 = m_option_3;
	}
	QByteArray bstr=m_text.toUtf8();
    QByteArray pstr=m_primaryMessage.left(99).toLatin1();
	strcpy(m_zintSymbol->primary,pstr.data());
	int error = ZBarcode_Encode(m_zintSymbol, (unsigned char*)bstr.data(), bstr.length());
	if (error > WARN_INVALID_OPTION)
		m_lastError=m_zintSymbol->errtxt;

	if (m_zintSymbol->symbology == BARCODE_MAXICODE)
		m_zintSymbol->height = 33;
	
	switch(m_zintSymbol->output_options) {
		case 0: m_border = NO_BORDER; break;
		case 2: m_border = BIND; break;
		case 4: m_border = BOX; break;
	}
	m_borderWidth = (BorderType)m_zintSymbol->border_width;
	m_whitespace = m_zintSymbol->whitespace_width;
}
예제 #7
0
파일: main.c 프로젝트: nitin-nizhawan/zint
int escape_char_process(struct zint_symbol *my_symbol, unsigned char input_string[], int length)
{
	int error_number;
	int i, j;
	unsigned char escaped_string[length + 1];

	i = 0;
	j = 0;

	do {
		if(input_string[i] == '\\') {
			switch(input_string[i + 1]) {
				case '0': escaped_string[j] = 0x00; i += 2; break; /* Null */
				case 'E': escaped_string[j] = 0x04; i += 2; break; /* End of Transmission */
				case 'a': escaped_string[j] = 0x07; i += 2; break; /* Bell */
				case 'b': escaped_string[j] = 0x08; i += 2; break; /* Backspace */
				case 't': escaped_string[j] = 0x09; i += 2; break; /* Horizontal tab */
				case 'n': escaped_string[j] = 0x0a; i += 2; break; /* Line feed */
				case 'v': escaped_string[j] = 0x0b; i += 2; break; /* Vertical tab */
				case 'f': escaped_string[j] = 0x0c; i += 2; break; /* Form feed */
				case 'r': escaped_string[j] = 0x0d; i += 2; break; /* Carriage return */
				case 'e': escaped_string[j] = 0x1b; i += 2; break; /* Escape */
				case 'G': escaped_string[j] = 0x1d; i += 2; break; /* Group Separator */
				case 'R': escaped_string[j] = 0x1e; i += 2; break; /* Record Separator */
				case '\\': escaped_string[j] = '\\'; i += 2; break;
				default: escaped_string[j] = input_string[i]; i++; break;
			}
		} else {
			escaped_string[j] = input_string[i];
			i++;
		}
		j++;
	} while (i < length);
	escaped_string[j] = '\0';

	error_number = ZBarcode_Encode(my_symbol, escaped_string, j);

	return error_number;
}
예제 #8
0
파일: bc-zint.c 프로젝트: DroiDev/glabels
lglBarcode *
gl_barcode_zint_new (const gchar          *id,
                           gboolean        text_flag,
                           gboolean        checksum_flag,
                           gdouble         w,
                           gdouble         h,
                           const gchar    *digits)
{
        lglBarcode          *gbc;
        struct zint_symbol  *symbol;
        gint                 result;

        symbol = ZBarcode_Create();

        /* Auto set to default size */
        if ( (w == 0) && (h == 0) )
        {
                w = DEFAULT_W;
                h = DEFAULT_H;
        }

        /* Assign type flag.  Pre-filter by length for subtypes. */
        if (g_ascii_strcasecmp (id, "AUSP") == 0)     { symbol->symbology = BARCODE_AUSPOST; }
        if (g_ascii_strcasecmp (id, "AUSRP") == 0)    { symbol->symbology = BARCODE_AUSREPLY; }
        if (g_ascii_strcasecmp (id, "AUSRT") == 0)    { symbol->symbology = BARCODE_AUSROUTE; }
        if (g_ascii_strcasecmp (id, "AUSRD") == 0)    { symbol->symbology = BARCODE_AUSREDIRECT; }
        if (g_ascii_strcasecmp (id, "AZTEC") == 0)    { symbol->symbology = BARCODE_AZTEC; }
        if (g_ascii_strcasecmp (id, "AZRUN") == 0)    { symbol->symbology = BARCODE_AZRUNE; }
        if (g_ascii_strcasecmp (id, "CBR") == 0)      { symbol->symbology = BARCODE_CODABAR; }
        if (g_ascii_strcasecmp (id, "Code1") == 0)    { symbol->symbology = BARCODE_CODEONE; }
        if (g_ascii_strcasecmp (id, "Code11") == 0)   { symbol->symbology = BARCODE_CODE11; }
        if (g_ascii_strcasecmp (id, "C16K") == 0)     { symbol->symbology = BARCODE_CODE16K; }
        if (g_ascii_strcasecmp (id, "C25M") == 0)     { symbol->symbology = BARCODE_C25MATRIX; }
        if (g_ascii_strcasecmp (id, "C25I") == 0)     { symbol->symbology = BARCODE_C25IATA; }
        if (g_ascii_strcasecmp (id, "C25DL") == 0)    { symbol->symbology = BARCODE_C25LOGIC; }
        if (g_ascii_strcasecmp (id, "Code32") == 0)   { symbol->symbology = BARCODE_CODE32; }
        if (g_ascii_strcasecmp (id, "Code39") == 0)   { symbol->symbology = BARCODE_CODE39; }
        if (g_ascii_strcasecmp (id, "Code39E") == 0)  { symbol->symbology = BARCODE_EXCODE39; }
        if (g_ascii_strcasecmp (id, "Code49") == 0)   { symbol->symbology = BARCODE_CODE49; }
        if (g_ascii_strcasecmp (id, "Code93") == 0)   { symbol->symbology = BARCODE_CODE93; }
        if (g_ascii_strcasecmp (id, "Code128") == 0)  { symbol->symbology = BARCODE_CODE128; }
        if (g_ascii_strcasecmp (id, "Code128B") == 0) { symbol->symbology = BARCODE_CODE128B; }
        if (g_ascii_strcasecmp (id, "DAFT") == 0)     { symbol->symbology = BARCODE_DAFT; }
        if (g_ascii_strcasecmp (id, "DMTX") == 0)     { symbol->symbology = BARCODE_DATAMATRIX; }
        if (g_ascii_strcasecmp (id, "DPL") == 0)      { symbol->symbology = BARCODE_DPLEIT; }
        if (g_ascii_strcasecmp (id, "DPI") == 0)      { symbol->symbology = BARCODE_DPIDENT; }
        if (g_ascii_strcasecmp (id, "KIX") == 0)      { symbol->symbology = BARCODE_KIX; }
        if (g_ascii_strcasecmp (id, "EAN") == 0)      { symbol->symbology = BARCODE_EANX; }
        if (g_ascii_strcasecmp (id, "HIBC128") == 0)  { symbol->symbology = BARCODE_HIBC_128; }
        if (g_ascii_strcasecmp (id, "HIBC39") == 0)   { symbol->symbology = BARCODE_HIBC_39; }
        if (g_ascii_strcasecmp (id, "HIBCDM") == 0)   { symbol->symbology = BARCODE_HIBC_DM; }
        if (g_ascii_strcasecmp (id, "HIBCQR") == 0)   { symbol->symbology = BARCODE_HIBC_QR; }
        if (g_ascii_strcasecmp (id, "HIBCPDF") == 0)  { symbol->symbology = BARCODE_HIBC_MICPDF; }
        if (g_ascii_strcasecmp (id, "HIBCMPDF") == 0) { symbol->symbology = BARCODE_HIBC_AZTEC; }
        if (g_ascii_strcasecmp (id, "HIBCAZ") == 0)   { symbol->symbology = BARCODE_C25INTER; }
        if (g_ascii_strcasecmp (id, "I25") == 0)      { symbol->symbology = BARCODE_C25INTER; }
        if (g_ascii_strcasecmp (id, "ISBN") == 0)     { symbol->symbology = BARCODE_ISBNX; }
        if (g_ascii_strcasecmp (id, "ITF14") == 0)    { symbol->symbology = BARCODE_ITF14; }
        if (g_ascii_strcasecmp (id, "GMTX") == 0)     { symbol->symbology = BARCODE_GRIDMATRIX; }
        if (g_ascii_strcasecmp (id, "GS1-128") == 0)  { symbol->symbology = BARCODE_EAN128; }
        if (g_ascii_strcasecmp (id, "LOGM") == 0)     { symbol->symbology = BARCODE_LOGMARS; }
        if (g_ascii_strcasecmp (id, "RSS14") == 0)    { symbol->symbology = BARCODE_RSS14; }
        if (g_ascii_strcasecmp (id, "RSSLTD") == 0)   { symbol->symbology = BARCODE_RSS_LTD; }
        if (g_ascii_strcasecmp (id, "RSSEXP") == 0)   { symbol->symbology = BARCODE_RSS_EXP; }
        if (g_ascii_strcasecmp (id, "RSSS") == 0)     { symbol->symbology = BARCODE_RSS14STACK; }
        if (g_ascii_strcasecmp (id, "RSSSO") == 0)    { symbol->symbology = BARCODE_RSS14STACK_OMNI; }
        if (g_ascii_strcasecmp (id, "RSSSE") == 0)    { symbol->symbology = BARCODE_RSS_EXPSTACK; }
        if (g_ascii_strcasecmp (id, "PHARMA") == 0)   { symbol->symbology = BARCODE_PHARMA; }
        if (g_ascii_strcasecmp (id, "PHARMA2") == 0)  { symbol->symbology = BARCODE_PHARMA_TWO; }
        if (g_ascii_strcasecmp (id, "PZN") == 0)      { symbol->symbology = BARCODE_PZN; }
        if (g_ascii_strcasecmp (id, "TELE") == 0)     { symbol->symbology = BARCODE_TELEPEN; }
        if (g_ascii_strcasecmp (id, "TELEX") == 0)    { symbol->symbology = BARCODE_TELEPEN_NUM; }
        if (g_ascii_strcasecmp (id, "JAPAN") == 0)    { symbol->symbology = BARCODE_JAPANPOST; }
        if (g_ascii_strcasecmp (id, "KOREA") == 0)    { symbol->symbology = BARCODE_KOREAPOST; }
        if (g_ascii_strcasecmp (id, "MAXI") == 0)     { symbol->symbology = BARCODE_MAXICODE; }
        if (g_ascii_strcasecmp (id, "MPDF") == 0)     { symbol->symbology = BARCODE_MICROPDF417; }
        if (g_ascii_strcasecmp (id, "MSI") == 0)      { symbol->symbology = BARCODE_MSI_PLESSEY; }
        if (g_ascii_strcasecmp (id, "MQR") == 0)      { symbol->symbology = BARCODE_MICROQR; }
        if (g_ascii_strcasecmp (id, "NVE") == 0)      { symbol->symbology = BARCODE_NVE18; }
        if (g_ascii_strcasecmp (id, "PLAN") == 0)     { symbol->symbology = BARCODE_PLANET; }
        if (g_ascii_strcasecmp (id, "POSTNET") == 0)  { symbol->symbology = BARCODE_POSTNET; }
        if (g_ascii_strcasecmp (id, "PDF") == 0)      { symbol->symbology = BARCODE_PDF417; }
        if (g_ascii_strcasecmp (id, "PDFT") == 0)     { symbol->symbology = BARCODE_PDF417TRUNC; }
        if (g_ascii_strcasecmp (id, "QR") == 0)       { symbol->symbology = BARCODE_QRCODE; }
        if (g_ascii_strcasecmp (id, "RM4") == 0)      { symbol->symbology = BARCODE_RM4SCC; }
        if (g_ascii_strcasecmp (id, "UPC-A") == 0)    { symbol->symbology = BARCODE_UPCA; }
        if (g_ascii_strcasecmp (id, "UPC-E") == 0)    { symbol->symbology = BARCODE_UPCE; }
        if (g_ascii_strcasecmp (id, "USPS") == 0)     { symbol->symbology = BARCODE_ONECODE; }
        if (g_ascii_strcasecmp (id, "PLS") == 0)      { symbol->symbology = BARCODE_PLESSEY; }


        result = ZBarcode_Encode(symbol, (unsigned char *)digits, 0);
        if (result)
        {
                gl_debug (DEBUG_BARCODE, "Zint Error: %s", symbol->errtxt);
                ZBarcode_Delete (symbol);
                return NULL;
        }

        if(!text_flag)
        {
                symbol->show_hrt = 0;
        }

        if (!ZBarcode_Render(symbol, (float) w, (float) h))
        {
                g_message("Zint Rendering Error: %s", symbol->errtxt);
                ZBarcode_Delete(symbol);
                return NULL;
        }

        /* Convert Sums provided by zint encode */
        gbc = render_zint(symbol, text_flag);

        ZBarcode_Delete(symbol);

        return gbc;
}