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 | 7 +++++++ 7 files changed, 47 insertions(+), 8 deletions(-)
New commits: commit ab63ad95c1538a0d03961cebfb0ffc77b6925d69 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sun Dec 19 22:31:31 2021 +0900 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Jan 6 09:19:17 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/+/127208 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 afdc7cb6ba6f..922126a1b6b7 100644 --- a/cui/source/inc/grfpage.hxx +++ b/cui/source/inc/grfpage.hxx @@ -57,6 +57,7 @@ class SvxGrfCropPage : public SfxTabPage long nOldWidth; long nOldHeight; bool bSetOrigSize; + sal_Int32 m_aPreferredDPI; SvxCropExample m_aExampleWN; @@ -93,7 +94,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 091ef70faddf..aca4dd392bf0 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 @@ -664,13 +669,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 d5522a0cd253..13ac3ab90173 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> @@ -177,6 +178,8 @@ private: const SfxItemSet* pSet; OUString aUserString; bool bHasExchangeSupport; + std::unordered_map<OString, css::uno::Any> maAdditionalProperties; + std::unique_ptr< TabPageImpl > pImpl; protected: @@ -238,6 +241,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 62980f1f000a..2d7d6a12248f 100644 --- a/include/svx/svdmodel.hxx +++ b/include/svx/svdmodel.hxx @@ -604,6 +604,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 79f9ea901da8..e560a6925210 100644 --- a/sd/inc/drawdoc.hxx +++ b/sd/inc/drawdoc.hxx @@ -628,7 +628,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 b321e0799f92..f0768d48b3cc 100644 --- a/svx/source/tbxctrls/grafctrl.cxx +++ b/svx/source/tbxctrls/grafctrl.cxx @@ -714,6 +714,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 ca59c421b394..d591cef7b264 100644 --- a/sw/source/ui/frmdlg/frmdlg.cxx +++ b/sw/source/ui/frmdlg/frmdlg.cxx @@ -32,6 +32,7 @@ #include <wrap.hxx> #include <column.hxx> #include <macassgn.hxx> +#include <IDocumentSettingAccess.hxx> #include <globals.hrc> #include <strings.hrc> @@ -194,6 +195,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: */