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: surfaceproxy.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 <boost/bind.hpp>
35 #include <basegfx/polygon/b2dpolygoncutandtouch.hxx>
36 #include <basegfx/polygon/b2dpolygontriangulator.hxx>
37 #include <basegfx/polygon/b2dpolypolygontools.hxx>
38 #include "surfaceproxy.hxx"
42 //////////////////////////////////////////////////////////////////////////////////
43 // SurfaceProxy::SurfaceProxy
44 //////////////////////////////////////////////////////////////////////////////////
46 SurfaceProxy::SurfaceProxy( const canvas::IColorBufferSharedPtr
& pBuffer
,
47 const PageManagerSharedPtr
& pPageManager
) :
48 mpPageManager( pPageManager
),
52 const ::basegfx::B2ISize
aImageSize(mpBuffer
->getWidth(),mpBuffer
->getHeight());
53 const ::basegfx::B2ISize
aPageSize(mpPageManager
->getPageSize());
54 const sal_Int32
aPageSizeX(aPageSize
.getX());
55 const sal_Int32
aPageSizeY(aPageSize
.getY());
56 const sal_Int32
aImageSizeX(aImageSize
.getX());
57 const sal_Int32
aImageSizeY(aImageSize
.getY());
59 // see if the size of the colorbuffer is larger than the size
60 // of a single page. if this is the case we divide the
61 // colorbuffer into as many surfaces as we need to get the
62 // whole area distributed. otherwise (the colorbuffer is
63 // smaller than the size of a single page) we search for free
64 // pages or create a new one.
65 // the incoming image is too large to fit into a single
66 // page. strategy: we split the image into rectangular
67 // areas that are as large as the maximum page size
68 // dictates and follow the strategy for fitting images.
69 size_t dwNumSurfaces(0);
70 for(sal_Int32 y
=0; y
<aImageSizeY
; y
+=aPageSizeY
)
71 for(sal_Int32 x
=0; x
<aImageSizeX
; x
+=aPageSizeX
)
73 maSurfaceList
.reserve(dwNumSurfaces
);
75 for(sal_Int32 y
=0; y
<aImageSizeY
; y
+=aPageSizeY
)
77 for(sal_Int32 x
=0; x
<aImageSizeX
; x
+=aPageSizeX
)
79 // the current surface is located at the position [x,y]
80 // and has the size [min(restx,pagesizex),min(resty,pagesizey)
81 ::basegfx::B2IPoint
aOffset(x
,y
);
82 ::basegfx::B2ISize
aSize( ::std::min( aImageSize
.getX()-x
,
84 ::std::min( aImageSize
.getY()-y
,
87 maSurfaceList
.push_back(
98 //////////////////////////////////////////////////////////////////////////////////
99 // SurfaceProxy::setColorBufferDirty
100 //////////////////////////////////////////////////////////////////////////////////
102 void SurfaceProxy::setColorBufferDirty()
104 ::std::for_each( maSurfaceList
.begin(),
106 ::boost::mem_fn(&Surface::setColorBufferDirty
));
109 //////////////////////////////////////////////////////////////////////////////////
110 // SurfaceProxy::draw
111 //////////////////////////////////////////////////////////////////////////////////
113 bool SurfaceProxy::draw( double fAlpha
,
114 const ::basegfx::B2DPoint
& rPos
,
115 const ::basegfx::B2DHomMatrix
& rTransform
)
117 ::std::for_each( maSurfaceList
.begin(),
119 ::boost::bind( &Surface::draw
,
123 ::boost::cref(rTransform
)));
128 //////////////////////////////////////////////////////////////////////////////////
129 // SurfaceProxy::draw
130 //////////////////////////////////////////////////////////////////////////////////
132 bool SurfaceProxy::draw( double fAlpha
,
133 const ::basegfx::B2DPoint
& rPos
,
134 const ::basegfx::B2DRange
& rArea
,
135 const ::basegfx::B2DHomMatrix
& rTransform
)
137 ::std::for_each( maSurfaceList
.begin(),
139 ::boost::bind(&Surface::drawRectangularArea
,
143 ::boost::cref(rArea
),
144 ::boost::cref(rTransform
)));
149 //////////////////////////////////////////////////////////////////////////////////
150 // SurfaceProxy::draw
151 //////////////////////////////////////////////////////////////////////////////////
153 bool SurfaceProxy::draw( double fAlpha
,
154 const ::basegfx::B2DPoint
& rPos
,
155 const ::basegfx::B2DPolyPolygon
& rClipPoly
,
156 const ::basegfx::B2DHomMatrix
& rTransform
)
158 const ::basegfx::B2DPolygon
& rTriangulatedPolygon(
159 ::basegfx::triangulator::triangulate(rClipPoly
));
161 #if defined(VERBOSE) && OSL_DEBUG_LEVEL > 0
163 OSL_TRACE( "Original clip polygon: %s\n"
164 "Triangulated polygon: %s\n",
165 rtl::OUStringToOString(
166 basegfx::tools::exportToSvgD( rClipPoly
),
167 RTL_TEXTENCODING_ASCII_US
).getStr(),
168 rtl::OUStringToOString(
169 basegfx::tools::exportToSvgD(
170 basegfx::B2DPolyPolygon(rTriangulatedPolygon
) ),
171 RTL_TEXTENCODING_ASCII_US
).getStr() );
174 ::std::for_each( maSurfaceList
.begin(),
176 ::boost::bind(&Surface::drawWithClip
,
180 ::boost::cref(rTriangulatedPolygon
),
181 ::boost::cref(rTransform
)));