tdf#150402 Correct wrong Bound of Shape in Slideshow

Added and use mbContainsPageField that gets set in
prepareHyperlinkIndices() which has to be run anyways,
so this will cause no change in execution speed.

It lets us detect the potential error case that a
PageField is contained in the Text of the Shape.
That is a hint that maBounds contains the wrong Range
and needs to be corrected.

For more backgrund information please refer to
tdf#150402, Comment 16.

Change-Id: Ifee01fffdb6e2f5915aa705afc7b5842781aae91
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140144
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
(cherry picked from commit 1b0ff1c166211b34370f53995ae9fb3f8eed182e)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140166
diff --git a/slideshow/source/engine/shapes/drawshape.cxx b/slideshow/source/engine/shapes/drawshape.cxx
index 22b65bf..000ffd2 100644
--- a/slideshow/source/engine/shapes/drawshape.cxx
+++ b/slideshow/source/engine/shapes/drawshape.cxx
@@ -366,7 +366,8 @@ namespace slideshow::internal
            mbIsVisible( true ),
            mbForceUpdate( false ),
            mbAttributeLayerRevoked( false ),
            mbDrawingLayerAnim( false )
            mbDrawingLayerAnim( false ),
            mbContainsPageField( false )
        {
            ENSURE_OR_THROW( mxShape.is(), "DrawShape::DrawShape(): Invalid XShape" );
            ENSURE_OR_THROW( mxPage.is(), "DrawShape::DrawShape(): Invalid containing page" );
@@ -391,6 +392,26 @@ namespace slideshow::internal
            maSubsetting.reset( mpCurrMtf );

            prepareHyperlinkIndices();

            if(mbContainsPageField && mpCurrMtf && !maBounds.isEmpty())
            {
                // tdf#150402 Use mbContainsPageField that gets set in prepareHyperlinkIndices
                // which has to be run anyways, so this will cause no harm in execution speed.
                // It lets us detect the potential error case that a PageField is contained in
                // the Text of the Shape. That is a hint that maBounds contains the wrong Range
                // and needs to be corrected. The correct size is in the PrefSize of the metafile.
                // For more backgrund information please refer to tdf#150402, Comment 16.
                const double fWidthDiff(fabs(mpCurrMtf->GetPrefSize().Width() - maBounds.getWidth()));
                const double fHeightDiff(fabs(mpCurrMtf->GetPrefSize().Height() - maBounds.getHeight()));

                if(fWidthDiff > 1.0 || fHeightDiff > 1.0)
                {
                    maBounds = basegfx::B2DRange(
                        maBounds.getMinX(), maBounds.getMinY(),
                        maBounds.getMinX() + mpCurrMtf->GetPrefSize().Width(),
                        maBounds.getMinY() + mpCurrMtf->GetPrefSize().Height());
                }
            }
        }

        DrawShape::DrawShape( const uno::Reference< drawing::XShape >&      xShape,
@@ -425,7 +446,8 @@ namespace slideshow::internal
            mbIsVisible( true ),
            mbForceUpdate( false ),
            mbAttributeLayerRevoked( false ),
            mbDrawingLayerAnim( false )
            mbDrawingLayerAnim( false ),
            mbContainsPageField( false )
        {
            ENSURE_OR_THROW( rGraphic.IsAnimated(),
                              "DrawShape::DrawShape(): Graphic is no animation" );
@@ -475,7 +497,8 @@ namespace slideshow::internal
            mbIsVisible( rSrc.mbIsVisible ),
            mbForceUpdate( false ),
            mbAttributeLayerRevoked( false ),
            mbDrawingLayerAnim( false )
            mbDrawingLayerAnim( false ),
            mbContainsPageField( false )
        {
            ENSURE_OR_THROW( mxShape.is(), "DrawShape::DrawShape(): Invalid XShape" );
            ENSURE_OR_THROW( mpCurrMtf, "DrawShape::DrawShape(): Invalid metafile" );
@@ -867,6 +890,10 @@ namespace slideshow::internal
                    {
                        maHyperlinkIndices.back().second = nIndex;
                    }
                    else if (pAct->GetComment().equalsIgnoreAsciiCase("FIELD_SEQ_BEGIN;PageField"))
                    {
                        mbContainsPageField = true;
                    }
                    ++nIndex;
                }
                else
diff --git a/slideshow/source/engine/shapes/drawshape.hxx b/slideshow/source/engine/shapes/drawshape.hxx
index eb9030a..8636a7a 100644
--- a/slideshow/source/engine/shapes/drawshape.hxx
+++ b/slideshow/source/engine/shapes/drawshape.hxx
@@ -349,6 +349,8 @@ namespace slideshow::internal
            /// whether a drawing layer animation has to be performed
            bool                                                                    mbDrawingLayerAnim;

            /// tdf#150402 wether mpCurrMtf contains any Text with a PageField ("FIELD_SEQ_BEGIN;PageField")
            mutable bool                                                            mbContainsPageField;
        };

}