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 <drawinglayer/primitive2d/primitivetools2d.hxx>
21 #include <basegfx/vector/b2dvector.hxx>
22 #include <drawinglayer/geometry/viewinformation2d.hxx>
25 namespace drawinglayer::primitive2d
27 void DiscreteMetricDependentPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
29 // get the current DiscreteUnit, look at X and Y and use the maximum
30 const basegfx::B2DVector
aDiscreteVector(rViewInformation
.getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 1.0));
31 const double fDiscreteUnit(std::min(fabs(aDiscreteVector
.getX()), fabs(aDiscreteVector
.getY())));
33 if(!getBuffered2DDecomposition().empty() && !basegfx::fTools::equal(fDiscreteUnit
, getDiscreteUnit()))
35 // conditions of last local decomposition have changed, delete
36 const_cast< DiscreteMetricDependentPrimitive2D
* >(this)->setBuffered2DDecomposition(Primitive2DContainer());
39 if(getBuffered2DDecomposition().empty())
41 // remember new valid DiscreteUnit
42 const_cast< DiscreteMetricDependentPrimitive2D
* >(this)->mfDiscreteUnit
= fDiscreteUnit
;
45 // call base implementation
46 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor
, rViewInformation
);
52 void ViewportDependentPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
54 // get the current Viewport
55 const basegfx::B2DRange
& rViewport
= rViewInformation
.getViewport();
57 if(!getBuffered2DDecomposition().empty() && !rViewport
.equal(getViewport()))
59 // conditions of last local decomposition have changed, delete
60 const_cast< ViewportDependentPrimitive2D
* >(this)->setBuffered2DDecomposition(Primitive2DContainer());
63 if(getBuffered2DDecomposition().empty())
65 // remember new valid DiscreteUnit
66 const_cast< ViewportDependentPrimitive2D
* >(this)->maViewport
= rViewport
;
69 // call base implementation
70 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor
, rViewInformation
);
73 void ViewTransformationDependentPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
75 // get the current ViewTransformation
76 const basegfx::B2DHomMatrix
& rViewTransformation
= rViewInformation
.getViewTransformation();
78 if(!getBuffered2DDecomposition().empty() && rViewTransformation
!= getViewTransformation())
80 // conditions of last local decomposition have changed, delete
81 const_cast< ViewTransformationDependentPrimitive2D
* >(this)->setBuffered2DDecomposition(Primitive2DContainer());
84 if(getBuffered2DDecomposition().empty())
86 // remember new valid ViewTransformation
87 const_cast< ViewTransformationDependentPrimitive2D
* >(this)->maViewTransformation
= rViewTransformation
;
90 // call base implementation
91 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor
, rViewInformation
);
94 void ObjectAndViewTransformationDependentPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
96 // get the current ViewTransformation
97 const basegfx::B2DHomMatrix
& rViewTransformation
= rViewInformation
.getViewTransformation();
99 if(!getBuffered2DDecomposition().empty() && rViewTransformation
!= getViewTransformation())
101 // conditions of last local decomposition have changed, delete
102 const_cast< ObjectAndViewTransformationDependentPrimitive2D
* >(this)->setBuffered2DDecomposition(Primitive2DContainer());
105 // get the current ObjectTransformation
106 const basegfx::B2DHomMatrix
& rObjectTransformation
= rViewInformation
.getObjectTransformation();
108 if(!getBuffered2DDecomposition().empty() && rObjectTransformation
!= getObjectTransformation())
110 // conditions of last local decomposition have changed, delete
111 const_cast< ObjectAndViewTransformationDependentPrimitive2D
* >(this)->setBuffered2DDecomposition(Primitive2DContainer());
114 if(getBuffered2DDecomposition().empty())
116 // remember new valid ViewTransformation, and ObjectTransformation
117 const_cast< ObjectAndViewTransformationDependentPrimitive2D
* >(this)->maViewTransformation
= rViewTransformation
;
118 const_cast< ObjectAndViewTransformationDependentPrimitive2D
* >(this)->maObjectTransformation
= rObjectTransformation
;
121 // call base implementation
122 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor
, rViewInformation
);
125 } // end of namespace
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */