CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / canvas / source / cairo / cairo_canvashelper_texturefill.cxx
blob43447645daf9a1fcbc65bcd65e7a957633c071ed
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
31 #include <canvas/debug.hxx>
33 #include <rtl/math.hxx>
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>
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>
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>
57 #include <utility>
59 #include <comphelper/sequence.hxx>
60 #include <canvas/canvastools.hxx>
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"
69 using namespace ::com::sun::star;
71 namespace cairocanvas
73 namespace
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)
85 bool bRet( false );
86 Point aCurrPos;
87 int nX, nY;
89 for( nY=0; nY < nTilesY; ++nY )
91 aCurrPos.X() = rPosPixel.X() + nY*rNextTileY.Width();
92 aCurrPos.Y() = rPosPixel.Y() + nY*rNextTileY.Height();
94 for( nX=0; nX < nTilesX; ++nX )
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 );
103 aCurrPos.X() += rNextTileX.Width();
104 aCurrPos.Y() += rNextTileX.Height();
108 return bRet;
111 inline sal_Int32 roundDown( const double& rVal )
113 return static_cast< sal_Int32 >( floor( rVal ) );
116 inline sal_Int32 roundUp( const double& rVal )
118 return static_cast< sal_Int32 >( ceil( rVal ) );
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 )
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");
133 cairo_save( mpCairo );
135 useStates( viewState, renderState, true );
136 mpTextures = &textures;
137 drawPolyPolygonPath( xPolyPolygon, Fill );
138 mpTextures = NULL;
140 cairo_restore( mpCairo );
142 return uno::Reference< rendering::XCachedPrimitive >(NULL);