From c2857ae2d6ac0d55b82c4af98ccf4c4f6ba8590b Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Wed, 1 Aug 2018 17:00:24 +0100 Subject: [PATCH] [4.0] FreeType fonts/library - Stop creating new instances. * The shaping tool creates a new instance of the FreeType library and the font faces instead of using the ones cached in the font client. It causes a bug in the WatchFace emulator when a new model is loaded (The text show the wrong glyphs shaped with the wrong font). Change-Id: I1c9ff437b9eed42ece2290642c279bc228ffa442 Signed-off-by: Victor Cebollada --- .../internal/text-abstraction/font-client-impl.cpp | 7 ++++ .../internal/text-abstraction/font-client-impl.h | 12 ++++++ .../text-abstraction/font-client-plugin-impl.cpp | 13 +++++++ .../text-abstraction/font-client-plugin-impl.h | 5 +++ .../internal/text-abstraction/shaping-impl.cpp | 45 ++++------------------ 5 files changed, 45 insertions(+), 37 deletions(-) diff --git a/text/dali/internal/text-abstraction/font-client-impl.cpp b/text/dali/internal/text-abstraction/font-client-impl.cpp index ee026cf..25cb710 100644 --- a/text/dali/internal/text-abstraction/font-client-impl.cpp +++ b/text/dali/internal/text-abstraction/font-client-impl.cpp @@ -297,6 +297,13 @@ bool FontClient::AddCustomFontDirectory( const FontPath& path ) return mPlugin->AddCustomFontDirectory( path ); } +FT_FaceRec_* FontClient::GetFreetypeFace( FontId fontId ) +{ + CreatePlugin(); + + return mPlugin->GetFreetypeFace( fontId ); +} + void FontClient::CreatePlugin() { if( !mPlugin ) diff --git a/text/dali/internal/text-abstraction/font-client-impl.h b/text/dali/internal/text-abstraction/font-client-impl.h index 725f0e0..7612d51 100644 --- a/text/dali/internal/text-abstraction/font-client-impl.h +++ b/text/dali/internal/text-abstraction/font-client-impl.h @@ -24,6 +24,9 @@ // INTERNAL INCLUDES #include + +struct FT_FaceRec_; + namespace Dali { @@ -203,6 +206,15 @@ public: */ bool AddCustomFontDirectory( const FontPath& path ); + /** + * @brief Retrieves the pointer to the FreeType Font Face for the given @p fontId. + * + * @param[in] fontId The font id. + * + * @return The pointer to the FreeType Font Face. + */ + FT_FaceRec_* GetFreetypeFace( FontId fontId ); + private: /** diff --git a/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp b/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp index 5f5a304..64c00c0 100644 --- a/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp +++ b/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp @@ -1288,6 +1288,19 @@ bool FontClient::Plugin::AddCustomFontDirectory( const FontPath& path ) return FcConfigAppFontAddDir( nullptr, reinterpret_cast( path.c_str() ) ); } +FT_FaceRec_* FontClient::Plugin::GetFreetypeFace( FontId fontId ) +{ + FT_Face fontFace = nullptr; + + if( ( fontId > 0u ) && + ( fontId - 1u < mFontFaceCache.size() ) ) + { + fontFace = mFontFaceCache[fontId - 1u].mFreeTypeFace; + } + + return fontFace; +} + void FontClient::Plugin::InitSystemFonts() { DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::InitSystemFonts\n" ); diff --git a/text/dali/internal/text-abstraction/font-client-plugin-impl.h b/text/dali/internal/text-abstraction/font-client-plugin-impl.h index 2e6e35a..31a1364 100644 --- a/text/dali/internal/text-abstraction/font-client-plugin-impl.h +++ b/text/dali/internal/text-abstraction/font-client-plugin-impl.h @@ -333,6 +333,11 @@ struct FontClient::Plugin */ bool AddCustomFontDirectory( const FontPath& path ); + /** + * @copydoc Dali::TextAbstraction::Internal::FontClient::GetFreetypeFace() + */ + FT_FaceRec_* GetFreetypeFace( FontId fontId ); + private: /** diff --git a/text/dali/internal/text-abstraction/shaping-impl.cpp b/text/dali/internal/text-abstraction/shaping-impl.cpp index 4d389c5..228b3de 100644 --- a/text/dali/internal/text-abstraction/shaping-impl.cpp +++ b/text/dali/internal/text-abstraction/shaping-impl.cpp @@ -23,14 +23,12 @@ #include #include #include +#include "font-client-impl.h" // EXTERNAL INCLUDES #include #include -#include -#include - namespace Dali { @@ -40,7 +38,7 @@ namespace TextAbstraction namespace Internal { -const char* DEFAULT_LANGUAGE = "en"; +const char* const DEFAULT_LANGUAGE = "en"; const unsigned int DEFAULT_LANGUAGE_LENGTH = 2u; const float FROM_266 = 1.0f / 64.0f; @@ -115,8 +113,7 @@ const hb_script_t SCRIPT_TO_HARFBUZZ[] = struct Shaping::Plugin { Plugin() - : mFreeTypeLibrary( NULL ), - mIndices(), + : mIndices(), mAdvance(), mCharacterMap(), mFontId( 0u ) @@ -125,16 +122,6 @@ struct Shaping::Plugin ~Plugin() { - FT_Done_FreeType( mFreeTypeLibrary ); - } - - void Initialize() - { - int error = FT_Init_FreeType( &mFreeTypeLibrary ); - if( FT_Err_Ok != error ) - { - DALI_LOG_ERROR( "FreeType Init error: %d\n", error ); - } } Length Shape( const Character* const text, @@ -157,30 +144,18 @@ struct Shaping::Plugin mOffset.Reserve( 2u * numberOfGlyphs ); TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); - - // Get the font's path file name from the font Id. - FontDescription fontDescription; - fontClient.GetDescription( fontId, fontDescription ); + TextAbstraction::Internal::FontClient& fontClientImpl = TextAbstraction::GetImplementation( fontClient ); // Create a FreeType font's face. FT_Face face; - FT_Error retVal = FT_New_Face( mFreeTypeLibrary, fontDescription.path.c_str(), 0u, &face ); - if( FT_Err_Ok != retVal ) + + face = fontClientImpl.GetFreetypeFace( fontId ); + if( nullptr == face ) { - DALI_LOG_ERROR( "Failed to open face: %s\n", fontDescription.path.c_str() ); + // Nothing to do if the face is null. return 0u; } - unsigned int horizontalDpi = 0u; - unsigned int verticalDpi = 0u; - fontClient.GetDpi( horizontalDpi, verticalDpi ); - - FT_Set_Char_Size( face, - 0u, - fontClient.GetPointSize( fontId ), - horizontalDpi, - verticalDpi ); - /* Get our harfbuzz font struct */ hb_font_t* harfBuzzFont; harfBuzzFont = hb_ft_font_create( face, NULL ); @@ -274,7 +249,6 @@ struct Shaping::Plugin /* Cleanup */ hb_buffer_destroy( harfBuzzBuffer ); hb_font_destroy( harfBuzzFont ); - FT_Done_Face( face ); return mIndices.Count(); } @@ -304,8 +278,6 @@ struct Shaping::Plugin } } - FT_Library mFreeTypeLibrary; - Vector mIndices; Vector mAdvance; Vector mOffset; @@ -375,7 +347,6 @@ void Shaping::CreatePlugin() if( !mPlugin ) { mPlugin = new Plugin(); - mPlugin->Initialize(); } } -- 2.7.4