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 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/vector-wrapper.h>
26 #include <dali/public-api/math/vector2.h>
27 #include <dali/integration-api/bitmap.h>
28 #include <dali/integration-api/resource-declarations.h>
36 typedef IntrusivePtr<GlyphSet> GlyphSetPointer;
39 * A Glyph holds information for a single character.
49 uint32_t code:21; ///< character code (UTF-32), max value of 0x10ffff (21 bits)
50 uint32_t quality:1; ///< 0 = low quality, 1 = high quality
51 float width; ///< glyph width in pixels
52 float height; ///< glyph height in pixels
53 float top; ///< distance between glyph's tallest pixel and baseline
54 float left; ///< where to place the glyph horizontally in relation to current 'pen' position
55 float xAdvance; ///< distance in pixels to move the 'pen' after displaying the character
56 unsigned int xPosition; ///< x position in target atlas texture
57 unsigned int yPosition; ///< y position in target atlas texture
61 * Stores font global metrics.
69 underlinePosition( 0.f ),
70 underlineThickness( 0.f ),
77 GlobalMetrics( float lh, float asc, float upem, float up, float ut, float pax, float pay, float mw, float mh )
81 underlinePosition( up ),
82 underlineThickness( ut ),
89 float lineHeight; ///< Distance between baselines
90 float ascender; ///< Distance from baseline to top of cell
91 float unitsPerEM; ///< font units/EM
92 float underlinePosition; ///< Underline distance from baseline
93 float underlineThickness; ///< Underline thickness
94 float padAdjustX; ///< X adjustment value for padding around distance field
95 float padAdjustY; ///< Y adjustment value for padding around distance field
96 float maxWidth; ///< Width of widest glyph
97 float maxHeight; ///< Height of tallest glyph
102 * Platform font class.
103 * A container for font data; consisting of some metrics and a list of bitmaps
105 class DALI_IMPORT_API GlyphSet : public Dali::RefObject
108 typedef std::pair<BitmapPtr, GlyphMetrics> Character;
109 typedef IntrusivePtr<Character> CharacterPtr;
110 typedef std::vector<Character> CharacterList;
111 typedef CharacterList::iterator CharacterIter;
112 typedef CharacterList::const_iterator CharacterConstIter;
125 * Add a character to the platform font
126 * @param [in] bitmapData A bitmap of the rendered character
127 * @param [in] glyphMetrics Metrics for the character, including its character code
129 void AddCharacter(BitmapPtr bitmapData, const GlyphMetrics& glyphMetrics);
132 * Add a character to the platform font
133 * @param [in] character The Character object
135 void AddCharacter(const Character& character);
138 * Get the list of characters in the font
139 * @return The list of characters
141 const CharacterList& GetCharacterList() const;
144 * Checks if the character is contained in the GlyphSet
145 * @param [in] charCode The character to search for.
146 * @return true if the character is contained in the GlyphSet
148 bool HasCharacter(const uint32_t charCode) const;
151 * Checks if the character is contained in the GlyphSet
152 * @param [in] character The character to search for.
153 * @return true if the character is contained in the GlyphSet
155 bool HasCharacter(const Character& character) const;
158 * Returns the resource ID of the texture atlas these bitmaps will be written to
159 * @return the resource id
161 ResourceId GetAtlasResourceId() const;
164 * Sets the resource ID of the texture atlas these bitmaps will be written to
165 * @param[in] resourceId the resource identifier of the texture atlas.
167 void SetAtlasResourceId(ResourceId resourceId);
169 size_t mFontHash; ///< hash of the fontname the glyphs were loaded for
170 float mLineHeight; ///< Distance between baselines
171 float mAscender; ///< Distance from baseline to top of cell
172 float mUnitsPerEM; ///< font units/EM
173 float mUnderlinePosition; ///< Underline distance from baseline
174 float mUnderlineThickness; ///< Underline thickness
175 float mPadAdjust; ///< Adjustment value for padding around distance field
178 CharacterList mCharacterList;
179 ResourceId mAtlasId; ///< Resource ID of target texture
182 } // namespace Integration
186 #endif // __DALI_INTEGRATION_PLATFORM_FONT_H__