Initialize Tizen 2.3
[apps/osp/Internet.git] / src / IntFontManager.cpp
1 //
2
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.1 (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 //!Internet
19 /*@file:  IntFontManager.cpp
20  *@brief: This header file contains the definitions of the FontManager class.
21  */
22
23 #include "IntFontManager.h"
24
25 using namespace Tizen::Base;
26 using namespace Tizen::Graphics;
27
28 FontTable fontTable[] = {
29                 //FONT_GT34
30                 {
31                                 NULL, L"Global" /*L"GT_Latin"*/, FONT_STYLE_PLAIN, 34
32                 },
33                 //FONT_GT32
34                 {
35                                 NULL, L"Global" /*L"GT_Latin"*/, FONT_STYLE_PLAIN | FONT_STYLE_BOLD, 32
36                 },
37                 //FONT_GT30
38                 {
39                                 NULL, L"Global" /*L"GT_Latin"*/, FONT_STYLE_PLAIN | FONT_STYLE_BOLD, 30
40                 },
41                 //FONT_GT26
42                 {
43                                 NULL, L"Global" /*L"GT_Latin"*/, FONT_STYLE_PLAIN | FONT_STYLE_BOLD, 26
44                 },
45                 //FONT_GT20
46                 {
47                                 NULL, L"Global" /*L"GT_Latin"*/, FONT_STYLE_PLAIN | FONT_STYLE_BOLD, 20
48                 },
49                 //FONT_GT14
50                 {
51                                 NULL, L"Global" /*L"GT_Latin"*/, FONT_STYLE_PLAIN | FONT_STYLE_BOLD, 14
52                 },
53
54                 //FONT_GP40
55                 {
56                                 NULL, L"Global" /*L"GP_Latin"*/, FONT_STYLE_PLAIN, 40
57                 },
58                 //FONT_GP38
59                 {
60                                 NULL, L"Global" /*L"GP_Latin"*/, FONT_STYLE_PLAIN, 38
61                 },
62                 //FONT_GP36
63                 {
64                                 NULL, L"Global" /*L"GP_Latin"*/, FONT_STYLE_PLAIN, 36
65                 },
66                 //FONT_GP34
67                 {
68                                 NULL, L"Global" /*L"GP_Latin"*/, FONT_STYLE_PLAIN, 34
69                 },
70                 //FONT_GP30
71                 {
72                                 NULL, L"Global" /*L"GP_Latin"*/, FONT_STYLE_PLAIN, 30
73                 },
74                 //FONT_GP26
75                 {
76                                 NULL, L"Global" /*L"GP_Latin"*/, FONT_STYLE_PLAIN, 26
77                 },
78                 //FONT_GP24
79                 {
80                                 NULL, L"Global" /*L"GP_Latin"*/, FONT_STYLE_PLAIN, 24
81                 },
82                 //FONT_GP18
83                 {
84                                 NULL, L"Global" /*L"GP_Latin"*/, FONT_STYLE_PLAIN, 18
85                 },
86
87                 //FONT_GS30
88                 {
89                                 NULL, L"Global" /*L"GS_Latin"*/, FONT_STYLE_PLAIN, 30
90                 },
91                 //FONT_GS34
92                 {
93                                 NULL, L"Global" /*L"GS_Latin"*/, FONT_STYLE_PLAIN, 34
94                 },
95
96                 // end of font table ----------
97                 {
98                                 NULL, L"", FONT_STYLE_PLAIN, 0
99                 }
100 };
101
102 void
103 FontManager::CreateFont(FontId fontValue)
104 {
105         Font* pFont = null;
106         if (fontValue < 0 || fontValue >= MAX_FONT)
107         {
108                 return;
109         }
110
111         if (fontTable[fontValue].pInstance)
112         {
113                 return;
114         }
115
116         if (fontTable[fontValue].fontName.GetLength() <= 0)
117         {
118                 return;
119         }
120
121         pFont = new(std::nothrow) Font();
122         // If pFont is null then return
123         if (pFont == NULL)
124         {
125                 return;
126         }
127
128         pFont->Construct( /*g_FontTable[fontid].fontName,*/
129                         fontTable[fontValue].fontStyle,
130                         fontTable[fontValue].fontSize);
131
132         fontTable[fontValue].pInstance = pFont;
133         return;
134 }
135
136 Font*
137 FontManager::GetFont(FontId fontValue)
138 {
139         if (fontValue < 0 || fontValue >= MAX_FONT)
140         {
141                 return NULL;
142         }
143
144         //Check for the existence of fontValue in fontTable and if its not null then call CreateFont(fontValue)
145
146         if (fontTable[fontValue].pInstance == null)
147         {
148                 CreateFont(fontValue);
149         }
150
151         return fontTable[fontValue].pInstance;
152
153 }
154
155 void
156 FontManager::ReleaseFonts(void)
157 {
158         int maxCount = 0;
159
160         for (maxCount = 0; maxCount < MAX_FONT; maxCount++)
161         {
162                 //delete if instance exists in fontTable
163                 if (fontTable[maxCount].pInstance)
164                 {
165                         delete fontTable[maxCount].pInstance;
166                         fontTable[maxCount].pInstance = NULL;
167                 }
168         }
169         return;
170 }