+void Controller::CalculateTextAlignment( const Size& size )
+{
+ // TODO : Calculate the vertical offset.
+
+ // Get the direction of the first character.
+ const CharacterDirection firstParagraphDirection = mImpl->mLogicalModel->GetCharacterDirection( 0u );
+
+ const Size& actualSize = mImpl->mVisualModel->GetActualSize();
+
+ // If the first paragraph is right to left swap ALIGN_BEGIN and ALIGN_END;
+ LayoutEngine::Alignment alignment = mImpl->mLayoutEngine.GetAlignment();
+ if( firstParagraphDirection &&
+ ( LayoutEngine::ALIGN_CENTER != alignment ) )
+ {
+ if( LayoutEngine::ALIGN_BEGIN == alignment )
+ {
+ alignment = LayoutEngine::ALIGN_END;
+ }
+ else
+ {
+ alignment = LayoutEngine::ALIGN_BEGIN;
+ }
+ }
+
+ switch( alignment )
+ {
+ case LayoutEngine::ALIGN_BEGIN:
+ {
+ mImpl->mAlignmentOffset = Vector2::ZERO;
+ break;
+ }
+ case LayoutEngine::ALIGN_CENTER:
+ {
+ mImpl->mAlignmentOffset.y = 0.f;
+ const int intOffset = static_cast<int>( 0.5f * ( size.width - actualSize.width ) ); // try to avoid pixel alignment.
+ mImpl->mAlignmentOffset.x = static_cast<float>( intOffset );
+ break;
+ }
+ case LayoutEngine::ALIGN_END:
+ {
+ mImpl->mAlignmentOffset.y = 0.f;
+ mImpl->mAlignmentOffset.x = size.width - actualSize.width;
+ break;
+ }
+ }
+}
+