acd4be17d8cad844b32cfd4b8095b018dfc5b085
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / font-client-plugin-impl.h
1 #ifndef DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H
2 #define DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
23 #include <dali/devel-api/text-abstraction/bitmap-font.h>
24 #include <dali/devel-api/text-abstraction/font-metrics.h>
25 #include <dali/devel-api/text-abstraction/glyph-info.h>
26 #include <dali/internal/text/text-abstraction/font-client-impl.h>
27
28 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
29 #include <third-party/glyphy/vector-font-cache.h>
30 #else
31 class VectorFontCache;
32 #endif
33
34 // EXTERNAL INCLUDES
35 #include <ft2build.h>
36 #include FT_FREETYPE_H
37 #include FT_GLYPH_H
38 #include FT_OUTLINE_H
39 #include FT_STROKER_H
40 #include FT_SYNTHESIS_H
41
42 // forward declarations of font config types.
43 struct _FcCharSet;
44 struct _FcFontSet;
45 struct _FcPattern;
46
47 namespace Dali
48 {
49 namespace TextAbstraction
50 {
51 namespace Internal
52 {
53 /**
54  * @brief Type used for indices addressing the vector with front descriptions of validated fonts.
55  */
56 typedef uint32_t FontDescriptionId;
57
58 /**
59  * @brief Type used for indices addressing the vector with pixel buffers.
60  */
61 typedef uint32_t PixelBufferId;
62
63 /**
64  * @brief Vector of character sets.
65  */
66 typedef Vector<_FcCharSet*> CharacterSetList;
67
68 /**
69  * @brief FontClient implementation.
70  */
71 struct FontClient::Plugin
72 {
73   struct FontIdCacheItem
74   {
75     FontDescription::Type type; ///< The type of font.
76     FontId                id;   ///< Index to the cache of fonts for the specified type.
77   };
78
79   /**
80    * @brief Caches an list of fallback fonts for a given font-description
81    */
82   struct FallbackCacheItem
83   {
84     FallbackCacheItem(FontDescription&& fontDescription, FontList* fallbackFonts, CharacterSetList* characterSets);
85
86     FontDescription   fontDescription; ///< The font description.
87     FontList*         fallbackFonts;   ///< The list of fallback fonts for the given font-description.
88     CharacterSetList* characterSets;   ///< The list of character sets for the given font-description.
89   };
90
91   /**
92    * @brief Caches an index to the vector of font descriptions for a given font.
93    */
94   struct FontDescriptionCacheItem
95   {
96     FontDescriptionCacheItem(const FontDescription& fontDescription,
97                              FontDescriptionId      index);
98     FontDescriptionCacheItem(FontDescription&& fontDescription,
99                              FontDescriptionId index);
100
101     FontDescription   fontDescription; ///< The font description.
102     FontDescriptionId index;           ///< Index to the vector of font descriptions.
103   };
104
105   /**
106    * @brief Caches the font id of the pair font point size and the index to the vector of font descriptions of validated fonts.
107    */
108   struct FontDescriptionSizeCacheItem
109   {
110     FontDescriptionSizeCacheItem(FontDescriptionId validatedFontId,
111                                  PointSize26Dot6   requestedPointSize,
112                                  FontId            fontId);
113
114     FontDescriptionId validatedFontId;    ///< Index to the vector with font descriptions.
115     PointSize26Dot6   requestedPointSize; ///< The font point size.
116     FontId            fontId;             ///< The font identifier.
117   };
118
119   /**
120    * @brief Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'.
121    */
122   struct FontFaceCacheItem
123   {
124     FontFaceCacheItem(FT_Face            ftFace,
125                       const FontPath&    path,
126                       PointSize26Dot6    requestedPointSize,
127                       FaceIndex          face,
128                       const FontMetrics& metrics);
129
130     FontFaceCacheItem(FT_Face            ftFace,
131                       const FontPath&    path,
132                       PointSize26Dot6    requestedPointSize,
133                       FaceIndex          face,
134                       const FontMetrics& metrics,
135                       int                fixedSizeIndex,
136                       float              fixedWidth,
137                       float              fixedHeight,
138                       bool               hasColorTables);
139
140     FT_Face         mFreeTypeFace;          ///< The FreeType face.
141     FontPath        mPath;                  ///< The path to the font file name.
142     PointSize26Dot6 mRequestedPointSize;    ///< The font point size.
143     FaceIndex       mFaceIndex;             ///< The face index.
144     FontMetrics     mMetrics;               ///< The font metrics.
145     _FcCharSet*     mCharacterSet;          ///< Pointer with the range of characters.
146     int             mFixedSizeIndex;        ///< Index to the fixed size table for the requested size.
147     float           mFixedWidthPixels;      ///< The height in pixels (fixed size bitmaps only)
148     float           mFixedHeightPixels;     ///< The height in pixels (fixed size bitmaps only)
149     unsigned int    mVectorFontId;          ///< The ID of the equivalent vector-based font
150     FontId          mFontId;                ///< Index to the vector with the cache of font's ids.
151     bool            mIsFixedSizeBitmap : 1; ///< Whether the font has fixed size bitmaps.
152     bool            mHasColorTables : 1;    ///< Whether the font has color tables.
153   };
154
155   struct EllipsisItem
156   {
157     PointSize26Dot6 requestedPointSize;
158     GlyphInfo       glyph;
159   };
160
161   /**
162    * @brief Caches pixel buffers.
163    */
164   struct PixelBufferCacheItem
165   {
166     Devel::PixelBuffer pixelBuffer; ///< The pixel buffer loaded from the url.
167     std::string        url;         ///< The url.
168   };
169
170   /**
171    * @brief Caches embedded items.
172    */
173   struct EmbeddedItem
174   {
175     PixelBufferId pixelBufferId; ///< Index to the vector of pixel buffers
176     unsigned int  width;         ///< The desired width.
177     unsigned int  height;        ///< The desired height.
178   };
179
180   /**
181    * @brief Stores a bitmap font and its pixel buffers per glyph.
182    */
183   struct BitmapFontCacheItem
184   {
185     BitmapFont                      font;         ///< The bitmap font.
186     std::vector<Devel::PixelBuffer> pixelBuffers; ///< The pixel buffers of the glyphs.
187     FontId                          id;           ///< Index to the vector with the cache of font's ids.
188   };
189
190   /**
191    * Constructor.
192    *
193    * Initializes the FreeType library.
194    * Initializes the dpi values.
195    *
196    * @param[in] horizontalDpi The horizontal dpi.
197    * @param[in] verticalDpi The vertical dpi.
198    */
199   Plugin(unsigned int horizontalDpi, unsigned int verticalDpi);
200
201   /**
202    * Default destructor.
203    *
204    * Frees any allocated resource.
205    */
206   ~Plugin();
207
208   /**
209    * @copydoc Dali::TextAbstraction::FontClient::ClearCache()
210    */
211   void ClearCache();
212
213   /**
214    * @copydoc Dali::TextAbstraction::FontClient::SetDpi()
215    */
216   void SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi);
217
218   /**
219    * @copydoc Dali::TextAbstraction::FontClient::ResetSystemDefaults()
220    */
221   void ResetSystemDefaults();
222
223   /**
224    * @copydoc Dali::TextAbstraction::FontClient::SetDefaultFont()
225    */
226   void SetDefaultFont(const FontDescription& preferredFontDescription);
227
228   /**
229    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultPlatformFontDescription()
230    */
231   void GetDefaultPlatformFontDescription(FontDescription& fontDescription);
232
233   /**
234    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFonts()
235    */
236   void GetDefaultFonts(FontList& defaultFonts);
237
238   /**
239    * @copydoc Dali::TextAbstraction::FontClient::GetSystemFonts()
240    */
241   void GetSystemFonts(FontList& systemFonts);
242
243   /**
244    * @copydoc Dali::TextAbstraction::FontClient::GetDescription()
245    */
246   void GetDescription(FontId id, FontDescription& fontDescription) const;
247
248   /**
249    * @copydoc Dali::TextAbstraction::FontClient::GetPointSize()
250    */
251   PointSize26Dot6 GetPointSize(FontId id);
252
253   /**
254    * @copydoc Dali::TextAbstraction::FontClient::IsCharacterSupportedByFont()
255    */
256   bool IsCharacterSupportedByFont(FontId fontId, Character character);
257
258   /**
259    * @brief Finds within the @p fontList a font which support the @p carcode.
260    *
261    * @param[in] fontList A list of font paths, family, width, weight and slant.
262    * @param[in] characterSetList A list that contains a character set for each description of the font list.
263    * @param[in] charcode The character for which a font is needed.
264    * @param[in] requestedPointSize The point size in 26.6 fractional points.
265    * @param[in] preferColor @e true if a color font is preferred.
266    *
267    * @return A valid font identifier, or zero if no font is found.
268    */
269   FontId FindFontForCharacter(const FontList&         fontList,
270                               const CharacterSetList& characterSetList,
271                               Character               charcode,
272                               PointSize26Dot6         requestedPointSize,
273                               bool                    preferColor);
274
275   /**
276    * @copydoc Dali::TextAbstraction::FontClient::FindDefaultFont()
277    */
278   FontId FindDefaultFont(Character       charcode,
279                          PointSize26Dot6 requestedPointSize,
280                          bool            preferColor);
281
282   /**
283    * @copydoc Dali::TextAbstraction::FontClient::FindFallbackFont()
284    */
285   FontId FindFallbackFont(Character              charcode,
286                           const FontDescription& preferredFontDescription,
287                           PointSize26Dot6        requestedPointSize,
288                           bool                   preferColor);
289
290   /**
291    * @see Dali::TextAbstraction::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
292    *
293    * @param[in] cacheDescription Whether to cache the font description.
294    */
295   FontId GetFontId(const FontPath& path,
296                    PointSize26Dot6 requestedPointSize,
297                    FaceIndex       faceIndex,
298                    bool            cacheDescription);
299
300   /**
301    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontDescription& preferredFontDescription, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
302    */
303   FontId GetFontId(const FontDescription& fontDescription,
304                    PointSize26Dot6        requestedPointSize,
305                    FaceIndex              faceIndex);
306
307   /**
308    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const BitmapFont& bitmapFont )
309    */
310   FontId GetFontId(const BitmapFont& bitmapFont);
311
312   /**
313    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontPath& path )
314    */
315   bool IsScalable(const FontPath& path);
316
317   /**
318    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontDescription& fontDescription )
319    */
320   bool IsScalable(const FontDescription& fontDescription);
321
322   /**
323    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes()
324    */
325   void GetFixedSizes(const FontPath& path, Dali::Vector<PointSize26Dot6>& sizes);
326
327   /**
328    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes()
329    */
330   void GetFixedSizes(const FontDescription&         fontDescription,
331                      Dali::Vector<PointSize26Dot6>& sizes);
332
333   /**
334    * @copydoc Dali::TextAbstraction::FontClient::HasItalicStyle()
335    */
336   bool HasItalicStyle(FontId fontId) const;
337
338   /**
339    * @copydoc Dali::TextAbstraction::FontClient::GetFontMetrics()
340    */
341   void GetFontMetrics(FontId fontId, FontMetrics& metrics);
342
343   /**
344    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
345    */
346   GlyphIndex GetGlyphIndex(FontId fontId, Character charcode);
347
348   /**
349    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphMetrics()
350    */
351   bool GetGlyphMetrics(GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal);
352
353   /**
354    * Helper for GetGlyphMetrics when using bitmaps
355    */
356   bool GetBitmapMetrics(GlyphInfo* array, uint32_t size, bool horizontal);
357
358   /**
359    * Helper for GetGlyphMetrics when using vectors
360    */
361   bool GetVectorMetrics(GlyphInfo* array, uint32_t size, bool horizontal);
362
363   /**
364    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
365    */
366   void CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth);
367
368   /**
369    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
370    */
371   PixelData CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth);
372
373   /**
374    * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
375    */
376   void CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight);
377
378   /**
379    * @copydoc Dali::TextAbstraction::FontClient::GetEllipsisGlyph()
380    */
381   const GlyphInfo& GetEllipsisGlyph(PointSize26Dot6 requestedPointSize);
382
383   /**
384    * @copydoc Dali::TextAbstraction::FontClient::IsColorGlyph()
385    */
386   bool IsColorGlyph(FontId fontId, GlyphIndex glyphIndex);
387
388   /**
389    * @copydoc Dali::TextAbstraction::FontClient::CreateEmbeddedItem()
390    */
391   GlyphIndex CreateEmbeddedItem(const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat);
392
393   /**
394    * @copydoc Dali::TextAbstraction::FontClient::EnableAtlasLimitation(bool enabled)
395    */
396   void EnableAtlasLimitation(bool enabled);
397
398   /**
399    * @copydoc Dali::TextAbstraction::FontClient::IsAtlasLimitationEnabled()
400    */
401   bool IsAtlasLimitationEnabled() const;
402
403   /**
404    * @copydoc Dali::TextAbstraction::FontClient::GetMaximumTextAtlasSize()
405    */
406   Size GetMaximumTextAtlasSize() const;
407
408   /**
409    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultTextAtlasSize()
410    */
411   Size GetDefaultTextAtlasSize() const;
412
413   /**
414    * @copydoc Dali::TextAbstraction::FontClient::GetCurrentMaximumBlockSizeFitInAtlas()
415    */
416   Size GetCurrentMaximumBlockSizeFitInAtlas() const;
417
418   /**
419    * @copydoc Dali::TextAbstraction::FontClient::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
420    */
421   bool SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas);
422
423   /**
424    * @copydoc Dali::TextAbstraction::FontClient::GetNumberOfPointsPerOneUnitOfPointSize()
425    */
426   uint32_t GetNumberOfPointsPerOneUnitOfPointSize() const;
427
428   /**
429    * @copydoc Dali::TextAbstraction::Internal::FontClient::GetFreetypeFace()
430    */
431   FT_FaceRec_* GetFreetypeFace(FontId fontId);
432
433   /**
434    * @copydoc Dali::TextAbstraction::Internal::FontClient::GetFontType()
435    */
436   FontDescription::Type GetFontType(FontId fontId);
437
438   /**
439    * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
440    */
441   bool AddCustomFontDirectory(const FontPath& path);
442
443 private:
444   /**
445    * @brief Caches the fonts present in the platform.
446    *
447    * Calls GetFcFontSet() to retrieve the fonts.
448    */
449   void InitSystemFonts();
450
451   /**
452    * @brief Gets the FontDescription which matches the given pattern.
453    *
454    * @note The reference counter of the @p characterSet has been increased. Call FcCharSetDestroy to decrease it.
455    *
456    * @param[in] pattern pattern to match against.
457    * @param[out] fontDescription the resultant fontDescription that matched.
458    * @param[out] characterSet The character set for that pattern.
459    * @return true if match found.
460    */
461   bool MatchFontDescriptionToPattern(_FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription, _FcCharSet** characterSet);
462
463   /**
464    * @brief Creates a font family pattern used to match fonts.
465    *
466    * @note Need to call FcPatternDestroy to free the resources.
467    *
468    * @param[in] fontDescription The font to cache.
469    *
470    * @return The pattern.
471    */
472   _FcPattern* CreateFontFamilyPattern(const FontDescription& fontDescription) const;
473
474   /**
475    * @brief Retrieves the fonts present in the platform.
476    *
477    * @note Need to call FcFontSetDestroy to free the allocated resources.
478    *
479    * @return A font fonfig data structure with the platform's fonts.
480    */
481   _FcFontSet* GetFcFontSet() const;
482
483   /**
484    * @brief Retrieves a font config object's value from a pattern.
485    *
486    * @param[in] pattern The font config pattern.
487    * @param[in] n The object.
488    * @param[out] string The object's value.
489    *
490    * @return @e true if the operation is successful.
491    */
492   bool GetFcString(const _FcPattern* const pattern, const char* const n, std::string& string);
493
494   /**
495    * @brief Retrieves a font config object's value from a pattern.
496    *
497    * @param[in] pattern The font config pattern.
498    * @param[in] n The object.
499    * @param[out] intVal The object's value.
500    *
501    * @return @e true if the operation is successful.
502    */
503   bool GetFcInt(const _FcPattern* const pattern, const char* const n, int& intVal);
504
505   /**
506    * @brief Creates a font.
507    *
508    * @param[in] path The path to the font file name.
509    * @param[in] requestedPointSize The requested point size.
510    * @param[in] faceIndex A face index.
511    * @param[in] cacheDescription Whether to cache the font description.
512    *
513    * @return The font identifier.
514    */
515   FontId CreateFont(const FontPath& path,
516                     PointSize26Dot6 requestedPointSize,
517                     FaceIndex       faceIndex,
518                     bool            cacheDescription);
519
520   /**
521    * @brief Copy the color bitmap given in @p srcBuffer to @p data.
522    *
523    * @param[out] data The bitmap data.
524    * @param[in] srcWidth The width of the bitmap.
525    * @param[in] srcHeight The height of the bitmap.
526    * @param[in] srcBuffer The buffer of the bitmap.
527    */
528   void ConvertBitmap(TextAbstraction::FontClient::GlyphBufferData& data, unsigned int srcWidth, unsigned int srcHeight, const unsigned char* const srcBuffer);
529
530   /**
531    * @brief Copy the FreeType bitmap to the given buffer.
532    *
533    * @param[out] data The bitmap data.
534    * @param[in] srcBitmap The FreeType bitmap.
535    * @param[in] isShearRequired Whether the bitmap needs a shear transform (for software italics).
536    */
537   void ConvertBitmap(TextAbstraction::FontClient::GlyphBufferData& data, FT_Bitmap srcBitmap, bool isShearRequired);
538
539   /**
540    * @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.
541    * If there is one , if writes the font identifier in the param @p fontId.
542    *
543    * @param[in] path Path to the font file name.
544    * @param[in] requestedPointSize The font point size.
545    * @param[in] faceIndex The face index.
546    * @param[out] fontId The font identifier.
547    *
548    * @return @e true if there triplet is found.
549    */
550   bool FindFont(const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex, FontId& fontId) const;
551
552   /**
553    * @brief Finds in the cache a cluster 'font family, font width, font weight, font slant'
554    * If there is one, it writes the index to the vector with font descriptions in the param @p validatedFontId.
555    *
556    * @param[in] fontDescription The font to validate.
557    * @param[out] validatedFontId The index to the vector with font descriptions.
558    *
559    * @return @e true if the pair is found.
560    */
561   bool FindValidatedFont(const FontDescription& fontDescription,
562                          FontDescriptionId&     validatedFontId);
563
564   /**
565    * @brief Finds a fallback font list from the cache for a given font-description
566    *
567    * @param[in] fontDescription The font to validate.
568    * @param[out] A valid pointer to a font list, or @e nullptr if not found.
569    * @param[out] characterSetList A valid pointer to a character set list, or @e nullptr if not found.
570    */
571   bool FindFallbackFontList(const FontDescription& fontDescription,
572                             FontList*&             fontList,
573                             CharacterSetList*&     characterSetList);
574
575   /**
576    * @brief Finds in the cache a pair 'validated font identifier and font point size'.
577    * If there is one it writes the font identifier in the param @p fontId.
578    *
579    * @param[in] validatedFontId Index to the vector with font descriptions.
580    * @param[in] requestedPointSize The font point size.
581    * @param[out] fontId The font identifier.
582    *
583    * @return @e true if the pair is found.
584    */
585   bool FindFont(FontDescriptionId validatedFontId,
586                 PointSize26Dot6   requestedPointSize,
587                 FontId&           fontId);
588
589   /**
590    * @brief Finds in the cache a bitmap font with the @p bitmapFont family name.
591    *
592    * @param[in] bitmapFont The font's family name.
593    * @param[out] fontId The id of the font.
594    *
595    * @return Whether the font has been found.
596    */
597   bool FindBitmapFont(const FontFamily& bitmapFont, FontId& fontId) const;
598
599   /**
600    * @brief Validate a font description.
601    *
602    * @param[in] fontDescription The font to validate.
603    * @param[out] validatedFontId Result of validation
604    */
605   void ValidateFont(const FontDescription& fontDescription,
606                     FontDescriptionId&     validatedFontId);
607
608   /**
609    * @brief Helper for GetDefaultFonts etc.
610    *
611    * @note CharacterSetList is a vector of FcCharSet that are reference counted. It's needed to call FcCharSetDestroy to decrease the reference counter.
612    *
613    * @param[in] fontDescription A font description.
614    * @param[out] fontList A list of the fonts which are a close match for fontDescription.
615    * @param[out] characterSetList A list of character sets which are a close match for fontDescription.
616    */
617   void SetFontList(const FontDescription& fontDescription, FontList& fontList, CharacterSetList& characterSetList);
618
619   /**
620    * Caches a font path.
621    *
622    * @param[in] ftFace The FreeType face.
623    * @param[in] id The font identifier.
624    * @param[in] requestedPointSize The font point size.
625    * @param[in] path Path to the font file name.
626    */
627   void CacheFontPath(FT_Face ftFace, FontId id, PointSize26Dot6 requestedPointSize, const FontPath& path);
628
629   /**
630    * @brief Creates a character set from a given font's @p description.
631    *
632    * @note Need to call FcCharSetDestroy to free the resources.
633    *
634    * @param[in] description The font's description.
635    *
636    * @return A character set.
637    */
638   _FcCharSet* CreateCharacterSetFromDescription(const FontDescription& description);
639
640   /**
641    * @brief Free the resources allocated in the fallback cache.
642    *
643    * @param[in] fallbackCache The fallback cache.
644    */
645   void ClearFallbackCache(std::vector<FallbackCacheItem>& fallbackCache);
646
647   /**
648    * @brief Free the resources allocated by the FcCharSet objects.
649    */
650   void ClearCharacterSetFromFontFaceCache();
651
652 private:
653   // Declared private and left undefined to avoid copies.
654   Plugin(const Plugin&);
655   // Declared private and left undefined to avoid copies.
656   Plugin& operator=(const Plugin&);
657
658 private:
659   FT_Library mFreeTypeLibrary; ///< A handle to a FreeType library instance.
660
661   unsigned int mDpiHorizontal; ///< Horizontal dpi.
662   unsigned int mDpiVertical;   ///< Vertical dpi.
663
664   FontDescription mDefaultFontDescription; ///< The cached default font from the system
665
666   FontList         mSystemFonts;  ///< Cached system fonts.
667   FontList         mDefaultFonts; ///< Cached default fonts.
668   CharacterSetList mDefaultFontCharacterSets;
669
670   std::vector<FallbackCacheItem> mFallbackCache; ///< Cached fallback font lists.
671
672   Vector<FontIdCacheItem>                   mFontIdCache;
673   std::vector<FontFaceCacheItem>            mFontFaceCache;            ///< Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'.
674   std::vector<FontDescriptionCacheItem>     mValidatedFontCache;       ///< Caches indices to the vector of font descriptions for a given font.
675   FontList                                  mFontDescriptionCache;     ///< Caches font descriptions for the validated font.
676   CharacterSetList                          mCharacterSetCache;        ///< Caches character set lists for the validated font.
677   std::vector<FontDescriptionSizeCacheItem> mFontDescriptionSizeCache; ///< Caches font identifiers for the pairs of font point size and the index to the vector with font descriptions of the validated fonts.
678
679   VectorFontCache* mVectorFontCache; ///< Separate cache for vector data blobs etc.
680
681   Vector<EllipsisItem>              mEllipsisCache;     ///< Caches ellipsis glyphs for a particular point size.
682   std::vector<PixelBufferCacheItem> mPixelBufferCache;  ///< Caches the pixel buffer of a url.
683   Vector<EmbeddedItem>              mEmbeddedItemCache; ///< Cache embedded items.
684   std::vector<BitmapFontCacheItem>  mBitmapFontCache;   ///< Stores bitmap fonts.
685
686   bool mDefaultFontDescriptionCached : 1; ///< Whether the default font is cached or not
687
688   bool    mIsAtlasLimitationEnabled : 1;      ///< Whether the validation on maximum atlas block size, then reduce block size to fit into it is enabled or not.
689   Vector2 mCurrentMaximumBlockSizeFitInAtlas; ///< The current maximum size (width, height) of text-atlas-block.
690 };
691
692 } // namespace Internal
693
694 } // namespace TextAbstraction
695
696 } // namespace Dali
697
698 #endif // DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H