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 / heightOfGroup
The 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 void
addRenderingHints(Map<?,?> map)
void
clearRect(int i, int j, int k, int l)
void
clip(Shape shape)
void
clipRect(int x, int y, int width, int height)
void
copyArea(int x, int y, int width, int height, int dx, int dy)
Graphics
create()
void
dispose()
void
draw(Shape shape)
void
drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
void
drawGlyphVector(GlyphVector g, float x, float y)
void
drawImage(BufferedImage bufferedimage, BufferedImageOp op, int x, int y)
boolean
drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgColor, ImageObserver imageobserver)
boolean
drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver imageobserver)
boolean
drawImage(Image image, int dx1, int dy1, int dx2, int dy2, Color bgColor, ImageObserver imageobserver)
boolean
drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
boolean
drawImage(Image image, int x, int y, Color bgColor, ImageObserver imageobserver)
boolean
drawImage(Image image, int x, int y, ImageObserver imageobserver)
boolean
drawImage(Image image, AffineTransform affinetransform, ImageObserver imageobserver)
void
drawLine(int x1, int y1, int x2, int y2)
void
drawLine(int x1, int y1, int x2, int y2, int width)
void
drawOval(int x, int y, int width, int height)
void
drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
void
drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
void
drawRect(int x, int y, int width, int height)
void
drawRenderableImage(RenderableImage renderableimage, AffineTransform affinetransform)
void
drawRenderedImage(RenderedImage renderedimage, AffineTransform affinetransform)
void
drawRoundRect(int i, int j, int k, int l, int i1, int j1)
void
drawString(String string, float x, float y)
void
drawString(String string, int x, int y)
void
drawString(AttributedCharacterIterator attributedcharacteriterator, float x, float y)
void
drawString(AttributedCharacterIterator attributedcharacteriterator, int x, int y)
void
fill(Shape shape)
void
fillArc(int i, int j, int k, int l, int i1, int j1)
void
fillOval(int x, int y, int width, int height)
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.void
fillRect(int x, int y, int width, int height)
void
fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
Color
getBackground()
Shape
getClip()
Rectangle
getClipBounds()
Color
getColor()
Composite
getComposite()
GraphicsConfiguration
getDeviceConfiguration()
Font
getFont()
FontMetrics
getFontMetrics(Font font)
FontRenderContext
getFontRenderContext()
Paint
getPaint()
Object
getRenderingHint(RenderingHints.Key key)
RenderingHints
getRenderingHints()
Stroke
getStroke()
AffineTransform
getTransform()
boolean
hit(Rectangle rectangle, Shape shape, boolean flag)
void
rotate(double d)
void
rotate(double d, double d1, double d2)
void
scale(double d, double d1)
void
setBackground(Color c)
void
setClip(int i, int j, int k, int l)
void
setClip(Shape shape)
void
setColor(Color c)
void
setComposite(Composite composite)
void
setFont(Font font)
void
setPaint(Paint paint1)
void
setPaintMode()
void
setRenderingHint(RenderingHints.Key key, Object obj)
void
setRenderingHints(Map<?,?> map)
void
setStroke(Stroke s)
void
setTransform(AffineTransform affinetransform)
void
setXORMode(Color color1)
void
shear(double d, double d1)
void
transform(AffineTransform affinetransform)
void
translate(double d, double d1)
void
translate(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:
addRenderingHints
in classGraphics2D
-
clearRect
public void clearRect(int i, int j, int k, int l)
-
clip
public void clip(Shape shape)
- Specified by:
clip
in 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:
draw
in 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:
drawGlyphVector
in 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:
drawImage
in classGraphics2D
-
drawImage
public void drawImage(BufferedImage bufferedimage, BufferedImageOp op, int x, int y)
- Specified by:
drawImage
in 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:
drawPolygon
in classGraphics
-
drawPolyline
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
- Specified by:
drawPolyline
in classGraphics
-
drawRect
public void drawRect(int x, int y, int width, int height)
-
drawRenderableImage
public void drawRenderableImage(RenderableImage renderableimage, AffineTransform affinetransform)
- Specified by:
drawRenderableImage
in classGraphics2D
-
drawRenderedImage
public void drawRenderedImage(RenderedImage renderedimage, AffineTransform affinetransform)
- Specified by:
drawRenderedImage
in classGraphics2D
-
drawRoundRect
public void drawRoundRect(int i, int j, int k, int l, int i1, int j1)
- Specified by:
drawRoundRect
in classGraphics
-
drawString
public void drawString(String string, float x, float y)
- Specified by:
drawString
in classGraphics2D
-
drawString
public void drawString(String string, int x, int y)
- Specified by:
drawString
in classGraphics2D
-
drawString
public void drawString(AttributedCharacterIterator attributedcharacteriterator, float x, float y)
- Specified by:
drawString
in classGraphics2D
-
drawString
public void drawString(AttributedCharacterIterator attributedcharacteriterator, int x, int y)
- Specified by:
drawString
in classGraphics2D
-
fill
public void fill(Shape shape)
- Specified by:
fill
in 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
nPoint
line segments. The firstnPoint - 1
line 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:
fillPolygon
in classGraphics
- Parameters:
xPoints
- array of thex
coordinates.yPoints
- array of they
coordinates.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:
fillRoundRect
in classGraphics
-
getBackground
public Color getBackground()
- Specified by:
getBackground
in classGraphics2D
-
getClipBounds
public Rectangle getClipBounds()
- Specified by:
getClipBounds
in classGraphics
-
getComposite
public Composite getComposite()
- Specified by:
getComposite
in classGraphics2D
-
getDeviceConfiguration
public GraphicsConfiguration getDeviceConfiguration()
- Specified by:
getDeviceConfiguration
in classGraphics2D
-
getFontMetrics
public FontMetrics getFontMetrics(Font font)
- Specified by:
getFontMetrics
in classGraphics
-
getFontRenderContext
public FontRenderContext getFontRenderContext()
- Specified by:
getFontRenderContext
in classGraphics2D
-
getPaint
public Paint getPaint()
- Specified by:
getPaint
in classGraphics2D
-
getRenderingHint
public Object getRenderingHint(RenderingHints.Key key)
- Specified by:
getRenderingHint
in classGraphics2D
-
getRenderingHints
public RenderingHints getRenderingHints()
- Specified by:
getRenderingHints
in classGraphics2D
-
getStroke
public Stroke getStroke()
- Specified by:
getStroke
in classGraphics2D
-
getTransform
public AffineTransform getTransform()
- Specified by:
getTransform
in classGraphics2D
-
hit
public boolean hit(Rectangle rectangle, Shape shape, boolean flag)
- Specified by:
hit
in classGraphics2D
-
rotate
public void rotate(double d)
- Specified by:
rotate
in classGraphics2D
-
rotate
public void rotate(double d, double d1, double d2)
- Specified by:
rotate
in classGraphics2D
-
scale
public void scale(double d, double d1)
- Specified by:
scale
in classGraphics2D
-
setBackground
public void setBackground(Color c)
- Specified by:
setBackground
in classGraphics2D
-
setComposite
public void setComposite(Composite composite)
- Specified by:
setComposite
in classGraphics2D
-
setPaint
public void setPaint(Paint paint1)
- Specified by:
setPaint
in classGraphics2D
-
setPaintMode
public void setPaintMode()
- Specified by:
setPaintMode
in classGraphics
-
setRenderingHint
public void setRenderingHint(RenderingHints.Key key, Object obj)
- Specified by:
setRenderingHint
in classGraphics2D
-
setRenderingHints
public void setRenderingHints(Map<?,?> map)
- Specified by:
setRenderingHints
in classGraphics2D
-
setStroke
public void setStroke(Stroke s)
- Specified by:
setStroke
in classGraphics2D
-
setTransform
public void setTransform(AffineTransform affinetransform)
- Specified by:
setTransform
in classGraphics2D
-
setXORMode
public void setXORMode(Color color1)
- Specified by:
setXORMode
in classGraphics
-
shear
public void shear(double d, double d1)
- Specified by:
shear
in classGraphics2D
-
transform
public void transform(AffineTransform affinetransform)
- Specified by:
transform
in classGraphics2D
-
translate
public void translate(double d, double d1)
- Specified by:
translate
in classGraphics2D
-
translate
public void translate(int i, int j)
- Specified by:
translate
in classGraphics2D
-
-