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.
19 * @file FGrp_FontImpl.cpp
20 * @brief This is the implementation file for _FontImpl class.
29 #include <FBaseSysLog.h>
31 #include "FGrp_FontImpl.h"
32 #include "FGrp_Font.h"
33 #include "FGrp_ResUtil.h"
36 #define IF_NOT_INITIALIZED(code) if (this->_pNativeFont == null || this->_pCoordHolder == null) \
40 #define IF_NOT_CONSTRUCTED(code) if (this->_pNativeFont == null || (!this->_pNativeFont->IsConstructed())) \
44 #define IsSucceeded(X) (!IsFailed(X))
45 #define CONVERT_INTEGER_TO_26_6_FIXED_POINT(value) (value * 64)
48 namespace Tizen { namespace Graphics
51 struct _FontCoordHolder
53 _ResUtil::CoordHolder <int> size;
54 _ResUtil::CoordHolder <int> charSpace;
69 _FontImpl::_FontImpl()
70 : _pCoordHolder(new (std::nothrow) _FontCoordHolder)
71 , _pNativeFont(new (std::nothrow) _Font)
73 if (_pNativeFont == null || _pCoordHolder == null)
83 _FontImpl::_FontImpl(const _FontImpl& obj)
84 : _pCoordHolder(new (std::nothrow) _FontCoordHolder)
89 *_pCoordHolder = *obj._pCoordHolder;
92 _pNativeFont = obj._pNativeFont->CloneN();
94 if (_pNativeFont == null || _pCoordHolder == null)
100 _pCoordHolder = null;
104 _FontImpl::~_FontImpl()
114 delete _pCoordHolder;
120 _FontImpl::Construct(int style, int vcSize)
122 IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY);
125 int pcSize = _ResUtil::ConvertToPhyCoordHeight(CONVERT_INTEGER_TO_26_6_FIXED_POINT(vcSize));
126 if (vcSize > 0 && pcSize <= CONVERT_INTEGER_TO_26_6_FIXED_POINT(1))
128 pcSize = CONVERT_INTEGER_TO_26_6_FIXED_POINT(1);
131 result r = _pNativeFont->Construct(style, pcSize);
132 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Failed to construct _Font", GetErrorMessage(r));
134 _pCoordHolder->Reset(vcSize);
140 _FontImpl::Construct(const Tizen::Base::String& fontName, int style, int vcSize, bool isPathEnabled)
142 IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY);
145 int pcSize = _ResUtil::ConvertToPhyCoordHeight(CONVERT_INTEGER_TO_26_6_FIXED_POINT(vcSize));
146 if (vcSize > 0 && pcSize <= CONVERT_INTEGER_TO_26_6_FIXED_POINT(1))
148 pcSize = CONVERT_INTEGER_TO_26_6_FIXED_POINT(1);
151 result r = _pNativeFont->Construct(fontName, style, pcSize, isPathEnabled);
152 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Failed to construct _Font", GetErrorMessage(r));
154 _pCoordHolder->Reset(vcSize);
160 _FontImpl::Construct(const Tizen::Base::ByteBuffer& fontData, int style, int vcSize)
162 IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY);
165 int pcSize = _ResUtil::ConvertToPhyCoordHeight(CONVERT_INTEGER_TO_26_6_FIXED_POINT(vcSize));
166 if (vcSize > 0 && pcSize <= CONVERT_INTEGER_TO_26_6_FIXED_POINT(1))
168 pcSize = CONVERT_INTEGER_TO_26_6_FIXED_POINT(1);
171 result r = _pNativeFont->Construct(fontData, style, pcSize);
172 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Failed to construct _Font", GetErrorMessage(r));
174 _pCoordHolder->Reset(vcSize);
180 _FontImpl::IsConstructed(void) const
182 IF_NOT_CONSTRUCTED(return false);
188 _FontImpl::GetMaxHeight(void) const
190 IF_NOT_CONSTRUCTED(return -1);
192 int pcMaxHeight = _pNativeFont->GetMaxHeight();
193 int vcMaxHeight = _ResUtil::ConvertToVirCoordY(pcMaxHeight);
199 _FontImpl::GetMaxWidth(void) const
201 IF_NOT_CONSTRUCTED(return -1);
203 int pcMaxWidth = _pNativeFont->GetMaxWidth();
204 int vcMaxWidth = _ResUtil::ConvertToVirCoordX(pcMaxWidth);
210 _FontImpl::GetAscender(void) const
212 IF_NOT_CONSTRUCTED(return -1);
214 int pcAscender = _pNativeFont->GetAscender();
215 int vcAscender = _ResUtil::ConvertToVirCoordY(pcAscender);
221 _FontImpl::GetDescender(void) const
223 IF_NOT_CONSTRUCTED(return -1);
225 int pcDescender = _pNativeFont->GetDescender();
226 int vcDescender = _ResUtil::ConvertToVirCoordY(pcDescender);
236 _FontImpl::GetLeftBear(wchar_t character, int& vcLeftBear) const
238 IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
241 result r = _pNativeFont->GetLeftBear(character, pcLeftBear);
244 vcLeftBear = _ResUtil::ConvertToVirCoordX(pcLeftBear);
250 _FontImpl::GetRightBear(wchar_t character, int& vcRightBear) const
252 IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
255 result r = _pNativeFont->GetRightBear(character, pcRightBear);
258 vcRightBear = _ResUtil::ConvertToVirCoordX(pcRightBear);
264 _FontImpl::GetTextExtent(const Tizen::Base::String& text, int length, Dimension& vcDim) const
266 IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
268 if (_ResUtil::NeedToConvertCoord())
271 result r = _pNativeFont->GetTextExtent(text, length, pcDim);
275 vcDim = _ResUtil::ConvertToVirCoord(pcDim);
282 return _pNativeFont->GetTextExtent(text, length, vcDim);
287 _FontImpl::IsBold(void) const
289 IF_NOT_CONSTRUCTED(return false);
291 return _pNativeFont->IsBold();
295 _FontImpl::IsItalic(void) const
297 IF_NOT_CONSTRUCTED(return false);
299 return _pNativeFont->IsItalic();
303 _FontImpl::IsPlain(void) const
305 IF_NOT_CONSTRUCTED(return false);
307 return _pNativeFont->IsPlain();
311 _FontImpl::IsStrikeOut(void) const
313 IF_NOT_CONSTRUCTED(return false);
315 return _pNativeFont->IsStrikeOut();
319 _FontImpl::IsUnderlined(void) const
321 IF_NOT_CONSTRUCTED(return false);
323 return _pNativeFont->IsUnderlined();
327 _FontImpl::GetSize(void) const
329 IF_NOT_CONSTRUCTED(return -1);
331 if (_ResUtil::NeedToConvertCoord())
333 return _pCoordHolder->size.required;
337 return _pNativeFont->GetSize();
342 _FontImpl::SetStrikeOut(bool strikeOut)
344 IF_NOT_CONSTRUCTED(return);
346 return _pNativeFont->SetStrikeOut(strikeOut);
350 _FontImpl::SetUnderline(bool underline)
352 IF_NOT_CONSTRUCTED(return);
354 return _pNativeFont->SetUnderline(underline);
358 _FontImpl::SetCharSpace(int vcSpace)
360 IF_NOT_CONSTRUCTED(return);
363 _pCoordHolder->charSpace = vcSpace;
366 int pcSpace = _ResUtil::ConvertToPhyCoordWidth(vcSpace);
368 return _pNativeFont->SetCharSpace(pcSpace);
372 _FontImpl::GetCharSpace(void) const
374 IF_NOT_CONSTRUCTED(return 0);
376 if (_ResUtil::NeedToConvertCoord())
378 return _pCoordHolder->charSpace.required;
382 return _pNativeFont->GetCharSpace();
387 _FontImpl::GetFaceName(void) const
389 IF_NOT_CONSTRUCTED(return "");
391 return _pNativeFont->GetFaceName();
394 Tizen::Base::Collection::IList*
395 _FontImpl::GetSystemFontListN(void)
397 return _Font::GetSystemFontListN();
401 _FontImpl::GetFaceName(const Tizen::Base::String& filePath)
403 return _Font::GetFaceName(filePath);
407 _FontImpl::CloneN(void)
409 IF_NOT_CONSTRUCTED(return null);
411 std::auto_ptr<_FontImpl> pFontImpl(new (std::nothrow) _FontImpl(*this));
413 SysTryReturn(NID_GRP, pFontImpl.get(), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocated memory");
414 SysTryReturn(NID_GRP, pFontImpl->_pNativeFont, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] FontEx::CloneN() has been failed");
416 return pFontImpl.release();
420 _FontImpl::CloneN(const Font& font)
422 // check the validation of input param
423 SysTryReturn(NID_GRP, font.__pImpl && font.__pImpl->IsConstructed(), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid input param given");
425 // make sure if the copy construction is well done
426 std::auto_ptr<Font> pFont(new (std::nothrow) Font(font));
428 SysTryReturn(NID_GRP, pFont.get() && pFont->__pImpl && pFont->__pImpl->IsConstructed(), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory");
430 return pFont.release();
434 _FontImpl::GetTextExtent(int vcWidth, const Tizen::Base::String& text, int startIndex, int length, bool outline, int& count, Dimension& vcDim) const
436 IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
438 SysTryReturnResult(NID_GRP, startIndex >= 0 && length >= 0 && startIndex < text.GetLength(), E_OUT_OF_RANGE,
439 "The length(%d) & startIndex(%d) of the given text is out of range", length, startIndex);
441 if (_ResUtil::NeedToConvertCoord())
443 int pcWidth = _ResUtil::ToPhyCoordW(vcWidth);
445 result r = _pNativeFont->GetTextExtent(pcWidth, text, startIndex, length, outline, count, pcDim);
449 vcDim = _ResUtil::ConvertToVirCoord(pcDim);
456 return _pNativeFont->GetTextExtent(vcWidth, text, startIndex, length, outline, count, vcDim);
461 _FontImpl::GetTextExtent(int vcWidth, const Tizen::Base::String& text, int startIndex, int length, bool outline, const Tizen::Base::String& delimiter, int& count, Dimension& vcDim) const
463 IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
465 SysTryReturnResult(NID_GRP, startIndex >= 0 && length >= 0 && startIndex < text.GetLength(), E_OUT_OF_RANGE,
466 "The length(%d) & startIndex(%d) of the given text is out of range", length, startIndex);
468 if (_ResUtil::NeedToConvertCoord())
470 int pcWidth = _ResUtil::ToPhyCoordW(vcWidth);
472 result r = _pNativeFont->GetTextExtent(pcWidth, text, startIndex, length, outline, delimiter, count, pcDim);
476 vcDim = _ResUtil::ConvertToVirCoord(pcDim);
483 return _pNativeFont->GetTextExtent(vcWidth, text, startIndex, length, outline, delimiter, count, vcDim);
488 _FontImpl::SetSize(int vcSize)
490 IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
491 SysTryReturnResult(NID_GRP, vcSize > 0, E_INVALID_ARG, "font size should be greater than 0");
493 _pCoordHolder->Reset(vcSize);
496 int pcSize = _ResUtil::ConvertToPhyCoordHeight(CONVERT_INTEGER_TO_26_6_FIXED_POINT(vcSize));
497 if (vcSize > 0 && pcSize <= CONVERT_INTEGER_TO_26_6_FIXED_POINT(1))
499 pcSize = CONVERT_INTEGER_TO_26_6_FIXED_POINT(1);
500 _pCoordHolder->size.phyCoord = pcSize;
501 _pCoordHolder->size.virCoord = vcSize;
504 result r = _pNativeFont->SetSize(pcSize);
505 SysTryReturnResult(NID_GRP, r == E_SUCCESS, E_SYSTEM, "Failed to set the size of _Font");
511 _FontImpl::SetStyle(int style)
513 IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
514 SysTryReturnResult(NID_GRP, style > FONT_STYLE_MIN && style <= (FONT_STYLE_PLAIN | FONT_STYLE_BOLD | FONT_STYLE_ITALIC), E_INVALID_ARG,
515 "Style(%d) is invalid", style);
517 result r = _pNativeFont->SetStyle(style);
518 SysTryReturnResult(NID_GRP, r == E_SUCCESS, E_SYSTEM, "Failed to set the style of _Font");
524 _FontImpl::GetStyle(void) const
526 IF_NOT_CONSTRUCTED(return FONT_STYLE_PLAIN);
528 return _pNativeFont->GetStyle();
532 _FontImpl::GetLeading(void) const
534 IF_NOT_CONSTRUCTED(return -1);
536 int pcLeading = _pNativeFont->GetLeading();
537 int vcLeading = _ResUtil::ConvertToVirCoordY(pcLeading);
543 _FontImpl::GetInstance(Font& font)
545 return (&font != null) ? font.__pImpl : null;
549 _FontImpl::GetInstance(const Font& font)
551 return (&font != null) ? font.__pImpl : null;
555 _FontImpl::UpdateDefaultFont(const Tizen::Base::String& key)
557 return _Font::UpdateDefaultFont(key);
560 }} // Tizen::Graphics