diff -r 748ec5531811 -r 336bee5c2d35 textrendering/textformatting/tbox/LAYEMU.CPP --- a/textrendering/textformatting/tbox/LAYEMU.CPP Tue Aug 31 17:01:26 2010 +0300 +++ b/textrendering/textformatting/tbox/LAYEMU.CPP Wed Sep 01 12:39:40 2010 +0100 @@ -29,11 +29,6 @@ #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 @@ -52,6 +47,32 @@ 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. @@ -109,11 +130,11 @@ TChar CTextLayout::TUtf32SourceCache::GetUtf32(TInt aIndex) { TText code = GetUtf16(aIndex); - if (TChar::IsHighSurrogate(code) && iSource->DocumentLength() < aIndex + 1) + if (IsHighSurrogate(code) && iSource->DocumentLength() < aIndex + 1) { TText code2 = GetUtf16(aIndex + 1); - if (TChar::IsLowSurrogate(code2)) - return TChar::JoinSurrogate(code, code2); + if (IsLowSurrogate(code2)) + return PairSurrogates(code, code2); } return code; } @@ -215,11 +236,7 @@ { if(!iReadyToRedraw) return; - - if (iBeginRedrawCount <= 0) - { - OstTrace0( TRACE_DUMP, CTEXTLAYOUT_ENDREDRAW, "CTextLayout::EndRedraw" ); - } + __ASSERT_ALWAYS(iBeginRedrawCount > 0, Panic(EInvalidRedraw)); if (0 == --iBeginRedrawCount) @@ -239,10 +256,6 @@ 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; @@ -250,10 +263,6 @@ void CTextLayout::ResetExternalDraw() { - if (1 != iBeginRedrawCount) - { - OstTrace0( TRACE_FATAL, CTEXTLAYOUT_RESETEXTERNALDRAW, "EInvalidRedraw" ); - } __ASSERT_ALWAYS(1 == iBeginRedrawCount, Panic(EInvalidRedraw)); iBeginRedrawCount--; @@ -432,10 +441,6 @@ { 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; } @@ -677,7 +682,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. @@ -798,10 +803,6 @@ @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; @@ -1060,8 +1061,8 @@ { TUint highSurrogate = text[0]; TUint lowSurrogate = text[1]; - if ( TChar::IsHighSurrogate( highSurrogate ) && - TChar::IsLowSurrogate( lowSurrogate ) ) + if ( IsHighSurrogate( highSurrogate ) && + IsLowSurrogate( lowSurrogate ) ) --r; } } @@ -1175,15 +1176,7 @@ 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); @@ -1197,10 +1190,6 @@ // 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 @@ -1547,7 +1536,7 @@ if(IsFormattingBand() && (iText->EndChar() <= aEndDocPos && iText->EndChar() < iSource->DocumentLength())) { - param.iEndChar = Min(aEndDocPos+1,iSource->DocumentLength()); + param.iEndChar = aEndDocPos; iText->ExtendFormattingDownwardsL(param); } else @@ -1612,10 +1601,6 @@ */ 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; @@ -1640,10 +1625,6 @@ { 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)); } @@ -1670,20 +1651,8 @@ 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; @@ -1734,16 +1703,8 @@ 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; } @@ -1931,10 +1892,7 @@ 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; } @@ -1964,10 +1922,7 @@ if (lines_scrolled) { if (!iText->LineNumberToLine(desired_top_line_number,info)) - { - OstTrace0( TRACE_DUMP, CTEXTLAYOUT_SCROLLLINESL, "EPosNotFormatted" ); - User::Leave(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) @@ -1984,10 +1939,7 @@ // 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)) - { - OstTrace0( TRACE_DUMP, DUP2_CTEXTLAYOUT_SCROLLLINESL, "EPosNotFormatted" ); - User::Leave(EPosNotFormatted); - } + User::Leave(EPosNotFormatted); return ScrollL(-info.iOuterRect.Height(), aScrollBlankSpace); } @@ -2010,10 +1962,7 @@ if (iText->YPosToLine(band_bottom - 1,info)) bottom_line_number = info.iLineNumber; else - { - OstTrace0( TRACE_DUMP, DUP3_CTEXTLAYOUT_SCROLLLINESL, "EPosNotFormatted" ); - User::Leave(EPosNotFormatted); - } + User::Leave(EPosNotFormatted); partial_line = band_bottom < info.iOuterRect.iBr.iY; // Find the line number of the desired last visible line. @@ -2039,10 +1988,7 @@ if (lines_scrolled) { if (!iText->LineNumberToLine(desired_bottom_line_number,info)) - { - OstTrace0( TRACE_DUMP, DUP4_CTEXTLAYOUT_SCROLLLINESL, "EPosNotFormattedL" ); - User::Leave(EPosNotFormatted); - } + User::Leave(EPosNotFormatted); return ScrollL(band_bottom - info.iOuterRect.iBr.iY,aScrollBlankSpace); } else @@ -2238,16 +2184,8 @@ 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)); } @@ -2280,25 +2218,9 @@ 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. @@ -2314,75 +2236,17 @@ { 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; } @@ -2462,10 +2326,6 @@ 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. @@ -2592,11 +2452,6 @@ { int excess = BandHeight() - FormattedHeightInPixels(); int space_before = 0; - - if (IsFormattingBand()) - { - OstTrace0( TRACE_FATAL, CTEXTLAYOUT_ADJUSTVERTICALALIGNMENT, "EMustFormatAllText" ); - } __ASSERT_ALWAYS(!IsFormattingBand(),Panic(EMustFormatAllText)); TTmLineInfo info; @@ -2837,10 +2692,6 @@ // 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]; @@ -4161,7 +4012,9 @@ 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 @@ -4205,6 +4058,19 @@ 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. @@ -4223,20 +4089,12 @@ 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);