Mercurial > hg > xemacs-beta
comparison src/objects-msw.c @ 440:8de8e3f6228a r21-2-28
Import from CVS: tag r21-2-28
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:33:38 +0200 |
parents | a5df635868b2 |
children | abe6d1db359e |
comparison
equal
deleted
inserted
replaced
439:357dd071b03c | 440:8de8e3f6228a |
---|---|
936 /************************************************************************/ | 936 /************************************************************************/ |
937 | 937 |
938 struct font_enum_t | 938 struct font_enum_t |
939 { | 939 { |
940 HDC hdc; | 940 HDC hdc; |
941 struct device *d; | 941 Lisp_Object list; |
942 }; | 942 }; |
943 | 943 |
944 static int CALLBACK | 944 static int CALLBACK |
945 font_enum_callback_2 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, | 945 font_enum_callback_2 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, |
946 int FontType, struct font_enum_t *font_enum) | 946 int FontType, struct font_enum_t *font_enum) |
947 { | 947 { |
948 struct mswindows_font_enum *fontlist, **fonthead; | |
949 char fontname[MSW_FONTSIZE]; | 948 char fontname[MSW_FONTSIZE]; |
949 Lisp_Object fontname_lispstr; | |
950 int i; | 950 int i; |
951 | 951 |
952 /* | 952 /* |
953 * The enumerated font weights are not to be trusted because: | 953 * The enumerated font weights are not to be trusted because: |
954 * a) lpelfe->elfStyle is only filled in for TrueType fonts. | 954 * a) lpelfe->elfStyle is only filled in for TrueType fonts. |
965 sprintf (fontname, "%s::::", lpelfe->elfLogFont.lfFaceName); | 965 sprintf (fontname, "%s::::", lpelfe->elfLogFont.lfFaceName); |
966 else | 966 else |
967 /* Formula for pointsize->height from LOGFONT docs in Platform SDK */ | 967 /* Formula for pointsize->height from LOGFONT docs in Platform SDK */ |
968 sprintf (fontname, "%s::%d::", lpelfe->elfLogFont.lfFaceName, | 968 sprintf (fontname, "%s::%d::", lpelfe->elfLogFont.lfFaceName, |
969 MulDiv (lpntme->ntmTm.tmHeight - lpntme->ntmTm.tmInternalLeading, | 969 MulDiv (lpntme->ntmTm.tmHeight - lpntme->ntmTm.tmInternalLeading, |
970 72, DEVICE_MSWINDOWS_LOGPIXELSY (font_enum->d))); | 970 72, GetDeviceCaps (font_enum->hdc, LOGPIXELSY))); |
971 | 971 |
972 /* | 972 /* |
973 * The enumerated font character set strings are not to be trusted because | 973 * The enumerated font character set strings are not to be trusted because |
974 * lpelfe->elfScript is returned in the host language and not in English. | 974 * lpelfe->elfScript is returned in the host language and not in English. |
975 * We can't know a priori the translations of "Western", "Central European" | 975 * We can't know a priori the translations of "Western", "Central European" |
983 break; | 983 break; |
984 } | 984 } |
985 if (i==countof (charset_map)) | 985 if (i==countof (charset_map)) |
986 strcpy (fontname, charset_map[0].name); | 986 strcpy (fontname, charset_map[0].name); |
987 | 987 |
988 /* Check that the new font is not a duplicate */ | 988 /* Add the font name to the list if not already there */ |
989 fonthead = &DEVICE_MSWINDOWS_FONTLIST (font_enum->d); | 989 fontname_lispstr = build_string (fontname); |
990 fontlist = *fonthead; | 990 if (NILP (memq_no_quit (fontname_lispstr, font_enum->list))) |
991 while (fontlist) | 991 font_enum->list = Fcons (fontname_lispstr, font_enum->list); |
992 if (!strcmp (fontname, fontlist->fontname)) | 992 |
993 return 1; /* found a duplicate */ | |
994 else | |
995 fontlist = fontlist->next; | |
996 | |
997 /* Insert entry at head */ | |
998 fontlist = *fonthead; | |
999 *fonthead = xmalloc (sizeof (struct mswindows_font_enum)); | |
1000 if (*fonthead == NULL) | |
1001 { | |
1002 *fonthead = fontlist; | |
1003 return 0; | |
1004 } | |
1005 strcpy ((*fonthead)->fontname, fontname); | |
1006 (*fonthead)->next = fontlist; | |
1007 return 1; | 993 return 1; |
1008 } | 994 } |
1009 | 995 |
1010 static int CALLBACK | 996 static int CALLBACK |
1011 font_enum_callback_1 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, | 997 font_enum_callback_1 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, |
1017 (FONTENUMPROC) font_enum_callback_2, | 1003 (FONTENUMPROC) font_enum_callback_2, |
1018 (LPARAM) font_enum, 0); | 1004 (LPARAM) font_enum, 0); |
1019 } | 1005 } |
1020 | 1006 |
1021 /* | 1007 /* |
1022 * Enumerate the available fonts. Called by mswindows_init_device(). | 1008 * Enumerate the available on the HDC fonts and return a list of string |
1023 * Fills in the device's device-type-specfic fontlist. | 1009 * font names. |
1024 */ | 1010 */ |
1025 void | 1011 Lisp_Object |
1026 mswindows_enumerate_fonts (struct device *d) | 1012 mswindows_enumerate_fonts (HDC hdc) |
1027 { | 1013 { |
1028 HDC hdc = CreateCompatibleDC (NULL); | 1014 /* This cannot CG */ |
1029 LOGFONT logfont; | 1015 LOGFONT logfont; |
1030 struct font_enum_t font_enum; | 1016 struct font_enum_t font_enum; |
1031 | 1017 |
1032 assert (hdc!=NULL); | 1018 assert (hdc!=NULL); |
1033 logfont.lfCharSet = DEFAULT_CHARSET; | 1019 logfont.lfCharSet = DEFAULT_CHARSET; |
1034 logfont.lfFaceName[0] = '\0'; | 1020 logfont.lfFaceName[0] = '\0'; |
1035 logfont.lfPitchAndFamily = DEFAULT_PITCH; | 1021 logfont.lfPitchAndFamily = DEFAULT_PITCH; |
1036 font_enum.hdc = hdc; | 1022 font_enum.hdc = hdc; |
1037 font_enum.d = d; | 1023 font_enum.list = Qnil; |
1038 DEVICE_MSWINDOWS_FONTLIST (d) = NULL; | |
1039 EnumFontFamiliesEx (hdc, &logfont, (FONTENUMPROC) font_enum_callback_1, | 1024 EnumFontFamiliesEx (hdc, &logfont, (FONTENUMPROC) font_enum_callback_1, |
1040 (LPARAM) (&font_enum), 0); | 1025 (LPARAM) (&font_enum), 0); |
1041 DeleteDC (hdc); | 1026 return font_enum.list; |
1042 } | 1027 } |
1043 | 1028 |
1029 static void | |
1030 mswindows_create_font_variant (Lisp_Font_Instance* f, | |
1031 int under, int strike) | |
1032 { | |
1033 /* Cannot GC */ | |
1034 | |
1035 LOGFONT lf; | |
1036 HFONT hfont; | |
1037 | |
1038 assert (FONT_INSTANCE_MSWINDOWS_HFONT_VARIANT (f, under, strike) == NULL); | |
1039 | |
1040 if (GetObject (FONT_INSTANCE_MSWINDOWS_HFONT_VARIANT (f, 0, 0), | |
1041 sizeof (lf), (void*) &lf) == 0) | |
1042 { | |
1043 hfont = MSWINDOWS_BAD_HFONT; | |
1044 } | |
1045 else | |
1046 { | |
1047 lf.lfUnderline = under; | |
1048 lf.lfStrikeOut = strike; | |
1049 | |
1050 hfont = CreateFontIndirect (&lf); | |
1051 if (hfont == NULL) | |
1052 hfont = MSWINDOWS_BAD_HFONT; | |
1053 } | |
1054 | |
1055 FONT_INSTANCE_MSWINDOWS_HFONT_VARIANT (f, under, strike) = hfont; | |
1056 } | |
1057 | |
1058 HFONT | |
1059 mswindows_get_hfont (Lisp_Font_Instance* f, | |
1060 int under, int strike) | |
1061 { | |
1062 /* Cannot GC */ | |
1063 HFONT hfont; | |
1064 | |
1065 if (FONT_INSTANCE_MSWINDOWS_HFONT_VARIANT (f, under, strike) == NULL) | |
1066 mswindows_create_font_variant (f, under, strike); | |
1067 | |
1068 assert (FONT_INSTANCE_MSWINDOWS_HFONT_VARIANT (f, under, strike) != NULL); | |
1069 | |
1070 hfont = FONT_INSTANCE_MSWINDOWS_HFONT_VARIANT (f, under, strike); | |
1071 | |
1072 /* If strikeout/underline variant of the font could not be | |
1073 created, then use the base version of the font */ | |
1074 if (hfont == MSWINDOWS_BAD_HFONT) | |
1075 hfont = FONT_INSTANCE_MSWINDOWS_HFONT_VARIANT (f, 0, 0); | |
1076 | |
1077 assert (hfont != NULL && hfont != MSWINDOWS_BAD_HFONT); | |
1078 | |
1079 return hfont; | |
1080 } | |
1044 | 1081 |
1045 /************************************************************************/ | 1082 /************************************************************************/ |
1046 /* methods */ | 1083 /* methods */ |
1047 /************************************************************************/ | 1084 /************************************************************************/ |
1048 | 1085 |
1049 static int | 1086 static int |
1050 mswindows_initialize_color_instance (struct Lisp_Color_Instance *c, Lisp_Object name, | 1087 mswindows_initialize_color_instance (Lisp_Color_Instance *c, Lisp_Object name, |
1051 Lisp_Object device, Error_behavior errb) | 1088 Lisp_Object device, Error_behavior errb) |
1052 { | 1089 { |
1053 CONST char *extname; | 1090 CONST char *extname; |
1054 COLORREF color; | 1091 COLORREF color; |
1055 | 1092 |
1056 GET_C_STRING_CTEXT_DATA_ALLOCA (name, extname); | 1093 TO_EXTERNAL_FORMAT (LISP_STRING, name, |
1094 C_STRING_ALLOCA, extname, | |
1095 Qctext); | |
1057 color = mswindows_string_to_color(extname); | 1096 color = mswindows_string_to_color(extname); |
1058 if (color != -1) | 1097 if (color != -1) |
1059 { | 1098 { |
1060 c->data = xnew (struct mswindows_color_instance_data); | 1099 c->data = xnew (struct mswindows_color_instance_data); |
1061 COLOR_INSTANCE_MSWINDOWS_COLOR (c) = color; | 1100 COLOR_INSTANCE_MSWINDOWS_COLOR (c) = color; |
1065 return(0); | 1104 return(0); |
1066 } | 1105 } |
1067 | 1106 |
1068 #if 0 | 1107 #if 0 |
1069 static void | 1108 static void |
1070 mswindows_mark_color_instance (struct Lisp_Color_Instance *c) | 1109 mswindows_mark_color_instance (Lisp_Color_Instance *c) |
1071 { | 1110 { |
1072 } | 1111 } |
1073 #endif | 1112 #endif |
1074 | 1113 |
1075 static void | 1114 static void |
1076 mswindows_print_color_instance (struct Lisp_Color_Instance *c, | 1115 mswindows_print_color_instance (Lisp_Color_Instance *c, |
1077 Lisp_Object printcharfun, | 1116 Lisp_Object printcharfun, |
1078 int escapeflag) | 1117 int escapeflag) |
1079 { | 1118 { |
1080 char buf[32]; | 1119 char buf[32]; |
1081 COLORREF color = COLOR_INSTANCE_MSWINDOWS_COLOR (c); | 1120 COLORREF color = COLOR_INSTANCE_MSWINDOWS_COLOR (c); |
1082 sprintf (buf, " %06ld=(%04X,%04X,%04X)", color & 0xffffff, | 1121 sprintf (buf, " %06ld=(%04X,%04X,%04X)", color & 0xffffff, |
1083 GetRValue(color)*257, GetGValue(color)*257, GetBValue(color)*257); | 1122 GetRValue(color)*257, GetGValue(color)*257, GetBValue(color)*257); |
1084 write_c_string (buf, printcharfun); | 1123 write_c_string (buf, printcharfun); |
1085 } | 1124 } |
1086 | 1125 |
1087 static void | 1126 static void |
1088 mswindows_finalize_color_instance (struct Lisp_Color_Instance *c) | 1127 mswindows_finalize_color_instance (Lisp_Color_Instance *c) |
1089 { | 1128 { |
1090 if (c->data) | 1129 if (c->data) |
1091 { | 1130 { |
1092 xfree (c->data); | 1131 xfree (c->data); |
1093 c->data = 0; | 1132 c->data = 0; |
1094 } | 1133 } |
1095 } | 1134 } |
1096 | 1135 |
1097 static int | 1136 static int |
1098 mswindows_color_instance_equal (struct Lisp_Color_Instance *c1, | 1137 mswindows_color_instance_equal (Lisp_Color_Instance *c1, |
1099 struct Lisp_Color_Instance *c2, | 1138 Lisp_Color_Instance *c2, |
1100 int depth) | 1139 int depth) |
1101 { | 1140 { |
1102 return (COLOR_INSTANCE_MSWINDOWS_COLOR(c1) == COLOR_INSTANCE_MSWINDOWS_COLOR(c2)); | 1141 return (COLOR_INSTANCE_MSWINDOWS_COLOR(c1) == COLOR_INSTANCE_MSWINDOWS_COLOR(c2)); |
1103 } | 1142 } |
1104 | 1143 |
1105 static unsigned long | 1144 static unsigned long |
1106 mswindows_color_instance_hash (struct Lisp_Color_Instance *c, int depth) | 1145 mswindows_color_instance_hash (Lisp_Color_Instance *c, int depth) |
1107 { | 1146 { |
1108 return (unsigned long) COLOR_INSTANCE_MSWINDOWS_COLOR(c); | 1147 return (unsigned long) COLOR_INSTANCE_MSWINDOWS_COLOR(c); |
1109 } | 1148 } |
1110 | 1149 |
1111 static Lisp_Object | 1150 static Lisp_Object |
1112 mswindows_color_instance_rgb_components (struct Lisp_Color_Instance *c) | 1151 mswindows_color_instance_rgb_components (Lisp_Color_Instance *c) |
1113 { | 1152 { |
1114 COLORREF color = COLOR_INSTANCE_MSWINDOWS_COLOR (c); | 1153 COLORREF color = COLOR_INSTANCE_MSWINDOWS_COLOR (c); |
1115 return list3 (make_int (GetRValue (color) * 257), | 1154 return list3 (make_int (GetRValue (color) * 257), |
1116 make_int (GetGValue (color) * 257), | 1155 make_int (GetGValue (color) * 257), |
1117 make_int (GetBValue (color) * 257)); | 1156 make_int (GetBValue (color) * 257)); |
1120 static int | 1159 static int |
1121 mswindows_valid_color_name_p (struct device *d, Lisp_Object color) | 1160 mswindows_valid_color_name_p (struct device *d, Lisp_Object color) |
1122 { | 1161 { |
1123 CONST char *extname; | 1162 CONST char *extname; |
1124 | 1163 |
1125 GET_C_STRING_CTEXT_DATA_ALLOCA (color, extname); | 1164 TO_EXTERNAL_FORMAT (LISP_STRING, color, |
1165 C_STRING_ALLOCA, extname, | |
1166 Qctext); | |
1126 return (mswindows_string_to_color(extname)!=-1); | 1167 return (mswindows_string_to_color(extname)!=-1); |
1127 } | 1168 } |
1128 | 1169 |
1129 | 1170 |
1130 | 1171 |
1131 static void | 1172 static void |
1132 mswindows_finalize_font_instance (struct Lisp_Font_Instance *f) | 1173 mswindows_finalize_font_instance (Lisp_Font_Instance *f); |
1133 { | 1174 |
1134 if (f->data) | 1175 /* |
1135 { | 1176 * This is a work horse for both mswindows_initialize_font_instanc and |
1136 DeleteObject(f->data); | 1177 * msprinter_initialize_font_instance. |
1137 f->data=0; | 1178 */ |
1138 } | |
1139 } | |
1140 | |
1141 | |
1142 static int | 1179 static int |
1143 mswindows_initialize_font_instance (struct Lisp_Font_Instance *f, Lisp_Object name, | 1180 initialize_font_instance (Lisp_Font_Instance *f, Lisp_Object name, |
1144 Lisp_Object device, Error_behavior errb) | 1181 Lisp_Object device_font_list, HDC hdc, |
1182 Error_behavior errb) | |
1145 { | 1183 { |
1146 CONST char *extname; | 1184 CONST char *extname; |
1147 LOGFONT logfont; | 1185 LOGFONT logfont; |
1148 int fields, i; | 1186 int fields, i; |
1149 int pt; | 1187 int pt; |
1150 char fontname[LF_FACESIZE], weight[LF_FACESIZE], *style, points[8]; | 1188 char fontname[LF_FACESIZE], weight[LF_FACESIZE], *style, points[8]; |
1151 char effects[LF_FACESIZE], charset[LF_FACESIZE]; | 1189 char effects[LF_FACESIZE], charset[LF_FACESIZE]; |
1152 char *c; | 1190 char *c; |
1153 HDC hdc; | 1191 HFONT hfont, holdfont; |
1154 HFONT holdfont; | |
1155 TEXTMETRIC metrics; | 1192 TEXTMETRIC metrics; |
1156 | 1193 |
1157 extname = XSTRING_DATA (name); | 1194 extname = XSTRING_DATA (name); |
1158 | 1195 |
1159 /* | 1196 /* |
1253 maybe_signal_simple_error ("Invalid font pointsize", name, Qfont, errb); | 1290 maybe_signal_simple_error ("Invalid font pointsize", name, Qfont, errb); |
1254 return (0); | 1291 return (0); |
1255 } | 1292 } |
1256 | 1293 |
1257 /* Formula for pointsize->height from LOGFONT docs in MSVC5 Platform SDK */ | 1294 /* Formula for pointsize->height from LOGFONT docs in MSVC5 Platform SDK */ |
1258 logfont.lfHeight = -MulDiv(pt, DEVICE_MSWINDOWS_LOGPIXELSY (XDEVICE (device)), 72); | 1295 logfont.lfHeight = -MulDiv(pt, GetDeviceCaps (hdc, LOGPIXELSY), 72); |
1259 logfont.lfWidth = 0; | 1296 logfont.lfWidth = 0; |
1260 | 1297 |
1261 /* Effects */ | 1298 /* Effects */ |
1262 logfont.lfUnderline = FALSE; | 1299 logfont.lfUnderline = FALSE; |
1263 logfont.lfStrikeOut = FALSE; | 1300 logfont.lfStrikeOut = FALSE; |
1351 logfont.lfQuality = PROOF_QUALITY; | 1388 logfont.lfQuality = PROOF_QUALITY; |
1352 #endif | 1389 #endif |
1353 /* Default to monospaced if the specified fontname doesn't exist. */ | 1390 /* Default to monospaced if the specified fontname doesn't exist. */ |
1354 logfont.lfPitchAndFamily = FF_MODERN; | 1391 logfont.lfPitchAndFamily = FF_MODERN; |
1355 | 1392 |
1356 /* Windows will silently substitute a default font if the fontname | 1393 /* Windows will silently substitute a default font if the fontname |
1357 * specifies a non-existent font. So we check the font against the device's | 1394 specifies a non-existent font. So we check the font against the |
1358 * list of font patterns to make sure that at least one of them matches. */ | 1395 device's list of font patterns to make sure that at least one of |
1359 { | 1396 them matches. |
1360 struct mswindows_font_enum *fontlist; | 1397 |
1361 char truename[MSW_FONTSIZE]; | 1398 Personally, I do not like the idea - it is better to come out with |
1362 int done = 0; | 1399 some font than completely without one. The diversity of printer |
1363 | 1400 fonts is much greater than that of screen font. We can tread on |
1364 sprintf (truename, "%s:%s:%d:%s:%s", fontname, weight, pt, effects, charset); | 1401 that. -- kkm. */ |
1365 fontlist = DEVICE_MSWINDOWS_FONTLIST (XDEVICE (device)); | 1402 |
1366 while (fontlist && !done) | 1403 if (!NILP (device_font_list)) |
1367 { | 1404 { |
1368 done = match_font (fontlist->fontname, truename, NULL); | 1405 Lisp_Object fonttail; |
1369 fontlist = fontlist->next; | 1406 char truename[MSW_FONTSIZE]; |
1370 } | 1407 |
1371 if (!done) | 1408 sprintf (truename, "%s:%s:%d:%s:%s", fontname, weight, pt, effects, charset); |
1372 { | 1409 LIST_LOOP (fonttail, device_font_list) |
1373 maybe_signal_simple_error ("No matching font", name, Qfont, errb); | 1410 { |
1374 return 0; | 1411 if (match_font (XSTRING_DATA (XCAR (fonttail)), truename, NULL)) |
1375 } | 1412 break; |
1376 } | 1413 } |
1377 | 1414 if (NILP (fonttail)) |
1378 if ((f->data = CreateFontIndirect(&logfont)) == NULL) | 1415 { |
1416 maybe_signal_simple_error ("No matching font", name, Qfont, errb); | |
1417 return 0; | |
1418 } | |
1419 } | |
1420 | |
1421 if ((hfont = CreateFontIndirect(&logfont)) == NULL) | |
1379 { | 1422 { |
1380 maybe_signal_simple_error ("Couldn't create font", name, Qfont, errb); | 1423 maybe_signal_simple_error ("Couldn't create font", name, Qfont, errb); |
1381 return 0; | 1424 return 0; |
1382 } | 1425 } |
1383 | 1426 |
1384 hdc = CreateCompatibleDC (NULL); | 1427 f->data = xnew_and_zero (struct mswindows_font_instance_data); |
1385 if (hdc) | 1428 FONT_INSTANCE_MSWINDOWS_HFONT_VARIANT (f,0,0) = hfont; |
1386 { | 1429 |
1387 holdfont = SelectObject(hdc, f->data); | 1430 holdfont = SelectObject(hdc, hfont); |
1388 if (holdfont) | 1431 if (!holdfont) |
1432 { | |
1433 mswindows_finalize_font_instance (f); | |
1434 maybe_signal_simple_error ("Couldn't map font", name, Qfont, errb); | |
1435 return 0; | |
1436 } | |
1437 | |
1438 GetTextMetrics (hdc, &metrics); | |
1439 SelectObject(hdc, holdfont); | |
1440 | |
1441 f->width = (unsigned short) metrics.tmAveCharWidth; | |
1442 f->height = (unsigned short) metrics.tmHeight; | |
1443 /* Font variant metrics hack. The problem is that in Windows | |
1444 some underlined fonts have the descent of one pixel more | |
1445 than their non-underlined counterparts. Font variants | |
1446 though are assumed to have identical metrics. Lowering | |
1447 the font's baseline one pixel down cures the problem, and | |
1448 is visually undetectable. - kkm */ | |
1449 f->ascent = (unsigned short) metrics.tmAscent - 1; | |
1450 f->descent = (unsigned short) metrics.tmDescent + 1; | |
1451 f->proportional_p = (metrics.tmPitchAndFamily & TMPF_FIXED_PITCH); | |
1452 | |
1453 return 1; | |
1454 } | |
1455 | |
1456 static int | |
1457 mswindows_initialize_font_instance (Lisp_Font_Instance *f, Lisp_Object name, | |
1458 Lisp_Object device, Error_behavior errb) | |
1459 { | |
1460 HDC hdc = CreateCompatibleDC (NULL); | |
1461 Lisp_Object font_list = DEVICE_MSWINDOWS_FONTLIST (XDEVICE (device)); | |
1462 int res = initialize_font_instance (f, name, font_list, hdc, errb); | |
1463 DeleteDC (hdc); | |
1464 return res; | |
1465 } | |
1466 | |
1467 static int | |
1468 msprinter_initialize_font_instance (Lisp_Font_Instance *f, Lisp_Object name, | |
1469 Lisp_Object device, Error_behavior errb) | |
1470 { | |
1471 HDC hdc = DEVICE_MSPRINTER_HDC (XDEVICE (device)); | |
1472 Lisp_Object font_list = DEVICE_MSPRINTER_FONTLIST (XDEVICE (device)); | |
1473 return initialize_font_instance (f, name, font_list, hdc, errb); | |
1474 } | |
1475 | |
1476 static void | |
1477 mswindows_finalize_font_instance (Lisp_Font_Instance *f) | |
1478 { | |
1479 int i; | |
1480 | |
1481 if (f->data) | |
1482 { | |
1483 for (i = 0; i < MSWINDOWS_NUM_FONT_VARIANTS; i++) | |
1389 { | 1484 { |
1390 GetTextMetrics (hdc, &metrics); | 1485 if (FONT_INSTANCE_MSWINDOWS_HFONT_I (f, i) != NULL |
1391 SelectObject(hdc, holdfont); | 1486 && FONT_INSTANCE_MSWINDOWS_HFONT_I (f, i) != MSWINDOWS_BAD_HFONT) |
1392 DeleteDC (hdc); | 1487 DeleteObject (FONT_INSTANCE_MSWINDOWS_HFONT_I (f, i)); |
1393 f->width = (unsigned short) metrics.tmAveCharWidth; | |
1394 f->height = (unsigned short) metrics.tmHeight; | |
1395 f->ascent = (unsigned short) metrics.tmAscent; | |
1396 f->descent = (unsigned short) metrics.tmDescent; | |
1397 f->proportional_p = (metrics.tmPitchAndFamily & TMPF_FIXED_PITCH); | |
1398 return 1; | |
1399 } | 1488 } |
1400 DeleteDC (hdc); | 1489 |
1401 } | 1490 xfree (f->data); |
1402 mswindows_finalize_font_instance (f); | 1491 f->data = 0; |
1403 maybe_signal_simple_error ("Couldn't map font", name, Qfont, errb); | 1492 } |
1404 return 0; | |
1405 } | 1493 } |
1406 | 1494 |
1407 #if 0 | 1495 #if 0 |
1408 static void | 1496 static void |
1409 mswindows_mark_font_instance (struct Lisp_Font_Instance *f) | 1497 mswindows_mark_font_instance (Lisp_Font_Instance *f) |
1410 { | 1498 { |
1411 } | 1499 } |
1412 #endif | 1500 #endif |
1413 | 1501 |
1414 static void | 1502 static void |
1415 mswindows_print_font_instance (struct Lisp_Font_Instance *f, | 1503 mswindows_print_font_instance (Lisp_Font_Instance *f, |
1416 Lisp_Object printcharfun, | 1504 Lisp_Object printcharfun, |
1417 int escapeflag) | 1505 int escapeflag) |
1418 { | 1506 { |
1507 char buf[10]; | |
1508 sprintf (buf, " 0x%lx", | |
1509 (unsigned long)FONT_INSTANCE_MSWINDOWS_HFONT_VARIANT (f,0,0)); | |
1510 write_c_string (buf, printcharfun); | |
1419 } | 1511 } |
1420 | 1512 |
1421 static Lisp_Object | 1513 static Lisp_Object |
1422 mswindows_list_fonts (Lisp_Object pattern, Lisp_Object device) | 1514 mswindows_list_fonts (Lisp_Object pattern, Lisp_Object device) |
1423 { | 1515 { |
1424 Lisp_Object result = Qnil; | 1516 Lisp_Object fonttail, result = Qnil; |
1425 struct mswindows_font_enum *fontlist; | 1517 char *extpattern; |
1426 char fontname[MSW_FONTSIZE], *extpattern; | 1518 |
1427 | 1519 TO_EXTERNAL_FORMAT (LISP_STRING, pattern, |
1428 GET_C_STRING_CTEXT_DATA_ALLOCA (pattern, extpattern); | 1520 C_STRING_ALLOCA, extpattern, |
1429 fontlist = DEVICE_MSWINDOWS_FONTLIST (XDEVICE (device)); | 1521 Qctext); |
1430 while (fontlist) | 1522 |
1431 { | 1523 LIST_LOOP (fonttail, DEVICE_MSWINDOWS_FONTLIST (XDEVICE (device))) |
1432 if (match_font (fontlist->fontname, extpattern, fontname)) | 1524 { |
1433 result = Fcons (build_string (fontname), result); | 1525 if (match_font (XSTRING_DATA (XCAR (fonttail)), extpattern, NULL)) |
1434 fontlist = fontlist->next; | 1526 result = Fcons (XCAR (fonttail), result); |
1435 } | 1527 } |
1436 | 1528 |
1437 return Fnreverse (result); | 1529 return Fnreverse (result); |
1438 } | 1530 } |
1439 | 1531 |
1446 * A maximal mswindows font spec looks like: | 1538 * A maximal mswindows font spec looks like: |
1447 * Courier New:Bold Italic:10:underline strikeout:Western | 1539 * Courier New:Bold Italic:10:underline strikeout:Western |
1448 * Missing parts of the font spec should be filled in with these values: | 1540 * Missing parts of the font spec should be filled in with these values: |
1449 * Courier New:Regular:10::Western */ | 1541 * Courier New:Regular:10::Western */ |
1450 static Lisp_Object | 1542 static Lisp_Object |
1451 mswindows_font_instance_truename (struct Lisp_Font_Instance *f, Error_behavior errb) | 1543 mswindows_font_instance_truename (Lisp_Font_Instance *f, Error_behavior errb) |
1452 { | 1544 { |
1453 int nsep=0; | 1545 int nsep=0; |
1454 char *name = (char *) XSTRING_DATA (f->name); | 1546 char *name = (char *) XSTRING_DATA (f->name); |
1455 char* ptr = name; | 1547 char* ptr = name; |
1456 char* extname = alloca (strlen (name) + 19); | 1548 char* extname = alloca (strlen (name) + 19); |
1477 strcat (extname, ":Western"); | 1569 strcat (extname, ":Western"); |
1478 break; | 1570 break; |
1479 default:; | 1571 default:; |
1480 } | 1572 } |
1481 | 1573 |
1482 return build_ext_string (extname, FORMAT_OS); | 1574 return build_ext_string (extname, Qnative); |
1483 } | 1575 } |
1484 | 1576 |
1485 #ifdef MULE | 1577 #ifdef MULE |
1486 | 1578 |
1487 static int | 1579 static int |
1560 CONSOLE_HAS_METHOD (mswindows, list_fonts); | 1652 CONSOLE_HAS_METHOD (mswindows, list_fonts); |
1561 #ifdef MULE | 1653 #ifdef MULE |
1562 CONSOLE_HAS_METHOD (mswindows, font_spec_matches_charset); | 1654 CONSOLE_HAS_METHOD (mswindows, font_spec_matches_charset); |
1563 CONSOLE_HAS_METHOD (mswindows, find_charset_font); | 1655 CONSOLE_HAS_METHOD (mswindows, find_charset_font); |
1564 #endif | 1656 #endif |
1657 | |
1658 /* Printer methods - delegate most to windows methods, | |
1659 since graphical objects behave the same way. */ | |
1660 | |
1661 CONSOLE_INHERITS_METHOD (msprinter, mswindows, initialize_color_instance); | |
1662 /* CONSOLE_INHERITS_METHOD (msprinter, mswindows, mark_color_instance); */ | |
1663 CONSOLE_INHERITS_METHOD (msprinter, mswindows, print_color_instance); | |
1664 CONSOLE_INHERITS_METHOD (msprinter, mswindows, finalize_color_instance); | |
1665 CONSOLE_INHERITS_METHOD (msprinter, mswindows, color_instance_equal); | |
1666 CONSOLE_INHERITS_METHOD (msprinter, mswindows, color_instance_hash); | |
1667 CONSOLE_INHERITS_METHOD (msprinter, mswindows, color_instance_rgb_components); | |
1668 CONSOLE_INHERITS_METHOD (msprinter, mswindows, valid_color_name_p); | |
1669 | |
1670 CONSOLE_HAS_METHOD (msprinter, initialize_font_instance); | |
1671 /* CONSOLE_INHERITS_METHOD (msprinter, mswindows, mark_font_instance); */ | |
1672 CONSOLE_INHERITS_METHOD (msprinter, mswindows, print_font_instance); | |
1673 CONSOLE_INHERITS_METHOD (msprinter, mswindows, finalize_font_instance); | |
1674 CONSOLE_INHERITS_METHOD (msprinter, mswindows, font_instance_truename); | |
1675 CONSOLE_INHERITS_METHOD (msprinter, mswindows, list_fonts); | |
1676 #ifdef MULE | |
1677 CONSOLE_INHERITS_METHOD (msprinter, mswindows, font_spec_matches_charset); | |
1678 CONSOLE_INHERITS_METHOD (msprinter, mswindows, find_charset_font); | |
1679 #endif | |
1565 } | 1680 } |
1566 | 1681 |
1567 void | 1682 void |
1568 vars_of_objects_mswindows (void) | 1683 vars_of_objects_mswindows (void) |
1569 { | 1684 { |