1 #ifndef __DALI_INTEGRATION_PLATFORM_FONT_H__
2 #define __DALI_INTEGRATION_PLATFORM_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.
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/public-api/math/vector2.h>
26 #include <dali/integration-api/bitmap.h>
27 #include <dali/integration-api/resource-declarations.h>
35 typedef IntrusivePtr<GlyphSet> GlyphSetPointer;
38 * A Glyph holds information for a single character.
40 struct DALI_IMPORT_API GlyphMetrics
48 uint32_t code:21; ///< character code (UTF-32), max value of 0x10ffff (21 bits)
49 uint32_t quality:1; ///< 0 = low quality, 1 = high quality
50 float width; ///< glyph width in pixels
51 float height; ///< glyph height in pixels
52 float top; ///< distance between glyph's tallest pixel and baseline
53 float left; ///< where to place the glyph horizontally in relation to current 'pen' position
54 float xAdvance; ///< distance in pixels to move the 'pen' after displaying the character
55 unsigned int xPosition; ///< x position in target atlas texture
56 unsigned int yPosition; ///< y position in target atlas texture
60 * Stores font global metrics.
62 struct DALI_IMPORT_API GlobalMetrics
68 underlinePosition( 0.f ),
69 underlineThickness( 0.f ),
76 GlobalMetrics( float lh, float asc, float upem, float up, float ut, float pax, float pay, float mw, float mh )
80 underlinePosition( up ),
81 underlineThickness( ut ),
88 float lineHeight; ///< Distance between baselines
89 float ascender; ///< Distance from baseline to top of cell
90 float unitsPerEM; ///< font units/EM
91 float underlinePosition; ///< Underline distance from baseline
92 float underlineThickness; ///< Underline thickness
93 float padAdjustX; ///< X adjustment value for padding around distance field
94 float padAdjustY; ///< Y adjustment value for padding around distance field
95 float maxWidth; ///< Width of widest glyph
96 float maxHeight; ///< Height of tallest glyph
101 * Platform font class.
102 * A container for font data; consisting of some metrics and a list of bitmaps
104 class DALI_IMPORT_API GlyphSet : public Dali::RefObject
107 typedef std::pair<BitmapPtr, GlyphMetrics> Character;
108 typedef IntrusivePtr<Character> CharacterPtr;
109 typedef std::vector<Character> CharacterList;
110 typedef CharacterList::iterator CharacterIter;
111 typedef CharacterList::const_iterator CharacterConstIter;
124 * Add a character to the platform font
125 * @param [in] bitmapData A bitmap of the rendered character
126 * @param [in] glyphMetrics Metrics for the character, including its character code
128 void AddCharacter(BitmapPtr bitmapData, const GlyphMetrics& glyphMetrics);
131 * Add a character to the platform font
132 * @param [in] character The Character object
134 void AddCharacter(const Character& character);
137 * Get the list of characters in the font
138 * @return The list of characters
140 const CharacterList& GetCharacterList() const;
143 * Checks if the character is contained in the GlyphSet
144 * @param [in] charCode The character to search for.
145 * @return true if the character is contained in the GlyphSet
147 bool HasCharacter(const uint32_t charCode) const;
150 * Checks if the character is contained in the GlyphSet
151 * @param [in] character The character to search for.
152 * @return true if the character is contained in the GlyphSet
154 bool HasCharacter(const Character& character) const;
157 * Returns the resource ID of the texture atlas these bitmaps will be written to
158 * @return the resource id
160 ResourceId GetAtlasResourceId() const;
163 * Sets the resource ID of the texture atlas these bitmaps will be written to
164 * @param[in] resourceId the resource identifier of the texture atlas.
166 void SetAtlasResourceId(ResourceId resourceId);
168 size_t mFontHash; ///< hash of the fontname the glyphs were loaded for
169 float mLineHeight; ///< Distance between baselines
170 float mAscender; ///< Distance from baseline to top of cell
171 float mUnitsPerEM; ///< font units/EM
172 float mUnderlinePosition; ///< Underline distance from baseline
173 float mUnderlineThickness; ///< Underline thickness
174 float mPadAdjust; ///< Adjustment value for padding around distance field
177 CharacterList mCharacterList;
178 ResourceId mAtlasId; ///< Resource ID of target texture
181 } // namespace Integration
185 #endif // __DALI_INTEGRATION_PLATFORM_FONT_H__