quartz: Restore 10.4-specific font code

The code for extracting font glyphs was replaced in
70cc8f250b with an implementation based
on CoreText, which is not available on MacOSX 10.4.  This commit
restores automatic detection of which API should be used by means of
dynamic linking.
This commit is contained in:
Andrea Canciani 2017-01-18 13:08:11 +01:00
parent dd4706d0a9
commit 5a8a9c97ed
3 changed files with 31 additions and 9 deletions

2
README
View file

@ -121,7 +121,7 @@ Supported, "platform" surface backends
quartz backend
--------------
MacOS X >= 10.5 with Xcode >= 3.0
MacOS X >= 10.4 with Xcode >= 2.5
win32 backend
-------------

View file

@ -81,6 +81,14 @@ static void (*CGFontGetGlyphsForUnicharsPtr) (CGFontRef, const UniChar[], const
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;
/* CTFontCreateWithGraphicsFont is not available until 10.5 */
typedef const struct __CTFontDescriptor *CTFontDescriptorRef;
static CTFontRef (*CTFontCreateWithGraphicsFontPtr) (CGFontRef, CGFloat, const CGAffineTransform*, CTFontDescriptorRef) = NULL;
static CGPathRef (*CTFontCreatePathForGlyphPtr) (CTFontRef, CGGlyph, CGAffineTransform *) = NULL;
/* CGFontGetHMetrics isn't public, but the other functions are public/present in 10.5 */
typedef struct {
int ascent;
@ -125,6 +133,11 @@ quartz_font_ensure_symbols(void)
CGFontGetUnitsPerEmPtr = dlsym(RTLD_DEFAULT, "CGFontGetUnitsPerEm");
CGFontGetGlyphAdvancesPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphAdvances");
CTFontCreateWithGraphicsFontPtr = dlsym(RTLD_DEFAULT, "CTFontCreateWithGraphicsFont");
CTFontCreatePathForGlyphPtr = dlsym(RTLD_DEFAULT, "CTFontCreatePathForGlyph");
if (!CTFontCreateWithGraphicsFontPtr || !CTFontCreatePathForGlyphPtr)
CGFontGetGlyphPathPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphPath");
CGFontGetHMetricsPtr = dlsym(RTLD_DEFAULT, "CGFontGetHMetrics");
CGFontGetAscentPtr = dlsym(RTLD_DEFAULT, "CGFontGetAscent");
CGFontGetDescentPtr = dlsym(RTLD_DEFAULT, "CGFontGetDescent");
@ -140,6 +153,7 @@ quartz_font_ensure_symbols(void)
CGFontGetGlyphsForUnicharsPtr &&
CGFontGetUnitsPerEmPtr &&
CGFontGetGlyphAdvancesPtr &&
((CTFontCreateWithGraphicsFontPtr && CTFontCreatePathForGlyphPtr) || CGFontGetGlyphPathPtr) &&
(CGFontGetHMetricsPtr || (CGFontGetAscentPtr && CGFontGetDescentPtr && CGFontGetLeadingPtr)))
_cairo_quartz_font_symbols_present = TRUE;
@ -545,7 +559,6 @@ _cairo_quartz_init_glyph_path (cairo_quartz_scaled_font_t *font,
CGGlyph glyph = _cairo_quartz_scaled_glyph_index (scaled_glyph);
CGAffineTransform textMatrix;
CGPathRef glyphPath;
CTFontRef ctFont;
cairo_path_fixed_t *path;
if (glyph == INVALID_GLYPH) {
@ -560,9 +573,14 @@ _cairo_quartz_init_glyph_path (cairo_quartz_scaled_font_t *font,
-font->base.scale.yy,
0, 0);
ctFont = CTFontCreateWithGraphicsFont (font_face->cgFont, 1.0, NULL, NULL);
glyphPath = CTFontCreatePathForGlyph (ctFont, glyph, &textMatrix);
CFRelease (ctFont);
if (CTFontCreateWithGraphicsFontPtr && CTFontCreatePathForGlyphPtr) {
CTFontRef ctFont = CTFontCreateWithGraphicsFontPtr (font_face->cgFont, 1.0, NULL, NULL);
glyphPath = CTFontCreatePathForGlyphPtr (ctFont, glyph, &textMatrix);
CFRelease (ctFont);
} else {
glyphPath = CGFontGetGlyphPathPtr (font_face->cgFont, &textMatrix, 0, glyph);
}
if (!glyphPath)
return CAIRO_INT_STATUS_UNSUPPORTED;

View file

@ -44,12 +44,13 @@
#include "cairo-quartz.h"
#include "cairo-surface-clipper-private.h"
#ifdef CGFLOAT_DEFINED
typedef CGFloat cairo_quartz_float_t;
#else
typedef float cairo_quartz_float_t;
#ifndef CGFLOAT_DEFINED
/* On 10.4, Quartz APIs used float instead of CGFloat */
typedef float CGFloat;
#endif
typedef CGFloat cairo_quartz_float_t;
typedef enum {
DO_DIRECT,
DO_SHADING,
@ -57,6 +58,9 @@ typedef enum {
DO_TILED_IMAGE
} cairo_quartz_action_t;
/* define CTFontRef for pre-10.5 SDKs */
typedef const struct __CTFont *CTFontRef;
typedef struct cairo_quartz_surface {
cairo_surface_t base;