private static SvgMarker CreateArrowMarker()
        {
            var size = 7f;

            return(new SvgMarker()
            {
                ID = "markerArrow",
                RefX = size * 1f,
                RefY = size * .5f,
                MarkerUnits = SvgMarkerUnits.StrokeWidth,
                MarkerWidth = size,
                MarkerHeight = size,
                Orient = new SvgOrient()
                {
                    IsAuto = true
                },
                Children =
                {
                    new SvgPath()
                    {
                        ID = "pathMarkerArrow",
                        Fill = new SvgColourServer(Color.Black),
                        PathData = SvgPathBuilder.Parse($@"M 0 0 L {size * 1f} {size * .5f} L 0 {size} z")
                    }
                }
            });
        }
        private static void AddHatching(SvgDocument document, SvgGroup group, Color color, float opacity, int margin, Boolean backDirection)
        {
            var w = document.Width;
            var h = document.Height;

            for (int i = margin; i < w + h; i += 4)
            {
                var x0 = i < h ? 0 : i - h;
                var y0 = i - x0;
                var x1 = (i + 1) < h ? 0 : (i + 1) - h;
                var y1 = (i + 1) - x1;
                var y2 = (i + 1) < w ? 0 : (i + 1) - w;
                var x2 = (i + 1) - y2;
                var y3 = i < w ? 0 : i - w;
                var x3 = i - y3;
                if (backDirection)
                {
                    x0 = w - x0;
                    x1 = w - x1;
                    x2 = w - x2;
                    x3 = w - x3;
                }
                var strPathTemplate = "M{0} {1} L{2} {3} L{4} {5} L{6} {7} z";
                var strPath         = String.Format(strPathTemplate, x0, y0, x1, y1, x2, y2, x3, y3);
                var path            = new SvgPath();
                path.PathData    = SvgPathBuilder.Parse(strPath);
                path.Fill        = new SvgColourServer(color);
                path.FillOpacity = opacity;
                group.Children.Add(path);
            }
        }
Beispiel #3
0
        protected override void BuildSVG()
        {
            base.BuildSVG();

            SampleGroup.Children.Clear();

            Definitions.Children.Add(SampleDefinition);
            PanZoomGroup.Children.Add(SampleGroup);

            //draw waveform
            Path.PathData.Clear();
            var coords    = new List <float>();
            var curveMove = 'M';

            foreach (var sample in Model.Samples)
            {
                coords.Add(sample.Time.Value);
                coords.Add(sample.Value.Value);
            }
            SvgPathBuilder.CreatePathSegment(curveMove, Path.PathData, coords, char.IsLower(curveMove));
            coords.Clear();

            SampleGroup.Children.Add(Path);

//			foreach (var sample in Samples)
//				sample.BuildSVGTo(SampleGroup);
        }
Beispiel #4
0
        protected virtual SvgBuilder FillSvg(bool[,] sprite, Color background, Color foreground)
        {
            int     side     = sprite.GetLength(0);
            decimal offset   = Options.Border / (decimal)Options.Scale;
            decimal fullSide = side + 2m * offset;

            SvgBuilder svg = new SvgBuilder()
                             .SetViewBox(0, 0, fullSide, fullSide)
                             .Append(new SvgRect {
                PercentageWidth  = 100,
                PercentageHeight = 100,
                Color            = background
            });

            SvgPathBuilder path = new SvgPathBuilder {
                Color = foreground
            };

            for (int y = 0; y < side; ++y)
            {
                for (int x = 0; x < side; ++x)
                {
                    if (sprite[y, x])
                    {
                        path.AppendPoint(x + offset, y + offset)
                        .AppendRelativeHorizontalLine(1)
                        .AppendRelativeVerticalLine(1)
                        .AppendRelativeHorizontalLine(-1)
                        .AppendClosePath();
                    }
                }
            }

            return(svg.Append(path));
        }
        protected override void AddElementDefinition(SvgGroup group)
        {
            var pathLeft    = new SvgPath();
            var strPathLeft = "M0 0 c 0 -1 1 -1 2 0 l1 1 c 1 1 2 2.6 2 4 l0 6.8 c 0 1 -1 1 -2 0 l-1 -1 c -1 -1 -2 -2.6 -2 -4 l0 -6.8 z";

            pathLeft.PathData = SvgPathBuilder.Parse(strPathLeft);
            group.Children.Add(pathLeft);
            var pathRight    = new SvgPath();
            var strPathRight = "M8 1 c -1 1 -2 2.6 -2 4 l0 6.8 c 0 1 1 1 2 0 l1 -1 c 1 -1 2 -2.6 2 -4 l0 -6.8 c 0 -1 -1 -1 -2 0 l-1 1 z";

            pathRight.PathData = SvgPathBuilder.Parse(strPathRight);
            group.Children.Add(pathRight);
        }
Beispiel #6
0
        /// <summary>
        /// adds static chain physics objects for each path in the SVG
        /// </summary>
        /// <param name="group">Group.</param>
        void addPaths(SvgGroup group)
        {
            var svgPathBuilder = new SvgPathBuilder();

            foreach (var path in group.paths)
            {
                var pts = path.getTransformedDrawingPoints(svgPathBuilder);

                createEntity(path.id)
                .addComponent <FSRigidBody>()
                .addComponent(new FSCollisionChain())
                .setVertices(pts);
            }
        }
Beispiel #7
0
        void CreatePath(float x1, float y1, float x2, float y2, bool isLinear, bool easeIn, bool easeOut)
        {
            var coords    = new List <float>();
            var curveMove = 'M';

            var curveType = 'C';

            if (isLinear)
            {
                curveType = 'L';
            }

            coords.Add(x1);
            coords.Add(-y1);

            SvgPathBuilder.CreatePathSegment(curveMove, Path.PathData, coords, char.IsLower(curveMove));
            coords.Clear();

            if (!isLinear)
            {
                if (easeOut)
                {
                    coords.Add(x1 + (x2 - x1) * (float)Model.Start.EaseOut.Value.x);
                    coords.Add(-y1);
                }
                else
                {
                    coords.Add(x1 + (x2 - x1) * (1 / 3f));
                    coords.Add(-(y1 + (y2 - y1) * (1 / 3f)));
                }

                if (easeIn)
                {
                    coords.Add(x2 + (x2 - x1) * (float)Model.Start.EaseIn.Value.x);
                    coords.Add(-y2);
                }
                else
                {
                    coords.Add(x2 - (x2 - x1) * (1 / 3f));
                    coords.Add(-(y2 - (y2 - y1) * (1 / 3f)));
                }
            }

            coords.Add(x2);
            coords.Add(-y2);
            SvgPathBuilder.CreatePathSegment(curveType, Path.PathData, coords, char.IsLower(curveType));
        }
Beispiel #8
0
        public void SavveAsSvg()
        {
            SvgDocument svg = new SvgDocument();

            var group = new SvgGroup();

            foreach (var stroke in Traits)
            {
                var     geometry = stroke.GetGeometry();
                SvgPath a        = new SvgPath
                {
                    PathData    = SvgPathBuilder.Parse(geometry.ToString()),
                    StrokeWidth = new SvgUnit((float)AttributsDessin.Width),
                };
                group.Children.Add(a);
                svg.Children.Add(group);
            }
            svg.Write("Game.svg");
        }
        protected override void AddElementDefinition(SvgGroup group)
        {
            var pathCross    = new SvgPath();
            var strPathCross = "M 1.65 0.65 a1.4 1.4 0 0 1 2 0 l 2.5 2.5 l 2.5 -2.5 a1.4 1.4 0 0 1 2 0 l 1 1 a1.4 1.4 0 0 1 0 2 l -2.5 2.5 l 2.5 2.5 a1.4 1.4 0 0 1 0 2 l -1 1 a1.4 1.4 0 0 1 -2 0 l -2.5 -2.5 l -2.5 2.5 a1.4 1.4 0 0 1 -2 0 l -1 -1 a1.4 1.4 0 0 1 0 -2 l 2.5 -2.5 l -2.5 -2.5 a1.4 1.4 0 0 1 0 -2 l 1 -1 z";

            pathCross.PathData = SvgPathBuilder.Parse(strPathCross);
            group.Children.Add(pathCross);
            var pathShadow    = new SvgPath();
            var strPathShadow = "M11.7 2 a1.4 1.4 0 0 1 0 2 l-8 8 a1.4 1.4 0 0 1 -2 0 l10 -10 z";

            pathShadow.PathData    = SvgPathBuilder.Parse(strPathShadow);
            pathShadow.Fill        = new SvgColourServer(Color.Black);
            pathShadow.FillOpacity = 0.2f;
            group.Children.Add(pathShadow);
            var pathLight    = new SvgPath();
            var strPathLight = "M8.7 0.65 a1.4 1.4 0 0 1 2 0 l-10 10 a1.4 1.4 0 0 1 0 -2 l10 -10 z";

            pathLight.PathData    = SvgPathBuilder.Parse(strPathLight);
            pathLight.Fill        = new SvgColourServer(Color.White);
            pathLight.FillOpacity = 0.2f;
            group.Children.Add(pathLight);
        }
Beispiel #10
0
        private static void Sample02()
        {
            var svgDoc = new SvgDocument
            {
                Width  = 500,
                Height = 500
            };

            svgDoc.ViewBox = new SvgViewBox(0, 0, 250, 250);

            var group = new SvgGroup();

            svgDoc.Children.Add(group);

            var seglist = SvgPathBuilder.Parse("M 10,60 L 30,10 90,10 110,60 z");

            group.Children.Add(new SvgPath
            {
                StrokeWidth = 1,
                Fill        = new SvgColourServer(Color.FromArgb(152, 225, 125)),
                Stroke      = new SvgColourServer(Color.DarkGray),
                PathData    = seglist
            });


            group.Children.Add(new SvgText
            {
                Nodes = { new SvgContentNode {
                              Content = "Sample"
                          } },
                X          = { 30 },
                Y          = { 50 },
                Fill       = new SvgColourServer(Color.White),
                FontSize   = 18,
                FontFamily = "sans-serif"
            });

            svgDoc.Write("sample2.svg");
        }
Beispiel #11
0
        public override void Create()
        {
            Children.Add(new SvgTitle {
                Content = Label
            });

            // 0,0 circle
            SvgCircle circle = Circles.CutCircle(FastenerDiameter, 0, 0);

            base.Children.Add(circle);
            var u = circle.CreateReference(0, Constants.JigHoleSpacing);

            Children.Add(u);

            var path = new SvgPath {
                Color = Colors.Cut()
            };

            //var rawPath = "m 82.210613,311.32719 c 4.903234,0.248 9.851491,-0.42473 14.510548,-1.97276 6.845049,-2.27436 12.976639,-6.39768 18.224889,-11.34575 5.24825,-4.94806 9.65879,-10.7159 13.73385,-16.66748 5.27384,-7.70239 10.07878,-15.87608 12.62569,-24.85681 1.78373,-6.28964 2.42151,-12.83684 3.15642,-19.33308 1.14521,-10.12306 2.52865,-20.51171 0,-30.38054 -1.63435,-6.37852 -4.83943,-12.23906 -8.31522,-17.83151 -3.47578,-5.59246 -7.26224,-11.01064 -10.22875,-16.88912 -5.18715,-10.27894 -7.73022,-21.7076 -9.07471,-33.14243 -2.65911,-22.61561 -0.80292,-45.499389 -1.57821,-68.257584 -0.27634,-8.111907 -0.89432,-16.256253 -2.80974,-24.143621 -1.56085,-6.427312 -4.05214,-12.768427 -8.34345,-17.801442 C 98.710395,22.369935 90.534001,18.489928 82.210613,18.312064";
            var rawPath = "M 0.01346761,428.37881 C 7.5312157,428.75905 15.117974,427.7275 22.26134,425.35407 c 10.494956,-3.487 19.896051,-9.80893 27.942852,-17.39546 8.046647,-7.58653 14.808916,-16.42983 21.056943,-25.55495 8.085899,-11.80948 15.453023,-24.34156 19.357982,-38.11096 2.734806,-9.64349 3.712694,-19.68179 4.839457,-29.6419 1.755845,-15.52094 3.877055,-31.44896 0,-46.58001 -2.505742,-9.7798 -7.419867,-18.76523 -12.749035,-27.33977 C 77.380372,232.15664 71.574986,223.84934 67.026534,214.83631 59.073566,199.07649 55.174433,181.55377 53.113018,164.0217 49.036031,129.347 51.881995,94.261102 50.693289,59.367779 50.26966,46.930432 49.32213,34.443348 46.385399,22.35027 43.992196,12.495787 40.172483,2.7734672 33.592974,-4.9432622 25.311284,-14.656398 12.77506,-20.605294 0.01346761,-20.878007";

            path.PathData    = SvgPathBuilder.Parse(rawPath);
            path.Fill        = SvgPaintServer.None;
            path.Stroke      = Colors.Cut();
            path.StrokeWidth = Units.Mm(Constants.Kerf);
            path.ID          = $"spacerOutline{idCounter++}";

            // matrix(-1,0,0,1,0.02693522,0)
            var mirror = path.CreateReference();

            // To get this I mirrored, and then moved the clone to make its endpoints snap to the original's
            mirror.Transforms.Add(new SvgMatrix(new List <float> {
                -1f, 0f, 0f, 1f, 0f, 0.02693522f, 0f
            }));

            Children.Add(path);
            Children.Add(mirror);
        }
Beispiel #12
0
        //public void AfficherTraitsClassique()
        //{
        //    StrokeCollection strokeCollections = Traits.Clone();
        //    StylusPointCollection points = new StylusPointCollection();


        //    foreach (Stroke stroke in strokeCollections)
        //    {
        //        points.Add(stroke.StylusPoints);
        //        StylusPointCollection first = new StylusPointCollection();
        //        first.Add(points[0]);
        //        Stroke newStroke = new Stroke(first);
        //        DispatcherTimer timer = new DispatcherTimer();
        //        timer.Interval = TimeSpan.FromMilliseconds(10);
        //        timer.Start();
        //        int index = 0;
        //        timer.Tick += (s, a) =>
        //        {

        //            newStroke.StylusPoints.Insert(index, points[index]);
        //            if (!NouveauxTraits.Contains(newStroke))
        //            {
        //                NouveauxTraits.Add(newStroke);
        //            }
        //            index++;
        //            if (index >= points.Count) timer.Stop();
        //        };
        //    };


        //}

        private void ConvertDrawingToSVG(object sender)
        {
            var svg         = new SvgDocument();
            var colorServer = new SvgColourServer(System.Drawing.Color.Black);

            var group = new SvgGroup {
                Fill = colorServer, Stroke = colorServer
            };

            svg.Children.Add(group);

            foreach (var stroke in Traits)
            {
                var geometry = stroke.GetGeometry(stroke.DrawingAttributes).GetOutlinedPath‌​Geometry();

                var s = XamlWriter.Save(geometry);

                if (!string.IsNullOrEmpty(s))
                {
                    var element = XElement.Parse(s);

                    var data = element.Attribute("Figures")?.Value;

                    if (!string.IsNullOrEmpty(data))
                    {
                        group.Children.Add(new SvgPath
                        {
                            PathData = SvgPathBuilder.Parse(data),
                            Fill     = colorServer,
                            Stroke   = colorServer
                        });
                    }
                }
            }

            Mediator.Notify("GoToNewDrawingConfirmation", "");
        }
Beispiel #13
0
        private ISvgImage GetEmbeddedImage(String name)
        {
            var srl  = new DasSerializer();
            var bldr = new SvgPathBuilder(_imageProvider, srl);

            var asm = GetType().GetTypeInfo().Assembly;

            //var bobsy = asm.GetManifestResourceNames();

            using (var stream = asm.GetManifestResourceStream(name))
            {
                if (stream == null)
                {
                    throw new InvalidOperationException("Missing Resource: " + name);
                }

                var res = srl.FromXml <SvgDocument>(stream);
                var bob = bldr.Parse(res);
                //var bob = SvgPathBuilder.Parse(res.Path.D);
                return(bob);
                //return _imageProvider.GetImage(stream) ??
                //       throw new InvalidOperationException("Missing Resource: " + name);
            }
        }
Beispiel #14
0
        public static string ConvertDrawingToSVG(StrokeCollection traits)
        {
            var svg         = new SvgDocument();
            var colorServer = new SvgColourServer(System.Drawing.Color.Black);

            var group = new SvgGroup {
                Fill = colorServer, Stroke = colorServer
            };

            svg.Children.Add(group);

            foreach (var stroke in traits)
            {
                var geometry = stroke.GetGeometry(stroke.DrawingAttributes).GetOutlinedPath‌​Geometry();

                var s = XamlWriter.Save(geometry);

                if (!string.IsNullOrEmpty(s))
                {
                    var element = XElement.Parse(s);

                    var data = element.Attribute("Figures")?.Value;

                    if (!string.IsNullOrEmpty(data))
                    {
                        group.Children.Add(new SvgPath
                        {
                            PathData = SvgPathBuilder.Parse(data),
                            Fill     = colorServer,
                            Stroke   = colorServer
                        });
                    }
                }
            }
            return(group.GetXML());
        }
Beispiel #15
0
        public IEnumerable <Lote> Generate(long id)
        {
            //Criar a lista de lotes
            var lotes = new List <Lote>();

            //Instanciar o bo do loteamneto e recuperar o loteamento selecionado
            var loteamentoBo = new LoteamentoLogic();
            var loteamento   = loteamentoBo.Get(id);

            //Caso o loteamento não possua mapa retorna nulo
            if (loteamento.MapaId == null)
            {
                return(null);
            }

            //Formata o source do mapa removendo os carateres adicionados de base64
            var source = Regex.Replace(loteamento.Mapa.Source, @"data:image/svg\+xml;base64,?", "");

            //Converte o base64 em um array de bytes
            var buffer = Convert.FromBase64String(source);

            using (var ms = new MemoryStream(buffer))
            {
                //Carrega o arquivo SVG (que na verdade é um XML)
                var doc = XDocument.Load(ms);

                //Selecione os retangulos (rects) do svg, calcula a area e adiciona o lote
                var rects = doc.Descendants().Where(x => x.Name.LocalName == "rect");
                foreach (var rect in rects)
                {
                    var width  = Convert.ToDecimal(rect.Attribute("width").Value);
                    var height = Convert.ToDecimal(rect.Attribute("height").Value);
                    var style  = rect.Attribute("style").Value;
                    var cor    = Regex.Match(style, @"fill:\s*(\#*.*);").Groups[1].Value.Split(';')[0];

                    lotes.Add(new Lote
                    {
                        Codigo       = rect.Attribute("id").Value,
                        Area         = Area.Retangulo(width, height),
                        StatusAdicao = StatusAdicao.Adicao,
                        Cor          = cor
                    });
                }

                //Selecione os caminhos (paths) do svg, calcula a area e adiciona o lote
                var paths = doc.Descendants().Where(x => x.Name.LocalName == "path");
                foreach (var path in paths)
                {
                    var d = SvgPathBuilder.Parse(path.Attribute("d").Value);

                    var points = new List <PointF>();
                    foreach (var seg in d)
                    {
                        if (seg != d.Last)
                        {
                            points.Add(new PointF(seg.Start.X, seg.Start.Y));
                            points.Add(new PointF(seg.End.X, seg.End.Y));
                        }

                        if (seg.GetType() == typeof(SvgCubicCurveSegment))
                        {
                            var cubic = (SvgCubicCurveSegment)seg;

                            points.Add(new PointF(cubic.FirstControlPoint.X, cubic.FirstControlPoint.Y));
                            points.Add(new PointF(cubic.SecondControlPoint.X, cubic.SecondControlPoint.Y));
                        }
                    }

                    points.Add(points[0]);
                    var area = (int)Math.Abs(points.Take(points.Count - 1)
                                             .Select((p, i) => (points[i + 1].X - p.X) * (points[i + 1].Y + p.Y))
                                             .Sum() / 2);

                    var style = path.Attribute("style").Value;
                    var cor   = Regex.Match(style, @"fill:\s*(\#*.*);").Groups[1].Value.Split(';')[0];

                    lotes.Add(new Lote
                    {
                        Codigo       = path.Attribute("id").Value,
                        Area         = area,
                        StatusAdicao = StatusAdicao.Adicao,
                        Cor          = cor
                    });
                }
            }

            //Recuperar os lotes do loteamento
            var lotesDb = List(id).ToList();

            //Marcar os lotes como alteração
            foreach (var loteDb in lotesDb)
            {
                var lote = lotes.FirstOrDefault(x => x.Codigo == loteDb.Codigo);

                if (lote != null)
                {
                    loteDb.StatusAdicao = StatusAdicao.Alteracao;
                    lotes.Insert(lotes.IndexOf(lote), loteDb);
                    lotes.Remove(lote);
                }
            }

            //Marcar os lotes como remoção
            var lotesRemocao = lotesDb.Where(x => !lotes.Select(l => l.Codigo).Contains(x.Codigo));

            foreach (var lote in lotesRemocao)
            {
                lote.StatusAdicao = StatusAdicao.Remocao;
            }

            //Retornar a lista de lotes
            return(lotes.OrderBy(x => x.Codigo));
        }
Beispiel #16
0
        public void TestArrowCodeCreation()
        {
            // Sample code from Issue 212. Thanks to podostro.
            const int width  = 50;
            const int height = 50;

            var document = new SvgDocument()
            {
                ID      = "svgMap",
                ViewBox = new SvgViewBox(0, 0, width, height)
            };

            var defsElement = new SvgDefinitionList()
            {
                ID = "defsMap"
            };

            document.Children.Add(defsElement);

            var groupElement = new SvgGroup()
            {
                ID = "gMap"
            };

            document.Children.Add(groupElement);

            var arrowPath = new SvgPath()
            {
                ID       = "pathMarkerArrow",
                Fill     = new SvgColourServer(Color.Black),
                PathData = SvgPathBuilder.Parse(@"M0,0 L4,2 L0,4 L1,2 z")
            };

            var arrowMarker = new SvgMarker()
            {
                ID           = "markerArrow",
                MarkerUnits  = SvgMarkerUnits.StrokeWidth,
                MarkerWidth  = 5,
                MarkerHeight = 5,
                RefX         = 3,
                RefY         = 2,
                Orient       = new SvgOrient()
                {
                    IsAuto = true
                },
                Children = { arrowPath }
            };

            defsElement.Children.Add(arrowMarker);

            var line = new SvgLine()
            {
                ID          = "lineLinkedPoint",
                StartX      = 0,
                StartY      = 15,
                EndX        = 35,
                EndY        = 35,
                Stroke      = new SvgColourServer(Color.Black),
                StrokeWidth = 3,
                MarkerEnd   = new Uri(string.Format("url(#{0})", arrowMarker.ID), UriKind.Relative)
            };

            groupElement.Children.Add(line);

            var svgXml = document.GetXML();
            var img    = document.Draw();

            var file = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            File.WriteAllText(file + ".svg", svgXml);
            img.Save(file + ".png");
            Debug.WriteLine(string.Format("Svg saved to '{0}'", file));

            Debugger.Break();

            // Remove
            var svg = new FileInfo(file + ".svg");

            if (svg.Exists)
            {
                svg.Delete();
            }
            var png = new FileInfo(file + ".png");

            if (png.Exists)
            {
                png.Delete();
            }
        }
 public void SvgPathBuilder_Parse_Small()
 {
     SvgPathBuilder.Parse(@"M0,0 L4,2 L0,4 L1,2 z".AsSpan());
 }
 public void SvgPathBuilder_Parse_Large()
 {
     SvgPathBuilder.Parse(@"m -129.83,103.065 c 0.503,6.048 1.491,12.617 3.23,15.736 0,0 -3.6,12.4 5.2,25.6 0,0 -0.4,7.2 1.2,10.4 0,0 4,8.4 8.8,9.2 3.884,0.647 12.607,3.716 22.468,5.12 0,0 17.132,14.08 13.932,26.88 0,0 -0.4,16.4 -4,18 0,0 11.6,-11.2 2,5.6 l -4.4,18.8 c 0,0 25.6,-21.6 10,-3.2 l -10,26 c 0,0 19.6,-18.4 12.4,-10 l -3.2,8.8 c 0,0 43.2,-27.2 12.4,2.4 0,0 8,-3.6 12.4,-0.8 0,0 6.8,-1.2 6,0.4 0,0 -20.8,10.4 -24.4,28.8 0,0 8.4,-10 5.2,0.8 l 0.4,11.6 c 0,0 4,-21.6 3.6,16 0,0 19.2,-18 7.6,2.8 l 0,16.8 c 0,0 15.2,-16.4 8.8,-3.6 0,0 10,-8.8 6,6.4 0,0 -0.8,10.4 3.6,-0.8 0,0 16,-30.6 10,-4.4 0,0 -0.8,19.2 4,4.4 0,0 0.4,10.4 9.6,17.6 0,0 -1.2,-50.8 11.6,-14.8 l 4,16.4 c 0,0 2.8,-9.2 2.4,-14.4 0,0 14.8,-16.4 8,8 0,0 15.2,-22.8 12,-9.6 0,0 -7.6,16 -6,20.8 0,0 16.8,-34.8 18,-36.4 0,0 -2,42.401 8.8,6.4 0,0 5.6,12 2.8,16.4 0,0 8,-8 7.2,-11.2 0,0 4.6,-8.2 7.4,5.4 0,0 1.8,9.4 3.4,6.2 0,0 4,24.001 5.2,1.2 0,0 1.6,-13.6 -5.6,-25.2 0,0 0.8,-3.2 -2,-7.2 0,0 13.6,21.6 6.4,-7.2 0,0 11.201,8 12.401,8 0,0 -13.601,-23.2 -4.801,-18.4 0,0 -5.2,-10.4 12.801,1.6 0,0 -16.001,-16 1.6,-6.4 0,0 8,6.4 0.4,-3.6 0,0 -14.401,-16 7.6,2 0,0 11.6,16.4 12.4,19.2 0,0 -10,-29.2 -14.4,-32 0,0 8.4,-36.4 49.6,-20.8 0,0 6.8,17.2 11.2,-1.2 0,0 12.8,-6.4 24,21.2 0,0 4,-13.6 3.2,-16.4 0,0 6.8,1.2 6,0 0,0 13.2,4.4 14.4,3.6 0,0 6.8,6.8 7.2,3.2 0,0 9.2,2.8 7.2,-0.8 0,0 8.8,15.6 9.2,19.2 l 2.4,-14 2,2.8 c 0,0 1.6,-7.6 0.8,-8.8 -0.8,-1.2 20,6.8 24.8,27.6 l 2,8.4 c 0,0 6,-14.8 4.4,-18.8 0,0 5.2,0.8 5.6,5.2 0,0 4,-23.2 -0.8,-29.2 0,0 4.4,-0.8 5.6,2.8 l 0,-7.2 c 0,0 7.2,0.8 7.2,-1.6 0,0 4.4,-4 6.4,0.8 0,0 -12.4,-35.2 6,-16 0,0 7.2,10.8 3.6,-8 -3.6,-18.8 -7.6,-20.4 -2.8,-20.8 0,0 0.8,-3.6 -1.2,-5.2 -2,-1.6 1.2,0 1.2,0 0,0 4.8,4 -0.4,-18 0,0 6.4,1.6 -5.6,-27.6 0,0 2.8,-2.4 -1.2,-10.8 0,0 8,4.4 10.8,2.8 0,0 -0.4,-1.6 -3.6,-5.6 0,0 -21.6,-54.801 -1.2,-32.8 0,0 11.85,13.55 5.45,-9.25 0,0 -9.111,-24.01 -8.334,-28.306 l -429.547,23.02 z".AsSpan());
 }
Beispiel #19
0
        protected override void CalcGeometry(SvgPath elem, Vector2 trans, Vector2 scale, int slice)
        {
            elem.PathData.Clear();

            var verts = FVerticesIn[slice];
            var cont1 = FControl1In[slice];
            var cont2 = FControl2In[slice];
            var comms = FCommandIn[slice];
            var arc   = FArcRotationIn[slice];

            var coords = new List <float>(7);

            for (int i = 0; i < verts.SliceCount; i++)
            {
                coords.Clear();

                var c = comms[i][0];

                //make sure the first and last command fits the specification
                if (i == 0)
                {
                    c = 'M';
                }
                else if (i == verts.SliceCount - 1)
                {
                    c = 'Z';
                }

                //fill in params
                switch (c)
                {
                case 'm':                         // relative moveto
                case 'M':                         // moveto

                    coords.Add(verts[i].X);
                    coords.Add(verts[i].Y);
                    break;

                case 'a':
                case 'A':

                    coords.Add(cont1[i].X);
                    coords.Add(cont1[i].Y);

                    coords.Add(arc[i] * 360);

                    coords.Add(cont2[i].X);
                    coords.Add(cont2[i].Y);

                    coords.Add(verts[i].X);
                    coords.Add(verts[i].Y);

                    break;

                case 'l':                         // relative lineto
                case 'L':                         // lineto

                    coords.Add(verts[i].X);
                    coords.Add(verts[i].Y);
                    break;

                case 'H':                         // horizontal lineto
                case 'h':                         // relative horizontal lineto

                    coords.Add(verts[i].X);
                    break;

                case 'V':                         // vertical lineto
                case 'v':                         // relative vertical lineto

                    coords.Add(verts[i].Y);
                    break;

                case 'Q':                         // curveto
                case 'q':                         // relative curveto

                    coords.Add(cont1[i].X);
                    coords.Add(cont1[i].Y);

                    coords.Add(verts[i].X);
                    coords.Add(verts[i].Y);
                    break;

                case 'T':                         // shorthand/smooth curveto
                case 't':                         // relative shorthand/smooth curveto

                    coords.Add(verts[i].X);
                    coords.Add(verts[i].Y);
                    break;

                case 'C':                         // curveto
                case 'c':                         // relative curveto

                    coords.Add(cont1[i].X);
                    coords.Add(cont1[i].Y);

                    coords.Add(cont2[i].X);
                    coords.Add(cont2[i].Y);

                    coords.Add(verts[i].X);
                    coords.Add(verts[i].Y);

                    break;

                case 'S':                         // shorthand/smooth curveto
                case 's':                         // relative shorthand/smooth curveto

                    coords.Add(cont1[i].X);
                    coords.Add(cont1[i].Y);

                    coords.Add(verts[i].X);
                    coords.Add(verts[i].Y);
                    break;
                }

                SvgPathBuilder.CreatePathSegment(c, elem.PathData, coords, char.IsLower(c));
            }
        }
Beispiel #20
0
        public void DeserializeSvgXml()
        {
            var settings = DasSettings.CloneDefault();

            settings.IsPropertyNamesCaseSensitive = false;

            var srl = new DasSerializer(settings);

            var xml = GetFileContents("cog.svg");

            //var fullName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
            //    "Files",
            //    "cog.svg");

            //var fi = new FileInfo(fullName);

            var res = srl.FromXml <SvgDocument>(xml);

            var bldr = new SvgPathBuilder(new TestImageProvider(), srl);

            //var bob = SvgPathBuilder.Parse(res.Path.D);
            var bob = bldr.Parse(res);

            var gpath = new GdiGraphicsPath();

            gpath.Path.FillMode = FillMode.Winding;
            bob.AddToPath(gpath);

            //using (var bmp = new Bitmap(200, 200))
            using (var bmp = new Bitmap(48, 48))
            {
                var path = gpath.Path;

                //var pBounds = path.GetBounds();
                var scaleX = bmp.Width / (Single)res.Width;
                var scaleY = bmp.Height / (Single)res.Height;

                Matrix m = new Matrix();
                m.Scale(scaleX, scaleY, MatrixOrder.Append);
                //m.Translate(offsetX, offsetY, MatrixOrder.Append);
                path.Transform(m);

                //using (var g = Graphics.FromImage(bmp))
                using (var g = bmp.GetSmoothGraphics())
                {
                    g.SmoothingMode     = SmoothingMode.HighQuality;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.PixelOffsetMode   = PixelOffsetMode.HighQuality;

                    g.Clear(Color.AliceBlue);
                    g.FillPath(Brushes.Black, gpath.Path);

                    //gpath.Path.Transform();
                    g.DrawPath(Pens.Black, gpath.Path);
                }

                bmp.Save("abcdefg.png");
            }


            Assert.NotNull(res.Path);
        }
Beispiel #21
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
            saveFileDialog.Title  = "Save";
            saveFileDialog.Filter = "SVG Image (*.svg)|*.svg | PNG Image (*.png)|*.png";
            if (saveFileDialog.ShowDialog() == true)
            {
                if (saveFileDialog.FilterIndex == 1)
                {
                    var svg = new SvgDocument();
                    svg.Width  = 1500;
                    svg.Height = 1500;

                    var group = new SvgGroup {
                        Fill = SvgPaintServer.None, Stroke = new SvgColourServer(System.Drawing.Color.Black)
                    };

                    svg.Children.Add(group);

                    foreach (var draw in this.creasePatternCanvas.Children)
                    {
                        var geometry = new Object();
                        if (draw.GetType() == typeof(Line))
                        {
                            geometry = ((Line)draw).RenderedGeometry;
                        }
                        else
                        {
                            continue;
                        }

                        var pathGeometry = PathGeometry.CreateFromGeometry((Geometry)geometry);
                        var s            = XamlWriter.Save(pathGeometry);

                        var scb            = ((SolidColorBrush)(((Line)draw).Stroke)).Color;
                        var color          = System.Drawing.Color.FromArgb(scb.A, scb.R, scb.G, scb.B);
                        var dashPatternSvg = new SvgUnitCollection();
                        var dashPattern    = ((Line)draw).StrokeDashArray;
                        for (int i = 0; i < dashPattern.Count; i++)
                        {
                            dashPatternSvg.Add(new SvgUnit((float)dashPattern[i]));
                        }

                        if (!String.IsNullOrEmpty(s))
                        {
                            var element = XElement.Parse(s);

                            var data = element.Attribute("Figures")?.Value;

                            if (!String.IsNullOrEmpty(data))
                            {
                                group.Children.Add(new SvgPath
                                {
                                    PathData        = SvgPathBuilder.Parse(data),
                                    Fill            = SvgPaintServer.None,
                                    Stroke          = new SvgColourServer(color),
                                    StrokeDashArray = dashPatternSvg
                                });
                            }
                        }
                    }

                    svg.Write(saveFileDialog.FileName, false);
                }

                if (saveFileDialog.FilterIndex == 2)
                {
                    Rect   bounds = VisualTreeHelper.GetDescendantBounds(creasePatternCanvas);
                    double dpi    = 96d;

                    RenderTargetBitmap rtb = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, dpi, dpi, System.Windows.Media.PixelFormats.Default);

                    DrawingVisual dv = new DrawingVisual();
                    using (DrawingContext dc = dv.RenderOpen())
                    {
                        VisualBrush vb = new VisualBrush(creasePatternCanvas);
                        dc.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
                    }

                    rtb.Render(dv);

                    BitmapEncoder pngEncoder = new PngBitmapEncoder();
                    pngEncoder.Frames.Add(BitmapFrame.Create(rtb));

                    try
                    {
                        System.IO.MemoryStream ms = new System.IO.MemoryStream();

                        pngEncoder.Save(ms);
                        ms.Close();

                        System.IO.File.WriteAllBytes(saveFileDialog.FileName, ms.ToArray());
                    }
                    catch (Exception err)
                    {
                        MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show(
                            err.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error
                            );
                    }
                }
            }
        }