From 6e89341b5045a01e823364633ef0fbfd44ebdfd5 Mon Sep 17 00:00:00 2001 From: Thorsten Behrens Date: Thu, 18 Mar 2004 09:38:44 +0000 Subject: #110496# Merge from cws_srx645_canvas01: first working version of XCanvas UNO components, for now consisting of javacanvas.uno.jar, vclcanvas.uno and directxcanvas.uno (windows only) --- canvas/inc/canvas/canvastools.hxx | 322 +++++++++++ canvas/inc/canvas/elapsedtime.hxx | 114 ++++ canvas/inc/canvas/vclwrapper.hxx | 197 +++++++ canvas/inc/canvas/verbosetrace.hxx | 72 +++ canvas/prj/build.lst | 6 + canvas/prj/d.lst | 12 + canvas/source/java/BackBuffer.java | 161 ++++++ canvas/source/java/BezierPolyPolygon.java | 194 +++++++ canvas/source/java/BitmapCanvas.java | 170 ++++++ canvas/source/java/BufferedGraphics2D.java | 630 ++++++++++++++++++++++ canvas/source/java/CanvasBase.java | 379 +++++++++++++ canvas/source/java/CanvasBitmap.java | 238 +++++++++ canvas/source/java/CanvasClonedSprite.java | 228 ++++++++ canvas/source/java/CanvasCustomSprite.java | 246 +++++++++ canvas/source/java/CanvasFont.java | 187 +++++++ canvas/source/java/CanvasGraphicDevice.java | 192 +++++++ canvas/source/java/CanvasSprite.java | 350 ++++++++++++ canvas/source/java/CanvasTest_perftest.java | 710 +++++++++++++++++++++++++ canvas/source/java/CanvasUtils.java | 670 +++++++++++++++++++++++ canvas/source/java/JavaCanvas.java | 624 ++++++++++++++++++++++ canvas/source/java/LinePolyPolygon.java | 235 ++++++++ canvas/source/java/SpriteBase.java | 84 +++ canvas/source/java/SpriteRep.java | 220 ++++++++ canvas/source/java/SpriteRunner.java | 249 +++++++++ canvas/source/java/java_Service.java | 118 ++++ canvas/source/java/makefile.mk | 94 ++++ canvas/source/java/manifest | 1 + canvas/source/java/perftest/PerfTest.java | 344 ++++++++++++ canvas/source/java/perftest/WindowAdapter.java | 227 ++++++++ canvas/source/java/perftest/makefile.mk | 68 +++ canvas/source/java/perftest/manifest | 1 + canvas/source/java/win/WindowAdapter.java | 229 ++++++++ canvas/source/java/x11/WindowAdapter.java | 228 ++++++++ canvas/source/tools/canvastools.cxx | 389 ++++++++++++++ canvas/source/tools/canvastools.flt | 4 + canvas/source/tools/elapsedtime.cxx | 184 +++++++ canvas/source/tools/makefile.mk | 104 ++++ canvas/source/vcl/canvasbitmap.cxx | 451 ++++++++++++++++ canvas/source/vcl/canvasbitmap.hxx | 137 +++++ canvas/source/vcl/canvascustomsprite.cxx | 444 ++++++++++++++++ canvas/source/vcl/canvascustomsprite.hxx | 258 +++++++++ canvas/source/vcl/canvasfont.cxx | 174 ++++++ canvas/source/vcl/canvasfont.hxx | 134 +++++ canvas/source/vcl/exports.dxp | 3 + canvas/source/vcl/impltools.cxx | 414 ++++++++++++++ canvas/source/vcl/impltools.hxx | 195 +++++++ canvas/source/vcl/makefile.mk | 106 ++++ canvas/source/vcl/outdevprovider.hxx | 124 +++++ canvas/source/vcl/sprite.hxx | 101 ++++ canvas/source/vcl/spritecanvas.cxx | 532 ++++++++++++++++++ canvas/source/vcl/spritecanvas.hxx | 298 +++++++++++ 51 files changed, 11852 insertions(+) create mode 100644 canvas/inc/canvas/canvastools.hxx create mode 100644 canvas/inc/canvas/elapsedtime.hxx create mode 100644 canvas/inc/canvas/vclwrapper.hxx create mode 100644 canvas/inc/canvas/verbosetrace.hxx create mode 100644 canvas/prj/build.lst create mode 100644 canvas/prj/d.lst create mode 100644 canvas/source/java/BackBuffer.java create mode 100644 canvas/source/java/BezierPolyPolygon.java create mode 100644 canvas/source/java/BitmapCanvas.java create mode 100644 canvas/source/java/BufferedGraphics2D.java create mode 100644 canvas/source/java/CanvasBase.java create mode 100644 canvas/source/java/CanvasBitmap.java create mode 100644 canvas/source/java/CanvasClonedSprite.java create mode 100644 canvas/source/java/CanvasCustomSprite.java create mode 100644 canvas/source/java/CanvasFont.java create mode 100644 canvas/source/java/CanvasGraphicDevice.java create mode 100644 canvas/source/java/CanvasSprite.java create mode 100644 canvas/source/java/CanvasTest_perftest.java create mode 100644 canvas/source/java/CanvasUtils.java create mode 100644 canvas/source/java/JavaCanvas.java create mode 100644 canvas/source/java/LinePolyPolygon.java create mode 100644 canvas/source/java/SpriteBase.java create mode 100644 canvas/source/java/SpriteRep.java create mode 100644 canvas/source/java/SpriteRunner.java create mode 100644 canvas/source/java/java_Service.java create mode 100644 canvas/source/java/makefile.mk create mode 100644 canvas/source/java/manifest create mode 100644 canvas/source/java/perftest/PerfTest.java create mode 100644 canvas/source/java/perftest/WindowAdapter.java create mode 100644 canvas/source/java/perftest/makefile.mk create mode 100644 canvas/source/java/perftest/manifest create mode 100644 canvas/source/java/win/WindowAdapter.java create mode 100644 canvas/source/java/x11/WindowAdapter.java create mode 100644 canvas/source/tools/canvastools.cxx create mode 100644 canvas/source/tools/canvastools.flt create mode 100644 canvas/source/tools/elapsedtime.cxx create mode 100644 canvas/source/tools/makefile.mk create mode 100644 canvas/source/vcl/canvasbitmap.cxx create mode 100644 canvas/source/vcl/canvasbitmap.hxx create mode 100644 canvas/source/vcl/canvascustomsprite.cxx create mode 100644 canvas/source/vcl/canvascustomsprite.hxx create mode 100644 canvas/source/vcl/canvasfont.cxx create mode 100644 canvas/source/vcl/canvasfont.hxx create mode 100644 canvas/source/vcl/exports.dxp create mode 100644 canvas/source/vcl/impltools.cxx create mode 100644 canvas/source/vcl/impltools.hxx create mode 100644 canvas/source/vcl/makefile.mk create mode 100644 canvas/source/vcl/outdevprovider.hxx create mode 100644 canvas/source/vcl/sprite.hxx create mode 100644 canvas/source/vcl/spritecanvas.cxx create mode 100644 canvas/source/vcl/spritecanvas.hxx (limited to 'canvas') diff --git a/canvas/inc/canvas/canvastools.hxx b/canvas/inc/canvas/canvastools.hxx new file mode 100644 index 000000000000..ff7cc931abfa --- /dev/null +++ b/canvas/inc/canvas/canvastools.hxx @@ -0,0 +1,322 @@ +/************************************************************************* + * + * $RCSfile: canvastools.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:24 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CANVAS_CANVASTOOLS_HXX +#define _CANVAS_CANVASTOOLS_HXX + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include +#endif +#ifndef _COM_SUN_STAR_UNO_RUNTIMEEXCEPTION_HDL_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_ +#include +#endif + +#include +#include + + +namespace basegfx +{ + class B2DHomMatrix; + class B2DRange; +} + +namespace drafts { namespace com { namespace sun { namespace star { namespace geometry +{ + struct AffineMatrix2D; +} } } } } + +namespace drafts { namespace com { namespace sun { namespace star { namespace rendering +{ + struct RenderState; + struct ViewState; + class XCanvas; +} } } } } + + +namespace canvas +{ + namespace tools + { + // View- and RenderState utilities + // =================================================================== + + ::drafts::com::sun::star::rendering::RenderState& + initRenderState( ::drafts::com::sun::star::rendering::RenderState& renderState ); + + ::drafts::com::sun::star::rendering::ViewState& + initViewState( ::drafts::com::sun::star::rendering::ViewState& viewState ); + + ::basegfx::B2DHomMatrix& + getViewStateTransform( ::basegfx::B2DHomMatrix& transform, + const ::drafts::com::sun::star::rendering::ViewState& viewState ); + + ::drafts::com::sun::star::rendering::ViewState& + setViewStateTransform( ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::basegfx::B2DHomMatrix& transform ); + + ::basegfx::B2DHomMatrix& + getRenderStateTransform( ::basegfx::B2DHomMatrix& transform, + const ::drafts::com::sun::star::rendering::RenderState& renderState ); + + ::drafts::com::sun::star::rendering::RenderState& + setRenderStateTransform( ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::basegfx::B2DHomMatrix& transform ); + + ::drafts::com::sun::star::rendering::ViewState& + appendToViewState( ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::basegfx::B2DHomMatrix& transform ); + + ::drafts::com::sun::star::rendering::RenderState& + appendToRenderState( ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::basegfx::B2DHomMatrix& transform ); + + ::drafts::com::sun::star::rendering::ViewState& + prependToViewState( ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::basegfx::B2DHomMatrix& transform ); + + ::drafts::com::sun::star::rendering::RenderState& + prependToRenderState( ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::basegfx::B2DHomMatrix& transform ); + + ::basegfx::B2DHomMatrix& + mergeViewAndRenderTransform( ::basegfx::B2DHomMatrix& transform, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ); + + ::drafts::com::sun::star::rendering::ViewState& + mergeViewAndRenderState( ::drafts::com::sun::star::rendering::ViewState& resultViewState, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::rendering::XCanvas > xCanvas ); + + bool operator==( const ::drafts::com::sun::star::rendering::RenderState& rLHS, + const ::drafts::com::sun::star::rendering::RenderState& rRHS ); + + bool operator==( const ::drafts::com::sun::star::rendering::ViewState& rLHS, + const ::drafts::com::sun::star::rendering::ViewState& rRHS ); + + + // Matrix utilities + // =================================================================== + + ::drafts::com::sun::star::geometry::AffineMatrix2D& + setIdentityAffineMatrix2D( ::drafts::com::sun::star::geometry::AffineMatrix2D& matrix ); + + + // Special utilities + // =================================================================== + + /** Calc the bounding rectangle of a transformed rectangle. + + The method applies the given transformation to the + specified input rectangle, and returns the bounding box of + the resulting output area. + + @param o_Rect + Output rectangle + + @param i_Rect + Input rectangle + + @param i_Transformation + Transformation to apply to the input rectangle + + @see calcRectToRectTransform() + */ + ::basegfx::B2DRange& calcTransformedRectBounds( ::basegfx::B2DRange& o_Rect, + const ::basegfx::B2DRange& i_Rect, + const ::basegfx::B2DHomMatrix& i_Transformation ); + + /** Calc a transform that maps one rectangle on top of + another. + + The method is a kissing cousin to + calcTransformedRectBounds(). It can be used to modify the + given transformation matrix, such that it transforms the + given input rectangle to the given output rectangle, + changing only translation and scale (if necessary). Thus, + if you've calculated an output rectangle via + calcTransformedRectBounds(), you can move and scale that + rectangle as you like, and have this method calculate the + required total transformation for it. + + @param o_transform + Output parameter, to receive the resulting transformation + matrix. + + @param i_destRect + Input parameter, specifies the requested destination + rectangle. The resulting transformation will exactly map + the source rectangle to the destination rectangle. + + @param i_srcRect + Input parameter, specifies the original source + rectangle. The resulting transformation will exactly map + the source rectangle to the destination rectangle. + + @param i_transformation + The original transformation matrix. This is changed with + translations and scalings (if necessary), to exactly map + the source rectangle to the destination rectangle. + + @return a reference to the resulting transformation matrix + + @see calcTransformedRectBounds() + */ + ::basegfx::B2DHomMatrix& calcRectToRectTransform( ::basegfx::B2DHomMatrix& o_transform, + const ::basegfx::B2DRange& i_destRect, + const ::basegfx::B2DRange& i_srcRect, + const ::basegfx::B2DHomMatrix& i_transformation ); + + /** Calc a transform that maps the upper, left corner of a + rectangle to the origin. + + The method is a specialized version of + calcRectToRectTransform(), mapping the input rectangle's + the upper, left corner to the origin, and leaving the size + untouched. + + @param o_transform + Output parameter, to receive the resulting transformation + matrix. + + @param i_srcRect + Input parameter, specifies the original source + rectangle. The resulting transformation will exactly map + the source rectangle's upper, left corner to the origin. + + @param i_transformation + The original transformation matrix. This is changed with + translations (if necessary), to exactly map the source + rectangle to the origin. + + @return a reference to the resulting transformation matrix + + @see calcRectToRectTransform() + @see calcTransformedRectBounds() + */ + ::basegfx::B2DHomMatrix& calcRectToOriginTransform( ::basegfx::B2DHomMatrix& o_transform, + const ::basegfx::B2DRange& i_srcRect, + const ::basegfx::B2DHomMatrix& i_transformation ); + + /** Range checker, which throws ::com::sun::star::lang::IllegalArgument exception, when + range is violated + */ + template< typename NumType > inline void checkRange( NumType arg, NumType lowerBound, NumType upperBound ) + { + if( arg < lowerBound || + arg > upperBound ) + { + throw ::com::sun::star::lang::IllegalArgumentException(); + } + } + + /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when + index range is violated + */ + template< typename NumType > inline void checkIndexRange( NumType arg, NumType lowerBound, NumType upperBound ) + { + if( arg < lowerBound || + arg > upperBound ) + { + throw ::com::sun::star::lang::IndexOutOfBoundsException(); + } + } + + // BEWARE: don't currently use with float or double, Solaris + // STLport's numeric_limits bark on that (unresolved + // externals) + + // Modeled closely after boost::numeric_cast, only that we + // issue some trace output here and throw a RuntimeException + template< typename Target, typename Source > inline Target numeric_cast( Source arg ) + { + // typedefs abbreviating respective trait classes + typedef ::std::numeric_limits< Source > SourceLimits; + typedef ::std::numeric_limits< Target > TargetLimits; + + if( ( arg<0 && !TargetLimits::is_signed) || // loosing the sign here + ( SourceLimits::is_signed && argTargetLimits::max() ) ) // overflow will happen + { +#ifdef VERBOSE + OSL_TRACE("numeric_cast detected data loss"); +#endif + throw ::com::sun::star::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "numeric_cast detected data loss" )), + NULL ); + } + + return static_cast(arg); + } + + } +} + +#endif /* _CANVAS_CANVASTOOLS_HXX */ diff --git a/canvas/inc/canvas/elapsedtime.hxx b/canvas/inc/canvas/elapsedtime.hxx new file mode 100644 index 000000000000..fcb008527f25 --- /dev/null +++ b/canvas/inc/canvas/elapsedtime.hxx @@ -0,0 +1,114 @@ +/************************************************************************* + * + * $RCSfile: elapsedtime.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:25 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CANVAS_ELAPSEDTIME_HXX +#define _CANVAS_ELAPSEDTIME_HXX + +#ifndef _SAL_TYPES_H_ +#include +#endif + +namespace canvas +{ + namespace tools + { + /** Calculate elapsed time + */ + class ElapsedTime + { + public: + /** Create a new ElapsedTime object + + The moment of construction starts the time + measurement. That means, a subsequent getElapsedTime() + call will return the time difference between object + creation and getElapsedTime() call. + */ + ElapsedTime(); + + /** Reset the time + + The instance of the reset() call starts the time + measurement from scratch. That means, a subsequent + getElapsedTime() call will return the time difference + between reset() and getElapsedTime() call. + */ + void reset(); + + /** Query the elapsed time + + This method returns the elapsed time in seconds + between either the construction of this object, or the + last reset() call, if any. + + @return the elapsed time in seconds. + */ + double getElapsedTime(); + + private: + sal_uInt64 mnStartTime; // implementation-dependent start time representation + double mfTimeFactor; // correction factor to get the time in seconds from mnStartTime + }; + + } +} + +#endif /* _CANVAS_ELAPSEDTIME_HXX */ diff --git a/canvas/inc/canvas/vclwrapper.hxx b/canvas/inc/canvas/vclwrapper.hxx new file mode 100644 index 000000000000..a1bcaf58688a --- /dev/null +++ b/canvas/inc/canvas/vclwrapper.hxx @@ -0,0 +1,197 @@ +/************************************************************************* + * + * $RCSfile: vclwrapper.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:25 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CANVAS_VCLWRAPPER_HXX +#define _CANVAS_VCLWRAPPER_HXX + +#ifndef _OSL_MUTEX_HXX_ +#include +#endif +#ifndef _VOS_MUTEX_HXX_ +#include +#endif +#ifndef _SV_SVAPP_HXX +#include +#endif + + +namespace canvas +{ + namespace vcltools + { + /** This helper template wraps VCL objects, and protects + object deletion with the Solar mutex. All other operations + are unprotected, this must be handled by client code. + + The reason for this template is the fact that VCL objects + hold by value in uno::Reference-handled classes are + deleted without having the chance to get inbetween and + lock the solar mutex. + + This template handles that problem transparently, the only + inconvenience is the fact that object member access now + has to be performed via operator->, since . is not + overloadable. + + Otherwise, the template preserves the value semantics of + the wrapped object, that is, copy operations are performed + not by copying pointers, but by copying the underlying + object. This includes constness, i.e. on a const + VCLObject, only const methods of the wrapped object can be + called. Simply imagine this to be a value object of type + "template argument", with the only peculiarity that + member/method access is performed by operator-> instead of + the non-existing "operator.". + */ + template< class _Wrappee > class VCLObject + { + public: + typedef _Wrappee Wrappee; + + VCLObject() : + mpWrappee( new Wrappee() ) + { + } + + // no explicit here. VCLObjects should be freely + // constructible with Wrappees, and AFAIK there is no other + // implicit conversion path that could cause harm here + VCLObject( Wrappee* pWrappee ) : + mpWrappee( pWrappee ) + { + } + + // This object has value semantics, thus, forward copy + // to wrappee + VCLObject( const VCLObject& rOrig ) + { + if( rOrig.mpWrappee ) + mpWrappee = new Wrappee( *rOrig.mpWrappee ); + else + mpWrappee = NULL; + } + + // This object has value semantics, thus, forward copy + // to wrappee + VCLObject( const Wrappee& rOrig ) : + mpWrappee( new Wrappee( rOrig ) ) + { + } + + // This object has value semantics, thus, forward + // assignment to wrappee + VCLObject& operator=( const VCLObject& rhs ) + { + if( mpWrappee ) + { + if( rhs.mpWrappee ) + *mpWrappee = *rhs.mpWrappee; + } + else + { + if( rhs.mpWrappee ) + mpWrappee = new Wrappee( *rhs.mpWrappee ); + } + + return *this; + } + + ~VCLObject() + { + // This here is the whole purpose of the template: + // protecting object deletion with the solar mutex + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + if( mpWrappee ) + delete mpWrappee; + } + + Wrappee* operator->() { return mpWrappee; } + const Wrappee* operator->() const { return mpWrappee; } + + Wrappee& operator*() { return *mpWrappee; } + const Wrappee& operator*() const { return *mpWrappee; } + + bool operator==( const Wrappee& rhs ) const + { + if( mpWrappee ) + return *const_cast(mpWrappee) == rhs; // force operator==() const call on wrappee + else + return mpWrappee == rhs.mpWrappee; // handle both-sides-null correctly + } + + bool operator==( const Wrappee& rhs ) + { + if( mpWrappee ) + return *mpWrappee == rhs; + else + return mpWrappee == rhs.mpWrappee; // handle both-sides-null correctly + } + + private: + + Wrappee* mpWrappee; + }; + + } +} + +#endif /* _CANVAS_VCLWRAPPER_HXX */ diff --git a/canvas/inc/canvas/verbosetrace.hxx b/canvas/inc/canvas/verbosetrace.hxx new file mode 100644 index 000000000000..e8acefcb2ed8 --- /dev/null +++ b/canvas/inc/canvas/verbosetrace.hxx @@ -0,0 +1,72 @@ +/************************************************************************* + * + * $RCSfile: verbosetrace.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:26 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CANVAS_VERBOSETRACE_HXX +#define _CANVAS_VERBOSETRACE_HXX + +#ifdef VERBOSE +/// Wrap OSL_TRACE with a verbosity switch +#define VERBOSE_TRACE OSL_TRACE +#else +#define VERBOSE_TRACE 1 ? ((void)0) : OSL_TRACE +#endif + +#endif /* _CANVAS_VERBOSETRACE_HXX */ diff --git a/canvas/prj/build.lst b/canvas/prj/build.lst new file mode 100644 index 000000000000..33346351480f --- /dev/null +++ b/canvas/prj/build.lst @@ -0,0 +1,6 @@ +uc canvas : comphelper cppuhelper offuh unoil tools vcl basegfx NULL +uc canvas usr1 - all uc_mkout NULL +uc canvas\source\tools nmake - all uc_tools NULL +uc canvas\source\win nmake - all uc_win uc_tools NULL +uc canvas\source\vcl nmake - all uc_vcl uc_tools NULL +uc canvas\source\java nmake - all uc_java NULL diff --git a/canvas/prj/d.lst b/canvas/prj/d.lst new file mode 100644 index 000000000000..5bfbf22dc6ef --- /dev/null +++ b/canvas/prj/d.lst @@ -0,0 +1,12 @@ +..\%__SRC%\bin\canvastools*.dll %_DEST%\bin%_EXT%\canvastools*.dll +..\%__SRC%\bin\vclcanvas*.dll %_DEST%\bin%_EXT%\vclcanvas*.dll +..\%__SRC%\bin\directxcanvas*.dll %_DEST%\bin%_EXT%\directxcanvas*.dll +..\%__SRC%\lib\icanvastools.lib %_DEST%\lib%_EXT%\icanvastools.lib +..\%__SRC%\lib\*.so %_DEST%\lib%_EXT%\*.so +..\%__SRC%\class\javacanvas*.jar %_DEST%\bin%_EXT%\javacanvas*.jar + +mkdir: %_DEST%\inc%_EXT%\canvas +hedabu: ..\inc\canvas\canvastools.hxx %_DEST%\inc%_EXT%\canvas\canvastools.hxx +hedabu: ..\inc\canvas\elapsedtime.hxx %_DEST%\inc%_EXT%\canvas\elapsedtime.hxx +hedabu: ..\inc\canvas\vclwrapper.hxx %_DEST%\inc%_EXT%\canvas\vclwrapper.hxx +hedabu: ..\inc\canvas\verbosetrace.hxx %_DEST%\inc%_EXT%\canvas\verbosetrace.hxx diff --git a/canvas/source/java/BackBuffer.java b/canvas/source/java/BackBuffer.java new file mode 100644 index 000000000000..abca8f200af6 --- /dev/null +++ b/canvas/source/java/BackBuffer.java @@ -0,0 +1,161 @@ +/************************************************************************* + * + * $RCSfile: BackBuffer.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; + +// Java AWT +import java.awt.*; +import java.awt.image.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public class BackBuffer +{ + private BufferedImage backBuffer; + //private VolatileImage backBuffer; + private Graphics2D backBufferGraphics; + private Graphics2D referenceDevice; + + public BackBuffer( Graphics2D _referenceDevice, + int width, + int height ) + { + referenceDevice = _referenceDevice; + setSize( width, height ); + } + + public Graphics2D getGraphics() + { + return backBufferGraphics; + } + + public void setSize( int width, + int height ) + { + if( backBuffer != null && + width == backBuffer.getWidth() && + height == backBuffer.getHeight() ) + { + return; + } + + if( backBufferGraphics != null ) + backBufferGraphics.dispose(); + + if( backBuffer != null ) + backBuffer.flush(); + + // TODO: Maybe VolatileImage with another BufferedImage as a backup is + // a tad faster here. + backBuffer = referenceDevice.getDeviceConfiguration().createCompatibleImage(width, + height); +// backBuffer = referenceDevice.getDeviceConfiguration().createCompatibleVolatileImage(width, +// height); + + backBufferGraphics = backBuffer.createGraphics(); + CanvasUtils.initGraphics( backBufferGraphics ); + + // clear the buffer to white (to have a defined state here) + backBufferGraphics.setColor( java.awt.Color.white ); + backBufferGraphics.fillRect( 0,0,width,height ); + } + + public void redraw( Graphics2D graph ) + { + if( graph != null && + backBuffer != null ) + { + CanvasUtils.printLog("BackBuffer.redraw(): using buffer of size (" + + backBuffer.getWidth() + "," + backBuffer.getHeight() + ")" ); + + graph.drawImage(backBuffer, 0, 0, null); + + // TODO: this is just twiddled to work. I cannot be sure + // that this volatile backbuffer will survive in the first + // place, nor that it wise to leave it in VRAM. + + // only flush non-volatile images + // CanvasUtils.postRenderImageTreatment( backBuffer ); + } + } + + public java.awt.Image getBackBuffer() + { + return backBuffer; + } + + public void dispose() + { + backBufferGraphics.dispose(); + backBuffer.flush(); + } +} diff --git a/canvas/source/java/BezierPolyPolygon.java b/canvas/source/java/BezierPolyPolygon.java new file mode 100644 index 000000000000..bd13ea029ca0 --- /dev/null +++ b/canvas/source/java/BezierPolyPolygon.java @@ -0,0 +1,194 @@ +/************************************************************************* + * + * $RCSfile: BezierPolyPolygon.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// system-dependent stuff +import sun.awt.*; + + +public class BezierPolyPolygon + extends com.sun.star.lib.uno.helper.ComponentBase + implements com.sun.star.lang.XServiceInfo, + drafts.com.sun.star.rendering.XBezierPolyPolygon2D +{ + private java.awt.geom.GeneralPath path; + + //---------------------------------------------------------------------------------- + + public BezierPolyPolygon( RealBezierSegment2D[][] points ) + { + setPoints( points, 0, 0 ); + } + + public java.awt.geom.GeneralPath getJavaPath() + { + return path; + } + + //---------------------------------------------------------------------------------- + + // + // XPolyPolygon implementation + // =========================== + // + public void addPolyPolygon( RealPoint2D position, XPolyPolygon2D polyPolygon ) + { + } + + public int getNumberOfPolygons( ) + { + return 0; + } + + public int getNumberOfPolygonPoints( int polygon ) + { + return 0; + } + + public FillRule getFillRule( ) + { + if( path.getWindingRule() == java.awt.geom.GeneralPath.WIND_EVEN_ODD ) + return FillRule.EVEN_ODD; + else + return FillRule.NON_ZERO; + } + + public void setFillRule( FillRule fillRule ) + { + if( fillRule == FillRule.EVEN_ODD ) + path.setWindingRule( java.awt.geom.GeneralPath.WIND_EVEN_ODD ); + else + path.setWindingRule( java.awt.geom.GeneralPath.WIND_NON_ZERO ); + } + + public boolean isClosed( int index ) + { + // TODO + return false; + } + + public void setClosed( int index, boolean closedState ) + { + // TODO + } + + //---------------------------------------------------------------------------------- + + // + // XBezierPolyPolygon implementation + // ================================= + // + public RealBezierSegment2D[][] getPoints( int nPolygonIndex, int nNumberOfPolygons, int nPointIndex, int nNumberOfPoints ) + { + return null; + } + + public void setPoints( RealBezierSegment2D[][] points, int nPolygonIndex, int nPointIndex ) + { + if( nPolygonIndex != 0 || nPointIndex != 0 ) + CanvasUtils.printLog( "LinePolyPolygon.setPoints: subset not yet implemented!" ); + + path = CanvasUtils.makeGenPathFromBezierPoints( points ); + } + + public RealBezierSegment2D getPoint( int nPolygonIndex, int nPointIndex ) + { + return null; + } + + public void setPoint( RealBezierSegment2D point, int nPolygonIndex, int nPointIndex ) + { + CanvasUtils.printLog( "LinePolyPolygon.setPoint: not yet implemented!" ); + } + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + + private static final String s_implName = "XBezierPolyPolygon2D.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.BezierPolyPolygon2D"; + + public String getImplementationName() + { + return s_implName; + } + + public String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/canvas/source/java/BitmapCanvas.java b/canvas/source/java/BitmapCanvas.java new file mode 100644 index 000000000000..8238ece71057 --- /dev/null +++ b/canvas/source/java/BitmapCanvas.java @@ -0,0 +1,170 @@ +/************************************************************************* + * + * $RCSfile: BitmapCanvas.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// Java AWT +import java.awt.*; +import java.awt.image.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public class BitmapCanvas + extends CanvasBase + implements drafts.com.sun.star.rendering.XBitmapCanvas, + com.sun.star.lang.XServiceInfo +{ + private Graphics2D graphics; + + public Graphics2D getGraphics() + { + return graphics; + } + + //---------------------------------------------------------------------------------- + + public BitmapCanvas( Graphics2D _graphics ) + { + graphics = _graphics; + } + + //---------------------------------------------------------------------------------- + + // + // XBitmapCanvas impl + // ================== + // + + public synchronized void copyRect( drafts.com.sun.star.rendering.XBitmapCanvas sourceCanvas, + drafts.com.sun.star.geometry.RealRectangle2D sourceRect, + drafts.com.sun.star.rendering.ViewState sourceViewState, + drafts.com.sun.star.rendering.RenderState sourceRenderState, + drafts.com.sun.star.geometry.RealRectangle2D destRect, + drafts.com.sun.star.rendering.ViewState destViewState, + drafts.com.sun.star.rendering.RenderState destRenderState ) + { + // TODO: create temp image when transform is non-trivial + + if( sourceCanvas == this ) + { + // copy rectangle within the canvas + graphics.copyArea((int)sourceRect.X1, + (int)sourceRect.Y1, + (int)(sourceRect.X2 - sourceRect.X1), + (int)(sourceRect.Y2 - sourceRect.Y1), + (int)(destRect.X1 - sourceRect.X1), + (int)(destRect.Y1 - sourceRect.Y1) ); + } + else + { + if( sourceCanvas instanceof JavaCanvas ) + { + // cache + CanvasUtils.setupGraphicsState( graphics, destViewState, destRenderState, CanvasUtils.alsoSetupPaint ); + + // TODO: really extract correct source rect here + BufferedImage backBuffer = ((BufferedGraphics2D)((JavaCanvas)sourceCanvas).getGraphics()).getBackBuffer(); + graphics.drawImage( backBuffer, 0, 0, null ); + CanvasUtils.postRenderImageTreatment( backBuffer ); + + } + // TODO: foreign canvas + } + } + + //---------------------------------------------------------------------------------- + + private static final String s_implName = "XBitmapCanvas.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.BitmapCanvas"; + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + public String getImplementationName() + { + return s_implName; + } + + public String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/canvas/source/java/BufferedGraphics2D.java b/canvas/source/java/BufferedGraphics2D.java new file mode 100644 index 000000000000..53c89990b11e --- /dev/null +++ b/canvas/source/java/BufferedGraphics2D.java @@ -0,0 +1,630 @@ +/************************************************************************* + * + * $RCSfile: BufferedGraphics2D.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +0 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// Java AWT +import java.awt.*; +import java.awt.geom.*; +import java.awt.image.*; +import java.awt.image.renderable.*; +import java.awt.font.*; +import java.text.*; +import java.util.*; + + +public class BufferedGraphics2D + extends java.awt.Graphics2D +{ + // TODO: Somehow, get rid of this duplicate graphics (the graphics member, + // and this object itself, extending a Graphics2D) + private Graphics2D graphics; + private BufferedImage backBuffer; + private Graphics2D backBufferGraphics; + + //---------------------------------------------------------------------------------- + + public BufferedGraphics2D( java.awt.Graphics2D _graphics, int width, int height ) + { + setGraphics( _graphics, Math.max(1,width), Math.max(1,height) ); + } + + public void redraw( Graphics2D graph ) + { + if( graph != null && + backBuffer != null ) + { + CanvasUtils.printLog("BufferedGraphics2D.redraw: using buffer of size (" + + backBuffer.getWidth() + "," + backBuffer.getHeight() + ")" ); + + // set transform to identity + graph.setTransform( new AffineTransform() ); + graph.drawImage(backBuffer, 0, 0, null); + CanvasUtils.postRenderImageTreatment( backBuffer ); + } + } + + public BufferedImage getBackBuffer() + { + return backBuffer; + } + + public void setSize( int width, int height ) + { + if( backBuffer != null && + width == backBuffer.getWidth() && + height == backBuffer.getHeight() ) + { + return; + } + + if( backBufferGraphics != null ) + backBufferGraphics.dispose(); + + if( backBuffer != null ) + backBuffer.flush(); + + // TODO: Maybe VolatileImage with another BufferedImage as a backup is + // a tad faster here. + backBuffer = graphics.getDeviceConfiguration().createCompatibleImage(width, + height); + + backBufferGraphics = backBuffer.createGraphics(); + CanvasUtils.initGraphics( backBufferGraphics ); + + // clear the buffer to white (to have a defined state here) + backBufferGraphics.setColor( java.awt.Color.white ); + backBufferGraphics.fillRect( 0,0,width,height ); + } + + public void setGraphics( Graphics2D _graphics, int width, int height ) + { + if( graphics != null ) + graphics.dispose(); + + graphics = _graphics; + + setSize(width,height); + } + + //---------------------------------------------------------------------------------- + + // + // Graphics + // ======== + // + public void clearRect(int x, int y, int width, int height) + { + graphics.clearRect(x,y,width,height); + backBufferGraphics.clearRect(x,y,width,height); + } + + public void clipRect(int x, int y, int width, int height) + { + graphics.clipRect(x,y,width,height); + backBufferGraphics.clipRect(x,y,width,height); + } + + public void copyArea(int x, int y, int width, int height, int dx, int dy) + { + graphics.copyArea(x,y,width,height,dx,dy); + backBufferGraphics.copyArea(x,y,width,height,dx,dy); + } + + public Graphics create() + { + return null; + } + + public Graphics create(int x, int y, int width, int height) + { + return null; + } + + public void dispose() + { + graphics.dispose(); + backBufferGraphics.dispose(); + backBuffer.flush(); + } + + public void draw3DRect(int x, int y, int width, int height, boolean raised) + { + graphics.draw3DRect(x,y,width,height,raised); + backBufferGraphics.draw3DRect(x,y,width,height,raised); + } + + public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) + { + graphics.drawArc(x,y,width,height,startAngle,arcAngle); + backBufferGraphics.drawArc(x,y,width,height,startAngle,arcAngle); + } + + public void drawBytes(byte[] data, int offset, int length, int x, int y) + { + graphics.drawBytes(data,offset,length,x,y); + backBufferGraphics.drawBytes(data,offset,length,x,y); + } + + public void drawChars(char[] data, int offset, int length, int x, int y) + { + graphics.drawChars(data,offset,length,x,y); + backBufferGraphics.drawChars(data,offset,length,x,y); + } + + public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) + { + backBufferGraphics.drawImage(img,x,y,bgcolor,observer); + return graphics.drawImage(img,x,y,bgcolor,observer); + } + + public boolean drawImage(Image img, int x, int y, ImageObserver observer) + { + backBufferGraphics.drawImage(img,x,y,observer); + return graphics.drawImage(img,x,y,observer); + } + + public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) + { + backBufferGraphics.drawImage(img,x,y,width,height,bgcolor,observer); + return graphics.drawImage(img,x,y,width,height,bgcolor,observer); + } + + public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) + { + backBufferGraphics.drawImage(img,x,y,width,height,observer); + return graphics.drawImage(img,x,y,width,height,observer); + } + + public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) + { + backBufferGraphics.drawImage(img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,bgcolor,observer); + return graphics.drawImage(img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,bgcolor,observer); + } + + public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) + { + backBufferGraphics.drawImage(img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,observer); + return graphics.drawImage(img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,observer); + } + + public void drawLine(int x1, int y1, int x2, int y2) + { + graphics.drawLine(x1,y1,x2,y2); + backBufferGraphics.drawLine(x1,y1,x2,y2); + } + + public void drawOval(int x, int y, int width, int height) + { + graphics.drawOval(x,y,width,height); + backBufferGraphics.drawOval(x,y,width,height); + } + + public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) + { + graphics.drawPolygon(xPoints,yPoints,nPoints); + backBufferGraphics.drawPolygon(xPoints,yPoints,nPoints); + } + + public void drawPolygon(Polygon p) + { + graphics.drawPolygon(p); + backBufferGraphics.drawPolygon(p); + } + + public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) + { + graphics.drawPolyline(xPoints,yPoints,nPoints); + backBufferGraphics.drawPolyline(xPoints,yPoints,nPoints); + } + + public void drawRect(int x, int y, int width, int height) + { + graphics.drawRect(x,y,width,height); + backBufferGraphics.drawRect(x,y,width,height); + } + + public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) + { + graphics.drawRoundRect(x,y,width,height,arcWidth,arcHeight); + backBufferGraphics.drawRoundRect(x,y,width,height,arcWidth,arcHeight); + } + + public void drawString(AttributedCharacterIterator iterator, int x, int y) + { + graphics.drawString(iterator,x,y); + backBufferGraphics.drawString(iterator,x,y); + } + + public void drawString(String str, int x, int y) + { + graphics.drawString(str,x,y); + backBufferGraphics.drawString(str,x,y); + } + + public void fill3DRect(int x, int y, int width, int height, boolean raised) + { + graphics.fill3DRect(x,y,width,height,raised); + backBufferGraphics.fill3DRect(x,y,width,height,raised); + } + + public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) + { + graphics.fillArc(x,y,width,height,startAngle,arcAngle); + backBufferGraphics.fillArc(x,y,width,height,startAngle,arcAngle); + } + + public void fillOval(int x, int y, int width, int height) + { + graphics.fillOval(x,y,width,height); + backBufferGraphics.fillOval(x,y,width,height); + } + + public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) + { + graphics.fillPolygon(xPoints,yPoints,nPoints); + backBufferGraphics.fillPolygon(xPoints,yPoints,nPoints); + } + + public void fillPolygon(Polygon p) + { + graphics.fillPolygon(p); + backBufferGraphics.fillPolygon(p); + } + + public void fillRect(int x, int y, int width, int height) + { + graphics.fillRect(x,y,width,height); + backBufferGraphics.fillRect(x,y,width,height); + } + + public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) + { + graphics.fillRoundRect(x,y,width,height,arcWidth,arcHeight); + backBufferGraphics.fillRoundRect(x,y,width,height,arcWidth,arcHeight); + } + + public Shape getClip() + { + return graphics.getClip(); + } + + public Rectangle getClipBounds() + { + return graphics.getClipBounds(); + } + + public Rectangle getClipBounds(Rectangle r) + { + return graphics.getClipBounds(r); + } + + public Rectangle getClipRect() + { + return graphics.getClipRect(); + } + + public Color getColor() + { + return getColor(); + } + + public Font getFont() + { + return getFont(); + } + + public FontMetrics getFontMetrics() + { + return getFontMetrics(); + } + + public FontMetrics getFontMetrics(Font f) + { + return getFontMetrics(f); + } + + public boolean hitClip(int x, int y, int width, int height) + { + return graphics.hitClip(x,y,width,height); + } + + public void setClip(int x, int y, int width, int height) + { + graphics.setClip(x,y,width,height); + backBufferGraphics.setClip(x,y,width,height); + } + + public void setClip(Shape clip) + { + graphics.setClip(clip); + backBufferGraphics.setClip(clip); + } + + public void setColor(Color c) + { + graphics.setColor(c); + backBufferGraphics.setColor(c); + } + + public void setFont(Font font) + { + graphics.setFont(font); + backBufferGraphics.setFont(font); + } + + public void setPaintMode() + { + graphics.setPaintMode(); + backBufferGraphics.setPaintMode(); + } + + public void setXORMode(Color c1) + { + graphics.setXORMode(c1); + backBufferGraphics.setXORMode(c1); + } + + public String toString() + { + return graphics.toString(); + } + + public void translate(int x, int y) + { + graphics.translate(x,y); + backBufferGraphics.translate(x,y); + } + + //---------------------------------------------------------------------------------- + + // + // Graphics2D + // ========== + // + public void addRenderingHints(Map hints) + { + graphics.addRenderingHints(hints); + backBufferGraphics.addRenderingHints(hints); + } + + public void clip(Shape s) + { + graphics.clip(s); + backBufferGraphics.clip(s); + } + + public void draw(Shape s) + { + graphics.draw(s); + backBufferGraphics.draw(s); + } + + public void drawGlyphVector(GlyphVector g, float x, float y) + { + graphics.drawGlyphVector(g,x,y); + backBufferGraphics.drawGlyphVector(g,x,y); + } + + public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) + { + graphics.drawImage(img,op,x,y); + backBufferGraphics.drawImage(img,op,x,y); + } + + public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) + { + backBufferGraphics.drawImage(img,xform,obs); + return graphics.drawImage(img,xform,obs); + } + + public void drawRenderableImage(RenderableImage img, AffineTransform xform) + { + graphics.drawRenderableImage(img,xform); + backBufferGraphics.drawRenderableImage(img,xform); + } + + public void drawRenderedImage(RenderedImage img, AffineTransform xform) + { + graphics.drawRenderedImage(img,xform); + backBufferGraphics.drawRenderedImage(img,xform); + } + + public void drawString(AttributedCharacterIterator iterator, float x, float y) + { + graphics.drawString(iterator,x,y); + backBufferGraphics.drawString(iterator,x,y); + } + + public void drawString(String s, float x, float y) + { + graphics.drawString(s,x,y); + backBufferGraphics.drawString(s,x,y); + } + + public void fill(Shape s) + { + graphics.fill(s); + backBufferGraphics.fill(s); + } + + public Color getBackground() + { + return graphics.getBackground(); + } + + public Composite getComposite() + { + return graphics.getComposite(); + } + + public GraphicsConfiguration getDeviceConfiguration() + { + return graphics.getDeviceConfiguration(); + } + + public FontRenderContext getFontRenderContext() + { + return graphics.getFontRenderContext(); + } + + public Paint getPaint() + { + return graphics.getPaint(); + } + + public Object getRenderingHint(RenderingHints.Key hintKey) + { + return graphics.getRenderingHint(hintKey); + } + + public RenderingHints getRenderingHints() + { + return graphics.getRenderingHints(); + } + + public Stroke getStroke() + { + return graphics.getStroke(); + } + + public AffineTransform getTransform() + { + return graphics.getTransform(); + } + + public boolean hit(Rectangle rect, Shape s, boolean onStroke) + { + return graphics.hit(rect,s,onStroke); + } + + public void rotate(double theta) + { + graphics.rotate(theta); + backBufferGraphics.rotate(theta); + } + + public void rotate(double theta, double x, double y) + { + graphics.rotate(theta,x,y); + backBufferGraphics.rotate(theta,x,y); + } + + public void scale(double sx, double sy) + { + graphics.scale(sx,sy); + backBufferGraphics.scale(sx,sy); + } + + public void setBackground(Color color) + { + graphics.setBackground(color); + backBufferGraphics.setBackground(color); + } + + public void setComposite(Composite comp) + { + graphics.setComposite(comp); + backBufferGraphics.setComposite(comp); + } + + public void setPaint(Paint paint) + { + graphics.setPaint(paint); + backBufferGraphics.setPaint(paint); + } + + public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) + { + graphics.setRenderingHint(hintKey,hintValue); + backBufferGraphics.setRenderingHint(hintKey,hintValue); + } + + public void setRenderingHints(Map hints) + { + graphics.setRenderingHints(hints); + backBufferGraphics.setRenderingHints(hints); + } + + public void setStroke(Stroke s) + { + graphics.setStroke(s); + backBufferGraphics.setStroke(s); + } + + public void setTransform(AffineTransform Tx) + { + graphics.setTransform(Tx); + backBufferGraphics.setTransform(Tx); + } + + public void shear(double shx, double shy) + { + graphics.shear(shx,shy); + backBufferGraphics.shear(shx,shy); + } + + public void transform(AffineTransform Tx) + { + graphics.transform(Tx); + backBufferGraphics.transform(Tx); + } + + public void translate(double tx, double ty) + { + graphics.translate(tx,ty); + backBufferGraphics.translate(tx,ty); + } +} diff --git a/canvas/source/java/CanvasBase.java b/canvas/source/java/CanvasBase.java new file mode 100644 index 000000000000..b57430d5b329 --- /dev/null +++ b/canvas/source/java/CanvasBase.java @@ -0,0 +1,379 @@ +/************************************************************************* + * + * $RCSfile: CanvasBase.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// Java AWT +import java.awt.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public abstract class CanvasBase + extends com.sun.star.lib.uno.helper.ComponentBase + implements drafts.com.sun.star.rendering.XCanvas +{ + // to be overridden + public abstract Graphics2D getGraphics(); + + //---------------------------------------------------------------------------------- + + // + // XCanvas interface + // ================= + // + public synchronized void drawPoint( RealPoint2D aPoint, + ViewState viewState, + RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + // cache + Graphics2D graphics = getGraphics(); + + // initialize the Graphics2D + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + + // calculate the domain value for a single device pixel. we're + // using delta mapping here, to avoid later subtraction of two + // mapped values (as we really only need a transformed size, + // not a transformed point). + AffineTransform transform = graphics.getTransform(); + AffineTransform inverse; + try + { + inverse = transform.createInverse(); + } + catch( NoninvertibleTransformException e ) + { + // transformation not invertible. Nothing to render then. + return; + } + + java.awt.geom.Point2D.Double pointSize = new java.awt.geom.Point2D.Double(1.0,1.0); + java.awt.geom.Point2D.Double domainPointSize = new java.awt.geom.Point2D.Double(); + inverse.deltaTransform( pointSize, domainPointSize ); + + // render a circle one device pixel wide + Ellipse2D.Double ellipse = new Ellipse2D.Double(aPoint.X, aPoint.Y, domainPointSize.x, domainPointSize.y); + + // render, at last + graphics.fill( ellipse ); + + CanvasUtils.printLog( "XCanvas: drawPoint called" ); + } + + public synchronized void drawLine( RealPoint2D aStartPoint, + RealPoint2D aEndPoint, + ViewState viewState, + RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + // cache + Graphics2D graphics = getGraphics(); + + // initialize the Graphics2D + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + graphics.setStroke( new BasicStroke() ); + + // setup line object + Line2D.Double line = new Line2D.Double(aStartPoint.X, aStartPoint.Y, aEndPoint.X, aEndPoint.Y); + + // render, at last + graphics.draw( line ); + + CanvasUtils.printLog( "XCanvas: drawLine called" ); + } + + public synchronized void drawBezier( RealBezierSegment2D aBezierSegment, + RealPoint2D aEndPoint, + ViewState viewState, + RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + // cache + Graphics2D graphics = getGraphics(); + + // initialize the Graphics2D + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + graphics.setStroke( new BasicStroke() ); + + // setup bezier object + CubicCurve2D.Double curve = new CubicCurve2D.Double(aBezierSegment.Px, aBezierSegment.Py, + aBezierSegment.C1x, aBezierSegment.C1y, + aBezierSegment.C2x, aBezierSegment.C2y, + aEndPoint.X, aEndPoint.Y); + + // render, at last + graphics.draw( curve ); + + CanvasUtils.printLog( "XCanvas: drawbezier called" ); + } + + public synchronized XCachedPrimitive drawPolyPolygon( XPolyPolygon2D xPolyPolygon, + ViewState viewState, + RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + CanvasUtils.printLog( "CanvasBase.drawPolyPolygon() called" ); + + // cache + Graphics2D graphics = getGraphics(); + + // initialize the Graphics2D + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + graphics.setStroke( new BasicStroke() ); + + // render the polygon + // TODO: maybe use Graphics.drawPolyline here! + graphics.draw( CanvasUtils.makeGeneralPath(xPolyPolygon) ); + + CanvasUtils.printLog( "XCanvas: drawPolyPolygon called" ); + + return null; + } + + public synchronized XCachedPrimitive strokePolyPolygon( XPolyPolygon2D xPolyPolygon, + ViewState viewState, + RenderState renderState, + StrokeAttributes strokeAttributes ) throws com.sun.star.lang.IllegalArgumentException + { + // cache + Graphics2D graphics = getGraphics(); + + // initialize the Graphics2D + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + CanvasUtils.applyStrokeAttributes( graphics, strokeAttributes ); + + // stroke the polygon + graphics.draw( CanvasUtils.makeGeneralPath(xPolyPolygon) ); + + CanvasUtils.printLog( "XCanvas: strokePolyPolygon called" ); + + return null; + } + + public synchronized XCachedPrimitive strokeTexturedPolyPolygon( XPolyPolygon2D xPolyPolygon, + ViewState viewState, + RenderState renderState, + Texture[] textures, + StrokeAttributes strokeAttributes ) throws com.sun.star.lang.IllegalArgumentException, VolatileContentDestroyedException + { + return null; + } + + public synchronized XCachedPrimitive strokeTextureMappedPolyPolygon( XPolyPolygon2D xPolyPolygon, + ViewState viewState, + RenderState renderState, + Texture[] textures, + drafts.com.sun.star.geometry.XMapping2D xMapping, + StrokeAttributes strokeAttributes ) throws com.sun.star.lang.IllegalArgumentException, VolatileContentDestroyedException + { + return null; + } + + public synchronized XPolyPolygon2D queryStrokeShapes( drafts.com.sun.star.rendering.XPolyPolygon2D xPolyPolygon, + drafts.com.sun.star.rendering.ViewState viewState, + drafts.com.sun.star.rendering.RenderState renderState, + drafts.com.sun.star.rendering.StrokeAttributes strokeAttributes ) throws com.sun.star.lang.IllegalArgumentException + { + return null; + } + + public synchronized XCachedPrimitive fillPolyPolygon( drafts.com.sun.star.rendering.XPolyPolygon2D xPolyPolygon, + drafts.com.sun.star.rendering.ViewState viewState, + drafts.com.sun.star.rendering.RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + CanvasUtils.printLog( "CanvasBase.fillPolyPolygon() called" ); + + // cache + Graphics2D graphics = getGraphics(); + + // initialize the Graphics2D + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + + // fill the polygon + graphics.fill( CanvasUtils.makeGeneralPath(xPolyPolygon) ); + + CanvasUtils.printLog( "XCanvas: fillPolyPolygon called" ); + + return null; + } + + public synchronized XCachedPrimitive fillTexturedPolyPolygon( drafts.com.sun.star.rendering.XPolyPolygon2D xPolyPolygon, + drafts.com.sun.star.rendering.ViewState viewState, + drafts.com.sun.star.rendering.RenderState renderState, + drafts.com.sun.star.rendering.Texture [] textures ) throws com.sun.star.lang.IllegalArgumentException + { + return null; + } + + public synchronized XCachedPrimitive fillTextureMappedPolyPolygon( XPolyPolygon2D xPolyPolygon, + ViewState viewState, + RenderState renderState, + Texture[] textures, + drafts.com.sun.star.geometry.XMapping2D xMapping ) throws com.sun.star.lang.IllegalArgumentException, VolatileContentDestroyedException + { + return null; + } + + public synchronized XCanvasFont queryFont( drafts.com.sun.star.rendering.FontRequest fontRequest ) throws com.sun.star.lang.IllegalArgumentException + { + return new CanvasFont( fontRequest, this ); + } + + public synchronized XCachedPrimitive drawText( drafts.com.sun.star.rendering.StringContext text, + drafts.com.sun.star.rendering.XCanvasFont xFont, + drafts.com.sun.star.rendering.ViewState viewState, + drafts.com.sun.star.rendering.RenderState renderState, + byte textDirection ) throws com.sun.star.lang.IllegalArgumentException + { + CanvasUtils.printLog( "CanvasBase.drawText() called" ); + + // cache + Graphics2D graphics = getGraphics(); + + CanvasUtils.printLog( "XCanvas: drawText called" ); + + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + CanvasUtils.setupGraphicsFont( graphics, viewState, renderState, xFont ); + + CanvasUtils.printLog( "XCanvas: drawText rendering \""+ text.Text.substring(text.StartPosition, text.StartPosition+text.Length) + "\"" ); + + graphics.drawString( text.Text.substring(text.StartPosition, text.StartPosition+text.Length), (float)0.0, (float)0.0 ); + return null; + } + + public synchronized XCachedPrimitive drawOffsettedText( drafts.com.sun.star.rendering.StringContext text, + drafts.com.sun.star.rendering.XCanvasFont xFont, + double [] offsets, + drafts.com.sun.star.rendering.ViewState viewState, + drafts.com.sun.star.rendering.RenderState renderState, + byte textDirection ) throws com.sun.star.lang.IllegalArgumentException + { + CanvasUtils.printLog( "CanvasBase.drawOffsettedText() called" ); + + CanvasUtils.preCondition( text.Length == text.Text.length() && + text.Length == offsets.length, "CanvasBase.drawOffsettedText" ); + + if( text.Length > 0 ) + { + // cache + Graphics2D graphics = getGraphics(); + + CanvasUtils.printLog( "XCanvas: drawOffsettedText called" ); + + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + CanvasUtils.setupGraphicsFont( graphics, viewState, renderState, xFont ); + + CanvasUtils.printLog( "XCanvas: drawOffsettedText canvas setup done" ); + + // TODO: use proper advancement. Text direction need not be horizontal! + // TODO: given text string need not have a one-to-one relationship between code point and glyph (offset)! + graphics.drawString( text.Text.substring(text.StartPosition, text.StartPosition + 1), (float)0.0, (float)0.0 ); + for( int i=1; i 1.0 ) currAlpha = 0.1f; + // TEST ONLY } + } + + if( true ) + { + // repaint background + backBuffer.redraw( graph ); + + // repaint all active sprites + java.util.Set entries = activeSprites.entrySet(); + java.util.Iterator iter = entries.iterator(); + while( iter.hasNext() ) + { + java.util.Map.Entry entry = (java.util.Map.Entry)iter.next(); + if( entry.getValue() != null ) + ((SpriteRep)entry.getValue()).redraw(graph); + } + } + + long currTime = System.currentTimeMillis(); + graph.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER) ); + graph.setFont( fpsFont ); + graph.setColor( java.awt.Color.black ); + + try + { + String fps = new String( String.valueOf(1000.0/(currTime-lastTime)) ); + graph.drawString( fps.substring(0,5) + " fps", 0, 20); + CanvasUtils.printLog( fps.substring(0,5) + " fps" ); + } + catch( Exception e ) + { + graph.drawString( "0 fps", 0, 20); + } + + lastTime = currTime; + } + finally + { + if( graph != null ) + graph.dispose(); + } + + bufferStrategy.show(); + } + + //---------------------------------------------------------------------------------- + + private static final String s_implName = "XCanvas.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.Canvas"; + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + public synchronized String getImplementationName() + { + return s_implName; + } + + public synchronized String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public synchronized boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } + + public static com.sun.star.lang.XSingleServiceFactory __getServiceFactory( + String implName, + com.sun.star.lang.XMultiServiceFactory multiFactory, + com.sun.star.registry.XRegistryKey regKey ) + { + if (implName.equals( s_implName )) + { + return com.sun.star.comp.loader.FactoryHelper.getServiceFactory( + CanvasTest.class, s_serviceName, multiFactory, regKey ); + } + return null; + } + + public static boolean __writeRegistryServiceInfo( + com.sun.star.registry.XRegistryKey regKey ) + { + return com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo( + s_implName, s_serviceName, regKey ); + } +} diff --git a/canvas/source/java/CanvasUtils.java b/canvas/source/java/CanvasUtils.java new file mode 100644 index 000000000000..0df1f69768ca --- /dev/null +++ b/canvas/source/java/CanvasUtils.java @@ -0,0 +1,670 @@ +/************************************************************************* + * + * $RCSfile: CanvasUtils.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// Java AWT +import java.awt.*; +import java.awt.image.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public class CanvasUtils +{ + // + // Canvas utilities + // ================ + // + public static java.awt.geom.AffineTransform makeTransform( AffineMatrix2D ooTransform ) + { + return new AffineTransform( ooTransform.m00, + ooTransform.m10, + ooTransform.m01, + ooTransform.m11, + ooTransform.m02, + ooTransform.m12 ); + } + + public static AffineMatrix2D makeAffineMatrix2D( java.awt.geom.AffineTransform transform ) + { + double[] matrix = new double[6]; + transform.getMatrix( matrix ); + + return new AffineMatrix2D( matrix[0], matrix[2], matrix[4], + matrix[1], matrix[3], matrix[5] ); + } + + public static void initGraphics( Graphics2D graphics ) + { + if( graphics != null ) + { + java.awt.RenderingHints hints = new java.awt.RenderingHints(null); + boolean hq = true; + + if( hq ) + { + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_FRACTIONALMETRICS, + java.awt.RenderingHints.VALUE_FRACTIONALMETRICS_ON ) ); +// hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_ALPHA_INTERPOLATION, +// java.awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_ALPHA_INTERPOLATION, + java.awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED) ); +// hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_INTERPOLATION, +// java.awt.RenderingHints.VALUE_INTERPOLATION_BICUBIC) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_INTERPOLATION, + java.awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR) ); +// hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_RENDERING, +// java.awt.RenderingHints.VALUE_RENDER_QUALITY) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_RENDERING, + java.awt.RenderingHints.VALUE_RENDER_SPEED) ); +// hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_STROKE_CONTROL, +// java.awt.RenderingHints.VALUE_STROKE_NORMALIZE) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_STROKE_CONTROL, + java.awt.RenderingHints.VALUE_STROKE_DEFAULT) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_ANTIALIASING, + java.awt.RenderingHints.VALUE_ANTIALIAS_ON) ); + } + else + { + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_ALPHA_INTERPOLATION, + java.awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_INTERPOLATION, + java.awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_RENDERING, + java.awt.RenderingHints.VALUE_RENDER_SPEED) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_STROKE_CONTROL, + java.awt.RenderingHints.VALUE_STROKE_DEFAULT) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_ANTIALIASING, + java.awt.RenderingHints.VALUE_ANTIALIAS_OFF) ); + } + + // the least common denominator standard + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_FRACTIONALMETRICS, + java.awt.RenderingHints.VALUE_FRACTIONALMETRICS_ON) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_TEXT_ANTIALIASING, + java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON) ); + + graphics.setRenderingHints( hints ); + } + } + + //---------------------------------------------------------------------------------- + + public static java.awt.geom.GeneralPath makeGenPathFromBezierPoints( RealBezierSegment2D [][] points ) + { + java.awt.geom.GeneralPath path = new java.awt.geom.GeneralPath(); + + // extract every polygon into GeneralPath object + for( int i=0; i 0 ) + path.moveTo((float) points[i][0].Px, (float) points[i][0].Py); + + for( int j=1; j 0 ) + path.moveTo((float) points[i][0].X, (float) points[i][0].Y); + + for( int j=1; j +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_RENDERSTATE_HPP__ +#include +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_VIEWSTATE_HPP__ +#include +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XCANVAS_HPP__ +#include +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_COMPOSITEOPERATION_HPP__ +#include +#endif + +#ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX +#include +#endif +#ifndef _BGFX_RANGE_B2DRANGE_HXX +#include +#endif +#ifndef _BGFX_RANGE_B2DRECTANGLE_HXX +#include +#endif +#ifndef _BGFX_POINT_B2DPOINT_HXX +#include +#endif +#ifndef _BGFX_TOOLS_CANVASTOOLS_HXX +#include +#endif + +#include + +#include +#include + + +using namespace ::drafts::com::sun::star; +using namespace ::com::sun::star; + +namespace canvas +{ + + namespace tools + { + rendering::RenderState& initRenderState( rendering::RenderState& renderState ) + { + // setup identity transform + setIdentityAffineMatrix2D( renderState.AffineTransform ); + renderState.Clip = uno::Reference< rendering::XPolyPolygon2D >(); + renderState.DeviceColor = uno::Sequence< double >(); + renderState.CompositeOperation = rendering::CompositeOperation::OVER; + + return renderState; + } + + rendering::ViewState& initViewState( rendering::ViewState& viewState ) + { + // setup identity transform + setIdentityAffineMatrix2D( viewState.AffineTransform ); + viewState.Clip = uno::Reference< rendering::XPolyPolygon2D >(); + + return viewState; + } + + ::basegfx::B2DHomMatrix& getViewStateTransform( ::basegfx::B2DHomMatrix& transform, + const rendering::ViewState& viewState ) + { + return ::basegfx::unotools::homMatrixFromAffineMatrix( transform, viewState.AffineTransform ); + } + + rendering::ViewState& setViewStateTransform( rendering::ViewState& viewState, + const ::basegfx::B2DHomMatrix& transform ) + { + ::basegfx::unotools::affineMatrixFromHomMatrix( viewState.AffineTransform, transform ); + + return viewState; + } + + ::basegfx::B2DHomMatrix& getRenderStateTransform( ::basegfx::B2DHomMatrix& transform, + const rendering::RenderState& renderState ) + { + return ::basegfx::unotools::homMatrixFromAffineMatrix( transform, renderState.AffineTransform ); + } + + rendering::RenderState& setRenderStateTransform( rendering::RenderState& renderState, + const ::basegfx::B2DHomMatrix& transform ) + { + ::basegfx::unotools::affineMatrixFromHomMatrix( renderState.AffineTransform, transform ); + + return renderState; + } + + rendering::RenderState& appendToRenderState( rendering::RenderState& renderState, + const ::basegfx::B2DHomMatrix& rTransform ) + { + ::basegfx::B2DHomMatrix transform; + + getRenderStateTransform( transform, renderState ); + return setRenderStateTransform( renderState, transform * rTransform ); + } + + rendering::ViewState& appendToViewState( rendering::ViewState& viewState, + const ::basegfx::B2DHomMatrix& rTransform ) + { + ::basegfx::B2DHomMatrix transform; + + getViewStateTransform( transform, viewState ); + return setViewStateTransform( viewState, transform * rTransform ); + } + + rendering::RenderState& prependToRenderState( rendering::RenderState& renderState, + const ::basegfx::B2DHomMatrix& rTransform ) + { + ::basegfx::B2DHomMatrix transform; + + getRenderStateTransform( transform, renderState ); + return setRenderStateTransform( renderState, rTransform * transform ); + } + + rendering::ViewState& prependToViewState( rendering::ViewState& viewState, + const ::basegfx::B2DHomMatrix& rTransform ) + { + ::basegfx::B2DHomMatrix transform; + + getViewStateTransform( transform, viewState ); + return setViewStateTransform( viewState, rTransform * transform ); + } + + ::basegfx::B2DHomMatrix& mergeViewAndRenderTransform( ::basegfx::B2DHomMatrix& combinedTransform, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState ) + { + ::basegfx::B2DHomMatrix viewTransform; + + ::basegfx::unotools::homMatrixFromAffineMatrix( combinedTransform, renderState.AffineTransform ); + ::basegfx::unotools::homMatrixFromAffineMatrix( viewTransform, viewState.AffineTransform ); + + // this statement performs combinedTransform = viewTransform * combinedTransform + combinedTransform *= viewTransform; + + return combinedTransform; + } + + rendering::ViewState& mergeViewAndRenderState( rendering::ViewState& resultViewState, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + const uno::Reference< rendering::XCanvas > xCanvas ) + { + ::basegfx::B2DHomMatrix aTmpMatrix; + geometry::AffineMatrix2D convertedMatrix; + + resultViewState.Clip = NULL; // TODO: intersect clippings + + return setViewStateTransform( + resultViewState, + mergeViewAndRenderTransform( aTmpMatrix, + viewState, + renderState ) ); + } + + geometry::AffineMatrix2D& setIdentityAffineMatrix2D( geometry::AffineMatrix2D& matrix ) + { + matrix.m00 = 1.0; + matrix.m01 = 0.0; + matrix.m02 = 0.0; + matrix.m10 = 0.0; + matrix.m11 = 1.0; + matrix.m12 = 0.0; + + return matrix; + } + + bool operator==( const rendering::RenderState& renderState1, + const rendering::RenderState& renderState2 ) + { + if( renderState1.Clip != renderState2.Clip ) + return false; + + if( renderState1.DeviceColor != renderState2.DeviceColor ) + return false; + + if( renderState1.CompositeOperation != renderState2.CompositeOperation ) + return false; + + ::basegfx::B2DHomMatrix mat1, mat2; + getRenderStateTransform( mat1, renderState1 ); + getRenderStateTransform( mat2, renderState2 ); + if( mat1 != mat2 ) + return false; + + return true; + } + + bool operator==( const rendering::ViewState& viewState1, + const rendering::ViewState& viewState2 ) + { + if( viewState1.Clip != viewState2.Clip ) + return false; + + ::basegfx::B2DHomMatrix mat1, mat2; + getViewStateTransform( mat1, viewState1 ); + getViewStateTransform( mat2, viewState2 ); + if( mat1 != mat2 ) + return false; + + return true; + } + + // Create a corrected view transformation out of the give one, + // which ensures that the rectangle given by (0,0) and + // rSpriteSize is mapped with its left,top corner to (0,0) + // again. This is required to properly render sprite + // animations to buffer bitmaps. + ::basegfx::B2DHomMatrix& calcRectToOriginTransform( ::basegfx::B2DHomMatrix& o_transform, + const ::basegfx::B2DRange& i_srcRect, + const ::basegfx::B2DHomMatrix& i_transformation ) + { + // transform by given transformation + ::basegfx::B2DRectangle aTransformedRect; + + calcTransformedRectBounds( aTransformedRect, + i_srcRect, + i_transformation ); + + // now move resulting left,top point of bounds to (0,0) + ::basegfx::B2DHomMatrix aCorrectedTransform; + aCorrectedTransform.translate( -aTransformedRect.getMinX(), + -aTransformedRect.getMinY() ); + + // prepend to original transformation + o_transform = aCorrectedTransform * i_transformation; + + return o_transform; + } + + ::basegfx::B2DRange& calcTransformedRectBounds( ::basegfx::B2DRange& outRect, + const ::basegfx::B2DRange& inRect, + const ::basegfx::B2DHomMatrix& transformation ) + { + double left, top, bottom, right; + + // transform all four extremal points of the rectangle, + // take bounding rect of those. + ::basegfx::B2DPoint aPoint; + + // transform left-top point + aPoint.setX( inRect.getMinX() ); + aPoint.setY( inRect.getMinY() ); + + aPoint *= transformation; + left = right = aPoint.getX(); + top = bottom = aPoint.getY(); + + // transform bottom-right point + aPoint.setX( inRect.getMaxX() ); + aPoint.setY( inRect.getMaxY() ); + + aPoint *= transformation; + left = ::std::min(left, aPoint.getX()); + top = ::std::min(top, aPoint.getY()); + right = ::std::max(right, aPoint.getX()); + bottom = ::std::max(bottom, aPoint.getY()); + + // transform top-right point + aPoint.setX( inRect.getMaxX() ); + aPoint.setY( inRect.getMinY() ); + + aPoint *= transformation; + left = ::std::min(left, aPoint.getX()); + top = ::std::min(top, aPoint.getY()); + right = ::std::max(right, aPoint.getX()); + bottom = ::std::max(bottom, aPoint.getY()); + + // transform bottom-left point + aPoint.setX( inRect.getMinX() ); + aPoint.setY( inRect.getMaxY() ); + + aPoint *= transformation; + left = ::std::min(left, aPoint.getX()); + top = ::std::min(top, aPoint.getY()); + right = ::std::max(right, aPoint.getX()); + bottom = ::std::max(bottom, aPoint.getY()); + + // over and out. + outRect = ::basegfx::B2DRectangle( left, top, right, bottom ); + return outRect; + } + + ::basegfx::B2DHomMatrix& calcRectToRectTransform( ::basegfx::B2DHomMatrix& o_transform, + const ::basegfx::B2DRange& destRect, + const ::basegfx::B2DRange& srcRect, + const ::basegfx::B2DHomMatrix& transformation ) + { + // transform inputRect by transformation + ::basegfx::B2DRectangle aTransformedRect; + calcTransformedRectBounds( aTransformedRect, + srcRect, + transformation ); + + // now move resulting left,top point of bounds to (0,0) + ::basegfx::B2DHomMatrix aCorrectedTransform; + aCorrectedTransform.translate( -aTransformedRect.getMinX(), + -aTransformedRect.getMinY() ); + + // scale to match outRect + const double xDenom( aTransformedRect.getWidth() ); + const double yDenom( aTransformedRect.getHeight() ); + if( xDenom != 0.0 && yDenom != 0.0 ) + aCorrectedTransform.scale( destRect.getWidth() / xDenom, + destRect.getHeight() / yDenom ); + // TODO: error handling + + // translate to final position + aCorrectedTransform.translate( destRect.getMinX(), + destRect.getMinY() ); + + ::basegfx::B2DHomMatrix transform( transformation ); + o_transform = aCorrectedTransform * transform; + + return o_transform; + } + + } // namespace tools + +} // namespace canvas diff --git a/canvas/source/tools/canvastools.flt b/canvas/source/tools/canvastools.flt new file mode 100644 index 000000000000..90ec48c26d4e --- /dev/null +++ b/canvas/source/tools/canvastools.flt @@ -0,0 +1,4 @@ +__CT +Impl +IMP +internal diff --git a/canvas/source/tools/elapsedtime.cxx b/canvas/source/tools/elapsedtime.cxx new file mode 100644 index 000000000000..bbc4b1d6dcb5 --- /dev/null +++ b/canvas/source/tools/elapsedtime.cxx @@ -0,0 +1,184 @@ +/************************************************************************* + * + * $RCSfile: elapsedtime.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _OSL_TIME_H_ +#include +#endif + +#include + +#ifdef WIN + +// TEMP!!! +// Awaiting corresponding functionality in OSL +// +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#endif + + +namespace canvas +{ + namespace tools + { + namespace + { +#ifdef WIN + static double fTimeFactor; +#endif + + double getTimeFactor() + { +#ifndef WIN + // value is in nanoseconds + return 1.0/10e9; +#else + // value is hardware-dependent + return fTimeFactor; +#endif + } + + sal_uInt64 getCurrentTime() + { +#ifndef WIN + TimeValue aTimeVal; + sal_uInt64 bRet( 0 ); + + if( osl_getSystemTime( &aTimeVal ) ) + { + // combine to seconds + fraction of second + bRet = ((sal_uInt64)aTimeVal.Seconds) * (sal_uInt64)1000000000 + (sal_uInt64)aTimeVal.Nanosec; + } +#else + sal_uInt64 bRet( 0 ); + + // TEMP!!! + // Awaiting corresponding functionality in OSL + // + + // is there a performance counter available? + static bool bTimeSetupDone( false ); + static bool bPerfTimerAvailable; + + if( !bTimeSetupDone ) + { + LONGLONG nPerfCount; + if( QueryPerformanceFrequency((LARGE_INTEGER *) &nPerfCount) ) + { + // yes, timer choice flag + bPerfTimerAvailable = true; + + // set scaling factor + fTimeFactor = 1.0/nPerfCount; + } + else + { + // no performance counter, read in using timeGetTime + bPerfTimerAvailable = false; + + // set timer scaling factor + fTimeFactor = 0.001; + } + + bTimeSetupDone = true; + } + + if( bPerfTimerAvailable ) + { + LONGLONG nCurrTime; + + // read initial time + QueryPerformanceCounter((LARGE_INTEGER *) &nCurrTime); + + bRet = nCurrTime; + } + else + { + bRet = timeGetTime(); + } +#endif + + return bRet; // TODO: is 0 okay for the failure case here? + } + } + + ElapsedTime::ElapsedTime() : + mnStartTime( getCurrentTime() ), + mfTimeFactor( getTimeFactor() ) + { + } + + void ElapsedTime::reset() + { + mnStartTime = getCurrentTime(); + } + + double ElapsedTime::getElapsedTime() + { + sal_uInt64 nCurrTime( getCurrentTime() ); + + return mfTimeFactor * (nCurrTime - mnStartTime); + } + + } +} diff --git a/canvas/source/tools/makefile.mk b/canvas/source/tools/makefile.mk new file mode 100644 index 000000000000..013d5a03bf4d --- /dev/null +++ b/canvas/source/tools/makefile.mk @@ -0,0 +1,104 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.2 $ +# +# last change: $Author: thb $ $Date: 2004-03-18 10:38:37 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=canvas +TARGET=canvastools +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Common ---------------------------------------------------------- + +.IF "$(verbose)"!="" || "$(VERBOSE)"!="" +CDEFS+= -DVERBOSE +.ENDIF + +SLOFILES = $(SLO)$/canvastools.obj $(SLO)$/elapsedtime.obj + +SHL1TARGET= $(TARGET)$(UPD)$(DLLPOSTFIX) +SHL1IMPLIB= i$(TARGET) +SHL1STDLIBS= $(SALLIB) $(CPPULIB) $(BASEGFXLIB) + +SHL1LIBS= $(SLB)$/$(TARGET).lib + +SHL1DEF= $(MISC)$/$(SHL1TARGET).def +DEF1NAME =$(SHL1TARGET) +DEF1DEPN =$(MISC)$/$(SHL1TARGET).flt \ + $(LIB1TARGET) + +DEF1DES =Canvastools +DEFLIB1NAME =$(TARGET) + +.IF "$(GUI)" == "WNT" +SHL1STDLIBS += winmm.lib kernel32.lib +.ENDIF + +# ========================================================================== + +.INCLUDE : target.mk + +$(MISC)$/$(SHL1TARGET).flt : makefile.mk + @+$(TYPE) $(TARGET).flt > $@ diff --git a/canvas/source/vcl/canvasbitmap.cxx b/canvas/source/vcl/canvasbitmap.cxx new file mode 100644 index 000000000000..ed5fbab62737 --- /dev/null +++ b/canvas/source/vcl/canvasbitmap.cxx @@ -0,0 +1,451 @@ +/************************************************************************* + * + * $RCSfile: canvasbitmap.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:39 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _SV_BMPACC_HXX +#include +#endif +#ifndef _VCL_CANVASTOOLS_HXX +#include +#endif + +#include + +#include "canvasbitmap.hxx" +#include "bitmapcanvas.hxx" +#include "impltools.hxx" + +using namespace ::com::sun::star; +using namespace ::drafts::com::sun::star; + +namespace vclcanvas +{ + // Currently, the only way to generate an XBitmap is from + // XGraphicDevice.getCompatibleBitmap(). Therefore, we don't even + // take a bitmap here, but a VDev directly. + CanvasBitmap::CanvasBitmap( const ::Size& rSize, + const OutDevProvider::ImplRef& rReferenceCanvas ) : + mpReferenceCanvas( rReferenceCanvas ), + mpBitmapCanvas( new BitmapCanvas( rSize, + rReferenceCanvas ) ) + { + } + + CanvasBitmap::CanvasBitmap( const BitmapEx& rBitmap, + const OutDevProvider::ImplRef& rReferenceCanvas ) : + mpReferenceCanvas( rReferenceCanvas ), + mpBitmapCanvas( new BitmapCanvas( rBitmap.GetSizePixel(), + rReferenceCanvas ) ) + { + // TODO: Support alpha canvas here + VirtualDevice& rVDev( getVirDev() ); + rVDev.EnableMapMode( FALSE ); + const Point aEmptyPoint(0,0); + rVDev.DrawBitmapEx(aEmptyPoint, rBitmap); + } + + CanvasBitmap::~CanvasBitmap() + { + } + + geometry::IntegerSize2D SAL_CALL CanvasBitmap::getSize( ) throw (uno::RuntimeException) + { + tools::LocalGuard aGuard; + return ::vcl::unotools::integerSize2DFromSize( getVirDev().GetOutputSizePixel() ); + } + + uno::Reference< rendering::XBitmapCanvas > SAL_CALL CanvasBitmap::queryBitmapCanvas( ) throw (uno::RuntimeException) + { + return mpBitmapCanvas.getRef(); + } + + uno::Reference< rendering::XBitmap > SAL_CALL CanvasBitmap::getScaledBitmap( const geometry::RealSize2D& newSize, sal_Bool beFast ) throw (uno::RuntimeException) + { + tools::LocalGuard aGuard; + +#if 0 + // TODO: To be used when dealing with real bitmaps here + BitmapEx aRes( *maBitmap ); + + aRes.Scale( ::canvas::tools::sizeFromRealSize2D(newSize), + beFast ? BMP_SCALE_FAST : BMP_SCALE_INTERPOLATE ); + + return uno::Reference< rendering::XBitmap >( new CanvasBitmap( aRes ) ); +#else + // TODO: Support alpha canvas here + VirtualDevice& rVDev( getVirDev() ); + const Point aEmptyPoint(0,0); + const Size aBmpSize( rVDev.GetOutputSizePixel() ); + + Bitmap aBitmap( rVDev.GetBitmap(aEmptyPoint, aBmpSize) ); + + aBitmap.Scale( ::vcl::unotools::sizeFromRealSize2D(newSize), + beFast ? BMP_SCALE_FAST : BMP_SCALE_INTERPOLATE ); + + return uno::Reference< rendering::XBitmap >( new CanvasBitmap( aBitmap, + mpReferenceCanvas ) ); +#endif + } + + uno::Sequence< sal_Int8 > SAL_CALL CanvasBitmap::getData( const geometry::IntegerRectangle2D& rect ) throw (lang::IndexOutOfBoundsException, rendering::VolatileContentDestroyedException,uno::RuntimeException) + { + tools::LocalGuard aGuard; + +#if 0 + // TODO: To be used when dealing with real bitmaps here + Bitmap aBitmap( maBitmap->GetBitmap() ); + Bitmap aAlpha( maBitmap->GetAlpha().GetBitmap() ); +#else + // TODO: Support alpha canvas here + VirtualDevice& rVDev( getVirDev() ); + const Point aEmptyPoint(0,0); + const Size aBmpSize( rVDev.GetOutputSizePixel() ); + + Bitmap aBitmap( rVDev.GetBitmap(aEmptyPoint, aBmpSize) ); + Bitmap aAlpha( Bitmap( aBmpSize, 8) ); +#endif + + ScopedBitmapReadAccess pReadAccess( aBitmap.AcquireReadAccess(), + aBitmap ); + ScopedBitmapReadAccess pAlphaReadAccess( aAlpha.AcquireReadAccess(), + aAlpha ); + + if( pReadAccess.get() != NULL && + pAlphaReadAccess.get() != NULL ) + { + // TODO: Support more formats. + const Size aBmpSize( aBitmap.GetSizePixel() ); + + // for the time being, always return as BGRA + uno::Sequence< sal_Int8 > aRes( 4*aBmpSize.Width()*aBmpSize.Height() ); + + int nCurrPos(0); + for( int y=rect.Y1; + yGetColor( y, x ).GetBlue(); + aRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetGreen(); + aRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetRed(); + aRes[ nCurrPos++ ] = pAlphaReadAccess->GetPixel( y, x ).GetIndex(); + } + } + + return aRes; + } + + return uno::Sequence< sal_Int8 >(); + } + + void SAL_CALL CanvasBitmap::setData( const uno::Sequence< sal_Int8 >& data, const geometry::IntegerRectangle2D& rect ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + +#if 0 + // TODO: To be used when dealing with real bitmaps here + + // retrieve local copies from the BitmapEx, which are later + // stored back. Unfortunately, the BitmapEx does not permit + // in-place modifications, as they are necessary here. + Bitmap aBitmap( maBitmap->GetBitmap() ); + Bitmap aAlpha( maBitmap->GetAlpha().GetBitmap() ); +#else + // TODO: Support alpha canvas here + VirtualDevice& rVDev( getVirDev() ); + const Point aEmptyPoint(0,0); + const Size aBmpSize( rVDev.GetOutputSizePixel() ); + + Bitmap aBitmap( rVDev.GetBitmap(aEmptyPoint, aBmpSize) ); + Bitmap aAlpha( Bitmap( aBmpSize, 8) ); +#endif + + bool bCopyBack( false ); // only copy something back, if we + // actually changed pixel + + { + ScopedBitmapWriteAccess pWriteAccess( aBitmap.AcquireWriteAccess(), + aBitmap ); + ScopedBitmapWriteAccess pAlphaWriteAccess( aAlpha.AcquireWriteAccess(), + aAlpha ); + + if( pWriteAccess.get() != NULL && + pAlphaWriteAccess.get() != NULL ) + { + // TODO: Support more formats. + const Size aBmpSize( aBitmap.GetSizePixel() ); + + // for the time being, always read as BGRA + int nCurrPos(0); + for( int y=rect.Y1; + ySetPixel( y, x, BitmapColor( data[ nCurrPos+2 ], + data[ nCurrPos+1 ], + data[ nCurrPos ] ) ); + nCurrPos += 3; + + pAlphaWriteAccess->SetPixel( y, x, BitmapColor( 255 - data[ nCurrPos++ ] ) ); + } + } + + bCopyBack = true; + } + } + + // copy back only here, since the BitmapAccessors must be + // destroyed beforehand + if( bCopyBack ) + { +#if 0 + // TODO: To be used when dealing with real bitmaps here + maBitmap = BitmapEx( aBitmap, + AlphaMask( aAlpha ) ); +#else + // TODO: Support alpha canvas here + VirtualDevice& rVDev( getVirDev() ); + rVDev.EnableMapMode( FALSE ); + const Point aEmptyPoint(0,0); + rVDev.DrawBitmap(aEmptyPoint, aBitmap); +#endif + } + } + + void SAL_CALL CanvasBitmap::setPixel( const uno::Sequence< sal_Int8 >& color, const geometry::IntegerPoint2D& pos ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + +#if 0 + // TODO: To be used when dealing with real bitmaps here + const Size aBmpSize( maBitmap->GetSizePixel() ); +#else + const Size aBmpSize( getVirDev().GetOutputSizePixel() ); +#endif + + OSL_ENSURE( pos.X >= 0 && pos.X < aBmpSize.Width(), "CanvasBitmap::setPixel: X coordinate out of bounds" ); + OSL_ENSURE( pos.Y >= 0 && pos.Y < aBmpSize.Height(), "CanvasBitmap::setPixel: Y coordinate out of bounds" ); + OSL_ENSURE( color.getLength() > 3, "CanvasBitmap::setPixel: not enough color components" ); + +#if 0 + // TODO: To be used when dealing with real bitmaps here + // retrieve local copies from the BitmapEx, which are later + // stored back. Unfortunately, the BitmapEx does not permit + // in-place modifications, as they are necessary here. + Bitmap aBitmap( maBitmap->GetBitmap() ); + Bitmap aAlpha( maBitmap->GetAlpha().GetBitmap() ); + + bool bCopyBack( false ); // only copy something back, if we + // actually changed a pixel + + { + ScopedBitmapWriteAccess pWriteAccess( aBitmap.AcquireWriteAccess(), + aBitmap ); + ScopedBitmapWriteAccess pAlphaWriteAccess( aAlpha.AcquireWriteAccess(), + aAlpha ); + + if( pWriteAccess.get() != NULL && + pAlphaWriteAccess.get() != NULL ) + { + pWriteAccess->SetPixel( pos.Y, pos.X, BitmapColor( color[ 2 ], + color[ 1 ], + color[ 0 ] ) ); + pAlphaWriteAccess->SetPixel( pos.Y, pos.X, BitmapColor( 255 - color[ 3 ] ) ); + } + } + + // copy back only here, since the BitmapAccessors must be + // destroyed beforehand + if( bCopyBack ) + { + maBitmap = BitmapEx( aBitmap, + AlphaMask( aAlpha ) ); + } +#else + VirtualDevice& rVDev( getVirDev() ); + rVDev.EnableMapMode( FALSE ); + + uno::Reference< rendering::XCanvas > xCanvas( mpBitmapCanvas.getRef(), + uno::UNO_QUERY ); + OSL_ENSURE( xCanvas.is(), "CanvasBitmap::setPixel(): Invalid reference canvas" ); + + getVirDev().DrawPixel( ::vcl::unotools::pointFromIntegerPoint2D( pos ), + ::vcl::unotools::sequenceToColor( + xCanvas->getDevice(), + color ) ); +#endif + } + + uno::Sequence< sal_Int8 > SAL_CALL CanvasBitmap::getPixel( const geometry::IntegerPoint2D& pos ) throw (lang::IndexOutOfBoundsException, rendering::VolatileContentDestroyedException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + +#if 0 + // TODO: To be used when dealing with real bitmaps here + const Size aBmpSize( maBitmap->GetSizePixel() ); +#else + const Size aBmpSize( getVirDev().GetOutputSizePixel() ); +#endif + + OSL_ENSURE( pos.X >= 0 && pos.X < aBmpSize.Width(), "CanvasBitmap::getPixel: X coordinate out of bounds" ); + OSL_ENSURE( pos.Y >= 0 && pos.Y < aBmpSize.Height(), "CanvasBitmap::getPixel: Y coordinate out of bounds" ); + +#if 0 + // TODO: To be used when dealing with real bitmaps here + Bitmap aBitmap( maBitmap->GetBitmap() ); + Bitmap aAlpha( maBitmap->GetAlpha().GetBitmap() ); + ScopedBitmapReadAccess pReadAccess( aBitmap.AcquireReadAccess(), + aBitmap ); + ScopedBitmapReadAccess pAlphaReadAccess( aAlpha.AcquireReadAccess(), + aAlpha ); + + if( pReadAccess.get() != NULL && + pAlphaReadAccess.get() != NULL ) + { + // for the time being, always return as BGRA + uno::Sequence< sal_Int8 > aRes( 4 ); + + const BitmapColor aColor( pReadAccess->GetColor( pos.Y, pos.X ) ); + aRes[ 3 ] = aColor.GetRed(); + aRes[ 2 ] = aColor.GetGreen(); + aRes[ 1 ] = aColor.GetBlue(); + + aRes[ 3 ] = pAlphaReadAccess->GetPixel( pos.Y, pos.X ).GetIndex(); + + return aRes; + } + + return uno::Sequence< sal_Int8 >(); +#else + VirtualDevice& rVDev( getVirDev() ); + rVDev.EnableMapMode( FALSE ); + + uno::Reference< rendering::XCanvas > xCanvas(mpBitmapCanvas.getRef(), + uno::UNO_QUERY); + + OSL_ENSURE( xCanvas.is(), "CanvasBitmap::getPixel(): Invalid reference canvas" ); + + return ::vcl::unotools::colorToIntSequence( + xCanvas->getDevice(), + getVirDev().GetPixel( ::vcl::unotools::pointFromIntegerPoint2D( pos ) ) ); +#endif + } + + uno::Reference< rendering::XBitmapPalette > SAL_CALL CanvasBitmap::getPalette( ) throw (uno::RuntimeException) + { + return uno::Reference< rendering::XBitmapPalette >(); + } + + rendering::IntegerBitmapLayout SAL_CALL CanvasBitmap::getMemoryLayout( ) throw (uno::RuntimeException) + { + // TODO: finish that one + rendering::IntegerBitmapLayout aLayout; + +#if 0 + // TODO: To be used when dealing with real bitmaps here + const Size aBmpSize( maBitmap->GetSizePixel() ); +#else + const Size aBmpSize( getVirDev().GetOutputSizePixel() ); +#endif + + aLayout.ScanLines = aBmpSize.Height(); + aLayout.ScanLineBytes = aBmpSize.Width()*4; + aLayout.ScanLineStride = aLayout.ScanLineBytes; + aLayout.Format = 0; + aLayout.NumComponents = 4; + aLayout.ComponentMasks = uno::Sequence(); + aLayout.Endianness = 0; + aLayout.IsPseudoColor = false; + + return aLayout; + } + +#define SERVICE_NAME "drafts.com.sun.star.rendering.CanvasBitmap" + + ::rtl::OUString SAL_CALL CanvasBitmap::getImplementationName( ) throw (uno::RuntimeException) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVASBITMAP_IMPLEMENTATION_NAME ) ); + } + + sal_Bool SAL_CALL CanvasBitmap::supportsService( const ::rtl::OUString& ServiceName ) throw (uno::RuntimeException) + { + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); + } + + uno::Sequence< ::rtl::OUString > SAL_CALL CanvasBitmap::getSupportedServiceNames( ) throw (uno::RuntimeException) + { + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); + + return aRet; + } + + VirtualDevice& CanvasBitmap::getVirDev() + { + return mpBitmapCanvas->getVirDev(); + } +} diff --git a/canvas/source/vcl/canvasbitmap.hxx b/canvas/source/vcl/canvasbitmap.hxx new file mode 100644 index 000000000000..7bceb6abcc77 --- /dev/null +++ b/canvas/source/vcl/canvasbitmap.hxx @@ -0,0 +1,137 @@ +/************************************************************************* + * + * $RCSfile: canvasbitmap.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:39 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VCLCANVAS_CANVASBITMAP_HXX +#define _VCLCANVAS_CANVASBITMAP_HXX + +#include + +#ifndef _CPPUHELPER_IMPLBASE2_HXX_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XINTEGERBITMAP_HPP_ +#include +#endif + +#ifndef _SV_BITMAPEX_HXX +#include +#endif + +#include "spritecanvas.hxx" +#include "bitmapcanvas.hxx" +#include "impltools.hxx" + +#define CANVASBITMAP_IMPLEMENTATION_NAME "VCLCanvas::CanvasBitmap" + +/* Definition of CanvasBitmap class */ + +namespace vclcanvas +{ + class CanvasBitmap : public ::cppu::WeakImplHelper2< ::drafts::com::sun::star::rendering::XIntegerBitmap, + ::com::sun::star::lang::XServiceInfo > + { + public: + // Must be called with locked Solar mutex + CanvasBitmap( const ::Size& rSize, + const OutDevProvider::ImplRef& rReferenceCanvas ); + + // XBitmap + virtual ::drafts::com::sun::star::geometry::IntegerSize2D SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmapCanvas > SAL_CALL queryBitmapCanvas( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmap > SAL_CALL getScaledBitmap( const ::drafts::com::sun::star::geometry::RealSize2D& newSize, sal_Bool beFast ) throw (::com::sun::star::uno::RuntimeException); + + // XIntegerBitmap + virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getData( const ::drafts::com::sun::star::geometry::IntegerRectangle2D& rect ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::drafts::com::sun::star::rendering::VolatileContentDestroyedException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setData( const ::com::sun::star::uno::Sequence< sal_Int8 >& data, const ::drafts::com::sun::star::geometry::IntegerRectangle2D& rect ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPixel( const ::com::sun::star::uno::Sequence< sal_Int8 >& color, const ::drafts::com::sun::star::geometry::IntegerPoint2D& pos ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getPixel( const ::drafts::com::sun::star::geometry::IntegerPoint2D& pos ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::drafts::com::sun::star::rendering::VolatileContentDestroyedException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmapPalette > SAL_CALL getPalette( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::drafts::com::sun::star::rendering::IntegerBitmapLayout SAL_CALL getMemoryLayout( ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); + + VirtualDevice& getVirDev(); + + protected: + ~CanvasBitmap(); // we're a ref-counted UNO class. _We_ destroy ourselves. + + private: + // default: disabled copy/assignment + CanvasBitmap(const CanvasBitmap&); + CanvasBitmap& operator=( const CanvasBitmap& ); + + // only needed internally + CanvasBitmap( const BitmapEx& rBitmap, + const OutDevProvider::ImplRef& rReferenceCanvas ); + + OutDevProvider::ImplRef mpReferenceCanvas; + BitmapCanvas::ImplRef mpBitmapCanvas; + }; +} + +#endif /* _VCLCANVAS_CANVASBITMAP_HXX */ diff --git a/canvas/source/vcl/canvascustomsprite.cxx b/canvas/source/vcl/canvascustomsprite.cxx new file mode 100644 index 000000000000..b228e67b3506 --- /dev/null +++ b/canvas/source/vcl/canvascustomsprite.cxx @@ -0,0 +1,444 @@ +/************************************************************************* + * + * $RCSfile: canvascustomsprite.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef INCLUDED_RTL_MATH_HXX +#include +#endif + +#include + +#include "canvascustomsprite.hxx" +#include "spritecanvas.hxx" +#include "impltools.hxx" + +#ifndef _SV_OUTDEV_HXX +#include +#endif +#ifndef _SV_BITMAP_HXX +#include +#endif +#ifndef _SV_GDIMTF_HXX +#include +#endif +#ifndef _SV_METAACT_HXX +#include +#endif +#ifndef _VCL_CANVASTOOLS_HXX +#include +#endif + +#ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX +#include +#endif +#ifndef _BGFX_POINT_B2DPOINT_HXX +#include +#endif +#ifndef _BGFX_TOOLS_CANVASTOOLS_HXX +#include +#endif + +using namespace ::com::sun::star; +using namespace ::drafts::com::sun::star; + +namespace vclcanvas +{ + + CanvasCustomSprite::CanvasCustomSprite( const geometry::RealSize2D& rSpriteSize, + const SpriteCanvas::ImplRef& rSpriteCanvas ) : + maVDev( new VirtualDevice( rSpriteCanvas->getOutDev() ) ), // create from reference device + maMaskVDev( new VirtualDevice( rSpriteCanvas->getOutDev(), 1) ), // create from reference device, bit depth: one + maCanvasHelper(), + mpSpriteCanvas( rSpriteCanvas ), + maPosition(0.0, 0.0), + maSize( ::vcl::unotools::sizeFromRealSize2D( rSpriteSize ) ), + mfAlpha(0.0), + mbActive( false ) + { + // setup outdev sizes to total sprite size + maVDev->SetOutputSizePixel( maSize ); + maMaskVDev->SetOutputSizePixel( maSize ); + + // set mask vdev drawmode, such that everything is painted + // black. That leaves us with a binary image, white for + // background, black for painted content + maMaskVDev->SetDrawMode( DRAWMODE_BLACKLINE | DRAWMODE_BLACKFILL | DRAWMODE_BLACKTEXT | + DRAWMODE_BLACKGRADIENT | DRAWMODE_BLACKBITMAP ); + + maCanvasHelper.setOutDev( *maVDev ); + maCanvasHelper.setBackgroundOutDev( *maMaskVDev ); + } + + CanvasCustomSprite::~CanvasCustomSprite() + { + hide(); + } + + OutDevProvider::ImplRef CanvasCustomSprite::getImplRef() + { + return OutDevProvider::ImplRef::createFromQuery( this ); + } + + void SAL_CALL CanvasCustomSprite::drawPoint( const geometry::RealPoint2D& aPoint, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + // TODO: You might consider copying the SpriteCanvas + // background VDev behaviour here, notably the call to + // SpriteSurface::updateSprite(). But on the other hand, there + // are enough external cases that could mess that up (see + // comment on XCustomSprite), that we're maybe wise to keep it + // like this (i.e. invalidating the sprite content only once, + // for the call to getContentCanvas). This way, the inevitable + // errors will show up earlier, not only when multi-threading + // the updateScreen. + maCanvasHelper.drawPoint( aPoint, viewState, renderState, getImplRef() ); + } + + void SAL_CALL CanvasCustomSprite::drawLine( const geometry::RealPoint2D& aStartPoint, const geometry::RealPoint2D& aEndPoint, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + maCanvasHelper.drawLine(aStartPoint, aEndPoint, viewState, renderState, getImplRef()); + } + + void SAL_CALL CanvasCustomSprite::drawBezier( const ::drafts::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment, + const ::drafts::com::sun::star::geometry::RealPoint2D& aEndPoint, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + maCanvasHelper.drawBezier(aBezierSegment, aEndPoint, viewState, renderState, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::drawPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.drawPolyPolygon(xPolyPolygon, viewState, renderState, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::strokePolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.strokePolyPolygon(xPolyPolygon, viewState, renderState, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::strokeTexturedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.strokeTexturedPolyPolygon(xPolyPolygon, viewState, renderState, textures, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::strokeTextureMappedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures, const uno::Reference< geometry::XMapping2D >& xMapping, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.strokeTextureMappedPolyPolygon(xPolyPolygon, viewState, renderState, textures, xMapping, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XPolyPolygon2D > SAL_CALL CanvasCustomSprite::queryStrokeShapes( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.queryStrokeShapes(xPolyPolygon, viewState, renderState, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::fillPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.fillPolyPolygon(xPolyPolygon, viewState, renderState, getImplRef() ); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::fillTexturedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.fillTexturedPolyPolygon(xPolyPolygon, viewState, renderState, textures, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::fillTextureMappedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures, const uno::Reference< geometry::XMapping2D >& xMapping ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.fillTextureMappedPolyPolygon(xPolyPolygon, viewState, renderState, textures, xMapping, getImplRef()); + } + + uno::Reference< rendering::XCanvasFont > SAL_CALL CanvasCustomSprite::queryFont( const rendering::FontRequest& fontRequest ) throw (uno::RuntimeException) + { + return maCanvasHelper.queryFont( fontRequest, getImplRef() ); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::drawText( const rendering::StringContext& text, + const uno::Reference< rendering::XCanvasFont >& xFont, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 textDirection ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.drawText(text, xFont, viewState, renderState, textDirection, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::drawOffsettedText( const rendering::StringContext& text, const uno::Reference< rendering::XCanvasFont >& xFont, const uno::Sequence< double >& offsets, const rendering::ViewState& viewState, const rendering::RenderState& renderState, sal_Int8 textDirection ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.drawOffsettedText(text, xFont, offsets, viewState, renderState, textDirection, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::drawBitmap( const uno::Reference< rendering::XBitmap >& xBitmap, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.drawBitmap(xBitmap, viewState, renderState, getImplRef()); + } + + uno::Reference< rendering::XGraphicDevice > SAL_CALL CanvasCustomSprite::getDevice() throw (uno::RuntimeException) + { + return maCanvasHelper.getDevice( getImplRef() ); + } + + void SAL_CALL CanvasCustomSprite::copyRect( const uno::Reference< rendering::XBitmapCanvas >& sourceCanvas, + const geometry::RealRectangle2D& sourceRect, + const rendering::ViewState& sourceViewState, + const rendering::RenderState& sourceRenderState, + const geometry::RealRectangle2D& destRect, + const rendering::ViewState& destViewState, + const rendering::RenderState& destRenderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + } + + void SAL_CALL CanvasCustomSprite::setAlpha( double alpha ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + ::canvas::tools::checkRange(alpha, 0.0, 1.0); + + if( alpha != mfAlpha ) + { + if( mbActive ) + mpSpriteCanvas->updateSprite( Sprite::ImplRef( this ), + ::vcl::unotools::pointFromB2DPoint( maPosition ), + Rectangle( ::vcl::unotools::pointFromB2DPoint( maPosition ), + maSize ) ); + + mfAlpha = alpha; + } + } + + void SAL_CALL CanvasCustomSprite::move( const ::drafts::com::sun::star::geometry::RealPoint2D& aNewPos, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + ::basegfx::B2DHomMatrix aTransform; + ::canvas::tools::mergeViewAndRenderTransform(aTransform, + viewState, + renderState); + + ::basegfx::B2DPoint aPoint( ::basegfx::unotools::b2DPointFromRealPoint2D(aNewPos) ); + aPoint *= aTransform; + + if( aPoint != maPosition ) + { + if( mbActive ) + mpSpriteCanvas->moveSprite( Sprite::ImplRef( this ), + ::vcl::unotools::pointFromB2DPoint( maPosition ), + ::vcl::unotools::pointFromB2DPoint( aPoint ) ); + + maPosition = aPoint; + } + } + + void SAL_CALL CanvasCustomSprite::transform( const geometry::AffineMatrix2D& aTransformation ) throw (lang::IllegalArgumentException, + uno::RuntimeException) + { + // TODO + } + + void SAL_CALL CanvasCustomSprite::clip( const uno::Reference< rendering::XPolyPolygon2D >& aClip, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, + uno::RuntimeException) + { + // TODO + } + + void SAL_CALL CanvasCustomSprite::show( ) throw (::com::sun::star::uno::RuntimeException) + { + if( !mbActive ) + { + mpSpriteCanvas->showSprite( Sprite::ImplRef( this ) ); + mbActive = true; + + if( mfAlpha != 0.0 ) + { + mpSpriteCanvas->updateSprite( Sprite::ImplRef( this ), + ::vcl::unotools::pointFromB2DPoint( maPosition ), + Rectangle( ::vcl::unotools::pointFromB2DPoint( maPosition ), + maSize ) ); + } + } + } + + void SAL_CALL CanvasCustomSprite::hide( ) throw (::com::sun::star::uno::RuntimeException) + { + if( mbActive ) + { + mpSpriteCanvas->hideSprite( Sprite::ImplRef( this ) ); + mbActive = false; + + if( mfAlpha != 0.0 ) + { + mpSpriteCanvas->updateSprite( Sprite::ImplRef( this ), + ::vcl::unotools::pointFromB2DPoint( maPosition ), + Rectangle( ::vcl::unotools::pointFromB2DPoint( maPosition ), + maSize ) ); + } + } + } + + uno::Reference< rendering::XCanvas > SAL_CALL CanvasCustomSprite::getContentCanvas() throw (uno::RuntimeException) + { + if( mbActive ) + { + // the client is about to render into the sprite. Thus, + // potentially the whole sprite area has changed. + mpSpriteCanvas->updateSprite( Sprite::ImplRef( this ), + ::vcl::unotools::pointFromB2DPoint( maPosition ), + Rectangle( ::vcl::unotools::pointFromB2DPoint( maPosition ), + maSize ) ); + } + + // TODO: Locking! Everywhere! + tools::LocalGuard aGuard; + + // clear surface + maVDev->EnableMapMode( FALSE ); + maVDev->SetFillColor( Color( COL_WHITE ) ); + maVDev->SetLineColor(); + maVDev->DrawRect( Rectangle(Point(), maSize) ); + + maMaskVDev->SetDrawMode( DRAWMODE_DEFAULT ); + maMaskVDev->EnableMapMode( FALSE ); + maMaskVDev->SetFillColor( Color( COL_WHITE ) ); + maMaskVDev->SetLineColor(); + maMaskVDev->DrawRect( Rectangle(Point(), maSize) ); + maMaskVDev->SetDrawMode( DRAWMODE_BLACKLINE | DRAWMODE_BLACKFILL | DRAWMODE_BLACKTEXT | + DRAWMODE_BLACKGRADIENT | DRAWMODE_BLACKBITMAP ); + + return this; + } + +#define SERVICE_NAME "drafts.com.sun.star.rendering.Canvas" + + ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException ) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVASCUSTOMSPRITE_IMPLEMENTATION_NAME ) ); + } + + sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) + { + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); + } + + uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException ) + { + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); + + return aRet; + } + + // Sprite + void CanvasCustomSprite::redraw( OutputDevice& rTargetSurface ) const + { + redraw( rTargetSurface, + ::vcl::unotools::pointFromB2DPoint( maPosition ) ); + } + + void CanvasCustomSprite::redraw( OutputDevice& rTargetSurface, const Point& rOutputPos ) const + { + tools::OutDevStateKeeper aStateKeeper(rTargetSurface); + + const Point aEmptyPoint; + const Bitmap aMaskBitmap( maMaskVDev->GetBitmap( aEmptyPoint, maSize ) ); + const Bitmap aContentBitmap( maVDev->GetBitmap( aEmptyPoint, maSize ) ); + + // TODO: Support for alpha-VDev + rTargetSurface.EnableMapMode( FALSE ); + + if( ::rtl::math::approxEqual(mfAlpha, 1.0) ) + { + // copy to output + rTargetSurface.DrawBitmapEx( rOutputPos, + BitmapEx( aContentBitmap, aMaskBitmap ) ); + } + else if( mfAlpha != 0.0 ) // TODO: be a little bit more tolerant here + { + // Only draw something if we're not completely transparent + BYTE nColor( static_cast(255.0*(1.0 - mfAlpha) + .5) ); + AlphaMask aAlpha( maSize, &nColor ); + + // mask out fully transparent areas + aAlpha.Replace( aMaskBitmap, 255 ); + + // alpha-blend to output + rTargetSurface.DrawBitmapEx( rOutputPos, + BitmapEx( aContentBitmap, aAlpha ) ); + } + } + + ::basegfx::B2DSize CanvasCustomSprite::getSize() const + { + // TODO: Use AW's wrappers once resynced + return ::basegfx::B2DSize( maSize.Width(), + maSize.Height() ); + } + + // OutDevProvider + ::OutputDevice& CanvasCustomSprite::getOutDev() + { + return *maVDev; + } + + const ::OutputDevice& CanvasCustomSprite::getOutDev() const + { + return *maVDev; + } + +} diff --git a/canvas/source/vcl/canvascustomsprite.hxx b/canvas/source/vcl/canvascustomsprite.hxx new file mode 100644 index 000000000000..4414ea6150ec --- /dev/null +++ b/canvas/source/vcl/canvascustomsprite.hxx @@ -0,0 +1,258 @@ +/************************************************************************* + * + * $RCSfile: canvascustomsprite.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VCLCANVAS_CANVASCUSTOMSPRITE_HXX +#define _VCLCANVAS_CANVASCUSTOMSPRITE_HXX + +#ifndef _CPPUHELPER_IMPLBASE3_HXX_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XCUSTOMSPRITE_HPP_ +#include +#endif + +#ifndef _BGFX_POINT_B2DPOINT_HXX +#include +#endif + +#ifndef _SV_VIRDEV_HXX +#include +#endif + +#include + +#include "outdevprovider.hxx" +#include "spritecanvas.hxx" +#include "bitmapcanvas.hxx" +#include "sprite.hxx" + +#define CANVASCUSTOMSPRITE_IMPLEMENTATION_NAME "VCLCanvas::CanvasCustomSprite" + +namespace vclcanvas +{ + typedef ::cppu::WeakImplHelper3< ::drafts::com::sun::star::rendering::XCustomSprite, + ::drafts::com::sun::star::rendering::XBitmapCanvas, + ::com::sun::star::lang::XServiceInfo > CanvasCustomSprite_Base; + + /* Definition of CanvasCustomSprite class */ + + class CanvasCustomSprite : public Sprite, + public OutDevProvider, + public CanvasCustomSprite_Base + { + public: + CanvasCustomSprite( const ::drafts::com::sun::star::geometry::RealSize2D& rSpriteSize, + const SpriteCanvas::ImplRef& rSpriteCanvas ); + + // XInterface + + // Need to implement that, because Sprite and OutDevProvider + // both come with an unimplemented version of XInterface. + + // Forwarding the XInterface implementation to the + // cppu::ImplHelper templated base, which does the refcounting and + // queryInterface for us: Classname Base doing refcount and handling queryInterface + // | | + // V V + DECLARE_UNO3_AGG_DEFAULTS( CanvasCustomSprite, CanvasCustomSprite_Base ); + + // XCanvas + virtual void SAL_CALL drawPoint( const ::drafts::com::sun::star::geometry::RealPoint2D& aPoint, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL drawLine( const ::drafts::com::sun::star::geometry::RealPoint2D& aStartPoint, + const ::drafts::com::sun::star::geometry::RealPoint2D& aEndPoint, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL drawBezier( const ::drafts::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment, + const ::drafts::com::sun::star::geometry::RealPoint2D& aEndPoint, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + strokePolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + strokeTexturedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + strokeTextureMappedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::geometry::XMapping2D >& xMapping, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D > SAL_CALL + queryStrokeShapes( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + fillPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + fillTexturedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + fillTextureMappedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::geometry::XMapping2D >& xMapping ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvasFont > SAL_CALL + queryFont( const ::drafts::com::sun::star::rendering::FontRequest& fontRequest ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawText( const ::drafts::com::sun::star::rendering::StringContext& text, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvasFont >& xFont, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + sal_Int8 textDirection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawOffsettedText( const ::drafts::com::sun::star::rendering::StringContext& text, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvasFont >& xFont, + const ::com::sun::star::uno::Sequence< double >& offsets, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + sal_Int8 textDirection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawBitmap( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmap >& xBitmap, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XGraphicDevice > SAL_CALL + getDevice() throw (::com::sun::star::uno::RuntimeException); + + // XBitmapCanvas (only providing, not implementing the + // interface. Also note subtle method parameter differences) + virtual void SAL_CALL copyRect( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmapCanvas >& sourceCanvas, + const ::drafts::com::sun::star::geometry::RealRectangle2D& sourceRect, + const ::drafts::com::sun::star::rendering::ViewState& sourceViewState, + const ::drafts::com::sun::star::rendering::RenderState& sourceRenderState, + const ::drafts::com::sun::star::geometry::RealRectangle2D& destRect, + const ::drafts::com::sun::star::rendering::ViewState& destViewState, + const ::drafts::com::sun::star::rendering::RenderState& destRenderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + // XSprite + virtual void SAL_CALL setAlpha( double alpha ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL move( const ::drafts::com::sun::star::geometry::RealPoint2D& aNewPos, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL transform( const ::drafts::com::sun::star::geometry::AffineMatrix2D& aTransformation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL clip( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& aClip, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL show( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL hide( ) throw (::com::sun::star::uno::RuntimeException); + + // XCustomSprite + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvas > SAL_CALL + getContentCanvas( ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ); + + // OutDevProvider + virtual OutputDevice& getOutDev(); + virtual const OutputDevice& getOutDev() const; + + // Sprite + virtual void redraw( OutputDevice& rTargetSurface ) const; + virtual void redraw( OutputDevice& rTargetSurface, const Point& rOutputPosition ) const; + virtual ::basegfx::B2DSize getSize() const; + + protected: + ~CanvasCustomSprite(); // we're a ref-counted UNO class. _We_ destroy ourselves. + + private: + // default: disabled copy/assignment + CanvasCustomSprite(const CanvasCustomSprite&); + CanvasCustomSprite& operator=( const CanvasCustomSprite& ); + + OutDevProvider::ImplRef getImplRef(); + + // for the integrated bitmap canvas implementation + ::canvas::vcltools::VCLObject maVDev; + ::canvas::vcltools::VCLObject maMaskVDev; + CanvasBase maCanvasHelper; + + SpriteCanvas::ImplRef mpSpriteCanvas; + + // sprite state + ::basegfx::B2DPoint maPosition; + Size maSize; + double mfAlpha; + bool mbActive; + }; +} + +#endif /* _VCLCANVAS_CANVASCUSTOMSPRITE_HXX */ diff --git a/canvas/source/vcl/canvasfont.cxx b/canvas/source/vcl/canvasfont.cxx new file mode 100644 index 000000000000..3f4d88efcd2b --- /dev/null +++ b/canvas/source/vcl/canvasfont.cxx @@ -0,0 +1,174 @@ +/************************************************************************* + * + * $RCSfile: canvasfont.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "canvasfont.hxx" +#include "spritecanvas.hxx" + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XSPRITECANVAS_HPP_ +#include +#endif + +using namespace ::com::sun::star; +using namespace ::drafts::com::sun::star; + +namespace vclcanvas +{ + CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest, + const OutDevProvider::ImplRef& rCanvas ) : + maFont( Font( rFontRequest.FamilyName, rFontRequest.StyleName, ::Size( 0, + static_cast(rFontRequest.CellSize + .5)) ) ), + maFontRequest( rFontRequest ), + mpCanvas( rCanvas ) + { + maFont->SetAlign( ALIGN_BASELINE ); + maFont->SetHeight( static_cast(rFontRequest.CellSize + .5) ); + } + + CanvasFont::~CanvasFont() + { + } + + uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL CanvasFont::queryTextShapes( const rendering::StringContext& text, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 direction ) throw (uno::RuntimeException) + { + // TODO + return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >(); + } + + uno::Sequence< geometry::RealRectangle2D > SAL_CALL CanvasFont::queryTightMeasures( const rendering::StringContext& text, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 direction ) throw (uno::RuntimeException) + { + // TODO + return uno::Sequence< geometry::RealRectangle2D >(); + } + + uno::Sequence< geometry::RealRectangle2D > SAL_CALL CanvasFont::queryTextMeasures( const rendering::StringContext& text, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 direction ) throw (uno::RuntimeException) + { + // TODO + return uno::Sequence< geometry::RealRectangle2D >(); + } + + uno::Sequence< double > SAL_CALL CanvasFont::queryTextOffsets( const rendering::StringContext& text, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 direction ) throw (uno::RuntimeException) + { + // TODO + return uno::Sequence< double >(); + } + + geometry::RealRectangle2D SAL_CALL CanvasFont::queryTextBounds( const rendering::StringContext& text, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 direction ) throw (uno::RuntimeException) + { + // TODO + return geometry::RealRectangle2D(); + } + + rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( ) throw (uno::RuntimeException) + { + return maFontRequest; + } + + rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( ) throw (uno::RuntimeException) + { + return rendering::FontMetrics(); + } + + uno::Reference< rendering::XCanvas > SAL_CALL CanvasFont::getAssociatedCanvas( ) throw (uno::RuntimeException) + { + return uno::Reference< rendering::XCanvas >( mpCanvas.getRef(), + uno::UNO_QUERY ); + } + +#define SERVICE_NAME "drafts.com.sun.star.rendering.CanvasFont" + + ::rtl::OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException ) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVASFONT_IMPLEMENTATION_NAME ) ); + } + + sal_Bool SAL_CALL CanvasFont::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) + { + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); + } + + uno::Sequence< ::rtl::OUString > SAL_CALL CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException ) + { + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); + + return aRet; + } + + ::Font CanvasFont::getVCLFont() const + { + return *maFont; + } +} diff --git a/canvas/source/vcl/canvasfont.hxx b/canvas/source/vcl/canvasfont.hxx new file mode 100644 index 000000000000..3bbbe5f21bd9 --- /dev/null +++ b/canvas/source/vcl/canvasfont.hxx @@ -0,0 +1,134 @@ +/************************************************************************* + * + * $RCSfile: canvasfont.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CANVASFONT_HXX +#define _CANVASFONT_HXX + +#ifndef _CPPUHELPER_IMPLBASE2_HXX_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XCANVASFONT_HPP_ +#include +#endif + +#ifndef _SV_FONT_HXX +#include +#endif + +#include + +#include "canvasbase.hxx" +#include "outdevprovider.hxx" +#include "impltools.hxx" + + +#define CANVASFONT_IMPLEMENTATION_NAME "VCLCanvas::CanvasFont" + +/* Definition of CanvasFont class */ + +namespace vclcanvas +{ + class SpriteCanvas; + + class CanvasFont : public ::cppu::WeakImplHelper2< ::drafts::com::sun::star::rendering::XCanvasFont, + ::com::sun::star::lang::XServiceInfo > + { + public: + CanvasFont( const ::drafts::com::sun::star::rendering::FontRequest& fontRequest, + const OutDevProvider::ImplRef& rCanvas ); + + // XCanvasFont + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D > > SAL_CALL queryTextShapes( const ::drafts::com::sun::star::rendering::StringContext& text, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState, sal_Int8 direction ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::geometry::RealRectangle2D > SAL_CALL queryTightMeasures( const ::drafts::com::sun::star::rendering::StringContext& text, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState, sal_Int8 direction ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::geometry::RealRectangle2D > SAL_CALL queryTextMeasures( const ::drafts::com::sun::star::rendering::StringContext& text, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState, sal_Int8 direction ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< double > SAL_CALL queryTextOffsets( const ::drafts::com::sun::star::rendering::StringContext& text, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState, sal_Int8 direction ) throw (::com::sun::star::uno::RuntimeException); + virtual ::drafts::com::sun::star::geometry::RealRectangle2D SAL_CALL queryTextBounds( const ::drafts::com::sun::star::rendering::StringContext& text, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState, sal_Int8 direction ) throw (::com::sun::star::uno::RuntimeException); + virtual ::drafts::com::sun::star::rendering::FontRequest SAL_CALL getFontRequest( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::drafts::com::sun::star::rendering::FontMetrics SAL_CALL getFontMetrics( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvas > SAL_CALL getAssociatedCanvas( ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ); + + ::Font getVCLFont() const; + + protected: + ~CanvasFont(); // we're a ref-counted UNO class. _We_ destroy ourselves. + + private: + // default: disabled copy/assignment + CanvasFont(const CanvasFont&); + CanvasFont& operator=( const CanvasFont& ); + + ::canvas::vcltools::VCLObject maFont; + ::drafts::com::sun::star::rendering::FontRequest maFontRequest; + OutDevProvider::ImplRef mpCanvas; + }; + +} + +#endif /* _CANVASFONT_HXX */ diff --git a/canvas/source/vcl/exports.dxp b/canvas/source/vcl/exports.dxp new file mode 100644 index 000000000000..0c2e3e7cddd7 --- /dev/null +++ b/canvas/source/vcl/exports.dxp @@ -0,0 +1,3 @@ +component_getImplementationEnvironment +component_writeInfo +component_getFactory \ No newline at end of file diff --git a/canvas/source/vcl/impltools.cxx b/canvas/source/vcl/impltools.cxx new file mode 100644 index 000000000000..75a492665a74 --- /dev/null +++ b/canvas/source/vcl/impltools.cxx @@ -0,0 +1,414 @@ +/************************************************************************* + * + * $RCSfile: impltools.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _DRAFTS_COM_SUN_STAR_GEOMETRY_REALSIZE2D_HPP__ +#include +#endif +#ifndef _DRAFTS_COM_SUN_STAR_GEOMETRY_REALPOINT2D_HPP__ +#include +#endif +#ifndef _DRAFTS_COM_SUN_STAR_GEOMETRY_REALRECTANGLE2D_HPP__ +#include +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_RENDERSTATE_HPP__ +#include +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XCANVAS_HPP__ +#include +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XBITMAP_HPP__ +#include +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XPOLYPOLYGON2D_HPP__ +#include +#endif +#ifndef _DRAFTS_COM_SUN_STAR_GEOMETRY_REALBEZIERSEGMENT2D_HPP__ +#include +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XINTEGERBITMAP_HPP__ +#include +#endif + +#ifndef _TL_POLY_HXX +#include +#endif +#ifndef _SV_SALBTYPE_HXX +#include +#endif +#ifndef _SV_BMPACC_HXX +#include +#endif +#ifndef _SV_BITMAPEX_HXX +#include +#endif +#ifndef _SV_METRIC_HXX +#include +#endif +#ifndef _VCL_CANVASTOOLS_HXX +#include +#endif + +#ifndef _BGFX_TUPLE_B2DTUPLE_HXX +#include +#endif +#ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX +#include +#endif +#ifndef _BGFX_TOOLS_CANVASTOOLS_HXX +#include +#endif + +#ifndef INCLUDED_RTL_MATH_HXX +#include +#endif + +#include // for fmod + +#include + +#include "impltools.hxx" +#include "linepolypolygon.hxx" +#include "canvasbitmap.hxx" + + +using namespace ::com::sun::star; +using namespace ::drafts::com::sun::star; + +namespace vclcanvas +{ + namespace tools + { + ::PolyPolygon polyPolygonFromXPolyPolygon2D( const uno::Reference< rendering::XPolyPolygon2D >& xPoly ) + { + uno::Reference< lang::XServiceInfo > xRef( xPoly, + uno::UNO_QUERY ); + + if( xRef.is() && + xRef->getImplementationName().equals( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(LINEPOLYPOLYGON_IMPLEMENTATION_NAME))) ) + { + // TODO: Maybe use dynamic_cast here + + // TODO: Provide true beziers here! + return static_cast(xPoly.get())->getVCLPolyPolygon(); + } + else + { + // TODO: extract points from polygon interface + } + + return ::PolyPolygon(); + } + + ::BitmapEx bitmapExFromXBitmap( const uno::Reference< rendering::XBitmap >& xBitmap ) + { + uno::Reference< lang::XServiceInfo > xRef( xBitmap, + uno::UNO_QUERY ); + + if( xRef.is() && + xRef->getImplementationName().equals( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CANVASBITMAP_IMPLEMENTATION_NAME))) ) + { + // TODO: Maybe use dynamic_cast here + VirtualDevice& rVDev( static_cast(xBitmap.get())->getVirDev() ); + const Point aEmptyPoint(0,0); + const Size aBmpSize(rVDev.GetOutputSizePixel()); + + // TODO: handle alpha vDev here + return rVDev.GetBitmap(aEmptyPoint, aBmpSize); + } + else + { + // TODO: extract points from polygon interface + } + + return ::BitmapEx(); + } + + ::Point setupFontTransform( ::Font& aVCLFont, + const rendering::ViewState& rViewState, + const rendering::RenderState& rRenderState, + OutputDevice& rOutDev ) + { + ::basegfx::B2DHomMatrix aMatrix; + + ::canvas::tools::mergeViewAndRenderTransform(aMatrix, + rViewState, + rRenderState); + + ::basegfx::B2DTuple aScale; + ::basegfx::B2DTuple aTranslate; + double nRotate, nShearX; + + aMatrix.decompose( aScale, aTranslate, nRotate, nShearX ); + + // query font metric _before_ tampering with width and height + if( !::rtl::math::approxEqual(aScale.getX(), aScale.getY()) ) + { + // retrieve true font width + const int aFontWidth( rOutDev.GetFontMetric( aVCLFont ).GetWidth() ); + + aVCLFont.SetWidth( static_cast(aFontWidth * aScale.getX() + .5) ); + } + + if( !::rtl::math::approxEqual(aScale.getY(), 1.0) ) + { + const int nFontHeight( aVCLFont.GetHeight() ); + aVCLFont.SetHeight( static_cast(nFontHeight * aScale.getY() + .5) ); + } + + aVCLFont.SetOrientation( static_cast< short >(-fmod(nRotate, 2*F_PI)*(1800.0/F_PI) + .5) ); + + // TODO: Missing functionality in VCL: shearing + return ::Point( static_cast(aTranslate.getX() + .5), + static_cast(aTranslate.getY() + .5) ); + } + + // VCL-Canvas related + //--------------------------------------------------------------------- + + ::Point mapRealPoint2D( const geometry::RealPoint2D& rPoint, + const rendering::ViewState& rViewState, + const rendering::RenderState& rRenderState ) + { + ::basegfx::B2DPoint aPoint( ::basegfx::unotools::b2DPointFromRealPoint2D(rPoint) ); + + ::basegfx::B2DHomMatrix aMatrix; + aPoint *= ::canvas::tools::mergeViewAndRenderTransform(aMatrix, + rViewState, + rRenderState); + + return ::vcl::unotools::pointFromB2DPoint( aPoint ); + } + + ::PolyPolygon mapPolyPolygon( const ::PolyPolygon& rPoly, + const rendering::ViewState& rViewState, + const rendering::RenderState& rRenderState ) + { + PolyPolygon aRes; + ::basegfx::B2DHomMatrix aMatrix; + ::canvas::tools::mergeViewAndRenderTransform(aMatrix, + rViewState, + rRenderState); + + int nCurrPoly, nCurrPoint; + for( nCurrPoly=0; nCurrPoly= aBmpSize.Width() || + nSrcY < 0 || nSrcX >= aBmpSize.Height() ) + { + pAlphaWriteAccess->SetPixel( y, x, BitmapColor(255) ); + } + else + { + pAlphaWriteAccess->SetPixel( y, x, pAlphaReadAccess->GetPixel( nSrcY, + nSrcX ) ); + pWriteAccess->SetPixel( y, x, pReadAccess->GetPixel( nSrcY, + nSrcX ) ); + } + } + } + else + { + for( int x=0; x= aBmpSize.Width() || + nSrcY < 0 || nSrcX >= aBmpSize.Height() ) + { + pAlphaWriteAccess->SetPixel( y, x, BitmapColor(255) ); + } + else + { + pAlphaWriteAccess->SetPixel( y, x, BitmapColor(0) ); + pWriteAccess->SetPixel( y, x, pReadAccess->GetPixel( nSrcY, + nSrcX ) ); + } + } + } + } + + bCopyBack = true; + } + else + { + // TODO: Error handling! + } + } + + if( bCopyBack ) + return BitmapEx( aDstBitmap, AlphaMask( aDstAlpha ) ); + else + return BitmapEx(); + } + } +} diff --git a/canvas/source/vcl/impltools.hxx b/canvas/source/vcl/impltools.hxx new file mode 100644 index 000000000000..92157cb6556f --- /dev/null +++ b/canvas/source/vcl/impltools.hxx @@ -0,0 +1,195 @@ +/************************************************************************* + * + * $RCSfile: impltools.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VCLCANVAS_TOOLS_HXX +#define _VCLCANVAS_TOOLS_HXX + +#ifndef _OSL_MUTEX_HXX_ +#include +#endif +#ifndef _VOS_MUTEX_HXX_ +#include +#endif +#ifndef _SV_SVAPP_HXX +#include +#endif + +#ifndef _SV_OUTDEV_HXX +#include +#endif + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include +#endif + +namespace basegfx +{ + namespace matrix + { + class B2DHomMatrix; + } + namespace vector + { + class B2DVector; + } + namespace point + { + class B2DPoint; + } +} + +namespace com { namespace sun { namespace star { namespace awt +{ + struct Point; + struct Size; + struct Rectangle; +} } } } + +namespace com { namespace sun { namespace star { namespace drawing +{ + struct HomogenMatrix3; +} } } } + +namespace drafts { namespace com { namespace sun { namespace star { namespace rendering +{ + struct RealPoint2D; + struct RealSize2D; + struct RealRectangle2D; + struct RenderState; + struct ViewState; + class XCanvas; + class XBitmap; + class XPolyPolygon2D; +} } } } } + + +namespace vclcanvas +{ + namespace tools + { + ::PolyPolygon + polyPolygonFromXPolyPolygon2D( const ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::rendering::XPolyPolygon2D >& ); + + ::BitmapEx + bitmapExFromXBitmap( const ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::rendering::XBitmap >& ); + + ::Point setupFontTransform( ::Font& aVCLFont, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + ::OutputDevice& rOutDev ); + + + // Little helper to encapsulate locking into policy class + class LocalGuard + { + public: + LocalGuard() : + aGuard( Application::GetSolarMutex() ) + { + } + + private: + ::vos::OGuard aGuard; + }; + + class OutDevStateKeeper + { + public: + explicit OutDevStateKeeper( OutputDevice& rOutDev ) : + mrOutDev( rOutDev ), + mbMappingWasEnable( rOutDev.IsMapModeEnabled() ) + { + mrOutDev.Push(); + mrOutDev.EnableMapMode(FALSE); + } + + ~OutDevStateKeeper() + { + mrOutDev.EnableMapMode( mbMappingWasEnable ); + mrOutDev.Pop(); + } + + private: + OutputDevice& mrOutDev; + const bool mbMappingWasEnable; + }; + + ::Point mapRealPoint2D( const ::drafts::com::sun::star::geometry::RealPoint2D& rPoint, + const ::drafts::com::sun::star::rendering::ViewState& rViewState, + const ::drafts::com::sun::star::rendering::RenderState& rRenderState ); + + ::PolyPolygon mapPolyPolygon( const ::PolyPolygon& rPoly, + const ::drafts::com::sun::star::rendering::ViewState& rViewState, + const ::drafts::com::sun::star::rendering::RenderState& rRenderState ); + + ::BitmapEx transformBitmap( const BitmapEx& rBitmap, + const ::drafts::com::sun::star::rendering::ViewState& rViewState, + const ::drafts::com::sun::star::rendering::RenderState& rRenderState ); + + } +} + +#endif /* _VCLCANVAS_TOOLS_HXX */ diff --git a/canvas/source/vcl/makefile.mk b/canvas/source/vcl/makefile.mk new file mode 100644 index 000000000000..d748dfcb81dc --- /dev/null +++ b/canvas/source/vcl/makefile.mk @@ -0,0 +1,106 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.2 $ +# +# last change: $Author: thb $ $Date: 2004-03-18 10:38:43 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=canvas +TARGET=vclcanvas +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------------- + +.INCLUDE : settings.mk +DLLPRE = + +# --- Common ---------------------------------------------------------- + +.IF "$(verbose)"!="" || "$(VERBOSE)"!="" +CDEFS+= -DVERBOSE +.ENDIF + +SLOFILES = $(SLO)$/spritecanvas.obj \ + $(SLO)$/linepolypolygon.obj \ + $(SLO)$/canvasfont.obj \ + $(SLO)$/graphicdevice.obj \ + $(SLO)$/canvasbitmap.obj \ + $(SLO)$/canvasbase.obj \ + $(SLO)$/bitmapcanvas.obj \ + $(SLO)$/canvascustomsprite.obj \ + $(SLO)$/redrawmanager.obj \ + $(SLO)$/impltools.obj + +SHL1TARGET=$(TARGET).uno + +SHL1STDLIBS= $(TOOLSLIB) $(CPPULIB) $(SALLIB) $(VCLLIB) $(COMPHELPERLIB) $(CPPUHELPERLIB) $(BASEGFXLIB) $(CANVASTOOLSLIB) + +#SHL1VERSIONMAP=$(TARGET).map + +SHL1IMPLIB=i$(TARGET) +SHL1LIBS=$(SLB)$/$(TARGET).lib +SHL1DEF=$(MISC)$/$(SHL1TARGET).def + +DEF1NAME=$(SHL1TARGET) +DEF1EXPORTFILE=exports.dxp + +# ========================================================================== + +.INCLUDE : target.mk diff --git a/canvas/source/vcl/outdevprovider.hxx b/canvas/source/vcl/outdevprovider.hxx new file mode 100644 index 000000000000..266a66f91e59 --- /dev/null +++ b/canvas/source/vcl/outdevprovider.hxx @@ -0,0 +1,124 @@ +/************************************************************************* + * + * $RCSfile: outdevprovider.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:43 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VCLCANVAS_OUTDEVPROVIDER_HXX +#define _VCLCANVAS_OUTDEVPROVIDER_HXX + +#ifndef _COMPHELPER_IMPLEMENTATIONREFERENCE_HXX +#include +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XCANVAS_HPP_ +#include +#endif + +class OutputDevice; + +namespace vclcanvas +{ + /* Definition of OutDevProvider interface */ + + /** Helper interface to connect CanvasBase with its various + clients. + */ + + // The problem here is the fact that first of all, XCanvas and its + // specialised interfaces form an inheritance hierarchy. Thus, + // every client of a base class implementing the commons of + // canvases, will have to implement all interface methods, and + // forward them to the base class. Thus, there's no real gain in + // using implementation inheritance here. If we instead use a + // helper class to be held as a member by its client, we have the + // problem that several base methods serve as object factories, + // generating objects which require links to the canvas + // implementation object _and_ a UNO reference. The latter is for + // lifetime issues, and should better be directly from the client + // object. + + // Therefore, every client of CanvasBase must implement this + // interface and pass a pointer to it to the CanvasBase + // instance. The XInterface base class is necessary to have basic + // UNO reference semantics. + + class OutDevProvider : public ::com::sun::star::uno::XInterface + { + public: + /** Use this type to store a C++ pointer alongside a UNO + reference to this interface. + + This is advantageous e.g. for CanvasBase, where several + helper methods (color conversion etc.) need access to the + XCanvas UNO interface. Performing a QueryInterface + everytime is a real performance killer there. + */ + typedef ::comphelper::ImplementationReference< + OutDevProvider, + ::drafts::com::sun::star::rendering::XCanvas, + ::com::sun::star::uno::XInterface > ImplRef; + + virtual ~OutDevProvider() {} + + virtual OutputDevice& getOutDev() = 0; + virtual const OutputDevice& getOutDev() const = 0; + }; +} + +#endif /* _VCLCANVAS_OUTDEVPROVIDER_HXX */ diff --git a/canvas/source/vcl/sprite.hxx b/canvas/source/vcl/sprite.hxx new file mode 100644 index 000000000000..97114e31ab58 --- /dev/null +++ b/canvas/source/vcl/sprite.hxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * $RCSfile: sprite.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:44 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VCLCANVAS_SPRITE_HXX +#define _VCLCANVAS_SPRITE_HXX + +#ifndef _RTL_REF_HXX_ +#include +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XCANVAS_HPP_ +#include +#endif + +#ifndef _BGFX_POINT_B2DSIZE_HXX +#include +#endif + +class OutputDevice; + +namespace vclcanvas +{ + /* Definition of Sprite class */ + + /** Helper interface to connect SpriteCanvas with various + sprite implementations. + */ + + class Sprite : public ::com::sun::star::uno::XInterface + { + public: + typedef ::rtl::Reference< Sprite > ImplRef; + + virtual ~Sprite() {} + + virtual void redraw( OutputDevice& rTargetSurface ) const = 0; + virtual void redraw( OutputDevice& rTargetSurface, const Point& rOutputPosition ) const = 0; + + virtual ::basegfx::B2DSize getSize() const = 0; + }; +} + +#endif /* _VCLCANVAS_SPRITE_HXX */ diff --git a/canvas/source/vcl/spritecanvas.cxx b/canvas/source/vcl/spritecanvas.cxx new file mode 100644 index 000000000000..c2dfb89c69f8 --- /dev/null +++ b/canvas/source/vcl/spritecanvas.cxx @@ -0,0 +1,532 @@ +/************************************************************************* + * + * $RCSfile: spritecanvas.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:44 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _OSL_DIAGNOSE_H_ +#include +#endif + +#ifndef _OSL_MUTEX_HXX_ +#include +#endif +#ifndef _VOS_MUTEX_HXX_ +#include +#endif +#ifndef _SV_SVAPP_HXX +#include +#endif + +#ifndef _SV_OUTDEV_HXX +#include +#endif +#ifndef _SV_WINDOW_HXX +#include +#endif +#ifndef _SV_BITMAPEX_HXX +#include +#endif + +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICENAME_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_XCOMPONENTCONTEXT_HPP_ +#include +#endif + +#ifndef _CPPUHELPER_FACTORY_HXX_ +#include +#endif +#ifndef _CPPUHELPER_IMPLBASE4_HXX_ +#include +#endif +#ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_ +#include +#endif +#ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_ +#include +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XSPRITECANVAS_HPP_ +#include +#endif + +#ifndef BOOST_SCOPED_ARRAY_HPP_INCLUDED +#include +#endif + +#ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX +#include +#endif +#ifndef _BGFX_POINT_B2DPOINT_HXX +#include +#endif +#ifndef _BGFX_TOOLS_CANVASTOOLS_HXX +#include +#endif + +#include + +#include + +#include + +#include "impltools.hxx" +#include "canvasfont.hxx" +#include "spritecanvas.hxx" +#include "graphicdevice.hxx" +#include "outdevprovider.hxx" +#include "canvascustomsprite.hxx" +#include "bitmapcanvas.hxx" + +using namespace ::com::sun::star; +using namespace ::drafts::com::sun::star; + +#define IMPLEMENTATION_NAME "VCLCanvas::SpriteCanvas" +#define SERVICE_NAME "drafts.com.sun.star.rendering.Canvas" + +namespace +{ + static ::rtl::OUString SAL_CALL getImplementationName_SpriteCanvas() + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); + } + + static uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_SpriteCanvas() + { + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); + + return aRet; + } + +} + +namespace vclcanvas +{ + SpriteCanvas::SpriteCanvas( const uno::Reference< uno::XComponentContext >& rxContext ) : + SpriteCanvas_Base( m_aMutex ) + { + } + + SpriteCanvas::~SpriteCanvas() + { + } + + OutDevProvider::ImplRef SpriteCanvas::getImplRef() + { + return OutDevProvider::ImplRef::createFromQuery( this ); + } + + void SAL_CALL SpriteCanvas::drawPoint( const geometry::RealPoint2D& aPoint, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + maCanvasHelper.drawPoint( aPoint, viewState, renderState, getImplRef() ); + } + + void SAL_CALL SpriteCanvas::drawLine( const geometry::RealPoint2D& aStartPoint, const geometry::RealPoint2D& aEndPoint, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + maCanvasHelper.drawLine(aStartPoint, aEndPoint, viewState, renderState, getImplRef()); + } + + void SAL_CALL SpriteCanvas::drawBezier( const geometry::RealBezierSegment2D& aBezierSegment, + const geometry::RealPoint2D& aEndPoint, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + maCanvasHelper.drawBezier(aBezierSegment, aEndPoint, viewState, renderState, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::drawPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + // TODO: Remember to handle backgroundDirty also for XCachedPrimitive redraw! + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.drawPolyPolygon(xPolyPolygon, viewState, renderState, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::strokePolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.strokePolyPolygon(xPolyPolygon, viewState, renderState, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::strokeTexturedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.strokeTexturedPolyPolygon(xPolyPolygon, viewState, renderState, textures, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::strokeTextureMappedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures, const uno::Reference< geometry::XMapping2D >& xMapping, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.strokeTextureMappedPolyPolygon(xPolyPolygon, viewState, renderState, textures, xMapping, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XPolyPolygon2D > SAL_CALL SpriteCanvas::queryStrokeShapes( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.queryStrokeShapes(xPolyPolygon, viewState, renderState, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::fillPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.fillPolyPolygon(xPolyPolygon, viewState, renderState, getImplRef() ); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::fillTexturedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.fillTexturedPolyPolygon(xPolyPolygon, viewState, renderState, textures, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::fillTextureMappedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures, const uno::Reference< geometry::XMapping2D >& xMapping ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.fillTextureMappedPolyPolygon(xPolyPolygon, viewState, renderState, textures, xMapping, getImplRef()); + } + + uno::Reference< rendering::XCanvasFont > SAL_CALL SpriteCanvas::queryFont( const rendering::FontRequest& fontRequest ) throw (uno::RuntimeException) + { + return maCanvasHelper.queryFont( fontRequest, getImplRef() ); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::drawText( const rendering::StringContext& text, + const uno::Reference< rendering::XCanvasFont >& xFont, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 textDirection ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.drawText(text, xFont, viewState, renderState, textDirection, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::drawOffsettedText( const rendering::StringContext& text, const uno::Reference< rendering::XCanvasFont >& xFont, const uno::Sequence< double >& offsets, const rendering::ViewState& viewState, const rendering::RenderState& renderState, sal_Int8 textDirection ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.drawOffsettedText(text, xFont, offsets, viewState, renderState, textDirection, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::drawBitmap( const uno::Reference< rendering::XBitmap >& xBitmap, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.drawBitmap(xBitmap, viewState, renderState, getImplRef()); + } + + uno::Reference< rendering::XGraphicDevice > SAL_CALL SpriteCanvas::getDevice() throw (uno::RuntimeException) + { + return maCanvasHelper.getDevice( getImplRef() ); + } + + void SAL_CALL SpriteCanvas::copyRect( const uno::Reference< rendering::XBitmapCanvas >& sourceCanvas, + const geometry::RealRectangle2D& sourceRect, + const rendering::ViewState& sourceViewState, + const rendering::RenderState& sourceRenderState, + const geometry::RealRectangle2D& destRect, + const rendering::ViewState& destViewState, + const rendering::RenderState& destRenderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + tools::LocalGuard aGuard; + + mpRedrawManager->backgroundDirty(); + } + + uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromAnimation( const uno::Reference< rendering::XAnimation >& animation ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + + return uno::Reference< rendering::XAnimatedSprite >(NULL); + } + + uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromBitmaps( const uno::Sequence< uno::Reference< rendering::XBitmap > >& animationBitmaps, + sal_Int16 interpolationMode ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + + return uno::Reference< rendering::XAnimatedSprite >(NULL); + } + + uno::Reference< rendering::XCustomSprite > SAL_CALL SpriteCanvas::createCustomSprite( const geometry::RealSize2D& spriteSize ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + + return uno::Reference< rendering::XCustomSprite >( + new CanvasCustomSprite( spriteSize, + ImplRef(this)) ); + } + + uno::Reference< rendering::XSprite > SAL_CALL SpriteCanvas::createClonedSprite( const uno::Reference< rendering::XSprite >& original ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + + return uno::Reference< rendering::XSprite >(NULL); + } + + sal_Bool SAL_CALL SpriteCanvas::updateScreen() throw (uno::RuntimeException) + { + checkOurState(); + + tools::LocalGuard aGuard; + + mpRedrawManager->updateScreen(); + + // commit to screen + maCanvasHelper.flush(); + + return sal_True; + } + + void SAL_CALL SpriteCanvas::initialize( const uno::Sequence< uno::Any >& aArguments ) throw( uno::Exception, + uno::RuntimeException) + { + VERBOSE_TRACE( "SpriteCanvas::initialize called" ); + + OSL_ENSURE( aArguments.getLength() >= 1, + "SpriteCanvas::initialize: wrong number of arguments" ); + + // We expect a single Any here, containing a pointer to a valid + // VCL window, on which to output + if( aArguments.getLength() >= 1 && + aArguments[0].getValueTypeClass() == uno::TypeClass_HYPER ) + { + mpOutputWindow = *(Window**)(aArguments[0].getValue()); + OSL_ENSURE( mpOutputWindow != NULL, + "SpriteCanvas::initialize: invalid Window pointer" ); + + // setup back buffer + maVDev->SetOutputSizePixel( mpOutputWindow->GetOutputSizePixel() ); + + // always render into back buffer + maCanvasHelper.setOutDev( *maVDev ); + + mpRedrawManager = ::std::auto_ptr< RedrawManager >( new RedrawManager( *mpOutputWindow, + *maVDev ) ); + } + } + + ::rtl::OUString SAL_CALL SpriteCanvas::getImplementationName() throw( uno::RuntimeException ) + { + return getImplementationName_SpriteCanvas(); + } + + sal_Bool SAL_CALL SpriteCanvas::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) + { + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); + } + + uno::Sequence< ::rtl::OUString > SAL_CALL SpriteCanvas::getSupportedServiceNames() throw( uno::RuntimeException ) + { + return getSupportedServiceNames_SpriteCanvas(); + } + + ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (::com::sun::star::uno::RuntimeException) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) ); + } + + uno::Reference< uno::XInterface > SAL_CALL SpriteCanvas::createInstance( const uno::Reference< uno::XComponentContext >& xContext ) throw ( uno::Exception ) + { + return uno::Reference< uno::XInterface >( static_cast(new SpriteCanvas( xContext )) ); + } + + // SpriteSurface + void SpriteCanvas::showSprite( const Sprite::ImplRef& sprite ) + { + checkOurState(); + + tools::LocalGuard aGuard; + mpRedrawManager->showSprite( sprite ); + } + + void SpriteCanvas::hideSprite( const Sprite::ImplRef& sprite ) + { + checkOurState(); + + // strictly speaking, the solar mutex here is overkill, and a + // object mutex would suffice. But on the other hand, nearly + // every other method needs the solar mutex anyway, so it's no + // big loss (and much simpler) here. + tools::LocalGuard aGuard; + mpRedrawManager->hideSprite( sprite ); + } + + void SpriteCanvas::moveSprite( const Sprite::ImplRef& sprite, + const Point& rOldPos, + const Point& rNewPos ) + { + checkOurState(); + + tools::LocalGuard aGuard; + mpRedrawManager->moveSprite( sprite, rOldPos, rNewPos ); + } + + void SpriteCanvas::updateSprite( const Sprite::ImplRef& sprite, + const Point& rPos, + const Rectangle& rUpdateArea ) + { + checkOurState(); + + tools::LocalGuard aGuard; + mpRedrawManager->updateSprite( sprite, rPos, rUpdateArea ); + } + + // OutDevProvider + ::OutputDevice& SpriteCanvas::getOutDev() + { + return maCanvasHelper.getOutDev(); + } + + const ::OutputDevice& SpriteCanvas::getOutDev() const + { + return maCanvasHelper.getOutDev(); + } + + void SpriteCanvas::checkOurState() + { + if( mpOutputWindow == NULL || + mpRedrawManager.get() == NULL ) + throw uno::RuntimeException(); + } + +} + +namespace +{ + /* shared lib exports implemented with helpers */ + static struct ::cppu::ImplementationEntry s_component_entries [] = + { + { + vclcanvas::SpriteCanvas::createInstance, getImplementationName_SpriteCanvas, + getSupportedServiceNames_SpriteCanvas, ::cppu::createSingleComponentFactory, + 0, 0 + }, + { 0, 0, 0, 0, 0, 0 } + }; +} + + +/* Exported UNO methods for registration and object creation. + ========================================================== + */ +extern "C" +{ + void SAL_CALL component_getImplementationEnvironment( const sal_Char** ppEnvTypeName, + uno_Environment** ppEnv ) + { + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; + } + + sal_Bool SAL_CALL component_writeInfo( lang::XMultiServiceFactory* xMgr, + registry::XRegistryKey* xRegistry ) + { + return ::cppu::component_writeInfoHelper( + xMgr, xRegistry, s_component_entries ); + } + + void * SAL_CALL component_getFactory( sal_Char const* implName, + lang::XMultiServiceFactory* xMgr, + registry::XRegistryKey* xRegistry ) + { + return ::cppu::component_getFactoryHelper( + implName, xMgr, xRegistry, s_component_entries ); + } +} diff --git a/canvas/source/vcl/spritecanvas.hxx b/canvas/source/vcl/spritecanvas.hxx new file mode 100644 index 000000000000..3ef72a84bea9 --- /dev/null +++ b/canvas/source/vcl/spritecanvas.hxx @@ -0,0 +1,298 @@ +/************************************************************************* + * + * $RCSfile: spritecanvas.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:44 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VCLCANVAS_SPRITECANVAS_HXX_ +#define _VCLCANVAS_SPRITECANVAS_HXX_ + +#include + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include +#endif +#ifndef _COM_SUN_STAR_UNO_ANY_HXX_ +#include +#endif + +#ifndef _CPPUHELPER_COMPBASE4_HXX_ +#include +#endif +#ifndef _COMPHELPER_BROADCASTHELPER_HXX_ +#include +#endif +#ifndef _COMPHELPER_UNO3_HXX +#include +#endif + +#ifndef _RTL_REF_HXX_ +#include +#endif + +#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICENAME_HPP_ +#include +#endif + +#ifndef _SV_VIRDEV_HXX +#include +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XSPRITECANVAS_HPP_ +#include +#endif + +#include + +#include "redrawmanager.hxx" +#include "spritesurface.hxx" +#include "outdevprovider.hxx" +#include "canvasbase.hxx" +#include "impltools.hxx" + +class OutputDevice; +class Point; + +namespace com { namespace sun { namespace star { namespace uno +{ + class XComponentContext; + class RuntimeException; +} } } } + +class Window; + +namespace vclcanvas +{ + typedef ::cppu::WeakComponentImplHelper4< ::drafts::com::sun::star::rendering::XSpriteCanvas, + ::com::sun::star::lang::XInitialization, + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::lang::XServiceName > SpriteCanvas_Base; + + class SpriteCanvas : public ::comphelper::OBaseMutex, + public SpriteSurface, + public OutDevProvider, + public SpriteCanvas_Base + + { + public: + typedef ::rtl::Reference< SpriteCanvas > ImplRef; + + SpriteCanvas( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ); + + // XInterface + + // Need to implement that, because OutDevProvide comes with an + // unimplemented version of XInterface. + + // Forwarding the XInterface implementation to the + // cppu::ImplHelper templated base, which does the refcounting and + // queryInterface for us: Classname Base doing refcount and handling queryInterface + // | | + // V V + DECLARE_UNO3_AGG_DEFAULTS( SpriteCanvas, SpriteCanvas_Base ); + + // XCanvas + virtual void SAL_CALL drawPoint( const ::drafts::com::sun::star::geometry::RealPoint2D& aPoint, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL drawLine( const ::drafts::com::sun::star::geometry::RealPoint2D& aStartPoint, + const ::drafts::com::sun::star::geometry::RealPoint2D& aEndPoint, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL drawBezier( const ::drafts::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment, + const ::drafts::com::sun::star::geometry::RealPoint2D& aEndPoint, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + strokePolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + strokeTexturedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + strokeTextureMappedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::geometry::XMapping2D >& xMapping, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D > SAL_CALL + queryStrokeShapes( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + fillPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + fillTexturedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + fillTextureMappedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::geometry::XMapping2D >& xMapping ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvasFont > SAL_CALL + queryFont( const ::drafts::com::sun::star::rendering::FontRequest& fontRequest ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawText( const ::drafts::com::sun::star::rendering::StringContext& text, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvasFont >& xFont, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + sal_Int8 textDirection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawOffsettedText( const ::drafts::com::sun::star::rendering::StringContext& text, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvasFont >& xFont, + const ::com::sun::star::uno::Sequence< double >& offsets, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + sal_Int8 textDirection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawBitmap( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmap >& xBitmap, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XGraphicDevice > SAL_CALL + getDevice() throw (::com::sun::star::uno::RuntimeException); + + // XBitmapCanvas (only providing, not implementing the + // interface. Also note subtle method parameter differences) + virtual void SAL_CALL copyRect( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmapCanvas >& sourceCanvas, + const ::drafts::com::sun::star::geometry::RealRectangle2D& sourceRect, + const ::drafts::com::sun::star::rendering::ViewState& sourceViewState, + const ::drafts::com::sun::star::rendering::RenderState& sourceRenderState, + const ::drafts::com::sun::star::geometry::RealRectangle2D& destRect, + const ::drafts::com::sun::star::rendering::ViewState& destViewState, + const ::drafts::com::sun::star::rendering::RenderState& destRenderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + // XSpriteCanvas + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XAnimatedSprite > SAL_CALL createSpriteFromAnimation( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XAnimation >& animation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XAnimatedSprite > SAL_CALL createSpriteFromBitmaps( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmap > >& animationBitmaps, + sal_Int16 interpolationMode ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCustomSprite > SAL_CALL createCustomSprite( const ::drafts::com::sun::star::geometry::RealSize2D& spriteSize ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XSprite > SAL_CALL createClonedSprite( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XSprite >& original ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL updateScreen() throw (::com::sun::star::uno::RuntimeException); + + // XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw( ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ); + + // XServiceName + virtual ::rtl::OUString SAL_CALL getServiceName( ) throw (::com::sun::star::uno::RuntimeException); + + // factory + static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext ) throw ( ::com::sun::star::uno::Exception ); + + // SpriteSurface + virtual void showSprite( const Sprite::ImplRef& sprite ); + virtual void hideSprite( const Sprite::ImplRef& sprite ); + virtual void moveSprite( const Sprite::ImplRef& sprite, + const Point& rOldPos, + const Point& rNewPos ); + virtual void updateSprite( const Sprite::ImplRef& sprite, + const Point& rPos, + const Rectangle& rUpdateArea ); + + // OutDevProvider + virtual OutputDevice& getOutDev(); + virtual const OutputDevice& getOutDev() const; + + protected: + ~SpriteCanvas(); // we're a ref-counted UNO class. _We_ destroy ourselves. + + private: + // default: disabled copy/assignment + SpriteCanvas(const SpriteCanvas&); + SpriteCanvas& operator=( const SpriteCanvas& ); + + void checkOurState(); // throws + OutDevProvider::ImplRef getImplRef(); + + // TODO: Lifetime issue. Cannot control pointer validity over + // object lifetime, since we're a UNO component + Window* mpOutputWindow; // for the screen output + ::canvas::vcltools::VCLObject maVDev; // for the back-buffer + ::std::auto_ptr< RedrawManager > mpRedrawManager; // handles smooth screen updates for us + CanvasBase maCanvasHelper; // for the basic canvas implementation + }; +} + +#endif -- cgit