diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-12-03 20:52:12 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-01-05 10:04:19 +0100 |
commit | bfd5a99e775e94531e67d5cda97740e18d907019 (patch) | |
tree | e72da530f5a827871571e09be8113180cc0a497b /sw/source | |
parent | 7cb0a56499c80fb2db15220bcab51eb6cc6f707b (diff) |
Add image preffered DPI document setting, use it in Writer, Impress
This adds a "image preferred DPI" document setting, which is used
as a suggestion of the DPI that an image should have in the
document. This is currently used when the image is inserted into
the document (Writer, Impress/Draw) to resize it to the preferred
DPI value.
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126334
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 4c00e8fb10437fcaefe8635ef390b78376938d15)
Change-Id: I3ee9d409257e3c6aa2ead05144ecbba7b3b916f6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127238
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/doc/DocumentSettingManager.cxx | 3 | ||||
-rw-r--r-- | sw/source/core/inc/DocumentSettingManager.hxx | 9 | ||||
-rw-r--r-- | sw/source/uibase/uno/SwXDocumentSettings.cxx | 17 | ||||
-rw-r--r-- | sw/source/uibase/wrtsh/wrtsh1.cxx | 19 |
4 files changed, 45 insertions, 3 deletions
diff --git a/sw/source/core/doc/DocumentSettingManager.cxx b/sw/source/core/doc/DocumentSettingManager.cxx index 9b8b19f71e7f..2006d9aeb0a5 100644 --- a/sw/source/core/doc/DocumentSettingManager.cxx +++ b/sw/source/core/doc/DocumentSettingManager.cxx @@ -100,7 +100,8 @@ sw::DocumentSettingManager::DocumentSettingManager(SwDoc &rDoc) mbProtectFields(false), mbHeaderSpacingBelowLastPara(false), mbFrameAutowidthWithMorePara(false), - mbGutterAtTop(false) + mbGutterAtTop(false), + mnImagePreferredDPI(0) // COMPATIBILITY FLAGS END { diff --git a/sw/source/core/inc/DocumentSettingManager.hxx b/sw/source/core/inc/DocumentSettingManager.hxx index 88877b26458d..e78f0fc20405 100644 --- a/sw/source/core/inc/DocumentSettingManager.hxx +++ b/sw/source/core/inc/DocumentSettingManager.hxx @@ -170,6 +170,7 @@ class DocumentSettingManager : bool mbFrameAutowidthWithMorePara; //tdf#124423 /// Gutter position: false means left (not a compatibility setting). bool mbGutterAtTop; + sal_Int32 mnImagePreferredDPI; public: @@ -190,6 +191,14 @@ public: virtual CharCompressType getCharacterCompressionType() const override; virtual void setCharacterCompressionType( /*[in]*/CharCompressType nType ) override; + sal_Int32 getImagePreferredDPI() override + { + return mnImagePreferredDPI; + } + void setImagePreferredDPI(sal_Int32 nValue) override + { + mnImagePreferredDPI = nValue; + } // Replace all compatibility options with those from rSource. void ReplaceCompatibilityOptions(const DocumentSettingManager& rSource); diff --git a/sw/source/uibase/uno/SwXDocumentSettings.cxx b/sw/source/uibase/uno/SwXDocumentSettings.cxx index 2643071e13dd..5ba5293a5031 100644 --- a/sw/source/uibase/uno/SwXDocumentSettings.cxx +++ b/sw/source/uibase/uno/SwXDocumentSettings.cxx @@ -147,6 +147,7 @@ enum SwDocumentSettingsPropertyHandles HANDLE_HEADER_SPACING_BELOW_LAST_PARA, HANDLE_FRAME_AUTOWIDTH_WITH_MORE_PARA, HANDLE_GUTTER_AT_TOP, + HANDLE_IMAGE_PREFERRED_DPI, }; } @@ -241,6 +242,7 @@ static MasterPropertySetInfo * lcl_createSettingsInfo() { OUString("HeaderSpacingBelowLastPara"), HANDLE_HEADER_SPACING_BELOW_LAST_PARA, cppu::UnoType<bool>::get(), 0 }, { OUString("FrameAutowidthWithMorePara"), HANDLE_FRAME_AUTOWIDTH_WITH_MORE_PARA, cppu::UnoType<bool>::get(), 0 }, { OUString("GutterAtTop"), HANDLE_GUTTER_AT_TOP, cppu::UnoType<bool>::get(), 0 }, + { OUString("ImagePreferredDPI"), HANDLE_IMAGE_PREFERRED_DPI, cppu::UnoType<sal_Int32>::get(), 0 }, /* * As OS said, we don't have a view when we need to set this, so I have to @@ -1007,6 +1009,16 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf } } break; + case HANDLE_IMAGE_PREFERRED_DPI: + { + sal_uInt32 nValue = 0; + if (rValue >>= nValue) + { + mpDoc->getIDocumentSettingAccess().setImagePreferredDPI(nValue); + } + } + break; + default: throw UnknownPropertyException(OUString::number(rInfo.mnHandle)); } @@ -1508,6 +1520,11 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & rInf rValue <<= mpDoc->getIDocumentSettingAccess().get(DocumentSettingId::GUTTER_AT_TOP); } break; + case HANDLE_IMAGE_PREFERRED_DPI: + { + rValue <<= mpDoc->getIDocumentSettingAccess().getImagePreferredDPI(); + } + break; default: throw UnknownPropertyException(OUString::number(rInfo.mnHandle)); } diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index 5e888e2c2ef6..f6c5cbd195c1 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -301,8 +301,23 @@ void SwWrtShell::Insert( const OUString &rPath, const OUString &rFilter, if( bSetGrfSize ) { - Size aGrfSize, aBound = GetGraphicDefaultSize(); - GetGrfSize( aGrfSize ); + Size aSizePixel = rGrf.GetSizePixel(); + Size aBound = GetGraphicDefaultSize(); + + sal_Int32 nPreferredDPI = mxDoc->getIDocumentSettingAccess().getImagePreferredDPI(); + Size aGrfSize; + + if (nPreferredDPI > 0) + { + constexpr double fTwipsInAnInch = 1444.0; + auto nWidth = (aSizePixel.Width() / double(nPreferredDPI)) * fTwipsInAnInch; + auto nHeight = (aSizePixel.Height() / double(nPreferredDPI)) * fTwipsInAnInch; + aGrfSize = Size(nWidth, nHeight); + } + else + { + GetGrfSize(aGrfSize); + } // Add the margin attributes to GrfSize, // because these counts at the margin additionally |