Moved all printing output code to NSGraphicsContext.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25268 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2007-06-18 12:49:04 +00:00
parent 1b4f334cda
commit cfff2ce6b4
5 changed files with 479 additions and 326 deletions

View file

@ -1,3 +1,11 @@
2007-06-18 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSGraphicsContext.h: Declare new printing
methods.
* Source/NSGraphicsContext.m: Implement Postscript printing methods.
* Source/NSPrintOperation.m: Move _endSheet method into NSView.
* Source/NSView.m: Use printing methods from NSGraphicsContext.
2007-06-07 Sergii Stoian <stoyan255@gmail.com> 2007-06-07 Sergii Stoian <stoyan255@gmail.com>
* Source/NSBrowser.m: ([drawWithFrame:inView:]) Pass inset rect by * Source/NSBrowser.m: ([drawWithFrame:inView:]) Pass inset rect by

View file

@ -433,6 +433,37 @@ transform between current user space and image space for this image.</desc>
@end @end
/* ----------------------------------------------------------------------- */
/* Printing Ops */
/* ----------------------------------------------------------------------- */
@interface NSGraphicsContext (Printing)
- (void) beginPage: (int)ordinalNum
label: (NSString*)aString
bBox: (NSRect)pageRect
fonts: (NSString*)fontNames;
- (void) beginPrologueBBox: (NSRect)boundingBox
creationDate: (NSString*)dateCreated
createdBy: (NSString*)anApplication
fonts: (NSString*)fontNames
forWhom: (NSString*)user
pages: (int)numPages
title: (NSString*)aTitle;
- (void) beginSetup;
- (void) beginTrailer;
- (void) endDocumentPages: (int)pages
documentFonts: (NSSet*)fontNames;
- (void) endHeaderComments;
- (void) endPageSetup;
- (void) endPrologue;
- (void) endSetup;
- (void) endSheet;
- (void) endTrailer;
- (void) printerProlog;
- (void) showPage;
@end
/* NSGraphicContext constants */ /* NSGraphicContext constants */
APPKIT_EXPORT NSString *NSGraphicsContextDestinationAttributeName; APPKIT_EXPORT NSString *NSGraphicsContextDestinationAttributeName;
APPKIT_EXPORT NSString *NSGraphicsContextPDFFormat; APPKIT_EXPORT NSString *NSGraphicsContextPDFFormat;

View file

@ -44,9 +44,12 @@
#include "AppKit/NSGraphicsContext.h" #include "AppKit/NSGraphicsContext.h"
#include "AppKit/NSAffineTransform.h" #include "AppKit/NSAffineTransform.h"
#include "AppKit/NSBezierPath.h" #include "AppKit/NSBezierPath.h"
#include "AppKit/NSPrintInfo.h"
#include "AppKit/NSPrintOperation.h"
#include "AppKit/NSWindow.h" #include "AppKit/NSWindow.h"
#include "AppKit/NSView.h" #include "AppKit/NSView.h"
#include "AppKit/DPSOperators.h" #include "AppKit/DPSOperators.h"
#include "GNUstepGUI/GSVersion.h"
/* The memory zone where all global objects are allocated from (Contexts /* The memory zone where all global objects are allocated from (Contexts
are also allocated from this zone) */ are also allocated from this zone) */
@ -1530,3 +1533,173 @@ NSGraphicsContext *GSCurrentContext(void)
} }
@end @end
@implementation NSGraphicsContext (Printing)
- (void) beginPage: (int)ordinalNum
label: (NSString*)aString
bBox: (NSRect)pageRect
fonts: (NSString*)fontNames
{
if (aString == nil)
aString = [[NSNumber numberWithInt: ordinalNum] description];
DPSPrintf(self, "%%%%Page: %s %d\n", [aString lossyCString], ordinalNum);
if (NSIsEmptyRect(pageRect) == NO)
DPSPrintf(self, "%%%%PageBoundingBox: %d %d %d %d\n",
(int)NSMinX(pageRect), (int)NSMinY(pageRect),
(int)NSMaxX(pageRect), (int)NSMaxY(pageRect));
if (fontNames)
DPSPrintf(self, "%%%%PageFonts: %s\n", [fontNames lossyCString]);
DPSPrintf(self, "%%%%BeginPageSetup\n");
}
- (void) beginPrologueBBox: (NSRect)boundingBox
creationDate: (NSString*)dateCreated
createdBy: (NSString*)anApplication
fonts: (NSString*)fontNames
forWhom: (NSString*)user
pages: (int)numPages
title: (NSString*)aTitle
{
NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSPrintingOrientation orient;
BOOL epsOp;
epsOp = [printOp isEPSOperation];
orient = [[printOp printInfo] orientation];
if (epsOp)
DPSPrintf(self, "%%!PS-Adobe-3.0 EPSF-3.0\n");
else
DPSPrintf(self, "%%!PS-Adobe-3.0\n");
DPSPrintf(self, "%%%%Title: %s\n", [aTitle lossyCString]);
DPSPrintf(self, "%%%%Creator: %s\n", [anApplication lossyCString]);
DPSPrintf(self, "%%%%CreationDate: %s\n",
[[dateCreated description] lossyCString]);
DPSPrintf(self, "%%%%For: %s\n", [user lossyCString]);
if (fontNames)
DPSPrintf(self, "%%%%DocumentFonts: %s\n", [fontNames lossyCString]);
else
DPSPrintf(self, "%%%%DocumentFonts: (atend)\n");
if (NSIsEmptyRect(boundingBox) == NO)
DPSPrintf(self, "%%%%BoundingBox: %d %d %d %d\n",
(int)NSMinX(boundingBox), (int)NSMinY(boundingBox),
(int)NSMaxX(boundingBox), (int)NSMaxY(boundingBox));
else
DPSPrintf(self, "%%%%BoundingBox: (atend)\n");
if (epsOp == NO)
{
if (numPages)
DPSPrintf(self, "%%%%Pages: %d\n", numPages);
else
DPSPrintf(self, "%%%%Pages: (atend)\n");
if ([printOp pageOrder] == NSDescendingPageOrder)
DPSPrintf(self, "%%%%PageOrder: Descend\n");
else if ([printOp pageOrder] == NSAscendingPageOrder)
DPSPrintf(self, "%%%%PageOrder: Ascend\n");
else if ([printOp pageOrder] == NSSpecialPageOrder)
DPSPrintf(self, "%%%%PageOrder: Special\n");
if (orient == NSPortraitOrientation)
DPSPrintf(self, "%%%%Orientation: Portrait\n");
else
DPSPrintf(self, "%%%%Orientation: Landscape\n");
}
DPSPrintf(self, "%%%%GNUstepVersion: %d.%d.%d\n",
GNUSTEP_GUI_MAJOR_VERSION, GNUSTEP_GUI_MINOR_VERSION,
GNUSTEP_GUI_SUBMINOR_VERSION);
}
- (void) beginSetup
{
DPSPrintf(self, "%%%%BeginSetup\n");
}
- (void) beginTrailer
{
DPSPrintf(self, "%%%%Trailer\n");
}
- (void) endDocumentPages: (int)pages
documentFonts: (NSSet*)fontNames
{
if (pages != 0)
{
DPSPrintf(self, "%%%%Pages: %d\n", pages);
}
if (fontNames && [fontNames count])
{
NSString *name;
NSEnumerator *e = [fontNames objectEnumerator];
DPSPrintf(self, "%%%%DocumentFonts: %@\n", [e nextObject]);
while ((name = [e nextObject]))
{
DPSPrintf(self, "%%%%+ %@\n", name);
}
}
}
- (void) endHeaderComments
{
DPSPrintf(self, "%%%%EndComments\n\n");
}
- (void) endPageSetup
{
DPSPrintf(self, "%%%%EndPageSetup\n");
}
- (void) endPrologue
{
DPSPrintf(self, "%%%%EndProlog\n\n");
}
- (void) endSetup
{
DPSPrintf(self, "%%%%EndSetup\n\n");
}
- (void) endSheet
{
NSPrintOperation *printOp = [NSPrintOperation currentOperation];
if ([printOp isEPSOperation] == NO)
{
[self showPage];
}
DPSPrintf(self, "%%%%PageTrailer\n\n");
}
- (void) endTrailer
{
DPSPrintf(self, "%%%%EOF\n");
}
- (void) printerProlog
{
NSString *prolog;
DPSPrintf(self, "%%%%BeginProlog\n");
prolog = [NSBundle pathForLibraryResource: @"GSProlog"
ofType: @"ps"
inDirectory: @"PostScript"];
if (prolog == nil)
{
NSLog(@"Cannot find printer prolog file");
return;
}
prolog = [NSString stringWithContentsOfFile: prolog];
DPSPrintf(self, [prolog cString]);
}
- (void) showPage
{
DPSPrintf(self, "showpage\n");
}
@end

View file

@ -65,10 +65,10 @@
/* Local pagination variables needed while printing */ /* Local pagination variables needed while printing */
typedef struct _page_info_t { typedef struct _page_info_t {
NSRect scaledBounds; /* View's rect scaled by the user specified scale NSRect scaledBounds; /* View's rect scaled by the user specified scale
and page fitting */ and page fitting */
NSRect paperBounds; /* Print area of a page in default user space, possibly NSRect paperBounds; /* Print area of a page in default user space, possibly
rotated if printing Landscape */ rotated if printing Landscape */
NSRect sheetBounds; /* Print are of a page in default user space */ NSRect sheetBounds; /* Print area of a sheet in default user space */
NSSize paperSize; /* Size of the paper */ NSSize paperSize; /* Size of the paper */
int xpages, ypages; int xpages, ypages;
int first, last; int first, last;
@ -86,16 +86,16 @@ typedef struct _page_info_t {
- (BOOL) _runOperation; - (BOOL) _runOperation;
- (void) _setupPrintInfo; - (void) _setupPrintInfo;
- (void)_printOperationDidRun:(NSPrintOperation *)printOperation - (void)_printOperationDidRun:(NSPrintOperation *)printOperation
returnCode:(int)returnCode returnCode:(int)returnCode
contextInfo:(void *)contextInfo; contextInfo:(void *)contextInfo;
- (void) _printPaginateWithInfo: (page_info_t *)info - (void) _printPaginateWithInfo: (page_info_t *)info
knowsRange: (BOOL)knowsRange; knowsRange: (BOOL)knowsRange;
- (NSRect) _rectForPage: (int)page info: (page_info_t *)info - (NSRect) _rectForPage: (int)page info: (page_info_t *)info
xpage: (int *)xptr xpage: (int *)xptr
ypage: (int *)yptr; ypage: (int *)yptr;
- (NSRect) _adjustPagesFirst: (int)first - (NSRect) _adjustPagesFirst: (int)first
last: (int)last last: (int)last
info: (page_info_t *)info; info: (page_info_t *)info;
- (void) _print; - (void) _print;
@end @end
@ -106,12 +106,11 @@ typedef struct _page_info_t {
@interface NSView (NSPrintOperation) @interface NSView (NSPrintOperation)
- (void) _displayPageInRect: (NSRect)pageRect - (void) _displayPageInRect: (NSRect)pageRect
atPlacement: (NSPoint)location withInfo: (page_info_t)info;
withInfo: (page_info_t)info;
- (void) _endSheet;
@end @end
@interface NSView (NPrintOperationPrivate) @interface NSView (NPrintOperationPrivate)
- (void) _endSheet;
- (void) _cleanupPrinting; - (void) _cleanupPrinting;
@end @end
@ -152,82 +151,82 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
// Creating and Initializing an NSPrintOperation Object // Creating and Initializing an NSPrintOperation Object
// //
+ (NSPrintOperation *)EPSOperationWithView:(NSView *)aView + (NSPrintOperation *)EPSOperationWithView:(NSView *)aView
insideRect:(NSRect)rect insideRect:(NSRect)rect
toData:(NSMutableData *)data toData:(NSMutableData *)data
{ {
return [self EPSOperationWithView: aView return [self EPSOperationWithView: aView
insideRect: rect insideRect: rect
toData: data toData: data
printInfo: nil]; printInfo: nil];
} }
+ (NSPrintOperation *)EPSOperationWithView:(NSView *)aView + (NSPrintOperation *)EPSOperationWithView:(NSView *)aView
insideRect:(NSRect)rect insideRect:(NSRect)rect
toData:(NSMutableData *)data toData:(NSMutableData *)data
printInfo:(NSPrintInfo *)aPrintInfo printInfo:(NSPrintInfo *)aPrintInfo
{ {
return AUTORELEASE([[GSEPSPrintOperation alloc] initWithView: aView return AUTORELEASE([[GSEPSPrintOperation alloc] initWithView: aView
insideRect: rect insideRect: rect
toData: data toData: data
printInfo: aPrintInfo]); printInfo: aPrintInfo]);
} }
+ (NSPrintOperation *)EPSOperationWithView:(NSView *)aView + (NSPrintOperation *)EPSOperationWithView:(NSView *)aView
insideRect:(NSRect)rect insideRect:(NSRect)rect
toPath:(NSString *)path toPath:(NSString *)path
printInfo:(NSPrintInfo *)aPrintInfo printInfo:(NSPrintInfo *)aPrintInfo
{ {
return AUTORELEASE([[GSEPSPrintOperation alloc] initWithView: aView return AUTORELEASE([[GSEPSPrintOperation alloc] initWithView: aView
insideRect: rect insideRect: rect
toPath: path toPath: path
printInfo: aPrintInfo]); printInfo: aPrintInfo]);
} }
+ (NSPrintOperation *)printOperationWithView:(NSView *)aView + (NSPrintOperation *)printOperationWithView:(NSView *)aView
{ {
return [self printOperationWithView: aView return [self printOperationWithView: aView
printInfo: nil]; printInfo: nil];
} }
+ (NSPrintOperation *)printOperationWithView:(NSView *)aView + (NSPrintOperation *)printOperationWithView:(NSView *)aView
printInfo:(NSPrintInfo *)aPrintInfo printInfo:(NSPrintInfo *)aPrintInfo
{ {
return AUTORELEASE([[GSPrintOperation alloc] initWithView: aView return AUTORELEASE([[GSPrintOperation alloc] initWithView: aView
printInfo: aPrintInfo]); printInfo: aPrintInfo]);
} }
+ (NSPrintOperation *)PDFOperationWithView:(NSView *)aView + (NSPrintOperation *)PDFOperationWithView:(NSView *)aView
insideRect:(NSRect)rect insideRect:(NSRect)rect
toData:(NSMutableData *)data toData:(NSMutableData *)data
{ {
return [self PDFOperationWithView: aView return [self PDFOperationWithView: aView
insideRect: rect insideRect: rect
toData: data toData: data
printInfo: nil]; printInfo: nil];
} }
+ (NSPrintOperation *)PDFOperationWithView:(NSView *)aView + (NSPrintOperation *)PDFOperationWithView:(NSView *)aView
insideRect:(NSRect)rect insideRect:(NSRect)rect
toData:(NSMutableData *)data toData:(NSMutableData *)data
printInfo:(NSPrintInfo*)aPrintInfo printInfo:(NSPrintInfo*)aPrintInfo
{ {
return AUTORELEASE([[GSPDFPrintOperation alloc] return AUTORELEASE([[GSPDFPrintOperation alloc]
initWithView: aView initWithView: aView
insideRect: rect insideRect: rect
toData: data toData: data
printInfo: aPrintInfo]); printInfo: aPrintInfo]);
} }
+ (NSPrintOperation *)PDFOperationWithView:(NSView *)aView + (NSPrintOperation *)PDFOperationWithView:(NSView *)aView
insideRect:(NSRect)rect insideRect:(NSRect)rect
toPath:(NSString *)path toPath:(NSString *)path
printInfo:(NSPrintInfo*)aPrintInfo printInfo:(NSPrintInfo*)aPrintInfo
{ {
return AUTORELEASE([[GSPDFPrintOperation alloc] return AUTORELEASE([[GSPDFPrintOperation alloc]
initWithView: aView initWithView: aView
insideRect: rect insideRect: rect
toPath: path toPath: path
printInfo: aPrintInfo]); printInfo: aPrintInfo]);
} }
// //
@ -267,25 +266,25 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
// //
- (id)initEPSOperationWithView:(NSView *)aView - (id)initEPSOperationWithView:(NSView *)aView
insideRect:(NSRect)rect insideRect:(NSRect)rect
toData:(NSMutableData *)data toData:(NSMutableData *)data
printInfo:(NSPrintInfo *)aPrintInfo printInfo:(NSPrintInfo *)aPrintInfo
{ {
RELEASE(self); RELEASE(self);
return [[GSEPSPrintOperation alloc] initWithView: aView return [[GSEPSPrintOperation alloc] initWithView: aView
insideRect: rect insideRect: rect
toData: data toData: data
printInfo: aPrintInfo]; printInfo: aPrintInfo];
} }
- (id)initWithView:(NSView *)aView - (id)initWithView:(NSView *)aView
printInfo:(NSPrintInfo *)aPrintInfo printInfo:(NSPrintInfo *)aPrintInfo
{ {
RELEASE(self); RELEASE(self);
return [[GSPrintOperation alloc] initWithView: aView return [[GSPrintOperation alloc] initWithView: aView
printInfo: aPrintInfo]; printInfo: aPrintInfo];
} }
- (void) dealloc - (void) dealloc
@ -490,10 +489,10 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
[panel setAccessoryView: nil]; [panel setAccessoryView: nil];
if (button != NSOKButton) if (button != NSOKButton)
{ {
[self cleanUpOperation]; [self cleanUpOperation];
return NO; return NO;
} }
[panel finalWritePrintInfo]; [panel finalWritePrintInfo];
} }
@ -534,11 +533,11 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
[self _setupPrintInfo]; [self _setupPrintInfo];
[panel updateFromPrintInfo]; [panel updateFromPrintInfo];
[panel beginSheetWithPrintInfo: _print_info [panel beginSheetWithPrintInfo: _print_info
modalForWindow: docWindow modalForWindow: docWindow
delegate: self delegate: self
didEndSelector: didEndSelector:
@selector(_printOperationDidRun:returnCode:contextInfo:) @selector(_printOperationDidRun:returnCode:contextInfo:)
contextInfo: contextInfo]; contextInfo: contextInfo];
[panel setAccessoryView: nil]; [panel setAccessoryView: nil];
} }
@ -598,14 +597,14 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
@implementation NSPrintOperation (Private) @implementation NSPrintOperation (Private)
- (id) initWithView:(NSView *)aView - (id) initWithView:(NSView *)aView
insideRect:(NSRect)rect insideRect:(NSRect)rect
toData:(NSMutableData *)data toData:(NSMutableData *)data
printInfo:(NSPrintInfo *)aPrintInfo printInfo:(NSPrintInfo *)aPrintInfo
{ {
if ([NSPrintOperation currentOperation] != nil) if ([NSPrintOperation currentOperation] != nil)
{ {
[NSException raise: NSPrintOperationExistsException [NSException raise: NSPrintOperationExistsException
format: @"There is already a printoperation for this thread"]; format: @"There is already a printoperation for this thread"];
} }
ASSIGN(_view, aView); ASSIGN(_view, aView);
@ -643,10 +642,10 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
if (_page_order == NSUnknownPageOrder) if (_page_order == NSUnknownPageOrder)
{ {
if ([[[_print_info dictionary] objectForKey: NSPrintReversePageOrder] if ([[[_print_info dictionary] objectForKey: NSPrintReversePageOrder]
boolValue] == YES) boolValue] == YES)
_page_order = NSDescendingPageOrder; _page_order = NSDescendingPageOrder;
else else
_page_order = NSAscendingPageOrder; _page_order = NSAscendingPageOrder;
} }
[NSGraphicsContext setCurrentContext: _context]; [NSGraphicsContext setCurrentContext: _context];
@ -661,7 +660,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
[_view _cleanupPrinting]; [_view _cleanupPrinting];
[NSGraphicsContext setCurrentContext: oldContext]; [NSGraphicsContext setCurrentContext: oldContext];
NSRunAlertPanel(@"Error", @"Printing error: %@", NSRunAlertPanel(@"Error", @"Printing error: %@",
@"OK", NULL, NULL, localException); @"OK", NULL, NULL, localException);
} }
NS_ENDHANDLER NS_ENDHANDLER
[self destroyContext]; [self destroyContext];
@ -686,8 +685,8 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
} }
- (void)_printOperationDidRun:(NSPrintOperation *)printOperation - (void)_printOperationDidRun:(NSPrintOperation *)printOperation
returnCode:(int)returnCode returnCode:(int)returnCode
contextInfo:(void *)contextInfo contextInfo:(void *)contextInfo
{ {
id delegate; id delegate;
SEL didRunSelector; SEL didRunSelector;
@ -700,7 +699,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
NSPrintPanel *panel = [self printPanel]; NSPrintPanel *panel = [self printPanel];
[panel finalWritePrintInfo]; [panel finalWritePrintInfo];
if ([self _runOperation]) if ([self _runOperation])
success = [self deliverResult]; success = [self deliverResult];
} }
[self cleanUpOperation]; [self cleanUpOperation];
dict = [_print_info dictionary]; dict = [_print_info dictionary];
@ -717,7 +716,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
/*
static NSSize static NSSize
scaleSize(NSSize size, double scale) scaleSize(NSSize size, double scale)
{ {
@ -725,14 +724,15 @@ scaleSize(NSSize size, double scale)
size.width *= scale; size.width *= scale;
return size; return size;
} }
*/
static NSRect static NSRect
scaleRect(NSRect rect, double scale) scaleRect(NSRect rect, double scale)
{ {
return NSMakeRect(NSMinX(rect) * scale, return NSMakeRect(NSMinX(rect) * scale,
NSMinY(rect) * scale, NSMinY(rect) * scale,
NSWidth(rect) * scale, NSWidth(rect) * scale,
NSHeight(rect) * scale); NSHeight(rect) * scale);
} }
/* Pagination - guess how many pages we need to print. This could be off /* Pagination - guess how many pages we need to print. This could be off
@ -770,17 +770,17 @@ scaleRect(NSRect rect, double scale)
if (info->orient == NSLandscapeOrientation) if (info->orient == NSLandscapeOrientation)
{ {
/* Bounding box needs to be in default user space, but the bbox /* Bounding box needs to be in default user space, but the bbox
we get is rotated */ we get is rotated */
info->sheetBounds = NSMakeRect(NSMinY(info->paperBounds), info->sheetBounds = NSMakeRect(NSMinY(info->paperBounds),
NSMinX(info->paperBounds), NSMinX(info->paperBounds),
NSHeight(info->paperBounds), NSHeight(info->paperBounds),
NSWidth(info->paperBounds)); NSWidth(info->paperBounds));
} }
/* Save this for the view to look at */ /* Save this for the view to look at */
[dict setObject: [NSValue valueWithRect: info->paperBounds] [dict setObject: [NSValue valueWithRect: info->paperBounds]
forKey: @"NSPrintPaperBounds"]; forKey: @"NSPrintPaperBounds"];
[dict setObject: [NSValue valueWithRect: info->sheetBounds] [dict setObject: [NSValue valueWithRect: info->sheetBounds]
forKey: @"NSPrintSheetBounds"]; forKey: @"NSPrintSheetBounds"];
/* Scale bounds by the user specified scaling */ /* Scale bounds by the user specified scaling */
info->scaledBounds = scaleRect(_rect, info->printScale); info->scaledBounds = scaleRect(_rect, info->printScale);
@ -790,11 +790,11 @@ scaleRect(NSRect rect, double scale)
{ {
/* Now calculate page fitting to get page scale */ /* Now calculate page fitting to get page scale */
if ([_print_info horizontalPagination] == NSFitPagination) if ([_print_info horizontalPagination] == NSFitPagination)
info->pageScale = info->paperBounds.size.width info->pageScale = info->paperBounds.size.width
/ NSWidth(info->scaledBounds); / NSWidth(info->scaledBounds);
if ([_print_info verticalPagination] == NSFitPagination) if ([_print_info verticalPagination] == NSFitPagination)
info->pageScale = MIN(info->pageScale, info->pageScale = MIN(info->pageScale,
NSHeight(info->paperBounds)/NSHeight(info->scaledBounds)); NSHeight(info->paperBounds)/NSHeight(info->scaledBounds));
/* Scale bounds by pageScale */ /* Scale bounds by pageScale */
info->scaledBounds = scaleRect(info->scaledBounds, info->pageScale); info->scaledBounds = scaleRect(info->scaledBounds, info->pageScale);
@ -802,9 +802,9 @@ scaleRect(NSRect rect, double scale)
info->xpages = ceil(NSWidth(info->scaledBounds)/NSWidth(info->paperBounds)); info->xpages = ceil(NSWidth(info->scaledBounds)/NSWidth(info->paperBounds));
info->ypages = ceil(NSHeight(info->scaledBounds)/NSHeight(info->paperBounds)); info->ypages = ceil(NSHeight(info->scaledBounds)/NSHeight(info->paperBounds));
if ([_print_info horizontalPagination] == NSClipPagination) if ([_print_info horizontalPagination] == NSClipPagination)
info->xpages = 1; info->xpages = 1;
if ([_print_info verticalPagination] == NSClipPagination) if ([_print_info verticalPagination] == NSClipPagination)
info->ypages = 1; info->ypages = 1;
} }
/* Calculate nup. If nup is an odd multiple of two, secretly change the /* Calculate nup. If nup is an odd multiple of two, secretly change the
@ -814,14 +814,14 @@ scaleRect(NSRect rect, double scale)
{ {
float tmp; float tmp;
if (info->orient == NSLandscapeOrientation) if (info->orient == NSLandscapeOrientation)
info->nupScale = info->nupScale =
info->paperSize.width/(2*info->paperSize.height); info->paperSize.width/(2*info->paperSize.height);
else else
info->nupScale = info->nupScale =
info->paperSize.height/(2*info->paperSize.width); info->paperSize.height/(2*info->paperSize.width);
info->nupScale /= (info->nup / 2); info->nupScale /= (info->nup / 2);
info->orient = (info->orient == NSPortraitOrientation) ? info->orient = (info->orient == NSPortraitOrientation) ?
NSLandscapeOrientation : NSPortraitOrientation; NSLandscapeOrientation : NSPortraitOrientation;
tmp = info->paperSize.width; tmp = info->paperSize.width;
info->paperSize.width = info->paperSize.height; info->paperSize.width = info->paperSize.height;
info->paperSize.height = tmp; info->paperSize.height = tmp;
@ -843,8 +843,8 @@ scaleRect(NSRect rect, double scale)
page. The returned pageRect is in the view's coordinate system page. The returned pageRect is in the view's coordinate system
*/ */
- (NSRect) _rectForPage: (int)page info: (page_info_t *)info - (NSRect) _rectForPage: (int)page info: (page_info_t *)info
xpage: (int *)xptr xpage: (int *)xptr
ypage: (int *)yptr ypage: (int *)yptr
{ {
int xpage, ypage; int xpage, ypage;
NSRect pageRect; NSRect pageRect;
@ -866,7 +866,7 @@ scaleRect(NSRect rect, double scale)
if (ypage == 0) if (ypage == 0)
info->lastHeight = 0; info->lastHeight = 0;
pageRect = NSMakeRect(info->lastWidth, info->lastHeight, pageRect = NSMakeRect(info->lastWidth, info->lastHeight,
NSWidth(info->paperBounds), NSHeight(info->paperBounds)); NSWidth(info->paperBounds), NSHeight(info->paperBounds));
pageRect = NSIntersectionRect(pageRect, info->scaledBounds); pageRect = NSIntersectionRect(pageRect, info->scaledBounds);
/* Scale to view's coordinate system */ /* Scale to view's coordinate system */
return scaleRect(pageRect, 1/(info->pageScale*info->printScale)); return scaleRect(pageRect, 1/(info->pageScale*info->printScale));
@ -877,8 +877,8 @@ scaleRect(NSRect rect, double scale)
_rectForPage: _rectForPage:
*/ */
- (NSRect) _adjustPagesFirst: (int)first - (NSRect) _adjustPagesFirst: (int)first
last: (int)last last: (int)last
info: (page_info_t *)info info: (page_info_t *)info
{ {
int i, xpage, ypage; int i, xpage, ypage;
double hlimit, wlimit; double hlimit, wlimit;
@ -891,22 +891,22 @@ scaleRect(NSRect rect, double scale)
pageRect = [self _rectForPage: i info: info xpage: &xpage ypage: &ypage]; pageRect = [self _rectForPage: i info: info xpage: &xpage ypage: &ypage];
limitVal = NSMaxY(pageRect) - hlimit * NSHeight(pageRect); limitVal = NSMaxY(pageRect) - hlimit * NSHeight(pageRect);
[_view adjustPageHeightNew: &newVal [_view adjustPageHeightNew: &newVal
top: NSMinY(pageRect) top: NSMinY(pageRect)
bottom: NSMaxY(pageRect) bottom: NSMaxY(pageRect)
limit: limitVal]; limit: limitVal];
if (newVal < NSMaxY(pageRect)) if (newVal < NSMaxY(pageRect))
pageRect.size.height = MAX(newVal, limitVal) - NSMinY(pageRect); pageRect.size.height = MAX(newVal, limitVal) - NSMinY(pageRect);
limitVal = NSMaxX(pageRect) - wlimit * NSWidth(pageRect); limitVal = NSMaxX(pageRect) - wlimit * NSWidth(pageRect);
[_view adjustPageWidthNew: &newVal [_view adjustPageWidthNew: &newVal
left: NSMinX(pageRect) left: NSMinX(pageRect)
right: NSMaxX(pageRect) right: NSMaxX(pageRect)
limit: limitVal]; limit: limitVal];
if (newVal < NSMaxX(pageRect)) if (newVal < NSMaxX(pageRect))
pageRect.size.width = MAX(newVal, limitVal) - NSMinX(pageRect); pageRect.size.width = MAX(newVal, limitVal) - NSMinX(pageRect);
if (info->pageDirection == 0 || ypage == info->ypages - 1) if (info->pageDirection == 0 || ypage == info->ypages - 1)
info->lastWidth = NSMaxX(pageRect)*(info->pageScale*info->printScale); info->lastWidth = NSMaxX(pageRect)*(info->pageScale*info->printScale);
if (info->pageDirection == 1 || xpage == info->xpages - 1) if (info->pageDirection == 1 || xpage == info->xpages - 1)
info->lastHeight = NSMaxY(pageRect)*(info->pageScale*info->printScale); info->lastHeight = NSMaxY(pageRect)*(info->pageScale*info->printScale);
} }
return pageRect; return pageRect;
} }
@ -936,7 +936,7 @@ scaleRect(NSRect rect, double scale)
} }
[dict setObject: NSNUMBER(NSMaxRange(viewPageRange)) [dict setObject: NSNUMBER(NSMaxRange(viewPageRange))
forKey: @"NSPrintTotalPages"]; forKey: @"NSPrintTotalPages"];
if (allPages == YES) if (allPages == YES)
{ {
info.first = viewPageRange.location; info.first = viewPageRange.location;
@ -960,10 +960,10 @@ scaleRect(NSRect rect, double scale)
else else
[dict setObject: NSNUMBER(info.last) forKey: NSPrintLastPage]; [dict setObject: NSNUMBER(info.last) forKey: NSPrintLastPage];
NSDebugLLog(@"NSPrinting", @"Printing pages %d to %d", NSDebugLLog(@"NSPrinting", @"Printing pages %d to %d",
info.first, info.last); info.first, info.last);
NSDebugLLog(@"NSPrinting", @"Printing rect %@, scaled %@", NSDebugLLog(@"NSPrinting", @"Printing rect %@, scaled %@",
NSStringFromRect(_rect), NSStringFromRect(_rect),
NSStringFromRect(info.scaledBounds)); NSStringFromRect(info.scaledBounds));
_currentPage = info.first; _currentPage = info.first;
dir = 1; dir = 1;
@ -975,11 +975,11 @@ scaleRect(NSRect rect, double scale)
if (dir > 0 && _currentPage != 1) if (dir > 0 && _currentPage != 1)
{ {
/* Calculate page rects we aren't processing to catch up to the /* Calculate page rects we aren't processing to catch up to the
first page we are */ first page we are */
NSRect pageRect; NSRect pageRect;
pageRect = [self _adjustPagesFirst: 1 pageRect = [self _adjustPagesFirst: 1
last: _currentPage-1 last: _currentPage-1
info: &info]; info: &info];
} }
/* Print the header information */ /* Print the header information */
@ -989,54 +989,50 @@ scaleRect(NSRect rect, double scale)
i = 0; i = 0;
while (i < (info.last-info.first+1)) while (i < (info.last-info.first+1))
{ {
NSPoint location; NSRect pageRect;
NSRect pageRect, scaledPageRect;
if (knowsPageRange == YES) if (knowsPageRange == YES)
{ {
pageRect = [_view rectForPage: _currentPage]; pageRect = [_view rectForPage: _currentPage];
} }
else else
{ {
if (dir < 0) if (dir < 0)
pageRect = [self _adjustPagesFirst: 1 pageRect = [self _adjustPagesFirst: 1
last: _currentPage last: _currentPage
info: &info]; info: &info];
else else
pageRect = [self _adjustPagesFirst: _currentPage pageRect = [self _adjustPagesFirst: _currentPage
last: _currentPage last: _currentPage
info: &info]; info: &info];
} }
NSDebugLLog(@"NSPrinting", @" current page %d, rect %@", NSDebugLLog(@"NSPrinting", @" current page %d, rect %@",
_currentPage, NSStringFromRect(pageRect)); _currentPage, NSStringFromRect(pageRect));
if (NSIsEmptyRect(pageRect)) if (NSIsEmptyRect(pageRect))
break; break;
scaledPageRect = scaleRect(pageRect, info.printScale*info.pageScale);
location = [_view locationOfPrintRect: scaledPageRect];
/* Draw using our special view routine */ /* Draw using our special view routine */
[_view _displayPageInRect: pageRect [_view _displayPageInRect: pageRect
atPlacement: location withInfo: info];
withInfo: info];
if (dir > 0 && _currentPage == info.last && allPages == YES) if (dir > 0 && _currentPage == info.last && allPages == YES)
{ {
/* Check if adjust pages forced part of the bounds onto /* Check if adjust pages forced part of the bounds onto
another page */ another page */
if (NSMaxX(pageRect) < NSMaxX(_rect) if (NSMaxX(pageRect) < NSMaxX(_rect)
&& [_print_info horizontalPagination] != NSClipPagination) && [_print_info horizontalPagination] != NSClipPagination)
{ {
info.xpages++; info.xpages++;
} }
if (NSMaxY(pageRect) < NSMaxY(_rect) if (NSMaxY(pageRect) < NSMaxY(_rect)
&& [_print_info verticalPagination] != NSClipPagination) && [_print_info verticalPagination] != NSClipPagination)
{ {
info.ypages++; info.ypages++;
} }
viewPageRange = NSMakeRange(1, (info.xpages * info.ypages)); viewPageRange = NSMakeRange(1, (info.xpages * info.ypages));
info.last = NSMaxRange(viewPageRange) - 1; info.last = NSMaxRange(viewPageRange) - 1;
} }
i++; i++;
_currentPage += dir; _currentPage += dir;
} /* Print each page */ } /* Print each page */
@ -1044,7 +1040,7 @@ scaleRect(NSRect rect, double scale)
/* Make sure we end the sheet */ /* Make sure we end the sheet */
if (info.nup > 1 && (info.last - info.first) % info.nup != info.nup - 1) if (info.nup > 1 && (info.last - info.first) % info.nup != info.nup - 1)
{ {
[_view drawSheetBorderWithSize: info.paperBounds.size]; [_view drawSheetBorderWithSize: info.sheetBounds.size];
[_view _endSheet]; [_view _endSheet];
} }
[_view endDocument]; [_view endDocument];
@ -1054,7 +1050,7 @@ scaleRect(NSRect rect, double scale)
if (((int)(info.nup / 2) & 0x1) == 1) if (((int)(info.nup / 2) & 0x1) == 1)
{ {
info.orient = (info.orient == NSPortraitOrientation) ? info.orient = (info.orient == NSPortraitOrientation) ?
NSLandscapeOrientation : NSPortraitOrientation; NSLandscapeOrientation : NSPortraitOrientation;
[dict setObject: NSNUMBER(info.orient) forKey: NSPrintOrientation]; [dict setObject: NSNUMBER(info.orient) forKey: NSPrintOrientation];
} }
} }
@ -1063,46 +1059,60 @@ scaleRect(NSRect rect, double scale)
@implementation NSView (NSPrintOperation) @implementation NSView (NSPrintOperation)
- (void) _displayPageInRect: (NSRect)pageRect - (void) _displayPageInRect: (NSRect)pageRect
atPlacement: (NSPoint)location withInfo: (page_info_t)info
withInfo: (page_info_t)info
{ {
int currentPage; int currentPage;
int numberOnSheet;
float xoffset, yoffset, scale; float xoffset, yoffset, scale;
NSString *label; NSPoint location;
NSPrintOperation *printOp = [NSPrintOperation currentOperation]; NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context]; NSGraphicsContext *ctxt = [printOp context];
currentPage = [printOp currentPage]; currentPage = [printOp currentPage];
numberOnSheet = (currentPage - info.first) % info.nup;
label = nil;
if (info.nup == 1)
label = [NSString stringWithFormat: @"%d", currentPage];
/* Begin a sheet (i.e. a physical page in Postscript terms). If /* Begin a sheet (i.e. a physical page in Postscript terms). If
nup > 1 then this occurs only once every nup pages */ nup > 1 then this occurs only once every nup pages */
if ((currentPage - info.first) % info.nup == 0) if (numberOnSheet == 0)
{ {
NSString *label;
label = nil;
if (info.nup == 1)
label = [NSString stringWithFormat: @"%d", currentPage];
[self beginPage: floor((currentPage - info.first)/info.nup)+1 [self beginPage: floor((currentPage - info.first)/info.nup)+1
label: label label: label
bBox: info.sheetBounds bBox: info.sheetBounds
fonts: nil]; fonts: nil];
if (info.orient == NSLandscapeOrientation) if (info.orient == NSLandscapeOrientation)
{ {
DPSrotate(ctxt, 90); DPSrotate(ctxt, 90);
DPStranslate(ctxt, 0, -info.paperSize.height); DPStranslate(ctxt, 0, -info.paperSize.height);
} }
/* Also offset by margins */ /* Also offset by margins */
DPStranslate(ctxt, NSMinX(info.paperBounds), NSMinY(info.paperBounds)); DPStranslate(ctxt, NSMinX(info.paperBounds), NSMinY(info.paperBounds));
/* End page setup for multi page */
if (info.nup != 1)
{
[self addToPageSetup];
[self endPageSetup];
}
} }
scale = info.pageScale * info.printScale;
location = [self locationOfPrintRect: scaleRect(pageRect, scale)];
/* Begin a logical page */ /* Begin a logical page */
[self beginPageInRect: pageRect atPlacement: location]; [self beginPageInRect: pageRect atPlacement: location];
scale = info.pageScale * info.printScale;
if (scale != 1.0) if (scale != 1.0)
DPSscale(ctxt, scale, scale); DPSscale(ctxt, scale, scale);
/* FIXME: Why is this needed? Shouldn't the flip be handled by the lockFocus method? */
if ([self isFlipped]) if ([self isFlipped])
{ {
NSAffineTransformStruct ats = { 1, 0, 0, -1, 0, NSHeight(_bounds) }; NSAffineTransformStruct ats = { 1, 0, 0, -1, 0, NSHeight(_bounds) };
NSAffineTransform *matrix, *flip; NSAffineTransform *matrix, *flip;
flip = [NSAffineTransform new]; flip = [NSAffineTransform new];
@ -1110,7 +1120,7 @@ scaleRect(NSRect rect, double scale)
[matrix prependTransform: _boundsMatrix]; [matrix prependTransform: _boundsMatrix];
/* /*
* The flipping process must result in a coordinate system that * The flipping process must result in a coordinate system that
* exactly overlays the original. To do that, we must translate * exactly overlays the original. To do that, we must translate
* the origin by the height of the view. * the origin by the height of the view.
*/ */
[flip setTransformStruct: ats]; [flip setTransformStruct: ats];
@ -1127,35 +1137,28 @@ scaleRect(NSRect rect, double scale)
xoffset = 0 - NSMinX(pageRect); xoffset = 0 - NSMinX(pageRect);
DPStranslate(ctxt, xoffset, yoffset); DPStranslate(ctxt, xoffset, yoffset);
if ((currentPage - info.first) % info.nup == 0) /* End page setup for single page */
[self endPageSetup]; if (info.nup == 1)
{
[self addToPageSetup];
[self endPageSetup];
}
/* Do the actual drawing */ /* Do the actual drawing */
[self displayRectIgnoringOpacity: pageRect]; [self displayRectIgnoringOpacity: pageRect];
/* End a logical page */ /* End a logical page */
DPSgrestore(ctxt); // Balance gsave in beginPageInRect: // Balance gsave in beginPageInRect:
[self drawPageBorderWithSize: DPSgrestore(ctxt);
scaleSize(info.paperBounds.size, info.nupScale)]; [self drawPageBorderWithSize: info.paperBounds.size];
[self endPage]; [self endPage];
/* End a physical page */ /* End a physical page */
if (((currentPage - info.first) % info.nup == info.nup-1)) if (numberOnSheet == info.nup - 1)
{ {
[self drawSheetBorderWithSize: info.paperBounds.size]; [self drawSheetBorderWithSize: info.sheetBounds.size];
[self _endSheet]; [self _endSheet];
} }
} }
- (void) _endSheet
{
NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context];
if ([printOp isEPSOperation] == NO)
DPSPrintf(ctxt, "showpage\n");
DPSPrintf(ctxt, "%%%%PageTrailer\n");
DPSPrintf(ctxt, "\n");
}
@end @end

View file

@ -71,7 +71,6 @@
#include "AppKit/PSOperators.h" #include "AppKit/PSOperators.h"
#include "GNUstepGUI/GSDisplayServer.h" #include "GNUstepGUI/GSDisplayServer.h"
#include "GNUstepGUI/GSTrackingRect.h" #include "GNUstepGUI/GSTrackingRect.h"
#include "GNUstepGUI/GSVersion.h"
#include "GSToolTips.h" #include "GSToolTips.h"
/* /*
@ -3765,9 +3764,9 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
if (pages == 1) if (pages == 1)
{ {
if ([printInfo isHorizontallyCentered]) if ([printInfo isHorizontallyCentered])
location.x = (NSWidth(bounds) - NSWidth(aRect))/2; location.x = (NSWidth(bounds) - NSWidth(aRect))/2;
if ([printInfo isVerticallyCentered]) if ([printInfo isVerticallyCentered])
location.y = (NSHeight(bounds) - NSHeight(aRect))/2; location.y = (NSHeight(bounds) - NSHeight(aRect))/2;
} }
return location; return location;
@ -3787,23 +3786,17 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
* Writing Conforming PostScript * Writing Conforming PostScript
*/ */
- (void) beginPage: (int)ordinalNum - (void) beginPage: (int)ordinalNum
label: (NSString*)aString label: (NSString*)aString
bBox: (NSRect)pageRect bBox: (NSRect)pageRect
fonts: (NSString*)fontNames fonts: (NSString*)fontNames
{ {
NSPrintOperation *printOp = [NSPrintOperation currentOperation]; NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context]; NSGraphicsContext *ctxt = [printOp context];
if (aString == nil) [ctxt beginPage: ordinalNum
aString = [[NSNumber numberWithInt: ordinalNum] description]; label: aString
DPSPrintf(ctxt, "%%%%Page: %s %d\n", [aString lossyCString], ordinalNum); bBox: pageRect
if (NSIsEmptyRect(pageRect) == NO) fonts: fontNames];
DPSPrintf(ctxt, "%%%%PageBoundingBox: %d %d %d %d\n",
(int)NSMinX(pageRect), (int)NSMinY(pageRect),
(int)NSMaxX(pageRect), (int)NSMaxY(pageRect));
if (fontNames)
DPSPrintf(ctxt, "%%%%PageFonts: %s\n", [fontNames lossyCString]);
DPSPrintf(ctxt, "%%%%BeginPageSetup\n");
} }
- (void) beginPageSetupRect: (NSRect)aRect placement: (NSPoint)location - (void) beginPageSetupRect: (NSRect)aRect placement: (NSPoint)location
@ -3812,64 +3805,23 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
} }
- (void) beginPrologueBBox: (NSRect)boundingBox - (void) beginPrologueBBox: (NSRect)boundingBox
creationDate: (NSString*)dateCreated creationDate: (NSString*)dateCreated
createdBy: (NSString*)anApplication createdBy: (NSString*)anApplication
fonts: (NSString*)fontNames fonts: (NSString*)fontNames
forWhom: (NSString*)user forWhom: (NSString*)user
pages: (int)numPages pages: (int)numPages
title: (NSString*)aTitle title: (NSString*)aTitle
{ {
NSPrintOperation *printOp = [NSPrintOperation currentOperation]; NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context]; NSGraphicsContext *ctxt = [printOp context];
NSPrintingOrientation orient;
BOOL epsOp;
epsOp = [printOp isEPSOperation]; [ctxt beginPrologueBBox: boundingBox
orient = [[printOp printInfo] orientation]; creationDate: dateCreated
createdBy: anApplication
if (epsOp) fonts: fontNames
DPSPrintf(ctxt, "%%!PS-Adobe-3.0 EPSF-3.0\n"); forWhom: user
else pages: numPages
DPSPrintf(ctxt, "%%!PS-Adobe-3.0\n"); title: aTitle];
DPSPrintf(ctxt, "%%%%Title: %s\n", [aTitle lossyCString]);
DPSPrintf(ctxt, "%%%%Creator: %s\n", [anApplication lossyCString]);
DPSPrintf(ctxt, "%%%%CreationDate: %s\n",
[[dateCreated description] lossyCString]);
DPSPrintf(ctxt, "%%%%For: %s\n", [user lossyCString]);
if (fontNames)
DPSPrintf(ctxt, "%%%%DocumentFonts: %s\n", [fontNames lossyCString]);
else
DPSPrintf(ctxt, "%%%%DocumentFonts: (atend)\n");
if (NSIsEmptyRect(boundingBox) == NO)
DPSPrintf(ctxt, "%%%%BoundingBox: %d %d %d %d\n",
(int)NSMinX(boundingBox), (int)NSMinY(boundingBox),
(int)NSMaxX(boundingBox), (int)NSMaxY(boundingBox));
else
DPSPrintf(ctxt, "%%%%BoundingBox: (atend)\n");
if (epsOp == NO)
{
if (numPages)
DPSPrintf(ctxt, "%%%%Pages: %d\n", numPages);
else
DPSPrintf(ctxt, "%%%%Pages: (atend)\n");
if ([printOp pageOrder] == NSDescendingPageOrder)
DPSPrintf(ctxt, "%%%%PageOrder: Descend\n");
else if ([printOp pageOrder] == NSAscendingPageOrder)
DPSPrintf(ctxt, "%%%%PageOrder: Ascend\n");
else if ([printOp pageOrder] == NSSpecialPageOrder)
DPSPrintf(ctxt, "%%%%PageOrder: Special\n");
if (orient == NSPortraitOrientation)
DPSPrintf(ctxt, "%%%%Orientation: Portrait\n");
else
DPSPrintf(ctxt, "%%%%Orientation: Landscape\n");
}
DPSPrintf(ctxt, "%%%%GNUstepVersion: %d.%d.%d\n",
GNUSTEP_GUI_MAJOR_VERSION, GNUSTEP_GUI_MINOR_VERSION,
GNUSTEP_GUI_SUBMINOR_VERSION);
} }
- (void) addToPageSetup - (void) addToPageSetup
@ -3881,7 +3833,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
NSPrintOperation *printOp = [NSPrintOperation currentOperation]; NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context]; NSGraphicsContext *ctxt = [printOp context];
DPSPrintf(ctxt, "%%%%BeginSetup\n"); [ctxt beginSetup];
} }
- (void) beginTrailer - (void) beginTrailer
@ -3889,7 +3841,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
NSPrintOperation *printOp = [NSPrintOperation currentOperation]; NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context]; NSGraphicsContext *ctxt = [printOp context];
DPSPrintf(ctxt, "%%%%Trailer\n"); [ctxt beginTrailer];
} }
- (void) drawPageBorderWithSize: (NSSize)borderSize - (void) drawPageBorderWithSize: (NSSize)borderSize
@ -3905,7 +3857,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
NSPrintOperation *printOp = [NSPrintOperation currentOperation]; NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context]; NSGraphicsContext *ctxt = [printOp context];
DPSPrintf(ctxt, "%%%%EndComments\n\n"); [ctxt endHeaderComments];
} }
- (void) endPrologue - (void) endPrologue
@ -3913,7 +3865,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
NSPrintOperation *printOp = [NSPrintOperation currentOperation]; NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context]; NSGraphicsContext *ctxt = [printOp context];
DPSPrintf(ctxt, "%%%%EndProlog\n\n"); [ctxt endPrologue];
} }
- (void) endSetup - (void) endSetup
@ -3921,7 +3873,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
NSPrintOperation *printOp = [NSPrintOperation currentOperation]; NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context]; NSGraphicsContext *ctxt = [printOp context];
DPSPrintf(ctxt, "%%%%EndSetup\n\n"); [ctxt endSetup];
} }
- (void) endPageSetup - (void) endPageSetup
@ -3929,7 +3881,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
NSPrintOperation *printOp = [NSPrintOperation currentOperation]; NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context]; NSGraphicsContext *ctxt = [printOp context];
DPSPrintf(ctxt, "%%%%EndPageSetup\n"); [ctxt endPageSetup];
} }
- (void) endPage - (void) endPage
@ -3953,13 +3905,12 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
NSPrintOperation *printOp = [NSPrintOperation currentOperation]; NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context]; NSGraphicsContext *ctxt = [printOp context];
DPSPrintf(ctxt, "%%%%EOF\n"); [ctxt endTrailer];
} }
- (NSAttributedString *) pageFooter - (NSAttributedString *) pageFooter
{ {
return [[[NSAttributedString alloc] return [[[NSAttributedString alloc] initWithString:
initWithString:
[NSString stringWithFormat:@"Page %d", [NSString stringWithFormat:@"Page %d",
[[NSPrintOperation currentOperation] currentPage]]] [[NSPrintOperation currentOperation] currentPage]]]
autorelease]; autorelease];
@ -3967,27 +3918,11 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
- (NSAttributedString *) pageHeader - (NSAttributedString *) pageHeader
{ {
return [[[NSAttributedString alloc] return [[[NSAttributedString alloc] initWithString:
initWithString:
[NSString stringWithFormat:@"%@ %@", [self printJobTitle], [NSString stringWithFormat:@"%@ %@", [self printJobTitle],
[[NSCalendarDate calendarDate] description]]] autorelease]; [[NSCalendarDate calendarDate] description]]] autorelease];
} }
- (void) _loadPrinterProlog: (NSGraphicsContext *)ctxt
{
NSString *prolog;
prolog = [NSBundle pathForLibraryResource: @"GSProlog"
ofType: @"ps"
inDirectory: @"PostScript"];
if (prolog == nil)
{
NSLog(@"Cannot find printer prolog file");
return;
}
prolog = [NSString stringWithContentsOfFile: prolog];
DPSPrintf(ctxt, [prolog cString]);
}
/** /**
Writes header and job information for the PostScript document. This Writes header and job information for the PostScript document. This
@ -4044,8 +3979,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
title: [self printJobTitle]]; title: [self printJobTitle]];
[self endHeaderComments]; [self endHeaderComments];
DPSPrintf(ctxt, "%%%%BeginProlog\n"); [ctxt printerProlog];
[self _loadPrinterProlog: ctxt];
[self endPrologue]; [self endPrologue];
if ([printOp isEPSOperation] == NO) if ([printOp isEPSOperation] == NO)
{ {
@ -4064,13 +3998,13 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
atPlacement:(NSPoint)location atPlacement:(NSPoint)location
{ {
int nup; int nup;
float scale;
NSRect bounds; NSRect bounds;
NSPrintOperation *printOp = [NSPrintOperation currentOperation]; NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context]; NSGraphicsContext *ctxt = [printOp context];
NSDictionary *dict = [[printOp printInfo] dictionary]; NSDictionary *dict = [[printOp printInfo] dictionary];
// FIXME: Need to place this correctly // FIXME: Need to place this correctly. Maybe it isn't needed at all,
// as all drawing happens in displayRectIgnoringOpacity:
[self lockFocusIfCanDrawInContext: ctxt]; [self lockFocusIfCanDrawInContext: ctxt];
if ([dict objectForKey: @"NSPrintPaperBounds"]) if ([dict objectForKey: @"NSPrintPaperBounds"])
@ -4083,37 +4017,47 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
{ {
int page; int page;
float xoff, yoff; float xoff, yoff;
float scale;
DPSPrintf(ctxt, "/__GSpagesaveobject save def\n"); DPSPrintf(ctxt, "/__GSpagesaveobject save def\n");
page = [printOp currentPage]
- [[dict objectForKey: NSPrintFirstPage] intValue];
page = page % nup;
scale = [[dict objectForKey: @"NSNupScale"] floatValue]; scale = [[dict objectForKey: @"NSNupScale"] floatValue];
page = [printOp currentPage]
- [[dict objectForKey: NSPrintFirstPage] intValue];
page = page % nup;
if (nup == 2) if (nup == 2)
xoff = page; xoff = page;
else else
xoff = (page % (nup/2)); xoff = (page % (nup/2));
xoff *= NSWidth(bounds) * scale; xoff *= NSWidth(bounds) * scale;
if (nup == 2) if (nup == 2)
yoff = 0; yoff = 0;
else else
yoff = (int)((nup-page-1) / (nup/2)); yoff = (int)((nup-page-1) / (nup/2));
yoff *= NSHeight(bounds) * scale; yoff *= NSHeight(bounds) * scale;
DPStranslate(ctxt, xoff, yoff); DPStranslate(ctxt, xoff, yoff);
DPSgsave(ctxt);
DPSscale(ctxt, scale, scale); DPSscale(ctxt, scale, scale);
} }
else
DPSgsave(ctxt); // FIXME: This needs to be balanced explicitly
DPSgsave(ctxt);
/* Translate to placement */ /* Translate to placement */
if (location.x != 0 || location.y != 0) if (location.x != 0 || location.y != 0)
DPStranslate(ctxt, location.x, location.y); DPStranslate(ctxt, location.x, location.y);
} }
- (void) _endSheet
{
NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context];
[ctxt endSheet];
}
- (void)endDocument - (void)endDocument
{ {
int first, last, current, pages; int first, last, current, pages;
NSSet *fontNames;
NSPrintOperation *printOp = [NSPrintOperation currentOperation]; NSPrintOperation *printOp = [NSPrintOperation currentOperation];
NSGraphicsContext *ctxt = [printOp context]; NSGraphicsContext *ctxt = [printOp context];
NSDictionary *dict = [[printOp printInfo] dictionary]; NSDictionary *dict = [[printOp printInfo] dictionary];
@ -4129,20 +4073,14 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
current = [printOp currentPage]; current = [printOp currentPage];
pages = current - first; // Current is 1 more than the last page pages = current - first; // Current is 1 more than the last page
if (nup > 1) if (nup > 1)
pages = ceil((float)pages / nup); pages = ceil((float)pages / nup);
DPSPrintf(ctxt, "%%%%Pages: %d\n", pages);
} }
fontNames = [ctxt usedFonts]; else
if (fontNames && [fontNames count])
{ {
NSString *name; // Already reported at start of document
NSEnumerator *e = [fontNames objectEnumerator]; pages = 0;
DPSPrintf(ctxt, "%%%%DocumentFonts: %@\n", [e nextObject]);
while ((name = [e nextObject]))
{
DPSPrintf(ctxt, "%%%%+ %@\n", name);
}
} }
[ctxt endDocumentPages: pages documentFonts: [ctxt usedFonts]];
[self endTrailer]; [self endTrailer];
[self _invalidateCoordinates]; [self _invalidateCoordinates];