static TextElementFlags GetTextFlags(object ownerControl) { TextTrimming textTrimming = TextTrimming.None; TextWrapping textWrapping = TextWrapping.NoWrap; if (ownerControl is TextControl textControl) { textTrimming = textControl.TextTrimming; textWrapping = textControl.TextWrapping; } TextElementFlags flags = 0; switch (textTrimming) { case TextTrimming.None: flags |= TextElementFlags.NoTrimming; break; case TextTrimming.CharacterEllipsis: flags |= TextElementFlags.CharacterEllipsis; break; case TextTrimming.WordEllipsis: flags |= TextElementFlags.WordEllipsis; break; default: Debug.Fail($"Unknown trimming: {textTrimming}"); break; } switch (textWrapping) { case TextWrapping.WrapWithOverflow: flags |= TextElementFlags.WrapWithOverflow; break; case TextWrapping.NoWrap: flags |= TextElementFlags.NoWrap; break; case TextWrapping.Wrap: flags |= TextElementFlags.Wrap; break; default: Debug.Fail($"Unknown wrapping: {textWrapping}"); break; } return(flags); }
public static FrameworkElement Create(IClassificationFormatMap classificationFormatMap, string text, List<TextClassificationTag> tagsList, TextElementFlags flags) { bool useFastTextBlock = (flags & (TextElementFlags.TrimmingMask | TextElementFlags.WrapMask | TextElementFlags.FilterOutNewLines)) == (TextElementFlags.NoTrimming | TextElementFlags.NoWrap | TextElementFlags.FilterOutNewLines); bool filterOutNewLines = (flags & TextElementFlags.FilterOutNewLines) != 0; if (tagsList.Count != 0) { if (useFastTextBlock) { return new FastTextBlock((flags & TextElementFlags.NewFormatter) != 0, new TextSrc { text = ToString(text, filterOutNewLines), classificationFormatMap = classificationFormatMap, tagsList = tagsList.ToArray(), }); } var propsSpans = tagsList.Select(a => new TextRunPropertiesAndSpan(a.Span, classificationFormatMap.GetTextProperties(a.ClassificationType))); var textBlock = TextBlockFactory.Create(text, classificationFormatMap.DefaultTextProperties, propsSpans, TextBlockFactory.Flags.DisableSetTextBlockFontFamily | TextBlockFactory.Flags.DisableFontSize | (filterOutNewLines ? TextBlockFactory.Flags.FilterOutNewlines : 0)); textBlock.TextTrimming = GetTextTrimming(flags); textBlock.TextWrapping = GetTextWrapping(flags); return textBlock; } FrameworkElement fwElem; if (useFastTextBlock) { fwElem = new FastTextBlock((flags & TextElementFlags.NewFormatter) != 0) { Text = ToString(text, filterOutNewLines) }; } else { fwElem = new TextBlock { Text = ToString(text, filterOutNewLines), TextTrimming = GetTextTrimming(flags), TextWrapping = GetTextWrapping(flags), }; } return InitializeDefault(classificationFormatMap, fwElem); }
static TextWrapping GetTextWrapping(TextElementFlags flags) { switch (flags & TextElementFlags.WrapMask) { case TextElementFlags.WrapWithOverflow: return TextWrapping.WrapWithOverflow; case TextElementFlags.NoWrap: return TextWrapping.NoWrap; case TextElementFlags.Wrap: return TextWrapping.Wrap; default: throw new ArgumentOutOfRangeException(nameof(flags)); } }
static TextTrimming GetTextTrimming(TextElementFlags flags) { switch (flags & TextElementFlags.TrimmingMask) { case TextElementFlags.NoTrimming: return TextTrimming.None; case TextElementFlags.CharacterEllipsis: return TextTrimming.CharacterEllipsis; case TextElementFlags.WordEllipsis: return TextTrimming.WordEllipsis; default: throw new ArgumentOutOfRangeException(nameof(flags)); } }
/// <summary> /// Constructor /// </summary> /// <param name="textElementFactory"></param> /// <param name="version">Version number. It's incremented when the theme has changed to make sure the UI element is regenerated.</param> /// <param name="classificationFormatMap"></param> /// <param name="text"></param> /// <param name="tags"></param> /// <param name="textElementFlags"></param> /// <param name="opacity"></param> public TextBlockContentInfo(ITextElementFactory textElementFactory, int version, IClassificationFormatMap classificationFormatMap, string text, TextClassificationTag[] tags, TextElementFlags textElementFlags, double opacity) { TextElementFactory = textElementFactory ?? throw new ArgumentNullException(nameof(textElementFactory)); Version = version; ClassificationFormatMap = classificationFormatMap ?? throw new ArgumentNullException(nameof(classificationFormatMap)); Text = text ?? throw new ArgumentNullException(nameof(text)); Tags = tags ?? throw new ArgumentNullException(nameof(tags)); TextElementFlags = textElementFlags; Opacity = opacity; }
static TextWrapping GetTextWrapping(TextElementFlags flags) { switch (flags & TextElementFlags.WrapMask) { case TextElementFlags.WrapWithOverflow: return(TextWrapping.WrapWithOverflow); case TextElementFlags.NoWrap: return(TextWrapping.NoWrap); case TextElementFlags.Wrap: return(TextWrapping.Wrap); default: throw new ArgumentOutOfRangeException(nameof(flags)); } }
static TextTrimming GetTextTrimming(TextElementFlags flags) { switch (flags & TextElementFlags.TrimmingMask) { case TextElementFlags.NoTrimming: return(TextTrimming.None); case TextElementFlags.CharacterEllipsis: return(TextTrimming.CharacterEllipsis); case TextElementFlags.WordEllipsis: return(TextTrimming.WordEllipsis); default: throw new ArgumentOutOfRangeException(nameof(flags)); } }
public FrameworkElement CreateTextElement(IClassificationFormatMap classificationFormatMap, TextClassifierContext context, string contentType, TextElementFlags flags) { if (classificationFormatMap == null) throw new ArgumentNullException(nameof(classificationFormatMap)); if (context == null) throw new ArgumentNullException(nameof(context)); if (contentType == null) throw new ArgumentNullException(nameof(contentType)); var ct = contentTypeRegistryService.GetContentType(contentType); if (ct == null) throw new ArgumentException($"Invalid content type: {contentType}"); ITextClassifierAggregator aggregator; if (!toAggregator.TryGetValue(ct, out aggregator)) toAggregator.Add(ct, aggregator = textClassifierAggregatorService.Create(ct)); try { tagsList.AddRange(aggregator.GetTags(context)); return TextElementFactory.Create(classificationFormatMap, context.Text, tagsList, flags); } finally { tagsList.Clear(); } }
public FrameworkElement CreateTextElement(TreeViewNodeClassifierContext context, string contentType, TextElementFlags flags) => textElementProvider.CreateTextElement(classificationFormatMap, context, contentType, flags);
public static FrameworkElement Create(IClassificationFormatMap classificationFormatMap, string text, IList <TextClassificationTag> tags, TextElementFlags flags) { bool useFastTextBlock = (flags & (TextElementFlags.TrimmingMask | TextElementFlags.WrapMask | TextElementFlags.FilterOutNewLines)) == (TextElementFlags.NoTrimming | TextElementFlags.NoWrap | TextElementFlags.FilterOutNewLines); bool filterOutNewLines = (flags & TextElementFlags.FilterOutNewLines) != 0; if (tags.Count != 0) { if (useFastTextBlock) { return(new FastTextBlock((flags & TextElementFlags.NewFormatter) != 0, new TextSrc { text = ToString(WpfUnicodeUtils.ReplaceBadChars(text), filterOutNewLines), classificationFormatMap = classificationFormatMap, tagsList = tags.ToArray(), })); } var propsSpans = tags.Select(a => new TextRunPropertiesAndSpan(a.Span, classificationFormatMap.GetTextProperties(a.ClassificationType))); var textBlock = TextBlockFactory.Create(text, classificationFormatMap.DefaultTextProperties, propsSpans, TextBlockFactory.Flags.DisableSetTextBlockFontFamily | TextBlockFactory.Flags.DisableFontSize | (filterOutNewLines ? TextBlockFactory.Flags.FilterOutNewlines : 0)); textBlock.TextTrimming = GetTextTrimming(flags); textBlock.TextWrapping = GetTextWrapping(flags); return(textBlock); } FrameworkElement fwElem; if (useFastTextBlock) { fwElem = new FastTextBlock((flags & TextElementFlags.NewFormatter) != 0) { Text = ToString(WpfUnicodeUtils.ReplaceBadChars(text), filterOutNewLines) }; } else { fwElem = new TextBlock { Text = ToString(WpfUnicodeUtils.ReplaceBadChars(text), filterOutNewLines), TextTrimming = GetTextTrimming(flags), TextWrapping = GetTextWrapping(flags), }; } return(InitializeDefault(classificationFormatMap, fwElem)); }
public FrameworkElement Create(IClassificationFormatMap classificationFormatMap, string text, IList <TextClassificationTag> tags, TextElementFlags flags) => TextElementFactory.Create(classificationFormatMap, text, tags, flags);
public FrameworkElement CreateTextElement(DecompilerTabContentClassifierContext context, string contentType, TextElementFlags flags) => textElementProvider.CreateTextElement(classificationFormatMap, context, contentType, flags);
public TextBlockContentInfo Create(int version, IClassificationFormatMap classificationFormatMap, TextClassifierContext context, string contentType, TextElementFlags flags, double opacity) { if (classificationFormatMap == null) { throw new ArgumentNullException(nameof(classificationFormatMap)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } if (contentType == null) { throw new ArgumentNullException(nameof(contentType)); } var ct = contentTypeRegistryService.GetContentType(contentType); if (ct == null) { throw new ArgumentException($"Invalid content type: {contentType}"); } if (!toAggregator.TryGetValue(ct, out var aggregator)) { toAggregator.Add(ct, aggregator = textClassifierAggregatorService.Create(ct)); } var tags = aggregator.GetTags(context).ToArray(); return(new TextBlockContentInfo(textElementFactory, version, classificationFormatMap, context.Text, tags, flags, opacity)); }
public FrameworkElement CreateTextElement(IClassificationFormatMap classificationFormatMap, TextClassifierContext context, string contentType, TextElementFlags flags) { if (classificationFormatMap == null) { throw new ArgumentNullException(nameof(classificationFormatMap)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } if (contentType == null) { throw new ArgumentNullException(nameof(contentType)); } var ct = contentTypeRegistryService.GetContentType(contentType); if (ct == null) { throw new ArgumentException($"Invalid content type: {contentType}"); } ITextClassifierAggregator aggregator; if (!toAggregator.TryGetValue(ct, out aggregator)) { toAggregator.Add(ct, aggregator = textClassifierAggregatorService.Create(ct)); } try { tagsList.AddRange(aggregator.GetTags(context)); return(TextElementFactory.Create(classificationFormatMap, context.Text, tagsList, flags)); } finally { tagsList.Clear(); } }