diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /cppcanvas/source/wrapper | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | cppcanvas/source/wrapper/basegfxfactory.cxx | 94 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implbitmap.cxx | 107 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implbitmap.hxx | 62 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implbitmapcanvas.cxx | 57 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implbitmapcanvas.hxx | 53 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implcanvas.cxx | 115 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implcanvas.hxx | 82 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implcustomsprite.cxx | 69 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implcustomsprite.hxx | 51 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implpolypolygon.cxx | 133 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implpolypolygon.hxx | 75 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implsprite.cxx | 190 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implsprite.hxx | 63 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implspritecanvas.cxx | 108 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/implspritecanvas.hxx | 80 | ||||
-rw-r--r-- | cppcanvas/source/wrapper/vclfactory.cxx | 83 |
16 files changed, 1422 insertions, 0 deletions
diff --git a/cppcanvas/source/wrapper/basegfxfactory.cxx b/cppcanvas/source/wrapper/basegfxfactory.cxx new file mode 100644 index 000000000..5b06bcfd9 --- /dev/null +++ b/cppcanvas/source/wrapper/basegfxfactory.cxx @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <osl/diagnose.h> + +#include <basegfx/polygon/b2dpolygon.hxx> +#include <basegfx/utils/canvastools.hxx> + +#include <cppcanvas/basegfxfactory.hxx> + +#include <com/sun/star/rendering/XCanvas.hpp> + +#include "implpolypolygon.hxx" +#include "implbitmap.hxx" + +using namespace ::com::sun::star; + +namespace cppcanvas +{ + PolyPolygonSharedPtr BaseGfxFactory::createPolyPolygon( const CanvasSharedPtr& rCanvas, + const ::basegfx::B2DPolygon& rPoly ) + { + OSL_ENSURE( rCanvas && rCanvas->getUNOCanvas().is(), + "BaseGfxFactory::createPolyPolygon(): Invalid canvas" ); + + if( !rCanvas ) + return PolyPolygonSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return PolyPolygonSharedPtr(); + + return std::make_shared<internal::ImplPolyPolygon>( rCanvas, + ::basegfx::unotools::xPolyPolygonFromB2DPolygon( + xCanvas->getDevice(), + rPoly) ); + } + + BitmapSharedPtr BaseGfxFactory::createBitmap( const CanvasSharedPtr& rCanvas, + const ::basegfx::B2ISize& rSize ) + { + OSL_ENSURE( rCanvas && rCanvas->getUNOCanvas().is(), + "BaseGfxFactory::createBitmap(): Invalid canvas" ); + + if( !rCanvas ) + return BitmapSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return BitmapSharedPtr(); + + return std::make_shared<internal::ImplBitmap>( rCanvas, + xCanvas->getDevice()->createCompatibleBitmap( + ::basegfx::unotools::integerSize2DFromB2ISize(rSize) ) ); + } + + BitmapSharedPtr BaseGfxFactory::createAlphaBitmap( const CanvasSharedPtr& rCanvas, + const ::basegfx::B2ISize& rSize ) + { + OSL_ENSURE( rCanvas && rCanvas->getUNOCanvas().is(), + "BaseGfxFactory::createBitmap(): Invalid canvas" ); + + if( !rCanvas ) + return BitmapSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return BitmapSharedPtr(); + + return std::make_shared<internal::ImplBitmap>( rCanvas, + xCanvas->getDevice()->createCompatibleAlphaBitmap( + ::basegfx::unotools::integerSize2DFromB2ISize(rSize) ) ); + } + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implbitmap.cxx b/cppcanvas/source/wrapper/implbitmap.cxx new file mode 100644 index 000000000..4b46ecb65 --- /dev/null +++ b/cppcanvas/source/wrapper/implbitmap.cxx @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include "implbitmap.hxx" +#include "implbitmapcanvas.hxx" + +#include <osl/diagnose.h> + + +using namespace ::com::sun::star; + +namespace cppcanvas::internal +{ + + ImplBitmap::ImplBitmap( const CanvasSharedPtr& rParentCanvas, + const uno::Reference< rendering::XBitmap >& rBitmap ) : + CanvasGraphicHelper( rParentCanvas ), + mxBitmap( rBitmap ) + { + OSL_ENSURE( mxBitmap.is(), "ImplBitmap::ImplBitmap: no valid bitmap" ); + + uno::Reference< rendering::XBitmapCanvas > xBitmapCanvas( rBitmap, + uno::UNO_QUERY ); + if( xBitmapCanvas.is() ) + mpBitmapCanvas = std::make_shared<ImplBitmapCanvas>( + uno::Reference< rendering::XBitmapCanvas >(rBitmap, + uno::UNO_QUERY) ); + } + + ImplBitmap::~ImplBitmap() + { + } + + bool ImplBitmap::draw() const + { + CanvasSharedPtr pCanvas( getCanvas() ); + + OSL_ENSURE( pCanvas && pCanvas->getUNOCanvas().is(), + "ImplBitmap::draw: invalid canvas" ); + + if( !pCanvas || + !pCanvas->getUNOCanvas().is() ) + { + return false; + } + + // TODO(P1): implement caching + pCanvas->getUNOCanvas()->drawBitmap( mxBitmap, + pCanvas->getViewState(), + getRenderState() ); + + return true; + } + + void ImplBitmap::drawAlphaModulated( double nAlphaModulation ) const + { + CanvasSharedPtr pCanvas( getCanvas() ); + + OSL_ENSURE( pCanvas && pCanvas->getUNOCanvas().is(), + "ImplBitmap::drawAlphaModulated(): invalid canvas" ); + + if( !pCanvas || + !pCanvas->getUNOCanvas().is() ) + { + return; + } + + rendering::RenderState aLocalState( getRenderState() ); + uno::Sequence<rendering::ARGBColor> aCol { { 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 ); + } + + BitmapCanvasSharedPtr ImplBitmap::getBitmapCanvas() const + { + return mpBitmapCanvas; + } + + uno::Reference< rendering::XBitmap > ImplBitmap::getUNOBitmap() const + { + return mxBitmap; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implbitmap.hxx b/cppcanvas/source/wrapper/implbitmap.hxx new file mode 100644 index 000000000..1b6066949 --- /dev/null +++ b/cppcanvas/source/wrapper/implbitmap.hxx @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/rendering/XBitmap.hpp> + +#include <cppcanvas/bitmap.hxx> +#include <canvasgraphichelper.hxx> + + +/*Definition of ImplBitmap */ + +namespace cppcanvas::internal +{ + // share partial CanvasGraphic implementation from CanvasGraphicHelper + class ImplBitmap : public virtual ::cppcanvas::Bitmap, protected CanvasGraphicHelper + { + public: + + ImplBitmap( const CanvasSharedPtr& rParentCanvas, + const css::uno::Reference< css::rendering::XBitmap >& rBitmap ); + + virtual ~ImplBitmap() override; + + // CanvasGraphic implementation (that was not already implemented by CanvasGraphicHelper) + virtual bool draw() const override; + virtual void drawAlphaModulated( double nAlphaModulation ) const override; + + virtual BitmapCanvasSharedPtr getBitmapCanvas() const override; + + // Bitmap implementation + virtual css::uno::Reference< css::rendering::XBitmap > getUNOBitmap() const override; + + private: + ImplBitmap(const ImplBitmap&) = delete; + ImplBitmap& operator=( const ImplBitmap& ) = delete; + + const css::uno::Reference< css::rendering::XBitmap > mxBitmap; + BitmapCanvasSharedPtr mpBitmapCanvas; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implbitmapcanvas.cxx b/cppcanvas/source/wrapper/implbitmapcanvas.cxx new file mode 100644 index 000000000..883ebb005 --- /dev/null +++ b/cppcanvas/source/wrapper/implbitmapcanvas.cxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <basegfx/utils/canvastools.hxx> +#include <osl/diagnose.h> + +#include "implbitmapcanvas.hxx" + + +using namespace ::com::sun::star; + +namespace cppcanvas::internal +{ + ImplBitmapCanvas::ImplBitmapCanvas( const uno::Reference< rendering::XBitmapCanvas >& rCanvas ) : + ImplCanvas( rCanvas ), + 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 std::make_shared<ImplBitmapCanvas>( *this ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implbitmapcanvas.hxx b/cppcanvas/source/wrapper/implbitmapcanvas.hxx new file mode 100644 index 000000000..62db8cc60 --- /dev/null +++ b/cppcanvas/source/wrapper/implbitmapcanvas.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/rendering/XBitmapCanvas.hpp> +#include <com/sun/star/rendering/XBitmap.hpp> +#include <cppcanvas/bitmapcanvas.hxx> + +#include "implcanvas.hxx" + + +namespace cppcanvas::internal +{ + // share Canvas implementation from ImplCanvas + class ImplBitmapCanvas : public virtual BitmapCanvas, protected virtual ImplCanvas + { + public: + explicit ImplBitmapCanvas( const css::uno::Reference< css::rendering::XBitmapCanvas >& rCanvas ); + virtual ~ImplBitmapCanvas() override; + + ImplBitmapCanvas(ImplBitmapCanvas const &) = default; + ImplBitmapCanvas(ImplBitmapCanvas &&) = default; + ImplBitmapCanvas & operator =(ImplBitmapCanvas const &) = delete; // due to const mxBitmapCanvas + ImplBitmapCanvas & operator =(ImplBitmapCanvas &&) = delete; // due to const mxBitmapCanvas + + virtual ::basegfx::B2ISize getSize() const override; + + virtual CanvasSharedPtr clone() const override; + + private: + const css::uno::Reference< css::rendering::XBitmapCanvas > mxBitmapCanvas; + const css::uno::Reference< css::rendering::XBitmap > mxBitmap; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implcanvas.cxx b/cppcanvas/source/wrapper/implcanvas.cxx new file mode 100644 index 000000000..8a412e805 --- /dev/null +++ b/cppcanvas/source/wrapper/implcanvas.cxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/utils/canvastools.hxx> + +#include <com/sun/star/rendering/XCanvas.hpp> + +#include <canvas/canvastools.hxx> +#include <utility> + +#include "implcanvas.hxx" + + +using namespace ::com::sun::star; + +namespace cppcanvas::internal +{ + + ImplCanvas::ImplCanvas( uno::Reference< rendering::XCanvas > xCanvas ) : + mxCanvas(std::move( 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 = rClipPoly; + maViewState.Clip.clear(); + } + + void ImplCanvas::setClip() + { + maClipPolyPolygon.reset(); + maViewState.Clip.clear(); + } + + ::basegfx::B2DPolyPolygon const* ImplCanvas::getClip() const + { + return !maClipPolyPolygon ? nullptr : &(*maClipPolyPolygon); + } + + CanvasSharedPtr ImplCanvas::clone() const + { + return std::make_shared<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; + } + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implcanvas.hxx b/cppcanvas/source/wrapper/implcanvas.hxx new file mode 100644 index 000000000..cc49c819e --- /dev/null +++ b/cppcanvas/source/wrapper/implcanvas.hxx @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/rendering/ViewState.hpp> +#include <cppcanvas/canvas.hxx> + +#include <optional> +#include <basegfx/polygon/b2dpolypolygon.hxx> + + +namespace basegfx +{ + class B2DHomMatrix; + class B2DPolyPolygon; +} + +namespace com::sun::star::rendering +{ + class XCanvas; +} + + +/* Definition of ImplCanvas */ + +namespace cppcanvas::internal +{ + + class ImplCanvas : public virtual Canvas + { + public: + explicit ImplCanvas( css::uno::Reference< css::rendering::XCanvas > xCanvas ); + virtual ~ImplCanvas() override; + + ImplCanvas(ImplCanvas const &) = default; + ImplCanvas(ImplCanvas &&) = default; + ImplCanvas & operator =(ImplCanvas const &) = delete; // due to const mxCanvas + ImplCanvas & operator =(ImplCanvas &&) = delete; // due to const mxCanvas + + virtual void setTransformation( const ::basegfx::B2DHomMatrix& rMatrix ) override; + virtual ::basegfx::B2DHomMatrix getTransformation() const override; + + virtual void setClip( const ::basegfx::B2DPolyPolygon& rClipPoly ) override; + virtual void setClip() override; + virtual ::basegfx::B2DPolyPolygon const* getClip() const override; + + virtual CanvasSharedPtr clone() const override; + + virtual void clear() const override; + + virtual css::uno::Reference< + css::rendering::XCanvas > getUNOCanvas() const override; + + virtual css::rendering::ViewState getViewState() const override; + + private: + mutable css::rendering::ViewState maViewState; + std::optional<basegfx::B2DPolyPolygon> maClipPolyPolygon; + const css::uno::Reference< css::rendering::XCanvas > mxCanvas; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implcustomsprite.cxx b/cppcanvas/source/wrapper/implcustomsprite.cxx new file mode 100644 index 000000000..f6af05cf9 --- /dev/null +++ b/cppcanvas/source/wrapper/implcustomsprite.cxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <osl/diagnose.h> + +#include "implcustomsprite.hxx" +#include "implcanvas.hxx" + +using namespace ::com::sun::star; + +namespace cppcanvas::internal +{ + ImplCustomSprite::ImplCustomSprite( const uno::Reference< rendering::XSpriteCanvas >& rParentCanvas, + const uno::Reference< rendering::XCustomSprite >& rSprite, + const ImplSpriteCanvas::TransformationArbiterSharedPtr& rTransformArbiter ) : + ImplSprite( rParentCanvas, + rSprite, + rTransformArbiter ), + 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 || + mpLastCanvas->getUNOCanvas() != xCanvas ) + { + mpLastCanvas = std::make_shared<ImplCanvas>( xCanvas ); + } + + return mpLastCanvas; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implcustomsprite.hxx b/cppcanvas/source/wrapper/implcustomsprite.hxx new file mode 100644 index 000000000..7c698ac5b --- /dev/null +++ b/cppcanvas/source/wrapper/implcustomsprite.hxx @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <cppcanvas/canvas.hxx> +#include <cppcanvas/customsprite.hxx> +#include "implsprite.hxx" +#include "implspritecanvas.hxx" + +namespace cppcanvas::internal +{ + // share Sprite implementation of ImplSprite + class ImplCustomSprite : public virtual CustomSprite, protected virtual ImplSprite + { + public: + ImplCustomSprite( const css::uno::Reference< + css::rendering::XSpriteCanvas >& rParentCanvas, + const css::uno::Reference< + css::rendering::XCustomSprite >& rSprite, + const ImplSpriteCanvas::TransformationArbiterSharedPtr& rTransformArbiter ); + virtual ~ImplCustomSprite() override; + + virtual CanvasSharedPtr getContentCanvas() const override; + + private: + ImplCustomSprite(const ImplCustomSprite&) = delete; + ImplCustomSprite& operator=( const ImplCustomSprite& ) = delete; + + mutable CanvasSharedPtr mpLastCanvas; + const css::uno::Reference< css::rendering::XCustomSprite > mxCustomSprite; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implpolypolygon.cxx b/cppcanvas/source/wrapper/implpolypolygon.cxx new file mode 100644 index 000000000..536bfa60a --- /dev/null +++ b/cppcanvas/source/wrapper/implpolypolygon.cxx @@ -0,0 +1,133 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <rtl/math.hxx> +#include <osl/diagnose.h> + +#include <com/sun/star/rendering/XCanvas.hpp> +#include <com/sun/star/rendering/PathJoinType.hpp> +#include <com/sun/star/rendering/PathCapType.hpp> + +#include "implpolypolygon.hxx" +#include <tools.hxx> +#include <utility> + + +using namespace ::com::sun::star; + + +namespace cppcanvas::internal +{ + ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas, + uno::Reference< rendering::XPolyPolygon2D > xPolyPoly ) : + CanvasGraphicHelper( rParentCanvas ), + mxPolyPoly(std::move( xPolyPoly )), + maStrokeAttributes(1.0, + 10.0, + uno::Sequence< double >(), + uno::Sequence< double >(), + rendering::PathCapType::ROUND, + rendering::PathCapType::ROUND, + rendering::PathJoinType::ROUND ), + mbFillColorSet( false ), + mbStrokeColorSet( false ) + { + OSL_ENSURE( mxPolyPoly.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" ); + } + + ImplPolyPolygon::~ImplPolyPolygon() + { + } + + void ImplPolyPolygon::setRGBAFillColor( IntSRGBA aColor ) + { + maFillColor = tools::intSRGBAToDoubleSequence( aColor ); + mbFillColorSet = true; + } + + void ImplPolyPolygon::setRGBALineColor( IntSRGBA aColor ) + { + maStrokeColor = tools::intSRGBAToDoubleSequence( aColor ); + mbStrokeColorSet = true; + } + + IntSRGBA ImplPolyPolygon::getRGBALineColor() const + { + return tools::doubleSequenceToIntSRGBA( 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 && pCanvas->getUNOCanvas().is(), + "ImplBitmap::draw: invalid canvas" ); + + if( !pCanvas || + !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; + } + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implpolypolygon.hxx b/cppcanvas/source/wrapper/implpolypolygon.hxx new file mode 100644 index 000000000..a756b4400 --- /dev/null +++ b/cppcanvas/source/wrapper/implpolypolygon.hxx @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/rendering/XPolyPolygon2D.hpp> +#include <com/sun/star/rendering/StrokeAttributes.hpp> + +#include <cppcanvas/polypolygon.hxx> +#include <canvasgraphichelper.hxx> + +namespace com::sun::star::rendering +{ + struct RealPoint2D; +} + + +namespace cppcanvas::internal +{ + + class ImplPolyPolygon : public virtual ::cppcanvas::PolyPolygon, protected CanvasGraphicHelper + { + public: + ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas, + css::uno::Reference< + css::rendering::XPolyPolygon2D > xPolyPoly ); + + virtual ~ImplPolyPolygon() override; + + virtual void setRGBAFillColor( IntSRGBA ) override; + virtual void setRGBALineColor( IntSRGBA ) override; + virtual IntSRGBA getRGBALineColor() const override; + + virtual void setStrokeWidth( const double& rStrokeWidth ) override; + virtual double getStrokeWidth() const override; + + virtual bool draw() const override; + + virtual css::uno::Reference< + css::rendering::XPolyPolygon2D > getUNOPolyPolygon() const override; + + private: + ImplPolyPolygon(const ImplPolyPolygon&) = delete; + ImplPolyPolygon& operator= ( const ImplPolyPolygon& ) = delete; + + const css::uno::Reference< css::rendering::XPolyPolygon2D > mxPolyPoly; + + css::rendering::StrokeAttributes maStrokeAttributes; + + css::uno::Sequence< double > maFillColor; + css::uno::Sequence< double > maStrokeColor; + bool mbFillColorSet; + bool mbStrokeColorSet; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implsprite.cxx b/cppcanvas/source/wrapper/implsprite.cxx new file mode 100644 index 000000000..66434f941 --- /dev/null +++ b/cppcanvas/source/wrapper/implsprite.cxx @@ -0,0 +1,190 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <basegfx/utils/canvastools.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <canvas/canvastools.hxx> +#include <utility> + +#include "implsprite.hxx" + + +using namespace ::com::sun::star; + +namespace cppcanvas::internal +{ + + ImplSprite::ImplSprite( const uno::Reference< rendering::XSpriteCanvas >& rParentCanvas, + uno::Reference< rendering::XSprite > rSprite, + ImplSpriteCanvas::TransformationArbiterSharedPtr xTransformArbiter ) : + mxSprite(std::move( rSprite )), + mpTransformArbiter(std::move( xTransformArbiter )) + { + // 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, "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() ) + return; + + 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()) ) + return; + + ::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); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implsprite.hxx b/cppcanvas/source/wrapper/implsprite.hxx new file mode 100644 index 000000000..d40fb0574 --- /dev/null +++ b/cppcanvas/source/wrapper/implsprite.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/rendering/XSpriteCanvas.hpp> +#include <com/sun/star/rendering/XSprite.hpp> +#include <cppcanvas/sprite.hxx> +#include "implspritecanvas.hxx" + +namespace cppcanvas::internal +{ + class ImplSprite : public virtual Sprite + { + public: + ImplSprite( const css::uno::Reference< + css::rendering::XSpriteCanvas >& rParentCanvas, + css::uno::Reference< + css::rendering::XSprite > xSprite, + ImplSpriteCanvas::TransformationArbiterSharedPtr xTransformArbiter ); + virtual ~ImplSprite() override; + + virtual void setAlpha( const double& rAlpha ) override; + virtual void movePixel( const ::basegfx::B2DPoint& rNewPos ) override; + virtual void move( const ::basegfx::B2DPoint& rNewPos ) override; + virtual void transform( const ::basegfx::B2DHomMatrix& rMatrix ) override; + virtual void setClipPixel( const ::basegfx::B2DPolyPolygon& rClipPoly ) override; + virtual void setClip( const ::basegfx::B2DPolyPolygon& rClipPoly ) override; + virtual void setClip() override; + + virtual void show() override; + virtual void hide() override; + + virtual void setPriority( double fPriority ) override; + + private: + ImplSprite(const ImplSprite&) = delete; + ImplSprite& operator=( const ImplSprite& ) = delete; + + css::uno::Reference< css::rendering::XGraphicDevice > mxGraphicDevice; + const css::uno::Reference< css::rendering::XSprite > mxSprite; + ImplSpriteCanvas::TransformationArbiterSharedPtr mpTransformArbiter; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implspritecanvas.cxx b/cppcanvas/source/wrapper/implspritecanvas.cxx new file mode 100644 index 000000000..65b36077b --- /dev/null +++ b/cppcanvas/source/wrapper/implspritecanvas.cxx @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/utils/canvastools.hxx> +#include <osl/diagnose.h> + +#include "implspritecanvas.hxx" +#include "implcustomsprite.hxx" + + +using namespace ::com::sun::star; + +namespace cppcanvas::internal +{ + ImplSpriteCanvas::TransformationArbiter::TransformationArbiter() : + maTransformation() + { + } + + void ImplSpriteCanvas::TransformationArbiter::setTransformation( const ::basegfx::B2DHomMatrix& rViewTransform ) + { + maTransformation = rViewTransform; + } + + + ImplSpriteCanvas::ImplSpriteCanvas( const uno::Reference< rendering::XSpriteCanvas >& rCanvas ) : + ImplCanvas( rCanvas ), + mxSpriteCanvas( rCanvas ), + mpTransformArbiter( std::make_shared<TransformationArbiter>() ) + { + OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::ImplSpriteCanvas(): Invalid canvas" ); + } + + ImplSpriteCanvas::ImplSpriteCanvas(const ImplSpriteCanvas& rOrig) : + Canvas(), + SpriteCanvas(), + ImplCanvas( rOrig ), + mxSpriteCanvas( rOrig.getUNOSpriteCanvas() ), + mpTransformArbiter( std::make_shared<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 std::make_shared<ImplCustomSprite>( mxSpriteCanvas, + mxSpriteCanvas->createCustomSprite( ::basegfx::unotools::size2DFromB2DSize(rSize) ), + mpTransformArbiter ); + } + + CanvasSharedPtr ImplSpriteCanvas::clone() const + { + return std::make_shared<ImplSpriteCanvas>( *this ); + } + + uno::Reference< rendering::XSpriteCanvas > ImplSpriteCanvas::getUNOSpriteCanvas() const + { + return mxSpriteCanvas; + } + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/implspritecanvas.hxx b/cppcanvas/source/wrapper/implspritecanvas.hxx new file mode 100644 index 000000000..efad54662 --- /dev/null +++ b/cppcanvas/source/wrapper/implspritecanvas.hxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/rendering/XSpriteCanvas.hpp> +#include <basegfx/vector/b2dsize.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <cppcanvas/spritecanvas.hxx> +#include "implcanvas.hxx" + +namespace cppcanvas::internal +{ + class ImplSpriteCanvas : public virtual SpriteCanvas, protected virtual ImplCanvas + { + public: + ImplSpriteCanvas( const css::uno::Reference< + css::rendering::XSpriteCanvas >& rCanvas ); + ImplSpriteCanvas(const ImplSpriteCanvas&); + + virtual ~ImplSpriteCanvas() override; + + virtual void setTransformation( const ::basegfx::B2DHomMatrix& rMatrix ) override; + + virtual bool updateScreen( bool bUpdateAll ) const override; + + virtual CustomSpriteSharedPtr createCustomSprite( const ::basegfx::B2DSize& ) const override; + + virtual CanvasSharedPtr clone() const override; + + virtual css::uno::Reference< + css::rendering::XSpriteCanvas > getUNOSpriteCanvas() const override; + + /** 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 ); + const ::basegfx::B2DHomMatrix& getTransformation() const { return maTransformation; } + + private: + ::basegfx::B2DHomMatrix maTransformation; + }; + + typedef std::shared_ptr< TransformationArbiter > TransformationArbiterSharedPtr; + + private: + ImplSpriteCanvas& operator=( const ImplSpriteCanvas& ) = delete; + + const css::uno::Reference< css::rendering::XSpriteCanvas > mxSpriteCanvas; + TransformationArbiterSharedPtr mpTransformArbiter; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppcanvas/source/wrapper/vclfactory.cxx b/cppcanvas/source/wrapper/vclfactory.cxx new file mode 100644 index 000000000..825368859 --- /dev/null +++ b/cppcanvas/source/wrapper/vclfactory.cxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <osl/diagnose.h> +#include <vcl/window.hxx> +#include <vcl/canvastools.hxx> + +#include <cppcanvas/vclfactory.hxx> + +#include "implbitmapcanvas.hxx" +#include "implspritecanvas.hxx" +#include "implbitmap.hxx" +#include <implrenderer.hxx> + +using namespace ::com::sun::star; + +namespace cppcanvas +{ + CanvasSharedPtr VCLFactory::createCanvas( const uno::Reference< rendering::XCanvas >& xCanvas ) + { + return std::make_shared<internal::ImplCanvas>( xCanvas ); + } + + BitmapCanvasSharedPtr VCLFactory::createBitmapCanvas( const uno::Reference< rendering::XBitmapCanvas >& xCanvas ) + { + return std::make_shared<internal::ImplBitmapCanvas>( xCanvas ); + } + + SpriteCanvasSharedPtr VCLFactory::createSpriteCanvas( const vcl::Window& rVCLWindow ) + { + return std::make_shared<internal::ImplSpriteCanvas>( + rVCLWindow.GetOutDev()->GetSpriteCanvas() ); + } + + SpriteCanvasSharedPtr VCLFactory::createSpriteCanvas( const uno::Reference< rendering::XSpriteCanvas >& xCanvas ) + { + return std::make_shared<internal::ImplSpriteCanvas>( xCanvas ); + } + + BitmapSharedPtr VCLFactory::createBitmap( const CanvasSharedPtr& rCanvas, + const ::BitmapEx& rBmpEx ) + { + OSL_ENSURE( rCanvas && rCanvas->getUNOCanvas().is(), + "VCLFactory::createBitmap(): Invalid canvas" ); + + if( !rCanvas ) + return BitmapSharedPtr(); + + uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() ); + if( !xCanvas.is() ) + return BitmapSharedPtr(); + + return std::make_shared<internal::ImplBitmap>( rCanvas, + vcl::unotools::xBitmapFromBitmapEx(rBmpEx) ); + } + + RendererSharedPtr VCLFactory::createRenderer( const CanvasSharedPtr& rCanvas, + const ::GDIMetaFile& rMtf, + const Renderer::Parameters& rParms ) + { + return std::make_shared<internal::ImplRenderer>( rCanvas, + rMtf, + rParms ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |