Class Java2DCanvasProvider
java.lang.Object
org.krysalis.barcode4j.output.AbstractCanvasProvider
org.krysalis.barcode4j.output.java2d.Java2DCanvasProvider
- All Implemented Interfaces:
CanvasProvider
CanvasProvider implementation that renders to Java2D (AWT).
- Version:
- $Id: Java2DCanvasProvider.java,v 1.7 2008-05-13 13:00:46 jmaerki Exp $
- Author:
- Jeremias Maerki
-
Field Summary
Fields inherited from class org.krysalis.barcode4j.output.AbstractCanvasProvider
bardim -
Constructor Summary
ConstructorsConstructorDescriptionJava2DCanvasProvider(Graphics2D g2d, int orientation) Creates a new Java2DCanvasProvider. -
Method Summary
Modifier and TypeMethodDescriptionvoiddeviceDrawRect(double x, double y, double w, double h) voiddeviceFillRect(double x, double y, double w, double h) Paints a filled rectangle.voiddeviceText(String text, double x1, double x2, double y1, String fontName, double fontSize, TextAlignment textAlign) Draws text.voidSets the dimensions of the barcode.Returns the Graphics2D in use.voidsetGraphics2D(Graphics2D g2d) Sets the Graphics2D instance to paint onMethods inherited from class org.krysalis.barcode4j.output.AbstractCanvasProvider
deviceCenteredText, deviceJustifiedText, getDimensions, getOrientation
-
Constructor Details
-
Java2DCanvasProvider
Creates a new Java2DCanvasProvider.This class internally operates with millimeters (mm) as units. This means you have to apply the necessary transformation before rendering a barcode to obtain the expected size. See the source code for BitmapBuilder.java for an example.
To improve the quality of text output it is recommended that fractional font metrics be enabled on the Graphics2D object passed in:
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);- Parameters:
g2d- Graphics2D object to paint on
-
-
Method Details
-
setGraphics2D
Sets the Graphics2D instance to paint on- Parameters:
g2d- the Graphics2D instance
-
getGraphics2D
Returns the Graphics2D in use.- Returns:
- the Graphics2D instance to paint on
-
establishDimensions
Sets the dimensions of the barcode.- Specified by:
establishDimensionsin interfaceCanvasProvider- Overrides:
establishDimensionsin classAbstractCanvasProvider- Parameters:
dim- the dimensions of the barcode
-
deviceFillRect
public void deviceFillRect(double x, double y, double w, double h) Paints a filled rectangle.- Parameters:
x- x coordinate of the upper left cornery- y coordinate of the upper left cornerw- the widthh- the height
-
deviceDrawRect
public void deviceDrawRect(double x, double y, double w, double h) -
deviceText
public void deviceText(String text, double x1, double x2, double y1, String fontName, double fontSize, TextAlignment textAlign) Draws text.- Parameters:
text- the text to drawx1- the left boundaryx2- the right boundaryy1- the y coordinatefontName- the name of the fontfontSize- the size of the fonttextAlign- the text alignment
-