Merge "Text improvement 1. Circular text implementation. * Adds to dali-adaptor...
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / font-client-impl.h
1 #ifndef DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H
2 #define DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H
3
4 /*
5  * Copyright (c) 2019 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/base-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/text-abstraction/font-client.h>
26
27
28 struct FT_FaceRec_;
29
30 namespace Dali
31 {
32
33 namespace TextAbstraction
34 {
35
36 namespace Internal
37 {
38
39 /**
40  * Implementation of the FontClient
41  */
42 class FontClient : public BaseObject
43 {
44 public:
45
46   /**
47    * Constructor
48    */
49   FontClient();
50
51   /**
52    * Destructor
53    */
54   ~FontClient();
55
56   /**
57    * @copydoc Dali::TextAbstraction::FontClient::Get()
58    */
59   static Dali::TextAbstraction::FontClient Get();
60
61   /**
62    * @copydoc Dali::TextAbstraction::FontClient::SetDpi()
63    */
64   void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
65
66   /**
67    * @copydoc Dali::TextAbstraction::FontClient::GetDpi()
68    */
69   void GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi );
70
71   /**
72    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFontSize()
73    */
74   int GetDefaultFontSize();
75
76   /**
77    * @copydoc Dali::TextAbstraction::FontClient::ResetSystemDefaults()
78    */
79   void ResetSystemDefaults();
80
81   /**
82    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFonts()
83    */
84   void GetDefaultFonts( FontList& defaultFonts );
85
86   /**
87    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultPlatformFontDescription()
88    */
89   void GetDefaultPlatformFontDescription( FontDescription& fontDescription );
90
91   /**
92    * @copydoc Dali::TextAbstraction::FontClient::GetSystemFonts()
93    */
94   void GetSystemFonts( FontList& systemFonts );
95
96   /**
97    * @copydoc Dali::TextAbstraction::FontClient::GetDescription()
98    */
99   void GetDescription( FontId id, FontDescription& fontDescription );
100
101   /**
102    * @copydoc Dali::TextAbstraction::FontClient::GetPointSize()
103    */
104   PointSize26Dot6 GetPointSize( FontId id );
105
106   /**
107    * @copydoc Dali::TextAbstraction::FontClient::IsCharacterSupportedByFont()
108    */
109   bool IsCharacterSupportedByFont( FontId fontId, Character character );
110
111   /**
112    * @copydoc Dali::TextAbstraction::FontClient::FindDefaultFont()
113    */
114   FontId FindDefaultFont( Character charcode,
115                           PointSize26Dot6 requestedPointSize,
116                           bool preferColor );
117
118   /**
119    * @copydoc Dali::TextAbstraction::FontClient::FindFallbackFont()
120    */
121   FontId FindFallbackFont( Character charcode,
122                            const FontDescription& preferredFontDescription,
123                            PointSize26Dot6 requestedPointSize,
124                            bool preferColor );
125
126   /**
127    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
128    */
129   FontId GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex );
130
131   /**
132    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
133    */
134   FontId GetFontId( const FontDescription& fontDescription,
135                     PointSize26Dot6 requestedPointSize,
136                     FaceIndex faceIndex );
137
138   /**
139    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const BitmapFont& bitmapFont )
140    */
141   FontId GetFontId( const BitmapFont& bitmapFont );
142
143   /**
144    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontPath& path )
145    */
146   bool IsScalable( const FontPath& path );
147
148   /**
149    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontDescription& fontDescription )
150    */
151   bool IsScalable( const FontDescription& fontDescription );
152
153   /**
154    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
155    */
156   void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
157
158   /**
159    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes()
160    */
161   void GetFixedSizes( const FontDescription& fontDescription,
162                       Dali::Vector< PointSize26Dot6 >& sizes );
163
164   /**
165    * @copydoc Dali::TextAbstraction::FontClient::HasItalicStyle()
166    */
167   bool HasItalicStyle( FontId fontId ) const;
168
169   /**
170    * @copydoc Dali::TextAbstraction::FontClient::GetFontMetrics()
171    */
172   void GetFontMetrics( FontId fontId, FontMetrics& metrics );
173
174   /**
175    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
176    */
177   GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
178
179   /**
180    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphMetrics()
181    */
182   bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal );
183
184   /**
185    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
186    */
187   void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth );
188
189   /**
190    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
191    */
192   PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth );
193
194   /**
195    * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
196    */
197   void CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight );
198
199   /**
200    * @copydoc Dali::TextAbstraction::FontClient::GetEllipsisGlyph()
201    */
202   const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 requestedPointSize );
203
204   /**
205    * @copydoc Dali::TextAbstraction::FontClient::IsColorGlyph()
206    */
207   bool IsColorGlyph( FontId fontId, GlyphIndex glyphIndex );
208
209   /**
210    * @copydoc Dali::TextAbstraction::FontClient::CreateEmbeddedItem()
211    */
212   GlyphIndex CreateEmbeddedItem( const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat );
213
214   /**
215    * @brief Retrieves the pointer to the FreeType Font Face for the given @p fontId.
216    *
217    * @param[in] fontId The font id.
218    *
219    * @return The pointer to the FreeType Font Face.
220    */
221   FT_FaceRec_* GetFreetypeFace( FontId fontId );
222
223   /**
224    * @brief Retrieves the type of font.
225    *
226    * @param[in] fontId The font id.
227    *
228    * @return FACE_FONT if the font has been loaded by FreeType, BITMAP_FONT if it's a font that has been loaded from images or INVALID if it's a non valid font.
229    */
230   FontDescription::Type GetFontType( FontId fontId );
231
232   /**
233    * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
234    */
235   bool AddCustomFontDirectory( const FontPath& path );
236
237 private:
238
239   /**
240    * Helper for lazy initialization.
241    */
242   void CreatePlugin();
243
244   // Undefined copy constructor.
245   FontClient( const FontClient& );
246
247   // Undefined assignment constructor.
248   FontClient& operator=( const FontClient& );
249
250 private:
251
252   struct Plugin;
253   Plugin* mPlugin;
254
255   // Allows DPI to be set without loading plugin
256   unsigned int mDpiHorizontal;
257   unsigned int mDpiVertical;
258
259 }; // class FontClient
260
261 } // namespace Internal
262
263 inline static Internal::FontClient& GetImplementation(FontClient& fontClient)
264 {
265   DALI_ASSERT_ALWAYS( fontClient && "fontClient handle is empty" );
266   BaseObject& handle = fontClient.GetBaseObject();
267   return static_cast<Internal::FontClient&>(handle);
268 }
269
270 inline static const Internal::FontClient& GetImplementation(const FontClient& fontClient)
271 {
272   DALI_ASSERT_ALWAYS( fontClient && "fontClient handle is empty" );
273   const BaseObject& handle = fontClient.GetBaseObject();
274   return static_cast<const Internal::FontClient&>(handle);
275 }
276
277 } // namespace TextAbstraction
278
279 } // namespace Dali
280
281 #endif // DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H