private void RenderTextPath(SvgTextContentElement element, WpfPathTextBuilder pathBuilder, string text, Point origin, double rotate, WpfTextPlacement placement) { if (string.IsNullOrWhiteSpace(text)) { return; } WpfSvgPaint fillPaint = new WpfSvgPaint(_context, element, "fill"); WpfSvgPaint strokePaint = new WpfSvgPaint(_context, element, "stroke"); Brush textBrush = fillPaint.GetBrush(); Pen textPen = strokePaint.GetPen(); if (textBrush == null && textPen == null) { return; } double emSize = GetComputedFontSize(element); var fontFamilyInfo = GetTextFontFamilyInfo(element); WpfTextStringFormat stringFormat = GetTextStringFormat(element); // Fix the use of Postscript fonts... WpfFontFamilyVisitor fontFamilyVisitor = _context.FontFamilyVisitor; if (!string.IsNullOrWhiteSpace(_actualFontName) && fontFamilyVisitor != null) { WpfFontFamilyInfo familyInfo = fontFamilyVisitor.Visit(_actualFontName, fontFamilyInfo, _context); if (familyInfo != null && !familyInfo.IsEmpty) { fontFamilyInfo = familyInfo; } } // Create the text builder object defined by the font family information WpfTextBuilder textBuilder = WpfTextBuilder.Create(fontFamilyInfo, this.TextCulture, emSize); textBuilder.TextDecorations = GetTextDecoration(element); textBuilder.TextAlignment = stringFormat.Alignment; // This is character-by-character placement, text-alignment will distort the view... textBuilder.TextAlignment = TextAlignment.Left; // Create the path-run information holder for this render request... WpfPathTextRun textPathRun = new WpfPathTextRun(element, textBuilder); // Finally, register the path-run with path builder... pathBuilder.AddTextRun(textPathRun, text, origin, textBrush, textPen); }
public void AddTextRun(WpfPathTextRun pathTextRun, string text, Point textPos, Brush textBrush, Pen textPen) { if (string.IsNullOrWhiteSpace(text)) { return; } if (_pathChars == null) { _pathChars = new List <WpfPathChar>(); } if (_endsWhitespace) { text = text.TrimStart(); _endsWhitespace = text.EndsWith(" ", StringComparison.OrdinalIgnoreCase); } else { _endsWhitespace = text.EndsWith(" ", StringComparison.OrdinalIgnoreCase); } pathTextRun.Initialize(text, textBrush, textPen); pathTextRun.SetPosition(textPos, _textPathElement, _textElement); WpfTextBuilder contentBuilder = pathTextRun.Builder; SvgTextContentElement contentElement = pathTextRun.Element; foreach (char ch in text) { var textChar = ch.ToString(); var textSize = contentBuilder.MeasureText(contentElement, textChar, true); _textLength += textSize.Width; _pathChars.Add(new WpfPathChar(textChar, textPos, textSize, _pathTextRuns.Count)); } _pathTextRuns.Add(pathTextRun); }