@Test public void testDraw() { Graphics2D g2d = mock( Graphics2D.class ); Rectangle2D bounds = mock( Rectangle2D.class ); doReturn( 200.0 ).when( bounds ).getWidth(); doReturn( 600.0 ).when( bounds ).getHeight(); doReturn( 10.0 ).when( barcodeDimension ).getWidthPlusQuiet(); doReturn( 20.0 ).when( barcodeDimension ).getHeightPlusQuiet(); barcodeDrawable.draw( g2d, bounds ); verify( g2d ).scale( 20, 20 ); verify( g2d ).translate( 0.0, 5.0 ); verify( g2d ).setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); verify( g2d ).setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON ); verify( g2d, never() ).setFont( any( Font.class ) ); verify( g2d, never() ).setColor( any( Color.class ) ); verify( g2d, never() ).fill( bounds ); verify( generator ).generateBarcode( any( CanvasProvider.class ), anyString() ); }
public void draw( final Graphics2D g2d, final Rectangle2D bounds ) { final double horzScale = bounds.getWidth() / getBarcodeDimension().getWidthPlusQuiet(); final double vertScale = bounds.getHeight() / getBarcodeDimension().getHeightPlusQuiet(); final double scale; double dx = 0; double dy = 0; if ( horzScale < vertScale ) { scale = horzScale; dy = ( ( bounds.getHeight() / scale ) - getBarcodeDimension().getHeightPlusQuiet() ) / 2; } else { scale = vertScale; dx = ( ( bounds.getWidth() / scale ) - getBarcodeDimension().getWidthPlusQuiet() ) / 2; } g2d.scale( scale, scale ); g2d.translate( dx, dy ); g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); g2d.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON ); if ( font != null ) { g2d.setFont( font ); } if ( backgroundColor != null ) { g2d.setColor( backgroundColor ); g2d.fill( bounds ); } if ( foregroundColor != null ) { g2d.setColor( foregroundColor ); } final Java2DCanvasProvider canvas = new Java2DCanvasProvider( g2d, 0 ); generator.generateBarcode( canvas, message ); }
BarcodeDrawable implements ReportDrawable { public void draw( final Graphics2D g2d, final Rectangle2D bounds ) { final double horzScale = bounds.getWidth() / getBarcodeDimension().getWidthPlusQuiet(); final double vertScale = bounds.getHeight() / getBarcodeDimension().getHeightPlusQuiet(); final double scale; double dx = 0; double dy = 0; if ( horzScale < vertScale ) { scale = horzScale; dy = ( ( bounds.getHeight() / scale ) - getBarcodeDimension().getHeightPlusQuiet() ) / 2; } else { scale = vertScale; dx = ( ( bounds.getWidth() / scale ) - getBarcodeDimension().getWidthPlusQuiet() ) / 2; } g2d.scale( scale, scale ); g2d.translate( dx, dy ); g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); g2d.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON ); if ( font != null ) { g2d.setFont( font ); } if ( backgroundColor != null ) { g2d.setColor( backgroundColor ); g2d.fill( bounds ); } if ( foregroundColor != null ) { g2d.setColor( foregroundColor ); } final Java2DCanvasProvider canvas = new Java2DCanvasProvider( g2d, 0 ); generator.generateBarcode( canvas, message ); } }
BarcodeDrawable implements ReportDrawable { public void draw( final Graphics2D g2d, final Rectangle2D bounds ) { final double horzScale = bounds.getWidth() / getBarcodeDimension().getWidthPlusQuiet(); final double vertScale = bounds.getHeight() / getBarcodeDimension().getHeightPlusQuiet(); final double scale; double dx = 0; double dy = 0; if ( horzScale < vertScale ) { scale = horzScale; dy = ( ( bounds.getHeight() / scale ) - getBarcodeDimension().getHeightPlusQuiet() ) / 2; } else { scale = vertScale; dx = ( ( bounds.getWidth() / scale ) - getBarcodeDimension().getWidthPlusQuiet() ) / 2; } g2d.scale( scale, scale ); g2d.translate( dx, dy ); g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); g2d.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON ); if ( font != null ) { g2d.setFont( font ); } if ( backgroundColor != null ) { g2d.setColor( backgroundColor ); g2d.fill( bounds ); } if ( foregroundColor != null ) { g2d.setColor( foregroundColor ); } final Java2DCanvasProvider canvas = new Java2DCanvasProvider( g2d, 0 ); generator.generateBarcode( canvas, message ); } BarcodeDrawable( final BarcodeGenerator generator, final String message ); }
BarcodeDrawable implements ReportDrawable { public void draw( final Graphics2D g2d, final Rectangle2D bounds ) { final double horzScale = bounds.getWidth() / getBarcodeDimension().getWidthPlusQuiet(); final double vertScale = bounds.getHeight() / getBarcodeDimension().getHeightPlusQuiet(); final double scale; double dx = 0; double dy = 0; if ( horzScale < vertScale ) { scale = horzScale; dy = ( ( bounds.getHeight() / scale ) - getBarcodeDimension().getHeightPlusQuiet() ) / 2; } else { scale = vertScale; dx = ( ( bounds.getWidth() / scale ) - getBarcodeDimension().getWidthPlusQuiet() ) / 2; } g2d.scale( scale, scale ); g2d.translate( dx, dy ); g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); g2d.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON ); if ( font != null ) { g2d.setFont( font ); } if ( backgroundColor != null ) { g2d.setColor( backgroundColor ); g2d.fill( bounds ); } if ( foregroundColor != null ) { g2d.setColor( foregroundColor ); } final Java2DCanvasProvider canvas = new Java2DCanvasProvider( g2d, 0 ); generator.generateBarcode( canvas, message ); } BarcodeDrawable( final BarcodeGenerator generator, final String message ); BarcodeGenerator getGenerator(); void draw( final Graphics2D g2d, final Rectangle2D bounds ); void setConfiguration( final Configuration config ); void setStyleSheet( final StyleSheet style ); void setResourceBundleFactory( final ResourceBundleFactory bundleFactory ); ImageMap getImageMap( final Rectangle2D bounds ); }
BarcodeDrawable implements ReportDrawable { public void draw( final Graphics2D g2d, final Rectangle2D bounds ) { final double horzScale = bounds.getWidth() / getBarcodeDimension().getWidthPlusQuiet(); final double vertScale = bounds.getHeight() / getBarcodeDimension().getHeightPlusQuiet(); final double scale; double dx = 0; double dy = 0; if ( horzScale < vertScale ) { scale = horzScale; dy = ( ( bounds.getHeight() / scale ) - getBarcodeDimension().getHeightPlusQuiet() ) / 2; } else { scale = vertScale; dx = ( ( bounds.getWidth() / scale ) - getBarcodeDimension().getWidthPlusQuiet() ) / 2; } g2d.scale( scale, scale ); g2d.translate( dx, dy ); g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); g2d.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON ); if ( font != null ) { g2d.setFont( font ); } if ( backgroundColor != null ) { g2d.setColor( backgroundColor ); g2d.fill( bounds ); } if ( foregroundColor != null ) { g2d.setColor( foregroundColor ); } final Java2DCanvasProvider canvas = new Java2DCanvasProvider( g2d, 0 ); generator.generateBarcode( canvas, message ); } BarcodeDrawable( final BarcodeGenerator generator, final String message ); BarcodeGenerator getGenerator(); void draw( final Graphics2D g2d, final Rectangle2D bounds ); void setConfiguration( final Configuration config ); void setStyleSheet( final StyleSheet style ); void setResourceBundleFactory( final ResourceBundleFactory bundleFactory ); ImageMap getImageMap( final Rectangle2D bounds );  }