private void ReadLineAttributes(LineVObject vObject, SvgLine svg) { ReadBaseRectangleVObjectAttributes(vObject, svg); vObject.Width = svg.StrokeWidth; vObject.ControlPoints = new[] { new PointF(svg.X1, svg.Y1), new PointF(svg.X2, svg.Y2) }; string color = null; foreach (var attr in svg.CustomAttributes) { if (attr.NamespaceUri == XmlNamespace.AurigmaVectorObjects && attr.LocalName == "fixed-width") { vObject.FixedWidth = attr.GetValue() == "true"; } else if (attr.NamespaceUri == XmlNamespace.AurigmaVectorObjects && attr.LocalName == "color") { color = attr.GetValue(); } } vObject.Color = !string.IsNullOrEmpty(color) ? _serializer.Deserialize <Color>(color) : new RgbColor(svg.Stroke); }
public override RenderedSvg RenderColumn() { RenderedSvg result = base.RenderColumn(); SvgGroup group = new SvgGroup(); SvgColourServer blackPaint = new SvgColourServer(System.Drawing.Color.Black); double width = view.RenderSize.Width; //drawing layer boundaries LayerVM[] layers = columnVm.Layers.ToArray(); double boundary = 0.0; for (int i = 0; i < layers.Length; i++) { LayerVM lVM = layers[i]; if (i < layers.Length - 1) { boundary += lVM.Length; SvgLine line = new SvgLine(); line.Stroke = blackPaint; line.StartX = Helpers.dtos(0.0); line.EndX = Helpers.dtos(width); line.StartY = Helpers.dtos(boundary); line.EndY = Helpers.dtos(boundary); group.Children.Add(line); } var layerSvg = layerPainter.Paint(layers[i], width, lVM.Length); layerSvg.Transforms.Add(new Svg.Transforms.SvgTranslate(0.0f, (float)(boundary - lVM.Length))); group.Children.Add(layerSvg); } result.SVG = group; return(result); }
void CreateArrow(SvgGroup g, bool startMarker, bool endMarker, float xStart, float yStart, float xEnd, float yEnd) { SvgLine stub = this.doc.AddLine(g); stub.Stroke = Color.Black; stub.X1 = this.ToPx(xStart); stub.X2 = this.ToPx(xEnd); stub.Y1 = this.ToPx(yStart); stub.Y2 = this.ToPx(yEnd); stub.StrokeWidth = this.ToPx(this.BorderWidth); if (startMarker) { stub.MarkerStart = $"url(#{ArrowStart})"; } if (endMarker) { stub.MarkerEnd = $"url(#{ArrowEnd})"; } }
/// <exception cref="ArgumentNullException"><paramref name="svgPath" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="svgLineSegment" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="sourceMatrix" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="viewMatrix" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="zplContainer" /> is <see langword="null" />.</exception> protected virtual void TranslateSvgLineSegment([NotNull] SvgPath svgPath, [NotNull] SvgLineSegment svgLineSegment, [NotNull] Matrix sourceMatrix, [NotNull] Matrix viewMatrix, [NotNull] ZplContainer zplContainer) { if (svgPath == null) { throw new ArgumentNullException(nameof(svgPath)); } if (svgLineSegment == null) { throw new ArgumentNullException(nameof(svgLineSegment)); } if (sourceMatrix == null) { throw new ArgumentNullException(nameof(sourceMatrix)); } if (viewMatrix == null) { throw new ArgumentNullException(nameof(viewMatrix)); } if (zplContainer == null) { throw new ArgumentNullException(nameof(zplContainer)); } var svgLine = new SvgLine { Color = svgPath.Color, Stroke = svgPath.Stroke, StrokeWidth = svgPath.StrokeWidth, StartX = svgLineSegment.Start.X, StartY = svgLineSegment.Start.Y, EndX = svgLineSegment.End.X, EndY = svgLineSegment.End.Y }; this.ZplTransformer.Transform(svgLine, sourceMatrix, viewMatrix, out var startX, out var startY, out var endX, out var endY, out var strokeWidth); var horizontalStart = (int)startX; var verticalStart = (int)endY; var width = (int)(endX - startX); var height = (int)(endY - startY); var thickness = (int)strokeWidth; zplContainer.Body.Add(this.ZplCommands.FieldTypeset(horizontalStart, verticalStart)); zplContainer.Body.Add(this.ZplCommands.GraphicBox(width, height, thickness, LineColor.Black)); }
public static LineDrawable Create(SvgLine svgLine, SKRect skViewport, DrawableBase?parent, IAssetLoader assetLoader, HashSet <Uri>?references, DrawAttributes ignoreAttributes = DrawAttributes.None) { var drawable = new LineDrawable(assetLoader, references) { Element = svgLine, Parent = parent, IgnoreAttributes = ignoreAttributes }; drawable.IsDrawable = drawable.CanDraw(svgLine, drawable.IgnoreAttributes) && drawable.HasFeatures(svgLine, drawable.IgnoreAttributes); if (!drawable.IsDrawable) { return(drawable); } drawable.Path = svgLine.ToPath(svgLine.FillRule, skViewport); if (drawable.Path is null || drawable.Path.IsEmpty) { drawable.IsDrawable = false; return(drawable); } drawable.Initialize(skViewport, references); return(drawable); }
private void CreateSvgOsd() { int _width = yascControl1.CamWidth, _height = yascControl1.CamHeight; Pen _whitePen = Pens.White; svgDoc = new SvgDocument() { Width = yascControl1.CamWidth, Height = yascControl1.CamHeight, ViewBox = new SvgViewBox(0, 0, yascControl1.CamWidth, yascControl1.CamHeight) }; var group = new SvgGroup(); svgDoc.Children.Add(group); var headbg = new RectangleF(0, 0, _width, _height * .07f); // Bottom line var line = new SvgLine() { StartX = headbg.Left + 5, StartY = headbg.Bottom - headbg.Height / 5, EndX = (SvgUnit)(headbg.Width - 5), EndY = (SvgUnit)(headbg.Bottom - headbg.Height * .2), }; using (var st = new MemoryStream()) { svgDoc.Write(st); svgData = Encoding.UTF8.GetString(st.GetBuffer()); } }
public LineDrawable(SvgLine svgLine, SKRect skOwnerBounds, Drawable?root, Drawable?parent, Attributes ignoreAttributes = Attributes.None) : base(svgLine, root, parent) { IgnoreAttributes = ignoreAttributes; IsDrawable = CanDraw(svgLine, IgnoreAttributes) && HasFeatures(svgLine, IgnoreAttributes); if (!IsDrawable) { return; } Path = svgLine.ToSKPath(svgLine.FillRule, skOwnerBounds, _disposable); if (Path == null || Path.IsEmpty) { IsDrawable = false; return; } IsAntialias = SvgPaintingExtensions.IsAntialias(svgLine); TransformedBounds = Path.Bounds; Transform = SvgTransformsExtensions.ToSKMatrix(svgLine.Transforms); bool canDrawFill = true; bool canDrawStroke = true; if (SvgPaintingExtensions.IsValidFill(svgLine)) { Fill = SvgPaintingExtensions.GetFillSKPaint(svgLine, TransformedBounds, ignoreAttributes, _disposable); if (Fill == null) { canDrawFill = false; } } if (SvgPaintingExtensions.IsValidStroke(svgLine, TransformedBounds)) { Stroke = SvgPaintingExtensions.GetStrokeSKPaint(svgLine, TransformedBounds, ignoreAttributes, _disposable); if (Stroke == null) { canDrawStroke = false; } } if (canDrawFill && !canDrawStroke) { IsDrawable = false; return; } SvgMarkerExtensions.CreateMarkers(svgLine, Path, skOwnerBounds, ref MarkerDrawables, _disposable); // TODO: Transform _skBounds using _skMatrix. TransformedBounds = Transform.MapRect(TransformedBounds); }
internal static void SvgLine2Pdf(SvgLine element, XGraphics graphics) { if (element.Display == "none") { return; } var pen = ConvertHelper.Stroke2XPen(element.Stroke, element.StrokeWidth); graphics.DrawLine(pen, ConvertHelper.Point2XPoint(element.StartX, element.StartY), ConvertHelper.Point2XPoint(element.EndX, element.EndY)); }
void CreateLine(SvgGroup g, float x1, float y1, float x2, float y2) { SvgLine stub = this.doc.AddLine(g); stub.Class = "connector"; stub.X1 = this.ToPx(x1); stub.X2 = this.ToPx(x2); stub.Y1 = this.ToPx(y1); stub.Y2 = this.ToPx(y2); }
void CreateLine(SvgGroup g, float x1, float y1, float x2, float y2) { SvgLine stub = this.doc.AddLine(g); stub.Stroke = Color.Black; stub.X1 = this.ToPx(x1); stub.X2 = this.ToPx(x2); stub.Y1 = this.ToPx(y1); stub.Y2 = this.ToPx(y2); stub.StrokeWidth = this.ToPx(this.BorderWidth); }
protected void DrawLine(SvgDocument source, PointF p1, PointF p2) { SvgLine svgLine = new SvgLine() { StartX = p1.X, StartY = p1.Y, EndX = p2.X, EndY = p2.Y, StrokeWidth = MandalaGenerator.StrokeWidth, Stroke = new SvgColourServer(Color.Black) }; source.Children.Add(svgLine); }
public Line(SvgLine svgLine) { x0 = svgLine.StartX.ToDeviceValue(null, UnitRenderingType.Horizontal, svgLine); y0 = svgLine.StartY.ToDeviceValue(null, UnitRenderingType.Vertical, svgLine); x1 = svgLine.EndX.ToDeviceValue(null, UnitRenderingType.Horizontal, svgLine); y1 = svgLine.EndY.ToDeviceValue(null, UnitRenderingType.Vertical, svgLine); float x = Math.Min(x0, x1); float y = Math.Min(y0, y1); float width = Math.Abs(x0 - x1); float height = Math.Abs(y0 - y1); bounds = SKRect.Create(x, y, width, height); matrix = SvgHelper.GetSKMatrix(svgLine.Transforms); }
public void ReadContent(XmlElement xmlElement, SvgReader svgReader) { _line1 = null; _line2 = null; foreach (var node in xmlElement.ChildNodes) { var childElement = node as XmlElement; if (childElement != null) { var svgNode = svgReader.CreateSvgNodeFromXml(childElement); svgReader.Read(svgNode, childElement); if (svgNode is SvgLine) { if (_line1 == null) { _line1 = svgNode as SvgLine; } else { _line2 = svgNode as SvgLine; } } } if (_line1 != null && _line2 != null) { break; } } if (_line1 != null && _line2 != null) { X1 = _line1.X1; Y1 = _line1.Y1; X2 = _line1.X2; Y2 = _line1.Y2; StrokeWidth = _line1.StrokeWidth; Stroke = _line1.Stroke; AltStroke = _line2.Stroke; DashWidth = _line1.StrokeDashArray[0]; AltDashWidth = _line1.StrokeDashArray[1]; } else { throw new SvgParseException(Resources.Exceptions.CanNotParseSvgVoDashLine); } }
public lineData(SvgLine svg) { Color cColor = svg.Stroke; strokeColor = Convert.ToString(cColor.R) + Convert.ToString(cColor.G) + Convert.ToString(cColor.B); strokeWidth = svg.StrokeWidth; xpos1 = Convert.ToDouble(svg.X1); xpos2 = Convert.ToDouble(svg.X2); ypos1 = Convert.ToDouble(svg.Y1); ypos2 = Convert.ToDouble(svg.Y2); Color fColor = svg.Fill; fillColor = Convert.ToString(fColor.R) + Convert.ToString(fColor.G) + Convert.ToString(fColor.B); Id = svg.Id; style = svg.Style; }
private void Createlines() { for (int idx = 0; idx < _simulationlength; idx++) { SvgLine line = new SvgLine() { StartX = (idx * _cycleWidth) + _startx, EndX = (idx * _cycleWidth) + _startx, StartY = 0, EndY = (_cores.Count * _cycleWidth) + 10, StrokeWidth = 0.25F, Stroke = new SvgColourServer(idx % 10 == 0 ? Color.Black : Color.FromArgb(255, 195, 195, 195)), }; _lines.Add(line); } }
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; }
protected override SvgElement GetContainer() { var line = new SvgLine { StartX = Left, StartY = Top, EndX = Left + Width, EndY = Top + Height }; if (!string.IsNullOrEmpty(CssClass)) { line.CustomAttributes.Add("class", CssClass); } return(line); }
public static XnaDrawLine Create(SvgLine svg) { try { var dobj = new XnaDrawLine(ParseSize(svg.X1, Dpi.X), ParseSize(svg.Y1, Dpi.Y), ParseSize(svg.X2, Dpi.X), ParseSize(svg.Y2, Dpi.Y)); dobj.SetStyleFromSvg(svg); return(dobj); } catch (Exception ex) { ErrH.Log("CreateLine", "Draw", ex.ToString(), ErrH._LogPriority.Info); return(null); } }
public void DrawLine(SvgLine svgLine, bool ignoreDisplay) { if (!CanDraw(svgLine, ignoreDisplay)) { return; } _skCanvas.Save(); var skMatrix = SkiaUtil.GetSKMatrix(svgLine.Transforms); SetTransform(skMatrix); SetClipPath(svgLine, _disposable); var skPaintOpacity = SetOpacity(svgLine, _disposable); var skPaintFilter = SetFilter(svgLine, _disposable); var skPath = SkiaUtil.ToSKPath(svgLine, svgLine.FillRule, _disposable); if (skPath != null && !skPath.IsEmpty) { var skBounds = skPath.Bounds; if (SkiaUtil.IsValidStroke(svgLine)) { var skPaint = SkiaUtil.GetStrokeSKPaint(svgLine, _skSize, skBounds, _disposable); _skCanvas.DrawPath(skPath, skPaint); } DrawMarkers(svgLine, skPath); } if (skPaintFilter != null) { _skCanvas.Restore(); } if (skPaintOpacity != null) { _skCanvas.Restore(); } _skCanvas.Restore(); }
private void AddLine() { if (!IsDocPresent()) { return; } SvgElement ele = GetCurrentSvgElement(); if (ele == null) { return; } SvgLine line = m_svg.AddLine(ele); AddNodeToTree(line); }
/// <summary> /// Creates the key-event relationship connectors. /// </summary> /// <param name="doc"></param> /// <param name="kers"></param> /// <param name="keyEventNodes"></param> private void DrawKeyEventRelationships(SvgDocument doc, ICollection <KeyEventRelationship> kers, Dictionary <KeyEvent, SvgRectangle> keyEventNodes) { foreach (var ker in kers) { var startNode = keyEventNodes[ker.FromNode]; var endNode = keyEventNodes[ker.ToNode]; var line = new SvgLine() { StartX = startNode.X + startNode.Width, StartY = startNode.Y + startNode.Height / 2, EndX = endNode.X, EndY = endNode.Y + startNode.Height / 2, Stroke = new SvgColourServer(Color.Black), MarkerEnd = new Uri($"url(#{arrowMarker.ID})", UriKind.Relative) }; doc.Children.Add(line); } }
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, });
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, });
private void WriteLineAttributes(SvgLine svg, LineVObject vObject) { WriteBaseRectangleVObjectAttributes(svg, vObject); var cm = vObject.GetColorManagement(true); svg.Stroke = ColorManagement.GetPreviewColor(cm, vObject.Color); svg.CustomAttributes.Add(new SvgVoAttribute("color", _serializer.Serialize(vObject.Color))); svg.StrokeWidth = vObject.Width; svg.X1 = vObject.Point0.X; svg.Y1 = vObject.Point0.Y; svg.X2 = vObject.Point1.X; svg.Y2 = vObject.Point1.Y; if (vObject.FixedWidth) { svg.CustomAttributes.Add(new SvgVoAttribute("fixed-width", vObject.FixedWidth)); } }
public override RenderedSvg RenderColumn() { RenderedSvg result = base.RenderColumn(); double width = result.RenderedSize.Width; SvgGroup linesGroup = new SvgGroup(); SvgColourServer blackPaint = new SvgColourServer(System.Drawing.Color.Black); int minRank = int.MaxValue; LayerBoundary[] boundaries = vm.Boundaries.OrderBy(b => b.Level).ToArray(); var rank = boundaries.Select(b => b.Rank).Min(); for (int i = 0; i < boundaries.Length; i++) { LayerBoundary boundary = boundaries[i]; SvgLine line = new SvgLine(); line.StartX = Helpers.dtos(0.0); line.EndX = Helpers.dtos(width); line.StartY = Helpers.dtos(boundary.Level); line.EndY = Helpers.dtos(boundary.Level); line.Stroke = blackPaint; linesGroup.Children.Add(line); minRank = Math.Min(minRank, boundary.Rank); string textStr = string.Format("{0}", boundary.Numbers[rank]); //putting layer number as well SvgText text2 = new SvgText(textStr); text2.Transforms.Add(new Svg.Transforms.SvgTranslate(labelXoffset, (float)(boundary.Level + labelYoffset))); text2.FontSize = Helpers.dtos(10.0); text2.Fill = blackPaint; linesGroup.Children.Add(text2); } result.SVG = linesGroup; return(result); }
private void DrawLine( SvgDocument document, SvgUnit x1, SvgUnit y1, SvgUnit x2, SvgUnit y2, string cssClass) { var line = new SvgLine { StartX = x1, StartY = y1, EndX = x2, EndY = y2 }; if (!string.IsNullOrEmpty(cssClass)) { line.CustomAttributes.Add("class", cssClass); } document.Children.Add(line); }
void CreateArrow(SvgGroup g, bool startMarker, bool endMarker, float xStart, float yStart, float xEnd, float yEnd) { SvgLine stub = this.doc.AddLine(g); stub.Class = "connector"; stub.X1 = this.ToPx(xStart); stub.X2 = this.ToPx(xEnd); stub.Y1 = this.ToPx(yStart); stub.Y2 = this.ToPx(yEnd); if (startMarker) { stub.MarkerStart = $"url(#{ArrowStart})"; } if (endMarker) { stub.MarkerEnd = $"url(#{ArrowEnd})"; } }
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 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(); } }
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 GenerateSVG() { SvgDocument doc = new SvgDocument(); doc.FontSize = 16; SvgColourServer blackPainter = new SvgColourServer(Color.Black); SvgColourServer whitePainter = new SvgColourServer(Color.White); SvgColourServer grayPainter = new SvgColourServer(Color.Gray); SvgColourServer greenPainter = new SvgColourServer(Color.LightGreen); int round_gap = 50; int matchup_width = 400; int matchup_height = 150; int matchup_team_x_offset = 20; int matchup_team_y_offset = 50; int matchup_team_font_size = 36; int matchup_vs_font_size = 24; int matchup_offset_y = 0; int matchup_gap_y = 10; for (int r_i = 0; r_i < Rounds.Count; r_i++) { Round r = Rounds[r_i]; Console.WriteLine("Round {0} Matches: ", r.ID); //Calculate matchup gap int round_x_offset = r_i * (matchup_width + round_gap); for (int m_i = 0; m_i < r.Matchups.Count; m_i++) { Matchup m = r.Matchups[m_i]; int round_y_offset = m_i * (matchup_height + matchup_gap_y) + matchup_offset_y; //Draw Rectangle per Matchup SvgRectangle rec = new SvgRectangle(); rec.X = round_x_offset; rec.Y = round_y_offset; rec.Width = matchup_width; rec.Height = matchup_height; rec.Stroke = blackPainter; rec.StrokeWidth = 2; if (!m.IsFinished) { rec.Fill = whitePainter; } else { rec.Fill = greenPainter; } doc.Children.Add(rec); //Team 1 Text string team_text = "TBD"; string team_id = ""; if (m.Team1 != null) { if (m.Team1.IsDummy) { team_text = "-"; } else { team_text = m.Team1.Name; team_id = m.Team1.ID.ToString("00"); } } //Add Text //Τeam ID SvgText t1 = new SvgText(team_id); t1.FontSize = matchup_team_font_size; t1.X.Add(round_x_offset + matchup_team_x_offset - 10); t1.Y.Add(round_y_offset + matchup_team_y_offset); doc.Children.Add(t1); //Τeam Name t1 = new SvgText(team_text); if (m.Team1 == m.Winner && m.Winner != null) { t1.FontWeight = SvgFontWeight.Bold; } t1.FontSize = matchup_team_font_size; t1.X.Add(round_x_offset + 50 + matchup_team_x_offset); t1.Y.Add(round_y_offset + matchup_team_y_offset); doc.Children.Add(t1); SvgText t3 = new SvgText("vs"); t3.FontSize = matchup_vs_font_size; t3.X.Add(round_x_offset + matchup_team_x_offset); t3.Y.Add(round_y_offset + 5 + matchup_height / 2.0f); doc.Children.Add(t3); //Horizontal Matchup Splitter Line Part 1 //Add horizontal line SvgLine hl1 = new SvgLine(); hl1.Stroke = blackPainter; hl1.StrokeWidth = 5; hl1.StrokeOpacity = 1.0f; hl1.FillOpacity = 1.0f; hl1.StartX = round_x_offset + matchup_team_x_offset + 40; hl1.StartY = round_y_offset + matchup_height / 2.0f; hl1.EndX = round_x_offset + matchup_width; hl1.EndY = hl1.StartY; doc.Children.Add(hl1); //Vertical Line on the splitter SvgLine vl1 = new SvgLine(); vl1.Stroke = blackPainter; vl1.StrokeWidth = 5; vl1.StrokeOpacity = 1.0f; vl1.FillOpacity = 1.0f; vl1.StartX = hl1.StartX; vl1.StartY = hl1.StartY; vl1.EndX = vl1.StartX; vl1.EndY = hl1.StartY - matchup_height / 2.0f; doc.Children.Add(vl1); SvgLine vl2 = new SvgLine(); vl2.Stroke = blackPainter; vl2.StrokeWidth = 5; vl2.StrokeOpacity = 1.0f; vl2.FillOpacity = 1.0f; vl2.StartX = hl1.StartX; vl2.StartY = hl1.StartY; vl2.EndX = vl1.StartX; vl2.EndY = hl1.StartY + matchup_height / 2.0f; doc.Children.Add(vl2); //Team 2 Text team_text = "TBD"; team_id = ""; if (m.Team2 != null) { if (m.Team2.IsDummy) { team_text = "-"; } else { team_text = m.Team2.Name; team_id = m.Team2.ID.ToString("00"); } } //Τeam ID SvgText t2 = new SvgText(team_id); t2.FontSize = matchup_team_font_size; t2.X.Add(round_x_offset + matchup_team_x_offset - 10); t2.Y.Add(round_y_offset + matchup_height / 2.0f + matchup_team_y_offset); doc.Children.Add(t2); t2 = new SvgText(team_text); if (m.Team2 == m.Winner && m.Winner != null) { t2.FontWeight = SvgFontWeight.Bold; } t2.FontSize = matchup_team_font_size; t2.X.Add(round_x_offset + 50 + matchup_team_x_offset); t2.Y.Add(round_y_offset + matchup_height / 2.0f + matchup_team_y_offset); doc.Children.Add(t2); //Draw Matchup Connector to next Matchup if (r_i != Rounds.Count - 1) { //Add horizontal line SvgLine l = new SvgLine(); l.Stroke = grayPainter; l.StrokeWidth = 5; l.StrokeOpacity = 1.0f; l.FillOpacity = 1.0f; l.StartX = round_x_offset + matchup_width; l.StartY = round_y_offset + matchup_height / 2.0f; l.EndX = l.StartX + round_gap / 2.0f; l.EndY = l.StartY; doc.Children.Add(l); //Vertical Line SvgLine l1 = new SvgLine(); l1.Stroke = grayPainter; l1.StrokeWidth = 5; l1.StrokeOpacity = 1.0f; l1.FillOpacity = 1.0f; l1.StartX = l.EndX; l1.StartY = l.EndY; l1.EndX = l.EndX; if (m_i % 2 == 0) { l1.EndY = l.StartY + (matchup_height + matchup_gap_y) / 2.0f; } else { l1.EndY = l.StartY - (matchup_height + matchup_gap_y) / 2.0f; } doc.Children.Add(l1); //Last horizontal line SvgLine l2 = new SvgLine(); l2.Stroke = grayPainter; l2.StrokeWidth = 5; l2.StrokeOpacity = 1.0f; l2.FillOpacity = 1.0f; l2.StartX = l1.EndX; l2.StartY = l1.EndY; l2.EndX = l1.EndX + round_gap / 2.0f; l2.EndY = l1.EndY; doc.Children.Add(l2); } } //Update Matchup gaps and offsets matchup_offset_y += (matchup_height + matchup_gap_y) / 2; matchup_gap_y = 2 * (matchup_gap_y + matchup_height) - matchup_height; } Bitmap img = doc.Draw(); img.Save("bracket.png"); img.Dispose(); }