1 #ifndef __DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H__
2 #define __DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
31 namespace TextAbstraction
37 namespace Internal DALI_INTERNAL
43 * @brief FontClient provides access to font information and resources.
45 * <h3>Querying the System Fonts</h3>
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".
50 * <h3>Accessing Fonts</h3>
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:
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 );
59 * Glyph metrics and bitmap resources can then be retrieved using the FontId.
61 class DALI_IMPORT_API FontClient : public BaseHandle
64 static const PointSize26Dot6 DEFAULT_POINT_SIZE; ///< The default point size.
69 * @brief Retrieve a handle to the FontClient instance.
71 * @return A handle to the FontClient
73 static FontClient Get();
76 * @brief Create an uninitialized TextAbstraction handle.
83 * This is non-virtual since derived Handle types must not contain data or virtual methods.
88 * @brief This copy constructor is required for (smart) pointer semantics.
90 * @param[in] handle A reference to the copied handle.
92 FontClient( const FontClient& handle );
95 * @brief This assignment operator is required for (smart) pointer semantics.
97 * @param [in] handle A reference to the copied handle.
98 * @return A reference to this.
100 FontClient& operator=( const FontClient& handle );
102 ////////////////////////////////////////
103 // Font management and validation.
104 ////////////////////////////////////////
107 * @brief Set the DPI of the target window.
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.
113 void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
116 * @brief Retrieves the DPI previously set to the target window.
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.
122 void GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi );
125 * Set the default font family and its style that should be used by the font client.
127 * @param[in] fontFamilyName The default name of the font's family.
128 * @param[in] fontStyle The default font's style.
130 void SetDefaultFontFamily( const std::string& fontFamilyName,
131 const std::string& fontStyle );
134 * @brief Retrieve the list of default fonts supported by the system.
136 * @param[out] defaultFonts A list of default font paths, family & style strings.
138 void GetDefaultFonts( FontList& defaultFonts );
141 * @brief Retrieve the list of fonts supported by the system.
143 * @param[out] systemFonts A list of font paths, family & style strings.
145 void GetSystemFonts( FontList& systemFonts );
148 * @brief Retrieves the font description of a given font @p id.
150 * @param[in] id The font id.
151 * @param[out] fontDescription The path, family & style describing the font.
153 void GetDescription( FontId id, FontDescription& fontDescription );
156 * @brief Retrieves the font point size of a given font @p id.
158 * @param[in] id The font id.
160 * @return The point size in 26.6 fractional points.
162 PointSize26Dot6 GetPointSize( FontId id );
165 * @brief Find an appropriate font for displaying a UTF-32 character.
167 * This is useful when localised strings are provided for multiple languages
168 * i.e. when a single default font does not work for all languages.
169 * @param[in] charcode The character for which a font is needed.
170 * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
171 * @param[in] preferColor True if a color font is preferred.
172 * @return A valid font ID, or zero if the font does not exist.
174 FontId FindDefaultFont( Character charcode,
175 PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE,
176 bool preferColor = false );
179 * @brief Retrieve the unique identifier for a font.
181 * @param[in] path The path to a font file.
182 * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
183 * @param[in] faceIndex The index of the font face (optional).
184 * @return A valid font ID, or zero if the font does not exist.
186 FontId GetFontId( const FontPath& path, PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE, FaceIndex faceIndex = 0 );
189 * @brief Retrieve the unique identifier for a font.
191 * @param[in] fontFamily The font family name.
192 * @param[in] fontStyle The font style.
193 * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
194 * @param[in] faceIndex The index of the font face (optional).
195 * @return A valid font ID, or zero if the font does not exist.
197 FontId GetFontId( const FontFamily& fontFamily,
198 const FontStyle& fontStyle,
199 PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE,
200 FaceIndex faceIndex = 0 );
203 * @brief Check to see if a font is scalable.
205 * @param[in] path The path to a font file.
206 * @return true if scalable.
208 bool IsScalable( const FontPath& path );
211 * @brief Check to see if a font is scalable.
213 * @param[in] fontFamily The font family name.
214 * @param[in] style The font style.
215 * @return true if scalable
217 bool IsScalable( const FontFamily& fontFamily, const FontStyle& style );
220 * @brief Get a list of sizes available for a fixed size font.
222 * @param[in] path The path to a font file.
223 * @param[out] sizes A list of the available sizes, if no sizes available will return empty.
225 void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
228 * @brief Get a list of sizes available for a fixed size font.
230 * @param[in] fontFamily The font family name.
231 * @param[in] style The font style.
232 * @param[out] sizes A list of the available sizes, if no sizes available will return empty.
234 void GetFixedSizes( const FontFamily& fontFamily,
235 const FontStyle& style,
236 Dali::Vector< PointSize26Dot6 >& sizes );
238 ////////////////////////////////////////
239 // Font metrics, glyphs and bitmaps.
240 ////////////////////////////////////////
243 * @brief Query the metrics for a font.
245 * @param[in] fontId The ID of the font for the required glyph.
246 * @param[out] metrics The font metrics.
247 * @param[in] maxFixedSize The metrics for fixed-size fonts will be down-scaled, when exceeding this maximum value in pixels.
249 void GetFontMetrics( FontId fontId, FontMetrics& metrics, int maxFixedSize = 0 );
252 * @brief Retrieve the glyph index for a UTF-32 character code.
254 * @param[in] fontId The ID of the font for the required glyph.
255 * @param[in] charcode The UTF-32 character code.
256 * @return The glyph index, or zero if the character code is undefined.
258 GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
261 * @brief Retrieve the metrics for a series of glyphs.
263 * @param[in,out] array An array of glyph-info structures with initialized FontId & GlyphIndex values.
264 * It may contain the advance and an offset set into the bearing from the shaping tool.
265 * 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.
266 * @param[in] size The size of the array.
267 * @param[in] horizontal True for horizontal layouts (set to false for vertical layouting).
268 * @param[in] maxFixedSize The metrics for fixed-size fonts will be down-scaled, when exceeding this maximum value in pixels.
269 * @return True if all of the requested metrics were found.
271 bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal = true, int maxFixedSize = 0 );
274 * @brief Render a bitmap representation of a glyph.
276 * @param[in] fontId The ID of the font.
277 * @param[in] glyphIndex The index of a glyph within the specified font.
278 * @return A valid BufferImage, or an empty handle if the glyph could not be rendered.
280 BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
283 * @brief Retrieves the ellipsis glyph for a requested point size.
285 * @param[in] pointSize The requested point size.
287 * @return The ellipsis glyph.
289 const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 pointSize );
291 public: // Not intended for application developers
293 * @brief This constructor is used by FontClient::Get().
295 * @param[in] fontClient A pointer to the internal fontClient object.
297 explicit DALI_INTERNAL FontClient( Internal::FontClient* fontClient );
300 } // namespace TextAbstraction
304 #endif // __DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H__