From: Victor Cebollada Date: Tue, 10 Mar 2015 09:35:10 +0000 (+0000) Subject: TextModel - Clear the buffers if the number of items is zero. X-Git-Tag: new_text_0.1~4^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=479e2b5a95c62cf2b6d39c4499e11aab49ded6cb TextModel - Clear the buffers if the number of items is zero. Change-Id: Ib5a7ee7d88b094b5cd8f82a0007a64f8bcde3237 Signed-off-by: Victor Cebollada --- diff --git a/dali-toolkit/internal/text/logical-model.cpp b/dali-toolkit/internal/text/logical-model.cpp index d4746f1..01b03fd 100644 --- a/dali-toolkit/internal/text/logical-model.cpp +++ b/dali-toolkit/internal/text/logical-model.cpp @@ -54,8 +54,16 @@ void LogicalModel::SetText( const Character* const text, Length numberOfCharacters ) { Vector& 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& 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& 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& 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& 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, diff --git a/dali-toolkit/internal/text/logical-model.h b/dali-toolkit/internal/text/logical-model.h index b80e9b2..5d14098 100644 --- a/dali-toolkit/internal/text/logical-model.h +++ b/dali-toolkit/internal/text/logical-model.h @@ -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. */ diff --git a/dali-toolkit/internal/text/visual-model.cpp b/dali-toolkit/internal/text/visual-model.cpp index 73400f0..6351ec3 100644 --- a/dali-toolkit/internal/text/visual-model.cpp +++ b/dali-toolkit/internal/text/visual-model.cpp @@ -73,36 +73,56 @@ void VisualModel::SetGlyphs( const GlyphInfo* glyphs, Length numberOfGlyphs ) { Vector& modelGlyphs = mImpl->mGlyphs; - modelGlyphs.Resize( numberOfGlyphs ); - memcpy( modelGlyphs.Begin(), glyphs, numberOfGlyphs * sizeof( GlyphInfo ) ); - Vector& modelGlyphsToCharacters = mImpl->mGlyphsToCharacters; - modelGlyphsToCharacters.Resize( numberOfGlyphs ); - memcpy( modelGlyphsToCharacters.Begin(), characterIndices, numberOfGlyphs * sizeof( CharacterIndex ) ); - Vector& modelCharactersPerGlyph = mImpl->mCharactersPerGlyph; - modelCharactersPerGlyph.Resize( numberOfGlyphs ); - memcpy( modelCharactersPerGlyph.Begin(), charactersPerGlyph, numberOfGlyphs * sizeof( Length ) ); - - // Build the characters to glyph conversion table. Vector& modelCharactersToGlyph = mImpl->mCharactersToGlyph; - // 1) Reserve some space for the characters to avoid reallocations. - modelCharactersToGlyph.Reserve( static_cast ( static_cast( numberOfGlyphs ) * 1.3f ) ); - - // 2) Traverse the glyphs and set the glyph indices. - GlyphIndex glyphIndex = 0u; - Length totalNumberOfCharacters = 0u; - for( Vector::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 ( static_cast( numberOfGlyphs ) * 1.3f ) ); + + // 2) Traverse the glyphs and set the glyph indices. + GlyphIndex glyphIndex = 0u; + Length totalNumberOfCharacters = 0u; + for( Vector::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& 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 ) ); + } } void VisualModel::GetGlyphPositions( Vector2* glyphPositions, @@ -191,8 +218,15 @@ void VisualModel::SetLines( const LineRun* const lines, Vector& 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; diff --git a/dali-toolkit/internal/text/visual-model.h b/dali-toolkit/internal/text/visual-model.h index ec74764..44e42d6 100644 --- a/dali-toolkit/internal/text/visual-model.h +++ b/dali-toolkit/internal/text/visual-model.h @@ -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. */ @@ -207,6 +212,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. */