diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-12-19 22:31:31 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-12-20 06:21:49 +0100 |
commit | e34067483ef78c1569641becfe99b79a97600aed (patch) | |
tree | 2878b9477b25623e19795fa02c446027aa439ee2 /cui/source | |
parent | 046e6cfa544d2ffd67fd29ba7dde41b495744618 (diff) |
Set the original size in crop dialog to preferred DPI calc. size
If we have the document setting preferred image size set, then
use that as the default DPI and recalcualte the logical image
size using the DPI and the size in pixels.
This is useful so we have the preferred DPI size as 100% in the
crop dialog, so we can adjust the size in relation to that value.
Change-Id: I50806f194032e228ee2cf56a39e5735a57358d46
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127096
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'cui/source')
-rw-r--r-- | cui/source/inc/grfpage.hxx | 3 | ||||
-rw-r--r-- | cui/source/tabpages/grfpage.cxx | 32 |
2 files changed, 28 insertions, 7 deletions
diff --git a/cui/source/inc/grfpage.hxx b/cui/source/inc/grfpage.hxx index 35653eaf6ade..2c7017a57189 100644 --- a/cui/source/inc/grfpage.hxx +++ b/cui/source/inc/grfpage.hxx @@ -56,6 +56,7 @@ class SvxGrfCropPage : public SfxTabPage tools::Long nOldWidth; tools::Long nOldHeight; bool bSetOrigSize; + sal_Int32 m_aPreferredDPI; SvxCropExample m_aExampleWN; @@ -92,7 +93,7 @@ class SvxGrfCropPage : public SfxTabPage void GraphicHasChanged(bool bFound); virtual void ActivatePage(const SfxItemSet& rSet) override; - static Size GetGrfOrigSize(const Graphic&); + Size GetGrfOrigSize(const Graphic& rGraphic); public: SvxGrfCropPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rSet); static std::unique_ptr<SfxTabPage> Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet ); diff --git a/cui/source/tabpages/grfpage.cxx b/cui/source/tabpages/grfpage.cxx index 8742044ab1c3..b83e0bbc0426 100644 --- a/cui/source/tabpages/grfpage.cxx +++ b/cui/source/tabpages/grfpage.cxx @@ -57,6 +57,7 @@ SvxGrfCropPage::SvxGrfCropPage(weld::Container* pPage, weld::DialogController* p , nOldWidth(0) , nOldHeight(0) , bSetOrigSize(false) + , m_aPreferredDPI(0) , m_xCropFrame(m_xBuilder->weld_widget("cropframe")) , m_xZoomConstRB(m_xBuilder->weld_radio_button("keepscale")) , m_xSizeConstRB(m_xBuilder->weld_radio_button("keepsize")) @@ -287,6 +288,11 @@ void SvxGrfCropPage::ActivatePage(const SfxItemSet& rSet) DBG_ASSERT( pPool, "Where is the pool?" ); #endif + if (!GetUserData().isEmpty()) + { + m_aPreferredDPI = GetUserData().toInt32(); + } + bSetOrigSize = false; // Size @@ -670,13 +676,27 @@ void SvxGrfCropPage::GraphicHasChanged( bool bFound ) Size SvxGrfCropPage::GetGrfOrigSize(const Graphic& rGrf) { - const MapMode aMapTwip( MapUnit::MapTwip ); - Size aSize( rGrf.GetPrefSize() ); - if( MapUnit::MapPixel == rGrf.GetPrefMapMode().GetMapUnit() ) - aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, aMapTwip); + Size aSize; + + if (m_aPreferredDPI > 0) + { + Size aPixelSize = rGrf.GetSizePixel(); + double fWidth = aPixelSize.Width() / double(m_aPreferredDPI); + double fHeight = aPixelSize.Height() / double(m_aPreferredDPI); + fWidth = o3tl::convert(fWidth, o3tl::Length::in, o3tl::Length::twip); + fHeight = o3tl::convert(fHeight, o3tl::Length::in, o3tl::Length::twip); + aSize = Size(fWidth, fHeight); + } else - aSize = OutputDevice::LogicToLogic( aSize, - rGrf.GetPrefMapMode(), aMapTwip ); + { + const MapMode aMapTwip( MapUnit::MapTwip ); + aSize = rGrf.GetPrefSize(); + if( MapUnit::MapPixel == rGrf.GetPrefMapMode().GetMapUnit() ) + aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, aMapTwip); + else + aSize = OutputDevice::LogicToLogic( aSize, + rGrf.GetPrefMapMode(), aMapTwip ); + } return aSize; } |