1
2 package org.freehep.graphicsio.emf.gdi;
3
4 import org.freehep.graphicsio.emf.EMFTag;
5 import org.freehep.graphicsio.emf.EMFRenderer;
6
7 import java.awt.Point;
8 import java.awt.Rectangle;
9 import java.awt.geom.GeneralPath;
10
11
12
13
14
15
16
17 public abstract class AbstractPolyPolygon extends EMFTag {
18
19 private Rectangle bounds;
20
21 private int[] numberOfPoints;
22
23 private Point[][] points;
24
25
26
27
28
29
30
31
32
33
34 protected AbstractPolyPolygon(
35 int id, int version,
36 Rectangle bounds,
37 int[] numberOfPoints,
38 Point[][] points) {
39
40 super(id, version);
41 this.bounds = bounds;
42 this.numberOfPoints = numberOfPoints;
43 this.points = points;
44 }
45
46 public String toString() {
47 return super.toString() +
48 "\n bounds: " + bounds +
49 "\n #polys: " + numberOfPoints.length;
50 }
51
52 protected Rectangle getBounds() {
53 return bounds;
54 }
55
56 protected int[] getNumberOfPoints() {
57 return numberOfPoints;
58 }
59
60 protected Point[][] getPoints() {
61 return points;
62 }
63
64
65
66
67
68
69
70 public void render(EMFRenderer renderer) {
71 render(renderer, true);
72 }
73
74
75
76
77
78
79
80 protected void render(EMFRenderer renderer, boolean closePath) {
81
82 GeneralPath path = new GeneralPath(
83 renderer.getWindingRule());
84
85
86 Point p;
87 for (int polygon = 0; polygon < numberOfPoints.length; polygon++) {
88
89
90 GeneralPath gp = new GeneralPath(
91 renderer.getWindingRule());
92 for (int point = 0; point < numberOfPoints[polygon]; point ++) {
93
94 p = points[polygon][point];
95 if (point > 0) {
96 gp.lineTo((float) p.getX(), (float)p.getY());
97 } else {
98 gp.moveTo((float) p.getX(), (float)p.getY());
99 }
100 }
101
102
103 if (closePath) {
104 gp.closePath();
105 }
106
107 path.append(gp, false);
108 }
109
110
111 if (closePath) {
112 renderer.fillAndDrawOrAppend(path);
113 } else {
114 renderer.drawOrAppend(path);
115 }
116 }
117 }