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.WMFGraphics2D
com.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 TypeMethodDescriptionvoid
clearRect
(int x, int y, int width, int height) See Graphics.void
clipRect
(int x, int y, int width, int height) See Graphics.void
copyArea
(int x, int y, int width, int height, int dx, int dy) Not supported.create()
void
Creates and selects three GDI Objects: a Pen, a Brush and a Font with the current styles and fore- and background color.void
Deletes all created GDI objects.void
dispose()
See Graphics.void
drawArc
(int x, int y, int width, int height, int startAngle, int arcAngle) See Graphics.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.boolean
drawImage
(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) See Graphics.boolean
drawImage
(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) See Graphics.boolean
drawImage
(Image img, int x, int y, int width, int height, ImageObserver observer) See Graphics.boolean
drawImage
(Image img, int x, int y, Color bgcolor, ImageObserver observer) See Graphics.boolean
drawImage
(Image img, int x, int y, ImageObserver observer) See Graphics.void
drawLine
(int x1, int y1, int x2, int y2) See Graphics.void
drawOval
(int x, int y, int width, int height) See Graphics.void
drawPolygon
(int[] xPoints, int[] yPoints, int nPoints) See Graphics.void
drawPolyline
(int[] xPoints, int[] yPoints, int nPoints) See Graphics.void
drawRect
(int x, int y, int width, int height) See Graphics.void
drawRoundRect
(int x, int y, int width, int height, int arcWidth, int arcHeight) See Graphics.void
drawString
(String str, int x, int y) See Graphics.void
drawString
(AttributedCharacterIterator text, int x, int y) Not supported.void
fillArc
(int x, int y, int width, int height, int startAngle, int arcAngle) See Graphics.void
fillOval
(int x, int y, int width, int height) See Graphics.void
fillPolygon
(int[] xPoints, int[] yPoints, int nPoints) See Graphics.void
fillRect
(int x, int y, int width, int height) See Graphics.void
fillRoundRect
(int x, int y, int width, int height, int arcWidth, int arcHeight) See Graphics.void
GDIPolyPolygon
(Polygon[] polys) Executes the GDI polypolygon.int
Returns the current fill style of the brush, used to fill shapes.int
Returns 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.int
Returns the current escapement of the font, used to draw text.See Graphics.int
Returns the current style of the pen, used to draw lines.int
Returns the current width of the pen, used to draw lines.getWMF()
Returns the current WMF object.void
reset()
Resets WMFGraphics to its standard Java AWT behavior.void
Restores internal WMFGraphics settings in WMF which have been changed by copies (Graphics.create()) of this Graphics object.void
setBrushFillStyle
(int style) Sets the fill style of the brush, used to fill shapes.void
setBrushHatch
(int hatch) Sets the hatch style of the brush, used to fill shapes.void
setBrushPattern
(Image pattern) Sets the bitmap of the pattern brush, used to fill shapes.void
setClip
(int x, int y, int width, int height) See Graphicsvoid
See Graphicsvoid
See Graphics.void
See Graphics.void
setFontEscapement
(int escapement) Sets the escapement(rotation) of the font, used to draw text.int
Creates and selects a new fill brush with the current fill style, hatch style, pattern and foreground color.int
Creates and selects a new font with the current Font and escapement.int
Creates and selects a new hollow brush with the current foreground color.int
Creates and selects a new pen with the current pen style, width and foreground color.void
Not supported.void
setPenStyle
(int style) Sets the style of the pen, used to draw lines.void
setPenWidth
(int width) Sets the width of the pen, used to draw lines.void
Sets a new WMF object.void
setXORMode
(Color c1) Not supported.void
translate
(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 aWMF
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 intowidth
- The width of the metafile extentheight
- The height of the metafile extent- See Also:
-
WMFGraphics
Constructs a WMFGraphics object. Expects aWMF
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 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 to
WMF.BS_Solid<//code>, the brush hatch style to
WMF.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:
drawPolygon
in classGraphics
- See Also:
-
drawPolyline
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) See Graphics.- Specified by:
drawPolyline
in 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:
drawRoundRect
in classGraphics
- See Also:
-
drawString
See Graphics.- Specified by:
drawString
in classGraphics
- See Also:
-
drawString
Not supported.- Specified by:
drawString
in 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:
fillPolygon
in 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:
fillRoundRect
in classGraphics
- See Also:
-
clipRect
public void clipRect(int x, int y, int width, int height) See Graphics. -
getClip
See Graphics. -
getClipRect
See Graphics.- Overrides:
getClipRect
in classGraphics
- See Also:
-
getClipBounds
See Graphics.- Specified by:
getClipBounds
in 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:
getFontMetrics
in classGraphics
- See Also:
-
setColor
See Graphics. -
setFont
See Graphics. -
setPaintMode
public void setPaintMode()Not supported.- Specified by:
setPaintMode
in classGraphics
- See Also:
-
setXORMode
Not supported.- Specified by:
setXORMode
in classGraphics
- See Also:
-
translate
public void translate(int x, int y) See Graphics.
-