Пример #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));
 }
Пример #2
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 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);
 }
 public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) {
   gp.curveTo(x1, y1, x2, y2, x3, y3);
   this.x = x3;
   this.y = y3;
   points.add(new GlyphPoint(x1, y1, true));
   points.add(new GlyphPoint(x2, y2, true));
   points.add(new GlyphPoint(x3, y3, false));
 }
Пример #5
0
  /**
   * converts this glyph into Shape. It could be called for root's preview mode or by include
   * invoke. Pushing either this GlyphFile or DIncludeInvoke should be handled before this.
   */
  public Shape toShape(AffineTransform a_trans) {

    int ppem = k_defaultPixelSize;

    GeneralPath retval = new GeneralPath();
    Iterator i = createIterator();
    while (i.hasNext()) {
      GlyphObject object = (GlyphObject) i.next();

      if (object instanceof EContourPoint || object instanceof EHint) {
        continue;
      } // if

      retval.append(object.toShape(a_trans, ppem), false);
    } // if

    return retval;
  }
 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 closePath() {
   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));
 }