Exemple #1
0
    internal void ParseSVGToPath(string urlToFile)
    {
        if (string.IsNullOrEmpty(urlToFile))
        {
            return;
        }
        svgPaths.Clear();
        svgClassesToShow.Clear();
        svgParser parser = new svgParser();
        SvgClass  svg    = parser.Parse(urlToFile);

        foreach (SvgPath svgPath in svg.SvgPath.Where(x => x.D.Length > 10))
        {
            SVG = new SVGData();
            SVG.Path(svgPath.D);
            Mesh.Fill(SVG);
            List <Coords> coordsForId = new List <Coords>();
            float         minX        = Mesh.MeshData.Vertices.Min(x => x.x);
            float         minY        = Mesh.MeshData.Vertices.Min(y => y.y);
            float         maxX        = Mesh.MeshData.Vertices.Max(x => x.x);
            float         maxY        = Mesh.MeshData.Vertices.Max(y => y.y);
            float         midX        = (maxX - minX);
            float         midY        = (maxY - minY);

            for (int i = 0; i < Mesh.MeshData.Vertices.Count; i++)
            {
                Coords coord = new Coords {
                    X = Mesh.MeshData.Vertices[i].x - midX, Y = Mesh.MeshData.Vertices[i].y - midY, Z = Mesh.MeshData.Vertices[i].z
                };
                coordsForId.Add(coord);
            }

            if (svgPath.Class == null)
            {
                svgPath.Class = svgPath.Id;
            }
            else if (svgPath.Class.Length == 0)
            {
                svgPath.Class = svgPath.Id;
            }
            if (string.IsNullOrEmpty(svgPath.Class))
            {
                svgPath.Class = (svgClassesToShow.Count + 1).ToString();
            }
            CreateSVGClassObject(svgPath.Class);
            svgPaths.Add(svgPath.Class, coordsForId);
            svgClassesToShow.Add(svgPath.Class);
        }
    }
Exemple #2
0
        public SvgClass Parse(string urlToFile)
        {
            if (System.IO.Path.GetExtension(urlToFile).ToUpper() != ".SVG")
            {
                return(null);
            }
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.ValidationType = ValidationType.None;
            settings.XmlResolver    = null;
            settings.DtdProcessing  = DtdProcessing.Ignore;
            XmlReader   reader = XmlReader.Create(urlToFile, settings);
            XmlDocument doc    = new XmlDocument();

            doc.Load(reader);
            SvgClass svg = new SvgClass();

            svg = XmlOperation.Deserialize <SvgClass>(urlToFile);
            return(svg);
        }