Revert " modify license, permission and remove ^M char"
[framework/osp/uifw.git] / src / graphics / FGrp_EnrichedTextImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 /*
19  * @file        FGrp_EnrichedTextImpl.cpp
20  * @brief       This is the cpp file for _EnrichedTextImpl class.
21  *
22  */
23
24 // Inlcudes
25 #include <new>
26 #include "FGrp_EnrichedTextImpl.h"
27 #include "FGrp_TextElementImpl.h"
28 #include "FGrp_TextTextElement.h"
29 #include "FGrp_TextTextObject.h"
30 #include "util/FGrp_Util.h"
31 #include "FGrp_CoordinateSystemUtils.h"
32
33 // Usings
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Utility;
36 using namespace Tizen::Graphics::_Text;
37 using namespace Tizen::Graphics;
38
39 namespace Tizen { namespace Graphics
40 {
41
42 _EnrichedTextImpl::_EnrichedTextImpl(void)
43 {
44         __width = 0;
45         __height = 0;
46         __lineSpace = 0;
47         __count = 0;
48         __verticalAlignment = TEXT_ALIGNMENT_VERTICAL_MIN;
49         __horizontalAlignment = TEXT_ALIGNMENT_HORIZONTAL_MIN;
50         __elementVerticalAlignment = TEXT_ALIGNMENT_VERTICAL_MIN;
51         __pLinkedListTextElementList = null;
52         __pTextElement = null;
53         __isCopiedEnrichedText = false;
54         __pLinkedListTextElementList = null;
55         __pTextElement = null;
56 }
57
58 _EnrichedTextImpl::~_EnrichedTextImpl(void)
59 {
60         if (GetTextElementCount() > 0)
61         {
62                 RemoveAllTextElements(false);
63         }
64
65         if (__pTextElement)
66         {
67                 delete __pTextElement;
68                 __pTextElement = null;
69         }
70
71         if (__pLinkedListTextElementList)
72         {
73                 delete __pLinkedListTextElementList;
74                 __pLinkedListTextElementList = null;
75         }
76 }
77
78 result
79 _EnrichedTextImpl::Construct(const Tizen::Graphics::Dimension& dim)
80 {
81         FloatDimension dimF = _CoordinateSystemUtils::ConvertToFloat(dim);
82
83         return Construct(dimF);
84 }
85
86 result
87 _EnrichedTextImpl::Construct(const Tizen::Graphics::FloatDimension& dim)
88 {
89         SysTryReturn(NID_GRP, (dim.width > 0.0f) && (dim.height > 0.0f), E_INVALID_ARG, E_INVALID_ARG
90                         , "[E_INVALID_ARG] The argument is invalid. (width = %d height = %d)", dim.width, dim.height);
91
92         result r = E_SUCCESS;
93
94         __width = dim.width;
95         __height = dim.height;
96         __lineSpace = 0.0f;
97
98         __pLinkedListTextElementList = new (std::nothrow) Tizen::Base::Collection::LinkedList;
99         SysTryCatch(NID_GRP
100                         , __pLinkedListTextElementList
101                         , r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Fails to create a element list.", GetErrorMessage(r));
102
103         __pTextElement = new (std::nothrow) TextElement();
104         SysTryCatch(NID_GRP
105                         , __pTextElement
106                         , r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Fails to create a element.", GetErrorMessage(r));
107
108         __pTextObject.reset(new (std::nothrow)TextObject);
109         SysTryCatch(NID_GRP
110                         , __pTextObject
111                         , r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Fails to create a TextObject.", GetErrorMessage(r));
112
113         __pTextObject->Construct();
114         __pTextObject->SetBounds(FloatRectangle(0.0f, 0.0f, __width, __height));
115         __pTextObject->SetCutLinkViewMode(true);
116         __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
117         __pTextObject->HideFrontSpace(TEXT_OBJECT_SPACE_HIDE_TYPE_ONE);
118
119         // this is only to manage user's bitmap
120         r = __elements.Construct();
121
122         return r;
123
124 CATCH:
125         if (__pLinkedListTextElementList)
126         {
127                 delete __pLinkedListTextElementList;
128                 __pLinkedListTextElementList = null;
129         }
130
131         if (__pTextElement)
132         {
133                 delete __pTextElement;
134                 __pTextElement = null;
135         }
136
137         return r;
138 }
139
140 result
141 _EnrichedTextImpl::InsertAt(int elementIndex, Tizen::Graphics::TextElement& element)
142 {
143         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
144                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
145         SysTryReturn(NID_GRP, elementIndex >= 0 && elementIndex <= GetTextElementCount()
146                         , E_INVALID_ARG, E_INVALID_ARG
147                         , "[E_INVALID_ARG] The argument is invalid.");
148
149         result r = E_SUCCESS;
150         int textLength = 0;
151         int count = 0;
152         _TextElementImpl* pTextElementImpl = _TextElementImpl::GetInstance(element);
153         if (pTextElementImpl == null)
154         {
155                 return E_INVALID_ARG;
156         }
157
158         if (pTextElementImpl->GetRegisteringEnrichedText() != null)
159         {
160                 return E_INVALID_ARG;
161         }
162         pTextElementImpl->SetRegisteringEnrichedText(this);
163
164         count = __pTextObject->GetElementCount();
165         if (elementIndex > count)
166         {
167                 return E_INVALID_ARG;
168         }
169
170         for (int i = 0; i < elementIndex; i++)
171         {
172                 _Text::TextElement* pTextComponent = __pTextObject->GetElementAtElementIndex(i);
173                 if (pTextComponent != null)
174                 {
175                         textLength = textLength + pTextComponent->GetTextLength();
176                 }
177         }
178
179         __pTextObject->InsertElementAt(textLength, *(pTextElementImpl->GetComponent()));
180         __pTextObject->Compose();
181
182         r = __pLinkedListTextElementList->InsertAt(element, elementIndex);
183
184         if (__isCopiedEnrichedText == false)
185         {
186                 if (__pTextElement)
187                 {
188                         __elements.InsertAt(*__pTextElement, elementIndex);
189                 }
190         }
191
192         return r;
193 }
194
195 result
196 _EnrichedTextImpl::RemoveAt(int elementIndex, bool deallocate)
197 {
198         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
199                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
200         SysTryReturn(NID_GRP, elementIndex >= 0 && elementIndex <= GetTextElementCount()
201                         , E_INVALID_ARG, E_INVALID_ARG
202                         , "[E_INVALID_ARG] The argument is invalid.");
203
204         if (__pTextObject.use_count() > 1)
205         {
206                 return E_SUCCESS;
207         }
208
209         result r = E_SUCCESS;
210         int count = GetTextElementCount();
211         TextElement* pTextElement = null;
212
213         if (count == 0)
214         {
215                 return E_SUCCESS;
216         }
217
218         pTextElement = dynamic_cast < TextElement* >(__pLinkedListTextElementList->GetAt(elementIndex));
219         if (pTextElement == null)   //Bitmap??
220         {
221                 __pTextObject->RemoveElementAt(elementIndex, true);
222                 __pLinkedListTextElementList->RemoveAt(elementIndex, true);
223
224                 if (__isCopiedEnrichedText == false)
225                 {
226                         __elements.RemoveAt(elementIndex, deallocate);
227                 }
228         }
229         else
230         {
231                 _TextElementImpl* pTextElementImpl = _TextElementImpl::GetInstance(*pTextElement);
232                 pTextElementImpl->SetRegisteringEnrichedText(null);
233                 _Text::TextElement* pTextComponent = pTextElementImpl->GetComponent();
234
235                 __pTextObject->RemoveElement(*pTextComponent, false);
236                 __pLinkedListTextElementList->RemoveAt(elementIndex, deallocate);
237
238                 if (__isCopiedEnrichedText == false)
239                 {
240                         __elements.RemoveAt(elementIndex, false);
241                 }
242         }
243
244         return r;
245 }
246
247 result
248 _EnrichedTextImpl::Remove(Tizen::Graphics::TextElement& element, bool deallocate)
249 {
250         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
251                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
252
253         if (__pTextObject.use_count() > 1)
254         {
255                 return E_SUCCESS;
256         }
257
258         int textElementIndex = 0;
259         result r = E_SUCCESS;
260         TextElement* pTextElement = null;
261
262         r = __pLinkedListTextElementList->IndexOf(element, textElementIndex);
263         if (r != E_SUCCESS)
264         {
265                 return E_INVALID_ARG;
266         }
267
268         pTextElement = dynamic_cast < TextElement* >(__pLinkedListTextElementList->GetAt(textElementIndex));
269         if (pTextElement)
270         {
271                 _TextElementImpl* pTextElementImpl = _TextElementImpl::GetInstance(*pTextElement);
272                 pTextElementImpl->SetRegisteringEnrichedText(null);
273                 _Text::TextElement* pTextComponent = pTextElementImpl->GetComponent();
274
275                 if (__pTextObject->RemoveElement(*pTextComponent, false) != E_SUCCESS)
276                 {
277                         return E_INVALID_ARG;
278                 }
279
280                 __pLinkedListTextElementList->RemoveAt(textElementIndex, deallocate);
281         }
282
283         return r;
284 }
285
286 result
287 _EnrichedTextImpl::Add(Tizen::Graphics::TextElement& element)
288 {
289         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
290
291         result r = E_SUCCESS;
292
293         _TextElementImpl* pTextElementImpl = _TextElementImpl::GetInstance(element);
294         SysTryReturn(NID_GRP
295                         , pTextElementImpl
296                         , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
297
298         _Text::TextElement* pTextComponent = pTextElementImpl->GetComponent();
299         SysTryReturn(NID_GRP
300                         , pTextComponent
301                         , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
302
303         if (pTextElementImpl->GetRegisteringEnrichedText() != null)
304         {
305                 return E_INVALID_ARG;
306         }
307         pTextElementImpl->SetRegisteringEnrichedText(this);
308
309         __pTextObject->AppendElement(*pTextComponent);
310         __pTextObject->SetRange(0, __pTextObject->GetTextLength());
311         __pTextObject->Compose();
312
313         __pLinkedListTextElementList->Add(element);
314
315         if (__isCopiedEnrichedText == false)
316         {
317                 if (__pTextElement)
318                 {
319                         __elements.Add(*__pTextElement);
320                 }
321         }
322
323         return r;
324 }
325
326 result
327 _EnrichedTextImpl::RemoveAllTextElements(bool deallocate)
328 {
329         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
330
331         result r = E_SUCCESS;
332         int elementCount = __pLinkedListTextElementList->GetCount();
333
334         for (int i = 0; i < elementCount; i++)
335         {
336                 r = RemoveAt(0, deallocate);
337                 r |= r;
338         }
339
340         if (r != E_SUCCESS)
341         {
342                 return E_SYSTEM;
343         }
344
345         return r;
346 }
347
348 result
349 _EnrichedTextImpl::RemoveAll(bool deallocate)
350 {
351         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
352
353         result r = E_SUCCESS;
354
355         int elementCount = __pLinkedListTextElementList->GetCount();
356
357         for (int i = 0; i < elementCount; i++)
358         {
359                 r = RemoveAt(0, deallocate);
360                 r |= r;
361         }
362
363         if (r != E_SUCCESS)
364         {
365                 return E_SYSTEM;
366         }
367
368         return E_SUCCESS;
369 }
370
371 TextElement*
372 _EnrichedTextImpl::GetTextElementAt(int elementIndex) const
373 {
374         SysTryReturn(NID_GRP, __pTextObject != null, null, E_OPERATION_FAILED
375                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
376         SysTryReturn(NID_GRP, elementIndex >= 0 && elementIndex < GetTextElementCount(), null, E_INVALID_ARG
377                         , "[E_INVALID_ARG] The argument is invalid. elementIndex = %d total element count = %d", elementIndex, GetTextElementCount());
378
379         TextElement* pElement = null;
380
381         ClearLastResult();
382
383         pElement = dynamic_cast < TextElement* >(__pLinkedListTextElementList->GetAt(elementIndex));
384
385         SetLastResult(E_SUCCESS);
386         return pElement;
387 }
388
389 int
390 _EnrichedTextImpl::GetTextElementCount(void) const
391 {
392         SysTryReturn(NID_GRP, __pTextObject != null, 0, E_OPERATION_FAILED
393                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
394
395         return __pLinkedListTextElementList->GetCount();
396 }
397
398 result
399 _EnrichedTextImpl::SetSize(const Tizen::Graphics::Dimension& size)
400 {
401         FloatDimension sizeF = _CoordinateSystemUtils::ConvertToFloat(size);
402
403         return SetSize(sizeF);
404 }
405
406 result
407 _EnrichedTextImpl::SetSize(const Tizen::Graphics::FloatDimension& size)
408 {
409         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
410                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
411         SysTryReturn(NID_GRP, (size.width > 0.0f) && (size.height > 0.0f), E_OUT_OF_RANGE, E_OUT_OF_RANGE
412                         , "[E_OUT_OF_RANGE] The given rectangle(width:%d,height:%d) is out of range.\n", size.width, size.height);
413
414         FloatRectangle rect(0.0f, 0.0f, size.width, size.height);
415
416         __pTextObject->SetBounds(rect);
417         __width = rect.width;
418         __height = rect.height;
419
420         return E_SUCCESS;
421 }
422
423 result
424 _EnrichedTextImpl::SetSize(int width, int height)
425 {
426         return SetSize(_CoordinateSystemUtils::ConvertToFloat(width),_CoordinateSystemUtils::ConvertToFloat(height));
427 }
428
429 result
430 _EnrichedTextImpl::SetSize(float width, float height)
431 {
432         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
433                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
434         SysTryReturn(NID_GRP, (width > 0.0f) && (height > 0.0f), E_OUT_OF_RANGE, E_OUT_OF_RANGE
435                         , "[E_OUT_OF_RANGE] The given rectangle(width:%d,height:%d) is out of range.\n", width, height);
436
437         FloatDimension dim(width, height);
438
439         result r = SetSize(dim);
440
441         return r;
442 }
443
444 Tizen::Graphics::Dimension
445 _EnrichedTextImpl::GetSize(void) const
446 {
447         SysTryReturn(NID_GRP, __pTextObject != null, Dimension(0, 0), E_OPERATION_FAILED
448                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
449
450         Dimension dim;
451
452         dim.width = _CoordinateSystemUtils::ConvertToInteger(__width);
453         dim.height = _CoordinateSystemUtils::ConvertToInteger(__height);
454
455         return dim;
456 }
457
458 Tizen::Graphics::FloatDimension
459 _EnrichedTextImpl::GetSizeF(void) const
460 {
461         SysTryReturn(NID_GRP, __pTextObject != null, FloatDimension(0.0f, 0.0f), E_OPERATION_FAILED
462                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
463
464         FloatDimension dim;
465
466         dim.width = __width;
467         dim.height = __height;
468
469         return dim;
470 }
471
472 void
473 _EnrichedTextImpl::GetSize(int& width, int& height) const
474 {
475         SysTryReturn(NID_GRP, __pTextObject != null, , E_OPERATION_FAILED
476                                 , "[E_OPERATION_FAILED] This instance is not constructed yet.");
477
478         width = _CoordinateSystemUtils::ConvertToInteger(__width);
479         height = _CoordinateSystemUtils::ConvertToInteger(__height);
480 }
481
482 void
483 _EnrichedTextImpl::GetSize(float& width, float& height) const
484 {
485         SysTryReturn(NID_GRP, __pTextObject != null, , E_OPERATION_FAILED
486                                 , "[E_OPERATION_FAILED] This instance is not constructed yet.");
487
488         width = __width;
489         height = __height;
490 }
491
492 int
493 _EnrichedTextImpl::GetWidth(void) const
494 {
495         SysTryReturn(NID_GRP, __pTextObject != null, 0, E_OPERATION_FAILED
496                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
497
498         return _CoordinateSystemUtils::ConvertToInteger(__width);
499 }
500
501 float
502 _EnrichedTextImpl::GetWidthF(void) const
503 {
504         SysTryReturn(NID_GRP, __pTextObject != null, 0.0f, E_OPERATION_FAILED
505                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
506
507         return __width;
508 }
509
510 int
511 _EnrichedTextImpl::GetHeight(void) const
512 {
513         SysTryReturn(NID_GRP, __pTextObject != null, 0, E_OPERATION_FAILED
514                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
515
516         return _CoordinateSystemUtils::ConvertToInteger(__height);
517 }
518
519 float
520 _EnrichedTextImpl::GetHeightF(void) const
521 {
522         SysTryReturn(NID_GRP, __pTextObject != null, 0.0f, E_OPERATION_FAILED
523                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
524
525         return __height;
526 }
527
528 result
529 _EnrichedTextImpl::SetVerticalAlignment(TextVerticalAlignment alignment)
530 {
531         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
532                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
533
534         TextObjectAlignment verticalAlign = ConvertVAlignment(alignment);
535         if (verticalAlign == TEXT_OBJECT_ALIGNMENT_INVALID)
536         {
537                 return E_INVALID_ARG;
538         }
539
540         TextObjectAlignment align = static_cast < TextObjectAlignment >((static_cast < TextObjectAlignment >(__pTextObject->GetAlignment())
541                                         & TEXT_HORIZONTAL_ALIGNMENT) | (verticalAlign & TEXT_VERTICAL_ALIGNMENT));
542
543         __pTextObject->SetAlignment(align);
544         __verticalAlignment = alignment;
545
546         return E_SUCCESS;
547 }
548
549 result
550 _EnrichedTextImpl::SetHorizontalAlignment(TextHorizontalAlignment alignment)
551 {
552         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
553                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
554
555         TextObjectAlignment horizontalAalign = ConvertHAlignment(alignment);
556         if (horizontalAalign == TEXT_OBJECT_ALIGNMENT_INVALID)
557         {
558                 return E_INVALID_ARG;
559         }
560
561         TextObjectAlignment align = static_cast < TextObjectAlignment >((static_cast < TextObjectAlignment >(__pTextObject->GetAlignment())
562                                         & TEXT_VERTICAL_ALIGNMENT) | (horizontalAalign & TEXT_HORIZONTAL_ALIGNMENT));
563
564         __pTextObject->SetAlignment(align);
565         __horizontalAlignment = alignment;
566
567         return E_SUCCESS;
568 }
569
570 TextVerticalAlignment
571 _EnrichedTextImpl::GetVerticalAlignment(void) const
572 {
573         SysTryReturn(NID_GRP, __pTextObject != null, TEXT_ALIGNMENT_VERTICAL_MIN, E_OPERATION_FAILED
574                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
575
576         return __verticalAlignment;
577 }
578
579 TextHorizontalAlignment
580 _EnrichedTextImpl::GetHorizontalAlignment(void) const
581 {
582         SysTryReturn(NID_GRP, __pTextObject != null, TEXT_ALIGNMENT_HORIZONTAL_MIN, E_OPERATION_FAILED
583                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
584
585         return __horizontalAlignment;
586 }
587
588 result
589 _EnrichedTextImpl::SetTextWrapStyle(TextWrap wrap)
590 {
591         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
592                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
593
594         SysTryReturn(NID_GRP, (TEXT_WRAP_MIN < wrap) && (wrap < TEXT_WRAP_MAX), E_INVALID_ARG, E_INVALID_ARG
595                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
596
597         _TextWrapType textWrap = ConvertWrapType(wrap);
598
599         if (__pTextObject->SetWrap(static_cast < TextObjectWrapType >(textWrap)) != E_SUCCESS)
600         {
601                 return E_INVALID_ARG;
602         }
603
604         return E_SUCCESS;
605 }
606
607 TextWrap
608 _EnrichedTextImpl::GetTextWrapStyle(void) const
609 {
610         SysTryReturn(NID_GRP, __pTextObject != null, TEXT_WRAP_MIN, E_OPERATION_FAILED
611                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
612
613         _TextWrapType textWrapType = static_cast < _TextWrapType >(__pTextObject->GetWrap());
614         TextWrap textWrap = ConvertWrap(textWrapType);
615
616         return textWrap;
617 }
618
619 result
620 _EnrichedTextImpl::SetTextAbbreviationEnabled(bool enable)
621 {
622         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
623                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
624
625         TextObjectActionType action = TEXT_OBJECT_ACTION_TYPE_NONE;
626
627         if (enable)
628         {
629                 action = TEXT_OBJECT_ACTION_TYPE_ABBREV;
630         }
631
632         __pTextObject->SetAction(action);
633
634         return E_SUCCESS;
635 }
636
637 bool
638 _EnrichedTextImpl::IsTextAbbreviationEnabled(void) const
639 {
640         SysTryReturn(NID_GRP, __pTextObject != null, false, E_OPERATION_FAILED
641                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
642
643         bool r = false;
644         TextObjectActionType action = __pTextObject->GetAction();
645
646         if (action & TEXT_OBJECT_ACTION_TYPE_ABBREV)
647         {
648                 r = true;
649         }
650
651         return r;
652 }
653
654 result
655 _EnrichedTextImpl::SetLineSpace(int lineSpace)
656 {
657         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
658                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
659         SysTryReturn(NID_GRP, lineSpace > 0, E_INVALID_ARG, E_INVALID_ARG
660                         , "[E_INVALID_ARG] The argument is invalid.");
661
662         __lineSpace = _CoordinateSystemUtils::ConvertToFloat(lineSpace);
663         __pTextObject->SetLineSpace(__lineSpace);
664
665         return E_SUCCESS;
666 }
667
668 result
669 _EnrichedTextImpl::SetLineSpace(float lineSpace)
670 {
671         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
672                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
673         SysTryReturn(NID_GRP, lineSpace > 0.0f, E_INVALID_ARG, E_INVALID_ARG
674                         , "[E_INVALID_ARG] The argument is invalid.");
675
676         __lineSpace = lineSpace;
677         __pTextObject->SetLineSpace(__lineSpace);
678
679         return E_SUCCESS;
680 }
681
682 int
683 _EnrichedTextImpl::GetLineSpace(void) const
684 {
685         return _CoordinateSystemUtils::ConvertToInteger(__lineSpace);
686 }
687
688 float
689 _EnrichedTextImpl::GetLineSpaceF(void) const
690 {
691         return __lineSpace;
692 }
693
694 void
695 _EnrichedTextImpl::Refresh(void)
696 {
697         SysTryReturn(NID_GRP, __pTextObject != null, , E_OPERATION_FAILED
698                                 , "[E_OPERATION_FAILED] This instance is not constructed yet.");
699
700         __pTextObject->Compose();
701 }
702
703 int
704 _EnrichedTextImpl::GetTotalLineCount(void) const
705 {
706         SysTryReturn(NID_GRP, __pTextObject != null, 0, E_OPERATION_FAILED
707                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
708
709         __pTextObject->Compose();
710
711         return __pTextObject->GetTotalLineCount();
712 }
713
714 int
715 _EnrichedTextImpl::GetTotalLineHeight(void) const
716 {
717         return _CoordinateSystemUtils::ConvertToInteger(GetTotalLineHeightF());
718 }
719
720 float
721 _EnrichedTextImpl::GetTotalLineHeightF(void) const
722 {
723         SysTryReturn(NID_GRP, __pTextObject != null, 0.0f, E_OPERATION_FAILED
724                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
725
726         __pTextObject->Compose();
727         float height = __pTextObject->GetTotalHeightF();
728
729         return height;
730 }
731
732 int
733 _EnrichedTextImpl::GetDisplayLineCount(void) const
734 {
735         SysTryReturn(NID_GRP, __pTextObject != null, 0, E_OPERATION_FAILED
736                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
737
738         int count = __pTextObject->GetDisplayLineCount();
739
740         __pTextObject->Compose();
741
742         if (count == 0xFFFF)
743         {
744                 return 0;
745         }
746
747         return count;
748 }
749
750 int
751 _EnrichedTextImpl::GetLineLength(int lineIndex) const
752 {
753         SysTryReturn(NID_GRP, __pTextObject != null, -1, E_OPERATION_FAILED
754                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
755         SysTryReturn(NID_GRP, GetTextElementCount() != 0, -1, E_OPERATION_FAILED
756                         , "[E_OPERATION_FAILED] It doesn't have TextElement.");
757         SysTryReturn(NID_GRP, lineIndex >= 0, -1, E_INVALID_ARG
758                         , "[E_INVALID_ARG] The invalid lineIndex(%d) is given.", lineIndex);
759
760         int totalLineCount = __pTextObject->GetTotalLineCount();
761
762         if (lineIndex > totalLineCount)
763         {
764                 return E_INVALID_ARG;
765         }
766
767         int lineLength = -1;
768
769         ClearLastResult();
770
771         __pTextObject->Compose();
772
773         lineLength = __pTextObject->GetTextLengthAt(lineIndex);
774         if (lineLength == -1)
775         {
776                 SetLastResult(E_INVALID_ARG);
777                 return -1;
778         }
779         else
780         {
781                 SetLastResult(E_SUCCESS);
782                 return lineLength;
783         }
784 }
785
786 int
787 _EnrichedTextImpl::GetFirstTextIndex(int lineIndex) const
788 {
789         SysTryReturn(NID_GRP, __pTextObject != null, -1, E_OPERATION_FAILED
790                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
791         SysTryReturn(NID_GRP, lineIndex >= 0, -1, E_INVALID_ARG
792                         , "[E_INVALID_ARG] The invalid lineIndex(%d) is given.", lineIndex);
793
794         ClearLastResult();
795         __pTextObject->Compose();
796
797         int totalLineCount = __pTextObject->GetTotalLineCount();
798         if (lineIndex >= totalLineCount)
799         {
800                 SetLastResult(E_INVALID_ARG);
801                 return -1;
802         }
803
804         int textIndex = __pTextObject->GetFirstTextIndexAt(lineIndex);
805         if (textIndex == -1)
806         {
807                 SetLastResult(E_INVALID_ARG);
808                 return -1;
809         }
810         else
811         {
812                 SetLastResult(E_SUCCESS);
813                 return textIndex;
814         }
815 }
816
817 int
818 _EnrichedTextImpl::GetLineIndex(int textIndex) const
819 {
820         SysTryReturn(NID_GRP, __pTextObject != null, -1, E_OPERATION_FAILED
821                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
822         SysTryReturn(NID_GRP, textIndex >= 0, -1, E_INVALID_ARG
823                         , "[E_INVALID_ARG] The invalid lineIndex(%d) is given.", textIndex);
824
825         ClearLastResult();
826         __pTextObject->Compose();
827
828         int totalLineCount = __pTextObject->GetTotalLineCount();
829         int lineIndex = __pTextObject->GetLineIndexAtTextIndex(textIndex);
830
831         if ((lineIndex > totalLineCount) || (textIndex > totalLineCount) || (lineIndex == -1))
832         {
833                 SetLastResult(E_INVALID_ARG);
834                 return -1;
835         }
836         else
837         {
838                 SetLastResult(E_SUCCESS);
839                 return lineIndex;
840         }
841 }
842
843 int
844 _EnrichedTextImpl::GetLineHeight(int lineIndex) const
845 {
846         return _CoordinateSystemUtils::ConvertToInteger(GetLineHeightF(lineIndex));
847 }
848
849 float
850 _EnrichedTextImpl::GetLineHeightF(int lineIndex) const
851 {
852         SysTryReturn(NID_GRP, __pTextObject != null, -1, E_OPERATION_FAILED
853                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
854         SysTryReturn(NID_GRP, lineIndex >= 0, -1, E_INVALID_ARG
855                         , "[E_INVALID_ARG] The invalid lineIndex(%d) is given.\n", lineIndex);
856
857         ClearLastResult();
858         __pTextObject->Compose();
859
860         int totalLineCount = __pTextObject->GetTotalLineCount();
861         if (lineIndex >= totalLineCount)
862         {
863                 SetLastResult(E_INVALID_ARG);
864                 return -1;
865         }
866
867         float height = __pTextObject->GetLineHeightAtF(lineIndex);
868
869         SetLastResult(E_SUCCESS);
870         return height;
871 }
872
873 int
874 _EnrichedTextImpl::GetTextLength(void) const
875 {
876         SysTryReturn(NID_GRP, __pTextObject != null, 0, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
877
878         if (GetTextElementCount() == 0)
879         {
880                 return 0;
881         }
882
883         __pTextObject->Compose();
884
885         return __pTextObject->GetTextLength();
886 }
887
888 result
889 _EnrichedTextImpl::GetTextExtent(int startTextIndex, int textLength, int& width, int& height, int& actualLength) const
890 {
891         float widthF = _CoordinateSystemUtils::ConvertToFloat(width);
892         float heightF = _CoordinateSystemUtils::ConvertToFloat(height);
893
894         result r = GetTextExtent(startTextIndex, textLength, widthF, heightF, actualLength);
895
896         width = _CoordinateSystemUtils::ConvertToInteger(widthF);
897         height = _CoordinateSystemUtils::ConvertToInteger(heightF);
898
899         return r;
900 }
901
902 result
903 _EnrichedTextImpl::GetTextExtent(int startTextIndex, int textLength, float& width, float& height, int& actualLength) const
904 {
905         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
906                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
907         SysTryReturn(NID_GRP, textLength >= 0, E_INVALID_ARG, E_INVALID_ARG
908                         , "[E_INVALID_ARG] The given text length(%d) is invalid\n", textLength);
909         SysTryReturn(NID_GRP, startTextIndex <= GetTextLength(), E_INVALID_ARG, E_INVALID_ARG
910                         , "[E_INVALID_ARG] 'startTextIndex' is greater than or equal to the text length.");
911
912         FloatDimension textSize;
913
914         actualLength = 0;
915
916         if (GetTextLength() == 0)
917         {
918                 width = 0;
919                 height = 0;
920
921                 return E_SUCCESS;
922         }
923
924         if (startTextIndex + textLength <= 0)
925         {
926                 width = 0;
927                 height = 0;
928
929                 return E_SUCCESS;
930         }
931
932         __pTextObject->Compose();
933         textSize = __pTextObject->GetTextExtentF(startTextIndex, textLength);
934         width = textSize.width;
935         height = textSize.height;
936
937         if (GetTextLength() - startTextIndex > textLength)
938         {
939                 actualLength = textLength;
940         }
941         else
942         {
943                 actualLength = GetTextLength() - startTextIndex;
944         }
945
946         return E_SUCCESS;
947 }
948
949
950 result
951 _EnrichedTextImpl::GetTextExtent(int startTextIndex, int textLength, Tizen::Graphics::Dimension& size, int &actualLength) const
952 {
953         FloatDimension sizeF = _CoordinateSystemUtils::ConvertToFloat(size);
954
955         result r = GetTextExtent(startTextIndex, textLength, sizeF, actualLength);
956
957         size = _CoordinateSystemUtils::ConvertToInteger(sizeF);
958
959         return r;
960 }
961
962 result
963 _EnrichedTextImpl::GetTextExtent(int startTextIndex, int textLength, Tizen::Graphics::FloatDimension& size, int &actualLength) const
964 {
965         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
966         SysTryReturn(NID_GRP, textLength >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given text length(%d) is invalid\n", textLength);
967         SysTryReturn(NID_GRP, startTextIndex <= GetTextLength(), E_INVALID_ARG, E_INVALID_ARG,
968                 "[E_INVALID_ARG] 'startTextIndex' is greater than or equal to the text length.\n");
969
970         actualLength = 0;
971
972         if (GetTextLength() == 0)
973         {
974                 size.width = 0;
975                 size.height = 0;
976
977                 return E_SUCCESS;
978         }
979
980         if (startTextIndex + textLength <= 0)
981         {
982                 size.width = 0;
983                 size.height = 0;
984
985                 return E_SUCCESS;
986         }
987
988         __pTextObject->Compose();
989
990         size = __pTextObject->GetTextExtentF(startTextIndex, textLength);
991         if (GetTextLength() - startTextIndex > textLength)
992         {
993                 actualLength = textLength;
994         }
995         else
996         {
997                 actualLength = GetTextLength() - startTextIndex;
998         }
999
1000         return E_SUCCESS;
1001 }
1002
1003 Tizen::Graphics::Dimension
1004 _EnrichedTextImpl::GetTextExtent(void) const
1005 {
1006         return _CoordinateSystemUtils::ConvertToInteger(GetTextExtentF());
1007 }
1008
1009 Tizen::Graphics::FloatDimension
1010 _EnrichedTextImpl::GetTextExtentF(void) const
1011 {
1012         SysTryReturn(NID_GRP, __pTextObject != null, FloatDimension(-1, -1), E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
1013
1014         FloatDimension size(0,0);
1015         if (GetTextLength() == 0)
1016         {
1017                 return size;
1018         }
1019
1020         __pTextObject->Compose();
1021
1022         FloatRectangle rtBound = __pTextObject->GetBoundsF();
1023         if (rtBound.width >= 0.0f && rtBound.height >= 0.0f)
1024         {
1025                 size.width = rtBound.width;
1026                 size.height = __pTextObject->GetTotalHeightF();
1027
1028                 return size;
1029         }
1030         else
1031         {
1032                 size.width = -1;
1033                 size.height = -1;
1034
1035                 return size;
1036         }
1037 }
1038
1039 result
1040 _EnrichedTextImpl::Add(const Tizen::Graphics::Bitmap& bitmap)
1041 {
1042         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
1043                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
1044         SysTryReturn(NID_GRP, &bitmap, E_INVALID_ARG, E_INVALID_ARG
1045                         , "[E_INVALID_ARG] The source bitmap is invalid.");
1046         SysTryReturn(NID_GRP, _Util::CheckValidity(&bitmap), E_INVALID_ARG, E_INVALID_ARG
1047                         , "[E_INVALID_ARG] The source bitmap is invalid.");
1048
1049         result r = E_SUCCESS;
1050
1051         Bitmap* pBitmap = const_cast < Bitmap* >(&bitmap);
1052         Bitmap* pNewBitmap = new (std::nothrow) Bitmap();
1053         if (pNewBitmap == null)
1054         {
1055                 SysLog(NID_GRP, "[E_OUT_OF_MEMORY] Fail to create a bitmap.");
1056                 return E_OUT_OF_MEMORY;
1057         }
1058
1059         r = pNewBitmap->Construct(*pBitmap, FloatRectangle(0, 0, pBitmap->GetWidthF(), pBitmap->GetHeightF()));
1060         SysTryCatch(NID_GRP
1061                         , r == E_SUCCESS
1062                         , , r, "[%s] Fails to append image.", GetErrorMessage(r));
1063
1064         __pTextObject->AppendElement(*pNewBitmap, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1065         __pTextObject->Compose();
1066
1067         r = __pLinkedListTextElementList->Add(*pNewBitmap);
1068         SysTryCatch(NID_GRP
1069                         , r == E_SUCCESS
1070                         , , r, "[%s] Fails to add image.", GetErrorMessage(r));
1071
1072         if (__isCopiedEnrichedText == false)
1073         {
1074                 __elements.Add(bitmap);
1075         }
1076
1077         return E_SUCCESS;
1078
1079 CATCH:
1080         if (pNewBitmap)
1081         {
1082                 delete pNewBitmap;
1083                 pNewBitmap = null;
1084         }
1085         return r;
1086 }
1087
1088 result
1089 _EnrichedTextImpl::InsertAt(int elementIndex, const Tizen::Graphics::Bitmap& bitmap)
1090 {
1091         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
1092                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
1093         SysTryReturn(NID_GRP, &bitmap, E_INVALID_ARG, E_INVALID_ARG
1094                         , "[E_INVALID_ARG] The source bitmap is invalid.");
1095         SysTryReturn(NID_GRP, _Util::CheckValidity(&bitmap), E_INVALID_ARG, E_INVALID_ARG
1096                         , "[E_INVALID_ARG] The source bitmap is invalid.");
1097         SysTryReturn(NID_GRP, elementIndex >= 0 && elementIndex <= GetTextElementCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE
1098                         , "[E_OUT_OF_RANGE] The given text index is invalid.");
1099
1100         result r = E_SUCCESS;
1101         _Text::TextElement* pTextComponent = null;
1102         int textLength = 0;
1103         int count = __pTextObject->GetElementCount();
1104         if (elementIndex > count)
1105         {
1106                 return E_INVALID_ARG;
1107         }
1108
1109         Bitmap* pBitmap = const_cast < Bitmap* >(&bitmap);
1110         Bitmap* pNewBitmap = new (std::nothrow) Bitmap();
1111         if (pNewBitmap == null)
1112         {
1113                 SysLog(NID_GRP, "[E_OUT_OF_MEMORY] Fail to create a bitmap.");
1114                 return E_OUT_OF_MEMORY;
1115         }
1116
1117         r = pNewBitmap->Construct(*pBitmap, FloatRectangle(0, 0, pBitmap->GetWidthF(), pBitmap->GetHeightF()));
1118         SysTryCatch(NID_GRP
1119                         , r == E_SUCCESS
1120                         , , r, "[%s] Fails to insert image.", GetErrorMessage(r));
1121
1122         for (int i = 0; i < elementIndex; i++)
1123         {
1124                 pTextComponent = __pTextObject->GetElementAtElementIndex(i);
1125                 if (pTextComponent != null)
1126                 {
1127                         textLength = textLength + pTextComponent->GetTextLength();
1128                 }
1129         }
1130
1131         __pTextObject->InsertElementAt(textLength, *pNewBitmap, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1132         __pTextObject->Compose();
1133
1134         r = __pLinkedListTextElementList->InsertAt(*pNewBitmap, elementIndex);
1135         SysTryCatch(NID_GRP
1136                         , r == E_SUCCESS
1137                         , , r, "[%s] Fails to insert image.", GetErrorMessage(r));
1138
1139         if (__isCopiedEnrichedText == false)
1140         {
1141                 __elements.InsertAt(bitmap, elementIndex);
1142         }
1143
1144         return E_SUCCESS;
1145
1146 CATCH:
1147         if (pNewBitmap)
1148         {
1149                 delete pNewBitmap;
1150                 pNewBitmap = null;
1151         }
1152
1153         return r;
1154 }
1155
1156 result
1157 _EnrichedTextImpl::GetLinkInfoFromPosition(const Point& point, Tizen::Base::Utility::LinkInfo& linkInfo) const
1158 {
1159         return GetLinkInfoFromPosition(_CoordinateSystemUtils::ConvertToFloat(point), linkInfo);
1160 }
1161
1162 result
1163 _EnrichedTextImpl::GetLinkInfoFromPosition(const FloatPoint& point, Tizen::Base::Utility::LinkInfo& linkInfo) const
1164 {
1165         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
1166                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
1167         SysTryReturn(NID_GRP, GetTextElementCount() > 0, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND
1168                         , "[E_OBJ_NOT_FOUND] The TextElement does not exist.");
1169         SysTryReturn(NID_GRP, point.x >= 0.0f && point.y >= 0.0f, E_INVALID_ARG, E_INVALID_ARG
1170                         , "[E_INVALID_ARG] The invalid position is given.");
1171         SysTryReturn(NID_GRP, GetWidthF() >= point.x && GetHeightF() >= point.y, E_INVALID_ARG, E_INVALID_ARG
1172                         , "[E_INVALID_ARG] The invalid position is given.");
1173
1174         return GetLinkInfoFromPosition(point.x, point.y, linkInfo);
1175 }
1176
1177 result
1178 _EnrichedTextImpl::GetLinkInfoFromPosition(int x, int y, Tizen::Base::Utility::LinkInfo& linkInfo) const
1179 {
1180         return GetLinkInfoFromPosition(_CoordinateSystemUtils::ConvertToFloat(x), _CoordinateSystemUtils::ConvertToFloat(y), linkInfo);
1181 }
1182
1183 result
1184 _EnrichedTextImpl::GetLinkInfoFromPosition(float x, float y, Tizen::Base::Utility::LinkInfo& linkInfo) const
1185 {
1186         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
1187                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
1188         SysTryReturn(NID_GRP, GetTextElementCount() > 0, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND
1189                         , "[E_OBJ_NOT_FOUND] The TextElement does not exist.");
1190         SysTryReturn(NID_GRP, x >= 0.0f && y >= 0.0f, E_INVALID_ARG, E_INVALID_ARG
1191                         , "[E_INVALID_ARG] The invalid position is given.");
1192         SysTryReturn(NID_GRP, GetWidthF() >= x && GetHeightF() >= y, E_INVALID_ARG, E_INVALID_ARG
1193                         , "[E_INVALID_ARG] The invalid position is given.");
1194
1195         FloatPoint point(x, y);
1196
1197         int textElementIndex = GetTextElementIndexFromPosition(point);
1198
1199         TextElement* pTextElement = GetTextElementAt(textElementIndex);
1200         if (pTextElement == null)
1201         {
1202                 return E_OBJ_NOT_FOUND;
1203         }
1204         _TextElementImpl* pTextElementImpl = _TextElementImpl::GetInstance(*pTextElement);
1205         if (pTextElementImpl != null)
1206         {
1207                 linkInfo.SetLinkType(pTextElementImpl->GetLinkType());
1208                 linkInfo.SetText(pTextElementImpl->GetText());
1209                 linkInfo.SetLink(pTextElementImpl->GetLinkText());
1210         }
1211
1212         return E_SUCCESS;
1213 }
1214
1215 TextVerticalAlignment
1216 _EnrichedTextImpl::GetElementVerticalAlignment(void) const
1217 {
1218         SysTryReturn(NID_GRP, __pTextObject != null, TEXT_ALIGNMENT_VERTICAL_MIN, E_OPERATION_FAILED
1219                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
1220
1221         return __elementVerticalAlignment;
1222 }
1223
1224 result
1225 _EnrichedTextImpl::SetElementVerticalAlignment(TextVerticalAlignment alignment)
1226 {
1227         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
1228                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
1229
1230         TextObjectAlignment elementAlign = ConvertVAlignment(alignment);
1231         if (elementAlign == TEXT_OBJECT_ALIGNMENT_INVALID)
1232         {
1233                 return E_INVALID_ARG;
1234         }
1235
1236         TextObjectAlignment align =
1237                         static_cast < TextObjectAlignment >((static_cast < TextObjectAlignment >(__pTextObject->GetAlignment())
1238                                         & TEXT_HORIZONTAL_ALIGNMENT) | (elementAlign & TEXT_VERTICAL_ALIGNMENT));
1239
1240         __pTextObject->SetElementVerticalAlignment(align);
1241         __elementVerticalAlignment = alignment;
1242
1243         return E_SUCCESS;
1244 }
1245
1246 Tizen::Graphics::Rectangle
1247 _EnrichedTextImpl::GetBounds() const
1248 {
1249         Rectangle rect(0, 0, _CoordinateSystemUtils::ConvertToInteger(__width), _CoordinateSystemUtils::ConvertToInteger(__height));
1250
1251         return rect;
1252 }
1253
1254 Tizen::Graphics::FloatRectangle
1255 _EnrichedTextImpl::GetBoundsF() const
1256 {
1257         FloatRectangle rect(0, 0, __width, __height);
1258
1259         return rect;
1260 }
1261
1262 result
1263 _EnrichedTextImpl::IndexOfFromLinkedList(TextElement& textElement, int& index)
1264 {
1265         return __pLinkedListTextElementList->IndexOf(textElement, index);
1266 }
1267
1268 int
1269 _EnrichedTextImpl::GetTextElementIndexFromPosition(Tizen::Graphics::Point& point) const
1270 {
1271         FloatPoint pointF = _CoordinateSystemUtils::ConvertToFloat(point);
1272
1273         return GetTextElementIndexFromPosition(pointF);
1274 }
1275
1276 int
1277 _EnrichedTextImpl::GetTextElementIndexFromPosition(Tizen::Graphics::FloatPoint& point) const
1278 {
1279         _TextElementImpl* pElement = null;
1280         TextElementType type;
1281         int length = 0;
1282         int offset = 0;
1283         int count = 0;
1284
1285         offset = GetIndexFromTouchPosition(point.x, point.y);
1286
1287         if (offset < 0 || offset > GetTextLength())
1288         {
1289                 return -1;
1290         }
1291
1292         count = GetTextElementCount();
1293         for (int i = 0; i < count; i++)
1294         {
1295                 type = GetTypeFromIndex(i);
1296
1297                 if (type == TEXT_ELEMENT_TYPE_IMAGE)
1298                 {
1299                         length = length + 1;
1300                 }
1301                 else
1302                 {
1303                         pElement = _TextElementImpl::GetInstance(*GetTextElementAt(i));
1304                         if (pElement)
1305                         {
1306                                 if (pElement->IsAuto() == true)
1307                                 {
1308                                         length = length + pElement->GetLinkText().GetLength();
1309                                 }
1310                                 else
1311                                 {
1312                                         String text = pElement->GetText();
1313                                         length = length + text.GetLength();
1314                                 }
1315                         }
1316                 }
1317                 if (offset <= length)
1318                 {
1319                         return i;
1320                 }
1321         }
1322         return -1;
1323 }
1324
1325 TextObject*
1326 _EnrichedTextImpl::GetTextObject(void) const
1327 {
1328         return __pTextObject.get();
1329 }
1330
1331 TextElementType
1332 _EnrichedTextImpl::GetTypeFromIndex(int textObjectIndex) const
1333 {
1334         TextElementType type = TEXT_ELEMENT_TYPE_NONE;
1335
1336         _Text::TextElement* pTextComponent = null;
1337
1338         pTextComponent = __pTextObject->GetElementAtElementIndex(textObjectIndex);
1339
1340         if (pTextComponent)
1341         {
1342                 type = pTextComponent->GetType();
1343         }
1344         else
1345         {
1346                 return TEXT_ELEMENT_TYPE_NONE;
1347         }
1348
1349         return type;
1350 }
1351
1352 int
1353 _EnrichedTextImpl::GetIndexFromTouchPosition(int posX, int posY) const
1354 {
1355         return GetIndexFromTouchPosition(_CoordinateSystemUtils::ConvertToFloat(posX), _CoordinateSystemUtils::ConvertToFloat(posY));
1356 }
1357
1358 int
1359 _EnrichedTextImpl::GetIndexFromTouchPosition(float posX, float posY) const
1360 {
1361         return __pTextObject->GetTextIndexFromPosition(posX, posY, true);
1362 }
1363
1364 result
1365 _EnrichedTextImpl::RemoveFromTextObject(_TextElementImpl* pTextElementImpl)
1366 {
1367         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
1368                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
1369
1370         _Text::TextElement* pTextComponent = pTextElementImpl->GetComponent();
1371         if (pTextComponent != null)
1372         {
1373                 __pTextObject->RemoveElement(*pTextComponent, false);
1374         }
1375
1376         return E_SUCCESS;
1377 }
1378
1379 result
1380 _EnrichedTextImpl::InsertAtFromTextObject(int index, _TextElementImpl* pTextElementImpl)
1381 {
1382         SysTryReturn(NID_GRP, __pTextObject != null, E_OPERATION_FAILED, E_OPERATION_FAILED
1383                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
1384
1385         int textLength = 0;
1386         int count = __pTextObject->GetElementCount();
1387         if (count > index)
1388         {
1389                 return E_INVALID_ARG;
1390         }
1391
1392         _Text::TextElement* pInsertTextComponent = pTextElementImpl->GetComponent();
1393         if (pInsertTextComponent != null)
1394         {
1395                 for (int i = 0; i < index; i++)
1396                 {
1397                         _Text::TextElement* pTextComponent = __pTextObject->GetElementAtElementIndex(i);
1398                         if (pTextComponent != null)
1399                         {
1400                                 textLength = textLength + pTextComponent->GetTextLength();
1401                         }
1402                 }
1403
1404                 __pTextObject->InsertElementAt(textLength, *pInsertTextComponent);
1405                 __pTextObject->Compose();
1406         }
1407
1408         return E_SUCCESS;
1409 }
1410
1411 int
1412 _EnrichedTextImpl::GetTextElementIndex(_TextElementImpl* pTextElementImpl) const
1413 {
1414         _Text::TextElement* pTextComponent = pTextElementImpl->GetComponent();
1415         if (pTextComponent != null)
1416         {
1417                 return __pTextObject->GetElementIndexOf(*pTextComponent);
1418         }
1419
1420         return -1;
1421 }
1422
1423 TextObjectAlignment
1424 _EnrichedTextImpl::ConvertHAlignment(TextHorizontalAlignment halign)
1425 {
1426         TextObjectAlignment align = TEXT_OBJECT_ALIGNMENT_LEFT;
1427
1428         switch (halign)
1429         {
1430         case TEXT_ALIGNMENT_LEFT:
1431                 align = TEXT_OBJECT_ALIGNMENT_LEFT;
1432                 break;
1433
1434         case TEXT_ALIGNMENT_CENTER:
1435                 align = TEXT_OBJECT_ALIGNMENT_CENTER;
1436                 break;
1437
1438         case TEXT_ALIGNMENT_RIGHT:
1439                 align = TEXT_OBJECT_ALIGNMENT_RIGHT;
1440                 break;
1441
1442         default:
1443                 align = TEXT_OBJECT_ALIGNMENT_INVALID;
1444                 break;
1445         }
1446
1447         return align;
1448 }
1449
1450 TextHorizontalAlignment
1451 _EnrichedTextImpl::ConvertHAlignment(TextObjectAlignment halign)
1452 {
1453         TextHorizontalAlignment align;
1454
1455         switch (halign)
1456         {
1457         case TEXT_OBJECT_ALIGNMENT_RIGHT:
1458                 align = TEXT_ALIGNMENT_RIGHT;
1459                 break;
1460
1461         case TEXT_OBJECT_ALIGNMENT_CENTER:
1462                 align = TEXT_ALIGNMENT_CENTER;
1463                 break;
1464
1465         case TEXT_OBJECT_ALIGNMENT_LEFT:
1466                 // fall through
1467         default:
1468                 align = TEXT_ALIGNMENT_LEFT;
1469                 break;
1470         }
1471
1472         return align;
1473 }
1474
1475 TextObjectAlignment
1476 _EnrichedTextImpl::ConvertVAlignment(TextVerticalAlignment valign)
1477 {
1478         TextObjectAlignment align;
1479
1480         switch (valign)
1481         {
1482         case TEXT_ALIGNMENT_TOP:
1483                 align = TEXT_OBJECT_ALIGNMENT_TOP;
1484                 break;
1485
1486         case TEXT_ALIGNMENT_MIDDLE:
1487                 align = TEXT_OBJECT_ALIGNMENT_MIDDLE;
1488                 break;
1489
1490         case TEXT_ALIGNMENT_BOTTOM:
1491                 align = TEXT_OBJECT_ALIGNMENT_BOTTOM;
1492                 break;
1493
1494         case TEXT_ALIGNMENT_BASELINE:
1495                 align = TEXT_OBJECT_ALIGNMENT_BASELINE;
1496                 break;
1497
1498         default:
1499                 align = TEXT_OBJECT_ALIGNMENT_INVALID;
1500                 break;
1501         }
1502
1503         return align;
1504 }
1505
1506 TextVerticalAlignment
1507 _EnrichedTextImpl::ConvertVAlignment(TextObjectAlignment valign)
1508 {
1509         TextVerticalAlignment align = TEXT_ALIGNMENT_TOP;
1510
1511         switch (valign)
1512         {
1513         case TEXT_OBJECT_ALIGNMENT_TOP:
1514                 align = TEXT_ALIGNMENT_TOP;
1515                 break;
1516
1517         case TEXT_OBJECT_ALIGNMENT_MIDDLE:
1518                 align = TEXT_ALIGNMENT_MIDDLE;
1519                 break;
1520
1521         case TEXT_OBJECT_ALIGNMENT_BOTTOM:
1522                 // fall through
1523         default:
1524                 align = TEXT_ALIGNMENT_BOTTOM;
1525                 break;
1526         }
1527
1528         return align;
1529 }
1530
1531 _TextWrapType
1532 _EnrichedTextImpl::ConvertWrapType(TextWrap warp)
1533 {
1534         _TextWrapType twrap;
1535
1536         switch (warp)
1537         {
1538         case TEXT_WRAP_CHARACTER_WRAP:
1539                 twrap = TEXT_WRAP_TYPE_WRAP;
1540                 break;
1541
1542         case TEXT_WRAP_WORD_WRAP:
1543                 twrap = TEXT_WRAP_TYPE_WORDWRAP;
1544                 break;
1545
1546         default:
1547                 twrap = TEXT_WRAP_TYPE_NONE;
1548                 break;
1549         }
1550
1551         return twrap;
1552 }
1553
1554 TextWrap
1555 _EnrichedTextImpl::ConvertWrap(_TextWrapType warp) const
1556 {
1557         TextWrap twrap;
1558
1559         switch (warp)
1560         {
1561         case TEXT_WRAP_TYPE_WRAP:
1562                 twrap = TEXT_WRAP_CHARACTER_WRAP;
1563                 break;
1564
1565         case TEXT_WRAP_TYPE_WORDWRAP:
1566                 twrap = TEXT_WRAP_WORD_WRAP;
1567                 break;
1568
1569         default:
1570                 twrap = TEXT_WRAP_NONE;
1571                 break;
1572         }
1573
1574         return twrap;
1575 }
1576
1577 _EnrichedTextImpl*
1578 _EnrichedTextImpl::GetCloneN(void) const
1579 {
1580         SysTryReturn(NID_GRP, __pTextObject != null, null, E_OPERATION_FAILED
1581                         , "[E_OPERATION_FAILED] This instance is not constructed yet.");
1582
1583         result r = E_SUCCESS;
1584         _EnrichedTextImpl* pNewEnrichedTextImpl = null;
1585
1586         pNewEnrichedTextImpl = new (std::nothrow)_EnrichedTextImpl(*this);
1587         r = GetLastResult();
1588         SysTryReturn(NID_GRP
1589                 , pNewEnrichedTextImpl
1590                 , null, r, "[%s] Propagating.", GetErrorMessage(r));
1591
1592         return pNewEnrichedTextImpl;
1593 }
1594
1595 _EnrichedTextImpl::_EnrichedTextImpl(const _EnrichedTextImpl& rhs)
1596 {
1597         SysTryReturnVoidResult(NID_GRP, rhs.__pTextObject, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not initialized.");
1598
1599         result r = E_SUCCESS;
1600         FloatDimension size = rhs.GetSizeF();
1601
1602         __width = size.width;
1603         __height = size.height;
1604         __lineSpace = GetLineSpaceF();
1605         __count = 0;
1606         __verticalAlignment = rhs.GetVerticalAlignment();
1607         __horizontalAlignment = rhs.GetHorizontalAlignment();
1608         __elementVerticalAlignment = rhs.GetElementVerticalAlignment();
1609         __pLinkedListTextElementList = null;
1610         __pTextElement = null;
1611         __isCopiedEnrichedText = true;
1612         __pTextObject = rhs.__pTextObject;
1613
1614         __pLinkedListTextElementList = new (std::nothrow) Tizen::Base::Collection::LinkedList;
1615         if (__pLinkedListTextElementList == null)
1616         {
1617                 SetLastResult(E_OUT_OF_MEMORY);
1618                 SysLog(NID_GRP, "[E_OUT_OF_MEMORY] Fail to create element list.");
1619         }
1620
1621         __pTextElement = new (std::nothrow) TextElement();
1622         if (__pTextElement == null)
1623         {
1624                 delete __pLinkedListTextElementList;
1625
1626                 SetLastResult(E_OUT_OF_MEMORY);
1627                 SysLog(NID_GRP, "[E_OUT_OF_MEMORY] Fail to create element.");
1628         }
1629
1630         r = __pTextElement->Construct();
1631         if (r != E_SUCCESS)
1632         {
1633                 delete __pLinkedListTextElementList;
1634                 delete __pTextElement;
1635
1636                 SysLog(NID_GRP, "[%s] Fail to construct text element.", GetErrorMessage(r));
1637         }
1638 }
1639
1640 _EnrichedTextImpl*
1641 _EnrichedTextImpl::GetInstance(EnrichedText& enrichedText)
1642 {
1643         return (&enrichedText != null) ? enrichedText.__pImpl : null;
1644 }
1645
1646 const _EnrichedTextImpl*
1647 _EnrichedTextImpl::GetInstance(const EnrichedText& enrichedText)
1648 {
1649         return (&enrichedText != null) ? enrichedText.__pImpl : null;
1650 }
1651
1652 bool
1653 _EnrichedTextImpl::IsConstructed(void) const
1654 {
1655         return (this->__pTextObject != null);
1656 }
1657
1658 }} // Tizen::Graphics