cui/source/inc/grfpage.hxx | 3 ++- cui/source/tabpages/grfpage.cxx | 31 +++++++++++++++++++++++++------ include/sfx2/tabdlg.hxx | 8 ++++++++ include/svx/svdmodel.hxx | 2 ++ sd/inc/drawdoc.hxx | 2 +- svx/source/tbxctrls/grafctrl.cxx | 2 ++ sw/source/ui/frmdlg/frmdlg.cxx | 8 ++++++++ 7 files changed, 48 insertions(+), 8 deletions(-)
New commits: commit 5f25ea47a7c98956189d4239d617094f0a34ccca Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sun Dec 19 22:31:31 2021 +0900 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Jan 5 10:13:59 2022 +0100 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. This adds to SfxTabPage a new member maAdditionalProperties, to make it easier to transfer additional properties into a tab page. This is then used to transfer the preferred DPI into the tab page, which was previously done by user data, which is less than ideal and always doesn't work. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127096 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit e34067483ef78c1569641becfe99b79a97600aed) Change-Id: I50806f194032e228ee2cf56a39e5735a57358d46 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127240 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> 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 707c954703e2..7567e9d3370b 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,10 @@ void SvxGrfCropPage::ActivatePage(const SfxItemSet& rSet) DBG_ASSERT( pPool, "Where is the pool?" ); #endif + auto& aProperties = getAdditionalProperties(); + if (aProperties.find("PreferredDPI") != aProperties.end()) + m_aPreferredDPI = aProperties.at("PreferredDPI").get<sal_Int32>(); + bSetOrigSize = false; // Size @@ -668,13 +673,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 = fWidth * 1440.0; + fHeight = fHeight * 1440.0; + 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; } diff --git a/include/sfx2/tabdlg.hxx b/include/sfx2/tabdlg.hxx index 50f378d14dc4..6f2b3908852f 100644 --- a/include/sfx2/tabdlg.hxx +++ b/include/sfx2/tabdlg.hxx @@ -20,6 +20,7 @@ #define INCLUDED_SFX2_TABDLG_HXX #include <memory> +#include <unordered_map> #include <sal/config.h> #include <sfx2/dllapi.h> #include <sfx2/basedlgs.hxx> @@ -180,6 +181,8 @@ private: const SfxItemSet* pSet; OUString aUserString; bool bHasExchangeSupport; + std::unordered_map<OString, css::uno::Any> maAdditionalProperties; + std::unique_ptr< TabPageImpl > pImpl; protected: @@ -241,6 +244,11 @@ public: bool IsVisible() const { return m_xContainer->get_visible(); } weld::Window* GetFrameWeld() const; + + std::unordered_map<OString, css::uno::Any>& getAdditionalProperties() + { + return maAdditionalProperties; + } }; #endif diff --git a/include/svx/svdmodel.hxx b/include/svx/svdmodel.hxx index 6f4581d1618a..bf1da119351b 100644 --- a/include/svx/svdmodel.hxx +++ b/include/svx/svdmodel.hxx @@ -603,6 +603,8 @@ public: bool DoesMakePageObjectsNamesUnique() const { return mbMakePageObjectsNamesUnique; } void DoMakePageObjectsNamesUnique(bool bDo) { mbMakePageObjectsNamesUnique = bDo; } + virtual sal_Int32 getImagePreferredDPI() const { return 0; } + virtual void dumpAsXml(xmlTextWriterPtr pWriter) const; }; diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx index 8b65b4d18870..5744a68fe66e 100644 --- a/sd/inc/drawdoc.hxx +++ b/sd/inc/drawdoc.hxx @@ -614,7 +614,7 @@ public: SAL_DLLPRIVATE void SetEmbedFontScriptAsian(bool bUse) { mbEmbedFontScriptAsian = bUse; } SAL_DLLPRIVATE void SetEmbedFontScriptComplex(bool bUse) { mbEmbedFontScriptComplex = bUse; } - sal_Int32 getImagePreferredDPI() { return mnImagePreferredDPI; } + sal_Int32 getImagePreferredDPI() const override { return mnImagePreferredDPI; } void setImagePreferredDPI(sal_Int32 nValue) { mnImagePreferredDPI = nValue; } void dumpAsXml(xmlTextWriterPtr pWriter) const override; diff --git a/svx/source/tbxctrls/grafctrl.cxx b/svx/source/tbxctrls/grafctrl.cxx index 10fc939395c3..f5dbb6620f57 100644 --- a/svx/source/tbxctrls/grafctrl.cxx +++ b/svx/source/tbxctrls/grafctrl.cxx @@ -658,6 +658,8 @@ void SvxGrafAttrHelper::ExecuteGrafAttr( SfxRequest& rReq, SdrView& rView ) SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( RID_SVXPAGE_GRFCROP ); std::unique_ptr<SfxTabPage> xTabPage = (*fnCreatePage)(aCropDialog.get_content_area(), &aCropDialog, &aCropDlgAttr); + sal_Int32 nPreferredDPI = rView.getSdrModelFromSdrView().getImagePreferredDPI(); + xTabPage->getAdditionalProperties().emplace("PreferredDPI", css::uno::makeAny(nPreferredDPI)); xTabPage->SetPageTitle(aCropStr); aCropDialog.SetTabPage(std::move(xTabPage)); diff --git a/sw/source/ui/frmdlg/frmdlg.cxx b/sw/source/ui/frmdlg/frmdlg.cxx index f2f13a682166..e487a7a4abad 100644 --- a/sw/source/ui/frmdlg/frmdlg.cxx +++ b/sw/source/ui/frmdlg/frmdlg.cxx @@ -31,6 +31,8 @@ #include <wrap.hxx> #include <column.hxx> #include <macassgn.hxx> +#include <doc.hxx> +#include <IDocumentSettingAccess.hxx> #include <strings.hrc> #include <svl/eitem.hxx> @@ -189,6 +191,12 @@ void SwFrameDlg::PageCreated(const OString& rId, SfxTabPage &rPage) { rPage.PageCreated(m_rSet); } + else if (rId == "crop") + { + sal_Int32 nPreferredDPI = m_pWrtShell->GetDoc()->getIDocumentSettingAccess().getImagePreferredDPI(); + if (nPreferredDPI) + rPage.getAdditionalProperties().emplace("PreferredDPI", css::uno::makeAny(nPreferredDPI)); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */