]> code.delx.au - gnu-emacs/blobdiff - src/macfont.m
Fix bug #15148 with garbled display in Dired when cache-long-scans is ON.
[gnu-emacs] / src / macfont.m
index ab5029743ef42795161809a4c1ac6c361f7f03d9..c284b3086f83ddcd91947be97b476f61ebb8276c 100644 (file)
@@ -64,7 +64,7 @@ static CGGlyph mac_ctfont_get_glyph_for_cid (CTFontRef,
 #endif
 
 /* The font property key specifying the font design destination.  The
-   value is an unsigned integer code: 0 for WYSIWIG, and 1 for Video
+   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
@@ -366,7 +366,7 @@ mac_font_shape_1 (NSFont *font, NSString *string,
   if (!(textStorage && layoutManager && textContainer))
     {
       [textStorage release];
-      
+
       return 0;
     }
 
@@ -624,19 +624,26 @@ get_cgcolor(unsigned long idx, struct frame *f)
 }
 
 #define CG_SET_FILL_COLOR_WITH_GC_FOREGROUND(context, s)                \
-  CGContextSetFillColorWithColor (context,                              \
-                                  get_cgcolor (NS_FACE_FOREGROUND (s->face), \
-                                               s->f))
-
+  do {                                                                  \
+    CGColorRef refcol_ = get_cgcolor (NS_FACE_FOREGROUND (s->face),     \
+                                      s->f);                            \
+    CGContextSetFillColorWithColor (context, refcol_) ;                 \
+    CGColorRelease (refcol_);                                           \
+  } while (0)
 #define CG_SET_FILL_COLOR_WITH_GC_BACKGROUND(context, s)                \
-  CGContextSetFillColorWithColor (context,                              \
-                                  get_cgcolor (NS_FACE_BACKGROUND (s->face), \
-                                               s->f))
-
+  do {                                                                  \
+    CGColorRef refcol_ = get_cgcolor (NS_FACE_BACKGROUND (s->face),\
+                                      s->f);                            \
+    CGContextSetFillColorWithColor (context, refcol_);                  \
+    CGColorRelease (refcol_);                                           \
+  } while (0)
 #define CG_SET_STROKE_COLOR_WITH_GC_FOREGROUND(context, s)              \
-  CGContextSetStrokeColorWithColor (context,                            \
-                                    get_cgcolor (NS_FACE_FOREGROUND (s->face),\
-                                                 s->f))
+  do {                                                                  \
+    CGColorRef refcol_ = get_cgcolor (NS_FACE_FOREGROUND (s->face),\
+                                      s->f);                            \
+    CGContextSetStrokeColorWithColor (context, refcol_);                \
+    CGColorRelease (refcol_);                                           \
+  } while (0)
 
 \f
 /* Mac font driver.  */
@@ -1159,7 +1166,7 @@ struct macfont_cache
 
     /* The cached glyph for a character c is stored as the (c %
        NGLYPHS_IN_VALUE)-th CGGlyph block of a value for the key (c /
-       NGLYPHS_IN_VALUE).  However, the glyph for a BMP characrer c is
+       NGLYPHS_IN_VALUE).  However, the glyph for a BMP character c is
        not stored here if row_nkeys_or_perm[c / 256] >=
        ROW_PERM_OFFSET.  */
     CFMutableDictionaryRef dictionary;
@@ -1518,7 +1525,7 @@ static Lisp_Object macfont_match (struct frame *, Lisp_Object);
 static Lisp_Object macfont_list_family (struct frame *);
 static void macfont_free_entity (Lisp_Object);
 static Lisp_Object macfont_open (struct frame *, Lisp_Object, int);
-static void macfont_close (struct frame *, struct font *);
+static void macfont_close (struct font *);
 static int macfont_has_char (Lisp_Object, int);
 static unsigned macfont_encode_char (struct font *, int);
 static int macfont_text_extents (struct font *, unsigned int *, int,
@@ -2465,7 +2472,7 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size)
   macfont_info = (struct macfont_info *) font;
   macfont_info->macfont = macfont;
   macfont_info->cgfont = mac_font_copy_graphics_font (macfont);
-  
+
   val = assq_no_quit (QCdestination, AREF (entity, FONT_EXTRA_INDEX));
   if (CONSP (val) && EQ (XCDR (val), make_number (1)))
     macfont_info->screen_font = mac_screen_font_create_with_name (font_name,
@@ -2580,23 +2587,28 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size)
 }
 
 static void
-macfont_close (struct frame * f, struct font *font)
+macfont_close (struct font *font)
 {
   struct macfont_info *macfont_info = (struct macfont_info *) font;
-  int i;
 
-  block_input ();
-  CFRelease (macfont_info->macfont);
-  CGFontRelease (macfont_info->cgfont);
-  if (macfont_info->screen_font)
-    CFRelease (macfont_info->screen_font);
-  macfont_release_cache (macfont_info->cache);
-  for (i = 0; i < macfont_info->metrics_nrows; i++)
-    if (macfont_info->metrics[i])
-      xfree (macfont_info->metrics[i]);
-  if (macfont_info->metrics)
-    xfree (macfont_info->metrics);
-  unblock_input ();
+  if (macfont_info->cache)
+    {
+      int i;
+
+      block_input ();
+      CFRelease (macfont_info->macfont);
+      CGFontRelease (macfont_info->cgfont);
+      if (macfont_info->screen_font)
+       CFRelease (macfont_info->screen_font);
+      macfont_release_cache (macfont_info->cache);
+      macfont_info->cache = NULL;
+      for (i = 0; i < macfont_info->metrics_nrows; i++)
+       if (macfont_info->metrics[i])
+         xfree (macfont_info->metrics[i]);
+      if (macfont_info->metrics)
+       xfree (macfont_info->metrics);
+      unblock_input ();
+    }
 }
 
 static int
@@ -2667,7 +2679,7 @@ macfont_text_extents (struct font *font, unsigned int *code, int nglyphs,
     }
   unblock_input ();
 
-  if (metrics) 
+  if (metrics)
     metrics->width = width;
 
   return width;
@@ -2708,7 +2720,7 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
     {
       CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, s);
       CGContextFillRect (context,
-                        NSMakeRect (x, y,
+                        CGRectMake (x, y,
                                      s->width, FONT_HEIGHT (s->font)));
     }
 
@@ -2720,7 +2732,7 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
       CGFloat font_size = mac_font_get_size (macfont);
       CGAffineTransform atfm;
       CGFloat advance_delta = 0;
-      int y_draw = -y-FONT_BASE (s->font);
+      int y_draw = -s->ybase;
       int no_antialias_p =
        (macfont_info->antialias == MACFONT_ANTIALIAS_OFF
         || (macfont_info->antialias == MACFONT_ANTIALIAS_DEFAULT
@@ -2729,7 +2741,7 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
       for (i = 0; i < len; i++)
        {
          int width;
+
          glyphs[i] = *(s->char2b + s->cmp_from + i);
          width = (s->padding_p ? 1
                   : macfont_glyph_extents (s->font, glyphs[i],
@@ -2817,7 +2829,6 @@ macfont_shape (Lisp_Object lgstring)
     }
 
   len = i;
-  assume (len <= TYPE_MAXIMUM (EMACS_INT) - 2);
 
   if (INT_MAX / 2 < len)
     memory_full (SIZE_MAX);
@@ -2990,7 +3001,7 @@ struct non_default_uvs_table
 #define BUINT32_VALUE(lval)    OSReadBigInt32 (&(lval), 0)
 
 /* Return UVS subtable for the specified FONT.  If the subtable is not
-   found or ill-formated, then return NULL.  */
+   found or ill-formatted, then return NULL.  */
 
 static CFDataRef
 mac_font_copy_uvs_table (FontRef font)
@@ -3321,10 +3332,8 @@ mac_ctfont_create_preferred_family_for_attributes (CFDictionaryRef attributes)
   CFStringRef result = NULL;
   CFStringRef charset_string =
     CFDictionaryGetValue (attributes, MAC_FONT_CHARACTER_SET_STRING_ATTRIBUTE);
-  CFIndex length;
 
-  if (charset_string
-      && (length = CFStringGetLength (charset_string)) > 0)
+  if (charset_string && CFStringGetLength (charset_string) > 0)
     {
       CFAttributedStringRef attr_string = NULL;
       CTLineRef ctline = NULL;