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"
|
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
|
|
|
#define CGSTATE ((CairoGState *)gstate)
|
2004-08-02 21:50:17 +00:00
|
|
|
|
2008-03-04 10:14:29 +00:00
|
|
|
#if BUILD_SERVER == SERVER_x11
|
|
|
|
# include "x11/XGServer.h"
|
|
|
|
# ifdef USE_GLITZ
|
|
|
|
# define _CAIRO_SURFACE_CLASSNAME XGCairoGlitzSurface
|
|
|
|
# include "cairo/XGCairoGlitzSurface.h"
|
|
|
|
# else
|
|
|
|
//# define _CAIRO_SURFACE_CLASSNAME XGCairoSurface
|
|
|
|
//# include "cairo/XGCairoSurface.h"
|
|
|
|
# define _CAIRO_SURFACE_CLASSNAME XGCairoXImageSurface
|
|
|
|
# include "cairo/XGCairoXImageSurface.h"
|
|
|
|
# endif /* USE_GLITZ */
|
|
|
|
# include "x11/XGServerWindow.h"
|
|
|
|
# include "x11/XWindowBuffer.h"
|
|
|
|
#elif BUILD_SERVER == SERVER_win32
|
|
|
|
# include <windows.h>
|
|
|
|
# ifdef USE_GLITZ
|
|
|
|
# define _CAIRO_SURFACE_CLASSNAME Win32CairoGlitzSurface
|
|
|
|
# include "cairo/Win32CairoGlitzSurface.h"
|
|
|
|
# else
|
|
|
|
# define _CAIRO_SURFACE_CLASSNAME Win32CairoSurface
|
|
|
|
# include "cairo/Win32CairoSurface.h"
|
|
|
|
# endif /* USE_GLITZ */
|
|
|
|
#else
|
|
|
|
# error Invalid server for Cairo backend : non implemented
|
|
|
|
#endif /* BUILD_SERVER */
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-01-19 13:12:03 +00:00
|
|
|
+ (Class) GStateClass
|
2004-08-02 21:50:17 +00:00
|
|
|
{
|
2008-01-19 13:12:03 +00:00
|
|
|
return [CairoGState class];
|
|
|
|
}
|
2004-08-02 21:50:17 +00:00
|
|
|
|
2008-01-19 13:12:03 +00:00
|
|
|
+ (BOOL) handlesPS
|
|
|
|
{
|
|
|
|
return YES;
|
2004-08-02 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) flushGraphics
|
|
|
|
{
|
2008-03-04 10:14:29 +00:00
|
|
|
#if BUILD_SERVER == SERVER_x11
|
2005-08-28 00:48:12 +00:00
|
|
|
XFlush([(XGServer *)server xDisplay]);
|
2008-03-04 10:14:29 +00:00
|
|
|
#endif // BUILD_SERVER = SERVER_x11
|
2004-08-02 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
2008-03-04 10:14:29 +00:00
|
|
|
#if BUILD_SERVER == SERVER_x11
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2008-03-04 10:14:29 +00:00
|
|
|
#endif // XSHM
|
|
|
|
|
|
|
|
#endif // BUILD_SERVER = SERVER_x11
|
2006-12-26 13:26:40 +00:00
|
|
|
|
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
|
|
|
|
2008-03-04 10:14:29 +00:00
|
|
|
surface = [[_CAIRO_SURFACE_CLASSNAME alloc] initWithDevice: device];
|
2007-04-04 14:33:10 +00:00
|
|
|
|
2007-04-27 12:23:28 +00:00
|
|
|
[CGSTATE GSSetSurface: surface : x : y];
|
2008-05-23 04:12:37 +00:00
|
|
|
[surface release];
|
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
|
2008-03-04 10:14:29 +00:00
|
|
|
|
|
|
|
#undef _CAIRO_SURFACE_CLASSNAME
|