X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=base%2Fdali-toolkit%2Finternal%2Fcontrols%2Ftext-view%2Ftext-view-word-processor.cpp;h=800a96b27fbc5943f41f591996f5a84a260bdfac;hp=8925f36d83b4ef42ac6196ba0335ec21aa840f23;hb=7f35cb5ac96b2360bba850dfa20d88bbc9f9a362;hpb=1bb77b62e55761f55511fedac0f831deff677782 diff --git a/base/dali-toolkit/internal/controls/text-view/text-view-word-processor.cpp b/base/dali-toolkit/internal/controls/text-view/text-view-word-processor.cpp index 8925f36..800a96b 100644 --- a/base/dali-toolkit/internal/controls/text-view/text-view-word-processor.cpp +++ b/base/dali-toolkit/internal/controls/text-view/text-view-word-processor.cpp @@ -39,33 +39,6 @@ namespace const std::string EMOJI_FONT_NAME( "SamsungEmoji" ); // Emoticons font family name. -/** - * Updates the word size and ascender. - * - * It's called after deleting some characters. - * - * @param[in] wordLayout The word layout info. - */ -void UpdateLayoutInfo( WordLayoutInfo& wordLayout ) -{ - // Initialize layout info for the whole word. - wordLayout.mSize = Size::ZERO; - wordLayout.mAscender = 0.f; - - // Traverse the character layout info to update the word layout. - for( CharacterLayoutInfoContainer::iterator layoutIt = wordLayout.mCharactersLayoutInfo.begin(), layoutEndIt = wordLayout.mCharactersLayoutInfo.end(); - layoutIt != layoutEndIt; - ++layoutIt ) - { - // Layout info for the current character. - CharacterLayoutInfo& layoutInfo( *layoutIt ); - - // Update layout info for the current word. - UpdateSize( wordLayout.mSize, layoutInfo.mSize ); - wordLayout.mAscender = std::max( wordLayout.mAscender, layoutInfo.mAscender ); - } -} - } // namespace ///////////////////// @@ -76,6 +49,7 @@ WordLayoutInfo::WordLayoutInfo() : mSize(), mAscender( 0.f ), mType( NoSeparator ), + mFirstCharacter( 0u ), mCharactersLayoutInfo() { } @@ -88,6 +62,7 @@ WordLayoutInfo::WordLayoutInfo( const WordLayoutInfo& word ) : mSize( word.mSize ), mAscender( word.mAscender ), mType( word.mType ), + mFirstCharacter( word.mFirstCharacter ), mCharactersLayoutInfo( word.mCharactersLayoutInfo ) { } @@ -97,88 +72,105 @@ WordLayoutInfo& WordLayoutInfo::operator=( const WordLayoutInfo& word ) mSize = word.mSize; mAscender = word.mAscender; mType = word.mType; + mFirstCharacter = word.mFirstCharacter; mCharactersLayoutInfo = word.mCharactersLayoutInfo; return *this; } -void CreateWordTextInfo( const MarkupProcessor::StyledTextArray& word, +void CreateWordTextInfo( const Text& paragraph, + Vector& textStyles, WordLayoutInfo& wordLayoutInfo ) { DALI_LOG_INFO( gTextViewProcessorLogFilter, Debug::General, "-->TextViewProcessor::CreateWordTextInfo\n" ); // Split in characters. - for( MarkupProcessor::StyledTextArray::const_iterator charIt = word.begin(), charEndIt = word.end(); charIt != charEndIt; ++charIt ) + std::size_t characterIndex = wordLayoutInfo.mFirstCharacter; + for( CharacterLayoutInfoContainer::iterator it = wordLayoutInfo.mCharactersLayoutInfo.begin(), + endIt = wordLayoutInfo.mCharactersLayoutInfo.end(); + it != endIt; + ++it, ++characterIndex ) { - const MarkupProcessor::StyledText& styledText( *charIt ); + // Gets a reference of the character's layout info. + CharacterLayoutInfo& characterLayoutInfo( *it ); - const std::size_t length = styledText.mText.GetLength(); + // Gets the character and the style for that character from the paragraph. + Character character = paragraph[characterIndex]; + TextStyle* textStyle = *( textStyles.Begin() + characterIndex ); - // It could be a group of characters. - for( std::size_t index = 0u; index < length; ++index ) + // Checks whether the character is an emoticon. + characterLayoutInfo.mIsColorGlyph = GlyphImage::IsColorGlyph( character ); + DALI_LOG_INFO( gTextViewProcessorLogFilter, Debug::General, " Is color glyph: %s\n", ( characterLayoutInfo.mIsColorGlyph ? "True" : "False" ) ); + + if( characterLayoutInfo.mIsColorGlyph ) + { + // If the character is an emoticon a predefined font is set. + textStyle->SetFontName( EMOJI_FONT_NAME ); + } + else { - MarkupProcessor::StyledText styledCharacter; - styledCharacter.mStyle = styledText.mStyle; - Character character = styledText.mText[index]; - styledCharacter.mText.Append( character ); + // Checks if the font family and the font style set in the text style supports the character. + // If not, it chooses the right font for the given character and style. + ChooseFontFamilyName( character, *textStyle ); + } - // Create layout character info. - CharacterLayoutInfo characterLayoutInfo; + // Gets the metrics of the font. + const Font font = Font::New( FontParameters( textStyle->GetFontName(), textStyle->GetFontStyle(), textStyle->GetFontPointSize() ) ); + const Font::Metrics metrics = font.GetMetrics( character ); + const float ascender = font.GetAscender(); - characterLayoutInfo.mIsColorGlyph = GlyphImage::IsColorGlyph( character ); - DALI_LOG_INFO( gTextViewProcessorLogFilter, Debug::General, " Is color glyph: %s\n", ( characterLayoutInfo.mIsColorGlyph ? "True" : "False" ) ); + // Fill Natural size info for current character. - if( characterLayoutInfo.mIsColorGlyph ) - { - styledCharacter.mStyle.SetFontName( EMOJI_FONT_NAME ); - } - else - { - //Choose the right font for the given character and style. - ChooseFontFamilyName( styledCharacter ); - } + // The font line's height is used as character's height. + characterLayoutInfo.mSize.height = font.GetLineHeight(); - const Font font = Font::New( FontParameters( styledCharacter.mStyle.GetFontName(), styledCharacter.mStyle.GetFontStyle(), styledCharacter.mStyle.GetFontPointSize() ) ); - const Font::Metrics metrics = font.GetMetrics( character ); - const float ascender = font.GetAscender(); + // The character's advance is used as charcter's width. + characterLayoutInfo.mSize.width = metrics.GetAdvance(); - // Fill Natural size info for current character. - characterLayoutInfo.mHeight = font.GetLineHeight(); - characterLayoutInfo.mAdvance = metrics.GetAdvance(); - characterLayoutInfo.mBearing = metrics.GetBearing(); + // The ascender and bearing are used to position correctly glyphs of different font sizes. + characterLayoutInfo.mAscender = ascender; + characterLayoutInfo.mBearing = metrics.GetBearing(); - if( character.IsNewLine() && !characterLayoutInfo.mIsColorGlyph ) - { - // A new paragraph character doesn't have any width. - characterLayoutInfo.mSize.width = 0.f; - } - else - { - // Uses advance as width. - characterLayoutInfo.mSize.width = characterLayoutInfo.mAdvance; - } - characterLayoutInfo.mSize.height = characterLayoutInfo.mHeight; - characterLayoutInfo.mAscender = ascender; - - if( styledCharacter.mStyle.IsUnderlineEnabled() ) - { - characterLayoutInfo.mUnderlineThickness = font.GetUnderlineThickness(); // Both thickness and position includes the - characterLayoutInfo.mUnderlinePosition = font.GetUnderlinePosition(); // vertical pad adjust used in effects like glow or shadow. - } + if( character.IsNewLine() && !characterLayoutInfo.mIsColorGlyph ) + { + // A new paragraph character '\n' doesn't have any width. + characterLayoutInfo.mSize.width = 0.f; + } - // stores the styled text. - characterLayoutInfo.mStyledText.mText = styledCharacter.mText; - characterLayoutInfo.mStyledText.mStyle = styledCharacter.mStyle; + // Set's the underline thickness and position. + // Both thickness and position includes the vertical pad adjust used in effects like glow or shadow. + if( textStyle->IsUnderlineEnabled() ) + { + characterLayoutInfo.mUnderlineThickness = font.GetUnderlineThickness(); + characterLayoutInfo.mUnderlinePosition = font.GetUnderlinePosition(); + } - // Add character layout info to the word layout info and update it. - wordLayoutInfo.mCharactersLayoutInfo.push_back( characterLayoutInfo ); - UpdateSize( wordLayoutInfo.mSize, characterLayoutInfo.mSize ); - wordLayoutInfo.mAscender = std::max( wordLayoutInfo.mAscender, characterLayoutInfo.mAscender ); - wordLayoutInfo.mType = GetTextSeparatorType( character ); - } // end of each character in the group of characters. + // Updates the word size and ascender. + UpdateSize( wordLayoutInfo.mSize, characterLayoutInfo.mSize ); + wordLayoutInfo.mAscender = std::max( wordLayoutInfo.mAscender, characterLayoutInfo.mAscender ); } // end of characters in the word. DALI_LOG_INFO( gTextViewProcessorLogFilter, Debug::General, "<--TextViewProcessor::CreateWordTextInfo\n" ); } +void UpdateLayoutInfo( WordLayoutInfo& wordLayout ) +{ + // Initialize layout info for the whole word. + wordLayout.mSize = Size::ZERO; + wordLayout.mAscender = 0.f; + + // Traverse the character layout info to update the word layout. + for( CharacterLayoutInfoContainer::iterator layoutIt = wordLayout.mCharactersLayoutInfo.begin(), layoutEndIt = wordLayout.mCharactersLayoutInfo.end(); + layoutIt != layoutEndIt; + ++layoutIt ) + { + // Layout info for the current character. + CharacterLayoutInfo& layoutInfo( *layoutIt ); + + // Update layout info for the current word. + UpdateSize( wordLayout.mSize, layoutInfo.mSize ); + wordLayout.mAscender = std::max( wordLayout.mAscender, layoutInfo.mAscender ); + } +} + void RemoveCharactersFromWordInfo( TextView::RelayoutData& relayoutData, const std::size_t numberOfCharacters, bool& mergeWords,