Refactored font-client-plugin-impl
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / plugin / font-face-cache-item.h
1 #ifndef DALI_TEST_ABSTRACTION_INTERNAL_FONT_FACE_CACHE_ITEM_H
2 #define DALI_TEST_ABSTRACTION_INTERNAL_FONT_FACE_CACHE_ITEM_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 // INTERNAL INCLUDES
21
22 #include <dali/internal/text/text-abstraction/plugin/font-cache-item-interface.h>
23
24 // EXTERNAL INCLUDES
25 #include <fontconfig/fontconfig.h>
26
27 // EXTERNAL INCLUDES
28 #include <ft2build.h>
29 #include FT_FREETYPE_H
30 #include FT_GLYPH_H
31 #include FT_OUTLINE_H
32 #include FT_STROKER_H
33 #include FT_SYNTHESIS_H
34
35 namespace Dali::TextAbstraction::Internal
36 {
37 /**
38  * @brief Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'.
39  */
40 struct FontFaceCacheItem : public FontCacheItemInterface
41 {
42   FontFaceCacheItem(FT_Library&        freeTypeLibrary,
43                     FT_Face            ftFace,
44                     const FontPath&    path,
45                     PointSize26Dot6    requestedPointSize,
46                     FaceIndex          face,
47                     const FontMetrics& metrics);
48
49   FontFaceCacheItem(FT_Library&        freeTypeLibrary,
50                     FT_Face            ftFace,
51                     const FontPath&    path,
52                     PointSize26Dot6    requestedPointSize,
53                     FaceIndex          face,
54                     const FontMetrics& metrics,
55                     int                fixedSizeIndex,
56                     float              fixedWidth,
57                     float              fixedHeight,
58                     bool               hasColorTables);
59
60   /**
61    * @copydoc FontCacheItemInterface::GetFontMetrics()
62    */
63   void GetFontMetrics(FontMetrics& metrics, unsigned int dpiVertical) const override;
64
65   /**
66    * @copydoc FontCacheItemInterface::GetGlyphMetrics()
67    */
68   bool GetGlyphMetrics(GlyphInfo& glyph, unsigned int dpiVertical, bool horizontal) const override;
69
70   /**
71    * @copydoc FontCacheItemInterface::CreateBitmap()
72    */
73   void CreateBitmap(GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth, bool isItalicRequired, bool isBoldRequired) const override;
74
75   /**
76    * @copydoc FontCacheItemInterface::IsColorGlyph()
77    */
78   bool IsColorGlyph(GlyphIndex glyphIndex) const override;
79
80   /**
81    * @copydoc FontCacheItemInterface::IsCharacterSupported()
82    */
83   bool IsCharacterSupported(Character character) override;
84
85   /**
86    * @copydoc FontCacheItemInterface::GetPointSize()
87    */
88   PointSize26Dot6 GetPointSize() const override
89   {
90     return mRequestedPointSize;
91   }
92
93   /**
94    * @copydoc FontCacheItemInterface::GetGlyphIndex()
95    */
96   GlyphIndex GetGlyphIndex(Character character) const override;
97
98   /**
99    * @copydoc FontCacheItemInterface::GetTypeface()
100    */
101   FT_Face GetTypeface() const override
102   {
103     return mFreeTypeFace;
104   }
105
106   /**
107    * @copydoc FontCacheItemInterface::HasItalicStyle()
108    */
109   bool HasItalicStyle() const override
110   {
111     return (0u != (mFreeTypeFace->style_flags & FT_STYLE_FLAG_ITALIC));
112   }
113
114   FT_Library&     mFreeTypeLibrary;       ///< A handle to a FreeType library instance.
115   FT_Face         mFreeTypeFace;          ///< The FreeType face.
116   FontPath        mPath;                  ///< The path to the font file name.
117   PointSize26Dot6 mRequestedPointSize;    ///< The font point size.
118   FaceIndex       mFaceIndex;             ///< The face index.
119   FontMetrics     mMetrics;               ///< The font metrics.
120   _FcCharSet*     mCharacterSet;          ///< Pointer with the range of characters.
121   int             mFixedSizeIndex;        ///< Index to the fixed size table for the requested size.
122   float           mFixedWidthPixels;      ///< The height in pixels (fixed size bitmaps only)
123   float           mFixedHeightPixels;     ///< The height in pixels (fixed size bitmaps only)
124   unsigned int    mVectorFontId;          ///< The ID of the equivalent vector-based font
125   FontId          mFontId;                ///< Index to the vector with the cache of font's ids.
126   bool            mIsFixedSizeBitmap : 1; ///< Whether the font has fixed size bitmaps.
127   bool            mHasColorTables : 1;    ///< Whether the font has color tables.
128 };
129
130 } // namespace Dali::TextAbstraction::Internal
131
132 #endif //DALI_TEST_ABSTRACTION_INTERNAL_FONT_FACE_CACHE_ITEM_H