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.io.IOException;
7   
8   import org.freehep.graphicsio.emf.EMFInputStream;
9   import org.freehep.graphicsio.emf.EMFOutputStream;
10  import org.freehep.graphicsio.emf.EMFTag;
11  
12  /**
13   * PolyPolygon TAG.
14   * 
15   * @author Mark Donszelmann
16   * @version $Id: PolyPolygon.java 10377 2007-01-23 15:44:34Z duns $
17   */
18  public class PolyPolygon extends AbstractPolyPolygon {
19  
20      private int start, end;
21  
22      public PolyPolygon() {
23          super(8, 1, null, null, null);
24      }
25  
26      public PolyPolygon(
27          Rectangle bounds,
28          int start,
29          int end,
30          int[] numberOfPoints,
31          Point[][] points) {
32  
33          super(8, 1, bounds, numberOfPoints, points);
34          this.start = start;
35          this.end = end;
36      }
37  
38      public EMFTag read(int tagID, EMFInputStream emf, int len)
39              throws IOException {
40  
41          Rectangle bounds = emf.readRECTL();
42          int np = emf.readDWORD();
43          /* int totalNumberOfPoints = */ emf.readDWORD();
44          int[] pc = new int[np];
45          Point[][] points = new Point[np][];
46          for (int i = 0; i < np; i++) {
47              pc[i] = emf.readDWORD();
48              points[i] = new Point[pc[i]];
49          }
50          for (int i = 0; i < np; i++) {
51              points[i] = emf.readPOINTL(pc[i]);
52          }
53          return new PolyPolygon(bounds, 0, np - 1, pc, points);
54      }
55  
56      public void write(int tagID, EMFOutputStream emf) throws IOException {
57          int[] numberOfPoints = getNumberOfPoints();
58          Point[][] points = getPoints();
59  
60          emf.writeRECTL(getBounds());
61          emf.writeDWORD(end - start + 1);
62          int c = 0;
63          for (int i = start; i < end + 1; i++) {
64              c += numberOfPoints[i];
65          }
66          emf.writeDWORD(c);
67          for (int i = start; i < end + 1; i++) {
68              emf.writeDWORD(numberOfPoints[i]);
69          }
70          for (int i = start; i < end + 1; i++) {
71              emf.writePOINTL(numberOfPoints[i], points[i]);
72          }
73      }
74  }