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