/// <summary> /// Creates a text style run that has overrides applied. Only overrides with equal TextStyle. /// If optimizeForShaping is <c>true</c> Foreground is ignored. /// </summary> /// <param name="text">The text to create the run for.</param> /// <param name="defaultTextStyle">The default text style for segments that don't have an override.</param> /// <param name="textStyleOverrides">The text style overrides.</param> /// <returns> /// The created text style run. /// </returns> private static TextStyleRun CreateTextStyleRunWithOverride(ReadOnlySlice <char> text, TextStyle defaultTextStyle, IReadOnlyList <TextStyleRun> textStyleOverrides) { if (textStyleOverrides == null || textStyleOverrides.Count == 0) { return(new TextStyleRun(new TextPointer(text.Start, text.Length), defaultTextStyle)); } var currentTextStyle = defaultTextStyle; var hasOverride = false; var i = 0; var length = 0; for (; i < textStyleOverrides.Count; i++) { var styleOverride = textStyleOverrides[i]; var textPointer = styleOverride.TextPointer; if (textPointer.End < text.Start) { continue; } if (textPointer.Start > text.End) { length = text.Length; break; } if (textPointer.Start > text.Start) { if (styleOverride.Style.TextFormat != currentTextStyle.TextFormat || !currentTextStyle.Foreground.Equals(styleOverride.Style.Foreground)) { length = Math.Min(Math.Abs(textPointer.Start - text.Start), text.Length); break; } } length += Math.Min(text.Length - length, textPointer.Length); if (hasOverride) { continue; } hasOverride = true; currentTextStyle = styleOverride.Style; } if (length < text.Length && i == textStyleOverrides.Count) { if (currentTextStyle.Foreground.Equals(defaultTextStyle.Foreground) && currentTextStyle.TextFormat == defaultTextStyle.TextFormat) { length = text.Length; } } if (length != text.Length) { text = text.Take(length); } return(new TextStyleRun(new TextPointer(text.Start, length), currentTextStyle)); }
public ShapedTextRun(ReadOnlySlice <char> text, TextStyle style) : this( TextShaper.Current.ShapeText(text, style.TextFormat), style) { }
public ShapedTextRun(GlyphRun glyphRun, TextStyle style) { Text = glyphRun.Characters; Style = style; GlyphRun = glyphRun; }
public TextCharacters(ReadOnlySlice <char> text, TextStyle style) { Text = text; Style = style; }