]> git.eshelyaron.com Git - emacs.git/commitdiff
Port the font backend from the Mac port.
authorJan Djärv <jan.h.d@swipnet.se>
Sun, 15 Sep 2013 17:58:46 +0000 (19:58 +0200)
committerJan Djärv <jan.h.d@swipnet.se>
Sun, 15 Sep 2013 17:58:46 +0000 (19:58 +0200)
* configure.ac: Add check for OSX 10.5, required for macfont.o.

* etc/NEWS: Mention the macfont backend.

* src/Makefile.in (NS_OBJ, SOME_MACHINE_OBJECTS): Add macfont.o.

* src/font.c (syms_of_font): Call syms_of_macfont.

* src/font.h: Declare syms_of_macfont.

* src/nsfns.m: Include macfont.h.
(Fx_create_frame): Register macfont driver, make a better default font.
(Fns_popup_font_panel): Get font from macfont driver, if used.

* src/nsfont.m (ns_tmp_flags, ns_tmp_font): Remove.
(nsfont_open): Set font driver type.
Set font->ascent and font->descent.  Figure out font instead of
ns_tmp_font, and flags instead of ns_tmp_flags.
Fix indentation. Remove call to ns_draw_text_decoration,
moved to nsterm.

* src/nsterm.m: Include macfont.h.
(ns_tmp_flags, ns_tmp_font): Remove.
(ns_compute_glyph_string_overhangs): Check for driver Qns.
(ns_draw_glyph_string): Use local variables instead of ns_tmp_flags,
ns_tmp_font.  Call ns_draw_text_decoration here instead of nsfont.m.
(changeFont:): Fix code style.  Check for font driver type when
getiing font.

* src/nsterm.h (FONT_DESCENT, FONT_ASCENT): Define to (f)->ascent and
(f)->descent.

12 files changed:
ChangeLog
configure.ac
etc/ChangeLog
etc/NEWS
src/ChangeLog
src/Makefile.in
src/font.c
src/font.h
src/nsfns.m
src/nsfont.m
src/nsterm.h
src/nsterm.m

index 4fc4e065e9275223ad79faa076458d68aac541ea..c034a2930043e977b6f77c79d77fbfdcce4c69fe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2013-09-15  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * configure.ac: Add check for OSX 10.5, required for macfont.o.
+
 2013-09-09  Glenn Morris  <rgm@gnu.org>
 
        * configure.ac (LDFLAGS_NOCOMBRELOC): New variable.
index ab2e48b6f0fc6bd2cb6185a2b19f97aa8e6fbac0..86a5f300982f4759f059a0d926a6de8c12e35bba 100644 (file)
@@ -1623,7 +1623,10 @@ fail;
                  [AC_MSG_ERROR([`--with-ns' was specified, but the include
   files are missing or cannot be compiled.])])
 
-  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <AppKit/AppKit.h>],
+  macfont_file=""
+  if test "${NS_IMPL_COCOA}" = "yes"; then
+    AC_MSG_CHECKING([for OSX 10.4 or newer])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <AppKit/AppKit.h>],
                                      [
 #ifdef MAC_OS_X_VERSION_MAX_ALLOWED
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
@@ -1635,13 +1638,33 @@ fail;
                    ])],
                    ns_osx_have_104=yes,
                    ns_osx_have_104=no)
+    AC_MSG_RESULT([$ns_osx_have_104])
+
+    if test $ns_osx_have_104 = no; then
+       AC_MSG_ERROR([`OSX 10.4 or newer is required']);
+    fi
+    AC_MSG_CHECKING([for OSX 10.5 or newer])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <AppKit/AppKit.h>],
+                                     [
+#ifdef MAC_OS_X_VERSION_MAX_ALLOWED
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
+ ; /* OK */
+#else
+#error "OSX 10.5 not found"
+#endif
+#endif
+                   ])],
+                   ns_osx_have_105=yes,
+                   ns_osx_have_105=no)
+    AC_MSG_RESULT([$ns_osx_have_105])
+    if test $ns_osx_have_105 = yes; then
+      macfont_file="macfont.o"
+    fi
+  fi
   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <Foundation/NSObjCRuntime.h>],
                                      [NSInteger i;])],
                    ns_have_nsinteger=yes,
                    ns_have_nsinteger=no)
-  if test $ns_osx_have_104 = no; then
-     AC_MSG_ERROR([`OSX 10.4 or newer is required']);
-  fi
   if test $ns_have_nsinteger = yes; then
     AC_DEFINE(NS_HAVE_NSINTEGER, 1, [Define to 1 if `NSInteger' is defined.])
   fi
@@ -1677,7 +1700,8 @@ if test "${HAVE_NS}" = yes; then
      leimdir="\${ns_appresdir}/leim"
      INSTALL_ARCH_INDEP_EXTRA=
   fi
-  NS_OBJC_OBJ="nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o"
+
+  NS_OBJC_OBJ="nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o $macfont_file"
 fi
 CFLAGS="$tmp_CFLAGS"
 CPPFLAGS="$tmp_CPPFLAGS"
index bd5534d94468becbb20a5a49701fb68458370373..5483d824da459cb3faeaa3f8fca0c744b50ec76f 100644 (file)
@@ -1,3 +1,7 @@
+2013-09-15  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * NEWS: Mention the macfont backend.
+
 2013-09-09  Glenn Morris  <rgm@gnu.org>
 
        * refcards/Makefile (PS_ENGLISH, PS_CZECH, PS_FRENCH, PS_GERMAN)
index a5da8eaa89313a21a6f422c7b20d79ad8e8a2f7a..7558fc530521bfc1cd3823e531375cd5b53420c6 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -54,6 +54,11 @@ and zlib-format compressed data.
 ** Emacs for NS (OSX, GNUStep) can be built with ImageMagick support.
 pkg-config is required to find ImageMagick libraries.
 
+** For OSX >= 10.5, the Core text based font backend from the Mac port is used.
+For GNUStep and OSX 10.4 the old backend is used.
+To use the old backend by default, do on the command line:
+% defaults write org.gnu.Emacs FontBackend ns
+
 \f
 * Startup Changes in Emacs 24.4
 
index 5f28dc3d7dfdd25d1992238457fb4fdd7bad34e9..e3b29c9b21d28c1cc3246b37cce0537b2b617f7a 100644 (file)
@@ -1,3 +1,35 @@
+2013-09-15  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * nsterm.m: Include macfont.h.
+       (ns_tmp_flags, ns_tmp_font): Remove.
+       (ns_compute_glyph_string_overhangs): Check for driver Qns.
+       (ns_draw_glyph_string): Use local variables instead of ns_tmp_flags,
+       ns_tmp_font.  Call ns_draw_text_decoration here instead of nsfont.m.
+       (changeFont:): Fix code style.  Check for font driver type when
+       getiing font.
+
+       * nsterm.h (FONT_DESCENT, FONT_ASCENT): Define to (f)->ascent and
+       (f)->descent.
+
+       * nsfont.m (ns_tmp_flags, ns_tmp_font): Remove.
+       (nsfont_open): Set font driver type.
+       Set font->ascent and font->descent.  Figure out font instead of
+       ns_tmp_font, and flags instead of ns_tmp_flags.
+       Fix indentation. Remove call to ns_draw_text_decoration,
+       moved to nsterm.
+
+       * nsfns.m: Include macfont.h.
+       (Fx_create_frame): Register macfont driver, make a better default font.
+       (Fns_popup_font_panel): Get font from macfont driver, if used.
+
+       * macfont.m, macfont.h, maccuvs.h: New files.
+
+       * font.h: Declare syms_of_macfont.
+
+       * font.c (syms_of_font): Call syms_of_macfont.
+
+       * Makefile.in (NS_OBJ, SOME_MACHINE_OBJECTS): Add macfont.o.
+
 2013-09-15  Dmitry Antipov  <dmantipov@yandex.ru>
 
        Drop VERTICAL_SCROLL_BAR_WIDTH_TRIM.  For X, it is zero since 1999,
index fe8d2d13ce074a8d777eeda86bd94aaf87549da6..254aa175d49860f9de37dedcc237d1cfe9ca3009 100644 (file)
@@ -266,7 +266,7 @@ MSDOS_OBJ =
 MSDOS_X_OBJ =
 
 NS_OBJ=@NS_OBJ@
-## nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o if HAVE_NS.
+## nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o macfont.o if HAVE_NS.
 NS_OBJC_OBJ=@NS_OBJC_OBJ@
 ## Only set if NS_IMPL_GNUSTEP.
 GNU_OBJC_CFLAGS=@GNU_OBJC_CFLAGS@
@@ -388,7 +388,7 @@ obj = $(base_obj) $(NS_OBJC_OBJ)
 SOME_MACHINE_OBJECTS = dosfns.o msdos.o \
   xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \
   fontset.o dbusbind.o cygw32.o \
-  nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o \
+  nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o macfont.o \
   w32.o w32console.o w32fns.o w32heap.o w32inevt.o w32notify.o \
   w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o \
   w16select.o widget.o xfont.o ftfont.o xftfont.o ftxfont.o gtkutil.o \
index fb64f2d9071c13d8449947a26b36a5b772b19ef5..27f4f5dca91d2b31a2753e3746501057f7f7d218 100644 (file)
@@ -5199,6 +5199,7 @@ EMACS_FONT_LOG is set.  Otherwise, it is set to t.  */);
 #endif /* HAVE_NTGUI */
 #ifdef HAVE_NS
   syms_of_nsfont ();
+  syms_of_macfont ();
 #endif /* HAVE_NS */
 #endif /* HAVE_WINDOW_SYSTEM */
 }
index 3e0d97baaacc97d0dc022f0aa1d2fa03a96026b7..0ec56590916a590730dfb32fe01b0139ce3afffc 100644 (file)
@@ -825,6 +825,7 @@ extern void syms_of_w32font (void);
 extern Lisp_Object Qfontsize;
 extern struct font_driver nsfont_driver;
 extern void syms_of_nsfont (void);
+extern void syms_of_macfont (void);
 #endif /* HAVE_NS */
 
 #ifndef FONT_DEBUG
index 8eaf529ed0476b25629db5550de3530154107d4e..1b4e6b7f57ec05c69ae3320162d5819f5535c194 100644 (file)
@@ -46,6 +46,9 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
 
 #ifdef NS_IMPL_COCOA
 #include <IOKit/graphics/IOGraphicsLib.h>
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+#include "macfont.h"
+#endif
 #endif
 
 #if 0
@@ -1171,7 +1174,17 @@ This function is an internal primitive--use `make-frame' instead.  */)
     }
 
   block_input ();
+
+#ifdef NS_IMPL_GNUSTEP ||                               \
+  MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
   register_font_driver (&nsfont_driver, f);
+#else
+  if (CTGetCoreTextVersion != NULL
+      && CTGetCoreTextVersion () >= kCTVersionNumber10_5)
+    mac_register_font_driver (f);
+  register_font_driver (&nsfont_driver, f);
+#endif
+
   x_default_parameter (f, parms, Qfont_backend, Qnil,
                        "fontBackend", "FontBackend", RES_TYPE_STRING);
 
@@ -1181,8 +1194,13 @@ This function is an internal primitive--use `make-frame' instead.  */)
     x_default_parameter (f, parms, Qfontsize,
                                     make_number (0 /*(int)[font pointSize]*/),
                                     "fontSize", "FontSize", RES_TYPE_NUMBER);
+    // Remove ' Regular', not handled by backends.
+    char *fontname = xstrdup ([[font displayName] UTF8String]);
+    int len = strlen (fontname);
+    if (len > 8 && strcmp (fontname + len - 8, " Regular") == 0)
+      fontname[len-8] = '\0';
     x_default_parameter (f, parms, Qfont,
-                                 build_string ([[font fontName] UTF8String]),
+                                 build_string (fontname),
                                  "font", "Font", RES_TYPE_STRING);
   }
   unblock_input ();
@@ -1362,9 +1380,15 @@ DEFUN ("ns-popup-font-panel", Fns_popup_font_panel, Sns_popup_font_panel,
 {
   struct frame *f = decode_window_system_frame (frame);
   id fm = [NSFontManager sharedFontManager];
-
-  [fm setSelectedFont: ((struct nsfont_info *)f->output_data.ns->font)->nsfont
-           isMultiple: NO];
+  struct font *font = f->output_data.ns->font;
+  NSFont *nsfont;
+  if (EQ (font->driver->type, Qns))
+    nsfont = ((struct nsfont_info *)font)->nsfont;
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+  else
+    nsfont = (NSFont *) macfont_get_nsctfont (font);
+#endif
+  [fm setSelectedFont: nsfont isMultiple: NO];
   [fm orderFrontFontPanel: NSApp];
   return Qnil;
 }
index b61147d66c4534725f2f4a20b87125228e93a6ce..d9c8660f1cd72122e8638d61189678863a4e10ce 100644 (file)
@@ -51,8 +51,6 @@ static Lisp_Object Qapple, Qroman, Qmedium;
 static Lisp_Object Qcondensed, Qexpanded;
 extern Lisp_Object Qappend;
 extern float ns_antialias_threshold;
-extern int ns_tmp_flags;
-extern struct nsfont_info *ns_tmp_font;
 
 
 /* font glyph and metrics caching functions, implemented at end */
@@ -798,6 +796,7 @@ nsfont_open (struct frame *f, Lisp_Object font_entity, int pixel_size)
 
   font_object = font_make_object (VECSIZE (struct nsfont_info),
                                   font_entity, pixel_size);
+  ASET (font_object, FONT_TYPE_INDEX, nsfont_driver.type);
   font_info = (struct nsfont_info *) XFONT_OBJECT (font_object);
   font = (struct font *) font_info;
   if (!font)
@@ -871,10 +870,11 @@ nsfont_open (struct frame *f, Lisp_Object font_entity, int pixel_size)
     font_info->size = font->pixel_size;
 
     /* max bounds */
-    font_info->max_bounds.ascent = lrint ([sfont ascender]);
+    font->ascent = font_info->max_bounds.ascent = lrint ([sfont ascender]);
     /* Descender is usually negative.  Use floor to avoid
        clipping descenders. */
-    font_info->max_bounds.descent = -lrint (floor(adjusted_descender));
+    font->descent =
+      font_info->max_bounds.descent = -lrint (floor(adjusted_descender));
     font_info->height =
       font_info->max_bounds.ascent + font_info->max_bounds.descent;
     font_info->max_bounds.width = lrint (font_info->width);
@@ -1051,16 +1051,26 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
 #endif
   struct face *face;
   NSRect r;
-  struct nsfont_info *font = ns_tmp_font;
+  struct nsfont_info *font;
   NSColor *col, *bgCol;
   unsigned short *t = s->char2b;
-  int i, len;
+  int i, len, flags;
   char isComposite = s->first_glyph->type == COMPOSITE_GLYPH;
   int end = isComposite ? s->cmp_to : s->nchars;
 
   block_input ();
+
+  font = (struct nsfont_info *)s->face->font;
+  if (font == NULL)
+    font = (struct nsfont_info *)FRAME_FONT (s->f);
+
   /* Select face based on input flags */
-  switch (ns_tmp_flags)
+  flags = s->hl == DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR :
+    (s->hl == DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE :
+     (s->for_overlaps ? NS_DUMPGLYPH_FOREGROUND :
+      NS_DUMPGLYPH_NORMAL));
+
+  switch (flags)
     {
     case NS_DUMPGLYPH_CURSOR:
       face = s->face;
@@ -1188,8 +1198,8 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
   col = (NS_FACE_FOREGROUND (face) != 0
          ? ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f)
          : FRAME_FOREGROUND_COLOR (s->f));
-  /* FIXME: find another way to pass this */
-  bgCol = (ns_tmp_flags != NS_DUMPGLYPH_FOREGROUND ? nil
+
+  bgCol = (flags != NS_DUMPGLYPH_FOREGROUND ? nil
            : (NS_FACE_BACKGROUND (face) != 0
               ? ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f)
               : FRAME_BACKGROUND_COLOR (s->f)));
@@ -1264,22 +1274,19 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
 
     CGContextSetTextPosition (gcontext, r.origin.x, r.origin.y);
     CGContextShowGlyphsWithAdvances (gcontext, s->char2b + s->cmp_from,
-                                    advances, len);
+                                     advances, len);
 
     if (face->overstrike)
       {
         CGContextSetTextPosition (gcontext, r.origin.x+0.5, r.origin.y);
         CGContextShowGlyphsWithAdvances (gcontext, s->char2b + s->cmp_from,
-                                        advances, len);
+                                         advances, len);
       }
 
     CGContextRestoreGState (gcontext);
   }
 #endif  /* NS_IMPL_COCOA */
 
-  /* Draw underline, overline, strike-through. */
-  ns_draw_text_decoration (s, face, col, r.size.width, r.origin.x);
-
   unblock_input ();
   return to-from;
 }
index d8482cebbb068e4cb9e951ebe506d779bcd282fd..1b5804b98b5e7a516f5fa42a14f2aa781c029d50 100644 (file)
@@ -701,10 +701,8 @@ struct x_output
 
 #define FONT_WIDTH(f)  ((f)->max_width)
 #define FONT_HEIGHT(f) ((f)->height)
-/*#define FONT_BASE(f)    ((f)->ascent) */
-#define FONT_BASE(f)    (((struct nsfont_info *)f)->max_bounds.ascent)
-/*#define FONT_DESCENT(f) ((f)->descent) */
-#define FONT_DESCENT(f) (((struct nsfont_info *)f)->max_bounds.descent)
+#define FONT_BASE(f)    ((f)->ascent)
+#define FONT_DESCENT(f) ((f)->descent)
 
 #define FRAME_DEFAULT_FACE(f) FACE_FROM_ID (f, DEFAULT_FACE_ID)
 
index 1dac6ba9fe43bb193a00392bb7b38cf53accd222..2fc8a09c80f842d1dce626fcaf196c3c20e879ca 100644 (file)
@@ -64,6 +64,12 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
 #include "process.h"
 #endif
 
+#ifdef NS_IMPL_COCOA
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+#include "macfont.h"
+#endif
+#endif
+
 /* call tracing */
 #if 0
 int term_trace_num = 0;
@@ -198,8 +204,6 @@ static NSRect uRect;
 #endif
 static BOOL gsaved = NO;
 static BOOL ns_fake_keydown = NO;
-int ns_tmp_flags; /* FIXME */
-struct nsfont_info *ns_tmp_font; /* FIXME */
 #ifdef NS_IMPL_COCOA
 static BOOL ns_menu_bar_is_hidden = NO;
 #endif
@@ -2158,8 +2162,11 @@ ns_compute_glyph_string_overhangs (struct glyph_string *s)
   else
     {
       s->left_overhang = 0;
-      s->right_overhang = ((struct nsfont_info *)font)->ital ?
-        FONT_HEIGHT (font) * 0.2 : 0;
+      if (EQ (font->driver->type, Qns))
+        s->right_overhang = ((struct nsfont_info *)font)->ital ?
+          FONT_HEIGHT (font) * 0.2 : 0;
+      else
+        s->right_overhang = 0;
     }
 }
 
@@ -3133,8 +3140,10 @@ ns_draw_glyph_string (struct glyph_string *s)
 {
   /* TODO (optimize): focus for box and contents draw */
   NSRect r[2];
-  int n;
+  int n, flags;
   char box_drawn_p = 0;
+  struct font *font = s->face->font;
+  if (! font) font = FRAME_FONT (s->f);
 
   NSTRACE (ns_draw_glyph_string);
 
@@ -3201,13 +3210,10 @@ ns_draw_glyph_string (struct glyph_string *s)
         ns_maybe_dumpglyphs_background
           (s, s->first_glyph->type == COMPOSITE_GLYPH);
 
-      ns_tmp_flags = s->hl == DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR :
-                    (s->hl == DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE :
-                     (s->for_overlaps ? NS_DUMPGLYPH_FOREGROUND :
-                      NS_DUMPGLYPH_NORMAL));
-      ns_tmp_font = (struct nsfont_info *)s->face->font;
-      if (ns_tmp_font == NULL)
-          ns_tmp_font = (struct nsfont_info *)FRAME_FONT (s->f);
+      flags = s->hl == DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR :
+        (s->hl == DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE :
+         (s->for_overlaps ? NS_DUMPGLYPH_FOREGROUND :
+          NS_DUMPGLYPH_NORMAL));
 
       if (s->hl == DRAW_CURSOR && s->w->phys_cursor_type == FILLED_BOX_CURSOR)
         {
@@ -3216,10 +3222,21 @@ ns_draw_glyph_string (struct glyph_string *s)
           NS_FACE_FOREGROUND (s->face) = tmp;
         }
 
-      ns_tmp_font->font.driver->draw
+      font->driver->draw
         (s, 0, s->nchars, s->x, s->y,
-         (ns_tmp_flags == NS_DUMPGLYPH_NORMAL && !s->background_filled_p)
-         || ns_tmp_flags == NS_DUMPGLYPH_MOUSEFACE);
+         (flags == NS_DUMPGLYPH_NORMAL && !s->background_filled_p)
+         || flags == NS_DUMPGLYPH_MOUSEFACE);
+
+      {
+        NSColor *col = (NS_FACE_FOREGROUND (s->face) != 0
+                        ? ns_lookup_indexed_color (NS_FACE_FOREGROUND (s->face),
+                                                   s->f)
+                        : FRAME_FOREGROUND_COLOR (s->f));
+        [col set];
+
+        /* Draw underline, overline, strike-through. */
+        ns_draw_text_decoration (s, s->face, col, s->width, s->x);
+      }
 
       if (s->hl == DRAW_CURSOR && s->w->phys_cursor_type == FILLED_BOX_CURSOR)
         {
@@ -3959,7 +3976,7 @@ static struct redisplay_interface ns_redisplay_interface =
   0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
   0, /* destroy_fringe_bitmap */
   ns_compute_glyph_string_overhangs,
-  ns_draw_glyph_string, /* interface to nsfont.m */
+  ns_draw_glyph_string,
   ns_define_frame_cursor,
   ns_clear_frame_area,
   ns_draw_window_cursor,
@@ -4809,17 +4826,26 @@ not_in_argv (NSString *arg)
 /* called on font panel selection */
 - (void)changeFont: (id)sender
 {
-  NSEvent *e =[[self window] currentEvent];
-  struct face *face =FRAME_DEFAULT_FACE (emacsframe);
+  NSEvent *e = [[self window] currentEvent];
+  struct face *face = FRAME_DEFAULT_FACE (emacsframe);
+  struct font *font = face->font;
   id newFont;
   CGFloat size;
+  NSFont *nsfont;
 
   NSTRACE (changeFont);
+
   if (!emacs_event)
     return;
 
-  if ((newFont = [sender convertFont:
-                           ((struct nsfont_info *)face->font)->nsfont]))
+  if (EQ (font->driver->type, Qns))
+    nsfont = ((struct nsfont_info *)font)->nsfont;
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+  else
+    nsfont = (NSFont *) macfont_get_nsctfont (font);
+#endif
+
+  if ((newFont = [sender convertFont: nsfont]))
     {
       SET_FRAME_GARBAGED (emacsframe); /* now needed as of 2008/10 */