diff options
Diffstat (limited to 'cppcanvas/source/wrapper')
23 files changed, 2729 insertions, 0 deletions
diff --git a/cppcanvas/source/wrapper/basegfxfactory.cxx b/cppcanvas/source/wrapper/basegfxfactory.cxx new file mode 100644 index 000000000000..acf6001d0ca7 --- /dev/null +++ b/cppcanvas/source/wrapper/basegfxfactory.cxx @@ -0,0 +1,164 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppcanvas.hxx" + +#include <rtl/instance.hxx> +#include <osl/getglobalmutex.hxx> +#include <osl/diagnose.h> + +#include <com/sun/star/rendering/InterpolationMode.hpp> + +#include <basegfx/polygon/b2dpolygon.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/tools/canvastools.hxx> + +#include <cppcanvas/basegfxfactory.hxx> + +#include "implpolypolygon.hxx" +#include "implbitmap.hxx" +#include "impltext.hxx" + + +using namespace ::com::sun::star; + +namespace cppcanvas +{ + /* Singleton handling */ + struct InitInstance2 + { + BaseGfxFactory* operator()() + { + return new BaseGfxFactory(); + } + }; + + BaseGfxFactory& BaseGfxFactory::getInstance() + { + return *rtl_Instance< BaseGfxFactory, InitInstance2, ::osl::MutexGuard, + ::osl::GetGlobalMutex >::create( + InitInstance2(), ::osl::GetGlobalMutex()); + } + + BaseGfxFactory::BaseGfxFactory() + { + } + + BaseGfxFactory::~BaseGfxFactory() + { + } + + PolyPolygonSharedPtr BaseGfxFactory::createPolyPolygon( const CanvasSharedPtr& rCanvas, + const ::basegfx::B2DPolygon& rPoly ) const + { + OSL_ENSURE( rCanvas.get() != NULL && + rCanvas->getUNOCanvas().is(), + "BaseGfxFactory::createPolyPolygon(): Invalid canvas" ); + + if( rCanvas.get() == NULL ) + return PolyPolygonSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return PolyPolygonSharedPtr(); + + return PolyPolygonSharedPtr( + new internal::ImplPolyPolygon( rCanvas, + ::basegfx::unotools::xPolyPolygonFromB2DPolygon( + xCanvas->getDevice(), + rPoly) ) ); + } + + PolyPolygonSharedPtr BaseGfxFactory::createPolyPolygon( const CanvasSharedPtr& rCanvas, + const ::basegfx::B2DPolyPolygon& rPolyPoly ) const + { + OSL_ENSURE( rCanvas.get() != NULL && + rCanvas->getUNOCanvas().is(), + "BaseGfxFactory::createPolyPolygon(): Invalid canvas" ); + + if( rCanvas.get() == NULL ) + return PolyPolygonSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return PolyPolygonSharedPtr(); + + return PolyPolygonSharedPtr( + new internal::ImplPolyPolygon( rCanvas, + ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( + xCanvas->getDevice(), + rPolyPoly) ) ); + } + + BitmapSharedPtr BaseGfxFactory::createBitmap( const CanvasSharedPtr& rCanvas, + const ::basegfx::B2ISize& rSize ) const + { + OSL_ENSURE( rCanvas.get() != NULL && + rCanvas->getUNOCanvas().is(), + "BaseGfxFactory::createBitmap(): Invalid canvas" ); + + if( rCanvas.get() == NULL ) + return BitmapSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return BitmapSharedPtr(); + + return BitmapSharedPtr( + new internal::ImplBitmap( rCanvas, + xCanvas->getDevice()->createCompatibleBitmap( + ::basegfx::unotools::integerSize2DFromB2ISize(rSize) ) ) ); + } + + BitmapSharedPtr BaseGfxFactory::createAlphaBitmap( const CanvasSharedPtr& rCanvas, + const ::basegfx::B2ISize& rSize ) const + { + OSL_ENSURE( rCanvas.get() != NULL && + rCanvas->getUNOCanvas().is(), + "BaseGfxFactory::createBitmap(): Invalid canvas" ); + + if( rCanvas.get() == NULL ) + return BitmapSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return BitmapSharedPtr(); + + return BitmapSharedPtr( + new internal::ImplBitmap( rCanvas, + xCanvas->getDevice()->createCompatibleAlphaBitmap( + ::basegfx::unotools::integerSize2DFromB2ISize(rSize) ) ) ); + } + + TextSharedPtr BaseGfxFactory::createText( const CanvasSharedPtr& rCanvas, const ::rtl::OUString& rText ) const + { + return TextSharedPtr( new internal::ImplText( rCanvas, + rText ) ); + } + +} diff --git a/cppcanvas/source/wrapper/implbitmap.cxx b/cppcanvas/source/wrapper/implbitmap.cxx new file mode 100644 index 000000000000..81d5a5d4e755 --- /dev/null +++ b/cppcanvas/source/wrapper/implbitmap.cxx @@ -0,0 +1,126 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppcanvas.hxx" + +#include "implbitmap.hxx" +#include "implbitmapcanvas.hxx" + +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <canvas/canvastools.hxx> + + +using namespace ::com::sun::star; + +namespace cppcanvas +{ + + namespace internal + { + + ImplBitmap::ImplBitmap( const CanvasSharedPtr& rParentCanvas, + const uno::Reference< rendering::XBitmap >& rBitmap ) : + CanvasGraphicHelper( rParentCanvas ), + mxBitmap( rBitmap ), + mpBitmapCanvas() + { + OSL_ENSURE( mxBitmap.is(), "ImplBitmap::ImplBitmap: no valid bitmap" ); + + uno::Reference< rendering::XBitmapCanvas > xBitmapCanvas( rBitmap, + uno::UNO_QUERY ); + if( xBitmapCanvas.is() ) + mpBitmapCanvas.reset( new ImplBitmapCanvas( + uno::Reference< rendering::XBitmapCanvas >(rBitmap, + uno::UNO_QUERY) ) ); + } + + ImplBitmap::~ImplBitmap() + { + } + + bool ImplBitmap::draw() const + { + CanvasSharedPtr pCanvas( getCanvas() ); + + OSL_ENSURE( pCanvas.get() != NULL && + pCanvas->getUNOCanvas().is(), + "ImplBitmap::draw: invalid canvas" ); + + if( pCanvas.get() == NULL || + !pCanvas->getUNOCanvas().is() ) + { + return false; + } + + // TODO(P1): implement caching + pCanvas->getUNOCanvas()->drawBitmap( mxBitmap, + pCanvas->getViewState(), + getRenderState() ); + + return true; + } + + bool ImplBitmap::drawAlphaModulated( double nAlphaModulation ) const + { + CanvasSharedPtr pCanvas( getCanvas() ); + + OSL_ENSURE( pCanvas.get() != NULL && + pCanvas->getUNOCanvas().is(), + "ImplBitmap::drawAlphaModulated(): invalid canvas" ); + + if( pCanvas.get() == NULL || + !pCanvas->getUNOCanvas().is() ) + { + return false; + } + + rendering::RenderState aLocalState( getRenderState() ); + uno::Sequence<rendering::ARGBColor> aCol(1); + aCol[0] = rendering::ARGBColor( nAlphaModulation, 1.0, 1.0, 1.0 ); + aLocalState.DeviceColor = + pCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace()->convertFromARGB(aCol); + + // TODO(P1): implement caching + pCanvas->getUNOCanvas()->drawBitmapModulated( mxBitmap, + pCanvas->getViewState(), + aLocalState ); + + return true; + } + + BitmapCanvasSharedPtr ImplBitmap::getBitmapCanvas() const + { + return mpBitmapCanvas; + } + + uno::Reference< rendering::XBitmap > ImplBitmap::getUNOBitmap() const + { + return mxBitmap; + } + } +} diff --git a/cppcanvas/source/wrapper/implbitmap.hxx b/cppcanvas/source/wrapper/implbitmap.hxx new file mode 100644 index 000000000000..974eb4176b5a --- /dev/null +++ b/cppcanvas/source/wrapper/implbitmap.hxx @@ -0,0 +1,82 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CPPCANVAS_IMPLBITMAP_HXX +#define _CPPCANVAS_IMPLBITMAP_HXX + +#include <com/sun/star/uno/Reference.hxx> +#ifndef _COM_SUN_STAR_RENDERING_XBITMAP_HPP__ +#include <com/sun/star/rendering/XBitmap.hpp> +#endif +#ifndef _COM_SUN_STAR_RENDERING_XGRAPHICDEVICE_HPP__ +#include <com/sun/star/rendering/XGraphicDevice.hpp> +#endif + +#include <cppcanvas/bitmap.hxx> +#include <canvasgraphichelper.hxx> + + +/*Definition of ImplBitmap */ + +namespace cppcanvas +{ + + namespace internal + { + // share partial CanvasGraphic implementation from CanvasGraphicHelper + class ImplBitmap : public virtual ::cppcanvas::Bitmap, protected CanvasGraphicHelper + { + public: + + ImplBitmap( const CanvasSharedPtr& rParentCanvas, + const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XBitmap >& rBitmap ); + + virtual ~ImplBitmap(); + + // CanvasGraphic implementation (that was not already implemented by CanvasGraphicHelper) + virtual bool draw() const; + virtual bool drawAlphaModulated( double nAlphaModulation ) const; + + virtual BitmapCanvasSharedPtr getBitmapCanvas() const; + + // Bitmap implementation + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XBitmap > getUNOBitmap() const; + + private: + // default: disabled copy/assignment + ImplBitmap(const ImplBitmap&); + ImplBitmap& operator=( const ImplBitmap& ); + + const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > mxBitmap; + BitmapCanvasSharedPtr mpBitmapCanvas; + }; + } +} + +#endif /* _CPPCANVAS_IMPLBITMAP_HXX */ diff --git a/cppcanvas/source/wrapper/implbitmapcanvas.cxx b/cppcanvas/source/wrapper/implbitmapcanvas.cxx new file mode 100644 index 000000000000..b9de616ebab1 --- /dev/null +++ b/cppcanvas/source/wrapper/implbitmapcanvas.cxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppcanvas.hxx" + +#include <com/sun/star/rendering/XCanvas.hpp> +#include <com/sun/star/rendering/XBitmapCanvas.hpp> + +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/tools/canvastools.hxx> + +#include "implbitmapcanvas.hxx" + + +using namespace ::com::sun::star; + +namespace cppcanvas +{ + namespace internal + { + ImplBitmapCanvas::ImplBitmapCanvas( const uno::Reference< rendering::XBitmapCanvas >& rCanvas ) : + ImplCanvas( uno::Reference< rendering::XCanvas >(rCanvas, + uno::UNO_QUERY) ), + mxBitmapCanvas( rCanvas ), + mxBitmap( rCanvas, + uno::UNO_QUERY ) + { + OSL_ENSURE( mxBitmapCanvas.is(), "ImplBitmapCanvas::ImplBitmapCanvas(): Invalid canvas" ); + OSL_ENSURE( mxBitmap.is(), "ImplBitmapCanvas::ImplBitmapCanvas(): Invalid bitmap" ); + } + + ImplBitmapCanvas::~ImplBitmapCanvas() + { + } + + ::basegfx::B2ISize ImplBitmapCanvas::getSize() const + { + OSL_ENSURE( mxBitmap.is(), "ImplBitmapCanvas::getSize(): Invalid canvas" ); + return ::basegfx::unotools::b2ISizeFromIntegerSize2D( mxBitmap->getSize() ); + } + + CanvasSharedPtr ImplBitmapCanvas::clone() const + { + return BitmapCanvasSharedPtr( new ImplBitmapCanvas( *this ) ); + } + } +} diff --git a/cppcanvas/source/wrapper/implbitmapcanvas.hxx b/cppcanvas/source/wrapper/implbitmapcanvas.hxx new file mode 100644 index 000000000000..7d70f226848e --- /dev/null +++ b/cppcanvas/source/wrapper/implbitmapcanvas.hxx @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CPPCANVAS_IMPLBITMAPCANVAS_HXX +#define _CPPCANVAS_IMPLBITMAPCANVAS_HXX + +#ifndef _COM_SUN_STAR_RENDERING_XBITMAPCANVAS_HPP__ +#include <com/sun/star/rendering/XBitmapCanvas.hpp> +#endif +#ifndef _COM_SUN_STAR_RENDERING_XBITMAP_HPP__ +#include <com/sun/star/rendering/XBitmap.hpp> +#endif + +#ifndef BOOST_SHARED_PTR_HPP_INCLUDED +#include <boost/shared_ptr.hpp> +#endif +#include <basegfx/vector/b2dsize.hxx> +#include <cppcanvas/bitmapcanvas.hxx> + +#include <implcanvas.hxx> + + +namespace cppcanvas +{ + namespace internal + { + // share Canvas implementation from ImplCanvas + class ImplBitmapCanvas : public virtual BitmapCanvas, protected virtual ImplCanvas + { + public: + ImplBitmapCanvas( const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XBitmapCanvas >& rCanvas ); + virtual ~ImplBitmapCanvas(); + + virtual ::basegfx::B2ISize getSize() const; + + virtual CanvasSharedPtr clone() const; + + // take compiler-provided default copy constructor + //ImplBitmapCanvas(const ImplBitmapCanvas&); + + private: + // default: disabled assignment + ImplBitmapCanvas& operator=( const ImplBitmapCanvas& ); + + const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > mxBitmapCanvas; + const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > mxBitmap; + }; + } +} + +#endif /* _CPPCANVAS_IMPLBITMAPCANVAS_HXX */ diff --git a/cppcanvas/source/wrapper/implcanvas.cxx b/cppcanvas/source/wrapper/implcanvas.cxx new file mode 100644 index 000000000000..e08f270d117b --- /dev/null +++ b/cppcanvas/source/wrapper/implcanvas.cxx @@ -0,0 +1,141 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppcanvas.hxx" + +#include <rtl/ustring.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/tools/canvastools.hxx> + +#include <com/sun/star/rendering/XCanvas.hpp> + +#include <canvas/canvastools.hxx> +#include <cppcanvas/polypolygon.hxx> + +#include "implfont.hxx" +#include "implcolor.hxx" +#include "implcanvas.hxx" + + +using namespace ::com::sun::star; + +namespace cppcanvas +{ + namespace internal + { + + ImplCanvas::ImplCanvas( const uno::Reference< rendering::XCanvas >& xCanvas ) : + maViewState(), + maClipPolyPolygon(), + mxCanvas( xCanvas ) + { + OSL_ENSURE( mxCanvas.is(), "Canvas::Canvas() invalid XCanvas" ); + + ::canvas::tools::initViewState( maViewState ); + } + + ImplCanvas::~ImplCanvas() + { + } + + void ImplCanvas::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix ) + { + ::canvas::tools::setViewStateTransform( maViewState, rMatrix ); + } + + ::basegfx::B2DHomMatrix ImplCanvas::getTransformation() const + { + ::basegfx::B2DHomMatrix aMatrix; + return ::canvas::tools::getViewStateTransform( aMatrix, + maViewState ); + } + + void ImplCanvas::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly ) + { + // TODO(T3): not thread-safe. B2DPolyPolygon employs copy-on-write + maClipPolyPolygon.reset( rClipPoly ); + maViewState.Clip.clear(); + } + + void ImplCanvas::setClip() + { + maClipPolyPolygon.reset(); + maViewState.Clip.clear(); + } + + ::basegfx::B2DPolyPolygon const* ImplCanvas::getClip() const + { + return !maClipPolyPolygon ? NULL : &(*maClipPolyPolygon); + } + + FontSharedPtr ImplCanvas::createFont( const ::rtl::OUString& rFontName, const double& rCellSize ) const + { + return FontSharedPtr( new ImplFont( getUNOCanvas(), rFontName, rCellSize ) ); + } + + ColorSharedPtr ImplCanvas::createColor() const + { + return ColorSharedPtr( new ImplColor( getUNOCanvas()->getDevice() ) ); + } + + CanvasSharedPtr ImplCanvas::clone() const + { + return CanvasSharedPtr( new ImplCanvas( *this ) ); + } + + void ImplCanvas::clear() const + { + OSL_ENSURE( mxCanvas.is(), "ImplCanvas::clear(): Invalid XCanvas" ); + mxCanvas->clear(); + } + + uno::Reference< rendering::XCanvas > ImplCanvas::getUNOCanvas() const + { + OSL_ENSURE( mxCanvas.is(), "ImplCanvas::getUNOCanvas(): Invalid XCanvas" ); + + return mxCanvas; + } + + rendering::ViewState ImplCanvas::getViewState() const + { + if( maClipPolyPolygon && !maViewState.Clip.is() ) + { + if( !mxCanvas.is() ) + return maViewState; + + maViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( + mxCanvas->getDevice(), + *maClipPolyPolygon ); + } + + return maViewState; + } + + } +} diff --git a/cppcanvas/source/wrapper/implcanvas.hxx b/cppcanvas/source/wrapper/implcanvas.hxx new file mode 100644 index 000000000000..87cb8b8c85fc --- /dev/null +++ b/cppcanvas/source/wrapper/implcanvas.hxx @@ -0,0 +1,104 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CPPCANVAS_IMPLCANVAS_HXX +#define _CPPCANVAS_IMPLCANVAS_HXX + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/rendering/ViewState.hpp> +#include <cppcanvas/canvas.hxx> + +#include <boost/optional.hpp> + +namespace rtl +{ + class OUString; +} + +namespace basegfx +{ + class B2DHomMatrix; + class B2DPolyPolygon; +} + +namespace com { namespace sun { namespace star { namespace rendering +{ + class XCanvas; +} } } } + + +/* Definition of ImplCanvas */ + +namespace cppcanvas +{ + + namespace internal + { + + class ImplCanvas : public virtual Canvas + { + public: + ImplCanvas( const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XCanvas >& rCanvas ); + virtual ~ImplCanvas(); + + virtual void setTransformation( const ::basegfx::B2DHomMatrix& rMatrix ); + virtual ::basegfx::B2DHomMatrix getTransformation() const; + + virtual void setClip( const ::basegfx::B2DPolyPolygon& rClipPoly ); + virtual void setClip(); + virtual ::basegfx::B2DPolyPolygon const* getClip() const; + + virtual FontSharedPtr createFont( const ::rtl::OUString& rFontName, const double& rCellSize ) const; + + virtual ColorSharedPtr createColor() const; + + virtual CanvasSharedPtr clone() const; + + virtual void clear() const; + + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XCanvas > getUNOCanvas() const; + + virtual ::com::sun::star::rendering::ViewState getViewState() const; + + // take compiler-provided default copy constructor + //ImplCanvas(const ImplCanvas&); + + private: + // default: disabled assignment + ImplCanvas& operator=( const ImplCanvas& ); + + mutable ::com::sun::star::rendering::ViewState maViewState; + boost::optional<basegfx::B2DPolyPolygon> maClipPolyPolygon; + const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvas > mxCanvas; + }; + + } +} + +#endif /* _CPPCANVAS_IMPLCANVAS_HXX */ diff --git a/cppcanvas/source/wrapper/implcolor.cxx b/cppcanvas/source/wrapper/implcolor.cxx new file mode 100644 index 000000000000..9e591e3e98f0 --- /dev/null +++ b/cppcanvas/source/wrapper/implcolor.cxx @@ -0,0 +1,68 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppcanvas.hxx" + +#include <implcolor.hxx> +#include <tools.hxx> + +using namespace ::com::sun::star; + +namespace cppcanvas +{ + namespace internal + { + + ImplColor::ImplColor( const uno::Reference< rendering::XGraphicDevice >& rDevice ) : + mxDevice( rDevice ) + { + OSL_ENSURE( mxDevice.is(), "ImplColor::ImplColor(): Invalid graphic device" ); + } + + ImplColor::~ImplColor() + { + } + + Color::IntSRGBA ImplColor::getIntSRGBA( uno::Sequence< double >& rDeviceColor ) const + { + OSL_ENSURE( mxDevice.is(), "ImplColor::getIntSRGBA(): Invalid graphic device" ); + + // TODO(F1): Color space handling + return tools::doubleSequenceToIntSRGBA( mxDevice, rDeviceColor ); + } + + uno::Sequence< double > ImplColor::getDeviceColor( Color::IntSRGBA aSRGBA ) const + { + OSL_ENSURE( mxDevice.is(), "ImplColor::getDeviceColor(): Invalid graphic device" ); + + // TODO(F1): Color space handling + return tools::intSRGBAToDoubleSequence( mxDevice, aSRGBA ); + } + + } +} diff --git a/cppcanvas/source/wrapper/implcolor.hxx b/cppcanvas/source/wrapper/implcolor.hxx new file mode 100644 index 000000000000..5140d905245c --- /dev/null +++ b/cppcanvas/source/wrapper/implcolor.hxx @@ -0,0 +1,66 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CPPCANVAS_IMPLCOLOR_HXX +#define _CPPCANVAS_IMPLCOLOR_HXX + +#include <com/sun/star/uno/Sequence.hxx> + +#ifndef BOOST_SHARED_PTR_HPP_INCLUDED +#include <boost/shared_ptr.hpp> +#endif + +#ifndef _COM_SUN_STAR_RENDERING_XGRAPHICDEVICE_HPP__ +#include <com/sun/star/rendering/XGraphicDevice.hpp> +#endif +#include <cppcanvas/color.hxx> + + +/* Definition of Color class */ + +namespace cppcanvas +{ + namespace internal + { + class ImplColor : public Color + { + public: + ImplColor( const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XGraphicDevice >& rDevice ); + virtual ~ImplColor(); + + virtual IntSRGBA getIntSRGBA( ::com::sun::star::uno::Sequence< double >& rDeviceColor ) const; + virtual ::com::sun::star::uno::Sequence< double > getDeviceColor( IntSRGBA aSRGBA ) const; + + private: + ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice > mxDevice; + }; + + } +} + +#endif /* _CPPCANVAS_IMPLCOLOR_HXX */ diff --git a/cppcanvas/source/wrapper/implcustomsprite.cxx b/cppcanvas/source/wrapper/implcustomsprite.cxx new file mode 100644 index 000000000000..786b3699af3b --- /dev/null +++ b/cppcanvas/source/wrapper/implcustomsprite.cxx @@ -0,0 +1,82 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppcanvas.hxx" + +#include <basegfx/polygon/b2dpolypolygon.hxx> + +#include "implcustomsprite.hxx" +#include "implcanvas.hxx" + +using namespace ::com::sun::star; + +namespace cppcanvas +{ + namespace internal + { + ImplCustomSprite::ImplCustomSprite( const uno::Reference< rendering::XSpriteCanvas >& rParentCanvas, + const uno::Reference< rendering::XCustomSprite >& rSprite, + const ImplSpriteCanvas::TransformationArbiterSharedPtr& rTransformArbiter ) : + ImplSprite( rParentCanvas, + uno::Reference< rendering::XSprite >(rSprite, + uno::UNO_QUERY), + rTransformArbiter ), + mpLastCanvas(), + mxCustomSprite( rSprite ) + { + OSL_ENSURE( rParentCanvas.is(), "ImplCustomSprite::ImplCustomSprite(): Invalid canvas" ); + OSL_ENSURE( mxCustomSprite.is(), "ImplCustomSprite::ImplCustomSprite(): Invalid sprite" ); + } + + ImplCustomSprite::~ImplCustomSprite() + { + } + + CanvasSharedPtr ImplCustomSprite::getContentCanvas() const + { + OSL_ENSURE( mxCustomSprite.is(), "ImplCustomSprite::getContentCanvas(): Invalid sprite" ); + + if( !mxCustomSprite.is() ) + return CanvasSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( mxCustomSprite->getContentCanvas() ); + + if( !xCanvas.is() ) + return CanvasSharedPtr(); + + // cache content canvas C++ wrapper + if( mpLastCanvas.get() == NULL || + mpLastCanvas->getUNOCanvas() != xCanvas ) + { + mpLastCanvas = CanvasSharedPtr( new ImplCanvas( xCanvas ) ); + } + + return mpLastCanvas; + } + } +} diff --git a/cppcanvas/source/wrapper/implcustomsprite.hxx b/cppcanvas/source/wrapper/implcustomsprite.hxx new file mode 100644 index 000000000000..b02eab38df1e --- /dev/null +++ b/cppcanvas/source/wrapper/implcustomsprite.hxx @@ -0,0 +1,71 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CPPCANVAS_IMPLCUSTOMSPRITE_HXX +#define _CPPCANVAS_IMPLCUSTOMSPRITE_HXX + +#include <sal/types.h> + +#ifndef BOOST_SHARED_PTR_HPP_INCLUDED +#include <boost/shared_ptr.hpp> +#endif +#include <cppcanvas/canvas.hxx> +#include <cppcanvas/customsprite.hxx> + +#include <implsprite.hxx> +#include <implspritecanvas.hxx> + + +namespace cppcanvas +{ + namespace internal + { + // share Sprite implementation of ImplSprite + class ImplCustomSprite : public virtual CustomSprite, protected virtual ImplSprite + { + public: + ImplCustomSprite( const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XSpriteCanvas >& rParentCanvas, + const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XCustomSprite >& rSprite, + const ImplSpriteCanvas::TransformationArbiterSharedPtr& rTransformArbiter ); + virtual ~ImplCustomSprite(); + + virtual CanvasSharedPtr getContentCanvas() const; + + private: + // default: disabled copy/assignment + ImplCustomSprite(const ImplCustomSprite&); + ImplCustomSprite& operator=( const ImplCustomSprite& ); + + mutable CanvasSharedPtr mpLastCanvas; + const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCustomSprite > mxCustomSprite; + }; + } +} + +#endif /* _CPPCANVAS_IMPLCUSTOMSPRITE_HXX */ diff --git a/cppcanvas/source/wrapper/implfont.cxx b/cppcanvas/source/wrapper/implfont.cxx new file mode 100644 index 000000000000..48decd6677da --- /dev/null +++ b/cppcanvas/source/wrapper/implfont.cxx @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppcanvas.hxx" + +#include <implfont.hxx> +#include <canvas/canvastools.hxx> + + +using namespace ::com::sun::star; + +/* Definition of Font class */ + +namespace cppcanvas +{ + namespace internal + { + + ImplFont::ImplFont( const uno::Reference< rendering::XCanvas >& rCanvas, + const ::rtl::OUString& rFontName, + const double& rCellSize ) : + mxCanvas( rCanvas ), + mxFont( NULL ) + { + OSL_ENSURE( mxCanvas.is(), "ImplFont::ImplFont(): Invalid Canvas" ); + + rendering::FontRequest aFontRequest; + aFontRequest.FontDescription.FamilyName = rFontName; + aFontRequest.CellSize = rCellSize; + + geometry::Matrix2D aFontMatrix; + ::canvas::tools::setIdentityMatrix2D( aFontMatrix ); + + mxFont = mxCanvas->createFont( aFontRequest, + uno::Sequence< beans::PropertyValue >(), + aFontMatrix ); + } + + + ImplFont::~ImplFont() + { + } + + ::rtl::OUString ImplFont::getName() const + { + OSL_ENSURE( mxFont.is(), "ImplFont::getName(): Invalid Font" ); + + return mxFont->getFontRequest().FontDescription.FamilyName; + } + + double ImplFont::getCellSize() const + { + OSL_ENSURE( mxFont.is(), "ImplFont::getCellSize(): Invalid Font" ); + + return mxFont->getFontRequest().CellSize; + } + + uno::Reference< rendering::XCanvasFont > ImplFont::getUNOFont() const + { + OSL_ENSURE( mxFont.is(), "ImplFont::getUNOFont(): Invalid Font" ); + + return mxFont; + } + + } +} diff --git a/cppcanvas/source/wrapper/implfont.hxx b/cppcanvas/source/wrapper/implfont.hxx new file mode 100644 index 000000000000..c7b93b876e10 --- /dev/null +++ b/cppcanvas/source/wrapper/implfont.hxx @@ -0,0 +1,83 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CPPCANVAS_IMPLFONT_HXX +#define _CPPCANVAS_IMPLFONT_HXX + +#include <com/sun/star/uno/Reference.hxx> + +#ifndef BOOST_SHARED_PTR_HPP_INCLUDED +#include <boost/shared_ptr.hpp> +#endif + +#ifndef _COM_SUN_STAR_RENDERING_XCANVAS_HPP__ +#include <com/sun/star/rendering/XCanvas.hpp> +#endif +#include <cppcanvas/font.hxx> + +namespace rtl +{ + class OUString; +} + +namespace com { namespace sun { namespace star { namespace rendering +{ + class XCanvasFont; +} } } } + +/* Definition of Font class */ + +namespace cppcanvas +{ + + namespace internal + { + + class ImplFont : public Font + { + public: + ImplFont( const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XCanvas >& rCanvas, + const ::rtl::OUString& rFontName, + const double& rCellSize ); + + virtual ~ImplFont(); + + virtual ::rtl::OUString getName() const; + virtual double getCellSize() const; + + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XCanvasFont > getUNOFont() const; + + private: + ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvas > mxCanvas; + ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > mxFont; + }; + } +} + +#endif /* _CPPCANVAS_IMPLFONT_HXX */ diff --git a/cppcanvas/source/wrapper/implpolypolygon.cxx b/cppcanvas/source/wrapper/implpolypolygon.cxx new file mode 100644 index 000000000000..5e7b8c8cf635 --- /dev/null +++ b/cppcanvas/source/wrapper/implpolypolygon.cxx @@ -0,0 +1,201 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppcanvas.hxx" + +#include <rtl/math.hxx> + +#include <com/sun/star/rendering/XCanvas.hpp> +#include <com/sun/star/rendering/PathJoinType.hpp> +#include <com/sun/star/rendering/PathCapType.hpp> + +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/tools/canvastools.hxx> + +#include "implpolypolygon.hxx" +#include "tools.hxx" + + +using namespace ::com::sun::star; + + +namespace cppcanvas +{ + namespace internal + { + ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas, + const uno::Reference< rendering::XPolyPolygon2D >& rPolyPoly ) : + CanvasGraphicHelper( rParentCanvas ), + mxPolyPoly( rPolyPoly ), + maStrokeAttributes(1.0, + 10.0, + uno::Sequence< double >(), + uno::Sequence< double >(), + rendering::PathCapType::ROUND, + rendering::PathCapType::ROUND, + rendering::PathJoinType::ROUND ), + maFillColor(), + maStrokeColor(), + mbFillColorSet( false ), + mbStrokeColorSet( false ) + { + OSL_ENSURE( mxPolyPoly.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" ); + } + + ImplPolyPolygon::~ImplPolyPolygon() + { + } + + void ImplPolyPolygon::addPolygon( const ::basegfx::B2DPolygon& rPoly ) + { + OSL_ENSURE( mxPolyPoly.is(), + "ImplPolyPolygon::addPolygon(): Invalid polygon" ); + + if( !mxPolyPoly.is() ) + return; + + uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() ); + + OSL_ENSURE( xDevice.is(), + "ImplPolyPolygon::addPolygon(): Invalid graphic device" ); + + if( !xDevice.is() ) + return; + + mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0), + ::basegfx::unotools::xPolyPolygonFromB2DPolygon( + xDevice, + rPoly) ); + } + + void ImplPolyPolygon::addPolyPolygon( const ::basegfx::B2DPolyPolygon& rPoly ) + { + OSL_ENSURE( mxPolyPoly.is(), + "ImplPolyPolygon::addPolyPolygon(): Invalid polygon" ); + + if( !mxPolyPoly.is() ) + return; + + uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() ); + + OSL_ENSURE( xDevice.is(), + "ImplPolyPolygon::addPolyPolygon(): Invalid graphic device" ); + + if( !xDevice.is() ) + return; + + mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0), + ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( + xDevice, + rPoly) ); + } + + void ImplPolyPolygon::setRGBAFillColor( Color::IntSRGBA aColor ) + { + maFillColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(), + aColor ); + mbFillColorSet = true; + } + + void ImplPolyPolygon::setRGBALineColor( Color::IntSRGBA aColor ) + { + maStrokeColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(), + aColor ); + mbStrokeColorSet = true; + } + + Color::IntSRGBA ImplPolyPolygon::getRGBAFillColor() const + { + return tools::doubleSequenceToIntSRGBA( getGraphicDevice(), + maFillColor ); + } + + Color::IntSRGBA ImplPolyPolygon::getRGBALineColor() const + { + return tools::doubleSequenceToIntSRGBA( getGraphicDevice(), + maStrokeColor ); + } + + void ImplPolyPolygon::setStrokeWidth( const double& rStrokeWidth ) + { + maStrokeAttributes.StrokeWidth = rStrokeWidth; + } + + double ImplPolyPolygon::getStrokeWidth() const + { + return maStrokeAttributes.StrokeWidth; + } + + bool ImplPolyPolygon::draw() const + { + CanvasSharedPtr pCanvas( getCanvas() ); + + OSL_ENSURE( pCanvas.get() != NULL && + pCanvas->getUNOCanvas().is(), + "ImplBitmap::draw: invalid canvas" ); + + if( pCanvas.get() == NULL || + !pCanvas->getUNOCanvas().is() ) + return false; + + if( mbFillColorSet ) + { + rendering::RenderState aLocalState( getRenderState() ); + aLocalState.DeviceColor = maFillColor; + + pCanvas->getUNOCanvas()->fillPolyPolygon( mxPolyPoly, + pCanvas->getViewState(), + aLocalState ); + } + + if( mbStrokeColorSet ) + { + rendering::RenderState aLocalState( getRenderState() ); + aLocalState.DeviceColor = maStrokeColor; + + if( ::rtl::math::approxEqual(maStrokeAttributes.StrokeWidth, 1.0) ) + pCanvas->getUNOCanvas()->drawPolyPolygon( mxPolyPoly, + pCanvas->getViewState(), + aLocalState ); + else + pCanvas->getUNOCanvas()->strokePolyPolygon( mxPolyPoly, + pCanvas->getViewState(), + aLocalState, + maStrokeAttributes ); + } + + return true; + } + + uno::Reference< rendering::XPolyPolygon2D > ImplPolyPolygon::getUNOPolyPolygon() const + { + return mxPolyPoly; + } + + } +} diff --git a/cppcanvas/source/wrapper/implpolypolygon.hxx b/cppcanvas/source/wrapper/implpolypolygon.hxx new file mode 100644 index 000000000000..bd5e02d6a3de --- /dev/null +++ b/cppcanvas/source/wrapper/implpolypolygon.hxx @@ -0,0 +1,99 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CANVAS_IMPLPOLYPOLYGON_HXX +#define _CANVAS_IMPLPOLYPOLYGON_HXX + +#include <com/sun/star/uno/Reference.hxx> +#ifndef _COM_SUN_STAR_RENDERING_XPOLYPOLYGON2D_HPP__ +#include <com/sun/star/rendering/XPolyPolygon2D.hpp> +#endif +#ifndef _COM_SUN_STAR_RENDERING_XGRAPHICDEVICE_HPP__ +#include <com/sun/star/rendering/XGraphicDevice.hpp> +#endif +#ifndef _COM_SUN_STAR_RENDERING_STROKEATTRIBUTES_HPP__ +#include <com/sun/star/rendering/StrokeAttributes.hpp> +#endif + +#include <cppcanvas/polypolygon.hxx> +#include <canvasgraphichelper.hxx> + +namespace com { namespace sun { namespace star { namespace rendering +{ + struct RealPoint2D; +} } } } + + +namespace cppcanvas +{ + namespace internal + { + + class ImplPolyPolygon : public virtual ::cppcanvas::PolyPolygon, protected CanvasGraphicHelper + { + public: + ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas, + const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XPolyPolygon2D >& rPolyPoly ); + + virtual ~ImplPolyPolygon(); + + virtual void addPolygon( const ::basegfx::B2DPolygon& rPoly ); + virtual void addPolyPolygon( const ::basegfx::B2DPolyPolygon& rPoly ); + + virtual void setRGBAFillColor( Color::IntSRGBA ); + virtual void setRGBALineColor( Color::IntSRGBA ); + virtual Color::IntSRGBA getRGBAFillColor() const; + virtual Color::IntSRGBA getRGBALineColor() const; + + virtual void setStrokeWidth( const double& rStrokeWidth ); + virtual double getStrokeWidth() const; + + virtual bool draw() const; + + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XPolyPolygon2D > getUNOPolyPolygon() const; + + private: + // default: disabled copy/assignment + ImplPolyPolygon(const ImplPolyPolygon&); + ImplPolyPolygon& operator= ( const ImplPolyPolygon& ); + + const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D > mxPolyPoly; + + ::com::sun::star::rendering::StrokeAttributes maStrokeAttributes; + + ::com::sun::star::uno::Sequence< double > maFillColor; + ::com::sun::star::uno::Sequence< double > maStrokeColor; + bool mbFillColorSet; + bool mbStrokeColorSet; + }; + + } +} + +#endif /* _CANVAS_IMPLPOLYPOLYGON_HXX */ diff --git a/cppcanvas/source/wrapper/implsprite.cxx b/cppcanvas/source/wrapper/implsprite.cxx new file mode 100644 index 000000000000..bf8a1a1a67d6 --- /dev/null +++ b/cppcanvas/source/wrapper/implsprite.cxx @@ -0,0 +1,236 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppcanvas.hxx" + +#include <com/sun/star/rendering/XSprite.hpp> +#include <com/sun/star/rendering/XAnimatedSprite.hpp> + +#include <basegfx/tools/canvastools.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <canvas/canvastools.hxx> + +#include "implsprite.hxx" + + +using namespace ::com::sun::star; + +namespace cppcanvas +{ + namespace internal + { + + ImplSprite::ImplSprite( const uno::Reference< rendering::XSpriteCanvas >& rParentCanvas, + const uno::Reference< rendering::XSprite >& rSprite, + const ImplSpriteCanvas::TransformationArbiterSharedPtr& rTransformArbiter ) : + mxGraphicDevice(), + mxSprite( rSprite ), + mxAnimatedSprite(), + mpTransformArbiter( rTransformArbiter ) + { + // Avoiding ternary operator in initializer list (Solaris + // compiler bug, when function call and temporary is + // involved) + if( rParentCanvas.is() ) + mxGraphicDevice = rParentCanvas->getDevice(); + + OSL_ENSURE( rParentCanvas.is() , "ImplSprite::ImplSprite(): Invalid canvas"); + OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::ImplSprite(): Invalid graphic device"); + OSL_ENSURE( mxSprite.is(), "ImplSprite::ImplSprite(): Invalid sprite"); + OSL_ENSURE( mpTransformArbiter.get(), "ImplSprite::ImplSprite(): Invalid transformation arbiter"); + } + + ImplSprite::ImplSprite( const uno::Reference< rendering::XSpriteCanvas >& rParentCanvas, + const uno::Reference< rendering::XAnimatedSprite >& rSprite, + const ImplSpriteCanvas::TransformationArbiterSharedPtr& rTransformArbiter ) : + mxGraphicDevice(), + mxSprite( uno::Reference< rendering::XSprite >(rSprite, + uno::UNO_QUERY) ), + mxAnimatedSprite( rSprite ), + mpTransformArbiter( rTransformArbiter ) + { + // Avoiding ternary operator in initializer list (Solaris + // compiler bug, when function call and temporary is + // involved) + if( rParentCanvas.is() ) + mxGraphicDevice = rParentCanvas->getDevice(); + + OSL_ENSURE( rParentCanvas.is() , "ImplSprite::ImplSprite(): Invalid canvas"); + OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::ImplSprite(): Invalid graphic device"); + OSL_ENSURE( mxSprite.is(), "ImplSprite::ImplSprite(): Invalid sprite"); + OSL_ENSURE( mpTransformArbiter.get(), "ImplSprite::ImplSprite(): Invalid transformation arbiter"); + } + + ImplSprite::~ImplSprite() + { + // hide the sprite on the canvas. If we don't hide the + // sprite, it will stay on the canvas forever, since the + // canvas naturally keeps a list of visible sprites + // (otherwise, it wouldn't be able to paint them + // autonomously) + if( mxSprite.is() ) + mxSprite->hide(); + } + + void ImplSprite::setAlpha( const double& rAlpha ) + { + OSL_ENSURE( mxSprite.is(), "ImplSprite::setAlpha(): Invalid sprite"); + + if( mxSprite.is() ) + mxSprite->setAlpha( rAlpha ); + } + + void ImplSprite::movePixel( const ::basegfx::B2DPoint& rNewPos ) + { + OSL_ENSURE( mxSprite.is(), "ImplSprite::movePixel(): Invalid sprite"); + + if( mxSprite.is() ) + { + rendering::ViewState aViewState; + rendering::RenderState aRenderState; + + ::canvas::tools::initViewState( aViewState ); + ::canvas::tools::initRenderState( aRenderState ); + + mxSprite->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos ), + aViewState, + aRenderState ); + } + } + + void ImplSprite::move( const ::basegfx::B2DPoint& rNewPos ) + { + OSL_ENSURE( mxSprite.is(), "ImplSprite::move(): Invalid sprite"); + + if( mxSprite.is() ) + { + rendering::ViewState aViewState; + rendering::RenderState aRenderState; + + ::canvas::tools::initViewState( aViewState ); + ::canvas::tools::initRenderState( aRenderState ); + + ::canvas::tools::setViewStateTransform( aViewState, + mpTransformArbiter->getTransformation() ); + + mxSprite->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos ), + aViewState, + aRenderState ); + } + } + + void ImplSprite::transform( const ::basegfx::B2DHomMatrix& rMatrix ) + { + OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite"); + + if( mxSprite.is() ) + { + geometry::AffineMatrix2D aMatrix; + + mxSprite->transform( ::basegfx::unotools::affineMatrixFromHomMatrix( aMatrix, + rMatrix ) ); + } + } + + void ImplSprite::setClipPixel( const ::basegfx::B2DPolyPolygon& rClipPoly ) + { + OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas"); + OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite"); + + if( mxSprite.is() && mxGraphicDevice.is() ) + mxSprite->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice, + rClipPoly ) ); + } + + void ImplSprite::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly ) + { + OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas"); + OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite"); + + if( mxSprite.is() && mxGraphicDevice.is() ) + { + ::basegfx::B2DPolyPolygon aTransformedClipPoly( rClipPoly ); + + // extract linear part of canvas view transformation (linear means: + // without translational components) + ::basegfx::B2DHomMatrix aViewTransform( mpTransformArbiter->getTransformation() ); + aViewTransform.set( 0, 2, 0.0 ); + aViewTransform.set( 1, 2, 0.0 ); + + // transform polygon from view to device coordinate space + aTransformedClipPoly.transform( aViewTransform ); + + mxSprite->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice, + aTransformedClipPoly ) ); + } + } + + void ImplSprite::setClip() + { + OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas"); + OSL_ENSURE( mxSprite.is(), "ImplSprite::setClip(): Invalid sprite"); + + if( mxSprite.is() && mxGraphicDevice.is() ) + mxSprite->clip( uno::Reference< rendering::XPolyPolygon2D >() ); + } + + void ImplSprite::show() + { + OSL_ENSURE( mxSprite.is(), "ImplSprite::show(): Invalid sprite"); + + if( mxSprite.is() ) + mxSprite->show(); + } + + void ImplSprite::hide() + { + OSL_ENSURE( mxSprite.is(), "ImplSprite::hide(): Invalid sprite"); + + if( mxSprite.is() ) + mxSprite->hide(); + } + + void ImplSprite::setPriority( double fPriority ) + { + OSL_ENSURE( mxSprite.is(), "ImplSprite::setPriority(): Invalid sprite"); + + if( mxSprite.is() ) + mxSprite->setPriority(fPriority); + } + + uno::Reference< rendering::XSprite > ImplSprite::getUNOSprite() const + { + return mxSprite; + } + + uno::Reference< rendering::XGraphicDevice > ImplSprite::getGraphicDevice() const + { + return mxGraphicDevice; + } + } +} diff --git a/cppcanvas/source/wrapper/implsprite.hxx b/cppcanvas/source/wrapper/implsprite.hxx new file mode 100644 index 000000000000..4f8c5fdcaef6 --- /dev/null +++ b/cppcanvas/source/wrapper/implsprite.hxx @@ -0,0 +1,95 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CPPCANVAS_IMPLSPRITE_HXX +#define _CPPCANVAS_IMPLSPRITE_HXX + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/rendering/XSpriteCanvas.hpp> +#include <com/sun/star/rendering/XSprite.hpp> + +#ifndef BOOST_SHARED_PTR_HPP_INCLUDED +#include <boost/shared_ptr.hpp> +#endif +#include <cppcanvas/sprite.hxx> + +#include <implspritecanvas.hxx> + + +namespace cppcanvas +{ + namespace internal + { + class ImplSprite : public virtual Sprite + { + public: + ImplSprite( const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XSpriteCanvas >& rParentCanvas, + const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XSprite >& rSprite, + const ImplSpriteCanvas::TransformationArbiterSharedPtr& rTransformArbiter ); + ImplSprite( const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XSpriteCanvas >& rParentCanvas, + const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XAnimatedSprite >& rSprite, + const ImplSpriteCanvas::TransformationArbiterSharedPtr& rTransformArbiter ); + virtual ~ImplSprite(); + + virtual void setAlpha( const double& rAlpha ); + virtual void movePixel( const ::basegfx::B2DPoint& rNewPos ); + virtual void move( const ::basegfx::B2DPoint& rNewPos ); + virtual void transform( const ::basegfx::B2DHomMatrix& rMatrix ); + virtual void setClipPixel( const ::basegfx::B2DPolyPolygon& rClipPoly ); + virtual void setClip( const ::basegfx::B2DPolyPolygon& rClipPoly ); + virtual void setClip(); + + virtual void show(); + virtual void hide(); + + virtual void setPriority( double fPriority ); + + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XSprite > getUNOSprite() const; + + ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XGraphicDevice > + getGraphicDevice() const; + + private: + // default: disabled copy/assignment + ImplSprite(const ImplSprite&); + ImplSprite& operator=( const ImplSprite& ); + + ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice > mxGraphicDevice; + const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XSprite > mxSprite; + const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimatedSprite > mxAnimatedSprite; + ImplSpriteCanvas::TransformationArbiterSharedPtr mpTransformArbiter; + }; + } +} + +#endif /* _CPPCANVAS_IMPLSPRITE_HXX */ diff --git a/cppcanvas/source/wrapper/implspritecanvas.cxx b/cppcanvas/source/wrapper/implspritecanvas.cxx new file mode 100644 index 000000000000..4cd555adfb28 --- /dev/null +++ b/cppcanvas/source/wrapper/implspritecanvas.cxx @@ -0,0 +1,159 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppcanvas.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/tools/canvastools.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <com/sun/star/rendering/InterpolationMode.hpp> + +#include <implspritecanvas.hxx> +#include <implcustomsprite.hxx> + + +using namespace ::com::sun::star; + +namespace cppcanvas +{ + namespace internal + { + ImplSpriteCanvas::TransformationArbiter::TransformationArbiter() : + maTransformation() + { + } + + void ImplSpriteCanvas::TransformationArbiter::setTransformation( const ::basegfx::B2DHomMatrix& rViewTransform ) + { + maTransformation = rViewTransform; + } + + ::basegfx::B2DHomMatrix ImplSpriteCanvas::TransformationArbiter::getTransformation() const + { + return maTransformation; + } + + + ImplSpriteCanvas::ImplSpriteCanvas( const uno::Reference< rendering::XSpriteCanvas >& rCanvas ) : + ImplCanvas( uno::Reference< rendering::XCanvas >(rCanvas, + uno::UNO_QUERY) ), + ImplBitmapCanvas( uno::Reference< rendering::XBitmapCanvas >(rCanvas, + uno::UNO_QUERY) ), + mxSpriteCanvas( rCanvas ), + mpTransformArbiter( new TransformationArbiter() ) + { + OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::ImplSpriteCanvas(): Invalid canvas" ); + } + + ImplSpriteCanvas::ImplSpriteCanvas(const ImplSpriteCanvas& rOrig) : + Canvas(), + BitmapCanvas(), + SpriteCanvas(), + ImplCanvas( rOrig ), + ImplBitmapCanvas( rOrig ), + mxSpriteCanvas( rOrig.getUNOSpriteCanvas() ), + mpTransformArbiter( new TransformationArbiter() ) + { + OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::ImplSpriteCanvas( const ImplSpriteCanvas& ): Invalid canvas" ); + + mpTransformArbiter->setTransformation( getTransformation() ); + } + + ImplSpriteCanvas::~ImplSpriteCanvas() + { + } + + void ImplSpriteCanvas::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix ) + { + mpTransformArbiter->setTransformation( rMatrix ); + + ImplCanvas::setTransformation( rMatrix ); + } + + bool ImplSpriteCanvas::updateScreen( bool bUpdateAll ) const + { + OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::updateScreen(): Invalid canvas" ); + + if( !mxSpriteCanvas.is() ) + return false; + + return mxSpriteCanvas->updateScreen( bUpdateAll ); + } + + CustomSpriteSharedPtr ImplSpriteCanvas::createCustomSprite( const ::basegfx::B2DSize& rSize ) const + { + OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::createCustomSprite(): Invalid canvas" ); + + if( !mxSpriteCanvas.is() ) + return CustomSpriteSharedPtr(); + + return CustomSpriteSharedPtr( + new ImplCustomSprite( mxSpriteCanvas, + mxSpriteCanvas->createCustomSprite( ::basegfx::unotools::size2DFromB2DSize(rSize) ), + mpTransformArbiter ) ); + } + + SpriteSharedPtr ImplSpriteCanvas::createClonedSprite( const SpriteSharedPtr& rSprite ) const + { + OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::createCustomSprite(): Invalid canvas" ); + OSL_ENSURE( rSprite.get() != NULL && rSprite->getUNOSprite().is(), + "ImplSpriteCanvas::createCustomSprite(): Invalid sprite" ); + + if( !mxSpriteCanvas.is() || + rSprite.get() == NULL || + !rSprite->getUNOSprite().is() ) + { + return SpriteSharedPtr(); + } + + return SpriteSharedPtr( + new ImplSprite( mxSpriteCanvas, + mxSpriteCanvas->createClonedSprite( rSprite->getUNOSprite() ), + mpTransformArbiter ) ); + } + + SpriteSharedPtr ImplSpriteCanvas::createSpriteFromBitmaps( const uno::Sequence< uno::Reference< rendering::XBitmap > >& rAnimationBitmaps, + sal_Int8 nInterpolationMode ) + { + return SpriteSharedPtr( new internal::ImplSprite( mxSpriteCanvas, + mxSpriteCanvas->createSpriteFromBitmaps( rAnimationBitmaps, + nInterpolationMode ), + mpTransformArbiter ) ); + } + + CanvasSharedPtr ImplSpriteCanvas::clone() const + { + return SpriteCanvasSharedPtr( new ImplSpriteCanvas( *this ) ); + } + + uno::Reference< rendering::XSpriteCanvas > ImplSpriteCanvas::getUNOSpriteCanvas() const + { + return mxSpriteCanvas; + } + + } +} diff --git a/cppcanvas/source/wrapper/implspritecanvas.hxx b/cppcanvas/source/wrapper/implspritecanvas.hxx new file mode 100644 index 000000000000..655bce3c05a2 --- /dev/null +++ b/cppcanvas/source/wrapper/implspritecanvas.hxx @@ -0,0 +1,110 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CPPCANVAS_IMPLSPRITECANVAS_HXX +#define _CPPCANVAS_IMPLSPRITECANVAS_HXX + +#ifndef _COM_SUN_STAR_RENDERING_XSPRITECANVAS_HPP__ +#include <com/sun/star/rendering/XSpriteCanvas.hpp> +#endif +#include <basegfx/vector/b2dsize.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> + +#ifndef BOOST_SHARED_PTR_HPP_INCLUDED +#include <boost/shared_ptr.hpp> +#endif + + +#include <cppcanvas/spritecanvas.hxx> + +#include <implbitmapcanvas.hxx> + + +namespace cppcanvas +{ + namespace internal + { + class ImplSpriteCanvas : public virtual SpriteCanvas, protected virtual ImplBitmapCanvas + { + public: + ImplSpriteCanvas( const ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XSpriteCanvas >& rCanvas ); + ImplSpriteCanvas(const ImplSpriteCanvas&); + + virtual ~ImplSpriteCanvas(); + + virtual void setTransformation( const ::basegfx::B2DHomMatrix& rMatrix ); + + virtual bool updateScreen( bool bUpdateAll ) const; + + virtual CustomSpriteSharedPtr createCustomSprite( const ::basegfx::B2DSize& ) const; + virtual SpriteSharedPtr createClonedSprite( const SpriteSharedPtr& ) const; + + SpriteSharedPtr createSpriteFromBitmaps( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XBitmap > >& animationBitmaps, + sal_Int8 interpolationMode ); + + virtual CanvasSharedPtr clone() const; + + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::rendering::XSpriteCanvas > getUNOSpriteCanvas() const; + + /** This class passes the view transformation + to child sprites + + This helper class is necessary, because the + ImplSpriteCanvas object cannot hand out shared ptrs of + itself, but has somehow pass an object to child + sprites those can query for the canvas' view transform. + */ + class TransformationArbiter + { + public: + TransformationArbiter(); + + void setTransformation( const ::basegfx::B2DHomMatrix& rViewTransform ); + ::basegfx::B2DHomMatrix getTransformation() const; + + private: + ::basegfx::B2DHomMatrix maTransformation; + }; + + typedef ::boost::shared_ptr< TransformationArbiter > TransformationArbiterSharedPtr; + + private: + // default: disabled assignment + ImplSpriteCanvas& operator=( const ImplSpriteCanvas& ); + + const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XSpriteCanvas > mxSpriteCanvas; + TransformationArbiterSharedPtr mpTransformArbiter; + }; + } +} + +#endif /* _CPPCANVAS_IMPLSPRITECANVAS_HXX */ diff --git a/cppcanvas/source/wrapper/impltext.cxx b/cppcanvas/source/wrapper/impltext.cxx new file mode 100644 index 000000000000..7ebb378ea401 --- /dev/null +++ b/cppcanvas/source/wrapper/impltext.cxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppcanvas.hxx" + +#include <impltext.hxx> +#include <canvas/canvastools.hxx> + +#ifndef _COM_SUN_STAR_RENDERING_TEXTDIRECTION_HPP__ +#include <com/sun/star/rendering/TextDirection.hpp> +#endif +#ifndef _COM_SUN_STAR_RENDERING_XCANVAS_HPP__ +#include <com/sun/star/rendering/XCanvas.hpp> +#endif +#ifndef _COM_SUN_STAR_RENDERING_STRINGCONTEXT_HPP__ +#include <com/sun/star/rendering/StringContext.hpp> +#endif +#include <rtl/ustring.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> + + +using namespace ::com::sun::star; + +namespace cppcanvas +{ + namespace internal + { + + ImplText::ImplText( const CanvasSharedPtr& rParentCanvas, + const ::rtl::OUString& rText ) : + CanvasGraphicHelper( rParentCanvas ), + mpFont(), + maText(rText) + { + } + + ImplText::~ImplText() + { + } + + bool ImplText::draw() const + { + CanvasSharedPtr pCanvas( getCanvas() ); + + OSL_ENSURE( pCanvas.get() != NULL && + pCanvas->getUNOCanvas().is(), + "ImplBitmap::draw: invalid canvas" ); + + rendering::StringContext aText; + aText.Text = maText; + aText.StartPosition = 0; + aText.Length = maText.getLength(); + + // TODO(P1): implement caching + // TODO(F2): where to get current BiDi status? + sal_Int8 nBidiOption = rendering::TextDirection::WEAK_LEFT_TO_RIGHT; + pCanvas->getUNOCanvas()->drawText( aText, + mpFont->getUNOFont(), + pCanvas->getViewState(), + getRenderState(), + nBidiOption ); + + return true; + } + + void ImplText::setFont( const FontSharedPtr& rFont ) + { + mpFont = rFont; + } + + FontSharedPtr ImplText::getFont() + { + return mpFont; + } + } +} diff --git a/cppcanvas/source/wrapper/impltext.hxx b/cppcanvas/source/wrapper/impltext.hxx new file mode 100644 index 000000000000..b2c8d9fd0e1f --- /dev/null +++ b/cppcanvas/source/wrapper/impltext.hxx @@ -0,0 +1,78 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CANVAS_IMPLTEXT_HXX +#define _CANVAS_IMPLTEXT_HXX + +#ifndef _COM_SUN_STAR_RENDERING_RENDERSTATE_HPP__ +#include <com/sun/star/rendering/RenderState.hpp> +#endif +#ifndef _COM_SUN_STAR_RENDERING_STRINGCONTEXT_HPP__ +#include <com/sun/star/rendering/StringContext.hpp> +#endif +#ifndef _COM_SUN_STAR_RENDERING_XCANVAS_HPP__ +#include <com/sun/star/rendering/XCanvas.hpp> +#endif +#ifndef _COM_SUN_STAR_RENDERING_XCANVASFONT_HPP__ +#include <com/sun/star/rendering/XCanvasFont.hpp> +#endif + +#include <cppcanvas/text.hxx> +#include <canvasgraphichelper.hxx> + + +namespace cppcanvas +{ + namespace internal + { + + class ImplText : public virtual ::cppcanvas::Text, protected CanvasGraphicHelper + { + public: + + ImplText( const CanvasSharedPtr& rParentCanvas, + const ::rtl::OUString& rText ); + + virtual ~ImplText(); + + virtual bool draw() const; + + virtual void setFont( const FontSharedPtr& ); + virtual FontSharedPtr getFont(); + + private: + // default: disabled copy/assignment + ImplText(const ImplText&); + ImplText& operator= ( const ImplText& ); + + FontSharedPtr mpFont; + ::rtl::OUString maText; + }; + } +} + +#endif /* _CANVAS_IMPLTEXT_HXX */ diff --git a/cppcanvas/source/wrapper/makefile.mk b/cppcanvas/source/wrapper/makefile.mk new file mode 100644 index 000000000000..255cc023d75c --- /dev/null +++ b/cppcanvas/source/wrapper/makefile.mk @@ -0,0 +1,60 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=cppcanvas +TARGET=canvaswrapper +ENABLE_EXCEPTIONS=TRUE + + +# --- Settings ----------------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Common ---------------------------------------------------------- + +.IF "$(verbose)"!="" || "$(VERBOSE)"!="" +CDEFS+= -DVERBOSE +.ENDIF + +SLOFILES = $(SLO)$/implbitmap.obj \ + $(SLO)$/implcanvas.obj \ + $(SLO)$/implcolor.obj \ + $(SLO)$/implfont.obj \ + $(SLO)$/vclfactory.obj \ + $(SLO)$/basegfxfactory.obj \ + $(SLO)$/impltext.obj \ + $(SLO)$/implpolypolygon.obj \ + $(SLO)$/implbitmapcanvas.obj \ + $(SLO)$/implspritecanvas.obj \ + $(SLO)$/implsprite.obj \ + $(SLO)$/implcustomsprite.obj + +# ========================================================================== + +.INCLUDE : target.mk diff --git a/cppcanvas/source/wrapper/vclfactory.cxx b/cppcanvas/source/wrapper/vclfactory.cxx new file mode 100644 index 000000000000..7983f081b2a9 --- /dev/null +++ b/cppcanvas/source/wrapper/vclfactory.cxx @@ -0,0 +1,363 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppcanvas.hxx" +#include <rtl/instance.hxx> +#include <osl/getglobalmutex.hxx> +#include <osl/diagnose.h> +#include <com/sun/star/rendering/InterpolationMode.hpp> +#include <vcl/window.hxx> +#include <vcl/graph.hxx> +#include <vcl/canvastools.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> + +#include <cppcanvas/vclfactory.hxx> + +#include <implbitmapcanvas.hxx> +#include <implspritecanvas.hxx> +#include <implpolypolygon.hxx> +#include <implbitmap.hxx> +#include <implrenderer.hxx> +#include <impltext.hxx> +#include <implsprite.hxx> + + +using namespace ::com::sun::star; + +namespace cppcanvas +{ + /* Singleton handling */ + struct InitInstance + { + VCLFactory* operator()() + { + return new VCLFactory(); + } + }; + + VCLFactory& VCLFactory::getInstance() + { + return *rtl_Instance< VCLFactory, InitInstance, ::osl::MutexGuard, + ::osl::GetGlobalMutex >::create( + InitInstance(), ::osl::GetGlobalMutex()); + } + + VCLFactory::VCLFactory() + { + } + + VCLFactory::~VCLFactory() + { + } + + BitmapCanvasSharedPtr VCLFactory::createCanvas( const ::Window& rVCLWindow ) + { + return BitmapCanvasSharedPtr( + new internal::ImplBitmapCanvas( + uno::Reference< rendering::XBitmapCanvas >( + rVCLWindow.GetCanvas(), + uno::UNO_QUERY) ) ); + } + + BitmapCanvasSharedPtr VCLFactory::createCanvas( const uno::Reference< rendering::XBitmapCanvas >& xCanvas ) + { + return BitmapCanvasSharedPtr( + new internal::ImplBitmapCanvas( xCanvas ) ); + } + + SpriteCanvasSharedPtr VCLFactory::createSpriteCanvas( const ::Window& rVCLWindow ) const + { + return SpriteCanvasSharedPtr( + new internal::ImplSpriteCanvas( + uno::Reference< rendering::XSpriteCanvas >( + rVCLWindow.GetSpriteCanvas(), + uno::UNO_QUERY) ) ); + } + + SpriteCanvasSharedPtr VCLFactory::createSpriteCanvas( const uno::Reference< rendering::XSpriteCanvas >& xCanvas ) const + { + return SpriteCanvasSharedPtr( + new internal::ImplSpriteCanvas( xCanvas ) ); + } + + SpriteCanvasSharedPtr VCLFactory::createFullscreenSpriteCanvas( const ::Window& rVCLWindow, + const Size& rFullscreenSize ) const + { + return SpriteCanvasSharedPtr( + new internal::ImplSpriteCanvas( + uno::Reference< rendering::XSpriteCanvas >( + rVCLWindow.GetFullscreenSpriteCanvas( rFullscreenSize ), + uno::UNO_QUERY) ) ); + } + + PolyPolygonSharedPtr VCLFactory::createPolyPolygon( const CanvasSharedPtr& rCanvas, + const ::Polygon& rPoly ) const + { + OSL_ENSURE( rCanvas.get() != NULL && + rCanvas->getUNOCanvas().is(), + "VCLFactory::createPolyPolygon(): Invalid canvas" ); + + if( rCanvas.get() == NULL ) + return PolyPolygonSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return PolyPolygonSharedPtr(); + + return PolyPolygonSharedPtr( + new internal::ImplPolyPolygon( rCanvas, + ::vcl::unotools::xPolyPolygonFromPolygon( + xCanvas->getDevice(), + rPoly) ) ); + } + + PolyPolygonSharedPtr VCLFactory::createPolyPolygon( const CanvasSharedPtr& rCanvas, + const ::PolyPolygon& rPolyPoly ) const + { + OSL_ENSURE( rCanvas.get() != NULL && + rCanvas->getUNOCanvas().is(), + "VCLFactory::createPolyPolygon(): Invalid canvas" ); + + if( rCanvas.get() == NULL ) + return PolyPolygonSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return PolyPolygonSharedPtr(); + + return PolyPolygonSharedPtr( + new internal::ImplPolyPolygon( rCanvas, + ::vcl::unotools::xPolyPolygonFromPolyPolygon( + xCanvas->getDevice(), + rPolyPoly) ) ); + } + + BitmapSharedPtr VCLFactory::createBitmap( const CanvasSharedPtr& rCanvas, + const ::Size& rSize ) const + { + OSL_ENSURE( rCanvas.get() != NULL && + rCanvas->getUNOCanvas().is(), + "VCLFactory::createBitmap(): Invalid canvas" ); + + if( rCanvas.get() == NULL ) + return BitmapSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return BitmapSharedPtr(); + + return BitmapSharedPtr( + new internal::ImplBitmap( rCanvas, + xCanvas->getDevice()->createCompatibleBitmap( + ::vcl::unotools::integerSize2DFromSize(rSize) ) ) ); + } + + BitmapSharedPtr VCLFactory::createAlphaBitmap( const CanvasSharedPtr& rCanvas, + const ::Size& rSize ) const + { + OSL_ENSURE( rCanvas.get() != NULL && + rCanvas->getUNOCanvas().is(), + "VCLFactory::createBitmap(): Invalid canvas" ); + + if( rCanvas.get() == NULL ) + return BitmapSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return BitmapSharedPtr(); + + return BitmapSharedPtr( + new internal::ImplBitmap( rCanvas, + xCanvas->getDevice()->createCompatibleAlphaBitmap( + ::vcl::unotools::integerSize2DFromSize(rSize) ) ) ); + } + + BitmapSharedPtr VCLFactory::createBitmap( const CanvasSharedPtr& rCanvas, + const ::Bitmap& rBitmap ) const + { + OSL_ENSURE( rCanvas.get() != NULL && + rCanvas->getUNOCanvas().is(), + "VCLFactory::createBitmap(): Invalid canvas" ); + + if( rCanvas.get() == NULL ) + return BitmapSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return BitmapSharedPtr(); + + return BitmapSharedPtr( new internal::ImplBitmap( rCanvas, + ::vcl::unotools::xBitmapFromBitmap( + xCanvas->getDevice(), + rBitmap) ) ); + } + + BitmapSharedPtr VCLFactory::createBitmap( const CanvasSharedPtr& rCanvas, + const ::BitmapEx& rBmpEx ) const + { + OSL_ENSURE( rCanvas.get() != NULL && + rCanvas->getUNOCanvas().is(), + "VCLFactory::createBitmap(): Invalid canvas" ); + + if( rCanvas.get() == NULL ) + return BitmapSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return BitmapSharedPtr(); + + return BitmapSharedPtr( new internal::ImplBitmap( rCanvas, + ::vcl::unotools::xBitmapFromBitmapEx( + xCanvas->getDevice(), + rBmpEx) ) ); + } + + RendererSharedPtr VCLFactory::createRenderer( const CanvasSharedPtr& rCanvas, + const ::Graphic& rGraphic, + const Renderer::Parameters& rParms ) const + { + OSL_ENSURE( rCanvas.get() != NULL && + rCanvas->getUNOCanvas().is(), + "VCLFactory::createRenderer(): Invalid canvas" ); + + if( rCanvas.get() == NULL ) + return RendererSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return RendererSharedPtr(); + + if( rGraphic.GetType() == GRAPHIC_GDIMETAFILE ) + return RendererSharedPtr( new internal::ImplRenderer( rCanvas, + rGraphic.GetGDIMetaFile(), + rParms ) ); + else + return RendererSharedPtr( new internal::ImplRenderer( rCanvas, + rGraphic.GetBitmapEx(), + rParms ) ); + } + + RendererSharedPtr VCLFactory::createRenderer( const CanvasSharedPtr& rCanvas, + const ::GDIMetaFile& rMtf, + const Renderer::Parameters& rParms ) const + { + return RendererSharedPtr( new internal::ImplRenderer( rCanvas, + rMtf, + rParms ) ); + } + + SpriteSharedPtr VCLFactory::createAnimatedSprite( const SpriteCanvasSharedPtr& rCanvas, const ::Animation& rAnim ) const + { + OSL_ENSURE( rCanvas.get() != NULL && + rCanvas->getUNOCanvas().is(), + "VCLFactory::createAnimatedSprite(): Invalid canvas" ); + + if( rCanvas.get() == NULL ) + return SpriteSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return SpriteSharedPtr(); + + uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( rCanvas->getUNOSpriteCanvas() ); + if( !xSpriteCanvas.is() ) + return SpriteSharedPtr(); + + if( rAnim.IsEmpty() ) + return SpriteSharedPtr(); + + internal::ImplSpriteCanvas* pSpriteCanvas = dynamic_cast< internal::ImplSpriteCanvas* >( rCanvas.get() ); + if( !pSpriteCanvas ) + return SpriteSharedPtr(); + + const USHORT nBitmaps( rAnim.Count() ); + uno::Sequence< uno::Reference< rendering::XBitmap > > aBitmapSequence( nBitmaps ); + uno::Reference< rendering::XBitmap >* pBitmaps = aBitmapSequence.getArray(); + + unsigned int i; + BitmapEx aBmpEx; + BitmapEx aRestoreBuffer; + aBmpEx.SetSizePixel( rAnim.GetDisplaySizePixel() ); + aRestoreBuffer.SetSizePixel( rAnim.GetDisplaySizePixel() ); + aBmpEx.Erase( ::Color( 255, 0,0,0 ) ); // clear alpha channel + aRestoreBuffer = aBmpEx; + const Point aEmptyPoint; + + for( i=0; i<nBitmaps; ++i ) + { + const AnimationBitmap& rAnimBmp( rAnim.Get((USHORT)i) ); + + // Handle dispose according to GIF spec: a + // DISPOSE_PREVIOUS does _not_ mean to revert to the + // previous frame, but to revert to the last frame with + // DISPOSE_NOT + + // dispose previous + if( rAnimBmp.eDisposal == DISPOSE_BACK ) + { + // simply clear bitmap to transparent + aBmpEx.Erase( ::Color( 255, 0,0,0 ) ); + } + else if( rAnimBmp.eDisposal == DISPOSE_PREVIOUS ) + { + // copy in last known full frame + aBmpEx = aRestoreBuffer; + } + // I have exactly _no_ idea what DISPOSE_FULL is supposed + // to do. It's apparently not set anywhere in our code + OSL_ENSURE( rAnimBmp.eDisposal!=DISPOSE_FULL, + "VCLFactory::createAnimatedSprite(): Somebody set the deprecated DISPOSE_FULL at the Animation" ); + + // update display + aBmpEx.CopyPixel( Rectangle( rAnimBmp.aPosPix, + rAnimBmp.aSizePix ), + Rectangle( aEmptyPoint, + rAnimBmp.aSizePix ), + &rAnimBmp.aBmpEx ); + + // store last DISPOSE_NOT frame, for later + // DISPOSE_PREVIOUS updates + if( rAnimBmp.eDisposal == DISPOSE_NOT ) + aRestoreBuffer = aBmpEx; + + pBitmaps[i] = ::vcl::unotools::xBitmapFromBitmapEx( + xCanvas->getDevice(), + aBmpEx); + } + + return pSpriteCanvas->createSpriteFromBitmaps( aBitmapSequence, + rendering::InterpolationMode::NEAREST_NEIGHBOR ); + } + + TextSharedPtr VCLFactory::createText( const CanvasSharedPtr& rCanvas, const ::rtl::OUString& rText ) const + { + return TextSharedPtr( new internal::ImplText( rCanvas, + rText ) ); + } + +} |