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 .
20 #include <boost/mem_fn.hpp>
25 Page::Page( const IRenderModuleSharedPtr
&rRenderModule
) :
26 mpRenderModule(rRenderModule
),
27 mpSurface(rRenderModule
->createSurface(::basegfx::B2ISize()))
35 ::std::for_each( mpFragments
.begin(),
37 ::boost::mem_fn(&PageFragment::refresh
));
41 bool Page::isValid() const
43 return mpSurface
&& mpSurface
->isValid();
46 FragmentSharedPtr
Page::allocateSpace( const ::basegfx::B2ISize
& rSize
)
48 SurfaceRect
rect(rSize
);
51 FragmentSharedPtr
pFragment(new PageFragment(rect
,this));
52 mpFragments
.push_back(pFragment
);
56 return FragmentSharedPtr();
59 bool Page::nakedFragment( const FragmentSharedPtr
& pFragment
)
61 SurfaceRect
rect(pFragment
->getSize());
64 pFragment
->setPage(this);
65 mpFragments
.push_back(pFragment
);
72 void Page::free( const FragmentSharedPtr
& pFragment
)
74 // the fragment passes as argument is no longer
75 // dedicated to this page. either it is about to
76 // be relocated to some other page or it will
77 // currently be deleted. in either case, simply
78 // remove the reference from our internal storage.
79 FragmentContainer_t::iterator
it(
81 mpFragments
.begin(),mpFragments
.end(),pFragment
));
82 mpFragments
.erase(it
,mpFragments
.end());
85 bool Page::insert( SurfaceRect
& r
)
87 const FragmentContainer_t::const_iterator
aEnd(mpFragments
.end());
88 FragmentContainer_t::const_iterator
it(mpFragments
.begin());
91 const SurfaceRect
&rect
= (*it
)->getRect();
92 const sal_Int32 x
= rect
.maPos
.getX();
93 const sal_Int32 y
= rect
.maPos
.getY();
94 // to avoid interpolation artifacts from other textures,
95 // one pixel gap between them
96 const sal_Int32 w
= rect
.maSize
.getX()+1;
97 const sal_Int32 h
= rect
.maSize
.getY()+1;
99 // probe location to the right
102 if(isValidLocation(r
))
105 // probe location at bottom
108 if(isValidLocation(r
))
117 return isValidLocation(r
);
120 bool Page::isValidLocation( const SurfaceRect
& r
) const
122 // the rectangle passed as argument has a valid
123 // location if and only if there's no intersection
124 // with existing areas.
125 SurfaceRect
aBoundary(mpRenderModule
->getPageSize()-basegfx::B2IVector(1,1));
126 if( !r
.inside(aBoundary
) )
129 const FragmentContainer_t::const_iterator
aEnd(mpFragments
.end());
130 FragmentContainer_t::const_iterator
it(mpFragments
.begin());
133 if(r
.intersection((*it
)->getRect()))
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */