/// <summary> /// 它创建一个新的SVG文本元素。 /// </summary> public SVGText AddText(SVGUnit parent, ref SVGUnit last) { SVGText txt = new SVGText(this); AddElement(parent, txt, ref last); return(txt); }
public bool SetStyleFromSvg(SVGText svg) { try { float x = ParseSize(svg.X, Dpi.X); float y = ParseSize(svg.Y, Dpi.Y); float w = ParseSize(svg.Width, Dpi.X); float h = ParseSize(svg.Height, Dpi.Y); Text = svg.Value; //font Stroke = svg.Fill; string family = svg.FontFamily; float size = ParseSize(svg.FontSize, Dpi.X); int fs = 0; if (svg.FontWeight.IndexOf("bold") >= 0) { fs = 1; } if (svg.FontStyle.IndexOf("italic") >= 0) { fs = fs | 2; } Font = new Font(family, size, (FontStyle)fs); // y -= font.Size; y -= Font.Height; RectangleF = new RectangleF(x, y, w, h); if (svg.TextAnchor.Length > 0) { switch (svg.TextAnchor) { case "start": TextAnchor.Alignment = StringAlignment.Near; break; case "end": TextAnchor.Alignment = StringAlignment.Far; RectangleF = new RectangleF(x - w, y, w, h); break; case "middle": TextAnchor.Alignment = StringAlignment.Center; RectangleF = new RectangleF(x - w / 2, y, w, h); break; } } return(true); } catch { SVGErr.Log("DrawText", "SetStyleFromSvg", "SetStyleFromSvg", SVGErr._LogPriority.Info); return(false); } }
public static DrawTextObject Create(SVGText svg) { if (string.IsNullOrEmpty(svg.Value)) { return(null); } try { var dobj = new DrawTextObject(ParseSize(svg.X, Dpi.X), ParseSize(svg.Y, Dpi.Y)) { Text = svg.Value }; dobj.SetStyleFromSvg(svg); return(dobj); } catch (Exception ex) { SVGErr.Log("DrawText", "DrawText", ex.ToString(), SVGErr._LogPriority.Info); return(null); } }
public void CreateSVGDependencyGraph(DependencyGraph graph) { SVG svg = new SVG(this.Document, SVGNameSpace, "1.1"); this.BodyElement.AppendChild((svg as ISVGElement).Element); SVGDefinitions definitions = new SVGDefinitions(svg); System.Collections.Generic.Dictionary <DependencyNode, SVGGroup> nodeToSVGGroup = new System.Collections.Generic.Dictionary <DependencyNode, SVGGroup>(); int rankCount = graph.RankCount; int numVerticalSlots = 2 * rankCount + 1; float verticalStride = 100 / numVerticalSlots; int y = (int)verticalStride;; for (int i = rankCount - 1; i >= 0; --i) { DependencyNodeCollection rank = graph[i]; int nodeCount = rank.Count; int numHorizontalSlots = 2 * nodeCount + 1; float horizontalStride = 100 / numHorizontalSlots; int x = (int)horizontalStride; System.Text.StringBuilder rankIdName = new System.Text.StringBuilder(); rankIdName.AppendFormat("Rank{0}", rank.Rank); SVGGroup rankGroup = new SVGGroup(svg, rankIdName.ToString()); SVGAttributes.Fill(rankGroup, "red"); SVGText rankText = new SVGText(rankGroup, rankIdName.ToString(), 0, y, 100, (int)verticalStride, "%"); SVGAttributes.Fill(rankText, "black"); foreach (DependencyNode node in rank) { SVGGroup nodeGroup = new SVGGroup(rankGroup, node.UniqueModuleName); SVGRect nodeRect = new SVGRect(nodeGroup, x, y, (int)horizontalStride, (int)verticalStride, "%"); SVGText nodeText = new SVGText(nodeGroup, node.UniqueModuleName, x, y + (int)verticalStride / 2, (int)horizontalStride, (int)verticalStride, "%"); SVGAttributes.Fill(nodeText, "black"); nodeToSVGGroup.Add(node, nodeGroup); x += (int)(2 * horizontalStride); } y += (int)(verticalStride * 2); } SVGArrow arrow = new SVGArrow(svg, 0, 0, 100, 100, ""); SVGAttributes.Stroke(arrow, "black"); SVGAttributes.StrokeWidth(arrow, 5); #if false System.Xml.XmlElement circle = this.Document.CreateElement("circle"); System.Xml.XmlAttribute cx = this.Document.CreateAttribute("cx"); cx.Value = "100"; System.Xml.XmlAttribute cy = this.Document.CreateAttribute("cy"); cy.Value = "50"; System.Xml.XmlAttribute r = this.Document.CreateAttribute("r"); r.Value = "40"; circle.Attributes.Append(cx); circle.Attributes.Append(cy); circle.Attributes.Append(r); svgElement.AppendChild(circle); #endif }