[cairo] [PATCH] Re: cairo-quartz-font.c: Non-public CGFontGetGlyphPath now deprecated
Andrea Canciani
ranma42 at gmail.com
Fri Jul 11 00:16:25 PDT 2014
On Wed, Jul 9, 2014 at 8:46 AM, Simon Cozens <simon at simon-cozens.org> wrote:
> On Thu, Jun 19, 2014 at 03:50:26PM +0900, Simon Cozens wrote:
> > I am guessing that the official way to do things is to move to Core
> > Text and CTFontCreatePathForGlyph.
>
> I've now done this, and it works...
>
> diff --git a/configure.ac b/configure.ac
> index 04479ff..f262dac 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -200,7 +200,7 @@ CAIRO_ENABLE_SURFACE_BACKEND(quartz, Quartz, auto, [
> if test "x$use_quartz" != "xyes" ; then
> dnl check for CoreGraphics as a separate framework
> AC_CHECK_HEADER(CoreGraphics/CoreGraphics.h, , [use_quartz="no
> (requires CoreGraphics framework)"])
> - quartz_LIBS="-Xlinker -framework -Xlinker CoreGraphics"
> + quartz_LIBS="-Xlinker -framework -Xlinker CoreGraphics -framework
> -Xlinker CoreText"
>
Is this also going to work on 10.4?
IIRC the CoreText API has been introduced in 10.5, so we should avoid
linking it.
> else
> quartz_LIBS="-Xlinker -framework -Xlinker ApplicationServices"
> fi
> diff --git a/src/cairo-quartz-font.c b/src/cairo-quartz-font.c
> index e6a379a..4518421 100644
> --- a/src/cairo-quartz-font.c
> +++ b/src/cairo-quartz-font.c
> @@ -81,8 +81,8 @@ 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;
> +static CTFontRef (*CTFontCreateWithGraphicsFontPtr) (CGFontRef fontRef) =
> NULL;
> +static CGPathRef (*CTFontCreatePathForGlyphPtr) (CTFontRef fontRef,
> CGGlyph glyph, CGAffineTransform *textTransform) = NULL;
>
> /* CGFontGetHMetrics isn't public, but the other functions are
> public/present in 10.5 */
> typedef struct {
> @@ -127,7 +127,8 @@ quartz_font_ensure_symbols(void)
> /* These have the same name in 10.4 and 10.5 */
> CGFontGetUnitsPerEmPtr = dlsym(RTLD_DEFAULT, "CGFontGetUnitsPerEm");
> CGFontGetGlyphAdvancesPtr = dlsym(RTLD_DEFAULT,
> "CGFontGetGlyphAdvances");
> - CGFontGetGlyphPathPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphPath");
> + CTFontCreatePathForGlyphPtr = dlsym(RTLD_DEFAULT,
> "CTFontCreatePathForGlyph");
> + CTFontCreateWithGraphicsFontPtr = dlsym(RTLD_DEFAULT,
> "CTFontCreateWithGraphicsFont");
>
> CGFontGetHMetricsPtr = dlsym(RTLD_DEFAULT, "CGFontGetHMetrics");
> CGFontGetAscentPtr = dlsym(RTLD_DEFAULT, "CGFontGetAscent");
> @@ -144,7 +145,8 @@ quartz_font_ensure_symbols(void)
> CGFontGetGlyphsForUnicharsPtr &&
> CGFontGetUnitsPerEmPtr &&
> CGFontGetGlyphAdvancesPtr &&
> - CGFontGetGlyphPathPtr &&
> + CTFontCreateWithGraphicsFontPtr &&
> + CTFontCreatePathForGlyphPtr &&
>
An alternative which should also work on 10.4 looks like this:
(CGFontGetGlyphPathPtr || (CTFontCreateWithGraphicsFontPtr &&
CTFontCreatePathForGlyphPtr)) &&
> (CGFontGetHMetricsPtr || (CGFontGetAscentPtr && CGFontGetDescentPtr &&
> CGFontGetLeadingPtr)))
> _cairo_quartz_font_symbols_present = TRUE;
>
> @@ -550,6 +552,7 @@ _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) {
> @@ -564,7 +567,8 @@ _cairo_quartz_init_glyph_path
> (cairo_quartz_scaled_font_t *font,
> -font->base.scale.yy,
> 0, 0);
>
> - glyphPath = CGFontGetGlyphPathPtr (font_face->cgFont, &textMatrix, 0,
> glyph);
> + ctFont = CTFontCreateWithGraphicsFontPtr (font_face->cgFont);
> + glyphPath = CTFontCreatePathForGlyphPtr (ctFont, glyph, &textMatrix);
>
Assuming the new check in the ensure function, you could do:
if (CTFontCreateWithGraphicsFontPtr && CTFontCreatePathForGlyphPtr) {
CTFontRef ctFont = CTFontCreateWithGraphicsFontPtr (font_face->cgFont);
glyphPath = CTFontCreatePathForGlyphPtr (ctFont, glyph, &textMatrix);
CFRelease(ctFont);
} else {
glyphPath = CGFontGetGlyphPathPtr (font_face->cgFont, &textMatrix, 0,
glyph);
}
I added CFRelease() because all of the examples of use of CTFont seem to
release it in this way.
Unfortunately right now I am unable to test the code, hence do not trust it.
Given that the minimum requirements for Firefox are now of MacOS X 10.6, it
might also be time to revisit the versions supported by Cairo.
This would also make it possible to get rid of most of the dynamic function
discovery mechanism, as only CGContextGetType and
CGContextGetAllowsFontSmoothing are not public in 10.6.
Jeff, Chris, what do you think about this?
I am afraid that testing on 10.4 will become increasingly difficult over
time (I would guess that even Mozilla is not testing anymore on it, as
they're not supporting it anymore).
Andrea
if (!glyphPath)
> return CAIRO_INT_STATUS_UNSUPPORTED;
>
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20140711/b5e627ea/attachment.html>
More information about the cairo
mailing list