private void RenderTextPath(SvgTextPathElement textPath, ref Point ctp, double rotate, WpfTextPlacement placement) { if (_pathRenderer == null) { return; } _pathRenderer.RenderSingleLineText(textPath, ref ctp, string.Empty, rotate, placement); }
public void BeginTextPath(SvgTextPathElement svgElement) { _textPathElement = svgElement; if (_pathChars == null || _pathChars.Count != 0) { _pathChars = new List <WpfPathChar>(); } if (_pathTextRuns == null || _pathTextRuns.Count != 0) { _pathTextRuns = new List <WpfPathTextRun>(); } _textLength = 0; _pathLength = 0; }
private ISvgAnimatedLength GetStartOffset(SvgTextPathElement pathElement, SvgTextBaseElement textElement) { ISvgAnimatedLength pathOffset = pathElement.StartOffset; if (pathOffset != null && pathOffset.AnimVal != null) { if (pathOffset.AnimVal.Value.Equals(0)) { var curOffset = this.GetStartOffset(textElement); if (curOffset != null && curOffset.AnimVal != null) { if (!curOffset.AnimVal.Value.Equals(0)) { return(curOffset); } } } return(pathOffset); } return(this.GetStartOffset(textElement)); }
public virtual void VisitTextPathElement(SvgTextPathElement element) => DefaultVisit(element);
private void RenderTextPath(SvgTextPathElement textPath, ref Point ctp, double rotate, WpfTextPlacement placement) { if (textPath.ChildNodes == null || textPath.ChildNodes.Count == 0) { return; } SvgElement targetPath = textPath.ReferencedElement as SvgElement; if (targetPath == null) { return; } PathGeometry pathGeometry = CreateGeometry(targetPath, true) as PathGeometry; if (pathGeometry == null) { return; } this.IsTextPath = true; WpfTextOnPathDrawing pathDrawing = new WpfTextOnPathDrawing(); pathDrawing.BeginTextPath(); XmlNodeType nodeType = XmlNodeType.None; foreach (XmlNode child in textPath.ChildNodes) { nodeType = child.NodeType; if (nodeType == XmlNodeType.Text) { RenderTextPath(textPath, pathDrawing, GetText(textPath, child), new Point(ctp.X, ctp.Y), rotate, placement); } else if (nodeType == XmlNodeType.Element) { string nodeName = child.Name; if (string.Equals(nodeName, "tref")) { RenderTRefPath((SvgTRefElement)child, pathDrawing, ref ctp); } else if (string.Equals(nodeName, "tspan")) { RenderTSpanPath((SvgTSpanElement)child, pathDrawing, ref ctp); } } } WpfTextStringFormat stringFormat = GetTextStringFormat(_textElement); ISvgAnimatedLength pathOffset = textPath.StartOffset; SvgTextPathMethod pathMethod = (SvgTextPathMethod)textPath.Method.BaseVal; SvgTextPathSpacing pathSpacing = (SvgTextPathSpacing)textPath.Spacing.BaseVal; pathDrawing.DrawTextPath(_textContext, pathGeometry, pathOffset, stringFormat.Alignment, pathMethod, pathSpacing); pathDrawing.EndTextPath(); }
private void RenderTextPath(SvgTextPathElement textPath, ref Point ctp, double rotate, WpfTextPlacement placement) { if (textPath.ChildNodes == null || textPath.ChildNodes.Count == 0) { return; } SvgElement targetPath = textPath.ReferencedElement as SvgElement; if (targetPath == null) { return; } Geometry textGeometry = CreateGeometry(targetPath, true); if (textGeometry == null) { return; } PathGeometry pathGeometry = textGeometry as PathGeometry; if (pathGeometry == null) { pathGeometry = textGeometry.GetFlattenedPathGeometry(); } // If the path has a transform, apply it to get a transformed path... if (targetPath.HasAttribute("transform")) { var svgTransform = new SvgTransform(targetPath.GetAttribute("transform")); var svgMatrix = svgTransform.Matrix; if (!svgMatrix.IsIdentity) { pathGeometry.Transform = new MatrixTransform(svgMatrix.A, svgMatrix.B, svgMatrix.C, svgMatrix.D, svgMatrix.E, svgMatrix.F); var transformPath = new PathGeometry(); transformPath.AddGeometry(pathGeometry); pathGeometry = transformPath; } } WpfPathTextBuilder pathBuilder = new WpfPathTextBuilder(_textElement); pathBuilder.BeginTextPath(textPath); var comparer = StringComparison.OrdinalIgnoreCase; XmlNodeType nodeType = XmlNodeType.None; int nodeCount = textPath.ChildNodes.Count; for (int i = 0; i < nodeCount; i++) { XmlNode child = textPath.ChildNodes[i]; nodeType = child.NodeType; if (nodeType == XmlNodeType.Text) { var nodeText = GetText(textPath, child); if (i == (nodeCount - 1)) { // No need to render the last white space... if (nodeCount == 1) { if (nodeText.StartsWith(NonBreaking, StringComparison.OrdinalIgnoreCase)) { if (!nodeText.EndsWith(NonBreaking, StringComparison.OrdinalIgnoreCase)) { nodeText = nodeText.TrimEnd(); } } else if (nodeText.EndsWith(NonBreaking, StringComparison.OrdinalIgnoreCase)) { nodeText = nodeText.TrimStart(); } else { nodeText = nodeText.Trim(); } } else { if (!nodeText.EndsWith(NonBreaking, StringComparison.OrdinalIgnoreCase)) { nodeText = nodeText.TrimEnd(); } } } else if (i == 0) { nodeText = nodeText.Trim(); } RenderTextPath(textPath, pathBuilder, nodeText, new Point(ctp.X, ctp.Y), rotate, placement); } else if (nodeType == XmlNodeType.Element) { string nodeName = child.Name; if (string.Equals(nodeName, "tref", comparer)) { RenderTRefPath((SvgTRefElement)child, pathBuilder, ref ctp); } else if (string.Equals(nodeName, "tspan", comparer)) { RenderTSpanPath((SvgTSpanElement)child, pathBuilder, ref ctp); } } } WpfTextStringFormat stringFormat = GetTextStringFormat(textPath); //ISvgAnimatedLength pathOffset = textPath.StartOffset; //SvgTextPathMethod pathMethod = (SvgTextPathMethod)textPath.Method.BaseVal; //SvgTextPathSpacing pathSpacing = (SvgTextPathSpacing)textPath.Spacing.BaseVal; pathBuilder.RenderTextPath(_drawContext, pathGeometry, stringFormat.Alignment); pathBuilder.EndTextPath(); }
public void SetPosition(Point pos, SvgTextPathElement pathElement, SvgTextBaseElement textElement) { _contentPos = pos; _startOffset = this.GetStartOffset(pathElement, textElement); }