comparison src/objects-msw.c @ 373:6240c7796c7a r21-2b2

Import from CVS: tag r21-2b2
author cvs
date Mon, 13 Aug 2007 11:04:06 +0200
parents cc15677e0335
children 8626e4521993
comparison
equal deleted inserted replaced
372:49e1ed2d7ed8 373:6240c7796c7a
49 #include "device.h" 49 #include "device.h"
50 #include "insdel.h" 50 #include "insdel.h"
51 51
52 #ifdef __CYGWIN32__ 52 #ifdef __CYGWIN32__
53 #define stricmp strcasecmp 53 #define stricmp strcasecmp
54 #define FONTENUMPROC FONTENUMEXPROC
55 #define ntmTm ntmentm
54 #endif 56 #endif
55 57
56 typedef struct colormap_t 58 typedef struct colormap_t
57 { 59 {
58 char *name; 60 CONST char *name;
59 COLORREF colorref; 61 CONST COLORREF colorref;
60 } colormap_t; 62 } colormap_t;
61 63
62 /* Colors from X11R6 "XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp" */ 64 /* Colors from X11R6 "XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp" */
63 static CONST colormap_t mswindows_X_color_map[] = 65 static CONST colormap_t mswindows_X_color_map[] =
64 { 66 {
719 {"DarkMagenta" , PALETTERGB (139, 0, 139) }, 721 {"DarkMagenta" , PALETTERGB (139, 0, 139) },
720 {"DarkRed" , PALETTERGB (139, 0, 0) }, 722 {"DarkRed" , PALETTERGB (139, 0, 0) },
721 {"LightGreen" , PALETTERGB (144, 238, 144) } 723 {"LightGreen" , PALETTERGB (144, 238, 144) }
722 }; 724 };
723 725
726
727 typedef struct fontmap_t
728 {
729 CONST char *name;
730 CONST int value;
731 } fontmap_t;
732
733 /* Default weight first, preferred names listed before synonyms */
734 static CONST fontmap_t fontweight_map[] =
735 {
736 {"Regular" , FW_REGULAR}, /* The standard font weight */
737 {"Thin" , FW_THIN},
738 {"Extra Light" , FW_EXTRALIGHT},
739 {"Ultra Light" , FW_ULTRALIGHT},
740 {"Light" , FW_LIGHT},
741 {"Normal" , FW_NORMAL},
742 {"Medium" , FW_MEDIUM},
743 {"Semi Bold" , FW_SEMIBOLD},
744 {"Demi Bold" , FW_DEMIBOLD},
745 {"Bold" , FW_BOLD}, /* The standard bold font weight */
746 {"Extra Bold" , FW_EXTRABOLD},
747 {"Ultra Bold" , FW_ULTRABOLD},
748 {"Heavy" , FW_HEAVY},
749 {"Black" , FW_BLACK}
750 };
751
752 /* Default charset first, no synonyms allowed because these names are
753 * matched against the names reported by win32 by match_font() */
754 static CONST fontmap_t charset_map[] =
755 {
756 {"Western" , ANSI_CHARSET},
757 {"Symbol" , SYMBOL_CHARSET},
758 {"Shift JIS" , SHIFTJIS_CHARSET}, /* #### Name to be verified */
759 {"GB2312" , GB2312_CHARSET}, /* #### Name to be verified */
760 {"Hanguel" , HANGEUL_CHARSET},
761 {"Chinese Big 5" , CHINESEBIG5_CHARSET}, /* #### Name to be verified */
762 #if (WINVER >= 0x0400)
763 {"Johab" , JOHAB_CHARSET}, /* #### Name to be verified */
764 {"Hebrew" , HEBREW_CHARSET}, /* #### Name to be verified */
765 {"Arabic" , ARABIC_CHARSET}, /* #### Name to be verified */
766 {"Greek" , GREEK_CHARSET},
767 {"Turkish" , TURKISH_CHARSET},
768 {"Vietnamese" , VIETNAMESE_CHARSET}, /* #### Name to be verified */
769 {"Thai" , THAI_CHARSET}, /* #### Name to be verified */
770 {"Central European" , EASTEUROPE_CHARSET},
771 {"Cyrillic" , RUSSIAN_CHARSET},
772 {"Mac" , MAC_CHARSET},
773 {"Baltic" , BALTIC_CHARSET},
774 #endif
775 {"OEM/DOS" , OEM_CHARSET}
776 };
777
724 778
725 /************************************************************************/ 779 /************************************************************************/
726 /* helpers */ 780 /* helpers */
727 /************************************************************************/ 781 /************************************************************************/
728 782
870 if (fontname) 924 if (fontname)
871 fontname[strlen (fontname) - 1] = '\0'; /* Trim trailing ':' */ 925 fontname[strlen (fontname) - 1] = '\0'; /* Trim trailing ':' */
872 return 1; 926 return 1;
873 } 927 }
874 928
929
930
931
932
933 /************************************************************************/
934 /* exports */
935 /************************************************************************/
936
937 struct font_enum_t
938 {
939 HDC hdc;
940 struct device *d;
941 };
942
943 static int CALLBACK
944 font_enum_callback_2 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme,
945 int FontType, struct font_enum_t *font_enum)
946 {
947 struct mswindows_font_enum *fontlist, **fonthead;
948 char fontname[MSW_FONTSIZE];
949 int i;
950
951 /*
952 * The enumerated font weights are not to be trusted because:
953 * a) lpelfe->elfStyle is only filled in for TrueType fonts.
954 * b) Not all Bold and Italic styles of all fonts (inluding some Vector,
955 * Truetype and Raster fonts) are enumerated.
956 * I guess that fonts for which Bold and Italic styles are generated
957 * 'on-the-fly' are not enumerated. It would be overly restrictive to
958 * disallow Bold And Italic weights for these fonts, so we just leave
959 * weights unspecified. This means that we have to weed out duplicates of
960 * those fonts that do get enumerated with different weights.
961 */
962 if (FontType == 0 /*vector*/ || FontType == TRUETYPE_FONTTYPE)
963 /* Scalable, so leave pointsize blank */
964 sprintf (fontname, "%s::::", lpelfe->elfLogFont.lfFaceName);
965 else
966 /* Formula for pointsize->height from LOGFONT docs in Platform SDK */
967 sprintf (fontname, "%s::%d::", lpelfe->elfLogFont.lfFaceName,
968 MulDiv (lpntme->ntmTm.tmHeight - lpntme->ntmTm.tmInternalLeading,
969 72, DEVICE_MSWINDOWS_LOGPIXELSY (font_enum->d)));
970
971 /*
972 * The enumerated font character set strings are not to be trusted because
973 * lpelfe->elfScript is returned in the host language and not in English.
974 * We can't know a priori the translations of "Western", "Central European"
975 * etc into the host language, so we must use English. The same argument
976 * applies to the font weight string when matching fonts.
977 */
978 for (i=0; i<countof (charset_map); i++)
979 if (lpelfe->elfLogFont.lfCharSet == charset_map[i].value)
980 {
981 strcat (fontname, charset_map[i].name);
982 break;
983 }
984 if (i==countof (charset_map))
985 strcpy (fontname, charset_map[0].name);
986
987 /* Check that the new font is not a duplicate */
988 fonthead = &DEVICE_MSWINDOWS_FONTLIST (font_enum->d);
989 fontlist = *fonthead;
990 while (fontlist)
991 if (!strcmp (fontname, fontlist->fontname))
992 return 1; /* found a duplicate */
993 else
994 fontlist = fontlist->next;
995
996 /* Insert entry at head */
997 fontlist = *fonthead;
998 *fonthead = xmalloc (sizeof (struct mswindows_font_enum));
999 if (*fonthead == NULL)
1000 {
1001 *fonthead = fontlist;
1002 return 0;
1003 }
1004 strcpy ((*fonthead)->fontname, fontname);
1005 (*fonthead)->next = fontlist;
1006 return 1;
1007 }
1008
1009 static int CALLBACK
1010 font_enum_callback_1 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme,
1011 int FontType, struct font_enum_t *font_enum)
1012 {
1013 /* This function gets called once per facename per character set.
1014 * We call a second callback to enumerate the fonts in each facename */
1015 return EnumFontFamiliesEx (font_enum->hdc, &lpelfe->elfLogFont,
1016 (FONTENUMPROC) font_enum_callback_2,
1017 (LPARAM) font_enum, 0);
1018 }
1019
1020 /*
1021 * Enumerate the available fonts. Called by mswindows_init_device().
1022 * Fills in the device's device-type-specfic fontlist.
1023 */
1024 void
1025 mswindows_enumerate_fonts (struct device *d)
1026 {
1027 HDC hdc = CreateCompatibleDC (NULL);
1028 LOGFONT logfont;
1029 struct font_enum_t font_enum;
1030
1031 assert (hdc!=NULL);
1032 logfont.lfCharSet = DEFAULT_CHARSET;
1033 logfont.lfFaceName[0] = '\0';
1034 logfont.lfPitchAndFamily = DEFAULT_PITCH;
1035 font_enum.hdc = hdc;
1036 font_enum.d = d;
1037 DEVICE_MSWINDOWS_FONTLIST (d) = NULL;
1038 EnumFontFamiliesEx (hdc, &logfont, (FONTENUMPROC) font_enum_callback_1,
1039 (LPARAM) (&font_enum), 0);
1040 DeleteDC (hdc);
1041 }
1042
875 1043
876 /************************************************************************/ 1044 /************************************************************************/
877 /* methods */ 1045 /* methods */
878 /************************************************************************/ 1046 /************************************************************************/
879 1047
968 DeleteObject(f->data); 1136 DeleteObject(f->data);
969 f->data=0; 1137 f->data=0;
970 } 1138 }
971 } 1139 }
972 1140
1141
973 static int 1142 static int
974 mswindows_initialize_font_instance (struct Lisp_Font_Instance *f, Lisp_Object name, 1143 mswindows_initialize_font_instance (struct Lisp_Font_Instance *f, Lisp_Object name,
975 Lisp_Object device, Error_behavior errb) 1144 Lisp_Object device, Error_behavior errb)
976 { 1145 {
977 CONST char *extname; 1146 CONST char *extname;
978 LOGFONT logfont; 1147 LOGFONT logfont;
979 int fields; 1148 int fields, i;
980 int pt; 1149 int pt;
981 char fontname[LF_FACESIZE], weight[LF_FACESIZE], *style, points[8]; 1150 char fontname[LF_FACESIZE], weight[LF_FACESIZE], *style, points[8];
982 char effects[LF_FACESIZE], charset[LF_FACESIZE]; 1151 char effects[LF_FACESIZE], charset[LF_FACESIZE];
983 char *c; 1152 char *c;
984 1153 HDC hdc;
985 GET_C_STRING_CTEXT_DATA_ALLOCA (f->name, extname); 1154 HFONT holdfont;
1155 TEXTMETRIC metrics;
1156
1157 extname = XSTRING_DATA (name);
986 1158
987 /* 1159 /*
988 * mswindows fonts look like: 1160 * mswindows fonts look like:
989 * fontname[:[weight ][style][:pointsize[:effects]]][:charset] 1161 * fontname[:[weight ][style][:pointsize[:effects]]][:charset]
990 * The font name field shouldn't be empty. 1162 * The font name field shouldn't be empty.
1001 fontname, weight, points, effects, charset); 1173 fontname, weight, points, effects, charset);
1002 1174
1003 /* This function is implemented in a fairly ad-hoc manner. 1175 /* This function is implemented in a fairly ad-hoc manner.
1004 * The general idea is to validate and canonicalize each of the above fields 1176 * The general idea is to validate and canonicalize each of the above fields
1005 * at the same time as we build up the win32 LOGFONT structure. This enables 1177 * at the same time as we build up the win32 LOGFONT structure. This enables
1006 * us to use math_font() on a canonicalized font string to check the 1178 * us to use match_font() on a canonicalized font string to check the
1007 * availability of the requested font */ 1179 * availability of the requested font */
1008 1180
1009 if (fields<0) 1181 if (fields < 0)
1010 { 1182 {
1011 maybe_signal_simple_error ("Invalid font", f->name, Qfont, errb); 1183 maybe_signal_simple_error ("Invalid font", name, Qfont, errb);
1012 return (0); 1184 return (0);
1013 } 1185 }
1014 1186
1015 if (fields>0 && strlen(fontname)) 1187 if (fields>0 && strlen(fontname))
1016 { 1188 {
1017 strncpy (logfont.lfFaceName, fontname, LF_FACESIZE); 1189 strncpy (logfont.lfFaceName, fontname, LF_FACESIZE);
1018 logfont.lfFaceName[LF_FACESIZE-1] = 0; 1190 logfont.lfFaceName[LF_FACESIZE-1] = 0;
1019 } 1191 }
1020 else 1192 else
1021 { 1193 {
1022 maybe_signal_simple_error ("Must specify a font name", f->name, Qfont, errb); 1194 maybe_signal_simple_error ("Must specify a font name", name, Qfont, errb);
1023 return (0); 1195 return (0);
1024 } 1196 }
1025 1197
1026 /* weight */ 1198 /* weight */
1027 if (fields < 2) 1199 if (fields < 2)
1028 strcpy (weight, "Regular"); 1200 strcpy (weight, fontweight_map[0].name);
1029 1201
1030 /* Maybe split weight into weight and style */ 1202 /* Maybe split weight into weight and style */
1031 if ((c=strchr(weight, ' '))) 1203 if ((c=strchr(weight, ' ')))
1032 { 1204 {
1033 *c = '\0'; 1205 *c = '\0';
1034 style = c+1; 1206 style = c+1;
1035 } 1207 }
1036 else 1208 else
1037 style = NULL; 1209 style = NULL;
1038 1210
1039 #define FROB(wgt) \ 1211 for (i=0; i<countof (fontweight_map); i++)
1040 if (stricmp (weight, #wgt) == 0) \ 1212 if (!stricmp (weight, fontweight_map[i].name))
1041 logfont.lfWeight = FW_##wgt 1213 {
1042 1214 logfont.lfWeight = fontweight_map[i].value;
1043 FROB (REGULAR); 1215 break;
1044 else FROB (THIN); 1216 }
1045 else FROB (EXTRALIGHT); 1217 if (i == countof (fontweight_map)) /* No matching weight */
1046 else FROB (ULTRALIGHT);
1047 else FROB (LIGHT);
1048 else FROB (NORMAL);
1049 else FROB (MEDIUM);
1050 else FROB (SEMIBOLD);
1051 else FROB (DEMIBOLD);
1052 else FROB (BOLD);
1053 else FROB (EXTRABOLD);
1054 else FROB (ULTRABOLD);
1055 else FROB (HEAVY);
1056 else FROB (BLACK);
1057 else if (!style)
1058 { 1218 {
1059 logfont.lfWeight = FW_REGULAR; 1219 if (!style)
1060 style = weight; /* May have specified style without weight */ 1220 {
1221 logfont.lfWeight = FW_REGULAR;
1222 style = weight; /* May have specified style without weight */
1223 }
1224 else
1225 {
1226 maybe_signal_simple_error ("Invalid font weight", name, Qfont, errb);
1227 return (0);
1228 }
1061 } 1229 }
1062 else
1063 {
1064 maybe_signal_simple_error ("Invalid font weight", f->name, Qfont, errb);
1065 return (0);
1066 }
1067
1068 #undef FROB
1069 1230
1070 if (style) 1231 if (style)
1071 { 1232 {
1072 /* #### what about oblique? */ 1233 /* #### what about oblique? */
1073 if (stricmp (style,"italic") == 0) 1234 if (stricmp (style,"italic") == 0)
1074 logfont.lfItalic = TRUE; 1235 logfont.lfItalic = TRUE;
1075 else 1236 else
1076 { 1237 {
1077 maybe_signal_simple_error ("Invalid font weight or style", f->name, Qfont, errb); 1238 maybe_signal_simple_error ("Invalid font weight or style", name, Qfont, errb);
1078 return (0); 1239 return (0);
1079 } 1240 }
1080 1241
1081 /* Glue weight and style together again */ 1242 /* Glue weight and style together again */
1082 if (weight != style) 1243 if (weight != style)
1087 1248
1088 if (fields < 3) 1249 if (fields < 3)
1089 pt = 10; /* #### Should we reject strings that don't specify a size? */ 1250 pt = 10; /* #### Should we reject strings that don't specify a size? */
1090 else if ((pt=atoi(points)) == 0) 1251 else if ((pt=atoi(points)) == 0)
1091 { 1252 {
1092 maybe_signal_simple_error ("Invalid font pointsize", f->name, Qfont, errb); 1253 maybe_signal_simple_error ("Invalid font pointsize", name, Qfont, errb);
1093 return (0); 1254 return (0);
1094 } 1255 }
1095 1256
1096 /* Formula for pointsize->height from LOGFONT docs in MSVC5 Platform SDK */ 1257 /* Formula for pointsize->height from LOGFONT docs in MSVC5 Platform SDK */
1097 logfont.lfHeight = -MulDiv(pt, DEVICE_MSWINDOWS_LOGPIXELSY(XDEVICE (device)), 72); 1258 logfont.lfHeight = -MulDiv(pt, DEVICE_MSWINDOWS_LOGPIXELSY (XDEVICE (device)), 72);
1098 logfont.lfWidth = 0; 1259 logfont.lfWidth = 0;
1099 1260
1100 /* Effects */ 1261 /* Effects */
1101 logfont.lfUnderline = FALSE; 1262 logfont.lfUnderline = FALSE;
1102 logfont.lfStrikeOut = FALSE; 1263 logfont.lfStrikeOut = FALSE;
1117 logfont.lfUnderline = TRUE; 1278 logfont.lfUnderline = TRUE;
1118 else if (stricmp (effects, "strikeout") == 0) 1279 else if (stricmp (effects, "strikeout") == 0)
1119 logfont.lfStrikeOut = TRUE; 1280 logfont.lfStrikeOut = TRUE;
1120 else 1281 else
1121 { 1282 {
1122 maybe_signal_simple_error ("Invalid font effect", f->name, 1283 maybe_signal_simple_error ("Invalid font effect", name, Qfont, errb);
1123 Qfont, errb);
1124 return (0); 1284 return (0);
1125 } 1285 }
1126 1286
1127 if (effects2 && effects2[0] != '\0') 1287 if (effects2 && effects2[0] != '\0')
1128 { 1288 {
1130 logfont.lfUnderline = TRUE; 1290 logfont.lfUnderline = TRUE;
1131 else if (stricmp (effects2, "strikeout") == 0) 1291 else if (stricmp (effects2, "strikeout") == 0)
1132 logfont.lfStrikeOut = TRUE; 1292 logfont.lfStrikeOut = TRUE;
1133 else 1293 else
1134 { 1294 {
1135 maybe_signal_simple_error ("Invalid font effect", f->name, 1295 maybe_signal_simple_error ("Invalid font effect", name,
1136 Qfont, errb); 1296 Qfont, errb);
1137 return (0); 1297 return (0);
1138 } 1298 }
1139 } 1299 }
1140 1300
1150 strcpy (effects, "strikeout"); 1310 strcpy (effects, "strikeout");
1151 } 1311 }
1152 else 1312 else
1153 effects[0] = '\0'; 1313 effects[0] = '\0';
1154 1314
1155 #define FROB(cs) \ 1315 /* Charset */
1156 else if (stricmp (charset, #cs) == 0) \
1157 logfont.lfCharSet = cs##_CHARSET
1158
1159 /* Charset aliases. Hangeul = Hangul is defined in windows.h.
1160 We do not use the name "russian", only "cyrillic", as it is
1161 the common name of this charset, used in other languages
1162 than Russian. */
1163 #define CYRILLIC_CHARSET RUSSIAN_CHARSET
1164 #define CENTRALEUROPEAN_CHARSET EASTEUROPE_CHARSET
1165 #define CENTRALEUROPEAN_CHARSET EASTEUROPE_CHARSET
1166
1167 /* charset can be specified even if earlier fields havn't been */ 1316 /* charset can be specified even if earlier fields havn't been */
1168 if ((fields < 5) && (c=strchr (extname, ':')) && (c=strchr (c+1, ':')) && 1317 if (fields < 5)
1169 (c=strchr (c+1, ':')) && (c=strchr (c+1, ':')))
1170 { 1318 {
1171 strncpy (charset, c+1, LF_FACESIZE); 1319 if ((c=strchr (extname, ':')) && (c=strchr (c+1, ':')) &&
1172 charset[LF_FACESIZE-1] = '\0'; 1320 (c=strchr (c+1, ':')) && (c=strchr (c+1, ':')))
1321 {
1322 strncpy (charset, c+1, LF_FACESIZE);
1323 charset[LF_FACESIZE-1] = '\0';
1324 }
1325 else
1326 strcpy (charset, charset_map[0].name);
1173 } 1327 }
1174 else 1328
1175 charset[0] = '\0'; 1329 for (i=0; i<countof (charset_map); i++)
1176 1330 if (!stricmp (charset, charset_map[i].name))
1177 if (charset[0] == '\0' || (stricmp (charset, "ansi") == 0) || 1331 {
1178 (stricmp (charset, "western") == 0)) 1332 logfont.lfCharSet = charset_map[i].value;
1333 break;
1334 }
1335
1336 if (i == countof (charset_map)) /* No matching charset */
1179 { 1337 {
1180 logfont.lfCharSet = ANSI_CHARSET; 1338 maybe_signal_simple_error ("Invalid charset", name, Qfont, errb);
1181 strcpy (charset, "western");
1182 }
1183 FROB (SYMBOL);
1184 FROB (SHIFTJIS);
1185 FROB (GB2312);
1186 FROB (HANGEUL);
1187 FROB (CHINESEBIG5);
1188 FROB (JOHAB);
1189 FROB (HEBREW);
1190 FROB (ARABIC);
1191 FROB (GREEK);
1192 FROB (TURKISH);
1193 FROB (THAI);
1194 FROB (EASTEUROPE);
1195 FROB (CENTRALEUROPEAN);
1196 FROB (CYRILLIC);
1197 FROB (MAC);
1198 FROB (BALTIC);
1199 else if (stricmp (charset, "oem/dos") == 0)
1200 logfont.lfCharSet = OEM_CHARSET;
1201 else
1202 {
1203 maybe_signal_simple_error ("Invalid charset", f->name, Qfont, errb);
1204 return 0; 1339 return 0;
1205 } 1340 }
1206 1341
1207 #undef FROB 1342 /* Misc crud */
1343 logfont.lfEscapement = logfont.lfOrientation = 0;
1344 #if 1
1345 logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
1346 logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1347 logfont.lfQuality = DEFAULT_QUALITY;
1348 #else
1349 logfont.lfOutPrecision = OUT_STROKE_PRECIS;
1350 logfont.lfClipPrecision = CLIP_STROKE_PRECIS;
1351 logfont.lfQuality = PROOF_QUALITY;
1352 #endif
1353 /* Default to monospaced if the specified fontname doesn't exist. */
1354 logfont.lfPitchAndFamily = FF_MODERN;
1208 1355
1209 /* Windows will silently substitute a default font if the fontname 1356 /* Windows will silently substitute a default font if the fontname
1210 * specifies a non-existent font. So we check the font against the device's 1357 * specifies a non-existent font. So we check the font against the device's
1211 * list of font patterns to make sure that at least one of them matches */ 1358 * list of font patterns to make sure that at least one of them matches. */
1212 { 1359 {
1213 struct mswindows_font_enum *fontlist; 1360 struct mswindows_font_enum *fontlist;
1214 char truename[MSW_FONTSIZE]; 1361 char truename[MSW_FONTSIZE];
1215 int done = 0; 1362 int done = 0;
1216 1363
1221 done = match_font (fontlist->fontname, truename, NULL); 1368 done = match_font (fontlist->fontname, truename, NULL);
1222 fontlist = fontlist->next; 1369 fontlist = fontlist->next;
1223 } 1370 }
1224 if (!done) 1371 if (!done)
1225 { 1372 {
1226 maybe_signal_simple_error ("No matching font", f->name, Qfont, errb); 1373 maybe_signal_simple_error ("No matching font", name, Qfont, errb);
1227 return 0; 1374 return 0;
1228 } 1375 }
1229 } 1376 }
1230 1377
1231 /* Misc crud */
1232 logfont.lfEscapement = logfont.lfOrientation = 0;
1233 #if 1
1234 logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
1235 logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1236 logfont.lfQuality = DEFAULT_QUALITY;
1237 #else
1238 logfont.lfOutPrecision = OUT_STROKE_PRECIS;
1239 logfont.lfClipPrecision = CLIP_STROKE_PRECIS;
1240 logfont.lfQuality = PROOF_QUALITY;
1241 #endif
1242 /* Default to monospaced if the specified fontname doesn't exist.
1243 * The match_font calls above should mean that this can't happen. */
1244 logfont.lfPitchAndFamily = FF_MODERN;
1245
1246 if ((f->data = CreateFontIndirect(&logfont)) == NULL) 1378 if ((f->data = CreateFontIndirect(&logfont)) == NULL)
1247 { 1379 {
1248 maybe_signal_simple_error ("Couldn't create font", f->name, Qfont, errb); 1380 maybe_signal_simple_error ("Couldn't create font", name, Qfont, errb);
1249 return 0; 1381 return 0;
1250 } 1382 }
1251 1383
1252 { 1384 hdc = CreateCompatibleDC (NULL);
1253 HDC hdc; 1385 if (hdc)
1254 HFONT holdfont; 1386 {
1255 TEXTMETRIC metrics; 1387 holdfont = SelectObject(hdc, f->data);
1256 1388 if (holdfont)
1257 hdc = CreateCompatibleDC (NULL); 1389 {
1258 if (hdc) 1390 GetTextMetrics (hdc, &metrics);
1259 { 1391 SelectObject(hdc, holdfont);
1260 holdfont = SelectObject(hdc, f->data); 1392 DeleteDC (hdc);
1261 if (holdfont) 1393 f->width = (unsigned short) metrics.tmAveCharWidth;
1262 { 1394 f->height = (unsigned short) metrics.tmHeight;
1263 GetTextMetrics (hdc, &metrics); 1395 f->ascent = (unsigned short) metrics.tmAscent;
1264 SelectObject(hdc, holdfont); 1396 f->descent = (unsigned short) metrics.tmDescent;
1265 DeleteDC (hdc); 1397 f->proportional_p = (metrics.tmPitchAndFamily & TMPF_FIXED_PITCH);
1266 f->width = (unsigned short) metrics.tmAveCharWidth; 1398 return 1;
1267 f->height = (unsigned short) metrics.tmHeight; 1399 }
1268 f->ascent = (unsigned short) metrics.tmAscent; 1400 DeleteDC (hdc);
1269 f->descent = (unsigned short) metrics.tmDescent; 1401 }
1270 f->proportional_p = (metrics.tmPitchAndFamily & TMPF_FIXED_PITCH); 1402 mswindows_finalize_font_instance (f);
1271 return 1; 1403 maybe_signal_simple_error ("Couldn't map font", name, Qfont, errb);
1272 }
1273 DeleteDC (hdc);
1274 }
1275 mswindows_finalize_font_instance (f);
1276 maybe_signal_simple_error ("Couldn't map font", f->name, Qfont, errb);
1277 }
1278 return 0; 1404 return 0;
1279 } 1405 }
1280 1406
1281 #if 0 1407 #if 0
1282 static void 1408 static void