[cairo-commit] src/cairo-quartz-font.c

Andrea Canciani ranma42 at kemper.freedesktop.org
Mon Nov 1 07:26:37 PDT 2010


 src/cairo-quartz-font.c |   39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

New commits:
commit 947d35c19539b84c866d792c067a0cc63485e94e
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Mon Nov 1 14:06:32 2010 +0100

    quartz-font: Add truetype font table tags accessor
    
    Improves the quality of embedded fonts.

diff --git a/src/cairo-quartz-font.c b/src/cairo-quartz-font.c
index 2c7e017..d13b395 100644
--- a/src/cairo-quartz-font.c
+++ b/src/cairo-quartz-font.c
@@ -61,6 +61,8 @@
  * This macro can be used to conditionally compile backend-specific code.
  */
 
+static CFDataRef (*CGFontCopyTableForTagPtr) (CGFontRef font, uint32_t tag) = NULL;
+
 /* CreateWithFontName exists in 10.5, but not in 10.4; CreateWithName isn't public in 10.4 */
 static CGFontRef (*CGFontCreateWithFontNamePtr) (CFStringRef) = NULL;
 static CGFontRef (*CGFontCreateWithNamePtr) (const char *) = NULL;
@@ -99,6 +101,8 @@ quartz_font_ensure_symbols(void)
     if (_cairo_quartz_font_symbol_lookup_done)
 	return;
 
+    CGFontCopyTableForTagPtr = dlsym(RTLD_DEFAULT, "CGFontCopyTableForTag");
+
     /* Look for the 10.5 versions first */
     CGFontGetGlyphBBoxesPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphBBoxes");
     if (!CGFontGetGlyphBBoxesPtr)
@@ -754,6 +758,39 @@ _cairo_quartz_ucs4_to_index (void *abstract_font,
     return glyph;
 }
 
+static cairo_int_status_t
+_cairo_quartz_load_truetype_table (void	            *abstract_font,
+				   unsigned long     tag,
+				   long              offset,
+				   unsigned char    *buffer,
+				   unsigned long    *length)
+{
+    cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face (abstract_font);
+    CFDataRef data = NULL;
+    CFIndex len;
+
+    if (likely (CGFontCopyTableForTagPtr))
+	data = CGFontCopyTableForTagPtr (font_face->cgFont, tag);
+
+    if (!data)
+        return CAIRO_INT_STATUS_UNSUPPORTED;
+
+    if (length) {
+	if (*length == 0) {
+	    *length = CFDataGetLength (data);
+	    return CAIRO_STATUS_SUCCESS;
+	}
+
+	len = *length;
+    } else
+	len = CFDataGetLength (data);
+
+    if (buffer)
+	CFDataGetBytes (data, CFRangeMake (offset, len), buffer);
+
+    return CAIRO_STATUS_SUCCESS;
+}
+
 static const cairo_scaled_font_backend_t _cairo_quartz_scaled_font_backend = {
     CAIRO_FONT_TYPE_QUARTZ,
     _cairo_quartz_scaled_font_fini,
@@ -761,7 +798,7 @@ static const cairo_scaled_font_backend_t _cairo_quartz_scaled_font_backend = {
     NULL, /* text_to_glyphs */
     _cairo_quartz_ucs4_to_index,
     NULL, /* show_glyphs */
-    NULL, /* load_truetype_table */
+    _cairo_quartz_load_truetype_table,
     NULL, /* map_glyphs_to_unicode */
 };
 


More information about the cairo-commit mailing list