Merge "Fixed issue preventing Emscripten build of DALi detecting build errors" into...
[platform/core/uifw/dali-adaptor.git] / text / dali / devel-api / text-abstraction / font-client.h
1 #ifndef __DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H__
2 #define __DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H__
3
4 /*
5  * Copyright (c) 2015 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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/images/buffer-image.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/devel-api/text-abstraction/font-list.h>
26 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
27
28 namespace Dali
29 {
30
31 namespace TextAbstraction
32 {
33
34 struct FontMetrics;
35 struct GlyphInfo;
36
37 namespace Internal DALI_INTERNAL
38 {
39 class FontClient;
40 }
41
42 /**
43  * @brief FontClient provides access to font information and resources.
44  *
45  * <h3>Querying the System Fonts</h3>
46  *
47  * A "system font" is described by a "path" to a font file on the native filesystem, along with a "family" and "style".
48  * For example on the Ubuntu system a "Regular" style font from the "Ubuntu Mono" family can be accessed from "/usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf".
49  *
50  * <h3>Accessing Fonts</h3>
51  *
52  * A "font" is created from the system for a specific point size in 26.6 fractional points. A "FontId" is used to identify each font.
53  * For example two different fonts with point sizes 10 & 12 can be created from the "Ubuntu Mono" family:
54  * @code
55  * FontClient fontClient   = FontClient::Get();
56  * FontId ubuntuMonoTen    = fontClient.GetFontId( "/usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf", 10*64 );
57  * FontId ubuntuMonoTwelve = fontClient.GetFontId( "/usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf", 12*64 );
58  * @endcode
59  * Glyph metrics and bitmap resources can then be retrieved using the FontId.
60  */
61 class DALI_IMPORT_API FontClient : public BaseHandle
62 {
63 public:
64   static const PointSize26Dot6 DEFAULT_POINT_SIZE; ///< The default point size.
65
66 public:
67
68   /**
69    * @brief Retrieve a handle to the FontClient instance.
70    *
71    * @return A handle to the FontClient
72    */
73   static FontClient Get();
74
75   /**
76    * @brief Create an uninitialized TextAbstraction handle.
77    */
78   FontClient();
79
80   /**
81    * @brief Destructor
82    *
83    * This is non-virtual since derived Handle types must not contain data or virtual methods.
84    */
85   ~FontClient();
86
87   /**
88    * @brief This copy constructor is required for (smart) pointer semantics.
89    *
90    * @param[in] handle A reference to the copied handle.
91    */
92   FontClient( const FontClient& handle );
93
94   /**
95    * @brief This assignment operator is required for (smart) pointer semantics.
96    *
97    * @param [in] handle  A reference to the copied handle.
98    * @return A reference to this.
99    */
100   FontClient& operator=( const FontClient& handle );
101
102   ////////////////////////////////////////
103   // Font management and validation.
104   ////////////////////////////////////////
105
106   /**
107    * @brief Set the DPI of the target window.
108    *
109    * @note Multiple windows are not currently supported.
110    * @param[in] horizontalDpi The horizontal resolution in DPI.
111    * @param[in] verticalDpi The vertical resolution in DPI.
112    */
113   void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
114
115   /**
116    * @brief Retrieves the DPI previously set to the target window.
117    *
118    * @note Multiple windows are not currently supported.
119    * @param[out] horizontalDpi The horizontal resolution in DPI.
120    * @param[out] verticalDpi The vertical resolution in DPI.
121    */
122   void GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi );
123
124   /**
125    * @brief Called when the user changes the system defaults.
126    *
127    * @post Previously cached system defaults are removed.
128    */
129   void ResetSystemDefaults();
130
131   /**
132    * @brief Retrieve the list of default fonts supported by the system.
133    *
134    * @param[out] defaultFonts A list of default font paths, family & style strings.
135    */
136   void GetDefaultFonts( FontList& defaultFonts );
137
138   /**
139    * @brief Retrieve the active default font from the system
140    *
141    * @param[out] fontDescription font structure describing the default font
142    */
143   void GetDefaultPlatformFontDescription( FontDescription& fontDescription );
144
145   /**
146    * @brief Retrieve the list of fonts supported by the system.
147    *
148    * @param[out] systemFonts A list of font paths, family & style strings.
149    */
150   void GetSystemFonts( FontList& systemFonts );
151
152   /**
153    * @brief Retrieves the font description of a given font @p id.
154    *
155    * @param[in] id The font id.
156    * @param[out] fontDescription The path, family & style describing the font.
157    */
158   void GetDescription( FontId id, FontDescription& fontDescription );
159
160   /**
161    * @brief Retrieves the font point size of a given font @p id.
162    *
163    * @param[in] id The font id.
164    *
165    * @return The point size in 26.6 fractional points.
166    */
167   PointSize26Dot6 GetPointSize( FontId id );
168
169   /**
170    * @brief Find the default font for displaying a UTF-32 character.
171    *
172    * This is useful when localised strings are provided for multiple languages
173    * i.e. when a single default font does not work for all languages.
174    * @param[in] charcode The character for which a font is needed.
175    * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
176    * @param[in] preferColor True if a color font is preferred.
177    * @return A valid font ID, or zero if the font does not exist.
178    */
179   FontId FindDefaultFont( Character charcode,
180                           PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE,
181                           bool preferColor = false );
182
183   /**
184    * @brief Find a fallback-font for displaying a UTF-32 character.
185    *
186    * This is useful when localised strings are provided for multiple languages
187    * i.e. when a single default font does not work for all languages.
188    * @param[in] preferredFont The preferred font which may not provide a glyph for charcode.
189    * The fallback-font will be the closest match to preferredFont, which does support the required glyph.
190    * @param[in] charcode The character for which a font is needed.
191    * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
192    * @param[in] preferColor True if a color font is preferred.
193    * @return A valid font ID, or zero if the font does not exist.
194    */
195   FontId FindFallbackFont( FontId preferredFont,
196                            Character charcode,
197                            PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE,
198                            bool preferColor = false );
199
200   /**
201    * @brief Retrieve the unique identifier for a font.
202    *
203    * @param[in] path The path to a font file.
204    * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
205    * @param[in] faceIndex The index of the font face (optional).
206    * @return A valid font ID, or zero if the font does not exist.
207    */
208   FontId GetFontId( const FontPath& path,
209                     PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE,
210                     FaceIndex faceIndex = 0 );
211
212   /**
213    * @brief Retrieve the unique identifier for a font.
214    *
215    * @note It the font style is not empty, it will be used instead the font weight and font slant slant.
216    *
217    * @param[in] fontDescription A font description.
218    * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
219    * @param[in] faceIndex The index of the font face (optional).
220    * @return A valid font ID, or zero if the font does not exist.
221    */
222   FontId GetFontId( const FontDescription& fontDescription,
223                     PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE,
224                     FaceIndex faceIndex = 0 );
225
226   /**
227    * @brief Check to see if a font is scalable.
228    *
229    * @param[in] path The path to a font file.
230    * @return true if scalable.
231    */
232   bool IsScalable( const FontPath& path );
233
234   /**
235    * @brief Check to see if a font is scalable.
236    *
237    * @note It the font style is not empty, it will be used instead the font weight and font slant slant.
238    *
239    * @param[in] fontDescription A font description.
240    *
241    * @return true if scalable
242    */
243   bool IsScalable( const FontDescription& fontDescription );
244
245   /**
246    * @brief Get a list of sizes available for a fixed size font.
247    *
248    * @param[in] path The path to a font file.
249    * @param[out] sizes A list of the available sizes, if no sizes available will return empty.
250    */
251   void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
252
253   /**
254    * @brief Get a list of sizes available for a fixed size font.
255    *
256    * @note It the font style is not empty, it will be used instead the font weight and font slant slant.
257    *
258    * @param[in] fontDescription A font description.
259    * @param[out] sizes A list of the available sizes, if no sizes available will return empty.
260    */
261   void GetFixedSizes( const FontDescription& fontDescription,
262                       Dali::Vector< PointSize26Dot6 >& sizes );
263
264   ////////////////////////////////////////
265   // Font metrics, glyphs and bitmaps.
266   ////////////////////////////////////////
267
268   /**
269    * @brief Query the metrics for a font.
270    *
271    * @param[in] fontId The ID of the font for the required glyph.
272    * @param[out] metrics The font metrics.
273    * @param[in] desiredFixedSize The metrics for fixed-size fonts will be scaled to this desired size (in pixels).
274    */
275   void GetFontMetrics( FontId fontId, FontMetrics& metrics, int desiredFixedSize = 0 );
276
277   /**
278    * @brief Retrieve the glyph index for a UTF-32 character code.
279    *
280    * @param[in] fontId The ID of the font for the required glyph.
281    * @param[in] charcode The UTF-32 character code.
282    * @return The glyph index, or zero if the character code is undefined.
283    */
284   GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
285
286   /**
287    * @brief Retrieve the metrics for a series of glyphs.
288    *
289    * @param[in,out] array An array of glyph-info structures with initialized FontId & GlyphIndex values.
290    * It may contain the advance and an offset set into the bearing from the shaping tool.
291    * On return, the glyph's size value will be initialized. The bearing value will be updated by adding the font's glyph bearing to the one set by the shaping tool.
292    * @param[in] size The size of the array.
293    * @param[in] type The type of glyphs used for rendering; either bitmaps or vectors.
294    * @param[in] horizontal True for horizontal layouts (set to false for vertical layouting).
295    * @param[in] desiredFixedSize The metrics for fixed-size fonts will be scaled to this desired size (in pixels).
296    * @return True if all of the requested metrics were found.
297    */
298   bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal = true, int desiredFixedSize = 0 );
299
300   /**
301    * @brief Create a bitmap representation of a glyph.
302    *
303    * @param[in] fontId The ID of the font.
304    * @param[in] glyphIndex The index of a glyph within the specified font.
305    * @return A valid BufferImage, or an empty handle if the glyph could not be rendered.
306    */
307   BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
308
309   /**
310    * @brief Create a vector representation of a glyph.
311    *
312    * @note This feature requires highp shader support and is not available on all platforms
313    * @param[in] fontId The ID of the font.
314    * @param[in] glyphIndex The index of a glyph within the specified font.
315    * @param[out] blob A blob of data; this is owned by FontClient and should be copied by the caller of CreateVectorData().
316    * @param[out] blobLength The length of the blob data, or zero if the blob creation failed.
317    * @param[out] nominalWidth The width of the blob.
318    * @param[out] nominalHeight The height of the blob.
319    */
320   void CreateVectorBlob( FontId fontId,
321                          GlyphIndex glyphIndex,
322                          VectorBlob*& blob,
323                          unsigned int& blobLength,
324                          unsigned int& nominalWidth,
325                          unsigned int& nominalHeight );
326
327   /**
328    * @brief Retrieves the ellipsis glyph for a requested point size.
329    *
330    * @param[in] pointSize The requested point size.
331    *
332    * @return The ellipsis glyph.
333    */
334   const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 pointSize );
335
336 public: // Not intended for application developers
337   /**
338    * @brief This constructor is used by FontClient::Get().
339    *
340    * @param[in] fontClient  A pointer to the internal fontClient object.
341    */
342   explicit DALI_INTERNAL FontClient( Internal::FontClient* fontClient );
343 };
344
345 } // namespace TextAbstraction
346
347 } // namespace Dali
348
349 #endif // __DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H__