Top Description Fields Constructors Methods
org.apache.poi.hssf.usermodel

public Class EscherGraphics

extends Graphics
Class Inheritance
Imports
org.apache.logging.log4j.LogManager, .Logger, org.apache.poi.hssf.util.HSSFColor, org.apache.poi.util.NotImplemented, .SuppressForbidden, java.awt.*, java.awt.image.ImageObserver, java.text.AttributedCharacterIterator

Translates Graphics 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 performed 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 we've had 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:

multiplier = 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().

Field Summary

Modifier and TypeField and Description
private Color
private final HSSFShapeGroup
private Font
private Color
private static final Logger
private final float
private final float
private final HSSFWorkbook

Constructor Summary

AccessConstructor and Description
public
EscherGraphics(HSSFShapeGroup
The escher group to write the graphics calls into.
escherGroup
,
HSSFWorkbook
The workbook we are using.
workbook
,
Color
The foreground color to use as default.
forecolor
,
float
The font multiplier. (See class description for information on how this works.).
verticalPointsPerPixel
)

Construct an escher graphics object.

pack-priv
EscherGraphics(HSSFShapeGroup
The escher group to write the graphics calls into.
escherGroup
,
HSSFWorkbook
The workbook we are using.
workbook
,
Color
The foreground color to use as default.
foreground
,
Font
The font to use.
font
,
float
The font multiplier. (See class description for information on how this works.).
verticalPointsPerPixel
)

Constructs an escher graphics object.

Method Summary

Modifier and TypeMethod and Description
private int[]
addToAll(int[] values, int amount)

public void
clearRect(int
the x coordinate of the rectangle to clear.
x
,
int
the y coordinate of the rectangle to clear.
y
,
int
the width of the rectangle to clear.
width
,
int
the height of the rectangle to clear.
height
)

Implements abstract java.awt.Graphics.clearRect.

Clears the specified rectangle by filling it with the background color of the current drawing surface.

public void
clipRect(int
the x coordinate of the rectangle to intersect the clip with
x
,
int
the y coordinate of the rectangle to intersect the clip with
y
,
int
the width of the rectangle to intersect the clip with
width
,
int
the height of the rectangle to intersect the clip with
height
)

Implements abstract java.awt.Graphics.clipRect.

Intersects the current clip with the specified rectangle.

public void
copyArea(int
the x coordinate of the source rectangle.
x
,
int
the y coordinate of the source rectangle.
y
,
int
the width of the source rectangle.
width
,
int
the height of the source rectangle.
height
,
int
the horizontal distance to copy the pixels.
dx
,
int
the vertical distance to copy the pixels.
dy
)

Implements abstract java.awt.Graphics.copyArea.

Copies an area of the component by a distance specified by dx and dy.

public Graphics
create()

Implements abstract java.awt.Graphics.create.

Creates a new Graphics object that is a copy of this Graphics object.

public void
dispose()

Implements abstract java.awt.Graphics.dispose.

Disposes of this graphics context and releases any system resources that it is using.

public void
drawArc(int
the x coordinate of the upper-left corner of the arc to be drawn.
x
,
int
the y coordinate of the upper-left corner of the arc to be drawn.
y
,
int
the width of the arc to be drawn.
width
,
int
the height of the arc to be drawn.
height
,
int
the beginning angle.
startAngle
,
int
the angular extent of the arc, relative to the start angle.
arcAngle
)

Implements abstract java.awt.Graphics.drawArc.

Draws the outline of a circular or elliptical arc covering the specified rectangle.

public boolean
drawImage(Image
the specified image to be drawn. This method does nothing if img is null.
img
,
int
the x coordinate of the first corner of the destination rectangle.
dx1
,
int
the y coordinate of the first corner of the destination rectangle.
dy1
,
int
the x coordinate of the second corner of the destination rectangle.
dx2
,
int
the y coordinate of the second corner of the destination rectangle.
dy2
,
int
the x coordinate of the first corner of the source rectangle.
sx1
,
int
the y coordinate of the first corner of the source rectangle.
sy1
,
int
the x coordinate of the second corner of the source rectangle.
sx2
,
int
the y coordinate of the second corner of the source rectangle.
sy2
,
Color
the background color to paint under the non-opaque portions of the image.
bgcolor
,
ImageObserver
object to be notified as more of the image is scaled and converted.
observer
)

Implements abstract java.awt.Graphics.drawImage.

Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.

public boolean
drawImage(Image
the specified image to be drawn. This method does nothing if img is null.
img
,
int
the x coordinate of the first corner of the destination rectangle.
dx1
,
int
the y coordinate of the first corner of the destination rectangle.
dy1
,
int
the x coordinate of the second corner of the destination rectangle.
dx2
,
int
the y coordinate of the second corner of the destination rectangle.
dy2
,
int
the x coordinate of the first corner of the source rectangle.
sx1
,
int
the y coordinate of the first corner of the source rectangle.
sy1
,
int
the x coordinate of the second corner of the source rectangle.
sx2
,
int
the y coordinate of the second corner of the source rectangle.
sy2
,
ImageObserver
object to be notified as more of the image is scaled and converted.
observer
)

Implements abstract java.awt.Graphics.drawImage.

Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.

public boolean
drawImage(Image
the specified image to be drawn. This method does nothing if img is null.
image
,
int
the x coordinate.
i
,
int
the y coordinate.
j
,
int
the width of the rectangle.
k
,
int
the height of the rectangle.
l
,
Color
the background color to paint under the non-opaque portions of the image.
color
,
ImageObserver
object to be notified as more of the image is converted.
imageobserver
)

Implements abstract java.awt.Graphics.drawImage.

Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.

public boolean
drawImage(Image
the specified image to be drawn. This method does nothing if img is null.
image
,
int
the x coordinate.
i
,
int
the y coordinate.
j
,
int
the width of the rectangle.
k
,
int
the height of the rectangle.
l
,
ImageObserver
object to be notified as more of the image is converted.
imageobserver
)

Implements abstract java.awt.Graphics.drawImage.

Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.

public boolean
drawImage(Image
the specified image to be drawn. This method does nothing if img is null.
image
,
int
the x coordinate.
i
,
int
the y coordinate.
j
,
Color
the background color to paint under the non-opaque portions of the image.
color
,
ImageObserver
object to be notified as more of the image is converted.
imageobserver
)

Implements abstract java.awt.Graphics.drawImage.

Draws as much of the specified image as is currently available.

public boolean
drawImage(Image
the specified image to be drawn. This method does nothing if img is null.
image
,
int
the x coordinate.
i
,
int
the y coordinate.
j
,
ImageObserver
object to be notified as more of the image is converted.
imageobserver
)

Implements abstract java.awt.Graphics.drawImage.

Draws as much of the specified image as is currently available.

public void
drawLine(int
the first point's x coordinate.
x1
,
int
the first point's y coordinate.
y1
,
int
the second point's x coordinate.
x2
,
int
the second point's y coordinate.
y2
)

Implements abstract java.awt.Graphics.drawLine.

Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.

public void
drawLine(int x1, int y1, int x2, int y2, int width)

public void
drawOval(int
the x coordinate of the upper left corner of the oval to be drawn.
x
,
int
the y coordinate of the upper left corner of the oval to be drawn.
y
,
int
the width of the oval to be drawn.
width
,
int
the height of the oval to be drawn.
height
)

Implements abstract java.awt.Graphics.drawOval.

Draws the outline of an oval.

public void
drawPolygon(int[]
an array of x coordinates.
xPoints
,
int[]
an array of y coordinates.
yPoints
,
int
the total number of points.
nPoints
)

Implements abstract java.awt.Graphics.drawPolygon.

Draws a closed polygon defined by arrays of x and y coordinates.

public void
drawPolyline(int[]
an array of x points
xPoints
,
int[]
an array of y points
yPoints
,
int
the total number of points
nPoints
)

Implements abstract java.awt.Graphics.drawPolyline.

Draws a sequence of connected lines defined by arrays of x and y coordinates.

public void
drawRect(int
the x coordinate of the rectangle to be drawn.
x
,
int
the y coordinate of the rectangle to be drawn.
y
,
int
the width of the rectangle to be drawn.
width
,
int
the height of the rectangle to be drawn.
height
)

Overrides java.awt.Graphics.drawRect.

Draws the outline of the specified rectangle.

public void
drawRoundRect(int
the x coordinate of the rectangle to be drawn.
x
,
int
the y coordinate of the rectangle to be drawn.
y
,
int
the width of the rectangle to be drawn.
width
,
int
the height of the rectangle to be drawn.
height
,
int
the horizontal diameter of the arc at the four corners.
arcWidth
,
int
the vertical diameter of the arc at the four corners.
arcHeight
)

Implements abstract java.awt.Graphics.drawRoundRect.

Draws an outlined round-cornered rectangle using this graphics context's current color.

public void
drawString(String
the string to be drawn.
str
,
int
the x coordinate.
x
,
int
the y coordinate.
y
)

Implements abstract java.awt.Graphics.drawString.

Draws the text given by the specified string, using this graphics context's current font and color.

public void
drawString(AttributedCharacterIterator
the iterator whose text is to be drawn
iterator
,
int
the x coordinate.
x
,
int
the y coordinate.
y
)

Implements abstract java.awt.Graphics.drawString.

Renders the text of the specified iterator applying its attributes in accordance with the specification of the TextAttribute class.

public void
fillArc(int
the x coordinate of the upper-left corner of the arc to be filled.
x
,
int
the y coordinate of the upper-left corner of the arc to be filled.
y
,
int
the width of the arc to be filled.
width
,
int
the height of the arc to be filled.
height
,
int
the beginning angle.
startAngle
,
int
the angular extent of the arc, relative to the start angle.
arcAngle
)

Implements abstract java.awt.Graphics.fillArc.

Fills a circular or elliptical arc covering the specified rectangle.

public void
fillOval(int
the x coordinate of the upper left corner of the oval to be filled.
x
,
int
the y coordinate of the upper left corner of the oval to be filled.
y
,
int
the width of the oval to be filled.
width
,
int
the height of the oval to be filled.
height
)

Implements abstract java.awt.Graphics.fillOval.

Fills an oval bounded by the specified rectangle with the current color.

public void
fillPolygon(int[]
array of the x coordinates.
xPoints
,
int[]
array of the y coordinates.
yPoints
,
int
the total number of points in the polygon.
nPoints
)

Implements abstract java.awt.Graphics.fillPolygon.

Fills a (closed) polygon, as defined by a pair of arrays, which hold the x and y coordinates.

public void
fillRect(int
the x coordinate of the rectangle to be filled.
x
,
int
the y coordinate of the rectangle to be filled.
y
,
int
the width of the rectangle to be filled.
width
,
int
the height of the rectangle to be filled.
height
)

Implements abstract java.awt.Graphics.fillRect.

Fills the specified rectangle.

public void
fillRoundRect(int
the x coordinate of the rectangle to be filled.
x
,
int
the y coordinate of the rectangle to be filled.
y
,
int
the width of the rectangle to be filled.
width
,
int
the height of the rectangle to be filled.
height
,
int
the horizontal diameter of the arc at the four corners.
arcWidth
,
int
the vertical diameter of the arc at the four corners.
arcHeight
)

Implements abstract java.awt.Graphics.fillRoundRect.

Fills the specified rounded corner rectangle with the current color.

private int
findBiggest(int[] values)

private int
findSmallest(int[] values)

public Color
public Shape
getClip()

Implements abstract java.awt.Graphics.getClip.

Gets the current clipping area.

public Rectangle
getClipBounds()

Implements abstract java.awt.Graphics.getClipBounds.

Returns the bounding rectangle of the current clipping area.

public Color
getColor()

Implements abstract java.awt.Graphics.getColor.

Gets this graphics context's current color.

pack-priv HSSFShapeGroup
public Font
getFont()

Implements abstract java.awt.Graphics.getFont.

Gets the current font.

public FontMetrics
getFontMetrics(Font
the specified font
f
)

Implements abstract java.awt.Graphics.getFontMetrics.

Gets the font metrics for the specified font.

private HSSFFont
matchFont(Font matchFont)

public void
setBackground(Color background)

public void
setClip(int
the x coordinate of the new clip rectangle.
x
,
int
the y coordinate of the new clip rectangle.
y
,
int
the width of the new clip rectangle.
width
,
int
the height of the new clip rectangle.
height
)

Implements abstract java.awt.Graphics.setClip.

Sets the current clip to the rectangle specified by the given coordinates.

public void
setClip(Shape
the Shape to use to set the clip. Passing null clears the current clip.
shape
)

Implements abstract java.awt.Graphics.setClip.

Sets the current clipping area to an arbitrary clip shape.

public void
setColor(Color
the new rendering color.
color
)

Implements abstract java.awt.Graphics.setColor.

Sets this graphics context's current color to the specified color.

public void
setFont(Font
the font.
f
)

Implements abstract java.awt.Graphics.setFont.

Sets this graphics context's font to the specified font.

public void
setPaintMode()

Implements abstract java.awt.Graphics.setPaintMode.

Sets the paint mode of this graphics context to overwrite the destination with this graphics context's current color.

public void
setXORMode(Color
the XOR alternation color
color
)

Implements abstract java.awt.Graphics.setXORMode.

Sets the paint mode of this graphics context to alternate between this graphics context's current color and the new specified color.

public void
translate(int
the x coordinate.
x
,
int
the y coordinate.
y
)

Implements abstract java.awt.Graphics.translate.

Translates the origin of the graphics context to the point (x, y) in the current coordinate system.

Inherited from java.awt.Graphics:
createdraw3DRectdrawBytesdrawCharsdrawPolygonfill3DRectfillPolygonfinalizegetClipBoundsgetClipRectgetFontMetricshitCliptoString