changeset 94912:5b153bea483d

: Throughout the file, delete all USE_FONT_BACKEND conditionals. Don't check enable_font_backend. Delete all codes used only when USE_FONT_BACKEND is not defined. Surround non-used code by "#ifdef OLD_FONT" and "endif".
author Kenichi Handa <handa@m17n.org>
date Wed, 14 May 2008 00:40:04 +0000
parents f29483946da4
children c83563acc3aa
files src/w32term.c
diffstat 1 files changed, 112 insertions(+), 178 deletions(-) [+]
line wrap: on
line diff
--- a/src/w32term.c	Wed May 14 00:39:27 2008 +0000
+++ b/src/w32term.c	Wed May 14 00:40:04 2008 +0000
@@ -59,10 +59,8 @@
 #include "w32bdf.h"
 #include <shellapi.h>
 
-#ifdef USE_FONT_BACKEND
 #include "font.h"
-#endif	/* USE_FONT_BACKEND */
-
+#include "w32font.h"
 
 /* Fringe bitmaps.  */
 
@@ -896,6 +894,8 @@
 
 /* Function prototypes of this page.  */
 
+#if OLD_FONT
+
 XCharStruct *w32_per_char_metric P_ ((XFontStruct *, wchar_t *, int));
 static int w32_encode_char P_ ((int, wchar_t *, struct font_info *,
 				struct charset *, int *));
@@ -1140,7 +1140,6 @@
     }
 }
 
-
 /* Determine if a font is double byte. */
 static int
 w32_font_is_double_byte (XFontStruct *font)
@@ -1483,6 +1482,7 @@
 		 nchars * charset_dim, NULL);
 }
 
+#endif	/* OLD_FONT */
 
 static void x_set_glyph_string_clipping P_ ((struct glyph_string *));
 static void x_set_glyph_string_gc P_ ((struct glyph_string *));
@@ -1594,11 +1594,6 @@
   /* If font in this face is same as S->font, use it.  */
   if (s->font == s->face->font)
     s->gc = s->face->gc;
-#ifdef USE_FONT_BACKEND
-  else if (enable_font_backend)
-    /* No need of setting a font for s->gc.  */
-    s->gc = s->face->gc;
-#endif	/* USE_FONT_BACKEND */
   else
     {
       /* Otherwise construct scratch_cursor_gc with values from FACE
@@ -1692,11 +1687,7 @@
 x_set_glyph_string_clipping (s)
      struct glyph_string *s;
 {
-#ifdef USE_FONT_BACKEND
   RECT *r = s->clip;
-#else
-  RECT r[2];
-#endif
   int n = get_glyph_string_clip_rects (s, r, 2);
 
   if (n == 1)
@@ -1714,9 +1705,7 @@
       DeleteObject (clip2);
       DeleteObject (full_clip);
     }
-#ifdef USE_FONT_BACKEND
     s->num_clips = n;
-#endif	/* USE_FONT_BACKEND */
 }
 
 /* Set SRC's clipping for output of glyph string DST.  This is called
@@ -1729,19 +1718,14 @@
 {
   RECT r;
 
-#ifdef USE_FONT_BACKEND
-  if (enable_font_backend)
+  r.left = src->x;
+  r.right = r.left + src->width;
+  r.top = src->y;
+  r.bottom = r.top + src->height;
+  dst->clip[0] = r;
+  dst->num_clips = 1;
+#if OLD_FONT
     {
-      r.left = src->x;
-      r.right = r.left + src->width;
-      r.top = src->y;
-      r.bottom = r.top + src->height;
-      dst->clip[0] = r;
-      dst->num_clips = 1;
-    }
-  else
-    {
-#endif	/* USE_FONT_BACKEND */
   struct glyph_string *clip_head = src->clip_head;
   struct glyph_string *clip_tail = src->clip_tail;
 
@@ -1749,43 +1733,33 @@
   src->clip_head = src->clip_tail = src;
   get_glyph_string_clip_rect (src, &r);
   src->clip_head = clip_head, src->clip_tail = clip_tail;
-#ifdef USE_FONT_BACKEND
     }
-#endif	/* USE_FONT_BACKEND */
+#endif	/* OLD_FONT */
   w32_set_clip_rectangle (dst->hdc, &r);
 }
 
 /* RIF:
-   Compute left and right overhang of glyph string S.  If S is a glyph
-   string for a composition, assume overhangs don't exist.  */
+   Compute left and right overhang of glyph string S.  */
 
 static void
 w32_compute_glyph_string_overhangs (s)
      struct glyph_string *s;
 {
   if (s->cmp == NULL
-      && s->first_glyph->type == CHAR_GLYPH)
+      && s->first_glyph->type == CHAR_GLYPH
+      && !s->font_not_found_p)
     {
-#ifdef USE_FONT_BACKEND
-      if (enable_font_backend)
-	{
-	  unsigned *code = alloca (sizeof (unsigned) * s->nchars);
-	  struct font *font = (struct font *) s->font_info;
-	  struct font_metrics metrics;
-	  int i;
-
-	  for (i = 0; i < s->nchars; i++)
-	    code[i] = s->char2b[i];
-	  font->driver->text_extents (font, code, s->nchars, &metrics);
-	  s->right_overhang = (metrics.rbearing > metrics.width
-			       ? metrics.rbearing - metrics.width : 0);
-	  s->left_overhang = metrics.lbearing < 0 ? -metrics.lbearing : 0;
-	}
-#else
-  /* TODO: Windows does not appear to have a method for
-     getting this info without getting the ABC widths for each
-     individual character and working it out manually. */
-#endif
+      unsigned *code = alloca (sizeof (unsigned) * s->nchars);
+      struct font *font = s->font;
+      struct font_metrics metrics;
+      int i;
+
+      for (i = 0; i < s->nchars; i++)
+	code[i] = s->char2b[i];
+      font->driver->text_extents (font, code, s->nchars, &metrics);
+      s->right_overhang = (metrics.rbearing > metrics.width
+			   ? metrics.rbearing - metrics.width : 0);
+      s->left_overhang = metrics.lbearing < 0 ? -metrics.lbearing : 0;
     }
   else if (s->cmp)
     {
@@ -1870,7 +1844,7 @@
         if (FONT_HEIGHT (s->font) < s->height - 2 * box_line_width
 	       || s->font_not_found_p
 	       || s->extends_to_end_of_line_p
-               || s->font->bdf
+	       || FONT_COMPAT (s->font)->bdf
 	       || cleartype_active
 	       || force_p)
 	{
@@ -1910,8 +1884,8 @@
   SetBkColor (s->hdc, s->gc->background);
   SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT);
 
-  if (s->font && s->font->hfont)
-    old_font = SelectObject (s->hdc, s->font->hfont);
+  if (s->font && FONT_COMPAT (s->font)->hfont)
+    old_font = SelectObject (s->hdc, FONT_COMPAT (s->font)->hfont);
 
   /* Draw characters of S as rectangles if S's font could not be
      loaded. */
@@ -1926,14 +1900,13 @@
           x += g->pixel_width;
         }
     }
-#ifdef USE_FONT_BACKEND
-  else if (enable_font_backend)
+  else
     {
-      int boff = s->font_info->baseline_offset;
-      struct font *font = (struct font *) s->font_info;
+      int boff = s->font->baseline_offset;
+      struct font *font = s->font;
       int y;
 
-      if (s->font_info->vertical_centering)
+      if (s->font->vertical_centering)
 	boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff;
 
       y = s->ybase - boff;
@@ -1945,34 +1918,8 @@
       if (s->face->overstrike)
 	font->driver->draw (s, 0, s->nchars, x + 1, y, 0);
     }
-#endif	/* USE_FONT_BACKEND */
-  else
-    {
-      char *char1b = (char *) s->char2b;
-      int boff = s->font_info->baseline_offset;
-
-      if (s->font_info->vertical_centering)
-	boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff;
-
-      /* If we can use 8-bit functions, condense S->char2b.  */
-      if (!s->two_byte_p)
-        for (i = 0; i < s->nchars; ++i)
-          char1b[i] = XCHAR2B_BYTE2 (&s->char2b[i]);
-
-      /* Draw text with TextOut and friends. */
-      w32_text_out (s, x, s->ybase - boff, s->char2b, s->nchars);
-
-      if (s->face->overstrike)
-	{
-	  /* For overstriking (to simulate bold-face), draw the
-	     characters again shifted to the right by one pixel.  */
-	  int old_BkMode = SetBkMode (s->hdc, TRANSPARENT);
-	  w32_text_out (s, x + 1, s->ybase - boff, s->char2b, s->nchars);
-	  if (old_BkMode && old_BkMode != TRANSPARENT)
-	    SetBkMode (s->hdc, old_BkMode);
-	}
-    }
-  if (s->font && s->font->hfont)
+
+  if (s->font && FONT_COMPAT (s->font)->hfont)
     SelectObject (s->hdc, old_font);
 }
 
@@ -2003,8 +1950,8 @@
   SetBkMode (s->hdc, TRANSPARENT);
   SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT);
 
-  if (s->font && s->font->hfont)
-    old_font = SelectObject (s->hdc, s->font->hfont);
+  if (s->font && FONT_COMPAT (s->font)->hfont)
+    old_font = SelectObject (s->hdc, FONT_COMPAT (s->font)->hfont);
 
   /* Draw a rectangle for the composition if the font for the very
      first character of the composition could not be loaded.  */
@@ -2014,10 +1961,9 @@
         w32_draw_rectangle (s->hdc, s->gc, x, s->y, s->width - 1,
                             s->height - 1);
     }
-#ifdef USE_FONT_BACKEND
-  else if (enable_font_backend)
+
     {
-      struct font *font = (struct font *) s->font_info;
+      struct font *font = s->font;
       int y = s->ybase;
       int width = 0;
 
@@ -2070,23 +2016,8 @@
 	      }
 	}
     }
-#endif	/* USE_FONT_BACKEND */
-  else
-    {
-      for (i = 0, j = s->gidx; i < s->nchars; i++, j++)
-	if (s->face)
-          {
-            w32_text_out (s, x + s->cmp->offsets[j * 2],
-                          s->ybase - s->cmp->offsets[j * 2 + 1],
-                          s->char2b + j, 1);
-            if (s->face->overstrike)
-	    w32_text_out (s, x + s->cmp->offsets[j * 2] + 1,
-			  s->ybase - s->cmp->offsets[j + 1],
-			  s->char2b + j, 1);
-          }
-    }
-
-  if (s->font && s->font->hfont)
+
+  if (s->font && FONT_COMPAT (s->font)->hfont)
     SelectObject (s->hdc, old_font);
 }
 
@@ -2894,9 +2825,7 @@
             x_set_glyph_string_gc (next);
             x_set_glyph_string_clipping (next);
             x_draw_glyph_string_background (next, 1);
-#ifdef USE_FONT_BACKEND
             next->num_clips = 0;
-#endif /* USE_FONT_BACKEND */
           }
     }
 
@@ -2959,46 +2888,46 @@
   if (!s->for_overlaps)
     {
       /* Draw underline.  */
-      if (s->face->underline_p
-          && (s->font->bdf || !s->font->tm.tmUnderlined))
+      if (s->face->underline_p)
         {
-          unsigned long h;
+          unsigned long thickness, position;
           int y;
-	  /* Get the underline thickness.  Default is 1 pixel.  */
-#ifdef USE_FONT_BACKEND
-	  if (enable_font_backend)
-	    /* In the future, we must use information of font.  */
-	    h = 1;
-	  else
-#endif	/* USE_FONT_BACKEND */
-            h = 1;
-
-#ifdef USE_FONT_BACKEND
-	  if (enable_font_backend)
-	    {
-	      if (s->face->font)
-		/* In the future, we must use information of font.  */
-		y = s->ybase + (s->face->font->max_bounds.descent + 1) / 2;
-	      else
-		y = s->y + s->height - h;
-	    }
-	  else
-#endif
+
+          if (s->prev && s->prev->face->underline_p)
+            {
+              /* We use the same underline style as the previous one.  */
+              thickness = s->prev->underline_thickness;
+              position = s->prev->underline_position;
+            }
+          else
             {
-                y = s->y + s->height - h;
-                /* TODO: Use font information for positioning and
-                   thickness of underline.  See OUTLINETEXTMETRIC,
-                   and xterm.c.  Note: If you make this work,
-                   don't forget to change the doc string of
-                   x-use-underline_color-position-properties
-                   below.  */
-#if 0
-              if (!x_underline_at_descent_line)
+              /* Get the underline thickness.  Default is 1 pixel.  */
+              if (s->font && s->font->underline_thickness > 0)
+                thickness = s->font->underline_thickness;
+              else
+                thickness = 1;
+              if (x_underline_at_descent_line)
+                position = (s->height - thickness) - s->ybase;
+              else
                 {
-                  ...
+                /* Get the underline position.  This is the recommended
+                   vertical offset in pixels from the baseline to the top of
+                   the underline.  This is a signed value according to the
+                   specs, and its default is
+
+                   ROUND ((maximum_descent) / 2), with
+                   ROUND (x) = floor (x + 0.5)  */
+
+                if (x_use_underline_position_properties
+                    && s->font && s->font->underline_position >= 0)
+                  position = s->font->underline_position;
+                else if (s->font)
+                  position = (s->font->descent + 1) / 2;
                 }
-#endif
+              s->underline_thickness = thickness;
+              s->underline_position =position;
             }
+          y = s->ybase + position;
           if (s->face->underline_defaulted_p)
             {
               w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x,
@@ -3029,7 +2958,8 @@
 
       /* Draw strike-through.  */
       if (s->face->strike_through_p
-          && (s->font->bdf || !s->font->tm.tmStruckOut))
+          && (FONT_COMPAT (s->font)->bdf
+	      || !FONT_COMPAT (s->font)->tm.tmStruckOut))
         {
           unsigned long h = 1;
           unsigned long dy = (s->height - h) / 2;
@@ -3071,9 +3001,7 @@
 		  x_draw_composite_glyph_string_foreground (prev);
                 w32_set_clip_rectangle (prev->hdc, NULL);
 		prev->hl = save;
-#ifdef USE_FONT_BACKEND
 		prev->num_clips = 0;
-#endif	/* USE_FONT_BACKEND */
 	      }
 	}
 
@@ -3098,18 +3026,14 @@
 		  x_draw_composite_glyph_string_foreground (next);
                 w32_set_clip_rectangle (next->hdc, NULL);
 		next->hl = save;
-#ifdef USE_FONT_BACKEND
 		next->num_clips = 0;
-#endif	/* USE_FONT_BACKEND */
 	      }
 	}
     }
 
   /* Reset clipping.  */
   w32_set_clip_rectangle (s->hdc, NULL);
-#ifdef USE_FONT_BACKEND
   s->num_clips = 0;
-#endif	/* USE_FONT_BACKEND */
 }
 
 
@@ -5853,6 +5777,8 @@
 
 /* Changing the font of the frame.  */
 
+#if OLD_FONT
+
 /* Give frame F the font named FONTNAME as its default font, and
    return the full name of that font.  FONTNAME may be a wildcard
    pattern; in that case, we choose some font that fits the pattern.
@@ -5951,31 +5877,32 @@
 
   return fontset_name (fontset);
 }
-
-#ifdef USE_FONT_BACKEND
+#endif	/* OLD_FONT */
+
+
 Lisp_Object
-x_new_fontset2 (f, fontset, font_object)
+x_new_font (f, font_object, fontset)
      struct frame *f;
+     Lisp_Object font_object;
      int fontset;
-     Lisp_Object font_object;
-{
-  struct font *font = XSAVE_VALUE (font_object)->pointer;
-
-  if (FRAME_FONT_OBJECT (f) == font)
+{
+  struct font *font = XFONT_OBJECT (font_object);
+
+  if (fontset < 0)
+    fontset = fontset_from_font (font_object);
+  FRAME_FONTSET (f) = fontset;
+  if (FRAME_FONT (f) == font)
     /* This font is already set in frame F.  There's nothing more to
        do.  */
     return fontset_name (fontset);
 
   BLOCK_INPUT;
 
-  FRAME_FONT_OBJECT (f) = font;
-  FRAME_FONT (f) = font->font.font;
-  FRAME_BASELINE_OFFSET (f) = font->font.baseline_offset;
-  FRAME_FONTSET (f) = fontset;
-
-  FRAME_COLUMN_WIDTH (f) = font->font.average_width;
-  FRAME_SPACE_WIDTH (f) = font->font.space_width;
-  FRAME_LINE_HEIGHT (f) = font->font.height;
+  FRAME_FONT (f) = font;
+  FRAME_BASELINE_OFFSET (f) = font->baseline_offset;
+  FRAME_COLUMN_WIDTH (f) = font->average_width;
+  FRAME_SPACE_WIDTH (f) = font->space_width;
+  FRAME_LINE_HEIGHT (f) = font->height;
 
   compute_fringe_widths (f, 1);
 
@@ -6012,7 +5939,6 @@
 
   return fontset_name (fontset);
 }
-#endif	/* USE_FONT_BACKEND */
 
 
 /***********************************************************************
@@ -6569,14 +6495,11 @@
 
   BLOCK_INPUT;
 
-#ifdef USE_FONT_BACKEND
-      /* We must free faces before destroying windows because some
-	 font-driver (e.g. xft) access a window while finishing a
-	 face.  */
-      if (enable_font_backend
-	  && FRAME_FACE_CACHE (f))
-	free_frame_faces (f);
-#endif	/* USE_FONT_BACKEND */
+  /* We must free faces before destroying windows because some
+     font-driver (e.g. xft) access a window while finishing a
+     face.  */
+  if (FRAME_FACE_CACHE (f))
+    free_frame_faces (f);
 
   if (FRAME_W32_WINDOW (f))
     my_destroy_window (f, FRAME_W32_WINDOW (f));
@@ -6681,6 +6604,8 @@
 				Fonts
  ***********************************************************************/
 
+#if OLD_FONT
+
 /* The following functions are listed here to help diff stay in step
    with xterm.c.  See w32fns.c for definitions.
 
@@ -6783,6 +6708,9 @@
 x_find_ccl_program (fontp)
 
 */
+
+#endif	/* OLD_FONT */
+
 
 /***********************************************************************
 			    Initialization
@@ -6916,8 +6844,10 @@
   w32_draw_fringe_bitmap,
   w32_define_fringe_bitmap,
   w32_destroy_fringe_bitmap,
+#if OLD_FONT
   w32_per_char_metric,
   w32_encode_char,
+#endif
   w32_compute_glyph_string_overhangs,
   x_draw_glyph_string,
   w32_define_frame_cursor,
@@ -7005,12 +6935,14 @@
     return;
 
   BLOCK_INPUT;
+#if OLD_FONT
   /* Free the fonts in the font table.  */
   for (i = 0; i < dpyinfo->n_fonts; i++)
     if (dpyinfo->font_table[i].name)
       {
         DeleteObject (((XFontStruct*)(dpyinfo->font_table[i].font))->hfont);
       }
+#endif
 
   x_delete_display (dpyinfo);
   UNBLOCK_INPUT;
@@ -7139,7 +7071,9 @@
     if (dpyinfo->palette)
       DeleteObject(dpyinfo->palette);
   }
+#if OLD_FONT
   xfree (dpyinfo->font_table);
+#endif
   xfree (dpyinfo->w32_id_name);
 
   w32_reset_fringes ();