mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Revert "Rework Apple printing to better handle rotation"
This reverts commit 35ac6bdeb450fe1acc3c12d4f09ec9badd7af7f2.
This commit is contained in:
parent
c072133fa4
commit
bce3e7340f
@ -26,29 +26,6 @@ namespace KIPLATFORM
|
||||
{
|
||||
namespace PRINTING
|
||||
{
|
||||
|
||||
BOOL hasMultipleOrientations( PDFDocument* document )
|
||||
{
|
||||
if( [document pageCount] == 0 )
|
||||
return NO;
|
||||
|
||||
PDFPage* firstPage = [document pageAtIndex:0];
|
||||
NSRect firstBounds = [firstPage boundsForBox:kPDFDisplayBoxMediaBox];
|
||||
BOOL firstIsLandscape = firstBounds.size.width > firstBounds.size.height;
|
||||
|
||||
for( NSUInteger i = 1; i < [document pageCount]; i++ )
|
||||
{
|
||||
PDFPage* page = [document pageAtIndex:i];
|
||||
NSRect bounds = [page boundsForBox:kPDFDisplayBoxMediaBox];
|
||||
BOOL isLandscape = bounds.size.width > bounds.size.height;
|
||||
|
||||
if( isLandscape != firstIsLandscape )
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
PRINT_RESULT PrintPDF( const std::string& aFile, bool fit_to_page)
|
||||
{
|
||||
@autoreleasepool
|
||||
@ -67,35 +44,17 @@ PRINT_RESULT PrintPDF( const std::string& aFile, bool fit_to_page)
|
||||
return PRINT_RESULT::FAILED_TO_LOAD;
|
||||
}
|
||||
|
||||
PDFView* pdfView = [[PDFView alloc] init];
|
||||
[pdfView setDocument:document];
|
||||
NSPrintInfo* printInfo = [NSPrintInfo sharedPrintInfo];
|
||||
|
||||
NSPrintInfo* printInfo = [[NSPrintInfo sharedPrintInfo] copy];
|
||||
PDFPrintScalingMode scalingMode = fit_to_page ?
|
||||
kPDFPrintPageScaleDownToFit : kPDFPrintPageScaleNone;
|
||||
|
||||
BOOL hasMixed = hasMultipleOrientations( document );
|
||||
|
||||
if( hasMixed )
|
||||
{
|
||||
[printInfo setOrientation:NSPrintingOrientationPortrait];
|
||||
[printInfo setHorizontallyCentered:YES];
|
||||
[printInfo setVerticallyCentered:YES];
|
||||
}
|
||||
|
||||
if( fit_to_page )
|
||||
{
|
||||
NSMutableDictionary* settings = [[printInfo printSettings] mutableCopy];
|
||||
[settings setObject:@YES forKey:@"com.apple.print.PrintSettings.PMScaleToFit"];
|
||||
[printInfo setPrintSettings:settings];
|
||||
[settings release];
|
||||
}
|
||||
|
||||
NSPrintOperation* op = [NSPrintOperation printOperationWithView:pdfView printInfo:printInfo];
|
||||
|
||||
[printInfo release];
|
||||
NSPrintOperation* op = [document printOperationForPrintInfo:printInfo
|
||||
scalingMode:scalingMode
|
||||
autoRotate:YES];
|
||||
|
||||
if( !op )
|
||||
{
|
||||
[pdfView release];
|
||||
[document release];
|
||||
return PRINT_RESULT::FAILED_TO_PRINT;
|
||||
}
|
||||
@ -107,24 +66,22 @@ PRINT_RESULT PrintPDF( const std::string& aFile, bool fit_to_page)
|
||||
|
||||
PRINT_RESULT result;
|
||||
|
||||
if( success )
|
||||
if (success)
|
||||
{
|
||||
result = PRINT_RESULT::OK;
|
||||
} else
|
||||
{
|
||||
// Check if operation was cancelled (uncertain that this works)
|
||||
NSPrintInfo* info = [op printInfo];
|
||||
NSDictionary* settings = [info printSettings];
|
||||
|
||||
if( [[settings objectForKey:NSPrintJobDisposition] isEqualToString:NSPrintCancelJob] )
|
||||
{
|
||||
if ([[settings objectForKey:NSPrintJobDisposition] isEqualToString:NSPrintCancelJob]) {
|
||||
result = PRINT_RESULT::CANCELLED;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
result = PRINT_RESULT::FAILED_TO_PRINT;
|
||||
}
|
||||
}
|
||||
|
||||
[pdfView release];
|
||||
[document release];
|
||||
return result;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user