TextModel - Create paragraph info for a given range of characters inside a text.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-text-model.cpp
index 10f910c..f07cfdc 100644 (file)
@@ -97,6 +97,8 @@ void ClearModelData( CharacterIndex characterIndex,
 
 void CreateTextModel( const std::string& text,
                       const Size& textArea,
+                      const Vector<FontDescriptionRun>& fontDescriptions,
+                      const LayoutOptions& options,
                       Size& layoutSize,
                       LogicalModelPtr logicalModel,
                       VisualModelPtr visualModel )
@@ -114,7 +116,10 @@ void CreateTextModel( const std::string& text,
   Vector<LineBreakInfo>& lineBreakInfo = logicalModel->mLineBreakInfo;
   lineBreakInfo.Resize( numberOfCharacters );
 
-  SetLineBreakInfo( utf32Characters, lineBreakInfo );
+  SetLineBreakInfo( utf32Characters,
+                    0u,
+                    numberOfCharacters,
+                    lineBreakInfo );
 
   if( 0u == numberOfCharacters )
   {
@@ -142,6 +147,7 @@ void CreateTextModel( const std::string& text,
 
   // 4) Set the font info
   Vector<FontDescriptionRun>& fontDescriptionRuns = logicalModel->mFontDescriptionRuns;
+  fontDescriptionRuns = fontDescriptions;
   Vector<FontRun>& validFonts = logicalModel->mFontRuns;
 
   // The default font id.
@@ -181,6 +187,10 @@ void CreateTextModel( const std::string& text,
                         numberOfCharacters,
                         bidirectionalInfo );
 
+  // Create the paragraph info.
+  logicalModel->CreateParagraphInfo( 0u,
+                                     numberOfCharacters );
+
   // 6) Set character directions.
   Vector<CharacterDirection>& characterDirections = logicalModel->mCharacterDirections;
   if( 0u != bidirectionalInfo.Count() )
@@ -214,30 +224,30 @@ void CreateTextModel( const std::string& text,
   Vector<Length>& charactersPerGlyph = visualModel->mCharactersPerGlyph;
   Vector<GlyphIndex> newParagraphGlyphs;
 
-  const Length currentNumberOfGlyphs = glyphs.Count();
   const Vector<Character>& textToShape = textMirrored ? mirroredUtf32Characters : utf32Characters;
 
   ShapeText( textToShape,
              lineBreakInfo,
              scripts,
              validFonts,
+             0u,
+             0u,
+             numberOfCharacters,
              glyphs,
              glyphsToCharactersMap,
              charactersPerGlyph,
              newParagraphGlyphs );
 
   // Create the 'number of glyphs' per character and the glyph to character conversion tables.
-  visualModel->CreateGlyphsPerCharacterTable( numberOfCharacters );
-  visualModel->CreateCharacterToGlyphTable( numberOfCharacters );
+  visualModel->CreateGlyphsPerCharacterTable( 0u, numberOfCharacters );
+  visualModel->CreateCharacterToGlyphTable( 0u, numberOfCharacters );
 
-  const Length numberOfGlyphs = glyphs.Count() - currentNumberOfGlyphs;
+  const Length numberOfGlyphs = glyphs.Count();
 
   // 8) Get the glyph metrics
   MetricsPtr metrics = Metrics::New( fontClient );
 
-  const GlyphIndex glyphIndex = currentNumberOfGlyphs;
-
-  GlyphInfo* glyphsBuffer = glyphs.Begin() + glyphIndex;
+  GlyphInfo* glyphsBuffer = glyphs.Begin();
   metrics->GetGlyphMetrics( glyphsBuffer, numberOfGlyphs );
 
   // Update the width and advance of all new paragraph characters.
@@ -247,7 +257,7 @@ void CreateTextModel( const std::string& text,
        ++it )
   {
     const GlyphIndex index = *it;
-    GlyphInfo& glyph = *( glyphsBuffer + ( index - glyphIndex ) );
+    GlyphInfo& glyph = *( glyphsBuffer + index );
 
     glyph.xBearing = 0.f;
     glyph.width = 0.f;
@@ -262,27 +272,29 @@ void CreateTextModel( const std::string& text,
   // Set the layout parameters.
   const Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
   const Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
+
   LayoutParameters layoutParameters( textArea,
                                      utf32Characters.Begin(),
                                      lineBreakInfo.Begin(),
                                      wordBreakInfo.Begin(),
                                      ( 0u != characterDirections.Count() ) ? characterDirections.Begin() : NULL,
-                                     glyphs.Count(),
                                      glyphs.Begin(),
                                      glyphsToCharactersMap.Begin(),
-                                     charactersPerGlyph.Begin() );
-
-  // Get the character to glyph conversion table and set into the layout.
-  layoutParameters.charactersToGlyphsBuffer = charactersToGlyph.Begin();
-  // Get the glyphs per character table and set into the layout.
-  layoutParameters.glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
+                                     charactersPerGlyph.Begin(),
+                                     charactersToGlyph.Begin(),
+                                     glyphsPerCharacter.Begin(),
+                                     numberOfGlyphs );
 
   Vector<LineRun>& lines = visualModel->mLines;
 
   Vector<Vector2>& glyphPositions = visualModel->mGlyphPositions;
   glyphPositions.Resize( numberOfGlyphs );
 
-  layoutParameters.isLastNewParagraph = TextAbstraction::IsNewParagraph( *( utf32Characters.Begin() + ( logicalModel->mText.Count() - 1u ) ) );
+  layoutParameters.isLastNewParagraph = TextAbstraction::IsNewParagraph( *( utf32Characters.Begin() + ( numberOfCharacters - 1u ) ) );
+
+  // The initial glyph and the number of glyphs to layout.
+  layoutParameters.startGlyphIndex = 0u;
+  layoutParameters.numberOfGlyphs = numberOfGlyphs;
 
   layoutEngine.LayoutText( layoutParameters,
                            glyphPositions,
@@ -315,9 +327,22 @@ void CreateTextModel( const std::string& text,
                                          0u,
                                          numberOfCharacters );
 
-    // Re-layout the text. Reorder those lines with right to left characters.
-    layoutEngine.ReLayoutRightToLeftLines( layoutParameters,
-                                           glyphPositions );
+    if( options.reorder )
+    {
+      // Re-layout the text. Reorder those lines with right to left characters.
+      layoutEngine.ReLayoutRightToLeftLines( layoutParameters,
+                                             0u,
+                                             numberOfCharacters,
+                                             glyphPositions );
+    }
+  }
+
+  if( options.align )
+  {
+    layoutEngine.Align( textArea,
+                        0u,
+                        numberOfCharacters,
+                        lines );
   }
 }