mirror of
https://github.com/gnustep/libs-back.git
synced 2025-05-30 17:00:52 +00:00
Implemented GSReadRect: for the cairo backend.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@24498 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
690f6936b1
commit
cc4ae5b8e3
2 changed files with 74 additions and 33 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2007-02-11 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Source/cairo/CairoGState.m (-GSReadRect:): Implemented this method.
|
||||||
|
|
||||||
2007-02-10 Fred Kiefer <FredKiefer@gmx.de>
|
2007-02-10 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/gsc/GSGState.m (-bezierPath): New method.
|
* Source/gsc/GSGState.m (-bezierPath): New method.
|
||||||
|
|
|
@ -753,57 +753,96 @@
|
||||||
- (NSDictionary *) GSReadRect: (NSRect)r
|
- (NSDictionary *) GSReadRect: (NSRect)r
|
||||||
{
|
{
|
||||||
NSMutableDictionary *dict;
|
NSMutableDictionary *dict;
|
||||||
NSData *data;
|
|
||||||
NSSize ssize;
|
NSSize ssize;
|
||||||
NSAffineTransform *matrix;
|
NSAffineTransform *matrix;
|
||||||
double x, y;
|
double x, y;
|
||||||
cairo_format_t format;
|
int ix, iy;
|
||||||
|
cairo_format_t format = CAIRO_FORMAT_ARGB32;
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface;
|
||||||
|
cairo_surface_t *isurface;
|
||||||
|
cairo_t *ct;
|
||||||
|
int size;
|
||||||
|
int i;
|
||||||
|
NSMutableData *data;
|
||||||
|
unsigned char *cdata;
|
||||||
|
|
||||||
surface = cairo_get_target(_ct);
|
|
||||||
dict = [NSMutableDictionary dictionary];
|
|
||||||
x = NSWidth(r);
|
x = NSWidth(r);
|
||||||
y = NSHeight(r);
|
y = NSHeight(r);
|
||||||
cairo_user_to_device_distance(_ct, &x, &y);
|
cairo_user_to_device_distance(_ct, &x, &y);
|
||||||
ssize = NSMakeSize(x, y);
|
ix = floor(x);
|
||||||
|
iy = -floor(y);
|
||||||
|
ssize = NSMakeSize(ix, iy);
|
||||||
|
|
||||||
|
/*
|
||||||
|
NSLog(@"rect %@ size %@", NSStringFromRect(r), NSStringFromSize(ssize));
|
||||||
|
*/
|
||||||
|
|
||||||
|
dict = [NSMutableDictionary dictionary];
|
||||||
[dict setObject: [NSValue valueWithSize: ssize] forKey: @"Size"];
|
[dict setObject: [NSValue valueWithSize: ssize] forKey: @"Size"];
|
||||||
[dict setObject: NSDeviceRGBColorSpace forKey: @"ColorSpace"];
|
[dict setObject: NSDeviceRGBColorSpace forKey: @"ColorSpace"];
|
||||||
format = cairo_image_surface_get_format(surface);
|
|
||||||
|
[dict setObject: [NSNumber numberWithUnsignedInt: 8] forKey: @"BitsPerSample"];
|
||||||
if (format == CAIRO_FORMAT_ARGB32)
|
[dict setObject: [NSNumber numberWithUnsignedInt: 32]
|
||||||
{
|
forKey: @"Depth"];
|
||||||
[dict setObject: [NSNumber numberWithUnsignedInt: 8] forKey: @"BitsPerSample"];
|
[dict setObject: [NSNumber numberWithUnsignedInt: 4]
|
||||||
[dict setObject: [NSNumber numberWithUnsignedInt: 32]
|
forKey: @"SamplesPerPixel"];
|
||||||
forKey: @"Depth"];
|
[dict setObject: [NSNumber numberWithUnsignedInt: 1]
|
||||||
[dict setObject: [NSNumber numberWithUnsignedInt: 4]
|
forKey: @"HasAlpha"];
|
||||||
forKey: @"SamplesPerPixel"];
|
|
||||||
[dict setObject: [NSNumber numberWithUnsignedInt: 1]
|
|
||||||
forKey: @"HasAlpha"];
|
|
||||||
}
|
|
||||||
else if (format == CAIRO_FORMAT_RGB24)
|
|
||||||
{
|
|
||||||
[dict setObject: [NSNumber numberWithUnsignedInt: 8] forKey: @"BitsPerSample"];
|
|
||||||
[dict setObject: [NSNumber numberWithUnsignedInt: 24]
|
|
||||||
forKey: @"Depth"];
|
|
||||||
[dict setObject: [NSNumber numberWithUnsignedInt: 3]
|
|
||||||
forKey: @"SamplesPerPixel"];
|
|
||||||
[dict setObject: [NSNumber numberWithUnsignedInt: 0]
|
|
||||||
forKey: @"HasAlpha"];
|
|
||||||
}
|
|
||||||
|
|
||||||
matrix = [self GSCurrentCTM];
|
matrix = [self GSCurrentCTM];
|
||||||
[matrix translateXBy: -r.origin.x - offset.x
|
[matrix translateXBy: -r.origin.x - offset.x
|
||||||
yBy: r.origin.y + NSHeight(r) - offset.y];
|
yBy: r.origin.y + NSHeight(r) - offset.y];
|
||||||
[dict setObject: matrix forKey: @"Matrix"];
|
[dict setObject: matrix forKey: @"Matrix"];
|
||||||
DESTROY(matrix);
|
|
||||||
// FIXME
|
size = ix*iy*4;
|
||||||
|
data = [NSMutableData dataWithLength: size];
|
||||||
|
if (data == nil)
|
||||||
|
return nil;
|
||||||
|
cdata = [data mutableBytes];
|
||||||
|
|
||||||
|
surface = cairo_get_target(_ct);
|
||||||
|
isurface = cairo_image_surface_create_for_data(cdata, format, ix, iy, 4*ix);
|
||||||
|
ct = cairo_create(isurface);
|
||||||
|
|
||||||
|
if (viewIsFlipped)
|
||||||
|
{
|
||||||
|
cairo_matrix_t local_matrix;
|
||||||
|
|
||||||
|
cairo_matrix_init_scale(&local_matrix, 1, -1);
|
||||||
|
cairo_matrix_translate(&local_matrix, 0, -iy);
|
||||||
|
cairo_set_matrix(ct, &local_matrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
cairo_set_source_surface(ct, surface, -r.origin.x, -r.origin.y);
|
||||||
|
cairo_rectangle(ct, 0, 0, ix, iy);
|
||||||
|
cairo_fill(ct);
|
||||||
|
cairo_destroy(ct);
|
||||||
|
cairo_surface_destroy(isurface);
|
||||||
|
|
||||||
|
for (i = 0; i < ix * iy; i++)
|
||||||
|
{
|
||||||
|
unsigned char d = cdata[4*i];
|
||||||
|
|
||||||
|
#if GS_WORDS_BIGENDIAN
|
||||||
|
cdata[4*i] = cdata[4*i + 1];
|
||||||
|
cdata[4*i + 1] = cdata[4*i + 2];
|
||||||
|
cdata[4*i + 2] = cdata[4*i + 3];
|
||||||
|
cdata[4*i + 3] = d;
|
||||||
|
#else
|
||||||
|
cdata[4*i] = cdata[4*i + 2];
|
||||||
|
//cdata[4*i + 1] = cdata[4*i + 1];
|
||||||
|
cdata[4*i + 2] = d;
|
||||||
|
//cdata[4*i + 3] = cdata[4*i + 3];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
[dict setObject: data forKey: @"Data"];
|
[dict setObject: data forKey: @"Data"];
|
||||||
|
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_set_op(cairo_t * ct, NSCompositingOperation op)
|
_set_op(cairo_t *ct, NSCompositingOperation op)
|
||||||
{
|
{
|
||||||
switch (op)
|
switch (op)
|
||||||
{
|
{
|
||||||
|
@ -875,7 +914,7 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NSLog(@"%@ DPSimage %dx%d (%p)", self, pixelsWide, pixelsHigh,
|
NSLog(@"%@ DPSimage %dx%d (%p)", self, pixelsWide, pixelsHigh,
|
||||||
cairo_current_target_surface (_ct));
|
cairo_get_target(_ct));
|
||||||
*/
|
*/
|
||||||
if (isPlanar || !([colorSpaceName isEqualToString: NSDeviceRGBColorSpace] ||
|
if (isPlanar || !([colorSpaceName isEqualToString: NSDeviceRGBColorSpace] ||
|
||||||
[colorSpaceName isEqualToString: NSCalibratedRGBColorSpace]))
|
[colorSpaceName isEqualToString: NSCalibratedRGBColorSpace]))
|
||||||
|
@ -1080,13 +1119,11 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
|
||||||
{
|
{
|
||||||
if (!source->viewIsFlipped)
|
if (!source->viewIsFlipped)
|
||||||
{
|
{
|
||||||
NSLog(@"Fall 1 %g, %g", height, dh);
|
|
||||||
cairo_set_source_surface(_ct, src, aPoint.x - minx, aPoint.y - miny - dh);
|
cairo_set_source_surface(_ct, src, aPoint.x - minx, aPoint.y - miny - dh);
|
||||||
//cairo_set_source_surface(_ct, src, aPoint.x - minx, aPoint.y - miny - height);
|
//cairo_set_source_surface(_ct, src, aPoint.x - minx, aPoint.y - miny - height);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSLog(@"Fall 2 %g, %g", height, dh);
|
|
||||||
// Both flipped
|
// Both flipped
|
||||||
cairo_pattern_t *cpattern;
|
cairo_pattern_t *cpattern;
|
||||||
cairo_matrix_t local_matrix;
|
cairo_matrix_t local_matrix;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue