Package java.awt.geom

Examples of java.awt.geom.PathIterator


   */
  public void writeObject (final Object o, final ObjectOutputStream out)
          throws IOException
  {
    final GeneralPath gp = (GeneralPath) o;
    final PathIterator it = gp.getPathIterator(new AffineTransform());
    out.writeInt(it.getWindingRule());
    while (it.isDone() == false)
    {
      final float[] corrds = new float[6];
      final int type = it.currentSegment(corrds);
      out.writeInt(type);

      switch (type)
      {
        case PathIterator.SEG_MOVETO:
          {
            out.writeFloat(corrds[0]);
            out.writeFloat(corrds[1]);
            break;
          }
        case PathIterator.SEG_LINETO:
          {
            out.writeFloat(corrds[0]);
            out.writeFloat(corrds[1]);
            break;
          }
        case PathIterator.SEG_QUADTO:
          {
            out.writeFloat(corrds[0]);
            out.writeFloat(corrds[1]);
            out.writeFloat(corrds[2]);
            out.writeFloat(corrds[3]);
            break;
          }
        case PathIterator.SEG_CUBICTO:
          {
            out.writeFloat(corrds[0]);
            out.writeFloat(corrds[1]);
            out.writeFloat(corrds[2]);
            out.writeFloat(corrds[3]);
            out.writeFloat(corrds[4]);
            out.writeFloat(corrds[5]);
            break;
          }
        case PathIterator.SEG_CLOSE:
          {
            break;
          }
        default:
          throw new IOException("Unexpected type encountered: " + type);
      }
      it.next();
    }
    out.writeInt(-1);
  }
View Full Code Here


    {
      throw new ObjectFactoryException("Class is not assignable");
    }

    final Shape s = (Shape) o;
    final PathIterator pi = s.getPathIterator(AffineTransform.getTranslateInstance(0, 0));
    if (pi.getWindingRule() == PathIterator.WIND_EVEN_ODD)
    {
      setParameter(GeneralPathObjectDescription.WINDING_RULE_NAME, GeneralPathObjectDescription.WINDING_RULE_EVEN_ODD);
    }
    else
    {
      setParameter(GeneralPathObjectDescription.WINDING_RULE_NAME, GeneralPathObjectDescription.WINDING_RULE_NON_ZERO);
    }

    final float[] points = new float[GeneralPathObjectDescription.MAX_POINTS];
    final ArrayList segments = new ArrayList();
    while (pi.isDone() == false)
    {
      final int type = pi.currentSegment(points);
      final PathIteratorSegment seg = new PathIteratorSegment();
      switch (type)
      {
        case PathIterator.SEG_CLOSE:
        {
          seg.setSegmentType(PathIterator.SEG_CLOSE);
          break;
        }
        case PathIterator.SEG_CUBICTO:
        {
          seg.setSegmentType(PathIterator.SEG_CUBICTO);
          seg.setX1(points[0]);
          seg.setY1(points[1]);
          seg.setX2(points[2]);
          seg.setY2(points[3]);
          seg.setX3(points[4]);
          seg.setY3(points[5]);
          break;
        }
        case PathIterator.SEG_LINETO:
        {
          seg.setSegmentType(PathIterator.SEG_LINETO);
          seg.setX1(points[0]);
          seg.setY1(points[1]);
          break;
        }
        case PathIterator.SEG_MOVETO:
        {
          seg.setSegmentType(PathIterator.SEG_MOVETO);
          seg.setX1(points[0]);
          seg.setY1(points[1]);
          break;
        }
        case PathIterator.SEG_QUADTO:
        {
          seg.setSegmentType(PathIterator.SEG_QUADTO);
          seg.setX1(points[0]);
          seg.setY1(points[1]);
          seg.setX2(points[2]);
          seg.setY2(points[3]);
          break;
        }
        default:
          throw new IllegalStateException("Unexpected result from PathIterator.");
      }
      segments.add(seg);
      pi.next();
    }

    setParameter(GeneralPathObjectDescription.SEGMENTS_NAME, segments.toArray(
        new PathIteratorSegment[segments.size()]));
  }
View Full Code Here

    }
    else if (drawType == PdfGraphics2D.FILL)
    {
      setFillPaint();
    }
    final PathIterator points;
    if (drawType == PdfGraphics2D.CLIP)
    {
      points = s.getPathIterator(PdfGraphics2D.IDENTITY);
    }
    else
    {
      points = s.getPathIterator(transform);
    }
    final float[] coords = new float[6];
    int traces = 0;
    while (!points.isDone())
    {
      ++traces;
      final int segtype = points.currentSegment(coords);
      normalizeY(coords);
      switch (segtype)
      {
        case PathIterator.SEG_CLOSE:
          cb.closePath();
          break;

        case PathIterator.SEG_CUBICTO:
          cb.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
          break;

        case PathIterator.SEG_LINETO:
          cb.lineTo(coords[0], coords[1]);
          break;

        case PathIterator.SEG_MOVETO:
          cb.moveTo(coords[0], coords[1]);
          break;

        case PathIterator.SEG_QUADTO:
          cb.curveTo(coords[0], coords[1], coords[2], coords[3]);
          break;
        default:
          throw new IllegalStateException("Invalid segment type in path");
      }
      points.next();
    }
    switch (drawType)
    {
      case PdfGraphics2D.FILL:
        if (traces > 0)
        {
          if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD)
          {
            cb.eoFill();
          }
          else
          {
            cb.fill();
          }
        }
        break;
      case PdfGraphics2D.STROKE:
        if (traces > 0)
        {
          cb.stroke();
        }
        break;
      default: //drawType==CLIP
        if (traces == 0)
        {
          cb.rectangle(0, 0, 0, 0);
        }
        if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD)
        {
          cb.eoClip();
        }
        else
        {
View Full Code Here

        }

        // Take advantage of CreatePolyPolygonalRgn on w32
        private void setMask(final Component w, final Area area) {
            GDI32 gdi = GDI32.INSTANCE;
            PathIterator pi = area.getPathIterator(null);
            int mode = pi.getWindingRule() == PathIterator.WIND_NON_ZERO
                ? WinGDI.WINDING: WinGDI.ALTERNATE;
            float[] coords = new float[6];
            List<POINT> points = new ArrayList<POINT>();
            int size = 0;
            List<Integer> sizes = new ArrayList<Integer>();
            while (!pi.isDone()) {
                int type = pi.currentSegment(coords);
                if (type == PathIterator.SEG_MOVETO) {
                    size = 1;
                    points.add(new POINT((int)coords[0], (int)coords[1]));
                }
                else if (type == PathIterator.SEG_LINETO) {
                    ++size;
                    points.add(new POINT((int)coords[0], (int)coords[1]));
                }
                else if (type == PathIterator.SEG_CLOSE) {
                    sizes.add(new Integer(size));
                }
                else {
                    throw new RuntimeException("Area is not polygonal: " + area);
                }
                pi.next();
            }
            POINT[] lppt = (POINT[])new POINT().toArray(points.size());
            POINT[] pts = points.toArray(new POINT[points.size()]);
            for (int i=0;i < lppt.length;i++) {
                lppt[i].x = pts[i].x;
View Full Code Here

this.sketchOutlines.optimize();
  }
 
  public void buildPathsFromAWTShape(Shape awtShape){

    PathIterator iter = awtShape.getPathIterator(null);
    SketchPath path = new SketchPath(getParentSketch());
    path.setType(SketchShape.TYPE_PATH);
    float coords[] = new float[6];
    SketchPoint prevVec = null;
   
    while (!iter.isDone()) {
      switch (iter.currentSegment(coords)) {

      case PathIterator.SEG_MOVETO: // 1 point (2 vars) in coords
        this.add(path);
        path = new SketchPath(this.getParentSketch());
        path.add(new SketchPoint(coords[0], coords[1]));

        break;

      case PathIterator.SEG_LINETO: // 1 point
        path.add(new SketchPoint(coords[0], coords[1]));
        break;

      case PathIterator.SEG_QUADTO: // 2 points
        break;

      case PathIterator.SEG_CUBICTO: // 3 points

        prevVec = path.getPath().getLast();
        SketchPoint newVec = new SketchPoint(coords[4], coords[5]);
        Vec2D controlNodeBack = new Vec2D(coords[0], coords[1]);
        Vec2D controlNodeFoward = new Vec2D(coords[2], coords[3]);

        newVec.controlPoint1 = controlNodeFoward;

        if (prevVec != null) {
          prevVec.controlPoint2 = controlNodeBack;
          path.set(path.size() - 1,
              prevVec);
        }
        path.add(newVec);
        break;

      case PathIterator.SEG_CLOSE:
        break;
      }
      iter.next();
    }
    path.setClosed(true);
   
    if(path.getList().size() > 1)
    this.add(path);
View Full Code Here

 

  public void buildOutlinesFromAWTShape(Shape awtShape){

    PathIterator iter = awtShape.getPathIterator(null);
    //PathIterator iter = gPath.getPathIterator(null);
    SketchOutline sktOutline = new SketchOutline(this.getParentSketch());

    float coords[] = new float[6];
    //  System.out.println("before");

    SketchPoint prevVec = null;
    while (!iter.isDone()) {
      switch (iter.currentSegment(coords)) {

      case PathIterator.SEG_MOVETO: // 1 point (2 vars) in coords
        this.sketchOutlines.add(sktOutline);
        sktOutline = new SketchOutline(this.getParentSketch());
        sktOutline.getPath().add(new SketchPoint(coords[0], coords[1]));
        //System.out.println("newSketch");

        break;

      case PathIterator.SEG_LINETO: // 1 point
        //  System.out.println( "SEG_LINETO " + coords[0]+" "+coords[1]);
        sktOutline.getPath().add(new SketchPoint(coords[0], coords[1]));
        break;

      case PathIterator.SEG_QUADTO: // 2 points
        //System.out.println("QUAD");
        break;

      case PathIterator.SEG_CUBICTO: // 3 points

        prevVec = sktOutline.getPath().getLast();
        SketchPoint newVec = new SketchPoint(coords[4], coords[5]);

        //SketchPoint preVecBez1 =  (SketchPoint) sktOutline.path.get(sktOutline.path.size()-2);
        //SketchPoint preVecBez2 =  (SketchPoint) sktOutline.path.get(sktOutline.path.size()-1);

        Vec2D controlNodeBack = new Vec2D(coords[0], coords[1]);
        Vec2D controlNodeFoward = new Vec2D(coords[2], coords[3]);

        //System.out.println("new back:"+newVec+":" + controlNodeBack + " : foward" + prevVec+":" + controlNodeFoward);

        newVec.controlPoint1 = controlNodeFoward;

        if (prevVec != null) {
          prevVec.controlPoint2 = controlNodeBack;
          sktOutline.getPath().set(sktOutline.getPath().size() - 1,
              prevVec);
        }
        sktOutline.getPath().add(newVec);
        //#IF JAVA
        /*
        if(preVecBez1.containsBezier()){
          preVecBez1.controlPoint2 = new Vec2D(controlNodeBack.x,controlNodeBack.y);
        }else{
         bezier = new  BezierControlNode(new Vec2D(preVecBez1.x,preVecBez1.y),controlNodeBack);
           // sktOutline.path.addBezier(preVecBez1, bezier);
        }
       
       
        if(preVecBez2.containsBezier()){
          preVecBez2.controlPoint1 = new Vec2D(controlNodeFoward.x,controlNodeFoward.y);
        }else{
         bezier = new  BezierControlNode(new Vec2D(controlNodeFoward.x,controlNodeFoward.y),controlNodeFoward);
        // sktOutline.path.addBezier(preVecBez2, bezier);
        }
       
       
       
        if(preVecBez2.containsBezier()){
        //    BezierControlNode prevControleNode = (BezierControlNode) sktOutline.path.bezierPoints.get(preVecBez2);
        //    prevControleNode.c2.x = controlNodeFoward.x;
        //   prevControleNode.c2.x = controlNodeFoward.y;
        }else{
        //  BezierControlNode bezierPrev = new  BezierControlNode(new Vec2D(preVecBez2.x,preVecBez2.y),controlNodeFoward);
        //sktOutline.path.addBezier(preVecBez2, bezierPrev);
       
        }
        */
        //#ENDIF JAVA

        break;

      case PathIterator.SEG_CLOSE:
        //     System.out.println("CLOSE");

        break;
      }
      iter.next();
    }

    this.sketchOutlines.add(sktOutline);
    //this.sketchOutlines.optimize();

View Full Code Here

        if (!nativePen) {
            super.draw(s);
            return;
        }

        PathIterator pi = s.getPathIterator(transform, 0.5);
        int len = getPathArray(pi);
        drawShape(gi, pathArray, len, pi.getWindingRule());
    }
View Full Code Here

        if (!nativeBrush) {
            super.fill(s);
            return;
        }

        PathIterator pi = s.getPathIterator(transform, 0.5);
        int len = getPathArray(pi);
        fillShape(gi, pathArray, len, pi.getWindingRule());
    }
View Full Code Here

  }

  private String shapeCoordinates(Shape shape)
  {
    final StringBuilder sb = new StringBuilder();
    final PathIterator pi = shape.getPathIterator(null, 1.0);
    final float[] coords = new float[6];
    final float[] lastMove = new float[2];
    while (!pi.isDone())
    {
      switch (pi.currentSegment(coords))
      {
        case PathIterator.SEG_MOVETO :
          if (sb.length() != 0)
          {
            sb.append(',');
          }
          sb.append(Math.round(coords[0]));
          sb.append(',');
          sb.append(Math.round(coords[1]));
          lastMove[0] = coords[0];
          lastMove[1] = coords[1];
          break;
        case PathIterator.SEG_LINETO :
          if (sb.length() != 0)
          {
            sb.append(',');
          }
          sb.append(Math.round(coords[0]));
          sb.append(',');
          sb.append(Math.round(coords[1]));
          break;
        case PathIterator.SEG_CLOSE :
          if (sb.length() != 0)
          {
            sb.append(',');
          }
          sb.append(Math.round(lastMove[0]));
          sb.append(',');
          sb.append(Math.round(lastMove[1]));
          break;
      }
      pi.next();
    }
    return sb.toString();
  }
View Full Code Here

            mismatch = Base64Test.compareStreams (is1, is2, false);
        }
    }

    public static void printShape(Shape s, PrintStream ps) {
        PathIterator pi = s.getPathIterator(null);
        float pts [] = new float[6];
        int type;
        while (!pi.isDone()) {
            type = pi.currentSegment(pts);
            switch (type) {
            case PathIterator.SEG_MOVETO:
                ps.println(" MoveTo: [" +
                                   pts[0] + ", " + pts[1] + "]");
                break;
            case PathIterator.SEG_LINETO:
                ps.println(" LineTo: [" +
                                   pts[0] + ", " + pts[1] + "]");
                break;

            case PathIterator.SEG_QUADTO:
                ps.println(" QuadTo: [" +
                                   pts[0] + ", " + pts[1] + "] [" +
                                   pts[2] + ", " + pts[3] + "]");
                break;

            case PathIterator.SEG_CUBICTO:
                ps.println("CurveTo: [" +
                                   pts[0] + ", " + pts[1] + "] [" +
                                   pts[2] + ", " + pts[3] + "] [" +
                                   pts[4] + ", " + pts[5] + "]");
                break;

            case PathIterator.SEG_CLOSE:
                ps.println("Close");
                break;
            }
            pi.next();
        }
    }
View Full Code Here

TOP

Related Classes of java.awt.geom.PathIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.