X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller.cpp;h=ab4179099bc1238d1e24e80bb55b3463f865e7f3;hb=3a14f4cd926da60a41c4dc9ca32ac808c5c7d349;hp=740e94807e43fdce234f61cb7c0ea60b062a6299;hpb=eefe73d95db6e9be0b518c5b796e1f1a081cce12;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 740e948..ab41790 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -43,7 +43,6 @@ const float MAX_FLOAT = std::numeric_limits::max(); const unsigned int POINTS_PER_INCH = 72; const std::string EMPTY_STRING(""); -const unsigned int ZERO = 0u; float ConvertToEven( float value ) { @@ -467,7 +466,7 @@ float Controller::GetDefaultPointSize() const return 0.0f; } -void Controller::UpdateAfterFontChange( std::string& newDefaultFont ) +void Controller::UpdateAfterFontChange( const std::string& newDefaultFont ) { DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange"); @@ -500,7 +499,7 @@ const Vector4& Controller::GetTextColor() const return mImpl->mTextColor; } -bool Controller::RemoveText( int cursorOffset, int numberOfChars ) +bool Controller::RemoveText( int cursorOffset, int numberOfCharacters ) { bool removed = false; @@ -509,8 +508,8 @@ bool Controller::RemoveText( int cursorOffset, int numberOfChars ) return removed; } - DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfChars %d\n", - this, mImpl->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfChars ); + DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n", + this, mImpl->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters ); if( !mImpl->IsShowingPlaceholderText() ) { @@ -526,12 +525,12 @@ bool Controller::RemoveText( int cursorOffset, int numberOfChars ) cursorIndex = oldCursorIndex + cursorOffset; } - if( ( cursorIndex + numberOfChars ) > currentText.Count() ) + if( ( cursorIndex + numberOfCharacters ) > currentText.Count() ) { - numberOfChars = currentText.Count() - cursorIndex; + numberOfCharacters = currentText.Count() - cursorIndex; } - if( ( cursorIndex + numberOfChars ) <= currentText.Count() ) + if( ( cursorIndex + numberOfCharacters ) <= currentText.Count() ) { // Update the input style and remove the text's style before removing the text. @@ -542,18 +541,18 @@ bool Controller::RemoveText( int cursorOffset, int numberOfChars ) mImpl->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle ); // Remove the text's style before removing the text. - mImpl->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfChars ); + mImpl->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters ); // Remove the characters. Vector::Iterator first = currentText.Begin() + cursorIndex; - Vector::Iterator last = first + numberOfChars; + Vector::Iterator last = first + numberOfCharacters; currentText.Erase( first, last ); // Cursor position retreat oldCursorIndex = cursorIndex; - DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfChars ); + DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters ); removed = true; } } @@ -1041,7 +1040,7 @@ float Controller::GetHeightForWidth( float width ) } else { - layoutSize = mImpl->mVisualModel->GetActualSize(); + layoutSize = mImpl->mVisualModel->GetLayoutSize(); DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height ); } @@ -1065,6 +1064,7 @@ bool Controller::Relayout( const Size& size ) return glyphsRemoved; } + // Whether a new size has been set. const bool newSize = ( size != mImpl->mVisualModel->mControlSize ); if( newSize ) @@ -1327,6 +1327,11 @@ bool Controller::DoRelayout( const Size& size, if( 0u == numberOfGlyphs ) { + if( UPDATE_ACTUAL_SIZE & operations ) + { + mImpl->mVisualModel->SetLayoutSize( Size::ZERO ); + } + // Nothing else to do if there is no glyphs. DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" ); return true; @@ -1339,6 +1344,8 @@ bool Controller::DoRelayout( const Size& size, const Vector& glyphsToCharactersMap = mImpl->mVisualModel->mGlyphsToCharacters; const Vector& charactersPerGlyph = mImpl->mVisualModel->mCharactersPerGlyph; const Character* const textBuffer = mImpl->mLogicalModel->mText.Begin(); + const Vector& charactersToGlyph = mImpl->mVisualModel->mCharactersToGlyph; + const Vector& glyphsPerCharacter = mImpl->mVisualModel->mGlyphsPerCharacter; // Set the layout parameters. LayoutParameters layoutParameters( size, @@ -1346,10 +1353,12 @@ bool Controller::DoRelayout( const Size& size, lineBreakInfo.Begin(), wordBreakInfo.Begin(), ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL, - numberOfGlyphs, glyphs.Begin(), glyphsToCharactersMap.Begin(), - charactersPerGlyph.Begin() ); + charactersPerGlyph.Begin(), + charactersToGlyph.Begin(), + glyphsPerCharacter.Begin(), + numberOfGlyphs ); // The laid-out lines. // It's not possible to know in how many lines the text is going to be laid-out, @@ -1370,6 +1379,10 @@ bool Controller::DoRelayout( const Size& size, // Whether the last character is a new paragraph character. layoutParameters.isLastNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mLogicalModel->mText.Count() - 1u ) ) ); + // The initial glyph and the number of glyphs to layout. + layoutParameters.startGlyphIndex = 0u; + layoutParameters.numberOfGlyphs = numberOfGlyphs; + // Update the visual model. viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters, glyphPositions, @@ -1390,7 +1403,7 @@ bool Controller::DoRelayout( const Size& size, // Get the lines const Length numberOfLines = mImpl->mVisualModel->mLines.Count(); const CharacterIndex startIndex = 0u; - Length requestedNumberOfCharacters = mImpl->mLogicalModel->mText.Count(); + const Length requestedNumberOfCharacters = mImpl->mLogicalModel->mText.Count(); // Reorder the lines. bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters. @@ -1410,13 +1423,10 @@ bool Controller::DoRelayout( const Size& size, startIndex, requestedNumberOfCharacters ); - // Get the character to glyph conversion table and set into the layout. - layoutParameters.charactersToGlyphsBuffer = mImpl->mVisualModel->mCharactersToGlyph.Begin(); - // Get the glyphs per character table and set into the layout. - layoutParameters.glyphsPerCharacterBuffer = mImpl->mVisualModel->mGlyphsPerCharacter.Begin(); - // Re-layout the text. Reorder those lines with right to left characters. mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters, + startIndex, + requestedNumberOfCharacters, glyphPositions ); // Free the allocated memory used to store the conversion table in the bidirectional line info run. @@ -1438,13 +1448,13 @@ bool Controller::DoRelayout( const Size& size, // Sets the actual size. if( UPDATE_ACTUAL_SIZE & operations ) { - mImpl->mVisualModel->SetActualSize( layoutSize ); + mImpl->mVisualModel->SetLayoutSize( layoutSize ); } } // view updated } else { - layoutSize = mImpl->mVisualModel->GetActualSize(); + layoutSize = mImpl->mVisualModel->GetLayoutSize(); } if( ALIGN & operations ) @@ -1452,7 +1462,12 @@ bool Controller::DoRelayout( const Size& size, // The laid-out lines. Vector& lines = mImpl->mVisualModel->mLines; - mImpl->mLayoutEngine.Align( layoutSize, + const CharacterIndex startIndex = 0u; + const Length requestedNumberOfCharacters = mImpl->mLogicalModel->mText.Count(); + + mImpl->mLayoutEngine.Align( size, + startIndex, + requestedNumberOfCharacters, lines ); viewUpdated = true; @@ -1525,49 +1540,62 @@ LayoutEngine::VerticalAlignment Controller::GetVerticalAlignment() const return mImpl->mLayoutEngine.GetVerticalAlignment(); } -void Controller::CalculateTextAlignment( const Size& size ) +void Controller::CalculateTextAlignment( const Size& controlSize ) { - // Get the direction of the first character. - const CharacterDirection firstParagraphDirection = mImpl->mLogicalModel->GetCharacterDirection( 0u ); + Size layoutSize = mImpl->mVisualModel->GetLayoutSize(); - Size actualSize = mImpl->mVisualModel->GetActualSize(); - if( fabsf( actualSize.height ) < Math::MACHINE_EPSILON_1000 ) + if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 ) { // Get the line height of the default font. - actualSize.height = mImpl->GetDefaultFontLineHeight(); + layoutSize.height = mImpl->GetDefaultFontLineHeight(); } - // If the first paragraph is right to left swap ALIGN_BEGIN and ALIGN_END; - LayoutEngine::HorizontalAlignment horizontalAlignment = mImpl->mLayoutEngine.GetHorizontalAlignment(); - if( firstParagraphDirection && - ( LayoutEngine::HORIZONTAL_ALIGN_CENTER != horizontalAlignment ) ) + if( LayoutEngine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() ) { - if( LayoutEngine::HORIZONTAL_ALIGN_BEGIN == horizontalAlignment ) - { - horizontalAlignment = LayoutEngine::HORIZONTAL_ALIGN_END; - } - else - { - horizontalAlignment = LayoutEngine::HORIZONTAL_ALIGN_BEGIN; - } - } + // Get the direction of the first character. + const CharacterDirection firstParagraphDirection = mImpl->mLogicalModel->GetCharacterDirection( 0u ); - switch( horizontalAlignment ) - { - case LayoutEngine::HORIZONTAL_ALIGN_BEGIN: + // If the first paragraph is right to left swap ALIGN_BEGIN and ALIGN_END; + LayoutEngine::HorizontalAlignment horizontalAlignment = mImpl->mLayoutEngine.GetHorizontalAlignment(); + if( firstParagraphDirection ) { - mImpl->mAlignmentOffset.x = 0.f; - break; - } - case LayoutEngine::HORIZONTAL_ALIGN_CENTER: - { - mImpl->mAlignmentOffset.x = floorf( 0.5f * ( size.width - actualSize.width ) ); // try to avoid pixel alignment. - break; + switch( horizontalAlignment ) + { + case LayoutEngine::HORIZONTAL_ALIGN_BEGIN: + { + horizontalAlignment = LayoutEngine::HORIZONTAL_ALIGN_END; + break; + } + case LayoutEngine::HORIZONTAL_ALIGN_CENTER: + { + // Nothing to do. + break; + } + case LayoutEngine::HORIZONTAL_ALIGN_END: + { + horizontalAlignment = LayoutEngine::HORIZONTAL_ALIGN_BEGIN; + break; + } + } } - case LayoutEngine::HORIZONTAL_ALIGN_END: + + switch( horizontalAlignment ) { - mImpl->mAlignmentOffset.x = size.width - actualSize.width; - break; + case LayoutEngine::HORIZONTAL_ALIGN_BEGIN: + { + mImpl->mAlignmentOffset.x = 0.f; + break; + } + case LayoutEngine::HORIZONTAL_ALIGN_CENTER: + { + mImpl->mAlignmentOffset.x = floorf( 0.5f * ( controlSize.width - layoutSize.width ) ); // try to avoid pixel alignment. + break; + } + case LayoutEngine::HORIZONTAL_ALIGN_END: + { + mImpl->mAlignmentOffset.x = controlSize.width - layoutSize.width; + break; + } } } @@ -1581,12 +1609,12 @@ void Controller::CalculateTextAlignment( const Size& size ) } case LayoutEngine::VERTICAL_ALIGN_CENTER: { - mImpl->mAlignmentOffset.y = floorf( 0.5f * ( size.height - actualSize.height ) ); // try to avoid pixel alignment. + mImpl->mAlignmentOffset.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment. break; } case LayoutEngine::VERTICAL_ALIGN_BOTTOM: { - mImpl->mAlignmentOffset.y = size.height - actualSize.height; + mImpl->mAlignmentOffset.y = controlSize.height - layoutSize.height; break; } } @@ -1748,14 +1776,14 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ // Remove the previous IMF pre-edit (predicitive text) if( mImpl->mEventData->mPreEditFlag && - ( 0 != mImpl->mEventData->mPreEditLength ) ) + ( 0u != mImpl->mEventData->mPreEditLength ) ) { - CharacterIndex offset = mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition; + const CharacterIndex offset = mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition; - removedPrevious = RemoveText( -static_cast(offset), mImpl->mEventData->mPreEditLength ); + removedPrevious = RemoveText( -static_cast( offset ), mImpl->mEventData->mPreEditLength ); mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition; - mImpl->mEventData->mPreEditLength = 0; + mImpl->mEventData->mPreEditLength = 0u; } else { @@ -1814,8 +1842,8 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ const Length numberOfCharactersInModel = mImpl->mLogicalModel->mText.Count(); - // Restrict new text to fit within Maximum characters setting - Length maxSizeOfNewText = std::min ( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount ); + // Restrict new text to fit within Maximum characters setting. + Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount ); maxLengthReached = ( characterCount > maxSizeOfNewText ); // The cursor position. @@ -2486,7 +2514,7 @@ void Controller::ShowPlaceholderText() // Transform a text array encoded in utf8 into an array encoded in utf32. // It returns the actual number of characters. - Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() ); + const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() ); utf32Characters.Resize( characterCount ); // Reset the cursor position