a few more wmf records ...

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/wmf_render@1568840 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2014-02-16 21:56:14 +00:00
parent 87a6135199
commit c8dee17f33
16 changed files with 735 additions and 506 deletions

View File

@ -8,6 +8,7 @@ import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream; import org.apache.poi.util.LittleEndianInputStream;
public class WmfBitmap16 { public class WmfBitmap16 {
final boolean isPartial;
int type; int type;
int width; int width;
int height; int height;
@ -15,6 +16,14 @@ public class WmfBitmap16 {
int planes; int planes;
int bitsPixel; int bitsPixel;
public WmfBitmap16() {
this(false);
}
public WmfBitmap16(boolean isPartial) {
this.isPartial = isPartial;
}
public int init(LittleEndianInputStream leis) throws IOException { public int init(LittleEndianInputStream leis) throws IOException {
// A 16-bit signed integer that defines the bitmap type. // A 16-bit signed integer that defines the bitmap type.
type = leis.readShort(); type = leis.readShort();
@ -35,9 +44,19 @@ public class WmfBitmap16 {
// An 8-bit unsigned integer that defines the number of adjacent color bits on // An 8-bit unsigned integer that defines the number of adjacent color bits on
// each plane. // each plane.
bitsPixel = leis.readUByte(); bitsPixel = leis.readUByte();
int size = 2*LittleEndianConsts.BYTE_SIZE+4*LittleEndianConsts.SHORT_SIZE;
if (isPartial) {
// Bits (4 bytes): This field MUST be ignored.
long skipSize = leis.skip(LittleEndianConsts.INT_SIZE);
assert(skipSize == LittleEndianConsts.INT_SIZE);
// Reserved (18 bytes): This field MUST be ignored.
skipSize = leis.skip(18);
assert(skipSize == 18);
size += 18+LittleEndianConsts.INT_SIZE;
}
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
int size = 2*LittleEndianConsts.BYTE_SIZE+4*LittleEndianConsts.SHORT_SIZE;
int size2 = 0; int size2 = 0;
byte buf[] = new byte[widthBytes]; byte buf[] = new byte[widthBytes];

View File

@ -1,124 +0,0 @@
package org.apache.poi.hwmf.record;
import java.io.IOException;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
/**
* The META_DIBCREATEPATTERNBRUSH record creates a Brush Object with a
* pattern specified by a DeviceIndependentBitmap (DIB) Object
*/
public class WmfDibCreatePatternBrush implements WmfRecord {
/**
* A 16-bit unsigned integer that defines the brush style. The legal values for this
* field are defined as follows: if the value is not BS_PATTERN, BS_DIBPATTERNPT MUST be
* assumed.
*/
public static enum BrushStyle {
/**
* A brush that paints a single, constant color, either solid or dithered.
*/
BS_SOLID(0x0000),
/**
* A brush that does nothing. Using a BS_NULL brush in a graphics operation
* MUST have the same effect as using no brush at all.
*/
BS_NULL(0x0001),
/**
* A brush that paints a predefined simple pattern, or "hatch", onto a solid background.
*/
BS_HATCHED(0x0002),
/**
* A brush that paints a pattern defined by a bitmap, which MAY be a Bitmap16
* Object or a DeviceIndependentBitmap (DIB) Object.
*/
BS_PATTERN(0x0003),
/**
* Not supported
*/
BS_INDEXED(0x0004),
/**
* A pattern brush specified by a DIB.
*/
BS_DIBPATTERN(0x0005),
/**
* A pattern brush specified by a DIB.
*/
BS_DIBPATTERNPT(0x0006),
/**
* Not supported
*/
BS_PATTERN8X8(0x0007),
/**
* Not supported
*/
BS_DIBPATTERN8X8(0x0008),
/**
* Not supported
*/
BS_MONOPATTERN(0x0009);
int flag;
BrushStyle(int flag) {
this.flag = flag;
}
static BrushStyle valueOf(int flag) {
for (BrushStyle bs : values()) {
if (bs.flag == flag) return bs;
}
return null;
}
}
BrushStyle style;
/**
* A 16-bit unsigned integer that defines whether the Colors field of a DIB
* Object contains explicit RGB values, or indexes into a palette.
*
* If the Style field specifies BS_PATTERN, a ColorUsage value of DIB_RGB_COLORS MUST be
* used regardless of the contents of this field.
*
* If the Style field specified anything but BS_PATTERN, this field MUST be one of the values:
* DIB_RGB_COLORS = 0x0000,
* DIB_PAL_COLORS = 0x0001,
* DIB_PAL_INDICES = 0x0002
*/
int colorUsage;
WmfBitmapDib patternDib;
WmfBitmap16 pattern16;
public WmfRecordType getRecordType() {
return WmfRecordType.dibCreatePatternBrush;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
style = BrushStyle.valueOf(leis.readUShort());
colorUsage = leis.readUShort();
int size = 2*LittleEndianConsts.SHORT_SIZE;
switch (style) {
case BS_SOLID:
case BS_NULL:
case BS_DIBPATTERN:
case BS_DIBPATTERNPT:
case BS_HATCHED:
patternDib = new WmfBitmapDib();
size += patternDib.init(leis);
break;
case BS_PATTERN:
pattern16 = new WmfBitmap16();
size += pattern16.init(leis);
break;
case BS_INDEXED:
case BS_DIBPATTERN8X8:
case BS_MONOPATTERN:
case BS_PATTERN8X8:
throw new RuntimeException("pattern not supported");
}
return size;
}
}

View File

@ -6,6 +6,33 @@ import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream; import org.apache.poi.util.LittleEndianInputStream;
public class WmfDraw { public class WmfDraw {
/**
* The META_MOVETO record sets the output position in the playback device context to a specified
* point.
*/
public static class WmfMoveTo implements WmfRecord {
/**
* A 16-bit signed integer that defines the y-coordinate, in logical units.
*/
int y;
/**
* A 16-bit signed integer that defines the x-coordinate, in logical units.
*/
int x;
public WmfRecordType getRecordType() {
return WmfRecordType.moveTo;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
y = leis.readShort();
x = leis.readShort();
return 2*LittleEndianConsts.SHORT_SIZE;
}
}
/** /**
* The META_LINETO record draws a line from the drawing position that is defined in the playback * The META_LINETO record draws a line from the drawing position that is defined in the playback
* device context up to, but not including, the specified point. * device context up to, but not including, the specified point.

View File

@ -244,10 +244,9 @@ public class WmfFill {
} }
} }
/**
*/
public static class WmfStretchBlt implements WmfRecord { public static class WmfStretchBlt implements WmfRecord {
/**
*/
/** /**
* A 32-bit unsigned integer that defines how the source pixels, the current brush * A 32-bit unsigned integer that defines how the source pixels, the current brush
* in the playback device context, and the destination pixels are to be combined to form the new * in the playback device context, and the destination pixels are to be combined to form the new
@ -337,6 +336,105 @@ public class WmfFill {
} }
} }
/**
* The META_STRETCHDIB record specifies the transfer of color data from a
* block of pixels in deviceindependent format according to a raster operation,
* with possible expansion or contraction.
* The source of the color data is a DIB, and the destination of the transfer is
* the current output region in the playback device context.
*/
public static class WmfStretchDib implements WmfRecord {
/**
* A 32-bit unsigned integer that defines how the source pixels, the current brush in
* the playback device context, and the destination pixels are to be combined to
* form the new image.
*/
WmfTernaryRasterOp rasterOperation;
/**
* A 16-bit unsigned integer that defines whether the Colors field of the
* DIB contains explicit RGB values or indexes into a palette.
* This value MUST be in the ColorUsage Enumeration:
* DIB_RGB_COLORS = 0x0000,
* DIB_PAL_COLORS = 0x0001,
* DIB_PAL_INDICES = 0x0002
*/
int colorUsage;
/**
* A 16-bit signed integer that defines the height, in logical units, of the
* source rectangle.
*/
int srcHeight;
/**
* A 16-bit signed integer that defines the width, in logical units, of the
* source rectangle.
*/
int srcWidth;
/**
* A 16-bit signed integer that defines the y-coordinate, in logical units, of the
* source rectangle.
*/
int ySrc;
/**
* A 16-bit signed integer that defines the x-coordinate, in logical units, of the
* source rectangle.
*/
int xSrc;
/**
* A 16-bit signed integer that defines the height, in logical units, of the
* destination rectangle.
*/
int destHeight;
/**
* A 16-bit signed integer that defines the width, in logical units, of the
* destination rectangle.
*/
int destWidth;
/**
* A 16-bit signed integer that defines the y-coordinate, in logical units, of the
* upper-left corner of the destination rectangle.
*/
int yDst;
/**
* A 16-bit signed integer that defines the x-coordinate, in logical units, of the
* upper-left corner of the destination rectangle.
*/
int xDst;
/**
* A variable-sized DeviceIndependentBitmap Object (section 2.2.2.9) that is the
* source of the color data.
*/
WmfBitmapDib dib;
public WmfRecordType getRecordType() {
return WmfRecordType.stretchDib;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
int rasterOpIndex = leis.readUShort();
int rasterOpCode = leis.readUShort();
rasterOperation = WmfTernaryRasterOp.fromOpIndex(rasterOpIndex);
assert(rasterOpCode == rasterOperation.opCode);
colorUsage = leis.readUShort();
srcHeight = leis.readShort();
srcWidth = leis.readShort();
ySrc = leis.readShort();
xSrc = leis.readShort();
destHeight = leis.readShort();
destWidth = leis.readShort();
yDst = leis.readShort();
xDst = leis.readShort();
int size = 11*LittleEndianConsts.SHORT_SIZE;
dib = new WmfBitmapDib();
size += dib.init(leis);
return size;
}
}
public static class WmfBitBlt implements WmfRecord { public static class WmfBitBlt implements WmfRecord {
/** /**
@ -587,4 +685,93 @@ public class WmfFill {
return size; return size;
} }
} }
public static class WmfDibStretchBlt implements WmfRecord {
/**
* A 32-bit unsigned integer that defines how the source pixels, the current brush
* in the playback device context, and the destination pixels are to be combined to form the
* new image. This code MUST be one of the values in the Ternary Raster Operation Enumeration.
*/
WmfTernaryRasterOp rasterOperation;
/**
* A 16-bit signed integer that defines the height, in logical units, of the source rectangle.
*/
int srcHeight;
/**
* A 16-bit signed integer that defines the width, in logical units, of the source rectangle.
*/
int srcWidth;
/**
* A 16-bit signed integer that defines the y-coordinate, in logical units, of the
* upper-left corner of the source rectangle.
*/
int ySrc;
/**
* A 16-bit signed integer that defines the x-coordinate, in logical units, of the
* upper-left corner of the source rectangle.
*/
int xSrc;
/**
* A 16-bit signed integer that defines the height, in logical units, of the
* destination rectangle.
*/
int destHeight;
/**
* A 16-bit signed integer that defines the width, in logical units, of the
* destination rectangle.
*/
int destWidth;
/**
* A 16-bit signed integer that defines the y-coordinate, in logical units,
* of the upper-left corner of the destination rectangle.
*/
int yDest;
/**
* A 16-bit signed integer that defines the x-coordinate, in logical units,
* of the upper-left corner of the destination rectangle.
*/
int xDest;
/**
* A variable-sized DeviceIndependentBitmap Object that defines image content.
* This object MUST be specified, even if the raster operation does not require a source.
*/
WmfBitmapDib target;
public WmfRecordType getRecordType() {
return WmfRecordType.dibStretchBlt;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
boolean hasBitmap = (recordSize > ((recordFunction >> 8) + 3));
int size = 0;
int rasterOpIndex = leis.readUShort();
int rasterOpCode = leis.readUShort();
rasterOperation = WmfTernaryRasterOp.fromOpIndex(rasterOpIndex);
assert(rasterOpCode == rasterOperation.opCode);
srcHeight = leis.readShort();
srcWidth = leis.readShort();
ySrc = leis.readShort();
xSrc = leis.readShort();
size = 6*LittleEndianConsts.SHORT_SIZE;
if (!hasBitmap) {
@SuppressWarnings("unused")
int reserved = leis.readShort();
size += LittleEndianConsts.SHORT_SIZE;
}
destHeight = leis.readShort();
destWidth = leis.readShort();
yDest = leis.readShort();
xDest = leis.readShort();
size += 4*LittleEndianConsts.SHORT_SIZE;
if (hasBitmap) {
target = new WmfBitmapDib();
size += target.init(leis);
}
return size;
}
}
} }

View File

@ -0,0 +1,481 @@
package org.apache.poi.hwmf.record;
import java.io.IOException;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
public class WmfMisc {
/**
* The META_SAVEDC record saves the playback device context for later retrieval.
*/
public static class WmfSaveDc implements WmfRecord {
public WmfRecordType getRecordType() { return WmfRecordType.saveDc; }
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
return 0;
}
}
/**
* The META_SETRELABS record is reserved and not supported.
*/
public static class WmfSetRelabs implements WmfRecord {
public WmfRecordType getRecordType() { return WmfRecordType.setRelabs; }
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
return 0;
}
}
/**
* The META_RESTOREDC record restores the playback device context from a previously saved device
* context.
*/
public static class WmfRestoreDc implements WmfRecord {
/**
* nSavedDC (2 bytes): A 16-bit signed integer that defines the saved state to be restored. If this
* member is positive, nSavedDC represents a specific instance of the state to be restored. If
* this member is negative, nSavedDC represents an instance relative to the current state.
*/
int nSavedDC;
public WmfRecordType getRecordType() {
return WmfRecordType.restoreDc;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
nSavedDC = leis.readShort();
return LittleEndianConsts.SHORT_SIZE;
}
}
/**
* The META_SETBKCOLOR record sets the background color in the playback device context to a
* specified color, or to the nearest physical color if the device cannot represent the specified color.
*/
public static class WmfSetBkColor implements WmfRecord {
WmfColorRef colorRef;
public WmfRecordType getRecordType() {
return WmfRecordType.setBkColor;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
WmfColorRef colorRef = new WmfColorRef();
return colorRef.init(leis);
}
}
/**
* The META_SETBKMODE record defines the background raster operation mix mode in the playback
* device context. The background mix mode is the mode for combining pens, text, hatched brushes,
* and interiors of filled objects with background colors on the output surface.
*/
public static class WmfSetBkMode implements WmfRecord {
/**
* A 16-bit unsigned integer that defines background mix mode.
* This MUST be either TRANSPARENT = 0x0001 or OPAQUE = 0x0002
*/
int bkMode;
public WmfRecordType getRecordType() {
return WmfRecordType.setBkMode;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
bkMode = leis.readUShort();
return LittleEndianConsts.SHORT_SIZE;
}
}
/**
* The META_SETLAYOUT record defines the layout orientation in the playback device context.
* The layout orientation determines the direction in which text and graphics are drawn
*/
public static class WmfSetLayout implements WmfRecord {
/**
* A 16-bit unsigned integer that defines the layout of text and graphics.
* LAYOUT_LTR = 0x0000
* LAYOUT_RTL = 0x0001
* LAYOUT_BITMAPORIENTATIONPRESERVED = 0x0008
*/
int layout;
public WmfRecordType getRecordType() {
return WmfRecordType.setLayout;
}
@SuppressWarnings("unused")
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
layout = leis.readUShort();
// A 16-bit field that MUST be ignored.
int reserved = leis.readShort();
return 2*LittleEndianConsts.SHORT_SIZE;
}
}
/**
* The META_SETMAPMODE record defines the mapping mode in the playback device context.
* The mapping mode defines the unit of measure used to transform page-space units into
* device-space units, and also defines the orientation of the device's x and y axes.
*/
public static class WmfSetMapMode implements WmfRecord {
/**
* A 16-bit unsigned integer that defines the mapping mode.
*
* The MapMode defines how logical units are mapped to physical units;
* that is, assuming that the origins in both the logical and physical coordinate systems
* are at the same point on the drawing surface, what is the physical coordinate (x',y')
* that corresponds to logical coordinate (x,y).
*
* For example, suppose the mapping mode is MM_TEXT. Given the following definition of that
* mapping mode, and an origin (0,0) at the top left corner of the drawing surface, logical
* coordinate (4,5) would map to physical coordinate (4,5) in pixels.
*
* Now suppose the mapping mode is MM_LOENGLISH, with the same origin as the previous
* example. Given the following definition of that mapping mode, logical coordinate (4,-5)
* would map to physical coordinate (0.04,0.05) in inches.
*
* This MUST be one of the following:
*
* MM_TEXT (= 0x0001):
* Each logical unit is mapped to one device pixel.
* Positive x is to the right; positive y is down.
*
* MM_LOMETRIC (= 0x0002):
* Each logical unit is mapped to 0.1 millimeter.
* Positive x is to the right; positive y is up.
*
* MM_HIMETRIC (= 0x0003):
* Each logical unit is mapped to 0.01 millimeter.
* Positive x is to the right; positive y is up.
*
* MM_LOENGLISH (= 0x0004):
* Each logical unit is mapped to 0.01 inch.
* Positive x is to the right; positive y is up.
*
* MM_HIENGLISH (= 0x0005):
* Each logical unit is mapped to 0.001 inch.
* Positive x is to the right; positive y is up.
*
* MM_TWIPS (= 0x0006):
* Each logical unit is mapped to one twentieth (1/20) of a point.
* In printing, a point is 1/72 of an inch; therefore, 1/20 of a point is 1/1440 of an inch.
* This unit is also known as a "twip".
* Positive x is to the right; positive y is up.
*
* MM_ISOTROPIC (= 0x0007):
* Logical units are mapped to arbitrary device units with equally scaled axes;
* that is, one unit along the x-axis is equal to one unit along the y-axis.
* The META_SETWINDOWEXT and META_SETVIEWPORTEXT records specify the units and the
* orientation of the axes.
* The processing application SHOULD make adjustments as necessary to ensure the x and y
* units remain the same size. For example, when the window extent is set, the viewport
* SHOULD be adjusted to keep the units isotropic.
*
* MM_ANISOTROPIC (= 0x0008):
* Logical units are mapped to arbitrary units with arbitrarily scaled axes.
*/
int mapMode;
public WmfRecordType getRecordType() {
return WmfRecordType.setMapMode;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
mapMode = leis.readUShort();
return LittleEndianConsts.SHORT_SIZE;
}
}
/**
* The META_SETMAPPERFLAGS record defines the algorithm that the font mapper uses when it maps
* logical fonts to physical fonts.
*/
public static class WmfSetMapperFlags implements WmfRecord {
/**
* A 32-bit unsigned integer that defines whether the font mapper should attempt to
* match a font's aspect ratio to the current device's aspect ratio. If bit 0 is
* set, the mapper selects only matching fonts.
*/
long mapperValues;
public WmfRecordType getRecordType() {
return WmfRecordType.setMapperFlags;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
mapperValues = leis.readUInt();
return LittleEndianConsts.INT_SIZE;
}
}
/**
* The META_SETROP2 record defines the foreground raster operation mix mode in the playback device
* context. The foreground mix mode is the mode for combining pens and interiors of filled objects with
* foreground colors on the output surface.
*/
public static class WmfSetRop2 implements WmfRecord {
/**
* A 16-bit unsigned integer that defines the foreground binary raster
* operation mixing mode. This MUST be one of the values:
* R2_BLACK = 0x0001,
* R2_NOTMERGEPEN = 0x0002,
* R2_MASKNOTPEN = 0x0003,
* R2_NOTCOPYPEN = 0x0004,
* R2_MASKPENNOT = 0x0005,
* R2_NOT = 0x0006,
* R2_XORPEN = 0x0007,
* R2_NOTMASKPEN = 0x0008,
* R2_MASKPEN = 0x0009,
* R2_NOTXORPEN = 0x000A,
* R2_NOP = 0x000B,
* R2_MERGENOTPEN = 0x000C,
* R2_COPYPEN = 0x000D,
* R2_MERGEPENNOT = 0x000E,
* R2_MERGEPEN = 0x000F,
* R2_WHITE = 0x0010
*/
int drawMode;
public WmfRecordType getRecordType() {
return WmfRecordType.setRop2;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
drawMode = leis.readUShort();
return LittleEndianConsts.SHORT_SIZE;
}
}
/**
* The META_SETSTRETCHBLTMODE record defines the bitmap stretching mode in the playback device
* context.
*/
public static class WmfSetStretchBltMode implements WmfRecord {
/**
* A 16-bit unsigned integer that defines bitmap stretching mode.
* This MUST be one of the values:
* BLACKONWHITE = 0x0001,
* WHITEONBLACK = 0x0002,
* COLORONCOLOR = 0x0003,
* HALFTONE = 0x0004
*/
int setStretchBltMode;
public WmfRecordType getRecordType() {
return WmfRecordType.setStretchBltMode;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
setStretchBltMode = leis.readUShort();
return LittleEndianConsts.SHORT_SIZE;
}
}
/**
* The META_DIBCREATEPATTERNBRUSH record creates a Brush Object with a
* pattern specified by a DeviceIndependentBitmap (DIB) Object
*/
public static class WmfDibCreatePatternBrush implements WmfRecord {
/**
* A 16-bit unsigned integer that defines the brush style. The legal values for this
* field are defined as follows: if the value is not BS_PATTERN, BS_DIBPATTERNPT MUST be
* assumed.
*/
public static enum BrushStyle {
/**
* A brush that paints a single, constant color, either solid or dithered.
*/
BS_SOLID(0x0000),
/**
* A brush that does nothing. Using a BS_NULL brush in a graphics operation
* MUST have the same effect as using no brush at all.
*/
BS_NULL(0x0001),
/**
* A brush that paints a predefined simple pattern, or "hatch", onto a solid background.
*/
BS_HATCHED(0x0002),
/**
* A brush that paints a pattern defined by a bitmap, which MAY be a Bitmap16
* Object or a DeviceIndependentBitmap (DIB) Object.
*/
BS_PATTERN(0x0003),
/**
* Not supported
*/
BS_INDEXED(0x0004),
/**
* A pattern brush specified by a DIB.
*/
BS_DIBPATTERN(0x0005),
/**
* A pattern brush specified by a DIB.
*/
BS_DIBPATTERNPT(0x0006),
/**
* Not supported
*/
BS_PATTERN8X8(0x0007),
/**
* Not supported
*/
BS_DIBPATTERN8X8(0x0008),
/**
* Not supported
*/
BS_MONOPATTERN(0x0009);
int flag;
BrushStyle(int flag) {
this.flag = flag;
}
static BrushStyle valueOf(int flag) {
for (BrushStyle bs : values()) {
if (bs.flag == flag) return bs;
}
return null;
}
}
BrushStyle style;
/**
* A 16-bit unsigned integer that defines whether the Colors field of a DIB
* Object contains explicit RGB values, or indexes into a palette.
*
* If the Style field specifies BS_PATTERN, a ColorUsage value of DIB_RGB_COLORS MUST be
* used regardless of the contents of this field.
*
* If the Style field specified anything but BS_PATTERN, this field MUST be one of the values:
* DIB_RGB_COLORS = 0x0000,
* DIB_PAL_COLORS = 0x0001,
* DIB_PAL_INDICES = 0x0002
*/
int colorUsage;
WmfBitmapDib patternDib;
WmfBitmap16 pattern16;
public WmfRecordType getRecordType() {
return WmfRecordType.dibCreatePatternBrush;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
style = BrushStyle.valueOf(leis.readUShort());
colorUsage = leis.readUShort();
int size = 2*LittleEndianConsts.SHORT_SIZE;
switch (style) {
case BS_SOLID:
case BS_NULL:
case BS_DIBPATTERN:
case BS_DIBPATTERNPT:
case BS_HATCHED:
patternDib = new WmfBitmapDib();
size += patternDib.init(leis);
break;
case BS_PATTERN:
pattern16 = new WmfBitmap16();
size += pattern16.init(leis);
break;
case BS_INDEXED:
case BS_DIBPATTERN8X8:
case BS_MONOPATTERN:
case BS_PATTERN8X8:
throw new RuntimeException("pattern not supported");
}
return size;
}
}
/**
* The META_DELETEOBJECT record deletes an object, including Bitmap16, Brush,
* DeviceIndependentBitmap, Font, Palette, Pen, and Region. After the object is deleted,
* its index in the WMF Object Table is no longer valid but is available to be reused.
*/
public static class WmfDeleteObject implements WmfRecord {
/**
* A 16-bit unsigned integer used to index into the WMF Object Table to
get the object to be deleted.
*/
int objectIndex;
public WmfRecordType getRecordType() { return WmfRecordType.deleteObject; }
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
objectIndex = leis.readUShort();
return LittleEndianConsts.SHORT_SIZE;
}
}
public static class WmfCreatePatternBrush implements WmfRecord {
WmfBitmap16 pattern;
public WmfRecordType getRecordType() { return WmfRecordType.createPatternBrush; }
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
pattern = new WmfBitmap16(true);
return pattern.init(leis);
}
}
public static class WmfCreatePenIndirect implements WmfRecord {
/**
* A 16-bit unsigned integer that specifies the pen style.
* The value MUST be defined from the PenStyle Enumeration table.
*
* PS_COSMETIC = 0x0000,
* PS_ENDCAP_ROUND = 0x0000,
* PS_JOIN_ROUND = 0x0000,
* PS_SOLID = 0x0000,
* PS_DASH = 0x0001,
* PS_DOT = 0x0002,
* PS_DASHDOT = 0x0003,
* PS_DASHDOTDOT = 0x0004,
* PS_NULL = 0x0005,
* PS_INSIDEFRAME = 0x0006,
* PS_USERSTYLE = 0x0007,
* PS_ALTERNATE = 0x0008,
* PS_ENDCAP_SQUARE = 0x0100,
* PS_ENDCAP_FLAT = 0x0200,
* PS_JOIN_BEVEL = 0x1000,
* PS_JOIN_MITER = 0x2000
*/
int penStyle;
/**
* A 32-bit PointS Object that specifies a point for the object dimensions.
* The xcoordinate is the pen width. The y-coordinate is ignored.
*/
int xWidth, yWidth;
/**
* A 32-bit ColorRef Object that specifies the pen color value.
*/
WmfColorRef colorRef;
public WmfRecordType getRecordType() { return WmfRecordType.createPatternBrush; }
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
penStyle = leis.readUShort();
xWidth = leis.readShort();
yWidth = leis.readShort();
colorRef = new WmfColorRef();
int size = 3*LittleEndianConsts.SHORT_SIZE;
size += colorRef.init(leis);
return size;
}
}
}

View File

@ -1,33 +0,0 @@
package org.apache.poi.hwmf.record;
import java.io.IOException;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
/**
* The META_MOVETO record sets the output position in the playback device context to a specified
* point.
*/
public class WmfMoveTo implements WmfRecord {
/**
* A 16-bit signed integer that defines the y-coordinate, in logical units.
*/
int y;
/**
* A 16-bit signed integer that defines the x-coordinate, in logical units.
*/
int x;
public WmfRecordType getRecordType() {
return WmfRecordType.moveTo;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
y = leis.readShort();
x = leis.readShort();
return 2*LittleEndianConsts.SHORT_SIZE;
}
}

View File

@ -1,27 +0,0 @@
package org.apache.poi.hwmf.record;
import java.io.IOException;
import org.apache.poi.util.LittleEndianInputStream;
public class WmfNoArg {
protected static abstract class WmfNoArgParent implements WmfRecord {
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
return 0;
}
}
/**
* The META_SAVEDC record saves the playback device context for later retrieval.
*/
public static class WmfSaveDc extends WmfNoArgParent {
public WmfRecordType getRecordType() { return WmfRecordType.saveDc; }
}
/**
* The META_SETRELABS record is reserved and not supported.
*/
public static class WmfSetRelabs extends WmfNoArgParent {
public WmfRecordType getRecordType() { return WmfRecordType.setRelabs; }
}
}

View File

@ -4,25 +4,25 @@ public enum WmfRecordType {
eof(0x0000, null), eof(0x0000, null),
realizePalette(0x0035, WmfPalette.WmfRealizePalette.class), realizePalette(0x0035, WmfPalette.WmfRealizePalette.class),
setPalEntries(0x0037, WmfPalette.WmfSetPaletteEntries.class), setPalEntries(0x0037, WmfPalette.WmfSetPaletteEntries.class),
setBkMode(0x0102, WmfSetBkMode.class), setBkMode(0x0102, WmfMisc.WmfSetBkMode.class),
setMapMode(0x0103, WmfSetMapMode.class), setMapMode(0x0103, WmfMisc.WmfSetMapMode.class),
setRop2(0x0104, WmfSetRop2.class), setRop2(0x0104, WmfMisc.WmfSetRop2.class),
setRelabs(0x0105, WmfNoArg.WmfSetRelabs.class), setRelabs(0x0105, WmfMisc.WmfSetRelabs.class),
setPolyFillMode(0x0106, WmfFill.WmfSetPolyfillMode.class), setPolyFillMode(0x0106, WmfFill.WmfSetPolyfillMode.class),
setStretchBltMode(0x0107, WmfSetStretchBltMode.class), setStretchBltMode(0x0107, WmfMisc.WmfSetStretchBltMode.class),
setTextCharExtra(0x0108, WmfText.WmfSetTextCharExtra.class), setTextCharExtra(0x0108, WmfText.WmfSetTextCharExtra.class),
restoreDc(0x0127, WmfRestoreDc.class), restoreDc(0x0127, WmfMisc.WmfRestoreDc.class),
resizePalette(0x0139, WmfPalette.WmfResizePalette.class), resizePalette(0x0139, WmfPalette.WmfResizePalette.class),
dibCreatePatternBrush(0x0142, WmfDibCreatePatternBrush.class), dibCreatePatternBrush(0x0142, WmfMisc.WmfDibCreatePatternBrush.class),
setLayout(0x0149, WmfSetLayout.class), setLayout(0x0149, WmfMisc.WmfSetLayout.class),
setBkColor(0x0201, WmfSetBkColor.class), setBkColor(0x0201, WmfMisc.WmfSetBkColor.class),
setTextColor(0x0209, WmfText.WmfSetTextColor.class), setTextColor(0x0209, WmfText.WmfSetTextColor.class),
offsetViewportOrg(0x0211, WmfWindowing.WmfOffsetViewportOrg.class), offsetViewportOrg(0x0211, WmfWindowing.WmfOffsetViewportOrg.class),
lineTo(0x0213, WmfDraw.WmfLineTo.class), lineTo(0x0213, WmfDraw.WmfLineTo.class),
moveTo(0x0214, WmfMoveTo.class), moveTo(0x0214, WmfDraw.WmfMoveTo.class),
offsetClipRgn(0x0220, WmfWindowing.WmfOffsetClipRgn.class), offsetClipRgn(0x0220, WmfWindowing.WmfOffsetClipRgn.class),
fillRegion(0x0228, WmfFill.WmfFillRegion.class), fillRegion(0x0228, WmfFill.WmfFillRegion.class),
setMapperFlags(0x0231, WmfSetMapperFlags.class), setMapperFlags(0x0231, WmfMisc.WmfSetMapperFlags.class),
selectPalette(0x0234, WmfPalette.WmfSelectPalette.class), selectPalette(0x0234, WmfPalette.WmfSelectPalette.class),
polygon(0x0324, WmfDraw.WmfPolygon.class), polygon(0x0324, WmfDraw.WmfPolygon.class),
polyline(0x0325, WmfDraw.WmfPolyline.class), polyline(0x0325, WmfDraw.WmfPolyline.class),
@ -47,7 +47,7 @@ public enum WmfRecordType {
setPixel(0x041f, WmfDraw.WmfSetPixel.class), setPixel(0x041f, WmfDraw.WmfSetPixel.class),
roundRect(0x061c, WmfDraw.WmfRoundRect.class), roundRect(0x061c, WmfDraw.WmfRoundRect.class),
patBlt(0x061d, WmfFill.WmfPatBlt.class), patBlt(0x061d, WmfFill.WmfPatBlt.class),
saveDc(0x001e, WmfNoArg.WmfSaveDc.class), saveDc(0x001e, WmfMisc.WmfSaveDc.class),
pie(0x081a, WmfDraw.WmfPie.class), pie(0x081a, WmfDraw.WmfPie.class),
stretchBlt(0x0b23, WmfFill.WmfStretchBlt.class), stretchBlt(0x0b23, WmfFill.WmfStretchBlt.class),
escape(0x0626, WmfEscape.class), escape(0x0626, WmfEscape.class),
@ -62,12 +62,12 @@ public enum WmfRecordType {
extTextOut(0x0a32, WmfText.WmfExtTextOut.class), extTextOut(0x0a32, WmfText.WmfExtTextOut.class),
setDibToDev(0x0d33, WmfFill.WmfSetDibToDev.class), setDibToDev(0x0d33, WmfFill.WmfSetDibToDev.class),
dibBitBlt(0x0940, WmfFill.WmfDibBitBlt.class), dibBitBlt(0x0940, WmfFill.WmfDibBitBlt.class),
dibStretchBlt(0x0b41, null), dibStretchBlt(0x0b41, WmfFill.WmfDibStretchBlt.class),
stretchDib(0x0f43, null), stretchDib(0x0f43, WmfFill.WmfStretchDib.class),
deleteObject(0x01f0, null), deleteObject(0x01f0, WmfMisc.WmfDeleteObject.class),
createPalette(0x00f7, WmfPalette.WmfCreatePalette.class), createPalette(0x00f7, WmfPalette.WmfCreatePalette.class),
createPatternBrush(0x01f9, null), createPatternBrush(0x01f9, WmfMisc.WmfCreatePatternBrush.class),
createPenIndirect(0x02fa, null), createPenIndirect(0x02fa, WmfMisc.WmfCreatePenIndirect.class),
createFontIndirect(0x02fb, null), createFontIndirect(0x02fb, null),
createBrushIndirect(0x02fc, null), createBrushIndirect(0x02fc, null),
createRegion(0x06ff, null); createRegion(0x06ff, null);

View File

@ -1,29 +0,0 @@
package org.apache.poi.hwmf.record;
import java.io.IOException;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
/**
* The META_RESTOREDC record restores the playback device context from a previously saved device
* context.
*/
public class WmfRestoreDc implements WmfRecord {
/**
* nSavedDC (2 bytes): A 16-bit signed integer that defines the saved state to be restored. If this
* member is positive, nSavedDC represents a specific instance of the state to be restored. If
* this member is negative, nSavedDC represents an instance relative to the current state.
*/
int nSavedDC;
public WmfRecordType getRecordType() {
return WmfRecordType.restoreDc;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
nSavedDC = leis.readShort();
return LittleEndianConsts.SHORT_SIZE;
}
}

View File

@ -1,23 +0,0 @@
package org.apache.poi.hwmf.record;
import java.io.IOException;
import org.apache.poi.util.LittleEndianInputStream;
/**
* The META_SETBKCOLOR record sets the background color in the playback device context to a
* specified color, or to the nearest physical color if the device cannot represent the specified color.
*/
public class WmfSetBkColor implements WmfRecord {
WmfColorRef colorRef;
public WmfRecordType getRecordType() {
return WmfRecordType.setBkColor;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
WmfColorRef colorRef = new WmfColorRef();
return colorRef.init(leis);
}
}

View File

@ -1,29 +0,0 @@
package org.apache.poi.hwmf.record;
import java.io.IOException;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
/**
* The META_SETBKMODE record defines the background raster operation mix mode in the playback
* device context. The background mix mode is the mode for combining pens, text, hatched brushes,
* and interiors of filled objects with background colors on the output surface.
*/
public class WmfSetBkMode implements WmfRecord {
/**
* A 16-bit unsigned integer that defines background mix mode.
* This MUST be either TRANSPARENT = 0x0001 or OPAQUE = 0x0002
*/
int bkMode;
public WmfRecordType getRecordType() {
return WmfRecordType.setBkMode;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
bkMode = leis.readUShort();
return LittleEndianConsts.SHORT_SIZE;
}
}

View File

@ -1,33 +0,0 @@
package org.apache.poi.hwmf.record;
import java.io.IOException;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
/**
* The META_SETLAYOUT record defines the layout orientation in the playback device context.
* The layout orientation determines the direction in which text and graphics are drawn
*/
public class WmfSetLayout implements WmfRecord {
/**
* A 16-bit unsigned integer that defines the layout of text and graphics.
* LAYOUT_LTR = 0x0000
* LAYOUT_RTL = 0x0001
* LAYOUT_BITMAPORIENTATIONPRESERVED = 0x0008
*/
int layout;
public WmfRecordType getRecordType() {
return WmfRecordType.setLayout;
}
@SuppressWarnings("unused")
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
layout = leis.readUShort();
// A 16-bit field that MUST be ignored.
int reserved = leis.readShort();
return 2*LittleEndianConsts.SHORT_SIZE;
}
}

View File

@ -1,81 +0,0 @@
package org.apache.poi.hwmf.record;
import java.io.IOException;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
/**
* The META_SETMAPMODE record defines the mapping mode in the playback device context.
* The mapping mode defines the unit of measure used to transform page-space units into
* device-space units, and also defines the orientation of the device's x and y axes.
*/
public class WmfSetMapMode implements WmfRecord {
/**
* A 16-bit unsigned integer that defines the mapping mode.
*
* The MapMode defines how logical units are mapped to physical units;
* that is, assuming that the origins in both the logical and physical coordinate systems
* are at the same point on the drawing surface, what is the physical coordinate (x',y')
* that corresponds to logical coordinate (x,y).
*
* For example, suppose the mapping mode is MM_TEXT. Given the following definition of that
* mapping mode, and an origin (0,0) at the top left corner of the drawing surface, logical
* coordinate (4,5) would map to physical coordinate (4,5) in pixels.
*
* Now suppose the mapping mode is MM_LOENGLISH, with the same origin as the previous
* example. Given the following definition of that mapping mode, logical coordinate (4,-5)
* would map to physical coordinate (0.04,0.05) in inches.
*
* This MUST be one of the following:
*
* MM_TEXT (= 0x0001):
* Each logical unit is mapped to one device pixel.
* Positive x is to the right; positive y is down.
*
* MM_LOMETRIC (= 0x0002):
* Each logical unit is mapped to 0.1 millimeter.
* Positive x is to the right; positive y is up.
*
* MM_HIMETRIC (= 0x0003):
* Each logical unit is mapped to 0.01 millimeter.
* Positive x is to the right; positive y is up.
*
* MM_LOENGLISH (= 0x0004):
* Each logical unit is mapped to 0.01 inch.
* Positive x is to the right; positive y is up.
*
* MM_HIENGLISH (= 0x0005):
* Each logical unit is mapped to 0.001 inch.
* Positive x is to the right; positive y is up.
*
* MM_TWIPS (= 0x0006):
* Each logical unit is mapped to one twentieth (1/20) of a point.
* In printing, a point is 1/72 of an inch; therefore, 1/20 of a point is 1/1440 of an inch.
* This unit is also known as a "twip".
* Positive x is to the right; positive y is up.
*
* MM_ISOTROPIC (= 0x0007):
* Logical units are mapped to arbitrary device units with equally scaled axes;
* that is, one unit along the x-axis is equal to one unit along the y-axis.
* The META_SETWINDOWEXT and META_SETVIEWPORTEXT records specify the units and the
* orientation of the axes.
* The processing application SHOULD make adjustments as necessary to ensure the x and y
* units remain the same size. For example, when the window extent is set, the viewport
* SHOULD be adjusted to keep the units isotropic.
*
* MM_ANISOTROPIC (= 0x0008):
* Logical units are mapped to arbitrary units with arbitrarily scaled axes.
*/
int mapMode;
public WmfRecordType getRecordType() {
return WmfRecordType.setMapMode;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
mapMode = leis.readUShort();
return LittleEndianConsts.SHORT_SIZE;
}
}

View File

@ -1,29 +0,0 @@
package org.apache.poi.hwmf.record;
import java.io.IOException;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
/**
* The META_SETMAPPERFLAGS record defines the algorithm that the font mapper uses when it maps
* logical fonts to physical fonts.
*/
public class WmfSetMapperFlags implements WmfRecord {
/**
* A 32-bit unsigned integer that defines whether the font mapper should attempt to
* match a font's aspect ratio to the current device's aspect ratio. If bit 0 is
* set, the mapper selects only matching fonts.
*/
long mapperValues;
public WmfRecordType getRecordType() {
return WmfRecordType.setMapperFlags;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
mapperValues = leis.readUInt();
return LittleEndianConsts.INT_SIZE;
}
}

View File

@ -1,45 +0,0 @@
package org.apache.poi.hwmf.record;
import java.io.IOException;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
/**
* The META_SETROP2 record defines the foreground raster operation mix mode in the playback device
* context. The foreground mix mode is the mode for combining pens and interiors of filled objects with
* foreground colors on the output surface.
*/
public class WmfSetRop2 implements WmfRecord {
/**
* A 16-bit unsigned integer that defines the foreground binary raster
* operation mixing mode. This MUST be one of the values:
* R2_BLACK = 0x0001,
* R2_NOTMERGEPEN = 0x0002,
* R2_MASKNOTPEN = 0x0003,
* R2_NOTCOPYPEN = 0x0004,
* R2_MASKPENNOT = 0x0005,
* R2_NOT = 0x0006,
* R2_XORPEN = 0x0007,
* R2_NOTMASKPEN = 0x0008,
* R2_MASKPEN = 0x0009,
* R2_NOTXORPEN = 0x000A,
* R2_NOP = 0x000B,
* R2_MERGENOTPEN = 0x000C,
* R2_COPYPEN = 0x000D,
* R2_MERGEPENNOT = 0x000E,
* R2_MERGEPEN = 0x000F,
* R2_WHITE = 0x0010
*/
int drawMode;
public WmfRecordType getRecordType() {
return WmfRecordType.setRop2;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
drawMode = leis.readUShort();
return LittleEndianConsts.SHORT_SIZE;
}
}

View File

@ -1,32 +0,0 @@
package org.apache.poi.hwmf.record;
import java.io.IOException;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
/**
* The META_SETSTRETCHBLTMODE record defines the bitmap stretching mode in the playback device
* context.
*/
public class WmfSetStretchBltMode implements WmfRecord {
/**
* A 16-bit unsigned integer that defines bitmap stretching mode.
* This MUST be one of the values:
* BLACKONWHITE = 0x0001,
* WHITEONBLACK = 0x0002,
* COLORONCOLOR = 0x0003,
* HALFTONE = 0x0004
*/
int setStretchBltMode;
public WmfRecordType getRecordType() {
return WmfRecordType.setStretchBltMode;
}
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
setStretchBltMode = leis.readUShort();
return LittleEndianConsts.SHORT_SIZE;
}
}