diff src/objects-msw.c @ 276:6330739388db r21-0b36

Import from CVS: tag r21-0b36
author cvs
date Mon, 13 Aug 2007 10:30:37 +0200
parents c5d627a313b1
children 7df0dd720c89
line wrap: on
line diff
--- a/src/objects-msw.c	Mon Aug 13 10:29:43 2007 +0200
+++ b/src/objects-msw.c	Mon Aug 13 10:30:37 2007 +0200
@@ -1050,36 +1050,33 @@
     return 0;
   }
 
-  /* Have to apply Font to a GC to get its values.
-   * We'll borrow the desktop window becuase its the only window that we
-   * know about that is guaranteed to exist when this gets called
-   */ 
   {
-    HWND hwnd;
     HDC hdc;
     HFONT holdfont;
     TEXTMETRIC metrics;
 
-    hwnd = GetDesktopWindow();
-    assert(hdc = GetDC(hwnd));	/* XXX FIXME: can this temporarily fail? */
-    holdfont = SelectObject(hdc, f->data);
-    if (!holdfont)
-    {
-      mswindows_finalize_font_instance (f);
-      maybe_signal_simple_error ("Couldn't map font", f->name, Qfont, errb);
-      return 0;
-    }
-    GetTextMetrics(hdc, &metrics);
-    SelectObject(hdc, holdfont);
-    ReleaseDC(hwnd, hdc);
-    f->width = (unsigned short) metrics.tmAveCharWidth;
-    f->height = (unsigned short) metrics.tmHeight;
-    f->ascent = (unsigned short) metrics.tmAscent;
-    f->descent = (unsigned short) metrics.tmDescent;
-    f->proportional_p = (metrics.tmPitchAndFamily & TMPF_FIXED_PITCH);
+    hdc = CreateCompatibleDC (NULL);
+    if (hdc)
+      {
+	holdfont = SelectObject(hdc, f->data);
+	if (holdfont)
+	  {
+	    GetTextMetrics (hdc, &metrics);
+	    SelectObject(hdc, holdfont);
+	    DeleteDC (hdc);
+	    f->width = (unsigned short) metrics.tmAveCharWidth;
+	    f->height = (unsigned short) metrics.tmHeight;
+	    f->ascent = (unsigned short) metrics.tmAscent;
+	    f->descent = (unsigned short) metrics.tmDescent;
+	    f->proportional_p = (metrics.tmPitchAndFamily & TMPF_FIXED_PITCH);
+	    return 1;
+	  }
+	DeleteDC (hdc);
+      }
+    mswindows_finalize_font_instance (f);
+    maybe_signal_simple_error ("Couldn't map font", f->name, Qfont, errb);
   }
-
-  return 1;
+  return 0;
 }
 
 #if 0