Package rma.util.wmf

Class WMF

java.lang.Object
rma.util.wmf.WMF

public class WMF extends Object
A class for writing Windows metafiles. It encapsulats many Windows GDI commands useful in Windows metafiles. To create a Windows metafile you have to construct a WMF object:
     WMF wmf = new WMF(); 
and call the appropriate GDI commands:
     wmf.moveTo(0, 0);
     wmf.lineTo(10, 24);
     wmf.rectangle(10, 24, 100, 130);
     ...
     
or use a WMFGraphics object:
     WMFGraphics wmfg = new WMFGraphics(wmf, 400, 300);
     wmfg.drawLine(10, 10, 45, 34);
     wmfg.drawRect(0, 0, 400, 300);
     ...
     wmfg.deleteGDIObjects(); //not necessary but clean style
     
To write a standard Windows metafile to an OutputStream out use:
     wmf.writePlaceableWMF(out, 0, 0, 300, 200) 
which creates a metafile compatible with almost all Windows programs.
In Windows metafiles GDI Objects like Pens, Brushes and Fonts are stored in a handle table by createXXXIndirect. SelectObject selects one of the objects to draw something, while DeleteObject removes them from the table. All GDI objects are removed via DeleteObject at the end of the metafile by WMF by default.
Please consult the Windows SDK for the GDI commands and GDI constants.

WMF is compatible with JDK 1.0, JDK 1.1 and JDK 1.2
See Also:
  • com.pietjonas.wmfwriter2d.WMFGraphics
  • com.pietjonas.wmfwriter2d.WMFGraphics2D
  • Field Details

  • Constructor Details

    • WMF

      public WMF()
      constructs a WMF object.
  • Method Details

    • metaRecord

      protected void metaRecord(int id, int wordparams)
      Write the leading metafile record
      Parameters:
      id - the id of the metafile record
      wordparames - the number of words (two bytes) of the parameters of therecord
    • writeWord

      protected void writeWord(int value)
      Write a word (two bytes) to the metafile
      Parameters:
      value - the word (in the lower two bytes)
    • writeInteger

      protected void writeInteger(int value)
      Write an integer (four bytes) to the metafile
      Parameters:
      value - the integer
    • writeColor

      protected void writeColor(Color color)
      Write a TColorRef struct to the metafile
      Parameters:
      color - the Color
    • writeBitmap

      protected void writeBitmap(int[] tmppix, int width, int height)
      Write a 24 bit bitmap (TBitmapInfoHeader plus pixels) to the metafile
      Parameters:
      tmppix - the pixels as retrieved by java.awt.image.PixelGrabber
      width - the width of the bitmap
      height - the height of the bitmap
    • addHandle

      protected int addHandle()
      Add a new handle to the handle table with GDI objects . Used by the createXXXIndirect methods.
      See Also:
    • translateFontName

      public String translateFontName(String name)
      Replace a Java font name (e.g 'helvetica') by its Windows counterpart (e.g 'Arial'). Uses a String [][2] table with pairs of font names. If the Java font name can not be found in the table the return value is equal to name.
      Parameters:
      name - the Java font name
      Returns:
      the corresponding Windows fontname
      See Also:
    • setTranslateFontNames

      public void setTranslateFontNames(String[][] names)
      Sets the String replacement table for the font names.
      Parameters:
      names - the String[][2] table with pairs of font names {Java font, Windows font}
      See Also:
    • getTranslateFontNames

      public String[][] getTranslateFontNames()
      Returns the current String replacement table.
      Returns:
      the String replacement table.
      See Also:
    • writePlaceableWMF

      public void writePlaceableWMF(OutputStream out, int x, int y, int width, int height, int dpi) throws IOException
      Write a placeable Windows metafile with the called GDI commands to the OutputStream out which is compatible with almost all Windows programs. All currently created GDI objects are deleted.
      Parameters:
      out - The OutputStream to write the metafile.
      x - The x coordinate of the bounding rectangle.
      y - The y coordinate of the bounding rectangle.
      width - The width of the bounding rectangle.
      height - The height of the bounding rectangle.
      dpi - Specifies the number of metafile units to the inch.
      Throws:
      IOException
      See Also:
    • writeWMF

      public void writeWMF(OutputStream out) throws IOException
      Write a simple Windows metafile with the called GDI commands to the OutputStream out which is not recognized by a lot of Windows programs. All currently created GDI objects are deleted.
      Parameters:
      out - The OutputStream to write the metafile.
      Throws:
      IOException
      See Also:
    • selectObject

      public void selectObject(int index)
      See Windows SDK. Selects a GDI object from the handle table.
      Parameters:
      index - The index in the handle table
      See Also:
    • deleteObject

      public void deleteObject(int index)
      See Windows SDK. Removes a GDI object from the handle table and deletes it.
      Parameters:
      index - The index in the handle table
      See Also:
    • createPenIndirect

      public int createPenIndirect(int style, int width, Color foreground)
      See Windows SDK. Adds this GDI pen object to the next free place in the handle table.
      Parameters:
      style - Use a PS_XXX constant.
      See Also:
    • createBrushIndirect

      public int createBrushIndirect(int style, Color foreground, int hatch)
      See Windows SDK. Adds this GDI brush object to the next free place in the handle table.
      Parameters:
      style - Use a BS_XXX constant.
      hatch - Use a HS_XXX constant.
      See Also:
    • createPatternBrush

      public int createPatternBrush(int[] pix, int width, int height)
      See Windows SDK. Adds this GDI pattern brush object to the next free place in the handle table.
      Parameters:
      pix - The pixels of the pattern bitmap (from java.awt.image.PixelGrabber).
      width - The width of the bitmap. Should be 8 at least.
      height - The height of the bitmap. Should be 8 at least.
      See Also:
    • createFont

      public int createFont(Font font, int escapement, boolean underline, boolean strikeout)
      Convenience method to call createFontIndirect with a java.awt.Font. Adds this GDI font object to the next free place in the handle table.
      Parameters:
      font - The Java Font object.
      escapement - The drawing angle of the font (in tenth degrees).
      underline - Whether to underline the font.
      strikeout - Whether to strike the font out.
      See Also:
    • createFontIndirect

      public int createFontIndirect(int height, int width, int escapement, int orientation, int weight, boolean italic, boolean underline, boolean strikeout, byte charset, byte outprecision, byte clipprecision, byte quality, byte pitchandfamiliy, String name)
      See Windows SDK. Adds this GDI font object to the next free place in the handle table.
      Parameters:
      height - The height of the font.
      width - The width of the font (can be 0).
      escapement - The drawing angle of the font (in tenth degrees).
      orientation - Ignored.
      weight - Use a FW_XXX constant.
      italic - Whether to draw use an italic font.
      underline - Whether to underline the font.
      strikeout - Whether to strike the font out.
      quality - Use a XXX_CHARSET constant.
      outprecision - Use a OUT_XXX constant.
      clipprecision - Use a CLIP_XXX constant.
      quality - Use a XXX_QUALITY constant.
      pitchandfamily - Use a combination of XXX_PITCH and FF_XXX constants.
      name - The font name.
      See Also:
    • setWindowOrg

      public void setWindowOrg(int x, int y)
      See Windows SDK, should be called at the beginning of a metafile with the origin of the metafile.
    • setWindowExt

      public void setWindowExt(int width, int height)
      See Windows SDK, should be called at the beginning of a metafile with the extend of the metafile.
    • offsetWindowOrg

      public void offsetWindowOrg(int x, int y)
      See Windows SDK.
    • scaleWindowExt

      public void scaleWindowExt(int xnum, int xdenom, int ynum, int ydenom)
      See Windows SDK.
    • setViewportOrg

      public void setViewportOrg(int x, int y)
      See Windows SDK, should not be called in a metafile.
    • setViewportExt

      public void setViewportExt(int width, int height)
      See Windows SDK, should not be called in a metafile.
    • offsetViewportOrg

      public void offsetViewportOrg(int x, int y)
      See Windows SDK, should not be called in a metafile.
    • scaleViewportExt

      public void scaleViewportExt(int xnum, int xdenom, int ynum, int ydenom)
      See Windows SDK, should not be called in a metafile.
    • setTextColor

      public void setTextColor(Color textcolor)
      See Windows SDK.
    • setBKMode

      public void setBKMode(int mode)
      See Windows SDK.
      Parameters:
      mode - Use TRANSPARENT or OPAQUE.
    • setBKColor

      public void setBKColor(Color bkcolor)
      See Windows SDK.
    • setMapMode

      public void setMapMode(int mode)
      See Windows SDK.
      Parameters:
      mode - Use a MM_XXX constant.
    • setPolyFillMode

      public void setPolyFillMode(int mode)
      See Windows SDK.
      Parameters:
      mode - Use ALTERNATE or WINDING.
    • setStretchBltMode

      public void setStretchBltMode(int mode)
      See Windows SDK.
      Parameters:
      mode - Use a STRETCH_XXX constant.
    • setTextAlign

      public void setTextAlign(int align)
      See Windows SDK.
      Parameters:
      align - Use a combination of TA_XXX constants.
    • setROP2

      public void setROP2(int mode)
      See Windows SDK.
      Parameters:
      mode - Use a R2_XXX constant.
    • setTextCharacterExtra

      public void setTextCharacterExtra(int charextra)
      See Windows SDK.
    • setTextJustification

      public void setTextJustification(int breakextra, int breakcount)
      See Windows SDK.
    • moveTo

      public void moveTo(int x, int y)
      See Windows SDK.
    • lineTo

      public void lineTo(int x, int y)
      See Windows SDK.
    • arc

      public void arc(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
      See Windows SDK.
    • chord

      public void chord(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
      See Windows SDK.
    • pie

      public void pie(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
      See Windows SDK.
    • rectangle

      public void rectangle(int x1, int y1, int x2, int y2)
      See Windows SDK.
    • ellipse

      public void ellipse(int x1, int y1, int x2, int y2)
      See Windows SDK.
    • roundRect

      public void roundRect(int x1, int y1, int x2, int y2, int x3, int y3)
      See Windows SDK.
    • polygon

      public void polygon(int[] xPoints, int[] yPoints, int nPoints)
      See Windows SDK.
    • polypolygon

      public void polypolygon(Polygon[] polys)
      See Windows SDK.
    • polyline

      public void polyline(int[] xPoints, int[] yPoints, int nPoints)
      See Windows SDK.
    • intersectClipRect

      public void intersectClipRect(int x1, int y1, int x2, int y2)
      See Windows SDK.
    • setClipRgn

      public void setClipRgn()
      See Windows SDK. Selects a NIL region, therefore removes any clipping
    • textOut

      public void textOut(int x, int y, String str)
      See Windows SDK.
    • extTextOut

      public void extTextOut(int x, int y, int options, Rectangle rect, String str)
      See Windows SDK.
      Parameters:
      options - Use a ETO_XXX constant.
      rect - Bounding box. Is ignored, if options == 0
    • extTextOut

      public void extTextOut(int x, int y, int options, Rectangle rect, String str, int[] dx)
      See Windows SDK.
      Parameters:
      options - Use a ETO_XXX constant.
      rect - Bounding box. Is ignored, if options == 0
      dx - Distance between character cells. Can be null. dx.length() >= str.length
    • escape

      public void escape(int number, byte[] data)
      See Windows SDK.
    • setPixel

      public void setPixel(int x, int y, Color pixelcolor)
      See Windows SDK.
    • stretchBlt

      public void stretchBlt(int dx, int dy, int dwidth, int dheight, int sx, int sy, int swidth, int sheight, int rop, int[] pix, int width, int height)
      See Windows SDK.
      Parameters:
      dx - ,dy,dwidth,dheight The destination rectangle
      sx - ,sy,swidth,sheight The source rectangle
      rop - Use a SRCXXX constant.
      pix - The pixels of the source bitmap (from java.awt.image.PixelGrabber).
      width - The width of the bitmap.
      height - The height of the bitmap.
    • bitBlt

      public void bitBlt(int dx, int dy, int dwidth, int dheight, int sx, int sy, int rop, int[] pix, int width, int height)
      See Windows SDK.
      Parameters:
      dx - ,dy,dwidth,dheight The destination rectangle
      sx - ,sy The source origin
      rop - Use a SRCXXX constant.
      pix - The pixels of the source bitmap (from java.awt.image.PixelGrabber).
      width - The width of the bitmap.
      height - The height of the bitmap.
    • patBlt

      public void patBlt(int x, int y, int width, int height, int rop)
      See Windows SDK.
      Parameters:
      x - ,y,width,height The destination rectangle
      rop - Use a PATXXX constant.