From 183922275465c160dd1525c9a82bfcbfb755941d Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Wed, 18 Apr 2007 08:25:43 +0000 Subject: [PATCH] Implement printing --- Sources/VLDocument.h | 2 ++ Sources/VLDocument.mm | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Sources/VLDocument.h b/Sources/VLDocument.h index 5a13e53..b036d69 100644 --- a/Sources/VLDocument.h +++ b/Sources/VLDocument.h @@ -13,6 +13,7 @@ @class VLSheetWindow; @class VLPDFWindow; @class VLLogWindow; +@class PDFDocument; @interface VLDocument : NSDocument { @@ -34,6 +35,7 @@ VLLogWindow * logWin; VLPDFWindow * pdfWin; VLKeyValueUndo* undo; + PDFDocument * printDoc; } - (VLSong *) song; diff --git a/Sources/VLDocument.mm b/Sources/VLDocument.mm index 2ca686f..e5ed3a3 100644 --- a/Sources/VLDocument.mm +++ b/Sources/VLDocument.mm @@ -11,11 +11,18 @@ #import "VLLilypondDocument.h" #import "VLMMADocument.h" #import "VLMIDIDocument.h" +#import "VLPDFDocument.h" #import "VLPDFWindow.h" #import "VLLogWindow.h" #import "VLSheetWindow.h" #import "VLSoundOut.h" +#import + +@interface PDFDocument (PDFKitSecretsIKnow) +- (NSPrintOperation *)getPrintOperationForPrintInfo:(NSPrintInfo *)printInfo autoRotate:(BOOL)doRotate; +@end + @interface VLSongWrapper : NSObject { VLSong * wrappedSong; } @@ -87,6 +94,7 @@ @"", @"songGroove", @"", @"songTempo", nil]]; + printDoc = nil; } return self; } @@ -421,6 +429,24 @@ [pdfWin reloadPDF]; } +- (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)printSettings + error:(NSError **)outError +{ + [self createTmpFileWithExtension:@"pdf" ofType:@"VLPDFType"]; + [printDoc autorelease]; + printDoc = [[PDFDocument alloc] initWithURL:[self fileURLWithExtension:@"pdf"]]; + + NSPrintOperation *printOperation = [printDoc getPrintOperationForPrintInfo:[self printInfo] autoRotate:NO]; + + // Specify that the print operation can run in a separate thread. This will cause the print progress panel to appear as a sheet on the document window. + [printOperation setCanSpawnSeparateThread:YES]; + + // Set any print settings that might have been specified in a Print Document Apple event. + [[[printOperation printInfo] dictionary] addEntriesFromDictionary:printSettings]; + + return printOperation; +} + - (IBAction) showLog:(id)sender { [[self logWin] showWindow:sender];