Add CreateFontN(FontMaxHeight)
[platform/framework/native/uifw.git] / src / graphics / FGrp_IFont.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /*
19  * @file        FGrp_IFont.h
20  * @brief       This is the header file for _IFont class.
21  *
22  */
23
24 #ifndef _FGRP_INTERNAL_IFONT_H_
25 #define _FGRP_INTERNAL_IFONT_H_
26
27 #include <memory>
28 #include <tr1/memory>
29
30
31 #ifdef USE_HASHMAP_FOR_FONT
32         #include <FBaseColHashMapT.h>
33 #else
34         #include <list>
35         #include <FBaseColIListT.h>
36 #endif
37
38 #include "util/FGrp_UtilType.h"
39
40 namespace Tizen { namespace Graphics
41 {
42
43 class _FontRsrcManager;
44
45 class _IFont
46 {
47 public:
48         typedef std::tr1::shared_ptr<_IFont> SharedFontResource;
49 #ifdef USE_HASHMAP_FOR_FONT
50         typedef Tizen::Base::Collection::HashMapT <_Util::WString, SharedFontResource> FontMapT;
51 #else
52         typedef std::list<std::pair<_Util::WString, SharedFontResource> > FontMapT;
53 #endif
54
55         //! Enumerated definition of the font style.
56         enum Style
57         {
58                 STYLE_NONE = 0,      //!< Basic style.
59                 STYLE_ITALIC = 1,    //!< Italic style.
60                 STYLE_BOLD = 2,      //!< Bold style.
61                 STYLE_UNDERLINE = 4, //!< Underline style.
62                 STYLE_BACKSLANT = 8  //!< Reverse italic style.
63         };
64
65         //! Enumerated definition of the font quality.
66         enum Quality
67         {
68                 QUALITY_MONO = 0,    //!< Glyph of 1-bit form.
69                 QUALITY_LOW = 1,     //!< Low quality of 8-bit form.
70                 QUALITY_MEDIUM = 2,  //!< Medium quality of 8-bit form.
71                 QUALITY_HIGH = 3     //!< High quality of 8-bit form.
72         };
73
74         //! Enumerated definition of the font capabilities.
75         enum Capability
76         {
77                 CAPS_SCALABLE = 0x0001,       //!< Support of the scalable font.
78                 CAPS_ANGLE = 0x0002,          //!< Support of the angle.
79                 CAPS_X_EXPANSION = 0x0004,    //!< Support of the expansion of the font.
80                 CAPS_BOLDWEIGHT = 0x0008,     //!< Support of the bold weight of the font.
81                 CAPS_QUALITY_MONO = 0x0010,   //!< Support of the white & black font.
82                 CAPS_QUALITY_LOW = 0x0020,    //!< Support of the low quality in the gray map font.
83                 CAPS_QUALITY_MEDIUM = 0x0040, //!< Support of the medium quality in the gray map font.
84                 CAPS_QUALITY_HIGH = 0x0080    //!< Support of the high quality in the gray map font.
85         };
86
87         //! Attrib structure
88         struct Attrib
89         {
90                 _Util::FixedPoint26_6 size;               //!< Size of the font. (26.6 fixed point unit)
91                 unsigned int style;      //!< Style of the font. (_IFont::Style)
92                 int quality;             //!< Quality of the font. (_IFont::Quality)
93                 float angle;             //!< Angle of the font.
94                 long xExpansion;         //!< Expansion of the font.
95                 _Util::FixedPoint26_6 boldWeight;         //!< Bold weight of the font
96         };
97
98         //! GlyphBitmap structure
99         struct GlyphBitmap
100         {
101                 long width;                   //!< Horizontal size of an image buffer.
102                 long height;                  //!< Vertical size of an image buffer.
103                 long bytesPerLine;            //!< The number of bytes to represent one horizontal line in buffer.
104                 unsigned long depth;          //!< The number of bits to compose one pixel.
105                 unsigned char* pBitmap;        //!< Start address of an image buffer.
106         };
107
108         //! Glyph structure
109         struct Glyph
110         {
111                 unsigned long id;            //!< Internal identifier of the font.
112                 _Util::FixedPoint22_10 xOffset;                //!< Starting point of displaying the font.
113                 _Util::FixedPoint22_10 yOffset;                //!< Starting point of displaying the font.
114                 _Util::FixedPoint22_10 xAdvance;               //!< Distance to move for displaying the next font.
115                 _Util::FixedPoint22_10 yAdvance;               //!< Distance to move for displaying the next font.
116                 long hasOwnerShip;
117                 GlyphBitmap image;           //!< Image information of a glyph.
118                 void* ptrAux;                //!< Internal data for each target.
119         };
120
121         //! Size Property structure
122         struct SizeProperty
123         {
124                 _Util::FixedPoint26_6 minSize;   //!< Minimal size of the supportable font.
125                 _Util::FixedPoint26_6 maxSize;   //!< Maximal size of the supportable font.
126
127                 _Util::FixedPoint26_6 maxWidth;           //!< Maximal width of this font data.
128                 _Util::FixedPoint26_6 maxHeight;          //!< Maximal height of this font data.
129                 _Util::FixedPoint26_6 baseLine;           //!< BaseLine of this font data.
130                 _Util::FixedPoint26_6 ascender;           //!< Ascender of this font data.
131                 _Util::FixedPoint26_6 descender;          //!< Descender of this font data.
132                 _Util::FixedPoint26_6 leading;            //!< Leading of this font data.
133         };
134
135         //! Font Property structure
136         struct Property
137         {
138                 int fontCaps;            //!< Flag for the font capability. (_IFont::Capability)
139                 int styleCaps;           //!< Flag for the font style capability. (_IFont::Style)
140
141                 const char* pEngineName;  //!< Name of the font engine.
142                 const char* pFamilyName;  //!< Name of the font family.
143                 const char* pStyleName;   //!< Name of the font style.
144                 long styleFlag;           //!< flag value of the font style. (Regular = 0, Bold = 2)
145                 long weightClass;         //!< Value of the font WeightClass.
146         };
147
148         virtual ~_IFont(void) {}
149
150         //! Changes the attribute using fontAttrib.
151         virtual bool SetAttrib(const Attrib& fontAttrib) = 0;
152         //! Gets current attribute and store it in fontAttrib.
153         virtual bool GetAttrib(Attrib& fontAttrib) const = 0;
154
155         //! Gets the value of the interval correctness between two characters.
156         virtual bool GetKerning(unsigned long ch1, unsigned long ch2, long& xVector, long& yVector) const = 0;
157
158         //! Loads the font glyph data for displaying font.
159         virtual bool LoadGlyph(unsigned long character, Glyph** pFontGlyphData) = 0;
160         //! Releases the resource of the font glyph data that is not needed any more.
161         virtual bool UnloadGlyph(Glyph** pFontGlyphData) = 0;
162         //! Check if specified glyph is included.
163         virtual unsigned long CheckGlyph(unsigned long character) = 0;
164
165         virtual float GetFontSizeFromMaxHeight(_Util::FixedPoint26_6 expectedMaxHeight) const = 0;
166
167         //! Gets the support range and the property for this font engine.
168         virtual bool GetFontSizeProperty(SizeProperty& sizeProperty) const = 0;
169         virtual bool GetFontProperty(Property& property) const = 0;
170
171         //! Harfbuzz test
172         virtual bool GetGlyphList(const _Util::String& text, Tizen::Base::Collection::IListT<Glyph *>& out, int script) = 0;
173
174         //! Gets the font fallback map.
175         virtual FontMapT* GetFallbackMap(void) = 0;
176
177         virtual bool IsEmoji(void) const = 0;
178
179 protected:
180         //! Initializes a font instance with the font data on the memory buffer.
181         virtual bool Create(const void* pBuffer, long bufSize, long face = 0) = 0;
182         //! Initializes a font instance with the font file.
183         virtual bool Create(const char* pFilePath, long face = 0) = 0;
184         //! Initializes a font instance with the font data on the static memory buffer.
185         virtual bool CreateStatic(const void* pBuffer, long bufSize, long face = 0) = 0;
186         //! Reloads a font instance with the font data on the memory buffer.
187         virtual bool Reload(const void* pBuffer, long bufSize, long face = 0) = 0;
188         //! Reloads a font instance with the font file
189         virtual bool Reload(const char* filePath, long face = 0) = 0;
190         //! Destroys the instance.
191         virtual void Destroy(void) = 0;
192         //! Finds glyph in the cache
193         virtual bool FindCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph** pOut) = 0;
194         //! Adds glyph in the cache
195         virtual bool AddCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph* pGlyph) = 0;
196         //! Clean cache
197         virtual bool CleanCache(void) = 0;
198
199 private:
200         friend class _FontRsrcManager;
201 }; // _IFont
202
203 }} // Tizen::Graphics
204
205 #endif // _FGRP_INTERNAL_IFONT_H_