X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Fvisual-model-impl.cpp;h=beeb08b21e55e12016c4274964b4b44252e6a111;hb=2f04666b2b18b76b7310b0e8f9332b67583dbe2e;hp=5822469ac82d976f8504e8b0b466d3b3bb2c58a9;hpb=3e17d9f63dedb5d669409301f8d9a3d8c393f979;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 5822469..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 ) @@ -68,11 +68,11 @@ void VisualModel::SetGlyphs( const GlyphInfo* glyphs, mCharactersPerGlyph.Resize( numberOfGlyphs ); memcpy( mCharactersPerGlyph.Begin(), charactersPerGlyph, numberOfGlyphs * sizeof( Length ) ); - // Build the characters to glyph conversion table. - CreateCharacterToGlyphTable(); - // Build the glyphs per character table. CreateGlyphsPerCharacterTable(); + + // Build the characters to glyph conversion table. + CreateCharacterToGlyphTable(); } } } @@ -87,22 +87,31 @@ void VisualModel::CreateCharacterToGlyphTable( Length numberOfCharacters ) } mCharactersToGlyph.Reserve( numberOfCharacters ); + DALI_ASSERT_DEBUG( mGlyphsPerCharacter.Count() != 0u || + ( 0u == numberOfCharacters ) ); + + const Length* const glyphsPerCharacterBuffer = mGlyphsPerCharacter.Begin(); + // 2) Traverse the glyphs and set the glyph indices per character. // Index to the glyph. GlyphIndex glyphIndex = 0u; + CharacterIndex characterIndex = 0u; for( Vector::ConstIterator it = mCharactersPerGlyph.Begin(), endIt = mCharactersPerGlyph.End(); it != endIt; - ++it, ++glyphIndex ) + ++it ) { const Length numberOfCharactersPerGlyph = *it; + Length numberOfGlyphs = 0u; // Set the glyph indices. - for( Length index = 0u; index < numberOfCharactersPerGlyph; ++index ) + for( Length index = 0u; index < numberOfCharactersPerGlyph; ++index, ++characterIndex ) { mCharactersToGlyph.PushBack( glyphIndex ); + numberOfGlyphs += *( glyphsPerCharacterBuffer + characterIndex ); } + glyphIndex += numberOfGlyphs; } } @@ -114,7 +123,7 @@ void VisualModel::CreateGlyphsPerCharacterTable( Length numberOfCharacters ) // If no number of characters is given, just set something sensible to avoid reallocations. numberOfCharacters = static_cast ( static_cast( mGlyphs.Count() ) * 1.3f ); } - mCharactersToGlyph.Reserve( numberOfCharacters ); + mGlyphsPerCharacter.Reserve( numberOfCharacters ); // 2) Traverse the glyphs and set the number of glyphs per character. @@ -216,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 ) @@ -334,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, @@ -361,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 ) { }