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/public-api/text-abstraction/glyph-info.h>
24 #include <dali/internal/text-abstraction/font-client-impl.h>
28 #include FT_FREETYPE_H
31 // forward declarations of font config types.
38 namespace TextAbstraction
45 *@brief Type used for indices addressing the vector with front descriptions of validated pairs 'font family name, font style'.
47 typedef uint32_t FontDescriptionId;
50 * @brief FontClient implementation.
52 struct FontClient::Plugin
55 * @brief Caches an index to the vector of font descriptions for a given 'font family name, font style'.
57 struct FontDescriptionCacheItem
59 FontDescriptionCacheItem( const FontFamily& fontFamily,
60 const FontStyle& fontStyle,
61 FontDescriptionId index );
63 FontFamily fontFamily; ///< The font family name.
64 FontStyle fontStyle; ///< The font style.
65 FontDescriptionId index; ///< Index to the vector of font descriptions.
69 * @brief Caches the font id of the pair font point size and the index to the vector of font descriptions of validated fonts.
71 struct FontIdCacheItem
73 FontIdCacheItem( FontDescriptionId validatedFontId,
74 PointSize26Dot6 pointSize,
77 FontDescriptionId validatedFontId; ///< Index to the vector with font descriptions.
78 PointSize26Dot6 pointSize; ///< The font point size.
79 FontId fontId; ///< The font id.
83 * @brief Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'.
87 CacheItem( FT_Face ftFace,
89 PointSize26Dot6 pointSize,
91 const FontMetrics& metrics );
93 CacheItem( FT_Face ftFace,
95 PointSize26Dot6 pointSize,
97 const FontMetrics& metrics,
101 FT_Face mFreeTypeFace; ///< The FreeType face.
102 FontPath mPath; ///< The path to the font file name.
103 PointSize26Dot6 mPointSize; ///< The font point size.
104 FaceIndex mFaceIndex; ///< The face index.
105 FontMetrics mMetrics; ///< The font metrics.
106 FT_Short mFixedWidthPixels; ///< The height in pixels (fixed size bitmaps only)
107 FT_Short mFixedHeightPixels; ///< The height in pixels (fixed size bitmaps only)
108 bool mIsFixedSizeBitmap; ///< Whether the font has fixed size bitmaps.
113 PointSize26Dot6 size;
120 * Initializes the FreeType library.
121 * Initializes the dpi values.
123 * @param[in] horizontalDpi The horizontal dpi.
124 * @param[in] verticalDpi The vertical dpi.
126 Plugin( unsigned int horizontalDpi, unsigned int verticalDpi );
129 * Default destructor.
131 * Frees any allocated resource.
136 * @copydoc Dali::FontClient::SetDpi()
138 void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
141 * @copydoc Dali::FontClient::SetDefaultFontFamily()
143 void SetDefaultFontFamily( const FontFamily& fontFamilyName,
144 const FontStyle& fontStyle );
147 * @copydoc Dali::FontClient::GetDefaultFonts()
149 void GetDefaultFonts( FontList& defaultFonts );
152 * @copydoc Dali::FontClient::GetSystemFonts()
154 void GetSystemFonts( FontList& systemFonts );
157 * @copydoc Dali::FontClient::GetDescription()
159 void GetDescription( FontId id, FontDescription& fontDescription ) const;
162 * @copydoc Dali::FontClient::GetPointSize()
164 PointSize26Dot6 GetPointSize( FontId id );
167 * @copydoc Dali::FontClient::FindDefaultFont()
169 FontId FindDefaultFont( Character charcode, PointSize26Dot6 pointSize, bool preferColor );
172 * @see Dali::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex )
174 * @param[in] cacheDescription Whether to cache the font description.
176 FontId GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription = true );
179 * @copydoc Dali::FontClient::GetFontId(const FontFamily& fontFamily, const FontStyle& fontStyle, PointSize26Dot6 pointSize, FaceIndex faceIndex )
181 FontId GetFontId( const FontFamily& fontFamily,
182 const FontStyle& fontStyle,
183 PointSize26Dot6 pointSize,
184 FaceIndex faceIndex );
187 * @copydoc Dali::FontClient::IsScalable(const FontPath& path )
189 bool IsScalable( const FontPath& path );
192 * @copydoc Dali::FontClient::IsScalable( const FontFamily& fontFamily, const FontStyle& fontStyle )
194 bool IsScalable( const FontFamily& fontFamily, const FontStyle& fontStyle );
197 * @copydoc Dali::FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
199 void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
202 * @copydoc Dali::FontClient::GetFixedSizes( const FontFamily& fontFamily, const FontStyle& fontStyle, Dali::Vector< PointSize26Dot6>& sizes )
204 void GetFixedSizes( const FontFamily& fontFamily,
205 const FontStyle& fontStyle,
206 Dali::Vector< PointSize26Dot6 >& sizes );
209 * @copydoc Dali::FontClient::GetFontMetrics()
211 void GetFontMetrics( FontId fontId, FontMetrics& metrics );
214 * @copydoc Dali::FontClient::GetGlyphIndex()
216 GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
219 * @copydoc Dali::FontClient::GetGlyphMetrics()
221 bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal );
224 * @copydoc Dali::FontClient::CreateBitmap()
226 BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
229 * @copydoc Dali::FontClient::GetEllipsisGlyph()
231 const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 pointSize );
236 * Caches the fonts present in the platform.
238 * Calls GetFcFontSet() to retrieve the fonts.
240 void InitSystemFonts();
243 * @brief Creates a font family pattern used to match fonts.
245 * @param[in] fontFamily The font family name.
246 * @param[in] fontStyle The font style.
248 * @return The pattern.
250 _FcPattern* CreateFontFamilyPattern( const FontFamily& fontFamily,
251 const FontStyle& fontStyle );
254 * Retrieves the fonts present in the platform.
256 * @return A font fonfig data structure with the platform's fonts.
258 _FcFontSet* GetFcFontSet() const;
261 * Retrieves a font config object's value from a pattern.
263 * @param[in] pattern The font config pattern.
264 * @param[in] n The object.
265 * @param[out] string The object's value.
267 * @return @e true if the operation is successful.
269 bool GetFcString( const _FcPattern* const pattern, const char* const n, std::string& string );
272 * @brief Creates a font.
274 * @param[in] path The path to the font file name.
275 * @param[in] pointSize The font point 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 CreateFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription );
284 * @brief Creates a fixed size font
286 * @param[in] path The path to the font file name.
287 * @param[in] pointSize The font point size( must be an available size ).
288 * @param[in] faceIndex A face index.
289 * @param[in] cacheDescription Whether to cache the font description.
291 * @return The font id.
293 FontId CreateFixedSizeFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription );
297 * @param[in] destBitmap
298 * @param[in] srcBitmap
300 void ConvertBitmap( BufferImage& destBitmap, FT_Bitmap srcBitmap );
303 * @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.
304 * If there is one , if writes the font id in the param @p fontId.
306 * @param[in] path Path to the font file name.
307 * @param[in] pointSize The font point size.
308 * @param[in] faceIndex The face index.
309 * @param[out] fontId The font id.
311 * @return @e true if there triplet is found.
313 bool FindFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, FontId& fontId ) const;
316 * @brief Finds in the cahce a pair 'font family, font style'.
317 * If there is one, it writes the index to the vector with font descriptions in the param @p validatedFontId.
319 * @param[in] fontFamily The font family name.
320 * @param[in] fontStyle The font style.
321 * @param[out] validatedFontId The index to the vector with font descriptions.
323 * @return @e true if the pair is found.
325 bool FindValidatedFont( const FontFamily& fontFamily,
326 const FontStyle& fontStyle,
327 FontDescriptionId& validatedFontId );
330 * @brief Finds in the cache a pair 'validated font id and font point size'.
331 * If there is one it writes the font id in the param @p fontId.
333 * @param[in] validatedFontId Index to the vector with font descriptions.
334 * @param[in] pointSize The font point size.
335 * @param[out] fontId The font id.
337 * @return @e true if the pair is found.
339 bool FindFont( FontDescriptionId validatedFontId,
340 PointSize26Dot6 pointSize,
344 * @brief Validate a font family and style
346 * @param[in] fontFamily Font Family to validate
347 * @param[in] fontStyle Font Style to validate
348 * @param[out] validatedFontId Result of validation
350 void ValidateFont( const FontFamily& fontFamily,
351 const FontStyle& fontStyle,
352 FontDescriptionId& validatedFontId );
354 FT_Library mFreeTypeLibrary; ///< A handle to a FreeType library instance.
356 unsigned int mDpiHorizontal; ///< Horizontal dpi.
357 unsigned int mDpiVertical; ///< Vertical dpi.
359 FontList mSystemFonts; ///< Cached system fonts.
360 FontList mDefaultFonts; ///< Cached default fonts.
362 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'.
363 std::vector<FontDescriptionCacheItem> mValidatedFontCache; ///< Caches indices to the vector of font descriptions for a given 'font family name, font style'.
364 FontList mFontDescriptionCache; ///< Caches font descriptions for the validated font family name and font style pairs.
365 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.
367 Vector<EllipsisItem> mEllipsisCache; ///< Caches ellipsis glyphs for a particular point size.
370 } // namespace Internal
372 } // namespace TextAbstraction
376 #endif // __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__