From aead83b18b539ee9e2ac9b4ec5faf85d6e2aae75 Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Wed, 1 Aug 2018 17:00:24 +0100 Subject: [PATCH] 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 --- .../text/text-abstraction/font-client-impl.cpp | 7 ++++ .../text/text-abstraction/font-client-impl.h | 12 ++++++ .../text-abstraction/font-client-plugin-impl.cpp | 13 +++++++ .../text-abstraction/font-client-plugin-impl.h | 5 +++ .../text/text-abstraction/shaping-impl.cpp | 45 ++++------------------ 5 files changed, 45 insertions(+), 37 deletions(-) diff --git a/dali/internal/text/text-abstraction/font-client-impl.cpp b/dali/internal/text/text-abstraction/font-client-impl.cpp index 6e081af..d88a8e6 100644 --- a/dali/internal/text/text-abstraction/font-client-impl.cpp +++ b/dali/internal/text/text-abstraction/font-client-impl.cpp @@ -281,6 +281,13 @@ bool FontClient::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex ) return mPlugin->IsColorGlyph( fontId, glyphIndex ); } +FT_FaceRec_* FontClient::GetFreetypeFace( FontId fontId ) +{ + CreatePlugin(); + + return mPlugin->GetFreetypeFace( fontId ); +} + void FontClient::CreatePlugin() { if( !mPlugin ) diff --git a/dali/internal/text/text-abstraction/font-client-impl.h b/dali/internal/text/text-abstraction/font-client-impl.h index cfa3a20..29c2a02 100644 --- a/dali/internal/text/text-abstraction/font-client-impl.h +++ b/dali/internal/text/text-abstraction/font-client-impl.h @@ -24,6 +24,9 @@ // INTERNAL INCLUDES #include + +struct FT_FaceRec_; + namespace Dali { @@ -193,6 +196,15 @@ public: */ bool IsColorGlyph( FontId fontId, GlyphIndex glyphIndex ); + /** + * @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/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp b/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp index fc85a4b..33bd524 100644 --- a/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp +++ b/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp @@ -1256,6 +1256,19 @@ bool FontClient::Plugin::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex ) return FT_Err_Ok == error; } +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/dali/internal/text/text-abstraction/font-client-plugin-impl.h b/dali/internal/text/text-abstraction/font-client-plugin-impl.h index 4de27b7..4d291e1 100644 --- a/dali/internal/text/text-abstraction/font-client-plugin-impl.h +++ b/dali/internal/text/text-abstraction/font-client-plugin-impl.h @@ -323,6 +323,11 @@ struct FontClient::Plugin */ bool IsColorGlyph( FontId fontId, GlyphIndex glyphIndex ); + /** + * @copydoc Dali::TextAbstraction::Internal::FontClient::GetFreetypeFace() + */ + FT_FaceRec_* GetFreetypeFace( FontId fontId ); + private: /** diff --git a/dali/internal/text/text-abstraction/shaping-impl.cpp b/dali/internal/text/text-abstraction/shaping-impl.cpp index cabbe89..f72475f 100644 --- a/dali/internal/text/text-abstraction/shaping-impl.cpp +++ b/dali/internal/text/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 ); @@ -273,7 +248,6 @@ struct Shaping::Plugin /* Cleanup */ hb_buffer_destroy( harfBuzzBuffer ); hb_font_destroy( harfBuzzFont ); - FT_Done_Face( face ); return mIndices.Count(); } @@ -303,8 +277,6 @@ struct Shaping::Plugin } } - FT_Library mFreeTypeLibrary; - Vector mIndices; Vector mAdvance; Vector mOffset; @@ -374,7 +346,6 @@ void Shaping::CreatePlugin() if( !mPlugin ) { mPlugin = new Plugin(); - mPlugin->Initialize(); } } -- 2.7.4