Exemplo n.º 1
0
 @Override
 public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
   polygonsStart.append(xs.size());
   polygonsSize.append(nPoints);
   xs.append(xPoints, 0, nPoints, tx);
   ys.append(yPoints, 0, nPoints, ty);
 }
Exemplo n.º 2
0
 @Override
 public void drawLine(int x1, int y1, int x2, int y2) {
   linesStart.append(xs.size());
   xs.append(x1 + tx);
   xs.append(x2 + tx);
   ys.append(y1 + ty);
   ys.append(y2 + ty);
 }
Exemplo n.º 3
0
 @Override
 public void write(DataOutput out) throws IOException {
   out.writeInt(width);
   out.writeInt(height);
   xs.write(out);
   ys.write(out);
   linesStart.write(out);
   polylinesStart.write(out);
   polylinesSize.write(out);
   polygonsStart.write(out);
   polygonsSize.write(out);
   rectanglesStart.write(out);
 }
Exemplo n.º 4
0
 @Override
 public void readFields(DataInput in) throws IOException {
   width = in.readInt();
   height = in.readInt();
   xs.readFields(in);
   ys.readFields(in);
   linesStart.readFields(in);
   polylinesStart.readFields(in);
   polylinesSize.readFields(in);
   polygonsStart.readFields(in);
   polygonsSize.readFields(in);
   rectanglesStart.readFields(in);
 }
Exemplo n.º 5
0
 @Override
 public void fillRect(int x, int y, int width, int height) {
   rectanglesStart.append(xs.size());
   xs.append(x + tx);
   ys.append(y + ty);
   xs.append(width);
   ys.append(height);
 }
Exemplo n.º 6
0
  public void writeAsSVG(PrintStream p) {
    // Write header
    p.println("<?xml version='1.0' standalone='no'?>");
    p.println(
        "<!DOCTYPE svg PUBLIC '-//W3C/DTD SVG 1.1//EN' "
            + "'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>");
    p.printf(
        "<svg width='%d' height='%d' version='1.1' " + "xmlns='http://www.w3.org/2000/svg'>\n",
        width, height);

    // Retrieve all xs and ys as java arrays for efficiency
    int[] xs = this.xs.underlyingArray();
    int[] ys = this.ys.underlyingArray();
    // 1- Draw all lines
    if (linesStart.size() > 0) {
      p.printf("<g style='stroke:rgb(0,0,0);'>\n");
      for (int i = 0; i < linesStart.size(); i++) {
        int lineStart = linesStart.get(i);
        p.printf(
            "<line x1='%d' y1='%d' x2='%d' y2='%d'/>\n",
            xs[lineStart], ys[lineStart], xs[lineStart + 1], ys[lineStart + 1]);
      }
      p.printf("</g>\n");
    }

    // 2- Draw all polygons
    if (polygonsStart.size() > 0) {
      p.printf("<g style='stroke:rgb(0,0,0);'>\n");
      for (int i = 0; i < polygonsStart.size(); i++) {
        int polygonStart = polygonsStart.get(i);
        int polygonSize = polygonsSize.get(i);
        p.print("<polygon points='");
        for (int j = polygonStart; j < polygonStart + polygonSize; j++) {
          p.printf("%d,%d ", xs[j], ys[j]);
        }
        p.println("'/>");
      }
      p.printf("</g>\n");
    }

    // 3- Draw all polylines
    if (polylinesStart.size() > 0) {
      p.printf("<g style='stroke:rgb(0,0,0); fill:none;'>\n");
      for (int i = 0; i < polylinesStart.size(); i++) {
        int polylineStart = polylinesStart.get(i);
        int polylineSize = polylinesSize.get(i);
        p.print("<polyline points='");
        for (int j = polylineStart; j < polylineStart + polylineSize; j++) {
          p.printf("%d,%d ", xs[j], ys[j]);
        }
        p.println("'/>");
      }
      p.printf("</g>\n");
    }
    // 4- Draw all rectangles
    if (rectanglesStart.size() > 0) {
      p.printf("<g style='stroke:rgb(0,0,0); fill:none;'>\n");
      for (int i = 0; i < rectanglesStart.size(); i++) {
        int rectStart = rectanglesStart.get(i);
        p.printf(
            "<rect x='%d' y='%d' width='%d' height='%d'/>\n",
            xs[rectStart], ys[rectStart], xs[rectStart + 1], ys[rectStart + 1]);
      }
      p.printf("</g>\n");
    }

    p.println("</svg>");
  }