[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.
This commit is contained in:
Vladimir Vukicevic 2008-03-12 18:19:59 -07:00 committed by Vladimir Vukicevic
parent 5d11b937f1
commit 6ac3eb487c

View file

@ -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 &&