X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=text%2Fdali%2Finternal%2Ftext-abstraction%2Ffont-client-plugin-impl.h;h=c1e158fa14a5ebecbf7cae7455bb9c4e8e992c90;hb=d8a28c83a0d0671086393c42275e4a2598445db5;hp=65cd9e56efea747d8abd64a3b12f72962c04aa8f;hpb=763860897fc161136098cc8ec843641d81137e4d;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git 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 65cd9e5..c1e158f 100644 --- a/text/dali/internal/text-abstraction/font-client-plugin-impl.h +++ b/text/dali/internal/text-abstraction/font-client-plugin-impl.h @@ -1,8 +1,8 @@ -#ifndef __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__ -#define __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__ +#ifndef DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H +#define DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -23,12 +23,21 @@ #include #include +#ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING +#include +#else +class VectorFontCache; +#endif + // EXTERNAL INCLUDES #include #include FT_FREETYPE_H #include FT_GLYPH_H +#include FT_OUTLINE_H +#include FT_STROKER_H // forward declarations of font config types. +struct _FcCharSet; struct _FcFontSet; struct _FcPattern; @@ -45,6 +54,7 @@ namespace Internal *@brief Type used for indices addressing the vector with front descriptions of validated fonts. */ typedef uint32_t FontDescriptionId; +typedef Vector<_FcCharSet*> CharacterSetList; /** * @brief FontClient implementation. @@ -56,10 +66,11 @@ struct FontClient::Plugin */ struct FallbackCacheItem { - FallbackCacheItem( const FontDescription& fontDescription, FontList* fallbackFonts ); + FallbackCacheItem( const FontDescription& fontDescription, FontList* fallbackFonts, CharacterSetList* characterSets ); FontDescription fontDescription; ///< The font description. FontList* fallbackFonts; ///< The list of fallback fonts for the given font-description. + CharacterSetList* characterSets; ///< The list of character sets for the given font-description. }; /** @@ -80,46 +91,50 @@ struct FontClient::Plugin struct FontIdCacheItem { FontIdCacheItem( FontDescriptionId validatedFontId, - PointSize26Dot6 pointSize, + PointSize26Dot6 requestedPointSize, FontId fontId ); - FontDescriptionId validatedFontId; ///< Index to the vector with font descriptions. - PointSize26Dot6 pointSize; ///< The font point size. - FontId fontId; ///< The font id. + FontDescriptionId validatedFontId; ///< Index to the vector with font descriptions. + PointSize26Dot6 requestedPointSize; ///< The font point size. + FontId fontId; ///< The font identifier. }; /** * @brief Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'. */ - struct CacheItem + struct FontFaceCacheItem { - CacheItem( FT_Face ftFace, - const FontPath& path, - PointSize26Dot6 pointSize, - FaceIndex face, - const FontMetrics& metrics ); - - CacheItem( FT_Face ftFace, - const FontPath& path, - PointSize26Dot6 pointSize, - FaceIndex face, - const FontMetrics& metrics, - float fixedWidth, - float fixedHeight ); - - FT_Face mFreeTypeFace; ///< The FreeType face. - FontPath mPath; ///< The path to the font file name. - PointSize26Dot6 mPointSize; ///< The font point size. - FaceIndex mFaceIndex; ///< The face index. - FontMetrics mMetrics; ///< The font metrics. - FT_Short mFixedWidthPixels; ///< The height in pixels (fixed size bitmaps only) - FT_Short mFixedHeightPixels; ///< The height in pixels (fixed size bitmaps only) - bool mIsFixedSizeBitmap; ///< Whether the font has fixed size bitmaps. + FontFaceCacheItem( FT_Face ftFace, + const FontPath& path, + PointSize26Dot6 requestedPointSize, + FaceIndex face, + const FontMetrics& metrics ); + + FontFaceCacheItem( FT_Face ftFace, + const FontPath& path, + PointSize26Dot6 requestedPointSize, + FaceIndex face, + const FontMetrics& metrics, + float fixedWidth, + float fixedHeight, + bool hasColorTables ); + + FT_Face mFreeTypeFace; ///< The FreeType face. + FontPath mPath; ///< The path to the font file name. + PointSize26Dot6 mRequestedPointSize; ///< The font point size. + FaceIndex mFaceIndex; ///< The face index. + FontMetrics mMetrics; ///< The font metrics. + _FcCharSet* mCharacterSet; ///< Pointer with the range of characters. + FT_Short mFixedWidthPixels; ///< The height in pixels (fixed size bitmaps only) + FT_Short mFixedHeightPixels; ///< The height in pixels (fixed size bitmaps only) + unsigned int mVectorFontId; ///< The ID of the equivalent vector-based font + bool mIsFixedSizeBitmap : 1; ///< Whether the font has fixed size bitmaps. + bool mHasColorTables : 1; ///< Whether the font has color tables. }; struct EllipsisItem { - PointSize26Dot6 size; + PointSize26Dot6 requestedPointSize; GlyphInfo glyph; }; @@ -142,139 +157,187 @@ struct FontClient::Plugin ~Plugin(); /** - * @copydoc Dali::FontClient::SetDpi() + * @copydoc Dali::TextAbstraction::FontClient::SetDpi() */ void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi ); /** - * @copydoc Dali::FontClient::ResetSystemDefaults() + * @copydoc Dali::TextAbstraction::FontClient::ResetSystemDefaults() */ void ResetSystemDefaults(); /** - * @copydoc Dali::FontClient::SetDefaultFont() + * @copydoc Dali::TextAbstraction::FontClient::SetDefaultFont() */ - void SetDefaultFont( const FontDescription& fontDescription ); + void SetDefaultFont( const FontDescription& preferredFontDescription ); /** - * @copydoc Dali::FontClient::GetDefaultPlatformFontDescription() + * @copydoc Dali::TextAbstraction::FontClient::GetDefaultPlatformFontDescription() */ void GetDefaultPlatformFontDescription( FontDescription& fontDescription ); /** - * @copydoc Dali::FontClient::GetDefaultFonts() + * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFonts() */ void GetDefaultFonts( FontList& defaultFonts ); /** - * @copydoc Dali::FontClient::GetSystemFonts() + * @copydoc Dali::TextAbstraction::FontClient::GetSystemFonts() */ void GetSystemFonts( FontList& systemFonts ); /** - * @copydoc Dali::FontClient::GetDescription() + * @copydoc Dali::TextAbstraction::FontClient::GetDescription() */ void GetDescription( FontId id, FontDescription& fontDescription ) const; /** - * @copydoc Dali::FontClient::GetPointSize() + * @copydoc Dali::TextAbstraction::FontClient::GetPointSize() */ PointSize26Dot6 GetPointSize( FontId id ); /** - * @copydoc Dali::FontClient::FindFontForCharacter() + * @copydoc Dali::TextAbstraction::FontClient::IsCharacterSupportedByFont() + */ + bool IsCharacterSupportedByFont( FontId fontId, Character character ); + + /** + * @brief Finds within the @p fontList a font which support the @p carcode. + * + * @param[in] fontList A list of font paths, family, width, weight and slant. + * @param[in] characterSetList A list that contains a character set for each description of the font list. + * @param[in] charcode The character for which a font is needed. + * @param[in] requestedPointSize The point size in 26.6 fractional points. + * @param[in] preferColor @e true if a color font is preferred. + * + * @return A valid font identifier, or zero if no font is found. */ FontId FindFontForCharacter( const FontList& fontList, + const CharacterSetList& characterSetList, Character charcode, - PointSize26Dot6 requestedSize, + PointSize26Dot6 requestedPointSize, bool preferColor ); /** - * @copydoc Dali::FontClient::FindDefaultFont() + * @copydoc Dali::TextAbstraction::FontClient::FindDefaultFont() */ - FontId FindDefaultFont( Character charcode, PointSize26Dot6 pointSize, bool preferColor ); + FontId FindDefaultFont( Character charcode, + PointSize26Dot6 requestedPointSize, + bool preferColor ); /** - * @copydoc Dali::FontClient::FindFallbackFont() + * @copydoc Dali::TextAbstraction::FontClient::FindFallbackFont() */ - FontId FindFallbackFont( FontId preferredFont, Character charcode, PointSize26Dot6 requestedSize, bool preferColor ); + FontId FindFallbackFont( Character charcode, + const FontDescription& preferredFontDescription, + PointSize26Dot6 requestedPointSize, + bool preferColor ); /** - * @see Dali::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex ) + * @see Dali::TextAbstraction::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex ) * * @param[in] cacheDescription Whether to cache the font description. */ - FontId GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription = true ); + FontId GetFontId( const FontPath& path, + PointSize26Dot6 requestedPointSize, + FaceIndex faceIndex, + bool cacheDescription ); /** - * @copydoc Dali::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 pointSize, FaceIndex faceIndex ) + * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontDescription& preferredFontDescription, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex ) */ FontId GetFontId( const FontDescription& fontDescription, - PointSize26Dot6 pointSize, + PointSize26Dot6 requestedPointSize, FaceIndex faceIndex ); /** - * @copydoc Dali::FontClient::IsScalable( const FontPath& path ) + * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontPath& path ) */ bool IsScalable( const FontPath& path ); /** - * @copydoc Dali::FontClient::IsScalable( const FontDescription& fontDescription ) + * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontDescription& fontDescription ) */ bool IsScalable( const FontDescription& fontDescription ); /** - * @copydoc Dali::FontClient::GetFixedSizes() + * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes() */ void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes ); /** - * @copydoc Dali::FontClient::GetFixedSizes() + * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes() */ void GetFixedSizes( const FontDescription& fontDescription, Dali::Vector< PointSize26Dot6 >& sizes ); /** - * @copydoc Dali::FontClient::GetFontMetrics() + * @copydoc Dali::TextAbstraction::FontClient::GetFontMetrics() */ - void GetFontMetrics( FontId fontId, FontMetrics& metrics, int desiredFixedSize ); + void GetFontMetrics( FontId fontId, FontMetrics& metrics ); /** - * @copydoc Dali::FontClient::GetGlyphIndex() + * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex() */ GlyphIndex GetGlyphIndex( FontId fontId, Character charcode ); /** - * @copydoc Dali::FontClient::GetGlyphMetrics() + * @copydoc Dali::TextAbstraction::FontClient::GetGlyphMetrics() + */ + bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal ); + + /** + * Helper for GetGlyphMetrics when using bitmaps + */ + bool GetBitmapMetrics( GlyphInfo* array, uint32_t size, bool horizontal ); + + /** + * Helper for GetGlyphMetrics when using vectors + */ + bool GetVectorMetrics( GlyphInfo* array, uint32_t size, bool horizontal ); + + /** + * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth ) + */ + void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth ); + + /** + * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth ) + */ + PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth ); + + /** + * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob() */ - bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal, int desiredFixedSize ); + void CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight ); /** - * @copydoc Dali::FontClient::CreateBitmap() + * @copydoc Dali::TextAbstraction::FontClient::GetEllipsisGlyph() */ - BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex ); + const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 requestedPointSize ); /** - * @copydoc Dali::FontClient::GetEllipsisGlyph() + * @copydoc Dali::TextAbstraction::FontClient::IsColorGlyph() */ - const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 pointSize ); + bool IsColorGlyph( FontId fontId, GlyphIndex glyphIndex ); private: /** - * Caches the fonts present in the platform. + * @brief Caches the fonts present in the platform. * * Calls GetFcFontSet() to retrieve the fonts. */ void InitSystemFonts(); /** - * Gets the FontDescription which matches the given pattern - * @param[in] pattern pattern to match against - * @param[out] fontDescription the resultant fontDescription that matched - * @return true if match found + * @brief Gets the FontDescription which matches the given pattern. + * @param[in] pattern pattern to match against. + * @param[out] fontDescription the resultant fontDescription that matched. + * @param[out] characterSet The character set for that pattern. + * @return true if match found. */ - bool MatchFontDescriptionToPattern( _FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription ); + bool MatchFontDescriptionToPattern( _FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription, _FcCharSet** characterSet ); /** * @brief Creates a font family pattern used to match fonts. @@ -283,7 +346,7 @@ private: * * @return The pattern. */ - _FcPattern* CreateFontFamilyPattern( const FontDescription& fontDescription ); + _FcPattern* CreateFontFamilyPattern( const FontDescription& fontDescription ) const; /** * Retrieves the fonts present in the platform. @@ -318,45 +381,37 @@ private: * @brief Creates a font. * * @param[in] path The path to the font file name. - * @param[in] pointSize The font point size. - * @param[in] faceIndex A face index. - * @param[in] cacheDescription Whether to cache the font description. - * - * @return The font id. - */ - FontId CreateFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription ); - - /** - * @brief Creates a fixed size font - * - * @param[in] path The path to the font file name. - * @param[in] pointSize The font point size( must be an available size ). + * @param[in] requestedPointSize The requested point size. * @param[in] faceIndex A face index. * @param[in] cacheDescription Whether to cache the font description. * - * @return The font id. + * @return The font identifier. */ - FontId CreateFixedSizeFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription ); + FontId CreateFont( const FontPath& path, + PointSize26Dot6 requestedPointSize, + FaceIndex faceIndex, + bool cacheDescription ); /** + * @brief Copy the FreeType bitmap to the given buffer. * - * @param[in] destBitmap - * @param[in] srcBitmap + * @param[out] data The bitmap data. + * @param[in] srcBitmap The FreeType bitmap. */ - void ConvertBitmap( BufferImage& destBitmap, FT_Bitmap srcBitmap ); + void ConvertBitmap( TextAbstraction::FontClient::GlyphBufferData& data, FT_Bitmap srcBitmap ); /** * @brief Finds in the cache if there is a triplet with the path to the font file name, the font point size and the face index. - * If there is one , if writes the font id in the param @p fontId. + * If there is one , if writes the font identifier in the param @p fontId. * * @param[in] path Path to the font file name. - * @param[in] pointSize The font point size. + * @param[in] requestedPointSize The font point size. * @param[in] faceIndex The face index. - * @param[out] fontId The font id. + * @param[out] fontId The font identifier. * * @return @e true if there triplet is found. */ - bool FindFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, FontId& fontId ) const; + bool FindFont( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex, FontId& fontId ) const; /** * @brief Finds in the cache a cluster 'font family, font width, font weight, font slant' @@ -375,22 +430,24 @@ private: * * @param[in] fontDescription The font to validate. * @param[out] A valid pointer to a font list, or NULL if not found. + * @param[out] characterSetList A valid pointer to a character set list, or NULL if not found. */ bool FindFallbackFontList( const FontDescription& fontDescription, - FontList*& fontList ); + FontList*& fontList, + CharacterSetList*& characterSetList ); /** - * @brief Finds in the cache a pair 'validated font id and font point size'. - * If there is one it writes the font id in the param @p fontId. + * @brief Finds in the cache a pair 'validated font identifier and font point size'. + * If there is one it writes the font identifier in the param @p fontId. * * @param[in] validatedFontId Index to the vector with font descriptions. - * @param[in] pointSize The font point size. - * @param[out] fontId The font id. + * @param[in] requestedPointSize The font point size. + * @param[out] fontId The font identifier. * * @return @e true if the pair is found. */ bool FindFont( FontDescriptionId validatedFontId, - PointSize26Dot6 pointSize, + PointSize26Dot6 requestedPointSize, FontId& fontId ); /** @@ -407,18 +464,37 @@ private: * * @param[in] fontDescription A font description. * @param[out] fontList A list of the fonts which are a close match for fontDescription. + * @param[out] characterSetList A list of the character sets which are a close match for fontDescription. */ - void SetFontList( const FontDescription& fontDescription, FontList& fontList ); + void SetFontList( const FontDescription& fontDescription, FontList& fontList, CharacterSetList& characterSetList ); /** * Caches a font path. * * @param[in] ftFace The FreeType face. * @param[in] id The font identifier. - * @param[in] pointSize The font point size. + * @param[in] requestedPointSize The font point size. * @param[in] path Path to the font file name. */ - void CacheFontPath( FT_Face ftFace, FontId id, PointSize26Dot6 pointSize, const FontPath& path ); + void CacheFontPath( FT_Face ftFace, FontId id, PointSize26Dot6 requestedPointSize, const FontPath& path ); + + /** + * @brief Creates a character set from a given font's @p description. + * + * @param[in] description The font's description. + * + * @return A character set. + */ + _FcCharSet* CreateCharacterSetFromDescription( const FontDescription& description ) const; + +private: + + // Declared private and left undefined to avoid copies. + Plugin( const Plugin& ); + // Declared private and left undefined to avoid copies. + Plugin& operator=( const Plugin& ); + +private: FT_Library mFreeTypeLibrary; ///< A handle to a FreeType library instance. @@ -429,13 +505,17 @@ private: FontList mSystemFonts; ///< Cached system fonts. FontList mDefaultFonts; ///< Cached default fonts. + CharacterSetList mDefaultFontCharacterSets; std::vector mFallbackCache; ///< Cached fallback font lists. - std::vector mFontCache; ///< Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'. + std::vector mFontCache; ///< Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'. std::vector mValidatedFontCache; ///< Caches indices to the vector of font descriptions for a given font. FontList mFontDescriptionCache; ///< Caches font descriptions for the validated font. - std::vector mFontIdCache; ///< Caches font ids for the pairs of font point size and the index to the vector with font descriptions of the validated fonts. + CharacterSetList mCharacterSetCache; ///< Caches character set lists for the validated font. + std::vector mFontIdCache; ///< Caches font identifiers for the pairs of font point size and the index to the vector with font descriptions of the validated fonts. + + VectorFontCache* mVectorFontCache; ///< Separate cache for vector data blobs etc. Vector mEllipsisCache; ///< Caches ellipsis glyphs for a particular point size. @@ -448,4 +528,4 @@ private: } // namespace Dali -#endif // __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__ +#endif // DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H