Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        public static FrameworkElement Create(IClassificationFormatMap classificationFormatMap, string text, List <TextClassificationTag> tagsList, bool useNewFormatter, bool useEllipsis = false, bool filterOutNewLines = true, TextWrapping textWrapping = TextWrapping.NoWrap)
        {
            if (tagsList.Count != 0)
            {
                if (!useEllipsis && filterOutNewLines)
                {
                    return(new FastTextBlock(useNewFormatter, new TextSrc {
                        text = ToString(text, filterOutNewLines),
                        classificationFormatMap = classificationFormatMap,
                        tagsList = tagsList.ToArray(),
                    }));
                }

                var propsSpans = tagsList.Select(a => new TextRunPropertiesAndSpan(a.Span, classificationFormatMap.GetTextProperties(a.ClassificationType)));
                return(TextBlockFactory.Create(text, classificationFormatMap.DefaultTextProperties, propsSpans, TextBlockFactory.Flags.DisableSetTextBlockFontFamily | TextBlockFactory.Flags.DisableFontSize));
            }

            FrameworkElement fwElem;

            if (!useEllipsis && filterOutNewLines)
            {
                fwElem = new FastTextBlock(useNewFormatter)
                {
                    Text = ToString(text, filterOutNewLines)
                };
            }
            else
            {
                fwElem = new TextBlock {
                    Text         = ToString(text, filterOutNewLines),
                    TextTrimming = TextTrimming.CharacterEllipsis,
                    TextWrapping = textWrapping,
                };
            }
            return(InitializeDefault(classificationFormatMap, fwElem));
        }
Ejemplo n.º 3
0
 public ParaProps(FastTextBlock tb)
 {
     this.tb = tb;
     props   = new TextProps(tb);
 }
Ejemplo n.º 4
0
 public void UpdateParent(FastTextBlock ftb)
 {
     text  = ftb.Text;
     props = new TextProps(ftb);
 }
Ejemplo n.º 5
0
 public TextProps(FastTextBlock tb) => this.tb = tb;
Ejemplo n.º 6
0
 public void UpdateParent(FastTextBlock ftb) => parent = ftb;