diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-12-03 20:52:12 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-12-06 12:43:00 +0100 |
commit | 4c00e8fb10437fcaefe8635ef390b78376938d15 (patch) | |
tree | fd001904cf7640a13bd4a3ef3521f1c2db93fa4b /sd | |
parent | 30d6787b98131fce5a280f005b75e9d496f21573 (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.
Change-Id: I3ee9d409257e3c6aa2ead05144ecbba7b3b916f6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126334
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/inc/drawdoc.hxx | 5 | ||||
-rw-r--r-- | sd/source/core/drawdoc.cxx | 1 | ||||
-rw-r--r-- | sd/source/ui/unoidl/UnoDocumentSettings.cxx | 20 | ||||
-rw-r--r-- | sd/source/ui/view/sdview4.cxx | 35 |
4 files changed, 52 insertions, 9 deletions
diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx index 80a79955537f..aaed07cae960 100644 --- a/sd/inc/drawdoc.hxx +++ b/sd/inc/drawdoc.hxx @@ -187,6 +187,8 @@ private: bool mbEmbedFontScriptAsian : 1; bool mbEmbedFontScriptComplex : 1; + sal_Int32 mnImagePreferredDPI; + SAL_DLLPRIVATE virtual css::uno::Reference< css::uno::XInterface > createUnoModel() override; public: @@ -614,6 +616,9 @@ public: SAL_DLLPRIVATE void SetEmbedFontScriptAsian(bool bUse) { mbEmbedFontScriptAsian = bUse; } SAL_DLLPRIVATE void SetEmbedFontScriptComplex(bool bUse) { mbEmbedFontScriptComplex = bUse; } + sal_Int32 getImagePreferredDPI() { return mnImagePreferredDPI; } + void setImagePreferredDPI(sal_Int32 nValue) { mnImagePreferredDPI = nValue; } + void dumpAsXml(xmlTextWriterPtr pWriter) const override; private: diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx index 0fea961a6902..953afd909302 100644 --- a/sd/source/core/drawdoc.cxx +++ b/sd/source/core/drawdoc.cxx @@ -137,6 +137,7 @@ SdDrawDocument::SdDrawDocument(DocumentType eType, SfxObjectShell* pDrDocSh) , mbEmbedFontScriptLatin(true) , mbEmbedFontScriptAsian(true) , mbEmbedFontScriptComplex(true) +, mnImagePreferredDPI(0) { mpDrawPageListWatcher.reset(new ImpDrawPageListWatcher(*this)); mpMasterPageListWatcher.reset(new ImpMasterPageListWatcher(*this)); diff --git a/sd/source/ui/unoidl/UnoDocumentSettings.cxx b/sd/source/ui/unoidl/UnoDocumentSettings.cxx index ec168b7e42d6..2515ea32eecc 100644 --- a/sd/source/ui/unoidl/UnoDocumentSettings.cxx +++ b/sd/source/ui/unoidl/UnoDocumentSettings.cxx @@ -148,6 +148,7 @@ enum SdDocumentSettingsPropertyHandles ,HANDLE_SLIDESPERHANDOUT, HANDLE_HANDOUTHORIZONTAL, HANDLE_EMBED_FONTS, HANDLE_EMBED_USED_FONTS, HANDLE_EMBED_LATIN_SCRIPT_FONTS, HANDLE_EMBED_ASIAN_SCRIPT_FONTS, HANDLE_EMBED_COMPLEX_SCRIPT_FONTS, + HANDLE_IMAGE_PREFERRED_DPI }; } @@ -218,6 +219,7 @@ enum SdDocumentSettingsPropertyHandles { OUString("EmbedLatinScriptFonts"), HANDLE_EMBED_LATIN_SCRIPT_FONTS, cppu::UnoType<bool>::get(), 0, 0 }, { OUString("EmbedAsianScriptFonts"), HANDLE_EMBED_ASIAN_SCRIPT_FONTS, cppu::UnoType<bool>::get(), 0, 0 }, { OUString("EmbedComplexScriptFonts"), HANDLE_EMBED_COMPLEX_SCRIPT_FONTS, cppu::UnoType<bool>::get(), 0, 0 }, + { OUString("ImagePreferredDPI"), HANDLE_IMAGE_PREFERRED_DPI, cppu::UnoType<sal_Int32>::get(), 0, 0 }, { OUString(), 0, css::uno::Type(), 0, 0 } }; @@ -1032,6 +1034,18 @@ DocumentSettings::_setPropertyValues(const PropertyMapEntry** ppEntries, } break; + case HANDLE_IMAGE_PREFERRED_DPI: + { + if (pValues->has<sal_Int32>()) + { + auto nNewValue = pValues->get<sal_Int32>(); + bChanged = (pDoc->getImagePreferredDPI() != nNewValue); + pDoc->setImagePreferredDPI(nNewValue); + bOk = true; + } + } + break; + default: throw UnknownPropertyException( OUString::number((*ppEntries)->mnHandle), static_cast<cppu::OWeakObject*>(this)); } @@ -1306,6 +1320,12 @@ DocumentSettings::_getPropertyValues( } break; + case HANDLE_IMAGE_PREFERRED_DPI: + { + *pValue <<= pDoc->getImagePreferredDPI(); + } + break; + default: throw UnknownPropertyException( OUString::number((*ppEntries)->mnHandle), static_cast<cppu::OWeakObject*>(this)); } diff --git a/sd/source/ui/view/sdview4.cxx b/sd/source/ui/view/sdview4.cxx index 34b1bf322d50..80a653b7b9c8 100644 --- a/sd/source/ui/view/sdview4.cxx +++ b/sd/source/ui/view/sdview4.cxx @@ -172,6 +172,8 @@ SdrGrafObj* View::InsertGraphic( const Graphic& rGraphic, sal_Int8& rAction, else if ( pPV ) { + Size aSizePixel = rGraphic.GetSizePixel(); + // create new object Size aSize; @@ -194,15 +196,30 @@ SdrGrafObj* View::InsertGraphic( const Graphic& rGraphic, sal_Int8& rAction, MapMode( MapUnit::Map100thMM ) ); } - pNewGrafObj = new SdrGrafObj( - getSdrModelFromSdrView(), - rGraphic, - ::tools::Rectangle(rPos, aSize)); - SdrPage* pPage = pPV->GetPage(); - Size aPageSize( pPage->GetSize() ); - aPageSize.AdjustWidth( -(pPage->GetLeftBorder() + pPage->GetRightBorder()) ); - aPageSize.AdjustHeight( -(pPage->GetUpperBorder() + pPage->GetLowerBorder()) ); - pNewGrafObj->AdjustToMaxRect( ::tools::Rectangle( Point(), aPageSize ), true ); + sal_Int32 nPreferredDPI = mrDoc.getImagePreferredDPI(); + if (nPreferredDPI > 0) + { + auto nWidth = o3tl::convert(aSizePixel.Width() / double(nPreferredDPI), o3tl::Length::in, o3tl::Length::mm100); + auto nHeight = o3tl::convert(aSizePixel.Height() / double(nPreferredDPI), o3tl::Length::in, o3tl::Length::mm100); + if (nWidth > 0 && nHeight > 0) + aSize = Size(nWidth, nHeight); + } + + pNewGrafObj = new SdrGrafObj(getSdrModelFromSdrView(), rGraphic, ::tools::Rectangle(rPos, aSize)); + + if (nPreferredDPI > 0) + { + // move to the center of insertion point + pNewGrafObj->NbcMove(Size(-aSize.Width() / 2, -aSize.Height() / 2)); + } + else + { + SdrPage* pPage = pPV->GetPage(); + Size aPageSize( pPage->GetSize() ); + aPageSize.AdjustWidth( -(pPage->GetLeftBorder() + pPage->GetRightBorder()) ); + aPageSize.AdjustHeight( -(pPage->GetUpperBorder() + pPage->GetLowerBorder()) ); + pNewGrafObj->AdjustToMaxRect( ::tools::Rectangle( Point(), aPageSize ), true ); + } SdrInsertFlags nOptions = SdrInsertFlags::SETDEFLAYER; bool bIsPresTarget = false; |