diff --git a/ChangeLog b/ChangeLog index 8dc3fbb..656d2fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-08-03 Fred Kiefer + + * Header/cairo/*: + * Source/cairo/*: + * Source/GSBackend.m: + * configure.ac: + * configure: + Added cairo backend from Banlu Kemiyatorn . + 2004-07-30 15:52 Alexander Malmberg * Headers/gsc/GSCStateOps.h, Source/gsc/GSContext.m, diff --git a/Headers/cairo/CairoContext.h b/Headers/cairo/CairoContext.h new file mode 100644 index 0000000..8cc7a6c --- /dev/null +++ b/Headers/cairo/CairoContext.h @@ -0,0 +1,42 @@ +/* + * CairoContext.h + * + * Copyright (C) 2003 Free Software Foundation, Inc. + * August 31, 2003 + * Written by Banlu Kemiyatorn + * 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 diff --git a/Headers/cairo/CairoDevice.h b/Headers/cairo/CairoDevice.h new file mode 100644 index 0000000..44559a5 --- /dev/null +++ b/Headers/cairo/CairoDevice.h @@ -0,0 +1,87 @@ +/* + * CairoFontInfo.h + * + * Copyright (C) 2003 Free Software Foundation, Inc. + * September 10, 2003 + * Written by Banlu Kemiyatorn + * 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 + +@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 diff --git a/Headers/cairo/CairoFaceInfo.h b/Headers/cairo/CairoFaceInfo.h new file mode 100644 index 0000000..32a3704 --- /dev/null +++ b/Headers/cairo/CairoFaceInfo.h @@ -0,0 +1,74 @@ +/* + * CairoFaceInfo.h + + * Copyright (C) 2003 Free Software Foundation, Inc. + * August 31, 2003 + * Written by Banlu Kemiyatorn + * Base on code by Alexander 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. + */ + +#ifndef CAIROFACEINFO_H +#define CAIROFACEINFO_H +#include +#include + +@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 diff --git a/Headers/cairo/CairoFontEnumerator.h b/Headers/cairo/CairoFontEnumerator.h new file mode 100644 index 0000000..1674db1 --- /dev/null +++ b/Headers/cairo/CairoFontEnumerator.h @@ -0,0 +1,32 @@ +/* + * CairoFontEnumerator.h + + * Copyright (C) 2003 Free Software Foundation, Inc. + * August 31, 2003 + * Written by Banlu Kemiyatorn + * 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 +#include + +@interface CairoFontEnumerator : GSFontEnumerator +@end + +#endif diff --git a/Headers/cairo/CairoFontInfo.h b/Headers/cairo/CairoFontInfo.h new file mode 100644 index 0000000..dc519b2 --- /dev/null +++ b/Headers/cairo/CairoFontInfo.h @@ -0,0 +1,56 @@ +/* + * CairoFontInfo.h + + * Copyright (C) 2003 Free Software Foundation, Inc. + * August 31, 2003 + * Written by Banlu Kemiyatorn + * 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 +#include + +#include "cairo/CairoFontEnumerator.h" +#include "cairo/CairoFontManager.h" + +#include + +@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 diff --git a/Headers/cairo/CairoFontManager.h b/Headers/cairo/CairoFontManager.h new file mode 100644 index 0000000..476362c --- /dev/null +++ b/Headers/cairo/CairoFontManager.h @@ -0,0 +1,35 @@ +/* + * CairoFontManager.h + + * Copyright (C) 2003 Free Software Foundation, Inc. + * August 31, 2003 + * Written by Banlu Kemiyatorn + * Base on code by Alexander 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. + */ + +#ifndef CAIROFONTMANAGER_H +#define CAIROFONTMANAGER_H +#include "CairoFaceInfo.h" +#include + +@interface CairoFontManager : NSObject +{ +} + ++ (NSArray *) allFontNames; ++ (CairoFaceInfo *) fontWithName: (NSString *)name; +@end +#endif diff --git a/Headers/cairo/CairoFreeTypeFontInfo.h b/Headers/cairo/CairoFreeTypeFontInfo.h new file mode 100644 index 0000000..7a61922 --- /dev/null +++ b/Headers/cairo/CairoFreeTypeFontInfo.h @@ -0,0 +1,45 @@ +/* + * CairoFreeTypeFontInfo.h + * + * Copyright (C) 2003 Free Software Foundation, Inc. + * April 27, 2004 + * Written by Banlu Kemiyatorn + * 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 +#include "nfont/GSNFont.h" +#include "cairo/CairoFontInfo.h" + +#include + +#define CACHE_SIZE 257 + +@interface CairoFreeTypeFontInfo : CairoFontInfo +{ +@public + /* We will implement FTC in cairo instead + FTC_ImageTypeRec _imgd; + + FTC_ImageTypeRec _advancementImgd; + */ +} +@end + +#endif diff --git a/Headers/cairo/CairoGState.h b/Headers/cairo/CairoGState.h new file mode 100644 index 0000000..7c60e81 --- /dev/null +++ b/Headers/cairo/CairoGState.h @@ -0,0 +1,174 @@ +/* + Copyright (C) 2004 Free Software Foundation, Inc. + + Author: Banlu Kemiyatorn + + 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 +#include +#include + +@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 + diff --git a/Headers/cairo/CairoSurface.h b/Headers/cairo/CairoSurface.h new file mode 100644 index 0000000..d4d3ade --- /dev/null +++ b/Headers/cairo/CairoSurface.h @@ -0,0 +1,53 @@ +/* + Copyright (C) 2002 Free Software Foundation, Inc. + + Author: Banlu Kemiyatorn + + 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 +#include + +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 + diff --git a/Headers/cairo/XGCairoGlitzSurface.h b/Headers/cairo/XGCairoGlitzSurface.h new file mode 100644 index 0000000..88efc32 --- /dev/null +++ b/Headers/cairo/XGCairoGlitzSurface.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2004 Free Software Foundation, Inc. + + Author: Banlu Kemiyatorn + + 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 + +@interface XGCairoGlitzSurface : CairoSurface +{ +} +@end + + +#endif + diff --git a/Headers/cairo/XGCairoSurface.h b/Headers/cairo/XGCairoSurface.h new file mode 100644 index 0000000..0b1ef45 --- /dev/null +++ b/Headers/cairo/XGCairoSurface.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2002 Free Software Foundation, Inc. + + Author: Banlu Kemiyatorn + + 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 + diff --git a/Headers/cairo/XGCairoXImageSurface.h b/Headers/cairo/XGCairoXImageSurface.h new file mode 100644 index 0000000..346369a --- /dev/null +++ b/Headers/cairo/XGCairoXImageSurface.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2002 Free Software Foundation, Inc. + + Author: Banlu Kemiyatorn + + 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 + diff --git a/Source/GSBackend.m b/Source/GSBackend.m index 84e2b0c..304221a 100644 --- a/Source/GSBackend.m +++ b/Source/GSBackend.m @@ -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]; diff --git a/Source/cairo/CairoContext.m b/Source/cairo/CairoContext.m new file mode 100644 index 0000000..b97e1b1 --- /dev/null +++ b/Source/cairo/CairoContext.m @@ -0,0 +1,153 @@ +/* + * CairoContext.m + + * Copyright (C) 2003 Free Software Foundation, Inc. + * August 31, 2003 + * Written by Banlu Kemiyatorn + * 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 diff --git a/Source/cairo/CairoDevice.m b/Source/cairo/CairoDevice.m new file mode 100644 index 0000000..c499774 --- /dev/null +++ b/Source/cairo/CairoDevice.m @@ -0,0 +1,401 @@ +/* + * CairoDevice.m + * + * Copyright (C) 2003 Free Software Foundation, Inc. + * September 10, 2003 + * Written by Banlu Kemiyatorn + * 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 +#include "cairo/CairoDevice.h" +#include +#include + +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 + diff --git a/Source/cairo/CairoFaceInfo.m b/Source/cairo/CairoFaceInfo.m new file mode 100644 index 0000000..5aad8d3 --- /dev/null +++ b/Source/cairo/CairoFaceInfo.m @@ -0,0 +1,133 @@ +/* + * CairoFaceInfo.m + * + * Copyright (C) 2003 Free Software Foundation, Inc. + * August 31, 2003 + * Written by Banlu Kemiyatorn + * 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 diff --git a/Source/cairo/CairoFontEnumerator.m b/Source/cairo/CairoFontEnumerator.m new file mode 100644 index 0000000..1c14875 --- /dev/null +++ b/Source/cairo/CairoFontEnumerator.m @@ -0,0 +1,107 @@ +/* + * CairoFontEnumerator.m + * + * Copyright (C) 2003 Free Software Foundation, Inc. + * August 31, 2003 + * Written by Banlu Kemiyatorn + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 diff --git a/Source/cairo/CairoFontInfo.m b/Source/cairo/CairoFontInfo.m new file mode 100644 index 0000000..980a6d4 --- /dev/null +++ b/Source/cairo/CairoFontInfo.m @@ -0,0 +1,307 @@ +/* + * CairoFontInfo.m + * + * Copyright (C) 2003 Free Software Foundation, Inc. + * August 31, 2003 + * Written by Banlu Kemiyatorn + * 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 +#include +#include + +@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 diff --git a/Source/cairo/CairoFontManager.m b/Source/cairo/CairoFontManager.m new file mode 100644 index 0000000..908f34d --- /dev/null +++ b/Source/cairo/CairoFontManager.m @@ -0,0 +1,109 @@ +/* + * CairoFontManager.m + * + * Copyright (C) 2003 Free Software Foundation, Inc. + * August 31, 2003 + * Written by Banlu Kemiyatorn + * 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 diff --git a/Source/cairo/CairoFreeTypeFontInfo.m b/Source/cairo/CairoFreeTypeFontInfo.m new file mode 100644 index 0000000..e780342 --- /dev/null +++ b/Source/cairo/CairoFreeTypeFontInfo.m @@ -0,0 +1,405 @@ +/* + * CairoFontInfo.m + * + * Copyright (C) 2003 Free Software Foundation, Inc. + * April 27, 2004 + * Written by Banlu Kemiyatorn + * 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 +@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 diff --git a/Source/cairo/CairoGState.m b/Source/cairo/CairoGState.m new file mode 100644 index 0000000..fc56065 --- /dev/null +++ b/Source/cairo/CairoGState.m @@ -0,0 +1,1083 @@ +/* + * CairoGState.m + + * Copyright (C) 2003 Free Software Foundation, Inc. + * August 31, 2003 + * Written by Banlu Kemiyatorn + * 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 +#include +#include "cairo/CairoGState.h" +#include "cairo/CairoFontInfo.h" +#include "cairo/CairoSurface.h" +#include "cairo/CairoContext.h" +#include "NSBezierPathCairo.h" +#include + +#define NEEDS_CSMK() NSLog(@"Need CSMK %@ %s", [self description], sel_get_name(_cmd)) +#define FIXME() NSLog(@":::FIXME::: %@ %s", [self description], sel_get_name(_cmd)) + + +static cairo_matrix_t *local_matrix; + +/* Be warned that CairoGState didn't derived GSGState */ +@implementation CairoGState + ++ (void) initialize +{ + local_matrix = cairo_matrix_create(); +} + +- (void) forwardInvocation: (NSInvocation *)anInvocation +{ + /* only for trapping any unknown message. */ + FIXME(); + exit(1); +} + +- (id) copyWithZone: (NSZone *)zone +{ + CairoGState *copy = (CairoGState *)NSCopyObject(self, 0, zone); + + copy->_ct = cairo_create(); + cairo_copy(copy->_ct, _ct); + /* + NSLog(@"copy state %p(%p) to %p(%p)",self, + cairo_current_target_surface(_ct), + copy, + cairo_current_target_surface(copy->_ct) + ); + */ + + RETAIN(_font); + RETAIN(_surface); + + return copy; +} + +- (id) init +{ + [self DPSinitgraphics]; + return self; +} + +- (id) initWithDrawContext: (CairoContext *)drawContext +{ + //NSLog (@"CairoGState initWithDrawContext:%@", drawContext); + [self init]; + + return self; +} + +- (void) dealloc +{ + //NSLog(@"destate %p",self); + cairo_destroy(_ct); + RELEASE(_font); + RELEASE(_surface); + + [super dealloc]; +} + +static void +_flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface) +{ + cairo_matrix_set_identity(local_matrix); + cairo_matrix_scale(local_matrix, 1, -1); + + if (surface != nil) + { + cairo_matrix_translate(local_matrix, 0, -[surface size].height); + } + cairo_set_matrix(ct, local_matrix); +} + +- (void) GSCurrentDevice: (void **)device: (int *)x : (int *)y +{ + if (x) + *x = 0; + if (y) + *y = 0; + if (device) + { + if (_surface) + { + *device = _surface->gsDevice; + } + else + { + *device = NULL; + NSLog(@":::FIXME::: surface isn't set. %@ %s", [self description], + sel_get_name(_cmd)); + } + } +} + +- (void) GSSetDevice: (void *)device : (int)x : (int)y +{ + CairoInfo cairo_info; + + ASSIGN(_surface, [CairoSurface surfaceForDevice: device depthInfo: &cairo_info]); + _offset = NSMakePoint(x, y); + NSLog(@"before: surface %p on state %p", + cairo_current_target_surface(_ct), self); + [_surface setAsTargetOfCairo: _ct]; + _flipCairoSurfaceMatrix(_ct, _surface); + NSLog(@"after: surface %p on state %p %@", + cairo_current_target_surface (_ct), self, + NSStringFromSize([_surface size])); +} + +/* This shall be invoked by Context */ +/* +-(void) _setSurface: (CairoSurface *)surface +{ + ASSIGN(_surface, surface); +} +*/ + +@end + +@implementation CairoGState (Ops) +/* + * Color operations + */ +- (void) DPScurrentalpha: (float *)a +{ + *a = cairo_current_alpha(_ct); +} + +- (void) DPScurrentcmykcolor: (float *)c : (float *)m : (float *)y :(float *)k +{ + double color[3]; + + cairo_current_rgb_color(_ct, &color[0], &color[1], &color[2]); + *c = 1 - color[0]; + *m = 1 - color[1]; + *y = 1 - color[2]; + *k = 0; +} + +- (void) DPScurrentgray: (float *)gray +{ + NEEDS_CSMK(); +} + +- (void) DPScurrenthsbcolor: (float *)h : (float *)s : (float *)b +{ + NEEDS_CSMK(); +} + +- (void) DPScurrentrgbcolor: (float *)r : (float *)g : (float *)b +{ + double dr, dg, db; + + cairo_current_rgb_color(_ct, &dr, &dg, &db); + *r = dr; + *g = dg; + *b = db; +} + +- (void) DPSsetalpha: (float)a +{ + cairo_set_alpha(_ct, a); +} + +- (void) DPSsetcmykcolor: (float)c : (float)m : (float)y : (float)k +{ + NEEDS_CSMK(); +} + +- (void) DPSsetgray: (float)gray +{ + cairo_set_rgb_color(_ct, gray, gray, gray); +} + +- (void) DPSsethsbcolor: (float)h : (float)s : (float)b +{ + NSColor *color; + float red, green, blue, alpha; + + color = [NSColor colorWithCalibratedHue: h + saturation: s + brightness: b + alpha: 1.0]; + [color getRed: &red + green: &green + blue: &blue + alpha: &alpha]; + [self DPSsetrgbcolor: red : green : blue]; +} + +- (void) DPSsetrgbcolor: (float)r : (float)g: (float)b +{ + cairo_set_rgb_color(_ct, r, g, b); +} + +- (void) GSSetFillColorspace: (void *)spaceref +{ + FIXME(); +} + +- (void) GSSetStrokeColorspace: (void *)spaceref +{ + FIXME(); +} + +- (void) GSSetFillColor: (const float *)values +{ + FIXME(); +} + +- (void) GSSetStrokeColor: (const float *)values +{ + FIXME(); +} + +/* + * Text operations + */ + +- (void) DPSashow: (float)x : (float)y : (const char *)s +{ + FIXME(); +} + +- (void) DPSawidthshow: (float)cx : (float)cy : (int)c : (float)ax + : (float)ay : (const char *)s +{ + FIXME(); +} + +- (void) DPScharpath: (const char *)s : (int)b +{ + char *c = malloc(b + 1); + + memcpy(c, s, b); + c[b + 1] = 0; + + cairo_text_path(_ct, c); + free (c); +} + +- (void) DPSshow: (const char *)s +{ + cairo_show_text(_ct, s); +} + +- (void) DPSwidthshow: (float)x : (float)y : (int)c : (const char *)s +{ + FIXME(); +} + +- (void) DPSxshow: (const char *)s : (const float *)numarray : (int)size +{ + FIXME(); +} + +- (void) DPSxyshow: (const char *)s : (const float *)numarray : (int)size +{ + FIXME(); +} + +- (void) DPSyshow: (const char *)s : (const float *)numarray : (int)size +{ + FIXME(); +} + +- (void) GSSetCharacterSpacing: (float)extra +{ + FIXME(); +} + +- (void) GSSetFont: (GSFontInfo *)fontref +{ + if (_font == fontref) + { + return; + } + + ASSIGN(_font, fontref); + cairo_set_font(_ct, ((CairoFontInfo *)_font)->xrFont); +} + +- (void) GSSetFontSize: (float)size +{ + FIXME(); +} + +- (NSAffineTransform *) GSGetTextCTM +{ + return [self GSCurrentCTM]; +} + +- (NSPoint) GSGetTextPosition +{ + float x, y; + + [self DPScurrentpoint: &x : &y]; + return NSMakePoint(x, y); +} + +- (void) GSSetTextCTM: (NSAffineTransform *)ctm +{ + [self GSSetCTM: ctm]; +} + +- (void) GSSetTextDrawingMode: (GSTextDrawingMode)mode +{ + FIXME(); +} + +- (void) GSSetTextPosition: (NSPoint)loc +{ + FIXME(); +} + +- (void) GSShowText: (const char *)string : (size_t)length +{ + FIXME(); +} + +- (void) GSShowGlyphs: (const NSGlyph *)glyphs : (size_t)length +{ + static cairo_glyph_t *cglyphs = NULL; + static int maxlength = 0; + size_t i; + double dx, dy; + cairo_text_extents_t gext; + + cairo_current_point(_ct, &dx, &dy); + + /* experimental, should do this in fontinfo */ + if (length > maxlength) + { + maxlength = length; + cglyphs = realloc(cglyphs, sizeof(cairo_glyph_t) * maxlength); + } + + for (i = 0; i < length; i++) + { + cglyphs[i].index = glyphs[i] + -29; /* experimental */ + cglyphs[i].x = dx; + cglyphs[i].y = dy; + cairo_glyph_extents(_ct, cglyphs + i, 1, &gext); + dx += gext.x_advance; + dy += gext.y_advance; + } + + cairo_show_glyphs(_ct, cglyphs, length); +} + +/* + * GState operations + */ + +- (void) DPSinitgraphics +{ + DESTROY(_font); + + if (_ct) + { + cairo_destroy(_ct); + } + _ct = cairo_create(); + /* Cairo's default line width is 2.0 */ + _flipCairoSurfaceMatrix(_ct, _surface); + //NSLog(@"in flip %p (%p)", self, cairo_current_target_surface(_ct)); + cairo_set_line_width(_ct, 1.0); +} + +- (void) DPScurrentflat: (float *)flatness +{ + *flatness = cairo_current_tolerance(_ct); +} + +- (void) DPScurrentlinecap: (int *)linecap +{ + cairo_line_cap_t lc; + + lc = cairo_current_line_cap(_ct); + *linecap = lc; + /* + switch (lc) + { + case CAIRO_LINE_CAP_BUTT: + *linecap = 0; + break; + case CAIRO_LINE_CAP_ROUND: + *linecap = 1; + break; + case CAIRO_LINE_CAP_SQUARE: + *linecap = 2; + break; + default: + NSLog(@"ERROR Line cap unknown"); + exit(-1); + } + */ +} + +- (void) DPScurrentlinejoin: (int *)linejoin +{ + cairo_line_join_t lj; + + lj = cairo_current_line_join(_ct); + *linejoin = lj; + /* + switch (lj) + { + case CAIRO_LINE_JOIN_MITER: + *linejoin = 0; + break; + case CAIRO_LINE_JOIN_ROUND: + *linejoin = 1; + break; + case CAIRO_LINE_JOIN_BEVEL: + *linejoin = 2; + break; + default: + NSLog(@"ERROR Line join unknown"); + exit(-1); + } + */ +} + +- (void) DPScurrentlinewidth: (float *)width +{ + *width = cairo_current_line_width(_ct); +} + +- (void) DPScurrentmiterlimit: (float *)limit +{ + *limit = cairo_current_miter_limit(_ct); +} + +- (void) DPScurrentpoint: (float *)x : (float *)y +{ + double dx, dy; + + cairo_current_point(_ct, &dx, &dy); + *x = dx; + *y = dy; +} + +- (void) DPScurrentstrokeadjust: (int *)b +{ + FIXME(); +} + +- (void) DPSsetdash: (const float *)pat : (int)size : (float)offset +{ + double *dpat; + int i; + + i = size; + dpat = malloc(sizeof(double) * size); + while (i) + { + i--; + dpat[i] = pat[i]; + } + cairo_set_dash(_ct, dpat, size, offset); + free(dpat); +} + +- (void) DPSsetflat: (float)flatness +{ + cairo_set_tolerance(_ct, flatness); +} + +- (void) DPSsetlinecap: (int)linecap +{ + cairo_set_line_cap(_ct, (cairo_line_cap_t)linecap); +} + +- (void) DPSsetlinejoin: (int)linejoin +{ + cairo_set_line_join(_ct, (cairo_line_join_t)linejoin); +} + +- (void) DPSsetlinewidth: (float)width +{ + cairo_set_line_width(_ct, width); +} + +- (void) DPSsetmiterlimit: (float)limit +{ + cairo_set_miter_limit(_ct, limit); +} + +- (void) DPSsetstrokeadjust: (int)b +{ + FIXME(); +} + +/* + * Matrix operations + */ + +- (void) DPSconcat: (const float *)m +{ + cairo_matrix_set_affine(local_matrix, m[0], m[1], m[2], m[3], m[4], m[5]); + cairo_concat_matrix(_ct, local_matrix); +} + +- (void) DPSinitmatrix +{ + cairo_matrix_set_identity(local_matrix); + cairo_set_matrix(_ct, local_matrix); + _flipCairoSurfaceMatrix(_ct, _surface); +} + +- (void) DPSrotate: (float)angle +{ + cairo_rotate(_ct, angle); +} + +- (void) DPSscale: (float)x : (float)y +{ + cairo_scale(_ct, x, y); +} + +- (void) DPStranslate: (float)x : (float)y +{ + cairo_translate(_ct, x, y); +} + +- (void) _flipCairoFont +{ + cairo_matrix_set_identity(local_matrix); + cairo_matrix_scale(local_matrix, 1, -1); + cairo_transform_font(_ct, local_matrix); +} + +/* +static void +_log_matrix(cairo_t * ct) +{ + double da, db, dc, dd, dtx, dty; + + cairo_current_matrix(ct, local_matrix); + cairo_matrix_get_affine(local_matrix, &da, &db, &dc, &dd, &dtx, &dty); + + NSLog(@"%g %g %g %g %g %g", da, db, dc, dd, dtx, dty); +} +*/ + +- (NSAffineTransform *) GSCurrentCTM +{ + NSAffineTransform *transform; + NSAffineTransformStruct tstruct; + double da, db, dc, dd, dtx, dty; + + transform = [NSAffineTransform transform]; + cairo_current_matrix(_ct, local_matrix); + cairo_matrix_get_affine(local_matrix, &da, &db, &dc, &dd, &dtx, &dty); + tstruct.m11 = da; + tstruct.m12 = db; + tstruct.m21 = dc; + tstruct.m22 = dd; + tstruct.tX = dtx; + tstruct.tY = dty; + [transform setTransformStruct:tstruct]; + return transform; +} + +- (void) GSSetCTM: (NSAffineTransform *)ctm +{ + NSAffineTransformStruct tstruct; + + tstruct = [ctm transformStruct]; + cairo_matrix_set_affine(local_matrix, + tstruct.m11, tstruct.m12, + tstruct.m21, tstruct.m22, tstruct.tX, tstruct.tY); + cairo_set_matrix(_ct, local_matrix); +} + +- (void) GSConcatCTM: (NSAffineTransform *)ctm +{ + NSAffineTransformStruct tstruct; + + tstruct = [ctm transformStruct]; + cairo_matrix_set_affine(local_matrix, + tstruct.m11, tstruct.m12, + tstruct.m21, tstruct.m22, tstruct.tX, tstruct.tY); + cairo_concat_matrix(_ct, local_matrix); +} + +/* + * Paint operations + */ + +- (NSPoint) currentPoint +{ + double dx, dy; + + //FIXME(); + cairo_current_point(_ct, &dx, &dy); + return NSMakePoint(dx, dy); +} + +- (void) DPSarc: (float)x : (float)y : (float)r : (float)angle1 : (float)angle2 +{ + //NSLog(@"%g %g", angle1, angle2); + cairo_arc(_ct, x, y, r, angle1 * M_PI / 180, angle2 * M_PI / 180); +} + +- (void) DPSarcn: (float)x : (float)y : (float)r : (float)angle1 : (float)angle2 +{ + cairo_arc_negative(_ct, x, y, r, angle1 * M_PI / 180, angle2 * M_PI / 180); +} + +- (void) DPSarct: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)r +{ + FIXME(); + /* + cairo_arc_to(_ct, x1, y1, x2, y2, r); + */ + /* + NSBezierPath *newPath; + + newPath = [[NSBezierPath alloc] init]; + if ((path != nil) && ([path elementCount] != 0)) + { + [newPath lineToPoint: [self currentPoint]]; + } + [newPath appendBezierPathWithArcFromPoint: NSMakePoint(x1, y1) + toPoint: NSMakePoint(x2, y2) + radius: r]; + [newPath transformUsingAffineTransform: ctm]; + CHECK_PATH; + [path appendBezierPath: newPath]; + RELEASE(newPath); + */ +} + +- (void) DPSclip +{ + cairo_clip(_ct); +} + +- (void) DPSclosepath +{ + cairo_close_path(_ct); +} + +- (void) DPScurveto: (float)x1 : (float)y1 : (float)x2 + : (float)y2 : (float)x3 : (float)y3 +{ + cairo_curve_to(_ct, x1, y1, x2, y2, x3, y3); +} + +- (void) DPSeoclip +{ + cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_EVEN_ODD); + cairo_clip(_ct); + cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_WINDING); +} + +- (void) DPSeofill +{ + + cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_EVEN_ODD); + cairo_fill(_ct); + cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_WINDING); +} + +- (void) DPSfill +{ + cairo_fill(_ct); +} + +static void +_c2cmoveto(void *cl, double x, double y) +{ + cairo_t *ct = (cairo_t *)cl; + cairo_move_to(ct, x, y); +} + +static void +_c2clineto(void *cl, double x, double y) +{ + cairo_t *ct = (cairo_t *)cl; + cairo_line_to(ct, x, y); +} + +static void +_c2cclosepath(void *cl) +{ + cairo_t *ct = (cairo_t *)cl; + cairo_close_path(ct); +} + +- (void) DPSflattenpath +{ + /* recheck this in plrm */ + cairo_t *fct = cairo_create(); + + cairo_copy(fct, _ct); + cairo_new_path(_ct); + cairo_current_path_flat(fct, _c2cmoveto, _c2clineto, _c2cclosepath, _ct); + cairo_destroy(fct); +} + +- (void) DPSinitclip +{ + cairo_init_clip(_ct); +} + +- (void) DPSlineto: (float)x : (float)y +{ + cairo_line_to(_ct, x, y); +} + +- (void) DPSmoveto: (float)x : (float)y +{ + cairo_move_to(_ct, x, y); +} + +- (void) DPSnewpath +{ + cairo_new_path(_ct); +} + +- (void) DPSpathbbox: (float *)llx : (float *)lly : (float *)urx : (float *)ury +{ + NSBezierPath *path = [NSBezierPath bezierPathFromCairo: _ct]; + NSRect rect = [path controlPointBounds]; + + if (llx) + *llx = NSMinX(rect); + if (lly) + *lly = NSMinY(rect); + if (urx) + *urx = NSMaxX(rect); + if (ury) + *ury = NSMaxY(rect); +} + +- (void) DPSrcurveto: (float)x1 : (float)y1 : (float)x2 + : (float)y2 : (float)x3 : (float)y3 +{ + cairo_rel_curve_to(_ct, x1, y1, x2, y2, x3, y3); +} + +- (void) DPSrectclip: (float)x : (float)y : (float)w : (float)h +{ + cairo_new_path(_ct); + cairo_move_to(_ct, x, y); + cairo_rel_line_to(_ct, w, 0); + cairo_rel_line_to(_ct, 0, h); + cairo_rel_line_to(_ct, -w, 0); + cairo_close_path(_ct); + cairo_clip(_ct); + cairo_new_path(_ct); +} + +- (void) DPSrectfill: (float)x : (float)y : (float)w : (float)h +{ + cairo_save(_ct); + cairo_new_path(_ct); + cairo_move_to(_ct, x, y); + cairo_rel_line_to(_ct, w, 0); + cairo_rel_line_to(_ct, 0, h); + cairo_rel_line_to(_ct, -w, 0); + cairo_close_path(_ct); + cairo_fill(_ct); + cairo_restore(_ct); +} + +- (void) DPSrectstroke: (float)x : (float)y : (float)w : (float)h +{ + cairo_save(_ct); + cairo_new_path(_ct); + cairo_move_to(_ct, x, y); + cairo_rel_line_to(_ct, w, 0); + cairo_rel_line_to(_ct, 0, h); + cairo_rel_line_to(_ct, -w, 0); + cairo_close_path(_ct); + cairo_stroke(_ct); + cairo_restore(_ct); +} + +- (void) DPSreversepath +{ + NSBezierPath *path = [NSBezierPath bezierPathFromCairo: _ct]; + + path = [path bezierPathByReversingPath]; + cairo_new_path(_ct); + [path appendBezierPathToCairo: _ct]; +} + +- (void) DPSrlineto: (float)x : (float)y +{ + cairo_rel_line_to(_ct, x, y); +} + +- (void) DPSrmoveto: (float)x : (float)y +{ + cairo_rel_move_to(_ct, x, y); +} + +- (void) DPSstroke +{ + cairo_stroke(_ct); +} + +- (void) GSSendBezierPath: (NSBezierPath *)path +{ + cairo_new_path(_ct); + [path appendBezierPathToCairo: _ct]; +} + +- (void) GSRectClipList: (const NSRect *)rects : (int)count +{ + int i; + NSRect union_rect; + + if (count == 0) + return; + + /* FIXME see gsc + The specification is not clear if the union of the rects + should produce the new clip rect or if the outline of all rects + should be used as clip path. + */ + union_rect = rects[0]; + for (i = 1; i < count; i++) + union_rect = NSUnionRect(union_rect, rects[i]); + + [self DPSrectclip: NSMinX(union_rect) : NSMinY(union_rect) + : NSWidth(union_rect) : NSHeight(union_rect)]; +} + +- (void) GSRectFillList: (const NSRect *)rects : (int)count +{ + int i; + + for (i = 0; i < count; i++) + { + [self DPSrectfill: NSMinX(rects[i]) : NSMinY(rects[i]) + : NSWidth(rects[i]) : NSHeight(rects[i])]; + } +} + +/* +static NSString * +_opName(NSCompositingOperation op) +{ + switch (op) + { + case NSCompositeClear: + return @"NSCompositeClear"; + + case NSCompositeCopy: + return @"NSCompositeCopy"; + + case NSCompositeSourceOver: + return @"NSCompositeSourceOver"; + + case NSCompositeSourceIn: + return @"NSCompositeSourceIn"; + + case NSCompositeSourceOut: + return @"NSCompositeSourceOut"; + + case NSCompositeSourceAtop: + return @"NSCompositeSourceAtop"; + + case NSCompositeDestinationOver: + return @"NSCompositeDestinationOver"; + + case NSCompositeDestinationIn: + return @"NSCompositeDestinationIn"; + + case NSCompositeDestinationOut: + return @"NSCompositeDestinationOut"; + + case NSCompositeDestinationAtop: + return @"NSCompositeDestinationAtop"; + + case NSCompositeXOR: + return @"NSCompositeXOR"; + + case NSCompositePlusDarker: + return @"NSCompositePlusDarker"; + + case NSCompositeHighlight: + return @"NSCompositeHighlight"; + + case NSCompositePlusLighter: + return @"NSCompositePlusLighter"; + + default: + return @"default"; + + } +} +*/ + +static void +_set_op(cairo_t * ct, NSCompositingOperation op) +{ + switch (op) + { + case NSCompositeClear: + cairo_set_operator(ct, CAIRO_OPERATOR_CLEAR); + break; + case NSCompositeCopy: + cairo_set_operator(ct, CAIRO_OPERATOR_SRC); + break; + case NSCompositeSourceOver: + cairo_set_operator(ct, CAIRO_OPERATOR_OVER); + break; + case NSCompositeSourceIn: + cairo_set_operator(ct, CAIRO_OPERATOR_IN); + break; + case NSCompositeSourceOut: + cairo_set_operator(ct, CAIRO_OPERATOR_OUT); + break; + case NSCompositeSourceAtop: + cairo_set_operator(ct, CAIRO_OPERATOR_ATOP); + break; + case NSCompositeDestinationOver: + cairo_set_operator(ct, CAIRO_OPERATOR_OVER_REVERSE); + break; + case NSCompositeDestinationIn: + cairo_set_operator(ct, CAIRO_OPERATOR_IN_REVERSE); + break; + case NSCompositeDestinationOut: + cairo_set_operator(ct, CAIRO_OPERATOR_OUT_REVERSE); + break; + case NSCompositeDestinationAtop: + cairo_set_operator(ct, CAIRO_OPERATOR_ATOP_REVERSE); + break; + case NSCompositeXOR: + cairo_set_operator(ct, CAIRO_OPERATOR_XOR); + break; + case NSCompositePlusDarker: + break; + case NSCompositeHighlight: + cairo_set_operator(ct, CAIRO_OPERATOR_SATURATE); + break; + case NSCompositePlusLighter: + cairo_set_operator(ct, CAIRO_OPERATOR_ADD); + break; + default: + cairo_set_operator(ct, CAIRO_OPERATOR_SRC); + } +} + +- (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 +{ + cairo_format_t format; + NSAffineTransformStruct tstruct; + cairo_t *ict; + +/* + NSLog(@"%@ DPSimage %dx%d (%p)", self, pixelsWide, pixelsHigh, + cairo_current_target_surface (_ct)); +*/ + switch (bitsPerSample * samplesPerPixel) + { + case 32: + format = CAIRO_FORMAT_ARGB32; + break; + case 24: + format = CAIRO_FORMAT_RGB24; + break; + default: + NSLog(@"not support"); + exit(1); + } +// [self DPSinitclip]; + + tstruct =[matrix transformStruct]; + /* + NSLog(@"%g %g %g %g %g %g", + tstruct.m11, tstruct.m12, + tstruct.m21, tstruct.m22, + tstruct.tX, tstruct.tY); + */ + + ict = cairo_create(); + [_surface setAsTargetOfCairo: ict]; + _flipCairoSurfaceMatrix(ict, _surface); + cairo_matrix_set_affine(local_matrix, + tstruct.m11, tstruct.m12, + tstruct.m21, tstruct.m22, tstruct.tX, tstruct.tY); + cairo_concat_matrix(ict, local_matrix); + + cairo_matrix_set_identity(local_matrix); + cairo_matrix_scale(local_matrix, 1, -1); + cairo_matrix_translate(local_matrix, 0, -pixelsHigh); +/* + cairo_move_to(ict, 10, 10); + cairo_set_rgb_color(ict, 0, 1, 0); + cairo_rel_line_to(ict, 0, pixelsHigh - 20); + cairo_rel_line_to(ict, pixelsWide - 20, 0); + cairo_rel_line_to(ict, 0, -pixelsHigh + 20); + cairo_fill(ict); + cairo_destroy(ict); +*/ +} + +- (void) compositerect: (NSRect)aRect op: (NSCompositingOperation)op +{ + _set_op(_ct, op); + cairo_rectangle(_ct, NSMinX(aRect), NSMinY(aRect), NSWidth(aRect), + NSHeight(aRect)); + cairo_fill(_ct); +} + +- (void) compositeGState: (CairoGState *)source + fromRect: (NSRect)aRect + toPoint: (NSPoint)aPoint + op: (NSCompositingOperation)op +{ + cairo_surface_t *src; + + _set_op(_ct, op); + cairo_save(_ct); + cairo_translate(_ct, aPoint.x, aPoint.y); + /* + NSLog(NSStringFromRect(aRect)); + NSLog(@"src %p(%p,%@) des %p(%p,%@)",source,cairo_current_target_surface(source->_ct),NSStringFromSize([source->_surface size]), + self,cairo_current_target_surface(_ct),NSStringFromSize([_surface size])); + */ + src = cairo_current_target_surface(source->_ct); + cairo_matrix_set_identity(local_matrix); + cairo_matrix_scale(local_matrix, 1, -1); + cairo_matrix_translate(local_matrix, 0, -[source->_surface size].height); + cairo_surface_set_matrix(src, local_matrix); + cairo_show_surface(_ct, src, NSWidth(aRect), NSHeight(aRect)); + +/* + [[NSColor redColor] set]; + aRect.origin = NSZeroPoint; + NSFrameRect(aRect); +*/ + cairo_restore(_ct); +} + +@end diff --git a/Source/cairo/CairoSurface.m b/Source/cairo/CairoSurface.m new file mode 100644 index 0000000..04e0aee --- /dev/null +++ b/Source/cairo/CairoSurface.m @@ -0,0 +1,151 @@ +/* + Copyright (C) 2004 Free Software Foundation, Inc. + + Author: Banlu Kemiyatorn + + 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 +#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:@"", self, NULL]; +} + +-(NSSize) size +{ + [self subclassResponsibility:_cmd]; + return NSMakeSize(0, 0); +} + +@end diff --git a/Source/cairo/GNUmakefile b/Source/cairo/GNUmakefile new file mode 100644 index 0000000..4845910 --- /dev/null +++ b/Source/cairo/GNUmakefile @@ -0,0 +1,50 @@ +# Copyright (C) 2004 Free Software Foundation, Inc. +# +# Author: Banlu Kemiyatorn +# +# 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 + diff --git a/Source/cairo/GNUmakefile.preamble b/Source/cairo/GNUmakefile.preamble new file mode 100644 index 0000000..bd8cf2b --- /dev/null +++ b/Source/cairo/GNUmakefile.preamble @@ -0,0 +1,51 @@ +# +# GNUmakefile.preamble +# +# Copyright (C) 2002 Free Software Foundation, Inc. +# +# Author: Adam Fedor +# +# 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 +# + diff --git a/Source/cairo/NSBezierPathCairo.h b/Source/cairo/NSBezierPathCairo.h new file mode 100644 index 0000000..b5403ff --- /dev/null +++ b/Source/cairo/NSBezierPathCairo.h @@ -0,0 +1,31 @@ +/* + * NSBezierPathCairo.m + + * Copyright (C) 2003 Free Software Foundation, Inc. + * April 10, 2004 + * Written by Banlu Kemiyatorn + * 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 +#include + +@interface NSBezierPath (Cairo) ++ (void) initializeCairoBezierPath; ++ (NSBezierPath *) bezierPathFromCairo: (cairo_t *)ct; +- (void) appendBezierPathToCairo: (cairo_t *)ct; +- (BOOL) containsFillPoint: (NSPoint)p; +- (BOOL) containsStrokePoint: (NSPoint)p; +@end diff --git a/Source/cairo/NSBezierPathCairo.m b/Source/cairo/NSBezierPathCairo.m new file mode 100644 index 0000000..f6b09fd --- /dev/null +++ b/Source/cairo/NSBezierPathCairo.m @@ -0,0 +1,142 @@ +/* + * NSBezierPathCairo.m + + * Copyright (C) 2003 Free Software Foundation, Inc. + * April 10, 2004 + * Written by Banlu Kemiyatorn + * 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 diff --git a/Source/cairo/XGCairoGlitzSurface.m b/Source/cairo/XGCairoGlitzSurface.m new file mode 100644 index 0000000..99b2a92 --- /dev/null +++ b/Source/cairo/XGCairoGlitzSurface.m @@ -0,0 +1,126 @@ +/* + Copyright (C) 2002 Free Software Foundation, Inc. + + Author: Alexander Malmberg + Author: Banlu Kemiyatorn + + 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 +#include +#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: @"", 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 + diff --git a/Source/cairo/XGCairoSurface.m b/Source/cairo/XGCairoSurface.m new file mode 100644 index 0000000..9db5564 --- /dev/null +++ b/Source/cairo/XGCairoSurface.m @@ -0,0 +1,110 @@ +/* + Copyright (C) 2002 Free Software Foundation, Inc. + + Author: Banlu Kemiyatorn + + 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 +#include +#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: @"", 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 + diff --git a/Source/cairo/XGCairoXImageSurface.m b/Source/cairo/XGCairoXImageSurface.m new file mode 100644 index 0000000..d6d12a7 --- /dev/null +++ b/Source/cairo/XGCairoXImageSurface.m @@ -0,0 +1,82 @@ +/* + Copyright (C) 2002 Free Software Foundation, Inc. + + Author: Banlu Kemiyatorn + + 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 +#include +#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: @"", 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 + diff --git a/configure b/configure index a355da2..e285e47 100755 --- a/configure +++ b/configure @@ -309,7 +309,7 @@ ac_includes_default="\ # include #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 +_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 +_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 +_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 +_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 diff --git a/configure.ac b/configure.ac index 34561a3..ed7301c 100644 --- a/configure.ac +++ b/configure.ac @@ -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([