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
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,
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,
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,
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,
/**
* @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.
*/
*
* 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.
*/
*
* 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.
*/
*
* 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.
*/
*
* 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.
*/
* 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.
*/
*
* 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.
*/
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 );
+ }
+ }
}
}
}
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 ) );
+ }
}
void VisualModel::GetGlyphPositions( Vector2* glyphPositions,
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;
/**
* @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.
*/
*
* 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.
*/