Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / drawinglayer / source / geometry / viewinformation2d.cxx
blobca7daf60e041bf5775bd4036944ce932de56d909
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/tools/canvastools.hxx>
24 #include <com/sun/star/geometry/AffineMatrix2D.hpp>
25 #include <com/sun/star/geometry/RealRectangle2D.hpp>
26 #include <rtl/instance.hxx>
29 using namespace com::sun::star;
32 namespace drawinglayer
34 namespace geometry
36 class ImpViewInformation2D
38 private:
39 // ViewInformation2D implementation can change refcount, so we have only
40 // two memory regions for pairs of ViewInformation2D/ImpViewInformation2D
41 friend class ::drawinglayer::geometry::ViewInformation2D;
43 protected:
44 // the object transformation
45 basegfx::B2DHomMatrix maObjectTransformation;
47 // the view transformation
48 basegfx::B2DHomMatrix maViewTransformation;
50 // the ObjectToView and it's inverse, both on demand from ObjectTransformation
51 // and ViewTransformation
52 basegfx::B2DHomMatrix maObjectToViewTransformation;
53 basegfx::B2DHomMatrix maInverseObjectToViewTransformation;
55 // the visible range and the on-demand one in ViewCoordinates
56 basegfx::B2DRange maViewport;
57 basegfx::B2DRange maDiscreteViewport;
59 // the DrawPage which is target of visualisation. This is needed e.g. for
60 // the view-dependent decomposition of PageNumber TextFields.
61 // This parameter is buffered here, but mainly resides in mxExtendedInformation,
62 // so it will be interpreted, but held there. It will also not be added
63 // to mxExtendedInformation in impFillViewInformationFromContent (it's there already)
64 uno::Reference< drawing::XDrawPage > mxVisualizedPage;
66 // the point in time
67 double mfViewTime;
69 // bitfield
70 bool mbReducedDisplayQuality : 1;
72 // the complete PropertyValue representation (if already created)
73 uno::Sequence< beans::PropertyValue > mxViewInformation;
75 // the extra PropertyValues; not represented by ViewTransformation,
76 // Viewport, VisualizedPage or ViewTime
77 uno::Sequence< beans::PropertyValue > mxExtendedInformation;
79 // the local UNO API strings
80 static OUString getNamePropertyObjectTransformation()
82 return OUString("ObjectTransformation");
85 static OUString getNamePropertyViewTransformation()
87 return OUString("ViewTransformation");
90 static OUString getNamePropertyViewport()
92 return OUString("Viewport");
95 static OUString getNamePropertyTime()
97 return OUString("Time");
100 static OUString getNamePropertyVisualizedPage()
102 return OUString("VisualizedPage");
105 static OUString getNamePropertyReducedDisplayQuality()
107 return OUString("ReducedDisplayQuality");
110 void impInterpretPropertyValues(const uno::Sequence< beans::PropertyValue >& rViewParameters)
112 if(rViewParameters.hasElements())
114 const sal_Int32 nCount(rViewParameters.getLength());
115 sal_Int32 nExtendedInsert(0);
117 // prepare extended information for filtering. Maximum size is nCount
118 mxExtendedInformation.realloc(nCount);
120 for(sal_Int32 a(0); a < nCount; a++)
122 const beans::PropertyValue& rProp = rViewParameters[a];
124 if(rProp.Name == getNamePropertyReducedDisplayQuality())
126 // extra information; add to filtered information
127 mxExtendedInformation[nExtendedInsert++] = rProp;
129 // for performance reasons, also cache content locally
130 bool bSalBool(false);
131 rProp.Value >>= bSalBool;
132 mbReducedDisplayQuality = bSalBool;
134 else if(rProp.Name == getNamePropertyObjectTransformation())
136 css::geometry::AffineMatrix2D aAffineMatrix2D;
137 rProp.Value >>= aAffineMatrix2D;
138 basegfx::unotools::homMatrixFromAffineMatrix(maObjectTransformation, aAffineMatrix2D);
140 else if(rProp.Name == getNamePropertyViewTransformation())
142 css::geometry::AffineMatrix2D aAffineMatrix2D;
143 rProp.Value >>= aAffineMatrix2D;
144 basegfx::unotools::homMatrixFromAffineMatrix(maViewTransformation, aAffineMatrix2D);
146 else if(rProp.Name == getNamePropertyViewport())
148 css::geometry::RealRectangle2D aViewport;
149 rProp.Value >>= aViewport;
150 maViewport = basegfx::unotools::b2DRectangleFromRealRectangle2D(aViewport);
152 else if(rProp.Name == getNamePropertyTime())
154 rProp.Value >>= mfViewTime;
156 else if(rProp.Name == getNamePropertyVisualizedPage())
158 rProp.Value >>= mxVisualizedPage;
160 else
162 // extra information; add to filtered information
163 mxExtendedInformation[nExtendedInsert++] = rProp;
167 // extra information size is now known; realloc to final size
168 mxExtendedInformation.realloc(nExtendedInsert);
172 void impFillViewInformationFromContent()
174 const bool bObjectTransformationUsed(!maObjectTransformation.isIdentity());
175 const bool bViewTransformationUsed(!maViewTransformation.isIdentity());
176 const bool bViewportUsed(!maViewport.isEmpty());
177 const bool bTimeUsed(0.0 < mfViewTime);
178 const bool bVisualizedPageUsed(mxVisualizedPage.is());
179 const bool bReducedDisplayQualityUsed(mbReducedDisplayQuality);
180 const bool bExtraInformation(mxExtendedInformation.hasElements());
181 sal_uInt32 nIndex(0);
182 const sal_uInt32 nCount(
183 (bObjectTransformationUsed ? 1 : 0) +
184 (bViewTransformationUsed ? 1 : 0) +
185 (bViewportUsed ? 1 : 0) +
186 (bTimeUsed ? 1 : 0) +
187 (bVisualizedPageUsed ? 1 : 0) +
188 (bReducedDisplayQualityUsed ? 1 : 0) +
189 (bExtraInformation ? mxExtendedInformation.getLength() : 0));
191 mxViewInformation.realloc(nCount);
193 if(bObjectTransformationUsed)
195 css::geometry::AffineMatrix2D aAffineMatrix2D;
196 basegfx::unotools::affineMatrixFromHomMatrix(aAffineMatrix2D, maObjectTransformation);
197 mxViewInformation[nIndex].Name = getNamePropertyObjectTransformation();
198 mxViewInformation[nIndex].Value <<= aAffineMatrix2D;
199 nIndex++;
202 if(bViewTransformationUsed)
204 css::geometry::AffineMatrix2D aAffineMatrix2D;
205 basegfx::unotools::affineMatrixFromHomMatrix(aAffineMatrix2D, maViewTransformation);
206 mxViewInformation[nIndex].Name = getNamePropertyViewTransformation();
207 mxViewInformation[nIndex].Value <<= aAffineMatrix2D;
208 nIndex++;
211 if(bViewportUsed)
213 const css::geometry::RealRectangle2D aViewport(basegfx::unotools::rectangle2DFromB2DRectangle(maViewport));
214 mxViewInformation[nIndex].Name = getNamePropertyViewport();
215 mxViewInformation[nIndex].Value <<= aViewport;
216 nIndex++;
219 if(bTimeUsed)
221 mxViewInformation[nIndex].Name = getNamePropertyTime();
222 mxViewInformation[nIndex].Value <<= mfViewTime;
223 nIndex++;
226 if(bVisualizedPageUsed)
228 mxViewInformation[nIndex].Name = getNamePropertyVisualizedPage();
229 mxViewInformation[nIndex].Value <<= mxVisualizedPage;
230 nIndex++;
233 if(bExtraInformation)
235 const sal_Int32 nExtra(mxExtendedInformation.getLength());
237 for(sal_Int32 a(0); a < nExtra; a++)
239 mxViewInformation[nIndex++] = mxExtendedInformation[a];
244 public:
245 ImpViewInformation2D(
246 const basegfx::B2DHomMatrix& rObjectTransformation,
247 const basegfx::B2DHomMatrix& rViewTransformation,
248 const basegfx::B2DRange& rViewport,
249 const uno::Reference< drawing::XDrawPage >& rxDrawPage,
250 double fViewTime,
251 const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
252 : maObjectTransformation(rObjectTransformation),
253 maViewTransformation(rViewTransformation),
254 maObjectToViewTransformation(),
255 maInverseObjectToViewTransformation(),
256 maViewport(rViewport),
257 maDiscreteViewport(),
258 mxVisualizedPage(rxDrawPage),
259 mfViewTime(fViewTime),
260 mbReducedDisplayQuality(false),
261 mxViewInformation(),
262 mxExtendedInformation()
264 impInterpretPropertyValues(rExtendedParameters);
267 explicit ImpViewInformation2D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
268 : maObjectTransformation(),
269 maViewTransformation(),
270 maObjectToViewTransformation(),
271 maInverseObjectToViewTransformation(),
272 maViewport(),
273 maDiscreteViewport(),
274 mxVisualizedPage(),
275 mfViewTime(),
276 mbReducedDisplayQuality(false),
277 mxViewInformation(rViewParameters),
278 mxExtendedInformation()
280 impInterpretPropertyValues(rViewParameters);
283 ImpViewInformation2D()
284 : maObjectTransformation(),
285 maViewTransformation(),
286 maObjectToViewTransformation(),
287 maInverseObjectToViewTransformation(),
288 maViewport(),
289 maDiscreteViewport(),
290 mxVisualizedPage(),
291 mfViewTime(),
292 mbReducedDisplayQuality(false),
293 mxViewInformation(),
294 mxExtendedInformation()
298 const basegfx::B2DHomMatrix& getObjectTransformation() const
300 return maObjectTransformation;
303 const basegfx::B2DHomMatrix& getViewTransformation() const
305 return maViewTransformation;
308 const basegfx::B2DRange& getViewport() const
310 return maViewport;
313 const basegfx::B2DRange& getDiscreteViewport() const
315 if(maDiscreteViewport.isEmpty() && !maViewport.isEmpty())
317 basegfx::B2DRange aDiscreteViewport(maViewport);
318 aDiscreteViewport.transform(getViewTransformation());
319 const_cast< ImpViewInformation2D* >(this)->maDiscreteViewport = aDiscreteViewport;
322 return maDiscreteViewport;
325 const basegfx::B2DHomMatrix& getObjectToViewTransformation() const
327 if(maObjectToViewTransformation.isIdentity() &&
328 (!maObjectTransformation.isIdentity() || !maViewTransformation.isIdentity()))
330 basegfx::B2DHomMatrix aObjectToView(maViewTransformation * maObjectTransformation);
331 const_cast< ImpViewInformation2D* >(this)->maObjectToViewTransformation = aObjectToView;
334 return maObjectToViewTransformation;
337 const basegfx::B2DHomMatrix& getInverseObjectToViewTransformation() const
339 if(maInverseObjectToViewTransformation.isIdentity() &&
340 (!maObjectTransformation.isIdentity() || !maViewTransformation.isIdentity()))
342 basegfx::B2DHomMatrix aInverseObjectToView(maViewTransformation * maObjectTransformation);
343 aInverseObjectToView.invert();
344 const_cast< ImpViewInformation2D* >(this)->maInverseObjectToViewTransformation = aInverseObjectToView;
347 return maInverseObjectToViewTransformation;
350 double getViewTime() const
352 return mfViewTime;
355 const uno::Reference< drawing::XDrawPage >& getVisualizedPage() const
357 return mxVisualizedPage;
360 bool getReducedDisplayQuality() const
362 return mbReducedDisplayQuality;
365 const uno::Sequence< beans::PropertyValue >& getViewInformationSequence() const
367 if(!mxViewInformation.hasElements())
369 const_cast< ImpViewInformation2D* >(this)->impFillViewInformationFromContent();
372 return mxViewInformation;
375 const uno::Sequence< beans::PropertyValue >& getExtendedInformationSequence() const
377 return mxExtendedInformation;
380 bool operator==(const ImpViewInformation2D& rCandidate) const
382 return (maObjectTransformation == rCandidate.maObjectTransformation
383 && maViewTransformation == rCandidate.maViewTransformation
384 && maViewport == rCandidate.maViewport
385 && mxVisualizedPage == rCandidate.mxVisualizedPage
386 && mfViewTime == rCandidate.mfViewTime
387 && mxExtendedInformation == rCandidate.mxExtendedInformation);
390 } // end of anonymous namespace
391 } // end of namespace drawinglayer
394 namespace drawinglayer
396 namespace geometry
398 namespace
400 struct theGlobalDefault :
401 public rtl::Static< ViewInformation2D::ImplType, theGlobalDefault > {};
404 ViewInformation2D::ViewInformation2D(
405 const basegfx::B2DHomMatrix& rObjectTransformation,
406 const basegfx::B2DHomMatrix& rViewTransformation,
407 const basegfx::B2DRange& rViewport,
408 const uno::Reference< drawing::XDrawPage >& rxDrawPage,
409 double fViewTime,
410 const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
411 : mpViewInformation2D(ImpViewInformation2D(
412 rObjectTransformation,
413 rViewTransformation,
414 rViewport,
415 rxDrawPage,
416 fViewTime,
417 rExtendedParameters))
421 ViewInformation2D::ViewInformation2D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
422 : mpViewInformation2D(ImpViewInformation2D(rViewParameters))
426 ViewInformation2D::ViewInformation2D()
427 : mpViewInformation2D(theGlobalDefault::get())
431 ViewInformation2D::ViewInformation2D(const ViewInformation2D& rCandidate)
432 : mpViewInformation2D(rCandidate.mpViewInformation2D)
436 ViewInformation2D::~ViewInformation2D()
440 ViewInformation2D& ViewInformation2D::operator=(const ViewInformation2D& rCandidate)
442 mpViewInformation2D = rCandidate.mpViewInformation2D;
443 return *this;
446 bool ViewInformation2D::operator==(const ViewInformation2D& rCandidate) const
448 return rCandidate.mpViewInformation2D == mpViewInformation2D;
451 const basegfx::B2DHomMatrix& ViewInformation2D::getObjectTransformation() const
453 return mpViewInformation2D->getObjectTransformation();
456 const basegfx::B2DHomMatrix& ViewInformation2D::getViewTransformation() const
458 return mpViewInformation2D->getViewTransformation();
461 const basegfx::B2DRange& ViewInformation2D::getViewport() const
463 return mpViewInformation2D->getViewport();
466 double ViewInformation2D::getViewTime() const
468 return mpViewInformation2D->getViewTime();
471 const uno::Reference< drawing::XDrawPage >& ViewInformation2D::getVisualizedPage() const
473 return mpViewInformation2D->getVisualizedPage();
476 const basegfx::B2DHomMatrix& ViewInformation2D::getObjectToViewTransformation() const
478 return mpViewInformation2D->getObjectToViewTransformation();
481 const basegfx::B2DHomMatrix& ViewInformation2D::getInverseObjectToViewTransformation() const
483 return mpViewInformation2D->getInverseObjectToViewTransformation();
486 const basegfx::B2DRange& ViewInformation2D::getDiscreteViewport() const
488 return mpViewInformation2D->getDiscreteViewport();
491 bool ViewInformation2D::getReducedDisplayQuality() const
493 return mpViewInformation2D->getReducedDisplayQuality();
496 const uno::Sequence< beans::PropertyValue >& ViewInformation2D::getViewInformationSequence() const
498 return mpViewInformation2D->getViewInformationSequence();
501 const uno::Sequence< beans::PropertyValue >& ViewInformation2D::getExtendedInformationSequence() const
503 return mpViewInformation2D->getExtendedInformationSequence();
505 } // end of namespace geometry
506 } // end of namespace drawinglayer
508 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */