X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Fvisual-model-impl.cpp;h=c0701796da42a80fef22fd0a4f8ca3be8c76da29;hp=ec94ecc007abf67c4768250dc90d1b970fd04ece;hb=744b2f892a2c8d9110adbfa9e82bc877f776978c;hpb=9b588454ec035214e69112ff4212460b2f8f7eaf;ds=sidebyside diff --git a/dali-toolkit/internal/text/visual-model-impl.cpp b/dali-toolkit/internal/text/visual-model-impl.cpp index ec94ecc..c070179 100644 --- a/dali-toolkit/internal/text/visual-model-impl.cpp +++ b/dali-toolkit/internal/text/visual-model-impl.cpp @@ -343,6 +343,46 @@ void VisualModel::GetLinesOfGlyphRange( LineRun* lines, memcpy( lines, mLines.Begin() + firstLine, numberOfLines * sizeof( LineRun ) ); } +LineIndex VisualModel::GetLineOfGlyph( GlyphIndex glyphIndex ) +{ + const CharacterIndex characterIndex = *( mGlyphsToCharacters.Begin() + glyphIndex ); + + return GetLineOfCharacter( characterIndex ); +} + +LineIndex VisualModel::GetLineOfCharacter( CharacterIndex characterIndex ) +{ + // 1) Check first in the cached line. + + const LineRun& lineRun = *( mLines.Begin() + mCachedLineIndex ); + + if( ( lineRun.characterRun.characterIndex <= characterIndex ) && + ( characterIndex < lineRun.characterRun.characterIndex + lineRun.characterRun.numberOfCharacters ) ) + { + return mCachedLineIndex; + } + + // 2) Is not in the cached line. Check in the other lines. + + LineIndex index = characterIndex < lineRun.characterRun.characterIndex ? 0u : mCachedLineIndex + 1u; + + for( Vector::ConstIterator it = mLines.Begin() + index, + endIt = mLines.End(); + it != endIt; + ++it, ++index ) + { + const LineRun& lineRun = *it; + + if( characterIndex < lineRun.characterRun.characterIndex + lineRun.characterRun.numberOfCharacters ) + { + mCachedLineIndex = index; + break; + } + } + + return index; +} + void VisualModel::ReplaceLines( GlyphIndex glyphIndex, Length numberOfGlyphsToRemove, const LineRun* const lines, @@ -426,12 +466,32 @@ bool VisualModel::IsUnderlineEnabled() const return mUnderlineEnabled; } +void VisualModel::ClearCaches() +{ + mCachedLineIndex = 0u; +} + VisualModel::~VisualModel() { } VisualModel::VisualModel() -: mUnderlineColorSet( false ) +: mGlyphs(), + mGlyphsToCharacters(), + mCharactersToGlyph(), + mCharactersPerGlyph(), + mGlyphsPerCharacter(), + mGlyphPositions(), + mLines(), + mTextColor(), + mShadowColor(), + mUnderlineColor(), + mShadowOffset(), + mNaturalSize(), + mActualSize(), + mCachedLineIndex( 0u ), + mUnderlineEnabled( false ), + mUnderlineColorSet( false ) { }