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_TextTextImage.cpp
20 * @brief This is the implementation file for TextImage class.
24 #include <FGrpBitmap.h>
25 #include <FBaseSysLog.h>
26 #include "FGrp_BitmapImpl.h"
27 #include "FGrp_CanvasImpl.h"
28 #include "FGrp_TextCommon.h"
29 #include "FGrp_TextTextElement.h"
30 #include "FGrp_TextTextImage.h"
31 #include "../FGrp_BitmapUtil.h"
32 #include "../FGrp_Canvas.h"
34 namespace Tizen { namespace Graphics
40 TextImage::TextImage(Bitmap& bitmap, TextElementSourceType sourceType, Rectangle* pRect, TextObjectAlignment align)
44 _type = TEXT_ELEMENT_TYPE_IMAGE;
45 _sourceType = sourceType;
48 _isAlternateLookEnabled = false;
52 if (sourceType == TEXT_ELEMENT_SOURCE_TYPE_INTERNAL)
54 __pBitmap = new (std::nothrow) Bitmap();
57 , , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
59 r = __pBitmap->Construct(bitmap, Rectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight()));
62 , , r, "[%s] Propagating.", GetErrorMessage(r));
73 __rect.width = __pBitmap->GetWidth();
74 __rect.height = __pBitmap->GetHeight();
90 TextImage::~TextImage(void)
92 if (_sourceType == TEXT_ELEMENT_SOURCE_TYPE_INTERNAL)
103 TextImage::ForwardAnalyze(int startTextIndex, int textLength, int maxWidth, TextObjectWrapType wrap, int& actualLength,
104 int& width, int& height)
107 , 0 <= startTextIndex && startTextIndex < _length
108 , -1, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
111 , textLength <= _length
112 , -1, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
120 return TEXT_RETBY_NORMAL;
123 if (maxWidth < __rect.width)
125 return TEXT_RETBY_OVERWIDTH;
130 width = __rect.width;
131 height = __rect.height;
134 return TEXT_RETBY_NORMAL;
138 TextImage::GetRegion(int textIndex, int textLength, int& width, int& height) const
141 , 0 <= textIndex && textIndex < _length
142 , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
145 , textLength <= _length
146 , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
155 width = __rect.width;
156 height = __rect.height;
162 TextImage::GetBlockRegion(int textIndex, int textLength, int& width, int& height) const
164 return GetRegion(textIndex, textLength, width, height);
168 TextImage::GetHeight(void) const
170 return __rect.height;
174 TextImage::Draw(_CanvasImpl& canvasImpl, Rectangle& displayRect, int startTextIndex, int textLength, const TextObjectAlignment align, const TextObjectActionType action)
178 , E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] This instance is not constructed yet.");
180 result r = E_SUCCESS;
186 _Canvas* pCanvas = _Canvas::GetInstance(canvasImpl);
189 , E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Fail to get native canvas instance.");
192 Rectangle bitmapRect = displayRect;
194 if (bitmapRect.width <= 0)
196 bitmapRect.width = __rect.width;
198 if (bitmapRect.height <= 0)
200 bitmapRect.height = __rect.height;
203 if (bitmapRect.width > __rect.width)
205 bitmapRect.width = __rect.width;
207 if (bitmapRect.height > __rect.height)
209 bitmapRect.height = __rect.height;
212 switch (__align & TEXT_ALIGNMASK_VERT)
214 case TEXT_OBJECT_ALIGNMENT_TOP:
219 case TEXT_OBJECT_ALIGNMENT_MIDDLE:
220 bitmapRect.y = (bitmapRect.height - __pBitmap->GetHeight()) / 2;
223 case TEXT_OBJECT_ALIGNMENT_BOTTOM:
224 bitmapRect.y = (bitmapRect.height - __pBitmap->GetHeight());
228 switch (__align & TEXT_ALIGNMASK_HORIZ)
230 case TEXT_OBJECT_ALIGNMENT_LEFT:
235 case TEXT_OBJECT_ALIGNMENT_CENTER:
236 bitmapRect.x = (bitmapRect.width - __pBitmap->GetWidth()) / 2;
239 case TEXT_OBJECT_ALIGNMENT_RIGHT:
240 bitmapRect.x = (bitmapRect.width - __pBitmap->GetWidth());
244 r = pCanvas->DrawBitmap(bitmapRect, *GetBitmapEx(*_BitmapImpl::GetInstance(*__pBitmap)));
247 , r, r, "[%s] Propagating.", GetErrorMessage(r));
251 r = pCanvas->DrawRectangle(_Util::Convert<Rectangle, _Util::Rectangle<double> >(bitmapRect));
254 , r, r, "[%s] Propagating.", GetErrorMessage(r));
261 TextImage::CloneN(TextComponentInfoValueType type, unsigned int value)
263 SysTryReturn(NID_GRP, __pBitmap, null, E_SYSTEM, "[E_SYSTEM] Failed to clone image.");
265 TextImage* pImageText = null;
267 pImageText = new (std::nothrow) TextImage(*__pBitmap, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, &__rect, __align);
270 , null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
272 TextElement::CopyMembers(pImageText);
274 pImageText->SetValue(type, value);
280 TextImage::CopyN(int startTextIndex, int textLength)
282 SysTryReturn(NID_GRP, __pBitmap, null, E_SYSTEM, "[E_SYSTEM] Failed to copy image.");
284 if (startTextIndex != 0)
294 TextImage* pImageText = null;
296 pImageText = new (std::nothrow) TextImage(*__pBitmap, _sourceType, &__rect, __align);
299 , null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
305 TextImage::GetValue(TextComponentInfoValueType type) const
309 case SET_IMAGE_ALIGN:
311 return (unsigned int) __align;
315 return (unsigned int) &__rect;
317 case SET_ALTERNATE_LOOK:
319 return (unsigned int) _isAlternateLookEnabled;
321 case SET_TEXT_OFFSET:
324 case SET_ALTERNATIVE_FGCOLOR:
335 TextImage::SetValue(TextComponentInfoValueType type, unsigned int value)
339 case SET_IMAGE_ALIGN:
340 __align = (TextObjectAlignment) value;
346 case SET_TEXT_OFFSET:
349 case SET_ALTERNATE_LOOK:
350 _isAlternateLookEnabled = (bool) value;
353 case SET_ALTERNATIVE_FGCOLOR:
364 TextImage::SetBounds(const Rectangle& rect)
374 TextImage::SetAlignment(TextObjectAlignment alignment)
377 , TEXT_OBJECT_ALIGNMENT_LEFT <= alignment && alignment <= TEXT_OBJECT_ALIGNMENT_BOTTOM
378 , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
386 TextImage::GetBounds(void) const
392 TextImage::GetAlignment(void) const
398 TextImage::GetBitmap(void) const
404 TextImage::SetTextLength(int length)
410 TextImage::GetBaseline(void) const
415 }}} // Tizen::Graphics::_Text