Reduced size of control depth index ranges
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / atlas / text-atlas-renderer.cpp
index f2e5596..2332c7a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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/public-api/images/frame-buffer-image.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>
@@ -168,7 +169,8 @@ struct AtlasRenderer::Impl
                   const Vector4& defaultColor,
                   const Vector4* const colorsBuffer,
                   const ColorIndex* const colorIndicesBuffer,
-                  int depth )
+                  int depth,
+                  float minLineOffset )
   {
     AtlasManager::AtlasSlot slot;
     std::vector< MeshRecord > meshContainer;
@@ -176,7 +178,6 @@ struct AtlasRenderer::Impl
     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() );
@@ -215,11 +216,11 @@ struct AtlasRenderer::Impl
     Vector< TextCacheEntry > newTextCache;
     const GlyphInfo* const glyphsBuffer = glyphs.Begin();
     const Vector2* const positionsBuffer = positions.Begin();
+    const Vector2 lineOffsetPosition( minLineOffset, 0.f );
 
     for( uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i )
     {
       const GlyphInfo& glyph = *( glyphsBuffer + i );
-
       const bool underlineGlyph = underlineEnabled || IsGlyphUnderlined( i, underlineRuns );
       thereAreUnderlinedGlyphs = thereAreUnderlinedGlyphs || underlineGlyph;
 
@@ -289,7 +290,7 @@ struct AtlasRenderer::Impl
           }
 
           // 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];
@@ -326,7 +327,7 @@ struct AtlasRenderer::Impl
         }
 
         // Move the origin (0,0) of the mesh to the center of the actor
-        const Vector2 position = *( positionsBuffer + i ) - halfTextSize;
+        const Vector2 position = *( positionsBuffer + i ) - halfTextSize - lineOffsetPosition;
 
         // Generate mesh data for this quad, plugging in our supplied position
         AtlasManager::Mesh2D newMesh;
@@ -393,6 +394,15 @@ struct AtlasRenderer::Impl
     // 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 )
@@ -401,8 +411,12 @@ struct AtlasRenderer::Impl
 
         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(),
@@ -415,39 +429,22 @@ struct AtlasRenderer::Impl
             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 );
-#if defined(DEBUG_ENABLED)
-            containerActor.SetName("TextContainer");
-#endif
-            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)
@@ -740,7 +737,9 @@ Text::RendererPtr AtlasRenderer::New()
   return Text::RendererPtr( new AtlasRenderer() );
 }
 
-Actor AtlasRenderer::Render( Text::ViewInterface& view, int depth )
+Actor AtlasRenderer::Render( Text::ViewInterface& view,
+                             float& alignmentOffset,
+                             int depth )
 {
   DALI_LOG_INFO( gLogFilter, Debug::General, "Text::AtlasRenderer::Render()\n" );
 
@@ -758,6 +757,7 @@ Actor AtlasRenderer::Render( Text::ViewInterface& view, int depth )
 
     numberOfGlyphs = view.GetGlyphs( glyphs.Begin(),
                                      positions.Begin(),
+                                     alignmentOffset,
                                      0u,
                                      numberOfGlyphs );
 
@@ -774,7 +774,8 @@ Actor AtlasRenderer::Render( Text::ViewInterface& view, int depth )
                       defaultColor,
                       colorsBuffer,
                       colorIndicesBuffer,
-                      depth );
+                      depth,
+                      alignmentOffset );
 
     /* In the case where AddGlyphs does not create a renderable Actor for example when glyphs are all whitespace create a new Actor. */
     /* This renderable actor is used to position the text, other "decorations" can rely on there always being an Actor regardless of it is whitespace or regular text. */