Package rma.util.wmf

Class WMFGraphics

java.lang.Object
java.awt.Graphics
rma.util.wmf.WMFGraphics

public class WMFGraphics extends Graphics
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 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 Details

    • WMFGraphics

      public WMFGraphics(WMF wmf, int width, int height)
      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 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:
    • WMFGraphics

      public WMFGraphics(WMF wmf, int width, int height, Color foreground, 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:
  • Method Details

    • reset

      public void reset()
      Resets WMFGraphics to its standard Java AWT behavior. The pen style is set back to WMF.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

      public void setBrushPattern(Image pattern)
      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

      public Image 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

      public void setWMF(WMF newwmf, int width, int height)
      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.
      Parameters:
      newwmf - The new WMF object.
      See Also:
    • getWMF

      public WMF 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

      public void GDIPolyPolygon(Polygon[] polys)
      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.
      Specified by:
      clearRect in class Graphics
      See Also:
    • copyArea

      public void copyArea(int x, int y, int width, int height, int dx, int dy)
      Not supported.
      Specified by:
      copyArea in class Graphics
      See Also:
    • create

      public Graphics create()
      Specified by:
      create in class Graphics
      See Also:
    • dispose

      public void dispose()
      See Graphics.
      Specified by:
      dispose in class Graphics
      See Also:
    • drawArc

      public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
      See Graphics.
      Specified by:
      drawArc in class Graphics
      See Also:
    • drawImage

      public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
      See Graphics.
      Specified by:
      drawImage in class Graphics
      See Also:
    • drawImage

      public boolean drawImage(Image img, int x, int y, ImageObserver observer)
      See Graphics.
      Specified by:
      drawImage in class Graphics
      See Also:
    • drawImage

      public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
      See Graphics.
      Specified by:
      drawImage in class Graphics
      See Also:
    • drawImage

      public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
      See Graphics.
      Specified by:
      drawImage in class Graphics
      See Also:
    • 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.
      Specified by:
      drawImage in class Graphics
      See Also:
    • 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.
      Specified by:
      drawImage in class Graphics
      See Also:
    • drawLine

      public void drawLine(int x1, int y1, int x2, int y2)
      See Graphics.
      Specified by:
      drawLine in class Graphics
      See Also:
    • drawOval

      public void drawOval(int x, int y, int width, int height)
      See Graphics.
      Specified by:
      drawOval in class Graphics
      See Also:
    • drawPolygon

      public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
      See Graphics.
      Specified by:
      drawPolygon in class Graphics
      See Also:
    • drawPolyline

      public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
      See Graphics.
      Specified by:
      drawPolyline in class Graphics
      See Also:
    • drawRect

      public void drawRect(int x, int y, int width, int height)
      See Graphics.
      Overrides:
      drawRect in class Graphics
      See Also:
    • drawRoundRect

      public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
      See Graphics.
      Specified by:
      drawRoundRect in class Graphics
      See Also:
    • drawString

      public void drawString(String str, int x, int y)
      See Graphics.
      Specified by:
      drawString in class Graphics
      See Also:
    • drawString

      public void drawString(AttributedCharacterIterator text, int x, int y)
      Not supported.
      Specified by:
      drawString in class Graphics
      See Also:
    • fillArc

      public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
      See Graphics.
      Specified by:
      fillArc in class Graphics
      See Also:
    • fillOval

      public void fillOval(int x, int y, int width, int height)
      See Graphics.
      Specified by:
      fillOval in class Graphics
      See Also:
    • fillPolygon

      public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
      See Graphics.
      Specified by:
      fillPolygon in class Graphics
      See Also:
    • fillRect

      public void fillRect(int x, int y, int width, int height)
      See Graphics.
      Specified by:
      fillRect in class Graphics
      See Also:
    • fillRoundRect

      public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
      See Graphics.
      Specified by:
      fillRoundRect in class Graphics
      See Also:
    • clipRect

      public void clipRect(int x, int y, int width, int height)
      See Graphics.
      Specified by:
      clipRect in class Graphics
      See Also:
    • getClip

      public Shape getClip()
      See Graphics.
      Specified by:
      getClip in class Graphics
      See Also:
    • getClipRect

      public Rectangle getClipRect()
      See Graphics.
      Overrides:
      getClipRect in class Graphics
      See Also:
    • getClipBounds

      public Rectangle getClipBounds()
      See Graphics.
      Specified by:
      getClipBounds in class Graphics
      See Also:
    • setClip

      public void setClip(int x, int y, int width, int height)
      See Graphics
      Specified by:
      setClip in class Graphics
      See Also:
    • setClip

      public void setClip(Shape clipshape)
      See Graphics
      Specified by:
      setClip in class Graphics
      See Also:
    • getColor

      public Color getColor()
      See Graphics.
      Specified by:
      getColor in class Graphics
      See Also:
    • getFont

      public Font getFont()
      See Graphics.
      Specified by:
      getFont in class Graphics
      See Also:
    • getFontMetrics

      public FontMetrics getFontMetrics(Font f)
      See Graphics.
      Specified by:
      getFontMetrics in class Graphics
      See Also:
    • setColor

      public void setColor(Color newcolor)
      See Graphics.
      Specified by:
      setColor in class Graphics
      See Also:
    • setFont

      public void setFont(Font newfont)
      See Graphics.
      Specified by:
      setFont in class Graphics
      See Also:
    • setPaintMode

      public void setPaintMode()
      Not supported.
      Specified by:
      setPaintMode in class Graphics
      See Also:
    • setXORMode

      public void setXORMode(Color c1)
      Not supported.
      Specified by:
      setXORMode in class Graphics
      See Also:
    • translate

      public void translate(int x, int y)
      See Graphics.
      Specified by:
      translate in class Graphics
      See Also: