/**
  * 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);
 }
Exemple #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();
   }
 }
 public void moveTo(float x, float y) {
   gp.moveTo(x, y);
   this.x = x;
   this.y = y;
   points.add(new GlyphPoint(x, y, false));
 }