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_TextTextUtility.cpp
20 * @brief This is the implementation file for TextUtility class.
24 #include <FBaseSysLog.h>
25 #include "../FGrp_Canvas.h"
26 #include "FGrp_FontImpl.h"
27 #include "FGrp_TextCommon.h"
28 #include "FGrp_TextTextSimple.h"
29 #include "FGrp_TextTextUtility.h"
31 using namespace Tizen::Base::Utility;
32 using namespace Tizen::Base;
34 namespace Tizen { namespace Graphics
40 TextUtility::GetObjectTypeFromValueType(TextComponentInfoValueType type)
42 if (type < MAX_TEXTOBJECT_VALUE)
44 return TEXT_ELEMENT_TYPE_TEXT;
46 else if (type < MAX_IMAGEOBJECT_VALUE)
48 return TEXT_ELEMENT_TYPE_IMAGE;
51 return TEXT_ELEMENT_TYPE_MAX;
55 TextUtility::CanMerge(TextElement* pCurrentTextElement, TextElement* pNextTextElement)
58 , pCurrentTextElement && pCurrentTextElement->GetType() == TEXT_ELEMENT_TYPE_TEXT
59 , false, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
62 , pNextTextElement && pNextTextElement->GetType() == TEXT_ELEMENT_TYPE_TEXT
63 , false, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
65 TextSimple* pCurrentSimpleText = dynamic_cast < TextSimple* >(pCurrentTextElement);
66 TextSimple* pNextSimpleText = dynamic_cast < TextSimple* >(pNextTextElement);
67 if (pCurrentSimpleText == null || pNextSimpleText == null)
72 if (pCurrentSimpleText->GetTextSource() != pNextSimpleText->GetTextSource())
77 if (!IsSameFontAttribute(pCurrentSimpleText->GetFont(), pNextSimpleText->GetFont()))
82 if (pCurrentSimpleText->GetForegroundColor() != pNextSimpleText->GetForegroundColor())
87 if (pCurrentSimpleText->GetBackgroundColor() != pNextSimpleText->GetBackgroundColor())
92 if (pCurrentSimpleText->GetBitmap() != null || pNextSimpleText->GetBitmap() != null)
101 TextUtility::IsSameFontAttribute(const Font* pFontSrc, const Font* pFontTarget)
103 if (pFontSrc->GetSize() != pFontTarget->GetSize())
108 if (pFontSrc->IsBold() != pFontTarget->IsBold())
113 if (pFontSrc->IsItalic() != pFontTarget->IsItalic())
118 if (pFontSrc->IsPlain() != pFontTarget->IsPlain())
123 if (pFontSrc->IsStrikeOut() != pFontTarget->IsStrikeOut())
128 if (pFontSrc->IsUnderlined() != pFontTarget->IsUnderlined())
137 TextUtility::GetFontMaxHeight(Font* pFont)
144 _Font* pNativeFont = _Font::GetInstance(*_FontImpl::GetInstance(*pFont));
147 , -1, E_SYSTEM, "[E_SYSTEM] Fail to get native font instance.");
149 return pNativeFont->GetLeading();
153 TextUtility::GetFontMaxHeight(_Font* pFont)
160 return pFont->GetLeading();
164 TextUtility::GetTextLength(const wchar_t* pText)
168 while (*(pText + count) != 0)
177 TextUtility::GetCharCountInWidth(_Font* pFont, const wchar_t* pText, int textLength, int maxWidth, bool outline, int& width, int& height)
184 result r = E_SUCCESS;
186 Dimension lineDimension;
187 Tizen::Base::String text(pText);
189 r = pFont->GetTextExtent(maxWidth, text, 0, textLength, outline, L"", count, lineDimension);
192 , , r, "[%s] Propagating.", GetErrorMessage(r));
194 width = lineDimension.width;
195 height = pFont->GetLeading();
197 SetLastResult(E_SUCCESS);
208 TextUtility::CopyText(wchar_t* pDstText, const wchar_t* pSrcText, int textLength)
211 , pDstText && pSrcText
212 , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
214 int srcTextLength = 0;
217 srcTextLength = GetTextLength(pSrcText);
218 if (srcTextLength < textLength)
220 textLength = srcTextLength;
233 if (--textLength == 0)
248 while (0 < --textLength);
254 TextUtility::CopyText(wchar_t* pDstText, const wchar_t* pSrcText)
257 , pDstText && pSrcText
258 , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
275 TextUtility::DrawText(_Canvas& canvas, int x, int y, const wchar_t* pText, int textLength)
277 result r = E_SUCCESS;
280 Tizen::Base::String text(pText);
282 if (pText[textLength - 1] == TEXT_LINE_FEED || pText[textLength - 1] == TEXT_CARRIAGE_RETURN)
287 r = canvas.DrawText(point, text, 0, textLength);
290 , r, r, "[%s] Propagating.", GetErrorMessage(r));
296 TextUtility::DrawOutlineText(_Canvas& canvas, int x, int y, const wchar_t* pText, int textLength, Color outlineColor)
298 result r = E_SUCCESS;
301 Tizen::Base::String text(pText);
303 if (pText[textLength - 1] == TEXT_LINE_FEED || pText[textLength - 1] == TEXT_CARRIAGE_RETURN)
308 r = canvas.DrawText(point, text, 0, textLength, outlineColor);
311 , r, r, "[%s] Propagating.", GetErrorMessage(r));
317 TextUtility::GetTextExtent(_Font* pFont, const wchar_t* pText, int textLength, bool outline, int& width, int& height)
321 , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
323 result r = E_SUCCESS;
324 Dimension lineDimension;
325 Tizen::Base::String text(pText);
327 r = pFont->GetTextExtent(text, textLength, lineDimension);
330 , , r, "[%s] Propagating.", GetErrorMessage(r));
332 width = lineDimension.width;
333 height = pFont->GetLeading();
344 TextUtility::GetTextExtent(Font* pFont, const wchar_t* pText, int textLength, bool outline, int& width, int& height)
348 , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
350 result r = E_SUCCESS;
352 Dimension lineDimension;
353 Tizen::Base::String text(pText);
355 _Font* pNativeFont = _Font::GetInstance(*_FontImpl::GetInstance(*pFont));
358 , -1, E_SYSTEM, "[E_SYSTEM] Fail to get native font instance.");
360 r = pNativeFont->GetTextExtent((Integer::VALUE_MAX >> 1) - 1, text, 0, textLength, outline, L"", count, lineDimension);
363 , , r, "[%s] Propagating.", GetErrorMessage(r));
365 width = lineDimension.width;
366 height = pNativeFont->GetLeading();
376 }}} // Tizen::Graphics::_Text