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::GetDefaultFonts()
146 void GetDefaultFonts( FontList& defaultFonts );
149 * @copydoc Dali::FontClient::GetSystemFonts()
151 void GetSystemFonts( FontList& systemFonts );
154 * @copydoc Dali::FontClient::GetDescription()
156 void GetDescription( FontId id, FontDescription& fontDescription ) const;
159 * @copydoc Dali::FontClient::GetPointSize()
161 PointSize26Dot6 GetPointSize( FontId id );
164 * @copydoc Dali::FontClient::FindDefaultFont()
166 FontId FindDefaultFont( Character charcode, PointSize26Dot6 pointSize, bool preferColor );
169 * @see Dali::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex )
171 * @param[in] cacheDescription Whether to cache the font description.
173 FontId GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription = true );
176 * @copydoc Dali::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 pointSize, FaceIndex faceIndex )
178 FontId GetFontId( const FontDescription& fontDescription,
179 PointSize26Dot6 pointSize,
180 FaceIndex faceIndex );
183 * @copydoc Dali::FontClient::IsScalable( const FontPath& path )
185 bool IsScalable( const FontPath& path );
188 * @copydoc Dali::FontClient::IsScalable( const FontDescription& fontDescription )
190 bool IsScalable( const FontDescription& fontDescription );
193 * @copydoc Dali::FontClient::GetFixedSizes()
195 void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
198 * @copydoc Dali::FontClient::GetFixedSizes()
200 void GetFixedSizes( const FontDescription& fontDescription,
201 Dali::Vector< PointSize26Dot6 >& sizes );
204 * @copydoc Dali::FontClient::GetFontMetrics()
206 void GetFontMetrics( FontId fontId, FontMetrics& metrics, int maxFixedSize );
209 * @copydoc Dali::FontClient::GetGlyphIndex()
211 GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
214 * @copydoc Dali::FontClient::GetGlyphMetrics()
216 bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal, int maxFixedSize );
219 * @copydoc Dali::FontClient::CreateBitmap()
221 BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
224 * @copydoc Dali::FontClient::GetEllipsisGlyph()
226 const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 pointSize );
231 * Caches the fonts present in the platform.
233 * Calls GetFcFontSet() to retrieve the fonts.
235 void InitSystemFonts();
238 * @brief Creates a font family pattern used to match fonts.
240 * @param[in] fontDescription The font to cache.
242 * @return The pattern.
244 _FcPattern* CreateFontFamilyPattern( const FontDescription& fontDescription );
247 * Retrieves the fonts present in the platform.
249 * @return A font fonfig data structure with the platform's fonts.
251 _FcFontSet* GetFcFontSet() const;
254 * Retrieves a font config object's value from a pattern.
256 * @param[in] pattern The font config pattern.
257 * @param[in] n The object.
258 * @param[out] string The object's value.
260 * @return @e true if the operation is successful.
262 bool GetFcString( const _FcPattern* const pattern, const char* const n, std::string& string );
265 * Retrieves a font config object's value from a pattern.
267 * @param[in] pattern The font config pattern.
268 * @param[in] n The object.
269 * @param[out] intVal The object's value.
271 * @return @e true if the operation is successful.
273 bool GetFcInt( const _FcPattern* const pattern, const char* const n, int& intVal );
276 * @brief Creates a font.
278 * @param[in] path The path to the font file name.
279 * @param[in] pointSize The font point size.
280 * @param[in] faceIndex A face index.
281 * @param[in] cacheDescription Whether to cache the font description.
283 * @return The font id.
285 FontId CreateFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription );
288 * @brief Creates a fixed size font
290 * @param[in] path The path to the font file name.
291 * @param[in] pointSize The font point size( must be an available size ).
292 * @param[in] faceIndex A face index.
293 * @param[in] cacheDescription Whether to cache the font description.
295 * @return The font id.
297 FontId CreateFixedSizeFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription );
301 * @param[in] destBitmap
302 * @param[in] srcBitmap
304 void ConvertBitmap( BufferImage& destBitmap, FT_Bitmap srcBitmap );
307 * @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.
308 * If there is one , if writes the font id in the param @p fontId.
310 * @param[in] path Path to the font file name.
311 * @param[in] pointSize The font point size.
312 * @param[in] faceIndex The face index.
313 * @param[out] fontId The font id.
315 * @return @e true if there triplet is found.
317 bool FindFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, FontId& fontId ) const;
320 * @brief Finds in the cahce a cluster 'font family, font width, font weight, font slant'
321 * If there is one, it writes the index to the vector with font descriptions in the param @p validatedFontId.
323 * @param[in] fontDescription The font to validate.
324 * @param[out] validatedFontId The index to the vector with font descriptions.
326 * @return @e true if the pair is found.
328 bool FindValidatedFont( const FontDescription& fontDescription,
329 FontDescriptionId& validatedFontId );
332 * @brief Finds in the cache a pair 'validated font id and font point size'.
333 * If there is one it writes the font id in the param @p fontId.
335 * @param[in] validatedFontId Index to the vector with font descriptions.
336 * @param[in] pointSize The font point size.
337 * @param[out] fontId The font id.
339 * @return @e true if the pair is found.
341 bool FindFont( FontDescriptionId validatedFontId,
342 PointSize26Dot6 pointSize,
346 * @brief Validate a font description.
348 * @param[in] fontDescription The font to validate.
349 * @param[out] validatedFontId Result of validation
351 void ValidateFont( const FontDescription& fontDescription,
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.
364 FontList mFontDescriptionCache; ///< Caches font descriptions for the validated font.
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__