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 FT_Face mFreeTypeFace; ///< The FreeType fance.
93 FontPath mPath; ///< The path to the font file name.
94 PointSize26Dot6 mPointSize; ///< The font point size.
95 FaceIndex mFaceIndex; ///< The face index.
96 FontMetrics mMetrics; ///< The font metrics.
102 * Initializes the FreeType library.
103 * Initializes the dpi values.
105 * @param[in] horizontalDpi The horizontal dpi.
106 * @param[in] verticalDpi The vertical dpi.
108 Plugin( unsigned int horizontalDpi, unsigned int verticalDpi );
111 * Default destructor.
113 * Frees any allocated resource.
118 * @copydoc Dali::FontClient::SetDpi()
120 void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
123 * @copydoc Dali::FontClient::SetDefaultFontFamily()
125 void SetDefaultFontFamily( const FontFamily& fontFamilyName,
126 const FontStyle& fontStyle );
129 * @copydoc Dali::FontClient::GetDefaultFonts()
131 void GetDefaultFonts( FontList& defaultFonts );
134 * @copydoc Dali::FontClient::GetSystemFonts()
136 void GetSystemFonts( FontList& systemFonts );
139 * @copydoc Dali::FontClient::GetDescription()
141 void GetDescription( FontId id, FontDescription& fontDescription ) const;
144 * @copydoc Dali::FontClient::GetPointSize()
146 PointSize26Dot6 GetPointSize( FontId id );
149 * @copydoc Dali::FontClient::FindDefaultFont()
151 FontId FindDefaultFont( Character charcode, PointSize26Dot6 pointSize );
154 * @see Dali::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex )
156 * @param[in] cacheDescription Whether to cache the font description.
158 FontId GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription = true );
161 * @copydoc Dali::FontClient::GetFontId(const FontFamily& fontFamily, const FontStyle& fontStyle, PointSize26Dot6 pointSize, FaceIndex faceIndex )
163 FontId GetFontId( const FontFamily& fontFamily,
164 const FontStyle& fontStyle,
165 PointSize26Dot6 pointSize,
166 FaceIndex faceIndex );
169 * @copydoc Dali::FontClient::GetFontMetrics()
171 void GetFontMetrics( FontId fontId, FontMetrics& metrics );
174 * @copydoc Dali::FontClient::GetGlyphIndex()
176 GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
179 * @copydoc Dali::FontClient::CreateMetrics()
181 bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal );
184 * @copydoc Dali::FontClient::CreateBitmap()
186 BitmapImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
191 * Caches the fonts present in the platform.
193 * Calls GetFcFontSet() to retrieve the fonts.
195 void InitSystemFonts();
198 * @brief Creates a font family pattern used to match fonts.
200 * @param[in] fontFamily The font family name.
201 * @param[in] fontStyle The font style.
203 * @return The pattern.
205 _FcPattern* CreateFontFamilyPattern( const FontFamily& fontFamily,
206 const FontStyle& fontStyle );
209 * Retrieves the fonts present in the platform.
211 * @return A font fonfig data structure with the platform's fonts.
213 _FcFontSet* GetFcFontSet() const;
216 * Retrieves a font config object's value from a pattern.
218 * @param[in] pattern The font config pattern.
219 * @param[in] n The object.
220 * @param[out] string The object's value.
222 * @return @e true if the operation is successful.
224 bool GetFcString( const _FcPattern* const pattern, const char* const n, std::string& string );
227 * @brief Creates a font.
229 * @param[in] path The path to the font file name.
230 * @param[in] pointSize The font point size.
231 * @param[in] faceIndex A face index.
232 * @param[in] cacheDescription Whether to cache the font description.
234 * @return The font id.
236 FontId CreateFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription );
240 * @param[in] destBitmap
241 * @param[in] srcBitmap
243 void ConvertBitmap( BitmapImage& destBitmap, FT_Bitmap srcBitmap );
246 * @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.
247 * If there is one , if writes the font id in the param @p fontId.
249 * @param[in] path Path to the font file name.
250 * @param[in] pointSize The font point size.
251 * @param[in] faceIndex The face index.
252 * @param[out] fontId The font id.
254 * @return @e true if there triplet is found.
256 bool FindFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, FontId& fontId ) const;
259 * @brief Finds in the cahce a pair 'font family, font style'.
260 * If there is one, it writes the index to the vector with font descriptions in the param @p validatedFontId.
262 * @param[in] fontFamily The font family name.
263 * @param[in] fontStyle The font style.
264 * @param[out] validatedFontId The index to the vector with font descriptions.
266 * @return @e true if the pair is found.
268 bool FindValidatedFont( const FontFamily& fontFamily,
269 const FontStyle& fontStyle,
270 FontDescriptionId& validatedFontId );
273 * @brief Finds in the cache a pair 'validated font id and font point size'.
274 * If there is one it writes the font id in the param @p fontId.
276 * @param[in] validatedFontId Index to the vector with font descriptions.
277 * @param[in] pointSize The font point size.
278 * @param[out] fontId The font id.
280 * @return @e true if the pair is found.
282 bool FindFont( FontDescriptionId validatedFontId,
283 PointSize26Dot6 pointSize,
286 FT_Library mFreeTypeLibrary; ///< A handle to a FreeType library instance.
288 unsigned int mDpiHorizontal; ///< Horizontal dpi.
289 unsigned int mDpiVertical; ///< Vertical dpi.
291 FontList mSystemFonts; ///< Cached system fonts.
292 FontList mDefaultFonts; ///< Cached default fonts.
294 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'.
295 std::vector<FontDescriptionCacheItem> mValidatedFontCache; ///< Caches indices to the vector of font descriptions for a given 'font family name, font style'.
296 FontList mFontDescriptionCache; ///< Caches font descriptions for the validated font family name and font style pairs.
297 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.
300 } // namespace Internal
302 } // namespace TextAbstraction
306 #endif // __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__