| 1 |
// Copyright 2002, FreeHEP. |
| 2 |
package org.freehep.graphicsio.emf.gdi; |
| 3 |
|
| 4 |
import java.awt.Point; |
| 5 |
import java.awt.Rectangle; |
| 6 |
import java.awt.geom.GeneralPath; |
| 7 |
import java.io.IOException; |
| 8 |
|
| 9 |
import org.freehep.graphicsio.emf.EMFInputStream; |
| 10 |
import org.freehep.graphicsio.emf.EMFTag; |
| 11 |
import org.freehep.graphicsio.emf.EMFRenderer; |
| 12 |
|
| 13 |
/** |
| 14 |
* PolylineTo TAG. |
| 15 |
* |
| 16 |
* @author Mark Donszelmann |
| 17 |
* @version $Id: freehep-graphicsio-emf/src/main/java/org/freehep/graphicsio/emf/gdi/EMFPolygon.java c0f15e7696d3 2007/01/22 19:26:48 duns $ |
| 18 |
*/ |
| 19 |
public class EMFPolygon extends AbstractPolygon { |
| 20 |
|
| 21 |
public EMFPolygon() { |
| 22 |
super(3, 1, null, 0, null); |
| 23 |
} |
| 24 |
|
| 25 |
public EMFPolygon(Rectangle bounds, int numberOfPoints, Point[] points) { |
| 26 |
super(3, 1, bounds, numberOfPoints, points); |
| 27 |
} |
| 28 |
|
| 29 |
protected EMFPolygon (int id, int version, Rectangle bounds, int numberOfPoints, Point[] points) { |
| 30 |
super(id, version, bounds, numberOfPoints, points); |
| 31 |
} |
| 32 |
|
| 33 |
public EMFTag read(int tagID, EMFInputStream emf, int len) |
| 34 |
throws IOException { |
| 35 |
|
| 36 |
Rectangle r = emf.readRECTL(); |
| 37 |
int n = emf.readDWORD(); |
| 38 |
return new EMFPolygon(r, n, emf.readPOINTL(n)); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* displays the tag using the renderer |
| 43 |
* |
| 44 |
* @param renderer EMFRenderer storing the drawing session data |
| 45 |
*/ |
| 46 |
public void render(EMFRenderer renderer) { |
| 47 |
Point[] points = getPoints(); |
| 48 |
|
| 49 |
// Safety check. |
| 50 |
if (points.length > 1) { |
| 51 |
GeneralPath path = new GeneralPath( |
| 52 |
renderer.getWindingRule()); |
| 53 |
path.moveTo((float)points[0].getX(), (float)points[0].getY()); |
| 54 |
for (int i = 1; i < points.length; i++) { |
| 55 |
path.lineTo((float)points[i].getX(), (float)points[i].getY()); |
| 56 |
} |
| 57 |
path.closePath(); |
| 58 |
renderer.fillAndDrawOrAppend(path); |
| 59 |
} |
| 60 |
} |
| 61 |
} |