Layout implementation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
index 67f91c4..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>
@@ -381,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;
@@ -399,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;
 
@@ -454,16 +467,37 @@ 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 );
       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 );
@@ -477,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,
-                                            glyphsToCharactersMap,
-                                            charactersPerGlyph,
-                                            *mImpl->mVisualModel );
+    viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
+                                                   glyphPositions,
+                                                   layoutSize );
+
+    // Sets the positions into the model.
+    mImpl->mVisualModel->SetGlyphPositions( glyphPositions.Begin(),
+                                            numberOfGlyphs );
 
-    viewUpdated = true;
+    // Sets the actual size.
+    mImpl->mVisualModel->SetActualSize( layoutSize );
   }
 
   return viewUpdated;