[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fix: Printing
From: |
Georg Fleischmann |
Subject: |
Fix: Printing |
Date: |
Sun, 16 Sep 2001 22:49:25 +0200 |
Hi,
here are three patches which fix a bunch of bugs for printing.
With the fixes [NSView -dataWithEPSInsideRect:] is now working for my
application.
The changes in NSPrintOperation create a context and deliver the results for
writing EPSData.
For all print operations, the context will be removed from the context list
after the printing has been finished.
The change in XGStreamContext just closes the stream. This can't be done in
dealloc, because the written file is needed before the autorelease pool has
been released. I have added a subclass of -destroyContext to close the stream.
The change in NSView removes the transformations to the window for printing,
because the printed view has to be the base. I'm not sure if this one is really
done in a wise way (Opinions?). For now, I have added this to
-dataWithEPSInsideRect only, but it has to be done for all printing operations.
Georg
2001-09-16 Georg Fleischmann
* gui/Source/NSPrintOperation.m
[NSPrintOperation -destroyContext:]: remove context from the context
list. Otherwise we will never get dealloced.
[NSPrintOperation -_print:]: use displayRectIgnoringOpacity to avoid
drawing of our ancestors.
[GSEPSPrintOperation -createContext:]: create a context.
[GSEPSPrintOperation -deliverResult:]: add contents of written file
to data object.
* gui/Source/XGStreamContext.m
[XGStreamContext -destroyContext:]: new, to close the stream
[XGStreamContext -dealloc:]: closing of stream removed. This has to
be done earlier (before we deliver the results).
* gui/Source/NSView.m
[NSView -dataWithEPSInsideRect:]: remove transformations to window
during the printing operation.
--- gui/Source/NSPrintOperation.m.orig Tue Jul 31 04:30:34 2001
+++ gui/Source/NSPrintOperation.m Sun Sep 16 20:48:03 2001
@@ -318,6 +318,7 @@
- (void)destroyContext
{
+ [_context destroyContext];
DESTROY(_context);
}
@@ -465,7 +466,7 @@
- (void) _print
{
// This is the actual printing
- [_view displayRect: _rect];
+ [_view displayRectIgnoringOpacity: _rect];
}
@end
@@ -554,14 +555,24 @@
- (NSGraphicsContext*)createContext
{
- // FIXME
- return nil;
+ NSMutableDictionary *info = [_printInfo dictionary];
+ NSGraphicsContext *psContext;
+
+ [info setObject: _path forKey: @"NSOutputFile"];
+ psContext = [NSGraphicsContext postscriptContextWithInfo: info];
+
+ return psContext;
}
- (BOOL)deliverResult
{
- if (_data != nil && _path != nil && [_data length])
- return [_data writeToFile: _path atomically: NO];
+ if (_data != nil && _path != nil)
+ {
+ NSString *eps;
+
+ eps = [NSString stringWithContentsOfFile: _path];
+ [_data setData: [eps dataUsingEncoding:NSASCIIStringEncoding]];
+ }
return YES;
}
--- xgps/Source/XGStreamContext.m.orig Sun Sep 16 16:44:37 2001
+++ xgps/Source/XGStreamContext.m Sun Sep 16 16:52:28 2001
@@ -61,6 +61,13 @@
return NULL;
}
+- (void) destroyContext;
+{
+ if (gstream)
+ fclose(gstream);
+ [super destroyContext];
+}
+
- initWithContextInfo: (NSDictionary *)info
{
NSZone *zone = GSObjCZone(self);
@@ -106,8 +113,6 @@
- (void) dealloc
{
- if (gstream)
- fclose(gstream);
RELEASE(opstack);
RELEASE(gstack);
RELEASE(glist);
--- gui/Source/NSView.m.orig Fri Sep 7 04:30:41 2001
+++ gui/Source/NSView.m Sun Sep 16 21:29:25 2001
@@ -2409,10 +2409,22 @@
- (NSData*) dataWithEPSInsideRect: (NSRect)aRect
{
NSMutableData *data = [NSMutableData data];
-
+ NSView *superview = _super_view;
+
+ /* for printing we have to get rid of any transformations
+ * to our superviews and window.
+ */
+ [self _invalidateCoordinates];
+ _super_view = nil;
+ [self _rebuildCoordinates];
+ _super_view = superview;
+
[[NSPrintOperation EPSOperationWithView: self
insideRect: aRect
toData: data] runOperation];
+
+ _coordinates_valid = NO;
+
return data;
}
- Fix: Printing,
Georg Fleischmann <=