--- src/library/grDevices/src/devQuartz.c.orig	2023-04-04 06:15:01.000000000 +0800
+++ src/library/grDevices/src/devQuartz.c	2023-04-25 17:15:03.000000000 +0800
@@ -38,6 +38,7 @@
 #include "grDevices.h"
 
 #include <CoreFoundation/CoreFoundation.h>
+#include <AvailabilityMacros.h>
 
 #define DEVQUARTZ_VERSION 1 /* first public Quartz API version */
 
@@ -2984,6 +2985,14 @@
     return capabilities; 
 }
 
+
+/* This is an implementation of CTFontDrawGlyphs for < 10.7. */
+static void legacy_CTFontDrawGlyphs(CTFontRef, const CGGlyph glyphs[], const CGPoint points[],
+                                       size_t count, CGContextRef cg)
+{
+    CGContextShowGlyphsAtPositions(cg, glyphs, points, count);
+}
+
 void RQuartz_glyph(int n, int *glyphs, double *x, double *y, 
                    SEXP font, double size,
                    int colour, double rot, pDevDesc dd)
@@ -3032,7 +3041,16 @@
         for (i=0; i<n; i++) {
             CGGlyph glyph = glyphs[i];
             CGPoint loc = CGPointMake(x[i], y[i]);
+#if MAC_OS_X_VERSION_MAX_ALLOWED > 1060
             CTFontDrawGlyphs(ctFont, &glyph, &loc, 1, ctx);
+#else /* Fallback code for legacy systems */
+            /* CTFontDrawGlyphs will apply the font, font size and font matrix to the CGContext. */
+            /* Our 'fake' one does not, so set up the CGContext here. */
+            CGContextSetFont(ctx, ctFont);
+            CGContextSetFontSize(ctx, CTFontGetSize(ctFont));
+            CGContextSetTextMatrix(ctx, CTFontGetMatrix(ctFont));
+            legacy_CTFontDrawGlyphs(ctFont, &glyph, &loc, 1, ctx);
+#endif
         }
         CGColorRelease(fillColorRef);
         CFRelease(ctFont);
