1
2 package org.freehep.graphicsio.emf.gdi;
3
4 import org.freehep.graphicsio.emf.EMFTag;
5 import org.freehep.graphicsio.emf.EMFRenderer;
6 import org.freehep.graphicsio.emf.EMFConstants;
7 import org.freehep.graphicsio.emf.EMFOutputStream;
8
9 import java.awt.geom.Arc2D;
10 import java.awt.Rectangle;
11 import java.awt.Point;
12 import java.awt.Shape;
13 import java.io.IOException;
14
15
16
17
18
19 public abstract class AbstractArc extends EMFTag {
20
21 private Rectangle bounds;
22
23 private Point start, end;
24
25 protected AbstractArc(int id, int version, Rectangle bounds, Point start, Point end) {
26 super(id, version);
27 this.bounds = bounds;
28 this.start = start;
29 this.end = end;
30 }
31
32 public void write(int tagID, EMFOutputStream emf) throws IOException {
33 emf.writeRECTL(bounds);
34 emf.writePOINTL(start);
35 emf.writePOINTL(end);
36 }
37
38 public String toString() {
39 return super.toString() +
40 "\n bounds: " + bounds +
41 "\n start: " + start +
42 "\n end: " + end;
43 }
44
45
46
47
48
49
50
51
52 protected Shape getShape(EMFRenderer renderer, int arcType) {
53
54 double nx0 = start.getX() / bounds.getWidth();
55
56
57 double nx1 = end.getX() / bounds.getWidth();
58
59
60
61 double alpha0, alpha1;
62 if (renderer.getArcDirection() == EMFConstants.AD_CLOCKWISE) {
63 alpha0 = Math.acos(nx0);
64 alpha1 = Math.acos(nx1);
65 } else {
66 alpha0 = Math.acos(nx1);
67 alpha1 = Math.acos(nx0);
68 }
69
70 return new Arc2D.Double(
71 start.getX(),
72 start.getY(),
73 bounds.getWidth(),
74 bounds.getHeight(),
75 alpha0,
76 alpha1 - alpha0,
77 arcType);
78 }
79 }