2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
20 * @brief This is the implementation file for Font class.
22 * This header file contains implementation of Font class.
26 #include <FApp_AppInfo.h>
28 #include <FBaseString.h>
30 #include <FBaseSysLog.h>
32 #include "FGrp_FontImpl.h"
33 #include "FGrp_ResUtil.h"
35 #define CHECK_NOT_CONSTRUCTED \
36 SysTryReturnResult(NID_GRP, this->__pImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Fails to allocate memory.") \
37 SysAssertf(!this->__pImpl->IsConstructed(), \
38 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
40 #define CHECK_CONSTRUCTED \
41 SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
42 "Not yet constructed! Construct() should be called before use.");
44 #define CHECK_CONSTRUCTED_EX(_result) \
45 SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
46 "Not yet constructed! Construct() should be called before use.");
48 #define CHECK_CONSTRUCTED_VOID \
49 SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
50 "Not yet constructed! Construct() should be called before use.");
53 using namespace Tizen::Base;
54 using namespace Tizen::Graphics;
57 namespace Tizen { namespace Graphics
62 __pImpl = new (std::nothrow) _FontImpl;
65 Font::Font(const Font& rhs)
67 __pImpl = rhs.__pImpl->CloneN();
77 Font::Construct(int style, int vc_size)
79 CHECK_NOT_CONSTRUCTED;
82 SysTryReturnResult(NID_GRP, vc_size > 0, E_INVALID_ARG, "Font size should be greater than 0");
83 SysTryReturnResult(NID_GRP, FONT_STYLE_MIN < style && style <= (FONT_STYLE_PLAIN | FONT_STYLE_BOLD | FONT_STYLE_ITALIC), E_INVALID_ARG,
84 "Style(%d) is invalid", style);
86 result r = __pImpl->Construct(style, vc_size);
88 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
94 Font::Construct(const Tizen::Base::String& fontNameOrPath, int style, int vc_size)
96 CHECK_NOT_CONSTRUCTED;
99 SysTryReturnResult(NID_GRP, vc_size > 0, E_INVALID_ARG, "Font size should be greater than 0");
100 SysTryReturnResult(NID_GRP, FONT_STYLE_MIN < style && style <= (FONT_STYLE_PLAIN | FONT_STYLE_BOLD | FONT_STYLE_ITALIC), E_INVALID_ARG,
101 "Style(%d) is invalid.\n", style);
102 SysTryReturnResult(NID_GRP, fontNameOrPath.GetLength() > 0, E_FILE_NOT_FOUND, "The specified font could not be found or accessed");
103 SysTryReturnResult(NID_GRP, !fontNameOrPath.EndsWith(L"/") && !fontNameOrPath.EndsWith(L"\\"), E_FILE_NOT_FOUND,
104 "The specified font could not be found or accessed.\n");
106 result r = __pImpl->Construct(fontNameOrPath, style, vc_size);
108 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
114 Font::Construct(const Tizen::Base::ByteBuffer& fontData, int style, int vc_size)
116 CHECK_NOT_CONSTRUCTED;
118 // check input param.
119 SysTryReturnResult(NID_GRP, fontData.GetLimit() > 0, E_INVALID_ARG, "Buffer size should be greater than 0");
120 SysTryReturnResult(NID_GRP, vc_size > 0, E_INVALID_ARG, "FontEx size should be greater than 0");
121 SysTryReturnResult(NID_GRP, style > FONT_STYLE_MIN && style <= (FONT_STYLE_PLAIN | FONT_STYLE_BOLD | FONT_STYLE_ITALIC), E_INVALID_ARG,
122 "Style(%d) is invalid", style);
124 result r = __pImpl->Construct(fontData, style, vc_size);
126 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
132 Font::GetMaxHeight(void) const
134 CHECK_CONSTRUCTED_EX(-1);
136 return __pImpl->GetMaxHeight();
140 Font::GetMaxWidth(void) const
142 CHECK_CONSTRUCTED_EX(-1);
144 return __pImpl->GetMaxWidth();
148 Font::GetAscender(void) const
150 CHECK_CONSTRUCTED_EX(-1);
152 return __pImpl->GetAscender();
156 Font::GetDescender(void) const
158 CHECK_CONSTRUCTED_EX(-1);
160 return __pImpl->GetDescender();
164 Font::GetLeftBear(wchar_t character, int& vc_leftBear) const
168 return __pImpl->GetLeftBear(character, vc_leftBear);
172 Font::GetRightBear(wchar_t character, int& vc_rightBear) const
176 return __pImpl->GetRightBear(character, vc_rightBear);
180 Font::GetTextExtent(const Tizen::Base::String& text, int length, Dimension& vc_dim) const
184 SysTryReturnResult(NID_GRP, length >= 0 && length <= text.GetLength(), E_OUT_OF_RANGE,
185 "The length(%d) of the given text is out of range", length);
187 if (length == 0 || text.GetLength() == 0)
192 result r = __pImpl->GetTextExtent(text, length, vc_dim);
194 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
196 if (!Tizen::App::_AppInfo::IsOspCompat())
198 vc_dim.height = GetMaxHeight();
205 Font::IsBold(void) const
207 CHECK_CONSTRUCTED_EX(false);
209 return __pImpl->IsBold();
213 Font::IsItalic(void) const
215 CHECK_CONSTRUCTED_EX(false);
217 return __pImpl->IsItalic();
221 Font::IsPlain(void) const
223 CHECK_CONSTRUCTED_EX(false);
225 return __pImpl->IsPlain();
229 Font::IsStrikeOut(void) const
231 CHECK_CONSTRUCTED_EX(false);
233 return __pImpl->IsStrikeOut();
237 Font::IsUnderlined(void) const
239 CHECK_CONSTRUCTED_EX(false);
241 return __pImpl->IsUnderlined();
245 Font::GetSize(void) const
247 CHECK_CONSTRUCTED_EX(-1);
249 return __pImpl->GetSize();
253 Font::SetStrikeOut(bool strikeout)
255 CHECK_CONSTRUCTED_VOID;
257 return __pImpl->SetStrikeOut(strikeout);
261 Font::SetUnderline(bool underline)
263 CHECK_CONSTRUCTED_VOID;
265 return __pImpl->SetUnderline(underline);
269 Font::SetCharSpace(int vc_space)
271 CHECK_CONSTRUCTED_VOID;
273 return __pImpl->SetCharSpace(vc_space);
277 Font::GetCharSpace(void) const
279 CHECK_CONSTRUCTED_EX(0);
281 return __pImpl->GetCharSpace();
285 Font::GetFaceName(void) const
287 CHECK_CONSTRUCTED_EX("");
289 return __pImpl->GetFaceName();
292 Tizen::Base::Collection::IList*
293 Font::GetSystemFontListN(void)
295 return _FontImpl::GetSystemFontListN();
299 Font::GetFaceName(const Tizen::Base::String& filePath)
301 return _FontImpl::GetFaceName(filePath);
304 }} // Tizen::Graphics