barcode4j 2.1.0

org.krysalis.barcode4j.output.java2d
Class Java2DCanvasProvider

java.lang.Object
  extended by org.krysalis.barcode4j.output.AbstractCanvasProvider
      extended by 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

Field Summary
 
Fields inherited from class org.krysalis.barcode4j.output.AbstractCanvasProvider
bardim
 
Constructor Summary
Java2DCanvasProvider(java.awt.Graphics2D g2d, int orientation)
          Creates a new Java2DCanvasProvider.
 
Method Summary
 void deviceDrawRect(double x, double y, double w, double h)
          
 void deviceFillRect(double x, double y, double w, double h)
          Paints a filled rectangle.
 void deviceText(java.lang.String text, double x1, double x2, double y1, java.lang.String fontName, double fontSize, TextAlignment textAlign)
          Draws text.
 void establishDimensions(BarcodeDimension dim)
          Sets the dimensions of the barcode.
 java.awt.Graphics2D getGraphics2D()
          Returns the Graphics2D in use.
 void setGraphics2D(java.awt.Graphics2D g2d)
          Sets the Graphics2D instance to paint on
 
Methods inherited from class org.krysalis.barcode4j.output.AbstractCanvasProvider
deviceCenteredText, deviceJustifiedText, getDimensions, getOrientation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Java2DCanvasProvider

public Java2DCanvasProvider(java.awt.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 Detail

setGraphics2D

public void setGraphics2D(java.awt.Graphics2D g2d)
Sets the Graphics2D instance to paint on

Parameters:
g2d - the Graphics2D instance

getGraphics2D

public java.awt.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(java.lang.String text,
                       double x1,
                       double x2,
                       double y1,
                       java.lang.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

barcode4j 2.1.0

Copyright © 2000-2010 Jeremias Maerki. All rights reserved.