Fix for Shaping. 15/36415/2
authorVictor Cebollada <v.cebollada@samsung.com>
Fri, 6 Mar 2015 07:49:03 +0000 (07:49 +0000)
committerVictor Cebollada <v.cebollada@samsung.com>
Fri, 6 Mar 2015 10:49:57 +0000 (10:49 +0000)
  - In a text with different scripts, the text is shaped in runs of
    characters with the same script. Adpator return the character
    index of each glyph starting always by 0. Toolkit was not
    updating the indices given by the adaptor for the runs after the
    first one.
  - characterIndices renamed to glyphsToCharactersMap.
  - Adaptor retrieves the glyphsToCharactersMap. Toolkit was setting
    the glyphsToCharactersMap to the charactersPerGlyph vector.

Change-Id: I9c74741fadb6d68bca29629ff79ed7bc48dd2840
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
dali-toolkit/internal/text/shaper.cpp
dali-toolkit/internal/text/shaper.h
dali-toolkit/internal/text/text-controller.cpp

index e70750c..eaaedeb 100644 (file)
@@ -48,7 +48,7 @@ void ShapeText( const Vector<Character>& text,
                 const Vector<ScriptRun>& scripts,
                 const Vector<FontRun>& fonts,
                 Vector<GlyphInfo>& glyphs,
                 const Vector<ScriptRun>& scripts,
                 const Vector<FontRun>& fonts,
                 Vector<GlyphInfo>& glyphs,
-                Vector<CharacterIndex>& characterIndices,
+                Vector<CharacterIndex>& glyphToCharacterMap,
                 Vector<Length>& charactersPerGlyph )
 {
   const Length numberOfCharacters = text.Count();
                 Vector<Length>& charactersPerGlyph )
 {
   const Length numberOfCharacters = text.Count();
@@ -95,7 +95,7 @@ void ShapeText( const Vector<Character>& text,
 
   Length numberOfGlyphsReserved = static_cast<Length>( numberOfCharacters * 1.3f );
   glyphs.Resize( numberOfGlyphsReserved );
 
   Length numberOfGlyphsReserved = static_cast<Length>( numberOfCharacters * 1.3f );
   glyphs.Resize( numberOfGlyphsReserved );
-  charactersPerGlyph.Resize( numberOfGlyphsReserved );
+  glyphToCharacterMap.Resize( numberOfGlyphsReserved );
 
   // The actual number of glyphs.
   Length totalNumberOfGlyphs = 0u;
 
   // The actual number of glyphs.
   Length totalNumberOfGlyphs = 0u;
@@ -103,7 +103,7 @@ void ShapeText( const Vector<Character>& text,
   const Character* textBuffer = text.Begin();
   const LineBreakInfo* lineBreakInfoBuffer = lineBreakInfo.Begin();
   GlyphInfo* glyphsBuffer = glyphs.Begin();
   const Character* textBuffer = text.Begin();
   const LineBreakInfo* lineBreakInfoBuffer = lineBreakInfo.Begin();
   GlyphInfo* glyphsBuffer = glyphs.Begin();
-  Length* charactersPerGlyphBuffer = charactersPerGlyph.Begin();
+  CharacterIndex* glyphToCharacterMapBuffer = glyphToCharacterMap.Begin();
 
   // Traverse the characters and shape the text.
   for( previousIndex = 0; previousIndex < numberOfCharacters; )
 
   // Traverse the characters and shape the text.
   for( previousIndex = 0; previousIndex < numberOfCharacters; )
@@ -153,16 +153,26 @@ void ShapeText( const Vector<Character>& text,
       // Resize the vectors to get enough space.
       numberOfGlyphsReserved = static_cast<Length>( totalNumberOfGlyphs * 1.3f );
       glyphs.Resize( numberOfGlyphsReserved );
       // Resize the vectors to get enough space.
       numberOfGlyphsReserved = static_cast<Length>( totalNumberOfGlyphs * 1.3f );
       glyphs.Resize( numberOfGlyphsReserved );
-      charactersPerGlyph.Resize( numberOfGlyphsReserved );
+      glyphToCharacterMap.Resize( numberOfGlyphsReserved );
 
       // Iterators are not valid anymore, set them again.
       glyphsBuffer = glyphs.Begin();
 
       // Iterators are not valid anymore, set them again.
       glyphsBuffer = glyphs.Begin();
-      charactersPerGlyphBuffer = charactersPerGlyph.Begin();
+      glyphToCharacterMapBuffer = glyphToCharacterMap.Begin();
     }
 
     // Retrieve the glyphs and the glyph to character conversion map.
     shaping.GetGlyphs( glyphsBuffer + glyphIndex,
     }
 
     // Retrieve the glyphs and the glyph to character conversion map.
     shaping.GetGlyphs( glyphsBuffer + glyphIndex,
-                       charactersPerGlyphBuffer + glyphIndex );
+                       glyphToCharacterMapBuffer + glyphIndex );
+
+    // Update indices.
+    if( 0u != glyphIndex )
+    {
+      for( Length index = glyphIndex; index < glyphIndex + numberOfGlyphs; ++index )
+      {
+        CharacterIndex& characterIndex = *( glyphToCharacterMapBuffer + index );
+        characterIndex += previousIndex;
+      }
+    }
 
     // Update the iterators to get the next font or script run.
     if( currentIndex == fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters )
 
     // Update the iterators to get the next font or script run.
     if( currentIndex == fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters )
@@ -178,19 +188,23 @@ void ShapeText( const Vector<Character>& text,
     previousIndex = mustBreak ? currentIndex + 1u : currentIndex;
   }
 
     previousIndex = mustBreak ? currentIndex + 1u : currentIndex;
   }
 
-  characterIndices.Reserve( totalNumberOfGlyphs );
-  CharacterIndex characterIndex = 0u;
-  characterIndices.PushBack( characterIndex );
-  for( Length index = 0u, length = totalNumberOfGlyphs - 1u; index < length; ++index )
+  // Add the number of characters per glyph.
+  charactersPerGlyph.Reserve( totalNumberOfGlyphs );
+  previousIndex = 0u;
+  for( Length index = 1u; index < totalNumberOfGlyphs; ++index )
   {
   {
-    characterIndex += *( charactersPerGlyphBuffer + index );
-    characterIndices.PushBack( characterIndex );
+    const CharacterIndex characterIndex = *( glyphToCharacterMapBuffer + index );
+
+    charactersPerGlyph.PushBack( characterIndex - previousIndex );
+
+    previousIndex = characterIndex;
   }
 
   }
 
+  charactersPerGlyph.PushBack( numberOfCharacters - previousIndex );
+
   // Resize the vectors to set the right number of items.
   glyphs.Resize( totalNumberOfGlyphs );
   // Resize the vectors to set the right number of items.
   glyphs.Resize( totalNumberOfGlyphs );
-  // characterIndices.Resize( totalNumberOfGlyphs );
-  charactersPerGlyph.Resize( totalNumberOfGlyphs );
+  glyphToCharacterMap.Resize( totalNumberOfGlyphs );
 }
 
 void ShapeText( const LogicalModel& logicalModel,
 }
 
 void ShapeText( const LogicalModel& logicalModel,
index 441465c..c1ccfb5 100644 (file)
@@ -43,7 +43,7 @@ class VisualModel;
  * @param[in] scripts Vector containing the script runs for the whole text.
  * @param[in] fonts Vector with validated fonts.
  * @param[out] glyphs Vector of glyphs in the visual order.
  * @param[in] scripts Vector containing the script runs for the whole text.
  * @param[in] fonts Vector with validated fonts.
  * @param[out] glyphs Vector of glyphs in the visual order.
- * @param[out] characterIndices Vector containing the first character in the logical model that each glyph relates to.
+ * @param[out] glyphToCharacterMap Vector containing the first character in the logical model that each glyph relates to.
  * @param[out] charactersPerGlyph Vector containing the number of characters per glyph.
  */
 void ShapeText( const Vector<Character>& text,
  * @param[out] charactersPerGlyph Vector containing the number of characters per glyph.
  */
 void ShapeText( const Vector<Character>& text,
@@ -51,7 +51,7 @@ void ShapeText( const Vector<Character>& text,
                 const Vector<ScriptRun>& scripts,
                 const Vector<FontRun>& fonts,
                 Vector<GlyphInfo>& glyphs,
                 const Vector<ScriptRun>& scripts,
                 const Vector<FontRun>& fonts,
                 Vector<GlyphInfo>& glyphs,
-                Vector<CharacterIndex>& characterIndices,
+                Vector<CharacterIndex>& glyphToCharacterMap,
                 Vector<Length>& charactersPerGlyph );
 
 /**
                 Vector<Length>& charactersPerGlyph );
 
 /**
index f12ba5b..67f91c4 100644 (file)
@@ -435,7 +435,7 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations )
   }
 
   Vector<GlyphInfo> glyphs;
   }
 
   Vector<GlyphInfo> glyphs;
-  Vector<CharacterIndex> characterIndices;
+  Vector<CharacterIndex> glyphsToCharactersMap;
   Vector<Length> charactersPerGlyph;
   if( SHAPE_TEXT & operations )
   {
   Vector<Length> charactersPerGlyph;
   if( SHAPE_TEXT & operations )
   {
@@ -445,7 +445,7 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations )
                scripts,
                fonts,
                glyphs,
                scripts,
                fonts,
                glyphs,
-               characterIndices,
+               glyphsToCharactersMap,
                charactersPerGlyph );
   }
 
                charactersPerGlyph );
   }
 
@@ -461,14 +461,14 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations )
       const Length numberOfGlyphs = mImpl->mVisualModel->GetNumberOfGlyphs();
 
       glyphs.Resize( numberOfGlyphs );
       const Length numberOfGlyphs = mImpl->mVisualModel->GetNumberOfGlyphs();
 
       glyphs.Resize( numberOfGlyphs );
-      characterIndices.Resize( numberOfGlyphs );
+      glyphsToCharactersMap.Resize( numberOfGlyphs );
       charactersPerGlyph.Resize( numberOfGlyphs );
 
       mImpl->mVisualModel->GetGlyphs( glyphs.Begin(),
                                       0u,
                                       numberOfGlyphs );
 
       charactersPerGlyph.Resize( numberOfGlyphs );
 
       mImpl->mVisualModel->GetGlyphs( glyphs.Begin(),
                                       0u,
                                       numberOfGlyphs );
 
-      mImpl->mVisualModel->GetGlyphToCharacterMap( characterIndices.Begin(),
+      mImpl->mVisualModel->GetGlyphToCharacterMap( glyphsToCharactersMap.Begin(),
                                                    0u,
                                                    numberOfGlyphs );
 
                                                    0u,
                                                    numberOfGlyphs );
 
@@ -480,7 +480,7 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations )
     // Update the visual model
     mImpl->mLayoutEngine.UpdateVisualModel( size,
                                             glyphs,
     // Update the visual model
     mImpl->mLayoutEngine.UpdateVisualModel( size,
                                             glyphs,
-                                            characterIndices,
+                                            glyphsToCharactersMap,
                                             charactersPerGlyph,
                                             *mImpl->mVisualModel );
 
                                             charactersPerGlyph,
                                             *mImpl->mVisualModel );