]> code.delx.au - gnu-emacs/commitdiff
Simplify NS font driver draw, merge from Macport.
authorJan Djärv <jan.h.d@swipnet.se>
Sun, 25 May 2014 10:28:52 +0000 (12:28 +0200)
committerJan Djärv <jan.h.d@swipnet.se>
Sun, 25 May 2014 10:28:52 +0000 (12:28 +0200)
* macfont.m (macfont_draw): Merge changes from Macport.

* nsterm.m (ns_draw_glyph_string): Move isComposite and end from
macfont.m, call draw with adjusted arguments so font drivers
don't need to do that.

* nsfont.m (nsfont_draw): Simplify as arguments are adjusted in
nsterm.m now.

src/ChangeLog
src/macfont.m
src/nsfont.m
src/nsterm.m

index 19da2bf89f3eb2a1509f05e4b10ad3447f7406a8..f40931cbabcabb653cd05a5e007504ec5c19d708 100644 (file)
@@ -1,3 +1,14 @@
+2014-05-25  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * nsfont.m (nsfont_draw): Simplify as arguments are adjusted in
+       nsterm.m now.
+
+       * nsterm.m (ns_draw_glyph_string): Move isComposite and end from
+       macfont.m, call draw with adjusted arguments so font drivers
+       don't need to do that.
+
+       * macfont.m (macfont_draw): Merge changes from Macport.
+
 2014-05-24  Eli Zaretskii  <eliz@gnu.org>
 
        * alloc.c (garbage_collect_1): New function, with all of the guts
index 7aa1d40b332a7e48af640eec4174b7e7ae8cc341..d34e03322367aafeec4acb4fb017e1629431c676 100644 (file)
@@ -776,7 +776,7 @@ cfnumber_get_font_symbolic_traits_value (CFNumberRef number,
   SInt64 sint64_value;
 
   /* Getting symbolic traits with kCFNumberSInt32Type is lossy on Mac
-     OS 10.6 when the value is greater than or equal to 1 << 31.  */
+     OS 10.6 when the value is greater than or equal to 1 << 31.  */
   if (CFNumberGetValue (number, kCFNumberSInt64Type, &sint64_value))
     {
       *sym_traits = (FontSymbolicTraits) sint64_value;
@@ -1251,8 +1251,7 @@ macfont_lookup_cache (CFStringRef key)
             CTFontCopyCharacterSet nor -[NSFont coveredCharacterSet]
             for this font is correct for non-BMP characters on Mac OS
             X 10.5, anyway.  */
-         if (CFStringCompare (key, CFSTR ("LastResort"), 0)
-             == kCFCompareEqualTo)
+         if (CFEqual (key, CFSTR ("LastResort")))
            {
              CFRange range = CFRangeMake (0, MAX_UNICODE_CHAR + 1);
 
@@ -2210,27 +2209,26 @@ macfont_list (struct frame *f, Lisp_Object spec)
         10.7 returns NULL if pat_desc represents the LastResort font.
         So we use CTFontDescriptorCreateMatchingFontDescriptor (no
         trailing "s") for such a font.  */
-      if (CFStringCompare (family_name, CFSTR ("LastResort"), 0)
-         != kCFCompareEqualTo)
-       descs = mac_font_descriptor_create_matching_font_descriptors (pat_desc,
-                                                                     NULL);
+      if (!CFEqual (family_name, CFSTR ("LastResort")))
+       descs = mac_font_descriptor_create_matching_font_descriptors (pat_desc,
+                                                                     NULL);
       else
-       {
-         FontDescriptorRef lr_desc =
-           mac_font_descriptor_create_matching_font_descriptor (pat_desc,
-                                                                NULL);
-         if (lr_desc)
-           {
-             descs = CFArrayCreate (NULL, (const void **) &lr_desc, 1,
-                                    &kCFTypeArrayCallBacks);
-             CFRelease (lr_desc);
-           }
-         else
-           descs = NULL;
-       }
+       {
+         FontDescriptorRef lr_desc =
+           mac_font_descriptor_create_matching_font_descriptor (pat_desc,
+                                                                NULL);
+         if (lr_desc)
+           {
+             descs = CFArrayCreate (NULL, (const void **) &lr_desc, 1,
+                                    &kCFTypeArrayCallBacks);
+             CFRelease (lr_desc);
+           }
+         else
+           descs = NULL;
+       }
       CFRelease (pat_desc);
       if (! descs)
-       goto err;
+       goto err;
 
       descs_count = CFArrayGetCount (descs);
       if (descs_count == 0
@@ -2571,12 +2569,9 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size)
       family_name = mac_font_copy_family_name (macfont);
       if (family_name)
        {
-         if ((CFStringCompare (family_name, CFSTR ("Courier"), 0)
-              == kCFCompareEqualTo)
-             || (CFStringCompare (family_name, CFSTR ("Helvetica"), 0)
-                 == kCFCompareEqualTo)
-             || (CFStringCompare (family_name, CFSTR ("Times"), 0)
-                 == kCFCompareEqualTo))
+         if (CFEqual (family_name, CFSTR ("Courier"))
+             || CFEqual (family_name, CFSTR ("Helvetica"))
+             || CFEqual (family_name, CFSTR ("Times")))
            ascent += (ascent + descent) * .15f;
          else if (CFStringHasPrefix (family_name, CFSTR ("Hiragino")))
            {
@@ -2711,33 +2706,54 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
 {
   struct frame * f = s->f;
   struct macfont_info *macfont_info = (struct macfont_info *) s->font;
-  FontRef macfont = macfont_info->macfont;
-  CGContextRef context;
-  BOOL isComposite = s->first_glyph->type == COMPOSITE_GLYPH;
-  int end = isComposite ? s->cmp_to : s->nchars;
-  int len = end - s->cmp_from;
+  CGRect background_rect;
+  CGPoint text_position;
+  CGGlyph *glyphs;
+  CGPoint *positions;
+  CGFloat font_size = mac_font_get_size (macfont_info->macfont);
+  bool no_antialias_p =
+    (macfont_info->antialias == MACFONT_ANTIALIAS_OFF
+     || (macfont_info->antialias == MACFONT_ANTIALIAS_DEFAULT
+        && font_size <= macfont_antialias_threshold));
+  int len = to - from;
   struct face *face = s->face;
-  int i;
+  CGContextRef context;
 
   block_input ();
 
-  context = [[NSGraphicsContext currentContext] graphicsPort];
-  CGContextSaveGState (context);
+  if (with_background)
+    background_rect = CGRectMake (x, y - FONT_BASE (s->font),
+                                  s->width, FONT_HEIGHT (s->font));
+ else
+    background_rect = CGRectNull;
+  
+  text_position = CGPointMake (x, -y);
+  glyphs = xmalloc (sizeof (CGGlyph) * len);
+  {
+    CGFloat advance_delta;
+    int i;
+    CGFloat total_width = 0;
 
-#if 0
-  if (s->num_clips > 0)
-    {
-      CGRect clips[2];
+    positions = xmalloc (sizeof (CGPoint) * len);
+    for (i = 0; i < len; i++)
+      {
+       int width;
+
+       glyphs[i] = s->char2b[from + i];
+       width = (s->padding_p ? 1
+                : macfont_glyph_extents (s->font, glyphs[i],
+                                         NULL, &advance_delta,
+                                         no_antialias_p));
+       positions[i].x = total_width + advance_delta;
+       positions[i].y = 0;
+       total_width += width;
+      }
+  }
 
-      for (i = 0; i < s->num_clips; i++)
-       clips[i] = mac_rect_make (f, s->clip[i].left, s->clip[i].top,
-                                 s->clip[i].right - s->clip[i].left,
-                                 s->clip[i].bottom - s->clip[i].top);
-      CGContextClipToRects (context, clips, s->num_clips);
-    }
-#endif
+  context = [[NSGraphicsContext currentContext] graphicsPort];
+  CGContextSaveGState (context);
 
-  if (with_background)
+  if (!CGRectIsNull (background_rect))
     {
       if (s->hl == DRAW_MOUSE_FACE) 
         {
@@ -2745,41 +2761,13 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
           if (!face)
             face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
         }
-
       CG_SET_FILL_COLOR_WITH_FACE_BACKGROUND (context, face, f);
-      CGContextFillRect (context,
-                        CGRectMake (x, y,
-                                     s->width, FONT_HEIGHT (s->font)));
+      CGContextFillRects (context, &background_rect, 1);
     }
 
   if (macfont_info->cgfont)
     {
-      CGGlyph *glyphs = alloca (sizeof (CGGlyph) * len);
-      CGPoint *positions = alloca (sizeof (CGPoint) * len);
-      CGFloat total_width = 0;
-      CGFloat font_size = mac_font_get_size (macfont);
       CGAffineTransform atfm;
-      CGFloat advance_delta = 0;
-      int y_draw = -s->ybase;
-      int no_antialias_p =
-       (macfont_info->antialias == MACFONT_ANTIALIAS_OFF
-        || (macfont_info->antialias == MACFONT_ANTIALIAS_DEFAULT
-            && font_size <= macfont_antialias_threshold));
-
-      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],
-                                           NULL, &advance_delta,
-                                           no_antialias_p));
-         positions[i].x = total_width + advance_delta;
-         positions[i].y = 0;
-         total_width += width;
-       }
-
       CGContextScaleCTM (context, 1, -1);
       CG_SET_FILL_COLOR_WITH_FACE_FOREGROUND (context, face, s->f);
       if (macfont_info->synthetic_italic_p)
@@ -2796,7 +2784,7 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
        CGContextSetShouldAntialias (context, false);
 
       CGContextSetTextMatrix (context, atfm);
-      CGContextSetTextPosition (context, x, y_draw);
+      CGContextSetTextPosition (context, text_position.x, text_position.y);
 
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
       if (macfont_info->color_bitmap_p
@@ -2807,7 +2795,8 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
        {
          if (len > 0)
            {
-             CTFontDrawGlyphs (macfont, glyphs, positions, len, context);
+             CTFontDrawGlyphs (macfont_info->macfont, glyphs, positions, len,
+                                context);
            }
        }
       else
@@ -2819,6 +2808,8 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
        }
     }
 
+
+  xfree (glyphs);
   CGContextRestoreGState (context);
 
   unblock_input ();
@@ -3557,7 +3548,7 @@ mac_ctfont_equal_in_postscript_name (CTFontRef font1, CTFontRef font2)
       name2 = CTFontCopyPostScriptName (font2);
       if (name2)
        {
-         result = (CFStringCompare (name1, name2, 0) == kCFCompareEqualTo);
+         result = CFEqual (name1, name2);
          CFRelease (name2);
        }
       CFRelease (name1);
@@ -3930,8 +3921,8 @@ mac_font_copy_default_descriptors_for_language (CFStringRef language)
 
       for (i = 0; macfont_language_default_font_names[i].language; i++)
        {
-         if (CFStringCompare (macfont_language_default_font_names[i].language,
-                              language, 0) == kCFCompareEqualTo)
+         if (CFEqual (macfont_language_default_font_names[i].language,
+                       language))
            {
              CFMutableArrayRef descriptors =
                CFArrayCreateMutable (NULL, 0, &kCFTypeArrayCallBacks);
@@ -4011,9 +4002,8 @@ mac_font_copy_default_name_for_charset_and_languages (CFCharacterSetRef charset,
              if (family)
                {
                  if (!CFStringHasPrefix (family, CFSTR ("."))
-                     && (CFStringCompare (family, CFSTR ("LastResort"), 0)
-                         != kCFCompareEqualTo))
-                   {
+                     && !CFEqual (family, CFSTR ("LastResort")))
+                    {
                      result = family;
                      break;
                    }
index 14e24c270e8507cc52f236b1fa4b6a45b2e1b34a..2c5e25b993c2ac4c4998709dd8f3d8f7feabe4b9 100644 (file)
@@ -1037,8 +1037,7 @@ nsfont_text_extents (struct font *font, unsigned int *code, int nglyphs,
 static int
 nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
              bool with_background)
-/* NOTE: focus and clip must be set
-     also, currently assumed (true in nsterm.m call) from ==0, to ==nchars */
+/* NOTE: focus and clip must be set */
 {
   static unsigned char cbuf[1024];
   unsigned char *c = cbuf;
@@ -1056,7 +1055,6 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
   unsigned short *t = s->char2b;
   int i, len, flags;
   char isComposite = s->first_glyph->type == COMPOSITE_GLYPH;
-  int end = isComposite ? s->cmp_to : s->nchars;
 
   block_input ();
 
@@ -1098,8 +1096,8 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
     int cwidth, twidth = 0;
     int hi, lo;
     /* FIXME: composition: no vertical displacement is considered. */
-    t += s->cmp_from; /* advance into composition */
-    for (i = s->cmp_from; i < end; i++, t++)
+    t += from; /* advance into composition */
+    for (i = from; i < to; i++, t++)
       {
         hi = (*t & 0xFF00) >> 8;
         lo = *t & 0x00FF;
@@ -1193,7 +1191,7 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
 
 
   /* set up for character rendering */
-  r.origin.y = s->ybase;
+  r.origin.y = y;
 
   col = (NS_FACE_FOREGROUND (face) != 0
          ? ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f)
@@ -1275,13 +1273,13 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
     [col set];
 
     CGContextSetTextPosition (gcontext, r.origin.x, r.origin.y);
-    CGContextShowGlyphsWithAdvances (gcontext, s->char2b + s->cmp_from,
+    CGContextShowGlyphsWithAdvances (gcontext, s->char2b + from,
                                      advances, len);
 
     if (face->overstrike)
       {
         CGContextSetTextPosition (gcontext, r.origin.x+0.5, r.origin.y);
-        CGContextShowGlyphsWithAdvances (gcontext, s->char2b + s->cmp_from,
+        CGContextShowGlyphsWithAdvances (gcontext, s->char2b + from,
                                          advances, len);
       }
 
index 17014b971210bfe8245b9d227b4bde8a5b6ec615..059ae6d0cd64e06b73d83a4dde6fffdb0a697171 100644 (file)
@@ -3355,10 +3355,16 @@ ns_draw_glyph_string (struct glyph_string *s)
           NS_FACE_FOREGROUND (s->face) = tmp;
         }
 
-      font->driver->draw
-        (s, 0, s->nchars, s->x, s->y,
-         (flags == NS_DUMPGLYPH_NORMAL && !s->background_filled_p)
-         || flags == NS_DUMPGLYPH_MOUSEFACE);
+      {
+        BOOL isComposite = s->first_glyph->type == COMPOSITE_GLYPH;
+        int end = isComposite ? s->cmp_to : s->nchars;
+
+        font->driver->draw
+          (s, s->cmp_from, end, s->x, s->ybase,
+           (flags == NS_DUMPGLYPH_NORMAL && !s->background_filled_p)
+           || flags == NS_DUMPGLYPH_MOUSEFACE);
+
+      }
 
       {
         NSColor *col = (NS_FACE_FOREGROUND (s->face) != 0