Merge "Updates following rename of PropertyBuffer to VertexBuffer" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / atlas / text-atlas-renderer.cpp
index e06b958..4fc28f8 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
@@ -93,7 +93,7 @@ const float HALF( 0.5f );
 const float ONE( 1.0f );
 const uint32_t DEFAULT_ATLAS_WIDTH = 512u;
 const uint32_t DEFAULT_ATLAS_HEIGHT = 512u;
-const uint32_t NO_OUTLINE = 0;
+const uint16_t NO_OUTLINE = 0u;
 }
 
 struct AtlasRenderer::Impl
@@ -168,17 +168,21 @@ struct AtlasRenderer::Impl
   struct TextCacheEntry
   {
     TextCacheEntry()
-    : mFontId( 0 ),
-      mIndex( 0 ),
-      mOutlineWidth( 0 ),
-      mImageId( 0 )
+    : mFontId{ 0u },
+      mIndex{ 0u },
+      mImageId{ 0u },
+      mOutlineWidth{ 0u },
+      isItalic{ false },
+      isBold{ false }
     {
     }
 
     FontId mFontId;
     Text::GlyphIndex mIndex;
-    uint32_t mOutlineWidth;
     uint32_t mImageId;
+    uint16_t mOutlineWidth;
+    bool isItalic:1;
+    bool isBold:1;
   };
 
   Impl()
@@ -211,9 +215,9 @@ struct AtlasRenderer::Impl
     return false;
   }
 
-  void CacheGlyph( const GlyphInfo& glyph, FontId lastFontId, uint32_t outline, AtlasManager::AtlasSlot& slot )
+  void CacheGlyph( const GlyphInfo& glyph, FontId lastFontId, const AtlasGlyphManager::GlyphStyle& style, AtlasManager::AtlasSlot& slot )
   {
-    const bool glyphNotCached = !mGlyphManager.IsCached( glyph.fontId, glyph.index, outline, slot );  // Check FontGlyphRecord vector for entry with glyph index and fontId
+    const bool glyphNotCached = !mGlyphManager.IsCached( glyph.fontId, glyph.index, style, slot );  // Check FontGlyphRecord vector for entry with glyph index and fontId
 
     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "AddGlyphs fontID[%u] glyphIndex[%u] [%s]\n", glyph.fontId, glyph.index, (glyphNotCached)?"not cached":"cached" );
 
@@ -243,7 +247,7 @@ struct AtlasRenderer::Impl
       PixelData bitmap;
 
       // Whether the glyph is an outline.
-      const bool isOutline = 0u != outline;
+      const bool isOutline = 0u != style.outline;
 
       // Whether the current glyph is a color one.
       const bool isColorGlyph = mFontClient.IsColorGlyph( glyph.fontId, glyph.index );
@@ -257,10 +261,10 @@ struct AtlasRenderer::Impl
 
         mFontClient.CreateBitmap( glyph.fontId,
                                   glyph.index,
-                                  glyph.softwareItalic,
-                                  glyph.softwareBold,
+                                  glyph.isItalicRequired,
+                                  glyph.isBoldRequired,
                                   glyphBufferData,
-                                  outline );
+                                  style.outline );
 
         // Create the pixel data.
         bitmap = PixelData::New( glyphBufferData.buffer,
@@ -292,21 +296,21 @@ struct AtlasRenderer::Impl
                                          blockSize.mNeededBlockHeight );
 
           // Locate a new slot for our glyph
-          mGlyphManager.Add( glyph, outline, bitmap, slot ); // slot will be 0 is glyph not added
+          mGlyphManager.Add( glyph, style, bitmap, slot ); // slot will be 0 is glyph not added
         }
       }
     }
     else
     {
       // We have 2+ copies of the same glyph
-      mGlyphManager.AdjustReferenceCount( glyph.fontId, glyph.index, outline, 1 ); //increment
+      mGlyphManager.AdjustReferenceCount( glyph.fontId, glyph.index, style, 1 ); //increment
     }
   }
 
   void GenerateMesh( const GlyphInfo& glyph,
                      const Vector2& position,
                      const Vector4& color,
-                     uint32_t outline,
+                     uint16_t outline,
                      AtlasManager::AtlasSlot& slot,
                      bool underlineGlyph,
                      float currentUnderlinePosition,
@@ -324,6 +328,8 @@ struct AtlasRenderer::Impl
     textCacheEntry.mImageId = slot.mImageId;
     textCacheEntry.mIndex = glyph.index;
     textCacheEntry.mOutlineWidth = outline;
+    textCacheEntry.isItalic = glyph.isItalicRequired;
+    textCacheEntry.isBold = glyph.isBoldRequired;
 
     newTextCache.PushBack( textCacheEntry );
 
@@ -363,10 +369,10 @@ struct AtlasRenderer::Impl
     {
       // 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 );
-      mActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
+      mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+      mActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+      mActor.SetProperty( Actor::Property::SIZE, textSize );
+      mActor.SetProperty( Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR );
     }
 
     for( std::vector< MeshRecord >::const_iterator it = meshContainer.begin(),
@@ -397,7 +403,7 @@ struct AtlasRenderer::Impl
 
         Actor shadowActor = CreateMeshActor(textControl, animatablePropertyIndex, color, meshRecord, textSize, STYLE_DROP_SHADOW );
 #if defined(DEBUG_ENABLED)
-        shadowActor.SetName( "Text Shadow renderable actor" );
+        shadowActor.SetProperty( Dali::Actor::Property::NAME, "Text Shadow renderable actor" );
 #endif
         // Offset shadow in x and y
         shadowActor.RegisterProperty("uOffset", shadowOffset );
@@ -445,7 +451,7 @@ struct AtlasRenderer::Impl
     const bool underlineEnabled = view.IsUnderlineEnabled();
     const Vector4& underlineColor( view.GetUnderlineColor() );
     const float underlineHeight = view.GetUnderlineHeight();
-    const unsigned int outlineWidth = view.GetOutlineWidth();
+    const uint16_t outlineWidth = view.GetOutlineWidth();
     const Vector4& outlineColor( view.GetOutlineColor() );
     const bool isOutline = 0u != outlineWidth;
 
@@ -528,17 +534,23 @@ struct AtlasRenderer::Impl
           lastUnderlinedFontId = glyph.fontId;
         } // underline
 
+        AtlasGlyphManager::GlyphStyle style;
+        style.isItalic = glyph.isItalicRequired;
+        style.isBold = glyph.isBoldRequired;
+
         // Retrieves and caches the glyph's bitmap.
-        CacheGlyph( glyph, lastFontId, NO_OUTLINE, slot );
+        CacheGlyph( glyph, lastFontId, style, slot );
 
         // Retrieves and caches the outline glyph's bitmap.
         if( isOutline )
         {
-          CacheGlyph( glyph, lastFontId, outlineWidth, slotOutline );
+          style.outline = outlineWidth;
+          CacheGlyph( glyph, lastFontId, style, slotOutline );
         }
 
         // Move the origin (0,0) of the mesh to the center of the actor
-        const Vector2 position = *( positionsBuffer + i ) - halfTextSize - lineOffsetPosition;
+        const Vector2& temp = *( positionsBuffer + i );
+        const Vector2 position = Vector2( roundf( temp.x ), temp.y ) - halfTextSize - lineOffsetPosition; // roundf() avoids pixel alignment issues.
 
         if ( 0u != slot.mImageId ) // invalid slot id, glyph has failed to be added to atlas
         {
@@ -655,7 +667,11 @@ struct AtlasRenderer::Impl
   {
     for( Vector< TextCacheEntry >::Iterator oldTextIter = mTextCache.Begin(); oldTextIter != mTextCache.End(); ++oldTextIter )
     {
-      mGlyphManager.AdjustReferenceCount( oldTextIter->mFontId, oldTextIter->mIndex, oldTextIter->mOutlineWidth, -1/*decrement*/ );
+      AtlasGlyphManager::GlyphStyle style;
+      style.outline = oldTextIter->mOutlineWidth;
+      style.isItalic = oldTextIter->isItalic;
+      style.isBold = oldTextIter->isBold;
+      mGlyphManager.AdjustReferenceCount( oldTextIter->mFontId, oldTextIter->mIndex, style, -1/*decrement*/ );
     }
     mTextCache.Resize( 0 );
   }
@@ -663,7 +679,7 @@ struct AtlasRenderer::Impl
   Actor CreateMeshActor( Actor textControl, Property::Index animatablePropertyIndex, const Vector4& defaultColor, const MeshRecord& meshRecord,
                          const Vector2& actorSize, Style style )
   {
-    PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat );
+    VertexBuffer quadVertices = VertexBuffer::New( mQuadVertexFormat );
     quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ), meshRecord.mMesh.mVertices.Size() );
 
     Geometry quadGeometry = Geometry::New();
@@ -721,15 +737,15 @@ struct AtlasRenderer::Impl
 
     Actor actor = Actor::New();
 #if defined(DEBUG_ENABLED)
-    actor.SetName( "Text renderable actor" );
+    actor.SetProperty( Dali::Actor::Property::NAME, "Text renderable actor" );
 #endif
     actor.AddRenderer( renderer );
     // Keep all of the origins aligned
-    actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
-    actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-    actor.SetSize( actorSize );
+    actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+    actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+    actor.SetProperty( Actor::Property::SIZE, actorSize );
     actor.RegisterProperty("uOffset", Vector2::ZERO );
-    actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
+    actor.SetProperty( Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR );
 
     return actor;
   }