1 #ifndef __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__
2 #define __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/text-abstraction/font-metrics.h>
23 #include <dali/internal/text-abstraction/font-client-impl.h>
27 #include FT_FREETYPE_H
30 // forward declarations of font config types.
37 namespace TextAbstraction
44 *@brief Type used for indices addressing the vector with front descriptions of validated pairs 'font family name, font style'.
46 typedef uint32_t FontDescriptionId;
49 * @brief FontClient implementation.
51 struct FontClient::Plugin
54 * @brief Caches an index to the vector of font descriptions for a given 'font family name, font style'.
56 struct FontDescriptionCacheItem
58 FontDescriptionCacheItem( const FontFamily& fontFamily,
59 const FontStyle& fontStyle,
60 FontDescriptionId index );
62 FontFamily fontFamily; ///< The font family name.
63 FontStyle fontStyle; ///< The font style.
64 FontDescriptionId index; ///< Index to the vector of font descriptions.
68 * @brief Caches the font id of the pair font point size and the index to the vector of font descriptions of validated fonts.
70 struct FontIdCacheItem
72 FontIdCacheItem( FontDescriptionId validatedFontId,
73 PointSize26Dot6 pointSize,
76 FontDescriptionId validatedFontId; ///< Index to the vector with font descriptions.
77 PointSize26Dot6 pointSize; ///< The font point size.
78 FontId fontId; ///< The font id.
82 * @brief Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'.
86 CacheItem( FT_Face ftFace,
88 PointSize26Dot6 pointSize,
90 const FontMetrics& metrics,
91 bool isFixedSizeBitmap = false );
93 FT_Face mFreeTypeFace; ///< The FreeType face.
94 FontPath mPath; ///< The path to the font file name.
95 PointSize26Dot6 mPointSize; ///< The font point size.
96 FaceIndex mFaceIndex; ///< The face index.
97 FontMetrics mMetrics; ///< The font metrics.
98 bool mIsFixedSizeBitmap; ///< Font is fixed size bitmap.
104 * Initializes the FreeType library.
105 * Initializes the dpi values.
107 * @param[in] horizontalDpi The horizontal dpi.
108 * @param[in] verticalDpi The vertical dpi.
110 Plugin( unsigned int horizontalDpi, unsigned int verticalDpi );
113 * Default destructor.
115 * Frees any allocated resource.
120 * @copydoc Dali::FontClient::SetDpi()
122 void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
125 * @copydoc Dali::FontClient::SetDefaultFontFamily()
127 void SetDefaultFontFamily( const FontFamily& fontFamilyName,
128 const FontStyle& fontStyle );
131 * @copydoc Dali::FontClient::GetDefaultFonts()
133 void GetDefaultFonts( FontList& defaultFonts );
136 * @copydoc Dali::FontClient::GetSystemFonts()
138 void GetSystemFonts( FontList& systemFonts );
141 * @copydoc Dali::FontClient::GetDescription()
143 void GetDescription( FontId id, FontDescription& fontDescription ) const;
146 * @copydoc Dali::FontClient::GetPointSize()
148 PointSize26Dot6 GetPointSize( FontId id );
151 * @copydoc Dali::FontClient::FindDefaultFont()
153 FontId FindDefaultFont( Character charcode, PointSize26Dot6 pointSize );
156 * @see Dali::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex )
158 * @param[in] cacheDescription Whether to cache the font description.
160 FontId GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription = true );
163 * @copydoc Dali::FontClient::GetFontId(const FontFamily& fontFamily, const FontStyle& fontStyle, PointSize26Dot6 pointSize, FaceIndex faceIndex )
165 FontId GetFontId( const FontFamily& fontFamily,
166 const FontStyle& fontStyle,
167 PointSize26Dot6 pointSize,
168 FaceIndex faceIndex );
171 * @copydoc Dali::FontClient::IsScalable(const FontPath& path )
173 bool IsScalable( const FontPath& path );
176 * @copydoc Dali::FontClient::IsScalable( const FontFamily& fontFamily, const FontStyle& fontStyle )
178 bool IsScalable( const FontFamily& fontFamily, const FontStyle& fontStyle );
181 * @copydoc Dali::FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
183 void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
186 * @copydoc Dali::FontClient::GetFixedSizes( const FontFamily& fontFamily, const FontStyle& fontStyle, Dali::Vector< PointSize26Dot6>& sizes )
188 void GetFixedSizes( const FontFamily& fontFamily,
189 const FontStyle& fontStyle,
190 Dali::Vector< PointSize26Dot6 >& sizes );
193 * @copydoc Dali::FontClient::GetFontMetrics()
195 void GetFontMetrics( FontId fontId, FontMetrics& metrics );
198 * @copydoc Dali::FontClient::GetGlyphIndex()
200 GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
203 * @copydoc Dali::FontClient::CreateMetrics()
205 bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal );
208 * @copydoc Dali::FontClient::CreateBitmap()
210 BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
215 * Caches the fonts present in the platform.
217 * Calls GetFcFontSet() to retrieve the fonts.
219 void InitSystemFonts();
222 * @brief Creates a font family pattern used to match fonts.
224 * @param[in] fontFamily The font family name.
225 * @param[in] fontStyle The font style.
227 * @return The pattern.
229 _FcPattern* CreateFontFamilyPattern( const FontFamily& fontFamily,
230 const FontStyle& fontStyle );
233 * Retrieves the fonts present in the platform.
235 * @return A font fonfig data structure with the platform's fonts.
237 _FcFontSet* GetFcFontSet() const;
240 * Retrieves a font config object's value from a pattern.
242 * @param[in] pattern The font config pattern.
243 * @param[in] n The object.
244 * @param[out] string The object's value.
246 * @return @e true if the operation is successful.
248 bool GetFcString( const _FcPattern* const pattern, const char* const n, std::string& string );
251 * @brief Creates a font.
253 * @param[in] path The path to the font file name.
254 * @param[in] pointSize The font point size.
255 * @param[in] faceIndex A face index.
256 * @param[in] cacheDescription Whether to cache the font description.
258 * @return The font id.
260 FontId CreateFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription );
263 * @brief Creates a fixed size font
265 * @param[in] path The path to the font file name.
266 * @param[in] pointSize The font point size( must be an available size ).
267 * @param[in] faceIndex A face index.
268 * @param[in] cacheDescription Whether to cache the font description.
270 * @return The font id.
272 FontId CreateFixedSizeFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription );
276 * @param[in] destBitmap
277 * @param[in] srcBitmap
279 void ConvertBitmap( BufferImage& destBitmap, FT_Bitmap srcBitmap );
282 * @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.
283 * If there is one , if writes the font id in the param @p fontId.
285 * @param[in] path Path to the font file name.
286 * @param[in] pointSize The font point size.
287 * @param[in] faceIndex The face index.
288 * @param[out] fontId The font id.
290 * @return @e true if there triplet is found.
292 bool FindFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, FontId& fontId ) const;
295 * @brief Finds in the cahce a pair 'font family, font style'.
296 * If there is one, it writes the index to the vector with font descriptions in the param @p validatedFontId.
298 * @param[in] fontFamily The font family name.
299 * @param[in] fontStyle The font style.
300 * @param[out] validatedFontId The index to the vector with font descriptions.
302 * @return @e true if the pair is found.
304 bool FindValidatedFont( const FontFamily& fontFamily,
305 const FontStyle& fontStyle,
306 FontDescriptionId& validatedFontId );
309 * @brief Finds in the cache a pair 'validated font id and font point size'.
310 * If there is one it writes the font id in the param @p fontId.
312 * @param[in] validatedFontId Index to the vector with font descriptions.
313 * @param[in] pointSize The font point size.
314 * @param[out] fontId The font id.
316 * @return @e true if the pair is found.
318 bool FindFont( FontDescriptionId validatedFontId,
319 PointSize26Dot6 pointSize,
323 * @brief Validate a font family and style
325 * @param[in] fontFamily Font Family to validate
326 * @param[in] fontStyle Font Style to validate
327 * @param[out] validatedFontId Result of validation
329 void ValidateFont( const FontFamily& fontFamily,
330 const FontStyle& fontStyle,
331 FontDescriptionId& validatedFontId );
333 FT_Library mFreeTypeLibrary; ///< A handle to a FreeType library instance.
335 unsigned int mDpiHorizontal; ///< Horizontal dpi.
336 unsigned int mDpiVertical; ///< Vertical dpi.
338 FontList mSystemFonts; ///< Cached system fonts.
339 FontList mDefaultFonts; ///< Cached default fonts.
341 std::vector<CacheItem> mFontCache; ///< Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'.
342 std::vector<FontDescriptionCacheItem> mValidatedFontCache; ///< Caches indices to the vector of font descriptions for a given 'font family name, font style'.
343 FontList mFontDescriptionCache; ///< Caches font descriptions for the validated font family name and font style pairs.
344 std::vector<FontIdCacheItem> mFontIdCache; ///< Caches font ids for the pairs of font point size and the index to the vector with font descriptions of the validated fonts.
347 } // namespace Internal
349 } // namespace TextAbstraction
353 #endif // __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__