org.apache.poi.hssf.usermodel
Class EscherGraphics

java.lang.Object
  extended by java.awt.Graphics
      extended by org.apache.poi.hssf.usermodel.EscherGraphics

public class EscherGraphics
extends java.awt.Graphics

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 it's 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:

      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
EscherGraphics(HSSFShapeGroup escherGroup, HSSFWorkbook workbook, java.awt.Color forecolor, float verticalPointsPerPixel)
          Construct an escher graphics object.
 
Method Summary
 void clearRect(int x, int y, int width, int height)
           
 void clipRect(int x, int y, int width, int height)
           
 void copyArea(int x, int y, int width, int height, int dx, int dy)
           
 java.awt.Graphics create()
           
 void dispose()
           
 void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
           
 boolean drawImage(java.awt.Image image, int i, int j, java.awt.Color color, java.awt.image.ImageObserver imageobserver)
           
 boolean drawImage(java.awt.Image image, int i, int j, java.awt.image.ImageObserver imageobserver)
           
 boolean drawImage(java.awt.Image image, int i, int j, int k, int l, java.awt.Color color, java.awt.image.ImageObserver imageobserver)
           
 boolean drawImage(java.awt.Image image, int i, int j, int k, int l, java.awt.image.ImageObserver imageobserver)
           
 boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver observer)
           
 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 drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
           
 void drawString(java.text.AttributedCharacterIterator iterator, int x, int y)
           
 void drawString(java.lang.String str, int x, int y)
           
 void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
           
 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)
           
 java.awt.Color getBackground()
           
 java.awt.Shape getClip()
           
 java.awt.Rectangle getClipBounds()
           
 java.awt.Color getColor()
           
 java.awt.Font getFont()
           
 java.awt.FontMetrics getFontMetrics(java.awt.Font f)
           
 void setBackground(java.awt.Color background)
           
 void setClip(int x, int y, int width, int height)
           
 void setClip(java.awt.Shape shape)
           
 void setColor(java.awt.Color color)
           
 void setFont(java.awt.Font f)
           
 void setPaintMode()
           
 void setXORMode(java.awt.Color color)
           
 void translate(int x, int y)
           
 
Methods inherited from class java.awt.Graphics
create, draw3DRect, drawBytes, drawChars, drawPolygon, fill3DRect, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EscherGraphics

public EscherGraphics(HSSFShapeGroup escherGroup,
                      HSSFWorkbook workbook,
                      java.awt.Color forecolor,
                      float verticalPointsPerPixel)
Construct an escher graphics object.

Parameters:
escherGroup - The escher group to write the graphics calls into.
workbook - The workbook we are using.
forecolor - The foreground color to use as default.
verticalPointsPerPixel - The font multiplier. (See class description for information on how this works.).
Method Detail

clearRect

@NotImplemented
public void clearRect(int x,
                                     int y,
                                     int width,
                                     int height)
Specified by:
clearRect in class java.awt.Graphics

clipRect

@NotImplemented
public void clipRect(int x,
                                    int y,
                                    int width,
                                    int height)
Specified by:
clipRect in class java.awt.Graphics

copyArea

@NotImplemented
public void copyArea(int x,
                                    int y,
                                    int width,
                                    int height,
                                    int dx,
                                    int dy)
Specified by:
copyArea in class java.awt.Graphics

create

public java.awt.Graphics create()
Specified by:
create in class java.awt.Graphics

dispose

public void dispose()
Specified by:
dispose in class java.awt.Graphics

drawArc

@NotImplemented
public void drawArc(int x,
                                   int y,
                                   int width,
                                   int height,
                                   int startAngle,
                                   int arcAngle)
Specified by:
drawArc in class java.awt.Graphics

drawImage

@NotImplemented
public boolean drawImage(java.awt.Image img,
                                        int dx1,
                                        int dy1,
                                        int dx2,
                                        int dy2,
                                        int sx1,
                                        int sy1,
                                        int sx2,
                                        int sy2,
                                        java.awt.Color bgcolor,
                                        java.awt.image.ImageObserver observer)
Specified by:
drawImage in class java.awt.Graphics

drawImage

@NotImplemented
public boolean drawImage(java.awt.Image img,
                                        int dx1,
                                        int dy1,
                                        int dx2,
                                        int dy2,
                                        int sx1,
                                        int sy1,
                                        int sx2,
                                        int sy2,
                                        java.awt.image.ImageObserver observer)
Specified by:
drawImage in class java.awt.Graphics

drawImage

public boolean drawImage(java.awt.Image image,
                         int i,
                         int j,
                         int k,
                         int l,
                         java.awt.Color color,
                         java.awt.image.ImageObserver imageobserver)
Specified by:
drawImage in class java.awt.Graphics

drawImage

public boolean drawImage(java.awt.Image image,
                         int i,
                         int j,
                         int k,
                         int l,
                         java.awt.image.ImageObserver imageobserver)
Specified by:
drawImage in class java.awt.Graphics

drawImage

public boolean drawImage(java.awt.Image image,
                         int i,
                         int j,
                         java.awt.Color color,
                         java.awt.image.ImageObserver imageobserver)
Specified by:
drawImage in class java.awt.Graphics

drawImage

public boolean drawImage(java.awt.Image image,
                         int i,
                         int j,
                         java.awt.image.ImageObserver imageobserver)
Specified by:
drawImage in class java.awt.Graphics

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Specified by:
drawLine in class java.awt.Graphics

drawLine

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

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
Specified by:
drawOval in class java.awt.Graphics

drawPolygon

public void drawPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Specified by:
drawPolygon in class java.awt.Graphics

drawPolyline

@NotImplemented
public void drawPolyline(int[] xPoints,
                                        int[] yPoints,
                                        int nPoints)
Specified by:
drawPolyline in class java.awt.Graphics

drawRect

@NotImplemented
public void drawRect(int x,
                                    int y,
                                    int width,
                                    int height)
Overrides:
drawRect in class java.awt.Graphics

drawRoundRect

@NotImplemented
public void drawRoundRect(int x,
                                         int y,
                                         int width,
                                         int height,
                                         int arcWidth,
                                         int arcHeight)
Specified by:
drawRoundRect in class java.awt.Graphics

drawString

public void drawString(java.lang.String str,
                       int x,
                       int y)
Specified by:
drawString in class java.awt.Graphics

drawString

public void drawString(java.text.AttributedCharacterIterator iterator,
                       int x,
                       int y)
Specified by:
drawString in class java.awt.Graphics

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Specified by:
fillArc in class java.awt.Graphics

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)
Specified by:
fillOval in class java.awt.Graphics

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 first nPoint - 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 class java.awt.Graphics
Parameters:
xPoints - array of the x coordinates.
yPoints - array of the y 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)
Specified by:
fillRect in class java.awt.Graphics

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Specified by:
fillRoundRect in class java.awt.Graphics

getClip

public java.awt.Shape getClip()
Specified by:
getClip in class java.awt.Graphics

getClipBounds

public java.awt.Rectangle getClipBounds()
Specified by:
getClipBounds in class java.awt.Graphics

getColor

public java.awt.Color getColor()
Specified by:
getColor in class java.awt.Graphics

getFont

public java.awt.Font getFont()
Specified by:
getFont in class java.awt.Graphics

getFontMetrics

public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
Specified by:
getFontMetrics in class java.awt.Graphics

setClip

public void setClip(int x,
                    int y,
                    int width,
                    int height)
Specified by:
setClip in class java.awt.Graphics

setClip

@NotImplemented
public void setClip(java.awt.Shape shape)
Specified by:
setClip in class java.awt.Graphics

setColor

public void setColor(java.awt.Color color)
Specified by:
setColor in class java.awt.Graphics

setFont

public void setFont(java.awt.Font f)
Specified by:
setFont in class java.awt.Graphics

setPaintMode

@NotImplemented
public void setPaintMode()
Specified by:
setPaintMode in class java.awt.Graphics

setXORMode

@NotImplemented
public void setXORMode(java.awt.Color color)
Specified by:
setXORMode in class java.awt.Graphics

translate

@NotImplemented
public void translate(int x,
                                     int y)
Specified by:
translate in class java.awt.Graphics

getBackground

public java.awt.Color getBackground()

setBackground

public void setBackground(java.awt.Color background)