Пример #1
0
        public static PolygonDrawable Create(SvgPolygon svgPolygon, SKRect skViewport, DrawableBase?parent, IAssetLoader assetLoader, HashSet <Uri>?references, DrawAttributes ignoreAttributes = DrawAttributes.None)
        {
            var drawable = new PolygonDrawable(assetLoader, references)
            {
                Element          = svgPolygon,
                Parent           = parent,
                IgnoreAttributes = ignoreAttributes
            };

            drawable.IsDrawable = drawable.CanDraw(svgPolygon, drawable.IgnoreAttributes) && drawable.HasFeatures(svgPolygon, drawable.IgnoreAttributes);

            if (!drawable.IsDrawable)
            {
                return(drawable);
            }

            drawable.Path = svgPolygon.Points?.ToPath(svgPolygon.FillRule, true, skViewport);
            if (drawable.Path is null || drawable.Path.IsEmpty)
            {
                drawable.IsDrawable = false;
                return(drawable);
            }

            drawable.Initialize(skViewport, references);

            return(drawable);
        }
Пример #2
0
        public polygonData(SvgPolygon svg)
        {
            style = svg.Style;
            if (style == "")
            {
                Color cColor = svg.Stroke;
                strokeColor = Convert.ToString(cColor.R) + Convert.ToString(cColor.G) + Convert.ToString(cColor.B);
                strokeWidth = svg.StrokeWidth;
                Color fColor = svg.Fill;
                fillColor = Convert.ToString(fColor.R) + Convert.ToString(fColor.G) + Convert.ToString(fColor.B);
            }
            else
            {
                //get from style attribute
                extractStyle rStyle = new extractStyle();
                rStyle.getStyle(style);
                Color sCol = ColorTranslator.FromHtml(rStyle.strokeColour);
                Color fCol = ColorTranslator.FromHtml(rStyle.fillColour);
                strokeColor = Convert.ToString(sCol.R) + Convert.ToString(sCol.G) + Convert.ToString(sCol.B);
                strokeWidth = rStyle.strokeWidth;
                fillColor   = Convert.ToString(fCol.R) + Convert.ToString(fCol.G) + Convert.ToString(fCol.B);
            }

            points = svg.Points;
            Id     = svg.Id;
        }
Пример #3
0
        public PolygonDrawable(SvgPolygon svgPolygon, SKRect skOwnerBounds, Drawable?root, Drawable?parent, Attributes ignoreAttributes = Attributes.None)
            : base(svgPolygon, root, parent)
        {
            IgnoreAttributes = ignoreAttributes;
            IsDrawable       = CanDraw(svgPolygon, IgnoreAttributes) && HasFeatures(svgPolygon, IgnoreAttributes);

            if (!IsDrawable)
            {
                return;
            }

            Path = svgPolygon.Points?.ToSKPath(svgPolygon.FillRule, true, skOwnerBounds, _disposable);
            if (Path == null || Path.IsEmpty)
            {
                IsDrawable = false;
                return;
            }

            IsAntialias = SvgPaintingExtensions.IsAntialias(svgPolygon);

            TransformedBounds = Path.Bounds;

            Transform = SvgTransformsExtensions.ToSKMatrix(svgPolygon.Transforms);

            bool canDrawFill   = true;
            bool canDrawStroke = true;

            if (SvgPaintingExtensions.IsValidFill(svgPolygon))
            {
                Fill = SvgPaintingExtensions.GetFillSKPaint(svgPolygon, TransformedBounds, ignoreAttributes, _disposable);
                if (Fill == null)
                {
                    canDrawFill = false;
                }
            }

            if (SvgPaintingExtensions.IsValidStroke(svgPolygon, TransformedBounds))
            {
                Stroke = SvgPaintingExtensions.GetStrokeSKPaint(svgPolygon, TransformedBounds, ignoreAttributes, _disposable);
                if (Stroke == null)
                {
                    canDrawStroke = false;
                }
            }

            if (canDrawFill && !canDrawStroke)
            {
                IsDrawable = false;
                return;
            }

            SvgMarkerExtensions.CreateMarkers(svgPolygon, Path, skOwnerBounds, ref MarkerDrawables, _disposable);

            // TODO: Transform _skBounds using _skMatrix.
            TransformedBounds = Transform.MapRect(TransformedBounds);
        }
Пример #4
0
        public static Polygon GetPolygon(SvgPolygon poly)
        {
            Polygon polygon = new Polygon()
            {
                Points = GetPoints(poly.Points),
                Fill   = GetBrush(poly)
            };

            return(polygon);
        }
Пример #5
0
        private void DrawBaseTypes()
        {
            var offset = _leftMargin;

            for (int i = 0; i < _classDiagram.BaseTypes.Count; i++)
            {
                var diagram     = _classDiagramSvgRenderer.RenderDiagram(_classDiagram.BaseTypes[i]);
                var diagramSize = new Size(
                    _classDiagramSvgRenderer.CalculateDiagramWidth(_classDiagram.BaseTypes[i]),
                    _classDiagramSvgRenderer.CalculateDiagramHeight(_classDiagram.BaseTypes[i]));

                var positionX = (i * 50) + offset;
                var positionY = 0;

                var translate = diagram.CreateAttribute("transform");
                translate.Value = string.Format("translate({0}, {1})", positionX.ToString("0.00", CultureInfo.InvariantCulture), positionY.ToString("0.00", CultureInfo.InvariantCulture));
                diagram["svg"]["g"].Attributes.Append(translate);

                _mainDiagram.ImportAdd((SvgElement)diagram["svg"]["g"]);

                offset += diagramSize.Width;

                var pathGraphic = new SvgGraphic(_mainDiagram);

                //line
                if (i == 0)
                {
                    var path = new SvgPath(_mainDiagram, string.Format("M{0},{1}L{0},{2}",
                                                                       (positionX + 50).ToString("0.00", CultureInfo.InvariantCulture),
                                                                       (positionY + diagramSize.Height).ToString("0.00", CultureInfo.InvariantCulture),
                                                                       _topMargin.ToString("0.00", CultureInfo.InvariantCulture)));
                    path.StrokeWidth = 1;
                    path.Stroke      = "#979797";
                    pathGraphic.Add(path);
                }

                //arrow
                var startX = positionX + 50;
                var startY = diagramSize.Height;

                var points = string.Format("{0},{1} {2},{3} {4},{3}",
                                           startX.ToString("0.00", CultureInfo.InvariantCulture),
                                           startY.ToString("0.00", CultureInfo.InvariantCulture),
                                           (startX - 5).ToString("0.00", CultureInfo.InvariantCulture),
                                           (startY + 10).ToString("0.00", CultureInfo.InvariantCulture),
                                           (startX + 5).ToString("0.00", CultureInfo.InvariantCulture));
                var arrow = new SvgPolygon(_mainDiagram, points);
                arrow.Stroke = "#979797";
                arrow.Fill   = "#FFFFFF";

                pathGraphic.Add(arrow);

                _mainDiagram.Add(pathGraphic);
            }
        }
Пример #6
0
        public static SvgPolygon ConvertDoubleToSVGPoints(double[] points)
        {
            SvgPolygon svg = new SvgPolygon {
                Points = new SvgPointCollection()
            };

            foreach (var point in points)
            {
                svg.Points.Add((int)point);
            }
            return(svg);
        }
Пример #7
0
        public static SvgPolygon ConvertFloatSVGPoints(PointF[] points)
        {
            SvgPolygon svg = new SvgPolygon {
                Points = new SvgPointCollection()
            };

            foreach (var point in points)
            {
                svg.Points.Add((int)point.X);
                svg.Points.Add((int)point.Y);
            }
            return(svg);
        }
Пример #8
0
        public void DrawPolygon(SvgPolygon svgPolygon, bool ignoreDisplay)
        {
            if (!CanDraw(svgPolygon, ignoreDisplay))
            {
                return;
            }

            _skCanvas.Save();

            var skMatrix = SkiaUtil.GetSKMatrix(svgPolygon.Transforms);

            SetTransform(skMatrix);
            SetClipPath(svgPolygon, _disposable);

            var skPaintOpacity = SetOpacity(svgPolygon, _disposable);

            var skPaintFilter = SetFilter(svgPolygon, _disposable);

            var skPath = SkiaUtil.ToSKPath(svgPolygon.Points, svgPolygon.FillRule, true, _disposable);

            if (skPath != null && !skPath.IsEmpty)
            {
                var skBounds = skPath.Bounds;

                if (SkiaUtil.IsValidFill(svgPolygon))
                {
                    var skPaint = SkiaUtil.GetFillSKPaint(svgPolygon, _skSize, skBounds, _disposable);
                    _skCanvas.DrawPath(skPath, skPaint);
                }

                if (SkiaUtil.IsValidStroke(svgPolygon))
                {
                    var skPaint = SkiaUtil.GetStrokeSKPaint(svgPolygon, _skSize, skBounds, _disposable);
                    _skCanvas.DrawPath(skPath, skPaint);
                }

                DrawMarkers(svgPolygon, skPath);
            }

            if (skPaintFilter != null)
            {
                _skCanvas.Restore();
            }

            if (skPaintOpacity != null)
            {
                _skCanvas.Restore();
            }

            _skCanvas.Restore();
        }
        public override RenderedSvg RenderColumn()
        {
            var result = base.RenderColumn();


            SvgGroup group = new SvgGroup();

            VisualLayerPresentingVM[] layers = vm.Layers.ToArray();



            for (int i = 0; i < layers.Length; i++)
            {
                VisualLayerPresentingVM lvm = layers[i];
                if (lvm.Origin.CurrentClass != null)
                {
                    ISideCurveGenerator sideCurveGenerator = SideCurveGeneratorFactory.GetGeneratorFor(lvm.Origin.CurrentClass.RightSideForm);

                    SvgPatternServer sps = lvm.Origin.CurrentClass.BackgroundPattern;
                    sps.PatternContentUnits = SvgCoordinateUnits.ObjectBoundingBox;
                    sps.PatternUnits        = SvgCoordinateUnits.UserSpaceOnUse;
                    float ratio = sps.Width.Value / 64f;
                    sps.Width  /= ratio;
                    sps.Height /= ratio;

                    SvgPolygon poly = new SvgPolygon();
                    poly.Stroke      = new SvgColourServer(System.Drawing.Color.Black);
                    poly.StrokeWidth = 1f;
                    poly.Fill        = sps;

                    var points = Drawing.GetPolygon(lvm.Width, lvm.Height, sideCurveGenerator).ToArray();

                    SvgPointCollection svgPoints = new SvgPointCollection();
                    for (int j = 0; j < points.Length; j++)
                    {
                        var point = points[j];
                        point.Y += lvm.Y;
                        AddPointToCollection(svgPoints, point);
                    }

                    poly.Points = svgPoints;

                    group.Children.Add(poly);
                }
            }

            result.SVG = group;

            return(result);
        }
        private void DrawConnectionArrow(double calledNodeMiddlePoint)
        {
            var startX = (int)calledNodeMiddlePoint;
            var startY = (int)_diagramSize.Height;

            var points = string.Format("{0},{1} {2},{3} {2},{4}", startX, startY, startX - 5, startY - 5, startY + 5);
            var arrow  = new SvgPolygon(_svgRoot, points);

            arrow.Stroke = arrow.Fill = "#979797";

            _svgGraphic.Add(arrow);

            _diagramSize.Height += ROWOFFSET;
        }
Пример #11
0
        void CreateArrowEnd()
        {
            SvgMarker arrowEnd = this.doc.AddMarker();

            arrowEnd.RefX         = $"{this.ToPx(ArrowEndSize)}";
            arrowEnd.RefY         = $"{this.ToPx(ArrowEndSize / 2)}";
            arrowEnd.MarkerWidth  = $"{this.ToPx(ArrowEndSize)}";
            arrowEnd.MarkerHeight = $"{this.ToPx(ArrowEndSize)}";
            arrowEnd.MarkerUnits  = "px";
            arrowEnd.Id           = ArrowEnd;

            SvgPolygon p = this.doc.AddPolygon(arrowEnd);

            p.Class  = "connector";
            p.Points = $"0 0 {this.ToPx(ArrowEndSize)} {this.ToPx(ArrowEndSize / 2)} 0 {this.ToPx(ArrowEndSize)}";
        }
Пример #12
0
        private void AddPolygon()
        {
            if (!IsDocPresent())
            {
                return;
            }

            SvgElement ele = GetCurrentSvgElement();

            if (ele == null)
            {
                return;
            }

            SvgPolygon poly = m_svg.AddPolygon(ele);

            AddNodeToTree(poly);
        }
Пример #13
0
        void CreateArrowEnd()
        {
            SvgMarker arrowEnd = this.doc.AddMarker();

            arrowEnd.RefX         = $"{this.ToPx(ArrowEndSize)}";
            arrowEnd.RefY         = $"{this.ToPx(ArrowEndSize / 2)}";
            arrowEnd.MarkerWidth  = $"{this.ToPx(ArrowEndSize)}";
            arrowEnd.MarkerHeight = $"{this.ToPx(ArrowEndSize)}";
            arrowEnd.MarkerUnits  = "px";
            arrowEnd.Id           = ArrowEnd;

            SvgPolygon p = this.doc.AddPolygon(arrowEnd);

            p.Points      = $"0 0 {this.ToPx(ArrowEndSize)} {this.ToPx(ArrowEndSize / 2)} 0 {this.ToPx(ArrowEndSize)}";
            p.StrokeWidth = "0";
            p.Fill        = Color.Black;
            p.StrokeWidth = "0";
        }
Пример #14
0
        public override SvgBasicShape ToSVGLibShape(SvgDoc doc)
        {
            String pointsStr = "";

            foreach (var point in points)
            {
                pointsStr += point.X + "," + point.Y + " ";
            }

            var res = new SvgPolygon(doc,
                                     pointsStr
                                     );

            res.Fill        = System.Drawing.Color.FromArgb(fill.A, fill.R, fill.G, fill.B);
            res.Stroke      = System.Drawing.Color.FromArgb(stroke.A, stroke.R, stroke.G, stroke.B);
            res.StrokeWidth = w.ToString() + "px";
            return(res);
        }
Пример #15
0
        public void DrawPolygon(SvgDocument SvgDocument, PointF[] vertices, Color c)
        {
            SvgPointCollection points = new SvgPointCollection();

            foreach (PointF p in vertices)
            {
                points.Add(new SvgUnit(p.X));
                points.Add(new SvgUnit(p.Y));
            }

            SvgPolygon SvgPolygon = new SvgPolygon()
            {
                Points      = points,
                Fill        = new SvgColourServer(c),
                StrokeWidth = 0
            };

            SvgDocument.Children.Add(SvgPolygon);
        }
Пример #16
0
 public static DrawableBase?Create(SvgElement svgElement, Rect skOwnerBounds, DrawableBase?parent, IAssetLoader assetLoader, Attributes ignoreAttributes = Attributes.None)
 {
     return(svgElement switch
     {
         SvgAnchor svgAnchor => AnchorDrawable.Create(svgAnchor, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         SvgFragment svgFragment => FragmentDrawable.Create(svgFragment, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         SvgImage svgImage => ImageDrawable.Create(svgImage, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         SvgSwitch svgSwitch => SwitchDrawable.Create(svgSwitch, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         SvgUse svgUse => UseDrawable.Create(svgUse, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         SvgCircle svgCircle => CircleDrawable.Create(svgCircle, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         SvgEllipse svgEllipse => EllipseDrawable.Create(svgEllipse, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         SvgRectangle svgRectangle => RectangleDrawable.Create(svgRectangle, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         SvgGroup svgGroup => GroupDrawable.Create(svgGroup, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         SvgLine svgLine => LineDrawable.Create(svgLine, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         SvgPath svgPath => PathDrawable.Create(svgPath, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         SvgPolyline svgPolyline => PolylineDrawable.Create(svgPolyline, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         SvgPolygon svgPolygon => PolygonDrawable.Create(svgPolygon, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         SvgText svgText => TextDrawable.Create(svgText, skOwnerBounds, parent, assetLoader, ignoreAttributes),
         _ => null,
     });
Пример #17
0
 public static Drawable?Create(SvgElement svgElement, SKRect skOwnerBounds, Drawable?root, Drawable?parent, Attributes ignoreAttributes = Attributes.None)
 {
     return(svgElement switch
     {
         SvgAnchor svgAnchor => new AnchorDrawable(svgAnchor, skOwnerBounds, root, parent, ignoreAttributes),
         SvgFragment svgFragment => new FragmentDrawable(svgFragment, skOwnerBounds, root, parent, ignoreAttributes),
         SvgImage svgImage => new ImageDrawable(svgImage, skOwnerBounds, root, parent, ignoreAttributes),
         SvgSwitch svgSwitch => new SwitchDrawable(svgSwitch, skOwnerBounds, root, parent, ignoreAttributes),
         SvgUse svgUse => new UseDrawable(svgUse, skOwnerBounds, root, parent, ignoreAttributes),
         SvgCircle svgCircle => new CircleDrawable(svgCircle, skOwnerBounds, root, parent, ignoreAttributes),
         SvgEllipse svgEllipse => new EllipseDrawable(svgEllipse, skOwnerBounds, root, parent, ignoreAttributes),
         SvgRectangle svgRectangle => new RectangleDrawable(svgRectangle, skOwnerBounds, root, parent, ignoreAttributes),
         SvgGroup svgGroup => new GroupDrawable(svgGroup, skOwnerBounds, root, parent, ignoreAttributes),
         SvgLine svgLine => new LineDrawable(svgLine, skOwnerBounds, root, parent, ignoreAttributes),
         SvgPath svgPath => new PathDrawable(svgPath, skOwnerBounds, root, parent, ignoreAttributes),
         SvgPolyline svgPolyline => new PolylineDrawable(svgPolyline, skOwnerBounds, root, parent, ignoreAttributes),
         SvgPolygon svgPolygon => new PolygonDrawable(svgPolygon, skOwnerBounds, root, parent, ignoreAttributes),
         SvgText svgText => new TextDrawable(svgText, skOwnerBounds, root, parent, ignoreAttributes),
         _ => null,
     });
        private void DrawReturnConnection(SequenceDiagramConnection connection)
        {
            var callerNodeMiddlePoint = _nodeMiddlePoints[connection.CallerId];
            var calledNodeMiddlePoint = connection.CalledId == Guid.Empty ? 0 : _nodeMiddlePoints[connection.CalledId];

            var textWidth = ("return " + connection.Text).GetWidth(12, Fonts.FontLight);
            var text      = new SvgText(_svgRoot, "return " + connection.Text, calledNodeMiddlePoint + 10, _diagramSize.Height + 10);

            text.FontSize = 12;
            _svgGraphic.Add(text);

            if ((textWidth + calledNodeMiddlePoint + 10) > _diagramSize.Width)
            {
                _diagramSize.Width = textWidth + calledNodeMiddlePoint + 20;
            }

            var path = new SvgPath(_svgRoot, string.Format("M{0},{1}L{2},{1}",
                                                           calledNodeMiddlePoint.ToString("0.00", CultureInfo.InvariantCulture),
                                                           (_diagramSize.Height + 20).ToString("0.00", CultureInfo.InvariantCulture),
                                                           callerNodeMiddlePoint.ToString("0.00", CultureInfo.InvariantCulture)));

            path.StrokeWidth = 1;
            path.Stroke      = "#979797";
            _svgGraphic.Add(path);

            var startX = (int)calledNodeMiddlePoint;
            var startY = (int)_diagramSize.Height + 20;

            var points = string.Format("{0},{1} {2},{3} {2},{4}", startX, startY, startX + 5, startY + 5, startY - 5);
            var arrow  = new SvgPolygon(_svgRoot, points);

            arrow.Stroke = arrow.Fill = "#979797";

            _svgGraphic.Add(arrow);

            _diagramSize.Height += 35;
        }
Пример #19
0
        void ParseSvgElement(SvgElement el)
        {
            VectorPath path = null;

            if (el is SvgPolygon)
            {
                SvgPolygon p = (SvgPolygon)el;
                path = CreatePath();

                int len = p.Points.Count;

                if (len % 2 != 0)
                {
                    len--;
                }

                for (int i = 0; i < len; i += 2)
                {
                    float x, y;

                    x = p.Points[i].Value / ppmx;
                    y = p.Points[i + 1].Value / ppmy;

                    if (i == 0)
                    {
                        path.MoveTo(x, y);
                    }
                    else
                    {
                        path.LineTo(x, y);
                    }
                }

                path.ClosePolygon();
            }

            if (el is SvgPath)
            {
                SvgPath p = (SvgPath)el;
                path = CreatePath();

                foreach (SvgElement e in p.Children)
                {
                    if (e is SvgTitle)
                    {
                        SvgTitle title = (SvgTitle)e;
                        path.Title = title.Content;
                    }
                }

                string tag, side;

                tag  = "";
                side = "";
                string guidStr = "";

                path.Side = VectorPathSide.None;

                if (p.TryGetAttribute("gf-tag", out tag))
                {
                    path.Tag = Encoding.UTF8.GetString(Convert.FromBase64String(tag));
                }

                try
                {
                    if (p.TryGetAttribute("gf-guid", out guidStr))
                    {
                        path.Guid = new Guid(guidStr);
                    }
                }
                catch
                {
                }

                if (p.TryGetAttribute("gf-side", out side))
                {
                    if (side == "left")
                    {
                        path.Side = VectorPathSide.Left;
                    }

                    if (side == "right")
                    {
                        path.Side = VectorPathSide.Right;
                    }
                }

                if (p.TryGetAttribute("gf-nome-peca", out string nomePeca))
                {
                    path.NomePeca = "";
                    try
                    {
                        path.NomePeca = Encoding.UTF8.GetString(Convert.FromBase64String(nomePeca));
                    }
                    catch
                    {
                    }
                }

                path.ForceAngle = false;
                string force = "";

                if (p.TryGetAttribute("gf-forceAngle", out force))
                {
                    bool pf = false;

                    if (bool.TryParse(force, out pf))
                    {
                        path.ForceAngle = pf;
                    }
                }

                float sx, sy, ex, ey;

                foreach (SvgPathSegment seg in p.PathData)
                {
                    sx = (seg.Start.X / ppmx);
                    sy = (seg.Start.Y / ppmy);
                    ex = (seg.End.X / ppmx);
                    ey = (seg.End.Y / ppmy);

                    if (seg is SvgLineSegment)
                    {
                        path.LineTo(ex, ey);
                    }
                    else if (seg is SvgCubicCurveSegment)
                    {
                        SvgCubicCurveSegment q = (SvgCubicCurveSegment)seg;
                        path.CurveTo(ex, ey, (q.FirstControlPoint.X / ppmx), (q.FirstControlPoint.Y / ppmy), (q.SecondControlPoint.X / ppmx), (q.SecondControlPoint.Y / ppmy));
                    }
                    else if (seg is SvgQuadraticCurveSegment)
                    {
                        SvgQuadraticCurveSegment q = (SvgQuadraticCurveSegment)seg;
                        path.QCurveTo(ex, ey, (q.ControlPoint.X / ppmx), (q.ControlPoint.Y / ppmy));
                    }
                    else if (seg is SvgClosePathSegment)
                    {
                        path.ClosePolygon();
                    }
                    else if (seg is SvgMoveToSegment)
                    {
                        path.MoveTo(ex, ey);
                    }
                    else
                    {
                    }
                }
            }
            else
            {
            }

            if (path != null)
            {
                path.ClosePath();
            }

            foreach (SvgElement n in el.Children)
            {
                ParseSvgElement(n);
            }
        }
Пример #20
0
 void AddPoint(SvgPolygon polygon, PointF point)
 {
     polygon.Points.Add(point.X);
     polygon.Points.Add(point.Y);
 }
Пример #21
0
 public Polygon(SvgPolygon svgPolygon)
 {
     matrix = SvgHelper.GetSKMatrix(svgPolygon.Transforms);
 }
Пример #22
0
        public string Draw(int width, int height)
        {
            //var b = new Bitmap(width, height);

            var hexWidth  = Math.Floor((double)(width / (Columns * 1.75)));
            var hexHeight = Math.Floor((double)(height / (Rows + 1))) * 2;

            hexWidth = hexHeight = Math.Min(hexWidth, hexHeight);

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

            var group = new SvgGroup();

            svgDoc.Children.Add(group);

            for (var r = 0; r < Hexes.GetLength(0); r++)
            {
                for (var q = 0; q < Hexes.GetLength(1); q++)
                {
                    int offsetRow = !(r % 2 == 0) ? 1 : 0;

                    var originX = (q * hexWidth * 1.5) + (hexWidth / 2) + (offsetRow * hexWidth * 0.75);
                    var originY = (r * hexHeight / 2) + (hexHeight / 2);

                    var ax = originX - (hexWidth / 4);
                    var ay = originY - (hexHeight / 2);

                    var bx = originX + (hexWidth / 4);
                    var by = originY - (hexHeight / 2);

                    var cx = originX + (hexWidth / 2);
                    var cy = originY;

                    var dx = originX + (hexWidth / 4);
                    var dy = originY + (hexHeight / 2);

                    var ex = originX - (hexWidth / 4);
                    var ey = originY + (hexHeight / 2);

                    var fx = originX - (hexWidth / 2);
                    var fy = originY;

                    var p = new SvgPolygon();

                    p.Points = new SvgPointCollection();


                    p.Points.Add(new SvgUnit((float)ax));
                    p.Points.Add(new SvgUnit((float)ay));

                    p.Points.Add(new SvgUnit((float)bx));
                    p.Points.Add(new SvgUnit((float)by));

                    p.Points.Add(new SvgUnit((float)cx));
                    p.Points.Add(new SvgUnit((float)cy));

                    p.Points.Add(new SvgUnit((float)dx));
                    p.Points.Add(new SvgUnit((float)dy));

                    p.Points.Add(new SvgUnit((float)ex));
                    p.Points.Add(new SvgUnit((float)ey));

                    p.Points.Add(new SvgUnit((float)fx));
                    p.Points.Add(new SvgUnit((float)fy));

                    p.Stroke = new SvgColourServer(Color.Black);
                    p.Fill   = new SvgColourServer(r % 2 == 0 ? Color.White : Color.AliceBlue);

                    group.Children.Add(p);

                    //DrawLine(b, ax, ay, bx, by);
                    //DrawLine(b, bx, by, cx, cy);
                    //DrawLine(b, cx, cy, dx, dy);
                    //DrawLine(b, dx, dy, ex, ey);
                    //DrawLine(b, ex, ey, fx, fy);
                    //DrawLine(b, fx, fy, ax, ay);

                    //DrawText(b, ax, ay, q, r);
                }
            }

            //b.Save(@"c:\temp\output.jpg");
            //svgDoc.Write(@"c:\temp\output.svg");


            using (var stream = new MemoryStream())
            {
                svgDoc.Write(stream);
                return(Encoding.UTF8.GetString(stream.GetBuffer()));
            }
        }
Пример #23
0
        public static PolygonDrawable Create(SvgPolygon svgPolygon, Rect skOwnerBounds, DrawableBase?parent, IAssetLoader assetLoader, Attributes ignoreAttributes = Attributes.None)
        {
            var drawable = new PolygonDrawable(assetLoader)
            {
                Element          = svgPolygon,
                Parent           = parent,
                IgnoreAttributes = ignoreAttributes
            };

            drawable.IsDrawable = drawable.CanDraw(svgPolygon, drawable.IgnoreAttributes) && drawable.HasFeatures(svgPolygon, drawable.IgnoreAttributes);

            if (!drawable.IsDrawable)
            {
                return(drawable);
            }

            drawable.Path = svgPolygon.Points?.ToPath(svgPolygon.FillRule, true, skOwnerBounds);
            if (drawable.Path is null || drawable.Path.IsEmpty)
            {
                drawable.IsDrawable = false;
                return(drawable);
            }

            drawable.IsAntialias = SvgModelExtensions.IsAntialias(svgPolygon);

            drawable.TransformedBounds = drawable.Path.Bounds;

            drawable.Transform = SvgModelExtensions.ToMatrix(svgPolygon.Transforms);

            var canDrawFill   = true;
            var canDrawStroke = true;

            if (SvgModelExtensions.IsValidFill(svgPolygon))
            {
                drawable.Fill = SvgModelExtensions.GetFillPaint(svgPolygon, drawable.TransformedBounds, assetLoader, ignoreAttributes);
                if (drawable.Fill is null)
                {
                    canDrawFill = false;
                }
            }

            if (SvgModelExtensions.IsValidStroke(svgPolygon, drawable.TransformedBounds))
            {
                drawable.Stroke = SvgModelExtensions.GetStrokePaint(svgPolygon, drawable.TransformedBounds, assetLoader, ignoreAttributes);
                if (drawable.Stroke is null)
                {
                    canDrawStroke = false;
                }
            }

            if (canDrawFill && !canDrawStroke)
            {
                drawable.IsDrawable = false;
                return(drawable);
            }

            SvgModelExtensions.CreateMarkers(svgPolygon, drawable.Path, skOwnerBounds, drawable, assetLoader);

            // TODO: Transform _skBounds using _skMatrix.
            drawable.TransformedBounds = drawable.Transform.MapRect(drawable.TransformedBounds);

            return(drawable);
        }
        public override RenderedSvg RenderColumn()
        {
            var result = base.RenderColumn();


            SvgGroup group = new SvgGroup();

            VisualLayerPresentingVM[] layers = vm.Layers.ToArray();



            for (int i = 0; i < layers.Length; i++)
            {
                VisualLayerPresentingVM lvm = layers[i];
                SvgGroup levelGroup         = new SvgGroup();
                if (lvm.BackgroundClass.CurrentClass != null)
                {
                    ISideCurveGenerator rightSideCurveGenerator = null;
                    if ((lvm.RightSideClass != null) && (lvm.RightSideClass.CurrentClass != null))
                    {
                        rightSideCurveGenerator = SideCurveGeneratorFactory.GetGeneratorFor(lvm.RightSideClass.CurrentClass.RightSideForm);
                    }
                    else
                    {
                        rightSideCurveGenerator = SideCurveGeneratorFactory.GetGeneratorFor(AnnotationPlane.Template.RightSideFormEnum.NotDefined);
                    }

                    SvgPolyline rightEdge = new SvgPolyline
                    {
                        Stroke      = new SvgColourServer(System.Drawing.Color.Black),
                        StrokeWidth = 1f
                    };

                    var rightPoints = Drawing.GetRightPolyline(lvm.Width, lvm.Height, rightSideCurveGenerator).ToArray();

                    SvgPointCollection svgPoints = new SvgPointCollection();
                    for (int j = 0; j < rightPoints.Length; j++)
                    {
                        var point = rightPoints[j];
                        point.Y += lvm.Y;
                        AddPointToCollection(svgPoints, point);
                    }

                    rightEdge.Points = svgPoints;

                    levelGroup.Children.Add(rightEdge);


                    ISideCurveGenerator bottomSideCurveGenerator = null;
                    if ((lvm.BottomSideClass != null) && (lvm.BottomSideClass.CurrentClass != null))
                    {
                        bottomSideCurveGenerator = SideCurveGeneratorFactory.GetGeneratorFor(lvm.BottomSideClass.CurrentClass.BottomSideForm);
                    }
                    else
                    {
                        bottomSideCurveGenerator = SideCurveGeneratorFactory.GetGeneratorFor(AnnotationPlane.Template.BottomSideFormEnum.NotDefined);
                    }

                    SvgPolyline bottomEdge = new SvgPolyline
                    {
                        Stroke        = new SvgColourServer(System.Drawing.Color.Black),
                        StrokeLineCap = SvgStrokeLineCap.Round,
                        StrokeWidth   = 1f
                    };
                    if (lvm.BottomSideClass.CurrentClass != null)
                    {
                        if (lvm.BottomSideClass.CurrentClass.BottomSideForm == AnnotationPlane.Template.BottomSideFormEnum.Dotted)
                        {
                            bottomEdge.StrokeDashArray = new List <float>()
                            {
                                3, 3
                            }.
                            Select(p => new SvgUnit(p)) as SvgUnitCollection;
                        }
                    }

                    var bottomPoints = Drawing.GetBottomPolyline(lvm.Width, lvm.Height, bottomSideCurveGenerator).ToArray();

                    SvgPointCollection svgBottomPoints = new SvgPointCollection();
                    for (int j = 0; j < bottomPoints.Length; j++)
                    {
                        var point = bottomPoints[j];
                        point.Y += lvm.Y;
                        AddPointToCollection(svgBottomPoints, point);
                    }

                    bottomEdge.Points = svgBottomPoints;

                    levelGroup.Children.Add(bottomEdge);


                    SvgPolygon bckgrPolygon = new SvgPolygon
                    {
                        StrokeWidth = 0f
                    };

                    SvgPatternServer sps = lvm.BackgroundClass.CurrentClass.BackgroundPattern;
                    sps.PatternContentUnits = SvgCoordinateUnits.ObjectBoundingBox;
                    sps.PatternUnits        = SvgCoordinateUnits.UserSpaceOnUse;
                    float ratio = sps.Width.Value / 64f;
                    sps.Width  /= ratio;
                    sps.Height /= ratio;

                    bckgrPolygon.Fill = sps;

                    var bckgrPoints = Drawing.GetBackgroundPolyline(lvm.Width, lvm.Height, rightSideCurveGenerator).ToArray();

                    SvgPointCollection svgBckgrPoints = new SvgPointCollection();
                    for (int j = 0; j < bckgrPoints.Length; j++)
                    {
                        var point = bckgrPoints[j];
                        point.Y += lvm.Y;
                        AddPointToCollection(svgBckgrPoints, point);
                    }

                    bckgrPolygon.Points = svgBckgrPoints;

                    levelGroup.Children.Add(bckgrPolygon);


                    group.Children.Add(levelGroup);
                }
            }

            result.SVG = group;

            return(result);
        }