From 060dc8cbdf8b6e60608e8111fe66f9c03c3af16b Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 28 Jan 2011 11:54:24 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20print=20capability=20of=20the=20?= =?UTF-8?q?HTML=20output=20window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleHTMLOutputController.m | 45 ++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m index 9fee7358..43ff1d1e 100644 --- a/Source/SPBundleHTMLOutputController.m +++ b/Source/SPBundleHTMLOutputController.m @@ -24,6 +24,7 @@ #import "SPBundleHTMLOutputController.h" #import "SPAlertSheets.h" +#import "SPPrintAccessory.h" @class WebScriptCallFrame; @@ -178,7 +179,49 @@ - (IBAction)printDocument:(id)sender { - [[[[webView mainFrame] frameView] documentView] print:sender]; + + NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo]; + + NSSize paperSize = [printInfo paperSize]; + NSRect printableRect = [printInfo imageablePageBounds]; + + // Calculate page margins + CGFloat marginL = printableRect.origin.x; + CGFloat marginR = paperSize.width - (printableRect.origin.x + printableRect.size.width); + CGFloat marginB = printableRect.origin.y; + CGFloat marginT = paperSize.height - (printableRect.origin.y + printableRect.size.height); + + // Make sure margins are symetric and positive + CGFloat marginLR = MAX(0, MAX(marginL, marginR)); + CGFloat marginTB = MAX(0, MAX(marginT, marginB)); + + // Set the margins + [printInfo setLeftMargin:marginLR]; + [printInfo setRightMargin:marginLR]; + [printInfo setTopMargin:marginTB]; + [printInfo setBottomMargin:marginTB]; + + [printInfo setHorizontalPagination:NSFitPagination]; + [printInfo setVerticalPagination:NSFitPagination]; + [printInfo setVerticallyCentered:NO]; + + NSPrintOperation *op = [NSPrintOperation printOperationWithView:[[[webView mainFrame] frameView] documentView] printInfo:printInfo]; + + // Perform the print operation on a background thread + [op setCanSpawnSeparateThread:YES]; + + // Add the ability to select the orientation to print panel + NSPrintPanel *printPanel = [op printPanel]; + + [printPanel setOptions:[printPanel options] + NSPrintPanelShowsOrientation + NSPrintPanelShowsScaling + NSPrintPanelShowsPaperSize]; + + [op setPrintPanel:printPanel]; + + [op runOperationModalForWindow:[self window] + delegate:self + didRunSelector:nil + contextInfo:nil]; + } - (void)showSourceCode -- cgit v1.2.3