Added object sizes to platform abstraction in profiling section
[platform/core/uifw/dali-core.git] / dali / integration-api / glyph-set.h
1 #ifndef __DALI_INTEGRATION_PLATFORM_FONT_H__
2 #define __DALI_INTEGRATION_PLATFORM_FONT_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
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
10 //
11 //     http://floralicense.org/license/
12 //
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.
18 //
19
20 // EXTERNAL INCLUDES
21 #include <stdint.h>
22
23 // INTERNAL INCLUDES
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>
28
29 namespace Dali
30 {
31
32 namespace Integration
33 {
34 class GlyphSet;
35 typedef IntrusivePtr<GlyphSet> GlyphSetPointer;
36
37 /**
38  * A Glyph holds information for a single character.
39  */
40 struct DALI_IMPORT_API GlyphMetrics
41 {
42   enum GlyphQuality
43   {
44     LOW_QUALITY = 0x0,
45     HIGH_QUALITY = 0x1
46   };
47
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
57 };
58
59 /**
60  * Stores font global metrics.
61  */
62 struct DALI_IMPORT_API GlobalMetrics
63 {
64   GlobalMetrics()
65   : lineHeight( 0.f ),
66     ascender( 0.f ),
67     unitsPerEM( 0.f ),
68     underlinePosition( 0.f ),
69     underlineThickness( 0.f ),
70     padAdjustX( 0.f ),
71     padAdjustY( 0.f ),
72     maxWidth( 0.f ),
73     maxHeight( 0.f )
74   {}
75
76   GlobalMetrics( float lh, float asc, float upem, float up, float ut, float pax, float pay, float mw, float mh )
77   : lineHeight( lh ),
78     ascender( asc ),
79     unitsPerEM( upem ),
80     underlinePosition( up ),
81     underlineThickness( ut ),
82     padAdjustX( pax ),
83     padAdjustY( pay ),
84     maxWidth( mw ),
85     maxHeight ( mh )
86   {}
87
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
97 };
98
99 /**
100  *
101  * Platform font class.
102  * A container for font data; consisting of some metrics and a list of bitmaps
103  */
104 class DALI_IMPORT_API GlyphSet : public Dali::RefObject
105 {
106 public:
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;
112
113   /**
114    * Constructor.
115    */
116   GlyphSet();
117
118   /**
119    * Destructor.
120    */
121   ~GlyphSet();
122
123   /**
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
127    */
128   void AddCharacter(BitmapPtr bitmapData, const GlyphMetrics& glyphMetrics);
129
130   /**
131    * Add a character to the platform font
132    * @param [in] character   The Character object
133    */
134   void AddCharacter(const Character& character);
135
136   /**
137    * Get the list of characters in the font
138    * @return The list of characters
139    */
140   const CharacterList& GetCharacterList() const;
141
142   /**
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
146    */
147   bool HasCharacter(const uint32_t charCode) const;
148
149   /**
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
153    */
154   bool HasCharacter(const Character& character) const;
155
156   /**
157    * Returns the resource ID of the texture atlas these bitmaps will be written to
158    * @return the resource id
159    */
160   ResourceId GetAtlasResourceId() const;
161
162   /**
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.
165    */
166   void SetAtlasResourceId(ResourceId resourceId);
167
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
175
176 private:
177   CharacterList mCharacterList;
178   ResourceId    mAtlasId;             ///< Resource ID of target texture
179 };
180
181 } // namespace Integration
182
183 } // namespace Dali
184
185 #endif // __DALI_INTEGRATION_PLATFORM_FONT_H__