X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller-impl.cpp;h=0c6b2b773ef32e23737bdbb7dff15bf593f9c97c;hp=08790c280a3a7e1d06608b9fa346a1c9c13aa692;hb=394b478479627e640973168935bc0045c584b752;hpb=3af09a190a90030049f6190ddd86522dc066c58a diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 08790c2..0c6b2b7 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -1228,6 +1228,7 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, // Get the glyphs per character table. const Length* const glyphsPerCharacterBuffer = mVisualModel->mGlyphsPerCharacter.Begin(); + const Length* const charactersPerGlyphBuffer = mVisualModel->mCharactersPerGlyph.Begin(); // If the vector is void, there is no right to left characters. const bool hasRightToLeftCharacters = NULL != visualToLogicalBuffer; @@ -1246,9 +1247,11 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, // The character in logical order. const CharacterIndex characterLogicalOrderIndex = hasRightToLeftCharacters ? *( visualToLogicalBuffer + visualIndex ) : visualIndex; + // Get the script of the character. + const Script script = mLogicalModel->GetScript( characterLogicalOrderIndex ); + // The first glyph for that character in logical order. const GlyphIndex glyphLogicalOrderIndex = *( charactersToGlyphBuffer + characterLogicalOrderIndex ); - // The number of glyphs for that character const Length numberOfGlyphs = *( glyphsPerCharacterBuffer + characterLogicalOrderIndex ); @@ -1262,12 +1265,25 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, const Vector2& position = *( positionsBuffer + glyphLogicalOrderIndex ); - // Find the mid-point of the area containing the glyph - const float glyphCenter = -glyphMetrics.xBearing + position.x + 0.5f * glyphMetrics.advance; + // Prevents to jump the whole Latin ligatures like fi, ff, ... + const Length numberOfCharactersInLigature = ( TextAbstraction::LATIN == script ) ? *( charactersPerGlyphBuffer + glyphLogicalOrderIndex ) : 1u; + const float glyphAdvance = glyphMetrics.advance / static_cast( numberOfCharactersInLigature ); - if( visualX < glyphCenter ) + for( GlyphIndex index = 0u; !matched && ( index < numberOfCharactersInLigature ); ++index ) + { + // Find the mid-point of the area containing the glyph + const float glyphCenter = -glyphMetrics.xBearing + position.x + ( static_cast( index ) + 0.5f ) * glyphAdvance; + + if( visualX < glyphCenter ) + { + visualIndex += index; + matched = true; + break; + } + } + + if( matched ) { - matched = true; break; } } @@ -1281,6 +1297,7 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, logicalIndex = hasRightToLeftCharacters ? *( visualToLogicalCursorBuffer + visualIndex ) : visualIndex; DALI_LOG_INFO( gLogFilter, Debug::Verbose, "%p closest visualIndex %d logicalIndex %d\n", this, visualIndex, logicalIndex ); + return logicalIndex; } @@ -1762,7 +1779,6 @@ void Controller::Impl::ScrollTextToMatchCursor() if( cursorInfo.isSecondaryCursor ) { - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_BOTH ); mEventData->mDecorator->SetPosition( SECONDARY_CURSOR, cursorInfo.secondaryPosition.x + offset.x, cursorInfo.secondaryPosition.y + offset.y, @@ -1770,9 +1786,24 @@ void Controller::Impl::ScrollTextToMatchCursor() cursorInfo.lineHeight ); DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Secondary cursor position: %f,%f\n", cursorInfo.secondaryPosition.x + offset.x, cursorInfo.secondaryPosition.y + offset.y ); } + + // Set which cursors are active according the state. + if( ( EventData::EDITING == mEventData->mState ) || + ( EventData::EDITING_WITH_POPUP == mEventData->mState ) || + ( EventData::GRAB_HANDLE_PANNING == mEventData->mState ) ) + { + if( cursorInfo.isSecondaryCursor ) + { + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_BOTH ); + } + else + { + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); + } + } else { - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); } }