05540719044f214e25f1aa9d6a3d58d92d717238
[platform/framework/native/uifw.git] / src / graphics / FGrp_CanvasImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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_CanvasImpl.cpp
20  * @brief       This is the implementation file for _CanvasImpl class.
21  *
22  */
23
24 #include <new>
25 #include <memory>
26
27 #include <unique_ptr.h>
28
29 #include <FBaseSysLog.h>
30
31 #include "FGrp_BufferInfoImpl.h"
32 #include "FGrp_Callback.h"
33 #include "FGrp_CanvasImpl.h"
34 #include "FGrp_BitmapUtil.h"
35 #include "FGrp_Bitmap.h"
36 #include "FGrp_CanvasCoordHolder.h"
37 #include "FGrp_Canvas.h"
38 #include "FGrp_CanvasImplPrivate.h"
39 #include "FGrp_FontUtil.h"
40 #include "FGrp_EnrichedTextImpl.h"
41 #include "util/FGrp_Util.h"
42 #include "FGrp_TextTextObject.h"
43
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Collection;
46
47
48 #define EXTRACT_CANVASEX(pVar, canvas)          Tizen::Graphics::_Canvas * pVar = canvas._pNativeCanvas
49 #define EXTRACT_BITMAPEX(pVar, bitmap)          Tizen::Graphics::_Bitmap * pVar = Tizen::Graphics::_GetBitmapEx(bitmap)
50 #define EXTRACT_FONTEX(pVar, font)              Tizen::Graphics::_Font * pVar = Tizen::Graphics::_GetFontEx(font)
51 #define EXTRACT_SCALED_BITMAPEX(pVar, bitmap)   Tizen::Graphics::_Bitmap * pVar = Tizen::Graphics::_GetScaledBitmapEx(bitmap)
52
53 #define IsSucceeded(X)          (!IsFailed(X))
54
55 #define INSTANCE_IS_VALID       (this && (this->_pNativeCanvas && this->_pNativeCanvas->IsValid()))
56 #define CANVAS_IS_VALID(canvas) (&canvas && (canvas._pNativeCanvas && canvas._pNativeCanvas->IsValid()))
57
58 #define BITMAP_IS_VALID(bitmap) (&bitmap && const_cast<_BitmapImpl*>(&bitmap)->__CheckValidity())
59
60
61 namespace // unnamed
62 {
63
64 // retrieving bounds rectangle which has (0,0,w,h).
65 Tizen::Graphics::Rectangle
66 _GetBoundsRel(const Tizen::Graphics::_CanvasImpl& canvas)
67 {
68         Tizen::Graphics::Rectangle rect = canvas.GetBounds();
69         rect.x = 0;
70         rect.y = 0;
71
72         return rect;
73 }
74
75 Tizen::Graphics::FloatRectangle
76 _GetBoundsRelF(const Tizen::Graphics::_CanvasImpl& canvas)
77 {
78         Tizen::Graphics::FloatRectangle rectF = canvas.GetBoundsF();
79         rectF.x = 0.0f;
80         rectF.y = 0.0f;
81
82         return rectF;
83 }
84
85 template<typename T>
86 void
87 _ExpandClippingAreaForLineWidth(Tizen::Graphics::Rectangle& rtCanvas, T lineWidth)
88 {
89         int lineWidthHalf = (lineWidth + 1) / 2;
90
91         rtCanvas.x -= lineWidthHalf;
92         rtCanvas.y -= lineWidthHalf;
93         rtCanvas.width += lineWidthHalf * 2;
94         rtCanvas.height += lineWidthHalf * 2;
95 }
96
97 }
98
99 namespace Tizen { namespace Graphics { namespace _Util
100 {
101
102 template <>
103 inline Tizen::Graphics::Point Convert<Tizen::Graphics::FloatPoint, Tizen::Graphics::Point>(const Tizen::Graphics::FloatPoint& point)
104 {
105         return Tizen::Graphics::Point(int(point.x), int(point.y));
106 }
107
108 template <>
109 inline Tizen::Graphics::Rectangle Convert<Tizen::Graphics::FloatRectangle, Tizen::Graphics::Rectangle>(const Tizen::Graphics::FloatRectangle& rect)
110 {
111         return Tizen::Graphics::Rectangle(int(rect.x), int(rect.y), int(rect.width), int(rect.height));
112 }
113
114 template <>
115 _Util::Point<double>* Convert<Tizen::Base::Collection::IList, _Util::Point<double>*>(const Tizen::Base::Collection::IList& points)
116 {
117         int count = points.GetCount();
118
119         std::unique_ptr<_Util::Point<double>[]> pPointArray(new (std::nothrow) _Util::Point<double>[count]);
120
121         SysTryReturn(NID_GRP, pPointArray, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
122
123         {
124                 for (int i = 0; i < count; i++)
125                 {
126                         const Tizen::Graphics::Point* pPoint = dynamic_cast <const Tizen::Graphics::Point*>(points.GetAt(i));
127
128                         if (pPoint)
129                         {
130                                 pPointArray[i].x = double(pPoint->x);
131                                 pPointArray[i].y = double(pPoint->y);
132                         }
133                         else
134                         {
135                                 const Tizen::Graphics::FloatPoint* pFloatPoint = dynamic_cast <const Tizen::Graphics::FloatPoint*>(points.GetAt(i));
136
137                                 if (pFloatPoint)
138                                 {
139                                         pPointArray[i].x = double(pFloatPoint->x);
140                                         pPointArray[i].y = double(pFloatPoint->y);
141                                 }
142                                 else
143                                 {
144                                         return null;
145                                 }
146                         }
147                 }
148         }
149
150         return pPointArray.release();
151 }
152
153 } // Tizen::Graphics::_Util
154
155 }} // Tizen::Graphics
156
157 ////////////////////////////////////////////////////////////////////////////////
158 //
159
160 namespace Tizen { namespace Graphics
161 {
162
163 _CanvasImpl::_CanvasImpl(void)
164         : _magicKey(0)
165         , _pNativeCanvas(0)
166         , _pCoordHolder(0)
167         , _pFont(0)
168         , _pPriorityFont(0)
169         , _dashOffset(0)
170         , _pShowCallbackFunc(null)
171         , _pShowCallbackParam(null)
172 {
173         _pNativeCanvas = new (std::nothrow) _Canvas;
174         _pCoordHolder = new (std::nothrow) _CanvasCoordHolder;
175
176         if (_pNativeCanvas == null || _pCoordHolder == null)
177         {
178                 delete _pCoordHolder;
179                 delete _pNativeCanvas;
180
181                 _pCoordHolder = null;
182                 _pNativeCanvas = null;
183         }
184
185         _Util::CarveMagicKey(*this, _magicKey);
186 }
187
188 _CanvasImpl::~_CanvasImpl(void)
189 {
190         if (_pFont)
191         {
192                 delete _pFont;
193                 _pFont = 0;
194         }
195
196         delete _pCoordHolder;
197         delete _pNativeCanvas;
198
199         _Util::EraseMagicKey(*this, _magicKey);
200 }
201
202 result
203 _CanvasImpl::Construct(void)
204 {
205         SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
206
207         SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Memory allocation failed.");
208
209         result r = this->_pNativeCanvas->Construct();
210
211         if (IsSucceeded(r))
212         {
213                 Rectangle pcRect = this->_pNativeCanvas->GetBounds();
214
215                 _Util::Rectangle<int> pcUtilRect = { pcRect.x, pcRect.y, pcRect.width, pcRect.height };
216
217                 this->_pCoordHolder->ResetFromPc(pcUtilRect);
218         }
219
220         return r;
221 }
222
223 result
224 _CanvasImpl::Construct(const Rectangle& vcRect)
225 {
226         SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
227
228         SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Memory allocation failed.");
229
230         SysTryReturnResult(NID_GRP, vcRect.width > 0 && vcRect.height > 0, E_OUT_OF_RANGE,
231                                           "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width,
232                                           vcRect.height);
233
234         _Util::Rectangle<int> vcUtilRect = { vcRect.x, vcRect.y, vcRect.width, vcRect.height };
235
236         this->_pCoordHolder->ResetFromVc(vcUtilRect);
237
238         Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
239
240         pcRect.width = this->_pCoordHolder->canvasSize.pcInt.w;
241         pcRect.height = this->_pCoordHolder->canvasSize.pcInt.h;
242
243         return this->_pNativeCanvas->Construct(pcRect);
244 }
245
246 result
247 _CanvasImpl::Construct(const BufferInfo& bufferInfo)
248 {
249         SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
250
251         SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Memory allocation failed.");
252
253         SysTryReturnResult(NID_GRP, (bufferInfo.width > 0) && (bufferInfo.height > 0) && (bufferInfo.pitch > 0)
254                 , E_INVALID_ARG
255                 , "Invalid argument (BufferInfo::width = %d, BufferInfo::height = %d, BufferInfo::pitch = %d)"
256                 , bufferInfo.width, bufferInfo.height, bufferInfo.pitch);
257
258         SysTryReturnResult(NID_GRP, bufferInfo.bitsPerPixel > 0
259                 , E_INVALID_ARG
260                 , "Invalid argument (BufferInfo::bitsPerPixel = %d)"
261                 , bufferInfo.bitsPerPixel);
262
263         SysTryReturnResult(NID_GRP, (bufferInfo.pixelFormat > PIXEL_FORMAT_MIN) && (bufferInfo.pixelFormat < PIXEL_FORMAT_MAX)
264                 , E_INVALID_ARG
265                 , "Invalid argument (BufferInfo::pixelFormat = %d)"
266                 , bufferInfo.pixelFormat);
267
268         SysTryReturnResult(NID_GRP, bufferInfo.bitsPerPixel == 32
269                 , E_UNSUPPORTED_FORMAT
270                 , "Unsupported format (BufferInfo::bitsPerPixel = %d)"
271                 , bufferInfo.bitsPerPixel);
272
273         SysTryReturnResult(NID_GRP, bufferInfo.pixelFormat == PIXEL_FORMAT_ARGB8888
274                 , E_UNSUPPORTED_FORMAT
275                 , "Unsupported format (BufferInfo::pixelFormat = %d)"
276                 , bufferInfo.pixelFormat);
277
278         if (bufferInfo.pPixels == null)
279         {
280                 const _BufferInfoImpl* pBufferInfoImpl = _BufferInfoImpl::GetInstance(bufferInfo);
281
282                 if (pBufferInfoImpl)
283                 {
284                         Handle handle = pBufferInfoImpl->GetHandle(_BufferInfoImpl::HANDLE_TYPE_VE_SURFACE);
285
286                         if (handle != 0) // not INVALID_HANDLE
287                         {
288                                 result r = this->Construct(handle);
289
290                                 // OUT_OF_RANGE does not occur
291                                 SysTryReturn(NID_GRP, (r == E_SUCCESS) && this->IsConstructed(), r, r, "[%s] Propagating.", GetErrorMessage(r));
292
293                                 _Util::Rectangle<int> pcUtilRect = { 0, 0, this->_pNativeCanvas->__pSurface->GetWidth(), this->_pNativeCanvas->__pSurface->GetHeight() };
294
295                                 this->_pCoordHolder->ResetFromPc(pcUtilRect);
296
297                                 return E_SUCCESS;
298                         }
299                 }
300
301                 SysTryReturnResult(NID_GRP, false
302                         , E_INVALID_ARG
303                         , "Invalid argument (BufferInfo::pPixels = null)");
304         }
305         else
306         {
307                 result r = this->_pNativeCanvas->Construct(bufferInfo);
308
309                 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
310
311                 _Util::Rectangle<int> pcUtilRect = { 0, 0, this->_pNativeCanvas->__pSurface->GetWidth(), this->_pNativeCanvas->__pSurface->GetHeight() };
312
313                 this->_pCoordHolder->ResetFromPc(pcUtilRect);
314
315                 return E_SUCCESS;
316         }
317
318         return E_SYSTEM;
319 }
320
321 result
322 _CanvasImpl::Construct(Handle windowHandle)
323 {
324         SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
325
326         SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Memory allocation failed.");
327
328         return this->_pNativeCanvas->Construct(windowHandle);
329 }
330
331 result
332 _CanvasImpl::Construct(Handle windowHandle, const Rectangle& vcRect)
333 {
334         SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
335
336         SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Memory allocation failed.");
337
338         SysTryReturnResult(NID_GRP, vcRect.width >= 0 && vcRect.height >= 0, E_OUT_OF_RANGE,
339                                           "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width,
340                                           vcRect.height);
341
342         _Util::Rectangle<int> vcUtilRect = { vcRect.x, vcRect.y, vcRect.width, vcRect.height };
343
344         this->_pCoordHolder->ResetFromVc(vcUtilRect);
345
346         Rectangle pcRect;
347
348         pcRect.x = _ResUtil::ConvertToPhyCoord(vcRect.x);
349         pcRect.y = _ResUtil::ConvertToPhyCoord(vcRect.y);
350         pcRect.width = this->_pCoordHolder->canvasSize.pcInt.w;
351         pcRect.height = this->_pCoordHolder->canvasSize.pcInt.h;
352
353         return this->_pNativeCanvas->Construct(windowHandle, pcRect);
354 }
355
356 result
357 _CanvasImpl::Construct(const FloatRectangle& vcRectF)
358 {
359         SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
360
361         SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Memory allocation failed.");
362
363         SysTryReturnResult(NID_GRP, vcRectF.width > 0.0f && vcRectF.height > 0.0f, E_OUT_OF_RANGE,
364                                           "The given rectangle(width:%f,height:%f) is out of range.", vcRectF.width,
365                                           vcRectF.height);
366
367         _Util::Rectangle<float> vcUtilRectF = { vcRectF.x, vcRectF.y, vcRectF.width, vcRectF.height };
368
369         this->_pCoordHolder->ResetFromVc(vcUtilRectF);
370
371         if (_ResUtil::NeedToConvertCoord())
372         {
373                 Rectangle pcRect;
374
375                 pcRect.x = _FloatToIntForPos(_ResUtil::ConvertToPhyCoord(vcRectF.x));
376                 pcRect.y = _FloatToIntForPos(_ResUtil::ConvertToPhyCoord(vcRectF.y));
377                 pcRect.width = this->_pCoordHolder->canvasSize.pcInt.w;
378                 pcRect.height = this->_pCoordHolder->canvasSize.pcInt.h;
379
380                 return this->_pNativeCanvas->Construct(pcRect);
381         }
382         else
383         {
384                 Rectangle vcRect;
385
386                 vcRect.x = this->_pCoordHolder->canvasPos.vcInt.x;
387                 vcRect.y = this->_pCoordHolder->canvasPos.vcInt.y;
388                 vcRect.width = this->_pCoordHolder->canvasSize.vcInt.w;
389                 vcRect.height = this->_pCoordHolder->canvasSize.vcInt.h;
390
391                 return this->_pNativeCanvas->Construct(vcRect);
392         }
393 }
394
395 result
396 _CanvasImpl::Construct(Handle windowHandle, const FloatRectangle& vcRectF)
397 {
398         SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
399
400         SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Memory allocation failed.");
401
402         SysTryReturnResult(NID_GRP, vcRectF.width >= 0.0f && vcRectF.height >= 0.0f, E_OUT_OF_RANGE,
403                                           "The given rectangle(width:%f,height:%f) is out of range.", vcRectF.width,
404                                           vcRectF.height);
405
406         _Util::Rectangle<float> vcUtilRectF = { vcRectF.x, vcRectF.y, vcRectF.width, vcRectF.height };
407
408         this->_pCoordHolder->ResetFromVc(vcUtilRectF);
409
410         Rectangle pcRect;
411
412         pcRect.x = _FloatToIntForPos(_ResUtil::ConvertToPhyCoord(vcRectF.x));
413         pcRect.y = _FloatToIntForPos(_ResUtil::ConvertToPhyCoord(vcRectF.y));
414         pcRect.width = this->_pCoordHolder->canvasSize.pcInt.w;
415         pcRect.height = this->_pCoordHolder->canvasSize.pcInt.h;
416
417         return this->_pNativeCanvas->Construct(windowHandle, pcRect);
418 }
419
420 bool
421 _CanvasImpl::IsConstructed(void) const
422 {
423         return (this->_pNativeCanvas != null) && this->_pNativeCanvas->IsValid();
424 }
425
426 result
427 _CanvasImpl::Clear(void)
428 {
429         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
430
431         return this->_pNativeCanvas->Clear();
432 }
433
434 result
435 _CanvasImpl::Clear(const Rectangle& vcRect)
436 {
437         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
438
439         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
440         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE,
441                                           "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width,
442                                           vcRect.height);
443
444         if ((vcRect.width == 0) || (vcRect.height == 0))
445         {
446                 return E_SUCCESS;
447         }
448
449         Rectangle rtCanvas = _GetBoundsRel(*this);
450
451         if (rtCanvas.IsEmpty())
452         {
453                 return E_SUCCESS;
454         }
455
456         result r = _Util::Validate(vcRect, rtCanvas);
457
458         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
459
460         if (_ResUtil::NeedToConvertCoord())
461         {
462                 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
463
464                 return this->_pNativeCanvas->Clear(pcRect);
465         }
466         else
467         {
468                 return this->_pNativeCanvas->Clear(vcRect);
469         }
470 }
471
472 result
473 _CanvasImpl::Clear(const FloatRectangle& vcRectF)
474 {
475         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
476
477         SysTryReturnResult(NID_GRP, &vcRectF, E_OUT_OF_RANGE, "The given rectangle is invalid.");
478         SysTryReturnResult(NID_GRP, (vcRectF.width >= 0.0f) && (vcRectF.height >= 0.0f), E_OUT_OF_RANGE,
479                                           "The given rectangle(width:%f,height:%f) is out of range.", vcRectF.width,
480                                           vcRectF.height);
481
482         if ((vcRectF.width == 0.0f) || (vcRectF.height == 0.0f))
483         {
484                 return E_SUCCESS;
485         }
486
487         FloatRectangle rtCanvasF = _GetBoundsRelF(*this);
488
489         if (rtCanvasF.IsEmpty())
490         {
491                 return E_SUCCESS;
492         }
493
494         result r = _Util::Validate(vcRectF, rtCanvasF);
495
496         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
497
498         if (_ResUtil::NeedToConvertCoord())
499         {
500                 FloatRectangle pcRectF = _ResUtil::ConvertToPhyCoord(vcRectF);
501                 Rectangle pcRect(_FloatToIntForPos(pcRectF.x), _FloatToIntForPos(pcRectF.y), _FloatToIntForSize(pcRectF.width), _FloatToIntForSize(pcRectF.height));
502
503                 return this->_pNativeCanvas->Clear(pcRect);
504         }
505         else
506         {
507                 Rectangle vcRect(_FloatToIntForPos(vcRectF.x), _FloatToIntForPos(vcRectF.y), _FloatToIntForSize(vcRectF.width), _FloatToIntForSize(vcRectF.height));
508
509                 return this->_pNativeCanvas->Clear(vcRect);
510         }
511 }
512
513 result
514 _CanvasImpl::Copy(const Point& vcDestPoint, const _CanvasImpl& canvas, const Rectangle& vcSrcRect)
515 {
516         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
517
518         SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(canvas), E_INVALID_ARG, "The specified source canvas is invalid.");
519
520         Rectangle srcRectCanvas = _GetBoundsRel(canvas);
521
522         if (srcRectCanvas.IsEmpty())
523         {
524                 return E_SUCCESS;
525         }
526
527         result r = _Util::Validate(vcSrcRect, srcRectCanvas);
528
529         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
530
531         // check if destRect is in this canvas.
532         Rectangle destRect(vcDestPoint.x, vcDestPoint.y, vcSrcRect.width, vcSrcRect.height);
533         Rectangle destRectCanvas = _GetBoundsRel(*this);
534
535         if (destRectCanvas.IsEmpty())
536         {
537                 return E_SUCCESS;
538         }
539
540         r = _Util::Validate(destRect, destRectCanvas);
541
542         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
543
544         EXTRACT_CANVASEX(_pNativeCanvas, canvas);
545
546
547         if (_ResUtil::NeedToConvertCoord())
548         {
549                 Point pcDestPoint = _ResUtil::ConvertToPhyCoord(vcDestPoint);
550                 Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
551
552                 return this->_pNativeCanvas->Copy(pcDestPoint, *_pNativeCanvas, pcSrcRect);
553         }
554         else
555         {
556                 return this->_pNativeCanvas->Copy(vcDestPoint, *_pNativeCanvas, vcSrcRect);
557         }
558 }
559
560 result
561 _CanvasImpl::Copy(const FloatPoint& vcDestPointF, const _CanvasImpl& srcCanvas, const FloatRectangle& vcSrcRectF)
562 {
563         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
564
565         SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(srcCanvas), E_INVALID_ARG, "The specified source canvas is invalid.");
566
567         FloatRectangle srcRectCanvasF = _GetBoundsRelF(srcCanvas);
568
569         if (srcRectCanvasF.IsEmpty())
570         {
571                 return E_SUCCESS;
572         }
573
574         result r = _Util::Validate(vcSrcRectF, srcRectCanvasF);
575
576         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
577
578         // check if destRect is in this canvas.
579         FloatRectangle destRectF(vcDestPointF.x, vcDestPointF.y, vcSrcRectF.width, vcSrcRectF.height);
580         FloatRectangle destRectCanvasF = _GetBoundsRelF(*this);
581
582         if (destRectCanvasF.IsEmpty())
583         {
584                 return E_SUCCESS;
585         }
586
587         r = _Util::Validate(destRectF, destRectCanvasF);
588
589         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
590
591         EXTRACT_CANVASEX(_pNativeCanvas, srcCanvas);
592
593         if (_ResUtil::NeedToConvertCoord())
594         {
595                 FloatPoint pcDestPointF = _ResUtil::ConvertToPhyCoord(vcDestPointF);
596                 FloatRectangle pcSrcRectF = _ResUtil::ConvertToPhyCoord(vcSrcRectF);
597
598                 Point pcDestPoint(_FloatToIntForPos(pcDestPointF.x), _FloatToIntForPos(pcDestPointF.y));
599                 Rectangle pcSrcRect(_FloatToIntForPos(pcSrcRectF.x), _FloatToIntForPos(pcSrcRectF.y), _FloatToIntForSize(pcSrcRectF.width), _FloatToIntForSize(pcSrcRectF.height));
600
601                 return this->_pNativeCanvas->Copy(pcDestPoint, *_pNativeCanvas, pcSrcRect);
602         }
603         else
604         {
605                 Point vcDestPoint(_FloatToIntForPos(vcDestPointF.x), _FloatToIntForPos(vcDestPointF.y));
606                 Rectangle vcSrcRect(_FloatToIntForPos(vcSrcRectF.x), _FloatToIntForPos(vcSrcRectF.y), _FloatToIntForSize(vcSrcRectF.width), _FloatToIntForSize(vcSrcRectF.height));
607
608                 return this->_pNativeCanvas->Copy(vcDestPoint, *_pNativeCanvas, vcSrcRect);
609         }
610 }
611
612 result
613 _CanvasImpl::Copy(const Rectangle& vcDestRect, const _CanvasImpl& canvas, const Rectangle& vcSrcRect)
614 {
615         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
616
617         SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(canvas), E_INVALID_ARG, "The specified source canvas is invalid.");
618
619         // check if srcRect is in source canvas.
620         Rectangle srcRectCanvas = _GetBoundsRel(canvas);
621
622         if (srcRectCanvas.IsEmpty())
623         {
624                 return E_SUCCESS;
625         }
626
627         result r = _Util::Validate(vcSrcRect, srcRectCanvas);
628
629         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
630
631         // check if destRect is in this canvas.
632         Rectangle destRectCanvas = _GetBoundsRel(*this);
633
634         if (destRectCanvas.IsEmpty())
635         {
636                 return E_SUCCESS;
637         }
638
639         r = _Util::Validate(vcDestRect, destRectCanvas);
640
641         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
642
643         EXTRACT_CANVASEX(_pNativeCanvas, canvas);
644
645         if (_ResUtil::NeedToConvertCoord())
646         {
647                 Rectangle pcDestRect = _ResUtil::ConvertToPhyCoord(vcDestRect);
648                 Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
649
650                 return this->_pNativeCanvas->Copy(pcDestRect, *_pNativeCanvas, pcSrcRect);
651         }
652         else
653         {
654                 return this->_pNativeCanvas->Copy(vcDestRect, *_pNativeCanvas, vcSrcRect);
655         }
656 }
657
658 result
659 _CanvasImpl::Copy(const FloatRectangle& vcDestRectF, const _CanvasImpl& srcCanvas, const FloatRectangle& vcSrcRectF)
660 {
661         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
662
663         SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(srcCanvas), E_INVALID_ARG, "The specified source canvas is invalid.");
664
665         // check if srcRect is in source canvas.
666         FloatRectangle srcRectCanvasF = _GetBoundsRelF(srcCanvas);
667
668         if (srcRectCanvasF.IsEmpty())
669         {
670                 return E_SUCCESS;
671         }
672
673         result r = _Util::Validate(vcSrcRectF, srcRectCanvasF);
674
675         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
676
677         // check if destRect is in this canvas.
678         FloatRectangle destRectCanvasF = _GetBoundsRelF(*this);
679
680         if (destRectCanvasF.IsEmpty())
681         {
682                 return E_SUCCESS;
683         }
684
685         r = _Util::Validate(vcDestRectF, destRectCanvasF);
686
687         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
688
689         EXTRACT_CANVASEX(_pNativeCanvas, srcCanvas);
690
691         if (_ResUtil::NeedToConvertCoord())
692         {
693                 FloatRectangle pcDestRectF = _ResUtil::ConvertToPhyCoord(vcDestRectF);
694                 FloatRectangle pcSrcRectF = _ResUtil::ConvertToPhyCoord(vcSrcRectF);
695
696                 Rectangle pcDestRect(_FloatToIntForPos(pcDestRectF.x), _FloatToIntForPos(pcDestRectF.y), _FloatToIntForSize(pcDestRectF.width), _FloatToIntForSize(pcDestRectF.height));
697                 Rectangle pcSrcRect(_FloatToIntForPos(pcSrcRectF.x), _FloatToIntForPos(pcSrcRectF.y), _FloatToIntForSize(pcSrcRectF.width), _FloatToIntForSize(pcSrcRectF.height));
698
699                 return this->_pNativeCanvas->Copy(pcDestRect, *_pNativeCanvas, pcSrcRect);
700         }
701         else
702         {
703                 Rectangle vcDestRect(_FloatToIntForPos(vcDestRectF.x), _FloatToIntForPos(vcDestRectF.y), _FloatToIntForSize(vcDestRectF.width), _FloatToIntForSize(vcDestRectF.height));
704                 Rectangle vcSrcRect(_FloatToIntForPos(vcSrcRectF.x), _FloatToIntForPos(vcSrcRectF.y), _FloatToIntForSize(vcSrcRectF.width), _FloatToIntForSize(vcSrcRectF.height));
705
706                 return this->_pNativeCanvas->Copy(vcDestRect, *_pNativeCanvas, vcSrcRect);
707         }
708 }
709
710 result
711 _CanvasImpl::Copy(const Point& vcDestPoint, const _CanvasImpl& canvas, const Rectangle& vcSrcRect, CompositeMode compositeMode)
712 {
713         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
714
715         SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(canvas), E_INVALID_ARG, "The specified source canvas is invalid.");
716
717         switch (compositeMode)
718         {
719         case COMPOSITE_MODE_CLEAR:
720         case COMPOSITE_MODE_SRC:
721         case COMPOSITE_MODE_DST:
722         case COMPOSITE_MODE_SRC_OVER:
723         case COMPOSITE_MODE_DST_OVER:
724         case COMPOSITE_MODE_SRC_IN:
725         case COMPOSITE_MODE_DST_IN:
726         case COMPOSITE_MODE_SRC_OUT:
727         case COMPOSITE_MODE_DST_OUT:
728         case COMPOSITE_MODE_SRC_ATOP:
729         case COMPOSITE_MODE_DST_ATOP:
730         case COMPOSITE_MODE_DST_XOR:
731         case COMPOSITE_MODE_ADD:
732         case COMPOSITE_MODE_SATURATE:
733         case COMPOSITE_MODE_MULTIPLY:
734         case COMPOSITE_MODE_SCREEN:
735         case COMPOSITE_MODE_OVERLAY:
736         case COMPOSITE_MODE_DARKEN:
737         case COMPOSITE_MODE_LIGHTEN:
738                 break;
739         default:
740                 SysTryReturnResult(NID_GRP, false, E_INVALID_ARG, "The specified composite mode is invalid.");
741         }
742
743         Rectangle srcRectCanvas = _GetBoundsRel(canvas);
744
745         if (srcRectCanvas.IsEmpty())
746         {
747                 return E_SUCCESS;
748         }
749
750         result r = _Util::Validate(vcSrcRect, srcRectCanvas);
751
752         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
753
754         // check if destRect is in this canvas.
755         Rectangle destRect(vcDestPoint.x, vcDestPoint.y, vcSrcRect.width, vcSrcRect.height);
756         Rectangle destRectCanvas = _GetBoundsRel(*this);
757
758         if (destRectCanvas.IsEmpty())
759         {
760                 return E_SUCCESS;
761         }
762
763         r = _Util::Validate(destRect, destRectCanvas);
764
765         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
766
767         EXTRACT_CANVASEX(_pNativeCanvas, canvas);
768
769
770         if (_ResUtil::NeedToConvertCoord())
771         {
772                 Point pcDestPoint = _ResUtil::ConvertToPhyCoord(vcDestPoint);
773                 Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
774
775                 return this->_pNativeCanvas->Copy(pcDestPoint, *_pNativeCanvas, pcSrcRect, compositeMode);
776         }
777         else
778         {
779                 return this->_pNativeCanvas->Copy(vcDestPoint, *_pNativeCanvas, vcSrcRect, compositeMode);
780         }
781 }
782
783 result
784 _CanvasImpl::Copy(const FloatPoint& vcDestPointF, const _CanvasImpl& srcCanvas, const FloatRectangle& vcSrcRectF, CompositeMode compositeMode)
785 {
786         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
787
788         SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(srcCanvas), E_INVALID_ARG, "The specified source canvas is invalid.");
789
790         switch (compositeMode)
791         {
792         case COMPOSITE_MODE_CLEAR:
793         case COMPOSITE_MODE_SRC:
794         case COMPOSITE_MODE_DST:
795         case COMPOSITE_MODE_SRC_OVER:
796         case COMPOSITE_MODE_DST_OVER:
797         case COMPOSITE_MODE_SRC_IN:
798         case COMPOSITE_MODE_DST_IN:
799         case COMPOSITE_MODE_SRC_OUT:
800         case COMPOSITE_MODE_DST_OUT:
801         case COMPOSITE_MODE_SRC_ATOP:
802         case COMPOSITE_MODE_DST_ATOP:
803         case COMPOSITE_MODE_DST_XOR:
804         case COMPOSITE_MODE_ADD:
805         case COMPOSITE_MODE_SATURATE:
806         case COMPOSITE_MODE_MULTIPLY:
807         case COMPOSITE_MODE_SCREEN:
808         case COMPOSITE_MODE_OVERLAY:
809         case COMPOSITE_MODE_DARKEN:
810         case COMPOSITE_MODE_LIGHTEN:
811                 break;
812         default:
813                 SysTryReturnResult(NID_GRP, false, E_INVALID_ARG, "The specified composite mode is invalid.");
814         }
815
816         FloatRectangle srcRectCanvasF = _GetBoundsRelF(srcCanvas);
817
818         if (srcRectCanvasF.IsEmpty())
819         {
820                 return E_SUCCESS;
821         }
822
823         result r = _Util::Validate(vcSrcRectF, srcRectCanvasF);
824
825         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
826
827         // check if destRect is in this canvas.
828         FloatRectangle destRectF(vcDestPointF.x, vcDestPointF.y, vcSrcRectF.width, vcSrcRectF.height);
829         FloatRectangle destRectCanvasF = _GetBoundsRelF(*this);
830
831         if (destRectCanvasF.IsEmpty())
832         {
833                 return E_SUCCESS;
834         }
835
836         r = _Util::Validate(destRectF, destRectCanvasF);
837
838         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
839
840         EXTRACT_CANVASEX(_pNativeCanvas, srcCanvas);
841
842
843         if (_ResUtil::NeedToConvertCoord())
844         {
845                 FloatPoint pcDestPointF = _ResUtil::ConvertToPhyCoord(vcDestPointF);
846                 FloatRectangle pcSrcRectF = _ResUtil::ConvertToPhyCoord(vcSrcRectF);
847
848                 Point pcDestPoint(_FloatToIntForPos(pcDestPointF.x), _FloatToIntForPos(pcDestPointF.y));
849                 Rectangle pcSrcRect(_FloatToIntForPos(pcSrcRectF.x), _FloatToIntForPos(pcSrcRectF.y), _FloatToIntForSize(pcSrcRectF.width), _FloatToIntForSize(pcSrcRectF.height));
850
851                 return this->_pNativeCanvas->Copy(pcDestPoint, *_pNativeCanvas, pcSrcRect, compositeMode);
852         }
853         else
854         {
855                 Point vcDestPoint(_FloatToIntForPos(vcDestPointF.x), _FloatToIntForPos(vcDestPointF.y));
856                 Rectangle vcSrcRect(_FloatToIntForPos(vcSrcRectF.x), _FloatToIntForPos(vcSrcRectF.y), _FloatToIntForSize(vcSrcRectF.width), _FloatToIntForSize(vcSrcRectF.height));
857
858                 return this->_pNativeCanvas->Copy(vcDestPoint, *_pNativeCanvas, vcSrcRect, compositeMode);
859         }
860 }
861
862 result
863 _CanvasImpl::CopyEx(const Point& vcDestPoint, const _CanvasImpl& srcCanvas, const Rectangle& vcSrcRect)
864 {
865         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
866
867         if (this != &srcCanvas)
868         {
869                 return this->Copy(vcDestPoint, srcCanvas, vcSrcRect);
870         }
871
872         // validity check as _CanvasImpl::Copy()
873         SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(srcCanvas), E_INVALID_ARG, "The specified source canvas is invalid.");
874
875         Rectangle srcRectCanvas = _GetBoundsRel(srcCanvas);
876
877         if (srcRectCanvas.IsEmpty())
878         {
879                 return E_SUCCESS;
880         }
881
882         result r = _Util::Validate(vcSrcRect, srcRectCanvas);
883
884         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
885
886         // check if destRect is in this canvas.
887         Rectangle destRect(vcDestPoint.x, vcDestPoint.y, vcSrcRect.width, vcSrcRect.height);
888         Rectangle destRectCanvas = _GetBoundsRel(*this);
889
890         if (destRectCanvas.IsEmpty())
891         {
892                 return E_SUCCESS;
893         }
894
895         r = _Util::Validate(destRect, destRectCanvas);
896
897         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
898
899         int pixelPerLine = 0;
900
901         {
902                 BufferInfo bufferInfo;
903
904                 result r = this->_pNativeCanvas->Lock(bufferInfo);
905
906                 //?? log
907                 SysTryReturn(NID_GRP, r == E_SUCCESS, r, E_SYSTEM, "[] ");
908
909                 this->_pNativeCanvas->Unlock();
910
911                 pixelPerLine = bufferInfo.pitch / (bufferInfo.bitsPerPixel / 8);
912         }
913
914         //?? Auto-scaling should be applied to vc**** parameters later
915         int sourDistance = vcSrcRect.y * pixelPerLine + vcSrcRect.x;
916         int destDistance = vcDestPoint.y * pixelPerLine + vcDestPoint.x;
917
918         typedef result (_Canvas::* FnCopy)(const Point&, const _Canvas&, const Rectangle&);
919         FnCopy fnCopy = (destDistance < sourDistance) ? FnCopy(&_Canvas::Copy) : FnCopy(&_Canvas::CopyReverse);
920
921         if (fnCopy)
922         {
923                 EXTRACT_CANVASEX(_pNativeCanvas, srcCanvas);
924
925                 if (_ResUtil::NeedToConvertCoord())
926                 {
927                         Point pcDestPoint = _ResUtil::ConvertToPhyCoord(vcDestPoint);
928                         Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
929
930                         return (this->_pNativeCanvas->*fnCopy)(pcDestPoint, *_pNativeCanvas, pcSrcRect);
931                 }
932                 else
933                 {
934                         return (this->_pNativeCanvas->*fnCopy)(vcDestPoint, *_pNativeCanvas, vcSrcRect);
935                 }
936         }
937
938         // never!!
939         return E_SYSTEM;
940 }
941
942 result
943 _CanvasImpl::CopyEx(const FloatPoint& vcDestPointF, const _CanvasImpl& srcCanvas, const FloatRectangle& vcSrcRectF)
944 {
945         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
946
947         if (this != &srcCanvas)
948         {
949                 return this->Copy(vcDestPointF, srcCanvas, vcSrcRectF);
950         }
951
952         // validity check as _CanvasImpl::Copy()
953         SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(srcCanvas), E_INVALID_ARG, "The specified source canvas is invalid.");
954
955         FloatRectangle srcRectCanvasF = _GetBoundsRelF(srcCanvas);
956
957         if (srcRectCanvasF.IsEmpty())
958         {
959                 return E_SUCCESS;
960         }
961
962         result r = _Util::Validate(vcSrcRectF, srcRectCanvasF);
963
964         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
965
966         // check if destRect is in this canvas.
967         FloatRectangle destRectF(vcDestPointF.x, vcDestPointF.y, vcSrcRectF.width, vcSrcRectF.height);
968         FloatRectangle destRectCanvasF = _GetBoundsRelF(*this);
969
970         if (destRectCanvasF.IsEmpty())
971         {
972                 return E_SUCCESS;
973         }
974
975         r = _Util::Validate(destRectF, destRectCanvasF);
976
977         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
978
979         int pixelPerLine = 0;
980
981         {
982                 BufferInfo bufferInfo;
983
984                 result r = this->_pNativeCanvas->Lock(bufferInfo);
985
986                 //?? log
987                 SysTryReturn(NID_GRP, r == E_SUCCESS, r, E_SYSTEM, "[] ");
988
989                 this->_pNativeCanvas->Unlock();
990
991                 pixelPerLine = bufferInfo.pitch / (bufferInfo.bitsPerPixel / 8);
992         }
993
994         Point vcDestPoint(_FloatToIntForPos(vcDestPointF.x), _FloatToIntForPos(vcDestPointF.y));
995         Rectangle vcSrcRect(_FloatToIntForPos(vcSrcRectF.x), _FloatToIntForPos(vcSrcRectF.y), _FloatToIntForSize(vcSrcRectF.width), _FloatToIntForSize(vcSrcRectF.height));
996
997         //?? Auto-scaling should be applied to vc**** parameters later
998         int sourDistance = vcSrcRect.y * pixelPerLine + vcSrcRect.x;
999         int destDistance = vcDestPoint.y * pixelPerLine + vcDestPoint.x;
1000
1001         typedef result (_Canvas::* FnCopy)(const Point&, const _Canvas&, const Rectangle&);
1002         FnCopy fnCopyF = (destDistance < sourDistance) ? FnCopy(&_Canvas::Copy) : FnCopy(&_Canvas::CopyReverse);
1003
1004         if (fnCopyF)
1005         {
1006                 EXTRACT_CANVASEX(_pNativeCanvas, srcCanvas);
1007
1008                 if (_ResUtil::NeedToConvertCoord())
1009                 {
1010                         FloatPoint pcDestPointF = _ResUtil::ConvertToPhyCoord(vcDestPointF);
1011                         FloatRectangle pcSrcRectF = _ResUtil::ConvertToPhyCoord(vcSrcRectF);
1012
1013                         Point pcDestPoint(_FloatToIntForPos(pcDestPointF.x), _FloatToIntForPos(pcDestPointF.y));
1014                         Rectangle pcSrcRect(_FloatToIntForPos(pcSrcRectF.x), _FloatToIntForPos(pcSrcRectF.y), _FloatToIntForSize(pcSrcRectF.width), _FloatToIntForSize(pcSrcRectF.height));
1015
1016                         return (this->_pNativeCanvas->*fnCopyF)(pcDestPoint, *_pNativeCanvas, pcSrcRect);
1017                 }
1018                 else
1019                 {
1020                         return (this->_pNativeCanvas->*fnCopyF)(vcDestPoint, *_pNativeCanvas, vcSrcRect);
1021                 }
1022         }
1023
1024         // never!!
1025         return E_SYSTEM;
1026 }
1027
1028 result
1029 _CanvasImpl::DrawArc(const FloatRectangle& vcBounds, float startAngle, float endAngle, ArcStyle arcStyle)
1030 {
1031         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1032         SysTryReturnResult(NID_GRP, ARC_STYLE_MIN < arcStyle && arcStyle < ARC_STYLE_MAX, E_INVALID_ARG, "The invalid arc type(%d) is given.", arcStyle);
1033         SysTryReturnResult(NID_GRP, &vcBounds, E_INVALID_ARG, "The given rectangle is invalid.");
1034         SysTryReturnResult(NID_GRP, (vcBounds.width >= 0.0f) && (vcBounds.height >= 0.0f), E_OUT_OF_RANGE,
1035                                           "The given rectangle(width:%f,height:%f) is out of range.", vcBounds.width, vcBounds.height);
1036
1037         return _CanvasImplPrivate::DrawArc(this, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcBounds), double(startAngle), double(endAngle), arcStyle);
1038 }
1039
1040 result
1041 _CanvasImpl::DrawArc(const Rectangle& vcBounds, int startAngle, int endAngle, ArcStyle arcStyle)
1042 {
1043         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1044         SysTryReturnResult(NID_GRP, ARC_STYLE_MIN < arcStyle && arcStyle < ARC_STYLE_MAX, E_INVALID_ARG, "The invalid arc type(%d) is given.", arcStyle);
1045         SysTryReturnResult(NID_GRP, &vcBounds, E_INVALID_ARG, "The given rectangle is invalid.");
1046         SysTryReturnResult(NID_GRP, (vcBounds.width >= 0) && (vcBounds.height >= 0), E_OUT_OF_RANGE,
1047                                           "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
1048
1049         return _CanvasImplPrivate::DrawArc(this, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcBounds), double(startAngle), double(endAngle), arcStyle);
1050 }
1051
1052 result
1053 _CanvasImpl::DrawBitmap(const Rectangle& vcRect, const _BitmapImpl& bitmap)
1054 {
1055         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1056
1057         return this->DrawBitmap(FloatRectangle(float(vcRect.x), float(vcRect.y), float(vcRect.width), float(vcRect.height)), bitmap);
1058 }
1059
1060 result
1061 _CanvasImpl::DrawBitmap(const FloatRectangle& vcRectF, const _BitmapImpl& bitmap)
1062 {
1063         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1064
1065         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
1066         SysTryReturnResult(NID_GRP, &vcRectF, E_INVALID_ARG, "The source rectangle is invalid.");
1067
1068         // @ykahn vcRectF.width in [bitmap.GetActualWidth()..bitmap.GetWidthF()]
1069         if (vcRectF.width == bitmap.GetWidthF() && vcRectF.height == bitmap.GetHeightF())
1070         {
1071                 return this->DrawBitmap(FloatPoint(vcRectF.x, vcRectF.y), bitmap);
1072         }
1073
1074         if (_FloatToIntForSize(vcRectF.width) == bitmap.GetWidth() && _FloatToIntForSize(vcRectF.height) == bitmap.GetHeight())
1075         {
1076                 return this->DrawBitmap(FloatPoint(vcRectF.x, vcRectF.y), bitmap);
1077         }
1078
1079         // check if bimap can be drew in canvas area.
1080         FloatRectangle rtCanvasF = _GetBoundsRelF(*this);
1081
1082         if (rtCanvasF.IsEmpty())
1083         {
1084                 return E_SUCCESS;
1085         }
1086
1087         result r = _Util::Validate(vcRectF, rtCanvasF);
1088
1089         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
1090
1091         EXTRACT_BITMAPEX(pBitmapEx, bitmap);
1092
1093         if (_ResUtil::NeedToConvertCoord())
1094         {
1095                 FloatRectangle pcRectF = _ResUtil::ConvertToPhyCoord(vcRectF);
1096
1097                 _Util::Rectangle<double> pcRectD = _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(pcRectF);
1098
1099                 return this->_pNativeCanvas->DrawBitmap(pcRectD, *pBitmapEx);
1100         }
1101         else
1102         {
1103                 _Util::Rectangle<double> vcRectD = _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcRectF);
1104
1105                 return this->_pNativeCanvas->DrawBitmap(vcRectD, *pBitmapEx);
1106         }
1107 }
1108
1109 result
1110 _CanvasImpl::DrawBitmap(const Point& vcPoint, const _BitmapImpl& bitmap)
1111 {
1112         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1113
1114         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
1115
1116         Rectangle rtCanvas = _GetBoundsRel(*this);
1117
1118         if (rtCanvas.IsEmpty())
1119         {
1120                 return E_SUCCESS;
1121         }
1122
1123         result r = _Util::Validate(Rectangle(vcPoint.x, vcPoint.y, bitmap.GetWidth(), bitmap.GetHeight()), rtCanvas);
1124
1125         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
1126
1127         EXTRACT_BITMAPEX(pBitmapEx, bitmap);
1128
1129         if (_ResUtil::NeedToConvertCoord())
1130         {
1131                 Tizen::Graphics::Dimension virSize;
1132                 Tizen::Graphics::Dimension phySize;
1133                 bool lazyScaling = Tizen::Graphics::_IsLazyScalingBitmap(bitmap, virSize, phySize);
1134
1135                 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
1136                 _Util::Point<int> pcPointI = _Util::Convert<Point, _Util::Point<int> >(pcPoint);
1137
1138                 if (lazyScaling)
1139                 {
1140                         EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
1141
1142                         return this->_pNativeCanvas->DrawBitmap(pcPointI, *pScaledBitmapEx);
1143                 }
1144                 else
1145                 {
1146                         return this->_pNativeCanvas->DrawBitmap(pcPointI, *pBitmapEx);
1147                 }
1148         }
1149         else
1150         {
1151                 _Util::Point<int> vcPointI = _Util::Convert<Point, _Util::Point<int> >(vcPoint);
1152
1153                 return this->_pNativeCanvas->DrawBitmap(vcPointI, *pBitmapEx);
1154         }
1155 }
1156
1157 result
1158 _CanvasImpl::DrawBitmap(const FloatPoint& vcPointF, const _BitmapImpl& bitmap)
1159 {
1160         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1161
1162         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
1163
1164         // This code is executed using neon.acceleration.
1165         {
1166                 bool isXEqualToInteger = _Util::Abs(vcPointF.x - int(vcPointF.x)) <= 0.01;
1167                 bool isYEqualToInteger = _Util::Abs(vcPointF.y - int(vcPointF.y)) <= 0.01;
1168
1169                 bool isCompositeModeUnbound = GetCompositeMode() == COMPOSITE_MODE_SRC_IN
1170                                                                          || GetCompositeMode() == COMPOSITE_MODE_DST_IN
1171                                                                          || GetCompositeMode() == COMPOSITE_MODE_SRC_OUT
1172                                                                          || GetCompositeMode() == COMPOSITE_MODE_DST_ATOP;
1173
1174                 if (isXEqualToInteger && isYEqualToInteger && !isCompositeModeUnbound)
1175                 {
1176                         return this->DrawBitmap(Point(int(vcPointF.x), int(vcPointF.y)), bitmap);
1177                 }
1178         }
1179
1180         FloatRectangle rtCanvasF = _GetBoundsRelF(*this);
1181
1182         if (rtCanvasF.IsEmpty())
1183         {
1184                 return E_SUCCESS;
1185         }
1186
1187         result r = _Util::Validate(FloatRectangle(vcPointF.x, vcPointF.y, bitmap.GetWidthF(), bitmap.GetHeightF()), rtCanvasF);
1188
1189         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
1190
1191         EXTRACT_BITMAPEX(pBitmapEx, bitmap);
1192
1193         if (_ResUtil::NeedToConvertCoord())
1194         {
1195                 Tizen::Graphics::Dimension virSize;
1196                 Tizen::Graphics::Dimension phySize;
1197                 bool lazyScaling = Tizen::Graphics::_IsLazyScalingBitmap(bitmap, virSize, phySize);
1198
1199                 FloatPoint pcPointF = _ResUtil::ConvertToPhyCoord(vcPointF);
1200                 _Util::Point<double> pcPointD = _Util::Convert<FloatPoint, _Util::Point<double> >(pcPointF);
1201
1202                 if (lazyScaling)
1203                 {
1204                         EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
1205
1206                         return this->_pNativeCanvas->DrawBitmap(pcPointD, *pScaledBitmapEx);
1207                 }
1208                 else
1209                 {
1210                         return this->_pNativeCanvas->DrawBitmap(pcPointD, *pBitmapEx);
1211                 }
1212         }
1213         else
1214         {
1215                 _Util::Point<double> vcPointD = _Util::Convert<FloatPoint, _Util::Point<double> >(vcPointF);
1216
1217                 return this->_pNativeCanvas->DrawBitmap(vcPointD, *pBitmapEx);
1218         }
1219 }
1220
1221 result
1222 _CanvasImpl::DrawBitmap(const Rectangle& vcDestRect, const _BitmapImpl& srcBitmap, const Rectangle& vcSrcRect)
1223 {
1224         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1225
1226         return this->DrawBitmap(FloatRectangle(float(vcDestRect.x), float(vcDestRect.y), float(vcDestRect.width), float(vcDestRect.height)), srcBitmap, FloatRectangle(float(vcSrcRect.x), float(vcSrcRect.y), float(vcSrcRect.width), float(vcSrcRect.height)));
1227 }
1228
1229 result
1230 _CanvasImpl::DrawBitmap(const FloatRectangle& vcDestRectF, const _BitmapImpl& srcBitmap, const FloatRectangle& vcSrcRectF)
1231 {
1232         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1233
1234         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(srcBitmap), E_INVALID_ARG, "The source bitmap is invalid.");
1235
1236         SysTryReturnResult(NID_GRP, (&vcSrcRectF) && (&vcDestRectF), E_INVALID_ARG, "The given rectangle is invalid.");
1237
1238         SysTryReturnResult(NID_GRP, (vcSrcRectF.width >= 0.0f) && (vcSrcRectF.height >= 0.0f), E_OUT_OF_RANGE, "The given source rectangle(width:%f,height:%f) is out of range.", vcSrcRectF.width,  vcSrcRectF.height);
1239         SysTryReturnResult(NID_GRP, (vcDestRectF.width >= 0.0f) && (vcDestRectF.height >= 0.0f), E_OUT_OF_RANGE, "The given destination rectangle(width:%f,height:%f) is out of range.", vcDestRectF.width, vcDestRectF.height);
1240
1241         if (vcSrcRectF.width == 0.0f || vcSrcRectF.height == 0.0f)
1242         {
1243                 return E_SUCCESS;
1244         }
1245
1246         if (vcDestRectF.width == 0.0f || vcDestRectF.height == 0.0f)
1247         {
1248                 return E_SUCCESS;
1249         }
1250
1251         if ((vcSrcRectF.x < 0.0f) || (vcSrcRectF.y < 0.0f) || (vcSrcRectF.x + vcSrcRectF.width > srcBitmap.GetWidthF()) || (vcSrcRectF.y + vcSrcRectF.height > srcBitmap.GetHeightF()))
1252         {
1253                 SysTryReturnResult(NID_GRP, 0, E_OUT_OF_RANGE, "The specified region of source bitmap is out of range.");
1254         }
1255
1256         if (vcSrcRectF.width == srcBitmap.GetWidthF() && vcSrcRectF.height == srcBitmap.GetHeightF())
1257         {
1258                 return this->DrawBitmap(vcDestRectF, srcBitmap);
1259         }
1260
1261         // check if srcRect is in bitmap's area.
1262         result r = _Util::Validate(vcSrcRectF, FloatRectangle(0, 0, srcBitmap.GetWidthF(), srcBitmap.GetHeightF()));
1263
1264         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
1265
1266         // check if destRect is in this canvas.
1267         FloatRectangle rtCanvas = _GetBoundsRelF(*this);
1268
1269         if (rtCanvas.IsEmpty())
1270         {
1271                 return E_SUCCESS;
1272         }
1273
1274         r = _Util::Validate(vcDestRectF, rtCanvas);
1275
1276         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
1277
1278         EXTRACT_BITMAPEX(pBitmapEx, srcBitmap);
1279
1280         if (_ResUtil::NeedToConvertCoord())
1281         {
1282                 Tizen::Graphics::Dimension virSize;
1283                 Tizen::Graphics::Dimension phySize;
1284                 bool lazyScaling = Tizen::Graphics::_IsLazyScalingBitmap(srcBitmap, virSize, phySize);
1285
1286                 FloatRectangle pcDestRectF = _ResUtil::ConvertToPhyCoord(vcDestRectF);
1287
1288                 _Util::Rectangle<double> pcDestRectD = _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(pcDestRectF);
1289
1290                 if (lazyScaling)
1291                 {
1292                         _Util::Rectangle<double> vcSrcRectD = _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcSrcRectF);
1293
1294                         return this->_pNativeCanvas->DrawBitmap(pcDestRectD, *pBitmapEx, vcSrcRectD);
1295                 }
1296                 else
1297                 {
1298                         FloatRectangle pcSrcRectF = _ResUtil::ConvertToPhyCoord(vcSrcRectF);
1299
1300                         _Util::Rectangle<double> pcSrcRectD = _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(pcSrcRectF);
1301
1302                         return this->_pNativeCanvas->DrawBitmap(pcDestRectD, *pBitmapEx, pcSrcRectD);
1303                 }
1304         }
1305         else
1306         {
1307                 _Util::Rectangle<double> vcSrcRectD = _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcSrcRectF);
1308                 _Util::Rectangle<double> vcDestRectD = _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcDestRectF);
1309
1310                 return this->_pNativeCanvas->DrawBitmap(vcDestRectD, *pBitmapEx, vcSrcRectD);
1311         }
1312 }
1313
1314 result
1315 _CanvasImpl::DrawBitmap(const Point& vcPoint, const _BitmapImpl& bitmap, FlipDirection dir)
1316 {
1317         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1318
1319         return this->DrawBitmap(FloatPoint(float(vcPoint.x), float(vcPoint.y)), bitmap, dir);
1320 }
1321
1322 result
1323 _CanvasImpl::DrawBitmap(const FloatPoint& vcPointF, const _BitmapImpl& bitmap, FlipDirection dir)
1324 {
1325         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1326
1327         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
1328
1329         switch (dir)
1330         {
1331         case FLIP_DIRECTION_HORIZONTAL:
1332         case FLIP_DIRECTION_VERTICAL:
1333                 break;
1334         default:
1335                 SysTryReturnResult(NID_GRP, 0, E_INVALID_ARG, "FlipStyle(%d) is invalid.", dir);
1336                 break;
1337         }
1338
1339         EXTRACT_BITMAPEX(pBitmapEx, bitmap);
1340
1341         if (_ResUtil::NeedToConvertCoord())
1342         {
1343                 Tizen::Graphics::Dimension virSize;
1344                 Tizen::Graphics::Dimension phySize;
1345                 bool lazyScaling = Tizen::Graphics::_IsLazyScalingBitmap(bitmap, virSize, phySize);
1346
1347                 FloatPoint pcPointF = _ResUtil::ConvertToPhyCoord(vcPointF);
1348
1349                 _Util::Point<double> pcPointD = _Util::Convert<FloatPoint, _Util::Point<double> >(pcPointF);
1350
1351                 if (lazyScaling)
1352                 {
1353                         EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
1354
1355                         return this->_pNativeCanvas->DrawBitmap(pcPointD, *pScaledBitmapEx, dir);
1356                 }
1357                 else
1358                 {
1359                         return this->_pNativeCanvas->DrawBitmap(pcPointD, *pBitmapEx, dir);
1360                 }
1361         }
1362         else
1363         {
1364                 _Util::Point<double> vcPointD = _Util::Convert<FloatPoint, _Util::Point<double> >(vcPointF);
1365
1366                 return this->_pNativeCanvas->DrawBitmap(vcPointD, *pBitmapEx, dir);
1367         }
1368 }
1369
1370 result
1371 _CanvasImpl::DrawBitmap(const Point& vcPoint, const _BitmapImpl& bitmap, const Point& vcPivot, int degree)
1372 {
1373         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1374
1375         return this->DrawBitmap(FloatPoint(float(vcPoint.x), float(vcPoint.y)), bitmap, FloatPoint(float(vcPivot.x), float(vcPivot.y)), float(degree));
1376 }
1377
1378 result
1379 _CanvasImpl::DrawBitmap(const FloatPoint& vcPointF, const _BitmapImpl& bitmap, const FloatPoint& vcPivotF, float degree)
1380 {
1381         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1382
1383         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
1384
1385         EXTRACT_BITMAPEX(pBitmapEx, bitmap);
1386
1387         if (_ResUtil::NeedToConvertCoord())
1388         {
1389                 Tizen::Graphics::Dimension virSize;
1390                 Tizen::Graphics::Dimension phySize;
1391                 bool lazyScaling = Tizen::Graphics::_IsLazyScalingBitmap(bitmap, virSize, phySize);
1392
1393                 FloatPoint pcPointF = _ResUtil::ConvertToPhyCoord(vcPointF);
1394                 FloatPoint pcPivotF = _ResUtil::ConvertToPhyCoord(vcPivotF);
1395
1396                 _Util::Point<double> pcPointD = _Util::Convert<FloatPoint, _Util::Point<double> >(pcPointF);
1397                 _Util::Point<double> pcPivotD = _Util::Convert<FloatPoint, _Util::Point<double> >(pcPivotF);
1398
1399                 if (lazyScaling)
1400                 {
1401                         EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
1402
1403                         return this->_pNativeCanvas->DrawBitmap(pcPointD, *pScaledBitmapEx, pcPivotD, double(degree));
1404                 }
1405                 else
1406                 {
1407                         return this->_pNativeCanvas->DrawBitmap(pcPointD, *pBitmapEx, pcPivotD, double(degree));
1408                 }
1409         }
1410         else
1411         {
1412                 return this->_pNativeCanvas->DrawBitmap(_Util::Convert<FloatPoint, _Util::Point<double> >(vcPointF), *pBitmapEx, _Util::Convert<FloatPoint, _Util::Point<double> >(vcPivotF), double(degree));
1413         }
1414 }
1415
1416 result
1417 _CanvasImpl::DrawNinePatchedBitmap(const Rectangle& vcRect, const _BitmapImpl& bitmap)
1418 {
1419         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1420
1421         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
1422
1423         SysTryReturnResult(NID_GRP, bitmap.IsNinePatchedBitmap(), E_INVALID_ARG, "The source bitmap is not a nine patched bitmap.");
1424
1425         // check if bimap can be drew in canvas area.
1426         Rectangle rtCanvas = _GetBoundsRel(*this);
1427
1428         if (rtCanvas.IsEmpty())
1429         {
1430                 SysTryReturnResult(NID_GRP, 0, E_OPERATION_FAILED, "Cannot get the bounds of the canvas.");
1431         }
1432
1433         result r = _Util::Validate(vcRect, rtCanvas);
1434
1435         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
1436
1437         EXTRACT_BITMAPEX(pBitmapEx, bitmap);
1438
1439         if (_ResUtil::NeedToConvertCoord())
1440         {
1441                 Tizen::Graphics::Dimension virSize;
1442                 Tizen::Graphics::Dimension phySize;
1443                 bool lazyScaling = Tizen::Graphics::_IsLazyScalingBitmap(bitmap, virSize, phySize);
1444
1445                 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
1446
1447                 if (lazyScaling)
1448                 {
1449                         EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
1450
1451                         return this->_pNativeCanvas->DrawNinePatchedBitmap(pcRect, *pScaledBitmapEx);
1452                 }
1453                 else
1454                 {
1455                         return this->_pNativeCanvas->DrawNinePatchedBitmap(pcRect, *pBitmapEx);
1456                 }
1457         }
1458         else
1459         {
1460                 return this->_pNativeCanvas->DrawNinePatchedBitmap(vcRect, *pBitmapEx);
1461         }
1462 }
1463
1464 result
1465 _CanvasImpl::DrawNinePatchedBitmap(const FloatRectangle& vcRectF, const _BitmapImpl& bitmap)
1466 {
1467         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1468
1469         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
1470
1471         SysTryReturnResult(NID_GRP, bitmap.IsNinePatchedBitmap(), E_INVALID_ARG, "The source bitmap is not a nine patched bitmap.");
1472
1473         // check if bimap can be drew in canvas area.
1474         FloatRectangle rtCanvasF = _GetBoundsRelF(*this);
1475
1476         if (rtCanvasF.IsEmpty())
1477         {
1478                 SysTryReturnResult(NID_GRP, 0, E_OPERATION_FAILED, "Cannot get the bounds of the canvas.");
1479         }
1480
1481         result r = _Util::Validate(vcRectF, rtCanvasF);
1482
1483         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
1484
1485         EXTRACT_BITMAPEX(pBitmapEx, bitmap);
1486
1487         if (_ResUtil::NeedToConvertCoord())
1488         {
1489                 Tizen::Graphics::Dimension virSize;
1490                 Tizen::Graphics::Dimension phySize;
1491                 bool lazyScaling = Tizen::Graphics::_IsLazyScalingBitmap(bitmap, virSize, phySize);
1492
1493                 FloatRectangle pcRectF = _ResUtil::ConvertToPhyCoord(vcRectF);
1494
1495                 Rectangle pcRect(_FloatToIntForPos(pcRectF.x), _FloatToIntForPos(pcRectF.y), _FloatToIntForSize(pcRectF.width), _FloatToIntForSize(pcRectF.height));
1496
1497                 if (lazyScaling)
1498                 {
1499                         EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
1500
1501                         return this->_pNativeCanvas->DrawNinePatchedBitmap(pcRect, *pScaledBitmapEx);
1502                 }
1503                 else
1504                 {
1505                         return this->_pNativeCanvas->DrawNinePatchedBitmap(pcRect, *pBitmapEx);
1506                 }
1507         }
1508         else
1509         {
1510                 Rectangle vcRect(_FloatToIntForPos(vcRectF.x), _FloatToIntForPos(vcRectF.y), _FloatToIntForSize(vcRectF.width), _FloatToIntForSize(vcRectF.height));
1511
1512                 return this->_pNativeCanvas->DrawNinePatchedBitmap(vcRect, *pBitmapEx);
1513         }
1514 }
1515
1516 result
1517 _CanvasImpl::DrawNineTiledBitmap(const Rectangle& vcRect, const _BitmapImpl& bitmap)
1518 {
1519         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1520
1521         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
1522
1523         SysTryReturnResult(NID_GRP, bitmap.IsNinePatchedBitmap(), E_INVALID_ARG, "The source bitmap is not a nine tiled bitmap.");
1524
1525         // check if bimap can be drew in canvas area.
1526         Rectangle rtCanvas = _GetBoundsRel(*this);
1527
1528         if (rtCanvas.IsEmpty())
1529         {
1530                 SysTryReturnResult(NID_GRP, 0, E_OPERATION_FAILED, "Cannot get the bounds of the canvas.");
1531         }
1532
1533         result r = _Util::Validate(vcRect, rtCanvas);
1534
1535         if (IsFailed(r))
1536         {
1537                 return E_SUCCESS;
1538         }
1539
1540         EXTRACT_BITMAPEX(pBitmapEx, bitmap);
1541
1542         if (_ResUtil::NeedToConvertCoord())
1543         {
1544                 Tizen::Graphics::Dimension virSize;
1545                 Tizen::Graphics::Dimension phySize;
1546                 bool lazyScaling = Tizen::Graphics::_IsLazyScalingBitmap(bitmap, virSize, phySize);
1547
1548                 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
1549
1550                 if (lazyScaling)
1551                 {
1552                         EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
1553
1554                         return this->_pNativeCanvas->DrawNineTiledBitmap(pcRect, *pScaledBitmapEx);
1555                 }
1556                 else
1557                 {
1558                         return this->_pNativeCanvas->DrawNineTiledBitmap(pcRect, *pBitmapEx);
1559                 }
1560         }
1561         else
1562         {
1563                 return this->_pNativeCanvas->DrawNineTiledBitmap(vcRect, *pBitmapEx);
1564         }
1565 }
1566
1567 result
1568 _CanvasImpl::DrawEllipse(const Rectangle& vcBounds)
1569 {
1570         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1571         SysTryReturnResult(NID_GRP, &vcBounds, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1572         SysTryReturnResult(NID_GRP, (vcBounds.width >= 0) && (vcBounds.height >= 0), E_OUT_OF_RANGE,
1573                                           "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
1574
1575         return _CanvasImplPrivate::DrawEllipse(this, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcBounds));
1576 }
1577
1578 result
1579 _CanvasImpl::DrawEllipse(const FloatRectangle& vcBounds)
1580 {
1581         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1582         SysTryReturnResult(NID_GRP, &vcBounds, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1583         SysTryReturnResult(NID_GRP, (vcBounds.width >= 0.0f) && (vcBounds.height >= 0.0f), E_OUT_OF_RANGE,
1584                                           "The given rectangle(width:%f,height:%f) is out of range.", vcBounds.width, vcBounds.height);
1585
1586         return _CanvasImplPrivate::DrawEllipse(this, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcBounds));
1587 }
1588
1589 result
1590 _CanvasImpl::DrawLine(const Point& vcPoint1, const Point& vcPoint2)
1591 {
1592         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1593
1594         return _CanvasImplPrivate::DrawLine(this,
1595                 _Util::Convert<Point, _Util::Point<double> >(vcPoint1),
1596                 _Util::Convert<Point, _Util::Point<double> >(vcPoint2));
1597 }
1598
1599 result
1600 _CanvasImpl::DrawLine(const FloatPoint& vcPoint1, const FloatPoint& vcPoint2)
1601 {
1602         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1603
1604         return _CanvasImplPrivate::DrawLine(this,
1605                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint1),
1606                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint2));
1607 }
1608
1609 result
1610 _CanvasImpl::DrawPolygon(const Tizen::Base::Collection::IList& vcPoints)
1611 {
1612         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1613
1614         int numPoint = vcPoints.GetCount();
1615
1616         SysTryReturnResult(NID_GRP, numPoint >= 0, E_INVALID_ARG, "The number of points (%d) is not valid.", numPoint);
1617
1618         if (numPoint < 2) // TBD.
1619         {
1620                 return E_SUCCESS;
1621         }
1622
1623         std::unique_ptr<_Util::Point<double>[]> doublePoint;
1624
1625         {
1626                 _Util::Point<double>* pDoublePoint = _Util::Convert<Tizen::Base::Collection::IList, _Util::Point<double>*>(vcPoints);
1627
1628                 SysTryReturnResult(NID_GRP, pDoublePoint != null, E_INVALID_ARG, "The type of points is not valid.");
1629
1630                 doublePoint.reset(pDoublePoint);
1631         }
1632
1633         if (_ResUtil::NeedToConvertCoord())
1634         {
1635                 for (int i = 0; i < numPoint; i++)
1636                 {
1637                         doublePoint[i] = _ResUtil::ConvertToPhyCoord(doublePoint[i]);
1638                 }
1639
1640                 return this->_pNativeCanvas->DrawPolygon(doublePoint.get(), numPoint);
1641         }
1642         else
1643         {
1644                 return this->_pNativeCanvas->DrawPolygon(doublePoint.get(), numPoint);
1645         }
1646 }
1647
1648 result
1649 _CanvasImpl::DrawPolyline(const Tizen::Base::Collection::IList& vcPoints)
1650 {
1651         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1652
1653         int numPoint = vcPoints.GetCount();
1654
1655         SysTryReturnResult(NID_GRP, numPoint >= 0, E_INVALID_ARG, "The number of points (%d) is not valid.", numPoint);
1656
1657         if (numPoint < 2)
1658         {
1659                 return E_SUCCESS;
1660         }
1661
1662         std::unique_ptr<_Util::Point<double>[]> doublePoint;
1663
1664         {
1665                 _Util::Point<double>* pDoublePoint = _Util::Convert<Tizen::Base::Collection::IList, _Util::Point<double>*>(vcPoints);
1666
1667                 SysTryReturnResult(NID_GRP, pDoublePoint != null, E_INVALID_ARG, "The type of points is not valid.");
1668
1669                 doublePoint.reset(pDoublePoint);
1670         }
1671
1672         if (_ResUtil::NeedToConvertCoord())
1673         {
1674                 for (int i = 0; i < numPoint; i++)
1675                 {
1676                         doublePoint[i] = _ResUtil::ConvertToPhyCoord(doublePoint[i]);
1677                 }
1678
1679                 return this->_pNativeCanvas->DrawPolyline(doublePoint.get(), numPoint);
1680         }
1681         else
1682         {
1683                 return this->_pNativeCanvas->DrawPolyline(doublePoint.get(), numPoint);
1684         }
1685 }
1686
1687 result
1688 _CanvasImpl::DrawRectangle(const Rectangle& vcRect)
1689 {
1690         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1691         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1692         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1693
1694         return _CanvasImplPrivate::DrawRectangle(this, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcRect));
1695 }
1696
1697 result
1698 _CanvasImpl::DrawRectangle(const FloatRectangle& vcRect)
1699 {
1700         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1701         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1702         SysTryReturnResult(NID_GRP, (vcRect.width >= 0.0f) && (vcRect.height >= 0.0f), E_OUT_OF_RANGE, "The given rectangle(width:%f,height:%f) is out of range.", vcRect.width, vcRect.height);
1703
1704         return _CanvasImplPrivate::DrawRectangle(this, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcRect));
1705 }
1706
1707 result
1708 _CanvasImpl::DrawRoundRectangle(const Rectangle& vcRect, const Dimension& vcArcDim)
1709 {
1710         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1711         SysTryReturnResult(NID_GRP, (&vcRect) && (&vcArcDim), E_OUT_OF_RANGE, "The given rectangle is invalid.");
1712         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1713         SysTryReturnResult(NID_GRP, (vcArcDim.width >= 0) && (vcArcDim.height >= 0), E_OUT_OF_RANGE, "The given arc size(width:%d,height:%d) is out of range.", vcArcDim.width, vcArcDim.height);
1714
1715         return _CanvasImplPrivate::DrawRoundRectangle(this, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcRect), _Util::Convert<Dimension, _Util::Dimension<double> >(vcArcDim));
1716 }
1717
1718 result
1719 _CanvasImpl::DrawRoundRectangle(const FloatRectangle& vcRect, const FloatDimension& vcArcDim)
1720 {
1721         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1722         SysTryReturnResult(NID_GRP, (&vcRect) && (&vcArcDim), E_OUT_OF_RANGE, "The given rectangle is invalid.");
1723         SysTryReturnResult(NID_GRP, (vcRect.width >= 0.0f) && (vcRect.height >= 0.0f), E_OUT_OF_RANGE, "The given rectangle(width:%f,height:%f) is out of range.", vcRect.width, vcRect.height);
1724         SysTryReturnResult(NID_GRP, (vcArcDim.width >= 0.0f) && (vcArcDim.height >= 0.0f), E_OUT_OF_RANGE, "The given arc size(width:%f,height:%f) is out of range.", vcArcDim.width, vcArcDim.height);
1725
1726         return _CanvasImplPrivate::DrawRoundRectangle(this, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcRect), _Util::Convert<FloatDimension, _Util::Dimension<double> >(vcArcDim));
1727 }
1728
1729 result
1730 _CanvasImpl::DrawTriangle(const Point& vcPoint1, const Point& vcPoint2, const Point& vcPoint3)
1731 {
1732         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1733
1734         return _CanvasImplPrivate::DrawTriangle(this,
1735                 _Util::Convert<Point, _Util::Point<double> >(vcPoint1),
1736                 _Util::Convert<Point, _Util::Point<double> >(vcPoint2),
1737                 _Util::Convert<Point, _Util::Point<double> >(vcPoint3));
1738 }
1739
1740 result
1741 _CanvasImpl::DrawTriangle(const FloatPoint& vcPoint1, const FloatPoint& vcPoint2, const FloatPoint& vcPoint3)
1742 {
1743         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1744
1745         return _CanvasImplPrivate::DrawTriangle(this,
1746                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint1),
1747                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint2),
1748                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint3));
1749 }
1750
1751 result
1752 _CanvasImpl::FillEllipse(const Color& color, const Rectangle& vcBounds)
1753 {
1754         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1755         SysTryReturnResult(NID_GRP, &vcBounds, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1756         SysTryReturnResult(NID_GRP, (vcBounds.width >= 0) && (vcBounds.height >= 0), E_OUT_OF_RANGE,
1757                                           "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
1758
1759         return _CanvasImplPrivate::FillEllipse(this, color, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcBounds));
1760 }
1761
1762 result
1763 _CanvasImpl::FillEllipse(const Color& color, const FloatRectangle& vcBounds)
1764 {
1765         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1766         SysTryReturnResult(NID_GRP, &vcBounds, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1767         SysTryReturnResult(NID_GRP, (vcBounds.width >= 0.0f) && (vcBounds.height >= 0.0f), E_OUT_OF_RANGE,
1768                                           "The given rectangle(width:%f,height:%f) is out of range.", vcBounds.width, vcBounds.height);
1769
1770         return _CanvasImplPrivate::FillEllipse(this, color, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcBounds));
1771 }
1772
1773 result
1774 _CanvasImpl::FillPolygon(const Color& color, const Tizen::Base::Collection::IList& vcPoints)
1775 {
1776         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1777
1778         SysTryReturnResult(NID_GRP, &vcPoints, E_INVALID_ARG, "The given rectangle is invalid.");
1779
1780         int numPoint = vcPoints.GetCount();
1781
1782         SysTryReturnResult(NID_GRP, numPoint >= 0, E_INVALID_ARG, "The number of points (%d) is not valid.", numPoint);
1783
1784         if (numPoint < 3) // TBD.
1785         {
1786                 return E_SUCCESS;
1787         }
1788
1789         std::unique_ptr<_Util::Point<double>[]> doublePoint;
1790
1791         {
1792                 _Util::Point<double>* pDoublePoint = _Util::Convert<Tizen::Base::Collection::IList, _Util::Point<double>*>(vcPoints);
1793
1794                 SysTryReturnResult(NID_GRP, pDoublePoint != null, E_INVALID_ARG, "The type of points is not valid.");
1795
1796                 doublePoint.reset(pDoublePoint);
1797         }
1798
1799         if (_ResUtil::NeedToConvertCoord())
1800         {
1801                 for (int i = 0; i < numPoint; i++)
1802                 {
1803                         doublePoint[i] = _ResUtil::ConvertToPhyCoord(doublePoint[i]);
1804                 }
1805
1806                 return this->_pNativeCanvas->FillPolygon(color, doublePoint.get(), numPoint);
1807         }
1808         else
1809         {
1810                 return this->_pNativeCanvas->FillPolygon(color, doublePoint.get(), numPoint);
1811         }
1812 }
1813
1814 result
1815 _CanvasImpl::FillRectangle(const Color& color, const Rectangle& vcRect)
1816 {
1817         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1818         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1819         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1820
1821         return _CanvasImplPrivate::FillRectangle(this, color, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcRect));
1822 }
1823
1824 result
1825 _CanvasImpl::FillRectangle(const Color& color, const FloatRectangle& vcRect)
1826 {
1827         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1828         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1829         SysTryReturnResult(NID_GRP, (vcRect.width >= 0.0f) && (vcRect.height >= 0.0f), E_OUT_OF_RANGE, "The given rectangle(width:%f,height:%f) is out of range.", vcRect.width, vcRect.height);
1830
1831         return _CanvasImplPrivate::FillRectangle(this, color, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcRect));
1832 }
1833
1834 result
1835 _CanvasImpl::FillRoundRectangle(const Color& color, const Rectangle& vcRect, const Dimension& vcArcDim)
1836 {
1837         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1838         SysTryReturnResult(NID_GRP, (&vcRect) && (&vcArcDim), E_OUT_OF_RANGE, "The given rectangle is invalid.");
1839         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1840         SysTryReturnResult(NID_GRP, (vcArcDim.width >= 0) && (vcArcDim.height >= 0), E_OUT_OF_RANGE, "The given arc size(width:%d,height:%d) is out of range.", vcArcDim.width, vcArcDim.height);
1841
1842         return _CanvasImplPrivate::FillRoundRectangle(this, color, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcRect), _Util::Convert<Dimension, _Util::Dimension<double> >(vcArcDim));
1843 }
1844
1845 result
1846 _CanvasImpl::FillRoundRectangle(const Color& color, const FloatRectangle& vcRect, const FloatDimension& vcArcDim)
1847 {
1848         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1849         SysTryReturnResult(NID_GRP, (&vcRect) && (&vcArcDim), E_OUT_OF_RANGE, "The given rectangle is invalid.");
1850         SysTryReturnResult(NID_GRP, (vcRect.width >= 0.0f) && (vcRect.height >= 0.0f), E_OUT_OF_RANGE, "The given rectangle(width:%f,height:%f) is out of range.", vcRect.width, vcRect.height);
1851         SysTryReturnResult(NID_GRP, (vcArcDim.width >= 0.0f) && (vcArcDim.height >= 0.0f), E_OUT_OF_RANGE, "The given arc size(width:%f,height:%f) is out of range.", vcArcDim.width, vcArcDim.height);
1852
1853         return _CanvasImplPrivate::FillRoundRectangle(this, color, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcRect), _Util::Convert<FloatDimension, _Util::Dimension<double> >(vcArcDim));
1854 }
1855
1856 result
1857 _CanvasImpl::FillTriangle(const Color& color, const FloatPoint& vcPoint1, const FloatPoint& vcPoint2, const FloatPoint& vcPoint3)
1858 {
1859         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1860
1861         return _CanvasImplPrivate::FillTriangle(this, color,
1862                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint1),
1863                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint2),
1864                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint3));
1865 }
1866
1867 result
1868 _CanvasImpl::FillTriangle(const Color& color, const Point& vcPoint1, const Point& vcPoint2, const Point& vcPoint3)
1869 {
1870         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1871
1872         return _CanvasImplPrivate::FillTriangle(this, color,
1873                 _Util::Convert<Point, _Util::Point<double> >(vcPoint1),
1874                 _Util::Convert<Point, _Util::Point<double> >(vcPoint2),
1875                 _Util::Convert<Point, _Util::Point<double> >(vcPoint3));
1876 }
1877
1878 result
1879 _CanvasImpl::DrawText(const Point& vcPoint, const Tizen::Base::String& text)
1880 {
1881         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1882
1883         SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
1884
1885         if (_ResUtil::NeedToConvertCoord())
1886         {
1887                 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
1888
1889                 return this->_pNativeCanvas->DrawText(pcPoint, text);
1890         }
1891         else
1892         {
1893                 return this->_pNativeCanvas->DrawText(vcPoint, text);
1894         }
1895 }
1896
1897 result
1898 _CanvasImpl::DrawText(const Point& vcPoint, const Tizen::Base::String& text, int startIndex, int length)
1899 {
1900         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1901         SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
1902         SysTryReturnResult(NID_GRP, length >= 0 && startIndex >= 0 && startIndex < text.GetLength(), E_OUT_OF_RANGE, "The value of the length (%d),  startIndex(%d) are outside the valid range defined by the method.", length, startIndex);
1903
1904         if (text.GetLength() == 0)
1905         {
1906                 return E_SUCCESS;
1907         }
1908
1909         if (_ResUtil::NeedToConvertCoord())
1910         {
1911                 Point pcPt = _ResUtil::ConvertToPhyCoord(vcPoint);
1912
1913                 return this->_pNativeCanvas->DrawText(pcPt, text, startIndex, length);
1914         }
1915         else
1916         {
1917                 return this->_pNativeCanvas->DrawText(vcPoint, text, startIndex, length);
1918         }
1919 }
1920
1921 result
1922 _CanvasImpl::DrawText(const Point& vcPoint, const Tizen::Base::String& text, int startIndex, const Color& outlineColor)
1923 {
1924         const char* pNotConstructedYet = "[E_OPERATION_FAILED] This instance is not constructed yet.";
1925
1926         SysTryReturn(NID_GRP, this, E_OPERATION_FAILED, E_OPERATION_FAILED, pNotConstructedYet);
1927         SysTryReturn(NID_GRP, this->_pNativeCanvas, E_OPERATION_FAILED, E_OPERATION_FAILED, pNotConstructedYet);
1928         SysTryReturn(NID_GRP, this->_pNativeCanvas->IsValid(), E_OPERATION_FAILED, E_OPERATION_FAILED, pNotConstructedYet);
1929
1930         SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
1931
1932         return this->DrawText(vcPoint, text, startIndex, text.GetLength(), outlineColor);
1933 }
1934
1935 result
1936 _CanvasImpl::DrawText(const Point& vcPoint, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor)
1937 {
1938         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1939
1940         SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
1941
1942         SysTryReturnResult(NID_GRP, length >= 0, E_OUT_OF_RANGE,
1943                                           "The value of the length (%d) is outside the valid range defined by the method.",
1944                                           length);
1945
1946         if (text.GetLength() == 0)
1947         {
1948                 return E_SUCCESS;
1949         }
1950
1951         if (_ResUtil::NeedToConvertCoord())
1952         {
1953                 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
1954
1955                 return this->_pNativeCanvas->DrawText(pcPoint, text, startIndex, length, outlineColor);
1956         }
1957         else
1958         {
1959                 return this->_pNativeCanvas->DrawText(vcPoint, text, startIndex, length, outlineColor);
1960         }
1961 }
1962
1963 result
1964 _CanvasImpl::DrawText(const Point& vcPoint, const EnrichedText& etext)
1965 {
1966         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1967
1968         const _EnrichedTextImpl* pImpl = _EnrichedTextImpl::GetInstance(etext);
1969
1970         if (pImpl == null)
1971         {
1972                 return E_OPERATION_FAILED;
1973         }
1974
1975         Tizen::Graphics::_Text::TextObject* pTextObject = const_cast <_EnrichedTextImpl*>(pImpl)->GetTextObject();
1976
1977         if (pTextObject == null)
1978         {
1979                 return E_OPERATION_FAILED;
1980         }
1981
1982         FloatRectangle bounds = pImpl->GetBoundsF();
1983         FloatRectangle rect(float(vcPoint.x), float(vcPoint.y), bounds.width, bounds.height);
1984
1985         pTextObject->SetBounds(rect);
1986         pTextObject->Draw(*this);
1987
1988         return E_SUCCESS;
1989 }
1990
1991 result
1992 _CanvasImpl::DrawText(const FloatPoint& vcPointF, const Tizen::Base::String& text)
1993 {
1994         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1995
1996         SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
1997
1998         if (_ResUtil::NeedToConvertCoord())
1999         {
2000                 Point pcPoint;
2001                 pcPoint.x = _FloatToIntForPos(_ResUtil::ConvertToPhyCoord(vcPointF.x));
2002                 pcPoint.y = _FloatToIntForPos(_ResUtil::ConvertToPhyCoord(vcPointF.y));
2003
2004                 return this->_pNativeCanvas->DrawText(pcPoint, text);
2005         }
2006         else
2007         {
2008                 Point vcPoint;
2009                 vcPoint.x = _FloatToIntForPos(vcPointF.x);
2010                 vcPoint.y = _FloatToIntForPos(vcPointF.y);
2011
2012                 return this->_pNativeCanvas->DrawText(vcPoint, text);
2013         }
2014 }
2015
2016 result
2017 _CanvasImpl::DrawText(const FloatPoint& vcPointF, const Tizen::Base::String& text, int startIndex, int length)
2018 {
2019         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2020         SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
2021         SysTryReturnResult(NID_GRP, length >= 0 && startIndex >= 0 && startIndex < text.GetLength(), E_OUT_OF_RANGE, "The value of the length (%d),  startIndex(%d) are outside the valid range defined by the method.", length, startIndex);
2022
2023         if (text.GetLength() == 0)
2024         {
2025                 return E_SUCCESS;
2026         }
2027
2028         if (_ResUtil::NeedToConvertCoord())
2029         {
2030                 Point pcPoint;
2031                 pcPoint.x = _FloatToIntForPos(_ResUtil::ConvertToPhyCoord(vcPointF.x));
2032                 pcPoint.y = _FloatToIntForPos(_ResUtil::ConvertToPhyCoord(vcPointF.y));
2033
2034                 return this->_pNativeCanvas->DrawText(pcPoint, text, startIndex, length);
2035         }
2036         else
2037         {
2038                 Point vcPoint;
2039                 vcPoint.x = _FloatToIntForPos(vcPointF.x);
2040                 vcPoint.y = _FloatToIntForPos(vcPointF.y);
2041
2042                 return this->_pNativeCanvas->DrawText(vcPoint, text, startIndex, length);
2043         }
2044 }
2045
2046 result
2047 _CanvasImpl::DrawText(const FloatPoint& vcPointF, const Tizen::Base::String& text, int startIndex, const Color& outlineColor)
2048 {
2049         const char* pNotConstructedYet = "[E_OPERATION_FAILED] This instance is not constructed yet.";
2050
2051         SysTryReturn(NID_GRP, this, E_OPERATION_FAILED, E_OPERATION_FAILED, pNotConstructedYet);
2052         SysTryReturn(NID_GRP, this->_pNativeCanvas, E_OPERATION_FAILED, E_OPERATION_FAILED, pNotConstructedYet);
2053         SysTryReturn(NID_GRP, this->_pNativeCanvas->IsValid(), E_OPERATION_FAILED, E_OPERATION_FAILED, pNotConstructedYet);
2054
2055         SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
2056
2057         Point vcPoint;
2058         vcPoint.x = _FloatToIntForPos(vcPointF.x);
2059         vcPoint.y = _FloatToIntForPos(vcPointF.y);
2060
2061         return this->DrawText(vcPoint, text, startIndex, text.GetLength(), outlineColor);
2062 }
2063
2064 result
2065 _CanvasImpl::DrawText(const FloatPoint& vcPointF, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor)
2066 {
2067         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2068
2069         SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
2070
2071         SysTryReturnResult(NID_GRP, length >= 0, E_OUT_OF_RANGE,
2072                                           "The value of the length (%d) is outside the valid range defined by the method.",
2073                                           length);
2074
2075         if (text.GetLength() == 0)
2076         {
2077                 return E_SUCCESS;
2078         }
2079
2080         if (_ResUtil::NeedToConvertCoord())
2081         {
2082                 Point pcPoint;
2083                 pcPoint.x = _FloatToIntForPos(_ResUtil::ConvertToPhyCoord(vcPointF.x));
2084                 pcPoint.y = _FloatToIntForPos(_ResUtil::ConvertToPhyCoord(vcPointF.y));
2085
2086                 return this->_pNativeCanvas->DrawText(pcPoint, text, startIndex, length, outlineColor);
2087         }
2088         else
2089         {
2090                 Point vcPoint;
2091                 vcPoint.x = _FloatToIntForPos(vcPointF.x);
2092                 vcPoint.y = _FloatToIntForPos(vcPointF.y);
2093
2094                 return this->_pNativeCanvas->DrawText(vcPoint, text, startIndex, length, outlineColor);
2095         }
2096 }
2097
2098 result
2099 _CanvasImpl::DrawText(const FloatPoint& vcPointF, const EnrichedText& etext)
2100 {
2101         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2102
2103         const _EnrichedTextImpl* pImpl = _EnrichedTextImpl::GetInstance(etext);
2104
2105         if (pImpl == null)
2106         {
2107                 return E_OPERATION_FAILED;
2108         }
2109
2110         Tizen::Graphics::_Text::TextObject* pTextObject = const_cast <_EnrichedTextImpl*>(pImpl)->GetTextObject();
2111
2112         if (pTextObject == null)
2113         {
2114                 return E_OPERATION_FAILED;
2115         }
2116
2117         FloatRectangle bounds = pImpl->GetBoundsF();
2118         FloatRectangle rect(vcPointF.x, vcPointF.y, bounds.width, bounds.height);
2119
2120         pTextObject->SetBounds(rect);
2121         pTextObject->Draw(*this);
2122
2123         return E_SUCCESS;
2124 }
2125
2126 Rectangle
2127 _CanvasImpl::GetBounds(void) const
2128 {
2129         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, Rectangle(), E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2130
2131         if (_ResUtil::NeedToConvertCoord())
2132         {
2133                 const _Util::Point<int>& pos = this->_pCoordHolder->canvasPos.vcInt;
2134                 const _Util::Dimension<int>& vcSize = this->_pCoordHolder->canvasSize.vcInt;
2135                 const Rectangle boundsFromPi = this->_pNativeCanvas->GetBounds();
2136
2137                 if ((vcSize.w == 0 && boundsFromPi.width > 0) || (vcSize.h == 0 && boundsFromPi.height > 0))
2138                 {
2139                         _CanvasImpl* pThis = const_cast<_CanvasImpl*>(this);
2140
2141                         _Util::Dimension<int> intPcSize = { boundsFromPi.width, boundsFromPi.height };
2142
2143                         pThis->_pCoordHolder->AssignCanvasSizeFromPcSize(intPcSize);
2144                 }
2145
2146                 // exception from the window canvas
2147                 if (boundsFromPi.x == 0 && boundsFromPi.y == 0)
2148                 {
2149                         return Rectangle(0, 0, vcSize.w, vcSize.h);
2150                 }
2151                 else
2152                 {
2153                         return Rectangle(pos.x, pos.y, vcSize.w, vcSize.h);
2154                 }
2155         }
2156         else
2157         {
2158                 return this->_pNativeCanvas->GetBounds();
2159         }
2160 }
2161
2162 FloatRectangle
2163 _CanvasImpl::GetBoundsF(void) const
2164 {
2165         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, FloatRectangle(), E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2166
2167         const Rectangle boundsFromPi = this->_pNativeCanvas->GetBounds();
2168
2169         if (_ResUtil::NeedToConvertCoord())
2170         {
2171                 const _Util::Point<float>& posF = this->_pCoordHolder->canvasPos.vcFloat;
2172                 const _Util::Dimension<float>& vcSizeF = this->_pCoordHolder->canvasSize.vcFloat;
2173
2174                 // exception from the window canvas
2175                 if (boundsFromPi.x == 0 && boundsFromPi.y == 0)
2176                 {
2177                         return FloatRectangle(0.0f, 0.0f, vcSizeF.w, vcSizeF.h);
2178                 }
2179                 else
2180                 {
2181                         return FloatRectangle(posF.x, posF.y, vcSizeF.w, vcSizeF.h);
2182                 }
2183         }
2184         else
2185         {
2186                 return FloatRectangle(static_cast<float>(boundsFromPi.x), static_cast<float>(boundsFromPi.x), static_cast<float>(boundsFromPi.width), static_cast<float>(boundsFromPi.height));
2187         }
2188 }
2189
2190
2191 FloatRectangle
2192 _CanvasImpl::GetActualBounds(void) const
2193 {
2194         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, FloatRectangle(), E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2195
2196         const Rectangle boundsFromPi = this->_pNativeCanvas->GetBounds();
2197
2198         if (_ResUtil::NeedToConvertCoord())
2199         {
2200                 const _Util::Point<float>& actualPosF = this->_pCoordHolder->canvasPos.vcFloatActual;
2201                 const _Util::Dimension<float>& vcActualSizeF = this->_pCoordHolder->canvasSize.vcFloatActual;
2202
2203                 // exception from the window canvas
2204                 if (boundsFromPi.x == 0 && boundsFromPi.y == 0)
2205                 {
2206                         return FloatRectangle(0.0f, 0.0f, vcActualSizeF.w, vcActualSizeF.h);
2207                 }
2208                 else
2209                 {
2210                         return FloatRectangle(actualPosF.x, actualPosF.y, vcActualSizeF.w, vcActualSizeF.h);
2211                 }
2212         }
2213         else
2214         {
2215                 return FloatRectangle(static_cast<float>(boundsFromPi.x), static_cast<float>(boundsFromPi.x), static_cast<float>(boundsFromPi.width), static_cast<float>(boundsFromPi.height));
2216         }
2217 }
2218
2219 LineStyle
2220 _CanvasImpl::GetLineStyle() const
2221 {
2222         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, LINE_STYLE_MAX, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2223
2224         return this->_pNativeCanvas->GetLineStyle();
2225 }
2226
2227 int
2228 _CanvasImpl::GetLineWidth() const
2229 {
2230         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, -1, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2231
2232         return this->_pCoordHolder->lineWidth.vcInt;
2233 }
2234
2235 float
2236 _CanvasImpl::GetLineWidthF() const
2237 {
2238         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, -1.0f, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2239
2240         return this->_pCoordHolder->lineWidth.vcFloat;
2241 }
2242
2243 LineCapStyle
2244 _CanvasImpl::GetLineCapStyle() const
2245 {
2246         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, LINE_CAP_STYLE_ROUND, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2247
2248         return this->_pNativeCanvas->GetLineCapStyle();
2249 }
2250
2251 LineJoinStyle
2252 _CanvasImpl::GetLineJoinStyle() const
2253 {
2254         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, LINE_JOIN_STYLE_ROUND, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2255
2256         return this->_pNativeCanvas->GetLineJoinStyle();
2257 }
2258
2259 result
2260 _CanvasImpl::SetLineStyle(LineStyle style)
2261 {
2262         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2263
2264         SysTryReturnResult(NID_GRP, LINE_STYLE_MIN < style && style < LINE_STYLE_MAX, E_INVALID_ARG, "The given line style(%d) is out of range.", style);
2265
2266         return this->_pNativeCanvas->SetLineStyle(style);
2267 }
2268
2269 result
2270 _CanvasImpl::SetLineWidth(int vcWidth)
2271 {
2272         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2273
2274         SysTryReturnResult(NID_GRP, vcWidth > 0, E_OUT_OF_RANGE, "The given line width(%d) is out of range.", vcWidth);
2275
2276         result r = E_SUCCESS;
2277
2278         if (_ResUtil::NeedToConvertCoord())
2279         {
2280                 int pcWidth = _ResUtil::ConvertToPhyCoordSize(vcWidth);
2281                 float pcWidthF = _ResUtil::ConvertToPhyCoordSize(float(vcWidth));
2282
2283                 if (vcWidth > 0 && pcWidth == 0)
2284                 {
2285                         pcWidth = 1;
2286                 }
2287
2288                 r = this->_pNativeCanvas->SetLineWidth(pcWidth, pcWidthF);
2289         }
2290         else
2291         {
2292                 r = this->_pNativeCanvas->SetLineWidth(vcWidth, float(vcWidth));
2293         }
2294
2295         if (IsSucceeded(r))
2296         {
2297                 this->_pCoordHolder->AssignLineWidthFromVc(vcWidth);
2298         }
2299
2300         return r;
2301 }
2302
2303 result
2304 _CanvasImpl::SetLineWidth(float vcWidthF)
2305 {
2306         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2307
2308         SysTryReturnResult(NID_GRP, vcWidthF > 0.0f, E_OUT_OF_RANGE, "The given line width(%f) is out of range.", vcWidthF);
2309
2310         result r = E_SUCCESS;
2311
2312         if (_ResUtil::NeedToConvertCoord())
2313         {
2314                 float pcWidthF = _ResUtil::ConvertToPhyCoordSize(vcWidthF);
2315
2316                 r = this->_pNativeCanvas->SetLineWidth(pcWidthF);
2317         }
2318         else
2319         {
2320                 r = this->_pNativeCanvas->SetLineWidth(vcWidthF);
2321         }
2322
2323         if (IsSucceeded(r))
2324         {
2325                 this->_pCoordHolder->AssignLineWidthFromVc(vcWidthF);
2326         }
2327
2328         return r;
2329 }
2330
2331 result
2332 _CanvasImpl::SetLineCapStyle(LineCapStyle lineCapStyle)
2333 {
2334         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2335
2336         switch (lineCapStyle)
2337         {
2338         case LINE_CAP_STYLE_ROUND:
2339         case LINE_CAP_STYLE_BUTT:
2340         case LINE_CAP_STYLE_SQUARE:
2341                 break;
2342         default:
2343                 SysTryReturnResult(NID_GRP, false, E_INVALID_ARG, "The given line cap style is out of range.");
2344         }
2345
2346         return this->_pNativeCanvas->SetLineCapStyle(lineCapStyle);
2347 }
2348
2349 result
2350 _CanvasImpl::SetLineJoinStyle(LineJoinStyle lineJoinStyle)
2351 {
2352         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2353
2354         switch (lineJoinStyle)
2355         {
2356         case LINE_JOIN_STYLE_ROUND:
2357         case LINE_JOIN_STYLE_MITER:
2358         case LINE_JOIN_STYLE_BEVEL:
2359                 break;
2360         default:
2361                 SysTryReturnResult(NID_GRP, false, E_INVALID_ARG, "The given line join style is out of range.");
2362         }
2363
2364         return this->_pNativeCanvas->SetLineJoinStyle(lineJoinStyle);
2365 }
2366
2367 result
2368 _CanvasImpl::GetDashPattern(Tizen::Base::Collection::IListT<int>& pattern, int& offset)
2369 {
2370         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2371
2372         pattern.RemoveAll();
2373
2374         result r = E_SUCCESS;
2375
2376         float floatValue = 0.0f;
2377
2378         for (int i = 0; i < this->_dashList.GetCount(); i++)
2379         {
2380                 this->_dashList.GetAt(i, floatValue);
2381
2382                 r = pattern.Add(_FloatToIntForPos(floatValue));
2383
2384                 if (r != E_SUCCESS)
2385                 {
2386                         break;
2387                 }
2388         }
2389
2390         if (IsFailed(r))
2391         {
2392                 switch (r)
2393                 {
2394                 case E_INVALID_ARG:
2395                 case E_OPERATION_FAILED:
2396                 case E_OUT_OF_MEMORY:
2397                         SysTryReturn(NID_GRP, false, r, r, "[%s] Propagating.", GetErrorMessage(r));
2398                         break;
2399                 default:
2400                         SysTryReturn(NID_GRP, false, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Tizen::Base::Collection::ArrayListT<int>::AddItems() failed");
2401                         break;
2402                 }
2403         }
2404
2405         offset = int(this->_dashOffset);
2406
2407         return r;
2408 }
2409
2410 result
2411 _CanvasImpl::GetDashPattern(Tizen::Base::Collection::IListT<float>& pattern, float& offset)
2412 {
2413         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2414
2415         pattern.RemoveAll();
2416
2417         result r = pattern.AddItems(this->_dashList);
2418
2419         if (IsFailed(r))
2420         {
2421                 switch (r)
2422                 {
2423                 case E_INVALID_ARG:
2424                 case E_OPERATION_FAILED:
2425                 case E_OUT_OF_MEMORY:
2426                         SysTryReturn(NID_GRP, false, r, r, "[%s] Propagating.", GetErrorMessage(r));
2427                         break;
2428                 default:
2429                         SysTryReturn(NID_GRP, false, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Tizen::Base::Collection::ArrayListT<int>::AddItems() failed");
2430                         break;
2431                 }
2432         }
2433
2434         offset = static_cast<float>(this->_dashOffset);
2435
2436         return r;
2437 }
2438
2439 result
2440 _CanvasImpl::SetDashPattern(const Tizen::Base::Collection::IListT<int>& pattern, int offset)
2441 {
2442         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2443
2444         int dashValue = 0;
2445
2446         for (int i = 0; i < pattern.GetCount(); i++)
2447         {
2448                 pattern.GetAt(i, dashValue);
2449                 SysTryReturn(NID_GRP, dashValue >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] One of the values of the specified pattern is negative(%d).", dashValue);
2450         }
2451
2452         result r = E_SUCCESS;
2453
2454         // It is NOT the strong guarantee for an exception
2455         this->_dashList.RemoveAll();
2456
2457         int intValue = 0;
2458
2459         for (int i = 0; i < pattern.GetCount(); i++)
2460         {
2461                 pattern.GetAt(i, intValue);
2462                 r = this->_dashList.Add(float(intValue));
2463                 if (r != E_SUCCESS)
2464                 {
2465                         break;
2466                 }
2467         }
2468
2469         if (IsFailed(r))
2470         {
2471                 switch (r)
2472                 {
2473                 case E_INVALID_ARG:
2474                 case E_OPERATION_FAILED:
2475                 case E_OUT_OF_MEMORY:
2476                         SysTryReturn(NID_GRP, false, r, r, "[%s] Propagating.", GetErrorMessage(r));
2477                         break;
2478                 default:
2479                         SysTryReturn(NID_GRP, false, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Tizen::Base::Collection::ArrayListT<int>::AddItems() failed");
2480                         break;
2481                 }
2482         }
2483
2484         {
2485                 int dashIntValue = 0;
2486                 Tizen::Graphics::_Util::AccumList<double> dashValueList;
2487
2488                 for (int i = 0; i < pattern.GetCount(); i++)
2489                 {
2490                         pattern.GetAt(i, dashIntValue);
2491                         dashValueList.Push(double(dashIntValue));
2492                 }
2493
2494                 r = this->_pNativeCanvas->SetDashPattern(dashValueList, double(offset));
2495                 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2496
2497                 this->_dashOffset = offset;
2498         }
2499
2500         return r;
2501 }
2502
2503 result
2504 _CanvasImpl::SetDashPattern(const Tizen::Base::Collection::IListT<float>& pattern, float offset)
2505 {
2506         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2507
2508         float dashValue = 0.0f;
2509
2510         for (int i = 0; i < pattern.GetCount(); i++)
2511         {
2512                 pattern.GetAt(i, dashValue);
2513                 SysTryReturn(NID_GRP, dashValue >= 0.0f, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] One of the values of the specified pattern is negative(%f).", dashValue);
2514         }
2515
2516         result r = E_SUCCESS;
2517
2518         // It is NOT the strong guarantee for an exception
2519         this->_dashList.RemoveAll();
2520
2521         r = this->_dashList.AddItems(pattern);
2522
2523         if (IsFailed(r))
2524         {
2525                 switch (r)
2526                 {
2527                 case E_INVALID_ARG:
2528                 case E_OPERATION_FAILED:
2529                 case E_OUT_OF_MEMORY:
2530                         SysTryReturn(NID_GRP, false, r, r, "[%s] Propagating.", GetErrorMessage(r));
2531                         break;
2532                 default:
2533                         SysTryReturn(NID_GRP, false, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Tizen::Base::Collection::ArrayListT<int>::AddItems() failed");
2534                         break;
2535                 }
2536         }
2537
2538         {
2539                 float dashFloatValue = 0.0f;
2540                 Tizen::Graphics::_Util::AccumList<double> dashValueList;
2541
2542                 for (int i = 0; i < pattern.GetCount(); i++)
2543                 {
2544                         pattern.GetAt(i, dashFloatValue);
2545                         dashValueList.Push(double(dashFloatValue));
2546                 }
2547
2548                 r = this->_pNativeCanvas->SetDashPattern(dashValueList, double(offset));
2549                 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2550
2551                 this->_dashOffset = _FloatToIntForPos(offset);
2552         }
2553
2554         return r;
2555 }
2556
2557 result
2558 _CanvasImpl::SetDrawingQuality(BitmapDrawingQuality quality)
2559 {
2560         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2561
2562         switch (quality)
2563         {
2564         case BITMAP_DRAWING_QUALITY_LOW:
2565         case BITMAP_DRAWING_QUALITY_MID:
2566         case BITMAP_DRAWING_QUALITY_HIGH:
2567                 break;
2568         default:
2569                 SysLogException(NID_GRP, E_INVALID_ARG, "The specified drawing quality(%d) is invalid.", quality);
2570                 return E_INVALID_ARG;
2571         }
2572
2573         this->_pNativeCanvas->SetDrawingQuality(quality);
2574
2575         return E_SUCCESS;
2576 }
2577
2578 BitmapDrawingQuality
2579 _CanvasImpl::GetDrawingQuality(void) const
2580 {
2581         return (INSTANCE_IS_VALID) ? this->_pNativeCanvas->GetDrawingQuality() : BITMAP_DRAWING_QUALITY_LOW;
2582 }
2583
2584 result
2585 _CanvasImpl::SetCompositeMode(CompositeMode compositeMode)
2586 {
2587         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2588
2589         switch (compositeMode)
2590         {
2591         case COMPOSITE_MODE_CLEAR:
2592         case COMPOSITE_MODE_SRC:
2593         case COMPOSITE_MODE_DST:
2594         case COMPOSITE_MODE_SRC_OVER:
2595         case COMPOSITE_MODE_DST_OVER:
2596         case COMPOSITE_MODE_SRC_IN:
2597         case COMPOSITE_MODE_DST_IN:
2598         case COMPOSITE_MODE_SRC_OUT:
2599         case COMPOSITE_MODE_DST_OUT:
2600         case COMPOSITE_MODE_SRC_ATOP:
2601         case COMPOSITE_MODE_DST_ATOP:
2602         case COMPOSITE_MODE_DST_XOR:
2603         case COMPOSITE_MODE_ADD:
2604         case COMPOSITE_MODE_SATURATE:
2605         case COMPOSITE_MODE_MULTIPLY:
2606         case COMPOSITE_MODE_SCREEN:
2607         case COMPOSITE_MODE_OVERLAY:
2608         case COMPOSITE_MODE_DARKEN:
2609         case COMPOSITE_MODE_LIGHTEN:
2610                 break;
2611         default:
2612                 SysLogException(NID_GRP, E_INVALID_ARG, "The specified composite mode(%d) is invalid.", compositeMode);
2613                 return E_INVALID_ARG;
2614         }
2615
2616         this->_pNativeCanvas->SetCompositeMode(compositeMode);
2617
2618         return E_SUCCESS;
2619 }
2620
2621 CompositeMode
2622 _CanvasImpl::GetCompositeMode(void) const
2623 {
2624         return (INSTANCE_IS_VALID) ? this->_pNativeCanvas->GetCompositeMode() : COMPOSITE_MODE_SRC_OVER;
2625 }
2626
2627 result
2628 _CanvasImpl::GetPixel(const Point& vcPoint, Color& color) const
2629 {
2630         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2631
2632         Rectangle rtCanvas = _GetBoundsRel(*this);
2633
2634         SysTryReturnResult(NID_GRP, !rtCanvas.IsEmpty(), E_OUT_OF_RANGE, "Cannot get the bounds of the canvas.");
2635
2636         result r = _Util::Validate(vcPoint, rtCanvas);
2637
2638         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
2639
2640         if (_ResUtil::NeedToConvertCoord())
2641         {
2642                 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
2643
2644                 return this->_pNativeCanvas->GetPixel(pcPoint, color);
2645         }
2646         else
2647         {
2648                 return this->_pNativeCanvas->GetPixel(vcPoint, color);
2649         }
2650 }
2651
2652 result
2653 _CanvasImpl::GetPixel(const FloatPoint& vcPointF, Color& color) const
2654 {
2655         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2656
2657         FloatRectangle rtCanvasF = _GetBoundsRelF(*this);
2658
2659         SysTryReturnResult(NID_GRP, !rtCanvasF.IsEmpty(), E_OUT_OF_RANGE, "Cannot get the bounds of the canvas.");
2660
2661         result r = _Util::Validate(vcPointF, rtCanvasF);
2662
2663         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
2664
2665         if (_ResUtil::NeedToConvertCoord())
2666         {
2667                 FloatPoint pcPointF = _ResUtil::ConvertToPhyCoord(vcPointF);
2668
2669                 Point pcPoint(_FloatToIntForPos(pcPointF.x), _FloatToIntForPos(pcPointF.y));
2670
2671                 return this->_pNativeCanvas->GetPixel(pcPoint, color);
2672         }
2673         else
2674         {
2675                 Point vcPoint(_FloatToIntForPos(vcPointF.x), _FloatToIntForPos(vcPointF.y));
2676
2677                 return this->_pNativeCanvas->GetPixel(vcPoint, color);
2678         }
2679 }
2680
2681 result
2682 _CanvasImpl::SetPixel(const FloatPoint& vcPoint)
2683 {
2684         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2685
2686         return _CanvasImplPrivate::SetPixel(this, _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint));
2687 }
2688
2689 result
2690 _CanvasImpl::SetPixel(const Point& vcPoint)
2691 {
2692         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2693
2694         return _CanvasImplPrivate::SetPixel(this, _Util::Convert<Point, _Util::Point<int> >(vcPoint));
2695 }
2696
2697 result
2698 _CanvasImpl::Show()
2699 {
2700         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2701
2702         if (this->_pShowCallbackFunc)
2703         {
2704                 if (this->_pShowCallbackFunc(this->_pShowCallbackParam))
2705                 {
2706                         return E_SUCCESS;
2707                 }
2708         }
2709
2710         result r = E_SUCCESS;
2711         Rectangle rect = this->GetBounds();
2712
2713         r = this->_pNativeCanvas->Show();
2714
2715         return r;
2716 }
2717
2718 result
2719 _CanvasImpl::Show(const Rectangle& vcRect)
2720 {
2721         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2722
2723         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
2724         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE,
2725                                           "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width,
2726                                           vcRect.height);
2727
2728         if (this->_pShowCallbackFunc)
2729         {
2730                 if (this->_pShowCallbackFunc(this->_pShowCallbackParam))
2731                 {
2732                         return E_SUCCESS;
2733                 }
2734         }
2735
2736         result r = E_SUCCESS;
2737         Rectangle rect = this->GetBounds();
2738
2739         if (_ResUtil::NeedToConvertCoord())
2740         {
2741                 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
2742
2743                 r = this->_pNativeCanvas->Show(pcRect);
2744         }
2745         else
2746         {
2747                 r = this->_pNativeCanvas->Show(vcRect);
2748         }
2749
2750         return r;
2751 }
2752
2753 result
2754 _CanvasImpl::SetFont(const Font& font)
2755 {
2756         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2757         SysTryReturnResult(NID_GRP, _FontImpl::GetInstance(font) && _FontImpl::GetInstance(font)->IsConstructed(), E_INVALID_ARG, "The given font is not constructed.");
2758         SysTryReturnResult(NID_GRP, font.GetMaxHeight() > 0 && font.GetMaxWidth() > 0, E_INVALID_ARG, "The infomation of the given font is not valid. (maxWidth=%d,maxHeight=%d).", font.GetMaxWidth(), font.GetMaxHeight());
2759
2760         // should keep clone font
2761         Font* pFont = _FontImpl::CloneN(font);
2762
2763         if (pFont == null)
2764         {
2765                 SysTryLog(NID_GRP, pFont, "[] Fails to allocate memory for font resource.");
2766
2767                 this->_pFont = null;
2768
2769                 // shkim, TODO.
2770                 // we failed to make cloned font. so, return what? E_SYSTEM which is not defined in header?? or use E_OPERATION_FAILED again for different meaning?
2771                 // or just setting defult font?!
2772                 return E_OPERATION_FAILED;
2773         }
2774
2775         EXTRACT_FONTEX(pFontEx, *pFont);
2776         result r = this->_pNativeCanvas->SetFont(*pFontEx);
2777         SysTryCatch(NID_GRP, E_SUCCESS == r, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Fails to set font.");
2778
2779         // succeed making cloned font, then keep it and replace old one.
2780         if (this->_pFont)
2781         {
2782                 delete this->_pFont;
2783                 this->_pFont = null;
2784         }
2785
2786         this->_pFont = pFont;
2787
2788         return r;
2789
2790 CATCH:
2791         delete pFont;
2792         pFont = null;
2793
2794         return r;
2795 }
2796
2797 Font*
2798 _CanvasImpl::GetFontN(void)
2799 {
2800         result r = E_SUCCESS;
2801         Font* pFont = null;
2802
2803         // clear last error
2804         ClearLastResult();
2805
2806         SysTryCatch(NID_GRP, INSTANCE_IS_VALID, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2807
2808         // we have the font user set
2809         if (this->_pFont)
2810         {
2811                 pFont = _FontImpl::CloneN(*(this->_pFont));
2812                 SysTryCatch(NID_GRP, pFont, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create Font instance.");
2813         }
2814         else
2815         {
2816                 pFont = new Font();
2817                 SysTryCatch(NID_GRP, pFont, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2818
2819                 const float defaultFontSize = _ResUtil::ConvertToVirCoordY(16.0f);
2820                 result r = pFont->Construct(FONT_STYLE_PLAIN, defaultFontSize);
2821                 SysTryCatch(NID_GRP, IsSucceeded(r), , r, "[%s] Propagating.", GetErrorMessage(r));
2822         }
2823
2824         SetLastResult(r);
2825         return pFont;
2826
2827 CATCH:
2828         if (pFont)
2829         {
2830                 delete pFont;
2831         }
2832
2833         SetLastResult(r);
2834
2835         return null;
2836 }
2837
2838 void
2839 _CanvasImpl::SetTextOrigin(TextOrigin origin)
2840 {
2841         if (INSTANCE_IS_VALID)
2842         {
2843                 switch (origin)
2844                 {
2845                 case TEXT_ORIGIN_LEFT_TOP:
2846                 case TEXT_ORIGIN_BASELINE:
2847                         this->_pNativeCanvas->__textOrigin = origin;
2848                         break;
2849                 }
2850         }
2851 }
2852
2853 result
2854 _CanvasImpl::SetClipBounds(const Rectangle& vcRect)
2855 {
2856         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2857
2858         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
2859         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
2860
2861         Rectangle rtCanvas = _GetBoundsRel(*this);
2862
2863         result r = _Util::Validate(vcRect, rtCanvas);
2864
2865         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
2866
2867         Rectangle revisedVcRect;
2868
2869         {
2870                 int x1 = vcRect.x;
2871                 int y1 = vcRect.y;
2872                 int x2 = vcRect.x + vcRect.width;
2873                 int y2 = vcRect.y + vcRect.height;
2874
2875                 x1 = (x1 > 0) ? x1 : 0;
2876                 y1 = (y1 > 0) ? y1 : 0;
2877                 x2 = (x2 < rtCanvas.width) ? x2 : rtCanvas.width;
2878                 y2 = (y2 < rtCanvas.height) ? y2 : rtCanvas.height;
2879
2880                 revisedVcRect.x = x1;
2881                 revisedVcRect.y = y1;
2882                 revisedVcRect.width = x2 - x1;
2883                 revisedVcRect.height = y2 - y1;
2884         }
2885
2886         if (_ResUtil::NeedToConvertCoord())
2887         {
2888                 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(revisedVcRect);
2889
2890                 // special case
2891                 pcRect.width = (pcRect.width >= 0) ? pcRect.width : 1;
2892                 pcRect.height = (pcRect.height >= 0) ? pcRect.height : 1;
2893
2894                 result r = this->_pNativeCanvas->SetClipBounds(pcRect);
2895
2896                 if (IsSucceeded(r))
2897                 {
2898                         _Util::Rectangle<int> vcRect =
2899                         {
2900                                 revisedVcRect.x,
2901                                 revisedVcRect.y,
2902                                 revisedVcRect.width,
2903                                 revisedVcRect.height
2904                         };
2905
2906                         this->_pCoordHolder->AssignClipBoundsFromVcSize(vcRect);
2907                 }
2908
2909                 return r;
2910         }
2911         else
2912         {
2913                 result r = this->_pNativeCanvas->SetClipBounds(revisedVcRect);
2914
2915                 if (IsSucceeded(r))
2916                 {
2917                         _Util::Rectangle<int> vcRect =
2918                         {
2919                                 revisedVcRect.x,
2920                                 revisedVcRect.y,
2921                                 revisedVcRect.width,
2922                                 revisedVcRect.height
2923                         };
2924
2925                         this->_pCoordHolder->AssignClipBoundsFromVcSize(vcRect);
2926                 }
2927
2928                 return r;
2929         }
2930 }
2931
2932 result
2933 _CanvasImpl::SetClipBounds(const FloatRectangle& vcRectF)
2934 {
2935         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2936
2937         SysTryReturnResult(NID_GRP, &vcRectF, E_OUT_OF_RANGE, "The given rectangle is invalid.");
2938         SysTryReturnResult(NID_GRP, (vcRectF.width >= 0.0f) && (vcRectF.height >= 0.0f), E_OUT_OF_RANGE, "The given rectangle(width:%f,height:%f) is out of range.", vcRectF.width, vcRectF.height);
2939
2940         FloatRectangle rtCanvasF = _GetBoundsRelF(*this);
2941
2942         result r = _Util::Validate(vcRectF, rtCanvasF);
2943
2944         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
2945
2946         FloatRectangle revisedVcRectF;
2947
2948         {
2949                 float x1 = vcRectF.x;
2950                 float y1 = vcRectF.y;
2951                 float x2 = vcRectF.x + vcRectF.width;
2952                 float y2 = vcRectF.y + vcRectF.height;
2953
2954                 x1 = (x1 > 0) ? x1 : 0;
2955                 y1 = (y1 > 0) ? y1 : 0;
2956                 x2 = (x2 < rtCanvasF.width) ? x2 : rtCanvasF.width;
2957                 y2 = (y2 < rtCanvasF.height) ? y2 : rtCanvasF.height;
2958
2959                 revisedVcRectF.x = x1;
2960                 revisedVcRectF.y = y1;
2961                 revisedVcRectF.width = x2 - x1;
2962                 revisedVcRectF.height = y2 - y1;
2963         }
2964
2965         _CanvasCoordHolder coordHolder;
2966
2967         {
2968                 _Util::Rectangle<float> tempRevisedVcRectF =
2969                 {
2970                         revisedVcRectF.x,
2971                         revisedVcRectF.y,
2972                         revisedVcRectF.width,
2973                         revisedVcRectF.height
2974                 };
2975
2976                 coordHolder.AssignClipBoundsFromVcSize(tempRevisedVcRectF);
2977         }
2978
2979         Rectangle pcRect
2980         (
2981                 coordHolder.clipBounds.pcInt.x,
2982                 coordHolder.clipBounds.pcInt.y,
2983                 coordHolder.clipBounds.pcInt.w,
2984                 coordHolder.clipBounds.pcInt.h
2985         );
2986
2987         r = this->_pNativeCanvas->SetClipBounds(pcRect);
2988
2989         if (IsSucceeded(r))
2990         {
2991                 this->_pCoordHolder->clipBounds = coordHolder.clipBounds;
2992         }
2993
2994         return r;
2995 }
2996
2997 Rectangle
2998 _CanvasImpl::GetClipBounds(void) const
2999 {
3000         Rectangle rect;
3001
3002         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, rect, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
3003
3004         if (_ResUtil::NeedToConvertCoord())
3005         {
3006                 const _Util::Rectangle<int>& bounds = this->_pCoordHolder->clipBounds.vcInt;
3007
3008                 return Rectangle(bounds.x, bounds.y, bounds.w, bounds.h);
3009         }
3010         else
3011         {
3012                 return this->_pNativeCanvas->GetClipBounds();
3013         }
3014 }
3015
3016 FloatRectangle
3017 _CanvasImpl::GetClipBoundsF(void) const
3018 {
3019         FloatRectangle rectF;
3020
3021         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, rectF, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
3022
3023         const _Util::Rectangle<float>& boundsF = this->_pCoordHolder->clipBounds.vcFloat;
3024
3025         return FloatRectangle(boundsF.x, boundsF.y, boundsF.w, boundsF.h);
3026 }
3027
3028 result
3029 _CanvasImpl::Lock(BufferInfo& info, long timeout)
3030 {
3031         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
3032
3033         SysTryReturnResult(NID_GRP, (static_cast <unsigned long>(timeout) == INFINITE) || (timeout >= 0), E_INVALID_ARG,
3034                                           "'timeout(=%d)' is not valid.",
3035                                           timeout);
3036
3037         return this->_pNativeCanvas->Lock(info, timeout);
3038 }
3039
3040 result
3041 _CanvasImpl::Unlock()
3042 {
3043         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
3044
3045         return this->_pNativeCanvas->Unlock();
3046 }
3047
3048 void
3049 _CanvasImpl::SetForegroundColor(const Color& fgColor)
3050 {
3051         SysTryReturnVoidResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
3052
3053         return this->_pNativeCanvas->SetForegroundColor(fgColor);
3054 }
3055
3056 Color
3057 _CanvasImpl::GetForegroundColor(void) const
3058 {
3059         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, Color::GetColor(COLOR_ID_BLACK), E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
3060
3061         return this->_pNativeCanvas->GetForegroundColor();
3062 }
3063
3064 void
3065 _CanvasImpl::SetBackgroundColor(const Color& bgColor)
3066 {
3067         SysTryReturnVoidResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
3068
3069         return this->_pNativeCanvas->SetBackgroundColor(bgColor);
3070 }
3071
3072 Color
3073 _CanvasImpl::GetBackgroundColor(void) const
3074 {
3075         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, Color::GetColor(COLOR_ID_BLACK), E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
3076
3077         return this->_pNativeCanvas->GetBackgroundColor();
3078 }
3079
3080 result
3081 _CanvasImpl::SetPosition(const Point& vcPoint)
3082 {
3083         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
3084
3085         return this->SetPosition(vcPoint.x, vcPoint.y);
3086 }
3087
3088 result
3089 _CanvasImpl::SetPosition(int vcX, int vcY)
3090 {
3091         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
3092
3093         _CanvasCoordHolder tempCoordHolder;
3094         tempCoordHolder.AssignCanvasPosFromVc(vcX, vcY);
3095
3096         result r = E_SUCCESS;
3097
3098         if (_ResUtil::NeedToConvertCoord())
3099         {
3100                 Point pcPoint(tempCoordHolder.canvasPos.pcInt.x, tempCoordHolder.canvasPos.pcInt.y);
3101
3102                 r = this->_pNativeCanvas->SetPosition(pcPoint.x, pcPoint.y);
3103         }
3104         else
3105         {
3106                 r = this->_pNativeCanvas->SetPosition(vcX, vcY);
3107         }
3108
3109         if (IsSucceeded(r))
3110         {
3111                 this->_pCoordHolder->canvasPos = tempCoordHolder.canvasPos;
3112         }
3113
3114         return r;
3115
3116 }
3117
3118 Canvas*
3119 _CanvasImpl::GetSubCanvasN(const Rectangle& subRegion) const
3120 {
3121         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, null, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
3122
3123         _Canvas* pSourceNativeCanvas = this->_pNativeCanvas;
3124
3125         std::auto_ptr <Canvas> subCanvas(new (std::nothrow) Canvas);
3126
3127         Canvas* pSubCanvas = subCanvas.get();
3128
3129         SysTryReturn(NID_GRP, pSubCanvas, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3130
3131         _CanvasImpl* pSubCanvasImpl = _CanvasImpl::GetInstance(*pSubCanvas);
3132
3133         SysTryReturn(NID_GRP, pSubCanvasImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3134
3135         if (_ResUtil::NeedToConvertCoord())
3136         {
3137                 Rectangle subRegionPC = _ResUtil::ConvertToPhyCoord(subRegion);
3138
3139                 subRegionPC.width = (subRegionPC.width > 0) ? subRegionPC.width : 1;
3140                 subRegionPC.height = (subRegionPC.height > 0) ? subRegionPC.height : 1;
3141
3142                 result r = pSubCanvasImpl->_pNativeCanvas->Construct(pSourceNativeCanvas, subRegionPC);
3143
3144                 SysTryReturn(NID_GRP, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3145
3146                 pSubCanvasImpl->_pCoordHolder->Init(subRegion);
3147                 pSubCanvasImpl->_pCoordHolder->canvasSize.pcInt.w = subRegionPC.width;
3148                 pSubCanvasImpl->_pCoordHolder->canvasSize.pcInt.h = subRegionPC.height;
3149         }
3150         else
3151         {
3152                 result r = pSubCanvasImpl->_pNativeCanvas->Construct(pSourceNativeCanvas, subRegion);
3153
3154                 SysTryReturn(NID_GRP, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3155         }
3156
3157         if (this->_pFont)
3158         {
3159                 pSubCanvasImpl->SetFont(*this->_pFont);
3160         }
3161
3162         if (this->_pPriorityFont)
3163         {
3164                 pSubCanvasImpl->SetPriorityFont(*this->_pPriorityFont);
3165         }
3166
3167         return subCanvas.release();
3168 }
3169
3170 Canvas*
3171 _CanvasImpl::GetSubCanvasFN(const FloatRectangle& subRegion) const
3172 {
3173         // @hoonik.lee
3174         Rectangle intSubRegion(static_cast<int>(subRegion.x), static_cast<int>(subRegion.y), static_cast<int>(subRegion.width), static_cast<int>(subRegion.height));
3175
3176         return this->GetSubCanvasN(intSubRegion);
3177 }
3178
3179 void
3180 _CanvasImpl::SetAntialiasingEnabled(bool enable)
3181 {
3182         SysTryReturnVoidResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "[E_OUT_OF_MEMORY] This instance is not constructed yet.");
3183
3184         return this->_pNativeCanvas->SetAntialiasingEnabled(enable);
3185 }
3186
3187 bool
3188 _CanvasImpl::IsAntialiasingEnabled(void) const
3189 {
3190         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, false, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
3191
3192         return this->_pNativeCanvas->IsAntialiasingEnabled();
3193 }
3194
3195 result
3196 _CanvasImpl::SetPriorityFont(const Font& font)
3197 {
3198         ClearLastResult();
3199
3200         // check input param
3201         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
3202         SysTryReturn(NID_GRP, font.GetMaxHeight() > 0 && font.GetMaxWidth() > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The infomation of the given font is not valid. (maxWidth=%d, maxHeight=%d).", font.GetMaxWidth(), font.GetMaxHeight());
3203
3204         Font* pFont = &(const_cast <Font&>(font));
3205
3206         EXTRACT_FONTEX(pFontEx, *pFont);
3207         result r = this->_pNativeCanvas->SetPriorityFont(*pFontEx);
3208         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3209         // overwrite existing priority font
3210         this->_pPriorityFont = pFont;
3211
3212         return E_SUCCESS;
3213 }
3214
3215 void
3216 _CanvasImpl::ResetPriorityFont(void)
3217 {
3218         if (INSTANCE_IS_VALID)
3219         {
3220                 this->_pPriorityFont = null;
3221                 this->_pNativeCanvas->ResetPriorityFont();
3222         }
3223 }
3224
3225 void
3226 _CanvasImpl::SetStableRenderer(bool isStable)
3227 {
3228         if (INSTANCE_IS_VALID)
3229         {
3230                 this->_pNativeCanvas->__useStableRenderer = isStable;
3231         }
3232 }
3233
3234 void
3235 _CanvasImpl::SetFrameInfoCallback(void* (*pGetDefaultFrameNativeHandle)(void), void* (*pGetDefaultFrameHandle)(void))
3236 {
3237         _GetDefaultFrameEcoreEvasHandle = (pGetDefaultFrameNativeHandle) ? pGetDefaultFrameNativeHandle : _GetNull;
3238         _GetDefaultFrameEvasHandle = (pGetDefaultFrameHandle) ? pGetDefaultFrameHandle : _GetNull;
3239 }
3240
3241 void
3242 _CanvasImpl::SetThemeInfoCallback(Color (*pGetDefaultForegroundColor)(void), Color (*pGetDefaultBackgroundColor)(void))
3243 {
3244         _GetDefaultForegroundColor = (pGetDefaultForegroundColor) ? pGetDefaultForegroundColor : _GetBlack;
3245         _GetDefaultBackgroundColor = (pGetDefaultBackgroundColor) ? pGetDefaultBackgroundColor : _GetWhite;
3246 }
3247
3248 _CanvasImpl*
3249 _CanvasImpl::GetInstance(Canvas& canvas)
3250 {
3251         return (&canvas != null) ? canvas.__pImpl : null;
3252 }
3253
3254 const _CanvasImpl*
3255 _CanvasImpl::GetInstance(const Canvas& canvas)
3256 {
3257         return (&canvas != null) ? canvas.__pImpl : null;
3258 }
3259
3260 }} // Tizen::Graphics