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 );
92 CacheItem( FT_Face ftFace,
94 PointSize26Dot6 pointSize,
96 const FontMetrics& metrics,
100 FT_Face mFreeTypeFace; ///< The FreeType face.
101 FontPath mPath; ///< The path to the font file name.
102 PointSize26Dot6 mPointSize; ///< The font point size.
103 FaceIndex mFaceIndex; ///< The face index.
104 FontMetrics mMetrics; ///< The font metrics.
105 FT_Short mFixedWidthPixels; ///< The height in pixels (fixed size bitmaps only)
106 FT_Short mFixedHeightPixels; ///< The height in pixels (fixed size bitmaps only)
107 bool mIsFixedSizeBitmap; ///< Whether the font has fixed size bitmaps.
113 * Initializes the FreeType library.
114 * Initializes the dpi values.
116 * @param[in] horizontalDpi The horizontal dpi.
117 * @param[in] verticalDpi The vertical dpi.
119 Plugin( unsigned int horizontalDpi, unsigned int verticalDpi );
122 * Default destructor.
124 * Frees any allocated resource.
129 * @copydoc Dali::FontClient::SetDpi()
131 void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
134 * @copydoc Dali::FontClient::SetDefaultFontFamily()
136 void SetDefaultFontFamily( const FontFamily& fontFamilyName,
137 const FontStyle& fontStyle );
140 * @copydoc Dali::FontClient::GetDefaultFonts()
142 void GetDefaultFonts( FontList& defaultFonts );
145 * @copydoc Dali::FontClient::GetSystemFonts()
147 void GetSystemFonts( FontList& systemFonts );
150 * @copydoc Dali::FontClient::GetDescription()
152 void GetDescription( FontId id, FontDescription& fontDescription ) const;
155 * @copydoc Dali::FontClient::GetPointSize()
157 PointSize26Dot6 GetPointSize( FontId id );
160 * @copydoc Dali::FontClient::FindDefaultFont()
162 FontId FindDefaultFont( Character charcode, PointSize26Dot6 pointSize );
165 * @see Dali::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex )
167 * @param[in] cacheDescription Whether to cache the font description.
169 FontId GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription = true );
172 * @copydoc Dali::FontClient::GetFontId(const FontFamily& fontFamily, const FontStyle& fontStyle, PointSize26Dot6 pointSize, FaceIndex faceIndex )
174 FontId GetFontId( const FontFamily& fontFamily,
175 const FontStyle& fontStyle,
176 PointSize26Dot6 pointSize,
177 FaceIndex faceIndex );
180 * @copydoc Dali::FontClient::IsScalable(const FontPath& path )
182 bool IsScalable( const FontPath& path );
185 * @copydoc Dali::FontClient::IsScalable( const FontFamily& fontFamily, const FontStyle& fontStyle )
187 bool IsScalable( const FontFamily& fontFamily, const FontStyle& fontStyle );
190 * @copydoc Dali::FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
192 void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
195 * @copydoc Dali::FontClient::GetFixedSizes( const FontFamily& fontFamily, const FontStyle& fontStyle, Dali::Vector< PointSize26Dot6>& sizes )
197 void GetFixedSizes( const FontFamily& fontFamily,
198 const FontStyle& fontStyle,
199 Dali::Vector< PointSize26Dot6 >& sizes );
202 * @copydoc Dali::FontClient::GetFontMetrics()
204 void GetFontMetrics( FontId fontId, FontMetrics& metrics );
207 * @copydoc Dali::FontClient::GetGlyphIndex()
209 GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
212 * @copydoc Dali::FontClient::CreateMetrics()
214 bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal );
217 * @copydoc Dali::FontClient::CreateBitmap()
219 BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
224 * Caches the fonts present in the platform.
226 * Calls GetFcFontSet() to retrieve the fonts.
228 void InitSystemFonts();
231 * @brief Creates a font family pattern used to match fonts.
233 * @param[in] fontFamily The font family name.
234 * @param[in] fontStyle The font style.
236 * @return The pattern.
238 _FcPattern* CreateFontFamilyPattern( const FontFamily& fontFamily,
239 const FontStyle& fontStyle );
242 * Retrieves the fonts present in the platform.
244 * @return A font fonfig data structure with the platform's fonts.
246 _FcFontSet* GetFcFontSet() const;
249 * Retrieves a font config object's value from a pattern.
251 * @param[in] pattern The font config pattern.
252 * @param[in] n The object.
253 * @param[out] string The object's value.
255 * @return @e true if the operation is successful.
257 bool GetFcString( const _FcPattern* const pattern, const char* const n, std::string& string );
260 * @brief Creates a font.
262 * @param[in] path The path to the font file name.
263 * @param[in] pointSize The font point size.
264 * @param[in] faceIndex A face index.
265 * @param[in] cacheDescription Whether to cache the font description.
267 * @return The font id.
269 FontId CreateFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription );
272 * @brief Creates a fixed size font
274 * @param[in] path The path to the font file name.
275 * @param[in] pointSize The font point size( must be an available size ).
276 * @param[in] faceIndex A face index.
277 * @param[in] cacheDescription Whether to cache the font description.
279 * @return The font id.
281 FontId CreateFixedSizeFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription );
285 * @param[in] destBitmap
286 * @param[in] srcBitmap
288 void ConvertBitmap( BufferImage& destBitmap, FT_Bitmap srcBitmap );
291 * @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.
292 * If there is one , if writes the font id in the param @p fontId.
294 * @param[in] path Path to the font file name.
295 * @param[in] pointSize The font point size.
296 * @param[in] faceIndex The face index.
297 * @param[out] fontId The font id.
299 * @return @e true if there triplet is found.
301 bool FindFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, FontId& fontId ) const;
304 * @brief Finds in the cahce a pair 'font family, font style'.
305 * If there is one, it writes the index to the vector with font descriptions in the param @p validatedFontId.
307 * @param[in] fontFamily The font family name.
308 * @param[in] fontStyle The font style.
309 * @param[out] validatedFontId The index to the vector with font descriptions.
311 * @return @e true if the pair is found.
313 bool FindValidatedFont( const FontFamily& fontFamily,
314 const FontStyle& fontStyle,
315 FontDescriptionId& validatedFontId );
318 * @brief Finds in the cache a pair 'validated font id and font point size'.
319 * If there is one it writes the font id in the param @p fontId.
321 * @param[in] validatedFontId Index to the vector with font descriptions.
322 * @param[in] pointSize The font point size.
323 * @param[out] fontId The font id.
325 * @return @e true if the pair is found.
327 bool FindFont( FontDescriptionId validatedFontId,
328 PointSize26Dot6 pointSize,
332 * @brief Validate a font family and style
334 * @param[in] fontFamily Font Family to validate
335 * @param[in] fontStyle Font Style to validate
336 * @param[out] validatedFontId Result of validation
338 void ValidateFont( const FontFamily& fontFamily,
339 const FontStyle& fontStyle,
340 FontDescriptionId& validatedFontId );
342 FT_Library mFreeTypeLibrary; ///< A handle to a FreeType library instance.
344 unsigned int mDpiHorizontal; ///< Horizontal dpi.
345 unsigned int mDpiVertical; ///< Vertical dpi.
347 FontList mSystemFonts; ///< Cached system fonts.
348 FontList mDefaultFonts; ///< Cached default fonts.
350 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'.
351 std::vector<FontDescriptionCacheItem> mValidatedFontCache; ///< Caches indices to the vector of font descriptions for a given 'font family name, font style'.
352 FontList mFontDescriptionCache; ///< Caches font descriptions for the validated font family name and font style pairs.
353 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.
356 } // namespace Internal
358 } // namespace TextAbstraction
362 #endif // __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__