diff options
author | Tibor Nagy <tibor.nagy.extern@allotropia.de> | 2024-12-11 06:46:33 +0100 |
---|---|---|
committer | Nagy Tibor <tibor.nagy.extern@allotropia.de> | 2024-12-11 15:58:43 +0100 |
commit | 77454306e200a3936f9d33d0dbab349dac3c72f7 (patch) | |
tree | 8cb41f26f8e13281bef959a0ece7c28936497e74 | |
parent | e5bc823ad47872cda353ae5965dc8a6e793128a7 (diff) |
tdf#161541 sd: fix the orientation of handouts on the printed page
Change-Id: I1896674ab317fcbcfe2ebbe9ea21dcc36c203328
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178274
Reviewed-by: Nagy Tibor <tibor.nagy.extern@allotropia.de>
Tested-by: Jenkins
(cherry picked from commit cc65bec38ca26265ce8ecfd02110c26bcc62b79b)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178310
Tested-by: allotropia jenkins <jenkins@allotropia.de>
-rw-r--r-- | sd/inc/sdpage.hxx | 2 | ||||
-rw-r--r-- | sd/source/core/sdpage.cxx | 266 | ||||
-rw-r--r-- | sd/source/ui/view/DocumentRenderer.cxx | 45 | ||||
-rw-r--r-- | vcl/source/window/printdlg.cxx | 25 |
4 files changed, 150 insertions, 188 deletions
diff --git a/sd/inc/sdpage.hxx b/sd/inc/sdpage.hxx index b0cb6f105c46..9e5a2e040034 100644 --- a/sd/inc/sdpage.hxx +++ b/sd/inc/sdpage.hxx @@ -349,7 +349,7 @@ public: ::tools::Rectangle GetTitleRect() const; ::tools::Rectangle GetLayoutRect() const; - static void CalculateHandoutAreas( SdDrawDocument& rModel, AutoLayout eLayout, bool bHorizontal, std::vector< ::tools::Rectangle >& rAreas ); + static void CalculateHandoutAreas( SdDrawDocument& rModel, AutoLayout eLayout, bool bHorizontal, std::vector< ::tools::Rectangle >& rAreas, Orientation eOrient ); /** Set the "precious" flag to the given value. */ diff --git a/sd/source/core/sdpage.cxx b/sd/source/core/sdpage.cxx index 1705e7bd4ee7..b79ae78873e5 100644 --- a/sd/source/core/sdpage.cxx +++ b/sd/source/core/sdpage.cxx @@ -840,7 +840,9 @@ void SdPage::CreateTitleAndLayout(bool bInit, bool bCreate ) } std::vector< ::tools::Rectangle > aAreas; - CalculateHandoutAreas( static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()), pMasterPage->GetAutoLayout(), false, aAreas ); + CalculateHandoutAreas(static_cast<SdDrawDocument&>(getSdrModelFromSdrPage()), + pMasterPage->GetAutoLayout(), false, aAreas, + pMasterPage->GetOrientation()); const bool bSkip = pMasterPage->GetAutoLayout() == AUTOLAYOUT_HANDOUT3; std::vector< ::tools::Rectangle >::iterator iter( aAreas.begin() ); @@ -2919,7 +2921,8 @@ bool SdPage::RestoreDefaultText( SdrObject* pObj ) return bRet; } -void SdPage::CalculateHandoutAreas( SdDrawDocument& rModel, AutoLayout eLayout, bool bHorizontal, std::vector< ::tools::Rectangle >& rAreas ) +void SdPage::CalculateHandoutAreas(SdDrawDocument& rModel, AutoLayout eLayout, bool bHorizontal, + std::vector<::tools::Rectangle>& rAreas, Orientation eOrient) { SdPage& rHandoutMaster = *rModel.GetMasterSdPage( 0, PageKind::Handout ); @@ -2935,182 +2938,145 @@ void SdPage::CalculateHandoutAreas( SdDrawDocument& rModel, AutoLayout eLayout, const sal_uInt16* pOffsets = aOffsets[0]; Size aArea = rHandoutMaster.GetSize(); - const bool bLandscape = aArea.Width() > aArea.Height(); + const bool bLandscape = aArea.Width() > aArea.Height() || eOrient == Orientation::Landscape; - if( eLayout == AUTOLAYOUT_NONE ) + if ((eOrient == Orientation::Landscape && aArea.Width() < aArea.Height()) + || (eOrient == Orientation::Portrait && aArea.Width() > aArea.Height())) { - // use layout from handout master - SdrObjListIter aShapeIter(&rHandoutMaster); + ::tools::Long nTmp = aArea.Width(); + aArea.setWidth(aArea.Height()); + aArea.setHeight(nTmp); + } - std::vector< ::tools::Rectangle > vSlidesAreas; - while ( aShapeIter.IsMore() ) - { - SdrPageObj* pPageObj = dynamic_cast<SdrPageObj*>( aShapeIter.Next() ); - // get slide rectangles - if (pPageObj) - vSlidesAreas.push_back( pPageObj->GetCurrentBoundRect() ); - } + if (eLayout == AUTOLAYOUT_NONE) + eLayout = rHandoutMaster.GetAutoLayout(); - if ( !bHorizontal || vSlidesAreas.size() < 4 ) - { // top to bottom, then right - rAreas.swap( vSlidesAreas ); - } - else - { // left to right, then down - switch ( vSlidesAreas.size() ) - { - case 4: - pOffsets = aOffsets[2]; - break; + const ::tools::Long nGapW = 1000; // gap is 1cm + const ::tools::Long nGapH = 1000; - default: - [[fallthrough]]; - case 6: - pOffsets = aOffsets[ bLandscape ? 3 : 1 ]; - break; + ::tools::Long nLeftBorder = rHandoutMaster.GetLeftBorder(); + ::tools::Long nRightBorder = rHandoutMaster.GetRightBorder(); + ::tools::Long nTopBorder = rHandoutMaster.GetUpperBorder(); + ::tools::Long nBottomBorder = rHandoutMaster.GetLowerBorder(); - case 9: - pOffsets = aOffsets[4]; - break; - } + const ::tools::Long nHeaderFooterHeight = static_cast< ::tools::Long >( (aArea.Height() - nTopBorder - nLeftBorder) * 0.05 ); - rAreas.resize( static_cast<size_t>(vSlidesAreas.size()) ); + nTopBorder += nHeaderFooterHeight; + nBottomBorder += nHeaderFooterHeight; - for( const ::tools::Rectangle& rRect : vSlidesAreas ) - { - rAreas[*pOffsets++] = rRect; - } - } - } - else - { - const ::tools::Long nGapW = 1000; // gap is 1cm - const ::tools::Long nGapH = 1000; + ::tools::Long nX = nGapW + nLeftBorder; + ::tools::Long nY = nGapH + nTopBorder; - ::tools::Long nLeftBorder = rHandoutMaster.GetLeftBorder(); - ::tools::Long nRightBorder = rHandoutMaster.GetRightBorder(); - ::tools::Long nTopBorder = rHandoutMaster.GetUpperBorder(); - ::tools::Long nBottomBorder = rHandoutMaster.GetLowerBorder(); + aArea.AdjustWidth( -(nGapW * 2 + nLeftBorder + nRightBorder) ); + aArea.AdjustHeight( -(nGapH * 2 + nTopBorder + nBottomBorder) ); - const ::tools::Long nHeaderFooterHeight = static_cast< ::tools::Long >( (aArea.Height() - nTopBorder - nLeftBorder) * 0.05 ); + sal_uInt16 nColCnt = 0, nRowCnt = 0; + switch ( eLayout ) + { + case AUTOLAYOUT_HANDOUT1: + nColCnt = 1; nRowCnt = 1; + break; - nTopBorder += nHeaderFooterHeight; - nBottomBorder += nHeaderFooterHeight; + case AUTOLAYOUT_HANDOUT2: + if( bLandscape ) + { + nColCnt = 2; nRowCnt = 1; + } + else + { + nColCnt = 1; nRowCnt = 2; + } + break; - ::tools::Long nX = nGapW + nLeftBorder; - ::tools::Long nY = nGapH + nTopBorder; + case AUTOLAYOUT_HANDOUT3: + if( bLandscape ) + { + nColCnt = 3; nRowCnt = 2; + } + else + { + nColCnt = 2; nRowCnt = 3; + } + pOffsets = aOffsets[ bLandscape ? 1 : 0 ]; + break; - aArea.AdjustWidth( -(nGapW * 2 + nLeftBorder + nRightBorder) ); - aArea.AdjustHeight( -(nGapH * 2 + nTopBorder + nBottomBorder) ); + case AUTOLAYOUT_HANDOUT4: + nColCnt = 2; nRowCnt = 2; + pOffsets = aOffsets[ bHorizontal ? 0 : 2 ]; + break; - sal_uInt16 nColCnt = 0, nRowCnt = 0; - switch ( eLayout ) - { - case AUTOLAYOUT_HANDOUT1: - nColCnt = 1; nRowCnt = 1; - break; + case AUTOLAYOUT_HANDOUT6: + if( bLandscape ) + { + nColCnt = 3; nRowCnt = 2; + } + else + { + nColCnt = 2; nRowCnt = 3; + } + if( !bHorizontal ) + pOffsets = aOffsets[ bLandscape ? 1 : 3 ]; + break; - case AUTOLAYOUT_HANDOUT2: - if( bLandscape ) - { - nColCnt = 2; nRowCnt = 1; - } - else - { - nColCnt = 1; nRowCnt = 2; - } - break; + default: + case AUTOLAYOUT_HANDOUT9: + nColCnt = 3; nRowCnt = 3; - case AUTOLAYOUT_HANDOUT3: - if( bLandscape ) - { - nColCnt = 3; nRowCnt = 2; - } - else - { - nColCnt = 2; nRowCnt = 3; - } - pOffsets = aOffsets[ bLandscape ? 1 : 0 ]; - break; + if( !bHorizontal ) + pOffsets = aOffsets[4]; + break; + } - case AUTOLAYOUT_HANDOUT4: - nColCnt = 2; nRowCnt = 2; - pOffsets = aOffsets[ bHorizontal ? 0 : 2 ]; - break; + rAreas.resize(static_cast<size_t>(nColCnt) * nRowCnt); - case AUTOLAYOUT_HANDOUT6: - if( bLandscape ) - { - nColCnt = 3; nRowCnt = 2; - } - else - { - nColCnt = 2; nRowCnt = 3; - } - if( !bHorizontal ) - pOffsets = aOffsets[ bLandscape ? 1 : 3 ]; - break; + Size aPartArea, aSize; + aPartArea.setWidth( (aArea.Width() - ((nColCnt-1) * nGapW) ) / nColCnt ); + aPartArea.setHeight( (aArea.Height() - ((nRowCnt-1) * nGapH) ) / nRowCnt ); - default: - case AUTOLAYOUT_HANDOUT9: - nColCnt = 3; nRowCnt = 3; + SdrPage* pFirstPage = rModel.GetMasterSdPage(0, PageKind::Standard); + if (pFirstPage && pFirstPage->GetWidth() && pFirstPage->GetHeight()) + { + // scale actual size into handout rect + double fScale = static_cast<double>(aPartArea.Width()) / static_cast<double>(pFirstPage->GetWidth()); - if( !bHorizontal ) - pOffsets = aOffsets[4]; - break; - } + aSize.setHeight( static_cast<::tools::Long>(fScale * pFirstPage->GetHeight() ) ); + if( aSize.Height() > aPartArea.Height() ) + { + fScale = static_cast<double>(aPartArea.Height()) / static_cast<double>(pFirstPage->GetHeight()); + aSize.setHeight( aPartArea.Height() ); + aSize.setWidth( static_cast<::tools::Long>(fScale * pFirstPage->GetWidth()) ); + } + else + { + aSize.setWidth( aPartArea.Width() ); + } - rAreas.resize(static_cast<size_t>(nColCnt) * nRowCnt); + nX += (aPartArea.Width() - aSize.Width()) / 2; + nY += (aPartArea.Height()- aSize.Height())/ 2; + } + else + { + aSize = aPartArea; + } - Size aPartArea, aSize; - aPartArea.setWidth( (aArea.Width() - ((nColCnt-1) * nGapW) ) / nColCnt ); - aPartArea.setHeight( (aArea.Height() - ((nRowCnt-1) * nGapH) ) / nRowCnt ); + Point aPos( nX, nY ); - SdrPage* pFirstPage = rModel.GetMasterSdPage(0, PageKind::Standard); - if (pFirstPage && pFirstPage->GetWidth() && pFirstPage->GetHeight()) - { - // scale actual size into handout rect - double fScale = static_cast<double>(aPartArea.Width()) / static_cast<double>(pFirstPage->GetWidth()); + const bool bRTL = rModel.GetDefaultWritingMode() == css::text::WritingMode_RL_TB; - aSize.setHeight( static_cast<::tools::Long>(fScale * pFirstPage->GetHeight() ) ); - if( aSize.Height() > aPartArea.Height() ) - { - fScale = static_cast<double>(aPartArea.Height()) / static_cast<double>(pFirstPage->GetHeight()); - aSize.setHeight( aPartArea.Height() ); - aSize.setWidth( static_cast<::tools::Long>(fScale * pFirstPage->GetWidth()) ); - } - else - { - aSize.setWidth( aPartArea.Width() ); - } + const ::tools::Long nOffsetX = (aPartArea.Width() + nGapW) * (bRTL ? -1 : 1); + const ::tools::Long nOffsetY = aPartArea.Height() + nGapH; + const ::tools::Long nStartX = bRTL ? nOffsetX*(1 - nColCnt) + nX : nX; - nX += (aPartArea.Width() - aSize.Width()) / 2; - nY += (aPartArea.Height()- aSize.Height())/ 2; - } - else + for(sal_uInt16 nRow = 0; nRow < nRowCnt; nRow++) + { + aPos.setX( nStartX ); + for(sal_uInt16 nCol = 0; nCol < nColCnt; nCol++) { - aSize = aPartArea; + rAreas[*pOffsets++] = ::tools::Rectangle(aPos, aSize); + aPos.AdjustX(nOffsetX ); } - Point aPos( nX, nY ); - - const bool bRTL = rModel.GetDefaultWritingMode() == css::text::WritingMode_RL_TB; - - const ::tools::Long nOffsetX = (aPartArea.Width() + nGapW) * (bRTL ? -1 : 1); - const ::tools::Long nOffsetY = aPartArea.Height() + nGapH; - const ::tools::Long nStartX = bRTL ? nOffsetX*(1 - nColCnt) + nX : nX; - - for(sal_uInt16 nRow = 0; nRow < nRowCnt; nRow++) - { - aPos.setX( nStartX ); - for(sal_uInt16 nCol = 0; nCol < nColCnt; nCol++) - { - rAreas[*pOffsets++] = ::tools::Rectangle(aPos, aSize); - aPos.AdjustX(nOffsetX ); - } - - aPos.AdjustY(nOffsetY ); - } + aPos.AdjustY(nOffsetY ); } } diff --git a/sd/source/ui/view/DocumentRenderer.cxx b/sd/source/ui/view/DocumentRenderer.cxx index b7e70c46694b..83e612bf5587 100644 --- a/sd/source/ui/view/DocumentRenderer.cxx +++ b/sd/source/ui/view/DocumentRenderer.cxx @@ -1262,6 +1262,21 @@ namespace { { SdPage& rHandoutPage (*rDocument.GetSdPage(0, PageKind::Handout)); + Size aPageSize(rHandoutPage.GetSize()); + Size aPrintPageSize = rPrinter.GetPrintPageSize(); + + if ((aPageSize.Width() < aPageSize.Height() + && aPrintPageSize.Width() > aPrintPageSize.Height()) + || (aPageSize.Width() > aPageSize.Height() + && aPrintPageSize.Width() < aPrintPageSize.Height())) + { + ::tools::Long nTmp = aPageSize.Width(); + aPageSize.setWidth(aPageSize.Height()); + aPageSize.setHeight(nTmp); + + rHandoutPage.SetSize(aPageSize); + } + Reference< css::beans::XPropertySet > xHandoutPage( rHandoutPage.getUnoPage(), UNO_QUERY ); static constexpr OUString sPageNumber( u"Number"_ustr ); @@ -1818,8 +1833,14 @@ private: const bool bDrawLines (eLayout == AUTOLAYOUT_HANDOUT3); + Size aHandoutPageSize = pHandout->GetSize(); + lcl_AdjustPageSize(aHandoutPageSize, mpPrinter->GetPrintPageSize()); + Orientation eOrient = aHandoutPageSize.Width() > aHandoutPageSize.Height() + ? Orientation::Landscape + : Orientation::Portrait; + std::vector< ::tools::Rectangle > aAreas; - SdPage::CalculateHandoutAreas( rModel, eLayout, bHandoutHorizontal, aAreas ); + SdPage::CalculateHandoutAreas( rModel, eLayout, bHandoutHorizontal, aAreas, eOrient ); std::vector< ::tools::Rectangle >::iterator iter( aAreas.begin() ); while( iter != aAreas.end() ) @@ -2062,28 +2083,18 @@ private: SdPage& rMaster (dynamic_cast<SdPage&>(rHandoutPage.TRG_GetMasterPage())); rInfo.meOrientation = rMaster.GetOrientation(); - const Size aPaperSize (rInfo.mpPrinter->GetPaperSize()); - if( (rInfo.meOrientation == Orientation::Landscape && - (aPaperSize.Width() < aPaperSize.Height())) - || - (rInfo.meOrientation == Orientation::Portrait && - (aPaperSize.Width() > aPaperSize.Height())) - ) - { - maPrintSize = awt::Size(aPaperSize.Height(), aPaperSize.Width()); - } - else - { - maPrintSize = awt::Size(aPaperSize.Width(), aPaperSize.Height()); - } + Size aPaperSize (rInfo.mpPrinter->GetPaperSize()); + lcl_AdjustPageSize(aPaperSize, rInfo.mpPrinter->GetPrintPageSize()); + maPrintSize = awt::Size(aPaperSize.Width(),aPaperSize.Height()); MapMode aMap (rInfo.maMap); const Point aPageOfs (rInfo.mpPrinter->GetPageOffset()); if ( bScalePage ) { - const Size aPageSize (rHandoutPage.GetSize()); - const Size aPrintSize (rInfo.mpPrinter->GetOutputSize()); + Size aPageSize (rHandoutPage.GetSize()); + Size aPrintSize (rInfo.mpPrinter->GetOutputSize()); + lcl_AdjustPageSize(aPageSize, aPrintSize); const double fHorz = static_cast<double>(aPrintSize.Width()) / aPageSize.Width(); const double fVert = static_cast<double>(aPrintSize.Height()) / aPageSize.Height(); diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx index b0df9bf73c2d..aaa5ebdf47f0 100644 --- a/vcl/source/window/printdlg.cxx +++ b/vcl/source/window/printdlg.cxx @@ -661,8 +661,6 @@ PrintDialog::PrintDialog(weld::Window* i_pWindow, std::shared_ptr<PrinterControl initFromMultiPageSetup( maPController->getMultipage() ); - updatePageSize(mxOrientationBox->get_active()); - // setup optional UI options set by application setupOptionalUI(); @@ -1191,23 +1189,10 @@ void PrintDialog::updateNup( bool i_bMayUseCache ) aMPS.aPaperSize = maNupPortraitSize; else // automatic mode { - updatePageSize(mxOrientationBox->get_active()); - Size aPrintPageSize = maPController->getPrinter()->GetPrintPageSize(); - // get size of first real page to see if it is portrait or landscape // we assume same page sizes for all the pages for this Size aPageSize = getJobPageSize(); - if ((aPageSize.Width() < aPageSize.Height() - && aPrintPageSize.Width() > aPrintPageSize.Height()) - || (aPageSize.Width() > aPageSize.Height() - && aPrintPageSize.Width() < aPrintPageSize.Height())) - { - tools::Long nTmp = aPageSize.Width(); - aPageSize.setWidth(aPageSize.Height()); - aPageSize.setHeight(nTmp); - } - Size aMultiSize( aPageSize.Width() * nCols, aPageSize.Height() * nRows ); if( aMultiSize.Width() > aMultiSize.Height() ) // fits better on landscape { @@ -1920,6 +1905,7 @@ IMPL_LINK(PrintDialog, ToggleHdl, weld::Toggleable&, rButton, void) { mxOrientationBox->set_sensitive( true ); mxOrientationBox->set_active( ORIENTATION_AUTOMATIC ); + updatePageSize(mxOrientationBox->get_active()); enableNupControls( true ); updateNupFromPages(); } @@ -2001,6 +1987,7 @@ IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, void ) maPController->resetPrinterOptions( false ); updateOrientationBox(); + updatePageSize(mxOrientationBox->get_active()); // update text fields mxOKButton->set_label(maPrintText); @@ -2017,10 +2004,10 @@ IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, void ) setPaperSizes(); updateOrientationBox(); + updatePageSize(mxOrientationBox->get_active()); maUpdatePreviewIdle.Start(); } - updatePageSize(mxOrientationBox->get_active()); setupPaperSidesBox(); } else if ( &rBox == mxPaperSidesBox.get() ) @@ -2064,10 +2051,6 @@ IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, void ) updatePageSize(mxOrientationBox->get_active()); - int nOrientation = mxOrientationBox->get_active(); - if (nOrientation != ORIENTATION_AUTOMATIC) - setPaperOrientation(static_cast<Orientation>(nOrientation - 1), true); - maUpdatePreviewNoCacheIdle.Start(); } } @@ -2199,6 +2182,8 @@ IMPL_LINK( PrintDialog, UIOption_SelectHdl, weld::ComboBox&, i_rBox, void ) checkOptionalControlDependencies(); + updatePageSize(mxOrientationBox->get_active()); + // update preview and page settings maUpdatePreviewNoCacheIdle.Start(); } |