1*25ea7f45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*25ea7f45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*25ea7f45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*25ea7f45SAndrew Rist  * distributed with this work for additional information
6*25ea7f45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*25ea7f45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*25ea7f45SAndrew Rist  * "License"); you may not use this file except in compliance
9*25ea7f45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*25ea7f45SAndrew Rist  *
11*25ea7f45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*25ea7f45SAndrew Rist  *
13*25ea7f45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*25ea7f45SAndrew Rist  * software distributed under the License is distributed on an
15*25ea7f45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*25ea7f45SAndrew Rist  * KIND, either express or implied.  See the License for the
17*25ea7f45SAndrew Rist  * specific language governing permissions and limitations
18*25ea7f45SAndrew Rist  * under the License.
19*25ea7f45SAndrew Rist  *
20*25ea7f45SAndrew Rist  *************************************************************/
21*25ea7f45SAndrew Rist 
22*25ea7f45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_canvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <canvas/debug.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <rtl/math.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <com/sun/star/rendering/TextDirection.hpp>
32cdf0e10cSrcweir #include <com/sun/star/rendering/TexturingMode.hpp>
33cdf0e10cSrcweir #include <com/sun/star/rendering/PathCapType.hpp>
34cdf0e10cSrcweir #include <com/sun/star/rendering/PathJoinType.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <tools/poly.hxx>
37cdf0e10cSrcweir #include <vcl/window.hxx>
38cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
39cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
40cdf0e10cSrcweir #include <vcl/canvastools.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
43cdf0e10cSrcweir #include <basegfx/range/b2drectangle.hxx>
44cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
45cdf0e10cSrcweir #include <basegfx/vector/b2dsize.hxx>
46cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
47cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
48cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
49cdf0e10cSrcweir #include <basegfx/polygon/b2dlinegeometry.hxx>
50cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
51cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #include <utility>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #include <comphelper/sequence.hxx>
56cdf0e10cSrcweir #include <canvas/canvastools.hxx>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #include "cairo_textlayout.hxx"
59cdf0e10cSrcweir #include "cairo_parametricpolypolygon.hxx"
60cdf0e10cSrcweir #include "cairo_canvashelper.hxx"
61cdf0e10cSrcweir #include "cairo_canvasbitmap.hxx"
62cdf0e10cSrcweir #include "cairo_impltools.hxx"
63cdf0e10cSrcweir #include "cairo_canvasfont.hxx"
64cdf0e10cSrcweir 
65cdf0e10cSrcweir using namespace ::com::sun::star;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir namespace cairocanvas
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     namespace
70cdf0e10cSrcweir     {
textureFill(OutputDevice & rOutDev,GraphicObject & rGraphic,const::Point & rPosPixel,const::Size & rNextTileX,const::Size & rNextTileY,sal_Int32 nTilesX,sal_Int32 nTilesY,const::Size & rTileSize,const GraphicAttr & rAttr)71cdf0e10cSrcweir         bool textureFill( OutputDevice&			rOutDev,
72cdf0e10cSrcweir                           GraphicObject&		rGraphic,
73cdf0e10cSrcweir                           const ::Point&		rPosPixel,
74cdf0e10cSrcweir                           const ::Size&			rNextTileX,
75cdf0e10cSrcweir                           const ::Size&			rNextTileY,
76cdf0e10cSrcweir                           sal_Int32				nTilesX,
77cdf0e10cSrcweir                           sal_Int32				nTilesY,
78cdf0e10cSrcweir                           const ::Size&			rTileSize,
79cdf0e10cSrcweir                           const GraphicAttr&	rAttr)
80cdf0e10cSrcweir         {
81cdf0e10cSrcweir             bool bRet( false );
82cdf0e10cSrcweir             Point 	aCurrPos;
83cdf0e10cSrcweir             int 	nX, nY;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir             for( nY=0; nY < nTilesY; ++nY )
86cdf0e10cSrcweir             {
87cdf0e10cSrcweir                 aCurrPos.X() = rPosPixel.X() + nY*rNextTileY.Width();
88cdf0e10cSrcweir                 aCurrPos.Y() = rPosPixel.Y() + nY*rNextTileY.Height();
89cdf0e10cSrcweir 
90cdf0e10cSrcweir                 for( nX=0; nX < nTilesX; ++nX )
91cdf0e10cSrcweir                 {
92cdf0e10cSrcweir                     // update return value. This method should return true, if
93cdf0e10cSrcweir                     // at least one of the looped Draws succeeded.
94cdf0e10cSrcweir                     bRet |= rGraphic.Draw( &rOutDev,
95cdf0e10cSrcweir                                            aCurrPos,
96cdf0e10cSrcweir                                            rTileSize,
97cdf0e10cSrcweir                                            &rAttr );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir                     aCurrPos.X() += rNextTileX.Width();
100cdf0e10cSrcweir                     aCurrPos.Y() += rNextTileX.Height();
101cdf0e10cSrcweir                 }
102cdf0e10cSrcweir             }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir             return bRet;
105cdf0e10cSrcweir         }
106cdf0e10cSrcweir 
roundDown(const double & rVal)107cdf0e10cSrcweir         inline sal_Int32 roundDown( const double& rVal )
108cdf0e10cSrcweir         {
109cdf0e10cSrcweir             return static_cast< sal_Int32 >( floor( rVal ) );
110cdf0e10cSrcweir         }
111cdf0e10cSrcweir 
roundUp(const double & rVal)112cdf0e10cSrcweir         inline sal_Int32 roundUp( const double& rVal )
113cdf0e10cSrcweir         {
114cdf0e10cSrcweir             return static_cast< sal_Int32 >( ceil( rVal ) );
115cdf0e10cSrcweir         }
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir 
fillTexturedPolyPolygon(const rendering::XCanvas & rCanvas,const uno::Reference<rendering::XPolyPolygon2D> & xPolyPolygon,const rendering::ViewState & viewState,const rendering::RenderState & renderState,const uno::Sequence<rendering::Texture> & textures)118cdf0e10cSrcweir     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::fillTexturedPolyPolygon( const rendering::XCanvas& 							rCanvas,
119cdf0e10cSrcweir                                                                                          const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon,
120cdf0e10cSrcweir                                                                                          const rendering::ViewState& 						viewState,
121cdf0e10cSrcweir                                                                                          const rendering::RenderState& 						renderState,
122cdf0e10cSrcweir                                                                                          const uno::Sequence< rendering::Texture >& 		textures )
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir         ENSURE_ARG_OR_THROW( xPolyPolygon.is(),
125cdf0e10cSrcweir                          "CanvasHelper::fillPolyPolygon(): polygon is NULL");
126cdf0e10cSrcweir         ENSURE_ARG_OR_THROW( textures.getLength(),
127cdf0e10cSrcweir                          "CanvasHelper::fillTexturedPolyPolygon: empty texture sequence");
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	cairo_save( mpCairo );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	useStates( viewState, renderState, true );
132cdf0e10cSrcweir 	mpTextures = &textures;
133cdf0e10cSrcweir 	drawPolyPolygonPath( xPolyPolygon, Fill );
134cdf0e10cSrcweir 	mpTextures = NULL;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	cairo_restore( mpCairo );
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         return uno::Reference< rendering::XCachedPrimitive >(NULL);
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir }
141