summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-12-03 20:52:12 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-01-06 09:18:06 +0100
commit331b1fba6b1981a867678795e2fc38185bc0cac6 (patch)
tree3df59ac65f2d4e51aaa5797b05f3a44b2b2db599 /sw
parent4aedf0956fb6849781bfb5139b04d8ca0708acdc (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/+/127206 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/IDocumentSettingAccess.hxx3
-rw-r--r--sw/source/core/doc/DocumentSettingManager.cxx3
-rw-r--r--sw/source/core/inc/DocumentSettingManager.hxx9
-rw-r--r--sw/source/uibase/uno/SwXDocumentSettings.cxx17
-rw-r--r--sw/source/uibase/wrtsh/wrtsh1.cxx19
5 files changed, 48 insertions, 3 deletions
diff --git a/sw/inc/IDocumentSettingAccess.hxx b/sw/inc/IDocumentSettingAccess.hxx
index 287a12604850..4a223b6fb563 100644
--- a/sw/inc/IDocumentSettingAccess.hxx
+++ b/sw/inc/IDocumentSettingAccess.hxx
@@ -242,6 +242,9 @@ enum class DocumentSettingId
*/
virtual void Setn32DummyCompatibilityOptions2( const sal_uInt32 CompatibilityOptions2 ) = 0;
+ virtual sal_Int32 getImagePreferredDPI() = 0;
+ virtual void setImagePreferredDPI(sal_Int32 nValue) = 0;
+
protected:
virtual ~IDocumentSettingAccess() {};
};
diff --git a/sw/source/core/doc/DocumentSettingManager.cxx b/sw/source/core/doc/DocumentSettingManager.cxx
index e69d50d123e6..afabba5c5215 100644
--- a/sw/source/core/doc/DocumentSettingManager.cxx
+++ b/sw/source/core/doc/DocumentSettingManager.cxx
@@ -95,7 +95,8 @@ sw::DocumentSettingManager::DocumentSettingManager(SwDoc &rDoc)
mbLastBrowseMode( false ),
mbDisableOffPagePositioning ( false ),
mbHeaderSpacingBelowLastPara(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 6b65839259d7..1e34319e56b4 100644
--- a/sw/source/core/inc/DocumentSettingManager.hxx
+++ b/sw/source/core/inc/DocumentSettingManager.hxx
@@ -166,6 +166,7 @@ class DocumentSettingManager :
bool mbHeaderSpacingBelowLastPara;
/// Gutter position: false means left (not a compatibility setting).
bool mbGutterAtTop;
+ sal_Int32 mnImagePreferredDPI;
public:
@@ -186,6 +187,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 b33be85354f2..458123d88871 100644
--- a/sw/source/uibase/uno/SwXDocumentSettings.cxx
+++ b/sw/source/uibase/uno/SwXDocumentSettings.cxx
@@ -148,6 +148,7 @@ enum SwDocumentSettingsPropertyHandles
HANDLE_CONTINUOUS_ENDNOTES,
HANDLE_HEADER_SPACING_BELOW_LAST_PARA,
HANDLE_GUTTER_AT_TOP,
+ HANDLE_IMAGE_PREFERRED_DPI,
};
static MasterPropertySetInfo * lcl_createSettingsInfo()
@@ -237,6 +238,7 @@ static MasterPropertySetInfo * lcl_createSettingsInfo()
{ OUString("ContinuousEndnotes"), HANDLE_CONTINUOUS_ENDNOTES, cppu::UnoType<bool>::get(), 0 },
{ OUString("HeaderSpacingBelowLastPara"), HANDLE_HEADER_SPACING_BELOW_LAST_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
@@ -977,6 +979,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));
}
@@ -1460,6 +1472,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 077a1b5f2968..87e33096ffa5 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -344,8 +344,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