mirror of
https://github.com/gnustep/libs-back.git
synced 2025-02-23 11:51:27 +00:00
Small imporvements for Cairo backend.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@20037 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f6f31db46f
commit
63366359cf
5 changed files with 180 additions and 125 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
2004-09-09 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Tools/xpbs.m (-[XPbOwner getSelectionData:type:], -[XPbOwner
|
||||
xProvideSelection:]): Removed some compiler warnings.
|
||||
* Source/cairo/CairoGState.m (-DPSimage:...:): Slightly improved.
|
||||
(-compositeGState:fromRect:toPoint:op:fraction:) New method
|
||||
(-compositeGState:fromRect:toPoint:op:,
|
||||
-dissolveGState:fromRect:toPoint:delta:) Implemented via new method.
|
||||
Added all missing colour conversions.
|
||||
(GSShowGlyphs::) Use new method on CairoFontInfo.
|
||||
* Header/cairo/CairoFontInfo.h (-drawGlyphs:length:on:atX:y:) New method.
|
||||
* Source/cairo/CairoFontInfo.m (-drawGlyphs:length:on:atX:y:) New method.
|
||||
Moved some includes from header to here, extracted method
|
||||
[setupAttributes] and other cleanup.
|
||||
|
||||
2004-09-08 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Headers/x11/XGServer.h: Add 8bit fast drawing.
|
||||
|
|
|
@ -24,11 +24,7 @@
|
|||
#define WOOM_CairoFontInfo_h
|
||||
|
||||
#include <GNUstepGUI/GSFontInfo.h>
|
||||
#include <Foundation/NSMapTable.h>
|
||||
|
||||
#include "cairo/CairoFontEnumerator.h"
|
||||
#include "cairo/CairoFontManager.h"
|
||||
|
||||
#include "cairo/CairoFaceInfo.h"
|
||||
#include <cairo.h>
|
||||
|
||||
@interface CairoFontInfo : GSFontInfo
|
||||
|
@ -51,6 +47,11 @@
|
|||
NSSize *_cachedSizes;
|
||||
}
|
||||
- (void) setCacheSize:(unsigned int)size;
|
||||
- (void) drawGlyphs: (const NSGlyph*)glyphs
|
||||
length: (int)length
|
||||
on: (cairo_t*)ct
|
||||
atX: (double)dx
|
||||
y: (double)dy;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
|
@ -20,8 +20,11 @@
|
|||
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "cairo/CairoFontInfo.h"
|
||||
#include <AppKit/NSAffineTransform.h>
|
||||
#include "cairo/CairoFontInfo.h"
|
||||
#include "cairo/CairoFontEnumerator.h"
|
||||
#include "cairo/CairoFontManager.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <cairo.h>
|
||||
|
||||
|
@ -49,22 +52,47 @@
|
|||
_cachedGlyphs = malloc(sizeof(unsigned int) * size);
|
||||
}
|
||||
|
||||
- (void) createCairoFontWithIdentity: (void *)ident
|
||||
- (BOOL) setupAttributes
|
||||
{
|
||||
/* subclass should override */
|
||||
cairo_matrix_t *font_matrix;
|
||||
cairo_font_extents_t font_extents;
|
||||
|
||||
cairo_select_font(_cf,[_faceInfo cairoCName],[_faceInfo cairoSlant],
|
||||
/* do not forget to check for font specific
|
||||
* cache size from face info FIXME FIXME
|
||||
*/
|
||||
ASSIGN(_faceInfo, [CairoFontManager fontWithName: fontName]);
|
||||
if (!_faceInfo)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
_cachedSizes = NULL;
|
||||
[self setCacheSize: [_faceInfo cacheSize]];
|
||||
|
||||
/* setting GSFontInfo:
|
||||
* weight, traits, familyName,
|
||||
* mostCompatibleStringEncoding, encodingScheme,
|
||||
*/
|
||||
|
||||
weight = [_faceInfo weight];
|
||||
traits = [_faceInfo traits];
|
||||
familyName = [[_faceInfo familyName] copy];
|
||||
mostCompatibleStringEncoding = NSUTF8StringEncoding;
|
||||
encodingScheme = @"iso10646-1";
|
||||
|
||||
/* 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);
|
||||
/*
|
||||
NSLog(@"%g %g %g %g %g %g",matrix[0],matrix[1],matrix[2],matrix[3],matrix[4],matrix[5]);
|
||||
*/
|
||||
cairo_matrix_destroy(font_matrix);
|
||||
|
||||
cairo_current_font_extents(_cf, &font_extents);
|
||||
ascender = font_extents.ascent;
|
||||
|
@ -72,7 +100,10 @@
|
|||
xHeight = font_extents.height;
|
||||
maximumAdvancement = NSMakeSize(font_extents.max_x_advance,
|
||||
font_extents.max_y_advance);
|
||||
cairo_matrix_destroy(font_matrix);
|
||||
fontBBox = NSMakeRect(0, descender,
|
||||
maximumAdvancement.width, ascender + descender);
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (id) initWithFontName: (NSString *)name
|
||||
|
@ -82,32 +113,9 @@
|
|||
//NSLog(@"initWithFontName %@",name);
|
||||
[super init];
|
||||
|
||||
/* do not forget to check for font specific
|
||||
* cache size from face info FIXME FIXME
|
||||
*/
|
||||
ASSIGN(_faceInfo, [CairoFontManager fontWithName: name]);
|
||||
if (!_faceInfo)
|
||||
{
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
_cachedSizes = NULL;
|
||||
[self setCacheSize: [_faceInfo cacheSize]];
|
||||
_screenFont = p_screenFont;
|
||||
|
||||
/* setting GSFontInfo:
|
||||
* weight, traits, fontName, familyName,
|
||||
* matrix, mostCompatibleStringEncoding, encodingScheme,
|
||||
*/
|
||||
|
||||
weight = [_faceInfo weight];
|
||||
traits = [_faceInfo traits];
|
||||
fontName = [name copy];
|
||||
familyName = [[_faceInfo familyName] copy];
|
||||
memcpy(matrix, fmatrix, sizeof(matrix));
|
||||
mostCompatibleStringEncoding = NSUTF8StringEncoding;
|
||||
encodingScheme = @"iso10646-1";
|
||||
|
||||
if (_screenFont)
|
||||
{
|
||||
|
@ -119,16 +127,12 @@
|
|||
matrix[3] = ceil(matrix[3]);
|
||||
}
|
||||
|
||||
/* setting GSFontInfo:
|
||||
* xHeight, pix_width, pix_height
|
||||
*/
|
||||
if (![self setupAttributes])
|
||||
{
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
_cf = cairo_create ();
|
||||
[self createCairoFontWithIdentity: _faceInfo];
|
||||
|
||||
fontBBox = NSMakeRect(0, descender,
|
||||
maximumAdvancement.width, ascender + descender);
|
||||
//NSLog(NSStringFromRect(fontBBox));
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -149,7 +153,6 @@
|
|||
|
||||
- (NSSize) advancementForGlyph: (NSGlyph)glyph
|
||||
{
|
||||
/* subclass should override */
|
||||
cairo_glyph_t cglyph;
|
||||
cairo_text_extents_t ctext;
|
||||
int entry;
|
||||
|
@ -169,13 +172,11 @@
|
|||
_cachedGlyphs[entry] = glyph;
|
||||
_cachedSizes[entry] = NSMakeSize(ctext.x_advance, ctext.y_advance);
|
||||
|
||||
//NSLog(NSStringFromSize(_cachedSizes[entry]));
|
||||
return _cachedSizes[entry];
|
||||
}
|
||||
|
||||
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
|
||||
{
|
||||
/* subclass should override */
|
||||
cairo_glyph_t cglyph;
|
||||
cairo_text_extents_t ctext;
|
||||
|
||||
|
@ -189,32 +190,12 @@
|
|||
ctext.width, ctext.height);
|
||||
}
|
||||
|
||||
- (NSPoint) positionOfGlyph: (NSGlyph)g
|
||||
precededByGlyph: (NSGlyph)prev
|
||||
isNominal: (BOOL *)nominal
|
||||
{
|
||||
NSSize size;
|
||||
|
||||
/* subclass should override */
|
||||
if (nominal)
|
||||
*nominal = YES;
|
||||
|
||||
if (g == NSControlGlyph || prev == NSControlGlyph)
|
||||
{
|
||||
return NSZeroPoint;
|
||||
}
|
||||
|
||||
size = [self advancementForGlyph: prev];
|
||||
return NSMakePoint(size.width, size.height);
|
||||
}
|
||||
|
||||
- (float) widthOfString: (NSString *)string
|
||||
{
|
||||
/* subclass should override */
|
||||
cairo_text_extents_t ctext;
|
||||
|
||||
cairo_text_extents(_cf, [string UTF8String], &ctext);
|
||||
//NSLog (@"widthOfString %@ = %g", string, ctext.width);
|
||||
|
||||
return ctext.width;
|
||||
}
|
||||
|
||||
|
@ -299,9 +280,34 @@
|
|||
#endif
|
||||
}
|
||||
|
||||
- (void) set
|
||||
- (void) drawGlyphs: (const NSGlyph*)glyphs
|
||||
length: (int)length
|
||||
on: (cairo_t*)ct
|
||||
atX: (double)dx
|
||||
y: (double)dy
|
||||
{
|
||||
NSLog(@"ignore -set method of font '%@'\n", fontName);
|
||||
}
|
||||
static cairo_glyph_t *cglyphs = NULL;
|
||||
static int maxlength = 0;
|
||||
size_t i;
|
||||
cairo_text_extents_t gext;
|
||||
|
||||
if (length > maxlength)
|
||||
{
|
||||
maxlength = length;
|
||||
cglyphs = realloc(cglyphs, sizeof(cairo_glyph_t) * maxlength);
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
cglyphs[i].index = glyphs[i] + -29; /* experimental */
|
||||
cglyphs[i].x = dx;
|
||||
cglyphs[i].y = dy;
|
||||
cairo_glyph_extents(ct, cglyphs + i, 1, &gext);
|
||||
dx += gext.x_advance;
|
||||
dy += gext.y_advance;
|
||||
}
|
||||
|
||||
cairo_show_glyphs(ct, cglyphs, length);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <AppKit/NSBezierPath.h>
|
||||
#include <AppKit/NSColor.h>
|
||||
#include <AppKit/NSGraphics.h>
|
||||
#include "cairo/CairoGState.h"
|
||||
#include "cairo/CairoFontInfo.h"
|
||||
#include "cairo/CairoSurface.h"
|
||||
|
@ -28,7 +29,6 @@
|
|||
#include "NSBezierPathCairo.h"
|
||||
#include <math.h>
|
||||
|
||||
#define NEEDS_CSMK() NSLog(@"Need CSMK %@ %s", [self description], sel_get_name(_cmd))
|
||||
#define FIXME() NSLog(@":::FIXME::: %@ %s", [self description], sel_get_name(_cmd))
|
||||
|
||||
static cairo_matrix_t *local_matrix;
|
||||
|
@ -182,12 +182,27 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
|
|||
|
||||
- (void) DPScurrentgray: (float *)gray
|
||||
{
|
||||
NEEDS_CSMK();
|
||||
double dr, dg, db;
|
||||
|
||||
cairo_current_rgb_color(_ct, &dr, &dg, &db);
|
||||
*gray = (dr + dg + db) / 3.0;
|
||||
}
|
||||
|
||||
- (void) DPScurrenthsbcolor: (float *)h : (float *)s : (float *)b
|
||||
{
|
||||
NEEDS_CSMK();
|
||||
NSColor *color;
|
||||
double dr, dg, db;
|
||||
float alpha;
|
||||
|
||||
cairo_current_rgb_color(_ct, &dr, &dg, &db);
|
||||
color = [NSColor colorWithCalibratedRed: dr
|
||||
green: dg
|
||||
blue: db
|
||||
alpha: 1.0];
|
||||
[color getHue: h
|
||||
saturation: s
|
||||
brightness: b
|
||||
alpha: &alpha];
|
||||
}
|
||||
|
||||
- (void) DPScurrentrgbcolor: (float *)r : (float *)g : (float *)b
|
||||
|
@ -207,7 +222,12 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
|
|||
|
||||
- (void) DPSsetcmykcolor: (float)c : (float)m : (float)y : (float)k
|
||||
{
|
||||
NEEDS_CSMK();
|
||||
double r, g, b;
|
||||
|
||||
r = 1 - c;
|
||||
g = 1 - m;
|
||||
b = 1 - y;
|
||||
cairo_set_rgb_color(_ct, r, g, b);
|
||||
}
|
||||
|
||||
- (void) DPSsetgray: (float)gray
|
||||
|
@ -363,32 +383,15 @@ _flipCairoSurfaceMatrix(cairo_t *ct, CairoSurface *surface)
|
|||
|
||||
- (void) GSShowGlyphs: (const NSGlyph *)glyphs : (size_t)length
|
||||
{
|
||||
static cairo_glyph_t *cglyphs = NULL;
|
||||
static int maxlength = 0;
|
||||
size_t i;
|
||||
double dx, dy;
|
||||
cairo_text_extents_t gext;
|
||||
|
||||
cairo_current_point(_ct, &dx, &dy);
|
||||
|
||||
/* experimental, should do this in fontinfo */
|
||||
if (length > maxlength)
|
||||
{
|
||||
maxlength = length;
|
||||
cglyphs = realloc(cglyphs, sizeof(cairo_glyph_t) * maxlength);
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
cglyphs[i].index = glyphs[i] + -29; /* experimental */
|
||||
cglyphs[i].x = dx;
|
||||
cglyphs[i].y = dy;
|
||||
cairo_glyph_extents(_ct, cglyphs + i, 1, &gext);
|
||||
dx += gext.x_advance;
|
||||
dy += gext.y_advance;
|
||||
}
|
||||
|
||||
cairo_show_glyphs(_ct, cglyphs, length);
|
||||
[_font drawGlyphs: glyphs
|
||||
length: length
|
||||
on: _ct
|
||||
atX: dx
|
||||
y: dy];
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1001,11 +1004,19 @@ _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));
|
||||
*/
|
||||
if (isPlanar || !([colorSpaceName isEqualToString: NSDeviceRGBColorSpace] ||
|
||||
[colorSpaceName isEqualToString: NSCalibratedRGBColorSpace]))
|
||||
{
|
||||
NSLog(@"Image format not support");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (bitsPerSample * samplesPerPixel)
|
||||
{
|
||||
case 32:
|
||||
|
@ -1015,18 +1026,18 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
|
|||
format = CAIRO_FORMAT_RGB24;
|
||||
break;
|
||||
default:
|
||||
NSLog(@"not support");
|
||||
exit(1);
|
||||
NSLog(@"Image format not support");
|
||||
return;
|
||||
}
|
||||
// [self DPSinitclip];
|
||||
|
||||
tstruct =[matrix transformStruct];
|
||||
tstruct = [matrix transformStruct];
|
||||
/*
|
||||
NSLog(@"%g %g %g %g %g %g",
|
||||
tstruct.m11, tstruct.m12,
|
||||
tstruct.m21, tstruct.m22,
|
||||
tstruct.tX, tstruct.tY);
|
||||
*/
|
||||
*/
|
||||
|
||||
ict = cairo_create();
|
||||
[_surface setAsTargetOfCairo: ict];
|
||||
|
@ -1036,18 +1047,21 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
|
|||
tstruct.m21, tstruct.m22, tstruct.tX, tstruct.tY);
|
||||
cairo_concat_matrix(ict, local_matrix);
|
||||
|
||||
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_move_to(ict, 10, 10);
|
||||
cairo_set_rgb_color(ict, 0, 1, 0);
|
||||
cairo_rel_line_to(ict, 0, pixelsHigh - 20);
|
||||
cairo_rel_line_to(ict, pixelsWide - 20, 0);
|
||||
cairo_rel_line_to(ict, 0, -pixelsHigh + 20);
|
||||
cairo_fill(ict);
|
||||
cairo_surface_set_matrix(surface, local_matrix);
|
||||
cairo_show_surface(ict,
|
||||
surface,
|
||||
pixelsWide,
|
||||
pixelsHigh);
|
||||
cairo_surface_destroy(surface);
|
||||
cairo_destroy(ict);
|
||||
*/
|
||||
}
|
||||
|
||||
- (void) compositerect: (NSRect)aRect op: (NSCompositingOperation)op
|
||||
|
@ -1062,30 +1076,52 @@ _set_op(cairo_t * ct, NSCompositingOperation op)
|
|||
fromRect: (NSRect)aRect
|
||||
toPoint: (NSPoint)aPoint
|
||||
op: (NSCompositingOperation)op
|
||||
fraction: (float)delta
|
||||
{
|
||||
cairo_surface_t *src;
|
||||
|
||||
_set_op(_ct, op);
|
||||
cairo_save(_ct);
|
||||
cairo_translate(_ct, aPoint.x, aPoint.y);
|
||||
/*
|
||||
NSLog(NSStringFromRect(aRect));
|
||||
NSLog(@"src %p(%p,%@) des %p(%p,%@)",source,cairo_current_target_surface(source->_ct),NSStringFromSize([source->_surface size]),
|
||||
self,cairo_current_target_surface(_ct),NSStringFromSize([_surface size]));
|
||||
*/
|
||||
src = cairo_current_target_surface(source->_ct);
|
||||
cairo_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));
|
||||
|
||||
/*
|
||||
[[NSColor redColor] set];
|
||||
aRect.origin = NSZeroPoint;
|
||||
NSFrameRect(aRect);
|
||||
*/
|
||||
cairo_restore(_ct);
|
||||
}
|
||||
|
||||
- (void) compositeGState: (CairoGState *)source
|
||||
fromRect: (NSRect)aRect
|
||||
toPoint: (NSPoint)aPoint
|
||||
op: (NSCompositingOperation)op
|
||||
{
|
||||
[self compositeGState: source
|
||||
fromRect: aRect
|
||||
toPoint: aPoint
|
||||
op: op
|
||||
fraction: 1.0];
|
||||
}
|
||||
|
||||
- (void) dissolveGState: (CairoGState *)source
|
||||
fromRect: (NSRect)aRect
|
||||
toPoint: (NSPoint)aPoint
|
||||
delta: (float)delta
|
||||
{
|
||||
[self compositeGState: source
|
||||
fromRect: aRect
|
||||
toPoint: aPoint
|
||||
op: NSCompositeSourceOver
|
||||
fraction: delta];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -683,7 +683,7 @@ xErrorHandler(Display *d, XErrorEvent *e)
|
|||
XFree(req_name);
|
||||
XFree(act_name);
|
||||
RELEASE(md);
|
||||
return;
|
||||
return nil;
|
||||
}
|
||||
[md appendBytes: (void *)data length: count];
|
||||
}
|
||||
|
@ -851,13 +851,10 @@ xErrorHandler(Display *d, XErrorEvent *e)
|
|||
- (BOOL) xProvideSelection: (XSelectionRequestEvent*)xEvent
|
||||
{
|
||||
NSArray *types = [_pb types];
|
||||
unsigned numOsTypes = [types count];
|
||||
NSString *osType = nil;
|
||||
Atom xType = XG_NULL;
|
||||
unsigned char *data = 0;
|
||||
int format = 0;
|
||||
int numItems = 0;
|
||||
unsigned i;
|
||||
|
||||
if (xEvent->target == XG_TARGETS)
|
||||
{
|
||||
|
@ -997,7 +994,7 @@ xErrorHandler(Display *d, XErrorEvent *e)
|
|||
[types containsObject: NSStringPboardType])
|
||||
{
|
||||
NSString *s = [_pb stringForType: NSStringPboardType];
|
||||
NSData *d;
|
||||
NSData *d = nil;
|
||||
|
||||
xType = xEvent->target;
|
||||
format = 8;
|
||||
|
|
Loading…
Reference in a new issue