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 <sal/config.h>
26 Page::Page( const std::shared_ptr
<IRenderModule
> &rRenderModule
) :
27 mpRenderModule(rRenderModule
),
28 mpSurface(rRenderModule
->createSurface(::basegfx::B2ISize()))
36 for( const auto& rFragmentPtr
: mpFragments
)
37 rFragmentPtr
->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
= std::make_shared
<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 for( const auto& pFragment
: mpFragments
)
89 const SurfaceRect
&rect
= pFragment
->getRect();
90 const sal_Int32 x
= rect
.maPos
.getX();
91 const sal_Int32 y
= rect
.maPos
.getY();
92 // to avoid interpolation artifacts from other textures,
93 // one pixel gap between them
94 const sal_Int32 w
= rect
.maSize
.getX()+1;
95 const sal_Int32 h
= rect
.maSize
.getY()+1;
97 // probe location to the right
100 if(isValidLocation(r
))
103 // probe location at bottom
106 if(isValidLocation(r
))
113 return isValidLocation(r
);
116 bool Page::isValidLocation( const SurfaceRect
& r
) const
118 // the rectangle passed as argument has a valid
119 // location if and only if there's no intersection
120 // with existing areas.
121 SurfaceRect
aBoundary(mpRenderModule
->getPageSize());
122 if( !r
.inside(aBoundary
) )
125 for( const auto& pFragment
: mpFragments
)
127 if( r
.intersection( pFragment
->getRect() ) )
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */