public override IText AddText(string text, double fontSize, SolidColorBrush brush) { if (cachedTypeface == null) { cachedTypeface = CreateTypeface(); } GlobalTextRunProperties p = new GlobalTextRunProperties { typeface = cachedTypeface, fontRenderingEmSize = fontSize, foregroundBrush = brush, cultureInfo = CultureInfo.CurrentCulture }; MyTextSource myTextSource = new MyTextSource { text = text, textRunProperties = p }; TextLine line = formatter.FormatLine(myTextSource, 0, 500, new MyTextParagraphProperties { defaultTextRunProperties = p }, null); MyText myText = new MyText { line = line, parent = this }; texts.Add(myText); return(myText); }
public static TextRunProperties CreateGlobalTextRunProperties() { var fe = new FrameworkElement(); var p = new GlobalTextRunProperties { typeface = CreateTypeface(), fontRenderingEmSize = GetFontSize(), foregroundBrush = (Brush)fe.GetValue(Control.ForegroundProperty), cultureInfo = CultureInfo.CurrentCulture }; return(p); }
public override IText AddText(string text, double fontSize, SolidColorBrush brush) { if (cachedTypeface == null) { cachedTypeface = CreateTypeface(); } GlobalTextRunProperties p = new GlobalTextRunProperties { typeface = cachedTypeface, fontRenderingEmSize = fontSize, foregroundBrush = brush, cultureInfo = CultureInfo.CurrentCulture }; MyTextSource myTextSource = new MyTextSource { text = text, textRunProperties = p }; TextLine line = formatter.FormatLine(myTextSource, 0, 500, new MyTextParagraphProperties {defaultTextRunProperties = p}, null); MyText myText = new MyText { line = line, parent = this }; texts.Add(myText); return myText; }
/// <summary> /// /// </summary> /// <param name="element"></param> /// <param name="text"></param> /// <param name="typeface"></param> /// <param name="emSize"></param> /// <param name="foreground"></param> /// <returns></returns> public static TextLine CreateTextLine(FrameworkElement element, string text, Typeface typeface, double?emSize, Brush foreground) { if (element == null) { throw new ArgumentNullException("element"); } if (text == null) { throw new ArgumentNullException("text"); } if (typeface == null) { typeface = element.CreateTypeface(); } if (emSize == null) { emSize = TextBlock.GetFontSize(element); } if (foreground == null) { foreground = TextBlock.GetForeground(element); } #if DOTNET4 var formatter = Create(element); var textRunProps = new GlobalTextRunProperties { typeface = typeface, foregroundBrush = foreground, fontRenderingEmSize = emSize.Value, cultureInfo = CultureInfo.CurrentCulture }; var line = formatter.FormatLine( new SimpleTextSource(text, textRunProps), 0, 32000, new VisualLineTextParagraphProperties { defaultTextRunProperties = textRunProps }, null); return(line); #else if (TextFormattingModeProperty != null) { object formattingMode = element.GetValue(TextFormattingModeProperty); return((FormattedText)Activator.CreateInstance( typeof(FormattedText), text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, emSize, foreground, null, formattingMode )); } else { return(new FormattedText( text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, emSize.Value, foreground )); } #endif }