Fix for PreInitialize, including FontClient
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / font-client-impl.cpp
old mode 100644 (file)
new mode 100755 (executable)
index ad125fd..4e82a54
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 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.
 #include <dali/internal/text/text-abstraction/font-client-impl.h>
 
 // EXTERNAL INCLUDES
-#ifndef DALI_PROFILE_UBUNTU
+#if !(defined(DALI_PROFILE_UBUNTU) || defined(ANDROID) || defined(WIN32))
 #include <vconf.h>
 #endif
 
 // INTERNAL INCLUDES
-#include <dali/devel-api/adaptor-framework/singleton-service.h>
+#include <dali/devel-api/common/singleton-service.h>
 #include <dali/internal/text/text-abstraction/font-client-plugin-impl.h>
 
+#include <dali/devel-api/text-abstraction/glyph-info.h>
+
 namespace Dali
 {
 
@@ -36,6 +38,8 @@ namespace TextAbstraction
 namespace Internal
 {
 
+Dali::TextAbstraction::FontClient FontClient::gPreInitializedFontClient( NULL );
+
 FontClient::FontClient()
 : mPlugin( nullptr ),
   mDpiHorizontal( 0 ),
@@ -65,7 +69,16 @@ Dali::TextAbstraction::FontClient FontClient::Get()
     }
     else // create and register the object
     {
-      fontClientHandle = Dali::TextAbstraction::FontClient( new FontClient );
+      if( gPreInitializedFontClient )
+      {
+        fontClientHandle = gPreInitializedFontClient;
+        gPreInitializedFontClient.Reset(); // No longer needed
+      }
+      else
+      {
+        fontClientHandle = Dali::TextAbstraction::FontClient( new FontClient );
+      }
+
       service.Register( typeid( fontClientHandle ), fontClientHandle );
     }
   }
@@ -73,6 +86,26 @@ Dali::TextAbstraction::FontClient FontClient::Get()
   return fontClientHandle;
 }
 
+Dali::TextAbstraction::FontClient FontClient::PreInitialize()
+{
+  gPreInitializedFontClient = Dali::TextAbstraction::FontClient( new FontClient );
+
+  // Make DefaultFontDescription cached
+  Dali::TextAbstraction::FontDescription defaultFontDescription;
+  gPreInitializedFontClient.GetDefaultPlatformFontDescription( defaultFontDescription );
+
+  return gPreInitializedFontClient;
+}
+
+void FontClient::ClearCache()
+{
+  if( mPlugin )
+  {
+    mPlugin->ClearCache();
+  }
+}
+
+
 void FontClient::SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi  )
 {
   mDpiHorizontal = horizontalDpi;
@@ -95,9 +128,9 @@ int FontClient::GetDefaultFontSize()
 {
   int fontSize( -1 );
 
-#ifndef DALI_PROFILE_UBUNTU
+#if !(defined(DALI_PROFILE_UBUNTU) || defined(ANDROID) || defined(WIN32))
   vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
-#endif // DALI_PROFILE_UBUNTU
+#endif
 
   return fontSize;
 }
@@ -204,6 +237,15 @@ void FontClient::GetFixedSizes( const FontDescription& fontDescription,
   mPlugin->GetFixedSizes( fontDescription, sizes );
 }
 
+bool FontClient::HasItalicStyle( FontId fontId ) const
+{
+  if( !mPlugin )
+  {
+    return false;
+  }
+  return mPlugin->HasItalicStyle( fontId );
+}
+
 FontId FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
 {
   CreatePlugin();
@@ -225,11 +267,18 @@ FontId FontClient::GetFontId( const FontDescription& fontDescription,
                              faceIndex );
 }
 
+FontId FontClient::GetFontId( const BitmapFont& bitmapFont )
+{
+  CreatePlugin();
+
+  return mPlugin->GetFontId( bitmapFont );
+}
+
 void FontClient::GetFontMetrics( FontId fontId, FontMetrics& metrics )
 {
   CreatePlugin();
 
-  return mPlugin->GetFontMetrics( fontId, metrics );
+  mPlugin->GetFontMetrics( fontId, metrics );
 }
 
 GlyphIndex FontClient::GetGlyphIndex( FontId fontId, Character charcode )
@@ -246,11 +295,11 @@ bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType typ
   return mPlugin->GetGlyphMetrics( array, size, type, horizontal );
 }
 
-void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool softwareItalic, bool softwareBold, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
+void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
 {
   CreatePlugin();
 
-  mPlugin->CreateBitmap( fontId, glyphIndex, softwareItalic, softwareBold, data, outlineWidth );
+  mPlugin->CreateBitmap( fontId, glyphIndex, isItalicRequired, isBoldRequired, data, outlineWidth );
 }
 
 PixelData FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
@@ -264,7 +313,7 @@ void FontClient::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorB
 {
   CreatePlugin();
 
-  return mPlugin->CreateVectorBlob( fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight );
+  mPlugin->CreateVectorBlob( fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight );
 }
 
 const GlyphInfo& FontClient::GetEllipsisGlyph( PointSize26Dot6 requestedPointSize )
@@ -281,6 +330,13 @@ bool FontClient::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex )
   return mPlugin->IsColorGlyph( fontId, glyphIndex );
 }
 
+GlyphIndex FontClient::CreateEmbeddedItem(const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat)
+{
+  CreatePlugin();
+
+  return mPlugin->CreateEmbeddedItem( description, pixelFormat );
+}
+
 FT_FaceRec_* FontClient::GetFreetypeFace( FontId fontId )
 {
   CreatePlugin();
@@ -288,6 +344,20 @@ FT_FaceRec_* FontClient::GetFreetypeFace( FontId fontId )
   return mPlugin->GetFreetypeFace( fontId );
 }
 
+FontDescription::Type FontClient::GetFontType( FontId fontId )
+{
+  CreatePlugin();
+
+  return mPlugin->GetFontType( fontId );
+}
+
+bool FontClient::AddCustomFontDirectory( const FontPath& path )
+{
+  CreatePlugin();
+
+  return mPlugin->AddCustomFontDirectory( path );
+}
+
 void FontClient::CreatePlugin()
 {
   if( !mPlugin )