From 9781c27f45116bf94d689dfffc44b9416da6472a Mon Sep 17 00:00:00 2001 From: Fred Kiefer Date: Wed, 25 Jun 2008 22:20:18 +0000 Subject: [PATCH] Small improvements for cairo backend. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@26711 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ Source/cairo/CairoFontInfo.m | 33 +++++++++++++++++++++++++++------ Source/cairo/CairoGState.m | 36 ++++++++++++++++++++++++------------ 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index d155096..088cd5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-06-26 Fred Kiefer + + * Source/cairo/CairoGState.m (-copyWithZone:): Use a runtime + version check and adjust from > to >= 1.6.0. + * Source/cairo/CairoFontInfo.m (-setupAttributes): Slightly better + error checks. + 2008-06-14 Adam Fedor * Version 0.14.0 diff --git a/Source/cairo/CairoFontInfo.m b/Source/cairo/CairoFontInfo.m index cb8d76b..3409567 100644 --- a/Source/cairo/CairoFontInfo.m +++ b/Source/cairo/CairoFontInfo.m @@ -93,25 +93,36 @@ */ cairo_matrix_init(&font_matrix, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); + //cairo_matrix_scale(&font_matrix, 0.9, 0.9); cairo_matrix_init_identity(&ctm); - // FIXME: Should get default font options from somewhere - options = cairo_font_options_create(); face = [_faceInfo fontFace]; if (!face) { return NO; } - _scaled = cairo_scaled_font_create(face, &font_matrix, &ctm, options); - cairo_font_options_destroy(options); - if (!_scaled) + // Get default font options + options = cairo_font_options_create(); + if (cairo_font_options_status(options) != CAIRO_STATUS_SUCCESS) { return NO; } + + _scaled = cairo_scaled_font_create(face, &font_matrix, &ctm, options); + cairo_font_options_destroy(options); + if (cairo_scaled_font_status(_scaled) != CAIRO_STATUS_SUCCESS) + { + return NO; + } + cairo_scaled_font_extents(_scaled, &font_extents); + if (cairo_scaled_font_status(_scaled) != CAIRO_STATUS_SUCCESS) + { + return NO; + } + ascender = font_extents.ascent; - // The FreeType documentation claims this value is already negative, but it isn't. descender = -font_extents.descent; xHeight = ascender * 0.6; lineHeight = font_extents.height; @@ -119,6 +130,16 @@ font_extents.max_y_advance); fontBBox = NSMakeRect(0, descender, maximumAdvancement.width, ascender - descender); +/* + NSLog(@"Font matrix (%g, %g, %g, %g, %g, %g) type %d", + matrix[0], matrix[1], matrix[2], + matrix[3], matrix[4], matrix[5], cairo_scaled_font_get_type(_scaled)); + NSLog(@"(%@) h=%g a=%g d=%g max=(%g %g) (%g %g)+(%g %g)\n", fontName, + xHeight, ascender, descender, + maximumAdvancement.width, maximumAdvancement.height, + fontBBox.origin.x, fontBBox.origin.y, + fontBBox.size.width, fontBBox.size.height); +*/ return YES; } diff --git a/Source/cairo/CairoGState.m b/Source/cairo/CairoGState.m index 31fe28c..f49c409 100644 --- a/Source/cairo/CairoGState.m +++ b/Source/cairo/CairoGState.m @@ -205,20 +205,32 @@ static float floatToUserSpace(NSAffineTransform *ctm, float f) { int i; - for (i = 0; i < clip_rects->num_rectangles; i++) + if (cairo_version() >= CAIRO_VERSION_ENCODE(1, 6, 0)) { - cairo_rectangle_t rect = clip_rects->rectangles[i]; - NSSize size = [_surface size]; + for (i = 0; i < clip_rects->num_rectangles; i++) + { + cairo_rectangle_t rect = clip_rects->rectangles[i]; - cairo_rectangle(copy->_ct, rect.x, -#if CAIRO_VERSION > CAIRO_VERSION_ENCODE(1, 6, 0) - rect.y, -#else - // This strange computation is due to the device offset. - rect.y + 2*(offset.y - size.height), -#endif - rect.width, rect.height); - cairo_clip(copy->_ct); + cairo_rectangle(copy->_ct, rect.x, rect.y, + rect.width, rect.height); + cairo_clip(copy->_ct); + } + } + else + { + for (i = 0; i < clip_rects->num_rectangles; i++) + { + cairo_rectangle_t rect = clip_rects->rectangles[i]; + NSSize size = [_surface size]; + + cairo_rectangle(copy->_ct, rect.x, + /* This strange computation is due + to the device offset missing for + clip rects in cairo < 1.6.0. */ + rect.y + 2*(offset.y - size.height), + rect.width, rect.height); + cairo_clip(copy->_ct); + } } } cairo_rectangle_list_destroy(clip_rects);