Package rma.util.wmf
Class WMFGraphics
java.lang.Object
java.awt.Graphics
rma.util.wmf.WMFGraphics
A class for writing into Windows Metafiles with standard
java.awt.Graphics methods. Additional methods for using GDI specialities
like different line and fill styles and rotated fonts are provided.
Usage is simple. Construct a WMFGraphics object with a WMF object
WMFGraphics is compatible with JDK 1.0, JDK 1.1 and JDK 1.2
Usage is simple. Construct a WMFGraphics 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);
...
You can even use GDI specialities:
...
wmfg.setPenStyle(WMF.PS_DOT);
wmfg.setPenWidth(5);
wmfg.drawLine(400, 0, 0, 300);
wmfg.setBrushFillStyle(WMF.BS_HATCHED);
wmfg.setBrushHatch(WMF.HS_CROSS);
wmfg.fillOval(150, 100, 100, 100);
wmfg.reset(); //set back to standard AWT settings
...
Finish your drawings with the delete of the GDI objects used by the
WMFGraphics objects:
wmfg.deleteGDIObjects()This is not really necessary because the WMF object deletes them automatically but clean style.
WMFGraphics is compatible with JDK 1.0, JDK 1.1 and JDK 1.2
- See Also:
-
com.pietjonas.wmfwriter2d.WMFGraphics2Dcom.pietjonas.wmfwriter2d.WMF
-
Constructor Summary
ConstructorsConstructorDescriptionWMFGraphics(WMF wmf, int width, int height) Constructs a WMFGraphics object.WMFGraphics(WMF wmf, int width, int height, Color foreground, Color background) Constructs a WMFGraphics object. -
Method Summary
Modifier and TypeMethodDescriptionvoidclearRect(int x, int y, int width, int height) See Graphics.voidclipRect(int x, int y, int width, int height) See Graphics.voidcopyArea(int x, int y, int width, int height, int dx, int dy) Not supported.create()voidCreates and selects three GDI Objects: a Pen, a Brush and a Font with the current styles and fore- and background color.voidDeletes all created GDI objects.voiddispose()See Graphics.voiddrawArc(int x, int y, int width, int height, int startAngle, int arcAngle) See Graphics.booleandrawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) See Graphics.booleandrawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) See Graphics.booleandrawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) See Graphics.booleandrawImage(Image img, int x, int y, int width, int height, ImageObserver observer) See Graphics.booleandrawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) See Graphics.booleandrawImage(Image img, int x, int y, ImageObserver observer) See Graphics.voiddrawLine(int x1, int y1, int x2, int y2) See Graphics.voiddrawOval(int x, int y, int width, int height) See Graphics.voiddrawPolygon(int[] xPoints, int[] yPoints, int nPoints) See Graphics.voiddrawPolyline(int[] xPoints, int[] yPoints, int nPoints) See Graphics.voiddrawRect(int x, int y, int width, int height) See Graphics.voiddrawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) See Graphics.voiddrawString(String str, int x, int y) See Graphics.voiddrawString(AttributedCharacterIterator text, int x, int y) Not supported.voidfillArc(int x, int y, int width, int height, int startAngle, int arcAngle) See Graphics.voidfillOval(int x, int y, int width, int height) See Graphics.voidfillPolygon(int[] xPoints, int[] yPoints, int nPoints) See Graphics.voidfillRect(int x, int y, int width, int height) See Graphics.voidfillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) See Graphics.voidGDIPolyPolygon(Polygon[] polys) Executes the GDI polypolygon.intReturns the current fill style of the brush, used to fill shapes.intReturns the current hatch style of the brush, used to fill shapes.Returns the bitmap of the pattern brush, used to fill shapes.getClip()See Graphics.See Graphics.See Graphics.getColor()See Graphics.getFont()See Graphics.intReturns the current escapement of the font, used to draw text.See Graphics.intReturns the current style of the pen, used to draw lines.intReturns the current width of the pen, used to draw lines.getWMF()Returns the current WMF object.voidreset()Resets WMFGraphics to its standard Java AWT behavior.voidRestores internal WMFGraphics settings in WMF which have been changed by copies (Graphics.create()) of this Graphics object.voidsetBrushFillStyle(int style) Sets the fill style of the brush, used to fill shapes.voidsetBrushHatch(int hatch) Sets the hatch style of the brush, used to fill shapes.voidsetBrushPattern(Image pattern) Sets the bitmap of the pattern brush, used to fill shapes.voidsetClip(int x, int y, int width, int height) See GraphicsvoidSee GraphicsvoidSee Graphics.voidSee Graphics.voidsetFontEscapement(int escapement) Sets the escapement(rotation) of the font, used to draw text.intCreates and selects a new fill brush with the current fill style, hatch style, pattern and foreground color.intCreates and selects a new font with the current Font and escapement.intCreates and selects a new hollow brush with the current foreground color.intCreates and selects a new pen with the current pen style, width and foreground color.voidNot supported.voidsetPenStyle(int style) Sets the style of the pen, used to draw lines.voidsetPenWidth(int width) Sets the width of the pen, used to draw lines.voidSets a new WMF object.voidsetXORMode(Color c1) Not supported.voidtranslate(int x, int y) See Graphics.Methods inherited from class java.awt.Graphics
create, draw3DRect, drawBytes, drawChars, drawPolygon, fill3DRect, fillPolygon, finalize, getClipBounds, getFontMetrics, hitClip, toString
-
Constructor Details
-
WMFGraphics
Constructs a WMFGraphics object. Expects aWMFobject 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 intowidth- The width of the metafile extentheight- The height of the metafile extent- See Also:
-
WMFGraphics
Constructs a WMFGraphics object. Expects aWMFobject 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 intowidth- The width of the metafile extentheight- The height of the metafile extentforeground- The foreground colorbackground- The background color- See Also:
-
-
Method Details
-
reset
public void reset()Resets WMFGraphics to its standard Java AWT behavior. The pen style is set back toWMF.PS_Solid<//code>, its width is set to 1 (one pixel wide lines). The brush fill style is set toWMF.BS_Solid<//code>, the brush hatch style toWMF.HS_Horizontal<//code>. The font escapement is set to 0.- See Also:
-
restoreState
public void restoreState()Restores internal WMFGraphics settings in WMF which have been changed by copies (Graphics.create()) of this Graphics object. -
setPenStyle
public void setPenStyle(int style) Sets the style of the pen, used to draw lines.- Parameters:
style- One of the WMF.PS_XXX constants.- See Also:
-
getPenStyle
public int getPenStyle()Returns the current style of the pen, used to draw lines.- Returns:
- The current style.
- See Also:
-
setPenWidth
public void setPenWidth(int width) Sets the width of the pen, used to draw lines.- Parameters:
width- The new pen width (0 means always 1 pixel wide).- See Also:
-
getPenWidth
public int getPenWidth()Returns the current width of the pen, used to draw lines.- Returns:
- The current width.
- See Also:
-
setBrushFillStyle
public void setBrushFillStyle(int style) Sets the fill style of the brush, used to fill shapes.- Parameters:
style- One of the WMF.BS_XXX constants.- See Also:
-
getBrushFillStyle
public int getBrushFillStyle()Returns the current fill style of the brush, used to fill shapes.- Returns:
- The current fill style.
- See Also:
-
setBrushHatch
public void setBrushHatch(int hatch) Sets the hatch style of the brush, used to fill shapes.- Parameters:
style- One of the WMF.HS_XXX constants.- See Also:
-
getBrushHatch
public int getBrushHatch()Returns the current hatch style of the brush, used to fill shapes.- Returns:
- The current hatch style.
- See Also:
-
setBrushPattern
Sets the bitmap of the pattern brush, used to fill shapes. There is no support for transparency.- Parameters:
Image- The bitmap of the pattern. Must have at least 8x8 pixels.- See Also:
-
getBrushPattern
Returns the bitmap of the pattern brush, used to fill shapes.- Returns:
- The current bitmap.
- See Also:
-
setFontEscapement
public void setFontEscapement(int escapement) Sets the escapement(rotation) of the font, used to draw text.- Parameters:
width- The new escapement (in tenth of degrees).- See Also:
-
getFontEscapement
public int getFontEscapement()Returns the current escapement of the font, used to draw text.- Returns:
- The current escapement.
- See Also:
-
createWMFHandles
public void createWMFHandles()Creates and selects three GDI Objects: a Pen, a Brush and a Font with the current styles and fore- and background color.- See Also:
-
setWMF
Sets a new WMF object. It creates and selects three GDI Objects: a Pen, a Brush and a Font with the current styles and fore- and background color. Sets the standard evironment in the metafile. -
getWMF
Returns the current WMF object.- Returns:
- The current WMF object.
- See Also:
-
setGDIPen
public int setGDIPen()Creates and selects a new pen with the current pen style, width and foreground color. Deletes the old pen.- Returns:
- The GDI handle of the pen.
- See Also:
-
setGDIHollowBrush
public int setGDIHollowBrush()Creates and selects a new hollow brush with the current foreground color. Deletes the old brush.- Returns:
- The GDI handle of the brush.
- See Also:
-
setGDIFillBrush
public int setGDIFillBrush()Creates and selects a new fill brush with the current fill style, hatch style, pattern and foreground color. Deletes the old brush.- Returns:
- The GDI handle of the brush.
- See Also:
-
setGDIFont
public int setGDIFont()Creates and selects a new font with the current Font and escapement. Deletes the old font.- Returns:
- The GDI handle of the font.
- See Also:
-
deleteGDIObjects
public void deleteGDIObjects()Deletes all created GDI objects. Should be the final method call before writing the metafile to an OutputStream. -
GDIPolyPolygon
Executes the GDI polypolygon.- Parameters:
polys- Array of java.awt.Polygon- See Also:
-
clearRect
public void clearRect(int x, int y, int width, int height) See Graphics. -
copyArea
public void copyArea(int x, int y, int width, int height, int dx, int dy) Not supported. -
create
-
dispose
public void dispose()See Graphics. -
drawArc
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) See Graphics. -
drawImage
See Graphics. -
drawImage
See Graphics. -
drawImage
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) See Graphics. -
drawImage
See Graphics. -
drawImage
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) See Graphics. -
drawImage
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) See Graphics. -
drawLine
public void drawLine(int x1, int y1, int x2, int y2) See Graphics. -
drawOval
public void drawOval(int x, int y, int width, int height) See Graphics. -
drawPolygon
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) See Graphics.- Specified by:
drawPolygonin classGraphics- See Also:
-
drawPolyline
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) See Graphics.- Specified by:
drawPolylinein classGraphics- See Also:
-
drawRect
public void drawRect(int x, int y, int width, int height) See Graphics. -
drawRoundRect
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) See Graphics.- Specified by:
drawRoundRectin classGraphics- See Also:
-
drawString
See Graphics.- Specified by:
drawStringin classGraphics- See Also:
-
drawString
Not supported.- Specified by:
drawStringin classGraphics- See Also:
-
fillArc
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) See Graphics. -
fillOval
public void fillOval(int x, int y, int width, int height) See Graphics. -
fillPolygon
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) See Graphics.- Specified by:
fillPolygonin classGraphics- See Also:
-
fillRect
public void fillRect(int x, int y, int width, int height) See Graphics. -
fillRoundRect
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) See Graphics.- Specified by:
fillRoundRectin classGraphics- See Also:
-
clipRect
public void clipRect(int x, int y, int width, int height) See Graphics. -
getClip
See Graphics. -
getClipRect
See Graphics.- Overrides:
getClipRectin classGraphics- See Also:
-
getClipBounds
See Graphics.- Specified by:
getClipBoundsin classGraphics- See Also:
-
setClip
public void setClip(int x, int y, int width, int height) See Graphics -
setClip
See Graphics -
getColor
See Graphics. -
getFont
See Graphics. -
getFontMetrics
See Graphics.- Specified by:
getFontMetricsin classGraphics- See Also:
-
setColor
See Graphics. -
setFont
See Graphics. -
setPaintMode
public void setPaintMode()Not supported.- Specified by:
setPaintModein classGraphics- See Also:
-
setXORMode
Not supported.- Specified by:
setXORModein classGraphics- See Also:
-
translate
public void translate(int x, int y) See Graphics.
-