org.apache.batik.transcoder.wmf.tosvg

Class AbstractWMFReader

public abstract class AbstractWMFReader extends Object

This class provides a general framework to read WMF Metafiles.
Field Summary
protected intbottom
protected booleanbReading
protected intheight
protected intinch
intlastObjectIdx
protected intleft
protected intmtHeaderSize
protected intmtMaxRecord
protected intmtNoObjects
protected intmtNoParameters
protected intmtSize
protected intmtType
protected intmtVersion
static floatMM_PER_PIXEL
protected intnumObjects
protected ListobjectVector
static floatPIXEL_PER_INCH
protected intright
protected floatscaleX
protected floatscaleY
protected inttop
protected intvpH
protected intvpW
protected intvpX
protected intvpY
protected intwidth
protected intwindowHeight
protected intwindowWidth
protected intxSign
protected intySign
Constructor Summary
AbstractWMFReader()
AbstractWMFReader(int width, int height)
Method Summary
intaddObject(int type, Object obj)
intaddObjectAt(int type, Object obj, int idx)
Adds a GdiObject to the internal handle table.
intgetBottomUnits()
get the bottom units in the WMF Metafile.
intgetHeightPixels()
get the height of the WMF Metafile, in pixels.
intgetHeightUnits()
get the height units in the WMF Metafile.
intgetLeftUnits()
get the left units in the WMF Metafile.
intgetMetaFileUnitsPerInch()
get the number of Metafile units per inch in the WMF Metafile.
intgetNumObjects()
Returns the number of GdiObjects in the handle table
GdiObjectgetObject(int idx)
Returns a GdiObject from the handle table
floatgetPixelsPerUnit()
Return the number of pixels per unit.
Rectangle2DgetRectangleInch()
get the Rectangle defining the viewport of the WMF Metafile, in inchs.
Rectangle2DgetRectanglePixel()
get the Rectangle defining the viewport of the WMF Metafile, in pixels.
RectanglegetRectangleUnits()
get the Rectangle defining the viewport of the WMF Metafile, in Metafile units.
intgetRightUnits()
get the right units in the WMF Metafile.
intgetTopUnits()
get the top units in the WMF Metafile.
floatgetUnitsToPixels()
get the factor to transform Metafile dimensions in pixels
floatgetViewportHeightInch()
Returns the viewport height, in inches.
floatgetViewportHeightUnits()
Returns the viewport height, in Metafile Units
floatgetViewportWidthInch()
Returns the viewport width, in inches.
floatgetViewportWidthUnits()
Returns the viewport width, in Metafile Units
intgetVpH()
Returns the viewport height, in pixels.
floatgetVpHFactor()
get the factor to transform logical units height in pixels
intgetVpW()
Returns the viewport width, in pixels.
floatgetVpWFactor()
get the factor to transform logical units width in pixels
intgetWidthPixels()
get the width of the WMF Metafile, in pixels.
intgetWidthUnits()
get the width units in the WMF Metafile.
intgetXSign()
Return the sign of X coordinates.
intgetYSign()
Return the sign of Y coordinates.
booleanisReading()
voidread(DataInputStream is)
Reads the WMF file from the specified Stream.
protected intreadInt(DataInputStream is)
Read the next int ( 4 bytes) value in the DataInputStream. we cant use is.readInt() because of different byte-order.
protected abstract booleanreadRecords(DataInputStream is)
Read this InputStream records.
protected shortreadShort(DataInputStream is)
Read the next short ( 2 bytes) value in the DataInputStream. we cant use is.readShort() because of different byte-order.
abstract voidreset()
resets this WMFReader.
protected voidsetReading(boolean state)

Field Detail

bottom

protected int bottom

bReading

protected volatile boolean bReading

height

protected int height

inch

protected int inch

lastObjectIdx

public int lastObjectIdx

left

protected int left

mtHeaderSize

protected int mtHeaderSize

mtMaxRecord

protected int mtMaxRecord

mtNoObjects

protected int mtNoObjects

mtNoParameters

protected int mtNoParameters

mtSize

protected int mtSize

mtType

protected int mtType

mtVersion

protected int mtVersion

MM_PER_PIXEL

public static final float MM_PER_PIXEL

numObjects

protected int numObjects

objectVector

protected List objectVector

PIXEL_PER_INCH

public static final float PIXEL_PER_INCH

right

protected int right

scaleX

protected float scaleX

scaleY

protected float scaleY

top

protected int top

vpH

protected int vpH

vpW

protected int vpW

vpX

protected int vpX

vpY

protected int vpY

width

protected int width

windowHeight

protected int windowHeight

windowWidth

protected int windowWidth

xSign

protected int xSign

ySign

protected int ySign

Constructor Detail

AbstractWMFReader

public AbstractWMFReader()

AbstractWMFReader

public AbstractWMFReader(int width, int height)

Method Detail

addObject

public int addObject(int type, Object obj)

addObjectAt

public int addObjectAt(int type, Object obj, int idx)
Adds a GdiObject to the internal handle table. Wmf files specify the index as given in EMF records such as EMRCREATEPENINDIRECT whereas WMF files always use 0. This function should not normally be called by an application.

Returns: the object index

getBottomUnits

public int getBottomUnits()
get the bottom units in the WMF Metafile. This value is given in the Aldus Placable Header.

getHeightPixels

public int getHeightPixels()
get the height of the WMF Metafile, in pixels.

getHeightUnits

public int getHeightUnits()
get the height units in the WMF Metafile. This value is given in the Aldus Placable Header.

getLeftUnits

public int getLeftUnits()
get the left units in the WMF Metafile. This value is given in the Aldus Placable Metafile.

getMetaFileUnitsPerInch

public int getMetaFileUnitsPerInch()
get the number of Metafile units per inch in the WMF Metafile. This value is given in the Aldus Placable Header.

getNumObjects

public int getNumObjects()
Returns the number of GdiObjects in the handle table

getObject

public GdiObject getObject(int idx)
Returns a GdiObject from the handle table

getPixelsPerUnit

public float getPixelsPerUnit()
Return the number of pixels per unit.

getRectangleInch

public Rectangle2D getRectangleInch()
get the Rectangle defining the viewport of the WMF Metafile, in inchs.

getRectanglePixel

public Rectangle2D getRectanglePixel()
get the Rectangle defining the viewport of the WMF Metafile, in pixels.

getRectangleUnits

public Rectangle getRectangleUnits()
get the Rectangle defining the viewport of the WMF Metafile, in Metafile units. This viewport is defined in the Aldus Placable Header, by its left, top, bottom, right components.

See Also: getRightUnits getLeftUnits getTopUnits getBottomUnits

getRightUnits

public int getRightUnits()
get the right units in the WMF Metafile. This value is given in the Aldus Placable Header.

getTopUnits

public int getTopUnits()
get the top units in the WMF Metafile. This value is given in the Aldus Placable Header.

getUnitsToPixels

public float getUnitsToPixels()
get the factor to transform Metafile dimensions in pixels

getViewportHeightInch

public float getViewportHeightInch()
Returns the viewport height, in inches.

getViewportHeightUnits

public float getViewportHeightUnits()
Returns the viewport height, in Metafile Units

getViewportWidthInch

public float getViewportWidthInch()
Returns the viewport width, in inches.

getViewportWidthUnits

public float getViewportWidthUnits()
Returns the viewport width, in Metafile Units

getVpH

public int getVpH()
Returns the viewport height, in pixels.

getVpHFactor

public float getVpHFactor()
get the factor to transform logical units height in pixels

getVpW

public int getVpW()
Returns the viewport width, in pixels.

getVpWFactor

public float getVpWFactor()
get the factor to transform logical units width in pixels

getWidthPixels

public int getWidthPixels()
get the width of the WMF Metafile, in pixels.

getWidthUnits

public int getWidthUnits()
get the width units in the WMF Metafile. This value is given in the Aldus Placable Header.

getXSign

public int getXSign()
Return the sign of X coordinates. It is equal to 1 by default, but can be -1 if all X coordinates are inversed.

getYSign

public int getYSign()
Return the sign of Y coordinates. It is equal to 1 by default, but can be -1 if all Y coordinates are inversed.

isReading

public boolean isReading()

Returns: true if the reader is currently reading an InputStream.

read

public void read(DataInputStream is)
Reads the WMF file from the specified Stream. This method read the aldus placeable header and set the corresponding properties :

Then it calls the {@link #readRecords(DataInputStream)} abstract method, whose behavior is left to the subclass

.

readInt

protected int readInt(DataInputStream is)
Read the next int ( 4 bytes) value in the DataInputStream. we cant use is.readInt() because of different byte-order.

readRecords

protected abstract boolean readRecords(DataInputStream is)
Read this InputStream records. The aldus placeable header have already been read (see {@link #read(DataInputStream)}). The behavior of this method is left to the subclass.

Each Metafile record is composed of :

Example :

while (functionId > 0) {
        recSize = readInt( is );
        // Subtract size in 16-bit words of recSize and functionId;
        recSize -= 3;
        functionId = readShort( is );
        if ( functionId <= 0 )
          break;
        switch ( functionId ) {
          case WMFConstants.<a WMF function ID> {
            do something when this function is encountered
          }
          break;

          default:
             for ( int j = 0; j < recSize; j++ )
               readShort(is);
          break;
 

See Also: WMFConstants

readShort

protected short readShort(DataInputStream is)
Read the next short ( 2 bytes) value in the DataInputStream. we cant use is.readShort() because of different byte-order.

reset

public abstract void reset()
resets this WMFReader.

setReading

protected void setReading(boolean state)
Copyright B) 2007 Apache Software Foundation. All Rights Reserved.