Layout implementation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
index 2b90bc3..995354c 100644 (file)
@@ -21,6 +21,7 @@
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/text/character-set-conversion.h>
 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
+#include <dali-toolkit/internal/text/layouts/layout-parameters.h>
 #include <dali-toolkit/internal/text/logical-model.h>
 #include <dali-toolkit/internal/text/multi-language-support.h>
 #include <dali-toolkit/internal/text/script-run.h>
@@ -307,6 +308,18 @@ void Controller::SetText( const std::string& text )
   }
 }
 
+void Controller::GetText( std::string& text )
+{
+  if( !mImpl->mNewText.empty() )
+  {
+    text = mImpl->mNewText;
+  }
+  else
+  {
+    // TODO - Convert from UTF-32
+  }
+}
+
 void Controller::EnableTextInput( DecoratorPtr decorator )
 {
   if( !mImpl->mTextInput )
@@ -369,7 +382,7 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations )
     mImpl->mLogicalModel->SetText( utf32Characters.Begin(), characterCount );
 
     // Discard temporary text
-    text.clear();
+    //text.clear(); temporary keep the text. will be fixed in the next patch.
   }
 
   Vector<LineBreakInfo> lineBreakInfo;
@@ -387,6 +400,18 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations )
     mImpl->mLogicalModel->SetLineBreakInfo( lineBreakInfo.Begin(), characterCount );
   }
 
+  Vector<WordBreakInfo> wordBreakInfo;
+  if( GET_WORD_BREAKS & operations )
+  {
+    // Retrieves the word break info. The word break info is used to layout the text (where to wrap the text in lines).
+    wordBreakInfo.Resize( characterCount, TextAbstraction::WORD_NO_BREAK );
+
+    SetWordBreakInfo( utf32Characters,
+                      wordBreakInfo );
+
+    mImpl->mLogicalModel->SetWordBreakInfo( wordBreakInfo.Begin(), characterCount );
+  }
+
   const bool getScripts = GET_SCRIPTS & operations;
   const bool validateFonts = VALIDATE_FONTS & operations;
 
@@ -423,7 +448,7 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations )
   }
 
   Vector<GlyphInfo> glyphs;
-  Vector<CharacterIndex> characterIndices;
+  Vector<CharacterIndex> glyphsToCharactersMap;
   Vector<Length> charactersPerGlyph;
   if( SHAPE_TEXT & operations )
   {
@@ -433,7 +458,7 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations )
                scripts,
                fonts,
                glyphs,
-               characterIndices,
+               glyphsToCharactersMap,
                charactersPerGlyph );
   }
 
@@ -442,21 +467,42 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations )
     mImpl->mFontClient.GetGlyphMetrics( glyphs.Begin(), glyphs.Count() );
   }
 
+  Length numberOfGlyphs = glyphs.Count();
+  if( 0u != numberOfGlyphs )
+  {
+    // Sets the glyphs into the model.
+    mImpl->mVisualModel->SetGlyphs( glyphs.Begin(),
+                                    glyphsToCharactersMap.Begin(),
+                                    charactersPerGlyph.Begin(),
+                                    numberOfGlyphs );
+  }
+
   if( LAYOUT & operations )
   {
-    if( 0u == glyphs.Count() )
+    if( 0u == numberOfGlyphs )
     {
-      const Length numberOfGlyphs = mImpl->mVisualModel->GetNumberOfGlyphs();
+      const Length numberOfCharacters = mImpl->mLogicalModel->GetNumberOfCharacters();
+      numberOfGlyphs = mImpl->mVisualModel->GetNumberOfGlyphs();
 
+      lineBreakInfo.Resize( numberOfCharacters );
+      wordBreakInfo.Resize( numberOfCharacters );
       glyphs.Resize( numberOfGlyphs );
-      characterIndices.Resize( numberOfGlyphs );
+      glyphsToCharactersMap.Resize( numberOfGlyphs );
       charactersPerGlyph.Resize( numberOfGlyphs );
 
+      mImpl->mLogicalModel->GetLineBreakInfo( lineBreakInfo.Begin(),
+                                              0u,
+                                              numberOfCharacters );
+
+      mImpl->mLogicalModel->GetWordBreakInfo( wordBreakInfo.Begin(),
+                                              0u,
+                                              numberOfCharacters );
+
       mImpl->mVisualModel->GetGlyphs( glyphs.Begin(),
                                       0u,
                                       numberOfGlyphs );
 
-      mImpl->mVisualModel->GetGlyphToCharacterMap( characterIndices.Begin(),
+      mImpl->mVisualModel->GetGlyphToCharacterMap( glyphsToCharactersMap.Begin(),
                                                    0u,
                                                    numberOfGlyphs );
 
@@ -465,14 +511,32 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations )
                                                      numberOfGlyphs );
     }
 
+    // Set the layout parameters.
+    LayoutParameters layoutParameters( size,
+                                       lineBreakInfo.Begin(),
+                                       wordBreakInfo.Begin(),
+                                       numberOfGlyphs,
+                                       glyphs.Begin(),
+                                       glyphsToCharactersMap.Begin(),
+                                       charactersPerGlyph.Begin() );
+
+    // Reserve space to set the positions of the glyphs.
+    Vector<Vector2> glyphPositions;
+    glyphPositions.Resize( numberOfGlyphs );
+
+    Size layoutSize;
+
     // Update the visual model
-    mImpl->mLayoutEngine.UpdateVisualModel( size,
-                                            glyphs,
-                                            characterIndices,
-                                            charactersPerGlyph,
-                                            *mImpl->mVisualModel );
+    viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
+                                                   glyphPositions,
+                                                   layoutSize );
 
-    viewUpdated = true;
+    // Sets the positions into the model.
+    mImpl->mVisualModel->SetGlyphPositions( glyphPositions.Begin(),
+                                            numberOfGlyphs );
+
+    // Sets the actual size.
+    mImpl->mVisualModel->SetActualSize( layoutSize );
   }
 
   return viewUpdated;
@@ -480,6 +544,9 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations )
 
 Vector3 Controller::GetNaturalSize()
 {
+  // TODO - Finish implementing
+  return Vector3::ZERO;
+
   // Operations that can be done only once until the text changes.
   const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
                                                                          GET_SCRIPTS      |