2004-07-10 10:19:34 +00:00
|
|
|
/*
|
|
|
|
GLPRSPrintOperation.m
|
|
|
|
|
|
|
|
Controls operations generating EPS, PDF or PS print jobs.
|
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
|
|
|
Date: 1996
|
|
|
|
Author: Fred Kiefer <FredKiefer@gmx.de>
|
|
|
|
Date: November 2000
|
|
|
|
Started implementation.
|
|
|
|
Modified for Printing Backend Support
|
|
|
|
Author: Chad Hardin
|
|
|
|
Date: June 2004
|
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-10-29 21:16:17 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2004-07-10 10:19:34 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:01:49 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2007-10-29 21:16:17 +00:00
|
|
|
|
2004-07-10 10:19:34 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-10-29 21:16:17 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2004-07-10 10:19:34 +00:00
|
|
|
|
2007-10-29 21:16:17 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2004-07-10 10:19:34 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
2007-10-29 21:16:17 +00:00
|
|
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
2004-07-10 10:19:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2011-02-07 18:08:33 +00:00
|
|
|
#import <Foundation/NSDebug.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSPathUtilities.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
#import <Foundation/NSTask.h>
|
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
#import "AppKit/NSGraphicsContext.h"
|
|
|
|
#import "AppKit/NSView.h"
|
|
|
|
#import "AppKit/NSPrinter.h"
|
|
|
|
#import "AppKit/NSPrintPanel.h"
|
|
|
|
#import "AppKit/NSPrintInfo.h"
|
|
|
|
#import "AppKit/NSPrintOperation.h"
|
|
|
|
#import "GSGuiPrivate.h"
|
|
|
|
#import "GSLPRPrintOperation.h"
|
2004-07-10 10:19:34 +00:00
|
|
|
|
|
|
|
//A subclass of GSPrintOperation, NOT NSPrintOperation.
|
|
|
|
@implementation GSLPRPrintOperation
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
|
|
|
+ (id) allocWithZone: (NSZone*)zone
|
|
|
|
{
|
|
|
|
return NSAllocateObject(self, 0, zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (id)initWithView:(NSView *)aView
|
2004-10-08 05:22:22 +00:00
|
|
|
printInfo:(NSPrintInfo *)aPrintInfo
|
2004-07-10 10:19:34 +00:00
|
|
|
{
|
|
|
|
self = [super initWithView: aView
|
|
|
|
printInfo: aPrintInfo];
|
2011-02-07 18:08:33 +00:00
|
|
|
if (self == nil)
|
|
|
|
return nil;
|
2004-07-10 10:19:34 +00:00
|
|
|
|
2004-09-23 16:03:23 +00:00
|
|
|
_path = [NSTemporaryDirectory()
|
|
|
|
stringByAppendingPathComponent: @"GSLPRPrintJob-"];
|
2004-07-10 10:19:34 +00:00
|
|
|
|
|
|
|
_path = [_path stringByAppendingString:
|
|
|
|
[[NSProcessInfo processInfo] globallyUniqueString]];
|
|
|
|
|
|
|
|
_path = [_path stringByAppendingPathExtension: @"ps"];
|
|
|
|
|
2004-09-23 16:03:23 +00:00
|
|
|
RETAIN(_path);
|
2004-07-10 10:19:34 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (BOOL) _deliverSpooledResult
|
|
|
|
{
|
|
|
|
int copies;
|
|
|
|
NSDictionary *dict;
|
|
|
|
NSTask *task;
|
|
|
|
NSString *name, *status;
|
|
|
|
NSMutableArray *args;
|
|
|
|
|
2007-01-17 12:09:41 +00:00
|
|
|
name = [[[self printInfo] printer] name];
|
2011-02-07 18:08:33 +00:00
|
|
|
status = [NSString stringWithFormat: _(@"Spooling to printer %@."), name];
|
2007-01-17 12:09:41 +00:00
|
|
|
[[self printPanel] _setStatusStringValue: status];
|
2004-07-10 10:19:34 +00:00
|
|
|
|
2007-01-17 12:09:41 +00:00
|
|
|
dict = [[self printInfo] dictionary];
|
2004-07-10 10:19:34 +00:00
|
|
|
args = [NSMutableArray array];
|
|
|
|
copies = [[dict objectForKey: NSPrintCopies] intValue];
|
|
|
|
if (copies > 1)
|
|
|
|
[args addObject: [NSString stringWithFormat: @"-#%0d", copies]];
|
|
|
|
if ([name isEqual: @"Unknown"] == NO)
|
|
|
|
{
|
|
|
|
[args addObject: @"-P"];
|
|
|
|
[args addObject: name];
|
|
|
|
}
|
|
|
|
[args addObject: _path];
|
|
|
|
|
|
|
|
task = [NSTask new];
|
|
|
|
[task setLaunchPath: @"lpr"];
|
|
|
|
[task setArguments: args];
|
|
|
|
[task launch];
|
|
|
|
[task waitUntilExit];
|
|
|
|
AUTORELEASE(task);
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSGraphicsContext*)createContext
|
|
|
|
{
|
|
|
|
NSMutableDictionary *info;
|
2004-09-23 16:03:23 +00:00
|
|
|
NSString *output;
|
2004-07-10 10:19:34 +00:00
|
|
|
|
|
|
|
if (_context)
|
|
|
|
{
|
|
|
|
NSDebugMLLog(@"GSPrinting", @"Already had context, returning it.");
|
|
|
|
return _context;
|
|
|
|
}
|
|
|
|
NSDebugMLLog(@"GSPrinting", @"Creating context.");
|
|
|
|
|
2007-01-17 12:09:41 +00:00
|
|
|
info = [[self printInfo] dictionary];
|
2004-09-23 16:03:23 +00:00
|
|
|
|
|
|
|
output = [info objectForKey: NSPrintSavePath];
|
|
|
|
if (output)
|
2004-07-10 10:19:34 +00:00
|
|
|
{
|
2004-09-23 16:03:23 +00:00
|
|
|
ASSIGN(_path, output);
|
2004-07-10 10:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NSDebugMLLog(@"GSPrinting", @"_path is %@", _path);
|
|
|
|
|
|
|
|
[info setObject: _path
|
|
|
|
forKey: @"NSOutputFile"];
|
2011-03-13 23:38:47 +00:00
|
|
|
|
|
|
|
if ([[[_path pathExtension] lowercaseString] isEqualToString: @"pdf"])
|
|
|
|
{
|
|
|
|
[info setObject: NSGraphicsContextPDFFormat
|
|
|
|
forKey: NSGraphicsContextRepresentationFormatAttributeName];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[info setObject: NSGraphicsContextPSFormat
|
|
|
|
forKey: NSGraphicsContextRepresentationFormatAttributeName];
|
|
|
|
}
|
2004-07-10 10:19:34 +00:00
|
|
|
|
|
|
|
_context = RETAIN([NSGraphicsContext graphicsContextWithAttributes: info]);
|
|
|
|
|
|
|
|
return _context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|