poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1721078 [2/3] - in /poi/trunk/src/scratchpad: src/org/apache/poi/hwmf/ src/org/apache/poi/hwmf/record/ src/org/apache/poi/hwmf/usermodel/ testcases/org/apache/poi/hwmf/
Date Mon, 21 Dec 2015 01:26:39 GMT
Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfFill.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfFill.java?rev=1721078&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfFill.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfFill.java Mon Dec 21 01:26:39 2015
@@ -0,0 +1,794 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hwmf.record;
+
+import java.io.IOException;
+
+import org.apache.poi.util.LittleEndianConsts;
+import org.apache.poi.util.LittleEndianInputStream;
+
+public class HwmfFill {
+    /**
+     * The META_FILLREGION record fills a region using a specified brush.
+     */
+    public static class WmfFillRegion implements HwmfRecord {
+        
+        /**
+         * A 16-bit unsigned integer used to index into the WMF Object Table to get
+         * the region to be filled.
+         */
+        int region;
+
+        /**
+         * A 16-bit unsigned integer used to index into the WMF Object Table to get the
+         * brush to use for filling the region.
+         */
+        int brush;
+        
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.fillRegion;
+        }
+        
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            region = leis.readUShort();
+            brush = leis.readUShort();
+            return 2*LittleEndianConsts.SHORT_SIZE;
+        }
+    }
+
+    /**
+     * The META_PAINTREGION record paints the specified region by using the brush that is
+     * defined in the playback device context.
+     */
+    public static class WmfPaintRegion implements HwmfRecord {
+        
+        /**
+         * A 16-bit unsigned integer used to index into the WMF Object Table to get
+         * the region to be painted.
+         */
+        int region;
+
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.paintRegion;
+        }
+        
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            region = leis.readUShort();
+            return LittleEndianConsts.SHORT_SIZE;
+        }
+    }
+    
+    
+    /**
+     * The META_FLOODFILL record fills an area of the output surface with the brush that
+     * is defined in the playback device context.
+     */
+    public static class WmfFloodFill implements HwmfRecord {
+        
+        /**
+         * A 32-bit ColorRef Object that defines the color value.
+         */
+        HwmfColorRef colorRef;
+        /**
+         * A 16-bit signed integer that defines the y-coordinate, in logical units, of the
+         * point where filling is to start.
+         */
+        int yStart;
+        /**
+         * A 16-bit signed integer that defines the x-coordinate, in logical units, of the
+         * point where filling is to start.
+         */
+        int xStart;
+        
+        
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.floodFill;
+        }
+        
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            colorRef = new HwmfColorRef();
+            int size = colorRef.init(leis);
+            yStart = leis.readShort();
+            xStart = leis.readShort();
+            return size+2*LittleEndianConsts.SHORT_SIZE;
+        }
+    }
+
+    /**
+     * The META_SETPOLYFILLMODE record sets polygon fill mode in the playback device context for
+     * graphics operations that fill polygons.
+     */
+    public static class WmfSetPolyfillMode implements HwmfRecord {
+        
+        /**
+         * A 16-bit unsigned integer that defines polygon fill mode.
+         * This MUST be one of the values: ALTERNATE = 0x0001, WINDING = 0x0002
+         */
+        int polyFillMode;
+        
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.setPolyFillMode;
+        }
+        
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            polyFillMode = leis.readUShort();
+            return LittleEndianConsts.SHORT_SIZE;
+        }
+    }
+
+
+    /**
+     * The META_EXTFLOODFILL record fills an area with the brush that is defined in
+     * the playback device context.
+     */
+    public static class WmfExtFloodFill implements HwmfRecord {
+        
+        /**
+         * A 16-bit unsigned integer that defines the fill operation to be performed. This
+         * member MUST be one of the values in the FloodFill Enumeration table:
+         * 
+         * FLOODFILLBORDER = 0x0000:
+         * The fill area is bounded by the color specified by the Color member.
+         * This style is identical to the filling performed by the META_FLOODFILL record.
+         * 
+         * FLOODFILLSURFACE = 0x0001:
+         * The fill area is bounded by the color that is specified by the Color member.
+         * Filling continues outward in all directions as long as the color is encountered.
+         * This style is useful for filling areas with multicolored boundaries.
+         */
+        int mode;
+        
+        /**
+         * A 32-bit ColorRef Object that defines the color value.
+         */
+        HwmfColorRef colorRef;
+        
+        /**
+         * A 16-bit signed integer that defines the y-coordinate, in logical units, of the point
+         * to be set.
+         */
+        int y;
+        
+        /**
+         * A 16-bit signed integer that defines the x-coordinate, in logical units, of the point
+         * to be set.
+         */
+        int x;  
+        
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.extFloodFill;
+        }
+        
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            mode = leis.readUShort();
+            colorRef = new HwmfColorRef();
+            int size = colorRef.init(leis);
+            y = leis.readShort();
+            x = leis.readShort();
+            return size+3*LittleEndianConsts.SHORT_SIZE;
+        }
+    }
+
+    /**
+     * The META_INVERTREGION record draws a region in which the colors are inverted.
+     */
+    public static class WmfInvertRegion implements HwmfRecord {
+        
+        /**
+         * A 16-bit unsigned integer used to index into the WMF Object Table to get
+         * the region to be inverted.
+         */
+        int region;
+        
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.invertRegion;
+        }
+        
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            region = leis.readUShort();
+            return LittleEndianConsts.SHORT_SIZE;
+        }
+    }
+    
+
+    /**
+     * The META_PATBLT record paints a specified rectangle using the brush that is defined in the playback
+     * device context. The brush color and the surface color or colors are combined using the specified
+     * raster operation.
+     */
+    public static class WmfPatBlt implements HwmfRecord {
+        
+        /**
+         * A 32-bit unsigned integer that defines the raster operation code.
+         * This code MUST be one of the values in the Ternary Raster Operation enumeration table.
+         */
+        HwmfTernaryRasterOp rasterOperation;
+        
+        /**
+         * A 16-bit signed integer that defines the height, in logical units, of the rectangle.
+         */
+        int height;
+        
+        /**
+         * A 16-bit signed integer that defines the width, in logical units, of the rectangle.
+         */
+        int width;
+        
+        /**
+         * A 16-bit signed integer that defines the y-coordinate, in logical units, of the
+         * upper-left corner of the rectangle to be filled.
+         */
+        int yLeft;
+        
+        /**
+         * A 16-bit signed integer that defines the x-coordinate, in logical units, of the
+         * upper-left corner of the rectangle to be filled.
+         */
+        int xLeft;
+        
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.patBlt;
+        }
+        
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            int rasterOpIndex = leis.readUShort();
+            int rasterOpCode = leis.readUShort();
+
+            rasterOperation = HwmfTernaryRasterOp.fromOpIndex(rasterOpIndex);
+            assert(rasterOpCode == rasterOperation.opCode);
+            
+            height = leis.readShort();
+            width = leis.readShort();
+            yLeft = leis.readShort();
+            xLeft = leis.readShort();
+
+            return 6*LittleEndianConsts.SHORT_SIZE;
+        }
+    }
+
+    /**
+     */
+    public static class WmfStretchBlt implements HwmfRecord {
+        /**
+         * 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
+         */
+        HwmfTernaryRasterOp 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 Bitmap16 Object that defines source image content.
+         * This object MUST be specified, even if the raster operation does not require a source.
+         */
+        HwmfBitmap16 target;
+        
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.stretchBlt;
+        }
+        
+        
+        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 = HwmfTernaryRasterOp.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 HwmfBitmap16();
+                size += target.init(leis);
+            }
+            
+            return size;
+        }
+    }
+
+    /**
+     * 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 HwmfRecord {
+        /**
+         * 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.
+         */
+        HwmfTernaryRasterOp 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.
+         */
+        HwmfBitmapDib dib;
+        
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.stretchDib;
+        }
+        
+        
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            int rasterOpIndex = leis.readUShort();
+            int rasterOpCode = leis.readUShort();
+            
+            rasterOperation = HwmfTernaryRasterOp.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 HwmfBitmapDib();
+            size += dib.init(leis);
+            return size;
+        }        
+    }
+    
+    public static class WmfBitBlt implements HwmfRecord {
+
+        /**
+         * 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.
+         */
+        HwmfTernaryRasterOp rasterOperation;
+        
+        /**
+         * 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 source and 
+        destination rectangles.
+         */
+        int height;
+        /**
+         * A 16-bit signed integer that defines the width, in logical units, of the source and destination 
+        rectangles.
+         */
+        int width;
+        /**
+         * 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 Bitmap16 Object that defines source image content.
+         * This object MUST be specified, even if the raster operation does not require a source.
+         */
+        HwmfBitmap16 target;
+
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.bitBlt;
+        }
+        
+        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 = HwmfTernaryRasterOp.fromOpIndex(rasterOpIndex);
+            assert(rasterOpCode == rasterOperation.opCode);
+
+            ySrc = leis.readShort();
+            xSrc = leis.readShort();
+
+            size = 4*LittleEndianConsts.SHORT_SIZE;
+            
+            if (!hasBitmap) {
+                @SuppressWarnings("unused")
+                int reserved = leis.readShort();
+                size += LittleEndianConsts.SHORT_SIZE;
+            }
+            
+            height = leis.readShort();
+            width = leis.readShort();
+            yDest = leis.readShort();
+            xDest = leis.readShort();
+
+            size += 4*LittleEndianConsts.SHORT_SIZE;
+            if (hasBitmap) {
+                target = new HwmfBitmap16();
+                size += target.init(leis);
+            }
+            
+            return size;
+        }
+    }
+
+
+    /**
+     * The META_SETDIBTODEV record sets a block of pixels in the playback device context
+     * using deviceindependent color data.
+     * The source of the color data is a DIB
+     */
+    public static class WmfSetDibToDev implements HwmfRecord {
+
+        /**
+         * A 16-bit unsigned integer that defines whether the Colors field of the
+         * DIB contains explicit RGB values or indexes into a palette.
+         * This MUST be one of the values in the ColorUsage Enumeration:
+         * DIB_RGB_COLORS = 0x0000,
+         * DIB_PAL_COLORS = 0x0001,
+         * DIB_PAL_INDICES = 0x0002
+         */
+        int colorUsage;  
+        /**
+         * A 16-bit unsigned integer that defines the number of scan lines in the source.
+         */
+        int scanCount;
+        /**
+         * A 16-bit unsigned integer that defines the starting scan line in the source.
+         */
+        int startScan;  
+        /**
+         * A 16-bit unsigned integer that defines the y-coordinate, in logical units, of the
+         * source rectangle.
+         */
+        int yDib;  
+        /**
+         * A 16-bit unsigned integer that defines the x-coordinate, in logical units, of the
+         * source rectangle.
+         */
+        int xDib;  
+        /**
+         * A 16-bit unsigned integer that defines the height, in logical units, of the
+         * source and destination rectangles.
+         */
+        int height;
+        /**
+         * A 16-bit unsigned integer that defines the width, in logical units, of the
+         * source and destination rectangles.
+         */
+        int width;
+        /**
+         * A 16-bit unsigned integer that defines the y-coordinate, in logical units, of the
+         * upper-left corner of the destination rectangle.
+         */
+        int yDest;
+        /**
+         * A 16-bit unsigned 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 is the source of the color data.
+         */
+        HwmfBitmapDib dib;        
+        
+        
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.setDibToDev;
+        }
+        
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            colorUsage = leis.readUShort();
+            scanCount = leis.readUShort();
+            startScan = leis.readUShort();
+            yDib = leis.readUShort();
+            xDib = leis.readUShort();
+            height = leis.readUShort();
+            width = leis.readUShort();
+            yDest = leis.readUShort();
+            xDest = leis.readUShort();
+            
+            int size = 9*LittleEndianConsts.SHORT_SIZE;
+            dib = new HwmfBitmapDib();
+            size += dib.init(leis);
+            
+            return size;
+        }        
+    }
+
+
+    public static class WmfDibBitBlt implements HwmfRecord {
+
+        /**
+         * 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.
+         */
+        HwmfTernaryRasterOp rasterOperation;  
+        /**
+         * 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 source and 
+         * destination rectangles.
+         */
+        int height;
+        /**
+         * A 16-bit signed integer that defines the width, in logical units, of the source and destination
+         * rectangles.
+         */
+        int width;
+        /**
+         * 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.
+         */
+        HwmfBitmapDib target;
+        
+        
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.dibBitBlt;
+        }
+        
+        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 = HwmfTernaryRasterOp.fromOpIndex(rasterOpIndex);
+            assert(rasterOpCode == rasterOperation.opCode);
+
+            ySrc = leis.readShort();
+            xSrc = leis.readShort();
+            size = 4*LittleEndianConsts.SHORT_SIZE;
+            if (!hasBitmap) {
+                @SuppressWarnings("unused")
+                int reserved = leis.readShort();
+                size += LittleEndianConsts.SHORT_SIZE;
+            }
+            height = leis.readShort();
+            width = leis.readShort();
+            yDest = leis.readShort();
+            xDest = leis.readShort();
+            
+            size += 4*LittleEndianConsts.SHORT_SIZE;
+            if (hasBitmap) {
+                target = new HwmfBitmapDib();
+                size += target.init(leis);
+            }
+            
+            return size;
+        }
+    }
+
+    public static class WmfDibStretchBlt implements HwmfRecord {
+        /**
+         * 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.
+         */
+        HwmfTernaryRasterOp 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.
+         */
+        HwmfBitmapDib target;
+        
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.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 = HwmfTernaryRasterOp.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 HwmfBitmapDib();
+                size += target.init(leis);
+            }
+            
+            return size;
+        }
+    }
+}

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfFont.java?rev=1721078&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfFont.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfFont.java Mon Dec 21 01:26:39 2015
@@ -0,0 +1,498 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hwmf.record;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+import org.apache.poi.util.LittleEndianInputStream;
+
+/**
+ * The Font object specifies the attributes of a logical font
+ */
+public class HwmfFont {
+    public enum WmfCharset {
+        /** Specifies the English character set. */
+        ANSI_CHARSET(0x00000000),
+        /**
+         * Specifies a character set based on the current system locale;
+         * for example, when the system locale is United States English,
+         * the default character set is ANSI_CHARSET.
+         */
+        DEFAULT_CHARSET(0x00000001),
+        /** Specifies a character set of symbols. */
+        SYMBOL_CHARSET(0x00000002),
+        /** Specifies the Apple Macintosh character set. */
+        MAC_CHARSET(0x0000004D),
+        /** Specifies the Japanese character set. */
+        SHIFTJIS_CHARSET(0x00000080),
+        /** Also spelled "Hangeul". Specifies the Hangul Korean character set. */
+        HANGUL_CHARSET(0x00000081),
+        /** Also spelled "Johap". Specifies the Johab Korean character set. */
+        JOHAB_CHARSET(0x00000082),
+        /** Specifies the "simplified" Chinese character set for People's Republic of China. */
+        GB2312_CHARSET(0x00000086),
+        /**
+         * Specifies the "traditional" Chinese character set, used mostly in
+         * Taiwan and in the Hong Kong and Macao Special Administrative Regions.
+         */
+        CHINESEBIG5_CHARSET(0x00000088),
+        /** Specifies the Greek character set. */
+        GREEK_CHARSET(0x000000A1),
+        /** Specifies the Turkish character set. */
+        TURKISH_CHARSET(0x000000A2),
+        /** Specifies the Vietnamese character set. */
+        VIETNAMESE_CHARSET(0x000000A3),
+        /** Specifies the Hebrew character set. */
+        HEBREW_CHARSET(0x000000B1),
+        /** Specifies the Arabic character set. */
+        ARABIC_CHARSET(0x000000B2),
+        /** Specifies the Baltic (Northeastern European) character set. */
+        BALTIC_CHARSET(0x000000BA),
+        /** Specifies the Russian Cyrillic character set. */
+        RUSSIAN_CHARSET(0x000000CC),
+        /** Specifies the Thai character set. */
+        THAI_CHARSET(0x000000DE),
+        /** Specifies a Eastern European character set. */
+        EASTEUROPE_CHARSET(0x000000EE),
+        /**
+         * Specifies a mapping to one of the OEM code pages,
+         * according to the current system locale setting.
+         */
+        OEM_CHARSET(0x000000FF);
+
+        int flag;
+        WmfCharset(int flag) {
+            this.flag = flag;
+        }
+
+        static WmfCharset valueOf(int flag) {
+            for (WmfCharset cs : values()) {
+                if (cs.flag == flag) return cs;
+            }
+            return null;
+        }
+    }
+
+    /**
+     * The output precision defines how closely the output must match the requested font's height,
+     * width, character orientation, escapement, pitch, and font type.
+     */
+    public enum WmfOutPrecision {
+        /**
+         * A value that specifies default behavior.
+         */
+        OUT_DEFAULT_PRECIS(0x00000000),
+        /**
+         * A value that is returned when rasterized fonts are enumerated.
+         */
+        OUT_STRING_PRECIS(0x00000001),
+        /**
+         * A value that is returned when TrueType and other outline fonts, and
+         * vector fonts are enumerated.
+         */
+        OUT_STROKE_PRECIS(0x00000003),
+        /**
+         * A value that specifies the choice of a TrueType font when the system
+         * contains multiple fonts with the same name.
+         */
+        OUT_TT_PRECIS(0x00000004),
+        /**
+         * A value that specifies the choice of a device font when the system
+         * contains multiple fonts with the same name.
+         */
+        OUT_DEVICE_PRECIS(0x00000005),
+        /**
+         * A value that specifies the choice of a rasterized font when the system
+         * contains multiple fonts with the same name.
+         */
+        OUT_RASTER_PRECIS(0x00000006),
+        /**
+         * A value that specifies the requirement for only TrueType fonts. If
+         * there are no TrueType fonts installed in the system, default behavior is specified.
+         */
+        OUT_TT_ONLY_PRECIS(0x00000007),
+        /**
+         * A value that specifies the requirement for TrueType and other outline fonts.
+         */
+        OUT_OUTLINE_PRECIS (0x00000008),
+        /**
+         * A value that specifies a preference for TrueType and other outline fonts.
+         */
+        OUT_SCREEN_OUTLINE_PRECIS (0x00000009),
+        /**
+         * A value that specifies a requirement for only PostScript fonts. If there
+         * are no PostScript fonts installed in the system, default behavior is specified.
+         */
+        OUT_PS_ONLY_PRECIS (0x0000000A);
+
+
+        int flag;
+        WmfOutPrecision(int flag) {
+            this.flag = flag;
+        }
+
+        static WmfOutPrecision valueOf(int flag) {
+            for (WmfOutPrecision op : values()) {
+                if (op.flag == flag) return op;
+            }
+            return null;
+        }
+    }
+
+    /**
+     * ClipPrecision Flags specify clipping precision, which defines how to clip characters that are
+     * partially outside a clipping region. These flags can be combined to specify multiple options.
+     */
+    public enum WmfClipPrecision {
+
+        /**
+         * Specifies that default clipping MUST be used.
+         */
+        CLIP_DEFAULT_PRECIS (0x00000000),
+
+        /**
+         * This value SHOULD NOT be used.
+         */
+        CLIP_CHARACTER_PRECIS (0x00000001),
+
+        /**
+         * This value MAY be returned when enumerating rasterized, TrueType and vector fonts.
+         */
+        CLIP_STROKE_PRECIS (0x00000002),
+
+        /**
+         * This value is used to control font rotation, as follows:
+         * If set, the rotation for all fonts SHOULD be determined by the orientation of the coordinate system;
+         * that is, whether the orientation is left-handed or right-handed.
+         *
+         * If clear, device fonts SHOULD rotate counterclockwise, but the rotation of other fonts
+         * SHOULD be determined by the orientation of the coordinate system.
+         */
+        CLIP_LH_ANGLES (0x00000010),
+
+        /**
+         * This value SHOULD NOT be used.
+         */
+        CLIP_TT_ALWAYS (0x00000020),
+
+        /**
+         * This value specifies that font association SHOULD< be turned off.
+         */
+        CLIP_DFA_DISABLE (0x00000040),
+
+        /**
+         * This value specifies that font embedding MUST be used to render document content;
+         * embedded fonts are read-only.
+         */
+        CLIP_EMBEDDED (0x00000080);
+
+
+        int flag;
+        WmfClipPrecision(int flag) {
+            this.flag = flag;
+        }
+
+        static WmfClipPrecision valueOf(int flag) {
+            for (WmfClipPrecision cp : values()) {
+                if (cp.flag == flag) return cp;
+            }
+            return null;
+        }
+    }
+
+    /**
+     * The output quality defines how carefully to attempt to match the logical font attributes to those of an actual
+     * physical font.
+     */
+    public enum WmfFontQuality {
+        /**
+         * Specifies that the character quality of the font does not matter, so DRAFT_QUALITY can be used.
+         */
+        DEFAULT_QUALITY (0x00),
+        
+        /**
+         * Specifies that the character quality of the font is less important than the
+         * matching of logical attribuetes. For rasterized fonts, scaling SHOULD be enabled, which
+         * means that more font sizes are available.
+         */
+        DRAFT_QUALITY (0x01),
+        
+        /**
+         * Specifies that the character quality of the font is more important than the
+         * matching of logical attributes. For rasterized fonts, scaling SHOULD be disabled, and the font
+         * closest in size SHOULD be chosen.
+         */
+        PROOF_QUALITY (0x02),
+        
+        /**
+         * Specifies that anti-aliasing SHOULD NOT be used when rendering text.
+         */
+        NONANTIALIASED_QUALITY (0x03),
+        
+        /**
+         * Specifies that anti-aliasing SHOULD be used when rendering text, if the font supports it.
+         */
+        ANTIALIASED_QUALITY (0x04),
+        
+        /**
+         * Specifies that ClearType anti-aliasing SHOULD be used when rendering text, if the font supports it.
+         * 
+         * Fonts that do not support ClearType anti-aliasing include type 1 fonts, PostScript fonts,
+         * OpenType fonts without TrueType outlines, rasterized fonts, vector fonts, and device fonts.
+         */
+        CLEARTYPE_QUALITY (0x05);
+        
+        int flag;
+        WmfFontQuality(int flag) {
+            this.flag = flag;
+        }
+
+        static WmfFontQuality valueOf(int flag) {
+            for (WmfFontQuality fq : values()) {
+                if (fq.flag == flag) return fq;
+            }
+            return null;
+        }
+    }
+    
+    /**
+     * A property of a font that describes its general appearance.
+     */
+    public enum WmfFontFamilyClass {
+        /**
+         * The default font is specified, which is implementation-dependent.
+         */
+        FF_DONTCARE (0x00),
+        /**
+         * Fonts with variable stroke widths, which are proportional to the actual widths of
+         * the glyphs, and which have serifs. "MS Serif" is an example.
+         */
+        FF_ROMAN (0x01),
+        /**
+         * Fonts with variable stroke widths, which are proportional to the actual widths of the
+         * glyphs, and which do not have serifs. "MS Sans Serif" is an example.
+         */
+        FF_SWISS (0x02),
+        /**
+         * Fonts with constant stroke width, with or without serifs. Fixed-width fonts are
+         * usually modern. "Pica", "Elite", and "Courier New" are examples.
+         */
+        FF_MODERN (0x03),
+        /**
+         * Fonts designed to look like handwriting. "Script" and "Cursive" are examples.
+         */
+        FF_SCRIPT (0x04),
+        /**
+         * Novelty fonts. "Old English" is an example.
+         */
+        FF_DECORATIVE (0x05);
+        
+        int flag;
+        WmfFontFamilyClass(int flag) {
+            this.flag = flag;
+        }
+
+        static WmfFontFamilyClass valueOf(int flag) {
+            for (WmfFontFamilyClass ff : values()) {
+                if (ff.flag == flag) return ff;
+            }
+            return null;
+        }
+    }
+
+    /**
+     * A property of a font that describes the pitch, of the characters.
+     */
+    public enum WmfFontPitch {
+        /**
+         * The default pitch, which is implementation-dependent.
+         */
+        DEFAULT_PITCH (0x00),
+        /**
+         * A fixed pitch, which means that all the characters in the font occupy the same
+         * width when output in a string.
+         */
+        FIXED_PITCH (0x01),
+        /**
+         * A variable pitch, which means that the characters in the font occupy widths
+         * that are proportional to the actual widths of the glyphs when output in a string. For example,
+         * the "i" and space characters usually have much smaller widths than a "W" or "O" character.
+         */
+        VARIABLE_PITCH (0x02);
+        
+        int flag;
+        WmfFontPitch(int flag) {
+            this.flag = flag;
+        }
+
+        static WmfFontPitch valueOf(int flag) {
+            for (WmfFontPitch fp : values()) {
+                if (fp.flag == flag) return fp;
+            }
+            return null;
+        }        
+    }
+    
+    /**
+     * A 16-bit signed integer that specifies the height, in logical units, of the font's
+     * character cell. The character height is computed as the character cell height minus the
+     * internal leading. The font mapper SHOULD interpret the height as follows.
+     *
+     * negative value:
+     * The font mapper SHOULD transform this value into device units and match its
+     * absolute value against the character height of available fonts.
+     *
+     * zero value:
+     * A default height value MUST be used when creating a physical font.
+     *
+     * positive value:
+     * The font mapper SHOULD transform this value into device units and match it
+     * against the cell height of available fonts.
+     *
+     * For all height comparisons, the font mapper SHOULD find the largest physical
+     * font that does not exceed the requested size.
+     */
+    int height;
+
+    /**
+     * A 16-bit signed integer that defines the average width, in logical units, of
+     * characters in the font. If Width is 0x0000, the aspect ratio of the device SHOULD be matched
+     * against the digitization aspect ratio of the available fonts to find the closest match,
+     * determined by the absolute value of the difference.
+     */
+    int width;
+
+    /**
+     * A 16-bit signed integer that defines the angle, in tenths of degrees, between the
+     * escapement vector and the x-axis of the device. The escapement vector is parallel
+     * to the base line of a row of text.
+     */
+    int escapement;
+
+    /**
+     * A 16-bit signed integer that defines the angle, in tenths of degrees,
+     * between each character's base line and the x-axis of the device.
+     */
+    int orientation;
+
+    /**
+     * A 16-bit signed integer that defines the weight of the font in the range 0
+     * through 1000. For example, 400 is normal and 700 is bold. If this value is 0x0000,
+     * a default weight SHOULD be used.
+     */
+    int weight;
+
+    /**
+     * A 8-bit Boolean value that specifies the italic attribute of the font.
+     * 0 = not italic / 1 = italic.
+     */
+    boolean italic;
+
+    /**
+     * An 8-bit Boolean value that specifies the underline attribute of the font.
+     * 0 = not underlined / 1 = underlined
+     */
+    boolean underline;
+
+    /**
+     * An 8-bit Boolean value that specifies the strike out attribute of the font.
+     * 0 = not striked out / 1 = striked out
+     */
+    boolean strikeOut;
+
+    /**
+     * An 8-bit unsigned integer that defines the character set.
+     * It SHOULD be set to a value in the {@link WmfCharset} Enumeration.
+     *
+     * The DEFAULT_CHARSET value MAY be used to allow the name and size of a font to fully
+     * describe the logical font. If the specified font name does not exist, a font in another character
+     * set MAY be substituted. The DEFAULT_CHARSET value is set to a value based on the current
+     * system locale. For example, when the system locale is United States, it is set to ANSI_CHARSET.
+     * If a typeface name in the FaceName field is specified, the CharSet value MUST match the
+     * character set of that typeface.
+     */
+    WmfCharset charSet;
+
+    /**
+     * An 8-bit unsigned integer that defines the output precision.
+     */
+    WmfOutPrecision outPrecision;
+
+    /**
+     * An 8-bit unsigned integer that defines the clipping precision.
+     * These flags can be combined to specify multiple options.
+     *
+     * @see WmfClipPrecision
+     */
+    int clipPrecision;
+
+    /**
+     * An 8-bit unsigned integer that defines the output quality.
+     */
+    WmfFontQuality quality;
+
+    /**
+     * Font families specify the look of fonts in a general way and are
+     * intended for specifying fonts when the exact typeface wanted is not available.
+     * (LSB 4 bits)
+     */
+    WmfFontFamilyClass family;
+    
+    /**
+     * A property of a font that describes the pitch (MSB 2 bits)
+     */
+    WmfFontPitch pitch;
+
+    /**
+     * A null-terminated string of 8-bit Latin-1 [ISO/IEC-8859-1] ANSI
+     * characters that specifies the typeface name of the font. The length of this string MUST NOT
+     * exceed 32 8-bit characters, including the terminating null.
+     */
+    String facename;
+
+    public int init(LittleEndianInputStream leis) throws IOException {
+        height = leis.readShort();
+        width = leis.readShort();
+        escapement = leis.readShort();
+        orientation = leis.readShort();
+        weight = leis.readShort();
+        italic = leis.readByte() != 0;
+        underline = leis.readByte() != 0;
+        strikeOut = leis.readByte() != 0;
+        charSet = WmfCharset.valueOf(leis.readUByte());
+        outPrecision = WmfOutPrecision.valueOf(leis.readUByte());
+        quality = WmfFontQuality.valueOf(leis.readUByte());
+        int pitchAndFamily = leis.readUByte();
+        family = WmfFontFamilyClass.valueOf(pitchAndFamily & 0xF);
+        pitch = WmfFontPitch.valueOf((pitchAndFamily >>> 6) & 3);
+        
+        byte buf[] = new byte[32], readBytes;
+        for (readBytes = 0; readBytes < 32; readBytes++) {
+            if ((buf[readBytes] = leis.readByte()) == 0) {
+                break;
+            }
+        }
+        if (readBytes == 1 || readBytes == 32) {
+            throw new IOException("Font facename can't be determined.");
+        }
+        facename = new String(buf, 0, readBytes-1, Charset.forName("ISO-8859-1"));
+        
+        return 17+readBytes;
+    }
+}

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfHatchStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfHatchStyle.java?rev=1721078&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfHatchStyle.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfHatchStyle.java Mon Dec 21 01:26:39 2015
@@ -0,0 +1,48 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hwmf.record;
+
+/**
+ * The HatchStyle Enumeration specifies the hatch pattern.
+ */
+public enum HwmfHatchStyle {
+    /** A horizontal hatch */
+    HS_HORIZONTAL(0x0000),
+    /** A vertical hatch */
+    HS_VERTICAL(0x0001),
+    /** A 45-degree downward, left-to-right hatch. */
+    HS_FDIAGONAL(0x0002),
+    /** A 45-degree upward, left-to-right hatch. */
+    HS_BDIAGONAL(0x0003),
+    /** A horizontal and vertical cross-hatch. */
+    HS_CROSS(0x0004),
+    /** A 45-degree crosshatch. */
+    HS_DIAGCROSS(0x0005);
+
+    int flag;
+    HwmfHatchStyle(int flag) {
+        this.flag = flag;
+    }
+
+    static HwmfHatchStyle valueOf(int flag) {
+        for (HwmfHatchStyle hs : values()) {
+            if (hs.flag == flag) return hs;
+        }
+        return null;
+    }
+}
\ No newline at end of file

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfHeader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfHeader.java?rev=1721078&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfHeader.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfHeader.java Mon Dec 21 01:26:39 2015
@@ -0,0 +1,76 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hwmf.record;
+
+import java.io.IOException;
+
+import org.apache.poi.util.LittleEndianConsts;
+import org.apache.poi.util.LittleEndianInputStream;
+
+public class HwmfHeader {
+    private int type;
+    private int recordSize;
+    private int version;
+    private int filesize;
+    private int numberOfObjects;
+    private long maxRecord;
+    private int numberOfMembers;
+    
+    public HwmfHeader(LittleEndianInputStream leis) throws IOException {
+        // Type (2 bytes):  A 16-bit unsigned integer that defines the type of metafile
+        // MEMORYMETAFILE = 0x0001, DISKMETAFILE = 0x0002 
+        type = leis.readUShort();
+
+        // HeaderSize (2 bytes):  A 16-bit unsigned integer that defines the number
+        // of 16-bit words in the header.
+        recordSize = leis.readUShort();
+        int bytesLeft = recordSize*LittleEndianConsts.SHORT_SIZE-4;
+        
+        // Version (2 bytes):  A 16-bit unsigned integer that defines the metafile version.
+        // METAVERSION100 = 0x0100, METAVERSION300 = 0x0300
+        version = leis.readUShort();
+        bytesLeft -= LittleEndianConsts.SHORT_SIZE;
+        
+        // SizeLow (2 bytes):  A 16-bit unsigned integer that defines the low-order word
+        // of the number of 16-bit words in the entire metafile.
+        // SizeHigh (2 bytes):  A 16-bit unsigned integer that defines the high-order word
+        // of the number of 16-bit words in the entire metafile.
+        filesize = leis.readInt();
+        bytesLeft -= LittleEndianConsts.INT_SIZE;
+        
+        // NumberOfObjects (2 bytes):  A 16-bit unsigned integer that specifies the number
+        // of graphics objects that are defined in the entire metafile. These objects include
+        // brushes, pens, and the other objects
+        numberOfObjects = leis.readUShort();
+        bytesLeft -= LittleEndianConsts.SHORT_SIZE;
+        
+        // MaxRecord (4 bytes):  A 32-bit unsigned integer that specifies the size of the
+        // largest record used in the metafile (in 16-bit elements).
+        maxRecord = leis.readUInt();
+        bytesLeft -= LittleEndianConsts.INT_SIZE;
+        
+        // NumberOfMembers (2 bytes):  A 16-bit unsigned integer that is not used.
+        // It SHOULD be 0x0000.
+        numberOfMembers = leis.readUShort();
+        bytesLeft -= LittleEndianConsts.SHORT_SIZE;
+        
+        if (bytesLeft > 0) {
+            leis.skip(bytesLeft);
+        }
+    }
+}

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfMisc.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfMisc.java?rev=1721078&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfMisc.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfMisc.java Mon Dec 21 01:26:39 2015
@@ -0,0 +1,506 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hwmf.record;
+
+import java.io.IOException;
+
+import org.apache.poi.util.LittleEndianConsts;
+import org.apache.poi.util.LittleEndianInputStream;
+
+public class HwmfMisc {
+
+    /**
+     * The META_SAVEDC record saves the playback device context for later retrieval.
+     */
+    public static class WmfSaveDc implements HwmfRecord {
+        public HwmfRecordType getRecordType() { return HwmfRecordType.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 HwmfRecord {
+        public HwmfRecordType getRecordType() { return HwmfRecordType.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 HwmfRecord {
+
+        /**
+         * 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 HwmfRecordType getRecordType() {
+            return HwmfRecordType.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 HwmfRecord {
+
+        HwmfColorRef colorRef;
+
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.setBkColor;
+        }
+
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            colorRef = new HwmfColorRef();
+            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 HwmfRecord {
+
+        /**
+         * A 16-bit unsigned integer that defines background mix mode.
+         * This MUST be either TRANSPARENT = 0x0001 or OPAQUE = 0x0002
+         */
+        int bkMode;
+
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.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 HwmfRecord {
+
+        /**
+         * 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 HwmfRecordType getRecordType() {
+            return HwmfRecordType.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 HwmfRecord {
+
+        /**
+         * 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 HwmfRecordType getRecordType() {
+            return HwmfRecordType.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 HwmfRecord {
+
+        /**
+         * 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 HwmfRecordType getRecordType() {
+            return HwmfRecordType.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 HwmfRecord {
+
+        /**
+         * 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 HwmfRecordType getRecordType() {
+            return HwmfRecordType.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 HwmfRecord {
+
+        /**
+         * 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 HwmfRecordType getRecordType() {
+            return HwmfRecordType.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 HwmfRecord {
+
+        HwmfBrushStyle 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;
+
+        HwmfBitmapDib patternDib;
+        HwmfBitmap16 pattern16;
+
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.dibCreatePatternBrush;
+        }
+
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            style = HwmfBrushStyle.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 HwmfBitmapDib();
+                size += patternDib.init(leis);
+                break;
+            case BS_PATTERN:
+                pattern16 = new HwmfBitmap16();
+                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 HwmfRecord {
+        /**
+         * A 16-bit unsigned integer used to index into the WMF Object Table to
+        get the object to be deleted.
+         */
+        int objectIndex;
+
+        public HwmfRecordType getRecordType() { return HwmfRecordType.deleteObject; }
+
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            objectIndex = leis.readUShort();
+            return LittleEndianConsts.SHORT_SIZE;
+        }
+    }
+
+    public static class WmfCreatePatternBrush implements HwmfRecord {
+
+        HwmfBitmap16 pattern;
+
+        public HwmfRecordType getRecordType() { return HwmfRecordType.createPatternBrush; }
+
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            pattern = new HwmfBitmap16(true);
+            return pattern.init(leis);
+        }
+    }
+
+    public static class WmfCreatePenIndirect implements HwmfRecord {
+
+        /**
+         * 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.
+         */
+        HwmfColorRef colorRef;
+
+        public HwmfRecordType getRecordType() { return HwmfRecordType.createPenIndirect; }
+
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            penStyle = leis.readUShort();
+            xWidth = leis.readShort();
+            yWidth = leis.readShort();
+            colorRef = new HwmfColorRef();
+            int size = 3*LittleEndianConsts.SHORT_SIZE;
+            size += colorRef.init(leis);
+            return size;
+        }
+    }
+
+    /**
+     * The META_CREATEBRUSHINDIRECT record creates a Brush Object
+     * from a LogBrush Object.
+     * 
+     * The following table shows the relationship between values in the BrushStyle,
+     * ColorRef and BrushHatch fields in a LogBrush Object. Only supported brush styles are listed.
+     * 
+     * <table>
+     * <tr>
+     *   <th>BrushStyle</th>
+     *   <th>ColorRef</th>
+     *   <th>BrushHatch</th>
+     * </tr>
+     * <tr>
+     *   <td>BS_SOLID</td>
+     *   <td>SHOULD be a ColorRef Object, which determines the color of the brush.</td>
+     *   <td>Not used, and SHOULD be ignored.</td>
+     * </tr>
+     * <tr>
+     *   <td>BS_NULL</td>
+     *   <td>Not used, and SHOULD be ignored.</td>
+     *   <td>Not used, and SHOULD be ignored.</td>
+     * </tr>
+     * <tr>
+     *   <td>BS_PATTERN</td>
+     *   <td>Not used, and SHOULD be ignored.</td>
+     *   <td>Not used. A default object, such as a solidcolor black Brush Object, MAY be created.</td>
+     * </tr>
+     * <tr>
+     *   <td>BS_DIBPATTERN</td>
+     *   <td>Not used, and SHOULD be ignored.</td>
+     *   <td>Not used. A default object, such as a solidcolor black Brush Object, MAY be created</td>
+     * </tr>
+     * <tr>
+     *   <td>BS_DIBPATTERNPT</td>
+     *   <td>Not used, and SHOULD be ignored.</td>
+     *   <td>Not used. A default object, such as a solidcolor black Brush Object, MAY be created.</td>
+     * </tr>
+     * <tr>
+     *   <td>BS_HATCHED</td>
+     *   <td>SHOULD be a ColorRef Object, which determines the foreground color of the hatch pattern.</td>
+     *   <td>A value from the {@link HwmfHatchStyle} Enumeration that specifies the orientation of lines used to create the hatch.</td>
+     * </tr>
+     * </table>
+     */
+    public static class WmfCreateBrushIndirect implements HwmfRecord {
+        HwmfBrushStyle brushStyle;
+
+        HwmfColorRef colorRef;
+
+        /**
+         * A 16-bit field that specifies the brush hatch type.
+         * Its interpretation depends on the value of BrushStyle.
+         * 
+         */
+        HwmfHatchStyle brushHatch;
+
+        public HwmfRecordType getRecordType() { return HwmfRecordType.createBrushIndirect; }
+
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            brushStyle = HwmfBrushStyle.valueOf(leis.readUShort());
+            colorRef = new HwmfColorRef();
+            int size = colorRef.init(leis);
+            brushHatch = HwmfHatchStyle.valueOf(leis.readUShort());
+            size += 4;
+            return size;
+        }
+    }
+}
\ No newline at end of file

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPalette.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPalette.java?rev=1721078&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPalette.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPalette.java Mon Dec 21 01:26:39 2015
@@ -0,0 +1,163 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hwmf.record;
+
+import java.io.IOException;
+
+import org.apache.poi.util.LittleEndianConsts;
+import org.apache.poi.util.LittleEndianInputStream;
+
+public class HwmfPalette {
+    
+    public static class PaletteEntry {
+        // Values (1 byte):  An 8-bit unsigned integer that defines how the palette entry is to be used. 
+        // The Values field MUST be 0x00 or one of the values in the PaletteEntryFlag Enumeration table.
+        // Blue (1 byte): An 8-bit unsigned integer that defines the blue intensity value for the palette entry.
+        // Green (1 byte): An 8-bit unsigned integer that defines the green intensity value for the palette entry.
+        // Red (1 byte): An 8-bit unsigned integer that defines the red intensity value for the palette entry.
+        int values, blue, green, red;
+        
+        public int init(LittleEndianInputStream leis) throws IOException {
+            values = leis.readUByte();
+            blue = leis.readUByte();
+            green = leis.readUByte();
+            red = leis.readUByte();
+            return 4*LittleEndianConsts.BYTE_SIZE;
+        }
+    }
+    
+    public static abstract class WmfPaletteParent implements HwmfRecord  {
+    
+        /**
+         * Start (2 bytes):  A 16-bit unsigned integer that defines the offset into the Palette Object when
+         * used with the META_SETPALENTRIES and META_ANIMATEPALETTE record types.
+         * When used with META_CREATEPALETTE, it MUST be 0x0300
+         */
+        int start;
+        
+        /**
+         * NumberOfEntries (2 bytes):  A 16-bit unsigned integer that defines the number of objects in
+         * aPaletteEntries.  
+         */
+        int numberOfEntries;
+        
+        PaletteEntry entries[];
+        
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            start = leis.readUShort();
+            numberOfEntries = leis.readUShort();
+            int size = 2*LittleEndianConsts.SHORT_SIZE;
+            entries = new PaletteEntry[numberOfEntries];
+            for (int i=0; i<numberOfEntries; i++) {
+                entries[i] = new PaletteEntry();
+                size += entries[i].init(leis);
+            }
+            return size;
+        }
+    }
+    
+    /**
+     * The META_CREATEPALETTE record creates a Palette Object
+     */
+    public static class WmfCreatePalette extends WmfPaletteParent {
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.createPalette;
+        }
+    }
+
+    /**
+     * The META_SETPALENTRIES record defines RGB color values in a range of entries in the logical
+     * palette that is defined in the playback device context.
+     */
+    public static class WmfSetPaletteEntries extends WmfPaletteParent {
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.setPalEntries;
+        }
+    }
+    
+    /**
+     * The META_RESIZEPALETTE record redefines the size of the logical palette that is defined in the
+     * playback device context.
+     */
+    public static class WmfResizePalette implements HwmfRecord {
+        /**
+         * A 16-bit unsigned integer that defines the number of entries in 
+         * the logical palette.
+         */
+        int numberOfEntries;
+        
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.resizePalette;
+        }
+        
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            numberOfEntries = leis.readUShort();
+            return LittleEndianConsts.SHORT_SIZE;
+        }        
+    }
+
+    /**
+     * The META_SELECTPALETTE record defines the current logical palette with a specified Palette Object.
+     */
+    public static class WmfSelectPalette implements HwmfRecord {
+        /**
+         * A 16-bit unsigned integer used to index into the WMF Object Table to get
+         * the Palette Object to be selected.
+         */
+        int palette;
+
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.selectPalette;
+        }
+        
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            palette = leis.readUShort();
+            return LittleEndianConsts.SHORT_SIZE;
+        }        
+    }
+
+    /**
+     * The META_REALIZEPALETTE record maps entries from the logical palette that
+     * is defined in the playback device context to the system palette.
+     */
+    public static class WmfRealizePalette implements HwmfRecord {
+        public HwmfRecordType getRecordType() { return HwmfRecordType.realizePalette; }
+
+        public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
+            return 0;
+        }
+    }
+
+    /**
+     * The META_ANIMATEPALETTE record redefines entries in the logical palette that
+     * is defined in the playback device context with the specified Palette object
+     * 
+     * The logical palette that is specified by the Palette object in this record is the
+     * source of the palette changes, and the logical palette that is currently selected
+     * into the playback device context is the destination. Entries in the destination
+     * palette with the PC_RESERVED PaletteEntryFlag set SHOULD be modified by this record,
+     * and entries with that flag clear SHOULD NOT be modified.
+     * If none of the entries in the destination palette have the PC_RESERVED flag set, then
+     * this record SHOULD have no effect.
+     */
+    public static class WmfAnimatePalette extends WmfPaletteParent {
+        public HwmfRecordType getRecordType() {
+            return HwmfRecordType.animatePalette;
+        }
+    }
+}

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPlaceableHeader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPlaceableHeader.java?rev=1721078&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPlaceableHeader.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPlaceableHeader.java Mon Dec 21 01:26:39 2015
@@ -0,0 +1,77 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hwmf.record;
+
+import java.io.IOException;
+
+import org.apache.poi.util.LittleEndianConsts;
+import org.apache.poi.util.LittleEndianInputStream;
+
+public class HwmfPlaceableHeader {
+    public static int WMF_HEADER_MAGIC = 0x9AC6CDD7;
+    
+    protected HwmfPlaceableHeader(LittleEndianInputStream leis) throws IOException {
+        /*
+         * HWmf (2 bytes):  The resource handle to the metafile, when the metafile is in memory. When
+         * the metafile is on disk, this field MUST contain 0x0000. This attribute of the metafile is
+         * specified in the Type field of the META_HEADER record.
+         */
+        leis.readShort(); // ignore
+        
+        /*
+         * BoundingBox (8 bytes):  The destination rectangle, measured in logical units, for displaying
+         * the metafile. The size of a logical unit is specified by the Inch field.
+         */
+        int x1 = leis.readShort();
+        int y1 = leis.readShort();
+        int x2 = leis.readShort();
+        int y2 = leis.readShort();
+        
+        /*
+         * Inch (2 bytes):  The number of logical units per inch used to represent the image.
+         * This value can be used to scale an image.
+         * By convention, an image is considered to be recorded at 1440 logical units (twips) per inch.
+         * Thus, a value of 720 specifies that the image SHOULD be rendered at twice its normal size,
+         * and a value of 2880 specifies that the image SHOULD be rendered at half its normal size.
+         */
+        int inch = leis.readShort();
+        
+        /*
+         * Reserved (4 bytes):  A field that is not used and MUST be set to 0x00000000.
+         */
+        leis.readInt();
+        
+        /*
+         * Checksum (2 bytes):  A checksum for the previous 10 16-bit values in the header.
+         * This value can be used to determine whether the metafile has become corrupted.
+         */
+        leis.readShort();
+        
+    }
+    
+    public static HwmfPlaceableHeader readHeader(LittleEndianInputStream leis) throws IOException {
+        leis.mark(LittleEndianConsts.INT_SIZE);
+        int magic = leis.readInt();
+        if (magic == WMF_HEADER_MAGIC) {
+            return new HwmfPlaceableHeader(leis);
+        } else {
+            leis.reset();
+            return null;
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message