+#ifdef WINDOWSNT
+
+static BOOL g_b_init_get_outline_metrics_w;
+static BOOL g_b_init_get_text_metrics_w;
+static BOOL g_b_init_get_glyph_outline_w;
+static BOOL g_b_init_get_glyph_outline_w;
+static BOOL g_b_init_get_char_width_32_w;
+
+typedef UINT (WINAPI * GetOutlineTextMetricsW_Proc) (
+ HDC hdc,
+ UINT cbData,
+ LPOUTLINETEXTMETRICW lpotmw);
+typedef BOOL (WINAPI * GetTextMetricsW_Proc) (
+ HDC hdc,
+ LPTEXTMETRICW lptmw);
+typedef DWORD (WINAPI * GetGlyphOutlineW_Proc) (
+ HDC hdc,
+ UINT uChar,
+ UINT uFormat,
+ LPGLYPHMETRICS lpgm,
+ DWORD cbBuffer,
+ LPVOID lpvBuffer,
+ const MAT2 *lpmat2);
+typedef BOOL (WINAPI * GetCharWidth32W_Proc) (
+ HDC hdc,
+ UINT uFirstChar,
+ UINT uLastChar,
+ LPINT lpBuffer);
+
+/* Several "wide" functions we use to support the font backends are
+ unavailable on Windows 9X, unless UNICOWS.DLL is installed (their
+ versions in the default libraries are non-functional stubs). On NT
+ and later systems, these functions are in GDI32.DLL. The following
+ helper function attempts to load UNICOWS.DLL on Windows 9X, and
+ refuses to let Emacs start up if that library is not found. On NT
+ and later versions, it simply loads GDI32.DLL, which should always
+ be available. */
+static HMODULE
+w32_load_unicows_or_gdi32 (void)
+{
+ return maybe_load_unicows_dll ();
+}
+
+/* The following 3 functions call the problematic "wide" APIs via
+ function pointers, to avoid linking against the non-standard
+ libunicows on W9X. */
+static UINT WINAPI
+get_outline_metrics_w(HDC hdc, UINT cbData, LPOUTLINETEXTMETRICW lpotmw)
+{
+ static GetOutlineTextMetricsW_Proc s_pfn_Get_Outline_Text_MetricsW = NULL;
+ HMODULE hm_unicows = NULL;
+ if (g_b_init_get_outline_metrics_w == 0)
+ {
+ g_b_init_get_outline_metrics_w = 1;
+ hm_unicows = w32_load_unicows_or_gdi32 ();
+ if (hm_unicows)
+ s_pfn_Get_Outline_Text_MetricsW = (GetOutlineTextMetricsW_Proc)
+ GetProcAddress (hm_unicows, "GetOutlineTextMetricsW");
+ }
+ eassert (s_pfn_Get_Outline_Text_MetricsW != NULL);
+ return s_pfn_Get_Outline_Text_MetricsW (hdc, cbData, lpotmw);
+}
+
+static BOOL WINAPI
+get_text_metrics_w(HDC hdc, LPTEXTMETRICW lptmw)
+{
+ static GetTextMetricsW_Proc s_pfn_Get_Text_MetricsW = NULL;
+ HMODULE hm_unicows = NULL;
+ if (g_b_init_get_text_metrics_w == 0)
+ {
+ g_b_init_get_text_metrics_w = 1;
+ hm_unicows = w32_load_unicows_or_gdi32 ();
+ if (hm_unicows)
+ s_pfn_Get_Text_MetricsW = (GetTextMetricsW_Proc)
+ GetProcAddress (hm_unicows, "GetTextMetricsW");
+ }
+ eassert (s_pfn_Get_Text_MetricsW != NULL);
+ return s_pfn_Get_Text_MetricsW (hdc, lptmw);
+}
+
+static DWORD WINAPI
+get_glyph_outline_w (HDC hdc, UINT uChar, UINT uFormat, LPGLYPHMETRICS lpgm,
+ DWORD cbBuffer, LPVOID lpvBuffer, const MAT2 *lpmat2)
+{
+ static GetGlyphOutlineW_Proc s_pfn_Get_Glyph_OutlineW = NULL;
+ HMODULE hm_unicows = NULL;
+ if (g_b_init_get_glyph_outline_w == 0)
+ {
+ g_b_init_get_glyph_outline_w = 1;
+ hm_unicows = w32_load_unicows_or_gdi32 ();
+ if (hm_unicows)
+ s_pfn_Get_Glyph_OutlineW = (GetGlyphOutlineW_Proc)
+ GetProcAddress (hm_unicows, "GetGlyphOutlineW");
+ }
+ eassert (s_pfn_Get_Glyph_OutlineW != NULL);
+ return s_pfn_Get_Glyph_OutlineW (hdc, uChar, uFormat, lpgm, cbBuffer,
+ lpvBuffer, lpmat2);
+}
+
+static DWORD WINAPI
+get_char_width_32_w (HDC hdc, UINT uFirstChar, UINT uLastChar, LPINT lpBuffer)
+{
+ static GetCharWidth32W_Proc s_pfn_Get_Char_Width_32W = NULL;
+ HMODULE hm_unicows = NULL;
+ if (g_b_init_get_char_width_32_w == 0)
+ {
+ g_b_init_get_char_width_32_w = 1;
+ hm_unicows = w32_load_unicows_or_gdi32 ();
+ if (hm_unicows)
+ s_pfn_Get_Char_Width_32W = (GetCharWidth32W_Proc)
+ GetProcAddress (hm_unicows, "GetCharWidth32W");
+ }
+ eassert (s_pfn_Get_Char_Width_32W != NULL);
+ return s_pfn_Get_Char_Width_32W (hdc, uFirstChar, uLastChar, lpBuffer);
+}
+
+#else /* Cygwin */
+
+/* Cygwin doesn't support Windows 9X, and links against GDI32.DLL, so
+ it can just call these functions directly. */
+#define get_outline_metrics_w(h,d,o) GetOutlineTextMetricsW(h,d,o)
+#define get_text_metrics_w(h,t) GetTextMetricsW(h,t)
+#define get_glyph_outline_w(h,uc,f,gm,b,v,m) \
+ GetGlyphOutlineW(h,uc,f,gm,b,v,m)
+#define get_char_width_32_w(h,fc,lc,b) GetCharWidth32W(h,fc,lc,b)
+
+#endif /* Cygwin */