mirror of
https://github.com/gnustep/libs-back.git
synced 2025-04-22 15:31:14 +00:00
Get cairo surfaces working for resized windows.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@21685 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2435fad1b6
commit
d8ce1e0de6
10 changed files with 82 additions and 210 deletions
18
ChangeLog
18
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
2005-08-28 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Headers/cairo/CairoSurface.h,
|
||||
* Source/cairo/CairoSurface.m,
|
||||
* Source/cairo/XGCairoGlitzSurface.m,
|
||||
* Source/cairo/XGCairoSurface.m,
|
||||
* Source/cairo/XGCairoXImageSurface.m,
|
||||
* Source/cairo/CairoGState.m (-GSSetDevice:::):
|
||||
Rewrote the device handling to work for resized windows.
|
||||
* Headers/cairo/CairoFontInfo.h,
|
||||
* Source/cairo/CairoFontInfo.m (-drawGlyphs:length:on:, -setupAttributes),
|
||||
* Source/cairo/CairoGState.m (-GSShowGlyphs::):
|
||||
Moved adjustment of font size and positioning to CairoFontInfo.
|
||||
* Source/cairo/CairoContext.m:
|
||||
Clean up.
|
||||
|
||||
2005-08-20 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/cairo/CairoGState.m (-DPSImage::::::::):
|
||||
|
@ -31,7 +47,7 @@
|
|||
* Source/cairo/NSBezierPathCairo.m,
|
||||
* Source/cairo/XGCairoGlitzSurface.m,
|
||||
* Source/cairo/XGCairoSurface.m,
|
||||
* Source/cairo/XGCairoXImageSurface.m,
|
||||
* Source/cairo/XGCairoXImageSurface.m:
|
||||
|
||||
Adopted to changes in latest release of cairo.
|
||||
|
||||
|
|
|
@ -48,9 +48,7 @@
|
|||
- (void) setCacheSize:(unsigned int)size;
|
||||
- (void) drawGlyphs: (const NSGlyph*)glyphs
|
||||
length: (int)length
|
||||
on: (cairo_t*)ct
|
||||
atX: (double)dx
|
||||
y: (double)dy;
|
||||
on: (cairo_t*)ct;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,10 +26,6 @@
|
|||
#include <cairo.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
typedef struct _CairoInfo
|
||||
{
|
||||
} CairoInfo;
|
||||
|
||||
@interface CairoSurface : NSObject
|
||||
{
|
||||
@public
|
||||
|
@ -37,13 +33,7 @@ typedef struct _CairoInfo
|
|||
cairo_surface_t *_surface;
|
||||
}
|
||||
|
||||
+ (CairoSurface *) surfaceForDevice: (void *) device
|
||||
depthInfo: (CairoInfo *) cairoInfo;
|
||||
|
||||
+ (CairoSurface *) createSurfaceForDevice:(void *)device
|
||||
depthInfo:(CairoInfo *)cairoInfo;
|
||||
|
||||
- (id) initWithDevice:(void *)device;
|
||||
- (id) initWithDevice: (void *)device;
|
||||
|
||||
- (NSSize) size;
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "cairo/CairoFontInfo.h"
|
||||
#include "cairo/CairoFontEnumerator.h"
|
||||
#include "NSBezierPathCairo.h"
|
||||
#include "x11/XGServer.h"
|
||||
|
||||
#define XRGSTATE ((CairoGState *)gstate)
|
||||
|
||||
|
@ -40,13 +41,6 @@
|
|||
[NSBezierPath initializeCairoBezierPath];
|
||||
}
|
||||
|
||||
/* FIXME: TRAP */
|
||||
- (void) forwardInvocation: (NSInvocation *)anInvocation
|
||||
{
|
||||
/* only for trapping any unknown message. */
|
||||
NSLog (@":::UNKNOWN::: %@ %@", self, anInvocation);
|
||||
}
|
||||
|
||||
- (void) GSWSetViewIsFlipped: (BOOL)flipped
|
||||
{
|
||||
if (gstate)
|
||||
|
@ -59,46 +53,17 @@
|
|||
{
|
||||
NSString *contextType;
|
||||
|
||||
/*
|
||||
CSMKColorType hsb_double;
|
||||
CSMKColorAttributes attr;
|
||||
*/
|
||||
|
||||
[super initWithContextInfo:info];
|
||||
|
||||
contextType = [info objectForKey:
|
||||
NSGraphicsContextRepresentationFormatAttributeName];
|
||||
if (contextType)
|
||||
{
|
||||
if (!([contextType isEqualToString: NSGraphicsContextPDFFormat] ||
|
||||
[contextType isEqualToString: NSGraphicsContextPSFormat]))
|
||||
{
|
||||
NSLog(@"CairoContext : Hmmmm");
|
||||
}
|
||||
NSLog(@"CairoContext : NSGCRFAName %@", contextType);
|
||||
/* Most likely this is a PS or PDF context, so just return what
|
||||
super gave us */
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
attr.signature = CSMKHSVColorSignature;
|
||||
attr.isPremultiplied = NO;
|
||||
attr.isPlanar = NO;
|
||||
attr.hasAlphaChannel = NO;
|
||||
attr.isEndian16 = NO;
|
||||
attr.flavor = CSMKBlackIsZeroFlavor;
|
||||
attr.numberOfColorComponents = 3;
|
||||
attr.bytesPerChannel = 4;
|
||||
|
||||
hsb_double = CSMKMakeColorType(&attr);
|
||||
|
||||
ASSIGN(_systemRGBprofile,
|
||||
[CSMKColorProfile defaultColorProfileForColorType:CSMKRGBDoubleColor]);
|
||||
ASSIGN(_systemCMYKprofile,
|
||||
[CSMKColorProfile defaultColorProfileForColorType:CSMKCMYKDoubleColor]);
|
||||
ASSIGN(_systemHSBprofile,
|
||||
[CSMKColorProfile defaultColorProfileForColorType:hsb_double]);
|
||||
*/
|
||||
|
||||
gstate = [[CairoGState allocWithZone: [self zone]] initWithDrawContext: self];
|
||||
|
||||
return self;
|
||||
|
@ -106,13 +71,7 @@
|
|||
|
||||
- (void) flushGraphics
|
||||
{
|
||||
/* FIXME */
|
||||
}
|
||||
|
||||
+ (void) handleExposeRect: (NSRect)rect forDriver: (void *)driver
|
||||
{
|
||||
NSLog (@"expose");
|
||||
/* FIXME: */
|
||||
XFlush([(XGServer *)server xDisplay]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -94,7 +94,8 @@
|
|||
return NO;
|
||||
}
|
||||
cairo_scaled_font_extents(_scaled, &font_extents);
|
||||
ascender = font_extents.ascent;
|
||||
// FIXME: Need some adjustment here
|
||||
ascender = font_extents.ascent + 3;
|
||||
descender = font_extents.descent;
|
||||
xHeight = font_extents.height;
|
||||
maximumAdvancement = NSMakeSize(font_extents.max_x_advance,
|
||||
|
@ -153,6 +154,14 @@
|
|||
return YES;
|
||||
}
|
||||
|
||||
// FIXME: This function is not exported by Cairo
|
||||
extern
|
||||
cairo_status_t
|
||||
_cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t *scaled_font,
|
||||
const char *utf8,
|
||||
cairo_glyph_t **glyphs,
|
||||
int *num_glyphs);
|
||||
|
||||
static
|
||||
cairo_glyph_t _cairo_glyph_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph)
|
||||
{
|
||||
|
@ -216,7 +225,6 @@ cairo_glyph_t _cairo_glyph_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph
|
|||
cairo_glyph_t *glyphs = NULL;
|
||||
int num_glyphs;
|
||||
|
||||
// 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);
|
||||
|
@ -256,14 +264,17 @@ cairo_glyph_t _cairo_glyph_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph
|
|||
- (void) drawGlyphs: (const NSGlyph*)glyphs
|
||||
length: (int)length
|
||||
on: (cairo_t*)ct
|
||||
atX: (double)dx
|
||||
y: (double)dy
|
||||
{
|
||||
static cairo_glyph_t *cglyphs = NULL;
|
||||
static int maxlength = 0;
|
||||
size_t i;
|
||||
cairo_text_extents_t gext;
|
||||
cairo_matrix_t font_matrix;
|
||||
double dx, dy;
|
||||
|
||||
cairo_get_current_point(ct, &dx, &dy);
|
||||
// FIXME: Need some adjustment here
|
||||
dy -= 5;
|
||||
|
||||
if (length > maxlength)
|
||||
{
|
||||
|
|
|
@ -162,14 +162,10 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
|
|||
|
||||
- (void) GSSetDevice: (void *)device : (int)x : (int)y
|
||||
{
|
||||
CairoInfo cairo_info;
|
||||
|
||||
ASSIGN(_surface, [CairoSurface surfaceForDevice: device depthInfo: &cairo_info]);
|
||||
DESTROY(_surface);
|
||||
_surface = [[CairoSurface alloc] initWithDevice: device];
|
||||
_offset = NSMakePoint(x, y);
|
||||
/*
|
||||
NSLog(@"before: surface %p on state %p",
|
||||
cairo_get_target(_ct), self);
|
||||
*/
|
||||
|
||||
[self DPSinitgraphics];
|
||||
/*
|
||||
NSLog(@"after: surface %p on state %p %@",
|
||||
|
@ -326,7 +322,7 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
|
|||
c[b + 1] = 0;
|
||||
|
||||
cairo_text_path(_ct, c);
|
||||
free (c);
|
||||
free(c);
|
||||
}
|
||||
|
||||
- (void) DPSshow: (const char *)s
|
||||
|
@ -367,8 +363,8 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
|
|||
}
|
||||
|
||||
ASSIGN(_font, fontref);
|
||||
//cairo_set_font_face(_ct, ((CairoFontInfo *)_font)->xrFont);
|
||||
//cairo_set_font_matrix(_ct, matrix);
|
||||
//cairo_set_font_face(_ct, [((CairoFontInfo *)_font)->_faceInfo fontFace]);
|
||||
//cairo_set_font_matrix(_ct, ((CairoFontInfo *)_font)->matrix);
|
||||
}
|
||||
|
||||
- (void) GSSetFontSize: (float)size
|
||||
|
@ -411,18 +407,9 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
|
|||
|
||||
- (void) GSShowGlyphs: (const NSGlyph *)glyphs : (size_t)length
|
||||
{
|
||||
double dx, dy;
|
||||
|
||||
|
||||
cairo_get_current_point(_ct, &dx, &dy);
|
||||
|
||||
// FIXME: Need some adjustment here
|
||||
dy -= 5;
|
||||
[_font drawGlyphs: glyphs
|
||||
length: length
|
||||
on: _ct
|
||||
atX: dx
|
||||
y: dy];
|
||||
on: _ct];
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -679,14 +666,12 @@ _log_matrix(cairo_t * ct)
|
|||
{
|
||||
double dx, dy;
|
||||
|
||||
//FIXME();
|
||||
cairo_get_current_point(_ct, &dx, &dy);
|
||||
return NSMakePoint(dx, dy);
|
||||
}
|
||||
|
||||
- (void) DPSarc: (float)x : (float)y : (float)r : (float)angle1 : (float)angle2
|
||||
{
|
||||
//NSLog(@"%g %g", angle1, angle2);
|
||||
cairo_arc(_ct, x, y, r, angle1 * M_PI / 180, angle2 * M_PI / 180);
|
||||
}
|
||||
|
||||
|
@ -756,12 +741,12 @@ _log_matrix(cairo_t * ct)
|
|||
|
||||
- (void) DPSflattenpath
|
||||
{
|
||||
/* recheck this in plrm */
|
||||
cairo_path_t *path;
|
||||
|
||||
path = cairo_copy_path_flat(_ct);
|
||||
cairo_new_path(_ct);
|
||||
cairo_append_path(_ct, path);
|
||||
cairo_path_destroy(path);
|
||||
}
|
||||
|
||||
- (void) DPSinitclip
|
||||
|
@ -1024,6 +1009,7 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
|
|||
cairo_surface_t *surface;
|
||||
unsigned char *tmp;
|
||||
int i = 0;
|
||||
int j;
|
||||
unsigned int pixels = pixelsHigh * pixelsWide;
|
||||
const unsigned char *bits = data[0];
|
||||
|
||||
|
@ -1042,7 +1028,7 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
|
|||
{
|
||||
case 32:
|
||||
tmp = objc_malloc(pixels * 4);
|
||||
while (i < pixels*4)
|
||||
while (i < pixels * 4)
|
||||
{
|
||||
tmp[i+0] = bits[i+2];
|
||||
tmp[i+1] = bits[i+1];
|
||||
|
@ -1054,6 +1040,19 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
|
|||
format = CAIRO_FORMAT_ARGB32;
|
||||
break;
|
||||
case 24:
|
||||
tmp = objc_malloc(pixels * 4);
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (i < pixels * 4)
|
||||
{
|
||||
tmp[i+0] = bits[j+2];
|
||||
tmp[i+1] = bits[j+1];
|
||||
tmp[i+2] = bits[j+0];
|
||||
tmp[i+3] = 0;
|
||||
i += 4;
|
||||
j += 3;
|
||||
}
|
||||
bits = tmp;
|
||||
format = CAIRO_FORMAT_RGB24;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -31,8 +31,6 @@
|
|||
@class XGCairoSurface;
|
||||
#endif
|
||||
|
||||
static CairoSurface **surface_list;
|
||||
static int num_cairo_surfaces;
|
||||
static Class __defaultSurfaceClass;
|
||||
|
||||
@implementation CairoSurface
|
||||
|
@ -54,73 +52,14 @@ static Class __defaultSurfaceClass;
|
|||
}
|
||||
}
|
||||
|
||||
+ (void) _listSurface
|
||||
+ (id) allocWithZone: (NSZone*)zone
|
||||
{
|
||||
int i;
|
||||
id str = @"surfaces :";
|
||||
|
||||
if (surface_list == NULL)
|
||||
{
|
||||
NSLog(@"no surface");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < num_cairo_surfaces; i++)
|
||||
{
|
||||
str = [NSString stringWithFormat: @"%@ %p", str, surface_list[i]];
|
||||
}
|
||||
NSLog(str);
|
||||
}
|
||||
|
||||
+ (CairoSurface *) surfaceForDevice: (void *)device
|
||||
depthInfo: (CairoInfo *)cairoInfo
|
||||
{
|
||||
id newsurface;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_cairo_surfaces; i++)
|
||||
{
|
||||
if (surface_list[i]->gsDevice == device)
|
||||
{
|
||||
return surface_list[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* a surface for the device isn't found
|
||||
* create a new one */
|
||||
|
||||
newsurface =[self createSurfaceForDevice: device depthInfo:cairoInfo];
|
||||
num_cairo_surfaces++;
|
||||
surface_list = realloc (surface_list, sizeof (void *) * num_cairo_surfaces);
|
||||
|
||||
if (!surface_list)
|
||||
{
|
||||
NSLog(@"Woah.. buy some memory man! CairoSurface.m meet OOMKiller! %d",
|
||||
__LINE__);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
surface_list[num_cairo_surfaces - 1] = newsurface;
|
||||
|
||||
return newsurface;
|
||||
}
|
||||
|
||||
+ (CairoSurface *) createSurfaceForDevice: (void *)device
|
||||
depthInfo: (CairoInfo *)cairoInfo
|
||||
{
|
||||
if (__defaultSurfaceClass == self)
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [__defaultSurfaceClass createSurfaceForDevice: device depthInfo: cairoInfo];
|
||||
return NSAllocateObject(__defaultSurfaceClass, 0, zone);
|
||||
}
|
||||
|
||||
- (id) initWithDevice: (void *) device
|
||||
{
|
||||
/* TODO FIXME make a more abstract struct for the device */
|
||||
/* _surface = cairo_surface_create_for_image(); */
|
||||
[self subclassResponsibility:_cmd];
|
||||
|
||||
return self;
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <math.h>
|
||||
#include "cairo/XGCairoGlitzSurface.h"
|
||||
|
||||
|
@ -29,27 +28,6 @@
|
|||
|
||||
@implementation XGCairoGlitzSurface
|
||||
|
||||
+ (CairoSurface *) createSurfaceForDevice: (void *)device
|
||||
depthInfo: (CairoInfo *)cairoInfo
|
||||
{
|
||||
#define NEWGSWINDEVICE ((gswindow_device_t *)device)
|
||||
XGCairoGlitzSurface *surface;
|
||||
|
||||
surface = [[self alloc] initWithDevice:NEWGSWINDEVICE];
|
||||
|
||||
|
||||
NSAssert(NEWGSWINDEVICE->buffer, @"FIXME! CairoSurface: Strange, a window doesn't have buffer");
|
||||
|
||||
return surface;
|
||||
#undef NEWGSWINDEVICE
|
||||
}
|
||||
|
||||
|
||||
- (NSString *) description
|
||||
{
|
||||
return [NSString stringWithFormat: @"<XGCairoSurface %p xr:%p>", self, NULL];
|
||||
}
|
||||
|
||||
- (id) initWithDevice: (void *)device
|
||||
{
|
||||
glitz_format_t *format;
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <math.h>
|
||||
#include "cairo/XGCairoSurface.h"
|
||||
#include <cairo-xlib.h>
|
||||
|
@ -29,17 +28,23 @@
|
|||
|
||||
@implementation XGCairoSurface
|
||||
|
||||
+ (CairoSurface *) createSurfaceForDevice: (void *)device
|
||||
depthInfo: (CairoInfo *)cairoInfo
|
||||
{
|
||||
return [[self alloc] initWithDevice: device];
|
||||
}
|
||||
|
||||
- (id) initWithDevice: (void *)device
|
||||
{
|
||||
Display *dpy;
|
||||
Drawable drawable;
|
||||
|
||||
gsDevice = device;
|
||||
|
||||
NSAssert(GSWINDEVICE->buffer, @"FIXME! CairoSurface: Strange, a window doesn't have buffer");
|
||||
dpy = GSWINDEVICE->display;
|
||||
if (GSWINDEVICE->type != NSBackingStoreNonretained)
|
||||
{
|
||||
drawable = GSWINDEVICE->buffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
drawable = GSWINDEVICE->ident;
|
||||
}
|
||||
|
||||
/*
|
||||
if (GSWINDEVICE->type != NSBackingStoreNonretained)
|
||||
{
|
||||
|
@ -50,24 +55,14 @@
|
|||
}
|
||||
*/
|
||||
|
||||
/* 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)));
|
||||
_surface = cairo_xlib_surface_create(dpy,
|
||||
drawable,
|
||||
DefaultVisual(dpy, DefaultScreen(dpy)),
|
||||
GSWINDEVICE->xframe.size.width,
|
||||
GSWINDEVICE->xframe.size.height);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) logDevice
|
||||
{
|
||||
NSLog(@"device %p id:%p buff:%p", self, GSWINDEVICE->ident, GSWINDEVICE->buffer);
|
||||
}
|
||||
|
||||
- (NSSize) size
|
||||
{
|
||||
return GSWINDEVICE->xframe.size;
|
||||
|
|
|
@ -28,20 +28,6 @@
|
|||
|
||||
@implementation XGCairoXImageSurface
|
||||
|
||||
+ (CairoSurface *) createSurfaceForDevice: (void *)device
|
||||
depthInfo: (CairoInfo *)cairoInfo
|
||||
{
|
||||
#define NEWGSWINDEVICE ((gswindow_device_t *)device)
|
||||
XGCairoXImageSurface *surface;
|
||||
|
||||
surface = [[self alloc] initWithDevice:NEWGSWINDEVICE];
|
||||
|
||||
NSAssert(NEWGSWINDEVICE->buffer, @"FIXME! CairoSurface: Strange, a window doesn't have buffer");
|
||||
|
||||
return surface;
|
||||
#undef NEWGSWINDEVICE
|
||||
}
|
||||
|
||||
- (id) initWithDevice: (void *)device
|
||||
{
|
||||
/* FIXME format is ignore when Visual isn't NULL
|
||||
|
@ -62,6 +48,7 @@
|
|||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSSize) size
|
||||
{
|
||||
return GSWINDEVICE->xframe.size;
|
||||
|
|
Loading…
Reference in a new issue