From 0f217b9896d284c667e1251ee617e4ddadd4c9e3 Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Thu, 11 Sep 2014 15:30:48 +0100 Subject: [PATCH] TextView - Merges the TextActor initialization and update in one function. Both functions traverses the whole text: 1) There is no need to have both functions as the structure is pretty similar. 2) Merge both functions simplifies the process of RTL text. Change-Id: Iac7920be581434cf5c9c15c00c74307d51700518 Signed-off-by: Victor Cebollada --- .../src/dali-toolkit/utc-Dali-TextView.cpp | 31 +- .../controls/text-view/relayout-utilities.cpp | 453 +++++++++++++++------ .../controls/text-view/relayout-utilities.h | 13 +- .../controls/text-view/split-by-char-policies.cpp | 28 +- .../text-view/split-by-new-line-char-policies.cpp | 28 +- .../controls/text-view/split-by-word-policies.cpp | 45 +- .../internal/controls/text-view/text-processor.cpp | 42 +- .../internal/controls/text-view/text-view-impl.cpp | 31 +- .../internal/controls/text-view/text-view-impl.h | 1 - .../text-view/text-view-line-processor.cpp | 56 +-- .../controls/text-view/text-view-line-processor.h | 16 +- .../text-view-processor-helper-functions.cpp | 2 +- .../controls/text-view/text-view-processor.cpp | 223 ++-------- .../controls/text-view/text-view-processor.h | 7 - .../text-view/text-view-word-processor.cpp | 30 +- 15 files changed, 493 insertions(+), 513 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextView.cpp index d781883..5569d96 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextView.cpp @@ -47,10 +47,7 @@ const char* const PROPERTY_MULTILINE_POLICY = "multiline-policy"; const char* const PROPERTY_WIDTH_EXCEED_POLICY = "width-exceed-policy"; const char* const PROPERTY_HEIGHT_EXCEED_POLICY = "height-exceed-policy"; const char* const PROPERTY_LINE_JUSTIFICATION = "line-justification"; -const char* const PROPERTY_FADE_BOUNDARY_LEFT = "fade-boundary-left"; -const char* const PROPERTY_FADE_BOUNDARY_RIGHT = "fade-boundary-right"; -const char* const PROPERTY_FADE_BOUNDARY_TOP = "fade-boundary-top"; -const char* const PROPERTY_FADE_BOUNDARY_BOTTOM = "fade-boundary-bottom"; +const char* const PROPERTY_FADE_BOUNDARY = "fade-boundary"; const char* const PROPERTY_LINE_HEIGHT_OFFSET = "line-height-offset"; const char* const PROPERTY_HORIZONTAL_ALIGNMENT = "horizontal-alignment"; const char* const PROPERTY_VERTICAL_ALIGNMENT = "vertical-alignment"; @@ -751,25 +748,13 @@ int UtcDaliTextViewSetProperty(void) DALI_TEST_CHECK( Toolkit::TextView::Justified == view.GetLineJustification() ); //Test fade boundary property - unsigned int testValue = 23; - PixelSize leftFadeBoundary(testValue); - view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_LEFT), testValue); - DALI_TEST_CHECK( leftFadeBoundary == view.GetFadeBoundary().mLeft ); - - testValue = 26; - PixelSize rightFadeBoundary(testValue); - view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_RIGHT), testValue); - DALI_TEST_CHECK( rightFadeBoundary == view.GetFadeBoundary().mRight ); - - testValue = 2; - PixelSize topFadeBoundary(testValue); - view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_TOP), testValue); - DALI_TEST_CHECK( topFadeBoundary == view.GetFadeBoundary().mTop ); - - testValue = 11; - PixelSize bottomFadeBoundary(testValue); - view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_BOTTOM), testValue); - DALI_TEST_CHECK( bottomFadeBoundary == view.GetFadeBoundary().mBottom ); + const Vector4 testValue( 23.f, 26.f, 2.f, 11.f ); + + view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY), testValue); + DALI_TEST_CHECK( testValue.x == view.GetFadeBoundary().mLeft ); + DALI_TEST_CHECK( testValue.y == view.GetFadeBoundary().mRight ); + DALI_TEST_CHECK( testValue.z == view.GetFadeBoundary().mTop ); + DALI_TEST_CHECK( testValue.w == view.GetFadeBoundary().mBottom ); //Test Line height offset property float testOffsetValue = 14.04f; diff --git a/base/dali-toolkit/internal/controls/text-view/relayout-utilities.cpp b/base/dali-toolkit/internal/controls/text-view/relayout-utilities.cpp index 4ac95cd..84fd943 100644 --- a/base/dali-toolkit/internal/controls/text-view/relayout-utilities.cpp +++ b/base/dali-toolkit/internal/controls/text-view/relayout-utilities.cpp @@ -512,10 +512,10 @@ void UpdateAlignment( const TextView::LayoutParameters& layoutParameters, const float textHorizontalOffset = CalculateXoffset( layoutParameters.mHorizontalAlignment, relayoutData.mTextViewSize.width, relayoutData.mTextSizeForRelayoutOption.width ); const float textVerticalOffset = CalculateYoffset( layoutParameters.mVerticalAlignment, relayoutData.mTextViewSize.height, relayoutData.mTextSizeForRelayoutOption.height ); - std::size_t lineJustificationIndex = 0; // Index to the first position of the vector which stores all line justification info. - std::size_t infoTableCharacterIndex = 0; + std::size_t lineJustificationIndex = 0u; // Index to the first position of the vector which stores all line justification info. + std::size_t infoTableCharacterIndex = 0u; - relayoutParameters.mIndices.mLineIndex = 0; + relayoutParameters.mIndices.mLineIndex = 0u; for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(), endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end(); @@ -526,7 +526,7 @@ void UpdateAlignment( const TextView::LayoutParameters& layoutParameters, float justificationOffset = 0.f; - relayoutParameters.mIndices.mWordIndex = 0; + relayoutParameters.mIndices.mWordIndex = 0u; for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.begin(), endWordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.end(); @@ -535,7 +535,7 @@ void UpdateAlignment( const TextView::LayoutParameters& layoutParameters, { TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt ); - relayoutParameters.mIndices.mCharacterIndex = 0; + relayoutParameters.mIndices.mCharacterIndex = 0u; for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(), endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end(); @@ -617,7 +617,7 @@ void CalculateBearing( TextViewProcessor::CharacterLayoutInfo& characterLayoutIn // gggggggggg // gggggggggg - const Toolkit::TextView::LineLayoutInfo& lineInfo( *( relayoutData.mLines.end() - 1 ) ); + const Toolkit::TextView::LineLayoutInfo& lineInfo( *( relayoutData.mLines.end() - 1u ) ); const float bearingOffset = ( lineInfo.mSize.height - lineInfo.mAscender ) - ( characterLayoutInfo.mSize.height - characterLayoutInfo.mAscender ); characterLayoutInfo.mPosition.y -= bearingOffset * relayoutData.mShrinkFactor; @@ -1068,7 +1068,6 @@ void CreateEllipsizeTextActor( const EllipsizeParameters& ellipsizeParameters, ellipsizeText.Append( ellipsizeCharacterLayoutInfo.mStyledText.mText ); TextViewProcessor::UpdateSize( ellipsizeSize, ellipsizeCharacterLayoutInfo.mSize ); } - } if( !ellipsizeText.IsEmpty() ) @@ -1233,19 +1232,19 @@ void UpdateVisibilityForFade( const TextView::LayoutParameters& layoutParameters // Calculates the fade thresholds (from where the text starts to fade out). If any of the fade boundaries is zero, it sets a very small value just to avoid a zero division. fadeParameters.mRightFadeBoundary = static_cast( visualParameters.mFadeBoundary.mRight ); - fadeParameters.mRightFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mRight > 0 ? fadeParameters.mRightFadeBoundary : MINIMUM_FADE_BOUNDARY ); + fadeParameters.mRightFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mRight > 0u ? fadeParameters.mRightFadeBoundary : MINIMUM_FADE_BOUNDARY ); fadeParameters.mRightFadeThreshold = relayoutData.mTextViewSize.width - fadeParameters.mRightFadeBoundary; fadeParameters.mRightFadeThresholdOffset = relayoutData.mTextViewSize.width - fadeParameters.mRightFadeBoundaryOffset; fadeParameters.mLeftFadeBoundary = static_cast( visualParameters.mFadeBoundary.mLeft ); - fadeParameters.mLeftFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mLeft > 0 ? fadeParameters.mLeftFadeBoundary : MINIMUM_FADE_BOUNDARY ); + fadeParameters.mLeftFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mLeft > 0u ? fadeParameters.mLeftFadeBoundary : MINIMUM_FADE_BOUNDARY ); fadeParameters.mLeftFadeThreshold = fadeParameters.mLeftFadeBoundary; fadeParameters.mLeftFadeThresholdOffset = fadeParameters.mLeftFadeBoundaryOffset; fadeParameters.mTopFadeBoundary = static_cast( visualParameters.mFadeBoundary.mTop ); - fadeParameters.mTopFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mTop > 0 ? fadeParameters.mTopFadeBoundary : MINIMUM_FADE_BOUNDARY ); + fadeParameters.mTopFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mTop > 0u ? fadeParameters.mTopFadeBoundary : MINIMUM_FADE_BOUNDARY ); fadeParameters.mTopFadeThreshold = fadeParameters.mTopFadeBoundary; fadeParameters.mTopFadeThresholdOffset = fadeParameters.mTopFadeBoundaryOffset; fadeParameters.mBottomFadeBoundary = static_cast( visualParameters.mFadeBoundary.mBottom ); - fadeParameters.mBottomFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mBottom > 0 ? fadeParameters.mBottomFadeBoundary : MINIMUM_FADE_BOUNDARY ); + fadeParameters.mBottomFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mBottom > 0u ? fadeParameters.mBottomFadeBoundary : MINIMUM_FADE_BOUNDARY ); fadeParameters.mBottomFadeThreshold = relayoutData.mTextViewSize.height - fadeParameters.mBottomFadeBoundary; fadeParameters.mBottomFadeThresholdOffset = relayoutData.mTextViewSize.height - fadeParameters.mBottomFadeBoundaryOffset; @@ -1257,9 +1256,9 @@ void UpdateVisibilityForFade( const TextView::LayoutParameters& layoutParameters // Traverses all characters and calculates the visibility. - std::size_t infoTableCharacterIndex = 0; + std::size_t infoTableCharacterIndex = 0u; - relayoutParameters.mIndices.mLineIndex = 0; + relayoutParameters.mIndices.mLineIndex = 0u; for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(), endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end(); @@ -1268,7 +1267,7 @@ void UpdateVisibilityForFade( const TextView::LayoutParameters& layoutParameters { TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt ); - relayoutParameters.mIndices.mWordIndex = 0; + relayoutParameters.mIndices.mWordIndex = 0u; for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.begin(), endWordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.end(); @@ -1279,7 +1278,7 @@ void UpdateVisibilityForFade( const TextView::LayoutParameters& layoutParameters relayoutParameters.mIsFirstCharacterOfWord = true; relayoutParameters.mWordSize = wordLayoutInfo.mSize; - relayoutParameters.mIndices.mCharacterIndex = 0; + relayoutParameters.mIndices.mCharacterIndex = 0u; for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(), endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end(); @@ -1334,15 +1333,15 @@ void UpdateVisibilityForEllipsize( const TextView::LayoutParameters& layoutParam // Retrieves the first index and the last index of the line. ellipsizeParameters.mFirstIndex = lineInfo.mCharacterGlobalIndex; - ellipsizeParameters.mLastIndex = 0; - if( ( lineInfoIt + 1 ) != endLineInfoIt ) + ellipsizeParameters.mLastIndex = 0u; + if( ( lineInfoIt + 1u ) != endLineInfoIt ) { - const Toolkit::TextView::LineLayoutInfo& nextLineInfo( *( lineInfoIt + 1 ) ); - ellipsizeParameters.mLastIndex = nextLineInfo.mCharacterGlobalIndex - 1; + const Toolkit::TextView::LineLayoutInfo& nextLineInfo( *( lineInfoIt + 1u ) ); + ellipsizeParameters.mLastIndex = nextLineInfo.mCharacterGlobalIndex - 1u; } else { - ellipsizeParameters.mLastIndex = relayoutData.mCharacterLayoutInfoTable.size() - 1; + ellipsizeParameters.mLastIndex = relayoutData.mCharacterLayoutInfoTable.size() - 1u; } // Retrieves the first character of the line and build the position of the line with the bearing. @@ -1386,7 +1385,7 @@ void UpdateVisibilityForEllipsize( const TextView::LayoutParameters& layoutParam { // Current line is not ellipsized. // Need to check if there is a next line and if it's not visible. If there is, current line needs to be ellipsized. - Toolkit::TextView::LineLayoutInfoContainer::const_iterator nextLineInfoIt = lineInfoIt + 1; + Toolkit::TextView::LineLayoutInfoContainer::const_iterator nextLineInfoIt = lineInfoIt + 1u; if( nextLineInfoIt != endLineInfoIt ) { // Retrives the position of the first character of the line and remove @@ -1460,122 +1459,330 @@ void UpdateVisibility( const TextView::LayoutParameters& layoutParameters, } } -void UpdateTextActorInfo( const TextView::VisualParameters& visualParameters, - TextView::RelayoutData& relayoutData ) +/** + * Creates an image actor for the emoticon. + * + * @param[in] visualParameters Some visual parameters (fade, sort modifier and blending). + * @param[in,out] characterLayout Layout info for the character. + * @param[in] character The character. + */ +void CreateEmoticon( const TextView::VisualParameters& visualParameters, + TextViewProcessor::CharacterLayoutInfo& characterLayout, + const Character& character ) +{ + // The character is an emoticon. + ImageActor imageActor = ImageActor::DownCast( characterLayout.mGlyphActor ); + if( !imageActor ) + { + imageActor = ImageActor::New(); + + GlyphImage image = GlyphImage::New( character ); + + if( image ) + { + imageActor.SetImage( image ); + } + } + + imageActor.SetPosition( Vector3( characterLayout.mPosition.x + characterLayout.mOffset.x, + characterLayout.mPosition.y + characterLayout.mOffset.y, + characterLayout.mPosition.z ) ); + imageActor.SetSize( characterLayout.mSize ); + + // Sets the sort modifier value. + imageActor.SetSortModifier( visualParameters.mSortModifier ); + + characterLayout.mGlyphActor = imageActor; +} + +/** + * Creates text-actors for the given text. + * + * @param[in] visualParameters Some visual parameters (fade, sort modifier and blending). + * @param[in,out] relayoutData Natural size (metrics), layout, text-actor info. + * @param[in,out] line Layout info for the line. + * @param[in,out] characterLayout Layout info for the character. + * @param[in] character The character. + * @param[in] style The character's style. + * @param[in,out] currentTextActorInfo Temporary stores the text-actor's info to be set. + * @param[in,out] createGlyphActors Whether to initialize renderable-actor handles. + */ +void CreateTextActor( const TextView::VisualParameters& visualParameters, + TextView::RelayoutData& relayoutData, + const TextViewProcessor::LineLayoutInfo& line, + TextViewProcessor::CharacterLayoutInfo& characterLayout, + const Character& character, + const TextStyle& style, + CurrentTextActorInfo& currentTextActorInfo, + bool createGlyphActors ) +{ + // Set the text-actor for the current traversed text. + if( currentTextActorInfo.textActor ) + { + currentTextActorInfo.textActor.SetText( currentTextActorInfo.text ); + currentTextActorInfo.textActor.SetPosition( currentTextActorInfo.position ); + currentTextActorInfo.textActor.SetSize( currentTextActorInfo.size ); + + SetVisualParameters( currentTextActorInfo, + visualParameters, + relayoutData, + line.mSize.height ); + } + + currentTextActorInfo.text = Text( character ); + currentTextActorInfo.position = Vector3( characterLayout.mPosition.x + characterLayout.mOffset.x, + characterLayout.mPosition.y + characterLayout.mOffset.y, + characterLayout.mPosition.z ); + currentTextActorInfo.size = characterLayout.mSize * relayoutData.mShrinkFactor; + + currentTextActorInfo.color = style.GetTextColor(); + currentTextActorInfo.color.a = characterLayout.mColorAlpha; + + currentTextActorInfo.gradientColor = characterLayout.mGradientColor; + currentTextActorInfo.startPoint = characterLayout.mStartPoint; + currentTextActorInfo.endPoint = characterLayout.mEndPoint; + + TextActor textActor = TextActor::DownCast( characterLayout.mGlyphActor ); + + if( createGlyphActors ) + { + if( textActor ) + { + // Try to reuse first the text-actor of this character. + textActor.SetTextStyle( style ); + } + else + { + // If there is no text-actor, try to retrieve one from the cache. + textActor = relayoutData.mTextActorCache.RetrieveTextActor(); + + // If still there is no text-actor, create one. + if( !textActor ) + { + TextActorParameters parameters( style, TextActorParameters::FONT_DETECTION_OFF ); + textActor = TextActor::New( Text(), parameters ); + } + else + { + textActor.SetTextStyle( style ); + } + } + characterLayout.mGlyphActor = textActor; + } + + // Update the current text-actor. + currentTextActorInfo.textActor = textActor; +} + +/** + * Traverses the whole line initializating renderable-actor handles and updating them with the new size and position. + * + * @param[in] visualParameters Some visual parameters (fade, sort modifier and blending). + * @param[in,out] relayoutData Natural size (metrics), layout, text-actor info. + * @param[in,out] line Layout info for the line. + * @param[in,out] characterGlobalIndex Index to the character within the whole text. + * @param[in,out] lineLayoutInfoIndex Index to the table of laid out lines. + * @param[in,out] createGlyphActors Whether to initialize renderable-actor handles. + */ +void UpdateTextActorInfoForLine( const TextView::VisualParameters& visualParameters, + TextView::RelayoutData& relayoutData, + TextViewProcessor::LineLayoutInfo& line, + std::size_t& characterGlobalIndex, + std::size_t& lineLayoutInfoIndex, + bool createGlyphActors ) { CurrentTextActorInfo currentTextActorInfo; - // Traverses the text-actor and layout info data structures. - for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(), - endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end(); - lineLayoutIt != endLineLayoutIt; - ++lineLayoutIt ) + const std::size_t lineLayoutInfoSize = relayoutData.mLines.size(); // Number of laid out lines. + bool lineLayoutEnd = false; // Whether lineLayoutInfoIndex points at the last laid out line. + bool glyphActorCreatedForLine = false; // Whether a renderable actor has been created for this line. + + TextStyle currentStyle; // style for the current text-actor. + + Vector4 currentGradientColor; // gradient color for the current text-actor. + Vector2 currentStartPoint; // start point for the current text-actor. + Vector2 currentEndPoint; // end point for the current text-actor. + + bool currentIsColorGlyph = false; // Whether current glyph is an emoticon. + + std::vector textActorsToRemove; // Keep a vector of text-actors to be included into the cache. + + std::size_t characterLineIndex = 0u; // Index to the character (within the line). + for( TextViewProcessor::WordLayoutInfoContainer::iterator wordIt = line.mWordsLayoutInfo.begin(), wordEndIt = line.mWordsLayoutInfo.end(); + wordIt != wordEndIt; + ++wordIt ) { - TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt ); + TextViewProcessor::WordLayoutInfo& word( *wordIt ); - for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.begin(), - endWordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.end(); - wordLayoutIt != endWordLayoutIt; - ++wordLayoutIt ) + for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterIt = word.mCharactersLayoutInfo.begin(), characterEndIt = word.mCharactersLayoutInfo.end(); + characterIt != characterEndIt; + ++characterIt ) { - TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt ); + TextViewProcessor::CharacterLayoutInfo& characterLayout( *characterIt ); - for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(), - endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end(); - characterLayoutIt != endCharacterLayoutIt; - ++characterLayoutIt ) + // Check if there is a new line. + const bool newLine = !lineLayoutEnd && ( characterGlobalIndex == relayoutData.mLines[lineLayoutInfoIndex].mCharacterGlobalIndex ); + + if( newLine ) { - TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt ); + // Point to the next line. + ++lineLayoutInfoIndex; + if( lineLayoutInfoIndex >= lineLayoutInfoSize ) + { + // Arrived at last line. + lineLayoutEnd = true; // Avoids access out of bounds in the relayoutData.mLines vector. + } + glyphActorCreatedForLine = false; + } + + // Do not create a glyph-actor if there is no text. + const Character character = characterLayout.mStyledText.mText[0u]; // there are only one character per character layout. + const TextStyle& style = characterLayout.mStyledText.mStyle; + + bool appendCharacter = false; - if( characterLayoutInfo.mIsColorGlyph ) + if( characterLayout.mIsColorGlyph || + !character.IsWhiteSpace() || // A new line character is also a white space. + ( character.IsWhiteSpace() && style.IsUnderlineEnabled() ) ) + { + // Do not create a glyph-actor if it's a white space (without underline) or a new line character. + + // Creates one glyph-actor for each counsecutive group of characters, with the same style, per line, or if it's an emoticon. + + if( !glyphActorCreatedForLine || + characterLayout.mIsColorGlyph || + ( characterLayout.mIsColorGlyph != currentIsColorGlyph ) || + ( style != currentStyle ) || + ( characterLayout.mGradientColor != currentGradientColor ) || + ( characterLayout.mStartPoint != currentStartPoint ) || + ( characterLayout.mEndPoint != currentEndPoint ) ) { - ImageActor imageActor = ImageActor::DownCast( characterLayoutInfo.mGlyphActor ); + characterLayout.mSetText = false; + characterLayout.mSetStyle = false; - if( characterLayoutInfo.mSetText ) - { - GlyphImage image = GlyphImage::New( characterLayoutInfo.mStyledText.mText[0] ); + // There is a new style or a new line. + glyphActorCreatedForLine = true; - if( image ) - { - imageActor.SetImage( image ); - } - characterLayoutInfo.mSetText = false; + if( characterLayout.mIsColorGlyph ) + { + CreateEmoticon( visualParameters, + characterLayout, + character ); + } + else + { + CreateTextActor( visualParameters, + relayoutData, + line, + characterLayout, + character, + style, + currentTextActorInfo, + createGlyphActors ); } - imageActor.SetPosition( Vector3( characterLayoutInfo.mPosition.x + characterLayoutInfo.mOffset.x, - characterLayoutInfo.mPosition.y + characterLayoutInfo.mOffset.y, - characterLayoutInfo.mPosition.z ) ); - imageActor.SetSize( characterLayoutInfo.mSize ); + // Update style to be checked with next characters. + currentStyle = style; + currentGradientColor = characterLayout.mGradientColor; + currentStartPoint = characterLayout.mStartPoint; + currentEndPoint = characterLayout.mEndPoint; + currentIsColorGlyph = characterLayout.mIsColorGlyph; - // Sets the sort modifier value. - imageActor.SetSortModifier( visualParameters.mSortModifier ); + characterLayout.mGlyphActor.SetParentOrigin( ParentOrigin::TOP_LEFT ); + characterLayout.mGlyphActor.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT ); } else { - TextActor textActor = TextActor::DownCast( characterLayoutInfo.mGlyphActor ); - if( textActor ) - { - // There is a new text-actor. Set text and everything to the previous one. - if( currentTextActorInfo.textActor ) - { - currentTextActorInfo.textActor.SetText( currentTextActorInfo.text ); - currentTextActorInfo.textActor.SetPosition( currentTextActorInfo.position ); - currentTextActorInfo.textActor.SetSize( currentTextActorInfo.size ); - - SetVisualParameters( currentTextActorInfo, - visualParameters, - relayoutData, - lineLayoutInfo.mSize.height ); - } + DALI_ASSERT_DEBUG( !characterLayout.mIsColorGlyph && "TextViewProcessor::InitializeTextActorInfo. An image-actor doesn't store more than one emoticon." ); - currentTextActorInfo.text = characterLayoutInfo.mStyledText.mText; - currentTextActorInfo.position = Vector3( characterLayoutInfo.mPosition.x + characterLayoutInfo.mOffset.x, - characterLayoutInfo.mPosition.y + characterLayoutInfo.mOffset.y, - characterLayoutInfo.mPosition.z ); - currentTextActorInfo.size = characterLayoutInfo.mSize * relayoutData.mShrinkFactor; + // Same style than previous one. - currentTextActorInfo.color = characterLayoutInfo.mStyledText.mStyle.GetTextColor(); - currentTextActorInfo.color.a = characterLayoutInfo.mColorAlpha; + // Add the character to the current text-actor and update the size. + appendCharacter = true; - currentTextActorInfo.gradientColor = characterLayoutInfo.mGradientColor; - currentTextActorInfo.startPoint = characterLayoutInfo.mStartPoint; - currentTextActorInfo.endPoint = characterLayoutInfo.mEndPoint; - - // Update the current text-actor. - currentTextActorInfo.textActor = textActor; - } - else + TextActor textActor = TextActor::DownCast( characterLayout.mGlyphActor ); + if( textActor ) { - // If this character layout has no text-actor is because this character has the same style than previous one. - // Add the character to the current text-actor and update the size. - if( characterLayoutInfo.mIsVisible && ( TextViewProcessor::LineSeparator != wordLayoutInfo.mType ) ) - { - currentTextActorInfo.text.Append( characterLayoutInfo.mStyledText.mText ); + // There is a previously created text-actor for this character. + // If this character has another one put it into the cache. + textActor.SetText( "" ); + textActorsToRemove.push_back( textActor ); + } - currentTextActorInfo.position.y = std::min( currentTextActorInfo.position.y, ( characterLayoutInfo.mPosition.y + characterLayoutInfo.mOffset.y ) ); - currentTextActorInfo.size.width += characterLayoutInfo.mSize.width * relayoutData.mShrinkFactor; - currentTextActorInfo.size.height = std::max( currentTextActorInfo.size.height, characterLayoutInfo.mSize.height * relayoutData.mShrinkFactor ); - } + if( characterLayout.mGlyphActor ) + { + characterLayout.mGlyphActor.Reset(); } } - } // end characters - } // end words + } // no white space / new line char + else + { + appendCharacter = true; + } - if( !currentTextActorInfo.text.IsEmpty() ) - { - if( currentTextActorInfo.textActor ) + if( appendCharacter ) { - currentTextActorInfo.textActor.SetText( currentTextActorInfo.text ); - currentTextActorInfo.textActor.SetPosition( currentTextActorInfo.position ); - currentTextActorInfo.textActor.SetSize( currentTextActorInfo.size ); + // Add the character to the current text-actor and update the size. + if( characterLayout.mIsVisible && ( TextViewProcessor::LineSeparator != word.mType ) ) + { + currentTextActorInfo.text.Append( character ); - SetVisualParameters( currentTextActorInfo, - visualParameters, - relayoutData, - lineLayoutInfo.mSize.height ); + currentTextActorInfo.position.y = std::min( currentTextActorInfo.position.y, ( characterLayout.mPosition.y + characterLayout.mOffset.y ) ); + currentTextActorInfo.size.width += characterLayout.mSize.width * relayoutData.mShrinkFactor; + currentTextActorInfo.size.height = std::max( currentTextActorInfo.size.height, characterLayout.mSize.height * relayoutData.mShrinkFactor ); + } } + + ++characterGlobalIndex; + ++characterLineIndex; + } // characters + } // words + + if( !currentTextActorInfo.text.IsEmpty() ) + { + if( currentTextActorInfo.textActor ) + { + currentTextActorInfo.textActor.SetText( currentTextActorInfo.text ); + currentTextActorInfo.textActor.SetPosition( currentTextActorInfo.position ); + currentTextActorInfo.textActor.SetSize( currentTextActorInfo.size ); + + SetVisualParameters( currentTextActorInfo, + visualParameters, + relayoutData, + line.mSize.height ); } - } // end lines + } + + // Insert the spare text-actors into the cache. + relayoutData.mTextActorCache.InsertTextActors( textActorsToRemove ); +} + +void UpdateTextActorInfo( const TextView::VisualParameters& visualParameters, + TextView::RelayoutData& relayoutData, + bool createGlyphActors ) +{ + if( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.empty() ) + { + // nothing to do if there is no lines. + return; + } + + std::size_t characterGlobalIndex = 0u; // Index to the global character (within the whole text). + std::size_t lineLayoutInfoIndex = 0u; // Index to the laid out line info. + + for( TextViewProcessor::LineLayoutInfoContainer::iterator lineIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(), lineEndIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end(); + lineIt != lineEndIt; + ++lineIt ) + { + TextViewProcessor::LineLayoutInfo& line( *lineIt ); + + UpdateTextActorInfoForLine( visualParameters, + relayoutData, + line, + characterGlobalIndex, + lineLayoutInfoIndex, + createGlyphActors ); + } // lines for( std::vector::iterator it = relayoutData.mEllipsizedGlyphActors.begin(), endIt = relayoutData.mEllipsizedGlyphActors.end(); @@ -1646,7 +1853,7 @@ void CalculateUnderlineInfo( TextView::RelayoutData& relayoutData, TextViewRelay else { // Retrieve last underline info and update it if current underline thickness is bigger. - UnderlineInfo& underlineInfo( *( textUnderlineStatus.mUnderlineInfo.end() - 1 ) ); + UnderlineInfo& underlineInfo( *( textUnderlineStatus.mUnderlineInfo.end() - 1u ) ); underlineInfo.mMaxHeight = std::max( underlineInfo.mMaxHeight, character.mSize.height ); @@ -1697,8 +1904,8 @@ void SetUnderlineInfo( TextView::RelayoutData& relayoutData ) // Whether current text is underlined. textUnderlineStatus.mCurrentUnderlineStatus = false; - textUnderlineStatus.mCharacterGlobalIndex = 0; - textUnderlineStatus.mLineGlobalIndex = 0; + textUnderlineStatus.mCharacterGlobalIndex = 0u; + textUnderlineStatus.mLineGlobalIndex = 0u; float currentLineHeight = 0.f; float currentLineAscender = 0.f; @@ -1807,13 +2014,9 @@ void RemoveGlyphActors( Actor textView, } } -void InsertToTextView( const TextView::RelayoutOperationMask relayoutOperationMask, - Actor textView, +void InsertToTextView( Actor textView, TextView::RelayoutData& relayoutData ) { - const bool insertToTextView = relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW; - const bool insertToTextActorList = relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST; - // Add text-actors to the text-view. for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(), @@ -1840,14 +2043,8 @@ void InsertToTextView( const TextView::RelayoutOperationMask relayoutOperationMa if( characterLayoutInfo.mIsVisible && characterLayoutInfo.mGlyphActor ) // White spaces and '\n' characters doesn't have a text-actor. { //Add to the text-view. - if( insertToTextView ) - { - textView.Add( characterLayoutInfo.mGlyphActor ); - } - if( insertToTextActorList ) - { - relayoutData.mGlyphActors.push_back( characterLayoutInfo.mGlyphActor ); - } + textView.Add( characterLayoutInfo.mGlyphActor ); + relayoutData.mGlyphActors.push_back( characterLayoutInfo.mGlyphActor ); } } // end character } // end words @@ -1861,14 +2058,8 @@ void InsertToTextView( const TextView::RelayoutOperationMask relayoutOperationMa RenderableActor glyphActor = ( *it ); //Add to the text-view. - if( insertToTextView ) - { - textView.Add( glyphActor ); - } - if( insertToTextActorList ) - { - relayoutData.mGlyphActors.push_back( glyphActor ); - } + textView.Add( glyphActor ); + relayoutData.mGlyphActors.push_back( glyphActor ); } relayoutData.mEllipsizedGlyphActors.clear(); } diff --git a/base/dali-toolkit/internal/controls/text-view/relayout-utilities.h b/base/dali-toolkit/internal/controls/text-view/relayout-utilities.h index d77f34e..79fdc36 100644 --- a/base/dali-toolkit/internal/controls/text-view/relayout-utilities.h +++ b/base/dali-toolkit/internal/controls/text-view/relayout-utilities.h @@ -436,13 +436,16 @@ void UpdateVisibility( const TextView::LayoutParameters& layoutParameters, TextView::RelayoutData& relayoutData ); /** - * Traverse all text updating text-actor handles with new size, position, ... + * Traverse all text initializing all non initialized text-actor handles + * and updating text-actor handles with new size, position, ... * * @param[in] visualParameters Some visual parameters (fade, sort modifier and blending). * @param[in,out] relayoutData Natural size (metrics), layout, text-actor info. + * @param[in] createGlyphActors Whether to create RenderableActor for text-actors or emojis. */ void UpdateTextActorInfo( const TextView::VisualParameters& visualParameters, - TextView::RelayoutData& relayoutData ); + TextView::RelayoutData& relayoutData, + bool createGlyphActors ); /** * Traverses the whole text and for each piece of underlined text, @@ -470,14 +473,12 @@ void RemoveGlyphActors( Actor textView, const std::vector& glyphActors ); /** - * Inserts the text-actors into the text-view and/or the text-actor's list. + * Inserts the text-actors into the text-view and the text-actor's list. * - * @param[in] relayoutOperationMask Whether the text-actors should be added into the text-view, the list of text-actors or in both. * @param[in,out] textView The text-view. * @param[in,out] relayoutData The text-view's data structures. */ -void InsertToTextView( TextView::RelayoutOperationMask relayoutOperationMask, - Actor textView, +void InsertToTextView( Actor textView, TextView::RelayoutData& relayoutData ); /** diff --git a/base/dali-toolkit/internal/controls/text-view/split-by-char-policies.cpp b/base/dali-toolkit/internal/controls/text-view/split-by-char-policies.cpp index 6ee85bd..c92b8e7 100644 --- a/base/dali-toolkit/internal/controls/text-view/split-by-char-policies.cpp +++ b/base/dali-toolkit/internal/controls/text-view/split-by-char-policies.cpp @@ -115,8 +115,8 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter relayoutParameters.mPositionOffset = Vector3::ZERO; relayoutParameters.mIsFirstCharacter = true; - relayoutParameters.mIndices.mLineIndex = 0; - relayoutParameters.mCharacterGlobalIndex = 0; + relayoutParameters.mIndices.mLineIndex = 0u; + relayoutParameters.mCharacterGlobalIndex = 0u; for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(), endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end(); @@ -127,7 +127,7 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter relayoutParameters.mIsNewLine = true; relayoutParameters.mLineSize = lineLayoutInfo.mSize; - relayoutParameters.mIndices.mWordIndex = 0; + relayoutParameters.mIndices.mWordIndex = 0u; for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.begin(), endWordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.end(); @@ -140,7 +140,7 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter relayoutParameters.mIsFirstCharacterOfWord = true; relayoutParameters.mWordSize = wordLayoutInfo.mSize; - relayoutParameters.mIndices.mCharacterIndex = 0; + relayoutParameters.mIndices.mCharacterIndex = 0u; for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(), endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end(); @@ -215,7 +215,7 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter // Check if the last character is a new line character. In that case the height should be added. if( !relayoutData.mTextLayoutInfo.mLinesLayoutInfo.empty() ) { - const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1 ) ); + const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1u ) ); if( lineLayoutInfo.mWordsLayoutInfo.empty() ) // if it's empty, it means the last character is a new line character. { @@ -254,22 +254,18 @@ void Relayout( Actor textView, relayoutData ); } - if( relayoutOperationMask & TextView::RELAYOUT_INITIALIZE_TEXT_ACTORS ) - { - TextViewProcessor::InitializeTextActorInfo( relayoutData ); - } - - if( relayoutOperationMask & TextView::RELAYOUT_TEXT_ACTOR_UPDATE ) + const bool initializeTextActors = relayoutOperationMask & TextView::RELAYOUT_INITIALIZE_TEXT_ACTORS; + const bool updateTextActors = relayoutOperationMask & TextView::RELAYOUT_TEXT_ACTOR_UPDATE; + if( initializeTextActors || updateTextActors ) { TextViewRelayout::UpdateTextActorInfo( visualParameters, - relayoutData ); + relayoutData, + initializeTextActors ); } - if( ( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW ) || - ( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ) ) + if( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW ) { - TextViewRelayout::InsertToTextView( relayoutOperationMask, - textView, + TextViewRelayout::InsertToTextView( textView, relayoutData ); } } diff --git a/base/dali-toolkit/internal/controls/text-view/split-by-new-line-char-policies.cpp b/base/dali-toolkit/internal/controls/text-view/split-by-new-line-char-policies.cpp index 3968cd8..770ed65 100644 --- a/base/dali-toolkit/internal/controls/text-view/split-by-new-line-char-policies.cpp +++ b/base/dali-toolkit/internal/controls/text-view/split-by-new-line-char-policies.cpp @@ -129,9 +129,9 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter } relayoutParameters.mIsFirstCharacter = true; - relayoutParameters.mIndices.mLineIndex = 0; + relayoutParameters.mIndices.mLineIndex = 0u; relayoutParameters.mPositionOffset = Vector3::ZERO; - relayoutParameters.mCharacterGlobalIndex = 0; + relayoutParameters.mCharacterGlobalIndex = 0u; for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(), endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end(); @@ -143,7 +143,7 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter relayoutParameters.mLineSize = lineLayoutInfo.mSize * relayoutData.mShrinkFactor; relayoutParameters.mIsNewLine = true; - relayoutParameters.mIndices.mWordIndex = 0; + relayoutParameters.mIndices.mWordIndex = 0u; for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.begin(), endWordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.end(); @@ -156,7 +156,7 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter relayoutParameters.mIsFirstCharacterOfWord = true; relayoutParameters.mWordSize = wordLayoutInfo.mSize; - relayoutParameters.mIndices.mCharacterIndex = 0; + relayoutParameters.mIndices.mCharacterIndex = 0u; if( relayoutParameters.mIsNewLine ) { @@ -271,7 +271,7 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter // Check if the last character is a new line character. In that case the height should be added. if( !relayoutData.mTextLayoutInfo.mLinesLayoutInfo.empty() ) { - const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1 ) ); + const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1u ) ); if( lineLayoutInfo.mWordsLayoutInfo.empty() ) // if it's empty, it means the last character is a new line character. { @@ -310,22 +310,18 @@ void Relayout( Actor textView, relayoutData ); } - if( relayoutOperationMask & TextView::RELAYOUT_INITIALIZE_TEXT_ACTORS ) - { - TextViewProcessor::InitializeTextActorInfo( relayoutData ); - } - - if( relayoutOperationMask & TextView::RELAYOUT_TEXT_ACTOR_UPDATE ) + const bool initializeTextActors = relayoutOperationMask & TextView::RELAYOUT_INITIALIZE_TEXT_ACTORS; + const bool updateTextActors = relayoutOperationMask & TextView::RELAYOUT_TEXT_ACTOR_UPDATE; + if( initializeTextActors || updateTextActors ) { TextViewRelayout::UpdateTextActorInfo( visualParameters, - relayoutData ); + relayoutData, + initializeTextActors ); } - if( ( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW ) || - ( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ) ) + if( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW ) { - TextViewRelayout::InsertToTextView( relayoutOperationMask, - textView, + TextViewRelayout::InsertToTextView( textView, relayoutData ); } } diff --git a/base/dali-toolkit/internal/controls/text-view/split-by-word-policies.cpp b/base/dali-toolkit/internal/controls/text-view/split-by-word-policies.cpp index 19b1592..e6a8794 100644 --- a/base/dali-toolkit/internal/controls/text-view/split-by-word-policies.cpp +++ b/base/dali-toolkit/internal/controls/text-view/split-by-word-policies.cpp @@ -268,7 +268,7 @@ void CalculatePositionsForShrinkWhenExceed( TextView::RelayoutData& relayoutData float lastCharHeight = 0.f; relayoutData.mLines.clear(); - std::size_t characterGlobalIndex = 0; + std::size_t characterGlobalIndex = 0u; for( TextViewProcessor::LineLayoutInfoContainer::iterator lineIt = textLayoutInfo.mLinesLayoutInfo.begin(), lineEndIt = textLayoutInfo.mLinesLayoutInfo.end(); lineIt != lineEndIt; @@ -279,9 +279,8 @@ void CalculatePositionsForShrinkWhenExceed( TextView::RelayoutData& relayoutData // The next character is in a new line. bool isNewLine = true; - // Reset the index of words. - indices.mWordIndex = 0; + indices.mWordIndex = 0u; for( TextViewProcessor::WordLayoutInfoContainer::iterator wordIt = lineLayoutInfo.mWordsLayoutInfo.begin(), wordEndIt = lineLayoutInfo.mWordsLayoutInfo.end(); wordIt != wordEndIt; @@ -290,7 +289,7 @@ void CalculatePositionsForShrinkWhenExceed( TextView::RelayoutData& relayoutData TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordIt ); // Reset the index of the character. - indices.mCharacterIndex = 0; + indices.mCharacterIndex = 0u; // Whether current character is the first of the word. bool isFirstCharOfWord = true; @@ -334,7 +333,6 @@ void CalculatePositionsForShrinkWhenExceed( TextView::RelayoutData& relayoutData lineInfo.mAscender = subLineInfo.mMaxAscender; // Ascender of this piece of line. relayoutData.mLines.push_back( lineInfo ); - // Stores some info to calculate the line justification in a post-process. TextView::LineJustificationInfo justificationInfo; @@ -349,7 +347,7 @@ void CalculatePositionsForShrinkWhenExceed( TextView::RelayoutData& relayoutData } // Get last line info and calculate the bearing. - const Toolkit::TextView::LineLayoutInfo& lineInfo( *( relayoutData.mLines.end() - 1 ) ); + const Toolkit::TextView::LineLayoutInfo& lineInfo( *( relayoutData.mLines.end() - 1u ) ); const float bearingOffset = ( ( lineInfo.mSize.height - lineInfo.mAscender ) - ( characterLayoutInfo.mSize.height - characterLayoutInfo.mAscender ) ) * shrinkFactor; previousSize = characterLayoutInfo.mSize * shrinkFactor; @@ -397,14 +395,14 @@ float RelayoutForShrinkToFit( TextView::RelayoutData& relayoutData, const float MIN_RATIO( 0.90f ); // The algorithm finishes if the ratio const float MAX_RATIO( 1.00f ); // new_text_height / text_view_height is between this two values - const unsigned int MAX_ITERATIONS( 8 ); // or max_iteration is reached. + const unsigned int MAX_ITERATIONS( 8u ); // or max_iteration is reached. float ratio = newTextHeight / textViewSize.height; float maxScaleFactor = shrinkFactor; // bigger scale factors than maxScaleFactor will produce a too big text. float minScaleFactor = shrinkFactor * ( textViewSize.height / newTextHeight ); // smaller scale factors than minScaleFactor will produce a too small text. - for( unsigned int iterations = 0; ( ( MIN_RATIO > ratio ) || ( ratio > MAX_RATIO ) ) && ( iterations < MAX_ITERATIONS ); ++iterations ) + for( unsigned int iterations = 0u; ( ( MIN_RATIO > ratio ) || ( ratio > MAX_RATIO ) ) && ( iterations < MAX_ITERATIONS ); ++iterations ) { // Calculates the new scale factor. // The new scale factor is always between the min and max scale factors. @@ -465,7 +463,7 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter relayoutData.mShrinkFactor = 1.f; // Shrink factor used when the exceed policy contains ShrinkToFit - if( TextView::Shrink== layoutParameters.mExceedPolicy ) + if( TextView::Shrink == layoutParameters.mExceedPolicy ) { // Relays-out the text for the shrink to fit policy. relayoutData.mShrinkFactor = RelayoutForShrinkToFit( relayoutData, layoutParameters ); @@ -477,8 +475,8 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter relayoutParameters.mPositionOffset = Vector3::ZERO; relayoutParameters.mIsFirstCharacter = true; - relayoutParameters.mIndices.mLineIndex = 0; - relayoutParameters.mCharacterGlobalIndex = 0; + relayoutParameters.mIndices.mLineIndex = 0u; + relayoutParameters.mCharacterGlobalIndex = 0u; for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(), endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end(); @@ -489,7 +487,7 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter relayoutParameters.mIsNewLine = true; relayoutParameters.mLineSize = lineLayoutInfo.mSize; - relayoutParameters.mIndices.mWordIndex = 0; + relayoutParameters.mIndices.mWordIndex = 0u; for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.begin(), endWordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.end(); @@ -502,7 +500,7 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter relayoutParameters.mIsFirstCharacterOfWord = true; relayoutParameters.mWordSize = wordLayoutInfo.mSize; - relayoutParameters.mIndices.mCharacterIndex = 0; + relayoutParameters.mIndices.mCharacterIndex = 0u; for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(), endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end(); @@ -601,7 +599,7 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter // Check if the last character is a new line character. In that case the height should be added. if( !relayoutData.mTextLayoutInfo.mLinesLayoutInfo.empty() ) { - const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1 ) ); + const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1u ) ); if( lineLayoutInfo.mWordsLayoutInfo.empty() ) // if it's empty, it means the last character is a new line character. { @@ -639,23 +637,18 @@ void Relayout( Actor textView, visualParameters, relayoutData ); } - - if( relayoutOperationMask & TextView::RELAYOUT_INITIALIZE_TEXT_ACTORS ) - { - TextViewProcessor::InitializeTextActorInfo( relayoutData ); - } - - if( relayoutOperationMask & TextView::RELAYOUT_TEXT_ACTOR_UPDATE ) + const bool initializeTextActors = relayoutOperationMask & TextView::RELAYOUT_INITIALIZE_TEXT_ACTORS; + const bool updateTextActors = relayoutOperationMask & TextView::RELAYOUT_TEXT_ACTOR_UPDATE; + if( initializeTextActors || updateTextActors ) { TextViewRelayout::UpdateTextActorInfo( visualParameters, - relayoutData ); + relayoutData, + initializeTextActors ); } - if( ( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW ) || - ( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ) ) + if( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW ) { - TextViewRelayout::InsertToTextView( relayoutOperationMask, - textView, + TextViewRelayout::InsertToTextView( textView, relayoutData ); } } diff --git a/base/dali-toolkit/internal/controls/text-view/text-processor.cpp b/base/dali-toolkit/internal/controls/text-view/text-processor.cpp index 1eeac3a..8e212a8 100644 --- a/base/dali-toolkit/internal/controls/text-view/text-processor.cpp +++ b/base/dali-toolkit/internal/controls/text-view/text-processor.cpp @@ -41,7 +41,7 @@ void SplitInLines( const MarkupProcessor::StyledTextArray& text, { const MarkupProcessor::StyledText& styledText( *it ); - for( size_t i = 0, length = styledText.mText.GetLength(); i < length; ++i ) + for( size_t i = 0u, length = styledText.mText.GetLength(); i < length; ++i ) { const Dali::Character character = styledText.mText[i]; @@ -75,7 +75,7 @@ void SplitInWords( const MarkupProcessor::StyledTextArray& line, for( MarkupProcessor::StyledTextArray::const_iterator it = line.begin(), endIt = line.end(); it != endIt; ++it ) { const MarkupProcessor::StyledText& styledText( *it ); - const Dali::Character character = styledText.mText[0]; + const Dali::Character character = styledText.mText[0u]; if( character.IsWhiteSpace() ) { @@ -121,7 +121,7 @@ bool BeginsRightToLeftCharacter( const MarkupProcessor::StyledTextArray& styledT { const Text& text( (*it).mText ); - for( size_t i = 0, length = text.GetLength(); i < length; ++i ) + for( size_t i = 0u, length = text.GetLength(); i < length; ++i ) { Character::CharacterDirection direction = text[i].GetCharacterDirection(); if( direction != Character::Neutral ) @@ -136,7 +136,7 @@ bool BeginsRightToLeftCharacter( const MarkupProcessor::StyledTextArray& styledT bool BeginsRightToLeftCharacter( const Text& text ) { - for( size_t i = 0, length = text.GetLength(); i < length; ++i ) + for( size_t i = 0u, length = text.GetLength(); i < length; ++i ) { Character::CharacterDirection direction = text[i].GetCharacterDirection(); if( direction != Character::Neutral ) @@ -154,7 +154,7 @@ bool ContainsRightToLeftCharacter( const MarkupProcessor::StyledTextArray& style { const Text& text( (*it).mText ); - for( size_t i = 0, length = text.GetLength(); i < length; ++i ) + for( size_t i = 0u, length = text.GetLength(); i < length; ++i ) { Character::CharacterDirection direction = text[i].GetCharacterDirection(); if( ( Character::RightToLeft == direction ) || ( Character::RightToLeftWeak == direction ) ) @@ -169,7 +169,7 @@ bool ContainsRightToLeftCharacter( const MarkupProcessor::StyledTextArray& style bool ContainsRightToLeftCharacter( const Dali::Text& text ) { - for( size_t i = 0, length = text.GetLength(); i < length; ++i ) + for( size_t i = 0u, length = text.GetLength(); i < length; ++i ) { Character::CharacterDirection direction = ( text[i] ).GetCharacterDirection(); if( ( Character::RightToLeft == direction ) || ( Character::RightToLeftWeak == direction ) ) @@ -209,15 +209,15 @@ void ConvertBidirectionalText( const MarkupProcessor::StyledTextArray& line, // pad these buffers with 0's, as it's unclear what fribidi_log2vis does w.r.t. // the length of it's output content (appears the same as input content, and does // not seem to generate bidi marks i.e. FRIBIDI_CHAR_LRM/FRIBIDI_CHAR_RLM) - logicalStrBuffer.resize( stringSize+1, 0 ); - visualStrBuffer.resize( stringSize+1, 0 ); - FriBidiChar *logicalStr( &logicalStrBuffer[0] ); - FriBidiChar *visualStr( &visualStrBuffer[0] ); + logicalStrBuffer.resize( stringSize+1u, 0u ); + visualStrBuffer.resize( stringSize+1u, 0u ); + FriBidiChar *logicalStr( &logicalStrBuffer[0u] ); + FriBidiChar *visualStr( &visualStrBuffer[0u] ); // Convert UTF-8 string to unicode string const std::size_t length = fribidi_charset_to_unicode( FRIBIDI_CHAR_SET_UTF8, textToBeConverted.c_str(), stringSize, logicalStr ); - if( 0 == length ) + if( 0u == length ) { DALI_ASSERT_DEBUG( !"TextProcessor::ConvertBidirectionalText. Error when calling at fribidi_charset_to_unicode" ); @@ -229,28 +229,28 @@ void ConvertBidirectionalText( const MarkupProcessor::StyledTextArray& line, // Convert and reorder the string as specified by the Unicode Bidirectional Algorithm FriBidiCharType baseDirection = FRIBIDI_TYPE_ON; - fribidi_boolean log2vis = fribidi_log2vis( logicalStr, length, &baseDirection, visualStr, &logicalToVisualMap[0], &visualToLogicalMap[0], NULL ); + fribidi_boolean log2vis = fribidi_log2vis( logicalStr, length, &baseDirection, visualStr, &logicalToVisualMap[0u], &visualToLogicalMap[0u], NULL ); if(log2vis) { // Convert the unicode string back to the UTF-8 string std::vector bidiTextConverted; - bidiTextConverted.resize( length * 4 + 1 ); // Maximum bytes to represent one UTF-8 character is 6. + bidiTextConverted.resize( length * 4u + 1u ); // Maximum bytes to represent one UTF-8 character is 6. // Currently Dali doesn't support this UTF-8 extension. Dali only supports 'regular' UTF-8 which has a maximum of 4 bytes per character. - fribidi_unicode_to_charset( FRIBIDI_CHAR_SET_UTF8, visualStr, length, &bidiTextConverted[0] ); + fribidi_unicode_to_charset( FRIBIDI_CHAR_SET_UTF8, visualStr, length, &bidiTextConverted[0u] ); - textToBeConverted = &bidiTextConverted[0]; + textToBeConverted = &bidiTextConverted[0u]; // After reorder the text, rebuild the text with the original styles is needed. // To assign the original style is needed to use the characterLogicalToVisualMap table. - Text text( &bidiTextConverted[0] ); + Text text( &bidiTextConverted[0u] ); // Split the line in words. // Add the correct styles for the characters after they are reordered. - for( size_t i = 0; i < length; ++i ) + for( size_t i = 0u; i < length; ++i ) { const Character character( text[i] ); @@ -268,13 +268,13 @@ bool IsWhiteSpace( const MarkupProcessor::StyledTextArray& text, size_t offset ) DALI_ASSERT_DEBUG( offset < text.size() ); // assume 1 Character per StyledText - return text[offset].mText[0].IsWhiteSpace(); + return text[offset].mText[0u].IsWhiteSpace(); } void FindNearestWord( const MarkupProcessor::StyledTextArray& text, size_t offset, size_t& start, size_t& end) { const size_t size(text.size()); - offset = std::min(offset, size-1); + offset = std::min(offset, size-1u); size_t i(offset); size_t j(offset); @@ -283,7 +283,7 @@ void FindNearestWord( const MarkupProcessor::StyledTextArray& text, size_t offse if(IsWhiteSpace(text, offset)) { // scan left until non-white space / beginning of string. - while(i > 0 && IsWhiteSpace(text, i)) + while(i > 0u && IsWhiteSpace(text, i)) { i--; } @@ -309,7 +309,7 @@ void FindNearestWord( const MarkupProcessor::StyledTextArray& text, size_t offse } // expand left and right markers to encompase entire word - while(i > 0 && !IsWhiteSpace(text, i-1)) + while(i > 0u && !IsWhiteSpace(text, i-1u)) { i--; } diff --git a/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp b/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp index ddf6cd7..63b6191 100644 --- a/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp +++ b/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp @@ -121,8 +121,8 @@ bool IsTextViewProcessorNewStyleOperation( const TextView::TextViewProcessorMeta TextView::TextViewProcessorMetadata::TextViewProcessorMetadata() : mType( TextView::TextSet ), - mPosition( 0 ), - mNumberOfCharacters( 0 ), + mPosition( 0u ), + mNumberOfCharacters( 0u ), mText() { } @@ -311,8 +311,7 @@ void TextView::SetLineHeightOffset( PointSize offset ) RELAYOUT_ALIGNMENT | RELAYOUT_VISIBILITY | RELAYOUT_TEXT_ACTOR_UPDATE | - RELAYOUT_INSERT_TO_TEXT_VIEW | - RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); + RELAYOUT_INSERT_TO_TEXT_VIEW ); } } } @@ -477,8 +476,7 @@ void TextView::SetHeightExceedPolicy( Toolkit::TextView::ExceedPolicy policy ) RELAYOUT_ALIGNMENT | RELAYOUT_VISIBILITY | RELAYOUT_TEXT_ACTOR_UPDATE | - RELAYOUT_INSERT_TO_TEXT_VIEW | - RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); + RELAYOUT_INSERT_TO_TEXT_VIEW ); } } } @@ -505,8 +503,7 @@ void TextView::SetLineJustification( Toolkit::TextView::LineJustification justif RELAYOUT_ALIGNMENT | RELAYOUT_VISIBILITY | RELAYOUT_TEXT_ACTOR_UPDATE | - RELAYOUT_INSERT_TO_TEXT_VIEW | - RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); + RELAYOUT_INSERT_TO_TEXT_VIEW ); } } } @@ -534,8 +531,7 @@ void TextView::SetFadeBoundary( const Toolkit::TextView::FadeBoundary& fadeBound RELAYOUT_REMOVE_TEXT_ACTORS | RELAYOUT_VISIBILITY | RELAYOUT_TEXT_ACTOR_UPDATE | - RELAYOUT_INSERT_TO_TEXT_VIEW | - RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); + RELAYOUT_INSERT_TO_TEXT_VIEW ); } } } @@ -635,7 +631,6 @@ void TextView::GetTextLayoutInfo() if( hasGlyphActors ) { mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_INSERT_TO_TEXT_VIEW ); - mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); } } @@ -741,8 +736,7 @@ void TextView::SetSnapshotModeEnabled( bool enable ) mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_REMOVE_TEXT_ACTORS | RELAYOUT_TEXT_ACTOR_UPDATE | - RELAYOUT_INSERT_TO_TEXT_VIEW | - RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); + RELAYOUT_INSERT_TO_TEXT_VIEW ); } RelayoutRequest(); } @@ -1066,7 +1060,6 @@ Vector3 TextView::GetNaturalSize() mRelayoutData.mGlyphActors.clear(); mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_INSERT_TO_TEXT_VIEW ); - mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); } PerformTextViewProcessorOperations(); @@ -1127,7 +1120,6 @@ float TextView::GetHeightForWidth( float width ) if( hasGlyphActors ) { mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_INSERT_TO_TEXT_VIEW ); - mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); } if( differentWidth || hasGlyphActors ) @@ -1191,8 +1183,7 @@ void TextView::OnRelaidOut( Vector2 size, ActorSizeContainer& container ) RELAYOUT_ALIGNMENT | RELAYOUT_VISIBILITY | RELAYOUT_TEXT_ACTOR_UPDATE | - RELAYOUT_INSERT_TO_TEXT_VIEW | - RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); + RELAYOUT_INSERT_TO_TEXT_VIEW ); } } @@ -1300,9 +1291,9 @@ void TextView::OptimizeTextViewProcessorOperations() { bool optimizationDone = false; - if( it + 1 != endIt ) + if( it + 1u != endIt ) { - const TextViewProcessorMetadata& nextRelayoutMetadata( *( it + 1 ) ); + const TextViewProcessorMetadata& nextRelayoutMetadata( *( it + 1u ) ); if( TextView::TextInserted == nextRelayoutMetadata.mType ) { if( relayoutMetadata.mPosition == nextRelayoutMetadata.mPosition ) @@ -2006,7 +1997,7 @@ void TextView::OnLineJustificationPropertySet( Property::Value propertyValue ) void TextView::OnFadeBoundaryPropertySet( Property::Value propertyValue ) { Vector4 value( propertyValue.Get() ); - DALI_ASSERT_ALWAYS( value.x >= 0 && value.y >= 0 && value.z >= 0 && value.w >= 0 + DALI_ASSERT_ALWAYS( ( value.x >= 0.f ) && ( value.y >= 0.f ) && ( value.z >= 0.f ) && ( value.w >= 0.f ) && "TextView::OnFadeBoundaryPropertySet(). Negative value is invalid. " ); Toolkit::TextView::FadeBoundary fadeBoundary( PixelSize( static_cast( value.x ) ), diff --git a/base/dali-toolkit/internal/controls/text-view/text-view-impl.h b/base/dali-toolkit/internal/controls/text-view/text-view-impl.h index 49bb4ea..f35f2de 100644 --- a/base/dali-toolkit/internal/controls/text-view/text-view-impl.h +++ b/base/dali-toolkit/internal/controls/text-view/text-view-impl.h @@ -108,7 +108,6 @@ public: RELAYOUT_INITIALIZE_TEXT_ACTORS = 0x10, ///< Initialize text-actors (create handles). RELAYOUT_TEXT_ACTOR_UPDATE = 0x20, ///< Updates text-actors (set size, position, style, ...) RELAYOUT_INSERT_TO_TEXT_VIEW = 0x40, ///< Adds the text-actors to the text-view. - RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST = 0x80, ///< Inserts the text-actors to the text-actor list. RELAYOUT_ALL = 0xFF ///< Does all operations. }; diff --git a/base/dali-toolkit/internal/controls/text-view/text-view-line-processor.cpp b/base/dali-toolkit/internal/controls/text-view/text-view-line-processor.cpp index 81c19cc..d82691f 100644 --- a/base/dali-toolkit/internal/controls/text-view/text-view-line-processor.cpp +++ b/base/dali-toolkit/internal/controls/text-view/text-view-line-processor.cpp @@ -44,7 +44,7 @@ LineLayoutInfo::LineLayoutInfo() mAscender( 0.f ), mLineHeightOffset( 0.f ), mWordsLayoutInfo(), - mNumberOfCharacters( 0 ) + mNumberOfCharacters( 0u ) { } @@ -68,27 +68,6 @@ LineLayoutInfo& LineLayoutInfo::operator=( const LineLayoutInfo& line ) return *this; } -void UpdateLineLayoutInfo( LineLayoutInfo& lineLayoutInfo, const float lineHeightOffset ) -{ - // Update layout info. - lineLayoutInfo.mSize = Size::ZERO; - lineLayoutInfo.mAscender = 0.f; - lineLayoutInfo.mNumberOfCharacters = 0u; - for( WordLayoutInfoContainer::iterator it = lineLayoutInfo.mWordsLayoutInfo.begin(), endIt = lineLayoutInfo.mWordsLayoutInfo.end(); - it != endIt; - ++it ) - { - WordLayoutInfo& word( *it ); - - UpdateSize( lineLayoutInfo.mSize, word.mSize ); - lineLayoutInfo.mAscender = std::max( lineLayoutInfo.mAscender, word.mAscender ); - lineLayoutInfo.mNumberOfCharacters += word.mCharactersLayoutInfo.size(); - } - - lineLayoutInfo.mSize.height += lineHeightOffset; - lineLayoutInfo.mLineHeightOffset = lineHeightOffset; -} - void CreateLineInfo( const MarkupProcessor::StyledTextArray& line, TextView::RelayoutData& relayoutData, LineLayoutInfo& lineLayoutInfo ) @@ -113,12 +92,12 @@ void CreateLineInfo( const MarkupProcessor::StyledTextArray& line, convertedLine = line; // Create trivial bidirectional map tables. - std::size_t index = 0; + std::size_t index = 0u; for( MarkupProcessor::StyledTextArray::const_iterator it = convertedLine.begin(), endIt = convertedLine.end(); it != endIt; ++it ) { const MarkupProcessor::StyledText& styledText( *it ); - for( std::size_t i = 0, length = styledText.mText.GetLength(); i < length; ++i ) + for( std::size_t i = 0u, length = styledText.mText.GetLength(); i < length; ++i ) { relayoutData.mCharacterLogicalToVisualMap.push_back( relayoutData.mTextLayoutInfo.mNumberOfCharacters + index ); relayoutData.mCharacterVisualToLogicalMap.push_back( relayoutData.mTextLayoutInfo.mNumberOfCharacters + index ); @@ -193,7 +172,7 @@ void CreateLineInfo( const MarkupProcessor::StyledTextArray& line, // kepps the font of the last character. if( !wordLayoutInfo.mCharactersLayoutInfo.empty() ) { - lastCharacterFont = ( *( wordLayoutInfo.mCharactersLayoutInfo.end() - 1 ) ).mStyledText.mStyle.GetFontName(); + lastCharacterFont = ( *( wordLayoutInfo.mCharactersLayoutInfo.end() - 1u ) ).mStyledText.mStyle.GetFontName(); } } @@ -210,6 +189,27 @@ void CreateLineInfo( const MarkupProcessor::StyledTextArray& line, } // end of words } +void UpdateLayoutInfo( LineLayoutInfo& lineLayoutInfo, const float lineHeightOffset ) +{ + // Update layout info. + lineLayoutInfo.mSize = Size::ZERO; + lineLayoutInfo.mAscender = 0.f; + lineLayoutInfo.mNumberOfCharacters = 0u; + for( WordLayoutInfoContainer::iterator it = lineLayoutInfo.mWordsLayoutInfo.begin(), endIt = lineLayoutInfo.mWordsLayoutInfo.end(); + it != endIt; + ++it ) + { + WordLayoutInfo& word( *it ); + + UpdateSize( lineLayoutInfo.mSize, word.mSize ); + lineLayoutInfo.mAscender = std::max( lineLayoutInfo.mAscender, word.mAscender ); + lineLayoutInfo.mNumberOfCharacters += word.mCharactersLayoutInfo.size(); + } + + lineLayoutInfo.mSize.height += lineHeightOffset; + lineLayoutInfo.mLineHeightOffset = lineHeightOffset; +} + void RemoveWordsFromLine( std::size_t wordIndex, std::size_t numberOfWords, float lineHeightOffset, @@ -223,7 +223,7 @@ void RemoveWordsFromLine( std::size_t wordIndex, lineLayout.mWordsLayoutInfo.erase( lineLayout.mWordsLayoutInfo.begin() + wordIndex, lineLayout.mWordsLayoutInfo.begin() + ( wordIndex + numberOfWords ) ); - UpdateLineLayoutInfo( lineLayout, lineHeightOffset ); + UpdateLayoutInfo( lineLayout, lineHeightOffset ); } void RemoveCharactersFromLineInfo( TextView::RelayoutData& relayoutData, @@ -400,7 +400,7 @@ void SplitLine( const TextInfoIndices& indices, // * Remove words added to the last part of the line from the first line. // early returns!! - if( ( 0 == indices.mWordIndex ) && ( 0 == indices.mCharacterIndex ) ) + if( ( 0u == indices.mWordIndex ) && ( 0u == indices.mCharacterIndex ) ) { // the whole line goes to the last part. lastLineLayoutInfo = firstLineLayoutInfo; @@ -471,7 +471,7 @@ void SplitLine( const TextInfoIndices& indices, firstLineLayoutInfo.mWordsLayoutInfo.erase( firstLineLayoutInfo.mWordsLayoutInfo.begin() + index, firstLineLayoutInfo.mWordsLayoutInfo.end() ); // 6) update layout info of the first line. - UpdateLineLayoutInfo( firstLineLayoutInfo, lineHeightOffset ); + UpdateLayoutInfo( firstLineLayoutInfo, lineHeightOffset ); } void MergeLine( LineLayoutInfo& firstLineLineLayoutInfo, diff --git a/base/dali-toolkit/internal/controls/text-view/text-view-line-processor.h b/base/dali-toolkit/internal/controls/text-view/text-view-line-processor.h index 5738c46..e5ff791 100644 --- a/base/dali-toolkit/internal/controls/text-view/text-view-line-processor.h +++ b/base/dali-toolkit/internal/controls/text-view/text-view-line-processor.h @@ -34,14 +34,6 @@ namespace TextViewProcessor { /** - * Updates the line layout size info. - * - * @param[in,out] lineLayoutInfo The line layout info. - * @param[in] lineHeightOffset The line height offset. - */ -void UpdateLineLayoutInfo( LineLayoutInfo& lineLayoutInfo, float lineHeightOffset ); - -/** * Creates a data structure with info to layout the line, and data structures with useful info to modify the layout data structure if characters are added or removed. * * @param[in] line The styled line. @@ -53,6 +45,14 @@ void CreateLineInfo( const MarkupProcessor::StyledTextArray& line, LineLayoutInfo& lineLayoutInfo ); /** + * Updates the line layout size info. + * + * @param[in,out] lineLayoutInfo The line layout info. + * @param[in] lineHeightOffset The line height offset. + */ +void UpdateLayoutInfo( LineLayoutInfo& lineLayoutInfo, float lineHeightOffset ); + +/** * Removes a given number of words from the given line. * * @pre \e wordIndex and \e wordIndex + \e numberOfWords can't exceed the bounds of the line. diff --git a/base/dali-toolkit/internal/controls/text-view/text-view-processor-helper-functions.cpp b/base/dali-toolkit/internal/controls/text-view/text-view-processor-helper-functions.cpp index 08d8ce6..3942d19 100644 --- a/base/dali-toolkit/internal/controls/text-view/text-view-processor-helper-functions.cpp +++ b/base/dali-toolkit/internal/controls/text-view/text-view-processor-helper-functions.cpp @@ -113,7 +113,7 @@ void GetIndicesFromGlobalCharacterIndex( const std::size_t index, return; } - std::size_t currentIndex = 0; // stores how many characters have been traversed (within the whole text). + std::size_t currentIndex = 0u; // stores how many characters have been traversed (within the whole text). // Traverse all lines and words until global index is found. bool found = false; diff --git a/base/dali-toolkit/internal/controls/text-view/text-view-processor.cpp b/base/dali-toolkit/internal/controls/text-view/text-view-processor.cpp index 36f7465..7ffbe3b 100644 --- a/base/dali-toolkit/internal/controls/text-view/text-view-processor.cpp +++ b/base/dali-toolkit/internal/controls/text-view/text-view-processor.cpp @@ -45,12 +45,12 @@ namespace * * @param[in,out] textLayoutInfo */ -void UpdateTextLayoutInfo( TextLayoutInfo& textLayoutInfo ) +void UpdateLayoutInfo( TextLayoutInfo& textLayoutInfo ) { // Initialize members to be updated. - textLayoutInfo.mWholeTextSize = Size(); + textLayoutInfo.mWholeTextSize = Size::ZERO; textLayoutInfo.mMaxWordWidth = 0.f; - textLayoutInfo.mNumberOfCharacters = 0; + textLayoutInfo.mNumberOfCharacters = 0u; // Traverse all text updating values. for( LineLayoutInfoContainer::const_iterator lineIt = textLayoutInfo.mLinesLayoutInfo.begin(), lineEndIt = textLayoutInfo.mLinesLayoutInfo.end(); @@ -81,9 +81,9 @@ void UpdateTextLayoutInfo( TextLayoutInfo& textLayoutInfo ) // Constructors and assignment operators TextInfoIndices::TextInfoIndices() -: mLineIndex( 0 ), - mWordIndex( 0 ), - mCharacterIndex( 0 ) +: mLineIndex( 0u ), + mWordIndex( 0u ), + mCharacterIndex( 0u ) { } @@ -111,7 +111,7 @@ TextLayoutInfo::TextLayoutInfo() : mWholeTextSize(), mMaxWordWidth( 0.f ), mLinesLayoutInfo(), - mNumberOfCharacters( 0 ), + mNumberOfCharacters( 0u ), mMaxItalicsOffset( 0.f ), mEllipsizeLayoutInfo() { @@ -154,7 +154,7 @@ void CreateTextInfo( const MarkupProcessor::StyledTextArray& text, // Collect previously created text-actors. std::vector textActors; - CollectTextActorsFromLines( textActors, relayoutData.mTextLayoutInfo, 0, relayoutData.mTextLayoutInfo.mLinesLayoutInfo.size() ); + CollectTextActorsFromLines( textActors, relayoutData.mTextLayoutInfo, 0u, relayoutData.mTextLayoutInfo.mLinesLayoutInfo.size() ); if( !textActors.empty() ) { @@ -192,7 +192,7 @@ void CreateTextInfo( const MarkupProcessor::StyledTextArray& text, relayoutData, lineLayoutInfo ); - if( 0 < lineLayoutInfo.mNumberOfCharacters ) + if( 0u < lineLayoutInfo.mNumberOfCharacters ) { // do not add the line offset if the line has no characters. lineLayoutInfo.mSize.height += layoutParameters.mLineHeightOffset; @@ -206,7 +206,7 @@ void CreateTextInfo( const MarkupProcessor::StyledTextArray& text, // Get the last character of the last line. if( !relayoutData.mTextLayoutInfo.mLinesLayoutInfo.empty() ) { - const LineLayoutInfo& lineInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1 ) ); + const LineLayoutInfo& lineInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1u ) ); const CharacterLayoutInfo characterInfo = GetLastCharacterLayoutInfo( lineInfo ); @@ -248,7 +248,7 @@ void UpdateTextInfo( const std::size_t position, return; } - if( 0 == relayoutData.mTextLayoutInfo.mNumberOfCharacters ) + if( 0u == relayoutData.mTextLayoutInfo.mNumberOfCharacters ) { // Current text is empty. There is no need to update current data structure, // just create a new one with the new input text. @@ -275,8 +275,8 @@ void UpdateTextInfo( const std::size_t position, // Update logical-to-visual and visual-to-logical tables. // TODO: check that for mixed RTL/LTR text. - std::size_t index = 0; - for( std::size_t i = 0; i < relayoutDataForNewText.mTextLayoutInfo.mNumberOfCharacters; ++i ) + std::size_t index = 0u; + for( std::size_t i = 0u; i < relayoutDataForNewText.mTextLayoutInfo.mNumberOfCharacters; ++i ) { relayoutData.mCharacterLogicalToVisualMap.push_back( relayoutData.mTextLayoutInfo.mNumberOfCharacters + index ); relayoutData.mCharacterVisualToLogicalMap.push_back( relayoutData.mTextLayoutInfo.mNumberOfCharacters + index ); @@ -322,14 +322,14 @@ void UpdateTextInfo( const std::size_t position, // Calculates indices for that position. if( !relayoutData.mTextLayoutInfo.mLinesLayoutInfo.empty() ) { - textInfoIndices.mLineIndex = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.size() - 1; - const LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1 ) ); + textInfoIndices.mLineIndex = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.size() - 1u; + const LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1u ) ); if( !lineLayoutInfo.mWordsLayoutInfo.empty() ) { - textInfoIndices.mWordIndex = lineLayoutInfo.mWordsLayoutInfo.size() - 1; + textInfoIndices.mWordIndex = lineLayoutInfo.mWordsLayoutInfo.size() - 1u; - const WordLayoutInfo& wordLayoutInfo( *( lineLayoutInfo.mWordsLayoutInfo.end() - 1 ) ); + const WordLayoutInfo& wordLayoutInfo( *( lineLayoutInfo.mWordsLayoutInfo.end() - 1u ) ); textInfoIndices.mCharacterIndex = wordLayoutInfo.mCharactersLayoutInfo.size(); } } @@ -337,23 +337,23 @@ void UpdateTextInfo( const std::size_t position, // 2) If the new text has more than 1 line, merge the last line of the input text with the last part of the split line. //TODO check this cases ( num lines ==1, >1, >2 ) if it could be simplified. - if( relayoutDataForNewText.mTextLayoutInfo.mLinesLayoutInfo.size() > 1 ) + if( relayoutDataForNewText.mTextLayoutInfo.mLinesLayoutInfo.size() > 1u ) { - LineLayoutInfo& lastInputLineLayoutInfo( *( relayoutDataForNewText.mTextLayoutInfo.mLinesLayoutInfo.end() - 1 ) ); + LineLayoutInfo& lastInputLineLayoutInfo( *( relayoutDataForNewText.mTextLayoutInfo.mLinesLayoutInfo.end() - 1u ) ); MergeLine( lastInputLineLayoutInfo, lastLineLayoutInfo ); - if( relayoutDataForNewText.mTextLayoutInfo.mLinesLayoutInfo.size() > 2 ) + if( relayoutDataForNewText.mTextLayoutInfo.mLinesLayoutInfo.size() > 2u ) { // Insert all lines except first and last in the text. - relayoutData.mTextLayoutInfo.mLinesLayoutInfo.insert( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + textInfoIndices.mLineIndex + 1, - relayoutDataForNewText.mTextLayoutInfo.mLinesLayoutInfo.begin() + 1, - relayoutDataForNewText.mTextLayoutInfo.mLinesLayoutInfo.end() - 1 ); + relayoutData.mTextLayoutInfo.mLinesLayoutInfo.insert( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + textInfoIndices.mLineIndex + 1u, + relayoutDataForNewText.mTextLayoutInfo.mLinesLayoutInfo.begin() + 1u, + relayoutDataForNewText.mTextLayoutInfo.mLinesLayoutInfo.end() - 1u ); } // Insert the last line to the text - relayoutData.mTextLayoutInfo.mLinesLayoutInfo.insert( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + textInfoIndices.mLineIndex + relayoutDataForNewText.mTextLayoutInfo.mLinesLayoutInfo.size() - 1, + relayoutData.mTextLayoutInfo.mLinesLayoutInfo.insert( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + textInfoIndices.mLineIndex + relayoutDataForNewText.mTextLayoutInfo.mLinesLayoutInfo.size() - 1u, lastInputLineLayoutInfo ); } else @@ -375,7 +375,7 @@ void UpdateTextInfo( const std::size_t position, // 4) Update text info. // Updates the whole text size, maximum word size, etc. - UpdateTextLayoutInfo( relayoutData.mTextLayoutInfo ); + UpdateLayoutInfo( relayoutData.mTextLayoutInfo ); } void UpdateTextInfo( const std::size_t position, @@ -549,7 +549,7 @@ void UpdateTextInfo( const std::size_t position, const std::size_t removedNumberOfCharacters = ( wordNumberCharacters - wordLayout.mCharactersLayoutInfo.size() ); lineLayout.mNumberOfCharacters -= removedNumberOfCharacters; } - UpdateLineLayoutInfo( lineLayout, layoutParameters.mLineHeightOffset ); + UpdateLayoutInfo( lineLayout, layoutParameters.mLineHeightOffset ); // Insert the text-actors in order. removedTextActorsFromBegin.insert( removedTextActorsFromBegin.end(), removedTextActorsFromFirstWord.begin(), removedTextActorsFromFirstWord.end() ); @@ -611,7 +611,7 @@ void UpdateTextInfo( const std::size_t position, const std::size_t removedNumberOfCharacters = ( wordNumberCharacters - wordLayout.mCharactersLayoutInfo.size() ); lineLayout.mNumberOfCharacters -= removedNumberOfCharacters; } - UpdateLineLayoutInfo( lineLayout, layoutParameters.mLineHeightOffset ); + UpdateLayoutInfo( lineLayout, layoutParameters.mLineHeightOffset ); // Insert the text-actors in order. removedTextActorsFromEnd.insert( removedTextActorsFromEnd.end(), removedTextActorsFromFirstWord.begin(), removedTextActorsFromFirstWord.end() ); @@ -664,7 +664,7 @@ void UpdateTextInfo( const std::size_t position, lineLayout.mWordsLayoutInfo.erase( lineLayout.mWordsLayoutInfo.begin() + textInfoIndicesBegin.mWordIndex, lineLayout.mWordsLayoutInfo.begin() + textInfoIndicesEnd.mWordIndex ); // Update line info. - UpdateLineLayoutInfo( lineLayout, layoutParameters.mLineHeightOffset ); + UpdateLayoutInfo( lineLayout, layoutParameters.mLineHeightOffset ); }// end delete text from same line. if( mergeLines ) @@ -691,7 +691,7 @@ void UpdateTextInfo( const std::size_t position, relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + textInfoIndicesEnd.mLineIndex ); // Update text info. - UpdateTextLayoutInfo( relayoutData.mTextLayoutInfo ); + UpdateLayoutInfo( relayoutData.mTextLayoutInfo ); // If the last character of the last line is a new line character, an empty line need to be added. if( !relayoutData.mTextLayoutInfo.mLinesLayoutInfo.empty() ) @@ -808,171 +808,6 @@ void UpdateTextInfo( const TextStyle& style, } // end lines } -void InitializeTextActorInfo( TextView::RelayoutData& relayoutData ) -{ - TextLayoutInfo& textLayoutInfo = relayoutData.mTextLayoutInfo; - if( textLayoutInfo.mLinesLayoutInfo.empty() ) - { - // nothing to do if there is no lines. - return; - } - - std::size_t characterGlobalIndex = 0; // Index to the global character (within the whole text). - std::size_t lineLayoutInfoIndex = 0; // Index to the laid out line info. - const std::size_t lineLayoutInfoSize = relayoutData.mLines.size(); // Number or laid out lines. - bool lineLayoutEnd = false; // Whether lineLayoutInfoIndex points at the last laid out line. - bool glyphActorCreatedForLine = false; // Whether a renderable actor has been created for this line. - - RenderableActor currentGlyphActor; // text-actor used when the edit mode is disabled. - TextStyle currentStyle; // style for the current text-actor. - Vector4 currentGradientColor; // gradient color for the current text-actor. - Vector2 currentStartPoint; // start point for the current text-actor. - Vector2 currentEndPoint; // end point for the current text-actor. - bool currentIsColorGlyph = false; // Whether current glyph is an emoticon. - - std::vector textActorsToRemove; // Keep a vector of text-actors to be included into the cache. - - for( LineLayoutInfoContainer::iterator lineIt = textLayoutInfo.mLinesLayoutInfo.begin(), lineEndIt = textLayoutInfo.mLinesLayoutInfo.end(); - lineIt != lineEndIt; - ++lineIt ) - { - LineLayoutInfo& line( *lineIt ); - - for( WordLayoutInfoContainer::iterator wordIt = line.mWordsLayoutInfo.begin(), wordEndIt = line.mWordsLayoutInfo.end(); - wordIt != wordEndIt; - ++wordIt ) - { - WordLayoutInfo& word( *wordIt ); - - for( CharacterLayoutInfoContainer::iterator characterIt = word.mCharactersLayoutInfo.begin(), characterEndIt = word.mCharactersLayoutInfo.end(); - characterIt != characterEndIt; - ++characterIt ) - { - CharacterLayoutInfo& characterLayout( *characterIt ); - - // Check if there is a new line. - const bool newLine = !lineLayoutEnd && ( characterGlobalIndex == relayoutData.mLines[lineLayoutInfoIndex].mCharacterGlobalIndex ); - - if( newLine ) - { - // Point to the next line. - ++lineLayoutInfoIndex; - if( lineLayoutInfoIndex >= lineLayoutInfoSize ) - { - // Arrived at last line. - lineLayoutEnd = true; // Avoids access out of bounds in the relayoutData.mLines vector. - } - glyphActorCreatedForLine = false; - } - - if( !characterLayout.mStyledText.mText.IsEmpty() ) - { - // Do not create a glyph-actor if there is no text. - const Character character = characterLayout.mStyledText.mText[0]; // there are only one character per character layout. - - if( characterLayout.mIsColorGlyph || - !character.IsWhiteSpace() || // A new line character is also a white space. - ( character.IsWhiteSpace() && characterLayout.mStyledText.mStyle.IsUnderlineEnabled() ) ) - { - // Do not create a glyph-actor if it's a white space (without underline) or a new line character. - - // Creates one glyph-actor per each counsecutive group of characters, with the same style, per line, or if it's an emoticon. - - if( !glyphActorCreatedForLine || - characterLayout.mIsColorGlyph || - ( characterLayout.mStyledText.mStyle != currentStyle ) || - ( characterLayout.mGradientColor != currentGradientColor ) || - ( characterLayout.mStartPoint != currentStartPoint ) || - ( characterLayout.mEndPoint != currentEndPoint ) || - ( characterLayout.mIsColorGlyph != currentIsColorGlyph ) ) - { - characterLayout.mSetText = false; - characterLayout.mSetStyle = false; - - // There is a new style or a new line. - glyphActorCreatedForLine = true; - - if( characterLayout.mIsColorGlyph ) - { - ImageActor imageActor = ImageActor::DownCast( characterLayout.mGlyphActor ); - if( !imageActor ) - { - characterLayout.mGlyphActor = ImageActor::New(); - characterLayout.mSetText = true; - } - } - else - { - TextActor textActor = TextActor::DownCast( characterLayout.mGlyphActor ); - - if( textActor ) - { - // Try to reuse first the text-actor of this character. - textActor.SetTextStyle( characterLayout.mStyledText.mStyle ); - currentGlyphActor = textActor; - } - else - { - // If there is no text-actor, try to retrieve one from the cache. - textActor = relayoutData.mTextActorCache.RetrieveTextActor(); - - // If still there is no text-actor, create one. - if( !textActor ) - { - TextActorParameters parameters( characterLayout.mStyledText.mStyle, TextActorParameters::FONT_DETECTION_OFF ); - textActor = TextActor::New( NULL, parameters ); - } - else - { - textActor.SetTextStyle( characterLayout.mStyledText.mStyle ); - } - - currentGlyphActor = textActor; - } - characterLayout.mGlyphActor = currentGlyphActor; - } - - // Update style to be checked with next characters. - currentStyle = characterLayout.mStyledText.mStyle; - currentGradientColor = characterLayout.mGradientColor; - currentStartPoint = characterLayout.mStartPoint; - currentEndPoint = characterLayout.mEndPoint; - currentIsColorGlyph = characterLayout.mIsColorGlyph; - - characterLayout.mGlyphActor.SetParentOrigin( ParentOrigin::TOP_LEFT ); - characterLayout.mGlyphActor.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT ); - } - else - { - DALI_ASSERT_DEBUG( !characterLayout.mIsColorGlyph && "TextViewProcessor::InitializeTextActorInfo. An image-actor doesn't store more than one emoticon." ); - - // Same style than previous one. - TextActor textActor = TextActor::DownCast( characterLayout.mGlyphActor ); - if( textActor ) - { - // There is a previously created text-actor for this character. - // If this character has another one put it into the cache. - textActor.SetText( "" ); - textActorsToRemove.push_back( textActor ); - } - - if( characterLayout.mGlyphActor ) - { - characterLayout.mGlyphActor.Reset(); - } - } - } // no white space / new line char - } // text not empty - - ++characterGlobalIndex; - } // characters - } // words - } // lines - - // Insert the spare text-actors into the cache. - relayoutData.mTextActorCache.InsertTextActors( textActorsToRemove ); -} - } // namespace TextViewProcessor } // namespace Internal diff --git a/base/dali-toolkit/internal/controls/text-view/text-view-processor.h b/base/dali-toolkit/internal/controls/text-view/text-view-processor.h index c1c9d35..a38eaa7 100644 --- a/base/dali-toolkit/internal/controls/text-view/text-view-processor.h +++ b/base/dali-toolkit/internal/controls/text-view/text-view-processor.h @@ -115,13 +115,6 @@ void UpdateTextInfo( const TextStyle& style, TextStyle::Mask mask, TextView::RelayoutData& relayoutData ); -/** - * Traverse all text initializing all non initialized text-actor handles. - * - * @param[in,out] relayoutData Natural size (metrics), layout, text-actor info. - */ -void InitializeTextActorInfo( TextView::RelayoutData& relayoutData ); - } // namespace TextViewProcessor } // namespace Internal 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 a1ee39d..ffca8df 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 @@ -49,7 +49,7 @@ const std::string EMOJI_FONT_NAME( "SamsungEmoji" ); // Emoticons font family na void UpdateLayoutInfo( WordLayoutInfo& wordLayout ) { // Initialize layout info for the whole word. - wordLayout.mSize = Size(); + wordLayout.mSize = Size::ZERO; wordLayout.mAscender = 0.f; // Traverse the character layout info to update the word layout. @@ -110,7 +110,7 @@ void CreateWordTextInfo( const MarkupProcessor::StyledTextArray& word, const std::size_t length = styledText.mText.GetLength(); // It could be a group of characters. - for( std::size_t index = 0; index < length; ++index ) + for( std::size_t index = 0u; index < length; ++index ) { MarkupProcessor::StyledText styledCharacter; styledCharacter.mStyle = styledText.mStyle; @@ -194,18 +194,18 @@ void RemoveCharactersFromWordInfo( TextView::RelayoutData& relayoutData, if( LineSeparator == wordLayout.mType ) { // If the word is a line separator and there is more lines, then current line and the line after need to be merged. - if( textInfoIndicesBegin.mLineIndex + 1 < textLayoutInfo.mLinesLayoutInfo.size() ) + if( textInfoIndicesBegin.mLineIndex + 1u < textLayoutInfo.mLinesLayoutInfo.size() ) { // current line is not the last one. // Update indices to merge lines. textInfoMergeIndicesBegin.mLineIndex = textInfoIndicesBegin.mLineIndex; - textInfoMergeIndicesEnd.mLineIndex = textInfoIndicesBegin.mLineIndex + 1; + textInfoMergeIndicesEnd.mLineIndex = textInfoIndicesBegin.mLineIndex + 1u; mergeLines = true; - ++textInfoIndicesBegin.mLineIndex; // increase both indices, - textInfoIndicesEnd.mLineIndex +=2; // will delete last line. + ++textInfoIndicesBegin.mLineIndex; // increase both indices, + textInfoIndicesEnd.mLineIndex += 2u; // will delete last line. } ++textInfoIndicesEnd.mWordIndex; //will delete the line separator; @@ -214,10 +214,10 @@ void RemoveCharactersFromWordInfo( TextView::RelayoutData& relayoutData, { // If the word is a word separator. Check if the word before and the word after can be merged. - if( ( 0 < textInfoIndicesBegin.mWordIndex ) && ( lineLayout.mWordsLayoutInfo.size() > textInfoIndicesBegin.mWordIndex + 1 ) ) + if( ( 0u < textInfoIndicesBegin.mWordIndex ) && ( lineLayout.mWordsLayoutInfo.size() > textInfoIndicesBegin.mWordIndex + 1u ) ) { - const WordLayoutInfo& wordLayoutBefore( *( lineLayout.mWordsLayoutInfo.begin() + textInfoIndicesBegin.mWordIndex - 1 ) ); - const WordLayoutInfo& wordLayoutAfter( *( lineLayout.mWordsLayoutInfo.begin() + textInfoIndicesBegin.mWordIndex + 1 ) ); + const WordLayoutInfo& wordLayoutBefore( *( lineLayout.mWordsLayoutInfo.begin() + textInfoIndicesBegin.mWordIndex - 1u ) ); + const WordLayoutInfo& wordLayoutAfter( *( lineLayout.mWordsLayoutInfo.begin() + textInfoIndicesBegin.mWordIndex + 1u ) ); if( ( NoSeparator == wordLayoutBefore.mType ) && ( NoSeparator == wordLayoutAfter.mType ) ) { @@ -225,10 +225,10 @@ void RemoveCharactersFromWordInfo( TextView::RelayoutData& relayoutData, mergeWords = true; // Set indices to merge the words. - textInfoMergeIndicesBegin.mWordIndex = textInfoIndicesBegin.mWordIndex - 1; // word before word separator. - textInfoMergeIndicesEnd.mWordIndex = textInfoIndicesBegin.mWordIndex + 1; // word after word separator. + textInfoMergeIndicesBegin.mWordIndex = textInfoIndicesBegin.mWordIndex - 1u; // word before word separator. + textInfoMergeIndicesEnd.mWordIndex = textInfoIndicesBegin.mWordIndex + 1u; // word after word separator. - textInfoIndicesEnd.mWordIndex += 2; // will delete the word separator and the merged word. + textInfoIndicesEnd.mWordIndex += 2u; // will delete the word separator and the merged word. } else { @@ -264,7 +264,7 @@ void RemoveCharactersFromWord( const std::size_t position, // Removes a given number of characters from the given word starting from the 'position' index. // Early return. - if( 0 == numberOfCharacters ) + if( 0u == numberOfCharacters ) { // nothing to do if the number of characters is zero. @@ -286,7 +286,7 @@ void SplitWord( const std::size_t position, // It moves characters from the first part of the word to the last one. // early returns - if( 0 == position ) + if( 0u == position ) { // the whole word goes to the last part of the word. lastWordLayoutInfo = firstWordLayoutInfo; @@ -380,7 +380,7 @@ CharacterLayoutInfo GetLastCharacterLayoutInfo( const WordLayoutInfo& wordLayout if( !wordLayoutInfo.mCharactersLayoutInfo.empty() ) { - layoutInfo = *( wordLayoutInfo.mCharactersLayoutInfo.end() - 1 ); + layoutInfo = *( wordLayoutInfo.mCharactersLayoutInfo.end() - 1u ); } return layoutInfo; -- 2.7.4