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