pax_global_header00006660000000000000000000000064116763752140014526gustar00rootroot0000000000000052 comment=379712559a34d9b638762310d07a03eb956f3953 a/000077500000000000000000000000001167637521400113125ustar00rootroot00000000000000a/Example.cs000066400000000000000000000041711167637521400132370ustar00rootroot00000000000000using System; using System.Drawing; using System.Drawing.Imaging; namespace BasicDrawingSample { class EllipseDrawer { public Image Draw(int width, int height, int strokeWidth, Color strokeColor, Color fillColor) { // create the bitmap we will draw to Image image = new Bitmap(width + strokeWidth, height + strokeWidth); // calculate the half of the stroke width for use later float halfStrokeWidth = strokeWidth / 2F; // create a rectangle that bounds the ellipse we want to draw RectangleF ellipseBound = new RectangleF( halfStrokeWidth, halfStrokeWidth, width, height); // create a Graphics object from the bitmap using(Graphics graphics = Graphics.FromImage(image)) { // create a solid color brush using(Brush fillBrush = new SolidBrush(fillColor)) { // fill the ellipse specified by the rectangle calculated above graphics.FillEllipse(fillBrush, ellipseBound); } // create a pen using(Pen pen = new Pen(strokeColor, strokeWidth)) { // draw the stroke of the ellipse specified by the rectangle calculated above graphics.DrawEllipse(pen, ellipseBound); } } return image; } [STAThread] static void Main(string[] args) { if(args.Length != 5) { Console.WriteLine("Usage: ellipseDrawer width height stroke-width stroke-color fill-color"); } else { // get values from the command line arguments int width = Int32.Parse(args[0]); int height = Int32.Parse(args[1]); int strokeWidth = Int32.Parse(args[2]); Color strokeColor = ColorTranslator.FromHtml(args[3]); Color fillColor = ColorTranslator.FromHtml(args[4]); // create and instance of the EllipseDrawer EllipseDrawer ellipseDrawer = new EllipseDrawer(); // draw our ellipse Image image = ellipseDrawer.Draw(width, height, strokeWidth, strokeColor, fillColor); // save to a file image.Save("ellipse.png", ImageFormat.Png); // clean up the image resources image.Dispose(); } } } } a/pom.xml000066400000000000000000000025541167637521400126350ustar00rootroot00000000000000 vectorgraphics org.freehep 2.1 4.0.0 org.freehep freehep-graphicsio-emf FreeHEP EMF and EMF+ Driver FreeHEP Enhanced Metafile Format Driver freehep-maven Maven FreeHEP http://java.freehep.org/maven2 org.freehep freehep-util 2.0.2 org.freehep freehep-graphicsio 2.1 org.freehep freehep-graphicsio-tests 2.1 jdom jdom 1.0 hep.aida aida a/src/000077500000000000000000000000001167637521400121015ustar00rootroot00000000000000a/src/main/000077500000000000000000000000001167637521400130255ustar00rootroot00000000000000a/src/main/java/000077500000000000000000000000001167637521400137465ustar00rootroot00000000000000a/src/main/java/org/000077500000000000000000000000001167637521400145355ustar00rootroot00000000000000a/src/main/java/org/freehep/000077500000000000000000000000001167637521400161535ustar00rootroot00000000000000a/src/main/java/org/freehep/graphicsio/000077500000000000000000000000001167637521400203035ustar00rootroot00000000000000a/src/main/java/org/freehep/graphicsio/emf/000077500000000000000000000000001167637521400210525ustar00rootroot00000000000000a/src/main/java/org/freehep/graphicsio/emf/EMF2SVG.java000066400000000000000000000015161167637521400227710ustar00rootroot00000000000000// Copyright FreeHEP 2006-2007. package org.freehep.graphicsio.emf; import org.freehep.graphicsio.ImageConstants; /** * simple class that uses EMFConverter to convert emf to svg. * Uses {@link org.freehep.graphicsio.emf.EMFConverter#export(String, String, String)} * with type = SVG. * * @author Steffen Greiffenberg * @version $Id$ */ public class EMF2SVG extends EMFConverter { /** * starts the export * * @param args args[0] source file name, args[1] target file (can be empty) */ public static void main(String[] args) { if (args == null || args.length == 0 || args[0] == null || args[0].length() == 0) { System.out.println("usage: EMF2SVG imput.emf [output.svg]"); return; } export(ImageConstants.SVG, args[0], args.length > 1 ? args[1] : null); } } a/src/main/java/org/freehep/graphicsio/emf/EMFApplet.java000066400000000000000000000027601167637521400234770ustar00rootroot00000000000000// Copyright 2007 FreeHEP package org.freehep.graphicsio.emf; import java.applet.Applet; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; /** * Applet to render EMF files on any platform in a browser. * * @author Mark Donszelmann * @version $Id$ */ public class EMFApplet extends Applet { // private EMFRenderer renderer; public void init() { super.init(); System.err.println("init"); try { URL url = new URL("file:/Users/duns/svn/freehep/vectorgraphics/freehep-graphicsio-emf/TestOffset.emf"); EMFInputStream is = new EMFInputStream(url.openStream()); EMFRenderer renderer = new EMFRenderer(is); EMFPanel panel = new EMFPanel(); panel.setRenderer(renderer); add(panel); } catch (MalformedURLException mfue) { System.err.println("URL Malformed "+mfue); } catch (IOException ioe) { System.err.println("IO Exception "+ioe); } } public void start() { super.start(); System.err.println("start"); // repaint(); } public void stop() { super.stop(); System.err.println("stop"); } public void destroy() { super.destroy(); System.err.println("destroy"); } /* public void paintComponents(Graphics g) { super.paintComponents(g); System.err.println("paint"); renderer.paint((Graphics2D)g); } */ } a/src/main/java/org/freehep/graphicsio/emf/EMFConstants.java000066400000000000000000000164231167637521400242270ustar00rootroot00000000000000// Copyright 2001, FreeHEP. package org.freehep.graphicsio.emf; /** * EMF Constants * * @author Mark Donszelmann * @version $Id$ */ public interface EMFConstants { public static final int UNITS_PER_PIXEL = 1; public static final int TWIPS = 20; public static final int GRADIENT_FILL_RECT_H = 0x00000000; public static final int GRADIENT_FILL_RECT_V = 0x00000001; public static final int GRADIENT_FILL_TRIANGLE = 0x00000002; public static final int SRCCOPY = 0x00CC0020; public static final int ICM_OFF = 1; public static final int ICM_ON = 2; public static final int ICM_QUERY = 3; public static final int ICM_DONE_OUTSIDEDC = 4; public static final int FW_DONTCARE = 0; public static final int FW_THIN = 100; public static final int FW_EXTRALIGHT = 200; public static final int FW_LIGHT = 300; public static final int FW_NORMAL = 400; public static final int FW_MEDIUM = 500; public static final int FW_SEMIBOLD = 600; public static final int FW_BOLD = 700; public static final int FW_EXTRABOLD = 800; public static final int FW_HEAVY = 900; public static final int PAN_ANY = 0; public static final int PAN_NO_FIT = 1; public static final int ETO_OPAQUE = 0x0002; public static final int ETO_CLIPPED = 0x0004; public static final int ETO_GLYPH_INDEX = 0x0010; public static final int ETO_RTLREADING = 0x0080; public static final int ETO_NUMERICSLOCAL = 0x0400; public static final int ETO_NUMERICSLATIN = 0x0800; public static final int ETO_IGNORELANGUAGE = 0x1000; public static final int ETO_PDY = 0x2000; public static final int GM_COMPATIBLE = 1; public static final int GM_ADVANCED = 2; public static final int FLOODFILLBORDER = 0; public static final int FLOODFILLSURFACE = 1; public static final int BLACKONWHITE = 1; public static final int WHITEONBLACK = 2; public static final int COLORONCOLOR = 3; public static final int HALFTONE = 4; public static final int STRETCH_ANDSCANS = BLACKONWHITE; public static final int STRETCH_ORSCANS = WHITEONBLACK; public static final int STRETCH_DELETESCANS = COLORONCOLOR; public static final int STRETCH_HALFTONE = HALFTONE; public static final int R2_BLACK = 1; public static final int R2_NOTMERGEPEN = 2; public static final int R2_MASKNOTPEN = 3; public static final int R2_NOTCOPYPEN = 4; public static final int R2_MASKPENNOT = 5; public static final int R2_NOT = 6; public static final int R2_XORPEN = 7; public static final int R2_NOTMASKPEN = 8; public static final int R2_MASKPEN = 9; public static final int R2_NOTXORPEN = 10; public static final int R2_NOP = 11; public static final int R2_MERGENOTPEN = 12; public static final int R2_COPYPEN = 13; public static final int R2_MERGEPENNOT = 14; public static final int R2_MERGEPEN = 15; public static final int R2_WHITE = 16; public static final int ALTERNATE = 1; public static final int WINDING = 2; public static final int TA_BASELINE = 24; public static final int TA_BOTTOM = 8; public static final int TA_TOP = 0; public static final int TA_CENTER = 6; public static final int TA_LEFT = 0; public static final int TA_RIGHT = 2; public static final int TA_NOUPDATECP = 0; public static final int TA_RTLREADING = 256; public static final int TA_UPDATECP = 1; public static final int MM_TEXT = 1; public static final int MM_LOMETRIC = 2; public static final int MM_HIMETRIC = 3; public static final int MM_LOENGLISH = 4; public static final int MM_HIENGLISH = 5; public static final int MM_TWIPS = 6; public static final int MM_ISOTROPIC = 7; public static final int MM_ANISOTROPIC = 8; public static final int AD_COUNTERCLOCKWISE = 1; public static final int AD_CLOCKWISE = 2; public static final int RGN_AND = 1; public static final int RGN_OR = 2; public static final int RGN_XOR = 3; public static final int RGN_DIFF = 4; public static final int RGN_COPY = 5; public static final int RGN_MIN = RGN_AND; public static final int RGN_MAX = RGN_COPY; public static final int BKG_TRANSPARENT = 1; public static final int BKG_OPAQUE = 2; public static final int PT_CLOSEFIGURE = 0x01; public static final int PT_LINETO = 0x02; public static final int PT_BEZIERTO = 0x04; public static final int PT_MOVETO = 0x06; public static final int MWT_IDENTITY = 1; public static final int MWT_LEFTMULTIPLY = 2; public static final int MWT_RIGHTMULTIPLY = 3; public static final int BI_RGB = 0; public static final int BI_RLE8 = 1; public static final int BI_RLE4 = 2; public static final int BI_BITFIELDS = 3; public static final int BI_JPEG = 4; public static final int BI_PNG = 5; public static final int BS_SOLID = 0; public static final int BS_NULL = 1; public static final int BS_HATCHED = 2; public static final int BS_PATTERN = 3; public static final int BS_INDEXED = 4; public static final int BS_DIBPATTERN = 5; public static final int BS_DIBPATTERNPT = 6; public static final int BS_PATTERN8X8 = 7; public static final int BS_DIBPATTERN8X8 = 8; public static final int BS_MONOPATTERN = 9; public static final int BS_HOLLOW = BS_NULL; public static final int DIB_RGB_COLORS = 0; public static final int DIB_PAL_COLORS = 1; public static final int HS_HORIZONTAL = 0; /* ----- */ public static final int HS_VERTICAL = 1; /* ||||| */ public static final int HS_FDIAGONAL = 2; /* \\\\\ */ public static final int HS_BDIAGONAL = 3; /* ///// */ public static final int HS_CROSS = 4; /* +++++ */ public static final int HS_DIAGCROSS = 5; /* xxxxx */ public static final int PS_GEOMETRIC = 0x00010000; public static final int PS_COSMETIC = 0x00000000; public static final int PS_SOLID = 0x00000000; public static final int PS_DASH = 0x00000001; public static final int PS_DOT = 0x00000002; public static final int PS_DASHDOT = 0x00000003; public static final int PS_DASHDOTDOT = 0x00000004; public static final int PS_NULL = 0x00000005; public static final int PS_INSIDEFRAME = 0x00000006; public static final int PS_USERSTYLE = 0x00000007; public static final int PS_ENDCAP_ROUND = 0x00000000; public static final int PS_ENDCAP_SQUARE = 0x00000100; public static final int PS_ENDCAP_FLAT = 0x00000200; public static final int PS_JOIN_ROUND = 0x00000000; public static final int PS_JOIN_BEVEL = 0x00001000; public static final int PS_JOIN_MITER = 0x00002000; public static final int AC_SRC_OVER = 0x00; public static final int AC_SRC_ALPHA = 0x01; public static final int GDICOMMENT_BEGINGROUP = 0x00000002; public static final int GDICOMMENT_ENDGROUP = 0x00000003; public static final int GDICOMMENT_UNICODE_STRING = 0x00000040; public static final int GDICOMMENT_UNICODE_END = 0x00000080; public static final int GDICOMMENT_MULTIFORMATS = 0x40000004; public static final int GDICOMMENT_IDENTIFIER = 0x43494447; public static final int GDICOMMENT_WINDOWS_METAFILE = 0x80000001; }a/src/main/java/org/freehep/graphicsio/emf/EMFConverter.java000066400000000000000000000074441167637521400242250ustar00rootroot00000000000000// Copyright FreeHEP 2007. package org.freehep.graphicsio.emf; import org.freehep.util.export.ExportFileType; import java.util.List; import java.io.FileInputStream; import java.io.File; /** * This class converts an EMF image to all available * grafik formats, e.g. PDF, or PNG * * @author Steffen Greiffenberg * @version $Id$ */ public class EMFConverter { /** * Looks for an (FreeHEP-) ExportFileType in class path * to create the selected output format for destFileName. * * @param type extension / file format to write * @param srcFileName emf file to read * @param destFileName file to create, if null srcFileName * is used with the extension type */ protected static void export(String type, String srcFileName, String destFileName) { try { List exportFileTypes = ExportFileType.getExportFileTypes(type); if (exportFileTypes == null || exportFileTypes.size() == 0) { System.out.println( type + " library is not available. check your classpath!"); return; } ExportFileType exportFileType = (ExportFileType) exportFileTypes.get(0); // read the EMF file EMFRenderer emfRenderer = new EMFRenderer( new EMFInputStream( new FileInputStream(srcFileName))); // create the destFileName, // replace or add the extension to the destFileName if (destFileName == null || destFileName.length() == 0) { // index of the beginning of the extension int lastPointIndex = srcFileName.lastIndexOf("."); // to be sure that the point separates an extension // and is not part of a directory name int lastSeparator1Index = srcFileName.lastIndexOf("/"); int lastSeparator2Index = srcFileName.lastIndexOf("\\"); if (lastSeparator1Index > lastPointIndex || lastSeparator2Index > lastPointIndex) { destFileName = srcFileName + "."; } else if (lastPointIndex > -1) { destFileName = srcFileName.substring( 0, lastPointIndex + 1); } // add the extension destFileName += type.toLowerCase(); } // TODO there is no possibility to use Constants of base class! /* create SVG properties Properties p = new Properties(); p.put(SVGGraphics2D.EMBED_FONTS, Boolean.toString(false)); p.put(SVGGraphics2D.CLIP, Boolean.toString(true)); p.put(SVGGraphics2D.COMPRESS, Boolean.toString(false)); p.put(SVGGraphics2D.TEXT_AS_SHAPES, Boolean.toString(false)); p.put(SVGGraphics2D.FOR, "Freehep EMF2SVG"); p.put(SVGGraphics2D.TITLE, emfFileName);*/ EMFPanel emfPanel = new EMFPanel(); emfPanel.setRenderer(emfRenderer); // TODO why uses this classes components?! exportFileType.exportToFile( new File(destFileName), emfPanel, emfPanel, null, "Freehep EMF converter"); } catch (Exception e) { e.printStackTrace(); } } /** * starts the conversion * * @param args args[0] source file, args[1] destination * file with target format in extension */ public static void main(String[] args) { try { export( args[1].substring(args[1].lastIndexOf(".") + 1), args[0], args[1]); } catch (Exception e) { System.out.println("usage: EMFConverter imput.emf output.extension"); } } } a/src/main/java/org/freehep/graphicsio/emf/EMFDisplay.java000066400000000000000000000014111167637521400236470ustar00rootroot00000000000000// Copyright 2000-2007 FreeHEP package org.freehep.graphicsio.emf; /** * EMFDisplay.java * * Created: Mon May 26 09:43:10 2003 * * Copyright: Copyright (c) 2000, 2001

* Company: ATLANTEC Enterprise Solutions GmbH

* * @author Carsten Zerbst carsten.zerbst@atlantec-es.com * @version $Id$ */ import java.io.File; /** * A simple interpreter displaying an EMF file read in by the EMFInputStream in * a JPanel */ public class EMFDisplay { public static void main(String[] args) { try { EMFViewer emfViewer = new EMFViewer(); if (args[0] != null) { emfViewer.show(new File(args[0])); } } catch (Exception exp) { exp.printStackTrace(); } } } // EMFDisplay a/src/main/java/org/freehep/graphicsio/emf/EMFExportFileType.java000066400000000000000000000037651167637521400252030ustar00rootroot00000000000000// Copyright 2000-2007, FreeHEP package org.freehep.graphicsio.emf; import java.awt.Component; import java.awt.Dimension; import java.io.IOException; import java.io.OutputStream; import java.util.Properties; import javax.swing.JLabel; import javax.swing.JPanel; import org.freehep.graphics2d.VectorGraphics; import org.freehep.graphicsio.AbstractVectorGraphicsIO; import org.freehep.graphicsio.exportchooser.AbstractExportFileType; import org.freehep.graphicsio.exportchooser.BackgroundPanel; import org.freehep.graphicsio.exportchooser.FontPanel; import org.freehep.graphicsio.exportchooser.OptionPanel; import org.freehep.swing.layout.TableLayout; import org.freehep.util.UserProperties; /** * // FIXME, check all options * * @author Mark Donszelmann * @version $Id$ */ public class EMFExportFileType extends AbstractExportFileType { public String getDescription() { return "Windows Enhanced Metafile"; } public String[] getExtensions() { return new String[] { "emf" }; } public String[] getMIMETypes() { return new String[] { "image/x-emf" }; } public boolean hasOptionPanel() { return true; } public JPanel createOptionPanel(Properties user) { UserProperties options = new UserProperties(user, EMFGraphics2D .getDefaultProperties()); String rootKey = EMFGraphics2D.class.getName(); String abstractRootKey = AbstractVectorGraphicsIO.class.getName(); // Make the full panel. OptionPanel optionsPanel = new OptionPanel(); optionsPanel.add("0 0 [5 5 5 5] wt", new BackgroundPanel(options, rootKey, true)); optionsPanel.add("0 1 [5 5 5 5] wt", new FontPanel(options, null, abstractRootKey)); optionsPanel.add(TableLayout.COLUMN_FILL, new JLabel()); return optionsPanel; } public VectorGraphics getGraphics(OutputStream os, Component target) throws IOException { return new EMFGraphics2D(os, target); } public VectorGraphics getGraphics(OutputStream os, Dimension dimension) throws IOException { return new EMFGraphics2D(os, dimension); } } a/src/main/java/org/freehep/graphicsio/emf/EMFGraphics2D.java000066400000000000000000000644621167637521400242070ustar00rootroot00000000000000// Copyright 2000-2007 FreeHEP package org.freehep.graphicsio.emf; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.GraphicsConfiguration; import java.awt.Paint; import java.awt.Point; import java.awt.Rectangle; import java.awt.Shape; import java.awt.Stroke; import java.awt.TexturePaint; import java.awt.Toolkit; import java.awt.geom.AffineTransform; import java.awt.geom.GeneralPath; import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.HashMap; import java.util.Map; import java.util.Properties; import org.freehep.graphics2d.PrintColor; import org.freehep.graphics2d.VectorGraphics; import org.freehep.graphics2d.font.FontEncoder; import org.freehep.graphics2d.font.FontUtilities; import org.freehep.graphicsio.AbstractVectorGraphicsIO; import org.freehep.graphicsio.PageConstants; import org.freehep.graphicsio.emf.gdi.AlphaBlend; import org.freehep.graphicsio.emf.gdi.BeginPath; import org.freehep.graphicsio.emf.gdi.CreateBrushIndirect; import org.freehep.graphicsio.emf.gdi.DeleteObject; import org.freehep.graphicsio.emf.gdi.EOF; import org.freehep.graphicsio.emf.gdi.EndPath; import org.freehep.graphicsio.emf.gdi.ExtCreateFontIndirectW; import org.freehep.graphicsio.emf.gdi.ExtCreatePen; import org.freehep.graphicsio.emf.gdi.ExtLogFontW; import org.freehep.graphicsio.emf.gdi.ExtLogPen; import org.freehep.graphicsio.emf.gdi.ExtTextOutW; import org.freehep.graphicsio.emf.gdi.FillPath; import org.freehep.graphicsio.emf.gdi.LogBrush32; import org.freehep.graphicsio.emf.gdi.ModifyWorldTransform; import org.freehep.graphicsio.emf.gdi.RestoreDC; import org.freehep.graphicsio.emf.gdi.SaveDC; import org.freehep.graphicsio.emf.gdi.SelectClipPath; import org.freehep.graphicsio.emf.gdi.SelectObject; import org.freehep.graphicsio.emf.gdi.SetBkMode; import org.freehep.graphicsio.emf.gdi.SetMapMode; import org.freehep.graphicsio.emf.gdi.SetMiterLimit; import org.freehep.graphicsio.emf.gdi.SetPolyFillMode; import org.freehep.graphicsio.emf.gdi.SetTextAlign; import org.freehep.graphicsio.emf.gdi.SetTextColor; import org.freehep.graphicsio.emf.gdi.SetViewportExtEx; import org.freehep.graphicsio.emf.gdi.SetViewportOrgEx; import org.freehep.graphicsio.emf.gdi.SetWindowExtEx; import org.freehep.graphicsio.emf.gdi.SetWindowOrgEx; import org.freehep.graphicsio.emf.gdi.SetWorldTransform; import org.freehep.graphicsio.emf.gdi.StrokeAndFillPath; import org.freehep.graphicsio.emf.gdi.StrokePath; import org.freehep.graphicsio.emf.gdi.TextW; import org.freehep.graphicsio.font.FontTable; import org.freehep.util.UserProperties; import org.freehep.util.images.ImageUtilities; /** * Enhanced Metafile Format Graphics 2D driver. * * @author Mark Donszelmann * @version $Id$ */ public class EMFGraphics2D extends AbstractVectorGraphicsIO implements EMFConstants { public static final String version = "$Revision$"; private EMFHandleManager handleManager; private int penHandle; private int brushHandle; private Rectangle imageBounds; private OutputStream ros; private EMFOutputStream os; private Color textColor = null; private Color penColor = null; private Color brushColor = null; private Map fontTable; // java fonts private Map unitFontTable; // windows fonts private EMFPathConstructor pathConstructor; private boolean evenOdd; private static final Rectangle dummy = new Rectangle(0, 0, 0, 0); /* * ================================================================================ * Table of Contents: ------------------ 1. Constructors & Factory Methods * 2. Document Settings 3. Header, Trailer, Multipage & Comments 3.1 Header & * Trailer 3.2 MultipageDocument methods 4. Create & Dispose 5. Drawing * Methods 5.1. shapes (draw/fill) 5.1.1. lines, rectangles, round * rectangles 5.1.2. polylines, polygons 5.1.3. ovals, arcs 5.1.4. shapes * 5.2. Images 5.3. Strings 6. Transformations 7. Clipping 8. Graphics State / * Settings 8.1. stroke/linewidth 8.2. paint/color 8.3. font 8.4. rendering * hints 9. Auxiliary 10. Private/Utility Methos * ================================================================================ */ private static final String rootKey = EMFGraphics2D.class.getName(); public static final String TRANSPARENT = rootKey + "." + PageConstants.TRANSPARENT; public static final String BACKGROUND = rootKey + "." + PageConstants.BACKGROUND; public static final String BACKGROUND_COLOR = rootKey + "." + PageConstants.BACKGROUND_COLOR; private static final UserProperties defaultProperties = new UserProperties(); static { defaultProperties.setProperty(TRANSPARENT, true); defaultProperties.setProperty(BACKGROUND, false); defaultProperties.setProperty(BACKGROUND_COLOR, Color.GRAY); defaultProperties.setProperty(CLIP, true); // NOTE: using TEXT_AS_SHAPES makes the text shapes quite unreadable. defaultProperties.setProperty(TEXT_AS_SHAPES, false); } public static Properties getDefaultProperties() { return defaultProperties; } public static void setDefaultProperties(Properties newProperties) { defaultProperties.setProperties(newProperties); } /* * ================================================================================ * 1. Constructors & Factory Methods * ================================================================================ */ public EMFGraphics2D(File file, Dimension size) throws FileNotFoundException { this(new FileOutputStream(file), size); } public EMFGraphics2D(File file, Component component) throws FileNotFoundException { this(new FileOutputStream(file), component); } public EMFGraphics2D(OutputStream os, Dimension size) { super(size, false); this.imageBounds = new Rectangle(0, 0, size.width, size.height); init(os); } public EMFGraphics2D(OutputStream os, Component component) { super(component, false); this.imageBounds = new Rectangle(0, 0, getSize().width, getSize().height); init(os); } private void init(OutputStream os) { fontTable = new HashMap(); unitFontTable = new HashMap(); evenOdd = false; handleManager = new EMFHandleManager(); ros = os; initProperties(defaultProperties); } protected EMFGraphics2D(EMFGraphics2D graphics, boolean doRestoreOnDispose) { super(graphics, doRestoreOnDispose); // Create a graphics context from a given graphics context. // This constructor is used by the system to clone a given graphics // context. // doRestoreOnDispose is used to call writeGraphicsRestore(), // when the graphics context is being disposed off. os = graphics.os; imageBounds = graphics.imageBounds; handleManager = graphics.handleManager; fontTable = graphics.fontTable; unitFontTable = graphics.unitFontTable; pathConstructor = graphics.pathConstructor; evenOdd = graphics.evenOdd; textColor = graphics.textColor; penColor = graphics.penColor; brushColor = graphics.brushColor; } /* * ================================================================================ | * 2. Document Settings * ================================================================================ */ /* * ================================================================================ | * 3. Header, Trailer, Multipage & Comments * ================================================================================ */ /* 3.1 Header & Trailer */ public void writeHeader() throws IOException { ros = new BufferedOutputStream(ros); Dimension device = isDeviceIndependent() ? new Dimension(1024, 768) : Toolkit.getDefaultToolkit().getScreenSize(); String producer = getClass().getName(); if (!isDeviceIndependent()) { producer += " " + version.substring(1, version.length() - 1); } os = new EMFOutputStream(ros, imageBounds, handleManager, getCreator(), producer, device); pathConstructor = new EMFPathConstructor(os, imageBounds); Point orig = new Point(imageBounds.x, imageBounds.y); Dimension size = new Dimension(imageBounds.width, imageBounds.height); os.writeTag(new SetMapMode(MM_ANISOTROPIC)); os.writeTag(new SetWindowOrgEx(orig)); os.writeTag(new SetWindowExtEx(size)); os.writeTag(new SetViewportOrgEx(orig)); os.writeTag(new SetViewportExtEx(size)); os.writeTag(new SetTextAlign(TA_BASELINE)); os.writeTag(new SetTextColor(getColor())); os.writeTag(new SetPolyFillMode(EMFConstants.WINDING)); } public void writeGraphicsState() throws IOException { super.writeGraphicsState(); // write a special matrix here to scale all written coordinates by a // factor of TWIPS AffineTransform n = AffineTransform.getScaleInstance(1.0 / TWIPS, 1.0 / TWIPS); os.writeTag(new SetWorldTransform(n)); } public void writeBackground() throws IOException { if (isProperty(TRANSPARENT)) { setBackground(null); os.writeTag(new SetBkMode(BKG_TRANSPARENT)); } else if (isProperty(BACKGROUND)) { os.writeTag(new SetBkMode(BKG_OPAQUE)); setBackground(getPropertyColor(BACKGROUND_COLOR)); clearRect(0.0, 0.0, getSize().width, getSize().height); } else { os.writeTag(new SetBkMode(BKG_OPAQUE)); setBackground(getComponent() != null ? getComponent() .getBackground() : Color.WHITE); clearRect(0.0, 0.0, getSize().width, getSize().height); } } public void writeTrailer() throws IOException { // delete any remaining objects for (;;) { int handle = handleManager.highestHandleInUse(); if (handle < 0) break; os.writeTag(new DeleteObject(handle)); handleManager.freeHandle(handle); } os.writeTag(new EOF()); } public void closeStream() throws IOException { os.close(); } /* 3.2 MultipageDocument methods */ /* * ================================================================================ * 4. Create & Dispose * ================================================================================ */ public Graphics create() { // Create a new graphics context from the current one. try { // Save the current context for restore later. writeGraphicsSave(); } catch (IOException e) { handleException(e); } // The correct graphics context should be created. return new EMFGraphics2D(this, true); } public Graphics create(double x, double y, double width, double height) { // Create a new graphics context from the current one. try { // Save the current context for restore later. writeGraphicsSave(); } catch (IOException e) { handleException(e); } // The correct graphics context should be created. VectorGraphics graphics = new EMFGraphics2D(this, true); graphics.translate(x, y); graphics.clipRect(0, 0, width, height); return graphics; } protected void writeGraphicsSave() throws IOException { os.writeTag(new SaveDC()); } protected void writeGraphicsRestore() throws IOException { if (penHandle != 0) os.writeTag(new DeleteObject(handleManager.freeHandle(penHandle))); if (brushHandle != 0) os .writeTag(new DeleteObject(handleManager .freeHandle(brushHandle))); os.writeTag(new RestoreDC()); } /* * ================================================================================ | * 5. Drawing Methods * ================================================================================ */ /* 5.1.4. shapes */ public void draw(Shape shape) { try { if (getStroke() instanceof BasicStroke) { writePen((BasicStroke) getStroke(), getColor()); writePath(shape); os.writeTag(new StrokePath(imageBounds)); } else { writeBrush(getColor()); writePath(getStroke().createStrokedShape(shape)); os.writeTag(new FillPath(imageBounds)); } } catch (IOException e) { handleException(e); } } public void fill(Shape shape) { try { if (getPaint() instanceof Color) { writeBrush(getColor()); writePath(shape); os.writeTag(new FillPath(imageBounds)); } else { // draw paint as image fill(shape, getPaint()); } } catch (IOException e) { handleException(e); } } public void fillAndDraw(Shape shape, Color fillColor) { try { if (getPaint() instanceof Color) { writePen((BasicStroke) getStroke(), getColor()); writeBrush(fillColor); writePath(shape); os.writeTag(new StrokeAndFillPath(imageBounds)); } else { // draw paint as image fill(shape, getPaint()); // draw shape draw(shape); } } catch (IOException e) { handleException(e); } } /* 5.2. Images */ public void copyArea(int x, int y, int width, int height, int dx, int dy) { writeWarning(getClass() + ": copyArea(int, int, int, int, int, int) not implemented."); // Mostly unimplemented. } // NOTE: does not use writeGraphicsSave and writeGraphicsRestore since these // delete pen and brush protected void writeImage(RenderedImage image, AffineTransform xform, Color bkg) throws IOException { os.writeTag(new SaveDC()); AffineTransform imageTransform = new AffineTransform( 1.0, 0.0, 0.0, -1.0, 0.0, image.getHeight()); imageTransform.preConcatenate(xform); writeTransform(imageTransform); BufferedImage bufferedImage = ImageUtilities.createBufferedImage( image, null, null); AlphaBlend alphaBlend = new AlphaBlend( imageBounds, toUnit(0), toUnit(0), toUnit(image.getWidth()), toUnit(image.getHeight()), new AffineTransform(), bufferedImage, bkg); os.writeTag(alphaBlend); os.writeTag(new RestoreDC()); } /* 5.3. Strings */ public void writeString(String string, double x, double y) throws IOException { Color color; Paint paint = getPaint(); if (paint instanceof Color) { color = (Color) paint; } else if (paint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) paint; color = PrintColor.mixColor(gp.getColor1(), gp.getColor2()); } else { Color bkg = getBackground(); if (bkg == null) { color = Color.BLACK; } else { color = PrintColor.invert(bkg); } } if (!color.equals(textColor)) { textColor = color; os.writeTag(new SetTextColor(textColor)); } // dialog.bold -> Dialog with TextAttribute.WEIGHT_BOLD Map attributes = FontUtilities.getAttributes(getFont()); FontTable.normalize(attributes); Font font = new Font(attributes); Font unitFont = (Font) unitFontTable.get(font); Integer fontIndex = (Integer) fontTable.get(font); if (fontIndex == null) { // for special fonts (Symbol, ZapfDingbats) we choose a standard // font and // encode using unicode. String fontName = font.getName(); string = FontEncoder.getEncodedString(string, fontName); String windowsFontName = FontUtilities .getWindowsFontName(fontName); unitFont = new Font(windowsFontName, font.getStyle(), font .getSize()); unitFont = unitFont.deriveFont(font.getSize2D() * UNITS_PER_PIXEL * TWIPS); unitFontTable.put(font, unitFont); ExtLogFontW logFontW = new ExtLogFontW(unitFont); int handle = handleManager.getHandle(); os.writeTag(new ExtCreateFontIndirectW(handle, logFontW)); fontIndex = new Integer(handle); fontTable.put(font, fontIndex); } os.writeTag(new SelectObject(fontIndex.intValue())); int[] widths = new int[string.length()]; for (int i = 0; i < widths.length; i++) { double w = unitFont.getStringBounds(string, i, i + 1, getFontRenderContext()).getWidth(); widths[i] = (int) w; } // font transformation sould _not_ transform string position translate(x, y); // apply font transformation AffineTransform t = font.getTransform(); if (!t.isIdentity()) { writeGraphicsSave(); writeTransform(t); } TextW text = new TextW(new Point(0, 0), string, 0, dummy, widths); os.writeTag(new ExtTextOutW(imageBounds, EMFConstants.GM_ADVANCED, 1, 1, text)); // revert font transformation if (!t.isIdentity()) { writeGraphicsRestore(); } // translation for string position. translate(-x, -y); } /* * ================================================================================ | * 6. Transformations * ================================================================================ */ protected void writeTransform(AffineTransform t) throws IOException { AffineTransform n = new AffineTransform(t.getScaleX(), t.getShearY(), t .getShearX(), t.getScaleY(), t.getTranslateX() * UNITS_PER_PIXEL * TWIPS, t.getTranslateY() * UNITS_PER_PIXEL * TWIPS); os.writeTag(new ModifyWorldTransform(n, EMFConstants.MWT_LEFTMULTIPLY)); } protected void writeSetTransform(AffineTransform t) throws IOException { // write a special matrix here to scale all written coordinates by a factor of TWIPS AffineTransform n = AffineTransform.getScaleInstance(1.0/TWIPS, 1.0/TWIPS); os.writeTag(new SetWorldTransform(n)); // apply transform writeTransform(t); } /* * ================================================================================ | * 7. Clipping * ================================================================================ */ protected void writeSetClip(Shape s) throws IOException { if (!isProperty(CLIP)) { return; } // if s == null the clip is reset to the imageBounds if (s == null && imageBounds != null) { s = new Rectangle(imageBounds); AffineTransform at = getTransform(); if (at != null) { s = at.createTransformedShape(s); } } writePath(s); os.writeTag(new SelectClipPath(EMFConstants.RGN_COPY)); } protected void writeClip(Shape s) throws IOException { if (s == null || !isProperty(CLIP)) { return; } writePath(s); os.writeTag(new SelectClipPath(EMFConstants.RGN_AND)); } /* * ================================================================================ | * 8. Graphics State * ================================================================================ */ public void writeStroke(Stroke stroke) throws IOException { if (stroke instanceof BasicStroke) { writePen((BasicStroke) stroke, getColor()); } } /* 8.2. paint/color */ public void setPaintMode() { writeWarning(getClass() + ": setPaintMode() not implemented."); // Mostly unimplemented. } public void setXORMode(Color c1) { writeWarning(getClass() + ": setXORMode(Color) not implemented."); // Mostly unimplemented. } protected void writePaint(Color p) throws IOException { // all color setting delayed } protected void writePaint(GradientPaint p) throws IOException { // all paint setting delayed } protected void writePaint(TexturePaint p) throws IOException { // all paint setting delayed } protected void writePaint(Paint p) throws IOException { // all paint setting delayed } /* 8.3. font */ protected void writeFont(Font font) throws IOException { // written when needed } /* 8.4. rendering hints */ /* * ================================================================================ | * 9. Auxiliary * ================================================================================ */ public GraphicsConfiguration getDeviceConfiguration() { writeWarning(getClass() + ": getDeviceConfiguration() not implemented."); // Mostly unimplemented return null; } public void writeComment(String comment) throws IOException { writeWarning(getClass() + ": writeComment(String) not implemented."); // Write out the comment. } public String toString() { return "EMFGraphics2D"; } /** * Implementation of createShape makes sure that the points are different by * at least one Unit. */ protected Shape createShape(double[] xPoints, double[] yPoints, int nPoints, boolean close) { GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD); if (nPoints > 0) { path.moveTo((float) xPoints[0], (float) yPoints[0]); double lastX = xPoints[0]; double lastY = yPoints[0]; if (close && (Math.abs(xPoints[nPoints - 1] - lastX) < 1) && (Math.abs(yPoints[nPoints - 1] - lastY) < 1)) { nPoints--; } for (int i = 1; i < nPoints; i++) { if ((Math.abs(xPoints[i] - lastX) > 1) || (Math.abs(yPoints[i] - lastY) > 1)) { path.lineTo((float) xPoints[i], (float) yPoints[i]); lastX = xPoints[i]; lastY = yPoints[i]; } } if (close) path.closePath(); } return path; } /* * Private methods */ private boolean writePath(Shape shape) throws IOException { boolean eo = EMFPathConstructor.isEvenOdd(shape); if (eo != evenOdd) { evenOdd = eo; os.writeTag(new SetPolyFillMode((evenOdd) ? EMFConstants.ALTERNATE : EMFConstants.WINDING)); } os.writeTag(new BeginPath()); pathConstructor.addPath(shape); os.writeTag(new EndPath()); return evenOdd; } private void writePen(BasicStroke stroke, Color color) throws IOException { if (color.equals(penColor) && stroke.equals(getStroke())) return; penColor = color; int style = EMFConstants.PS_GEOMETRIC; switch (stroke.getEndCap()) { case BasicStroke.CAP_BUTT: style |= EMFConstants.PS_ENDCAP_FLAT; break; case BasicStroke.CAP_ROUND: style |= EMFConstants.PS_ENDCAP_ROUND; break; case BasicStroke.CAP_SQUARE: style |= EMFConstants.PS_ENDCAP_SQUARE; break; } switch (stroke.getLineJoin()) { case BasicStroke.JOIN_MITER: style |= EMFConstants.PS_JOIN_MITER; break; case BasicStroke.JOIN_ROUND: style |= EMFConstants.PS_JOIN_ROUND; break; case BasicStroke.JOIN_BEVEL: style |= EMFConstants.PS_JOIN_BEVEL; break; } // FIXME int conversion // FIXME phase ignored float[] dashArray = stroke.getDashArray(); int[] dash = new int[(dashArray != null) ? dashArray.length : 0]; style |= (dash.length == 0) ? EMFConstants.PS_SOLID : EMFConstants.PS_USERSTYLE; for (int i = 0; i < dash.length; i++) { dash[i] = toUnit(dashArray[i]); } int brushStyle = (color.getAlpha() == 0) ? EMFConstants.BS_NULL : EMFConstants.BS_SOLID; ExtLogPen pen = new ExtLogPen(style, toUnit(stroke.getLineWidth()), brushStyle, getPrintColor(color), 0, dash); if (penHandle != 0) { os.writeTag(new DeleteObject(penHandle)); } else { penHandle = handleManager.getHandle(); } os.writeTag(new ExtCreatePen(penHandle, pen)); os.writeTag(new SelectObject(penHandle)); if (!(getStroke() instanceof BasicStroke) || (((BasicStroke) getStroke()).getMiterLimit() != stroke .getMiterLimit())) { os.writeTag(new SetMiterLimit(toUnit(stroke.getMiterLimit()))); } } private void writeBrush(Color color) throws IOException { if (color.equals(brushColor)) return; brushColor = color; int brushStyle = (color.getAlpha() == 0) ? EMFConstants.BS_NULL : EMFConstants.BS_SOLID; LogBrush32 brush = new LogBrush32(brushStyle, getPrintColor(color), 0); if (brushHandle != 0) { os.writeTag(new DeleteObject(brushHandle)); } else { brushHandle = handleManager.getHandle(); } os.writeTag(new CreateBrushIndirect(brushHandle, brush)); os.writeTag(new SelectObject(brushHandle)); } private int toUnit(double d) { return (int) Math.floor(d * UNITS_PER_PIXEL * TWIPS); } } a/src/main/java/org/freehep/graphicsio/emf/EMFHandleManager.java000066400000000000000000000015741167637521400247420ustar00rootroot00000000000000package org.freehep.graphicsio.emf; import java.util.BitSet; /** * Allocates and frees handles for EMF files * * @author Tony Johnson * @version $Id$ */ public class EMFHandleManager { private BitSet handles = new BitSet(); private int maxHandle; public int getHandle() { int handle = nextClearBit(); handles.set(handle); if (handle > maxHandle) maxHandle = handle; return handle; } public int freeHandle(int handle) { handles.clear(handle); return handle; } private int nextClearBit() { // return handles.nextClearBit(1); // JDK 1.4 for (int i = 1;; i++) if (!handles.get(i)) return i; } public int highestHandleInUse() { return handles.length() - 1; } public int maxHandlesUsed() { return maxHandle + 1; } } a/src/main/java/org/freehep/graphicsio/emf/EMFHeader.java000066400000000000000000000226641167637521400234470ustar00rootroot00000000000000// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.emf; import java.awt.Dimension; import java.awt.Rectangle; import java.io.IOException; /** * EMF File Header. * * @author Mark Donszelmann * @version $Id$ */ 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; private String signature; private int versionMajor; private int versionMinor; private int bytes; private int records; private int handles; private String description; private int palEntries; private Dimension device; private Dimension millimeters; private Dimension micrometers; 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 double pixelWidth = (double) screenMM.width / device.width; double pixelHeight = (double) screenMM.height / device.height; this.frame = new Rectangle((int) (bounds.x * 100 * pixelWidth), (int) (bounds.y * 100 * pixelHeight), (int) (bounds.width * 100 * pixelWidth), (int) (bounds.height * 100 * pixelHeight)); this.signature = " EMF"; this.versionMajor = versionMajor >= 0x4000 ? versionMajor - 0x4000 : versionMajor; this.versionMinor = versionMinor; this.bytes = bytes; this.records = records; this.handles = handles; this.description = application.trim() + "\0" + name.trim() + "\0\0"; this.palEntries = 0; this.device = device; this.millimeters = screenMM; this.openGL = false; this.micrometers = new Dimension(screenMM.width * 1000, screenMM.height * 1000); } EMFHeader(EMFInputStream emf) throws IOException { // FIXME: incomplete type = emf.readDWORD(); // 4 int length = emf.readDWORD(); // 8 bounds = emf.readRECTL(); // 24 frame = emf.readRECTL(); // 40 signature = new String(emf.readBYTE(4)); // 44 int version = emf.readDWORD(); // 48 versionMajor = version >> 16; versionMinor = version & 0xFFFF; bytes = emf.readDWORD(); // 52 records = emf.readDWORD(); // 56 handles = emf.readWORD(); // 58 emf.readWORD(); // 60 int dLen = emf.readDWORD(); // 64 int dOffset = emf.readDWORD(); // 68 palEntries = emf.readDWORD(); // 72 device = emf.readSIZEL(); // 80 millimeters = emf.readSIZEL(); // 88 int bytesRead = 88; if (dOffset > 88) { emf.readDWORD(); // 92 emf.readDWORD(); // 96 openGL = (emf.readDWORD() != 0) ? true : false; // 100 bytesRead += 12; if (dOffset > 100) { micrometers = emf.readSIZEL(); // 108 bytesRead += 8; } } // Discard any bytes leading up to the description (usually zero, but safer not to assume.) if (bytesRead < dOffset) { emf.skipBytes(dOffset - bytesRead); bytesRead = dOffset; } description = emf.readWCHAR(dLen); bytesRead += dLen * 2; // Discard bytes after the description up to the end of the header. if (bytesRead < length) { emf.skipBytes(length - bytesRead); } } public void write(EMFOutputStream emf) throws IOException { int align = emf.getTagAlignment(); int padding = (align - (size() % align)) % align; int alignedSize = size() + padding; emf.writeDWORD(type); // Header Type emf.writeDWORD(alignedSize); // length of header emf.writeRECTL(bounds); // inclusive bounds emf.writeRECTL(frame); // inclusive picture emf.writeBYTE(signature.getBytes()); // signature ID EMF emf.writeDWORD((versionMajor << 16) | versionMinor); // version emf.writeDWORD(alignedSize + bytes); // file size emf.writeDWORD(records); // # of records emf.writeWORD(handles); // # of handles, 1 minimum emf.writeWORD(0); // reserved 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 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); } // padding for (int i = 0; i < padding; i++) { emf.write(0); } } /** * @return size of emf file in bytes ? */ public int size() { return 108 + (2 * description.length()); } public String toString() { StringBuffer s = new StringBuffer("EMF Header\n"); s.append(" bounds: ").append(bounds).append("\n"); s.append(" frame: ").append(frame).append("\n"); s.append(" signature: ").append(signature).append("\n"); s.append(" versionMajor: ").append(versionMajor).append("\n"); s.append(" versionMinor: ").append(versionMinor).append("\n"); s.append(" #bytes: ").append(bytes).append("\n"); s.append(" #records: ").append(records).append("\n"); s.append(" #handles: ").append(handles).append("\n"); s.append(" description: ").append(description).append("\n"); s.append(" #palEntries: ").append(palEntries).append("\n"); s.append(" device: ").append(device).append("\n"); s.append(" millimeters: ").append(millimeters).append("\n"); s.append(" openGL: ").append(openGL).append("\n"); s.append(" micrometers: ").append(micrometers); return s.toString(); } /** * Specifies the dimensions, in device units, of the smallest rectangle that * can be drawn around the picture stored in the metafile. This rectangle is * supplied by graphics device interface (GDI). Its dimensions include the * right and bottom edges. * @return bounds of device */ public Rectangle getBounds() { return bounds; } /** * Specifies the dimensions, in .01 millimeter units, of a rectangle that * surrounds the picture stored in the metafile. This rectangle must be * supplied by the application that creates the metafile. Its dimensions * include the right and bottom edges. * @return bounds of frame */ public Rectangle getFrame() { return frame; } /** * Specifies a double word signature. This member must specify the value * assigned to the ENHMETA_SIGNATURE constant. * @return signature */ public String getSignature() { return signature; } /** * @return the description of the enhanced metafile's contents */ public String getDescription() { return description; } /** * Specifies the resolution of the reference device, in pixels. * @return resolution of the reference device, in pixels */ public Dimension getDevice() { return device; } /** * Specifies the resolution of the reference device, in millimeters. * @return size in millimeters */ public Dimension getMillimeters() { return millimeters; } /** * Windows 98/Me, Windows 2000/XP: Size of the reference device in * micrometers. * @return size in micrometers */ public Dimension getMicrometers() { return micrometers; } /** * Windows 95/98/Me, Windows NT 4.0 and later: Specifies whether any OpenGL * records are present in a metafile. bOpenGL is a simple Boolean flag that * you can use to determine whether an enhanced metafile requires OpenGL * handling. When a metafile contains OpenGL records, bOpenGL is TRUE; * otherwise it is FALSE. * * @return false is default */ public boolean isOpenGL() { return openGL; } } a/src/main/java/org/freehep/graphicsio/emf/EMFImageLoader.java000066400000000000000000000435231167637521400244250ustar00rootroot00000000000000package org.freehep.graphicsio.emf; import org.freehep.graphicsio.emf.gdi.BitmapInfoHeader; import org.freehep.graphicsio.emf.gdi.BlendFunction; import java.awt.image.BufferedImage; import java.awt.Color; import java.io.IOException; import java.util.Arrays; /** * this class creates a BufferedImage from EMF imaga data stored in * a byte[]. * * @author Steffen Greiffenberg * @version $Id$ */ public class EMFImageLoader { /** * creates a BufferedImage from an EMFInputStream using * BitmapInfoHeader data * * @param bmi BitmapInfoHeader storing Bitmap informations * @param width expected image width * @param height expected image height * @param emf EMF stream * @param len length of image data * @param blendFunction contains values for transparency * @return BufferedImage or null * @throws java.io.IOException thrown by EMFInputStream */ public static BufferedImage readImage( BitmapInfoHeader bmi, int width, int height, EMFInputStream emf, int len, BlendFunction blendFunction) throws IOException { // 0 Windows 98/Me, Windows 2000/XP: The number of bits-per-pixel // is specified or is implied by the JPEG or PNG format. if (bmi.getBitCount() == 1) { // 1 The bitmap is monochrome, and the bmiColors // member of BITMAPINFO contains two entries. Each // bit in the bitmap array represents a pixel. If // the bit is clear, the pixel is displayed with // the color of the first entry in the bmiColors // table; if the bit is set, the pixel has the color // of the second entry in the table. // byte[] bytes = emf.readByte(len); int blue = emf.readUnsignedByte(); int green = emf.readUnsignedByte(); int red = emf.readUnsignedByte(); /*int unused =*/ emf.readUnsignedByte(); int color1 = new Color(red, green, blue).getRGB(); blue = emf.readUnsignedByte(); green = emf.readUnsignedByte(); red = emf.readUnsignedByte(); /*unused = */ emf.readUnsignedByte(); int color2 = new Color(red, green, blue).getRGB(); BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); int[] data = emf.readUnsignedByte(len - 8); // TODO: this is highly experimental and does // not work for the tested examples int strangeOffset = width % 8; if (strangeOffset != 0) { strangeOffset = 8 - strangeOffset; } // iterator for pixel data int pixel = 0; // mask for getting the bits from a pixel data byte int[] mask = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; // image data are swapped compared to java standard for (int y = height - 1; y > -1; y--) { for (int x = 0; x < width; x++) { int pixelDataGroup = data[pixel / 8]; int pixelData = pixelDataGroup & mask[pixel % 8]; pixel ++; if (pixelData > 0) { result.setRGB(x, y, color2); } else { result.setRGB(x, y, color1); } } // add the extra width pixel = pixel + strangeOffset; } /* for debugging: shows every loaded image javax.swing.JFrame f = new javax.swing.JFrame("test"); f.getContentPane().setBackground(Color.green); f.getContentPane().setLayout( new java.awt.BorderLayout(0, 0)); f.getContentPane().add( java.awt.BorderLayout.CENTER, new javax.swing.JLabel( new javax.swing.ImageIcon(result))); f.setSize(new java.awt.Dimension(width + 20, height + 20)); f.setVisible(true);*/ return result; } else if ((bmi.getBitCount() == 8) && (bmi.getCompression() == EMFConstants.BI_RGB)) { // 8 The bitmap has a maximum of 256 colors, and the bmiColors member // of BITMAPINFO contains up to 256 entries. In this case, each byte in // the array represents a single pixel. // TODO has to be done in BitMapInfoHeader? // read the color table int colorsUsed = bmi.getClrUsed(); // typedef struct tagRGBQUAD { // BYTE rgbBlue; // BYTE rgbGreen; // BYTE rgbRed; // BYTE rgbReserved; // } RGBQUAD; int[] colors = emf.readUnsignedByte(colorsUsed * 4); // data a indexes to a certain color in the colortable. // Each byte represents a pixel int[] data = emf.readUnsignedByte(len - (colorsUsed * 4)); // convert it to a color table int[] colorTable = new int[256]; // iterator for color data int color = 0; for (int i = 0; i < colorsUsed; i++, color = i * 4) { colorTable[i] = new Color( colors[color + 2], colors[color + 1], colors[color]).getRGB(); } // fill with black to avoid ArrayIndexOutOfBoundExceptions; // somme images seem to use more colors than stored in ClrUsed if (colorsUsed < 256) { Arrays.fill(colorTable, colorsUsed, 256, 0); } // don't know why, but the width has to be adjusted ... // it took more than an hour to determine the strangeOffset int strangeOffset = width % 4; if (strangeOffset != 0) { strangeOffset = 4 - strangeOffset; } // create the image BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // iterator for pixel data int pixel = 0; // image data are swapped compared to java standard for (int y = height - 1; y > -1; y--) { for (int x = 0; x < width; x++) { result.setRGB(x, y, colorTable[data[pixel++]]); } // add the extra width pixel = pixel + strangeOffset; } return result; } // The bitmap has a maximum of 2^16 colors. If the biCompression member // of the BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is // NULL. else if ((bmi.getBitCount() == 16) && (bmi.getCompression() == EMFConstants.BI_RGB)) { // Each WORD in the bitmap array represents a single pixel. The // relative intensities of red, green, and blue are represented with // five bits for each color component. The value for blue is in the least // significant five bits, followed by five bits each for green and red. // The most significant bit is not used. The bmiColors color table is used // for optimizing colors used on palette-based devices, and must contain // the number of entries specified by the biClrUsed member of the // BITMAPINFOHEADER. int[] data = emf.readDWORD(len / 4); // don't know why, by the width has to be the half ... // maybe that has something to do with sie HALFTONE rendering setting. width = (width + (width % 2)) / 2; // to avoid ArrayIndexOutOfBoundExcesptions height = data.length / width / 2; // create a non transparent image BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // found no sample and color model to mak this work // tag.image.setRGB(0, 0, tag.widthSrc, tag.heightSrc, data, 0, 0); // used in the loop int off = 0; int pixel, neighbor; // image data are swapped compared to java standard for (int y = height - 1; y > -1; y--, off = off + width) { for (int x = 0; x < width; x++) { neighbor = data[off + width]; pixel = data[off++]; // compute the average of the pixel and it's neighbor // and set the reulting color values result.setRGB(x, y, new Color( // 0xF800 = 2 * 0x7C00 (float)((pixel & 0x7C00) + (neighbor & 0x7C00)) / 0xF800, (float)((pixel & 0x3E0) + (neighbor & 0x3E0)) / 0x7C0, (float)((pixel & 0x1F) + (neighbor & 0x1F)) / 0x3E).getRGB()); } } /* for debugging: shows every loaded image javax.swing.JFrame f = new javax.swing.JFrame("test"); f.getContentPane().setBackground(Color.green); f.getContentPane().setLayout( new java.awt.BorderLayout(0, 0)); f.getContentPane().add( java.awt.BorderLayout.CENTER, new javax.swing.JLabel( new javax.swing.ImageIcon(result))); f.pack(); f.setVisible(true);*/ return result; } // The bitmap has a maximum of 2^32 colors. If the biCompression member of the // BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is NULL. else if ((bmi.getBitCount() == 32) && (bmi.getCompression() == EMFConstants.BI_RGB)) { // Each DWORD in the bitmap array represents the relative intensities of blue, // green, and red, respectively, for a pixel. The high byte in each DWORD is not // used. The bmiColors color table is used for optimizing colors used on // palette-based devices, and must contain the number of entries specified // by the biClrUsed member of the BITMAPINFOHEADER. width = (width + (width % 20)) / 20; height = (height + (height % 20)) / 20; // create a transparent image BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // read the image data int[] data = emf.readDWORD(len / 4); // used to iterate the pixels later int off = 0; int pixel; int alpha; // The SourceConstantaAlpha member of BLENDFUNCTION specifies an alpha transparency // value to be used on the entire source bitmap. The SourceConstantAlpha value is // combined with any per-pixel alpha values. If SourceConstantAlpha is 0, it is // assumed that the image is transparent. Set the SourceConstantAlpha value to 255 // (which indicates that the image is opaque) when you only want to use per-pixel // alpha values. int sourceConstantAlpha = blendFunction.getSourceConstantAlpha(); if (blendFunction.getAlphaFormat() != EMFConstants.AC_SRC_ALPHA) { // If the source bitmap has no per-pixel alpha value (that is, AC_SRC_ALPHA is not // set), the SourceConstantAlpha value determines the blend of the source and // destination bitmaps, as shown in the following table. Note that SCA is used // for SourceConstantAlpha here. Also, SCA is divided by 255 because it has a // value that ranges from 0 to 255. // Dst.Red = Src.Red * (SCA/255.0) + Dst.Red * (1.0 - (SCA/255.0)) // Dst.Green = Src.Green * (SCA/255.0) + Dst.Green * (1.0 - (SCA/255.0)) // Dst.Blue = Src.Blue * (SCA/255.0) + Dst.Blue * (1.0 - (SCA/255.0)) // If the destination bitmap has an alpha channel, then the blend is as follows. // Dst.Alpha = Src.Alpha * (SCA/255.0) + Dst.Alpha * (1.0 - (SCA/255.0)) for (int y = height - 1; y > -1 && off < data.length; y--) { for (int x = 0; x < width && off < data.length; x++) { pixel = data[off++]; result.setRGB(x, y, new Color( (pixel & 0xFF0000) >> 16, (pixel & 0xFF00) >> 8, (pixel & 0xFF), // TODO not tested sourceConstantAlpha ).getRGB()); } } } // When the BlendOp parameter is AC_SRC_OVER , the source bitmap is placed over // the destination bitmap based on the alpha values of the source pixels. else { // If the source bitmap does not use SourceConstantAlpha (that is, it equals // 0xFF), the per-pixel alpha determines the blend of the source and destination // bitmaps, as shown in the following table. if (sourceConstantAlpha == 0xFF) { // Dst.Red = Src.Red + (1 - Src.Alpha) * Dst.Red // Dst.Green = Src.Green + (1 - Src.Alpha) * Dst.Green // Dst.Blue = Src.Blue + (1 - Src.Alpha) * Dst.Blue // If the destination bitmap has an alpha channel, then the blend is as follows. // Dest.alpha = Src.Alpha + (1 - SrcAlpha) * Dst.Alpha // image data are swapped compared to java standard for (int y = height - 1; y > -1 && off < data.length; y--) { for (int x = 0; x < width && off < data.length; x++) { pixel = data[off++]; alpha = (pixel & 0xFF000000) >> 24; if (alpha == -1) { alpha = 0xFF; } result.setRGB(x, y, new Color( (pixel & 0xFF0000) >> 16, (pixel & 0xFF00) >> 8, (pixel & 0xFF), alpha ).getRGB()); } } } // If the source has both the SourceConstantAlpha (that is, it is not 0xFF) // and per-pixel alpha, the source is pre-multiplied by the SourceConstantAlpha // and then the blend is based on the per-pixel alpha. The following tables show // this. Note that SourceConstantAlpha is divided by 255 because it has a value // that ranges from 0 to 255. else { // Src.Red = Src.Red * SourceConstantAlpha / 255.0; // Src.Green = Src.Green * SourceConstantAlpha / 255.0; // Src.Blue = Src.Blue * SourceConstantAlpha / 255.0; // Src.Alpha = Src.Alpha * SourceConstantAlpha / 255.0; // Dst.Red = Src.Red + (1 - Src.Alpha) * Dst.Red // Dst.Green = Src.Green + (1 - Src.Alpha) * Dst.Green // Dst.Blue = Src.Blue + (1 - Src.Alpha) * Dst.Blue // Dst.Alpha = Src.Alpha + (1 - Src.Alpha) * Dst.Alpha for (int y = height - 1; y > -1 && off < data.length; y--) { for (int x = 0; x < width && off < data.length; x++) { pixel = data[off++]; alpha = (pixel & 0xFF000000) >> 24; if (alpha == -1) { alpha = 0xFF; } // TODO not tested alpha = alpha * sourceConstantAlpha / 0xFF; result.setRGB(x, y, new Color( (pixel & 0xFF0000) >> 16, (pixel & 0xFF00) >> 8, (pixel & 0xFF), alpha ).getRGB()); } } } } /* for debugging: shows every loaded image javax.swing.JFrame f = new javax.swing.JFrame("test"); f.getContentPane().setBackground(Color.green); f.getContentPane().setLayout( new java.awt.BorderLayout(0, 0)); f.getContentPane().add( java.awt.BorderLayout.CENTER, new javax.swing.JLabel( new javax.swing.ImageIcon(result))); f.setSize(new java.awt.Dimension(width + 20, height + 20)); f.setVisible(true);*/ return result; } // If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, // the bmiColors member contains three DWORD color masks that specify the // red, green, and blue components, respectively, of each pixel. Each DWORD // in the bitmap array represents a single pixel. // Windows NT/ 2000: When the biCompression member is BI_BITFIELDS, bits set in // each DWORD mask must be contiguous and should not overlap the bits of // another mask. All the bits in the pixel do not need to be used. // Windows 95/98/Me: When the biCompression member is BI_BITFIELDS, the system // supports only the following 32-bpp color mask: The blue mask is 0x000000FF, // the green mask is 0x0000FF00, and the red mask is 0x00FF0000. else if ((bmi.getBitCount() == 32) && (bmi.getCompression() == EMFConstants.BI_BITFIELDS)) { /* byte[] bytes =*/ emf.readByte(len); return null; } else { /* byte[] bytes =*/ emf.readByte(len); return null; } } } a/src/main/java/org/freehep/graphicsio/emf/EMFInputStream.java000066400000000000000000000124751167637521400245310ustar00rootroot00000000000000// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.emf; import java.awt.Color; import java.awt.Dimension; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.AffineTransform; import java.io.IOException; import java.io.InputStream; import org.freehep.util.io.ActionHeader; import org.freehep.util.io.TagHeader; import org.freehep.util.io.TaggedInputStream; /** * This class extends the TaggedInputStream with several methods to read EMF * primitives from the stream and to read TagHeaders. * * @author Mark Donszelmann * @version $Id$ */ public class EMFInputStream extends TaggedInputStream implements EMFConstants { public static int DEFAULT_VERSION = 1; public EMFInputStream(InputStream is) { this(is, DEFAULT_VERSION); } public EMFInputStream(InputStream is, int version) { this(is, new EMFTagSet(version)); } public EMFInputStream(InputStream is, EMFTagSet tagSet) { // EMF is little-endian super(is, tagSet, null, true); } public int readDWORD() throws IOException { long i = readUnsignedInt(); return (int) i; } public int[] readDWORD(int size) throws IOException { int[] x = new int[size]; for (int i = 0; i < x.length; i++) { x[i] = readDWORD(); } return x; } public int readWORD() throws IOException { return readUnsignedShort(); } public int readLONG() throws IOException { return readInt(); } public int[] readLONG(int size) throws IOException { int[] x = new int[size]; for (int i = 0; i < x.length; i++) { x[i] = readLONG(); } return x; } public float readFLOAT() throws IOException { return readFloat(); } public int readUINT() throws IOException { return (int) readUnsignedInt(); } public int readULONG() throws IOException { return (int) readUnsignedInt(); } public Color readCOLORREF() throws IOException { Color c = new Color(readUnsignedByte(), readUnsignedByte(), readUnsignedByte()); readByte(); return c; } public Color readCOLOR16() throws IOException { return new Color(readShort() >> 8, readShort() >> 8, readShort() >> 8, readShort() >> 8); } public Color readCOLOR() throws IOException { int b = readUnsignedByte(); int g = readUnsignedByte(); int r = readUnsignedByte(); int a = readUnsignedByte(); Color c = new Color(r, g, b, a); return c; } public AffineTransform readXFORM() throws IOException { return new AffineTransform(readFLOAT(), readFLOAT(), readFLOAT(), readFLOAT(), readFLOAT(), readFLOAT()); } public Rectangle readRECTL() throws IOException { int x = readLONG(); int y = readLONG(); int w = readLONG() - x; int h = readLONG() - y; return new Rectangle(x, y, w, h); } public Point readPOINTL() throws IOException { int x = readLONG(); int y = readLONG(); return new Point(x, y); } public Point[] readPOINTL(int size) throws IOException { Point[] p = new Point[size]; for (int i = 0; i < p.length; i++) { p[i] = readPOINTL(); } return p; } public Point readPOINTS() throws IOException { int x = readShort(); int y = readShort(); return new Point(x, y); } public Point[] readPOINTS(int size) throws IOException { Point[] p = new Point[size]; for (int i = 0; i < p.length; i++) { p[i] = readPOINTS(); } return p; } public Dimension readSIZEL() throws IOException { return new Dimension(readLONG(), readLONG()); } public int readBYTE() throws IOException { return readByte(); } public byte[] readBYTE(int size) throws IOException { byte[] x = new byte[size]; for (int i = 0; i < x.length; i++) { x[i] = (byte) readBYTE(); } return x; } public boolean readBOOLEAN() throws IOException { return (readBYTE() != 0); } public String readWCHAR(int size) throws IOException { byte[] bytes = readByte(2 * size); int length = 2 * size; for (int i = 0; i < 2 * size; i += 2) { if (bytes[i] == 0 && bytes[i + 1] == 0) { length = i; break; } } return new String(bytes, 0, length, "UTF-16LE"); } protected TagHeader readTagHeader() throws IOException { // Read the tag. // byteAlign(); int tagID = read(); // End of stream if (tagID == -1) return null; tagID |= readUnsignedByte() << 8; int flags = readUnsignedByte(); flags |= readUnsignedByte() << 8; long length = readDWORD(); return new EMFTagHeader(tagID, length - 8, flags); } protected ActionHeader readActionHeader() throws IOException { return null; } private EMFHeader header; public EMFHeader readHeader() throws IOException { if (header == null) { header = new EMFHeader(this); } return header; } public int getVersion() { return DEFAULT_VERSION; } } a/src/main/java/org/freehep/graphicsio/emf/EMFOutputStream.java000066400000000000000000000161461167637521400247310ustar00rootroot00000000000000// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.emf; import java.awt.Color; import java.awt.Dimension; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.AffineTransform; import java.io.IOException; import java.io.OutputStream; import org.freehep.graphicsio.emf.gdi.GDIComment; import org.freehep.graphicsio.emf.gdiplus.EMFPlusTag; import org.freehep.util.io.ActionHeader; import org.freehep.util.io.Tag; import org.freehep.util.io.TagHeader; import org.freehep.util.io.TaggedOutputStream; /** * EMF Binary Output Stream. Tags written with this OutputStream will produce a * binary EMF file. * * @author Mark Donszelmann * @version $Id$ */ public class EMFOutputStream extends TaggedOutputStream { private String application; private String name; private int recordCount; private Rectangle imageBounds; private int version; private EMFHandleManager handles; private Dimension device; public EMFOutputStream(OutputStream os, Rectangle imageBounds, EMFHandleManager handles, String application, String name, Dimension device, int version) throws IOException { // EMF is little-endian super(os, new EMFTagSet(version), null, true); this.recordCount = 0; this.version = version; this.imageBounds = imageBounds; this.handles = handles; this.application = application; this.name = name; this.device = device; // will be popped by close() pushBuffer(); } public EMFOutputStream(OutputStream os, Rectangle imageBounds, EMFHandleManager handles, String application, String name, Dimension device) throws IOException { this(os, imageBounds, handles, application, name, device, 1); } public void close() throws IOException { int len = popBuffer(); recordCount++; // FIXME check this EMFHeader header = new EMFHeader(EMFHeader.TYPE_WMF, imageBounds, getVersion(), 0, len, recordCount, handles.maxHandlesUsed(), application, name, device); writeHeader(header); append(); super.close(); } // DWORD public void writeDWORD(int i) throws IOException { writeUnsignedInt(i); } // DWORD [] public void writeDWORD(int[] w) throws IOException { for (int i = 0; i < w.length; i++) { writeDWORD(w[i]); } } // WORD public void writeWORD(int s) throws IOException { writeUnsignedShort(s); } public void writeFLOAT(float f) throws IOException { writeFloat(f); } public void writeCOLORREF(Color c) throws IOException { writeByte(c.getRed()); writeByte(c.getGreen()); writeByte(c.getBlue()); // NOTE: if not 0x00 EMF does not display correctly in full screen mode. writeByte(0x00); } // COLOR16 public void writeCOLOR16(Color c) throws IOException { writeShort(c.getRed() << 8); writeShort(c.getGreen() << 8); writeShort(c.getBlue() << 8); writeShort(c.getAlpha() << 8); } public void writeCOLOR(Color c) throws IOException { writeByte(c.getBlue()); writeByte(c.getGreen()); writeByte(c.getRed()); writeByte(c.getAlpha()); } public void writeXFORM(AffineTransform t) throws IOException { writeFLOAT((float) t.getScaleX()); writeFLOAT((float) t.getShearY()); writeFLOAT((float) t.getShearX()); writeFLOAT((float) t.getScaleY()); writeFLOAT((float) t.getTranslateX()); writeFLOAT((float) t.getTranslateY()); } // POINTS [] public void writePOINTS(Point[] p) throws IOException { writePOINTS(p.length, p); } public void writePOINTS(int n, Point[] p) throws IOException { for (int i = 0; i < n; i++) { writePOINTS(p[i]); } } public void writePOINTS(Point p) throws IOException { writeSHORT((short) p.x); writeSHORT((short) p.y); } // POINTL [] public void writePOINTL(Point[] p) throws IOException { writePOINTL(p.length, p); } public void writePOINTL(int n, Point[] p) throws IOException { for (int i = 0; i < n; i++) { writePOINTL(p[i]); } } // POINTL public void writePOINTL(Point p) throws IOException { writeLONG(p.x); writeLONG(p.y); } // RECTL public void writeRECTL(Rectangle r) throws IOException { writeLONG(r.x); writeLONG(r.y); writeLONG(r.x + r.width); writeLONG(r.y + r.height); } // SIZEL public void writeSIZEL(Dimension d) throws IOException { writeLONG(d.width); writeLONG(d.height); } // UINT public void writeUINT(int i) throws IOException { writeUnsignedInt(i); } // ULONG public void writeULONG(int i) throws IOException { writeUnsignedInt(i); } // LONG public void writeLONG(int i) throws IOException { writeInt(i); } public void writeSHORT(short i) throws IOException { writeShort(i); } // BYTE [] public void writeBYTE(byte[] b) throws IOException { writeByte(b); } // BYTE public void writeBYTE(byte b) throws IOException { writeByte(b); } // BYTE public void writeBYTE(int b) throws IOException { writeByte(b); } public void writeBYTE(boolean b) throws IOException { writeBYTE((b) ? 1 : 0); } public void writeWORD(boolean b) throws IOException { writeWORD((b) ? 1 : 0); } public void writeDWORD(boolean b) throws IOException { writeDWORD((b) ? 1 : 0); } public void writeWCHAR(String s) throws IOException { writeByte(s.getBytes("UTF-16LE")); } public void writeWCHAR(String s, int size) throws IOException { writeWCHAR(s); for (int i = size - s.length(); i > 0; i--) { writeWORD(0); } } protected int getTagAlignment() { return 4; } protected TagHeader createTagHeader(Tag tag, long len) { EMFTag emfTag = (EMFTag)tag; return new EMFTagHeader(tag.getTag(), len, emfTag.getFlags()); } protected void writeTagHeader(TagHeader header) throws IOException { EMFTagHeader tagHeader = (EMFTagHeader)header; writeUnsignedInt(tagHeader.getTag() | (tagHeader.getFlags() << 16)); writeUnsignedInt(tagHeader.getLength() + 8); } public void writeTag(Tag tag) throws IOException { // nest EMFPlusTags in GDIComments if (tag instanceof EMFPlusTag) { tag = new GDIComment((EMFPlusTag)tag); } writeTag(tag, true); } public void writeTag(Tag tag, boolean doNotEmbed) throws IOException { recordCount++; super.writeTag(tag); } protected void writeActionHeader(ActionHeader header) throws IOException { // empty } public void writeHeader(EMFHeader header) throws IOException { header.write(this); } public int getVersion() { return version; } } a/src/main/java/org/freehep/graphicsio/emf/EMFPanel.java000066400000000000000000000044461167637521400233140ustar00rootroot00000000000000// Copyright 2007 FreeHEP package org.freehep.graphicsio.emf; import javax.swing.JComponent; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; /** * simple panel which displays an EMF image using the {@link EMFRenderer} * * @author Steffen Greiffenberg * @version $id$ */ public class EMFPanel extends JComponent { /** * factor used for zoom in an out */ private static double SCALE_FACTOR = 2; /** * renders an EMF image to a Graphics2D instance */ private EMFRenderer renderer; /** * used for zooming */ private double scale = 1; /** * defines a white background */ public EMFPanel() { setBackground(Color.white); } /** * sets the renderer an resets size * @param renderer EMFRenderer to display */ public void setRenderer(EMFRenderer renderer) { this.renderer = renderer; scale = 1; setSize(getPreferredSize()); } /** * @return {@link EMFRenderer#getSize()} for the renderer */ public Dimension getPreferredSize() { if (renderer == null) { return new Dimension(0, 0); } Dimension bounds = renderer.getSize(); return new Dimension( (int)Math.ceil(bounds.width * scale), (int)Math.ceil(bounds.height * scale)); } /** * paints using the renderer * @param g Context of the component */ public void paintComponent(Graphics g) { Graphics2D g2 = ((Graphics2D)g); super.paintComponent(g2); if (renderer == null) { return; } // to restore AffineTransform AffineTransform at = g2.getTransform(); // apply the scale factor g2.scale(scale, scale); // render the emf renderer.paint(g2); // rest the AffineTransform g2.setTransform(at); } /** * scale = scale * 2 */ public void zoomIn() { scale = scale * SCALE_FACTOR; setSize(getPreferredSize()); repaint(); } /** * scale = scale / 2; */ public void zoomOut() { scale = scale / SCALE_FACTOR; setSize(getPreferredSize()); repaint(); } } a/src/main/java/org/freehep/graphicsio/emf/EMFPathConstructor.java000066400000000000000000000067451167637521400254230ustar00rootroot00000000000000// Copyright 2001 FreeHEP. package org.freehep.graphicsio.emf; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.QuadToCubicPathConstructor; import org.freehep.graphicsio.emf.gdi.CloseFigure; import org.freehep.graphicsio.emf.gdi.LineTo; import org.freehep.graphicsio.emf.gdi.MoveToEx; import org.freehep.graphicsio.emf.gdi.PolyBezierTo; import org.freehep.graphicsio.emf.gdi.PolyBezierTo16; import org.freehep.graphicsio.emf.gdi.PolylineTo; import org.freehep.graphicsio.emf.gdi.PolylineTo16; /** * @author Mark Donszelmann * @version $Id$ */ public class EMFPathConstructor extends QuadToCubicPathConstructor implements EMFConstants { private EMFOutputStream os; private Rectangle imageBounds; private boolean curved; private int pointIndex = 0; private boolean wide = false; private Point[] points = new Point[4]; public EMFPathConstructor(EMFOutputStream os, Rectangle imageBounds) { super(); this.os = os; this.imageBounds = imageBounds; this.curved = false; } public void move(double x, double y) throws IOException { flush(); os.writeTag(new MoveToEx(new Point(toUnit(x), toUnit(y)))); super.move(x, y); } private void addPoint(int n, double x, double y) { if (n >= points.length) { Point[] buf = new Point[n << 1]; System.arraycopy(points, 0, buf, 0, points.length); points = buf; } int ix = toUnit(x); int iy = toUnit(y); if (wide || (ix < Short.MIN_VALUE) || (ix > Short.MAX_VALUE) || (iy < Short.MIN_VALUE) || (iy > Short.MAX_VALUE)) { wide = true; } if (points[n] == null) { points[n] = new Point(ix, iy); } else { points[n].x = ix; points[n].y = iy; } } public void line(double x, double y) throws IOException { if (curved && (pointIndex > 0)) flush(); curved = false; addPoint(pointIndex++, x, y); super.line(x, y); } public void cubic(double x1, double y1, double x2, double y2, double x3, double y3) throws IOException { if (!curved && (pointIndex > 0)) flush(); curved = true; addPoint(pointIndex++, x1, y1); addPoint(pointIndex++, x2, y2); addPoint(pointIndex++, x3, y3); super.cubic(x1, y1, x2, y2, x3, y3); } public void closePath(double x0, double y0) throws IOException { flush(); os.writeTag(new CloseFigure()); super.closePath(x0, y0); } public void flush() throws IOException { if (curved) { if (wide) { os.writeTag(new PolyBezierTo(imageBounds, pointIndex, points)); } else { os .writeTag(new PolyBezierTo16(imageBounds, pointIndex, points)); } } else if (pointIndex == 1) { os.writeTag(new LineTo(points[0])); } else if (pointIndex > 1) { if (wide) { os.writeTag(new PolylineTo(imageBounds, pointIndex, points)); } else { os.writeTag(new PolylineTo16(imageBounds, pointIndex, points)); } } pointIndex = 0; wide = false; super.flush(); } protected int toUnit(double d) { return (int) (d * UNITS_PER_PIXEL * TWIPS); } } a/src/main/java/org/freehep/graphicsio/emf/EMFPlusExportFileType.java000066400000000000000000000041251167637521400260360ustar00rootroot00000000000000// Copyright 2006 FreeHEP package org.freehep.graphicsio.emf; import java.awt.Component; import java.awt.Dimension; import java.io.IOException; import java.io.OutputStream; import java.util.Properties; import javax.swing.JLabel; import javax.swing.JPanel; import org.freehep.graphics2d.VectorGraphics; import org.freehep.graphicsio.exportchooser.AbstractExportFileType; import org.freehep.graphicsio.exportchooser.BackgroundPanel; import org.freehep.graphicsio.exportchooser.OptionPanel; import org.freehep.swing.layout.TableLayout; import org.freehep.util.UserProperties; /** * * @author Mark Donszelmann * @version $Id: EMFExportFileType.java 10100 2006-11-30 18:44:02Z duns $ */ public class EMFPlusExportFileType extends AbstractExportFileType { public String getDescription() { return "Windows Enhanced Metafile Plus"; } public String[] getExtensions() { // NOTE: the extension emf+ is strictly not correct, but ExportFileType will not select it otherwise. return new String[] { "emf", "emf+" }; } public String[] getMIMETypes() { return new String[] { "image/x-emf" }; } public boolean hasOptionPanel() { return true; } public JPanel createOptionPanel(Properties user) { UserProperties options = new UserProperties(user, EMFGraphics2D .getDefaultProperties()); String rootKey = EMFPlusGraphics2D.class.getName(); // Make the full panel. OptionPanel optionsPanel = new OptionPanel(); optionsPanel.add("0 0 [5 5 5 5] wt", new BackgroundPanel(options, rootKey, true)); optionsPanel.add(TableLayout.COLUMN_FILL, new JLabel()); return optionsPanel; } public VectorGraphics getGraphics(OutputStream os, Component target) throws IOException { return new EMFPlusGraphics2D(os, target); } public VectorGraphics getGraphics(OutputStream os, Dimension size) throws IOException { return new EMFPlusGraphics2D(os, size); } } a/src/main/java/org/freehep/graphicsio/emf/EMFPlusGraphics2D.java000066400000000000000000000330251167637521400250420ustar00rootroot00000000000000// Copyright 2006, FreeHEP package org.freehep.graphicsio.emf; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.GraphicsConfiguration; import java.awt.Paint; import java.awt.Rectangle; import java.awt.Shape; import java.awt.Stroke; import java.awt.TexturePaint; import java.awt.Toolkit; import java.awt.font.FontRenderContext; import java.awt.geom.AffineTransform; import java.awt.geom.Area; import java.awt.image.RenderedImage; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Properties; import org.freehep.graphics2d.VectorGraphics; import org.freehep.graphicsio.AbstractVectorGraphicsIO; import org.freehep.graphicsio.PageConstants; import org.freehep.graphicsio.emf.gdi.EOF; import org.freehep.graphicsio.emf.gdiplus.Clear; import org.freehep.graphicsio.emf.gdiplus.DrawImage; import org.freehep.graphicsio.emf.gdiplus.DrawPath; import org.freehep.graphicsio.emf.gdiplus.EndOfFile; import org.freehep.graphicsio.emf.gdiplus.FillPath; import org.freehep.graphicsio.emf.gdiplus.GDIPlusObject; import org.freehep.graphicsio.emf.gdiplus.Header; import org.freehep.graphicsio.emf.gdiplus.MultiplyWorldTransform; import org.freehep.graphicsio.emf.gdiplus.ResetClip; import org.freehep.graphicsio.emf.gdiplus.Restore; import org.freehep.graphicsio.emf.gdiplus.Save; import org.freehep.graphicsio.emf.gdiplus.SetAntiAliasMode; import org.freehep.graphicsio.emf.gdiplus.SetClipPath; import org.freehep.graphicsio.emf.gdiplus.SetWorldTransform; import org.freehep.util.UserProperties; import org.freehep.util.Value; /** * Converts calls to Graphics2D to EMF+ Format. * * @author Mark Donszelmann * @version $Id: DummyGraphics2D.java 8584 2006-08-10 23:06:37Z duns $ */ public class EMFPlusGraphics2D extends AbstractVectorGraphicsIO { public static final String version = "$Revision: 10140 $"; private OutputStream ros; private EMFOutputStream os; private Rectangle imageBounds; // FIXME do we need this? private EMFHandleManager handleManager; private Value containerIndex; private Paint restorePaint; private static final String rootKey = EMFPlusGraphics2D.class.getName(); public static final String TRANSPARENT = rootKey + "." + PageConstants.TRANSPARENT; public static final String BACKGROUND = rootKey + "." + PageConstants.BACKGROUND; public static final String BACKGROUND_COLOR = rootKey + "." + PageConstants.BACKGROUND_COLOR; private static final UserProperties defaultProperties = new UserProperties(); static { defaultProperties.setProperty(TRANSPARENT, true); defaultProperties.setProperty(BACKGROUND, false); defaultProperties.setProperty(BACKGROUND_COLOR, Color.GRAY); defaultProperties.setProperty(CLIP, true); defaultProperties.setProperty(TEXT_AS_SHAPES, true); } public static Properties getDefaultProperties() { return defaultProperties; } // FIXME public FontRenderContext getFontRenderContext() { // NOTE: not sure? return new FontRenderContext(new AffineTransform(-1, 0, 0, 1, 0, 0), true, true); } public static void setDefaultProperties(Properties newProperties) { defaultProperties.setProperties(newProperties); } public EMFPlusGraphics2D(File file, Dimension size) throws FileNotFoundException { this(new FileOutputStream(file), size); } public EMFPlusGraphics2D(File file, Component component) throws FileNotFoundException { this(new FileOutputStream(file), component); } public EMFPlusGraphics2D(OutputStream os, Dimension size) { super(size, false); this.imageBounds = new Rectangle(0, 0, size.width, size.height); init(os); } public EMFPlusGraphics2D(OutputStream os, Component component) { super(component, false); this.imageBounds = new Rectangle(0, 0, getSize().width, getSize().height); init(os); } private void init(OutputStream os) { handleManager = new EMFHandleManager(); ros = os; containerIndex = new Value(); containerIndex.set(0); initProperties(defaultProperties); } protected EMFPlusGraphics2D(EMFPlusGraphics2D graphics, boolean doRestoreOnDispose) { super(graphics, doRestoreOnDispose); // Create a graphics context from a given graphics context. // This constructor is used by the system to clone a given graphics // context. // doRestoreOnDispose is used to call writeGraphicsRestore(), // when the graphics context is being disposed off. os = graphics.os; imageBounds = graphics.imageBounds; handleManager = graphics.handleManager; containerIndex = graphics.containerIndex; restorePaint = graphics.getPaint(); } public void writeHeader() throws IOException { ros = new BufferedOutputStream(ros); Dimension device = isDeviceIndependent() ? new Dimension(1024, 768) : Toolkit.getDefaultToolkit().getScreenSize(); String producer = getClass().getName(); if (!isDeviceIndependent()) { producer += " " + version.substring(1, version.length() - 1); } os = new EMFOutputStream(ros, imageBounds, handleManager, getCreator(), producer, device, 0x4001); os.writeTag(new Header()); // leave this on since we do text as shapes. os.writeTag(new SetAntiAliasMode(true)); //Point orig = new Point(imageBounds.x, imageBounds.y); //Dimension size = new Dimension(imageBounds.width, imageBounds.height); // FIXME check what to write // os.writeTag(new SetMapMode(MM_ANISOTROPIC)); // os.writeTag(new SetWindowOrgEx(orig)); // os.writeTag(new SetWindowExtEx(size)); // os.writeTag(new SetViewportOrgEx(orig)); // os.writeTag(new SetViewportExtEx(size)); // os.writeTag(new SetTextAlign(TA_BASELINE)); // os.writeTag(new SetTextColor(getColor())); // os.writeTag(new SetPolyFillMode(EMFConstants.WINDING)); } public void writeBackground() throws IOException { if (isProperty(TRANSPARENT)) { setBackground(null); // FIXME // os.writeTag(new Clear(new Color(0xFF, 0xFF, 0xFF, 0x00))); } else if (isProperty(BACKGROUND)) { setBackground(getPropertyColor(BACKGROUND_COLOR)); os.writeTag(new Clear(getBackground())); } else { setBackground(getComponent() != null ? getComponent() .getBackground() : Color.WHITE); os.writeTag(new Clear(getBackground())); } } public void writeTrailer() throws IOException { // delete any remaining objects for (;;) { int handle = handleManager.highestHandleInUse(); if (handle < 0) break; // os.writeTag(new DeleteObject(handle)); handleManager.freeHandle(handle); } os.writeTag(new EndOfFile()); os.writeTag(new EOF()); } public void closeStream() throws IOException { os.close(); } public Graphics create() { // Create a new graphics context from the current one. try { // Save the current context for restore later. writeGraphicsSave(); } catch (IOException e) { handleException(e); } // The correct graphics context should be created. return new EMFPlusGraphics2D(this, true); } public Graphics create(double x, double y, double width, double height) { // Create a new graphics context from the current one. try { // Save the current context for restore later. writeGraphicsSave(); } catch (IOException e) { handleException(e); } // The correct graphics context should be created. VectorGraphics graphics = new EMFPlusGraphics2D(this, true); graphics.translate(x, y); graphics.clipRect(0, 0, width, height); return graphics; } protected void writeGraphicsSave() throws IOException { os.writeTag(new Save(containerIndex.getInt())); containerIndex.set(containerIndex.getInt()+1); } protected void writeGraphicsRestore() throws IOException { containerIndex.set(containerIndex.getInt()-1); os.writeTag(new Restore(containerIndex.getInt())); if (restorePaint != null) writePaint(restorePaint); } public void draw(Shape shape) { try { Stroke stroke = getStroke(); if ((stroke instanceof BasicStroke) && (((BasicStroke)stroke).getLineWidth() == 0)) { os.writeTag(new GDIPlusObject(1, shape, false)); os.writeTag(new GDIPlusObject(2, new BasicStroke(0), getPaint())); os.writeTag(new DrawPath(1, 2)); } else { Shape strokedShape = getStroke().createStrokedShape(shape); fill(new Area(strokedShape)); } } catch (IOException e) { handleException(e); } } public void fill(Shape shape) { try { os.writeTag(new GDIPlusObject(1, shape, false)); os.writeTag(new FillPath(1, 0)); } catch (IOException e) { handleException(e); } } public void copyArea(int x, int y, int width, int height, int dx, int dy) { writeWarning(getClass() + ": copyArea(int, int, int, int, int, int) not implemented."); // Mostly unimplemented. } protected void writeImage(RenderedImage image, AffineTransform xform, Color bkg) throws IOException { // FIXME use BKG and xform writeGraphicsSave(); os.writeTag(new GDIPlusObject(5, image)); os.writeTag(new MultiplyWorldTransform(xform, true)); os.writeTag(new DrawImage(5, image)); writeGraphicsRestore(); } protected void writeString(String string, double x, double y) throws IOException { // text is drawn as shapes } protected void writeTransform(AffineTransform t) throws IOException { os.writeTag(new MultiplyWorldTransform(t, true)); } protected void writeSetTransform(AffineTransform t) throws IOException { os.writeTag(new SetWorldTransform(t)); } protected void writeClip(Shape s) throws IOException { os.writeTag(new GDIPlusObject(4, s, false)); os.writeTag(new SetClipPath(4, SetClipPath.INTERSECT)); } protected void writeSetClip(Shape s) throws IOException { if (s != null) { os.writeTag(new GDIPlusObject(4, s, false)); os.writeTag(new SetClipPath(4, SetClipPath.REPLACE)); } else { os.writeTag(new ResetClip()); } } protected void writeWidth(float width) throws IOException { // settings convert to shape } protected void writeCap(int cap) throws IOException { // settings convert to shape } protected void writeJoin(int join) throws IOException { // settings convert to shape } protected void writeMiterLimit(float limit) throws IOException { // settings convert to shape } protected void writeDash(float[] dash, float phase) throws IOException { // settings convert to shape } public void setPaintMode() { writeWarning(getClass() + ": setPaintMode() not implemented."); // Mostly unimplemented. } public void setXORMode(Color c1) { writeWarning(getClass() + ": setXORMode(Color) not implemented."); // Mostly unimplemented. } protected void writePaint(Color p) throws IOException { os.writeTag(new GDIPlusObject(0, p)); } protected void writePaint(GradientPaint p) throws IOException { os.writeTag(new GDIPlusObject(0, p)); } protected void writePaint(TexturePaint p) throws IOException { os.writeTag(new GDIPlusObject(0, p)); } protected void writePaint(Paint p) throws IOException { os.writeTag(new GDIPlusObject(0, p)); } protected void writeFont(Font font) throws IOException { // text converts to shapes } public GraphicsConfiguration getDeviceConfiguration() { writeWarning(getClass() + ": getDeviceConfiguration() not implemented."); // Mostly unimplemented return null; } public boolean hit(Rectangle rect, Shape s, boolean onStroke) { writeWarning(getClass() + ": hit(Rectangle, Shape, boolean) not implemented."); // Mostly unimplemented return false; } public void writeComment(String comment) throws IOException { writeWarning(getClass() + ": writeComment(String) not implemented."); // Write out the comment. } protected void writeWarning(String string) { System.err.println(string); } public String toString() { return "EMFPlusGraphics2D"; } } a/src/main/java/org/freehep/graphicsio/emf/EMFRenderer.java000066400000000000000000000635731167637521400240310ustar00rootroot00000000000000package org.freehep.graphicsio.emf; import java.io.IOException; import java.awt.Graphics2D; import java.awt.Dimension; import java.awt.Point; import java.awt.BasicStroke; import java.awt.Stroke; import java.awt.Paint; import java.awt.Color; import java.awt.Shape; import java.awt.AlphaComposite; import java.awt.Image; import java.awt.RenderingHints; import java.awt.Font; import java.awt.image.BufferedImage; import java.awt.font.TextLayout; import java.awt.geom.AffineTransform; import java.awt.geom.GeneralPath; import java.util.logging.Logger; import java.util.Stack; import java.util.Vector; import java.util.Map; import org.freehep.util.io.Tag; import org.freehep.graphicsio.emf.gdi.GDIObject; /** * Standalone EMF renderer. * * @author Daniel Noll (daniel@nuix.com) * @version $Id$ */ public class EMFRenderer { private static final Logger logger = Logger.getLogger("org.freehep.graphicsio.emf"); /** * Header read from the EMFInputStream */ private EMFHeader header; /** * Each logical unit is mapped to one twentieth of a * printer's point (1/1440 inch, also called a twip). */ public static double TWIP_SCALE = 1d / 1440 * 254; /** * affect by all XXXTo methods, e.g. LinTo. ExtMoveTo creates the * starting point. CloseFigure closes the figure. */ private GeneralPath figure = null; /** * AffineTransform which is the base for all rendering * operations. */ private AffineTransform initialTransform; /** * origin of the emf window, set by SetWindowOrgEx */ private Point windowOrigin = null; /** * origin of the emf viewport, set By SetViewportOrgEx */ private Point viewportOrigin = null; /** * size of the emf window, set by SetWindowExtEx */ private Dimension windowSize = null; /** * size of the emf viewport, set by SetViewportExtEx */ private Dimension viewportSize = null; /** * The MM_ISOTROPIC mode ensures a 1:1 aspect ratio. * The MM_ANISOTROPIC mode allows the x-coordinates * and y-coordinates to be adjusted independently. */ private boolean mapModeIsotropic = false; /** * AffineTransform defined by SetMapMode. Used for * resizing the emf to propper device bounds. */ private AffineTransform mapModeTransform = AffineTransform.getScaleInstance(TWIP_SCALE, TWIP_SCALE); /** * clipping area which is the base for all rendering * operations. */ private Shape initialClip; /** * current Graphics2D to paint on. It is set during * {@link #paint(java.awt.Graphics2D)} */ private Graphics2D g2; /** * objects used by {@link org.freehep.graphicsio.emf.gdi.SelectObject}. * The array is filled by CreateXXX functions, e.g. * {@link org.freehep.graphicsio.emf.gdi.CreatePen} */ private GDIObject[] gdiObjects = new GDIObject[256]; // TODO: Make this more flexible. // Rendering state. private Paint brushPaint = new Color(0, 0, 0, 0); private Paint penPaint = Color.BLACK; private Stroke penStroke = new BasicStroke(); private int textAlignMode = 0; /** * color for simple text rendering */ private Color textColor = Color.BLACK; /** * written by {@link org.freehep.graphicsio.emf.gdi.SetPolyFillMode} used by * e.g. {@link org.freehep.graphicsio.emf.gdi.PolyPolygon16} */ private int windingRule = GeneralPath.WIND_EVEN_ODD; /** * Defined by SetBkModes, either {@link EMFConstants#BKG_OPAQUE} or * {@link EMFConstants#BKG_TRANSPARENT}. Used in * {@link #fillAndDrawOrAppend(java.awt.Graphics2D, java.awt.Shape)} */ private int bkMode = EMFConstants.BKG_OPAQUE; /** * The SetBkMode function affects the line styles for lines drawn using a * pen created by the CreatePen function. SetBkMode does not affect lines * drawn using a pen created by the ExtCreatePen function. */ private boolean useCreatePen = true; /** * The miter length is defined as the distance from the intersection * of the line walls on the inside of the join to the intersection of * the line walls on the outside of the join. The miter limit is the * maximum allowed ratio of the miter length to the line width. */ private int meterLimit = 10; /** * The SetROP2 function sets the current foreground mix mode. * Default is to use the pen. */ private int rop2 = EMFConstants.R2_COPYPEN; /** * e.g. {@link Image#SCALE_SMOOTH} for rendering images */ private int scaleMode = Image.SCALE_SMOOTH; /** * The brush origin is a pair of coordinates specifying the location of one * pixel in the bitmap. The default brush origin coordinates are (0,0). For * horizontal coordinates, the value 0 corresponds to the leftmost column * of pixels; the width corresponds to the rightmost column. For vertical * coordinates, the value 0 corresponds to the uppermost row of pixels; * the height corresponds to the lowermost row. */ private Point brushOrigin = new Point(0, 0); /** * stores the parsed tags. Filled by the constructor. Read by * {@link #paint(java.awt.Graphics2D)} */ private Vector tags = new Vector(0); /** * Created by BeginPath and closed by EndPath. */ private GeneralPath path = null; /** * The transformations set by ModifyWorldTransform are redirected to * that AffineTransform. They do not affect the current paint context, * after BeginPath is called. Only the figures appended to path * are transformed by this AffineTransform. * BeginPath clears the transformation, ModifyWorldTransform changes ist. */ private AffineTransform pathTransform = new AffineTransform(); /** * {@link org.freehep.graphicsio.emf.gdi.SaveDC} stores * an Instance of DC if saveDC is read. RestoreDC pops an object. */ private Stack dcStack = new Stack(); /** * default direction is counterclockwise */ private int arcDirection = EMFConstants.AD_COUNTERCLOCKWISE; /** * Class the encapsulate the state of a Graphics2D object. * Instances are store in dcStack by * {@link org.freehep.graphicsio.emf.EMFRenderer#paint(java.awt.Graphics2D)} */ private class DC { private Paint paint; private Stroke stroke; private AffineTransform transform; private Shape clip; public GeneralPath path; public int bkMode; public int windingRule; public int meterLimit; public boolean useCreatePen; public int scaleMode; public AffineTransform pathTransform; } /** * Constructs the renderer. * * @param is the input stream to read the EMF records from. * @throws IOException if an error occurs reading the header. */ public EMFRenderer(EMFInputStream is) throws IOException { this.header = is.readHeader(); // read all tags Tag tag; while ((tag = is.readTag()) != null) { tags.add(tag); } is.close(); } /** * Gets the size of a canvas which would be required to render the EMF. * * @return the size. */ public Dimension getSize() { return header.getBounds().getSize(); // TODO see the mapModePart of resetTransformation() // if uncommented size is too small /* Dimension bounds = header.getBounds().getSize(); return new Dimension( (int)Math.ceil(bounds.width * TWIP_SCALE), (int)Math.ceil(bounds.height * TWIP_SCALE));*/ } /** * Paints the EMF onto the provided graphics context. * * @param g2 the graphics context to paint onto. */ public void paint(Graphics2D g2) { this.g2 = g2; // store at leat clip and transformation Shape clip = g2.getClip(); AffineTransform at = g2.getTransform(); Map hints = g2.getRenderingHints(); // some quality settings g2.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // used by SetWorldTransform to reset transformation initialTransform = g2.getTransform(); // set the initial value, defaults for EMF path = null; figure = null; meterLimit = 10; windingRule = GeneralPath.WIND_EVEN_ODD; bkMode = EMFConstants.BKG_OPAQUE; useCreatePen = true; scaleMode = Image.SCALE_SMOOTH; windowOrigin = null; viewportOrigin = null; windowSize = null; viewportSize = null; mapModeIsotropic = false; mapModeTransform = AffineTransform.getScaleInstance( TWIP_SCALE, TWIP_SCALE); // apply all default settings resetTransformation(g2); // determin initial clip after all basic transformations initialClip = g2.getClip(); // iterate and render all tags Tag tag; for (int i = 0; i < tags.size(); i++) { tag = (Tag) tags.get(i); if (tag instanceof EMFTag) { ((EMFTag) tags.get(i)).render(this); } else { logger.warning("unknown tag: " + tag); } } // reset Transform and clip g2.setRenderingHints(hints); g2.setTransform(at); g2.setClip(clip); } // --------------------------------------------------------------------- // complex drawing methods for EMFTags // --------------------------------------------------------------------- /** * set the initial transform, the windowOrigin and viewportOrigin, * scales by viewportSize and windowSize * @param g2 Context to apply transformations */ private void resetTransformation(Graphics2D g2) { // rest to device configuration if (initialTransform != null) { g2.setTransform(initialTransform); } else { g2.setTransform(new AffineTransform()); } /* TODO mapModeTransform dows not work correctly if (mapModeTransform != null) { g2.transform(mapModeTransform); }*/ // move to window origin if (windowOrigin != null) { g2.translate( - windowOrigin.getX(), - windowOrigin.getY()); } // move to window origin if (viewportOrigin != null) { g2.translate( - viewportOrigin.getX(), - viewportOrigin.getY()); } // TWIP_SCALE by window and viewport size if (viewportSize != null && windowSize != null) { double scaleX = viewportSize.getWidth() / windowSize.getWidth(); double scaleY = viewportSize.getHeight() / windowSize.getHeight(); g2.scale(scaleX, scaleY); } } /** * Stores the current state. Used by * {@link org.freehep.graphicsio.emf.gdi.SaveDC} */ public void saveDC() { // create a DC instance with current settings DC dc = new DC(); dc.paint = g2.getPaint(); dc.stroke = g2.getStroke(); dc.transform = g2.getTransform(); dc.pathTransform = pathTransform; dc.clip = g2.getClip(); dc.path = path; dc.meterLimit = meterLimit; dc.windingRule = windingRule; dc.bkMode = bkMode; dc.useCreatePen = useCreatePen; dc.scaleMode = scaleMode; // push it on top of the stack dcStack.push(dc); } /** * Retores a saved state. Used by * {@link org.freehep.graphicsio.emf.gdi.RestoreDC} */ public void retoreDC() { // is somethoing stored? if (!dcStack.empty()) { // read it DC dc = (DC) dcStack.pop(); // use it meterLimit = dc.meterLimit; windingRule = dc.windingRule; path = dc.path; bkMode = dc.bkMode; useCreatePen = dc.useCreatePen; scaleMode = dc.scaleMode; pathTransform = dc.pathTransform; g2.setPaint(dc.paint); g2.setStroke(dc.stroke); g2.setTransform(dc.transform); g2.setClip(dc.clip); } else { // set the default values } } /** * closes and appends the current open figure to the * path */ public void closeFigure() { if (figure == null) { return; } try { figure.closePath(); appendToPath(figure); figure = null; } catch (java.awt.geom.IllegalPathStateException e) { logger.warning("no figure to close"); } } /** * Logical units are mapped to arbitrary units with equally scaled axes; * that is, one unit along the x-axis is equal to one unit along the y-axis. * Use the SetWindowExtEx and SetViewportExtEx functions to specify the * units and the orientation of the axes. Graphics device interface (GDI) * makes adjustments as necessary to ensure the x and y units remain the * same size (When the window extent is set, the viewport will be adjusted * to keep the units isotropic). */ public void fixViewportSize() { if (mapModeIsotropic && (windowSize != null && viewportSize != null)) { viewportSize.setSize( viewportSize.getWidth(), viewportSize.getWidth() * (windowSize.getHeight() / windowSize.getWidth()) ); } } /** * fills a shape using the brushPaint, penPaint and penStroke * @param g2 Painting context * @param s Shape to fill with current brush */ private void fillAndDrawOrAppend(Graphics2D g2, Shape s) { // don't draw, just append the shape if BeginPath // has opened the path if (!appendToPath(s)) { // The SetBkMode function affects the line styles for lines drawn using a // pen created by the CreatePen function. SetBkMode does not affect lines // drawn using a pen created by the ExtCreatePen function. if (useCreatePen) { // OPAQUE Background is filled with the current background // color before the text, hatched brush, or pen is drawn. if (bkMode == EMFConstants.BKG_OPAQUE) { fillShape(g2, s); } else { // TRANSPARENT Background remains untouched. // TODO: if we really do nothing some drawings are incomplete // this needs definitly a fix fillShape(g2, s); } } else { // always fill the background if ExtCreatePen is set fillShape(g2, s); } drawShape(g2, s); } } /** * draws a shape using the penPaint and penStroke * @param g2 Painting context * @param s Shape to draw with current paen */ private void drawOrAppend(Graphics2D g2, Shape s) { // don't draw, just append the shape if BeginPath // opens a GeneralPath if (!appendToPath(s)) { drawShape(g2, s); } } /** * draws the text * * @param text Text * @param x x-Position * @param y y-Position */ public void drawOrAppendText(String text, double x, double y) { // TODO: Use explicit widths to pixel-position each character, if present. // TODO: Implement alignment properly. What we have already seems to work well enough. // FontRenderContext frc = g2.getFontRenderContext(); // TextLayout layout = new TextLayout(str, g2.getFont(), frc); // if ((textAlignMode & EMFConstants.TA_CENTER) != 0) { // layout.draw(g2, x + (width - textWidth) / 2, y); // } else if ((textAlignMode & EMFConstants.TA_RIGHT) != 0) { // layout.draw(g2, x + width - textWidth, y); // } else { // layout.draw(g2, x, y); // } if (path != null) { // do not use g2.drawString(str, x, y) to be aware of path TextLayout tl = new TextLayout( text, g2.getFont(), g2.getFontRenderContext()); path.append(tl.getOutline(null), false); } else { g2.setPaint(textColor); g2.drawString(text, (int)x, (int)y); } } /** * Append the shape to the current path * * @param s Shape to fill with current brush * @return true, if path was changed */ private boolean appendToPath(Shape s) { // don't draw, just append the shape if BeginPath // opens a GeneralPath if (path != null) { // aplly transformation if set if (pathTransform != null) { s = pathTransform.createTransformedShape(s); } // append the shape path.append(s, false); // current path set return true; } // current path not set return false; } /** * closes the path opened by {@link org.freehep.graphicsio.emf.gdi.BeginPath} */ public void closePath() { if (path != null) { try { path.closePath(); } catch (java.awt.geom.IllegalPathStateException e) { logger.warning("no figure to close"); } } } /** * fills a shape using the brushPaint, penPaint and penStroke. * This method should only be called for path painting. It doesn't check for a * current path. * * @param g2 Painting context * @param s Shape to fill with current brush */ private void fillShape(Graphics2D g2, Shape s) { g2.setPaint(brushPaint); g2.fill(s); } /** * draws a shape using the penPaint and penStroke * This method should only be called for path drawing. It doesn't check for a * current path. * * @param g2 Painting context * @param s Shape to draw with current pen */ private void drawShape(Graphics2D g2, Shape s) { g2.setStroke(penStroke); // R2_BLACK Pixel is always 0. if (rop2 == EMFConstants.R2_BLACK) { g2.setComposite(AlphaComposite.SrcOver); g2.setPaint(Color.black); } // R2_COPYPEN Pixel is the pen color. else if (rop2 == EMFConstants.R2_COPYPEN) { g2.setComposite(AlphaComposite.SrcOver); g2.setPaint(penPaint); } // R2_NOP Pixel remains unchanged. else if (rop2 == EMFConstants.R2_NOP) { g2.setComposite(AlphaComposite.SrcOver); g2.setPaint(penPaint); } // R2_WHITE Pixel is always 1. else if (rop2 == EMFConstants.R2_WHITE) { g2.setComposite(AlphaComposite.SrcOver); g2.setPaint(Color.white); } // R2_NOTCOPYPEN Pixel is the inverse of the pen color. else if (rop2 == EMFConstants.R2_NOTCOPYPEN) { g2.setComposite(AlphaComposite.SrcOver); // TODO: set at least inverted color if paint is a color } // R2_XORPEN Pixel is a combination of the colors // in the pen and in the screen, but not in both. else if (rop2 == EMFConstants.R2_XORPEN) { g2.setComposite(AlphaComposite.Xor); } else { logger.warning("got unsupported ROP" + rop2); // TODO: //R2_MASKNOTPEN Pixel is a combination of the colors common to both the screen and the inverse of the pen. //R2_MASKPEN Pixel is a combination of the colors common to both the pen and the screen. //R2_MASKPENNOT Pixel is a combination of the colors common to both the pen and the inverse of the screen. //R2_MERGENOTPEN Pixel is a combination of the screen color and the inverse of the pen color. //R2_MERGEPEN Pixel is a combination of the pen color and the screen color. //R2_MERGEPENNOT Pixel is a combination of the pen color and the inverse of the screen color. //R2_NOT Pixel is the inverse of the screen color. //R2_NOTCOPYPEN Pixel is the inverse of the pen color. //R2_NOTMASKPEN Pixel is the inverse of the R2_MASKPEN color. //R2_NOTMERGEPEN Pixel is the inverse of the R2_MERGEPEN color. //R2_NOTXORPEN Pixel is the inverse of the R2_XORPEN color. } g2.draw(s); } // --------------------------------------------------------------------- // simple wrapping methods to the painting context // --------------------------------------------------------------------- public void setFont(Font font) { g2.setFont(font); } public AffineTransform getTransform() { return g2.getTransform(); } public void transform(AffineTransform transform) { g2.transform(transform); } public void resetTransformation() { resetTransformation(g2); } public void setTransform(AffineTransform at) { g2.setTransform(at); } public void setClip(Shape shape) { g2.setClip(shape); } public void clip(Shape shape) { g2.clip(shape); } public Shape getClip() { return g2.getClip(); } public void drawImage(BufferedImage image, AffineTransform transform) { g2.drawImage(image, transform, null); } public void drawImage(BufferedImage image, int x, int y, int width, int height) { g2.drawImage(image, x, y, width, height, null); } public void drawShape(Shape shape) { drawShape(g2, shape); } public void fillShape(Shape shape) { fillShape(g2, shape); } public void fillAndDrawOrAppend(Shape s) { fillAndDrawOrAppend(g2, s); } public void drawOrAppend(Shape s) { drawOrAppend(g2, s); } // --------------------------------------------------------------------- // simple getter / setter methods // --------------------------------------------------------------------- public int getWindingRule() { return windingRule; } public GeneralPath getFigure() { return figure; } public void setFigure(GeneralPath figure) { this.figure = figure; } public GeneralPath getPath() { return path; } public void setPath(GeneralPath path) { this.path = path; } public Shape getInitialClip() { return initialClip; } public AffineTransform getPathTransform() { return pathTransform; } public void setPathTransform(AffineTransform pathTransform) { this.pathTransform = pathTransform; } public void setWindingRule(int windingRule) { this.windingRule = windingRule; } public void setMapModeIsotropic(boolean mapModeIsotropic) { this.mapModeIsotropic = mapModeIsotropic; } public AffineTransform getMapModeTransform() { return mapModeTransform; } public void setMapModeTransform(AffineTransform mapModeTransform) { this.mapModeTransform = mapModeTransform; } public void setWindowOrigin(Point windowOrigin) { this.windowOrigin = windowOrigin; } public void setViewportOrigin(Point viewportOrigin) { this.viewportOrigin = viewportOrigin; } public void setViewportSize(Dimension viewportSize) { this.viewportSize = viewportSize; fixViewportSize(); resetTransformation(); } public void setWindowSize(Dimension windowSize) { this.windowSize = windowSize; fixViewportSize(); resetTransformation(); } public GDIObject getGDIObject(int index) { return gdiObjects[index]; } public void storeGDIObject(int index, GDIObject tag) { gdiObjects[index] = tag; } public void setUseCreatePen(boolean useCreatePen) { this.useCreatePen = useCreatePen; } public void setPenPaint(Paint penPaint) { this.penPaint = penPaint; } public Stroke getPenStroke() { return penStroke; } public void setPenStroke(Stroke penStroke) { this.penStroke = penStroke; } public void setBrushPaint(Paint brushPaint) { this.brushPaint = brushPaint; } public float getMeterLimit() { return meterLimit; } public void setMeterLimit(int meterLimit) { this.meterLimit = meterLimit; } public void setTextColor(Color textColor) { this.textColor = textColor; } public void setRop2(int rop2) { this.rop2 = rop2; } public void setBkMode(int bkMode) { this.bkMode = bkMode; } public int getTextAlignMode() { return textAlignMode; } public void setTextAlignMode(int textAlignMode) { this.textAlignMode = textAlignMode; } public void setScaleMode(int scaleMode) { this.scaleMode = scaleMode; } public Point getBrushOrigin() { return brushOrigin; } public void setBrushOrigin(Point brushOrigin) { this.brushOrigin = brushOrigin; } public void setArcDirection(int arcDirection) { this.arcDirection = arcDirection; } public int getArcDirection() { return arcDirection; } } a/src/main/java/org/freehep/graphicsio/emf/EMFTag.java000066400000000000000000000046501167637521400227650ustar00rootroot00000000000000// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.emf; import java.io.IOException; import java.util.logging.Logger; import org.freehep.util.io.Tag; import org.freehep.util.io.TaggedInputStream; import org.freehep.util.io.TaggedOutputStream; import org.freehep.graphicsio.emf.gdi.GDIObject; /** * EMF specific tag, from which all other EMF Tags inherit. * * @author Mark Donszelmann * @version $Id$ */ public abstract class EMFTag extends Tag implements GDIObject { /** * logger for all instances */ protected static final Logger logger = Logger.getLogger("org.freehep.graphicsio.emf"); protected int flags = 0; /** * Constructs a EMFTag. * * @param id id of the element * @param version emf version in which this element was first supported */ protected EMFTag(int id, int version) { super(id, version); } public Tag read(int tagID, TaggedInputStream input, int len) throws IOException { EMFInputStream emf = (EMFInputStream)input; EMFTagHeader tagHeader = (EMFTagHeader)emf.getTagHeader(); flags = tagHeader.getFlags(); return read(tagID, emf, len); } public abstract EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException; public void write(int tagID, TaggedOutputStream output) throws IOException { write(tagID, (EMFOutputStream) output); } /** * Writes the extra tag information to the outputstream in binary format. * This implementation writes nothing, but concrete tags may override this * method. This method is called just after the TagHeader is written. * * @param tagID id of the tag * @param emf Binary EMF output stream * @throws java.io.IOException thrown by EMFOutputStream */ public void write(int tagID, EMFOutputStream emf) throws IOException { // empty } public int getFlags() { return flags; } /** * @return a description of the tagName and tagID */ public String toString() { int id = getTag(); return "EMFTag " + getName() + " (" + id + ") (0x"+Integer.toHexString(id)+")"; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { logger.warning("EMF tag not supported: " + toString()); } } a/src/main/java/org/freehep/graphicsio/emf/EMFTagHeader.java000066400000000000000000000007311167637521400240720ustar00rootroot00000000000000// Copyright 2006, FreeHEP. package org.freehep.graphicsio.emf; import org.freehep.util.io.TagHeader; /** * Special TagHeader for EMF to include flags. * * @author duns * @version $Id$ */ public class EMFTagHeader extends TagHeader { private int flags; public EMFTagHeader(int tagID, long len, int flags) { super(tagID, len); this.flags = flags; } public int getFlags() { return flags; } } a/src/main/java/org/freehep/graphicsio/emf/EMFTagSet.java000066400000000000000000000353261167637521400234450ustar00rootroot00000000000000// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.emf; import org.freehep.util.io.TagSet; /** * EMF specific tagset. * * @author Mark Donszelmann * @version $Id$ */ public class EMFTagSet extends TagSet { public EMFTagSet(int version) { if ((version >= 1) /* && (version < 0x4000) FIXME check */) { // Set for Windows 3 addTag(new org.freehep.graphicsio.emf.gdi.PolyBezier()); // 2 02 addTag(new org.freehep.graphicsio.emf.gdi.EMFPolygon()); // 3 03 addTag(new org.freehep.graphicsio.emf.gdi.Polyline()); // 4 04 addTag(new org.freehep.graphicsio.emf.gdi.PolyBezierTo()); // 5 05 addTag(new org.freehep.graphicsio.emf.gdi.PolylineTo()); // 6 06 addTag(new org.freehep.graphicsio.emf.gdi.PolyPolyline()); // 7 07 addTag(new org.freehep.graphicsio.emf.gdi.PolyPolygon()); // 8 08 addTag(new org.freehep.graphicsio.emf.gdi.SetWindowExtEx()); // 9 09 addTag(new org.freehep.graphicsio.emf.gdi.SetWindowOrgEx()); // 10 0a addTag(new org.freehep.graphicsio.emf.gdi.SetViewportExtEx()); // 11 0b addTag(new org.freehep.graphicsio.emf.gdi.SetViewportOrgEx()); // 12 0c addTag(new org.freehep.graphicsio.emf.gdi.SetBrushOrgEx()); // 13 0d addTag(new org.freehep.graphicsio.emf.gdi.EOF()); // 14 0e addTag(new org.freehep.graphicsio.emf.gdi.SetPixelV()); // 15 0f addTag(new org.freehep.graphicsio.emf.gdi.SetMapperFlags()); // 16 10 addTag(new org.freehep.graphicsio.emf.gdi.SetMapMode()); // 17 11 addTag(new org.freehep.graphicsio.emf.gdi.SetBkMode()); // 18 12 addTag(new org.freehep.graphicsio.emf.gdi.SetPolyFillMode()); // 19 13 addTag(new org.freehep.graphicsio.emf.gdi.SetROP2()); // 20 14 addTag(new org.freehep.graphicsio.emf.gdi.SetStretchBltMode()); // 21 15 addTag(new org.freehep.graphicsio.emf.gdi.SetTextAlign()); // 22 16 // addTag(new org.freehep.graphicsio.emf.gdi.SetColorAdjustment()); // 23 17 addTag(new org.freehep.graphicsio.emf.gdi.SetTextColor()); // 24 18 addTag(new org.freehep.graphicsio.emf.gdi.SetBkColor()); // 25 19 addTag(new org.freehep.graphicsio.emf.gdi.OffsetClipRgn()); // 26 1a addTag(new org.freehep.graphicsio.emf.gdi.MoveToEx()); // 27 1b addTag(new org.freehep.graphicsio.emf.gdi.SetMetaRgn()); // 28 1c addTag(new org.freehep.graphicsio.emf.gdi.ExcludeClipRect()); // 29 1d addTag(new org.freehep.graphicsio.emf.gdi.IntersectClipRect()); // 30 1e addTag(new org.freehep.graphicsio.emf.gdi.ScaleViewportExtEx()); // 31 1f addTag(new org.freehep.graphicsio.emf.gdi.ScaleWindowExtEx()); // 32 20 addTag(new org.freehep.graphicsio.emf.gdi.SaveDC()); // 33 21 addTag(new org.freehep.graphicsio.emf.gdi.RestoreDC()); // 34 22 addTag(new org.freehep.graphicsio.emf.gdi.SetWorldTransform()); // 35 23 addTag(new org.freehep.graphicsio.emf.gdi.ModifyWorldTransform()); // 36 24 addTag(new org.freehep.graphicsio.emf.gdi.SelectObject()); // 37 25 addTag(new org.freehep.graphicsio.emf.gdi.CreatePen()); // 38 26 addTag(new org.freehep.graphicsio.emf.gdi.CreateBrushIndirect()); // 39 27 addTag(new org.freehep.graphicsio.emf.gdi.DeleteObject()); // 40 28 addTag(new org.freehep.graphicsio.emf.gdi.AngleArc()); // 41 29 addTag(new org.freehep.graphicsio.emf.gdi.Ellipse()); // 42 2a addTag(new org.freehep.graphicsio.emf.gdi.EMFRectangle()); // 43 2b addTag(new org.freehep.graphicsio.emf.gdi.RoundRect()); // 44 2c addTag(new org.freehep.graphicsio.emf.gdi.Arc()); // 45 2d addTag(new org.freehep.graphicsio.emf.gdi.Chord()); // 46 2e addTag(new org.freehep.graphicsio.emf.gdi.Pie()); // 47 2f addTag(new org.freehep.graphicsio.emf.gdi.SelectPalette()); // 48 30 // addTag(new org.freehep.graphicsio.emf.gdi.CreatePalette()); // 49 31 // addTag(new org.freehep.graphicsio.emf.gdi.SetPaletteEntries()); // 50 32 addTag(new org.freehep.graphicsio.emf.gdi.ResizePalette()); // 51 33 addTag(new org.freehep.graphicsio.emf.gdi.RealizePalette()); // 52 34 addTag(new org.freehep.graphicsio.emf.gdi.ExtFloodFill()); // 53 35 addTag(new org.freehep.graphicsio.emf.gdi.LineTo()); // 54 36 addTag(new org.freehep.graphicsio.emf.gdi.ArcTo()); // 55 37 addTag(new org.freehep.graphicsio.emf.gdi.PolyDraw()); // 56 38 addTag(new org.freehep.graphicsio.emf.gdi.SetArcDirection()); // 57 39 addTag(new org.freehep.graphicsio.emf.gdi.SetMiterLimit()); // 58 3a addTag(new org.freehep.graphicsio.emf.gdi.BeginPath()); // 59 3b addTag(new org.freehep.graphicsio.emf.gdi.EndPath()); // 60 3c addTag(new org.freehep.graphicsio.emf.gdi.CloseFigure()); // 61 3d addTag(new org.freehep.graphicsio.emf.gdi.FillPath()); // 62 3e addTag(new org.freehep.graphicsio.emf.gdi.StrokeAndFillPath()); // 63 3f addTag(new org.freehep.graphicsio.emf.gdi.StrokePath()); // 64 40 addTag(new org.freehep.graphicsio.emf.gdi.FlattenPath()); // 65 41 addTag(new org.freehep.graphicsio.emf.gdi.WidenPath()); // 66 42 addTag(new org.freehep.graphicsio.emf.gdi.SelectClipPath()); // 67 43 addTag(new org.freehep.graphicsio.emf.gdi.AbortPath()); // 68 44 // this tag does not exist // 69 45 addTag(new org.freehep.graphicsio.emf.gdi.GDIComment()); // 70 46 // addTag(new org.freehep.graphicsio.emf.gdi.FillRgn()); // 71 47 // addTag(new org.freehep.graphicsio.emf.gdi.FrameRgn()); // 72 48 // addTag(new org.freehep.graphicsio.emf.gdi.InvertRgn()); // 73 49 // addTag(new org.freehep.graphicsio.emf.gdi.PaintRgn()); // 74 4a addTag(new org.freehep.graphicsio.emf.gdi.ExtSelectClipRgn()); // 75 4b addTag(new org.freehep.graphicsio.emf.gdi.BitBlt()); // 76 4c // addTag(new org.freehep.graphicsio.emf.gdi.StretchBlt()); // 77 4d // addTag(new org.freehep.graphicsio.emf.gdi.MaskBlt()); // 78 4e // addTag(new org.freehep.graphicsio.emf.gdi.PlgBlt()); // 79 4f // addTag(new org.freehep.graphicsio.emf.gdi.SetDIBitsToDevice()); // 80 50 addTag(new org.freehep.graphicsio.emf.gdi.StretchDIBits()); // 81 51 addTag(new org.freehep.graphicsio.emf.gdi.ExtCreateFontIndirectW()); // 82 52 addTag(new org.freehep.graphicsio.emf.gdi.ExtTextOutA()); // 83 53 addTag(new org.freehep.graphicsio.emf.gdi.ExtTextOutW()); // 84 54 addTag(new org.freehep.graphicsio.emf.gdi.PolyBezier16()); // 85 55 addTag(new org.freehep.graphicsio.emf.gdi.Polygon16()); // 86 56 addTag(new org.freehep.graphicsio.emf.gdi.Polyline16()); // 87 57 addTag(new org.freehep.graphicsio.emf.gdi.PolyBezierTo16()); // 88 58 addTag(new org.freehep.graphicsio.emf.gdi.PolylineTo16()); // 89 59 addTag(new org.freehep.graphicsio.emf.gdi.PolyPolyline16()); // 90 5a addTag(new org.freehep.graphicsio.emf.gdi.PolyPolygon16()); // 91 5b addTag(new org.freehep.graphicsio.emf.gdi.PolyDraw16()); // 92 5c // addTag(new org.freehep.graphicsio.emf.gdi.CreateMonoBrush()); // 93 5d // addTag(new org.freehep.graphicsio.emf.gdi.CreateDIBPatternBrushPt()); // 94 5e addTag(new org.freehep.graphicsio.emf.gdi.ExtCreatePen()); // 95 5f // addTag(new org.freehep.graphicsio.emf.gdi.PolyTextOutA()); // 96 60 // addTag(new org.freehep.graphicsio.emf.gdi.PolyTextOutW()); // 97 61 // Set for Windows 4 (NT) addTag(new org.freehep.graphicsio.emf.gdi.SetICMMode()); // 98 62 // addTag(new org.freehep.graphicsio.emf.gdi.CreateColorSpace()); // 99 63 // addTag(new org.freehep.graphicsio.emf.gdi.SetColorSpace()); // 100 64 // addTag(new org.freehep.graphicsio.emf.gdi.DeleteColorSpace()); // 101 65 // addTag(new org.freehep.graphicsio.emf.gdi.GLSRecord()); // 102 66 // addTag(new org.freehep.graphicsio.emf.gdi.GLSBoundedRecord()); // 103 67 // addTag(new org.freehep.graphicsio.emf.gdi.PixelFormat()); // 104 68 // Set for Windows 5 (2000/XP) // addTag(new org.freehep.graphicsio.emf.gdi.DrawEscape()); // 105 69 // addTag(new org.freehep.graphicsio.emf.gdi.ExtEscape()); // 106 6a // addTag(new org.freehep.graphicsio.emf.gdi.StartDoc()); // 107 6b // addTag(new org.freehep.graphicsio.emf.gdi.SmallTextOut()); // 108 6c // addTag(new org.freehep.graphicsio.emf.gdi.ForceUFIMapping()); // 109 6d // addTag(new org.freehep.graphicsio.emf.gdi.NamedEscape()); // 110 6e // addTag(new org.freehep.graphicsio.emf.gdi.ColorCorrectPalette()); // 111 6f // addTag(new org.freehep.graphicsio.emf.gdi.SetICMProfileA()); // 112 70 // addTag(new org.freehep.graphicsio.emf.gdi.SetICMProfileW()); // 113 71 addTag(new org.freehep.graphicsio.emf.gdi.AlphaBlend()); // 114 72 // addTag(new org.freehep.graphicsio.emf.gdi.AlphaDIBBlend()); // 115 73 // addTag(new org.freehep.graphicsio.emf.gdi.TransparentBlt()); // 116 74 // addTag(new org.freehep.graphicsio.emf.gdi.TransparentDIB()); // 117 75 addTag(new org.freehep.graphicsio.emf.gdi.GradientFill()); // 118 76 // addTag(new org.freehep.graphicsio.emf.gdi.SetLinkedUFIs()); // 119 77 // addTag(new org.freehep.graphicsio.emf.gdi.SetTextJustification()); // 120 78 } if (version >= 0x4000) { // From GdiPlusEnums.h of Microsoft Platform SDK 2003 R2 // base 0x0004000 addTag(new org.freehep.graphicsio.emf.gdiplus.Header()); // 1 addTag(new org.freehep.graphicsio.emf.gdiplus.EndOfFile()); // 2 //addTag(new org.freehep.graphicsio.emf.gdiplus.Comment()); // 3 //addTag(new org.freehep.graphicsio.emf.gdiplus.GetDC()); // 4 //addTag(new org.freehep.graphicsio.emf.gdiplus.MultiFormatStart()); // 5 //addTag(new org.freehep.graphicsio.emf.gdiplus.MultiFormatSection());// 6 //addTag(new org.freehep.graphicsio.emf.gdiplus.MultiFormatEnd()); // 7 // For all persistent objects addTag(new org.freehep.graphicsio.emf.gdiplus.GDIPlusObject()); // 8 // Drawing Records addTag(new org.freehep.graphicsio.emf.gdiplus.Clear()); // 9 //addTag(new org.freehep.graphicsio.emf.gdiplus.FillRects()); // 10 //addTag(new org.freehep.graphicsio.emf.gdiplus.DrawRects()); // 11 //addTag(new org.freehep.graphicsio.emf.gdiplus.FillPolygon()); // 12 addTag(new org.freehep.graphicsio.emf.gdiplus.DrawLines()); // 13 addTag(new org.freehep.graphicsio.emf.gdiplus.FillEllipse()); // 14 addTag(new org.freehep.graphicsio.emf.gdiplus.DrawEllipse()); // 15 //addTag(new org.freehep.graphicsio.emf.gdiplus.FillPie()); // 16 //addTag(new org.freehep.graphicsio.emf.gdiplus.DrawPie()); // 17 //addTag(new org.freehep.graphicsio.emf.gdiplus.DrawArc()); // 18 //addTag(new org.freehep.graphicsio.emf.gdiplus.FillRegion()); // 19 addTag(new org.freehep.graphicsio.emf.gdiplus.FillPath()); // 20 addTag(new org.freehep.graphicsio.emf.gdiplus.DrawPath()); // 21 //addTag(new org.freehep.graphicsio.emf.gdiplus.FillClosedCurve()); // 22 //addTag(new org.freehep.graphicsio.emf.gdiplus.DrawClosedCurve()); // 23 //addTag(new org.freehep.graphicsio.emf.gdiplus.DrawCurve()); // 24 //addTag(new org.freehep.graphicsio.emf.gdiplus.DrawBeziers()); // 25 addTag(new org.freehep.graphicsio.emf.gdiplus.DrawImage()); // 26 //addTag(new org.freehep.graphicsio.emf.gdiplus.DrawImagePoints()); // 27 //addTag(new org.freehep.graphicsio.emf.gdiplus.DrawString()); // 28 // Graphics State Records //addTag(new org.freehep.graphicsio.emf.gdiplus.SetRenderingOrigin());// 29 addTag(new org.freehep.graphicsio.emf.gdiplus.SetAntiAliasMode()); // 30 //addTag(new org.freehep.graphicsio.emf.gdiplus.SetTextRenderingHint());//31 //addTag(new org.freehep.graphicsio.emf.gdiplus.SetTextContrast()); // 32 //addTag(new org.freehep.graphicsio.emf.gdiplus.SetInterpolationMode());//33 //addTag(new org.freehep.graphicsio.emf.gdiplus.SetPixelOffsetMode());// 34 //addTag(new org.freehep.graphicsio.emf.gdiplus.SetCompositingMode());// 35 //addTag(new org.freehep.graphicsio.emf.gdiplus.SetCompositingQuality());//36 addTag(new org.freehep.graphicsio.emf.gdiplus.Save()); // 37 addTag(new org.freehep.graphicsio.emf.gdiplus.Restore()); // 38 //addTag(new org.freehep.graphicsio.emf.gdiplus.BeginContainer()); // 39 //addTag(new org.freehep.graphicsio.emf.gdiplus.BeginContainerNoParams());//40 //addTag(new org.freehep.graphicsio.emf.gdiplus.EndContainer()); // 41 addTag(new org.freehep.graphicsio.emf.gdiplus.SetWorldTransform()); // 42 //addTag(new org.freehep.graphicsio.emf.gdiplus.ResetWorldTransform());// 43 addTag(new org.freehep.graphicsio.emf.gdiplus.MultiplyWorldTransform());//44 //addTag(new org.freehep.graphicsio.emf.gdiplus.TranslateWorldTransform());//45 //addTag(new org.freehep.graphicsio.emf.gdiplus.ScaleWorldTransform());// 46 //addTag(new org.freehep.graphicsio.emf.gdiplus.RotateWorldTransform());//47 //addTag(new org.freehep.graphicsio.emf.gdiplus.SetPageTransform()); // 48 addTag(new org.freehep.graphicsio.emf.gdiplus.ResetClip()); // 49 //addTag(new org.freehep.graphicsio.emf.gdiplus.SetClipRect()); // 50 addTag(new org.freehep.graphicsio.emf.gdiplus.SetClipPath()); // 51 //addTag(new org.freehep.graphicsio.emf.gdiplus.SetClipRegion()); // 52 //addTag(new org.freehep.graphicsio.emf.gdiplus.OffsetClip()); // 53 //addTag(new org.freehep.graphicsio.emf.gdiplus.DrawDriverString()); // 54 } } } a/src/main/java/org/freehep/graphicsio/emf/EMFViewer.java000066400000000000000000000103201167637521400235020ustar00rootroot00000000000000// Copyright 2007 FreeHEP package org.freehep.graphicsio.emf; import org.freehep.swing.ExtensionFileFilter; import javax.swing.JFrame; import javax.swing.JFileChooser; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JScrollPane; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileInputStream; import java.io.BufferedInputStream; /** * Simple frame to display EMF images. * * @author Steffen Greiffenberg * @version $ID$ */ public class EMFViewer extends JFrame { /** * Prefix for the TITLE */ private static String TITLE = "Freehep EMF Viewer"; /** * Title for the Button */ private static String LOAD_BUTTON_TITLE = "Open EMF"; /** * Title for the Button */ private static String ZOOMIN__BUTTON_TITLE = "Zoom in"; /** * Title for the Button */ private static String ZOOMOUT_BUTTON_TITLE = "Zoom out"; /** * simple panel for displaying an EMF */ private EMFPanel emfPanel = new EMFPanel(); /** * used to open EMF-Files */ private JFileChooser fileChooser = new JFileChooser(); public EMFViewer() { initGUI(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 300); } /** * creates the content of tha frame */ private void initGUI() { setTitle(TITLE); // create a panel for the window content getContentPane().setLayout(new BorderLayout(0, 0)); JPanel mainPanel = new JPanel(); getContentPane().add(mainPanel); // layout the mainPanel mainPanel.setLayout(new BorderLayout(3, 3)); mainPanel.add( BorderLayout.CENTER, new JScrollPane(emfPanel)); // prepare the filechooser fileChooser.addChoosableFileFilter( new ExtensionFileFilter("emf", "Encapsulated Metafile")); // panel for buttons JPanel buttonPanel = new JPanel( new FlowLayout(FlowLayout.RIGHT, 3, 3)); mainPanel.add( BorderLayout.SOUTH, buttonPanel); // button to zoom in JButton zoomInButton = new JButton(ZOOMIN__BUTTON_TITLE); zoomInButton.addActionListener(new ZoomInAction()); buttonPanel.add(zoomInButton); // button to zoom out JButton zoomOutButton = new JButton(ZOOMOUT_BUTTON_TITLE); zoomOutButton.addActionListener(new ZoomOutAction()); buttonPanel.add(zoomOutButton); // loadButton to open files JButton loadButton = new JButton(LOAD_BUTTON_TITLE); loadButton.addActionListener(new OpenFileAction()); buttonPanel.add(loadButton); } /** * displays the file and * @param emfFile File to show */ public void show(File emfFile) { try { FileInputStream fis = new FileInputStream(emfFile); EMFInputStream emf = new EMFInputStream(new BufferedInputStream(fis)); EMFRenderer renderer = new EMFRenderer(emf); emfPanel.setRenderer(renderer); // set the window title setTitle(TITLE + " - " + emfFile.getName()); } catch (Exception e) { e.printStackTrace(); } // show the frame if (!isVisible()) { setVisible(true); } } /** * Uses the fileChooser to open a file. * Uses the emfPanel to display the file. */ private class OpenFileAction implements ActionListener { public void actionPerformed(ActionEvent e) { int result = fileChooser.showOpenDialog(EMFViewer.this); if (result == JFileChooser.APPROVE_OPTION) { show(fileChooser.getSelectedFile()); } } } /** * zoom the panel in */ private class ZoomInAction implements ActionListener { public void actionPerformed(ActionEvent e) { emfPanel.zoomIn(); } } /** * zoom the panel out */ private class ZoomOutAction implements ActionListener { public void actionPerformed(ActionEvent e) { emfPanel.zoomOut(); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/000077500000000000000000000000001167637521400216155ustar00rootroot00000000000000a/src/main/java/org/freehep/graphicsio/emf/gdi/AbortPath.java000066400000000000000000000007441167637521400243510ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; /** * AbortPath TAG. * * @author Mark Donszelmann * @version $Id$ */ public class AbortPath extends EMFTag { public AbortPath() { super(68, 1); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return this; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/AbstractArc.java000066400000000000000000000043271167637521400246570ustar00rootroot00000000000000// Copyright 2007, FreeHEP. package org.freehep.graphicsio.emf.gdi; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFOutputStream; import java.awt.geom.Arc2D; import java.awt.Rectangle; import java.awt.Point; import java.awt.Shape; import java.io.IOException; /** * @author Steffen Greiffenberg * @version $Id$ */ public abstract class AbstractArc extends EMFTag { private Rectangle bounds; private Point start, end; protected AbstractArc(int id, int version, Rectangle bounds, Point start, Point end) { super(id, version); this.bounds = bounds; this.start = start; this.end = end; } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); emf.writePOINTL(start); emf.writePOINTL(end); } public String toString() { return super.toString() + "\n bounds: " + bounds + "\n start: " + start + "\n end: " + end; } /** * creates a shape based on bounds, start and end * * @param renderer EMFRenderer storing the drawing session data * @param arcType type of arc, e.g. {@link Arc2D#OPEN} * @return shape to render */ protected Shape getShape(EMFRenderer renderer, int arcType) { // normalize start and end point to a circle double nx0 = start.getX() / bounds.getWidth(); // double ny0 = arc.getStart().y / arc.getBounds().height; double nx1 = end.getX() / bounds.getWidth(); // double ny1 = arc.getEnd().y / arc.getBounds().height; // calculate angle of start point double alpha0, alpha1; if (renderer.getArcDirection() == EMFConstants.AD_CLOCKWISE) { alpha0 = Math.acos(nx0); alpha1 = Math.acos(nx1); } else { alpha0 = Math.acos(nx1); alpha1 = Math.acos(nx0); } return new Arc2D.Double( start.getX(), start.getY(), bounds.getWidth(), bounds.getHeight(), alpha0, alpha1 - alpha0, arcType); } }a/src/main/java/org/freehep/graphicsio/emf/gdi/AbstractClipPath.java000066400000000000000000000067401167637521400256570ustar00rootroot00000000000000// Copyright 2007, FreeHEP. package org.freehep.graphicsio.emf.gdi; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; import org.freehep.graphicsio.emf.EMFConstants; import java.awt.geom.GeneralPath; import java.awt.geom.AffineTransform; import java.awt.geom.Area; import java.awt.Shape; /** * base class for all tags that change the * clipping area of the {@link org.freehep.graphicsio.emf.EMFRenderer} * * @author Steffen Greiffenberg * @version $Id$ */ public abstract class AbstractClipPath extends EMFTag { private int mode; protected AbstractClipPath(int id, int version, int mode) { super(id, version); this.mode = mode; } public String toString() { return super.toString() + "\n mode: " + mode; } public int getMode() { return mode; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data * @param shape shape to use as clipping area */ public void render(EMFRenderer renderer, Shape shape) { if (shape != null) { // The new clipping region includes the intersection // (overlapping areas) of the current clipping region and the current shape. if (mode == EMFConstants.RGN_AND) { renderer.clip(shape); } // The new clipping region is the current shape else if (mode == EMFConstants.RGN_COPY) { // rest the clip ... AffineTransform at = renderer.getTransform(); // temporarly switch to the base transformation to // aplly the base clipping area renderer.resetTransformation(); // set the clip renderer.setClip(renderer.getInitialClip()); renderer.setTransform(at); renderer.clip(shape); } // The new clipping region includes the areas of the // current clipping region with those of the current shape excluded. else if (mode == EMFConstants.RGN_DIFF) { Shape clip = renderer.getClip(); if (clip != null) { Area a = new Area(shape); a.subtract(new Area(clip)); renderer.setClip(a); } else { renderer.setClip(shape); } } // The new clipping region includes the union (combined areas) // of the current clipping region and the current shape. else if(mode == EMFConstants.RGN_OR) { GeneralPath path = new GeneralPath(shape); Shape clip = renderer.getClip(); if (clip != null) { path.append(clip, false); } renderer.setClip(path); } // The new clipping region includes the union of the current // clipping region and the current shape but without the overlapping areas. else if(mode == EMFConstants.RGN_XOR) { Shape clip = renderer.getClip(); if (clip != null) { Area a = new Area(shape); a.exclusiveOr(new Area(clip)); renderer.setClip(a); } else { renderer.setClip(shape); } } } // delete the current shape renderer.setPath(null); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/AbstractExtTextOut.java000066400000000000000000000042451167637521400262460ustar00rootroot00000000000000// Copyright 2007, FreeHEP package org.freehep.graphicsio.emf.gdi; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; import org.freehep.graphicsio.emf.EMFOutputStream; import java.awt.Rectangle; import java.io.IOException; /** * Abstraction of commonality between the {@link ExtTextOutA} and {@link ExtTextOutW} tags. * * @author Daniel Noll (daniel@nuix.com) * @version $Id: ExtTextOutW.java 10140 2006-12-07 07:50:41Z duns $ */ public abstract class AbstractExtTextOut extends EMFTag implements EMFConstants { private Rectangle bounds; private int mode; private float xScale, yScale; /** * Constructs the tag. * * @param id id of the element * @param version emf version in which this element was first supported * @param bounds text boundary * @param mode text mode * @param xScale horizontal scale factor * @param yScale vertical scale factor */ protected AbstractExtTextOut( int id, int version, Rectangle bounds, int mode, float xScale, float yScale) { super(id, version); this.bounds = bounds; this.mode = mode; this.xScale = xScale; this.yScale = yScale; } public abstract Text getText(); public String toString() { return super.toString() + "\n bounds: " + bounds + "\n mode: " + mode + "\n xScale: " + xScale + "\n yScale: " + yScale + "\n" + getText().toString(); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); emf.writeDWORD(mode); emf.writeFLOAT(xScale); emf.writeFLOAT(yScale); getText().write(emf); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { Text text = getText(); renderer.drawOrAppendText( text.getString(), text.getPos().getX(), text.getPos().getY()); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/AbstractPen.java000066400000000000000000000147471167637521400247030ustar00rootroot00000000000000// Copyright 2007, FreeHEP. package org.freehep.graphicsio.emf.gdi; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFRenderer; import java.util.logging.Logger; import java.awt.BasicStroke; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; /** * @author Steffen Greiffenberg * @version $Id$ */ public abstract class AbstractPen implements EMFConstants, GDIObject { /** * Represents a stroke that draws inside the given shape. * Used if EMFConstants.PS_INSIDEFRAME is used */ private class InsideFrameStroke implements Stroke { private BasicStroke stroke; public InsideFrameStroke ( float width, int cap, int join, float miterlimit, float dash[], float dash_phase) { stroke = new BasicStroke(width, cap, join, miterlimit, dash, dash_phase); } public Shape createStrokedShape(Shape shape) { if (shape == null) { return null; } Rectangle2D oldBounds = shape.getBounds2D(); float witdh = stroke.getLineWidth(); // calcute a transformation for inside drawing // based on the stroke width AffineTransform at = new AffineTransform(); if (oldBounds.getWidth() > 0) { at.scale( (oldBounds.getWidth() - witdh) / oldBounds.getWidth(), 1); } if (oldBounds.getHeight() > 0) { at.scale(1, (oldBounds.getHeight() - witdh) / oldBounds.getHeight()); } // recalculate shape and its oldBounds shape = at.createTransformedShape(shape); Rectangle2D newBounds = shape.getBounds2D(); // move the shape to the old origin + the line width offset AffineTransform moveBackTransform = AffineTransform.getTranslateInstance( oldBounds.getX() - newBounds.getX() + witdh / 2, oldBounds.getY() - newBounds.getY() + witdh / 2); shape = moveBackTransform.createTransformedShape(shape); // outline the shape using the simple basic stroke return stroke.createStrokedShape(shape); } } /** * logger for all instances */ private static final Logger logger = Logger.getLogger("org.freehep.graphicsio.emf"); /** * returns a BasicStroke JOIN for an EMF pen style * @param penStyle penstyle * @return e.g. {@link java.awt.BasicStroke#JOIN_MITER} */ protected int getJoin(int penStyle) { switch (penStyle & 0xF000) { case EMFConstants.PS_JOIN_ROUND: return BasicStroke.JOIN_ROUND; case EMFConstants.PS_JOIN_BEVEL: return BasicStroke.JOIN_BEVEL; case EMFConstants.PS_JOIN_MITER: return BasicStroke.JOIN_MITER; default: logger.warning("got unsupported pen style " + penStyle); return BasicStroke.JOIN_ROUND; } } /** * returns a BasicStroke JOIN for an EMF pen style * @param penStyle Style to convert * @return asicStroke.CAP_ROUND, BasicStroke.CAP_SQUARE, BasicStroke.CAP_BUTT */ protected int getCap(int penStyle) { switch (penStyle & 0xF00) { case EMFConstants.PS_ENDCAP_ROUND: return BasicStroke.CAP_ROUND; case EMFConstants.PS_ENDCAP_SQUARE: return BasicStroke.CAP_SQUARE; case EMFConstants.PS_ENDCAP_FLAT: return BasicStroke.CAP_BUTT; default: logger.warning("got unsupported pen style " + penStyle); return BasicStroke.CAP_ROUND; } } /** * returns a Dash for an EMF pen style * @param penStyle Style to convert * @param style used if EMFConstants#PS_USERSTYLE is set * @return float[] representing a dash */ protected float[] getDash(int penStyle, int[] style) { switch (penStyle & 0xFF) { case EMFConstants.PS_SOLID: // do not use float[] { 1 } // it's _slow_ return null; case EMFConstants.PS_DASH: return new float[] { 5, 5 }; case EMFConstants.PS_DOT: return new float[] { 1, 2 }; case EMFConstants.PS_DASHDOT: return new float[] { 5, 2, 1, 2 }; case EMFConstants.PS_DASHDOTDOT: return new float[] { 5, 2, 1, 2, 1, 2 }; case EMFConstants.PS_INSIDEFRAME: // Represents a pen style that consists of a solid // pen that is drawn from within any given bounding rectangle return null; case EMFConstants.PS_NULL: // do not use float[] { 1 } // it's _slow_ return null; case EMFConstants.PS_USERSTYLE: if (style != null && style.length > 0) { float[] result = new float[style.length]; for (int i = 0; i < style.length; i++) { result[i] = style[i]; } return result; } else { return null; } default: logger.warning("got unsupported pen style " + penStyle); // do not use float[] { 1 } // it's _slow_ return null; } } /** * @param penStyle stored pen style * @return true if PS_INSIDEFRAME is set */ private boolean isInsideFrameStroke(int penStyle) { return (penStyle & 0xFF) == EMFConstants.PS_INSIDEFRAME; } protected Stroke createStroke( EMFRenderer renderer, int penStyle, int[] style, float width) { if (isInsideFrameStroke(penStyle)) { return new InsideFrameStroke( width, getCap(penStyle), getJoin(penStyle), renderer.getMeterLimit(), getDash(penStyle, style), 0); } else { return new BasicStroke( width, getCap(penStyle), getJoin(penStyle), renderer.getMeterLimit(), getDash(penStyle, style), 0); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/AbstractPolyPolygon.java000066400000000000000000000061211167637521400264370ustar00rootroot00000000000000// Copyright 2007, FreeHEP. package org.freehep.graphicsio.emf.gdi; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.GeneralPath; /** * abstract parent for PolyPolygon drawing * * @author Steffen Greiffenberg * @version $Id$ */ public abstract class AbstractPolyPolygon extends EMFTag { private Rectangle bounds; private int[] numberOfPoints; private Point[][] points; /** * Constructs a EMFTag. * * @param id id of the element * @param version emf version in which this element was first supported * @param bounds bounds of figure * @param numberOfPoints number of points * @param points points */ protected AbstractPolyPolygon( int id, int version, Rectangle bounds, int[] numberOfPoints, Point[][] points) { super(id, version); this.bounds = bounds; this.numberOfPoints = numberOfPoints; this.points = points; } public String toString() { return super.toString() + "\n bounds: " + bounds + "\n #polys: " + numberOfPoints.length; } protected Rectangle getBounds() { return bounds; } protected int[] getNumberOfPoints() { return numberOfPoints; } protected Point[][] getPoints() { return points; } /** * displays the tag using the renderer. The default behavior * is to close and fill the polgygons for rendering. * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { render(renderer, true); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data * @param closePath if true the path is closed and filled */ protected void render(EMFRenderer renderer, boolean closePath) { // create a GeneralPath containing GeneralPathes GeneralPath path = new GeneralPath( renderer.getWindingRule()); // iterate the polgons Point p; for (int polygon = 0; polygon < numberOfPoints.length; polygon++) { // create a new member of path GeneralPath gp = new GeneralPath( renderer.getWindingRule()); for (int point = 0; point < numberOfPoints[polygon]; point ++) { // add a point to gp p = points[polygon][point]; if (point > 0) { gp.lineTo((float) p.getX(), (float)p.getY()); } else { gp.moveTo((float) p.getX(), (float)p.getY()); } } // close the member, add it to path if (closePath) { gp.closePath(); } path.append(gp, false); } // draw the complete path if (closePath) { renderer.fillAndDrawOrAppend(path); } else { renderer.drawOrAppend(path); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/AbstractPolyPolyline.java000066400000000000000000000016271167637521400266110ustar00rootroot00000000000000// Copyright 2007, FreeHEP. package org.freehep.graphicsio.emf.gdi; import org.freehep.graphicsio.emf.EMFRenderer; import java.awt.Point; import java.awt.Rectangle; /** * Parent class for a group of PolyLines. Childs are * rendered as not closed polygons. * * @author Steffen Greiffenberg * @version $Id$§ */ public abstract class AbstractPolyPolyline extends AbstractPolyPolygon { protected AbstractPolyPolyline( int id, int version, Rectangle bounds, int[] numberOfPoints, Point[][] points) { super(id, version, bounds, numberOfPoints, points); } /** * displays the tag using the renderer. The default behavior * is not to close the polygons and not to fill them. * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { render(renderer, false); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/AbstractPolygon.java000066400000000000000000000032511167637521400255740ustar00rootroot00000000000000// Copyright 2007, FreeHEP. package org.freehep.graphicsio.emf.gdi; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFOutputStream; import java.awt.Rectangle; import java.awt.Point; import java.io.IOException; /** * @author Steffen Greiffenberg * @version $Id$ */ public abstract class AbstractPolygon extends EMFTag { private Rectangle bounds; private int numberOfPoints; private Point[] points; protected AbstractPolygon(int id, int version) { super(id, version); } protected AbstractPolygon(int id, int version, Rectangle bounds, int numberOfPoints, Point[] points) { super(id, version); this.bounds = bounds; this.numberOfPoints = numberOfPoints; this.points = points; } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); emf.writeDWORD(numberOfPoints); emf.writePOINTL(numberOfPoints, points); } public String toString() { String result = super.toString() + "\n bounds: " + bounds + "\n #points: " + numberOfPoints; if (points != null) { result += "\n points: "; for (int i = 0; i < points.length; i++) { result += "[" + points[i].x + "," + points[i].y + "]"; if (i < points.length - 1) { result += ", "; } } } return result; } protected Rectangle getBounds() { return bounds; } protected int getNumberOfPoints() { return numberOfPoints; } protected Point[] getPoints() { return points; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/AlphaBlend.java000066400000000000000000000130601167637521400244520ustar00rootroot00000000000000// Copyright 2002-2007, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Color; import java.awt.Rectangle; import java.awt.geom.AffineTransform; import java.awt.image.RenderedImage; import java.awt.image.BufferedImage; import java.io.IOException; import org.freehep.graphicsio.ImageGraphics2D; import org.freehep.graphicsio.ImageConstants; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFImageLoader; import org.freehep.graphicsio.emf.EMFRenderer; import org.freehep.util.io.NoCloseOutputStream; /** * PNG and JPG seem not to work. * * @author Mark Donszelmann * @version $Id$ */ public class AlphaBlend extends EMFTag implements EMFConstants { private final static int size = 108; private Rectangle bounds; private int x, y, width, height; private BlendFunction dwROP; private int xSrc, ySrc; private AffineTransform transform; private Color bkg; private int usage; private BitmapInfo bmi; private BufferedImage image; public AlphaBlend() { super(114, 1); } public AlphaBlend( Rectangle bounds, int x, int y, int width, int height, AffineTransform transform, BufferedImage image, Color bkg) { this(); this.bounds = bounds; this.x = x; this.y = y; this.width = width; this.height = height; this.dwROP = new BlendFunction(AC_SRC_OVER, 0, 0xFF, AC_SRC_ALPHA); this.xSrc = 0; this.ySrc = 0; this.transform = transform; this.bkg = (bkg == null) ? new Color(0, 0, 0, 0) : bkg; this.usage = DIB_RGB_COLORS; this.image = image; this.bmi = null; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { AlphaBlend tag = new AlphaBlend(); tag.bounds = emf.readRECTL(); // 16 tag.x = emf.readLONG(); // 20 tag.y = emf.readLONG(); // 24 tag.width = emf.readLONG(); // 28 tag.height = emf.readLONG(); // 32 tag.dwROP = new BlendFunction(emf); // 36 tag.xSrc = emf.readLONG(); // 40 tag.ySrc = emf.readLONG(); // 44 tag.transform = emf.readXFORM(); // 68 tag.bkg = emf.readCOLORREF(); // 72 tag.usage = emf.readDWORD(); // 76 // ignored /* int bmiOffset = */ emf.readDWORD(); // 80 int bmiSize = emf.readDWORD(); // 84 /* int bitmapOffset = */ emf.readDWORD(); // 88 int bitmapSize = emf.readDWORD(); // 92 /* int width = */ emf.readLONG(); // 96 /* int height = */ emf.readLONG(); // 100 // FIXME: this size can differ and can be placed somewhere else tag.bmi = (bmiSize > 0) ? new BitmapInfo(emf) : null; tag.image = EMFImageLoader.readImage( tag.bmi.getHeader(), tag.width, tag.height, emf, bitmapSize, tag.dwROP); return tag; } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); emf.writeLONG(x); emf.writeLONG(y); emf.writeLONG(width); emf.writeLONG(height); dwROP.write(emf); emf.writeLONG(xSrc); emf.writeLONG(ySrc); emf.writeXFORM(transform); emf.writeCOLORREF(bkg); emf.writeDWORD(usage); emf.writeDWORD(size); // bmi follows this record immediately emf.writeDWORD(BitmapInfoHeader.size); emf.writeDWORD(size + BitmapInfoHeader.size); // bitmap follows bmi emf.pushBuffer(); int encode; // plain encode = BI_RGB; ImageGraphics2D.writeImage( (RenderedImage) image, ImageConstants.RAW.toLowerCase(), ImageGraphics2D.getRAWProperties(bkg, "*BGRA"), new NoCloseOutputStream(emf)); // emf.writeImage(image, bkg, "*BGRA", 1); // png // encode = BI_PNG; // ImageGraphics2D.writeImage(image, "png", new Properties(), new // NoCloseOutputStream(emf)); // jpg // encode = BI_JPEG; // ImageGraphics2D.writeImage(image, "jpg", new Properties(), new // NoCloseOutputStream(emf)); int length = emf.popBuffer(); emf.writeDWORD(length); emf.writeLONG(image.getWidth()); emf.writeLONG(image.getHeight()); BitmapInfoHeader header = new BitmapInfoHeader(image.getWidth(), image .getHeight(), 32, encode, length, 0, 0, 0, 0); bmi = new BitmapInfo(header); bmi.write(emf); emf.append(); } public String toString() { return super.toString() + "\n bounds: " + bounds + "\n x, y, w, h: " + x + " " + y + " " + width + " " + height + "\n dwROP: " + dwROP + "\n xSrc, ySrc: " + xSrc + " " + ySrc + "\n transform: " + transform + "\n bkg: " + bkg + "\n usage: " + usage + "\n" + ((bmi != null) ? bmi.toString() : " bitmap: null"); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // This function displays bitmaps that have transparent or semitransparent pixels. if (image != null) { renderer.drawImage(image, x, y, width, height); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/AngleArc.java000066400000000000000000000026741167637521400241450ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * AngleArc TAG. * * @author Mark Donszelmann * @version $Id$ */ public class AngleArc extends EMFTag { private Point center; private int radius; private float startAngle, sweepAngle; public AngleArc() { super(41, 1); } public AngleArc(Point center, int radius, float startAngle, float sweepAngle) { this(); this.center = center; this.radius = radius; this.startAngle = startAngle; this.sweepAngle = sweepAngle; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new AngleArc( emf.readPOINTL(), emf.readDWORD(), emf.readFLOAT(), emf.readFLOAT()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writePOINTL(center); emf.writeDWORD(radius); emf.writeFLOAT(startAngle); emf.writeFLOAT(sweepAngle); } public String toString() { return super.toString() + "\n center: " + center + "\n radius: " + radius + "\n startAngle: " + startAngle + "\n sweepAngle: " + sweepAngle; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/Arc.java000066400000000000000000000046761167637521400232020ustar00rootroot00000000000000// Copyright 2002-2007, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.Arc2D; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * Arc TAG. * * @author Mark Donszelmann * @version $Id$ */ public class Arc extends AbstractArc { public Arc() { super(45, 1, null, null, null); } public Arc(Rectangle bounds, Point start, Point end) { super(45, 1, bounds, start, end); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new Arc( emf.readRECTL(), emf.readPOINTL(), emf.readPOINTL()); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The Arc function draws an elliptical arc. // // BOOL Arc( // HDC hdc, // handle to device context // int nLeftRect, // x-coord of rectangle's upper-left corner // int nTopRect, // y-coord of rectangle's upper-left corner // int nRightRect, // x-coord of rectangle's lower-right corner // int nBottomRect, // y-coord of rectangle's lower-right corner // int nXStartArc, // x-coord of first radial ending point // int nYStartArc, // y-coord of first radial ending point // int nXEndArc, // x-coord of second radial ending point // int nYEndArc // y-coord of second radial ending point // ); // The points (nLeftRect, nTopRect) and (nRightRect, nBottomRect) // specify the bounding rectangle. // An ellipse formed by the specified bounding rectangle defines the // curve of the arc. // The arc extends in the current drawing direction from the point // where it intersects the // radial from the center of the bounding rectangle to the // (nXStartArc, nYStartArc) point. // The arc ends where it intersects the radial from the center of // the bounding rectangle to // the (nXEndArc, nYEndArc) point. If the starting point and ending // point are the same, // a complete ellipse is drawn. renderer.fillAndDrawOrAppend( getShape(renderer, Arc2D.OPEN)); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ArcTo.java000066400000000000000000000055121167637521400234730ustar00rootroot00000000000000// Copyright 2002-2007, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.Arc2D; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * ArcTo TAG. * * @author Mark Donszelmann * @version $Id$ */ public class ArcTo extends AbstractArc { public ArcTo() { super(55, 1, null, null, null); } public ArcTo(Rectangle bounds, Point start, Point end) { super(55, 1, bounds, start, end); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new ArcTo( emf.readRECTL(), emf.readPOINTL(), emf.readPOINTL()); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The ArcTo function draws an elliptical arc. // // BOOL ArcTo( // HDC hdc, // handle to device context // int nLeftRect, // x-coord of rectangle's upper-left corner // int nTopRect, // y-coord of rectangle's upper-left corner // int nRightRect, // x-coord of rectangle's lower-right corner // int nBottomRect, // y-coord of rectangle's lower-right corner // int nXRadial1, // x-coord of first radial ending point // int nYRadial1, // y-coord of first radial ending point // int nXRadial2, // x-coord of second radial ending point // int nYRadial2 // y-coord of second radial ending point // ); // ArcTo is similar to the Arc function, except that the current // position is updated. // // The points (nLeftRect, nTopRect) and (nRightRect, nBottomRect) // specify the bounding rectangle. // An ellipse formed by the specified bounding rectangle defines the // curve of the arc. The arc extends // counterclockwise from the point where it intersects the radial // line from the center of the bounding // rectangle to the (nXRadial1, nYRadial1) point. The arc ends where // it intersects the radial line from // the center of the bounding rectangle to the (nXRadial2, // nYRadial2) point. If the starting point and // ending point are the same, a complete ellipse is drawn. // // A line is drawn from the current position to the starting point // of the arc. // If no error occurs, the current position is set to the ending // point of the arc. // // The arc is drawn using the current pen; it is not filled. renderer.getFigure().append( getShape(renderer, Arc2D.OPEN), true); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/BeginPath.java000066400000000000000000000020121167637521400243140ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import java.awt.geom.GeneralPath; import java.awt.geom.AffineTransform; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * BeginPath TAG. * * @author Mark Donszelmann * @version $Id$ */ public class BeginPath extends EMFTag { public BeginPath() { super(59, 1); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return this; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The BeginPath function opens a path bracket in the specified // device context. renderer.setPath(new GeneralPath( renderer.getWindingRule())); renderer.setPathTransform(new AffineTransform()); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/BitBlt.java000066400000000000000000000123461167637521400236460ustar00rootroot00000000000000// Copyright 2002-2003, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Color; import java.awt.Rectangle; import java.awt.geom.AffineTransform; import java.awt.image.RenderedImage; import java.awt.image.BufferedImage; import java.io.IOException; import org.freehep.graphicsio.ImageGraphics2D; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFImageLoader; import org.freehep.graphicsio.emf.EMFRenderer; import org.freehep.graphicsio.raw.RawImageWriteParam; import org.freehep.util.UserProperties; import org.freehep.util.io.NoCloseOutputStream; /** * BitBlt TAG. Encoded as plain RGB rather than the not-yet-working PNG format. * The BI_code for BI_PNG and BI_JPG seems to be missing from the WINGDI.H file * of visual C++. * * @author Mark Donszelmann * @version $Id$ */ public class BitBlt extends EMFTag implements EMFConstants { private final static int size = 100; private Rectangle bounds; private int x, y, width, height; private int dwROP; private int xSrc, ySrc; private AffineTransform transform; private Color bkg; private int usage; private BitmapInfo bmi; private BufferedImage image; public BitBlt() { super(76, 1); } public BitBlt(Rectangle bounds, int x, int y, int width, int height, AffineTransform transform, BufferedImage image, Color bkg) { this(); this.bounds = bounds; this.x = x; this.y = y; this.width = width; this.height = height; this.dwROP = SRCCOPY; this.xSrc = 0; this.ySrc = 0; this.transform = transform; this.bkg = bkg; this.usage = DIB_RGB_COLORS; this.image = image; this.bmi = null; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { BitBlt tag = new BitBlt(); tag.bounds = emf.readRECTL(); // 16 tag.x = emf.readLONG(); // 20 tag.y = emf.readLONG(); // 24 tag.width = emf.readLONG(); // 28 tag.height = emf.readLONG(); // 32 tag.dwROP = emf.readDWORD(); // 36 tag.xSrc = emf.readLONG(); // 40 tag.ySrc = emf.readLONG(); // 44 tag.transform = emf.readXFORM(); // 68 tag.bkg = emf.readCOLORREF(); // 72 tag.usage = emf.readDWORD(); // 76 // ignored /* int bmiOffset = */ emf.readDWORD(); // 80 int bmiSize = emf.readDWORD(); // 84 /* int bitmapOffset = */ emf.readDWORD(); // 88 int bitmapSize = emf.readDWORD(); // 92 // read bmi if (bmiSize > 0) { tag.bmi = new BitmapInfo(emf); } else { tag.bmi = null; } if (bitmapSize > 0 && tag.bmi != null) { tag.image = EMFImageLoader.readImage( tag.bmi.getHeader(), tag.width, tag.height, emf, bitmapSize, null); } else { tag.image = null; } return tag; } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); emf.writeLONG(x); emf.writeLONG(y); emf.writeLONG(width); emf.writeLONG(height); emf.writeDWORD(dwROP); emf.writeLONG(xSrc); emf.writeLONG(ySrc); emf.writeXFORM(transform); emf.writeCOLORREF(bkg); emf.writeDWORD(usage); emf.writeDWORD(size); // bmi follows this record immediately emf.writeDWORD(BitmapInfoHeader.size); emf.writeDWORD(size + BitmapInfoHeader.size); // bitmap follows bmi emf.pushBuffer(); UserProperties properties = new UserProperties(); properties.setProperty(RawImageWriteParam.BACKGROUND, bkg); properties.setProperty(RawImageWriteParam.CODE, "BGR"); properties.setProperty(RawImageWriteParam.PAD, 4); ImageGraphics2D.writeImage((RenderedImage)image, "raw", properties, new NoCloseOutputStream(emf)); // emf.writeImage(image, bkg, "BGR", 4); int length = emf.popBuffer(); BitmapInfoHeader header = new BitmapInfoHeader( image.getWidth(), image.getHeight(), 24, BI_RGB, length, 0, 0, 0, 0); bmi = new BitmapInfo(header); bmi.write(emf); emf.writeDWORD(length); emf.append(); } public String toString() { return super.toString() + "\n bounds: " + bounds + "\n x, y, w, h: " + x + " " + y + " " + width + " " + height + "\n dwROP: 0x" + Integer.toHexString(dwROP) + "\n xSrc, ySrc: " + xSrc + " " + ySrc + "\n transform: " + transform + "\n bkg: " + bkg + "\n usage: " + usage + "\n" + ((bmi != null) ? bmi.toString() : " bitmap: null"); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { if (image != null) { renderer.drawImage(image, transform); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/BitmapInfo.java000066400000000000000000000016201167637521400245070ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; /** * EMF BitmapInfo * * @author Mark Donszelmann * @version $Id$ */ public class BitmapInfo { private BitmapInfoHeader header; public BitmapInfo(BitmapInfoHeader header) { this.header = header; } public BitmapInfo(EMFInputStream emf) throws IOException { header = new BitmapInfoHeader(emf); // colormap not necessary for true color image } public void write(EMFOutputStream emf) throws IOException { header.write(emf); // colormap not necessary for true color image } public String toString() { return " BitmapInfo\n" + header.toString(); } public BitmapInfoHeader getHeader() { return header; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/BitmapInfoHeader.java000066400000000000000000000057441167637521400256330ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; /** * EMF BitmapInfoHeader * * @author Mark Donszelmann * @version $Id$ */ public class BitmapInfoHeader implements EMFConstants { public static final int size = 40; private int width; private int height; private int planes; private int bitCount; private int compression; private int sizeImage; private int xPelsPerMeter; private int yPelsPerMeter; private int clrUsed; private int clrImportant; public BitmapInfoHeader(int width, int height, int bitCount, int compression, int sizeImage, int xPelsPerMeter, int yPelsPerMeter, int clrUsed, int clrImportant) { this.width = width; this.height = height; this.planes = 1; this.bitCount = bitCount; this.compression = compression; this.sizeImage = sizeImage; this.xPelsPerMeter = xPelsPerMeter; this.yPelsPerMeter = yPelsPerMeter; this.clrUsed = clrUsed; this.clrImportant = clrImportant; } public BitmapInfoHeader(EMFInputStream emf) throws IOException { /*int len = */ emf.readDWORD(); // seems fixed width = emf.readLONG(); height = emf.readLONG(); planes = emf.readWORD(); bitCount = emf.readWORD(); compression = emf.readDWORD(); sizeImage = emf.readDWORD(); xPelsPerMeter = emf.readLONG(); yPelsPerMeter = emf.readLONG(); clrUsed = emf.readDWORD(); clrImportant = emf.readDWORD(); } public void write(EMFOutputStream emf) throws IOException { emf.writeDWORD(size); emf.writeLONG(width); emf.writeLONG(height); emf.writeWORD(planes); emf.writeWORD(bitCount); emf.writeDWORD(compression); emf.writeDWORD(sizeImage); emf.writeLONG(xPelsPerMeter); emf.writeLONG(yPelsPerMeter); emf.writeDWORD(clrUsed); emf.writeDWORD(clrImportant); } public String toString() { return " size: " + size + "\n width: " + width + "\n height: " + height + "\n planes: " + planes + "\n bitCount: " + bitCount + "\n compression: " + compression + "\n sizeImage: " + sizeImage + "\n xPelsPerMeter: " + xPelsPerMeter + "\n yPelsPerMeter: " + yPelsPerMeter + "\n clrUsed: " + clrUsed + "\n clrImportant: " + clrImportant; } public int getBitCount() { return bitCount; } public int getCompression() { return compression; } public int getClrUsed() { return clrUsed; } public int getWidth() { return width; } public int getHeight() { return height; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/BlendFunction.java000066400000000000000000000030001167637521400252030ustar00rootroot00000000000000// Copyright 2002-2003, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; /** * EMF BitmapInfoHeader * * @author Mark Donszelmann * @version $Id$ */ public class BlendFunction implements EMFConstants { public static final int size = 4; private int blendOp; private int blendFlags; private int sourceConstantAlpha; private int alphaFormat; public BlendFunction(int blendOp, int blendFlags, int sourceConstantAlpha, int alphaFormat) { this.blendOp = blendOp; this.blendFlags = blendFlags; this.sourceConstantAlpha = sourceConstantAlpha; this.alphaFormat = alphaFormat; } public BlendFunction(EMFInputStream emf) throws IOException { blendOp = emf.readUnsignedByte(); blendFlags = emf.readUnsignedByte(); sourceConstantAlpha = emf.readUnsignedByte(); alphaFormat = emf.readUnsignedByte(); } public void write(EMFOutputStream emf) throws IOException { emf.writeBYTE(blendOp); emf.writeBYTE(blendFlags); emf.writeBYTE(sourceConstantAlpha); emf.writeBYTE(alphaFormat); } public String toString() { return "BlendFunction"; } public int getSourceConstantAlpha() { return sourceConstantAlpha; } public int getAlphaFormat() { return alphaFormat; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/Chord.java000066400000000000000000000022161167637521400235200ustar00rootroot00000000000000// Copyright 2002-2007, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.Arc2D; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * Chord TAG. * * @author Mark Donszelmann * @version $Id$ */ public class Chord extends AbstractArc { private Rectangle bounds; private Point start, end; public Chord() { super(46, 1, null, null, null); } public Chord(Rectangle bounds, Point start, Point end) { super(46, 1, bounds, start, end); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new Chord( emf.readRECTL(), emf.readPOINTL(), emf.readPOINTL()); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.fillAndDrawOrAppend( getShape(renderer, Arc2D.CHORD)); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/CloseFigure.java000066400000000000000000000013701167637521400246700ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * CloseFigure TAG. * * @author Mark Donszelmann * @version $Id$ */ public class CloseFigure extends EMFTag { public CloseFigure() { super(61, 1); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return this; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.closeFigure(); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/CreateBrushIndirect.java000066400000000000000000000032761167637521400263610ustar00rootroot00000000000000// Copyright 2001, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * CreateBrushIndirect TAG. * * @author Mark Donszelmann * @version $Id$ */ public class CreateBrushIndirect extends EMFTag { private int index; private LogBrush32 brush; public CreateBrushIndirect() { super(39, 1); } public CreateBrushIndirect(int index, LogBrush32 brush) { this(); this.index = index; this.brush = brush; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new CreateBrushIndirect( emf.readDWORD(), new LogBrush32(emf)); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(index); brush.write(emf); } public String toString() { return super.toString() + "\n index: 0x" + Integer.toHexString(index) + "\n" + brush.toString(); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // CreateBrushIndirect // // The CreateBrushIndirect function creates a logical brush that has the // specified style, color, and pattern. // // HBRUSH CreateBrushIndirect( // CONST LOGBRUSH *lplb // brush information // ); renderer.storeGDIObject(index, brush); } }a/src/main/java/org/freehep/graphicsio/emf/gdi/CreateDIBPatternBrushPt.java000066400000000000000000000057741167637521400270650ustar00rootroot00000000000000/** * $Id$ * * Copyright (c) 1998-2006 * semture GmbH * * Alle Rechte vorbehalten */ package org.freehep.graphicsio.emf.gdi; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFImageLoader; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFRenderer; import java.io.IOException; import java.awt.image.BufferedImage; import java.awt.TexturePaint; import java.awt.Rectangle; /** * @author Steffen Greiffenberg * @version $Revision$ */ public class CreateDIBPatternBrushPt extends EMFTag { private int usage; private BitmapInfo bmi; private BufferedImage image; private int index; public CreateDIBPatternBrushPt() { super(94, 1); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { CreateDIBPatternBrushPt tag = new CreateDIBPatternBrushPt(); // read the index for storing the GDIObject tag.index = emf.readDWORD(); // read whatever /*byte[] bytes =*/ emf.readByte(24); tag.bmi = new BitmapInfo(emf); // not used but read: // DIB_PAL_COLORS A color table is provided and // consists of an array of 16-bit indexes into the // logical palette of the device context into which // the brush is to be selected. // DIB_RGB_COLORS A color table is provided and // contains literal RGB values. tag.usage = emf.readDWORD(); tag.image = EMFImageLoader.readImage( tag.bmi.getHeader(), tag.bmi.getHeader().getWidth(), tag.bmi.getHeader().getHeight(), emf, len - 4 - 24 - BitmapInfoHeader.size - 4, null); return tag; } public void write(int tagID, EMFOutputStream emf) throws IOException { logger.warning("not implemented"); } public String toString() { return super.toString() + "\n usage: " + usage + "\n" + bmi.toString(); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The StretchDIBits function copies the color data for a rectangle of pixels in a // DIB to the specified destination rectangle. If the destination rectangle is larger // than the source rectangle, this function stretches the rows and columns of color // data to fit the destination rectangle. If the destination rectangle is smaller // than the source rectangle, this function compresses the rows and columns by using // the specified raster operation. renderer.storeGDIObject(index, new GDIObject() { public void render(EMFRenderer renderer) { if (image != null) { renderer.setBrushPaint(new TexturePaint(image, new Rectangle(0, 0, 16, 16))); } } }); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/CreatePen.java000066400000000000000000000035041167637521400243300ustar00rootroot00000000000000// Copyright 2001, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * CreatePen TAG. * * @author Mark Donszelmann * @version $Id$ */ public class CreatePen extends EMFTag { private int index; private LogPen pen; public CreatePen() { super(38, 1); } public CreatePen(int index, LogPen pen) { this(); this.index = index; this.pen = pen; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new CreatePen(emf.readDWORD(), new LogPen(emf)); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(index); pen.write(emf); } public String toString() { return super.toString() + "\n index: 0x" + Integer.toHexString(index) + "\n" + pen.toString(); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // ExtCreatePen // // The ExtCreatePen function creates a logical cosmetic or // geometric pen that has the specified style, width, // and brush attributes. // // HPEN ExtCreatePen( // DWORD dwPenStyle, // pen style // DWORD dwWidth, // pen width // CONST LOGBRUSH *lplb, // brush attributes // DWORD dwStyleCount, // length of custom style array // CONST DWORD *lpStyle // custom style array //); renderer.storeGDIObject(index, pen); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/DeleteObject.java000066400000000000000000000022741167637521400250160ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * DeleteObject TAG. * * @author Mark Donszelmann * @version $Id$ */ public class DeleteObject extends EMFTag { private int index; public DeleteObject() { super(40, 1); } public DeleteObject(int index) { this(); this.index = index; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new DeleteObject(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(index); } public String toString() { return super.toString() + "\n index: 0x" + Integer.toHexString(index); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.storeGDIObject(index, null); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/EMFPolygon.java000066400000000000000000000033221167637521400244370ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.GeneralPath; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * PolylineTo TAG. * * @author Mark Donszelmann * @version $Id$ */ public class EMFPolygon extends AbstractPolygon { public EMFPolygon() { super(3, 1, null, 0, null); } public EMFPolygon(Rectangle bounds, int numberOfPoints, Point[] points) { super(3, 1, bounds, numberOfPoints, points); } protected EMFPolygon (int id, int version, Rectangle bounds, int numberOfPoints, Point[] points) { super(id, version, bounds, numberOfPoints, points); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { Rectangle r = emf.readRECTL(); int n = emf.readDWORD(); return new EMFPolygon(r, n, emf.readPOINTL(n)); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { Point[] points = getPoints(); // Safety check. if (points.length > 1) { GeneralPath path = new GeneralPath( renderer.getWindingRule()); path.moveTo((float)points[0].getX(), (float)points[0].getY()); for (int i = 1; i < points.length; i++) { path.lineTo((float)points[i].getX(), (float)points[i].getY()); } path.closePath(); renderer.fillAndDrawOrAppend(path); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/EMFRectangle.java000066400000000000000000000023041167637521400247130ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * Rectangle TAG. * * @author Mark Donszelmann * @version $Id$ */ public class EMFRectangle extends EMFTag { private Rectangle bounds; public EMFRectangle() { super(43, 1); } public EMFRectangle(Rectangle bounds) { this(); this.bounds = bounds; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new EMFRectangle(emf.readRECTL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); } public String toString() { return super.toString() + "\n bounds: " + bounds; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.fillAndDrawOrAppend(bounds); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/EOF.java000066400000000000000000000021261167637521400230720ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * Rectangle TAG. * * @author Mark Donszelmann * @version $Id$ */ public class EOF extends EMFTag { public EOF() { super(14, 1); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { /* int[] bytes = */ emf.readUnsignedByte(len); return new EOF(); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(0); // # of palette entries emf.writeDWORD(0x10); // offset for palette // ... palette emf.writeDWORD(0x14); // offset to start of record } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // do nothing } } a/src/main/java/org/freehep/graphicsio/emf/gdi/Ellipse.java000066400000000000000000000032241167637521400240560ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Rectangle; import java.awt.geom.Ellipse2D; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * Ellipse TAG. * * @author Mark Donszelmann * @version $Id$ */ public class Ellipse extends EMFTag { private Rectangle bounds; public Ellipse(Rectangle bounds) { this(); this.bounds = bounds; } public Ellipse() { super(42, 1); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new Ellipse(emf.readRECTL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); } public String toString() { return super.toString() + "\n bounds: " + bounds; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The Ellipse function draws an ellipse. The center of the ellipse // is the center of the specified bounding rectangle. // The ellipse is outlined by using the current pen and is filled by // using the current brush. // The current position is neither used nor updated by Ellipse. renderer.fillAndDrawOrAppend(new Ellipse2D.Double( bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight())); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/EndPath.java000066400000000000000000000022341167637521400240040ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * EndPath TAG. * * @author Mark Donszelmann * @version $Id$ */ public class EndPath extends EMFTag { public EndPath() { super(60, 1); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return this; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // TODO: fix EMFGraphics2D? // this happens only when EMF is created by EMFGraphics2D // there could be an open figure (created with LineTo, PolylineTo etc.) // that is not closed and therefore not written to the currentPath renderer.closeFigure(); // The EndPath function closes a path bracket and selects the path // defined by the bracket into the specified device context. renderer.closePath(); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ExcludeClipRect.java000066400000000000000000000016751167637521400255100ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * ExcludeClipRect TAG. * * @author Mark Donszelmann * @version $Id$ */ public class ExcludeClipRect extends EMFTag { private Rectangle bounds; public ExcludeClipRect() { super(29, 1); } public ExcludeClipRect(Rectangle bounds) { this(); this.bounds = bounds; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new ExcludeClipRect(emf.readRECTL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); } public String toString() { return super.toString() + "\n bounds: " + bounds; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ExtCreateFontIndirectW.java000066400000000000000000000026461167637521400270140ustar00rootroot00000000000000// Copyright 2001, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * ExtCreateFontIndirectW TAG. * * @author Mark Donszelmann * @version $Id$ */ public class ExtCreateFontIndirectW extends EMFTag { private int index; private ExtLogFontW font; public ExtCreateFontIndirectW() { super(82, 1); } public ExtCreateFontIndirectW(int index, ExtLogFontW font) { this(); this.index = index; this.font = font; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new ExtCreateFontIndirectW( emf.readDWORD(), new ExtLogFontW(emf)); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(index); font.write(emf); } public String toString() { return super.toString() + "\n index: 0x" + Integer.toHexString(index) + "\n" + font.toString(); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.storeGDIObject(index, font); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ExtCreatePen.java000066400000000000000000000033431167637521400250120ustar00rootroot00000000000000// Copyright 2001, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * ExtCreatePen TAG. * * @author Mark Donszelmann * @version $Id$ */ public class ExtCreatePen extends EMFTag { private int index; private ExtLogPen pen; public ExtCreatePen() { super(95, 1); } public ExtCreatePen(int index, ExtLogPen pen) { this(); this.index = index; this.pen = pen; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { int index = emf.readDWORD(); /* int bmiOffset = */ emf.readDWORD(); /* int bmiSize = */ emf.readDWORD(); /* int brushOffset = */ emf.readDWORD(); /* int brushSize = */ emf.readDWORD(); return new ExtCreatePen(index, new ExtLogPen(emf)); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(index); emf.writeDWORD(0); // offset to bmi emf.writeDWORD(0); // size of bmi emf.writeDWORD(0); // offset to brush bitmap emf.writeDWORD(0); // size of brush bitmap pen.write(emf); } public String toString() { return super.toString() + "\n index: 0x" + Integer.toHexString(index) + "\n" + pen.toString(); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.storeGDIObject(index, pen); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ExtFloodFill.java000066400000000000000000000025261167637521400250200ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Color; import java.awt.Point; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * ExtFloodFill TAG. * * @author Mark Donszelmann * @version $Id$ */ public class ExtFloodFill extends EMFTag implements EMFConstants { private Point start; private Color color; private int mode; public ExtFloodFill() { super(53, 1); } public ExtFloodFill(Point start, Color color, int mode) { this(); this.start = start; this.color = color; this.mode = mode; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new ExtFloodFill( emf.readPOINTL(), emf.readCOLORREF(), emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writePOINTL(start); emf.writeCOLORREF(color); emf.writeDWORD(mode); } public String toString() { return super.toString() + "\n start: " + start + "\n color: " + color + "\n mode: " + mode; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ExtLogFontW.java000066400000000000000000000060671167637521400246510ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Font; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFRenderer; /** * EMF ExtLogFontW * * @author Mark Donszelmann * @version $Id$ */ public class ExtLogFontW implements EMFConstants, GDIObject { private LogFontW font; private String fullName; private String style; private int version; private int styleSize; private int match; private byte[] vendorID; private int culture; private Panose panose; public ExtLogFontW(LogFontW font, String fullName, String style, int version, int styleSize, int match, byte[] vendorID, int culture, Panose panose) { this.font = font; this.fullName = fullName; this.style = style; this.version = version; this.styleSize = styleSize; this.match = match; this.vendorID = vendorID; this.culture = culture; this.panose = panose; } public ExtLogFontW(Font font) { this.font = new LogFontW(font); this.fullName = ""; this.style = ""; this.version = 0; this.styleSize = 0; this.match = 0; this.vendorID = new byte[] { 0, 0, 0, 0 }; this.culture = 0; this.panose = new Panose(); } public ExtLogFontW(EMFInputStream emf) throws IOException { font = new LogFontW(emf); fullName = emf.readWCHAR(64); style = emf.readWCHAR(32); version = emf.readDWORD(); styleSize = emf.readDWORD(); match = emf.readDWORD(); emf.readDWORD(); vendorID = emf.readBYTE(4); culture = emf.readDWORD(); panose = new Panose(emf); emf.readWORD(); // Pad to 4-byte boundary // to avoid an eception emf.popBuffer(); } public void write(EMFOutputStream emf) throws IOException { font.write(emf); emf.writeWCHAR(fullName, 64); emf.writeWCHAR(style, 32); emf.writeDWORD(version); emf.writeDWORD(styleSize); emf.writeDWORD(match); emf.writeDWORD(0); // reserved emf.writeBYTE(vendorID); emf.writeDWORD(culture); panose.write(emf); emf.writeWORD(0); } public String toString() { return super.toString() + "\n LogFontW\n" + font.toString() + "\n fullname: " + fullName + "\n style: " + style + "\n version: " + version + "\n stylesize: " + styleSize + "\n match: " + match + "\n vendorID: " + vendorID + "\n culture: " + culture + "\n" + panose.toString(); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.setFont(font.getFont()); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ExtLogPen.java000066400000000000000000000055131167637521400243310ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Color; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFRenderer; /** * EMF ExtLogPen * * @author Mark Donszelmann * @version $Id$ */ public class ExtLogPen extends AbstractPen { private int penStyle; private int width; private int brushStyle; private Color color; private int hatch; private int[] style; public ExtLogPen( int penStyle, int width, int brushStyle, Color color, int hatch, int[] style) { this.penStyle = penStyle; this.width = width; this.brushStyle = brushStyle; this.color = color; this.hatch = hatch; this.style = style; } public ExtLogPen(EMFInputStream emf) throws IOException { penStyle = emf.readDWORD(); width = emf.readDWORD(); brushStyle = emf.readUINT(); color = emf.readCOLORREF(); hatch = emf.readULONG(); int nStyle = emf.readDWORD(); // it seems we always have to read one! if (nStyle == 0) emf.readDWORD(); style = emf.readDWORD(nStyle); } public void write(EMFOutputStream emf) throws IOException { emf.writeDWORD(penStyle); emf.writeDWORD(width); emf.writeUINT(brushStyle); emf.writeCOLORREF(color); emf.writeULONG(hatch); emf.writeDWORD(style.length); // it seems we always have to write one! if (style.length == 0) emf.writeDWORD(0); emf.writeDWORD(style); } public String toString() { StringBuffer s = new StringBuffer(); s.append(" ExtLogPen\n"); s.append(" penStyle: "); s.append(Integer.toHexString(penStyle)); s.append("\n"); s.append(" width: "); s.append(width); s.append("\n"); s.append(" brushStyle: "); s.append(brushStyle); s.append("\n"); s.append(" color: "); s.append(color); s.append("\n"); s.append(" hatch: "); s.append(hatch); s.append("\n"); for (int i = 0; i < style.length; i++) { s.append(" style["); s.append(i); s.append("]: "); s.append(style[i]); s.append("\n"); } return s.toString(); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.setUseCreatePen(false); renderer.setPenPaint(color); renderer.setPenStroke( createStroke(renderer, penStyle, style, width)); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ExtSelectClipRgn.java000066400000000000000000000027041167637521400256420ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * ExtSelectClipRgn TAG. * * @author Mark Donszelmann * @version $Id$ */ public class ExtSelectClipRgn extends AbstractClipPath { private Region rgn; public ExtSelectClipRgn() { super(75, 1, EMFConstants.RGN_COPY); } public ExtSelectClipRgn(int mode, Region rgn) { super(75, 1, mode); this.rgn = rgn; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { int length = emf.readDWORD(); int mode = emf.readDWORD(); return new ExtSelectClipRgn( mode, length > 8 ? new Region(emf) : null); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(rgn.length()); emf.writeDWORD(getMode()); rgn.write(emf); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { if (rgn == null || rgn.getBounds() == null) { return; } render(renderer, rgn.getBounds()); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ExtTextOutA.java000066400000000000000000000020651167637521400246610ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; /** * ExtTextOutA TAG. * * @author Mark Donszelmann * @version $Id$ */ public class ExtTextOutA extends AbstractExtTextOut implements EMFConstants { private TextA text; public ExtTextOutA() { super(83, 1, null, 0, 1, 1); } public ExtTextOutA( Rectangle bounds, int mode, float xScale, float yScale, TextA text) { super(83, 1, bounds, mode, xScale, yScale); this.text = text; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new ExtTextOutA( emf.readRECTL(), emf.readDWORD(), emf.readFLOAT(), emf.readFLOAT(), TextA.read(emf)); } public Text getText() { return text; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ExtTextOutW.java000066400000000000000000000020721167637521400247050ustar00rootroot00000000000000// Copyright 2002-2007, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; /** * ExtTextOutW TAG. * * @author Mark Donszelmann * @version $Id$ */ public class ExtTextOutW extends AbstractExtTextOut implements EMFConstants { private TextW text; public ExtTextOutW() { super(84, 1, null, 0, 1, 1); } public ExtTextOutW( Rectangle bounds, int mode, float xScale, float yScale, TextW text) { super(84, 1, bounds, mode, xScale, yScale); this.text = text; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new ExtTextOutW( emf.readRECTL(), emf.readDWORD(), emf.readFLOAT(), emf.readFLOAT(), TextW.read(emf)); } public Text getText() { return text; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/FillPath.java000066400000000000000000000025751167637521400241740ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Rectangle; import java.awt.geom.GeneralPath; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * FillPath TAG. * * @author Mark Donszelmann * @version $Id$ */ public class FillPath extends EMFTag { private Rectangle bounds; public FillPath() { super(62, 1); } public FillPath(Rectangle bounds) { this(); this.bounds = bounds; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new FillPath(emf.readRECTL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); } public String toString() { return super.toString() + "\n bounds: " + bounds; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { GeneralPath currentPath = renderer.getPath(); // fills the current path if (currentPath != null) { renderer.fillShape(currentPath); renderer.setPath(null); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/FlattenPath.java000066400000000000000000000007561167637521400247020ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; /** * FlattenPath TAG. * * @author Mark Donszelmann * @version $Id$ */ public class FlattenPath extends EMFTag { public FlattenPath() { super(65, 1); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return this; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/GDIComment.java000066400000000000000000000065401167637521400244130ustar00rootroot00000000000000// Copyright 2001-2006, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Image; import java.io.ByteArrayInputStream; import java.io.IOException; import javax.imageio.ImageIO; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFRenderer; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.util.io.Tag; /** * GDIComment TAG. * * @author Mark Donszelmann * @version $Id$ */ public class GDIComment extends EMFTag { private static final String EMF_PLUS = "EMF+"; private byte[] bytes; private EMFTag tag; public GDIComment() { super(70, 1); } public GDIComment(String comment) { this(comment.getBytes()); } public GDIComment(byte[] bytes) { this(); this.bytes = bytes; } // FIXME should be EMFPlusTag public GDIComment(EMFTag tag) { this(); this.tag = tag; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { // FIXME decode internal EMFPlus Tags int l = emf.readDWORD(); GDIComment tag = new GDIComment(emf.readBYTE(l)); // Align to 4-byte boundary if (l % 4 != 0) emf.readBYTE(4 - l % 4); return tag; } public void write(int tagID, EMFOutputStream emf) throws IOException { if (tag != null) { emf.pushBuffer(); emf.writeBYTE(EMF_PLUS.getBytes()); emf.writeTag(tag, true); int len = emf.popBuffer(); emf.writeDWORD(len); emf.append(); } else { emf.writeDWORD(bytes.length); emf.writeBYTE(bytes); if (bytes.length % 4 != 0) { for (int i = 0; i < 4 - bytes.length % 4; i++) { emf.writeBYTE(0); } } } } public String toString() { StringBuffer sb = new StringBuffer(super.toString()); sb.append("\n"); sb.append(" length: "); sb.append(bytes.length); sb.append("\n"); String s = new String(bytes); if (s.startsWith(EMF_PLUS)) { try { EMFInputStream emf = new EMFInputStream(new ByteArrayInputStream(bytes, 4, bytes.length-4), 0x4001); sb.append(" --> Embedding:\n"); Tag emfPlusTag = emf.readTag(); while (emfPlusTag != null) { sb.append(emfPlusTag); emfPlusTag = emf.readTag(); if (emfPlusTag != null) sb.append("\n"); } emf.close(); } catch (IOException e) { System.err.println(e); } } else { int n = Math.min(bytes.length, 40); sb.append(" bytes: "); for (int i=0; i 400) { style |= Font.BOLD; } int size = Math.abs(height); font = new Font(faceFamily, style, size); } return font; } public String toString() { return " LogFontW\n" + " height: " + height + "\n width: " + width + "\n orientation: " + orientation + "\n weight: " + weight + "\n italic: " + italic + "\n underline: " + underline + "\n strikeout: " + strikeout + "\n charSet: " + charSet + "\n outPrecision: " + outPrecision + "\n clipPrecision: " + clipPrecision + "\n quality: " + quality + "\n pitchAndFamily: " + pitchAndFamily + "\n faceFamily: " + faceFamily; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // TODO: See if this ever happens. renderer.setFont(font); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/LogPen.java000066400000000000000000000030221167637521400236410ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Color; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFRenderer; /** * EMF LogPen * * @author Mark Donszelmann * @version $Id$ */ public class LogPen extends AbstractPen { private int penStyle; private int width; private Color color; public LogPen(int penStyle, int width, Color color) { this.penStyle = penStyle; this.width = width; this.color = color; } public LogPen(EMFInputStream emf) throws IOException { penStyle = emf.readDWORD(); width = emf.readDWORD(); /* int y = */ emf.readDWORD(); color = emf.readCOLORREF(); } public void write(EMFOutputStream emf) throws IOException { emf.writeDWORD(penStyle); emf.writeDWORD(width); emf.writeDWORD(0); emf.writeCOLORREF(color); } public String toString() { return " LogPen\n" + " penstyle: " + penStyle + "\n width: " + width + "\n color: " + color; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.setUseCreatePen(true); renderer.setPenPaint(color); renderer.setPenStroke( createStroke(renderer, penStyle, null, width)); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ModifyWorldTransform.java000066400000000000000000000071341167637521400266200ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.geom.AffineTransform; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * ModifyWorldTransform TAG. * * @author Mark Donszelmann * @version $Id$ */ public class ModifyWorldTransform extends EMFTag implements EMFConstants { private AffineTransform transform; private int mode; public ModifyWorldTransform() { super(36, 1); } public ModifyWorldTransform(AffineTransform transform, int mode) { this(); this.transform = transform; this.mode = mode; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new ModifyWorldTransform( emf.readXFORM(), emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeXFORM(transform); emf.writeDWORD(mode); } public String toString() { return super.toString() + "\n transform: " + transform + "\n mode: " + mode; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // MWT_IDENTITY Resets the current world transformation by using // the identity matrix. If this mode is specified, the XFORM structure // pointed to by lpXform is ignored. if (mode == EMFConstants.MWT_IDENTITY) { if (renderer.getPath() != null) { renderer.setPathTransform(new AffineTransform()); } else { renderer.resetTransformation(); } } // MWT_LEFTMULTIPLY Multiplies the current transformation by the // data in the XFORM structure. (The data in the XFORM structure becomes // the left multiplicand, and the data for the current transformation // becomes the right multiplicand.) else if (mode == EMFConstants.MWT_LEFTMULTIPLY) { if (renderer.getPath() != null) { renderer.getPathTransform().concatenate(transform); renderer.transform(transform); } else { renderer.transform(transform); } } // MWT_RIGHTMULTIPLY Multiplies the current transformation by the data // in the XFORM structure. (The data in the XFORM structure becomes the // right multiplicand, and the data for the current transformation // becomes the left multiplicand.) else if (mode != EMFConstants.MWT_RIGHTMULTIPLY) { // TODO expected that this should work but it doesn't // doing nothing renders the right emf embedding /* if (renderer.getPath() != null) { AffineTransform transform = new AffineTransform(this.transform); transform.concatenate(renderer.getPathTransform()); renderer.setPathTransform(transform); } else { AffineTransform transform = new AffineTransform(this.transform); transform.concatenate(renderer.getTransform()); renderer.resetTransformation(); renderer.transform(transform); }*/ } // Unknown mode else { logger.warning("unsupport transform mode " + toString()); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/MoveToEx.java000066400000000000000000000030321167637521400241640ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.geom.GeneralPath; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * MoveToEx TAG. * * @author Mark Donszelmann * @version $Id$ */ public class MoveToEx extends EMFTag { private Point point; public MoveToEx() { super(27, 1); } public MoveToEx(Point point) { this(); this.point = point; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new MoveToEx(emf.readPOINTL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writePOINTL(point); } public String toString() { return super.toString() + "\n point: " + point; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The MoveToEx function updates the current position to the // specified point // and optionally returns the previous position. GeneralPath currentFigure = new GeneralPath( renderer.getWindingRule()); currentFigure.moveTo( (float) point.getX(), (float) point.getY()); renderer.setFigure(currentFigure); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/OffsetClipRgn.java000066400000000000000000000016511167637521400251700ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * OffsetClipRgn TAG. * * @author Mark Donszelmann * @version $Id$ */ public class OffsetClipRgn extends EMFTag { private Point offset; public OffsetClipRgn() { super(26, 1); } public OffsetClipRgn(Point offset) { this(); this.offset = offset; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new OffsetClipRgn(emf.readPOINTL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writePOINTL(offset); } public String toString() { return super.toString() + "\n offset: " + offset; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/Panose.java000066400000000000000000000045561167637521400237170ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; /** * EMF Panose * * @author Mark Donszelmann * @version $Id$ */ public class Panose implements EMFConstants { private int familyType; private int serifStyle; private int weight; private int proportion; private int contrast; private int strokeVariation; private int armStyle; private int letterForm; private int midLine; private int xHeight; public Panose() { // FIXME, fixed this.familyType = PAN_NO_FIT; this.serifStyle = PAN_NO_FIT; this.proportion = PAN_NO_FIT; this.weight = PAN_NO_FIT; this.contrast = PAN_NO_FIT; this.strokeVariation = PAN_NO_FIT; this.armStyle = PAN_ANY; this.letterForm = PAN_ANY; this.midLine = PAN_ANY; this.xHeight = PAN_ANY; } public Panose(EMFInputStream emf) throws IOException { familyType = emf.readBYTE(); serifStyle = emf.readBYTE(); proportion = emf.readBYTE(); weight = emf.readBYTE(); contrast = emf.readBYTE(); strokeVariation = emf.readBYTE(); armStyle = emf.readBYTE(); letterForm = emf.readBYTE(); midLine = emf.readBYTE(); xHeight = emf.readBYTE(); } public void write(EMFOutputStream emf) throws IOException { emf.writeBYTE(familyType); emf.writeBYTE(serifStyle); emf.writeBYTE(weight); emf.writeBYTE(proportion); emf.writeBYTE(contrast); emf.writeBYTE(strokeVariation); emf.writeBYTE(armStyle); emf.writeBYTE(letterForm); emf.writeBYTE(midLine); emf.writeBYTE(xHeight); } public String toString() { return " Panose\n" + " familytype: " + familyType + "\n serifStyle: " + serifStyle + "\n weight: " + weight + "\n proportion: " + proportion + "\n contrast: " + contrast + "\n strokeVariation: " + strokeVariation + "\n armStyle: " + armStyle + "\n letterForm: " + letterForm + "\n midLine: " + midLine + "\n xHeight: " + xHeight; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/Pie.java000066400000000000000000000021001167637521400231660ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.Arc2D; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * Pie TAG. * * @author Mark Donszelmann * @version $Id$ */ public class Pie extends AbstractArc { public Pie() { super(47, 1, null, null, null); } public Pie(Rectangle bounds, Point start, Point end) { super(47, 1, bounds, start, end); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new Pie( emf.readRECTL(), emf.readPOINTL(), emf.readPOINTL()); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.fillAndDrawOrAppend( getShape(renderer, Arc2D.PIE)); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/PolyBezier.java000066400000000000000000000041501167637521400245440ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.GeneralPath; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * PolyBezier TAG. * * @author Mark Donszelmann * @version $Id$ */ public class PolyBezier extends AbstractPolygon { public PolyBezier() { super(2, 1, null, 0, null); } public PolyBezier(Rectangle bounds, int numberOfPoints, Point[] points) { super(2, 1, bounds, numberOfPoints, points); } protected PolyBezier (int id, int version, Rectangle bounds, int numberOfPoints, Point[] points) { super(id, version, bounds, numberOfPoints, points); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { Rectangle r = emf.readRECTL(); int n = emf.readDWORD(); return new PolyBezier(r, n, emf.readPOINTL(n)); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { Point[] points = getPoints(); int numberOfPoints = getNumberOfPoints(); if (points != null && points.length > 0) { GeneralPath gp = new GeneralPath( renderer.getWindingRule()); Point p = points[0]; gp.moveTo((float) p.getX(), (float)p.getY()); for (int point = 1; point < numberOfPoints; point = point + 3) { // add a point to gp Point p1 = points[point]; Point p2 = points[point + 1]; Point p3 = points[point + 2]; if (point > 0) { gp.curveTo( (float)p1.getX(), (float)p1.getY(), (float)p2.getX(), (float)p2.getY(), (float)p3.getX(), (float)p3.getY()); } } renderer.fillAndDrawOrAppend(gp); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/PolyBezier16.java000066400000000000000000000021011167637521400247050ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * PolyBezier16 TAG. * * @author Mark Donszelmann * @version $Id$ */ public class PolyBezier16 extends PolyBezier { public PolyBezier16() { super(85, 1, null, 0, null); } public PolyBezier16(Rectangle bounds, int numberOfPoints, Point[] points) { super(85, 1, bounds, numberOfPoints, points); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { Rectangle r = emf.readRECTL(); int n = emf.readDWORD(); return new PolyBezier16(r, n, emf.readPOINTS(n)); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(getBounds()); emf.writeDWORD(getNumberOfPoints()); emf.writePOINTS(getNumberOfPoints(), getPoints()); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/PolyBezierTo.java000066400000000000000000000036361167637521400250570ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.GeneralPath; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * PolyBezierTo TAG. * * @author Mark Donszelmann * @version $Id$ */ public class PolyBezierTo extends AbstractPolygon { public PolyBezierTo() { super(5, 1, null, 0, null); } public PolyBezierTo(Rectangle bounds, int numberOfPoints, Point[] points) { super(5, 1, bounds, numberOfPoints, points); } protected PolyBezierTo (int id, int version, Rectangle bounds, int numberOfPoints, Point[] points) { super(id, version, bounds, numberOfPoints, points); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { Rectangle r = emf.readRECTL(); int n = emf.readDWORD(); return new PolyBezierTo(r, n, emf.readPOINTL(n)); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { Point[] points = getPoints(); int numberOfPoints = getNumberOfPoints(); GeneralPath currentFigure = renderer.getFigure(); if (points != null && points.length > 0) { Point p1, p2, p3; for (int point = 0; point < numberOfPoints; point = point + 3) { // add a point to gp p1 = points[point]; p2 = points[point + 1]; p3 = points[point + 2]; currentFigure.curveTo( (float)p1.getX(), (float)p1.getY(), (float)p2.getX(), (float)p2.getY(), (float)p3.getX(), (float)p3.getY()); } } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/PolyBezierTo16.java000066400000000000000000000021111167637521400252110ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * PolyBezierTo16 TAG. * * @author Mark Donszelmann * @version $Id$ */ public class PolyBezierTo16 extends PolyBezierTo { public PolyBezierTo16() { super(88, 1, null, 0, null); } public PolyBezierTo16(Rectangle bounds, int numberOfPoints, Point[] points) { super(88, 1, bounds, numberOfPoints, points); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { Rectangle r = emf.readRECTL(); int n = emf.readDWORD(); return new PolyBezierTo16(r, n, emf.readPOINTS(n)); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(getBounds()); emf.writeDWORD(getNumberOfPoints()); emf.writePOINTS(getNumberOfPoints(), getPoints()); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/PolyDraw.java000066400000000000000000000026231167637521400242240ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * PolyDraw TAG. * * @author Mark Donszelmann * @version $Id$ */ public class PolyDraw extends EMFTag implements EMFConstants { private Rectangle bounds; private Point[] points; private byte[] types; public PolyDraw() { super(56, 1); } public PolyDraw(Rectangle bounds, Point[] points, byte[] types) { this(); this.bounds = bounds; this.points = points; this.types = types; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { int n; return new PolyDraw( emf.readRECTL(), emf.readPOINTL(n = emf.readDWORD()), emf.readBYTE(n)); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); emf.writeDWORD(points.length); emf.writePOINTL(points); emf.writeBYTE(types); } public String toString() { return super.toString() + "\n bounds: " + bounds + "\n #points: " + points.length; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/PolyDraw16.java000066400000000000000000000026351167637521400243760ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * PolyDraw16 TAG. * * @author Mark Donszelmann * @version $Id$ */ public class PolyDraw16 extends EMFTag implements EMFConstants { private Rectangle bounds; private Point[] points; private byte[] types; public PolyDraw16() { super(92, 1); } public PolyDraw16(Rectangle bounds, Point[] points, byte[] types) { this(); this.bounds = bounds; this.points = points; this.types = types; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { int n; return new PolyDraw16( emf.readRECTL(), emf.readPOINTS(n = emf.readDWORD()), emf.readBYTE(n)); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); emf.writeDWORD(points.length); emf.writePOINTS(points); emf.writeBYTE(types); } public String toString() { return super.toString() + "\n bounds: " + bounds + "\n #points: " + points.length; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/PolyPolygon.java000066400000000000000000000037221167637521400247570ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * PolyPolygon TAG. * * @author Mark Donszelmann * @version $Id$ */ public class PolyPolygon extends AbstractPolyPolygon { private int start, end; public PolyPolygon() { super(8, 1, null, null, null); } public PolyPolygon( Rectangle bounds, int start, int end, int[] numberOfPoints, Point[][] points) { super(8, 1, bounds, numberOfPoints, points); this.start = start; this.end = end; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { Rectangle bounds = emf.readRECTL(); int np = emf.readDWORD(); /* int totalNumberOfPoints = */ emf.readDWORD(); int[] pc = new int[np]; Point[][] points = new Point[np][]; for (int i = 0; i < np; i++) { pc[i] = emf.readDWORD(); points[i] = new Point[pc[i]]; } for (int i = 0; i < np; i++) { points[i] = emf.readPOINTL(pc[i]); } return new PolyPolygon(bounds, 0, np - 1, pc, points); } public void write(int tagID, EMFOutputStream emf) throws IOException { int[] numberOfPoints = getNumberOfPoints(); Point[][] points = getPoints(); emf.writeRECTL(getBounds()); emf.writeDWORD(end - start + 1); int c = 0; for (int i = start; i < end + 1; i++) { c += numberOfPoints[i]; } emf.writeDWORD(c); for (int i = start; i < end + 1; i++) { emf.writeDWORD(numberOfPoints[i]); } for (int i = start; i < end + 1; i++) { emf.writePOINTL(numberOfPoints[i], points[i]); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/PolyPolygon16.java000066400000000000000000000037261167637521400251320ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * PolyPolygon16 TAG. * * @author Mark Donszelmann * @version $Id$ */ public class PolyPolygon16 extends AbstractPolyPolygon { private int numberOfPolys; public PolyPolygon16() { super(91, 1, null, null, null); } public PolyPolygon16( Rectangle bounds, int numberOfPolys, int[] numberOfPoints, Point[][] points) { super(91, 1, bounds, numberOfPoints, points); this.numberOfPolys = numberOfPolys; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { Rectangle bounds = emf.readRECTL(); int np = emf.readDWORD(); /* int totalNumberOfPoints = */ emf.readDWORD(); int[] pc = new int[np]; Point[][] points = new Point[np][]; for (int i = 0; i < np; i++) { pc[i] = emf.readDWORD(); points[i] = new Point[pc[i]]; } for (int i = 0; i < np; i++) { points[i] = emf.readPOINTS(pc[i]); } return new PolyPolygon16(bounds, np, pc, points); } public void write(int tagID, EMFOutputStream emf) throws IOException { int[] numberOfPoints = getNumberOfPoints(); Point[][] points = getPoints(); emf.writeRECTL(getBounds()); emf.writeDWORD(numberOfPolys); int c = 0; for (int i = 0; i < numberOfPolys; i++) { c += getNumberOfPoints()[i]; } emf.writeDWORD(c); for (int i = 0; i < numberOfPolys; i++) { emf.writeDWORD(numberOfPoints[i]); } for (int i = 0; i < numberOfPolys; i++) { emf.writePOINTS(numberOfPoints[i], points[i]); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/PolyPolyline.java000066400000000000000000000040231167637521400251160ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * PolyPolyline TAG. * * @author Mark Donszelmann * @version $Id$ */ public class PolyPolyline extends AbstractPolyPolyline { private int start, end; public PolyPolyline() { super(7, 1, null, null, null); } public PolyPolyline( Rectangle bounds, int start, int end, int[] numberOfPoints, Point[][] points) { super(7, 1, bounds, numberOfPoints, points); this.start = start; this.end = Math.min(end, numberOfPoints.length - 1); } public EMFTag read( int tagID, EMFInputStream emf, int len) throws IOException { Rectangle bounds = emf.readRECTL(); int np = emf.readDWORD(); /* int totalNumberOfPoints = */ emf.readDWORD(); int[] pc = new int[np]; Point[][] points = new Point[np][]; for (int i = 0; i < np; i++) { pc[i] = emf.readDWORD(); points[i] = new Point[pc[i]]; } for (int i = 0; i < np; i++) { points[i] = emf.readPOINTL(pc[i]); } return new PolyPolyline(bounds, 0, np - 1, pc, points); } public void write(int tagID, EMFOutputStream emf) throws IOException { int[] numberOfPoints = getNumberOfPoints(); Point[][] points = getPoints(); emf.writeRECTL(getBounds()); emf.writeDWORD(end - start + 1); int c = 0; for (int i = start; i < end + 1; i++) { c += numberOfPoints[i]; } emf.writeDWORD(c); for (int i = start; i < end + 1; i++) { emf.writeDWORD(numberOfPoints[i]); } for (int i = start; i < end + 1; i++) { emf.writePOINTL(numberOfPoints[i], points[i]); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/PolyPolyline16.java000066400000000000000000000037331167637521400252740ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * PolyPolyline16 TAG. * * @author Mark Donszelmann * @version $Id$ */ public class PolyPolyline16 extends AbstractPolyPolyline { private int numberOfPolys; public PolyPolyline16() { super(90, 1, null, null, null); } public PolyPolyline16( Rectangle bounds, int numberOfPolys, int[] numberOfPoints, Point[][] points) { super(90, 1, bounds, numberOfPoints, points); this.numberOfPolys = numberOfPolys; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { Rectangle bounds = emf.readRECTL(); int np = emf.readDWORD(); /* int totalNumberOfPoints = */ emf.readDWORD(); int[] pc = new int[np]; Point[][] points = new Point[np][]; for (int i = 0; i < np; i++) { pc[i] = emf.readDWORD(); points[i] = new Point[pc[i]]; } for (int i = 0; i < np; i++) { points[i] = emf.readPOINTS(pc[i]); } return new PolyPolyline16(bounds, np, pc, points); } public void write(int tagID, EMFOutputStream emf) throws IOException { int[] numberOfPoints = getNumberOfPoints(); Point[][] points = getPoints(); emf.writeRECTL(getBounds()); emf.writeDWORD(numberOfPolys); int c = 0; for (int i = 0; i < numberOfPolys; i++) { c += numberOfPoints[i]; } emf.writeDWORD(c); for (int i = 0; i < numberOfPolys; i++) { emf.writeDWORD(numberOfPoints[i]); } for (int i = 0; i < numberOfPolys; i++) { emf.writePOINTS(numberOfPoints[i], points[i]); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/Polygon16.java000066400000000000000000000020621167637521400242560ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * Polygon16 TAG. * * @author Mark Donszelmann * @version $Id$ */ public class Polygon16 extends EMFPolygon { public Polygon16() { super(86, 1, null, 0, null); } public Polygon16(Rectangle bounds, int numberOfPoints, Point[] points) { super(86, 1, bounds, numberOfPoints, points); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { Rectangle r = emf.readRECTL(); int n = emf.readDWORD(); return new Polygon16(r, n, emf.readPOINTS(n)); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(getBounds()); emf.writeDWORD(getNumberOfPoints()); emf.writePOINTS(getNumberOfPoints(), getPoints()); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/Polyline.java000066400000000000000000000035531167637521400242610ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.GeneralPath; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * Polyline TAG. * * @author Mark Donszelmann * @version $Id$ */ public class Polyline extends AbstractPolygon { public Polyline() { super(4, 1, null, 0, null); } public Polyline(Rectangle bounds, int numberOfPoints, Point[] points) { super(4, 1, bounds, numberOfPoints, points); } protected Polyline (int id, int version, Rectangle bounds, int numberOfPoints, Point[] points) { super(id, version, bounds, numberOfPoints, points); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { Rectangle r = emf.readRECTL(); int n = emf.readDWORD(); return new Polyline(r, n, emf.readPOINTL(n)); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { Point[] points = getPoints(); int numberOfPoints = getNumberOfPoints(); if (points != null && points.length > 0) { GeneralPath gp = new GeneralPath( renderer.getWindingRule()); Point p; for (int point = 0; point < numberOfPoints; point ++) { // add a point to gp p = points[point]; if (point > 0) { gp.lineTo((float) p.getX(), (float)p.getY()); } else { gp.moveTo((float) p.getX(), (float)p.getY()); } } renderer.drawOrAppend(gp); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/Polyline16.java000066400000000000000000000020651167637521400244250ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * Polyline16 TAG. * * @author Mark Donszelmann * @version $Id$ */ public class Polyline16 extends Polyline { public Polyline16() { super(87, 1, null, 0, null); } public Polyline16(Rectangle bounds, int numberOfPoints, Point[] points) { super(87, 1, bounds, numberOfPoints, points); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { Rectangle r = emf.readRECTL(); int n = emf.readDWORD(); return new Polyline16(r, n, emf.readPOINTS(n)); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(getBounds()); emf.writeDWORD(getNumberOfPoints()); emf.writePOINTS(getNumberOfPoints(), getPoints()); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/PolylineTo.java000066400000000000000000000032331167637521400245570ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.GeneralPath; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * PolylineTo TAG. * * @author Mark Donszelmann * @version $Id$ */ public class PolylineTo extends AbstractPolygon { public PolylineTo() { super(6, 1, null, 0, null); } public PolylineTo(Rectangle bounds, int numberOfPoints, Point[] points) { this(6, 1, bounds, numberOfPoints, points); } protected PolylineTo (int id, int version, Rectangle bounds, int numberOfPoints, Point[] points) { super(id, version, bounds, numberOfPoints, points); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { Rectangle r = emf.readRECTL(); int n = emf.readDWORD(); return new PolylineTo(r, n, emf.readPOINTL(n)); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { Point[] points = getPoints(); int numberOfPoints = getNumberOfPoints(); GeneralPath currentFigure = renderer.getFigure(); if (points != null) { for (int point = 0; point < numberOfPoints; point ++) { // add a point to gp currentFigure.lineTo( (float) points[point].getX(), (float) points[point].getY()); } } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/PolylineTo16.java000066400000000000000000000021011167637521400247170ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * PolylineTo16 TAG. * * @author Mark Donszelmann * @version $Id$ */ public class PolylineTo16 extends PolylineTo { public PolylineTo16() { super(89, 1, null, 0, null); } public PolylineTo16(Rectangle bounds, int numberOfPoints, Point[] points) { super(89, 1, bounds, numberOfPoints, points); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { Rectangle r = emf.readRECTL(); int n = emf.readDWORD(); return new PolylineTo16(r, n, emf.readPOINTS(n)); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(getBounds()); emf.writeDWORD(getNumberOfPoints()); emf.writePOINTS(getNumberOfPoints(), getPoints()); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/RealizePalette.java000066400000000000000000000007671167637521400254040ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; /** * RealizePalette TAG. * * @author Mark Donszelmann * @version $Id$ */ public class RealizePalette extends EMFTag { public RealizePalette() { super(52, 1); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return this; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/Region.java000066400000000000000000000024511167637521400237050ustar00rootroot00000000000000package org.freehep.graphicsio.emf.gdi; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; /** * * @author tonyj */ public class Region { private Rectangle bounds; private Rectangle region; public Region(Rectangle bounds, Rectangle region) { this.bounds = bounds; this.region = region; } public Region(EMFInputStream emf) throws IOException { /* int length = */ emf.readDWORD(); /* int mode = */ emf.readDWORD(); /* int nRect = */ emf.readDWORD(); int size = emf.readDWORD(); bounds = emf.readRECTL(); region = emf.readRECTL(); for (int i = 16; i < size; i += 16) emf.readRECTL(); } public void write(EMFOutputStream emf) throws IOException { emf.writeDWORD(32); emf.writeDWORD(1); // RDH_RECTANGLES emf.writeDWORD(1); emf.writeDWORD(16); emf.writeRECTL(bounds); emf.writeRECTL(region); } public int length() { return 48; } public String toString() { return " Region\n" + " bounds: " + bounds + "\n region: " + region; } public Rectangle getBounds() { return bounds; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ResizePalette.java000066400000000000000000000020701167637521400252370ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * ResizePalette TAG. * * @author Mark Donszelmann * @version $Id$ */ public class ResizePalette extends EMFTag { private int index, entries; public ResizePalette() { super(51, 1); } public ResizePalette(int index, int entries) { this(); this.index = index; this.entries = entries; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new ResizePalette(emf.readDWORD(), emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(index); emf.writeDWORD(entries); } public String toString() { return super.toString() + "\n index: 0x" + Integer.toHexString(index) + "\n entries: " + entries; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/RestoreDC.java000066400000000000000000000022141167637521400243110ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * RestoreDC TAG. * * @author Mark Donszelmann * @version $Id$ */ public class RestoreDC extends EMFTag { private int savedDC = -1; public RestoreDC() { super(34, 1); } public RestoreDC(int savedDC) { this(); this.savedDC = savedDC; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new RestoreDC(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(savedDC); } public String toString() { return super.toString() + "\n savedDC: " + savedDC; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.retoreDC(); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/RoundRect.java000066400000000000000000000031651167637521400243720ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.geom.RoundRectangle2D; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * RoundRect TAG. * * @author Mark Donszelmann * @version $Id$ */ public class RoundRect extends EMFTag { private Rectangle bounds; private Dimension corner; public RoundRect() { super(44, 1); } public RoundRect(Rectangle bounds, Dimension corner) { this(); this.bounds = bounds; this.corner = corner; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new RoundRect(emf.readRECTL(), emf.readSIZEL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); emf.writeSIZEL(corner); } public String toString() { return super.toString() + "\n bounds: " + bounds + "\n corner: " + corner; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.fillAndDrawOrAppend(new RoundRectangle2D.Double( bounds.getX(), bounds.getX(), bounds.getWidth(), bounds.getHeight(), corner.getWidth(), corner.getHeight())); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SaveDC.java000066400000000000000000000013441167637521400235670ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SaveDC TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SaveDC extends EMFTag { public SaveDC() { super(33, 1); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return this; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.saveDC(); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ScaleViewportExtEx.java000066400000000000000000000026201167637521400262250ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * ScaleViewportExtEx TAG. * * @author Mark Donszelmann * @version $Id$ */ public class ScaleViewportExtEx extends EMFTag { private int xNum, xDenom, yNum, yDenom; public ScaleViewportExtEx() { super(31, 1); } public ScaleViewportExtEx(int xNum, int xDenom, int yNum, int yDenom) { this(); this.xNum = xNum; this.xDenom = xDenom; this.yNum = yNum; this.yDenom = yDenom; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { /* int[] bytes = */ emf.readUnsignedByte(len); return new ScaleViewportExtEx( emf.readLONG(), emf.readLONG(), emf.readLONG(), emf.readLONG()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeLONG(xNum); emf.writeLONG(xDenom); emf.writeLONG(yNum); emf.writeLONG(yDenom); } public String toString() { return super.toString() + "\n xNum: " + xNum + "\n xDenom: " + xDenom + "\n yNum: " + yNum + "\n yDenom: " + yDenom; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/ScaleWindowExtEx.java000066400000000000000000000025171167637521400256620ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * ScaleWindowExtEx TAG. * * @author Mark Donszelmann * @version $Id$ */ public class ScaleWindowExtEx extends EMFTag { private int xNum, xDenom, yNum, yDenom; public ScaleWindowExtEx() { super(32, 1); } public ScaleWindowExtEx(int xNum, int xDenom, int yNum, int yDenom) { this(); this.xNum = xNum; this.xDenom = xDenom; this.yNum = yNum; this.yDenom = yDenom; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new ScaleWindowExtEx( emf.readLONG(), emf.readLONG(), emf.readLONG(), emf.readLONG()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeLONG(xNum); emf.writeLONG(xDenom); emf.writeLONG(yNum); emf.writeLONG(yDenom); } public String toString() { return super.toString() + "\n xNum: " + xNum + "\n xDenom: " + xDenom + "\n yNum: " + yNum + "\n yDenom: " + yDenom; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SelectClipPath.java000066400000000000000000000021571167637521400253310ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SelectClipPath TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SelectClipPath extends AbstractClipPath { public SelectClipPath() { super(67, 1, EMFConstants.RGN_AND); } public SelectClipPath(int mode) { super(67, 1, mode); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SelectClipPath(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(getMode()); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { render(renderer, renderer.getPath()); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SelectObject.java000066400000000000000000000030461167637521400250310ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SelectObject TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SelectObject extends EMFTag { private int index; public SelectObject() { super(37, 1); } public SelectObject(int index) { this(); this.index = index; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SelectObject(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(index); } public String toString() { return super.toString() + "\n index: 0x" + Integer.toHexString(index); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { GDIObject gdiObject; if (index < 0) { gdiObject = StockObjects.getStockObject(index); } else { gdiObject = renderer.getGDIObject(index); } if (gdiObject != null) { // render that object gdiObject.render(renderer); } else { logger.warning("gdi object with index " + index + " not found"); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SelectPalette.java000066400000000000000000000025061167637521400252210ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SelectPalette TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SelectPalette extends EMFTag { private int index; public SelectPalette() { super(48, 1); } public SelectPalette(int index) { this(); this.index = index; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SelectPalette(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(index); } public String toString() { return super.toString() + "\n index: 0x" + Integer.toHexString(index); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The SelectPalette function selects the specified // logical palette into a device context. // TODO needs CreatePalette and CreatePalletteIndex to work } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetArcDirection.java000066400000000000000000000025731167637521400255110ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetArcDirection TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetArcDirection extends EMFTag implements EMFConstants { private int direction; public SetArcDirection() { super(57, 1); } public SetArcDirection(int direction) { this(); this.direction = direction; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetArcDirection(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(direction); } public String toString() { return super.toString() + "\n direction: " + direction; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The SetArcDirection sets the drawing direction to // be used for arc and rectangle functions. renderer.setArcDirection(direction); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetBkColor.java000066400000000000000000000035051167637521400244720ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Color; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetBkColor TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetBkColor extends EMFTag { private Color color; public SetBkColor() { super(25, 1); } public SetBkColor(Color color) { this(); this.color = color; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetBkColor(emf.readCOLORREF()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeCOLORREF(color); } public String toString() { return super.toString() + "\n color: " + color; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // This function fills the gaps between styled lines drawn using a // pen created by the CreatePen function; it does not fill the gaps // between styled lines drawn using a pen created by the ExtCreatePen // function. The SetBKColor function also sets the background colors // for TextOut and ExtTextOut. // If the background mode is OPAQUE, the background color is used to // fill gaps between styled lines, gaps between hatched lines in brushes, // and character cells. The background color is also used when converting // bitmaps from color to monochrome and vice versa. // TODO: affects TextOut and ExtTextOut, CreatePen } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetBkMode.java000066400000000000000000000026461167637521400243050ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetBkMode TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetBkMode extends EMFTag implements EMFConstants { private int mode; public SetBkMode() { super(18, 1); } public SetBkMode(int mode) { this(); this.mode = mode; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetBkMode(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(mode); } public String toString() { return super.toString() + "\n mode: " + mode; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The SetBkMode function affects the line styles for lines drawn using a // pen created by the CreatePen function. SetBkMode does not affect lines // drawn using a pen created by the ExtCreatePen function. renderer.setBkMode(mode); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetBrushOrgEx.java000066400000000000000000000025701167637521400251700ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetBrushOrgEx TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetBrushOrgEx extends EMFTag { private Point point; public SetBrushOrgEx() { super(13, 1); } public SetBrushOrgEx(Point point) { this(); this.point = point; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetBrushOrgEx(emf.readPOINTL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writePOINTL(point); } public String toString() { return super.toString() + "\n point: " + point; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The SetBrushOrgEx function sets the brush origin that GDI assigns to // the next (only to the next!) brush an application selects into the specified // device context. renderer.setBrushOrigin(point); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetICMMode.java000066400000000000000000000022701167637521400243520ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetICMMode TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetICMMode extends EMFTag implements EMFConstants { private int mode; public SetICMMode() { super(98, 1); } public SetICMMode(int mode) { this(); this.mode = mode; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetICMMode(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(mode); } public String toString() { return super.toString() + "\n mode: " + mode; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // do nothing } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetMapMode.java000066400000000000000000000105241167637521400244600ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import java.awt.geom.AffineTransform; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetMapMode TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetMapMode extends EMFTag implements EMFConstants { private int mode; public SetMapMode() { super(17, 1); } public SetMapMode(int mode) { this(); this.mode = mode; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetMapMode(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(mode); } public String toString() { return super.toString() + "\n mode: " + mode; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // MM_ANISOTROPIC Logical units are mapped to arbitrary // units with arbitrarily scaled axes. Use the SetWindowExtEx // and SetViewportExtEx functions to specify the units, // orientation, and scaling. if (mode == EMFConstants.MM_ANISOTROPIC) { renderer.setMapModeIsotropic(false); } // MM_HIENGLISH Each logical unit is mapped to 0.001 inch. // Positive x is to the right; positive y is up. else if (mode == EMFConstants.MM_HIENGLISH) { // TODO not sure double scale = 0.001 * 25.4; renderer.setMapModeTransform( AffineTransform.getScaleInstance(scale, scale)); } // MM_HIMETRIC Each logical unit is mapped to 0.01 millimeter. // Positive x is to the right; positive y is up. else if (mode == EMFConstants.MM_HIMETRIC) { // TODO not sure double scale = 0.01; renderer.setMapModeTransform( AffineTransform.getScaleInstance(scale, scale)); } // MM_ISOTROPIC Logical units are mapped to arbitrary units // with equally scaled axes; that is, one unit along the x-axis // is equal to one unit along the y-axis. Use the SetWindowExtEx // and SetViewportExtEx functions to specify the units and the // orientation of the axes. Graphics device interface (GDI) makes // adjustments as necessary to ensure the x and y units remain // the same size (When the window extent is set, the viewport will // be adjusted to keep the units isotropic). else if (mode == EMFConstants.MM_ISOTROPIC) { renderer.setMapModeIsotropic(true); renderer.fixViewportSize(); } // MM_LOENGLISH Each logical unit is mapped to 0.01 inch. // Positive x is to the right; positive y is up. else if (mode == EMFConstants.MM_LOENGLISH) { // TODO not sure double scale = 0.01 * 25.4; renderer.setMapModeTransform( AffineTransform.getScaleInstance(scale, scale)); } // MM_LOMETRIC Each logical unit is mapped to 0.1 millimeter. // Positive x is to the right; positive y is up. else if (mode == EMFConstants.MM_LOMETRIC) { // TODO not sure double scale = 0.1; renderer.setMapModeTransform( AffineTransform.getScaleInstance(scale, scale)); } // MM_TEXT Each logical unit is mapped to one device pixel. Positive // x is to the right; positive y is down. else if (mode == EMFConstants.MM_TEXT) { renderer.setMapModeTransform( AffineTransform.getScaleInstance(1, -1)); } // MM_TWIPS Each logical unit is mapped to one twentieth of a // printer's point (1/1440 inch, also called a twip). Positive x // is to the right; positive y is up. else if (mode == EMFConstants.MM_TWIPS) { renderer.setMapModeTransform( AffineTransform.getScaleInstance( EMFRenderer.TWIP_SCALE, EMFRenderer.TWIP_SCALE)); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetMapperFlags.java000066400000000000000000000016121167637521400253350ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * SetMapperFlags TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetMapperFlags extends EMFTag { private int flags; public SetMapperFlags() { super(16, 1); } public SetMapperFlags(int flags) { this(); this.flags = flags; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetMapperFlags(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(flags); } public String toString() { return super.toString() + "\n flags: " + flags; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetMetaRgn.java000066400000000000000000000020651167637521400244740ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetMetaRgn TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetMetaRgn extends EMFTag { public SetMetaRgn() { super(28, 1); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return this; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The SetMetaRgn function intersects the current clipping region // for the specified device context with the current metaregion and // saves the combined region as the new metaregion for the specified // device context. The clipping region is reset to a null region. // TODO: what ist the current metaregion? } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetMiterLimit.java000066400000000000000000000031641167637521400252170ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetMiterLimit TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetMiterLimit extends EMFTag { private int limit; public SetMiterLimit() { super(58, 1); } public SetMiterLimit(int limit) { this(); this.limit = limit; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetMiterLimit(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(limit); } public String toString() { return super.toString() + "\n limit: " + limit; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The SetMiterLimit function sets the limit for the length of miter // joins for the specified device context. // The miter length is defined as the distance from the intersection // of the line walls on the inside of the join to the intersection of // the line walls on the outside of the join. The miter limit is the // maximum allowed ratio of the miter length to the line width. // The default miter limit is 10.0. renderer.setMeterLimit(limit); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetPixelV.java000066400000000000000000000021161167637521400243430ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Color; import java.awt.Point; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; /** * SetPixelV TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetPixelV extends EMFTag { private Point point; private Color color; public SetPixelV() { super(15, 1); } public SetPixelV(Point point, Color color) { this(); this.point = point; this.color = color; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetPixelV(emf.readPOINTL(), emf.readCOLORREF()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writePOINTL(point); emf.writeCOLORREF(color); } public String toString() { return super.toString() + "\n point: " + point + "\n color: " + color; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetPolyFillMode.java000066400000000000000000000034441167637521400255000ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import java.awt.geom.GeneralPath; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetPolyFillMode TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetPolyFillMode extends EMFTag implements EMFConstants { private int mode; public SetPolyFillMode() { super(19, 1); } public SetPolyFillMode(int mode) { this(); this.mode = mode; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetPolyFillMode(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(mode); } public String toString() { return super.toString() + "\n mode: " + mode; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.setWindingRule(getWindingRule(mode)); } /** * gets a winding rule for GeneralPath creation based on * EMF SetPolyFillMode. * * @param polyFillMode PolyFillMode to convert * @return winding rule */ private int getWindingRule(int polyFillMode) { if (polyFillMode == EMFConstants.WINDING) { return GeneralPath.WIND_EVEN_ODD; } else if (polyFillMode == EMFConstants.ALTERNATE) { return GeneralPath.WIND_NON_ZERO; } else { return GeneralPath.WIND_EVEN_ODD; } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetROP2.java000066400000000000000000000030271167637521400236600ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetROP2 TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetROP2 extends EMFTag implements EMFConstants { private int mode; public SetROP2() { super(20, 1); } public SetROP2(int mode) { this(); this.mode = mode; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetROP2(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(mode); } public String toString() { return super.toString() + "\n mode: " + mode; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The SetROP2 function sets the current foreground mix mode. // GDI uses the foreground mix mode to combine pens and interiors // of filled objects with the colors already on the screen. The // foreground mix mode defines how colors from the brush or pen // and the colors in the existing image are to be combined. renderer.setRop2(mode); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetStretchBltMode.java000066400000000000000000000067241167637521400260300ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import java.awt.Image; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetStretchBltMode TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetStretchBltMode extends EMFTag implements EMFConstants { private int mode; public SetStretchBltMode() { super(21, 1); } public SetStretchBltMode(int mode) { this(); this.mode = mode; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetStretchBltMode(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(mode); } public String toString() { return super.toString() + "\n mode: " + mode; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The stretching mode defines how the system combines rows or columns of a // bitmap with existing pixels on a display device when an application calls // the StretchBlt function. renderer.setScaleMode( getScaleMode(mode)); } /** * converts a SetStretchBltMode to a TWIP_SCALE constat of class Image * @return e.g. {@link java.awt.Image#SCALE_FAST} * @param mode EMFTag SetStretchBltMode */ private int getScaleMode(int mode) { // COLORONCOLOR Deletes the pixels. This mode deletes all // eliminated lines of pixels without trying to preserve their information. if ( mode == EMFConstants.COLORONCOLOR /*|| mode == EMFConstants.STRETCH_DELETESCANS*/) { return Image.SCALE_FAST; } // HALFTONE Maps pixels from the source rectangle into blocks // of pixels in the destination rectangle. The average color over the // destination block of pixels approximates the color of the source pixels. else if ( mode == EMFConstants.HALFTONE /*|| mode == EMFConstants.STRETCH_HALFTONE*/) { return Image.SCALE_SMOOTH; } // BLACKONWHITE Performs a Boolean AND operation using the // color values for the eliminated and existing pixels. If the bitmap // is a monochrome bitmap, this mode preserves black pixels at the // expense of white pixels. else if ( mode == EMFConstants.BLACKONWHITE /*|| mode == EMFConstants.STRETCH_ANDSCANS*/) { // TODO not sure return Image.SCALE_REPLICATE; } // WHITEONBLACK Performs a Boolean OR operation using the // color values for the eliminated and existing pixels. If the bitmap // is a monochrome bitmap, this mode preserves white pixels at the // expense of black pixels. else if ( mode == EMFConstants.WHITEONBLACK /*|| mode == EMFConstants.STRETCH_ORSCANS*/) { // TODO not sure return Image.SCALE_REPLICATE; } else { logger.warning("got unsupported SetStretchBltMode " + mode); return Image.SCALE_DEFAULT; } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetTextAlign.java000066400000000000000000000023251167637521400250350ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetTextAlign TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetTextAlign extends EMFTag implements EMFConstants { private int mode; public SetTextAlign() { super(22, 1); } public SetTextAlign(int mode) { this(); this.mode = mode; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetTextAlign(emf.readDWORD()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeDWORD(mode); } public String toString() { return super.toString() + "\n mode: " + mode; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.setTextAlignMode(mode); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetTextColor.java000066400000000000000000000022621167637521400250610ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Color; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetTextColor TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetTextColor extends EMFTag { private Color color; public SetTextColor() { super(24, 1); } public SetTextColor(Color color) { this(); this.color = color; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetTextColor(emf.readCOLORREF()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeCOLORREF(color); } public String toString() { return super.toString() + "\n color: " + color; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.setTextColor(color); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetViewportExtEx.java000066400000000000000000000034561167637521400257410ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Dimension; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetViewportExtEx TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetViewportExtEx extends EMFTag { private Dimension size; public SetViewportExtEx() { super(11, 1); } public SetViewportExtEx(Dimension size) { this(); this.size = size; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetViewportExtEx(emf.readSIZEL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeSIZEL(size); } public String toString() { return super.toString() + "\n size: " + size; } // The SetViewportExtEx function sets the horizontal and vertical // extents of the viewport for a device context by using the specified values. /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The viewport refers to the device coordinate system of the device space. // The extent is the maximum value of an axis. This function sets the maximum // values for the horizontal and vertical axes of the viewport in device // coordinates (or pixels). When mapping between page space and device space, // SetWindowExtEx and SetViewportExtEx determine the scaling factor between // the window and the viewport. renderer.setViewportSize(size); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetViewportOrgEx.java000066400000000000000000000034511167637521400257230ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetViewportOrgEx TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetViewportOrgEx extends EMFTag { private Point point; public SetViewportOrgEx() { super(12, 1); } public SetViewportOrgEx(Point point) { this(); this.point = point; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetViewportOrgEx(emf.readPOINTL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writePOINTL(point); } public String toString() { return super.toString() + "\n point: " + point; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The SetViewportOrgEx function specifies which device point maps // to the viewport origin (0,0). // This function (along with SetViewportExtEx and SetWindowExtEx) helps // define the mapping from the logical coordinate space (also known as a // window) to the device coordinate space (the viewport). SetViewportOrgEx // specifies which device point maps to the logical point (0,0). It has the // effect of shifting the axes so that the logical point (0,0) no longer // refers to the upper-left corner. renderer.setViewportOrigin(point); renderer.resetTransformation(); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetWindowExtEx.java000066400000000000000000000022721167637521400253640ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Dimension; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetWindowExtEx TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetWindowExtEx extends EMFTag { private Dimension size; public SetWindowExtEx() { super(9, 1); } public SetWindowExtEx(Dimension size) { this(); this.size = size; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetWindowExtEx(emf.readSIZEL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeSIZEL(size); } public String toString() { return super.toString() + "\n size: " + size; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { renderer.setWindowSize(size); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetWindowOrgEx.java000066400000000000000000000025231167637521400253520ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetWindowOrgEx TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetWindowOrgEx extends EMFTag { private Point point; public SetWindowOrgEx() { super(10, 1); } public SetWindowOrgEx(Point point) { this(); this.point = point; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetWindowOrgEx(emf.readPOINTL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writePOINTL(point); } public String toString() { return super.toString() + "\n point: " + point; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The SetWindowOrgEx function specifies which window point maps to // the window origin (0,0). renderer.setWindowOrigin(point); renderer.resetTransformation(); } } a/src/main/java/org/freehep/graphicsio/emf/gdi/SetWorldTransform.java000066400000000000000000000026541167637521400261260ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.geom.AffineTransform; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * SetWorldTransform TAG. * * @author Mark Donszelmann * @version $Id$ */ public class SetWorldTransform extends EMFTag { private AffineTransform transform; public SetWorldTransform() { super(35, 1); } public SetWorldTransform(AffineTransform transform) { this(); this.transform = transform; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new SetWorldTransform(emf.readXFORM()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeXFORM(transform); } public String toString() { return super.toString() + "\n transform: " + transform; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { if (renderer.getPath() != null) { renderer.setPathTransform(transform); } else { renderer.resetTransformation(); renderer.transform(transform); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/StockObjects.java000066400000000000000000000073711167637521400250650ustar00rootroot00000000000000// Copyright 2007 FreeHEP package org.freehep.graphicsio.emf.gdi; import java.awt.Color; import java.awt.Font; import org.freehep.graphicsio.emf.EMFConstants; /** * StockObjects.java * * Created: Wed Dec 20 14:20:00 2006 * * Copyright: * Company: * * @author Daniel Noll daniel@nuix.com * @version $Id$ */ public class StockObjects { // Supported by all versions of Win32... private static final int WHITE_BRUSH = 0; private static final int LTGRAY_BRUSH = 1; private static final int GRAY_BRUSH = 2; private static final int DKGRAY_BRUSH = 3; private static final int BLACK_BRUSH = 4; private static final int NULL_BRUSH = 5; private static final int WHITE_PEN = 6; private static final int BLACK_PEN = 7; private static final int NULL_PEN = 8; private static final int OEM_FIXED_FONT = 10; private static final int ANSI_FIXED_FONT = 11; private static final int ANSI_VAR_FONT = 12; private static final int SYSTEM_FONT = 13; private static final int DEVICE_DEFAULT_FONT = 14; private static final int DEFAULT_PALETTE = 15; private static final int SYSTEM_FIXED_FONT = 16; // Windows 2000 or later... private static final int DEFAULT_GUI_FONT = 17; // Windows XP or later... // These ones are magic. They take the colour of the current device context // as set by SetDCBrushColor and SetDCPenColor private static final int DC_BRUSH = 18; private static final int DC_PEN = 19; private static final GDIObject[] objects = new GDIObject[20]; static { Color nullColor = new Color(0, 0, 0, 0); objects[WHITE_BRUSH] = new LogBrush32(EMFConstants.BS_SOLID, Color.WHITE, 0); objects[LTGRAY_BRUSH] = new LogBrush32(EMFConstants.BS_SOLID, Color.LIGHT_GRAY, 0); objects[GRAY_BRUSH] = new LogBrush32(EMFConstants.BS_SOLID, Color.GRAY, 0); objects[DKGRAY_BRUSH] = new LogBrush32(EMFConstants.BS_SOLID, Color.DARK_GRAY, 0); objects[BLACK_BRUSH] = new LogBrush32(EMFConstants.BS_SOLID, Color.BLACK, 0); objects[NULL_BRUSH] = new LogBrush32(EMFConstants.BS_NULL, nullColor, 0); objects[WHITE_PEN] = new LogPen(EMFConstants.PS_SOLID, 1, Color.WHITE); objects[BLACK_PEN] = new LogPen(EMFConstants.PS_SOLID, 1, Color.BLACK); objects[NULL_PEN] = new LogPen(EMFConstants.PS_NULL, 1, nullColor); // XXX: Should these depend on the look and feel? objects[OEM_FIXED_FONT] = new LogFontW(new Font("Monospaced", Font.PLAIN, 12)); objects[ANSI_FIXED_FONT] = objects[OEM_FIXED_FONT]; objects[ANSI_VAR_FONT] = new LogFontW(new Font("SansSerif", Font.PLAIN, 12)); objects[SYSTEM_FONT] = new LogFontW(new Font("Dialog", Font.PLAIN, 12)); objects[DEVICE_DEFAULT_FONT] = objects[ANSI_VAR_FONT]; objects[SYSTEM_FIXED_FONT] = objects[OEM_FIXED_FONT]; objects[DEFAULT_GUI_FONT] = objects[SYSTEM_FONT]; // TODO: DEFAULT_PALETTE, DC_BRUSH and DC_PEN } /** * Gets a stock object by value. * * @param value the value. * @return the stock object. */ public static GDIObject getStockObject(int value) { if (value >= 0) { throw new IllegalArgumentException("Value does not represent a stock object: " + value); } value ^= 0x80000000; if (value >= objects.length) { throw new IllegalArgumentException("Stock object is out of bounds: " + value); } GDIObject object = objects[value]; if (object == null) { throw new UnsupportedOperationException("Stock object not yet supported: " + value); } return object; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/StretchDIBits.java000066400000000000000000000132411167637521400251340ustar00rootroot00000000000000// Copyright 2002-2007, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Color; import java.awt.Rectangle; import java.awt.image.RenderedImage; import java.awt.image.BufferedImage; import java.io.IOException; import org.freehep.graphicsio.ImageGraphics2D; import org.freehep.graphicsio.ImageConstants; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFImageLoader; import org.freehep.graphicsio.emf.EMFRenderer; import org.freehep.util.io.NoCloseOutputStream; /** * StretchDIBits TAG. Encoded as plain RGB rather than the not-yet-working PNG * format. The BI_code for BI_PNG and BI_JPG seems to be missing from the * WINGDI.H file of visual C++. * * @author Mark Donszelmann * @version $Id$ */ public class StretchDIBits extends EMFTag implements EMFConstants { public final static int size = 80; private Rectangle bounds; private int x, y, width, height; private int xSrc, ySrc, widthSrc, heightSrc; private int usage, dwROP; private Color bkg; private BitmapInfo bmi; private BufferedImage image; public StretchDIBits() { super(81, 1); } public StretchDIBits(Rectangle bounds, int x, int y, int width, int height, BufferedImage image, Color bkg) { this(); this.bounds = bounds; this.x = x; this.y = y; this.width = width; this.height = height; this.xSrc = 0; this.ySrc = 0; this.widthSrc = image.getWidth(); this.heightSrc = image.getHeight(); this.usage = DIB_RGB_COLORS; this.dwROP = SRCCOPY; this.bkg = bkg; this.image = image; this.bmi = null; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { StretchDIBits tag = new StretchDIBits(); tag.bounds = emf.readRECTL(); // 16 tag.x = emf.readLONG(); // 20 tag.y = emf.readLONG(); // 24 tag.xSrc = emf.readLONG(); // 28 tag.ySrc = emf.readLONG(); // 32 tag.width = emf.readLONG(); // 36 tag.height = emf.readLONG(); // 40 // ignored emf.readDWORD(); // 44 emf.readDWORD(); // 48 emf.readDWORD(); // 52 emf.readDWORD(); // 56 tag.usage = emf.readDWORD(); // 60 tag.dwROP = emf.readDWORD(); // 64 tag.widthSrc = emf.readLONG(); // 68 tag.heightSrc = emf.readLONG(); // 72 // FIXME: this size can differ and can be placed somewhere else tag.bmi = new BitmapInfo(emf); tag.image = EMFImageLoader.readImage( tag.bmi.getHeader(), tag.width, tag.height, emf, len - 72 - BitmapInfoHeader.size, null); return tag; } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); emf.writeLONG(x); emf.writeLONG(y); emf.writeLONG(xSrc); emf.writeLONG(ySrc); emf.writeLONG(widthSrc); emf.writeLONG(heightSrc); emf.writeDWORD(size); // bmi follows this record immediately emf.writeDWORD(BitmapInfoHeader.size); emf.writeDWORD(size + BitmapInfoHeader.size); // bitmap follows bmi // write image and calculate size emf.pushBuffer(); int encode; // plain encode = BI_RGB; ImageGraphics2D.writeImage( (RenderedImage) image, ImageConstants.RAW.toLowerCase(), ImageGraphics2D.getRAWProperties(bkg, "BGR"), new NoCloseOutputStream(emf)); // emf.writeImage(image, bkg, "BGR", 1); // png // encode = BI_PNG; // ImageGraphics2D.writeImage(image, "png", new Properties(), new // NoCloseOutputStream(emf)); // jpg // encode = BI_JPEG; // ImageGraphics2D.writeImage(image, "jpg", new Properties(), new // NoCloseOutputStream(emf)); int length = emf.popBuffer(); emf.writeDWORD(length); emf.writeDWORD(usage); emf.writeDWORD(dwROP); emf.writeLONG(width); emf.writeLONG(height); BitmapInfoHeader header = new BitmapInfoHeader(widthSrc, heightSrc, 24, encode, length, 0, 0, 0, 0); bmi = new BitmapInfo(header); bmi.write(emf); emf.append(); } public String toString() { return super.toString() + "\n bounds: " + bounds + "\n x, y, w, h: " + x + " " + y + " " + width + " " + height + "\n xSrc, ySrc, widthSrc, heightSrc: " + xSrc + " " + ySrc + " " + widthSrc + " " + heightSrc + "\n usage: " + usage + "\n dwROP: " + dwROP + "\n bkg: " + bkg + "\n" + bmi.toString(); } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { // The StretchDIBits function copies the color data for a rectangle of pixels in a // DIB to the specified destination rectangle. If the destination rectangle is larger // than the source rectangle, this function stretches the rows and columns of color // data to fit the destination rectangle. If the destination rectangle is smaller // than the source rectangle, this function compresses the rows and columns by using // the specified raster operation. if (image != null) { renderer.drawImage(image, x, y, widthSrc, heightSrc); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/StrokeAndFillPath.java000066400000000000000000000027271167637521400260060ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Rectangle; import java.awt.geom.GeneralPath; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * StrokeAndFillPath TAG. * * @author Mark Donszelmann * @version $Id$ */ public class StrokeAndFillPath extends EMFTag { private Rectangle bounds; public StrokeAndFillPath() { super(63, 1); } public StrokeAndFillPath(Rectangle bounds) { this(); this.bounds = bounds; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new StrokeAndFillPath(emf.readRECTL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); } public String toString() { return super.toString() + "\n bounds: " + bounds; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { GeneralPath currentPath = renderer.getPath(); // fills the current path if (currentPath != null) { renderer.fillShape(currentPath); renderer.drawShape(currentPath); renderer.setPath(null); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/StrokePath.java000066400000000000000000000026101167637521400245430ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Rectangle; import java.awt.geom.GeneralPath; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * StrokePath TAG. * * @author Mark Donszelmann * @version $Id$ */ public class StrokePath extends EMFTag { private Rectangle bounds; public StrokePath() { super(64, 1); } public StrokePath(Rectangle bounds) { this(); this.bounds = bounds; } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return new StrokePath(emf.readRECTL()); } public void write(int tagID, EMFOutputStream emf) throws IOException { emf.writeRECTL(bounds); } public String toString() { return super.toString() + "\n bounds: " + bounds; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { GeneralPath currentPath = renderer.getPath(); // fills the current path if (currentPath != null) { renderer.drawShape(currentPath); renderer.setPath(null); } } } a/src/main/java/org/freehep/graphicsio/emf/gdi/Text.java000066400000000000000000000017101167637521400234030ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFOutputStream; /** * EMF Text * * @author Mark Donszelmann * @version $Id$ */ public abstract class Text implements EMFConstants { Point pos; String string; int options; Rectangle bounds; int[] widths; protected Text(Point pos, String string, int options, Rectangle bounds, int[] widths) { this.pos = pos; this.string = string; this.options = options; this.bounds = bounds; this.widths = widths; } public Point getPos() { return pos; } public Rectangle getBounds() { return bounds; } public String getString() { return string; } public abstract void write(EMFOutputStream emf) throws IOException; } a/src/main/java/org/freehep/graphicsio/emf/gdi/TextA.java000066400000000000000000000045701167637521400235130ustar00rootroot00000000000000package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; public class TextA extends Text { public TextA(Point pos, String string, int options, Rectangle bounds, int[] widths) { super(pos, string, options, bounds, widths); } public static TextA read(EMFInputStream emf) throws IOException { Point pos = emf.readPOINTL(); int sLen = emf.readDWORD(); /* int sOffset = */ emf.readDWORD(); int options = emf.readDWORD(); Rectangle bounds = emf.readRECTL(); /* int cOffset = */ emf.readDWORD(); // FIXME: nothing done with offsets String string = new String(emf.readBYTE(sLen)); if ((sLen) % 4 != 0) for (int i = 0; i < 4 - (sLen) % 4; i++) emf.readBYTE(); int[] widths = new int[sLen]; for (int i = 0; i < sLen; i++) widths[i] = emf.readDWORD(); return new TextA(pos, string, options, bounds, widths); } public void write(EMFOutputStream emf) throws IOException { emf.writePOINTL(pos); emf.writeDWORD(string.length()); emf.writeDWORD(8 + 28 + 40); // TagHeader + ExtTextOutA + Text emf.writeDWORD(options); emf.writeRECTL(bounds); int pad = (string.length()) % 4; if (pad > 0) pad = 4 - pad; emf.writeDWORD(8 + 28 + 40 + string.length() + pad); // offset to // character // spacing array emf.writeBYTE(string.getBytes()); for (int i = 0; i < pad; i++) emf.writeBYTE(0); for (int i = 0; i < string.length(); i++) emf.writeDWORD(widths[i]); } public String toString() { StringBuffer widthsS = new StringBuffer(); for (int i = 0; i < string.length(); i++) { widthsS.append(","); widthsS.append(widths[i]); } widthsS.append(']'); widthsS.setCharAt(0, '['); return " TextA\n" + " pos: " + pos + "\n options: " + options + "\n bounds: " + bounds + "\n string: " + string + "\n widths: " + widthsS; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/TextW.java000066400000000000000000000051271167637521400235400ustar00rootroot00000000000000// Copyright 2002-2007, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Point; import java.awt.Rectangle; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; /** * EMF Text * * @author Mark Donszelmann * @version $Id$ */ public class TextW extends Text { public TextW(Point pos, String string, int options, Rectangle bounds, int[] widths) { super(pos, string, options, bounds, widths); } public static TextW read(EMFInputStream emf) throws IOException { Point pos = emf.readPOINTL(); int sLen = emf.readDWORD(); /* int sOffset = */ emf.readDWORD(); int options = emf.readDWORD(); Rectangle bounds = emf.readRECTL(); /* int cOffset = */ emf.readDWORD(); // FIXME: nothing done with offsets String string = new String(emf.readBYTE(2 * sLen), "UTF-16LE"); if ((2 * sLen) % 4 != 0) for (int i = 0; i < 4 - (2 * sLen) % 4; i++) emf.readBYTE(); int[] widths = new int[sLen]; for (int i = 0; i < sLen; i++) widths[i] = emf.readDWORD(); return new TextW(pos, string, options, bounds, widths); } public void write(EMFOutputStream emf) throws IOException { emf.writePOINTL(pos); emf.writeDWORD(string.length()); emf.writeDWORD(8 + 28 + 40); // TagHeader + ExtTextOutA + Text emf.writeDWORD(options); emf.writeRECTL(bounds); int pad = (2 * string.length()) % 4; if (pad > 0) pad = 4 - pad; emf.writeDWORD(8 + 28 + 40 + 2 * string.length() + pad); // offset to // character // spacing // array emf.writeBYTE(string.getBytes("UTF-16LE")); for (int i = 0; i < pad; i++) emf.writeBYTE(0); for (int i = 0; i < string.length(); i++) emf.writeDWORD(widths[i]); } public String toString() { StringBuffer widthsS = new StringBuffer(); for (int i = 0; i < string.length(); i++) { widthsS.append(","); widthsS.append(widths[i]); } widthsS.append(']'); widthsS.setCharAt(0, '['); return " TextW\n" + " pos: " + pos + "\n options: " + options + "\n bounds: " + bounds + "\n string: " + string + "\n widths: " + widthsS; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/TriVertex.java000066400000000000000000000016061167637521400244170ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.awt.Color; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; /** * EMF TriVertex * * @author Mark Donszelmann * @version $Id$ */ public class TriVertex { private int x, y; private Color color; public TriVertex(int x, int y, Color color) { this.x = x; this.y = y; this.color = color; } public TriVertex(EMFInputStream emf) throws IOException { x = emf.readLONG(); y = emf.readLONG(); color = emf.readCOLOR16(); } public void write(EMFOutputStream emf) throws IOException { emf.writeLONG(x); emf.writeLONG(y); emf.writeCOLOR16(color); } public String toString() { return "[" + x + ", " + y + "] " + color; } } a/src/main/java/org/freehep/graphicsio/emf/gdi/WidenPath.java000066400000000000000000000025571167637521400243540ustar00rootroot00000000000000// Copyright 2002, FreeHEP. package org.freehep.graphicsio.emf.gdi; import java.io.IOException; import java.awt.geom.GeneralPath; import java.awt.Stroke; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.EMFRenderer; /** * WidenPath TAG. * * @author Mark Donszelmann * @version $Id$ */ public class WidenPath extends EMFTag { public WidenPath() { super(66, 1); } public EMFTag read(int tagID, EMFInputStream emf, int len) throws IOException { return this; } /** * displays the tag using the renderer * * @param renderer EMFRenderer storing the drawing session data */ public void render(EMFRenderer renderer) { GeneralPath currentPath = renderer.getPath(); Stroke currentPenStroke = renderer.getPenStroke(); // The WidenPath function redefines the current path as the area // that would be painted if the path were stroked using the pen // currently selected into the given device context. if (currentPath != null && currentPenStroke != null) { GeneralPath newPath = new GeneralPath( renderer.getWindingRule()); newPath.append(currentPenStroke.createStrokedShape(currentPath), false); renderer.setPath(newPath); } } } a/src/main/java/org/freehep/graphicsio/emf/gdiplus/000077500000000000000000000000001167637521400225215ustar00rootroot00000000000000a/src/main/java/org/freehep/graphicsio/emf/gdiplus/Clear.java000066400000000000000000000020151167637521400244100ustar00rootroot00000000000000// Copyright 2006, FreeHEP. package org.freehep.graphicsio.emf.gdiplus; import java.awt.Color; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; /** * The Clear metafile record represents an operation which * sets the entire drawing surface to a solid color. * * @author Mark Donszelmann * @version $Id$ */ public class Clear extends EMFPlusTag { private Color color = null; public Clear() { super(9, 1); } public Clear(Color color) { this(); flags = 0; this.color = color; } public EMFPlusTag read(int tagID, int flags, EMFInputStream emf, int len) throws IOException { Clear tag = new Clear(); tag.flags = flags; tag.color = emf.readCOLOR(); return tag; } public void write(int tagID, int flags, EMFOutputStream emf) throws IOException { emf.writeCOLOR(color); } public String toString() { return super.toString()+"\n color: "+color; } } a/src/main/java/org/freehep/graphicsio/emf/gdiplus/DrawEllipse.java000066400000000000000000000031741167637521400256040ustar00rootroot00000000000000// Copyright 2006, FreeHEP. package org.freehep.graphicsio.emf.gdiplus; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; /** * The DrawEllipse metafile record represents a call to * Graphics.DrawEllipse, which draws the border of an ellipse. * * @author Mark Donszelmann * @version $Id$ */ public class DrawEllipse extends EMFPlusTag { private float x, y, w, h; public DrawEllipse() { super(15, 1); } public DrawEllipse(int penIndex, float x, float y, float w, float h) { this(); flags = penIndex; this.x = x; this.y = y; this.w = w; this.h = h; } public EMFPlusTag read(int tagID, int flags, EMFInputStream emf, int len) throws IOException { DrawEllipse tag = new DrawEllipse(); tag.flags = flags; if ((flags & 0x4000) > 0) { tag.x = emf.readWORD(); tag.y = emf.readWORD(); tag.w = emf.readWORD(); tag.h = emf.readWORD(); } else { tag.x = emf.readFLOAT(); tag.y = emf.readFLOAT(); tag.w = emf.readFLOAT(); tag.h = emf.readFLOAT(); } return tag; } public void write(int tagID, int flags, EMFOutputStream emf) throws IOException { // No Provision for 16 bit integer values. emf.writeFLOAT(x); emf.writeFLOAT(y); emf.writeFLOAT(w); emf.writeFLOAT(h); } public String toString() { return super.toString() +"\n rect: ("+x+", "+y+", "+w+", "+h+")"; } } a/src/main/java/org/freehep/graphicsio/emf/gdiplus/DrawImage.java000066400000000000000000000034011167637521400252220ustar00rootroot00000000000000// Copyright 2006, FreeHEP. package org.freehep.graphicsio.emf.gdiplus; import java.awt.image.RenderedImage; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; /** * The DrawImage metafile record represents a call to Graphics.DrawImage, * which draws a bitmap or other image to the drawing surface. * * FIXME no 16 bit handling * * @author Mark Donszelmann * @version $Id$ */ public class DrawImage extends EMFPlusTag { private RenderedImage image; public DrawImage() { super(26, 1); } public DrawImage(int imageIndex, RenderedImage image) { this(); flags = imageIndex; this.image = image; } public EMFPlusTag read(int tagID, int flags, EMFInputStream emf, int len) throws IOException { DrawImage tag = new DrawImage(); tag.flags = flags; emf.readInt(); // image attributes emf.readUINT(); // source unit emf.readFLOAT(); // X, Y, W, H (src) emf.readFLOAT(); emf.readFLOAT(); emf.readFLOAT(); emf.readFLOAT(); // X, Y, W, H (dst) emf.readFLOAT(); emf.readFLOAT(); emf.readFLOAT(); return tag; } public void write(int tagID, int flags, EMFOutputStream emf) throws IOException { emf.writeInt(-1); // image attributes emf.writeUINT(0x02); // source unit: pixel emf.writeFLOAT(0); // X, Y, W, H (src) emf.writeFLOAT(0); emf.writeFLOAT(image.getWidth()); emf.writeFLOAT(image.getHeight()); emf.writeFLOAT(0); // X, Y, W, H (dst) emf.writeFLOAT(0); emf.writeFLOAT(image.getWidth()); emf.writeFLOAT(image.getHeight()); } } a/src/main/java/org/freehep/graphicsio/emf/gdiplus/DrawLines.java000066400000000000000000000025411167637521400252560ustar00rootroot00000000000000// Copyright 2006, FreeHEP. package org.freehep.graphicsio.emf.gdiplus; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; /** * The DrawLines metafile record represents a call to Graphics.DrawLines, * which draws a series of straight lines connecting successive points. * * No Provision for 16 bit integer values. * * @author Mark Donszelmann * @version $Id$ */ public class DrawLines extends EMFPlusTag { private float[] x, y; public DrawLines() { super(13, 1); } public DrawLines(int penIndex, float[] x, float[] y) { this(); flags = penIndex; this.x = x; this.y = y; } public EMFPlusTag read(int tagID, int flags, EMFInputStream emf, int len) throws IOException { DrawLines tag = new DrawLines(); tag.flags = flags; int n = emf.readUINT(); tag.x = new float[n]; tag.y = new float[n]; for (int i=0; i 0) { tag.brushColor = emf.readCOLOR(); } else { tag.brushIndex = emf.readUINT(); } if ((flags & 0x4000) > 0) { tag.x = emf.readWORD(); tag.y = emf.readWORD(); tag.w = emf.readWORD(); tag.h = emf.readWORD(); } else { tag.x = emf.readFLOAT(); tag.y = emf.readFLOAT(); tag.w = emf.readFLOAT(); tag.h = emf.readFLOAT(); } return tag; } public void write(int tagID, int flags, EMFOutputStream emf) throws IOException { // FIXME No Provision for 16 bit integer values. emf.writeUINT(brushIndex); emf.writeFLOAT(x); emf.writeFLOAT(y); emf.writeFLOAT(w); emf.writeFLOAT(h); } public String toString() { StringBuffer sb = new StringBuffer(super.toString()); sb.append("\n rect: ("+x+", "+y+", "+w+", "+h+")"); sb.append("\n "); sb.append(brushColor != null ? "brushColor: "+brushColor : "brushIndex: "+brushIndex); return sb.toString(); } } a/src/main/java/org/freehep/graphicsio/emf/gdiplus/FillPath.java000066400000000000000000000025401167637521400250700ustar00rootroot00000000000000// Copyright 2006, FreeHEP. package org.freehep.graphicsio.emf.gdiplus; import java.awt.Color; import java.io.IOException; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; /** * The FillPath metafile record represents a call to Graphics.FillPath, * which fills the interior of a GraphicsPath object. * * @author Mark Donszelmann * @version $Id$ */ public class FillPath extends EMFPlusTag { private Color brushColor = null; private int brushIndex; public FillPath() { super(20, 1); } public FillPath(int pathIndex, int brushIndex) { this(); flags = pathIndex; this.brushIndex = brushIndex; } public EMFPlusTag read(int tagID, int flags, EMFInputStream emf, int len) throws IOException { FillPath tag = new FillPath(); tag.flags = flags; if ((flags & 0x8000) > 0) { tag.brushColor = emf.readCOLOR(); } else { tag.brushIndex = emf.readUINT(); } return tag; } public void write(int tagID, int flags, EMFOutputStream emf) throws IOException { if (brushColor != null) { emf.writeCOLOR(brushColor); } else { emf.writeUINT(brushIndex); } } public String toString() { return super.toString() + "\n " + (brushColor != null ? "brushColor: "+brushColor : "brushIndex: "+brushIndex); } } a/src/main/java/org/freehep/graphicsio/emf/gdiplus/GDIPlusObject.java000066400000000000000000000324241167637521400257670ustar00rootroot00000000000000// Copyright 2006, FreeHEP. package org.freehep.graphicsio.emf.gdiplus; import java.awt.BasicStroke; import java.awt.Color; import java.awt.GradientPaint; import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; import java.awt.TexturePaint; import java.awt.geom.AffineTransform; import java.awt.image.RenderedImage; import java.io.IOException; import java.util.Properties; import org.freehep.graphicsio.ImageGraphics2D; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFOutputStream; /** * The Object metafile record contains information on an object * which must be stored for use by a future metafile record. * Examples include pens, brushes, fonts, images, StringFormat * objects, and so on. Naturally, the data format of each type * of object differs, and so the Flags value is used to determine * which type of object is being stored. *

* Object metafile records contain a numeric index (0 to 255). * The first Object record to appear in the file will have an * index of 0, the next record 1, and so on. Applications which * process metafiles should store these objects in an index-based * collection so that a later record can access them. For example, * a future DrawRects record might reference the Pen with index 2, * and the application should ensure that that object is still * accessible. Since the index is only one byte, only 256 objects * can be stored at any time. Thus, a simple stack will not suffice * and applications will have to be prepared for new Object records * overwriting old ones with the same index. * * FIXME: no support for 16 bit * * @author Mark Donszelmann * @version $Id$ */ public class GDIPlusObject extends EMFPlusTag { protected final static int INVALID = 0x000; protected final static int BRUSH = 0x100; protected final static int PEN = 0x200; protected final static int PATH = 0x300; protected final static int REGION = 0x400; protected final static int IMAGE = 0x500; protected final static int FONT = 0x600; protected final static int STRING_FORMAT = 0x700; protected final static int IMAGE_ATTRIBUTES = 0x800; protected final static int CUSTOM_LINE_CAP = 0x900; protected final static int BRUSH_TYPE_SOLID_COLOR = 0; protected final static int BRUSH_TYPE_HATCH_FILL = 1; protected final static int BRUSH_TYPE_TEXTURE_GRADIENT = 2; protected final static int BRUSH_TYPE_PATH_GRADIENT = 3; protected final static int BRUSH_TYPE_LINEAR_GRADIENT = 4; protected final static int WRAP_MODE_TYLE = 0; protected final static int WRAP_MODE_TYLE_FLIP_X = 1; protected final static int WRAP_MODE_TYLE_FLIP_Y = 2; protected final static int WRAP_MODE_TYLE_FLIP_XY = 3; protected final static int WRAP_MODE_CLAMP = 4; protected final static int IMAGE_TYPE_UNKNOWN = 0; protected final static int IMAGE_TYPE_BITMAP = 1; protected final static int IMAGE_TYPE_METAFILE = 2; protected final static int FILL_MODE_ALTERNATE = 0x0000; protected final static int FILL_MODE_WINDING = 0x2000; private Paint brush; private BasicStroke stroke; private PathPoint[] path; private int pathFillMode; private RenderedImage image; public GDIPlusObject() { super(8,1); } public GDIPlusObject(int index, Paint brush) { this(); this.brush = brush; flags = index | BRUSH; } public GDIPlusObject(int index, Stroke stroke, Paint brush) { this(); if (!(stroke instanceof BasicStroke)) throw new IllegalArgumentException(getClass()+": can only handle Stroke of class BasicStroke"); this.stroke = (BasicStroke)stroke; this.brush = brush; flags = index | PEN; } public GDIPlusObject(int index, Shape shape, boolean windingFill) { this(); try { EMFPlusPathConstructor p = new EMFPlusPathConstructor(); p.reset(); p.addPath(shape); path = p.getPath(); flags = index | PATH; pathFillMode = windingFill ? FILL_MODE_WINDING : FILL_MODE_ALTERNATE; } catch (IOException e) { // ignored } } public GDIPlusObject(int index, RenderedImage image) { this(); this.image = image; flags = index | IMAGE; } public EMFPlusTag read(int tagID, int flags, EMFInputStream emf, int len) throws IOException { GDIPlusObject tag = new GDIPlusObject(); tag.flags = flags; int type = flags & 0x0000FF00; // FIXME some missing switch(type) { case BRUSH: tag.brush = readBrush(emf); break; case PEN: emf.readUINT(); // magic word emf.readUINT(); // unknown emf.readUINT(); // additional flags, NOTE no join, endcap, miterlimit etc. emf.readUINT(); // unknown float lineWidth = emf.readFLOAT(); tag.stroke = new BasicStroke(lineWidth); tag.brush = readBrush(emf); break; case PATH: emf.readUINT(); // magic word tag.path = new PathPoint[emf.readUINT()]; int moreFlags = emf.readUINT(); pathFillMode = moreFlags & 0x2000; for (int i=0; i 0) { for (int i=4-(tag.path.length%4); i>0; i--) { emf.readBYTE(); } } break; case INVALID: default: System.err.println ("GDIObject: Invalid TYPE: "+Integer.toHexString(type)); break; } return tag; } public void write(int tagID, int flags, EMFOutputStream emf) throws IOException { int type = flags & 0x0000FF00; switch(type) { case BRUSH: writeBrush(emf, brush); break; case PEN: emf.writeUINT(0xDBC01001); emf.writeUINT(0x0000); // unknown emf.writeUINT(0x0000); // additional flags, NOTE no join, endcap, miterlimit etc. emf.writeUINT(0x0000); // unknown emf.writeFLOAT(stroke.getLineWidth()); writeBrush(emf, brush); break; case PATH: emf.writeUINT(0xDBC01001); emf.writeUINT(path.length); emf.writeUINT(pathFillMode); for (int i=0; i 0) { for (int i=4-(path.length%4); i>0; i--) { emf.writeBYTE(0); } } break; case IMAGE: writeImage(emf, image); break; case INVALID: default: break; } } public String toString() { StringBuffer sb = new StringBuffer(super.toString()); sb.append("\n "); int type = flags & 0x0000FF00; switch(type) { case BRUSH: sb.append("brush: "+brush); break; case PEN: sb.append("stroke: "+stroke); sb.append("\n brush: "+brush); break; case PATH: sb.append("fillMode: "+pathFillMode); sb.append("\n n: "+path.length); for (int i=0; i EMF, Enhanced Meta File, Input and Output Format.

EMF is meant as interchange format for MS Office tools. This driver generates EMF for Office 2000 and up. Earlier versions of Office may have problems.

The following Limitations exist:

@status Stable.

a/src/main/java/overview.html000066400000000000000000000001271167637521400165020ustar00rootroot00000000000000 This is the API specification of the FreeHEP VectorGraphics package. a/src/main/resources/000077500000000000000000000000001167637521400150375ustar00rootroot00000000000000a/src/main/resources/META-INF/000077500000000000000000000000001167637521400161775ustar00rootroot00000000000000a/src/main/resources/META-INF/services/000077500000000000000000000000001167637521400200225ustar00rootroot00000000000000a/src/main/resources/META-INF/services/org.freehep.util.export.ExportFileType000066400000000000000000000001361167637521400273670ustar00rootroot00000000000000org.freehep.graphicsio.emf.EMFExportFileType org.freehep.graphicsio.emf.EMFPlusExportFileType a/src/site/000077500000000000000000000000001167637521400130455ustar00rootroot00000000000000a/src/site/site.xml000066400000000000000000000017371167637521400145430ustar00rootroot00000000000000 FreeHEP GraphicsIO EMF http://java.freehep.org/mvn/freehep-graphicsio-emf FreeHEP http://java.freehep.org/images/sm-freehep.gif http://java.freehep.org/ a/src/test/000077500000000000000000000000001167637521400130605ustar00rootroot00000000000000a/src/test/java/000077500000000000000000000000001167637521400140015ustar00rootroot00000000000000a/src/test/java/org/000077500000000000000000000000001167637521400145705ustar00rootroot00000000000000a/src/test/java/org/freehep/000077500000000000000000000000001167637521400162065ustar00rootroot00000000000000a/src/test/java/org/freehep/graphicsio/000077500000000000000000000000001167637521400203365ustar00rootroot00000000000000a/src/test/java/org/freehep/graphicsio/emf/000077500000000000000000000000001167637521400211055ustar00rootroot00000000000000a/src/test/java/org/freehep/graphicsio/emf/test/000077500000000000000000000000001167637521400220645ustar00rootroot00000000000000a/src/test/java/org/freehep/graphicsio/emf/test/EMFAnalyze.java000066400000000000000000000032221167637521400246610ustar00rootroot00000000000000// Copyright 2003, FreeHEP. package org.freehep.graphicsio.emf.test; import hep.aida.IAnalysisFactory; import hep.aida.ITree; import hep.aida.ITuple; import hep.aida.ITupleFactory; import java.io.FileInputStream; import java.io.IOException; import org.freehep.graphicsio.emf.EMFHeader; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.util.io.Tag; /** * @author Mark Donszelmann * @version $Id$ */ public class EMFAnalyze { public static void main(String[] args) { try { IAnalysisFactory af = IAnalysisFactory.create(); ITree tree = af.createTreeFactory().create("EMFAnalyze.aida", "xml", false, true); ITupleFactory tf = af.createTupleFactory(tree); ITuple tuple = tf.create("EMF", "TagType", new String[] { "Tag", "TagSize" }, new Class[] { String.class, int.class }); FileInputStream fis = new FileInputStream(args[0]); EMFInputStream emf = new EMFInputStream(fis); long start = System.currentTimeMillis(); EMFHeader header = emf.readHeader(); System.out.println(header); Tag tag = emf.readTag(); while (tag != null) { // System.out.println(tag); tuple.fill(0, tag.getName()); tuple.addRow(); tag = emf.readTag(); // FIXME add tagSize } tree.commit(); System.out.println("Analyzed file in: " + (System.currentTimeMillis() - start) + " ms."); } catch (IOException e) { e.printStackTrace(); } } } a/src/test/java/org/freehep/graphicsio/emf/test/EMFDump.java000066400000000000000000000020061167637521400241620ustar00rootroot00000000000000// Copyright 2001, FreeHEP. package org.freehep.graphicsio.emf.test; import java.io.FileInputStream; import java.io.IOException; import org.freehep.graphicsio.emf.EMFHeader; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.util.io.Tag; /** * @author Mark Donszelmann * @version $Id$ */ public class EMFDump { public static void main(String[] args) { try { FileInputStream fis = new FileInputStream(args[0]); EMFInputStream emf = new EMFInputStream(fis); long start = System.currentTimeMillis(); EMFHeader header = emf.readHeader(); System.out.println(header); Tag tag = emf.readTag(); while (tag != null) { System.out.println(tag); tag = emf.readTag(); } System.out.println("Parsed file in: " + (System.currentTimeMillis() - start) + " ms."); } catch (IOException e) { e.printStackTrace(); } } } a/src/test/java/org/freehep/graphicsio/emf/test/EMFPlusDrawLinesTest.java000066400000000000000000000041101167637521400266470ustar00rootroot00000000000000// Copyright 2006, FreeHEP. package org.freehep.graphicsio.emf.test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; import java.awt.Rectangle; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.swing.JPanel; import org.freehep.graphicsio.emf.EMFHandleManager; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.gdi.EOF; import org.freehep.graphicsio.emf.gdi.GDIComment; import org.freehep.graphicsio.emf.gdiplus.Clear; import org.freehep.graphicsio.emf.gdiplus.DrawLines; import org.freehep.graphicsio.emf.gdiplus.EndOfFile; import org.freehep.graphicsio.emf.gdiplus.GDIPlusObject; import org.freehep.graphicsio.emf.gdiplus.Header; public class EMFPlusDrawLinesTest extends JPanel { private static final long serialVersionUID = 1L; public EMFPlusDrawLinesTest() { } public void run() throws IOException { Rectangle bounds = new Rectangle(0, 0, 400, 400); List emf = new ArrayList(); emf.add(new GDIComment(new Header())); emf.add(new GDIComment(new Clear(Color.ORANGE))); emf.add(new GDIComment(new GDIPlusObject(0, new BasicStroke(3), Color.BLACK))); float x[] = { 20, 50, 200 }; float y[] = { 50, 100, 200 }; emf.add(new GDIComment(new DrawLines(0, x, y))); emf.add(new GDIComment(new EndOfFile())); emf.add(new EOF()); EMFOutputStream out = new EMFOutputStream(new FileOutputStream( "EMFPlusDrawLinesTest.emf"), bounds, new EMFHandleManager(), "EMFTest", "TestFile", new Dimension(1024, 768), 0x4001); for (int i = 0; i < emf.size(); i++) { out.writeTag((EMFTag) emf.get(i)); } out.close(); } public static void main(String[] args) throws IOException { EMFPlusDrawLinesTest test = new EMFPlusDrawLinesTest(); test.run(); System.exit(0); } } a/src/test/java/org/freehep/graphicsio/emf/test/EMFTest.java000066400000000000000000000154121167637521400242010ustar00rootroot00000000000000package org.freehep.graphicsio.emf.test; import java.awt.Color; import java.awt.Dimension; import java.awt.Image; import java.awt.MediaTracker; import java.awt.Point; import java.awt.Rectangle; import java.io.FileOutputStream; import java.io.IOException; import java.util.Vector; import javax.swing.JPanel; import org.freehep.graphicsio.emf.EMFConstants; import org.freehep.graphicsio.emf.EMFHandleManager; import org.freehep.graphicsio.emf.EMFOutputStream; import org.freehep.graphicsio.emf.EMFTag; import org.freehep.graphicsio.emf.gdi.EOF; import org.freehep.graphicsio.emf.gdi.GDIComment; import org.freehep.graphicsio.emf.gdi.SetBkMode; import org.freehep.graphicsio.emf.gdi.SetMapMode; import org.freehep.graphicsio.emf.gdi.SetStretchBltMode; import org.freehep.graphicsio.emf.gdi.SetViewportExtEx; import org.freehep.graphicsio.emf.gdi.SetViewportOrgEx; import org.freehep.graphicsio.emf.gdi.SetWindowExtEx; import org.freehep.graphicsio.emf.gdi.SetWindowOrgEx; import org.freehep.graphicsio.emf.gdi.StretchDIBits; import org.freehep.util.images.ImageHandler; import org.freehep.util.images.ImageUtilities; public class EMFTest extends JPanel { private static final long serialVersionUID = 1L; public EMFTest() { } public void run() throws IOException { Rectangle bounds = new Rectangle(0, 0, 800, 600); /* Point p1[][] = { { new Point(40, 50), new Point(160, 170), new Point(80, 30) } }; Point p2[] = { new Point(20, 20), new Point(40, 60), new Point(30, 50), new Point(00, 60) }; */ Vector emf = new Vector(); emf.add(new GDIComment("Settings")); emf.add(new SetMapMode(SetMapMode.MM_ANISOTROPIC)); emf.add(new SetBkMode(SetBkMode.BKG_TRANSPARENT)); emf.add(new SetWindowOrgEx(new Point(0, 0))); emf.add(new SetViewportOrgEx(new Point(0, 0))); emf.add(new SetWindowExtEx(new Dimension(bounds.width, bounds.height))); emf .add(new SetViewportExtEx(new Dimension(bounds.width, bounds.height))); /* * emf.add(new SaveDC()); * * emf.add(new GDIComment("Polygon")); LogBrush32 brush = new * LogBrush32(LogBrush32.BS_SOLID, Color.red, 0); emf.add(new * CreateBrushIndirect(1, brush)); emf.add(new SelectObject(1)); * ExtLogPen pen1 = new ExtLogPen(ExtLogPen.PS_GEOMETRIC | * ExtLogPen.PS_SOLID | ExtLogPen.PS_ENDCAP_ROUND | * ExtLogPen.PS_JOIN_ROUND, 5, ExtLogPen.BS_SOLID, Color.green, 0, new * int[0]); emf.add(new ExtCreatePen(2, pen1)); emf.add(new * SelectObject(2)); emf.add(new SetMiterLimit(10)); emf.add(new * PolyPolygon(bounds, p1)); emf.add(new DeleteObject(1)); emf.add(new * DeleteObject(2)); * * emf.add(new GDIComment("Polyline")); emf.add(new * ModifyWorldTransform(new AffineTransform(1, 0, 0, 1, 200, 0), * ModifyWorldTransform.MWT_LEFTMULTIPLY)); ExtLogPen pen2 = new * ExtLogPen(ExtLogPen.PS_GEOMETRIC | ExtLogPen.PS_SOLID | * ExtLogPen.PS_ENDCAP_ROUND | ExtLogPen.PS_JOIN_ROUND, 5, * ExtLogPen.BS_SOLID, Color.blue, 0, new int[0]); emf.add(new * ExtCreatePen(1, pen2)); emf.add(new SelectObject(1)); emf.add(new * SetMiterLimit(10)); emf.add(new Polyline(bounds, p2)); emf.add(new * DeleteObject(1)); * * emf.add(new GDIComment("Ellipse")); emf.add(new * ModifyWorldTransform(new AffineTransform(1, 0, 0, 1, 200, 0), * ModifyWorldTransform.MWT_LEFTMULTIPLY)); ExtLogPen pen3 = new * ExtLogPen(ExtLogPen.PS_GEOMETRIC | ExtLogPen.PS_SOLID | * ExtLogPen.PS_ENDCAP_ROUND | ExtLogPen.PS_JOIN_ROUND, 5, * ExtLogPen.BS_SOLID, Color.orange, 0, new int[0]); emf.add(new * ExtCreatePen(1, pen3)); emf.add(new SelectObject(1)); emf.add(new * SetMiterLimit(10)); emf.add(new Ellipse(new Rectangle(20,20,50,30))); * emf.add(new DeleteObject(1)); * * emf.add(new RestoreDC()); * * emf.add(new GDIComment("Arc")); emf.add(new ModifyWorldTransform(new * AffineTransform(1, 0, 0, 1, 0, 200), * ModifyWorldTransform.MWT_LEFTMULTIPLY)); ExtLogPen pen4 = new * ExtLogPen(ExtLogPen.PS_GEOMETRIC | ExtLogPen.PS_SOLID | * ExtLogPen.PS_ENDCAP_ROUND | ExtLogPen.PS_JOIN_ROUND, 5, * ExtLogPen.BS_SOLID, Color.cyan, 0, new int[0]); emf.add(new * ExtCreatePen(1, pen4)); emf.add(new SelectObject(1)); emf.add(new * SetMiterLimit(10)); emf.add(new AngleArc(new Point(100,100), 50, 20, * 280)); emf.add(new DeleteObject(1)); * * emf.add(new GDIComment("Image")); emf.add(new * ModifyWorldTransform(new AffineTransform(1, 0, 0, 1, 0, 200), * ModifyWorldTransform.MWT_LEFTMULTIPLY)); */ MediaTracker t = new MediaTracker(this); Image image = ImageHandler.getImage("BrokenCursor.gif", getClass()); t.addImage(image, 0); try { t.waitForAll(); } catch (InterruptedException e) { e.printStackTrace(); } emf.add(new SetStretchBltMode(EMFConstants.COLORONCOLOR)); emf.add(new StretchDIBits( bounds, 0, 0, image.getWidth(this), image.getHeight(this), ImageUtilities.createBufferedImage(image, this, Color.BLACK), Color.BLACK)); /* * emf.add(new GDIComment("Text")); emf.add(new ModifyWorldTransform(new * AffineTransform(1, 0, 0, 1, 0, 200), * ModifyWorldTransform.MWT_LEFTMULTIPLY)); * * LogFontW font = new LogFontW(-82, 0, 0, 0, 265, false, false, false, * 0xCC, 7, 2, 1, 0x22, "Arial TUR"); Panose panose = new Panose(); * ExtLogFontW extFont = new ExtLogFontW(font, "", "", 0, 0, 0, new * byte[] {0, 0, 0, 0}, 0, panose); emf.add(new * ExtCreateFontIndirectW(1, extFont)); * * emf.add(new SelectObject(1)); Text text = new Text(new Point (0, 0), * "Test", Text.ETO_OPAQUE, bounds); emf.add(new ExtTextOutA(new * Rectangle(0,0,100,100), ExtTextOutA.GM_COMPATIBLE, 100, 100, text)); * emf.add(new DeleteObject(1)); * */ emf.add(new GDIComment("End")); emf.add(new EOF()); EMFOutputStream out = new EMFOutputStream(new FileOutputStream( "EMFTest.emf"), bounds, new EMFHandleManager(), "EMFTest", "TestFile", new Dimension(1024, 768)); for (int i = 0; i < emf.size(); i++) { out.writeTag((EMFTag) emf.get(i)); } out.close(); } public static void main(String[] args) throws IOException { EMFTest test = new EMFTest(); test.run(); System.exit(0); } } a/src/test/java/org/freehep/graphicsio/emf/test/EMFTestSuite.java000066400000000000000000000006511167637521400252120ustar00rootroot00000000000000// Copyright 2005-2006, FreeHEP. package org.freehep.graphicsio.emf.test; import org.freehep.graphicsio.test.TestSuite; /** * @author Mark Donszelmann * @version $Id$ */ public class EMFTestSuite extends TestSuite { public static TestSuite suite() { EMFTestSuite suite = new EMFTestSuite(); // FIXME: re-enable // suite.addTests("EMF"); suite.addTests("EMF+"); return suite; } } a/src/test/java/org/freehep/graphicsio/emf/test/package.html000066400000000000000000000000641167637521400243450ustar00rootroot00000000000000 Tests for the EMF Reader and Writer.