Esempio n. 1
0
 public LineType(System.Drawing.Color pColor, float pWidth, float pOpacity, SvgUnitCollection pDashArray)
 {
     color     = pColor;
     width     = pWidth;
     opacity   = pOpacity;
     dashArray = pDashArray;
 }
Esempio n. 2
0
        private SvgUnitCollection createUnitCollection(params SvgUnit[] p)
        {
            var c = new SvgUnitCollection();

            c.AddRange(p);
            return(c);
        }
        private static SvgUnitCollection MapLineType(LineType lineType)
        {
            var results = new SvgUnitCollection();

            switch (lineType)
            {
            case LineType.Dashed:
                results.AddRange(new[] { new SvgUnit(SvgUnitType.User, 5), new SvgUnit(SvgUnitType.User, 5) });
                break;

            case LineType.DotDash:
                results.AddRange(new[]
                {
                    new SvgUnit(SvgUnitType.User, 5),
                    new SvgUnit(SvgUnitType.User, 5),
                    new SvgUnit(SvgUnitType.User, 1),
                    new SvgUnit(SvgUnitType.User, 5)
                });
                break;

            case LineType.Dotted:
                results.AddRange(new[] { new SvgUnit(SvgUnitType.User, 1), new SvgUnit(SvgUnitType.User, 5) });
                break;

            case LineType.LongDash:
                results.AddRange(new[] { new SvgUnit(SvgUnitType.User, 10), new SvgUnit(SvgUnitType.User, 5) });
                break;

            case LineType.TwoDash:
                results.AddRange(new[] { new SvgUnit(SvgUnitType.User, 1), new SvgUnit(SvgUnitType.User, 5) });
                break;
            }

            return(results);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets 100th part of inch * <c>val</c>
        /// </summary>
        /// <param name="val">The value.</param>
        /// <returns></returns>
        public static SvgUnitCollection Get_ci(this Int32 val)
        {
            SvgUnit           svgUnit           = new SvgUnit(SvgUnitType.Inch, val / 100);
            SvgUnitCollection svgUnitCollection = new SvgUnitCollection();

            svgUnitCollection.Add(svgUnit);
            return(svgUnitCollection);
        }
Esempio n. 5
0
        public static SvgUnitCollection Get_mm(this Int32 val)
        {
            SvgUnit           svgUnit           = new SvgUnit(SvgUnitType.Millimeter, val);
            SvgUnitCollection svgUnitCollection = new SvgUnitCollection();

            svgUnitCollection.Add(svgUnit);
            return(svgUnitCollection);
        }
Esempio n. 6
0
        public static SvgUnitCollection Get_px(this Int32 val)
        {
            SvgUnit           svgUnit           = new SvgUnit(SvgUnitType.Pixel, val);
            SvgUnitCollection svgUnitCollection = new SvgUnitCollection();

            svgUnitCollection.Add(svgUnit);
            return(svgUnitCollection);
        }
Esempio n. 7
0
        protected override void InitializeDocument()
        {
            Document = new SvgDocument();

            if (!string.IsNullOrEmpty(Layout.LayoutName))
                Document.CustomAttributes.Add("LayoutName", Layout.LayoutName);

            LayoutBounds = Layout.GetLayoutBounds();

            Document.X = new SvgUnit(0);
            Document.Y = new SvgUnit(0);
            Document.Width = GetDocumentUnit(LayoutBounds.Width);
            Document.Height = GetDocumentUnit(LayoutBounds.Height);

            if (Options.InkscapeCompatible)
            {
                Document.CustomAttributes.Add("xmlns:inkscape", "http://www.inkscape.org/namespaces/inkscape");
                //The Svg library serializes the viewbox with comma and space, but this combination is not handled by the Inkscape DXF exporter
                Document.CustomAttributes.Add("viewBox",
                    string.Format(NumberFormatInfo.InvariantInfo, "0,0,{0},{1}",
                    LayoutBounds.Width[Options.ExportUnit].DoubleValue,
                    LayoutBounds.Height[Options.ExportUnit].DoubleValue));
            }
            else
            {
                Document.ViewBox = new SvgViewBox(0, 0, Document.Width, Document.Height);
            }

            OriginOffset = new PointM(LayoutBounds.Location.X * -1, LayoutBounds.Location.Y);
            OriginOffestVec = OriginOffset.ToVector(Options.ExportUnit);

            LineDashPattern = new SvgUnitCollection
            {
                GetRelativeUnit(6, SvgUnitType.Point),
                GetRelativeUnit(4, SvgUnitType.Point),
                GetRelativeUnit(2, SvgUnitType.Point),
                GetRelativeUnit(4, SvgUnitType.Point)
            };
        }
        private static SvgUnitCollection MapLineType(LineType lineType)
        {
            var results = new SvgUnitCollection();

            switch (lineType)
            {
                case LineType.Dashed:
                    results.AddRange(new[] { new SvgUnit(SvgUnitType.User, 5), new SvgUnit(SvgUnitType.User, 5) });
                    break;
                case LineType.DotDash:
                    results.AddRange(new[]
                    {
                        new SvgUnit( SvgUnitType.User, 5 ),
                        new SvgUnit( SvgUnitType.User, 5 ),
                        new SvgUnit( SvgUnitType.User, 1 ),
                        new SvgUnit( SvgUnitType.User, 5 )
                    });
                    break;
                case LineType.Dotted:
                    results.AddRange(new[] { new SvgUnit(SvgUnitType.User, 1), new SvgUnit(SvgUnitType.User, 5) });
                    break;
                case LineType.LongDash:
                    results.AddRange(new[] { new SvgUnit(SvgUnitType.User, 10), new SvgUnit(SvgUnitType.User, 5) });
                    break;
                case LineType.TwoDash:
                    results.AddRange(new[] { new SvgUnit(SvgUnitType.User, 1), new SvgUnit(SvgUnitType.User, 5) });
                    break;
            }

            return results;
        }
 private SvgUnitCollection createUnitCollection(params SvgUnit[] p)
 {
     var c = new SvgUnitCollection();
     c.AddRange(p);
     return c;
 }
Esempio n. 10
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
                            );
                    }
                }
            }
        }
Esempio n. 11
0
 private SvgLine CreateSvgLine(SvgElement owner, PointM p1, PointM p2, SvgUnit stroke, Color color, SvgUnitCollection dashPattern)
 {
     var svgLine = new SvgLine()
     {
         StartX = GetRelativeUnit(p1.X + OriginOffset.X),
         StartY = GetRelativeUnit(p1.Y * -1 + OriginOffset.Y),
         EndX = GetRelativeUnit(p2.X + OriginOffset.X),
         EndY = GetRelativeUnit(p2.Y * -1 + OriginOffset.Y),
         StrokeWidth = stroke,
         Stroke = new SvgColourServer(color),
         StrokeDashArray = dashPattern
     };
     if (owner != null)
         owner.Children.Add(svgLine);
     return svgLine;
 }
Esempio n. 12
0
        public void DrawMapSvg([ItemCanBeNull][NotNull] List <MapPoint> wgsmapPointsWithNull,
                               [NotNull] string fileName,
                               [ItemNotNull][NotNull] List <MapLegendEntry> plegendEntries)
        {
            var legendEntries = plegendEntries.ToList();

            if (wgsmapPointsWithNull.Count == 0)
            {
                throw new FlaException("not a single mappoint was given");
            }

            var mapPointTypes = wgsmapPointsWithNull.Where(x => x != null).Select(x => x.Mode).Distinct().ToList();

            if (mapPointTypes.Count != 1)
            {
                throw new FlaException("different types of map points.");
            }

            var mapPoints = wgsmapPointsWithNull.Where(x => x != null).Select(x => x.ConvertToSwissMapPoint()).ToList();
            var xmin      = mapPoints.Min(x => x.X);
            var ymin      = mapPoints.Min(x => x.Y);
            var xmax      = mapPoints.Max(x => x.X);
            var ymax      = mapPoints.Max(x => x.Y);

            // ReSharper disable twice PossibleInvalidOperationException
            const int coordfactor = 1;
            var       width       = (int)((xmax.Value - xmin.Value) * coordfactor);
            // ReSharper disable twice PossibleInvalidOperationException
            var height = (int)((ymax.Value - ymin.Value) * coordfactor);
            var min    = mapPoints.Min(x => x.Value);
            var max    = mapPoints.Max(x => x.Value);
            var spread = max - min;

            if (spread < 1)
            {
                spread = 1;
            }

            var factor = 255 / spread;


            var doc = new SvgDocument {
                Width   = width,
                Height  = height,
                ViewBox = new SvgViewBox(0, 0, width, height)
            };

            var group = new SvgGroup();

            doc.Children.Add(group);
            var legendY = 100;

            foreach (var entry in legendEntries)
            {
                SvgText c = new SvgText(entry.Name)
                {
                    Color    = new SvgColourServer(Color.FromArgb(entry.R, entry.G, entry.B)),
                    FontSize = 100,
                    Fill     = new SvgColourServer(Color.FromArgb(entry.R, entry.G, entry.B))
                };
                var svgux = new SvgUnitCollection {
                    new SvgUnit(100)
                };
                c.X = svgux;
                var svguy = new SvgUnitCollection {
                    new SvgUnit(legendY)
                };
                c.Y      = svguy;
                c.Y      = svguy;
                legendY += 100;
                group.Children.Add(c);
            }

            var messedUpPoints = 0;

            foreach (var mapPoint in mapPoints)
            {
                if (mapPoint.X == null)
                {
                    Error("Mappoint with x == null #" + messedUpPoints);
                    messedUpPoints++;
                    continue;
                }

                if (mapPoint.Y == null)
                {
                    Error("Mappoint with y == null #" + messedUpPoints);
                    messedUpPoints++;
                    continue;
                }

                var c = new SvgCircle {
                    CenterX = mapPoint.AdjustedX(xmin, width, coordfactor, false),
                    CenterY = mapPoint.AdjustedY(ymin, height, coordfactor),
                    Radius  = mapPoint.Radius
                };
                var   red = (mapPoint.Value - min) * factor;
                Color col;
                if (mapPoint.Mode == MapPointMode.DotAbsoluteColor)
                {
                    col = Color.FromArgb(255, mapPoint.R, mapPoint.G, mapPoint.B);
                }
                else
                {
                    col = Color.FromArgb(255, (byte)red, 0, 0);
                }

                c.Fill        = new SvgColourServer(col);
                c.Stroke      = new SvgColourServer(col);
                c.StrokeWidth = 1;
                group.Children.Add(c);
            }

            using (var stream = new FileStream(fileName, FileMode.Create)) {
                Debug("Wrote svg map to " + fileName);
                doc.Write(stream);
            }

            //var bitmap = doc.Draw();
            //string pngfileName = fileName.Replace(".svg", ".png");
            //bitmap.Save(pngfileName, ImageFormat.Png);
        }