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