1 #ifndef __DALI_INTERNAL_FONT_H__
2 #define __DALI_INTERNAL_FONT_H__
5 * Copyright (c) 2014 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.
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/text/font.h>
27 #include <dali/public-api/object/base-object.h>
28 #include <dali/internal/event/text/font-metrics.h>
29 #include <dali/internal/common/text-vertex-buffer.h>
30 #include <dali/internal/event/text/text-observer.h>
31 #include <dali/internal/event/text/resource/glyph-texture-observer.h>
32 #include <dali/internal/event/text/atlas/glyph-atlas-manager-interface.h>
33 #include <dali/internal/common/message.h>
34 #include <dali/integration-api/text-array.h>
41 class PlatformAbstraction;
47 // Forward declarations.
54 * Responsible for loading and rendering fonts using the Freetype library.
56 class Font : public BaseObject
59 static const float MIN_FONT_POINT_SIZE; ///< Minimum font point size supported.
60 static const float MAX_FONT_POINT_SIZE; ///< Maximum font point size supported.
63 * Create a new font object using a font name and size
64 * @param [in] fontFamily The family's name of the font requested
65 * @param [in] fontStyle The style of the font requested
66 * @param [in] size size of the font in points.
67 * @return A newly allocated Font
69 static Font* New(const std::string& fontFamily, const std::string& fontStyle, float size);
74 * Two fonts are considered equal if they are created with the same family, style and size.
76 * @param[in] font The font to be compared.
78 * @return \e true if the given font is equal to current one, otherwise it returns \e false.
80 bool operator==( const Font& font ) const;
83 * @copydoc Dali::Font::GetFamilyForText()
85 static const std::string GetFamilyForText(const Integration::TextArray& text);
88 * @copydoc Dali::Font::GetLineHeightFromCapsHeight()
90 static PixelSize GetLineHeightFromCapsHeight(const std::string& fontFamily, const std::string& fontStyle, const CapsHeight& capsHeight);
93 * @copydoc Dali::Font::GetInstalledFonts()
95 static void GetInstalledFonts( Dali::Font::FontListMode mode, std::vector<std::string>& fontList );
98 * @copydoc Dali::Font::AllGlyphsSupported()
100 bool AllGlyphsSupported(const Integration::TextArray& text) const;
103 * returns the Id used for lookups
104 * @return the unique ID of the font. This is actually also the same as FontMetrics and FontAtlas Id.
106 unsigned int GetResourceId() const;
109 * @copydoc Dali::Font::MeasureTextWidth()
111 float MeasureTextWidth(const Integration::TextArray& text, float textHeightPx) const;
114 * @copydoc Dali::Font::MeasureTextHeight()
116 float MeasureTextHeight(const Integration::TextArray& text, float textWidthPx) const;
119 * @copydoc Dali::Font::MeasureText(const Text& text) const
121 Vector3 MeasureText(const Integration::TextArray& text) const;
124 * @copydoc Dali::Font::IsDefaultSystemFont()
126 bool IsDefaultSystemFont() const;
129 * @copydoc Dali::Font::IsDefaultSystemSize()
131 bool IsDefaultSystemSize() const;
134 * @copydoc Dali::Font::GetName()
136 const std::string& GetName() const;
139 * @copydoc Dali::Font::GetStyle()
141 const std::string& GetStyle() const;
144 * @copydoc Dali::Font::GetPointSize()
146 float GetPointSize() const;
149 * @copydoc Dali::Font::GetPixelSize()
151 unsigned int GetPixelSize() const;
154 * The line height is the vertical distance between the top of the highest character
155 * to the bottom of the lowest character
156 * @return the line height of the font in pixels
158 float GetLineHeight() const;
161 * The ascender is the vertical distance from the
162 * baseline to the highest character coordinate in a font face.
163 * @return the ascender in pixels
165 float GetAscender() const;
168 * @copydoc Dali::Font::GetUnderlineThickness()
170 float GetUnderlineThickness() const;
173 * @copydoc Dali::Font::GetUnderlinePosition()
175 float GetUnderlinePosition() const;
178 * Returns the scale factor to convert font units to pixels
179 * @return The scale factor to convert font units to pixels
181 float GetUnitsToPixels() const;
184 * Get the glyph metrics for a character
185 * @param[in] character the character to get glyph metrics for
186 * @param[out] metrics used to store the glyph metrics .
188 void GetMetrics(const Dali::Character& character, Dali::Font::Metrics::Impl& metrics) const;
191 * @copydoc Dali::PointsToPixels()
193 static unsigned int PointsToPixels(float pointSize);
196 * @copydoc Dali::PixelsToPointsSize()
198 static float PixelsToPoints(int pixelSize);
201 * Validates a font request.
202 * Provide a requested fontFamily, fontStyle, and point size.
203 * Will update with valid values for these.
204 * @param[in,out] fontFamily The font family name to be validated
205 * @param[in,out] fontStyle The font style to be validated
206 * @param[in,out] fontPointSize The font point size to be validated
207 * @param[out] fontFamilyDefault Whether the requested font family is default or not.
208 * @param[out] fontPointSizeDefault Whether the requested point size is default or not.
210 static void ValidateFontRequest(std::string& fontFamily, std::string& fontStyle, float& fontPointSize, bool& fontFamilyDefault, bool& fontPointSizeDefault );
213 * @copydoc GlyphAtlasManagerInterface::AddObserver()
215 void AddObserver(TextObserver& observer);
218 * @copydoc GlyphAtlasManagerInterface::RemoveObserver()
220 void RemoveObserver(TextObserver& observer);
223 * @copydoc GlyphAtlasManagerInterface::TextRequired()
225 TextVertexBuffer* TextRequired( const Integration::TextArray& text, const TextFormat& format );
228 * @copydoc GlyphAtlasManagerInterface::TextNotRequired()
230 void TextNotRequired( const Integration::TextArray& text, const TextFormat& format, unsigned int textureId );
233 * Add a glyph texture observer
234 * @param observer atlas observer
236 void AddTextureObserver(GlyphTextureObserver& observer );
239 * Remove a glyph texture observer
240 * @param observer atlas observer
242 void RemoveTextureObserver(GlyphTextureObserver& observer );
245 * Check if the characters are loaded into a texture (atlas).
246 * @param[in] text text array
247 * @paran[in] format text format
248 * @param[in] textureId texture ID of the atlas
249 * @return true if all characters are available, false if not
251 bool IsTextLoaded( const Integration::TextArray& text, const TextFormat& format, unsigned int textureId ) const;
257 * Create a new font object using a font name and size
258 * @param [in] fontFamily The family's name of the font requested
259 * @param [in] fontStyle The style of the font requested
260 * @param [in] size The size of the font in points
261 * @param [in] platform platform abstraction
262 * @param [in] resourceClient resourceClient
263 * @param [in] fontfactory font factory
264 * @param [in] atlasInterface reference to the atlas manager interface
265 * @return A newly allocated Font
267 Font(const std::string& fontFamily,
268 const std::string& fontStyle,
270 Integration::PlatformAbstraction& platform,
271 ResourceClient& resourceClient,
272 FontFactory& fontfactory,
273 GlyphAtlasManagerInterface& atlasInterface);
278 * A reference counted object may only be deleted by calling Unreference()
283 bool mIsDefault; ///< Whether the font is a system default font.
284 bool mIsDefaultSize; ///< Whether the font is a system default size.
285 std::string mName; ///< Name of the font's family
286 std::string mStyle; ///< Font's style
287 FontMetricsIntrusivePtr mMetrics; ///< Pointer to font metrics object
288 float mPointSize; ///< Point size
289 float mUnitsToPixels; ///< Used to scale from font metrics to pixels
290 Integration::PlatformAbstraction& mPlatform; ///< platform abstraction
291 ResourceClient& mResourceClient; ///< resource client
292 FontFactory& mFontFactory; ///< font factory
293 GlyphAtlasManagerInterface& mAtlasManager; ///< glyph atlas manager interface
296 } // namespace Internal
298 inline const Internal::Font& GetImplementation(const Dali::Font& font)
300 DALI_ASSERT_ALWAYS( font && "Font handle is empty" );
302 const BaseObject& handle = font.GetBaseObject();
304 return static_cast<const Internal::Font&>(handle);
308 inline Internal::Font& GetImplementation(Dali::Font& font)
310 DALI_ASSERT_ALWAYS( font && "Font handle is empty" );
312 BaseObject& handle = font.GetBaseObject();
314 return static_cast<Internal::Font&>(handle);
319 #endif // __DALI_INTERNAL_FONT_H__