com.pietjonas.wmfwriter2d
Class WMFGraphics2D

java.lang.Object
  extended byjava.awt.Graphics
      extended byjava.awt.Graphics2D
          extended bycom.pietjonas.wmfwriter2d.WMFGraphics2D

public class WMFGraphics2D
extends java.awt.Graphics2D

A class for writing into Windows Metafiles with java.awt.Graphics2D methods.
Usage is simple. Construct a WMFGraphics2D object with a WMF object wmf and the metafile extent:

     WMFGraphics wmfg = new WMFGraphics(wmf, 400, 300); 
Use the standard java.awt.Graphics methods to draw:
     ...
   wmfg.drawLine(0, 0, 400, 300);
   wmfg.drawOval(100, 100, 200, 100);
   ...
   
Almost all features of the Java2D are supported. WMFGraphics2D is compatible with JDK 1.2 and above

Version:
2.0
Author:
Dr. Piet Jonas (piet@jonas.com)
See Also:
WMFGraphics, WMF

Constructor Summary
WMFGraphics2D(WMF wmf, int width, int height)
          Constructs a WMFGraphics2D object.
WMFGraphics2D(WMF wmf, int width, int height, java.awt.Color foreground, java.awt.Color background)
          Constructs a WMFGraphics object.
 
Method Summary
 void addRenderingHints(java.util.Map hints)
          See Graphics2D.
 void clearRect(int x, int y, int width, int height)
          See Graphics2D.
 void clip(java.awt.Shape s)
          See Graphics2D.
 void clipRect(int x, int y, int width, int height)
          See Graphics2D.
 void copyArea(int x, int y, int width, int height, int dx, int dy)
          See Graphics2D.
 java.awt.Graphics create()
          See Graphics2D.
 void dispose()
          See Graphics2D.
 void draw(java.awt.Shape s)
          See Graphics2D.
 void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          See Graphics2D.
 void drawGlyphVector(java.awt.font.GlyphVector g, float x, float y)
          See Graphics2D.
 void drawImage(java.awt.image.BufferedImage img, java.awt.image.BufferedImageOp op, int x, int y)
          See Graphics2D.
 boolean drawImage(java.awt.Image img, java.awt.geom.AffineTransform xform, java.awt.image.ImageObserver obs)
          See Graphics2D.
 boolean drawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
          See Graphics2D.
 boolean drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
          See Graphics2D.
 boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
          See Graphics2D.
 boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)
          See Graphics2D.
 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)
          See Graphics2D.
 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)
          See Graphics2D.
 void drawLine(int x1, int y1, int x2, int y2)
          See Graphics2D.
 void drawOval(int x, int y, int width, int height)
          See Graphics2D.
 void drawPolygon(int[] xpoints, int[] ypoints, int npoints)
          See Graphics2D.
 void drawPolyline(int[] xpoints, int[] ypoints, int npoints)
          See Graphics2D.
 void drawRect(int x, int y, int width, int height)
          See Graphics2D.
 void drawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)
          See Graphics2D.
 void drawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)
          See Graphics2D.
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          See Graphics2D.
 void drawString(java.text.AttributedCharacterIterator iterator, float x, float y)
          See Graphics2D.
 void drawString(java.text.AttributedCharacterIterator iterator, int x, int y)
          See Graphics2D.
 void drawString(java.lang.String s, float x, float y)
          See Graphics2D.
 void drawString(java.lang.String str, int x, int y)
          See Graphics2D.
 void fill(java.awt.Shape s)
          See Graphics2D.
 void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          See Graphics2D.
 void fillOval(int x, int y, int width, int height)
          See Graphics2D.
 void fillPolygon(int[] xpoints, int[] ypoints, int npoints)
          See Graphics2D.
 void fillRect(int x, int y, int width, int height)
          See Graphics2D.
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          See Graphics2D.
 java.awt.Color getBackground()
          See Graphics2D.
 java.awt.Shape getClip()
          See Graphics2D.
 java.awt.Rectangle getClipBounds()
          See Graphics2D.
 java.awt.Color getColor()
          See Graphics2D.
 java.awt.Composite getComposite()
          See Graphics2D.
 java.awt.GraphicsConfiguration getDeviceConfiguration()
          See Graphics2D.
 double getFlatness()
           
 java.awt.Font getFont()
          See Graphics2D.
 java.awt.FontMetrics getFontMetrics(java.awt.Font f)
          See Graphics2D.
 java.awt.font.FontRenderContext getFontRenderContext()
          See Graphics2D.
 java.awt.Paint getPaint()
          See Graphics2D.
 java.lang.Object getRenderingHint(java.awt.RenderingHints.Key key)
          See Graphics2D.
 java.awt.RenderingHints getRenderingHints()
          See Graphics2D.
 java.awt.Stroke getStroke()
          See Graphics2D.
 java.awt.geom.AffineTransform getTransform()
          See Graphics2D.
 boolean hit(java.awt.Rectangle rect, java.awt.Shape s, boolean onStroke)
          See Graphics2D.
 boolean isGDIFontDrawing()
          Indicates the use of the native GDI font drawing mechanism.
 boolean isGDIPenDrawing()
          Indicates the use of the native GDI pen drawing mechanism.
 boolean isGDIPenWidthDrawing()
          Indicates the use of the native GDI pen width drawing.
 void rotate(double theta)
          See Graphics2D.
 void rotate(double theta, double x, double y)
          See Graphics2D.
 void scale(double sx, double sy)
          See Graphics2D.
 void setBackground(java.awt.Color color)
          See Graphics2D.
 void setClip(int x, int y, int width, int height)
          See Graphics2D.
 void setClip(java.awt.Shape clip)
          See Graphics2D.
 void setColor(java.awt.Color c)
          See Graphics2D.
 void setComposite(java.awt.Composite comp)
          See Graphics2D.
 void setFlatness(double flatness)
          Sets the number of polygons produced for drawing curved shapes.
 void setFont(java.awt.Font font)
          See Graphics2D.
 void setGDIFontDrawing(boolean gdifontdrawing)
          Sets the use of the native GDI font drawing mechanism.
 void setGDIPenDrawing(boolean gdipendrawing)
          Sets the use of the native GDI pen drawing mechanism for java.awt.Shape outlines.
 void setGDIPenWidthDrawing(boolean gdipenwidthdrawing)
          Sets the use of width for the native GDI pen drawing (isGDIPenDrawing() must be true).
 void setPaint(java.awt.Paint paint)
          See Graphics2D.
 void setPaintMode()
          See Graphics2D.
 void setRenderingHint(java.awt.RenderingHints.Key key, java.lang.Object hintValue)
          See Graphics2D.
 void setRenderingHints(java.util.Map hints)
          See Graphics2D.
 void setStroke(java.awt.Stroke s)
          See Graphics2D.
 void setTransform(java.awt.geom.AffineTransform Tx)
          See Graphics2D.
 void setXORMode(java.awt.Color color)
          See Graphics2D.
 void shear(double shx, double shy)
          See Graphics2D.
 void transform(java.awt.geom.AffineTransform Tx)
          See Graphics2D.
 void translate(double tx, double ty)
          See Graphics2D.
 void translate(int x, int y)
          See Graphics2D.
 
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
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WMFGraphics2D

public WMFGraphics2D(WMF wmf,
                     int width,
                     int height)
Constructs a WMFGraphics2D object. Expects a WMF object in which the Windows metafile commands are written and the extent the metafile will have.
It writes some GDI commands to the Windows Metafile to setup a standard environment (setWindowOrg, setWindowExt, setBKMode, ...) It creates and selects three GDI Objects: a Pen, a Brush and a Font with black fore- and white background color.

Parameters:
wmf - The WMF object to write the metafile into
width - The width of the metafile extent
height - The height of the metafile extent
See Also:
WMF

WMFGraphics2D

public WMFGraphics2D(WMF wmf,
                     int width,
                     int height,
                     java.awt.Color foreground,
                     java.awt.Color background)
Constructs a WMFGraphics object. Expects a WMF object in which the Windows metafile commands are written and the extent the metafile will have.
It writes some GDI commands to the Windows Metafile to setup a standard environment (setWindowOrg, setWindowExt, setBKMode, ...) It creates and selects three GDI Objects: a Pen, a Brush and a Font with the specified fore- and background color.

Parameters:
wmf - The WMF object to write the metafile into
width - The width of the metafile extent
height - The height of the metafile extent
foreground - The foreground color
background - The background color
See Also:
WMF
Method Detail

setGDIFontDrawing

public void setGDIFontDrawing(boolean gdifontdrawing)
Sets the use of the native GDI font drawing mechanism. GDI fonts are used if the current transformation is identity, the current java.awt.Paint is instance of java.awt.Color, the font transformation is identity, there is no clip. GDI fonts lead to smaller WMF, faster replay and better font quality but can produce slightly different appearence.

Parameters:
gdifontdrawing - Whether to use GDI fonts

isGDIFontDrawing

public boolean isGDIFontDrawing()
Indicates the use of the native GDI font drawing mechanism.

Returns:
True if the GDI mechanism is used

setGDIPenDrawing

public void setGDIPenDrawing(boolean gdipendrawing)
Sets the use of the native GDI pen drawing mechanism for java.awt.Shape outlines. GDI pens are used if the current java.awt.Stroke is instance of java.awt.BasicStroke with no or empty dash array, the current java.awt.Paint is instance of java.awt.Color. GDI pens lead to smaller WMF, faster replay and better drawing quality but can produce slightly different appearence (joins, end caps).

Parameters:
gdipendrawing - Whether to use GDI pens
See Also:
setGDIPenWidthDrawing(boolean)

isGDIPenDrawing

public boolean isGDIPenDrawing()
Indicates the use of the native GDI pen drawing mechanism.

Returns:
True if the GDI mechanism is used

setGDIPenWidthDrawing

public void setGDIPenWidthDrawing(boolean gdipenwidthdrawing)
Sets the use of width for the native GDI pen drawing (isGDIPenDrawing() must be true). GDI pens are used with the width indicated by the current java.awt.BasicStroke instance. If set to false, a GDI pen with width 0 is used plus line filling by the java.awt.Stroke object. GDI pens with native width lead to smaller WMF, faster replay and better drawing quality but can produce slightly different appearence (joins, end caps).

Parameters:
gdipenwidthdrawing - Whether to use GDI pen width
See Also:
setGDIPenDrawing(boolean)

isGDIPenWidthDrawing

public boolean isGDIPenWidthDrawing()
Indicates the use of the native GDI pen width drawing.

Returns:
True if the GDI pen width is used

setFlatness

public void setFlatness(double flatness)
Sets the number of polygons produced for drawing curved shapes. A smaller flatness parameter means a higher number of polygons which leads to better drawing quality but bigger WMF. See java.awt.Shape.getPathIterator(java.awt.geom.AffineTransform, double flatness)

Parameters:
flatness - The flatness parameter

getFlatness

public double getFlatness()
Returns:
The current flatness parameter

getRenderingHints

public java.awt.RenderingHints getRenderingHints()
See Graphics2D.

See Also:
Graphics2D

create

public java.awt.Graphics create()
See Graphics2D.

See Also:
Graphics2D

getFont

public java.awt.Font getFont()
See Graphics2D.

See Also:
Graphics2D

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
See Graphics2D.

See Also:
Graphics2D

clip

public void clip(java.awt.Shape s)
See Graphics2D.

See Also:
Graphics2D

setPaintMode

public void setPaintMode()
See Graphics2D.

See Also:
Graphics2D

hit

public boolean hit(java.awt.Rectangle rect,
                   java.awt.Shape s,
                   boolean onStroke)
See Graphics2D.

See Also:
Graphics2D

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         java.awt.Color bgcolor,
                         java.awt.image.ImageObserver observer)
See Graphics2D.

See Also:
Graphics2D

getFontRenderContext

public java.awt.font.FontRenderContext getFontRenderContext()
See Graphics2D.

See Also:
Graphics2D

getDeviceConfiguration

public java.awt.GraphicsConfiguration getDeviceConfiguration()
See Graphics2D.

See Also:
Graphics2D

getColor

public java.awt.Color getColor()
See Graphics2D.

See Also:
Graphics2D

getComposite

public java.awt.Composite getComposite()
See Graphics2D.

See Also:
Graphics2D

getPaint

public java.awt.Paint getPaint()
See Graphics2D.

See Also:
Graphics2D

drawRenderedImage

public void drawRenderedImage(java.awt.image.RenderedImage img,
                              java.awt.geom.AffineTransform xform)
See Graphics2D.

See Also:
Graphics2D

setClip

public void setClip(java.awt.Shape clip)
See Graphics2D.

See Also:
Graphics2D

setTransform

public void setTransform(java.awt.geom.AffineTransform Tx)
See Graphics2D.

See Also:
Graphics2D

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
See Graphics2D.

See Also:
Graphics2D

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
See Graphics2D.

See Also:
Graphics2D

setBackground

public void setBackground(java.awt.Color color)
See Graphics2D.

See Also:
Graphics2D

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
See Graphics2D.

See Also:
Graphics2D

getStroke

public java.awt.Stroke getStroke()
See Graphics2D.

See Also:
Graphics2D

fillPolygon

public void fillPolygon(int[] xpoints,
                        int[] ypoints,
                        int npoints)
See Graphics2D.

See Also:
Graphics2D

setRenderingHint

public void setRenderingHint(java.awt.RenderingHints.Key key,
                             java.lang.Object hintValue)
See Graphics2D.

See Also:
Graphics2D

clipRect

public void clipRect(int x,
                     int y,
                     int width,
                     int height)
See Graphics2D.

See Also:
Graphics2D

drawImage

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)
See Graphics2D.

See Also:
Graphics2D

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
See Graphics2D.

See Also:
Graphics2D

setFont

public void setFont(java.awt.Font font)
See Graphics2D.

See Also:
Graphics2D

setPaint

public void setPaint(java.awt.Paint paint)
See Graphics2D.

See Also:
Graphics2D

copyArea

public void copyArea(int x,
                     int y,
                     int width,
                     int height,
                     int dx,
                     int dy)
See Graphics2D.

See Also:
Graphics2D

setStroke

public void setStroke(java.awt.Stroke s)
See Graphics2D.

See Also:
Graphics2D

drawPolygon

public void drawPolygon(int[] xpoints,
                        int[] ypoints,
                        int npoints)
See Graphics2D.

See Also:
Graphics2D

drawString

public void drawString(java.text.AttributedCharacterIterator iterator,
                       int x,
                       int y)
See Graphics2D.

See Also:
Graphics2D

drawPolyline

public void drawPolyline(int[] xpoints,
                         int[] ypoints,
                         int npoints)
See Graphics2D.

See Also:
Graphics2D

drawString

public void drawString(java.lang.String str,
                       int x,
                       int y)
See Graphics2D.

See Also:
Graphics2D

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
See Graphics2D.

See Also:
Graphics2D

drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height)
See Graphics2D.

See Also:
Graphics2D

dispose

public void dispose()
See Graphics2D.

See Also:
Graphics2D

setClip

public void setClip(int x,
                    int y,
                    int width,
                    int height)
See Graphics2D.

See Also:
Graphics2D

drawRenderableImage

public void drawRenderableImage(java.awt.image.renderable.RenderableImage img,
                                java.awt.geom.AffineTransform xform)
See Graphics2D.

See Also:
Graphics2D

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         java.awt.Color bgcolor,
                         java.awt.image.ImageObserver observer)
See Graphics2D.

See Also:
Graphics2D

rotate

public void rotate(double theta,
                   double x,
                   double y)
See Graphics2D.

See Also:
Graphics2D

transform

public void transform(java.awt.geom.AffineTransform Tx)
See Graphics2D.

See Also:
Graphics2D

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
See Graphics2D.

See Also:
Graphics2D

setColor

public void setColor(java.awt.Color c)
See Graphics2D.

See Also:
Graphics2D

getRenderingHint

public java.lang.Object getRenderingHint(java.awt.RenderingHints.Key key)
See Graphics2D.

See Also:
Graphics2D

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         java.awt.image.ImageObserver observer)
See Graphics2D.

See Also:
Graphics2D

setRenderingHints

public void setRenderingHints(java.util.Map hints)
See Graphics2D.

See Also:
Graphics2D

translate

public void translate(int x,
                      int y)
See Graphics2D.

See Also:
Graphics2D

setXORMode

public void setXORMode(java.awt.Color color)
See Graphics2D.

See Also:
Graphics2D

getClipBounds

public java.awt.Rectangle getClipBounds()
See Graphics2D.

See Also:
Graphics2D

drawString

public void drawString(java.text.AttributedCharacterIterator iterator,
                       float x,
                       float y)
See Graphics2D.

See Also:
Graphics2D

addRenderingHints

public void addRenderingHints(java.util.Map hints)
See Graphics2D.

See Also:
Graphics2D

getBackground

public java.awt.Color getBackground()
See Graphics2D.

See Also:
Graphics2D

translate

public void translate(double tx,
                      double ty)
See Graphics2D.

See Also:
Graphics2D

fill

public void fill(java.awt.Shape s)
See Graphics2D.

See Also:
Graphics2D

getClip

public java.awt.Shape getClip()
See Graphics2D.

See Also:
Graphics2D

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         java.awt.image.ImageObserver observer)
See Graphics2D.

See Also:
Graphics2D

drawGlyphVector

public void drawGlyphVector(java.awt.font.GlyphVector g,
                            float x,
                            float y)
See Graphics2D.

See Also:
Graphics2D

setComposite

public void setComposite(java.awt.Composite comp)
See Graphics2D.

See Also:
Graphics2D

scale

public void scale(double sx,
                  double sy)
See Graphics2D.

See Also:
Graphics2D

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)
See Graphics2D.

See Also:
Graphics2D

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)
See Graphics2D.

See Also:
Graphics2D

getFontMetrics

public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
See Graphics2D.

See Also:
Graphics2D

drawImage

public boolean drawImage(java.awt.Image img,
                         java.awt.geom.AffineTransform xform,
                         java.awt.image.ImageObserver obs)
See Graphics2D.

See Also:
Graphics2D

rotate

public void rotate(double theta)
See Graphics2D.

See Also:
Graphics2D

draw

public void draw(java.awt.Shape s)
See Graphics2D.

See Also:
Graphics2D

drawString

public void drawString(java.lang.String s,
                       float x,
                       float y)
See Graphics2D.

See Also:
Graphics2D

drawImage

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)
See Graphics2D.

See Also:
Graphics2D

getTransform

public java.awt.geom.AffineTransform getTransform()
See Graphics2D.

See Also:
Graphics2D

drawImage

public void drawImage(java.awt.image.BufferedImage img,
                      java.awt.image.BufferedImageOp op,
                      int x,
                      int y)
See Graphics2D.

See Also:
Graphics2D

shear

public void shear(double shx,
                  double shy)
See Graphics2D.

See Also:
Graphics2D