View Javadoc

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   * PolyBezier TAG.
15   * 
16   * @author Mark Donszelmann
17   * @version $Id: PolyBezier.java 10367 2007-01-22 19:26:48Z duns $
18   */
19  public class PolyBezier extends AbstractPolygon {
20  
21      public PolyBezier() {
22          super(2, 1, null, 0, null);
23      }
24  
25      public PolyBezier(Rectangle bounds, int numberOfPoints, Point[] points) {
26          super(2, 1, bounds, numberOfPoints, points);
27      }
28  
29      protected PolyBezier (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 PolyBezier(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          int numberOfPoints = getNumberOfPoints();
49  
50          if (points != null && points.length > 0) {
51              GeneralPath gp = new GeneralPath(
52                  renderer.getWindingRule());
53              Point p = points[0];
54              gp.moveTo((float) p.getX(),  (float)p.getY());
55  
56              for (int point = 1; point < numberOfPoints; point = point + 3) {
57                  // add a point to gp
58                  Point p1 = points[point];
59                  Point p2 = points[point + 1];
60                  Point p3 = points[point + 2];
61                  if (point > 0) {
62                      gp.curveTo(
63                          (float)p1.getX(), (float)p1.getY(),
64                          (float)p2.getX(), (float)p2.getY(),
65                          (float)p3.getX(), (float)p3.getY());
66                  }
67              }
68              renderer.fillAndDrawOrAppend(gp);
69          }
70      }
71  }