mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 17:10:37 +00:00
Split up in three classes added primitiv printing in file
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8169 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
eee86903f2
commit
6f5e42e1d1
1 changed files with 236 additions and 58 deletions
|
@ -34,6 +34,7 @@
|
||||||
#include <Foundation/NSData.h>
|
#include <Foundation/NSData.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
#include <Foundation/NSThread.h>
|
#include <Foundation/NSThread.h>
|
||||||
|
#include <Foundation/NSFileManager.h>
|
||||||
#include <AppKit/AppKitExceptions.h>
|
#include <AppKit/AppKitExceptions.h>
|
||||||
#include <AppKit/NSGraphicsContext.h>
|
#include <AppKit/NSGraphicsContext.h>
|
||||||
#include <AppKit/NSView.h>
|
#include <AppKit/NSView.h>
|
||||||
|
@ -41,19 +42,53 @@
|
||||||
#include <AppKit/NSPrintInfo.h>
|
#include <AppKit/NSPrintInfo.h>
|
||||||
#include <AppKit/NSPrintOperation.h>
|
#include <AppKit/NSPrintOperation.h>
|
||||||
|
|
||||||
@interface NSPrintOperation (Private)
|
@interface NSGraphicsContext (Printing)
|
||||||
|
|
||||||
- (void) setPath: (NSString *) path;
|
+ (NSGraphicsContext*) postscriptContextWithInfo: (NSDictionary*)info;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSPrintOperation (Private)
|
||||||
|
|
||||||
- (id) initWithView:(NSView *)aView
|
- (id) initWithView:(NSView *)aView
|
||||||
insideRect:(NSRect)rect
|
insideRect:(NSRect)rect
|
||||||
toData:(NSMutableData *)data
|
toData:(NSMutableData *)data
|
||||||
printInfo:(NSPrintInfo *)aPrintInfo;
|
printInfo:(NSPrintInfo *)aPrintInfo;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
// Subclass for the regular printing
|
||||||
|
@interface GSPrintOperation: NSPrintOperation
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
// subclass for EPS output
|
||||||
|
@interface GSEPSPrintOperation: NSPrintOperation
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) initEPSOperationWithView:(NSView *)aView
|
||||||
|
insideRect:(NSRect)rect
|
||||||
|
toPath:(NSString *)path
|
||||||
|
printInfo:(NSPrintInfo *)aPrintInfo;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
// subclass for PDF output
|
||||||
|
@interface GSPDFPrintOperation: NSPrintOperation
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
- (id) initPDFOperationWithView:(NSView *)aView
|
- (id) initPDFOperationWithView:(NSView *)aView
|
||||||
insideRect:(NSRect)rect
|
insideRect:(NSRect)rect
|
||||||
toData:(NSMutableData *)data
|
toData:(NSMutableData *)data
|
||||||
printInfo:(NSPrintInfo*)aPrintInfo;
|
printInfo:(NSPrintInfo*)aPrintInfo;
|
||||||
|
- (id) initPDFOperationWithView:(NSView *)aView
|
||||||
|
insideRect:(NSRect)rect
|
||||||
|
toPath:(NSString *)path
|
||||||
|
printInfo:(NSPrintInfo*)aPrintInfo;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -91,10 +126,10 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
toData:(NSMutableData *)data
|
toData:(NSMutableData *)data
|
||||||
printInfo:(NSPrintInfo *)aPrintInfo
|
printInfo:(NSPrintInfo *)aPrintInfo
|
||||||
{
|
{
|
||||||
return [[self alloc] initEPSOperationWithView: aView
|
return AUTORELEASE([[GSEPSPrintOperation alloc] initEPSOperationWithView: aView
|
||||||
insideRect: rect
|
insideRect: rect
|
||||||
toData: data
|
toData: data
|
||||||
printInfo: aPrintInfo];
|
printInfo: aPrintInfo]);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSPrintOperation *)EPSOperationWithView:(NSView *)aView
|
+ (NSPrintOperation *)EPSOperationWithView:(NSView *)aView
|
||||||
|
@ -102,14 +137,10 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
toPath:(NSString *)path
|
toPath:(NSString *)path
|
||||||
printInfo:(NSPrintInfo *)aPrintInfo
|
printInfo:(NSPrintInfo *)aPrintInfo
|
||||||
{
|
{
|
||||||
NSMutableData *data = [NSMutableData data];
|
return AUTORELEASE([[GSEPSPrintOperation alloc] initEPSOperationWithView: aView
|
||||||
NSPrintOperation *new = [self EPSOperationWithView: aView
|
insideRect: rect
|
||||||
insideRect: rect
|
toPath: path
|
||||||
toData: data
|
printInfo: aPrintInfo]);
|
||||||
printInfo: aPrintInfo];
|
|
||||||
|
|
||||||
[new setPath: path];
|
|
||||||
return new;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSPrintOperation *)printOperationWithView:(NSView *)aView
|
+ (NSPrintOperation *)printOperationWithView:(NSView *)aView
|
||||||
|
@ -121,8 +152,8 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
+ (NSPrintOperation *)printOperationWithView:(NSView *)aView
|
+ (NSPrintOperation *)printOperationWithView:(NSView *)aView
|
||||||
printInfo:(NSPrintInfo *)aPrintInfo
|
printInfo:(NSPrintInfo *)aPrintInfo
|
||||||
{
|
{
|
||||||
return [[self alloc] initWithView: aView
|
return AUTORELEASE([[GSPrintOperation alloc] initWithView: aView
|
||||||
printInfo: aPrintInfo];
|
printInfo: aPrintInfo]);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSPrintOperation *)PDFOperationWithView:(NSView *)aView
|
+ (NSPrintOperation *)PDFOperationWithView:(NSView *)aView
|
||||||
|
@ -140,10 +171,10 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
toData:(NSMutableData *)data
|
toData:(NSMutableData *)data
|
||||||
printInfo:(NSPrintInfo*)aPrintInfo
|
printInfo:(NSPrintInfo*)aPrintInfo
|
||||||
{
|
{
|
||||||
return [[self alloc] initPDFOperationWithView: aView
|
return AUTORELEASE([[self alloc] initPDFOperationWithView: aView
|
||||||
insideRect: rect
|
insideRect: rect
|
||||||
toData: data
|
toData: data
|
||||||
printInfo: aPrintInfo];
|
printInfo: aPrintInfo]);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSPrintOperation *)PDFOperationWithView:(NSView *)aView
|
+ (NSPrintOperation *)PDFOperationWithView:(NSView *)aView
|
||||||
|
@ -151,14 +182,10 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
toPath:(NSString *)path
|
toPath:(NSString *)path
|
||||||
printInfo:(NSPrintInfo*)aPrintInfo
|
printInfo:(NSPrintInfo*)aPrintInfo
|
||||||
{
|
{
|
||||||
NSMutableData *data = [NSMutableData data];
|
return AUTORELEASE([[self alloc] initPDFOperationWithView: aView
|
||||||
NSPrintOperation *new = [self PDFOperationWithView: aView
|
insideRect: rect
|
||||||
insideRect: rect
|
toPath: path
|
||||||
toData: data
|
printInfo: aPrintInfo]);
|
||||||
printInfo: aPrintInfo];
|
|
||||||
|
|
||||||
[new setPath: path];
|
|
||||||
return new;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -193,26 +220,21 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
toData:(NSMutableData *)data
|
toData:(NSMutableData *)data
|
||||||
printInfo:(NSPrintInfo *)aPrintInfo
|
printInfo:(NSPrintInfo *)aPrintInfo
|
||||||
{
|
{
|
||||||
self = [self initWithView: aView
|
RELEASE(self);
|
||||||
insideRect: rect
|
|
||||||
toData: data
|
return [[GSEPSPrintOperation alloc] initEPSOperationWithView: aView
|
||||||
printInfo: aPrintInfo];
|
insideRect: rect
|
||||||
|
toData: data
|
||||||
return self;
|
printInfo: aPrintInfo];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithView:(NSView *)aView
|
- (id)initWithView:(NSView *)aView
|
||||||
printInfo:(NSPrintInfo *)aPrintInfo
|
printInfo:(NSPrintInfo *)aPrintInfo
|
||||||
{
|
{
|
||||||
NSMutableData *data = [NSMutableData data];
|
RELEASE(self);
|
||||||
|
|
||||||
self = [self initWithView: aView
|
return [[GSPrintOperation alloc] initWithView: aView
|
||||||
insideRect: [aView bounds]
|
printInfo: aPrintInfo];
|
||||||
toData: data
|
|
||||||
printInfo: aPrintInfo];
|
|
||||||
_showPanels = YES;
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
|
@ -220,10 +242,11 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
RELEASE(_printInfo);
|
RELEASE(_printInfo);
|
||||||
RELEASE(_view);
|
RELEASE(_view);
|
||||||
RELEASE(_data);
|
RELEASE(_data);
|
||||||
TEST_RELEASE(_path);
|
|
||||||
TEST_RELEASE(_context);
|
TEST_RELEASE(_context);
|
||||||
TEST_RELEASE(_printPanel);
|
TEST_RELEASE(_printPanel);
|
||||||
TEST_RELEASE(_accessoryView);
|
TEST_RELEASE(_accessoryView);
|
||||||
|
|
||||||
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -281,7 +304,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
- (NSGraphicsContext*)createContext
|
- (NSGraphicsContext*)createContext
|
||||||
{
|
{
|
||||||
// FIXME
|
// FIXME
|
||||||
return _context;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSGraphicsContext *)context
|
- (NSGraphicsContext *)context
|
||||||
|
@ -324,13 +347,12 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
- (BOOL)deliverResult
|
- (BOOL)deliverResult
|
||||||
{
|
{
|
||||||
// FIXME
|
// FIXME
|
||||||
return NO;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)runOperation
|
- (BOOL)runOperation
|
||||||
{
|
{
|
||||||
BOOL result;
|
BOOL result;
|
||||||
NSGraphicsContext *oldContext;
|
|
||||||
|
|
||||||
if (_showPanels)
|
if (_showPanels)
|
||||||
{
|
{
|
||||||
|
@ -341,20 +363,36 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
[panel updateFromPrintInfo];
|
[panel updateFromPrintInfo];
|
||||||
button = [panel runModal];
|
button = [panel runModal];
|
||||||
[panel setAccessoryView: nil];
|
[panel setAccessoryView: nil];
|
||||||
|
/*
|
||||||
if (button != NSOKButton)
|
if (button != NSOKButton)
|
||||||
{
|
{
|
||||||
[self cleanUpOperation];
|
[self cleanUpOperation];
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
[panel finalWritePrintInfo];
|
[panel finalWritePrintInfo];
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the actual printing
|
ASSIGN(_context, [self createContext]);
|
||||||
oldContext = [NSGraphicsContext currentContext];
|
|
||||||
[NSGraphicsContext setCurrentContext: [self createContext]];
|
if (_context != nil)
|
||||||
[_view displayRect: _rect];
|
{
|
||||||
[NSGraphicsContext setCurrentContext: oldContext];
|
NSGraphicsContext *oldContext = [NSGraphicsContext currentContext];
|
||||||
|
|
||||||
|
[NSGraphicsContext setCurrentContext: _context];
|
||||||
|
// This is the actual printing
|
||||||
|
NS_DURING
|
||||||
|
{
|
||||||
|
[_view displayRect: _rect];
|
||||||
|
}
|
||||||
|
NS_HANDLER
|
||||||
|
{
|
||||||
|
NSLog(@"Error while printing: %@\n", localException);
|
||||||
|
}
|
||||||
|
NS_ENDHANDLER
|
||||||
|
[NSGraphicsContext setCurrentContext: oldContext];
|
||||||
|
[self destroyContext];
|
||||||
|
}
|
||||||
|
|
||||||
result = [self deliverResult];
|
result = [self deliverResult];
|
||||||
[self cleanUpOperation];
|
[self cleanUpOperation];
|
||||||
|
@ -390,11 +428,6 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
|
|
||||||
@implementation NSPrintOperation (Private)
|
@implementation NSPrintOperation (Private)
|
||||||
|
|
||||||
- (void) setPath: (NSString *) path
|
|
||||||
{
|
|
||||||
ASSIGN(_path, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) initWithView:(NSView *)aView
|
- (id) initWithView:(NSView *)aView
|
||||||
insideRect:(NSRect)rect
|
insideRect:(NSRect)rect
|
||||||
toData:(NSMutableData *)data
|
toData:(NSMutableData *)data
|
||||||
|
@ -411,10 +444,122 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
_showPanels = NO;
|
_showPanels = NO;
|
||||||
[self setPrintInfo: aPrintInfo];
|
[self setPrintInfo: aPrintInfo];
|
||||||
|
|
||||||
|
ASSIGN(_path, @"/tmp/NSTempPrintFile");
|
||||||
|
_pathSet = NO;
|
||||||
|
|
||||||
[NSPrintOperation setCurrentOperation: self];
|
[NSPrintOperation setCurrentOperation: self];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation GSPrintOperation
|
||||||
|
|
||||||
|
- (id)initWithView:(NSView *)aView
|
||||||
|
printInfo:(NSPrintInfo *)aPrintInfo
|
||||||
|
{
|
||||||
|
NSMutableData *data = [NSMutableData data];
|
||||||
|
|
||||||
|
self = [self initWithView: aView
|
||||||
|
insideRect: [aView bounds]
|
||||||
|
toData: data
|
||||||
|
printInfo: aPrintInfo];
|
||||||
|
_showPanels = YES;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSGraphicsContext*)createContext
|
||||||
|
{
|
||||||
|
NSMutableDictionary *info = [_printInfo dictionary];
|
||||||
|
NSGraphicsContext *psContext;
|
||||||
|
|
||||||
|
[info setObject: _path forKey: @"NSOutputFile"];
|
||||||
|
psContext = [NSGraphicsContext postscriptContextWithInfo: info];
|
||||||
|
|
||||||
|
return psContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)deliverResult
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (!_pathSet)
|
||||||
|
[[NSFileManager defaultManager] removeFileAtPath: _path
|
||||||
|
handler: nil];
|
||||||
|
*/
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation GSEPSPrintOperation
|
||||||
|
|
||||||
|
-(void) dealloc
|
||||||
|
{
|
||||||
|
TEST_RELEASE(_path);
|
||||||
|
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id)initEPSOperationWithView:(NSView *)aView
|
||||||
|
insideRect:(NSRect)rect
|
||||||
|
toData:(NSMutableData *)data
|
||||||
|
printInfo:(NSPrintInfo *)aPrintInfo
|
||||||
|
{
|
||||||
|
self = [self initWithView: aView
|
||||||
|
insideRect: rect
|
||||||
|
toData: data
|
||||||
|
printInfo: aPrintInfo];
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) initEPSOperationWithView:(NSView *)aView
|
||||||
|
insideRect:(NSRect)rect
|
||||||
|
toPath:(NSString *)path
|
||||||
|
printInfo:(NSPrintInfo *)aPrintInfo
|
||||||
|
{
|
||||||
|
NSMutableData *data = [NSMutableData data];
|
||||||
|
|
||||||
|
self = [self initEPSOperationWithView: aView
|
||||||
|
insideRect: rect
|
||||||
|
toData: data
|
||||||
|
printInfo: aPrintInfo];
|
||||||
|
|
||||||
|
ASSIGN(_path, path);
|
||||||
|
_pathSet = YES;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSGraphicsContext*)createContext
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)deliverResult
|
||||||
|
{
|
||||||
|
if (_data != nil && _path != nil && [_data length])
|
||||||
|
return [_data writeToFile: _path atomically: NO];
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation GSPDFPrintOperation
|
||||||
|
|
||||||
|
-(void) dealloc
|
||||||
|
{
|
||||||
|
TEST_RELEASE(_path);
|
||||||
|
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
- (id) initPDFOperationWithView:(NSView *)aView
|
- (id) initPDFOperationWithView:(NSView *)aView
|
||||||
insideRect:(NSRect)rect
|
insideRect:(NSRect)rect
|
||||||
toData:(NSMutableData *)data
|
toData:(NSMutableData *)data
|
||||||
|
@ -428,4 +573,37 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) initPDFOperationWithView:(NSView *)aView
|
||||||
|
insideRect:(NSRect)rect
|
||||||
|
toPath:(NSString *)path
|
||||||
|
printInfo:(NSPrintInfo*)aPrintInfo
|
||||||
|
{
|
||||||
|
NSMutableData *data = [NSMutableData data];
|
||||||
|
|
||||||
|
self = [self initPDFOperationWithView: aView
|
||||||
|
insideRect: rect
|
||||||
|
toData: data
|
||||||
|
printInfo: aPrintInfo];
|
||||||
|
|
||||||
|
ASSIGN(_path, path);
|
||||||
|
_pathSet = YES;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSGraphicsContext*)createContext
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)deliverResult
|
||||||
|
{
|
||||||
|
if (_data != nil && _path != nil && [_data length])
|
||||||
|
return [_data writeToFile: _path atomically: NO];
|
||||||
|
// FIXME Until we can create PDF we shoud convert the file with GhostScript
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue