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 = 0u;
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;
282 // Reset the index of words.
283 indices.mWordIndex = 0u;
285 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordIt = lineLayoutInfo.mWordsLayoutInfo.begin(), wordEndIt = lineLayoutInfo.mWordsLayoutInfo.end();
287 ++wordIt, ++indices.mWordIndex )
289 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordIt );
291 // Reset the index of the character.
292 indices.mCharacterIndex = 0u;
294 // Whether current character is the first of the word.
295 bool isFirstCharOfWord = true;
296 const float wordOffset = previousPosition.x + previousSize.width;
298 isLastCharacterNewLineChar = ( TextViewProcessor::LineSeparator == wordLayoutInfo.mType );
300 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator charIt = wordLayoutInfo.mCharactersLayoutInfo.begin(), charEndIt = wordLayoutInfo.mCharactersLayoutInfo.end();
302 ++charIt, ++indices.mCharacterIndex )
304 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *charIt );
305 lastCharHeight = characterLayoutInfo.mSize.height * shrinkFactor;
307 const float previousPositionY = isFirstChar ? 0.f : previousPosition.y;
309 if( ( isNewLine || isFirstChar ) ||
310 ( isFirstCharOfWord && ( wordOffset + wordLayoutInfo.mSize.width * shrinkFactor > parentWidth ) ) )
314 // Calculates the line length and the max character height for the current line.
315 TextViewRelayout::SubLineLayoutInfo subLineInfo;
316 subLineInfo.mLineLength = 0.f;
317 subLineInfo.mMaxCharHeight = 0.f;
318 subLineInfo.mMaxAscender = 0.f;
319 TextViewRelayout::CalculateSubLineLayout( parentWidth,
322 TextViewRelayout::WrapByWord,
326 characterLayoutInfo.mPosition = Vector3( 0.f, previousPositionY + subLineInfo.mMaxCharHeight + layoutParameters.mLineHeightOffset * shrinkFactor, 0.f );
328 newTextHeight += subLineInfo.mMaxCharHeight + layoutParameters.mLineHeightOffset * shrinkFactor;
330 Toolkit::TextView::LineLayoutInfo lineInfo;
331 lineInfo.mCharacterGlobalIndex = characterGlobalIndex; // Index to the first character of the next line.
332 lineInfo.mSize = Size( subLineInfo.mLineLength, subLineInfo.mMaxCharHeight ); // Size of this piece of line.
333 lineInfo.mAscender = subLineInfo.mMaxAscender; // Ascender of this piece of line.
334 relayoutData.mLines.push_back( lineInfo );
336 // Stores some info to calculate the line justification in a post-process.
337 TextView::LineJustificationInfo justificationInfo;
339 justificationInfo.mIndices = indices;
340 justificationInfo.mLineLength = subLineInfo.mLineLength;
342 relayoutData.mLineJustificationInfo.push_back( justificationInfo );
346 characterLayoutInfo.mPosition = previousPosition + Vector3( previousSize.width, 0.f, 0.f );
349 // Get last line info and calculate the bearing.
350 const Toolkit::TextView::LineLayoutInfo& lineInfo( *( relayoutData.mLines.end() - 1u ) );
351 const float bearingOffset = ( ( lineInfo.mSize.height - lineInfo.mAscender ) - ( characterLayoutInfo.mSize.height - characterLayoutInfo.mAscender ) ) * shrinkFactor;
353 previousSize = characterLayoutInfo.mSize * shrinkFactor;
354 previousPosition = characterLayoutInfo.mPosition;
355 characterLayoutInfo.mPosition.y -= bearingOffset;
356 isFirstCharOfWord = false;
359 ++characterGlobalIndex;
364 if( isLastCharacterNewLineChar )
366 newTextHeight += lastCharHeight + layoutParameters.mLineHeightOffset * shrinkFactor;
370 float RelayoutForShrinkToFit( TextView::RelayoutData& relayoutData,
371 const TextView::LayoutParameters& layoutParameters )
373 const Size& textViewSize = relayoutData.mTextViewSize;
374 TextViewProcessor::TextLayoutInfo& textLayoutInfo = relayoutData.mTextLayoutInfo;
376 // First step is assure the longest word fits in the text view width.
377 float shrinkFactor = ( textLayoutInfo.mMaxWordWidth > textViewSize.width ? textViewSize.width / textLayoutInfo.mMaxWordWidth : 1.f );
379 // Out parameter. Will store the new text height after relayout the text.
380 float newTextHeight = 0.f;
382 // Relayout the text for the given character's sizes.
383 CalculatePositionsForShrinkWhenExceed( relayoutData,
388 if( newTextHeight > textViewSize.height )
390 // After relayouting, the text exceeds the text view height.
391 // Find a new scale factor to fit all the text in the text view size is needed.
393 // The next algorithm does some iterations to calculate an acceptable scale factor.
394 // Some magic numbers are defined.
396 const float MIN_RATIO( 0.90f ); // The algorithm finishes if the ratio
397 const float MAX_RATIO( 1.00f ); // new_text_height / text_view_height is between this two values
398 const unsigned int MAX_ITERATIONS( 8u ); // or max_iteration is reached.
400 float ratio = newTextHeight / textViewSize.height;
402 float maxScaleFactor = shrinkFactor; // bigger scale factors than maxScaleFactor will produce a too big text.
403 float minScaleFactor = shrinkFactor * ( textViewSize.height / newTextHeight ); // smaller scale factors than minScaleFactor will produce a too small text.
405 for( unsigned int iterations = 0u; ( ( MIN_RATIO > ratio ) || ( ratio > MAX_RATIO ) ) && ( iterations < MAX_ITERATIONS ); ++iterations )
407 // Calculates the new scale factor.
408 // The new scale factor is always between the min and max scale factors.
409 // 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
410 // minScaleFactor. Alternatively if the text is too big a new scale factor close to maxScaleFactor is selected.
411 // This allows the text shrink or grow smoothly.
412 shrinkFactor = minScaleFactor + ( ratio < 1.f ? 0.4f : 0.6f ) * ( maxScaleFactor - minScaleFactor );
414 CalculatePositionsForShrinkWhenExceed( relayoutData, // Relayout the text for the given character's sizes.
419 // Calculates the new text size ratio. It allows update the min and max scale factors.
420 // If the ratio is not good enough a new scale factor between min and max could be used in next iteration.
421 ratio = newTextHeight / textViewSize.height;
424 minScaleFactor = shrinkFactor;
428 maxScaleFactor = shrinkFactor;
432 if( ratio > MAX_RATIO )
434 // The algorithm didn't find an acceptable scale factor.
435 // In that case the text is shrunk to fit in the boundaries of the text view actor.
436 shrinkFactor = minScaleFactor;
438 CalculatePositionsForShrinkWhenExceed( relayoutData,
448 void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameters,
449 TextView::RelayoutData& relayoutData )
451 TextViewRelayout::RelayoutParameters relayoutParameters;
454 relayoutData.mCharacterLayoutInfoTable.clear();
455 relayoutData.mLines.clear();
456 relayoutData.mTextSizeForRelayoutOption = Size();
458 // Calculates the text size for split by char.
459 Vector4 minMaxXY( std::numeric_limits<float>::max(),
460 std::numeric_limits<float>::max(),
461 std::numeric_limits<float>::min(),
462 std::numeric_limits<float>::min() );
464 relayoutData.mShrinkFactor = 1.f; // Shrink factor used when the exceed policy contains ShrinkToFit
466 if( TextView::Shrink == layoutParameters.mExceedPolicy )
468 // Relays-out the text for the shrink to fit policy.
469 relayoutData.mShrinkFactor = RelayoutForShrinkToFit( relayoutData, layoutParameters );
471 else if( TextView::ShrinkOriginal == layoutParameters.mExceedPolicy )
473 relayoutData.mShrinkFactor = ( relayoutData.mTextLayoutInfo.mMaxWordWidth > relayoutData.mTextViewSize.width ? relayoutData.mTextViewSize.width / relayoutData.mTextLayoutInfo.mMaxWordWidth : 1.f );
476 relayoutParameters.mPositionOffset = Vector3::ZERO;
477 relayoutParameters.mIsFirstCharacter = true;
478 relayoutParameters.mIndices.mLineIndex = 0u;
479 relayoutParameters.mCharacterGlobalIndex = 0u;
481 for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
482 endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
483 lineLayoutIt != endLineLayoutIt;
484 ++lineLayoutIt, ++relayoutParameters.mIndices.mLineIndex )
486 TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
488 relayoutParameters.mIsNewLine = true;
489 relayoutParameters.mLineSize = lineLayoutInfo.mSize;
490 relayoutParameters.mIndices.mWordIndex = 0u;
492 for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.begin(),
493 endWordLayoutIt = lineLayoutInfo.mWordsLayoutInfo.end();
494 wordLayoutIt != endWordLayoutIt;
495 ++wordLayoutIt, ++relayoutParameters.mIndices.mWordIndex )
497 TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
498 relayoutParameters.mIsWhiteSpace = TextViewProcessor::WordSeparator == wordLayoutInfo.mType;
499 relayoutParameters.mIsNewLineCharacter = TextViewProcessor::LineSeparator == wordLayoutInfo.mType;
501 relayoutParameters.mIsFirstCharacterOfWord = true;
502 relayoutParameters.mWordSize = wordLayoutInfo.mSize;
503 relayoutParameters.mIndices.mCharacterIndex = 0u;
505 for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
506 endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
507 ( characterLayoutIt != endCharacterLayoutIt );
508 ++characterLayoutIt, ++relayoutParameters.mIndices.mCharacterIndex )
510 TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
512 relayoutParameters.mCharacterSize = characterLayoutInfo.mSize;
514 switch( layoutParameters.mExceedPolicy )
516 case TextView::OriginalShrink:
517 case TextView::SplitShrink:
518 case TextView::ShrinkFade:
520 DALI_LOG_WARNING( "SplitByWord::CalculateSizeAndPosition() policy not implemented.\n" );
523 case TextView::Original:
524 case TextView::OriginalFade:
525 case TextView::FadeOriginal:
527 case TextView::EllipsizeEndOriginal:
528 case TextView::EllipsizeEnd: // Fall Through
530 characterLayoutInfo.mPosition = OriginalPosition( relayoutParameters,
534 relayoutParameters.mPositionOffset = characterLayoutInfo.mPosition + Vector3( characterLayoutInfo.mSize.width, 0.f, 0.f );
537 case TextView::SplitOriginal:
538 case TextView::SplitFade:
539 case TextView::SplitEllipsizeEnd:
541 characterLayoutInfo.mPosition = SplitWhenExceedPosition( relayoutParameters,
545 relayoutParameters.mPositionOffset = characterLayoutInfo.mPosition + Vector3( characterLayoutInfo.mSize.width, 0.f, 0.f );
548 case TextView::ShrinkOriginal:
550 characterLayoutInfo.mPosition = ShrinkWidthWhenExceedPosition( relayoutParameters,
554 relayoutParameters.mPositionOffset = characterLayoutInfo.mPosition + Vector3( characterLayoutInfo.mSize.width * relayoutData.mShrinkFactor, 0.f, 0.f );
557 case TextView::Shrink:
559 // Does nothing. All the job has been done in the RelayoutForShrinkToFit() function.
564 DALI_LOG_WARNING( "SplitByWord::CalculateSizeAndPosition() policy combination not possible.\n" );
568 // Get last line info and calculate the bearing (used to align glyphs with the baseline).
569 if( TextView::Shrink != layoutParameters.mExceedPolicy )
571 TextViewRelayout::CalculateBearing( characterLayoutInfo, relayoutData );
574 // updates min and max position to calculate the text size for split by word.
575 TextViewRelayout::UpdateLayoutInfoTable( minMaxXY,
581 ++relayoutParameters.mCharacterGlobalIndex;
582 relayoutParameters.mIsFirstCharacter = false;
583 relayoutParameters.mIsFirstCharacterOfWord = false;
584 relayoutParameters.mIsNewLine = false;
589 if( relayoutData.mCharacterLayoutInfoTable.empty() )
591 relayoutData.mTextSizeForRelayoutOption = Size();
595 relayoutData.mTextSizeForRelayoutOption.width = minMaxXY.z - minMaxXY.x;
596 relayoutData.mTextSizeForRelayoutOption.height = minMaxXY.w - minMaxXY.y;
599 // Check if the last character is a new line character. In that case the height should be added.
600 if( !relayoutData.mTextLayoutInfo.mLinesLayoutInfo.empty() )
602 const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1u ) );
604 if( lineLayoutInfo.mWordsLayoutInfo.empty() ) // if it's empty, it means the last character is a new line character.
606 relayoutData.mTextSizeForRelayoutOption.height += lineLayoutInfo.mSize.height * relayoutData.mShrinkFactor;
613 void Relayout( Actor textView,
614 TextView::RelayoutOperationMask relayoutOperationMask,
615 const TextView::LayoutParameters& layoutParameters,
616 const TextView::VisualParameters& visualParameters,
617 TextView::RelayoutData& relayoutData )
619 if( relayoutOperationMask & TextView::RELAYOUT_SIZE_POSITION )
621 relayoutData.mLineJustificationInfo.clear();
622 CalculateSizeAndPosition( layoutParameters,
625 TextViewRelayout::SetUnderlineInfo( relayoutData );
628 if( relayoutOperationMask & TextView::RELAYOUT_ALIGNMENT )
630 TextViewRelayout::UpdateAlignment( layoutParameters,
634 if( relayoutOperationMask & TextView::RELAYOUT_VISIBILITY )
636 TextViewRelayout::UpdateVisibility( layoutParameters,
640 const bool initializeTextActors = relayoutOperationMask & TextView::RELAYOUT_INITIALIZE_TEXT_ACTORS;
641 const bool updateTextActors = relayoutOperationMask & TextView::RELAYOUT_TEXT_ACTOR_UPDATE;
642 if( initializeTextActors || updateTextActors )
644 TextViewRelayout::UpdateTextActorInfo( visualParameters,
646 initializeTextActors );
649 if( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW )
651 TextViewRelayout::InsertToTextView( textView,
656 } // namespace SplitByWord
658 } // namespace Internal
660 } // namespace Toolkit