1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
30 
31 #include <canvas/debug.hxx>
32 
33 #include <rtl/math.hxx>
34 
35 #include <com/sun/star/rendering/TextDirection.hpp>
36 #include <com/sun/star/rendering/TexturingMode.hpp>
37 #include <com/sun/star/rendering/PathCapType.hpp>
38 #include <com/sun/star/rendering/PathJoinType.hpp>
39 
40 #include <tools/poly.hxx>
41 #include <vcl/window.hxx>
42 #include <vcl/bitmapex.hxx>
43 #include <vcl/bmpacc.hxx>
44 #include <vcl/canvastools.hxx>
45 
46 #include <basegfx/matrix/b2dhommatrix.hxx>
47 #include <basegfx/range/b2drectangle.hxx>
48 #include <basegfx/point/b2dpoint.hxx>
49 #include <basegfx/vector/b2dsize.hxx>
50 #include <basegfx/polygon/b2dpolygon.hxx>
51 #include <basegfx/polygon/b2dpolygontools.hxx>
52 #include <basegfx/polygon/b2dpolypolygontools.hxx>
53 #include <basegfx/polygon/b2dlinegeometry.hxx>
54 #include <basegfx/tools/canvastools.hxx>
55 #include <basegfx/numeric/ftools.hxx>
56 
57 #include <utility>
58 
59 #include <comphelper/sequence.hxx>
60 #include <canvas/canvastools.hxx>
61 
62 #include "cairo_textlayout.hxx"
63 #include "cairo_parametricpolypolygon.hxx"
64 #include "cairo_canvashelper.hxx"
65 #include "cairo_canvasbitmap.hxx"
66 #include "cairo_impltools.hxx"
67 #include "cairo_canvasfont.hxx"
68 
69 using namespace ::com::sun::star;
70 
71 namespace cairocanvas
72 {
73     namespace
74     {
75         bool textureFill( OutputDevice&			rOutDev,
76                           GraphicObject&		rGraphic,
77                           const ::Point&		rPosPixel,
78                           const ::Size&			rNextTileX,
79                           const ::Size&			rNextTileY,
80                           sal_Int32				nTilesX,
81                           sal_Int32				nTilesY,
82                           const ::Size&			rTileSize,
83                           const GraphicAttr&	rAttr)
84         {
85             bool bRet( false );
86             Point 	aCurrPos;
87             int 	nX, nY;
88 
89             for( nY=0; nY < nTilesY; ++nY )
90             {
91                 aCurrPos.X() = rPosPixel.X() + nY*rNextTileY.Width();
92                 aCurrPos.Y() = rPosPixel.Y() + nY*rNextTileY.Height();
93 
94                 for( nX=0; nX < nTilesX; ++nX )
95                 {
96                     // update return value. This method should return true, if
97                     // at least one of the looped Draws succeeded.
98                     bRet |= rGraphic.Draw( &rOutDev,
99                                            aCurrPos,
100                                            rTileSize,
101                                            &rAttr );
102 
103                     aCurrPos.X() += rNextTileX.Width();
104                     aCurrPos.Y() += rNextTileX.Height();
105                 }
106             }
107 
108             return bRet;
109         }
110 
111         inline sal_Int32 roundDown( const double& rVal )
112         {
113             return static_cast< sal_Int32 >( floor( rVal ) );
114         }
115 
116         inline sal_Int32 roundUp( const double& rVal )
117         {
118             return static_cast< sal_Int32 >( ceil( rVal ) );
119         }
120     }
121 
122     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::fillTexturedPolyPolygon( const rendering::XCanvas& 							rCanvas,
123                                                                                          const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon,
124                                                                                          const rendering::ViewState& 						viewState,
125                                                                                          const rendering::RenderState& 						renderState,
126                                                                                          const uno::Sequence< rendering::Texture >& 		textures )
127     {
128         ENSURE_ARG_OR_THROW( xPolyPolygon.is(),
129                          "CanvasHelper::fillPolyPolygon(): polygon is NULL");
130         ENSURE_ARG_OR_THROW( textures.getLength(),
131                          "CanvasHelper::fillTexturedPolyPolygon: empty texture sequence");
132 
133 	cairo_save( mpCairo );
134 
135 	useStates( viewState, renderState, true );
136 	mpTextures = &textures;
137 	drawPolyPolygonPath( xPolyPolygon, Fill );
138 	mpTextures = NULL;
139 
140 	cairo_restore( mpCairo );
141 
142         return uno::Reference< rendering::XCachedPrimitive >(NULL);
143     }
144 }
145