diff -r f902e87c146f -r 748ec5531811 textrendering/textformatting/tbox/LAYEMU.CPP --- a/textrendering/textformatting/tbox/LAYEMU.CPP Wed Jun 09 11:40:52 2010 +0300 +++ b/textrendering/textformatting/tbox/LAYEMU.CPP Tue Aug 31 17:01:26 2010 +0300 @@ -29,6 +29,11 @@ #include "FRMTLAY_INTERNAL.H" #endif +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "LAYEMUTraces.h" +#endif + const TInt KMaxExtraLines = 10; // maximum number of lines to format after the current and following lines // before using background formatting // during page down/up, the number of lines that should remain visible after @@ -47,32 +52,6 @@ the KNumberOfLinesToKeepVisibleDuringScroll constant.*/ const TInt KMinProportionOfScreenToScroll = 600; -/** -Tests for a high surrogate. -@param a UTF16 value. -@return ETrue if argument is a high surrogate. -@internalComponent -*/ -inline TBool IsHighSurrogate(TText a) { return 0xD800 == (a & 0xFC00); } -/** -Tests for a low surrogate. -@param a UTF16 value. -@return ETrue if argument is a high surrogate. -@internalComponent -*/ -inline TBool IsLowSurrogate(TText a) { return 0xDC00 == (a & 0xFC00); } -/** -Adds a high surrogate to a low surrogate to create a supplementary character. -@param aHigh UTF16 high surrogate. -@param aLow UTF16 low surrogate. -@return Supplementary character represented by the pair . -@pre aHigh is a high surrogate and aLow is a low surrogate. -@internalComponent -*/ -inline TChar PairSurrogates(TText aHigh, TText aLow) - { - return ((aHigh - 0xd7f7) << 10) + aLow; - } /** Constructs an iterator over the text referenced by aSource. @@ -130,11 +109,11 @@ TChar CTextLayout::TUtf32SourceCache::GetUtf32(TInt aIndex) { TText code = GetUtf16(aIndex); - if (IsHighSurrogate(code) && iSource->DocumentLength() < aIndex + 1) + if (TChar::IsHighSurrogate(code) && iSource->DocumentLength() < aIndex + 1) { TText code2 = GetUtf16(aIndex + 1); - if (IsLowSurrogate(code2)) - return PairSurrogates(code, code2); + if (TChar::IsLowSurrogate(code2)) + return TChar::JoinSurrogate(code, code2); } return code; } @@ -236,7 +215,11 @@ { if(!iReadyToRedraw) return; - + + if (iBeginRedrawCount <= 0) + { + OstTrace0( TRACE_DUMP, CTEXTLAYOUT_ENDREDRAW, "CTextLayout::EndRedraw" ); + } __ASSERT_ALWAYS(iBeginRedrawCount > 0, Panic(EInvalidRedraw)); if (0 == --iBeginRedrawCount) @@ -256,6 +239,10 @@ void CTextLayout::SetExternalDraw(const TRect& aRect) { + if (0 != iBeginRedrawCount) + { + OstTrace0( TRACE_FATAL, DUP1_CTEXTLAYOUT_SETEXTERNALDRAW, "EInvalidRedraw" ); + } __ASSERT_ALWAYS(0 == iBeginRedrawCount, Panic(EInvalidRedraw)); iBeginRedrawCount++; iRedrawRect = aRect; @@ -263,6 +250,10 @@ void CTextLayout::ResetExternalDraw() { + if (1 != iBeginRedrawCount) + { + OstTrace0( TRACE_FATAL, CTEXTLAYOUT_RESETEXTERNALDRAW, "EInvalidRedraw" ); + } __ASSERT_ALWAYS(1 == iBeginRedrawCount, Panic(EInvalidRedraw)); iBeginRedrawCount--; @@ -441,6 +432,10 @@ { if (aFormatMode == CLayoutData::EFWysiwygMode || aFormatMode == CLayoutData::EFPrintPreviewMode) { + if (aFormatDevice == NULL) + { + OstTrace0( TRACE_FATAL, CTEXTLAYOUT_SETFORMATMODE, "EFormatDeviceNotSet" ); + } __ASSERT_ALWAYS(aFormatDevice != NULL,Panic(EFormatDeviceNotSet)); iSource->iFormatDevice = aFormatDevice; } @@ -682,7 +677,7 @@ @return The y coordinate of the bottom of the last formatted line. */ EXPORT_C TInt CTextLayout::YBottomLastFormattedLine() const { - return Max(0, iText->LayoutHeight() - iBandTop ); + return Max(0, iText->LayoutHeight() - iBandTop ); } /** Returns the height in pixels of the formatted text. @@ -803,6 +798,10 @@ @return The document position of the first character on the line. */ EXPORT_C TInt CTextLayout::FirstCharOnLine(TInt aLineNo) const { + if (aLineNo <= 0) + { + OstTrace0( TRACE_DUMP, CTEXTLAYOUT_FIRSTCHARONLINE, "EInvalidLineNumber" ); + } __ASSERT_DEBUG(aLineNo > 0,Panic(EInvalidLineNumber)); if (iText->StartChar() == iText->EndChar()) return EFNoCurrentFormat; @@ -1061,8 +1060,8 @@ { TUint highSurrogate = text[0]; TUint lowSurrogate = text[1]; - if ( IsHighSurrogate( highSurrogate ) && - IsLowSurrogate( lowSurrogate ) ) + if ( TChar::IsHighSurrogate( highSurrogate ) && + TChar::IsLowSurrogate( lowSurrogate ) ) --r; } } @@ -1176,7 +1175,15 @@ if (iText->LayoutHeight() == 0) return TRect(0,0,0,0); + if (!PosIsFormatted(aDocPos1)) + { + OstTrace0( TRACE_FATAL, CTEXTLAYOUT_GETLINERECTL, "ECharacterNotFormatted" ); + } __ASSERT_ALWAYS(PosIsFormatted(aDocPos1),Panic(ECharacterNotFormatted)); + if (!PosIsFormatted(aDocPos2)) + { + OstTrace0( TRACE_DUMP, DUP1_CTEXTLAYOUT_GETLINERECTL, "ECharacterNotFormatted" ); + } __ASSERT_DEBUG(PosIsFormatted(aDocPos2),Panic(ECharacterNotFormatted)); TTmDocPosSpec docSpec(aDocPos1, TTmDocPosSpec::ELeading); @@ -1190,6 +1197,10 @@ // Getthe Line rectangle GetLineRect(point.iY,rect); + if (rect.iTl.iY > point.iY || rect.iBr.iY < point.iY) + { + OstTrace0( TRACE_DUMP, DUP2_CTEXTLAYOUT_GETLINERECTL, "EPixelNotInFormattedLine" ); + } __ASSERT_DEBUG(rect.iTl.iY <= point.iY && rect.iBr.iY >= point.iY,Panic(EPixelNotInFormattedLine)); // Finding the leading edge of aDocPos2 @@ -1536,7 +1547,7 @@ if(IsFormattingBand() && (iText->EndChar() <= aEndDocPos && iText->EndChar() < iSource->DocumentLength())) { - param.iEndChar = aEndDocPos; + param.iEndChar = Min(aEndDocPos+1,iSource->DocumentLength()); iText->ExtendFormattingDownwardsL(param); } else @@ -1601,6 +1612,10 @@ */ EXPORT_C void CTextLayout::ExtendFormattingToCoverPosL(TInt aDocPos) { + if (0 > aDocPos || aDocPos > DocumentLength()) + { + OstTrace0( TRACE_DUMP, CTEXTLAYOUT_EXTENDFORMATTINGTOCOVERPOSL, "EInvalidDocPos" ); + } __ASSERT_DEBUG(0 <= aDocPos && aDocPos <= DocumentLength(), Panic(EInvalidDocPos)); TTmFormatParam param; @@ -1625,6 +1640,10 @@ { iText->ExtendFormattingDownwardsL(param); } + if ((aDocPos < iText->StartChar()) || (aDocPos > iText->EndChar())) + { + OstTrace0( TRACE_DUMP, DUP1_CTEXTLAYOUT_EXTENDFORMATTINGTOCOVERPOSL, "ECharacterNotFormatted" ); + } __ASSERT_DEBUG((aDocPos >= iText->StartChar()) && (aDocPos <= iText->EndChar()), Panic(ECharacterNotFormatted)); } @@ -1651,8 +1670,20 @@ void CTextLayout::FormatCharRangeL(TInt aStartDocPos,TInt aEndDocPos,TInt aPixelOffset) { + if (aStartDocPos < 0 && aStartDocPos > DocumentLength()) + { + OstTrace0( TRACE_DUMP, CTEXTLAYOUT_FORMATCHARRANGEL, "EInvalidDocPos" ); + } __ASSERT_DEBUG(aStartDocPos >= 0 && aStartDocPos <= DocumentLength(),Panic(EInvalidDocPos)); + if (aEndDocPos < 0 || aEndDocPos > DocumentLength()) + { + OstTrace0( TRACE_DUMP, DUP1_CTEXTLAYOUT_FORMATCHARRANGEL, "EInvalidDocPos" ); + } __ASSERT_DEBUG(aEndDocPos >= 0 && aEndDocPos <= DocumentLength(),Panic(EInvalidDocPos)); + if (aStartDocPos > aEndDocPos) + { + OstTrace0( TRACE_DUMP, DUP2_CTEXTLAYOUT_FORMATCHARRANGEL, "ENoCharRangeToFormat" ); + } __ASSERT_DEBUG(aStartDocPos <= aEndDocPos,Panic(ENoCharRangeToFormat)); TTmFormatParam param; @@ -1703,8 +1734,16 @@ TTmLineInfo info; TTmDocPos pos(iUnformattedStart, ETrue); TBool isFormatted = iText->DocPosToLine(pos,info); + if (!isFormatted) + { + OstTrace0( TRACE_DUMP, CTEXTLAYOUT_FORMATNEXTLINEL, "EPosNotFormatted" ); + } __ASSERT_DEBUG(isFormatted, Panic(EPosNotFormatted)); isFormatted = iText->ParNumberToLine(info.iParNumber,KMaxTInt,info); + if (!isFormatted) + { + OstTrace0( TRACE_DUMP, DUP1_CTEXTLAYOUT_FORMATNEXTLINEL, "EPosNotFormatted" ); + } __ASSERT_DEBUG(isFormatted, Panic(EPosNotFormatted)); aBottomPixel = info.iOuterRect.iBr.iY - iBandTop; } @@ -1892,7 +1931,10 @@ if (iText->YPosToLine(iBandTop,info)) top_line_number = info.iLineNumber; else + { + OstTrace0( TRACE_DUMP, DUP1_CTEXTLAYOUT_SCROLLLINESL, "EPosNotFormatted" ); User::Leave(EPosNotFormatted); + } partial_line = iBandTop > info.iOuterRect.iTl.iY; } @@ -1922,7 +1964,10 @@ if (lines_scrolled) { if (!iText->LineNumberToLine(desired_top_line_number,info)) - User::Leave(EPosNotFormatted); + { + OstTrace0( TRACE_DUMP, CTEXTLAYOUT_SCROLLLINESL, "EPosNotFormatted" ); + User::Leave(EPosNotFormatted); + } // if the line to be scrolled to is taller than the screen, we want // to make sure that the baseline is not scrolled off the screen. if (visible_height < info.iBaseline - info.iOuterRect.iTl.iY) @@ -1939,7 +1984,10 @@ // If we are restricting scroll to the tops of lines, then lines at // bottom are irrelevant, so all we do is lose the top line. if (!iText->YPosToLine(iBandTop, info)) - User::Leave(EPosNotFormatted); + { + OstTrace0( TRACE_DUMP, DUP2_CTEXTLAYOUT_SCROLLLINESL, "EPosNotFormatted" ); + User::Leave(EPosNotFormatted); + } return ScrollL(-info.iOuterRect.Height(), aScrollBlankSpace); } @@ -1962,7 +2010,10 @@ if (iText->YPosToLine(band_bottom - 1,info)) bottom_line_number = info.iLineNumber; else - User::Leave(EPosNotFormatted); + { + OstTrace0( TRACE_DUMP, DUP3_CTEXTLAYOUT_SCROLLLINESL, "EPosNotFormatted" ); + User::Leave(EPosNotFormatted); + } partial_line = band_bottom < info.iOuterRect.iBr.iY; // Find the line number of the desired last visible line. @@ -1988,7 +2039,10 @@ if (lines_scrolled) { if (!iText->LineNumberToLine(desired_bottom_line_number,info)) - User::Leave(EPosNotFormatted); + { + OstTrace0( TRACE_DUMP, DUP4_CTEXTLAYOUT_SCROLLLINESL, "EPosNotFormattedL" ); + User::Leave(EPosNotFormatted); + } return ScrollL(band_bottom - info.iOuterRect.iBr.iY,aScrollBlankSpace); } else @@ -2184,8 +2238,16 @@ visible_height - 1 : SuggestCursorPos(aYCursorPos); + if (-visible_height > aPixelsScrolled) + { + OstTrace0( TRACE_DUMP, CTEXTLAYOUT_PAGEDOWNL, "EPageScrollError" ); + } __ASSERT_DEBUG(-visible_height <= aPixelsScrolled, Panic(EPageScrollError)); + if (0 > aYCursorPos || aYCursorPos > visible_height) + { + OstTrace0( TRACE_DUMP, DUP1_CTEXTLAYOUT_PAGEDOWNL, "EPageScrollError" ); + } __ASSERT_DEBUG(0 <= aYCursorPos && aYCursorPos <= visible_height, Panic(EPageScrollError)); } @@ -2218,9 +2280,25 @@ EXPORT_C TBool CTextLayout::HandleCharEditL(TUint aType,TInt& aCursorPos,TInt& aGood,TInt& aFormatBottom, TInt& aFormatTop,TInt& aScroll,TBool aFormatFromStartOfPar) { + if (iSource->iFormatMode == CLayoutData::EFPrintPreviewMode) + { + OstTrace0( TRACE_FATAL, DUP2_CTEXTLAYOUT_HANDLECHAREDITL, "EPrintPreviewModeError" ); + } __ASSERT_ALWAYS(iSource->iFormatMode != CLayoutData::EFPrintPreviewMode,Panic(EPrintPreviewModeError)); + if (aType > EFRightDelete) + { + OstTrace0( TRACE_FATAL, CTEXTLAYOUT_HANDLECHAREDITL, "EBadCharacterEditType" ); + } __ASSERT_ALWAYS(aType <= EFRightDelete,Panic(EBadCharacterEditType)); + if (!(!aFormatFromStartOfPar || aType == EFRightDelete || aType == EFLeftDelete)) + { + OstTrace0( TRACE_FATAL, DUP1_CTEXTLAYOUT_HANDLECHAREDITL, "EBadCharacterEditType" ); + } __ASSERT_ALWAYS(!aFormatFromStartOfPar || aType == EFRightDelete || aType == EFLeftDelete,Panic(EBadCharacterEditType)); + if (aCursorPos < iText->StartChar() || aCursorPos >= iText->EndChar()) + { + OstTrace0( TRACE_FATAL, DUP3_CTEXTLAYOUT_HANDLECHAREDITL, "ECharacterNotFormatted" ); + } __ASSERT_ALWAYS(aCursorPos >= iText->StartChar() && aCursorPos < iText->EndChar(),Panic(ECharacterNotFormatted)); // Mark the entire paragraph invalid if background formatting is taking place. @@ -2236,17 +2314,75 @@ { case EFCharacterInsert: case EFParagraphDelimiter: + { reformat_param.iStartChar = aCursorPos++; reformat_param.iNewLength = 1; + + // surrogate support + TPtrC textForSurrogate; + TTmCharFormat formatForSurrogate; + + iSource->GetText(aCursorPos-1, textForSurrogate, formatForSurrogate); + if ( textForSurrogate.Length() > 1 ) + { + TUint highSurrogate = textForSurrogate[0]; + TUint lowSurrogate = textForSurrogate[1]; + if ( TChar::IsHighSurrogate( highSurrogate ) && TChar::IsLowSurrogate( lowSurrogate ) ) + { + // if we are inserting a surrogate pair, do not break the pair + aCursorPos++; + reformat_param.iNewLength++; + } + } break; + } case EFLeftDelete: + { reformat_param.iStartChar = --aCursorPos; reformat_param.iOldLength = 1; + + // surrogate support + TPtrC textForSurrogate; + TTmCharFormat formatForSurrogate; + + if (aCursorPos >= 1) + { + iSource->GetText(aCursorPos-1, textForSurrogate, formatForSurrogate); + if ( textForSurrogate.Length() > 1 ) + { + TUint highSurrogate = textForSurrogate[0]; + TUint lowSurrogate = textForSurrogate[1]; + if ( TChar::IsHighSurrogate( highSurrogate ) && TChar::IsLowSurrogate( lowSurrogate ) ) + { + // if we are deleting a surrogate pair, do not break the pair + reformat_param.iStartChar = --aCursorPos; + reformat_param.iOldLength++; + } + } + } break; + } case EFRightDelete: + { reformat_param.iStartChar = aCursorPos; reformat_param.iOldLength = 1; + + // surrogate support + TPtrC textForSurrogate; + TTmCharFormat formatForSurrogate; + + iSource->GetText(aCursorPos, textForSurrogate, formatForSurrogate); + if ( textForSurrogate.Length() > 1 ) + { + TUint highSurrogate = textForSurrogate[0]; + TUint lowSurrogate = textForSurrogate[1]; + if ( TChar::IsHighSurrogate( highSurrogate ) && TChar::IsLowSurrogate( lowSurrogate ) ) + { + reformat_param.iOldLength++; + } + } break; + } default: break; } @@ -2326,6 +2462,10 @@ EXPORT_C void CTextLayout::HandleBlockChangeL(TCursorSelection aSelection,TInt aOldLength, TViewRectChanges& aChanges,TBool aFormatFromStartOfPar) { + if (iSource->iFormatMode == CLayoutData::EFPrintPreviewMode) + { + OstTrace0( TRACE_FATAL, CTEXTLAYOUT_HANDLEBLOCKCHANGEL, "EPrintPreviewModeError" ); + } __ASSERT_ALWAYS(iSource->iFormatMode != CLayoutData::EFPrintPreviewMode,Panic(EPrintPreviewModeError)); // Do nothing if the selection is outside the formatted range. @@ -2452,6 +2592,11 @@ { int excess = BandHeight() - FormattedHeightInPixels(); int space_before = 0; + + if (IsFormattingBand()) + { + OstTrace0( TRACE_FATAL, CTEXTLAYOUT_ADJUSTVERTICALALIGNMENT, "EMustFormatAllText" ); + } __ASSERT_ALWAYS(!IsFormattingBand(),Panic(EMustFormatAllText)); TTmLineInfo info; @@ -2692,6 +2837,10 @@ // Repeat draw, for double border. if (aBorder.iBorder[border].iLineStyle==TParaBorder::EDouble) // Now have only got solid border, drawn as rect. { + if (drawAsLine) + { + OstTrace0( TRACE_DUMP, CTEXTLAYOUT_DRAWBORDERS, "EDrawingBorderError" ); + } __ASSERT_DEBUG(!drawAsLine,Panic(EDrawingBorderError)); (*ptrStartWidth)-=directionOut*widthInPixels[border]; (*ptrEndWidth)-=directionOut*widthInPixels[border]; @@ -4012,9 +4161,7 @@ if (aDy > 0) // text moves down; iBandTop decreases { if (aTopNoLimitBorder) - { iBandTop = desired_bandtop; - } else iBandTop = Max(0,desired_bandtop);//Disallow text scrolled beyond top border @@ -4058,19 +4205,6 @@ if (!AddFormattingAtEndL(param, height_increase,paragraphs_increase)) break; } - - // Shift the whole band upwards if we're at the very end of the text - // and there's no more text to format. This prevents a situation were - // iText->LayoutHeight() < BandHeightInPixels. - if ( aBottomNoLimitBorder && iText->LayoutHeight() - iBandTop < visible_height ) - { - if ( iText->EndChar() > iText->Source()->DocumentLength() ) - { - iBandTop = desired_bandtop; - return pixels_scrolled; - } - } - } // Scroll blank space off the display if desired. @@ -4089,12 +4223,20 @@ TInt CTextLayout::ScrollDocPosIntoViewL(const TTmDocPos& aDocPos) { + if (aDocPos.iPos > iText->Source()->DocumentLength()) + { + OstTrace0( TRACE_DUMP, CTEXTLAYOUT_SCROLLDOCPOSINTOVIEWL, "EInvalidDocPos" ); + } __ASSERT_DEBUG(aDocPos.iPos <= iText->Source()->DocumentLength(), Panic(EInvalidDocPos)); TTmLineInfo info; ExtendFormattingToCoverPosL(aDocPos.iPos); if (!iText->DocPosToLine(aDocPos,info)) { + if (iText->Source()->DocumentLength() != 0) + { + OstTrace0( TRACE_DUMP, DUP1_CTEXTLAYOUT_SCROLLDOCPOSINTOVIEWL, "ECharacterNotFormatted" ); + } __ASSERT_DEBUG(iText->Source()->DocumentLength() == 0, Panic(ECharacterNotFormatted)); return ScrollL(iBandTop, EFDisallowScrollingBlankSpace);