Package org.apache.fop.afp
Class AFPGraphics2D
- java.lang.Object
-
- java.awt.Graphics
-
- java.awt.Graphics2D
-
- org.apache.xmlgraphics.java2d.AbstractGraphics2D
-
- org.apache.fop.afp.AFPGraphics2D
-
- All Implemented Interfaces:
java.lang.Cloneable
,NativeImageHandler
public class AFPGraphics2D extends org.apache.xmlgraphics.java2d.AbstractGraphics2D implements NativeImageHandler
This is a concrete implementation ofAbstractGraphics2D
(and therefore ofGraphics2D
) which is able to generate GOCA byte codes.- See Also:
AbstractGraphics2D
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.xmlgraphics.java2d.TextHandler
customTextHandler
Custom text handlerprotected org.apache.xmlgraphics.java2d.TextHandler
fallbackTextHandler
Fallback text handlerprivate FontInfo
fontInfo
The AFP FontInfoprivate org.apache.xmlgraphics.java2d.GraphicsConfigurationWithTransparency
graphicsConfig
AFP graphics configurationprivate GraphicsObject
graphicsObj
graphics objectprivate static org.apache.commons.logging.Log
LOG
private AFPPaintingState
paintingState
Current AFP stateprivate AFPResourceInfo
resourceInfo
AFP resource infoprivate AFPResourceManager
resourceManager
AFP resource managerprivate static int
X
private static int
X1
private static int
X2
private static int
X3
private static int
Y
private static int
Y1
private static int
Y2
private static int
Y3
-
Constructor Summary
Constructors Constructor Description AFPGraphics2D(boolean textAsShapes, AFPPaintingState paintingState, AFPResourceManager resourceManager, AFPResourceInfo resourceInfo, FontInfo fontInfo)
Main constructorAFPGraphics2D(AFPGraphics2D g2d)
Copy Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.private boolean
applyPaint(java.awt.Paint paint, boolean fill)
Apply the java paint to the AFP.protected void
applyStroke(java.awt.Stroke stroke)
Apply the stroke to the AFP graphics object.private java.awt.image.BufferedImage
buildBufferedImage(java.awt.Dimension size)
void
clearRect(int x, int y, int width, int height)
double
convertToAbsoluteLength(double length)
Converts a length value to an absolute value.void
copyArea(int x, int y, int width, int height, int dx, int dy)
java.awt.Graphics
create()
void
dispose()
private void
doDrawing(java.awt.Shape shape, boolean fill)
Handle the Batik drawing eventvoid
draw(java.awt.Shape shape)
private boolean
drawBufferedImage(java.awt.Image img, java.awt.image.BufferedImage bufferedImage, int width, int height, java.awt.image.ImageObserver observer)
Draws an AWT image into a BufferedImage using an AWT Graphics2D implementationboolean
drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)
boolean
drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
void
drawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)
void
drawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)
void
drawString(java.lang.String str, float x, float y)
void
fill(java.awt.Shape shape)
private void
flush(java.util.List<java.lang.Integer> fillets)
java.awt.GraphicsConfiguration
getDeviceConfiguration()
FontInfo
getFontInfo()
Returns the FontInfojava.awt.FontMetrics
getFontMetrics(java.awt.Font f)
GraphicsObject
getGraphicsObject()
Returns the GOCA graphics objectAFPPaintingState
getPaintingState()
Returns the AFP painting stateprivate int
getResolution()
AFPResourceManager
getResourceManager()
Returns the AFP resource manager associated with thisGraphics2D
instance.void
handleIOException(java.io.IOException ioe)
Central handler for IOExceptions for this class.private java.util.List<int[]>
listToIntLists(java.util.List<java.lang.Integer> input)
private void
processPathIterator(java.awt.geom.PathIterator iter)
Processes a path iterator generating the necessary painting operations.void
setCustomTextHandler(org.apache.xmlgraphics.java2d.TextHandler handler)
Sets a custom TextHandler implementation that is responsible for painting text.private void
setFontInfo(FontInfo fontInfo)
Sets the FontInfovoid
setGraphicContext(org.apache.xmlgraphics.java2d.GraphicContext gc)
Sets the GraphicContextvoid
setGraphicsObject(GraphicsObject obj)
Sets the GOCA graphics objectprivate void
setPaintingState(AFPPaintingState paintingState)
Sets the AFP painting stateprivate void
setResourceInfo(AFPResourceInfo resourceInfo)
Sets the AFP resource infoprivate void
setResourceManager(AFPResourceManager resourceManager)
Sets the AFP resource managervoid
setXORMode(java.awt.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, translate
-
-
-
-
Field Detail
-
LOG
private static final org.apache.commons.logging.Log LOG
-
X
private static final int X
- See Also:
- Constant Field Values
-
Y
private static final int Y
- See Also:
- Constant Field Values
-
X1
private static final int X1
- See Also:
- Constant Field Values
-
Y1
private static final int Y1
- See Also:
- Constant Field Values
-
X2
private static final int X2
- See Also:
- Constant Field Values
-
Y2
private static final int Y2
- See Also:
- Constant Field Values
-
X3
private static final int X3
- See Also:
- Constant Field Values
-
Y3
private static final int Y3
- See Also:
- Constant Field Values
-
graphicsObj
private GraphicsObject graphicsObj
graphics object
-
fallbackTextHandler
protected org.apache.xmlgraphics.java2d.TextHandler fallbackTextHandler
Fallback text handler
-
customTextHandler
protected org.apache.xmlgraphics.java2d.TextHandler customTextHandler
Custom text handler
-
resourceManager
private AFPResourceManager resourceManager
AFP resource manager
-
resourceInfo
private AFPResourceInfo resourceInfo
AFP resource info
-
paintingState
private AFPPaintingState paintingState
Current AFP state
-
graphicsConfig
private final org.apache.xmlgraphics.java2d.GraphicsConfigurationWithTransparency graphicsConfig
AFP graphics configuration
-
fontInfo
private FontInfo fontInfo
The AFP FontInfo
-
-
Constructor Detail
-
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
public AFPGraphics2D(AFPGraphics2D g2d)
Copy Constructor- Parameters:
g2d
- a AFPGraphics2D whose properties should be copied
-
-
Method Detail
-
setResourceManager
private void setResourceManager(AFPResourceManager resourceManager)
Sets the AFP resource manager- Parameters:
resourceManager
- the AFP resource manager
-
getResourceManager
public AFPResourceManager getResourceManager()
Returns the AFP resource manager associated with thisGraphics2D
instance.- Returns:
- the resource manager
-
setResourceInfo
private void setResourceInfo(AFPResourceInfo resourceInfo)
Sets the AFP resource info- Parameters:
resourceInfo
- the AFP resource info
-
getGraphicsObject
public GraphicsObject getGraphicsObject()
Returns the GOCA graphics object- Returns:
- the GOCA graphics object
-
setGraphicsObject
public void setGraphicsObject(GraphicsObject obj)
Sets the GOCA graphics object- Parameters:
obj
- the GOCA graphics object
-
setPaintingState
private void setPaintingState(AFPPaintingState paintingState)
Sets the AFP painting state- Parameters:
paintingState
- the AFP painting state
-
getPaintingState
public AFPPaintingState getPaintingState()
Returns the AFP painting state- Returns:
- the AFP painting state
-
setFontInfo
private void setFontInfo(FontInfo fontInfo)
Sets the FontInfo- Parameters:
fontInfo
- the FontInfo
-
getFontInfo
public FontInfo getFontInfo()
Returns the FontInfo- Returns:
- the FontInfo
-
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
protected void applyStroke(java.awt.Stroke stroke)
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
private boolean applyPaint(java.awt.Paint paint, boolean fill)
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
private void doDrawing(java.awt.Shape shape, boolean fill)
Handle the Batik drawing event- Parameters:
shape
- the shape to drawfill
- true if the shape is to be drawn filled
-
processPathIterator
private void processPathIterator(java.awt.geom.PathIterator iter)
Processes a path iterator generating the necessary painting operations.- Parameters:
iter
- PathIterator to process
-
flush
private void flush(java.util.List<java.lang.Integer> fillets)
-
listToIntLists
private java.util.List<int[]> listToIntLists(java.util.List<java.lang.Integer> input)
-
draw
public void draw(java.awt.Shape shape)
- Specified by:
draw
in classjava.awt.Graphics2D
-
fill
public void fill(java.awt.Shape shape)
- Specified by:
fill
in classjava.awt.Graphics2D
-
handleIOException
public void handleIOException(java.io.IOException ioe)
Central handler for IOExceptions for this class.- Parameters:
ioe
- IOException to handle
-
drawString
public void drawString(java.lang.String str, float x, float y)
- Specified by:
drawString
in classjava.awt.Graphics2D
-
getDeviceConfiguration
public java.awt.GraphicsConfiguration getDeviceConfiguration()
- Specified by:
getDeviceConfiguration
in classjava.awt.Graphics2D
-
create
public java.awt.Graphics create()
- Specified by:
create
in classjava.awt.Graphics
-
dispose
public void dispose()
- Specified by:
dispose
in classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
- Specified by:
drawImage
in classjava.awt.Graphics
-
buildBufferedImage
private java.awt.image.BufferedImage buildBufferedImage(java.awt.Dimension size)
-
drawBufferedImage
private boolean drawBufferedImage(java.awt.Image img, java.awt.image.BufferedImage bufferedImage, int width, int height, java.awt.image.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
public boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)
- Specified by:
drawImage
in classjava.awt.Graphics
-
drawRenderedImage
public void drawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)
- Specified by:
drawRenderedImage
in classjava.awt.Graphics2D
-
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
public void drawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)
- Specified by:
drawRenderableImage
in classjava.awt.Graphics2D
-
getFontMetrics
public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
- Specified by:
getFontMetrics
in classjava.awt.Graphics
-
setXORMode
public void setXORMode(java.awt.Color col)
- Specified by:
setXORMode
in classjava.awt.Graphics
-
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:
addNativeImage
in 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
public void copyArea(int x, int y, int width, int height, int dx, int dy)
- Specified by:
copyArea
in classjava.awt.Graphics
-
clearRect
public void clearRect(int x, int y, int width, int height)
- Overrides:
clearRect
in classorg.apache.xmlgraphics.java2d.AbstractGraphics2D
-
-