Class AbstractWMFReader
- java.lang.Object
-
- org.apache.batik.transcoder.wmf.tosvg.AbstractWMFReader
-
- Direct Known Subclasses:
WMFHeaderProperties,WMFRecordStore
public abstract class AbstractWMFReader extends java.lang.ObjectThis class provides a general framework to read WMF Metafiles.- Version:
- $Id: AbstractWMFReader.java 1831630 2018-05-15 12:56:55Z ssteiner $
-
-
Field Summary
Fields Modifier and Type Field Description protected intbottomprotected booleanbReadingprotected intheightprotected intinchprotected booleanisAldusprotected booleanisotropicintlastObjectIdxprotected intleftstatic floatMM_PER_PIXELprotected intmtHeaderSizeprotected intmtMaxRecordprotected intmtNoObjectsprotected intmtNoParametersprotected intmtSizeprotected intmtTypeprotected intmtVersionprotected intnumObjectsprotected java.util.ListobjectVectorstatic floatPIXEL_PER_INCHprotected intrightprotected floatscaleXprotected floatscaleXYprotected floatscaleYprotected inttopprotected intvpHprotected intvpWprotected intvpXprotected intvpYprotected intwidthprotected intwindowHeightprotected intwindowWidthprotected intxSignprotected intySign
-
Constructor Summary
Constructors Constructor Description AbstractWMFReader()AbstractWMFReader(int width, int height)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intaddObject(int type, java.lang.Object obj)intaddObjectAt(int type, java.lang.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 tableGdiObjectgetObject(int idx)Returns a GdiObject from the handle tablefloatgetPixelsPerUnit()Return the number of pixels per unit.java.awt.geom.Rectangle2DgetRectangleInch()get the Rectangle defining the viewport of the WMF Metafile, in inchs.java.awt.geom.Rectangle2DgetRectanglePixel()get the Rectangle defining the viewport of the WMF Metafile, in pixels.java.awt.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 pixelsfloatgetViewportHeightInch()Returns the viewport height, in inches.floatgetViewportHeightUnits()Returns the viewport height, in Metafile UnitsfloatgetViewportWidthInch()Returns the viewport width, in inches.floatgetViewportWidthUnits()Returns the viewport width, in Metafile UnitsintgetVpH()Returns the viewport height, in pixels.floatgetVpHFactor()get the factor to transform logical units height in pixelsintgetVpW()Returns the viewport width, in pixels.floatgetVpWFactor()get the factor to transform logical units width in pixelsintgetWidthPixels()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(java.io.DataInputStream is)Reads the WMF file from the specified Stream, read it and set the following properties:mtType: File type (0 : memory, 1 : disk)mtHeaderSize: Size of header in WORDS (always 9)mtVersion: Version of Microsoft Windows usedmtSize: Total size of the metafile in WORDsmtNoObjects: Number of objects in the filemtMaxRecord: The size of largest record in WORDsmtNoParameters: Not Used (always 0) If the file contains an APM (aldus placeable header), this method read these additionnal properties :left: Left coordinate in metafile unitsright: Right coordinate in metafile unitstop: Top coordinate in metafile unitsbottom: Bottom coordinate in metafile unitsinch: Number of metafile units per inchprotected intreadInt(java.io.DataInputStream is)Read the next int (4 bytes) value in the DataInputStream.protected abstract booleanreadRecords(java.io.DataInputStream is)Read this InputStream records.protected shortreadShort(java.io.DataInputStream is)Read the next short (2 bytes) value in the DataInputStream.abstract voidreset()resets this WMFReader.protected voidsetReading(boolean state)
-
-
-
Field Detail
-
PIXEL_PER_INCH
public static final float PIXEL_PER_INCH
-
MM_PER_PIXEL
public static final float MM_PER_PIXEL
-
left
protected int left
-
right
protected int right
-
top
protected int top
-
bottom
protected int bottom
-
width
protected int width
-
height
protected int height
-
inch
protected int inch
-
scaleX
protected float scaleX
-
scaleY
protected float scaleY
-
scaleXY
protected float scaleXY
-
vpW
protected int vpW
-
vpH
protected int vpH
-
vpX
protected int vpX
-
vpY
protected int vpY
-
xSign
protected int xSign
-
ySign
protected int ySign
-
bReading
protected volatile boolean bReading
-
isAldus
protected boolean isAldus
-
isotropic
protected boolean isotropic
-
mtType
protected int mtType
-
mtHeaderSize
protected int mtHeaderSize
-
mtVersion
protected int mtVersion
-
mtSize
protected int mtSize
-
mtNoObjects
protected int mtNoObjects
-
mtMaxRecord
protected int mtMaxRecord
-
mtNoParameters
protected int mtNoParameters
-
windowWidth
protected int windowWidth
-
windowHeight
protected int windowHeight
-
numObjects
protected int numObjects
-
objectVector
protected java.util.List objectVector
-
lastObjectIdx
public int lastObjectIdx
-
-
Method Detail
-
readShort
protected short readShort(java.io.DataInputStream is) throws java.io.IOExceptionRead the next short (2 bytes) value in the DataInputStream.- Throws:
java.io.IOException
-
readInt
protected int readInt(java.io.DataInputStream is) throws java.io.IOExceptionRead the next int (4 bytes) value in the DataInputStream.- Throws:
java.io.IOException
-
getViewportWidthUnits
public float getViewportWidthUnits()
Returns the viewport width, in Metafile Units
-
getViewportHeightUnits
public float getViewportHeightUnits()
Returns the viewport height, in Metafile Units
-
getViewportWidthInch
public float getViewportWidthInch()
Returns the viewport width, in inches.
-
getViewportHeightInch
public float getViewportHeightInch()
Returns the viewport height, in inches.
-
getPixelsPerUnit
public float getPixelsPerUnit()
Return the number of pixels per unit.
-
getVpW
public int getVpW()
Returns the viewport width, in pixels.
-
getVpH
public int getVpH()
Returns the viewport height, in pixels.
-
getLeftUnits
public int getLeftUnits()
get the left units in the WMF Metafile. This value is given in the Aldus Placable Metafile.
-
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.
-
getWidthUnits
public int getWidthUnits()
get the width units in the WMF Metafile. This value is given in the Aldus Placable Header.
-
getHeightUnits
public int getHeightUnits()
get the height units in the WMF Metafile. This value is given in the Aldus Placable Header.
-
getBottomUnits
public int getBottomUnits()
get the bottom units in the WMF Metafile. This value is given in the Aldus Placable Header.
-
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.
-
getRectangleUnits
public java.awt.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()
-
getRectanglePixel
public java.awt.geom.Rectangle2D getRectanglePixel()
get the Rectangle defining the viewport of the WMF Metafile, in pixels.
-
getRectangleInch
public java.awt.geom.Rectangle2D getRectangleInch()
get the Rectangle defining the viewport of the WMF Metafile, in inchs.
-
getWidthPixels
public int getWidthPixels()
get the width of the WMF Metafile, in pixels.
-
getUnitsToPixels
public float getUnitsToPixels()
get the factor to transform Metafile dimensions in pixels
-
getVpWFactor
public float getVpWFactor()
get the factor to transform logical units width in pixels
-
getVpHFactor
public float getVpHFactor()
get the factor to transform logical units height in pixels
-
getHeightPixels
public int getHeightPixels()
get the height of the WMF Metafile, in pixels.
-
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.
-
setReading
protected void setReading(boolean state)
-
isReading
public boolean isReading()
- Returns:
- true if the reader is currently reading an InputStream.
-
reset
public abstract void reset()
resets this WMFReader.
-
readRecords
protected abstract boolean readRecords(java.io.DataInputStream is) throws java.io.IOExceptionRead this InputStream records. The aldus placeable header have already been read (seeread(DataInputStream)). The behavior of this method is left to the subclass. Each Metafile record is composed of :- the size of the Record in int (32 bits)
- the function ID for the Record on a short word (16 bits)
- the function parameters, according to the WMF Metafile specification. the remaining size in short words (16 bits) for the parameters is equal to the total size for the record minus 3 short words (= 16 + 32 bits)
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;- Throws:
java.io.IOException- See Also:
WMFConstants
-
read
public void read(java.io.DataInputStream is) throws java.io.IOExceptionReads the WMF file from the specified Stream, read it and set the following properties:mtType: File type (0 : memory, 1 : disk)mtHeaderSize: Size of header in WORDS (always 9)mtVersion: Version of Microsoft Windows usedmtSize: Total size of the metafile in WORDsmtNoObjects: Number of objects in the filemtMaxRecord: The size of largest record in WORDsmtNoParameters: Not Used (always 0)
left: Left coordinate in metafile unitsright: Right coordinate in metafile unitstop: Top coordinate in metafile unitsbottom: Bottom coordinate in metafile unitsinch: Number of metafile units per inch
Then it calls the
.readRecords(DataInputStream)abstract method, whose behavior is left to the subclass- Throws:
java.io.IOException
-
addObject
public int addObject(int type, java.lang.Object obj)
-
addObjectAt
public int addObjectAt(int type, java.lang.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
-
getObject
public GdiObject getObject(int idx)
Returns a GdiObject from the handle table
-
getNumObjects
public int getNumObjects()
Returns the number of GdiObjects in the handle table
-
-