Class Java2DCanvasProvider

java.lang.Object
org.krysalis.barcode4j.output.AbstractCanvasProvider
org.krysalis.barcode4j.output.java2d.Java2DCanvasProvider
All Implemented Interfaces:
CanvasProvider

public class Java2DCanvasProvider extends AbstractCanvasProvider
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
  • Constructor Details

    • Java2DCanvasProvider

      public Java2DCanvasProvider(Graphics2D g2d, int orientation)
      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

      public void setGraphics2D(Graphics2D g2d)
      Sets the Graphics2D instance to paint on
      Parameters:
      g2d - the Graphics2D instance
    • getGraphics2D

      public Graphics2D getGraphics2D()
      Returns the Graphics2D in use.
      Returns:
      the Graphics2D instance to paint on
    • establishDimensions

      public void establishDimensions(BarcodeDimension dim)
      Sets the dimensions of the barcode.
      Specified by:
      establishDimensions in interface CanvasProvider
      Overrides:
      establishDimensions in class AbstractCanvasProvider
      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 corner
      y - y coordinate of the upper left corner
      w - the width
      h - 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 draw
      x1 - the left boundary
      x2 - the right boundary
      y1 - the y coordinate
      fontName - the name of the font
      fontSize - the size of the font
      textAlign - the text alignment