Add CreateFontN(FontMaxHeight)
[platform/framework/native/uifw.git] / src / graphics / FGrp_Font.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_Font.h
20  * @brief       This is the header file for the _Font class.
21  *
22  * This header file contains the declarations of the %_Font class.
23  *
24  */
25
26 #ifndef _FGRP_INTERNAL_FONT_H_
27 #define _FGRP_INTERNAL_FONT_H_
28
29 #include <memory>
30 #include <tr1/memory>
31
32 #include <FBaseObject.h>
33 #include <FGrpFontCommon.h>
34
35 #include "FGrp_IFont.h"
36 #include "FGrp_FontBidiUtil.h"
37
38 #include "util/FGrp_UtilTemplate.h"
39 #include "util/FGrp_UtilType.h"
40
41 namespace Tizen { namespace Base
42 {
43 class String;
44 class ByteBuffer;
45 }} // Tizen::Base
46
47 namespace Tizen { namespace Base { namespace Collection
48 {
49 class IList;
50 }}} // Tizen::Base::Collection
51
52 namespace Tizen { namespace Graphics
53 {
54 class Dimension;
55 class Color;
56 class Point;
57 class Rectangle;
58
59 class _Canvas;
60 class _FontImpl;
61
62 struct _FontAttribute
63 {
64         int style;
65         _Util::FixedPoint26_6 size;
66         _Util::FixedPoint26_6 maxWidth;
67         _Util::FixedPoint26_6 maxHeight;
68         int charSpace;
69         _Util::FixedPoint26_6 ascender;
70         _Util::FixedPoint26_6 descender;
71         _Util::FixedPoint26_6 leading;
72         int lineThickness;
73         bool strikeout;
74         bool underline;
75
76         void Init()
77         {
78                 style = FONT_STYLE_MIN;
79                 size.Reset(0);
80                 maxWidth.Reset(0);
81                 maxHeight.Reset(0);
82                 charSpace = 0;
83                 ascender.Reset(0);
84                 descender.Reset(0);
85                 leading.Reset(0);
86                 lineThickness = -1;
87                 strikeout = false;
88                 underline = false;
89         }
90 };
91
92 class _Font
93         : public Tizen::Base::Object
94 {
95 public:
96         typedef unsigned long SystemPixel;
97
98 public:
99         _Font(void);
100         _Font(const _Font& obj);
101         virtual ~_Font(void);
102
103         result Construct(int style, _Util::FixedPoint26_6 size);
104         result Construct(const Tizen::Base::String& fontName, int style, _Util::FixedPoint26_6 pcSize, bool isPathEnabled = true);
105         result Construct(const Tizen::Base::ByteBuffer& fontData, int style, _Util::FixedPoint26_6 pcSize);
106
107         bool IsConstructed(void) const;
108
109         _Util::FixedPoint26_6 GetMaxHeight(void) const;
110         _Util::FixedPoint26_6 GetMaxWidth(void) const;
111         _Util::FixedPoint26_6 GetAscender(void) const;
112         _Util::FixedPoint26_6 GetDescender(void) const;
113
114         result GetLeftBear(wchar_t character, _Util::FixedPoint22_10& leftBear) const;
115         result GetRightBear(wchar_t character, _Util::FixedPoint22_10& rightBear) const;
116
117         bool IsBold(void) const;
118         bool IsItalic(void) const;
119         bool IsPlain(void) const;
120         bool IsStrikeOut(void) const;
121         bool IsUnderlined(void) const;
122
123         _Util::FixedPoint26_6 GetSize(void) const;
124
125         void SetStrikeOut(bool strikeOut);
126         void SetUnderline(bool underline);
127
128         void SetCharSpace(int space);
129         int GetCharSpace(void) const;
130
131         int GetLineThickness(void) const;
132         Tizen::Base::String GetFaceName(void) const;
133         static Tizen::Base::Collection::IList* GetSystemFontListN(void);
134         static Tizen::Base::String GetFaceName(const Tizen::Base::String& filePath);
135
136         _IFont* GetNativeFont(void) const;
137         _Font* CloneN(void);
138         bool ApplyAttribute(void);
139
140         result GetTextExtent(int width, const _Util::String& text, bool outline, int& count, Dimension& dim) const;
141         result GetTextExtent(int width, const _Util::String& text, bool outline, const Tizen::Base::String& delimiter, int& count, Dimension& dim) const;
142
143         result GetTextExtentList(const _Util::String& text, _Util::AccumList<_Util::Pair<int, int> >& outList) const;
144
145         result SetSize(_Util::FixedPoint26_6 pcSize);
146         result SetStyle(int style);
147
148         int GetStyle(void) const;
149
150         _Util::FixedPoint26_6 GetLeading(void) const;
151
152         // native font interface
153         bool SetAttrib(const _IFont::Attrib& fontAttrib);
154         bool GetAttrib(_IFont::Attrib& fontAttrib) const;
155         bool GetKerning(unsigned long character1, unsigned long character2, long& xVector, long& yVector) const;
156         bool GetFontSizeProperty(_IFont::SizeProperty& sizeProperty) const;
157         bool GetFontProperty(_IFont::Property& property) const;
158         bool LoadGlyph(unsigned long character, _IFont::Glyph** ppFontGlyphData);
159         bool UnloadGlyph(_IFont::Glyph** ppFontGlyphData);
160         unsigned long CheckGlyph(unsigned long character);
161
162         float GetFontSizeFromMaxHeight(const _Util::FixedPoint26_6 expectedMaxHeight);
163
164         static float GetFontSizeFromMaxHeight(int style, const _Util::FixedPoint26_6 expectedMaxHeight);
165         static float GetFontSizeFromMaxHeight(const Tizen::Base::String& fontName, int style, const _Util::FixedPoint26_6 expectedMaxHeight);
166
167         static result DrawText(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length);
168         static result DrawText(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor);
169
170         static _Font* GetInstance(_FontImpl& font);
171         static const _Font* GetInstance(const _FontImpl& font);
172
173         static bool UpdateDefaultFont(const Tizen::Base::String& key);
174
175 private:
176         _Font& operator =(const _Font& rhs);
177         void __UpdateFontAttribute(int style, _Util::FixedPoint26_6 size);
178
179         result __DrawText(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length);
180         result __DrawText(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor);
181
182         static result __DrawTextLastFallback(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length);
183         static result __DrawTextDefault(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length);
184         static result __DrawTextDefault(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor);
185
186         _IFont* __GetFont(wchar_t character);
187         bool __GetFallbackFontFileList(wchar_t character, Tizen::Base::Collection::IListT<Tizen::Base::String>& out);
188
189         result __GetTextExtent(int width, const _Util::String& text, bool outline, int& count, Dimension& dim) const;
190         result __GetTextExtentEx(int width, const _Util::String& text, bool outline, int& count, Dimension& dim) const;
191
192         result __GetTextExtentList(const _Util::String& text, _Util::AccumList<_Util::Pair<int, int> >& outList) const;
193         result __GetTextExtentList(_TextBidiPropertyWithReorder& bidiProperty, _Util::AccumList<_Util::Pair<int, int> >& outList) const;
194
195 private:
196         unsigned long __magicKey;
197         std::tr1::shared_ptr <_IFont> __sharedFont;
198         _FontAttribute __fontAttrib;
199
200 }; // _Font
201
202 }} // Tizen::Graphics
203
204 #endif // _FGRP_INTERNAL_FONT_H_