2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 * @brief This is the header file for the %Font class.
22 * This header file contains the declarations of the %Font class.
29 #include <FBaseObject.h>
30 #include <FGrpDimension.h>
31 #include <FGrpFontCommon.h>
33 namespace Tizen { namespace Graphics
37 * @brief This class provides methods to retrieve the font information.
41 * @final This class is not intended for extension.
43 * The %Font class encapsulates the characteristics, such as the size and style of a specific vector font.
44 * Fonts are used to draw text on a Canvas.
46 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/graphics/fonts.htm">Fonts</a>.
50 class _OSP_EXPORT_ Font
51 : public Tizen::Base::Object
55 * This is the default constructor for this class.
59 * @remarks After creating an instance of this class, one of the
60 * Construct() methods must be called explicitly to initialize this instance.
65 * This is the destructor for this class.
72 * Initializes this instance of %Font with the specified size and style. @n
73 * If the size and style are not specified, the default system font is set.
77 * @return An error code
78 * @param[in] style The font style @n
79 * For more information, see Tizen::Graphics::FontStyle.
80 * @param[in] size The font size in pixels @n
81 * The size must be greater than @c 0.
82 * @exception E_SUCCESS The method is successful.
83 * @exception E_INVALID_ARG A specified input parameter is invalid.
85 result Construct(int style, int size);
88 * Initializes this instance of %Font with the specified parameters.
91 * @brief <i> [Compatibility] </i>
95 * @compatibility This method has compatibility issues with OSP compatible applications. @n
96 * For more information, see @ref CompIoPathPage "IoPath" and @ref CompFontConstructPage "FontConstructor" issues.
98 * @return An error code
99 * @param[in] fontNameOrPath The local file path of a font-resource file or app font name or system font name @n
100 * The app font name is retrieved using GetFaceName(Osp::Base::String& filepath).
101 * The system font name is retrieved using GetSystemFontListN().
102 * @param[in] style The font style @n
103 * Multiple styles can be combined using the bitwise OR operator.
104 * @param[in] size The font size in pixels @n
105 * The size must be greater than @c 0.
106 * @exception E_SUCCESS The method is successful.
107 * @exception E_INVALID_ARG A specified input parameter is invalid.
108 * @exception E_FILE_NOT_FOUND The specified font cannot be found or accessed.
109 * @exception E_UNSUPPORTED_FORMAT The specified font format is not supported.
110 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
111 * @remarks Only TrueType font is supported.
112 * The value of fontNameOrPath is considered system font name if it matches one of the retrieved values using GetSystemFontListN().
113 * If not, it is considered local file path of a font-resource file.
115 result Construct(const Tizen::Base::String& fontNameOrPath, int style, int size);
119 * @page CompFontConstructPage Compatibility for Construct().
120 * @section CompFontConstructPageIssueSection Issues
121 * Implementing this method in OSP compatible applications has the following issues: @n
122 * -# In OSP, the value of 1 st parameter(fontNameOrPath) can be system font name or local font path. At first, it is compared to the retrieved values using GetSystemFontListN(). If the matched value is exist, it is considered system font name. Or, it is considered local file path of a font-resource file.
123 * -# In Tizen, the value of 1 st parameter(fontNameOrPath) can be app font name or system font name or local font path. At first, it is compared to the font face names in app font resource folder. If the matched value is exist, it is considered app font name. Or, it is considered system font name if it matches one of the retrieved values using GetSystemFontListN().
128 * Initializes this instance of %Font with the specified parameters.
132 * @return An error code
133 * @param[in] fontData The font data
134 * @param[in] style The font style @n
135 * Multiple styles can be combined using the bitwise OR operator.
136 * @param[in] size The font size in pixels @n
137 * The size must be greater than @c 0.
138 * @exception E_SUCCESS The method is successful.
139 * @exception E_INVALID_ARG A specified input parameter is invalid.
140 * @exception E_UNSUPPORTED_FORMAT The specified font format is not supported.
141 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
143 result Construct(const Tizen::Base::ByteBuffer& fontData, int style, int size);
146 * Gets the maximum height of the current instance of %Font.
150 * @return The maximum height of the current instance of %Font, @n
151 * else @c -1 if the method fails
153 int GetMaxHeight(void) const;
156 * Gets the maximum width of the current instance of %Font.
160 * @return The maximum width of the current instance of %Font, @n
161 * else @c -1 if the method fails
163 int GetMaxWidth(void) const;
166 * Gets the ascender of the current instance of %Font.
170 * @return The ascender of the current instance of %Font, @n
171 * else @c -1 if the method fails
173 int GetAscender(void) const;
176 * Gets the descender of the current instance of %Font.
180 * @return The descender of the current instance of %Font, @n
181 * else @c -1 if the method fails
183 int GetDescender(void) const;
186 * Gets the left bear of a character.
190 * @return An error code
191 * @param[in] character A character for getting left bear
192 * @param[out] leftBear The left bear of the specified @c character
193 * @exception E_SUCCESS The method is successful.
194 * @exception E_DATA_NOT_FOUND The requested data does not exist.
196 result GetLeftBear(wchar_t character, int& leftBear) const;
199 * Gets the right bear of a character.
203 * @return An error code
204 * @param[in] character A character for getting the right bear
205 * @param[out] rightBear The right bear of the specified @c character
206 * @exception E_SUCCESS The method is successful.
207 * @exception E_DATA_NOT_FOUND The requested data does not exist.
209 result GetRightBear(wchar_t character, int& rightBear) const;
212 * Gets the width and height of the font used in the specified text. @n
213 * This method retrieves the font dimension of the text.
216 * @brief <i> [Compatibility] </i>
220 * @compatibility This method has compatibility issues with OSP compatible applications. @n
221 * For more information, see the issue description for @ref CompFontGetTextExtentPage "here".
224 * @return An error code
225 * @param[in] text The string
226 * @param[in] length The length of @c text @n
227 * The length must be greater than or equal to @c 0.
228 * @param[out] dim The width and height of the font of the @c text
229 * @exception E_SUCCESS The method is successful.
230 * @exception E_OUT_OF_RANGE The value of @c length is greater than the actual length of @c text.
232 result GetTextExtent(const Tizen::Base::String& text, int length, Dimension& dim) const;
236 * @page CompFontGetTextExtentPage Compatibility for the file path.
237 * @section CompFontGetTextExtentPageIssueSection Issues
238 * Implementing this method in OSP compatible applications has the following issues: @n
239 * -# The method returns exact height only if the font resource is designed to fit inside the emBox. @n
241 * @section CompFontGetTextExtentPageSolutionSection Resolutions
242 * This issue has been resolved in Tizen. @n
243 * -# The method returns exact height regardless of font design. @n
249 * Checks whether the font style of the current instance is bold.
253 * @return @c true if the font style of the current instance is bold, @n
256 bool IsBold(void) const;
259 * Checks whether the font style for the current instance is italics.
263 * @return @c true if the font style for the current instance is italics, @n
266 bool IsItalic(void) const;
269 * Checks whether the current instance has any style defined.
273 * @return @c true if an extra style is not defined for the current instance, @n
276 bool IsPlain(void) const;
279 * Checks whether the current instance has the strikeout style set.
283 * @return @c true if the current instance has the strikeout style set, @n
286 bool IsStrikeOut(void) const;
289 * Checks whether the current instance has the underline style set.
293 * @return @c true if the current instance has the underline style set, @n
296 bool IsUnderlined(void) const;
299 * Gets the font size of the current instance of %Font.
303 * @return The font size, @n
304 * else @c -1 if the method fails
306 int GetSize(void) const;
309 * Sets the strikeout style for the current instance of %Font.
313 * @param[in] strikeOut Set to @c true to use the strikeout style for the current instance of %Font, @n
316 void SetStrikeOut(bool strikeOut);
319 * Sets the underline style for the current instance of %Font.
323 * @param[in] underline Set to @c true to use the underline style for the current instance of %Font, @n
326 void SetUnderline(bool underline);
329 * Gets the system font list.
333 * @return The list of system fonts @n
334 * The font list consists of Tizen::Base::String items.
335 * @remarks After using the system font list, you can call IList::RemoveAll(true) to clean up string items in the list.
337 static Tizen::Base::Collection::IList* GetSystemFontListN(void);
340 * Gets the face name of the font file of the specific path.
344 * @return The face name of the font file of the specific path
345 * @param[in] filePath The path of the font file
347 static Tizen::Base::String GetFaceName(const Tizen::Base::String& filePath);
350 * Sets the character space.
354 * @param[in] space A character space
356 void SetCharSpace(int space);
359 * Gets the character space.
363 * @return The character space of this font instance, @n
364 * else @c -1 if the method fails
366 int GetCharSpace(void) const;
369 * Gets the face name.
373 * @return The face name of this font instance
375 Tizen::Base::String GetFaceName(void) const;
378 friend class _FontImpl;
381 // This method is for internal use only. Using this method can cause behavioral, security-related,
382 // and consistency-related issues in the application.
387 class _FontImpl* __pImpl;
390 * This is the copy constructor for the Font class.
392 * @remarks Do not use this constructor.
394 Font(const Font& rhs);
395 Font& operator =(const Font& rhs);
399 }} // Tizen::Graphics
401 #endif //_FGRP_FONT_H_