FontClient interface amendments
[platform/core/uifw/dali-adaptor.git] / text / dali / public-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/object/base-handle.h>
23 #include <dali/public-api/images/bitmap-image.h>
24 #include <dali/public-api/text-abstraction/glyph-info.h>
25 #include <dali/public-api/text-abstraction/font-list.h>
26 #include <dali/public-api/text-abstraction/font-metrics.h>
27
28 namespace Dali
29 {
30
31 namespace TextAbstraction
32 {
33
34 namespace Internal DALI_INTERNAL
35 {
36 class FontClient;
37 }
38
39 /**
40  * @brief FontClient provides access to font information and resources.
41  *
42  * <h3>Querying the System Fonts</h3>
43  *
44  * A "system font" is described by a "path" to a font file on the native filesystem, along with a "family" and "style".
45  * 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".
46  *
47  * <h3>Accessing Fonts</h3>
48  *
49  * 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.
50  * For example two different fonts with point sizes 10 & 12 can be created from the "Ubuntu Mono" family:
51  * @code
52  * FontClient fontClient   = FontClient::Get();
53  * FontId ubuntuMonoTen    = fontClient.GetFontId( "/usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf", 10*64 );
54  * FontId ubuntuMonoTwelve = fontClient.GetFontId( "/usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf", 12*64 );
55  * @endcode
56  * Glyph metrics and bitmap resources can then be retrieved using the FontId.
57  */
58 class DALI_IMPORT_API FontClient : public BaseHandle
59 {
60 public:
61   static const PointSize26Dot6 DEFAULT_POINT_SIZE; ///< The default point size.
62
63 public:
64
65   /**
66    * @brief Retrieve a handle to the FontClient instance.
67    *
68    * @return A handle to the FontClient
69    */
70   static FontClient Get();
71
72   /**
73    * @brief Create an uninitialized TextAbstraction handle.
74    */
75   FontClient();
76
77   /**
78    * @brief Destructor
79    *
80    * This is non-virtual since derived Handle types must not contain data or virtual methods.
81    */
82   ~FontClient();
83
84   /**
85    * @brief This copy constructor is required for (smart) pointer semantics.
86    *
87    * @param[in] handle A reference to the copied handle.
88    */
89   FontClient( const FontClient& handle );
90
91   /**
92    * @brief This assignment operator is required for (smart) pointer semantics.
93    *
94    * @param [in] handle  A reference to the copied handle.
95    * @return A reference to this.
96    */
97   FontClient& operator=( const FontClient& handle );
98
99   ////////////////////////////////////////
100   // Font management and validation.
101   ////////////////////////////////////////
102
103   /**
104    * @brief Set the DPI of the target window.
105    *
106    * @note Multiple windows are not currently supported.
107    * @param[in] horizontalDpi The horizontal resolution in DPI.
108    * @param[in] verticalDpi The vertical resolution in DPI.
109    */
110   void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
111
112   /**
113    * @brief Retrieve the list of fonts supported by the system.
114    *
115    * @param[out] systemFonts A list of font paths, family & style strings.
116    */
117   void GetSystemFonts( FontList& systemFonts );
118
119   /**
120    * @brief Retrieves the font description of a given font @p id.
121    *
122    * @param[in] id The font id.
123    * @param[out] fontDescription The path, family & style describing the font.
124    */
125   void GetDescription( FontId id, FontDescription& fontDescription );
126
127   /**
128    * @brief Retrieves the font point size of a given font @p id.
129    *
130    * @param[in] id The font id.
131    *
132    * @return The point size in 26.6 fractional points.
133    */
134   PointSize26Dot6 GetPointSize( FontId id );
135
136   /**
137    * @brief Find an appropriate font for displaying a UTF-32 character.
138    *
139    * This is useful when localised strings are provided for multiple languages
140    * i.e. when a single default font does not work for all languages.
141    * @param[in] charcode The character for which a font is needed.
142    * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
143    * @return A valid font ID, or zero if the font does not exist.
144    */
145   FontId FindDefaultFont( Character charcode,
146                           PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE );
147
148   /**
149    * @brief Retrieve the unique identifier for a font.
150    *
151    * @param[in] path The path to a font file.
152    * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
153    * @param[in] faceIndex The index of the font face (optional).
154    * @return A valid font ID, or zero if the font does not exist.
155    */
156   FontId GetFontId( const FontPath& path, PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE, FaceIndex faceIndex = 0 );
157
158   /**
159    * @brief Retrieve the unique identifier for a font.
160    *
161    * @param[in] fontFamily The font family name.
162    * @param[in] fontStyle  The font style.
163    * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
164    * @param[in] faceIndex The index of the font face (optional).
165    * @return A valid font ID, or zero if the font does not exist.
166    */
167   FontId GetFontId( const FontFamily& fontFamily,
168                     const FontStyle& fontStyle,
169                     PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE,
170                     FaceIndex faceIndex = 0 );
171
172   ////////////////////////////////////////
173   // Font metrics, glyphs and bitmaps.
174   ////////////////////////////////////////
175
176   /**
177    * @brief Query the metrics for a font.
178    *
179    * @param[in] fontId The ID of the font for the required glyph.
180    * @param[out] metrics The font metrics.
181    */
182   void GetFontMetrics( FontId fontId, FontMetrics& metrics );
183
184   /**
185    * @brief Retrieve the glyph index for a UTF-32 character code.
186    *
187    * @param[in] fontId The ID of the font for the required glyph.
188    * @param[in] charcode The UTF-32 character code.
189    * @return The glyph index, or zero if the character code is undefined.
190    */
191   GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
192
193   /**
194    * @brief Retrieve the metrics for a series of glyphs.
195    *
196    * @param[in,out] array An array of glyph-info structures with initialized FontId & GlyphIndex values.
197    * On return, the remaining metrics values will be initialized e.g. glyph size & bearing values.
198    * @param[in] size The size of the array.
199    * @param[in] horizontal True for horizontal layouts (set to false for vertical layouting).
200    * @return True if all of the requested metrics were found.
201    */
202   bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal = true );
203
204   /**
205    * @brief Render a bitmap representation of a glyph.
206    *
207    * @param[in] fontId The ID of the font.
208    * @param[in] glyphIndex The index of a glyph within the specified font.
209    * @return A valid BitmapImage, or an empty handle if the glyph could not be rendered.
210    */
211   BitmapImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
212
213 public: // Not intended for application developers
214   /**
215    * @brief This constructor is used by FontClient::Get().
216    *
217    * @param[in] fontClient  A pointer to the internal fontClient object.
218    */
219   explicit DALI_INTERNAL FontClient( Internal::FontClient* fontClient );
220 };
221
222 } // namespace TextAbstraction
223
224 } // namespace Dali
225
226 #endif // __DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H__