diff options
author | Abhilash <abhilash300singh@gmail.com> | 2016-07-29 00:19:27 +0530 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2016-09-07 18:02:22 +0000 |
commit | 511acc66f543b0200ebe70cf072e5a8db8677809 (patch) | |
tree | 8486aa1aa6eb4885b45f9f5f4b79829d87ae19ae /sd/source | |
parent | 6323e6628668849438e6e19ba7ad2c6598263261 (diff) |
tdf#64575 Photo Album: Better Image Layout
Change-Id: I021c5fa921eb80edd996e0224e69e3b3d54b76d3
Reviewed-on: https://gerrit.libreoffice.org/27654
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'sd/source')
-rw-r--r-- | sd/source/ui/dlg/PhotoAlbumDialog.cxx | 49 | ||||
-rw-r--r-- | sd/source/ui/dlg/PhotoAlbumDialog.hxx | 2 |
2 files changed, 47 insertions, 4 deletions
diff --git a/sd/source/ui/dlg/PhotoAlbumDialog.cxx b/sd/source/ui/dlg/PhotoAlbumDialog.cxx index 9622b8c1acde..c1de735bb19e 100644 --- a/sd/source/ui/dlg/PhotoAlbumDialog.cxx +++ b/sd/source/ui/dlg/PhotoAlbumDialog.cxx @@ -55,6 +55,7 @@ SdPhotoAlbumDialog::SdPhotoAlbumDialog(vcl::Window* pWindow, SdDrawDocument* pAc get(pInsTypeCombo, "opt_combo"); get(pASRCheck, "asr_check"); + get(pASRCheckCrop, "asr_check_crop"); get(pCapCheck, "cap_check"); get(pInsertAsLinkCheck, "insert_as_link_check"); @@ -93,6 +94,7 @@ void SdPhotoAlbumDialog::dispose() pImg.clear(); pInsTypeCombo.clear(); pASRCheck.clear(); + pASRCheckCrop.clear(); pCapCheck.clear(); pInsertAsLinkCheck.clear(); ModalDialog::dispose(); @@ -163,15 +165,14 @@ IMPL_LINK_NOARG_TYPED(SdPhotoAlbumDialog, CreateHdl, Button*, void) ::awt::Point aPicPos; - if(pASRCheck->IsChecked()) + if(pASRCheck->IsChecked() && !pASRCheckCrop->IsChecked()) { // Resize the image, with keeping ASR aPicSize = createASRSize(aPicSize, aPageSize); } - else + else if(pASRCheckCrop->IsChecked()) { - aPicSize.Width = aPageSize.Width; - aPicSize.Height = aPageSize.Height; + aPicSize = createASRSizeCrop(aPicSize, aPageSize); } xShape->setSize(aPicSize); @@ -698,6 +699,46 @@ awt::Size SdPhotoAlbumDialog::createASRSize(const awt::Size& aPicSize, const awt return awt::Size(resizeWidth, resizeHeight); } +awt::Size SdPhotoAlbumDialog::createASRSizeCrop(const awt::Size& aPicSize, const awt::Size& aMaxSize) +{ + double resizeWidth = aPicSize.Width; + double resizeHeight = aPicSize.Height; + double imgAspect = resizeWidth / resizeHeight; + double windowAspectRatio = static_cast<double>(aMaxSize.Width) / aMaxSize.Height ; + + + //When both sides of an image are bigger than canvas size, image would be downscaled. + if( resizeWidth > aMaxSize.Width && resizeHeight > aMaxSize.Height ) + { + if( imgAspect > windowAspectRatio ) + { + resizeHeight = aMaxSize.Height; + resizeWidth = aMaxSize.Height * imgAspect; + } + else + { + resizeHeight = aMaxSize.Width / imgAspect; + resizeWidth = aMaxSize.Width; + } + + } + //In all other cases image is upscaled + else + { + if( imgAspect > windowAspectRatio ) + { + resizeHeight = aMaxSize.Height; + resizeWidth = aMaxSize.Height * imgAspect; + } + else + { + resizeWidth = aMaxSize.Width; + resizeHeight = aMaxSize.Width / imgAspect; + } + } + return awt::Size(resizeWidth, resizeHeight); +} + void SdPhotoAlbumDialog::createCaption(const awt::Size& aPageSize ) { Point CapPos; diff --git a/sd/source/ui/dlg/PhotoAlbumDialog.hxx b/sd/source/ui/dlg/PhotoAlbumDialog.hxx index dfdefb071938..cf8854a58fb8 100644 --- a/sd/source/ui/dlg/PhotoAlbumDialog.hxx +++ b/sd/source/ui/dlg/PhotoAlbumDialog.hxx @@ -65,6 +65,7 @@ private: VclPtr<ListBox> pInsTypeCombo; VclPtr<CheckBox> pASRCheck; + VclPtr<CheckBox> pASRCheckCrop; VclPtr<CheckBox> pCapCheck; VclPtr<CheckBox> pInsertAsLinkCheck; @@ -85,6 +86,7 @@ private: const Reference< drawing::XDrawPages >& xDrawPages); static awt::Size createASRSize(const awt::Size& aPicSize, const awt::Size& aMaxSize); + static awt::Size createASRSizeCrop(const awt::Size& aPicSize, const awt::Size& aMaxSize); void createCaption(const awt::Size& aPageSize); static Reference< graphic::XGraphic> createXGraphicFromUrl(const OUString& sUrl, const Reference< graphic::XGraphicProvider>& xProvider); |