diff --git a/Source/art/ARTContext.m b/Source/art/ARTContext.m index 71f7f2b..6338a9c 100644 --- a/Source/art/ARTContext.m +++ b/Source/art/ARTContext.m @@ -64,24 +64,13 @@ static int byte_order(void) [FTFontInfo initializeBackend]; } -- (id) initWithContextInfo: (NSDictionary *)info ++ (Class) GStateClass { - NSString *contextType; - contextType = [info objectForKey: - NSGraphicsContextRepresentationFormatAttributeName]; - - self = [super initWithContextInfo: info]; - if (contextType) - { - /* Most likely this is a PS or PDF context, so just return what - super gave us - */ - return self; - } - - /* Create a default gstate */ - gstate = [[ARTGState allocWithZone: [self zone]] initWithDrawContext: self]; + return [ARTGState class]; +} +- (void) setupDrawInfo +{ #ifdef RDS { RDSServer *s = (RDSServer *)server; @@ -110,21 +99,21 @@ static int byte_order(void) visualInfo = XGetVisualInfo(d, VisualClassMask, &template, &numMatches); if (!visualInfo) { - template.class = TrueColor; - visualInfo = XGetVisualInfo(d, VisualClassMask, &template, &numMatches); + template.class = TrueColor; + visualInfo = XGetVisualInfo(d, VisualClassMask, &template, &numMatches); } if (visualInfo) { - visual = visualInfo->visual; - bpp = visualInfo->depth; - XFree(visualInfo); + visual = visualInfo->visual; + bpp = visualInfo->depth; + XFree(visualInfo); } else { - visual = DefaultVisual(d, DefaultScreen(d)); - bpp = DefaultDepth(d, DefaultScreen(d)); + visual = DefaultVisual(d, DefaultScreen(d)); + bpp = DefaultDepth(d, DefaultScreen(d)); } - + i = XCreateImage(d, visual, bpp, ZPixmap, 0, NULL, 8, 8, 8, 0); bpp = i->bits_per_pixel; XDestroyImage(i); @@ -136,11 +125,11 @@ static int byte_order(void) int us = byte_order(); /* True iff we're big-endian. */ int them = ImageByteOrder(d); /* True iff the server is big-endian. */ if (us != them) - { - visual->red_mask = flip_bytes(visual->red_mask); - visual->green_mask = flip_bytes(visual->green_mask); - visual->blue_mask = flip_bytes(visual->blue_mask); - } + { + visual->red_mask = flip_bytes(visual->red_mask); + visual->green_mask = flip_bytes(visual->green_mask); + visual->blue_mask = flip_bytes(visual->blue_mask); + } } /* Only returns if the visual was usable. */ @@ -148,8 +137,6 @@ static int byte_order(void) visual->blue_mask, bpp); } #endif - - return self; } - (void) flushGraphics @@ -183,6 +170,7 @@ static int byte_order(void) @implementation ARTContext (ops) - (void) GSSetDevice: (void*)device : (int)x : (int)y { + [self setupDrawInfo]; [(ARTGState *)gstate GSSetDevice: device : x : y]; } diff --git a/Source/cairo/CairoContext.m b/Source/cairo/CairoContext.m index 76a1f55..374ed59 100644 --- a/Source/cairo/CairoContext.m +++ b/Source/cairo/CairoContext.m @@ -58,19 +58,14 @@ [GSFontInfo setDefaultClass: [CairoFontInfo class]]; } -- (id) initWithContextInfo: (NSDictionary *)info ++ (Class) GStateClass { - // Don't allow super to handle PS case. - self = [super initWithContextInfo: nil]; - if (!self) - return self; + return [CairoGState class]; +} - // Now save the info - ASSIGN(context_info, info); - - gstate = [[CairoGState allocWithZone: [self zone]] initWithDrawContext: self]; - - return self; ++ (BOOL) handlesPS +{ + return YES; } - (void) flushGraphics diff --git a/Source/gsc/GSContext.m b/Source/gsc/GSContext.m index 3a5f6a9..f49f3a3 100644 --- a/Source/gsc/GSContext.m +++ b/Source/gsc/GSContext.m @@ -155,6 +155,16 @@ static NSMapTable *gtable; NSMapRemove(gtable, (void *)(uintptr_t)index); } ++ (Class) GStateClass +{ + return [GSGState class]; +} + ++ (BOOL) handlesPS +{ + return NO; +} + - (id) initWithContextInfo: (NSDictionary *)info { NSString *contextType; @@ -162,24 +172,39 @@ static NSMapTable *gtable; contextType = [info objectForKey: NSGraphicsContextRepresentationFormatAttributeName]; - if ([self isMemberOfClass: [GSStreamContext class]] == NO - && contextType && [contextType isEqual: NSGraphicsContextPSFormat]) + if (([isa handlesPS] == NO) && contextType + && [contextType isEqual: NSGraphicsContextPSFormat]) { /* Don't call self, since we aren't initialized */ [super dealloc]; return [[GSStreamContext allocWithZone: z] initWithContextInfo: info]; } - /* A context is only associated with one server. Do not retain - the server, however */ - server = GSCurrentServer(); + self = [super initWithContextInfo: info]; + if (self != nil) + { + id dest; - /* Initialize lists and stacks */ - opstack = NSZoneMalloc(z, sizeof(GSIArray_t)); - GSIArrayInitWithZoneAndCapacity((GSIArray)opstack, z, 2); - gstack = NSZoneMalloc(z, sizeof(GSIArray_t)); - GSIArrayInitWithZoneAndCapacity((GSIArray)gstack, z, 2); - [super initWithContextInfo: info]; + /* Initialize lists and stacks */ + opstack = NSZoneMalloc(z, sizeof(GSIArray_t)); + GSIArrayInitWithZoneAndCapacity((GSIArray)opstack, z, 2); + gstack = NSZoneMalloc(z, sizeof(GSIArray_t)); + GSIArrayInitWithZoneAndCapacity((GSIArray)gstack, z, 2); + /* Create a default gstate */ + gstate = [[[isa GStateClass] allocWithZone: z] + initWithDrawContext: self]; + + // Special handling for window drawing + dest = [info objectForKey: NSGraphicsContextDestinationAttributeName]; + if ((dest != nil) && [dest isKindOfClass: [NSWindow class]]) + { + /* A context is only associated with one server. Do not retain + the server, however */ + server = GSCurrentServer(); + [server setWindowdevice: [(NSWindow*)dest windowNumber] + forContext: self]; + } + } return self; } diff --git a/Source/gsc/GSStreamContext.m b/Source/gsc/GSStreamContext.m index c1582bf..321a734 100644 --- a/Source/gsc/GSStreamContext.m +++ b/Source/gsc/GSStreamContext.m @@ -72,6 +72,16 @@ fpfloat(FILE *stream, float f) @implementation GSStreamContext ++ (Class) GStateClass +{ + return [GSStreamGState class]; +} + ++ (BOOL) handlesPS +{ + return YES; +} + - (void) dealloc { if (gstream) @@ -81,7 +91,10 @@ fpfloat(FILE *stream, float f) - initWithContextInfo: (NSDictionary *)info { - [super initWithContextInfo: info]; + self = [super initWithContextInfo: info]; + if (!self) + return nil; + if (info && [info objectForKey: @"NSOutputFile"]) { NSString *path = [info objectForKey: @"NSOutputFile"]; @@ -93,22 +106,19 @@ fpfloat(FILE *stream, float f) #endif if (!gstream) { - NSDebugLLog(@"GSContext", @"%@: Could not open printer file %@", - DPSinvalidfileaccess, path); - return nil; - } + NSDebugLLog(@"GSContext", @"%@: Could not open printer file %@", + DPSinvalidfileaccess, path); + return nil; + } } else { NSDebugLLog(@"GSContext", @"%@: No stream file specified", - DPSconfigurationerror); + DPSconfigurationerror); + DESTROY(self); return nil; } - /* Create a default gstate */ - gstate = [[GSStreamGState allocWithZone: [self zone]] - initWithDrawContext: self]; - return self; } diff --git a/Source/win32/WIN32Server.m b/Source/win32/WIN32Server.m index 7c60f17..23bf905 100644 --- a/Source/win32/WIN32Server.m +++ b/Source/win32/WIN32Server.m @@ -1111,15 +1111,13 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, return NO; } -- (void) windowdevice: (int) winNum +- (void) setWindowdevice: (int)win forContext: (NSGraphicsContext *)ctxt { - NSGraphicsContext *ctxt; RECT rect; float h, l, r, t, b; NSWindow *window; NSDebugLLog(@"WTrace", @"windowdevice: %d", winNum); - ctxt = GSCurrentContext(); window = GSWindowWithNumber(winNum); GetClientRect((HWND)winNum, &rect); h = rect.bottom - rect.top; diff --git a/Source/winlib/WIN32Context.m b/Source/winlib/WIN32Context.m index fd30306..ed6720f 100644 --- a/Source/winlib/WIN32Context.m +++ b/Source/winlib/WIN32Context.m @@ -45,14 +45,9 @@ [GSFontInfo setDefaultClass: [WIN32FontInfo class]]; } -- (id) initWithContextInfo: (NSDictionary *)info ++ (Class) GStateClass { - [super initWithContextInfo: info]; - - /* Create a default gstate */ - gstate = [[WIN32GState allocWithZone: [self zone]] initWithDrawContext: self]; - - return self; + return [WIN32GState class]; } - (void)flushGraphics diff --git a/Source/x11/XGServerWindow.m b/Source/x11/XGServerWindow.m index 851b888..e319c2d 100644 --- a/Source/x11/XGServerWindow.m +++ b/Source/x11/XGServerWindow.m @@ -2541,13 +2541,12 @@ NSLog(@"styleoffsets ... guessing offsets\n"); /** Make sure we have the most up-to-date window information and then - make sure the current context has our new information + make sure the context has our new information */ -- (void) windowdevice: (int)win +- (void) setWindowdevice: (int)win forContext: (NSGraphicsContext *)ctxt { unsigned width, height; gswindow_device_t *window; - NSGraphicsContext *ctxt; float t, b, l, r; NSDebugLLog(@"XGTrace", @"DPSwindowdevice: %d ", win); @@ -2572,7 +2571,7 @@ NSLog(@"styleoffsets ... guessing offsets\n"); XFreePixmap(dpy, window->buffer); window->buffer = 0; if (window->alpha_buffer) - XFreePixmap (dpy, window->alpha_buffer); + XFreePixmap (dpy, window->alpha_buffer); window->alpha_buffer = 0; } @@ -2584,7 +2583,6 @@ NSLog(@"styleoffsets ... guessing offsets\n"); [self _createBuffer: window]; } - ctxt = GSCurrentContext(); [self styleoffsets: &l : &r : &t : &b : window->win_attrs.window_style : window->ident]; GSSetDevice(ctxt, window, l, NSHeight(window->xframe) + b); diff --git a/Source/xlib/XGContext.m b/Source/xlib/XGContext.m index 1e8ee66..3ad3be4 100644 --- a/Source/xlib/XGContext.m +++ b/Source/xlib/XGContext.m @@ -131,24 +131,9 @@ [GSFontEnumerator setDefaultClass: fontEnumerator]; } -- (id) initWithContextInfo: (NSDictionary *)info ++ (Class) GStateClass { - NSString *contextType; - contextType = [info objectForKey: - NSGraphicsContextRepresentationFormatAttributeName]; - - self = [super initWithContextInfo: info]; - if (contextType) - { - /* Most likely this is a PS or PDF context, so just return what - super gave us */ - return self; - } - - /* Create a default gstate */ - gstate = [[XGGState allocWithZone: [self zone]] initWithDrawContext: self]; - - return self; + return [XGGState class]; } - (void) flushGraphics