Added cairo backend.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@19820 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2004-08-02 21:50:17 +00:00
parent e131192a2f
commit 1e896954aa
32 changed files with 4615 additions and 4 deletions

View file

@ -1,3 +1,12 @@
2004-08-03 Fred Kiefer <FredKiefer@gmx.de>
* Header/cairo/*:
* Source/cairo/*:
* Source/GSBackend.m:
* configure.ac:
* configure:
Added cairo backend from Banlu Kemiyatorn <object@gmail.com>.
2004-07-30 15:52 Alexander Malmberg <alexander@malmberg.org>
* Headers/gsc/GSCStateOps.h, Source/gsc/GSContext.m,

View file

@ -0,0 +1,42 @@
/*
* CairoContext.h
*
* Copyright (C) 2003 Free Software Foundation, Inc.
* August 31, 2003
* Written by Banlu Kemiyatorn <id at project-ile dot net>
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef WOOM_CairoContext_h
#define WOOM_CairoContext_h
#include "gsc/GSContext.h"
#include "cairo/CairoSurface.h"
/*
#include "Maliwan/Maliwan.h"
*/
@interface CairoContext : GSContext
{
/*
CSMKColorProfile *_systemRGBprofile;
CSMKColorProfile *_systemCMYKprofile;
CSMKColorProfile *_systemHSBprofile;
*/
}
@end
#endif

View file

@ -0,0 +1,87 @@
/*
* CairoFontInfo.h
*
* Copyright (C) 2003 Free Software Foundation, Inc.
* September 10, 2003
* Written by Banlu Kemiyatorn <id at project-ile dot net>
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef WOOM_CairoDevice_h
#define WOOM_CairoDevice_h
#include "x11/XGServerWindow.h"
#include <cairo.h>
@interface CairoBuffer : NSObject
{
@public
gswindow_device_t * _gsdevice;
void *_deviceid;
NSSize _pixmapSize;
Pixmap _pixmap;
}
+ (CairoBuffer *) pixmapWithWindowDevice: (gswindow_device_t *)device;
- (id) initWithWindowDevice: (gswindow_device_t *)device;
- (Pixmap) pixmap;
- (gswindow_device_t *) device;
- (NSSize) size;
- (void) dealloc;
/*- (id) copyWithZone: (NSZone *)zone;*/
@end
@interface CairoType : NSObject
{
@public
cairo_t *_cr;
}
@end
@interface CairoType (Ops)
- (void) save;
- (void) restore;
- (void) translateToPoint: (NSPoint)p;
- (void) scaleToSize:(NSSize)s;
- (void) rotateWithAngle:(float)angle;
- (void) setTargetBuffer:(CairoBuffer *)buffer;
- (void) setColorRGB:(float)r :(float)g :(float)b;
- (void) setColorGray:(float)gray;
- (void) clip;
- (void) newPath;
- (void) closePath;
- (void) rectangle:(NSRect)rect;
- (void) stroke;
- (void) moveToPoint:(NSPoint)p;
- (void) lineToPoint:(NSPoint)p;
- (void) relativeLineToPoint:(NSPoint)p;
- (void) relativeLineToSize:(NSSize)s;
- (void) fill;
- (NSAffineTransform *) CTM;
- (void) setCTM: (NSAffineTransform *)newctm;
- (void) concatCTM: (NSAffineTransform *)concatctm;
@end /* CairoType */
@interface CairoDevice : NSObject
{
@public
CairoType *_ct;
CairoBuffer *_buffer;
}
- (CairoType *) ct;
- (void) setDevice: (gswindow_device_t *)window;
@end
#endif

View file

@ -0,0 +1,74 @@
/*
* CairoFaceInfo.h
* Copyright (C) 2003 Free Software Foundation, Inc.
* August 31, 2003
* Written by Banlu Kemiyatorn <object at gmail dot com>
* Base on code by Alexander Malmberg <alexander@malmberg.org>
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef CAIROFACEINFO_H
#define CAIROFACEINFO_H
#include <Foundation/Foundation.h>
#include <cairo.h>
@interface CairoFaceInfo : NSObject
{
int _weight;
unsigned int _traits;
cairo_font_slant_t _c_slant;
cairo_font_weight_t _c_weight;
NSString *_faceName;
NSString *_familyName;
NSString *_displayName;
NSString *_cairoName;
}
- (id) initWithName: (NSString *)name
familyName: (NSString *)familyName
displayName: (NSString *)displayName
cairoName: (NSString *)cairoName
weight: (int)weight
traits: (unsigned int)traits
cairoSlant: (cairo_font_slant_t)cairoSlant
cairoWeight: (cairo_font_weight_t)cairoWeight;
- (unsigned int) cacheSize;
- (cairo_font_weight_t) cairoWeight;
- (void) setCairoWeight: (cairo_font_weight_t) weight;
- (cairo_font_slant_t) cairoSlant;
- (void) setCairoSlant: (cairo_font_slant_t) slant;
- (int) weight;
- (void) setWeight: (int)weight;
- (unsigned int) traits;
- (void) setTraits: (unsigned int)traits;
- (NSString *) displayName;
- (void) setDisplayName: (NSString *)name;
- (NSString *) familyName;
- (void) setFamilyName: (NSString *)name;
- (NSString *) name;
- (void) setName: (NSString *)name;
- (const char *) cairoCName;
- (void) setCairoName: (NSString *)name;
@end
#endif

View file

@ -0,0 +1,32 @@
/*
* CairoFontEnumerator.h
* Copyright (C) 2003 Free Software Foundation, Inc.
* August 31, 2003
* Written by Banlu Kemiyatorn <object at gmail dot com>
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef WOOM_CairoFontEnumerator_h
#define WOOM_CairoFontEnumerator_h
#include <GNUstepGUI/GSFontInfo.h>
#include <cairo.h>
@interface CairoFontEnumerator : GSFontEnumerator
@end
#endif

View file

@ -0,0 +1,56 @@
/*
* CairoFontInfo.h
* Copyright (C) 2003 Free Software Foundation, Inc.
* August 31, 2003
* Written by Banlu Kemiyatorn <object at gmail dot com>
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef WOOM_CairoFontInfo_h
#define WOOM_CairoFontInfo_h
#include <GNUstepGUI/GSFontInfo.h>
#include <Foundation/NSMapTable.h>
#include "cairo/CairoFontEnumerator.h"
#include "cairo/CairoFontManager.h"
#include <cairo.h>
@interface CairoFontInfo : GSFontInfo
{
@public
cairo_t *_cf;
cairo_font_t *xrFont;
CairoFaceInfo *_faceInfo;
BOOL _screenFont;
/* will be used in GSNFont subclass
NSMapTable *_ligatureMap;
NSMapTable *_kerningMap;
*/
unsigned int _cacheSize;
unsigned int *_cachedGlyphs;
NSSize *_cachedSizes;
}
- (void) setCacheSize:(unsigned int)size;
@end
#endif

View file

@ -0,0 +1,35 @@
/*
* CairoFontManager.h
* Copyright (C) 2003 Free Software Foundation, Inc.
* August 31, 2003
* Written by Banlu Kemiyatorn <object at gmail dot com>
* Base on code by Alexander Malmberg <alexander@malmberg.org>
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef CAIROFONTMANAGER_H
#define CAIROFONTMANAGER_H
#include "CairoFaceInfo.h"
#include <AppKit/NSFontManager.h>
@interface CairoFontManager : NSObject
{
}
+ (NSArray *) allFontNames;
+ (CairoFaceInfo *) fontWithName: (NSString *)name;
@end
#endif

View file

@ -0,0 +1,45 @@
/*
* CairoFreeTypeFontInfo.h
*
* Copyright (C) 2003 Free Software Foundation, Inc.
* April 27, 2004
* Written by Banlu Kemiyatorn <lastlifeintheuniverse at hotmail dot com>
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef WOOM_CairoFreeTypeFontInfo_h
#define WOOM_CairoFreeTypeFontInfo_h
#include <Foundation/NSMapTable.h>
#include "nfont/GSNFont.h"
#include "cairo/CairoFontInfo.h"
#include <cairo.h>
#define CACHE_SIZE 257
@interface CairoFreeTypeFontInfo : CairoFontInfo
{
@public
/* We will implement FTC in cairo instead
FTC_ImageTypeRec _imgd;
FTC_ImageTypeRec _advancementImgd;
*/
}
@end
#endif

174
Headers/cairo/CairoGState.h Normal file
View file

@ -0,0 +1,174 @@
/*
Copyright (C) 2004 Free Software Foundation, Inc.
Author: 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 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.
*/
#ifndef CairoGState_h
#define CairoGState_h
#include <AppKit/NSAffineTransform.h>
#include <AppKit/NSGraphicsContext.h>
#include <cairo.h>
@class CairoContext;
@class CairoFontInfo;
@class CairoSurface;
@interface CairoGState : NSObject /* No need of overhead */
{
@public
cairo_t *_ct;
CairoSurface *_surface;
CairoFontInfo *_font;
BOOL _viewIsFlipped;
NSPoint _offset;
}
- (id) initWithDrawContext: (CairoContext *)drawContext;
- (void) GSCurrentDevice: (void **)device: (int *)x : (int *)y;
- (void) GSSetDevice: (void *)device : (int)x : (int)y;
@end
@interface CairoGState (Ops)
/* ----------------------------------------------------------------------- */
/* Color operations */
/* ----------------------------------------------------------------------- */
- (void) DPScurrentalpha: (float*)a;
- (void) DPScurrentcmykcolor: (float*)c : (float*)m : (float*)y : (float*)k;
- (void) DPScurrentgray: (float*)gray;
- (void) DPScurrenthsbcolor: (float*)h : (float*)s : (float*)b;
- (void) DPScurrentrgbcolor: (float*)r : (float*)g : (float*)b;
- (void) DPSsetalpha: (float)a;
- (void) DPSsetcmykcolor: (float)c : (float)m : (float)y : (float)k;
- (void) DPSsetgray: (float)gray;
- (void) DPSsethsbcolor: (float)h : (float)s : (float)b;
- (void) DPSsetrgbcolor: (float)r : (float)g : (float)b;
- (void) GSSetFillColorspace: (void *)spaceref;
- (void) GSSetStrokeColorspace: (void *)spaceref;
- (void) GSSetFillColor: (const float *)values;
- (void) GSSetStrokeColor: (const float *)values;
/* ----------------------------------------------------------------------- */
/* Text operations */
/* ----------------------------------------------------------------------- */
- (void) DPSashow: (float)x : (float)y : (const char*)s;
- (void) DPSawidthshow: (float)cx : (float)cy : (int)c : (float)ax : (float)ay
: (const char*)s;
- (void) DPScharpath: (const char*)s : (int)b;
- (void) DPSshow: (const char*)s;
- (void) DPSwidthshow: (float)x : (float)y : (int)c : (const char*)s;
- (void) DPSxshow: (const char*)s : (const float*)numarray : (int)size;
- (void) DPSxyshow: (const char*)s : (const float*)numarray : (int)size;
- (void) DPSyshow: (const char*)s : (const float*)numarray : (int)size;
- (void) GSSetCharacterSpacing: (float)extra;
- (void) GSSetFont: (GSFontInfo *)fontref;
- (void) GSSetFontSize: (float)size;
- (NSAffineTransform *) GSGetTextCTM;
- (NSPoint) GSGetTextPosition;
- (void) GSSetTextCTM: (NSAffineTransform *)ctm;
- (void) GSSetTextDrawingMode: (GSTextDrawingMode)mode;
- (void) GSSetTextPosition: (NSPoint)loc;
- (void) GSShowText: (const char *)string : (size_t) length;
- (void) GSShowGlyphs: (const NSGlyph *)glyphs : (size_t) length;
/* ----------------------------------------------------------------------- */
/* Gstate operations */
/* ----------------------------------------------------------------------- */
- (void) DPSinitgraphics;
- (void) DPScurrentflat: (float*)flatness;
- (void) DPScurrentlinecap: (int*)linecap;
- (void) DPScurrentlinejoin: (int*)linejoin;
- (void) DPScurrentlinewidth: (float*)width;
- (void) DPScurrentmiterlimit: (float*)limit;
- (void) DPScurrentpoint: (float*)x : (float*)y;
- (void) DPScurrentstrokeadjust: (int*)b;
- (void) DPSsetdash: (const float*)pat : (int)size : (float)offset;
- (void) DPSsetflat: (float)flatness;
- (void) DPSsetlinecap: (int)linecap;
- (void) DPSsetlinejoin: (int)linejoin;
- (void) DPSsetlinewidth: (float)width;
- (void) DPSsetmiterlimit: (float)limit;
- (void) DPSsetstrokeadjust: (int)b;
/* ----------------------------------------------------------------------- */
/* Matrix operations */
/* ----------------------------------------------------------------------- */
- (void) DPSconcat: (const float*)m;
- (void) DPSinitmatrix;
- (void) DPSrotate: (float)angle;
- (void) DPSscale: (float)x : (float)y;
- (void) DPStranslate: (float)x : (float)y;
- (NSAffineTransform *) GSCurrentCTM;
- (void) GSSetCTM: (NSAffineTransform *)ctm;
- (void) GSConcatCTM: (NSAffineTransform *)ctm;
/* ----------------------------------------------------------------------- */
/* Paint operations */
/* ----------------------------------------------------------------------- */
- (NSPoint) currentPoint;
- (void) DPSarc: (float)x : (float)y : (float)r : (float)angle1
: (float)angle2;
- (void) DPSarcn: (float)x : (float)y : (float)r : (float)angle1
: (float)angle2;
- (void) DPSarct: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)r;
- (void) DPSclip;
- (void) DPSclosepath;
- (void) DPScurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2
: (float)x3 : (float)y3;
- (void) DPSeoclip;
- (void) DPSeofill;
- (void) DPSfill;
- (void) DPSflattenpath;
- (void) DPSinitclip;
- (void) DPSlineto: (float)x : (float)y;
- (void) DPSmoveto: (float)x : (float)y;
- (void) DPSnewpath;
- (void) DPSpathbbox: (float*)llx : (float*)lly : (float*)urx : (float*)ury;
- (void) DPSrcurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2
: (float)x3 : (float)y3;
- (void) DPSrectclip: (float)x : (float)y : (float)w : (float)h;
- (void) DPSrectfill: (float)x : (float)y : (float)w : (float)h;
- (void) DPSrectstroke: (float)x : (float)y : (float)w : (float)h;
- (void) DPSreversepath;
- (void) DPSrlineto: (float)x : (float)y;
- (void) DPSrmoveto: (float)x : (float)y;
- (void) DPSstroke;
- (void) GSSendBezierPath: (NSBezierPath *)path;
- (void) GSRectClipList: (const NSRect *)rects : (int) count;
- (void) GSRectFillList: (const NSRect *)rects : (int) count;
- (void)DPSimage: (NSAffineTransform*) matrix
: (int) pixelsWide : (int) pixelsHigh
: (int) bitsPerSample : (int) samplesPerPixel
: (int) bitsPerPixel : (int) bytesPerRow : (BOOL) isPlanar
: (BOOL) hasAlpha : (NSString *) colorSpaceName
: (const unsigned char *const [5]) data;
@end
#endif

View file

@ -0,0 +1,53 @@
/*
Copyright (C) 2002 Free Software Foundation, Inc.
Author: 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 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.
*/
#ifndef CairoSurface_h
#define CairoSurface_h
#include <cairo.h>
#include <Foundation/Foundation.h>
typedef struct _CairoInfo
{
} CairoInfo;
@interface CairoSurface : NSObject
{
@public
void *gsDevice;
}
+ (CairoSurface *) surfaceForDevice: (void *) device
depthInfo: (CairoInfo *) cairoInfo;
+ (CairoSurface *) createSurfaceForDevice:(void *)device
depthInfo:(CairoInfo *)cairoInfo;
- (id) initWithDevice:(void *)device;
- (void) setAsTargetOfCairo:(cairo_t *)ct;
- (NSSize) size;
@end
#endif

View file

@ -0,0 +1,39 @@
/*
Copyright (C) 2004 Free Software Foundation, Inc.
Author: 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 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.
*/
#ifndef XGCairoGlitzSurface_h
#define XGCairoGlitzSurface_h
#include "x11/XGServer.h"
#include "x11/XGServerWindow.h"
#include "cairo/CairoSurface.h"
#include <glitz.h>
@interface XGCairoGlitzSurface : CairoSurface
{
}
@end
#endif

View file

@ -0,0 +1,39 @@
/*
Copyright (C) 2002 Free Software Foundation, Inc.
Author: 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 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.
*/
#ifndef XGCairoSurface_h
#define XGCairoSurface_h
#include "x11/XGServer.h"
#include "x11/XGServerWindow.h"
#include "cairo/CairoSurface.h"
@interface XGCairoSurface : CairoSurface
{
cairo_surface_t *xrSurface;
}
@end
#endif

View file

@ -0,0 +1,39 @@
/*
Copyright (C) 2002 Free Software Foundation, Inc.
Author: 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 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.
*/
#ifndef XGCairoXImageSurface_h
#define XGCairoXImageSurface_h
#include "x11/XGServer.h"
#include "x11/XGServerWindow.h"
#include "cairo/CairoSurface.h"
@interface XGCairoXImageSurface : CairoSurface
{
XImage *image;
}
@end
#endif

View file

@ -75,7 +75,9 @@
contextClass = objc_get_class("ARTContext");
else if ([context isEqual: @"winlib"])
contextClass = objc_get_class("WIN32Context");
else
else if ([context isEqual: @"cairo"])
contextClass = objc_get_class("CairoContext");
else
contextClass = objc_get_class("XGContext");
[contextClass initializeBackend];

153
Source/cairo/CairoContext.m Normal file
View file

@ -0,0 +1,153 @@
/*
* CairoContext.m
* Copyright (C) 2003 Free Software Foundation, Inc.
* August 31, 2003
* Written by Banlu Kemiyatorn <object at gmail dot com>
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include "cairo/CairoContext.h"
#include "cairo/CairoGState.h"
#include "NSBezierPathCairo.h"
#define XRGSTATE ((CairoGState *)gstate)
@class CairoFontEnumerator;
@class CairoFontInfo;
@implementation CairoContext
+ (void) initializeBackend
{
//NSLog (@"CairoContext : Initializing cairo backend");
[NSGraphicsContext setDefaultContextClass:self];
[CairoSurface initializeBackend];
[CairoFontEnumerator initializeBackend];
[CairoFontInfo initializeBackend];
[NSBezierPath initializeCairoBezierPath];
}
/* FIXME: TRAP */
- (void) forwardInvocation: (NSInvocation *)anInvocation
{
/* only for trapping any unknown message. */
NSLog (@":::UNKNOWN::: %@ %@", self, anInvocation);
}
- (void) GSWSetViewIsFlipped: (BOOL)flipped
{
if (gstate)
{
((CairoGState *) gstate)->_viewIsFlipped = flipped;
}
}
- (id) initWithContextInfo: (NSDictionary *)info
{
NSString *contextType;
/*
CSMKColorType hsb_double;
CSMKColorAttributes attr;
*/
[super initWithContextInfo:info];
contextType = [info objectForKey:
NSGraphicsContextRepresentationFormatAttributeName];
if (contextType)
{
if (!([contextType isEqualToString: NSGraphicsContextPDFFormat] ||
[contextType isEqualToString: NSGraphicsContextPSFormat]))
{
NSLog(@"CairoContext : Hmmmm");
}
NSLog(@"CairoContext : NSGCRFAName %@", contextType);
return self;
}
/*
attr.signature = CSMKHSVColorSignature;
attr.isPremultiplied = NO;
attr.isPlanar = NO;
attr.hasAlphaChannel = NO;
attr.isEndian16 = NO;
attr.flavor = CSMKBlackIsZeroFlavor;
attr.numberOfColorComponents = 3;
attr.bytesPerChannel = 4;
hsb_double = CSMKMakeColorType(&attr);
ASSIGN(_systemRGBprofile,
[CSMKColorProfile defaultColorProfileForColorType:CSMKRGBDoubleColor]);
ASSIGN(_systemCMYKprofile,
[CSMKColorProfile defaultColorProfileForColorType:CSMKCMYKDoubleColor]);
ASSIGN(_systemHSBprofile,
[CSMKColorProfile defaultColorProfileForColorType:hsb_double]);
*/
gstate = [[CairoGState allocWithZone: [self zone]] initWithDrawContext: self];
return self;
}
- (void) DPSsetoffset: (short int)x : (short int)y
{
XRGSTATE->_offset = NSMakePoint(x, y);
}
- (void) flushGraphics
{
/* FIXME */
}
- (NSColor *) NSReadPixel: (NSPoint)location
{
/* FIXME */
return nil;
}
- (void) beep
{
/* FIXME: Flash screen? */
}
+ (void) handleExposeRect: (NSRect)rect forDriver: (void *)driver
{
NSLog (@"expose");
/* FIXME: */
}
@end
@implementation CairoContext (Ops)
- (void) GSCurrentDevice: (void **)device : (int *)x : (int *)y
{
[XRGSTATE GSCurrentDevice: device : x : y];
}
- (void) GSSetDevice: (void *)device : (int)x : (int)y
{
[XRGSTATE GSSetDevice: device : x : y];
}
- (void) DPScurrentalpha: (float *)a
{
*a = cairo_current_alpha(XRGSTATE->_ct);
}
@end

401
Source/cairo/CairoDevice.m Normal file
View file

@ -0,0 +1,401 @@
/*
* CairoDevice.m
*
* Copyright (C) 2003 Free Software Foundation, Inc.
* September 10, 2003
* Written by Banlu Kemiyatorn <id at project-ile dot net>
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include "Foundation/NSValue.h"
#include "Foundation/NSArray.h"
#include "Foundation/NSDictionary.h"
#include <AppKit/NSAffineTransform.h>
#include "cairo/CairoDevice.h"
#include <cairo.h>
#include <X11/Xlib.h>
NSAffineTransform * WMCairoMatrixToNSAffine (cairo_matrix_t *cairo_mp)
{
double af[6];
NSAffineTransformStruct ats;
NSAffineTransform *aCTM = [NSAffineTransform transform];
cairo_matrix_get_affine(cairo_mp,&af[0],&af[1],&af[2],&af[3],&af[4],&af[5]);
ats.m11 = af[0];
ats.m12 = af[1];
ats.m21 = af[2];
ats.m22 = af[3];
ats.tx = af[4];
ats.ty = af[5];
[aCTM setTransformStruct:ats];
return aCTM;
}
@implementation CairoType
- (id) init
{
// FIXME: first we need to create the dummy instance
// by returning a trapper ok, CairoTypeDummy
// and recording invocations into stack
// and when we know device's size, we'll apply
// all invocations to the real one.
_cr = cairo_create();
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
cairo_scale(_cr,1,-1);
return self;
}
- (void) dealloc
{
cairo_destroy(_cr);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
[super dealloc];
NSLog (@"done CT dealloc");
}
- (id) retain
{
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
return [super retain];
}
- (void) release
{
NSLog (@":::FIXME::: %@ %s cairo %d",[self description], sel_get_name(_cmd),_cr);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
[super release];
}
- (id) copyWithZone: (NSZone *)zone
{
CairoType *aCT = (CairoType *)NSCopyObject(self, 0, zone);
NSLog (@":::FIXME::: %@ %s copy %0x to %0x",[self description], sel_get_name(_cmd), self, aCT );
aCT->_cr = cairo_create();
cairo_copy(aCT->_cr,_cr);
NSLog(@"cairo_copy %d to %d [%s]",_cr,aCT->_cr,cairo_status_string(_cr));
return aCT;
}
@end
@implementation CairoType (Ops)
- (void) save
{
// cairo_save(_cr);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) restore
{
// cairo_restore(_cr);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) translateToPoint: (NSPoint)p
{
cairo_translate(_cr,p.x,p.y);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) scaleToSize:(NSSize)s
{
cairo_scale(_cr,s.width,s.height);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) rotateWithAngle:(float)angle
{
// cairo_rotate(_cr,angle);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) setTargetBuffer:(CairoBuffer *)buffer
{
// cairo_set_target_drawable(_cr, buffer->_gsdevice->display, buffer->_pixmap);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) setColorRGB:(float)r :(float)g :(float)b
{
// cairo_set_rgb_color(_cr,r,g,b);
}
- (void) setAlpha:(float)alpha
{
cairo_set_alpha(_cr, alpha);
}
- (float) currentAlpha
{
return cairo_current_alpha(_cr);
}
- (float) currentGray
{
return _currentGray;
}
- (void) clip
{
// cairo_clip(_cr);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) newPath
{
// cairo_new_path(_cr);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) closePath
{
// cairo_close_path(_cr);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) rectangle:(NSRect)rect
{
// cairo_rectangle(_cr,NSMinX(rect),NSMinY(rect),NSWidth(rect),NSHeight(rect));
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) stroke
{
// cairo_stroke(_cr);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) moveToPoint:(NSPoint)p
{
// cairo_move_to(_cr,p.x,p.y);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) lineToPoint:(NSPoint)p
{
// cairo_line_to(_cr,p.x,p.y);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) relativeLineToPoint:(NSPoint)p
{
// cairo_rel_line_to(_cr,p.x,p.y);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) relativeLineToSize:(NSSize)s
{
// cairo_rel_line_to(_cr,s.width,s.height);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
- (void) fill
{
// cairo_fill(_cr);
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
}
/* What is the Matrix? */
- (NSAffineTransform *) CTM
{
cairo_matrix_t *cairo_ctm;
cairo_ctm = cairo_matrix_create();
cairo_current_matrix(_cr, cairo_ctm);
id retMe = WMCairoMatrixToNSAffine(cairo_ctm);
cairo_matrix_destroy(cairo_ctm);
return retMe;
}
- (void) setCTM: (NSAffineTransform *)newctm
{
NSAffineTransformStruct ats = [newctm transformStruct];
cairo_matrix_t *cairo_mp = cairo_matrix_create();
cairo_matrix_set_affine(cairo_mp,ats.m11,ats.m12,ats.m21,ats.m22,ats.tx,ats.ty);
cairo_set_matrix(_cr, cairo_mp);
cairo_matrix_destroy(cairo_mp);
}
- (void) concatCTM: (NSAffineTransform *)concatctm
{
NSAffineTransformStruct ats = [concatctm transformStruct];
cairo_matrix_t *cairo_mp = cairo_matrix_create();
cairo_matrix_set_affine(cairo_mp,ats.m11,ats.m12,ats.m21,ats.m22,ats.tx,ats.ty);
cairo_concat_matrix(_cr, cairo_mp);
cairo_matrix_destroy(cairo_mp);
}
@end /* CairoType */
@implementation CairoBuffer
NSMapTable * buffermap;
+ (void) initialize
{
buffermap = NSCreateMapTable(NSIntMapKeyCallBacks,NSNonRetainedObjectMapValueCallBacks,10);
}
+ (CairoBuffer *) pixmapWithWindowDevice: (gswindow_device_t *)device
{
id buff = [[self alloc] initWithWindowDevice: device];
AUTORELEASE(buff);
return buff;
}
+ (CairoBuffer *) bufferForDevice: (gswindow_device_t *)device
{
CairoBuffer *_b = (CairoBuffer *) NSMapGet(buffermap, (void*)(device->ident));
if (_b == nil)
{
_b = [[self alloc] initWithWindowDevice: device];
}
return _b;
}
- (void) handleExposeRect:(NSRect)er
{
XCopyArea(_gsdevice->display, _pixmap, _gsdevice->ident,_gsdevice->gc, NSMinX(er), NSMinY(er), NSWidth(er), NSHeight(er), NSMinX(er), NSMinY(er));
/*
XClearWindow(_gsdevice->display, _gsdevice->ident);
XClearArea(_gsdevice->display, _gsdevice->ident, NSMinX(er), NSMinY(er), NSWidth(er), NSHeight(er), NO);
*/
}
- (id) init
{
RELEASE(self);
return nil;
}
- (id) initWithWindowDevice: (gswindow_device_t *)device
{
NSLog (@":::FIXME::: %@ %s",[self description], sel_get_name(_cmd) );
_gsdevice = device;
id oldbuffer = NSMapGet(buffermap, (const void*)(device->ident));
if (oldbuffer != nil)
{
ASSIGN(self, oldbuffer);
if (!NSEqualSizes(_pixmapSize, device->xframe.size))
{
_pixmapSize = device->xframe.size;
_pixmap = XCreatePixmap(device->display,
device->ident,
NSWidth(device->xframe),
NSHeight(device->xframe),
device->depth);
}
}
else
{
_deviceid = (void *)(device->ident);
_pixmapSize = device->xframe.size;
_pixmap = XCreatePixmap(device->display,
device->ident,
NSWidth(device->xframe),
NSHeight(device->xframe),
device->depth);
NSMapInsert(buffermap, _deviceid, (const void*)self);
}
/*
XSetWindowAttributes attr;
attr.event_mask = KeyPressMask |
KeyReleaseMask | ButtonPressMask |
ButtonReleaseMask | ButtonMotionMask |
StructureNotifyMask | PointerMotionMask |
EnterWindowMask | LeaveWindowMask |
FocusChangeMask | PropertyChangeMask |
ColormapChangeMask | KeymapStateMask |
VisibilityChangeMask;
XChangeWindowAttributes(device->display, device->ident, CWEventMask, &attr);
*/
#ifdef CAIRO_USE_BACKGROUND_PIXMAP
XSetWindowBackgroundPixmap(device->display, device->ident,_pixmap);
XClearWindow(device->display, device->ident);
#endif
return self;
}
/*
- (id) copyWithZone: (NSZone *)zone
{
CairoDevice *aCP = (CairoBuffer *)NSCopyObject(self, 0, zone);
}
*/
- (Pixmap) pixmap
{
return _pixmap;
}
- (NSSize) size
{
return _pixmapSize;
}
- (gswindow_device_t *) device
{
return _gsdevice;
}
- (void) dealloc
{
NSLog (@":::FIXME::: %@ %s",[self description], sel_get_name(_cmd) );
if (_deviceid)
NSMapRemove(buffermap, _deviceid);
if (_pixmap)
XFreePixmap([XGServer currentXDisplay], _pixmap);
[super dealloc];
NSLog(@"done CBF dealloc");
}
@end /* CairoBuffer */
@implementation CairoDevice
- (id) init
{
NSLog (@":::FIXME::: %@ %s",[self description], sel_get_name(_cmd) );
_ct = [[CairoType alloc] init];
return self;
}
- (void) setDevice: (gswindow_device_t *)window
{
NSLog (@":::FIXME::: %@ %s %0x",[self description], sel_get_name(_cmd) ,_ct);
_buffer = RETAIN([CairoBuffer pixmapWithWindowDevice:window]);
XSetWindowAttributes attr;
[_ct setTargetBuffer:_buffer];
[_ct translateToPoint:NSMakePoint(0,-NSHeight(window->xframe))];
attr.event_mask = KeyPressMask |
KeyReleaseMask | ButtonPressMask |
ButtonReleaseMask | ButtonMotionMask |
StructureNotifyMask | PointerMotionMask |
EnterWindowMask | LeaveWindowMask |
FocusChangeMask | PropertyChangeMask |
ColormapChangeMask | KeymapStateMask |
VisibilityChangeMask;
XChangeWindowAttributes(window->display, window->ident, CWEventMask, &attr);
}
- (CairoType *) ct
{
NSLog (@":::FIXME::: %@ %s %0x",[self description], sel_get_name(_cmd) ,_ct);
return _ct;
}
- (void) dealloc
{
NSLog (@":::FIXME::: %@ %s %0x",[self description], sel_get_name(_cmd) ,_ct);
[_ct release];
if (_buffer)
{
[_buffer release];
}
[super dealloc];
NSLog(@"done CD dealloc");
}
- (id) copyWithZone: (NSZone *)zone
{
CairoDevice *aCD = (CairoDevice *)NSCopyObject(self, 0, zone);
NSLog (@":::FIXME::: %@ %s copy to %0x",[self description], sel_get_name(_cmd), aCD );
aCD->_ct = [_ct copyWithZone:zone];
// aCD->_buffer = [_buffer copy];
RETAIN(_buffer);
return aCD;
}
@end

View file

@ -0,0 +1,133 @@
/*
* CairoFaceInfo.m
*
* Copyright (C) 2003 Free Software Foundation, Inc.
* August 31, 2003
* Written by Banlu Kemiyatorn <object at gmail dot com>
* Base on original code of Alex Malmberg
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include "cairo/CairoFaceInfo.h"
@ implementation CairoFaceInfo
- (id) initWithName: (NSString *)name
familyName: (NSString *)familyName
displayName: (NSString *)displayName
cairoName: (NSString *)cairoName
weight: (int)weight
traits: (unsigned int)traits
cairoSlant: (cairo_font_slant_t)cairoSlant
cairoWeight: (cairo_font_weight_t)cairoWeight
{
[self setName: name];
[self setFamilyName: familyName];
[self setDisplayName: displayName];
[self setCairoName: cairoName];
[self setWeight: weight];
[self setTraits: traits];
[self setCairoSlant: cairoSlant];
[self setCairoWeight: cairoWeight];
return self;
}
- (void) setFamilyName: (NSString *)name
{
ASSIGN(_familyName, name);
}
- (void) setName: (NSString *)name
{
ASSIGN(_faceName, name);
}
- (void) setDisplayName: (NSString *)name
{
ASSIGN(_displayName, name);
}
- (const char *) cairoCName
{
return [_cairoName lossyCString];
}
- (void) setCairoName: (NSString *)name
{
ASSIGN(_cairoName, name);
}
- (NSString *)familyName
{
return _familyName;
}
- (NSString *) name
{
return _faceName;
}
- (NSString *) displayName
{
return _displayName;
}
- (int) weight
{
return _weight;
}
- (void) setWeight: (int)weight
{
_weight = weight;
}
- (unsigned int) traits
{
return _traits;
}
- (cairo_font_weight_t) cairoWeight
{
return _c_weight;
}
- (cairo_font_slant_t) cairoSlant
{
return _c_slant;
}
- (void) setCairoWeight: (cairo_font_weight_t)weight
{
_c_weight = weight;
}
- (void) setCairoSlant: (cairo_font_slant_t)slant
{
_c_slant = slant;
}
- (void) setTraits: (unsigned int)traits
{
_traits = traits;
}
- (unsigned int) cacheSize
{
return 257;
}
@end

View file

@ -0,0 +1,107 @@
/*
* CairoFontEnumerator.m
*
* Copyright (C) 2003 Free Software Foundation, Inc.
* August 31, 2003
* Written by Banlu Kemiyatorn <object at gmail dot com>
* Base on original code of Alex Malmberg
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include <Foundation/NSObject.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSSet.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSValue.h>
#include <Foundation/NSPathUtilities.h>
#include <Foundation/NSFileManager.h>
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSBundle.h>
#include <Foundation/NSDebug.h>
#include <GNUstepGUI/GSFontInfo.h>
#include <AppKit/NSAffineTransform.h>
#include <AppKit/NSBezierPath.h>
#include "gsc/GSGState.h"
#include "cairo/CairoFontEnumerator.h"
#include "cairo/CairoFontManager.h"
@implementation CairoFontEnumerator
+ (void) initializeBackend
{
}
- (void) enumerateFontsAndFamilies
{
static BOOL done = NO;
if (!done)
{
NSArray *fontDef;
NSMutableArray *fontDefs;
ASSIGN(allFontNames, [CairoFontManager allFontNames]);
allFontFamilies =[[NSMutableDictionary alloc] init];
fontDefs =[NSMutableArray arrayWithCapacity:10];
[allFontFamilies setObject: fontDefs forKey:@"Helvetica"];
fontDef =[NSArray arrayWithObjects: @"Helvetica", @"Medium",
[NSNumber numberWithInt: 5],
[NSNumber numberWithUnsignedInt:0], nil];
[fontDefs addObject:fontDef];
fontDef =[NSArray arrayWithObjects: @"Helvetica-Bold", @"Bold",
[NSNumber numberWithInt: 9],
[NSNumber numberWithUnsignedInt:NSBoldFontMask],
nil];
[fontDefs addObject:fontDef];
fontDef =[NSArray arrayWithObjects: @"Helvetica-Oblique", @"Oblique",
[NSNumber numberWithInt: 5],
[NSNumber numberWithUnsignedInt:NSItalicFontMask],
nil];
[fontDefs addObject:fontDef];
fontDefs =[NSMutableArray arrayWithCapacity:10];
[allFontFamilies setObject: fontDefs forKey:@"Courier"];
fontDef =[NSArray arrayWithObjects: @"Courier", @"Medium",
[NSNumber numberWithInt: 5],
[NSNumber numberWithUnsignedInt:NSFixedPitchFontMask],
nil];
[fontDefs addObject:fontDef];
done = YES;
}
NSLog (@"%@", allFontNames);
}
- (NSString *) defaultSystemFontName
{
return @"Helvetica";
}
- (NSString *) defaultBoldSystemFontName
{
return @"Helvetica-Bold";
}
- (NSString *) defaultFixedPitchFontName
{
return @"Courier";
}
@end

View file

@ -0,0 +1,307 @@
/*
* CairoFontInfo.m
*
* Copyright (C) 2003 Free Software Foundation, Inc.
* August 31, 2003
* Written by Banlu Kemiyatorn <object at gmail dot com>
* Base on original code of Alex Malmberg
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include "cairo/CairoFontInfo.h"
#include <AppKit/NSAffineTransform.h>
#include <math.h>
#include <cairo.h>
@implementation CairoFontInfo
+ (void) initializeBackend
{
//NSLog(@"CairoFontInfo : Initializing...");
[GSFontEnumerator setDefaultClass: [CairoFontEnumerator class]];
[GSFontInfo setDefaultClass: self];
}
- (void) setCacheSize: (unsigned int)size
{
_cacheSize = size;
if (_cachedSizes)
{
free(_cachedSizes);
}
if (_cachedGlyphs)
{
free(_cachedGlyphs);
}
_cachedSizes = malloc(sizeof(NSSize) * size);
_cachedGlyphs = malloc(sizeof(unsigned int) * size);
}
- (void) createCairoFontWithIdentity: (void *)ident
{
/* subclass should override */
cairo_matrix_t *font_matrix;
cairo_font_extents_t font_extents;
cairo_select_font(_cf,[_faceInfo cairoCName],[_faceInfo cairoSlant],
[_faceInfo cairoWeight]);
xrFont = cairo_current_font(_cf);
font_matrix = cairo_matrix_create();
cairo_matrix_set_affine(font_matrix, matrix[0], matrix[1], matrix[2],
-matrix[3], matrix[4], matrix[5]);
cairo_transform_font(_cf, font_matrix);
/*
NSLog(@"%g %g %g %g %g %g",matrix[0],matrix[1],matrix[2],matrix[3],matrix[4],matrix[5]);
*/
cairo_current_font_extents(_cf, &font_extents);
ascender = font_extents.ascent;
descender = font_extents.descent;
xHeight = font_extents.height;
maximumAdvancement = NSMakeSize(font_extents.max_x_advance,
font_extents.max_y_advance);
cairo_matrix_destroy(font_matrix);
}
- (id) initWithFontName: (NSString *)name
matrix: (const float *)fmatrix
screenFont: (BOOL)p_screenFont
{
//NSLog(@"initWithFontName %@",name);
[super init];
/* do not forget to check for font specific
* cache size from face info FIXME FIXME
*/
ASSIGN(_faceInfo, [CairoFontManager fontWithName: name]);
if (!_faceInfo)
{
RELEASE(self);
return nil;
}
_cachedSizes = NULL;
[self setCacheSize: [_faceInfo cacheSize]];
_screenFont = p_screenFont;
/* setting GSFontInfo:
* weight, traits, fontName, familyName,
* matrix, mostCompatibleStringEncoding, encodingScheme,
*/
weight = [_faceInfo weight];
traits = [_faceInfo traits];
fontName = [name copy];
familyName = [[_faceInfo familyName] copy];
memcpy(matrix, fmatrix, sizeof(matrix));
mostCompatibleStringEncoding = NSUTF8StringEncoding;
encodingScheme = @"iso10646-1";
if (_screenFont)
{
/* Round up; makes the text more legible. */
matrix[0] = ceil(matrix[0]);
if (matrix[3] < 0.0)
matrix[3] = floor(matrix[3]);
else
matrix[3] = ceil(matrix[3]);
}
/* setting GSFontInfo:
* xHeight, pix_width, pix_height
*/
_cf = cairo_create ();
[self createCairoFontWithIdentity: _faceInfo];
fontBBox = NSMakeRect(0, descender,
maximumAdvancement.width, ascender + descender);
//NSLog(NSStringFromRect(fontBBox));
return self;
}
- (void) dealloc
{
RELEASE(_faceInfo);
cairo_destroy(_cf);
free(_cachedSizes);
free(_cachedGlyphs);
[super dealloc];
}
- (BOOL) glyphIsEncoded: (NSGlyph)glyph
{
/* subclass should override */
return YES;
}
- (NSSize) advancementForGlyph: (NSGlyph)glyph
{
/* subclass should override */
cairo_glyph_t cglyph;
cairo_text_extents_t ctext;
int entry;
glyph -= 29;
entry = glyph % _cacheSize;
if (_cachedGlyphs[entry] == glyph)
{
return _cachedSizes[entry];
}
cglyph.index = glyph;
cglyph.x = 0;
cglyph.y = 0;
cairo_glyph_extents(_cf, &cglyph, 1, &ctext);
_cachedGlyphs[entry] = glyph;
_cachedSizes[entry] = NSMakeSize(ctext.x_advance, ctext.y_advance);
//NSLog(NSStringFromSize(_cachedSizes[entry]));
return _cachedSizes[entry];
}
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
{
/* subclass should override */
cairo_glyph_t cglyph;
cairo_text_extents_t ctext;
glyph -= 29;
cglyph.index = glyph;
cglyph.x = 0;
cglyph.y = 0;
cairo_glyph_extents(_cf, &cglyph, 1, &ctext);
return NSMakeRect(ctext.x_bearing, ctext.y_bearing,
ctext.width, ctext.height);
}
- (NSPoint) positionOfGlyph: (NSGlyph)g
precededByGlyph: (NSGlyph)prev
isNominal: (BOOL *)nominal
{
NSSize size;
/* subclass should override */
if (nominal)
*nominal = YES;
if (g == NSControlGlyph || prev == NSControlGlyph)
{
return NSZeroPoint;
}
size = [self advancementForGlyph: prev];
return NSMakePoint(size.width, size.height);
}
- (float) widthOfString: (NSString *)string
{
/* subclass should override */
cairo_text_extents_t ctext;
cairo_text_extents(_cf, [string UTF8String], &ctext);
//NSLog (@"widthOfString %@ = %g", string, ctext.width);
return ctext.width;
}
-(NSGlyph) glyphWithName: (NSString *) glyphName
{
/* subclass should override */
/* terrible! FIXME */
NSGlyph g = [glyphName cString][0];
return g;
}
/* need cairo to export its cairo_path_t first */
- (void) appendBezierPathWithGlyphs: (NSGlyph *)glyphs
count: (int)count
toBezierPath: (NSBezierPath *)path
{
/* TODO LATER
cairo_t *ct;
int i;
NSPoint start = [path currentPoint];
cairo_glyph_t *cairo_glyphs;
cairo_glyphs = malloc(sizeof(cairo_glyph_t) * count);
ct = cairo_create();
cairo_destroy(ct);
*/
#if 0
int i;
NSGlyph glyph;
FT_Matrix ftmatrix;
FT_Vector ftdelta;
NSPoint p = [path currentPoint];
ftmatrix.xx = 65536;
ftmatrix.xy = 0;
ftmatrix.yx = 0;
ftmatrix.yy = 65536;
ftdelta.x = p.x * 64.0;
ftdelta.y = p.y * 64.0;
for (i = 0; i < count; i++, glyphs++)
{
FT_Face face;
FT_Glyph gl;
FT_OutlineGlyph og;
glyph = *glyphs - 1;
if (FTC_Manager_Lookup_Size(ftc_manager, &_imgd.font, &face, 0))
continue;
if (FT_Load_Glyph(face, glyph, FT_LOAD_DEFAULT))
continue;
if (FT_Get_Glyph(face->glyph, &gl))
continue;
if (FT_Glyph_Transform(gl, &ftmatrix, &ftdelta))
{
NSLog(@"glyph transformation failed!");
continue;
}
og = (FT_OutlineGlyph)gl;
ftdelta.x += gl->advance.x >> 10;
ftdelta.y += gl->advance.y >> 10;
FT_Outline_Decompose(&og->outline, &bezierpath_funcs, path);
FT_Done_Glyph(gl);
}
if (count)
{
[path moveToPoint: NSMakePoint(ftdelta.x / 64.0,
ftdelta.y / 64.0)];
}
#endif
}
- (void) set
{
NSLog(@"ignore -set method of font '%@'\n", fontName);
}
@end

View file

@ -0,0 +1,109 @@
/*
* CairoFontManager.m
*
* Copyright (C) 2003 Free Software Foundation, Inc.
* August 31, 2003
* Written by Banlu Kemiyatorn <object at gmail dot com>
* Base on original code of Alex Malmberg
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include "cairo/CairoFontManager.h"
#include "cairo/CairoFaceInfo.h"
@implementation CairoFontManager
NSMutableDictionary * __allFonts;
NSMutableArray *__allFamilies;
+ (void) addFace: (CairoFaceInfo *)aFace PostScriptName: (NSString *)psname
{
[__allFonts setObject: aFace forKey: psname];
if (![__allFamilies containsObject: [aFace familyName]])
{
[__allFamilies addObject: [aFace familyName]];
}
}
+ (void) initialize
{
id aFace;
NSLog(@"init cairo font manager");
__allFonts = [[NSMutableDictionary alloc] init];
__allFamilies = [[NSMutableArray alloc] init];
aFace = [[CairoFaceInfo alloc] initWithName: @"Medium"
familyName: @"Helvetica"
displayName: @"Helvetica"
cairoName: @"serif"
weight: 5
traits: 0
cairoSlant: CAIRO_FONT_SLANT_NORMAL
cairoWeight: CAIRO_FONT_WEIGHT_NORMAL];
AUTORELEASE(aFace);
[self addFace: aFace PostScriptName: @"Helvetica"];
aFace = [[CairoFaceInfo alloc] initWithName: @"Bold"
familyName: @"Helvetica"
displayName: @"Helvetica Bold"
cairoName: @"serif"
weight: 9
traits: NSBoldFontMask
cairoSlant: CAIRO_FONT_SLANT_NORMAL
cairoWeight: CAIRO_FONT_WEIGHT_BOLD];
AUTORELEASE(aFace);
[self addFace: aFace PostScriptName: @"Helvetica-Bold"];
aFace = [[CairoFaceInfo alloc] initWithName: @"Oblique"
familyName: @"Helvetica"
displayName: @"Helvetica Oblique"
cairoName: @"serif"
weight: 5
traits: NSItalicFontMask
cairoSlant: CAIRO_FONT_SLANT_OBLIQUE
cairoWeight: CAIRO_FONT_WEIGHT_NORMAL];
AUTORELEASE(aFace);
[self addFace: aFace PostScriptName: @"Helvetica-Oblique"];
aFace = [[CairoFaceInfo alloc] initWithName: @"Medium"
familyName: @"Courier"
displayName: @"Courier"
cairoName: @"Courier"
weight: 5
traits: NSFixedPitchFontMask
cairoSlant: CAIRO_FONT_SLANT_NORMAL
cairoWeight: CAIRO_FONT_WEIGHT_NORMAL];
AUTORELEASE(aFace);
[self addFace: aFace PostScriptName: @"Courier"];
}
+ (CairoFaceInfo *) fontWithName: (NSString *) name
{
CairoFaceInfo *face;
face =[__allFonts objectForKey: name];
if (!face)
{
NSLog (@"Font not found %@", name);
}
return face;
}
+ (NSArray *) allFontNames
{
return [__allFonts allKeys];
}
@end

View file

@ -0,0 +1,405 @@
/*
* CairoFontInfo.m
*
* Copyright (C) 2003 Free Software Foundation, Inc.
* April 27, 2004
* Written by Banlu Kemiyatorn <lastlifeintheuniverse at hotmail dot com>
* Base on original code of Alex Malmberg
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include "cairo/CairoFontInfo.h"
#include <cairo.h>
@class NSAffineTransform;
@implementation CairoFontInfo
/* TODO port this freetype code so it can be shared with other backends */
/* TODO or simply use cairo's text/glyph extense */
static FT_Library ft_library;
static FTC_Manager ftc_manager;
+ (void) initializeBackend
{
NSLog(@"CairoFreeTypeFontInfo : Initializing...");
[super initializeBackend];
[GSFontInfo setDefaultClass: self];
if (FT_Init_FreeType(&ft_library))
NSLog(@"FT_Init_FreeType failed");
}
- (void) setFaceId:(void *)face_id
{
_imgd.font.face_id = (FTC_FaceID)face_id;
}
- (id) initWithFontName:(NSString *)name
matrix:(const float *)fmatrix
screenFont:(BOOL)p_screenFont
{
FT_Size size;
FT_Face face;
[super initWithFontName:name
matrix:fmatrix
screenFont:p_screenFont];
_imgd.font.pix_width = fabs(matrix[0]);
_imgd.font.pix_height = fabs(matrix[3]);
if ((error=FTC_Manager_Lookup_Size(ftc_manager, &_imgd.font, &face, &size)))
{
NSLog(@"FTC_Manager_Lookup_Size() failed for '%@', error %08x!\n", name, error);
return self;
}
ascender = fabs(((int)size->metrics.ascender) / 64.0);
descender = fabs(((int)size->metrics.descender) / 64.0);
xHeight = ascender * 0.5; /* TODO */
maximumAdvancement = NSMakeSize((_size->metrics.max_advance / 64.0), ascender + descender);
fontBBox = NSMakeRect(0, descender, maximumAdvancement.width, ascender + descender);
descender = -descender;
{
float xx, yy;
FTC_ImageTypeRec cur;
cur = _imgd;
xx = matrix[0];
yy = matrix[3];
if (xx == yy && xx < 16 && xx >= 8)
{
int rh = _faceInfo->_render_hints_hack;
if (rh & 0x10000)
{
cur.flags = FT_LOAD_TARGET_NORMAL;
rh = (rh >> 8) & 0xff;
}
else
{
cur.flags = FT_LOAD_TARGET_MONO;
rh = rh & 0xff;
}
if (rh & 1)
cur.flags |= FT_LOAD_FORCE_AUTOHINT;
if (!(rh & 2))
cur.flags |= FT_LOAD_NO_HINTING;
}
else if (xx < 8)
cur.flags = FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING;
else
cur.flags = FT_LOAD_TARGET_NORMAL;
_advancementImgd = cur;
}
/* create font here */
FT_New_Face(ft_library, [[_faceInfo->files] objectAtIndex:0]);
_font = cairo_ft_font_create(&face);
return self;
}
- (BOOL) glyphIsEncoded: (NSGlyph)glyph
{
[self subclassResponsibility: _cmd];
return NO;
}
- (NSSize) advancementForGlyph: (NSGlyph)glyph
{
cairo_glyph_t cglyph;
cairo_text_extents_t ctext;
glyph--;
if (screenFont)
{
int entry = glyph % CACHE_SIZE;
if (cachedGlyph[entry] == glyph)
return cachedSize[entry];
if ((error=FTC_SBitCache_Lookup(ftc_sbitcache, &advancementImgd, glyph, &sbit, NULL)))
{
NSLog(@"FTC_SBitCache_Lookup() failed with error %08x (%08x, %08x, %ix%i, %08x)\n",
error, glyph, advancementImgd.font.face_id,
advancementImgd.font.pix_width, advancementImgd.font.pix_height,
advancementImgd.flags
);
return NSZeroSize;
}
cachedGlyph[entry] = glyph;
cachedSize[entry] = NSMakeSize(sbit->xadvance, sbit->yadvance);
return cachedSize[entry];
}
else
{
FT_Face face;
FT_Glyph gl;
FT_Matrix ftmatrix;
FT_Vector ftdelta;
float f;
NSSize s;
f = fabs(matrix[0] * matrix[3] - matrix[1] * matrix[2]);
if (f > 1)
f = sqrt(f);
else
f = 1.0;
f = (int)f;
ftmatrix.xx = matrix[0] / f * 65536.0;
ftmatrix.xy = matrix[1] / f * 65536.0;
ftmatrix.yx = matrix[2] / f * 65536.0;
ftmatrix.yy = matrix[3] / f * 65536.0;
ftdelta.x = ftdelta.y = 0;
if (FTC_Manager_Lookup_Size(ftc_manager, &_imgd.font, &face, 0))
return NSZeroSize;
if (FT_Load_Glyph(face, glyph, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP))
return NSZeroSize;
if (FT_Get_Glyph(face->glyph, &gl))
return NSZeroSize;
if (FT_Glyph_Transform(gl, &ftmatrix, &ftdelta))
return NSZeroSize;
s = NSMakeSize(gl->advance.x / 65536.0, gl->advance.y / 65536.0);
FT_Done_Glyph(gl);
return s;
}
}
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
{
FTC_ImageTypeRec *cur;
FT_BBox bbox;
FT_Glyph g;
FT_Error error;
glyph--;
/* TODO: this is ugly */
cur = &_imgd;
if ((error=FTC_ImageCache_Lookup(ftc_imagecache, cur, glyph, &g, NULL)))
{
NSLog(@"FTC_ImageCache_Lookup() failed with error %08x",error);
// NSLog(@"boundingRectForGlyph: %04x -> %i\n", aGlyph, glyph);
return fontBBox;
}
FT_Glyph_Get_CBox(g, ft_glyph_bbox_gridfit, &bbox);
/* printf("got cbox for %04x: %i, %i - %i, %i\n",
aGlyph, bbox.xMin, bbox.yMin, bbox.xMax, bbox.yMax);*/
return NSMakeRect(bbox.xMin / 64.0, bbox.yMin / 64.0,
(bbox.xMax - bbox.xMin) / 64.0, (bbox.yMax - bbox.yMin) / 64.0);
}
-(NSPoint) positionOfGlyph: (NSGlyph)g
precededByGlyph: (NSGlyph)prev
isNominal: (BOOL *)nominal
{
NSPoint a;
FT_Face face;
FT_Vector vec;
FT_GlyphSlot glyph;
g--;
prev--;
if (nominal)
*nominal = YES;
if (g == NSControlGlyph || prev == NSControlGlyph)
return NSZeroPoint;
if (FTC_Manager_Lookup_Size(ftc_manager, &_imgd.font, &face, 0))
return NSZeroPoint;
if (FT_Load_Glyph(face, prev, FT_LOAD_DEFAULT))
return NSZeroPoint;
glyph = face->glyph;
a = NSMakePoint(glyph->advance.x / 64.0, glyph->advance.y / 64.0);
if (FT_Get_Kerning(face, prev, g, ft_kerning_default, &vec))
return a;
if (vec.x == 0 && vec.y == 0)
return a;
if (nominal)
*nominal = NO;
a.x += vec.x / 64.0;
a.y += vec.y / 64.0;
return a;
}
- (float) widthOfString: (NSString*)string
{
unichar ch;
int i, c = [string length];
int total;
FTC_CMapDescRec cmap;
unsigned int glyph;
FTC_SBit sbit;
FTC_ImageTypeRec *cur;
cmap.face_id = _imgd.font.face_id;
cmap.u.encoding = ft_encoding_unicode;
cmap.type = FTC_CMAP_BY_ENCODING;
total = 0;
for (i = 0; i < c; i++)
{
ch = [string characterAtIndex: i];
cur = &_imgd;
glyph = FTC_CMapCache_Lookup(ftc_cmapcache, &cmap, ch);
/* TODO: shouldn't use sbit cache for this */
if (1)
{
if (FTC_SBitCache_Lookup(ftc_sbitcache, cur, glyph, &sbit, NULL))
continue;
total += sbit->xadvance;
}
else
{
NSLog(@"non-sbit code not implemented");
}
}
return total;
}
-(NSGlyph) glyphWithName: (NSString *)glyphName
{
FT_Face face;
NSGlyph g;
if (FTC_Manager_Lookup_Size(ftc_manager, &_imgd.font, &face, 0))
return NSNullGlyph;
g = FT_Get_Name_Index(face, (FT_String *)[glyphName lossyCString]);
if (g)
return g + 1;
return NSNullGlyph;
}
/* need cairo to export its cairo_path_t first */
-(void) appendBezierPathWithGlyphs: (NSGlyph *)glyphs
count: (int)count
toBezierPath: (NSBezierPath *)path
{
cairo_t *ct;
int i;
/* TODO LATER
NSPoint start = [path currentPoint];
cairo_glyph_t *cairo_glyphs;
cairo_glyphs = malloc(sizeof(cairo_glyph_t) * count);
ct = cairo_create();
cairo_destroy(ct);
*/
#if 0
int i;
NSGlyph glyph;
FT_Matrix ftmatrix;
FT_Vector ftdelta;
NSPoint p = [path currentPoint];
ftmatrix.xx = 65536;
ftmatrix.xy = 0;
ftmatrix.yx = 0;
ftmatrix.yy = 65536;
ftdelta.x = p.x * 64.0;
ftdelta.y = p.y * 64.0;
for (i = 0; i < count; i++, glyphs++)
{
FT_Face face;
FT_Glyph gl;
FT_OutlineGlyph og;
glyph = *glyphs - 1;
if (FTC_Manager_Lookup_Size(ftc_manager, &_imgd.font, &face, 0))
continue;
if (FT_Load_Glyph(face, glyph, FT_LOAD_DEFAULT))
continue;
if (FT_Get_Glyph(face->glyph, &gl))
continue;
if (FT_Glyph_Transform(gl, &ftmatrix, &ftdelta))
{
NSLog(@"glyph transformation failed!");
continue;
}
og = (FT_OutlineGlyph)gl;
ftdelta.x += gl->advance.x >> 10;
ftdelta.y += gl->advance.y >> 10;
FT_Outline_Decompose(&og->outline, &bezierpath_funcs, path);
FT_Done_Glyph(gl);
}
if (count)
{
[path moveToPoint: NSMakePoint(ftdelta.x / 64.0, ftdelta.y / 64.0)];
}
#endif
}
- (void) set
{
NSLog(@"ignore -set method of font '%@'\n", fontName);
}
/*** CairoFontInfo Protocol ***/
@end

1083
Source/cairo/CairoGState.m Normal file

File diff suppressed because it is too large Load diff

151
Source/cairo/CairoSurface.m Normal file
View file

@ -0,0 +1,151 @@
/*
Copyright (C) 2004 Free Software Foundation, Inc.
Author: 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 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 "cairo/CairoSurface.h"
#include <math.h>
#include "config.h"
#ifdef USE_GLITZ
@class XGCairoGlitzSurface;
#else
@class XGCairoSurface;
#endif
static CairoSurface **surface_list;
static int num_cairo_surfaces;
static Class __defaultSurfaceClass;
@implementation CairoSurface
+ (void) setDefaultSurfaceClass: (Class)aClass
{
__defaultSurfaceClass = aClass;
}
+ (void) initializeBackend
{
if (BUILD_SERVER == SERVER_x11)
{
#ifdef USE_GLITZ
[self setDefaultSurfaceClass: [XGCairoGlitzSurface class]];
#else
[self setDefaultSurfaceClass: [XGCairoSurface class]];
#endif
}
}
+ (void) _listSurface
{
int i;
id str = @"surfaces :";
if (surface_list == NULL)
{
NSLog(@"no surface");
return;
}
for (i = 0; i < num_cairo_surfaces; i++)
{
str = [NSString stringWithFormat: @"%@ %p", str, surface_list[i]];
}
NSLog(str);
}
+ (CairoSurface *) surfaceForDevice: (void *)device
depthInfo: (CairoInfo *)cairoInfo
{
id newsurface;
int i;
for (i = 0; i < num_cairo_surfaces; i++)
{
if (surface_list[i]->gsDevice == device)
{
return surface_list[i];
}
}
/* a surface for the device isn't found
* create a new one */
newsurface =[self createSurfaceForDevice: device depthInfo:cairoInfo];
num_cairo_surfaces++;
surface_list = realloc (surface_list, sizeof (void *) * num_cairo_surfaces);
if (!surface_list)
{
NSLog(@"Woah.. buy some memory man! CairoSurface.m meet OOMKiller! %d",
__LINE__);
exit(1);
}
surface_list[num_cairo_surfaces - 1] = newsurface;
return newsurface;
}
+ (CairoSurface *) createSurfaceForDevice: (void *)device
depthInfo: (CairoInfo *)cairoInfo
{
if (__defaultSurfaceClass == self)
{
[self subclassResponsibility: _cmd];
return nil;
}
return [__defaultSurfaceClass createSurfaceForDevice: device depthInfo: cairoInfo];
}
- (id) initWithDevice: (void *) device
{
/* TODO FIXME make a more abstract struct for the device */
/* _surface = cairo_surface_create_for_image(); */
[self subclassResponsibility:_cmd];
return self;
}
- (void) dealloc
{
//NSLog(@"CairoSurface dealloc");
[super dealloc];
}
- (void) setAsTargetOfCairo: (cairo_t *)ct
{
[self subclassResponsibility:_cmd];
}
- (NSString *) description
{
return [NSString stringWithFormat:@"<CairoSurface %p xr:%p>", self, NULL];
}
-(NSSize) size
{
[self subclassResponsibility:_cmd];
return NSMakeSize(0, 0);
}
@end

50
Source/cairo/GNUmakefile Normal file
View file

@ -0,0 +1,50 @@
# Copyright (C) 2004 Free Software Foundation, Inc.
#
# Author: Banlu Kemiyatorn <object at gmail dot com>
#
# This file is part of the GNUstep Backend.
#
# 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; see the file COPYING.LIB.
# If not, write to the Free Software Foundation,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
GNUSTEP_LOCAL_ADDITIONAL_MAKEFILES=../../back.make
include $(GNUSTEP_MAKEFILES)/common.make
include ../../config.make
SUBPROJECT_NAME=cairo
# The Objective-C source files to be compiled
cairo_OBJC_FILES = CairoSurface.m \
CairoFontInfo.m \
CairoGState.m \
CairoContext.m \
CairoFontEnumerator.m \
CairoFontManager.m \
CairoFaceInfo.m \
XGCairoSurface.m \
XGCairoXImageSurface.m \
NSBezierPathCairo.m \
# CairoFreeTypeFontInfo.m \
-include GNUmakefile.preamble
include $(GNUSTEP_MAKEFILES)/subproject.make
-include GNUmakefile.postamble

View file

@ -0,0 +1,51 @@
#
# GNUmakefile.preamble
#
# Copyright (C) 2002 Free Software Foundation, Inc.
#
# Author: Adam Fedor <fedor@gnu.org>
#
# This file is part of the GNUstep Backend.
#
# 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; see the file COPYING.LIB.
# If not, write to the Free Software Foundation,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Flags dealing with compiling and linking
#
# Additional flags to pass to the preprocessor
ADDITIONAL_CPPFLAGS += -Wall $(CONFIG_SYSTEM_DEFS)
# Additional flags to pass to the Objective-C compiler
#ADDITIONAL_OBJCFLAGS =
# Additional flags to pass to the C compiler
#ADDITIONAL_CFLAGS =
# Additional include directories the compiler should search
ADDITIONAL_INCLUDE_DIRS = -I../../Headers \
-I../$(GNUSTEP_TARGET_DIR) $(GRAPHIC_CFLAGS) \
# Additional LDFLAGS to pass to the linker
#ADDITIONAL_LDFLAGS =
# Additional library directories the linker should search
#ADDITIONAL_LIB_DIRS =
#
# Flags dealing with installing and uninstalling
#

View file

@ -0,0 +1,31 @@
/*
* NSBezierPathCairo.m
* Copyright (C) 2003 Free Software Foundation, Inc.
* April 10, 2004
* Written by Banlu Kemiyatorn <object at gmail dot com>
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include <AppKit/NSBezierPath.h>
#include <cairo.h>
@interface NSBezierPath (Cairo)
+ (void) initializeCairoBezierPath;
+ (NSBezierPath *) bezierPathFromCairo: (cairo_t *)ct;
- (void) appendBezierPathToCairo: (cairo_t *)ct;
- (BOOL) containsFillPoint: (NSPoint)p;
- (BOOL) containsStrokePoint: (NSPoint)p;
@end

View file

@ -0,0 +1,142 @@
/*
* NSBezierPathCairo.m
* Copyright (C) 2003 Free Software Foundation, Inc.
* April 10, 2004
* Written by Banlu Kemiyatorn <object at gmail dot com>
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include "NSBezierPathCairo.h"
@implementation NSBezierPath (Cairo)
static void
gs_cairo_move_to(void *data, double x, double y)
{
NSBezierPath *path = (NSBezierPath *)data;
[path moveToPoint: NSMakePoint(x, y)];
}
static void
gs_cairo_line_to(void *data, double x, double y)
{
NSBezierPath *path = (NSBezierPath *)data;
[path lineToPoint: NSMakePoint(x, y)];
}
static void
gs_cairo_curve_to(void *data,
double x1, double y1,
double x2, double y2, double x3, double y3)
{
NSBezierPath *path = (NSBezierPath *)data;
[path curveToPoint: NSMakePoint(x1, y1)
controlPoint1: NSMakePoint(x2, y2)
controlPoint2: NSMakePoint(x3, y3)];
}
static void
gs_cairo_close_path(void *data)
{
NSBezierPath *path = (NSBezierPath *)data;
[path closePath];
}
+ (NSBezierPath *) bezierPathFromCairo: (cairo_t *)ct
{
NSBezierPath *path =[NSBezierPath bezierPath];
cairo_current_path(ct, gs_cairo_move_to, gs_cairo_line_to,
gs_cairo_curve_to, gs_cairo_close_path, path);
return path;
}
static cairo_t *__ct = NULL;
+ (void) initializeCairoBezierPath
{
__ct = cairo_create();
}
- (void) appendBezierPathToCairo: (cairo_t *)ct
{
int i, n;
double *dpat;
NSPoint pts[3];
NSBezierPathElement e;
SEL elmsel = @selector(elementAtIndex: associatedPoints:);
IMP elmidx = [self methodForSelector:elmsel];
n = [self elementCount];
for (i = 0; i < n; i++)
{
e = (NSBezierPathElement)(*elmidx)(self, elmsel, i, pts);
switch (e)
{
case NSMoveToBezierPathElement:
cairo_move_to(ct, pts[0].x, pts[0].y);
break;
case NSLineToBezierPathElement:
cairo_line_to(ct, pts[0].x, pts[0].y);
break;
case NSCurveToBezierPathElement:
cairo_curve_to(ct, pts[0].x, pts[0].y, pts[1].x, pts[1].y,
pts[2].x, pts[2].y);
break;
case NSClosePathBezierPathElement:
cairo_close_path(ct);
break;
}
}
cairo_set_line_width(ct, _lineWidth);
cairo_set_line_join(ct, (cairo_line_join_t)_lineJoinStyle);
cairo_set_line_cap(ct, (cairo_line_cap_t)_lineCapStyle);
cairo_set_miter_limit(ct, _miterLimit);
dpat = malloc(sizeof (double) * _dash_count);
for (i = 0; i < _dash_count; i++)
{
dpat[i] = _dash_pattern[i];
}
cairo_set_dash(ct, dpat, _dash_count, _dash_phase);
free (dpat);
}
- (BOOL) containsFillPoint: (NSPoint)p;
{
BOOL ret;
cairo_new_path(__ct);
[self appendBezierPathToCairo: __ct];
ret = cairo_in_fill(__ct, p.x, p.y);
return ret;
}
- (BOOL) containsStrokePoint: (NSPoint)p;
{
BOOL ret;
cairo_new_path (__ct);
[self appendBezierPathToCairo:__ct];
ret = cairo_in_stroke(__ct, p.x, p.y);
return ret;
}
@end

View file

@ -0,0 +1,126 @@
/*
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Alexander Malmberg <alexander@malmberg.org>
Author: 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 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 <Foundation/NSUserDefaults.h>
#include <math.h>
#include "cairo/XGCairoGlitzSurface.h"
#define GSWINDEVICE ((gswindow_device_t *)gsDevice)
@implementation XGCairoGlitzSurface
+ (CairoSurface *) createSurfaceForDevice: (void *)device
depthInfo: (CairoInfo *)cairoInfo
{
#define NEWGSWINDEVICE ((gswindow_device_t *)device)
XGCairoGlitzSurface *surface;
surface = [[self alloc] initWithDevice:NEWGSWINDEVICE];
NSAssert(NEWGSWINDEVICE->buffer, @"FIXME! CairoSurface: Strange, a window doesn't have buffer");
return surface;
#undef NEWGSWINDEVICE
}
- (NSString *) description
{
return [NSString stringWithFormat: @"<XGCairoSurface %p xr:%p>", self, NULL];
}
- (id) initWithDevice: (void *)device
{
/* FIXME format is ignore when Visual isn't NULL
* Cairo may change this API
*/
gsDevice = device;
/*
if (GSWINDEVICE->type != NSBackingStoreNonretained)
{
XSetWindowBackgroundPixmap(GSWINDEVICE->display,
GSWINDEVICE->ident,
GSWINDEVICE->buffer);
}
*/
return self;
}
- (void) setAsTargetOfCairo: (cairo_t *)ct
{
glitz_surface_t *glsurface;
glitz_format_t *format;
Colormap cm;
XVisualInfo *vi;
unsigned long format_options = GLITZ_FORMAT_OPTION_ONSCREEN_MASK;
format_options |= GLITZ_FORMAT_OPTION_NO_MULTISAMPLE_MASK;
format_options |= GLITZ_FORMAT_OPTION_SINGLEBUFFER_MASK;
format = glitz_glx_find_standard_format(GSWINDEVICE->display,
GSWINDEVICE->screen,
format_options,
GLITZ_STANDARD_RGB24);
if (!format)
{
NSLog(@"XGCairoGlitzSurface : %d : no format",__LINE__);
exit(1);
}
vi = glitz_glx_get_visual_info_from_format(GSWINDEVICE->display,
GSWINDEVICE->screen,
format);
if (!vi)
{
NSLog(@"XGCairoGlitzSurface : %d : no visual info",__LINE__);
exit(1);
}
/*
cm = XCreateColormap(GSWINDEVICE->display,
GSWINDEVICE->root, vi->visual, AllocNone);
XSetWindowColormap(GSWINDEVICE->display,GSWINDEVICE->ident,cm);
*/
glsurface = glitz_glx_surface_create(GSWINDEVICE->display,
GSWINDEVICE->screen,
format,
GSWINDEVICE->ident);
// glitz_surface_update_size(glsurface);
cairo_set_target_gl(ct, glsurface);
}
- (NSSize) size
{
return GSWINDEVICE->xframe.size;
}
@end

View file

@ -0,0 +1,110 @@
/*
Copyright (C) 2002 Free Software Foundation, Inc.
Author: 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 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 <Foundation/NSUserDefaults.h>
#include <math.h>
#include "cairo/XGCairoSurface.h"
#define GSWINDEVICE ((gswindow_device_t *)gsDevice)
@implementation XGCairoSurface
+ (CairoSurface *) createSurfaceForDevice: (void *)device
depthInfo: (CairoInfo *)cairoInfo
{
#define NEWGSWINDEVICE ((gswindow_device_t *)device)
XGCairoSurface *surface;
surface = [[self alloc] initWithDevice: NEWGSWINDEVICE];
NSAssert(NEWGSWINDEVICE->buffer, @"FIXME! CairoSurface: Strange, a window doesn't have buffer");
return surface;
#undef NEWGSWINDEVICE
}
- (NSString *) description
{
return [NSString stringWithFormat: @"<XGCairoSurface %p xr:%p>", self, xrSurface];
}
- (id) initWithDevice: (void *)device
{
/* FIXME format is ignore when Visual isn't NULL
* Cairo may change this API
*/
gsDevice = device;
/*
if (GSWINDEVICE->type != NSBackingStoreNonretained)
{
GSWINDEVICE->gdriverProtocol |= GDriverHandlesExpose;
XSetWindowBackgroundPixmap(GSWINDEVICE->display,
GSWINDEVICE->ident,
GSWINDEVICE->buffer);
}
*/
xrSurface = cairo_xlib_surface_create(GSWINDEVICE->display,
GSWINDEVICE->buffer,
DefaultVisual(GSWINDEVICE->display,
DefaultScreen(GSWINDEVICE->display)),
0,
DefaultColormap(GSWINDEVICE->display,
DefaultScreen(GSWINDEVICE->display)));
return self;
}
- (void) setAsTargetOfCairo: (cairo_t *)ct
{
/*
if (GSWINDEVICE->type != NSBackingStoreNonretained)
{
GSWINDEVICE->gdriverProtocol |= GDriverHandlesExpose;
XSetWindowBackgroundPixmap(GSWINDEVICE->display,
GSWINDEVICE->ident,
GSWINDEVICE->buffer);
}
*/
//cairo_set_target_drawable(ct, GSWINDEVICE->display, GSWINDEVICE->buffer);
cairo_set_target_surface(ct, xrSurface);
}
- (void) dealloc
{
cairo_surface_destroy(xrSurface);
[super dealloc];
}
- (void) logDevice
{
NSLog(@"device %p id:%p buff:%p",self,GSWINDEVICE->ident,GSWINDEVICE->buffer);
}
- (NSSize) size
{
return GSWINDEVICE->xframe.size;
}
@end

View file

@ -0,0 +1,82 @@
/*
Copyright (C) 2002 Free Software Foundation, Inc.
Author: 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 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 <Foundation/NSUserDefaults.h>
#include <math.h>
#include "cairo/XGCairoXImageSurface.h"
#define GSWINDEVICE ((gswindow_device_t *)gsDevice)
@implementation XGCairoXImageSurface
+ (CairoSurface *) createSurfaceForDevice: (void *)device
depthInfo: (CairoInfo *)cairoInfo
{
#define NEWGSWINDEVICE ((gswindow_device_t *)device)
XGCairoXImageSurface *surface;
surface = [[self alloc] initWithDevice:NEWGSWINDEVICE];
NSAssert(NEWGSWINDEVICE->buffer, @"FIXME! CairoSurface: Strange, a window doesn't have buffer");
return surface;
#undef NEWGSWINDEVICE
}
- (NSString *) description
{
return [NSString stringWithFormat: @"<XGCairoXImageSurface %p xr:%p>", self, image];
}
- (id) initWithDevice: (void *)device
{
/* FIXME format is ignore when Visual isn't NULL
* Cairo may change this API
*/
gsDevice = device;
image = XCreateImage(GSWINDEVICE->display,
DefaultVisual(GSWINDEVICE->display,
DefaultScreen(GSWINDEVICE->display)),
24, ZPixmap, 0, NULL,
GSWINDEVICE->xframe.size.width,
GSWINDEVICE->xframe.size.height,
8, 0);
image->data = malloc(image->height * image->bytes_per_line);
NSLog(@"alloc %d %d %d",image->width,image->height,(image->height * image->bytes_per_line));
return self;
}
- (void) setAsTargetOfCairo: (cairo_t *)ct
{
cairo_set_target_image(ct, image->data, CAIRO_FORMAT_ARGB32,
image->width, image->height, image->width*4);
}
- (NSSize) size
{
return GSWINDEVICE->xframe.size;
}
@end

379
configure vendored
View file

@ -309,7 +309,7 @@ ac_includes_default="\
# include <unistd.h>
#endif"
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os CPP X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS EGREP WITH_XFT WITH_GLX WITH_WRASTER GRAPHIC_LIBS GRAPHIC_CFLAGS GRAPHIC_LFLAGS BUILD_SERVER BUILD_GRAPHICS BACKEND_NAME LIBOBJS LTLIBOBJS'
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os CPP X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS EGREP WITH_XFT WITH_GLX WITH_GLITZ WITH_WRASTER GRAPHIC_LIBS GRAPHIC_CFLAGS GRAPHIC_LFLAGS BUILD_SERVER BUILD_GRAPHICS BACKEND_NAME LIBOBJS LTLIBOBJS'
ac_subst_files=''
# Initialize some variables set by options.
@ -851,8 +851,9 @@ Optional Features:
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--disable-glx Disable GLX support
--disable-xim Disable XIM support
--disable-glitz Disable Glitz support
--enable-server=SRV Build server type: x11, win32
--enable-graphics=GPH Build graphics: xlib, xdps, winlib, art
--enable-graphics=GPH Build graphics: xlib, xdps, winlib, art, cairo
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@ -6315,6 +6316,373 @@ fi
CPPFLAGS="${save_header}"
LIBS="${save_libs}"
#--------------------------------------------------------------------
# Cairo graphics libraries
#--------------------------------------------------------------------
save_header=${CPPFLAGS}
save_libs=${LIBS}
CPPFLAGS="${GRAPHIC_CFLAGS} ${GRAPHIC_LFLAGS} ${CPPFLAGS}"
LIBS="${GRAPHIC_LIBS} ${LIBS}"
CAIRO_LIBS="`pkg-config --libs cairo`"
CAIRO_CFLAGS="`pkg-config --cflags cairo`"
CPPFLAGS="${CPPFLAGS} ${CAIRO_CFLAGS}"
LIBS="${LIBS} ${CAIRO_LIBS}"
if test "${ac_cv_header_cairo_h+set}" = set; then
echo "$as_me:$LINENO: checking for cairo.h" >&5
echo $ECHO_N "checking for cairo.h... $ECHO_C" >&6
if test "${ac_cv_header_cairo_h+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
fi
echo "$as_me:$LINENO: result: $ac_cv_header_cairo_h" >&5
echo "${ECHO_T}$ac_cv_header_cairo_h" >&6
else
# Is the header compilable?
echo "$as_me:$LINENO: checking cairo.h usability" >&5
echo $ECHO_N "checking cairo.h usability... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
$ac_includes_default
#include <cairo.h>
_ACEOF
rm -f conftest.$ac_objext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -z "$ac_c_werror_flag"
|| test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; } &&
{ ac_try='test -s conftest.$ac_objext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
ac_header_compiler=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_header_compiler=no
fi
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
echo "${ECHO_T}$ac_header_compiler" >&6
# Is the header present?
echo "$as_me:$LINENO: checking cairo.h presence" >&5
echo $ECHO_N "checking cairo.h presence... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <cairo.h>
_ACEOF
if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
(eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } >/dev/null; then
if test -s conftest.err; then
ac_cpp_err=$ac_c_preproc_warn_flag
ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
else
ac_cpp_err=
fi
else
ac_cpp_err=yes
fi
if test -z "$ac_cpp_err"; then
ac_header_preproc=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_header_preproc=no
fi
rm -f conftest.err conftest.$ac_ext
echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
echo "${ECHO_T}$ac_header_preproc" >&6
# So? What about this header?
case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
yes:no: )
{ echo "$as_me:$LINENO: WARNING: cairo.h: accepted by the compiler, rejected by the preprocessor!" >&5
echo "$as_me: WARNING: cairo.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
{ echo "$as_me:$LINENO: WARNING: cairo.h: proceeding with the compiler's result" >&5
echo "$as_me: WARNING: cairo.h: proceeding with the compiler's result" >&2;}
ac_header_preproc=yes
;;
no:yes:* )
{ echo "$as_me:$LINENO: WARNING: cairo.h: present but cannot be compiled" >&5
echo "$as_me: WARNING: cairo.h: present but cannot be compiled" >&2;}
{ echo "$as_me:$LINENO: WARNING: cairo.h: check for missing prerequisite headers?" >&5
echo "$as_me: WARNING: cairo.h: check for missing prerequisite headers?" >&2;}
{ echo "$as_me:$LINENO: WARNING: cairo.h: see the Autoconf documentation" >&5
echo "$as_me: WARNING: cairo.h: see the Autoconf documentation" >&2;}
{ echo "$as_me:$LINENO: WARNING: cairo.h: section \"Present But Cannot Be Compiled\"" >&5
echo "$as_me: WARNING: cairo.h: section \"Present But Cannot Be Compiled\"" >&2;}
{ echo "$as_me:$LINENO: WARNING: cairo.h: proceeding with the preprocessor's result" >&5
echo "$as_me: WARNING: cairo.h: proceeding with the preprocessor's result" >&2;}
{ echo "$as_me:$LINENO: WARNING: cairo.h: in the future, the compiler will take precedence" >&5
echo "$as_me: WARNING: cairo.h: in the future, the compiler will take precedence" >&2;}
(
cat <<\_ASBOX
## ------------------------------------------ ##
## Report this to the AC_PACKAGE_NAME lists. ##
## ------------------------------------------ ##
_ASBOX
) |
sed "s/^/$as_me: WARNING: /" >&2
;;
esac
echo "$as_me:$LINENO: checking for cairo.h" >&5
echo $ECHO_N "checking for cairo.h... $ECHO_C" >&6
if test "${ac_cv_header_cairo_h+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
ac_cv_header_cairo_h=$ac_header_preproc
fi
echo "$as_me:$LINENO: result: $ac_cv_header_cairo_h" >&5
echo "${ECHO_T}$ac_cv_header_cairo_h" >&6
fi
if test $ac_cv_header_cairo_h = yes; then
have_cairo=yes
else
have_cairo=no
fi
if test "$have_cairo" = yes; then
GRAPHIC_LIBS="$CAIRO_LIBS $GRAPHIC_LIBS"
GRAPHIC_CFLAGS="$CAIRO_CFLAGS $GRAPHIC_CFLAGS"
fi
CPPFLAGS="${save_header}"
LIBS="${save_libs}"
#--------------------------------------------------------------------
# Glitz-GLX libraries
#--------------------------------------------------------------------
WITH_GLITZ=no
# Check whether --enable-glx or --disable-glx was given.
if test "${enable_glx+set}" = set; then
enableval="$enable_glx"
else
enable_glx=yes
fi;
if test "x$enable_glx" = "xyes"; then
# Check whether --enable-glitz or --disable-glitz was given.
if test "${enable_glitz+set}" = set; then
enableval="$enable_glitz"
else
enable_glitz=yes
fi;
if test "x$enable_glitz" = "xyes"; then
WITH_GLITZ=yes
save_header=${CPPFLAGS}
save_libs=${LIBS}
CPPFLAGS="${GRAPHIC_CFLAGS} ${GRAPHIC_LFLAGS} ${CPPFLAGS}"
LIBS="${GRAPHIC_LIBS} ${LIBS}"
GLITZ_GLX_LIBS="`pkg-config --libs glitz-glx`"
GLITZ_GLX_CFLAGS="`pkg-config --cflags glitz-glx`"
CPPFLAGS="${CPPFLAGS} ${GLITZ_GLX_CFLAGS}"
LIBS="${LIBS} ${GLITZ_GLX_LIBS}"
if test "${ac_cv_header_glitz_glx_h+set}" = set; then
echo "$as_me:$LINENO: checking for glitz-glx.h" >&5
echo $ECHO_N "checking for glitz-glx.h... $ECHO_C" >&6
if test "${ac_cv_header_glitz_glx_h+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
fi
echo "$as_me:$LINENO: result: $ac_cv_header_glitz_glx_h" >&5
echo "${ECHO_T}$ac_cv_header_glitz_glx_h" >&6
else
# Is the header compilable?
echo "$as_me:$LINENO: checking glitz-glx.h usability" >&5
echo $ECHO_N "checking glitz-glx.h usability... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
$ac_includes_default
#include <glitz-glx.h>
_ACEOF
rm -f conftest.$ac_objext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -z "$ac_c_werror_flag"
|| test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; } &&
{ ac_try='test -s conftest.$ac_objext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
ac_header_compiler=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_header_compiler=no
fi
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
echo "${ECHO_T}$ac_header_compiler" >&6
# Is the header present?
echo "$as_me:$LINENO: checking glitz-glx.h presence" >&5
echo $ECHO_N "checking glitz-glx.h presence... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <glitz-glx.h>
_ACEOF
if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
(eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } >/dev/null; then
if test -s conftest.err; then
ac_cpp_err=$ac_c_preproc_warn_flag
ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
else
ac_cpp_err=
fi
else
ac_cpp_err=yes
fi
if test -z "$ac_cpp_err"; then
ac_header_preproc=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_header_preproc=no
fi
rm -f conftest.err conftest.$ac_ext
echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
echo "${ECHO_T}$ac_header_preproc" >&6
# So? What about this header?
case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
yes:no: )
{ echo "$as_me:$LINENO: WARNING: glitz-glx.h: accepted by the compiler, rejected by the preprocessor!" >&5
echo "$as_me: WARNING: glitz-glx.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
{ echo "$as_me:$LINENO: WARNING: glitz-glx.h: proceeding with the compiler's result" >&5
echo "$as_me: WARNING: glitz-glx.h: proceeding with the compiler's result" >&2;}
ac_header_preproc=yes
;;
no:yes:* )
{ echo "$as_me:$LINENO: WARNING: glitz-glx.h: present but cannot be compiled" >&5
echo "$as_me: WARNING: glitz-glx.h: present but cannot be compiled" >&2;}
{ echo "$as_me:$LINENO: WARNING: glitz-glx.h: check for missing prerequisite headers?" >&5
echo "$as_me: WARNING: glitz-glx.h: check for missing prerequisite headers?" >&2;}
{ echo "$as_me:$LINENO: WARNING: glitz-glx.h: see the Autoconf documentation" >&5
echo "$as_me: WARNING: glitz-glx.h: see the Autoconf documentation" >&2;}
{ echo "$as_me:$LINENO: WARNING: glitz-glx.h: section \"Present But Cannot Be Compiled\"" >&5
echo "$as_me: WARNING: glitz-glx.h: section \"Present But Cannot Be Compiled\"" >&2;}
{ echo "$as_me:$LINENO: WARNING: glitz-glx.h: proceeding with the preprocessor's result" >&5
echo "$as_me: WARNING: glitz-glx.h: proceeding with the preprocessor's result" >&2;}
{ echo "$as_me:$LINENO: WARNING: glitz-glx.h: in the future, the compiler will take precedence" >&5
echo "$as_me: WARNING: glitz-glx.h: in the future, the compiler will take precedence" >&2;}
(
cat <<\_ASBOX
## ------------------------------------------ ##
## Report this to the AC_PACKAGE_NAME lists. ##
## ------------------------------------------ ##
_ASBOX
) |
sed "s/^/$as_me: WARNING: /" >&2
;;
esac
echo "$as_me:$LINENO: checking for glitz-glx.h" >&5
echo $ECHO_N "checking for glitz-glx.h... $ECHO_C" >&6
if test "${ac_cv_header_glitz_glx_h+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
ac_cv_header_glitz_glx_h=$ac_header_preproc
fi
echo "$as_me:$LINENO: result: $ac_cv_header_glitz_glx_h" >&5
echo "${ECHO_T}$ac_cv_header_glitz_glx_h" >&6
fi
if test $ac_cv_header_glitz_glx_h = yes; then
have_glitz_glx=yes
else
have_glitz_glx=no
fi
if test "$have_glitz_glx" = yes; then
GRAPHIC_LIBS="$GLITZ_GLX_LIBS $GRAPHIC_LIBS"
GRAPHIC_CFLAGS="$GLITZ_GLX_CFLAGS $GRAPHIC_CFLAGS"
fi
CPPFLAGS="${save_header}"
LIBS="${save_libs}"
cat >>confdefs.h <<\_ACEOF
#define HAVE_GLITZ_GLX 1
_ACEOF
cat >>confdefs.h <<\_ACEOF
#define USE_GLITZ 1
_ACEOF
fi
fi
#--------------------------------------------------------------------
# Set definitions
#--------------------------------------------------------------------
@ -6388,6 +6756,12 @@ echo "$as_me: error: can't find libart, required for graphics=art!" >&2;}
fi
elif test x"$BUILD_GRAPHICS" = "xwinlib"; then
GRAPHIC_LIBS="$WIN32_LIBS $GRAPHIC_LIBS"
elif test x"$BUILD_GRAPHICS" = "xcairo"; then
if test "$have_cairo" = no; then
{ { echo "$as_me:$LINENO: error: can't find cairo, required for graphics=cairo!" >&5
echo "$as_me: error: can't find cairo, required for graphics=cairo!" >&2;}
{ (exit 1); exit 1; }; }
fi
fi
@ -7053,6 +7427,7 @@ s,@X_EXTRA_LIBS@,$X_EXTRA_LIBS,;t t
s,@EGREP@,$EGREP,;t t
s,@WITH_XFT@,$WITH_XFT,;t t
s,@WITH_GLX@,$WITH_GLX,;t t
s,@WITH_GLITZ@,$WITH_GLITZ,;t t
s,@WITH_WRASTER@,$WITH_WRASTER,;t t
s,@GRAPHIC_LIBS@,$GRAPHIC_LIBS,;t t
s,@GRAPHIC_CFLAGS@,$GRAPHIC_CFLAGS,;t t

View file

@ -287,6 +287,71 @@ fi
CPPFLAGS="${save_header}"
LIBS="${save_libs}"
#--------------------------------------------------------------------
# Cairo graphics libraries
#--------------------------------------------------------------------
save_header=${CPPFLAGS}
save_libs=${LIBS}
CPPFLAGS="${GRAPHIC_CFLAGS} ${GRAPHIC_LFLAGS} ${CPPFLAGS}"
LIBS="${GRAPHIC_LIBS} ${LIBS}"
CAIRO_LIBS="`pkg-config --libs cairo`"
CAIRO_CFLAGS="`pkg-config --cflags cairo`"
CPPFLAGS="${CPPFLAGS} ${CAIRO_CFLAGS}"
LIBS="${LIBS} ${CAIRO_LIBS}"
AC_CHECK_HEADER(cairo.h,have_cairo=yes, have_cairo=no)
if test "$have_cairo" = yes; then
GRAPHIC_LIBS="$CAIRO_LIBS $GRAPHIC_LIBS"
GRAPHIC_CFLAGS="$CAIRO_CFLAGS $GRAPHIC_CFLAGS"
fi
CPPFLAGS="${save_header}"
LIBS="${save_libs}"
#--------------------------------------------------------------------
# Glitz-GLX libraries
#--------------------------------------------------------------------
WITH_GLITZ=no
AC_ARG_ENABLE(glx,
[ --disable-glx Disable GLX support],,
enable_glx=yes)
if test "x$enable_glx" = "xyes"; then
AC_ARG_ENABLE(glitz,
[ --disable-glitz Disable Glitz support],,
enable_glitz=yes)
if test "x$enable_glitz" = "xyes"; then
WITH_GLITZ=yes
save_header=${CPPFLAGS}
save_libs=${LIBS}
CPPFLAGS="${GRAPHIC_CFLAGS} ${GRAPHIC_LFLAGS} ${CPPFLAGS}"
LIBS="${GRAPHIC_LIBS} ${LIBS}"
GLITZ_GLX_LIBS="`pkg-config --libs glitz-glx`"
GLITZ_GLX_CFLAGS="`pkg-config --cflags glitz-glx`"
CPPFLAGS="${CPPFLAGS} ${GLITZ_GLX_CFLAGS}"
LIBS="${LIBS} ${GLITZ_GLX_LIBS}"
AC_CHECK_HEADER(glitz-glx.h,have_glitz_glx=yes, have_glitz_glx=no)
if test "$have_glitz_glx" = yes; then
GRAPHIC_LIBS="$GLITZ_GLX_LIBS $GRAPHIC_LIBS"
GRAPHIC_CFLAGS="$GLITZ_GLX_CFLAGS $GRAPHIC_CFLAGS"
fi
CPPFLAGS="${save_header}"
LIBS="${save_libs}"
AC_SUBST(WITH_GLITZ)
AC_DEFINE(HAVE_GLITZ_GLX,1,[Define if you have glitz])
AC_DEFINE(USE_GLITZ,1,[Define to enable glitz support])
fi
fi
#--------------------------------------------------------------------
# Set definitions
#--------------------------------------------------------------------
@ -310,7 +375,7 @@ AC_ARG_ENABLE(server,
[ --enable-server=SRV Build server type: x11, win32],,
enable_server=$BUILD_SERVER)
AC_ARG_ENABLE(graphics,
[ --enable-graphics=GPH Build graphics: xlib, xdps, winlib, art],,
[ --enable-graphics=GPH Build graphics: xlib, xdps, winlib, art, cairo],,
enable_graphics="$BUILD_GRAPHICS")
BUILD_SERVER=$enable_server
@ -338,6 +403,10 @@ elif test x"$BUILD_GRAPHICS" = "xart"; then
fi
elif test x"$BUILD_GRAPHICS" = "xwinlib"; then
GRAPHIC_LIBS="$WIN32_LIBS $GRAPHIC_LIBS"
elif test x"$BUILD_GRAPHICS" = "xcairo"; then
if test "$have_cairo" = no; then
AC_MSG_ERROR([can't find cairo, required for graphics=cairo!])
fi
fi
AH_TOP([