Changed to compile with latest cairo interface changes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@21561 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2005-07-27 23:25:32 +00:00
parent 365394b949
commit 75055208a2
17 changed files with 420 additions and 316 deletions

View file

@ -1,3 +1,26 @@
2005-07-28 Fred Kiefer <FredKiefer@gmx.de>
* Headers/cairo/CairoFaceInfo.h,
* Headers/cairo/CairoFontEnumerator.h,
* Headers/cairo/CairoFontInfo.h,
* Headers/cairo/CairoSurface.h,
* Headers/cairo/XGCairoSurface.h,
* Source/cairo/CairoContext.m,
* Source/cairo/CairoGState.m,
* Source/cairo/CairoFaceInfo.m,
* Source/cairo/CairoFontInfo.m,
* Source/cairo/CairoFontEnumerator.m,
* Source/cairo/CairoSurface.m,
* Source/cairo/NSBezierPathCairo.m,
* Source/cairo/XGCairoGlitzSurface.m,
* Source/cairo/XGCairoSurface.m,
* Source/cairo/XGCairoXImageSurface.m,
Adopted to changes in latest release of cairo.
* Source/cairo/GNUmakefile:
Removed file CairoFontManager.m
2005-07-22 Adam Fedor <fedor@gnu.org>
* Version 0.10.0

View file

@ -32,6 +32,7 @@
cairo_font_slant_t _c_slant;
cairo_font_weight_t _c_weight;
cairo_font_face_t *_fontFace;
NSString *_faceName;
NSString *_familyName;
@ -67,6 +68,7 @@
- (void) setName: (NSString *)name;
- (const char *) cairoCName;
- (void) setCairoName: (NSString *)name;
- (cairo_font_face_t *)fontFace;

View file

@ -25,8 +25,10 @@
#include <GNUstepGUI/GSFontInfo.h>
#include <cairo.h>
#include "cairo/CairoFaceInfo.h"
@interface CairoFontEnumerator : GSFontEnumerator
+ (CairoFaceInfo *) fontWithName: (NSString *)name;
@end
#endif

View file

@ -30,8 +30,7 @@
@interface CairoFontInfo : GSFontInfo
{
@public
cairo_t *_cf;
cairo_font_t *xrFont;
cairo_scaled_font_t *_scaled;
CairoFaceInfo *_faceInfo;

View file

@ -34,6 +34,7 @@ typedef struct _CairoInfo
{
@public
void *gsDevice;
cairo_surface_t *_surface;
}
+ (CairoSurface *) surfaceForDevice: (void *) device
@ -43,10 +44,11 @@ typedef struct _CairoInfo
depthInfo:(CairoInfo *)cairoInfo;
- (id) initWithDevice:(void *)device;
- (void) setAsTargetOfCairo:(cairo_t *)ct;
- (NSSize) size;
- (cairo_surface_t *) surface;
@end
#endif

View file

@ -30,7 +30,6 @@
@interface XGCairoSurface : CairoSurface
{
cairo_surface_t *xrSurface;
}
@end

View file

@ -20,12 +20,12 @@
*/
#include "cairo/CairoContext.h"
#include "cairo/CairoGState.h"
#include "cairo/CairoFontInfo.h"
#include "cairo/CairoFontEnumerator.h"
#include "NSBezierPathCairo.h"
#define XRGSTATE ((CairoGState *)gstate)
@class CairoFontEnumerator;
@class CairoFontInfo;
@implementation CairoContext
@ -35,8 +35,8 @@
[NSGraphicsContext setDefaultContextClass:self];
[CairoSurface initializeBackend];
[CairoFontEnumerator initializeBackend];
[CairoFontInfo initializeBackend];
[GSFontEnumerator setDefaultClass: [CairoFontEnumerator class]];
[GSFontInfo setDefaultClass: [CairoFontInfo class]];
[NSBezierPath initializeCairoBezierPath];
}

View file

@ -21,6 +21,8 @@
*/
#include "cairo/CairoFaceInfo.h"
#include <cairo-ft.h>
#include <AppKit/NSFontManager.h>
@ implementation CairoFaceInfo
@ -45,6 +47,16 @@
return self;
}
- (void) dealloc
{
cairo_font_face_destroy(_fontFace);
RELEASE(_familyName);
RELEASE(_faceName);
RELEASE(_displayName);
RELEASE(_cairoName);
[super dealloc];
}
- (void) setFamilyName: (NSString *)name
{
ASSIGN(_familyName, name);
@ -130,4 +142,11 @@
return 257;
}
- (cairo_font_face_t *)fontFace
{
_fontFace =_cairo_simple_font_face_create([_familyName cString], _c_slant, _c_weight);
return _fontFace;
}
@end

View file

@ -36,12 +36,22 @@
#include "gsc/GSGState.h"
#include "cairo/CairoFontEnumerator.h"
#include "cairo/CairoFontManager.h"
#include "cairo/CairoFontInfo.h"
@implementation CairoFontEnumerator
+ (void) initializeBackend
NSMutableDictionary * __allFonts;
+ (CairoFaceInfo *) fontWithName: (NSString *) name
{
CairoFaceInfo *face;
face =[__allFonts objectForKey: name];
if (!face)
{
NSLog (@"Font not found %@", name);
}
return face;
}
- (void) enumerateFontsAndFamilies
@ -52,29 +62,61 @@
{
NSArray *fontDef;
NSMutableArray *fontDefs;
CairoFaceInfo *aFace;
ASSIGN(allFontNames, [CairoFontManager allFontNames]);
__allFonts = [[NSMutableDictionary alloc] init];
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];
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];
[__allFonts setObject: aFace forKey: @"Helvetica"];
RELEASE(aFace);
fontDef =[NSArray arrayWithObjects: @"Helvetica-Bold", @"Bold",
[NSNumber numberWithInt: 9],
[NSNumber numberWithUnsignedInt:NSBoldFontMask],
nil];
[fontDefs addObject:fontDef];
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];
[__allFonts setObject: aFace forKey: @"Helvetica-Bold"];
RELEASE(aFace);
fontDef =[NSArray arrayWithObjects: @"Helvetica-Oblique", @"Oblique",
[NSNumber numberWithInt: 5],
[NSNumber numberWithUnsignedInt:NSItalicFontMask],
nil];
[fontDefs addObject:fontDef];
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];
[__allFonts setObject: aFace forKey: @"Helvetica-Oblique"];
RELEASE(aFace);
fontDefs =[NSMutableArray arrayWithCapacity:10];
[allFontFamilies setObject: fontDefs forKey:@"Courier"];
@ -83,10 +125,21 @@
[NSNumber numberWithUnsignedInt:NSFixedPitchFontMask],
nil];
[fontDefs addObject:fontDef];
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];
[__allFonts setObject: aFace forKey: @"Courier"];
RELEASE(aFace);
ASSIGN(allFontNames, [__allFonts allKeys]);
done = YES;
}
NSLog (@"%@", allFontNames);
//NSLog (@"%@", allFontNames);
}
- (NSString *) defaultSystemFontName

View file

@ -23,20 +23,12 @@
#include <AppKit/NSAffineTransform.h>
#include "cairo/CairoFontInfo.h"
#include "cairo/CairoFontEnumerator.h"
#include "cairo/CairoFontManager.h"
#include <math.h>
#include <cairo.h>
#include <cairo-ft.h>
@implementation CairoFontInfo
+ (void) initializeBackend
{
//NSLog(@"CairoFontInfo : Initializing...");
[GSFontEnumerator setDefaultClass: [CairoFontEnumerator class]];
[GSFontInfo setDefaultClass: self];
}
- (void) setCacheSize: (unsigned int)size
{
_cacheSize = size;
@ -54,13 +46,16 @@
- (BOOL) setupAttributes
{
cairo_matrix_t *font_matrix;
cairo_font_extents_t font_extents;
cairo_font_face_t *face;
cairo_matrix_t font_matrix;
cairo_matrix_t ctm;
cairo_font_options_t *options;
/* do not forget to check for font specific
* cache size from face info FIXME FIXME
*/
ASSIGN(_faceInfo, [CairoFontManager fontWithName: fontName]);
ASSIGN(_faceInfo, [CairoFontEnumerator fontWithName: fontName]);
if (!_faceInfo)
{
return NO;
@ -83,18 +78,14 @@
/* setting GSFontInfo:
* xHeight, pix_width, pix_height
*/
_cf = cairo_create();
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);
cairo_matrix_destroy(font_matrix);
cairo_current_font_extents(_cf, &font_extents);
face = [_faceInfo fontFace];
cairo_matrix_init(&font_matrix, matrix[0], matrix[1], matrix[2],
-matrix[3], matrix[4], matrix[5]);
cairo_matrix_init_identity(&ctm);
// FIXME: Should get default font options from somewhere
options = cairo_font_options_create();
_scaled = cairo_scaled_font_create(face, &font_matrix, &ctm, options);
cairo_scaled_font_extents(_scaled, &font_extents);
ascender = font_extents.ascent;
descender = font_extents.descent;
xHeight = font_extents.height;
@ -139,7 +130,7 @@
- (void) dealloc
{
RELEASE(_faceInfo);
cairo_destroy(_cf);
cairo_scaled_font_destroy(_scaled);
free(_cachedSizes);
free(_cachedGlyphs);
[super dealloc];
@ -151,13 +142,25 @@
return YES;
}
static
cairo_glyph_t _cairo_glyph_for_NSGlyph(NSGlyph glyph)
{
cairo_glyph_t cglyph;
// FIXME: This is an unclear hack!
cglyph.index = glyph - 31;
cglyph.x = 0;
cglyph.y = 0;
return cglyph;
}
- (NSSize) advancementForGlyph: (NSGlyph)glyph
{
cairo_glyph_t cglyph;
cairo_text_extents_t ctext;
int entry;
glyph -= 29;
entry = glyph % _cacheSize;
if (_cachedGlyphs[entry] == glyph)
@ -165,10 +168,8 @@
return _cachedSizes[entry];
}
cglyph.index = glyph;
cglyph.x = 0;
cglyph.y = 0;
cairo_glyph_extents(_cf, &cglyph, 1, &ctext);
cglyph = _cairo_glyph_for_NSGlyph(glyph);
cairo_scaled_font_glyph_extents(_scaled, &cglyph, 1, &ctext);
_cachedGlyphs[entry] = glyph;
_cachedSizes[entry] = NSMakeSize(ctext.x_advance, ctext.y_advance);
@ -180,11 +181,8 @@
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);
cglyph = _cairo_glyph_for_NSGlyph(glyph);
cairo_scaled_font_glyph_extents(_scaled, &cglyph, 1, &ctext);
return NSMakeRect(ctext.x_bearing, ctext.y_bearing,
ctext.width, ctext.height);
@ -193,8 +191,14 @@
- (float) widthOfString: (NSString *)string
{
cairo_text_extents_t ctext;
cairo_status_t status;
cairo_glyph_t *glyphs;
int num_glyphs;
cairo_text_extents(_cf, [string UTF8String], &ctext);
// FIXME: This function is not exported by Cairo
status = _cairo_scaled_font_text_to_glyphs (_scaled, [string UTF8String],
&glyphs, &num_glyphs);
cairo_scaled_font_glyph_extents(_scaled, glyphs, num_glyphs, &ctext);
return ctext.width;
}
@ -290,6 +294,7 @@
static int maxlength = 0;
size_t i;
cairo_text_extents_t gext;
cairo_matrix_t font_matrix;
if (length > maxlength)
{
@ -297,16 +302,26 @@
cglyphs = realloc(cglyphs, sizeof(cairo_glyph_t) * maxlength);
}
cairo_matrix_init(&font_matrix, matrix[0], matrix[1], matrix[2],
-matrix[3], matrix[4], matrix[5]);
cairo_set_font_face(ct, [_faceInfo fontFace]);
cairo_set_font_matrix(ct, &font_matrix);
/*
status = _cairo_scaled_font_text_to_glyphs (_scaled, glyphs,
&cglyphs, &length);
*/
for (i = 0; i < length; i++)
{
cglyphs[i].index = glyphs[i] + -29; /* experimental */
cglyphs[i] = _cairo_glyph_for_NSGlyph(glyphs[i]);
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);
}

View file

@ -31,7 +31,7 @@
#define FIXME() NSLog(@":::FIXME::: %@ %s", [self description], sel_get_name(_cmd))
static cairo_matrix_t *local_matrix;
static cairo_matrix_t local_matrix;
/* Be warned that CairoGState didn't derived GSGState */
@implementation CairoGState
@ -40,7 +40,6 @@ static cairo_matrix_t *local_matrix;
{
if (self == [CairoGState class])
{
local_matrix = cairo_matrix_create();
}
}
@ -55,13 +54,33 @@ static cairo_matrix_t *local_matrix;
{
CairoGState *copy = (CairoGState *)NSCopyObject(self, 0, zone);
copy->_ct = cairo_create();
cairo_copy(copy->_ct, _ct);
if (_ct)
{
cairo_path_t *path;
cairo_status_t status;
// FIXME: Need some way to do a copy
//cairo_copy(copy->_ct, _ct);
copy->_ct = cairo_create(cairo_get_target(_ct));
cairo_get_matrix(_ct, &local_matrix);
cairo_set_matrix(copy->_ct, &local_matrix);
path = cairo_copy_path(_ct);
cairo_append_path(copy->_ct, path);
cairo_path_destroy(path);
//NSLog(@"copy gstate old %d new %d", _ct, copy->_ct);
status = cairo_status(copy->_ct);
if (status != CAIRO_STATUS_SUCCESS)
{
NSLog(@"Cairo status %s in copy", cairo_status_to_string(status));
}
}
/*
NSLog(@"copy state %p(%p) to %p(%p)",self,
cairo_current_target_surface(_ct),
cairo_get_target(_ct),
copy,
cairo_current_target_surface(copy->_ct)
cairo_get_target(copy->_ct)
);
*/
@ -88,7 +107,10 @@ static cairo_matrix_t *local_matrix;
- (void) dealloc
{
//NSLog(@"destate %p",self);
cairo_destroy(_ct);
if (_ct)
{
cairo_destroy(_ct);
}
RELEASE(_font);
RELEASE(_surface);
@ -98,14 +120,13 @@ static cairo_matrix_t *local_matrix;
static void
_flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
{
cairo_matrix_set_identity(local_matrix);
cairo_matrix_scale(local_matrix, 1, -1);
cairo_matrix_init_scale(&local_matrix, 1, -1);
if (surface != nil)
{
cairo_matrix_translate(local_matrix, 0, -[surface size].height);
cairo_matrix_translate(&local_matrix, 0, -[surface size].height);
}
cairo_set_matrix(ct, local_matrix);
cairo_set_matrix(ct, &local_matrix);
}
- (void) setOffset: (NSPoint)theOffset
@ -147,13 +168,12 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
_offset = NSMakePoint(x, y);
/*
NSLog(@"before: surface %p on state %p",
cairo_current_target_surface(_ct), self);
cairo_get_target(_ct), self);
*/
[_surface setAsTargetOfCairo: _ct];
_flipCairoSurfaceMatrix(_ct, _surface);
[self DPSinitgraphics];
/*
NSLog(@"after: surface %p on state %p %@",
cairo_current_target_surface (_ct), self,
cairo_get_target (_ct), self,
NSStringFromSize([_surface size]));
*/
}
@ -166,38 +186,40 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
*/
- (void) DPScurrentalpha: (float *)a
{
*a = cairo_current_alpha(_ct);
//FIXME
*a = 1.0;
//*a = cairo_current_alpha(_ct);
}
- (void) DPScurrentcmykcolor: (float *)c : (float *)m : (float *)y :(float *)k
{
double color[3];
float r, g, b;
cairo_current_rgb_color(_ct, &color[0], &color[1], &color[2]);
*c = 1 - color[0];
*m = 1 - color[1];
*y = 1 - color[2];
[self DPScurrentrgbcolor: &r: &g: &b];
*c = 1 - r;
*m = 1 - g;
*y = 1 - b;
*k = 0;
}
- (void) DPScurrentgray: (float *)gray
{
double dr, dg, db;
float r, g, b;
cairo_current_rgb_color(_ct, &dr, &dg, &db);
*gray = (dr + dg + db) / 3.0;
[self DPScurrentrgbcolor: &r: &g: &b];
*gray = (r + g + b) / 3.0;
}
- (void) DPScurrenthsbcolor: (float *)h : (float *)s : (float *)b
{
NSColor *color;
double dr, dg, db;
float fr, fg, fb;
float alpha;
cairo_current_rgb_color(_ct, &dr, &dg, &db);
color = [NSColor colorWithCalibratedRed: dr
green: dg
blue: db
[self DPScurrentrgbcolor: &fr: &fg: &fb];
color = [NSColor colorWithCalibratedRed: fr
green: fg
blue: fb
alpha: 1.0];
[color getHue: h
saturation: s
@ -209,7 +231,9 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
{
double dr, dg, db;
cairo_current_rgb_color(_ct, &dr, &dg, &db);
//FIXME:
//cairo_current_rgb_color(_ct, &dr, &dg, &db);
dr = dg = db = 0.8;
*r = dr;
*g = dg;
*b = db;
@ -217,7 +241,10 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
- (void) DPSsetalpha: (float)a
{
cairo_set_alpha(_ct, a);
// float r, g, b;
//FIXME
//cairo_set_source_rgba(_ct, r, g, b, a);
}
- (void) DPSsetcmykcolor: (float)c : (float)m : (float)y : (float)k
@ -227,12 +254,12 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
r = 1 - c;
g = 1 - m;
b = 1 - y;
cairo_set_rgb_color(_ct, r, g, b);
cairo_set_source_rgb(_ct, r, g, b);
}
- (void) DPSsetgray: (float)gray
{
cairo_set_rgb_color(_ct, gray, gray, gray);
cairo_set_source_rgb(_ct, gray, gray, gray);
}
- (void) DPSsethsbcolor: (float)h : (float)s : (float)b
@ -253,7 +280,7 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
- (void) DPSsetrgbcolor: (float)r : (float)g: (float)b
{
cairo_set_rgb_color(_ct, r, g, b);
cairo_set_source_rgb(_ct, r, g, b);
}
- (void) GSSetFillColorspace: (void *)spaceref
@ -340,12 +367,13 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
}
ASSIGN(_font, fontref);
cairo_set_font(_ct, ((CairoFontInfo *)_font)->xrFont);
//cairo_set_font_face(_ct, ((CairoFontInfo *)_font)->xrFont);
//cairo_set_font_matrix(_ct, matrix);
}
- (void) GSSetFontSize: (float)size
{
FIXME();
cairo_set_font_size(_ct, size);
}
- (NSAffineTransform *) GSGetTextCTM
@ -385,8 +413,11 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
{
double dx, dy;
cairo_current_point(_ct, &dx, &dy);
cairo_get_current_point(_ct, &dx, &dy);
// FIXME: Need some adjustment here
dy -= 5;
[_font drawGlyphs: glyphs
length: length
on: _ct
@ -400,29 +431,40 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
- (void) DPSinitgraphics
{
cairo_status_t status;
DESTROY(_font);
if (_ct)
{
cairo_destroy(_ct);
}
_ct = cairo_create();
/* Cairo's default line width is 2.0 */
if (!_surface)
{
return;
}
_ct = cairo_create([_surface surface]);
status = cairo_status(_ct);
if (status != CAIRO_STATUS_SUCCESS)
{
NSLog(@"Cairo status %s in DPSinitgraphics", cairo_status_to_string(status));
}
_flipCairoSurfaceMatrix(_ct, _surface);
//NSLog(@"in flip %p (%p)", self, cairo_current_target_surface(_ct));
//NSLog(@"in flip %p (%p)", self, cairo_get_target(_ct));
/* Cairo's default line width is 2.0 */
cairo_set_line_width(_ct, 1.0);
}
- (void) DPScurrentflat: (float *)flatness
{
*flatness = cairo_current_tolerance(_ct);
*flatness = cairo_get_tolerance(_ct);
}
- (void) DPScurrentlinecap: (int *)linecap
{
cairo_line_cap_t lc;
lc = cairo_current_line_cap(_ct);
lc = cairo_get_line_cap(_ct);
*linecap = lc;
/*
switch (lc)
@ -447,7 +489,7 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
{
cairo_line_join_t lj;
lj = cairo_current_line_join(_ct);
lj = cairo_get_line_join(_ct);
*linejoin = lj;
/*
switch (lj)
@ -470,19 +512,19 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
- (void) DPScurrentlinewidth: (float *)width
{
*width = cairo_current_line_width(_ct);
*width = cairo_get_line_width(_ct);
}
- (void) DPScurrentmiterlimit: (float *)limit
{
*limit = cairo_current_miter_limit(_ct);
*limit = cairo_get_miter_limit(_ct);
}
- (void) DPScurrentpoint: (float *)x : (float *)y
{
double dx, dy;
cairo_current_point(_ct, &dx, &dy);
cairo_get_current_point(_ct, &dx, &dy);
*x = dx;
*y = dy;
}
@ -544,14 +586,13 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
- (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);
cairo_matrix_init(&local_matrix, m[0], m[1], m[2], m[3], m[4], m[5]);
cairo_transform(_ct, &local_matrix);
}
- (void) DPSinitmatrix
{
cairo_matrix_set_identity(local_matrix);
cairo_set_matrix(_ct, local_matrix);
cairo_identity_matrix(_ct);
_flipCairoSurfaceMatrix(_ct, _surface);
}
@ -572,21 +613,18 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
- (void) _flipCairoFont
{
cairo_matrix_set_identity(local_matrix);
cairo_matrix_scale(local_matrix, 1, -1);
cairo_transform_font(_ct, local_matrix);
cairo_matrix_init_scale(&local_matrix, 1, -1);
cairo_set_font_matrix(_ct, &local_matrix);
}
/*
static void
_log_matrix(cairo_t * ct)
{
double da, db, dc, dd, dtx, dty;
cairo_get_matrix(ct, &local_matrix);
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);
NSLog(@"%g %g %g %g %g %g", local_matrix.xx, local_matrix.yx, local_matrix.xy,
local_matrix.yy, local_matrix.x0, local_matrix.y0);
}
*/
@ -594,17 +632,15 @@ _log_matrix(cairo_t * ct)
{
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;
cairo_get_matrix(_ct, &local_matrix);
tstruct.m11 = local_matrix.xx;
tstruct.m12 = local_matrix.yx;
tstruct.m21 = local_matrix.xy;
tstruct.m22 = local_matrix.yy;
tstruct.tX = local_matrix.x0;
tstruct.tY = local_matrix.y0;
[transform setTransformStruct:tstruct];
return transform;
}
@ -613,11 +649,14 @@ _log_matrix(cairo_t * ct)
{
NSAffineTransformStruct tstruct;
_flipCairoSurfaceMatrix(_ct, _surface);
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);
cairo_matrix_init(&local_matrix,
tstruct.m11, tstruct.m12,
tstruct.m21, tstruct.m22,
tstruct.tX, tstruct.tY);
//cairo_set_matrix(_ct, &local_matrix);
cairo_transform(_ct, &local_matrix);
}
- (void) GSConcatCTM: (NSAffineTransform *)ctm
@ -625,10 +664,11 @@ _log_matrix(cairo_t * ct)
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);
cairo_matrix_init(&local_matrix,
tstruct.m11, tstruct.m12,
tstruct.m21, tstruct.m22,
tstruct.tX, tstruct.tY);
cairo_transform(_ct, &local_matrix);
}
/*
@ -640,7 +680,7 @@ _log_matrix(cairo_t * ct)
double dx, dy;
//FIXME();
cairo_current_point(_ct, &dx, &dy);
cairo_get_current_point(_ct, &dx, &dy);
return NSMakePoint(dx, dy);
}
@ -704,7 +744,6 @@ _log_matrix(cairo_t * ct)
- (void) DPSeofill
{
cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_EVEN_ODD);
cairo_fill(_ct);
cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_WINDING);
@ -715,41 +754,19 @@ _log_matrix(cairo_t * ct)
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_path_t *path;
cairo_copy(fct, _ct);
path = cairo_copy_path_flat(_ct);
cairo_new_path(_ct);
cairo_current_path_flat(fct, _c2cmoveto, _c2clineto, _c2cclosepath, _ct);
cairo_destroy(fct);
cairo_append_path(_ct, path);
}
- (void) DPSinitclip
{
cairo_init_clip(_ct);
cairo_reset_clip(_ct);
}
- (void) DPSlineto: (float)x : (float)y
@ -952,7 +969,7 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
cairo_set_operator(ct, CAIRO_OPERATOR_CLEAR);
break;
case NSCompositeCopy:
cairo_set_operator(ct, CAIRO_OPERATOR_SRC);
cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE);
break;
case NSCompositeSourceOver:
cairo_set_operator(ct, CAIRO_OPERATOR_OVER);
@ -967,21 +984,22 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
cairo_set_operator(ct, CAIRO_OPERATOR_ATOP);
break;
case NSCompositeDestinationOver:
cairo_set_operator(ct, CAIRO_OPERATOR_OVER_REVERSE);
cairo_set_operator(ct, CAIRO_OPERATOR_DEST_OVER);
break;
case NSCompositeDestinationIn:
cairo_set_operator(ct, CAIRO_OPERATOR_IN_REVERSE);
cairo_set_operator(ct, CAIRO_OPERATOR_DEST_IN);
break;
case NSCompositeDestinationOut:
cairo_set_operator(ct, CAIRO_OPERATOR_OUT_REVERSE);
cairo_set_operator(ct, CAIRO_OPERATOR_DEST_OUT);
break;
case NSCompositeDestinationAtop:
cairo_set_operator(ct, CAIRO_OPERATOR_ATOP_REVERSE);
cairo_set_operator(ct, CAIRO_OPERATOR_DEST_ATOP);
break;
case NSCompositeXOR:
cairo_set_operator(ct, CAIRO_OPERATOR_XOR);
break;
case NSCompositePlusDarker:
// FIXME
break;
case NSCompositeHighlight:
cairo_set_operator(ct, CAIRO_OPERATOR_SATURATE);
@ -990,7 +1008,7 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
cairo_set_operator(ct, CAIRO_OPERATOR_ADD);
break;
default:
cairo_set_operator(ct, CAIRO_OPERATOR_SRC);
cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE);
}
}
@ -1003,9 +1021,8 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
{
cairo_format_t format;
NSAffineTransformStruct tstruct;
cairo_t *ict;
cairo_surface_t *surface;
/*
NSLog(@"%@ DPSimage %dx%d (%p)", self, pixelsWide, pixelsHigh,
cairo_current_target_surface (_ct));
@ -1038,30 +1055,30 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
tstruct.m21, tstruct.m22,
tstruct.tX, tstruct.tY);
*/
cairo_save(_ct);
_flipCairoSurfaceMatrix(_ct, _surface);
cairo_matrix_init(&local_matrix,
tstruct.m11, tstruct.m12,
tstruct.m21, tstruct.m22,
tstruct.tX, tstruct.tY);
cairo_transform(_ct, &local_matrix);
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);
surface = cairo_image_surface_create_for_data((void*)data,
format,
pixelsWide,
pixelsHigh,
bytesPerRow);
if (surface == NULL)
{
NSLog(@"Image surface could not be created");
return;
}
surface = cairo_surface_create_for_image((void*)data,
format,
pixelsWide,
pixelsHigh,
bytesPerRow);
cairo_matrix_set_identity(local_matrix);
cairo_matrix_scale(local_matrix, 1, -1);
cairo_matrix_translate(local_matrix, 0, -pixelsHigh);
cairo_surface_set_matrix(surface, local_matrix);
cairo_show_surface(ict,
surface,
pixelsWide,
pixelsHigh);
cairo_set_source_surface(_ct, surface, 0, 0);
cairo_rectangle(_ct, 0, 0, pixelsWide, pixelsHigh);
cairo_fill(_ct);
cairo_surface_destroy(surface);
cairo_destroy(ict);
cairo_restore(_ct);
}
- (void) compositerect: (NSRect)aRect op: (NSCompositingOperation)op
@ -1079,24 +1096,47 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
fraction: (float)delta
{
cairo_surface_t *src;
double minx, miny;
double width, height;
/*
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]));
NSLog(@"src %p(%p,%@) des %p(%p,%@)",
source,cairo_get_target(source->_ct),NSStringFromSize([source->_surface size]),
self,cairo_get_target(_ct),NSStringFromSize([_surface size]));
*/
cairo_save(_ct);
_set_op(_ct, op);
cairo_set_alpha(_ct, delta);
cairo_translate(_ct, aPoint.x, aPoint.y);
cairo_matrix_set_identity(local_matrix);
cairo_matrix_scale(local_matrix, 1, -1);
cairo_matrix_translate(local_matrix, 0, -[source->_surface size].height);
// cairo_matrix_translate(local_matrix, NSMinX(aRect), NSMinY(aRect));
src = cairo_current_target_surface(source->_ct);
cairo_surface_set_matrix(src, local_matrix);
cairo_show_surface(_ct, src, NSWidth(aRect), NSHeight(aRect));
src = cairo_get_target(source->_ct);
minx = NSMinX(aRect);
miny = NSMinY(aRect);
width = NSWidth(aRect);
height = NSHeight(aRect);
/*
cairo_user_to_device(source->_ct, &minx, &miny);
cairo_device_to_user(_ct, &minx, &miny);
cairo_user_to_device_distance(source->_ct, &width, &height);
cairo_device_to_user_distance(_ct, &width, &height);
NSLog(@"Rect %@ = %f, %f, %f, %f", NSStringFromRect(aRect), minx, miny, width, height);
*/
cairo_set_source_surface(_ct, src, aPoint.x - minx, aPoint.y - miny);
cairo_rectangle (_ct, aPoint.x, aPoint.y, width, height);
/*
cairo_set_source_surface(_ct, src, aPoint.x - NSMinX(aRect), aPoint.y - NSMinY(aRect));
cairo_rectangle (_ct, aPoint.x, aPoint.y, NSWidth(aRect), NSHeight(aRect));
*/
if (delta < 1.0)
{
cairo_pattern_t *pattern;
pattern = cairo_pattern_create_rgba(1.0, 1.0, 1.0, delta);
cairo_mask(_ct, pattern);
cairo_pattern_destroy(pattern);
}
cairo_fill(_ct);
cairo_restore(_ct);
}

View file

@ -129,17 +129,16 @@ static Class __defaultSurfaceClass;
- (void) dealloc
{
//NSLog(@"CairoSurface dealloc");
if (_surface != NULL)
{
cairo_surface_destroy(_surface);
}
[super dealloc];
}
- (void) setAsTargetOfCairo: (cairo_t *)ct
{
[self subclassResponsibility:_cmd];
}
- (NSString *) description
{
return [NSString stringWithFormat:@"<CairoSurface %p xr:%p>", self, NULL];
return [NSString stringWithFormat:@"<%@ %p xr:%p>", [self class], self, _surface];
}
-(NSSize) size
@ -148,4 +147,9 @@ static Class __defaultSurfaceClass;
return NSMakeSize(0, 0);
}
- (cairo_surface_t *) surface
{
return _surface;
}
@end

View file

@ -34,11 +34,11 @@ cairo_OBJC_FILES = CairoSurface.m \
CairoGState.m \
CairoContext.m \
CairoFontEnumerator.m \
CairoFontManager.m \
CairoFaceInfo.m \
XGCairoSurface.m \
XGCairoXImageSurface.m \
NSBezierPathCairo.m \
# CairoFontManager.m \
# CairoFreeTypeFontInfo.m \

View file

@ -23,44 +23,38 @@
@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
{
int i;
cairo_path_t *cpath;
cairo_path_data_t *data;
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);
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;
}
@ -69,7 +63,11 @@ static cairo_t *__ct = NULL;
+ (void) initializeCairoBezierPath
{
__ct = cairo_create();
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

View file

@ -52,6 +52,11 @@
- (id) initWithDevice: (void *)device
{
glitz_format_t *format;
Colormap cm;
XVisualInfo *vi;
unsigned long format_options = GLITZ_FORMAT_OPTION_ONSCREEN_MASK;
/* FIXME format is ignore when Visual isn't NULL
* Cairo may change this API
*/
@ -65,17 +70,6 @@
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;
@ -108,13 +102,12 @@
XSetWindowColormap(GSWINDEVICE->display,GSWINDEVICE->ident,cm);
*/
glsurface = glitz_glx_surface_create(GSWINDEVICE->display,
GSWINDEVICE->screen,
format,
GSWINDEVICE->ident);
// glitz_surface_update_size(glsurface);
_surface = cairo_glitz_surface_create(glitz_glx_surface_create(GSWINDEVICE->display,
GSWINDEVICE->screen,
format,
GSWINDEVICE->ident));
cairo_set_target_gl(ct, glsurface);
return self;
}
- (NSSize) size

View file

@ -23,6 +23,7 @@
#include <Foundation/NSUserDefaults.h>
#include <math.h>
#include "cairo/XGCairoSurface.h"
#include <cairo-xlib.h>
#define GSWINDEVICE ((gswindow_device_t *)gsDevice)
@ -31,29 +32,14 @@
+ (CairoSurface *) createSurfaceForDevice: (void *)device
depthInfo: (CairoInfo *)cairoInfo
{
#define NEWGSWINDEVICE ((gswindow_device_t *)device)
XGCairoSurface *surface;
surface = [[self alloc] initWithDevice: NEWGSWINDEVICE];
NSAssert(NEWGSWINDEVICE->buffer, @"FIXME! CairoSurface: Strange, a window doesn't have buffer");
return surface;
#undef NEWGSWINDEVICE
}
- (NSString *) description
{
return [NSString stringWithFormat: @"<XGCairoSurface %p xr:%p>", self, xrSurface];
return [[self alloc] initWithDevice: device];
}
- (id) initWithDevice: (void *)device
{
/* FIXME format is ignore when Visual isn't NULL
* Cairo may change this API
*/
gsDevice = device;
NSAssert(GSWINDEVICE->buffer, @"FIXME! CairoSurface: Strange, a window doesn't have buffer");
/*
if (GSWINDEVICE->type != NSBackingStoreNonretained)
{
@ -64,41 +50,22 @@
}
*/
xrSurface = cairo_xlib_surface_create(GSWINDEVICE->display,
GSWINDEVICE->buffer,
DefaultVisual(GSWINDEVICE->display,
DefaultScreen(GSWINDEVICE->display)),
0,
DefaultColormap(GSWINDEVICE->display,
DefaultScreen(GSWINDEVICE->display)));
/* FIXME format is ignore when Visual isn't NULL
* Cairo may change this API
*/
_surface = 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);
NSLog(@"device %p id:%p buff:%p", self, GSWINDEVICE->ident, GSWINDEVICE->buffer);
}
- (NSSize) size
@ -107,4 +74,3 @@
}
@end

View file

@ -42,12 +42,6 @@
#undef NEWGSWINDEVICE
}
- (NSString *) description
{
return [NSString stringWithFormat: @"<XGCairoXImageSurface %p xr:%p>", self, image];
}
- (id) initWithDevice: (void *)device
{
/* FIXME format is ignore when Visual isn't NULL
@ -62,17 +56,12 @@
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));
//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,
image->width, image->height, image->width*4);
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;