2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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/dali.h>
26 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
27 #include "text-view-line-processor.h"
28 #include "text-view-word-processor.h"
29 #include "text-view-processor-helper-functions.h"
30 #include "text-view-processor-dbg.h"
41 namespace TextViewRelayout
44 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.
46 RelayoutParameters::RelayoutParameters()
52 mCharacterGlobalIndex( 0u ),
53 mIsFirstCharacter( false ),
54 mIsFirstCharacterOfWord( false ),
56 mIsNewLineCharacter( false ),
57 mIsWhiteSpace( false ),
62 RelayoutParameters::~RelayoutParameters()
66 FadeParameters::FadeParameters()
67 : mRightFadeBoundary( 0.f ),
68 mRightFadeThreshold( 0.f ),
69 mRightFadeBoundaryOffset( 0.f ),
70 mRightFadeThresholdOffset( 0.f ),
71 mRightAlphaCoeficients(),
72 mLeftFadeBoundary( 0.f ),
73 mLeftFadeThreshold( 0.f ),
74 mLeftFadeBoundaryOffset( 0.f ),
75 mLeftFadeThresholdOffset( 0.f ),
76 mLeftAlphaCoeficients(),
77 mTopFadeBoundary( 0.f ),
78 mTopFadeThreshold( 0.f ),
79 mTopFadeBoundaryOffset( 0.f ),
80 mTopFadeThresholdOffset( 0.f ),
81 mTopAlphaCoeficients(),
82 mBottomFadeBoundary( 0.f ),
83 mBottomFadeThreshold( 0.f ),
84 mBottomFadeBoundaryOffset( 0.f ),
85 mBottomFadeThresholdOffset( 0.f ),
86 mBottomAlphaCoeficients(),
87 mIsPartiallyVisible( false )
91 FadeParameters::~FadeParameters()
95 EllipsizeParameters::EllipsizeParameters()
97 mLineDescender( 0.f ),
102 mEllipsizeLine( false ),
103 mIsLineWidthFullyVisible( false ),
104 mIsLineHeightFullyVisible( false ),
105 mIsNextLineFullyVisibleHeight( false ),
106 mCreateEllipsizedTextActors( false ),
112 EllipsizeParameters::~EllipsizeParameters()
116 UnderlineInfo::UnderlineInfo()
118 mMaxThickness( 0.f ),
123 UnderlineInfo::~UnderlineInfo()
127 TextUnderlineStatus::TextUnderlineStatus()
129 mCharacterGlobalIndex( 0u ),
130 mLineGlobalIndex( 0u ),
131 mCurrentUnderlineStatus( false )
135 TextUnderlineStatus::~TextUnderlineStatus()
139 SubLineLayoutInfo::SubLineLayoutInfo()
140 : mLineLength( 0.f ),
141 mMaxCharHeight( 0.f ),
146 SubLineLayoutInfo::~SubLineLayoutInfo()
151 * Whether the given text-actor exceeds the left or the right boundary of the text-view.
153 * @param[in] position The position of the text-actor.
154 * @param[in] size The size of the text-actor.
155 * @param[in] parantSize The size of the text-view.
157 * @return \e true if the text-actor exceeds the left or the right boundary of the text-view.
159 bool IsExceedingWidth( const Vector3& position, const Size& size, const Size& parentSize )
161 return ( ( position.x < 0.f ) ||
162 ( position.x + size.width > parentSize.width ) );
166 * Whether the given text-actor exceeds the top or the bottom boundary of the text-view.
168 * @param[in] position The position of the text-actor.
169 * @param[in] size The size of the text-actor.
170 * @param[in] parantSize The size of the text-view.
172 * @return \e true if the text-actor exceeds the top or the bottom boundary of the text-view.
174 bool IsExceedingHeight( const Vector3& position, const Size& size, const Size& parentSize )
176 return ( ( position.y > parentSize.height ) ||
177 ( position.y < size.height ) );
181 * Calculates the line length adding the new word or character width.
183 * It also returns the length of white spaces if they are at the end of the line.
185 * @param[in] isWhiteSpace Whether the word is a white space.
186 * @param[in] width The width of the character or word.
187 * @param[in] parentWidth The parent width.
188 * @param[out] found Whether the sum of the new character or word is exceding the parent's width.
189 * @param[out] lineLength The length of the portion of line which doesn't exceed the parant's width
190 * @param[out] endWhiteSpaceLength The length of white spaces which are at the end of the line.
192 void CalculateLineLength( const bool isWhiteSpace, const float width, const float parentWidth, bool& found, float& lineLength, float& endWhiteSpaceLength )
194 if( lineLength + width > parentWidth )
197 lineLength -= endWhiteSpaceLength;
205 endWhiteSpaceLength += width;
209 endWhiteSpaceLength = 0.f;
214 struct CurrentTextActorInfo
221 Vector4 gradientColor;
226 void SetVisualParameters( CurrentTextActorInfo& currentTextActorInfo,
227 const TextView::VisualParameters& visualParameters,
228 TextView::RelayoutData& relayoutData,
229 const float lineHeight )
231 currentTextActorInfo.textActor.SetTextColor( currentTextActorInfo.color );
232 currentTextActorInfo.textActor.SetGradientColor( currentTextActorInfo.gradientColor );
233 currentTextActorInfo.textActor.SetGradientStartPoint( currentTextActorInfo.startPoint );
234 currentTextActorInfo.textActor.SetGradientEndPoint( currentTextActorInfo.endPoint );
236 // The italics offset is used in the offscreen rendering. When text is in italics, it may exceed the text-view's boundary
237 // due to the trick used to implement it.
238 const Radian& italicsAngle = currentTextActorInfo.textActor.GetItalicsAngle();
239 const float italicsOffset = lineHeight * std::tan( italicsAngle );
240 relayoutData.mTextLayoutInfo.mMaxItalicsOffset = std::max( relayoutData.mTextLayoutInfo.mMaxItalicsOffset, italicsOffset );
242 // Sets the sort modifier value.
243 currentTextActorInfo.textActor.SetSortModifier( visualParameters.mSortModifier );
245 // Enables or disables the blending.
246 currentTextActorInfo.textActor.SetBlendMode( !visualParameters.mSnapshotModeEnabled ? BlendingMode::ON : BlendingMode::OFF );
249 void CalculateSubLineLayout( const float parentWidth,
250 const TextViewProcessor::TextInfoIndices& indices,
251 const TextViewProcessor::LineLayoutInfo& lineLayoutInfo,
252 const HorizontalWrapType splitPolicy,
253 const float shrinkFactor,
254 SubLineLayoutInfo& subLineInfo )
256 subLineInfo.mLineLength = 0.f;
257 subLineInfo.mMaxCharHeight = 0.f;
258 subLineInfo.mMaxAscender = 0.f;
260 float endWhiteSpaceLength = 0.f;
262 std::size_t wordIndex = indices.mWordIndex;
263 std::size_t characterIndex = indices.mCharacterIndex;
264 float lineOffset = 0.f;
266 bool isFirstCharacter = true;
267 for( TextViewProcessor::WordGroupLayoutInfoContainer::const_iterator wordGroupIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin() + indices.mGroupIndex,
268 wordGroupEndIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
269 ( wordGroupIt != wordGroupEndIt ) && !found;
272 const TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *wordGroupIt );
274 for( TextViewProcessor::WordLayoutInfoContainer::const_iterator wordIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin() + wordIndex,
275 wordEndIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
276 ( wordIt != wordEndIt ) && !found;
279 const TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordIt );
281 const float shrunkWordWidth = wordLayoutInfo.mSize.width * shrinkFactor;
282 const bool isWhiteSpace = TextViewProcessor::WordSeparator == wordLayoutInfo.mType;
284 bool splitByCharacter = false;
286 switch( splitPolicy )
288 case WrapByCharacter:
290 splitByCharacter = true;
294 case WrapByLine: // Fall through
296 splitByCharacter = false;
299 case WrapByWordAndSplit:
301 splitByCharacter = ( shrunkWordWidth > parentWidth );
304 case WrapByLineAndSplit:
306 if( ( 0 != characterIndex ) ||
307 ( ( 0 == characterIndex ) && ( lineOffset + shrunkWordWidth > parentWidth ) ) )
309 splitByCharacter = true;
313 lineOffset += shrunkWordWidth;
314 splitByCharacter = false;
319 if( splitByCharacter )
321 for( TextViewProcessor::CharacterLayoutInfoContainer::const_iterator charIt = wordLayoutInfo.mCharactersLayoutInfo.begin() + characterIndex,
322 charEndIt = wordLayoutInfo.mCharactersLayoutInfo.end();
323 ( charIt != charEndIt ) && !found;
326 const TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *charIt );
327 CalculateLineLength( isWhiteSpace, characterLayoutInfo.mSize.width * shrinkFactor, parentWidth, found, subLineInfo.mLineLength, endWhiteSpaceLength );
328 if( !found || isFirstCharacter )
330 subLineInfo.mMaxCharHeight = std::max( subLineInfo.mMaxCharHeight, characterLayoutInfo.mSize.height );
331 subLineInfo.mMaxAscender = std::max( subLineInfo.mMaxAscender, characterLayoutInfo.mAscender );
334 // All characters for word 'wordIndex' have been processed.
335 // Next word need to process all characters, so the characterIndex is reset to 0.
337 isFirstCharacter = false;
340 lineOffset += subLineInfo.mLineLength;
344 CalculateLineLength( isWhiteSpace, shrunkWordWidth, parentWidth, found, subLineInfo.mLineLength, endWhiteSpaceLength );
345 if( !found || isFirstCharacter )
347 subLineInfo.mMaxCharHeight = std::max( subLineInfo.mMaxCharHeight, wordLayoutInfo.mSize.height );
348 subLineInfo.mMaxAscender = std::max( subLineInfo.mMaxAscender, wordLayoutInfo.mAscender );
350 isFirstCharacter = false;
354 // All words for group 'groupIndex' have been processed.
355 // Next group need to process all words, so the wordIndex is reset to 0.
359 subLineInfo.mMaxCharHeight *= shrinkFactor;
360 subLineInfo.mMaxAscender *= shrinkFactor;
363 float CalculateXoffset( const Toolkit::Alignment::Type horizontalTextAlignment, const float parentWidth, const float wholeTextWidth )
365 float xOffset( 0.f );
366 switch( horizontalTextAlignment )
368 case Toolkit::Alignment::HorizontalLeft:
373 case Toolkit::Alignment::HorizontalCenter:
375 xOffset = 0.5f * ( parentWidth - wholeTextWidth );
378 case Toolkit::Alignment::HorizontalRight:
380 xOffset = parentWidth - wholeTextWidth;
385 DALI_ASSERT_ALWAYS( !"TextViewRelayout::CalculateXoffset: Wrong horizontal text alignment. Did you set a vertical one?" );
392 float CalculateYoffset( const Toolkit::Alignment::Type verticalTextAlignment, const float parentHeight, const float wholeTextHeight )
394 float yOffset( 0.f );
395 switch( verticalTextAlignment )
397 case Toolkit::Alignment::VerticalTop:
402 case Toolkit::Alignment::VerticalCenter:
404 yOffset = 0.5f * ( parentHeight - wholeTextHeight );
407 case Toolkit::Alignment::VerticalBottom:
409 yOffset = parentHeight - wholeTextHeight;
414 DALI_ASSERT_ALWAYS( !"TextViewRelayout::CalculateXoffset: Wrong vertical text alignment. Did you set an horizontal one?" );
421 float CalculateJustificationOffset( const Toolkit::TextView::LineJustification justification, const float wholeTextWidth, const float lineLength )
424 switch( justification )
426 case Toolkit::TextView::Left:
431 case Toolkit::TextView::Center:
433 offset = 0.5f * ( wholeTextWidth - lineLength );
436 case Toolkit::TextView::Right:
438 offset = wholeTextWidth - lineLength;
441 case Toolkit::TextView::Justified:
451 bool IsVisible( const Vector3& position, const Size& size, const Size& parentSize, const VisibilityTestType type )
453 bool visible = false;
459 // Whether the text-actor is fully inside the boundaries of the text-view.
460 visible = ( ( position.x >= 0.f ) && ( position.x + size.width <= parentSize.width ) &&
461 ( position.y >= size.height ) && ( position.y <= parentSize.height ) );
464 case FULLY_VISIBLE_WIDTH:
466 // Whether the text-actor is between the left and right boundaries of the text-view.
467 visible = ( ( position.x >= 0.f ) && ( position.x + size.width <= parentSize.width ) );
470 case FULLY_VISIBLE_HEIGHT:
472 // Whether the text-actor is between the top and bottom boundaries of the text-view.
473 visible = ( ( position.y >= size.height ) && ( position.y <= parentSize.height ) );
476 case PARTIALLY_VISIBLE:
478 // Whether the text-actor is partially inside the boundaries of the text-view.
479 visible = ( ( position.x < parentSize.width ) &&
480 ( position.x + size.width > 0.f ) &&
481 ( position.y > 0.f ) &&
482 ( position.y - size.height < parentSize.height ) );
485 case PARTIALLY_VISIBLE_WIDTH:
487 // Whether the text-actor is partially inside the area defined by the left and the right boundaries of the text-view.
488 // It may not be partially inside the text-view.
489 visible = ( ( position.x < parentSize.width ) &&
490 ( position.x + size.width > 0.f ) );
493 case PARTIALLY_VISIBLE_HEIGHT:
495 // Whether the text-actor is partially inside the area defined by the top and the bottom boundaries of the text-view.
496 // It may not be partially inside the text-view.
497 visible = ( ( position.y > 0.f ) &&
498 ( position.y - size.height < parentSize.height ) );
506 Vector2 CalculateRectParameters( const Vector2& p0, const Vector2& p1 )
508 const float gradient = ( p1.y - p0.y ) / ( p1.x - p0.x );
510 return Vector2( gradient, p0.y - gradient * p0.x );
513 void UpdateAlignment( const TextView::LayoutParameters& layoutParameters,
514 TextView::RelayoutData& relayoutData )
516 // Calculates an offset to align the whole text within the text-view's boundary accordingly with the set alignment and justification options.
517 // The offset could be negative if the whole text is bigger than the boundary of the text-view.
519 // If the exceed policy is ellipsize at the end, negative offsets are not wanted.
520 // In that case, it will align the line to the left and/or top, and ellipsize the end.
521 const bool ellipsizeAlignToLeft = ( layoutParameters.mExceedPolicy == TextView::EllipsizeEndOriginal ) || ( layoutParameters.mExceedPolicy == TextView::EllipsizeEnd );
522 const bool ellipsizeAlignToTop = ( layoutParameters.mExceedPolicy == TextView::EllipsizeEnd );
524 RelayoutParameters relayoutParameters;
526 // Calculates the vertical and horizontal offsets.
527 const float textHorizontalOffset = CalculateXoffset( layoutParameters.mHorizontalAlignment, relayoutData.mTextViewSize.width, relayoutData.mTextSizeForRelayoutOption.width );
528 const float textVerticalOffset = CalculateYoffset( layoutParameters.mVerticalAlignment, relayoutData.mTextViewSize.height, relayoutData.mTextSizeForRelayoutOption.height );
530 std::size_t lineJustificationIndex = 0; // Index to the first position of the vector which stores all line justification info.
531 std::size_t infoTableCharacterIndex = 0;
533 relayoutParameters.mIndices.mLineIndex = 0;
535 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
536 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
537 lineLayoutIt != endLineLayoutIt;
538 ++lineLayoutIt, ++relayoutParameters.mIndices.mLineIndex )
540 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
542 relayoutParameters.mIndices.mGroupIndex = 0;
543 float justificationOffset = 0.f;
545 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(),
546 endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
547 groupLayoutIt != endGroupLayoutIt;
548 ++groupLayoutIt, ++relayoutParameters.mIndices.mGroupIndex )
550 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
552 relayoutParameters.mIndices.mWordIndex = 0;
554 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(),
555 endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
556 wordLayoutIt != endWordLayoutIt;
557 ++wordLayoutIt, ++relayoutParameters.mIndices.mWordIndex )
559 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
561 relayoutParameters.mIndices.mCharacterIndex = 0;
563 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
564 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
565 characterLayoutIt != endCharacterLayoutIt;
566 ++characterLayoutIt, ++relayoutParameters.mIndices.mCharacterIndex, ++infoTableCharacterIndex )
568 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
570 // Calculate line justification offset.
571 if( lineJustificationIndex < relayoutData.mLineJustificationInfo.size() )
573 const TextView::LineJustificationInfo lineJustificationInfo( *( relayoutData.mLineJustificationInfo.begin() + lineJustificationIndex ) );
575 if( relayoutParameters.mIndices == lineJustificationInfo.mIndices )
577 justificationOffset = CalculateJustificationOffset( layoutParameters.mLineJustification, relayoutData.mTextSizeForRelayoutOption.width, lineJustificationInfo.mLineLength );
578 ++lineJustificationIndex; // increase the index to point the next position in the vector.
582 // Deletes the offsets if the exceed policies are EllipsizeEnd.
583 const float horizontalOffset = textHorizontalOffset + justificationOffset;
584 characterLayoutInfo.mOffset.x = ( ellipsizeAlignToLeft && ( horizontalOffset < 0.f ) ) ? 0.f : horizontalOffset;
585 characterLayoutInfo.mOffset.y = ( ellipsizeAlignToTop && ( textVerticalOffset < 0.f ) ) ? 0.f : textVerticalOffset;
587 // Updates the size and position table for text-input with the alignment offset.
588 Vector3 positionOffset( characterLayoutInfo.mPosition );
590 std::vector<Toolkit::TextView::CharacterLayoutInfo>::iterator infoTableIt = relayoutData.mCharacterLayoutInfoTable.begin() + infoTableCharacterIndex;
591 Toolkit::TextView::CharacterLayoutInfo& characterTableInfo( *infoTableIt );
593 characterTableInfo.mPosition.x = positionOffset.x + characterLayoutInfo.mOffset.x;
594 characterTableInfo.mPosition.y = positionOffset.y + characterLayoutInfo.mOffset.y;
596 positionOffset.x += characterLayoutInfo.mAdvance * relayoutData.mShrinkFactor;
599 } // end group of words
603 void CalculateBearing( TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo,
604 TextView::RelayoutData& relayoutData )
616 // ggggg gggggggggg bb ggggg
617 // gg gg gggggggggg bb gg gg
618 // gg gg gggg bb gg gg
619 // gg gg gggg bb gg gg
620 // ggggg gg gggg bbbbbbb ggggg
621 // gg gg gggg bb bb gg
622 // g gg gggggggggg bb bb g gg
623 // ggggg gggggggggg bbbbbbb ggggg
632 // ggggg gggg gggg bb ggggg
633 // gg gg gggg gggg bbbbbbb gg gg
634 // gg gg gggg gggg bb bb gg gg
635 // gg gg gggggggggg bb bb gg gg
636 // ggggg gggggggggg bbbbbbb ggggg
639 // ggggg gg gggg ggggg
644 const Toolkit::TextView::LineLayoutInfo& lineInfo( *( relayoutData.mLines.end() - 1 ) );
645 const float bearingOffset = ( lineInfo.mSize.height - lineInfo.mAscender ) - ( characterLayoutInfo.mSize.height - characterLayoutInfo.mAscender );
647 characterLayoutInfo.mPosition.y -= bearingOffset * relayoutData.mShrinkFactor;
650 void UpdateLayoutInfoTable( Vector4& minMaxXY,
651 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo,
652 TextViewProcessor::WordLayoutInfo& wordLayoutInfo,
653 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo,
654 RelayoutParameters& relayoutParameters,
655 TextView::RelayoutData& relayoutData )
657 // updates min and max position to calculate the text size for multiline policies.
658 minMaxXY.x = std::min( minMaxXY.x, characterLayoutInfo.mPosition.x );
659 minMaxXY.z = std::max( minMaxXY.z, characterLayoutInfo.mPosition.x + characterLayoutInfo.mSize.width * relayoutData.mShrinkFactor );
661 minMaxXY.y = std::min( minMaxXY.y, characterLayoutInfo.mPosition.y - characterLayoutInfo.mSize.height * relayoutData.mShrinkFactor );
662 minMaxXY.w = std::max( minMaxXY.w, characterLayoutInfo.mPosition.y );
664 // Adds layout info to be retrieved by external controls or applications.
665 Vector3 positionOffset( characterLayoutInfo.mPosition );
667 const float descender = characterLayoutInfo.mSize.height - characterLayoutInfo.mAscender;
669 const Toolkit::TextView::CharacterLayoutInfo characterLayoutTableInfo( Size( characterLayoutInfo.mAdvance * relayoutData.mShrinkFactor,
670 characterLayoutInfo.mHeight * relayoutData.mShrinkFactor ),
672 ( TextViewProcessor::LineSeparator == wordLayoutInfo.mType ),
673 ( TextViewProcessor::RTL == wordGroupLayoutInfo.mDirection ),
677 relayoutData.mCharacterLayoutInfoTable.push_back( characterLayoutTableInfo );
679 positionOffset.x += characterLayoutInfo.mAdvance * relayoutData.mShrinkFactor;
682 void CalculateVisibilityForFade( const Internal::TextView::LayoutParameters& layoutParameters,
683 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo,
684 RelayoutParameters& relayoutParameters,
685 FadeParameters& fadeParameters,
686 TextView::RelayoutData& relayoutData )
688 if( ( TextView::Fade != layoutParameters.mExceedPolicy ) &&
689 ( TextView::SplitFade != layoutParameters.mExceedPolicy ) &&
690 ( TextView::FadeOriginal != layoutParameters.mExceedPolicy ) &&
691 ( TextView::OriginalFade != layoutParameters.mExceedPolicy ) )
697 // Calculates visibility of a text-actor according the exceed policies.
699 // position + alignment offset.
700 const Vector3 position( characterLayoutInfo.mPosition.x + characterLayoutInfo.mOffset.x,
701 characterLayoutInfo.mPosition.y + characterLayoutInfo.mOffset.y,
702 characterLayoutInfo.mPosition.z );
704 // Whether the text actor is fully, partially or non visible (according exceed policies).
705 switch( layoutParameters.mExceedPolicy )
709 // All text-actors which are not completely inside the text-view's boundaries are set as non visible.
710 // All text-actors which are partially inside the text-view's boundaries are set as partially visible.
711 if( !IsVisible( position,
712 characterLayoutInfo.mSize,
713 relayoutData.mTextViewSize,
716 relayoutParameters.mIsVisible = false;
717 if( IsVisible( position,
718 characterLayoutInfo.mSize,
719 relayoutData.mTextViewSize,
720 PARTIALLY_VISIBLE ) )
722 fadeParameters.mIsPartiallyVisible = true;
724 // Checks if a text-actor is exceeding more than one boundary as this case is not supported.
725 if( IsExceedingWidth( position,
726 characterLayoutInfo.mSize,
727 relayoutData.mTextViewSize ) &&
728 IsExceedingHeight( position,
729 characterLayoutInfo.mSize,
730 relayoutData.mTextViewSize ) )
732 // Combination not fully supported by text-view.
733 // Need to check if text-actor really supports this combination.
734 fadeParameters.mIsPartiallyVisible = false;
740 case TextView::FadeOriginal:
742 // All text-actors which are not completely between the left and right text-view's boundaries are set as non visible.
743 // All text-actors which are partially inside the text-view's boundaries are set as partially visible.
744 if( !IsVisible( position,
745 characterLayoutInfo.mSize,
746 relayoutData.mTextViewSize,
747 FULLY_VISIBLE_WIDTH ) )
749 relayoutParameters.mIsVisible = false;
750 if( IsVisible( position,
751 characterLayoutInfo.mSize,
752 relayoutData.mTextViewSize,
753 PARTIALLY_VISIBLE_WIDTH ) )
755 fadeParameters.mIsPartiallyVisible = true;
760 case TextView::OriginalFade:
761 case TextView::SplitFade: // Fallthrough
763 // All text-actors which are not completely between the top and bottom text-view's boundaries are set as non visible.
764 // All text-actors which are partially inside the text-view's boundaries are set as partially visible.
765 if( !IsVisible( position,
766 characterLayoutInfo.mSize,
767 relayoutData.mTextViewSize,
768 FULLY_VISIBLE_HEIGHT ) )
770 relayoutParameters.mIsVisible = false;
771 if( IsVisible( position,
772 characterLayoutInfo.mSize,
773 relayoutData.mTextViewSize,
774 PARTIALLY_VISIBLE_HEIGHT ) )
776 fadeParameters.mIsPartiallyVisible = true;
783 DALI_ASSERT_ALWAYS( !"TextViewRelayout::CalculateVisibilityForFade. Wrong exceed policies." )
788 if( relayoutParameters.mIsVisible || fadeParameters.mIsPartiallyVisible )
790 characterLayoutInfo.mIsVisible = true;
792 const Size size = characterLayoutInfo.mSize * relayoutData.mShrinkFactor;
793 const float characterPositionPlusWidth = position.x + size.width;
794 const float characterPositionMinusHeight = position.y - size.height;
796 // Calculates which edges need to be faded-out.
797 bool rightFadeOut = false;
798 bool leftFadeOut = false;
799 bool bottomFadeOut = false;
800 bool topFadeOut = false;
802 switch( layoutParameters.mExceedPolicy )
806 // All text-actors exceeding any of the boundaries will be faded-out.
807 rightFadeOut = ( characterPositionPlusWidth > fadeParameters.mRightFadeThreshold );
808 leftFadeOut = ( position.x < fadeParameters.mLeftFadeThreshold );
809 bottomFadeOut = ( position.y > fadeParameters.mBottomFadeThreshold );
810 topFadeOut = ( characterPositionMinusHeight < fadeParameters.mTopFadeThreshold );
813 case TextView::FadeOriginal:
815 // Only text-actors exceeding the left or the right boundaries will be faded-out.
816 rightFadeOut = ( characterPositionPlusWidth > fadeParameters.mRightFadeThreshold );
817 leftFadeOut = ( position.x < fadeParameters.mLeftFadeThreshold );
820 case TextView::SplitFade:
821 case TextView::OriginalFade: //Fallthrough
823 // Only text-actors exceeding the top or the bottom boundaries will be faded-out.
824 bottomFadeOut = ( position.y > fadeParameters.mBottomFadeThreshold );
825 topFadeOut = ( characterPositionMinusHeight < fadeParameters.mTopFadeThreshold );
830 DALI_ASSERT_ALWAYS( !"TextViewRelayout::CalculateVisibilityForFade. Wrong exceed policies." );
835 // Calculates gradient parameters for a text-actor.
836 Vector4 gradientColor = Vector4::ZERO;
837 Vector2 startPoint = Vector2::ZERO;
838 Vector2 endPoint = Vector2::ZERO;
840 if( !( rightFadeOut && leftFadeOut ) )
842 // Current implementation can't set gradient parameters for a text-actor exceeding at the same time the left and the right boundaries.
845 gradientColor = characterLayoutInfo.mStyledText.mStyle.GetTextColor();
847 // Calculates gradient coeficients.
848 characterLayoutInfo.mColorAlpha = gradientColor.a * std::min( 1.f, fadeParameters.mRightAlphaCoeficients.x * position.x + fadeParameters.mRightAlphaCoeficients.y );
849 gradientColor.a *= std::max( 0.f, fadeParameters.mRightAlphaCoeficients.x * characterPositionPlusWidth + fadeParameters.mRightAlphaCoeficients.y );
851 startPoint = Vector2( std::max( 0.f, ( fadeParameters.mRightFadeThresholdOffset - position.x ) / size.width ), 0.5f );
852 endPoint = Vector2( std::min( 1.f, ( relayoutData.mTextViewSize.width - position.x ) / size.width ), 0.5f );
854 else if( leftFadeOut )
856 gradientColor = characterLayoutInfo.mStyledText.mStyle.GetTextColor();
858 // Calculates gradient coeficients.
859 characterLayoutInfo.mColorAlpha = std::min( 1.f, fadeParameters.mLeftAlphaCoeficients.x * characterPositionPlusWidth + fadeParameters.mLeftAlphaCoeficients.y );
860 gradientColor.a *= gradientColor.a * std::max( 0.f, fadeParameters.mLeftAlphaCoeficients.x * position.x + fadeParameters.mLeftAlphaCoeficients.y );
862 startPoint = Vector2( std::max( 0.f, ( fadeParameters.mLeftFadeThresholdOffset - position.x ) / size.width ), 0.5f );
863 endPoint = Vector2( std::min( 1.f, -position.x / size.width ), 0.5f );
867 if( !( bottomFadeOut && topFadeOut ) )
869 // Current implementation can't set gradient parameters for a text-actor exceeding at the same time the top and the bottom boundaries.
872 gradientColor = characterLayoutInfo.mStyledText.mStyle.GetTextColor();
874 // Calculates gradient coeficients.
875 characterLayoutInfo.mColorAlpha = gradientColor.a * std::min( 1.f, fadeParameters.mBottomAlphaCoeficients.x * characterPositionMinusHeight + fadeParameters.mBottomAlphaCoeficients.y );
876 gradientColor.a *= std::max( 0.f, fadeParameters.mBottomAlphaCoeficients.x * position.y + fadeParameters.mBottomAlphaCoeficients.y );
878 startPoint = Vector2( 0.5f, std::max( 0.f, ( fadeParameters.mBottomFadeThresholdOffset - characterPositionMinusHeight ) / size.height ) );
879 endPoint = Vector2( 0.5f, std::min( 1.f, ( relayoutData.mTextViewSize.height - characterPositionMinusHeight ) / size.height ) );
881 else if( topFadeOut )
883 gradientColor = characterLayoutInfo.mStyledText.mStyle.GetTextColor();
885 // Calculates gradient coeficients.
886 characterLayoutInfo.mColorAlpha *= gradientColor.a * std::min( 1.f, fadeParameters.mTopAlphaCoeficients.x * position.y + fadeParameters.mTopAlphaCoeficients.y );
887 gradientColor.a *= std::max( 0.f, fadeParameters.mTopAlphaCoeficients.x * characterPositionMinusHeight + fadeParameters.mTopAlphaCoeficients.y );
889 startPoint = Vector2( 0.5f, std::max( 0.f, ( fadeParameters.mTopFadeThresholdOffset - characterPositionMinusHeight ) / size.height ) );
890 endPoint = Vector2( 0.5f, std::min( 1.f, -characterPositionMinusHeight / size.height ) );
894 characterLayoutInfo.mGradientColor = gradientColor;
895 characterLayoutInfo.mStartPoint = startPoint;
896 characterLayoutInfo.mEndPoint = endPoint;
900 characterLayoutInfo.mIsVisible = false;
904 bool CalculateVisibilityForEllipsizeEndOriginal( TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo,
905 const EllipsizeParameters& ellipsizeParameters )
907 bool isPartiallyVisible = false;
909 if( !IsVisible( ellipsizeParameters.mPosition,
910 characterLayoutInfo.mSize,
911 ellipsizeParameters.mEllipsizeBoundary,
912 FULLY_VISIBLE_WIDTH ) )
914 // The character doesn't fit in the text-view's width.
915 characterLayoutInfo.mIsVisible = false;
917 // Checks if the character is partially visible (it's cut by the boundary)
918 isPartiallyVisible = IsVisible( ellipsizeParameters.mPosition,
919 characterLayoutInfo.mSize,
920 ellipsizeParameters.mEllipsizeBoundary,
921 PARTIALLY_VISIBLE_WIDTH );
925 // The character fits in the text-view's width. Set it to visible.
926 characterLayoutInfo.mIsVisible = true;
929 return isPartiallyVisible;
932 bool CalculateVisibilityForEllipsizeEnd( TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo,
933 const EllipsizeParameters& ellipsizeParameters )
935 bool isPartiallyVisible = false;
937 if( !IsVisible( ellipsizeParameters.mPosition,
938 characterLayoutInfo.mSize,
939 ellipsizeParameters.mEllipsizeBoundary,
942 // The character is not fully visible. Needs to check if it's partially visible.
943 characterLayoutInfo.mIsVisible = false;
945 // Checks if the character doesn't cut the bottom edge of the text-view.
946 const bool fullyVisibleHeight = IsVisible( ellipsizeParameters.mPosition,
947 characterLayoutInfo.mSize,
948 ellipsizeParameters.mEllipsizeBoundary,
949 FULLY_VISIBLE_HEIGHT );
951 // Checks if the character cuts the right edge of the text-view.
952 const bool partiallyVisibleWidth = IsVisible( ellipsizeParameters.mPosition,
953 characterLayoutInfo.mSize,
954 ellipsizeParameters.mEllipsizeBoundary,
955 PARTIALLY_VISIBLE_WIDTH );
957 // Character will be ellipsized if it cuts the right edge of the text-view but fits completely in the text-view's height.
958 isPartiallyVisible = ( fullyVisibleHeight && partiallyVisibleWidth );
962 // The character fits in the boundary of the text-view. Set it to visible.
963 characterLayoutInfo.mIsVisible = true;
966 return isPartiallyVisible;
969 void CalculateVisibilityForEllipsize( const Internal::TextView::LayoutParameters& layoutParameters,
970 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo,
971 EllipsizeParameters& ellipsizeParameters,
972 TextView::RelayoutData& relayoutData )
974 // Calculates visibility for EllipsizeEnd exceed policies.
976 // 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.
977 // If a character is cut by this boundary and the whole line (if the multi-line policy is split-by-new-line-char)
978 // 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.
980 // Position of the character used to do the visibility test.
981 ellipsizeParameters.mPosition = Vector3( characterLayoutInfo.mPosition.x + characterLayoutInfo.mOffset.x,
982 characterLayoutInfo.mPosition.y + characterLayoutInfo.mOffset.y,
983 characterLayoutInfo.mPosition.z );
985 // 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).
986 bool isPartiallyVisible = false;
988 // Checks if the whole line or the whole word fits in the text-view's width accordingly with the multiline policy.
989 const bool fitsInWidth = ( Toolkit::TextView::SplitByNewLineChar == layoutParameters.mMultilinePolicy ) ? ellipsizeParameters.mLineFits: ellipsizeParameters.mWordFits;
991 // Will only ellipsize the text if it cuts the right vertical edge and it doesn't fit in the text-view's width.
994 // The line or word fits completely inside the text-view's width. Nothing else to do.
995 characterLayoutInfo.mIsVisible = true;
999 // The line or word doesn't fit in the text-view's width.
1001 // Calculates visibility for each type of ellipsize policies.
1002 switch( layoutParameters.mExceedPolicy )
1004 case TextView::EllipsizeEndOriginal:
1006 // 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.
1008 isPartiallyVisible = CalculateVisibilityForEllipsizeEndOriginal( characterLayoutInfo,
1009 ellipsizeParameters );
1013 case TextView::EllipsizeEnd:
1015 // Ellipsizes the text if it doesn't fit in the width and fully fits in the text-view's height.
1017 isPartiallyVisible = CalculateVisibilityForEllipsizeEnd( characterLayoutInfo,
1018 ellipsizeParameters );
1024 DALI_ASSERT_DEBUG( !"TextViewRelayout::CalculateVisibilityForEllipsize. Wrong exceed value." );
1030 // If the current character is not fully visible but is partially visible, it is cut by the boundary of the text-view.
1031 // In that case, the charater needs to be replaced by the ellipsize text.
1032 ellipsizeParameters.mCreateEllipsizedTextActors = ( !characterLayoutInfo.mIsVisible && isPartiallyVisible );
1035 void CreateEllipsizeTextActor( const EllipsizeParameters& ellipsizeParameters,
1036 TextView::RelayoutData& relayoutData )
1038 // 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.
1039 // The code bellow creates the text-actors needed for the ellipsize text.
1041 // Set ellipsize's position by the end of visible text.
1042 Vector3 ellipsizePosition = ellipsizeParameters.mPosition;
1043 // Stores current ellipsize text.
1045 // Stores current ellipsize style.
1046 TextStyle ellipsizeStyle;
1047 // Stores the current size.
1049 //Whether current glyph is an emoticon.
1050 bool isColorGlyph = false;
1052 float bearingOffset = 0.f;
1054 // Create ellipsize text-actor.
1055 for( TextViewProcessor::CharacterLayoutInfoContainer::const_iterator ellipsizeCharacterLayoutIt = relayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo.mCharactersLayoutInfo.begin(),
1056 endEllipsizeCharacterLayoutIt = relayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo.mCharactersLayoutInfo.end();
1057 ellipsizeCharacterLayoutIt != endEllipsizeCharacterLayoutIt;
1058 ++ellipsizeCharacterLayoutIt )
1060 const TextViewProcessor::CharacterLayoutInfo& ellipsizeCharacterLayoutInfo( *ellipsizeCharacterLayoutIt );
1063 ( isColorGlyph != ellipsizeCharacterLayoutInfo.mIsColorGlyph ) ||
1064 ( ellipsizeStyle != ellipsizeCharacterLayoutInfo.mStyledText.mStyle ) )
1066 // The style is different, so a new text-actor is needed.
1067 if( !ellipsizeText.IsEmpty() )
1069 // It only creates a text-actor if there is any text.
1070 RenderableActor ellipsizeGlyphActor = CreateGlyphActor( ellipsizeText, ellipsizeStyle, relayoutData.mTextActorCache );
1071 ellipsizeGlyphActor.SetSize( ellipsizeSize );
1072 ellipsizeGlyphActor.SetPosition( Vector3( ellipsizePosition.x, ellipsizePosition.y - bearingOffset, ellipsizePosition.z ) );
1074 // Updates the position for the next text-actor.
1075 ellipsizePosition.x += ellipsizeSize.width;
1077 // Adds the text-actor to the list.
1078 relayoutData.mEllipsizedGlyphActors.push_back( ellipsizeGlyphActor );
1081 // Resets the current ellipsize info.
1082 ellipsizeText = ellipsizeCharacterLayoutInfo.mStyledText.mText;
1083 ellipsizeStyle = ellipsizeCharacterLayoutInfo.mStyledText.mStyle;
1084 ellipsizeSize = ellipsizeCharacterLayoutInfo.mSize;
1085 isColorGlyph = ellipsizeCharacterLayoutInfo.mIsColorGlyph;
1087 bearingOffset = ( ellipsizeParameters.mLineDescender - ( ellipsizeCharacterLayoutInfo.mSize.height - ellipsizeCharacterLayoutInfo.mAscender ) ) * relayoutData.mShrinkFactor;
1091 // Updates text and size with the new character.
1092 ellipsizeText.Append( ellipsizeCharacterLayoutInfo.mStyledText.mText );
1093 TextViewProcessor::UpdateSize( ellipsizeSize, ellipsizeCharacterLayoutInfo.mSize );
1098 if( !ellipsizeText.IsEmpty() )
1100 // Creates the last glyph-actor.
1101 RenderableActor ellipsizeGlyphActor = CreateGlyphActor( ellipsizeText, ellipsizeStyle, relayoutData.mTextActorCache );
1102 ellipsizeGlyphActor.SetSize( ellipsizeSize );
1103 ellipsizeGlyphActor.SetPosition( Vector3( ellipsizePosition.x, ellipsizePosition.y - bearingOffset, ellipsizePosition.z ) );
1105 // Adds the glyph-actor to the list.
1106 relayoutData.mEllipsizedGlyphActors.push_back( ellipsizeGlyphActor );
1110 void EllipsizeLine( const TextView::LayoutParameters& layoutParameters,
1111 EllipsizeParameters& ellipsizeParameters,
1112 TextView::RelayoutData& relayoutData )
1114 // Traverses the text layout info from the first character of the laid out line
1115 // to the last one setting to each character its visibility. If needed, it adds the ellipsize text (...).
1117 // Indices to the first character of the laid out line.
1118 TextViewProcessor::TextInfoIndices firstIndices;
1119 TextViewProcessor::GetIndicesFromGlobalCharacterIndex( ellipsizeParameters.mFirstIndex,
1120 relayoutData.mTextLayoutInfo,
1123 // Indices to the last character of the laid out line.
1124 TextViewProcessor::TextInfoIndices lastIndices;
1125 TextViewProcessor::GetIndicesFromGlobalCharacterIndex( ellipsizeParameters.mLastIndex,
1126 relayoutData.mTextLayoutInfo,
1129 // Defines a boundary by substracting the ellipsize-text's width to the text-view's width.
1130 // This is the boundary used to check if a character have to be ellipsized.
1131 ellipsizeParameters.mEllipsizeBoundary = relayoutData.mTextViewSize;
1132 ellipsizeParameters.mEllipsizeBoundary.width -= relayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo.mSize.width;
1134 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + firstIndices.mLineIndex,
1135 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + lastIndices.mLineIndex + 1;
1136 lineLayoutIt != endLineLayoutIt;
1139 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
1141 ellipsizeParameters.mLineFits = ellipsizeParameters.mIsLineWidthFullyVisible && ellipsizeParameters.mIsLineHeightFullyVisible && ellipsizeParameters.mIsNextLineFullyVisibleHeight;
1143 if( !ellipsizeParameters.mIsNextLineFullyVisibleHeight )
1145 ellipsizeParameters.mEllipsizeBoundary.width = ellipsizeParameters.mLineWidth;
1148 bool firstGroup = true;
1149 bool lastGroup = false;
1150 std::size_t groupCount = 0;
1152 bool firstWord = true;
1153 bool lastWord = false;
1155 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin() + firstIndices.mGroupIndex,
1156 endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin() + lastIndices.mGroupIndex + 1;
1157 groupLayoutIt != endGroupLayoutIt;
1158 ++groupLayoutIt, ++groupCount )
1160 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
1162 if( groupCount == lastIndices.mGroupIndex - firstIndices.mGroupIndex )
1167 std::size_t wordCount = 0;
1168 const std::size_t firstWordIndex = firstGroup ? firstIndices.mWordIndex : 0u;
1169 const std::size_t lastWordIndex = lastGroup ? lastIndices.mWordIndex : wordGroupLayoutInfo.mWordsLayoutInfo.size() - 1;
1171 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin() + firstWordIndex,
1172 endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin() + lastWordIndex + 1;
1173 wordLayoutIt != endWordLayoutIt;
1174 ++wordLayoutIt, ++wordCount )
1176 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
1178 if( lastGroup && ( wordCount == lastIndices.mWordIndex - firstWordIndex ) )
1183 const std::size_t firstCharacterIndex = firstWord ? firstIndices.mCharacterIndex : 0u;
1184 const std::size_t lastCharacterIndex = lastWord ? lastIndices.mCharacterIndex : wordLayoutInfo.mCharactersLayoutInfo.size() - 1;
1185 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin() + firstCharacterIndex,
1186 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin() + lastCharacterIndex + 1;
1187 characterLayoutIt != endCharacterLayoutIt;
1188 ++characterLayoutIt )
1190 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
1192 if( ellipsizeParameters.mEllipsizeLine )
1194 // Calculates the character visibility and whether it needs to be replace by ellipsized text.
1195 CalculateVisibilityForEllipsize( layoutParameters,
1196 characterLayoutInfo,
1197 ellipsizeParameters,
1200 if( ellipsizeParameters.mCreateEllipsizedTextActors )
1202 // Create ellipsize text-actors if the character needs to be replaced.
1203 CreateEllipsizeTextActor( ellipsizeParameters,
1209 if( TextView::EllipsizeEnd == layoutParameters.mExceedPolicy )
1211 if( !ellipsizeParameters.mIsLineHeightFullyVisible )
1213 // Make characters invisible.
1214 characterLayoutInfo.mIsVisible = false;
1226 void SetTextVisible( TextView::RelayoutData& relayoutData )
1228 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
1229 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
1230 lineLayoutIt != endLineLayoutIt;
1233 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
1235 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(),
1236 endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
1237 groupLayoutIt != endGroupLayoutIt;
1240 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
1242 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(),
1243 endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
1244 wordLayoutIt != endWordLayoutIt;
1247 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
1249 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
1250 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
1251 characterLayoutIt != endCharacterLayoutIt;
1252 ++characterLayoutIt )
1254 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
1256 characterLayoutInfo.mIsVisible = true;
1257 characterLayoutInfo.mGradientColor = Vector4::ZERO;
1258 characterLayoutInfo.mStartPoint = Vector2::ZERO;
1259 characterLayoutInfo.mEndPoint = Vector2::ZERO;
1262 } // end group of words
1265 // Updates the visibility for text-input..
1266 for( std::vector<Toolkit::TextView::CharacterLayoutInfo>::iterator it = relayoutData.mCharacterLayoutInfoTable.begin(),
1267 endIt = relayoutData.mCharacterLayoutInfoTable.end();
1271 Toolkit::TextView::CharacterLayoutInfo& characterLayoutInfo( *it );
1273 characterLayoutInfo.mIsVisible = true;
1277 void UpdateVisibilityForFade( const TextView::LayoutParameters& layoutParameters,
1278 const TextView::VisualParameters& visualParameters,
1279 TextView::RelayoutData& relayoutData )
1281 RelayoutParameters relayoutParameters;
1282 FadeParameters fadeParameters;
1284 // 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.
1285 fadeParameters.mRightFadeBoundary = static_cast<float>( visualParameters.mFadeBoundary.mRight );
1286 fadeParameters.mRightFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mRight > 0 ? fadeParameters.mRightFadeBoundary : MINIMUM_FADE_BOUNDARY );
1287 fadeParameters.mRightFadeThreshold = relayoutData.mTextViewSize.width - fadeParameters.mRightFadeBoundary;
1288 fadeParameters.mRightFadeThresholdOffset = relayoutData.mTextViewSize.width - fadeParameters.mRightFadeBoundaryOffset;
1289 fadeParameters.mLeftFadeBoundary = static_cast<float>( visualParameters.mFadeBoundary.mLeft );
1290 fadeParameters.mLeftFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mLeft > 0 ? fadeParameters.mLeftFadeBoundary : MINIMUM_FADE_BOUNDARY );
1291 fadeParameters.mLeftFadeThreshold = fadeParameters.mLeftFadeBoundary;
1292 fadeParameters.mLeftFadeThresholdOffset = fadeParameters.mLeftFadeBoundaryOffset;
1293 fadeParameters.mTopFadeBoundary = static_cast<float>( visualParameters.mFadeBoundary.mTop );
1294 fadeParameters.mTopFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mTop > 0 ? fadeParameters.mTopFadeBoundary : MINIMUM_FADE_BOUNDARY );
1295 fadeParameters.mTopFadeThreshold = fadeParameters.mTopFadeBoundary;
1296 fadeParameters.mTopFadeThresholdOffset = fadeParameters.mTopFadeBoundaryOffset;
1297 fadeParameters.mBottomFadeBoundary = static_cast<float>( visualParameters.mFadeBoundary.mBottom );
1298 fadeParameters.mBottomFadeBoundaryOffset = ( visualParameters.mFadeBoundary.mBottom > 0 ? fadeParameters.mBottomFadeBoundary : MINIMUM_FADE_BOUNDARY );
1299 fadeParameters.mBottomFadeThreshold = relayoutData.mTextViewSize.height - fadeParameters.mBottomFadeBoundary;
1300 fadeParameters.mBottomFadeThresholdOffset = relayoutData.mTextViewSize.height - fadeParameters.mBottomFadeBoundaryOffset;
1302 // Calculates the fade out rect coeficients for the right, left, top and bottom sides of the text-view.
1303 fadeParameters.mRightAlphaCoeficients = CalculateRectParameters( Vector2( fadeParameters.mRightFadeThresholdOffset, 1.f ), Vector2( relayoutData.mTextViewSize.width, 0.f ) );
1304 fadeParameters.mLeftAlphaCoeficients = CalculateRectParameters( Vector2( fadeParameters.mLeftFadeThresholdOffset, 1.f ), Vector2( 0.f, 0.f ) );
1305 fadeParameters.mTopAlphaCoeficients = CalculateRectParameters( Vector2( fadeParameters.mTopFadeThresholdOffset, 1.f ), Vector2( 0.f, 0.f ) );
1306 fadeParameters.mBottomAlphaCoeficients = CalculateRectParameters( Vector2( fadeParameters.mBottomFadeThresholdOffset, 1.f ), Vector2( relayoutData.mTextViewSize.height, 0.f ) );
1308 // Traverses all groups of characters and calculates the visibility.
1310 std::size_t infoTableCharacterIndex = 0;
1312 relayoutParameters.mIndices.mLineIndex = 0;
1314 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
1315 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
1316 lineLayoutIt != endLineLayoutIt;
1317 ++lineLayoutIt, ++relayoutParameters.mIndices.mLineIndex )
1319 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
1321 relayoutParameters.mIndices.mGroupIndex = 0;
1323 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(),
1324 endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
1325 groupLayoutIt != endGroupLayoutIt;
1326 ++groupLayoutIt, ++relayoutParameters.mIndices.mGroupIndex )
1328 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
1330 relayoutParameters.mIndices.mWordIndex = 0;
1332 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(),
1333 endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
1334 wordLayoutIt != endWordLayoutIt;
1335 ++wordLayoutIt, ++relayoutParameters.mIndices.mWordIndex )
1337 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
1339 relayoutParameters.mIsFirstCharacterOfWord = true;
1340 relayoutParameters.mWordSize = wordLayoutInfo.mSize;
1341 relayoutParameters.mIndices.mCharacterIndex = 0;
1343 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
1344 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
1345 characterLayoutIt != endCharacterLayoutIt;
1346 ++characterLayoutIt, ++relayoutParameters.mIndices.mCharacterIndex, ++infoTableCharacterIndex )
1348 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
1350 relayoutParameters.mIsVisible = true;
1351 fadeParameters.mIsPartiallyVisible = false;
1353 // Calculates the visibility for the current group of characters.
1354 CalculateVisibilityForFade( layoutParameters,
1355 characterLayoutInfo,
1360 // Updates the visibility for text-input..
1361 std::vector<Toolkit::TextView::CharacterLayoutInfo>::iterator it = relayoutData.mCharacterLayoutInfoTable.begin() + infoTableCharacterIndex;
1363 Toolkit::TextView::CharacterLayoutInfo& characterLayoutTableInfo( *it );
1365 characterLayoutTableInfo.mIsVisible = relayoutParameters.mIsVisible;
1367 relayoutParameters.mIsFirstCharacterOfWord = false;
1368 } // end group of character
1370 } // end group of words
1374 void UpdateVisibilityForEllipsize( const TextView::LayoutParameters& layoutParameters,
1375 const TextView::VisualParameters& visualParameters,
1376 TextView::RelayoutData& relayoutData )
1378 // Traverses the laid-out lines and checks which ones doesn't fit in the text-view's boundary.
1379 for( Toolkit::TextView::LineLayoutInfoContainer::const_iterator lineInfoIt = relayoutData.mLines.begin(), endLineInfoIt = relayoutData.mLines.end();
1380 lineInfoIt != endLineInfoIt;
1383 const Toolkit::TextView::LineLayoutInfo& lineInfo( *lineInfoIt );
1385 // To check if a laid-out line fits in the text-view's boundary,
1386 // get the position of the first character is needed and do the test
1387 // with the laid-out line size.
1389 // An bearing offset may have been applied to the first character so it's needed to
1390 // get the start position of the line.
1392 // Some parameters used in the CalculateVisibilityForEllipsize() function.
1393 EllipsizeParameters ellipsizeParameters;
1395 // Retrieves the first index and the last index of the line.
1396 ellipsizeParameters.mFirstIndex = lineInfo.mCharacterGlobalIndex;
1397 ellipsizeParameters.mLastIndex = 0;
1398 if( ( lineInfoIt + 1 ) != endLineInfoIt )
1400 const Toolkit::TextView::LineLayoutInfo& nextLineInfo( *( lineInfoIt + 1 ) );
1401 ellipsizeParameters.mLastIndex = nextLineInfo.mCharacterGlobalIndex - 1;
1405 ellipsizeParameters.mLastIndex = relayoutData.mCharacterLayoutInfoTable.size() - 1;
1408 // Retrieves the first character of the line and build the position of the line with the bearing.
1409 const Toolkit::TextView::CharacterLayoutInfo& characterInfo = *( relayoutData.mCharacterLayoutInfoTable.begin() + ellipsizeParameters.mFirstIndex );
1411 // Calculates the bearing offset applied to the first character.
1412 const float bearingOffset = ( lineInfo.mSize.height - lineInfo.mAscender ) - characterInfo.mDescender;
1414 // Build the position of the line by removing the bearing offset from the first character's position.
1415 const Vector3 position( characterInfo.mPosition.x,
1416 characterInfo.mPosition.y + bearingOffset,
1417 characterInfo.mPosition.z );
1419 // Checks if the line needs to be ellipsized,
1420 ellipsizeParameters.mIsLineWidthFullyVisible = IsVisible( position,
1422 relayoutData.mTextViewSize,
1423 FULLY_VISIBLE_WIDTH );
1425 // If the exceed policy is EllipsizeEndOriginal it's enough to check
1426 // if the line fits in the width.
1427 ellipsizeParameters.mEllipsizeLine = !ellipsizeParameters.mIsLineWidthFullyVisible;
1429 // If the exceed policy is EllipsizeEnd, it's needed to check if the next line exceeds the text-view's height.
1430 // If the next line exceeds the text-view height then it's going to be invisible and current line needs to be ellipsized.
1431 ellipsizeParameters.mIsLineHeightFullyVisible = true;
1432 ellipsizeParameters.mIsNextLineFullyVisibleHeight = true;
1433 if( TextView::EllipsizeEnd == layoutParameters.mExceedPolicy )
1435 // Need to check if there is lines which doesn't fit in the height.
1437 ellipsizeParameters.mIsLineHeightFullyVisible = IsVisible( position,
1439 relayoutData.mTextViewSize,
1440 FULLY_VISIBLE_HEIGHT );
1442 ellipsizeParameters.mEllipsizeLine = ellipsizeParameters.mEllipsizeLine && ellipsizeParameters.mIsLineHeightFullyVisible;
1444 if( ellipsizeParameters.mIsLineHeightFullyVisible && !ellipsizeParameters.mEllipsizeLine )
1446 // Current line is not ellipsized.
1447 // Need to check if there is a next line and if it's not visible. If there is, current line needs to be ellipsized.
1448 Toolkit::TextView::LineLayoutInfoContainer::const_iterator nextLineInfoIt = lineInfoIt + 1;
1449 if( nextLineInfoIt != endLineInfoIt )
1451 // Retrives the position of the first character of the line and remove
1452 // the bearing offset to build to build the position of the line.
1453 const Toolkit::TextView::LineLayoutInfo& nextLineInfo( *nextLineInfoIt );
1454 const Toolkit::TextView::CharacterLayoutInfo& characterInfo = *( relayoutData.mCharacterLayoutInfoTable.begin() + nextLineInfo.mCharacterGlobalIndex );
1456 const float bearingOffset = ( ( lineInfo.mSize.height - lineInfo.mAscender ) - characterInfo.mDescender ) * relayoutData.mShrinkFactor;
1458 const Vector3 position( characterInfo.mPosition.x,
1459 characterInfo.mPosition.y + bearingOffset,
1460 characterInfo.mPosition.z );
1462 ellipsizeParameters.mIsNextLineFullyVisibleHeight = IsVisible( position,
1464 relayoutData.mTextViewSize,
1465 FULLY_VISIBLE_HEIGHT );
1467 // If the next line is not visible, current line have to be ellipsized.
1468 ellipsizeParameters.mEllipsizeLine = !ellipsizeParameters.mIsNextLineFullyVisibleHeight;
1473 if( !ellipsizeParameters.mIsNextLineFullyVisibleHeight )
1475 ellipsizeParameters.mLineWidth = position.x + lineInfo.mSize.width - relayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo.mSize.width;
1478 // Sets the line descender.
1479 ellipsizeParameters.mLineDescender = lineInfo.mSize.height - lineInfo.mAscender;
1481 // At this point, ellipsizeLine distinguish if a piece of line have to be ellipsized or not.
1482 EllipsizeLine( layoutParameters, ellipsizeParameters, relayoutData );
1486 void UpdateVisibility( const TextView::LayoutParameters& layoutParameters,
1487 const TextView::VisualParameters& visualParameters,
1488 TextView::RelayoutData& relayoutData )
1490 switch( layoutParameters.mExceedPolicy )
1492 case TextView::FadeOriginal:
1493 case TextView::OriginalFade:
1494 case TextView::Fade:
1495 case TextView::SplitFade: // Fall through
1497 UpdateVisibilityForFade( layoutParameters,
1502 case TextView::EllipsizeEndOriginal:
1503 case TextView::EllipsizeEnd: // Fall through
1505 // Set first all characters to visible as UpdateVisibilityForEllipsize() doesn't traverse all of them.
1506 SetTextVisible( relayoutData );
1508 UpdateVisibilityForEllipsize( layoutParameters,
1515 SetTextVisible( relayoutData );
1521 void UpdateTextActorInfo( const TextView::VisualParameters& visualParameters,
1522 TextView::RelayoutData& relayoutData )
1524 CurrentTextActorInfo currentTextActorInfo;
1526 // Traverses the text-actor and layout info data structures.
1527 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
1528 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
1529 lineLayoutIt != endLineLayoutIt;
1532 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
1534 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(),
1535 endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
1536 groupLayoutIt != endGroupLayoutIt;
1539 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
1541 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(),
1542 endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
1543 wordLayoutIt != endWordLayoutIt;
1546 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
1548 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
1549 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
1550 characterLayoutIt != endCharacterLayoutIt;
1551 ++characterLayoutIt )
1553 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
1555 if( characterLayoutInfo.mIsColorGlyph )
1557 ImageActor imageActor = ImageActor::DownCast( characterLayoutInfo.mGlyphActor );
1559 if( characterLayoutInfo.mSetText )
1561 GlyphImage image = GlyphImage::New( characterLayoutInfo.mStyledText.mText[0] );
1565 imageActor.SetImage( image );
1567 characterLayoutInfo.mSetText = false;
1570 imageActor.SetPosition( Vector3( characterLayoutInfo.mPosition.x + characterLayoutInfo.mOffset.x,
1571 characterLayoutInfo.mPosition.y + characterLayoutInfo.mOffset.y,
1572 characterLayoutInfo.mPosition.z ) );
1573 imageActor.SetSize( characterLayoutInfo.mSize );
1575 // Sets the sort modifier value.
1576 imageActor.SetSortModifier( visualParameters.mSortModifier );
1580 TextActor textActor = TextActor::DownCast( characterLayoutInfo.mGlyphActor );
1583 // There is a new text-actor. Set text and everything to the previous one.
1584 if( currentTextActorInfo.textActor )
1586 currentTextActorInfo.textActor.SetText( currentTextActorInfo.text );
1587 currentTextActorInfo.textActor.SetPosition( currentTextActorInfo.position );
1588 currentTextActorInfo.textActor.SetSize( currentTextActorInfo.size );
1590 SetVisualParameters( currentTextActorInfo,
1593 lineLayoutInfo.mSize.height );
1596 currentTextActorInfo.text = characterLayoutInfo.mStyledText.mText;
1597 currentTextActorInfo.position = Vector3( characterLayoutInfo.mPosition.x + characterLayoutInfo.mOffset.x,
1598 characterLayoutInfo.mPosition.y + characterLayoutInfo.mOffset.y,
1599 characterLayoutInfo.mPosition.z );
1600 currentTextActorInfo.size = characterLayoutInfo.mSize * relayoutData.mShrinkFactor;
1602 currentTextActorInfo.color = characterLayoutInfo.mStyledText.mStyle.GetTextColor();
1603 currentTextActorInfo.color.a = characterLayoutInfo.mColorAlpha;
1605 currentTextActorInfo.gradientColor = characterLayoutInfo.mGradientColor;
1606 currentTextActorInfo.startPoint = characterLayoutInfo.mStartPoint;
1607 currentTextActorInfo.endPoint = characterLayoutInfo.mEndPoint;
1609 // Update the current text-actor.
1610 currentTextActorInfo.textActor = textActor;
1614 // If this character layout has no text-actor is because this character has the same style than previous one.
1615 // Add the character to the current text-actor and update the size.
1616 if( characterLayoutInfo.mIsVisible && ( TextViewProcessor::LineSeparator != wordLayoutInfo.mType ) )
1618 currentTextActorInfo.text.Append( characterLayoutInfo.mStyledText.mText );
1620 currentTextActorInfo.position.y = std::min( currentTextActorInfo.position.y, ( characterLayoutInfo.mPosition.y + characterLayoutInfo.mOffset.y ) );
1621 currentTextActorInfo.size.width += characterLayoutInfo.mSize.width * relayoutData.mShrinkFactor;
1622 currentTextActorInfo.size.height = std::max( currentTextActorInfo.size.height, characterLayoutInfo.mSize.height * relayoutData.mShrinkFactor );
1629 if( !currentTextActorInfo.text.IsEmpty() )
1631 if( currentTextActorInfo.textActor )
1633 currentTextActorInfo.textActor.SetText( currentTextActorInfo.text );
1634 currentTextActorInfo.textActor.SetPosition( currentTextActorInfo.position );
1635 currentTextActorInfo.textActor.SetSize( currentTextActorInfo.size );
1637 SetVisualParameters( currentTextActorInfo,
1640 lineLayoutInfo.mSize.height );
1643 } //end groups of words
1646 for( std::vector<RenderableActor>::iterator it = relayoutData.mEllipsizedGlyphActors.begin(),
1647 endIt = relayoutData.mEllipsizedGlyphActors.end();
1651 RenderableActor glyphActor = ( *it );
1653 glyphActor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1654 glyphActor.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
1656 // Sets the sort modifier value.
1657 glyphActor.SetSortModifier( visualParameters.mSortModifier );
1659 // Enables or disables the blending.
1660 glyphActor.SetBlendMode( !visualParameters.mSnapshotModeEnabled ? BlendingMode::ON : BlendingMode::OFF );
1664 void CalculateUnderlineInfo( TextView::RelayoutData& relayoutData, TextViewRelayout::TextUnderlineStatus& textUnderlineStatus )
1666 // Traverse the whole text to find all groups of consecutive underlined characters in the same laid-out line.
1668 // 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.
1669 // According with the layout option, one of this lines could be laid-out in more than one.
1671 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(), lineEndIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
1672 lineIt != lineEndIt;
1675 TextViewProcessor::LineLayoutInfo& line( *lineIt );
1677 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupIt = line.mWordGroupsLayoutInfo.begin(), groupEndIt = line.mWordGroupsLayoutInfo.end();
1678 groupIt != groupEndIt;
1681 TextViewProcessor::WordGroupLayoutInfo& group( *groupIt );
1683 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordIt = group.mWordsLayoutInfo.begin(), wordEndIt = group.mWordsLayoutInfo.end();
1684 wordIt != wordEndIt;
1687 TextViewProcessor::WordLayoutInfo& word( *wordIt );
1689 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterIt = word.mCharactersLayoutInfo.begin(), characterEndIt = word.mCharactersLayoutInfo.end();
1690 characterIt != characterEndIt;
1693 TextViewProcessor::CharacterLayoutInfo& characterGroup( *characterIt );
1695 // Check if current character is the first of a new laid-out line
1696 const bool isNewLine = ( textUnderlineStatus.mLineGlobalIndex < relayoutData.mLines.size() ) &&
1697 ( textUnderlineStatus.mCharacterGlobalIndex == ( *( relayoutData.mLines.begin() + textUnderlineStatus.mLineGlobalIndex ) ).mCharacterGlobalIndex );
1700 ++textUnderlineStatus.mLineGlobalIndex; // If it's a new line, point to the next one.
1703 if( characterGroup.mStyledText.mStyle.GetUnderline() )
1705 if( !textUnderlineStatus.mCurrentUnderlineStatus || // Current character is underlined but previous one it wasn't.
1706 isNewLine ) // Current character is underlined and is the first of current laid-out line.
1708 // Create a new underline info for the current underlined characters.
1709 UnderlineInfo underlineInfo;
1710 underlineInfo.mMaxHeight = characterGroup.mSize.height;
1711 underlineInfo.mMaxThickness = characterGroup.mUnderlineThickness;
1712 underlineInfo.mPosition = characterGroup.mUnderlinePosition;
1714 textUnderlineStatus.mUnderlineInfo.push_back( underlineInfo );
1716 textUnderlineStatus.mCurrentUnderlineStatus = true; // Set the current text is underlined.
1720 // Retrieve last underline info and update it if current underline thickness is bigger.
1721 UnderlineInfo& underlineInfo( *( textUnderlineStatus.mUnderlineInfo.end() - 1 ) );
1723 underlineInfo.mMaxHeight = std::max( underlineInfo.mMaxHeight, characterGroup.mSize.height );
1725 if( characterGroup.mUnderlineThickness > underlineInfo.mMaxThickness )
1727 underlineInfo.mMaxThickness = characterGroup.mUnderlineThickness;
1728 underlineInfo.mPosition = characterGroup.mUnderlinePosition;
1734 textUnderlineStatus.mCurrentUnderlineStatus = false;
1737 ++textUnderlineStatus.mCharacterGlobalIndex;
1738 } // end group of characters.
1740 } // end group of words.
1744 void SetUnderlineInfo( TextView::RelayoutData& relayoutData )
1746 // 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.
1747 TextViewRelayout::TextUnderlineStatus textUnderlineStatus;
1749 // Traverse the whole text to find all groups of consecutive underlined characters in the same laid-out line.
1750 CalculateUnderlineInfo( relayoutData, textUnderlineStatus );
1752 if( textUnderlineStatus.mUnderlineInfo.empty() )
1754 // There is no underlined text. Just exit.
1758 // At this point textUnderlineStatus.mUnderlineInfo has for each group of consecutive underlined characters their maximum thickness, position and maximum height.
1759 // Traverse the whole text and set the previously stored underline info in the text style.
1761 std::vector<UnderlineInfo>::const_iterator underlineInfoIt = textUnderlineStatus.mUnderlineInfo.begin();
1762 std::vector<UnderlineInfo>::const_iterator underlineInfoEndIt = textUnderlineStatus.mUnderlineInfo.end();
1764 UnderlineInfo underlineInfo;
1766 if( underlineInfoIt < underlineInfoEndIt )
1768 underlineInfo = ( *underlineInfoIt );
1771 // Whether current text is underlined.
1772 textUnderlineStatus.mCurrentUnderlineStatus = false;
1773 textUnderlineStatus.mCharacterGlobalIndex = 0;
1774 textUnderlineStatus.mLineGlobalIndex = 0;
1776 float currentLineHeight = 0.f;
1777 float currentLineAscender = 0.f;
1779 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(), lineEndIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
1780 lineIt != lineEndIt;
1783 TextViewProcessor::LineLayoutInfo& line( *lineIt );
1785 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupIt = line.mWordGroupsLayoutInfo.begin(), groupEndIt = line.mWordGroupsLayoutInfo.end();
1786 groupIt != groupEndIt;
1789 TextViewProcessor::WordGroupLayoutInfo& group( *groupIt );
1791 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordIt = group.mWordsLayoutInfo.begin(), wordEndIt = group.mWordsLayoutInfo.end();
1792 wordIt != wordEndIt;
1795 TextViewProcessor::WordLayoutInfo& word( *wordIt );
1797 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterIt = word.mCharactersLayoutInfo.begin(), characterEndIt = word.mCharactersLayoutInfo.end();
1798 characterIt != characterEndIt;
1801 TextViewProcessor::CharacterLayoutInfo& characterGroup( *characterIt );
1803 // Check if current character is the first of a new laid-out line
1805 bool isNewLine = false;
1807 if( textUnderlineStatus.mLineGlobalIndex < relayoutData.mLines.size() )
1809 const Toolkit::TextView::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mLines.begin() + textUnderlineStatus.mLineGlobalIndex ) );
1810 isNewLine = ( textUnderlineStatus.mCharacterGlobalIndex == lineLayoutInfo.mCharacterGlobalIndex );
1814 currentLineHeight = lineLayoutInfo.mSize.height;
1815 currentLineAscender = lineLayoutInfo.mAscender;
1816 ++textUnderlineStatus.mLineGlobalIndex; // If it's a new line, point to the next one.
1820 if( characterGroup.mStyledText.mStyle.GetUnderline() )
1822 if( textUnderlineStatus.mCurrentUnderlineStatus )
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.mCurrentUnderlineStatus = true;
1840 // Sets the underline's thickness.
1841 characterGroup.mStyledText.mStyle.SetUnderlineThickness( underlineInfo.mMaxThickness );
1843 // Before setting the position it needs to be adjusted to match the base line.
1844 const float bearingOffset = ( currentLineHeight - currentLineAscender ) - ( characterGroup.mSize.height - characterGroup.mAscender );
1845 const float positionOffset = ( underlineInfo.mMaxHeight - characterGroup.mSize.height ) - bearingOffset;
1847 // Sets the underline's position.
1848 characterGroup.mStyledText.mStyle.SetUnderlinePosition( underlineInfo.mPosition - positionOffset );
1850 // Mark the group of characters to be set the new style into the text-actor.
1851 characterGroup.mSetStyle = true;
1855 if( textUnderlineStatus.mCurrentUnderlineStatus )
1857 textUnderlineStatus.mCurrentUnderlineStatus = false;
1859 // Retrieves the thickness and position for the next piece of underlined text.
1860 if( underlineInfoIt < underlineInfoEndIt )
1863 if( underlineInfoIt < underlineInfoEndIt )
1865 underlineInfo = *underlineInfoIt;
1871 ++textUnderlineStatus.mCharacterGlobalIndex;
1872 } // end of group of characters.
1874 } // end of group of words.
1878 void RemoveGlyphActors( Actor textView,
1879 const std::vector<RenderableActor>& glyphActors )
1881 // Removes previously inserted renderable-actors.
1882 // The SplitByNewLineChar::Relayout(), SplitByWord::Relayout() and SplitByChar::Relayout() functions add
1883 // renderable-actors to the text-view. A handle to these renderable-actors are stored and passed to this function
1884 // in order to remove 'only' renderable-actors added by these functions.
1885 // Any other actor added by a programmer or application won't be removed.
1887 for( std::vector<RenderableActor>::const_reverse_iterator it = glyphActors.rbegin(), endIt = glyphActors.rend(); it != endIt; ++it )
1889 textView.Remove( *it );
1893 void InsertToTextView( const TextView::RelayoutOperationMask relayoutOperationMask,
1895 TextView::RelayoutData& relayoutData )
1897 const bool insertToTextView = relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW;
1898 const bool insertToTextActorList = relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST;
1900 // Add text-actors to the text-view.
1902 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
1903 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
1904 lineLayoutIt != endLineLayoutIt;
1907 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
1909 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(),
1910 endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
1911 groupLayoutIt != endGroupLayoutIt;
1914 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
1916 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(),
1917 endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
1918 wordLayoutIt != endWordLayoutIt;
1921 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
1923 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
1924 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
1925 characterLayoutIt != endCharacterLayoutIt;
1926 ++characterLayoutIt )
1928 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
1930 if( characterLayoutInfo.mIsVisible && characterLayoutInfo.mGlyphActor ) // White spaces and '\n' characters doesn't have a text-actor.
1932 //Add to the text-view.
1933 if( insertToTextView )
1935 textView.Add( characterLayoutInfo.mGlyphActor );
1937 if( insertToTextActorList )
1939 relayoutData.mGlyphActors.push_back( characterLayoutInfo.mGlyphActor );
1942 } // end group of character
1944 } // end group of words
1947 for( std::vector<RenderableActor>::iterator it = relayoutData.mEllipsizedGlyphActors.begin(),
1948 endIt = relayoutData.mEllipsizedGlyphActors.end();
1952 RenderableActor glyphActor = ( *it );
1954 //Add to the text-view.
1955 if( insertToTextView )
1957 textView.Add( glyphActor );
1959 if( insertToTextActorList )
1961 relayoutData.mGlyphActors.push_back( glyphActor );
1964 relayoutData.mEllipsizedGlyphActors.clear();
1967 RenderableActor CreateGlyphActor( const Text& text, const TextStyle& style, TextActorCache& cache )
1969 TextActor textActor = cache.RetrieveTextActor();
1973 // Update the text-actor.
1974 textActor.SetText( text );
1975 textActor.SetTextStyle( style );
1979 // The text-actor cache is empty. Create a new one.
1980 textActor = TextActor::New( text, style, false, true );
1986 } // namespace TextViewRelayout
1988 } // namespace Internal
1990 } // namespace Toolkit