Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / slideshow / source / engine / tools.cxx
blobde7030f80778464989ce4eb73c2d159a3dcbcf35
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 .
21 #include <comphelper/diagnose_ex.hxx>
22 #include <canvas/canvastools.hxx>
24 #include <math.h>
26 #include <com/sun/star/beans/NamedValue.hpp>
27 #include <com/sun/star/awt/Rectangle.hpp>
28 #include <com/sun/star/animations/ValuePair.hpp>
29 #include <com/sun/star/drawing/FillStyle.hpp>
30 #include <com/sun/star/drawing/LineStyle.hpp>
31 #include <com/sun/star/awt/FontSlant.hpp>
33 #include <basegfx/polygon/b2dpolygon.hxx>
34 #include <basegfx/polygon/b2dpolygontools.hxx>
35 #include <basegfx/range/b2drange.hxx>
36 #include <basegfx/vector/b2dvector.hxx>
37 #include <basegfx/vector/b2ivector.hxx>
38 #include <basegfx/matrix/b2dhommatrix.hxx>
39 #include <basegfx/numeric/ftools.hxx>
40 #include <basegfx/utils/lerp.hxx>
41 #include <basegfx/matrix/b2dhommatrixtools.hxx>
43 #include <cppcanvas/basegfxfactory.hxx>
45 #include <svtools/colorcfg.hxx>
47 #include <unoview.hxx>
48 #include <slideshowexceptions.hxx>
49 #include <smilfunctionparser.hxx>
50 #include <tools.hxx>
52 #include <limits>
55 using namespace ::com::sun::star;
57 namespace slideshow::internal
59 namespace
61 class NamedValueComparator
63 public:
64 explicit NamedValueComparator( const beans::NamedValue& rKey ) :
65 mrKey( rKey )
69 bool operator()( const beans::NamedValue& rValue ) const
71 return rValue.Name == mrKey.Name && rValue.Value == mrKey.Value;
74 private:
75 const beans::NamedValue& mrKey;
78 ::basegfx::B2DHomMatrix getAttributedShapeTransformation( const ::basegfx::B2DRectangle& rShapeBounds,
79 const ShapeAttributeLayerSharedPtr& pAttr )
81 ::basegfx::B2DHomMatrix aTransform;
82 const basegfx::B2DSize rSize(rShapeBounds.getRange().getX(), rShapeBounds.getRange().getY());
84 const double nShearX( pAttr->isShearXAngleValid() ?
85 pAttr->getShearXAngle() :
86 0.0 );
87 const double nShearY( pAttr->isShearYAngleValid() ?
88 pAttr->getShearYAngle() :
89 0.0 );
90 const double nRotation( pAttr->isRotationAngleValid() ?
91 basegfx::deg2rad(pAttr->getRotationAngle()) :
92 0.0 );
94 // scale, shear and rotation pivot point is the shape
95 // center - adapt origin accordingly
96 aTransform.translate( -0.5, -0.5 );
98 // ensure valid size (zero size will inevitably lead
99 // to a singular transformation matrix)
100 aTransform.scale( ::basegfx::pruneScaleValue(
101 rSize.getWidth() ),
102 ::basegfx::pruneScaleValue(
103 rSize.getHeight() ) );
105 const bool bNeedShearX( !::basegfx::fTools::equalZero(nShearX) );
106 const bool bNeedShearY( !::basegfx::fTools::equalZero(nShearY) );
107 const bool bNeedRotation( !::basegfx::fTools::equalZero(nRotation) );
109 if( bNeedRotation || bNeedShearX || bNeedShearY )
111 if( bNeedShearX )
112 aTransform.shearX( nShearX );
114 if( bNeedShearY )
115 aTransform.shearY( nShearY );
117 if( bNeedRotation )
118 aTransform.rotate( nRotation );
121 // move left, top corner back to position of the
122 // shape. Since we've already translated the
123 // center of the shape to the origin (the
124 // translate( -0.5, -0.5 ) above), translate to
125 // center of final shape position here.
126 aTransform.translate( rShapeBounds.getCenterX(),
127 rShapeBounds.getCenterY() );
129 return aTransform;
133 // Value extraction from Any
134 // =========================
136 /// extract unary double value from Any
137 bool extractValue( double& o_rValue,
138 const uno::Any& rSourceAny,
139 const ShapeSharedPtr& rShape,
140 const ::basegfx::B2DVector& rSlideBounds )
142 // try to extract numeric value (double, or smaller POD, like float or int)
143 if( rSourceAny >>= o_rValue)
145 // succeeded
146 return true;
149 // try to extract string
150 OUString aString;
151 if( !(rSourceAny >>= aString) )
152 return false; // nothing left to try
154 // parse the string into an ExpressionNode
157 // Parse string into ExpressionNode, eval node at time 0.0
158 o_rValue = (*SmilFunctionParser::parseSmilValue(
159 aString,
160 calcRelativeShapeBounds(rSlideBounds,
161 rShape->getBounds()) ))(0.0);
163 catch( ParseError& )
165 return false;
168 return true;
171 /// extract enum/constant group value from Any
172 bool extractValue( sal_Int32& o_rValue,
173 const uno::Any& rSourceAny,
174 const ShapeSharedPtr& /*rShape*/,
175 const ::basegfx::B2DVector& /*rSlideBounds*/ )
177 // try to extract numeric value (int, or smaller POD, like byte)
178 if( rSourceAny >>= o_rValue)
180 // succeeded
181 return true;
184 // okay, no plain int. Maybe one of the domain-specific enums?
185 drawing::FillStyle eFillStyle;
186 if( rSourceAny >>= eFillStyle )
188 o_rValue = sal::static_int_cast<sal_Int16>(eFillStyle);
190 // succeeded
191 return true;
194 drawing::LineStyle eLineStyle;
195 if( rSourceAny >>= eLineStyle )
197 o_rValue = sal::static_int_cast<sal_Int16>(eLineStyle);
199 // succeeded
200 return true;
203 awt::FontSlant eFontSlant;
204 if( rSourceAny >>= eFontSlant )
206 o_rValue = sal::static_int_cast<sal_Int16>(eFontSlant);
208 // succeeded
209 return true;
212 // nothing left to try. Failure
213 return false;
216 /// extract enum/constant group value from Any
217 bool extractValue( sal_Int16& o_rValue,
218 const uno::Any& rSourceAny,
219 const ShapeSharedPtr& rShape,
220 const ::basegfx::B2DVector& rSlideBounds )
222 sal_Int32 aValue;
223 if( !extractValue(aValue,rSourceAny,rShape,rSlideBounds) )
224 return false;
226 if( std::numeric_limits<sal_Int16>::max() < aValue ||
227 std::numeric_limits<sal_Int16>::min() > aValue )
229 return false;
232 o_rValue = static_cast<sal_Int16>(aValue);
234 return true;
237 /// extract color value from Any
238 bool extractValue( RGBColor& o_rValue,
239 const uno::Any& rSourceAny,
240 const ShapeSharedPtr& /*rShape*/,
241 const ::basegfx::B2DVector& /*rSlideBounds*/ )
243 // try to extract numeric value (double, or smaller POD, like float or int)
245 double nTmp = 0;
246 if( rSourceAny >>= nTmp )
248 sal_uInt32 aIntColor( static_cast< sal_uInt32 >(nTmp) );
250 // TODO(F2): Handle color values correctly, here
251 o_rValue = unoColor2RGBColor( aIntColor );
253 // succeeded
254 return true;
258 // try double sequence
260 uno::Sequence< double > aTmp;
261 if( rSourceAny >>= aTmp )
263 ENSURE_OR_THROW( aTmp.getLength() == 3,
264 "extractValue(): inappropriate length for RGB color value" );
266 o_rValue = RGBColor( aTmp[0], aTmp[1], aTmp[2] );
268 // succeeded
269 return true;
273 // try sal_Int32 sequence
275 uno::Sequence< sal_Int32 > aTmp;
276 if( rSourceAny >>= aTmp )
278 ENSURE_OR_THROW( aTmp.getLength() == 3,
279 "extractValue(): inappropriate length for RGB color value" );
281 // truncate to byte
282 o_rValue = RGBColor( ::cppcanvas::makeColor(
283 static_cast<sal_uInt8>(aTmp[0]),
284 static_cast<sal_uInt8>(aTmp[1]),
285 static_cast<sal_uInt8>(aTmp[2]),
286 255 ) );
288 // succeeded
289 return true;
293 // try sal_Int8 sequence
295 uno::Sequence< sal_Int8 > aTmp;
296 if( rSourceAny >>= aTmp )
298 ENSURE_OR_THROW( aTmp.getLength() == 3,
299 "extractValue(): inappropriate length for RGB color value" );
301 o_rValue = RGBColor( ::cppcanvas::makeColor( aTmp[0], aTmp[1], aTmp[2], 255 ) );
303 // succeeded
304 return true;
308 // try to extract string
309 OUString aString;
310 if( !(rSourceAny >>= aString) )
311 return false; // nothing left to try
313 // TODO(F2): Provide symbolic color values here
314 o_rValue = RGBColor( 0.5, 0.5, 0.5 );
316 return true;
319 /// extract color value from Any
320 bool extractValue( HSLColor& o_rValue,
321 const uno::Any& rSourceAny,
322 const ShapeSharedPtr& /*rShape*/,
323 const ::basegfx::B2DVector& /*rSlideBounds*/ )
325 // try double sequence
327 uno::Sequence< double > aTmp;
328 if( rSourceAny >>= aTmp )
330 ENSURE_OR_THROW( aTmp.getLength() == 3,
331 "extractValue(): inappropriate length for HSL color value" );
333 o_rValue = HSLColor( aTmp[0], aTmp[1], aTmp[2] );
335 // succeeded
336 return true;
340 // try sal_Int8 sequence
342 uno::Sequence< sal_Int8 > aTmp;
343 if( rSourceAny >>= aTmp )
345 ENSURE_OR_THROW( aTmp.getLength() == 3,
346 "extractValue(): inappropriate length for HSL color value" );
348 o_rValue = HSLColor( aTmp[0]*360.0/255.0, aTmp[1]/255.0, aTmp[2]/255.0 );
350 // succeeded
351 return true;
355 return false; // nothing left to try
358 /// extract plain string from Any
359 bool extractValue( OUString& o_rValue,
360 const uno::Any& rSourceAny,
361 const ShapeSharedPtr& /*rShape*/,
362 const ::basegfx::B2DVector& /*rSlideBounds*/ )
364 // try to extract string
365 return rSourceAny >>= o_rValue;
368 /// extract bool value from Any
369 bool extractValue( bool& o_rValue,
370 const uno::Any& rSourceAny,
371 const ShapeSharedPtr& /*rShape*/,
372 const ::basegfx::B2DVector& /*rSlideBounds*/ )
374 bool bTmp;
375 // try to extract bool value
376 if( rSourceAny >>= bTmp )
378 o_rValue = bTmp;
380 // succeeded
381 return true;
384 // try to extract string
385 OUString aString;
386 if( !(rSourceAny >>= aString) )
387 return false; // nothing left to try
389 // we also take the strings "true" and "false",
390 // as well as "on" and "off" here
391 if( aString.equalsIgnoreAsciiCase("true") ||
392 aString.equalsIgnoreAsciiCase("on") )
394 o_rValue = true;
395 return true;
397 if( aString.equalsIgnoreAsciiCase("false") ||
398 aString.equalsIgnoreAsciiCase("off") )
400 o_rValue = false;
401 return true;
404 // ultimately failed.
405 return false;
408 /// extract double 2-tuple from Any
409 bool extractValue( ::basegfx::B2DTuple& o_rPair,
410 const uno::Any& rSourceAny,
411 const ShapeSharedPtr& rShape,
412 const ::basegfx::B2DVector& rSlideBounds )
414 animations::ValuePair aPair;
416 if( !(rSourceAny >>= aPair) )
417 return false;
419 double nFirst;
420 if( !extractValue( nFirst, aPair.First, rShape, rSlideBounds ) )
421 return false;
423 double nSecond;
424 if( !extractValue( nSecond, aPair.Second, rShape, rSlideBounds ) )
425 return false;
427 o_rPair.setX( nFirst );
428 o_rPair.setY( nSecond );
430 return true;
433 bool findNamedValue( uno::Sequence< beans::NamedValue > const& rSequence,
434 const beans::NamedValue& rSearchKey )
436 return ::std::any_of( rSequence.begin(), rSequence.end(),
437 NamedValueComparator( rSearchKey ) );
440 basegfx::B2DRange calcRelativeShapeBounds( const basegfx::B2DVector& rPageSize,
441 const basegfx::B2DRange& rShapeBounds )
443 return basegfx::B2DRange( rShapeBounds.getMinX() / rPageSize.getX(),
444 rShapeBounds.getMinY() / rPageSize.getY(),
445 rShapeBounds.getMaxX() / rPageSize.getX(),
446 rShapeBounds.getMaxY() / rPageSize.getY() );
449 // TODO(F2): Currently, the positional attributes DO NOT mirror the XShape properties.
450 // First and foremost, this is because we must operate with the shape boundrect,
451 // not position and size (the conversion between logic rect, snap rect and boundrect
452 // are non-trivial for draw shapes, and I won't duplicate them here). Thus, shapes
453 // rotated on the page will still have 0.0 rotation angle, as the metafile
454 // representation fetched over the API is our default zero case.
456 ::basegfx::B2DHomMatrix getShapeTransformation( const ::basegfx::B2DRectangle& rShapeBounds,
457 const ShapeAttributeLayerSharedPtr& pAttr )
459 if( !pAttr )
461 const basegfx::B2DHomMatrix aTransform(basegfx::utils::createScaleTranslateB2DHomMatrix(
462 rShapeBounds.getWidth(), rShapeBounds.getHeight(),
463 rShapeBounds.getMinX(), rShapeBounds.getMinY()));
465 return aTransform;
467 else
469 return getAttributedShapeTransformation( rShapeBounds,
470 pAttr );
474 ::basegfx::B2DHomMatrix getSpriteTransformation( const ::basegfx::B2DVector& rPixelSize,
475 const ::basegfx::B2DVector& rOrigSize,
476 const ShapeAttributeLayerSharedPtr& pAttr )
478 ::basegfx::B2DHomMatrix aTransform;
480 if( pAttr )
482 const double nShearX( pAttr->isShearXAngleValid() ?
483 pAttr->getShearXAngle() :
484 0.0 );
485 const double nShearY( pAttr->isShearYAngleValid() ?
486 pAttr->getShearYAngle() :
487 0.0 );
488 const double nRotation( pAttr->isRotationAngleValid() ?
489 basegfx::deg2rad(pAttr->getRotationAngle()) :
490 0.0 );
492 // scale, shear and rotation pivot point is the
493 // sprite's pixel center - adapt origin accordingly
494 aTransform.translate( -0.5*rPixelSize.getX(),
495 -0.5*rPixelSize.getY() );
497 const ::basegfx::B2DSize aSize(
498 pAttr->isWidthValid() ? pAttr->getWidth() : rOrigSize.getX(),
499 pAttr->isHeightValid() ? pAttr->getHeight() : rOrigSize.getY() );
501 // ensure valid size (zero size will inevitably lead
502 // to a singular transformation matrix).
503 aTransform.scale( ::basegfx::pruneScaleValue(
504 aSize.getWidth() /
505 ::basegfx::pruneScaleValue(
506 rOrigSize.getX() ) ),
507 ::basegfx::pruneScaleValue(
508 aSize.getHeight() /
509 ::basegfx::pruneScaleValue(
510 rOrigSize.getY() ) ) );
512 const bool bNeedShearX( !::basegfx::fTools::equalZero(nShearX) );
513 const bool bNeedShearY( !::basegfx::fTools::equalZero(nShearY) );
514 const bool bNeedRotation( !::basegfx::fTools::equalZero(nRotation) );
516 if( bNeedRotation || bNeedShearX || bNeedShearY )
518 if( bNeedShearX )
519 aTransform.shearX( nShearX );
521 if( bNeedShearY )
522 aTransform.shearY( nShearY );
524 if( bNeedRotation )
525 aTransform.rotate( nRotation );
528 // move left, top corner back to original position of
529 // the sprite (we've translated the center of the
530 // sprite to the origin above).
531 aTransform.translate( 0.5*rPixelSize.getX(),
532 0.5*rPixelSize.getY() );
535 // return identity transform for un-attributed
536 // shapes. This renders the sprite as-is, in its
537 // document-supplied size.
538 return aTransform;
541 ::basegfx::B2DRectangle getShapeUpdateArea( const ::basegfx::B2DRectangle& rUnitBounds,
542 const ::basegfx::B2DHomMatrix& rShapeTransform,
543 const ShapeAttributeLayerSharedPtr& pAttr )
545 ::basegfx::B2DHomMatrix aTransform;
547 if( pAttr &&
548 pAttr->isCharScaleValid() &&
549 fabs(pAttr->getCharScale()) > 1.0 )
551 // enlarge shape bounds. Have to consider the worst
552 // case here (the text fully fills the shape)
554 const double nCharScale( pAttr->getCharScale() );
556 // center of scaling is the middle of the shape
557 aTransform.translate( -0.5, -0.5 );
558 aTransform.scale( nCharScale, nCharScale );
559 aTransform.translate( 0.5, 0.5 );
562 aTransform *= rShapeTransform;
564 ::basegfx::B2DRectangle aRes;
566 // apply shape transformation to unit rect
567 return ::canvas::tools::calcTransformedRectBounds(
568 aRes,
569 rUnitBounds,
570 aTransform );
573 ::basegfx::B2DRange getShapeUpdateArea( const ::basegfx::B2DRange& rUnitBounds,
574 const ::basegfx::B2DRange& rShapeBounds )
576 return ::basegfx::B2DRectangle(
577 basegfx::utils::lerp( rShapeBounds.getMinX(),
578 rShapeBounds.getMaxX(),
579 rUnitBounds.getMinX() ),
580 basegfx::utils::lerp( rShapeBounds.getMinY(),
581 rShapeBounds.getMaxY(),
582 rUnitBounds.getMinY() ),
583 basegfx::utils::lerp( rShapeBounds.getMinX(),
584 rShapeBounds.getMaxX(),
585 rUnitBounds.getMaxX() ),
586 basegfx::utils::lerp( rShapeBounds.getMinY(),
587 rShapeBounds.getMaxY(),
588 rUnitBounds.getMaxY() ) );
591 ::basegfx::B2DRectangle getShapePosSize( const ::basegfx::B2DRectangle& rOrigBounds,
592 const ShapeAttributeLayerSharedPtr& pAttr )
594 // an already empty shape bound need no further
595 // treatment. In fact, any changes applied below would
596 // actually remove the special empty state, thus, don't
597 // change!
598 if( !pAttr ||
599 rOrigBounds.isEmpty() )
601 return rOrigBounds;
603 else
605 // cannot use maBounds anymore, attributes might have been
606 // changed by now.
607 // Have to use absolute values here, as negative sizes
608 // (aka mirrored shapes) _still_ have the same bounds,
609 // only with mirrored content.
610 ::basegfx::B2DSize aSize;
611 aSize.setWidth( fabs( pAttr->isWidthValid() ?
612 pAttr->getWidth() :
613 rOrigBounds.getWidth() ) );
614 aSize.setHeight( fabs( pAttr->isHeightValid() ?
615 pAttr->getHeight() :
616 rOrigBounds.getHeight() ) );
618 ::basegfx::B2DPoint aPos;
619 aPos.setX( pAttr->isPosXValid() ?
620 pAttr->getPosX() :
621 rOrigBounds.getCenterX() );
622 aPos.setY( pAttr->isPosYValid() ?
623 pAttr->getPosY() :
624 rOrigBounds.getCenterY() );
626 // the positional attribute retrieved from the
627 // ShapeAttributeLayer actually denotes the _middle_
628 // of the shape (do it as the PPTs do...)
629 return ::basegfx::B2DRectangle(aPos - 0.5 * basegfx::B2DPoint(aSize),
630 aPos + 0.5 * basegfx::B2DPoint(aSize));
634 RGBColor unoColor2RGBColor( sal_Int32 nColor )
636 return RGBColor(
637 ::cppcanvas::makeColor(
638 // convert from API color to IntSRGBA color
639 // (0xAARRGGBB -> 0xRRGGBBAA)
640 static_cast< sal_uInt8 >( nColor >> 16U ),
641 static_cast< sal_uInt8 >( nColor >> 8U ),
642 static_cast< sal_uInt8 >( nColor ),
643 static_cast< sal_uInt8 >( nColor >> 24U ) ) );
646 sal_Int32 RGBAColor2UnoColor( ::cppcanvas::IntSRGBA aColor )
648 return ::cppcanvas::makeColorARGB(
649 // convert from IntSRGBA color to API color
650 // (0xRRGGBBAA -> 0xAARRGGBB)
651 static_cast< sal_uInt8 >(0),
652 ::cppcanvas::getRed(aColor),
653 ::cppcanvas::getGreen(aColor),
654 ::cppcanvas::getBlue(aColor));
657 void fillRect( const ::cppcanvas::CanvasSharedPtr& rCanvas,
658 const ::basegfx::B2DRectangle& rRect,
659 ::cppcanvas::IntSRGBA aFillColor )
661 const ::basegfx::B2DPolygon aPoly(
662 ::basegfx::utils::createPolygonFromRect( rRect ));
664 ::cppcanvas::PolyPolygonSharedPtr pPolyPoly(
665 ::cppcanvas::BaseGfxFactory::createPolyPolygon( rCanvas, aPoly ) );
667 if( pPolyPoly )
669 pPolyPoly->setRGBAFillColor( aFillColor );
670 pPolyPoly->draw();
674 void initSlideBackground( const ::cppcanvas::CanvasSharedPtr& rCanvas,
675 const ::basegfx::B2ISize& rSize )
677 ::cppcanvas::CanvasSharedPtr pCanvas( rCanvas->clone() );
679 // set transformation to identity (->device pixel)
680 pCanvas->setTransformation( ::basegfx::B2DHomMatrix() );
682 // #i42440# Fill the _full_ background in
683 // black. Since we had to extend the bitmap by one
684 // pixel, and the bitmap is initialized white,
685 // depending on the slide content a one pixel wide
686 // line will show to the bottom and the right.
687 fillRect( pCanvas,
688 ::basegfx::B2DRectangle( 0.0, 0.0,
689 rSize.getX(),
690 rSize.getY() ),
691 0x000000FFU );
693 // tdf#148884 in dark mode impress's auto text color assumes it will render against
694 // the DOCCOLOR by default, so leaving this as white gives white on white, this
695 // looks the simplest approach, propagate dark mode into slideshow mode instead
696 // of reformatting to render onto a white slideshow
697 svtools::ColorConfig aColorConfig;
698 Color aApplicationDocumentColor = aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor;
699 cppcanvas::IntSRGBA nCanvasColor = cppcanvas::makeColor(aApplicationDocumentColor.GetRed(),
700 aApplicationDocumentColor.GetGreen(),
701 aApplicationDocumentColor.GetBlue(),
702 0xFF);
704 // fill the bounds rectangle in DOCCOLOR (typically white).
705 // Subtract one pixel from both width and height, because the slide
706 // size is chosen one pixel larger than given by the drawing layer.
707 // This is because shapes with line style, that have the size of
708 // the slide would otherwise be cut off. OTOH, every other slide
709 // background (solid fill, gradient, bitmap) render one pixel less,
710 // thus revealing ugly white pixel to the right and the bottom.
711 fillRect( pCanvas,
712 ::basegfx::B2DRectangle( 0.0, 0.0,
713 rSize.getX()-1,
714 rSize.getY()-1 ),
715 nCanvasColor );
718 ::basegfx::B2DRectangle getAPIShapeBounds( const uno::Reference< drawing::XShape >& xShape )
720 uno::Reference< beans::XPropertySet > xPropSet( xShape,
721 uno::UNO_QUERY_THROW );
722 // read bound rect
723 awt::Rectangle aTmpRect;
724 if( !(xPropSet->getPropertyValue("BoundRect") >>= aTmpRect) )
726 ENSURE_OR_THROW( false,
727 "getAPIShapeBounds(): Could not get \"BoundRect\" property from shape" );
730 return ::basegfx::B2DRectangle( aTmpRect.X,
731 aTmpRect.Y,
732 aTmpRect.X+aTmpRect.Width,
733 aTmpRect.Y+aTmpRect.Height );
737 TODO(F1): When ZOrder someday becomes usable enable this
739 double getAPIShapePrio( const uno::Reference< drawing::XShape >& xShape )
741 uno::Reference< beans::XPropertySet > xPropSet( xShape,
742 uno::UNO_QUERY_THROW );
743 // read prio
744 sal_Int32 nPrio(0);
745 if( !(xPropSet->getPropertyValue(
746 OUString("ZOrder") ) >>= nPrio) )
748 ENSURE_OR_THROW( false,
749 "getAPIShapePrio(): Could not get \"ZOrder\" property from shape" );
752 // TODO(F2): Check and adapt the range of possible values here.
753 // Maybe we can also take the total number of shapes here
754 return nPrio / 65535.0;
758 basegfx::B2IVector getSlideSizePixel( const basegfx::B2DVector& rSlideSize,
759 const UnoViewSharedPtr& pView )
761 ENSURE_OR_THROW(pView, "getSlideSizePixel(): invalid view");
763 // determine transformed page bounds
764 const basegfx::B2DRange aRect( 0,0,
765 rSlideSize.getX(),
766 rSlideSize.getY() );
767 basegfx::B2DRange aTmpRect;
768 canvas::tools::calcTransformedRectBounds( aTmpRect,
769 aRect,
770 pView->getTransformation() );
772 // #i42440# Returned slide size is one pixel too small, as
773 // rendering happens one pixel to the right and below the
774 // actual bound rect.
775 return basegfx::B2IVector(
776 basegfx::fround( aTmpRect.getRange().getX() ) + 1,
777 basegfx::fround( aTmpRect.getRange().getY() ) + 1 );
781 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */