Clean up of font attributes and better protection against _ct being null

in cairo backend.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@24710 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2007-02-27 16:35:31 +00:00
parent 6163436fb0
commit 78ba818f54
8 changed files with 219 additions and 89 deletions

View file

@ -1,3 +1,19 @@
2007-02-27 Fred Kiefer <FredKiefer@gmx.de>
* Source/winlib/Win32FontInfo.m (-setupAttributes:):
Correct setting of maximumAdvancement and add xHeight.
* Source/art/ftfont.m (-initWithFontName:matrix:screenFont:):
Correct setting of maximumAdvancement and xHeight.
* Source/xlib/GSXftFontInfo.m (-setupAttributes:):
Correct setting of maximumAdvancement.
* Source/xlib/XGFont.m(-setupAttributes:): Correct setting of
maximumAdvancement.
* Headers/cairo/CairoFontInfo.h: Add new ivar lineHeight.
* Source/cairo/CairoFontInfo.m (-setupAttributes:):
Correct setting of descender and add lineHeight and xHeight.
* Source/cairo/CairoFontInfo.m (-drawGlyphs:length:on:): Remove adjustment.
* Source/cairo/CairoGState.m: Better protection against _ct being null.
2007-02-27 Nicola Pero <nicola.pero@meta-innovation.com> 2007-02-27 Nicola Pero <nicola.pero@meta-innovation.com>
* Source/GNUmakefile.postamble (config.h): Use MKDIRS, not * Source/GNUmakefile.postamble (config.h): Use MKDIRS, not

View file

@ -31,15 +31,9 @@
{ {
@public @public
cairo_scaled_font_t *_scaled; cairo_scaled_font_t *_scaled;
CairoFaceInfo *_faceInfo; CairoFaceInfo *_faceInfo;
BOOL _screenFont; BOOL _screenFont;
float lineHeight;
/* will be used in GSNFont subclass
NSMapTable *_ligatureMap;
NSMapTable *_kerningMap;
*/
unsigned int _cacheSize; unsigned int _cacheSize;
unsigned int *_cachedGlyphs; unsigned int *_cachedGlyphs;

View file

@ -764,15 +764,13 @@ static FT_Error ft_get_face(FTC_FaceID fid, FT_Library lib, FT_Pointer data, FT_
return self; return self;
} }
// xHeight = ft_size->metrics.height / 64.0; /* TODO: these are _really_ messed up when fonts are flipped */
/* TODO: these are _really_ messed up when fonts are flipped */ /* TODO: need to look carefully at these and make sure they are correct */
/* TODO: need to look acrefully at these and make sure they are correct */
ascender = fabs(((int)ft_size->metrics.ascender) / 64.0); ascender = fabs(((int)ft_size->metrics.ascender) / 64.0);
descender = fabs(((int)ft_size->metrics.descender) / 64.0); descender = fabs(((int)ft_size->metrics.descender) / 64.0);
lineHeight = (int)ft_size->metrics.height / 64.0; lineHeight = (int)ft_size->metrics.height / 64.0;
xHeight = ascender * 0.5; /* TODO */ xHeight = (int)ft_size->metrics.y_ppem / 64.0;
maximumAdvancement maximumAdvancement = NSMakeSize((ft_size->metrics.max_advance / 64.0), 0.0);
= NSMakeSize((ft_size->metrics.max_advance / 64.0), ascender + descender);
fontBBox fontBBox
= NSMakeRect(0, descender, maximumAdvancement.width, ascender + descender); = NSMakeRect(0, descender, maximumAdvancement.width, ascender + descender);

View file

@ -99,14 +99,15 @@
return NO; return NO;
} }
cairo_scaled_font_extents(_scaled, &font_extents); cairo_scaled_font_extents(_scaled, &font_extents);
// FIXME: Need some adjustment here ascender = font_extents.ascent;
ascender = font_extents.ascent + 3; // The FreeType documentation claims this value is already negative, but it isn't.
descender = font_extents.descent; descender = -font_extents.descent;
xHeight = font_extents.height; xHeight = ascender * 0.6;
lineHeight = font_extents.height;
maximumAdvancement = NSMakeSize(font_extents.max_x_advance, maximumAdvancement = NSMakeSize(font_extents.max_x_advance,
font_extents.max_y_advance); font_extents.max_y_advance);
fontBBox = NSMakeRect(0, descender, fontBBox = NSMakeRect(0, descender,
maximumAdvancement.width, ascender + descender); maximumAdvancement.width, ascender - descender);
return YES; return YES;
} }
@ -153,6 +154,11 @@
[super dealloc]; [super dealloc];
} }
- (float) defaultLineHeightForFont
{
return lineHeight;
}
- (BOOL) glyphIsEncoded: (NSGlyph)glyph - (BOOL) glyphIsEncoded: (NSGlyph)glyph
{ {
/* subclass should override */ /* subclass should override */
@ -305,8 +311,6 @@ BOOL _cairo_extents_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph,
return; return;
} }
// FIXME: Need some adjustment here
cairo_rel_move_to(ct, 0.0, -5.0);
cairo_show_text(ct, str); cairo_show_text(ct, str);
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS) if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
{ {

View file

@ -294,15 +294,21 @@
- (void) DPScurrentflat: (float *)flatness - (void) DPScurrentflat: (float *)flatness
{ {
if (_ct)
{
*flatness = cairo_get_tolerance(_ct); *flatness = cairo_get_tolerance(_ct);
}
} }
- (void) DPScurrentlinecap: (int *)linecap - (void) DPScurrentlinecap: (int *)linecap
{ {
cairo_line_cap_t lc; cairo_line_cap_t lc;
if (_ct)
{
lc = cairo_get_line_cap(_ct); lc = cairo_get_line_cap(_ct);
*linecap = lc; *linecap = lc;
}
/* /*
switch (lc) switch (lc)
{ {
@ -326,8 +332,11 @@
{ {
cairo_line_join_t lj; cairo_line_join_t lj;
if (_ct)
{
lj = cairo_get_line_join(_ct); lj = cairo_get_line_join(_ct);
*linejoin = lj; *linejoin = lj;
}
/* /*
switch (lj) switch (lj)
{ {
@ -349,19 +358,33 @@
- (void) DPScurrentlinewidth: (float *)width - (void) DPScurrentlinewidth: (float *)width
{ {
if (_ct)
{
*width = cairo_get_line_width(_ct); *width = cairo_get_line_width(_ct);
}
} }
- (void) DPScurrentmiterlimit: (float *)limit - (void) DPScurrentmiterlimit: (float *)limit
{ {
if (_ct)
{
*limit = cairo_get_miter_limit(_ct); *limit = cairo_get_miter_limit(_ct);
}
} }
- (NSPoint) currentPoint - (NSPoint) currentPoint
{ {
double dx, dy; double dx, dy;
if (_ct)
{
cairo_get_current_point(_ct, &dx, &dy); cairo_get_current_point(_ct, &dx, &dy);
}
else
{
dx = 0.0;
dy = 0.0;
}
return NSMakePoint(dx, dy); return NSMakePoint(dx, dy);
} }
@ -375,6 +398,8 @@
double *dpat; double *dpat;
int i; int i;
if (_ct)
{
i = size; i = size;
dpat = malloc(sizeof(double) * size); dpat = malloc(sizeof(double) * size);
while (i) while (i)
@ -385,31 +410,47 @@
// FIXME: There may be a difference in concept as some dashes look wrong // FIXME: There may be a difference in concept as some dashes look wrong
cairo_set_dash(_ct, dpat, size, doffset); cairo_set_dash(_ct, dpat, size, doffset);
free(dpat); free(dpat);
}
} }
- (void) DPSsetflat: (float)flatness - (void) DPSsetflat: (float)flatness
{ {
if (_ct)
{
cairo_set_tolerance(_ct, flatness); cairo_set_tolerance(_ct, flatness);
}
} }
- (void) DPSsetlinecap: (int)linecap - (void) DPSsetlinecap: (int)linecap
{ {
if (_ct)
{
cairo_set_line_cap(_ct, (cairo_line_cap_t)linecap); cairo_set_line_cap(_ct, (cairo_line_cap_t)linecap);
}
} }
- (void) DPSsetlinejoin: (int)linejoin - (void) DPSsetlinejoin: (int)linejoin
{ {
if (_ct)
{
cairo_set_line_join(_ct, (cairo_line_join_t)linejoin); cairo_set_line_join(_ct, (cairo_line_join_t)linejoin);
}
} }
- (void) DPSsetlinewidth: (float)width - (void) DPSsetlinewidth: (float)width
{ {
if (_ct)
{
cairo_set_line_width(_ct, width); cairo_set_line_width(_ct, width);
}
} }
- (void) DPSsetmiterlimit: (float)limit - (void) DPSsetmiterlimit: (float)limit
{ {
if (_ct)
{
cairo_set_miter_limit(_ct, limit); cairo_set_miter_limit(_ct, limit);
}
} }
- (void) DPSsetstrokeadjust: (int)b - (void) DPSsetstrokeadjust: (int)b
@ -545,12 +586,18 @@
- (void) DPSarc: (float)x : (float)y : (float)r : (float)angle1 : (float)angle2 - (void) DPSarc: (float)x : (float)y : (float)r : (float)angle1 : (float)angle2
{ {
if (_ct)
{
cairo_arc(_ct, x, y, r, angle1 * M_PI / 180, angle2 * M_PI / 180); cairo_arc(_ct, x, y, r, angle1 * M_PI / 180, angle2 * M_PI / 180);
}
} }
- (void) DPSarcn: (float)x : (float)y : (float)r : (float)angle1 : (float)angle2 - (void) DPSarcn: (float)x : (float)y : (float)r : (float)angle1 : (float)angle2
{ {
if (_ct)
{
cairo_arc_negative(_ct, x, y, r, angle1 * M_PI / 180, angle2 * M_PI / 180); cairo_arc_negative(_ct, x, y, r, angle1 * M_PI / 180, angle2 * M_PI / 180);
}
} }
- (void)DPSarct: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)r - (void)DPSarct: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)r
@ -562,52 +609,76 @@
- (void) DPSclip - (void) DPSclip
{ {
if (_ct)
{
cairo_clip(_ct); cairo_clip(_ct);
}
} }
- (void) DPSclosepath - (void) DPSclosepath
{ {
if (_ct)
{
cairo_close_path(_ct); cairo_close_path(_ct);
}
} }
- (void) DPScurveto: (float)x1 : (float)y1 : (float)x2 - (void) DPScurveto: (float)x1 : (float)y1 : (float)x2
: (float)y2 : (float)x3 : (float)y3 : (float)y2 : (float)x3 : (float)y3
{ {
if (_ct)
{
cairo_curve_to(_ct, x1, y1, x2, y2, x3, y3); cairo_curve_to(_ct, x1, y1, x2, y2, x3, y3);
}
} }
- (void) DPSeoclip - (void) DPSeoclip
{ {
if (_ct)
{
cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_EVEN_ODD);
cairo_clip(_ct); cairo_clip(_ct);
cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_WINDING); cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_WINDING);
}
} }
- (void) DPSeofill - (void) DPSeofill
{ {
if (_ct)
{
cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_EVEN_ODD);
cairo_fill(_ct); cairo_fill(_ct);
cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_WINDING); cairo_set_fill_rule(_ct, CAIRO_FILL_RULE_WINDING);
}
} }
- (void) DPSfill - (void) DPSfill
{ {
if (_ct)
{
cairo_fill(_ct); cairo_fill(_ct);
}
} }
- (void) DPSflattenpath - (void) DPSflattenpath
{ {
cairo_path_t *cpath; cairo_path_t *cpath;
if (_ct)
{
cpath = cairo_copy_path_flat(_ct); cpath = cairo_copy_path_flat(_ct);
cairo_new_path(_ct); cairo_new_path(_ct);
cairo_append_path(_ct, cpath); cairo_append_path(_ct, cpath);
cairo_path_destroy(cpath); cairo_path_destroy(cpath);
}
} }
- (void) DPSinitclip - (void) DPSinitclip
{ {
if (_ct)
{
cairo_reset_clip(_ct); cairo_reset_clip(_ct);
}
} }
- (void) DPSlineto: (float)x : (float)y - (void) DPSlineto: (float)x : (float)y
@ -641,6 +712,11 @@
cairo_path_data_t *data; cairo_path_data_t *data;
NSBezierPath *bpath =[NSBezierPath bezierPath]; NSBezierPath *bpath =[NSBezierPath bezierPath];
if (!_ct)
{
return bpath;
}
cpath = cairo_copy_path(_ct); cpath = cairo_copy_path(_ct);
for (i=0; i < cpath->num_data; i += cpath->data[i].header.length) for (i=0; i < cpath->num_data; i += cpath->data[i].header.length)
@ -673,33 +749,45 @@
- (void) DPSrcurveto: (float)x1 : (float)y1 : (float)x2 - (void) DPSrcurveto: (float)x1 : (float)y1 : (float)x2
: (float)y2 : (float)x3 : (float)y3 : (float)y2 : (float)x3 : (float)y3
{ {
if (_ct)
{
cairo_rel_curve_to(_ct, x1, y1, x2, y2, x3, y3); cairo_rel_curve_to(_ct, x1, y1, x2, y2, x3, y3);
}
} }
- (void) DPSrectclip: (float)x : (float)y : (float)w : (float)h - (void) DPSrectclip: (float)x : (float)y : (float)w : (float)h
{ {
if (_ct)
{
cairo_new_path(_ct); cairo_new_path(_ct);
cairo_rectangle(_ct, x, y, w, h); cairo_rectangle(_ct, x, y, w, h);
cairo_clip(_ct); cairo_clip(_ct);
cairo_new_path(_ct); cairo_new_path(_ct);
}
} }
- (void) DPSrectfill: (float)x : (float)y : (float)w : (float)h - (void) DPSrectfill: (float)x : (float)y : (float)w : (float)h
{ {
if (_ct)
{
cairo_save(_ct); cairo_save(_ct);
cairo_new_path(_ct); cairo_new_path(_ct);
cairo_rectangle(_ct, x, y, w, h); cairo_rectangle(_ct, x, y, w, h);
cairo_fill(_ct); cairo_fill(_ct);
cairo_restore(_ct); cairo_restore(_ct);
}
} }
- (void) DPSrectstroke: (float)x : (float)y : (float)w : (float)h - (void) DPSrectstroke: (float)x : (float)y : (float)w : (float)h
{ {
if (_ct)
{
cairo_save(_ct); cairo_save(_ct);
cairo_new_path(_ct); cairo_new_path(_ct);
cairo_rectangle(_ct, x, y, w, h); cairo_rectangle(_ct, x, y, w, h);
cairo_stroke(_ct); cairo_stroke(_ct);
cairo_restore(_ct); cairo_restore(_ct);
}
} }
- (void) DPSreversepath - (void) DPSreversepath
@ -712,17 +800,26 @@
- (void) DPSrlineto: (float)x : (float)y - (void) DPSrlineto: (float)x : (float)y
{ {
if (_ct)
{
cairo_rel_line_to(_ct, x, y); cairo_rel_line_to(_ct, x, y);
}
} }
- (void) DPSrmoveto: (float)x : (float)y - (void) DPSrmoveto: (float)x : (float)y
{ {
if (_ct)
{
cairo_rel_move_to(_ct, x, y); cairo_rel_move_to(_ct, x, y);
}
} }
- (void) DPSstroke - (void) DPSstroke
{ {
if (_ct)
{
cairo_stroke(_ct); cairo_stroke(_ct);
}
} }
- (void) GSSendBezierPath: (NSBezierPath *)bpath - (void) GSSendBezierPath: (NSBezierPath *)bpath
@ -736,6 +833,11 @@
SEL elmsel = @selector(elementAtIndex: associatedPoints:); SEL elmsel = @selector(elementAtIndex: associatedPoints:);
IMP elmidx = [bpath methodForSelector: elmsel]; IMP elmidx = [bpath methodForSelector: elmsel];
if (!_ct)
{
return;
}
cairo_new_path(_ct); cairo_new_path(_ct);
n = [bpath elementCount]; n = [bpath elementCount];
@ -786,6 +888,11 @@
NSMutableData *data; NSMutableData *data;
unsigned char *cdata; unsigned char *cdata;
if (!_ct)
{
return nil;
}
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);
@ -934,6 +1041,11 @@ _set_op(cairo_t *ct, NSCompositingOperation op)
NSLog(@"%@ DPSimage %dx%d (%p)", self, pixelsWide, pixelsHigh, NSLog(@"%@ DPSimage %dx%d (%p)", self, pixelsWide, pixelsHigh,
cairo_get_target(_ct)); cairo_get_target(_ct));
*/ */
if (!_ct)
{
return;
}
if (isPlanar || !([colorSpaceName isEqualToString: NSDeviceRGBColorSpace] || if (isPlanar || !([colorSpaceName isEqualToString: NSDeviceRGBColorSpace] ||
[colorSpaceName isEqualToString: NSCalibratedRGBColorSpace])) [colorSpaceName isEqualToString: NSCalibratedRGBColorSpace]))
{ {
@ -1088,12 +1200,15 @@ _set_op(cairo_t *ct, NSCompositingOperation op)
- (void) compositerect: (NSRect)aRect op: (NSCompositingOperation)op - (void) compositerect: (NSRect)aRect op: (NSCompositingOperation)op
{ {
if (_ct)
{
cairo_save(_ct); cairo_save(_ct);
_set_op(_ct, op); _set_op(_ct, op);
cairo_rectangle(_ct, NSMinX(aRect), NSMinY(aRect), NSWidth(aRect), cairo_rectangle(_ct, NSMinX(aRect), NSMinY(aRect), NSWidth(aRect),
NSHeight(aRect)); NSHeight(aRect));
cairo_fill(_ct); cairo_fill(_ct);
cairo_restore(_ct); cairo_restore(_ct);
}
} }
- (void) compositeGState: (CairoGState *)source - (void) compositeGState: (CairoGState *)source
@ -1109,6 +1224,11 @@ _set_op(cairo_t *ct, NSCompositingOperation op)
NSSize size; NSSize size;
double x, y; double x, y;
if (!_ct || !source->_ct)
{
return;
}
size = [source->_surface size]; size = [source->_surface size];
dh = size.height; dh = size.height;

View file

@ -331,15 +331,15 @@ NSLog(@"No glyph for U%d", c);
ascender = metric.tmAscent; ascender = metric.tmAscent;
//NSLog(@"Resulted in height %d and ascent %d", metric.tmHeight, metric.tmAscent); //NSLog(@"Resulted in height %d and ascent %d", metric.tmHeight, metric.tmAscent);
descender = -metric.tmDescent; descender = -metric.tmDescent;
/* TODO */
xHeight = ascender * 0.5;
maximumAdvancement = NSMakeSize((float)metric.tmMaxCharWidth, 0.0);
fontBBox = NSMakeRect((float)(0), fontBBox = NSMakeRect((float)(0),
(float)(0 - metric.tmAscent), (float)(0 - metric.tmAscent),
(float)metric.tmMaxCharWidth, (float)metric.tmMaxCharWidth,
(float)metric.tmHeight); (float)metric.tmHeight);
maximumAdvancement = NSMakeSize((float)metric.tmMaxCharWidth,
(float)metric.tmHeight);
weight = win32_font_weight(metric.tmWeight); weight = win32_font_weight(metric.tmWeight);
traits = 0; traits = 0;

View file

@ -706,8 +706,7 @@ static NSArray *faFromFc(FcPattern *pat)
(float)(0 - font_info->ascent), (float)(0 - font_info->ascent),
(float)(font_info->max_advance_width), (float)(font_info->max_advance_width),
(float)(font_info->ascent + font_info->descent)); (float)(font_info->ascent + font_info->descent));
maximumAdvancement = NSMakeSize(font_info->max_advance_width, maximumAdvancement = NSMakeSize(font_info->max_advance_width, 0.0);
(font_info->ascent + font_info->descent));
minimumAdvancement = NSMakeSize(0,0); minimumAdvancement = NSMakeSize(0,0);
// printf("h=%g a=%g d=%g max=(%g %g) (%g %g)+(%g %g)\n", // printf("h=%g a=%g d=%g max=(%g %g) (%g %g)+(%g %g)\n",
// xHeight, ascender, descender, // xHeight, ascender, descender,

View file

@ -307,8 +307,7 @@ static BOOL XGInitAtoms(Display *dpy)
(float)(0 - font_info->max_bounds.ascent), (float)(0 - font_info->max_bounds.ascent),
(float)(font_info->max_bounds.rbearing - font_info->min_bounds.lbearing), (float)(font_info->max_bounds.rbearing - font_info->min_bounds.lbearing),
(float)(font_info->max_bounds.ascent + font_info->max_bounds.descent)); (float)(font_info->max_bounds.ascent + font_info->max_bounds.descent));
maximumAdvancement = NSMakeSize(font_info->max_bounds.width, maximumAdvancement = NSMakeSize(font_info->max_bounds.width, 0.0);
(font_info->max_bounds.ascent +font_info->max_bounds.descent));
minimumAdvancement = NSMakeSize(0,0); minimumAdvancement = NSMakeSize(0,0);
weight = XGWeightOfFont(xdpy, font_info); weight = XGWeightOfFont(xdpy, font_info);
traits = XGTraitsOfFont(xdpy, font_info); traits = XGTraitsOfFont(xdpy, font_info);