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);
		
	}

}
Example #2
0
int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle)
{
	int error_number;

	error_number = 0;

	error_number = ZBarcode_Encode_File(symbol, filename);
	if(error_number != 0) {
		return error_number;
	}

	return ZBarcode_Print(symbol, rotate_angle);
}
Example #3
0
int ZBarcode_Encode_and_Print(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_Print(symbol, rotate_angle);
	return error_number;
}
Example #4
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; }
}
Example #5
0
int main(int argc, char **argv)
{
	struct zint_symbol *my_symbol;
	int c;
	int error_number;
	int rotate_angle;
	int generated;
	int batch_mode;
	
	error_number = 0;
	rotate_angle = 0;
	generated = 0;
	my_symbol = ZBarcode_Create();
	my_symbol->input_mode = UNICODE_MODE;
	batch_mode = 0;

	if(argc == 1)
		die(help_usage);

	while(1) {
		int option_index = 0;
		static struct option long_options[] = {
			{"help", 0, 0, 'h'},
			{"types", 0, 0, 't'},
			{"bind", 0, 0, 0},
			{"box", 0, 0, 0},
			{"directeps", 0, 0, 0},
			{"directpdf", 0, 0, 0},
			{"directpng", 0, 0, 0},
			{"directsvg", 0, 0, 0},
			{"dump", 0, 0, 0},
			{"barcode", 1, 0, 'b'},
			{"height", 1, 0, 0},
			{"whitesp", 1, 0, 'w'},
			{"border", 1, 0, 0},
			{"data", 1, 0, 'd'},
			{"output", 1, 0, 'o'},
			{"input", 1, 0, 'i'},
			{"fg", 1, 0, 0},
			{"bg", 1, 0, 0},
			{"cols", 1, 0, 0},
			{"vers", 1, 0, 0},
			{"rotate", 1, 0, 0},
			{"secure", 1, 0, 0},
			{"reverse", 1, 0, 'r'},
			{"mode", 1, 0, 0},
			{"primary", 1, 0, 0},
			{"scale", 1, 0, 0},
			{"gs1", 0, 0, 0},
			{"kanji", 0, 0, 0},
			{"sjis", 0, 0, 0},
			{"binary", 0, 0, 0},
			{"notext", 0, 0, 0},
			{"square", 0, 0, 0},
			{"init", 0, 0, 0},
			{"smalltext", 0, 0, 0},
			{"batch", 0, 0, 0},
			{0, 0, 0, 0}
		};
		c = getopt_long(argc, argv, "htb:w:d:o:i:rcmp", long_options, &option_index);
		if(c == -1) break; 
		
		switch(c) {
			case 0: 
				if(!strcmp(long_options[option_index].name, "bind")) {
					my_symbol->output_options += BARCODE_BIND;
				}
				if(!strcmp(long_options[option_index].name, "box")) {
					my_symbol->output_options += BARCODE_BOX;
				}
				if(!strcmp(long_options[option_index].name, "init")) {
					my_symbol->output_options += READER_INIT;
				}
				if(!strcmp(long_options[option_index].name, "smalltext")) {
					my_symbol->output_options += SMALL_TEXT;
				}
				if(!strcmp(long_options[option_index].name, "directeps")) {
					my_symbol->output_options += BARCODE_STDOUT;
					strncpy(my_symbol->outfile, "dummy.eps", 10);
				}
				if(!strcmp(long_options[option_index].name, "directpdf")) {
					my_symbol->output_options += BARCODE_STDOUT;
					strncpy(my_symbol->outfile, "dummy.pdf", 10);
				}
				if(!strcmp(long_options[option_index].name, "directpng")) {
					my_symbol->output_options += BARCODE_STDOUT;
					strncpy(my_symbol->outfile, "dummy.png", 10);
				}
				if(!strcmp(long_options[option_index].name, "directsvg")) {
					my_symbol->output_options += BARCODE_STDOUT;
					strncpy(my_symbol->outfile, "dummy.svg", 10);
				}
				if(!strcmp(long_options[option_index].name, "dump")) {
					my_symbol->output_options += BARCODE_STDOUT;
					strncpy(my_symbol->outfile, "dummy.txt", 10);
				}
				if(!strcmp(long_options[option_index].name, "gs1")) {
					my_symbol->input_mode = GS1_MODE;
				}
				if(!strcmp(long_options[option_index].name, "kanji")) {
					my_symbol->input_mode = KANJI_MODE;
				}
				if(!strcmp(long_options[option_index].name, "sjis")) {
					my_symbol->input_mode = SJIS_MODE;
				}
				if(!strcmp(long_options[option_index].name, "binary")) {
					my_symbol->input_mode = DATA_MODE;
				}
				if(!strcmp(long_options[option_index].name, "fg")) {
					strncpy(my_symbol->fgcolour, optarg, 7);
				}
				if(!strcmp(long_options[option_index].name, "bg")) {
					strncpy(my_symbol->bgcolour, optarg, 7);
				}
				if(!strcmp(long_options[option_index].name, "notext")) {
					my_symbol->show_hrt = 0;
				}
				if(!strcmp(long_options[option_index].name, "square")) {
					my_symbol->option_3 = DM_SQUARE;
				}
				if(!strcmp(long_options[option_index].name, "scale")) {
					my_symbol->scale = (float)(atof(optarg));
					if(my_symbol->scale < 0.01) {
						/* Zero and negative values are not permitted */
						fprintf(stderr, "Invalid scale value\n");
						my_symbol->scale = 1.0;
					}
				}
				if(!strcmp(long_options[option_index].name, "border")) {
					error_number = validator(NESET, optarg);
					if(error_number == ZERROR_INVALID_DATA)
						die("Invalid border width\n");
					if((atoi(optarg) >= 0) && (atoi(optarg) <= 1000)) {
						my_symbol->border_width = atoi(optarg);
					} else {
						fprintf(stderr, "Border width out of range\n");
					}
				}
				if(!strcmp(long_options[option_index].name, "height")) {
					error_number = validator(NESET, optarg);
					if(error_number == ZERROR_INVALID_DATA)
						die("Invalid symbol height\n");
					if((atoi(optarg) >= 1) && (atoi(optarg) <= 1000)) {
						my_symbol->height = atoi(optarg);
					} else {
						fprintf(stderr, "Symbol height out of range\n");
					}
				}

				if(!strcmp(long_options[option_index].name, "cols")) {
					if((atoi(optarg) >= 1) && (atoi(optarg) <= 30)) {
						my_symbol->option_2 = atoi(optarg);
					} else {
						fprintf(stderr, "Number of columns out of range\n");
					}
				}
				if(!strcmp(long_options[option_index].name, "vers")) {
					if((atoi(optarg) >= 1) && (atoi(optarg) <= 40)) {
						my_symbol->option_2 = atoi(optarg);
					} else {
						fprintf(stderr, "Invalid QR Code version\n");
					}
				}
				if(!strcmp(long_options[option_index].name, "secure")) {
					if((atoi(optarg) >= 1) && (atoi(optarg) <= 8)) {
						my_symbol->option_1 = atoi(optarg);
					} else {
						fprintf(stderr, "ECC level out of range\n");
					}
				}
				if(!strcmp(long_options[option_index].name, "primary")) {
					if(strlen(optarg) <= 90) {
						strcpy(my_symbol->primary, optarg);
					} else {
						fprintf(stderr, "Primary data string too long");
					}
				}
				if(!strcmp(long_options[option_index].name, "mode")) {
					if((optarg[0] >= '0') && (optarg[0] <= '6')) {
						my_symbol->option_1 = optarg[0] - '0';
					} else {
						fprintf(stderr, "Invalid mode\n");
					}
				}
				if(!strcmp(long_options[option_index].name, "rotate")) {
					/* Only certain inputs allowed */
					error_number = validator(NESET, optarg);
					if(error_number == ZERROR_INVALID_DATA)
						die("Invalid rotation parameter\n");
					switch(atoi(optarg)) {
						case 90: rotate_angle = 90; break;
						case 180: rotate_angle = 180; break;
						case 270: rotate_angle = 270; break;
						default: rotate_angle = 0; break;
					}
				}
				if(!strcmp(long_options[option_index].name, "batch")) {
					/* Switch to batch processing mode */
					batch_mode = 1;
				}
				break;
				
			case 'h':
				die(help_usage);
				
			case 't':
				die(help_types);
				
			case 'b':
				error_number = validator(NESET, optarg);
				if (error_number == ZERROR_INVALID_DATA)
					die("Invalid barcode type\n");
				my_symbol->symbology = atoi(optarg);
				break;
				
			case 'w':
				error_number = validator(NESET, optarg);
				if (error_number == ZERROR_INVALID_DATA)
					die("Invalid whitespace value\n");
				if((atoi(optarg) >= 0) && (atoi(optarg) <= 1000)) {
					my_symbol->whitespace_width = atoi(optarg);
				} else {
					fprintf(stderr, "Whitespace value out of range");
				}
				break;
				
			case 'd': /* we have some data! */
				if(batch_mode == 0) {
					error_number = escape_char_process(my_symbol, (unsigned char*)optarg, strlen(optarg));
					if(error_number == 0) {
						error_number = ZBarcode_Print(my_symbol, rotate_angle);
					}
					generated = 1;
					if(error_number != 0) {
						fprintf(stderr, "%s\n", my_symbol->errtxt);
						ZBarcode_Delete(my_symbol);
						return 1;
					}
				} else {
					fprintf(stderr, "Cannot define data in batch mode");
				}
				break;
				
			case 'i': /* Take data from file */
				if(batch_mode == 0) {
					error_number = ZBarcode_Encode_File(my_symbol, optarg);
					if(error_number == 0) {
						error_number = ZBarcode_Print(my_symbol, rotate_angle);
					}
					generated = 1;
					if(error_number != 0) {
						fprintf(stderr, "%s\n", my_symbol->errtxt);
						ZBarcode_Delete(my_symbol);
						return 1;
					}
				} else {
					/* Take each line of text as a separate data set */
					error_number = batch_process(my_symbol, optarg);
					generated = 1;
					if(error_number != 0) {
						fprintf(stderr, "%s\n", my_symbol->errtxt);
						ZBarcode_Delete(my_symbol);
						return 1;
					}
				}
				break;

			case 'o':
				strncpy(my_symbol->outfile, optarg, 250);
				break;
				
			case 'r':
				strcpy(my_symbol->fgcolour, "ffffff");
				strcpy(my_symbol->bgcolour, "000000");
				break;
				
			case '?':
				break;
				
			default:
				fprintf(stderr, "?? getopt error 0%o\n", c);
		} 
	}
	
	if (optind < argc) {
		fprintf(stderr, "Invalid option ");
		while (optind < argc)
			fprintf(stderr, "%s", argv[optind++]);
		fprintf(stderr, "\n");
	}
	
	if(generated == 0) {
		fprintf(stderr, "error: No data received, no symbol generated\n");
	}
	
	ZBarcode_Delete(my_symbol); 
	
	return error_number;
}