Exemplo n.º 1
0
        // ------------------------------------------------------------------ 
        // 
        //  TextSource Implementation
        // 
        // -----------------------------------------------------------------

        #region TextSource Implementation
 
        // ------------------------------------------------------------------
        // Get a text run at specified text source position. 
        // ------------------------------------------------------------------ 
        public override TextRun GetTextRun(int dcp)
        { 
            TextRun run = null;
            StaticTextPointer position = _owner.TextContainer.CreateStaticPointerAtOffset(dcp);

            switch (position.GetPointerContext(LogicalDirection.Forward)) 
            {
                case TextPointerContext.Text: 
                    run = HandleText(position); 
                    break;
 
                case TextPointerContext.ElementStart:
                    run = HandleElementStartEdge(position);
                    break;
 
                case TextPointerContext.ElementEnd:
                    run = HandleElementEndEdge(position); 
                    break; 

                case TextPointerContext.EmbeddedElement: 
                    run = HandleInlineObject(position, dcp);
                    break;

                case TextPointerContext.None: 
                    run = new TextEndOfParagraph(_syntheticCharacterLength);
                    break; 
            } 
            Debug.Assert(run != null, "TextRun has not been created.");
            Debug.Assert(run.Length > 0, "TextRun has to have positive length."); 
            return run;
        }
Exemplo n.º 2
0
        // ------------------------------------------------------------------
        //
        //  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;
        } 
Exemplo n.º 3
0
 public override TextRun GetTextRun(int textSourceCharacterIndex)
 {
     if (this._itemsCount <= 0)
     {
         this.UniscribeScriptItemizeOpenType();
     }
     TextRun result;
     if (textSourceCharacterIndex < 0)
     {
         result = new TextEndOfParagraph(1);
     }
     else
     {
         if (textSourceCharacterIndex < this.Text.Length)
         {
             for (int index = 0; index < this._itemsCount - 1; index++)
             {
                 if (this._items[index].iCharPos <= textSourceCharacterIndex && this._items[index + 1].iCharPos > textSourceCharacterIndex)
                 {
                     result = this.MakeTextCharactors(index, textSourceCharacterIndex, this._items[index + 1].iCharPos - textSourceCharacterIndex);
                     return result;
                 }
             }
             result = this.MakeTextCharactors(this._itemsCount - 1, textSourceCharacterIndex, this.Text.Length - textSourceCharacterIndex);
         }
         else
         {
             result = new TextEndOfParagraph(1);
         }
     }
     return result;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Get a text run at specified text source position.
        /// </summary>
        public override TextRun GetTextRun(int dcp)
        {
            TextRun run = null;
            StaticTextPointer position = _owner.Host.TextContainer.CreateStaticPointerAtOffset(dcp);

            switch (position.GetPointerContext(LogicalDirection.Forward))
            {
                case TextPointerContext.Text:
                    run = HandleText(position);
                    break;

                case TextPointerContext.None:
                    run = new TextEndOfParagraph(_syntheticCharacterLength);
                    break;

                case TextPointerContext.ElementStart:
                case TextPointerContext.ElementEnd:
                case TextPointerContext.EmbeddedElement:
                default:
                    Invariant.Assert(false, "Unsupported position type.");
                    break;
            }
            Invariant.Assert(run != null, "TextRun has not been created.");
            Invariant.Assert(run.Length > 0, "TextRun has to have positive length.");

            return run;
        }