1 // Copyright 2002, FreeHEP.
2 package org.freehep.graphicsio.emf.gdi;
3
4 import java.awt.geom.AffineTransform;
5 import java.io.IOException;
6
7 import org.freehep.graphicsio.emf.EMFConstants;
8 import org.freehep.graphicsio.emf.EMFInputStream;
9 import org.freehep.graphicsio.emf.EMFOutputStream;
10 import org.freehep.graphicsio.emf.EMFTag;
11 import org.freehep.graphicsio.emf.EMFRenderer;
12
13 /**
14 * ModifyWorldTransform TAG.
15 *
16 * @author Mark Donszelmann
17 * @version $Id: ModifyWorldTransform.java 10377 2007-01-23 15:44:34Z duns $
18 */
19 public class ModifyWorldTransform extends EMFTag implements EMFConstants {
20
21 private AffineTransform transform;
22
23 private int mode;
24
25 public ModifyWorldTransform() {
26 super(36, 1);
27 }
28
29 public ModifyWorldTransform(AffineTransform transform, int mode) {
30 this();
31 this.transform = transform;
32 this.mode = mode;
33 }
34
35 public EMFTag read(int tagID, EMFInputStream emf, int len)
36 throws IOException {
37
38 return new ModifyWorldTransform(
39 emf.readXFORM(),
40 emf.readDWORD());
41 }
42
43 public void write(int tagID, EMFOutputStream emf) throws IOException {
44 emf.writeXFORM(transform);
45 emf.writeDWORD(mode);
46 }
47
48 public String toString() {
49 return super.toString() +
50 "\n transform: " + transform +
51 "\n mode: " + mode;
52 }
53
54 /**
55 * displays the tag using the renderer
56 *
57 * @param renderer EMFRenderer storing the drawing session data
58 */
59 public void render(EMFRenderer renderer) {
60 // MWT_IDENTITY Resets the current world transformation by using
61 // the identity matrix. If this mode is specified, the XFORM structure
62 // pointed to by lpXform is ignored.
63 if (mode == EMFConstants.MWT_IDENTITY) {
64 if (renderer.getPath() != null) {
65 renderer.setPathTransform(new AffineTransform());
66 } else {
67 renderer.resetTransformation();
68 }
69 }
70
71 // MWT_LEFTMULTIPLY Multiplies the current transformation by the
72 // data in the XFORM structure. (The data in the XFORM structure becomes
73 // the left multiplicand, and the data for the current transformation
74 // becomes the right multiplicand.)
75 else if (mode == EMFConstants.MWT_LEFTMULTIPLY) {
76 if (renderer.getPath() != null) {
77 renderer.getPathTransform().concatenate(transform);
78 renderer.transform(transform);
79 } else {
80 renderer.transform(transform);
81 }
82 }
83
84 // MWT_RIGHTMULTIPLY Multiplies the current transformation by the data
85 // in the XFORM structure. (The data in the XFORM structure becomes the
86 // right multiplicand, and the data for the current transformation
87 // becomes the left multiplicand.)
88 else if (mode != EMFConstants.MWT_RIGHTMULTIPLY) {
89 // TODO expected that this should work but it doesn't
90 // doing nothing renders the right emf embedding
91
92 /* if (renderer.getPath() != null) {
93 AffineTransform transform = new AffineTransform(this.transform);
94 transform.concatenate(renderer.getPathTransform());
95 renderer.setPathTransform(transform);
96 } else {
97 AffineTransform transform = new AffineTransform(this.transform);
98 transform.concatenate(renderer.getTransform());
99 renderer.resetTransformation();
100 renderer.transform(transform);
101 }*/
102 }
103
104 // Unknown mode
105 else {
106 logger.warning("unsupport transform mode " + toString());
107 }
108 }
109 }