mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 06:30:38 +00:00
Backend printing bundle system changes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19705 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ca71d7e075
commit
989ae0cdd8
36 changed files with 3424 additions and 1256 deletions
|
@ -191,7 +191,12 @@ GSTitleView.m \
|
|||
GSToolbar.m \
|
||||
GSToolbarView.m \
|
||||
GSStandardWindowDecorationView.m \
|
||||
GSWindowDecorationView.m
|
||||
GSWindowDecorationView.m \
|
||||
GSPrinting.m \
|
||||
GSPrintOperation.m \
|
||||
GSEPSPrintOperation.m \
|
||||
GSPDFPrintOperation.m
|
||||
|
||||
|
||||
# Turn off NSMenuItem warning that NSMenuItem conforms to <NSObject>,
|
||||
# but does not implement <NSObject>'s methods itself (it inherits
|
||||
|
@ -363,7 +368,11 @@ GSToolbar.h \
|
|||
GSToolbarView.h \
|
||||
GSNibCompatibility.h \
|
||||
GSDragView.h \
|
||||
GSTitleView.h
|
||||
GSTitleView.h \
|
||||
GSPrinting.h \
|
||||
GSPrintOperation.h \
|
||||
GSEPSPrintOperation.h \
|
||||
GSPDFPrintOperation.h
|
||||
|
||||
libgnustep-gui_HEADER_FILES = ${GUI_HEADERS}
|
||||
|
||||
|
|
151
Source/GSEPSPrintOperation.m
Normal file
151
Source/GSEPSPrintOperation.m
Normal file
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
GSEPSPrintOperation.m
|
||||
|
||||
Controls operations generating EPS output files.
|
||||
|
||||
Copyright (C) 1996, 2004 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
Author: Fred Kiefer <FredKiefer@gmx.de>
|
||||
Date: November 2000
|
||||
Started implementation.
|
||||
Author: Chad Hardin <cehardin@mac.com>
|
||||
Date: June 2004
|
||||
Modified for printing backend support, split off from NSPrintOperation.m
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSPathUtilities.h>
|
||||
#include <Foundation/NSTask.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include "AppKit/NSView.h"
|
||||
#include "AppKit/NSPrintInfo.h"
|
||||
#include "AppKit/NSPrintOperation.h"
|
||||
#include "GNUstepGUI/GSEPSPrintOperation.h"
|
||||
|
||||
|
||||
/**
|
||||
<unit>
|
||||
<heading>Class Description</heading>
|
||||
<p>
|
||||
GSEPSPrintOperation is a subclass of NSPrintOperation
|
||||
that can create eps files suitable for saving, previewing, etc.
|
||||
</p>
|
||||
</unit>
|
||||
*/
|
||||
|
||||
@implementation GSEPSPrintOperation
|
||||
|
||||
- (id)initWithView:(NSView *)aView
|
||||
insideRect:(NSRect)rect
|
||||
toData:(NSMutableData *)data
|
||||
printInfo:(NSPrintInfo *)aPrintInfo
|
||||
{
|
||||
self = [super initWithView: aView
|
||||
insideRect: rect
|
||||
toData: data
|
||||
printInfo: aPrintInfo];
|
||||
|
||||
_path = [NSTemporaryDirectory() stringByAppendingPathComponent: @"GSPrint-"];
|
||||
|
||||
_path = [_path stringByAppendingString:
|
||||
[[NSProcessInfo processInfo] globallyUniqueString]];
|
||||
|
||||
_path = [_path stringByAppendingPathExtension: @"ps"];
|
||||
RETAIN( _path );
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithView:(NSView *)aView
|
||||
insideRect:(NSRect)rect
|
||||
toPath:(NSString *)path
|
||||
printInfo:(NSPrintInfo *)aPrintInfo
|
||||
{
|
||||
NSMutableData *data = [NSMutableData data];
|
||||
|
||||
self = [super initWithView: aView
|
||||
insideRect: rect
|
||||
toData: data
|
||||
printInfo: aPrintInfo];
|
||||
|
||||
ASSIGN(_path, path);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) _print
|
||||
{
|
||||
/* Save this for the view to look at. Seems like there should
|
||||
be a better way to pass it to beginDocument */
|
||||
[[_printInfo dictionary] setObject: [NSValue valueWithRect: _rect]
|
||||
forKey: @"NSPrintSheetBounds"];
|
||||
|
||||
[_view beginDocument];
|
||||
|
||||
[_view beginPageInRect: _rect
|
||||
atPlacement: NSMakePoint(0,0)];
|
||||
|
||||
[_view displayRectIgnoringOpacity: _rect];
|
||||
[_view endDocument];
|
||||
}
|
||||
|
||||
- (BOOL)isEPSOperation
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)deliverResult
|
||||
{
|
||||
if (_data != nil && _path != nil)
|
||||
{
|
||||
NSString *eps;
|
||||
|
||||
eps = [NSString stringWithContentsOfFile: _path];
|
||||
|
||||
[_data setData: [eps dataUsingEncoding:NSASCIIStringEncoding]];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSGraphicsContext*)createContext
|
||||
{
|
||||
NSMutableDictionary *info;
|
||||
|
||||
if (_context)
|
||||
return _context;
|
||||
|
||||
info = [_printInfo dictionary];
|
||||
|
||||
[info setObject: _path
|
||||
forKey: @"NSOutputFile"];
|
||||
|
||||
[info setObject: NSGraphicsContextPSFormat
|
||||
forKey: NSGraphicsContextRepresentationFormatAttributeName];
|
||||
|
||||
_context = RETAIN([NSGraphicsContext graphicsContextWithAttributes: info]);
|
||||
return _context;
|
||||
}
|
||||
|
||||
@end
|
112
Source/GSPDFPrintOperation.m
Normal file
112
Source/GSPDFPrintOperation.m
Normal file
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
GSPDFPrintOperation.m
|
||||
|
||||
Controls operations generating PDF output files.
|
||||
|
||||
Copyright (C) 1996, 2004 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
Author: Fred Kiefer <FredKiefer@gmx.de>
|
||||
Date: November 2000
|
||||
Started implementation.
|
||||
Author: Chad Hardin <cehardin@mac.com>
|
||||
Date: June 2004
|
||||
Modified for printing backend support, split off from NSPrintOperation.m
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <Foundation/NSPathUtilities.h>
|
||||
#include <Foundation/NSTask.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include "AppKit/NSView.h"
|
||||
#include "GNUstepGUI/GSPDFPrintOperation.h"
|
||||
|
||||
|
||||
/**
|
||||
<unit>
|
||||
<heading>Class Description</heading>
|
||||
<p>
|
||||
GSPDFPrintOperation produces PDF files for saving, previewing, etc
|
||||
</p>
|
||||
</unit>
|
||||
*/
|
||||
|
||||
|
||||
@implementation GSPDFPrintOperation
|
||||
|
||||
- (id) initWithView:(NSView *)aView
|
||||
insideRect:(NSRect)rect
|
||||
toData:(NSMutableData *)data
|
||||
printInfo:(NSPrintInfo*)aPrintInfo
|
||||
{
|
||||
self = [super initWithView: aView
|
||||
insideRect: rect
|
||||
toData: data
|
||||
printInfo: aPrintInfo];
|
||||
|
||||
_path = [NSTemporaryDirectory() stringByAppendingPathComponent: @"GSPrint-"];
|
||||
|
||||
_path = [_path stringByAppendingString:
|
||||
[[NSProcessInfo processInfo] globallyUniqueString]];
|
||||
|
||||
_path = [_path stringByAppendingPathExtension: @"pdf"];
|
||||
RETAIN( _path );
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithView:(NSView *)aView
|
||||
insideRect:(NSRect)rect
|
||||
toPath:(NSString *)path
|
||||
printInfo:(NSPrintInfo*)aPrintInfo
|
||||
{
|
||||
NSMutableData *data = [NSMutableData data];
|
||||
|
||||
self = [super initWithView: aView
|
||||
insideRect: rect
|
||||
toData: data
|
||||
printInfo: aPrintInfo];
|
||||
|
||||
ASSIGN(_path, path);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSGraphicsContext*)createContext
|
||||
{
|
||||
// FIXME
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) _print
|
||||
{
|
||||
[_view displayRectIgnoringOpacity: _rect];
|
||||
}
|
||||
|
||||
- (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
|
171
Source/GSPrintOperation.m
Normal file
171
Source/GSPrintOperation.m
Normal file
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
GSPrintOperation.m
|
||||
|
||||
Controls operations generating print jobs.
|
||||
|
||||
Copyright (C) 1996,2004 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
Author: Fred Kiefer <FredKiefer@gmx.de>
|
||||
Date: November 2000
|
||||
Started implementation.
|
||||
Author: Chad Hardin <cehardin@mac.com>
|
||||
Date: June 2004
|
||||
Modified for printing backend support, split off from NSPrintOperation.m
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSTask.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include "AppKit/NSView.h"
|
||||
#include "AppKit/NSPrintPanel.h"
|
||||
#include "AppKit/NSPrintInfo.h"
|
||||
#include "AppKit/NSWorkspace.h"
|
||||
#include "GNUstepGUI/GSPrinting.h"
|
||||
#include "GNUstepGUI/GSPrintOperation.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
<unit>
|
||||
<heading>Class Description</heading>
|
||||
<p>
|
||||
GSPrintOperation is a generic class that should be subclasses
|
||||
by printing backend classes for the purpose of controlling and
|
||||
sending print jobs to a printing system.
|
||||
</p>
|
||||
</unit>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
@implementation GSPrintOperation
|
||||
|
||||
/** Load the appropriate bundle for the PrintInfo
|
||||
(eg: GSLPRPrintInfo, GSCUPSPrintInfo).
|
||||
*/
|
||||
+ (id) allocWithZone: (NSZone*) zone
|
||||
{
|
||||
Class principalClass;
|
||||
|
||||
principalClass = [[GSPrinting printingBundle] principalClass];
|
||||
|
||||
if( principalClass == nil )
|
||||
return nil;
|
||||
|
||||
return [[principalClass gsPrintOperationClass] allocWithZone: zone];
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (id)initWithView:(NSView *)aView
|
||||
printInfo:(NSPrintInfo *)aPrintInfo
|
||||
{
|
||||
|
||||
self = [self initWithView: aView
|
||||
insideRect: [aView bounds]
|
||||
toData: [NSMutableData data]
|
||||
printInfo: aPrintInfo];
|
||||
|
||||
_showPanels = YES;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSGraphicsContext*)createContext
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/ !!!Here is the method that will be overridden in the printer bundle
|
||||
*/
|
||||
- (BOOL) _deliverSpooledResult
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) deliverResult
|
||||
{
|
||||
BOOL success;
|
||||
NSString *job;
|
||||
|
||||
success = YES;
|
||||
job = [_printInfo jobDisposition];
|
||||
if ([job isEqual: NSPrintPreviewJob])
|
||||
{
|
||||
/* Check to see if there is a GNUstep app that can preview PS files.
|
||||
It's not likely at this point, so also check for a standards
|
||||
previewer, like gv.
|
||||
*/
|
||||
NSTask *task;
|
||||
NSString *preview;
|
||||
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
||||
[_printPanel _setStatusStringValue: @"Opening in previewer..."];
|
||||
|
||||
preview = [ws getBestAppInRole: @"Viewer"
|
||||
forExtension: @"ps"];
|
||||
if (preview)
|
||||
{
|
||||
[ws openFile: _path withApplication: preview];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
|
||||
preview = [def objectForKey: @"NSPreviewApp"];
|
||||
|
||||
if (preview == nil || [preview length] == 0)
|
||||
preview = @"gv";
|
||||
|
||||
task = [NSTask new];
|
||||
[task setLaunchPath: preview];
|
||||
[task setArguments: [NSArray arrayWithObject: _path]];
|
||||
[task launch];
|
||||
AUTORELEASE(task);
|
||||
}
|
||||
}
|
||||
else if ([job isEqual: NSPrintSpoolJob])
|
||||
{
|
||||
success = [self _deliverSpooledResult];
|
||||
}
|
||||
else if ([job isEqual: NSPrintFaxJob])
|
||||
{
|
||||
}
|
||||
|
||||
/* We can't remove the temp file because the previewer might still be
|
||||
using it, perhaps the printer is also?
|
||||
if ( _path )
|
||||
{
|
||||
[[NSFileManager defaultManager] removeFileAtPath: _path
|
||||
handler: nil];
|
||||
}
|
||||
*/
|
||||
return success;
|
||||
}
|
||||
|
||||
@end
|
||||
|
234
Source/GSPrinting.m
Normal file
234
Source/GSPrinting.m
Normal file
|
@ -0,0 +1,234 @@
|
|||
/** <title>GSPrinting.m</title>
|
||||
|
||||
<abstract>GSPrinting loads the proper bundle for the printing backend.</abstract>
|
||||
|
||||
Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
|
||||
Author: Chad Elliott Hardin <cehardin@mac.com>
|
||||
Date: June 2004
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "GNUstepGUI/GSPrinting.h"
|
||||
#include <Foundation/NSBundle.h>
|
||||
#include <Foundation/NSEnumerator.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSPathUtilities.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include "AppKit/NSPanel.h"
|
||||
|
||||
static NSBundle *printingBundle = nil;
|
||||
|
||||
|
||||
/**
|
||||
<unit>
|
||||
<heading>Class Description</heading>
|
||||
<p>
|
||||
GSPrinting is used by all of the NSPrint and the NSPageLayout
|
||||
class(es) so that a printing backend bundle can be loaded. It
|
||||
first utilizes NSUserDefaults to find the user's preferred printing
|
||||
backend bundle. It looks for the key GSPrinting. If the user's
|
||||
preferred bundle cannot be loaded, it tries to load any working
|
||||
printing bundle.
|
||||
</p>
|
||||
</unit>
|
||||
*/
|
||||
@implementation GSPrinting
|
||||
|
||||
+(NSBundle*) loadPrintingBundle: (NSString*) bundleName
|
||||
{
|
||||
NSString *path;
|
||||
NSEnumerator *libraryPathsEnumerator;
|
||||
|
||||
bundleName = [bundleName stringByAppendingString: @".bundle"];
|
||||
|
||||
NSDebugLLog(@"GSPrinting", @"Looking for %@", bundleName);
|
||||
|
||||
libraryPathsEnumerator = [NSStandardLibraryPaths() objectEnumerator];
|
||||
|
||||
while( (path = [libraryPathsEnumerator nextObject]) )
|
||||
{
|
||||
path = [path stringByAppendingPathComponent: @"Bundles"];
|
||||
path = [path stringByAppendingPathComponent: @"GSPrinting"];
|
||||
path = [path stringByAppendingPathComponent: bundleName];
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath: path])
|
||||
{
|
||||
NSBundle *bundle;
|
||||
|
||||
bundle = [NSBundle bundleWithPath: path];
|
||||
if( [bundle load] == NO )
|
||||
{
|
||||
NSDebugLLog(@"GSPrinting", @"Error loading printing bundle at %@", path);
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
//one last check to make sure the principle class can be loaded
|
||||
if( [bundle principalClass] == Nil)
|
||||
{
|
||||
NSDebugLLog(@"GSPrinting", @"Error loading principal class from printing bundle at %@", path);
|
||||
return nil;
|
||||
}
|
||||
//if we get here, finally, then everything should be ok, barring errors from later in loading resources.
|
||||
NSDebugLLog(@"GSPrinting", @"Loaded printing bundle at %@", path);
|
||||
return bundle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSDebugLLog(@"GSPrinting", @"Unable to find printing bundle %@", bundleName);
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+(NSBundle*) loadAnyWorkingPrintingBundle
|
||||
{
|
||||
NSBundle *bundle;
|
||||
|
||||
if( (bundle = [GSPrinting loadPrintingBundle: @"GSCUPS"]) )
|
||||
return bundle;
|
||||
|
||||
if( (bundle = [GSPrinting loadPrintingBundle: @"GSLPR"]) )
|
||||
return bundle;
|
||||
|
||||
if( (bundle = [GSPrinting loadPrintingBundle: @"GSWin32"]) )
|
||||
return bundle;
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+ (NSBundle*) printingBundle
|
||||
{
|
||||
NSString *defaultBundleName;
|
||||
NSBundle *bundle;
|
||||
|
||||
if( printingBundle )
|
||||
{
|
||||
return printingBundle;
|
||||
}
|
||||
|
||||
NSDebugLLog(@"GSPrinting", @"Bundle has not been loaded. Loading in progress...");
|
||||
|
||||
defaultBundleName = [[NSUserDefaults standardUserDefaults] stringForKey: @"GSPrinting"];
|
||||
|
||||
/*Which Printing Bundle?*/
|
||||
if( defaultBundleName == nil )
|
||||
{
|
||||
NSDebugLLog(@"GSPrinting", @"User did not set a printing bundle, trying till something works");
|
||||
bundle = [GSPrinting loadAnyWorkingPrintingBundle];
|
||||
if( bundle == nil )
|
||||
{
|
||||
NSDebugLLog(@"GSPrinting", @"Could not load any working printing bundle");
|
||||
NSRunAlertPanel(@"GNUstep Printing Backend System", @"Could not open any working printing bundle. Printing will not work.", @"Ok", NULL, NULL );
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDebugLLog(@"GSPrinting", @"User set %@ as the printing bundle", defaultBundleName);
|
||||
|
||||
bundle = [GSPrinting loadPrintingBundle: defaultBundleName];
|
||||
if( bundle == nil )
|
||||
{
|
||||
NSDebugLLog(@"GSPrinting", @"User set %@ as the printing bundle but that did not work. Will try to find anything that will work", defaultBundleName);
|
||||
bundle = [GSPrinting loadAnyWorkingPrintingBundle];
|
||||
if( bundle == nil )
|
||||
{
|
||||
NSDebugLLog(@"GSPrinting", @"Could not load any working printing bundle");
|
||||
NSRunAlertPanel(@"GNUstep Printing Backend System", @"Could not open any working printing bundle. Printing will not work.", @"Ok", NULL, NULL );
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *msg;
|
||||
msg = [NSString stringWithFormat: @"Your chosen printing bundle, %@, could not be loaded. %@ was loaded instead", defaultBundleName, [[bundle bundlePath] lastPathComponent]];
|
||||
NSRunAlertPanel(@"GNUstep Printing Backend System", msg, @"Ok", NULL, NULL );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printingBundle = bundle;
|
||||
[printingBundle retain];
|
||||
return printingBundle;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
<unit>
|
||||
<heading>Class Description</heading>
|
||||
<p>
|
||||
GSPrintingPrincipleClass is the base class that all
|
||||
Printing backend bundles should use as their principle
|
||||
class. Subclasses are responsible for the allocating
|
||||
of that bundle's particular NSPrint, NSPageLayout, and
|
||||
GSPrintOperation sublclassed objects.
|
||||
</p>
|
||||
</unit>
|
||||
*/
|
||||
@implementation GSPrintingPrincipalClass : NSObject
|
||||
{
|
||||
}
|
||||
|
||||
+(Class) pageLayoutClass
|
||||
{
|
||||
return Nil;
|
||||
}
|
||||
|
||||
+(Class) printInfoClass
|
||||
{
|
||||
return Nil;
|
||||
}
|
||||
|
||||
|
||||
+(Class) printOperationClass
|
||||
{
|
||||
return Nil;
|
||||
}
|
||||
|
||||
+(Class) printPanelClass
|
||||
{
|
||||
return Nil;
|
||||
}
|
||||
|
||||
|
||||
+(Class) printerClass
|
||||
{
|
||||
return Nil;
|
||||
}
|
||||
|
||||
+(Class) gsPrintOperationClass
|
||||
{
|
||||
return Nil;
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -2,10 +2,13 @@
|
|||
|
||||
<abstract>Standard panel for querying user about page layout.</abstract>
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
Copyright (C) 2001,2004 Free Software Foundation, Inc.
|
||||
|
||||
Written By: Adam Fedor <fedor@gnu.org>
|
||||
Date: Oct 2001
|
||||
Modified for Printing Backend Support
|
||||
Author: Chad Hardin <cehardin@mac.com>
|
||||
Date: June 2004
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -43,6 +46,7 @@
|
|||
#include "AppKit/NSPageLayout.h"
|
||||
#include "AppKit/NSPrinter.h"
|
||||
#include "GSGuiPrivate.h"
|
||||
#include "GNUstepGUI/GSPrinting.h"
|
||||
|
||||
static NSPageLayout *shared_instance;
|
||||
|
||||
|
@ -82,6 +86,22 @@ static NSPageLayout *shared_instance;
|
|||
//
|
||||
// Class methods
|
||||
//
|
||||
/** Load the appropriate bundle for the PageLayout
|
||||
(eg: GSLPRPageLayout, GSCUPSPageLayout).
|
||||
*/
|
||||
+ (id) allocWithZone: (NSZone*) zone
|
||||
{
|
||||
Class principalClass;
|
||||
|
||||
principalClass = [[GSPrinting printingBundle] principalClass];
|
||||
|
||||
if( principalClass == nil )
|
||||
return nil;
|
||||
|
||||
return [[principalClass pageLayoutClass] allocWithZone: zone];
|
||||
}
|
||||
|
||||
|
||||
/** Creates and returns a shared instance of the NSPageLayout panel.
|
||||
*/
|
||||
+ (NSPageLayout *)pageLayout
|
||||
|
@ -403,7 +423,7 @@ static NSPageLayout *shared_instance;
|
|||
- (void)pickedButton:(id)sender
|
||||
{
|
||||
NSLog(@"[NSPageLayout -pickedButton:] method depreciated");
|
||||
[self pickedButton: sender];
|
||||
//[self pickedButton: sender];
|
||||
}
|
||||
|
||||
/** This method has been depreciated. It doesn't do anything useful.
|
||||
|
|
|
@ -3,10 +3,13 @@
|
|||
|
||||
Stores information used in printing
|
||||
|
||||
Copyright (C) 1996,1997 Free Software Foundation, Inc.
|
||||
Copyright (C) 1996,1997,2004 Free Software Foundation, Inc.
|
||||
|
||||
Author: Simon Frankau <sgf@frankau.demon.co.uk>
|
||||
Date: July 1997
|
||||
Modified for Printing Backend Support
|
||||
Author: Chad Hardin <cehardin@mac.com>
|
||||
Date: June 2004
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -35,8 +38,8 @@
|
|||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include "AppKit/NSPrinter.h"
|
||||
|
||||
#include "AppKit/NSPrintInfo.h"
|
||||
#include "GNUstepGUI/GSPrinting.h"
|
||||
|
||||
#define NSNUMBER(val) [NSNumber numberWithInt: val]
|
||||
#define DICTSET(dict, obj, key) \
|
||||
|
@ -45,12 +48,8 @@
|
|||
// FIXME: retain/release of dictionary with retain/release of printInfo?
|
||||
|
||||
// Class variables:
|
||||
static NSPrintInfo *sharedPrintInfoObject = nil;
|
||||
static NSMutableDictionary *printInfoDefaults = nil;
|
||||
static NSPrintInfo *sharedPrintInfo = nil;
|
||||
|
||||
@interface NSPrintInfo (private)
|
||||
+ initPrintInfoDefaults;
|
||||
@end
|
||||
|
||||
/**
|
||||
<unit>
|
||||
|
@ -76,24 +75,36 @@ static NSMutableDictionary *printInfoDefaults = nil;
|
|||
}
|
||||
}
|
||||
|
||||
/** Load the appropriate bundle for the PrintInfo
|
||||
(eg: GSLPRPrintInfo, GSCUPSPrintInfo).
|
||||
*/
|
||||
+ (id) allocWithZone: (NSZone*) zone
|
||||
{
|
||||
Class principalClass;
|
||||
|
||||
principalClass = [[GSPrinting printingBundle] principalClass];
|
||||
|
||||
if( principalClass == nil )
|
||||
return nil;
|
||||
|
||||
return [[principalClass printInfoClass] allocWithZone: zone];
|
||||
}
|
||||
|
||||
//
|
||||
// Managing the Shared NSPrintInfo Object
|
||||
//
|
||||
+ (void)setSharedPrintInfo:(NSPrintInfo *)printInfo
|
||||
{
|
||||
sharedPrintInfoObject = printInfo;
|
||||
ASSIGN(sharedPrintInfo, printInfo);
|
||||
}
|
||||
|
||||
+ (NSPrintInfo *)sharedPrintInfo
|
||||
{
|
||||
if (!sharedPrintInfoObject)
|
||||
{
|
||||
if (!printInfoDefaults)
|
||||
[NSPrintInfo initPrintInfoDefaults];
|
||||
sharedPrintInfoObject = [[self alloc]
|
||||
initWithDictionary:printInfoDefaults];
|
||||
}
|
||||
return sharedPrintInfoObject;
|
||||
if (!sharedPrintInfo)
|
||||
{
|
||||
sharedPrintInfo = [[NSPrintInfo alloc] initWithDictionary: nil];
|
||||
}
|
||||
return sharedPrintInfo;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -109,16 +120,26 @@ static NSMutableDictionary *printInfoDefaults = nil;
|
|||
//
|
||||
+ (NSPrinter *)defaultPrinter
|
||||
{
|
||||
if (!printInfoDefaults)
|
||||
[NSPrintInfo initPrintInfoDefaults];
|
||||
return [printInfoDefaults objectForKey:NSPrintPrinter];
|
||||
Class principalClass;
|
||||
|
||||
principalClass = [[GSPrinting printingBundle] principalClass];
|
||||
|
||||
if( principalClass == nil )
|
||||
return nil;
|
||||
|
||||
return [[principalClass printInfoClass] defaultPrinter];
|
||||
}
|
||||
|
||||
+ (void)setDefaultPrinter:(NSPrinter *)printer
|
||||
{
|
||||
if (!printInfoDefaults)
|
||||
[NSPrintInfo initPrintInfoDefaults];
|
||||
[printInfoDefaults setObject:printer forKey:NSPrintPrinter];
|
||||
Class principalClass;
|
||||
|
||||
principalClass = [[GSPrinting printingBundle] principalClass];
|
||||
|
||||
if( principalClass == nil )
|
||||
return;
|
||||
|
||||
[[principalClass printInfoClass] setDefaultPrinter: printer];
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -130,7 +151,40 @@ static NSMutableDictionary *printInfoDefaults = nil;
|
|||
- (id)initWithDictionary:(NSDictionary *)aDict
|
||||
{
|
||||
[super init];
|
||||
_info = [[NSMutableDictionary alloc] initWithDictionary:aDict];
|
||||
|
||||
_info = [[NSMutableDictionary alloc] init];
|
||||
|
||||
//put in the defaults
|
||||
[self setVerticalPagination: NSAutoPagination];
|
||||
|
||||
[self setHorizontalPagination: NSClipPagination];
|
||||
|
||||
[self setJobDisposition: NSPrintSpoolJob];
|
||||
|
||||
[self setHorizontallyCentered: YES];
|
||||
|
||||
[self setVerticallyCentered: YES];
|
||||
|
||||
[self setOrientation: NSPortraitOrientation];
|
||||
|
||||
if( aDict != nil )
|
||||
{
|
||||
[_info addEntriesFromDictionary: aDict];
|
||||
|
||||
if([[_info objectForKey: NSPrintPrinter] isKindOfClass: [NSString class]])
|
||||
{
|
||||
NSString *printerName;
|
||||
NSPrinter *printer;
|
||||
|
||||
printerName = [_info objectForKey: NSPrintPrinter];
|
||||
printer = [NSPrinter printerWithName: printerName];
|
||||
|
||||
if( printer )
|
||||
[self setPrinter: printer];
|
||||
else
|
||||
[_info removeObjectForKey: NSPrintPrinter];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -330,20 +384,7 @@ static NSMutableDictionary *printInfoDefaults = nil;
|
|||
|
||||
- (void)setUpPrintOperationDefaultValues
|
||||
{
|
||||
NSEnumerator *keys, *objects;
|
||||
NSString *key;
|
||||
id object;
|
||||
|
||||
if (!printInfoDefaults)
|
||||
[NSPrintInfo initPrintInfoDefaults];
|
||||
keys = [printInfoDefaults keyEnumerator];
|
||||
objects = [printInfoDefaults objectEnumerator];
|
||||
while ((key = [keys nextObject]))
|
||||
{
|
||||
object = [objects nextObject];
|
||||
if (![_info objectForKey:key])
|
||||
[_info setObject:object forKey:key];
|
||||
}
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -359,73 +400,34 @@ static NSMutableDictionary *printInfoDefaults = nil;
|
|||
//
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
//There is a NSPrinter in the dict, will that work as a Property list?
|
||||
NSMutableDictionary *dict;
|
||||
|
||||
dict = AUTORELEASE([_info mutableCopy]);
|
||||
|
||||
[dict setObject: [[self printer] name]
|
||||
forKey: NSPrintPrinter];
|
||||
|
||||
[aCoder encodePropertyList: _info];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)aDecoder
|
||||
{
|
||||
NSString *printerName;
|
||||
NSPrinter *printer;
|
||||
|
||||
_info = RETAIN([aDecoder decodePropertyList]);
|
||||
return self;
|
||||
}
|
||||
|
||||
//
|
||||
// Private method to initialise printing defaults dictionary
|
||||
//
|
||||
+ initPrintInfoDefaults
|
||||
{
|
||||
NSUserDefaults *def;
|
||||
NSString *defPrinter, *str;
|
||||
NSPrinter *printer = nil;
|
||||
|
||||
def = [NSUserDefaults standardUserDefaults];
|
||||
printInfoDefaults = [def objectForKey: @"DefaultPrinter"];
|
||||
if (printInfoDefaults)
|
||||
printInfoDefaults = [printInfoDefaults mutableCopy];
|
||||
defPrinter = [printInfoDefaults objectForKey:NSPrintPrinter];
|
||||
if (defPrinter)
|
||||
printer = [NSPrinter printerWithName: defPrinter];
|
||||
if (printer == nil)
|
||||
defPrinter = nil;
|
||||
if (printInfoDefaults == nil)
|
||||
{
|
||||
NSDebugLog(@"NSPrinter", @"Could not find printing defaults table");
|
||||
printInfoDefaults = RETAIN([NSMutableDictionary dictionary]);
|
||||
}
|
||||
if (defPrinter == nil)
|
||||
{
|
||||
defPrinter = [[NSPrinter printerNames] objectAtIndex: 0];
|
||||
DICTSET(printInfoDefaults, defPrinter, NSPrintPrinter);
|
||||
}
|
||||
|
||||
/* Replace the printer name with a real NSPrinter object */
|
||||
printer = [NSPrinter printerWithName: defPrinter];
|
||||
DICTSET(printInfoDefaults, [NSPrinter printerWithName: defPrinter], NSPrintPrinter);
|
||||
|
||||
/* Set up other defaults from the printer object */
|
||||
str = [printer stringForKey:@"DefaultPageSize" inTable: @"PPD"];
|
||||
/* FIXME: Need to check for AutoSelect and probably a million other things... */
|
||||
if (str == nil)
|
||||
str = @"A4";
|
||||
DICTSET(printInfoDefaults, str, NSPrintPaperName);
|
||||
DICTSET(printInfoDefaults,
|
||||
[NSValue valueWithSize: [NSPrintInfo sizeForPaperName: str]],
|
||||
NSPrintPaperSize);
|
||||
|
||||
/* Set default margins. FIXME: Probably should check ImageableArea */
|
||||
DICTSET(printInfoDefaults, NSNUMBER(36), NSPrintRightMargin);
|
||||
DICTSET(printInfoDefaults, NSNUMBER(36), NSPrintLeftMargin);
|
||||
DICTSET(printInfoDefaults, NSNUMBER(72), NSPrintTopMargin);
|
||||
DICTSET(printInfoDefaults, NSNUMBER(72), NSPrintBottomMargin);
|
||||
DICTSET(printInfoDefaults, NSNUMBER(NSPortraitOrientation),
|
||||
NSPrintOrientation);
|
||||
//DICTSET(printInfoDefaults, NSNUMBER(NSClipPagination),
|
||||
// NSPrintHorizontalPagination);
|
||||
DICTSET(printInfoDefaults, NSNUMBER(NSAutoPagination),
|
||||
NSPrintVerticalPagination);
|
||||
DICTSET(printInfoDefaults, NSNUMBER(1), NSPrintHorizontallyCentered);
|
||||
DICTSET(printInfoDefaults, NSNUMBER(1), NSPrintVerticallyCentered);
|
||||
|
||||
|
||||
printerName = [_info objectForKey: NSPrintPrinter];
|
||||
printer = [NSPrinter printerWithName: printerName];
|
||||
|
||||
if( printer )
|
||||
[self setPrinter: printer];
|
||||
else
|
||||
[_info removeObjectForKey: NSPrintPrinter];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
/*
|
||||
NSPrintOperation.m
|
||||
|
||||
Controls operations generating EPS, PDF or PS print jobs.
|
||||
Controls operations generating print jobs.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
Copyright (C) 1996,2004 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 <cehardin@mac.com>
|
||||
Date: June 2004
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -52,6 +55,9 @@
|
|||
#include "AppKit/NSPrintOperation.h"
|
||||
#include "AppKit/NSWorkspace.h"
|
||||
#include "AppKit/PSOperators.h"
|
||||
#include "GNUstepGUI/GSEPSPrintOperation.h"
|
||||
#include "GNUstepGUI/GSPDFPrintOperation.h"
|
||||
#include "GNUstepGUI/GSPrintOperation.h"
|
||||
|
||||
#define NSNUMBER(a) [NSNumber numberWithInt: (a)]
|
||||
#define NSFNUMBER(a) [NSNumber numberWithFloat: (a)]
|
||||
|
@ -75,20 +81,27 @@ typedef struct _page_info_t {
|
|||
int pageDirection; /* NSPrintPageDirection */
|
||||
} page_info_t;
|
||||
|
||||
@interface NSPrintOperation (Private)
|
||||
|
||||
- (id) initWithView:(NSView *)aView
|
||||
insideRect:(NSRect)rect
|
||||
toData:(NSMutableData *)data
|
||||
printInfo:(NSPrintInfo *)aPrintInfo;
|
||||
|
||||
@interface NSPrintOperation (TrulyPrivate)
|
||||
- (BOOL) _runOperation;
|
||||
- (void) _setupPrintInfo;
|
||||
- (void)_printOperationDidRun:(NSPrintOperation *)printOperation
|
||||
success:(BOOL)success
|
||||
contextInfo:(void *)contextInfo;
|
||||
- (void) _printPaginateWithInfo: (page_info_t *)info
|
||||
knowsRange: (BOOL)knowsRange;
|
||||
- (NSRect) _rectForPage: (int)page info: (page_info_t *)info
|
||||
xpage: (int *)xptr
|
||||
ypage: (int *)yptr;
|
||||
- (NSRect) _adjustPagesFirst: (int)first
|
||||
last: (int)last
|
||||
info: (page_info_t *)info;
|
||||
- (void) _print;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSPrintPanel (Private)
|
||||
- (void) _setStatusStringValue: (NSString *)string;
|
||||
@end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@interface NSView (NSPrintOperation)
|
||||
|
@ -102,40 +115,7 @@ typedef struct _page_info_t {
|
|||
- (void) _cleanupPrinting;
|
||||
@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
|
||||
insideRect:(NSRect)rect
|
||||
toData:(NSMutableData *)data
|
||||
printInfo:(NSPrintInfo*)aPrintInfo;
|
||||
- (id) initPDFOperationWithView:(NSView *)aView
|
||||
insideRect:(NSRect)rect
|
||||
toPath:(NSString *)path
|
||||
printInfo:(NSPrintInfo*)aPrintInfo;
|
||||
|
||||
@end
|
||||
|
||||
static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||
|
||||
|
@ -186,7 +166,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
|||
toData:(NSMutableData *)data
|
||||
printInfo:(NSPrintInfo *)aPrintInfo
|
||||
{
|
||||
return AUTORELEASE([[GSEPSPrintOperation alloc] initEPSOperationWithView: aView
|
||||
return AUTORELEASE([[GSEPSPrintOperation alloc] initWithView: aView
|
||||
insideRect: rect
|
||||
toData: data
|
||||
printInfo: aPrintInfo]);
|
||||
|
@ -197,7 +177,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
|||
toPath:(NSString *)path
|
||||
printInfo:(NSPrintInfo *)aPrintInfo
|
||||
{
|
||||
return AUTORELEASE([[GSEPSPrintOperation alloc] initEPSOperationWithView: aView
|
||||
return AUTORELEASE([[GSEPSPrintOperation alloc] initWithView: aView
|
||||
insideRect: rect
|
||||
toPath: path
|
||||
printInfo: aPrintInfo]);
|
||||
|
@ -232,7 +212,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
|||
printInfo:(NSPrintInfo*)aPrintInfo
|
||||
{
|
||||
return AUTORELEASE([[GSPDFPrintOperation alloc]
|
||||
initPDFOperationWithView: aView
|
||||
initWithView: aView
|
||||
insideRect: rect
|
||||
toData: data
|
||||
printInfo: aPrintInfo]);
|
||||
|
@ -244,7 +224,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
|||
printInfo:(NSPrintInfo*)aPrintInfo
|
||||
{
|
||||
return AUTORELEASE([[GSPDFPrintOperation alloc]
|
||||
initPDFOperationWithView: aView
|
||||
initWithView: aView
|
||||
insideRect: rect
|
||||
toPath: path
|
||||
printInfo: aPrintInfo]);
|
||||
|
@ -293,7 +273,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
|||
{
|
||||
RELEASE(self);
|
||||
|
||||
return [[GSEPSPrintOperation alloc] initEPSOperationWithView: aView
|
||||
return [[GSEPSPrintOperation alloc] initWithView: aView
|
||||
insideRect: rect
|
||||
toData: data
|
||||
printInfo: aPrintInfo];
|
||||
|
@ -466,64 +446,6 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
|||
return NO;
|
||||
}
|
||||
|
||||
/* Private method to run the printing operation. Needs to create an
|
||||
autoreleaes pool to make sure the print context is destroyed before
|
||||
returning (which closes the print file.) */
|
||||
- (BOOL) _runOperation
|
||||
{
|
||||
BOOL result;
|
||||
CREATE_AUTORELEASE_POOL(pool);
|
||||
NSGraphicsContext *oldContext = [NSGraphicsContext currentContext];
|
||||
|
||||
[self createContext];
|
||||
if (_context == nil)
|
||||
return NO;
|
||||
|
||||
result = NO;
|
||||
if (_pageOrder == NSUnknownPageOrder)
|
||||
{
|
||||
if ([[[_printInfo dictionary] objectForKey: NSPrintReversePageOrder]
|
||||
boolValue] == YES)
|
||||
_pageOrder = NSDescendingPageOrder;
|
||||
else
|
||||
_pageOrder = NSAscendingPageOrder;
|
||||
}
|
||||
|
||||
[NSGraphicsContext setCurrentContext: _context];
|
||||
NS_DURING
|
||||
{
|
||||
[self _print];
|
||||
result = YES;
|
||||
[NSGraphicsContext setCurrentContext: oldContext];
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
[_view _cleanupPrinting];
|
||||
[NSGraphicsContext setCurrentContext: oldContext];
|
||||
NSRunAlertPanel(@"Error", @"Printing error: %@",
|
||||
@"OK", NULL, NULL, localException);
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
[self destroyContext];
|
||||
RELEASE(pool);
|
||||
return result;
|
||||
}
|
||||
|
||||
- (void) _setupPrintInfo
|
||||
{
|
||||
BOOL knowsPageRange;
|
||||
NSRange viewPageRange;
|
||||
NSMutableDictionary *dict = [_printInfo dictionary];
|
||||
|
||||
knowsPageRange = [_view knowsPageRange: &viewPageRange];
|
||||
if (knowsPageRange == YES)
|
||||
{
|
||||
int first = viewPageRange.location;
|
||||
int last = NSMaxRange(viewPageRange) - 1;
|
||||
[dict setObject: NSNUMBER(first) forKey: NSPrintFirstPage];
|
||||
[dict setObject: NSNUMBER(last) forKey: NSPrintLastPage];
|
||||
}
|
||||
}
|
||||
|
||||
/** Call this message to run the print operation on a view. This includes
|
||||
(optionally) displaying a print panel and working with the NSView to
|
||||
|
@ -560,31 +482,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
|||
return result;
|
||||
}
|
||||
|
||||
- (void)_printOperationDidRun:(NSPrintOperation *)printOperation
|
||||
success:(BOOL)success
|
||||
contextInfo:(void *)contextInfo
|
||||
{
|
||||
id delegate;
|
||||
SEL *didRunSelector;
|
||||
NSMutableDictionary *dict;
|
||||
void (*didRun)(id, SEL, BOOL, id);
|
||||
|
||||
if (success == YES)
|
||||
{
|
||||
NSPrintPanel *panel = [self printPanel];
|
||||
[panel finalWritePrintInfo];
|
||||
success = NO;
|
||||
if ([self _runOperation])
|
||||
success = [self deliverResult];
|
||||
}
|
||||
[self cleanUpOperation];
|
||||
dict = [_printInfo dictionary];
|
||||
didRunSelector = [[dict objectForKey: @"GSModalRunSelector"] pointerValue];
|
||||
delegate = [dict objectForKey: @"GSModalRunDelegate"];
|
||||
didRun = (void (*)(id, SEL, BOOL, id))[delegate methodForSelector:
|
||||
*didRunSelector];
|
||||
didRun (delegate, *didRunSelector, success, contextInfo);
|
||||
}
|
||||
|
||||
/** Run a print operation modally with respect to a window.
|
||||
*/
|
||||
|
@ -659,8 +557,10 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
|||
printInfo:(NSPrintInfo *)aPrintInfo
|
||||
{
|
||||
if ([NSPrintOperation currentOperation] != nil)
|
||||
[NSException raise: NSPrintOperationExistsException
|
||||
format: @"There is already a printoperation for this thread"];
|
||||
{
|
||||
[NSException raise: NSPrintOperationExistsException
|
||||
format: @"There is already a printoperation for this thread"];
|
||||
}
|
||||
|
||||
ASSIGN(_view, aView);
|
||||
_rect = rect;
|
||||
|
@ -668,18 +568,105 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
|||
_pageOrder = NSUnknownPageOrder;
|
||||
_showPanels = NO;
|
||||
[self setPrintInfo: aPrintInfo];
|
||||
|
||||
_path = [NSTemporaryDirectory() stringByAppendingPathComponent: @"GSPrint-"];
|
||||
_path = [_path stringByAppendingString:
|
||||
[[NSProcessInfo processInfo] globallyUniqueString]];
|
||||
_path = [_path stringByAppendingPathExtension: @"ps"];
|
||||
RETAIN(_path);
|
||||
_pathSet = NO;
|
||||
_path = nil;
|
||||
_currentPage = 0;
|
||||
|
||||
[NSPrintOperation setCurrentOperation: self];
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSPrintOperation (TrulyPrivate)
|
||||
|
||||
|
||||
/* Private method to run the printing operation. Needs to create an
|
||||
autoreleaes pool to make sure the print context is destroyed before
|
||||
returning (which closes the print file.) */
|
||||
- (BOOL) _runOperation
|
||||
{
|
||||
BOOL result;
|
||||
CREATE_AUTORELEASE_POOL(pool);
|
||||
NSGraphicsContext *oldContext = [NSGraphicsContext currentContext];
|
||||
|
||||
[self createContext];
|
||||
if (_context == nil)
|
||||
return NO;
|
||||
|
||||
result = NO;
|
||||
if (_pageOrder == NSUnknownPageOrder)
|
||||
{
|
||||
if ([[[_printInfo dictionary] objectForKey: NSPrintReversePageOrder]
|
||||
boolValue] == YES)
|
||||
_pageOrder = NSDescendingPageOrder;
|
||||
else
|
||||
_pageOrder = NSAscendingPageOrder;
|
||||
}
|
||||
|
||||
[NSGraphicsContext setCurrentContext: _context];
|
||||
NS_DURING
|
||||
{
|
||||
[self _print];
|
||||
result = YES;
|
||||
[NSGraphicsContext setCurrentContext: oldContext];
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
[_view _cleanupPrinting];
|
||||
[NSGraphicsContext setCurrentContext: oldContext];
|
||||
NSRunAlertPanel(@"Error", @"Printing error: %@",
|
||||
@"OK", NULL, NULL, localException);
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
[self destroyContext];
|
||||
RELEASE(pool);
|
||||
return result;
|
||||
}
|
||||
|
||||
- (void) _setupPrintInfo
|
||||
{
|
||||
BOOL knowsPageRange;
|
||||
NSRange viewPageRange;
|
||||
NSMutableDictionary *dict = [_printInfo dictionary];
|
||||
|
||||
knowsPageRange = [_view knowsPageRange: &viewPageRange];
|
||||
if (knowsPageRange == YES)
|
||||
{
|
||||
int first = viewPageRange.location;
|
||||
int last = NSMaxRange(viewPageRange) - 1;
|
||||
[dict setObject: NSNUMBER(first) forKey: NSPrintFirstPage];
|
||||
[dict setObject: NSNUMBER(last) forKey: NSPrintLastPage];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_printOperationDidRun:(NSPrintOperation *)printOperation
|
||||
success:(BOOL)success
|
||||
contextInfo:(void *)contextInfo
|
||||
{
|
||||
id delegate;
|
||||
SEL *didRunSelector;
|
||||
NSMutableDictionary *dict;
|
||||
void (*didRun)(id, SEL, BOOL, id);
|
||||
|
||||
if (success == YES)
|
||||
{
|
||||
NSPrintPanel *panel = [self printPanel];
|
||||
[panel finalWritePrintInfo];
|
||||
success = NO;
|
||||
if ([self _runOperation])
|
||||
success = [self deliverResult];
|
||||
}
|
||||
[self cleanUpOperation];
|
||||
dict = [_printInfo dictionary];
|
||||
didRunSelector = [[dict objectForKey: @"GSModalRunSelector"] pointerValue];
|
||||
delegate = [dict objectForKey: @"GSModalRunDelegate"];
|
||||
didRun = (void (*)(id, SEL, BOOL, id))[delegate methodForSelector:
|
||||
*didRunSelector];
|
||||
didRun (delegate, *didRunSelector, success, contextInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static NSSize
|
||||
scaleSize(NSSize size, double scale)
|
||||
|
@ -1113,266 +1100,3 @@ scaleRect(NSRect rect, double scale)
|
|||
}
|
||||
@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;
|
||||
if (_context)
|
||||
return _context;
|
||||
|
||||
info = [_printInfo dictionary];
|
||||
if (_pathSet == NO)
|
||||
{
|
||||
NSString *output = [info objectForKey: NSPrintSavePath];
|
||||
if (output)
|
||||
{
|
||||
ASSIGN(_path, output);
|
||||
_pathSet = YES;
|
||||
}
|
||||
}
|
||||
|
||||
[info setObject: _path forKey: @"NSOutputFile"];
|
||||
[info setObject: NSGraphicsContextPSFormat
|
||||
forKey: NSGraphicsContextRepresentationFormatAttributeName];
|
||||
_context = RETAIN([NSGraphicsContext graphicsContextWithAttributes: info]);
|
||||
|
||||
return _context;
|
||||
}
|
||||
|
||||
- (BOOL) _deliverSpooledResult
|
||||
{
|
||||
int copies;
|
||||
NSDictionary *dict;
|
||||
NSTask *task;
|
||||
NSString *name, *status;
|
||||
NSMutableArray *args;
|
||||
name = [[_printInfo printer] name];
|
||||
status = [NSString stringWithFormat: @"Spooling to printer %@.", name];
|
||||
[_printPanel _setStatusStringValue: status];
|
||||
|
||||
dict = [_printInfo dictionary];
|
||||
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;
|
||||
}
|
||||
|
||||
- (BOOL) deliverResult
|
||||
{
|
||||
BOOL success;
|
||||
NSString *job;
|
||||
|
||||
success = YES;
|
||||
job = [_printInfo jobDisposition];
|
||||
if ([job isEqual: NSPrintPreviewJob])
|
||||
{
|
||||
/* Check to see if there is a GNUstep app that can preview PS files.
|
||||
It's not likely at this point, so also check for a standards
|
||||
previewer, like gv.
|
||||
*/
|
||||
NSTask *task;
|
||||
NSString *preview;
|
||||
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
||||
[_printPanel _setStatusStringValue: @"Opening in previewer..."];
|
||||
preview = [ws getBestAppInRole: @"Viewer" forExtension: @"ps"];
|
||||
if (preview)
|
||||
{
|
||||
[ws openFile: _path withApplication: preview];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
|
||||
preview = [def objectForKey: @"NSPreviewApp"];
|
||||
if (preview == nil || [preview length] == 0)
|
||||
preview = @"gv";
|
||||
task = [NSTask new];
|
||||
[task setLaunchPath: preview];
|
||||
[task setArguments: [NSArray arrayWithObject: _path]];
|
||||
[task launch];
|
||||
AUTORELEASE(task);
|
||||
}
|
||||
}
|
||||
else if ([job isEqual: NSPrintSpoolJob])
|
||||
{
|
||||
success = [self _deliverSpooledResult];
|
||||
}
|
||||
else if ([job isEqual: NSPrintFaxJob])
|
||||
{
|
||||
}
|
||||
|
||||
/* We can't remove the temp file because the previewer might still be
|
||||
using it, perhaps the printer is also?
|
||||
if (!_pathSet)
|
||||
[[NSFileManager defaultManager] removeFileAtPath: _path
|
||||
handler: nil];
|
||||
*/
|
||||
return success;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation GSEPSPrintOperation
|
||||
|
||||
- (id)initEPSOperationWithView:(NSView *)aView
|
||||
insideRect:(NSRect)rect
|
||||
toData:(NSMutableData *)data
|
||||
printInfo:(NSPrintInfo *)aPrintInfo
|
||||
{
|
||||
self = [self initWithView: aView
|
||||
insideRect: rect
|
||||
toData: data
|
||||
printInfo: aPrintInfo];
|
||||
_pathSet = YES; /* Use the default temp path */
|
||||
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;
|
||||
}
|
||||
|
||||
- (void) _print
|
||||
{
|
||||
/* Save this for the view to look at. Seems like there should
|
||||
be a better way to pass it to beginDocument */
|
||||
[[_printInfo dictionary] setObject: [NSValue valueWithRect: _rect]
|
||||
forKey: @"NSPrintSheetBounds"];
|
||||
[_view beginDocument];
|
||||
[_view beginPageInRect: _rect atPlacement: NSMakePoint(0,0)];
|
||||
[_view displayRectIgnoringOpacity: _rect];
|
||||
[_view endDocument];
|
||||
}
|
||||
|
||||
- (BOOL)isEPSOperation
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)deliverResult
|
||||
{
|
||||
if (_data != nil && _path != nil)
|
||||
{
|
||||
NSString *eps;
|
||||
|
||||
eps = [NSString stringWithContentsOfFile: _path];
|
||||
[_data setData: [eps dataUsingEncoding:NSASCIIStringEncoding]];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSGraphicsContext*)createContext
|
||||
{
|
||||
NSMutableDictionary *info;
|
||||
|
||||
if (_context)
|
||||
return _context;
|
||||
|
||||
info = [_printInfo dictionary];
|
||||
|
||||
[info setObject: _path forKey: @"NSOutputFile"];
|
||||
[info setObject: NSGraphicsContextPSFormat
|
||||
forKey: NSGraphicsContextRepresentationFormatAttributeName];
|
||||
_context = RETAIN([NSGraphicsContext graphicsContextWithAttributes: info]);
|
||||
return _context;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation GSPDFPrintOperation
|
||||
|
||||
- (id) initPDFOperationWithView:(NSView *)aView
|
||||
insideRect:(NSRect)rect
|
||||
toData:(NSMutableData *)data
|
||||
printInfo:(NSPrintInfo*)aPrintInfo
|
||||
{
|
||||
self = [self initWithView: aView
|
||||
insideRect: rect
|
||||
toData: data
|
||||
printInfo: aPrintInfo];
|
||||
_pathSet = YES; /* Use the default temp path */
|
||||
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;
|
||||
}
|
||||
|
||||
- (void) _print
|
||||
{
|
||||
[_view displayRectIgnoringOpacity: _rect];
|
||||
}
|
||||
|
||||
- (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
|
||||
|
|
|
@ -2,10 +2,13 @@
|
|||
|
||||
<abstract>Standard panel for querying user about printing.</abstract>
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
Copyright (C) 2001,2004 Free Software Foundation, Inc.
|
||||
|
||||
Written By: Adam Fedor <fedor@gnu.org>
|
||||
Date: Oct 2001
|
||||
Modified for Printing Backend Support
|
||||
Author: Chad Hardin <cehardin@mac.com>
|
||||
Date: June 2004
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -42,6 +45,7 @@
|
|||
#include "AppKit/NSSavePanel.h"
|
||||
#include "AppKit/NSView.h"
|
||||
#include "GSGuiPrivate.h"
|
||||
#include "GNUstepGUI/GSPrinting.h"
|
||||
|
||||
static NSPrintPanel *shared_instance;
|
||||
|
||||
|
@ -71,6 +75,22 @@ static NSPrintPanel *shared_instance;
|
|||
//
|
||||
// Class Methods
|
||||
//
|
||||
/** Load the appropriate bundle for the PrintPanel
|
||||
and alloc the class from that in our place
|
||||
(eg: GSLPRPrintPanel, GSCUPSPrintPanel).
|
||||
*/
|
||||
+ (id) allocWithZone: (NSZone*) zone
|
||||
{
|
||||
Class principalClass;
|
||||
|
||||
principalClass = [[GSPrinting printingBundle] principalClass];
|
||||
|
||||
if( principalClass == nil )
|
||||
return nil;
|
||||
|
||||
return [[principalClass printPanelClass] allocWithZone: zone];
|
||||
}
|
||||
|
||||
/** Creates and returns a shared instance of the NSPrintPanel panel.
|
||||
*/
|
||||
+ (NSPrintPanel *)printPanel
|
||||
|
|
|
@ -2,10 +2,13 @@
|
|||
|
||||
<abstract>Class representing a printer's or printer model's capabilities.</abstract>
|
||||
|
||||
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
||||
Copyright (C) 1996, 1997, 2004 Free Software Foundation, Inc.
|
||||
|
||||
Authors: Simon Frankau <sgf@frankau.demon.co.uk>
|
||||
Date: June 1997
|
||||
Modified for Printing Backend Support
|
||||
Author: Chad Hardin <cehardin@mac.com>
|
||||
Date: June 2004
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -51,195 +54,13 @@
|
|||
#include <Foundation/NSUtilities.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSMapTable.h>
|
||||
#include <Foundation/NSSet.h>
|
||||
#include "AppKit/AppKitExceptions.h"
|
||||
#include "AppKit/NSGraphics.h"
|
||||
|
||||
#include "AppKit/NSPrinter.h"
|
||||
|
||||
// Define size used for the name and type maps - just use a small table
|
||||
#define NAMEMAPSIZE 0
|
||||
#define TYPEMAPSIZE 0
|
||||
|
||||
// The maximum level of nesting of *Include directives
|
||||
#define MAX_PPD_INCLUDES 4
|
||||
|
||||
// A macro to skip whitespace over lines
|
||||
#define skipSpace(x) [x scanCharactersFromSet:\
|
||||
[NSCharacterSet whitespaceAndNewlineCharacterSet]\
|
||||
intoString:NULL]
|
||||
|
||||
static NSString *NSPrinter_PATH = @"PostScript/PPD";
|
||||
static NSString *NSPrinter_INDEXFILE = @"Printers";
|
||||
|
||||
//
|
||||
// Class variables:
|
||||
//
|
||||
|
||||
// Maps holding NSPrinters with the types of printers, and the real printers
|
||||
static NSMapTable *typeMap = NULL;
|
||||
static NSMapTable *nameMap = NULL;
|
||||
// Dictionary of real printers, from which NSPrinters can be made
|
||||
static NSDictionary *nameDict = nil;
|
||||
// An array to cache the available printer types
|
||||
static NSArray *printerTypesAvailable = nil;
|
||||
|
||||
//
|
||||
// Class variables used during scanning:
|
||||
//
|
||||
|
||||
// Character sets used in scanning.
|
||||
static NSCharacterSet *newlineSet = nil;
|
||||
static NSCharacterSet *keyEndSet = nil;
|
||||
static NSCharacterSet *optKeyEndSet = nil;
|
||||
static NSCharacterSet *valueEndSet = nil;
|
||||
// Array of Repeated Keywords (Appendix B of the PostScript Printer
|
||||
// Description File Format Specification).
|
||||
static NSArray *repKeys = nil;
|
||||
// Array to collect the values of symbol values in.
|
||||
static NSMutableDictionary *PPDSymbolValues;
|
||||
// File name of the file being processed
|
||||
static NSString *PPDFileName;
|
||||
|
||||
#ifndef LIB_FOUNDATION_LIBRARY
|
||||
|
||||
static void __NSRetainNothing(void *table, const void *anObject)
|
||||
{
|
||||
}
|
||||
|
||||
static void __NSReleaseNothing(void *table, void *anObject)
|
||||
{
|
||||
}
|
||||
|
||||
static NSString* __NSDescribeObjects(void *table, const void *anObject)
|
||||
{
|
||||
return [(NSObject*)anObject description];
|
||||
}
|
||||
|
||||
static const NSMapTableValueCallBacks NSNonRetainedObjectMapValueCallBacks = {
|
||||
(void (*)(NSMapTable *, const void *))__NSRetainNothing,
|
||||
(void (*)(NSMapTable *, void *))__NSReleaseNothing,
|
||||
(NSString *(*)(NSMapTable *, const void *))__NSDescribeObjects
|
||||
};
|
||||
|
||||
#endif /* LIB_FOUNDATION_LIBRARY */
|
||||
#include "GNUstepGUI/GSPrinting.h"
|
||||
|
||||
|
||||
// Convert a character to a value between 0 and 15
|
||||
static int gethex(unichar character)
|
||||
{
|
||||
switch (character)
|
||||
{
|
||||
case '0': return 0;
|
||||
case '1': return 1;
|
||||
case '2': return 2;
|
||||
case '3': return 3;
|
||||
case '4': return 4;
|
||||
case '5': return 5;
|
||||
case '6': return 6;
|
||||
case '7': return 7;
|
||||
case '8': return 8;
|
||||
case '9': return 9;
|
||||
case 'A': return 10;
|
||||
case 'B': return 11;
|
||||
case 'C': return 12;
|
||||
case 'D': return 13;
|
||||
case 'E': return 14;
|
||||
case 'F': return 15;
|
||||
case 'a': return 10;
|
||||
case 'b': return 11;
|
||||
case 'c': return 12;
|
||||
case 'd': return 13;
|
||||
case 'e': return 14;
|
||||
case 'f': return 15;
|
||||
}
|
||||
[NSException
|
||||
raise:NSPPDParseException
|
||||
format:@"Badly formatted hexadeximal substring in PPD printer file."];
|
||||
// NOT REACHED
|
||||
return 0; /* Quiet compiler warnings */
|
||||
}
|
||||
|
||||
// Function to convert hexadecimal substrings
|
||||
static NSString *interpretQuotedValue(NSString *qString)
|
||||
{
|
||||
NSScanner *scanner;
|
||||
NSCharacterSet *emptySet;
|
||||
NSString *value = nil;
|
||||
NSString *part;
|
||||
int stringLength;
|
||||
int location;
|
||||
NSRange range;
|
||||
|
||||
// Don't bother unless there's something to convert
|
||||
range = [qString rangeOfString:@"<"];
|
||||
if(!range.length)
|
||||
return qString;
|
||||
|
||||
scanner = [NSScanner scannerWithString:qString];
|
||||
emptySet = [NSCharacterSet characterSetWithCharactersInString:@""];
|
||||
[scanner setCharactersToBeSkipped:emptySet];
|
||||
if(![scanner scanUpToString:@"<" intoString:&value])
|
||||
value = [NSString string];
|
||||
stringLength = [qString length];
|
||||
|
||||
while (![scanner isAtEnd]) {
|
||||
[scanner scanString:@"<" intoString:NULL];
|
||||
skipSpace(scanner);
|
||||
while (![scanner scanString:@">" intoString:NULL])
|
||||
{
|
||||
location = [scanner scanLocation];
|
||||
if (location+2 > stringLength)
|
||||
{
|
||||
[NSException
|
||||
raise:NSPPDParseException
|
||||
format:@"Badly formatted hexadecimal substring in PPD printer file."];
|
||||
// NOT REACHED
|
||||
}
|
||||
value = [value stringByAppendingFormat:@"%c",
|
||||
16 * gethex([qString characterAtIndex:location])
|
||||
+ gethex([qString characterAtIndex:location+1])];
|
||||
[scanner setScanLocation:location+2];
|
||||
skipSpace(scanner);
|
||||
}
|
||||
if([scanner scanUpToString:@"<" intoString:&part])
|
||||
{
|
||||
value = [value stringByAppendingString:part];
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static NSString *getFile(NSString *name, NSString *type)
|
||||
{
|
||||
return [NSBundle pathForLibraryResource: name
|
||||
ofType: type
|
||||
inDirectory: NSPrinter_PATH];
|
||||
}
|
||||
|
||||
|
||||
@interface NSPrinter (private)
|
||||
+ allocMaps;
|
||||
- initWithPPD:(NSString *)PPDstring
|
||||
withName:(NSString *)name
|
||||
withType:(NSString *)type
|
||||
withHost:(NSString *)host
|
||||
withNote:(NSString *)note
|
||||
fromFile:(NSString *)file
|
||||
isReal:(BOOL)real;
|
||||
- loadPPD:(NSString *)PPDstring
|
||||
inclusionNum:(int)includeNum;
|
||||
- addPPDKeyword:(NSString *)mainKeyword
|
||||
withScanner:(NSScanner *)PPDdata;
|
||||
- addPPDUIConstraint:(NSScanner *)constraint;
|
||||
- addPPDOrderDependency:(NSScanner *)dependency;
|
||||
- addValue:(NSString *)value
|
||||
andValueTranslation:(NSString *)valueTranslation
|
||||
andOptionTranslation:(NSString *)optionTranslation
|
||||
forKey:(NSString *)key;
|
||||
- addString:(NSString *)string
|
||||
forKey:(NSString *)key
|
||||
inTable:(NSMutableDictionary *)table;
|
||||
@end
|
||||
|
||||
@implementation NSPrinter
|
||||
|
||||
|
@ -255,131 +76,108 @@ andOptionTranslation:(NSString *)optionTranslation
|
|||
}
|
||||
}
|
||||
|
||||
/** Load the appropriate bundle for the Printer
|
||||
(eg: GSLPRPrinter, GSCUPSPrinter).
|
||||
*/
|
||||
+ (id) allocWithZone: (NSZone*) zone
|
||||
{
|
||||
Class principalClass;
|
||||
|
||||
principalClass = [[GSPrinting printingBundle] principalClass];
|
||||
|
||||
if( principalClass == nil )
|
||||
return nil;
|
||||
|
||||
return [[principalClass printerClass] allocWithZone: zone];
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Finding an NSPrinter
|
||||
//
|
||||
+ (NSPrinter *)printerWithName:(NSString *)name
|
||||
{
|
||||
NSString *path;
|
||||
NSArray *printerInfo;
|
||||
NSPrinter *printer;
|
||||
/* Contents of printerInfo array:
|
||||
* [0]: NSString of the printer's type
|
||||
* [1]: NSString of the printer's host
|
||||
* [2]: NSString of the printer's note
|
||||
*/
|
||||
// Make sure the printer names dictionary etc. exists
|
||||
if (!nameMap)
|
||||
[self allocMaps];
|
||||
printer = NSMapGet(nameMap, name);
|
||||
// If the NSPrinter object for the printer already exists, return it
|
||||
if (printer)
|
||||
return printer;
|
||||
// Otherwise, try to find the information in the nameDict
|
||||
printerInfo = [nameDict objectForKey:name];
|
||||
// Make sure you can find the printer name in the dictionary
|
||||
if (!printerInfo)
|
||||
{
|
||||
[NSException raise:NSGenericException
|
||||
format:@"Could not find printer named %@", name];
|
||||
// NOT REACHED
|
||||
}
|
||||
// Create it
|
||||
path = getFile([printerInfo objectAtIndex:0], @"ppd");
|
||||
// If not found
|
||||
if (path == nil || [path length] == 0)
|
||||
{
|
||||
[NSException raise:NSGenericException
|
||||
format:@"Could not find PPD file %@.ppd",
|
||||
[printerInfo objectAtIndex:0]];
|
||||
// NOT REACHED
|
||||
}
|
||||
printer = AUTORELEASE([[self alloc]
|
||||
initWithPPD:[NSString stringWithContentsOfFile:path]
|
||||
withName:name
|
||||
withType:[printerInfo objectAtIndex:0]
|
||||
withHost:[printerInfo objectAtIndex:1]
|
||||
withNote:[printerInfo objectAtIndex:2]
|
||||
fromFile:[printerInfo objectAtIndex:0]
|
||||
isReal:YES]);
|
||||
// Once created, put it in the map table
|
||||
NSMapInsert(nameMap, name, printer);
|
||||
return printer;
|
||||
Class principalClass;
|
||||
|
||||
principalClass = [[GSPrinting printingBundle] principalClass];
|
||||
|
||||
if( principalClass == nil )
|
||||
return nil;
|
||||
|
||||
return [[principalClass printerClass] printerWithName: name];
|
||||
}
|
||||
|
||||
//
|
||||
// This now different than the OpenStep spec and instead
|
||||
// follows the more useful implementation Apple choosed. In
|
||||
// OpenStep, this method would read a PPD and return a NSPrinter
|
||||
// based upon values from that PPD, regardless if that printer
|
||||
// was actually avaiable for use or not. On the contrary, Apple's
|
||||
// implementation looks
|
||||
// at all avaiable printers and returns one that has the same
|
||||
// type. The reason for this is because they use CUPS. CUPS
|
||||
// does not work by maintaining a repository of PPDs. Instead,
|
||||
// the CUPS server trasnmits PPDs as they are needed, and only
|
||||
// for actual real printers. Since we cannot know how the backend
|
||||
// bundles will be handling their PPDs, or if they will even be using
|
||||
// PPDs for that matter, (a Win32 printing backend, for example),
|
||||
// I've choosen to go with Apple's implementation. Really, I see
|
||||
// little use in creating a NSPrinter for a printer that is not
|
||||
// available for use in the first place, I am open for commments
|
||||
// on this, of course.
|
||||
+ (NSPrinter *)printerWithType:(NSString *)type
|
||||
{
|
||||
NSString *path;
|
||||
NSPrinter *printer = nil;
|
||||
// Make sure the printer types dictionary exists
|
||||
if (!typeMap)
|
||||
[self allocMaps];
|
||||
else
|
||||
printer = NSMapGet(typeMap, type);
|
||||
// If the NSPrinter is already created, use it
|
||||
if (printer)
|
||||
return printer;
|
||||
path = getFile(type, @"ppd");
|
||||
// If not found
|
||||
if (path == nil || [path length] == 0)
|
||||
NSEnumerator *printerNamesEnum;
|
||||
NSString *printerName;
|
||||
|
||||
printerNamesEnum = [[self printerNames] objectEnumerator];
|
||||
|
||||
while( (printerName = [printerNamesEnum nextObject]) )
|
||||
{
|
||||
[NSException raise:NSGenericException
|
||||
format:@"Could not find PPD file %@.ppd", type];
|
||||
// NOT REACHED
|
||||
NSPrinter *printer;
|
||||
|
||||
printer = [self printerWithName: printerName];
|
||||
|
||||
if( [[printer type] isEqualToString: type] )
|
||||
{
|
||||
return printer;
|
||||
}
|
||||
}
|
||||
printer = AUTORELEASE([[self alloc]
|
||||
initWithPPD:[NSString stringWithContentsOfFile:path]
|
||||
withName:type withType:type withHost:@"" withNote:@""
|
||||
fromFile:path isReal:NO]);
|
||||
// Once created, put it in the hash table
|
||||
NSMapInsert(typeMap, type, printer);
|
||||
return printer;
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSArray *)printerNames
|
||||
{
|
||||
if(!nameDict)
|
||||
[NSPrinter allocMaps];
|
||||
return [nameDict allKeys];
|
||||
Class principalClass;
|
||||
|
||||
principalClass = [[GSPrinting printingBundle] principalClass];
|
||||
|
||||
if( principalClass == nil )
|
||||
return nil;
|
||||
|
||||
return [[principalClass printerClass] printerNames];
|
||||
}
|
||||
|
||||
// See note at +(NSPrinter *)printerWithType:(NSString *)type
|
||||
+ (NSArray *)printerTypes
|
||||
{
|
||||
NSEnumerator *pathEnum;
|
||||
NSBundle *lbdle;
|
||||
NSString *lpath;
|
||||
NSArray *ppdpaths;
|
||||
NSMutableArray *printers;
|
||||
NSString *path;
|
||||
NSAutoreleasePool *subpool; // There's a lot of temp strings used...
|
||||
int i, max;
|
||||
|
||||
if (printerTypesAvailable)
|
||||
return printerTypesAvailable;
|
||||
|
||||
printers = RETAIN([NSMutableArray array]);
|
||||
subpool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
pathEnum = [NSSearchPathForDirectoriesInDomains(GSLibrariesDirectory,
|
||||
NSAllDomainsMask, YES) objectEnumerator];
|
||||
while ((lpath = [pathEnum nextObject]))
|
||||
NSMutableSet *printerTypes;
|
||||
NSEnumerator *printerNamesEnum;
|
||||
NSString *printerName;
|
||||
NSPrinter *printer;
|
||||
|
||||
printerTypes = [NSMutableSet setWithCapacity:1];
|
||||
|
||||
printerNamesEnum = [[self printerNames] objectEnumerator];
|
||||
|
||||
while( (printerName = [printerNamesEnum nextObject]) )
|
||||
{
|
||||
lbdle = [NSBundle bundleWithPath: lpath];
|
||||
ppdpaths = [lbdle pathsForResourcesOfType:@"ppd"
|
||||
inDirectory:NSPrinter_PATH];
|
||||
|
||||
// FIXME - should get name from contents of PPD, not filename
|
||||
max = [ppdpaths count];
|
||||
for (i = 0; i < max; i++)
|
||||
{
|
||||
path = [[ppdpaths objectAtIndex:i] lastPathComponent];
|
||||
[printers addObject:[path substringToIndex:[path length]-4]];
|
||||
}
|
||||
printer = [self printerWithName: printerName];
|
||||
|
||||
[printerTypes addObject: [printer type]];
|
||||
}
|
||||
RELEASE(subpool);
|
||||
|
||||
printerTypesAvailable = printers;
|
||||
return printers;
|
||||
|
||||
return [printerTypes allObjects];
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -390,11 +188,6 @@ andOptionTranslation:(NSString *)optionTranslation
|
|||
//
|
||||
- (void)dealloc
|
||||
{
|
||||
// Remove object from the appropriate table
|
||||
if (_isRealPrinter)
|
||||
NSMapRemove(nameMap, _printerName);
|
||||
else
|
||||
NSMapRemove(typeMap, _printerType);
|
||||
RELEASE(_printerHost);
|
||||
RELEASE(_printerName);
|
||||
RELEASE(_printerNote);
|
||||
|
@ -830,7 +623,6 @@ andOptionTranslation:(NSString *)optionTranslation
|
|||
|
||||
[aCoder encodeValueOfObjCType: @encode(int) at: &_cacheAcceptsBinary];
|
||||
[aCoder encodeValueOfObjCType: @encode(int) at: &_cacheOutputOrder];
|
||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isRealPrinter];
|
||||
|
||||
[aCoder encodeObject: _PPD];
|
||||
[aCoder encodeObject: _PPDOptionTranslation];
|
||||
|
@ -850,7 +642,6 @@ andOptionTranslation:(NSString *)optionTranslation
|
|||
|
||||
[aDecoder decodeValueOfObjCType: @encode(int) at: &_cacheAcceptsBinary];
|
||||
[aDecoder decodeValueOfObjCType: @encode(int) at: &_cacheOutputOrder];
|
||||
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isRealPrinter];
|
||||
|
||||
[aDecoder decodeValueOfObjCType: @encode(id) at: &_PPD];
|
||||
[aDecoder decodeValueOfObjCType: @encode(id) at: &_PPDOptionTranslation];
|
||||
|
@ -861,467 +652,43 @@ andOptionTranslation:(NSString *)optionTranslation
|
|||
return self;
|
||||
}
|
||||
|
||||
//
|
||||
// Private Methods
|
||||
//
|
||||
@end
|
||||
|
||||
|
||||
|
||||
///
|
||||
///Private implementation of routines that will be usefull
|
||||
///for the printing backend bundles that subclass us.
|
||||
///
|
||||
@implementation NSPrinter (Private)
|
||||
|
||||
//
|
||||
// Allocate the printer name to PPD filename index dictionary
|
||||
// Initialisation method used by backend bundles
|
||||
//
|
||||
+ allocMaps
|
||||
-(id) initWithName:(NSString *)name
|
||||
withType:(NSString *)type
|
||||
withHost:(NSString *)host
|
||||
withNote:(NSString *)note
|
||||
{
|
||||
NSString *path;
|
||||
|
||||
// Allocate name and type maps
|
||||
typeMap = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||
NSNonRetainedObjectMapValueCallBacks,
|
||||
TYPEMAPSIZE);
|
||||
nameMap = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||
NSNonRetainedObjectMapValueCallBacks,
|
||||
NAMEMAPSIZE);
|
||||
|
||||
// Load the index file
|
||||
path = [NSBundle pathForLibraryResource: NSPrinter_INDEXFILE
|
||||
ofType: nil
|
||||
inDirectory: @"PostScript"];
|
||||
// If not found
|
||||
if (path == nil || [path length] == 0)
|
||||
{
|
||||
NSLog(@"Could not find index of printers, file %@", NSPrinter_INDEXFILE);
|
||||
nameDict = [NSDictionary dictionaryWithObject:
|
||||
[NSArray arrayWithObjects: @"Apple_LaserWriter_II_NTX",
|
||||
@"localhost", @"A Note", nil]
|
||||
forKey: @"Unknown"];
|
||||
}
|
||||
else
|
||||
nameDict = [NSDictionary dictionaryWithContentsOfFile:path];
|
||||
RETAIN(nameDict);
|
||||
return self;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialisation method
|
||||
//
|
||||
// To keep loading of PPDs relatively fast, not much checking is done on it.
|
||||
- initWithPPD:(NSString *)PPDstring
|
||||
withName:(NSString *)name
|
||||
withType:(NSString *)type
|
||||
withHost:(NSString *)host
|
||||
withNote:(NSString *)note
|
||||
fromFile:(NSString *)file
|
||||
isReal:(BOOL)real
|
||||
{
|
||||
NSAutoreleasePool *subpool;
|
||||
NSEnumerator *objEnum;
|
||||
NSMutableArray *valArray;
|
||||
|
||||
self = [super init];
|
||||
|
||||
// Initialise instance variables
|
||||
_printerName = RETAIN(name);
|
||||
_printerType = RETAIN(type);
|
||||
_printerHost = RETAIN(host);
|
||||
_printerNote = RETAIN(note);
|
||||
ASSIGN(_printerName, name);
|
||||
ASSIGN(_printerType, type);
|
||||
ASSIGN(_printerHost, host);
|
||||
ASSIGN(_printerNote, note);
|
||||
_cacheAcceptsBinary = _cacheOutputOrder = -1;
|
||||
_isRealPrinter = real;
|
||||
_PPD = RETAIN([NSMutableDictionary dictionary]);
|
||||
_PPDOptionTranslation = RETAIN([NSMutableDictionary dictionary]);
|
||||
_PPDArgumentTranslation = RETAIN([NSMutableDictionary dictionary]);
|
||||
_PPDOrderDependency = RETAIN([NSMutableDictionary dictionary]);
|
||||
_PPDUIConstraints = RETAIN([NSMutableDictionary dictionary]);
|
||||
// Create a temporary autorelease pool, as many temporary objects are used
|
||||
subpool = [[NSAutoreleasePool alloc] init];
|
||||
// Create character sets used during scanning
|
||||
newlineSet = [NSCharacterSet characterSetWithCharactersInString:@"\n\r"];
|
||||
keyEndSet = [NSCharacterSet characterSetWithCharactersInString:@"\n\r\t: "];
|
||||
optKeyEndSet = [NSCharacterSet characterSetWithCharactersInString:@"\n\r:/"];
|
||||
valueEndSet = [NSCharacterSet characterSetWithCharactersInString:@"\n\r/"];
|
||||
// Allowed repeated keys, used during scanning.
|
||||
repKeys = [NSArray arrayWithObjects:@"Emulators",
|
||||
@"Extensions",
|
||||
@"FaxSupport",
|
||||
//@"Include", (handled separately)
|
||||
@"Message",
|
||||
@"PrinterError",
|
||||
@"Product",
|
||||
@"Protocols",
|
||||
@"PSVersion",
|
||||
@"Source",
|
||||
@"Status",
|
||||
//@"UIConstraints", (handled separately)
|
||||
// Even though this is not mentioned in the list of repeated keywords,
|
||||
// it's often repeated anyway, so I'm putting it here.
|
||||
@"InkName",
|
||||
nil];
|
||||
// Set the file name to use
|
||||
PPDFileName = file;
|
||||
// NB: There are some structure keywords (such as OpenUI/CloseUI) that may
|
||||
// be repeated, but as yet are not used. Since they are structure keywords,
|
||||
// they'll probably need special processing anyway, and so aren't
|
||||
// added to this list.
|
||||
// Create dictionary for temporary storage of symbol values
|
||||
PPDSymbolValues = [NSMutableDictionary dictionary];
|
||||
// And scan the PPD itself
|
||||
[self loadPPD:PPDstring inclusionNum:0];
|
||||
// Search the PPD dictionary for symbolvalues, and substitute them.
|
||||
objEnum = [_PPD objectEnumerator];
|
||||
while ((valArray = [objEnum nextObject]))
|
||||
{
|
||||
NSString *oldValue;
|
||||
NSString *newValue;
|
||||
int i, max;
|
||||
max = [valArray count];
|
||||
for(i=0 ; i < max ; i++ )
|
||||
{
|
||||
oldValue = [valArray objectAtIndex:i];
|
||||
if ([oldValue isKindOfClass:[NSString class]]
|
||||
&& ![oldValue isEqual:@""]
|
||||
&& [[oldValue substringToIndex:1] isEqual:@"^"])
|
||||
{
|
||||
newValue = [PPDSymbolValues
|
||||
objectForKey:[oldValue substringFromIndex:1]];
|
||||
if (!newValue)
|
||||
{
|
||||
[NSException
|
||||
raise:NSPPDParseException
|
||||
format:@"Unknown symbol value, ^%@ in PPD file %@.ppd",
|
||||
oldValue, PPDFileName];
|
||||
// NOT REACHED
|
||||
}
|
||||
[valArray replaceObjectAtIndex:i withObject:newValue];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
// DISABLED: Though the following keywords *should* be present, there seems
|
||||
// to be few problems is they are omitted. Many of the .ppd files I have
|
||||
// don't have *LanguageEncoding, for example.
|
||||
|
||||
// Make sure all the required keys are present
|
||||
objEnum = [[NSArray arrayWithObjects:@"NickName",
|
||||
@"ModelName",
|
||||
@"PCFileName",
|
||||
@"Product",
|
||||
@"PSVersion",
|
||||
@"FileVersion",
|
||||
@"FormatVersion",
|
||||
@"LanguageEncoding",
|
||||
@"LanguageVersion",
|
||||
@"PageSize",
|
||||
@"PageRegion",
|
||||
@"ImageableArea",
|
||||
@"PaperDimension",
|
||||
@"PPD-Adobe",
|
||||
nil] objectEnumerator];
|
||||
|
||||
while (checkVal = [objEnum nextObject])
|
||||
{
|
||||
if (![self isKey:checkVal inTable:@"PPD"])
|
||||
{
|
||||
[NSException
|
||||
raise:NSPPDParseException
|
||||
format:@"Required keyword *%@ not found in PPD file %@.ppd",
|
||||
checkVal, PPDFileName];
|
||||
// NOT REACHED
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Release the local autoreleasePool
|
||||
RELEASE(subpool);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- loadPPD:(NSString *)PPDstring
|
||||
inclusionNum:(int)includeNum
|
||||
{
|
||||
NSScanner *PPDdata;
|
||||
NSString *keyword;
|
||||
|
||||
// Set up the scanner - Appending a newline means that it should be
|
||||
// able to process the last line correctly
|
||||
PPDdata = [NSScanner scannerWithString:
|
||||
[PPDstring stringByAppendingString:@"\n"]];
|
||||
[PPDdata setCharactersToBeSkipped:[NSCharacterSet whitespaceCharacterSet]];
|
||||
// Main processing starts here...
|
||||
while (1) // Check it is not at end only after skipping the blanks
|
||||
{
|
||||
// Get to the start of a new keyword, skipping blank lines
|
||||
skipSpace(PPDdata);
|
||||
if ([PPDdata isAtEnd])
|
||||
break;
|
||||
// All new entries should starts '*'
|
||||
if (![PPDdata scanString:@"*" intoString:NULL])
|
||||
{
|
||||
[NSException raise:NSPPDParseException
|
||||
format:@"Line not starting * in PPD file %@.ppd",
|
||||
PPDFileName];
|
||||
// NOT REACHED
|
||||
}
|
||||
// Skip lines starting '*%', '*End', '*SymbolLength', or '*SymbolEnd'
|
||||
if ([PPDdata scanString:@"%" intoString:NULL]
|
||||
|| [PPDdata scanString:@"End" intoString:NULL]
|
||||
|| [PPDdata scanString:@"SymbolLength" intoString:NULL]
|
||||
|| [PPDdata scanString:@"SymbolEnd" intoString:NULL])
|
||||
{
|
||||
[PPDdata scanUpToCharactersFromSet:newlineSet intoString:NULL];
|
||||
continue;
|
||||
}
|
||||
// Read main keyword, up to a colon, space or newline
|
||||
[PPDdata scanUpToCharactersFromSet:keyEndSet intoString:&keyword];
|
||||
// Loop if there is no value section
|
||||
if ([PPDdata scanCharactersFromSet:newlineSet intoString:NULL])
|
||||
continue;
|
||||
// Add the line to the relevant table
|
||||
if ([keyword isEqual:@"OrderDependency"])
|
||||
[self addPPDOrderDependency:PPDdata];
|
||||
else if ([keyword isEqual:@"UIConstraints"])
|
||||
[self addPPDUIConstraint:PPDdata];
|
||||
else if ([keyword isEqual:@"Include"])
|
||||
{
|
||||
NSString *fileName;
|
||||
NSString *path;
|
||||
[PPDdata scanString:@":" intoString:NULL];
|
||||
// Find the filename between two "s
|
||||
[PPDdata scanString:@"\"" intoString:NULL];
|
||||
[PPDdata scanUpToString:@"\"" intoString:&fileName];
|
||||
[PPDdata scanString:@"\"" intoString:NULL];
|
||||
// Load the file
|
||||
path = getFile(fileName, nil);
|
||||
// If not found
|
||||
if (path == nil || [path length] == 0)
|
||||
{
|
||||
[NSException raise:NSPPDIncludeNotFoundException
|
||||
format:@"Could not find included PPD file %@",
|
||||
fileName];
|
||||
// NOT REACHED
|
||||
}
|
||||
includeNum++;
|
||||
if (includeNum > MAX_PPD_INCLUDES)
|
||||
{
|
||||
[NSException raise:NSPPDIncludeStackOverflowException
|
||||
format:@"Too many *Includes in PPD"];
|
||||
// NOT REACHED
|
||||
}
|
||||
[self loadPPD:[NSString stringWithContentsOfFile:path]
|
||||
inclusionNum:includeNum];
|
||||
}
|
||||
else if ([keyword isEqual:@"SymbolValue"])
|
||||
{
|
||||
NSString *symbolName;
|
||||
NSString *symbolVal;
|
||||
if (![PPDdata scanString:@"^" intoString:NULL])
|
||||
{
|
||||
[NSException
|
||||
raise:NSPPDParseException
|
||||
format:@"Badly formatted *SymbolValue in PPD file %@.ppd",
|
||||
PPDFileName];
|
||||
// NOT REACHED
|
||||
}
|
||||
[PPDdata scanUpToString:@":" intoString:&symbolName];
|
||||
[PPDdata scanString:@":" intoString:NULL];
|
||||
[PPDdata scanString:@"\"" intoString:NULL];
|
||||
[PPDdata scanUpToString:@"\"" intoString:&symbolVal];
|
||||
if (!symbolVal)
|
||||
symbolVal = @"";
|
||||
[PPDdata scanString:@"\"" intoString:NULL];
|
||||
[PPDSymbolValues setObject:symbolVal forKey:symbolName];
|
||||
}
|
||||
else
|
||||
[self addPPDKeyword:keyword withScanner:PPDdata];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- addPPDKeyword:(NSString *)mainKeyword
|
||||
withScanner:(NSScanner *)PPDdata
|
||||
{
|
||||
NSString *optionKeyword = nil;
|
||||
NSString *optionTranslation = nil;
|
||||
NSString *value = nil;
|
||||
NSString *valueTranslation = nil;
|
||||
// Scan off any optionKeyword
|
||||
[PPDdata scanUpToCharactersFromSet:optKeyEndSet intoString:&optionKeyword];
|
||||
if ([PPDdata scanCharactersFromSet:newlineSet intoString:NULL])
|
||||
{
|
||||
[NSException raise:NSPPDParseException
|
||||
format:@"Keyword has optional keyword but no value in PPD file %@.ppd",
|
||||
PPDFileName];
|
||||
// NOT REACHED
|
||||
}
|
||||
if ([PPDdata scanString:@"/" intoString:NULL])
|
||||
{
|
||||
// Option keyword translation exists - scan it
|
||||
[PPDdata scanUpToString:@":" intoString:&optionTranslation];
|
||||
}
|
||||
[PPDdata scanString:@":" intoString:NULL];
|
||||
// Read the value part
|
||||
// Values starting with a " are read until the second ", ignoring \n etc.
|
||||
if ([PPDdata scanString:@"\"" intoString:NULL])
|
||||
{
|
||||
[PPDdata scanUpToString:@"\"" intoString:&value];
|
||||
if (!value)
|
||||
value = @"";
|
||||
[PPDdata scanString:@"\"" intoString:NULL];
|
||||
// It is a QuotedValue if it's in quotes, and there is no option
|
||||
// key, or the main key is a *JCL keyword
|
||||
if (!optionKeyword || [[mainKeyword substringToIndex:3]
|
||||
isEqualToString:@"JCL"])
|
||||
value = interpretQuotedValue(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, scan up to the end of line or '/'
|
||||
[PPDdata scanUpToCharactersFromSet:valueEndSet intoString:&value];
|
||||
}
|
||||
// If there is a value translation, scan it
|
||||
if ([PPDdata scanString:@"/" intoString:NULL])
|
||||
{
|
||||
[PPDdata scanUpToCharactersFromSet:newlineSet
|
||||
intoString:&valueTranslation];
|
||||
}
|
||||
// The translations also have to have any hex substrings interpreted
|
||||
if (optionTranslation)
|
||||
optionTranslation = interpretQuotedValue(optionTranslation);
|
||||
if (valueTranslation)
|
||||
valueTranslation = interpretQuotedValue(valueTranslation);
|
||||
// The keyword (or keyword/option pair, if there's a option), should only
|
||||
// only have one value, unless it's one of the optionless keywords which
|
||||
// allow multiple instances.
|
||||
// If a keyword is read twice, 'first instance is correct', according to
|
||||
// the standard.
|
||||
// Finally, add the strings to the tables
|
||||
if (optionKeyword)
|
||||
{
|
||||
NSString *mainAndOptionKeyword=[mainKeyword
|
||||
stringByAppendingFormat:@"/%@",
|
||||
optionKeyword];
|
||||
if ([self isKey:mainAndOptionKeyword inTable:@"PPD"])
|
||||
return self;
|
||||
[self addValue:value
|
||||
andValueTranslation:valueTranslation
|
||||
andOptionTranslation:optionTranslation
|
||||
forKey:mainAndOptionKeyword];
|
||||
// Deal with the oddities of stringForKey:inTable:
|
||||
// If this method is used to find a keyword with options, using
|
||||
// just the keyword it should return an empty string
|
||||
// stringListForKey:inTable:, however, should return the list of
|
||||
// option keywords.
|
||||
// This is done by making the first item in the array an empty
|
||||
// string, which will be skipped by stringListForKey:, if necessary
|
||||
if (![_PPD objectForKey:mainKeyword])
|
||||
{
|
||||
[self addString:@"" forKey:mainKeyword inTable:_PPD];
|
||||
[self addString:@"" forKey:mainKeyword inTable:_PPDOptionTranslation];
|
||||
[self addString:@"" forKey:mainKeyword
|
||||
inTable:_PPDArgumentTranslation];
|
||||
}
|
||||
[self addValue:optionKeyword
|
||||
andValueTranslation:optionKeyword
|
||||
andOptionTranslation:optionKeyword
|
||||
forKey:mainKeyword];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ([self isKey:mainKeyword inTable:@"PPD"] &&
|
||||
![repKeys containsObject:mainKeyword])
|
||||
return self;
|
||||
[self addValue:value
|
||||
andValueTranslation:valueTranslation
|
||||
andOptionTranslation:optionTranslation
|
||||
forKey:mainKeyword];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- addPPDUIConstraint:(NSScanner *)constraint
|
||||
{
|
||||
NSString *mainKey1 = nil;
|
||||
NSString *optionKey1 = nil;
|
||||
NSString *mainKey2 = nil;
|
||||
NSString *optionKey2 = nil;
|
||||
// UIConstraint should have no option keyword
|
||||
if (![constraint scanString:@":" intoString:NULL])
|
||||
{
|
||||
[NSException raise:NSPPDParseException
|
||||
format:@"UIConstraints has option keyword in PPDFileName %@.ppd",
|
||||
PPDFileName];
|
||||
// NOT REACHED
|
||||
}
|
||||
// Skip the '*'
|
||||
[constraint scanString:@"*" intoString:NULL];
|
||||
// Scan the bits. Stuff not starting with * must be an optionKeyword
|
||||
[constraint scanUpToCharactersFromSet:[NSCharacterSet whitespaceCharacterSet]
|
||||
intoString:&mainKey1];
|
||||
if (![constraint scanString:@"*" intoString:NULL])
|
||||
{
|
||||
[constraint scanUpToCharactersFromSet:[NSCharacterSet
|
||||
whitespaceCharacterSet]
|
||||
intoString:&optionKey1];
|
||||
[constraint scanString:@"*" intoString:NULL];
|
||||
}
|
||||
[constraint scanUpToCharactersFromSet:
|
||||
[NSCharacterSet whitespaceAndNewlineCharacterSet]
|
||||
intoString:&mainKey2];
|
||||
if (![constraint scanCharactersFromSet:newlineSet intoString:NULL])
|
||||
{
|
||||
[constraint scanUpToCharactersFromSet:
|
||||
[NSCharacterSet whitespaceAndNewlineCharacterSet]
|
||||
intoString:&optionKey2];
|
||||
}
|
||||
else
|
||||
{
|
||||
optionKey2 = @"";
|
||||
}
|
||||
// Add to table
|
||||
if (optionKey1)
|
||||
mainKey1 = [mainKey1 stringByAppendingFormat:@"/%@", optionKey1];
|
||||
[self addString:mainKey2
|
||||
forKey:mainKey1
|
||||
inTable:_PPDUIConstraints];
|
||||
[self addString:optionKey2
|
||||
forKey:mainKey1
|
||||
inTable:_PPDUIConstraints];
|
||||
return self;
|
||||
}
|
||||
|
||||
- addPPDOrderDependency:(NSScanner *)dependency
|
||||
{
|
||||
NSString *realValue = nil;
|
||||
NSString *section = nil;
|
||||
NSString *keyword = nil;
|
||||
NSString *optionKeyword = nil;
|
||||
// Order dependency should have no option keyword
|
||||
if (![dependency scanString:@":" intoString:NULL])
|
||||
{
|
||||
[NSException raise:NSPPDParseException
|
||||
format:@"OrderDependency has option keyword in PPD file %@.ppd",
|
||||
PPDFileName];
|
||||
// NOT REACHED
|
||||
}
|
||||
[dependency scanUpToCharactersFromSet:[NSCharacterSet whitespaceCharacterSet]
|
||||
intoString:&realValue];
|
||||
[dependency scanUpToCharactersFromSet:[NSCharacterSet whitespaceCharacterSet]
|
||||
intoString:§ion];
|
||||
[dependency scanString:@"*" intoString:NULL];
|
||||
[dependency scanUpToCharactersFromSet:
|
||||
[NSCharacterSet whitespaceAndNewlineCharacterSet]
|
||||
intoString:&keyword];
|
||||
if (![dependency scanCharactersFromSet:newlineSet intoString:NULL])
|
||||
{
|
||||
// Optional keyword exists
|
||||
[dependency scanUpToCharactersFromSet:
|
||||
[NSCharacterSet whitespaceAndNewlineCharacterSet]
|
||||
intoString:&optionKeyword];
|
||||
}
|
||||
// Go to next line of PPD file
|
||||
[dependency scanCharactersFromSet:newlineSet intoString:NULL];
|
||||
// Add to table
|
||||
if (optionKeyword)
|
||||
keyword = [keyword stringByAppendingFormat:@"/%s", optionKeyword];
|
||||
[self addString:realValue forKey:keyword inTable:_PPDOrderDependency];
|
||||
[self addString:section forKey:keyword inTable:_PPDOrderDependency];
|
||||
return self;
|
||||
}
|
||||
|
||||
//
|
||||
// Adds the various values to the relevant tables, for the given key
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue