/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
#include <dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.h>
// EXTERNAL INCLUDES
-#include <dali/integration-api/debug.h>
-#include <dali/devel-api/rendering/renderer.h>
-#include <dali/devel-api/rendering/geometry.h>
+#include <dali/public-api/rendering/geometry.h>
+#include <dali/public-api/rendering/renderer.h>
#include <dali/devel-api/text-abstraction/font-client.h>
+#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
namespace
{
#if defined(DEBUG_ENABLED)
- Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_RENDERING");
+ Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_RENDERING");
#endif
const float ZERO( 0.0f );
mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
mQuadVertexFormat[ "aTexCoord" ] = Property::VECTOR2;
mQuadVertexFormat[ "aColor" ] = Property::VECTOR4;
- mQuadIndexFormat[ "indices" ] = Property::INTEGER;
}
bool IsGlyphUnderlined( GlyphIndex index,
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;
TextCacheEntry textCacheEntry;
mDepth = depth;
- const Vector2& actorSize( view.GetControlSize() );
const Vector2& textSize( view.GetLayoutSize() );
const Vector2 halfTextSize( textSize * 0.5f );
const Vector2& shadowOffset( view.GetShadowOffset() );
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 )
{
}
// Create a new image for the glyph
- BufferImage bitmap = mFontClient.CreateBitmap( glyph.fontId, glyph.index );
+ PixelData bitmap = mFontClient.CreateBitmap( glyph.fontId, glyph.index );
if( bitmap )
{
MaxBlockSize& blockSize = mBlockSizes[currentBlockSize];
}
// 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;
// For each MeshData object, create a mesh actor and add to the renderable actor
if( !meshContainer.empty() )
{
+ if( !mActor )
+ {
+ // Create a container actor to act as a common parent for text and shadow, to avoid color inheritence issues.
+ mActor = Actor::New();
+ mActor.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mActor.SetSize( textSize );
+ }
+
for( std::vector< MeshRecord >::iterator it = meshContainer.begin(),
endIt = meshContainer.end();
it != endIt; ++it )
Actor actor = CreateMeshActor( meshRecord, textSize );
+ // Whether the actor has renderers.
+ const bool hasRenderer = actor.GetRendererCount() > 0u;
+
// Create an effect if necessary
- if( style == STYLE_DROP_SHADOW )
+ if( hasRenderer &&
+ ( style == STYLE_DROP_SHADOW ) )
{
// Change the color of the vertices.
for( Vector<AtlasManager::Vertex2D>::Iterator vIt = meshRecord.mMesh.mVertices.Begin(),
vertex.mColor = shadowColor;
}
- // Create a container actor to act as a common parent for text and shadow, to avoid color inheritence issues.
- Actor containerActor = Actor::New();
- containerActor.SetParentOrigin( ParentOrigin::CENTER );
- containerActor.SetSize( actorSize );
-
Actor shadowActor = CreateMeshActor( meshRecord, textSize );
#if defined(DEBUG_ENABLED)
shadowActor.SetName( "Text Shadow renderable actor" );
#endif
// Offset shadow in x and y
shadowActor.RegisterProperty("uOffset", shadowOffset );
- if( actor.GetRendererCount() )
- {
- Dali::Renderer renderer( shadowActor.GetRendererAt( 0 ) );
- int depthIndex = renderer.GetProperty<int>(Dali::Renderer::Property::DEPTH_INDEX);
- renderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, depthIndex - 1 );
- containerActor.Add( shadowActor );
- containerActor.Add( actor );
- actor = containerActor;
- }
+ Dali::Renderer renderer( shadowActor.GetRendererAt( 0 ) );
+ int depthIndex = renderer.GetProperty<int>(Dali::Renderer::Property::DEPTH_INDEX);
+ renderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, depthIndex - 1 );
+ mActor.Add( shadowActor );
}
- if( mActor )
+ if( hasRenderer )
{
mActor.Add( actor );
}
- else
- {
- mActor = actor;
- }
}
}
#if defined(DEBUG_ENABLED)
Actor CreateMeshActor( const MeshRecord& meshRecord, const Vector2& actorSize )
{
PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat );
- PropertyBuffer quadIndices = PropertyBuffer::New( mQuadIndexFormat );
quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ), meshRecord.mMesh.mVertices.Size() );
- quadIndices.SetData( const_cast< unsigned int* >( &meshRecord.mMesh.mIndices[ 0 ] ), meshRecord.mMesh.mIndices.Size() );
Geometry quadGeometry = Geometry::New();
quadGeometry.AddVertexBuffer( quadVertices );
- quadGeometry.SetIndexBuffer( quadIndices );
+ quadGeometry.SetIndexBuffer( &meshRecord.mMesh.mIndices[0], meshRecord.mMesh.mIndices.Size() );
- Material material = mGlyphManager.GetMaterial( meshRecord.mAtlasId );
- Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material );
- renderer.SetProperty( Dali::Renderer::Property::BLENDING_MODE, BlendingMode::ON );
+ TextureSet textureSet( mGlyphManager.GetTextures( meshRecord.mAtlasId ) );
+ Shader shader( mGlyphManager.GetShader( meshRecord.mAtlasId ) );
+ Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, shader );
+ renderer.SetTextures( textureSet );
+ renderer.SetProperty( Dali::Renderer::Property::BLEND_MODE, BlendMode::ON );
renderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, DepthIndex::CONTENT + mDepth );
Actor actor = Actor::New();
#if defined(DEBUG_ENABLED)
// Keep all of the origins aligned
actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-
actor.SetSize( actorSize );
actor.RegisterProperty("uOffset", Vector2::ZERO );
return actor;
vert.mPosition.y = baseLine;
vert.mTexCoords.x = ZERO;
vert.mTexCoords.y = ZERO;
+ vert.mColor = underlineColor;
newMesh.mVertices.PushBack( vert );
vert.mPosition.x = brx;
vert.mPosition.y = baseLine;
vert.mTexCoords.x = u;
+ vert.mColor = underlineColor;
newMesh.mVertices.PushBack( vert );
vert.mPosition.x = tlx;
vert.mPosition.y = baseLine + thickness;
vert.mTexCoords.x = ZERO;
vert.mTexCoords.y = v;
+ vert.mColor = underlineColor;
newMesh.mVertices.PushBack( vert );
vert.mPosition.x = brx;
vert.mPosition.y = baseLine + thickness;
vert.mTexCoords.x = u;
+ vert.mColor = underlineColor;
newMesh.mVertices.PushBack( vert );
// Six indices in counter clockwise winding
newMesh.mIndices.PushBack( faceIndex + 1u );
faceIndex += 4;
- vert.mColor = underlineColor;
-
Toolkit::Internal::AtlasMeshFactory::AppendMesh( meshRecords[ index ].mMesh, newMesh );
}
}
std::vector< MaxBlockSize > mBlockSizes; ///> Maximum size needed to contain a glyph in a block within a new atlas
Vector< TextCacheEntry > mTextCache; ///> Caches data from previous render
Property::Map mQuadVertexFormat; ///> Describes the vertex format for text
- Property::Map mQuadIndexFormat; ///> Describes the index format for text
int mDepth; ///> DepthIndex passed by control when connect to stage
};
Actor AtlasRenderer::Render( Text::ViewInterface& view, int depth )
{
+ DALI_LOG_INFO( gLogFilter, Debug::General, "Text::AtlasRenderer::Render()\n" );
+
UnparentAndReset( mImpl->mActor );
Length numberOfGlyphs = view.GetNumberOfGlyphs();
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. */