(x_set_alpha): Set alpha to -1 if nil given.
[bpt/emacs.git] / src / w32term.c
index aeab2b7..3e73ceb 100644 (file)
@@ -54,7 +54,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "keymap.h"
 
 #include "w32heap.h"
-#include "w32bdf.h"
 #include <shellapi.h>
 
 #include "font.h"
@@ -87,8 +86,7 @@ static int any_help_event_p;
 /* Last window where we saw the mouse.  Used by mouse-autoselect-window.  */
 static Lisp_Object last_window;
 
-/* Non-zero means make use of UNDERLINE_POSITION font properties.
-   (Not yet supported, see TODO in x_draw_glyph_string.)  */
+/* Non-zero means make use of UNDERLINE_POSITION font properties.  */
 int x_use_underline_position_properties;
 
 /* Non-zero means to draw the underline at the same place as the descent line.  */
@@ -102,8 +100,6 @@ extern void free_frame_menubar ();
 extern int w32_codepage_for_font (char *fontname);
 extern Cursor w32_load_cursor (LPCTSTR name);
 
-extern glyph_metric *w32_BDF_TextMetric(bdffont *fontp,
-                                       unsigned char *text, int dim);
 extern Lisp_Object Vwindow_system;
 
 #define x_any_window_to_frame x_window_to_frame
@@ -131,19 +127,28 @@ typedef struct tagWCRANGE
   USHORT cGlyphs;
 } WCRANGE;
 
-typedef struct tagGLYPHSET 
+typedef struct tagGLYPHSET
 {
   DWORD cbThis;
   DWORD flAccel;
   DWORD cGlyphsSupported;
   DWORD cRanges;
   WCRANGE ranges[1];
-} GLYPHSET;  
+} GLYPHSET;
 
 #endif
 
-/* Dynamic linking to GetFontUnicodeRanges (not available on 95, 98, ME).  */
-DWORD (PASCAL *pfnGetFontUnicodeRanges) (HDC device, GLYPHSET *ranges);
+/* Dynamic linking to SetLayeredWindowAttribute (only since 2000).  */
+BOOL (PASCAL *pfnSetLayeredWindowAttributes) (HWND, COLORREF, BYTE, DWORD);
+
+#ifndef LWA_ALPHA
+#define LWA_ALPHA 0x02
+#endif
+/* WS_EX_LAYERED is defined unconditionally by MingW, but only for W2K and
+   later targets by MSVC headers.  */
+#ifndef WS_EX_LAYERED
+#define WS_EX_LAYERED 0x80000
+#endif
 
 /* Frame being updated by update_frame.  This is declared in term.c.
    This is set by update_begin and looked at by all the
@@ -162,14 +167,6 @@ int w32_system_caret_x;
 int w32_system_caret_y;
 int w32_use_visible_system_caret;
 
-/* Flag to enable Unicode output in case users wish to use programs
-   like Twinbridge on '95 rather than installed system level support
-   for Far East languages.  */
-int w32_enable_unicode_output;
-
-/* Flag to enable Cleartype hack for font metrics.  */
-static int cleartype_active;
-
 DWORD dwWindowsThreadId = 0;
 HANDLE hWindowsThread = NULL;
 DWORD dwMainThreadId = 0;
@@ -254,8 +251,6 @@ void x_set_window_size P_ ((struct frame *, int, int, int));
 void x_wm_set_window_state P_ ((struct frame *, int));
 void x_wm_set_icon_pixmap P_ ((struct frame *, int));
 static void w32_initialize P_ ((void));
-static void x_font_min_bounds P_ ((XFontStruct *, int *, int *));
-int x_compute_min_glyph_bounds P_ ((struct frame *));
 static void x_update_end P_ ((struct frame *));
 static void w32_frame_up_to_date P_ ((struct frame *));
 static void w32_set_terminal_modes P_ ((struct terminal *));
@@ -417,6 +412,69 @@ w32_clear_window (f)
   release_frame_dc (f, hdc);
 }
 
+#define OPAQUE_FRAME 255
+
+void
+x_set_frame_alpha (f)
+     struct frame *f;
+{
+  struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
+  double alpha = 1.0;
+  double alpha_min = 1.0;
+  BYTE opac;
+  LONG ex_style;
+  HWND window = FRAME_W32_WINDOW (f);
+
+  /* Older versions of Windows do not support transparency.  */
+  if (!pfnSetLayeredWindowAttributes)
+    return;
+
+  if (dpyinfo->x_highlight_frame == f)
+    alpha = f->alpha[0];
+  else
+    alpha = f->alpha[1];
+
+  if (FLOATP (Vframe_alpha_lower_limit))
+    alpha_min = XFLOAT_DATA (Vframe_alpha_lower_limit);
+  else if (INTEGERP (Vframe_alpha_lower_limit))
+    alpha_min = (XINT (Vframe_alpha_lower_limit)) / 100.0;
+
+  if (alpha < 0.0)
+    return;
+  else if (alpha > 1.0)
+    alpha = 1.0;
+  else if (alpha < alpha_min && alpha_min <= 1.0)
+    alpha = alpha_min;
+
+  opac = alpha * OPAQUE_FRAME;
+
+  ex_style = GetWindowLong (window, GWL_EXSTYLE);
+
+  if (opac == OPAQUE_FRAME)
+    ex_style &= ~WS_EX_LAYERED;
+  else
+    ex_style |= WS_EX_LAYERED;
+
+  SetWindowLong (window, GWL_EXSTYLE, ex_style);
+
+  if (opac != OPAQUE_FRAME)
+    pfnSetLayeredWindowAttributes (window, 0, opac, LWA_ALPHA);
+}
+
+int
+x_display_pixel_height (dpyinfo)
+     struct w32_display_info *dpyinfo;
+{
+  return GetDeviceCaps (GetDC (GetDesktopWindow ()), VERTRES);
+}
+
+int
+x_display_pixel_width (dpyinfo)
+     struct w32_display_info *dpyinfo;
+{
+  return GetDeviceCaps (GetDC (GetDesktopWindow ()), HORZRES);
+}
+
 \f
 /***********************************************************************
                    Starting and ending an update
@@ -892,596 +950,6 @@ w32_reset_terminal_modes (struct terminal *term)
 
 /* 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 *));
-
-
-/* Get metrics of character CHAR2B in FONT.  Value is always non-null.
-   If CHAR2B is not contained in FONT, the font's default character
-   metric is returned. */
-
-static int
-w32_bdf_per_char_metric (font, char2b, dim, pcm)
-     XFontStruct *font;
-     wchar_t *char2b;
-     int dim;
-     XCharStruct * pcm;
-{
-  glyph_metric * bdf_metric;
-  char buf[2];
-
-  if (dim == 1)
-    buf[0] = (char)(*char2b);
-  else
-    {
-      buf[0] = XCHAR2B_BYTE1 (char2b);
-      buf[1] = XCHAR2B_BYTE2 (char2b);
-    }
-
-  bdf_metric = w32_BDF_TextMetric (font->bdf, buf, dim);
-
-  if (bdf_metric)
-    {
-      pcm->width = bdf_metric->dwidth;
-      pcm->lbearing = bdf_metric->bbox;
-      pcm->rbearing = bdf_metric->dwidth
-                    - (bdf_metric->bbox + bdf_metric->bbw);
-      pcm->ascent = bdf_metric->bboy + bdf_metric->bbh;
-      pcm->descent = -bdf_metric->bboy;
-
-      return 1;
-    }
-  return 0;
-}
-
-
-static int
-w32_native_per_char_metric (font, char2b, font_type, pcm)
-     XFontStruct *font;
-     wchar_t *char2b;
-     enum w32_char_font_type font_type;
-     XCharStruct * pcm;
-{
-  HDC hdc = GetDC (NULL);
-  HFONT old_font;
-  BOOL retval = FALSE;
-
-  xassert (font && char2b);
-  xassert (font->hfont);
-  xassert (font_type == UNICODE_FONT || font_type == ANSI_FONT);
-
-  old_font = SelectObject (hdc, font->hfont);
-
-  if ((font->tm.tmPitchAndFamily & TMPF_TRUETYPE) != 0)
-    {
-      ABC char_widths;
-
-      if (font_type == UNICODE_FONT)
-       retval = GetCharABCWidthsW (hdc, *char2b, *char2b, &char_widths);
-      else
-       retval = GetCharABCWidthsA (hdc, *char2b, *char2b, &char_widths);
-
-      if (retval)
-       {
-#if 0
-         /* Disabled until we can find a way to get the right results
-            on all versions of Windows.  */
-
-         /* Don't trust the ABC widths.  For synthesized fonts they are
-            wrong, and so is the result of GetCharWidth()!  */
-         int real_width;
-         GetCharWidth (hdc, *char2b, *char2b, &real_width);
-#endif
-         if (cleartype_active)
-           {
-             /* Cleartype antialiasing causes characters to overhang
-                by a pixel on each side compared with what GetCharABCWidths
-                reports.  */
-             char_widths.abcA -= 1;
-             char_widths.abcC -= 1;
-             char_widths.abcB += 2;
-           }
-
-         pcm->width = char_widths.abcA + char_widths.abcB + char_widths.abcC;
-#if 0
-         /* As far as I can tell, this is the best way to determine what
-            ExtTextOut will do with the broken font.  */
-         if (pcm->width != real_width)
-           pcm->width = (pcm->width + real_width) / 2;
-#endif
-         pcm->lbearing = char_widths.abcA;
-         pcm->rbearing = char_widths.abcA + char_widths.abcB;
-         pcm->ascent = FONT_BASE (font);
-         pcm->descent = FONT_DESCENT (font);
-       }
-    }
-
-  if (!retval)
-    {
-      /* Either font is not a True-type font, or GetCharABCWidthsW
-        failed (it is not supported on Windows 9x for instance), so we
-        can't determine the full info we would like.  All is not lost
-        though - we can call GetTextExtentPoint32 to get rbearing and
-        deduce width based on the font's per-string overhang.  lbearing
-        is assumed to be zero.  */
-
-      /* TODO: Some Thai characters (and other composites if Windows
-         supports them) do have lbearing, and report their total width
-         as zero. Need some way of handling them when
-         GetCharABCWidthsW fails. */
-      SIZE sz;
-
-      if (font_type == UNICODE_FONT)
-       retval = GetTextExtentPoint32W (hdc, char2b, 1, &sz);
-      else
-       retval = GetTextExtentPoint32A (hdc, (char*)char2b, 1, &sz);
-
-      if (retval)
-       {
-         pcm->width = sz.cx;
-         pcm->rbearing = sz.cx + font->tm.tmOverhang;
-         pcm->lbearing = 0;
-         pcm->ascent = FONT_BASE (font);
-         pcm->descent = FONT_DESCENT (font);
-       }
-    }
-
-
-  if (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0)
-    {
-      retval = FALSE;
-    }
-
-  SelectObject (hdc, old_font);
-  ReleaseDC (NULL, hdc);
-
-  return retval;
-}
-
-
-XCharStruct *
-w32_per_char_metric (font, char2b, font_type)
-     XFontStruct *font;
-     wchar_t *char2b;
-     int /* enum w32_char_font_type */ font_type;
-{
-  /* The result metric information.  */
-  XCharStruct *pcm;
-  BOOL retval;
-
-  xassert (font && char2b);
-
-  /* TODO: This function is currently called through the RIF, and in
-     some cases font_type is UNKNOWN_FONT. We currently allow the
-     cached metrics to be used, which seems to work, but in cases
-     where font_type is UNKNOWN_FONT, we probably haven't encoded
-     char2b appropriately. All callers need checking to see what they
-     are passing.  This is most likely to affect variable width fonts
-     outside the Latin-1 range, particularly in languages like Thai
-     that rely on rbearing and lbearing to provide composition. I
-     don't think that is working currently anyway, but we don't seem
-     to have anyone testing such languages on Windows.  */
-
-  /* Handle the common cases quickly.  */
-  if (!font->bdf && font->per_char == NULL)
-    /* TODO: determine whether char2b exists in font?  */
-    return &font->max_bounds;
-  else if (!font->bdf && *char2b < 128)
-    return &font->per_char[*char2b];
-
-  xassert (font_type != UNKNOWN_FONT);
-
-  pcm = &font->scratch;
-
-  if (font_type == BDF_1D_FONT)
-    retval = w32_bdf_per_char_metric (font, char2b, 1, pcm);
-  else if (font_type == BDF_2D_FONT)
-    retval = w32_bdf_per_char_metric (font, char2b, 2, pcm);
-  else
-    retval = w32_native_per_char_metric (font, char2b, font_type, pcm);
-
-  if (retval)
-    return pcm;
-
-  return NULL;
-}
-
-void
-w32_cache_char_metrics (font)
-     XFontStruct *font;
-{
-  wchar_t char2b = L'x';
-
-  /* Cache char metrics for the common cases.  */
-  if (font->bdf)
-    {
-      /* TODO: determine whether font is fixed-pitch.  */
-      if (!w32_bdf_per_char_metric (font, &char2b, 1, &font->max_bounds))
-        {
-          /* Use the font width and height as max bounds, as not all BDF
-             fonts contain the letter 'x'. */
-          font->max_bounds.width = FONT_WIDTH (font);
-          font->max_bounds.lbearing = -font->bdf->llx;
-          font->max_bounds.rbearing = FONT_WIDTH (font) - font->bdf->urx;
-          font->max_bounds.ascent = FONT_BASE (font);
-          font->max_bounds.descent = FONT_DESCENT (font);
-        }
-    }
-  else
-    {
-      if (((font->tm.tmPitchAndFamily & TMPF_FIXED_PITCH) != 0)
-          /* Some fonts (eg DBCS fonts) are marked as fixed width even
-             though they contain characters of different widths. */
-          || (font->tm.tmMaxCharWidth != font->tm.tmAveCharWidth))
-       {
-         /* Font is not fixed pitch, so cache per_char info for the
-             ASCII characters.  It would be much more work, and probably
-             not worth it, to cache other chars, since we may change
-             between using Unicode and ANSI text drawing functions at
-             run-time.  */
-         int i;
-
-         font->per_char = xmalloc (128 * sizeof(XCharStruct));
-         for (i = 0; i < 128; i++)
-           {
-             char2b = i;
-             w32_native_per_char_metric (font, &char2b, ANSI_FONT,
-                                         &font->per_char[i]);
-           }
-       }
-      else
-       w32_native_per_char_metric (font, &char2b, ANSI_FONT,
-                                   &font->max_bounds);
-    }
-}
-
-/* Determine if a font is double byte. */
-static int
-w32_font_is_double_byte (XFontStruct *font)
-{
-  return font->double_byte_p;
-}
-
-
-static BOOL
-w32_use_unicode_for_codepage (codepage)
-     int codepage;
-{
-  /* If the current codepage is supported, use Unicode for output. */
-  return (w32_enable_unicode_output
-          && codepage != CP_8BIT
-          && (codepage == CP_UNICODE || IsValidCodePage (codepage)));
-}
-
-/* Encode CHAR2B using encoding information from FONT_INFO.  CHAR2B is
-   the two-byte form of C.  Encoding is returned in *CHAR2B.  */
-
-static int /* enum w32_char_font_type */
-w32_encode_char (c, char2b, font_info, charset, two_byte_p)
-     int c;
-     wchar_t *char2b;
-     struct font_info *font_info;
-     struct charset *charset;
-     int * two_byte_p;
-{
-  int codepage;
-  int unicode_p = 0;
-  int internal_two_byte_p = 0;
-
-  XFontStruct *font = font_info->font;
-
-  internal_two_byte_p = w32_font_is_double_byte (font);
-  codepage = font_info->codepage;
-
-  /* If font can output unicode, use the original unicode character.  */
-  if ( font && !font->bdf && w32_use_unicode_for_codepage (codepage)
-       && c >= 0x100)
-    {
-      *char2b = c;
-      unicode_p = 1;
-      internal_two_byte_p = 1;
-    }
-
-  /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
-     This may be either a program in a special encoder language or a
-     fixed encoding.  */
-  else if (font_info->font_encoder)
-    {
-      /* It's a program.  */
-      struct ccl_program *ccl = font_info->font_encoder;
-
-      if (CHARSET_DIMENSION (charset) == 1)
-       {
-         ccl->reg[0] = CHARSET_ID (charset);
-         ccl->reg[1] = XCHAR2B_BYTE2 (char2b);
-         ccl->reg[2] = -1;
-       }
-      else
-       {
-         ccl->reg[0] = CHARSET_ID (charset);
-         ccl->reg[1] = XCHAR2B_BYTE1 (char2b);
-         ccl->reg[2] = XCHAR2B_BYTE2 (char2b);
-       }
-
-      ccl_driver (ccl, NULL, NULL, 0, 0, Qnil);
-
-      /* We assume that MSBs are appropriately set/reset by CCL
-        program.  */
-      if (!internal_two_byte_p)        /* 1-byte font */
-       STORE_XCHAR2B (char2b, 0, ccl->reg[1]);
-      else
-       STORE_XCHAR2B (char2b, ccl->reg[1], ccl->reg[2]);
-    }
-  else if (font_info->encoding_type)
-    {
-      /* Fixed encoding scheme.  See fontset.h for the meaning of the
-        encoding numbers.  */
-      unsigned char enc = font_info->encoding_type;
-
-      if ((enc == 1 || enc == 2)
-         && CHARSET_DIMENSION (charset) == 2)
-       STORE_XCHAR2B (char2b, XCHAR2B_BYTE1 (char2b) | 0x80, XCHAR2B_BYTE2 (char2b));
-
-      if (enc == 1 || enc == 3          || (enc == 4 && CHARSET_DIMENSION (charset) == 1))
-       STORE_XCHAR2B (char2b, XCHAR2B_BYTE1 (char2b), XCHAR2B_BYTE2 (char2b) | 0x80);
-      else if (enc == 4)
-        {
-          int code = (int) (*char2b);
-
-         JIS_TO_SJIS (code);
-          STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF));
-        }
-    }
-
-  if (two_byte_p)
-    *two_byte_p = internal_two_byte_p;
-
-  if (!font)
-    return UNKNOWN_FONT;
-  else if (font->bdf && CHARSET_DIMENSION (charset) == 1)
-    return BDF_1D_FONT;
-  else if (font->bdf)
-    return BDF_2D_FONT;
-  else if (unicode_p)
-    return UNICODE_FONT;
-  else
-    return ANSI_FONT;
-}
-
-
-/* Return a char-table whose elements are t if the font FONT_INFO
-   contains a glyph for the corresponding character, and nil if not.
-
-   Fixme: For the moment, this function works only for fonts whose
-   glyph encoding is the same as Unicode (e.g. ISO10646-1 fonts).  */
-
-Lisp_Object
-x_get_font_repertory (f, font_info)
-     FRAME_PTR f;
-     struct font_info *font_info;
-{
-  XFontStruct *font = (XFontStruct *) font_info->font;
-  Lisp_Object table;
-  int min_byte1, max_byte1, min_byte2, max_byte2;
-  int c;
-  struct charset *charset = CHARSET_FROM_ID (font_info->charset);
-  int offset = CHARSET_OFFSET (charset);
-
-  table = Fmake_char_table (Qnil, Qnil);
-
-  if (!font->bdf && pfnGetFontUnicodeRanges)
-    {
-      GLYPHSET *glyphset;
-      DWORD glyphset_size;
-      HDC display = get_frame_dc (f);
-      HFONT prev_font;
-      int i;
-
-      prev_font = SelectObject (display, font->hfont);
-
-      /* First call GetFontUnicodeRanges to find out how big a structure
-        we need.  */
-      glyphset_size = pfnGetFontUnicodeRanges (display, NULL);
-      if (glyphset_size)
-       {
-         glyphset = (GLYPHSET *) alloca (glyphset_size);
-         glyphset->cbThis = glyphset_size;
-
-         /* Now call it again to get the ranges.  */
-         glyphset_size = pfnGetFontUnicodeRanges (display, glyphset);
-
-         if (glyphset_size)
-           {
-             /* Store the ranges in TABLE.  */
-             for (i = 0; i < glyphset->cRanges; i++)
-               {
-                 int from = glyphset->ranges[i].wcLow;
-                 int to = from + glyphset->ranges[i].cGlyphs - 1;
-                 char_table_set_range (table, from, to, Qt);
-               }
-           }
-       }
-
-      SelectObject (display, prev_font);
-      release_frame_dc (f, display);
-
-      /* If we got the information we wanted above, then return it.  */
-      if (glyphset_size)
-       return table;
-    }
-
-#if 0 /* TODO: Convert to work on Windows so BDF and older platforms work.  */
-  /* When GetFontUnicodeRanges is not available or does not work,
-     work it out manually.  */
-  min_byte1 = font->min_byte1;
-  max_byte1 = font->max_byte1;
-  min_byte2 = font->min_char_or_byte2;
-  max_byte2 = font->max_char_or_byte2;
-  if (min_byte1 == 0 && max_byte1 == 0)
-    {
-      if (! font->per_char || font->all_chars_exist == True)
-        {
-          if (offset >= 0)
-            char_table_set_range (table, offset + min_byte2,
-                                  offset + max_byte2, Qt);
-          else
-            for (; min_byte2 <= max_byte2; min_byte2++)
-              {
-                c = DECODE_CHAR (charset, min_byte2);
-                CHAR_TABLE_SET (table, c, Qt);
-              }
-        }
-      else
-       {
-         XCharStruct *pcm = font->per_char;
-         int from = -1;
-         int i;
-
-         for (i = min_byte2; i <= max_byte2; i++, pcm++)
-           {
-             if (pcm->width == 0 && pcm->rbearing == pcm->lbearing)
-               {
-                 if (from >= 0)
-                   {
-                      if (offset >= 0)
-                        char_table_set_range (table, offset + from,
-                                              offset + i - 1, Qt);
-                      else
-                        for (; from < i; from++)
-                          {
-                            c = DECODE_CHAR (charset, from);
-                            CHAR_TABLE_SET (table, c, Qt);
-                          }
-                     from = -1;
-                   }
-               }
-             else if (from < 0)
-               from = i;
-           }
-         if (from >= 0)
-            {
-              if (offset >= 0)
-                char_table_set_range (table, offset + from, offset + i - 1,
-                                      Qt);
-              else
-                for (; from < i; from++)
-                  {
-                    c = DECODE_CHAR (charset, from);
-                    CHAR_TABLE_SET (table, c, Qt);
-                  }
-            }
-       }
-    }
-  else
-    {
-      if (! font->per_char || font->all_chars_exist == True)
-       {
-         int i, j;
-
-          if (offset >= 0)
-            for (i = min_byte1; i <= max_byte1; i++)
-              char_table_set_range
-                (table, offset + ((i << 8) | min_byte2),
-                 offset + ((i << 8) | max_byte2), Qt);
-          else
-            for (i = min_byte1; i <= max_byte1; i++)
-              for (j = min_byte2; j <= max_byte2; j++)
-                {
-                  unsiged code = (i << 8) | j;
-                  c = DECODE_CHAR (charset, code);
-                  CHAR_TABLE_SET (table, c, Qt);
-                }
-       }
-      else
-       {
-         XCharStruct *pcm = font->per_char;
-         int i;
-
-         for (i = min_byte1; i <= max_byte1; i++)
-           {
-             int from = -1;
-             int j;
-
-             for (j = min_byte2; j <= max_byte2; j++, pcm++)
-               {
-                 if (pcm->width == 0 && pcm->rbearing == pcm->lbearing)
-                   {
-                     if (from >= 0)
-                       {
-                          if (offset >= 0)
-                            char_table_set_range
-                              (table, offset + ((i << 8) | from),
-                               offset + ((i << 8) | (j - 1)), Qt);
-                          else
-                            {
-                              for (; from < j; from++)
-                                {
-                                  unsigned code = (i << 8) | from;
-                                  c = ENCODE_CHAR (charset, code);
-                                  CHAR_TABLE_SET (table, c, Qt);
-                                }
-                            }
-                         from = -1;
-                       }
-                   }
-                 else if (from < 0)
-                   from = j;
-               }
-             if (from >= 0)
-                {
-                  if (offset >= 0)
-                    char_table_set_range
-                      (table, offset + ((i << 8) | from),
-                       offset + ((i << 8) | (j - 1)), Qt);
-                  else
-                    {
-                      for (; from < j; from++)
-                        {
-                          unsigned code = (i << 8) | from;
-                          c = DECODE_CHAR (charset, code);
-                          CHAR_TABLE_SET (table, c, Qt);
-                        }
-                    }
-                }
-           }
-       }
-    }
-#endif
-  return table;
-}
-
-\f
-/***********************************************************************
-                           Glyph display
- ***********************************************************************/
-
-
-/* Encapsulate the different ways of displaying text under W32.  */
-
-static void
-w32_text_out (s, x, y,chars,nchars)
-     struct glyph_string * s;
-     int x, y;
-     wchar_t * chars;
-     int nchars;
-{
-  int charset_dim = w32_font_is_double_byte (s->font) ? 2 : 1;
-  if (s->font->bdf)
-    w32_BDF_TextOut (s->font->bdf, s->hdc,
-                     x, y, (char *) chars, charset_dim,
-                     nchars * charset_dim, 0);
-  else if (s->first_glyph->font_type == UNICODE_FONT)
-    ExtTextOutW (s->hdc, x, y, 0, NULL, chars, nchars, NULL);
-  else
-    ExtTextOutA (s->hdc, x, y, 0, NULL, (char *) chars,
-                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 *));
 static void x_draw_glyph_string_background P_ ((struct glyph_string *,
@@ -1509,10 +977,6 @@ static void w32_draw_relief_rect P_ ((struct frame *, int, int, int, int,
 static void w32_draw_box_rect P_ ((struct glyph_string *, int, int, int, int,
                                 int, int, int, RECT *));
 
-#if GLYPH_DEBUG
-static void x_check_font P_ ((struct frame *, XFontStruct *));
-#endif
-
 
 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
    face.  */
@@ -1722,17 +1186,6 @@ x_set_glyph_string_clipping_exactly (src, dst)
   r.bottom = r.top + src->height;
   dst->clip[0] = r;
   dst->num_clips = 1;
-#if OLD_FONT
-    {
-  struct glyph_string *clip_head = src->clip_head;
-  struct glyph_string *clip_tail = src->clip_tail;
-
-  /* This foces clipping just this glyph string.  */
-  src->clip_head = src->clip_tail = src;
-  get_glyph_string_clip_rect (src, &r);
-  src->clip_head = clip_head, src->clip_tail = clip_tail;
-    }
-#endif /* OLD_FONT */
   w32_set_clip_rectangle (dst->hdc, &r);
 }
 
@@ -1766,20 +1219,6 @@ w32_compute_glyph_string_overhangs (s)
     }
 }
 
-
-static void
-w32_get_glyph_overhangs (glyph, f, left, right)
-     struct glyph *glyph;
-     struct frame *f;
-     int *left, *right;
-{
-  HDC hdc = get_frame_dc (f);
-  /* Convert to unicode! */
-  x_get_glyph_overhangs (glyph, f, left, right);
-  release_frame_dc (f, hdc);
-}
-
-
 /* Fill rectangle X, Y, W, H with background color of glyph string S.  */
 
 static INLINE void
@@ -1842,8 +1281,6 @@ x_draw_glyph_string_background (s, force_p)
         if (FONT_HEIGHT (s->font) < s->height - 2 * box_line_width
               || s->font_not_found_p
               || s->extends_to_end_of_line_p
-              || FONT_COMPAT (s->font)->bdf
-              || cleartype_active
               || force_p)
        {
          x_clear_glyph_string_rect (s, s->x, s->y + box_line_width,
@@ -1862,7 +1299,6 @@ x_draw_glyph_string_foreground (s)
      struct glyph_string *s;
 {
   int i, x;
-  HFONT old_font;
 
   /* If first glyph of S has a left box line, start drawing the text
      of S to the right of that box line.  */
@@ -1872,19 +1308,10 @@ x_draw_glyph_string_foreground (s)
   else
     x = s->x;
 
-  if (s->for_overlaps || (s->background_filled_p && s->hl != DRAW_CURSOR)
-      || cleartype_active)
-    SetBkMode (s->hdc, TRANSPARENT);
-  else
-    SetBkMode (s->hdc, OPAQUE);
-
   SetTextColor (s->hdc, s->gc->foreground);
   SetBkColor (s->hdc, s->gc->background);
   SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT);
 
-  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. */
   if (s->font_not_found_p)
@@ -1900,12 +1327,15 @@ x_draw_glyph_string_foreground (s)
     }
   else
     {
-      int boff = s->font->baseline_offset;
       struct font *font = s->font;
+      int boff = font->baseline_offset;
       int y;
+      HFONT old_font;
+
+      old_font = SelectObject (s->hdc, FONT_HANDLE (font));
 
-      if (s->font->vertical_centering)
-       boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff;
+      if (font->vertical_centering)
+       boff = VCENTER_BASELINE_OFFSET (font, s->f) - boff;
 
       y = s->ybase - boff;
       if (s->for_overlaps
@@ -1915,10 +1345,9 @@ x_draw_glyph_string_foreground (s)
        font->driver->draw (s, 0, s->nchars, x, y, 1);
       if (s->face->overstrike)
        font->driver->draw (s, 0, s->nchars, x + 1, y, 0);
-    }
 
-  if (s->font && FONT_COMPAT (s->font)->hfont)
-    SelectObject (s->hdc, old_font);
+      SelectObject (s->hdc, old_font);
+    }
 }
 
 /* Draw the foreground of composite glyph string S.  */
@@ -1928,7 +1357,7 @@ x_draw_composite_glyph_string_foreground (s)
      struct glyph_string *s;
 {
   int i, j, x;
-  HFONT old_font;
+  struct font *font = s->font;
 
   /* If first glyph of S has a left box line, start drawing the text
      of S to the right of that box line.  */
@@ -1938,85 +1367,81 @@ x_draw_composite_glyph_string_foreground (s)
   else
     x = s->x;
 
-  /* S is a glyph string for a composition.  S->gidx is the index of
-     the first character drawn for glyphs of this composition.
-     S->gidx == 0 means we are drawing the very first character of
+  /* S is a glyph string for a composition.  S->cmp_from is the index
+     of the first character drawn for glyphs of this composition.
+     S->cmp_from == 0 means we are drawing the very first character of
      this composition.  */
 
   SetTextColor (s->hdc, s->gc->foreground);
   SetBkColor (s->hdc, s->gc->background);
-  SetBkMode (s->hdc, TRANSPARENT);
   SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT);
 
-  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.  */
   if (s->font_not_found_p)
     {
-      if (s->gidx == 0)
+      if (s->cmp_from == 0)
         w32_draw_rectangle (s->hdc, s->gc, x, s->y, s->width - 1,
                             s->height - 1);
     }
+  else if (! s->first_glyph->u.cmp.automatic)
+    {
+      int y = s->ybase;
+      int width = 0;
+      HFONT old_font;
+
+      old_font = SelectObject (s->hdc, FONT_HANDLE (font));
+
+      for (i = 0, j = s->cmp_from; i < s->nchars; i++, j++)
+       if (COMPOSITION_GLYPH (s->cmp, j) != '\t')
+         {
+           int xx = x + s->cmp->offsets[j * 2];
+           int yy = y - s->cmp->offsets[j * 2 + 1];
 
+           font->driver->draw (s, j, j + 1, xx, yy, 0);
+           if (s->face->overstrike)
+             font->driver->draw (s, j, j + 1, xx + 1, yy, 0);
+         }
+      SelectObject (s->hdc, old_font);
+    }
+  else
     {
-      struct font *font = s->font;
+      Lisp_Object gstring = composition_gstring_from_id (s->cmp_id);
+      Lisp_Object glyph;
       int y = s->ybase;
       int width = 0;
+      HFONT old_font;
 
-      if (s->cmp->method == COMPOSITION_WITH_GLYPH_STRING)
-       {
-         Lisp_Object gstring = AREF (XHASH_TABLE (composition_hash_table)
-                                     ->key_and_value,
-                                     s->cmp->hash_index * 2);
-         int from;
+      old_font = SelectObject (s->hdc, FONT_HANDLE (font));
 
-         for (i = from = 0; i < s->nchars; i++)
+      for (i = j = s->cmp_from; i < s->cmp_to; i++)
+       {
+         glyph = LGSTRING_GLYPH (gstring, i);
+         if (NILP (LGLYPH_ADJUSTMENT (glyph)))
+           width += LGLYPH_WIDTH (glyph);
+         else
            {
-             Lisp_Object g = LGSTRING_GLYPH (gstring, i);
-             Lisp_Object adjustment = LGLYPH_ADJUSTMENT (g);
              int xoff, yoff, wadjust;
 
-             if (! VECTORP (adjustment))
-               {
-                 width += LGLYPH_WIDTH (g);
-                 continue;
-               }
-             if (from < i)
+             if (j < i)
                {
-                 font->driver->draw (s, from, i, x, y, 0);
+                 font->driver->draw (s, j, i, x, y, 0);
                  x += width;
                }
-             xoff = XINT (AREF (adjustment, 0));
-             yoff = XINT (AREF (adjustment, 1));
-             wadjust = XINT (AREF (adjustment, 2));
-
+             xoff = LGLYPH_XOFF (glyph);
+             yoff = LGLYPH_YOFF (glyph);
+             wadjust = LGLYPH_WADJUST (glyph);
              font->driver->draw (s, i, i + 1, x + xoff, y + yoff, 0);
              x += wadjust;
-             from = i + 1;
+             j = i + 1;
              width = 0;
            }
-         if (from < i)
-           font->driver->draw (s, from, i, x, y, 0);
        }
-      else
-       {
-         for (i = 0, j = s->gidx; i < s->nchars; i++, j++)
-           if (COMPOSITION_GLYPH (s->cmp, j) != '\t')
-             {
-               int xx = x + s->cmp->offsets[j * 2];
-               int yy = y - s->cmp->offsets[j * 2 + 1];
+      if (j < i)
+       font->driver->draw (s, j, i, x, y, 0);
 
-               font->driver->draw (s, j, j + 1, xx, yy, 0);
-               if (s->face->overstrike)
-                 font->driver->draw (s, j, j + 1, xx + 1, yy, 0);
-             }
-       }
+      SelectObject (s->hdc, old_font);
     }
-
-  if (s->font && FONT_COMPAT (s->font)->hfont)
-    SelectObject (s->hdc, old_font);
 }
 
 
@@ -2844,8 +2269,10 @@ x_draw_glyph_string (s)
       x_set_glyph_string_clipping (s);
       relief_drawn_p = 1;
     }
-  else if ((s->prev && s->prev->hl != s->hl && s->left_overhang)
-          || (s->next && s->next->hl != s->hl && s->right_overhang))
+  else if (!s->clip_head /* draw_glyphs didn't specify a clip mask.  */
+           && !s->clip_tail
+           && ((s->prev && s->prev->hl != s->hl && s->left_overhang)
+               || (s->next && s->next->hl != s->hl && s->right_overhang)))
     /* We must clip just this glyph.  left_overhang part has already
        drawn when s->prev was drawn, and right_overhang part will be
        drawn later when s->next is drawn. */
@@ -2872,7 +2299,8 @@ x_draw_glyph_string (s)
       break;
 
     case COMPOSITE_GLYPH:
-      if (s->for_overlaps || s->gidx > 0)
+      if (s->for_overlaps || (s->cmp_from > 0
+                             && ! s->first_glyph->u.cmp.automatic))
        s->background_filled_p = 1;
       else
        x_draw_glyph_string_background (s, 1);
@@ -2905,7 +2333,7 @@ x_draw_glyph_string (s)
               else
                 thickness = 1;
               if (x_underline_at_descent_line)
-                position = (s->height - thickness) - s->ybase;
+                position = (s->height - thickness) - (s->ybase - s->y);
               else
                 {
                 /* Get the underline position.  This is the recommended
@@ -2922,9 +2350,16 @@ x_draw_glyph_string (s)
                 else if (s->font)
                   position = (s->font->descent + 1) / 2;
                 }
-              s->underline_thickness = thickness;
-              s->underline_position =position;
+             position = max (position, underline_minimum_offset);
             }
+         /* Check the sanity of thickness and position.  We should
+            avoid drawing underline out of the current line area.  */
+         if (s->y + s->height <= s->ybase + position)
+           position = (s->height - 1) - (s->ybase - s->y);
+         if (s->y + s->height < s->ybase + position + thickness)
+           thickness = (s->y + s->height) - (s->ybase + position);
+         s->underline_thickness = thickness;
+         s->underline_position =position;
           y = s->ybase + position;
           if (s->face->underline_defaulted_p)
             {
@@ -2956,8 +2391,7 @@ x_draw_glyph_string (s)
 
       /* Draw strike-through.  */
       if (s->face->strike_through_p
-          && (FONT_COMPAT (s->font)->bdf
-             || !FONT_COMPAT (s->font)->tm.tmStruckOut))
+          && !FONT_TEXTMETRIC(s->font).tmStruckOut)
         {
           unsigned long h = 1;
           unsigned long dy = (s->height - h) / 2;
@@ -3245,6 +2679,7 @@ frame_highlight (f)
      struct frame *f;
 {
   x_update_cursor (f, 1);
+  x_set_frame_alpha (f);
 }
 
 static void
@@ -3252,6 +2687,7 @@ frame_unhighlight (f)
      struct frame *f;
 {
   x_update_cursor (f, 1);
+  x_set_frame_alpha (f);
 }
 
 /* The focus has changed.  Update the frames as necessary to reflect
@@ -4819,7 +4255,7 @@ w32_read_socket (sd, expected, hold_quit)
              inev.timestamp = msg.msg.time;
            }
          break;
-          
+
        case WM_MOUSEMOVE:
          /* Ignore non-movement.  */
          {
@@ -5266,11 +4702,10 @@ w32_read_socket (sd, expected, hold_quit)
 
          if (f)
            {
-             dpyinfo->width = (short) LOWORD (msg.msg.lParam);
-             dpyinfo->height = (short) HIWORD (msg.msg.lParam);
              dpyinfo->n_cbits = msg.msg.wParam;
-             DebPrint (("display change: %d %d\n", dpyinfo->width,
-                        dpyinfo->height));
+             DebPrint (("display change: %d %d\n",
+                        (short) LOWORD (msg.msg.lParam),
+                        (short) HIWORD (msg.msg.lParam)));
            }
 
          check_visibility = 1;
@@ -5552,7 +4987,8 @@ x_draw_bar_cursor (w, row, width, kind)
          w32_fill_area (f, hdc, cursor_color, x,
                         WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y +
                                                  row->height - width),
-                        cursor_glyph->pixel_width, width);
+                        min (FRAME_COLUMN_WIDTH (f), cursor_glyph->pixel_width),
+                        width);
        }
 
       w32_set_clip_rectangle (hdc, NULL);
@@ -5775,109 +5211,6 @@ x_io_error_quitter (display)
 \f
 /* 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.
-   The return value shows which font we chose.  */
-
-Lisp_Object
-x_new_font (f, fontname)
-     struct frame *f;
-     register char *fontname;
-{
-  struct font_info *fontp
-    = FS_LOAD_FONT (f, fontname);
-
-  if (!fontp)
-    return Qnil;
-
-  if (FRAME_FONT (f) == (XFontStruct *) (fontp->font))
-    /* This font is already set in frame F.  There's nothing more to
-       do.  */
-    return build_string (fontp->full_name);
-
-  FRAME_FONT (f) = (XFontStruct *) (fontp->font);
-  FRAME_BASELINE_OFFSET (f) = fontp->baseline_offset;
-  FRAME_FONTSET (f) = -1;
-
-  FRAME_COLUMN_WIDTH (f) = fontp->average_width;
-  FRAME_SPACE_WIDTH (f) = fontp->space_width;
-  FRAME_LINE_HEIGHT (f) = FONT_HEIGHT (FRAME_FONT (f));
-
-  compute_fringe_widths (f, 1);
-
-  /* Compute the scroll bar width in character columns.  */
-  if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0)
-    {
-      int wid = FRAME_COLUMN_WIDTH (f);
-      FRAME_CONFIG_SCROLL_BAR_COLS (f)
-       = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) + wid-1) / wid;
-    }
-  else
-    {
-      int wid = FRAME_COLUMN_WIDTH (f);
-      FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid;
-    }
-
-  /* Now make the frame display the given font.  */
-  if (FRAME_W32_WINDOW (f) != 0)
-    {
-      if (NILP (tip_frame) || XFRAME (tip_frame) != f)
-        x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
-    }
-
-  return build_string (fontp->full_name);
-}
-\f
-/* Give frame F the fontset named FONTSETNAME as its default fontset,
-   and return the full name of that fontset.  FONTSETNAME may be a
-   wildcard pattern; in that case, we choose some fontset that fits
-   the pattern.  FONTSETNAME may be a font name for ASCII characters;
-   in that case, we create a fontset from that font name.
-
-   The return value shows which fontset we chose.
-   If FONTSETNAME specifies the default fontset, return Qt.
-   If an ASCII font in the specified fontset can't be loaded, return
-   Qnil.  */
-
-Lisp_Object
-x_new_fontset (f, fontsetname)
-     struct frame *f;
-     Lisp_Object fontsetname;
-{
-  int fontset = fs_query_fontset (fontsetname, 0);
-  Lisp_Object result;
-
-  if (fontset > 0 && FRAME_FONTSET(f) == fontset)
-    /* This fontset is already set in frame F.  There's nothing more
-       to do.  */
-    return fontset_name (fontset);
-  else if (fontset == 0)
-    /* The default fontset can't be the default font.   */
-    return Qt;
-
-  if (fontset > 0)
-    result = x_new_font (f, (SDATA (fontset_ascii (fontset))));
-  else
-    result = x_new_font (f, SDATA (fontsetname));
-
-  if (!STRINGP (result))
-    /* Can't load ASCII font.  */
-    return Qnil;
-
-  if (fontset < 0)
-    fontset = new_fontset_from_font_name (result);
-
-  /* Since x_new_font doesn't update any fontset information, do it now.  */
-  FRAME_FONTSET(f) = fontset;
-
-  return fontset_name (fontset);
-}
-#endif /* OLD_FONT */
-
-
 Lisp_Object
 x_new_font (f, font_object, fontset)
      struct frame *f;
@@ -5996,13 +5329,13 @@ x_calc_absolute_position (f)
   /* Treat negative positions as relative to the rightmost bottommost
      position that fits on the screen.  */
   if (flags & XNegative)
-    f->left_pos = (FRAME_W32_DISPLAY_INFO (f)->width
+    f->left_pos = (x_display_pixel_width (FRAME_W32_DISPLAY_INFO (f))
                   - FRAME_PIXEL_WIDTH (f)
                   + f->left_pos
                   - (left_right_borders_width - 1));
 
   if (flags & YNegative)
-    f->top_pos = (FRAME_W32_DISPLAY_INFO (f)->height
+    f->top_pos = (x_display_pixel_height (FRAME_W32_DISPLAY_INFO (f))
                  - FRAME_PIXEL_HEIGHT (f)
                  + f->top_pos
                  - (top_bottom_borders_height - 1));
@@ -6133,7 +5466,7 @@ x_set_window_size (f, change_gravity, cols, rows)
      resize will happen asynchronously. But on Windows, the menu bar
      automatically wraps when the frame is too narrow to contain it,
      and that causes any calculations made here to come out wrong. The
-     end is some nasty buggy behaviour, including the potential loss
+     end is some nasty buggy behavior, including the potential loss
      of the minibuffer.
 
      Disabling this code is either not sufficient to fix the problems
@@ -6256,9 +5589,9 @@ x_raise_frame (f)
   BLOCK_INPUT;
 
   /* Strictly speaking, raise-frame should only change the frame's Z
-     order, leaving input focus unchanged.  This is reasonable behaviour
+     order, leaving input focus unchanged.  This is reasonable behavior
      on X where the usual policy is point-to-focus.  However, this
-     behaviour would be very odd on Windows where the usual policy is
+     behavior would be very odd on Windows where the usual policy is
      click-to-focus.
 
      On X, if the mouse happens to be over the raised frame, it gets
@@ -6383,8 +5716,15 @@ x_make_frame_visible (f)
 
       f->output_data.w32->asked_for_visible = 1;
 
-/*      my_show_window (f, FRAME_W32_WINDOW (f), f->async_iconified ? SW_RESTORE : SW_SHOW);  */
-      my_show_window (f, FRAME_W32_WINDOW (f), SW_SHOWNORMAL);
+      /* The first of these seems to give more expected behavior, but
+         was added as a commented out line in Sept 1997, with the
+         second version remaining uncommented. There may have been
+         some problem with it that led to it not being enabled,
+         so the old version remains commented out below in case we
+         decide we need to go back to it [23.0.60 2008-06-09].  */
+      my_show_window (f, FRAME_W32_WINDOW (f),
+                      f->async_iconified ? SW_RESTORE : SW_SHOW);
+      /* my_show_window (f, FRAME_W32_WINDOW (f), SW_SHOWNORMAL);  */
     }
 
   /* Synchronize to ensure Emacs knows the frame is visible
@@ -6598,118 +5938,6 @@ x_wm_set_icon_position (f, icon_x, icon_y)
 }
 
 \f
-/***********************************************************************
-                               Fonts
- ***********************************************************************/
-
-#if OLD_FONT
-
-/* The following functions are listed here to help diff stay in step
-   with xterm.c.  See w32fns.c for definitions.
-
-x_get_font_info (f, font_idx)
-x_list_fonts (f, pattern, size, maxnames)
-
- */
-
-#if GLYPH_DEBUG
-
-/* Check that FONT is valid on frame F.  It is if it can be found in F's
-   font table.  */
-
-static void
-x_check_font (f, font)
-     struct frame *f;
-     XFontStruct *font;
-{
-  int i;
-  struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
-
-  xassert (font != NULL);
-
-  for (i = 0; i < dpyinfo->n_fonts; i++)
-    if (dpyinfo->font_table[i].name
-       && font == dpyinfo->font_table[i].font)
-      break;
-
-  xassert (i < dpyinfo->n_fonts);
-}
-
-#endif /* GLYPH_DEBUG != 0 */
-
-/* Set *W to the minimum width, *H to the minimum font height of FONT.
-   Note: There are (broken) X fonts out there with invalid XFontStruct
-   min_bounds contents.  For example, handa@etl.go.jp reports that
-   "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
-   have font->min_bounds.width == 0.  */
-
-static INLINE void
-x_font_min_bounds (font, w, h)
-     XFontStruct *font;
-     int *w, *h;
-{
-  /*
-   * TODO: Windows does not appear to offer min bound, only
-   * average and maximum width, and maximum height.
-   */
-  *h = FONT_HEIGHT (font);
-  *w = FONT_AVG_WIDTH (font);
-}
-
-
-/* Compute the smallest character width and smallest font height over
-   all fonts available on frame F.  Set the members smallest_char_width
-   and smallest_font_height in F's x_display_info structure to
-   the values computed.  Value is non-zero if smallest_font_height or
-   smallest_char_width become smaller than they were before.  */
-
-int
-x_compute_min_glyph_bounds (f)
-     struct frame *f;
-{
-  int i;
-  struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
-  XFontStruct *font;
-  int old_width = dpyinfo->smallest_char_width;
-  int old_height = dpyinfo->smallest_font_height;
-
-  dpyinfo->smallest_font_height = 100000;
-  dpyinfo->smallest_char_width = 100000;
-
-  for (i = 0; i < dpyinfo->n_fonts; ++i)
-    if (dpyinfo->font_table[i].name)
-      {
-       struct font_info *fontp = dpyinfo->font_table + i;
-       int w, h;
-
-       font = (XFontStruct *) fontp->font;
-       xassert (font != (XFontStruct *) ~0);
-       x_font_min_bounds (font, &w, &h);
-
-       dpyinfo->smallest_font_height = min (dpyinfo->smallest_font_height, h);
-       dpyinfo->smallest_char_width = min (dpyinfo->smallest_char_width, w);
-      }
-
-  xassert (dpyinfo->smallest_char_width > 0
-          && dpyinfo->smallest_font_height > 0);
-
-  return (dpyinfo->n_fonts == 1
-         || dpyinfo->smallest_char_width < old_width
-         || dpyinfo->smallest_font_height < old_height);
-}
-
-/* The following functions are listed here to help diff stay in step
-   with xterm.c.  See w32fns.c for definitions.
-
-x_load_font (f, fontname, size)
-x_query_font (f, fontname)
-x_find_ccl_program (fontp)
-
-*/
-
-#endif /* OLD_FONT */
-
-\f
 /***********************************************************************
                            Initialization
  ***********************************************************************/
@@ -6740,8 +5968,6 @@ w32_initialize_display_info (display_name)
      with values obtained from system metrics.  */
   dpyinfo->resx = 1;
   dpyinfo->resy = 1;
-  dpyinfo->height_in = 1;
-  dpyinfo->width_in = 1;
   dpyinfo->n_planes = 1;
   dpyinfo->n_cbits = 4;
   dpyinfo->n_fonts = 0;
@@ -6837,15 +6063,11 @@ static struct redisplay_interface w32_redisplay_interface =
   x_flush,
   0,  /* flush_display_optional */
   x_clear_window_mouse_face,
-  w32_get_glyph_overhangs,
+  x_get_glyph_overhangs,
   x_fix_overlapping_area,
   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,
@@ -6901,7 +6123,6 @@ w32_create_terminal (struct w32_display_info *dpyinfo)
   terminal->memory_below_frame = 0;   /* We don't remember what scrolls
                                         off the bottom. */
 
-#ifdef MULTI_KBOARD
   /* We don't yet support separate terminals on W32, so don't try to share
      keyboards between virtual terminals that are on the same physical
      terminal like X does.  */
@@ -6916,7 +6137,6 @@ w32_create_terminal (struct w32_display_info *dpyinfo)
   if (current_kboard == initial_kboard)
     current_kboard = terminal->kboard;
   terminal->kboard->reference_count++;
-#endif
 
   return terminal;
 }
@@ -6933,14 +6153,6 @@ x_delete_terminal (struct terminal *terminal)
     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;
@@ -6982,8 +6194,6 @@ w32_term_init (display_name, xrm_option, resource_name)
 
   hdc = GetDC (GetDesktopWindow ());
 
-  dpyinfo->height = GetDeviceCaps (hdc, VERTRES);
-  dpyinfo->width = GetDeviceCaps (hdc, HORZRES);
   dpyinfo->root_window = GetDesktopWindow ();
   dpyinfo->n_planes = GetDeviceCaps (hdc, PLANES);
   dpyinfo->n_cbits = GetDeviceCaps (hdc, BITSPIXEL);
@@ -6991,8 +6201,6 @@ w32_term_init (display_name, xrm_option, resource_name)
   dpyinfo->resy = GetDeviceCaps (hdc, LOGPIXELSY);
   dpyinfo->has_palette = GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE;
   dpyinfo->terminal->image_cache = make_image_cache ();
-  dpyinfo->height_in = dpyinfo->height / dpyinfo->resx;
-  dpyinfo->width_in = dpyinfo->width / dpyinfo->resy;
   ReleaseDC (GetDesktopWindow (), hdc);
 
   /* initialise palette with white and black */
@@ -7069,9 +6277,6 @@ x_delete_display (dpyinfo)
     if (dpyinfo->palette)
       DeleteObject(dpyinfo->palette);
   }
-#if OLD_FONT
-  xfree (dpyinfo->font_table);
-#endif
   xfree (dpyinfo->w32_id_name);
 
   w32_reset_fringes ();
@@ -7133,25 +6338,22 @@ w32_initialize ()
      program.  Unfortunately, we have good reasons for doing that, so
      instead we need to send messages to windowsThread to make some API
      calls for us (ones that affect, or depend on, the active/focus
-     window state.  */
+     window state.)  */
 #ifdef ATTACH_THREADS
   AttachThreadInput (dwMainThreadId, dwWindowsThreadId, TRUE);
 #endif
 
   /* Dynamically link to optional system components.  */
   {
-    UINT smoothing_type;
-    BOOL smoothing_enabled;
-
-    HANDLE gdi_lib = LoadLibrary ("gdi32.dll");
+    HANDLE user_lib = LoadLibrary ("user32.dll");
 
 #define LOAD_PROC(lib, fn) pfn##fn = (void *) GetProcAddress (lib, #fn)
 
-    LOAD_PROC (gdi_lib, GetFontUnicodeRanges);
-    
+    LOAD_PROC (user_lib, SetLayeredWindowAttributes);
+
 #undef LOAD_PROC
 
-    FreeLibrary (gdi_lib);
+    FreeLibrary (user_lib);
 
     /* Ensure scrollbar handle is at least 5 pixels.  */
     vertical_scroll_bar_min_handle = 5;
@@ -7160,28 +6362,6 @@ w32_initialize ()
        effectively form the border of the main scroll bar range.  */
     vertical_scroll_bar_top_border = vertical_scroll_bar_bottom_border
       = GetSystemMetrics (SM_CYVSCROLL);
-
-    /* Constants that are not always defined by the system headers
-       since they only exist on certain versions of Windows.  */
-#ifndef SPI_GETFONTSMOOTHING
-#define SPI_GETFONTSMOOTHING 0x4A
-#endif
-#ifndef SPI_GETFONTSMOOTHINGTYPE
-#define SPI_GETFONTSMOOTHINGTYPE 0x0200A
-#endif
-#ifndef FE_FONTSMOOTHINGCLEARTYPE
-#define FE_FONTSMOOTHINGCLEARTYPE 0x2
-#endif
-
-    /* Determine if Cleartype is in use.  Used to enable a hack in
-       the char metric calculations which adds extra pixels to
-       compensate for the "sub-pixels" that are not counted by the
-       system APIs. */
-    cleartype_active =
-      SystemParametersInfo (SPI_GETFONTSMOOTHING, 0, &smoothing_enabled, 0)
-      && smoothing_enabled
-      && SystemParametersInfo (SPI_GETFONTSMOOTHINGTYPE, 0, &smoothing_type, 0)
-      && smoothing_type == FE_FONTSMOOTHINGCLEARTYPE;
   }
 }
 
@@ -7228,15 +6408,6 @@ When nil, the right-alt and left-ctrl key combination is
 interpreted normally.  */);
   Vw32_recognize_altgr = Qt;
 
-  DEFVAR_BOOL ("w32-enable-unicode-output",
-               &w32_enable_unicode_output,
-               doc: /* Enable the use of Unicode for text output if non-nil.
-Unicode output may prevent some third party applications for displaying
-Far-East Languages on Windows 95/98 from working properly.
-NT uses Unicode internally anyway, so this flag will probably have no
-effect on NT machines.  */);
-  w32_enable_unicode_output = 1;
-
   DEFVAR_BOOL ("w32-use-visible-system-caret",
               &w32_use_visible_system_caret,
               doc: /* Flag to make the system caret visible.