Re: A patch to detect CTFont API availability (Re: [PATCH 2/3] Update README with new minimum MacOSX requirements)

Andrea Canciani <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAN_5=BDkEPHx0uwKzVniQAzaWGkN1TK_2BNLy4AMPvEMe9S+bg@mail.gmail.com>
On Tue, Mar 10, 2015 at 12:17 PM, suzuki toshiya <[email protected]
> wrote:

> Hi,
>
> Here I propose a patch to restore the support of Mac OS X 10.4
> support, which detects the CTFont availability by configure,
> following to the design by Ryan Schmidt
> http://lists.cairographics.org/archives/cairo/2015-February/025959.html
>
> I don't think the change is too complex to drop Mac OS X 10.4
> support... How do you think of?
>

The change itself is not very complex, but maintaining 10.4 is becoming
unfeasible, given that testing is very hard.
This is confirmed by the bug you have in your patch :P (see comment inline).

Instead of adding #ifdef's and configure-time detection (which is usually
the wrong thing to do for mac, as you might be compiling with a newer SDK
and targeting an old OSX version), the commit you're looking for should be
something like
http://cgit.freedesktop.org/~ranma42/cairo/commit/?h=wip/restore-10.4&id=c2d111ecbf729fe1ecdfcc260f2c51cd3e96fe37

Another option, which at least to me sounds very appealing, is to let 10.4
die (from Apple's point of view, it's unsupported since September 2009) and
cleanup cairo-quartz as in
http://cgit.freedesktop.org/~ranma42/cairo/commit/?h=wip/remove-10.4&id=66b5419704aa1971c77de764fd94b2f7d2a05b76
This would remove most of the weirdness in the quartz backend (the two
bigger culprits are currently blend modes and font metrics).

Of course, if the remove-10.4 branch was merged, the patch to restore 10.4
would be much more complex, so we could say that supporting 10.4 requires a
significant complexity in cairo-quartz.

Andrea


> Regards,
> mpsuzuki
>
>
> Andrea Canciani wrote:
> > From: Andrea Canciani <[email protected]>
> >
> > Since 70cc8f250b5669e757b4f044571ba0f71e3dea9e the quartz backend is
> > using some APIs that are not available on MacOSX 10.4 directly
> > (i.e. without detecting their availability through dynamic linking).
> > This means that the quartz backend does not work anymore on MacOSX
> > 10.4 and that the 10.5 SDK (or newer) is needed to build.
> > ---
> >  README | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/README b/README
> > index 5926430..0be9947 100644
> > --- a/README
> > +++ b/README
> > @@ -121,7 +121,7 @@ Supported, "platform" surface backends
> >
> >       quartz backend
> >       --------------
> > -     MacOS X >= 10.4 with Xcode >= 2.4
> > +     MacOS X >= 10.5 with Xcode >= 3.0
> >
> >       win32 backend
> >       -------------

diff --git a/configure.ac b/configure.ac

index 2ce1959..23216c2 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -210,8 +210,43 @@ CAIRO_ENABLE_SURFACE_BACKEND(quartz, Quartz, auto, [
>
>  CAIRO_ENABLE_FONT_BACKEND(quartz_font, Quartz, auto, [
>    use_quartz_font=$use_quartz
> +  if test "x$use_quartz_font" = "xyes" ; then
> +    dnl include Quartz header to check CTFontRef declaration
> +    header_for_CTFontRef=""
> +    if test "x${ac_cv_header_ApplicationServices_ApplicationServices_h}"
> = "xyes" ; then
> +      header_for_CTFontRef=ApplicationServices/ApplicationServices.h
> +    else
> +      AC_CHECK_HEADER(CoreText/CoreText.h,[
> +        header_for_CTFontRef=CoreText/CoreText.h
> +      ],[])
> +    fi
> +
> +    if test "x${header_for_CTFontRef}" != "x" ; then
> +      AC_CHECK_TYPE(CTFontRef,[
> +          AC_DEFINE([QUARTZ_HAS_CTFONTREF_T], 1, [Define to 1 if
> CTFontRef type is defined in CTFont.h])
> +        ],[],[#include "${header_for_CTFontRef}"]
> +      )
> +    fi
> +  fi
>  ])
>
> +if test "x$use_quartz" = "xyes" ; then
> +  dnl include Quartz header to check CGDataProviderReleaseDataCallback
> declaration
> +  header_for_CGDataProviderReleaseDataCallback=""
> +  if test "x${ac_cv_header_ApplicationServices_ApplicationServices_h}" =
> "xyes" ; then
> +
> header_for_CGDataProviderReleaseDataCallback=ApplicationServices/ApplicationServices.h
> +  elif test "x${ac_cv_header_CoreGraphics_CoreGraphics_h}" = "xyes" ; then
> +
> header_for_CGDataProviderReleaseDataCallback=CoreGraphics/CoreGraphics.h
> +  fi
> +
> +  if test "x${header_for_CGDataProviderReleaseDataCallback}" != "x" ; then
> +    AC_CHECK_TYPE(CGDataProviderReleaseDataCallback,[
> +        AC_DEFINE([QUARTZ_HAS_CGDATAPROVIDERRELEASEDATACALLBACK_T], 1,
> [Define to 1 if CGDataProviderReleaseDataCallback type is defined in
> CGDataProvider.h])
> +      ],[],[#include "${header_for_CGDataProviderReleaseDataCallback}"]
> +    )
> +  fi
> +fi
> +
>  CAIRO_ENABLE_SURFACE_BACKEND(quartz_image, Quartz Image, no, [
>    use_quartz_image=$use_quartz
>  ])
> diff --git a/src/cairo-quartz-font.c b/src/cairo-quartz-font.c
> index 02f3426..35fe24d 100644
> --- a/src/cairo-quartz-font.c
> +++ b/src/cairo-quartz-font.c
> @@ -81,6 +81,18 @@ 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;
> +
> +/* CoreText Replacement of CGFontGetGlyphPathPtr */
> +#ifdef QUARTZ_HAS_CTFONTREF_T

+static CTFontRef (*CTFontCreateWithGraphicsFontPtr) (CGFontRef , CGFloat
> size, const CGAffineTransform*, CTFontDescriptorRef) = NULL;

+static CGPathRef (*CTFontCreatePathForGlyphPtr) (CTFontRef, CGGlyph,
> CGAffineTransform *) = NULL;
> +#else
> +static void* CTFontCreateWithGraphicsFontPtr = NULL;
> +static void* CTFontCreatePathForGlyphPtr = NULL;
> +#endif
> +
>  /* CGFontGetHMetrics isn't public, but the other functions are
> public/present in 10.5 */
>  typedef struct {
>      int ascent;
> @@ -125,6 +137,13 @@ quartz_font_ensure_symbols(void)
>      CGFontGetUnitsPerEmPtr = dlsym(RTLD_DEFAULT, "CGFontGetUnitsPerEm");
>      CGFontGetGlyphAdvancesPtr = dlsym(RTLD_DEFAULT,
> "CGFontGetGlyphAdvances");
>
> +#ifdef QUARTZ_HAS_CTFONTREF_T
> +    CTFontCreateWithGraphicsFontPtr = dlsym(RTLD_DEFAULT,
> "CTFontCreateWithGraphicsFont");
> +    CTFontCreatePathForGlyphPtr = dlsym(RTLD_DEFAULT,
> "CTFontCreatePathForGlyphPtr");
>

Hidden bug!
CTFontCreatePathForGlyphPtr = dlsym(RTLD_DEFAULT,
"CTFontCreatePathForGlyphPtr");
should be
CTFontCreatePathForGlyphPtr = dlsym(RTLD_DEFAULT,
"CTFontCreatePathForGlyph");


> +    if (!CTFontCreateWithGraphicsFontPtr || !CTFontCreatePathForGlyphPtr)
> +#endif
> +       CGFontGetGlyphPathPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphPath");
> +
>      CGFontGetHMetricsPtr = dlsym(RTLD_DEFAULT, "CGFontGetHMetrics");
>      CGFontGetAscentPtr = dlsym(RTLD_DEFAULT, "CGFontGetAscent");
>      CGFontGetDescentPtr = dlsym(RTLD_DEFAULT, "CGFontGetDescent");
> @@ -140,6 +159,7 @@ quartz_font_ensure_symbols(void)
>         CGFontGetGlyphsForUnicharsPtr &&
>         CGFontGetUnitsPerEmPtr &&
>         CGFontGetGlyphAdvancesPtr &&
> +       ((CTFontCreateWithGraphicsFontPtr && CTFontCreatePathForGlyphPtr)
> || CGFontGetGlyphPathPtr) &&
>         (CGFontGetHMetricsPtr || (CGFontGetAscentPtr &&
> CGFontGetDescentPtr && CGFontGetLeadingPtr)))
>         _cairo_quartz_font_symbols_present = TRUE;
>
> @@ -545,7 +565,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 +579,14 @@ _cairo_quartz_init_glyph_path
> (cairo_quartz_scaled_font_t *font,
>                                         -font->base.scale.yy,
>                                         0, 0);
>
> -    ctFont = CTFontCreateWithGraphicsFont (font_face->cgFont, 0.0, NULL,
> NULL);
> -    glyphPath = CTFontCreatePathForGlyph (ctFont, glyph, &textMatrix);
> -    CFRelease (ctFont);
> +#ifdef QUARTZ_HAS_CTFONTREF_T
> +    if (CTFontCreateWithGraphicsFontPtr && CTFontCreatePathForGlyphPtr) {
> +        CTFontRef ctFont = CTFontCreateWithGraphicsFontPtr
> (font_face->cgFont, 0.0, NULL, NULL);
> +        glyphPath = CTFontCreatePathForGlyphPtr (ctFont, glyph,
> &textMatrix);
> +        CFRelease (ctFont);
> +    } else
> +#endif
> +       glyphPath = CGFontGetGlyphPathPtr (font_face->cgFont, &textMatrix,
> 0, glyph);
>      if (!glyphPath)
>         return CAIRO_INT_STATUS_UNSUPPORTED;
>
>
>

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.