2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
19 #include "relayout-utilities.h"
25 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
26 #include "text-view-line-processor.h"
27 #include "text-view-word-processor.h"
28 #include "text-view-processor-helper-functions.h"
29 #include "text-view-processor-dbg.h"
40 namespace TextViewRelayout
43 const float MINIMUM_FADE_BOUNDARY = 0.05f; // When the fade boundary is the same as the text-view boundary, this constant reduces it in order to avoid a zero division.
45 RelayoutParameters::RelayoutParameters()
51 mCharacterGlobalIndex( 0u ),
52 mIsFirstCharacter( false ),
53 mIsFirstCharacterOfWord( false ),
55 mIsNewLineCharacter( false ),
56 mIsWhiteSpace( false ),
61 RelayoutParameters::~RelayoutParameters()
65 FadeParameters::FadeParameters()
66 : mRightFadeBoundary( 0.f ),
67 mRightFadeThreshold( 0.f ),
68 mRightFadeBoundaryOffset( 0.f ),
69 mRightFadeThresholdOffset( 0.f ),
70 mRightAlphaCoeficients(),
71 mLeftFadeBoundary( 0.f ),
72 mLeftFadeThreshold( 0.f ),
73 mLeftFadeBoundaryOffset( 0.f ),
74 mLeftFadeThresholdOffset( 0.f ),
75 mLeftAlphaCoeficients(),
76 mTopFadeBoundary( 0.f ),
77 mTopFadeThreshold( 0.f ),
78 mTopFadeBoundaryOffset( 0.f ),
79 mTopFadeThresholdOffset( 0.f ),
80 mTopAlphaCoeficients(),
81 mBottomFadeBoundary( 0.f ),
82 mBottomFadeThreshold( 0.f ),
83 mBottomFadeBoundaryOffset( 0.f ),
84 mBottomFadeThresholdOffset( 0.f ),
85 mBottomAlphaCoeficients(),
86 mIsPartiallyVisible( false )
90 FadeParameters::~FadeParameters()
94 EllipsizeParameters::EllipsizeParameters()
96 mLineDescender( 0.f ),
101 mEllipsizeLine( false ),
102 mIsLineWidthFullyVisible( false ),
103 mIsLineHeightFullyVisible( false ),
104 mIsNextLineFullyVisibleHeight( false ),
105 mCreateEllipsizedTextActors( false ),
111 EllipsizeParameters::~EllipsizeParameters()
115 UnderlineInfo::UnderlineInfo()
117 mMaxThickness( 0.f ),
122 UnderlineInfo::~UnderlineInfo()
126 TextUnderlineStatus::TextUnderlineStatus()
128 mCharacterGlobalIndex( 0u ),
129 mLineGlobalIndex( 0u ),
130 mCurrentUnderlineStatus( false )
134 TextUnderlineStatus::~TextUnderlineStatus()
138 SubLineLayoutInfo::SubLineLayoutInfo()
139 : mLineLength( 0.f ),
140 mMaxCharHeight( 0.f ),
145 SubLineLayoutInfo::~SubLineLayoutInfo()
150 * Whether the given text-actor exceeds the left or the right boundary of the text-view.
152 * @param[in] position The position of the text-actor.
153 * @param[in] size The size of the text-actor.
154 * @param[in] parantSize The size of the text-view.
156 * @return \e true if the text-actor exceeds the left or the right boundary of the text-view.
158 bool IsExceedingWidth( const Vector3& position, const Size& size, const Size& parentSize )
160 return ( ( position.x < 0.f ) ||
161 ( position.x + size.width > parentSize.width ) );
165 * Whether the given text-actor exceeds the top or the bottom boundary of the text-view.
167 * @param[in] position The position of the text-actor.
168 * @param[in] size The size of the text-actor.
169 * @param[in] parantSize The size of the text-view.
171 * @return \e true if the text-actor exceeds the top or the bottom boundary of the text-view.
173 bool IsExceedingHeight( const Vector3& position, const Size& size, const Size& parentSize )
175 return ( ( position.y > parentSize.height ) ||
176 ( position.y < size.height ) );
180 * Calculates the line length adding the new word or character width.
182 * It also returns the length of white spaces if they are at the end of the line.
184 * @param[in] isWhiteSpace Whether the word is a white space.
185 * @param[in] width The width of the character or word.
186 * @param[in] parentWidth The parent width.
187 * @param[out] found Whether the sum of the new character or word is exceding the parent's width.
188 * @param[out] lineLength The length of the portion of line which doesn't exceed the parant's width
189 * @param[out] endWhiteSpaceLength The length of white spaces which are at the end of the line.
191 void CalculateLineLength( const bool isWhiteSpace, const float width, const float parentWidth, bool& found, float& lineLength, float& endWhiteSpaceLength )
193 if( lineLength + width > parentWidth )
196 lineLength -= endWhiteSpaceLength;
204 endWhiteSpaceLength += width;
208 endWhiteSpaceLength = 0.f;
213 struct CurrentTextActorInfo
220 Vector4 gradientColor;
225 void SetVisualParameters( CurrentTextActorInfo& currentTextActorInfo,
226 const TextView::VisualParameters& visualParameters,
227 TextView::RelayoutData& relayoutData,
228 const float lineHeight )
230 currentTextActorInfo.textActor.SetTextColor( currentTextActorInfo.color );
231 currentTextActorInfo.textActor.SetGradientColor( currentTextActorInfo.gradientColor );
232 currentTextActorInfo.textActor.SetGradientStartPoint( currentTextActorInfo.startPoint );
233 currentTextActorInfo.textActor.SetGradientEndPoint( currentTextActorInfo.endPoint );
235 // The italics offset is used in the offscreen rendering. When text is in italics, it may exceed the text-view's boundary
236 // due to the trick used to implement it.
237 const Radian& italicsAngle = currentTextActorInfo.textActor.GetItalicsAngle();
238 const float italicsOffset = lineHeight * std::tan( italicsAngle );
239 relayoutData.mTextLayoutInfo.mMaxItalicsOffset = std::max( relayoutData.mTextLayoutInfo.mMaxItalicsOffset, italicsOffset );
241 // Sets the sort modifier value.
242 currentTextActorInfo.textActor.SetSortModifier( visualParameters.mSortModifier );
244 // Enables or disables the blending.
245 currentTextActorInfo.textActor.SetBlendMode( !visualParameters.mSnapshotModeEnabled ? BlendingMode::ON : BlendingMode::OFF );
248 void CalculateSubLineLayout( const float parentWidth,
249 const TextViewProcessor::TextInfoIndices& indices,
250 const TextViewProcessor::LineLayoutInfo& lineLayoutInfo,
251 const HorizontalWrapType splitPolicy,
252 const float shrinkFactor,
253 SubLineLayoutInfo& subLineInfo )
255 subLineInfo.mLineLength = 0.f;
256 subLineInfo.mMaxCharHeight = 0.f;
257 subLineInfo.mMaxAscender = 0.f;
259 float endWhiteSpaceLength = 0.f;
261 std::size_t wordIndex = indices.mWordIndex;
262 std::size_t characterIndex = indices.mCharacterIndex;
263 float lineOffset = 0.f;
265 bool isFirstCharacter = true;
266 for( TextViewProcessor::WordGroupLayoutInfoContainer::const_iterator wordGroupIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin() + indices.mGroupIndex,
267 wordGroupEndIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
268 ( wordGroupIt != wordGroupEndIt ) && !found;
271 const TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *wordGroupIt );
273 for( TextViewProcessor::WordLayoutInfoContainer::const_iterator wordIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin() + wordIndex,
274 wordEndIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
275 ( wordIt != wordEndIt ) && !found;
278 const TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordIt );
280 const float shrunkWordWidth = wordLayoutInfo.mSize.width * shrinkFactor;
281 const bool isWhiteSpace = TextViewProcessor::WordSeparator == wordLayoutInfo.mType;
283 bool splitByCharacter = false;
285 switch( splitPolicy )
287 case WrapByCharacter:
289 splitByCharacter = true;
293 case WrapByLine: // Fall through
295 splitByCharacter = false;
298 case WrapByWordAndSplit:
300 splitByCharacter = ( shrunkWordWidth > parentWidth );
303 case WrapByLineAndSplit:
305 if( ( 0 != characterIndex ) ||
306 ( ( 0 == characterIndex ) && ( lineOffset + shrunkWordWidth > parentWidth ) ) )
308 splitByCharacter = true;
312 lineOffset += shrunkWordWidth;
313 splitByCharacter = false;
318 if( splitByCharacter )
320 for( TextViewProcessor::CharacterLayoutInfoContainer::const_iterator charIt = wordLayoutInfo.mCharactersLayoutInfo.begin() + characterIndex,
321 charEndIt = wordLayoutInfo.mCharactersLayoutInfo.end();
322 ( charIt != charEndIt ) && !found;
325 const TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *charIt );
326 CalculateLineLength( isWhiteSpace, characterLayoutInfo.mSize.width * shrinkFactor, parentWidth, found, subLineInfo.mLineLength, endWhiteSpaceLength );
327 if( !found || isFirstCharacter )
329 subLineInfo.mMaxCharHeight = std::max( subLineInfo.mMaxCharHeight, characterLayoutInfo.mSize.height );
330 subLineInfo.mMaxAscender = std::max( subLineInfo.mMaxAscender, characterLayoutInfo.mAscender );
333 // All characters for word 'wordIndex' have been processed.
334 // Next word need to process all characters, so the characterIndex is reset to 0.
336 isFirstCharacter = false;
339 lineOffset += subLineInfo.mLineLength;
343 CalculateLineLength( isWhiteSpace, shrunkWordWidth, parentWidth, found, subLineInfo.mLineLength, endWhiteSpaceLength );
344 if( !found || isFirstCharacter )
346 subLineInfo.mMaxCharHeight = std::max( subLineInfo.mMaxCharHeight, wordLayoutInfo.mSize.height );
347 subLineInfo.mMaxAscender = std::max( subLineInfo.mMaxAscender, wordLayoutInfo.mAscender );
349 isFirstCharacter = false;
353 // All words for group 'groupIndex' have been processed.
354 // Next group need to process all words, so the wordIndex is reset to 0.
358 subLineInfo.mMaxCharHeight *= shrinkFactor;
359 subLineInfo.mMaxAscender *= shrinkFactor;
362 float CalculateXoffset( const Toolkit::Alignment::Type horizontalTextAlignment, const float parentWidth, const float wholeTextWidth )
364 float xOffset( 0.f );
365 switch( horizontalTextAlignment )
367 case Toolkit::Alignment::HorizontalLeft:
372 case Toolkit::Alignment::HorizontalCenter:
374 xOffset = 0.5f * ( parentWidth - wholeTextWidth );
377 case Toolkit::Alignment::HorizontalRight:
379 xOffset = parentWidth - wholeTextWidth;
384 DALI_ASSERT_ALWAYS( !"TextViewRelayout::CalculateXoffset: Wrong horizontal text alignment. Did you set a vertical one?" );
391 float CalculateYoffset( const Toolkit::Alignment::Type verticalTextAlignment, const float parentHeight, const float wholeTextHeight )
393 float yOffset( 0.f );
394 switch( verticalTextAlignment )
396 case Toolkit::Alignment::VerticalTop:
401 case Toolkit::Alignment::VerticalCenter:
403 yOffset = 0.5f * ( parentHeight - wholeTextHeight );
406 case Toolkit::Alignment::VerticalBottom:
408 yOffset = parentHeight - wholeTextHeight;
413 DALI_ASSERT_ALWAYS( !"TextViewRelayout::CalculateXoffset: Wrong vertical text alignment. Did you set an horizontal one?" );
420 float CalculateJustificationOffset( const Toolkit::TextView::LineJustification justification, const float wholeTextWidth, const float lineLength )
423 switch( justification )
425 case Toolkit::TextView::Left:
430 case Toolkit::TextView::Center:
432 offset = 0.5f * ( wholeTextWidth - lineLength );
435 case Toolkit::TextView::Right:
437 offset = wholeTextWidth - lineLength;
440 case Toolkit::TextView::Justified:
450 bool IsVisible( const Vector3& position, const Size& size, const Size& parentSize, VisibilityTestType type )
452 bool visible = false;
458 // Whether the text-actor is fully inside the boundaries of the text-view.
459 visible = ( ( position.x >= 0.f ) && ( position.x + size.width <= parentSize.width ) &&
460 ( position.y >= size.height ) && ( position.y <= parentSize.height ) );
463 case FULLY_VISIBLE_WIDTH:
465 // Whether the text-actor is between the left and right boundaries of the text-view.
466 visible = ( ( position.x >= 0.f ) && ( position.x + size.width <= parentSize.width ) );
469 case FULLY_VISIBLE_HEIGHT:
471 // Whether the text-actor is between the top and bottom boundaries of the text-view.
472 visible = ( ( position.y >= size.height ) && ( position.y <= parentSize.height ) );
475 case PARTIALLY_VISIBLE:
477 // Whether the text-actor is partially inside the boundaries of the text-view.
478 visible = ( ( position.x < parentSize.width ) &&
479 ( position.x + size.width > 0.f ) &&
480 ( position.y > 0.f ) &&
481 ( position.y - size.height < parentSize.height ) );
484 case PARTIALLY_VISIBLE_WIDTH:
486 // Whether the text-actor is partially inside the area defined by the left and the right boundaries of the text-view.
487 // It may not be partially inside the text-view.
488 visible = ( ( position.x < parentSize.width ) &&
489 ( position.x + size.width > 0.f ) );
492 case PARTIALLY_VISIBLE_HEIGHT:
494 // Whether the text-actor is partially inside the area defined by the top and the bottom boundaries of the text-view.
495 // It may not be partially inside the text-view.
496 visible = ( ( position.y > 0.f ) &&
497 ( position.y - size.height < parentSize.height ) );
505 Vector2 CalculateRectParameters( const Vector2& p0, const Vector2& p1 )
507 const float gradient = ( p1.y - p0.y ) / ( p1.x - p0.x );
509 return Vector2( gradient, p0.y - gradient * p0.x );
512 void UpdateAlignment( const TextView::LayoutParameters& layoutParameters,
513 TextView::RelayoutData& relayoutData )
515 // Calculates an offset to align the whole text within the text-view's boundary accordingly with the set alignment and justification options.
516 // The offset could be negative if the whole text is bigger than the boundary of the text-view.
518 // If the exceed policy is ellipsize at the end, negative offsets are not wanted.
519 // In that case, it will align the line to the left and/or top, and ellipsize the end.
520 const bool ellipsizeAlignToLeft = ( layoutParameters.mExceedPolicy == TextView::EllipsizeEndOriginal ) || ( layoutParameters.mExceedPolicy == TextView::EllipsizeEnd );
521 const bool ellipsizeAlignToTop = ( layoutParameters.mExceedPolicy == TextView::EllipsizeEnd );
523 RelayoutParameters relayoutParameters;
525 // Calculates the vertical and horizontal offsets.
526 const float textHorizontalOffset = CalculateXoffset( layoutParameters.mHorizontalAlignment, relayoutData.mTextViewSize.width, relayoutData.mTextSizeForRelayoutOption.width );
527 const float textVerticalOffset = CalculateYoffset( layoutParameters.mVerticalAlignment, relayoutData.mTextViewSize.height, relayoutData.mTextSizeForRelayoutOption.height );
529 std::size_t lineJustificationIndex = 0; // Index to the first position of the vector which stores all line justification info.
530 std::size_t infoTableCharacterIndex = 0;
532 relayoutParameters.mIndices.mLineIndex = 0;
534 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
535 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
536 lineLayoutIt != endLineLayoutIt;
537 ++lineLayoutIt, ++relayoutParameters.mIndices.mLineIndex )
539 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
541 relayoutParameters.mIndices.mGroupIndex = 0;
542 float justificationOffset = 0.f;
544 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(),
545 endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
546 groupLayoutIt != endGroupLayoutIt;
547 ++groupLayoutIt, ++relayoutParameters.mIndices.mGroupIndex )
549 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
551 relayoutParameters.mIndices.mWordIndex = 0;
553 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(),
554 endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
555 wordLayoutIt != endWordLayoutIt;
556 ++wordLayoutIt, ++relayoutParameters.mIndices.mWordIndex )
558 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
560 relayoutParameters.mIndices.mCharacterIndex = 0;
562 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
563 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
564 characterLayoutIt != endCharacterLayoutIt;
565 ++characterLayoutIt, ++relayoutParameters.mIndices.mCharacterIndex, ++infoTableCharacterIndex )
567 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
569 // Calculate line justification offset.
570 if( lineJustificationIndex < relayoutData.mLineJustificationInfo.size() )
572 const TextView::LineJustificationInfo lineJustificationInfo( *( relayoutData.mLineJustificationInfo.begin() + lineJustificationIndex ) );
574 if( relayoutParameters.mIndices == lineJustificationInfo.mIndices )
576 justificationOffset = CalculateJustificationOffset( layoutParameters.mLineJustification, relayoutData.mTextSizeForRelayoutOption.width, lineJustificationInfo.mLineLength );
577 ++lineJustificationIndex; // increase the index to point the next position in the vector.
581 // Deletes the offsets if the exceed policies are EllipsizeEnd.
582 const float horizontalOffset = textHorizontalOffset + justificationOffset;
583 characterLayoutInfo.mOffset.x = ( ellipsizeAlignToLeft && ( horizontalOffset < 0.f ) ) ? 0.f : horizontalOffset;
584 characterLayoutInfo.mOffset.y = ( ellipsizeAlignToTop && ( textVerticalOffset < 0.f ) ) ? 0.f : textVerticalOffset;
586 // Updates the size and position table for text-input with the alignment offset.
587 Vector3 positionOffset( characterLayoutInfo.mPosition );
589 std::vector<Toolkit::TextView::CharacterLayoutInfo>::iterator infoTableIt = relayoutData.mCharacterLayoutInfoTable.begin() + infoTableCharacterIndex;
590 Toolkit::TextView::CharacterLayoutInfo& characterTableInfo( *infoTableIt );
592 characterTableInfo.mPosition.x = positionOffset.x + characterLayoutInfo.mOffset.x;
593 characterTableInfo.mPosition.y = positionOffset.y + characterLayoutInfo.mOffset.y;
595 positionOffset.x += characterLayoutInfo.mAdvance * relayoutData.mShrinkFactor;
598 } // end group of words
602 void CalculateBearing( TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo,
603 TextView::RelayoutData& relayoutData )
615 // ggggg gggggggggg bb ggggg
616 // gg gg gggggggggg bb gg gg
617 // gg gg gggg bb gg gg
618 // gg gg gggg bb gg gg
619 // ggggg gg gggg bbbbbbb ggggg
620 // gg gg gggg bb bb gg
621 // g gg gggggggggg bb bb g gg
622 // ggggg gggggggggg bbbbbbb ggggg
631 // ggggg gggg gggg bb ggggg
632 // gg gg gggg gggg bbbbbbb gg gg
633 // gg gg gggg gggg bb bb gg gg
634 // gg gg gggggggggg bb bb gg gg
635 // ggggg gggggggggg bbbbbbb ggggg
638 // ggggg gg gggg ggggg
643 const Toolkit::TextView::LineLayoutInfo& lineInfo( *( relayoutData.mLines.end() - 1 ) );
644 const float bearingOffset = ( lineInfo.mSize.height - lineInfo.mAscender ) - ( characterLayoutInfo.mSize.height - characterLayoutInfo.mAscender );
646 characterLayoutInfo.mPosition.y -= bearingOffset * relayoutData.mShrinkFactor;
649 void UpdateLayoutInfoTable( Vector4& minMaxXY,
650 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo,
651 TextViewProcessor::WordLayoutInfo& wordLayoutInfo,
652 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo,
653 RelayoutParameters& relayoutParameters,
654 TextView::RelayoutData& relayoutData )
656 // updates min and max position to calculate the text size for multiline policies.
657 minMaxXY.x = std::min( minMaxXY.x, characterLayoutInfo.mPosition.x );
658 minMaxXY.z = std::max( minMaxXY.z, characterLayoutInfo.mPosition.x + characterLayoutInfo.mSize.width * relayoutData.mShrinkFactor );
660 minMaxXY.y = std::min( minMaxXY.y, characterLayoutInfo.mPosition.y - characterLayoutInfo.mSize.height * relayoutData.mShrinkFactor );
661 minMaxXY.w = std::max( minMaxXY.w, characterLayoutInfo.mPosition.y );
663 // Adds layout info to be retrieved by external controls or applications.
664 Vector3 positionOffset( characterLayoutInfo.mPosition );
666 const float descender = characterLayoutInfo.mSize.height - characterLayoutInfo.mAscender;
668 const Toolkit::TextView::CharacterLayoutInfo characterLayoutTableInfo( Size( characterLayoutInfo.mAdvance * relayoutData.mShrinkFactor,
669 characterLayoutInfo.mHeight * relayoutData.mShrinkFactor ),
671 ( TextViewProcessor::LineSeparator == wordLayoutInfo.mType ),
672 ( TextViewProcessor::RTL == wordGroupLayoutInfo.mDirection ),
676 relayoutData.mCharacterLayoutInfoTable.push_back( characterLayoutTableInfo );
678 positionOffset.x += characterLayoutInfo.mAdvance * relayoutData.mShrinkFactor;
681 void CalculateVisibilityForFade( const Internal::TextView::LayoutParameters& layoutParameters,
682 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo,
683 RelayoutParameters& relayoutParameters,
684 FadeParameters& fadeParameters,
685 TextView::RelayoutData& relayoutData )
687 if( ( TextView::Fade != layoutParameters.mExceedPolicy ) &&
688 ( TextView::SplitFade != layoutParameters.mExceedPolicy ) &&
689 ( TextView::FadeOriginal != layoutParameters.mExceedPolicy ) &&
690 ( TextView::OriginalFade != layoutParameters.mExceedPolicy ) )
696 // Calculates visibility of a text-actor according the exceed policies.
698 // position + alignment offset.
699 const Vector3 position( characterLayoutInfo.mPosition.x + characterLayoutInfo.mOffset.x,
700 characterLayoutInfo.mPosition.y + characterLayoutInfo.mOffset.y,
701 characterLayoutInfo.mPosition.z );
703 // Whether the text actor is fully, partially or non visible (according exceed policies).
704 switch( layoutParameters.mExceedPolicy )
708 // All text-actors which are not completely inside the text-view's boundaries are set as non visible.
709 // All text-actors which are partially inside the text-view's boundaries are set as partially visible.
710 if( !IsVisible( position,
711 characterLayoutInfo.mSize,
712 relayoutData.mTextViewSize,
715 relayoutParameters.mIsVisible = false;
716 if( IsVisible( position,
717 characterLayoutInfo.mSize,
718 relayoutData.mTextViewSize,
719 PARTIALLY_VISIBLE ) )
721 fadeParameters.mIsPartiallyVisible = true;
723 // Checks if a text-actor is exceeding more than one boundary as this case is not supported.
724 if( IsExceedingWidth( position,
725 characterLayoutInfo.mSize,
726 relayoutData.mTextViewSize ) &&
727 IsExceedingHeight( position,
728 characterLayoutInfo.mSize,
729 relayoutData.mTextViewSize ) )
731 // Combination not fully supported by text-view.
732 // Need to check if text-actor really supports this combination.
733 fadeParameters.mIsPartiallyVisible = false;
739 case TextView::FadeOriginal:
741 // All text-actors which are not completely between the left and right text-view's boundaries are set as non visible.
742 // All text-actors which are partially inside the text-view's boundaries are set as partially visible.
743 if( !IsVisible( position,
744 characterLayoutInfo.mSize,
745 relayoutData.mTextViewSize,
746 FULLY_VISIBLE_WIDTH ) )
748 relayoutParameters.mIsVisible = false;
749 if( IsVisible( position,
750 characterLayoutInfo.mSize,
751 relayoutData.mTextViewSize,
752 PARTIALLY_VISIBLE_WIDTH ) )
754 fadeParameters.mIsPartiallyVisible = true;
759 case TextView::OriginalFade:
760 case TextView::SplitFade: // Fallthrough
762 // All text-actors which are not completely between the top and bottom text-view's boundaries are set as non visible.
763 // All text-actors which are partially inside the text-view's boundaries are set as partially visible.
764 if( !IsVisible( position,
765 characterLayoutInfo.mSize,
766 relayoutData.mTextViewSize,
767 FULLY_VISIBLE_HEIGHT ) )
769 relayoutParameters.mIsVisible = false;
770 if( IsVisible( position,
771 characterLayoutInfo.mSize,
772 relayoutData.mTextViewSize,
773 PARTIALLY_VISIBLE_HEIGHT ) )
775 fadeParameters.mIsPartiallyVisible = true;
782 DALI_ASSERT_ALWAYS( !"TextViewRelayout::CalculateVisibilityForFade. Wrong exceed policies." )
787 if( relayoutParameters.mIsVisible || fadeParameters.mIsPartiallyVisible )
789 characterLayoutInfo.mIsVisible = true;
791 const Size size = characterLayoutInfo.mSize * relayoutData.mShrinkFactor;
792 const float characterPositionPlusWidth = position.x + size.width;
793 const float characterPositionMinusHeight = position.y - size.height;
795 // Calculates which edges need to be faded-out.
796 bool rightFadeOut = false;
797 bool leftFadeOut = false;
798 bool bottomFadeOut = false;
799 bool topFadeOut = false;
801 switch( layoutParameters.mExceedPolicy )
805 // All text-actors exceeding any of the boundaries will be faded-out.
806 rightFadeOut = ( characterPositionPlusWidth > fadeParameters.mRightFadeThreshold );
807 leftFadeOut = ( position.x < fadeParameters.mLeftFadeThreshold );
808 bottomFadeOut = ( position.y > fadeParameters.mBottomFadeThreshold );
809 topFadeOut = ( characterPositionMinusHeight < fadeParameters.mTopFadeThreshold );
812 case TextView::FadeOriginal:
814 // Only text-actors exceeding the left or the right boundaries will be faded-out.
815 rightFadeOut = ( characterPositionPlusWidth > fadeParameters.mRightFadeThreshold );
816 leftFadeOut = ( position.x < fadeParameters.mLeftFadeThreshold );
819 case TextView::SplitFade:
820 case TextView::OriginalFade: //Fallthrough
822 // Only text-actors exceeding the top or the bottom boundaries will be faded-out.
823 bottomFadeOut = ( position.y > fadeParameters.mBottomFadeThreshold );
824 topFadeOut = ( characterPositionMinusHeight < fadeParameters.mTopFadeThreshold );
829 DALI_ASSERT_ALWAYS( !"TextViewRelayout::CalculateVisibilityForFade. Wrong exceed policies." );
834 // Calculates gradient parameters for a text-actor.
835 Vector4 gradientColor = Vector4::ZERO;
836 Vector2 startPoint = Vector2::ZERO;
837 Vector2 endPoint = Vector2::ZERO;
839 if( !( rightFadeOut && leftFadeOut ) )
841 // Current implementation can't set gradient parameters for a text-actor exceeding at the same time the left and the right boundaries.
844 gradientColor = characterLayoutInfo.mStyledText.mStyle.GetTextColor();
846 // Calculates gradient coeficients.
847 characterLayoutInfo.mColorAlpha = gradientColor.a * std::min( 1.f, fadeParameters.mRightAlphaCoeficients.x * position.x + fadeParameters.mRightAlphaCoeficients.y );
848 gradientColor.a *= std::max( 0.f, fadeParameters.mRightAlphaCoeficients.x * characterPositionPlusWidth + fadeParameters.mRightAlphaCoeficients.y );
850 startPoint = Vector2( std::max( 0.f, ( fadeParameters.mRightFadeThresholdOffset - position.x ) / size.width ), 0.5f );
851 endPoint = Vector2( std::min( 1.f, ( relayoutData.mTextViewSize.width - position.x ) / size.width ), 0.5f );
853 else if( leftFadeOut )
855 gradientColor = characterLayoutInfo.mStyledText.mStyle.GetTextColor();
857 // Calculates gradient coeficients.
858 characterLayoutInfo.mColorAlpha = std::min( 1.f, fadeParameters.mLeftAlphaCoeficients.x * characterPositionPlusWidth + fadeParameters.mLeftAlphaCoeficients.y );
859 gradientColor.a *= gradientColor.a * std::max( 0.f, fadeParameters.mLeftAlphaCoeficients.x * position.x + fadeParameters.mLeftAlphaCoeficients.y );
861 startPoint = Vector2( std::max( 0.f, ( fadeParameters.mLeftFadeThresholdOffset - position.x ) / size.width ), 0.5f );
862 endPoint = Vector2( std::min( 1.f, -position.x / size.width ), 0.5f );
866 if( !( bottomFadeOut && topFadeOut ) )
868 // Current implementation can't set gradient parameters for a text-actor exceeding at the same time the top and the bottom boundaries.
871 gradientColor = characterLayoutInfo.mStyledText.mStyle.GetTextColor();
873 // Calculates gradient coeficients.
874 characterLayoutInfo.mColorAlpha = gradientColor.a * std::min( 1.f, fadeParameters.mBottomAlphaCoeficients.x * characterPositionMinusHeight + fadeParameters.mBottomAlphaCoeficients.y );
875 gradientColor.a *= std::max( 0.f, fadeParameters.mBottomAlphaCoeficients.x * position.y + fadeParameters.mBottomAlphaCoeficients.y );
877 startPoint = Vector2( 0.5f, std::max( 0.f, ( fadeParameters.mBottomFadeThresholdOffset - characterPositionMinusHeight ) / size.height ) );
878 endPoint = Vector2( 0.5f, std::min( 1.f, ( relayoutData.mTextViewSize.height - characterPositionMinusHeight ) / size.height ) );
880 else if( topFadeOut )
882 gradientColor = characterLayoutInfo.mStyledText.mStyle.GetTextColor();
884 // Calculates gradient coeficients.
885 characterLayoutInfo.mColorAlpha *= gradientColor.a * std::min( 1.f, fadeParameters.mTopAlphaCoeficients.x * position.y + fadeParameters.mTopAlphaCoeficients.y );
886 gradientColor.a *= std::max( 0.f, fadeParameters.mTopAlphaCoeficients.x * characterPositionMinusHeight + fadeParameters.mTopAlphaCoeficients.y );
888 startPoint = Vector2( 0.5f, std::max( 0.f, ( fadeParameters.mTopFadeThresholdOffset - characterPositionMinusHeight ) / size.height ) );
889 endPoint = Vector2( 0.5f, std::min( 1.f, -characterPositionMinusHeight / size.height ) );
893 characterLayoutInfo.mGradientColor = gradientColor;
894 characterLayoutInfo.mStartPoint = startPoint;
895 characterLayoutInfo.mEndPoint = endPoint;
899 characterLayoutInfo.mIsVisible = false;
903 bool CalculateVisibilityForEllipsizeEndOriginal( TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo,
904 const EllipsizeParameters& ellipsizeParameters )
906 bool isPartiallyVisible = false;
908 if( !IsVisible( ellipsizeParameters.mPosition,
909 characterLayoutInfo.mSize,
910 ellipsizeParameters.mEllipsizeBoundary,
911 FULLY_VISIBLE_WIDTH ) )
913 // The character doesn't fit in the text-view's width.
914 characterLayoutInfo.mIsVisible = false;
916 // Checks if the character is partially visible (it's cut by the boundary)
917 isPartiallyVisible = IsVisible( ellipsizeParameters.mPosition,
918 characterLayoutInfo.mSize,
919 ellipsizeParameters.mEllipsizeBoundary,
920 PARTIALLY_VISIBLE_WIDTH );
924 // The character fits in the text-view's width. Set it to visible.
925 characterLayoutInfo.mIsVisible = true;
928 return isPartiallyVisible;
931 bool CalculateVisibilityForEllipsizeEnd( TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo,
932 const EllipsizeParameters& ellipsizeParameters )
934 bool isPartiallyVisible = false;
936 if( !IsVisible( ellipsizeParameters.mPosition,
937 characterLayoutInfo.mSize,
938 ellipsizeParameters.mEllipsizeBoundary,
941 // The character is not fully visible. Needs to check if it's partially visible.
942 characterLayoutInfo.mIsVisible = false;
944 // Checks if the character doesn't cut the bottom edge of the text-view.
945 const bool fullyVisibleHeight = IsVisible( ellipsizeParameters.mPosition,
946 characterLayoutInfo.mSize,
947 ellipsizeParameters.mEllipsizeBoundary,
948 FULLY_VISIBLE_HEIGHT );
950 // Checks if the character cuts the right edge of the text-view.
951 const bool partiallyVisibleWidth = IsVisible( ellipsizeParameters.mPosition,
952 characterLayoutInfo.mSize,
953 ellipsizeParameters.mEllipsizeBoundary,
954 PARTIALLY_VISIBLE_WIDTH );
956 // Character will be ellipsized if it cuts the right edge of the text-view but fits completely in the text-view's height.
957 isPartiallyVisible = ( fullyVisibleHeight && partiallyVisibleWidth );
961 // The character fits in the boundary of the text-view. Set it to visible.
962 characterLayoutInfo.mIsVisible = true;
965 return isPartiallyVisible;
968 void CalculateVisibilityForEllipsize( const Internal::TextView::LayoutParameters& layoutParameters,
969 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo,
970 EllipsizeParameters& ellipsizeParameters,
971 TextView::RelayoutData& relayoutData )
973 // Calculates visibility for EllipsizeEnd exceed policies.
975 // It defines a boundary on the right side of the text-view by substracting the ellipsize-text's size (...) to the text-view's size.
976 // If a character is cut by this boundary and the whole line (if the multi-line policy is split-by-new-line-char)
977 // or the whole word (if the multi-line policy is split-by-word) doesn't fit in the text-view's width, then it's replaced by the ellipsize-text.
979 // Position of the character used to do the visibility test.
980 ellipsizeParameters.mPosition = Vector3( characterLayoutInfo.mPosition.x + characterLayoutInfo.mOffset.x,
981 characterLayoutInfo.mPosition.y + characterLayoutInfo.mOffset.y,
982 characterLayoutInfo.mPosition.z );
984 // Text will be ellipsized if a character is partially visible (it's cut by the boundary defined in the right side of the text-view).
985 bool isPartiallyVisible = false;
987 // Checks if the whole line or the whole word fits in the text-view's width accordingly with the multiline policy.
988 const bool fitsInWidth = ( Toolkit::TextView::SplitByNewLineChar == layoutParameters.mMultilinePolicy ) ? ellipsizeParameters.mLineFits: ellipsizeParameters.mWordFits;
990 // Will only ellipsize the text if it cuts the right vertical edge and it doesn't fit in the text-view's width.
993 // The line or word fits completely inside the text-view's width. Nothing else to do.
994 characterLayoutInfo.mIsVisible = true;
998 // The line or word doesn't fit in the text-view's width.
1000 // Calculates visibility for each type of ellipsize policies.
1001 switch( layoutParameters.mExceedPolicy )
1003 case TextView::EllipsizeEndOriginal:
1005 // Ellipsizes the text if it doesn't fit in the width but it doesn't ellipsize if the text doesn't fit in the height.
1007 isPartiallyVisible = CalculateVisibilityForEllipsizeEndOriginal( characterLayoutInfo,
1008 ellipsizeParameters );
1012 case TextView::EllipsizeEnd:
1014 // Ellipsizes the text if it doesn't fit in the width and fully fits in the text-view's height.
1016 isPartiallyVisible = CalculateVisibilityForEllipsizeEnd( characterLayoutInfo,
1017 ellipsizeParameters );
1023 DALI_ASSERT_DEBUG( !"TextViewRelayout::CalculateVisibilityForEllipsize. Wrong exceed value." );
1029 // If the current character is not fully visible but is partially visible, it is cut by the boundary of the text-view.
1030 // In that case, the charater needs to be replaced by the ellipsize text.
1031 ellipsizeParameters.mCreateEllipsizedTextActors = ( !characterLayoutInfo.mIsVisible && isPartiallyVisible );
1034 void CreateEllipsizeTextActor( const EllipsizeParameters& ellipsizeParameters,
1035 TextView::RelayoutData& relayoutData )
1037 // The default ellipsize text is '...' and all dots have the same style. However, a differernt ellipsize text could be set and it can have characters with differernt styles.
1038 // The code bellow creates the text-actors needed for the ellipsize text.
1040 // Set ellipsize's position by the end of visible text.
1041 Vector3 ellipsizePosition = ellipsizeParameters.mPosition;
1042 // Stores current ellipsize text.
1044 // Stores current ellipsize style.
1045 TextStyle ellipsizeStyle;
1046 // Stores the current size.
1049 float bearingOffset = 0.f;
1051 // Create ellipsize text-actor.
1052 for( TextViewProcessor::CharacterLayoutInfoContainer::const_iterator ellipsizeCharacterLayoutIt = relayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo.mCharactersLayoutInfo.begin(),
1053 endEllipsizeCharacterLayoutIt = relayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo.mCharactersLayoutInfo.end();
1054 ellipsizeCharacterLayoutIt != endEllipsizeCharacterLayoutIt;
1055 ++ellipsizeCharacterLayoutIt )
1057 const TextViewProcessor::CharacterLayoutInfo& ellipsizeCharacterLayoutInfo( *ellipsizeCharacterLayoutIt );
1059 if( ellipsizeStyle != ellipsizeCharacterLayoutInfo.mStyledText.mStyle )
1061 // The style is different, so a new text-actor is needed.
1062 if( !ellipsizeText.IsEmpty() )
1064 // It only creates a text-actor if there is any text.
1065 TextActor ellipsizeTextActor = CreateTextActor( ellipsizeText, ellipsizeStyle, relayoutData.mTextActorCache );
1066 ellipsizeTextActor.SetSize( ellipsizeSize );
1067 ellipsizeTextActor.SetPosition( Vector3( ellipsizePosition.x, ellipsizePosition.y - bearingOffset, ellipsizePosition.z ) );
1069 // Updates the position for the next text-actor.
1070 ellipsizePosition.x += ellipsizeSize.width;
1072 // Adds the text-actor to the list.
1073 relayoutData.mEllipsizedTextActors.push_back( ellipsizeTextActor );
1076 // Resets the current ellipsize info.
1077 ellipsizeText = ellipsizeCharacterLayoutInfo.mStyledText.mText;
1078 ellipsizeStyle = ellipsizeCharacterLayoutInfo.mStyledText.mStyle;
1079 ellipsizeSize = ellipsizeCharacterLayoutInfo.mSize;
1081 bearingOffset = ( ellipsizeParameters.mLineDescender - ( ellipsizeCharacterLayoutInfo.mSize.height - ellipsizeCharacterLayoutInfo.mAscender ) ) * relayoutData.mShrinkFactor;
1085 // Updates text and size with the new character.
1086 ellipsizeText.Append( ellipsizeCharacterLayoutInfo.mStyledText.mText );
1087 TextViewProcessor::UpdateSize( ellipsizeSize, ellipsizeCharacterLayoutInfo.mSize );
1092 if( !ellipsizeText.IsEmpty() )
1094 // Creates the last text-actor.
1095 TextActor ellipsizeTextActor = CreateTextActor( ellipsizeText, ellipsizeStyle, relayoutData.mTextActorCache );
1096 ellipsizeTextActor.SetSize( ellipsizeSize );
1097 ellipsizeTextActor.SetPosition( Vector3( ellipsizePosition.x, ellipsizePosition.y - bearingOffset, ellipsizePosition.z ) );
1099 // Adds the text-actor to the list.
1100 relayoutData.mEllipsizedTextActors.push_back( ellipsizeTextActor );
1104 void EllipsizeLine( const TextView::LayoutParameters& layoutParameters,
1105 EllipsizeParameters& ellipsizeParameters,
1106 TextView::RelayoutData& relayoutData )
1108 // Traverses the text layout info from the first character of the laid out line
1109 // to the last one setting to each character its visibility. If needed, it adds the ellipsize text (...).
1111 // Indices to the first character of the laid out line.
1112 TextViewProcessor::TextInfoIndices firstIndices;
1113 TextViewProcessor::GetIndicesFromGlobalCharacterIndex( ellipsizeParameters.mFirstIndex,
1114 relayoutData.mTextLayoutInfo,
1117 // Indices to the last character of the laid out line.
1118 TextViewProcessor::TextInfoIndices lastIndices;
1119 TextViewProcessor::GetIndicesFromGlobalCharacterIndex( ellipsizeParameters.mLastIndex,
1120 relayoutData.mTextLayoutInfo,
1123 // Defines a boundary by substracting the ellipsize-text's width to the text-view's width.
1124 // This is the boundary used to check if a character have to be ellipsized.
1125 ellipsizeParameters.mEllipsizeBoundary = relayoutData.mTextViewSize;
1126 ellipsizeParameters.mEllipsizeBoundary.width -= relayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo.mSize.width;
1128 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + firstIndices.mLineIndex,
1129 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + lastIndices.mLineIndex + 1;
1130 lineLayoutIt != endLineLayoutIt;
1133 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
1135 ellipsizeParameters.mLineFits = ellipsizeParameters.mIsLineWidthFullyVisible && ellipsizeParameters.mIsLineHeightFullyVisible && ellipsizeParameters.mIsNextLineFullyVisibleHeight;
1137 if( !ellipsizeParameters.mIsNextLineFullyVisibleHeight )
1139 ellipsizeParameters.mEllipsizeBoundary.width = ellipsizeParameters.mLineWidth;
1142 bool firstGroup = true;
1143 bool lastGroup = false;
1144 std::size_t groupCount = 0;
1146 bool firstWord = true;
1147 bool lastWord = false;
1149 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin() + firstIndices.mGroupIndex,
1150 endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin() + lastIndices.mGroupIndex + 1;
1151 groupLayoutIt != endGroupLayoutIt;
1152 ++groupLayoutIt, ++groupCount )
1154 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
1156 if( groupCount == lastIndices.mGroupIndex - firstIndices.mGroupIndex )
1161 std::size_t wordCount = 0;
1162 const std::size_t firstWordIndex = firstGroup ? firstIndices.mWordIndex : 0u;
1163 const std::size_t lastWordIndex = lastGroup ? lastIndices.mWordIndex : wordGroupLayoutInfo.mWordsLayoutInfo.size() - 1;
1165 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin() + firstWordIndex,
1166 endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin() + lastWordIndex + 1;
1167 wordLayoutIt != endWordLayoutIt;
1168 ++wordLayoutIt, ++wordCount )
1170 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
1172 if( lastGroup && ( wordCount == lastIndices.mWordIndex - firstWordIndex ) )
1177 const std::size_t firstCharacterIndex = firstWord ? firstIndices.mCharacterIndex : 0u;
1178 const std::size_t lastCharacterIndex = lastWord ? lastIndices.mCharacterIndex : wordLayoutInfo.mCharactersLayoutInfo.size() - 1;
1179 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin() + firstCharacterIndex,
1180 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin() + lastCharacterIndex + 1;
1181 characterLayoutIt != endCharacterLayoutIt;
1182 ++characterLayoutIt )
1184 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
1186 if( ellipsizeParameters.mEllipsizeLine )
1188 // Calculates the character visibility and whether it needs to be replace by ellipsized text.
1189 CalculateVisibilityForEllipsize( layoutParameters,
1190 characterLayoutInfo,
1191 ellipsizeParameters,
1194 if( ellipsizeParameters.mCreateEllipsizedTextActors )
1196 // Create ellipsize text-actors if the character needs to be replaced.
1197 CreateEllipsizeTextActor( ellipsizeParameters,
1203 if( TextView::EllipsizeEnd == layoutParameters.mExceedPolicy )
1205 if( !ellipsizeParameters.mIsLineHeightFullyVisible )
1207 // Make characters invisible.
1208 characterLayoutInfo.mIsVisible = false;
1220 void SetTextVisible( TextView::RelayoutData& relayoutData )
1222 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
1223 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
1224 lineLayoutIt != endLineLayoutIt;
1227 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
1229 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(),
1230 endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
1231 groupLayoutIt != endGroupLayoutIt;
1234 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
1236 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(),
1237 endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
1238 wordLayoutIt != endWordLayoutIt;
1241 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
1243 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
1244 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
1245 characterLayoutIt != endCharacterLayoutIt;
1246 ++characterLayoutIt )
1248 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
1250 characterLayoutInfo.mIsVisible = true;
1251 characterLayoutInfo.mGradientColor = Vector4::ZERO;
1252 characterLayoutInfo.mStartPoint = Vector2::ZERO;
1253 characterLayoutInfo.mEndPoint = Vector2::ZERO;
1256 } // end group of words
1259 // Updates the visibility for text-input..
1260 for( std::vector<Toolkit::TextView::CharacterLayoutInfo>::iterator it = relayoutData.mCharacterLayoutInfoTable.begin(),
1261 endIt = relayoutData.mCharacterLayoutInfoTable.end();
1265 Toolkit::TextView::CharacterLayoutInfo& characterLayoutInfo( *it );
1267 characterLayoutInfo.mIsVisible = true;
1271 void UpdateVisibilityForFade( const TextView::LayoutParameters& layoutParameters,
1272 const TextView::VisualParameters& visualParameters,
1273 TextView::RelayoutData& relayoutData )
1275 RelayoutParameters relayoutParameters;
1276 FadeParameters fadeParameters;
1278 // 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.
1279 fadeParameters.mRightFadeBoundary = static_cast<float>( visualParameters.mFadeBoundary.mRight );
1280 fadeParameters.mRightFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mRight > 0 ? fadeParameters.mRightFadeBoundary : MINIMUM_FADE_BOUNDARY );
1281 fadeParameters.mRightFadeThreshold = relayoutData.mTextViewSize.width - fadeParameters.mRightFadeBoundary;
1282 fadeParameters.mRightFadeThresholdOffset = relayoutData.mTextViewSize.width - fadeParameters.mRightFadeBoundaryOffset;
1283 fadeParameters.mLeftFadeBoundary = static_cast<float>( visualParameters.mFadeBoundary.mLeft );
1284 fadeParameters.mLeftFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mLeft > 0 ? fadeParameters.mLeftFadeBoundary : MINIMUM_FADE_BOUNDARY );
1285 fadeParameters.mLeftFadeThreshold = fadeParameters.mLeftFadeBoundary;
1286 fadeParameters.mLeftFadeThresholdOffset = fadeParameters.mLeftFadeBoundaryOffset;
1287 fadeParameters.mTopFadeBoundary = static_cast<float>( visualParameters.mFadeBoundary.mTop );
1288 fadeParameters.mTopFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mTop > 0 ? fadeParameters.mTopFadeBoundary : MINIMUM_FADE_BOUNDARY );
1289 fadeParameters.mTopFadeThreshold = fadeParameters.mTopFadeBoundary;
1290 fadeParameters.mTopFadeThresholdOffset = fadeParameters.mTopFadeBoundaryOffset;
1291 fadeParameters.mBottomFadeBoundary = static_cast<float>( visualParameters.mFadeBoundary.mBottom );
1292 fadeParameters.mBottomFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mBottom > 0 ? fadeParameters.mBottomFadeBoundary : MINIMUM_FADE_BOUNDARY );
1293 fadeParameters.mBottomFadeThreshold = relayoutData.mTextViewSize.height - fadeParameters.mBottomFadeBoundary;
1294 fadeParameters.mBottomFadeThresholdOffset = relayoutData.mTextViewSize.height - fadeParameters.mBottomFadeBoundaryOffset;
1296 // Calculates the fade out rect coeficients for the right, left, top and bottom sides of the text-view.
1297 fadeParameters.mRightAlphaCoeficients = CalculateRectParameters( Vector2( fadeParameters.mRightFadeThresholdOffset, 1.f ), Vector2( relayoutData.mTextViewSize.width, 0.f ) );
1298 fadeParameters.mLeftAlphaCoeficients = CalculateRectParameters( Vector2( fadeParameters.mLeftFadeThresholdOffset, 1.f ), Vector2( 0.f, 0.f ) );
1299 fadeParameters.mTopAlphaCoeficients = CalculateRectParameters( Vector2( fadeParameters.mTopFadeThresholdOffset, 1.f ), Vector2( 0.f, 0.f ) );
1300 fadeParameters.mBottomAlphaCoeficients = CalculateRectParameters( Vector2( fadeParameters.mBottomFadeThresholdOffset, 1.f ), Vector2( relayoutData.mTextViewSize.height, 0.f ) );
1302 // Traverses all groups of characters and calculates the visibility.
1304 std::size_t infoTableCharacterIndex = 0;
1306 relayoutParameters.mIndices.mLineIndex = 0;
1308 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
1309 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
1310 lineLayoutIt != endLineLayoutIt;
1311 ++lineLayoutIt, ++relayoutParameters.mIndices.mLineIndex )
1313 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
1315 relayoutParameters.mIndices.mGroupIndex = 0;
1317 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(),
1318 endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
1319 groupLayoutIt != endGroupLayoutIt;
1320 ++groupLayoutIt, ++relayoutParameters.mIndices.mGroupIndex )
1322 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
1324 relayoutParameters.mIndices.mWordIndex = 0;
1326 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(),
1327 endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
1328 wordLayoutIt != endWordLayoutIt;
1329 ++wordLayoutIt, ++relayoutParameters.mIndices.mWordIndex )
1331 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
1333 relayoutParameters.mIsFirstCharacterOfWord = true;
1334 relayoutParameters.mWordSize = wordLayoutInfo.mSize;
1335 relayoutParameters.mIndices.mCharacterIndex = 0;
1337 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
1338 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
1339 characterLayoutIt != endCharacterLayoutIt;
1340 ++characterLayoutIt, ++relayoutParameters.mIndices.mCharacterIndex, ++infoTableCharacterIndex )
1342 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
1344 relayoutParameters.mIsVisible = true;
1345 fadeParameters.mIsPartiallyVisible = false;
1347 // Calculates the visibility for the current group of characters.
1348 CalculateVisibilityForFade( layoutParameters,
1349 characterLayoutInfo,
1354 // Updates the visibility for text-input..
1355 std::vector<Toolkit::TextView::CharacterLayoutInfo>::iterator it = relayoutData.mCharacterLayoutInfoTable.begin() + infoTableCharacterIndex;
1357 Toolkit::TextView::CharacterLayoutInfo& characterLayoutTableInfo( *it );
1359 characterLayoutTableInfo.mIsVisible = relayoutParameters.mIsVisible;
1361 relayoutParameters.mIsFirstCharacterOfWord = false;
1362 } // end group of character
1364 } // end group of words
1368 void UpdateVisibilityForEllipsize( const TextView::LayoutParameters& layoutParameters,
1369 const TextView::VisualParameters& visualParameters,
1370 TextView::RelayoutData& relayoutData )
1372 // Traverses the laid-out lines and checks which ones doesn't fit in the text-view's boundary.
1373 for( Toolkit::TextView::LineLayoutInfoContainer::const_iterator lineInfoIt = relayoutData.mLines.begin(), endLineInfoIt = relayoutData.mLines.end();
1374 lineInfoIt != endLineInfoIt;
1377 const Toolkit::TextView::LineLayoutInfo& lineInfo( *lineInfoIt );
1379 // To check if a laid-out line fits in the text-view's boundary,
1380 // get the position of the first character is needed and do the test
1381 // with the laid-out line size.
1383 // An bearing offset may have been applied to the first character so it's needed to
1384 // get the start position of the line.
1386 // Some parameters used in the CalculateVisibilityForEllipsize() function.
1387 EllipsizeParameters ellipsizeParameters;
1389 // Retrieves the first index and the last index of the line.
1390 ellipsizeParameters.mFirstIndex = lineInfo.mCharacterGlobalIndex;
1391 ellipsizeParameters.mLastIndex = 0;
1392 if( ( lineInfoIt + 1 ) != endLineInfoIt )
1394 const Toolkit::TextView::LineLayoutInfo& nextLineInfo( *( lineInfoIt + 1 ) );
1395 ellipsizeParameters.mLastIndex = nextLineInfo.mCharacterGlobalIndex - 1;
1399 ellipsizeParameters.mLastIndex = relayoutData.mCharacterLayoutInfoTable.size() - 1;
1402 // Retrieves the first character of the line and build the position of the line with the bearing.
1403 const Toolkit::TextView::CharacterLayoutInfo& characterInfo = *( relayoutData.mCharacterLayoutInfoTable.begin() + ellipsizeParameters.mFirstIndex );
1405 // Calculates the bearing offset applied to the first character.
1406 const float bearingOffset = ( lineInfo.mSize.height - lineInfo.mAscender ) - characterInfo.mDescender;
1408 // Build the position of the line by removing the bearing offset from the first character's position.
1409 const Vector3 position( characterInfo.mPosition.x,
1410 characterInfo.mPosition.y + bearingOffset,
1411 characterInfo.mPosition.z );
1413 // Checks if the line needs to be ellipsized,
1414 ellipsizeParameters.mIsLineWidthFullyVisible = IsVisible( position,
1416 relayoutData.mTextViewSize,
1417 FULLY_VISIBLE_WIDTH );
1419 // If the exceed policy is EllipsizeEndOriginal it's enough to check
1420 // if the line fits in the width.
1421 ellipsizeParameters.mEllipsizeLine = !ellipsizeParameters.mIsLineWidthFullyVisible;
1423 // If the exceed policy is EllipsizeEnd, it's needed to check if the next line exceeds the text-view's height.
1424 // If the next line exceeds the text-view height then it's going to be invisible and current line needs to be ellipsized.
1425 ellipsizeParameters.mIsLineHeightFullyVisible = true;
1426 ellipsizeParameters.mIsNextLineFullyVisibleHeight = true;
1427 if( TextView::EllipsizeEnd == layoutParameters.mExceedPolicy )
1429 // Need to check if there is lines which doesn't fit in the height.
1431 ellipsizeParameters.mIsLineHeightFullyVisible = IsVisible( position,
1433 relayoutData.mTextViewSize,
1434 FULLY_VISIBLE_HEIGHT );
1436 ellipsizeParameters.mEllipsizeLine = ellipsizeParameters.mEllipsizeLine && ellipsizeParameters.mIsLineHeightFullyVisible;
1438 if( ellipsizeParameters.mIsLineHeightFullyVisible && !ellipsizeParameters.mEllipsizeLine )
1440 // Current line is not ellipsized.
1441 // Need to check if there is a next line and if it's not visible. If there is, current line needs to be ellipsized.
1442 Toolkit::TextView::LineLayoutInfoContainer::const_iterator nextLineInfoIt = lineInfoIt + 1;
1443 if( nextLineInfoIt != endLineInfoIt )
1445 // Retrives the position of the first character of the line and remove
1446 // the bearing offset to build to build the position of the line.
1447 const Toolkit::TextView::LineLayoutInfo& nextLineInfo( *nextLineInfoIt );
1448 const Toolkit::TextView::CharacterLayoutInfo& characterInfo = *( relayoutData.mCharacterLayoutInfoTable.begin() + nextLineInfo.mCharacterGlobalIndex );
1450 const float bearingOffset = ( ( lineInfo.mSize.height - lineInfo.mAscender ) - characterInfo.mDescender ) * relayoutData.mShrinkFactor;
1452 const Vector3 position( characterInfo.mPosition.x,
1453 characterInfo.mPosition.y + bearingOffset,
1454 characterInfo.mPosition.z );
1456 ellipsizeParameters.mIsNextLineFullyVisibleHeight = IsVisible( position,
1458 relayoutData.mTextViewSize,
1459 FULLY_VISIBLE_HEIGHT );
1461 // If the next line is not visible, current line have to be ellipsized.
1462 ellipsizeParameters.mEllipsizeLine = !ellipsizeParameters.mIsNextLineFullyVisibleHeight;
1467 if( !ellipsizeParameters.mIsNextLineFullyVisibleHeight )
1469 ellipsizeParameters.mLineWidth = position.x + lineInfo.mSize.width - relayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo.mSize.width;
1472 // Sets the line descender.
1473 ellipsizeParameters.mLineDescender = lineInfo.mSize.height - lineInfo.mAscender;
1475 // At this point, ellipsizeLine distinguish if a piece of line have to be ellipsized or not.
1476 EllipsizeLine( layoutParameters, ellipsizeParameters, relayoutData );
1480 void UpdateVisibility( const TextView::LayoutParameters& layoutParameters,
1481 const TextView::VisualParameters& visualParameters,
1482 TextView::RelayoutData& relayoutData )
1484 switch( layoutParameters.mExceedPolicy )
1486 case TextView::FadeOriginal:
1487 case TextView::OriginalFade:
1488 case TextView::Fade:
1489 case TextView::SplitFade: // Fall through
1491 UpdateVisibilityForFade( layoutParameters,
1496 case TextView::EllipsizeEndOriginal:
1497 case TextView::EllipsizeEnd: // Fall through
1499 // Set first all characters to visible as UpdateVisibilityForEllipsize() doesn't traverse all of them.
1500 SetTextVisible( relayoutData );
1502 UpdateVisibilityForEllipsize( layoutParameters,
1509 SetTextVisible( relayoutData );
1515 void UpdateTextActorInfo( const TextView::VisualParameters& visualParameters,
1516 TextView::RelayoutData& relayoutData )
1518 CurrentTextActorInfo currentTextActorInfo;
1520 // Traverses the text-actor and layout info data structures.
1521 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
1522 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
1523 lineLayoutIt != endLineLayoutIt;
1526 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
1528 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(),
1529 endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
1530 groupLayoutIt != endGroupLayoutIt;
1533 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
1535 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(),
1536 endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
1537 wordLayoutIt != endWordLayoutIt;
1540 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
1542 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
1543 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
1544 characterLayoutIt != endCharacterLayoutIt;
1545 ++characterLayoutIt )
1547 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
1549 if( characterLayoutInfo.mTextActor )
1551 // There is a new text-actor. Set text and everything to the previous one.
1552 if( currentTextActorInfo.textActor )
1554 currentTextActorInfo.textActor.SetText( currentTextActorInfo.text );
1555 currentTextActorInfo.textActor.SetPosition( currentTextActorInfo.position );
1556 currentTextActorInfo.textActor.SetSize( currentTextActorInfo.size );
1558 SetVisualParameters( currentTextActorInfo,
1561 lineLayoutInfo.mSize.height );
1564 currentTextActorInfo.text = characterLayoutInfo.mStyledText.mText;
1565 currentTextActorInfo.position = Vector3( characterLayoutInfo.mPosition.x + characterLayoutInfo.mOffset.x,
1566 characterLayoutInfo.mPosition.y + characterLayoutInfo.mOffset.y,
1567 characterLayoutInfo.mPosition.z );
1568 currentTextActorInfo.size = characterLayoutInfo.mSize * relayoutData.mShrinkFactor;
1570 currentTextActorInfo.color = characterLayoutInfo.mStyledText.mStyle.GetTextColor();
1571 currentTextActorInfo.color.a = characterLayoutInfo.mColorAlpha;
1573 currentTextActorInfo.gradientColor = characterLayoutInfo.mGradientColor;
1574 currentTextActorInfo.startPoint = characterLayoutInfo.mStartPoint;
1575 currentTextActorInfo.endPoint = characterLayoutInfo.mEndPoint;
1577 // Update the current text-actor.
1578 currentTextActorInfo.textActor = characterLayoutInfo.mTextActor;
1582 // If this character layout has no text-actor is because this character has the same style than previous one.
1583 // Add the character to the current text-actor and update the size.
1584 if( characterLayoutInfo.mIsVisible && ( TextViewProcessor::LineSeparator != wordLayoutInfo.mType ) )
1586 currentTextActorInfo.text.Append( characterLayoutInfo.mStyledText.mText );
1588 currentTextActorInfo.position.y = std::min( currentTextActorInfo.position.y, ( characterLayoutInfo.mPosition.y + characterLayoutInfo.mOffset.y ) );
1589 currentTextActorInfo.size.width += characterLayoutInfo.mSize.width * relayoutData.mShrinkFactor;
1590 currentTextActorInfo.size.height = std::max( currentTextActorInfo.size.height, characterLayoutInfo.mSize.height * relayoutData.mShrinkFactor );
1596 if( !currentTextActorInfo.text.IsEmpty() )
1598 if( currentTextActorInfo.textActor )
1600 currentTextActorInfo.textActor.SetText( currentTextActorInfo.text );
1601 currentTextActorInfo.textActor.SetPosition( currentTextActorInfo.position );
1602 currentTextActorInfo.textActor.SetSize( currentTextActorInfo.size );
1604 SetVisualParameters( currentTextActorInfo,
1607 lineLayoutInfo.mSize.height );
1610 } //end groups of words
1613 for( std::vector<TextActor>::iterator it = relayoutData.mEllipsizedTextActors.begin(),
1614 endIt = relayoutData.mEllipsizedTextActors.end();
1618 TextActor textActor = ( *it );
1620 textActor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1621 textActor.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
1623 // Sets the sort modifier value.
1624 textActor.SetSortModifier( visualParameters.mSortModifier );
1626 // Enables or disables the blending.
1627 textActor.SetBlendMode( !visualParameters.mSnapshotModeEnabled ? BlendingMode::ON : BlendingMode::OFF );
1631 void CalculateUnderlineInfo( TextView::RelayoutData& relayoutData, TextViewRelayout::TextUnderlineStatus& textUnderlineStatus )
1633 // Traverse the whole text to find all groups of consecutive underlined characters in the same laid-out line.
1635 // Note that relayoutData.mTextLayoutInfo contains layout info per line but these lines are the result of split the whole text every time a '\n' is found.
1636 // According with the layout option, one of this lines could be laid-out in more than one.
1638 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(), lineEndIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
1639 lineIt != lineEndIt;
1642 TextViewProcessor::LineLayoutInfo& line( *lineIt );
1644 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupIt = line.mWordGroupsLayoutInfo.begin(), groupEndIt = line.mWordGroupsLayoutInfo.end();
1645 groupIt != groupEndIt;
1648 TextViewProcessor::WordGroupLayoutInfo& group( *groupIt );
1650 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordIt = group.mWordsLayoutInfo.begin(), wordEndIt = group.mWordsLayoutInfo.end();
1651 wordIt != wordEndIt;
1654 TextViewProcessor::WordLayoutInfo& word( *wordIt );
1656 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterIt = word.mCharactersLayoutInfo.begin(), characterEndIt = word.mCharactersLayoutInfo.end();
1657 characterIt != characterEndIt;
1660 TextViewProcessor::CharacterLayoutInfo& characterGroup( *characterIt );
1662 // Check if current character is the first of a new laid-out line
1663 const bool isNewLine = ( textUnderlineStatus.mLineGlobalIndex < relayoutData.mLines.size() ) &&
1664 ( textUnderlineStatus.mCharacterGlobalIndex == ( *( relayoutData.mLines.begin() + textUnderlineStatus.mLineGlobalIndex ) ).mCharacterGlobalIndex );
1667 ++textUnderlineStatus.mLineGlobalIndex; // If it's a new line, point to the next one.
1670 if( characterGroup.mStyledText.mStyle.GetUnderline() )
1672 if( !textUnderlineStatus.mCurrentUnderlineStatus || // Current character is underlined but previous one it wasn't.
1673 isNewLine ) // Current character is underlined and is the first of current laid-out line.
1675 // Create a new underline info for the current underlined characters.
1676 UnderlineInfo underlineInfo;
1677 underlineInfo.mMaxHeight = characterGroup.mSize.height;
1678 underlineInfo.mMaxThickness = characterGroup.mUnderlineThickness;
1679 underlineInfo.mPosition = characterGroup.mUnderlinePosition;
1681 textUnderlineStatus.mUnderlineInfo.push_back( underlineInfo );
1683 textUnderlineStatus.mCurrentUnderlineStatus = true; // Set the current text is underlined.
1687 // Retrieve last underline info and update it if current underline thickness is bigger.
1688 UnderlineInfo& underlineInfo( *( textUnderlineStatus.mUnderlineInfo.end() - 1 ) );
1690 underlineInfo.mMaxHeight = std::max( underlineInfo.mMaxHeight, characterGroup.mSize.height );
1692 if( characterGroup.mUnderlineThickness > underlineInfo.mMaxThickness )
1694 underlineInfo.mMaxThickness = characterGroup.mUnderlineThickness;
1695 underlineInfo.mPosition = characterGroup.mUnderlinePosition;
1701 textUnderlineStatus.mCurrentUnderlineStatus = false;
1704 ++textUnderlineStatus.mCharacterGlobalIndex;
1705 } // end group of characters.
1707 } // end group of words.
1711 void SetUnderlineInfo( TextView::RelayoutData& relayoutData )
1713 // Stores for each group of consecutive underlined text in each laid-out line its maximum thicknes, its position of that thickness and the maximum character's height.
1714 TextViewRelayout::TextUnderlineStatus textUnderlineStatus;
1716 // Traverse the whole text to find all groups of consecutive underlined characters in the same laid-out line.
1717 CalculateUnderlineInfo( relayoutData, textUnderlineStatus );
1719 if( textUnderlineStatus.mUnderlineInfo.empty() )
1721 // There is no underlined text. Just exit.
1725 // At this point textUnderlineStatus.mUnderlineInfo has for each group of consecutive underlined characters their maximum thickness, position and maximum height.
1726 // Traverse the whole text and set the previously stored underline info in the text style.
1728 std::vector<UnderlineInfo>::const_iterator underlineInfoIt = textUnderlineStatus.mUnderlineInfo.begin();
1729 std::vector<UnderlineInfo>::const_iterator underlineInfoEndIt = textUnderlineStatus.mUnderlineInfo.end();
1731 UnderlineInfo underlineInfo;
1733 if( underlineInfoIt < underlineInfoEndIt )
1735 underlineInfo = ( *underlineInfoIt );
1738 // Whether current text is underlined.
1739 textUnderlineStatus.mCurrentUnderlineStatus = false;
1740 textUnderlineStatus.mCharacterGlobalIndex = 0;
1741 textUnderlineStatus.mLineGlobalIndex = 0;
1743 float currentLineHeight = 0.f;
1744 float currentLineAscender = 0.f;
1746 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(), lineEndIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
1747 lineIt != lineEndIt;
1750 TextViewProcessor::LineLayoutInfo& line( *lineIt );
1752 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupIt = line.mWordGroupsLayoutInfo.begin(), groupEndIt = line.mWordGroupsLayoutInfo.end();
1753 groupIt != groupEndIt;
1756 TextViewProcessor::WordGroupLayoutInfo& group( *groupIt );
1758 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordIt = group.mWordsLayoutInfo.begin(), wordEndIt = group.mWordsLayoutInfo.end();
1759 wordIt != wordEndIt;
1762 TextViewProcessor::WordLayoutInfo& word( *wordIt );
1764 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterIt = word.mCharactersLayoutInfo.begin(), characterEndIt = word.mCharactersLayoutInfo.end();
1765 characterIt != characterEndIt;
1768 TextViewProcessor::CharacterLayoutInfo& characterGroup( *characterIt );
1770 // Check if current character is the first of a new laid-out line
1772 bool isNewLine = false;
1774 if( textUnderlineStatus.mLineGlobalIndex < relayoutData.mLines.size() )
1776 const Toolkit::TextView::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mLines.begin() + textUnderlineStatus.mLineGlobalIndex ) );
1777 isNewLine = ( textUnderlineStatus.mCharacterGlobalIndex == lineLayoutInfo.mCharacterGlobalIndex );
1781 currentLineHeight = lineLayoutInfo.mSize.height;
1782 currentLineAscender = lineLayoutInfo.mAscender;
1783 ++textUnderlineStatus.mLineGlobalIndex; // If it's a new line, point to the next one.
1787 if( characterGroup.mStyledText.mStyle.GetUnderline() )
1789 if( textUnderlineStatus.mCurrentUnderlineStatus )
1793 // Retrieves the thickness and position for the next piece of underlined text.
1794 if( underlineInfoIt < underlineInfoEndIt )
1797 if( underlineInfoIt < underlineInfoEndIt )
1799 underlineInfo = *underlineInfoIt;
1805 textUnderlineStatus.mCurrentUnderlineStatus = true;
1807 // Sets the underline's thickness.
1808 characterGroup.mStyledText.mStyle.SetUnderlineThickness( underlineInfo.mMaxThickness );
1810 // Before setting the position it needs to be adjusted to match the base line.
1811 const float bearingOffset = ( currentLineHeight - currentLineAscender ) - ( characterGroup.mSize.height - characterGroup.mAscender );
1812 const float positionOffset = ( underlineInfo.mMaxHeight - characterGroup.mSize.height ) - bearingOffset;
1814 // Sets the underline's position.
1815 characterGroup.mStyledText.mStyle.SetUnderlinePosition( underlineInfo.mPosition - positionOffset );
1817 // Mark the group of characters to be set the new style into the text-actor.
1818 characterGroup.mSetStyle = true;
1822 if( textUnderlineStatus.mCurrentUnderlineStatus )
1824 textUnderlineStatus.mCurrentUnderlineStatus = false;
1826 // Retrieves the thickness and position for the next piece of underlined text.
1827 if( underlineInfoIt < underlineInfoEndIt )
1830 if( underlineInfoIt < underlineInfoEndIt )
1832 underlineInfo = *underlineInfoIt;
1838 ++textUnderlineStatus.mCharacterGlobalIndex;
1839 } // end of group of characters.
1841 } // end of group of words.
1845 void RemoveTextActors( Actor textView,
1846 const std::vector<TextActor>& textActors )
1848 // Removes previously inserted text-actors.
1849 // The SplitByNewLineChar::Relayout(), SplitByWord::Relayout() and SplitByChar::Relayout() functions add
1850 // text-actors to the text-view. A handle to these text-actors are stored and passed to this function
1851 // in order to remove 'only' text-actors added by these functions.
1852 // Any other actor added by a programmer or application won't be removed.
1854 for( std::vector<TextActor>::const_reverse_iterator it = textActors.rbegin(), endIt = textActors.rend(); it != endIt; ++it )
1856 textView.Remove( *it );
1860 void InsertToTextView( const TextView::RelayoutOperationMask relayoutOperationMask,
1862 TextView::RelayoutData& relayoutData )
1864 const bool insertToTextView = relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW;
1865 const bool insertToTextActorList = relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST;
1867 // Add text-actors to the text-view.
1869 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
1870 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
1871 lineLayoutIt != endLineLayoutIt;
1874 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
1876 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(),
1877 endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
1878 groupLayoutIt != endGroupLayoutIt;
1881 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
1883 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(),
1884 endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
1885 wordLayoutIt != endWordLayoutIt;
1888 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
1890 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
1891 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
1892 characterLayoutIt != endCharacterLayoutIt;
1893 ++characterLayoutIt )
1895 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
1897 if( characterLayoutInfo.mIsVisible && characterLayoutInfo.mTextActor ) // White spaces and '\n' characters doesn't have a text-actor.
1899 //Add to the text-view.
1900 if( insertToTextView )
1902 textView.Add( characterLayoutInfo.mTextActor );
1904 if( insertToTextActorList )
1906 relayoutData.mTextActors.push_back( characterLayoutInfo.mTextActor );
1909 } // end group of character
1911 } // end group of words
1914 for( std::vector<TextActor>::iterator it = relayoutData.mEllipsizedTextActors.begin(),
1915 endIt = relayoutData.mEllipsizedTextActors.end();
1919 TextActor textActor = ( *it );
1921 //Add to the text-view.
1922 if( insertToTextView )
1924 textView.Add( textActor );
1926 if( insertToTextActorList )
1928 relayoutData.mTextActors.push_back( textActor );
1931 relayoutData.mEllipsizedTextActors.clear();
1934 TextActor CreateTextActor( const Text& text, const TextStyle& style, TextActorCache& cache )
1936 TextActor textActor = cache.RetrieveTextActor();
1940 // Update the text-actor.
1941 textActor.SetText( text );
1942 textActor.SetTextStyle( style );
1946 // The text-actor cache is empty. Create a new one.
1947 textActor = TextActor::New( text, style, false, true );
1953 } // namespace TextViewRelayout
1955 } // namespace Internal
1957 } // namespace Toolkit