예제 #1
0
        public static SVGElementArray line(string URL)
        {
            //attributes to look for from a line
            SVGElementArray       lines           = new SVGElementArray();
            List <attributeArray> attributeValues = new List <attributeArray>();

            readSVG.getElements(allElementAttributes.line, "line", URL, ref attributeValues);
            if (attributeValues.Count > 0)
            {
                //seporate the attributes that are more than the attribute list
                //these are the transformMatricieStrings
                for (int elementNum = 0; elementNum < attributeValues.Count; elementNum++)
                {
                    string[] matricies     = new string[0];
                    int      numTransforms = attributeValues[elementNum].atributes.Count
                                             - allElementAttributes.line.Count();
                    //seporate the transform matricies from the other attributes
                    for (int transformNum = 0; transformNum < numTransforms; transformNum++)
                    {
                        Array.Resize(ref matricies, matricies.Length + 1);
                        matricies[transformNum] = attributeValues[elementNum].atributes
                                                  [allElementAttributes.line.Count() + transformNum];
                    }

                    //convert lineangle points to SVGline
                    double lineX1 = double.Parse(attributeValues[elementNum].atributes[0]);
                    double lineY1 = double.Parse(attributeValues[elementNum].atributes[1]);
                    double lineX2 = double.Parse(attributeValues[elementNum].atributes[2]);
                    double lineY2 = double.Parse(attributeValues[elementNum].atributes[3]);

                    point start = new point();
                    point end   = new point();

                    start.x = lineX1;
                    start.y = lineY1;
                    end.x   = lineX2;
                    end.y   = lineY2;

                    QuadCode quadCode = new QuadCode();
                    lines.SVGelement.Add(quadCode.addLine(start, end, matricies));
                }
                return(lines);
            }
            else
            {
                return(new SVGElementArray());
            }
        }
예제 #2
0
        public static SVGElementArray polylineToQuadLine(point[] points, string[] matricies, bool closedFigure)
        {
            //add two lines for every two points
            var             quadCode = new QuadCode();
            SVGElementArray lines    = new SVGElementArray();

            for (int pointNum = 1; pointNum < points.Length; pointNum++)
            {
                lines.SVGelement.Add(quadCode.addLine(points[pointNum - 1], points[pointNum], matricies));
            }
            //draw a line closing the start and end points
            if (closedFigure)
            {
                lines.SVGelement.Add(quadCode.addLine(points[0], points[points.Length - 1], matricies));
            }
            return(lines);
        }
예제 #3
0
        public static SVGElementArray circle(string URL)
        {
            //attributes to look for from a circle
            SVGElementArray       circles         = new SVGElementArray();
            List <attributeArray> attributeValues = new List <attributeArray>();

            readSVG.getElements(allElementAttributes.circle, "circle", URL, ref attributeValues);
            if (attributeValues.Count > 0)
            {
                //seporate the attributes that are more than the attribute list
                //these are the transformMatricieStrings
                for (int elementNum = 0; elementNum < attributeValues.Count; elementNum++)
                {
                    string[] matricies     = new string[0];
                    int      numTransforms = attributeValues[elementNum].atributes.Count
                                             - allElementAttributes.circle.Count();
                    //seporate the transform matricies from the other attributes
                    for (int transformNum = 0; transformNum < numTransforms; transformNum++)
                    {
                        Array.Resize(ref matricies, matricies.Length + 1);
                        matricies[transformNum] = attributeValues[elementNum].atributes
                                                  [allElementAttributes.circle.Count() + transformNum];
                    }

                    //convert circle to SVGellipse
                    point center = new point();
                    point radius = new point();

                    center.x = double.Parse(attributeValues[elementNum].atributes[0]);
                    center.y = double.Parse(attributeValues[elementNum].atributes[1]);
                    radius.x = double.Parse(attributeValues[elementNum].atributes[2]);
                    radius.y = radius.x;

                    QuadCode quadCode = new QuadCode();
                    circles.SVGelement.Add(quadCode.addEllipse(center, radius, matricies));
                }
                return(circles);
            }
            else
            {
                return(new SVGElementArray());
            }
        }
예제 #4
0
        public static SVGElementArray path(attributeArray attributeValues)
        {
            //0 = d's : 1 = points
            //takes in d and points to make an SVGElementArray

            //!!ADD SUPPORT FOR POINTS TO POLYLINE CONVERSION!!

            SVGElementArray returnElements = new SVGElementArray();
            List <char>     allCMD         = new List <char>();

            //transforming
            string[] matricies     = new string[0];
            int      numTransforms = attributeValues.atributes.Count
                                     - allElementAttributes.path.Count();

            //seporate the transform matricies from the other attributes
            for (int transformNum = 0; transformNum < numTransforms; transformNum++)
            {
                Array.Resize(ref matricies, matricies.Length + 1);
                matricies[transformNum] = attributeValues.atributes
                                          [allElementAttributes.path.Count() + transformNum];
            }
            transformMatrix finalMatrix = transform.combineMatricies(matricies);
            string          dVal        = attributeValues.atributes[0];

            string[] seporateDVals = dVal.Split(new char[2] {
                ' ', ','
            });
            char         CMD           = ' ';
            point        handle0       = new point();
            point        handle1       = new point();
            point        startPoint    = new point();
            point        currentPoint  = new point();
            point        previousPoint = new point();
            QuadCode     quadCode      = new QuadCode();
            List <point> moveTos       = new List <point>();

            //going through the loop
            for (int dValIndex = 0; dValIndex < seporateDVals.Length - 1; dValIndex++)
            {
                //look for a cmd
                char firstChar = seporateDVals[dValIndex][0];
                if (char.IsLetter(firstChar) == true)
                {
                    CMD = firstChar;
                    if (seporateDVals[dValIndex].Length > 1)
                    {
                        seporateDVals[dValIndex] = seporateDVals[dValIndex].Substring(1);
                    }
                    else
                    {
                        dValIndex++;
                    }
                    allCMD.Add(CMD);
                }
                double firstVal = double.Parse(seporateDVals[dValIndex]);
                switch (CMD)
                {
                case 'M':     //move to point absolute
                    startPoint.x = firstVal;
                    dValIndex++;
                    startPoint.y = double.Parse(seporateDVals[dValIndex]);
                    currentPoint = startPoint;
                    moveTos.Add(startPoint);
                    break;

                case 'm':     //move to point relative
                    startPoint.x = currentPoint.x + firstVal;
                    dValIndex++;
                    startPoint.y = currentPoint.y + double.Parse(seporateDVals[dValIndex]);
                    currentPoint = startPoint;
                    moveTos.Add(startPoint);
                    break;

                case 'L':     //line to point absolute
                    currentPoint.x = firstVal;
                    dValIndex++;
                    currentPoint.y = double.Parse(seporateDVals[dValIndex]);
                    returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies));
                    break;

                case 'l':     //line to point relative
                    currentPoint.x += firstVal;
                    dValIndex++;
                    currentPoint.y += double.Parse(seporateDVals[dValIndex]);
                    returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies));
                    break;

                case 'H':     //horizontal line absolute
                    currentPoint.x = firstVal;
                    currentPoint.y = 0;
                    returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies));
                    break;

                case 'h':     //horizontal line relative
                    currentPoint.x += firstVal;
                    returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies));
                    break;

                case 'V':     //vertical line absolute
                    currentPoint.x = 0;
                    currentPoint.y = firstVal;
                    returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies));
                    break;

                case 'v':     //vertical line relative
                    currentPoint.y += firstVal;
                    returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies));
                    break;

                case 'C':     // Cubic bezier curve absolute
                case 'S':
                    handle0.x = firstVal;
                    dValIndex++;
                    handle0.y = double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    handle1.x = double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    handle1.y = double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.x = double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.y = double.Parse(seporateDVals[dValIndex]);
                    returnElements.SVGelement.Add(quadCode.addCurve(previousPoint, handle0, handle1, currentPoint, matricies));
                    break;

                case 'c':     // Cubic bezier curve relative
                case 's':
                    handle0.x = previousPoint.x + firstVal;
                    dValIndex++;
                    handle0.y = previousPoint.y + double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    handle1.x = previousPoint.x + double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    handle1.y = previousPoint.y + double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.x += double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.y += double.Parse(seporateDVals[dValIndex]);
                    returnElements.SVGelement.Add(quadCode.addCurve(previousPoint, handle0, handle1, currentPoint, matricies));
                    break;

                case 'Q':     // Cubic bezier curve absolute
                case 'T':
                    handle0.x = firstVal;
                    dValIndex++;
                    handle0.y = double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.x = double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.y = double.Parse(seporateDVals[dValIndex]);
                    returnElements.SVGelement.Add(quadCode.addCurve(previousPoint, handle0, handle0, currentPoint, matricies));
                    break;

                case 'q':     // Cubic bezier curve relative
                case 't':
                    handle0.x = previousPoint.x + firstVal;
                    dValIndex++;
                    handle0.y = previousPoint.y + double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.x += double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.y += double.Parse(seporateDVals[dValIndex]);
                    returnElements.SVGelement.Add(quadCode.addCurve(previousPoint, handle0, handle0, currentPoint, matricies));
                    break;

                case 'A':     //Arcto absolute
                    //????????????????????
                    break;

                case 'a':     //Arcto relative
                    //????????????????????
                    break;

                case 'Z':     //closing line to start point
                case 'z':
                    returnElements.SVGelement.Add(quadCode.addLine(startPoint, currentPoint, matricies));
                    break;
                }
                previousPoint = currentPoint;
            }
            if (allCMD.Count == 2)
            {
                if (allCMD[0].ToString().ToUpper() == "M" & allCMD[1].ToString().ToUpper() == "Z")
                {
                    return(Quadify.polylineToQuadLine(moveTos.ToArray(), matricies, true));
                }
            }
            else if (allCMD.Count == 1)
            {
                if (allCMD[0].ToString().ToUpper() == "M")
                {
                    return(Quadify.polylineToQuadLine(moveTos.ToArray(), matricies, true));
                }
            }
            return(returnElements);
        }