Beispiel #1
0
 public void end_poly(ShapePath.FlagsAndCommand flags)
 {
     if (ShapePath.is_vertex(vertices.last_command()))
     {
         vertices.AddVertex(0.0, 0.0, ShapePath.FlagsAndCommand.CommandEndPoly | flags);
     }
 }
 public static void Save(IVertexSource vertexSource, string pathAndFileName, bool oldStyle = true)
 {
     if (oldStyle)
     {
         using (StreamWriter outFile = new StreamWriter(pathAndFileName))
         {
             vertexSource.rewind(0);
             double x;
             double y;
             ShapePath.FlagsAndCommand flagsAndCommand = vertexSource.vertex(out x, out y);
             do
             {
                 outFile.WriteLine("{0}, {1}, {2}", x, y, flagsAndCommand.ToString());
                 flagsAndCommand = vertexSource.vertex(out x, out y);
             }while (flagsAndCommand != ShapePath.FlagsAndCommand.Stop);
         }
     }
     else
     {
         using (StreamWriter outFile = new StreamWriter(pathAndFileName))
         {
             foreach (VertexData vertexData in vertexSource.Vertices())
             {
                 outFile.WriteLine("{0}, {1}, {2}", vertexData.position.X, vertexData.position.Y, vertexData.command.ToString());
             }
         }
     }
 }
Beispiel #3
0
        public override ShapePath.FlagsAndCommand vertex(out double x, out double y)
        {
            x = 0;
            y = 0;
            ShapePath.FlagsAndCommand cmd = ShapePath.FlagsAndCommand.CommandStop;
            switch (m_idx)
            {
            case 0:
            case 1:
            case 2:
                cmd = m_stroke.vertex(out x, out y);
                break;

            case 3:
            case 4:
            case 5:
            case 6:
                cmd = m_ellipse.vertex(out x, out y);
                break;
            }

            if (!ShapePath.is_stop(cmd))
            {
                ParentToChildTransform.transform(ref x, ref y);
            }
            return(cmd);
        }
 public void AddVertex(double x, double y, ShapePath.FlagsAndCommand cmd)
 {
     m_status = StrokeMath.status_e.initial;
     if (ShapePath.is_move_to(cmd))
     {
         m_src_vertices.modify_last(new VertexDistance(x, y));
     }
     else
     {
         if (ShapePath.is_vertex(cmd))
         {
             m_src_vertices.add(new VertexDistance(x, y));
         }
         else
         {
             if (ShapePath.is_end_poly(cmd))
             {
                 m_closed = (ShapePath.get_close_flag(cmd) == ShapePath.FlagsAndCommand.FlagClose);
                 if (m_orientation == ShapePath.FlagsAndCommand.FlagNone)
                 {
                     m_orientation = ShapePath.get_orientation(cmd);
                 }
             }
         }
     }
 }
Beispiel #5
0
        static public bool OldEqualsNewStyle(IVertexSource control, IVertexSource test, double maxError = .0001)
        {
            control.rewind(0);
            double controlX;
            double controlY;

            ShapePath.FlagsAndCommand controlFlagsAndCommand = control.vertex(out controlX, out controlY);

            int index = 0;

            foreach (VertexData vertexData in test.Vertices())
            {
                if (controlFlagsAndCommand != vertexData.command ||
                    controlX < vertexData.position.x - maxError || controlX > vertexData.position.x + maxError ||
                    controlY < vertexData.position.y - maxError || controlY > vertexData.position.y + maxError)
                {
                    return(false);
                }
                controlFlagsAndCommand = control.vertex(out controlX, out controlY);
                index++;
            }

            if (controlFlagsAndCommand == ShapePath.FlagsAndCommand.CommandStop)
            {
                return(true);
            }

            return(false);
        }
Beispiel #6
0
            private void allocate_if_required(int indexToAdd)
            {
                if (indexToAdd < m_num_vertices)
                {
                    return;
                }

                while (indexToAdd >= m_allocated_vertices)
                {
                    int      newSize = m_allocated_vertices + 256;
                    double[] newX    = new double[newSize];
                    double[] newY    = new double[newSize];
                    ShapePath.FlagsAndCommand[] newCmd = new ShapePath.FlagsAndCommand[newSize];

                    if (m_coord_x != null)
                    {
                        for (int i = 0; i < m_num_vertices; i++)
                        {
                            newX[i]   = m_coord_x[i];
                            newY[i]   = m_coord_y[i];
                            newCmd[i] = m_CommandAndFlags[i];
                        }
                    }

                    m_coord_x         = newX;
                    m_coord_y         = newY;
                    m_CommandAndFlags = newCmd;

                    m_allocated_vertices = newSize;
                }
            }
 public void end_poly(ShapePath.FlagsAndCommand flags)
 {
     if (ShapePath.is_vertex(vertexDataManager.last_command()))
     {
         vertexDataManager.AddVertex(0.0, 0.0, ShapePath.FlagsAndCommand.EndPoly | flags);
     }
 }
            public void AddVertex(double x, double y, ShapePath.FlagsAndCommand CommandAndFlags, int index = -1)
            {
                index = index == -1 ? numVertices : index;
                allocate_if_required(numVertices);
                vertexData[index] = new VertexData(CommandAndFlags, x, y);

                numVertices++;
            }
Beispiel #9
0
 public ShapePath.FlagsAndCommand vertex(out double x, out double y)
 {
     ShapePath.FlagsAndCommand cmd = VertexSource.vertex(out x, out y);
     if (ShapePath.is_vertex(cmd))
     {
         ApplayYWarp(ref x, ref y);
     }
     return(cmd);
 }
Beispiel #10
0
 public ShapePath.FlagsAndCommand vertex(out double x, out double y)
 {
     ShapePath.FlagsAndCommand cmd = VertexSource.vertex(out x, out y);
     if (ShapePath.is_vertex(cmd))
     {
         transformToApply.transform(ref x, ref y);
     }
     return(cmd);
 }
Beispiel #11
0
            public void AddVertex(double x, double y, ShapePath.FlagsAndCommand CommandAndFlags)
            {
                allocate_if_required(m_num_vertices);
                m_coord_x[m_num_vertices]         = x;
                m_coord_y[m_num_vertices]         = y;
                m_CommandAndFlags[m_num_vertices] = CommandAndFlags;

                m_num_vertices++;
            }
Beispiel #12
0
        public override ShapePath.FlagsAndCommand vertex(out double x, out double y)
        {
            x = 0;
            y = 0;
            ShapePath.FlagsAndCommand cmd = ShapePath.FlagsAndCommand.LineTo;
            switch (m_idx)
            {
            case 0:
                if (m_vertex == 0)
                {
                    cmd = ShapePath.FlagsAndCommand.MoveTo;
                }
                if (m_vertex >= 4)
                {
                    cmd = ShapePath.FlagsAndCommand.Stop;
                }
                x = m_vx[m_vertex];
                y = m_vy[m_vertex];
                m_vertex++;
                break;

            case 1:
                if (m_vertex == 0 || m_vertex == 4)
                {
                    cmd = ShapePath.FlagsAndCommand.MoveTo;
                }
                if (m_vertex >= 8)
                {
                    cmd = ShapePath.FlagsAndCommand.Stop;
                }
                x = m_vx[m_vertex];
                y = m_vy[m_vertex];
                m_vertex++;
                break;

            case 2:
                cmd = m_curve_poly.vertex(out x, out y);
                break;

            case 3:
            case 4:
                cmd = m_curve_pnt.vertex(out x, out y);
                break;

            default:
                cmd = ShapePath.FlagsAndCommand.Stop;
                break;
            }

            if (!ShapePath.is_stop(cmd))
            {
                //OriginRelativeParentTransform.transform(ref x, ref y);
            }

            return(cmd);
        }
Beispiel #13
0
        public ShapePath.FlagsAndCommand vertex(out double x, out double y)
        {
            x = currentEnumerator.Current.position.x;
            y = currentEnumerator.Current.position.y;
            ShapePath.FlagsAndCommand command = currentEnumerator.Current.command;

            currentEnumerator.MoveNext();

            return(command);
        }
Beispiel #14
0
            public void swap_vertices(int v1, int v2)
            {
                double val;

                val = m_coord_x[v1]; m_coord_x[v1] = m_coord_x[v2]; m_coord_x[v2] = val;
                val = m_coord_y[v1]; m_coord_y[v1] = m_coord_y[v2]; m_coord_y[v2] = val;
                ShapePath.FlagsAndCommand cmd = m_CommandAndFlags[v1];
                m_CommandAndFlags[v1] = m_CommandAndFlags[v2];
                m_CommandAndFlags[v2] = cmd;
            }
Beispiel #15
0
 public void flip_y(double y1, double y2)
 {
     for (int i = 0; i < vertexDataManager.total_vertices(); i++)
     {
         ShapePath.FlagsAndCommand PathAndFlags = vertexDataManager.vertex(i, out double x, out double y);
         if (ShapePath.is_vertex(PathAndFlags))
         {
             vertexDataManager.modify_vertex(i, x, y2 - y + y1);
         }
     }
 }
Beispiel #16
0
 public void arrange_orientations_all_paths(ShapePath.FlagsAndCommand orientation)
 {
     if (orientation != ShapePath.FlagsAndCommand.FlagNone)
     {
         int start = 0;
         while (start < vertices.total_vertices())
         {
             start = arrange_orientations(start, orientation);
         }
     }
 }
 public ContourGenerator()
 {
     m_stroker      = new StrokeMath();
     m_width        = 1;
     m_src_vertices = new VertexSequence();
     m_out_vertices = new Vector2Container();
     m_status       = StrokeMath.status_e.initial;
     m_src_vertex   = 0;
     m_closed       = false;
     m_orientation  = 0;
     m_auto_detect  = false;
 }
		public ContourGenerator()
		{
			m_stroker = new StrokeMath();
			m_width = 1;
			m_src_vertices = new VertexSequence();
			m_out_vertices = new Vector2Container();
			m_status = StrokeMath.status_e.initial;
			m_src_vertex = 0;
			m_closed = false;
			m_orientation = 0;
			m_auto_detect = false;
		}
 public IEnumerable <VertexData> Vertices()
 {
     rewind(0);
     ShapePath.FlagsAndCommand command = ShapePath.FlagsAndCommand.CommandStop;
     do
     {
         double x;
         double y;
         command = vertex(out x, out y);
         yield return(new VertexData(command, new Vector2(x, y)));
     } while (command != ShapePath.FlagsAndCommand.CommandStop);
 }
Beispiel #20
0
        public void flip_y(double y1, double y2)
        {
            int    i;
            double x, y;

            for (i = 0; i < vertices.total_vertices(); i++)
            {
                ShapePath.FlagsAndCommand PathAndFlags = vertices.vertex(i, out x, out y);
                if (ShapePath.is_vertex(PathAndFlags))
                {
                    vertices.modify_vertex(i, x, y2 - y + y1);
                }
            }
        }
Beispiel #21
0
        // Flip all vertices horizontally or vertically,
        // between x1 and x2, or between y1 and y2 respectively
        //--------------------------------------------------------------------
        public void flip_x(double x1, double x2)
        {
            int    i;
            double x, y;

            for (i = 0; i < vertexDataManager.total_vertices(); i++)
            {
                ShapePath.FlagsAndCommand PathAndFlags = vertexDataManager.vertex(i, out x, out y);
                if (ShapePath.is_vertex(PathAndFlags))
                {
                    vertexDataManager.modify_vertex(i, x2 - x + x1, y);
                }
            }
        }
Beispiel #22
0
        public ShapePath.FlagsAndCommand vertex(out double x, out double y)
        {
            if (currentEnumerator == null)
            {
                rewind(0);
            }
            x = currentEnumerator.Current.position.X;
            y = currentEnumerator.Current.position.Y;
            ShapePath.FlagsAndCommand command = currentEnumerator.Current.command;

            currentEnumerator.MoveNext();

            return(command);
        }
Beispiel #23
0
        /*
         * public void arc_to(double rx, double ry,
         *                                                 double angle,
         *                                                 bool large_arc_flag,
         *                                                 bool sweep_flag,
         *                                                 double x, double y)
         * {
         *      if(m_vertices.total_vertices() && is_vertex(m_vertices.last_command()))
         *      {
         *              double epsilon = 1e-30;
         *              double x0 = 0.0;
         *              double y0 = 0.0;
         *              m_vertices.last_vertex(&x0, &y0);
         *
         *              rx = fabs(rx);
         *              ry = fabs(ry);
         *
         *              // Ensure radii are valid
         *              //-------------------------
         *              if(rx < epsilon || ry < epsilon)
         *              {
         *                      line_to(x, y);
         *                      return;
         *              }
         *
         *              if(calc_distance(x0, y0, x, y) < epsilon)
         *              {
         *                      // If the endpoints (x, y) and (x0, y0) are identical, then this
         *                      // is equivalent to omitting the elliptical arc segment entirely.
         *                      return;
         *              }
         *              bezier_arc_svg a(x0, y0, rx, ry, angle, large_arc_flag, sweep_flag, x, y);
         *              if(a.radii_ok())
         *              {
         *                      join_path(a);
         *              }
         *              else
         *              {
         *                      line_to(x, y);
         *              }
         *      }
         *      else
         *      {
         *              move_to(x, y);
         *      }
         * }
         *
         * public void arc_rel(double rx, double ry,
         *                                                      double angle,
         *                                                      bool large_arc_flag,
         *                                                      bool sweep_flag,
         *                                                      double dx, double dy)
         * {
         *      rel_to_abs(&dx, &dy);
         *      arc_to(rx, ry, angle, large_arc_flag, sweep_flag, dx, dy);
         * }
         */
        public IEnumerable <VertexData> Vertices()
        {
            int count = vertices.total_vertices();

            for (int i = 0; i < count; i++)
            {
                double x = 0;
                double y = 0;
                ShapePath.FlagsAndCommand command = vertices.vertex(i, out x, out y);
                yield return(new VertexData(command, new Vector2(x, y)));
            }

            yield return(new VertexData(ShapePath.FlagsAndCommand.CommandStop, new Vector2(0, 0)));
        }
Beispiel #24
0
        public ShapePath.FlagsAndCommand vertex(out double x, out double y)
        {
            if (!ShapePath.is_stop(m_curve3.vertex(out x, out y)))
            {
                lastX = x;
                lastY = y;
                return(ShapePath.FlagsAndCommand.CommandLineTo);
            }

            if (!ShapePath.is_stop(m_curve4.vertex(out x, out y)))
            {
                lastX = x;
                lastY = y;
                return(ShapePath.FlagsAndCommand.CommandLineTo);
            }

            double ct2_x;
            double ct2_y;
            double end_x;
            double end_y;

            ShapePath.FlagsAndCommand cmd = VertexSource.vertex(out x, out y);
            switch (cmd)
            {
            case ShapePath.FlagsAndCommand.CommandCurve3:
                VertexSource.vertex(out end_x, out end_y);

                m_curve3.init(lastX, lastY, x, y, end_x, end_y);

                m_curve3.vertex(out x, out y);                            // First call returns path_cmd_move_to
                m_curve3.vertex(out x, out y);                            // This is the first vertex of the curve
                cmd = ShapePath.FlagsAndCommand.CommandLineTo;
                break;

            case ShapePath.FlagsAndCommand.CommandCurve4:
                VertexSource.vertex(out ct2_x, out ct2_y);
                VertexSource.vertex(out end_x, out end_y);

                m_curve4.init(lastX, lastY, x, y, ct2_x, ct2_y, end_x, end_y);

                m_curve4.vertex(out x, out y);                            // First call returns path_cmd_move_to
                m_curve4.vertex(out x, out y);                            // This is the first vertex of the curve
                cmd = ShapePath.FlagsAndCommand.CommandLineTo;
                break;
            }
            lastX = x;
            lastY = y;
            return(cmd);
        }
Beispiel #25
0
 public int arrange_orientations(int start, ShapePath.FlagsAndCommand orientation)
 {
     if (orientation != ShapePath.FlagsAndCommand.FlagNone)
     {
         while (start < vertices.total_vertices())
         {
             start = arrange_polygon_orientation(start, orientation);
             if (ShapePath.is_stop(vertices.command(start)))
             {
                 ++start;
                 break;
             }
         }
     }
     return(start);
 }
Beispiel #26
0
        public void join_path(PathStorage vs, int path_id)
        {
            double x, y;

            vs.rewind(path_id);
            ShapePath.FlagsAndCommand PathAndFlags = vs.vertex(out x, out y);
            if (!ShapePath.is_stop(PathAndFlags))
            {
                if (ShapePath.is_vertex(PathAndFlags))
                {
                    double x0, y0;
                    ShapePath.FlagsAndCommand PathAndFlags0 = last_vertex(out x0, out y0);
                    if (ShapePath.is_vertex(PathAndFlags0))
                    {
                        if (agg_math.calc_distance(x, y, x0, y0) > agg_math.vertex_dist_epsilon)
                        {
                            if (ShapePath.is_move_to(PathAndFlags))
                            {
                                PathAndFlags = ShapePath.FlagsAndCommand.CommandLineTo;
                            }
                            vertices.AddVertex(x, y, PathAndFlags);
                        }
                    }
                    else
                    {
                        if (ShapePath.is_stop(PathAndFlags0))
                        {
                            PathAndFlags = ShapePath.FlagsAndCommand.CommandMoveTo;
                        }
                        else
                        {
                            if (ShapePath.is_move_to(PathAndFlags))
                            {
                                PathAndFlags = ShapePath.FlagsAndCommand.CommandLineTo;
                            }
                        }
                        vertices.AddVertex(x, y, PathAndFlags);
                    }
                }
                while (!ShapePath.is_stop(PathAndFlags = vs.vertex(out x, out y)))
                {
                    vertices.AddVertex(x, y, ShapePath.is_move_to(PathAndFlags) ?
                                       ShapePath.FlagsAndCommand.CommandLineTo :
                                       PathAndFlags);
                }
            }
        }
Beispiel #27
0
        // Arrange the orientation of a polygon, all polygons in a path,
        // or in all paths. After calling arrange_orientations() or
        // arrange_orientations_all_paths(), all the polygons will have
        // the same orientation, i.e. path_flags_cw or path_flags_ccw
        //--------------------------------------------------------------------
        public int arrange_polygon_orientation(int start, ShapePath.FlagsAndCommand orientation)
        {
            if (orientation == ShapePath.FlagsAndCommand.FlagNone)
            {
                return(start);
            }

            // Skip all non-vertices at the beginning
            while (start < vertices.total_vertices() &&
                   !ShapePath.is_vertex(vertices.command(start)))
            {
                ++start;
            }

            // Skip all insignificant move_to
            while (start + 1 < vertices.total_vertices() &&
                   ShapePath.is_move_to(vertices.command(start)) &&
                   ShapePath.is_move_to(vertices.command(start + 1)))
            {
                ++start;
            }

            // Find the last vertex
            int end = start + 1;

            while (end < vertices.total_vertices() &&
                   !ShapePath.is_next_poly(vertices.command(end)))
            {
                ++end;
            }

            if (end - start > 2)
            {
                if (perceive_polygon_orientation(start, end) != orientation)
                {
                    // Invert polygon, set orientation flag, and skip all end_poly
                    invert_polygon(start, end);
                    ShapePath.FlagsAndCommand PathAndFlags;
                    while (end < vertices.total_vertices() &&
                           ShapePath.is_end_poly(PathAndFlags = vertices.command(end)))
                    {
                        vertices.modify_command(end++, PathAndFlags | orientation);                        // Path.set_orientation(cmd, orientation));
                    }
                }
            }
            return(end);
        }
 void add_vertex(double x, double y, ShapePath.FlagsAndCommand cmd)
 {
     if (ShapePath.is_move_to(cmd))
     {
         move_to_d(x, y);
     }
     else
     if (ShapePath.is_vertex(cmd))
     {
         line_to_d(x, y);
     }
     else
     if (ShapePath.is_close(cmd))
     {
         m_VectorClipper.line_to(m_Rasterizer, m_start_x, m_start_y);
     }
 }
        public ImageBuffer GetImageForCharacter(char character, double xFraction, double yFraction, RGBA_Bytes color)
        {
            if (xFraction > 1 || xFraction < 0 || yFraction > 1 || yFraction < 0)
            {
                throw new ArgumentException("The x and y fractions must both be between 0 and 1.");
            }

            ImageBuffer imageForCharacter;
            Dictionary <char, ImageBuffer> characterImageCache = StyledTypeFaceImageCache.GetCorrectCache(this.TypeFace, color, this.emSizeInPixels);

            characterImageCache.TryGetValue(character, out imageForCharacter);
            if (imageForCharacter != null)
            {
                return(imageForCharacter);
            }

            IVertexSource glyphForCharacter = GetGlyphForCharacter(character);

            if (glyphForCharacter == null)
            {
                return(null);
            }

            glyphForCharacter.rewind(0);
            double x, y;

            ShapePath.FlagsAndCommand curCommand = glyphForCharacter.vertex(out x, out y);
            RectangleDouble           bounds     = new RectangleDouble(x, y, x, y);

            while (curCommand != ShapePath.FlagsAndCommand.CommandStop)
            {
                bounds.ExpandToInclude(x, y);
                curCommand = glyphForCharacter.vertex(out x, out y);
            }

            int         descentExtraHeight = (int)(-DescentInPixels + .5);
            ImageBuffer charImage          = new ImageBuffer(Math.Max((int)(bounds.Width + .5), 1) + 1, Math.Max((int)(EmSizeInPixels + descentExtraHeight + .5), 1) + 1, 32, new BlenderPreMultBGRA());

            charImage.OriginOffset = new VectorMath.Vector2(0, descentExtraHeight);
            Graphics2D graphics = charImage.NewGraphics2D();

            graphics.Render(glyphForCharacter, xFraction, yFraction + descentExtraHeight, color);
            characterImageCache[character] = charImage;

            return(charImage);
        }
Beispiel #30
0
        public override ShapePath.FlagsAndCommand vertex(out double x, out double y)
        {
            x = 0;
            y = 0;
            ShapePath.FlagsAndCommand cmd = ShapePath.FlagsAndCommand.CommandLineTo;
            switch (m_idx)
            {
            case 0:
                cmd = m_curve_poly.vertex(out x, out y);
                break;

            case 1:
                if (m_vertex == 0 ||
                    m_vertex == 4 ||
                    m_vertex == 8 ||
                    m_vertex == 14)
                {
                    cmd = ShapePath.FlagsAndCommand.CommandMoveTo;
                }

                if (m_vertex >= 20)
                {
                    cmd = ShapePath.FlagsAndCommand.CommandStop;
                }
                x = gridVertexX[m_vertex];
                y = gridVertexY[m_vertex];
                m_vertex++;
                break;

            case 2:                     // Point1
            case 3:                     // Point2
                cmd = m_ellipse.vertex(out x, out y);
                break;

            case 4:
                cmd = m_text_poly.vertex(out x, out y);
                break;

            default:
                cmd = ShapePath.FlagsAndCommand.CommandStop;
                break;
            }

            return(cmd);
        }
Beispiel #31
0
        public static void SendShapeToTesselator(VertexTesselatorAbstract tesselator, IVertexSource vertexSource)
        {
#if !DEBUG
            try
#endif
            {
                tesselator.BeginPolygon();

                ShapePath.FlagsAndCommand PathAndFlags = 0;
                double x, y;
                bool   haveBegunContour = false;
                while (!ShapePath.is_stop(PathAndFlags = vertexSource.vertex(out x, out y)))
                {
                    if (ShapePath.is_close(PathAndFlags) ||
                        (haveBegunContour && ShapePath.is_move_to(PathAndFlags)))
                    {
                        tesselator.EndContour();
                        haveBegunContour = false;
                    }

                    if (!ShapePath.is_close(PathAndFlags))
                    {
                        if (!haveBegunContour)
                        {
                            tesselator.BeginContour();
                            haveBegunContour = true;
                        }

                        tesselator.AddVertex(x, y);
                    }
                }

                if (haveBegunContour)
                {
                    tesselator.EndContour();
                }

                tesselator.EndPolygon();
            }
#if !DEBUG
            catch
            {
            }
#endif
        }
Beispiel #32
0
            private void allocate_if_required(int indexToAdd)
            {
                if (indexToAdd < m_num_vertices)
                {
                    return;
                }

                while (indexToAdd >= m_allocated_vertices)
                {
                    int newSize = m_allocated_vertices + 256;
                    double[] newX = new double[newSize];
                    double[] newY = new double[newSize];
                    ShapePath.FlagsAndCommand[] newCmd = new ShapePath.FlagsAndCommand[newSize];

                    if (m_coord_x != null)
                    {
                        for (int i = 0; i < m_num_vertices; i++)
                        {
                            newX[i] = m_coord_x[i];
                            newY[i] = m_coord_y[i];
                            newCmd[i] = m_CommandAndFlags[i];
                        }
                    }

                    m_coord_x = newX;
                    m_coord_y = newY;
                    m_CommandAndFlags = newCmd;

                    m_allocated_vertices = newSize;
                }
            }
Beispiel #33
0
        public ShapePath.FlagsAndCommand vertex(out double x, out double y)
        {
            x = 0;
            y = 0;
            ShapePath.FlagsAndCommand command = ShapePath.FlagsAndCommand.CommandStop;
            bool done = false;
            while (!done)
            {
                switch (m_status)
                {
                    case status.initial:
                        markers.remove_all();
                        m_last_cmd = VertexSource.vertex(out m_start_x, out m_start_y);
                        m_status = status.accumulate;
                        goto case status.accumulate;

                    case status.accumulate:
                        if (ShapePath.is_stop(m_last_cmd))
                        {
                            return ShapePath.FlagsAndCommand.CommandStop;
                        }

                        generator.RemoveAll();
                        generator.AddVertex(m_start_x, m_start_y, ShapePath.FlagsAndCommand.CommandMoveTo);
                        markers.add_vertex(m_start_x, m_start_y, ShapePath.FlagsAndCommand.CommandMoveTo);

                        for (; ; )
                        {
                            command = VertexSource.vertex(out x, out y);
                            //DebugFile.Print("x=" + x.ToString() + " y=" + y.ToString() + "\n");
                            if (ShapePath.is_vertex(command))
                            {
                                m_last_cmd = command;
                                if (ShapePath.is_move_to(command))
                                {
                                    m_start_x = x;
                                    m_start_y = y;
                                    break;
                                }
                                generator.AddVertex(x, y, command);
                                markers.add_vertex(x, y, ShapePath.FlagsAndCommand.CommandLineTo);
                            }
                            else
                            {
                                if (ShapePath.is_stop(command))
                                {
                                    m_last_cmd = ShapePath.FlagsAndCommand.CommandStop;
                                    break;
                                }
                                if (ShapePath.is_end_poly(command))
                                {
                                    generator.AddVertex(x, y, command);
                                    break;
                                }
                            }
                        }
                        generator.Rewind(0);
                        m_status = status.generate;
                        goto case status.generate;

                    case status.generate:
                        command = generator.Vertex(ref x, ref y);
                        //DebugFile.Print("x=" + x.ToString() + " y=" + y.ToString() + "\n");
                        if (ShapePath.is_stop(command))
                        {
                            m_status = status.accumulate;
                            break;
                        }
                        done = true;
                        break;
                }
            }
            return command;
        }
		public void AddVertex(double x, double y, ShapePath.FlagsAndCommand cmd)
		{
			m_status = StrokeMath.status_e.initial;
			if (ShapePath.is_move_to(cmd))
			{
				m_src_vertices.modify_last(new VertexDistance(x, y));
			}
			else
			{
				if (ShapePath.is_vertex(cmd))
				{
					m_src_vertices.add(new VertexDistance(x, y));
				}
				else
				{
					if (ShapePath.is_end_poly(cmd))
					{
						m_closed = (ShapePath.get_close_flag(cmd) == ShapePath.FlagsAndCommand.FlagClose);
						if (m_orientation == ShapePath.FlagsAndCommand.FlagNone)
						{
							m_orientation = ShapePath.get_orientation(cmd);
						}
					}
				}
			}
		}
		// Vertex Source Interface
		public void Rewind(int idx)
		{
			if (m_status == StrokeMath.status_e.initial)
			{
				m_src_vertices.close(true);
				if (m_auto_detect)
				{
					if (!ShapePath.is_oriented(m_orientation))
					{
						m_orientation = (agg_math.calc_polygon_area(m_src_vertices) > 0.0) ?
										ShapePath.FlagsAndCommand.FlagCCW :
										ShapePath.FlagsAndCommand.FlagCW;
					}
				}
				if (ShapePath.is_oriented(m_orientation))
				{
					m_stroker.width(ShapePath.is_ccw(m_orientation) ? m_width : -m_width);
				}
			}
			m_status = StrokeMath.status_e.ready;
			m_src_vertex = 0;
		}