Rework of context window device setting. Requires corresponding change

in gui.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@25981 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2008-01-19 13:12:03 +00:00
parent f07e56c4b8
commit 61985e25a9
8 changed files with 89 additions and 95 deletions

View file

@ -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];
}

View file

@ -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

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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

View file

@ -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);

View file

@ -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