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