[4.0] FreeType fonts/library - Stop creating new instances.
[platform/core/uifw/dali-adaptor.git] / text / dali / internal / 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) 2017 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::ClearCache()
63    */
64   void ClearCache();
65
66   /**
67    * @copydoc Dali::TextAbstraction::FontClient::SetDpi()
68    */
69   void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
70
71   /**
72    * @copydoc Dali::TextAbstraction::FontClient::GetDpi()
73    */
74   void GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi );
75
76   /**
77    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFontSize()
78    */
79   int GetDefaultFontSize();
80
81   /**
82    * @copydoc Dali::TextAbstraction::FontClient::ResetSystemDefaults()
83    */
84   void ResetSystemDefaults();
85
86   /**
87    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFonts()
88    */
89   void GetDefaultFonts( FontList& defaultFonts );
90
91   /**
92    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultPlatformFontDescription()
93    */
94   void GetDefaultPlatformFontDescription( FontDescription& fontDescription );
95
96   /**
97    * @copydoc Dali::TextAbstraction::FontClient::GetSystemFonts()
98    */
99   void GetSystemFonts( FontList& systemFonts );
100
101   /**
102    * @copydoc Dali::TextAbstraction::FontClient::GetDescription()
103    */
104   void GetDescription( FontId id, FontDescription& fontDescription );
105
106   /**
107    * @copydoc Dali::TextAbstraction::FontClient::GetPointSize()
108    */
109   PointSize26Dot6 GetPointSize( FontId id );
110
111   /**
112    * @copydoc Dali::TextAbstraction::FontClient::IsCharacterSupportedByFont()
113    */
114   bool IsCharacterSupportedByFont( FontId fontId, Character character );
115
116   /**
117    * @copydoc Dali::TextAbstraction::FontClient::FindDefaultFont()
118    */
119   FontId FindDefaultFont( Character charcode,
120                           PointSize26Dot6 requestedPointSize,
121                           bool preferColor );
122
123   /**
124    * @copydoc Dali::TextAbstraction::FontClient::FindFallbackFont()
125    */
126   FontId FindFallbackFont( Character charcode,
127                            const FontDescription& preferredFontDescription,
128                            PointSize26Dot6 requestedPointSize,
129                            bool preferColor );
130
131   /**
132    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
133    */
134   FontId GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex );
135
136   /**
137    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
138    */
139   FontId GetFontId( const FontDescription& fontDescription,
140                     PointSize26Dot6 requestedPointSize,
141                     FaceIndex faceIndex );
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::GetFontMetrics()
166    */
167   void GetFontMetrics( FontId fontId, FontMetrics& metrics );
168
169   /**
170    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
171    */
172   GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
173
174   /**
175    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphMetrics()
176    */
177   bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal );
178
179   /**
180    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
181    */
182   void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth );
183
184   /**
185    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
186    */
187   PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth );
188
189   /**
190    * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
191    */
192   void CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight );
193
194   /**
195    * @copydoc Dali::TextAbstraction::FontClient::GetEllipsisGlyph()
196    */
197   const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 requestedPointSize );
198
199   /**
200    * @copydoc Dali::TextAbstraction::FontClient::IsColorGlyph()
201    */
202   bool IsColorGlyph( FontId fontId, GlyphIndex glyphIndex );
203
204   /**
205    * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
206    */
207   bool AddCustomFontDirectory( const FontPath& path );
208
209   /**
210    * @brief Retrieves the pointer to the FreeType Font Face for the given @p fontId.
211    *
212    * @param[in] fontId The font id.
213    *
214    * @return The pointer to the FreeType Font Face.
215    */
216   FT_FaceRec_* GetFreetypeFace( FontId fontId );
217
218 private:
219
220   /**
221    * Helper for lazy initialization.
222    */
223   void CreatePlugin();
224
225   // Undefined copy constructor.
226   FontClient( const FontClient& );
227
228   // Undefined assignment constructor.
229   FontClient& operator=( const FontClient& );
230
231 private:
232
233   struct Plugin;
234   Plugin* mPlugin;
235
236   // Allows DPI to be set without loading plugin
237   unsigned int mDpiHorizontal;
238   unsigned int mDpiVertical;
239
240 }; // class FontClient
241
242 } // namespace Internal
243
244 inline static Internal::FontClient& GetImplementation(FontClient& fontClient)
245 {
246   DALI_ASSERT_ALWAYS( fontClient && "fontClient handle is empty" );
247   BaseObject& handle = fontClient.GetBaseObject();
248   return static_cast<Internal::FontClient&>(handle);
249 }
250
251 inline static const Internal::FontClient& GetImplementation(const FontClient& fontClient)
252 {
253   DALI_ASSERT_ALWAYS( fontClient && "fontClient handle is empty" );
254   const BaseObject& handle = fontClient.GetBaseObject();
255   return static_cast<const Internal::FontClient&>(handle);
256 }
257
258 } // namespace TextAbstraction
259
260 } // namespace Dali
261
262 #endif // DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H