1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <boost/bind.hpp>
22 #include <basegfx/polygon/b2dpolygoncutandtouch.hxx>
23 #include <basegfx/polygon/b2dpolygontriangulator.hxx>
24 #include <basegfx/polygon/b2dpolypolygontools.hxx>
25 #include "surfaceproxy.hxx"
30 // SurfaceProxy::SurfaceProxy
33 SurfaceProxy::SurfaceProxy( const canvas::IColorBufferSharedPtr
& pBuffer
,
34 const PageManagerSharedPtr
& pPageManager
) :
35 mpPageManager( pPageManager
),
39 const ::basegfx::B2ISize
aImageSize(mpBuffer
->getWidth(),mpBuffer
->getHeight());
40 const ::basegfx::B2ISize
aPageSize(mpPageManager
->getPageSize());
41 const sal_Int32
aPageSizeX(aPageSize
.getX());
42 const sal_Int32
aPageSizeY(aPageSize
.getY());
43 const sal_Int32
aImageSizeX(aImageSize
.getX());
44 const sal_Int32
aImageSizeY(aImageSize
.getY());
46 // see if the size of the colorbuffer is larger than the size
47 // of a single page. if this is the case we divide the
48 // colorbuffer into as many surfaces as we need to get the
49 // whole area distributed. otherwise (the colorbuffer is
50 // smaller than the size of a single page) we search for free
51 // pages or create a new one.
52 // the incoming image is too large to fit into a single
53 // page. strategy: we split the image into rectangular
54 // areas that are as large as the maximum page size
55 // dictates and follow the strategy for fitting images.
56 size_t dwNumSurfaces(0);
57 for(sal_Int32 y
=0; y
<aImageSizeY
; y
+=aPageSizeY
)
58 for(sal_Int32 x
=0; x
<aImageSizeX
; x
+=aPageSizeX
)
60 maSurfaceList
.reserve(dwNumSurfaces
);
62 for(sal_Int32 y
=0; y
<aImageSizeY
; y
+=aPageSizeY
)
64 for(sal_Int32 x
=0; x
<aImageSizeX
; x
+=aPageSizeX
)
66 // the current surface is located at the position [x,y]
67 // and has the size [min(restx,pagesizex),min(resty,pagesizey)
68 ::basegfx::B2IPoint
aOffset(x
,y
);
69 ::basegfx::B2ISize
aSize( ::std::min( aImageSize
.getX()-x
,
71 ::std::min( aImageSize
.getY()-y
,
74 maSurfaceList
.push_back(
86 // SurfaceProxy::setColorBufferDirty
89 void SurfaceProxy::setColorBufferDirty()
91 ::std::for_each( maSurfaceList
.begin(),
93 ::boost::mem_fn(&Surface::setColorBufferDirty
));
100 bool SurfaceProxy::draw( double fAlpha
,
101 const ::basegfx::B2DPoint
& rPos
,
102 const ::basegfx::B2DHomMatrix
& rTransform
)
104 ::std::for_each( maSurfaceList
.begin(),
106 ::boost::bind( &Surface::draw
,
110 ::boost::cref(rTransform
)));
116 // SurfaceProxy::draw
119 bool SurfaceProxy::draw( double fAlpha
,
120 const ::basegfx::B2DPoint
& rPos
,
121 const ::basegfx::B2DRange
& rArea
,
122 const ::basegfx::B2DHomMatrix
& rTransform
)
124 ::std::for_each( maSurfaceList
.begin(),
126 ::boost::bind(&Surface::drawRectangularArea
,
130 ::boost::cref(rArea
),
131 ::boost::cref(rTransform
)));
137 // SurfaceProxy::draw
140 bool SurfaceProxy::draw( double fAlpha
,
141 const ::basegfx::B2DPoint
& rPos
,
142 const ::basegfx::B2DPolyPolygon
& rClipPoly
,
143 const ::basegfx::B2DHomMatrix
& rTransform
)
145 const ::basegfx::B2DPolygon
& rTriangulatedPolygon(
146 ::basegfx::triangulator::triangulate(rClipPoly
));
148 #if OSL_DEBUG_LEVEL > 2
150 OSL_TRACE( "Original clip polygon: %s\n"
151 "Triangulated polygon: %s\n",
153 basegfx::tools::exportToSvgD( rClipPoly
, true, true, false ),
154 RTL_TEXTENCODING_ASCII_US
).getStr(),
156 basegfx::tools::exportToSvgD(
157 basegfx::B2DPolyPolygon(rTriangulatedPolygon
), true, true, false ),
158 RTL_TEXTENCODING_ASCII_US
).getStr() );
161 ::std::for_each( maSurfaceList
.begin(),
163 ::boost::bind(&Surface::drawWithClip
,
167 ::boost::cref(rTriangulatedPolygon
),
168 ::boost::cref(rTransform
)));
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */