From fdbf6b99adf43b0d901663b4e289d6cf5d1ac4be Mon Sep 17 00:00:00 2001 From: Sungyeon Woo Date: Sat, 30 Mar 2013 17:09:11 +0900 Subject: [PATCH] remove unnecessary GetTextExtent code Change-Id: Ibc0500f25f4061b2445cdec62f9cd49023a58b00 Signed-off-by: Sungyeon Woo --- src/graphics/FGrp_Font.cpp | 154 +---------------------------------------- src/graphics/FGrp_Font.h | 3 - src/graphics/FGrp_FontImpl.cpp | 10 ++- 3 files changed, 8 insertions(+), 159 deletions(-) diff --git a/src/graphics/FGrp_Font.cpp b/src/graphics/FGrp_Font.cpp index 34e0531..a3d241c 100644 --- a/src/graphics/FGrp_Font.cpp +++ b/src/graphics/FGrp_Font.cpp @@ -745,158 +745,6 @@ _Font::GetRightBear(wchar_t character, _Util::FixedPoint22_10& rightBear) const return E_SUCCESS; } -result -_Font::GetTextExtent(const _Util::String& text, Dimension& pcDim) const -{ - IF_NOT_INITIALIZED(return E_OPERATION_FAILED); - - if (text.pStart == null || text.length <= 0) - { - pcDim.SetSize(0, 0); - - return E_SUCCESS; - } - - _TextBidiPropertyWithReorder bidiProperty(text.pStart, text.length); - - if (bidiProperty.HasBidi()) - { - int dummyCount = 0 ; - - return this->GetTextExtent(INT_MAX, text, false, dummyCount, pcDim); - } - else - { - return this->__GetTextExtent(text, pcDim); - } -} - -result -_Font::__GetTextExtent(const _Util::String& text, Dimension& pcDim) const -{ - if (text.pStart == null) - { - pcDim.SetSize(0, 0); - SysTryReturn(NID_GRP, false, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The given string is invalid."); - } - - int x1 = 0x7FFFFFFF; - int y1 = 0x7FFFFFFF; - int x2 = -0x7FFFFFFF; - int y2 = -0x7FFFFFFF; - - int curX = 0; - int curY = 0; - - int italicSpace = 0; - int boldSpace = 0; - - long xVec = 0; - long yVec = 0; - int left = 0; - wchar_t leftChar = 0; - - _IFont::Glyph* pFontGlyphData = 0; - - IF_NOT_INITIALIZED(return E_OPERATION_FAILED); - - _Font* pThis = const_cast <_Font*>(this); - - APPLY_ATTRIBUTE(E_SYSTEM); - - { - _IFont::SizeProperty sizeProperty; - GET_FONT_SIZE_PROPERTY(sizeProperty, E_SYSTEM); - - if (__fontAttrib.style & FONT_STYLE_ITALIC) - { - italicSpace = (sizeProperty.ascender.ToInt() * 2) >> 4; - } - } - - if (__fontAttrib.style & FONT_STYLE_BOLD) - { - _IFont::Attrib attr; - pThis->GetAttrib(attr); - boldSpace = static_cast(attr.boldWeight.ToFloat() + 0.5f); - } - - const wchar_t* pText = text.pStart; - int length = text.length; - - while (*pText && --length >= 0) - { - _IFont* pFont = pThis->__GetFont(*pText); - - if (pFont != __pNativeFont) - { - _IFont::Attrib fontAttrib; - bool rtn = pFont->GetAttrib(fontAttrib); - - fontAttrib.size = __fontAttrib.size; - fontAttrib.style = _IFont::STYLE_NONE; - fontAttrib.style |= (__fontAttrib.style & FONT_STYLE_BOLD) ? _IFont::STYLE_BOLD : 0; - fontAttrib.style |= (__fontAttrib.style & FONT_STYLE_ITALIC) ? _IFont::STYLE_ITALIC : 0; - fontAttrib.style |= (__fontAttrib.underline) ? _IFont::STYLE_UNDERLINE : 0; - rtn = pFont->SetAttrib(fontAttrib); - } - - if (left > 0) - { - if (pFont->GetKerning(leftChar, *pText, xVec, yVec)) - { - curX += xVec; - } - } - - if (pFont->LoadGlyph(*pText++, &pFontGlyphData)) - { - int glyphBoundX1 = curX; - int glyphBoundY1 = curY - pFontGlyphData->yOffset.ToInt(); - int glyphBoundX2 = glyphBoundX1 + pFontGlyphData->xOffset.ToInt() + pFontGlyphData->image.width; - int glyphBoundY2 = glyphBoundY1 + pFontGlyphData->image.height; - -#ifdef SYNCHRONIZATION_2_0 - // adjusting x bounds for synchronizing this operation with 2.0 - if (length == 0) - { - glyphBoundX2 = glyphBoundX1 + pFontGlyphData->xAdvance.ToInt() + italicSpace + boldSpace; - } -#endif // 2_0_SYNCHROMIZATION - - _ExpandBounds(glyphBoundX1, glyphBoundY1, x1, y1, x2, y2); - _ExpandBounds(glyphBoundX2, glyphBoundY1, x1, y1, x2, y2); - _ExpandBounds(glyphBoundX1, glyphBoundY2, x1, y1, x2, y2); - _ExpandBounds(glyphBoundX2, glyphBoundY2, x1, y1, x2, y2); - -#ifdef SYNCHRONIZATION_2_0 - curX += pFontGlyphData->xAdvance.ToInt() + __fontAttrib.charSpace + italicSpace + boldSpace; -#else - curX += pFontGlyphData->xAdvance.ToInt() + __fontAttrib.charSpace + boldSpace; -#endif - curY += pFontGlyphData->yAdvance.ToInt(); - left++; - leftChar = *(pText - 1); - - pFont->UnloadGlyph(&pFontGlyphData); - } - } - - SysTryCatch(NID_GRP, x1 <= x2 && y1 <= y2, pcDim.SetSize(0, 0), E_SYSTEM, "[E_SYSTEM] Failed to calculate text extent"); - - pcDim.width = x2 - x1; -#ifdef SYNCHRONIZATION_2_0 - pcDim.height = __fontAttrib.size.ToInt(); -#else - pcDim.height = y2 - y1; -#endif // 2_0_SYNCHROMIZATION - - return E_SUCCESS; - -CATCH: - return E_SYSTEM; -} - bool _Font::IsBold(void) const { @@ -1448,7 +1296,7 @@ _Font::__GetTextExtentList(const _Util::String& text, _Util::AccumList<_Util::Pa if (pFont->LoadGlyph(*pText, &pFontGlyphData)) { - // ¿ø·¡ Äڵ忡¼­´Â ¿¬¼ÓÀ¸·Î LoadGlyphÀÌ ½ÇÆÐÇÒ ¶§ ÀÌÀü °á°úÀÇ prevChar·Î kerningÀ» üũÇÏ´Â ¹®Á¦°¡ ÀÖÀ½ + // 원래 코드에서는 연속으로 LoadGlyph이 실패할 때 이전 결과의 prevChar로 kerning을 체크하는 문제가 있음 if (prevChar > 0) { long xVec = 0; diff --git a/src/graphics/FGrp_Font.h b/src/graphics/FGrp_Font.h index 3836bad..72a8fb0 100644 --- a/src/graphics/FGrp_Font.h +++ b/src/graphics/FGrp_Font.h @@ -112,8 +112,6 @@ public: result GetLeftBear(wchar_t character, _Util::FixedPoint22_10& leftBear) const; result GetRightBear(wchar_t character, _Util::FixedPoint22_10& rightBear) const; - result GetTextExtent(const _Util::String& text, Dimension& dim) const; - bool IsBold(void) const; bool IsItalic(void) const; bool IsPlain(void) const; @@ -181,7 +179,6 @@ private: _IFont* __GetFont(wchar_t character); bool __GetFallbackFontFileList(wchar_t character, Tizen::Base::Collection::IListT& out); - result __GetTextExtent(const _Util::String& text, Dimension& dim) const; result __GetTextExtent(int width, const _Util::String& text, bool outline, int& count, Dimension& dim) const; result __GetTextExtentList(const _Util::String& text, _Util::AccumList<_Util::Pair >& outList) const; diff --git a/src/graphics/FGrp_FontImpl.cpp b/src/graphics/FGrp_FontImpl.cpp index f8afc36..7b87444 100755 --- a/src/graphics/FGrp_FontImpl.cpp +++ b/src/graphics/FGrp_FontImpl.cpp @@ -430,10 +430,12 @@ _FontImpl::GetTextExtent(const Tizen::Base::String& text, int length, Dimension& { IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); + int dummyCount = 0 ; + if (_ResUtil::NeedToConvertCoord()) { Dimension pcDim; - result r = _pNativeFont->GetTextExtent(_Util::String(text.GetPointer(), text.GetLength(), 0, length), pcDim); + result r = _pNativeFont->GetTextExtent(INT_MAX, _Util::String(text.GetPointer(), text.GetLength(), 0, length), false, dummyCount, pcDim); if (IsSucceeded(r)) { @@ -444,7 +446,7 @@ _FontImpl::GetTextExtent(const Tizen::Base::String& text, int length, Dimension& } else { - return _pNativeFont->GetTextExtent(_Util::String(text.GetPointer(), text.GetLength(), 0, length), vcDim); + return _pNativeFont->GetTextExtent(INT_MAX, _Util::String(text.GetPointer(), text.GetLength(), 0, length), false, dummyCount, vcDim); } } @@ -453,8 +455,10 @@ _FontImpl::GetTextExtent(const Tizen::Base::String& text, int length, FloatDimen { IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); + int dummyCount = 0; Dimension pcDim; - result r = _pNativeFont->GetTextExtent(_Util::String(text.GetPointer(), text.GetLength(), 0, length), pcDim); + + result r = _pNativeFont->GetTextExtent(INT_MAX, _Util::String(text.GetPointer(), text.GetLength(), 0, length), false, dummyCount, pcDim); if (IsSucceeded(r)) { -- 2.7.4