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/devel-api/images/pixel-data.h>
25 #include <dali/public-api/object/base-handle.h>
26 #include <dali/devel-api/text-abstraction/font-list.h>
27 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
32 namespace TextAbstraction
38 namespace Internal DALI_INTERNAL
44 * @brief FontClient provides access to font information and resources.
46 * <h3>Querying the System Fonts</h3>
48 * A "system font" is described by a "path" to a font file on the native filesystem, along with a "family" and "style".
49 * 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".
51 * <h3>Accessing Fonts</h3>
53 * 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.
54 * For example two different fonts with point sizes 10 & 12 can be created from the "Ubuntu Mono" family:
56 * FontClient fontClient = FontClient::Get();
57 * FontId ubuntuMonoTen = fontClient.GetFontId( "/usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf", 10*64 );
58 * FontId ubuntuMonoTwelve = fontClient.GetFontId( "/usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf", 12*64 );
60 * Glyph metrics and bitmap resources can then be retrieved using the FontId.
62 class DALI_IMPORT_API FontClient : public BaseHandle
65 static const PointSize26Dot6 DEFAULT_POINT_SIZE; ///< The default point size.
70 * @brief Retrieve a handle to the FontClient instance.
72 * @return A handle to the FontClient
74 static FontClient Get();
77 * @brief Create an uninitialized TextAbstraction handle.
84 * This is non-virtual since derived Handle types must not contain data or virtual methods.
89 * @brief This copy constructor is required for (smart) pointer semantics.
91 * @param[in] handle A reference to the copied handle.
93 FontClient( const FontClient& handle );
96 * @brief This assignment operator is required for (smart) pointer semantics.
98 * @param [in] handle A reference to the copied handle.
99 * @return A reference to this.
101 FontClient& operator=( const FontClient& handle );
103 ////////////////////////////////////////
104 // Font management and validation.
105 ////////////////////////////////////////
108 * @brief Set the DPI of the target window.
110 * @note Multiple windows are not currently supported.
111 * @param[in] horizontalDpi The horizontal resolution in DPI.
112 * @param[in] verticalDpi The vertical resolution in DPI.
114 void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
117 * @brief Retrieves the DPI previously set to the target window.
119 * @note Multiple windows are not currently supported.
120 * @param[out] horizontalDpi The horizontal resolution in DPI.
121 * @param[out] verticalDpi The vertical resolution in DPI.
123 void GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi );
126 * @brief Called when the user changes the system defaults.
128 * @post Previously cached system defaults are removed.
130 void ResetSystemDefaults();
133 * @brief Retrieve the list of default fonts supported by the system.
135 * @param[out] defaultFonts A list of default font paths, family & style strings.
137 void GetDefaultFonts( FontList& defaultFonts );
140 * @brief Retrieve the active default font from the system
142 * @param[out] fontDescription font structure describing the default font
144 void GetDefaultPlatformFontDescription( FontDescription& fontDescription );
147 * @brief Retrieve the list of fonts supported by the system.
149 * @param[out] systemFonts A list of font paths, family & style strings.
151 void GetSystemFonts( FontList& systemFonts );
154 * @brief Retrieves the font description of a given font @p id.
156 * @param[in] id The font id.
157 * @param[out] fontDescription The path, family & style describing the font.
159 void GetDescription( FontId id, FontDescription& fontDescription );
162 * @brief Retrieves the font point size of a given font @p id.
164 * @param[in] id The font id.
166 * @return The point size in 26.6 fractional points.
168 PointSize26Dot6 GetPointSize( FontId id );
171 * @brief Find the default font for displaying a UTF-32 character.
173 * This is useful when localised strings are provided for multiple languages
174 * i.e. when a single default font does not work for all languages.
175 * @param[in] charcode The character for which a font is needed.
176 * @param[in] requestedPointSize The point size in 26.6 fractional points; the default point size is 12*64.
177 * @param[in] preferColor True if a color font is preferred.
178 * @return A valid font ID, or zero if the font does not exist.
180 FontId FindDefaultFont( Character charcode,
181 PointSize26Dot6 requestedPointSize = DEFAULT_POINT_SIZE,
182 bool preferColor = false );
185 * @brief Find a fallback-font for displaying a UTF-32 character.
187 * This is useful when localised strings are provided for multiple languages
188 * i.e. when a single default font does not work for all languages.
189 * @param[in] preferredFont The preferred font which may not provide a glyph for charcode.
190 * The fallback-font will be the closest match to preferredFont, which does support the required glyph.
191 * @param[in] charcode The character for which a font is needed.
192 * @param[in] requestedPointSize The point size in 26.6 fractional points; the default point size is 12*64.
193 * @param[in] preferColor True if a color font is preferred.
194 * @return A valid font ID, or zero if the font does not exist.
196 FontId FindFallbackFont( FontId preferredFont,
198 PointSize26Dot6 requestedPointSize = DEFAULT_POINT_SIZE,
199 bool preferColor = false );
202 * @brief Retrieve the unique identifier for a font.
204 * @param[in] path The path to a font file.
205 * @param[in] requestedPointSize The point size in 26.6 fractional points; the default point size is 12*64.
206 * @param[in] faceIndex The index of the font face (optional).
207 * @return A valid font ID, or zero if the font does not exist.
209 FontId GetFontId( const FontPath& path,
210 PointSize26Dot6 requestedPointSize = DEFAULT_POINT_SIZE,
211 FaceIndex faceIndex = 0 );
214 * @brief Retrieve the unique identifier for a font.
216 * @note It the font style is not empty, it will be used instead the font weight and font slant slant.
218 * @param[in] fontDescription A font description.
219 * @param[in] requestedPointSize The point size in 26.6 fractional points; the default point size is 12*64.
220 * @param[in] faceIndex The index of the font face (optional).
221 * @return A valid font ID, or zero if the font does not exist.
223 FontId GetFontId( const FontDescription& fontDescription,
224 PointSize26Dot6 requestedPointSize = DEFAULT_POINT_SIZE,
225 FaceIndex faceIndex = 0 );
228 * @brief Check to see if a font is scalable.
230 * @param[in] path The path to a font file.
231 * @return true if scalable.
233 bool IsScalable( const FontPath& path );
236 * @brief Check to see if a font is scalable.
238 * @note It the font style is not empty, it will be used instead the font weight and font slant slant.
240 * @param[in] fontDescription A font description.
242 * @return true if scalable
244 bool IsScalable( const FontDescription& fontDescription );
247 * @brief Get a list of sizes available for a fixed size font.
249 * @param[in] path The path to a font file.
250 * @param[out] sizes A list of the available sizes, if no sizes available will return empty.
252 void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
255 * @brief Get a list of sizes available for a fixed size font.
257 * @note It the font style is not empty, it will be used instead the font weight and font slant slant.
259 * @param[in] fontDescription A font description.
260 * @param[out] sizes A list of the available sizes, if no sizes available will return empty.
262 void GetFixedSizes( const FontDescription& fontDescription,
263 Dali::Vector< PointSize26Dot6 >& sizes );
265 ////////////////////////////////////////
266 // Font metrics, glyphs and bitmaps.
267 ////////////////////////////////////////
270 * @brief Query the metrics for a font.
272 * @param[in] fontId The ID of the font for the required glyph.
273 * @param[out] metrics The font metrics.
275 void GetFontMetrics( FontId fontId, FontMetrics& metrics );
278 * @brief Retrieve the glyph index for a UTF-32 character code.
280 * @param[in] fontId The ID of the font for the required glyph.
281 * @param[in] charcode The UTF-32 character code.
282 * @return The glyph index, or zero if the character code is undefined.
284 GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
287 * @brief Retrieve the metrics for a series of glyphs.
289 * @param[in,out] array An array of glyph-info structures with initialized FontId & GlyphIndex values.
290 * It may contain the advance and an offset set into the bearing from the shaping tool.
291 * 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.
292 * @param[in] size The size of the array.
293 * @param[in] type The type of glyphs used for rendering; either bitmaps or vectors.
294 * @param[in] horizontal True for horizontal layouts (set to false for vertical layouting).
295 * @return True if all of the requested metrics were found.
297 bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal = true );
300 * @brief Create a bitmap representation of a glyph.
302 * @param[in] fontId The ID of the font.
303 * @param[in] glyphIndex The index of a glyph within the specified font.
304 * @return A valid BufferImage, or an empty handle if the glyph could not be rendered.
306 PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
309 * @brief Create a vector representation of a glyph.
311 * @note This feature requires highp shader support and is not available on all platforms
312 * @param[in] fontId The ID of the font.
313 * @param[in] glyphIndex The index of a glyph within the specified font.
314 * @param[out] blob A blob of data; this is owned by FontClient and should be copied by the caller of CreateVectorData().
315 * @param[out] blobLength The length of the blob data, or zero if the blob creation failed.
316 * @param[out] nominalWidth The width of the blob.
317 * @param[out] nominalHeight The height of the blob.
319 void CreateVectorBlob( FontId fontId,
320 GlyphIndex glyphIndex,
322 unsigned int& blobLength,
323 unsigned int& nominalWidth,
324 unsigned int& nominalHeight );
327 * @brief Retrieves the ellipsis glyph for a requested point size.
329 * @param[in] requestedPointSize The requested point size.
331 * @return The ellipsis glyph.
333 const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 requestedPointSize );
335 public: // Not intended for application developers
337 * @brief This constructor is used by FontClient::Get().
339 * @param[in] fontClient A pointer to the internal fontClient object.
341 explicit DALI_INTERNAL FontClient( Internal::FontClient* fontClient );
344 } // namespace TextAbstraction
348 #endif // __DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H__