@@ -1,4 +1,4 @@
-// Copyright 2001, FreeHEP.
+// Copyright 2001-2006, FreeHEP.
package org.freehep.graphicsio.emf;
import java.awt.Dimension;
@@ -9,11 +9,20 @@
* EMF File Header.
*
* @author Mark Donszelmann
- * @version $Id: EMFHeader.java 8584 2006-08-10 23:06:37Z duns $
+ * @version $Id: EMFHeader.java 10305 2007-01-12 23:43:03Z duns $
*/
public class EMFHeader implements EMFConstants {
private static final Dimension screenMM = new Dimension(320, 240);
+ public final static int TYPE_INVALID = 0; // Invalid metafile
+ public final static int TYPE_WMF = 1; // Standard WMF
+ public final static int TYPE_WMF_PLACEABLE = 2; // Placeable WMF
+ public final static int TYPE_EMF = 3; // EMF (not EMF+)
+ public final static int TYPE_EMF_PLUS_ONLY = 4; // EMF+ without dual, down-level records
+ public final static int TYPE_EMF_PLUS_DUAL = 5; // EMF+ with dual, down-level records
+
+ private int type;
+
private Rectangle bounds;
private Rectangle frame;
@@ -42,9 +51,20 @@
private boolean openGL;
+ /**
+ * @deprecated
+ */
public EMFHeader(Rectangle bounds, int versionMajor, int versionMinor,
int bytes, int records, int handles, String application,
String name, Dimension device) {
+ // Was WMF in 2.0 should be EMF from now on
+ this(TYPE_EMF, bounds, versionMajor, versionMinor, bytes, records, handles, application, name, device);
+ }
+
+ public EMFHeader(int type, Rectangle bounds, int versionMajor, int versionMinor,
+ int bytes, int records, int handles, String application,
+ String name, Dimension device) {
+ this.type = type;
this.bounds = bounds;
// this assumes you use MM_ANISOTROPIC or MM_ISOTROPIC as MapMode
@@ -56,7 +76,7 @@
(int) (bounds.height * 100 * pixelHeight));
this.signature = " EMF";
- this.versionMajor = versionMajor;
+ this.versionMajor = versionMajor >= 0x4000 ? versionMajor - 0x4000 : versionMajor;
this.versionMinor = versionMinor;
this.bytes = bytes;
this.records = records;
@@ -74,7 +94,7 @@
EMFHeader(EMFInputStream emf) throws IOException {
// FIXME: incomplete
- emf.readUnsignedInt(); // 4
+ type = emf.readDWORD(); // 4
int length = emf.readDWORD(); // 8
@@ -118,7 +138,7 @@
int padding = (align - (size() % align)) % align;
int alignedSize = size() + padding;
- emf.writeDWORD(0x00000001); // Header Type
+ emf.writeDWORD(type); // Header Type
emf.writeDWORD(alignedSize); // length of header
emf.writeRECTL(bounds); // inclusive bounds
emf.writeRECTL(frame); // inclusive picture
@@ -129,19 +149,21 @@
emf.writeDWORD(records); // # of records
emf.writeWORD(handles); // # of handles, 1 minimum
emf.writeWORD(0); // reserved
- emf.writeDWORD(description.length()); // size of descriptor in WORDS
- emf.writeDWORD(0x6C); // offset to descriptor
+ emf.writeDWORD(type == TYPE_EMF_PLUS_ONLY ? 0 : description.length()); // size of descriptor in WORDS
+ emf.writeDWORD(type == TYPE_EMF_PLUS_ONLY ? 0 : 0x6C); // offset to descriptor
emf.writeDWORD(palEntries); // # of palette entries
emf.writeSIZEL(device); // size of ref device
emf.writeSIZEL(millimeters); // size of ref device in MM
- emf.writeDWORD(0); // cbPixelFormat
- emf.writeDWORD(0); // offPixelFormat
- emf.writeDWORD(openGL); // bOpenGL
- emf.writeSIZEL(micrometers); // size of ref device in microns
+ if (type != TYPE_EMF_PLUS_ONLY) {
+ emf.writeDWORD(0); // cbPixelFormat
+ emf.writeDWORD(0); // offPixelFormat
+ emf.writeDWORD(openGL); // bOpenGL
+ emf.writeSIZEL(micrometers); // size of ref device in microns
- // optional description
- emf.writeWCHAR(description);
-
+ // optional description
+ emf.writeWCHAR(description);
+ }
+
// padding
for (int i = 0; i < padding; i++) {
emf.write(0);
|