2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FGrp_CanvasImpl.cpp
20 * @brief This is the implementation file for _CanvasImpl class.
27 #include <unique_ptr.h>
29 #include <FBaseSysLog.h>
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"
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Collection;
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)
53 #define IsSucceeded(X) (!IsFailed(X))
55 #define INSTANCE_IS_VALID (this && (this->_pNativeCanvas && this->_pNativeCanvas->IsValid()))
56 #define CANVAS_IS_VALID(canvas) (&canvas && (canvas._pNativeCanvas && canvas._pNativeCanvas->IsValid()))
58 #define BITMAP_IS_VALID(bitmap) (&bitmap && const_cast<_BitmapImpl*>(&bitmap)->__CheckValidity())
64 // retrieving bounds rectangle which has (0,0,w,h).
65 Tizen::Graphics::Rectangle
66 _GetBoundsRel(const Tizen::Graphics::_CanvasImpl& canvas)
68 Tizen::Graphics::Rectangle rect = canvas.GetBounds();
77 _ExpandClippingAreaForLineWidth(Tizen::Graphics::Rectangle& rtCanvas, T lineWidth)
79 int lineWidthHalf = (lineWidth + 1) / 2;
81 rtCanvas.x -= lineWidthHalf;
82 rtCanvas.y -= lineWidthHalf;
83 rtCanvas.width += lineWidthHalf * 2;
84 rtCanvas.height += lineWidthHalf * 2;
89 namespace Tizen { namespace Graphics { namespace _Util
93 inline Tizen::Graphics::Point Convert<Tizen::Graphics::FloatPoint, Tizen::Graphics::Point>(const Tizen::Graphics::FloatPoint& point)
95 return Tizen::Graphics::Point(int(point.x), int(point.y));
99 inline Tizen::Graphics::Rectangle Convert<Tizen::Graphics::FloatRectangle, Tizen::Graphics::Rectangle>(const Tizen::Graphics::FloatRectangle& rect)
101 return Tizen::Graphics::Rectangle(int(rect.x), int(rect.y), int(rect.width), int(rect.height));
105 _Util::Point<double>* Convert<Tizen::Base::Collection::IList, _Util::Point<double>*>(const Tizen::Base::Collection::IList& points)
107 int count = points.GetCount();
109 std::unique_ptr<_Util::Point<double>[]> pPointArray(new (std::nothrow) _Util::Point<double>[count]);
111 SysTryReturn(NID_GRP, pPointArray, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
114 for (int i = 0; i < count; i++)
116 const Tizen::Graphics::Point* pPoint = dynamic_cast <const Tizen::Graphics::Point*>(points.GetAt(i));
120 pPointArray[i].x = double(pPoint->x);
121 pPointArray[i].y = double(pPoint->y);
125 const Tizen::Graphics::FloatPoint* pFloatPoint = dynamic_cast <const Tizen::Graphics::FloatPoint*>(points.GetAt(i));
129 pPointArray[i].x = double(pFloatPoint->x);
130 pPointArray[i].y = double(pFloatPoint->y);
140 return pPointArray.release();
143 } // Tizen::Graphics::_Util
145 }} // Tizen::Graphics
147 ////////////////////////////////////////////////////////////////////////////////
150 namespace Tizen { namespace Graphics
153 _CanvasImpl::_CanvasImpl(void)
160 _pNativeCanvas = new (std::nothrow) _Canvas;
161 _pCoordHolder = new (std::nothrow) _CanvasCoordHolder;
163 if (_pNativeCanvas == null || _pCoordHolder == null)
165 delete _pCoordHolder;
166 delete _pNativeCanvas;
168 _pCoordHolder = null;
169 _pNativeCanvas = null;
173 _CanvasImpl::~_CanvasImpl(void)
181 delete _pCoordHolder;
182 delete _pNativeCanvas;
186 _CanvasImpl::Construct(void)
188 SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
190 SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Fails to allocate memory.");
192 if (_ResUtil::NeedToConvertCoord())
194 result r = this->_pNativeCanvas->Construct();
198 Rectangle pcRect = this->_pNativeCanvas->GetBounds();
199 Rectangle vcRect = _ResUtil::ConvertToVirCoord(pcRect);
200 this->_pCoordHolder->Init(vcRect);
207 return this->_pNativeCanvas->Construct();
212 _CanvasImpl::Construct(const Rectangle& vcRect)
214 SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
216 SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Fails to allocate memory.");
218 SysTryReturnResult(NID_GRP, vcRect.width > 0 && vcRect.height > 0, E_OUT_OF_RANGE,
219 "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width,
222 if (_ResUtil::NeedToConvertCoord())
224 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
226 pcRect.width = (pcRect.width > 0) ? pcRect.width : 1;
227 pcRect.height = (pcRect.height > 0) ? pcRect.height : 1;
229 result r = this->_pNativeCanvas->Construct(pcRect);
233 this->_pCoordHolder->Init(vcRect);
234 this->_pCoordHolder->canvasSize.phyCoord.w = pcRect.width;
235 this->_pCoordHolder->canvasSize.phyCoord.h = pcRect.height;
242 return this->_pNativeCanvas->Construct(vcRect);
247 _CanvasImpl::Construct(Handle windowHandle, const Rectangle& vcRect)
249 SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
251 SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Fails to allocate memory.");
253 SysTryReturnResult(NID_GRP, vcRect.width > 0 && vcRect.height > 0, E_OUT_OF_RANGE,
254 "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width,
257 if (_ResUtil::NeedToConvertCoord())
259 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
261 pcRect.width = (pcRect.width > 0) ? pcRect.width : 1;
262 pcRect.height = (pcRect.height > 0) ? pcRect.height : 1;
264 result r = this->_pNativeCanvas->Construct(windowHandle, pcRect);
268 this->_pCoordHolder->Init(vcRect);
269 this->_pCoordHolder->canvasSize.phyCoord.w = pcRect.width;
270 this->_pCoordHolder->canvasSize.phyCoord.h = pcRect.height;
277 return this->_pNativeCanvas->Construct(windowHandle, vcRect);
282 _CanvasImpl::Construct(const BufferInfo& bufferInfo)
284 SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
286 SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Fails to allocate memory.");
288 SysTryReturnResult(NID_GRP, (bufferInfo.width > 0) && (bufferInfo.height > 0) && (bufferInfo.pitch > 0)
290 , "Invalid argument (BufferInfo::width = %d, BufferInfo::height = %d, BufferInfo::pitch = %d)"
291 , bufferInfo.width, bufferInfo.height, bufferInfo.pitch);
293 SysTryReturnResult(NID_GRP, bufferInfo.bitsPerPixel > 0
295 , "Invalid argument (BufferInfo::bitsPerPixel = %d)"
296 , bufferInfo.bitsPerPixel);
298 SysTryReturnResult(NID_GRP, (bufferInfo.pixelFormat > PIXEL_FORMAT_MIN) && (bufferInfo.pixelFormat < PIXEL_FORMAT_MAX)
300 , "Invalid argument (BufferInfo::pixelFormat = %d)"
301 , bufferInfo.pixelFormat);
303 SysTryReturnResult(NID_GRP, bufferInfo.bitsPerPixel == 32
304 , E_UNSUPPORTED_FORMAT
305 , "Unsupported format (BufferInfo::bitsPerPixel = %d)"
306 , bufferInfo.bitsPerPixel);
308 SysTryReturnResult(NID_GRP, bufferInfo.pixelFormat == PIXEL_FORMAT_ARGB8888
309 , E_UNSUPPORTED_FORMAT
310 , "Unsupported format (BufferInfo::pixelFormat = %d)"
311 , bufferInfo.pixelFormat);
313 if (bufferInfo.pPixels == null)
315 const _BufferInfoImpl* pBufferInfoImpl = _BufferInfoImpl::GetInstance(bufferInfo);
319 Handle handle = pBufferInfoImpl->GetHandle(_BufferInfoImpl::HANDLE_TYPE_VE_SURFACE);
321 if (handle != 0) // not INVALID_HANDLE
323 result r = this->Construct(handle, Rectangle(0, 0, bufferInfo.width, bufferInfo.height));
325 // OUT_OF_RANGE does not occur
327 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
333 SysTryReturnResult(NID_GRP, false
335 , "Invalid argument (BufferInfo::pPixels = null)");
339 result r = this->_pNativeCanvas->Construct(bufferInfo);
341 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
343 if (_ResUtil::NeedToConvertCoord())
345 Rectangle pcRect(0, 0, bufferInfo.width, bufferInfo.height);
346 Rectangle vcRect = _ResUtil::ConvertToVirCoord(pcRect);
348 vcRect.width = (vcRect.width > 0) ? vcRect.width : 1;
349 vcRect.height = (vcRect.height > 0) ? vcRect.height : 1;
351 this->_pCoordHolder->Init(vcRect);
352 this->_pCoordHolder->canvasSize.phyCoord.w = pcRect.width;
353 this->_pCoordHolder->canvasSize.phyCoord.h = pcRect.height;
363 _CanvasImpl::IsConstructed(void) const
365 return (this->_pNativeCanvas != null) && this->_pNativeCanvas->IsValid();
369 _CanvasImpl::Clear(void)
371 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
373 return this->_pNativeCanvas->Clear();
377 _CanvasImpl::Clear(const Rectangle& vcRect)
379 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
381 SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
382 SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE,
383 "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width,
386 if ((vcRect.width == 0) || (vcRect.height == 0))
391 Rectangle rtCanvas = _GetBoundsRel(*this);
393 if (rtCanvas.IsEmpty())
398 result r = _Util::Validate(vcRect, rtCanvas);
400 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
402 if (_ResUtil::NeedToConvertCoord())
404 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
406 return this->_pNativeCanvas->Clear(pcRect);
410 return this->_pNativeCanvas->Clear(vcRect);
415 _CanvasImpl::Copy(const Point& vcDestPoint, const _CanvasImpl& canvas, const Rectangle& vcSrcRect)
417 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
419 SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(canvas), E_INVALID_ARG, "The specified source canvas is invalid.");
421 Rectangle srcRectCanvas = _GetBoundsRel(canvas);
423 if (srcRectCanvas.IsEmpty())
428 result r = _Util::Validate(vcSrcRect, srcRectCanvas);
430 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
432 // check if destRect is in this canvas.
433 Rectangle destRect(vcDestPoint.x, vcDestPoint.y, vcSrcRect.width, vcSrcRect.height);
434 Rectangle destRectCanvas = _GetBoundsRel(*this);
436 if (destRectCanvas.IsEmpty())
441 r = _Util::Validate(destRect, destRectCanvas);
443 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
445 EXTRACT_CANVASEX(_pNativeCanvas, canvas);
448 if (_ResUtil::NeedToConvertCoord())
450 Point pcDestPoint = _ResUtil::ConvertToPhyCoord(vcDestPoint);
451 Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
453 return this->_pNativeCanvas->Copy(pcDestPoint, *_pNativeCanvas, pcSrcRect);
457 return this->_pNativeCanvas->Copy(vcDestPoint, *_pNativeCanvas, vcSrcRect);
462 _CanvasImpl::Copy(const Rectangle& vcDestRect, const _CanvasImpl& canvas, const Rectangle& vcSrcRect)
464 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
466 SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(canvas), E_INVALID_ARG, "The specified source canvas is invalid.");
468 // check if srcRect is in source canvas.
469 Rectangle srcRectCanvas = _GetBoundsRel(canvas);
471 if (srcRectCanvas.IsEmpty())
476 result r = _Util::Validate(vcSrcRect, srcRectCanvas);
478 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
480 // check if destRect is in this canvas.
481 Rectangle destRectCanvas = _GetBoundsRel(*this);
483 if (destRectCanvas.IsEmpty())
488 r = _Util::Validate(vcDestRect, destRectCanvas);
490 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
492 EXTRACT_CANVASEX(_pNativeCanvas, canvas);
494 if (_ResUtil::NeedToConvertCoord())
496 Rectangle pcDestRect = _ResUtil::ConvertToPhyCoord(vcDestRect);
497 Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
499 return this->_pNativeCanvas->Copy(pcDestRect, *_pNativeCanvas, pcSrcRect);
503 return this->_pNativeCanvas->Copy(vcDestRect, *_pNativeCanvas, vcSrcRect);
508 _CanvasImpl::Copy(const Point& vcDestPoint, const _CanvasImpl& canvas, const Rectangle& vcSrcRect, BlendingMode blendingMode)
510 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
512 SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(canvas), E_INVALID_ARG, "The specified source canvas is invalid.");
514 switch (blendingMode)
516 case BLENDING_MODE_CLEAR:
517 case BLENDING_MODE_SRC:
518 case BLENDING_MODE_DST:
519 case BLENDING_MODE_SRC_OVER:
520 case BLENDING_MODE_DST_OVER:
521 case BLENDING_MODE_SRC_IN:
522 case BLENDING_MODE_DST_IN:
523 case BLENDING_MODE_SRC_OUT:
524 case BLENDING_MODE_DST_OUT:
525 case BLENDING_MODE_SRC_ATOP:
526 case BLENDING_MODE_DST_ATOP:
527 case BLENDING_MODE_DST_XOR:
528 case BLENDING_MODE_ADD:
529 case BLENDING_MODE_SATURATE:
530 case BLENDING_MODE_MULTIPLY:
531 case BLENDING_MODE_SCREEN:
532 case BLENDING_MODE_OVERLAY:
533 case BLENDING_MODE_DARKEN:
534 case BLENDING_MODE_LIGHTEN:
535 case BLENDING_MODE_COLOR_DODGE:
536 case BLENDING_MODE_COLOR_BURN:
537 case BLENDING_MODE_HARD_LIGHT:
538 case BLENDING_MODE_SOFT_LIGHT:
539 case BLENDING_MODE_DIFFERENCE:
540 case BLENDING_MODE_EXCLUSION:
543 SysTryReturnResult(NID_GRP, false, E_INVALID_ARG, "The specified blending mode is invalid.");
546 Rectangle srcRectCanvas = _GetBoundsRel(canvas);
548 if (srcRectCanvas.IsEmpty())
553 result r = _Util::Validate(vcSrcRect, srcRectCanvas);
555 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
557 // check if destRect is in this canvas.
558 Rectangle destRect(vcDestPoint.x, vcDestPoint.y, vcSrcRect.width, vcSrcRect.height);
559 Rectangle destRectCanvas = _GetBoundsRel(*this);
561 if (destRectCanvas.IsEmpty())
566 r = _Util::Validate(destRect, destRectCanvas);
568 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
570 EXTRACT_CANVASEX(_pNativeCanvas, canvas);
573 if (_ResUtil::NeedToConvertCoord())
575 Point pcDestPoint = _ResUtil::ConvertToPhyCoord(vcDestPoint);
576 Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
578 return this->_pNativeCanvas->Copy(pcDestPoint, *_pNativeCanvas, pcSrcRect, blendingMode);
582 return this->_pNativeCanvas->Copy(vcDestPoint, *_pNativeCanvas, vcSrcRect, blendingMode);
587 _CanvasImpl::CopyEx(const Point& vcDestPoint, const _CanvasImpl& srcCanvas, const Rectangle& vcSrcRect)
589 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
591 if (this != &srcCanvas)
593 return this->Copy(vcDestPoint, srcCanvas, vcSrcRect);
596 // validity check as _CanvasImpl::Copy()
597 SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(srcCanvas), E_INVALID_ARG, "The specified source canvas is invalid.");
599 Rectangle srcRectCanvas = _GetBoundsRel(srcCanvas);
601 if (srcRectCanvas.IsEmpty())
606 result r = _Util::Validate(vcSrcRect, srcRectCanvas);
608 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
610 // check if destRect is in this canvas.
611 Rectangle destRect(vcDestPoint.x, vcDestPoint.y, vcSrcRect.width, vcSrcRect.height);
612 Rectangle destRectCanvas = _GetBoundsRel(*this);
614 if (destRectCanvas.IsEmpty())
619 r = _Util::Validate(destRect, destRectCanvas);
621 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
623 int pixelPerLine = 0;
626 BufferInfo bufferInfo;
628 result r = this->_pNativeCanvas->Lock(bufferInfo);
631 SysTryReturn(NID_GRP, r == E_SUCCESS, r, E_SYSTEM, "[] ");
633 this->_pNativeCanvas->Unlock();
635 pixelPerLine = bufferInfo.pitch / (bufferInfo.bitsPerPixel / 8);
638 //?? Auto-scaling should be applied to vc**** parameters later
639 int sourDistance = vcSrcRect.y * pixelPerLine + vcSrcRect.x;
640 int destDistance = vcDestPoint.y * pixelPerLine + vcDestPoint.x;
642 typedef result (_Canvas::* FnCopy)(const Point&, const _Canvas&, const Rectangle&);
643 FnCopy fnCopy = (destDistance < sourDistance) ? FnCopy(&_Canvas::Copy) : FnCopy(&_Canvas::CopyReverse);
647 EXTRACT_CANVASEX(_pNativeCanvas, srcCanvas);
649 if (_ResUtil::NeedToConvertCoord())
651 Point pcDestPoint = _ResUtil::ConvertToPhyCoord(vcDestPoint);
652 Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
654 return (this->_pNativeCanvas->*fnCopy)(pcDestPoint, *_pNativeCanvas, pcSrcRect);
658 return (this->_pNativeCanvas->*fnCopy)(vcDestPoint, *_pNativeCanvas, vcSrcRect);
667 _CanvasImpl::DrawArc(const FloatRectangle& vcBounds, float startAngle, float endAngle, ArcStyle arcStyle)
669 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
670 SysTryReturnResult(NID_GRP, ARC_STYLE_MIN < arcStyle && arcStyle < ARC_STYLE_MAX, E_INVALID_ARG, "The invalid arc type(%d) is given.", arcStyle);
671 SysTryReturnResult(NID_GRP, &vcBounds, E_INVALID_ARG, "The given rectangle is invalid.");
672 SysTryReturnResult(NID_GRP, (vcBounds.width >= 0) && (vcBounds.height >= 0), E_OUT_OF_RANGE,
673 "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
675 return _CanvasImplPrivate::DrawArc(this, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcBounds), double(startAngle), double(endAngle), arcStyle);
679 _CanvasImpl::DrawArc(const Rectangle& vcBounds, int startAngle, int endAngle, ArcStyle arcStyle)
681 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
682 SysTryReturnResult(NID_GRP, ARC_STYLE_MIN < arcStyle && arcStyle < ARC_STYLE_MAX, E_INVALID_ARG, "The invalid arc type(%d) is given.", arcStyle);
683 SysTryReturnResult(NID_GRP, &vcBounds, E_INVALID_ARG, "The given rectangle is invalid.");
684 SysTryReturnResult(NID_GRP, (vcBounds.width >= 0) && (vcBounds.height >= 0), E_OUT_OF_RANGE,
685 "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
687 return _CanvasImplPrivate::DrawArc(this, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcBounds), double(startAngle), double(endAngle), arcStyle);
691 _CanvasImpl::DrawBitmap(const Rectangle& vcRect, const _BitmapImpl& bitmap)
693 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
695 SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
696 SysTryReturnResult(NID_GRP, &vcRect, E_INVALID_ARG, "The source rectangle is invalid.");
698 if (vcRect.width == bitmap.GetWidth() && vcRect.height == bitmap.GetHeight())
700 return this->DrawBitmap(Point(vcRect.x, vcRect.y), bitmap);
703 // check if bimap can be drew in canvas area.
704 Rectangle rtCanvas = _GetBoundsRel(*this);
706 if (rtCanvas.IsEmpty())
711 result r = _Util::Validate(vcRect, rtCanvas);
713 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
715 EXTRACT_BITMAPEX(pBitmapEx, bitmap);
717 if (_ResUtil::NeedToConvertCoord())
719 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
721 return this->_pNativeCanvas->DrawBitmap(pcRect, *pBitmapEx);
725 return this->_pNativeCanvas->DrawBitmap(vcRect, *pBitmapEx);
730 _CanvasImpl::DrawBitmap(const FloatRectangle& vcRect, const _BitmapImpl& bitmap)
732 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
734 return this->DrawBitmap(_Util::Convert<FloatRectangle, Rectangle>(vcRect), bitmap);
738 _CanvasImpl::DrawBitmap(const Point& vcPoint, const _BitmapImpl& bitmap)
740 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
742 SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
744 Rectangle rtCanvas = _GetBoundsRel(*this);
746 if (rtCanvas.IsEmpty())
751 result r = _Util::Validate(Rectangle(vcPoint.x, vcPoint.y, bitmap.GetWidth(), bitmap.GetHeight()), rtCanvas);
753 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
755 EXTRACT_BITMAPEX(pBitmapEx, bitmap);
757 if (_ResUtil::NeedToConvertCoord())
759 Tizen::Graphics::Dimension virSize;
760 Tizen::Graphics::Dimension phySize;
761 bool lazyScaling = Tizen::Graphics::IsLazyScalingBitmap(bitmap, virSize, phySize);
763 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
765 Rectangle vcRect(vcPoint.x, vcPoint.y, bitmap.GetWidth(), bitmap.GetHeight());
767 #if 1 // Bitmap scaling is always uniform
770 EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
772 return this->_pNativeCanvas->DrawBitmap(pcPoint, *pScaledBitmapEx);
776 return this->_pNativeCanvas->DrawBitmap(pcPoint, *pBitmapEx);
779 int testSize = 2 * 3 * 5 * 7;
780 bool isUniform = _ResUtil::ConvertToPhyCoordWidth(testSize) == ConvertToPhyCoordHeight(testSize);
782 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
788 EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
792 return this->_pNativeCanvas->DrawBitmap(pcPoint, *pScaledBitmapEx);
796 return this->_pNativeCanvas->DrawBitmap(pcRect, *pScaledBitmapEx);
803 return this->_pNativeCanvas->DrawBitmap(pcPoint, *pBitmapEx);
807 return this->_pNativeCanvas->DrawBitmap(pcRect, *pBitmapEx);
814 return this->_pNativeCanvas->DrawBitmap(vcPoint, *pBitmapEx);
819 _CanvasImpl::DrawBitmap(const FloatPoint& vcPoint, const _BitmapImpl& bitmap)
821 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
823 return this->DrawBitmap(_Util::Convert<FloatPoint, Point>(vcPoint), bitmap);
827 _CanvasImpl::DrawBitmap(const Rectangle& vcDestRect, const _BitmapImpl& srcBitmap, const Rectangle& vcSrcRect)
829 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
831 SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(srcBitmap), E_INVALID_ARG, "The source bitmap is invalid.");
833 SysTryReturnResult(NID_GRP, (&vcSrcRect) && (&vcDestRect), E_INVALID_ARG, "The given rectangle is invalid.");
835 SysTryReturnResult(NID_GRP, (vcSrcRect.width >= 0) && (vcSrcRect.height >= 0), E_OUT_OF_RANGE, "The given source rectangle(width:%d,height:%d) is out of range.", vcSrcRect.width, vcSrcRect.height);
836 SysTryReturnResult(NID_GRP, (vcDestRect.width >= 0) && (vcDestRect.height >= 0), E_OUT_OF_RANGE, "The given destination rectangle(width:%d,height:%d) is out of range.", vcDestRect.width, vcDestRect.height);
838 if (vcSrcRect.width == 0 || vcSrcRect.height == 0)
843 if (vcDestRect.width == 0 || vcDestRect.height == 0)
848 if ((vcSrcRect.x < 0) || (vcSrcRect.y < 0) || (vcSrcRect.x + vcSrcRect.width > srcBitmap.GetWidth()) || (vcSrcRect.y + vcSrcRect.height > srcBitmap.GetHeight()))
850 SysTryReturnResult(NID_GRP, 0, E_OUT_OF_RANGE, "The specified region of source bitmap is out of range.");
853 // check if srcRect is in bitmap's area.
854 result r = _Util::Validate(vcSrcRect, Rectangle(0, 0, srcBitmap.GetWidth(), srcBitmap.GetHeight()));
856 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
858 // check if destRect is in this canvas.
859 Rectangle rtCanvas = _GetBoundsRel(*this);
861 if (rtCanvas.IsEmpty())
866 r = _Util::Validate(vcDestRect, rtCanvas);
868 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
870 EXTRACT_BITMAPEX(pBitmapEx, srcBitmap);
872 if (_ResUtil::NeedToConvertCoord())
874 Tizen::Graphics::Dimension virSize;
875 Tizen::Graphics::Dimension phySize;
876 bool lazyScaling = Tizen::Graphics::IsLazyScalingBitmap(srcBitmap, virSize, phySize);
878 Rectangle pcDestRect = _ResUtil::ConvertToPhyCoord(vcDestRect);
882 return this->_pNativeCanvas->DrawBitmap(pcDestRect, *pBitmapEx, vcSrcRect);
886 Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
888 return this->_pNativeCanvas->DrawBitmap(pcDestRect, *pBitmapEx, pcSrcRect);
893 return this->_pNativeCanvas->DrawBitmap(vcDestRect, *pBitmapEx, vcSrcRect);
898 _CanvasImpl::DrawBitmap(const FloatRectangle& vcDestRect, const _BitmapImpl& srcBitmap, const FloatRectangle& vcSrcRect)
900 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
902 return this->DrawBitmap(_Util::Convert<FloatRectangle, Rectangle>(vcDestRect), srcBitmap, _Util::Convert<FloatRectangle, Rectangle>(vcSrcRect));
906 _CanvasImpl::DrawBitmap(const Point& vcPoint, const _BitmapImpl& bitmap, FlipDirection dir)
908 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
910 SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
914 case FLIP_DIRECTION_HORIZONTAL:
915 case FLIP_DIRECTION_VERTICAL:
918 SysTryReturnResult(NID_GRP, 0, E_INVALID_ARG, "FlipStyle(%d) is invalid.", dir);
922 EXTRACT_BITMAPEX(pBitmapEx, bitmap);
924 if (_ResUtil::NeedToConvertCoord())
926 Tizen::Graphics::Dimension virSize;
927 Tizen::Graphics::Dimension phySize;
928 bool lazyScaling = Tizen::Graphics::IsLazyScalingBitmap(bitmap, virSize, phySize);
930 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
934 EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
936 return this->_pNativeCanvas->DrawBitmap(pcPoint, *pScaledBitmapEx, dir);
940 return this->_pNativeCanvas->DrawBitmap(pcPoint, *pBitmapEx, dir);
945 return this->_pNativeCanvas->DrawBitmap(vcPoint, *pBitmapEx, dir);
950 _CanvasImpl::DrawBitmap(const FloatPoint& vcPoint, const _BitmapImpl& bitmap, FlipDirection dir)
952 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
954 return this->DrawBitmap(_Util::Convert<FloatPoint, Point>(vcPoint), bitmap, dir);
958 _CanvasImpl::DrawBitmap(const Point& vcPoint, const _BitmapImpl& bitmap, const Point& vcPivot, int degree)
960 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
962 SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
964 EXTRACT_BITMAPEX(pBitmapEx, bitmap);
966 if (_ResUtil::NeedToConvertCoord())
968 Tizen::Graphics::Dimension virSize;
969 Tizen::Graphics::Dimension phySize;
970 bool lazyScaling = Tizen::Graphics::IsLazyScalingBitmap(bitmap, virSize, phySize);
972 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
973 Point pcPivot = _ResUtil::ConvertToPhyCoord(vcPivot);
977 EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
979 return this->_pNativeCanvas->DrawBitmap(pcPoint, *pScaledBitmapEx, pcPivot, degree);
983 return this->_pNativeCanvas->DrawBitmap(pcPoint, *pBitmapEx, pcPivot, degree);
988 return this->_pNativeCanvas->DrawBitmap(vcPoint, *pBitmapEx, vcPivot, degree);
993 _CanvasImpl::DrawBitmap(const FloatPoint& vcPoint, const _BitmapImpl& bitmap, const FloatPoint& vcPivot, float degree)
995 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
997 return this->DrawBitmap(_Util::Convert<FloatPoint, Point>(vcPoint), bitmap, _Util::Convert<FloatPoint, Point>(vcPivot), int(degree));
1001 _CanvasImpl::DrawNinePatchedBitmap(const Rectangle& vcRect, const _BitmapImpl& bitmap)
1003 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1005 SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
1007 SysTryReturnResult(NID_GRP, bitmap.IsNinePatchedBitmap(), E_INVALID_ARG, "The source bitmap is not a nine patched bitmap.");
1009 // check if bimap can be drew in canvas area.
1010 Rectangle rtCanvas = _GetBoundsRel(*this);
1012 if (rtCanvas.IsEmpty())
1014 SysTryReturnResult(NID_GRP, 0, E_OPERATION_FAILED, "Cannot get the bounds of the canvas.");
1017 result r = _Util::Validate(vcRect, rtCanvas);
1024 EXTRACT_BITMAPEX(pBitmapEx, bitmap);
1026 if (_ResUtil::NeedToConvertCoord())
1028 Tizen::Graphics::Dimension virSize;
1029 Tizen::Graphics::Dimension phySize;
1030 bool lazyScaling = Tizen::Graphics::IsLazyScalingBitmap(bitmap, virSize, phySize);
1032 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
1036 EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
1038 return this->_pNativeCanvas->DrawNinePatchedBitmap(pcRect, *pScaledBitmapEx);
1042 return this->_pNativeCanvas->DrawNinePatchedBitmap(pcRect, *pBitmapEx);
1047 return this->_pNativeCanvas->DrawNinePatchedBitmap(vcRect, *pBitmapEx);
1052 _CanvasImpl::DrawNinePatchedBitmap(const FloatRectangle& vcRect, const _BitmapImpl& bitmap)
1054 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1056 return this->DrawNinePatchedBitmap(_Util::Convert<FloatRectangle, Rectangle>(vcRect), bitmap);
1060 _CanvasImpl::DrawEllipse(const Rectangle& vcBounds)
1062 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1063 SysTryReturnResult(NID_GRP, &vcBounds, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1064 SysTryReturnResult(NID_GRP, (vcBounds.width >= 0) && (vcBounds.height >= 0), E_OUT_OF_RANGE,
1065 "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
1067 return _CanvasImplPrivate::DrawEllipse(this, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcBounds));
1071 _CanvasImpl::DrawEllipse(const FloatRectangle& vcBounds)
1073 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1074 SysTryReturnResult(NID_GRP, &vcBounds, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1075 SysTryReturnResult(NID_GRP, (vcBounds.width >= 0) && (vcBounds.height >= 0), E_OUT_OF_RANGE,
1076 "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
1078 return _CanvasImplPrivate::DrawEllipse(this, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcBounds));
1082 _CanvasImpl::DrawLine(const Point& vcPoint1, const Point& vcPoint2)
1084 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1086 return _CanvasImplPrivate::DrawLine(this,
1087 _Util::Convert<Point, _Util::Point<double> >(vcPoint1),
1088 _Util::Convert<Point, _Util::Point<double> >(vcPoint2));
1092 _CanvasImpl::DrawLine(const FloatPoint& vcPoint1, const FloatPoint& vcPoint2)
1094 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1096 return _CanvasImplPrivate::DrawLine(this,
1097 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint1),
1098 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint2));
1102 _CanvasImpl::DrawPolygon(const Tizen::Base::Collection::IList& vcPoints)
1104 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1106 int numPoint = vcPoints.GetCount();
1108 SysTryReturnResult(NID_GRP, numPoint >= 0, E_INVALID_ARG, "The number of points (%d) is not valid.", numPoint);
1110 if (numPoint < 2) // TBD.
1115 std::unique_ptr<_Util::Point<double>[]> doublePoint;
1118 _Util::Point<double>* pDoublePoint = _Util::Convert<Tizen::Base::Collection::IList, _Util::Point<double>*>(vcPoints);
1120 SysTryReturnResult(NID_GRP, pDoublePoint != null, E_INVALID_ARG, "The type of points is not valid.");
1122 doublePoint.reset(pDoublePoint);
1125 if (_ResUtil::NeedToConvertCoord())
1127 for (int i = 0; i < numPoint; i++)
1129 doublePoint[i] = _ResUtil::ConvertToPhyCoord(doublePoint[i]);
1132 return this->_pNativeCanvas->DrawPolygon(doublePoint.get(), numPoint);
1136 return this->_pNativeCanvas->DrawPolygon(doublePoint.get(), numPoint);
1141 _CanvasImpl::DrawPolyline(const Tizen::Base::Collection::IList& vcPoints)
1143 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1145 int numPoint = vcPoints.GetCount();
1147 SysTryReturnResult(NID_GRP, numPoint >= 0, E_INVALID_ARG, "The number of points (%d) is not valid.", numPoint);
1154 std::unique_ptr<_Util::Point<double>[]> doublePoint;
1157 _Util::Point<double>* pDoublePoint = _Util::Convert<Tizen::Base::Collection::IList, _Util::Point<double>*>(vcPoints);
1159 SysTryReturnResult(NID_GRP, pDoublePoint != null, E_INVALID_ARG, "The type of points is not valid.");
1161 doublePoint.reset(pDoublePoint);
1164 if (_ResUtil::NeedToConvertCoord())
1166 for (int i = 0; i < numPoint; i++)
1168 doublePoint[i] = _ResUtil::ConvertToPhyCoord(doublePoint[i]);
1171 return this->_pNativeCanvas->DrawPolyline(doublePoint.get(), numPoint);
1175 return this->_pNativeCanvas->DrawPolyline(doublePoint.get(), numPoint);
1180 _CanvasImpl::DrawRectangle(const Rectangle& vcRect)
1182 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1183 SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1184 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);
1186 return _CanvasImplPrivate::DrawRectangle(this, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcRect));
1190 _CanvasImpl::DrawRectangle(const FloatRectangle& vcRect)
1192 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1193 SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1194 SysTryReturnResult(NID_GRP, (vcRect.width >= 0.0f) && (vcRect.height >= 0.0f), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1196 return _CanvasImplPrivate::DrawRectangle(this, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcRect));
1200 _CanvasImpl::DrawRoundRectangle(const Rectangle& vcRect, const Dimension& vcArcDim)
1202 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1203 SysTryReturnResult(NID_GRP, (&vcRect) && (&vcArcDim), E_OUT_OF_RANGE, "The given rectangle is invalid.");
1204 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);
1205 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);
1207 return _CanvasImplPrivate::DrawRoundRectangle(this, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcRect), _Util::Convert<Dimension, _Util::Dimension<double> >(vcArcDim));
1211 _CanvasImpl::DrawRoundRectangle(const FloatRectangle& vcRect, const FloatDimension& vcArcDim)
1213 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1214 SysTryReturnResult(NID_GRP, (&vcRect) && (&vcArcDim), E_OUT_OF_RANGE, "The given rectangle is invalid.");
1215 SysTryReturnResult(NID_GRP, (vcRect.width >= 0.0f) && (vcRect.height >= 0.0f), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1216 SysTryReturnResult(NID_GRP, (vcArcDim.width >= 0.0f) && (vcArcDim.height >= 0.0f), E_OUT_OF_RANGE, "The given arc size(width:%d,height:%d) is out of range.", vcArcDim.width, vcArcDim.height);
1218 return _CanvasImplPrivate::DrawRoundRectangle(this, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcRect), _Util::Convert<FloatDimension, _Util::Dimension<double> >(vcArcDim));
1222 _CanvasImpl::DrawTriangle(const Point& vcPoint1, const Point& vcPoint2, const Point& vcPoint3)
1224 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1226 return _CanvasImplPrivate::DrawTriangle(this,
1227 _Util::Convert<Point, _Util::Point<double> >(vcPoint1),
1228 _Util::Convert<Point, _Util::Point<double> >(vcPoint2),
1229 _Util::Convert<Point, _Util::Point<double> >(vcPoint3));
1233 _CanvasImpl::DrawTriangle(const FloatPoint& vcPoint1, const FloatPoint& vcPoint2, const FloatPoint& vcPoint3)
1235 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1237 return _CanvasImplPrivate::DrawTriangle(this,
1238 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint1),
1239 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint2),
1240 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint3));
1244 _CanvasImpl::FillEllipse(const Color& color, const Rectangle& vcBounds)
1246 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1247 SysTryReturnResult(NID_GRP, &vcBounds, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1248 SysTryReturnResult(NID_GRP, (vcBounds.width >= 0) && (vcBounds.height >= 0), E_OUT_OF_RANGE,
1249 "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
1251 return _CanvasImplPrivate::FillEllipse(this, color, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcBounds));
1255 _CanvasImpl::FillEllipse(const Color& color, const FloatRectangle& vcBounds)
1257 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1258 SysTryReturnResult(NID_GRP, &vcBounds, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1259 SysTryReturnResult(NID_GRP, (vcBounds.width >= 0.0f) && (vcBounds.height >= 0.0f), E_OUT_OF_RANGE,
1260 "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
1262 return _CanvasImplPrivate::FillEllipse(this, color, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcBounds));
1266 _CanvasImpl::FillPolygon(const Color& color, const Tizen::Base::Collection::IList& vcPoints)
1268 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1270 SysTryReturnResult(NID_GRP, &vcPoints, E_INVALID_ARG, "The given rectangle is invalid.");
1272 int numPoint = vcPoints.GetCount();
1274 SysTryReturnResult(NID_GRP, numPoint >= 0, E_INVALID_ARG, "The number of points (%d) is not valid.", numPoint);
1276 if (numPoint < 3) // TBD.
1281 std::unique_ptr<_Util::Point<double>[]> doublePoint;
1284 _Util::Point<double>* pDoublePoint = _Util::Convert<Tizen::Base::Collection::IList, _Util::Point<double>*>(vcPoints);
1286 SysTryReturnResult(NID_GRP, pDoublePoint != null, E_INVALID_ARG, "The type of points is not valid.");
1288 doublePoint.reset(pDoublePoint);
1291 if (_ResUtil::NeedToConvertCoord())
1293 for (int i = 0; i < numPoint; i++)
1295 doublePoint[i] = _ResUtil::ConvertToPhyCoord(doublePoint[i]);
1298 return this->_pNativeCanvas->FillPolygon(color, doublePoint.get(), numPoint);
1302 return this->_pNativeCanvas->FillPolygon(color, doublePoint.get(), numPoint);
1307 _CanvasImpl::FillRectangle(const Color& color, const Rectangle& vcRect)
1309 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1310 SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1311 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);
1313 return _CanvasImplPrivate::FillRectangle(this, color, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcRect));
1317 _CanvasImpl::FillRectangle(const Color& color, const FloatRectangle& vcRect)
1319 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1320 SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1321 SysTryReturnResult(NID_GRP, (vcRect.width >= 0.0f) && (vcRect.height >= 0.0f), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1323 return _CanvasImplPrivate::FillRectangle(this, color, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcRect));
1327 _CanvasImpl::FillRoundRectangle(const Color& color, const Rectangle& vcRect, const Dimension& vcArcDim)
1329 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1330 SysTryReturnResult(NID_GRP, (&vcRect) && (&vcArcDim), E_OUT_OF_RANGE, "The given rectangle is invalid.");
1331 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);
1332 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);
1334 return _CanvasImplPrivate::FillRoundRectangle(this, color, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcRect), _Util::Convert<Dimension, _Util::Dimension<double> >(vcArcDim));
1338 _CanvasImpl::FillRoundRectangle(const Color& color, const FloatRectangle& vcRect, const FloatDimension& vcArcDim)
1340 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1341 SysTryReturnResult(NID_GRP, (&vcRect) && (&vcArcDim), E_OUT_OF_RANGE, "The given rectangle is invalid.");
1342 SysTryReturnResult(NID_GRP, (vcRect.width >= 0.0f) && (vcRect.height >= 0.0f), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1343 SysTryReturnResult(NID_GRP, (vcArcDim.width >= 0.0f) && (vcArcDim.height >= 0.0f), E_OUT_OF_RANGE, "The given arc size(width:%d,height:%d) is out of range.", vcArcDim.width, vcArcDim.height);
1345 return _CanvasImplPrivate::FillRoundRectangle(this, color, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcRect), _Util::Convert<FloatDimension, _Util::Dimension<double> >(vcArcDim));
1349 _CanvasImpl::FillTriangle(const Color& color, const FloatPoint& vcPoint1, const FloatPoint& vcPoint2, const FloatPoint& vcPoint3)
1351 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1353 return _CanvasImplPrivate::FillTriangle(this, color,
1354 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint1),
1355 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint2),
1356 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint3));
1360 _CanvasImpl::FillTriangle(const Color& color, const Point& vcPoint1, const Point& vcPoint2, const Point& vcPoint3)
1362 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1364 return _CanvasImplPrivate::FillTriangle(this, color,
1365 _Util::Convert<Point, _Util::Point<double> >(vcPoint1),
1366 _Util::Convert<Point, _Util::Point<double> >(vcPoint2),
1367 _Util::Convert<Point, _Util::Point<double> >(vcPoint3));
1371 _CanvasImpl::DrawText(const Point& vcPoint, const Tizen::Base::String& text)
1373 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1375 SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
1377 if (_ResUtil::NeedToConvertCoord())
1379 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
1381 return this->_pNativeCanvas->DrawText(pcPoint, text);
1385 return this->_pNativeCanvas->DrawText(vcPoint, text);
1390 _CanvasImpl::DrawText(const Point& vcPoint, const Tizen::Base::String& text, int startIndex, int length)
1392 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1393 SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
1394 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);
1396 if (text.GetLength() == 0)
1401 if (_ResUtil::NeedToConvertCoord())
1403 Point pcPt = _ResUtil::ConvertToPhyCoord(vcPoint);
1405 return this->_pNativeCanvas->DrawText(pcPt, text, startIndex, length);
1409 return this->_pNativeCanvas->DrawText(vcPoint, text, startIndex, length);
1414 _CanvasImpl::DrawText(const Point& vcPoint, const Tizen::Base::String& text, int startIndex, const Color& outlineColor)
1416 const char* pNotConstructedYet = "[E_OPERATION_FAILED] This instance is not constructed yet.";
1418 SysTryReturn(NID_GRP, this, E_OPERATION_FAILED, E_OPERATION_FAILED, pNotConstructedYet);
1419 SysTryReturn(NID_GRP, this->_pNativeCanvas, E_OPERATION_FAILED, E_OPERATION_FAILED, pNotConstructedYet);
1420 SysTryReturn(NID_GRP, this->_pNativeCanvas->IsValid(), E_OPERATION_FAILED, E_OPERATION_FAILED, pNotConstructedYet);
1422 SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
1424 return this->DrawText(vcPoint, text, startIndex, text.GetLength(), outlineColor);
1428 _CanvasImpl::DrawText(const Point& vcPoint, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor)
1430 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1432 SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
1434 SysTryReturnResult(NID_GRP, length >= 0, E_OUT_OF_RANGE,
1435 "The value of the length (%d) is outside the valid range defined by the method.",
1438 if (text.GetLength() == 0)
1443 if (_ResUtil::NeedToConvertCoord())
1445 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
1447 return this->_pNativeCanvas->DrawText(pcPoint, text, startIndex, length, outlineColor);
1451 return this->_pNativeCanvas->DrawText(vcPoint, text, startIndex, length, outlineColor);
1456 _CanvasImpl::DrawText(const Point& vcPoint, const EnrichedText& etext)
1458 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1460 const _EnrichedTextImpl* pImpl = _EnrichedTextImpl::GetInstance(etext);
1464 return E_OPERATION_FAILED;
1467 Tizen::Graphics::_Text::TextObject* pTextObject = const_cast <_EnrichedTextImpl*>(pImpl)->GetTextObject();
1469 if (pTextObject == null)
1471 return E_OPERATION_FAILED;
1474 Rectangle bounds = pImpl->GetBounds();
1475 Rectangle rect(vcPoint.x, vcPoint.y, bounds.width, bounds.height);
1476 pTextObject->SetBounds(rect);
1477 pTextObject->Draw(*this);
1483 _CanvasImpl::GetBounds(void) const
1485 SysTryReturn(NID_GRP, INSTANCE_IS_VALID, Rectangle(), E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1487 if (_ResUtil::NeedToConvertCoord())
1489 const _ResUtil::Pos& pos = this->_pCoordHolder->canvasPos.required;
1490 const _ResUtil::Rect& bounds = this->_pCoordHolder->canvasSize.required;
1491 const Rectangle boundsFromPi = this->_pNativeCanvas->GetBounds();
1493 if ((bounds.w == 0 && boundsFromPi.width > 0) || (bounds.h == 0 && boundsFromPi.height > 0))
1495 _CanvasImpl* pThis = const_cast<_CanvasImpl*>(this);
1497 pThis->_pCoordHolder->canvasSize = _ResUtil::Rect(boundsFromPi.x, boundsFromPi.y, boundsFromPi.width, boundsFromPi.height);
1499 pThis->_pCoordHolder->canvasSize.phyCoord.x = boundsFromPi.x;
1500 pThis->_pCoordHolder->canvasSize.phyCoord.y = boundsFromPi.y;
1501 pThis->_pCoordHolder->canvasSize.phyCoord.w = boundsFromPi.width;
1502 pThis->_pCoordHolder->canvasSize.phyCoord.h = boundsFromPi.height;
1505 // exception from the window canvas
1506 if (boundsFromPi.x == 0 && boundsFromPi.y == 0)
1508 return Rectangle(0, 0, bounds.w, bounds.h);
1512 return Rectangle(pos.x, pos.y, bounds.w, bounds.h);
1517 return this->_pNativeCanvas->GetBounds();
1522 _CanvasImpl::GetLineStyle() const
1524 SysTryReturn(NID_GRP, INSTANCE_IS_VALID, LINE_STYLE_MAX, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1526 return this->_pNativeCanvas->GetLineStyle();
1530 _CanvasImpl::GetLineWidth() const
1532 SysTryReturn(NID_GRP, INSTANCE_IS_VALID, -1, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1534 if (_ResUtil::NeedToConvertCoord())
1536 return this->_pCoordHolder->lineWidth.required;
1540 return this->_pNativeCanvas->GetLineWidth();
1545 _CanvasImpl::SetLineStyle(LineStyle style)
1547 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1549 SysTryReturnResult(NID_GRP, LINE_STYLE_MIN < style && style < LINE_STYLE_MAX, E_INVALID_ARG, "The given line style(%d) is out of range.", style);
1551 return this->_pNativeCanvas->SetLineStyle(style);
1555 _CanvasImpl::SetLineWidth(int vcWidth)
1557 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1559 SysTryReturnResult(NID_GRP, vcWidth > 0, E_OUT_OF_RANGE, "The given line width(%d) is out of range.", vcWidth);
1561 if (_ResUtil::NeedToConvertCoord())
1563 int pcWidth = _ResUtil::ConvertToPhyCoordSize(vcWidth);
1564 float pcWidthFloat = _ResUtil::ConvertToPhyCoordSize(float(vcWidth));
1566 result r = this->_pNativeCanvas->SetLineWidth(pcWidth, pcWidthFloat);
1570 this->_pCoordHolder->lineWidth = vcWidth;
1577 return this->_pNativeCanvas->SetLineWidth(vcWidth, float(vcWidth));
1582 _CanvasImpl::GetDashPattern(Tizen::Base::Collection::IListT<int>& pattern, int& offset)
1584 SysTryReturn(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1586 pattern.RemoveAll();
1588 result r = pattern.AddItems(this->_dashList);
1595 case E_OPERATION_FAILED:
1596 case E_OUT_OF_MEMORY:
1597 SysTryReturn(NID_GRP, false, r, r, "[%s] Propagating.", GetErrorMessage(r));
1600 SysTryReturn(NID_GRP, false, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Tizen::Base::Collection::ArrayListT<int>::AddItems() failed");
1605 offset = this->_dashOffset;
1611 _CanvasImpl::SetDashPattern(const Tizen::Base::Collection::IListT<int>& pattern, int offset)
1613 SysTryReturn(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1615 result r = E_SUCCESS;
1617 // It is NOT the strong guarantee for an exception
1618 this->_dashList.RemoveAll();
1620 r = this->_dashList.AddItems(pattern);
1627 case E_OPERATION_FAILED:
1628 case E_OUT_OF_MEMORY:
1629 SysTryReturn(NID_GRP, false, r, r, "[%s] Propagating.", GetErrorMessage(r));
1632 SysTryReturn(NID_GRP, false, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Tizen::Base::Collection::ArrayListT<int>::AddItems() failed");
1638 int dashIntValue = 0;
1639 Tizen::Graphics::_Util::AccumList<double> dashValueList;
1641 for (int i = 0; i < pattern.GetCount(); i++)
1643 pattern.GetAt(i, dashIntValue);
1644 dashValueList.Push(double(dashIntValue));
1647 r = this->_pNativeCanvas->SetDashPattern(dashValueList, double(offset));
1648 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1650 this->_dashOffset = offset;
1657 _CanvasImpl::SetDrawingQuality(BitmapDrawingQuality quality)
1659 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1663 case BITMAP_DRAWING_QUALITY_LOW:
1664 case BITMAP_DRAWING_QUALITY_MID:
1665 case BITMAP_DRAWING_QUALITY_HIGH:
1668 SysLogException(NID_GRP, E_INVALID_ARG, "The specified drawing quality(%d) is invalid.", quality);
1669 return E_INVALID_ARG;
1672 this->_pNativeCanvas->SetDrawingQuality(quality);
1677 BitmapDrawingQuality
1678 _CanvasImpl::GetDrawingQuality(void) const
1680 return (INSTANCE_IS_VALID) ? this->_pNativeCanvas->GetDrawingQuality() : BITMAP_DRAWING_QUALITY_LOW;
1684 _CanvasImpl::SetBlendingMode(BlendingMode blendingMode)
1686 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1688 switch (blendingMode)
1690 case BLENDING_MODE_CLEAR:
1691 case BLENDING_MODE_SRC:
1692 case BLENDING_MODE_DST:
1693 case BLENDING_MODE_SRC_OVER:
1694 case BLENDING_MODE_DST_OVER:
1695 case BLENDING_MODE_SRC_IN:
1696 case BLENDING_MODE_DST_IN:
1697 case BLENDING_MODE_SRC_OUT:
1698 case BLENDING_MODE_DST_OUT:
1699 case BLENDING_MODE_SRC_ATOP:
1700 case BLENDING_MODE_DST_ATOP:
1701 case BLENDING_MODE_DST_XOR:
1702 case BLENDING_MODE_ADD:
1703 case BLENDING_MODE_SATURATE:
1704 case BLENDING_MODE_MULTIPLY:
1705 case BLENDING_MODE_SCREEN:
1706 case BLENDING_MODE_OVERLAY:
1707 case BLENDING_MODE_DARKEN:
1708 case BLENDING_MODE_LIGHTEN:
1709 case BLENDING_MODE_COLOR_DODGE:
1710 case BLENDING_MODE_COLOR_BURN:
1711 case BLENDING_MODE_HARD_LIGHT:
1712 case BLENDING_MODE_SOFT_LIGHT:
1713 case BLENDING_MODE_DIFFERENCE:
1714 case BLENDING_MODE_EXCLUSION:
1717 SysLogException(NID_GRP, E_INVALID_ARG, "The specified blending mode(%d) is invalid.", blendingMode);
1718 return E_INVALID_ARG;
1721 this->_pNativeCanvas->SetBlendingMode(blendingMode);
1727 _CanvasImpl::GetBlendingMode(void) const
1729 return (INSTANCE_IS_VALID) ? this->_pNativeCanvas->GetBlendingMode() : BLENDING_MODE_SRC_OVER;
1733 _CanvasImpl::GetPixel(const Point& vcPoint, Color& color) const
1735 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1737 Rectangle rtCanvas = _GetBoundsRel(*this);
1739 SysTryReturnResult(NID_GRP, !rtCanvas.IsEmpty(), E_OUT_OF_RANGE, "Cannot get the bounds of the canvas.");
1741 result r = _Util::Validate(vcPoint, rtCanvas);
1743 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
1745 if (_ResUtil::NeedToConvertCoord())
1747 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
1749 return this->_pNativeCanvas->GetPixel(pcPoint, color);
1753 return this->_pNativeCanvas->GetPixel(vcPoint, color);
1758 _CanvasImpl::SetPixel(const FloatPoint& vcPoint)
1760 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1762 return _CanvasImplPrivate::SetPixel(this, _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint));
1766 _CanvasImpl::SetPixel(const Point& vcPoint)
1768 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1770 return _CanvasImplPrivate::SetPixel(this, _Util::Convert<Point, _Util::Point<int> >(vcPoint));
1776 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1778 result r = E_SUCCESS;
1779 Rectangle rect = this->GetBounds();
1781 r = this->_pNativeCanvas->Show();
1787 _CanvasImpl::Show(const Rectangle& vcRect)
1789 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1791 SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1792 SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE,
1793 "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width,
1796 result r = E_SUCCESS;
1797 Rectangle rect = this->GetBounds();
1799 if (_ResUtil::NeedToConvertCoord())
1801 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
1803 r = this->_pNativeCanvas->Show(pcRect);
1807 r = this->_pNativeCanvas->Show(vcRect);
1814 _CanvasImpl::SetFont(const Font& font)
1816 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1817 SysTryReturnResult(NID_GRP, _FontImpl::GetInstance(font) && _FontImpl::GetInstance(font)->IsConstructed(), E_INVALID_ARG, "The given font is not constructed.");
1818 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());
1820 // should keep clone font
1821 Font* pFont = _FontImpl::CloneN(font);
1825 SysTryLog(NID_GRP, pFont, "[] Fails to allocate memory for font resource.");
1827 this->_pFont = null;
1830 // 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?
1831 // or just setting defult font?!
1832 return E_OPERATION_FAILED;
1835 EXTRACT_FONTEX(pFontEx, *pFont);
1836 result r = this->_pNativeCanvas->SetFont(*pFontEx);
1837 SysTryCatch(NID_GRP, E_SUCCESS == r, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Fails to set font.");
1839 // succeed making cloned font, then keep it and replace old one.
1842 delete this->_pFont;
1843 this->_pFont = null;
1846 this->_pFont = pFont;
1858 _CanvasImpl::GetFontN(void)
1860 result r = E_SUCCESS;
1866 SysTryCatch(NID_GRP, INSTANCE_IS_VALID, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1868 // we have the font user set
1871 pFont = _FontImpl::CloneN(*(this->_pFont));
1872 SysTryCatch(NID_GRP, pFont, r = E_OUT_OF_MEMORY, E_OPERATION_FAILED, "[E_OUT_OF_MEMORY] Failed to create Font instance.");
1876 // make font instance with the attribute of system default font
1895 _CanvasImpl::SetTextOrigin(TextOrigin origin)
1897 if (INSTANCE_IS_VALID)
1901 case TEXT_ORIGIN_LEFT_TOP:
1902 case TEXT_ORIGIN_BASELINE:
1903 this->_pNativeCanvas->__textOrigin = origin;
1910 _CanvasImpl::SetClipBounds(const Rectangle& vcRect)
1912 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1914 SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1915 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);
1917 Rectangle rtCanvas = _GetBoundsRel(*this);
1919 result r = _Util::Validate(vcRect, rtCanvas);
1921 SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
1923 Rectangle revisedVcRect;
1928 int x2 = vcRect.x + vcRect.width;
1929 int y2 = vcRect.y + vcRect.height;
1931 x1 = (x1 > 0) ? x1 : 0;
1932 y1 = (y1 > 0) ? y1 : 0;
1933 x2 = (x2 < rtCanvas.width) ? x2 : rtCanvas.width;
1934 y2 = (y2 < rtCanvas.height) ? y2 : rtCanvas.height;
1936 revisedVcRect.x = x1;
1937 revisedVcRect.y = y1;
1938 revisedVcRect.width = x2 - x1;
1939 revisedVcRect.height = y2 - y1;
1942 if (_ResUtil::NeedToConvertCoord())
1944 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(revisedVcRect);
1947 pcRect.width = (pcRect.width >= 0) ? pcRect.width : 1;
1948 pcRect.height = (pcRect.height >= 0) ? pcRect.height : 1;
1950 result r = this->_pNativeCanvas->SetClipBounds(pcRect);
1954 this->_pCoordHolder->clipBounds = _ResUtil::Rect(revisedVcRect.x, revisedVcRect.y, revisedVcRect.width,
1955 revisedVcRect.height);
1962 return this->_pNativeCanvas->SetClipBounds(revisedVcRect);
1967 _CanvasImpl::GetClipBounds(void) const
1970 SysTryReturn(NID_GRP, INSTANCE_IS_VALID, rect, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1972 if (_ResUtil::NeedToConvertCoord())
1974 const _ResUtil::Rect& bounds = this->_pCoordHolder->clipBounds.required;
1976 return Rectangle(bounds.x, bounds.y, bounds.w, bounds.h);
1980 return this->_pNativeCanvas->GetClipBounds();
1985 _CanvasImpl::Lock(BufferInfo& info, long timeout)
1987 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1989 SysTryReturnResult(NID_GRP, (static_cast <unsigned long>(timeout) == INFINITE) || (timeout >= 0), E_INVALID_ARG,
1990 "'timeout(=%d)' is not valid.",
1993 return this->_pNativeCanvas->Lock(info, timeout);
1997 _CanvasImpl::Unlock()
1999 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2001 return this->_pNativeCanvas->Unlock();
2005 _CanvasImpl::SetForegroundColor(const Color& fgColor)
2007 SysTryReturnVoidResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2009 return this->_pNativeCanvas->SetForegroundColor(fgColor);
2013 _CanvasImpl::GetForegroundColor(void) const
2015 SysTryReturn(NID_GRP, INSTANCE_IS_VALID, Color::GetColor(COLOR_ID_BLACK), E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2017 return this->_pNativeCanvas->GetForegroundColor();
2021 _CanvasImpl::SetBackgroundColor(const Color& bgColor)
2023 SysTryReturnVoidResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2025 return this->_pNativeCanvas->SetBackgroundColor(bgColor);
2029 _CanvasImpl::GetBackgroundColor(void) const
2031 SysTryReturn(NID_GRP, INSTANCE_IS_VALID, Color::GetColor(COLOR_ID_BLACK), E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2033 return this->_pNativeCanvas->GetBackgroundColor();
2037 _CanvasImpl::SetPosition(const Point& vcPoint)
2039 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2041 return this->SetPosition(vcPoint.x, vcPoint.y);
2045 _CanvasImpl::SetPosition(int vcX, int vcY)
2047 SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2049 if (_ResUtil::NeedToConvertCoord())
2051 Point pcPoint = _ResUtil::ConvertToPhyCoord(Point(vcX, vcY));
2053 result r = this->_pNativeCanvas->SetPosition(pcPoint.x, pcPoint.y);
2057 this->_pCoordHolder->canvasPos = _ResUtil::Pos(vcX, vcY);
2064 return this->_pNativeCanvas->SetPosition(vcX, vcY);
2069 _CanvasImpl::GetSubCanvasN(const Rectangle& subRegion) const
2071 SysTryReturn(NID_GRP, INSTANCE_IS_VALID, null, E_OPERATION_FAILED, "This instance is not constructed yet.");
2073 _Canvas* pSourceNativeCanvas = this->_pNativeCanvas;
2075 std::auto_ptr <Canvas> subCanvas(new (std::nothrow) Canvas);
2077 Canvas* pSubCanvas = subCanvas.get();
2079 SysTryReturn(NID_GRP, pSubCanvas, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
2081 _CanvasImpl* pSubCanvasImpl = _CanvasImpl::GetInstance(*pSubCanvas);
2083 SysTryReturn(NID_GRP, pSubCanvasImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
2085 if (_ResUtil::NeedToConvertCoord())
2087 Rectangle subRegionPC = _ResUtil::ConvertToPhyCoord(subRegion);
2089 subRegionPC.width = (subRegionPC.width > 0) ? subRegionPC.width : 1;
2090 subRegionPC.height = (subRegionPC.height > 0) ? subRegionPC.height : 1;
2092 result r = pSubCanvasImpl->_pNativeCanvas->Construct(pSourceNativeCanvas, subRegionPC);
2094 SysTryReturn(NID_GRP, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
2096 pSubCanvasImpl->_pCoordHolder->Init(subRegion);
2097 pSubCanvasImpl->_pCoordHolder->canvasSize.phyCoord.w = subRegionPC.width;
2098 pSubCanvasImpl->_pCoordHolder->canvasSize.phyCoord.h = subRegionPC.height;
2102 result r = pSubCanvasImpl->_pNativeCanvas->Construct(pSourceNativeCanvas, subRegion);
2104 SysTryReturn(NID_GRP, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
2109 pSubCanvasImpl->SetFont(*this->_pFont);
2112 if (this->_pPriorityFont)
2114 pSubCanvasImpl->SetPriorityFont(*this->_pPriorityFont);
2117 return subCanvas.release();
2121 _CanvasImpl::SetPriorityFont(const Font& font)
2125 // check input param
2126 SysTryReturn(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2127 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());
2129 Font* pFont = &(const_cast <Font&>(font));
2131 EXTRACT_FONTEX(pFontEx, *pFont);
2132 result r = this->_pNativeCanvas->SetPriorityFont(*pFontEx);
2133 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2134 // overwrite existing priority font
2135 this->_pPriorityFont = pFont;
2141 _CanvasImpl::ResetPriorityFont(void)
2143 if (INSTANCE_IS_VALID)
2145 this->_pPriorityFont = null;
2146 this->_pNativeCanvas->ResetPriorityFont();
2151 _CanvasImpl::SetStableRenderer(bool isStable)
2153 if (INSTANCE_IS_VALID)
2155 this->_pNativeCanvas->__useStableRenderer = isStable;
2160 _CanvasImpl::SetFrameInfoCallback(void* (*pGetDefaultFrameNativeHandle)(void), void* (*pGetDefaultFrameHandle)(void))
2162 _GetDefaultFrameEcoreEvasHandle = (pGetDefaultFrameNativeHandle) ? pGetDefaultFrameNativeHandle : _GetNull;
2163 _GetDefaultFrameEvasHandle = (pGetDefaultFrameHandle) ? pGetDefaultFrameHandle : _GetNull;
2167 _CanvasImpl::SetThemeInfoCallback(Color (*pGetDefaultForegroundColor)(void), Color (*pGetDefaultBackgroundColor)(void))
2169 _GetDefaultForegroundColor = (pGetDefaultForegroundColor) ? pGetDefaultForegroundColor : _GetBlack;
2170 _GetDefaultBackgroundColor = (pGetDefaultBackgroundColor) ? pGetDefaultBackgroundColor : _GetWhite;
2174 _CanvasImpl::GetInstance(Canvas& canvas)
2176 return (&canvas != null) ? canvas.__pImpl : null;
2180 _CanvasImpl::GetInstance(const Canvas& canvas)
2182 return (&canvas != null) ? canvas.__pImpl : null;
2185 }} // Tizen::Graphics