calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / drawinglayer / source / geometry / viewinformation2d.cxx
blob7e0240690a68d1b84376c13391cec8c7fbfa66b9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/geometry/viewinformation2d.hxx>
21 #include <basegfx/matrix/b2dhommatrix.hxx>
22 #include <basegfx/range/b2drange.hxx>
23 #include <basegfx/utils/canvastools.hxx>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/drawing/XDrawPage.hpp>
26 #include <com/sun/star/geometry/AffineMatrix2D.hpp>
27 #include <com/sun/star/geometry/RealRectangle2D.hpp>
28 #include <officecfg/Office/Common.hxx>
29 #include <unotools/configmgr.hxx>
30 #include <utility>
32 using namespace com::sun::star;
34 namespace drawinglayer::geometry
36 namespace
38 constexpr OUStringLiteral g_PropertyName_ObjectTransformation = u"ObjectTransformation";
39 constexpr OUStringLiteral g_PropertyName_ViewTransformation = u"ViewTransformation";
40 constexpr OUStringLiteral g_PropertyName_Viewport = u"Viewport";
41 constexpr OUStringLiteral g_PropertyName_Time = u"Time";
42 constexpr OUStringLiteral g_PropertyName_VisualizedPage = u"VisualizedPage";
43 constexpr OUStringLiteral g_PropertyName_ReducedDisplayQuality = u"ReducedDisplayQuality";
44 constexpr OUStringLiteral g_PropertyName_UseAntiAliasing = u"UseAntiAliasing";
45 constexpr OUStringLiteral g_PropertyName_PixelSnapHairline = u"PixelSnapHairline";
48 namespace
50 bool bForwardsAreInitialized(false);
51 bool bForwardedAntiAliasing(true);
52 bool bForwardPixelSnapHairline(true);
55 class ImpViewInformation2D
57 private:
58 // ViewInformation2D implementation can change refcount, so we have only
59 // two memory regions for pairs of ViewInformation2D/ImpViewInformation2D
60 friend class ::drawinglayer::geometry::ViewInformation2D;
62 protected:
63 // the object transformation
64 basegfx::B2DHomMatrix maObjectTransformation;
66 // the view transformation
67 basegfx::B2DHomMatrix maViewTransformation;
69 // the ObjectToView and it's inverse, both on demand from ObjectTransformation
70 // and ViewTransformation
71 basegfx::B2DHomMatrix maObjectToViewTransformation;
72 basegfx::B2DHomMatrix maInverseObjectToViewTransformation;
74 // the visible range and the on-demand one in ViewCoordinates
75 basegfx::B2DRange maViewport;
76 basegfx::B2DRange maDiscreteViewport;
78 // the DrawPage which is target of visualisation. This is needed e.g. for
79 // the view-dependent decomposition of PageNumber TextFields.
80 // This parameter is buffered here, but mainly resides in mxExtendedInformation,
81 // so it will be interpreted, but held there. It will also not be added
82 // to mxExtendedInformation in impFillViewInformationFromContent (it's there already)
83 uno::Reference<drawing::XDrawPage> mxVisualizedPage;
85 // the point in time
86 double mfViewTime;
88 // allow to reduce DisplayQuality (e.g. sw 3d fallback renderer for interactions)
89 bool mbReducedDisplayQuality : 1;
91 // determine if to use AntiAliasing on target pixel device
92 bool mbUseAntiAliasing : 1;
94 // determine if to use PixelSnapHairline on target pixel device
95 bool mbPixelSnapHairline : 1;
97 public:
98 ImpViewInformation2D()
99 : maObjectTransformation()
100 , maViewTransformation()
101 , maObjectToViewTransformation()
102 , maInverseObjectToViewTransformation()
103 , maViewport()
104 , maDiscreteViewport()
105 , mxVisualizedPage()
106 , mfViewTime(0.0)
107 , mbReducedDisplayQuality(false)
108 , mbUseAntiAliasing(bForwardedAntiAliasing)
109 , mbPixelSnapHairline(bForwardedAntiAliasing && bForwardPixelSnapHairline)
113 const basegfx::B2DHomMatrix& getObjectTransformation() const { return maObjectTransformation; }
114 void setObjectTransformation(const basegfx::B2DHomMatrix& rNew)
116 maObjectTransformation = rNew;
117 maObjectToViewTransformation.identity();
118 maInverseObjectToViewTransformation.identity();
121 const basegfx::B2DHomMatrix& getViewTransformation() const { return maViewTransformation; }
122 void setViewTransformation(const basegfx::B2DHomMatrix& rNew)
124 maViewTransformation = rNew;
125 maDiscreteViewport.reset();
126 maObjectToViewTransformation.identity();
127 maInverseObjectToViewTransformation.identity();
130 const basegfx::B2DRange& getViewport() const { return maViewport; }
131 void setViewport(const basegfx::B2DRange& rNew)
133 maViewport = rNew;
134 maDiscreteViewport.reset();
137 const basegfx::B2DRange& getDiscreteViewport() const
139 if (maDiscreteViewport.isEmpty() && !maViewport.isEmpty())
141 basegfx::B2DRange aDiscreteViewport(maViewport);
142 aDiscreteViewport.transform(getViewTransformation());
143 const_cast<ImpViewInformation2D*>(this)->maDiscreteViewport = aDiscreteViewport;
146 return maDiscreteViewport;
149 const basegfx::B2DHomMatrix& getObjectToViewTransformation() const
151 if (maObjectToViewTransformation.isIdentity()
152 && (!maObjectTransformation.isIdentity() || !maViewTransformation.isIdentity()))
154 basegfx::B2DHomMatrix aObjectToView(maViewTransformation * maObjectTransformation);
155 const_cast<ImpViewInformation2D*>(this)->maObjectToViewTransformation = aObjectToView;
158 return maObjectToViewTransformation;
161 const basegfx::B2DHomMatrix& getInverseObjectToViewTransformation() const
163 if (maInverseObjectToViewTransformation.isIdentity()
164 && (!maObjectTransformation.isIdentity() || !maViewTransformation.isIdentity()))
166 basegfx::B2DHomMatrix aInverseObjectToView(maViewTransformation
167 * maObjectTransformation);
168 aInverseObjectToView.invert();
169 const_cast<ImpViewInformation2D*>(this)->maInverseObjectToViewTransformation
170 = aInverseObjectToView;
173 return maInverseObjectToViewTransformation;
176 double getViewTime() const { return mfViewTime; }
177 void setViewTime(double fNew)
179 if (fNew >= 0.0)
181 mfViewTime = fNew;
185 const uno::Reference<drawing::XDrawPage>& getVisualizedPage() const { return mxVisualizedPage; }
186 void setVisualizedPage(const uno::Reference<drawing::XDrawPage>& rNew)
188 mxVisualizedPage = rNew;
191 bool getReducedDisplayQuality() const { return mbReducedDisplayQuality; }
192 void setReducedDisplayQuality(bool bNew) { mbReducedDisplayQuality = bNew; }
194 bool getUseAntiAliasing() const { return mbUseAntiAliasing; }
195 void setUseAntiAliasing(bool bNew) { mbUseAntiAliasing = bNew; }
197 bool getPixelSnapHairline() const { return mbPixelSnapHairline; }
198 void setPixelSnapHairline(bool bNew) { mbPixelSnapHairline = bNew; }
200 bool operator==(const ImpViewInformation2D& rCandidate) const
202 return (maObjectTransformation == rCandidate.maObjectTransformation
203 && maViewTransformation == rCandidate.maViewTransformation
204 && maViewport == rCandidate.maViewport
205 && mxVisualizedPage == rCandidate.mxVisualizedPage
206 && mfViewTime == rCandidate.mfViewTime
207 && mbReducedDisplayQuality == rCandidate.mbReducedDisplayQuality
208 && mbUseAntiAliasing == rCandidate.mbUseAntiAliasing
209 && mbPixelSnapHairline == rCandidate.mbPixelSnapHairline);
213 namespace
215 ViewInformation2D::ImplType& theGlobalDefault()
217 static ViewInformation2D::ImplType SINGLETON;
218 return SINGLETON;
222 ViewInformation2D::ViewInformation2D()
223 : mpViewInformation2D(theGlobalDefault())
225 if (!bForwardsAreInitialized)
227 bForwardsAreInitialized = true;
228 if (!utl::ConfigManager::IsFuzzing())
230 bForwardedAntiAliasing = officecfg::Office::Common::Drawinglayer::AntiAliasing::get();
231 bForwardPixelSnapHairline
232 = officecfg::Office::Common::Drawinglayer::SnapHorVerLinesToDiscrete::get();
236 setUseAntiAliasing(bForwardedAntiAliasing);
237 setPixelSnapHairline(bForwardPixelSnapHairline);
240 ViewInformation2D::ViewInformation2D(const ViewInformation2D&) = default;
242 ViewInformation2D::ViewInformation2D(ViewInformation2D&&) = default;
244 ViewInformation2D::~ViewInformation2D() = default;
246 ViewInformation2D& ViewInformation2D::operator=(const ViewInformation2D&) = default;
248 ViewInformation2D& ViewInformation2D::operator=(ViewInformation2D&&) = default;
250 bool ViewInformation2D::operator==(const ViewInformation2D& rCandidate) const
252 return rCandidate.mpViewInformation2D == mpViewInformation2D;
255 const basegfx::B2DHomMatrix& ViewInformation2D::getObjectTransformation() const
257 return mpViewInformation2D->getObjectTransformation();
260 void ViewInformation2D::setObjectTransformation(const basegfx::B2DHomMatrix& rNew)
262 if (std::as_const(mpViewInformation2D)->getObjectTransformation() != rNew)
263 mpViewInformation2D->setObjectTransformation(rNew);
266 const basegfx::B2DHomMatrix& ViewInformation2D::getViewTransformation() const
268 return mpViewInformation2D->getViewTransformation();
271 void ViewInformation2D::setViewTransformation(const basegfx::B2DHomMatrix& rNew)
273 if (std::as_const(mpViewInformation2D)->getViewTransformation() != rNew)
274 mpViewInformation2D->setViewTransformation(rNew);
277 const basegfx::B2DRange& ViewInformation2D::getViewport() const
279 return mpViewInformation2D->getViewport();
282 void ViewInformation2D::setViewport(const basegfx::B2DRange& rNew)
284 if (rNew != std::as_const(mpViewInformation2D)->getViewport())
285 mpViewInformation2D->setViewport(rNew);
288 double ViewInformation2D::getViewTime() const { return mpViewInformation2D->getViewTime(); }
290 void ViewInformation2D::setViewTime(double fNew)
292 if (fNew != std::as_const(mpViewInformation2D)->getViewTime())
293 mpViewInformation2D->setViewTime(fNew);
296 const uno::Reference<drawing::XDrawPage>& ViewInformation2D::getVisualizedPage() const
298 return mpViewInformation2D->getVisualizedPage();
301 void ViewInformation2D::setVisualizedPage(const uno::Reference<drawing::XDrawPage>& rNew)
303 if (rNew != std::as_const(mpViewInformation2D)->getVisualizedPage())
304 mpViewInformation2D->setVisualizedPage(rNew);
307 const basegfx::B2DHomMatrix& ViewInformation2D::getObjectToViewTransformation() const
309 return mpViewInformation2D->getObjectToViewTransformation();
312 const basegfx::B2DHomMatrix& ViewInformation2D::getInverseObjectToViewTransformation() const
314 return mpViewInformation2D->getInverseObjectToViewTransformation();
317 const basegfx::B2DRange& ViewInformation2D::getDiscreteViewport() const
319 return mpViewInformation2D->getDiscreteViewport();
322 bool ViewInformation2D::getReducedDisplayQuality() const
324 return mpViewInformation2D->getReducedDisplayQuality();
327 void ViewInformation2D::setReducedDisplayQuality(bool bNew)
329 if (bNew != std::as_const(mpViewInformation2D)->getReducedDisplayQuality())
330 mpViewInformation2D->setReducedDisplayQuality(bNew);
333 bool ViewInformation2D::getUseAntiAliasing() const
335 return mpViewInformation2D->getUseAntiAliasing();
338 void ViewInformation2D::setUseAntiAliasing(bool bNew)
340 if (bNew != std::as_const(mpViewInformation2D)->getUseAntiAliasing())
341 mpViewInformation2D->setUseAntiAliasing(bNew);
344 bool ViewInformation2D::getPixelSnapHairline() const
346 return mpViewInformation2D->getPixelSnapHairline();
349 void ViewInformation2D::setPixelSnapHairline(bool bNew)
351 if (bNew != std::as_const(mpViewInformation2D)->getPixelSnapHairline())
352 mpViewInformation2D->setPixelSnapHairline(bNew);
355 void ViewInformation2D::forwardAntiAliasing(bool bAntiAliasing)
357 bForwardedAntiAliasing = bAntiAliasing;
360 void ViewInformation2D::forwardPixelSnapHairline(bool bPixelSnapHairline)
362 bForwardPixelSnapHairline = bPixelSnapHairline;
365 ViewInformation2D
366 createViewInformation2D(const css::uno::Sequence<css::beans::PropertyValue>& rViewParameters)
368 if (!rViewParameters.hasElements())
369 return ViewInformation2D();
371 ViewInformation2D aRetval;
373 for (auto const& rPropertyValue : rViewParameters)
375 if (rPropertyValue.Name == g_PropertyName_ReducedDisplayQuality)
377 bool bNew(false);
378 rPropertyValue.Value >>= bNew;
379 aRetval.setReducedDisplayQuality(bNew);
381 else if (rPropertyValue.Name == g_PropertyName_PixelSnapHairline)
383 bool bNew(
384 true); //SvtOptionsDrawinglayer::IsAntiAliasing() && SvtOptionsDrawinglayer::IsSnapHorVerLinesToDiscrete());
385 rPropertyValue.Value >>= bNew;
386 aRetval.setPixelSnapHairline(bNew);
388 else if (rPropertyValue.Name == g_PropertyName_UseAntiAliasing)
390 bool bNew(true); //SvtOptionsDrawinglayer::IsAntiAliasing());
391 rPropertyValue.Value >>= bNew;
392 aRetval.setUseAntiAliasing(bNew);
394 else if (rPropertyValue.Name == g_PropertyName_ObjectTransformation)
396 css::geometry::AffineMatrix2D aAffineMatrix2D;
397 rPropertyValue.Value >>= aAffineMatrix2D;
398 basegfx::B2DHomMatrix aTransformation;
399 basegfx::unotools::homMatrixFromAffineMatrix(aTransformation, aAffineMatrix2D);
400 aRetval.setObjectTransformation(aTransformation);
402 else if (rPropertyValue.Name == g_PropertyName_ViewTransformation)
404 css::geometry::AffineMatrix2D aAffineMatrix2D;
405 rPropertyValue.Value >>= aAffineMatrix2D;
406 basegfx::B2DHomMatrix aTransformation;
407 basegfx::unotools::homMatrixFromAffineMatrix(aTransformation, aAffineMatrix2D);
408 aRetval.setViewTransformation(aTransformation);
410 else if (rPropertyValue.Name == g_PropertyName_Viewport)
412 css::geometry::RealRectangle2D aUnoViewport;
413 rPropertyValue.Value >>= aUnoViewport;
414 const basegfx::B2DRange aViewport(
415 basegfx::unotools::b2DRectangleFromRealRectangle2D(aUnoViewport));
416 aRetval.setViewport(aViewport);
418 else if (rPropertyValue.Name == g_PropertyName_Time)
420 double fViewTime(0.0);
421 rPropertyValue.Value >>= fViewTime;
422 aRetval.setViewTime(fViewTime);
424 else if (rPropertyValue.Name == g_PropertyName_VisualizedPage)
426 css::uno::Reference<css::drawing::XDrawPage> xVisualizedPage;
427 rPropertyValue.Value >>= xVisualizedPage;
428 aRetval.setVisualizedPage(xVisualizedPage);
432 return aRetval;
435 } // end of namespace drawinglayer::geometry
437 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */