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 <dali-toolkit/internal/controls/text-view/split-by-word-policies.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali-toolkit/internal/controls/text-view/relayout-utilities.h>
24 #include <dali-toolkit/internal/controls/text-view/text-view-processor.h>
41 Vector3 OriginalPosition( const TextViewRelayout::RelayoutParameters& relayoutParameters,
42 const TextView::LayoutParameters& layoutParameters,
43 TextView::RelayoutData& relayoutData )
45 const float wordOffset = ( relayoutParameters.mIsFirstCharacter ? 0.f : relayoutParameters.mPositionOffset.x );
46 const float previousPositionY = ( relayoutParameters.mIsFirstCharacter ? 0.f : relayoutParameters.mPositionOffset.y );
48 if( relayoutParameters.mIsNewLine ||
49 relayoutParameters.mIsFirstCharacter ||
50 ( relayoutParameters.mIsFirstCharacterOfWord && ( wordOffset + relayoutParameters.mWordSize.width > relayoutData.mTextViewSize.width ) ) )
52 if( !relayoutParameters.mIsNewLine &&
53 ( relayoutParameters.mIsWhiteSpace || relayoutParameters.mIsNewLineCharacter ) )
55 // Current character is a white space. Don't want to move a white space to the next line.
56 // These white spaces are placed just in the edge.
57 return Vector3( relayoutData.mTextViewSize.width - relayoutParameters.mWordSize.width, relayoutParameters.mPositionOffset.y, 0.f );
61 // 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.
62 TextViewRelayout::SubLineLayoutInfo subLineInfo;
63 subLineInfo.mLineLength = 0.f;
64 subLineInfo.mMaxCharHeight = 0.f;
65 subLineInfo.mMaxAscender = 0.f;
66 const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + relayoutParameters.mIndices.mLineIndex ) );
68 TextViewRelayout::CalculateSubLineLayout( relayoutData.mTextViewSize.width,
69 relayoutParameters.mIndices,
71 TextViewRelayout::WrapByWord,
75 if( subLineInfo.mLineLength < Math::MACHINE_EPSILON_1000 )
77 // It may mean there is a word which is actually longer than the width of the text-view.
78 // In that case the length of this word is needed.
79 if( !lineLayoutInfo.mWordsLayoutInfo.empty() )
81 const TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *( lineLayoutInfo.mWordsLayoutInfo.begin() + relayoutParameters.mIndices.mWordIndex ) );
82 subLineInfo.mLineLength = wordLayoutInfo.mSize.width;
86 // Stores some info to calculate the line justification in a post-process.
87 TextView::LineJustificationInfo justificationInfo;
89 justificationInfo.mIndices = relayoutParameters.mIndices;
90 justificationInfo.mLineLength = subLineInfo.mLineLength;
92 relayoutData.mLineJustificationInfo.push_back( justificationInfo );
94 Toolkit::TextView::LineLayoutInfo lineInfo;
95 lineInfo.mCharacterGlobalIndex = relayoutParameters.mCharacterGlobalIndex; // Index to the first character of the next line.
96 lineInfo.mSize = Size( subLineInfo.mLineLength, subLineInfo.mMaxCharHeight ); // Size of this piece of line.
97 lineInfo.mAscender = subLineInfo.mMaxAscender; // Ascender of this piece of line.
98 relayoutData.mLines.push_back( lineInfo );
100 return Vector3( 0.f, previousPositionY + subLineInfo.mMaxCharHeight + layoutParameters.mLineHeightOffset, 0.f );
105 return Vector3( wordOffset, previousPositionY, 0.f );
110 * Calculates character position.
111 * @param[in] relayoutParameters Temporary layout parameters (previous size, previous position, ... )
112 * @param[in] layoutParameters The layout parameters.
113 * @param[in] relayoutData The text-view's data structures.
114 * @return The character's position.
116 Vector3 SplitWhenExceedPosition( const TextViewRelayout::RelayoutParameters& relayoutParameters,
117 const TextView::LayoutParameters& layoutParameters,
118 TextView::RelayoutData& relayoutData )
120 const float wordOffset = ( relayoutParameters.mIsFirstCharacter ? 0.f : relayoutParameters.mPositionOffset.x );
121 const float previousPositionY = ( relayoutParameters.mIsFirstCharacter ? 0.f : relayoutParameters.mPositionOffset.y );
123 if( ( relayoutParameters.mIsNewLine || relayoutParameters.mIsFirstCharacter ) ||
124 ( relayoutParameters.mIsFirstCharacterOfWord && ( wordOffset + relayoutParameters.mWordSize.width > relayoutData.mTextViewSize.width ) ) ||
125 ( wordOffset + relayoutParameters.mCharacterSize.width > relayoutData.mTextViewSize.width ) )
127 if( !relayoutParameters.mIsNewLine &&
128 ( relayoutParameters.mIsWhiteSpace || relayoutParameters.mIsNewLineCharacter ) )
130 // Current character is a white space. Don't want to move a white space to the next line.
131 // These white spaces are placed just in the edge.
132 return Vector3( relayoutData.mTextViewSize.width - relayoutParameters.mWordSize.width, relayoutParameters.mPositionOffset.y, 0.f );
136 // Calculates the line length and the max character height for the current line.
137 TextViewRelayout::SubLineLayoutInfo subLineInfo;
138 subLineInfo.mLineLength = 0.f;
139 subLineInfo.mMaxCharHeight = 0.f;
140 subLineInfo.mMaxAscender = 0.f;
141 const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + relayoutParameters.mIndices.mLineIndex ) );
143 TextViewRelayout::CalculateSubLineLayout( relayoutData.mTextViewSize.width,
144 relayoutParameters.mIndices,
146 TextViewRelayout::WrapByWordAndSplit,
147 1.f, // Shrink factor.
150 // Stores some info to calculate the line justification in a post-process.
151 TextView::LineJustificationInfo justificationInfo;
153 justificationInfo.mIndices = relayoutParameters.mIndices;
154 justificationInfo.mLineLength = subLineInfo.mLineLength;
156 relayoutData.mLineJustificationInfo.push_back( justificationInfo );
158 Toolkit::TextView::LineLayoutInfo lineInfo;
159 lineInfo.mCharacterGlobalIndex = relayoutParameters.mCharacterGlobalIndex; // Index to the first character of the next line.
160 lineInfo.mSize = Size( subLineInfo.mLineLength, subLineInfo.mMaxCharHeight ); // Size of this piece of line.
161 lineInfo.mAscender = subLineInfo.mMaxAscender; // Ascender of this piece of line.
162 relayoutData.mLines.push_back( lineInfo );
164 return Vector3( 0.f, previousPositionY + subLineInfo.mMaxCharHeight + layoutParameters.mLineHeightOffset, 0.f );
169 return Vector3( wordOffset, previousPositionY, 0.f );
174 * Calculates character position.
175 * @param[in] relayoutParameters Temporary layout parameters (previous size, previous position, ... )
176 * @param[in] layoutParameters The layout parameters.
177 * @param[in] relayoutData The text-view's data structures.
178 * @return The character's position.
180 Vector3 ShrinkWidthWhenExceedPosition( const TextViewRelayout::RelayoutParameters& relayoutParameters,
181 const TextView::LayoutParameters& layoutParameters,
182 TextView::RelayoutData& relayoutData )
184 const float wordOffset = ( relayoutParameters.mIsFirstCharacter ? 0.f : relayoutParameters.mPositionOffset.x );
185 const float previousPositionY = ( relayoutParameters.mIsFirstCharacter ? 0.f : relayoutParameters.mPositionOffset.y );
186 const Size wordSize = relayoutParameters.mWordSize * relayoutData.mShrinkFactor;
188 if( ( relayoutParameters.mIsNewLine || relayoutParameters.mIsFirstCharacter ) || // isNewLine is true when '\n' is found.
189 ( relayoutParameters.mIsFirstCharacterOfWord && ( wordOffset + wordSize.width > relayoutData.mTextViewSize.width ) ) ) // The word doesn't fit in the parent width.
191 if( !relayoutParameters.mIsNewLine &&
192 ( relayoutParameters.mIsWhiteSpace || relayoutParameters.mIsNewLineCharacter ) )
194 // Current character is a white space. Don't want to move a white space to the next line.
195 // These white spaces are placed just in the edge.
196 return Vector3( relayoutData.mTextViewSize.width - relayoutParameters.mWordSize.width, relayoutParameters.mPositionOffset.y, 0.f );
200 // Calculates the line length and the max character height for the current line.
201 TextViewRelayout::SubLineLayoutInfo subLineInfo;
202 subLineInfo.mLineLength = 0.f;
203 subLineInfo.mMaxCharHeight = 0.f;
204 subLineInfo.mMaxAscender = 0.f;
205 const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + relayoutParameters.mIndices.mLineIndex ) );
207 TextViewRelayout::CalculateSubLineLayout( relayoutData.mTextViewSize.width,
208 relayoutParameters.mIndices,
210 TextViewRelayout::WrapByWord,
211 relayoutData.mShrinkFactor,
214 // Stores some info to calculate the line justification in a post-process.
215 TextView::LineJustificationInfo justificationInfo;
217 justificationInfo.mIndices = relayoutParameters.mIndices;
218 justificationInfo.mLineLength = subLineInfo.mLineLength;
220 relayoutData.mLineJustificationInfo.push_back( justificationInfo );
222 Toolkit::TextView::LineLayoutInfo lineInfo;
223 lineInfo.mCharacterGlobalIndex = relayoutParameters.mCharacterGlobalIndex; // Index to the first character of the next line.
224 lineInfo.mSize = Size( subLineInfo.mLineLength, subLineInfo.mMaxCharHeight ); // Size of this piece of line.
225 lineInfo.mAscender = subLineInfo.mMaxAscender; // Ascender of this piece of line.
226 relayoutData.mLines.push_back( lineInfo );
228 return Vector3( 0.f, previousPositionY + subLineInfo.mMaxCharHeight + layoutParameters.mLineHeightOffset * relayoutData.mShrinkFactor, 0.f );
233 return Vector3( wordOffset, previousPositionY, 0.f );
237 void CalculatePositionsForShrinkWhenExceed( TextView::RelayoutData& relayoutData,
238 const TextView::LayoutParameters& layoutParameters,
239 const float shrinkFactor,
240 float& newTextHeight )
242 const float parentWidth = relayoutData.mTextViewSize.width;
243 TextViewProcessor::TextLayoutInfo& textLayoutInfo = relayoutData.mTextLayoutInfo;
245 relayoutData.mLineJustificationInfo.clear();
247 // Reset the text height. This value is returned in order to shrink further or not the text.
250 // Whether the first character is being processed.
251 bool isFirstChar = true;
253 // Stores the size of the previous character.
255 // Stores the position of the previous character.
256 Vector3 previousPosition;
258 // Reset the index of lines.
259 TextViewProcessor::TextInfoIndices indices;
261 // Whether the last character of the whole text is a new line char.
262 // This information is used to increase or not the height of the whole text by one line.
263 // Increase the whole text's height by one line is useful i.e. in TextInput to place the cursor
264 // after pressing 'Enter' in the last line.
265 bool isLastCharacterNewLineChar = false;
266 // Stores the height of the last character. This height used to be added to the whole text height if
267 // isLastCharacterNewLineChar is true.
268 float lastCharHeight = 0.f;
270 relayoutData.mLines.clear();
271 std::size_t characterGlobalIndex = 0;
273 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineIt = textLayoutInfo.mLinesLayoutInfo.begin(), lineEndIt = textLayoutInfo.mLinesLayoutInfo.end();
275 ++lineIt, ++indices.mLineIndex )
277 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineIt );
279 // The next character is in a new line.
280 bool isNewLine = true;
283 // Reset the index of words.
284 indices.mWordIndex = 0;
286 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordIt = lineLayoutInfo.mWordsLayoutInfo.begin(), wordEndIt = lineLayoutInfo.mWordsLayoutInfo.end();
288 ++wordIt, ++indices.mWordIndex )
290 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordIt );
292 // Reset the index of the character.
293 indices.mCharacterIndex = 0;
295 // Whether current character is the first of the word.
296 bool isFirstCharOfWord = true;
297 const float wordOffset = previousPosition.x + previousSize.width;
299 isLastCharacterNewLineChar = ( TextViewProcessor::LineSeparator == wordLayoutInfo.mType );
301 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator charIt = wordLayoutInfo.mCharactersLayoutInfo.begin(), charEndIt = wordLayoutInfo.mCharactersLayoutInfo.end();
303 ++charIt, ++indices.mCharacterIndex )
305 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *charIt );
306 lastCharHeight = characterLayoutInfo.mSize.height * shrinkFactor;
308 const float previousPositionY = isFirstChar ? 0.f : previousPosition.y;
310 if( ( isNewLine || isFirstChar ) ||
311 ( isFirstCharOfWord && ( wordOffset + wordLayoutInfo.mSize.width * shrinkFactor > parentWidth ) ) )
315 // Calculates the line length and the max character height for the current line.
316 TextViewRelayout::SubLineLayoutInfo subLineInfo;
317 subLineInfo.mLineLength = 0.f;
318 subLineInfo.mMaxCharHeight = 0.f;
319 subLineInfo.mMaxAscender = 0.f;
320 TextViewRelayout::CalculateSubLineLayout( parentWidth,
323 TextViewRelayout::WrapByWord,
327 characterLayoutInfo.mPosition = Vector3( 0.f, previousPositionY + subLineInfo.mMaxCharHeight + layoutParameters.mLineHeightOffset * shrinkFactor, 0.f );
329 newTextHeight += subLineInfo.mMaxCharHeight + layoutParameters.mLineHeightOffset * shrinkFactor;
331 Toolkit::TextView::LineLayoutInfo lineInfo;
332 lineInfo.mCharacterGlobalIndex = characterGlobalIndex; // Index to the first character of the next line.
333 lineInfo.mSize = Size( subLineInfo.mLineLength, subLineInfo.mMaxCharHeight ); // Size of this piece of line.
334 lineInfo.mAscender = subLineInfo.mMaxAscender; // Ascender of this piece of line.
335 relayoutData.mLines.push_back( lineInfo );
338 // Stores some info to calculate the line justification in a post-process.
339 TextView::LineJustificationInfo justificationInfo;
341 justificationInfo.mIndices = indices;
342 justificationInfo.mLineLength = subLineInfo.mLineLength;
344 relayoutData.mLineJustificationInfo.push_back( justificationInfo );
348 characterLayoutInfo.mPosition = previousPosition + Vector3( previousSize.width, 0.f, 0.f );
351 // Get last line info and calculate the bearing.
352 const Toolkit::TextView::LineLayoutInfo& lineInfo( *( relayoutData.mLines.end() - 1 ) );
353 const float bearingOffset = ( ( lineInfo.mSize.height - lineInfo.mAscender ) - ( characterLayoutInfo.mSize.height - characterLayoutInfo.mAscender ) ) * shrinkFactor;
355 previousSize = characterLayoutInfo.mSize * shrinkFactor;
356 previousPosition = characterLayoutInfo.mPosition;
357 characterLayoutInfo.mPosition.y -= bearingOffset;
358 isFirstCharOfWord = false;
361 ++characterGlobalIndex;
366 if( isLastCharacterNewLineChar )
368 newTextHeight += lastCharHeight + layoutParameters.mLineHeightOffset * shrinkFactor;
372 float RelayoutForShrinkToFit( TextView::RelayoutData& relayoutData,
373 const TextView::LayoutParameters& layoutParameters )
375 const Size& textViewSize = relayoutData.mTextViewSize;
376 TextViewProcessor::TextLayoutInfo& textLayoutInfo = relayoutData.mTextLayoutInfo;
378 // First step is assure the longest word fits in the text view width.
379 float shrinkFactor = ( textLayoutInfo.mMaxWordWidth > textViewSize.width ? textViewSize.width / textLayoutInfo.mMaxWordWidth : 1.f );
381 // Out parameter. Will store the new text height after relayout the text.
382 float newTextHeight = 0.f;
384 // Relayout the text for the given character's sizes.
385 CalculatePositionsForShrinkWhenExceed( relayoutData,
390 if( newTextHeight > textViewSize.height )
392 // After relayouting, the text exceeds the text view height.
393 // Find a new scale factor to fit all the text in the text view size is needed.
395 // The next algorithm does some iterations to calculate an acceptable scale factor.
396 // Some magic numbers are defined.
398 const float MIN_RATIO( 0.90f ); // The algorithm finishes if the ratio
399 const float MAX_RATIO( 1.00f ); // new_text_height / text_view_height is between this two values
400 const unsigned int MAX_ITERATIONS( 8 ); // or max_iteration is reached.
402 float ratio = newTextHeight / textViewSize.height;
404 float maxScaleFactor = shrinkFactor; // bigger scale factors than maxScaleFactor will produce a too big text.
405 float minScaleFactor = shrinkFactor * ( textViewSize.height / newTextHeight ); // smaller scale factors than minScaleFactor will produce a too small text.
407 for( unsigned int iterations = 0; ( ( MIN_RATIO > ratio ) || ( ratio > MAX_RATIO ) ) && ( iterations < MAX_ITERATIONS ); ++iterations )
409 // Calculates the new scale factor.
410 // The new scale factor is always between the min and max scale factors.
411 // 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
412 // minScaleFactor. Alternatively if the text is too big a new scale factor close to maxScaleFactor is selected.
413 // This allows the text shrink or grow smoothly.
414 shrinkFactor = minScaleFactor + ( ratio < 1.f ? 0.4f : 0.6f ) * ( maxScaleFactor - minScaleFactor );
416 CalculatePositionsForShrinkWhenExceed( relayoutData, // Relayout the text for the given character's sizes.
421 // Calculates the new text size ratio. It allows update the min and max scale factors.
422 // If the ratio is not good enough a new scale factor between min and max could be used in next iteration.
423 ratio = newTextHeight / textViewSize.height;
426 minScaleFactor = shrinkFactor;
430 maxScaleFactor = shrinkFactor;
434 if( ratio > MAX_RATIO )
436 // The algorithm didn't find an acceptable scale factor.
437 // In that case the text is shrunk to fit in the boundaries of the text view actor.
438 shrinkFactor = minScaleFactor;
440 CalculatePositionsForShrinkWhenExceed( relayoutData,
450 void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameters,
451 TextView::RelayoutData& relayoutData )
453 TextViewRelayout::RelayoutParameters relayoutParameters;
456 relayoutData.mCharacterLayoutInfoTable.clear();
457 relayoutData.mLines.clear();
458 relayoutData.mTextSizeForRelayoutOption = Size();
460 // Calculates the text size for split by char.
461 Vector4 minMaxXY( std::numeric_limits<float>::max(),
462 std::numeric_limits<float>::max(),
463 std::numeric_limits<float>::min(),
464 std::numeric_limits<float>::min() );
466 relayoutData.mShrinkFactor = 1.f; // Shrink factor used when the exceed policy contains ShrinkToFit
468 if( TextView::Shrink== layoutParameters.mExceedPolicy )
470 // Relays-out the text for the shrink to fit policy.
471 relayoutData.mShrinkFactor = RelayoutForShrinkToFit( relayoutData, layoutParameters );
473 else if( TextView::ShrinkOriginal == layoutParameters.mExceedPolicy )
475 relayoutData.mShrinkFactor = ( relayoutData.mTextLayoutInfo.mMaxWordWidth > relayoutData.mTextViewSize.width ? relayoutData.mTextViewSize.width / relayoutData.mTextLayoutInfo.mMaxWordWidth : 1.f );
478 relayoutParameters.mPositionOffset = Vector3::ZERO;
479 relayoutParameters.mIsFirstCharacter = true;
480 relayoutParameters.mIndices.mLineIndex = 0;
481 relayoutParameters.mCharacterGlobalIndex = 0;
483 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
484 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
485 lineLayoutIt != endLineLayoutIt;
486 ++lineLayoutIt, ++relayoutParameters.mIndices.mLineIndex )
488 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
490 relayoutParameters.mIsNewLine = true;
491 relayoutParameters.mLineSize = lineLayoutInfo.mSize;
492 relayoutParameters.mIndices.mWordIndex = 0;
494 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.begin(),
495 endWordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.end();
496 wordLayoutIt != endWordLayoutIt;
497 ++wordLayoutIt, ++relayoutParameters.mIndices.mWordIndex )
499 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
500 relayoutParameters.mIsWhiteSpace = TextViewProcessor::WordSeparator == wordLayoutInfo.mType;
501 relayoutParameters.mIsNewLineCharacter = TextViewProcessor::LineSeparator == wordLayoutInfo.mType;
503 relayoutParameters.mIsFirstCharacterOfWord = true;
504 relayoutParameters.mWordSize = wordLayoutInfo.mSize;
505 relayoutParameters.mIndices.mCharacterIndex = 0;
507 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
508 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
509 ( characterLayoutIt != endCharacterLayoutIt );
510 ++characterLayoutIt, ++relayoutParameters.mIndices.mCharacterIndex )
512 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
514 relayoutParameters.mCharacterSize = characterLayoutInfo.mSize;
516 switch( layoutParameters.mExceedPolicy )
518 case TextView::OriginalShrink:
519 case TextView::SplitShrink:
520 case TextView::ShrinkFade:
522 DALI_LOG_WARNING( "SplitByWord::CalculateSizeAndPosition() policy not implemented.\n" );
525 case TextView::Original:
526 case TextView::OriginalFade:
527 case TextView::FadeOriginal:
529 case TextView::EllipsizeEndOriginal:
530 case TextView::EllipsizeEnd: // Fall Through
532 characterLayoutInfo.mPosition = OriginalPosition( relayoutParameters,
536 relayoutParameters.mPositionOffset = characterLayoutInfo.mPosition + Vector3( characterLayoutInfo.mSize.width, 0.f, 0.f );
539 case TextView::SplitOriginal:
540 case TextView::SplitFade:
541 case TextView::SplitEllipsizeEnd:
543 characterLayoutInfo.mPosition = SplitWhenExceedPosition( relayoutParameters,
547 relayoutParameters.mPositionOffset = characterLayoutInfo.mPosition + Vector3( characterLayoutInfo.mSize.width, 0.f, 0.f );
550 case TextView::ShrinkOriginal:
552 characterLayoutInfo.mPosition = ShrinkWidthWhenExceedPosition( relayoutParameters,
556 relayoutParameters.mPositionOffset = characterLayoutInfo.mPosition + Vector3( characterLayoutInfo.mSize.width * relayoutData.mShrinkFactor, 0.f, 0.f );
559 case TextView::Shrink:
561 // Does nothing. All the job has been done in the RelayoutForShrinkToFit() function.
566 DALI_LOG_WARNING( "SplitByWord::CalculateSizeAndPosition() policy combination not possible.\n" );
570 // Get last line info and calculate the bearing (used to align glyphs with the baseline).
571 if( TextView::Shrink != layoutParameters.mExceedPolicy )
573 TextViewRelayout::CalculateBearing( characterLayoutInfo, relayoutData );
576 // updates min and max position to calculate the text size for split by word.
577 TextViewRelayout::UpdateLayoutInfoTable( minMaxXY,
583 ++relayoutParameters.mCharacterGlobalIndex;
584 relayoutParameters.mIsFirstCharacter = false;
585 relayoutParameters.mIsFirstCharacterOfWord = false;
586 relayoutParameters.mIsNewLine = false;
591 if( relayoutData.mCharacterLayoutInfoTable.empty() )
593 relayoutData.mTextSizeForRelayoutOption = Size();
597 relayoutData.mTextSizeForRelayoutOption.width = minMaxXY.z - minMaxXY.x;
598 relayoutData.mTextSizeForRelayoutOption.height = minMaxXY.w - minMaxXY.y;
601 // Check if the last character is a new line character. In that case the height should be added.
602 if( !relayoutData.mTextLayoutInfo.mLinesLayoutInfo.empty() )
604 const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1 ) );
606 if( lineLayoutInfo.mWordsLayoutInfo.empty() ) // if it's empty, it means the last character is a new line character.
608 relayoutData.mTextSizeForRelayoutOption.height += lineLayoutInfo.mSize.height * relayoutData.mShrinkFactor;
615 void Relayout( Actor textView,
616 TextView::RelayoutOperationMask relayoutOperationMask,
617 const TextView::LayoutParameters& layoutParameters,
618 const TextView::VisualParameters& visualParameters,
619 TextView::RelayoutData& relayoutData )
621 if( relayoutOperationMask & TextView::RELAYOUT_SIZE_POSITION )
623 relayoutData.mLineJustificationInfo.clear();
624 CalculateSizeAndPosition( layoutParameters,
627 TextViewRelayout::SetUnderlineInfo( relayoutData );
630 if( relayoutOperationMask & TextView::RELAYOUT_ALIGNMENT )
632 TextViewRelayout::UpdateAlignment( layoutParameters,
636 if( relayoutOperationMask & TextView::RELAYOUT_VISIBILITY )
638 TextViewRelayout::UpdateVisibility( layoutParameters,
643 if( relayoutOperationMask & TextView::RELAYOUT_INITIALIZE_TEXT_ACTORS )
645 TextViewProcessor::InitializeTextActorInfo( relayoutData );
648 if( relayoutOperationMask & TextView::RELAYOUT_TEXT_ACTOR_UPDATE )
650 TextViewRelayout::UpdateTextActorInfo( visualParameters,
654 if( ( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW ) ||
655 ( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ) )
657 TextViewRelayout::InsertToTextView( relayoutOperationMask,
663 } // namespace SplitByWord
665 } // namespace Internal
667 } // namespace Toolkit