Merge "TextModel - Clear the buffers if the number of items is zero." into new_text
authorPaul Wisbey <p.wisbey@samsung.com>
Tue, 10 Mar 2015 14:13:45 +0000 (07:13 -0700)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Tue, 10 Mar 2015 14:13:45 +0000 (07:13 -0700)
dali-toolkit/internal/text/logical-model.cpp
dali-toolkit/internal/text/logical-model.h
dali-toolkit/internal/text/visual-model.cpp
dali-toolkit/internal/text/visual-model.h

index d4746f1..01b03fd 100644 (file)
@@ -54,8 +54,16 @@ void LogicalModel::SetText( const Character* const text,
                             Length numberOfCharacters )
 {
   Vector<Character>& modelText = mImpl->mText;
-  modelText.Resize( numberOfCharacters );
-  memcpy( modelText.Begin(), text, numberOfCharacters * sizeof( Character ) );
+
+  if( 0u == numberOfCharacters )
+  {
+    modelText.Clear();
+  }
+  else
+  {
+    modelText.Resize( numberOfCharacters );
+    memcpy( modelText.Begin(), text, numberOfCharacters * sizeof( Character ) );
+  }
 }
 
 Length LogicalModel::GetNumberOfCharacters() const
@@ -80,8 +88,16 @@ void LogicalModel::SetScripts( const ScriptRun* const scripts,
                                Length numberOfRuns )
 {
   Vector<ScriptRun>& scriptRuns = mImpl->mScriptRuns;
-  scriptRuns.Resize( numberOfRuns );
-  memcpy( scriptRuns.Begin(), scripts, numberOfRuns * sizeof( ScriptRun ) );
+
+  if( 0u == numberOfRuns )
+  {
+    scriptRuns.Clear();
+  }
+  else
+  {
+    scriptRuns.Resize( numberOfRuns );
+    memcpy( scriptRuns.Begin(), scripts, numberOfRuns * sizeof( ScriptRun ) );
+  }
 }
 
 Length LogicalModel::GetNumberOfScriptRuns( CharacterIndex characterIndex,
@@ -165,8 +181,16 @@ void LogicalModel::SetFonts( const FontRun* const fonts,
                              Length numberOfRuns )
 {
   Vector<FontRun>& fontRuns = mImpl->mFontRuns;
-  fontRuns.Resize( numberOfRuns );
-  memcpy( fontRuns.Begin(), fonts, numberOfRuns * sizeof( FontRun ) );
+
+  if( 0u == numberOfRuns )
+  {
+    fontRuns.Clear();
+  }
+  else
+  {
+    fontRuns.Resize( numberOfRuns );
+    memcpy( fontRuns.Begin(), fonts, numberOfRuns * sizeof( FontRun ) );
+  }
 }
 
 Length LogicalModel::GetNumberOfFontRuns( CharacterIndex characterIndex,
@@ -248,8 +272,16 @@ void LogicalModel::SetLineBreakInfo( const LineBreakInfo* const lineBreakInfo,
                                      Length length )
 {
   Vector<LineBreakInfo>& modelLineBreakInfo = mImpl->mLineBreakInfo;
-  modelLineBreakInfo.Resize( length );
-  memcpy( modelLineBreakInfo.Begin(), lineBreakInfo, length * sizeof( LineBreakInfo ) );
+
+  if( 0u == length )
+  {
+    modelLineBreakInfo.Clear();
+  }
+  else
+  {
+    modelLineBreakInfo.Resize( length );
+    memcpy( modelLineBreakInfo.Begin(), lineBreakInfo, length * sizeof( LineBreakInfo ) );
+  }
 }
 
 void LogicalModel::GetLineBreakInfo( LineBreakInfo* lineBreakInfo,
@@ -268,8 +300,16 @@ void LogicalModel::SetWordBreakInfo( const WordBreakInfo* const wordBreakInfo,
                                      Length length )
 {
   Vector<WordBreakInfo>& modelWordBreakInfo = mImpl->mWordBreakInfo;
-  modelWordBreakInfo.Resize( length );
-  memcpy( modelWordBreakInfo.Begin(), wordBreakInfo, length * sizeof( WordBreakInfo ) );
+
+  if( 0u == length )
+  {
+    modelWordBreakInfo.Clear();
+  }
+  else
+  {
+    modelWordBreakInfo.Resize( length );
+    memcpy( modelWordBreakInfo.Begin(), wordBreakInfo, length * sizeof( WordBreakInfo ) );
+  }
 }
 
 void LogicalModel::GetWordBreakInfo( WordBreakInfo* wordBreakInfo,
index b80e9b2..5d14098 100644 (file)
@@ -62,6 +62,8 @@ public:
   /**
    * @brief Replaces any text previously set.
    *
+   * @note If the number of characters is zero the text buffer is cleared.
+   *
    * @param[in] text An array of UTF-32 characters.
    * @param[in] numberOfCharacters The length of the array.
    */
@@ -105,6 +107,8 @@ public:
    *
    * A run is a group of consecutive characters. A script run contains the script for a run.
    *
+   * @note If the number of runs is zero the script buffer is cleared.
+   *
    * @param[in] scripts Pointer to a buffer with all the script runs.
    * @param[in] numberOfRuns The number of script runs.
    */
@@ -154,6 +158,8 @@ public:
    *
    * A run is a group of consecutive characters. A font run contains the font id for a run.
    *
+   * @note If the number of runs is zero the font buffer is cleared.
+   *
    * @param[in] fonts Pointer to a buffer with all the font runs.
    * @param[in] numberOfRuns The number of font runs.
    */
@@ -205,6 +211,8 @@ public:
    *
    * Replaces any line break info previously set.
    *
+   * @note If the @length is zero the break info buffer is cleared.
+   *
    * @param[in] lineBreakInfo Pointer to a buffer with the line break info.
    * @param[in] length The size of the buffer.
    */
@@ -249,6 +257,8 @@ public:
    *
    * Replaces any word break info previously set.
    *
+   * @note If the @length is zero the break info buffer is cleared.
+   *
    * @param[in] wordBreakInfo Pointer to a buffer with the word break info.
    * @param[in] length The size of the buffer.
    */
@@ -300,6 +310,8 @@ public:
    * In terms of the bidirectional algorithm, a 'paragraph' is understood as a run of characters between Paragraph Separators or appropriate Newline Functions.
    * A 'paragraph' may also be determined by higher-level protocols like a mark-up tag.
    *
+   * @note If the number of runs is zero the bidirectional info buffer is cleared.
+   *
    * @param[in] bidirectionalInfo Pointer to a buffer with all the bidirectional info runs.
    * @param[in] numberOfRuns The number of bidirectional info runs.
    */
@@ -355,6 +367,8 @@ public:
    *
    * Replaces any map tables previously set.
    *
+   * @note If the number of runs is zero the bidirectional info buffer is cleared.
+   *
    * @param[in] bidirectionalInfo Pointer to a buffer with all the bidirectional info runs.
    * @param[in] numberOfRuns The number of bidirectional info runs.
    */
index 4ee9015..9daa2d1 100644 (file)
@@ -73,36 +73,56 @@ void VisualModel::SetGlyphs( const GlyphInfo* glyphs,
                              Length numberOfGlyphs )
 {
   Vector<GlyphInfo>& modelGlyphs = mImpl->mGlyphs;
-  modelGlyphs.Resize( numberOfGlyphs );
-  memcpy( modelGlyphs.Begin(), glyphs, numberOfGlyphs * sizeof( GlyphInfo ) );
-
   Vector<CharacterIndex>& modelGlyphsToCharacters = mImpl->mGlyphsToCharacters;
-  modelGlyphsToCharacters.Resize( numberOfGlyphs );
-  memcpy( modelGlyphsToCharacters.Begin(), characterIndices, numberOfGlyphs * sizeof( CharacterIndex ) );
-
   Vector<Length>& modelCharactersPerGlyph = mImpl->mCharactersPerGlyph;
-  modelCharactersPerGlyph.Resize( numberOfGlyphs );
-  memcpy( modelCharactersPerGlyph.Begin(), charactersPerGlyph, numberOfGlyphs * sizeof( Length ) );
-
-  // Build the characters to glyph conversion table.
   Vector<GlyphIndex>& modelCharactersToGlyph = mImpl->mCharactersToGlyph;
 
-  // 1) Reserve some space for the characters to avoid reallocations.
-  modelCharactersToGlyph.Reserve( static_cast<Length> ( static_cast<float>( numberOfGlyphs ) * 1.3f ) );
-
-  // 2) Traverse the glyphs and set the glyph indices.
-  GlyphIndex glyphIndex = 0u;
-  Length totalNumberOfCharacters = 0u;
-  for( Vector<Length>::ConstIterator it = modelCharactersPerGlyph.Begin(),
-         endIt = modelCharactersPerGlyph.End();
-       it != endIt;
-       ++it, ++glyphIndex )
+  if( 0u == numberOfGlyphs )
   {
-    const Length numberOfCharacters = *it;
+    modelGlyphs.Clear();
+    modelGlyphsToCharacters.Clear();
+    modelCharactersToGlyph.Clear();
+    modelCharactersPerGlyph.Clear();
+  }
+  else
+  {
+    if( NULL != glyphs )
+    {
+      modelGlyphs.Resize( numberOfGlyphs );
+      memcpy( modelGlyphs.Begin(), glyphs, numberOfGlyphs * sizeof( GlyphInfo ) );
+    }
+
+    if( NULL != characterIndices )
+    {
+      modelGlyphsToCharacters.Resize( numberOfGlyphs );
+      memcpy( modelGlyphsToCharacters.Begin(), characterIndices, numberOfGlyphs * sizeof( CharacterIndex ) );
+    }
 
-    for( Length index = 0u; index < numberOfCharacters; ++index, ++totalNumberOfCharacters )
+    if( NULL != charactersPerGlyph )
     {
-      modelCharactersToGlyph.PushBack( glyphIndex );
+      modelCharactersPerGlyph.Resize( numberOfGlyphs );
+      memcpy( modelCharactersPerGlyph.Begin(), charactersPerGlyph, numberOfGlyphs * sizeof( Length ) );
+
+      // Build the characters to glyph conversion table.
+
+      // 1) Reserve some space for the characters to avoid reallocations.
+      modelCharactersToGlyph.Reserve( static_cast<Length> ( static_cast<float>( numberOfGlyphs ) * 1.3f ) );
+
+      // 2) Traverse the glyphs and set the glyph indices.
+      GlyphIndex glyphIndex = 0u;
+      Length totalNumberOfCharacters = 0u;
+      for( Vector<Length>::ConstIterator it = modelCharactersPerGlyph.Begin(),
+             endIt = modelCharactersPerGlyph.End();
+           it != endIt;
+           ++it, ++glyphIndex )
+      {
+        const Length numberOfCharacters = *it;
+
+        for( Length index = 0u; index < numberOfCharacters; ++index, ++totalNumberOfCharacters )
+        {
+          modelCharactersToGlyph.PushBack( glyphIndex );
+        }
+      }
     }
   }
 }
@@ -168,8 +188,15 @@ void VisualModel::SetGlyphPositions( const Vector2* glyphPositions,
                                      Length numberOfGlyphs )
 {
   Vector<Vector2>& modelPositions = mImpl->mGlyphPositions;
-  modelPositions.Resize( numberOfGlyphs );
-  memcpy( modelPositions.Begin(), glyphPositions, numberOfGlyphs * sizeof( Vector2 ) );
+  if( 0u == numberOfGlyphs )
+  {
+    modelPositions.Clear();
+  }
+  else
+  {
+    modelPositions.Resize( numberOfGlyphs );
+    memcpy( modelPositions.Begin(), glyphPositions, numberOfGlyphs * sizeof( Vector2 ) );
+  }
 }
 
 Length VisualModel::GetNumberOfGlyphPositions() const
@@ -196,8 +223,15 @@ void VisualModel::SetLines( const LineRun* const lines,
   Vector<LineRun>& modelLines = mImpl->mLines;
   GetLineCache& lineCache = mImpl->mGetLineCache;
 
-  modelLines.Resize( numberOfLines );
-  memcpy( modelLines.Begin(), lines, numberOfLines * sizeof( LineRun ) );
+  if( 0u == numberOfLines )
+  {
+    modelLines.Clear();
+  }
+  else
+  {
+    modelLines.Resize( numberOfLines );
+    memcpy( modelLines.Begin(), lines, numberOfLines * sizeof( LineRun ) );
+  }
 
   // Clear the get line cache.
   lineCache.glyphIndex = 0u;
index 5c57e2d..9593fd8 100644 (file)
@@ -61,6 +61,9 @@ public:
   /**
    * @brief Replaces any glyphs previously set.
    *
+   * @note If the number of glyphs is zero, all buffers are cleared.
+   * @note If one pointer is NULL and the number of glyphs is not zero, the buffer is not touched.
+   *
    * @param[in] glyphs An array of glyphs in the visual order.
    * @param[in] characterIndices An array containing the first character in the logical model that each glyph relates to.
    * @param[in] charactersPerGlyph An array containing the number of characters per glyph.
@@ -171,6 +174,8 @@ public:
   /**
    * @brief Replaces any glyph positions previously set.
    *
+   * @note If the number of glyphs is zero the position buffer is cleared.
+   *
    * @param[in] glyphPositions An array of visual positions for each glyph.
    * @param[in] numberOfGlyphs The number of positions.
    */
@@ -215,6 +220,8 @@ public:
    *
    * Every line is an item run containing the index to the first glyph of the line and the number of glyphs.
    *
+   * @note If the number of lines is zero or the pointer is NULL, the lines buffer is cleared.
+   *
    * @param[in] lines Pointer to a buffer containing all the line runs.
    * @param[in] numberOfLines The number of lines in the buffer.
    */