Ejemplo n.º 1
0
        bool GetSegment(SVGPathElement svgElement, SVGPathSeg segment, List <List <Vector2> > output, List <Vector2> positionBuffer, SVGMatrix matrix)
        {
            if (segment == null)
            {
                return(false);
            }

//            Debug.Log("command: "+segment.type+", lastCommand: "+lastCommand);

            switch (segment.type)
            {
            case SVGPathSegTypes.Arc_Abs:
                SVGPathSegArcAbs arcAbs = segment as SVGPathSegArcAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("arcAbs");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.Arc(SVGGeomUtils.TransformPoint(arcAbs.previousPoint, matrix), arcAbs.r1, arcAbs.r2, arcAbs.angle, arcAbs.largeArcFlag, arcAbs.sweepFlag, SVGGeomUtils.TransformPoint(arcAbs.currentPoint, matrix)));
                break;

            case SVGPathSegTypes.Arc_Rel:
                SVGPathSegArcRel arcRel = segment as SVGPathSegArcRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("arcRel");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.Arc(SVGGeomUtils.TransformPoint(arcRel.previousPoint, matrix), arcRel.r1, arcRel.r2, arcRel.angle, arcRel.largeArcFlag, arcRel.sweepFlag, SVGGeomUtils.TransformPoint(arcRel.currentPoint, matrix)));
                break;

            case SVGPathSegTypes.Close:
                    #if PATH_COMMAND_DEBUG
                Debug.Log("Close");
                    #endif
                //Debug.Log("Close");
                if (positionBuffer.Count > 0)
                {
                    output.Add(new List <Vector2>(positionBuffer.ToArray()));
                }
                positionBuffer.Clear();
                break;

            case SVGPathSegTypes.CurveTo_Cubic_Abs:
                SVGPathSegCurvetoCubicAbs curvetoCubicAbs = segment as SVGPathSegCurvetoCubicAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoCubicAbs");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicAbs.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicAbs.currentPoint, matrix)));
                break;

            case SVGPathSegTypes.CurveTo_Cubic_Rel:
                SVGPathSegCurvetoCubicRel curvetoCubicRel = segment as SVGPathSegCurvetoCubicRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoCubicRel");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicRel.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicRel.currentPoint, matrix)));
                break;

            case SVGPathSegTypes.CurveTo_Cubic_Smooth_Abs:
                SVGPathSegCurvetoCubicSmoothAbs curvetoCubicSmoothAbs = segment as SVGPathSegCurvetoCubicSmoothAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoCubicSmoothAbs");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.currentPoint, matrix)));
                break;

            case SVGPathSegTypes.CurveTo_Cubic_Smooth_Rel:
                SVGPathSegCurvetoCubicSmoothRel curvetoCubicSmoothRel = segment as SVGPathSegCurvetoCubicSmoothRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoCubicSmoothRel");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.currentPoint, matrix)));

                break;

            case SVGPathSegTypes.CurveTo_Quadratic_Abs:
                SVGPathSegCurvetoQuadraticAbs curvetoQuadraticAbs = segment as SVGPathSegCurvetoQuadraticAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoQuadraticAbs");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticAbs.currentPoint, matrix)));
                break;

            case SVGPathSegTypes.CurveTo_Quadratic_Rel:
                SVGPathSegCurvetoQuadraticRel curvetoQuadraticRel = segment as SVGPathSegCurvetoQuadraticRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoQuadraticRel");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticRel.currentPoint, matrix)));

                break;

            case SVGPathSegTypes.CurveTo_Quadratic_Smooth_Abs:
                SVGPathSegCurvetoQuadraticSmoothAbs curvetoQuadraticSmoothAbs = segment as SVGPathSegCurvetoQuadraticSmoothAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoQuadraticSmoothAbs");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothAbs.currentPoint, matrix)));

                break;

            case SVGPathSegTypes.CurveTo_Quadratic_Smooth_Rel:
                SVGPathSegCurvetoQuadraticSmoothRel curvetoQuadraticSmoothRel = segment as SVGPathSegCurvetoQuadraticSmoothRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("curvetoQuadraticSmoothRel");
                    #endif
                positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothRel.currentPoint, matrix)));

                break;

            case SVGPathSegTypes.LineTo_Abs:
                SVGPathSegLinetoAbs linetoAbs = segment as SVGPathSegLinetoAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("linetoAbs");
                    #endif
                positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoAbs.currentPoint, matrix));
                break;

            case SVGPathSegTypes.LineTo_Horizontal_Abs:
                    #if PATH_COMMAND_DEBUG
                Debug.Log("linetoHorizontalAbs");
                    #endif
                SVGPathSegLinetoHorizontalAbs linetoHorizontalAbs = segment as SVGPathSegLinetoHorizontalAbs;
                positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoHorizontalAbs.currentPoint, matrix));
                break;

            case SVGPathSegTypes.LineTo_Horizontal_Rel:
                    #if PATH_COMMAND_DEBUG
                Debug.Log("linetoHorizontalRel");
                    #endif
                SVGPathSegLinetoHorizontalRel linetoHorizontalRel = segment as SVGPathSegLinetoHorizontalRel;
                positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoHorizontalRel.currentPoint, matrix));
                break;

            case SVGPathSegTypes.LineTo_Rel:
                SVGPathSegLinetoRel linetoRel = segment as SVGPathSegLinetoRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("linetoRel");
                    #endif
                positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoRel.currentPoint, matrix));
                break;

            case SVGPathSegTypes.LineTo_Vertical_Abs:
                SVGPathSegLinetoVerticalAbs linetoVerticalAbs = segment as SVGPathSegLinetoVerticalAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("linetoVerticalAbs");
                    #endif
                positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoVerticalAbs.currentPoint, matrix));
                break;

            case SVGPathSegTypes.LineTo_Vertical_Rel:
                SVGPathSegLinetoVerticalRel linetoVerticalRel = segment as SVGPathSegLinetoVerticalRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("linetoVerticalRel");
                    #endif
                positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoVerticalRel.currentPoint, matrix));
                break;

            case SVGPathSegTypes.MoveTo_Abs:
                if (lastCommand != SVGPathSegTypes.Close && lastCommand != SVGPathSegTypes.MoveTo_Abs && lastCommand != SVGPathSegTypes.MoveTo_Rel)
                {
                    if (positionBuffer.Count > 0)
                    {
                        output.Add(new List <Vector2>(positionBuffer.ToArray()));
                        positionBuffer.Clear();
                    }
                }
                SVGPathSegMovetoAbs movetoAbs = segment as SVGPathSegMovetoAbs;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("movetoAbs");
                    #endif
                positionBuffer.Add(SVGGeomUtils.TransformPoint(movetoAbs.currentPoint, matrix));
                break;

            case SVGPathSegTypes.MoveTo_Rel:
                if (lastCommand != SVGPathSegTypes.Close && lastCommand != SVGPathSegTypes.MoveTo_Abs && lastCommand != SVGPathSegTypes.MoveTo_Rel)
                {
                    if (positionBuffer.Count > 0)
                    {
                        output.Add(new List <Vector2>(positionBuffer.ToArray()));
                        positionBuffer.Clear();
                    }
                }
                SVGPathSegMovetoRel movetoRel = segment as SVGPathSegMovetoRel;
                    #if PATH_COMMAND_DEBUG
                Debug.Log("movetoRel");
                    #endif
                positionBuffer.Add(SVGGeomUtils.TransformPoint(movetoRel.currentPoint, matrix));
                break;
            }

            lastCommand = segment.type;
            return(true);
        }
Ejemplo n.º 2
0
        static bool GetSegment(SVGPathElement svgElement, SVGPathSeg segment, List<List<Vector2>> output, List<Vector2> positionBuffer, SVGMatrix matrix)
        {
            if (segment == null)
                return false;

//            Debug.Log("command: "+segment.type+", lastCommand: "+lastCommand);

            switch (segment.type)
            {
                case SVGPathSegTypes.Arc_Abs:
                    SVGPathSegArcAbs arcAbs = segment as SVGPathSegArcAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("arcAbs");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.Arc(SVGGeomUtils.TransformPoint(arcAbs.previousPoint, matrix), arcAbs.r1, arcAbs.r2, arcAbs.angle, arcAbs.largeArcFlag, arcAbs.sweepFlag, SVGGeomUtils.TransformPoint(arcAbs.currentPoint, matrix)));
                    break;
                case SVGPathSegTypes.Arc_Rel:
                    SVGPathSegArcRel arcRel = segment as SVGPathSegArcRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("arcRel");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.Arc(SVGGeomUtils.TransformPoint(arcRel.previousPoint, matrix), arcRel.r1, arcRel.r2, arcRel.angle, arcRel.largeArcFlag, arcRel.sweepFlag, SVGGeomUtils.TransformPoint(arcRel.currentPoint, matrix)));
                    break;
                case SVGPathSegTypes.Close:
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("Close");
                    #endif
                    //Debug.Log("Close");
                    if(positionBuffer.Count > 0)
                    {
                        output.Add(new List<Vector2>(positionBuffer.ToArray()));
                    }
                    positionBuffer.Clear();
                    break;
                case SVGPathSegTypes.CurveTo_Cubic_Abs:
                    SVGPathSegCurvetoCubicAbs curvetoCubicAbs = segment as SVGPathSegCurvetoCubicAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoCubicAbs");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicAbs.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicAbs.currentPoint, matrix)));
                    break;
                case SVGPathSegTypes.CurveTo_Cubic_Rel:
                    SVGPathSegCurvetoCubicRel curvetoCubicRel = segment as SVGPathSegCurvetoCubicRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoCubicRel");
                    #endif          
                    positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicRel.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicRel.currentPoint, matrix)));
                    break;
                case SVGPathSegTypes.CurveTo_Cubic_Smooth_Abs:
                    SVGPathSegCurvetoCubicSmoothAbs curvetoCubicSmoothAbs = segment as SVGPathSegCurvetoCubicSmoothAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoCubicSmoothAbs");
                    #endif               
                    positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothAbs.currentPoint, matrix)));
                    break;
                case SVGPathSegTypes.CurveTo_Cubic_Smooth_Rel:
                    SVGPathSegCurvetoCubicSmoothRel curvetoCubicSmoothRel = segment as SVGPathSegCurvetoCubicSmoothRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoCubicSmoothRel");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.CubicCurve(SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.controlPoint2, matrix), SVGGeomUtils.TransformPoint(curvetoCubicSmoothRel.currentPoint, matrix)));
                    
                    break;
                case SVGPathSegTypes.CurveTo_Quadratic_Abs:
                    SVGPathSegCurvetoQuadraticAbs curvetoQuadraticAbs = segment as SVGPathSegCurvetoQuadraticAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoQuadraticAbs");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticAbs.currentPoint, matrix)));
                    break;
                case SVGPathSegTypes.CurveTo_Quadratic_Rel:
                    SVGPathSegCurvetoQuadraticRel curvetoQuadraticRel = segment as SVGPathSegCurvetoQuadraticRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoQuadraticRel");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticRel.currentPoint, matrix)));
                    
                    break;
                case SVGPathSegTypes.CurveTo_Quadratic_Smooth_Abs:
                    SVGPathSegCurvetoQuadraticSmoothAbs curvetoQuadraticSmoothAbs = segment as SVGPathSegCurvetoQuadraticSmoothAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoQuadraticSmoothAbs");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothAbs.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothAbs.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothAbs.currentPoint, matrix)));
                    
                    break;
                case SVGPathSegTypes.CurveTo_Quadratic_Smooth_Rel:
                    SVGPathSegCurvetoQuadraticSmoothRel curvetoQuadraticSmoothRel = segment as SVGPathSegCurvetoQuadraticSmoothRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("curvetoQuadraticSmoothRel");
                    #endif
                    positionBuffer.AddRange(SVGGeomUtils.QuadraticCurve(SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothRel.previousPoint, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothRel.controlPoint1, matrix), SVGGeomUtils.TransformPoint(curvetoQuadraticSmoothRel.currentPoint, matrix)));
                    
                    break;
                case SVGPathSegTypes.LineTo_Abs:
                    SVGPathSegLinetoAbs linetoAbs = segment as SVGPathSegLinetoAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("linetoAbs");
                    #endif
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoAbs.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.LineTo_Horizontal_Abs:
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("linetoHorizontalAbs");
                    #endif
                    SVGPathSegLinetoHorizontalAbs linetoHorizontalAbs = segment as SVGPathSegLinetoHorizontalAbs;
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoHorizontalAbs.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.LineTo_Horizontal_Rel:
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("linetoHorizontalRel");
                    #endif
                    SVGPathSegLinetoHorizontalRel linetoHorizontalRel = segment as SVGPathSegLinetoHorizontalRel;
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoHorizontalRel.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.LineTo_Rel:
                    SVGPathSegLinetoRel linetoRel = segment as SVGPathSegLinetoRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("linetoRel");
                    #endif
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoRel.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.LineTo_Vertical_Abs:
                    SVGPathSegLinetoVerticalAbs linetoVerticalAbs = segment as SVGPathSegLinetoVerticalAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("linetoVerticalAbs");
                    #endif
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoVerticalAbs.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.LineTo_Vertical_Rel:
                    SVGPathSegLinetoVerticalRel linetoVerticalRel = segment as SVGPathSegLinetoVerticalRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("linetoVerticalRel");
                    #endif
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(linetoVerticalRel.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.MoveTo_Abs:
                    if(lastCommand != SVGPathSegTypes.Close && lastCommand != SVGPathSegTypes.MoveTo_Abs && lastCommand != SVGPathSegTypes.MoveTo_Rel)
                    {
                        if(positionBuffer.Count > 0)
                        {
                            output.Add(new List<Vector2>(positionBuffer.ToArray()));
                            positionBuffer.Clear();
                        }
                    }
                    SVGPathSegMovetoAbs movetoAbs = segment as SVGPathSegMovetoAbs;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("movetoAbs");
                    #endif
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(movetoAbs.currentPoint, matrix));
                    break;
                case SVGPathSegTypes.MoveTo_Rel:
                    if(lastCommand != SVGPathSegTypes.Close && lastCommand != SVGPathSegTypes.MoveTo_Abs && lastCommand != SVGPathSegTypes.MoveTo_Rel)
                    {
                        if(positionBuffer.Count > 0)
                        {
                            output.Add(new List<Vector2>(positionBuffer.ToArray()));
                            positionBuffer.Clear();
                        }
                    }
                    SVGPathSegMovetoRel movetoRel = segment as SVGPathSegMovetoRel;
                    #if PATH_COMMAND_DEBUG
                    Debug.Log("movetoRel");
                    #endif
                    positionBuffer.Add(SVGGeomUtils.TransformPoint(movetoRel.currentPoint, matrix));
                    break;
            }
            
            lastCommand = segment.type;
            return true;
        }