X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dali-toolkit%2Finternal%2Ftext%2Frendering%2Fvector-based%2Fvector-based-renderer.cpp;h=d7b245dc29cabb1ea7ee5a2bf8b3b47add58ac1f;hb=37809ae7570411971d415a9060b38f64bba81744;hp=816a45ddc06da499688889a046c0c9ab03ee2c6b;hpb=0302e2897031cbf4ab7f15a93eb784ab85d4507d;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/text/rendering/vector-based/vector-based-renderer.cpp b/dali-toolkit/internal/text/rendering/vector-based/vector-based-renderer.cpp index 816a45d..d7b245d 100644 --- a/dali-toolkit/internal/text/rendering/vector-based/vector-based-renderer.cpp +++ b/dali-toolkit/internal/text/rendering/vector-based/vector-based-renderer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,10 @@ #include // EXTERNAL INCLUDES -#include -#include -#include +#include +#include #include +#include // INTERNAL INCLUDES #include @@ -50,19 +50,21 @@ struct Vertex2D float y; float u; float v; + Vector4 color; }; -void AddVertex( Vector& vertices, float x, float y, float u, float v ) +void AddVertex( Vector& 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 ); } -void AddTriangle( Vector& indices, unsigned int v0, unsigned int v1, unsigned int v2 ) +void AddTriangle( Vector& indices, unsigned int v0, unsigned int v1, unsigned int v2 ) { indices.PushBack( v0 ); indices.PushBack( v1 ); @@ -77,8 +79,14 @@ bool CreateGeometry( const Vector& glyphs, VectorBlobAtlas& atlas, Dali::TextAbstraction::FontClient& fontClient, Vector< Vertex2D >& vertices, - Vector< unsigned int >& indices ) + Vector< unsigned short >& 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& glyphs, 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; } @@ -148,7 +160,7 @@ struct VectorBasedRenderer::Impl mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2; mQuadVertexFormat[ "aTexCoord" ] = Property::VECTOR2; - mQuadIndexFormat[ "indices" ] = Property::INTEGER; + mQuadVertexFormat[ "aColor" ] = Property::VECTOR4; } Actor mActor; ///< The actor parent which renders the text @@ -156,7 +168,6 @@ struct VectorBasedRenderer::Impl TextAbstraction::FontClient mFontClient; ///> The font client used to supply glyph information Property::Map mQuadVertexFormat; ///> Describes the vertex format for text - Property::Map mQuadIndexFormat; ///> Describes the index format for text Shader mShaderEffect; @@ -170,16 +181,20 @@ Text::RendererPtr VectorBasedRenderer::New() return Text::RendererPtr( new VectorBasedRenderer() ); } -Actor VectorBasedRenderer::Render( Text::ViewInterface& view, int /*depth*/ ) +Actor VectorBasedRenderer::Render( Text::ViewInterface& view, + Actor textControl, + Property::Index animatablePropertyIndex, + float& alignmentOffset, + int /*depth*/ ) { UnparentAndReset( mImpl->mActor ); mImpl->mActor = Actor::New(); - mImpl->mActor.SetParentOrigin( ParentOrigin::CENTER ); - mImpl->mActor.SetSize( view.GetControlSize() ); - mImpl->mActor.SetColor( Color::BLACK ); + mImpl->mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mImpl->mActor.SetProperty( Actor::Property::SIZE, Vector2( view.GetControlSize() ) ); + mImpl->mActor.SetProperty( Actor::Property::COLOR, Color::WHITE ); #if defined(DEBUG_ENABLED) - mImpl->mActor.SetName( "Text renderable actor" ); + mImpl->mActor.SetProperty( Dali::Actor::Property::NAME, "Text renderable actor" ); #endif Length numberOfGlyphs = view.GetNumberOfGlyphs(); @@ -192,22 +207,24 @@ Actor VectorBasedRenderer::Render( Text::ViewInterface& view, int /*depth*/ ) Vector positions; positions.Resize( numberOfGlyphs ); - Vector colors; - colors.Resize( numberOfGlyphs, view.GetTextColor() ); - numberOfGlyphs = view.GetGlyphs( glyphs.Begin(), positions.Begin(), - colors.Begin(), + alignmentOffset, 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; + Vector< unsigned short > indices; const Vector2& controlSize = view.GetControlSize(); - float xOffset = controlSize.width * -0.5f; + float xOffset = -alignmentOffset + controlSize.width * -0.5f; float yOffset = controlSize.height * -0.5f; if( ! mImpl->mAtlas || @@ -218,7 +235,18 @@ Actor VectorBasedRenderer::Render( Text::ViewInterface& view, int /*depth*/ ) } // 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 ) { @@ -230,21 +258,31 @@ Actor VectorBasedRenderer::Render( Text::ViewInterface& view, int /*depth*/ ) 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 } if( 0 != vertices.Count() ) { - PropertyBuffer quadVertices = PropertyBuffer::New( mImpl->mQuadVertexFormat ); - PropertyBuffer quadIndices = PropertyBuffer::New( mImpl->mQuadIndexFormat ); + VertexBuffer quadVertices = VertexBuffer::New( mImpl->mQuadVertexFormat ); quadVertices.SetData( &vertices[ 0 ], vertices.Size() ); - quadIndices.SetData( &indices[ 0 ], indices.Size() ); + Geometry quadGeometry = Geometry::New(); quadGeometry.AddVertexBuffer( quadVertices ); - quadGeometry.SetIndexBuffer( quadIndices ); + quadGeometry.SetIndexBuffer( &indices[ 0 ], indices.Size() ); TextureSet texture = mImpl->mAtlas->GetTextureSet(); @@ -269,4 +307,3 @@ VectorBasedRenderer::~VectorBasedRenderer() { delete mImpl; } -