visualModel->mGlyphsPerCharacter.Clear();
visualModel->mGlyphPositions.Clear();
visualModel->mLines.Clear();
- visualModel->mColorRuns.Clear();
visualModel->ClearCaches();
}
Vector4 color; ///< The color of the characters.
};
-struct ColorGlyphRun
-{
- GlyphRun glyphRun; ///< The initial glyph index and the number of glyphs of the run.
- Vector4 color; ///< The color of the glyphs.
-};
-
} // namespace Text
} // namespace Toolkit
namespace Text
{
-void SetColorSegmentationInfo( const Vector<ColorRun>& characterColorRuns,
+/**
+ * @brief Finds a color in the vector of colors.
+ * It inserts the color in the vector if it's not in.
+ *
+ * @param[in,out] colors The vector of colors.
+ * @param[in] color The color to find.
+ *
+ * @return The index where the color is in the vector.
+ */
+ColorIndex FindColor( Vector<Vector4>& colors,
+ const Vector4& color )
+{
+ ColorIndex index = 1u;
+ for( Vector<Vector4>::Iterator it = colors.Begin(),
+ endIt = colors.End();
+ it != endIt;
+ ++it )
+ {
+ if( color == *it )
+ {
+ return index;
+ }
+
+ ++index;
+ }
+
+ colors.PushBack( color );
+
+ return index;
+}
+
+void SetColorSegmentationInfo( const Vector<ColorRun>& colorRuns,
const Vector<GlyphIndex>& charactersToGlyph,
const Vector<Length>& glyphsPerCharacter,
- Vector<ColorGlyphRun>& glyphColorRuns )
+ CharacterIndex startCharacterIndex,
+ GlyphIndex startGlyphIndex,
+ Length numberOfCharacters,
+ Vector<Vector4>& colors,
+ Vector<ColorIndex>& colorIndices )
{
- const VectorBase::SizeType numberOfColorRuns = characterColorRuns.Count();
-
- if( 0u == numberOfColorRuns )
+ if( 0u == charactersToGlyph.Count() )
{
- // Nothing to do.
+ // Nothing to do if there is no text.
return;
}
- // Resize the color runs for the glyphs.
- glyphColorRuns.Resize( numberOfColorRuns );
-
// Get pointers to the buffers.
- ColorGlyphRun* glyphColorRunsBuffer = glyphColorRuns.Begin();
const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
+ // Calculate the number of glyphs to insert.
+ const CharacterIndex lastCharacterIndex = startCharacterIndex + numberOfCharacters - 1u;
+ const Length numberOfNewGlyphs = *( charactersToGlyphBuffer + lastCharacterIndex ) + *( glyphsPerCharacterBuffer + lastCharacterIndex ) - *( charactersToGlyphBuffer + startCharacterIndex );
+
+ // Reserve space for the new color indices.
+ Vector<ColorIndex> newColorIndices;
+ newColorIndices.Resize( numberOfNewGlyphs );
+
+ ColorIndex* newColorIndicesBuffer = newColorIndices.Begin();
+
// Convert from characters to glyphs.
Length index = 0u;
- for( Vector<ColorRun>::ConstIterator it = characterColorRuns.Begin(),
- endIt = characterColorRuns.End();
+ for( Vector<ColorRun>::ConstIterator it = colorRuns.Begin(),
+ endIt = colorRuns.End();
it != endIt;
++it, ++index )
{
const ColorRun& colorRun = *it;
- if( 0u < colorRun.characterRun.numberOfCharacters )
+ if( ( startCharacterIndex < colorRun.characterRun.characterIndex + colorRun.characterRun.numberOfCharacters ) &&
+ ( colorRun.characterRun.characterIndex < startCharacterIndex + numberOfCharacters ) )
{
- // Get the next color glyph run.
- ColorGlyphRun& colorGlyphRun = *( glyphColorRunsBuffer + index );
- colorGlyphRun.color = colorRun.color;
-
- // Convert the color run index from character to glyph.
- colorGlyphRun.glyphRun.glyphIndex = *( charactersToGlyphBuffer + colorRun.characterRun.characterIndex );
-
- // Get the index to the last character of the run.
- const CharacterIndex lastIndex = colorRun.characterRun.characterIndex + colorRun.characterRun.numberOfCharacters - 1u;
-
- // Calculate the number of glyphs.
- colorGlyphRun.glyphRun.numberOfGlyphs = *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - colorGlyphRun.glyphRun.glyphIndex;
+ if( 0u < colorRun.characterRun.numberOfCharacters )
+ {
+ // Find the color index.
+ const ColorIndex colorIndex = FindColor( colors, colorRun.color );
+
+ // Get the index to the last character of the run.
+ const CharacterIndex lastIndex = colorRun.characterRun.characterIndex + colorRun.characterRun.numberOfCharacters - 1u;
+
+ const GlyphIndex glyphIndex = std::max( startGlyphIndex, *( charactersToGlyphBuffer + colorRun.characterRun.characterIndex ) ) - startGlyphIndex;
+ // Get the number of glyphs of the run.
+ const Length lastGlyphIndexPlusOne = std::min( numberOfNewGlyphs, *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex );
+
+ // Set the indices.
+ for( GlyphIndex i = glyphIndex; i < lastGlyphIndexPlusOne; ++i )
+ {
+ *( newColorIndicesBuffer + i ) = colorIndex;
+ }
+ }
}
}
+
+ // Insert the new indices.
+ colorIndices.Insert( colorIndices.Begin() + startGlyphIndex,
+ newColorIndices.Begin(),
+ newColorIndices.End() );
}
} // namespace Text
/**
* @brief Creates color glyph runs.
*
- * @param[in] characterColorRuns The color runs in characters (set in the mark-up string).
+ * @param[in] colorRuns The color runs in characters (set in the mark-up string).
* @param[in] charactersToGlyph Conversion table from characters to glyphs.
* @param[in] glyphsPerCharacter Table with the number of glyphs for each character.
- * @param[out] glyphColorRuns The color runs in glyphs.
+ * @param[in] startCharacterIndex The character from where the text is shaped.
+ * @param[in] startGlyphIndex The glyph from where the text is shaped.
+ * @param[in] numberOfCharacters The number of characters to be shaped.
+ * @param[out] colors The vector of colors.
+ * @param[out] colorIndices Indices to the vector of colors.
*/
-void SetColorSegmentationInfo( const Vector<ColorRun>& characterColorRuns,
+void SetColorSegmentationInfo( const Vector<ColorRun>& colorRuns,
const Vector<GlyphIndex>& charactersToGlyph,
const Vector<Length>& glyphsPerCharacter,
- Vector<ColorGlyphRun>& glyphColorRuns );
+ CharacterIndex startCharacterIndex,
+ GlyphIndex startGlyphIndex,
+ Length numberOfCharacters,
+ Vector<Vector4>& colors,
+ Vector<ColorIndex>& colorIndices );
} // namespace Text
width( TextAbstraction::FontWidth::NORMAL ),
slant( TextAbstraction::FontSlant::NORMAL ),
size( 0.f ),
+ isDefaultColor( true ),
familyDefined( false ),
weightDefined( false ),
widthDefined( false ),
FontSlant slant; ///< The font's slant.
float size; ///< The font's size.
- bool familyDefined : 1; ///< Whether the font's family is defined.
- bool weightDefined : 1; ///< Whether the font's weight is defined.
- bool widthDefined : 1; ///< Whether the font's width is defined.
- bool slantDefined : 1; ///< Whether the font's slant is defined.
- bool sizeDefined : 1; ///< Whether the font's size is defined.
+ bool isDefaultColor : 1; ///< Whether the text's color is the default.
+ bool familyDefined : 1; ///< Whether the font's family is defined.
+ bool weightDefined : 1; ///< Whether the font's weight is defined.
+ bool widthDefined : 1; ///< Whether the font's width is defined.
+ bool slantDefined : 1; ///< Whether the font's slant is defined.
+ bool sizeDefined : 1; ///< Whether the font's size is defined.
};
} // namespace Text
if( colorOverriden )
{
style.textColor = ( *( colorRunsBuffer + colorIndex ) ).color;
+ style.isDefaultColor = false;
}
// Reset the run index.
style.size = static_cast<float>( fontDescriptionRun.size ) / 64.f;
style.sizeDefined = true;
}
-
- // Reset the run index.
- runIndex = 0u;
}
void LogicalModel::ClearFontDescriptionRuns()
void AddGlyphs( Text::ViewInterface& view,
const Vector<Vector2>& positions,
const Vector<GlyphInfo>& glyphs,
- const Vector<Vector4>& colors,
+ const Vector4& defaultColor,
+ const Vector4* const colorsBuffer,
+ const ColorIndex* const colorIndicesBuffer,
int depth )
{
AtlasManager::AtlasSlot slot;
const Vector4& underlineColor( view.GetUnderlineColor() );
const float underlineHeight( view.GetUnderlineHeight() );
+ const bool useDefaultColor = ( NULL == colorsBuffer );
+
// Get the underline runs.
const Length numberOfUnderlineRuns = view.GetNumberOfUnderlineRuns();
Vector<GlyphRun> underlineRuns;
Vector< TextCacheEntry > newTextCache;
const GlyphInfo* const glyphsBuffer = glyphs.Begin();
const Vector2* const positionsBuffer = positions.Begin();
- const Vector4* const colorsBuffer = colors.Begin();
for( uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i )
{
}
// Get the color of the character.
- const Vector4& color = *( colorsBuffer + i );
+ const ColorIndex colorIndex = useDefaultColor ? 0u : *( colorIndicesBuffer + i );
+ const Vector4& color = ( useDefaultColor || ( 0u == colorIndex ) ) ? defaultColor : *( colorsBuffer + colorIndex - 1u );
for( unsigned int index = 0u, size = newMesh.mVertices.Count();
index < size;
Vector<Vector2> positions;
positions.Resize( numberOfGlyphs );
- Vector<Vector4> colors;
- colors.Resize( numberOfGlyphs, view.GetTextColor() );
-
numberOfGlyphs = view.GetGlyphs( glyphs.Begin(),
positions.Begin(),
- colors.Begin(),
0u,
numberOfGlyphs );
glyphs.Resize( numberOfGlyphs );
positions.Resize( numberOfGlyphs );
- colors.Resize( numberOfGlyphs );
+
+ const Vector4* const colorsBuffer = view.GetColors();
+ const ColorIndex* const colorIndicesBuffer = view.GetColorIndices();
+ const Vector4& defaultColor = view.GetTextColor();
mImpl->AddGlyphs( view,
positions,
glyphs,
- colors,
+ defaultColor,
+ colorsBuffer,
+ colorIndicesBuffer,
depth );
/* In the case where AddGlyphs does not create a renderable Actor for example when glyphs are all whitespace create a new Actor. */
"varying mediump vec3 vNormal;\n"
"attribute mediump vec2 aPosition;\n"
"varying mediump vec4 vVertex;\n"
+"attribute mediump vec4 aColor;\n"
+"varying mediump vec4 vColor;\n"
"varying vec4 v_glyph;\n"
"\n"
"vec4\n"
"{\n"
" gl_Position = uMvpMatrix * vec4 (aPosition, 0.0, 1.0);\n"
" v_glyph = glyph_vertex_transcode (aTexCoord);\n"
+" vColor = aColor;\n"
"}\n"
;
"uniform lowp vec4 uColor;\n"
"varying highp vec4 vVertex;\n"
"varying highp vec3 vNormal;\n"
+"varying mediump vec4 vColor;\n"
"uniform vec4 u_atlas_info;\n"
"\n"
"#define GLYPHY_TEXTURE1D_EXTRA_DECLS , sampler2D _tex, ivec4 _atlas_info, ivec2 _atlas_pos\n"
" vec2 dpdy = dFdy (p);\n"
" float m = length (vec2 (length (dpdx), length (dpdy))) * SQRT2_2;\n"
"\n"
-" vec4 color = uColor;\n"
+" vec4 color = vec4( vColor.rgb * uColor.rgb, vColor.a * uColor.a );\n"
"\n"
" ivec4 uu_atlas_info = ivec4( u_atlas_info );"
" float gsdist = glyphy_sdf (p, gi.nominal_size GLYPHY_DEMO_EXTRA_ARGS);\n"
float y;
float u;
float v;
+ Vector4 color;
};
-void AddVertex( Vector<Vertex2D>& vertices, float x, float y, float u, float v )
+void AddVertex( Vector<Vertex2D>& vertices, float x, float y, float u, float v, const Vector4& color )
{
Vertex2D meshVertex;
meshVertex.x = x;
meshVertex.y = y;
meshVertex.u = u;
meshVertex.v = v;
+ meshVertex.color = color;
vertices.PushBack( meshVertex );
}
VectorBlobAtlas& atlas,
Dali::TextAbstraction::FontClient& fontClient,
Vector< Vertex2D >& vertices,
- Vector< unsigned int >& indices )
+ Vector< unsigned int >& indices,
+ const Vector4* const colorsBuffer,
+ const ColorIndex* const colorIndicesBuffer,
+ const Vector4& defaultColor )
{
+ // Whether the default color is used.
+ const bool useDefaultColor = ( NULL == colorsBuffer );
+
bool atlasFull( false );
for( unsigned int i=0, idx=0; i<numberOfGlyphs && !atlasFull; ++i )
if( foundBlob )
{
+ // Get the color of the character.
+ const ColorIndex colorIndex = useDefaultColor ? 0u : *( colorIndicesBuffer + i );
+ const Vector4& color = ( useDefaultColor || ( 0u == colorIndex ) ) ? defaultColor : *( colorsBuffer + colorIndex - 1u );
+
const float x1( xOffset + positions[i].x );
const float x2( xOffset + positions[i].x + glyphs[i].width );
const float y1( yOffset + positions[i].y );
const float y2( yOffset + positions[i].y + glyphs[i].height );
- AddVertex( vertices, x1, y2, blobCoords[0].u, blobCoords[0].v );
- AddVertex( vertices, x1, y1, blobCoords[1].u, blobCoords[1].v );
- AddVertex( vertices, x2, y2, blobCoords[2].u, blobCoords[2].v );
+ AddVertex( vertices, x1, y2, blobCoords[0].u, blobCoords[0].v, color );
+ AddVertex( vertices, x1, y1, blobCoords[1].u, blobCoords[1].v, color );
+ AddVertex( vertices, x2, y2, blobCoords[2].u, blobCoords[2].v, color );
AddTriangle( indices, idx, idx+1, idx+2 );
idx+=3;
- AddVertex( vertices, x1, y1, blobCoords[1].u, blobCoords[1].v );
- AddVertex( vertices, x2, y2, blobCoords[2].u, blobCoords[2].v );
- AddVertex( vertices, x2, y1, blobCoords[3].u, blobCoords[3].v );
+ AddVertex( vertices, x1, y1, blobCoords[1].u, blobCoords[1].v, color );
+ AddVertex( vertices, x2, y2, blobCoords[2].u, blobCoords[2].v, color );
+ AddVertex( vertices, x2, y1, blobCoords[3].u, blobCoords[3].v, color );
AddTriangle( indices, idx, idx+1, idx+2 );
idx+=3;
}
mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
mQuadVertexFormat[ "aTexCoord" ] = Property::VECTOR2;
+ mQuadVertexFormat[ "aColor" ] = Property::VECTOR4;
mQuadIndexFormat[ "indices" ] = Property::INTEGER;
}
mImpl->mActor = Actor::New();
mImpl->mActor.SetParentOrigin( ParentOrigin::CENTER );
mImpl->mActor.SetSize( view.GetControlSize() );
- mImpl->mActor.SetColor( Color::BLACK );
+ mImpl->mActor.SetColor( Color::WHITE );
#if defined(DEBUG_ENABLED)
mImpl->mActor.SetName( "Text renderable actor" );
#endif
Vector<Vector2> positions;
positions.Resize( numberOfGlyphs );
- Vector<Vector4> colors;
- colors.Resize( numberOfGlyphs, view.GetTextColor() );
-
numberOfGlyphs = view.GetGlyphs( glyphs.Begin(),
positions.Begin(),
- colors.Begin(),
0u,
numberOfGlyphs );
glyphs.Resize( numberOfGlyphs );
positions.Resize( numberOfGlyphs );
+ const Vector4* const colorsBuffer = view.GetColors();
+ const ColorIndex* const colorIndicesBuffer = view.GetColorIndices();
+ const Vector4& defaultColor = view.GetTextColor();
+
Vector< Vertex2D > vertices;
Vector< unsigned int > indices;
}
// First try adding the glyphs to the previous shared atlas
- bool allGlyphsAdded = CreateGeometry( glyphs, numberOfGlyphs, positions, xOffset, yOffset, *mImpl->mAtlas, mImpl->mFontClient, vertices, indices );
+ bool allGlyphsAdded = CreateGeometry( glyphs,
+ numberOfGlyphs,
+ positions,
+ xOffset,
+ yOffset,
+ *mImpl->mAtlas,
+ mImpl->mFontClient,
+ vertices,
+ indices,
+ colorsBuffer,
+ colorIndicesBuffer,
+ defaultColor );
if( ! allGlyphsAdded )
{
VectorBlobAtlasShare atlasShare = VectorBlobAtlasShare::Get();
mImpl->mAtlas = atlasShare.GetNewAtlas();
- CreateGeometry( glyphs, numberOfGlyphs, positions, xOffset, yOffset, *mImpl->mAtlas, mImpl->mFontClient, vertices, indices );
+ CreateGeometry( glyphs,
+ numberOfGlyphs,
+ positions,
+ xOffset,
+ yOffset,
+ *mImpl->mAtlas,
+ mImpl->mFontClient,
+ vertices,
+ indices,
+ colorsBuffer,
+ colorIndicesBuffer,
+ defaultColor );
// Return value ignored; using more than an entire new atlas is not supported
}
numberOfCharacters = lastParagraph.characterRun.characterIndex + lastParagraph.characterRun.numberOfCharacters - mTextUpdateInfo.mParagraphCharacterIndex;
}
}
+
mTextUpdateInfo.mRequestedNumberOfCharacters = numberOfCharacters + mTextUpdateInfo.mNumberOfCharactersToAdd - mTextUpdateInfo.mNumberOfCharactersToRemove;
mTextUpdateInfo.mStartGlyphIndex = *( mVisualModel->mCharactersToGlyph.Begin() + mTextUpdateInfo.mParagraphCharacterIndex );
}
{
mVisualModel->mLines.Clear();
}
+
+ if( COLOR & operations )
+ {
+ mVisualModel->mColorIndices.Clear();
+ }
}
void Controller::Impl::ClearCharacterModelData( CharacterIndex startIndex, CharacterIndex endIndex, OperationsMask operations )
const CharacterIndex endIndexPlusOne = endIndex + 1u;
const Length numberOfCharactersRemoved = endIndexPlusOne - startIndex;
- const bool clearShape = SHAPE_TEXT & operations;
- const bool clearLayout = LAYOUT & operations;
+ // Convert the character index to glyph index before deleting the character to glyph and the glyphs per character buffers.
+ GlyphIndex* charactersToGlyphBuffer = mVisualModel->mCharactersToGlyph.Begin();
+ Length* glyphsPerCharacterBuffer = mVisualModel->mGlyphsPerCharacter.Begin();
- if( clearShape || clearLayout )
- {
- // Convert the character index to glyph index before deleting the character to glyph and the glyphs per character buffers.
- GlyphIndex* charactersToGlyphBuffer = mVisualModel->mCharactersToGlyph.Begin();
- Length* glyphsPerCharacterBuffer = mVisualModel->mGlyphsPerCharacter.Begin();
+ const GlyphIndex endGlyphIndexPlusOne = *( charactersToGlyphBuffer + endIndex ) + *( glyphsPerCharacterBuffer + endIndex );
+ const Length numberOfGlyphsRemoved = endGlyphIndexPlusOne - mTextUpdateInfo.mStartGlyphIndex;
- const GlyphIndex endGlyphIndex = *( charactersToGlyphBuffer + endIndex );
- const GlyphIndex endGlyphIndexPlusOne = endGlyphIndex + *( glyphsPerCharacterBuffer + endIndex );
- const Length numberOfGlyphsRemoved = endGlyphIndexPlusOne - mTextUpdateInfo.mStartGlyphIndex;
-
- if( clearShape )
+ if( SHAPE_TEXT & operations )
+ {
+ // Update the character to glyph indices.
+ for( Vector<GlyphIndex>::Iterator it = charactersToGlyphBuffer + endIndexPlusOne,
+ endIt = charactersToGlyphBuffer + mVisualModel->mCharactersToGlyph.Count();
+ it != endIt;
+ ++it )
{
- // Update the character to glyph indices.
- for( Vector<GlyphIndex>::Iterator it = charactersToGlyphBuffer + endIndexPlusOne,
- endIt = charactersToGlyphBuffer + mVisualModel->mCharactersToGlyph.Count();
- it != endIt;
- ++it )
- {
- CharacterIndex& index = *it;
- index -= numberOfGlyphsRemoved;
- }
+ CharacterIndex& index = *it;
+ index -= numberOfGlyphsRemoved;
+ }
- // Clear the character to glyph conversion table.
- mVisualModel->mCharactersToGlyph.Erase( charactersToGlyphBuffer + startIndex,
- charactersToGlyphBuffer + endIndexPlusOne );
+ // Clear the character to glyph conversion table.
+ mVisualModel->mCharactersToGlyph.Erase( charactersToGlyphBuffer + startIndex,
+ charactersToGlyphBuffer + endIndexPlusOne );
- // Clear the glyphs per character table.
- mVisualModel->mGlyphsPerCharacter.Erase( glyphsPerCharacterBuffer + startIndex,
- glyphsPerCharacterBuffer + endIndexPlusOne );
+ // Clear the glyphs per character table.
+ mVisualModel->mGlyphsPerCharacter.Erase( glyphsPerCharacterBuffer + startIndex,
+ glyphsPerCharacterBuffer + endIndexPlusOne );
- // Clear the glyphs buffer.
- GlyphInfo* glyphsBuffer = mVisualModel->mGlyphs.Begin();
- mVisualModel->mGlyphs.Erase( glyphsBuffer + mTextUpdateInfo.mStartGlyphIndex,
- glyphsBuffer + endGlyphIndexPlusOne );
+ // Clear the glyphs buffer.
+ GlyphInfo* glyphsBuffer = mVisualModel->mGlyphs.Begin();
+ mVisualModel->mGlyphs.Erase( glyphsBuffer + mTextUpdateInfo.mStartGlyphIndex,
+ glyphsBuffer + endGlyphIndexPlusOne );
- CharacterIndex* glyphsToCharactersBuffer = mVisualModel->mGlyphsToCharacters.Begin();
+ CharacterIndex* glyphsToCharactersBuffer = mVisualModel->mGlyphsToCharacters.Begin();
- // Update the glyph to character indices.
- for( Vector<CharacterIndex>::Iterator it = glyphsToCharactersBuffer + endGlyphIndexPlusOne,
- endIt = glyphsToCharactersBuffer + mVisualModel->mGlyphsToCharacters.Count();
- it != endIt;
- ++it )
- {
- CharacterIndex& index = *it;
- index -= numberOfCharactersRemoved;
- }
+ // Update the glyph to character indices.
+ for( Vector<CharacterIndex>::Iterator it = glyphsToCharactersBuffer + endGlyphIndexPlusOne,
+ endIt = glyphsToCharactersBuffer + mVisualModel->mGlyphsToCharacters.Count();
+ it != endIt;
+ ++it )
+ {
+ CharacterIndex& index = *it;
+ index -= numberOfCharactersRemoved;
+ }
- // Clear the glyphs to characters buffer.
- mVisualModel->mGlyphsToCharacters.Erase( glyphsToCharactersBuffer + mTextUpdateInfo.mStartGlyphIndex,
- glyphsToCharactersBuffer + endGlyphIndexPlusOne );
+ // Clear the glyphs to characters buffer.
+ mVisualModel->mGlyphsToCharacters.Erase( glyphsToCharactersBuffer + mTextUpdateInfo.mStartGlyphIndex,
+ glyphsToCharactersBuffer + endGlyphIndexPlusOne );
- // Clear the characters per glyph buffer.
- Length* charactersPerGlyphBuffer = mVisualModel->mCharactersPerGlyph.Begin();
- mVisualModel->mCharactersPerGlyph.Erase( charactersPerGlyphBuffer + mTextUpdateInfo.mStartGlyphIndex,
- charactersPerGlyphBuffer + endGlyphIndexPlusOne );
+ // Clear the characters per glyph buffer.
+ Length* charactersPerGlyphBuffer = mVisualModel->mCharactersPerGlyph.Begin();
+ mVisualModel->mCharactersPerGlyph.Erase( charactersPerGlyphBuffer + mTextUpdateInfo.mStartGlyphIndex,
+ charactersPerGlyphBuffer + endGlyphIndexPlusOne );
- // Clear the positions buffer.
- Vector2* positionsBuffer = mVisualModel->mGlyphPositions.Begin();
- mVisualModel->mGlyphPositions.Erase( positionsBuffer + mTextUpdateInfo.mStartGlyphIndex,
- positionsBuffer + endGlyphIndexPlusOne );
- }
+ // Clear the positions buffer.
+ Vector2* positionsBuffer = mVisualModel->mGlyphPositions.Begin();
+ mVisualModel->mGlyphPositions.Erase( positionsBuffer + mTextUpdateInfo.mStartGlyphIndex,
+ positionsBuffer + endGlyphIndexPlusOne );
+ }
- if( clearLayout )
- {
- // Clear the lines.
- uint32_t startRemoveIndex = mVisualModel->mLines.Count();
- uint32_t endRemoveIndex = startRemoveIndex;
- ClearCharacterRuns( startIndex,
- endIndex,
- mVisualModel->mLines,
- startRemoveIndex,
- endRemoveIndex );
+ if( LAYOUT & operations )
+ {
+ // Clear the lines.
+ uint32_t startRemoveIndex = mVisualModel->mLines.Count();
+ uint32_t endRemoveIndex = startRemoveIndex;
+ ClearCharacterRuns( startIndex,
+ endIndex,
+ mVisualModel->mLines,
+ startRemoveIndex,
+ endRemoveIndex );
- // Will update the glyph runs.
- uint32_t startRemoveGlyphIndex = mVisualModel->mLines.Count();
- uint32_t endRemoveGlyphIndex = startRemoveIndex;
- ClearGlyphRuns( mTextUpdateInfo.mStartGlyphIndex,
- endGlyphIndex,
- mVisualModel->mLines,
- startRemoveGlyphIndex,
- endRemoveGlyphIndex );
+ // Will update the glyph runs.
+ startRemoveIndex = mVisualModel->mLines.Count();
+ endRemoveIndex = startRemoveIndex;
+ ClearGlyphRuns( mTextUpdateInfo.mStartGlyphIndex,
+ endGlyphIndexPlusOne - 1u,
+ mVisualModel->mLines,
+ startRemoveIndex,
+ endRemoveIndex );
- // Set the line index from where to insert the new laid-out lines.
- mTextUpdateInfo.mStartLineIndex = startRemoveIndex;
+ // Set the line index from where to insert the new laid-out lines.
+ mTextUpdateInfo.mStartLineIndex = startRemoveIndex;
- LineRun* linesBuffer = mVisualModel->mLines.Begin();
- mVisualModel->mLines.Erase( linesBuffer + startRemoveIndex,
- linesBuffer + endRemoveIndex );
+ LineRun* linesBuffer = mVisualModel->mLines.Begin();
+ mVisualModel->mLines.Erase( linesBuffer + startRemoveIndex,
+ linesBuffer + endRemoveIndex );
+ }
+
+ if( COLOR & operations )
+ {
+ if( 0u != mVisualModel->mColorIndices.Count() )
+ {
+ ColorIndex* colorIndexBuffer = mVisualModel->mColorIndices.Begin();
+ mVisualModel->mColorIndices.Erase( colorIndexBuffer + mTextUpdateInfo.mStartGlyphIndex,
+ colorIndexBuffer + endGlyphIndexPlusOne );
}
}
}
mTextUpdateInfo.mEstimatedNumberOfLines = std::max( mVisualModel->mLines.Count(), mLogicalModel->mParagraphInfo.Count() );
mVisualModel->ClearCaches();
-
- // TODO finish the mark-up.
- mVisualModel->mColorRuns.Clear();
}
-void Controller::Impl::UpdateModel( OperationsMask operationsRequired )
+bool Controller::Impl::UpdateModel( OperationsMask operationsRequired )
{
DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::UpdateModel\n" );
if( NO_OPERATION == operations )
{
// Nothing to do if no operations are pending and required.
- return;
+ return false;
}
Vector<Character>& utf32Characters = mLogicalModel->mText;
mTextUpdateInfo.mClearAll = false;
+ // Whether the model is updated.
+ bool updated = false;
+
Vector<LineBreakInfo>& lineBreakInfo = mLogicalModel->mLineBreakInfo;
const Length requestedNumberOfCharacters = mTextUpdateInfo.mRequestedNumberOfCharacters;
// Create the paragraph info.
mLogicalModel->CreateParagraphInfo( startIndex,
requestedNumberOfCharacters );
+ updated = true;
}
Vector<WordBreakInfo>& wordBreakInfo = mLogicalModel->mWordBreakInfo;
startIndex,
requestedNumberOfCharacters,
wordBreakInfo );
+ updated = true;
}
const bool getScripts = GET_SCRIPTS & operations;
requestedNumberOfCharacters,
validFonts );
}
+ updated = true;
}
Vector<Character> mirroredUtf32Characters;
// There is no right to left characters. Clear the directions vector.
mLogicalModel->mCharacterDirections.Clear();
}
+ updated = true;
}
Vector<GlyphInfo>& glyphs = mVisualModel->mGlyphs;
// Create the 'number of glyphs' per character and the glyph to character conversion tables.
mVisualModel->CreateGlyphsPerCharacterTable( startIndex, mTextUpdateInfo.mStartGlyphIndex, requestedNumberOfCharacters );
mVisualModel->CreateCharacterToGlyphTable( startIndex, mTextUpdateInfo.mStartGlyphIndex, requestedNumberOfCharacters );
+ updated = true;
}
const Length numberOfGlyphs = glyphs.Count() - currentNumberOfGlyphs;
glyph.width = 0.f;
glyph.advance = 0.f;
}
+ updated = true;
+ }
+
+ if( COLOR & operationsRequired )
+ {
+ // Set the color runs in glyphs.
+ SetColorSegmentationInfo( mLogicalModel->mColorRuns,
+ mVisualModel->mCharactersToGlyph,
+ mVisualModel->mGlyphsPerCharacter,
+ startIndex,
+ mTextUpdateInfo.mStartGlyphIndex,
+ requestedNumberOfCharacters,
+ mVisualModel->mColors,
+ mVisualModel->mColorIndices );
+
+ updated = true;
}
if( ( NULL != mEventData ) &&
// Set the previous number of characters for the next time the text is updated.
mTextUpdateInfo.mPreviousNumberOfCharacters = numberOfCharacters;
-}
-
-bool Controller::Impl::UpdateModelStyle( OperationsMask operationsRequired )
-{
- bool updated = false;
-
- if( COLOR & operationsRequired )
- {
- // Set the color runs in glyphs.
- SetColorSegmentationInfo( mLogicalModel->mColorRuns,
- mVisualModel->mCharactersToGlyph,
- mVisualModel->mGlyphsPerCharacter,
- mVisualModel->mColorRuns );
-
- updated = true;
- }
return updated;
}
{
// Sets the default text's color.
inputStyle.textColor = mTextColor;
+ inputStyle.isDefaultColor = true;
// Sets the default font's family name, weight, width, slant and size.
if( mFontDefaults )
void ClearModelData( CharacterIndex startIndex, CharacterIndex endIndex, OperationsMask operations );
/**
- * @brief Updates the logical and visual models.
+ * @brief Updates the logical and visual models. Updates the style runs in the visual model when the text's styles changes.
*
* When text or style changes the model is set with some operations pending.
* When i.e. the text's size or a relayout is required this method is called
* matched with the operations pending to perform the minimum number of operations.
*
* @param[in] operationsRequired The operations required.
- */
- void UpdateModel( OperationsMask operationsRequired );
-
- /**
- * @brief Updates the style runs in the visual model when the text's styles changes.
- *
- * @param[in] operationsRequired The operations required.
*
* @return @e true if the model has been modified.
*/
- bool UpdateModelStyle( OperationsMask operationsRequired );
+ bool UpdateModel( OperationsMask operationsRequired );
/**
* @brief Retreieves the default style.
if( !text.empty() )
{
+ mImpl->mVisualModel->SetTextColor( mImpl->mTextColor );
+
MarkupProcessData markupProcessData( mImpl->mLogicalModel->mColorRuns,
mImpl->mLogicalModel->mFontDescriptionRuns );
if( NULL != mImpl->mEventData )
{
mImpl->mEventData->mInputStyle.textColor = color;
+ mImpl->mEventData->mInputStyle.isDefaultColor = false;
if( EventData::SELECTING == mImpl->mEventData->mState )
{
// Request to relayout.
mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
mImpl->RequestRelayout();
+
+ mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
+ mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
+ mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
}
}
}
// Not worth to relayout if width or height is equal to zero.
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
+
return glyphsRemoved;
}
}
// Whether there are modify events.
- const bool isModifyEventsEmpty = 0u == mImpl->mModifyEvents.Count();
-
- // Make sure the model is up-to-date before layouting.
- ProcessModifyEvents();
- mImpl->UpdateModel( mImpl->mOperationsPending );
-
- // Style operations that need to be done if the text is modified.
- if( !isModifyEventsEmpty )
+ if( 0u != mImpl->mModifyEvents.Count() )
{
+ // Style operations that need to be done if the text is modified.
mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
COLOR );
}
- // Apply the style runs if text is modified.
- bool updated = mImpl->UpdateModelStyle( mImpl->mOperationsPending );
+ // Make sure the model is up-to-date before layouting.
+ ProcessModifyEvents();
+ bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
// Layout the text.
Size layoutSize;
// Clear the update info. This info will be set the next time the text is updated.
mImpl->mTextUpdateInfo.Clear();
-
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
+
return updated;
}
// Retrieve the text's style for the given index.
InputStyle style;
+ mImpl->RetrieveDefaultInputStyle( style );
mImpl->mLogicalModel->RetrieveStyle( styleIndex, style );
// Whether to add a new text color run.
- const bool addColorRun = style.textColor != mImpl->mEventData->mInputStyle.textColor;
+ const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
// Whether to add a new font run.
const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
typedef uint32_t BidirectionalLineRunIndex; ///< An index into an array of bidirectional line info.
typedef uint32_t LineIndex; ///< An index into an array of lines.
typedef uint32_t ParagraphRunIndex; ///< An index into an array of paragraphs.
+typedef uint32_t ColorIndex; ///< An index into an array of colors.
} // namespace Text
*
* @param[out] glyphs Pointer to a buffer where the glyphs are copied.
* @param[out] glyphPositions Pointer to a buffer where the glyph's positions are copied.
- * @param[out] colors Pointer to a buffer where the glyph's colors are copied.
* @param[in] glyphIndex Index to the first glyph.
* @param[in] numberOfGlyphs Number of glyphs to be copied.
*
*/
virtual Length GetGlyphs( GlyphInfo* glyphs,
Vector2* glyphPositions,
- Vector4* glyphColors,
GlyphIndex glyphIndex,
Length numberOfGlyphs ) const = 0;
/**
+ * @brief Retrieves the vector of colors.
+ *
+ * @return Pointer to the vector of colors.
+ */
+ virtual const Vector4* const GetColors() const = 0;
+
+ /**
+ * @brief Retrieves the vector of indices to the vector of colors.
+ *
+ * @return Pointer to a vector which stores for each glyph the index to the vector of colors.
+ */
+ virtual const ColorIndex* const GetColorIndices() const = 0;
+
+ /**
* @brief Retrieves the text color
*
* @return The text color
Length View::GetGlyphs( GlyphInfo* glyphs,
Vector2* glyphPositions,
- Vector4* glyphColors,
GlyphIndex glyphIndex,
Length numberOfGlyphs ) const
{
glyphIndex,
numberOfLaidOutGlyphs );
- // Set the colors.
- const GlyphIndex lastLaidOutGlyphIndex = glyphIndex + numberOfLaidOutGlyphs;
-
- for( Vector<ColorGlyphRun>::ConstIterator it = mImpl->mVisualModel->mColorRuns.Begin(),
- endIt = mImpl->mVisualModel->mColorRuns.End();
- it != endIt;
- ++it )
- {
- const ColorGlyphRun& colorGlyphRun = *it;
- const GlyphIndex lastGlyphIndex = colorGlyphRun.glyphRun.glyphIndex + colorGlyphRun.glyphRun.numberOfGlyphs;
-
- if( ( colorGlyphRun.glyphRun.glyphIndex < lastLaidOutGlyphIndex ) &&
- ( glyphIndex < lastGlyphIndex ) )
- {
- for( GlyphIndex index = glyphIndex < colorGlyphRun.glyphRun.glyphIndex ? colorGlyphRun.glyphRun.glyphIndex : glyphIndex,
- endIndex = lastLaidOutGlyphIndex < lastGlyphIndex ? lastLaidOutGlyphIndex : lastGlyphIndex;
- index < endIndex;
- ++index )
- {
- *( glyphColors + index - glyphIndex ) = colorGlyphRun.color;
- }
- }
- }
-
// Get the lines for the given range of glyphs.
// The lines contain the alignment offset which needs to be added to the glyph's position.
LineIndex firstLine = 0u;
return numberOfLaidOutGlyphs;
}
+const Vector4* const View::GetColors() const
+{
+ if( mImpl->mVisualModel )
+ {
+ return mImpl->mVisualModel->mColors.Begin();
+ }
+
+ return NULL;
+}
+
+const ColorIndex* const View::GetColorIndices() const
+{
+ if( mImpl->mVisualModel )
+ {
+ return mImpl->mVisualModel->mColorIndices.Begin();
+ }
+
+ return NULL;
+}
+
const Vector4& View::GetTextColor() const
{
if( mImpl->mVisualModel )
*/
virtual Length GetGlyphs( GlyphInfo* glyphs,
Vector2* glyphPositions,
- Vector4* glyphColors,
GlyphIndex glyphIndex,
Length numberOfGlyphs ) const;
/**
+ * @copydoc Dali::Toolkit::Text::ViewInterface::GetColors()
+ */
+ virtual const Vector4* const GetColors() const;
+
+ /**
+ * @copydoc Dali::Toolkit::Text::ViewInterface::GetColorIndices()
+ */
+ virtual const ColorIndex* const GetColorIndices() const;
+
+ /**
* @copydoc Dali::Toolkit::Text::ViewInterface::GetTextColor()
*/
virtual const Vector4& GetTextColor() const;
Vector<Vector2> mGlyphPositions; ///< For each glyph, the position.
Vector<LineRun> mLines; ///< The laid out lines.
Vector<GlyphRun> mUnderlineRuns; ///< Runs of glyphs that are underlined.
- Vector<ColorGlyphRun> mColorRuns; ///< Runs of glyphs with the same color.
+ Vector<Vector4> mColors; ///< Colors of the glyphs.
+ Vector<ColorIndex> mColorIndices; ///< Indices to the vector of colors for each glyphs.
Vector2 mControlSize; ///< The size of the UI control the decorator is adding it's decorations to.
Vector4 mTextColor; ///< The text color