Class EscherGraphics2d
- java.lang.Object
-
- java.awt.Graphics
-
- java.awt.Graphics2D
-
- org.apache.poi.hssf.usermodel.EscherGraphics2d
-
public final class EscherGraphics2d extends Graphics2D
Translates Graphics2d calls into escher calls. The translation is lossy so many features are not supported and some just aren't implemented yet. If in doubt test the specific calls you wish to make. Graphics calls are always drawn into an EscherGroup so one will need to be created.Important:
One important concept worth considering is that of font size. One of the difficulties in converting Graphics calls into escher drawing calls is that Excel does not have the concept of absolute pixel positions. It measures its cell widths in 'characters' and the cell heights in points. Unfortunately it's not defined exactly what a type of character it's measuring. Presumably this is due to the fact that the Excel will be using different fonts on different platforms or even within the same platform.
Because of this constraint you have to calculate the verticalPointsPerPixel. This the amount the font should be scaled by when you issue commands such as drawString(). A good way to calculate this is to use the follow formula:
multipler = groupHeightInPoints / heightOfGroupThe height of the group is calculated fairly simply by calculating the difference between the y coordinates of the bounding box of the shape. The height of the group can be calculated by using a convenience called
HSSFClientAnchor.getAnchorHeightInPoints().
-
-
Constructor Summary
Constructors Constructor Description EscherGraphics2d(EscherGraphics escherGraphics)Constructs one escher graphics object from an escher graphics object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRenderingHints(Map<?,?> map)voidclearRect(int i, int j, int k, int l)voidclip(Shape shape)voidclipRect(int x, int y, int width, int height)voidcopyArea(int x, int y, int width, int height, int dx, int dy)Graphicscreate()voiddispose()voiddraw(Shape shape)voiddrawArc(int x, int y, int width, int height, int startAngle, int arcAngle)voiddrawGlyphVector(GlyphVector g, float x, float y)voiddrawImage(BufferedImage bufferedimage, BufferedImageOp op, int x, int y)booleandrawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgColor, ImageObserver imageobserver)booleandrawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver imageobserver)booleandrawImage(Image image, int dx1, int dy1, int dx2, int dy2, Color bgColor, ImageObserver imageobserver)booleandrawImage(Image img, int x, int y, int width, int height, ImageObserver observer)booleandrawImage(Image image, int x, int y, Color bgColor, ImageObserver imageobserver)booleandrawImage(Image image, int x, int y, ImageObserver imageobserver)booleandrawImage(Image image, AffineTransform affinetransform, ImageObserver imageobserver)voiddrawLine(int x1, int y1, int x2, int y2)voiddrawLine(int x1, int y1, int x2, int y2, int width)voiddrawOval(int x, int y, int width, int height)voiddrawPolygon(int[] xPoints, int[] yPoints, int nPoints)voiddrawPolyline(int[] xPoints, int[] yPoints, int nPoints)voiddrawRect(int x, int y, int width, int height)voiddrawRenderableImage(RenderableImage renderableimage, AffineTransform affinetransform)voiddrawRenderedImage(RenderedImage renderedimage, AffineTransform affinetransform)voiddrawRoundRect(int i, int j, int k, int l, int i1, int j1)voiddrawString(String string, float x, float y)voiddrawString(String string, int x, int y)voiddrawString(AttributedCharacterIterator attributedcharacteriterator, float x, float y)voiddrawString(AttributedCharacterIterator attributedcharacteriterator, int x, int y)voidfill(Shape shape)voidfillArc(int i, int j, int k, int l, int i1, int j1)voidfillOval(int x, int y, int width, int height)voidfillPolygon(int[] xPoints, int[] yPoints, int nPoints)Fills a (closed) polygon, as defined by a pair of arrays, which hold the x and y coordinates.voidfillRect(int x, int y, int width, int height)voidfillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)ColorgetBackground()ShapegetClip()RectanglegetClipBounds()ColorgetColor()CompositegetComposite()GraphicsConfigurationgetDeviceConfiguration()FontgetFont()FontMetricsgetFontMetrics(Font font)FontRenderContextgetFontRenderContext()PaintgetPaint()ObjectgetRenderingHint(RenderingHints.Key key)RenderingHintsgetRenderingHints()StrokegetStroke()AffineTransformgetTransform()booleanhit(Rectangle rectangle, Shape shape, boolean flag)voidrotate(double d)voidrotate(double d, double d1, double d2)voidscale(double d, double d1)voidsetBackground(Color c)voidsetClip(int i, int j, int k, int l)voidsetClip(Shape shape)voidsetColor(Color c)voidsetComposite(Composite composite)voidsetFont(Font font)voidsetPaint(Paint paint1)voidsetPaintMode()voidsetRenderingHint(RenderingHints.Key key, Object obj)voidsetRenderingHints(Map<?,?> map)voidsetStroke(Stroke s)voidsetTransform(AffineTransform affinetransform)voidsetXORMode(Color color1)voidshear(double d, double d1)voidtransform(AffineTransform affinetransform)voidtranslate(double d, double d1)voidtranslate(int i, int j)-
Methods inherited from class java.awt.Graphics2D
draw3DRect, fill3DRect
-
Methods inherited from class java.awt.Graphics
create, drawBytes, drawChars, drawPolygon, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toString
-
-
-
-
Constructor Detail
-
EscherGraphics2d
public EscherGraphics2d(EscherGraphics escherGraphics)
Constructs one escher graphics object from an escher graphics object.- Parameters:
escherGraphics- the original EscherGraphics2d object to copy
-
-
Method Detail
-
addRenderingHints
public void addRenderingHints(Map<?,?> map)
- Specified by:
addRenderingHintsin classGraphics2D
-
clearRect
public void clearRect(int i, int j, int k, int l)
-
clip
public void clip(Shape shape)
- Specified by:
clipin classGraphics2D
-
clipRect
public void clipRect(int x, int y, int width, int height)
-
copyArea
public void copyArea(int x, int y, int width, int height, int dx, int dy)
-
draw
public void draw(Shape shape)
- Specified by:
drawin classGraphics2D
-
drawArc
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
-
drawGlyphVector
public void drawGlyphVector(GlyphVector g, float x, float y)
- Specified by:
drawGlyphVectorin classGraphics2D
-
drawImage
public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgColor, ImageObserver imageobserver)
-
drawImage
public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver imageobserver)
-
drawImage
public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2, Color bgColor, ImageObserver imageobserver)
-
drawImage
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
-
drawImage
public boolean drawImage(Image image, int x, int y, Color bgColor, ImageObserver imageobserver)
-
drawImage
public boolean drawImage(Image image, int x, int y, ImageObserver imageobserver)
-
drawImage
public boolean drawImage(Image image, AffineTransform affinetransform, ImageObserver imageobserver)
- Specified by:
drawImagein classGraphics2D
-
drawImage
public void drawImage(BufferedImage bufferedimage, BufferedImageOp op, int x, int y)
- Specified by:
drawImagein classGraphics2D
-
drawLine
public void drawLine(int x1, int y1, int x2, int y2, int width)
-
drawLine
public void drawLine(int x1, int y1, int x2, int y2)
-
drawOval
public void drawOval(int x, int y, int width, int height)
-
drawPolygon
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)- Specified by:
drawPolygonin classGraphics
-
drawPolyline
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)- Specified by:
drawPolylinein classGraphics
-
drawRect
public void drawRect(int x, int y, int width, int height)
-
drawRenderableImage
public void drawRenderableImage(RenderableImage renderableimage, AffineTransform affinetransform)
- Specified by:
drawRenderableImagein classGraphics2D
-
drawRenderedImage
public void drawRenderedImage(RenderedImage renderedimage, AffineTransform affinetransform)
- Specified by:
drawRenderedImagein classGraphics2D
-
drawRoundRect
public void drawRoundRect(int i, int j, int k, int l, int i1, int j1)- Specified by:
drawRoundRectin classGraphics
-
drawString
public void drawString(String string, float x, float y)
- Specified by:
drawStringin classGraphics2D
-
drawString
public void drawString(String string, int x, int y)
- Specified by:
drawStringin classGraphics2D
-
drawString
public void drawString(AttributedCharacterIterator attributedcharacteriterator, float x, float y)
- Specified by:
drawStringin classGraphics2D
-
drawString
public void drawString(AttributedCharacterIterator attributedcharacteriterator, int x, int y)
- Specified by:
drawStringin classGraphics2D
-
fill
public void fill(Shape shape)
- Specified by:
fillin classGraphics2D
-
fillArc
public void fillArc(int i, int j, int k, int l, int i1, int j1)
-
fillOval
public void fillOval(int x, int y, int width, int height)
-
fillPolygon
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)Fills a (closed) polygon, as defined by a pair of arrays, which hold the x and y coordinates.This draws the polygon, with
nPointline segments. The firstnPoint - 1line segments are drawn between sequential points (xPoints[i],yPoints[i],xPoints[i+1],yPoints[i+1]). The final line segment is a closing one, from the last point to the first (assuming they are different).The area inside of the polygon is defined by using an even-odd fill rule (also known as the alternating rule), and the area inside of it is filled.
- Specified by:
fillPolygonin classGraphics- Parameters:
xPoints- array of thexcoordinates.yPoints- array of theycoordinates.nPoints- the total number of points in the polygon.- See Also:
Graphics.drawPolygon(int[], int[], int)
-
fillRect
public void fillRect(int x, int y, int width, int height)
-
fillRoundRect
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)- Specified by:
fillRoundRectin classGraphics
-
getBackground
public Color getBackground()
- Specified by:
getBackgroundin classGraphics2D
-
getClipBounds
public Rectangle getClipBounds()
- Specified by:
getClipBoundsin classGraphics
-
getComposite
public Composite getComposite()
- Specified by:
getCompositein classGraphics2D
-
getDeviceConfiguration
public GraphicsConfiguration getDeviceConfiguration()
- Specified by:
getDeviceConfigurationin classGraphics2D
-
getFontMetrics
public FontMetrics getFontMetrics(Font font)
- Specified by:
getFontMetricsin classGraphics
-
getFontRenderContext
public FontRenderContext getFontRenderContext()
- Specified by:
getFontRenderContextin classGraphics2D
-
getPaint
public Paint getPaint()
- Specified by:
getPaintin classGraphics2D
-
getRenderingHint
public Object getRenderingHint(RenderingHints.Key key)
- Specified by:
getRenderingHintin classGraphics2D
-
getRenderingHints
public RenderingHints getRenderingHints()
- Specified by:
getRenderingHintsin classGraphics2D
-
getStroke
public Stroke getStroke()
- Specified by:
getStrokein classGraphics2D
-
getTransform
public AffineTransform getTransform()
- Specified by:
getTransformin classGraphics2D
-
hit
public boolean hit(Rectangle rectangle, Shape shape, boolean flag)
- Specified by:
hitin classGraphics2D
-
rotate
public void rotate(double d)
- Specified by:
rotatein classGraphics2D
-
rotate
public void rotate(double d, double d1, double d2)- Specified by:
rotatein classGraphics2D
-
scale
public void scale(double d, double d1)- Specified by:
scalein classGraphics2D
-
setBackground
public void setBackground(Color c)
- Specified by:
setBackgroundin classGraphics2D
-
setComposite
public void setComposite(Composite composite)
- Specified by:
setCompositein classGraphics2D
-
setPaint
public void setPaint(Paint paint1)
- Specified by:
setPaintin classGraphics2D
-
setPaintMode
public void setPaintMode()
- Specified by:
setPaintModein classGraphics
-
setRenderingHint
public void setRenderingHint(RenderingHints.Key key, Object obj)
- Specified by:
setRenderingHintin classGraphics2D
-
setRenderingHints
public void setRenderingHints(Map<?,?> map)
- Specified by:
setRenderingHintsin classGraphics2D
-
setStroke
public void setStroke(Stroke s)
- Specified by:
setStrokein classGraphics2D
-
setTransform
public void setTransform(AffineTransform affinetransform)
- Specified by:
setTransformin classGraphics2D
-
setXORMode
public void setXORMode(Color color1)
- Specified by:
setXORModein classGraphics
-
shear
public void shear(double d, double d1)- Specified by:
shearin classGraphics2D
-
transform
public void transform(AffineTransform affinetransform)
- Specified by:
transformin classGraphics2D
-
translate
public void translate(double d, double d1)- Specified by:
translatein classGraphics2D
-
translate
public void translate(int i, int j)- Specified by:
translatein classGraphics2D
-
-