xref: /AOO41X/main/canvas/source/tools/canvastools.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_canvas.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <canvas/debug.hxx>
32*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <com/sun/star/geometry/AffineMatrix2D.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/geometry/Matrix2D.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/awt/Rectangle.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/util/Endianness.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/rendering/XIntegerBitmapColorSpace.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/rendering/IntegerBitmapLayout.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/rendering/ColorSpaceType.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/rendering/ColorComponentTag.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/rendering/RenderingIntent.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/rendering/RenderState.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/rendering/ViewState.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/rendering/XColorSpace.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/rendering/CompositeOperation.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
52*cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx>
53*cdf0e10cSrcweir #include <basegfx/range/b2irange.hxx>
54*cdf0e10cSrcweir #include <basegfx/range/b2drectangle.hxx>
55*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
56*cdf0e10cSrcweir #include <basegfx/point/b2ipoint.hxx>
57*cdf0e10cSrcweir #include <basegfx/vector/b2ivector.hxx>
58*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
59*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
60*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
61*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
62*cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
63*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx>
66*cdf0e10cSrcweir #include <rtl/instance.hxx>
67*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
68*cdf0e10cSrcweir #include <vcl/window.hxx>
69*cdf0e10cSrcweir #include <vcl/canvastools.hxx>
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir #include <canvas/canvastools.hxx>
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir #include <limits>
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir using namespace ::com::sun::star;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace rendering
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir     bool operator==( const RenderState& renderState1,
81*cdf0e10cSrcweir                      const RenderState& renderState2 )
82*cdf0e10cSrcweir     {
83*cdf0e10cSrcweir         if( renderState1.Clip != renderState2.Clip )
84*cdf0e10cSrcweir             return false;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir         if( renderState1.DeviceColor != renderState2.DeviceColor )
87*cdf0e10cSrcweir             return false;
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir         if( renderState1.CompositeOperation != renderState2.CompositeOperation )
90*cdf0e10cSrcweir             return false;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir         ::basegfx::B2DHomMatrix mat1, mat2;
93*cdf0e10cSrcweir         ::canvas::tools::getRenderStateTransform( mat1, renderState1 );
94*cdf0e10cSrcweir         ::canvas::tools::getRenderStateTransform( mat2, renderState2 );
95*cdf0e10cSrcweir         if( mat1 != mat2 )
96*cdf0e10cSrcweir             return false;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir         return true;
99*cdf0e10cSrcweir     }
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir     bool operator==( const ViewState& viewState1,
102*cdf0e10cSrcweir                      const ViewState& viewState2 )
103*cdf0e10cSrcweir     {
104*cdf0e10cSrcweir         if( viewState1.Clip != viewState2.Clip )
105*cdf0e10cSrcweir             return false;
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir         ::basegfx::B2DHomMatrix mat1, mat2;
108*cdf0e10cSrcweir         ::canvas::tools::getViewStateTransform( mat1, viewState1 );
109*cdf0e10cSrcweir         ::canvas::tools::getViewStateTransform( mat2, viewState2 );
110*cdf0e10cSrcweir         if( mat1 != mat2 )
111*cdf0e10cSrcweir             return false;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir         return true;
114*cdf0e10cSrcweir     }
115*cdf0e10cSrcweir }}}}
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir namespace canvas
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir     namespace tools
120*cdf0e10cSrcweir     {
121*cdf0e10cSrcweir         geometry::RealSize2D createInfiniteSize2D()
122*cdf0e10cSrcweir         {
123*cdf0e10cSrcweir             return geometry::RealSize2D(
124*cdf0e10cSrcweir                 ::std::numeric_limits<double>::infinity(),
125*cdf0e10cSrcweir                 ::std::numeric_limits<double>::infinity() );
126*cdf0e10cSrcweir         }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir         rendering::RenderState& initRenderState( rendering::RenderState& renderState )
129*cdf0e10cSrcweir         {
130*cdf0e10cSrcweir             // setup identity transform
131*cdf0e10cSrcweir             setIdentityAffineMatrix2D( renderState.AffineTransform );
132*cdf0e10cSrcweir             renderState.Clip = uno::Reference< rendering::XPolyPolygon2D >();
133*cdf0e10cSrcweir             renderState.DeviceColor = uno::Sequence< double >();
134*cdf0e10cSrcweir             renderState.CompositeOperation = rendering::CompositeOperation::OVER;
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir             return renderState;
137*cdf0e10cSrcweir         }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir         rendering::ViewState& initViewState( rendering::ViewState& viewState )
140*cdf0e10cSrcweir         {
141*cdf0e10cSrcweir             // setup identity transform
142*cdf0e10cSrcweir             setIdentityAffineMatrix2D( viewState.AffineTransform );
143*cdf0e10cSrcweir             viewState.Clip = uno::Reference< rendering::XPolyPolygon2D >();
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir             return viewState;
146*cdf0e10cSrcweir         }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir         ::basegfx::B2DHomMatrix& getViewStateTransform( ::basegfx::B2DHomMatrix&	transform,
149*cdf0e10cSrcweir                                                         const rendering::ViewState&	viewState )
150*cdf0e10cSrcweir         {
151*cdf0e10cSrcweir             return ::basegfx::unotools::homMatrixFromAffineMatrix( transform, viewState.AffineTransform );
152*cdf0e10cSrcweir         }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir         rendering::ViewState& setViewStateTransform( rendering::ViewState& 			viewState,
155*cdf0e10cSrcweir                                                      const ::basegfx::B2DHomMatrix&	transform )
156*cdf0e10cSrcweir         {
157*cdf0e10cSrcweir             ::basegfx::unotools::affineMatrixFromHomMatrix( viewState.AffineTransform, transform );
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir             return viewState;
160*cdf0e10cSrcweir         }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir         ::basegfx::B2DHomMatrix& getRenderStateTransform( ::basegfx::B2DHomMatrix&		transform,
163*cdf0e10cSrcweir                                                           const rendering::RenderState&	renderState )
164*cdf0e10cSrcweir         {
165*cdf0e10cSrcweir             return ::basegfx::unotools::homMatrixFromAffineMatrix( transform, renderState.AffineTransform );
166*cdf0e10cSrcweir         }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir         rendering::RenderState& setRenderStateTransform( rendering::RenderState& 		renderState,
169*cdf0e10cSrcweir                                                          const ::basegfx::B2DHomMatrix&	transform )
170*cdf0e10cSrcweir         {
171*cdf0e10cSrcweir             ::basegfx::unotools::affineMatrixFromHomMatrix( renderState.AffineTransform, transform );
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir             return renderState;
174*cdf0e10cSrcweir         }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         rendering::RenderState& appendToRenderState( rendering::RenderState&		renderState,
177*cdf0e10cSrcweir                                                    const ::basegfx::B2DHomMatrix&	rTransform )
178*cdf0e10cSrcweir         {
179*cdf0e10cSrcweir             ::basegfx::B2DHomMatrix transform;
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir             getRenderStateTransform( transform, renderState );
182*cdf0e10cSrcweir             return setRenderStateTransform( renderState, transform * rTransform );
183*cdf0e10cSrcweir         }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir         rendering::ViewState& appendToViewState( rendering::ViewState&			viewState,
186*cdf0e10cSrcweir                                                  const ::basegfx::B2DHomMatrix&	rTransform )
187*cdf0e10cSrcweir         {
188*cdf0e10cSrcweir             ::basegfx::B2DHomMatrix transform;
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir             getViewStateTransform( transform, viewState );
191*cdf0e10cSrcweir             return setViewStateTransform( viewState, transform * rTransform );
192*cdf0e10cSrcweir         }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir         rendering::RenderState& prependToRenderState( rendering::RenderState&			renderState,
195*cdf0e10cSrcweir                                                       const ::basegfx::B2DHomMatrix&	rTransform )
196*cdf0e10cSrcweir         {
197*cdf0e10cSrcweir             ::basegfx::B2DHomMatrix transform;
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir             getRenderStateTransform( transform, renderState );
200*cdf0e10cSrcweir             return setRenderStateTransform( renderState, rTransform * transform );
201*cdf0e10cSrcweir         }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir         rendering::ViewState& prependToViewState( rendering::ViewState&				viewState,
204*cdf0e10cSrcweir                                                   const ::basegfx::B2DHomMatrix&		rTransform )
205*cdf0e10cSrcweir         {
206*cdf0e10cSrcweir             ::basegfx::B2DHomMatrix transform;
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir             getViewStateTransform( transform, viewState );
209*cdf0e10cSrcweir             return setViewStateTransform( viewState, rTransform * transform );
210*cdf0e10cSrcweir         }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir         ::basegfx::B2DHomMatrix& mergeViewAndRenderTransform( ::basegfx::B2DHomMatrix&		combinedTransform,
213*cdf0e10cSrcweir                                                               const rendering::ViewState&	viewState,
214*cdf0e10cSrcweir                                                               const rendering::RenderState& renderState	)
215*cdf0e10cSrcweir         {
216*cdf0e10cSrcweir             ::basegfx::B2DHomMatrix viewTransform;
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir             ::basegfx::unotools::homMatrixFromAffineMatrix( combinedTransform, renderState.AffineTransform );
219*cdf0e10cSrcweir             ::basegfx::unotools::homMatrixFromAffineMatrix( viewTransform, viewState.AffineTransform );
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 			// this statement performs combinedTransform = viewTransform * combinedTransform
222*cdf0e10cSrcweir             combinedTransform *= viewTransform;
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir             return combinedTransform;
225*cdf0e10cSrcweir         }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir         rendering::ViewState& mergeViewAndRenderState( rendering::ViewState&						resultViewState,
228*cdf0e10cSrcweir                                                        const rendering::ViewState&					viewState,
229*cdf0e10cSrcweir                                                        const rendering::RenderState&				renderState,
230*cdf0e10cSrcweir                                                        const uno::Reference< rendering::XCanvas >& 	/*xCanvas*/ 	)
231*cdf0e10cSrcweir         {
232*cdf0e10cSrcweir             ::basegfx::B2DHomMatrix		aTmpMatrix;
233*cdf0e10cSrcweir             geometry::AffineMatrix2D 	convertedMatrix;
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir             resultViewState.Clip = NULL; // TODO(F2): intersect clippings
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir             return setViewStateTransform(
238*cdf0e10cSrcweir                 resultViewState,
239*cdf0e10cSrcweir                 mergeViewAndRenderTransform( aTmpMatrix,
240*cdf0e10cSrcweir                                              viewState,
241*cdf0e10cSrcweir                                              renderState ) );
242*cdf0e10cSrcweir         }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir         geometry::AffineMatrix2D& setIdentityAffineMatrix2D( geometry::AffineMatrix2D& matrix )
245*cdf0e10cSrcweir         {
246*cdf0e10cSrcweir             matrix.m00 = 1.0;
247*cdf0e10cSrcweir             matrix.m01 = 0.0;
248*cdf0e10cSrcweir             matrix.m02 = 0.0;
249*cdf0e10cSrcweir             matrix.m10 = 0.0;
250*cdf0e10cSrcweir             matrix.m11 = 1.0;
251*cdf0e10cSrcweir             matrix.m12 = 0.0;
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir             return matrix;
254*cdf0e10cSrcweir         }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir         geometry::Matrix2D& setIdentityMatrix2D( geometry::Matrix2D& matrix )
257*cdf0e10cSrcweir         {
258*cdf0e10cSrcweir             matrix.m00 = 1.0;
259*cdf0e10cSrcweir             matrix.m01 = 0.0;
260*cdf0e10cSrcweir             matrix.m10 = 0.0;
261*cdf0e10cSrcweir             matrix.m11 = 1.0;
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir             return matrix;
264*cdf0e10cSrcweir         }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir         namespace
267*cdf0e10cSrcweir         {
268*cdf0e10cSrcweir             class StandardColorSpace : public cppu::WeakImplHelper1< com::sun::star::rendering::XIntegerBitmapColorSpace >
269*cdf0e10cSrcweir             {
270*cdf0e10cSrcweir             private:
271*cdf0e10cSrcweir                 uno::Sequence< sal_Int8 >  maComponentTags;
272*cdf0e10cSrcweir                 uno::Sequence< sal_Int32 > maBitCounts;
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir                 virtual ::sal_Int8 SAL_CALL getType(  ) throw (uno::RuntimeException)
275*cdf0e10cSrcweir                 {
276*cdf0e10cSrcweir                     return rendering::ColorSpaceType::RGB;
277*cdf0e10cSrcweir                 }
278*cdf0e10cSrcweir                 virtual uno::Sequence< ::sal_Int8 > SAL_CALL getComponentTags(  ) throw (uno::RuntimeException)
279*cdf0e10cSrcweir                 {
280*cdf0e10cSrcweir                     return maComponentTags;
281*cdf0e10cSrcweir                 }
282*cdf0e10cSrcweir                 virtual ::sal_Int8 SAL_CALL getRenderingIntent(  ) throw (uno::RuntimeException)
283*cdf0e10cSrcweir                 {
284*cdf0e10cSrcweir                     return rendering::RenderingIntent::PERCEPTUAL;
285*cdf0e10cSrcweir                 }
286*cdf0e10cSrcweir                 virtual uno::Sequence< beans::PropertyValue > SAL_CALL getProperties(  ) throw (uno::RuntimeException)
287*cdf0e10cSrcweir                 {
288*cdf0e10cSrcweir                     return uno::Sequence< beans::PropertyValue >();
289*cdf0e10cSrcweir                 }
290*cdf0e10cSrcweir                 virtual uno::Sequence< double > SAL_CALL convertColorSpace( const uno::Sequence< double >& deviceColor,
291*cdf0e10cSrcweir                                                                             const uno::Reference< rendering::XColorSpace >& targetColorSpace ) throw (lang::IllegalArgumentException,
292*cdf0e10cSrcweir                                                                                                                                                       uno::RuntimeException)
293*cdf0e10cSrcweir                 {
294*cdf0e10cSrcweir                     // TODO(P3): if we know anything about target
295*cdf0e10cSrcweir                     // colorspace, this can be greatly sped up
296*cdf0e10cSrcweir                     uno::Sequence<rendering::ARGBColor> aIntermediate(
297*cdf0e10cSrcweir                         convertToARGB(deviceColor));
298*cdf0e10cSrcweir                     return targetColorSpace->convertFromARGB(aIntermediate);
299*cdf0e10cSrcweir                 }
300*cdf0e10cSrcweir                 virtual uno::Sequence< rendering::RGBColor > SAL_CALL convertToRGB( const uno::Sequence< double >& deviceColor ) throw (lang::IllegalArgumentException, uno::RuntimeException)
301*cdf0e10cSrcweir                 {
302*cdf0e10cSrcweir                     const double*  pIn( deviceColor.getConstArray() );
303*cdf0e10cSrcweir                     const sal_Size nLen( deviceColor.getLength() );
304*cdf0e10cSrcweir                     ENSURE_ARG_OR_THROW2(nLen%4==0,
305*cdf0e10cSrcweir                                          "number of channels no multiple of 4",
306*cdf0e10cSrcweir                                          static_cast<rendering::XColorSpace*>(this), 0);
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir                     uno::Sequence< rendering::RGBColor > aRes(nLen/4);
309*cdf0e10cSrcweir                     rendering::RGBColor* pOut( aRes.getArray() );
310*cdf0e10cSrcweir                     for( sal_Size i=0; i<nLen; i+=4 )
311*cdf0e10cSrcweir                     {
312*cdf0e10cSrcweir                         *pOut++ = rendering::RGBColor(pIn[0],pIn[1],pIn[2]);
313*cdf0e10cSrcweir                         pIn += 4;
314*cdf0e10cSrcweir                     }
315*cdf0e10cSrcweir                     return aRes;
316*cdf0e10cSrcweir                 }
317*cdf0e10cSrcweir                 virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertToARGB( const uno::Sequence< double >& deviceColor ) throw (lang::IllegalArgumentException, uno::RuntimeException)
318*cdf0e10cSrcweir                 {
319*cdf0e10cSrcweir                     const double*  pIn( deviceColor.getConstArray() );
320*cdf0e10cSrcweir                     const sal_Size nLen( deviceColor.getLength() );
321*cdf0e10cSrcweir                     ENSURE_ARG_OR_THROW2(nLen%4==0,
322*cdf0e10cSrcweir                                          "number of channels no multiple of 4",
323*cdf0e10cSrcweir                                          static_cast<rendering::XColorSpace*>(this), 0);
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir                     uno::Sequence< rendering::ARGBColor > aRes(nLen/4);
326*cdf0e10cSrcweir                     rendering::ARGBColor* pOut( aRes.getArray() );
327*cdf0e10cSrcweir                     for( sal_Size i=0; i<nLen; i+=4 )
328*cdf0e10cSrcweir                     {
329*cdf0e10cSrcweir                         *pOut++ = rendering::ARGBColor(pIn[3],pIn[0],pIn[1],pIn[2]);
330*cdf0e10cSrcweir                         pIn += 4;
331*cdf0e10cSrcweir                     }
332*cdf0e10cSrcweir                     return aRes;
333*cdf0e10cSrcweir                 }
334*cdf0e10cSrcweir                 virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertToPARGB( const uno::Sequence< double >& deviceColor ) throw (lang::IllegalArgumentException, uno::RuntimeException)
335*cdf0e10cSrcweir                 {
336*cdf0e10cSrcweir                     const double*  pIn( deviceColor.getConstArray() );
337*cdf0e10cSrcweir                     const sal_Size nLen( deviceColor.getLength() );
338*cdf0e10cSrcweir                     ENSURE_ARG_OR_THROW2(nLen%4==0,
339*cdf0e10cSrcweir                                          "number of channels no multiple of 4",
340*cdf0e10cSrcweir                                          static_cast<rendering::XColorSpace*>(this), 0);
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir                     uno::Sequence< rendering::ARGBColor > aRes(nLen/4);
343*cdf0e10cSrcweir                     rendering::ARGBColor* pOut( aRes.getArray() );
344*cdf0e10cSrcweir                     for( sal_Size i=0; i<nLen; i+=4 )
345*cdf0e10cSrcweir                     {
346*cdf0e10cSrcweir                         *pOut++ = rendering::ARGBColor(pIn[3],pIn[3]*pIn[0],pIn[3]*pIn[1],pIn[3]*pIn[2]);
347*cdf0e10cSrcweir                         pIn += 4;
348*cdf0e10cSrcweir                     }
349*cdf0e10cSrcweir                     return aRes;
350*cdf0e10cSrcweir                 }
351*cdf0e10cSrcweir                 virtual uno::Sequence< double > SAL_CALL convertFromRGB( const uno::Sequence< rendering::RGBColor >& rgbColor ) throw (lang::IllegalArgumentException, uno::RuntimeException)
352*cdf0e10cSrcweir                 {
353*cdf0e10cSrcweir                     const rendering::RGBColor* pIn( rgbColor.getConstArray() );
354*cdf0e10cSrcweir                     const sal_Size             nLen( rgbColor.getLength() );
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir                     uno::Sequence< double > aRes(nLen*4);
357*cdf0e10cSrcweir                     double* pColors=aRes.getArray();
358*cdf0e10cSrcweir                     for( sal_Size i=0; i<nLen; ++i )
359*cdf0e10cSrcweir                     {
360*cdf0e10cSrcweir                         *pColors++ = pIn->Red;
361*cdf0e10cSrcweir                         *pColors++ = pIn->Green;
362*cdf0e10cSrcweir                         *pColors++ = pIn->Blue;
363*cdf0e10cSrcweir                         *pColors++ = 1.0;
364*cdf0e10cSrcweir                         ++pIn;
365*cdf0e10cSrcweir                     }
366*cdf0e10cSrcweir                     return aRes;
367*cdf0e10cSrcweir                 }
368*cdf0e10cSrcweir                 virtual uno::Sequence< double > SAL_CALL convertFromARGB( const uno::Sequence< rendering::ARGBColor >& rgbColor ) throw (lang::IllegalArgumentException, uno::RuntimeException)
369*cdf0e10cSrcweir                 {
370*cdf0e10cSrcweir                     const rendering::ARGBColor* pIn( rgbColor.getConstArray() );
371*cdf0e10cSrcweir                     const sal_Size              nLen( rgbColor.getLength() );
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir                     uno::Sequence< double > aRes(nLen*4);
374*cdf0e10cSrcweir                     double* pColors=aRes.getArray();
375*cdf0e10cSrcweir                     for( sal_Size i=0; i<nLen; ++i )
376*cdf0e10cSrcweir                     {
377*cdf0e10cSrcweir                         *pColors++ = pIn->Red;
378*cdf0e10cSrcweir                         *pColors++ = pIn->Green;
379*cdf0e10cSrcweir                         *pColors++ = pIn->Blue;
380*cdf0e10cSrcweir                         *pColors++ = pIn->Alpha;
381*cdf0e10cSrcweir                         ++pIn;
382*cdf0e10cSrcweir                     }
383*cdf0e10cSrcweir                     return aRes;
384*cdf0e10cSrcweir                 }
385*cdf0e10cSrcweir                 virtual uno::Sequence< double > SAL_CALL convertFromPARGB( const uno::Sequence< rendering::ARGBColor >& rgbColor ) throw (lang::IllegalArgumentException, uno::RuntimeException)
386*cdf0e10cSrcweir                 {
387*cdf0e10cSrcweir                     const rendering::ARGBColor* pIn( rgbColor.getConstArray() );
388*cdf0e10cSrcweir                     const sal_Size              nLen( rgbColor.getLength() );
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir                     uno::Sequence< double > aRes(nLen*4);
391*cdf0e10cSrcweir                     double* pColors=aRes.getArray();
392*cdf0e10cSrcweir                     for( sal_Size i=0; i<nLen; ++i )
393*cdf0e10cSrcweir                     {
394*cdf0e10cSrcweir                         *pColors++ = pIn->Red/pIn->Alpha;
395*cdf0e10cSrcweir                         *pColors++ = pIn->Green/pIn->Alpha;
396*cdf0e10cSrcweir                         *pColors++ = pIn->Blue/pIn->Alpha;
397*cdf0e10cSrcweir                         *pColors++ = pIn->Alpha;
398*cdf0e10cSrcweir                         ++pIn;
399*cdf0e10cSrcweir                     }
400*cdf0e10cSrcweir                     return aRes;
401*cdf0e10cSrcweir                 }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir                 // XIntegerBitmapColorSpace
404*cdf0e10cSrcweir                 virtual ::sal_Int32 SAL_CALL getBitsPerPixel(  ) throw (uno::RuntimeException)
405*cdf0e10cSrcweir                 {
406*cdf0e10cSrcweir                     return 32;
407*cdf0e10cSrcweir                 }
408*cdf0e10cSrcweir                 virtual uno::Sequence< ::sal_Int32 > SAL_CALL getComponentBitCounts(  ) throw (uno::RuntimeException)
409*cdf0e10cSrcweir                 {
410*cdf0e10cSrcweir                     return maBitCounts;
411*cdf0e10cSrcweir                 }
412*cdf0e10cSrcweir                 virtual ::sal_Int8 SAL_CALL getEndianness(  ) throw (uno::RuntimeException)
413*cdf0e10cSrcweir                 {
414*cdf0e10cSrcweir                     return util::Endianness::LITTLE;
415*cdf0e10cSrcweir                 }
416*cdf0e10cSrcweir                 virtual uno::Sequence<double> SAL_CALL convertFromIntegerColorSpace( const uno::Sequence< ::sal_Int8 >& deviceColor,
417*cdf0e10cSrcweir                                                                                      const uno::Reference< rendering::XColorSpace >& targetColorSpace ) throw (lang::IllegalArgumentException,
418*cdf0e10cSrcweir                                                                                                                                                                uno::RuntimeException)
419*cdf0e10cSrcweir                 {
420*cdf0e10cSrcweir                     if( dynamic_cast<StandardColorSpace*>(targetColorSpace.get()) )
421*cdf0e10cSrcweir                     {
422*cdf0e10cSrcweir                         const sal_Int8* pIn( deviceColor.getConstArray() );
423*cdf0e10cSrcweir                         const sal_Size  nLen( deviceColor.getLength() );
424*cdf0e10cSrcweir                         ENSURE_ARG_OR_THROW2(nLen%4==0,
425*cdf0e10cSrcweir                                              "number of channels no multiple of 4",
426*cdf0e10cSrcweir                                              static_cast<rendering::XColorSpace*>(this), 0);
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir                         uno::Sequence<double> aRes(nLen);
429*cdf0e10cSrcweir                         double* pOut( aRes.getArray() );
430*cdf0e10cSrcweir                         for( sal_Size i=0; i<nLen; i+=4 )
431*cdf0e10cSrcweir                         {
432*cdf0e10cSrcweir                             *pOut++ = vcl::unotools::toDoubleColor(*pIn++);
433*cdf0e10cSrcweir                             *pOut++ = vcl::unotools::toDoubleColor(*pIn++);
434*cdf0e10cSrcweir                             *pOut++ = vcl::unotools::toDoubleColor(*pIn++);
435*cdf0e10cSrcweir                             *pOut++ = vcl::unotools::toDoubleColor(255-*pIn++);
436*cdf0e10cSrcweir                         }
437*cdf0e10cSrcweir                         return aRes;
438*cdf0e10cSrcweir                     }
439*cdf0e10cSrcweir                     else
440*cdf0e10cSrcweir                     {
441*cdf0e10cSrcweir                         // TODO(P3): if we know anything about target
442*cdf0e10cSrcweir                         // colorspace, this can be greatly sped up
443*cdf0e10cSrcweir                         uno::Sequence<rendering::ARGBColor> aIntermediate(
444*cdf0e10cSrcweir                             convertIntegerToARGB(deviceColor));
445*cdf0e10cSrcweir                         return targetColorSpace->convertFromARGB(aIntermediate);
446*cdf0e10cSrcweir                     }
447*cdf0e10cSrcweir                 }
448*cdf0e10cSrcweir                 virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertToIntegerColorSpace( const uno::Sequence< ::sal_Int8 >& deviceColor,
449*cdf0e10cSrcweir                                                                                          const uno::Reference< rendering::XIntegerBitmapColorSpace >& targetColorSpace ) throw (lang::IllegalArgumentException,
450*cdf0e10cSrcweir                                                                                                                                                                               uno::RuntimeException)
451*cdf0e10cSrcweir                 {
452*cdf0e10cSrcweir                     if( dynamic_cast<StandardColorSpace*>(targetColorSpace.get()) )
453*cdf0e10cSrcweir                     {
454*cdf0e10cSrcweir                         // it's us, so simply pass-through the data
455*cdf0e10cSrcweir                         return deviceColor;
456*cdf0e10cSrcweir                     }
457*cdf0e10cSrcweir                     else
458*cdf0e10cSrcweir                     {
459*cdf0e10cSrcweir                         // TODO(P3): if we know anything about target
460*cdf0e10cSrcweir                         // colorspace, this can be greatly sped up
461*cdf0e10cSrcweir                         uno::Sequence<rendering::ARGBColor> aIntermediate(
462*cdf0e10cSrcweir                             convertIntegerToARGB(deviceColor));
463*cdf0e10cSrcweir                         return targetColorSpace->convertIntegerFromARGB(aIntermediate);
464*cdf0e10cSrcweir                     }
465*cdf0e10cSrcweir                 }
466*cdf0e10cSrcweir                 virtual uno::Sequence< rendering::RGBColor > SAL_CALL convertIntegerToRGB( const uno::Sequence< ::sal_Int8 >& deviceColor ) throw (lang::IllegalArgumentException, uno::RuntimeException)
467*cdf0e10cSrcweir                 {
468*cdf0e10cSrcweir                     const sal_Int8* pIn( deviceColor.getConstArray() );
469*cdf0e10cSrcweir                     const sal_Size  nLen( deviceColor.getLength() );
470*cdf0e10cSrcweir                     ENSURE_ARG_OR_THROW2(nLen%4==0,
471*cdf0e10cSrcweir                                          "number of channels no multiple of 4",
472*cdf0e10cSrcweir                                          static_cast<rendering::XColorSpace*>(this), 0);
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir                     uno::Sequence< rendering::RGBColor > aRes(nLen/4);
475*cdf0e10cSrcweir                     rendering::RGBColor* pOut( aRes.getArray() );
476*cdf0e10cSrcweir                     for( sal_Size i=0; i<nLen; i+=4 )
477*cdf0e10cSrcweir                     {
478*cdf0e10cSrcweir                         *pOut++ = rendering::RGBColor(
479*cdf0e10cSrcweir                             vcl::unotools::toDoubleColor(pIn[0]),
480*cdf0e10cSrcweir                             vcl::unotools::toDoubleColor(pIn[1]),
481*cdf0e10cSrcweir                             vcl::unotools::toDoubleColor(pIn[2]));
482*cdf0e10cSrcweir                         pIn += 4;
483*cdf0e10cSrcweir                     }
484*cdf0e10cSrcweir                     return aRes;
485*cdf0e10cSrcweir                 }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir                 virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertIntegerToARGB( const uno::Sequence< ::sal_Int8 >& deviceColor ) throw (lang::IllegalArgumentException, uno::RuntimeException)
488*cdf0e10cSrcweir                 {
489*cdf0e10cSrcweir                     const sal_Int8* pIn( deviceColor.getConstArray() );
490*cdf0e10cSrcweir                     const sal_Size  nLen( deviceColor.getLength() );
491*cdf0e10cSrcweir                     ENSURE_ARG_OR_THROW2(nLen%4==0,
492*cdf0e10cSrcweir                                          "number of channels no multiple of 4",
493*cdf0e10cSrcweir                                          static_cast<rendering::XColorSpace*>(this), 0);
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir                     uno::Sequence< rendering::ARGBColor > aRes(nLen/4);
496*cdf0e10cSrcweir                     rendering::ARGBColor* pOut( aRes.getArray() );
497*cdf0e10cSrcweir                     for( sal_Size i=0; i<nLen; i+=4 )
498*cdf0e10cSrcweir                     {
499*cdf0e10cSrcweir                         *pOut++ = rendering::ARGBColor(
500*cdf0e10cSrcweir                             vcl::unotools::toDoubleColor(255-pIn[3]),
501*cdf0e10cSrcweir                             vcl::unotools::toDoubleColor(pIn[0]),
502*cdf0e10cSrcweir                             vcl::unotools::toDoubleColor(pIn[1]),
503*cdf0e10cSrcweir                             vcl::unotools::toDoubleColor(pIn[2]));
504*cdf0e10cSrcweir                         pIn += 4;
505*cdf0e10cSrcweir                     }
506*cdf0e10cSrcweir                     return aRes;
507*cdf0e10cSrcweir                 }
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir                 virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertIntegerToPARGB( const uno::Sequence< ::sal_Int8 >& deviceColor ) throw (lang::IllegalArgumentException, uno::RuntimeException)
510*cdf0e10cSrcweir                 {
511*cdf0e10cSrcweir                     const sal_Int8* pIn( deviceColor.getConstArray() );
512*cdf0e10cSrcweir                     const sal_Size  nLen( deviceColor.getLength() );
513*cdf0e10cSrcweir                     ENSURE_ARG_OR_THROW2(nLen%4==0,
514*cdf0e10cSrcweir                                          "number of channels no multiple of 4",
515*cdf0e10cSrcweir                                          static_cast<rendering::XColorSpace*>(this), 0);
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir                     uno::Sequence< rendering::ARGBColor > aRes(nLen/4);
518*cdf0e10cSrcweir                     rendering::ARGBColor* pOut( aRes.getArray() );
519*cdf0e10cSrcweir                     for( sal_Size i=0; i<nLen; i+=4 )
520*cdf0e10cSrcweir                     {
521*cdf0e10cSrcweir                         const sal_Int8 nAlpha( 255-pIn[3] );
522*cdf0e10cSrcweir                         *pOut++ = rendering::ARGBColor(
523*cdf0e10cSrcweir                             vcl::unotools::toDoubleColor(nAlpha),
524*cdf0e10cSrcweir                             vcl::unotools::toDoubleColor(nAlpha*pIn[0]),
525*cdf0e10cSrcweir                             vcl::unotools::toDoubleColor(nAlpha*pIn[1]),
526*cdf0e10cSrcweir                             vcl::unotools::toDoubleColor(nAlpha*pIn[2]));
527*cdf0e10cSrcweir                         pIn += 4;
528*cdf0e10cSrcweir                     }
529*cdf0e10cSrcweir                     return aRes;
530*cdf0e10cSrcweir                 }
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir                 virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromRGB( const uno::Sequence< rendering::RGBColor >& rgbColor ) throw (lang::IllegalArgumentException, uno::RuntimeException)
533*cdf0e10cSrcweir                 {
534*cdf0e10cSrcweir                     const rendering::RGBColor* pIn( rgbColor.getConstArray() );
535*cdf0e10cSrcweir                     const sal_Size             nLen( rgbColor.getLength() );
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir                     uno::Sequence< sal_Int8 > aRes(nLen*4);
538*cdf0e10cSrcweir                     sal_Int8* pColors=aRes.getArray();
539*cdf0e10cSrcweir                     for( sal_Size i=0; i<nLen; ++i )
540*cdf0e10cSrcweir                     {
541*cdf0e10cSrcweir                         *pColors++ = vcl::unotools::toByteColor(pIn->Red);
542*cdf0e10cSrcweir                         *pColors++ = vcl::unotools::toByteColor(pIn->Green);
543*cdf0e10cSrcweir                         *pColors++ = vcl::unotools::toByteColor(pIn->Blue);
544*cdf0e10cSrcweir                         *pColors++ = 0;
545*cdf0e10cSrcweir                         ++pIn;
546*cdf0e10cSrcweir                     }
547*cdf0e10cSrcweir                     return aRes;
548*cdf0e10cSrcweir                 }
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir                 virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromARGB( const uno::Sequence< rendering::ARGBColor >& rgbColor ) throw (lang::IllegalArgumentException, uno::RuntimeException)
551*cdf0e10cSrcweir                 {
552*cdf0e10cSrcweir                     const rendering::ARGBColor* pIn( rgbColor.getConstArray() );
553*cdf0e10cSrcweir                     const sal_Size              nLen( rgbColor.getLength() );
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir                     uno::Sequence< sal_Int8 > aRes(nLen*4);
556*cdf0e10cSrcweir                     sal_Int8* pColors=aRes.getArray();
557*cdf0e10cSrcweir                     for( sal_Size i=0; i<nLen; ++i )
558*cdf0e10cSrcweir                     {
559*cdf0e10cSrcweir                         *pColors++ = vcl::unotools::toByteColor(pIn->Red);
560*cdf0e10cSrcweir                         *pColors++ = vcl::unotools::toByteColor(pIn->Green);
561*cdf0e10cSrcweir                         *pColors++ = vcl::unotools::toByteColor(pIn->Blue);
562*cdf0e10cSrcweir                         *pColors++ = 255-vcl::unotools::toByteColor(pIn->Alpha);
563*cdf0e10cSrcweir                         ++pIn;
564*cdf0e10cSrcweir                     }
565*cdf0e10cSrcweir                     return aRes;
566*cdf0e10cSrcweir                 }
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir                 virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromPARGB( const uno::Sequence< rendering::ARGBColor >& rgbColor ) throw (lang::IllegalArgumentException, uno::RuntimeException)
569*cdf0e10cSrcweir                 {
570*cdf0e10cSrcweir                     const rendering::ARGBColor* pIn( rgbColor.getConstArray() );
571*cdf0e10cSrcweir                     const sal_Size              nLen( rgbColor.getLength() );
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir                     uno::Sequence< sal_Int8 > aRes(nLen*4);
574*cdf0e10cSrcweir                     sal_Int8* pColors=aRes.getArray();
575*cdf0e10cSrcweir                     for( sal_Size i=0; i<nLen; ++i )
576*cdf0e10cSrcweir                     {
577*cdf0e10cSrcweir                         *pColors++ = vcl::unotools::toByteColor(pIn->Red/pIn->Alpha);
578*cdf0e10cSrcweir                         *pColors++ = vcl::unotools::toByteColor(pIn->Green/pIn->Alpha);
579*cdf0e10cSrcweir                         *pColors++ = vcl::unotools::toByteColor(pIn->Blue/pIn->Alpha);
580*cdf0e10cSrcweir                         *pColors++ = 255-vcl::unotools::toByteColor(pIn->Alpha);
581*cdf0e10cSrcweir                         ++pIn;
582*cdf0e10cSrcweir                     }
583*cdf0e10cSrcweir                     return aRes;
584*cdf0e10cSrcweir                 }
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir             public:
587*cdf0e10cSrcweir                 StandardColorSpace() :
588*cdf0e10cSrcweir                     maComponentTags(4),
589*cdf0e10cSrcweir                     maBitCounts(4)
590*cdf0e10cSrcweir                 {
591*cdf0e10cSrcweir                     sal_Int8*  pTags = maComponentTags.getArray();
592*cdf0e10cSrcweir                     sal_Int32* pBitCounts = maBitCounts.getArray();
593*cdf0e10cSrcweir                     pTags[0] = rendering::ColorComponentTag::RGB_RED;
594*cdf0e10cSrcweir                     pTags[1] = rendering::ColorComponentTag::RGB_GREEN;
595*cdf0e10cSrcweir                     pTags[2] = rendering::ColorComponentTag::RGB_BLUE;
596*cdf0e10cSrcweir                     pTags[3] = rendering::ColorComponentTag::ALPHA;
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir                     pBitCounts[0] =
599*cdf0e10cSrcweir                     pBitCounts[1] =
600*cdf0e10cSrcweir                     pBitCounts[2] =
601*cdf0e10cSrcweir                     pBitCounts[3] = 8;
602*cdf0e10cSrcweir                 }
603*cdf0e10cSrcweir             };
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir             struct StandardColorSpaceHolder : public rtl::StaticWithInit<uno::Reference<rendering::XIntegerBitmapColorSpace>,
606*cdf0e10cSrcweir                                                                          StandardColorSpaceHolder>
607*cdf0e10cSrcweir             {
608*cdf0e10cSrcweir                 uno::Reference<rendering::XIntegerBitmapColorSpace> operator()()
609*cdf0e10cSrcweir                 {
610*cdf0e10cSrcweir                     return new StandardColorSpace();
611*cdf0e10cSrcweir                 }
612*cdf0e10cSrcweir             };
613*cdf0e10cSrcweir         }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir         uno::Reference<rendering::XIntegerBitmapColorSpace> getStdColorSpace()
616*cdf0e10cSrcweir         {
617*cdf0e10cSrcweir             return StandardColorSpaceHolder::get();
618*cdf0e10cSrcweir         }
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir         rendering::IntegerBitmapLayout getStdMemoryLayout( const geometry::IntegerSize2D& rBmpSize )
621*cdf0e10cSrcweir         {
622*cdf0e10cSrcweir             rendering::IntegerBitmapLayout aLayout;
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir             aLayout.ScanLines = rBmpSize.Height;
625*cdf0e10cSrcweir             aLayout.ScanLineBytes = rBmpSize.Width*4;
626*cdf0e10cSrcweir             aLayout.ScanLineStride = aLayout.ScanLineBytes;
627*cdf0e10cSrcweir             aLayout.PlaneStride = 0;
628*cdf0e10cSrcweir             aLayout.ColorSpace = getStdColorSpace();
629*cdf0e10cSrcweir             aLayout.Palette.clear();
630*cdf0e10cSrcweir             aLayout.IsMsbFirst = sal_False;
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir             return aLayout;
633*cdf0e10cSrcweir         }
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir         ::Color stdIntSequenceToColor( const uno::Sequence<sal_Int8>& rColor )
636*cdf0e10cSrcweir         {
637*cdf0e10cSrcweir #ifdef OSL_BIGENDIAN
638*cdf0e10cSrcweir             const sal_Int8* pCols( rColor.getConstArray() );
639*cdf0e10cSrcweir             return ::Color( pCols[3], pCols[0], pCols[1], pCols[2] );
640*cdf0e10cSrcweir #else
641*cdf0e10cSrcweir             return ::Color( *reinterpret_cast< const ::ColorData* >(rColor.getConstArray()) );
642*cdf0e10cSrcweir #endif
643*cdf0e10cSrcweir         }
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir         uno::Sequence<sal_Int8> colorToStdIntSequence( const ::Color& rColor )
646*cdf0e10cSrcweir         {
647*cdf0e10cSrcweir             uno::Sequence<sal_Int8> aRet(4);
648*cdf0e10cSrcweir             sal_Int8* pCols( aRet.getArray() );
649*cdf0e10cSrcweir #ifdef OSL_BIGENDIAN
650*cdf0e10cSrcweir             pCols[0] = rColor.GetRed();
651*cdf0e10cSrcweir             pCols[1] = rColor.GetGreen();
652*cdf0e10cSrcweir             pCols[2] = rColor.GetBlue();
653*cdf0e10cSrcweir             pCols[3] = 255-rColor.GetTransparency();
654*cdf0e10cSrcweir #else
655*cdf0e10cSrcweir             *reinterpret_cast<sal_Int32*>(pCols) = rColor.GetColor();
656*cdf0e10cSrcweir #endif
657*cdf0e10cSrcweir             return aRet;
658*cdf0e10cSrcweir         }
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir         // Create a corrected view transformation out of the give one,
661*cdf0e10cSrcweir         // which ensures that the rectangle given by (0,0) and
662*cdf0e10cSrcweir         // rSpriteSize is mapped with its left,top corner to (0,0)
663*cdf0e10cSrcweir         // again. This is required to properly render sprite
664*cdf0e10cSrcweir         // animations to buffer bitmaps.
665*cdf0e10cSrcweir         ::basegfx::B2DHomMatrix& calcRectToOriginTransform( ::basegfx::B2DHomMatrix&			o_transform,
666*cdf0e10cSrcweir                                                             const ::basegfx::B2DRange&			i_srcRect,
667*cdf0e10cSrcweir                                                             const ::basegfx::B2DHomMatrix&		i_transformation )
668*cdf0e10cSrcweir         {
669*cdf0e10cSrcweir             if( i_srcRect.isEmpty() )
670*cdf0e10cSrcweir                 return o_transform=i_transformation;
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir             // transform by given transformation
673*cdf0e10cSrcweir             ::basegfx::B2DRectangle aTransformedRect;
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir             calcTransformedRectBounds( aTransformedRect,
676*cdf0e10cSrcweir                                        i_srcRect,
677*cdf0e10cSrcweir                                        i_transformation );
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir             // now move resulting left,top point of bounds to (0,0)
680*cdf0e10cSrcweir             const basegfx::B2DHomMatrix aCorrectedTransform(basegfx::tools::createTranslateB2DHomMatrix(
681*cdf0e10cSrcweir                 -aTransformedRect.getMinX(), -aTransformedRect.getMinY()));
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir             // prepend to original transformation
684*cdf0e10cSrcweir             o_transform = aCorrectedTransform * i_transformation;
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir             return o_transform;
687*cdf0e10cSrcweir         }
688*cdf0e10cSrcweir 
689*cdf0e10cSrcweir         ::basegfx::B2DRange& calcTransformedRectBounds( ::basegfx::B2DRange&			outRect,
690*cdf0e10cSrcweir                                                         const ::basegfx::B2DRange&		inRect,
691*cdf0e10cSrcweir                                                         const ::basegfx::B2DHomMatrix& 	transformation )
692*cdf0e10cSrcweir         {
693*cdf0e10cSrcweir             outRect.reset();
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir             if( inRect.isEmpty() )
696*cdf0e10cSrcweir                 return outRect;
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir             // transform all four extremal points of the rectangle,
699*cdf0e10cSrcweir             // take bounding rect of those.
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir             // transform left-top point
702*cdf0e10cSrcweir             outRect.expand( transformation * inRect.getMinimum() );
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir             // transform bottom-right point
705*cdf0e10cSrcweir             outRect.expand( transformation * inRect.getMaximum() );
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir             ::basegfx::B2DPoint aPoint;
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir             // transform top-right point
710*cdf0e10cSrcweir             aPoint.setX( inRect.getMaxX() );
711*cdf0e10cSrcweir             aPoint.setY( inRect.getMinY() );
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir             aPoint *= transformation;
714*cdf0e10cSrcweir             outRect.expand( aPoint );
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir             // transform bottom-left point
717*cdf0e10cSrcweir             aPoint.setX( inRect.getMinX() );
718*cdf0e10cSrcweir             aPoint.setY( inRect.getMaxY() );
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir             aPoint *= transformation;
721*cdf0e10cSrcweir             outRect.expand( aPoint );
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir             // over and out.
724*cdf0e10cSrcweir             return outRect;
725*cdf0e10cSrcweir         }
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir         ::basegfx::B2DHomMatrix& calcRectToRectTransform( ::basegfx::B2DHomMatrix&			o_transform,
728*cdf0e10cSrcweir                                                           const ::basegfx::B2DRange&		destRect,
729*cdf0e10cSrcweir                                                           const ::basegfx::B2DRange&		srcRect,
730*cdf0e10cSrcweir                                                           const ::basegfx::B2DHomMatrix&	transformation )
731*cdf0e10cSrcweir         {
732*cdf0e10cSrcweir             if( srcRect.isEmpty() ||
733*cdf0e10cSrcweir                 destRect.isEmpty() )
734*cdf0e10cSrcweir             {
735*cdf0e10cSrcweir                 return o_transform=transformation;
736*cdf0e10cSrcweir             }
737*cdf0e10cSrcweir 
738*cdf0e10cSrcweir             // transform inputRect by transformation
739*cdf0e10cSrcweir             ::basegfx::B2DRectangle aTransformedRect;
740*cdf0e10cSrcweir             calcTransformedRectBounds( aTransformedRect,
741*cdf0e10cSrcweir                                        srcRect,
742*cdf0e10cSrcweir                                        transformation );
743*cdf0e10cSrcweir 
744*cdf0e10cSrcweir             // now move resulting left,top point of bounds to (0,0)
745*cdf0e10cSrcweir             basegfx::B2DHomMatrix aCorrectedTransform(basegfx::tools::createTranslateB2DHomMatrix(
746*cdf0e10cSrcweir                 -aTransformedRect.getMinX(), -aTransformedRect.getMinY()));
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir             // scale to match outRect
749*cdf0e10cSrcweir             const double xDenom( aTransformedRect.getWidth() );
750*cdf0e10cSrcweir             const double yDenom( aTransformedRect.getHeight() );
751*cdf0e10cSrcweir             if( xDenom != 0.0 && yDenom != 0.0 )
752*cdf0e10cSrcweir                 aCorrectedTransform.scale( destRect.getWidth() / xDenom,
753*cdf0e10cSrcweir                                            destRect.getHeight() / yDenom );
754*cdf0e10cSrcweir             // TODO(E2): error handling
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir             // translate to final position
757*cdf0e10cSrcweir             aCorrectedTransform.translate( destRect.getMinX(),
758*cdf0e10cSrcweir                                            destRect.getMinY() );
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir             ::basegfx::B2DHomMatrix transform( transformation );
761*cdf0e10cSrcweir             o_transform = aCorrectedTransform * transform;
762*cdf0e10cSrcweir 
763*cdf0e10cSrcweir             return o_transform;
764*cdf0e10cSrcweir         }
765*cdf0e10cSrcweir 
766*cdf0e10cSrcweir 		bool isInside( const ::basegfx::B2DRange& 		rContainedRect,
767*cdf0e10cSrcweir                        const ::basegfx::B2DRange& 		rTransformRect,
768*cdf0e10cSrcweir                        const ::basegfx::B2DHomMatrix&	rTransformation )
769*cdf0e10cSrcweir         {
770*cdf0e10cSrcweir             if( rContainedRect.isEmpty() || rTransformRect.isEmpty() )
771*cdf0e10cSrcweir                 return false;
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir             ::basegfx::B2DPolygon aPoly(
774*cdf0e10cSrcweir                 ::basegfx::tools::createPolygonFromRect( rTransformRect ) );
775*cdf0e10cSrcweir             aPoly.transform( rTransformation );
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir             return ::basegfx::tools::isInside( aPoly,
778*cdf0e10cSrcweir                                                ::basegfx::tools::createPolygonFromRect(
779*cdf0e10cSrcweir                                                    rContainedRect ),
780*cdf0e10cSrcweir                                                true );
781*cdf0e10cSrcweir         }
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir         namespace
784*cdf0e10cSrcweir         {
785*cdf0e10cSrcweir             bool clipAreaImpl( ::basegfx::B2IRange*       o_pDestArea,
786*cdf0e10cSrcweir                                ::basegfx::B2IRange&       io_rSourceArea,
787*cdf0e10cSrcweir                                ::basegfx::B2IPoint&       io_rDestPoint,
788*cdf0e10cSrcweir                                const ::basegfx::B2IRange& rSourceBounds,
789*cdf0e10cSrcweir                                const ::basegfx::B2IRange& rDestBounds )
790*cdf0e10cSrcweir             {
791*cdf0e10cSrcweir                 const ::basegfx::B2IPoint aSourceTopLeft(
792*cdf0e10cSrcweir                     io_rSourceArea.getMinimum() );
793*cdf0e10cSrcweir 
794*cdf0e10cSrcweir                 ::basegfx::B2IRange aLocalSourceArea( io_rSourceArea );
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir                 // clip source area (which must be inside rSourceBounds)
797*cdf0e10cSrcweir                 aLocalSourceArea.intersect( rSourceBounds );
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir                 if( aLocalSourceArea.isEmpty() )
800*cdf0e10cSrcweir                     return false;
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir                 // calc relative new source area points (relative to orig
803*cdf0e10cSrcweir                 // source area)
804*cdf0e10cSrcweir                 const ::basegfx::B2IVector aUpperLeftOffset(
805*cdf0e10cSrcweir                     aLocalSourceArea.getMinimum()-aSourceTopLeft );
806*cdf0e10cSrcweir                 const ::basegfx::B2IVector aLowerRightOffset(
807*cdf0e10cSrcweir                     aLocalSourceArea.getMaximum()-aSourceTopLeft );
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir                 ::basegfx::B2IRange aLocalDestArea( io_rDestPoint + aUpperLeftOffset,
810*cdf0e10cSrcweir                                                     io_rDestPoint + aLowerRightOffset );
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir                 // clip dest area (which must be inside rDestBounds)
813*cdf0e10cSrcweir                 aLocalDestArea.intersect( rDestBounds );
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir                 if( aLocalDestArea.isEmpty() )
816*cdf0e10cSrcweir                     return false;
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir                 // calc relative new dest area points (relative to orig
819*cdf0e10cSrcweir                 // source area)
820*cdf0e10cSrcweir                 const ::basegfx::B2IVector aDestUpperLeftOffset(
821*cdf0e10cSrcweir                     aLocalDestArea.getMinimum()-io_rDestPoint );
822*cdf0e10cSrcweir                 const ::basegfx::B2IVector aDestLowerRightOffset(
823*cdf0e10cSrcweir                     aLocalDestArea.getMaximum()-io_rDestPoint );
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir                 io_rSourceArea = ::basegfx::B2IRange( aSourceTopLeft + aDestUpperLeftOffset,
826*cdf0e10cSrcweir                                                       aSourceTopLeft + aDestLowerRightOffset );
827*cdf0e10cSrcweir                 io_rDestPoint  = aLocalDestArea.getMinimum();
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir                 if( o_pDestArea )
830*cdf0e10cSrcweir                     *o_pDestArea = aLocalDestArea;
831*cdf0e10cSrcweir 
832*cdf0e10cSrcweir                 return true;
833*cdf0e10cSrcweir             }
834*cdf0e10cSrcweir         }
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir         bool clipScrollArea( ::basegfx::B2IRange&                  io_rSourceArea,
837*cdf0e10cSrcweir                              ::basegfx::B2IPoint&                  io_rDestPoint,
838*cdf0e10cSrcweir                              ::std::vector< ::basegfx::B2IRange >& o_ClippedAreas,
839*cdf0e10cSrcweir                              const ::basegfx::B2IRange&            rBounds )
840*cdf0e10cSrcweir         {
841*cdf0e10cSrcweir             ::basegfx::B2IRange aResultingDestArea;
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir             // compute full destination area (to determine uninitialized
844*cdf0e10cSrcweir             // areas below)
845*cdf0e10cSrcweir             const ::basegfx::B2I64Tuple& rRange( io_rSourceArea.getRange() );
846*cdf0e10cSrcweir             ::basegfx::B2IRange aInputDestArea( io_rDestPoint.getX(),
847*cdf0e10cSrcweir                                                 io_rDestPoint.getY(),
848*cdf0e10cSrcweir                                                 (io_rDestPoint.getX()
849*cdf0e10cSrcweir                                                  + static_cast<sal_Int32>(rRange.getX())),
850*cdf0e10cSrcweir                                                 (io_rDestPoint.getY()
851*cdf0e10cSrcweir                                                  + static_cast<sal_Int32>(rRange.getY())) );
852*cdf0e10cSrcweir             // limit to output area (no point updating outside of it)
853*cdf0e10cSrcweir             aInputDestArea.intersect( rBounds );
854*cdf0e10cSrcweir 
855*cdf0e10cSrcweir             // clip to rBounds
856*cdf0e10cSrcweir             if( !clipAreaImpl( &aResultingDestArea,
857*cdf0e10cSrcweir                                io_rSourceArea,
858*cdf0e10cSrcweir                                io_rDestPoint,
859*cdf0e10cSrcweir                                rBounds,
860*cdf0e10cSrcweir                                rBounds ) )
861*cdf0e10cSrcweir                 return false;
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir             // finally, compute all areas clipped off the total
864*cdf0e10cSrcweir             // destination area.
865*cdf0e10cSrcweir             ::basegfx::computeSetDifference( o_ClippedAreas,
866*cdf0e10cSrcweir                                              aInputDestArea,
867*cdf0e10cSrcweir                                              aResultingDestArea );
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir             return true;
870*cdf0e10cSrcweir         }
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir         bool clipBlit( ::basegfx::B2IRange&       io_rSourceArea,
873*cdf0e10cSrcweir                        ::basegfx::B2IPoint&       io_rDestPoint,
874*cdf0e10cSrcweir                        const ::basegfx::B2IRange& rSourceBounds,
875*cdf0e10cSrcweir                        const ::basegfx::B2IRange& rDestBounds )
876*cdf0e10cSrcweir         {
877*cdf0e10cSrcweir             return clipAreaImpl( NULL,
878*cdf0e10cSrcweir                                  io_rSourceArea,
879*cdf0e10cSrcweir                                  io_rDestPoint,
880*cdf0e10cSrcweir                                  rSourceBounds,
881*cdf0e10cSrcweir                                  rDestBounds );
882*cdf0e10cSrcweir         }
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir         ::basegfx::B2IRange spritePixelAreaFromB2DRange( const ::basegfx::B2DRange& rRange )
885*cdf0e10cSrcweir         {
886*cdf0e10cSrcweir             if( rRange.isEmpty() )
887*cdf0e10cSrcweir                 return ::basegfx::B2IRange();
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir             const ::basegfx::B2IPoint aTopLeft( ::basegfx::fround( rRange.getMinX() ),
890*cdf0e10cSrcweir                                                 ::basegfx::fround( rRange.getMinY() ) );
891*cdf0e10cSrcweir             return ::basegfx::B2IRange( aTopLeft,
892*cdf0e10cSrcweir                                         aTopLeft + ::basegfx::B2IPoint(
893*cdf0e10cSrcweir                                             ::basegfx::fround( rRange.getWidth() ),
894*cdf0e10cSrcweir                                             ::basegfx::fround( rRange.getHeight() ) ) );
895*cdf0e10cSrcweir         }
896*cdf0e10cSrcweir 
897*cdf0e10cSrcweir 		uno::Sequence< uno::Any >& getDeviceInfo( const uno::Reference< rendering::XCanvas >& i_rxCanvas,
898*cdf0e10cSrcweir 												  uno::Sequence< uno::Any >& 				  o_rxParams )
899*cdf0e10cSrcweir 		{
900*cdf0e10cSrcweir 			o_rxParams.realloc( 0 );
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir 			if( i_rxCanvas.is() )
903*cdf0e10cSrcweir 			{
904*cdf0e10cSrcweir                 try
905*cdf0e10cSrcweir                 {
906*cdf0e10cSrcweir                     uno::Reference< rendering::XGraphicDevice > xDevice( i_rxCanvas->getDevice(),
907*cdf0e10cSrcweir                                                                          uno::UNO_QUERY_THROW );
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir                     uno::Reference< lang::XServiceInfo >  xServiceInfo( xDevice,
910*cdf0e10cSrcweir                                                                         uno::UNO_QUERY_THROW );
911*cdf0e10cSrcweir                     uno::Reference< beans::XPropertySet > xPropSet( xDevice,
912*cdf0e10cSrcweir                                                                     uno::UNO_QUERY_THROW );
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir                     o_rxParams.realloc( 2 );
915*cdf0e10cSrcweir 
916*cdf0e10cSrcweir                     o_rxParams[ 0 ] = uno::makeAny( xServiceInfo->getImplementationName() );
917*cdf0e10cSrcweir                     o_rxParams[ 1 ] = uno::makeAny( xPropSet->getPropertyValue(
918*cdf0e10cSrcweir                                                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DeviceHandle") ) ) );
919*cdf0e10cSrcweir                 }
920*cdf0e10cSrcweir                 catch( uno::Exception& )
921*cdf0e10cSrcweir                 {
922*cdf0e10cSrcweir                     // ignore, but return empty sequence
923*cdf0e10cSrcweir                 }
924*cdf0e10cSrcweir 			}
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir 			return o_rxParams;
927*cdf0e10cSrcweir 		}
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir         awt::Rectangle getAbsoluteWindowRect( const awt::Rectangle&                  rRect,
930*cdf0e10cSrcweir                                               const uno::Reference< awt::XWindow2 >& xWin  )
931*cdf0e10cSrcweir         {
932*cdf0e10cSrcweir             awt::Rectangle aRetVal( rRect );
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir             ::Window* pWindow = VCLUnoHelper::GetWindow(xWin);
935*cdf0e10cSrcweir             if( pWindow )
936*cdf0e10cSrcweir             {
937*cdf0e10cSrcweir                 ::Point aPoint( aRetVal.X,
938*cdf0e10cSrcweir                                 aRetVal.Y );
939*cdf0e10cSrcweir 
940*cdf0e10cSrcweir                 aPoint = pWindow->OutputToScreenPixel( aPoint );
941*cdf0e10cSrcweir 
942*cdf0e10cSrcweir                 aRetVal.X = aPoint.X();
943*cdf0e10cSrcweir                 aRetVal.Y = aPoint.Y();
944*cdf0e10cSrcweir             }
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir             return aRetVal;
947*cdf0e10cSrcweir         }
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir         ::basegfx::B2DPolyPolygon getBoundMarksPolyPolygon( const ::basegfx::B2DRange& rRange )
950*cdf0e10cSrcweir         {
951*cdf0e10cSrcweir             ::basegfx::B2DPolyPolygon aPolyPoly;
952*cdf0e10cSrcweir             ::basegfx::B2DPolygon     aPoly;
953*cdf0e10cSrcweir 
954*cdf0e10cSrcweir             const double nX0( rRange.getMinX() );
955*cdf0e10cSrcweir             const double nY0( rRange.getMinY() );
956*cdf0e10cSrcweir             const double nX1( rRange.getMaxX() );
957*cdf0e10cSrcweir             const double nY1( rRange.getMaxY() );
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir             aPoly.append( ::basegfx::B2DPoint( nX0+4,
960*cdf0e10cSrcweir                                                nY0 ) );
961*cdf0e10cSrcweir             aPoly.append( ::basegfx::B2DPoint( nX0,
962*cdf0e10cSrcweir                                                nY0 ) );
963*cdf0e10cSrcweir             aPoly.append( ::basegfx::B2DPoint( nX0,
964*cdf0e10cSrcweir                                                nY0+4 ) );
965*cdf0e10cSrcweir             aPolyPoly.append( aPoly ); aPoly.clear();
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir             aPoly.append( ::basegfx::B2DPoint( nX1-4,
968*cdf0e10cSrcweir                                                nY0 ) );
969*cdf0e10cSrcweir             aPoly.append( ::basegfx::B2DPoint( nX1,
970*cdf0e10cSrcweir                                                nY0 ) );
971*cdf0e10cSrcweir             aPoly.append( ::basegfx::B2DPoint( nX1,
972*cdf0e10cSrcweir                                                nY0+4 ) );
973*cdf0e10cSrcweir             aPolyPoly.append( aPoly ); aPoly.clear();
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir             aPoly.append( ::basegfx::B2DPoint( nX0+4,
976*cdf0e10cSrcweir                                                nY1 ) );
977*cdf0e10cSrcweir             aPoly.append( ::basegfx::B2DPoint( nX0,
978*cdf0e10cSrcweir                                                nY1 ) );
979*cdf0e10cSrcweir             aPoly.append( ::basegfx::B2DPoint( nX0,
980*cdf0e10cSrcweir                                                nY1-4 ) );
981*cdf0e10cSrcweir             aPolyPoly.append( aPoly ); aPoly.clear();
982*cdf0e10cSrcweir 
983*cdf0e10cSrcweir             aPoly.append( ::basegfx::B2DPoint( nX1-4,
984*cdf0e10cSrcweir                                                nY1 ) );
985*cdf0e10cSrcweir             aPoly.append( ::basegfx::B2DPoint( nX1,
986*cdf0e10cSrcweir                                                nY1 ) );
987*cdf0e10cSrcweir             aPoly.append( ::basegfx::B2DPoint( nX1,
988*cdf0e10cSrcweir                                                nY1-4 ) );
989*cdf0e10cSrcweir             aPolyPoly.append( aPoly );
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir             return aPolyPoly;
992*cdf0e10cSrcweir         }
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir         int calcGradientStepCount( ::basegfx::B2DHomMatrix&      rTotalTransform,
995*cdf0e10cSrcweir                                    const rendering::ViewState&   viewState,
996*cdf0e10cSrcweir                                    const rendering::RenderState& renderState,
997*cdf0e10cSrcweir                                    const rendering::Texture&     texture,
998*cdf0e10cSrcweir                                    int                           nColorSteps )
999*cdf0e10cSrcweir         {
1000*cdf0e10cSrcweir             // calculate overall texture transformation (directly from
1001*cdf0e10cSrcweir             // texture to device space).
1002*cdf0e10cSrcweir             ::basegfx::B2DHomMatrix aMatrix;
1003*cdf0e10cSrcweir 
1004*cdf0e10cSrcweir             rTotalTransform.identity();
1005*cdf0e10cSrcweir             ::basegfx::unotools::homMatrixFromAffineMatrix( rTotalTransform,
1006*cdf0e10cSrcweir                                                             texture.AffineTransform );
1007*cdf0e10cSrcweir             ::canvas::tools::mergeViewAndRenderTransform(aMatrix,
1008*cdf0e10cSrcweir                                                          viewState,
1009*cdf0e10cSrcweir                                                          renderState);
1010*cdf0e10cSrcweir             rTotalTransform *= aMatrix; // prepend total view/render transformation
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir             // determine size of gradient in device coordinate system
1013*cdf0e10cSrcweir             // (to e.g. determine sensible number of gradient steps)
1014*cdf0e10cSrcweir             ::basegfx::B2DPoint aLeftTop( 0.0, 0.0 );
1015*cdf0e10cSrcweir             ::basegfx::B2DPoint aLeftBottom( 0.0, 1.0 );
1016*cdf0e10cSrcweir             ::basegfx::B2DPoint aRightTop( 1.0, 0.0 );
1017*cdf0e10cSrcweir             ::basegfx::B2DPoint aRightBottom( 1.0, 1.0 );
1018*cdf0e10cSrcweir 
1019*cdf0e10cSrcweir             aLeftTop	*= rTotalTransform;
1020*cdf0e10cSrcweir             aLeftBottom *= rTotalTransform;
1021*cdf0e10cSrcweir             aRightTop 	*= rTotalTransform;
1022*cdf0e10cSrcweir             aRightBottom*= rTotalTransform;
1023*cdf0e10cSrcweir 
1024*cdf0e10cSrcweir             // longest line in gradient bound rect
1025*cdf0e10cSrcweir             const int nGradientSize(
1026*cdf0e10cSrcweir                 static_cast<int>(
1027*cdf0e10cSrcweir                     ::std::max(
1028*cdf0e10cSrcweir                         ::basegfx::B2DVector(aRightBottom-aLeftTop).getLength(),
1029*cdf0e10cSrcweir                         ::basegfx::B2DVector(aRightTop-aLeftBottom).getLength() ) + 1.0 ) );
1030*cdf0e10cSrcweir 
1031*cdf0e10cSrcweir             // typical number for pixel of the same color (strip size)
1032*cdf0e10cSrcweir             const int nStripSize( nGradientSize < 50 ? 2 : 4 );
1033*cdf0e10cSrcweir 
1034*cdf0e10cSrcweir             // use at least three steps, and at utmost the number of color
1035*cdf0e10cSrcweir             // steps
1036*cdf0e10cSrcweir             return ::std::max( 3,
1037*cdf0e10cSrcweir                                ::std::min(
1038*cdf0e10cSrcweir                                    nGradientSize / nStripSize,
1039*cdf0e10cSrcweir                                    nColorSteps ) );
1040*cdf0e10cSrcweir         }
1041*cdf0e10cSrcweir 
1042*cdf0e10cSrcweir 	} // namespace tools
1043*cdf0e10cSrcweir 
1044*cdf0e10cSrcweir } // namespace canvas
1045