1 #ifndef __DALI_FONT_H__
2 #define __DALI_FONT_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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
11 // http://floralicense.org/license/
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.
21 * @addtogroup CAPI_DALI_TEXT_MODULE
26 #include <dali/public-api/object/base-handle.h>
27 #include <dali/public-api/text/font-parameters.h>
28 #include <dali/public-api/text/text.h>
30 namespace Dali DALI_IMPORT_API
35 namespace Internal DALI_INTERNAL
41 * @brief Encapsulates a font resource.
42 * Fonts are managed by the font manager, which loads any new fonts requested by applications. The font
43 * manager keeps a cache of the most recently used fonts, and if a new font is requested when the cache
44 * is full it will delete an old one (if there is one not in use).
45 * This font class will request a font from the font manager in a manner which is not visible to the
48 * Fonts will be created from a font name (like courier or comic) and font size (specified in points).
50 class Font : public BaseHandle
54 * @brief Stores glyph's metrics.
57 * <li>\e Advance. The distance between the glyph's current pen position and the pen's position of the next glyph.
58 * <li>\e Bearing. The horizontal top side bearing. Is the distance between the baseline and the top of the glyph.
59 * <li>\e Width. The glyph's width.
60 * <li>\e Height. The glyph's height.
67 * @brief Default constructor.
69 * Creates the implentation instance.
76 * Destroyes the implementaiton instance.
81 * @brief Copy constructor.
83 * @param [in] metrics Metrics to be copied.
85 Metrics( const Metrics& metrics );
88 * @brief Assignment operator.
90 * @param [in] metrics Metrics to be assigned.
91 * @return a reference to this
93 Metrics& operator=( const Metrics& metrics );
96 * @brief Retrieves the advance metric.
98 * @return the advance metric.
100 float GetAdvance() const;
103 * @brief Retrieves the bearing metric.
105 * @return the bearing metric.
107 float GetBearing() const;
110 * @brief Retrieves the width metric.
112 * @return the width metric.
114 float GetWidth() const;
117 * @brief Retrieves the height metric.
119 * @return the height metric.
121 float GetHeight() const;
123 public: // Not intended for application developers
127 * @brief Constructor.
129 * Initialization with metrics data.
130 * @param implementation Glyph's metrics.
132 Metrics( const Impl& implementation );
135 Impl* mImpl; ///< Implementation.
140 * @brief Create an empty Font.
142 * This can be initialised with Font::New(...)
147 * @brief Create an initialised Font with the given parameters. If no parameters are given, system defaults are used.
149 * @param [in] fontParameters The font parameters.
150 * @return A handle to a newly allocated font.
152 static Font New( const FontParameters& fontParameters = DEFAULT_FONT_PARAMETERS );
155 * @brief Downcast an Object handle to Font handle.
157 * If handle points to a Font object the downcast produces valid
158 * handle. If not the returned handle is left uninitialized.
160 * @param[in] handle to An object
161 * @return handle to a Font object or an uninitialized handle
163 static Font DownCast( BaseHandle handle );
166 * @brief Try to detect font for text.
168 * @param [in] text displayed text
169 * @return string containing a font name, or an empty string.
171 static const std::string GetFamilyForText(const std::string& text);
174 * @copydoc GetFamilyForText(const std::string& text)
176 static const std::string GetFamilyForText(const Text& text);
179 * @brief Try to detect font for character.
181 * @param [in] character displayed character
182 * @return string containing a font name, or an empty string.
184 static const std::string GetFamilyForText(const Character& character);
187 * @brief Virtual destructor.
189 * Dali::Object derived classes typically do not contain member data.
194 * @copydoc Dali::BaseHandle::operator=
196 using BaseHandle::operator=;
199 * @brief Convert a PixelSize from CapsHeight to it's equivalent LineHeight.
201 * @param [in] fontFamily The family's name of the font requested
202 * @param [in] fontStyle The style of the font requested.
203 * @param [in] capsHeight The size of the font ascenders required in pixels
204 * @return The equivalent LineHeight (baseline to baseline) for the font
206 static PixelSize GetLineHeightFromCapsHeight(const std::string& fontFamily, const std::string& fontStyle, const CapsHeight& capsHeight);
209 * @brief The mode for GetInstalledFonts()
213 LIST_SYSTEM_FONTS, ///< List system fonts
214 LIST_APPLICATION_FONTS, ///< List application fonts
215 LIST_ALL_FONTS ///< List all fonts
219 * @brief Gets the list of available fonts.
221 * @param mode which fonts to include in the list, default is LIST_SYSTEM_FONTS
222 * @return a list of font family names
224 static std::vector<std::string> GetInstalledFonts( FontListMode mode = LIST_SYSTEM_FONTS );
227 * @brief Returns the width of the area needed to display some text if the text is textHeightPx pixels high.
229 * Note that the text is not processed in any way before this calculation is performed (no stretching/scaling)
230 * @param [in] text The text to measure
231 * @param [in] textHeightPx The text height required
232 * @return The displayed width in pixels
234 float MeasureTextWidth(const std::string& text, float textHeightPx) const;
237 * @copydoc MeasureTextWidth(const std::string& text, float textHeightPx) const
239 float MeasureTextWidth(const Text& text, float textHeightPx) const;
242 * @brief Returns the width of the area needed to display the character if the text is textHeightPx pixels high.
244 * Note that the character is not processed in any way before this calculation is performed (no stretching/scaling)
245 * @param [in] character The character to measure
246 * @param [in] textHeightPx The text height required
247 * @return The displayed width in pixels
249 float MeasureTextWidth(const Character& character, float textHeightPx) const;
252 * @brief Returns the height of the area needed to display the text if the text is textWidthPx pixels wide.
254 * Note that the text is not processed in any way before this calculation is performed (no stretching/scaling)
255 * @param [in] text The text to measure
256 * @param [in] textWidthPx The text width required
257 * @return The displayed height in pixels
259 float MeasureTextHeight(const std::string& text, float textWidthPx) const;
262 * @copydoc MeasureTextHeight(const std::string& text, float textWidthPx) const
264 float MeasureTextHeight(const Text& text, float textWidthPx) const;
267 * @brief Returns the height of the area needed to display the character if the text is textWidthPx pixels wide.
269 * Note that the character is not processed in any way before this calculation is performed (no stretching/scaling)
270 * @param [in] character The character to measure
271 * @param [in] textWidthPx The text width required
272 * @return The displayed height in pixels
274 float MeasureTextHeight(const Character& character, float textWidthPx) const;
277 * @brief Measure the natural size of a text string, as displayed in this font.
279 * @param[in] text The text string to measure.
280 * @return The natural size of the text.
282 Vector3 MeasureText(const std::string& text) const;
285 * @copydoc MeasureText(const std::string& text) const
287 Vector3 MeasureText(const Text& text) const;
290 * @brief Measure the natural size of a character, as displayed in this font.
292 * @param[in] character The character to measure.
293 * @return The natural size of the character.
295 Vector3 MeasureText(const Character& character) const;
298 * @brief Tells whether text is supported with font.
300 * @param [in] text glyphs to test
301 * @return true if the glyphs are all supported by the font
303 bool AllGlyphsSupported(const std::string& text) const;
306 * @copydoc AllGlyphsSupported(const std::string& text) const
307 * @param [in] text glyphs to test
308 * @return true if the glyphs are all supported by the font
310 bool AllGlyphsSupported(const Text& text) const;
313 * @brief Tells whether character is supported with font.
315 * @param [in] character The character to test
316 * @return true if the glyph is supported by the font
318 bool AllGlyphsSupported(const Character& character) const;
321 * @brief Retrieves the line height.
323 * The line height is the distance between two consecutive base lines.
324 * @return The line height.
326 float GetLineHeight() const;
329 * @brief Retrieves the ascender metric.
331 * The ascender metric is the distance between the base line and the top of the highest character in the font.
332 * @return The ascender metric.
334 float GetAscender() const;
337 * @brief Retrieves the underline's thickness.
340 * It includes the vertical pad adjust used to add effects like glow or shadow.
342 * @return The underline's thickness.
344 float GetUnderlineThickness() const;
347 * @brief Retrieves the underline's position.
350 * It includes the vertical pad adjust used to add effects like glow or shadow.
352 * @return The underline's position.
354 float GetUnderlinePosition() const;
357 * @brief Retrieves glyph metrics.
359 * @see Font::Metrics.
360 * @param [in] character The character which its metrics are going to be retrieved.
361 * @return The glyph metrics.
363 Metrics GetMetrics(const Character& character) const;
366 * @brief Retrieves whether this font was created with a default system font.
368 * @return \e true if this font was created as a default system font.
370 bool IsDefaultSystemFont() const;
373 * @brief Retrieves whether this font was created with a default system size.
375 * @return \e true if this font was created as a default system size.
377 bool IsDefaultSystemSize() const;
380 * @brief Gets the name of the font's family.
382 * @return The name of the font's family.
384 const std::string& GetName() const;
387 * @brief Gets the font's style.
389 * @return The font's style.
391 const std::string& GetStyle() const;
394 * @brief Return font size in points.
396 * @return size in points
398 float GetPointSize() const;
401 * @brief Return font size in pixels.
403 * @return size in pixels
405 unsigned int GetPixelSize() const;
408 * @brief Retrieves the size of the font in pixels from a given size in points.
410 * @param[in] pointSize Size of the font in points.
411 * @return size of the font in pixels.
413 static unsigned int PointsToPixels( float pointSize );
416 * @brief Retrieves the size of the font in points from a given size in pixels
417 * @param[in] pixelsSize Size of the font in pixels.
419 * @return size of the font in points.
421 static float PixelsToPoints( unsigned int pixelsSize );
423 public: // Not intended for application developers
426 * @brief This constructor is used by Dali New() methods
428 * @param [in] font A pointer to a newly allocated Dali resource
430 explicit DALI_INTERNAL Font(Internal::Font* font);
438 #endif // __DALI_FONT_H__