+
+
+
+\f
+/************************************************************************/
+/* exports */
+/************************************************************************/
+
+struct font_enum_t
+{
+ HDC hdc;
+ struct device *d;
+};
+
+static int CALLBACK
+font_enum_callback_2 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme,
+ int FontType, struct font_enum_t *font_enum)
+{
+ struct mswindows_font_enum *fontlist, **fonthead;
+ char fontname[MSW_FONTSIZE];
+ int i;
+
+ /*
+ * The enumerated font weights are not to be trusted because:
+ * a) lpelfe->elfStyle is only filled in for TrueType fonts.
+ * b) Not all Bold and Italic styles of all fonts (inluding some Vector,
+ * Truetype and Raster fonts) are enumerated.
+ * I guess that fonts for which Bold and Italic styles are generated
+ * 'on-the-fly' are not enumerated. It would be overly restrictive to
+ * disallow Bold And Italic weights for these fonts, so we just leave
+ * weights unspecified. This means that we have to weed out duplicates of
+ * those fonts that do get enumerated with different weights.
+ */
+ if (FontType == 0 /*vector*/ || FontType == TRUETYPE_FONTTYPE)
+ /* Scalable, so leave pointsize blank */
+ sprintf (fontname, "%s::::", lpelfe->elfLogFont.lfFaceName);
+ else
+ /* Formula for pointsize->height from LOGFONT docs in Platform SDK */
+ sprintf (fontname, "%s::%d::", lpelfe->elfLogFont.lfFaceName,
+ MulDiv (lpntme->ntmTm.tmHeight - lpntme->ntmTm.tmInternalLeading,
+ 72, DEVICE_MSWINDOWS_LOGPIXELSY (font_enum->d)));
+
+ /*
+ * The enumerated font character set strings are not to be trusted because
+ * lpelfe->elfScript is returned in the host language and not in English.
+ * We can't know a priori the translations of "Western", "Central European"
+ * etc into the host language, so we must use English. The same argument
+ * applies to the font weight string when matching fonts.
+ */
+ for (i=0; i<countof (charset_map); i++)
+ if (lpelfe->elfLogFont.lfCharSet == charset_map[i].value)
+ {
+ strcat (fontname, charset_map[i].name);
+ break;
+ }
+ if (i==countof (charset_map))
+ strcpy (fontname, charset_map[0].name);
+
+ /* Check that the new font is not a duplicate */
+ fonthead = &DEVICE_MSWINDOWS_FONTLIST (font_enum->d);
+ fontlist = *fonthead;
+ while (fontlist)
+ if (!strcmp (fontname, fontlist->fontname))
+ return 1; /* found a duplicate */
+ else
+ fontlist = fontlist->next;
+
+ /* Insert entry at head */
+ fontlist = *fonthead;
+ *fonthead = xmalloc (sizeof (struct mswindows_font_enum));
+ if (*fonthead == NULL)
+ {
+ *fonthead = fontlist;
+ return 0;
+ }
+ strcpy ((*fonthead)->fontname, fontname);
+ (*fonthead)->next = fontlist;
+ return 1;
+}
+
+static int CALLBACK
+font_enum_callback_1 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme,
+ int FontType, struct font_enum_t *font_enum)
+{
+ /* This function gets called once per facename per character set.
+ * We call a second callback to enumerate the fonts in each facename */
+ return EnumFontFamiliesEx (font_enum->hdc, &lpelfe->elfLogFont,
+ (FONTENUMPROC) font_enum_callback_2,
+ (LPARAM) font_enum, 0);
+}
+
+/*
+ * Enumerate the available fonts. Called by mswindows_init_device().
+ * Fills in the device's device-type-specfic fontlist.
+ */
+void
+mswindows_enumerate_fonts (struct device *d)
+{
+ HDC hdc = CreateCompatibleDC (NULL);
+ LOGFONT logfont;
+ struct font_enum_t font_enum;
+
+ assert (hdc!=NULL);
+ logfont.lfCharSet = DEFAULT_CHARSET;
+ logfont.lfFaceName[0] = '\0';
+ logfont.lfPitchAndFamily = DEFAULT_PITCH;
+ font_enum.hdc = hdc;
+ font_enum.d = d;
+ DEVICE_MSWINDOWS_FONTLIST (d) = NULL;
+ EnumFontFamiliesEx (hdc, &logfont, (FONTENUMPROC) font_enum_callback_1,
+ (LPARAM) (&font_enum), 0);
+ DeleteDC (hdc);
+}
+