xref: /AOO41X/main/canvas/source/cairo/cairo_canvashelper_texturefill.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 
33*cdf0e10cSrcweir #include <rtl/math.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <com/sun/star/rendering/TextDirection.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/rendering/TexturingMode.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/rendering/PathCapType.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/rendering/PathJoinType.hpp>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <tools/poly.hxx>
41*cdf0e10cSrcweir #include <vcl/window.hxx>
42*cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
43*cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
44*cdf0e10cSrcweir #include <vcl/canvastools.hxx>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
47*cdf0e10cSrcweir #include <basegfx/range/b2drectangle.hxx>
48*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
49*cdf0e10cSrcweir #include <basegfx/vector/b2dsize.hxx>
50*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
51*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
52*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
53*cdf0e10cSrcweir #include <basegfx/polygon/b2dlinegeometry.hxx>
54*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
55*cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #include <utility>
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
60*cdf0e10cSrcweir #include <canvas/canvastools.hxx>
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir #include "cairo_textlayout.hxx"
63*cdf0e10cSrcweir #include "cairo_parametricpolypolygon.hxx"
64*cdf0e10cSrcweir #include "cairo_canvashelper.hxx"
65*cdf0e10cSrcweir #include "cairo_canvasbitmap.hxx"
66*cdf0e10cSrcweir #include "cairo_impltools.hxx"
67*cdf0e10cSrcweir #include "cairo_canvasfont.hxx"
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir using namespace ::com::sun::star;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir namespace cairocanvas
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir     namespace
74*cdf0e10cSrcweir     {
75*cdf0e10cSrcweir         bool textureFill( OutputDevice&			rOutDev,
76*cdf0e10cSrcweir                           GraphicObject&		rGraphic,
77*cdf0e10cSrcweir                           const ::Point&		rPosPixel,
78*cdf0e10cSrcweir                           const ::Size&			rNextTileX,
79*cdf0e10cSrcweir                           const ::Size&			rNextTileY,
80*cdf0e10cSrcweir                           sal_Int32				nTilesX,
81*cdf0e10cSrcweir                           sal_Int32				nTilesY,
82*cdf0e10cSrcweir                           const ::Size&			rTileSize,
83*cdf0e10cSrcweir                           const GraphicAttr&	rAttr)
84*cdf0e10cSrcweir         {
85*cdf0e10cSrcweir             bool bRet( false );
86*cdf0e10cSrcweir             Point 	aCurrPos;
87*cdf0e10cSrcweir             int 	nX, nY;
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir             for( nY=0; nY < nTilesY; ++nY )
90*cdf0e10cSrcweir             {
91*cdf0e10cSrcweir                 aCurrPos.X() = rPosPixel.X() + nY*rNextTileY.Width();
92*cdf0e10cSrcweir                 aCurrPos.Y() = rPosPixel.Y() + nY*rNextTileY.Height();
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir                 for( nX=0; nX < nTilesX; ++nX )
95*cdf0e10cSrcweir                 {
96*cdf0e10cSrcweir                     // update return value. This method should return true, if
97*cdf0e10cSrcweir                     // at least one of the looped Draws succeeded.
98*cdf0e10cSrcweir                     bRet |= rGraphic.Draw( &rOutDev,
99*cdf0e10cSrcweir                                            aCurrPos,
100*cdf0e10cSrcweir                                            rTileSize,
101*cdf0e10cSrcweir                                            &rAttr );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir                     aCurrPos.X() += rNextTileX.Width();
104*cdf0e10cSrcweir                     aCurrPos.Y() += rNextTileX.Height();
105*cdf0e10cSrcweir                 }
106*cdf0e10cSrcweir             }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir             return bRet;
109*cdf0e10cSrcweir         }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir         inline sal_Int32 roundDown( const double& rVal )
112*cdf0e10cSrcweir         {
113*cdf0e10cSrcweir             return static_cast< sal_Int32 >( floor( rVal ) );
114*cdf0e10cSrcweir         }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir         inline sal_Int32 roundUp( const double& rVal )
117*cdf0e10cSrcweir         {
118*cdf0e10cSrcweir             return static_cast< sal_Int32 >( ceil( rVal ) );
119*cdf0e10cSrcweir         }
120*cdf0e10cSrcweir     }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::fillTexturedPolyPolygon( const rendering::XCanvas& 							rCanvas,
123*cdf0e10cSrcweir                                                                                          const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon,
124*cdf0e10cSrcweir                                                                                          const rendering::ViewState& 						viewState,
125*cdf0e10cSrcweir                                                                                          const rendering::RenderState& 						renderState,
126*cdf0e10cSrcweir                                                                                          const uno::Sequence< rendering::Texture >& 		textures )
127*cdf0e10cSrcweir     {
128*cdf0e10cSrcweir         ENSURE_ARG_OR_THROW( xPolyPolygon.is(),
129*cdf0e10cSrcweir                          "CanvasHelper::fillPolyPolygon(): polygon is NULL");
130*cdf0e10cSrcweir         ENSURE_ARG_OR_THROW( textures.getLength(),
131*cdf0e10cSrcweir                          "CanvasHelper::fillTexturedPolyPolygon: empty texture sequence");
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	cairo_save( mpCairo );
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	useStates( viewState, renderState, true );
136*cdf0e10cSrcweir 	mpTextures = &textures;
137*cdf0e10cSrcweir 	drawPolyPolygonPath( xPolyPolygon, Fill );
138*cdf0e10cSrcweir 	mpTextures = NULL;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	cairo_restore( mpCairo );
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         return uno::Reference< rendering::XCachedPrimitive >(NULL);
143*cdf0e10cSrcweir     }
144*cdf0e10cSrcweir }
145