Class AFPGraphics2D
java.lang.Object
java.awt.Graphics
java.awt.Graphics2D
org.apache.xmlgraphics.java2d.AbstractGraphics2D
org.apache.fop.afp.AFPGraphics2D
- All Implemented Interfaces:
Cloneable, NativeImageHandler
public class AFPGraphics2D
extends org.apache.xmlgraphics.java2d.AbstractGraphics2D
implements NativeImageHandler
This is a concrete implementation of
AbstractGraphics2D (and
therefore of Graphics2D) which is able to generate GOCA byte
codes.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.xmlgraphics.java2d.TextHandlerCustom text handlerprotected org.apache.xmlgraphics.java2d.TextHandlerFallback text handlerprivate FontInfoThe AFP FontInfoprivate final org.apache.xmlgraphics.java2d.GraphicsConfigurationWithTransparencyAFP graphics configurationprivate GraphicsObjectgraphics objectprivate static final org.apache.commons.logging.Logprivate AFPPaintingStateCurrent AFP stateprivate AFPResourceInfoAFP resource infoprivate AFPResourceManagerAFP resource managerprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intFields inherited from class org.apache.xmlgraphics.java2d.AbstractGraphics2D
gc, inPossibleRecursion, textAsShapes -
Constructor Summary
ConstructorsConstructorDescriptionAFPGraphics2D(boolean textAsShapes, AFPPaintingState paintingState, AFPResourceManager resourceManager, AFPResourceInfo resourceInfo, FontInfo fontInfo) Main constructorCopy Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNativeImage(org.apache.xmlgraphics.image.loader.Image image, float x, float y, float width, float height) Add a natively handled image directly to the document.private booleanapplyPaint(Paint paint, boolean fill) Apply the java paint to the AFP.protected voidapplyStroke(Stroke stroke) Apply the stroke to the AFP graphics object.private BufferedImagebuildBufferedImage(Dimension size) voidclearRect(int x, int y, int width, int height) doubleconvertToAbsoluteLength(double length) Converts a length value to an absolute value.voidcopyArea(int x, int y, int width, int height, int dx, int dy) create()voiddispose()private voidHandle the Batik drawing eventvoidprivate booleandrawBufferedImage(Image img, BufferedImage bufferedImage, int width, int height, ImageObserver observer) Draws an AWT image into a BufferedImage using an AWT Graphics2D implementationbooleandrawImage(Image img, int x, int y, int width, int height, ImageObserver observer) booleandrawImage(Image img, int x, int y, ImageObserver observer) voiddrawRenderableImage(RenderableImage img, AffineTransform xform) voiddrawRenderedImage(RenderedImage img, AffineTransform xform) voiddrawString(String str, float x, float y) voidprivate voidReturns the FontInfoReturns the GOCA graphics objectReturns the AFP painting stateprivate intReturns the AFP resource manager associated with thisGraphics2Dinstance.voidCentral handler for IOExceptions for this class.private List<int[]> listToIntLists(List<Integer> input) private voidProcesses a path iterator generating the necessary painting operations.voidsetCustomTextHandler(org.apache.xmlgraphics.java2d.TextHandler handler) Sets a custom TextHandler implementation that is responsible for painting text.private voidsetFontInfo(FontInfo fontInfo) Sets the FontInfovoidsetGraphicContext(org.apache.xmlgraphics.java2d.GraphicContext gc) Sets the GraphicContextvoidSets the GOCA graphics objectprivate voidsetPaintingState(AFPPaintingState paintingState) Sets the AFP painting stateprivate voidsetResourceInfo(AFPResourceInfo resourceInfo) Sets the AFP resource infoprivate voidsetResourceManager(AFPResourceManager resourceManager) Sets the AFP resource managervoidsetXORMode(Color col) Methods inherited from class org.apache.xmlgraphics.java2d.AbstractGraphics2D
addRenderingHints, clip, clipRect, drawArc, drawGlyphVector, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawLine, drawOval, drawPolygon, drawPolyline, drawRect, drawRoundRect, drawString, drawString, drawString, fillArc, fillOval, fillPolygon, fillRect, fillRoundRect, getBackground, getClip, getClipBounds, getColor, getComposite, getFont, getFontRenderContext, getGraphicContext, getPaint, getRenderingHint, getRenderingHints, getStroke, getTransform, hit, rotate, rotate, scale, setBackground, setClip, setClip, setColor, setComposite, setFont, setPaint, setPaintMode, setRenderingHint, setRenderingHints, setStroke, setTransform, shear, transform, translate, translateMethods inherited from class Graphics2D
draw3DRect, fill3DRectMethods inherited from class Graphics
create, drawBytes, drawChars, drawPolygon, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toString
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOG -
X
private static final int X- See Also:
-
Y
private static final int Y- See Also:
-
X1
private static final int X1- See Also:
-
Y1
private static final int Y1- See Also:
-
X2
private static final int X2- See Also:
-
Y2
private static final int Y2- See Also:
-
X3
private static final int X3- See Also:
-
Y3
private static final int Y3- See Also:
-
graphicsObj
graphics object -
fallbackTextHandler
protected org.apache.xmlgraphics.java2d.TextHandler fallbackTextHandlerFallback text handler -
customTextHandler
protected org.apache.xmlgraphics.java2d.TextHandler customTextHandlerCustom text handler -
resourceManager
AFP resource manager -
resourceInfo
AFP resource info -
paintingState
Current AFP state -
graphicsConfig
private final org.apache.xmlgraphics.java2d.GraphicsConfigurationWithTransparency graphicsConfigAFP graphics configuration -
fontInfo
The AFP FontInfo
-
-
Constructor Details
-
AFPGraphics2D
public AFPGraphics2D(boolean textAsShapes, AFPPaintingState paintingState, AFPResourceManager resourceManager, AFPResourceInfo resourceInfo, FontInfo fontInfo) Main constructor- Parameters:
textAsShapes- if true, all text is turned into shapes in the convertion. No text is output.paintingState- painting stateresourceManager- resource managerresourceInfo- resource infofontInfo- font info
-
AFPGraphics2D
Copy Constructor- Parameters:
g2d- a AFPGraphics2D whose properties should be copied
-
-
Method Details
-
setResourceManager
Sets the AFP resource manager- Parameters:
resourceManager- the AFP resource manager
-
getResourceManager
Returns the AFP resource manager associated with thisGraphics2Dinstance.- Returns:
- the resource manager
-
setResourceInfo
Sets the AFP resource info- Parameters:
resourceInfo- the AFP resource info
-
getGraphicsObject
Returns the GOCA graphics object- Returns:
- the GOCA graphics object
-
setGraphicsObject
Sets the GOCA graphics object- Parameters:
obj- the GOCA graphics object
-
setPaintingState
Sets the AFP painting state- Parameters:
paintingState- the AFP painting state
-
getPaintingState
Returns the AFP painting state- Returns:
- the AFP painting state
-
setFontInfo
-
getFontInfo
-
setGraphicContext
public void setGraphicContext(org.apache.xmlgraphics.java2d.GraphicContext gc) Sets the GraphicContext- Parameters:
gc- GraphicContext to use
-
getResolution
private int getResolution() -
convertToAbsoluteLength
public double convertToAbsoluteLength(double length) Converts a length value to an absolute value. Please note that this only uses the "ScaleY" factor, so this will result in a bad value should "ScaleX" and "ScaleY" be different.- Parameters:
length- the length- Returns:
- the absolute length
-
applyStroke
Apply the stroke to the AFP graphics object. This takes the java stroke and outputs the appropriate settings to the AFP graphics object so that the stroke attributes are handled.- Parameters:
stroke- the java stroke
-
applyPaint
Apply the java paint to the AFP. This takes the java paint sets up the appropriate AFP commands for the drawing with that paint. Currently this supports the gradients and patterns from batik.- Parameters:
paint- the paint to convert to AFPfill- true if the paint should be set for filling- Returns:
- true if the paint is handled natively, false if the paint should be rasterized
-
doDrawing
Handle the Batik drawing event- Parameters:
shape- the shape to drawfill- true if the shape is to be drawn filled
-
processPathIterator
Processes a path iterator generating the necessary painting operations.- Parameters:
iter- PathIterator to process
-
flush
-
listToIntLists
-
draw
- Specified by:
drawin classGraphics2D
-
fill
- Specified by:
fillin classGraphics2D
-
handleIOException
Central handler for IOExceptions for this class.- Parameters:
ioe- IOException to handle
-
drawString
- Specified by:
drawStringin classGraphics2D
-
getDeviceConfiguration
- Specified by:
getDeviceConfigurationin classGraphics2D
-
create
-
dispose
-
drawImage
-
buildBufferedImage
-
drawBufferedImage
private boolean drawBufferedImage(Image img, BufferedImage bufferedImage, int width, int height, ImageObserver observer) Draws an AWT image into a BufferedImage using an AWT Graphics2D implementation- Parameters:
img- the AWT imagebufferedImage- the AWT buffered imagewidth- the image widthheight- the image heightobserver- the image observer- Returns:
- true if the image was drawn
-
drawImage
-
drawRenderedImage
- Specified by:
drawRenderedImagein classGraphics2D
-
setCustomTextHandler
public void setCustomTextHandler(org.apache.xmlgraphics.java2d.TextHandler handler) Sets a custom TextHandler implementation that is responsible for painting text. The default TextHandler paints all text as shapes. A custom implementation can implement text painting using text painting operators.- Parameters:
handler- the custom TextHandler implementation
-
drawRenderableImage
- Specified by:
drawRenderableImagein classGraphics2D
-
getFontMetrics
- Specified by:
getFontMetricsin classGraphics
-
setXORMode
- Specified by:
setXORModein classGraphics
-
addNativeImage
public void addNativeImage(org.apache.xmlgraphics.image.loader.Image image, float x, float y, float width, float height) Add a natively handled image directly to the document. This is used by the ImageElementBridge to draw a natively handled image (like JPEG or CCITT images) directly into the document rather than converting the image into a bitmap and increasing the size.- Specified by:
addNativeImagein interfaceNativeImageHandler- Parameters:
image- the image to drawx- the x positiony- the y positionwidth- the width to draw the imageheight- the height to draw the image
-
copyArea
-
clearRect
public void clearRect(int x, int y, int width, int height) - Overrides:
clearRectin classorg.apache.xmlgraphics.java2d.AbstractGraphics2D
-