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/devel-api/text-abstraction/font-metrics.h>
23 #include <dali/devel-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 fonts.
47 typedef uint32_t FontDescriptionId;
50 * @brief FontClient implementation.
52 struct FontClient::Plugin
55 * @brief Caches an list of fallback fonts for a given font-description
57 struct FallbackCacheItem
59 FallbackCacheItem( const FontDescription& fontDescription, FontList* fallbackFonts );
61 FontDescription fontDescription; ///< The font description.
62 FontList* fallbackFonts; ///< The list of fallback fonts for the given font-description.
66 * @brief Caches an index to the vector of font descriptions for a given font.
68 struct FontDescriptionCacheItem
70 FontDescriptionCacheItem( const FontDescription& fontDescription,
71 FontDescriptionId index );
73 FontDescription fontDescription; ///< The font description.
74 FontDescriptionId index; ///< Index to the vector of font descriptions.
78 * @brief Caches the font id of the pair font point size and the index to the vector of font descriptions of validated fonts.
80 struct FontIdCacheItem
82 FontIdCacheItem( FontDescriptionId validatedFontId,
83 PointSize26Dot6 pointSize,
86 FontDescriptionId validatedFontId; ///< Index to the vector with font descriptions.
87 PointSize26Dot6 pointSize; ///< The font point size.
88 FontId fontId; ///< The font id.
92 * @brief Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'.
96 CacheItem( FT_Face ftFace,
98 PointSize26Dot6 pointSize,
100 const FontMetrics& metrics );
102 CacheItem( FT_Face ftFace,
103 const FontPath& path,
104 PointSize26Dot6 pointSize,
106 const FontMetrics& metrics,
110 FT_Face mFreeTypeFace; ///< The FreeType face.
111 FontPath mPath; ///< The path to the font file name.
112 PointSize26Dot6 mPointSize; ///< The font point size.
113 FaceIndex mFaceIndex; ///< The face index.
114 FontMetrics mMetrics; ///< The font metrics.
115 FT_Short mFixedWidthPixels; ///< The height in pixels (fixed size bitmaps only)
116 FT_Short mFixedHeightPixels; ///< The height in pixels (fixed size bitmaps only)
117 bool mIsFixedSizeBitmap; ///< Whether the font has fixed size bitmaps.
122 PointSize26Dot6 size;
129 * Initializes the FreeType library.
130 * Initializes the dpi values.
132 * @param[in] horizontalDpi The horizontal dpi.
133 * @param[in] verticalDpi The vertical dpi.
135 Plugin( unsigned int horizontalDpi, unsigned int verticalDpi );
138 * Default destructor.
140 * Frees any allocated resource.
145 * @copydoc Dali::FontClient::SetDpi()
147 void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
150 * @copydoc Dali::FontClient::SetDefaultFont()
152 void SetDefaultFont( const FontDescription& fontDescription );
155 * @copydoc Dali::FontClient::GetDefaultPlatformFontDescription()
157 void GetDefaultPlatformFontDescription( FontDescription& fontDescription );
160 * @copydoc Dali::FontClient::GetDefaultFonts()
162 void GetDefaultFonts( FontList& defaultFonts );
165 * @copydoc Dali::FontClient::GetSystemFonts()
167 void GetSystemFonts( FontList& systemFonts );
170 * @copydoc Dali::FontClient::GetDescription()
172 void GetDescription( FontId id, FontDescription& fontDescription ) const;
175 * @copydoc Dali::FontClient::GetPointSize()
177 PointSize26Dot6 GetPointSize( FontId id );
180 * @copydoc Dali::FontClient::FindFontForCharacter()
182 FontId FindFontForCharacter( const FontList& fontList,
184 PointSize26Dot6 requestedSize,
188 * @copydoc Dali::FontClient::FindDefaultFont()
190 FontId FindDefaultFont( Character charcode, PointSize26Dot6 pointSize, bool preferColor );
193 * @copydoc Dali::FontClient::FindFallbackFont()
195 FontId FindFallbackFont( FontId preferredFont, Character charcode, PointSize26Dot6 requestedSize, bool preferColor );
198 * @see Dali::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex )
200 * @param[in] cacheDescription Whether to cache the font description.
202 FontId GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription = true );
205 * @copydoc Dali::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 pointSize, FaceIndex faceIndex )
207 FontId GetFontId( const FontDescription& fontDescription,
208 PointSize26Dot6 pointSize,
209 FaceIndex faceIndex );
212 * @copydoc Dali::FontClient::IsScalable( const FontPath& path )
214 bool IsScalable( const FontPath& path );
217 * @copydoc Dali::FontClient::IsScalable( const FontDescription& fontDescription )
219 bool IsScalable( const FontDescription& fontDescription );
222 * @copydoc Dali::FontClient::GetFixedSizes()
224 void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
227 * @copydoc Dali::FontClient::GetFixedSizes()
229 void GetFixedSizes( const FontDescription& fontDescription,
230 Dali::Vector< PointSize26Dot6 >& sizes );
233 * @copydoc Dali::FontClient::GetFontMetrics()
235 void GetFontMetrics( FontId fontId, FontMetrics& metrics, int maxFixedSize );
238 * @copydoc Dali::FontClient::GetGlyphIndex()
240 GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
243 * @copydoc Dali::FontClient::GetGlyphMetrics()
245 bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal, int maxFixedSize );
248 * @copydoc Dali::FontClient::CreateBitmap()
250 BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
253 * @copydoc Dali::FontClient::GetEllipsisGlyph()
255 const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 pointSize );
260 * Caches the fonts present in the platform.
262 * Calls GetFcFontSet() to retrieve the fonts.
264 void InitSystemFonts();
267 * Gets the FontDescription which matches the given pattern
268 * @param[in] pattern pattern to match against
269 * @param[out] fontDescription the resultant fontDescription that matched
270 * @return true if match found
272 bool MatchFontDescriptionToPattern( _FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription );
275 * @brief Creates a font family pattern used to match fonts.
277 * @param[in] fontDescription The font to cache.
279 * @return The pattern.
281 _FcPattern* CreateFontFamilyPattern( const FontDescription& fontDescription );
284 * Retrieves the fonts present in the platform.
286 * @return A font fonfig data structure with the platform's fonts.
288 _FcFontSet* GetFcFontSet() const;
291 * Retrieves a font config object's value from a pattern.
293 * @param[in] pattern The font config pattern.
294 * @param[in] n The object.
295 * @param[out] string The object's value.
297 * @return @e true if the operation is successful.
299 bool GetFcString( const _FcPattern* const pattern, const char* const n, std::string& string );
302 * Retrieves a font config object's value from a pattern.
304 * @param[in] pattern The font config pattern.
305 * @param[in] n The object.
306 * @param[out] intVal The object's value.
308 * @return @e true if the operation is successful.
310 bool GetFcInt( const _FcPattern* const pattern, const char* const n, int& intVal );
313 * @brief Creates a font.
315 * @param[in] path The path to the font file name.
316 * @param[in] pointSize The font point size.
317 * @param[in] faceIndex A face index.
318 * @param[in] cacheDescription Whether to cache the font description.
320 * @return The font id.
322 FontId CreateFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription );
325 * @brief Creates a fixed size font
327 * @param[in] path The path to the font file name.
328 * @param[in] pointSize The font point size( must be an available size ).
329 * @param[in] faceIndex A face index.
330 * @param[in] cacheDescription Whether to cache the font description.
332 * @return The font id.
334 FontId CreateFixedSizeFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription );
338 * @param[in] destBitmap
339 * @param[in] srcBitmap
341 void ConvertBitmap( BufferImage& destBitmap, FT_Bitmap srcBitmap );
344 * @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.
345 * If there is one , if writes the font id in the param @p fontId.
347 * @param[in] path Path to the font file name.
348 * @param[in] pointSize The font point size.
349 * @param[in] faceIndex The face index.
350 * @param[out] fontId The font id.
352 * @return @e true if there triplet is found.
354 bool FindFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, FontId& fontId ) const;
357 * @brief Finds in the cache a cluster 'font family, font width, font weight, font slant'
358 * If there is one, it writes the index to the vector with font descriptions in the param @p validatedFontId.
360 * @param[in] fontDescription The font to validate.
361 * @param[out] validatedFontId The index to the vector with font descriptions.
363 * @return @e true if the pair is found.
365 bool FindValidatedFont( const FontDescription& fontDescription,
366 FontDescriptionId& validatedFontId );
369 * @brief Finds a fallback font list from the cache for a given font-description
371 * @param[in] fontDescription The font to validate.
372 * @param[out] A valid pointer to a font list, or NULL if not found.
374 bool FindFallbackFontList( const FontDescription& fontDescription,
375 FontList*& fontList );
378 * @brief Finds in the cache a pair 'validated font id and font point size'.
379 * If there is one it writes the font id in the param @p fontId.
381 * @param[in] validatedFontId Index to the vector with font descriptions.
382 * @param[in] pointSize The font point size.
383 * @param[out] fontId The font id.
385 * @return @e true if the pair is found.
387 bool FindFont( FontDescriptionId validatedFontId,
388 PointSize26Dot6 pointSize,
392 * @brief Validate a font description.
394 * @param[in] fontDescription The font to validate.
395 * @param[out] validatedFontId Result of validation
397 void ValidateFont( const FontDescription& fontDescription,
398 FontDescriptionId& validatedFontId );
401 * Helper for SetDefaultFont etc.
403 * @param[in] fontDescription A font description.
404 * @param[out] fontList A list of the fonts which are a close match for fontDescription.
406 void SetFontList( const FontDescription& fontDescription, FontList& fontList );
408 FT_Library mFreeTypeLibrary; ///< A handle to a FreeType library instance.
410 unsigned int mDpiHorizontal; ///< Horizontal dpi.
411 unsigned int mDpiVertical; ///< Vertical dpi.
413 FontList mSystemFonts; ///< Cached system fonts.
414 FontList mDefaultFonts; ///< Cached default fonts.
416 std::vector<FallbackCacheItem> mFallbackCache; ///< Cached fallback font lists.
418 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'.
419 std::vector<FontDescriptionCacheItem> mValidatedFontCache; ///< Caches indices to the vector of font descriptions for a given font.
420 FontList mFontDescriptionCache; ///< Caches font descriptions for the validated font.
421 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.
423 Vector<EllipsisItem> mEllipsisCache; ///< Caches ellipsis glyphs for a particular point size.
426 } // namespace Internal
428 } // namespace TextAbstraction
432 #endif // __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__