Mercurial > emacs
comparison src/w32font.c @ 92539:d4cf72c99c2f
(w32_registry): Take font_type argument. Use ANSI
when charset not specified. Only translate ANSI to unicode when
font_type is truetype.
(w32font_coverage_ok): New function.
(add_font_entity_to_list): Use it to filter unsuitable fonts.
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Fri, 07 Mar 2008 00:44:49 +0000 |
parents | dba28a9d071a |
children | fb1da73bc0c4 |
comparison
equal
deleted
inserted
replaced
92538:30ee025de4a3 | 92539:d4cf72c99c2f |
---|---|
83 static Lisp_Object font_supported_scripts P_ ((FONTSIGNATURE * sig)); | 83 static Lisp_Object font_supported_scripts P_ ((FONTSIGNATURE * sig)); |
84 static int w32font_full_name P_ ((LOGFONT * font, Lisp_Object font_obj, | 84 static int w32font_full_name P_ ((LOGFONT * font, Lisp_Object font_obj, |
85 int pixel_size, char *name, int nbytes)); | 85 int pixel_size, char *name, int nbytes)); |
86 static void recompute_cached_metrics P_ ((HDC dc, struct w32font_info * font)); | 86 static void recompute_cached_metrics P_ ((HDC dc, struct w32font_info * font)); |
87 | 87 |
88 static Lisp_Object w32_registry P_ ((LONG w32_charset)); | 88 static Lisp_Object w32_registry P_ ((LONG w32_charset, DWORD font_type)); |
89 | 89 |
90 /* EnumFontFamiliesEx callbacks. */ | 90 /* EnumFontFamiliesEx callbacks. */ |
91 static int CALLBACK add_font_entity_to_list P_ ((ENUMLOGFONTEX *, | 91 static int CALLBACK add_font_entity_to_list P_ ((ENUMLOGFONTEX *, |
92 NEWTEXTMETRICEX *, | 92 NEWTEXTMETRICEX *, |
93 DWORD, LPARAM)); | 93 DWORD, LPARAM)); |
940 | 940 |
941 entity = Fmake_vector (make_number (FONT_ENTITY_MAX), Qnil); | 941 entity = Fmake_vector (make_number (FONT_ENTITY_MAX), Qnil); |
942 | 942 |
943 ASET (entity, FONT_TYPE_INDEX, backend); | 943 ASET (entity, FONT_TYPE_INDEX, backend); |
944 ASET (entity, FONT_FRAME_INDEX, frame); | 944 ASET (entity, FONT_FRAME_INDEX, frame); |
945 ASET (entity, FONT_REGISTRY_INDEX, w32_registry (lf->lfCharSet)); | 945 ASET (entity, FONT_REGISTRY_INDEX, w32_registry (lf->lfCharSet, font_type)); |
946 ASET (entity, FONT_OBJLIST_INDEX, Qnil); | 946 ASET (entity, FONT_OBJLIST_INDEX, Qnil); |
947 | 947 |
948 /* Foundry is difficult to get in readable form on Windows. | 948 /* Foundry is difficult to get in readable form on Windows. |
949 But Emacs crashes if it is not set, so set it to something more | 949 But Emacs crashes if it is not set, so set it to something more |
950 generic. Thes values make xflds compatible with Emacs 22. */ | 950 generic. Thes values make xflds compatible with Emacs 22. */ |
1216 } | 1216 } |
1217 } | 1217 } |
1218 return 1; | 1218 return 1; |
1219 } | 1219 } |
1220 | 1220 |
1221 static int | |
1222 w32font_coverage_ok (coverage, charset) | |
1223 FONTSIGNATURE * coverage; | |
1224 BYTE charset; | |
1225 { | |
1226 DWORD subrange1 = coverage->fsUsb[1]; | |
1227 | |
1228 #define SUBRANGE1_HAN_MASK 0x08000000 | |
1229 #define SUBRANGE1_HANGEUL_MASK 0x01000000 | |
1230 #define SUBRANGE1_JAPANESE_MASK (0x00060000 | SUBRANGE1_HAN_MASK) | |
1231 | |
1232 if (charset == GB2312_CHARSET || charset == CHINESEBIG5_CHARSET) | |
1233 { | |
1234 return (subrange1 & SUBRANGE1_HAN_MASK) == SUBRANGE1_HAN_MASK; | |
1235 } | |
1236 else if (charset == SHIFTJIS_CHARSET) | |
1237 { | |
1238 return (subrange1 & SUBRANGE1_JAPANESE_MASK) == SUBRANGE1_JAPANESE_MASK; | |
1239 } | |
1240 else if (charset == HANGEUL_CHARSET) | |
1241 { | |
1242 return (subrange1 & SUBRANGE1_HANGEUL_MASK) == SUBRANGE1_HANGEUL_MASK; | |
1243 } | |
1244 | |
1245 return 1; | |
1246 } | |
1247 | |
1221 /* Callback function for EnumFontFamiliesEx. | 1248 /* Callback function for EnumFontFamiliesEx. |
1222 * Checks if a font matches everything we are trying to check agaist, | 1249 * Checks if a font matches everything we are trying to check agaist, |
1223 * and if so, adds it to a list. Both the data we are checking against | 1250 * and if so, adds it to a list. Both the data we are checking against |
1224 * and the list to which the fonts are added are passed in via the | 1251 * and the list to which the fonts are added are passed in via the |
1225 * lparam argument, in the form of a font_callback_data struct. */ | 1252 * lparam argument, in the form of a font_callback_data struct. */ |
1236 if ((!match_data->opentype_only | 1263 if ((!match_data->opentype_only |
1237 || (physical_font->ntmTm.ntmFlags & NTMFLAGS_OPENTYPE)) | 1264 || (physical_font->ntmTm.ntmFlags & NTMFLAGS_OPENTYPE)) |
1238 && logfonts_match (&logical_font->elfLogFont, &match_data->pattern) | 1265 && logfonts_match (&logical_font->elfLogFont, &match_data->pattern) |
1239 && font_matches_spec (font_type, physical_font, | 1266 && font_matches_spec (font_type, physical_font, |
1240 match_data->orig_font_spec) | 1267 match_data->orig_font_spec) |
1268 && w32font_coverage_ok (&physical_font->ntmFontSig, | |
1269 match_data->pattern.lfCharSet) | |
1241 /* Avoid substitutions involving raster fonts (eg Helv -> MS Sans Serif) | 1270 /* Avoid substitutions involving raster fonts (eg Helv -> MS Sans Serif) |
1242 We limit this to raster fonts, because the test can catch some | 1271 We limit this to raster fonts, because the test can catch some |
1243 genuine fonts (eg the full name of DejaVu Sans Mono Light is actually | 1272 genuine fonts (eg the full name of DejaVu Sans Mono Light is actually |
1244 DejaVu Sans Mono ExtraLight). Helvetica -> Arial substitution will | 1273 DejaVu Sans Mono ExtraLight). Helvetica -> Arial substitution will |
1245 therefore get through this test. Since full names can be prefixed | 1274 therefore get through this test. Since full names can be prefixed |
1295 else | 1324 else |
1296 return DEFAULT_CHARSET; | 1325 return DEFAULT_CHARSET; |
1297 } | 1326 } |
1298 | 1327 |
1299 static Lisp_Object | 1328 static Lisp_Object |
1300 w32_registry (w32_charset) | 1329 w32_registry (w32_charset, font_type) |
1301 LONG w32_charset; | 1330 LONG w32_charset; |
1302 { | 1331 DWORD font_type; |
1303 if (w32_charset == ANSI_CHARSET) | 1332 { |
1333 /* If charset is defaulted, use ANSI (unicode for truetype fonts). */ | |
1334 if (w32_charset == DEFAULT_CHARSET) | |
1335 w32_charset = ANSI_CHARSET; | |
1336 | |
1337 if (font_type == TRUETYPE_FONTTYPE && w32_charset == ANSI_CHARSET) | |
1304 return Qiso10646_1; | 1338 return Qiso10646_1; |
1305 else | 1339 else |
1306 { | 1340 { |
1307 char * charset = w32_to_x_charset (w32_charset, NULL); | 1341 char * charset = w32_to_x_charset (w32_charset, NULL); |
1308 return intern_downcase (charset, strlen(charset)); | 1342 return intern_downcase (charset, strlen(charset)); |