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