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 index to the vector of font descriptions for a given font.
57 struct FontDescriptionCacheItem
59 FontDescriptionCacheItem( const FontDescription& fontDescription,
60 FontDescriptionId index );
62 FontDescription fontDescription; ///< The font description.
63 FontDescriptionId index; ///< Index to the vector of font descriptions.
67 * @brief Caches the font id of the pair font point size and the index to the vector of font descriptions of validated fonts.
69 struct FontIdCacheItem
71 FontIdCacheItem( FontDescriptionId validatedFontId,
72 PointSize26Dot6 pointSize,
75 FontDescriptionId validatedFontId; ///< Index to the vector with font descriptions.
76 PointSize26Dot6 pointSize; ///< The font point size.
77 FontId fontId; ///< The font id.
81 * @brief Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'.
85 CacheItem( FT_Face ftFace,
87 PointSize26Dot6 pointSize,
89 const FontMetrics& metrics );
91 CacheItem( FT_Face ftFace,
93 PointSize26Dot6 pointSize,
95 const FontMetrics& metrics,
99 FT_Face mFreeTypeFace; ///< The FreeType face.
100 FontPath mPath; ///< The path to the font file name.
101 PointSize26Dot6 mPointSize; ///< The font point size.
102 FaceIndex mFaceIndex; ///< The face index.
103 FontMetrics mMetrics; ///< The font metrics.
104 FT_Short mFixedWidthPixels; ///< The height in pixels (fixed size bitmaps only)
105 FT_Short mFixedHeightPixels; ///< The height in pixels (fixed size bitmaps only)
106 bool mIsFixedSizeBitmap; ///< Whether the font has fixed size bitmaps.
111 PointSize26Dot6 size;
118 * Initializes the FreeType library.
119 * Initializes the dpi values.
121 * @param[in] horizontalDpi The horizontal dpi.
122 * @param[in] verticalDpi The vertical dpi.
124 Plugin( unsigned int horizontalDpi, unsigned int verticalDpi );
127 * Default destructor.
129 * Frees any allocated resource.
134 * @copydoc Dali::FontClient::SetDpi()
136 void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
139 * @copydoc Dali::FontClient::SetDefaultFont()
141 void SetDefaultFont( const FontDescription& fontDescription );
144 * @copydoc Dali::FontClient::GetDefaultPlatformFontDescription()
146 void GetDefaultPlatformFontDescription( FontDescription& fontDescription );
149 * @copydoc Dali::FontClient::GetDefaultFonts()
151 void GetDefaultFonts( FontList& defaultFonts );
154 * @copydoc Dali::FontClient::GetSystemFonts()
156 void GetSystemFonts( FontList& systemFonts );
159 * @copydoc Dali::FontClient::GetDescription()
161 void GetDescription( FontId id, FontDescription& fontDescription ) const;
164 * @copydoc Dali::FontClient::GetPointSize()
166 PointSize26Dot6 GetPointSize( FontId id );
169 * @copydoc Dali::FontClient::FindDefaultFont()
171 FontId FindDefaultFont( Character charcode, PointSize26Dot6 pointSize, bool preferColor );
174 * @see Dali::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex )
176 * @param[in] cacheDescription Whether to cache the font description.
178 FontId GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription = true );
181 * @copydoc Dali::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 pointSize, FaceIndex faceIndex )
183 FontId GetFontId( const FontDescription& fontDescription,
184 PointSize26Dot6 pointSize,
185 FaceIndex faceIndex );
188 * @copydoc Dali::FontClient::IsScalable( const FontPath& path )
190 bool IsScalable( const FontPath& path );
193 * @copydoc Dali::FontClient::IsScalable( const FontDescription& fontDescription )
195 bool IsScalable( const FontDescription& fontDescription );
198 * @copydoc Dali::FontClient::GetFixedSizes()
200 void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
203 * @copydoc Dali::FontClient::GetFixedSizes()
205 void GetFixedSizes( const FontDescription& fontDescription,
206 Dali::Vector< PointSize26Dot6 >& sizes );
209 * @copydoc Dali::FontClient::GetFontMetrics()
211 void GetFontMetrics( FontId fontId, FontMetrics& metrics, int maxFixedSize );
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, int maxFixedSize );
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] fontDescription The font to cache.
247 * @return The pattern.
249 _FcPattern* CreateFontFamilyPattern( const FontDescription& fontDescription );
252 * Retrieves the fonts present in the platform.
254 * @return A font fonfig data structure with the platform's fonts.
256 _FcFontSet* GetFcFontSet() const;
259 * Retrieves a font config object's value from a pattern.
261 * @param[in] pattern The font config pattern.
262 * @param[in] n The object.
263 * @param[out] string The object's value.
265 * @return @e true if the operation is successful.
267 bool GetFcString( const _FcPattern* const pattern, const char* const n, std::string& string );
270 * Retrieves a font config object's value from a pattern.
272 * @param[in] pattern The font config pattern.
273 * @param[in] n The object.
274 * @param[out] intVal The object's value.
276 * @return @e true if the operation is successful.
278 bool GetFcInt( const _FcPattern* const pattern, const char* const n, int& intVal );
281 * @brief Creates a font.
283 * @param[in] path The path to the font file name.
284 * @param[in] pointSize The font point size.
285 * @param[in] faceIndex A face index.
286 * @param[in] cacheDescription Whether to cache the font description.
288 * @return The font id.
290 FontId CreateFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription );
293 * @brief Creates a fixed size font
295 * @param[in] path The path to the font file name.
296 * @param[in] pointSize The font point size( must be an available size ).
297 * @param[in] faceIndex A face index.
298 * @param[in] cacheDescription Whether to cache the font description.
300 * @return The font id.
302 FontId CreateFixedSizeFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription );
306 * @param[in] destBitmap
307 * @param[in] srcBitmap
309 void ConvertBitmap( BufferImage& destBitmap, FT_Bitmap srcBitmap );
312 * @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.
313 * If there is one , if writes the font id in the param @p fontId.
315 * @param[in] path Path to the font file name.
316 * @param[in] pointSize The font point size.
317 * @param[in] faceIndex The face index.
318 * @param[out] fontId The font id.
320 * @return @e true if there triplet is found.
322 bool FindFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, FontId& fontId ) const;
325 * @brief Finds in the cahce a cluster 'font family, font width, font weight, font slant'
326 * If there is one, it writes the index to the vector with font descriptions in the param @p validatedFontId.
328 * @param[in] fontDescription The font to validate.
329 * @param[out] validatedFontId The index to the vector with font descriptions.
331 * @return @e true if the pair is found.
333 bool FindValidatedFont( const FontDescription& fontDescription,
334 FontDescriptionId& validatedFontId );
337 * @brief Finds in the cache a pair 'validated font id and font point size'.
338 * If there is one it writes the font id in the param @p fontId.
340 * @param[in] validatedFontId Index to the vector with font descriptions.
341 * @param[in] pointSize The font point size.
342 * @param[out] fontId The font id.
344 * @return @e true if the pair is found.
346 bool FindFont( FontDescriptionId validatedFontId,
347 PointSize26Dot6 pointSize,
351 * @brief Validate a font description.
353 * @param[in] fontDescription The font to validate.
354 * @param[out] validatedFontId Result of validation
356 void ValidateFont( const FontDescription& fontDescription,
357 FontDescriptionId& validatedFontId );
359 FT_Library mFreeTypeLibrary; ///< A handle to a FreeType library instance.
361 unsigned int mDpiHorizontal; ///< Horizontal dpi.
362 unsigned int mDpiVertical; ///< Vertical dpi.
364 FontList mSystemFonts; ///< Cached system fonts.
365 FontList mDefaultFonts; ///< Cached default fonts.
367 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'.
368 std::vector<FontDescriptionCacheItem> mValidatedFontCache; ///< Caches indices to the vector of font descriptions for a given font.
369 FontList mFontDescriptionCache; ///< Caches font descriptions for the validated font.
370 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.
372 Vector<EllipsisItem> mEllipsisCache; ///< Caches ellipsis glyphs for a particular point size.
375 } // namespace Internal
377 } // namespace TextAbstraction
381 #endif // __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__