// ------------------------------------------------------------------
        //
        //  TextSource Implementation
        //
        // ------------------------------------------------------------------

        #region TextSource Implementation

        // ------------------------------------------------------------------
        // Get a text run at specified text source position.
        // ------------------------------------------------------------------
        public override TextRun GetTextRun(int dcp)
        {
            Debug.Assert(dcp >= 0, "Character index must be non-negative.");

            TextRun run;

            // There is only one run of text.
            if (dcp < _content.Length)
            {
                // LineLayout may ask for dcp != 0. This case may only happen during partial
                // validation of TextRunCache.
                // Example:
                //  1) TextRunCache and LineMetrics array were created during measure process.
                //  2) Before OnRender is called somebody invalidates render only property.
                //     This invalidates TextRunCache.
                //  3) Before OnRender is called InputHitTest is invoked. Because LineMetrics
                //     array is valid, we don't have to recreate all lines. There is only
                //     need to recreate the N-th line (line that has been hit).
                //     During line recreation LineLayout will not refetch all runs from the
                //     beginning of TextBlock control - it will ask for the run at the beginning
                //     of the current line.
                // For this reason set 'offsetToFirstChar' to 'dcp' value.
                run = new TextCharacters(_content, dcp, _content.Length - dcp, _textProps);
            }
            else
            {
                run = new TextEndOfParagraph(_syntheticCharacterLength);
            }

            return(run);
        }
示例#2
0
        private TextRun MakeTextCharactors(int index, int textSourceCharacterIndex, int length)
        {
            TextCharacters textCharacters = new TextCharacters(this.Text, textSourceCharacterIndex, length, this.JapaneseTextRunProperties);

            this.UniscribeScriptShapeOpenType(this.Text, index, textSourceCharacterIndex, length);
            return(textCharacters);
        }
        // Token: 0x06006607 RID: 26119 RVA: 0x001CB000 File Offset: 0x001C9200
        private TextRun HandleElementStartEdge(StaticTextPointer position)
        {
            TextElement textElement = (TextElement)position.GetAdjacentElement(LogicalDirection.Forward);
            TextRun     result;

            if (textElement is LineBreak)
            {
                result = new TextEndOfLine(ComplexLine._elementEdgeCharacterLength * 2);
            }
            else if (textElement.IsEmpty)
            {
                TextRunProperties textRunProperties = new TextProperties(textElement, position, false, true, base.PixelsPerDip);
                char[]            array             = new char[ComplexLine._elementEdgeCharacterLength * 2];
                array[0] = '​';
                array[1] = '​';
                result   = new TextCharacters(array, 0, array.Length, textRunProperties);
            }
            else
            {
                Inline inline = textElement as Inline;
                if (inline == null)
                {
                    result = new TextHidden(ComplexLine._elementEdgeCharacterLength);
                }
                else
                {
                    DependencyObject parent         = inline.Parent;
                    FlowDirection    flowDirection  = inline.FlowDirection;
                    FlowDirection    flowDirection2 = flowDirection;
                    if (parent != null)
                    {
                        flowDirection2 = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty);
                    }
                    TextDecorationCollection textDecorations = DynamicPropertyReader.GetTextDecorations(inline);
                    if (flowDirection != flowDirection2)
                    {
                        if (textDecorations == null || textDecorations.Count == 0)
                        {
                            result = new TextSpanModifier(ComplexLine._elementEdgeCharacterLength, null, null, flowDirection);
                        }
                        else
                        {
                            result = new TextSpanModifier(ComplexLine._elementEdgeCharacterLength, textDecorations, inline.Foreground, flowDirection);
                        }
                    }
                    else if (textDecorations == null || textDecorations.Count == 0)
                    {
                        result = new TextHidden(ComplexLine._elementEdgeCharacterLength);
                    }
                    else
                    {
                        result = new TextSpanModifier(ComplexLine._elementEdgeCharacterLength, textDecorations, inline.Foreground);
                    }
                }
            }
            return(result);
        }
示例#4
0
        internal override void BuildTextRun(IList <TextRun> textRuns)
        {
            var text = (Text ?? "").AsMemory();

            var textRunProperties = CreateTextRunProperties();

            var textCharacters = new TextCharacters(text, textRunProperties);

            textRuns.Add(textCharacters);
        }
示例#5
0
        internal override void BuildTextRun(IList <TextRun> textRuns)
        {
            var text = Environment.NewLine.AsMemory();

            var textRunProperties = CreateTextRunProperties();

            var textCharacters = new TextCharacters(text, textRunProperties);

            textRuns.Add(textCharacters);
        }
示例#6
0
 private FormattedTextSymbols GetFormattedTextSymbols(TextCharacters textRun, CharacterBufferRange chars, int bidiLevel)
 {
     return(new FormattedTextSymbols(
                _fullText.Formatter.GlyphingCache,
                textRun,
                chars,
                (bidiLevel & 1) == 1,              //rightToLeft
                TextFormatterImp.ToIdeal,          // scalingFactor
                (float)_fullText.TextStore.Settings.TextSource.PixelsPerDip,
                _textFormattingMode,
                false));             // isSideways
 }
示例#7
0
        // Token: 0x0600666D RID: 26221 RVA: 0x001CC3BC File Offset: 0x001CA5BC
        public override TextRun GetTextRun(int dcp)
        {
            TextRun textRun;

            if (dcp < this._content.Length)
            {
                textRun = new TextCharacters(this._content, dcp, this._content.Length - dcp, this._textProps);
            }
            else
            {
                textRun = new TextEndOfParagraph(Line._syntheticCharacterLength);
            }
            if (textRun.Properties != null)
            {
                textRun.Properties.PixelsPerDip = base.PixelsPerDip;
            }
            return(textRun);
        }
示例#8
0
        internal override void BuildTextRun(IList <TextRun> textRuns)
        {
            if (Inlines.HasComplexContent)
            {
                foreach (var inline in Inlines)
                {
                    inline.BuildTextRun(textRuns);
                }
            }
            else
            {
                if (Inlines.Text is string text)
                {
                    var textRunProperties = CreateTextRunProperties();

                    var textCharacters = new TextCharacters(text.AsMemory(), textRunProperties);

                    textRuns.Add(textCharacters);
                }
            }
        }
        public override TextRun CreateTextRun(int startVisualColumn, ITextRunConstructionContext context)
        {
            var foreground = ThemeManager.Current.GetThemeColorBrush(ThemeColorStyle.DefaultForeground);
            var background = ThemeManager.Current.GetThemeColorBrush(ThemeColorStyle.DefaultBackground);

            TextRunProperties.SetBackgroundBrush(background);
            TextRunProperties.SetForegroundBrush(foreground);

            var spacesBuilder = new StringBuilder();

            for (var i = 0; i < VisualLength - 1; i++)
            {
                spacesBuilder.Append(Symbols.Space);
            }

            spacesBuilder.Append(Symbols.VerticalBar);

            var textCharacters = new TextCharacters(spacesBuilder.ToString(), TextRunProperties);

            return(textCharacters);
        }
示例#10
0
            public override TextRun GetTextRun(int textSourceCharacterIndex)
            {
                var index = textSourceCharacterIndex;

                if (runs.ContainsKey(index))
                {
                    var run = runs[index];
                    runs.Remove(index);
                    return(run);
                }

                if (index >= text.Length || text[index] == '\r' || text[index] == '\n')
                {
                    if (index < text.Length && text[index] != '\r')
                    {
                        return(new TextCharacters(" ", null));
                    }
                    else
                    {
                        return(new TextEndOfParagraph(1));
                    }
                }

                int           defaultTextLength, tokenLength;
                TextTokenType tokenType;

                if (!tokens.Find(index, out defaultTextLength, out tokenType, out tokenLength))
                {
                    Debug.Fail("Could not find token info");
                    return(new TextCharacters(" ", null));
                }

                TextCharacters defaultRun = null, tokenRun = null;

                if (defaultTextLength != 0)
                {
                    var defaultText = text.Substring(index, defaultTextLength);

                    defaultRun = new TextCharacters(defaultText, new TextProps {
                        background = (Brush)parent.GetValue(TextElement.BackgroundProperty),
                        foreground = TextElement.GetForeground(parent),
                        typeface   = new Typeface(
                            TextElement.GetFontFamily(parent),
                            TextElement.GetFontStyle(parent),
                            TextElement.GetFontWeight(parent),
                            TextElement.GetFontStretch(parent)
                            ),
                        fontSize = TextElement.GetFontSize(parent),
                    });
                }
                index += defaultTextLength;

                if (tokenLength != 0)
                {
                    var hlColor   = GetColor(tokenType);
                    var tokenText = text.Substring(index, tokenLength);

                    var textProps = new TextProps();
                    textProps.fontSize = TextElement.GetFontSize(parent);

                    if (hlColor.Foreground != null)
                    {
                        textProps.foreground = hlColor.Foreground.GetBrush(null);
                    }
                    else
                    {
                        textProps.foreground = TextElement.GetForeground(parent);
                    }

                    if (hlColor.Background != null)
                    {
                        textProps.background = hlColor.Background.GetBrush(null);
                    }
                    else
                    {
                        textProps.background = (Brush)parent.GetValue(TextElement.BackgroundProperty);
                    }

                    textProps.typeface = new Typeface(
                        TextElement.GetFontFamily(parent),
                        hlColor.FontStyle ?? TextElement.GetFontStyle(parent),
                        hlColor.FontWeight ?? TextElement.GetFontWeight(parent),
                        TextElement.GetFontStretch(parent)
                        );

                    tokenRun = new TextCharacters(tokenText, textProps);
                }

                Debug.Assert(defaultRun != null || tokenRun != null);
                if ((defaultRun != null) ^ (tokenRun != null))
                {
                    return(defaultRun ?? tokenRun);
                }
                else
                {
                    runs[index] = tokenRun;
                    return(defaultRun);
                }
            }
示例#11
0
        // ------------------------------------------------------------------
        // Fetch the next run at element open edge position.
        //
        //      position - current position in the text array
        // ------------------------------------------------------------------
        private TextRun HandleElementStartEdge(StaticTextPointer position)
        {
            Debug.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart, "TextPointer does not point to element start edge.");

            //

            TextRun     run     = null;
            TextElement element = (TextElement)position.GetAdjacentElement(LogicalDirection.Forward);

            Debug.Assert(element != null, "Cannot use ITextContainer that does not provide TextElement instances.");

            if (element is LineBreak)
            {
                run = new TextEndOfLine(_elementEdgeCharacterLength * 2);
            }
            else if (element.IsEmpty)
            {
                // Empty TextElement should affect line metrics.
                // TextFormatter does not support this feature right now, so as workaround
                // TextRun with ZERO WIDTH SPACE is used.
                TextRunProperties textProps  = new TextProperties(element, position, false /* inline objects */, true /* get background */);
                char[]            textBuffer = new char[_elementEdgeCharacterLength * 2];
                textBuffer[0] = (char)0x200B;
                textBuffer[1] = (char)0x200B;
                run           = new TextCharacters(textBuffer, 0, textBuffer.Length, textProps);
            }
            else
            {
                Inline inline = element as Inline;
                if (inline == null)
                {
                    run = new TextHidden(_elementEdgeCharacterLength);
                }
                else
                {
                    DependencyObject parent = inline.Parent;
                    FlowDirection    inlineFlowDirection = inline.FlowDirection;
                    FlowDirection    parentFlowDirection = inlineFlowDirection;

                    if (parent != null)
                    {
                        parentFlowDirection = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty);
                    }

                    TextDecorationCollection inlineTextDecorations = DynamicPropertyReader.GetTextDecorations(inline);

                    if (inlineFlowDirection != parentFlowDirection)
                    {
                        // Inline's flow direction is different from its parent. Need to create new TextSpanModifier with flow direction
                        if (inlineTextDecorations == null || inlineTextDecorations.Count == 0)
                        {
                            run = new TextSpanModifier(
                                _elementEdgeCharacterLength,
                                null,
                                null,
                                inlineFlowDirection
                                );
                        }
                        else
                        {
                            run = new TextSpanModifier(
                                _elementEdgeCharacterLength,
                                inlineTextDecorations,
                                inline.Foreground,
                                inlineFlowDirection
                                );
                        }
                    }
                    else
                    {
                        if (inlineTextDecorations == null || inlineTextDecorations.Count == 0)
                        {
                            run = new TextHidden(_elementEdgeCharacterLength);
                        }
                        else
                        {
                            run = new TextSpanModifier(
                                _elementEdgeCharacterLength,
                                inlineTextDecorations,
                                inline.Foreground
                                );
                        }
                    }
                }
            }
            return(run);
        }
            public override TextRun GetTextRun(int textSourceCharacterIndex)
            {
                var index = textSourceCharacterIndex;

                if (runs.ContainsKey(index))
                {
                    var run = runs[index];
                    runs.Remove(index);
                    return(run);
                }

                if (index >= text.Length)
                {
                    return(new TextEndOfParagraph(1));
                }
                char c = text[index];

                if (c == '\r' || c == '\n' || c == '\u0085' || c == '\u2028' || c == '\u2029')
                {
                    int nlLen = c == '\r' && index + 1 < text.Length && text[index + 1] == '\n' ? 2 : 1;
                    return(new TextEndOfParagraph(nlLen));
                }

                int    defaultTextLength, tokenLength;
                object color;

                if (!cachedTextColorsCollection.Find(index, out defaultTextLength, out color, out tokenLength))
                {
                    Debug.Fail("Could not find token info");
                    return(new TextCharacters(" ", GetDefaultTextRunProperties()));
                }

                TextCharacters defaultRun = null, tokenRun = null;

                if (defaultTextLength != 0)
                {
                    var defaultText = text.Substring(index, defaultTextLength);

                    defaultRun = new TextCharacters(defaultText, GetDefaultTextRunProperties());
                }
                index += defaultTextLength;

                if (tokenLength != 0)
                {
                    var tc        = GetTextColor(themeManager.Theme, color);
                    var tokenText = text.Substring(index, tokenLength);

                    var textProps = new TextProps();
                    textProps.fontSize = TextElement.GetFontSize(parent);

                    textProps.foreground = tc.Foreground ?? TextElement.GetForeground(parent);
                    textProps.background = tc.Background ?? (Brush)parent.GetValue(TextElement.BackgroundProperty);

                    textProps.typeface = new Typeface(
                        TextElement.GetFontFamily(parent),
                        tc.FontStyle ?? TextElement.GetFontStyle(parent),
                        tc.FontWeight ?? TextElement.GetFontWeight(parent),
                        TextElement.GetFontStretch(parent)
                        );

                    tokenRun = new TextCharacters(tokenText.Length == 0 ? " " : tokenText, textProps);
                }

                Debug.Assert(defaultRun != null || tokenRun != null);
                if ((defaultRun != null) ^ (tokenRun != null))
                {
                    return(defaultRun ?? tokenRun);
                }
                else
                {
                    runs[index] = tokenRun;
                    return(defaultRun);
                }
            }
示例#13
0
        /// <summary>
        /// Return next TextRun at element edge start position
        /// </summary>
        /// <param name="position">
        /// Current position in text array
        /// </param>
        protected TextRun HandleElementStartEdge(StaticTextPointer position)
        {
            Invariant.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart, "TextPointer does not point to element start edge.");

            //      In the future, handle visibility collapsed.
            TextRun     run     = null;
            TextElement element = (TextElement)position.GetAdjacentElement(LogicalDirection.Forward);

            Debug.Assert(element != null, "Cannot use ITextContainer that does not provide TextElement instances.");

            Invariant.Assert(!(element is Block), "We do not expect any Blocks inside Paragraphs");

            // Treat figure and floaters as special hidden runs.
            if (element is Figure || element is Floater)
            {
                // Get the length of the element
                int cch = TextContainerHelper.GetElementLength(_paraClient.Paragraph.StructuralCache.TextContainer, element);
                // Create special hidden run.
                run = new FloatingRun(cch, element is Figure);
                if (element is Figure)
                {
                    _hasFigures = true;
                }
                else
                {
                    _hasFloaters = true;
                }
            }
            else if (element is LineBreak)
            {
                int cch = TextContainerHelper.GetElementLength(_paraClient.Paragraph.StructuralCache.TextContainer, element);
                run = new LineBreakRun(cch, PTS.FSFLRES.fsflrSoftBreak);
            }
            else if (element.IsEmpty)
            {
                // Empty TextElement should affect line metrics.
                // TextFormatter does not support this feature right now, so as workaround
                // TextRun with ZERO WIDTH SPACE is used.
                TextProperties textProps = new TextProperties(element, position, false /* inline objects */, true /* get background */,
                                                              _paraClient.Paragraph.StructuralCache.TextFormatterHost.PixelsPerDip);

                char[] textBuffer = new char[_elementEdgeCharacterLength * 2];

                // Assert that _elementEdgeCharacterLength is 1 before we use hard-coded indices
                Invariant.Assert(_elementEdgeCharacterLength == 1, "Expected value of _elementEdgeCharacterLength is 1");

                textBuffer[0] = (char)0x200B;
                textBuffer[1] = (char)0x200B;

                run = new TextCharacters(textBuffer, 0, textBuffer.Length, textProps);
            }
            else
            {
                Inline           inline = (Inline)element;
                DependencyObject parent = inline.Parent;

                FlowDirection inlineFlowDirection = inline.FlowDirection;
                FlowDirection parentFlowDirection = inlineFlowDirection;

                TextDecorationCollection inlineTextDecorations = DynamicPropertyReader.GetTextDecorations(inline);

                if (parent != null)
                {
                    parentFlowDirection = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty);
                }

                if (inlineFlowDirection != parentFlowDirection)
                {
                    // Inline's flow direction is different from its parent. Need to create new TextSpanModifier with flow direction
                    if (inlineTextDecorations == null || inlineTextDecorations.Count == 0)
                    {
                        run = new TextSpanModifier(
                            _elementEdgeCharacterLength,
                            null,
                            null,
                            inlineFlowDirection
                            );
                    }
                    else
                    {
                        run = new TextSpanModifier(
                            _elementEdgeCharacterLength,
                            inlineTextDecorations,
                            inline.Foreground,
                            inlineFlowDirection
                            );
                    }
                }
                else
                {
                    if (inlineTextDecorations == null || inlineTextDecorations.Count == 0)
                    {
                        run = new TextHidden(_elementEdgeCharacterLength);
                    }
                    else
                    {
                        run = new TextSpanModifier(
                            _elementEdgeCharacterLength,
                            inlineTextDecorations,
                            inline.Foreground
                            );
                    }
                }
            }
            return(run);
        }
        // Token: 0x0600688E RID: 26766 RVA: 0x001D7E38 File Offset: 0x001D6038
        protected TextRun HandleElementStartEdge(StaticTextPointer position)
        {
            Invariant.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart, "TextPointer does not point to element start edge.");
            TextElement textElement = (TextElement)position.GetAdjacentElement(LogicalDirection.Forward);

            Invariant.Assert(!(textElement is Block), "We do not expect any Blocks inside Paragraphs");
            TextRun result;

            if (textElement is Figure || textElement is Floater)
            {
                int elementLength = TextContainerHelper.GetElementLength(this._paraClient.Paragraph.StructuralCache.TextContainer, textElement);
                result = new FloatingRun(elementLength, textElement is Figure);
                if (textElement is Figure)
                {
                    this._hasFigures = true;
                }
                else
                {
                    this._hasFloaters = true;
                }
            }
            else if (textElement is LineBreak)
            {
                int elementLength2 = TextContainerHelper.GetElementLength(this._paraClient.Paragraph.StructuralCache.TextContainer, textElement);
                result = new LineBreakRun(elementLength2, PTS.FSFLRES.fsflrSoftBreak);
            }
            else if (textElement.IsEmpty)
            {
                TextProperties textRunProperties = new TextProperties(textElement, position, false, true, this._paraClient.Paragraph.StructuralCache.TextFormatterHost.PixelsPerDip);
                char[]         array             = new char[LineBase._elementEdgeCharacterLength * 2];
                Invariant.Assert(LineBase._elementEdgeCharacterLength == 1, "Expected value of _elementEdgeCharacterLength is 1");
                array[0] = '​';
                array[1] = '​';
                result   = new TextCharacters(array, 0, array.Length, textRunProperties);
            }
            else
            {
                Inline                   inline          = (Inline)textElement;
                DependencyObject         parent          = inline.Parent;
                FlowDirection            flowDirection   = inline.FlowDirection;
                FlowDirection            flowDirection2  = flowDirection;
                TextDecorationCollection textDecorations = DynamicPropertyReader.GetTextDecorations(inline);
                if (parent != null)
                {
                    flowDirection2 = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty);
                }
                if (flowDirection != flowDirection2)
                {
                    if (textDecorations == null || textDecorations.Count == 0)
                    {
                        result = new TextSpanModifier(LineBase._elementEdgeCharacterLength, null, null, flowDirection);
                    }
                    else
                    {
                        result = new TextSpanModifier(LineBase._elementEdgeCharacterLength, textDecorations, inline.Foreground, flowDirection);
                    }
                }
                else if (textDecorations == null || textDecorations.Count == 0)
                {
                    result = new TextHidden(LineBase._elementEdgeCharacterLength);
                }
                else
                {
                    result = new TextSpanModifier(LineBase._elementEdgeCharacterLength, textDecorations, inline.Foreground);
                }
            }
            return(result);
        }