2002-03-27 23:44:41 +00:00
|
|
|
/* -*- mode:ObjC -*-
|
|
|
|
XGContext - Drawing context using the Xlib Library.
|
|
|
|
|
|
|
|
Copyright (C) 1998,1999,2002 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
|
|
|
Date: Nov 1998
|
|
|
|
|
|
|
|
This file is part of the GNU Objective C User Interface 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; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <AppKit/AppKitExceptions.h>
|
|
|
|
#include <AppKit/NSAffineTransform.h>
|
|
|
|
#include <AppKit/NSColor.h>
|
|
|
|
#include <AppKit/NSView.h>
|
|
|
|
#include <AppKit/NSWindow.h>
|
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
#include <Foundation/NSData.h>
|
|
|
|
#include <Foundation/NSValue.h>
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
#include <Foundation/NSUserDefaults.h>
|
|
|
|
#include <Foundation/NSDebug.h>
|
|
|
|
|
|
|
|
#include "x11/XGServer.h"
|
|
|
|
#include "xlib/XGContext.h"
|
|
|
|
#include "xlib/XGPrivate.h"
|
|
|
|
#include "xlib/XGGState.h"
|
|
|
|
|
2002-05-04 19:39:47 +00:00
|
|
|
#ifdef HAVE_XFT
|
2003-01-24 04:50:18 +00:00
|
|
|
#include "xlib/GSXftFontInfo.h"
|
2002-03-27 23:44:41 +00:00
|
|
|
#endif
|
|
|
|
|
2003-07-24 03:24:13 +00:00
|
|
|
#include "xlib/XGFontSetFontInfo.h"
|
|
|
|
|
2002-03-27 23:44:41 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
<unit>
|
|
|
|
<heading>XGContext</heading>
|
|
|
|
<p>
|
|
|
|
The documentation below mostly describes methods that are specific to
|
|
|
|
this backend and wouldn't necessarily be used in other backends. The methods
|
|
|
|
that this class does implement that would need to be in every backend are
|
|
|
|
the methods of its NSGraphicContext superclass. See the documentation
|
|
|
|
for NSGraphicContext for more information.
|
|
|
|
</p>
|
|
|
|
</unit>
|
|
|
|
*/
|
|
|
|
@implementation XGContext
|
|
|
|
|
|
|
|
/* Initialize AppKit backend */
|
|
|
|
+ (void)initializeBackend
|
|
|
|
{
|
|
|
|
Class fontClass = Nil;
|
2003-02-27 01:24:58 +00:00
|
|
|
Class fontEnumerator = Nil;
|
2003-07-24 03:24:13 +00:00
|
|
|
BOOL enableFontSet;
|
2004-10-30 14:17:08 +00:00
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
2002-03-27 23:44:41 +00:00
|
|
|
|
|
|
|
NSDebugLog(@"Initializing GNUstep xlib backend.\n");
|
|
|
|
|
|
|
|
[NSGraphicsContext setDefaultContextClass: [XGContext class]];
|
|
|
|
|
2002-05-04 19:39:47 +00:00
|
|
|
#ifdef HAVE_XFT
|
2004-10-30 14:17:08 +00:00
|
|
|
if (([ud objectForKey: @"GSFontAntiAlias"] == nil) ||
|
|
|
|
([ud boolForKey: @"GSFontAntiAlias"]))
|
2002-03-27 23:44:41 +00:00
|
|
|
{
|
2003-01-24 04:50:18 +00:00
|
|
|
fontClass = [GSXftFontInfo class];
|
2003-02-27 01:24:58 +00:00
|
|
|
#ifdef HAVE_FC
|
|
|
|
fontEnumerator = [FcFontEnumerator class];
|
|
|
|
#endif
|
2002-03-27 23:44:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
2004-10-30 14:17:08 +00:00
|
|
|
enableFontSet = [ud boolForKey: @"GSXEnableFontSet"];
|
2002-03-27 23:44:41 +00:00
|
|
|
if (fontClass == Nil)
|
|
|
|
{
|
2003-07-24 03:24:13 +00:00
|
|
|
if (enableFontSet == NO)
|
|
|
|
{
|
|
|
|
fontClass = [XGFontInfo class];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef X_HAVE_UTF8_STRING
|
|
|
|
fontClass = [XGFontSetFontInfo class];
|
|
|
|
#else
|
2003-10-08 14:02:05 +00:00
|
|
|
NSLog(@"Can't use GSXEnableFontSet: You need XFree86 >= 4.0.2");
|
2003-07-24 03:24:13 +00:00
|
|
|
fontClass = [XGFontInfo class];
|
|
|
|
#endif
|
|
|
|
}
|
2002-03-27 23:44:41 +00:00
|
|
|
}
|
|
|
|
[GSFontInfo setDefaultClass: fontClass];
|
2003-07-24 03:24:13 +00:00
|
|
|
|
2003-02-27 01:24:58 +00:00
|
|
|
if (fontEnumerator == Nil)
|
|
|
|
{
|
2003-07-24 03:24:13 +00:00
|
|
|
if (enableFontSet == NO)
|
|
|
|
{
|
|
|
|
fontEnumerator = [XGFontEnumerator class];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef X_HAVE_UTF8_STRING
|
|
|
|
// Commented out till the implementation of XGFontSetEnumerator
|
|
|
|
// completes.
|
|
|
|
//fontEnumerator = [XGFontSetEnumerator class];
|
|
|
|
fontEnumerator = [XGFontEnumerator class];
|
|
|
|
#else
|
|
|
|
fontEnumerator = [XGFontEnumerator class];
|
|
|
|
#endif
|
|
|
|
}
|
2003-02-27 01:24:58 +00:00
|
|
|
}
|
|
|
|
[GSFontEnumerator setDefaultClass: fontEnumerator];
|
2002-03-27 23:44:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithContextInfo: (NSDictionary *)info
|
|
|
|
{
|
2002-04-07 02:26:40 +00:00
|
|
|
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;
|
|
|
|
}
|
2002-03-27 23:44:41 +00:00
|
|
|
|
|
|
|
/* Create a default gstate */
|
|
|
|
gstate = [[XGGState allocWithZone: [self zone]] initWithDrawContext: self];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) flushGraphics
|
|
|
|
{
|
|
|
|
XFlush([(XGServer *)server xDisplay]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation XGContext (Ops)
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* Window system ops */
|
|
|
|
/* ----------------------------------------------------------------------- */
|
2002-04-15 02:59:15 +00:00
|
|
|
- (void) GSCurrentDevice: (void **)device : (int *)x : (int *)y
|
2002-03-27 23:44:41 +00:00
|
|
|
{
|
2002-04-15 02:59:15 +00:00
|
|
|
void *windevice = [(XGGState *)gstate windevice];
|
|
|
|
if (device)
|
|
|
|
*device = windevice;
|
2002-03-27 23:44:41 +00:00
|
|
|
if (x && y)
|
|
|
|
{
|
|
|
|
NSPoint offset = [gstate offset];
|
|
|
|
*x = offset.x;
|
|
|
|
*y = offset.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-15 02:59:15 +00:00
|
|
|
- (void) GSSetDevice: (void *)device : (int)x : (int)y
|
2002-03-27 23:44:41 +00:00
|
|
|
{
|
2002-04-15 02:59:15 +00:00
|
|
|
[(XGGState *)gstate setWindowDevice: device];
|
2002-03-27 23:44:41 +00:00
|
|
|
[gstate setOffset: NSMakePoint(x, y)];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|