2004-08-02 21:50:17 +00:00
|
|
|
/*
|
2007-10-29 23:25:10 +00:00
|
|
|
CairoContext.m
|
|
|
|
|
|
|
|
Copyright (C) 2003 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
August 31, 2003
|
|
|
|
Written by Banlu Kemiyatorn <object at gmail dot com>
|
|
|
|
|
|
|
|
This file is part of GNUstep.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 3 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
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2004-08-02 21:50:17 +00:00
|
|
|
#include "cairo/CairoContext.h"
|
|
|
|
#include "cairo/CairoGState.h"
|
2006-03-12 21:50:17 +00:00
|
|
|
#include "cairo/CairoSurface.h"
|
2007-04-27 12:23:28 +00:00
|
|
|
#include "cairo/CairoPSSurface.h"
|
2007-09-12 15:46:55 +00:00
|
|
|
#include "cairo/CairoPDFSurface.h"
|
2005-07-27 23:25:32 +00:00
|
|
|
#include "cairo/CairoFontInfo.h"
|
|
|
|
#include "cairo/CairoFontEnumerator.h"
|
2005-08-28 00:48:12 +00:00
|
|
|
#include "x11/XGServer.h"
|
2006-03-12 21:50:17 +00:00
|
|
|
#include "config.h"
|
2004-08-02 21:50:17 +00:00
|
|
|
|
2006-03-12 21:50:17 +00:00
|
|
|
#ifdef USE_GLITZ
|
|
|
|
#include "cairo/XGCairoGlitzSurface.h"
|
|
|
|
#else
|
|
|
|
#include "cairo/XGCairoSurface.h"
|
2006-12-26 13:26:40 +00:00
|
|
|
#include "cairo/XGCairoXImageSurface.h"
|
2007-04-27 12:23:28 +00:00
|
|
|
#include "x11/XGServerWindow.h"
|
|
|
|
#include "x11/XWindowBuffer.h"
|
2006-03-12 21:50:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CGSTATE ((CairoGState *)gstate)
|
2004-08-02 21:50:17 +00:00
|
|
|
|
2006-12-27 11:25:54 +00:00
|
|
|
@class XWindowBuffer;
|
2004-08-02 21:50:17 +00:00
|
|
|
|
|
|
|
@implementation CairoContext
|
|
|
|
|
|
|
|
+ (void) initializeBackend
|
|
|
|
{
|
2006-03-12 21:50:17 +00:00
|
|
|
[NSGraphicsContext setDefaultContextClass: self];
|
2004-08-02 21:50:17 +00:00
|
|
|
|
2005-07-27 23:25:32 +00:00
|
|
|
[GSFontEnumerator setDefaultClass: [CairoFontEnumerator class]];
|
|
|
|
[GSFontInfo setDefaultClass: [CairoFontInfo class]];
|
2004-08-02 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithContextInfo: (NSDictionary *)info
|
|
|
|
{
|
2007-04-27 12:23:28 +00:00
|
|
|
// Don't allow super to handle PS case.
|
|
|
|
self = [super initWithContextInfo: nil];
|
|
|
|
if (!self)
|
|
|
|
return self;
|
|
|
|
|
2007-09-12 15:46:55 +00:00
|
|
|
// Now save the info
|
|
|
|
ASSIGN(context_info, info);
|
2007-04-27 12:23:28 +00:00
|
|
|
|
2007-09-12 15:46:55 +00:00
|
|
|
gstate = [[CairoGState allocWithZone: [self zone]] initWithDrawContext: self];
|
2004-08-02 21:50:17 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) flushGraphics
|
|
|
|
{
|
2005-08-28 00:48:12 +00:00
|
|
|
XFlush([(XGServer *)server xDisplay]);
|
2004-08-02 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
2006-12-26 13:26:40 +00:00
|
|
|
/* Private backend methods */
|
2007-10-18 16:51:56 +00:00
|
|
|
+ (void) handleExposeRect: (NSRect)rect forDriver: (void *)driver
|
2006-12-26 13:26:40 +00:00
|
|
|
{
|
|
|
|
[(XWindowBuffer *)driver _exposeRect: rect];
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XSHM
|
|
|
|
|
2007-10-18 16:51:56 +00:00
|
|
|
+ (void) _gotShmCompletion: (Drawable)d
|
2006-12-26 13:26:40 +00:00
|
|
|
{
|
|
|
|
[XWindowBuffer _gotShmCompletion: d];
|
|
|
|
}
|
|
|
|
|
2007-10-18 16:51:56 +00:00
|
|
|
- (void) gotShmCompletion: (Drawable)d
|
2006-12-26 13:26:40 +00:00
|
|
|
{
|
|
|
|
[XWindowBuffer _gotShmCompletion: d];
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2004-08-02 21:50:17 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation CairoContext (Ops)
|
|
|
|
|
|
|
|
- (void) GSCurrentDevice: (void **)device : (int *)x : (int *)y
|
|
|
|
{
|
2007-04-27 12:23:28 +00:00
|
|
|
CairoSurface *surface;
|
|
|
|
|
|
|
|
[CGSTATE GSCurrentSurface: &surface : x : y];
|
|
|
|
if (device)
|
|
|
|
{
|
|
|
|
*device = surface->gsDevice;
|
|
|
|
}
|
2004-08-02 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) GSSetDevice: (void *)device : (int)x : (int)y
|
|
|
|
{
|
2007-04-27 12:23:28 +00:00
|
|
|
CairoSurface *surface;
|
2004-08-02 21:50:17 +00:00
|
|
|
|
2007-04-27 12:23:28 +00:00
|
|
|
#ifdef USE_GLITZ
|
|
|
|
surface = [[XGCairoGlitzSurface alloc] initWithDevice: device];
|
|
|
|
#else
|
|
|
|
//surface = [[XGCairoSurface alloc] initWithDevice: device];
|
|
|
|
surface = [[XGCairoXImageSurface alloc] initWithDevice: device];
|
|
|
|
#endif
|
2007-04-04 14:33:10 +00:00
|
|
|
|
2007-04-27 12:23:28 +00:00
|
|
|
[CGSTATE GSSetSurface: surface : x : y];
|
2007-04-04 14:33:10 +00:00
|
|
|
}
|
|
|
|
|
2007-06-29 11:31:53 +00:00
|
|
|
- (void) beginPrologueBBox: (NSRect)boundingBox
|
|
|
|
creationDate: (NSString*)dateCreated
|
|
|
|
createdBy: (NSString*)anApplication
|
|
|
|
fonts: (NSString*)fontNames
|
|
|
|
forWhom: (NSString*)user
|
|
|
|
pages: (int)numPages
|
|
|
|
title: (NSString*)aTitle
|
|
|
|
{
|
2007-09-12 15:46:55 +00:00
|
|
|
CairoSurface *surface;
|
|
|
|
NSSize size;
|
|
|
|
NSString *contextType;
|
|
|
|
|
|
|
|
contextType = [context_info objectForKey:
|
|
|
|
NSGraphicsContextRepresentationFormatAttributeName];
|
|
|
|
|
|
|
|
if (contextType)
|
|
|
|
{
|
|
|
|
if ([contextType isEqual: NSGraphicsContextPSFormat])
|
|
|
|
{
|
|
|
|
size = boundingBox.size;
|
|
|
|
surface = [[CairoPSSurface alloc] initWithDevice: context_info];
|
|
|
|
[surface setSize: size];
|
|
|
|
// This strange setting is needed because of the way GUI handles offset.
|
|
|
|
[CGSTATE GSSetSurface: surface : 0.0 : size.height];
|
|
|
|
RELEASE(surface);
|
|
|
|
}
|
|
|
|
else if ([contextType isEqual: NSGraphicsContextPDFFormat])
|
|
|
|
{
|
|
|
|
size = boundingBox.size;
|
|
|
|
surface = [[CairoPDFSurface alloc] initWithDevice: context_info];
|
|
|
|
[surface setSize: size];
|
|
|
|
// This strange setting is needed because of the way GUI handles offset.
|
|
|
|
[CGSTATE GSSetSurface: surface : 0.0 : size.height];
|
|
|
|
RELEASE(surface);
|
|
|
|
}
|
|
|
|
}
|
2007-06-29 11:31:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) showPage
|
|
|
|
{
|
|
|
|
[CGSTATE showPage];
|
|
|
|
}
|
|
|
|
|
2004-08-02 21:50:17 +00:00
|
|
|
@end
|