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)
1  2 
dali-toolkit/internal/text/visual-model.cpp
dali-toolkit/internal/text/visual-model.h

@@@ -73,36 -73,56 +73,56 @@@ void VisualModel::SetGlyphs( const Glyp
                               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 )
+   {
+     modelGlyphs.Clear();
+     modelGlyphsToCharacters.Clear();
+     modelCharactersToGlyph.Clear();
+     modelCharactersPerGlyph.Clear();
+   }
+   else
    {
-     const Length numberOfCharacters = *it;
+     if( NULL != glyphs )
+     {
+       modelGlyphs.Resize( numberOfGlyphs );
+       memcpy( modelGlyphs.Begin(), glyphs, numberOfGlyphs * sizeof( GlyphInfo ) );
+     }
  
-     for( Length index = 0u; index < numberOfCharacters; ++index, ++totalNumberOfCharacters )
+     if( NULL != characterIndices )
      {
-       modelCharactersToGlyph.PushBack( glyphIndex );
+       modelGlyphsToCharacters.Resize( numberOfGlyphs );
+       memcpy( modelGlyphsToCharacters.Begin(), characterIndices, numberOfGlyphs * sizeof( CharacterIndex ) );
+     }
+     if( NULL != charactersPerGlyph )
+     {
+       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,15 -188,17 +188,22 @@@ void VisualModel::SetGlyphPositions( co
                                       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
 +{
 +  return mImpl->mGlyphPositions.Count();
 +}
 +
  void VisualModel::GetGlyphPositions( Vector2* glyphPositions,
                                       GlyphIndex glyphIndex,
                                       Length numberOfGlyphs ) const
@@@ -196,8 -218,15 +223,15 @@@ void VisualModel::SetLines( const LineR
    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;
@@@ -61,6 -61,9 +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.
    /**
     * @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.
     */
                            Length numberOfGlyphs );
  
    /**
 +   * Retrieves the number of glyph positions set.
 +   *
 +   * @note This may be less than the number of glyphs in the model.
 +   * @return The number of glyphs.
 +   */
 +  Length GetNumberOfGlyphPositions() const;
 +
 +  /**
     * @brief Retrieves the glyph positions.
     *
     * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.
     *
     * 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.
     */