Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
27 :
28 : //////////////////////////////////////////////////////////////////////////////
29 :
30 : using namespace com::sun::star;
31 :
32 : //////////////////////////////////////////////////////////////////////////////
33 :
34 : namespace drawinglayer
35 : {
36 : namespace geometry
37 : {
38 151386 : class ImpViewInformation2D
39 : {
40 : private:
41 : // ViewInformation2D implementation can change refcount, so we have only
42 : // two memory regions for pairs of ViewInformation2D/ImpViewInformation2D
43 : friend class ::drawinglayer::geometry::ViewInformation2D;
44 :
45 : protected:
46 : // the object transformation
47 : basegfx::B2DHomMatrix maObjectTransformation;
48 :
49 : // the view transformation
50 : basegfx::B2DHomMatrix maViewTransformation;
51 :
52 : // the ObjectToView and it's inverse, both on demand from ObjectTransformation
53 : // and ViewTransformation
54 : basegfx::B2DHomMatrix maObjectToViewTransformation;
55 : basegfx::B2DHomMatrix maInverseObjectToViewTransformation;
56 :
57 : // the visible range and the on-demand one in ViewCoordinates
58 : basegfx::B2DRange maViewport;
59 : basegfx::B2DRange maDiscreteViewport;
60 :
61 : // the DrawPage which is target of visualisation. This is needed e.g. for
62 : // the view-dependent decomposition of PageNumber TextFields.
63 : // This parameter is buffered here, but mainly resides in mxExtendedInformation,
64 : // so it will be interpreted, but held there. It will also not be added
65 : // to mxExtendedInformation in impFillViewInformationFromContent (it's there already)
66 : uno::Reference< drawing::XDrawPage > mxVisualizedPage;
67 :
68 : // the point in time
69 : double mfViewTime;
70 :
71 : // bitfield
72 : bool mbReducedDisplayQuality : 1;
73 :
74 : // the complete PropertyValue representation (if already created)
75 : uno::Sequence< beans::PropertyValue > mxViewInformation;
76 :
77 : // the extra PropertyValues; not represented by ViewTransformation,
78 : // Viewport, VisualizedPage or ViewTime
79 : uno::Sequence< beans::PropertyValue > mxExtendedInformation;
80 :
81 : // the local UNO API strings
82 0 : const OUString& getNamePropertyObjectTransformation()
83 : {
84 0 : static OUString s_sNameProperty("ObjectTransformation");
85 0 : return s_sNameProperty;
86 : }
87 :
88 0 : const OUString& getNamePropertyViewTransformation()
89 : {
90 0 : static OUString s_sNameProperty("ViewTransformation");
91 0 : return s_sNameProperty;
92 : }
93 :
94 0 : const OUString& getNamePropertyViewport()
95 : {
96 0 : static OUString s_sNameProperty("Viewport");
97 0 : return s_sNameProperty;
98 : }
99 :
100 0 : const OUString& getNamePropertyTime()
101 : {
102 0 : static OUString s_sNameProperty("Time");
103 0 : return s_sNameProperty;
104 : }
105 :
106 0 : const OUString& getNamePropertyVisualizedPage()
107 : {
108 0 : static OUString s_sNameProperty("VisualizedPage");
109 0 : return s_sNameProperty;
110 : }
111 :
112 1088 : const OUString& getNamePropertyReducedDisplayQuality()
113 : {
114 1088 : static OUString s_sNameProperty("ReducedDisplayQuality");
115 1088 : return s_sNameProperty;
116 : }
117 :
118 50441 : void impInterpretPropertyValues(const uno::Sequence< beans::PropertyValue >& rViewParameters)
119 : {
120 50441 : if(rViewParameters.hasElements())
121 : {
122 1088 : const sal_Int32 nCount(rViewParameters.getLength());
123 1088 : sal_Int32 nExtendedInsert(0);
124 :
125 : // prepare extended information for filtering. Maximum size is nCount
126 1088 : mxExtendedInformation.realloc(nCount);
127 :
128 2176 : for(sal_Int32 a(0); a < nCount; a++)
129 : {
130 1088 : const beans::PropertyValue& rProp = rViewParameters[a];
131 :
132 1088 : if(rProp.Name == getNamePropertyReducedDisplayQuality())
133 : {
134 : // extra information; add to filtered information
135 1088 : mxExtendedInformation[nExtendedInsert++] = rProp;
136 :
137 : // for performance reasons, also cache content locally
138 1088 : sal_Bool bSalBool(false);
139 1088 : rProp.Value >>= bSalBool;
140 1088 : mbReducedDisplayQuality = bSalBool;
141 : }
142 0 : else if(rProp.Name == getNamePropertyObjectTransformation())
143 : {
144 0 : com::sun::star::geometry::AffineMatrix2D aAffineMatrix2D;
145 0 : rProp.Value >>= aAffineMatrix2D;
146 0 : basegfx::unotools::homMatrixFromAffineMatrix(maObjectTransformation, aAffineMatrix2D);
147 : }
148 0 : else if(rProp.Name == getNamePropertyViewTransformation())
149 : {
150 0 : com::sun::star::geometry::AffineMatrix2D aAffineMatrix2D;
151 0 : rProp.Value >>= aAffineMatrix2D;
152 0 : basegfx::unotools::homMatrixFromAffineMatrix(maViewTransformation, aAffineMatrix2D);
153 : }
154 0 : else if(rProp.Name == getNamePropertyViewport())
155 : {
156 0 : com::sun::star::geometry::RealRectangle2D aViewport;
157 0 : rProp.Value >>= aViewport;
158 0 : maViewport = basegfx::unotools::b2DRectangleFromRealRectangle2D(aViewport);
159 : }
160 0 : else if(rProp.Name == getNamePropertyTime())
161 : {
162 0 : rProp.Value >>= mfViewTime;
163 : }
164 0 : else if(rProp.Name == getNamePropertyVisualizedPage())
165 : {
166 0 : rProp.Value >>= mxVisualizedPage;
167 : }
168 : else
169 : {
170 : // extra information; add to filtered information
171 0 : mxExtendedInformation[nExtendedInsert++] = rProp;
172 : }
173 : }
174 :
175 : // extra information size is now known; realloc to final size
176 1088 : mxExtendedInformation.realloc(nExtendedInsert);
177 : }
178 50441 : }
179 :
180 0 : void impFillViewInformationFromContent()
181 : {
182 0 : uno::Sequence< beans::PropertyValue > xRetval;
183 0 : const bool bObjectTransformationUsed(!maObjectTransformation.isIdentity());
184 0 : const bool bViewTransformationUsed(!maViewTransformation.isIdentity());
185 0 : const bool bViewportUsed(!maViewport.isEmpty());
186 0 : const bool bTimeUsed(0.0 < mfViewTime);
187 0 : const bool bVisualizedPageUsed(mxVisualizedPage.is());
188 0 : const bool bReducedDisplayQualityUsed(true == mbReducedDisplayQuality);
189 0 : const bool bExtraInformation(mxExtendedInformation.hasElements());
190 0 : sal_uInt32 nIndex(0);
191 : const sal_uInt32 nCount(
192 0 : (bObjectTransformationUsed ? 1 : 0) +
193 0 : (bViewTransformationUsed ? 1 : 0) +
194 0 : (bViewportUsed ? 1 : 0) +
195 0 : (bTimeUsed ? 1 : 0) +
196 0 : (bVisualizedPageUsed ? 1 : 0) +
197 0 : (bReducedDisplayQualityUsed ? 1 : 0) +
198 0 : (bExtraInformation ? mxExtendedInformation.getLength() : 0));
199 :
200 0 : mxViewInformation.realloc(nCount);
201 :
202 0 : if(bObjectTransformationUsed)
203 : {
204 0 : com::sun::star::geometry::AffineMatrix2D aAffineMatrix2D;
205 0 : basegfx::unotools::affineMatrixFromHomMatrix(aAffineMatrix2D, maObjectTransformation);
206 0 : mxViewInformation[nIndex].Name = getNamePropertyObjectTransformation();
207 0 : mxViewInformation[nIndex].Value <<= aAffineMatrix2D;
208 0 : nIndex++;
209 : }
210 :
211 0 : if(bViewTransformationUsed)
212 : {
213 0 : com::sun::star::geometry::AffineMatrix2D aAffineMatrix2D;
214 0 : basegfx::unotools::affineMatrixFromHomMatrix(aAffineMatrix2D, maViewTransformation);
215 0 : mxViewInformation[nIndex].Name = getNamePropertyViewTransformation();
216 0 : mxViewInformation[nIndex].Value <<= aAffineMatrix2D;
217 0 : nIndex++;
218 : }
219 :
220 0 : if(bViewportUsed)
221 : {
222 0 : const com::sun::star::geometry::RealRectangle2D aViewport(basegfx::unotools::rectangle2DFromB2DRectangle(maViewport));
223 0 : mxViewInformation[nIndex].Name = getNamePropertyViewport();
224 0 : mxViewInformation[nIndex].Value <<= aViewport;
225 0 : nIndex++;
226 : }
227 :
228 0 : if(bTimeUsed)
229 : {
230 0 : mxViewInformation[nIndex].Name = getNamePropertyTime();
231 0 : mxViewInformation[nIndex].Value <<= mfViewTime;
232 0 : nIndex++;
233 : }
234 :
235 0 : if(bVisualizedPageUsed)
236 : {
237 0 : mxViewInformation[nIndex].Name = getNamePropertyVisualizedPage();
238 0 : mxViewInformation[nIndex].Value <<= mxVisualizedPage;
239 0 : nIndex++;
240 : }
241 :
242 0 : if(bExtraInformation)
243 : {
244 0 : const sal_Int32 nExtra(mxExtendedInformation.getLength());
245 :
246 0 : for(sal_Int32 a(0); a < nExtra; a++)
247 : {
248 0 : mxViewInformation[nIndex++] = mxExtendedInformation[a];
249 : }
250 0 : }
251 0 : }
252 :
253 : public:
254 47876 : ImpViewInformation2D(
255 : const basegfx::B2DHomMatrix& rObjectTransformation,
256 : const basegfx::B2DHomMatrix& rViewTransformation,
257 : const basegfx::B2DRange& rViewport,
258 : const uno::Reference< drawing::XDrawPage >& rxDrawPage,
259 : double fViewTime,
260 : const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
261 : : maObjectTransformation(rObjectTransformation),
262 : maViewTransformation(rViewTransformation),
263 : maObjectToViewTransformation(),
264 : maInverseObjectToViewTransformation(),
265 : maViewport(rViewport),
266 : maDiscreteViewport(),
267 : mxVisualizedPage(rxDrawPage),
268 : mfViewTime(fViewTime),
269 : mbReducedDisplayQuality(false),
270 : mxViewInformation(),
271 47876 : mxExtendedInformation()
272 : {
273 47876 : impInterpretPropertyValues(rExtendedParameters);
274 47876 : }
275 :
276 2565 : explicit ImpViewInformation2D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
277 : : maObjectTransformation(),
278 : maViewTransformation(),
279 : maObjectToViewTransformation(),
280 : maInverseObjectToViewTransformation(),
281 : maViewport(),
282 : maDiscreteViewport(),
283 : mxVisualizedPage(),
284 : mfViewTime(),
285 : mbReducedDisplayQuality(false),
286 : mxViewInformation(rViewParameters),
287 2565 : mxExtendedInformation()
288 : {
289 2565 : impInterpretPropertyValues(rViewParameters);
290 2565 : }
291 :
292 65 : ImpViewInformation2D()
293 : : maObjectTransformation(),
294 : maViewTransformation(),
295 : maObjectToViewTransformation(),
296 : maInverseObjectToViewTransformation(),
297 : maViewport(),
298 : maDiscreteViewport(),
299 : mxVisualizedPage(),
300 : mfViewTime(),
301 : mbReducedDisplayQuality(false),
302 : mxViewInformation(),
303 65 : mxExtendedInformation()
304 : {
305 65 : }
306 :
307 7346 : const basegfx::B2DHomMatrix& getObjectTransformation() const
308 : {
309 7346 : return maObjectTransformation;
310 : }
311 :
312 16419 : const basegfx::B2DHomMatrix& getViewTransformation() const
313 : {
314 16419 : return maViewTransformation;
315 : }
316 :
317 54866 : const basegfx::B2DRange& getViewport() const
318 : {
319 54866 : return maViewport;
320 : }
321 :
322 5095 : const basegfx::B2DRange& getDiscreteViewport() const
323 : {
324 5095 : if(maDiscreteViewport.isEmpty() && !maViewport.isEmpty())
325 : {
326 1314 : basegfx::B2DRange aDiscreteViewport(maViewport);
327 1314 : aDiscreteViewport.transform(getViewTransformation());
328 1314 : const_cast< ImpViewInformation2D* >(this)->maDiscreteViewport = aDiscreteViewport;
329 : }
330 :
331 5095 : return maDiscreteViewport;
332 : }
333 :
334 120389 : const basegfx::B2DHomMatrix& getObjectToViewTransformation() const
335 : {
336 196987 : if(maObjectToViewTransformation.isIdentity() &&
337 106671 : (!maObjectTransformation.isIdentity() || !maViewTransformation.isIdentity()))
338 : {
339 23248 : basegfx::B2DHomMatrix aObjectToView(maViewTransformation * maObjectTransformation);
340 23248 : const_cast< ImpViewInformation2D* >(this)->maObjectToViewTransformation = aObjectToView;
341 : }
342 :
343 120389 : return maObjectToViewTransformation;
344 : }
345 :
346 122953 : const basegfx::B2DHomMatrix& getInverseObjectToViewTransformation() const
347 : {
348 148124 : if(maInverseObjectToViewTransformation.isIdentity() &&
349 40311 : (!maObjectTransformation.isIdentity() || !maViewTransformation.isIdentity()))
350 : {
351 3763 : basegfx::B2DHomMatrix aInverseObjectToView(maViewTransformation * maObjectTransformation);
352 3763 : aInverseObjectToView.invert();
353 3763 : const_cast< ImpViewInformation2D* >(this)->maInverseObjectToViewTransformation = aInverseObjectToView;
354 : }
355 :
356 122953 : return maInverseObjectToViewTransformation;
357 : }
358 :
359 7127 : double getViewTime() const
360 : {
361 7127 : return mfViewTime;
362 : }
363 :
364 17133 : const uno::Reference< drawing::XDrawPage >& getVisualizedPage() const
365 : {
366 17133 : return mxVisualizedPage;
367 : }
368 :
369 5 : bool getReducedDisplayQuality() const
370 : {
371 5 : return mbReducedDisplayQuality;
372 : }
373 :
374 0 : const uno::Sequence< beans::PropertyValue >& getViewInformationSequence() const
375 : {
376 0 : if(!mxViewInformation.hasElements())
377 : {
378 0 : const_cast< ImpViewInformation2D* >(this)->impFillViewInformationFromContent();
379 : }
380 :
381 0 : return mxViewInformation;
382 : }
383 :
384 7127 : const uno::Sequence< beans::PropertyValue >& getExtendedInformationSequence() const
385 : {
386 7127 : return mxExtendedInformation;
387 : }
388 :
389 0 : bool operator==(const ImpViewInformation2D& rCandidate) const
390 : {
391 0 : return (maObjectTransformation == rCandidate.maObjectTransformation
392 0 : && maViewTransformation == rCandidate.maViewTransformation
393 0 : && maViewport == rCandidate.maViewport
394 0 : && mxVisualizedPage == rCandidate.mxVisualizedPage
395 0 : && mfViewTime == rCandidate.mfViewTime
396 0 : && mxExtendedInformation == rCandidate.mxExtendedInformation);
397 : }
398 : };
399 : } // end of anonymous namespace
400 : } // end of namespace drawinglayer
401 :
402 : //////////////////////////////////////////////////////////////////////////////
403 :
404 : namespace drawinglayer
405 : {
406 : namespace geometry
407 : {
408 : namespace
409 : {
410 : struct theGlobalDefault :
411 : public rtl::Static< ViewInformation2D::ImplType, theGlobalDefault > {};
412 : }
413 :
414 47876 : ViewInformation2D::ViewInformation2D(
415 : const basegfx::B2DHomMatrix& rObjectTransformation,
416 : const basegfx::B2DHomMatrix& rViewTransformation,
417 : const basegfx::B2DRange& rViewport,
418 : const uno::Reference< drawing::XDrawPage >& rxDrawPage,
419 : double fViewTime,
420 : const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
421 : : mpViewInformation2D(ImpViewInformation2D(
422 : rObjectTransformation,
423 : rViewTransformation,
424 : rViewport,
425 : rxDrawPage,
426 : fViewTime,
427 47876 : rExtendedParameters))
428 : {
429 47876 : }
430 :
431 2565 : ViewInformation2D::ViewInformation2D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
432 2565 : : mpViewInformation2D(ImpViewInformation2D(rViewParameters))
433 : {
434 2565 : }
435 :
436 16594 : ViewInformation2D::ViewInformation2D()
437 16594 : : mpViewInformation2D(theGlobalDefault::get())
438 : {
439 16594 : }
440 :
441 54964 : ViewInformation2D::ViewInformation2D(const ViewInformation2D& rCandidate)
442 54964 : : mpViewInformation2D(rCandidate.mpViewInformation2D)
443 : {
444 54964 : }
445 :
446 121997 : ViewInformation2D::~ViewInformation2D()
447 : {
448 121997 : }
449 :
450 0 : bool ViewInformation2D::isDefault() const
451 : {
452 0 : return mpViewInformation2D.same_object(theGlobalDefault::get());
453 : }
454 :
455 37767 : ViewInformation2D& ViewInformation2D::operator=(const ViewInformation2D& rCandidate)
456 : {
457 37767 : mpViewInformation2D = rCandidate.mpViewInformation2D;
458 37767 : return *this;
459 : }
460 :
461 0 : bool ViewInformation2D::operator==(const ViewInformation2D& rCandidate) const
462 : {
463 0 : return rCandidate.mpViewInformation2D == mpViewInformation2D;
464 : }
465 :
466 7346 : const basegfx::B2DHomMatrix& ViewInformation2D::getObjectTransformation() const
467 : {
468 7346 : return mpViewInformation2D->getObjectTransformation();
469 : }
470 :
471 15105 : const basegfx::B2DHomMatrix& ViewInformation2D::getViewTransformation() const
472 : {
473 15105 : return mpViewInformation2D->getViewTransformation();
474 : }
475 :
476 54866 : const basegfx::B2DRange& ViewInformation2D::getViewport() const
477 : {
478 54866 : return mpViewInformation2D->getViewport();
479 : }
480 :
481 7127 : double ViewInformation2D::getViewTime() const
482 : {
483 7127 : return mpViewInformation2D->getViewTime();
484 : }
485 :
486 17133 : const uno::Reference< drawing::XDrawPage >& ViewInformation2D::getVisualizedPage() const
487 : {
488 17133 : return mpViewInformation2D->getVisualizedPage();
489 : }
490 :
491 120389 : const basegfx::B2DHomMatrix& ViewInformation2D::getObjectToViewTransformation() const
492 : {
493 120389 : return mpViewInformation2D->getObjectToViewTransformation();
494 : }
495 :
496 122953 : const basegfx::B2DHomMatrix& ViewInformation2D::getInverseObjectToViewTransformation() const
497 : {
498 122953 : return mpViewInformation2D->getInverseObjectToViewTransformation();
499 : }
500 :
501 5095 : const basegfx::B2DRange& ViewInformation2D::getDiscreteViewport() const
502 : {
503 5095 : return mpViewInformation2D->getDiscreteViewport();
504 : }
505 :
506 5 : bool ViewInformation2D::getReducedDisplayQuality() const
507 : {
508 5 : return mpViewInformation2D->getReducedDisplayQuality();
509 : }
510 :
511 0 : const uno::Sequence< beans::PropertyValue >& ViewInformation2D::getViewInformationSequence() const
512 : {
513 0 : return mpViewInformation2D->getViewInformationSequence();
514 : }
515 :
516 7127 : const uno::Sequence< beans::PropertyValue >& ViewInformation2D::getExtendedInformationSequence() const
517 : {
518 7127 : return mpViewInformation2D->getExtendedInformationSequence();
519 : }
520 : } // end of namespace geometry
521 : } // end of namespace drawinglayer
522 :
523 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|