From 6ac3eb487cf0de0d28bf6b14852de91b09fecb05 Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Wed, 12 Mar 2008 18:19:59 -0700 Subject: [PATCH] [quartz] correctly force subpixel AA on a context, even if defaults say otherwise In some cases (in my case, having an external monitor attached to my MBP), Quartz seems to default to grayscale AA even when it should be using subpixel AA. CGContextGetAllowsFontSmoothing returns FALSE in this case (pretty sure this is a Quartz bug). We can force subpixel AA in this case by setting CGContextSetAllowsFontSmoothing. --- src/cairo-quartz-surface.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c index 1e445bac5..a96b0fb2d 100644 --- a/src/cairo-quartz-surface.c +++ b/src/cairo-quartz-surface.c @@ -109,8 +109,10 @@ static void (*CGContextDrawTiledImagePtr) (CGContextRef, CGRect, CGImageRef) = N static unsigned int (*CGContextGetTypePtr) (CGContextRef) = NULL; static void (*CGContextSetShouldAntialiasFontsPtr) (CGContextRef, bool) = NULL; static void (*CGContextSetShouldSmoothFontsPtr) (CGContextRef, bool) = NULL; -static void (*CGContextGetShouldAntialiasFontsPtr) (CGContextRef, bool) = NULL; -static void (*CGContextGetShouldSmoothFontsPtr) (CGContextRef, bool) = NULL; +static bool (*CGContextGetShouldAntialiasFontsPtr) (CGContextRef) = NULL; +static bool (*CGContextGetShouldSmoothFontsPtr) (CGContextRef) = NULL; +static void (*CGContextSetAllowsFontSmoothingPtr) (CGContextRef, bool) = NULL; +static bool (*CGContextGetAllowsFontSmoothingPtr) (CGContextRef) = NULL; static CGPathRef (*CGContextCopyPathPtr) (CGContextRef) = NULL; static void (*CGContextReplacePathWithClipPathPtr) (CGContextRef) = NULL; @@ -146,6 +148,8 @@ static void quartz_ensure_symbols(void) CGContextGetShouldSmoothFontsPtr = dlsym(RTLD_DEFAULT, "CGContextGetShouldSmoothFonts"); CGContextCopyPathPtr = dlsym(RTLD_DEFAULT, "CGContextCopyPath"); CGContextReplacePathWithClipPathPtr = dlsym(RTLD_DEFAULT, "CGContextReplacePathWithClipPath"); + CGContextGetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing"); + CGContextSetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing"); _cairo_quartz_symbol_lookup_done = TRUE; } @@ -1840,6 +1844,7 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface, CGFontRef cgfref = NULL; cairo_bool_t isClipping = FALSE; + cairo_bool_t didForceFontSmoothing = TRUE; if (IS_EMPTY(surface)) return CAIRO_STATUS_SUCCESS; @@ -1879,15 +1884,23 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface, case CAIRO_ANTIALIAS_SUBPIXEL: CGContextSetShouldAntialiasFontsPtr (surface->cgContext, TRUE); CGContextSetShouldSmoothFontsPtr (surface->cgContext, TRUE); + if (CGContextSetAllowsFontSmoothingPtr && + !CGContextGetAllowsFontSmoothingPtr (surface->cgContext)) + { + didForceFontSmoothing = TRUE; + CGContextSetAllowsFontSmoothingPtr (surface->cgContext, TRUE); + } break; case CAIRO_ANTIALIAS_NONE: CGContextSetShouldAntialiasFontsPtr (surface->cgContext, FALSE); break; case CAIRO_ANTIALIAS_GRAY: - case CAIRO_ANTIALIAS_DEFAULT: CGContextSetShouldAntialiasFontsPtr (surface->cgContext, TRUE); CGContextSetShouldSmoothFontsPtr (surface->cgContext, FALSE); break; + case CAIRO_ANTIALIAS_DEFAULT: + /* Don't do anything */ + break; } } @@ -1979,6 +1992,9 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface, BAIL: _cairo_quartz_teardown_source (surface, source); + if (didForceFontSmoothing) + CGContextSetAllowsFontSmoothingPtr (surface->cgContext, FALSE); + CGContextRestoreGState (surface->cgContext); if (rv == CAIRO_STATUS_SUCCESS &&