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