Make GlyphBufferData as another class
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / plugin / font-face-cache-item.h
1 #ifndef DALI_TEXT_ABSTRACTION_INTERNAL_FONT_FACE_CACHE_ITEM_H
2 #define DALI_TEXT_ABSTRACTION_INTERNAL_FONT_FACE_CACHE_ITEM_H
3
4 /*
5  * Copyright (c) 2022 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 #include <dali/internal/text/text-abstraction/plugin/font-cache-item-interface.h>
22 #include <dali/internal/text/text-abstraction/plugin/font-face-glyph-cache-manager.h>
23 #include <dali/internal/text/text-abstraction/plugin/harfbuzz-proxy-font.h>
24
25 // EXTERNAL INCLUDES
26 #include <fontconfig/fontconfig.h>
27 #include <memory> // for std::unique_ptr
28
29 // EXTERNAL INCLUDES
30 #include <ft2build.h>
31 #include FT_FREETYPE_H
32 #include FT_GLYPH_H
33 #include FT_OUTLINE_H
34 #include FT_STROKER_H
35 #include FT_SYNTHESIS_H
36
37 namespace Dali::TextAbstraction::Internal
38 {
39 /**
40  * @brief Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'.
41  */
42 struct FontFaceCacheItem : public FontCacheItemInterface
43 {
44   FontFaceCacheItem(const FT_Library&  freeTypeLibrary,
45                     FT_Face            ftFace,
46                     GlyphCacheManager* glyphCacheManager,
47                     const FontPath&    path,
48                     PointSize26Dot6    requestedPointSize,
49                     FaceIndex          face,
50                     const FontMetrics& metrics);
51
52   FontFaceCacheItem(const FT_Library&  freeTypeLibrary,
53                     FT_Face            ftFace,
54                     GlyphCacheManager* glyphCacheManager,
55                     const FontPath&    path,
56                     PointSize26Dot6    requestedPointSize,
57                     FaceIndex          face,
58                     const FontMetrics& metrics,
59                     int                fixedSizeIndex,
60                     float              fixedWidth,
61                     float              fixedHeight,
62                     bool               hasColorTables);
63
64   FontFaceCacheItem(const FontFaceCacheItem& rhs) = delete; // Do not use copy construct
65   FontFaceCacheItem(FontFaceCacheItem&& rhs);
66
67   ~FontFaceCacheItem();
68
69   /**
70    * @copydoc FontCacheItemInterface::GetFontMetrics()
71    */
72   void GetFontMetrics(FontMetrics& metrics, unsigned int dpiVertical) const override;
73
74   /**
75    * @copydoc FontCacheItemInterface::GetGlyphMetrics()
76    */
77   bool GetGlyphMetrics(GlyphInfo& glyphInfo, unsigned int dpiVertical, bool horizontal) const override;
78
79   /**
80    * @copydoc FontCacheItemInterface::CreateBitmap()
81    */
82   void CreateBitmap(GlyphIndex glyphIndex, Dali::TextAbstraction::GlyphBufferData& data, int outlineWidth, bool isItalicRequired, bool isBoldRequired) const override;
83
84   /**
85    * @copydoc FontCacheItemInterface::IsColorGlyph()
86    */
87   bool IsColorGlyph(GlyphIndex glyphIndex) const override;
88
89   /**
90    * @copydoc FontCacheItemInterface::IsCharacterSupported()
91    */
92   bool IsCharacterSupported(Character character) override;
93
94   /**
95    * @copydoc FontCacheItemInterface::GetPointSize()
96    */
97   PointSize26Dot6 GetPointSize() const override
98   {
99     return mRequestedPointSize;
100   }
101
102   /**
103    * @copydoc FontCacheItemInterface::GetGlyphIndex()
104    */
105   GlyphIndex GetGlyphIndex(Character character) const override;
106
107   /**
108    * @copydoc FontCacheItemInterface::GetGlyphIndex()
109    */
110   GlyphIndex GetGlyphIndex(Character character, Character variantSelector) const override;
111
112   /**
113    * @copydoc FontCacheItemInterface::GetTypeface()
114    */
115   FT_Face GetTypeface() const override
116   {
117     return mFreeTypeFace;
118   }
119
120   /**
121    * @copydoc FontCacheItemInterface::GetHarfBuzzFont()
122    */
123   HarfBuzzFontHandle GetHarfBuzzFont(const uint32_t& horizontalDpi, const uint32_t& verticalDpi) override;
124
125   /**
126    * @copydoc FontCacheItemInterface::HasItalicStyle()
127    */
128   bool HasItalicStyle() const override
129   {
130     return (0u != (mFreeTypeFace->style_flags & FT_STYLE_FLAG_ITALIC));
131   }
132
133 public:
134   const FT_Library& mFreeTypeLibrary; ///< A handle to a FreeType library instance.
135   FT_Face           mFreeTypeFace;    ///< The FreeType face.
136
137   GlyphCacheManager*                 mGlyphCacheManager; ///< The reference of Glyph cache manager. Owned from font-client-plugin-cache-handler.
138   std::unique_ptr<HarfBuzzProxyFont> mHarfBuzzProxyFont; ///< The harfbuzz font. It will store harfbuzz relate data.
139
140   FontPath        mPath;                  ///< The path to the font file name.
141   PointSize26Dot6 mRequestedPointSize;    ///< The font point size.
142   FaceIndex       mFaceIndex;             ///< The face index.
143   FontMetrics     mMetrics;               ///< The font metrics.
144   _FcCharSet*     mCharacterSet;          ///< Pointer with the range of characters.
145   int             mFixedSizeIndex;        ///< Index to the fixed size table for the requested size.
146   float           mFixedWidthPixels;      ///< The height in pixels (fixed size bitmaps only)
147   float           mFixedHeightPixels;     ///< The height in pixels (fixed size bitmaps only)
148   unsigned int    mVectorFontId;          ///< The ID of the equivalent vector-based font
149   FontId          mFontId;                ///< Index to the vector with the cache of font's ids.
150   bool            mIsFixedSizeBitmap : 1; ///< Whether the font has fixed size bitmaps.
151   bool            mHasColorTables : 1;    ///< Whether the font has color tables.
152 };
153
154 } // namespace Dali::TextAbstraction::Internal
155
156 #endif //DALI_TEXT_ABSTRACTION_INTERNAL_FONT_FACE_CACHE_ITEM_H