emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r117734: One more minor cleanup of font subsystem.


From: Dmitry Antipov
Subject: [Emacs-diffs] trunk r117734: One more minor cleanup of font subsystem.
Date: Mon, 25 Aug 2014 07:02:08 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117734
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Mon 2014-08-25 11:00:42 +0400
message:
  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.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/font.h                     font.h-20091113204419-o5vbwnq5f7feedwu-8541
  src/ftfont.c                   ftfont.c-20091113204419-o5vbwnq5f7feedwu-8542
  src/macfont.m                  macfont.m-20130915173740-04lgloz0557bz98l-2
  src/nsfont.m                   nsfont.m-20091113204419-o5vbwnq5f7feedwu-8748
  src/w32font.c                  w32font.c-20091113204419-o5vbwnq5f7feedwu-8545
  src/w32font.h                  w32font.h-20091113204419-o5vbwnq5f7feedwu-8546
  src/w32uniscribe.c             
w32uniscribe.c-20091113204419-o5vbwnq5f7feedwu-8619
  src/xfont.c                    xfont.c-20091113204419-o5vbwnq5f7feedwu-8547
  src/xftfont.c                  xftfont.c-20091113204419-o5vbwnq5f7feedwu-8548
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-08-25 05:44:57 +0000
+++ b/src/ChangeLog     2014-08-25 07:00:42 +0000
@@ -1,3 +1,15 @@
+2014-08-25  Dmitry Antipov  <address@hidden>
+
+       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  <address@hidden>
 
        Minor cleanups of str_collate fix (Bug#18051).

=== modified file 'src/font.h'
--- a/src/font.h        2014-07-09 23:35:31 +0000
+++ b/src/font.h        2014-08-25 07:00:42 +0000
@@ -570,9 +570,9 @@
   /* 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
 

=== modified file 'src/ftfont.c'
--- a/src/ftfont.c      2014-07-09 06:25:35 +0000
+++ b/src/ftfont.c      2014-08-25 07:00:42 +0000
@@ -499,8 +499,8 @@
 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 @@
   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 @@
 
          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

=== modified file 'src/macfont.m'
--- a/src/macfont.m     2014-07-21 06:03:08 +0000
+++ b/src/macfont.m     2014-08-25 07:00:42 +0000
@@ -1553,8 +1553,8 @@
 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 @@
   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 @@
   for (i = 1; i < nglyphs; i++)
     {
       struct font_metrics m;
-      int w = macfont_glyph_extents (font, code[i], metrics ? &m : NULL,
-                                    NULL, 0);
+      int w = macfont_glyph_extents (font, code[i], &m, 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;
-       }
+      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

=== modified file 'src/nsfont.m'
--- a/src/nsfont.m      2014-07-09 06:25:35 +0000
+++ b/src/nsfont.m      2014-08-25 07:00:42 +0000
@@ -627,8 +627,8 @@
 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 @@
 /* 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 @@
 
   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 @@
     }
 
   metrics->width = totalWidth;
-
-  return totalWidth; /* not specified in doc, but xfont.c does it */
 }
 
 

=== modified file 'src/w32font.c'
--- a/src/w32font.c     2014-07-09 06:25:35 +0000
+++ b/src/w32font.c     2014-08-25 07:00:42 +0000
@@ -473,7 +473,7 @@
    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 @@
 
   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++)
     {
-      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;
-
-         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;
-           }
-
-         if (!w32_font->cached_metrics[block])
-           {
-             w32_font->cached_metrics[block]
-               = xzalloc (CACHE_BLOCKSIZE * sizeof (struct w32_metric_cache));
-           }
-
-         char_metric = w32_font->cached_metrics[block] + pos_in_block;
-
-         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);
-           }
-
-         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;
-           }
+      struct w32_metric_cache *char_metric;
+      int block = *(code + i) / CACHE_BLOCKSIZE;
+      int pos_in_block = *(code + i) % CACHE_BLOCKSIZE;
+
+      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
-           /* 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 metrics->width;
-        }
+           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;
+       }
+
+      if (!w32_font->cached_metrics[block])
+       {
+         w32_font->cached_metrics[block]
+           = xzalloc (CACHE_BLOCKSIZE * sizeof (struct w32_metric_cache));
+       }
+
+      char_metric = w32_font->cached_metrics[block] + pos_in_block;
+
+      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);
+       }
+
+      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 @@
     }
 
   /* 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.

=== modified file 'src/w32font.h'
--- a/src/w32font.h     2014-01-01 07:43:34 +0000
+++ b/src/w32font.h     2014-08-25 07:00:42 +0000
@@ -74,8 +74,8 @@
                            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);
 

=== modified file 'src/w32uniscribe.c'
--- a/src/w32uniscribe.c        2014-07-09 06:25:35 +0000
+++ b/src/w32uniscribe.c        2014-08-25 07:00:42 +0000
@@ -591,8 +591,8 @@
    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);
 

=== modified file 'src/xfont.c'
--- a/src/xfont.c       2014-07-09 06:25:35 +0000
+++ b/src/xfont.c       2014-08-25 07:00:42 +0000
@@ -124,8 +124,8 @@
 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 @@
   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 @@
        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

=== modified file 'src/xftfont.c'
--- a/src/xftfont.c     2014-07-09 06:25:35 +0000
+++ b/src/xftfont.c     2014-08-25 07:00:42 +0000
@@ -557,8 +557,9 @@
   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 @@
   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 *


reply via email to

[Prev in Thread] Current Thread [Next in Thread]