#include <new>
#include <memory>
+#include <pthread.h>
#include <FGrpFont.h>
-
#include <FBaseSysLog.h>
+#include <FBaseRtMutex.h>
#include "FGrp_FontImpl.h"
#include "FGrp_Font.h"
#include "FGrp_ResUtil.h"
+using namespace Tizen::Base::Runtime;
+
#define IF_NOT_INITIALIZED(code) if (this->_pNativeFont == null || this->_pCoordHolder == null) \
{ \
code; \
}
#define IsSucceeded(X) (!IsFailed(X))
+
+#if 1
+#define CRITICAL_SECTION _MutexGuard __mutexGuard__
+#else
+#define CRITICAL_SECTION
+#endif
+
+
namespace Tizen { namespace Graphics
{
+class _MutexGuard
+{
+public:
+ _MutexGuard()
+ {
+ Mutex* pMutex = GetMutexInstance();
+ pMutex->Acquire();
+ }
+
+ ~_MutexGuard()
+ {
+ Mutex* pMutex = GetMutexInstance();
+ pMutex->Release();
+ }
+
+private:
+ static void __InitCreateMutex(void)
+ {
+ static Mutex mutex;
+ mutex.Create();
+ _MutexGuard::pMutexInstance = &mutex;
+ }
+
+ static Mutex* GetMutexInstance(void)
+ {
+ static pthread_once_t once_block = PTHREAD_ONCE_INIT;
+
+ if (_MutexGuard::pMutexInstance == null)
+ {
+ pthread_once(&once_block, __InitCreateMutex);
+ }
+
+ return _MutexGuard::pMutexInstance;
+ }
+
+public:
+ static Mutex* pMutexInstance;
+};
+
+Mutex* _MutexGuard::pMutexInstance = null;
+
+
struct _FontCoordHolder
{
_ResUtil::CoordHolder <int> size;
result
_FontImpl::Construct(int style, int vcSize)
{
+ CRITICAL_SECTION;
IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY);
// convert VC -> PC
result
_FontImpl::Construct(const Tizen::Base::String& fontName, int style, int vcSize, bool isPathEnabled)
{
+ CRITICAL_SECTION;
IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY);
// convert VC -> PC
result
_FontImpl::Construct(const Tizen::Base::ByteBuffer& fontData, int style, int vcSize)
{
+ CRITICAL_SECTION;
IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY);
// convert VC -> PC
result
_FontImpl::Construct(int style, float vcSize)
{
+ CRITICAL_SECTION;
IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY);
// convert VC -> PC
result
_FontImpl::Construct(const Tizen::Base::String& fontName, int style, float vcSize, bool isPathEnabled)
{
+ CRITICAL_SECTION;
IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY);
// convert VC -> PC
result
_FontImpl::Construct(const Tizen::Base::ByteBuffer& fontData, int style, float vcSize)
{
+ CRITICAL_SECTION;
IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY);
// convert VC -> PC
bool
_FontImpl::IsConstructed(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return false);
return true;
int
_FontImpl::GetMaxHeight(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return -1);
int pcMaxHeight = _DoubleToIntForPos(ceil(_pNativeFont->GetMaxHeight().ToDouble()));
float
_FontImpl::GetMaxHeightF(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return -1.0f);
float pcMaxHeight = float(ceil(_pNativeFont->GetMaxHeight().ToDouble()));
int
_FontImpl::GetMaxWidth(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return -1);
int pcMaxWidth = _pNativeFont->GetMaxWidth().ToInt();
float
_FontImpl::GetMaxWidthF(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return -1.0f);
float pcMaxWidth = _pNativeFont->GetMaxWidth().ToFloat();
int
_FontImpl::GetAscender(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return -1);
int pcAscender = _pNativeFont->GetAscender().ToInt();
float
_FontImpl::GetAscenderF(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return -1.0f);
float pcAscender = _pNativeFont->GetAscender().ToFloat();
int
_FontImpl::GetDescender(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return -1);
int pcDescender = _pNativeFont->GetDescender().ToInt();
float
_FontImpl::GetDescenderF(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return -1.0f);
float pcDescender = _pNativeFont->GetDescender().ToFloat();
result
_FontImpl::GetLeftBear(wchar_t character, int& vcLeftBear) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
_Util::FixedPoint22_10 pcLeftBear(0);
result
_FontImpl::GetLeftBear(wchar_t character, float& vcLeftBear) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
_Util::FixedPoint22_10 pcLeftBear(0);
result
_FontImpl::GetRightBear(wchar_t character, int& vcRightBear) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
_Util::FixedPoint22_10 pcRightBear(0);
result
_FontImpl::GetRightBear(wchar_t character, float& vcRightBear) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
_Util::FixedPoint22_10 pcRightBear(0);
result
_FontImpl::GetTextExtent(const Tizen::Base::String& text, int length, Dimension& vcDim, bool outline) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
int dummyCount = 0 ;
result
_FontImpl::GetTextExtent(const Tizen::Base::String& text, int length, FloatDimension& vcDim, bool outline) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
int dummyCount = 0;
bool
_FontImpl::IsBold(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return false);
return _pNativeFont->IsBold();
bool
_FontImpl::IsItalic(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return false);
return _pNativeFont->IsItalic();
bool
_FontImpl::IsPlain(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return false);
return _pNativeFont->IsPlain();
bool
_FontImpl::IsStrikeOut(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return false);
return _pNativeFont->IsStrikeOut();
bool
_FontImpl::IsUnderlined(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return false);
return _pNativeFont->IsUnderlined();
int
_FontImpl::GetSize(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return -1);
return _pCoordHolder->size.required;
float
_FontImpl::GetSizeF(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return -1.0f);
return _pCoordHolder->sizeF.required;
void
_FontImpl::SetStrikeOut(bool strikeOut)
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return);
_pNativeFont->SetStrikeOut(strikeOut);
void
_FontImpl::SetUnderline(bool underline)
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return);
_pNativeFont->SetUnderline(underline);
void
_FontImpl::SetCharSpace(int vcSpace)
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return);
// save it
void
_FontImpl::SetCharSpace(float vcSpace)
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return);
// save it
int
_FontImpl::GetCharSpace(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return 0);
return _pCoordHolder->charSpace.required;
float
_FontImpl::GetCharSpaceF(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return 0.0f);
return _pCoordHolder->charSpaceF.required;
Tizen::Base::String
_FontImpl::GetFaceName(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return "");
return _pNativeFont->GetFaceName();
Tizen::Base::Collection::IList*
_FontImpl::GetSystemFontListN(void)
{
+ CRITICAL_SECTION;
return _Font::GetSystemFontListN();
}
Tizen::Base::String
_FontImpl::GetFaceName(const Tizen::Base::String& filePath)
{
+ CRITICAL_SECTION;
return _Font::GetFaceName(filePath);
}
_FontImpl*
_FontImpl::CloneN(void)
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return null);
std::auto_ptr<_FontImpl> pFontImpl(new (std::nothrow) _FontImpl(*this));
Font*
_FontImpl::CloneN(const Font& font)
{
+ CRITICAL_SECTION;
+
// check the validation of input param
SysTryReturn(NID_GRP, font.__pImpl && font.__pImpl->IsConstructed(), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid input param given");
result
_FontImpl::GetTextExtent(int vcWidth, const Tizen::Base::String& text, int startIndex, int length, bool outline, int& count, Dimension& vcDim) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
SysTryReturnResult(NID_GRP, startIndex >= 0 && length >= 0 && startIndex < text.GetLength(), E_OUT_OF_RANGE,
result
_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
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
SysTryReturnResult(NID_GRP, startIndex >= 0 && length >= 0 && startIndex < text.GetLength(), E_OUT_OF_RANGE,
result
_FontImpl::GetTextExtent(float vcWidth, const Tizen::Base::String& text, int startIndex, int length, bool outline, int& count, FloatDimension& vcDim) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
SysTryReturnResult(NID_GRP, startIndex >= 0 && length >= 0 && startIndex < text.GetLength(), E_OUT_OF_RANGE,
result
_FontImpl::GetTextExtent(float vcWidth, const Tizen::Base::String& text, int startIndex, int length, bool outline, const Tizen::Base::String& delimiter, int& count, FloatDimension& vcDim) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
SysTryReturnResult(NID_GRP, startIndex >= 0 && length >= 0 && startIndex < text.GetLength(), E_OUT_OF_RANGE,
result
_FontImpl::SetSize(int vcSize)
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
SysTryReturnResult(NID_GRP, vcSize > 0, E_INVALID_ARG, "Font size should be greater than 0");
result
_FontImpl::SetSize(float vcSize)
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
SysTryReturnResult(NID_GRP, vcSize > 0.0f, E_INVALID_ARG, "Font size should be greater than 0");
result
_FontImpl::SetStyle(int style)
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
SysTryReturnResult(NID_GRP, style > FONT_STYLE_MIN && style <= (FONT_STYLE_PLAIN | FONT_STYLE_BOLD | FONT_STYLE_ITALIC), E_INVALID_ARG,
"Style(%d) is invalid", style);
int
_FontImpl::GetStyle(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return FONT_STYLE_PLAIN);
return _pNativeFont->GetStyle();
int
_FontImpl::GetLeading(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return -1);
int pcLeading = _DoubleToIntForPos(ceil(_pNativeFont->GetLeading().ToDouble()));
float
_FontImpl::GetLeadingF(void) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return -1.0f);
float pcLeading = float(ceil(_pNativeFont->GetLeading().ToDouble()));
_FontImpl*
_FontImpl::GetInstance(Font& font)
{
+ CRITICAL_SECTION;
return (&font != null) ? font.__pImpl : null;
}
const _FontImpl*
_FontImpl::GetInstance(const Font& font)
{
+ CRITICAL_SECTION;
return (&font != null) ? font.__pImpl : null;
}
bool
_FontImpl::UpdateDefaultFont(const Tizen::Base::String& key)
{
+ CRITICAL_SECTION;
return _Font::UpdateDefaultFont(key);
}
result
_FontImpl::GetTextExtentList(const Tizen::Base::String& string, int startIndex, int length, Tizen::Base::Collection::ArrayListT<_FloatPair>& outList) const
{
+ CRITICAL_SECTION;
IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
SysTryReturnResult(NID_GRP, startIndex >= 0 && length >= 0 && startIndex < string.GetLength(), E_OUT_OF_RANGE,