summaryrefslogtreecommitdiff
path: root/src/cairo-quartz-font.c
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2010-05-13 11:54:32 +0200
committerAndrea Canciani <ranma42@gmail.com>2010-05-17 21:34:38 +0200
commit1687e6169463947554f5476674a577e67e2c543b (patch)
treeb95ea5b32f7f19be6e826f653824b33494281ad4 /src/cairo-quartz-font.c
parentd68bbc0fe5706634e4c025bdcb311905b7f008e4 (diff)
downloadcairo-1687e6169463947554f5476674a577e67e2c543b.tar.gz
quartz-font: Conform context and antialias handling to quartz-surface
A8 surfaces are now kAlphaOnly surfaces in quartz-font too. Subpixel font smoothing can be enabled.
Diffstat (limited to 'src/cairo-quartz-font.c')
-rw-r--r--src/cairo-quartz-font.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/cairo-quartz-font.c b/src/cairo-quartz-font.c
index 537cfff0f..74674ea55 100644
--- a/src/cairo-quartz-font.c
+++ b/src/cairo-quartz-font.c
@@ -55,6 +55,8 @@ static CGRect (*CGFontGetFontBBoxPtr) (CGFontRef) = NULL;
/* Not public, but present */
static void (*CGFontGetGlyphsForUnicharsPtr) (CGFontRef, const UniChar[], const CGGlyph[], size_t) = NULL;
+static void (*CGContextSetAllowsFontSmoothingPtr) (CGContextRef, bool) = NULL;
+static bool (*CGContextGetAllowsFontSmoothingPtr) (CGContextRef) = NULL;
/* Not public in the least bit */
static CGPathRef (*CGFontGetGlyphPathPtr) (CGFontRef fontRef, CGAffineTransform *textTransform, int unknown, CGGlyph glyph) = NULL;
@@ -104,6 +106,9 @@ quartz_font_ensure_symbols(void)
CGFontGetDescentPtr = dlsym(RTLD_DEFAULT, "CGFontGetDescent");
CGFontGetLeadingPtr = dlsym(RTLD_DEFAULT, "CGFontGetLeading");
+ CGContextGetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing");
+ CGContextSetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing");
+
if ((CGFontCreateWithFontNamePtr || CGFontCreateWithNamePtr) &&
CGFontGetGlyphBBoxesPtr &&
CGFontGetGlyphsForUnicharsPtr &&
@@ -597,7 +602,6 @@ _cairo_quartz_init_glyph_surface (cairo_quartz_scaled_font_t *font,
double xscale, yscale;
double emscale = CGFontGetUnitsPerEmPtr (font_face->cgFont);
- CGColorSpaceRef gray;
CGContextRef cgContext = NULL;
CGAffineTransform textMatrix;
CGRect glyphRect, glyphRectInt;
@@ -669,26 +673,40 @@ _cairo_quartz_init_glyph_surface (cairo_quartz_scaled_font_t *font,
if (surface->base.status)
return surface->base.status;
- gray = CGColorSpaceCreateDeviceGray ();
cgContext = CGBitmapContextCreate (surface->data,
surface->width,
surface->height,
8,
surface->stride,
- gray,
- kCGImageAlphaNone);
- CGColorSpaceRelease (gray);
+ NULL,
+ kCGImageAlphaOnly);
CGContextSetFont (cgContext, font_face->cgFont);
CGContextSetFontSize (cgContext, 1.0);
CGContextSetTextMatrix (cgContext, textMatrix);
- CGContextClearRect (cgContext, CGRectMake (0.0f, 0.0f, width, height));
-
- if (font->base.options.antialias == CAIRO_ANTIALIAS_NONE)
- CGContextSetShouldAntialias (cgContext, false);
+ switch (font->base.options.antialias) {
+ case CAIRO_ANTIALIAS_SUBPIXEL:
+ CGContextSetShouldAntialias (cgContext, TRUE);
+ CGContextSetShouldSmoothFonts (cgContext, TRUE);
+ if (CGContextSetAllowsFontSmoothingPtr &&
+ !CGContextGetAllowsFontSmoothingPtr (cgContext))
+ CGContextSetAllowsFontSmoothingPtr (cgContext, TRUE);
+ break;
+ case CAIRO_ANTIALIAS_NONE:
+ CGContextSetShouldAntialias (cgContext, FALSE);
+ break;
+ case CAIRO_ANTIALIAS_GRAY:
+ CGContextSetShouldAntialias (cgContext, TRUE);
+ CGContextSetShouldSmoothFonts (cgContext, FALSE);
+ break;
+ case CAIRO_ANTIALIAS_DEFAULT:
+ default:
+ /* Don't do anything */
+ break;
+ }
- CGContextSetRGBFillColor (cgContext, 1.0, 1.0, 1.0, 1.0);
+ CGContextSetAlpha (cgContext, 1.0);
CGContextShowGlyphsAtPoint (cgContext, - glyphOrigin.x, - glyphOrigin.y, &glyph, 1);
CGContextRelease (cgContext);