Merge "Multi-line layout." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / shaper.cpp
index 55101eb..0f4a114 100644 (file)
@@ -19,8 +19,8 @@
 #include <dali-toolkit/internal/text/shaper.h>
 
 // EXTERNAL INCLUDES
-#include <dali/public-api/text-abstraction/script.h>
-#include <dali/public-api/text-abstraction/shaping.h>
+#include <dali/devel-api/text-abstraction/script.h>
+#include <dali/devel-api/text-abstraction/shaping.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/text/font-run.h>
@@ -49,7 +49,8 @@ void ShapeText( const Vector<Character>& text,
                 const Vector<FontRun>& fonts,
                 Vector<GlyphInfo>& glyphs,
                 Vector<CharacterIndex>& glyphToCharacterMap,
-                Vector<Length>& charactersPerGlyph )
+                Vector<Length>& charactersPerGlyph,
+                Vector<GlyphIndex>& newParagraphGlyphs )
 {
   const Length numberOfCharacters = text.Count();
 
@@ -74,7 +75,7 @@ void ShapeText( const Vector<Character>& text,
 
   // The text needs to be split in chunks of consecutive characters.
   // Each chunk must contain characters with the same font id and script set.
-  // A chunk of consecutive characters must not contain a LINE_MUST_BREAK, if there is one a new chunk have to be created.
+  // A chunk of consecutive characters must not contain a LINE_MUST_BREAK, if there is one a new chunk has to be created.
 
   TextAbstraction::Shaping shaping = TextAbstraction::Shaping::Get();
 
@@ -100,8 +101,8 @@ void ShapeText( const Vector<Character>& text,
   // The actual number of glyphs.
   Length totalNumberOfGlyphs = 0u;
 
-  const Character* textBuffer = text.Begin();
-  const LineBreakInfo* lineBreakInfoBuffer = lineBreakInfo.Begin();
+  const Character* const textBuffer = text.Begin();
+  const LineBreakInfo* const lineBreakInfoBuffer = lineBreakInfo.Begin();
   GlyphInfo* glyphsBuffer = glyphs.Begin();
   CharacterIndex* glyphToCharacterMapBuffer = glyphToCharacterMap.Begin();
 
@@ -121,27 +122,26 @@ void ShapeText( const Vector<Character>& text,
 
     // Check if there is a line must break.
     bool mustBreak = false;
+
+    // Check if the current index is a new paragraph character.
+    // A new paragraph character is going to be shaped in order to not to mess the conversion tables.
+    // However, the metrics need to be changed in order to not to draw a square.
+    bool isNewParagraph = false;
+
     for( CharacterIndex index = previousIndex; index < currentIndex; ++index )
     {
       mustBreak = TextAbstraction::LINE_MUST_BREAK == *( lineBreakInfoBuffer + index );
       if( mustBreak )
       {
-        currentIndex = index;
+        isNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + index ) );
+        currentIndex = index + 1u;
         break;
       }
     }
 
-    // Check if the current index is a white space. Do not want to shape a \n.
-    // The last character is always a must-break even if it's not a \n.
-    Length numberOfCharactersToShape = currentIndex - previousIndex;
-    if( mustBreak && !TextAbstraction::IsWhiteSpace( *( textBuffer + currentIndex ) ) )
-    {
-      ++numberOfCharactersToShape;
-    }
-
     // Shape the text for the current chunk.
     const Length numberOfGlyphs = shaping.Shape( textBuffer + previousIndex,
-                                                 numberOfCharactersToShape,
+                                                 ( currentIndex - previousIndex ), // The number of characters to shape.
                                                  currentFontId,
                                                  currentScript );
 
@@ -164,6 +164,13 @@ void ShapeText( const Vector<Character>& text,
     shaping.GetGlyphs( glyphsBuffer + glyphIndex,
                        glyphToCharacterMapBuffer + glyphIndex );
 
+    if( isNewParagraph )
+    {
+      // Add the index of the new paragraph glyph to a vector.
+      // Their metrics will be updated in a following step.
+      newParagraphGlyphs.PushBack( totalNumberOfGlyphs - 1u );
+    }
+
     // Update indices.
     if( 0u != glyphIndex )
     {
@@ -184,8 +191,8 @@ void ShapeText( const Vector<Character>& text,
       ++scriptRunIt;
     }
 
-    // Update the previous index. Jumps the \n if needed.
-    previousIndex = mustBreak ? currentIndex + 1u : currentIndex;
+    // Update the previous index.
+    previousIndex = currentIndex;
   }
 
   // Add the number of characters per glyph.
@@ -207,14 +214,6 @@ void ShapeText( const Vector<Character>& text,
   glyphToCharacterMap.Resize( totalNumberOfGlyphs );
 }
 
-void ShapeText( const LogicalModel& logicalModel,
-                VisualModel& visualModel,
-                CharacterIndex characterIndex,
-                Length numberOfCharactersToRemove,
-                Length numberOfCharactersToInsert )
-{
-}
-
 } // namespace Text
 
 } // namespace Toolkit