[cairo-commit] 5 commits - src/cairo-quartz-font.c src/cairo-quartz-surface.c
Andrea Canciani
ranma42 at kemper.freedesktop.org
Mon Jun 28 08:04:22 PDT 2010
src/cairo-quartz-font.c | 97 ++++++++++++++++-----------------------------
src/cairo-quartz-surface.c | 61 +++++++---------------------
2 files changed, 52 insertions(+), 106 deletions(-)
New commits:
commit bd4c14b94eeb386b30439929e8e54a5d9b5d5fca
Author: Andrea Canciani <ranma42 at gmail.com>
Date: Thu Jun 24 23:20:41 2010 +0200
quartz: remove unused os version info
It was previously used to activate a workaround for text transformation
whenrunning on some os versions. Now the workaround is not needed anymore.
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 8c6fb71..da025aa 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -124,8 +124,6 @@ static bool (*CGContextGetAllowsFontSmoothingPtr) (CGContextRef) = NULL;
static CGPathRef (*CGContextCopyPathPtr) (CGContextRef) = NULL;
static void (*CGContextReplacePathWithClipPathPtr) (CGContextRef) = NULL;
-static SInt32 _cairo_quartz_osx_version = 0x0;
-
static cairo_bool_t _cairo_quartz_symbol_lookup_done = FALSE;
/*
@@ -160,11 +158,6 @@ static void quartz_ensure_symbols(void)
CGContextGetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing");
CGContextSetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing");
- if (Gestalt(gestaltSystemVersion, &_cairo_quartz_osx_version) != noErr) {
- // assume 10.4
- _cairo_quartz_osx_version = 0x1040;
- }
-
_cairo_quartz_symbol_lookup_done = TRUE;
}
commit aa7e9c43b6381930455a68258dcc3e14dce2b0e4
Author: Andrea Canciani <ranma42 at gmail.com>
Date: Thu Jun 24 14:18:02 2010 +0200
quartz-font: correct and explain matrix computations
glyph_path was taking into account the translation (which currently
is already applied in gstate) and the sign of the elements of the
matrices was not explained.
diff --git a/src/cairo-quartz-font.c b/src/cairo-quartz-font.c
index 17b6ba1..736fdc2 100644
--- a/src/cairo-quartz-font.c
+++ b/src/cairo-quartz-font.c
@@ -532,14 +532,12 @@ _cairo_quartz_init_glyph_path (cairo_quartz_scaled_font_t *font,
return CAIRO_STATUS_SUCCESS;
}
+ /* scale(1,-1) * font->base.scale */
textMatrix = CGAffineTransformMake (font->base.scale.xx,
- -font->base.scale.yx,
+ font->base.scale.yx,
-font->base.scale.xy,
- font->base.scale.yy,
- font->base.scale.x0,
- font->base.scale.y0);
-
- textMatrix = CGAffineTransformConcat (textMatrix, CGAffineTransformMake (1.0, 0.0, 0.0, -1.0, 0.0, 0.0));
+ -font->base.scale.yy,
+ 0, 0);
glyphPath = CGFontGetGlyphPathPtr (font_face->cgFont, &textMatrix, 0, glyph);
if (!glyphPath)
@@ -612,11 +610,12 @@ _cairo_quartz_init_glyph_surface (cairo_quartz_scaled_font_t *font,
if (status)
return status;
+ /* scale(1,-1) * font->base.scale * scale(1,-1) */
textMatrix = CGAffineTransformMake (font->base.scale.xx,
-font->base.scale.yx,
-font->base.scale.xy,
font->base.scale.yy,
- 0.0f, 0.0f);
+ 0, -0);
glyphRect = CGRectMake (bbox.origin.x / emscale,
bbox.origin.y / emscale,
bbox.size.width / emscale,
commit b26f72fef99e9869a62cbb8e44a82837f87cf2c6
Author: Andrea Canciani <ranma42 at gmail.com>
Date: Thu Jun 24 22:34:36 2010 +0200
quartz: check return status
If the font backend is unable to tell the extents of the operation,
consider it unbound.
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 48603db..8c6fb71 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -2490,6 +2490,7 @@ _cairo_quartz_surface_show_glyphs_cg (void *abstract_surface,
CGGlyph *cg_glyphs = &glyphs_static[0];
CGSize *cg_advances = &cg_advances_static[0];
+ cairo_rectangle_int_t glyph_extents;
cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
cairo_int_status_t rv = CAIRO_STATUS_SUCCESS;
cairo_quartz_action_t action;
@@ -2519,11 +2520,10 @@ _cairo_quartz_surface_show_glyphs_cg (void *abstract_surface,
CGContextSaveGState (surface->cgContext);
- if (_cairo_quartz_source_needs_extents (source))
+ if (_cairo_quartz_source_needs_extents (source) &&
+ !_cairo_scaled_font_glyph_device_extents (scaled_font, glyphs, num_glyphs,
+ &glyph_extents, NULL))
{
- cairo_rectangle_int_t glyph_extents;
- _cairo_scaled_font_glyph_device_extents (scaled_font, glyphs, num_glyphs,
- &glyph_extents, NULL);
action = _cairo_quartz_setup_source (surface, source, &glyph_extents);
} else {
action = _cairo_quartz_setup_source (surface, source, NULL);
commit 9c0d761bfcdd28d52c83d74f46dd3c709ae0fa69
Author: Andrea Canciani <ranma42 at gmail.com>
Date: Thu Jun 24 15:26:03 2010 +0200
quartz: improve text transform handling
Use scale instead of manually compositing font_matrix and ctm and
composite it with the context ctm, so that no workaround for clipping
is needed anymore.
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index df98ab4..48603db 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -680,8 +680,9 @@ _cairo_quartz_fixup_unbounded_operation (cairo_quartz_surface_t *surface,
} else if (op->op == UNBOUNDED_SHOW_GLYPHS) {
CGContextSetFont (cgc, op->u.show_glyphs.font);
CGContextSetFontSize (cgc, 1.0);
- CGContextSetTextMatrix (cgc, op->u.show_glyphs.textTransform);
+ CGContextSetTextMatrix (cgc, CGAffineTransformIdentity);
CGContextTranslateCTM (cgc, op->u.show_glyphs.origin.x, op->u.show_glyphs.origin.y);
+ CGContextConcatCTM (cgc, op->u.show_glyphs.textTransform);
if (op->u.show_glyphs.isClipping) {
/* Note that the comment in show_glyphs about kCGTextClip
@@ -2482,7 +2483,7 @@ _cairo_quartz_surface_show_glyphs_cg (void *abstract_surface,
cairo_clip_t *clip,
int *remaining_glyphs)
{
- CGAffineTransform textTransform, ctm;
+ CGAffineTransform textTransform, ctm, invTextTransform;
#define STATIC_BUF_SIZE 64
CGGlyph glyphs_static[STATIC_BUF_SIZE];
CGSize cg_advances_static[STATIC_BUF_SIZE];
@@ -2581,20 +2582,14 @@ _cairo_quartz_surface_show_glyphs_cg (void *abstract_surface,
}
}
- textTransform = CGAffineTransformMake (scaled_font->font_matrix.xx,
- scaled_font->font_matrix.yx,
- scaled_font->font_matrix.xy,
- scaled_font->font_matrix.yy,
- 0., 0.);
- textTransform = CGAffineTransformScale (textTransform, 1.0, -1.0);
- textTransform = CGAffineTransformConcat (CGAffineTransformMake(scaled_font->ctm.xx,
- -scaled_font->ctm.yx,
- -scaled_font->ctm.xy,
- scaled_font->ctm.yy,
- 0., 0.),
- textTransform);
+ textTransform = CGAffineTransformMake (scaled_font->scale.xx,
+ scaled_font->scale.yx,
+ -scaled_font->scale.xy,
+ -scaled_font->scale.yy,
+ 0, 0);
+ _cairo_quartz_cairo_matrix_to_quartz (&scaled_font->scale_inverse, &invTextTransform);
- CGContextSetTextMatrix (surface->cgContext, textTransform);
+ CGContextSetTextMatrix (surface->cgContext, CGAffineTransformIdentity);
/* Convert our glyph positions to glyph advances. We need n-1 advances,
* since the advance at index 0 is applied after glyph 0. */
@@ -2607,32 +2602,15 @@ _cairo_quartz_surface_show_glyphs_cg (void *abstract_surface,
cairo_quartz_float_t xf = glyphs[i].x;
cairo_quartz_float_t yf = glyphs[i].y;
cg_glyphs[i] = glyphs[i].index;
- cg_advances[i-1].width = xf - xprev;
- cg_advances[i-1].height = yf - yprev;
+ cg_advances[i - 1] = CGSizeApplyAffineTransform(CGSizeMake (xf - xprev, yf - yprev), invTextTransform);
xprev = xf;
yprev = yf;
}
- if (_cairo_quartz_osx_version >= 0x1050 && isClipping) {
- /* If we're clipping, OSX 10.5 (at least as of 10.5.2) has a
- * bug (apple bug ID #5834794) where the glyph
- * advances/positions are not transformed by the text matrix
- * if kCGTextClip is being used. So, we pre-transform here.
- * 10.4 does not have this problem (as of 10.4.11).
- */
- for (i = 0; i < num_glyphs - 1; i++)
- cg_advances[i] = CGSizeApplyAffineTransform(cg_advances[i], textTransform);
- }
-
-#if 0
- for (i = 0; i < num_glyphs; i++) {
- ND((stderr, "[%d: %d %f,%f]\n", i, cg_glyphs[i], cg_advances[i].width, cg_advances[i].height));
- }
-#endif
-
/* Translate to the first glyph's position before drawing */
ctm = CGContextGetCTM (surface->cgContext);
CGContextTranslateCTM (surface->cgContext, glyphs[0].x, glyphs[0].y);
+ CGContextConcatCTM (surface->cgContext, textTransform);
CGContextShowGlyphsWithAdvances (surface->cgContext,
cg_glyphs,
commit 9068b5768b8560fbf095f1c0eecb5c805232f794
Author: Andrea Canciani <ranma42 at gmail.com>
Date: Thu Jun 24 15:15:37 2010 +0200
quartz-font: silence compiler warnings
Remove an unused function, explicitly ignore or check return values,
don't define unused variables.
diff --git a/src/cairo-quartz-font.c b/src/cairo-quartz-font.c
index 2147cd3..17b6ba1 100644
--- a/src/cairo-quartz-font.c
+++ b/src/cairo-quartz-font.c
@@ -333,7 +333,8 @@ cairo_quartz_font_face_create_for_cgfont (CGFontRef font)
font_face = malloc (sizeof (cairo_quartz_font_face_t));
if (!font_face) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ cairo_status_t ignore_status;
+ ignore_status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
return (cairo_font_face_t *)&_cairo_font_face_nil;
}
@@ -372,36 +373,6 @@ _cairo_quartz_scaled_glyph_index (cairo_scaled_glyph_t *scaled_glyph) {
return (CGGlyph) index;
}
-static inline cairo_status_t
-_cairo_matrix_to_unit_quartz_matrix (const cairo_matrix_t *m, CGAffineTransform *txout,
- double *xout, double *yout)
-{
- CGAffineTransform transform;
- double xscale, yscale;
- cairo_status_t status;
-
- status = _cairo_matrix_compute_basis_scale_factors (m, &xscale, &yscale, 1);
- if (status)
- return status;
-
- transform = CGAffineTransformMake (m->xx, - m->yx,
- - m->xy, m->yy,
- 0.0f, 0.0f);
- if (xout)
- *xout = xscale;
- if (yout)
- *yout = yscale;
-
- if (xscale)
- xscale = 1.0 / xscale;
- if (yscale)
- yscale = 1.0 / yscale;
-
- *txout = CGAffineTransformScale (transform, xscale, yscale);
-
- return CAIRO_STATUS_SUCCESS;
-}
-
static cairo_int_status_t
_cairo_quartz_init_glyph_metrics (cairo_quartz_scaled_font_t *font,
cairo_scaled_glyph_t *scaled_glyph)
@@ -410,7 +381,6 @@ _cairo_quartz_init_glyph_metrics (cairo_quartz_scaled_font_t *font,
cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face(font);
cairo_text_extents_t extents = {0, 0, 0, 0, 0, 0};
- CGAffineTransform textMatrix;
CGGlyph glyph = _cairo_quartz_scaled_glyph_index (scaled_glyph);
int advance;
CGRect bbox;
@@ -497,17 +467,20 @@ static void
_cairo_quartz_path_apply_func (void *info, const CGPathElement *el)
{
cairo_path_fixed_t *path = (cairo_path_fixed_t *) info;
+ cairo_status_t status;
switch (el->type) {
case kCGPathElementMoveToPoint:
- _cairo_path_fixed_move_to (path,
- _cairo_fixed_from_double(el->points[0].x),
- _cairo_fixed_from_double(el->points[0].y));
+ status = _cairo_path_fixed_move_to (path,
+ _cairo_fixed_from_double(el->points[0].x),
+ _cairo_fixed_from_double(el->points[0].y));
+ assert(!status);
break;
case kCGPathElementAddLineToPoint:
- _cairo_path_fixed_line_to (path,
- _cairo_fixed_from_double(el->points[0].x),
- _cairo_fixed_from_double(el->points[0].y));
+ status = _cairo_path_fixed_line_to (path,
+ _cairo_fixed_from_double(el->points[0].x),
+ _cairo_fixed_from_double(el->points[0].y));
+ assert(!status);
break;
case kCGPathElementAddQuadCurveToPoint: {
cairo_fixed_t fx, fy;
@@ -517,26 +490,29 @@ _cairo_quartz_path_apply_func (void *info, const CGPathElement *el)
x = _cairo_fixed_to_double (fx);
y = _cairo_fixed_to_double (fy);
- _cairo_path_fixed_curve_to (path,
- _cairo_fixed_from_double((x + el->points[0].x * 2.0) / 3.0),
- _cairo_fixed_from_double((y + el->points[0].y * 2.0) / 3.0),
- _cairo_fixed_from_double((el->points[0].x * 2.0 + el->points[1].x) / 3.0),
- _cairo_fixed_from_double((el->points[0].y * 2.0 + el->points[1].y) / 3.0),
- _cairo_fixed_from_double(el->points[1].x),
- _cairo_fixed_from_double(el->points[1].y));
+ status = _cairo_path_fixed_curve_to (path,
+ _cairo_fixed_from_double((x + el->points[0].x * 2.0) / 3.0),
+ _cairo_fixed_from_double((y + el->points[0].y * 2.0) / 3.0),
+ _cairo_fixed_from_double((el->points[0].x * 2.0 + el->points[1].x) / 3.0),
+ _cairo_fixed_from_double((el->points[0].y * 2.0 + el->points[1].y) / 3.0),
+ _cairo_fixed_from_double(el->points[1].x),
+ _cairo_fixed_from_double(el->points[1].y));
}
+ assert(!status);
break;
case kCGPathElementAddCurveToPoint:
- _cairo_path_fixed_curve_to (path,
- _cairo_fixed_from_double(el->points[0].x),
- _cairo_fixed_from_double(el->points[0].y),
- _cairo_fixed_from_double(el->points[1].x),
- _cairo_fixed_from_double(el->points[1].y),
- _cairo_fixed_from_double(el->points[2].x),
- _cairo_fixed_from_double(el->points[2].y));
+ status = _cairo_path_fixed_curve_to (path,
+ _cairo_fixed_from_double(el->points[0].x),
+ _cairo_fixed_from_double(el->points[0].y),
+ _cairo_fixed_from_double(el->points[1].x),
+ _cairo_fixed_from_double(el->points[1].y),
+ _cairo_fixed_from_double(el->points[2].x),
+ _cairo_fixed_from_double(el->points[2].y));
+ assert(!status);
break;
case kCGPathElementCloseSubpath:
- _cairo_path_fixed_close_path (path);
+ status = _cairo_path_fixed_close_path (path);
+ assert(!status);
break;
}
}
@@ -683,7 +659,7 @@ _cairo_quartz_init_glyph_surface (cairo_quartz_scaled_font_t *font,
kCGImageAlphaOnly);
if (cgContext == NULL) {
- cairo_surface_destroy (surface);
+ cairo_surface_destroy (&surface->base);
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
More information about the cairo-commit
mailing list