Merge "fix the bug when window is resized by display server" into devel/master
[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                     const FontPath&    path,
47                     PointSize26Dot6    requestedPointSize,
48                     FaceIndex          face,
49                     const FontMetrics& metrics);
50
51   FontFaceCacheItem(const FT_Library&  freeTypeLibrary,
52                     FT_Face            ftFace,
53                     const FontPath&    path,
54                     PointSize26Dot6    requestedPointSize,
55                     FaceIndex          face,
56                     const FontMetrics& metrics,
57                     int                fixedSizeIndex,
58                     float              fixedWidth,
59                     float              fixedHeight,
60                     bool               hasColorTables);
61
62   FontFaceCacheItem(const FontFaceCacheItem& rhs) = delete; // Do not use copy construct
63   FontFaceCacheItem(FontFaceCacheItem&& rhs);
64
65   ~FontFaceCacheItem();
66
67   /**
68    * @copydoc FontCacheItemInterface::GetFontMetrics()
69    */
70   void GetFontMetrics(FontMetrics& metrics, unsigned int dpiVertical) const override;
71
72   /**
73    * @copydoc FontCacheItemInterface::GetGlyphMetrics()
74    */
75   bool GetGlyphMetrics(GlyphInfo& glyphInfo, unsigned int dpiVertical, bool horizontal) const override;
76
77   /**
78    * @copydoc FontCacheItemInterface::CreateBitmap()
79    */
80   void CreateBitmap(GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth, bool isItalicRequired, bool isBoldRequired) const override;
81
82   /**
83    * @copydoc FontCacheItemInterface::IsColorGlyph()
84    */
85   bool IsColorGlyph(GlyphIndex glyphIndex) const override;
86
87   /**
88    * @copydoc FontCacheItemInterface::IsCharacterSupported()
89    */
90   bool IsCharacterSupported(Character character) override;
91
92   /**
93    * @copydoc FontCacheItemInterface::GetPointSize()
94    */
95   PointSize26Dot6 GetPointSize() const override
96   {
97     return mRequestedPointSize;
98   }
99
100   /**
101    * @copydoc FontCacheItemInterface::GetGlyphIndex()
102    */
103   GlyphIndex GetGlyphIndex(Character character) const override;
104
105   /**
106    * @copydoc FontCacheItemInterface::GetGlyphIndex()
107    */
108   GlyphIndex GetGlyphIndex(Character character, Character variantSelector) const override;
109
110   /**
111    * @copydoc FontCacheItemInterface::GetTypeface()
112    */
113   FT_Face GetTypeface() const override
114   {
115     return mFreeTypeFace;
116   }
117
118   /**
119    * @copydoc FontCacheItemInterface::GetHarfBuzzFont()
120    */
121   HarfBuzzFontHandle GetHarfBuzzFont(const uint32_t& horizontalDpi, const uint32_t& verticalDpi) override;
122
123   /**
124    * @copydoc FontCacheItemInterface::HasItalicStyle()
125    */
126   bool HasItalicStyle() const override
127   {
128     return (0u != (mFreeTypeFace->style_flags & FT_STYLE_FLAG_ITALIC));
129   }
130
131 public:
132   const FT_Library& mFreeTypeLibrary; ///< A handle to a FreeType library instance.
133   FT_Face           mFreeTypeFace;    ///< The FreeType face.
134
135   std::unique_ptr<GlyphCacheManager> mGlyphCacheManager; ///< The glyph cache manager. It will cache this face's glyphs.
136   std::unique_ptr<HarfBuzzProxyFont> mHarfBuzzProxyFont; ///< The harfbuzz font. It will store harfbuzz relate data.
137
138   FontPath        mPath;                  ///< The path to the font file name.
139   PointSize26Dot6 mRequestedPointSize;    ///< The font point size.
140   FaceIndex       mFaceIndex;             ///< The face index.
141   FontMetrics     mMetrics;               ///< The font metrics.
142   _FcCharSet*     mCharacterSet;          ///< Pointer with the range of characters.
143   int             mFixedSizeIndex;        ///< Index to the fixed size table for the requested size.
144   float           mFixedWidthPixels;      ///< The height in pixels (fixed size bitmaps only)
145   float           mFixedHeightPixels;     ///< The height in pixels (fixed size bitmaps only)
146   unsigned int    mVectorFontId;          ///< The ID of the equivalent vector-based font
147   FontId          mFontId;                ///< Index to the vector with the cache of font's ids.
148   bool            mIsFixedSizeBitmap : 1; ///< Whether the font has fixed size bitmaps.
149   bool            mHasColorTables : 1;    ///< Whether the font has color tables.
150 };
151
152 } // namespace Dali::TextAbstraction::Internal
153
154 #endif //DALI_TEXT_ABSTRACTION_INTERNAL_FONT_FACE_CACHE_ITEM_H