X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Fvisual-model-impl.cpp;h=beeb08b21e55e12016c4274964b4b44252e6a111;hb=fbab2277a4fcec98f071ecf7334894d79912af52;hp=74291b49fa1bae9d327bf611b8da83a7a22ed42c;hpb=70703869596d06ae4abfb815fc84bca0920d7f9d;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/text/visual-model-impl.cpp b/dali-toolkit/internal/text/visual-model-impl.cpp index 74291b4..beeb08b 100644 --- a/dali-toolkit/internal/text/visual-model-impl.cpp +++ b/dali-toolkit/internal/text/visual-model-impl.cpp @@ -36,9 +36,9 @@ VisualModelPtr VisualModel::New() return VisualModelPtr( new VisualModel() ); } -void VisualModel::SetGlyphs( const GlyphInfo* glyphs, - const CharacterIndex* characterIndices, - const Length* charactersPerGlyph, +void VisualModel::SetGlyphs( const GlyphInfo* const glyphs, + const CharacterIndex* const characterIndices, + const Length* const charactersPerGlyph, Length numberOfGlyphs ) { if( 0u == numberOfGlyphs ) @@ -225,7 +225,7 @@ void VisualModel::GetGlyphsPerCharacterMap( Length* glyphsPerCharacter, memcpy( glyphsPerCharacter, mGlyphsPerCharacter.Begin() + characterIndex, numberOfCharacters * sizeof( Length ) ); } -void VisualModel::SetGlyphPositions( const Vector2* glyphPositions, +void VisualModel::SetGlyphPositions( const Vector2* const glyphPositions, Length numberOfGlyphs ) { if( 0u == numberOfGlyphs ) @@ -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, @@ -370,11 +410,99 @@ const Vector2& VisualModel::GetActualSize() const return mActualSize; } +void VisualModel::SetTextColor( const Vector4& textColor ) +{ + mTextColor = textColor; + + if ( !mUnderlineColorSet ) + { + mUnderlineColor = textColor; + } +} + +void VisualModel::SetShadowOffset( const Vector2& shadowOffset ) +{ + mShadowOffset = shadowOffset; +} + +void VisualModel::SetShadowColor( const Vector4& shadowColor ) +{ + mShadowColor = shadowColor; +} + +void VisualModel::SetUnderlineColor( const Vector4& color ) +{ + mUnderlineColor = color; + mUnderlineColorSet = true; +} + +void VisualModel::SetUnderlineEnabled( bool enabled ) +{ + mUnderlineEnabled = enabled; +} + +void VisualModel::SetUnderlineHeight( float height ) +{ + mUnderlineHeight = height; +} + +const Vector4& VisualModel::GetTextColor() const +{ + return mTextColor; +} + +const Vector2& VisualModel::GetShadowOffset() const +{ + return mShadowOffset; +} + +const Vector4& VisualModel::GetShadowColor() const +{ + return mShadowColor; +} + +const Vector4& VisualModel::GetUnderlineColor() const +{ + return mUnderlineColor; +} + +bool VisualModel::IsUnderlineEnabled() const +{ + return mUnderlineEnabled; +} + +float VisualModel::GetUnderlineHeight() const +{ + return mUnderlineHeight; +} + +void VisualModel::ClearCaches() +{ + mCachedLineIndex = 0u; +} + VisualModel::~VisualModel() { } VisualModel::VisualModel() +: mGlyphs(), + mGlyphsToCharacters(), + mCharactersToGlyph(), + mCharactersPerGlyph(), + mGlyphsPerCharacter(), + mGlyphPositions(), + mLines(), + mTextColor( Color::BLACK ), + mShadowColor( Color::BLACK ), + mUnderlineColor( Color::BLACK ), + mShadowOffset( Vector2::ZERO ), + mUnderlineHeight( 0.0f ), + mNaturalSize(), + mActualSize(), + mCachedLineIndex( 0u ), + mUnderlineEnabled( false ), + mUnderlineColorSet( false ) { }