static cairo_status_t _cairo_quartz_font_create_toy (cairo_toy_font_face_t *toy_face, const cairo_matrix_t *font_matrix, const cairo_matrix_t *ctm, const cairo_font_options_t *options, cairo_scaled_font_t **font_out) { cairo_font_face_t *face; cairo_scaled_font_t *scaled_font; cairo_status_t status; status = _cairo_quartz_font_get_implementation (toy_face, &face); if (status) return status; status = _cairo_quartz_font_face_scaled_font_create (face, font_matrix, ctm, options, &scaled_font); cairo_font_face_destroy (face); if (status) return status; *font_out = scaled_font; return CAIRO_STATUS_SUCCESS; }
static cairo_status_t _cairo_quartz_font_create_toy(cairo_toy_font_face_t *toy_face, const cairo_matrix_t *font_matrix, const cairo_matrix_t *ctm, const cairo_font_options_t *options, cairo_scaled_font_t **font_out) { const char *family = toy_face->family; char *full_name = malloc(strlen(family) + 64); // give us a bit of room to tack on Bold, Oblique, etc. CFStringRef cgFontName = NULL; CGFontRef cgFont = NULL; int loop; cairo_status_t status; cairo_font_face_t *face; cairo_scaled_font_t *scaled_font; quartz_font_ensure_symbols(); if (!_cairo_quartz_font_symbols_present) return _cairo_error (CAIRO_STATUS_NO_MEMORY); /* handle CSS-ish faces */ if (!strcmp(family, "serif") || !strcmp(family, "Times Roman")) family = "Times"; else if (!strcmp(family, "sans-serif") || !strcmp(family, "sans")) family = "Helvetica"; else if (!strcmp(family, "cursive")) family = "Apple Chancery"; else if (!strcmp(family, "fantasy")) family = "Papyrus"; else if (!strcmp(family, "monospace") || !strcmp(family, "mono")) family = "Courier"; /* Try to build up the full name, e.g. "Helvetica Bold Oblique" first, * then drop the bold, then drop the slant, then drop both.. finally * just use "Helvetica". And if Helvetica doesn't exist, give up. */ for (loop = 0; loop < 5; loop++) { if (loop == 4) family = "Helvetica"; strcpy (full_name, family); if (loop < 3 && (loop & 1) == 0) { if (toy_face->weight == CAIRO_FONT_WEIGHT_BOLD) strcat (full_name, " Bold"); } if (loop < 3 && (loop & 2) == 0) { if (toy_face->slant == CAIRO_FONT_SLANT_ITALIC) strcat (full_name, " Italic"); else if (toy_face->slant == CAIRO_FONT_SLANT_OBLIQUE) strcat (full_name, " Oblique"); } if (CGFontCreateWithFontNamePtr) { cgFontName = CFStringCreateWithCString (NULL, full_name, kCFStringEncodingASCII); cgFont = CGFontCreateWithFontNamePtr (cgFontName); CFRelease (cgFontName); } else { cgFont = CGFontCreateWithNamePtr (full_name); } if (cgFont) break; } if (!cgFont) { /* Give up */ return CAIRO_STATUS_NO_MEMORY; } face = cairo_quartz_font_face_create_for_cgfont (cgFont); CGFontRelease (cgFont); if (face->status) return face->status; status = _cairo_quartz_font_face_scaled_font_create (face, font_matrix, ctm, options, &scaled_font); cairo_font_face_destroy (face); if (status) return status; *font_out = scaled_font; return CAIRO_STATUS_SUCCESS; }