textandlocutils/inlinetext/src/InlineTextNoMatchesIndicatorSource.cpp
changeset 37 6be019398652
equal deleted inserted replaced
32:8b9155204a54 37:6be019398652
       
     1 /*
       
     2 * Copyright (c) 2003-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <tagma.h>
       
    21 #include "InlineTextNoMatchesIndicatorSource.h"
       
    22 
       
    23 // MODULE TEMPLATES
       
    24 
       
    25 // MODULE DATA STRUCTURES
       
    26 
       
    27 // LOCAL CONSTANTS
       
    28 _LIT(KTextForUnknownPredictiveTextWestern, "?" );
       
    29 _LIT(KTextForUnknownPredictiveTextArabic, "\x061f" );   // Arabic Question Mark
       
    30 
       
    31 #define ARABIC_CODE_PAGE_BASE   0x0600
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 
       
    36 ////////////////////////////////////////////////////////////////////////////////
       
    37 //
       
    38 // CInlineTextNoMatchesIndicatorSource
       
    39 //
       
    40 ////////////////////////////////////////////////////////////////////////////////
       
    41 
       
    42 EXPORT_C CInlineTextNoMatchesIndicatorSource* CInlineTextNoMatchesIndicatorSource::NewL( const MTmSource& aTextSource )
       
    43     {
       
    44     CInlineTextNoMatchesIndicatorSource* self = 
       
    45         new (ELeave) CInlineTextNoMatchesIndicatorSource( aTextSource );
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop();
       
    49     return self;
       
    50     }
       
    51 
       
    52 CInlineTextNoMatchesIndicatorSource::~CInlineTextNoMatchesIndicatorSource()
       
    53     {
       
    54     }
       
    55 
       
    56 void CInlineTextNoMatchesIndicatorSource::CheckFormattingL(const TTmDocPos& aFrom, const TTmDocPos& aTo )
       
    57     {
       
    58     DoFormatL( aFrom, aTo );
       
    59     }
       
    60 
       
    61 void CInlineTextNoMatchesIndicatorSource::DoFormatL( const TTmDocPos& aFrom, const TTmDocPos& aTo)
       
    62     {
       
    63     // Check if this contains no text. Can we adjust it to contain at least something?
       
    64     TTmDocPos from( aFrom );
       
    65     if ( aTo.iPos - from.iPos <= 0 && from.iPos > 0 )
       
    66         {
       
    67         from.iPos--;
       
    68         from.iLeadingEdge = ETrue;
       
    69         }
       
    70         
       
    71     InlineTextStore()->ClearRange( aFrom, aTo );
       
    72 
       
    73     TTmCharFormat format;
       
    74     TPtrC buffer;
       
    75     TBool endOfPara(EFalse);
       
    76 
       
    77     TInt charPos = from.iPos;
       
    78     // Process the buffer within the format 
       
    79     while ( charPos <= aTo.iPos && !endOfPara )
       
    80         {
       
    81         iTextSource.GetText( charPos, buffer, format );
       
    82 
       
    83         // Check for end of paragraph mark 
       
    84         TInt lengthInFormat = buffer.Length();
       
    85         // trim off the paragraph delimeter from the format chunk, or at least for our book-keeping of it
       
    86         if ( buffer[lengthInFormat-1] == KInlineTextParagraphDelimiter )
       
    87             {
       
    88             lengthInFormat--;
       
    89             endOfPara = ETrue;
       
    90             }
       
    91 
       
    92         if ( format.iEffects & TTmCharFormat::ENoMatchesIndicator )
       
    93             {
       
    94             // Have to ensure that this is at the logical end of the markup (eg, there could be more 
       
    95             // marked up text wrapped to the next line)
       
    96             if ( !FormatOfNextCharacterIsUnknownInlineFepTextStyle( charPos + lengthInFormat ) )
       
    97                 // Store at end/trailing           
       
    98                 StoreNoMatchesIndicatorInlineTextL( charPos + lengthInFormat, EFalse, buffer );
       
    99             }
       
   100 
       
   101         charPos += lengthInFormat;
       
   102         }
       
   103 
       
   104 #ifdef INLINE_EDIT_DUMPING
       
   105     // Dumping code
       
   106     TBuf<80> buf;
       
   107     RDebug::Print(_L("\nDump of inline texts"));
       
   108     for ( TInt index = 0; index < InlineTextStore()->Count(); index++)
       
   109         {
       
   110 
       
   111         CInlineTextPositionedText* inlineText = InlineTextStore()->At( index );
       
   112         TPtrC ptr = inlineText->InlineText();
       
   113         buf.Format( _L("DocPos: %d  Trailing/Leading: %d   Text=<%S>"), 
       
   114             inlineText->DocPos().iPos,
       
   115             inlineText->DocPos().iLeadingEdge, &ptr );
       
   116 
       
   117         RDebug::Print( buf );
       
   118         }
       
   119 #endif
       
   120 
       
   121     }
       
   122 
       
   123 CInlineTextNoMatchesIndicatorSource::CInlineTextNoMatchesIndicatorSource( const MTmSource& aTextSource )
       
   124  : CInlineTextSource(), iTextSource( aTextSource )
       
   125     {}
       
   126 
       
   127 void CInlineTextNoMatchesIndicatorSource::StoreNoMatchesIndicatorInlineTextL( 
       
   128     TInt aPos, 
       
   129     TBool aLeadingEdge,
       
   130     const TDesC& aSampleText )
       
   131     {
       
   132     TTmDocPos docPos( aPos, aLeadingEdge );
       
   133 
       
   134     CInlineTextPositionedText* inlineText = 
       
   135         CInlineTextPositionedText::NewL( 
       
   136             docPos, 
       
   137             TextForUnknownPredictiveTextIndication( aSampleText) );
       
   138 
       
   139     CleanupStack::PushL( inlineText );
       
   140     InlineTextStore()->InsertInlineTextL( inlineText );
       
   141     CleanupStack::Pop(); // inlineText
       
   142     }
       
   143 
       
   144 TPtrC CInlineTextNoMatchesIndicatorSource::TextForUnknownPredictiveTextIndication( const TDesC& aSampleText ) const
       
   145     {
       
   146     TUint codebase = CodeBaseOfText( aSampleText);
       
   147     if ( codebase == ARABIC_CODE_PAGE_BASE )
       
   148         return KTextForUnknownPredictiveTextArabic(); //unknownTextBuffer;
       
   149     else
       
   150         return KTextForUnknownPredictiveTextWestern(); //unknownTextBuffer;
       
   151     }
       
   152 /**
       
   153 * Implementation is not safe for surrogate pairs
       
   154 */
       
   155 TUint CInlineTextNoMatchesIndicatorSource::CodeBaseOfText( const TDesC& aSampleText ) const
       
   156     {
       
   157     TUint base = 0;
       
   158 
       
   159     // examine buffer; take first printable character
       
   160     // if none found, then 0 is returned
       
   161     TChar character;
       
   162     for ( TInt index = 0;index < aSampleText.Length(); index++)
       
   163         {
       
   164         character = aSampleText[index];
       
   165         if ( character.IsPrint() )
       
   166             {
       
   167             TUint ch(character); 
       
   168             ch &= 0xffffff00; // only interested in upper bits
       
   169             base = (TUint)ch;
       
   170             break;
       
   171             }
       
   172         }
       
   173 
       
   174     return base;
       
   175     }
       
   176 
       
   177 TBool CInlineTextNoMatchesIndicatorSource::FormatOfNextCharacterIsUnknownInlineFepTextStyle( TInt aNextPos) const
       
   178     {
       
   179     TBool effectIsUnknownInlineFepText(EFalse);
       
   180 
       
   181     TPtrC textPtr;
       
   182 
       
   183     // Use separate, new format on the stack to hold the info on the next character
       
   184     TTmCharFormat format;
       
   185 
       
   186     // Get characters immediately following current chunk.
       
   187     iTextSource.GetText( aNextPos, textPtr, format );
       
   188 
       
   189     // Must be at least one character
       
   190     if ( textPtr.Length() >= 1 )
       
   191     // Check if it is the correct effect.
       
   192     if (format.iEffects & TTmCharFormat::ENoMatchesIndicator )
       
   193             effectIsUnknownInlineFepText = ETrue;
       
   194 
       
   195     return effectIsUnknownInlineFepText;
       
   196     }
       
   197 
       
   198 //  End of File