diff options
Diffstat (limited to 'sd/source/ui/view/sdview4.cxx')
-rw-r--r-- | sd/source/ui/view/sdview4.cxx | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/sd/source/ui/view/sdview4.cxx b/sd/source/ui/view/sdview4.cxx index 0bf877f6fc02..3d804dff36e5 100644 --- a/sd/source/ui/view/sdview4.cxx +++ b/sd/source/ui/view/sdview4.cxx @@ -170,6 +170,8 @@ SdrGrafObj* View::InsertGraphic( const Graphic& rGraphic, sal_Int8& rAction, else if ( pPV ) { + Size aSizePixel = rGraphic.GetSizePixel(); + // create new object Size aSize; @@ -192,15 +194,34 @@ SdrGrafObj* View::InsertGraphic( const Graphic& rGraphic, sal_Int8& rAction, MapMode( MapUnit::Map100thMM ) ); } - pNewGrafObj = new SdrGrafObj( - getSdrModelFromSdrView(), - rGraphic, - ::tools::Rectangle(rPos, aSize)); - SdrPage* pPage = pPV->GetPage(); - Size aPageSize( pPage->GetSize() ); - aPageSize.AdjustWidth( -(pPage->GetLeftBorder() + pPage->GetRightBorder()) ); - aPageSize.AdjustHeight( -(pPage->GetUpperBorder() + pPage->GetLowerBorder()) ); - pNewGrafObj->AdjustToMaxRect( ::tools::Rectangle( Point(), aPageSize ), true ); + sal_Int32 nPreferredDPI = mrDoc.getImagePreferredDPI(); + if (nPreferredDPI > 0) + { + constexpr double fTwipsInAnInch = 1444.0; + auto nWidth = (aSizePixel.Width() / double(nPreferredDPI)) * fTwipsInAnInch; + auto nHeight = (aSizePixel.Height() / double(nPreferredDPI)) * fTwipsInAnInch; + nWidth = convertTwipToMm100(nWidth); + nHeight = convertTwipToMm100(nHeight); + + if (nWidth > 0 && nHeight > 0) + aSize = Size(nWidth, nHeight); + } + + pNewGrafObj = new SdrGrafObj(getSdrModelFromSdrView(), rGraphic, ::tools::Rectangle(rPos, aSize)); + + if (nPreferredDPI > 0) + { + // move to the center of insertion point + pNewGrafObj->NbcMove(Size(-aSize.Width() / 2, -aSize.Height() / 2)); + } + else + { + SdrPage* pPage = pPV->GetPage(); + Size aPageSize( pPage->GetSize() ); + aPageSize.AdjustWidth( -(pPage->GetLeftBorder() + pPage->GetRightBorder()) ); + aPageSize.AdjustHeight( -(pPage->GetUpperBorder() + pPage->GetLowerBorder()) ); + pNewGrafObj->AdjustToMaxRect( ::tools::Rectangle( Point(), aPageSize ), true ); + } SdrInsertFlags nOptions = SdrInsertFlags::SETDEFLAYER; bool bIsPresTarget = false; |