]> code.delx.au - gnu-emacs/blobdiff - src/macfont.m
doh, fixing year in ChangeLog entries introduced by last two commits
[gnu-emacs] / src / macfont.m
index b1fa5a1a41b1bcb83f35cc013f08ba0e7bd94299..cbf1b07bc94370c8db11b9b40f0487f430a3ca9e 100644 (file)
@@ -1,5 +1,5 @@
 /* Font driver on Mac OSX Core text.
-   Copyright (C) 2009-2014 Free Software Foundation, Inc.
+   Copyright (C) 2009-2015 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -36,15 +36,10 @@ Original author: YAMAMOTO Mitsuharu
 #include "macfont.h"
 #include "macuvs.h"
 
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
-
 #include <libkern/OSByteOrder.h>
 
 static struct font_driver macfont_driver;
 
-/* Core Text, for Mac OS X 10.5 and later.  */
-static Lisp_Object Qmac_ct;
-
 static double mac_ctfont_get_advance_width_for_glyph (CTFontRef, CGGlyph);
 static CGRect mac_ctfont_get_bounding_rect_for_glyph (CTFontRef, CGGlyph);
 static CFArrayRef mac_ctfont_create_available_families (void);
@@ -71,18 +66,6 @@ static CGGlyph mac_ctfont_get_glyph_for_cid (CTFontRef,
                                              CGFontIndex);
 #endif
 
-/* The font property key specifying the font design destination.  The
-   value is an unsigned integer code: 0 for WYSIWYG, and 1 for Video
-   text.  (See the documentation of X Logical Font Description
-   Conventions.)  In the Mac font driver, 1 means the screen font is
-   used for calculating some glyph metrics.  You can see the
-   difference with Monaco 8pt or 9pt, for example.  */
-static Lisp_Object QCdestination;
-
-/* The boolean-valued font property key specifying the use of
-   leading.  */
-static Lisp_Object QCminspace;
-
 struct macfont_metrics;
 
 /* The actual structure for Mac font that can be cast to struct font.  */
@@ -926,22 +909,9 @@ macfont_create_family_with_symbol (Lisp_Object symbol)
   if (family_name == NULL)
     return NULL;
 
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
-  if (CTFontManagerCompareFontFamilyNames != NULL)
-#endif
     {
       family_name_comparator = CTFontManagerCompareFontFamilyNames;
     }
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
-  else              /* CTFontManagerCompareFontFamilyNames == NULL */
-#endif
-#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 */
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
-    {
-      family_name_comparator = mac_font_family_compare;
-    }
-#endif
 
   if ((*family_name_comparator) (family_name, CFSTR ("LastResort"), NULL)
       == kCFCompareEqualTo)
@@ -1101,7 +1071,7 @@ macfont_glyph_extents (struct font *font, CGGlyph glyph,
               bounds.size =
                 CGSizeApplyAffineTransform (bounds.size, synthetic_italic_atfm);
             }
-          if (macfont_info->synthetic_bold_p)
+          if (macfont_info->synthetic_bold_p && ! force_integral_p)
             {
               CGFloat d =
                 - synthetic_bold_factor * mac_font_get_size (macfont) / 2;
@@ -1331,12 +1301,8 @@ macfont_get_glyph_for_character (struct font *font, UTF32Char c)
           CGGlyph *glyphs;
           int i, len;
           int nrows;
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
           dispatch_queue_t queue;
           dispatch_group_t group = NULL;
-#else
-          int nkeys;
-#endif
 
           if (row != 0)
             {
@@ -1374,14 +1340,12 @@ macfont_get_glyph_for_character (struct font *font, UTF32Char c)
                   return glyph;
                 }
 
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
               queue =
                 dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
               group = dispatch_group_create ();
               dispatch_group_async (group, queue, ^{
                   int nkeys;
                   uintptr_t key;
-#endif
                   nkeys = nkeys_or_perm;
                   for (key = row * (256 / NGLYPHS_IN_VALUE); ; key++)
                     if (CFDictionaryContainsKey (dictionary,
@@ -1392,9 +1356,7 @@ macfont_get_glyph_for_character (struct font *font, UTF32Char c)
                         if (--nkeys == 0)
                           break;
                       }
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
                 });
-#endif
             }
 
           len = 0;
@@ -1436,13 +1398,11 @@ macfont_get_glyph_for_character (struct font *font, UTF32Char c)
           cache->glyph.matrix[nrows - 1] = glyphs;
           cache->glyph.nrows = nrows;
 
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
           if (group)
             {
               dispatch_group_wait (group, DISPATCH_TIME_FOREVER);
               dispatch_release (group);
             }
-#endif
         }
 
       return cache->glyph.matrix[nkeys_or_perm - ROW_PERM_OFFSET][c % 256];
@@ -2717,7 +2677,8 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
   CGPoint *positions;
   CGFloat font_size = mac_font_get_size (macfont_info->macfont);
   bool no_antialias_p =
-    (macfont_info->antialias == MACFONT_ANTIALIAS_OFF
+    (NILP (ns_antialias_text)
+     || macfont_info->antialias == MACFONT_ANTIALIAS_OFF
      || (macfont_info->antialias == MACFONT_ANTIALIAS_DEFAULT
          && font_size <= macfont_antialias_threshold));
   int len = to - from;
@@ -2731,7 +2692,7 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
                                   s->width, FONT_HEIGHT (s->font));
   else
     background_rect = CGRectNull;
-  
+
   text_position = CGPointMake (x, -y);
   glyphs = xmalloc (sizeof (CGGlyph) * len);
   {
@@ -2760,7 +2721,7 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
 
   if (!CGRectIsNull (background_rect))
     {
-      if (s->hl == DRAW_MOUSE_FACE) 
+      if (s->hl == DRAW_MOUSE_FACE)
         {
           face = FACE_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id);
           if (!face)
@@ -2769,7 +2730,7 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
       CG_SET_FILL_COLOR_WITH_FACE_BACKGROUND (context, face, f);
       CGContextFillRects (context, &background_rect, 1);
     }
-  
+
   if (macfont_info->cgfont)
     {
       CGAffineTransform atfm;
@@ -2780,7 +2741,7 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
         atfm = synthetic_italic_atfm;
       else
         atfm = CGAffineTransformIdentity;
-      if (macfont_info->synthetic_bold_p)
+      if (macfont_info->synthetic_bold_p && ! no_antialias_p)
         {
           CGContextSetTextDrawingMode (context, kCGTextFillStroke);
           CGContextSetLineWidth (context, synthetic_bold_factor * font_size);
@@ -2827,9 +2788,9 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
 static Lisp_Object
 macfont_shape (Lisp_Object lgstring)
 {
-  struct font *font;
-  struct macfont_info *macfont_info;
-  FontRef macfont;
+  struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring));
+  struct macfont_info *macfont_info = (struct macfont_info *) font;
+  FontRef macfont = macfont_info->macfont;
   ptrdiff_t glyph_len, len, i, j;
   CFIndex nonbmp_len;
   UniChar *unichars;
@@ -2838,10 +2799,6 @@ macfont_shape (Lisp_Object lgstring)
   CFIndex used = 0;
   struct mac_glyph_layout *glyph_layouts;
 
-  CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring), font);
-  macfont_info = (struct macfont_info *) font;
-  macfont = macfont_info->macfont;
-
   glyph_len = LGSTRING_GLYPH_LEN (lgstring);
   nonbmp_len = 0;
   for (i = 0; i < glyph_len; i++)
@@ -3165,11 +3122,9 @@ mac_font_get_glyphs_for_variants (CFDataRef uvs_table, UTF32Char c,
   struct variation_selector_record *records = uvs->variation_selector_records;
   CFIndex i;
   UInt32 ir, nrecords;
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
   dispatch_queue_t queue =
     dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
   dispatch_group_t group = dispatch_group_create ();
-#endif
 
   nrecords = BUINT32_VALUE (uvs->num_var_selector_records);
   i = 0;
@@ -3193,9 +3148,7 @@ mac_font_get_glyphs_for_variants (CFDataRef uvs_table, UTF32Char c,
       default_uvs_offset = BUINT32_VALUE (records[ir].default_uvs_offset);
       non_default_uvs_offset =
         BUINT32_VALUE (records[ir].non_default_uvs_offset);
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
       dispatch_group_async (group, queue, ^{
-#endif
           glyphs[i] = kCGFontIndexInvalid;
 
           if (default_uvs_offset)
@@ -3247,18 +3200,14 @@ mac_font_get_glyphs_for_variants (CFDataRef uvs_table, UTF32Char c,
                   BUINT24_VALUE (mappings[hi - 1].unicode_value) == c)
                 glyphs[i] = BUINT16_VALUE (mappings[hi - 1].glyph_id);
             }
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
         });
-#endif
       i++;
       ir++;
     }
   while (i < count)
     glyphs[i++] = kCGFontIndexInvalid;
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
   dispatch_group_wait (group, DISPATCH_TIME_FOREVER);
   dispatch_release (group);
-#endif
 }
 
 static int
@@ -3460,10 +3409,6 @@ mac_ctfont_create_available_families (void)
 {
   CFMutableArrayRef families = NULL;
 
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
-  if (CTFontManagerCopyAvailableFontFamilyNames != NULL)
-#endif
     {
       CFArrayRef orig_families = CTFontManagerCopyAvailableFontFamilyNames ();
 
@@ -3487,56 +3432,8 @@ mac_ctfont_create_available_families (void)
           CFRelease (orig_families);
         }
     }
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
-  else        /* CTFontManagerCopyAvailableFontFamilyNames == NULL */
-#endif
-#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 */
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
-    {
-      CTFontCollectionRef collection;
-      CFArrayRef descs = NULL;
 
-      collection = CTFontCollectionCreateFromAvailableFonts (NULL);
-      if (collection)
-        {
-          descs = CTFontCollectionCreateMatchingFontDescriptors (collection);
-          CFRelease (collection);
-        }
-      if (descs)
-        {
-          CFIndex i, count = CFArrayGetCount (descs);
-
-          families = CFArrayCreateMutable (NULL, count, &kCFTypeArrayCallBacks);
-          if (families)
-            for (i = 0; i < count; i++)
-              {
-                FontDescriptorRef desc = CFArrayGetValueAtIndex (descs, i);
-                CFStringRef name =
-                  mac_font_descriptor_copy_attribute (desc,
-                                                      MAC_FONT_FAMILY_NAME_ATTRIBUTE);
-
-                if (name)
-                  {
-                    CFIndex p, limit = CFArrayGetCount (families);
-
-                    p = CFArrayBSearchValues (families, CFRangeMake (0, limit),
-                                              (const void *) name,
-                                              mac_font_family_compare, NULL);
-                    if (p >= limit)
-                      CFArrayAppendValue (families, name);
-                    else if (mac_font_family_compare
-                             (CFArrayGetValueAtIndex (families, p),
-                              name, NULL) != kCFCompareEqualTo)
-                      CFArrayInsertValueAtIndex (families, p, name);
-                    CFRelease (name);
-                  }
-              }
-          CFRelease (descs);
-        }
-    }
-#endif
-
-  return families;
+    return families;
 }
 
 static Boolean
@@ -3855,41 +3752,6 @@ mac_ctfont_get_glyph_for_cid (CTFontRef font, CTCharacterCollection collection,
 }
 #endif
 
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
-static inline int
-mac_font_family_group (CFStringRef family)
-{
-  if (CFStringHasPrefix (family, CFSTR ("#")))
-    return 2;
-  else
-    {
-      CFRange range;
-
-      range = CFStringFind (family, CFSTR ("Apple"),
-                            kCFCompareCaseInsensitive | kCFCompareAnchored);
-      if (range.location != kCFNotFound)
-        return 1;
-
-      return 0;
-    }
-}
-
-static CFComparisonResult
-mac_font_family_compare (const void *val1, const void *val2, void *context)
-{
-  CFStringRef family1 = (CFStringRef) val1, family2 = (CFStringRef) val2;
-  int group1, group2;
-
-  group1 = mac_font_family_group (family1);
-  group2 = mac_font_family_group (family2);
-  if (group1 < group2)
-    return kCFCompareLessThan;
-  if (group1 > group2)
-    return kCFCompareGreaterThan;
-  return CFStringCompare (family1, family2, kCFCompareCaseInsensitive);
-}
-#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1060 */
-
 static CFArrayRef
 mac_font_copy_default_descriptors_for_language (CFStringRef language)
 {
@@ -4040,20 +3902,25 @@ mac_register_font_driver (struct frame *f)
   register_font_driver (&macfont_driver, f);
 }
 
-#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
-
 \f
 void
 syms_of_macfont (void)
 {
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
   static struct font_driver mac_font_driver;
 
+  /* Core Text, for Mac OS X.  */
   DEFSYM (Qmac_ct, "mac-ct");
   macfont_driver.type = Qmac_ct;
   register_font_driver (&macfont_driver, NULL);
 
+  /* The font property key specifying the font design destination.  The
+     value is an unsigned integer code: 0 for WYSIWYG, and 1 for Video
+     text.  (See the documentation of X Logical Font Description
+     Conventions.)  In the Mac font driver, 1 means the screen font is
+     used for calculating some glyph metrics.  You can see the
+     difference with Monaco 8pt or 9pt, for example.  */
   DEFSYM (QCdestination, ":destination");
+
+  /* The boolean-valued font property key specifying the use of leading.  */
   DEFSYM (QCminspace, ":minspace");
-#endif
 }