Exemplo n.º 1
1
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and shape.
  *
  * @return Returns true, if the polygon is inside of the image bounds.
  */
 private boolean writePolyAttributes(IXMLElement elem, SVGFigure f, Shape shape) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     StringBuilder buf = new StringBuilder();
     float[] coords = new float[6];
     GeneralPath path = new GeneralPath();
     for (PathIterator i = shape.getPathIterator(t, 1.5f);
     ! i.isDone(); i.next()) {
         switch (i.currentSegment(coords)) {
             case PathIterator.SEG_MOVETO :
                 if (buf.length() != 0) {
                     throw new IllegalArgumentException("Illegal shape "+shape);
                 }
                 if (buf.length() != 0) {
                     buf.append(',');
                 }
                 buf.append((int) coords[0]);
                 buf.append(',');
                 buf.append((int) coords[1]);
                 path.moveTo(coords[0], coords[1]);
                 break;
             case PathIterator.SEG_LINETO :
                 if (buf.length() != 0) {
                     buf.append(',');
                 }
                 buf.append((int) coords[0]);
                 buf.append(',');
                 buf.append((int) coords[1]);
                 path.lineTo(coords[0], coords[1]);
                 break;
             case PathIterator.SEG_CLOSE :
                 path.closePath();
                 break;
             default :
                 throw new InternalError("Illegal segment type "+i.currentSegment(coords));
         }
     }
     elem.setAttribute("shape", "poly");
     elem.setAttribute("coords", buf.toString());
     writeHrefAttribute(elem, f);
     return path.intersects(new Rectangle2D.Float(bounds.x, bounds.y, bounds.width, bounds.height));
 }
 public void setAdvance(float adv) {
   advance = adv;
   advp = new GeneralPath();
   advp.moveTo(-2, -2);
   advp.lineTo(2, 2);
   advp.moveTo(-2, 2);
   advp.lineTo(2, -2);
   advp.moveTo(adv - 2, -2);
   advp.lineTo(adv, 0);
   advp.lineTo(adv + 2, -2);
   advp.moveTo(adv, 0);
   advp.lineTo(adv, -8);
 }
Exemplo n.º 3
0
 /**
  * Draw a filled polygon with the given (x[i], y[i]) coordinates.
  *
  * @param x an array of all the x-coordindates of the polygon
  * @param y an array of all the y-coordindates of the polygon
  */
 public static void filledPolygon(double[] x, double[] y) {
   int N = x.length;
   GeneralPath path = new GeneralPath();
   path.moveTo((float) scaleX(x[0]), (float) scaleY(y[0]));
   for (int i = 0; i < N; i++) path.lineTo((float) scaleX(x[i]), (float) scaleY(y[i]));
   path.closePath();
   offscreen.fill(path);
   draw();
 }
 public GlyphPoint(float x, float y, boolean curvectrl) {
   this.x = x;
   this.y = y;
   this.curvecontrol = curvectrl;
   gp = new GeneralPath();
   if (curvectrl) {
     gp.moveTo(x - 4, y - 4);
     gp.lineTo(x + 4, y + 4);
     gp.moveTo(x - 4, y + 4);
     gp.lineTo(x + 4, y - 4);
   } else {
     gp.moveTo(x - 4, y - 4);
     gp.lineTo(x - 4, y + 4);
     gp.lineTo(x + 4, y + 4);
     gp.lineTo(x + 4, y - 4);
     gp.closePath();
   }
 }
Exemplo n.º 5
0
  /** Used to draw a Shape. */
  public static GeneralPath makeShape(float loc[][]) {
    GeneralPath path = new GeneralPath(GeneralPath.WIND_NON_ZERO);

    path.moveTo(loc[0][0], loc[0][1]);

    for (int i = 1; i < loc.length; i++) path.lineTo(loc[i][0], loc[i][1]);

    return path;
  }
 public void drawPolylines(Graphics2D g2) {
   int i, ipol, npoints, noffs;
   // draw GeneralPath (polyline)
   for (ipol = 0; ipol < numpolys; ipol++) {
     noffs = bufpol[ipol];
     npoints = bufpts[noffs + 1];
     if (npoints > 1) { // was 0, TS on 20.08.'12
       polyline.moveTo(bufpts[noffs + 2], bufpts[noffs + 3]);
       for (i = 1; i < npoints; i++) {
         polyline.lineTo(bufpts[noffs + 2 * i + 2], bufpts[noffs + 2 * i + 3]);
       }
       /* //TS on 20.08.'12
                       if (npoints == 1) {
                           polyline.lineTo(bufpts[noffs+2], bufpts[noffs+3]);
                       }
       */
       g2.setStroke(DatanGraphics.strokes[bufpts[noffs] - 1]);
       g2.setPaint(DatanGraphics.ct[bufpts[noffs]]);
       g2.draw(polyline);
       polyline.reset();
     }
   }
 }
 public void lineTo(float x, float y) {
   gp.lineTo(x, y);
   this.x = x;
   this.y = y;
   points.add(new GlyphPoint(x, y, false));
 }