コード例 #1
0
ファイル: genbarcode.c プロジェクト: danielfb88/IFBA_SigaADM
int main(int argc, char **argv)
{
    struct Barcode_Item * bc;
    int bar;
    if (argc<2 || argc>3){
	usage();
	return 1;
    }
    if (argc==3){
	if (!strcasecmp(argv[2], "ANY")) bar=BARCODE_ANY;
	else if (!strcasecmp(argv[2], "EAN")) bar=BARCODE_EAN;
	else if (!strcasecmp(argv[2], "UPC")) bar=BARCODE_UPC;
	else if (!strcasecmp(argv[2], "ISBN")) bar=BARCODE_ISBN;
	else if (!strcasecmp(argv[2], "39")) bar=BARCODE_39;
	else if (!strcasecmp(argv[2], "128")) bar=BARCODE_128;
	else if (!strcasecmp(argv[2], "128C")) bar=BARCODE_128C;
	else if (!strcasecmp(argv[2], "128B")) bar=BARCODE_128B;
	else if (!strcasecmp(argv[2], "I25")) bar=BARCODE_I25;
	else if (!strcasecmp(argv[2], "128RAW")) bar=BARCODE_128RAW;
	else if (!strcasecmp(argv[2], "CBR")) bar=BARCODE_CBR;
	else if (!strcasecmp(argv[2], "MSI")) bar=BARCODE_MSI;
	else if (!strcasecmp(argv[2], "PLS")) bar=BARCODE_PLS;
#if BARCODE_VERSION_INT >= 9700
	else if (!strcasecmp(argv[2], "93")) bar=BARCODE_93;
#endif
	else {
	    usage();
	    return 1;
	}
    } else {
	bar=BARCODE_ANY;
    }
    
    bc=Barcode_Create(argv[1]);
    if (bc!=NULL){
	Barcode_Encode(bc, bar );
	if (bc->error==0){
	    printf("%s\n", bc->partial);
	    printf("%s\n", bc->textinfo);
	    printf("%s\n", bc->encoding);

		    
	} else {
	    fprintf(stderr, "Encoding Error\n");
	    return 1;
	}
	Barcode_Delete(bc);
    } else {
	fprintf(stderr, "Cannot create barcode\n");
	return 1;
    }

    return 0;
}
コード例 #2
0
ファイル: FLCodBar.cpp プロジェクト: AliYousuf/abanq-port
void FLCodBar::createBarcode() {
  if ( barcode.value.isEmpty() ) {
    barcode.valid = true;
    return ;
  }

  QString psBarcode;

  barcode.valid = false;
  cleanUp();

  struct Barcode_Item *bc;

  bc = Barcode_Create(( char * ) barcode.value.ascii() );
  if ( !bc )
    return ;

  bc->scalef = barcode.scale;

  if ( Barcode_Encode( bc, barcode.type ) == -1 ) {
    pError.resize( 350, 50 );
    pError.fill( barcode.bg );
    QPainter pter( &pError );
    pter.setFont( QFont( "Helvetica", 11 ) );
    pter.setBrush( barcode.fg );
    pter.drawText( 15, 30, tr( "El valor no se puede codificar para %1" ).arg( typeToName( barcode.type ) ) );
    return ;
  }

  if ( Barcode_Print( bc, &psBarcode, BARCODE_OUT_PS ) ) {
    pError.resize( 300, 50 );
    pError.fill( barcode.bg );
    QPainter pter( &pError );
    pter.setFont( QFont( "Helvetica", 11 ) );
    pter.setBrush( barcode.fg );
    pter.drawText( 15, 30, tr( "Error en la generación del código de barras" ) );
    return ;
  }

  proc = new QProcess();
#if defined(Q_OS_WIN32)

  proc->addArgument( "gswin32c" );
#else

  proc->addArgument( "gs" );
#endif

  proc->addArgument( "-q" );
  proc->addArgument( "-dBATCH" );
  proc->addArgument( "-dNOPAUSE" );
  proc->addArgument( "-sDEVICE=pnggray" );
  proc->addArgument( QString( "-g%1x%2" ).arg( bc->xoff + ( bc->width * barcode.res / 72 ) + ( 2 * barcode.margin * barcode.res / 72 ) ).arg( bc->yoff + ( bc->height * barcode.res / 72 ) + ( 2 * barcode.margin * barcode.res / 72 ) ) );
  QString res = QString::number( barcode.res );
  proc->addArgument( "-r" + res + "x" + res );
  proc->addArgument( "-sOutputFile=-" );
  proc->addArgument( "-" );

  Barcode_Delete( bc );

  writingStdout = true;
  if ( !proc->launch( psBarcode ) ) {
    pError.resize( 300, 50 );
    pError.fill( barcode.bg );
    QPainter pter( &pError );
    pter.setFont( QFont( "Helvetica", 11 ) );
    pter.setBrush( barcode.fg );
    pter.drawText( 27, 20, tr( "Necesita tener instalado GhostScript" ) );
    pter.drawText( 27, 39, tr( "para poder generar códigos de barras" ) );
    writingStdout = false;
    return ;
  } else {
    readingStdout = true;
    while ( readingStdout ) {
      qApp->processEvents();
      if ( !proc->isRunning() )
        writingStdoutFinished();
    }
  }
}
コード例 #3
0
ファイル: bincodes.c プロジェクト: anotherwon/bincodes
int main(int argc, char* argv[]) {

	Config config = (Config) {
		BARCODE_STD,
		BAR_CHAR,
		SPACE_BAR,
		BAR_WIDTH,
		0,
		0
	};

	int last = parseArguments(argc, argv, &config);

	setDebugLevel(config.debug_level);

	if (last >= argc) {
		return 2;
	}
	debug(LOG_DEBUG,"to barcode: %s\n",argv[last]);

	struct Barcode_Item *bc = Barcode_Create(argv[last]);
	if (!bc) {
		return 1;
	}

	unsigned int encoding = find_encoding(config.encoding);

	debug(LOG_DEBUG, "encoding: %s: %d\n", config.encoding, encoding);

	if (!config.checksum) {
		debug(LOG_DEBUG, "encode without checksum\n");
		encoding |= BARCODE_NO_CHECKSUM;
	}

	int status = Barcode_Encode(bc, encoding);

	if (status < 0) {
		printf("Encoding failed: error %s\n", strerror(bc->error));
		return 4;
	}


	int i = 0;
	int j = 0;
	char* output = bc->partial;

	debug(LOG_DEBUG,"textinfo: %s\nascii: %s\npartial: %s\n", bc->textinfo, bc->ascii, bc->partial);

	unsigned int flag = 0;
	char c = config.bar;
	int num = 0;
	int k = 0;
	while (output[i] != 0) {

		if (flag) {
			c = config.bar;	
		} else {
			c = config.space;
		}


		if (isdigit(output[i])) {
			num = output[i] - '0';
		} else {
			num = output[i] - 96;
		}

		for (k = 0; k < num * config.width; k++) {
			printf("%c", c);
		}

		i++;
		flag = !flag;
	}
	printf("\n");

	Barcode_Delete(bc);

	return 0;
}