]> git.eshelyaron.com Git - emacs.git/commitdiff
One more minor cleanup of font subsystem.
authorDmitry Antipov <dmantipov@yandex.ru>
Mon, 25 Aug 2014 07:00:42 +0000 (11:00 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Mon, 25 Aug 2014 07:00:42 +0000 (11:00 +0400)
* font.h (struct font_driver): Convert text_extents to
return void because returned value is never actually used.
* macfont.c (macfont_text_extents):
* w32font.c (w32font_text_extents):
* xftfont.c (xftfont_text_extents): Adjust to return void
and assume that 'metrics' argument is always non-NULL.
* ftfont.c (ftfont_text_extents):
* xfont.c (xfont_text_extents): Likewise.  Avoid redundant memset.

src/ChangeLog
src/font.h
src/ftfont.c
src/macfont.m
src/nsfont.m
src/w32font.c
src/w32font.h
src/w32uniscribe.c
src/xfont.c
src/xftfont.c

index 9b70b8f541108e569433fb69598db327c65886ca..efd469ad053d5d84a768da232849163a73356a83 100644 (file)
@@ -1,3 +1,15 @@
+2014-08-25  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       One more minor cleanup of font subsystem.
+       * font.h (struct font_driver): Convert text_extents to
+       return void because returned value is never actually used.
+       * macfont.c (macfont_text_extents):
+       * w32font.c (w32font_text_extents):
+       * xftfont.c (xftfont_text_extents): Adjust to return void
+       and assume that 'metrics' argument is always non-NULL.
+       * ftfont.c (ftfont_text_extents):
+       * xfont.c (xfont_text_extents): Likewise.  Avoid redundant memset.
+
 2014-08-25  Paul Eggert  <eggert@cs.ucla.edu>
 
        Minor cleanups of str_collate fix (Bug#18051).
index cffc035cd4915d830328e09bff57296213523fa4..52783419ebeff34abdab727b026eb31709de5ff3 100644 (file)
@@ -570,9 +570,9 @@ struct font_driver
   /* Compute the total metrics of the NGLYPHS glyphs specified by
      the font FONT and the sequence of glyph codes CODE, and store the
      result in METRICS.  */
-  int (*text_extents) (struct font *font,
-                       unsigned *code, int nglyphs,
-                       struct font_metrics *metrics);
+  void (*text_extents) (struct font *font,
+                       unsigned *code, int nglyphs,
+                       struct font_metrics *metrics);
 
 #ifdef HAVE_WINDOW_SYSTEM
 
index 419274a30aa4a5066615ab3f9284cdc200a40838..1cad158065be6712609ee7e9c9038e7157f4464f 100644 (file)
@@ -499,8 +499,8 @@ static Lisp_Object ftfont_open (struct frame *, Lisp_Object, int);
 static void ftfont_close (struct font *);
 static int ftfont_has_char (Lisp_Object, int);
 static unsigned ftfont_encode_char (struct font *, int);
-static int ftfont_text_extents (struct font *, unsigned *, int,
-                                struct font_metrics *);
+static void ftfont_text_extents (struct font *, unsigned *, int,
+                                struct font_metrics *);
 static int ftfont_get_bitmap (struct font *, unsigned,
                               struct font_bitmap *, int);
 static int ftfont_anchor_point (struct font *, unsigned, int,
@@ -1371,19 +1371,18 @@ ftfont_encode_char (struct font *font, int c)
   return (code > 0 ? code : FONT_INVALID_CODE);
 }
 
-static int
-ftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct font_metrics *metrics)
+static void
+ftfont_text_extents (struct font *font, unsigned int *code,
+                    int nglyphs, struct font_metrics *metrics)
 {
   struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
   FT_Face ft_face = ftfont_info->ft_size->face;
-  int width = 0;
-  int i;
+  int i, width = 0;
   bool first;
 
   if (ftfont_info->ft_size != ft_face->size)
     FT_Activate_Size (ftfont_info->ft_size);
-  if (metrics)
-    memset (metrics, 0, sizeof (struct font_metrics));
+
   for (i = 0, first = 1; i < nglyphs; i++)
     {
       if (FT_Load_Glyph (ft_face, code[i], FT_LOAD_DEFAULT) == 0)
@@ -1392,39 +1391,28 @@ ftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct
 
          if (first)
            {
-             if (metrics)
-               {
-                 metrics->lbearing = m->horiBearingX >> 6;
-                 metrics->rbearing = (m->horiBearingX + m->width) >> 6;
-                 metrics->ascent = m->horiBearingY >> 6;
-                 metrics->descent = (m->height - m->horiBearingY) >> 6;
-               }
+             metrics->lbearing = m->horiBearingX >> 6;
+             metrics->rbearing = (m->horiBearingX + m->width) >> 6;
+             metrics->ascent = m->horiBearingY >> 6;
+             metrics->descent = (m->height - m->horiBearingY) >> 6;
              first = 0;
            }
-         if (metrics)
-           {
-             if (metrics->lbearing > width + (m->horiBearingX >> 6))
-               metrics->lbearing = width + (m->horiBearingX >> 6);
-             if (metrics->rbearing
-                 < width + ((m->horiBearingX + m->width) >> 6))
-               metrics->rbearing
-                 = width + ((m->horiBearingX + m->width) >> 6);
-             if (metrics->ascent < (m->horiBearingY >> 6))
-               metrics->ascent = m->horiBearingY >> 6;
-             if (metrics->descent > ((m->height - m->horiBearingY) >> 6))
-               metrics->descent = (m->height - m->horiBearingY) >> 6;
-           }
+         if (metrics->lbearing > width + (m->horiBearingX >> 6))
+           metrics->lbearing = width + (m->horiBearingX >> 6);
+         if (metrics->rbearing
+             < width + ((m->horiBearingX + m->width) >> 6))
+           metrics->rbearing
+             = width + ((m->horiBearingX + m->width) >> 6);
+         if (metrics->ascent < (m->horiBearingY >> 6))
+           metrics->ascent = m->horiBearingY >> 6;
+         if (metrics->descent > ((m->height - m->horiBearingY) >> 6))
+           metrics->descent = (m->height - m->horiBearingY) >> 6;
          width += m->horiAdvance >> 6;
        }
       else
-       {
-         width += font->space_width;
-       }
+       width += font->space_width;
     }
-  if (metrics)
-    metrics->width = width;
-
-  return width;
+  metrics->width = width;
 }
 
 static int
index 0d702873220f5e9bf5806d60123b84293997ad4b..4bc58229d6e7ff94d37e02c4fcd928d63a54eb52 100644 (file)
@@ -1553,8 +1553,8 @@ static Lisp_Object macfont_open (struct frame *, Lisp_Object, int);
 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,
-                                struct font_metrics *);
+static void macfont_text_extents (struct font *, unsigned int *, int,
+                                 struct font_metrics *);
 static int macfont_draw (struct glyph_string *, int, int, int, int, bool);
 static Lisp_Object macfont_shape (Lisp_Object);
 static int macfont_variation_glyphs (struct font *, int c,
@@ -2653,9 +2653,9 @@ macfont_encode_char (struct font *font, int c)
   return glyph != kCGFontIndexInvalid ? glyph : FONT_INVALID_CODE;
 }
 
-static int
-macfont_text_extents (struct font *font, unsigned int *code, int nglyphs,
-                     struct font_metrics *metrics)
+static void
+macfont_text_extents (struct font *font, unsigned int *code,
+                     int nglyphs, struct font_metrics *metrics)
 {
   int width, i;
 
@@ -2664,28 +2664,21 @@ macfont_text_extents (struct font *font, unsigned int *code, int nglyphs,
   for (i = 1; i < nglyphs; i++)
     {
       struct font_metrics m;
-      int w = macfont_glyph_extents (font, code[i], metrics ? &m : NULL,
-                                    NULL, 0);
-
-      if (metrics)
-       {
-         if (width + m.lbearing < metrics->lbearing)
-           metrics->lbearing = width + m.lbearing;
-         if (width + m.rbearing > metrics->rbearing)
-           metrics->rbearing = width + m.rbearing;
-         if (m.ascent > metrics->ascent)
-           metrics->ascent = m.ascent;
-         if (m.descent > metrics->descent)
-           metrics->descent = m.descent;
-       }
+      int w = macfont_glyph_extents (font, code[i], &m, NULL, 0);
+
+      if (width + m.lbearing < metrics->lbearing)
+       metrics->lbearing = width + m.lbearing;
+      if (width + m.rbearing > metrics->rbearing)
+       metrics->rbearing = width + m.rbearing;
+      if (m.ascent > metrics->ascent)
+       metrics->ascent = m.ascent;
+      if (m.descent > metrics->descent)
+       metrics->descent = m.descent;
       width += w;
     }
   unblock_input ();
 
-  if (metrics)
-    metrics->width = width;
-
-  return width;
+  metrics->width = width;
 }
 
 static int
index 98c25fcdedd07191457778a05f357db3df1f04ce..202ebe10c9702ee650bf13f76244f81c2a54596c 100644 (file)
@@ -627,8 +627,8 @@ static Lisp_Object nsfont_open (struct frame *f, Lisp_Object font_entity,
 static void nsfont_close (struct font *font);
 static int nsfont_has_char (Lisp_Object entity, int c);
 static unsigned int nsfont_encode_char (struct font *font, int c);
-static int nsfont_text_extents (struct font *font, unsigned int *code,
-                                int nglyphs, struct font_metrics *metrics);
+static void nsfont_text_extents (struct font *font, unsigned int *code,
+                                int nglyphs, struct font_metrics *metrics);
 static int nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
                         bool with_background);
 
@@ -988,9 +988,9 @@ nsfont_encode_char (struct font *font, int c)
 /* Perform the size computation of glyphs of FONT and fill in members
    of METRICS.  The glyphs are specified by their glyph codes in
    CODE (length NGLYPHS). */
-static int
-nsfont_text_extents (struct font *font, unsigned int *code, int nglyphs,
-                     struct font_metrics *metrics)
+static void
+nsfont_text_extents (struct font *font, unsigned int *code,
+                    int nglyphs, struct font_metrics *metrics)
 {
   struct nsfont_info *font_info = (struct nsfont_info *)font;
   struct font_metrics *pcm;
@@ -1000,7 +1000,7 @@ nsfont_text_extents (struct font *font, unsigned int *code, int nglyphs,
 
   memset (metrics, 0, sizeof (struct font_metrics));
 
-  for (i =0; i<nglyphs; i++)
+  for (i = 0; i < nglyphs; i++)
     {
       /* get metrics for this glyph, filling cache if need be */
       /* TODO: get metrics for whole string from an NSLayoutManager
@@ -1024,8 +1024,6 @@ nsfont_text_extents (struct font *font, unsigned int *code, int nglyphs,
     }
 
   metrics->width = totalWidth;
-
-  return totalWidth; /* not specified in doc, but xfont.c does it */
 }
 
 
index 81e25eb0856ae24accb7f2b1009438d7cf731159..de0732dd4da39c9708d865c11d5a63b4482d900a 100644 (file)
@@ -473,7 +473,7 @@ w32font_encode_char (struct font *font, int c)
    of METRICS.  The glyphs are specified by their glyph codes in
    CODE (length NGLYPHS).  Apparently metrics can be NULL, in this
    case just return the overall width.  */
-int
+void
 w32font_text_extents (struct font *font, unsigned *code,
                      int nglyphs, struct font_metrics *metrics)
 {
@@ -487,84 +487,80 @@ w32font_text_extents (struct font *font, unsigned *code,
 
   struct w32font_info *w32_font = (struct w32font_info *) font;
 
-  if (metrics)
-    {
-      memset (metrics, 0, sizeof (struct font_metrics));
-      metrics->ascent = font->ascent;
-      metrics->descent = font->descent;
-
-      for (i = 0; i < nglyphs; i++)
-        {
-         struct w32_metric_cache *char_metric;
-         int block = *(code + i) / CACHE_BLOCKSIZE;
-         int pos_in_block = *(code + i) % CACHE_BLOCKSIZE;
+  memset (metrics, 0, sizeof (struct font_metrics));
+  metrics->ascent = font->ascent;
+  metrics->descent = font->descent;
 
-         if (block >= w32_font->n_cache_blocks)
-           {
-             if (!w32_font->cached_metrics)
-               w32_font->cached_metrics
-                 = xmalloc ((block + 1)
-                            * sizeof (struct w32_metric_cache *));
-             else
-               w32_font->cached_metrics
-                 = xrealloc (w32_font->cached_metrics,
-                             (block + 1)
-                             * sizeof (struct w32_metric_cache *));
-             memset (w32_font->cached_metrics + w32_font->n_cache_blocks, 0,
-                     ((block + 1 - w32_font->n_cache_blocks)
-                      * sizeof (struct w32_metric_cache *)));
-             w32_font->n_cache_blocks = block + 1;
-           }
+  for (i = 0; i < nglyphs; i++)
+    {
+      struct w32_metric_cache *char_metric;
+      int block = *(code + i) / CACHE_BLOCKSIZE;
+      int pos_in_block = *(code + i) % CACHE_BLOCKSIZE;
 
-         if (!w32_font->cached_metrics[block])
-           {
-             w32_font->cached_metrics[block]
-               = xzalloc (CACHE_BLOCKSIZE * sizeof (struct w32_metric_cache));
-           }
+      if (block >= w32_font->n_cache_blocks)
+       {
+         if (!w32_font->cached_metrics)
+           w32_font->cached_metrics
+             = xmalloc ((block + 1)
+                        * sizeof (struct w32_metric_cache *));
+         else
+           w32_font->cached_metrics
+             = xrealloc (w32_font->cached_metrics,
+                         (block + 1)
+                         * sizeof (struct w32_metric_cache *));
+         memset (w32_font->cached_metrics + w32_font->n_cache_blocks, 0,
+                 ((block + 1 - w32_font->n_cache_blocks)
+                  * sizeof (struct w32_metric_cache *)));
+         w32_font->n_cache_blocks = block + 1;
+       }
 
-         char_metric = w32_font->cached_metrics[block] + pos_in_block;
+      if (!w32_font->cached_metrics[block])
+       {
+         w32_font->cached_metrics[block]
+           = xzalloc (CACHE_BLOCKSIZE * sizeof (struct w32_metric_cache));
+       }
 
-         if (char_metric->status == W32METRIC_NO_ATTEMPT)
-           {
-             if (dc == NULL)
-               {
-                 /* TODO: Frames can come and go, and their fonts
-                    outlive them. So we can't cache the frame in the
-                    font structure.  Use selected_frame until the API
-                    is updated to pass in a frame.  */
-                 f = XFRAME (selected_frame);
-
-                  dc = get_frame_dc (f);
-                  old_font = SelectObject (dc, w32_font->hfont);
-               }
-             compute_metrics (dc, w32_font, *(code + i), char_metric);
-           }
+      char_metric = w32_font->cached_metrics[block] + pos_in_block;
 
-         if (char_metric->status == W32METRIC_SUCCESS)
+      if (char_metric->status == W32METRIC_NO_ATTEMPT)
+       {
+         if (dc == NULL)
            {
-             metrics->lbearing = min (metrics->lbearing,
-                                      metrics->width + char_metric->lbearing);
-             metrics->rbearing = max (metrics->rbearing,
-                                      metrics->width + char_metric->rbearing);
-             metrics->width += char_metric->width;
+             /* TODO: Frames can come and go, and their fonts
+                outlive them. So we can't cache the frame in the
+                font structure.  Use selected_frame until the API
+                is updated to pass in a frame.  */
+             f = XFRAME (selected_frame);
+
+             dc = get_frame_dc (f);
+             old_font = SelectObject (dc, w32_font->hfont);
            }
-         else
-           /* If we couldn't get metrics for a char,
-              use alternative method.  */
-           break;
+         compute_metrics (dc, w32_font, *(code + i), char_metric);
        }
-      /* If we got through everything, return.  */
-      if (i == nglyphs)
-        {
-          if (dc != NULL)
-            {
-              /* Restore state and release DC.  */
-              SelectObject (dc, old_font);
-              release_frame_dc (f, dc);
-            }
 
-          return metrics->width;
-        }
+      if (char_metric->status == W32METRIC_SUCCESS)
+       {
+         metrics->lbearing = min (metrics->lbearing,
+                                  metrics->width + char_metric->lbearing);
+         metrics->rbearing = max (metrics->rbearing,
+                                  metrics->width + char_metric->rbearing);
+         metrics->width += char_metric->width;
+       }
+      else
+       /* If we couldn't get metrics for a char,
+          use alternative method.  */
+       break;
+    }
+  /* If we got through everything, return.  */
+  if (i == nglyphs)
+    {
+      if (dc != NULL)
+       {
+         /* Restore state and release DC.  */
+         SelectObject (dc, old_font);
+         release_frame_dc (f, dc);
+       }
+      return;
     }
 
   /* For non-truetype fonts, GetGlyphOutlineW is not supported, so
@@ -620,18 +616,13 @@ w32font_text_extents (struct font *font, unsigned *code,
     }
 
   /* Give our best estimate of the metrics, based on what we know.  */
-  if (metrics)
-    {
-      metrics->width = total_width - w32_font->metrics.tmOverhang;
-      metrics->lbearing = 0;
-      metrics->rbearing = total_width;
-    }
+  metrics->width = total_width - w32_font->metrics.tmOverhang;
+  metrics->lbearing = 0;
+  metrics->rbearing = total_width;
 
   /* Restore state and release DC.  */
   SelectObject (dc, old_font);
   release_frame_dc (f, dc);
-
-  return total_width;
 }
 
 /* w32 implementation of draw for font backend.
index 1be49bb91c276540f0cb66263895ea520ad87d33..5ce3ac7a5f93b59400d69ff22b017763c6bec1ac 100644 (file)
@@ -74,8 +74,8 @@ int w32font_open_internal (struct frame *f, Lisp_Object font_entity,
                            int pixel_size, Lisp_Object font_object);
 void w32font_close (struct font *font);
 int w32font_has_char (Lisp_Object entity, int c);
-int w32font_text_extents (struct font *font, unsigned *code, int nglyphs,
-                          struct font_metrics *metrics);
+void w32font_text_extents (struct font *font, unsigned *code, int nglyphs,
+                          struct font_metrics *metrics);
 int w32font_draw (struct glyph_string *s, int from, int to,
                   int x, int y, bool with_background);
 
index d06586f973ab5a9b653fa7a3b0b3c4804b5cf86b..7e6419c4d2832e9a6e8b380d787e5a2b32cb84a2 100644 (file)
@@ -591,8 +591,8 @@ uniscribe_encode_char (struct font *font, int c)
    Lisp_Object uniscribe_get_cache (Lisp_Object frame);
    void uniscribe_free_entity (Lisp_Object font_entity);
    int uniscribe_has_char (Lisp_Object entity, int c);
-   int uniscribe_text_extents (struct font *font, unsigned *code,
-                               int nglyphs, struct font_metrics *metrics);
+   void uniscribe_text_extents (struct font *font, unsigned *code,
+                                int nglyphs, struct font_metrics *metrics);
    int uniscribe_draw (struct glyph_string *s, int from, int to,
                        int x, int y, int with_background);
 
index 8996783541b9e3353cdfedeac771dd52123aba94..c39c8455aa506116dca1a6b520aa5b98bad34a4d 100644 (file)
@@ -124,8 +124,8 @@ static void xfont_close (struct font *);
 static void xfont_prepare_face (struct frame *, struct face *);
 static int xfont_has_char (Lisp_Object, int);
 static unsigned xfont_encode_char (struct font *, int);
-static int xfont_text_extents (struct font *, unsigned *, int,
-                               struct font_metrics *);
+static void xfont_text_extents (struct font *, unsigned *, int,
+                               struct font_metrics *);
 static int xfont_draw (struct glyph_string *, int, int, int, int, bool);
 static int xfont_check (struct frame *, struct font *);
 
@@ -975,15 +975,14 @@ xfont_encode_char (struct font *font, int c)
   return (xfont_get_pcm (xfont, &char2b) ? code : FONT_INVALID_CODE);
 }
 
-static int
-xfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct font_metrics *metrics)
+static void
+xfont_text_extents (struct font *font, unsigned int *code,
+                   int nglyphs, struct font_metrics *metrics)
 {
   XFontStruct *xfont = ((struct xfont_info *) font)->xfont;
-  int width = 0;
-  int i, first;
+  int i, width = 0;
+  bool first;
 
-  if (metrics)
-    memset (metrics, 0, sizeof (struct font_metrics));
   for (i = 0, first = 1; i < nglyphs; i++)
     {
       XChar2b char2b;
@@ -997,34 +996,27 @@ xfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct f
        continue;
       if (first)
        {
-         if (metrics)
-           {
-             metrics->lbearing = pcm->lbearing;
-             metrics->rbearing = pcm->rbearing;
-             metrics->ascent = pcm->ascent;
-             metrics->descent = pcm->descent;
-           }
+         metrics->lbearing = pcm->lbearing;
+         metrics->rbearing = pcm->rbearing;
+         metrics->ascent = pcm->ascent;
+         metrics->descent = pcm->descent;
          first = 0;
        }
       else
        {
-         if (metrics)
-           {
-             if (metrics->lbearing > width + pcm->lbearing)
-               metrics->lbearing = width + pcm->lbearing;
-             if (metrics->rbearing < width + pcm->rbearing)
-               metrics->rbearing = width + pcm->rbearing;
-             if (metrics->ascent < pcm->ascent)
-               metrics->ascent = pcm->ascent;
-             if (metrics->descent < pcm->descent)
-               metrics->descent = pcm->descent;
-           }
+         if (metrics->lbearing > width + pcm->lbearing)
+           metrics->lbearing = width + pcm->lbearing;
+         if (metrics->rbearing < width + pcm->rbearing)
+           metrics->rbearing = width + pcm->rbearing;
+         if (metrics->ascent < pcm->ascent)
+           metrics->ascent = pcm->ascent;
+         if (metrics->descent < pcm->descent)
+           metrics->descent = pcm->descent;
        }
       width += pcm->width;
     }
-  if (metrics)
-    metrics->width = width;
-  return width;
+
+  metrics->width = width;
 }
 
 static int
index 9726a3b991199317bfba7c148756ecfb4b3471ea..0a883a7b87b4386acb7d5439b457c8b3c9d3ca14 100644 (file)
@@ -557,8 +557,9 @@ xftfont_encode_char (struct font *font, int c)
   return (code ? code : FONT_INVALID_CODE);
 }
 
-static int
-xftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct font_metrics *metrics)
+static void
+xftfont_text_extents (struct font *font, unsigned int *code,
+                     int nglyphs, struct font_metrics *metrics)
 {
   struct xftfont_info *xftfont_info = (struct xftfont_info *) font;
   XGlyphInfo extents;
@@ -567,15 +568,12 @@ xftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct
   XftGlyphExtents (xftfont_info->display, xftfont_info->xftfont, code, nglyphs,
                   &extents);
   unblock_input ();
-  if (metrics)
-    {
-      metrics->lbearing = - extents.x;
-      metrics->rbearing = - extents.x + extents.width;
-      metrics->width = extents.xOff;
-      metrics->ascent = extents.y;
-      metrics->descent = extents.height - extents.y;
-    }
-  return extents.xOff;
+
+  metrics->lbearing = - extents.x;
+  metrics->rbearing = - extents.x + extents.width;
+  metrics->width = extents.xOff;
+  metrics->ascent = extents.y;
+  metrics->descent = extents.height - extents.y;
 }
 
 static XftDraw *