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 "split-by-word-policies.h"
25 #include "relayout-utilities.h"
26 #include "text-view-processor.h"
27 #include <dali/integration-api/debug.h>
44 Vector3 OriginalPosition( const TextViewRelayout::RelayoutParameters& relayoutParameters,
45 const TextView::LayoutParameters& layoutParameters,
46 TextView::RelayoutData& relayoutData )
48 const float wordOffset = ( relayoutParameters.mIsFirstCharacter ? 0.f : relayoutParameters.mPositionOffset.x );
49 const float previousPositionY = ( relayoutParameters.mIsFirstCharacter ? 0.f : relayoutParameters.mPositionOffset.y );
51 if( relayoutParameters.mIsNewLine ||
52 relayoutParameters.mIsFirstCharacter ||
53 ( relayoutParameters.mIsFirstCharacterOfWord && ( wordOffset + relayoutParameters.mWordSize.width > relayoutData.mTextViewSize.width ) ) )
55 if( !relayoutParameters.mIsNewLine &&
56 ( relayoutParameters.mIsWhiteSpace || relayoutParameters.mIsNewLineCharacter ) )
58 // Current character is a white space. Don't want to move a white space to the next line.
59 // These white spaces are placed just in the edge.
60 return Vector3( relayoutData.mTextViewSize.width - relayoutParameters.mWordSize.width, relayoutParameters.mPositionOffset.y, 0.f );
64 // Calculates the length of the portion of the line which doesn't exceed the text-view's width and the max character height for the current line.
65 TextViewRelayout::SubLineLayoutInfo subLineInfo;
66 subLineInfo.mLineLength = 0.f;
67 subLineInfo.mMaxCharHeight = 0.f;
68 subLineInfo.mMaxAscender = 0.f;
69 const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + relayoutParameters.mIndices.mLineIndex ) );
71 TextViewRelayout::CalculateSubLineLayout( relayoutData.mTextViewSize.width,
72 relayoutParameters.mIndices,
74 TextViewRelayout::WrapByWord,
78 if( subLineInfo.mLineLength < Math::MACHINE_EPSILON_1000 )
80 // It may mean there is a word which is actually longer than the width of the text-view.
81 // In that case the length of this word is needed.
82 if( !lineLayoutInfo.mWordGroupsLayoutInfo.empty() )
84 const TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *( lineLayoutInfo.mWordGroupsLayoutInfo.begin() + relayoutParameters.mIndices.mGroupIndex ) );
85 if( !wordGroupLayoutInfo.mWordsLayoutInfo.empty() )
87 const TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *( wordGroupLayoutInfo.mWordsLayoutInfo.begin() + relayoutParameters.mIndices.mWordIndex ) );
88 subLineInfo.mLineLength = wordLayoutInfo.mSize.width;
93 // Stores some info to calculate the line justification in a post-process.
94 TextView::LineJustificationInfo justificationInfo;
96 justificationInfo.mIndices = relayoutParameters.mIndices;
97 justificationInfo.mLineLength = subLineInfo.mLineLength;
99 relayoutData.mLineJustificationInfo.push_back( justificationInfo );
101 Toolkit::TextView::LineLayoutInfo lineInfo;
102 lineInfo.mCharacterGlobalIndex = relayoutParameters.mCharacterGlobalIndex; // Index to the first character of the next line.
103 lineInfo.mSize = Size( subLineInfo.mLineLength, subLineInfo.mMaxCharHeight ); // Size of this piece of line.
104 lineInfo.mAscender = subLineInfo.mMaxAscender; // Ascender of this piece of line.
105 relayoutData.mLines.push_back( lineInfo );
107 return Vector3( 0.f, previousPositionY + subLineInfo.mMaxCharHeight + layoutParameters.mLineHeightOffset, 0.f );
112 return Vector3( wordOffset, previousPositionY, 0.f );
117 * Calculates character position.
118 * @param[in] relayoutParameters Temporary layout parameters (previous size, previous position, ... )
119 * @param[in] layoutParameters The layout parameters.
120 * @param[in] relayoutData The text-view's data structures.
121 * @return The character's position.
123 Vector3 SplitWhenExceedPosition( const TextViewRelayout::RelayoutParameters& relayoutParameters,
124 const TextView::LayoutParameters& layoutParameters,
125 TextView::RelayoutData& relayoutData )
127 const float wordOffset = ( relayoutParameters.mIsFirstCharacter ? 0.f : relayoutParameters.mPositionOffset.x );
128 const float previousPositionY = ( relayoutParameters.mIsFirstCharacter ? 0.f : relayoutParameters.mPositionOffset.y );
130 if( ( relayoutParameters.mIsNewLine || relayoutParameters.mIsFirstCharacter ) ||
131 ( relayoutParameters.mIsFirstCharacterOfWord && ( wordOffset + relayoutParameters.mWordSize.width > relayoutData.mTextViewSize.width ) ) ||
132 ( wordOffset + relayoutParameters.mCharacterSize.width > relayoutData.mTextViewSize.width ) )
134 if( !relayoutParameters.mIsNewLine &&
135 ( relayoutParameters.mIsWhiteSpace || relayoutParameters.mIsNewLineCharacter ) )
137 // Current character is a white space. Don't want to move a white space to the next line.
138 // These white spaces are placed just in the edge.
139 return Vector3( relayoutData.mTextViewSize.width - relayoutParameters.mWordSize.width, relayoutParameters.mPositionOffset.y, 0.f );
143 // Calculates the line length and the max character height for the current line.
144 TextViewRelayout::SubLineLayoutInfo subLineInfo;
145 subLineInfo.mLineLength = 0.f;
146 subLineInfo.mMaxCharHeight = 0.f;
147 subLineInfo.mMaxAscender = 0.f;
148 const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + relayoutParameters.mIndices.mLineIndex ) );
150 TextViewRelayout::CalculateSubLineLayout( relayoutData.mTextViewSize.width,
151 relayoutParameters.mIndices,
153 TextViewRelayout::WrapByWordAndSplit,
154 1.f, // Shrink factor.
157 // Stores some info to calculate the line justification in a post-process.
158 TextView::LineJustificationInfo justificationInfo;
160 justificationInfo.mIndices = relayoutParameters.mIndices;
161 justificationInfo.mLineLength = subLineInfo.mLineLength;
163 relayoutData.mLineJustificationInfo.push_back( justificationInfo );
165 Toolkit::TextView::LineLayoutInfo lineInfo;
166 lineInfo.mCharacterGlobalIndex = relayoutParameters.mCharacterGlobalIndex; // Index to the first character of the next line.
167 lineInfo.mSize = Size( subLineInfo.mLineLength, subLineInfo.mMaxCharHeight ); // Size of this piece of line.
168 lineInfo.mAscender = subLineInfo.mMaxAscender; // Ascender of this piece of line.
169 relayoutData.mLines.push_back( lineInfo );
171 return Vector3( 0.f, previousPositionY + subLineInfo.mMaxCharHeight + layoutParameters.mLineHeightOffset, 0.f );
176 return Vector3( wordOffset, previousPositionY, 0.f );
181 * Calculates character position.
182 * @param[in] relayoutParameters Temporary layout parameters (previous size, previous position, ... )
183 * @param[in] layoutParameters The layout parameters.
184 * @param[in] relayoutData The text-view's data structures.
185 * @return The character's position.
187 Vector3 ShrinkWidthWhenExceedPosition( const TextViewRelayout::RelayoutParameters& relayoutParameters,
188 const TextView::LayoutParameters& layoutParameters,
189 TextView::RelayoutData& relayoutData )
191 const float wordOffset = ( relayoutParameters.mIsFirstCharacter ? 0.f : relayoutParameters.mPositionOffset.x );
192 const float previousPositionY = ( relayoutParameters.mIsFirstCharacter ? 0.f : relayoutParameters.mPositionOffset.y );
193 const Size wordSize = relayoutParameters.mWordSize * relayoutData.mShrinkFactor;
195 if( ( relayoutParameters.mIsNewLine || relayoutParameters.mIsFirstCharacter ) || // isNewLine is true when '\n' is found.
196 ( relayoutParameters.mIsFirstCharacterOfWord && ( wordOffset + wordSize.width > relayoutData.mTextViewSize.width ) ) ) // The word doesn't fit in the parent width.
198 if( !relayoutParameters.mIsNewLine &&
199 ( relayoutParameters.mIsWhiteSpace || relayoutParameters.mIsNewLineCharacter ) )
201 // Current character is a white space. Don't want to move a white space to the next line.
202 // These white spaces are placed just in the edge.
203 return Vector3( relayoutData.mTextViewSize.width - relayoutParameters.mWordSize.width, relayoutParameters.mPositionOffset.y, 0.f );
207 // Calculates the line length and the max character height for the current line.
208 TextViewRelayout::SubLineLayoutInfo subLineInfo;
209 subLineInfo.mLineLength = 0.f;
210 subLineInfo.mMaxCharHeight = 0.f;
211 subLineInfo.mMaxAscender = 0.f;
212 const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + relayoutParameters.mIndices.mLineIndex ) );
214 TextViewRelayout::CalculateSubLineLayout( relayoutData.mTextViewSize.width,
215 relayoutParameters.mIndices,
217 TextViewRelayout::WrapByWord,
218 relayoutData.mShrinkFactor,
221 // Stores some info to calculate the line justification in a post-process.
222 TextView::LineJustificationInfo justificationInfo;
224 justificationInfo.mIndices = relayoutParameters.mIndices;
225 justificationInfo.mLineLength = subLineInfo.mLineLength;
227 relayoutData.mLineJustificationInfo.push_back( justificationInfo );
229 Toolkit::TextView::LineLayoutInfo lineInfo;
230 lineInfo.mCharacterGlobalIndex = relayoutParameters.mCharacterGlobalIndex; // Index to the first character of the next line.
231 lineInfo.mSize = Size( subLineInfo.mLineLength, subLineInfo.mMaxCharHeight ); // Size of this piece of line.
232 lineInfo.mAscender = subLineInfo.mMaxAscender; // Ascender of this piece of line.
233 relayoutData.mLines.push_back( lineInfo );
235 return Vector3( 0.f, previousPositionY + subLineInfo.mMaxCharHeight + layoutParameters.mLineHeightOffset * relayoutData.mShrinkFactor, 0.f );
240 return Vector3( wordOffset, previousPositionY, 0.f );
244 void CalculatePositionsForShrinkWhenExceed( TextView::RelayoutData& relayoutData,
245 const TextView::LayoutParameters& layoutParameters,
246 const float shrinkFactor,
247 float& newTextHeight )
249 const float parentWidth = relayoutData.mTextViewSize.width;
250 TextViewProcessor::TextLayoutInfo& textLayoutInfo = relayoutData.mTextLayoutInfo;
252 // Reset the text height. This value is returned in order to shrink further or not the text.
255 // Whether the first character is being processed.
256 bool isFirstChar = true;
258 // Stores the size of the previous character.
260 // Stores the position of the previous character.
261 Vector3 previousPosition;
263 // Reset the index of lines.
264 TextViewProcessor::TextInfoIndices indices;
266 // Whether the last character of the whole text is a new line char.
267 // This information is used to increase or not the height of the whole text by one line.
268 // Increase the whole text's height by one line is useful i.e. in TextInput to place the cursor
269 // after pressing 'Enter' in the last line.
270 bool isLastCharacterNewLineChar = false;
271 // Stores the height of the last character. This height used to be added to the whole text height if
272 // isLastCharacterNewLineChar is true.
273 float lastCharHeight = 0.f;
275 relayoutData.mLines.clear();
276 std::size_t characterGlobalIndex = 0;
278 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineIt = textLayoutInfo.mLinesLayoutInfo.begin(), lineEndIt = textLayoutInfo.mLinesLayoutInfo.end();
280 ++lineIt, ++indices.mLineIndex )
282 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineIt );
284 // The next character is in a new line.
285 bool isNewLine = true;
287 // Reset the index of groups of words.
288 indices.mGroupIndex = 0;
290 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(), groupEndIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
291 groupIt != groupEndIt;
292 ++groupIt, ++indices.mGroupIndex )
294 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupIt );
296 // Reset the index of words.
297 indices.mWordIndex = 0;
299 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(), wordEndIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
301 ++wordIt, ++indices.mWordIndex )
303 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordIt );
305 // Reset the index of the character.
306 indices.mCharacterIndex = 0;
308 // Whether current character is the first of the word.
309 bool isFirstCharOfWord = true;
310 const float wordOffset = previousPosition.x + previousSize.width;
312 isLastCharacterNewLineChar = ( TextViewProcessor::LineSeparator == wordLayoutInfo.mType );
314 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator charIt = wordLayoutInfo.mCharactersLayoutInfo.begin(), charEndIt = wordLayoutInfo.mCharactersLayoutInfo.end();
316 ++charIt, ++indices.mCharacterIndex )
318 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *charIt );
319 lastCharHeight = characterLayoutInfo.mSize.height * shrinkFactor;
321 const float previousPositionY = isFirstChar ? 0.f : previousPosition.y;
323 if( ( isNewLine || isFirstChar ) ||
324 ( isFirstCharOfWord && ( wordOffset + wordLayoutInfo.mSize.width * shrinkFactor > parentWidth ) ) )
327 const float minWidth = std::min( parentWidth, textLayoutInfo.mWholeTextSize.width );
329 // Calculates the line length and the max character height for the current line.
330 TextViewRelayout::SubLineLayoutInfo subLineInfo;
331 subLineInfo.mLineLength = 0.f;
332 subLineInfo.mMaxCharHeight = 0.f;
333 subLineInfo.mMaxAscender = 0.f;
334 TextViewRelayout::CalculateSubLineLayout( minWidth,
337 TextViewRelayout::WrapByWord,
341 float justificationOffset = TextViewRelayout::CalculateJustificationOffset( layoutParameters.mLineJustification, minWidth, subLineInfo.mLineLength );
343 characterLayoutInfo.mPosition = Vector3( justificationOffset, previousPositionY + subLineInfo.mMaxCharHeight + layoutParameters.mLineHeightOffset * shrinkFactor, 0.f );
345 newTextHeight += subLineInfo.mMaxCharHeight + layoutParameters.mLineHeightOffset * shrinkFactor;
347 Toolkit::TextView::LineLayoutInfo lineInfo;
348 lineInfo.mCharacterGlobalIndex = characterGlobalIndex; // Index to the first character of the next line.
349 lineInfo.mSize = Size( subLineInfo.mLineLength, subLineInfo.mMaxCharHeight ); // Size of this piece of line.
350 lineInfo.mAscender = subLineInfo.mMaxAscender; // Ascender of this piece of line.
351 relayoutData.mLines.push_back( lineInfo );
355 characterLayoutInfo.mPosition = previousPosition + Vector3( previousSize.width, 0.f, 0.f );
358 // Get last line info and calculate the bearing.
359 const Toolkit::TextView::LineLayoutInfo& lineInfo( *( relayoutData.mLines.end() - 1 ) );
360 const float bearingOffset = ( ( lineInfo.mSize.height - lineInfo.mAscender ) - ( characterLayoutInfo.mSize.height - characterLayoutInfo.mAscender ) ) * shrinkFactor;
362 previousSize = characterLayoutInfo.mSize * shrinkFactor;
363 previousPosition = characterLayoutInfo.mPosition;
364 characterLayoutInfo.mPosition.y -= bearingOffset;
365 isFirstCharOfWord = false;
368 ++characterGlobalIndex;
374 if( isLastCharacterNewLineChar )
376 newTextHeight += lastCharHeight + layoutParameters.mLineHeightOffset * shrinkFactor;
380 float RelayoutForShrinkToFit( TextView::RelayoutData& relayoutData,
381 const TextView::LayoutParameters& layoutParameters )
383 const Size& textViewSize = relayoutData.mTextViewSize;
384 TextViewProcessor::TextLayoutInfo& textLayoutInfo = relayoutData.mTextLayoutInfo;
386 // First step is assure the longest word fits in the text view width.
387 float shrinkFactor = ( textLayoutInfo.mMaxWordWidth > textViewSize.width ? textViewSize.width / textLayoutInfo.mMaxWordWidth : 1.f );
389 // Out parameter. Will store the new text height after relayout the text.
390 float newTextHeight = 0.f;
392 // Relayout the text for the given character's sizes.
393 CalculatePositionsForShrinkWhenExceed( relayoutData,
398 if( newTextHeight > textViewSize.height )
400 // After relayouting, the text exceeds the text view height.
401 // Find a new scale factor to fit all the text in the text view size is needed.
403 // The next algorithm does some iterations to calculate an acceptable scale factor.
404 // Some magic numbers are defined.
406 const float MIN_RATIO( 0.90f ); // The algorithm finishes if the ratio
407 const float MAX_RATIO( 1.00f ); // new_text_height / text_view_height is between this two values
408 const unsigned int MAX_ITERATIONS( 8 ); // or max_iteration is reached.
410 float ratio = newTextHeight / textViewSize.height;
412 float maxScaleFactor = shrinkFactor; // bigger scale factors than maxScaleFactor will produce a too big text.
413 float minScaleFactor = shrinkFactor * ( textViewSize.height / newTextHeight ); // smaller scale factors than minScaleFactor will produce a too small text.
415 for( unsigned int iterations = 0; ( ( MIN_RATIO > ratio ) || ( ratio > MAX_RATIO ) ) && ( iterations < MAX_ITERATIONS ); ++iterations )
417 // Calculates the new scale factor.
418 // The new scale factor is always between the min and max scale factors.
419 // If ratio < 1 it means the text is too small and a bigger scale factor is needed. In this case the algorithm selects a new scale factor close to
420 // minScaleFactor. Alternatively if the text is too big a new scale factor close to maxScaleFactor is selected.
421 // This allows the text shrink or grow smoothly.
422 shrinkFactor = minScaleFactor + ( ratio < 1.f ? 0.4f : 0.6f ) * ( maxScaleFactor - minScaleFactor );
424 CalculatePositionsForShrinkWhenExceed( relayoutData, // Relayout the text for the given character's sizes.
429 // Calculates the new text size ratio. It allows update the min and max scale factors.
430 // If the ratio is not good enough a new scale factor between min and max could be used in next iteration.
431 ratio = newTextHeight / textViewSize.height;
434 minScaleFactor = shrinkFactor;
438 maxScaleFactor = shrinkFactor;
442 if( ratio > MAX_RATIO )
444 // The algorithm didn't find an acceptable scale factor.
445 // In that case the text is shrunk to fit in the boundaries of the text view actor.
446 shrinkFactor = minScaleFactor;
448 CalculatePositionsForShrinkWhenExceed( relayoutData,
458 void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameters,
459 TextView::RelayoutData& relayoutData )
461 TextViewRelayout::RelayoutParameters relayoutParameters;
464 relayoutData.mCharacterLayoutInfoTable.clear();
465 relayoutData.mLines.clear();
466 relayoutData.mTextSizeForRelayoutOption = Size();
468 // Calculates the text size for split by char.
469 Vector4 minMaxXY( std::numeric_limits<float>::max(),
470 std::numeric_limits<float>::max(),
471 std::numeric_limits<float>::min(),
472 std::numeric_limits<float>::min() );
474 relayoutData.mShrinkFactor = 1.f; // Shrink factor used when the exceed policy contains ShrinkToFit
476 if( TextView::Shrink== layoutParameters.mExceedPolicy )
478 // Relays-out the text for the shrink to fit policy.
479 relayoutData.mShrinkFactor = RelayoutForShrinkToFit( relayoutData, layoutParameters );
481 else if( TextView::ShrinkOriginal == layoutParameters.mExceedPolicy )
483 relayoutData.mShrinkFactor = ( relayoutData.mTextLayoutInfo.mMaxWordWidth > relayoutData.mTextViewSize.width ? relayoutData.mTextViewSize.width / relayoutData.mTextLayoutInfo.mMaxWordWidth : 1.f );
486 relayoutParameters.mPositionOffset = Vector3::ZERO;
487 relayoutParameters.mIsFirstCharacter = true;
488 relayoutParameters.mIndices.mLineIndex = 0;
489 relayoutParameters.mCharacterGlobalIndex = 0;
491 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
492 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
493 lineLayoutIt != endLineLayoutIt;
494 ++lineLayoutIt, ++relayoutParameters.mIndices.mLineIndex )
496 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
498 relayoutParameters.mIsNewLine = true;
499 relayoutParameters.mLineSize = lineLayoutInfo.mSize;
500 relayoutParameters.mIndices.mGroupIndex = 0;
502 for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(),
503 endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
504 groupLayoutIt != endGroupLayoutIt;
505 ++groupLayoutIt, ++relayoutParameters.mIndices.mGroupIndex )
507 TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
509 relayoutParameters.mIndices.mWordIndex = 0;
511 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(),
512 endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
513 wordLayoutIt != endWordLayoutIt;
514 ++wordLayoutIt, ++relayoutParameters.mIndices.mWordIndex )
516 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
517 relayoutParameters.mIsWhiteSpace = TextViewProcessor::WordSeparator == wordLayoutInfo.mType;
518 relayoutParameters.mIsNewLineCharacter = TextViewProcessor::LineSeparator == wordLayoutInfo.mType;
520 relayoutParameters.mIsFirstCharacterOfWord = true;
521 relayoutParameters.mWordSize = wordLayoutInfo.mSize;
522 relayoutParameters.mIndices.mCharacterIndex = 0;
524 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
525 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
526 ( characterLayoutIt != endCharacterLayoutIt );
527 ++characterLayoutIt, ++relayoutParameters.mIndices.mCharacterIndex )
529 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
531 relayoutParameters.mCharacterSize = characterLayoutInfo.mSize;
533 switch( layoutParameters.mExceedPolicy )
535 case TextView::OriginalShrink:
536 case TextView::SplitShrink:
537 case TextView::ShrinkFade:
539 DALI_LOG_WARNING( "SplitByWord::CalculateSizeAndPosition() policy not implemented.\n" );
542 case TextView::Original:
543 case TextView::OriginalFade:
544 case TextView::FadeOriginal:
546 case TextView::EllipsizeEndOriginal:
547 case TextView::EllipsizeEnd: // Fall Through
549 characterLayoutInfo.mPosition = OriginalPosition( relayoutParameters,
553 relayoutParameters.mPositionOffset = characterLayoutInfo.mPosition + Vector3( characterLayoutInfo.mSize.width, 0.f, 0.f );
556 case TextView::SplitOriginal:
558 characterLayoutInfo.mPosition = SplitWhenExceedPosition( relayoutParameters,
562 relayoutParameters.mPositionOffset = characterLayoutInfo.mPosition + Vector3( characterLayoutInfo.mSize.width, 0.f, 0.f );
565 case TextView::SplitFade:
567 characterLayoutInfo.mPosition = SplitWhenExceedPosition( relayoutParameters,
571 relayoutParameters.mPositionOffset = characterLayoutInfo.mPosition + Vector3( characterLayoutInfo.mSize.width, 0.f, 0.f );
574 case TextView::ShrinkOriginal:
576 characterLayoutInfo.mPosition = ShrinkWidthWhenExceedPosition( relayoutParameters,
580 relayoutParameters.mPositionOffset = characterLayoutInfo.mPosition + Vector3( characterLayoutInfo.mSize.width * relayoutData.mShrinkFactor, 0.f, 0.f );
583 case TextView::Shrink:
585 // Does nothing. All the job has been done in the RelayoutForShrinkToFit() function.
590 DALI_LOG_WARNING( "SplitByWord::CalculateSizeAndPosition() policy combination not possible.\n" );
594 // Get last line info and calculate the bearing (used to align glyphs with the baseline).
595 if( TextView::Shrink != layoutParameters.mExceedPolicy )
597 TextViewRelayout::CalculateBearing( characterLayoutInfo, relayoutData );
600 // updates min and max position to calculate the text size for split by word.
601 TextViewRelayout::UpdateLayoutInfoTable( minMaxXY,
608 ++relayoutParameters.mCharacterGlobalIndex;
609 relayoutParameters.mIsFirstCharacter = false;
610 relayoutParameters.mIsFirstCharacterOfWord = false;
611 relayoutParameters.mIsNewLine = false;
614 } // end group of words
617 if( relayoutData.mCharacterLayoutInfoTable.empty() )
619 relayoutData.mTextSizeForRelayoutOption = Size();
623 relayoutData.mTextSizeForRelayoutOption.width = minMaxXY.z - minMaxXY.x;
624 relayoutData.mTextSizeForRelayoutOption.height = minMaxXY.w - minMaxXY.y;
627 // Check if the last character is a new line character. In that case the height should be added.
628 if( !relayoutData.mTextLayoutInfo.mLinesLayoutInfo.empty() )
630 const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1 ) );
632 if( lineLayoutInfo.mWordGroupsLayoutInfo.empty() ) // if it's empty, it means the last character is a new line character.
634 relayoutData.mTextSizeForRelayoutOption.height += lineLayoutInfo.mSize.height * relayoutData.mShrinkFactor;
641 void Relayout( Actor textView,
642 TextView::RelayoutOperationMask relayoutOperationMask,
643 const TextView::LayoutParameters& layoutParameters,
644 const TextView::VisualParameters& visualParameters,
645 TextView::RelayoutData& relayoutData )
647 if( relayoutOperationMask & TextView::RELAYOUT_SIZE_POSITION )
649 relayoutData.mLineJustificationInfo.clear();
650 CalculateSizeAndPosition( layoutParameters,
653 TextViewRelayout::SetUnderlineInfo( relayoutData );
656 if( relayoutOperationMask & TextView::RELAYOUT_ALIGNMENT )
658 TextViewRelayout::UpdateAlignment( layoutParameters,
662 if( relayoutOperationMask & TextView::RELAYOUT_VISIBILITY )
664 TextViewRelayout::UpdateVisibility( layoutParameters,
669 if( relayoutOperationMask & TextView::RELAYOUT_INITIALIZE_TEXT_ACTORS )
671 TextViewProcessor::InitializeTextActorInfo( relayoutData );
674 if( relayoutOperationMask & TextView::RELAYOUT_TEXT_ACTOR_UPDATE )
676 TextViewRelayout::UpdateTextActorInfo( visualParameters,
680 if( ( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW ) ||
681 ( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ) )
683 TextViewRelayout::InsertToTextView( relayoutOperationMask,
689 } // namespace SplitByWord
691 } // namespace Internal
693 } // namespace Toolkit