Java源码示例:org.krysalis.barcode4j.BarcodeGenerator

示例1
@Test
public void testCreateBarcode4J() {
  BarcodeGenerator barcodeGen = SimpleBarcodesUtility.createBarcode4J( INCORRECT_TYPE, true, false, BAR_HEIGHT );
  assertThat( barcodeGen, is( nullValue() ) );

  for ( BarcodeTypeInfo info : barcode4JTypes ) {
    barcodeGen = SimpleBarcodesUtility.createBarcode4J( info.getType(), true, true, null );
    assertThat( barcodeGen, is( instanceOf( info.getClazz() ) ) );
    if ( info.isCheckIncorrect() ) {
      barcodeGen = SimpleBarcodesUtility.createBarcode4J( info.getType(), false, true, BAR_HEIGHT );
      assertThat( barcodeGen, is( instanceOf( info.getClazz() ) ) );
      assertThat( barcodeGen, is( instanceOf( ConfigurableBarcodeGenerator.class ) ) );
      ConfigurableBarcodeGenerator commonGen = (ConfigurableBarcodeGenerator) barcodeGen;
      assertThat( commonGen.getBean(), is( notNullValue() ) );
      assertThat( commonGen.getBean().getMsgPosition(), is( equalTo( HumanReadablePlacement.HRP_NONE ) ) );
      double expectedHeight = UnitConv.pt2mm( BAR_HEIGHT );
      assertThat( commonGen.getBean().getBarHeight(), is( equalTo( expectedHeight ) ) );
    }
  }
}
 
示例2
@Override
public Renderable createImage(
	JasperReportsContext jasperReportsContext,
	JRComponentElement componentElement, 
	BarcodeGenerator barcode, 
	String message
	)
{
	try
	{
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		
		int resolution = JRPropertiesUtil.getInstance(jasperReportsContext).getIntegerProperty(
				componentElement, PROPERTY_RESOLUTION, 300);
		boolean gray = JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(
				componentElement, PROPERTY_GRAY, true);
		boolean antiAlias = JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(
				componentElement, PROPERTY_ANTIALIAS, true);
		int imageType = gray ? BufferedImage.TYPE_BYTE_GRAY 
				: BufferedImage.TYPE_BYTE_BINARY;
		
		BitmapCanvasProvider provider = 
			new BitmapCanvasProvider(
				out, "image/x-png", resolution, imageType, antiAlias, 
				((Barcode4jComponent)componentElement.getComponent()).getOrientationValue().getValue()
				);
		barcode.generateBarcode(provider, message);
		provider.finish();
		
		byte[] imageData = out.toByteArray();
		return SimpleDataRenderer.getInstance(imageData);
	}
	catch (Exception e)
	{
		throw new JRRuntimeException(e);
	}
}
 
示例3
@Override
public Renderable createImage(
	JasperReportsContext jasperReportsContext,
	JRComponentElement componentElement,
	BarcodeGenerator barcode, 
	String message
	)
{
	try
	{
		SVGCanvasProvider provider = 
			new SVGCanvasProvider(
				false, 
				((Barcode4jComponent)componentElement.getComponent()).getOrientationValue().getValue()
				);
		barcode.generateBarcode(provider, message);
		Document svgDoc = provider.getDOM();

		Source source = new DOMSource(svgDoc);
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		Result output = new StreamResult(baos);
		Transformer transformer = TransformerFactory.newInstance()
				.newTransformer();
		transformer.transform(source, output);

		return SimpleRenderToImageAwareDataRenderer.getInstance(baos.toByteArray());
	}
	catch (Exception e)
	{
		throw new JRRuntimeException(e);
	}
}
 
示例4
private synchronized BufferedImage getBufferedBarcodeImage(String documentNumber, BarcodeGenerator bean){
    try {
        BitmapCanvasProvider canvas = new BitmapCanvasProvider(DPI, BufferedImage.TYPE_BYTE_BINARY,false ,0 );
        bean.generateBarcode(canvas, documentNumber);
        BufferedImage image=canvas.getBufferedImage();
        canvas.finish();
        return image;
    }
    catch(Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
示例5
@Before
public void setUp() {
  generator = mock( BarcodeGenerator.class );
  barcodeDimension = mock( BarcodeDimension.class );
  doReturn( barcodeDimension ).when( generator ).calcDimensions( MSG );
  barcodeDrawable = new BarcodeDrawable( generator, MSG );
}
 
示例6
Renderable createImage(
JasperReportsContext jasperReportsContext,
JRComponentElement componentElement, 
BarcodeGenerator barcode, 
String message
);
 
示例7
public BarcodeDrawable( final BarcodeGenerator generator, final String message ) throws IllegalArgumentException {
  this.generator = generator;
  this.message = message;
  this.barcodeDimension = this.generator.calcDimensions( message );
}
 
示例8
public BarcodeGenerator getGenerator() {
  return generator;
}
 
示例9
/**
 * Return the current expression value.
 * <p/>
 * The value depends (obviously) on the expression implementation.
 *
 * @return the value of the function.
 */
public Object getValue() {
  final String data = getData();
  if ( data == null ) {
    logger.info( "No data supplied to barcode element." );
    return null;
  }
  String ltype;
  if ( type == null ) {
    // if no static type, retrieve it from the type field
    ltype = computeRawType();
  } else {
    ltype = type;
  }
  if ( ltype == null ) {
    logger.info( "No type supplied to barcode element." );
    return null;
  }

  try {
    final BarcodeGenerator generator =
        SimpleBarcodesUtility.createBarcode4J( type, showText, checksum, Integer.valueOf( barHeight ) );
    if ( generator != null ) {
      return new BarcodeDrawable( generator, data );
    }
  } catch ( Exception e ) {
    if ( logger.isInfoEnabled() ) {
      logger.info( "Error creating barcode, falling back to null value", e );
    }
    return null;
  }

  final Barcode barcode = SimpleBarcodesUtility.createBarcode( data, ltype, checksum );
  if ( barcode == null ) {
    return null;
  }
  barcode.setDrawingText( showText );
  barcode.setBarWidth( barWidth );
  barcode.setBarHeight( barHeight );
  return new BarcodeWrapper( barcode );
}