Tizen 2.1 base
[framework/osp/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 Flora License, Version 1.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://floralicense.org/license/
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
37 #include "util/FGrp_UtilTemplate.h"
38 #include "util/FGrp_UtilType.h"
39
40 namespace Tizen { namespace Base
41 {
42 class String;
43 class ByteBuffer;
44 }} // Tizen::Base
45
46 namespace Tizen { namespace Base { namespace Collection
47 {
48 class IList;
49 }}} // Tizen::Base::Collection
50
51 namespace Tizen { namespace Graphics
52 {
53 class Dimension;
54 class Color;
55 class Point;
56 class Rectangle;
57
58 class _Canvas;
59 class _FontImpl;
60
61 struct _FontAttribute
62 {
63         int style;
64         int size;
65         int maxWidth;
66         int maxHeight;
67         int charSpace;
68         bool strikeout;
69         bool underline;
70         int lineThickness;
71         int ascender;
72         int descender;
73
74         void Init()
75         {
76                 style = FONT_STYLE_MIN;
77                 size = -1;
78                 maxWidth = -1;
79                 maxHeight = -1;
80                 charSpace = 0;
81                 strikeout = false;
82                 underline = false;
83                 lineThickness = -1;
84                 ascender = -1;
85                 descender = -1;
86         }
87 };
88
89 class _Font
90         : public Tizen::Base::Object
91 {
92 public:
93         typedef unsigned long SystemPixel;
94
95 public:
96         _Font(void);
97         _Font(const _Font& obj);
98         virtual ~_Font(void);
99
100         result Construct(int style, int size);
101         result Construct(const Tizen::Base::String& fontName, int style, int pcSize, bool isPathEnabled = true);
102         result Construct(const Tizen::Base::ByteBuffer& fontData, int style, int pcSize);
103
104         bool IsConstructed(void) const;
105
106         int GetMaxHeight(void) const;
107         int GetMaxWidth(void) const;
108         int GetAscender(void) const;
109         int GetDescender(void) const;
110
111         result GetLeftBear(wchar_t character, int& leftBear) const;
112         result GetRightBear(wchar_t character, int& rightBear) const;
113         result GetTextExtent(const Tizen::Base::String& text, int length, Dimension& dim) const;
114
115         bool IsBold(void) const;
116         bool IsItalic(void) const;
117         bool IsPlain(void) const;
118         bool IsStrikeOut(void) const;
119         bool IsUnderlined(void) const;
120         bool IsEmoji(void) const;
121         int GetSize(void) const;
122         void SetStrikeOut(bool strikeOut);
123         void SetUnderline(bool underline);
124         void SetCharSpace(int space);
125         int GetCharSpace(void) const;
126         int GetLineThickness(void) const;
127         Tizen::Base::String GetFaceName(void) const;
128         static Tizen::Base::Collection::IList* GetSystemFontListN(void);
129         static Tizen::Base::String GetFaceName(const Tizen::Base::String& filePath);
130
131         _IFont* GetNativeFont(void) const;
132         _Font* CloneN(void);
133         bool ApplyAttribute(void);
134
135         result GetTextExtent(int width, const Tizen::Base::String& text, int startIndex, int length, bool outline, int& count, Dimension& dim) const;
136         result GetTextExtent(int width, const Tizen::Base::String& text, int startIndex, int length, bool outline, const Tizen::Base::String& delimiter, int& count, Dimension& dim) const;
137
138         result SetSize(int pcSize);
139         result SetStyle(int style);
140
141         int GetStyle(void) const;
142         int GetLeading(void) const;
143
144         // native font interface
145         bool SetAttrib(const _IFont::Attrib& fontAttrib);
146         bool GetAttrib(_IFont::Attrib& fontAttrib) const;
147         bool GetKerning(unsigned long character1, unsigned long character2, long& xVector, long& yVector) const;
148         bool GetFontProperty(_IFont::Property& property) const;
149         bool LoadGlyph(unsigned long character, _IFont::Glyph** ppFontGlyphData);
150         bool UnloadGlyph(_IFont::Glyph** ppFontGlyphData);
151         unsigned long CheckGlyph(unsigned long character);
152
153         static result DrawText(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length);
154         static result DrawText(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor);
155
156         static _Font* GetInstance(_FontImpl& font);
157         static const _Font* GetInstance(const _FontImpl& font);
158
159         static bool UpdateDefaultFont(const Tizen::Base::String& key);
160
161 private:
162         _Font& operator =(const _Font& rhs);
163         void __UpdateFontAttribute(int style, int size);
164
165         result __DrawText(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length);
166         result __DrawText(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor);
167
168         static result __DrawTextLastFallback(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length);
169         static result __DrawTextDefault(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length);
170         static result __DrawTextDefault(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor);
171
172         _IFont* __GetFont(wchar_t character);
173         bool __GetFallbackFontFileList(wchar_t character, Tizen::Base::Collection::IListT<Tizen::Base::String>& out);
174
175 private:
176         std::tr1::shared_ptr <_IFont> __sharedFont;
177         _FontAttribute __fontAttrib;
178
179 }; // _Font
180
181 }} // Tizen::Graphics
182
183 #endif // _FGRP_INTERNAL_FONT_H_