public override RenderedSvg RenderColumn() { RenderedSvg result = base.RenderColumn(); SvgGroup group = new SvgGroup(); for (int i = 0; i < vm.Samples.Length; i++) { SampleVM sample = vm.Samples[i]; //sample circle sign SvgCircle circle = new SvgCircle(); circle.CenterX = Helpers.dtos(circleXoffset); circle.CenterY = Helpers.dtos(sample.Level); circle.Radius = Helpers.dtos(circleRadius); circle.Stroke = blackPaint; group.Children.Add(circle); //sample depth label SvgText depthText = new SvgText(string.Format("{0:0.##} м", sample.Depth)); depthText.Transforms.Add(new Svg.Transforms.SvgTranslate(textXoffset, (float)(sample.Level + 2.0 * circleRadius + textFontSize * 0.5))); depthText.Fill = blackPaint; depthText.FontSize = Helpers.dtos(textFontSize); group.Children.Add(depthText); //sample comment SvgText commentText = new SvgText(sample.Comment); commentText.Transforms.Add(new Svg.Transforms.SvgTranslate(textXoffset, (float)(sample.Level + 2.0 * circleRadius + textFontSize * 1.5))); commentText.Fill = blackPaint; commentText.FontSize = Helpers.dtos(textFontSize); group.Children.Add(commentText); } result.SVG = group; return(result); }
public static CircleDrawable Create(SvgCircle svgCircle, SKRect skViewport, DrawableBase?parent, IAssetLoader assetLoader, HashSet <Uri>?references, DrawAttributes ignoreAttributes = DrawAttributes.None) { var drawable = new CircleDrawable(assetLoader, references) { Element = svgCircle, Parent = parent, IgnoreAttributes = ignoreAttributes }; drawable.IsDrawable = drawable.CanDraw(svgCircle, drawable.IgnoreAttributes) && drawable.HasFeatures(svgCircle, drawable.IgnoreAttributes); if (!drawable.IsDrawable) { return(drawable); } drawable.Path = svgCircle.ToPath(svgCircle.FillRule, skViewport); if (drawable.Path is null || drawable.Path.IsEmpty) { drawable.IsDrawable = false; return(drawable); } drawable.Initialize(references); return(drawable); }
public circleData(SvgCircle 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); } radius = Convert.ToDouble(svg.R); xpos = Convert.ToDouble(svg.CX); ypos = Convert.ToDouble(svg.CY); Id = svg.Id; }
public Circle(SvgCircle svgCircle) { cx = svgCircle.CenterX.ToDeviceValue(null, UnitRenderingType.Horizontal, svgCircle); cy = svgCircle.CenterY.ToDeviceValue(null, UnitRenderingType.Vertical, svgCircle); radius = svgCircle.Radius.ToDeviceValue(null, UnitRenderingType.Other, svgCircle); bounds = SKRect.Create(cx - radius, cy - radius, radius + radius, radius + radius); matrix = SvgHelper.GetSKMatrix(svgCircle.Transforms); }
public void TestCircle() { var svgCircle = new SvgCircle() { CenterX = new SvgUnit(SvgUnitType.Percentage, 50), CenterY = new SvgUnit(SvgUnitType.Percentage, 50), Radius = new SvgUnit(SvgUnitType.Percentage, 15), }; CheckPercentageSize(svgCircle); }
public CircleDrawable(SvgCircle svgCircle, SKRect skOwnerBounds, Drawable?root, Drawable?parent, Attributes ignoreAttributes = Attributes.None) : base(svgCircle, root, parent) { IgnoreAttributes = ignoreAttributes; IsDrawable = CanDraw(svgCircle, IgnoreAttributes) && HasFeatures(svgCircle, IgnoreAttributes); if (!IsDrawable) { return; } Path = svgCircle.ToSKPath(svgCircle.FillRule, skOwnerBounds, _disposable); if (Path == null || Path.IsEmpty) { IsDrawable = false; return; } IsAntialias = SvgPaintingExtensions.IsAntialias(svgCircle); TransformedBounds = Path.Bounds; Transform = SvgTransformsExtensions.ToSKMatrix(svgCircle.Transforms); bool canDrawFill = true; bool canDrawStroke = true; if (SvgPaintingExtensions.IsValidFill(svgCircle)) { Fill = SvgPaintingExtensions.GetFillSKPaint(svgCircle, TransformedBounds, ignoreAttributes, _disposable); if (Fill == null) { canDrawFill = false; } } if (SvgPaintingExtensions.IsValidStroke(svgCircle, TransformedBounds)) { Stroke = SvgPaintingExtensions.GetStrokeSKPaint(svgCircle, TransformedBounds, ignoreAttributes, _disposable); if (Stroke == null) { canDrawStroke = false; } } if (canDrawFill && !canDrawStroke) { IsDrawable = false; return; } // TODO: Transform _skBounds using _skMatrix. TransformedBounds = Transform.MapRect(TransformedBounds); }
private static readonly int _radius = 100; //Radius set to 100 as the SvgDocument size is set at 200. #region Create Shape public static SvgCircle CreateSvgCircle(int radius) { SvgCircle svg = new SvgCircle { CenterX = _radius, CenterY = _radius, Radius = radius }; return(svg); }
public void DrawCircle(SvgDocument SvgDocument, PointF center, float radius, Color c) { SvgCircle SvgCircle = new SvgCircle() { CenterX = center.X, CenterY = center.Y, Radius = radius, Fill = new SvgColourServer(c) }; SvgDocument.Children.Add(SvgCircle); }
public void SetupElement(SvgCircle pEl) { pEl.Stroke = new SvgColourServer(color); pEl.Radius = radius; pEl.StrokeWidth = width; pEl.StrokeOpacity = opacity; if (isFill) { pEl.Fill = new SvgColourServer(fill); pEl.FillOpacity = fillOpacity; } }
public void DrawCircle(SvgCircle svgCircle, bool ignoreDisplay) { if (!CanDraw(svgCircle, ignoreDisplay)) { return; } float cx = svgCircle.CenterX.ToDeviceValue(null, UnitRenderingType.Horizontal, svgCircle); float cy = svgCircle.CenterY.ToDeviceValue(null, UnitRenderingType.Vertical, svgCircle); float radius = svgCircle.Radius.ToDeviceValue(null, UnitRenderingType.Other, svgCircle); if (radius <= 0f) { return; } var skRectBounds = SKRect.Create(cx - radius, cy - radius, radius + radius, radius + radius); _skCanvas.Save(); var skMatrix = SkiaUtil.GetSKMatrix(svgCircle.Transforms); SetTransform(skMatrix); SetClipPath(svgCircle, _disposable); var skPaintOpacity = SetOpacity(svgCircle, _disposable); var skPaintFilter = SetFilter(svgCircle, _disposable); if (SkiaUtil.IsValidFill(svgCircle)) { var skPaintFill = SkiaUtil.GetFillSKPaint(svgCircle, _skSize, skRectBounds, _disposable); _skCanvas.DrawCircle(cx, cy, radius, skPaintFill); } if (SkiaUtil.IsValidStroke(svgCircle)) { var skPaintStroke = SkiaUtil.GetStrokeSKPaint(svgCircle, _skSize, skRectBounds, _disposable); _skCanvas.DrawCircle(cx, cy, radius, skPaintStroke); } if (skPaintFilter != null) { _skCanvas.Restore(); } if (skPaintOpacity != null) { _skCanvas.Restore(); } _skCanvas.Restore(); }
public override SvgBasicShape ToSVGLibShape(SvgDoc doc) { var res = new SvgCircle(doc, center.X.ToString() + "px", center.X.ToString() + "px", r.ToString() + "px" ); 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); }
public static Ellipse GetCircle(SvgCircle circle) { Ellipse cir = new Ellipse() { Fill = GetBrush(circle), StrokeThickness = circle.StrokeWidth, Width = circle.Radius * 2, Height = circle.Radius * 2, }; Canvas.SetLeft(cir, circle.CenterX - circle.Radius); Canvas.SetTop(cir, circle.CenterY - circle.Radius); return(cir); }
protected void DrawCircle(SvgDocument source, PointF center, float radius, Color color) { SvgCircle svgCircle = new SvgCircle() { CenterX = center.X, CenterY = center.Y, Radius = radius, Fill = new SvgColourServer(Color.Transparent), StrokeWidth = MandalaGenerator.StrokeWidth, Stroke = new SvgColourServer(color) }; source.Children.Add(svgCircle); }
// Save created svg private static void SaveSvg(string fileName) { var oSvgDocument = new SvgDocument(); // draw all lines foreach (KeyValuePair <string, Line> l in Elements.Graphics.Lines) { SvgElement el = l.Value.SvgElement; if (el != null) { if (Elements.Graphics.LineTypes.ContainsKey(l.Value.type)) { Elements.Graphics.LineTypes[l.Value.type].SetupElement(el); } else { el.Stroke = new SvgColourServer(Color.Black); el.StrokeWidth = 0.5F; el.StrokeOpacity = 1F; } oSvgDocument.Children.Add(el); } } // draw all point foreach (KeyValuePair <string, Elements.Point> p in Elements.Graphics.Points) { SvgCircle ep = p.Value.SvgElement; if (ep != null) { if (Elements.Graphics.PointTypes.ContainsKey(p.Value.type)) { Elements.Graphics.PointTypes[p.Value.type].SetupElement(ep); } else { ep.Stroke = new SvgColourServer(Color.Black); ep.StrokeWidth = 0.5F; ep.StrokeOpacity = 1F; ep.Fill = new SvgColourServer(Color.Black); } oSvgDocument.Children.Add(ep); } } oSvgDocument.Write(fileName); }
public override SvgElement Draw() { var container = GetContainer(); var sum = _data.Aggregate(0f, (s, v) => s + v.Item2); if (sum > 0f) { var circumference = (float)(Math.PI * Width); var dashOffset = circumference * 1.25f; for (var i = 0; i < _data.Length; i++) { if (_data[i].Item2 > sum / 1000f) { var arc = _data[i].Item2 * circumference / sum; var outerRing = new SvgCircle { CenterX = Width / 2f, CenterY = Height / 2f, Radius = Width * 0.45f }; outerRing.CustomAttributes.Add("class", _css + " segment_" + ((i % 9) + 1).ToString()); outerRing.CustomAttributes.Add("stroke-dasharray", arc.ToString() + " " + (circumference - arc).ToString()); outerRing.CustomAttributes.Add("stroke-dashoffset", dashOffset.ToString()); container.Children.Add(outerRing); dashOffset -= arc; } } } var centerCircle = new SvgCircle { CenterX = Width / 2f, CenterY = Height / 2f, Radius = Width * 0.35f }; centerCircle.CustomAttributes.Add("class", "center"); container.Children.Add(centerCircle); DrawChildren(container.Children); return(container); }
public void TestGetAttribute() { var owner = new SvgCircle(); var parent = new SvgFragment(); parent.Children.Add(owner); parent.Attributes["test"] = "parent"; owner.Attributes["test"] = "owner"; Assert.AreEqual("owner", owner.Attributes.GetAttribute <string>("test")); owner.Attributes["test"] = "inherit"; Assert.AreEqual("inherit", owner.Attributes.GetAttribute <string>("test")); owner.Attributes.Remove("test"); Assert.IsNull(owner.Attributes.GetAttribute <string>("test")); }
internal static void SvgCircle2Pdf(SvgCircle element, XGraphics graphics) { if (element.Display == "none") { return; } if (element.Fill == SvgPaintServer.None) { var pen = ConvertHelper.Stroke2XPen(element.Stroke, element.StrokeWidth); graphics.DrawEllipse(pen, ConvertHelper.Circle2XRect(element.CenterX, element.CenterY, element.Radius)); } else { var brush = ConvertHelper.Fill2XBrush(element.Fill); graphics.DrawEllipse(brush, ConvertHelper.Circle2XRect(element.CenterX, element.CenterY, element.Radius)); } }
protected override void OnParametersSet() { Circles.Clear(); Legends.Clear(); double counterClockwiseOffset = 25; double totalPercent = 0; double offset = counterClockwiseOffset; int counter = 0; foreach (double data in GetNormalizedData()) { double percent = data * 100; double reversePercent = 100 - percent; offset = 100 - totalPercent + counterClockwiseOffset; totalPercent = totalPercent + percent; var circle = new SvgCircle() { Index = counter, CX = 20, CY = 20, Radius = 15.91549430918954, StrokeDashArray = $"{ToS(percent)} {ToS(reversePercent)}", StrokeDashOffset = offset }; Circles.Add(circle); string labels = ""; if (counter < InputLabels.Length) { labels = InputLabels[counter]; } SvgLegend Legend = new SvgLegend() { Index = counter, Labels = labels, Data = data.ToString() }; Legends.Add(Legend); counter += 1; } }
private void AddCircle() { if (!IsDocPresent()) { return; } SvgElement ele = GetCurrentSvgElement(); if (ele == null) { return; } SvgCircle circle = m_svg.AddCircle(ele); AddNodeToTree(circle); }
public void AddPoint(Vector2 point, string?containerId) { var circle = new SvgCircle() { CenterX = new SvgUnit(point.X), CenterY = new SvgUnit(point.Y), Fill = new SvgColourServer(Color.Red), Radius = new SvgUnit(1) }; SvgElement container = _svg; if (!string.IsNullOrWhiteSpace(containerId)) { container = _svg.GetElementById(containerId); } container.Children.Add(circle); }
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, });
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, });
void CreateArrowStart() { float radius = 0.125f; SvgMarker arrowStart = this.doc.AddMarker(); arrowStart.RefX = $"{this.ToPx(radius)}"; arrowStart.RefY = $"{this.ToPx(radius)}"; arrowStart.MarkerWidth = $"{this.ToPx(2 * radius)}"; arrowStart.MarkerHeight = $"{this.ToPx(2 * radius)}"; arrowStart.MarkerUnits = "px"; arrowStart.Id = ArrowStart; SvgCircle c = this.doc.AddCircle(arrowStart); c.Class = "connector"; c.CX = $"{this.ToPx(radius)}"; c.CY = $"{this.ToPx(radius)}"; c.R = $"{this.ToPx(radius)}"; }
public void TestGetInheritedAttribute() { var owner = new SvgCircle(); var parent = new SvgFragment(); parent.Children.Add(owner); parent.Attributes["test"] = "parent"; owner.Attributes["test"] = "owner"; Assert.AreEqual("owner", owner.Attributes.GetInheritedAttribute("test", true, "default")); Assert.AreEqual("owner", owner.Attributes.GetInheritedAttribute("test", false, "default")); owner.Attributes["test"] = "inherit"; Assert.AreEqual("parent", owner.Attributes.GetInheritedAttribute("test", true, "default")); Assert.AreEqual("parent", owner.Attributes.GetInheritedAttribute("test", false, "default")); owner.Attributes.Remove("test"); Assert.AreEqual("parent", owner.Attributes.GetInheritedAttribute("test", true, "default")); Assert.AreEqual("default", owner.Attributes.GetInheritedAttribute("test", false, "default")); }
void CreateArrowStart() { float radius = 0.125f; SvgMarker arrowStart = this.doc.AddMarker(); arrowStart.RefX = $"{this.ToPx(radius)}"; arrowStart.RefY = $"{this.ToPx(radius)}"; arrowStart.MarkerWidth = $"{this.ToPx(2 * radius)}"; arrowStart.MarkerHeight = $"{this.ToPx(2 * radius)}"; arrowStart.MarkerUnits = "px"; arrowStart.Id = ArrowStart; SvgCircle c = this.doc.AddCircle(arrowStart); c.CX = $"{this.ToPx(radius)}"; c.CY = $"{this.ToPx(radius)}"; c.R = $"{this.ToPx(radius)}"; c.Fill = Color.Black; c.StrokeWidth = "0"; }
public override SvgElement Draw() { var container = GetContainer(); var ring = new SvgCircle { CenterX = Height / 2f, CenterY = Height / 2f, Radius = Height * 0.45f }; ring.CustomAttributes.Add("class", "segment_" + ((_segment % 9) + 1).ToString()); container.Children.Add(ring); var label = new SvgText(_label); label.Transforms.Add(new SvgTranslate(Height + _gap, Height)); label.Children.Add(new SvgTextSpan()); container.Children.Add(label); return(container); }
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); }
private void BtnSVG_Click(object sender, RoutedEventArgs e) { var blue = new SvgColourServer(System.Drawing.Color.Blue); var yellow = new SvgColourServer(System.Drawing.Color.Yellow); var white = new SvgColourServer(System.Drawing.Color.White); var black = new SvgColourServer(System.Drawing.Color.Black); SvgDocument svgdoc = new SvgDocument(); svgdoc.Width = new SvgUnit(SvgUnitType.Pixel, 500); svgdoc.Height = new SvgUnit(SvgUnitType.Pixel, 500); svgdoc.ViewBox = new SvgViewBox(0, 0, 500, 500); var group = new SvgGroup(); svgdoc.Children.Add(group); var dd = new SvgFontStyleConverter(); group.Children.Add(new SvgText { Text = "华青仪表", X = new SvgUnitCollection { new SvgUnit(SvgUnitType.Pixel, 100) }, Y = new SvgUnitCollection { new SvgUnit(SvgUnitType.Pixel, 100) }, FontSize = new SvgUnit(SvgUnitType.Point, 20), Fill = black, Font = "黑体" }); SvgLine line = new SvgLine(); line.StartX = new SvgUnit(SvgUnitType.Pixel, 10); line.StartY = new SvgUnit(SvgUnitType.Pixel, 110); line.EndX = new SvgUnit(SvgUnitType.Pixel, 400); line.EndY = new SvgUnit(SvgUnitType.Pixel, 400); SvgCircle circle = new SvgCircle() { CenterX = 250, CenterY = 250, Stroke = blue, Radius = 50, StrokeWidth = new SvgUnit(SvgUnitType.Pixel, 5) }; group.Children.Add(circle); line.Stroke = blue; line.Fill = blue; line.StrokeWidth = new SvgUnit(SvgUnitType.Pixel, 5); group.Children.Add(line); #region 使用时,svg文档与数据库 /*注:XmlDocument读取svg文档内容,保存数据库(), * 然后SvgDocument.FromSvg<SvgDocument>()读取SvgDocument,在提取里面的<g>标签, * 给<g>加上平移变换translate即可实现将现有svg文档导入另外一个文档*/ //string strDoc = ""; //XmlDocument xmldoc = new XmlDocument(); //xmlDoc.Load(openSvgFile.FileName); //strDoc = xmlDoc.InnerXml; //SaveDB(strDoc); //strDoc = ReadFromDB(); //xmldoc.LoadXml(strDoc); //var dd = SvgDocument.FromSvg<SvgDocument>(strDoc); //var g = dd.Children.FindSvgElementOf<SvgGroup>(); #endregion //加载表盘测试.svg,将其中的group 加入到当前svg SvgDocument svgtest = SvgDocument.Open("表盘测试.svg"); var groupstest = svgtest.Children.FindSvgElementsOf <SvgGroup>(); foreach (var g in groupstest) { g.Transforms.Add(new Svg.Transforms.SvgTranslate(50, 50)); group.Children.Add(g); } //string strPath = @"<path transform=""translate(-20,0)"" fill-rule=""evenodd"" clip-rule=""evenodd"" fill=""none"" stroke=""#000000"" stroke-width=""1.4173"" stroke-miterlimit=""2.4142"" d="" //M217.274,209.852c4.294,0,7.796,3.502,7.796,7.795c0,4.295-3.502,7.797-7.796,7.797s-7.795-3.502-7.795-7.797 //C209.479,213.354,212.98,209.852,217.274,209.852L217.274,209.852z""/>"; /* * <path transform="translate(-20,0)" fill-rule="evenodd" clip-rule="evenodd" fill="none" stroke="#000000" stroke-width="1.4173" stroke-miterlimit="2.4142" d=" * M217.274,209.852c4.294,0,7.796,3.502,7.796,7.795c0,4.295-3.502,7.797-7.796,7.797s-7.795-3.502-7.795-7.797 * C209.479,213.354,212.98,209.852,217.274,209.852L217.274,209.852z"/> */ //var b = SvgPathBuilder.Parse(@"M217.274,209.852c4.294,0,7.796,3.502,7.796,7.795c0,4.295-3.502,7.797-7.796,7.797s-7.795-3.502-7.795-7.797 // C209.479, 213.354, 212.98, 209.852, 217.274, 209.852L217.274, 209.852z"); //SvgPath p = new SvgPath(); //p.PathData = b; //group.Children.Add(p); svgdoc.Write("456.svg"); svgdoc.Draw().Save("456.png", System.Drawing.Imaging.ImageFormat.Png); MessageBox.Show("456.svg + 456.png"); BitmapImage bitmap = GetBitmap("456.png"); img.Source = bitmap; }
public void DrawCorner() { Bitmap Image; if (true) { Image = _svg.Draw(); LuminanceSource source = new BitmapLuminanceSource(Image); var binBitmap = new BinaryBitmap(new HybridBinarizer(source)); var result = new MultiFormatReader().decode(binBitmap); if (result != null) { var moduleSize = ((FinderPattern)result.ResultPoints[0]).EstimatedModuleSize; var fill = true; var outterFill = new SvgColourServer(Color.Black); var backFill = new SvgColourServer(Color.White); var innerFill = new SvgColourServer(Color.Black); for (var i = 0; i < 3; ++i) { if (!(result.ResultPoints[i] is FinderPattern)) { continue; } var p = new PointF(result.ResultPoints[i].X, result.ResultPoints[i].Y); var m = moduleSize * 3.5f; var r1 = new RectangleF(p.X - m, p.Y - m, m * 2, m * 2); m = moduleSize * 2.5f; var r2 = new RectangleF(p.X - m, p.Y - m, m * 2, m * 2); m = moduleSize * 1.5f; var r3 = new RectangleF(p.X - m, p.Y - m, m * 2, m * 2); var qry = SvgQrcodeGroup.Children.Where( r => r is SvgRectangle && r1.IntersectsWith(((SvgRectangle)r).Bounds)) .ToList(); foreach (var c in qry) { SvgQrcodeGroup.Children.Remove(c); } SvgVisualElement c1, c2; PositionPatterns POP = PositionPatterns.RoundedRect; PositionPatterns PIP = PositionPatterns.RoundedRect; switch (POP) { case PositionPatterns.RoundedRect: var rect2 = new SvgRectangle { X = r1.X, Y = r1.Y, Width = r1.Width, Height = r1.Height }; SvgQrcodeGroup.Children.Add(rect2); var rect = rect2; rect.CornerRadiusX = r1.Width * 0.2f; rect.CornerRadiusY = r1.Height * 0.2f; c1 = rect; var rect3 = new SvgRectangle { X = r2.X, Y = r2.Y, Width = r2.Width, Height = r2.Height }; SvgQrcodeGroup.Children.Add(rect3); var rect1 = rect3; rect1.CornerRadiusX = r2.Width * 0.2f; rect1.CornerRadiusY = r2.Height * 0.2f; c2 = rect1; break; case PositionPatterns.Circle: var c = new SvgCircle { CenterX = r1.X + r1.Width / 2, CenterY = r1.Y + r1.Height / 2, Radius = r1.Width / 2 }; SvgQrcodeGroup.Children.Add(c); c1 = c; var c3 = new SvgCircle { CenterX = r2.X + r2.Width / 2, CenterY = r2.Y + r2.Height / 2, Radius = r2.Width / 2 }; SvgQrcodeGroup.Children.Add(c3); c2 = c3; break; default: var rect4 = new SvgRectangle { X = r1.X, Y = r1.Y, Width = r1.Width, Height = r1.Height }; SvgQrcodeGroup.Children.Add(rect4); c1 = rect4; var rect5 = new SvgRectangle { X = r2.X, Y = r2.Y, Width = r2.Width, Height = r2.Height }; SvgQrcodeGroup.Children.Add(rect5); c2 = rect5; break; } if (fill) { c1.Fill = outterFill; } c2.Fill = backFill; switch (PIP) { case PositionPatterns.RoundedRect: var rect1 = new SvgRectangle { X = r3.X, Y = r3.Y, Width = r3.Width, Height = r3.Height }; SvgQrcodeGroup.Children.Add(rect1); var rect = rect1; rect.CornerRadiusX = r3.Width * 0.2f; rect.CornerRadiusY = r3.Height * 0.2f; c1 = rect; break; case PositionPatterns.Circle: var c = new SvgCircle { CenterX = r3.X + r3.Width / 2, CenterY = r3.Y + r3.Height / 2, Radius = r3.Width / 2 }; SvgQrcodeGroup.Children.Add(c); c1 = c; break; default: var rect2 = new SvgRectangle { X = r3.X, Y = r3.Y, Width = r3.Width, Height = r3.Height }; SvgQrcodeGroup.Children.Add(rect2); c1 = rect2; break; } if (fill) { c1.Fill = innerFill; } } } } }
public static CircleDrawable Create(SvgCircle svgCircle, Rect skOwnerBounds, DrawableBase?parent, IAssetLoader assetLoader, Attributes ignoreAttributes = Attributes.None) { var drawable = new CircleDrawable(assetLoader) { Element = svgCircle, Parent = parent, IgnoreAttributes = ignoreAttributes }; drawable.IsDrawable = drawable.CanDraw(svgCircle, drawable.IgnoreAttributes) && drawable.HasFeatures(svgCircle, drawable.IgnoreAttributes); if (!drawable.IsDrawable) { return(drawable); } drawable.Path = svgCircle.ToPath(svgCircle.FillRule, skOwnerBounds); if (drawable.Path is null || drawable.Path.IsEmpty) { drawable.IsDrawable = false; return(drawable); } drawable.IsAntialias = SvgModelExtensions.IsAntialias(svgCircle); drawable.TransformedBounds = drawable.Path.Bounds; drawable.Transform = SvgModelExtensions.ToMatrix(svgCircle.Transforms); var canDrawFill = true; var canDrawStroke = true; if (SvgModelExtensions.IsValidFill(svgCircle)) { drawable.Fill = SvgModelExtensions.GetFillPaint(svgCircle, drawable.TransformedBounds, assetLoader, ignoreAttributes); if (drawable.Fill is null) { canDrawFill = false; } } if (SvgModelExtensions.IsValidStroke(svgCircle, drawable.TransformedBounds)) { drawable.Stroke = SvgModelExtensions.GetStrokePaint(svgCircle, drawable.TransformedBounds, assetLoader, ignoreAttributes); if (drawable.Stroke is null) { canDrawStroke = false; } } if (canDrawFill && !canDrawStroke) { drawable.IsDrawable = false; return(drawable); } // TODO: Transform _skBounds using _skMatrix. drawable.TransformedBounds = drawable.Transform.MapRect(drawable.TransformedBounds); return(drawable); }