[ATSUI] make drawing glyphs with paths conditional on the style. This completes the implementation of synthetic bold/oblique while staying pretty for preselected fonts. --- commit 3b9c0520c6008a8a55fa12b325a2b8a066d5a322 tree a3db4e662c3b06e4f8981bd9ec7a92badcf57712 parent b98cdf60021b50e35b1ef4c89b60f347b4b037b5 author Brian Ewins Thu, 04 Jan 2007 16:31:37 +0000 committer Brian Ewins Thu, 04 Jan 2007 16:31:37 +0000 src/cairo-atsui-font.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c index 8615b1e..4229994 100644 --- a/src/cairo-atsui-font.c +++ b/src/cairo-atsui-font.c @@ -286,6 +286,15 @@ _cairo_atsui_font_create_scaled (cairo_f OSStatus err; cairo_status_t status; + ItemCount attribute_count; + ATSUAttributeInfo *attribute; + /* shouldn't really allow 'no hinting'. */ + static const ATSStyleRenderingOptions allowed_options = + kATSStyleApplyAntiAliasing + |kATSStyleNoAntiAliasing + |kATSStyleNoHinting; + unsigned int i; + font = malloc(sizeof(cairo_atsui_font_t)); if (font == NULL) return CAIRO_STATUS_NO_MEMORY; @@ -293,8 +302,57 @@ _cairo_atsui_font_create_scaled (cairo_f _cairo_scaled_font_init(&font->base, font_face, font_matrix, ctm, options, &cairo_atsui_scaled_font_backend); - /* Force use of this path, make this conditional later */ - font->draw_using_paths = true; + /* If there are any styles applied to the glyph, + * other than resizing it, we can't draw it with CGContextShowGlyphXXX. + * Strikethrough/underline colors, drop shadows cannot be + * supported and may need faked at some point. + */ + font->draw_using_paths = false; + err = ATSUGetAllAttributes (style, NULL, 0, &attribute_count); + attribute = malloc (attribute_count * sizeof (ATSUAttributeInfo)); + err = ATSUGetAllAttributes (style, attribute, attribute_count, NULL); + for (i = 0; i < attribute_count; i++) { + switch (attribute[i].fTag) { + case kATSUQDBoldfaceTag: + case kATSUQDItalicTag: + case kATSUQDUnderlineTag: + case kATSUQDCondensedTag: + case kATSUQDExtendedTag: + case kATSUStyleStrikeThroughTag: + case kATSUStyleDropShadowTag: + { + Boolean option; + err = ATSUGetAttribute (style, + attribute[i].fTag, + attribute[i].fValueSize, + &option, + NULL); + if (option) { + font->draw_using_paths = true; + goto END_ATTRIBUTES; + } + } + break; + case kATSUStyleRenderingOptionsTag: + { + ATSStyleRenderingOptions options; + + err = ATSUGetAttribute (style, + attribute[i].fTag, + attribute[i].fValueSize, + &options, + NULL); + + if ((options | allowed_options) ^ allowed_options) { + font->draw_using_paths = true; + goto END_ATTRIBUTES; + } + } + break; + } + } + END_ATTRIBUTES: + free(attribute); font->font_to_device = CGAffineTransformMakeWithCairoFontScale (&font->base.scale); font->device_to_user_scale = CGAffineTransformInvert (CGAffineTransformMakeWithCairoScaleFactors (ctm));