63aa2adaa6de00f3c342c85e47fda1527c9e89b3
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller-relayouter.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/text-controller-relayouter.h>
20
21 // EXTERNAL INCLUDES
22 #include <limits>
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
27 #include <dali-toolkit/internal/text/text-controller-impl.h>
28
29 namespace
30 {
31
32 #if defined(DEBUG_ENABLED)
33 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
34 #endif
35
36 constexpr float MAX_FLOAT = std::numeric_limits<float>::max();
37
38 float ConvertToEven( float value )
39 {
40   int intValue(static_cast<int>( value ));
41   return static_cast<float>( intValue + ( intValue & 1 ) );
42 }
43
44 } // namespace
45
46 namespace Dali
47 {
48
49 namespace Toolkit
50 {
51
52 namespace Text
53 {
54
55 Vector3 Controller::Relayouter::GetNaturalSize(Controller& controller)
56 {
57   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
58   Vector3 naturalSize;
59
60   // Make sure the model is up-to-date before layouting
61   controller.ProcessModifyEvents();
62
63   Controller::Impl& impl = *controller.mImpl;
64   ModelPtr& model = impl.mModel;
65   VisualModelPtr& visualModel = model->mVisualModel;
66   if( impl.mRecalculateNaturalSize )
67   {
68     // Operations that can be done only once until the text changes.
69     const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32  |
70                                                                            GET_SCRIPTS       |
71                                                                            VALIDATE_FONTS    |
72                                                                            GET_LINE_BREAKS   |
73                                                                            BIDI_INFO         |
74                                                                            SHAPE_TEXT        |
75                                                                            GET_GLYPH_METRICS );
76
77     // Set the update info to relayout the whole text.
78     TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo;
79     textUpdateInfo.mParagraphCharacterIndex = 0u;
80     textUpdateInfo.mRequestedNumberOfCharacters = model->mLogicalModel->mText.Count();
81
82     // Make sure the model is up-to-date before layouting
83     impl.UpdateModel( onlyOnceOperations );
84
85     // Get a reference to the pending operations member
86     OperationsMask& operationsPending = impl.mOperationsPending;
87
88     // Layout the text for the new width.
89     operationsPending = static_cast<OperationsMask>( operationsPending | LAYOUT | REORDER );
90
91     // Store the actual control's size to restore later.
92     const Size actualControlSize = visualModel->mControlSize;
93
94     DoRelayout( controller,
95                 Size( MAX_FLOAT, MAX_FLOAT ),
96                 static_cast<OperationsMask>( onlyOnceOperations |
97                                              LAYOUT | REORDER ),
98                 naturalSize.GetVectorXY() );
99
100     // Do not do again the only once operations.
101     operationsPending = static_cast<OperationsMask>( operationsPending & ~onlyOnceOperations );
102
103     // Do the size related operations again.
104     const OperationsMask sizeOperations =  static_cast<OperationsMask>( LAYOUT |
105                                                                         ALIGN  |
106                                                                         REORDER );
107     operationsPending = static_cast<OperationsMask>( operationsPending | sizeOperations );
108
109     // Stores the natural size to avoid recalculate it again
110     // unless the text/style changes.
111     visualModel->SetNaturalSize( naturalSize.GetVectorXY() );
112
113     impl.mRecalculateNaturalSize = false;
114
115     // Clear the update info. This info will be set the next time the text is updated.
116     textUpdateInfo.Clear();
117     textUpdateInfo.mClearAll = true;
118
119     // Restore the actual control's size.
120     visualModel->mControlSize = actualControlSize;
121
122     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
123   }
124   else
125   {
126     naturalSize = visualModel->GetNaturalSize();
127
128     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
129   }
130
131   naturalSize.x = ConvertToEven( naturalSize.x );
132   naturalSize.y = ConvertToEven( naturalSize.y );
133
134   return naturalSize;
135 }
136
137 bool Controller::Relayouter::CheckForTextFit(Controller& controller, float pointSize, const Size& layoutSize)
138 {
139   Size textSize;
140   Controller::Impl& impl = *controller.mImpl;
141   TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo;
142   impl.mFontDefaults->mFitPointSize = pointSize;
143   impl.mFontDefaults->sizeDefined = true;
144   controller.ClearFontData();
145
146   // Operations that can be done only once until the text changes.
147   const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
148                                                                               GET_SCRIPTS |
149                                                                            VALIDATE_FONTS |
150                                                                           GET_LINE_BREAKS |
151                                                                                 BIDI_INFO |
152                                                                                 SHAPE_TEXT|
153                                                                          GET_GLYPH_METRICS );
154
155   textUpdateInfo.mParagraphCharacterIndex = 0u;
156   textUpdateInfo.mRequestedNumberOfCharacters = impl.mModel->mLogicalModel->mText.Count();
157
158   // Make sure the model is up-to-date before layouting
159   impl.UpdateModel( onlyOnceOperations );
160
161   DoRelayout( controller,
162               Size( layoutSize.width, MAX_FLOAT ),
163               static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
164               textSize);
165
166   // Clear the update info. This info will be set the next time the text is updated.
167   textUpdateInfo.Clear();
168   textUpdateInfo.mClearAll = true;
169
170   if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
171   {
172     return false;
173   }
174   return true;
175 }
176
177 float Controller::Relayouter::GetHeightForWidth(Controller& controller, float width)
178 {
179   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", &controller, width );
180   // Make sure the model is up-to-date before layouting
181   controller.ProcessModifyEvents();
182
183   Controller::Impl& impl = *controller.mImpl;
184   ModelPtr& model = impl.mModel;
185   VisualModelPtr& visualModel = model->mVisualModel;
186   TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo;
187
188   Size layoutSize;
189   if( fabsf( width - visualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
190       textUpdateInfo.mFullRelayoutNeeded ||
191       textUpdateInfo.mClearAll )
192   {
193     // Operations that can be done only once until the text changes.
194     const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32  |
195                                                                            GET_SCRIPTS       |
196                                                                            VALIDATE_FONTS    |
197                                                                            GET_LINE_BREAKS   |
198                                                                            BIDI_INFO         |
199                                                                            SHAPE_TEXT        |
200                                                                            GET_GLYPH_METRICS );
201
202     // Set the update info to relayout the whole text.
203     textUpdateInfo.mParagraphCharacterIndex = 0u;
204     textUpdateInfo.mRequestedNumberOfCharacters = model->mLogicalModel->mText.Count();
205
206     // Make sure the model is up-to-date before layouting
207     impl.UpdateModel( onlyOnceOperations );
208
209     // Get a reference to the pending operations member
210     OperationsMask& operationsPending = impl.mOperationsPending;
211
212     // Layout the text for the new width.
213     operationsPending = static_cast<OperationsMask>( operationsPending | LAYOUT );
214
215     // Store the actual control's width.
216     const float actualControlWidth = visualModel->mControlSize.width;
217
218     DoRelayout( controller,
219                 Size( width, MAX_FLOAT ),
220                 static_cast<OperationsMask>( onlyOnceOperations |
221                                              LAYOUT ),
222                 layoutSize );
223
224     // Do not do again the only once operations.
225     operationsPending = static_cast<OperationsMask>( operationsPending & ~onlyOnceOperations );
226
227     // Do the size related operations again.
228     const OperationsMask sizeOperations =  static_cast<OperationsMask>( LAYOUT |
229                                                                         ALIGN  |
230                                                                         REORDER );
231
232     operationsPending = static_cast<OperationsMask>( operationsPending | sizeOperations );
233
234     // Clear the update info. This info will be set the next time the text is updated.
235     textUpdateInfo.Clear();
236     textUpdateInfo.mClearAll = true;
237
238     // Restore the actual control's width.
239     visualModel->mControlSize.width = actualControlWidth;
240
241     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
242   }
243   else
244   {
245     layoutSize = visualModel->GetLayoutSize();
246     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
247   }
248
249   return layoutSize.height;
250 }
251
252 Controller::UpdateTextType Controller::Relayouter::Relayout(Controller& controller, const Size& size, Dali::LayoutDirection::Type layoutDirection)
253 {
254   Controller::Impl& impl = *controller.mImpl;
255   ModelPtr& model = impl.mModel;
256   VisualModelPtr& visualModel = model->mVisualModel;
257   TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo;
258
259   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", &controller, size.width, size.height, impl.mIsAutoScrollEnabled ?"true":"false"  );
260
261   UpdateTextType updateTextType = NONE_UPDATED;
262
263   if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
264   {
265     if( 0u != visualModel->mGlyphPositions.Count() )
266     {
267       visualModel->mGlyphPositions.Clear();
268       updateTextType = MODEL_UPDATED;
269     }
270
271     // Clear the update info. This info will be set the next time the text is updated.
272     textUpdateInfo.Clear();
273
274     // Not worth to relayout if width or height is equal to zero.
275     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
276
277     return updateTextType;
278   }
279
280   // Whether a new size has been set.
281   const bool newSize = ( size != visualModel->mControlSize );
282
283   // Get a reference to the pending operations member
284   OperationsMask& operationsPending = impl.mOperationsPending;
285
286   if( newSize )
287   {
288     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", visualModel->mControlSize.width, visualModel->mControlSize.height );
289
290     if( ( 0 == textUpdateInfo.mNumberOfCharactersToAdd ) &&
291         ( 0 == textUpdateInfo.mPreviousNumberOfCharacters ) &&
292         ( ( visualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( visualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
293     {
294       textUpdateInfo.mNumberOfCharactersToAdd = model->mLogicalModel->mText.Count();
295     }
296
297     // Layout operations that need to be done if the size changes.
298     operationsPending = static_cast<OperationsMask>( operationsPending  |
299                                                      LAYOUT             |
300                                                      ALIGN              |
301                                                      UPDATE_LAYOUT_SIZE |
302                                                      REORDER );
303     // Set the update info to relayout the whole text.
304     textUpdateInfo.mFullRelayoutNeeded = true;
305     textUpdateInfo.mCharacterIndex = 0u;
306
307     // Store the size used to layout the text.
308     visualModel->mControlSize = size;
309   }
310
311   // Whether there are modify events.
312   if( 0u != impl.mModifyEvents.Count() )
313   {
314     // Style operations that need to be done if the text is modified.
315     operationsPending = static_cast<OperationsMask>( operationsPending | COLOR );
316   }
317
318   // Set the update info to elide the text.
319   if( model->mElideEnabled ||
320       ( ( NULL != impl.mEventData ) && impl.mEventData->mIsPlaceholderElideEnabled ) )
321   {
322     // Update Text layout for applying elided
323     operationsPending = static_cast<OperationsMask>( operationsPending  |
324                                                      ALIGN              |
325                                                      LAYOUT             |
326                                                      UPDATE_LAYOUT_SIZE |
327                                                      REORDER );
328     textUpdateInfo.mFullRelayoutNeeded = true;
329     textUpdateInfo.mCharacterIndex = 0u;
330   }
331
332   if( model->mMatchSystemLanguageDirection  && impl.mLayoutDirection != layoutDirection )
333   {
334     // Clear the update info. This info will be set the next time the text is updated.
335     textUpdateInfo.mClearAll = true;
336     // Apply modifications to the model
337     // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
338     operationsPending = static_cast<OperationsMask>( operationsPending |
339                                                      GET_GLYPH_METRICS |
340                                                      SHAPE_TEXT        |
341                                                      UPDATE_DIRECTION  |
342                                                      LAYOUT            |
343                                                      BIDI_INFO         |
344                                                      REORDER );
345     impl.mLayoutDirection = layoutDirection;
346   }
347
348   // Make sure the model is up-to-date before layouting.
349   controller.ProcessModifyEvents();
350   bool updated = impl.UpdateModel( operationsPending );
351
352   // Layout the text.
353   Size layoutSize;
354   updated = DoRelayout( controller, size, operationsPending, layoutSize ) || updated;
355
356
357   if( updated )
358   {
359     updateTextType = MODEL_UPDATED;
360   }
361
362   // Do not re-do any operation until something changes.
363   operationsPending = NO_OPERATION;
364   model->mScrollPositionLast = model->mScrollPosition;
365
366   // Whether the text control is editable
367   const bool isEditable = NULL != impl.mEventData;
368
369   // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
370   Vector2 offset;
371   if( newSize && isEditable )
372   {
373     offset = model->mScrollPosition;
374   }
375
376   if( !isEditable || !controller.IsMultiLineEnabled() )
377   {
378     // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
379     controller.CalculateVerticalOffset( size );
380   }
381
382   if( isEditable )
383   {
384     if( newSize )
385     {
386       // If there is a new size, the scroll position needs to be clamped.
387       impl.ClampHorizontalScroll( layoutSize );
388
389       // Update the decorator's positions is needed if there is a new size.
390       impl.mEventData->mDecorator->UpdatePositions( model->mScrollPosition - offset );
391     }
392
393     // Move the cursor, grab handle etc.
394     if( impl.ProcessInputEvents() )
395     {
396       updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
397     }
398   }
399
400   // Clear the update info. This info will be set the next time the text is updated.
401   textUpdateInfo.Clear();
402   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
403
404   return updateTextType;
405 }
406
407 bool Controller::Relayouter::DoRelayout(Controller& controller, const Size& size, OperationsMask operationsRequired, Size& layoutSize )
408 {
409   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", &controller, size.width, size.height );
410   bool viewUpdated( false );
411
412   Controller::Impl& impl = *controller.mImpl;
413
414   // Calculate the operations to be done.
415   const OperationsMask operations = static_cast<OperationsMask>( impl.mOperationsPending & operationsRequired );
416
417   TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo;
418   const CharacterIndex startIndex = textUpdateInfo.mParagraphCharacterIndex;
419   const Length requestedNumberOfCharacters = textUpdateInfo.mRequestedNumberOfCharacters;
420
421   // Get the current layout size.
422   VisualModelPtr& visualModel = impl.mModel->mVisualModel;
423   layoutSize = visualModel->GetLayoutSize();
424
425   if( NO_OPERATION != ( LAYOUT & operations ) )
426   {
427     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
428
429     // Some vectors with data needed to layout and reorder may be void
430     // after the first time the text has been laid out.
431     // Fill the vectors again.
432
433     // Calculate the number of glyphs to layout.
434     const Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
435     const Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
436     const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
437     const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
438
439     const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
440     const GlyphIndex startGlyphIndex = textUpdateInfo.mStartGlyphIndex;
441
442     // Make sure the index is not out of bound
443     if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
444          requestedNumberOfCharacters > charactersToGlyph.Count() ||
445          ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
446     {
447       std::string currentText;
448       controller.GetText( currentText );
449
450       DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
451       DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
452       DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
453
454       return false;
455     }
456
457     const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
458     const Length totalNumberOfGlyphs = visualModel->mGlyphs.Count();
459
460     if( 0u == totalNumberOfGlyphs )
461     {
462       if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
463       {
464         visualModel->SetLayoutSize( Size::ZERO );
465       }
466
467       // Nothing else to do if there is no glyphs.
468       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
469       return true;
470     }
471
472     // Set the layout parameters.
473     Layout::Parameters layoutParameters( size, impl.mModel);
474
475     // Resize the vector of positions to have the same size than the vector of glyphs.
476     Vector<Vector2>& glyphPositions = visualModel->mGlyphPositions;
477     glyphPositions.Resize( totalNumberOfGlyphs );
478
479     // Whether the last character is a new paragraph character.
480     const Character* const textBuffer = impl.mModel->mLogicalModel->mText.Begin();
481     textUpdateInfo.mIsLastCharacterNewParagraph =  TextAbstraction::IsNewParagraph( *( textBuffer + ( impl.mModel->mLogicalModel->mText.Count() - 1u ) ) );
482     layoutParameters.isLastNewParagraph = textUpdateInfo.mIsLastCharacterNewParagraph;
483
484     // The initial glyph and the number of glyphs to layout.
485     layoutParameters.startGlyphIndex = startGlyphIndex;
486     layoutParameters.numberOfGlyphs = numberOfGlyphs;
487     layoutParameters.startLineIndex = textUpdateInfo.mStartLineIndex;
488     layoutParameters.estimatedNumberOfLines = textUpdateInfo.mEstimatedNumberOfLines;
489
490     // Update the ellipsis
491     bool elideTextEnabled = impl.mModel->mElideEnabled;
492
493     if( NULL != impl.mEventData )
494     {
495       if( impl.mEventData->mPlaceholderEllipsisFlag && impl.IsShowingPlaceholderText() )
496       {
497         elideTextEnabled = impl.mEventData->mIsPlaceholderElideEnabled;
498       }
499       else if( EventData::INACTIVE != impl.mEventData->mState )
500       {
501         // Disable ellipsis when editing
502         elideTextEnabled = false;
503       }
504
505       // Reset the scroll position in inactive state
506       if( elideTextEnabled && ( impl.mEventData->mState == EventData::INACTIVE ) )
507       {
508         controller.ResetScrollPosition();
509       }
510     }
511
512     // Update the visual model.
513     bool isAutoScrollEnabled = impl.mIsAutoScrollEnabled;
514     Size newLayoutSize;
515     viewUpdated = impl.mLayoutEngine.LayoutText( layoutParameters,
516                                                  newLayoutSize,
517                                                  elideTextEnabled,
518                                                  isAutoScrollEnabled );
519     impl.mIsAutoScrollEnabled = isAutoScrollEnabled;
520
521     viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
522
523     if( viewUpdated )
524     {
525       layoutSize = newLayoutSize;
526
527       if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
528       {
529         impl.mIsTextDirectionRTL = false;
530       }
531
532       if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && !visualModel->mLines.Empty() )
533       {
534         impl.mIsTextDirectionRTL = visualModel->mLines[0u].direction;
535       }
536
537       // Sets the layout size.
538       if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
539       {
540         visualModel->SetLayoutSize( layoutSize );
541       }
542     } // view updated
543   }
544
545   if( NO_OPERATION != ( ALIGN & operations ) )
546   {
547     // The laid-out lines.
548     Vector<LineRun>& lines = visualModel->mLines;
549
550     CharacterIndex alignStartIndex = startIndex;
551     Length alignRequestedNumberOfCharacters = requestedNumberOfCharacters;
552
553     // the whole text needs to be full aligned.
554     // If you do not do a full aligned, only the last line of the multiline input is aligned.
555     if(  impl.mEventData && impl.mEventData->mUpdateAlignment )
556     {
557       alignStartIndex = 0u;
558       alignRequestedNumberOfCharacters = impl.mModel->mLogicalModel->mText.Count();
559       impl.mEventData->mUpdateAlignment = false;
560     }
561
562     // Need to align with the control's size as the text may contain lines
563     // starting either with left to right text or right to left.
564     impl.mLayoutEngine.Align( size,
565                               alignStartIndex,
566                               alignRequestedNumberOfCharacters,
567                               impl.mModel->mHorizontalAlignment,
568                               lines,
569                               impl.mModel->mAlignmentOffset,
570                               impl.mLayoutDirection,
571                               impl.mModel->mMatchSystemLanguageDirection );
572
573     viewUpdated = true;
574   }
575 #if defined(DEBUG_ENABLED)
576   std::string currentText;
577   controller.GetText( currentText );
578   DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", &controller, (impl.mIsTextDirectionRTL)?"true":"false",  currentText.c_str() );
579 #endif
580   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
581   return viewUpdated;
582 }
583
584 void Controller::Relayouter::CalculateVerticalOffset(Controller& controller, const Size& controlSize)
585 {
586   Controller::Impl& impl = *controller.mImpl;
587   ModelPtr& model = impl.mModel;
588   Size layoutSize = model->mVisualModel->GetLayoutSize();
589
590   if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
591   {
592     // Get the line height of the default font.
593     layoutSize.height = impl.GetDefaultFontLineHeight();
594   }
595
596   switch( model->mVerticalAlignment )
597   {
598     case VerticalAlignment::TOP:
599     {
600       model->mScrollPosition.y = 0.f;
601       break;
602     }
603     case VerticalAlignment::CENTER:
604     {
605       model->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
606       break;
607     }
608     case VerticalAlignment::BOTTOM:
609     {
610       model->mScrollPosition.y = controlSize.height - layoutSize.height;
611       break;
612     }
613   }
614 }
615
616 } // namespace Text
617
618 } // namespace Toolkit
619
620 } // namespace Dali