vcl/osx/printview.mm | 8 +++++-- vcl/osx/salprn.cxx | 53 +++++++++++++++++++++++++-------------------------- 2 files changed, 32 insertions(+), 29 deletions(-)
New commits: commit 09484a1befd41681276cc9909b3228e5bf28a76e Author: Patrick Luby <guibmac...@gmail.com> AuthorDate: Sun Dec 29 11:20:11 2024 -0500 Commit: Patrick Luby <guibomac...@gmail.com> CommitDate: Mon Dec 30 19:40:40 2024 +0100 Related: tdf#159995 fix pages per sheet in the non-native print dialog Use filtered page sizes so that printing multiple pages per sheet in LibreOffice's non-native print dialog uses the correct paper size. On macOS, the native pages per sheet setting in the native print dialog adds margins and scales down the pages to fit. So the only alternative is to have LibreOffice handle pages per sheet but that is only available in LibreOffice's non-native print dialog. Note: to enable LibreOffice's non-native print dialog, set "UseSystemPrintDialog" to "false" in LibreOffice's Expert Conguration dialog and restart. Also, fix the following bugs when printing a Writer document with different paper sizes on each page: - Print jobs with different paper sizes are broken up into a separate NSPrintOperation for each set of continguous pages with the same size so the page number needs to be offset by the current page start range. - If the LibreOffice paper name is empty, fallback to setting the paper size by width and height. - When the last page has a page size change, one more loop still needs to run so set the current page range count to zero. - When using the native print dialog and one of the print dialogs is cancelled, abort the entire print job. Change-Id: I3450a11acefba5db6cb39a0111ce83da7546f6b3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179508 Tested-by: Jenkins Reviewed-by: Patrick Luby <guibomac...@gmail.com> diff --git a/vcl/osx/printview.mm b/vcl/osx/printview.mm index b54e1b0561c3..fe9b41609228 100644 --- a/vcl/osx/printview.mm +++ b/vcl/osx/printview.mm @@ -70,9 +70,13 @@ NSSize aPaperSize = [mpInfoPrinter->getPrintInfo() paperSize]; int nPage = static_cast<int>(aPaperSize.width * rect.origin.y + rect.origin.x); - // page count is 1 based + // Notes: + // - Page count is 1 based + // - Print jobs with different paper sizes are broken up into a separate + // NSPrintOperation for each set of continguous pages with the same size + // so the page number needs to be offset by the current page start range if( nPage - 1 < (mpInfoPrinter->getCurPageRangeStart() + mpInfoPrinter->getCurPageRangeCount() ) ) - mpController->printFilteredPage( nPage-1 ); + mpController->printFilteredPage( mpInfoPrinter->getCurPageRangeStart() + nPage - 1 ); } @end diff --git a/vcl/osx/salprn.cxx b/vcl/osx/salprn.cxx index 4232f653e974..673d114a3663 100644 --- a/vcl/osx/salprn.cxx +++ b/vcl/osx/salprn.cxx @@ -216,13 +216,21 @@ void AquaSalInfoPrinter::setPaperSize( tools::Long i_nWidth, tools::Long i_nHeig Orientation ePaperOrientation = Orientation::Portrait; const PaperInfo* pPaper = matchPaper( i_nWidth, i_nHeight, ePaperOrientation ); + bool bPaperSet = false; if( pPaper ) { - NSString* pPaperName = [CreateNSString( OStringToOUString(PaperInfo::toPSName(pPaper->getPaper()), RTL_TEXTENCODING_ASCII_US) ) autorelease]; - [mpPrintInfo setPaperName: pPaperName]; + // If the paper name is empty, fallback to setting the paper size + // using the specified width and height. + const rtl::OString &rPaperName( PaperInfo::toPSName( pPaper->getPaper() ) ); + if( !rPaperName.isEmpty() ) + { + NSString* pPaperName = [CreateNSString( OStringToOUString( rPaperName, RTL_TEXTENCODING_ASCII_US ) ) autorelease]; + [mpPrintInfo setPaperName: pPaperName]; + bPaperSet = true; + } } - else if( i_nWidth > 0 && i_nHeight > 0 ) + if( !bPaperSet && i_nWidth > 0 && i_nHeight > 0 ) { NSSize aPaperSize = { static_cast<CGFloat>(TenMuToPt(i_nWidth)), static_cast<CGFloat>(TenMuToPt(i_nHeight)) }; [mpPrintInfo setPaperSize: aPaperSize]; @@ -353,24 +361,6 @@ void AquaSalInfoPrinter::GetPageInfo( const ImplJobSetup*, } } -static Size getPageSize( vcl::PrinterController const & i_rController, sal_Int32 i_nPage ) -{ - Size aPageSize; - uno::Sequence< PropertyValue > const aPageParms( i_rController.getPageParameters( i_nPage ) ); - for( const PropertyValue & pv : aPageParms ) - { - if ( pv.Name == "PageSize" ) - { - awt::Size aSize; - pv.Value >>= aSize; - aPageSize.setWidth( aSize.Width ); - aPageSize.setHeight( aSize.Height ); - break; - } - } - return aPageSize; -} - bool AquaSalInfoPrinter::StartJob( const OUString* i_pFileName, const OUString& i_rJobName, ImplJobSetup* i_pSetupData, @@ -433,14 +423,21 @@ bool AquaSalInfoPrinter::StartJob( const OUString* i_pFileName, Size aCurSize( 21000, 29700 ); if( nAllPages > 0 ) { + // Related: tdf#159995 use filtered page sizes so that + // printing multiple pages per sheet in LibreOffice's + // non-native print dialog uses the correct paper size. + // Note: to use LibreOffice's non-native print dialog, + // set "UseSystemPrintDialog" to "false" in LibreOffice's + // Expert Conguration dialog and restart. + GDIMetaFile aPageFile; mnCurPageRangeCount = 1; - aCurSize = getPageSize( i_rController, mnCurPageRangeStart ); + aCurSize = i_rController.getFilteredPageFile( mnCurPageRangeStart, aPageFile ).aSize; Size aNextSize( aCurSize ); // print pages up to a different size - while( mnCurPageRangeCount + mnCurPageRangeStart < nAllPages ) + while( mnCurPageRangeStart + mnCurPageRangeCount < nAllPages ) { - aNextSize = getPageSize( i_rController, mnCurPageRangeStart + mnCurPageRangeCount ); + aNextSize = i_rController.getFilteredPageFile( mnCurPageRangeStart + mnCurPageRangeCount, aPageFile ).aSize; if( aCurSize == aNextSize // same page size || (aCurSize.Width() == aNextSize.Height() && aCurSize.Height() == aNextSize.Width()) // same size, but different orientation @@ -517,15 +514,17 @@ bool AquaSalInfoPrinter::StartJob( const OUString* i_pFileName, bool wasSuccessful = [pPrintOperation runOperation]; pInst->endedPrintJob(); bSuccess = wasSuccessful; - bWasAborted = [[[pPrintOperation printInfo] jobDisposition] compare: NSPrintCancelJob] == NSOrderedSame; + bWasAborted = [[[pPrintOperation printInfo] jobDisposition] isEqualToString: NSPrintCancelJob]; mbJob = false; if( pReleaseAfterUse ) [pReleaseAfterUse release]; } + // When the last page has a page size change, one more loop + // still needs to run so set mnCurPageRangeCount to zero. mnCurPageRangeStart += mnCurPageRangeCount; - mnCurPageRangeCount = 1; - } while( aAccViewState.bNeedRestart || mnCurPageRangeStart + mnCurPageRangeCount < nAllPages ); + mnCurPageRangeCount = 0; + } while( ( !bWasAborted || aAccViewState.bNeedRestart ) && mnCurPageRangeStart + mnCurPageRangeCount < nAllPages ); } // inform application that it can release its data