mirror of
https://github.com/gnustep/libs-back.git
synced 2025-04-22 15:31:14 +00:00
General cleanup of cairo backend code.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@22644 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7b8851bbed
commit
4f41a5e84e
18 changed files with 153 additions and 1298 deletions
27
ChangeLog
27
ChangeLog
|
@ -1,3 +1,30 @@
|
|||
2006-03-12 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/cairo/NSBezierPathCairo.m
|
||||
* Source/cairo/NSBezierPathCairo.h
|
||||
* Source/cairo/CairoDevice.m
|
||||
* Source/cairo/CairoFontManager.m
|
||||
* Source/cairo/CairoFreeTypeFontInfo.m
|
||||
* Headers/cairo/CairoDevice.m
|
||||
* Headers/cairo/CairoFontManager.m
|
||||
* Headers/cairo/CairoFreeTypeFontInfo.m:
|
||||
Removed these files.
|
||||
* Source/cairo/GNUmakefile:
|
||||
Removed references to obsolete files.
|
||||
* Source/cairo/CairoFontInfo.m (-setCacheSize:):
|
||||
Fill the cache with zeros.
|
||||
* Source/cairo/CairoFontInfo.m (-setupAttributes):
|
||||
Free the font options.
|
||||
* Source/cairo/CairoGState.m (:bezierPath, -GSSendBezierPath:):
|
||||
Added NSBezierPath methods.
|
||||
* Source/cairo/XGCairoXImageSurface.m
|
||||
* Source/cairo/CairoContext.m
|
||||
* Source/cairo/XGCairoSurface.m
|
||||
* Source/cairo/CairoSurface.m
|
||||
* Source/cairo/XGCairoGlitzSurface.m
|
||||
* Headers/cairo/CairoSurface.h:
|
||||
Clean up of cairo backend code.
|
||||
|
||||
2006-03-07 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/cairo/CairoGState.m (-compositeGState:...fraction:,
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* CairoFontInfo.h
|
||||
*
|
||||
* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
* September 10, 2003
|
||||
* Written by Banlu Kemiyatorn <id at project-ile dot net>
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef WOOM_CairoDevice_h
|
||||
#define WOOM_CairoDevice_h
|
||||
|
||||
#include "x11/XGServerWindow.h"
|
||||
#include <cairo.h>
|
||||
|
||||
@interface CairoBuffer : NSObject
|
||||
{
|
||||
@public
|
||||
gswindow_device_t * _gsdevice;
|
||||
void *_deviceid;
|
||||
NSSize _pixmapSize;
|
||||
Pixmap _pixmap;
|
||||
}
|
||||
+ (CairoBuffer *) pixmapWithWindowDevice: (gswindow_device_t *)device;
|
||||
- (id) initWithWindowDevice: (gswindow_device_t *)device;
|
||||
- (Pixmap) pixmap;
|
||||
- (gswindow_device_t *) device;
|
||||
- (NSSize) size;
|
||||
- (void) dealloc;
|
||||
/*- (id) copyWithZone: (NSZone *)zone;*/
|
||||
@end
|
||||
|
||||
@interface CairoType : NSObject
|
||||
{
|
||||
@public
|
||||
cairo_t *_cr;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface CairoType (Ops)
|
||||
- (void) save;
|
||||
- (void) restore;
|
||||
- (void) translateToPoint: (NSPoint)p;
|
||||
- (void) scaleToSize:(NSSize)s;
|
||||
- (void) rotateWithAngle:(float)angle;
|
||||
- (void) setTargetBuffer:(CairoBuffer *)buffer;
|
||||
- (void) setColorRGB:(float)r :(float)g :(float)b;
|
||||
- (void) setColorGray:(float)gray;
|
||||
- (void) clip;
|
||||
- (void) newPath;
|
||||
- (void) closePath;
|
||||
- (void) rectangle:(NSRect)rect;
|
||||
- (void) stroke;
|
||||
- (void) moveToPoint:(NSPoint)p;
|
||||
- (void) lineToPoint:(NSPoint)p;
|
||||
- (void) relativeLineToPoint:(NSPoint)p;
|
||||
- (void) relativeLineToSize:(NSSize)s;
|
||||
- (void) fill;
|
||||
- (NSAffineTransform *) CTM;
|
||||
- (void) setCTM: (NSAffineTransform *)newctm;
|
||||
- (void) concatCTM: (NSAffineTransform *)concatctm;
|
||||
@end /* CairoType */
|
||||
|
||||
@interface CairoDevice : NSObject
|
||||
{
|
||||
@public
|
||||
CairoType *_ct;
|
||||
CairoBuffer *_buffer;
|
||||
}
|
||||
- (CairoType *) ct;
|
||||
- (void) setDevice: (gswindow_device_t *)window;
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* CairoFontManager.h
|
||||
|
||||
* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
* August 31, 2003
|
||||
* Written by Banlu Kemiyatorn <object at gmail dot com>
|
||||
* Base on code by Alexander Malmberg <alexander@malmberg.org>
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef CAIROFONTMANAGER_H
|
||||
#define CAIROFONTMANAGER_H
|
||||
#include "CairoFaceInfo.h"
|
||||
#include <AppKit/NSFontManager.h>
|
||||
|
||||
@interface CairoFontManager : NSObject
|
||||
{
|
||||
}
|
||||
|
||||
+ (NSArray *) allFontNames;
|
||||
+ (CairoFaceInfo *) fontWithName: (NSString *)name;
|
||||
@end
|
||||
#endif
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* CairoFreeTypeFontInfo.h
|
||||
*
|
||||
* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
* April 27, 2004
|
||||
* Written by Banlu Kemiyatorn <lastlifeintheuniverse at hotmail dot com>
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef WOOM_CairoFreeTypeFontInfo_h
|
||||
#define WOOM_CairoFreeTypeFontInfo_h
|
||||
|
||||
#include <Foundation/NSMapTable.h>
|
||||
#include "nfont/GSNFont.h"
|
||||
#include "cairo/CairoFontInfo.h"
|
||||
|
||||
#include <cairo.h>
|
||||
|
||||
#define CACHE_SIZE 257
|
||||
|
||||
@interface CairoFreeTypeFontInfo : CairoFontInfo
|
||||
{
|
||||
@public
|
||||
/* We will implement FTC in cairo instead
|
||||
FTC_ImageTypeRec _imgd;
|
||||
|
||||
FTC_ImageTypeRec _advancementImgd;
|
||||
*/
|
||||
}
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -33,6 +33,8 @@
|
|||
cairo_surface_t *_surface;
|
||||
}
|
||||
|
||||
+ (void) setDefaultSurfaceClass: (Class)aClass;
|
||||
|
||||
- (id) initWithDevice: (void *)device;
|
||||
|
||||
- (NSSize) size;
|
||||
|
|
|
@ -20,12 +20,19 @@
|
|||
*/
|
||||
#include "cairo/CairoContext.h"
|
||||
#include "cairo/CairoGState.h"
|
||||
#include "cairo/CairoSurface.h"
|
||||
#include "cairo/CairoFontInfo.h"
|
||||
#include "cairo/CairoFontEnumerator.h"
|
||||
#include "NSBezierPathCairo.h"
|
||||
#include "x11/XGServer.h"
|
||||
#include "config.h"
|
||||
|
||||
#define XRGSTATE ((CairoGState *)gstate)
|
||||
#ifdef USE_GLITZ
|
||||
#include "cairo/XGCairoGlitzSurface.h"
|
||||
#else
|
||||
#include "cairo/XGCairoSurface.h"
|
||||
#endif
|
||||
|
||||
#define CGSTATE ((CairoGState *)gstate)
|
||||
|
||||
|
||||
@implementation CairoContext
|
||||
|
@ -33,19 +40,22 @@
|
|||
+ (void) initializeBackend
|
||||
{
|
||||
//NSLog (@"CairoContext : Initializing cairo backend");
|
||||
[NSGraphicsContext setDefaultContextClass:self];
|
||||
[NSGraphicsContext setDefaultContextClass: self];
|
||||
|
||||
[CairoSurface initializeBackend];
|
||||
#ifdef USE_GLITZ
|
||||
[CairoSurface setDefaultSurfaceClass: [XGCairoGlitzSurface class]];
|
||||
#else
|
||||
[CairoSurface setDefaultSurfaceClass: [XGCairoSurface class]];
|
||||
#endif
|
||||
[GSFontEnumerator setDefaultClass: [CairoFontEnumerator class]];
|
||||
[GSFontInfo setDefaultClass: [CairoFontInfo class]];
|
||||
[NSBezierPath initializeCairoBezierPath];
|
||||
}
|
||||
|
||||
- (void) GSWSetViewIsFlipped: (BOOL)flipped
|
||||
{
|
||||
if (gstate)
|
||||
{
|
||||
((CairoGState *) gstate)->_viewIsFlipped = flipped;
|
||||
CGSTATE->_viewIsFlipped = flipped;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,12 +90,12 @@
|
|||
|
||||
- (void) GSCurrentDevice: (void **)device : (int *)x : (int *)y
|
||||
{
|
||||
[XRGSTATE GSCurrentDevice: device : x : y];
|
||||
[CGSTATE GSCurrentDevice: device : x : y];
|
||||
}
|
||||
|
||||
- (void) GSSetDevice: (void *)device : (int)x : (int)y
|
||||
{
|
||||
[XRGSTATE GSSetDevice: device : x : y];
|
||||
[CGSTATE GSSetDevice: device : x : y];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,401 +0,0 @@
|
|||
/*
|
||||
* CairoDevice.m
|
||||
*
|
||||
* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
* September 10, 2003
|
||||
* Written by Banlu Kemiyatorn <id at project-ile dot net>
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "Foundation/NSValue.h"
|
||||
#include "Foundation/NSArray.h"
|
||||
#include "Foundation/NSDictionary.h"
|
||||
#include <AppKit/NSAffineTransform.h>
|
||||
#include "cairo/CairoDevice.h"
|
||||
#include <cairo.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
NSAffineTransform * WMCairoMatrixToNSAffine (cairo_matrix_t *cairo_mp)
|
||||
{
|
||||
double af[6];
|
||||
NSAffineTransformStruct ats;
|
||||
NSAffineTransform *aCTM = [NSAffineTransform transform];
|
||||
cairo_matrix_get_affine(cairo_mp,&af[0],&af[1],&af[2],&af[3],&af[4],&af[5]);
|
||||
ats.m11 = af[0];
|
||||
ats.m12 = af[1];
|
||||
ats.m21 = af[2];
|
||||
ats.m22 = af[3];
|
||||
ats.tx = af[4];
|
||||
ats.ty = af[5];
|
||||
[aCTM setTransformStruct:ats];
|
||||
return aCTM;
|
||||
}
|
||||
|
||||
|
||||
@implementation CairoType
|
||||
- (id) init
|
||||
{
|
||||
// FIXME: first we need to create the dummy instance
|
||||
// by returning a trapper ok, CairoTypeDummy
|
||||
// and recording invocations into stack
|
||||
// and when we know device's size, we'll apply
|
||||
// all invocations to the real one.
|
||||
_cr = cairo_create();
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
cairo_scale(_cr,1,-1);
|
||||
return self;
|
||||
}
|
||||
- (void) dealloc
|
||||
{
|
||||
cairo_destroy(_cr);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
[super dealloc];
|
||||
NSLog (@"done CT dealloc");
|
||||
}
|
||||
- (id) retain
|
||||
{
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
return [super retain];
|
||||
}
|
||||
- (void) release
|
||||
{
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d",[self description], sel_get_name(_cmd),_cr);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
[super release];
|
||||
}
|
||||
- (id) copyWithZone: (NSZone *)zone
|
||||
{
|
||||
CairoType *aCT = (CairoType *)NSCopyObject(self, 0, zone);
|
||||
NSLog (@":::FIXME::: %@ %s copy %0x to %0x",[self description], sel_get_name(_cmd), self, aCT);
|
||||
aCT->_cr = cairo_create();
|
||||
cairo_copy(aCT->_cr,_cr);
|
||||
NSLog(@"cairo_copy %d to %d [%s]",_cr,aCT->_cr,cairo_status_string(_cr));
|
||||
return aCT;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CairoType (Ops)
|
||||
- (void) save
|
||||
{
|
||||
// cairo_save(_cr);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) restore
|
||||
{
|
||||
// cairo_restore(_cr);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) translateToPoint: (NSPoint)p
|
||||
{
|
||||
cairo_translate(_cr,p.x,p.y);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) scaleToSize:(NSSize)s
|
||||
{
|
||||
cairo_scale(_cr,s.width,s.height);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) rotateWithAngle:(float)angle
|
||||
{
|
||||
// cairo_rotate(_cr,angle);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) setTargetBuffer:(CairoBuffer *)buffer
|
||||
{
|
||||
// cairo_set_target_drawable(_cr, buffer->_gsdevice->display, buffer->_pixmap);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) setColorRGB:(float)r :(float)g :(float)b
|
||||
{
|
||||
// cairo_set_rgb_color(_cr,r,g,b);
|
||||
}
|
||||
- (void) setAlpha:(float)alpha
|
||||
{
|
||||
cairo_set_alpha(_cr, alpha);
|
||||
}
|
||||
- (float) currentAlpha
|
||||
{
|
||||
return cairo_current_alpha(_cr);
|
||||
}
|
||||
- (float) currentGray
|
||||
{
|
||||
return _currentGray;
|
||||
}
|
||||
- (void) clip
|
||||
{
|
||||
// cairo_clip(_cr);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) newPath
|
||||
{
|
||||
// cairo_new_path(_cr);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) closePath
|
||||
{
|
||||
// cairo_close_path(_cr);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) rectangle:(NSRect)rect
|
||||
{
|
||||
// cairo_rectangle(_cr,NSMinX(rect),NSMinY(rect),NSWidth(rect),NSHeight(rect));
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) stroke
|
||||
{
|
||||
// cairo_stroke(_cr);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) moveToPoint:(NSPoint)p
|
||||
{
|
||||
// cairo_move_to(_cr,p.x,p.y);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) lineToPoint:(NSPoint)p
|
||||
{
|
||||
// cairo_line_to(_cr,p.x,p.y);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) relativeLineToPoint:(NSPoint)p
|
||||
{
|
||||
// cairo_rel_line_to(_cr,p.x,p.y);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) relativeLineToSize:(NSSize)s
|
||||
{
|
||||
// cairo_rel_line_to(_cr,s.width,s.height);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
- (void) fill
|
||||
{
|
||||
// cairo_fill(_cr);
|
||||
NSLog (@":::FIXME::: %@ %s cairo %d [%s]",[self description], sel_get_name(_cmd),_cr,cairo_status_string(_cr));
|
||||
}
|
||||
|
||||
/* What is the Matrix? */
|
||||
|
||||
- (NSAffineTransform *) CTM
|
||||
{
|
||||
cairo_matrix_t *cairo_ctm;
|
||||
cairo_ctm = cairo_matrix_create();
|
||||
cairo_current_matrix(_cr, cairo_ctm);
|
||||
id retMe = WMCairoMatrixToNSAffine(cairo_ctm);
|
||||
cairo_matrix_destroy(cairo_ctm);
|
||||
return retMe;
|
||||
}
|
||||
|
||||
- (void) setCTM: (NSAffineTransform *)newctm
|
||||
{
|
||||
NSAffineTransformStruct ats = [newctm transformStruct];
|
||||
cairo_matrix_t *cairo_mp = cairo_matrix_create();
|
||||
cairo_matrix_set_affine(cairo_mp,ats.m11,ats.m12,ats.m21,ats.m22,ats.tx,ats.ty);
|
||||
cairo_set_matrix(_cr, cairo_mp);
|
||||
cairo_matrix_destroy(cairo_mp);
|
||||
}
|
||||
|
||||
- (void) concatCTM: (NSAffineTransform *)concatctm
|
||||
{
|
||||
NSAffineTransformStruct ats = [concatctm transformStruct];
|
||||
cairo_matrix_t *cairo_mp = cairo_matrix_create();
|
||||
cairo_matrix_set_affine(cairo_mp,ats.m11,ats.m12,ats.m21,ats.m22,ats.tx,ats.ty);
|
||||
cairo_concat_matrix(_cr, cairo_mp);
|
||||
cairo_matrix_destroy(cairo_mp);
|
||||
}
|
||||
|
||||
@end /* CairoType */
|
||||
|
||||
@implementation CairoBuffer
|
||||
|
||||
NSMapTable * buffermap;
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
buffermap = NSCreateMapTable(NSIntMapKeyCallBacks,NSNonRetainedObjectMapValueCallBacks,10);
|
||||
}
|
||||
|
||||
+ (CairoBuffer *) pixmapWithWindowDevice: (gswindow_device_t *)device
|
||||
{
|
||||
id buff = [[self alloc] initWithWindowDevice: device];
|
||||
AUTORELEASE(buff);
|
||||
return buff;
|
||||
}
|
||||
|
||||
+ (CairoBuffer *) bufferForDevice: (gswindow_device_t *)device
|
||||
{
|
||||
CairoBuffer *_b = (CairoBuffer *) NSMapGet(buffermap, (void*)(device->ident));
|
||||
if (_b == nil)
|
||||
{
|
||||
_b = [[self alloc] initWithWindowDevice: device];
|
||||
}
|
||||
return _b;
|
||||
}
|
||||
|
||||
- (void) handleExposeRect:(NSRect)er
|
||||
{
|
||||
XCopyArea(_gsdevice->display, _pixmap, _gsdevice->ident,_gsdevice->gc, NSMinX(er), NSMinY(er), NSWidth(er), NSHeight(er), NSMinX(er), NSMinY(er));
|
||||
/*
|
||||
XClearWindow(_gsdevice->display, _gsdevice->ident);
|
||||
XClearArea(_gsdevice->display, _gsdevice->ident, NSMinX(er), NSMinY(er), NSWidth(er), NSHeight(er), NO);
|
||||
*/
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
- (id) initWithWindowDevice: (gswindow_device_t *)device
|
||||
{
|
||||
NSLog (@":::FIXME::: %@ %s",[self description], sel_get_name(_cmd));
|
||||
_gsdevice = device;
|
||||
id oldbuffer = NSMapGet(buffermap, (const void*)(device->ident));
|
||||
if (oldbuffer != nil)
|
||||
{
|
||||
ASSIGN(self, oldbuffer);
|
||||
if (!NSEqualSizes(_pixmapSize, device->xframe.size))
|
||||
{
|
||||
_pixmapSize = device->xframe.size;
|
||||
_pixmap = XCreatePixmap(device->display,
|
||||
device->ident,
|
||||
NSWidth(device->xframe),
|
||||
NSHeight(device->xframe),
|
||||
device->depth);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_deviceid = (void *)(device->ident);
|
||||
_pixmapSize = device->xframe.size;
|
||||
_pixmap = XCreatePixmap(device->display,
|
||||
device->ident,
|
||||
NSWidth(device->xframe),
|
||||
NSHeight(device->xframe),
|
||||
device->depth);
|
||||
|
||||
NSMapInsert(buffermap, _deviceid, (const void*)self);
|
||||
}
|
||||
|
||||
/*
|
||||
XSetWindowAttributes attr;
|
||||
attr.event_mask = KeyPressMask |
|
||||
KeyReleaseMask | ButtonPressMask |
|
||||
ButtonReleaseMask | ButtonMotionMask |
|
||||
StructureNotifyMask | PointerMotionMask |
|
||||
EnterWindowMask | LeaveWindowMask |
|
||||
FocusChangeMask | PropertyChangeMask |
|
||||
ColormapChangeMask | KeymapStateMask |
|
||||
VisibilityChangeMask;
|
||||
XChangeWindowAttributes(device->display, device->ident, CWEventMask, &attr);
|
||||
*/
|
||||
#ifdef CAIRO_USE_BACKGROUND_PIXMAP
|
||||
XSetWindowBackgroundPixmap(device->display, device->ident,_pixmap);
|
||||
XClearWindow(device->display, device->ident);
|
||||
#endif
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
- (id) copyWithZone: (NSZone *)zone
|
||||
{
|
||||
CairoDevice *aCP = (CairoBuffer *)NSCopyObject(self, 0, zone);
|
||||
}
|
||||
*/
|
||||
|
||||
- (Pixmap) pixmap
|
||||
{
|
||||
return _pixmap;
|
||||
}
|
||||
|
||||
- (NSSize) size
|
||||
{
|
||||
return _pixmapSize;
|
||||
}
|
||||
|
||||
- (gswindow_device_t *) device
|
||||
{
|
||||
return _gsdevice;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
NSLog (@":::FIXME::: %@ %s",[self description], sel_get_name(_cmd));
|
||||
if (_deviceid)
|
||||
NSMapRemove(buffermap, _deviceid);
|
||||
if (_pixmap)
|
||||
XFreePixmap([XGServer currentXDisplay], _pixmap);
|
||||
[super dealloc];
|
||||
NSLog(@"done CBF dealloc");
|
||||
}
|
||||
@end /* CairoBuffer */
|
||||
|
||||
@implementation CairoDevice
|
||||
- (id) init
|
||||
{
|
||||
NSLog (@":::FIXME::: %@ %s",[self description], sel_get_name(_cmd));
|
||||
_ct = [[CairoType alloc] init];
|
||||
|
||||
return self;
|
||||
}
|
||||
- (void) setDevice: (gswindow_device_t *)window
|
||||
{
|
||||
NSLog (@":::FIXME::: %@ %s %0x",[self description], sel_get_name(_cmd) ,_ct);
|
||||
_buffer = RETAIN([CairoBuffer pixmapWithWindowDevice:window]);
|
||||
XSetWindowAttributes attr;
|
||||
[_ct setTargetBuffer:_buffer];
|
||||
[_ct translateToPoint:NSMakePoint(0,-NSHeight(window->xframe))];
|
||||
attr.event_mask = KeyPressMask |
|
||||
KeyReleaseMask | ButtonPressMask |
|
||||
ButtonReleaseMask | ButtonMotionMask |
|
||||
StructureNotifyMask | PointerMotionMask |
|
||||
EnterWindowMask | LeaveWindowMask |
|
||||
FocusChangeMask | PropertyChangeMask |
|
||||
ColormapChangeMask | KeymapStateMask |
|
||||
VisibilityChangeMask;
|
||||
XChangeWindowAttributes(window->display, window->ident, CWEventMask, &attr);
|
||||
|
||||
}
|
||||
- (CairoType *) ct
|
||||
{
|
||||
NSLog (@":::FIXME::: %@ %s %0x",[self description], sel_get_name(_cmd) ,_ct);
|
||||
return _ct;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
NSLog (@":::FIXME::: %@ %s %0x",[self description], sel_get_name(_cmd) ,_ct);
|
||||
[_ct release];
|
||||
if (_buffer)
|
||||
{
|
||||
[_buffer release];
|
||||
}
|
||||
[super dealloc];
|
||||
NSLog(@"done CD dealloc");
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone *)zone
|
||||
{
|
||||
CairoDevice *aCD = (CairoDevice *)NSCopyObject(self, 0, zone);
|
||||
NSLog (@":::FIXME::: %@ %s copy to %0x",[self description], sel_get_name(_cmd), aCD);
|
||||
aCD->_ct = [_ct copyWithZone:zone];
|
||||
// aCD->_buffer = [_buffer copy];
|
||||
RETAIN(_buffer);
|
||||
return aCD;
|
||||
}
|
||||
@end
|
||||
|
|
@ -42,7 +42,9 @@
|
|||
free(_cachedGlyphs);
|
||||
}
|
||||
_cachedSizes = malloc(sizeof(NSSize) * size);
|
||||
memset(_cachedSizes, 0, sizeof(NSSize) * size);
|
||||
_cachedGlyphs = malloc(sizeof(unsigned int) * size);
|
||||
memset(_cachedGlyphs, 0, sizeof(unsigned int) * size);
|
||||
}
|
||||
|
||||
- (BOOL) setupAttributes
|
||||
|
@ -90,6 +92,7 @@
|
|||
return NO;
|
||||
}
|
||||
_scaled = cairo_scaled_font_create(face, &font_matrix, &ctm, options);
|
||||
cairo_font_options_destroy(options);
|
||||
if (!_scaled)
|
||||
{
|
||||
return NO;
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
/*
|
||||
* CairoFontManager.m
|
||||
*
|
||||
* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
* August 31, 2003
|
||||
* Written by Banlu Kemiyatorn <object at gmail dot com>
|
||||
* Base on original code of Alex Malmberg
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 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
|
|
@ -1,405 +0,0 @@
|
|||
/*
|
||||
* CairoFontInfo.m
|
||||
*
|
||||
* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
* April 27, 2004
|
||||
* Written by Banlu Kemiyatorn <lastlifeintheuniverse at hotmail dot com>
|
||||
* Base on original code of Alex Malmberg
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "cairo/CairoFontInfo.h"
|
||||
#include <cairo.h>
|
||||
@class NSAffineTransform;
|
||||
|
||||
|
||||
@implementation CairoFontInfo
|
||||
|
||||
/* TODO port this freetype code so it can be shared with other backends */
|
||||
/* TODO or simply use cairo's text/glyph extense */
|
||||
|
||||
static FT_Library ft_library;
|
||||
static FTC_Manager ftc_manager;
|
||||
|
||||
+ (void) initializeBackend
|
||||
{
|
||||
NSLog(@"CairoFreeTypeFontInfo : Initializing...");
|
||||
[super initializeBackend];
|
||||
|
||||
[GSFontInfo setDefaultClass: self];
|
||||
|
||||
if (FT_Init_FreeType(&ft_library))
|
||||
NSLog(@"FT_Init_FreeType failed");
|
||||
}
|
||||
|
||||
- (void) setFaceId:(void *)face_id
|
||||
{
|
||||
_imgd.font.face_id = (FTC_FaceID)face_id;
|
||||
}
|
||||
|
||||
- (id) initWithFontName:(NSString *)name
|
||||
matrix:(const float *)fmatrix
|
||||
screenFont:(BOOL)p_screenFont
|
||||
{
|
||||
FT_Size size;
|
||||
FT_Face face;
|
||||
|
||||
[super initWithFontName:name
|
||||
matrix:fmatrix
|
||||
screenFont:p_screenFont];
|
||||
|
||||
_imgd.font.pix_width = fabs(matrix[0]);
|
||||
_imgd.font.pix_height = fabs(matrix[3]);
|
||||
if ((error=FTC_Manager_Lookup_Size(ftc_manager, &_imgd.font, &face, &size)))
|
||||
{
|
||||
NSLog(@"FTC_Manager_Lookup_Size() failed for '%@', error %08x!\n", name, error);
|
||||
return self;
|
||||
}
|
||||
|
||||
ascender = fabs(((int)size->metrics.ascender) / 64.0);
|
||||
descender = fabs(((int)size->metrics.descender) / 64.0);
|
||||
xHeight = ascender * 0.5; /* TODO */
|
||||
maximumAdvancement = NSMakeSize((_size->metrics.max_advance / 64.0), ascender + descender);
|
||||
|
||||
fontBBox = NSMakeRect(0, descender, maximumAdvancement.width, ascender + descender);
|
||||
descender = -descender;
|
||||
|
||||
{
|
||||
float xx, yy;
|
||||
|
||||
FTC_ImageTypeRec cur;
|
||||
|
||||
cur = _imgd;
|
||||
|
||||
xx = matrix[0];
|
||||
yy = matrix[3];
|
||||
|
||||
if (xx == yy && xx < 16 && xx >= 8)
|
||||
{
|
||||
int rh = _faceInfo->_render_hints_hack;
|
||||
if (rh & 0x10000)
|
||||
{
|
||||
cur.flags = FT_LOAD_TARGET_NORMAL;
|
||||
rh = (rh >> 8) & 0xff;
|
||||
}
|
||||
else
|
||||
{
|
||||
cur.flags = FT_LOAD_TARGET_MONO;
|
||||
rh = rh & 0xff;
|
||||
}
|
||||
if (rh & 1)
|
||||
cur.flags |= FT_LOAD_FORCE_AUTOHINT;
|
||||
if (!(rh & 2))
|
||||
cur.flags |= FT_LOAD_NO_HINTING;
|
||||
}
|
||||
else if (xx < 8)
|
||||
cur.flags = FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING;
|
||||
else
|
||||
cur.flags = FT_LOAD_TARGET_NORMAL;
|
||||
_advancementImgd = cur;
|
||||
}
|
||||
|
||||
/* create font here */
|
||||
|
||||
FT_New_Face(ft_library, [[_faceInfo->files] objectAtIndex:0]);
|
||||
_font = cairo_ft_font_create(&face);
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL) glyphIsEncoded: (NSGlyph)glyph
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSSize) advancementForGlyph: (NSGlyph)glyph
|
||||
{
|
||||
cairo_glyph_t cglyph;
|
||||
cairo_text_extents_t ctext;
|
||||
|
||||
glyph--;
|
||||
|
||||
|
||||
if (screenFont)
|
||||
{
|
||||
int entry = glyph % CACHE_SIZE;
|
||||
|
||||
if (cachedGlyph[entry] == glyph)
|
||||
return cachedSize[entry];
|
||||
|
||||
if ((error=FTC_SBitCache_Lookup(ftc_sbitcache, &advancementImgd, glyph, &sbit, NULL)))
|
||||
{
|
||||
NSLog(@"FTC_SBitCache_Lookup() failed with error %08x (%08x, %08x, %ix%i, %08x)\n",
|
||||
error, glyph, advancementImgd.font.face_id,
|
||||
advancementImgd.font.pix_width, advancementImgd.font.pix_height,
|
||||
advancementImgd.flags
|
||||
);
|
||||
return NSZeroSize;
|
||||
}
|
||||
|
||||
cachedGlyph[entry] = glyph;
|
||||
cachedSize[entry] = NSMakeSize(sbit->xadvance, sbit->yadvance);
|
||||
return cachedSize[entry];
|
||||
}
|
||||
else
|
||||
{
|
||||
FT_Face face;
|
||||
FT_Glyph gl;
|
||||
FT_Matrix ftmatrix;
|
||||
FT_Vector ftdelta;
|
||||
float f;
|
||||
NSSize s;
|
||||
|
||||
f = fabs(matrix[0] * matrix[3] - matrix[1] * matrix[2]);
|
||||
if (f > 1)
|
||||
f = sqrt(f);
|
||||
else
|
||||
f = 1.0;
|
||||
|
||||
f = (int)f;
|
||||
|
||||
ftmatrix.xx = matrix[0] / f * 65536.0;
|
||||
ftmatrix.xy = matrix[1] / f * 65536.0;
|
||||
ftmatrix.yx = matrix[2] / f * 65536.0;
|
||||
ftmatrix.yy = matrix[3] / f * 65536.0;
|
||||
ftdelta.x = ftdelta.y = 0;
|
||||
|
||||
if (FTC_Manager_Lookup_Size(ftc_manager, &_imgd.font, &face, 0))
|
||||
return NSZeroSize;
|
||||
|
||||
if (FT_Load_Glyph(face, glyph, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP))
|
||||
return NSZeroSize;
|
||||
|
||||
if (FT_Get_Glyph(face->glyph, &gl))
|
||||
return NSZeroSize;
|
||||
|
||||
if (FT_Glyph_Transform(gl, &ftmatrix, &ftdelta))
|
||||
return NSZeroSize;
|
||||
|
||||
s = NSMakeSize(gl->advance.x / 65536.0, gl->advance.y / 65536.0);
|
||||
|
||||
FT_Done_Glyph(gl);
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
|
||||
{
|
||||
FTC_ImageTypeRec *cur;
|
||||
FT_BBox bbox;
|
||||
FT_Glyph g;
|
||||
FT_Error error;
|
||||
|
||||
glyph--;
|
||||
/* TODO: this is ugly */
|
||||
cur = &_imgd;
|
||||
if ((error=FTC_ImageCache_Lookup(ftc_imagecache, cur, glyph, &g, NULL)))
|
||||
{
|
||||
NSLog(@"FTC_ImageCache_Lookup() failed with error %08x",error);
|
||||
// NSLog(@"boundingRectForGlyph: %04x -> %i\n", aGlyph, glyph);
|
||||
return fontBBox;
|
||||
}
|
||||
|
||||
FT_Glyph_Get_CBox(g, ft_glyph_bbox_gridfit, &bbox);
|
||||
|
||||
/* printf("got cbox for %04x: %i, %i - %i, %i\n",
|
||||
aGlyph, bbox.xMin, bbox.yMin, bbox.xMax, bbox.yMax);*/
|
||||
|
||||
return NSMakeRect(bbox.xMin / 64.0, bbox.yMin / 64.0,
|
||||
(bbox.xMax - bbox.xMin) / 64.0, (bbox.yMax - bbox.yMin) / 64.0);
|
||||
}
|
||||
|
||||
-(NSPoint) positionOfGlyph: (NSGlyph)g
|
||||
precededByGlyph: (NSGlyph)prev
|
||||
isNominal: (BOOL *)nominal
|
||||
{
|
||||
NSPoint a;
|
||||
FT_Face face;
|
||||
FT_Vector vec;
|
||||
FT_GlyphSlot glyph;
|
||||
|
||||
g--;
|
||||
prev--;
|
||||
|
||||
if (nominal)
|
||||
*nominal = YES;
|
||||
|
||||
if (g == NSControlGlyph || prev == NSControlGlyph)
|
||||
return NSZeroPoint;
|
||||
|
||||
if (FTC_Manager_Lookup_Size(ftc_manager, &_imgd.font, &face, 0))
|
||||
return NSZeroPoint;
|
||||
|
||||
if (FT_Load_Glyph(face, prev, FT_LOAD_DEFAULT))
|
||||
return NSZeroPoint;
|
||||
|
||||
glyph = face->glyph;
|
||||
a = NSMakePoint(glyph->advance.x / 64.0, glyph->advance.y / 64.0);
|
||||
|
||||
if (FT_Get_Kerning(face, prev, g, ft_kerning_default, &vec))
|
||||
return a;
|
||||
|
||||
if (vec.x == 0 && vec.y == 0)
|
||||
return a;
|
||||
|
||||
if (nominal)
|
||||
*nominal = NO;
|
||||
|
||||
a.x += vec.x / 64.0;
|
||||
a.y += vec.y / 64.0;
|
||||
return a;
|
||||
}
|
||||
|
||||
- (float) widthOfString: (NSString*)string
|
||||
{
|
||||
unichar ch;
|
||||
int i, c = [string length];
|
||||
int total;
|
||||
|
||||
FTC_CMapDescRec cmap;
|
||||
unsigned int glyph;
|
||||
|
||||
FTC_SBit sbit;
|
||||
|
||||
FTC_ImageTypeRec *cur;
|
||||
|
||||
cmap.face_id = _imgd.font.face_id;
|
||||
cmap.u.encoding = ft_encoding_unicode;
|
||||
cmap.type = FTC_CMAP_BY_ENCODING;
|
||||
|
||||
total = 0;
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
ch = [string characterAtIndex: i];
|
||||
cur = &_imgd;
|
||||
glyph = FTC_CMapCache_Lookup(ftc_cmapcache, &cmap, ch);
|
||||
|
||||
/* TODO: shouldn't use sbit cache for this */
|
||||
if (1)
|
||||
{
|
||||
if (FTC_SBitCache_Lookup(ftc_sbitcache, cur, glyph, &sbit, NULL))
|
||||
continue;
|
||||
|
||||
total += sbit->xadvance;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"non-sbit code not implemented");
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
-(NSGlyph) glyphWithName: (NSString *)glyphName
|
||||
{
|
||||
FT_Face face;
|
||||
NSGlyph g;
|
||||
|
||||
if (FTC_Manager_Lookup_Size(ftc_manager, &_imgd.font, &face, 0))
|
||||
return NSNullGlyph;
|
||||
|
||||
g = FT_Get_Name_Index(face, (FT_String *)[glyphName lossyCString]);
|
||||
if (g)
|
||||
return g + 1;
|
||||
|
||||
return NSNullGlyph;
|
||||
}
|
||||
|
||||
/* need cairo to export its cairo_path_t first */
|
||||
-(void) appendBezierPathWithGlyphs: (NSGlyph *)glyphs
|
||||
count: (int)count
|
||||
toBezierPath: (NSBezierPath *)path
|
||||
{
|
||||
cairo_t *ct;
|
||||
int i;
|
||||
/* TODO LATER
|
||||
NSPoint start = [path currentPoint];
|
||||
|
||||
|
||||
cairo_glyph_t *cairo_glyphs;
|
||||
cairo_glyphs = malloc(sizeof(cairo_glyph_t) * count);
|
||||
|
||||
ct = cairo_create();
|
||||
|
||||
|
||||
cairo_destroy(ct);
|
||||
*/
|
||||
|
||||
#if 0
|
||||
int i;
|
||||
NSGlyph glyph;
|
||||
|
||||
FT_Matrix ftmatrix;
|
||||
FT_Vector ftdelta;
|
||||
|
||||
NSPoint p = [path currentPoint];
|
||||
|
||||
ftmatrix.xx = 65536;
|
||||
ftmatrix.xy = 0;
|
||||
ftmatrix.yx = 0;
|
||||
ftmatrix.yy = 65536;
|
||||
ftdelta.x = p.x * 64.0;
|
||||
ftdelta.y = p.y * 64.0;
|
||||
|
||||
for (i = 0; i < count; i++, glyphs++)
|
||||
{
|
||||
FT_Face face;
|
||||
FT_Glyph gl;
|
||||
FT_OutlineGlyph og;
|
||||
|
||||
glyph = *glyphs - 1;
|
||||
|
||||
if (FTC_Manager_Lookup_Size(ftc_manager, &_imgd.font, &face, 0))
|
||||
continue;
|
||||
if (FT_Load_Glyph(face, glyph, FT_LOAD_DEFAULT))
|
||||
continue;
|
||||
|
||||
if (FT_Get_Glyph(face->glyph, &gl))
|
||||
continue;
|
||||
|
||||
if (FT_Glyph_Transform(gl, &ftmatrix, &ftdelta))
|
||||
{
|
||||
NSLog(@"glyph transformation failed!");
|
||||
continue;
|
||||
}
|
||||
og = (FT_OutlineGlyph)gl;
|
||||
|
||||
ftdelta.x += gl->advance.x >> 10;
|
||||
ftdelta.y += gl->advance.y >> 10;
|
||||
|
||||
FT_Outline_Decompose(&og->outline, &bezierpath_funcs, path);
|
||||
|
||||
FT_Done_Glyph(gl);
|
||||
}
|
||||
|
||||
if (count)
|
||||
{
|
||||
[path moveToPoint: NSMakePoint(ftdelta.x / 64.0, ftdelta.y / 64.0)];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void) set
|
||||
{
|
||||
NSLog(@"ignore -set method of font '%@'\n", fontName);
|
||||
}
|
||||
|
||||
/*** CairoFontInfo Protocol ***/
|
||||
|
||||
|
||||
@end
|
|
@ -29,7 +29,6 @@
|
|||
#include "cairo/CairoFontInfo.h"
|
||||
#include "cairo/CairoSurface.h"
|
||||
#include "cairo/CairoContext.h"
|
||||
#include "NSBezierPathCairo.h"
|
||||
#include <math.h>
|
||||
|
||||
#define FIXME() NSLog(@":::FIXME::: %@ %s", [self description], sel_get_name(_cmd))
|
||||
|
@ -800,9 +799,45 @@ static float last_r, last_g, last_b;
|
|||
cairo_new_path(_ct);
|
||||
}
|
||||
|
||||
- (NSBezierPath *) bezierPath
|
||||
{
|
||||
int i;
|
||||
cairo_path_t *cpath;
|
||||
cairo_path_data_t *data;
|
||||
NSBezierPath *path =[NSBezierPath bezierPath];
|
||||
|
||||
cpath = cairo_copy_path(_ct);
|
||||
|
||||
for (i=0; i < cpath->num_data; i += cpath->data[i].header.length)
|
||||
{
|
||||
data = &cpath->data[i];
|
||||
switch (data->header.type)
|
||||
{
|
||||
case CAIRO_PATH_MOVE_TO:
|
||||
[path moveToPoint: NSMakePoint(data[1].point.x, data[1].point.y)];
|
||||
break;
|
||||
case CAIRO_PATH_LINE_TO:
|
||||
[path lineToPoint: NSMakePoint(data[1].point.x, data[1].point.y)];
|
||||
break;
|
||||
case CAIRO_PATH_CURVE_TO:
|
||||
[path curveToPoint: NSMakePoint(data[1].point.x, data[1].point.y)
|
||||
controlPoint1: NSMakePoint(data[2].point.x, data[2].point.y)
|
||||
controlPoint2: NSMakePoint(data[3].point.x, data[3].point.y)];
|
||||
break;
|
||||
case CAIRO_PATH_CLOSE_PATH:
|
||||
[path closePath];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cairo_path_destroy(cpath);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
- (void) DPSpathbbox: (float *)llx : (float *)lly : (float *)urx : (float *)ury
|
||||
{
|
||||
NSBezierPath *path = [NSBezierPath bezierPathFromCairo: _ct];
|
||||
NSBezierPath *path = [self bezierPath];
|
||||
NSRect rect = [path controlPointBounds];
|
||||
|
||||
if (llx)
|
||||
|
@ -861,11 +896,10 @@ static float last_r, last_g, last_b;
|
|||
|
||||
- (void) DPSreversepath
|
||||
{
|
||||
NSBezierPath *path = [NSBezierPath bezierPathFromCairo: _ct];
|
||||
NSBezierPath *path = [self bezierPath];
|
||||
|
||||
path = [path bezierPathByReversingPath];
|
||||
cairo_new_path(_ct);
|
||||
[path appendBezierPathToCairo: _ct];
|
||||
[self GSSendBezierPath: path];
|
||||
}
|
||||
|
||||
- (void) DPSrlineto: (float)x : (float)y
|
||||
|
@ -885,8 +919,46 @@ static float last_r, last_g, last_b;
|
|||
|
||||
- (void) GSSendBezierPath: (NSBezierPath *)path
|
||||
{
|
||||
int i, n;
|
||||
int count = 10;
|
||||
float dash_pattern[10];
|
||||
float phase;
|
||||
NSPoint pts[3];
|
||||
NSBezierPathElement e;
|
||||
SEL elmsel = @selector(elementAtIndex: associatedPoints:);
|
||||
IMP elmidx = [path methodForSelector: elmsel];
|
||||
|
||||
cairo_new_path(_ct);
|
||||
[path appendBezierPathToCairo: _ct];
|
||||
|
||||
n = [path elementCount];
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
e = (NSBezierPathElement)(*elmidx)(path, 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, [path lineWidth]);
|
||||
cairo_set_line_join(_ct, (cairo_line_join_t)[path lineJoinStyle]);
|
||||
cairo_set_line_cap(_ct, (cairo_line_cap_t)[path lineCapStyle]);
|
||||
cairo_set_miter_limit(_ct, [path miterLimit]);
|
||||
|
||||
[path getLineDash: dash_pattern count: &count phase: &phase];
|
||||
[self DPSsetdash: dash_pattern : count : phase];
|
||||
}
|
||||
|
||||
- (void) GSRectClipList: (const NSRect *)rects : (int)count
|
||||
|
@ -1184,7 +1256,25 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
|
|||
*/
|
||||
if (_viewIsFlipped)
|
||||
{
|
||||
cairo_set_source_surface(_ct, src, aPoint.x - minx, aPoint.y - miny - height);
|
||||
/*
|
||||
if (!source->_viewIsFlipped)
|
||||
{
|
||||
// Undo flipping of the source coordinate system
|
||||
cairo_pattern_t *pattern;
|
||||
cairo_matrix_t local_matrix;
|
||||
|
||||
pattern = cairo_pattern_create_for_surface(src);
|
||||
cairo_matrix_init_scale(&local_matrix, 1, -1);
|
||||
cairo_matrix_translate(&local_matrix, -aPoint.x + minx, -aPoint.y + miny);
|
||||
cairo_pattern_set_matrix(pattern, &local_matrix);
|
||||
cairo_set_source(_ct, pattern);
|
||||
cairo_pattern_destroy(pattern);
|
||||
}
|
||||
else
|
||||
*/
|
||||
{
|
||||
cairo_set_source_surface(_ct, src, aPoint.x - minx, aPoint.y - miny - height);
|
||||
}
|
||||
cairo_rectangle (_ct, aPoint.x, aPoint.y - height, width, height);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -22,15 +22,6 @@
|
|||
|
||||
#include "cairo/CairoSurface.h"
|
||||
|
||||
#include <math.h>
|
||||
#include "config.h"
|
||||
|
||||
#ifdef USE_GLITZ
|
||||
@class XGCairoGlitzSurface;
|
||||
#else
|
||||
@class XGCairoSurface;
|
||||
#endif
|
||||
|
||||
static Class __defaultSurfaceClass;
|
||||
|
||||
@implementation CairoSurface
|
||||
|
@ -40,18 +31,6 @@ static Class __defaultSurfaceClass;
|
|||
__defaultSurfaceClass = aClass;
|
||||
}
|
||||
|
||||
+ (void) initializeBackend
|
||||
{
|
||||
if (BUILD_SERVER == SERVER_x11)
|
||||
{
|
||||
#ifdef USE_GLITZ
|
||||
[self setDefaultSurfaceClass: [XGCairoGlitzSurface class]];
|
||||
#else
|
||||
[self setDefaultSurfaceClass: [XGCairoSurface class]];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)zone
|
||||
{
|
||||
return NSAllocateObject(__defaultSurfaceClass, 0, zone);
|
||||
|
|
|
@ -36,10 +36,11 @@ cairo_OBJC_FILES = CairoSurface.m \
|
|||
CairoFontEnumerator.m \
|
||||
CairoFaceInfo.m \
|
||||
XGCairoSurface.m \
|
||||
XGCairoXImageSurface.m \
|
||||
NSBezierPathCairo.m \
|
||||
# CairoFontManager.m \
|
||||
# CairoFreeTypeFontInfo.m \
|
||||
XGCairoXImageSurface.m
|
||||
|
||||
ifeq ($(WITH_GLITZ),yes)
|
||||
cairo_OBJC_FILES += XGCairoGlitzSurface.m
|
||||
endif
|
||||
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* NSBezierPathCairo.m
|
||||
|
||||
* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
* April 10, 2004
|
||||
* Written by Banlu Kemiyatorn <object at gmail dot com>
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <AppKit/NSBezierPath.h>
|
||||
#include <cairo.h>
|
||||
|
||||
@interface NSBezierPath (Cairo)
|
||||
+ (void) initializeCairoBezierPath;
|
||||
+ (NSBezierPath *) bezierPathFromCairo: (cairo_t *)ct;
|
||||
- (void) appendBezierPathToCairo: (cairo_t *)ct;
|
||||
- (BOOL) containsFillPoint: (NSPoint)p;
|
||||
- (BOOL) containsStrokePoint: (NSPoint)p;
|
||||
@end
|
|
@ -1,140 +0,0 @@
|
|||
/*
|
||||
* NSBezierPathCairo.m
|
||||
|
||||
* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
* April 10, 2004
|
||||
* Written by Banlu Kemiyatorn <object at gmail dot com>
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "NSBezierPathCairo.h"
|
||||
|
||||
@implementation NSBezierPath (Cairo)
|
||||
|
||||
+ (NSBezierPath *) bezierPathFromCairo: (cairo_t *)ct
|
||||
{
|
||||
int i;
|
||||
cairo_path_t *cpath;
|
||||
cairo_path_data_t *data;
|
||||
NSBezierPath *path =[NSBezierPath bezierPath];
|
||||
|
||||
cpath = cairo_copy_path (ct);
|
||||
|
||||
for (i=0; i < cpath->num_data; i += cpath->data[i].header.length)
|
||||
{
|
||||
data = &cpath->data[i];
|
||||
switch (data->header.type)
|
||||
{
|
||||
case CAIRO_PATH_MOVE_TO:
|
||||
[path moveToPoint: NSMakePoint(data[1].point.x, data[1].point.y)];
|
||||
break;
|
||||
case CAIRO_PATH_LINE_TO:
|
||||
[path lineToPoint: NSMakePoint(data[1].point.x, data[1].point.y)];
|
||||
break;
|
||||
case CAIRO_PATH_CURVE_TO:
|
||||
[path curveToPoint: NSMakePoint(data[1].point.x, data[1].point.y)
|
||||
controlPoint1: NSMakePoint(data[2].point.x, data[2].point.y)
|
||||
controlPoint2: NSMakePoint(data[3].point.x, data[3].point.y)];
|
||||
break;
|
||||
case CAIRO_PATH_CLOSE_PATH:
|
||||
[path closePath];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cairo_path_destroy(cpath);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
static cairo_t *__ct = NULL;
|
||||
|
||||
+ (void) initializeCairoBezierPath
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
|
||||
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 100, 100);
|
||||
__ct = cairo_create(surface);
|
||||
cairo_surface_destroy(surface);
|
||||
}
|
||||
|
||||
- (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
|
|
@ -21,7 +21,6 @@
|
|||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include "cairo/XGCairoGlitzSurface.h"
|
||||
|
||||
#define GSWINDEVICE ((gswindow_device_t *)gsDevice)
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include "cairo/XGCairoSurface.h"
|
||||
#include <cairo-xlib.h>
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <math.h>
|
||||
#include "cairo/XGCairoXImageSurface.h"
|
||||
|
||||
#define GSWINDEVICE ((gswindow_device_t *)gsDevice)
|
||||
|
@ -43,7 +41,7 @@
|
|||
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));
|
||||
_surface = cairo_image_surface_create_for_data(image->data, CAIRO_FORMAT_ARGB32,
|
||||
_surface = cairo_image_surface_create_for_data((unsigned char*)image->data, CAIRO_FORMAT_ARGB32,
|
||||
image->width, image->height, image->width*4);
|
||||
|
||||
return self;
|
||||
|
|
Loading…
Reference in a new issue