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