[cairo-commit] 2 commits - src/cairo-quartz-font.c
Andrea Canciani
ranma42 at kemper.freedesktop.org
Mon May 17 13:07:25 PDT 2010
src/cairo-quartz-font.c | 67 ++++++++++++++++++++++++++++++++----------------
1 file changed, 46 insertions(+), 21 deletions(-)
New commits:
commit f40e3b09a130a9ccbe310120fd5cfc7ad7828a4d
Author: Andrea Canciani <ranma42 at gmail.com>
Date: Thu May 13 12:15:19 2010 +0200
quartz-font: Silence 0x0 CGContext warning
Silence Quartz complaints about operations on empty contexts:
<Error>: CGContextSetFont: invalid context 0x0
<Error>: CGContextSetFontSize: invalid context 0x0
<Error>: CGContextSetTextMatrix: invalid context 0x0
<Error>: CGContextSetAlpha: invalid context 0x0
<Error>: CGContextShowGlyphsAtPoint: invalid context 0x0
diff --git a/src/cairo-quartz-font.c b/src/cairo-quartz-font.c
index 74674ea..2147cd3 100644
--- a/src/cairo-quartz-font.c
+++ b/src/cairo-quartz-font.c
@@ -673,43 +673,50 @@ _cairo_quartz_init_glyph_surface (cairo_quartz_scaled_font_t *font,
if (surface->base.status)
return surface->base.status;
- cgContext = CGBitmapContextCreate (surface->data,
- surface->width,
- surface->height,
- 8,
- surface->stride,
- NULL,
- kCGImageAlphaOnly);
-
- CGContextSetFont (cgContext, font_face->cgFont);
- CGContextSetFontSize (cgContext, 1.0);
- CGContextSetTextMatrix (cgContext, textMatrix);
-
- 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;
- }
+ if (surface->width != 0 && surface->height != 0) {
+ cgContext = CGBitmapContextCreate (surface->data,
+ surface->width,
+ surface->height,
+ 8,
+ surface->stride,
+ NULL,
+ kCGImageAlphaOnly);
+
+ if (cgContext == NULL) {
+ cairo_surface_destroy (surface);
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ }
- CGContextSetAlpha (cgContext, 1.0);
- CGContextShowGlyphsAtPoint (cgContext, - glyphOrigin.x, - glyphOrigin.y, &glyph, 1);
+ CGContextSetFont (cgContext, font_face->cgFont);
+ CGContextSetFontSize (cgContext, 1.0);
+ CGContextSetTextMatrix (cgContext, textMatrix);
+
+ 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;
+ }
- CGContextRelease (cgContext);
+ CGContextSetAlpha (cgContext, 1.0);
+ CGContextShowGlyphsAtPoint (cgContext, - glyphOrigin.x, - glyphOrigin.y, &glyph, 1);
+
+ CGContextRelease (cgContext);
+ }
cairo_surface_set_device_offset (&surface->base,
- glyphOrigin.x,
commit 1687e6169463947554f5476674a577e67e2c543b
Author: Andrea Canciani <ranma42 at gmail.com>
Date: Thu May 13 11:54:32 2010 +0200
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.
diff --git a/src/cairo-quartz-font.c b/src/cairo-quartz-font.c
index 537cfff..74674ea 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);
More information about the cairo-commit
mailing list