bump product version to 4.1.6.2
[LibreOffice.git] / slideshow / source / engine / tools.cxx
blobfac4bed6e1f5b7c3867d1be3459fa80625c58dfb
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 <canvas/debug.hxx>
22 #include <tools/diagnose_ex.h>
23 #include <canvas/canvastools.hxx>
25 #include <math.h>
27 #include <com/sun/star/beans/NamedValue.hpp>
28 #include <com/sun/star/awt/Rectangle.hpp>
29 #include <com/sun/star/animations/ValuePair.hpp>
30 #include <com/sun/star/drawing/FillStyle.hpp>
31 #include <com/sun/star/drawing/LineStyle.hpp>
32 #include <com/sun/star/awt/FontSlant.hpp>
34 #include <basegfx/polygon/b2dpolygon.hxx>
35 #include <basegfx/polygon/b2dpolygontools.hxx>
36 #include <basegfx/range/b2drange.hxx>
37 #include <basegfx/vector/b2dvector.hxx>
38 #include <basegfx/vector/b2ivector.hxx>
39 #include <basegfx/matrix/b2dhommatrix.hxx>
40 #include <basegfx/numeric/ftools.hxx>
41 #include <basegfx/tools/lerp.hxx>
42 #include <basegfx/matrix/b2dhommatrixtools.hxx>
44 #include <cppcanvas/basegfxfactory.hxx>
46 #include "unoview.hxx"
47 #include "smilfunctionparser.hxx"
48 #include "tools.hxx"
50 #include <limits>
53 using namespace ::com::sun::star;
55 namespace slideshow
57 namespace internal
59 namespace
61 class NamedValueStringComparator
63 public:
64 NamedValueStringComparator( const OUString& rSearchString ) :
65 mrSearchString( rSearchString )
69 bool operator()( const beans::NamedValue& rValue ) const
71 return rValue.Name == mrSearchString;
74 private:
75 const OUString& mrSearchString;
78 class NamedValueComparator
80 public:
81 NamedValueComparator( const beans::NamedValue& rKey ) :
82 mrKey( rKey )
86 bool operator()( const beans::NamedValue& rValue ) const
88 return rValue.Name == mrKey.Name && rValue.Value == mrKey.Value;
91 private:
92 const beans::NamedValue& mrKey;
95 ::basegfx::B2DHomMatrix getAttributedShapeTransformation( const ::basegfx::B2DRectangle& rShapeBounds,
96 const ShapeAttributeLayerSharedPtr& pAttr )
98 ::basegfx::B2DHomMatrix aTransform;
99 const ::basegfx::B2DSize& rSize( rShapeBounds.getRange() );
101 const double nShearX( pAttr->isShearXAngleValid() ?
102 pAttr->getShearXAngle() :
103 0.0 );
104 const double nShearY( pAttr->isShearYAngleValid() ?
105 pAttr->getShearYAngle() :
106 0.0 );
107 const double nRotation( pAttr->isRotationAngleValid() ?
108 pAttr->getRotationAngle()*M_PI/180.0 :
109 0.0 );
111 // scale, shear and rotation pivot point is the shape
112 // center - adapt origin accordingly
113 aTransform.translate( -0.5, -0.5 );
115 // ensure valid size (zero size will inevitably lead
116 // to a singular transformation matrix)
117 aTransform.scale( ::basegfx::pruneScaleValue(
118 rSize.getX() ),
119 ::basegfx::pruneScaleValue(
120 rSize.getY() ) );
122 const bool bNeedShearX( !::basegfx::fTools::equalZero(nShearX) );
123 const bool bNeedShearY( !::basegfx::fTools::equalZero(nShearY) );
124 const bool bNeedRotation( !::basegfx::fTools::equalZero(nRotation) );
126 if( bNeedRotation || bNeedShearX || bNeedShearY )
128 if( bNeedShearX )
129 aTransform.shearX( nShearX );
131 if( bNeedShearY )
132 aTransform.shearY( nShearY );
134 if( bNeedRotation )
135 aTransform.rotate( nRotation );
138 // move left, top corner back to position of the
139 // shape. Since we've already translated the
140 // center of the shape to the origin (the
141 // translate( -0.5, -0.5 ) above), translate to
142 // center of final shape position here.
143 aTransform.translate( rShapeBounds.getCenterX(),
144 rShapeBounds.getCenterY() );
146 return aTransform;
150 // Value extraction from Any
151 // =========================
153 /// extract unary double value from Any
154 bool extractValue( double& o_rValue,
155 const uno::Any& rSourceAny,
156 const ShapeSharedPtr& rShape,
157 const ::basegfx::B2DVector& rSlideBounds )
159 // try to extract numeric value (double, or smaller POD, like float or int)
160 if( (rSourceAny >>= o_rValue) )
162 // succeeded
163 return true;
166 // try to extract string
167 OUString aString;
168 if( !(rSourceAny >>= aString) )
169 return false; // nothing left to try
171 // parse the string into an ExpressionNode
174 // Parse string into ExpressionNode, eval node at time 0.0
175 o_rValue = (*SmilFunctionParser::parseSmilValue(
176 aString,
177 calcRelativeShapeBounds(rSlideBounds,
178 rShape->getBounds()) ))(0.0);
180 catch( ParseError& )
182 return false;
185 return true;
188 /// extract enum/constant group value from Any
189 bool extractValue( sal_Int32& o_rValue,
190 const uno::Any& rSourceAny,
191 const ShapeSharedPtr& /*rShape*/,
192 const ::basegfx::B2DVector& /*rSlideBounds*/ )
194 // try to extract numeric value (int, or smaller POD, like byte)
195 if( (rSourceAny >>= o_rValue) )
197 // succeeded
198 return true;
201 // okay, no plain int. Maybe one of the domain-specific enums?
202 drawing::FillStyle eFillStyle;
203 if( (rSourceAny >>= eFillStyle) )
205 o_rValue = sal::static_int_cast<sal_Int16>(eFillStyle);
207 // succeeded
208 return true;
211 drawing::LineStyle eLineStyle;
212 if( (rSourceAny >>= eLineStyle) )
214 o_rValue = sal::static_int_cast<sal_Int16>(eLineStyle);
216 // succeeded
217 return true;
220 awt::FontSlant eFontSlant;
221 if( (rSourceAny >>= eFontSlant) )
223 o_rValue = sal::static_int_cast<sal_Int16>(eFontSlant);
225 // succeeded
226 return true;
229 // nothing left to try. Failure
230 return false;
233 /// extract enum/constant group value from Any
234 bool extractValue( sal_Int16& o_rValue,
235 const uno::Any& rSourceAny,
236 const ShapeSharedPtr& rShape,
237 const ::basegfx::B2DVector& rSlideBounds )
239 sal_Int32 aValue;
240 if( !extractValue(aValue,rSourceAny,rShape,rSlideBounds) )
241 return false;
243 if( std::numeric_limits<sal_Int16>::max() < aValue ||
244 std::numeric_limits<sal_Int16>::min() > aValue )
246 return false;
249 o_rValue = static_cast<sal_Int16>(aValue);
251 return true;
254 /// extract color value from Any
255 bool extractValue( RGBColor& o_rValue,
256 const uno::Any& rSourceAny,
257 const ShapeSharedPtr& /*rShape*/,
258 const ::basegfx::B2DVector& /*rSlideBounds*/ )
260 // try to extract numeric value (double, or smaller POD, like float or int)
262 double nTmp = 0;
263 if( (rSourceAny >>= nTmp) )
265 sal_uInt32 aIntColor( static_cast< sal_uInt32 >(nTmp) );
267 // TODO(F2): Handle color values correctly, here
268 o_rValue = unoColor2RGBColor( aIntColor );
270 // succeeded
271 return true;
275 // try double sequence
277 uno::Sequence< double > aTmp;
278 if( (rSourceAny >>= aTmp) )
280 ENSURE_OR_THROW( aTmp.getLength() == 3,
281 "extractValue(): inappropriate length for RGB color value" );
283 o_rValue = RGBColor( aTmp[0], aTmp[1], aTmp[2] );
285 // succeeded
286 return true;
290 // try sal_Int32 sequence
292 uno::Sequence< sal_Int32 > aTmp;
293 if( (rSourceAny >>= aTmp) )
295 ENSURE_OR_THROW( aTmp.getLength() == 3,
296 "extractValue(): inappropriate length for RGB color value" );
298 // truncate to byte
299 o_rValue = RGBColor( ::cppcanvas::makeColor(
300 static_cast<sal_uInt8>(aTmp[0]),
301 static_cast<sal_uInt8>(aTmp[1]),
302 static_cast<sal_uInt8>(aTmp[2]),
303 255 ) );
305 // succeeded
306 return true;
310 // try sal_Int8 sequence
312 uno::Sequence< sal_Int8 > aTmp;
313 if( (rSourceAny >>= aTmp) )
315 ENSURE_OR_THROW( aTmp.getLength() == 3,
316 "extractValue(): inappropriate length for RGB color value" );
318 o_rValue = RGBColor( ::cppcanvas::makeColor( aTmp[0], aTmp[1], aTmp[2], 255 ) );
320 // succeeded
321 return true;
325 // try to extract string
326 OUString aString;
327 if( !(rSourceAny >>= aString) )
328 return false; // nothing left to try
330 // TODO(F2): Provide symbolic color values here
331 o_rValue = RGBColor( 0.5, 0.5, 0.5 );
333 return true;
336 /// extract color value from Any
337 bool extractValue( HSLColor& o_rValue,
338 const uno::Any& rSourceAny,
339 const ShapeSharedPtr& /*rShape*/,
340 const ::basegfx::B2DVector& /*rSlideBounds*/ )
342 // try double sequence
344 uno::Sequence< double > aTmp;
345 if( (rSourceAny >>= aTmp) )
347 ENSURE_OR_THROW( aTmp.getLength() == 3,
348 "extractValue(): inappropriate length for HSL color value" );
350 o_rValue = HSLColor( aTmp[0], aTmp[1], aTmp[2] );
352 // succeeded
353 return true;
357 // try sal_Int8 sequence
359 uno::Sequence< sal_Int8 > aTmp;
360 if( (rSourceAny >>= aTmp) )
362 ENSURE_OR_THROW( aTmp.getLength() == 3,
363 "extractValue(): inappropriate length for HSL color value" );
365 o_rValue = HSLColor( aTmp[0]*360.0/255.0, aTmp[1]/255.0, aTmp[2]/255.0 );
367 // succeeded
368 return true;
372 return false; // nothing left to try
375 /// extract plain string from Any
376 bool extractValue( OUString& o_rValue,
377 const uno::Any& rSourceAny,
378 const ShapeSharedPtr& /*rShape*/,
379 const ::basegfx::B2DVector& /*rSlideBounds*/ )
381 // try to extract string
382 if( !(rSourceAny >>= o_rValue) )
383 return false; // nothing left to try
385 return true;
388 /// extract bool value from Any
389 bool extractValue( bool& o_rValue,
390 const uno::Any& rSourceAny,
391 const ShapeSharedPtr& /*rShape*/,
392 const ::basegfx::B2DVector& /*rSlideBounds*/ )
394 sal_Bool nTmp = sal_Bool();
395 // try to extract bool value
396 if( (rSourceAny >>= nTmp) )
398 o_rValue = nTmp;
400 // succeeded
401 return true;
404 // try to extract string
405 OUString aString;
406 if( !(rSourceAny >>= aString) )
407 return false; // nothing left to try
409 // we also take the strings "true" and "false",
410 // as well as "on" and "off" here
411 if( aString.equalsIgnoreAsciiCase("true") ||
412 aString.equalsIgnoreAsciiCase("on") )
414 o_rValue = true;
415 return true;
417 if( aString.equalsIgnoreAsciiCase("false") ||
418 aString.equalsIgnoreAsciiCase("off") )
420 o_rValue = false;
421 return true;
424 // ultimately failed.
425 return false;
428 /// extract double 2-tuple from Any
429 bool extractValue( ::basegfx::B2DTuple& o_rPair,
430 const uno::Any& rSourceAny,
431 const ShapeSharedPtr& rShape,
432 const ::basegfx::B2DVector& rSlideBounds )
434 animations::ValuePair aPair;
436 if( !(rSourceAny >>= aPair) )
437 return false;
439 double nFirst;
440 if( !extractValue( nFirst, aPair.First, rShape, rSlideBounds ) )
441 return false;
443 double nSecond;
444 if( !extractValue( nSecond, aPair.Second, rShape, rSlideBounds ) )
445 return false;
447 o_rPair.setX( nFirst );
448 o_rPair.setY( nSecond );
450 return true;
453 bool findNamedValue( uno::Sequence< beans::NamedValue > const& rSequence,
454 const beans::NamedValue& rSearchKey )
456 const beans::NamedValue* pArray = rSequence.getConstArray();
457 const size_t nLen( rSequence.getLength() );
459 if( nLen == 0 )
460 return false;
462 const beans::NamedValue* pFound = ::std::find_if( pArray,
463 pArray + nLen,
464 NamedValueComparator( rSearchKey ) );
466 if( pFound == rSequence.getConstArray() + nLen )
467 return false;
469 return true;
472 basegfx::B2DRange calcRelativeShapeBounds( const basegfx::B2DVector& rPageSize,
473 const basegfx::B2DRange& rShapeBounds )
475 return basegfx::B2DRange( rShapeBounds.getMinX() / rPageSize.getX(),
476 rShapeBounds.getMinY() / rPageSize.getY(),
477 rShapeBounds.getMaxX() / rPageSize.getX(),
478 rShapeBounds.getMaxY() / rPageSize.getY() );
481 // TODO(F2): Currently, the positional attributes DO NOT mirror the XShape properties.
482 // First and foremost, this is because we must operate with the shape boundrect,
483 // not position and size (the conversion between logic rect, snap rect and boundrect
484 // are non-trivial for draw shapes, and I won't duplicate them here). Thus, shapes
485 // rotated on the page will still have 0.0 rotation angle, as the metafile
486 // representation fetched over the API is our default zero case.
488 ::basegfx::B2DHomMatrix getShapeTransformation( const ::basegfx::B2DRectangle& rShapeBounds,
489 const ShapeAttributeLayerSharedPtr& pAttr )
491 if( !pAttr )
493 const basegfx::B2DHomMatrix aTransform(basegfx::tools::createScaleTranslateB2DHomMatrix(
494 rShapeBounds.getWidth(), rShapeBounds.getHeight(),
495 rShapeBounds.getMinX(), rShapeBounds.getMinY()));
497 return aTransform;
499 else
501 return getAttributedShapeTransformation( rShapeBounds,
502 pAttr );
506 ::basegfx::B2DHomMatrix getSpriteTransformation( const ::basegfx::B2DVector& rPixelSize,
507 const ::basegfx::B2DVector& rOrigSize,
508 const ShapeAttributeLayerSharedPtr& pAttr )
510 ::basegfx::B2DHomMatrix aTransform;
512 if( pAttr )
514 const double nShearX( pAttr->isShearXAngleValid() ?
515 pAttr->getShearXAngle() :
516 0.0 );
517 const double nShearY( pAttr->isShearYAngleValid() ?
518 pAttr->getShearYAngle() :
519 0.0 );
520 const double nRotation( pAttr->isRotationAngleValid() ?
521 pAttr->getRotationAngle()*M_PI/180.0 :
522 0.0 );
524 // scale, shear and rotation pivot point is the
525 // sprite's pixel center - adapt origin accordingly
526 aTransform.translate( -0.5*rPixelSize.getX(),
527 -0.5*rPixelSize.getY() );
529 const ::basegfx::B2DSize aSize(
530 pAttr->isWidthValid() ? pAttr->getWidth() : rOrigSize.getX(),
531 pAttr->isHeightValid() ? pAttr->getHeight() : rOrigSize.getY() );
533 // ensure valid size (zero size will inevitably lead
534 // to a singular transformation matrix).
535 aTransform.scale( ::basegfx::pruneScaleValue(
536 aSize.getX() /
537 ::basegfx::pruneScaleValue(
538 rOrigSize.getX() ) ),
539 ::basegfx::pruneScaleValue(
540 aSize.getY() /
541 ::basegfx::pruneScaleValue(
542 rOrigSize.getY() ) ) );
544 const bool bNeedShearX( !::basegfx::fTools::equalZero(nShearX) );
545 const bool bNeedShearY( !::basegfx::fTools::equalZero(nShearY) );
546 const bool bNeedRotation( !::basegfx::fTools::equalZero(nRotation) );
548 if( bNeedRotation || bNeedShearX || bNeedShearY )
550 if( bNeedShearX )
551 aTransform.shearX( nShearX );
553 if( bNeedShearY )
554 aTransform.shearY( nShearY );
556 if( bNeedRotation )
557 aTransform.rotate( nRotation );
560 // move left, top corner back to original position of
561 // the sprite (we've translated the center of the
562 // sprite to the origin above).
563 aTransform.translate( 0.5*rPixelSize.getX(),
564 0.5*rPixelSize.getY() );
567 // return identity transform for un-attributed
568 // shapes. This renders the sprite as-is, in it's
569 // document-supplied size.
570 return aTransform;
573 ::basegfx::B2DRectangle getShapeUpdateArea( const ::basegfx::B2DRectangle& rUnitBounds,
574 const ::basegfx::B2DHomMatrix& rShapeTransform,
575 const ShapeAttributeLayerSharedPtr& pAttr )
577 ::basegfx::B2DHomMatrix aTransform;
579 if( pAttr &&
580 pAttr->isCharScaleValid() &&
581 fabs(pAttr->getCharScale()) > 1.0 )
583 // enlarge shape bounds. Have to consider the worst
584 // case here (the text fully fills the shape)
586 const double nCharScale( pAttr->getCharScale() );
588 // center of scaling is the middle of the shape
589 aTransform.translate( -0.5, -0.5 );
590 aTransform.scale( nCharScale, nCharScale );
591 aTransform.translate( 0.5, 0.5 );
594 aTransform *= rShapeTransform;
596 ::basegfx::B2DRectangle aRes;
598 // apply shape transformation to unit rect
599 return ::canvas::tools::calcTransformedRectBounds(
600 aRes,
601 rUnitBounds,
602 aTransform );
605 ::basegfx::B2DRange getShapeUpdateArea( const ::basegfx::B2DRange& rUnitBounds,
606 const ::basegfx::B2DRange& rShapeBounds )
608 return ::basegfx::B2DRectangle(
609 basegfx::tools::lerp( rShapeBounds.getMinX(),
610 rShapeBounds.getMaxX(),
611 rUnitBounds.getMinX() ),
612 basegfx::tools::lerp( rShapeBounds.getMinY(),
613 rShapeBounds.getMaxY(),
614 rUnitBounds.getMinY() ),
615 basegfx::tools::lerp( rShapeBounds.getMinX(),
616 rShapeBounds.getMaxX(),
617 rUnitBounds.getMaxX() ),
618 basegfx::tools::lerp( rShapeBounds.getMinY(),
619 rShapeBounds.getMaxY(),
620 rUnitBounds.getMaxY() ) );
623 ::basegfx::B2DRectangle getShapePosSize( const ::basegfx::B2DRectangle& rOrigBounds,
624 const ShapeAttributeLayerSharedPtr& pAttr )
626 // an already empty shape bound need no further
627 // treatment. In fact, any changes applied below would
628 // actually remove the special empty state, thus, don't
629 // change!
630 if( !pAttr ||
631 rOrigBounds.isEmpty() )
633 return rOrigBounds;
635 else
637 // cannot use maBounds anymore, attributes might have been
638 // changed by now.
639 // Have to use absolute values here, as negative sizes
640 // (aka mirrored shapes) _still_ have the same bounds,
641 // only with mirrored content.
642 ::basegfx::B2DSize aSize;
643 aSize.setX( fabs( pAttr->isWidthValid() ?
644 pAttr->getWidth() :
645 rOrigBounds.getWidth() ) );
646 aSize.setY( fabs( pAttr->isHeightValid() ?
647 pAttr->getHeight() :
648 rOrigBounds.getHeight() ) );
650 ::basegfx::B2DPoint aPos;
651 aPos.setX( pAttr->isPosXValid() ?
652 pAttr->getPosX() :
653 rOrigBounds.getCenterX() );
654 aPos.setY( pAttr->isPosYValid() ?
655 pAttr->getPosY() :
656 rOrigBounds.getCenterY() );
658 // the positional attribute retrieved from the
659 // ShapeAttributeLayer actually denotes the _middle_
660 // of the shape (do it as the PPTs do...)
661 return ::basegfx::B2DRectangle( aPos - 0.5*aSize,
662 aPos + 0.5*aSize );
666 RGBColor unoColor2RGBColor( sal_Int32 nColor )
668 return RGBColor(
669 ::cppcanvas::makeColor(
670 // convert from API color to IntSRGBA color
671 // (0xAARRGGBB -> 0xRRGGBBAA)
672 static_cast< sal_uInt8 >( nColor >> 16U ),
673 static_cast< sal_uInt8 >( nColor >> 8U ),
674 static_cast< sal_uInt8 >( nColor ),
675 static_cast< sal_uInt8 >( nColor >> 24U ) ) );
678 sal_Int32 RGBAColor2UnoColor( ::cppcanvas::Color::IntSRGBA aColor )
680 return ::cppcanvas::makeColorARGB(
681 // convert from IntSRGBA color to API color
682 // (0xRRGGBBAA -> 0xAARRGGBB)
683 static_cast< sal_uInt8 >(0),
684 ::cppcanvas::getRed(aColor),
685 ::cppcanvas::getGreen(aColor),
686 ::cppcanvas::getBlue(aColor));
689 void fillRect( const ::cppcanvas::CanvasSharedPtr& rCanvas,
690 const ::basegfx::B2DRectangle& rRect,
691 ::cppcanvas::Color::IntSRGBA aFillColor )
693 const ::basegfx::B2DPolygon aPoly(
694 ::basegfx::tools::createPolygonFromRect( rRect ));
696 ::cppcanvas::PolyPolygonSharedPtr pPolyPoly(
697 ::cppcanvas::BaseGfxFactory::getInstance().createPolyPolygon( rCanvas,
698 aPoly ) );
700 if( pPolyPoly )
702 pPolyPoly->setRGBAFillColor( aFillColor );
703 pPolyPoly->draw();
707 void initSlideBackground( const ::cppcanvas::CanvasSharedPtr& rCanvas,
708 const ::basegfx::B2ISize& rSize )
710 ::cppcanvas::CanvasSharedPtr pCanvas( rCanvas->clone() );
712 // set transformation to identitiy (->device pixel)
713 pCanvas->setTransformation( ::basegfx::B2DHomMatrix() );
715 // #i42440# Fill the _full_ background in
716 // black. Since we had to extend the bitmap by one
717 // pixel, and the bitmap is initialized white,
718 // depending on the slide content a one pixel wide
719 // line will show to the bottom and the right.
720 fillRect( pCanvas,
721 ::basegfx::B2DRectangle( 0.0, 0.0,
722 rSize.getX(),
723 rSize.getY() ),
724 0x000000FFU );
726 // fill the bounds rectangle in white. Subtract one pixel
727 // from both width and height, because the slide size is
728 // chosen one pixel larger than given by the drawing
729 // layer. This is because shapes with line style, that
730 // have the size of the slide would otherwise be cut
731 // off. OTOH, every other slide background (solid fill,
732 // gradient, bitmap) render one pixel less, thus revealing
733 // ugly white pixel to the right and the bottom.
734 fillRect( pCanvas,
735 ::basegfx::B2DRectangle( 0.0, 0.0,
736 rSize.getX()-1,
737 rSize.getY()-1 ),
738 0xFFFFFFFFU );
741 ::basegfx::B2DRectangle getAPIShapeBounds( const uno::Reference< drawing::XShape >& xShape )
743 uno::Reference< beans::XPropertySet > xPropSet( xShape,
744 uno::UNO_QUERY_THROW );
745 // read bound rect
746 awt::Rectangle aTmpRect;
747 if( !(xPropSet->getPropertyValue(
748 OUString("BoundRect") ) >>= aTmpRect) )
750 ENSURE_OR_THROW( false,
751 "getAPIShapeBounds(): Could not get \"BoundRect\" property from shape" );
754 return ::basegfx::B2DRectangle( aTmpRect.X,
755 aTmpRect.Y,
756 aTmpRect.X+aTmpRect.Width,
757 aTmpRect.Y+aTmpRect.Height );
761 TODO(F1): When ZOrder someday becomes usable enable this
763 double getAPIShapePrio( const uno::Reference< drawing::XShape >& xShape )
765 uno::Reference< beans::XPropertySet > xPropSet( xShape,
766 uno::UNO_QUERY_THROW );
767 // read prio
768 sal_Int32 nPrio(0);
769 if( !(xPropSet->getPropertyValue(
770 OUString("ZOrder") ) >>= nPrio) )
772 ENSURE_OR_THROW( false,
773 "getAPIShapePrio(): Could not get \"ZOrder\" property from shape" );
776 // TODO(F2): Check and adapt the range of possible values here.
777 // Maybe we can also take the total number of shapes here
778 return nPrio / 65535.0;
782 basegfx::B2IVector getSlideSizePixel( const basegfx::B2DVector& rSlideSize,
783 const UnoViewSharedPtr& pView )
785 ENSURE_OR_THROW(pView, "getSlideSizePixel(): invalid view");
787 // determine transformed page bounds
788 const basegfx::B2DRange aRect( 0,0,
789 rSlideSize.getX(),
790 rSlideSize.getY() );
791 basegfx::B2DRange aTmpRect;
792 canvas::tools::calcTransformedRectBounds( aTmpRect,
793 aRect,
794 pView->getTransformation() );
796 // #i42440# Returned slide size is one pixel too small, as
797 // rendering happens one pixel to the right and below the
798 // actual bound rect.
799 return basegfx::B2IVector(
800 basegfx::fround( aTmpRect.getRange().getX() ) + 1,
801 basegfx::fround( aTmpRect.getRange().getY() ) + 1 );
806 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */