sd/inc/sdgrffilter.hxx | 1 sd/source/filter/grf/sdgrffilter.cxx | 85 +++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 32 deletions(-)
New commits: commit 844a97295444b30147ac484166353fba21c582c0 Author: rash419 <rashesh.pa...@collabora.com> AuthorDate: Wed Jun 7 11:25:00 2023 +0530 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Thu Jun 8 07:08:34 2023 +0200 tdf#155444 added support for multi image tiff file Signed-off-by: rash419 <rashesh.pa...@collabora.com> Change-Id: I188aebae9c853e87dc50ffda5b7d88228559a7c7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152693 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sd/inc/sdgrffilter.hxx b/sd/inc/sdgrffilter.hxx index dc9027f94ca3..28ce9de6dd29 100644 --- a/sd/inc/sdgrffilter.hxx +++ b/sd/inc/sdgrffilter.hxx @@ -34,6 +34,7 @@ public: bool Export() override; static void HandleGraphicFilterError(ErrCode nFilterError, ErrCode nStreamError); + static void InsertSdrGrafObj(Graphic pGraphic, SdPage* pPage); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/filter/grf/sdgrffilter.cxx b/sd/source/filter/grf/sdgrffilter.cxx index 71f9221ab055..693f297a19c6 100644 --- a/sd/source/filter/grf/sdgrffilter.cxx +++ b/sd/source/filter/grf/sdgrffilter.cxx @@ -156,50 +156,71 @@ bool SdGRFFilter::Import() if( mrDocument.GetPageCount() == 0 ) mrDocument.CreateFirstPages(); - SdPage* pPage = mrDocument.GetSdPage( 0, PageKind::Standard ); - Point aPos; - Size aPagSize( pPage->GetSize() ); - Size aGrfSize( OutputDevice::LogicToLogic( aGraphic.GetPrefSize(), - aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM))); - - aPagSize.AdjustWidth( -(pPage->GetLeftBorder() + pPage->GetRightBorder()) ); - aPagSize.AdjustHeight( -(pPage->GetUpperBorder() + pPage->GetLowerBorder()) ); - - // scale to fit page - if ( ( ( aGrfSize.Height() > aPagSize.Height() ) || ( aGrfSize.Width() > aPagSize.Width() ) ) && - aGrfSize.Height() && aPagSize.Height() ) + GfxLink aGfxLink = aGraphic.GetGfxLink(); + if( aGfxLink.GetType() == GfxLinkType::NativeTif && aGraphic.IsAnimated() ) { - double fGrfWH = static_cast<double>(aGrfSize.Width()) / aGrfSize.Height(); - double fWinWH = static_cast<double>(aPagSize.Width()) / aPagSize.Height(); - - // adjust graphic to page size (scales) - if( fGrfWH < fWinWH ) + Animation aAnim( aGraphic.GetAnimation() ); + const auto nImages = aAnim.Count(); + for (size_t i = 0; i < nImages - 1; ++i) { - aGrfSize.setWidth( static_cast<tools::Long>( aPagSize.Height() * fGrfWH ) ); - aGrfSize.setHeight( aPagSize.Height() ); + mrDocument.DuplicatePage(0); } - else if( fGrfWH > 0.F ) + for (size_t nPageIndex = 0; nPageIndex < nImages; ++nPageIndex) { - aGrfSize.setWidth( aPagSize.Width() ); - aGrfSize.setHeight( static_cast<tools::Long>( aPagSize.Width() / fGrfWH ) ); + Graphic pGraphic = aAnim.Get(nPageIndex).maBitmapEx; + SdPage* pPage = mrDocument.GetSdPage(nPageIndex, PageKind::Standard); + InsertSdrGrafObj(pGraphic, pPage); } } - - // set output rectangle for graphic - aPos.setX( ( ( aPagSize.Width() - aGrfSize.Width() ) >> 1 ) + pPage->GetLeftBorder() ); - aPos.setY( ( ( aPagSize.Height() - aGrfSize.Height() ) >> 1 ) + pPage->GetUpperBorder() ); - - pPage->InsertObject( - new SdrGrafObj( - pPage->getSdrModelFromSdrPage(), - aGraphic, - ::tools::Rectangle(aPos, aGrfSize))); + else + { + SdPage* pPage = mrDocument.GetSdPage(0, PageKind::Standard); + InsertSdrGrafObj(aGraphic, pPage); + } bRet = true; } return bRet; } +void SdGRFFilter::InsertSdrGrafObj(Graphic pGraphic, SdPage* pPage) +{ + Point aPos; + Size aPagSize(pPage->GetSize()); + Size aGrfSize(OutputDevice::LogicToLogic(pGraphic.GetPrefSize(), pGraphic.GetPrefMapMode(), + MapMode(MapUnit::Map100thMM))); + + aPagSize.AdjustWidth(-(pPage->GetLeftBorder() + pPage->GetRightBorder())); + aPagSize.AdjustHeight(-(pPage->GetUpperBorder() + pPage->GetLowerBorder())); + + // scale to fit page + if (((aGrfSize.Height() > aPagSize.Height()) || (aGrfSize.Width() > aPagSize.Width())) + && aGrfSize.Height() && aPagSize.Height()) + { + double fGrfWH = static_cast<double>(aGrfSize.Width()) / aGrfSize.Height(); + double fWinWH = static_cast<double>(aPagSize.Width()) / aPagSize.Height(); + + // adjust graphic to page size (scales) + if (fGrfWH < fWinWH) + { + aGrfSize.setWidth(static_cast<tools::Long>(aPagSize.Height() * fGrfWH)); + aGrfSize.setHeight(aPagSize.Height()); + } + else if (fGrfWH > 0.F) + { + aGrfSize.setWidth(aPagSize.Width()); + aGrfSize.setHeight(static_cast<tools::Long>(aPagSize.Width() / fGrfWH)); + } + } + + // set output rectangle for graphic + aPos.setX(((aPagSize.Width() - aGrfSize.Width()) >> 1) + pPage->GetLeftBorder()); + aPos.setY(((aPagSize.Height() - aGrfSize.Height()) >> 1) + pPage->GetUpperBorder()); + + pPage->InsertObject(new SdrGrafObj(pPage->getSdrModelFromSdrPage(), pGraphic, + ::tools::Rectangle(aPos, aGrfSize))); +} + bool SdGRFFilter::Export() { // SJ: todo: error handling, the GraphicExportFilter does not support proper errorhandling