+#ifdef GDK_WINDOWING_WIN32
+
+static gint num_fonts;
+static gint font_names_size;
+static gchar **xfontnames;
+static HDC hdc;
+
+static char *
+logfont_to_xlfd (const LOGFONT *lfp,
+ int size,
+ int res,
+ int avg_width)
+{
+ const gchar *weight;
+ const gchar *registry, *encoding;
+ int point_size;
+ static int logpixelsy = 0;
+ gchar facename[LF_FACESIZE*3];
+ gchar *p;
+ const gchar *q;
+
+ if (logpixelsy == 0)
+ {
+ HDC hdc = GetDC (NULL);
+ logpixelsy = GetDeviceCaps (hdc, LOGPIXELSY);
+ ReleaseDC (NULL, hdc);
+ }
+
+ /* Don't use _() here, only N_(), the actual translation is done elsewhere */
+ if (lfp->lfWeight >= FW_HEAVY)
+ weight = N_("heavy");
+ else if (lfp->lfWeight >= FW_EXTRABOLD)
+ weight = N_("extrabold");
+ else if (lfp->lfWeight >= FW_BOLD)
+ weight = N_("bold");
+#ifdef FW_DEMIBOLD
+ else if (lfp->lfWeight >= FW_DEMIBOLD)
+ weight = N_("demibold");
+#endif
+ else if (lfp->lfWeight >= FW_MEDIUM)
+ weight = N_("medium");
+ else if (lfp->lfWeight >= FW_NORMAL)
+ weight = N_("normal");
+ else if (lfp->lfWeight >= FW_LIGHT)
+ weight = N_("light");
+ else if (lfp->lfWeight >= FW_EXTRALIGHT)
+ weight = N_("extralight");
+ else if (lfp->lfWeight >= FW_THIN)
+ weight = N_("thin");
+ else
+ weight = N_("regular");
+
+ if (lfp->lfCharSet == ANSI_CHARSET)
+ {
+ registry = "iso8859";
+ encoding = "1";
+ }
+ else
+ {
+ registry = "windows";
+ if (lfp->lfCharSet == DEFAULT_CHARSET)
+ encoding = "default";
+ else if (lfp->lfCharSet == SYMBOL_CHARSET)
+ encoding = "symbol";
+ else if (lfp->lfCharSet == SHIFTJIS_CHARSET)
+ encoding = "shiftjis";
+ else if (lfp->lfCharSet == GB2312_CHARSET)
+ encoding = "gb2312";
+ else if (lfp->lfCharSet == HANGEUL_CHARSET)
+ encoding = "hangeul";
+ else if (lfp->lfCharSet == CHINESEBIG5_CHARSET)
+ encoding = "chinesebig5";
+ else if (lfp->lfCharSet == OEM_CHARSET)
+ encoding = "oem";
+#ifdef JOHAB_CHARSET
+ else if (lfp->lfCharSet == JOHAB_CHARSET)
+ encoding = "johab";
+#endif
+ else if (lfp->lfCharSet == HEBREW_CHARSET)
+ encoding = "hebrew";
+ else if (lfp->lfCharSet == ARABIC_CHARSET)
+ encoding = "arabic";
+ else if (lfp->lfCharSet == GREEK_CHARSET)
+ encoding = "greek";
+ else if (lfp->lfCharSet == TURKISH_CHARSET)
+ encoding = "turkish";
+ else if (lfp->lfCharSet == THAI_CHARSET)
+ encoding = "thai";
+ else if (lfp->lfCharSet == EASTEUROPE_CHARSET)
+ encoding = "easteurope";
+ else if (lfp->lfCharSet == RUSSIAN_CHARSET)
+ encoding = "russian";
+ else if (lfp->lfCharSet == MAC_CHARSET)
+ encoding = "mac";
+ else if (lfp->lfCharSet == BALTIC_CHARSET)
+ encoding = "baltic";
+ else
+ encoding = "unknown";
+ }
+
+ point_size = (int) (((double) size/logpixelsy) * 720.);
+
+ if (res == -1)
+ res = logpixelsy;
+
+ /* Replace illegal characters with hex escapes. */
+ p = facename;
+ q = lfp->lfFaceName;
+ while (*q)
+ {
+ if (*q == '-' || *q == '*' || *q == '?' || *q == '%')
+ p += sprintf (p, "%%%.02x", *q);
+ else
+ *p++ = *q;
+ q++;
+ }
+ *p = '\0';
+
+ return g_strdup_printf
+ ("-%s-%s-%s-%s-%s-%s-%d-%d-%d-%d-%s-%d-%s-%s",
+ "unknown",
+ facename,
+ weight,
+ (lfp->lfItalic ?
+ ((lfp->lfPitchAndFamily & 0xF0) == FF_ROMAN
+ || (lfp->lfPitchAndFamily & 0xF0) == FF_SCRIPT ?
+ "i" : "o") : "r"),
+ "normal",
+ "",
+ size,
+ point_size,
+ res,
+ res,
+ ((lfp->lfPitchAndFamily & 0x03) == FIXED_PITCH ? "m" : "p"),
+ avg_width,
+ registry, encoding);
+}
+
+int CALLBACK
+InnerEnumFontFamExProc (const LOGFONT *lfp,
+ const TEXTMETRIC *metrics,
+ DWORD fontType,
+ LPARAM lParam)
+{
+ int size;
+
+ if (fontType == TRUETYPE_FONTTYPE)
+ {
+ size = 0;
+ }
+ else
+ {
+ size = lfp->lfHeight;
+ }
+
+ num_fonts++;
+ if (num_fonts == font_names_size)
+ {
+ font_names_size *= 2;
+ xfontnames = g_realloc (xfontnames, font_names_size * sizeof (gchar *));
+ }
+ xfontnames[num_fonts-1] =
+ logfont_to_xlfd (lfp, size, 0, 0);
+ return 1;
+}
+
+int CALLBACK
+EnumFontFamExProc (const LOGFONT *lfp,
+ const TEXTMETRIC *metrics,
+ DWORD fontType,
+ LPARAM lParam)
+{
+ if (fontType == TRUETYPE_FONTTYPE)
+ {
+ LOGFONT lf = *lfp;
+ lf.lfPitchAndFamily = 0;
+ EnumFontFamiliesEx (hdc, &lf, InnerEnumFontFamExProc, 0, 0);
+ }
+ else
+ InnerEnumFontFamExProc (lfp, metrics, fontType, lParam);
+ return 1;
+}
+
+#endif
+