Commit | Line | Data |
---|---|---|
f7a84cb4 | 1 | /* Font backend for the Microsoft W32 API. |
acaf905b | 2 | Copyright (C) 2007-2012 Free Software Foundation, Inc. |
f7a84cb4 JR |
3 | |
4 | This file is part of GNU Emacs. | |
5 | ||
9ec0b715 | 6 | GNU Emacs is free software: you can redistribute it and/or modify |
f7a84cb4 | 7 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
8 | the Free Software Foundation, either version 3 of the License, or |
9 | (at your option) any later version. | |
f7a84cb4 JR |
10 | |
11 | GNU Emacs is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 17 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
f7a84cb4 JR |
18 | |
19 | #include <config.h> | |
20 | #include <windows.h> | |
09fe06b7 | 21 | #include <math.h> |
0500dcc9 | 22 | #include <ctype.h> |
6fe9826d | 23 | #include <commdlg.h> |
d7306fe6 | 24 | #include <setjmp.h> |
f7a84cb4 JR |
25 | |
26 | #include "lisp.h" | |
27 | #include "w32term.h" | |
28 | #include "frame.h" | |
29 | #include "dispextern.h" | |
30 | #include "character.h" | |
31 | #include "charset.h" | |
e6df5336 | 32 | #include "coding.h" |
f7a84cb4 JR |
33 | #include "fontset.h" |
34 | #include "font.h" | |
46fd1ded | 35 | #include "w32font.h" |
f7a84cb4 | 36 | |
91583281 JR |
37 | /* Cleartype available on Windows XP, cleartype_natural from XP SP1. |
38 | The latter does not try to fit cleartype smoothed fonts into the | |
39 | same bounding box as the non-antialiased version of the font. | |
40 | */ | |
41 | #ifndef CLEARTYPE_QUALITY | |
42 | #define CLEARTYPE_QUALITY 5 | |
43 | #endif | |
44 | #ifndef CLEARTYPE_NATURAL_QUALITY | |
45 | #define CLEARTYPE_NATURAL_QUALITY 6 | |
46 | #endif | |
47 | ||
57016d37 JR |
48 | /* VIETNAMESE_CHARSET and JOHAB_CHARSET are not defined in some versions |
49 | of MSVC headers. */ | |
50 | #ifndef VIETNAMESE_CHARSET | |
51 | #define VIETNAMESE_CHARSET 163 | |
52 | #endif | |
53 | #ifndef JOHAB_CHARSET | |
54 | #define JOHAB_CHARSET 130 | |
55 | #endif | |
56 | ||
91583281 | 57 | Lisp_Object Qgdi; |
34fd2d28 JR |
58 | Lisp_Object Quniscribe; |
59 | static Lisp_Object QCformat; | |
9e1a2995 JR |
60 | static Lisp_Object Qmonospace, Qsansserif, Qmono, Qsans, Qsans_serif; |
61 | static Lisp_Object Qserif, Qscript, Qdecorative; | |
62 | static Lisp_Object Qraster, Qoutline, Qunknown; | |
d205d43b | 63 | |
91583281 | 64 | /* antialiasing */ |
91583281 JR |
65 | extern Lisp_Object Qnone; /* reuse from w32fns.c */ |
66 | static Lisp_Object Qstandard, Qsubpixel, Qnatural; | |
67 | ||
8f112d52 | 68 | /* languages */ |
314d66f4 | 69 | static Lisp_Object Qzh; |
8f112d52 | 70 | |
d205d43b | 71 | /* scripts */ |
a11889ab | 72 | static Lisp_Object Qgreek, Qcoptic, Qcyrillic, Qarmenian, Qhebrew; |
d205d43b JR |
73 | static Lisp_Object Qarabic, Qsyriac, Qnko, Qthaana, Qdevanagari, Qbengali; |
74 | static Lisp_Object Qgurmukhi, Qgujarati, Qoriya, Qtamil, Qtelugu; | |
75 | static Lisp_Object Qkannada, Qmalayalam, Qsinhala, Qthai, Qlao; | |
76 | static Lisp_Object Qtibetan, Qmyanmar, Qgeorgian, Qhangul, Qethiopic; | |
77 | static Lisp_Object Qcherokee, Qcanadian_aboriginal, Qogham, Qrunic; | |
78 | static Lisp_Object Qkhmer, Qmongolian, Qsymbol, Qbraille, Qhan; | |
79 | static Lisp_Object Qideographic_description, Qcjk_misc, Qkana, Qbopomofo; | |
80 | static Lisp_Object Qkanbun, Qyi, Qbyzantine_musical_symbol; | |
174f1c74 | 81 | static Lisp_Object Qmusical_symbol, Qmathematical, Qcham, Qphonetic; |
56df6710 JR |
82 | /* Not defined in characters.el, but referenced in fontset.el. */ |
83 | static Lisp_Object Qbalinese, Qbuginese, Qbuhid, Qcuneiform, Qcypriot; | |
84 | static Lisp_Object Qdeseret, Qglagolitic, Qgothic, Qhanunoo, Qkharoshthi; | |
85 | static Lisp_Object Qlimbu, Qlinear_b, Qold_italic, Qold_persian, Qosmanya; | |
86 | static Lisp_Object Qphags_pa, Qphoenician, Qshavian, Qsyloti_nagri; | |
87 | static Lisp_Object Qtagalog, Qtagbanwa, Qtai_le, Qtifinagh, Qugaritic; | |
d205d43b | 88 | |
57016d37 JR |
89 | /* W32 charsets: for use in Vw32_charset_info_alist. */ |
90 | static Lisp_Object Qw32_charset_ansi, Qw32_charset_default; | |
91 | static Lisp_Object Qw32_charset_symbol, Qw32_charset_shiftjis; | |
92 | static Lisp_Object Qw32_charset_hangeul, Qw32_charset_gb2312; | |
93 | static Lisp_Object Qw32_charset_chinesebig5, Qw32_charset_oem; | |
94 | static Lisp_Object Qw32_charset_easteurope, Qw32_charset_turkish; | |
95 | static Lisp_Object Qw32_charset_baltic, Qw32_charset_russian; | |
96 | static Lisp_Object Qw32_charset_arabic, Qw32_charset_greek; | |
97 | static Lisp_Object Qw32_charset_hebrew, Qw32_charset_vietnamese; | |
98 | static Lisp_Object Qw32_charset_thai, Qw32_charset_johab, Qw32_charset_mac; | |
99 | ||
d205d43b JR |
100 | /* Font spacing symbols - defined in font.c. */ |
101 | extern Lisp_Object Qc, Qp, Qm; | |
f7a84cb4 | 102 | |
f57e2426 | 103 | static void fill_in_logfont (FRAME_PTR, LOGFONT *, Lisp_Object); |
f7a84cb4 | 104 | |
f57e2426 J |
105 | static BYTE w32_antialias_type (Lisp_Object); |
106 | static Lisp_Object lispy_antialias_type (BYTE); | |
91583281 | 107 | |
f57e2426 J |
108 | static Lisp_Object font_supported_scripts (FONTSIGNATURE *); |
109 | static int w32font_full_name (LOGFONT *, Lisp_Object, int, char *, int); | |
110 | static void compute_metrics (HDC, struct w32font_info *, unsigned int, | |
111 | struct w32_metric_cache *); | |
f7a84cb4 | 112 | |
f57e2426 | 113 | static Lisp_Object w32_registry (LONG, DWORD); |
f7a84cb4 JR |
114 | |
115 | /* EnumFontFamiliesEx callbacks. */ | |
f57e2426 J |
116 | static int CALLBACK add_font_entity_to_list (ENUMLOGFONTEX *, |
117 | NEWTEXTMETRICEX *, | |
118 | DWORD, LPARAM); | |
119 | static int CALLBACK add_one_font_entity_to_list (ENUMLOGFONTEX *, | |
f7a84cb4 | 120 | NEWTEXTMETRICEX *, |
f57e2426 J |
121 | DWORD, LPARAM); |
122 | static int CALLBACK add_font_name_to_list (ENUMLOGFONTEX *, | |
123 | NEWTEXTMETRICEX *, | |
124 | DWORD, LPARAM); | |
f7a84cb4 | 125 | |
d205d43b JR |
126 | /* struct passed in as LPARAM arg to EnumFontFamiliesEx, for keeping track |
127 | of what we really want. */ | |
128 | struct font_callback_data | |
129 | { | |
130 | /* The logfont we are matching against. EnumFontFamiliesEx only matches | |
131 | face name and charset, so we need to manually match everything else | |
132 | in the callback function. */ | |
133 | LOGFONT pattern; | |
134 | /* The original font spec or entity. */ | |
135 | Lisp_Object orig_font_spec; | |
136 | /* The frame the font is being loaded on. */ | |
137 | Lisp_Object frame; | |
138 | /* The list to add matches to. */ | |
139 | Lisp_Object list; | |
46fd1ded JR |
140 | /* Whether to match only opentype fonts. */ |
141 | int opentype_only; | |
d205d43b JR |
142 | }; |
143 | ||
144 | /* Handles the problem that EnumFontFamiliesEx will not return all | |
145 | style variations if the font name is not specified. */ | |
f57e2426 | 146 | static void list_all_matching_fonts (struct font_callback_data *); |
d205d43b | 147 | |
db4f02f2 EZ |
148 | static BOOL g_b_init_is_w9x; |
149 | static BOOL g_b_init_get_outline_metrics_w; | |
150 | static BOOL g_b_init_get_text_metrics_w; | |
151 | static BOOL g_b_init_get_glyph_outline_w; | |
152 | static BOOL g_b_init_get_glyph_outline_w; | |
153 | ||
154 | typedef UINT (WINAPI * GetOutlineTextMetricsW_Proc) ( | |
155 | HDC hdc, | |
156 | UINT cbData, | |
157 | LPOUTLINETEXTMETRICW lpotmw); | |
158 | typedef BOOL (WINAPI * GetTextMetricsW_Proc) ( | |
159 | HDC hdc, | |
160 | LPTEXTMETRICW lptmw); | |
161 | typedef DWORD (WINAPI * GetGlyphOutlineW_Proc) ( | |
162 | HDC hdc, | |
163 | UINT uChar, | |
164 | UINT uFormat, | |
165 | LPGLYPHMETRICS lpgm, | |
166 | DWORD cbBuffer, | |
167 | LPVOID lpvBuffer, | |
168 | const MAT2 *lpmat2); | |
169 | ||
170 | /* Several "wide" functions we use to support the font backends are | |
171 | unavailable on Windows 9X, unless UNICOWS.DLL is installed (their | |
172 | versions in the default libraries are non-functional stubs). On NT | |
173 | and later systems, these functions are in GDI32.DLL. The following | |
174 | helper function attempts to load UNICOWS.DLL on Windows 9X, and | |
175 | refuses to let Emacs start up if that library is not found. On NT | |
176 | and later versions, it simply loads GDI32.DLL, which should always | |
177 | be available. */ | |
178 | static HMODULE | |
179 | w32_load_unicows_or_gdi32 (void) | |
180 | { | |
181 | static BOOL is_9x = 0; | |
182 | OSVERSIONINFO os_ver; | |
183 | HMODULE ret; | |
184 | if (g_b_init_is_w9x == 0) | |
185 | { | |
186 | g_b_init_is_w9x = 1; | |
187 | ZeroMemory (&os_ver, sizeof (OSVERSIONINFO)); | |
188 | os_ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); | |
189 | if (GetVersionEx (&os_ver)) | |
190 | is_9x = (os_ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS); | |
191 | } | |
192 | if (is_9x) | |
193 | { | |
194 | ret = LoadLibrary ("Unicows.dll"); | |
195 | if (!ret) | |
196 | { | |
197 | int button; | |
198 | ||
199 | button = MessageBox (NULL, | |
200 | "Emacs cannot load the UNICOWS.DLL library.\n" | |
201 | "This library is essential for using Emacs\n" | |
202 | "on this system. You need to install it.\n\n" | |
203 | "However, you can still use Emacs by invoking\n" | |
204 | "it with the '-nw' command-line option.\n\n" | |
205 | "Emacs will exit when you click OK.", | |
206 | "Emacs cannot load UNICOWS.DLL", | |
207 | MB_ICONERROR | MB_TASKMODAL | |
208 | | MB_SETFOREGROUND | MB_OK); | |
209 | switch (button) | |
210 | { | |
211 | case IDOK: | |
212 | default: | |
213 | exit (1); | |
214 | } | |
215 | } | |
216 | } | |
217 | else | |
218 | ret = LoadLibrary ("Gdi32.dll"); | |
c20992f4 | 219 | return ret; |
db4f02f2 EZ |
220 | } |
221 | ||
222 | /* The following 3 functions call the problematic "wide" APIs via | |
223 | function pointers, to avoid linking against the non-standard | |
224 | libunicows on W9X. */ | |
225 | static UINT WINAPI | |
226 | get_outline_metrics_w(HDC hdc, UINT cbData, LPOUTLINETEXTMETRICW lpotmw) | |
227 | { | |
228 | static GetOutlineTextMetricsW_Proc s_pfn_Get_Outline_Text_MetricsW = NULL; | |
229 | HMODULE hm_unicows = NULL; | |
230 | if (g_b_init_get_outline_metrics_w == 0) | |
231 | { | |
232 | g_b_init_get_outline_metrics_w = 1; | |
233 | hm_unicows = w32_load_unicows_or_gdi32 (); | |
234 | if (hm_unicows) | |
235 | s_pfn_Get_Outline_Text_MetricsW = (GetOutlineTextMetricsW_Proc) | |
236 | GetProcAddress (hm_unicows, "GetOutlineTextMetricsW"); | |
237 | } | |
238 | if (s_pfn_Get_Outline_Text_MetricsW == NULL) | |
239 | abort (); /* cannot happen */ | |
240 | return s_pfn_Get_Outline_Text_MetricsW (hdc, cbData, lpotmw); | |
241 | } | |
242 | ||
243 | static BOOL WINAPI | |
244 | get_text_metrics_w(HDC hdc, LPTEXTMETRICW lptmw) | |
245 | { | |
246 | static GetTextMetricsW_Proc s_pfn_Get_Text_MetricsW = NULL; | |
247 | HMODULE hm_unicows = NULL; | |
248 | if (g_b_init_get_text_metrics_w == 0) | |
249 | { | |
250 | g_b_init_get_text_metrics_w = 1; | |
251 | hm_unicows = w32_load_unicows_or_gdi32 (); | |
252 | if (hm_unicows) | |
253 | s_pfn_Get_Text_MetricsW = (GetTextMetricsW_Proc) | |
254 | GetProcAddress (hm_unicows, "GetTextMetricsW"); | |
255 | } | |
256 | if (s_pfn_Get_Text_MetricsW == NULL) | |
257 | abort (); /* cannot happen */ | |
258 | return s_pfn_Get_Text_MetricsW (hdc, lptmw); | |
259 | } | |
260 | ||
261 | static DWORD WINAPI | |
262 | get_glyph_outline_w (HDC hdc, UINT uChar, UINT uFormat, LPGLYPHMETRICS lpgm, | |
263 | DWORD cbBuffer, LPVOID lpvBuffer, const MAT2 *lpmat2) | |
264 | { | |
265 | static GetGlyphOutlineW_Proc s_pfn_Get_Glyph_OutlineW = NULL; | |
266 | HMODULE hm_unicows = NULL; | |
267 | if (g_b_init_get_glyph_outline_w == 0) | |
268 | { | |
269 | g_b_init_get_glyph_outline_w = 1; | |
270 | hm_unicows = w32_load_unicows_or_gdi32 (); | |
271 | if (hm_unicows) | |
272 | s_pfn_Get_Glyph_OutlineW = (GetGlyphOutlineW_Proc) | |
273 | GetProcAddress (hm_unicows, "GetGlyphOutlineW"); | |
274 | } | |
275 | if (s_pfn_Get_Glyph_OutlineW == NULL) | |
276 | abort (); /* cannot happen */ | |
277 | return s_pfn_Get_Glyph_OutlineW (hdc, uChar, uFormat, lpgm, cbBuffer, | |
278 | lpvBuffer, lpmat2); | |
279 | } | |
f7a84cb4 JR |
280 | |
281 | static int | |
b56ceb92 | 282 | memq_no_quit (Lisp_Object elt, Lisp_Object list) |
f7a84cb4 JR |
283 | { |
284 | while (CONSP (list) && ! EQ (XCAR (list), elt)) | |
285 | list = XCDR (list); | |
286 | return (CONSP (list)); | |
287 | } | |
288 | ||
e6df5336 | 289 | Lisp_Object |
b56ceb92 | 290 | intern_font_name (char * string) |
e6df5336 JR |
291 | { |
292 | Lisp_Object obarray, tem, str; | |
293 | int len; | |
294 | ||
295 | str = DECODE_SYSTEM (build_string (string)); | |
296 | len = SCHARS (str); | |
297 | ||
298 | /* The following code is copied from the function intern (in lread.c). */ | |
299 | obarray = Vobarray; | |
77b37c05 | 300 | if (!VECTORP (obarray) || ASIZE (obarray) == 0) |
e6df5336 JR |
301 | obarray = check_obarray (obarray); |
302 | tem = oblookup (obarray, SDATA (str), len, len); | |
303 | if (SYMBOLP (tem)) | |
304 | return tem; | |
305 | return Fintern (str, obarray); | |
306 | } | |
307 | ||
f7a84cb4 JR |
308 | /* w32 implementation of get_cache for font backend. |
309 | Return a cache of font-entities on FRAME. The cache must be a | |
310 | cons whose cdr part is the actual cache area. */ | |
46fd1ded | 311 | Lisp_Object |
b56ceb92 | 312 | w32font_get_cache (FRAME_PTR f) |
f7a84cb4 | 313 | { |
a4c71909 | 314 | struct w32_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
f7a84cb4 JR |
315 | |
316 | return (dpyinfo->name_list_element); | |
317 | } | |
318 | ||
319 | /* w32 implementation of list for font backend. | |
320 | List fonts exactly matching with FONT_SPEC on FRAME. The value | |
321 | is a vector of font-entities. This is the sole API that | |
322 | allocates font-entities. */ | |
20399669 | 323 | static Lisp_Object |
b56ceb92 | 324 | w32font_list (Lisp_Object frame, Lisp_Object font_spec) |
f7a84cb4 | 325 | { |
07d9ba9b | 326 | Lisp_Object fonts = w32font_list_internal (frame, font_spec, 0); |
678dca3d | 327 | FONT_ADD_LOG ("w32font-list", font_spec, fonts); |
07d9ba9b | 328 | return fonts; |
f7a84cb4 JR |
329 | } |
330 | ||
331 | /* w32 implementation of match for font backend. | |
332 | Return a font entity most closely matching with FONT_SPEC on | |
4c36be58 | 333 | FRAME. The closeness is determined by the font backend, thus |
f7a84cb4 | 334 | `face-font-selection-order' is ignored here. */ |
20399669 | 335 | static Lisp_Object |
b56ceb92 | 336 | w32font_match (Lisp_Object frame, Lisp_Object font_spec) |
f7a84cb4 | 337 | { |
07d9ba9b | 338 | Lisp_Object entity = w32font_match_internal (frame, font_spec, 0); |
678dca3d | 339 | FONT_ADD_LOG ("w32font-match", font_spec, entity); |
07d9ba9b | 340 | return entity; |
f7a84cb4 JR |
341 | } |
342 | ||
f7a84cb4 JR |
343 | /* w32 implementation of list_family for font backend. |
344 | List available families. The value is a list of family names | |
345 | (symbols). */ | |
20399669 | 346 | static Lisp_Object |
b56ceb92 | 347 | w32font_list_family (Lisp_Object frame) |
f7a84cb4 JR |
348 | { |
349 | Lisp_Object list = Qnil; | |
350 | LOGFONT font_match_pattern; | |
351 | HDC dc; | |
352 | FRAME_PTR f = XFRAME (frame); | |
353 | ||
72af86bd | 354 | memset (&font_match_pattern, 0, sizeof (font_match_pattern)); |
56df6710 | 355 | font_match_pattern.lfCharSet = DEFAULT_CHARSET; |
f7a84cb4 JR |
356 | |
357 | dc = get_frame_dc (f); | |
358 | ||
359 | EnumFontFamiliesEx (dc, &font_match_pattern, | |
360 | (FONTENUMPROC) add_font_name_to_list, | |
361 | (LPARAM) &list, 0); | |
362 | release_frame_dc (f, dc); | |
363 | ||
364 | return list; | |
365 | } | |
366 | ||
367 | /* w32 implementation of open for font backend. | |
368 | Open a font specified by FONT_ENTITY on frame F. | |
369 | If the font is scalable, open it with PIXEL_SIZE. */ | |
5f18d119 | 370 | static Lisp_Object |
b56ceb92 | 371 | w32font_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) |
f7a84cb4 | 372 | { |
bd187c49 JR |
373 | Lisp_Object font_object |
374 | = font_make_object (VECSIZE (struct w32font_info), | |
375 | font_entity, pixel_size); | |
376 | struct w32font_info *w32_font | |
377 | = (struct w32font_info *) XFONT_OBJECT (font_object); | |
f7a84cb4 | 378 | |
4b135503 | 379 | ASET (font_object, FONT_TYPE_INDEX, Qgdi); |
f7a84cb4 | 380 | |
5f18d119 | 381 | if (!w32font_open_internal (f, font_entity, pixel_size, font_object)) |
f7a84cb4 | 382 | { |
5f18d119 | 383 | return Qnil; |
f7a84cb4 JR |
384 | } |
385 | ||
bd187c49 JR |
386 | /* GDI backend does not use glyph indices. */ |
387 | w32_font->glyph_idx = 0; | |
388 | ||
5f18d119 | 389 | return font_object; |
f7a84cb4 JR |
390 | } |
391 | ||
392 | /* w32 implementation of close for font_backend. | |
393 | Close FONT on frame F. */ | |
46fd1ded | 394 | void |
b56ceb92 | 395 | w32font_close (FRAME_PTR f, struct font *font) |
f7a84cb4 | 396 | { |
c35f9821 | 397 | int i; |
5f18d119 | 398 | struct w32font_info *w32_font = (struct w32font_info *) font; |
c35f9821 JR |
399 | |
400 | /* Delete the GDI font object. */ | |
1b5defe6 | 401 | DeleteObject (w32_font->hfont); |
c35f9821 JR |
402 | |
403 | /* Free all the cached metrics. */ | |
404 | if (w32_font->cached_metrics) | |
405 | { | |
406 | for (i = 0; i < w32_font->n_cache_blocks; i++) | |
407 | { | |
5f445726 | 408 | xfree (w32_font->cached_metrics[i]); |
c35f9821 JR |
409 | } |
410 | xfree (w32_font->cached_metrics); | |
411 | w32_font->cached_metrics = NULL; | |
412 | } | |
f7a84cb4 JR |
413 | } |
414 | ||
415 | /* w32 implementation of has_char for font backend. | |
416 | Optional. | |
417 | If FONT_ENTITY has a glyph for character C (Unicode code point), | |
418 | return 1. If not, return 0. If a font must be opened to check | |
419 | it, return -1. */ | |
46fd1ded | 420 | int |
b56ceb92 | 421 | w32font_has_char (Lisp_Object entity, int c) |
f7a84cb4 | 422 | { |
e6eee6ae JR |
423 | /* We can't be certain about which characters a font will support until |
424 | we open it. Checking the scripts that the font supports turns out | |
425 | to not be reliable. */ | |
426 | return -1; | |
427 | ||
428 | #if 0 | |
d205d43b | 429 | Lisp_Object supported_scripts, extra, script; |
f7a84cb4 JR |
430 | DWORD mask; |
431 | ||
01dbeb0b JR |
432 | extra = AREF (entity, FONT_EXTRA_INDEX); |
433 | if (!CONSP (extra)) | |
434 | return -1; | |
435 | ||
d205d43b | 436 | supported_scripts = assq_no_quit (QCscript, extra); |
6a8082b5 JR |
437 | /* If font doesn't claim to support any scripts, then we can't be certain |
438 | until we open it. */ | |
d205d43b | 439 | if (!CONSP (supported_scripts)) |
f7a84cb4 JR |
440 | return -1; |
441 | ||
d205d43b | 442 | supported_scripts = XCDR (supported_scripts); |
f7a84cb4 | 443 | |
d205d43b | 444 | script = CHAR_TABLE_REF (Vchar_script_table, c); |
f7a84cb4 | 445 | |
6a8082b5 JR |
446 | /* If we don't know what script the character is from, then we can't be |
447 | certain until we open it. Also if the font claims support for the script | |
448 | the character is from, it may only have partial coverage, so we still | |
449 | can't be certain until we open the font. */ | |
450 | if (NILP (script) || memq_no_quit (script, supported_scripts)) | |
451 | return -1; | |
452 | ||
453 | /* Font reports what scripts it supports, and none of them are the script | |
e6eee6ae JR |
454 | the character is from. But we still can't be certain, as some fonts |
455 | will contain some/most/all of the characters in that script without | |
456 | claiming support for it. */ | |
457 | return -1; | |
458 | #endif | |
f7a84cb4 JR |
459 | } |
460 | ||
461 | /* w32 implementation of encode_char for font backend. | |
51e4f4a8 | 462 | Return a glyph code of FONT for character C (Unicode code point). |
bd187c49 JR |
463 | If FONT doesn't have such a glyph, return FONT_INVALID_CODE. |
464 | ||
fe7a3057 | 465 | For speed, the gdi backend uses Unicode (Emacs calls encode_char |
bd187c49 JR |
466 | far too often for it to be efficient). But we still need to detect |
467 | which characters are not supported by the font. | |
468 | */ | |
34fd2d28 | 469 | static unsigned |
b56ceb92 | 470 | w32font_encode_char (struct font *font, int c) |
f7a84cb4 | 471 | { |
bd187c49 | 472 | struct w32font_info * w32_font = (struct w32font_info *)font; |
34fd2d28 | 473 | |
bd187c49 JR |
474 | if (c < w32_font->metrics.tmFirstChar |
475 | || c > w32_font->metrics.tmLastChar) | |
476 | return FONT_INVALID_CODE; | |
34fd2d28 | 477 | else |
bd187c49 | 478 | return c; |
f7a84cb4 JR |
479 | } |
480 | ||
481 | /* w32 implementation of text_extents for font backend. | |
482 | Perform the size computation of glyphs of FONT and fillin members | |
483 | of METRICS. The glyphs are specified by their glyph codes in | |
78573c57 | 484 | CODE (length NGLYPHS). Apparently metrics can be NULL, in this |
f7a84cb4 | 485 | case just return the overall width. */ |
46fd1ded | 486 | int |
b56ceb92 JB |
487 | w32font_text_extents (struct font *font, unsigned *code, |
488 | int nglyphs, struct font_metrics *metrics) | |
f7a84cb4 JR |
489 | { |
490 | int i; | |
2a36efcf JR |
491 | HFONT old_font = NULL; |
492 | HDC dc = NULL; | |
46fd1ded | 493 | struct frame * f; |
f7a84cb4 | 494 | int total_width = 0; |
f31cf550 | 495 | WORD *wcode; |
d205d43b | 496 | SIZE size; |
f7a84cb4 | 497 | |
1b5defe6 JR |
498 | struct w32font_info *w32_font = (struct w32font_info *) font; |
499 | ||
f7a84cb4 JR |
500 | if (metrics) |
501 | { | |
72af86bd | 502 | memset (metrics, 0, sizeof (struct font_metrics)); |
388c38f9 JR |
503 | metrics->ascent = font->ascent; |
504 | metrics->descent = font->descent; | |
f7a84cb4 JR |
505 | |
506 | for (i = 0; i < nglyphs; i++) | |
507 | { | |
8f112d52 JR |
508 | struct w32_metric_cache *char_metric; |
509 | int block = *(code + i) / CACHE_BLOCKSIZE; | |
510 | int pos_in_block = *(code + i) % CACHE_BLOCKSIZE; | |
511 | ||
512 | if (block >= w32_font->n_cache_blocks) | |
513 | { | |
514 | if (!w32_font->cached_metrics) | |
515 | w32_font->cached_metrics | |
516 | = xmalloc ((block + 1) | |
9cac6313 | 517 | * sizeof (struct w32_metric_cache *)); |
8f112d52 JR |
518 | else |
519 | w32_font->cached_metrics | |
520 | = xrealloc (w32_font->cached_metrics, | |
521 | (block + 1) | |
9cac6313 | 522 | * sizeof (struct w32_metric_cache *)); |
72af86bd AS |
523 | memset (w32_font->cached_metrics + w32_font->n_cache_blocks, 0, |
524 | ((block + 1 - w32_font->n_cache_blocks) | |
525 | * sizeof (struct w32_metric_cache *))); | |
8f112d52 JR |
526 | w32_font->n_cache_blocks = block + 1; |
527 | } | |
528 | ||
529 | if (!w32_font->cached_metrics[block]) | |
530 | { | |
531 | w32_font->cached_metrics[block] | |
9cac6313 | 532 | = xmalloc (CACHE_BLOCKSIZE * sizeof (struct w32_metric_cache)); |
72af86bd AS |
533 | memset (w32_font->cached_metrics[block], 0, |
534 | CACHE_BLOCKSIZE * sizeof (struct w32_metric_cache)); | |
8f112d52 JR |
535 | } |
536 | ||
537 | char_metric = w32_font->cached_metrics[block] + pos_in_block; | |
538 | ||
539 | if (char_metric->status == W32METRIC_NO_ATTEMPT) | |
540 | { | |
541 | if (dc == NULL) | |
542 | { | |
543 | /* TODO: Frames can come and go, and their fonts | |
544 | outlive them. So we can't cache the frame in the | |
545 | font structure. Use selected_frame until the API | |
546 | is updated to pass in a frame. */ | |
547 | f = XFRAME (selected_frame); | |
9c623c85 | 548 | |
2a36efcf | 549 | dc = get_frame_dc (f); |
1b5defe6 | 550 | old_font = SelectObject (dc, w32_font->hfont); |
8f112d52 JR |
551 | } |
552 | compute_metrics (dc, w32_font, *(code + i), char_metric); | |
553 | } | |
78573c57 | 554 | |
8f112d52 JR |
555 | if (char_metric->status == W32METRIC_SUCCESS) |
556 | { | |
557 | metrics->lbearing = min (metrics->lbearing, | |
558 | metrics->width + char_metric->lbearing); | |
559 | metrics->rbearing = max (metrics->rbearing, | |
560 | metrics->width + char_metric->rbearing); | |
561 | metrics->width += char_metric->width; | |
562 | } | |
563 | else | |
564 | /* If we couldn't get metrics for a char, | |
565 | use alternative method. */ | |
566 | break; | |
567 | } | |
78573c57 JR |
568 | /* If we got through everything, return. */ |
569 | if (i == nglyphs) | |
570 | { | |
2a36efcf JR |
571 | if (dc != NULL) |
572 | { | |
573 | /* Restore state and release DC. */ | |
574 | SelectObject (dc, old_font); | |
575 | release_frame_dc (f, dc); | |
576 | } | |
78573c57 JR |
577 | |
578 | return metrics->width; | |
579 | } | |
f7a84cb4 | 580 | } |
78573c57 | 581 | |
56df6710 JR |
582 | /* For non-truetype fonts, GetGlyphOutlineW is not supported, so |
583 | fallback on other methods that will at least give some of the metric | |
584 | information. */ | |
b003e5ff | 585 | |
f31cf550 JR |
586 | /* Make array big enough to hold surrogates. */ |
587 | wcode = alloca (nglyphs * sizeof (WORD) * 2); | |
588 | for (i = 0; i < nglyphs; i++) | |
589 | { | |
590 | if (code[i] < 0x10000) | |
591 | wcode[i] = code[i]; | |
592 | else | |
593 | { | |
594 | DWORD surrogate = code[i] - 0x10000; | |
595 | ||
596 | /* High surrogate: U+D800 - U+DBFF. */ | |
597 | wcode[i++] = 0xD800 + ((surrogate >> 10) & 0x03FF); | |
598 | /* Low surrogate: U+DC00 - U+DFFF. */ | |
599 | wcode[i] = 0xDC00 + (surrogate & 0x03FF); | |
600 | /* An extra glyph. wcode is already double the size of code to | |
601 | cope with this. */ | |
602 | nglyphs++; | |
603 | } | |
604 | } | |
605 | ||
2a36efcf JR |
606 | if (dc == NULL) |
607 | { | |
8f112d52 JR |
608 | /* TODO: Frames can come and go, and their fonts outlive |
609 | them. So we can't cache the frame in the font structure. Use | |
610 | selected_frame until the API is updated to pass in a | |
611 | frame. */ | |
612 | f = XFRAME (selected_frame); | |
613 | ||
2a36efcf | 614 | dc = get_frame_dc (f); |
1b5defe6 | 615 | old_font = SelectObject (dc, w32_font->hfont); |
2a36efcf JR |
616 | } |
617 | ||
d205d43b | 618 | if (GetTextExtentPoint32W (dc, wcode, nglyphs, &size)) |
f7a84cb4 | 619 | { |
d205d43b | 620 | total_width = size.cx; |
f7a84cb4 JR |
621 | } |
622 | ||
fe7a3057 | 623 | /* On 95/98/ME, only some Unicode functions are available, so fallback |
56df6710 | 624 | on doing a dummy draw to find the total width. */ |
d205d43b | 625 | if (!total_width) |
f7a84cb4 JR |
626 | { |
627 | RECT rect; | |
5f18d119 | 628 | rect.top = 0; rect.bottom = font->height; rect.left = 0; rect.right = 1; |
f7a84cb4 JR |
629 | DrawTextW (dc, wcode, nglyphs, &rect, |
630 | DT_CALCRECT | DT_NOPREFIX | DT_SINGLELINE); | |
631 | total_width = rect.right; | |
632 | } | |
d205d43b | 633 | |
56df6710 | 634 | /* Give our best estimate of the metrics, based on what we know. */ |
78573c57 JR |
635 | if (metrics) |
636 | { | |
79ca7db1 | 637 | metrics->width = total_width - w32_font->metrics.tmOverhang; |
78573c57 | 638 | metrics->lbearing = 0; |
79ca7db1 | 639 | metrics->rbearing = total_width; |
78573c57 JR |
640 | } |
641 | ||
f7a84cb4 JR |
642 | /* Restore state and release DC. */ |
643 | SelectObject (dc, old_font); | |
46fd1ded | 644 | release_frame_dc (f, dc); |
f7a84cb4 JR |
645 | |
646 | return total_width; | |
647 | } | |
648 | ||
649 | /* w32 implementation of draw for font backend. | |
650 | Optional. | |
651 | Draw glyphs between FROM and TO of S->char2b at (X Y) pixel | |
652 | position of frame F with S->FACE and S->GC. If WITH_BACKGROUND | |
653 | is nonzero, fill the background in advance. It is assured that | |
a74ddbda JR |
654 | WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). |
655 | ||
656 | TODO: Currently this assumes that the colors and fonts are already | |
657 | set in the DC. This seems to be true now, but maybe only due to | |
658 | the old font code setting it up. It may be safer to resolve faces | |
659 | and fonts in here and set them explicitly | |
660 | */ | |
661 | ||
46fd1ded | 662 | int |
b56ceb92 JB |
663 | w32font_draw (struct glyph_string *s, int from, int to, |
664 | int x, int y, int with_background) | |
f7a84cb4 | 665 | { |
34fd2d28 | 666 | UINT options; |
f70eb806 | 667 | HRGN orig_clip = NULL; |
9c88f339 | 668 | int len = to - from; |
5f18d119 | 669 | struct w32font_info *w32font = (struct w32font_info *) s->font; |
34fd2d28 JR |
670 | |
671 | options = w32font->glyph_idx; | |
5c2c9c79 | 672 | |
5c2c9c79 JR |
673 | if (s->num_clips > 0) |
674 | { | |
675 | HRGN new_clip = CreateRectRgnIndirect (s->clip); | |
676 | ||
f70eb806 JR |
677 | /* Save clip region for later restoration. */ |
678 | orig_clip = CreateRectRgn (0, 0, 0, 0); | |
ed3751c8 | 679 | if (!GetClipRgn (s->hdc, orig_clip)) |
f70eb806 JR |
680 | { |
681 | DeleteObject (orig_clip); | |
682 | orig_clip = NULL; | |
683 | } | |
684 | ||
5c2c9c79 JR |
685 | if (s->num_clips > 1) |
686 | { | |
687 | HRGN clip2 = CreateRectRgnIndirect (s->clip + 1); | |
688 | ||
689 | CombineRgn (new_clip, new_clip, clip2, RGN_OR); | |
690 | DeleteObject (clip2); | |
691 | } | |
692 | ||
693 | SelectClipRgn (s->hdc, new_clip); | |
694 | DeleteObject (new_clip); | |
695 | } | |
f7a84cb4 | 696 | |
fb3b8017 JR |
697 | /* Using OPAQUE background mode can clear more background than expected |
698 | when Cleartype is used. Draw the background manually to avoid this. */ | |
699 | SetBkMode (s->hdc, TRANSPARENT); | |
f7a84cb4 JR |
700 | if (with_background) |
701 | { | |
1065a502 JR |
702 | HBRUSH brush; |
703 | RECT rect; | |
5f18d119 | 704 | struct font *font = s->font; |
1065a502 JR |
705 | |
706 | brush = CreateSolidBrush (s->gc->background); | |
707 | rect.left = x; | |
fb3b8017 | 708 | rect.top = y - font->ascent; |
1065a502 | 709 | rect.right = x + s->width; |
fb3b8017 | 710 | rect.bottom = y + font->descent; |
1065a502 | 711 | FillRect (s->hdc, &rect, brush); |
f2b25c0e | 712 | DeleteObject (brush); |
f7a84cb4 | 713 | } |
040fe918 | 714 | |
de63f07f KH |
715 | if (s->padding_p) |
716 | { | |
9c88f339 | 717 | int i; |
de63f07f KH |
718 | |
719 | for (i = 0; i < len; i++) | |
720 | ExtTextOutW (s->hdc, x + i, y, options, NULL, | |
8501c48b | 721 | s->char2b + from + i, 1, NULL); |
de63f07f KH |
722 | } |
723 | else | |
9c88f339 | 724 | ExtTextOutW (s->hdc, x, y, options, NULL, s->char2b + from, len, NULL); |
5c2c9c79 JR |
725 | |
726 | /* Restore clip region. */ | |
727 | if (s->num_clips > 0) | |
f70eb806 JR |
728 | SelectClipRgn (s->hdc, orig_clip); |
729 | ||
730 | if (orig_clip) | |
731 | DeleteObject (orig_clip); | |
9c88f339 JB |
732 | |
733 | return len; | |
f7a84cb4 JR |
734 | } |
735 | ||
736 | /* w32 implementation of free_entity for font backend. | |
737 | Optional (if FONT_EXTRA_INDEX is not Lisp_Save_Value). | |
738 | Free FONT_EXTRA_INDEX field of FONT_ENTITY. | |
20399669 JR |
739 | static void |
740 | w32font_free_entity (Lisp_Object entity); | |
f7a84cb4 JR |
741 | */ |
742 | ||
743 | /* w32 implementation of prepare_face for font backend. | |
744 | Optional (if FACE->extra is not used). | |
745 | Prepare FACE for displaying characters by FONT on frame F by | |
746 | storing some data in FACE->extra. If successful, return 0. | |
747 | Otherwise, return -1. | |
20399669 JR |
748 | static int |
749 | w32font_prepare_face (FRAME_PTR f, struct face *face); | |
f7a84cb4 JR |
750 | */ |
751 | /* w32 implementation of done_face for font backend. | |
752 | Optional. | |
753 | Done FACE for displaying characters by FACE->font on frame F. | |
20399669 JR |
754 | static void |
755 | w32font_done_face (FRAME_PTR f, struct face *face); */ | |
f7a84cb4 JR |
756 | |
757 | /* w32 implementation of get_bitmap for font backend. | |
758 | Optional. | |
759 | Store bitmap data for glyph-code CODE of FONT in BITMAP. It is | |
f2b25c0e | 760 | intended that this method is called from the other font-driver |
f7a84cb4 | 761 | for actual drawing. |
20399669 JR |
762 | static int |
763 | w32font_get_bitmap (struct font *font, unsigned code, | |
764 | struct font_bitmap *bitmap, int bits_per_pixel); | |
f7a84cb4 JR |
765 | */ |
766 | /* w32 implementation of free_bitmap for font backend. | |
767 | Optional. | |
768 | Free bitmap data in BITMAP. | |
20399669 JR |
769 | static void |
770 | w32font_free_bitmap (struct font *font, struct font_bitmap *bitmap); | |
f7a84cb4 JR |
771 | */ |
772 | /* w32 implementation of get_outline for font backend. | |
773 | Optional. | |
774 | Return an outline data for glyph-code CODE of FONT. The format | |
775 | of the outline data depends on the font-driver. | |
20399669 JR |
776 | static void * |
777 | w32font_get_outline (struct font *font, unsigned code); | |
f7a84cb4 JR |
778 | */ |
779 | /* w32 implementation of free_outline for font backend. | |
780 | Optional. | |
781 | Free OUTLINE (that is obtained by the above method). | |
20399669 JR |
782 | static void |
783 | w32font_free_outline (struct font *font, void *outline); | |
f7a84cb4 JR |
784 | */ |
785 | /* w32 implementation of anchor_point for font backend. | |
786 | Optional. | |
787 | Get coordinates of the INDEXth anchor point of the glyph whose | |
788 | code is CODE. Store the coordinates in *X and *Y. Return 0 if | |
bbd240ce | 789 | the operations was successful. Otherwise return -1. |
20399669 JR |
790 | static int |
791 | w32font_anchor_point (struct font *font, unsigned code, | |
f7a84cb4 JR |
792 | int index, int *x, int *y); |
793 | */ | |
794 | /* w32 implementation of otf_capability for font backend. | |
795 | Optional. | |
796 | Return a list describing which scripts/languages FONT | |
797 | supports by which GSUB/GPOS features of OpenType tables. | |
20399669 JR |
798 | static Lisp_Object |
799 | w32font_otf_capability (struct font *font); | |
f7a84cb4 JR |
800 | */ |
801 | /* w32 implementation of otf_drive for font backend. | |
802 | Optional. | |
803 | Apply FONT's OTF-FEATURES to the glyph string. | |
804 | ||
805 | FEATURES specifies which OTF features to apply in this format: | |
806 | (SCRIPT LANGSYS GSUB-FEATURE GPOS-FEATURE) | |
807 | See the documentation of `font-drive-otf' for the detail. | |
808 | ||
809 | This method applies the specified features to the codes in the | |
810 | elements of GSTRING-IN (between FROMth and TOth). The output | |
811 | codes are stored in GSTRING-OUT at the IDXth element and the | |
812 | following elements. | |
813 | ||
814 | Return the number of output codes. If none of the features are | |
815 | applicable to the input data, return 0. If GSTRING-OUT is too | |
816 | short, return -1. | |
20399669 JR |
817 | static int |
818 | w32font_otf_drive (struct font *font, Lisp_Object features, | |
819 | Lisp_Object gstring_in, int from, int to, | |
820 | Lisp_Object gstring_out, int idx, | |
821 | int alternate_subst); | |
f7a84cb4 JR |
822 | */ |
823 | ||
46fd1ded JR |
824 | /* Internal implementation of w32font_list. |
825 | Additional parameter opentype_only restricts the returned fonts to | |
826 | opentype fonts, which can be used with the Uniscribe backend. */ | |
827 | Lisp_Object | |
b56ceb92 | 828 | w32font_list_internal (Lisp_Object frame, Lisp_Object font_spec, int opentype_only) |
46fd1ded JR |
829 | { |
830 | struct font_callback_data match_data; | |
831 | HDC dc; | |
832 | FRAME_PTR f = XFRAME (frame); | |
833 | ||
834 | match_data.orig_font_spec = font_spec; | |
835 | match_data.list = Qnil; | |
836 | match_data.frame = frame; | |
837 | ||
72af86bd | 838 | memset (&match_data.pattern, 0, sizeof (LOGFONT)); |
46fd1ded JR |
839 | fill_in_logfont (f, &match_data.pattern, font_spec); |
840 | ||
19ae3e61 JR |
841 | /* If the charset is unrecognized, then we won't find a font, so don't |
842 | waste time looking for one. */ | |
843 | if (match_data.pattern.lfCharSet == DEFAULT_CHARSET) | |
844 | { | |
845 | Lisp_Object spec_charset = AREF (font_spec, FONT_REGISTRY_INDEX); | |
846 | if (!NILP (spec_charset) | |
847 | && !EQ (spec_charset, Qiso10646_1) | |
848 | && !EQ (spec_charset, Qunicode_bmp) | |
849 | && !EQ (spec_charset, Qunicode_sip) | |
850 | && !EQ (spec_charset, Qunknown)) | |
851 | return Qnil; | |
852 | } | |
853 | ||
46fd1ded JR |
854 | match_data.opentype_only = opentype_only; |
855 | if (opentype_only) | |
856 | match_data.pattern.lfOutPrecision = OUT_OUTLINE_PRECIS; | |
857 | ||
858 | if (match_data.pattern.lfFaceName[0] == '\0') | |
859 | { | |
860 | /* EnumFontFamiliesEx does not take other fields into account if | |
861 | font name is blank, so need to use two passes. */ | |
862 | list_all_matching_fonts (&match_data); | |
863 | } | |
864 | else | |
865 | { | |
866 | dc = get_frame_dc (f); | |
867 | ||
868 | EnumFontFamiliesEx (dc, &match_data.pattern, | |
869 | (FONTENUMPROC) add_font_entity_to_list, | |
870 | (LPARAM) &match_data, 0); | |
871 | release_frame_dc (f, dc); | |
872 | } | |
873 | ||
19ae3e61 | 874 | return match_data.list; |
46fd1ded JR |
875 | } |
876 | ||
877 | /* Internal implementation of w32font_match. | |
878 | Additional parameter opentype_only restricts the returned fonts to | |
879 | opentype fonts, which can be used with the Uniscribe backend. */ | |
880 | Lisp_Object | |
b56ceb92 | 881 | w32font_match_internal (Lisp_Object frame, Lisp_Object font_spec, int opentype_only) |
46fd1ded JR |
882 | { |
883 | struct font_callback_data match_data; | |
884 | HDC dc; | |
885 | FRAME_PTR f = XFRAME (frame); | |
886 | ||
887 | match_data.orig_font_spec = font_spec; | |
888 | match_data.frame = frame; | |
889 | match_data.list = Qnil; | |
890 | ||
72af86bd | 891 | memset (&match_data.pattern, 0, sizeof (LOGFONT)); |
46fd1ded JR |
892 | fill_in_logfont (f, &match_data.pattern, font_spec); |
893 | ||
894 | match_data.opentype_only = opentype_only; | |
895 | if (opentype_only) | |
896 | match_data.pattern.lfOutPrecision = OUT_OUTLINE_PRECIS; | |
897 | ||
898 | dc = get_frame_dc (f); | |
899 | ||
900 | EnumFontFamiliesEx (dc, &match_data.pattern, | |
901 | (FONTENUMPROC) add_one_font_entity_to_list, | |
902 | (LPARAM) &match_data, 0); | |
903 | release_frame_dc (f, dc); | |
904 | ||
905 | return NILP (match_data.list) ? Qnil : XCAR (match_data.list); | |
906 | } | |
907 | ||
f0121ad2 | 908 | int |
b56ceb92 JB |
909 | w32font_open_internal (FRAME_PTR f, Lisp_Object font_entity, |
910 | int pixel_size, Lisp_Object font_object) | |
f0121ad2 | 911 | { |
9c88f339 | 912 | int len, size; |
f0121ad2 JR |
913 | LOGFONT logfont; |
914 | HDC dc; | |
915 | HFONT hfont, old_font; | |
916 | Lisp_Object val, extra; | |
5f18d119 KH |
917 | struct w32font_info *w32_font; |
918 | struct font * font; | |
bd187c49 | 919 | OUTLINETEXTMETRICW* metrics = NULL; |
5f18d119 KH |
920 | |
921 | w32_font = (struct w32font_info *) XFONT_OBJECT (font_object); | |
922 | font = (struct font *) w32_font; | |
f0121ad2 | 923 | |
f0121ad2 JR |
924 | if (!font) |
925 | return 0; | |
926 | ||
72af86bd | 927 | memset (&logfont, 0, sizeof (logfont)); |
f0121ad2 JR |
928 | fill_in_logfont (f, &logfont, font_entity); |
929 | ||
1519d52e JR |
930 | /* Prefer truetype fonts, to avoid known problems with type1 fonts, and |
931 | limitations in bitmap fonts. */ | |
932 | val = AREF (font_entity, FONT_FOUNDRY_INDEX); | |
933 | if (!EQ (val, Qraster)) | |
934 | logfont.lfOutPrecision = OUT_TT_PRECIS; | |
935 | ||
f0121ad2 JR |
936 | size = XINT (AREF (font_entity, FONT_SIZE_INDEX)); |
937 | if (!size) | |
938 | size = pixel_size; | |
939 | ||
940 | logfont.lfHeight = -size; | |
941 | hfont = CreateFontIndirect (&logfont); | |
942 | ||
943 | if (hfont == NULL) | |
944 | return 0; | |
945 | ||
f0121ad2 JR |
946 | /* Get the metrics for this font. */ |
947 | dc = get_frame_dc (f); | |
948 | old_font = SelectObject (dc, hfont); | |
949 | ||
5f18d119 | 950 | /* Try getting the outline metrics (only works for truetype fonts). */ |
db4f02f2 | 951 | len = get_outline_metrics_w (dc, 0, NULL); |
5f18d119 KH |
952 | if (len) |
953 | { | |
bd187c49 | 954 | metrics = (OUTLINETEXTMETRICW *) alloca (len); |
db4f02f2 | 955 | if (get_outline_metrics_w (dc, len, metrics)) |
72af86bd AS |
956 | memcpy (&w32_font->metrics, &metrics->otmTextMetrics, |
957 | sizeof (TEXTMETRICW)); | |
5f18d119 KH |
958 | else |
959 | metrics = NULL; | |
960 | } | |
f0121ad2 | 961 | |
943f2093 | 962 | if (!metrics) |
db4f02f2 | 963 | get_text_metrics_w (dc, &w32_font->metrics); |
b003e5ff | 964 | |
8f112d52 JR |
965 | w32_font->cached_metrics = NULL; |
966 | w32_font->n_cache_blocks = 0; | |
54efdcd1 | 967 | |
f0121ad2 JR |
968 | SelectObject (dc, old_font); |
969 | release_frame_dc (f, dc); | |
34fd2d28 | 970 | |
1b5defe6 | 971 | w32_font->hfont = hfont; |
f0121ad2 | 972 | |
5ace1ec1 JR |
973 | { |
974 | char *name; | |
975 | ||
976 | /* We don't know how much space we need for the full name, so start with | |
977 | 96 bytes and go up in steps of 32. */ | |
978 | len = 96; | |
c35f9821 | 979 | name = alloca (len); |
67997c79 JR |
980 | while (name && w32font_full_name (&logfont, font_entity, pixel_size, |
981 | name, len) < 0) | |
5ace1ec1 | 982 | { |
c35f9821 JR |
983 | len += 32; |
984 | name = alloca (len); | |
5ace1ec1 JR |
985 | } |
986 | if (name) | |
5f18d119 | 987 | font->props[FONT_FULLNAME_INDEX] |
e6df5336 | 988 | = DECODE_SYSTEM (build_string (name)); |
5ace1ec1 | 989 | else |
e6df5336 JR |
990 | font->props[FONT_FULLNAME_INDEX] |
991 | = DECODE_SYSTEM (build_string (logfont.lfFaceName)); | |
5ace1ec1 | 992 | } |
5f18d119 KH |
993 | |
994 | font->max_width = w32_font->metrics.tmMaxCharWidth; | |
b003e5ff | 995 | /* Parts of Emacs display assume that height = ascent + descent... |
9196133b | 996 | so height is defined later, after ascent and descent. |
5f18d119 | 997 | font->height = w32_font->metrics.tmHeight |
f0121ad2 | 998 | + w32_font->metrics.tmExternalLeading; |
9196133b JR |
999 | */ |
1000 | ||
5f18d119 KH |
1001 | font->space_width = font->average_width = w32_font->metrics.tmAveCharWidth; |
1002 | ||
1003 | font->vertical_centering = 0; | |
1004 | font->encoding_type = 0; | |
1005 | font->baseline_offset = 0; | |
1006 | font->relative_compose = 0; | |
1007 | font->default_ascent = w32_font->metrics.tmAscent; | |
1008 | font->font_encoder = NULL; | |
f0121ad2 JR |
1009 | font->pixel_size = size; |
1010 | font->driver = &w32font_driver; | |
34fd2d28 JR |
1011 | /* Use format cached during list, as the information we have access to |
1012 | here is incomplete. */ | |
1013 | extra = AREF (font_entity, FONT_EXTRA_INDEX); | |
1014 | if (CONSP (extra)) | |
1015 | { | |
1016 | val = assq_no_quit (QCformat, extra); | |
1017 | if (CONSP (val)) | |
5f18d119 | 1018 | font->props[FONT_FORMAT_INDEX] = XCDR (val); |
34fd2d28 | 1019 | else |
5f18d119 | 1020 | font->props[FONT_FORMAT_INDEX] = Qunknown; |
34fd2d28 JR |
1021 | } |
1022 | else | |
5f18d119 | 1023 | font->props[FONT_FORMAT_INDEX] = Qunknown; |
34fd2d28 | 1024 | |
5f18d119 | 1025 | font->props[FONT_FILE_INDEX] = Qnil; |
f0121ad2 JR |
1026 | font->encoding_charset = -1; |
1027 | font->repertory_charset = -1; | |
04b65d2b | 1028 | /* TODO: do we really want the minimum width here, which could be negative? */ |
5f18d119 | 1029 | font->min_width = font->space_width; |
f0121ad2 JR |
1030 | font->ascent = w32_font->metrics.tmAscent; |
1031 | font->descent = w32_font->metrics.tmDescent; | |
9196133b | 1032 | font->height = font->ascent + font->descent; |
5f18d119 KH |
1033 | |
1034 | if (metrics) | |
1035 | { | |
1036 | font->underline_thickness = metrics->otmsUnderscoreSize; | |
1037 | font->underline_position = -metrics->otmsUnderscorePosition; | |
1038 | } | |
1039 | else | |
1040 | { | |
1041 | font->underline_thickness = 0; | |
1042 | font->underline_position = -1; | |
1043 | } | |
f0121ad2 | 1044 | |
5f18d119 KH |
1045 | /* For temporary compatibility with legacy code that expects the |
1046 | name to be usable in x-list-fonts. Eventually we expect to change | |
1047 | x-list-fonts and other places that use fonts so that this can be | |
1048 | an fcname or similar. */ | |
a30e1957 | 1049 | font->props[FONT_NAME_INDEX] = Ffont_xlfd_name (font_object, Qnil); |
04b65d2b | 1050 | |
f0121ad2 JR |
1051 | return 1; |
1052 | } | |
1053 | ||
f7a84cb4 JR |
1054 | /* Callback function for EnumFontFamiliesEx. |
1055 | * Adds the name of a font to a Lisp list (passed in as the lParam arg). */ | |
20399669 | 1056 | static int CALLBACK |
b56ceb92 JB |
1057 | add_font_name_to_list (ENUMLOGFONTEX *logical_font, |
1058 | NEWTEXTMETRICEX *physical_font, | |
1059 | DWORD font_type, LPARAM list_object) | |
f7a84cb4 JR |
1060 | { |
1061 | Lisp_Object* list = (Lisp_Object *) list_object; | |
20a2b756 JR |
1062 | Lisp_Object family; |
1063 | ||
1064 | /* Skip vertical fonts (intended only for printing) */ | |
1065 | if (logical_font->elfLogFont.lfFaceName[0] == '@') | |
1066 | return 1; | |
1067 | ||
e6df5336 | 1068 | family = intern_font_name (logical_font->elfLogFont.lfFaceName); |
f7a84cb4 JR |
1069 | if (! memq_no_quit (family, *list)) |
1070 | *list = Fcons (family, *list); | |
1071 | ||
1072 | return 1; | |
1073 | } | |
1074 | ||
f57e2426 J |
1075 | static int w32_decode_weight (int); |
1076 | static int w32_encode_weight (int); | |
5f18d119 | 1077 | |
f7a84cb4 | 1078 | /* Convert an enumerated Windows font to an Emacs font entity. */ |
20399669 | 1079 | static Lisp_Object |
b56ceb92 JB |
1080 | w32_enumfont_pattern_entity (Lisp_Object frame, |
1081 | ENUMLOGFONTEX *logical_font, | |
1082 | NEWTEXTMETRICEX *physical_font, | |
1083 | DWORD font_type, | |
1084 | LOGFONT *requested_font, | |
1085 | Lisp_Object backend) | |
f7a84cb4 JR |
1086 | { |
1087 | Lisp_Object entity, tem; | |
1088 | LOGFONT *lf = (LOGFONT*) logical_font; | |
1089 | BYTE generic_type; | |
56df6710 | 1090 | DWORD full_type = physical_font->ntmTm.ntmFlags; |
f7a84cb4 | 1091 | |
5f18d119 | 1092 | entity = font_make_entity (); |
f7a84cb4 | 1093 | |
34fd2d28 | 1094 | ASET (entity, FONT_TYPE_INDEX, backend); |
c960bff8 | 1095 | ASET (entity, FONT_REGISTRY_INDEX, w32_registry (lf->lfCharSet, font_type)); |
f7a84cb4 JR |
1096 | ASET (entity, FONT_OBJLIST_INDEX, Qnil); |
1097 | ||
1098 | /* Foundry is difficult to get in readable form on Windows. | |
d205d43b | 1099 | But Emacs crashes if it is not set, so set it to something more |
9c623c85 | 1100 | generic. These values make xlfds compatible with Emacs 22. */ |
d205d43b JR |
1101 | if (lf->lfOutPrecision == OUT_STRING_PRECIS) |
1102 | tem = Qraster; | |
1103 | else if (lf->lfOutPrecision == OUT_STROKE_PRECIS) | |
1104 | tem = Qoutline; | |
1105 | else | |
1106 | tem = Qunknown; | |
1107 | ||
1108 | ASET (entity, FONT_FOUNDRY_INDEX, tem); | |
1109 | ||
1110 | /* Save the generic family in the extra info, as it is likely to be | |
1111 | useful to users looking for a close match. */ | |
f7a84cb4 JR |
1112 | generic_type = physical_font->ntmTm.tmPitchAndFamily & 0xF0; |
1113 | if (generic_type == FF_DECORATIVE) | |
1114 | tem = Qdecorative; | |
1115 | else if (generic_type == FF_MODERN) | |
9e1a2995 | 1116 | tem = Qmono; |
f7a84cb4 | 1117 | else if (generic_type == FF_ROMAN) |
d205d43b | 1118 | tem = Qserif; |
f7a84cb4 JR |
1119 | else if (generic_type == FF_SCRIPT) |
1120 | tem = Qscript; | |
1121 | else if (generic_type == FF_SWISS) | |
9e1a2995 | 1122 | tem = Qsans; |
f7a84cb4 | 1123 | else |
5f18d119 | 1124 | tem = Qnil; |
9e1a2995 JR |
1125 | |
1126 | ASET (entity, FONT_ADSTYLE_INDEX, tem); | |
f7a84cb4 | 1127 | |
d205d43b | 1128 | if (physical_font->ntmTm.tmPitchAndFamily & 0x01) |
5f18d119 | 1129 | ASET (entity, FONT_SPACING_INDEX, make_number (FONT_SPACING_PROPORTIONAL)); |
d205d43b | 1130 | else |
ed18e612 | 1131 | ASET (entity, FONT_SPACING_INDEX, make_number (FONT_SPACING_CHARCELL)); |
f7a84cb4 | 1132 | |
91583281 JR |
1133 | if (requested_font->lfQuality != DEFAULT_QUALITY) |
1134 | { | |
1135 | font_put_extra (entity, QCantialias, | |
1136 | lispy_antialias_type (requested_font->lfQuality)); | |
1137 | } | |
f7a84cb4 | 1138 | ASET (entity, FONT_FAMILY_INDEX, |
e6df5336 | 1139 | intern_font_name (lf->lfFaceName)); |
f7a84cb4 | 1140 | |
5f18d119 KH |
1141 | FONT_SET_STYLE (entity, FONT_WEIGHT_INDEX, |
1142 | make_number (w32_decode_weight (lf->lfWeight))); | |
1143 | FONT_SET_STYLE (entity, FONT_SLANT_INDEX, | |
1144 | make_number (lf->lfItalic ? 200 : 100)); | |
d205d43b JR |
1145 | /* TODO: PANOSE struct has this info, but need to call GetOutlineTextMetrics |
1146 | to get it. */ | |
5f18d119 | 1147 | FONT_SET_STYLE (entity, FONT_WIDTH_INDEX, make_number (100)); |
f7a84cb4 | 1148 | |
040fe918 | 1149 | if (font_type & RASTER_FONTTYPE) |
597634cb JR |
1150 | ASET (entity, FONT_SIZE_INDEX, |
1151 | make_number (physical_font->ntmTm.tmHeight | |
1152 | + physical_font->ntmTm.tmExternalLeading)); | |
040fe918 JR |
1153 | else |
1154 | ASET (entity, FONT_SIZE_INDEX, make_number (0)); | |
f7a84cb4 | 1155 | |
fe7a3057 | 1156 | /* Cache Unicode codepoints covered by this font, as there is no other way |
f7a84cb4 | 1157 | of getting this information easily. */ |
040fe918 | 1158 | if (font_type & TRUETYPE_FONTTYPE) |
f7a84cb4 | 1159 | { |
aee986fd JR |
1160 | tem = font_supported_scripts (&physical_font->ntmFontSig); |
1161 | if (!NILP (tem)) | |
1162 | font_put_extra (entity, QCscript, tem); | |
f7a84cb4 | 1163 | } |
d205d43b | 1164 | |
34fd2d28 JR |
1165 | /* This information is not fully available when opening fonts, so |
1166 | save it here. Only Windows 2000 and later return information | |
1167 | about opentype and type1 fonts, so need a fallback for detecting | |
1168 | truetype so that this information is not any worse than we could | |
1169 | have obtained later. */ | |
56df6710 JR |
1170 | if (EQ (backend, Quniscribe) && (full_type & NTMFLAGS_OPENTYPE)) |
1171 | tem = intern ("opentype"); | |
1172 | else if (font_type & TRUETYPE_FONTTYPE) | |
34fd2d28 | 1173 | tem = intern ("truetype"); |
34fd2d28 JR |
1174 | else if (full_type & NTM_PS_OPENTYPE) |
1175 | tem = intern ("postscript"); | |
56df6710 JR |
1176 | else if (full_type & NTM_TYPE1) |
1177 | tem = intern ("type1"); | |
34fd2d28 JR |
1178 | else if (font_type & RASTER_FONTTYPE) |
1179 | tem = intern ("w32bitmap"); | |
1180 | else | |
1181 | tem = intern ("w32vector"); | |
1182 | ||
1183 | font_put_extra (entity, QCformat, tem); | |
1184 | ||
f7a84cb4 JR |
1185 | return entity; |
1186 | } | |
1187 | ||
d205d43b JR |
1188 | |
1189 | /* Convert generic families to the family portion of lfPitchAndFamily. */ | |
24f981c9 | 1190 | static BYTE |
d205d43b JR |
1191 | w32_generic_family (Lisp_Object name) |
1192 | { | |
1193 | /* Generic families. */ | |
1194 | if (EQ (name, Qmonospace) || EQ (name, Qmono)) | |
1195 | return FF_MODERN; | |
9e1a2995 | 1196 | else if (EQ (name, Qsans) || EQ (name, Qsans_serif) || EQ (name, Qsansserif)) |
d205d43b JR |
1197 | return FF_SWISS; |
1198 | else if (EQ (name, Qserif)) | |
1199 | return FF_ROMAN; | |
1200 | else if (EQ (name, Qdecorative)) | |
1201 | return FF_DECORATIVE; | |
1202 | else if (EQ (name, Qscript)) | |
1203 | return FF_SCRIPT; | |
1204 | else | |
1205 | return FF_DONTCARE; | |
1206 | } | |
1207 | ||
1208 | static int | |
b56ceb92 | 1209 | logfonts_match (LOGFONT *font, LOGFONT *pattern) |
d205d43b JR |
1210 | { |
1211 | /* Only check height for raster fonts. */ | |
1212 | if (pattern->lfHeight && font->lfOutPrecision == OUT_STRING_PRECIS | |
1213 | && font->lfHeight != pattern->lfHeight) | |
1214 | return 0; | |
1215 | ||
1216 | /* Have some flexibility with weights. */ | |
1217 | if (pattern->lfWeight | |
1218 | && ((font->lfWeight < (pattern->lfWeight - 150)) | |
1219 | || font->lfWeight > (pattern->lfWeight + 150))) | |
1220 | return 0; | |
1221 | ||
1222 | /* Charset and face should be OK. Italic has to be checked | |
1223 | against the original spec, in case we don't have any preference. */ | |
1224 | return 1; | |
1225 | } | |
1226 | ||
4c100a01 JR |
1227 | /* Codepage Bitfields in FONTSIGNATURE struct. */ |
1228 | #define CSB_JAPANESE (1 << 17) | |
1229 | #define CSB_KOREAN ((1 << 19) | (1 << 21)) | |
1230 | #define CSB_CHINESE ((1 << 18) | (1 << 20)) | |
1231 | ||
d205d43b | 1232 | static int |
b56ceb92 JB |
1233 | font_matches_spec (DWORD type, NEWTEXTMETRICEX *font, |
1234 | Lisp_Object spec, Lisp_Object backend, | |
1235 | LOGFONT *logfont) | |
d205d43b JR |
1236 | { |
1237 | Lisp_Object extra, val; | |
1238 | ||
1239 | /* Check italic. Can't check logfonts, since it is a boolean field, | |
1240 | so there is no difference between "non-italic" and "don't care". */ | |
5f18d119 KH |
1241 | { |
1242 | int slant = FONT_SLANT_NUMERIC (spec); | |
1243 | ||
1244 | if (slant >= 0 | |
1245 | && ((slant > 150 && !font->ntmTm.tmItalic) | |
1246 | || (slant <= 150 && font->ntmTm.tmItalic))) | |
1247 | return 0; | |
1248 | } | |
d205d43b | 1249 | |
4f2a2ee2 JR |
1250 | /* Check adstyle against generic family. */ |
1251 | val = AREF (spec, FONT_ADSTYLE_INDEX); | |
1252 | if (!NILP (val)) | |
1253 | { | |
1254 | BYTE family = w32_generic_family (val); | |
1255 | if (family != FF_DONTCARE | |
1256 | && family != (font->ntmTm.tmPitchAndFamily & 0xF0)) | |
1257 | return 0; | |
1258 | } | |
1259 | ||
5f18d119 KH |
1260 | /* Check spacing */ |
1261 | val = AREF (spec, FONT_SPACING_INDEX); | |
1262 | if (INTEGERP (val)) | |
1263 | { | |
1264 | int spacing = XINT (val); | |
1265 | int proportional = (spacing < FONT_SPACING_MONO); | |
1266 | ||
1267 | if ((proportional && !(font->ntmTm.tmPitchAndFamily & 0x01)) | |
1268 | || (!proportional && (font->ntmTm.tmPitchAndFamily & 0x01))) | |
1269 | return 0; | |
1270 | } | |
1271 | ||
d205d43b JR |
1272 | /* Check extra parameters. */ |
1273 | for (extra = AREF (spec, FONT_EXTRA_INDEX); | |
1274 | CONSP (extra); extra = XCDR (extra)) | |
1275 | { | |
1276 | Lisp_Object extra_entry; | |
1277 | extra_entry = XCAR (extra); | |
1278 | if (CONSP (extra_entry)) | |
1279 | { | |
1280 | Lisp_Object key = XCAR (extra_entry); | |
d205d43b | 1281 | |
5f18d119 KH |
1282 | val = XCDR (extra_entry); |
1283 | if (EQ (key, QCscript) && SYMBOLP (val)) | |
d205d43b JR |
1284 | { |
1285 | /* Only truetype fonts will have information about what | |
1286 | scripts they support. This probably means the user | |
7877f373 JB |
1287 | will have to force Emacs to use raster, PostScript |
1288 | or ATM fonts for non-ASCII text. */ | |
d205d43b JR |
1289 | if (type & TRUETYPE_FONTTYPE) |
1290 | { | |
1291 | Lisp_Object support | |
1292 | = font_supported_scripts (&font->ntmFontSig); | |
1293 | if (! memq_no_quit (val, support)) | |
1294 | return 0; | |
22610910 JR |
1295 | |
1296 | /* Avoid using non-Japanese fonts for Japanese, even | |
1297 | if they claim they are capable, due to known | |
1298 | breakage in Vista and Windows 7 fonts | |
1299 | (bug#6029). */ | |
1300 | if (EQ (val, Qkana) | |
1301 | && (font->ntmTm.tmCharSet != SHIFTJIS_CHARSET | |
1302 | || !(font->ntmFontSig.fsCsb[0] & CSB_JAPANESE))) | |
1303 | return 0; | |
d205d43b JR |
1304 | } |
1305 | else | |
1306 | { | |
1307 | /* Return specific matches, but play it safe. Fonts | |
1308 | that cover more than their charset would suggest | |
1309 | are likely to be truetype or opentype fonts, | |
1310 | covered above. */ | |
1311 | if (EQ (val, Qlatin)) | |
1312 | { | |
1313 | /* Although every charset but symbol, thai and | |
1314 | arabic contains the basic ASCII set of latin | |
1315 | characters, Emacs expects much more. */ | |
1316 | if (font->ntmTm.tmCharSet != ANSI_CHARSET) | |
1317 | return 0; | |
1318 | } | |
1319 | else if (EQ (val, Qsymbol)) | |
1320 | { | |
1321 | if (font->ntmTm.tmCharSet != SYMBOL_CHARSET) | |
1322 | return 0; | |
1323 | } | |
1324 | else if (EQ (val, Qcyrillic)) | |
1325 | { | |
1326 | if (font->ntmTm.tmCharSet != RUSSIAN_CHARSET) | |
1327 | return 0; | |
1328 | } | |
1329 | else if (EQ (val, Qgreek)) | |
1330 | { | |
1331 | if (font->ntmTm.tmCharSet != GREEK_CHARSET) | |
1332 | return 0; | |
1333 | } | |
1334 | else if (EQ (val, Qarabic)) | |
1335 | { | |
1336 | if (font->ntmTm.tmCharSet != ARABIC_CHARSET) | |
1337 | return 0; | |
1338 | } | |
1339 | else if (EQ (val, Qhebrew)) | |
1340 | { | |
1341 | if (font->ntmTm.tmCharSet != HEBREW_CHARSET) | |
1342 | return 0; | |
1343 | } | |
1344 | else if (EQ (val, Qthai)) | |
1345 | { | |
1346 | if (font->ntmTm.tmCharSet != THAI_CHARSET) | |
1347 | return 0; | |
1348 | } | |
1349 | else if (EQ (val, Qkana)) | |
1350 | { | |
1351 | if (font->ntmTm.tmCharSet != SHIFTJIS_CHARSET) | |
1352 | return 0; | |
1353 | } | |
1354 | else if (EQ (val, Qbopomofo)) | |
1355 | { | |
1356 | if (font->ntmTm.tmCharSet != CHINESEBIG5_CHARSET) | |
1357 | return 0; | |
1358 | } | |
1359 | else if (EQ (val, Qhangul)) | |
1360 | { | |
1361 | if (font->ntmTm.tmCharSet != HANGUL_CHARSET | |
1362 | && font->ntmTm.tmCharSet != JOHAB_CHARSET) | |
1363 | return 0; | |
1364 | } | |
1365 | else if (EQ (val, Qhan)) | |
1366 | { | |
1367 | if (font->ntmTm.tmCharSet != CHINESEBIG5_CHARSET | |
1368 | && font->ntmTm.tmCharSet != GB2312_CHARSET | |
1369 | && font->ntmTm.tmCharSet != HANGUL_CHARSET | |
1370 | && font->ntmTm.tmCharSet != JOHAB_CHARSET | |
1371 | && font->ntmTm.tmCharSet != SHIFTJIS_CHARSET) | |
1372 | return 0; | |
1373 | } | |
1374 | else | |
56df6710 JR |
1375 | /* Other scripts unlikely to be handled by non-truetype |
1376 | fonts. */ | |
d205d43b JR |
1377 | return 0; |
1378 | } | |
1379 | } | |
5f18d119 | 1380 | else if (EQ (key, QClang) && SYMBOLP (val)) |
8f112d52 | 1381 | { |
4c100a01 | 1382 | /* Just handle the CJK languages here, as the lang |
8f112d52 JR |
1383 | parameter is used to select a font with appropriate |
1384 | glyphs in the cjk unified ideographs block. Other fonts | |
1385 | support for a language can be solely determined by | |
1386 | its character coverage. */ | |
1387 | if (EQ (val, Qja)) | |
1388 | { | |
4c100a01 | 1389 | if (!(font->ntmFontSig.fsCsb[0] & CSB_JAPANESE)) |
8f112d52 JR |
1390 | return 0; |
1391 | } | |
1392 | else if (EQ (val, Qko)) | |
1393 | { | |
4c100a01 | 1394 | if (!(font->ntmFontSig.fsCsb[0] & CSB_KOREAN)) |
8f112d52 JR |
1395 | return 0; |
1396 | } | |
1397 | else if (EQ (val, Qzh)) | |
1398 | { | |
4c100a01 JR |
1399 | if (!(font->ntmFontSig.fsCsb[0] & CSB_CHINESE)) |
1400 | return 0; | |
8f112d52 JR |
1401 | } |
1402 | else | |
4c100a01 JR |
1403 | /* Any other language, we don't recognize it. Only the above |
1404 | currently appear in fontset.el, so it isn't worth | |
1405 | creating a mapping table of codepages/scripts to languages | |
1406 | or opening the font to see if there are any language tags | |
1407 | in it that the W32 API does not expose. Fontset | |
8f112d52 JR |
1408 | spec should have a fallback, as some backends do |
1409 | not recognize language at all. */ | |
1410 | return 0; | |
1411 | } | |
56df6710 JR |
1412 | else if (EQ (key, QCotf) && CONSP (val)) |
1413 | { | |
1414 | /* OTF features only supported by the uniscribe backend. */ | |
1415 | if (EQ (backend, Quniscribe)) | |
1416 | { | |
1417 | if (!uniscribe_check_otf (logfont, val)) | |
1418 | return 0; | |
1419 | } | |
1420 | else | |
1421 | return 0; | |
1422 | } | |
d205d43b JR |
1423 | } |
1424 | } | |
1425 | return 1; | |
1426 | } | |
1427 | ||
c960bff8 | 1428 | static int |
b56ceb92 | 1429 | w32font_coverage_ok (FONTSIGNATURE * coverage, BYTE charset) |
c960bff8 JR |
1430 | { |
1431 | DWORD subrange1 = coverage->fsUsb[1]; | |
1432 | ||
1433 | #define SUBRANGE1_HAN_MASK 0x08000000 | |
1434 | #define SUBRANGE1_HANGEUL_MASK 0x01000000 | |
1435 | #define SUBRANGE1_JAPANESE_MASK (0x00060000 | SUBRANGE1_HAN_MASK) | |
1436 | ||
1437 | if (charset == GB2312_CHARSET || charset == CHINESEBIG5_CHARSET) | |
1438 | { | |
1439 | return (subrange1 & SUBRANGE1_HAN_MASK) == SUBRANGE1_HAN_MASK; | |
1440 | } | |
1441 | else if (charset == SHIFTJIS_CHARSET) | |
1442 | { | |
1443 | return (subrange1 & SUBRANGE1_JAPANESE_MASK) == SUBRANGE1_JAPANESE_MASK; | |
1444 | } | |
1445 | else if (charset == HANGEUL_CHARSET) | |
1446 | { | |
1447 | return (subrange1 & SUBRANGE1_HANGEUL_MASK) == SUBRANGE1_HANGEUL_MASK; | |
1448 | } | |
1449 | ||
1450 | return 1; | |
1451 | } | |
1452 | ||
b0857706 JR |
1453 | |
1454 | static int | |
b56ceb92 | 1455 | check_face_name (LOGFONT *font, char *full_name) |
b0857706 JR |
1456 | { |
1457 | char full_iname[LF_FULLFACESIZE+1]; | |
1458 | ||
1459 | /* Just check for names known to cause problems, since the full name | |
1460 | can contain expanded abbreviations, prefixed foundry, postfixed | |
1461 | style, the latter of which sometimes differs from the style indicated | |
1462 | in the shorter name (eg Lt becomes Light or even Extra Light) */ | |
1463 | ||
1464 | /* Helvetica is mapped to Arial in Windows, but if a Type-1 Helvetica is | |
1465 | installed, we run into problems with the Uniscribe backend which tries | |
1466 | to avoid non-truetype fonts, and ends up mixing the Type-1 Helvetica | |
7877f373 | 1467 | with Arial's characteristics, since that attempt to use TrueType works |
b0857706 | 1468 | some places, but not others. */ |
c285743c | 1469 | if (!xstrcasecmp (font->lfFaceName, "helvetica")) |
b0857706 JR |
1470 | { |
1471 | strncpy (full_iname, full_name, LF_FULLFACESIZE); | |
1472 | full_iname[LF_FULLFACESIZE] = 0; | |
1473 | _strlwr (full_iname); | |
c285743c | 1474 | return strstr ("helvetica", full_iname) != NULL; |
b0857706 | 1475 | } |
631ea4fb JR |
1476 | /* Same for Helv. */ |
1477 | if (!xstrcasecmp (font->lfFaceName, "helv")) | |
1478 | { | |
1479 | strncpy (full_iname, full_name, LF_FULLFACESIZE); | |
1480 | full_iname[LF_FULLFACESIZE] = 0; | |
1481 | _strlwr (full_iname); | |
1482 | return strstr ("helv", full_iname) != NULL; | |
1483 | } | |
c285743c JR |
1484 | |
1485 | /* Since Times is mapped to Times New Roman, a substring | |
1486 | match is not sufficient to filter out the bogus match. */ | |
1487 | else if (!xstrcasecmp (font->lfFaceName, "times")) | |
1488 | return xstrcasecmp (full_name, "times") == 0; | |
b0857706 JR |
1489 | |
1490 | return 1; | |
1491 | } | |
1492 | ||
1493 | ||
f7a84cb4 | 1494 | /* Callback function for EnumFontFamiliesEx. |
91af3942 | 1495 | * Checks if a font matches everything we are trying to check against, |
d205d43b JR |
1496 | * and if so, adds it to a list. Both the data we are checking against |
1497 | * and the list to which the fonts are added are passed in via the | |
1498 | * lparam argument, in the form of a font_callback_data struct. */ | |
20399669 | 1499 | static int CALLBACK |
b56ceb92 JB |
1500 | add_font_entity_to_list (ENUMLOGFONTEX *logical_font, |
1501 | NEWTEXTMETRICEX *physical_font, | |
1502 | DWORD font_type, LPARAM lParam) | |
f7a84cb4 | 1503 | { |
d205d43b JR |
1504 | struct font_callback_data *match_data |
1505 | = (struct font_callback_data *) lParam; | |
56df6710 | 1506 | Lisp_Object backend = match_data->opentype_only ? Quniscribe : Qgdi; |
19ae3e61 JR |
1507 | Lisp_Object entity; |
1508 | ||
1509 | int is_unicode = physical_font->ntmFontSig.fsUsb[3] | |
1510 | || physical_font->ntmFontSig.fsUsb[2] | |
1511 | || physical_font->ntmFontSig.fsUsb[1] | |
1512 | || physical_font->ntmFontSig.fsUsb[0] & 0x3fffffff; | |
1513 | ||
1514 | /* Skip non matching fonts. */ | |
1515 | ||
1516 | /* For uniscribe backend, consider only truetype or opentype fonts | |
fe7a3057 | 1517 | that have some Unicode coverage. */ |
19ae3e61 | 1518 | if (match_data->opentype_only |
22610910 | 1519 | && ((!(physical_font->ntmTm.ntmFlags & NTMFLAGS_OPENTYPE) |
19ae3e61 JR |
1520 | && !(font_type & TRUETYPE_FONTTYPE)) |
1521 | || !is_unicode)) | |
1522 | return 1; | |
1523 | ||
1524 | /* Ensure a match. */ | |
1525 | if (!logfonts_match (&logical_font->elfLogFont, &match_data->pattern) | |
1526 | || !font_matches_spec (font_type, physical_font, | |
1527 | match_data->orig_font_spec, backend, | |
1528 | &logical_font->elfLogFont) | |
1529 | || !w32font_coverage_ok (&physical_font->ntmFontSig, | |
1530 | match_data->pattern.lfCharSet)) | |
1531 | return 1; | |
f7a84cb4 | 1532 | |
19ae3e61 JR |
1533 | /* Avoid substitutions involving raster fonts (eg Helv -> MS Sans Serif) |
1534 | We limit this to raster fonts, because the test can catch some | |
1535 | genuine fonts (eg the full name of DejaVu Sans Mono Light is actually | |
1536 | DejaVu Sans Mono ExtraLight). Helvetica -> Arial substitution will | |
1537 | therefore get through this test. Since full names can be prefixed | |
1538 | by a foundry, we accept raster fonts if the font name is found | |
1539 | anywhere within the full name. */ | |
1540 | if ((logical_font->elfLogFont.lfOutPrecision == OUT_STRING_PRECIS | |
c73abf54 JR |
1541 | && !strstr (logical_font->elfFullName, |
1542 | logical_font->elfLogFont.lfFaceName)) | |
b0857706 JR |
1543 | /* Check for well known substitutions that mess things up in the |
1544 | presence of Type-1 fonts of the same name. */ | |
631ea4fb JR |
1545 | || (!check_face_name (&logical_font->elfLogFont, |
1546 | logical_font->elfFullName))) | |
19ae3e61 JR |
1547 | return 1; |
1548 | ||
1549 | /* Make a font entity for the font. */ | |
1550 | entity = w32_enumfont_pattern_entity (match_data->frame, logical_font, | |
1551 | physical_font, font_type, | |
1552 | &match_data->pattern, | |
1553 | backend); | |
1554 | ||
1555 | if (!NILP (entity)) | |
d205d43b | 1556 | { |
19ae3e61 JR |
1557 | Lisp_Object spec_charset = AREF (match_data->orig_font_spec, |
1558 | FONT_REGISTRY_INDEX); | |
1559 | ||
fe7a3057 | 1560 | /* iso10646-1 fonts must contain Unicode mapping tables. */ |
19ae3e61 JR |
1561 | if (EQ (spec_charset, Qiso10646_1)) |
1562 | { | |
1563 | if (!is_unicode) | |
9d32f818 | 1564 | return 1; |
19ae3e61 JR |
1565 | } |
1566 | /* unicode-bmp fonts must contain characters from the BMP. */ | |
1567 | else if (EQ (spec_charset, Qunicode_bmp)) | |
1568 | { | |
1569 | if (!physical_font->ntmFontSig.fsUsb[3] | |
1570 | && !(physical_font->ntmFontSig.fsUsb[2] & 0xFFFFFF9E) | |
1571 | && !(physical_font->ntmFontSig.fsUsb[1] & 0xE81FFFFF) | |
1572 | && !(physical_font->ntmFontSig.fsUsb[0] & 0x007F001F)) | |
1573 | return 1; | |
1574 | } | |
fe7a3057 | 1575 | /* unicode-sip fonts must contain characters in Unicode plane 2. |
19ae3e61 JR |
1576 | so look for bit 57 (surrogates) in the Unicode subranges, plus |
1577 | the bits for CJK ranges that include those characters. */ | |
1578 | else if (EQ (spec_charset, Qunicode_sip)) | |
1579 | { | |
22610910 JR |
1580 | if (!(physical_font->ntmFontSig.fsUsb[1] & 0x02000000) |
1581 | || !(physical_font->ntmFontSig.fsUsb[1] & 0x28000000)) | |
19ae3e61 JR |
1582 | return 1; |
1583 | } | |
1584 | ||
1585 | /* This font matches. */ | |
1586 | ||
1587 | /* If registry was specified, ensure it is reported as the same. */ | |
1588 | if (!NILP (spec_charset)) | |
22610910 JR |
1589 | { |
1590 | /* Avoid using non-Japanese fonts for Japanese, even if they | |
1591 | claim they are capable, due to known breakage in Vista | |
1592 | and Windows 7 fonts (bug#6029). */ | |
1593 | if (logical_font->elfLogFont.lfCharSet == SHIFTJIS_CHARSET | |
1594 | && !(physical_font->ntmFontSig.fsCsb[0] & CSB_JAPANESE)) | |
1595 | return 1; | |
1596 | else | |
1597 | ASET (entity, FONT_REGISTRY_INDEX, spec_charset); | |
1598 | } | |
19ae3e61 | 1599 | /* Otherwise if using the uniscribe backend, report ANSI and DEFAULT |
fe7a3057 | 1600 | fonts as Unicode and skip other charsets. */ |
19ae3e61 JR |
1601 | else if (match_data->opentype_only) |
1602 | { | |
1603 | if (logical_font->elfLogFont.lfCharSet == ANSI_CHARSET | |
1604 | || logical_font->elfLogFont.lfCharSet == DEFAULT_CHARSET) | |
1605 | ASET (entity, FONT_REGISTRY_INDEX, Qiso10646_1); | |
1606 | else | |
1607 | return 1; | |
1608 | } | |
1609 | ||
1610 | /* Add this font to the list. */ | |
1611 | match_data->list = Fcons (entity, match_data->list); | |
d205d43b | 1612 | } |
f7a84cb4 JR |
1613 | return 1; |
1614 | } | |
1615 | ||
1616 | /* Callback function for EnumFontFamiliesEx. | |
d205d43b | 1617 | * Terminates the search once we have a match. */ |
20399669 | 1618 | static int CALLBACK |
b56ceb92 JB |
1619 | add_one_font_entity_to_list (ENUMLOGFONTEX *logical_font, |
1620 | NEWTEXTMETRICEX *physical_font, | |
1621 | DWORD font_type, LPARAM lParam) | |
f7a84cb4 | 1622 | { |
d205d43b JR |
1623 | struct font_callback_data *match_data |
1624 | = (struct font_callback_data *) lParam; | |
1625 | add_font_entity_to_list (logical_font, physical_font, font_type, lParam); | |
1626 | ||
1627 | /* If we have a font in the list, terminate the search. */ | |
4624b6e3 | 1628 | return NILP (match_data->list); |
f7a84cb4 JR |
1629 | } |
1630 | ||
57016d37 JR |
1631 | /* Old function to convert from x to w32 charset, from w32fns.c. */ |
1632 | static LONG | |
b56ceb92 | 1633 | x_to_w32_charset (char * lpcs) |
57016d37 JR |
1634 | { |
1635 | Lisp_Object this_entry, w32_charset; | |
1636 | char *charset; | |
1637 | int len = strlen (lpcs); | |
1638 | ||
1639 | /* Support "*-#nnn" format for unknown charsets. */ | |
1640 | if (strncmp (lpcs, "*-#", 3) == 0) | |
1641 | return atoi (lpcs + 3); | |
1642 | ||
fe7a3057 | 1643 | /* All Windows fonts qualify as Unicode. */ |
57016d37 JR |
1644 | if (!strncmp (lpcs, "iso10646", 8)) |
1645 | return DEFAULT_CHARSET; | |
1646 | ||
1647 | /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */ | |
1648 | charset = alloca (len + 1); | |
1649 | strcpy (charset, lpcs); | |
1650 | lpcs = strchr (charset, '*'); | |
1651 | if (lpcs) | |
1652 | *lpcs = '\0'; | |
1653 | ||
1654 | /* Look through w32-charset-info-alist for the character set. | |
1655 | Format of each entry is | |
1656 | (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). | |
1657 | */ | |
1658 | this_entry = Fassoc (build_string (charset), Vw32_charset_info_alist); | |
1659 | ||
1660 | if (NILP (this_entry)) | |
1661 | { | |
1662 | /* At startup, we want iso8859-1 fonts to come up properly. */ | |
1663 | if (xstrcasecmp (charset, "iso8859-1") == 0) | |
1664 | return ANSI_CHARSET; | |
1665 | else | |
1666 | return DEFAULT_CHARSET; | |
1667 | } | |
1668 | ||
1669 | w32_charset = Fcar (Fcdr (this_entry)); | |
1670 | ||
1671 | /* Translate Lisp symbol to number. */ | |
1672 | if (EQ (w32_charset, Qw32_charset_ansi)) | |
1673 | return ANSI_CHARSET; | |
1674 | if (EQ (w32_charset, Qw32_charset_symbol)) | |
1675 | return SYMBOL_CHARSET; | |
1676 | if (EQ (w32_charset, Qw32_charset_shiftjis)) | |
1677 | return SHIFTJIS_CHARSET; | |
1678 | if (EQ (w32_charset, Qw32_charset_hangeul)) | |
1679 | return HANGEUL_CHARSET; | |
1680 | if (EQ (w32_charset, Qw32_charset_chinesebig5)) | |
1681 | return CHINESEBIG5_CHARSET; | |
1682 | if (EQ (w32_charset, Qw32_charset_gb2312)) | |
1683 | return GB2312_CHARSET; | |
1684 | if (EQ (w32_charset, Qw32_charset_oem)) | |
1685 | return OEM_CHARSET; | |
1686 | if (EQ (w32_charset, Qw32_charset_johab)) | |
1687 | return JOHAB_CHARSET; | |
1688 | if (EQ (w32_charset, Qw32_charset_easteurope)) | |
1689 | return EASTEUROPE_CHARSET; | |
1690 | if (EQ (w32_charset, Qw32_charset_turkish)) | |
1691 | return TURKISH_CHARSET; | |
1692 | if (EQ (w32_charset, Qw32_charset_baltic)) | |
1693 | return BALTIC_CHARSET; | |
1694 | if (EQ (w32_charset, Qw32_charset_russian)) | |
1695 | return RUSSIAN_CHARSET; | |
1696 | if (EQ (w32_charset, Qw32_charset_arabic)) | |
1697 | return ARABIC_CHARSET; | |
1698 | if (EQ (w32_charset, Qw32_charset_greek)) | |
1699 | return GREEK_CHARSET; | |
1700 | if (EQ (w32_charset, Qw32_charset_hebrew)) | |
1701 | return HEBREW_CHARSET; | |
1702 | if (EQ (w32_charset, Qw32_charset_vietnamese)) | |
1703 | return VIETNAMESE_CHARSET; | |
1704 | if (EQ (w32_charset, Qw32_charset_thai)) | |
1705 | return THAI_CHARSET; | |
1706 | if (EQ (w32_charset, Qw32_charset_mac)) | |
1707 | return MAC_CHARSET; | |
1708 | ||
1709 | return DEFAULT_CHARSET; | |
1710 | } | |
1711 | ||
1712 | ||
f7a84cb4 | 1713 | /* Convert a Lisp font registry (symbol) to a windows charset. */ |
20399669 | 1714 | static LONG |
b56ceb92 | 1715 | registry_to_w32_charset (Lisp_Object charset) |
f7a84cb4 JR |
1716 | { |
1717 | if (EQ (charset, Qiso10646_1) || EQ (charset, Qunicode_bmp) | |
1718 | || EQ (charset, Qunicode_sip)) | |
1719 | return DEFAULT_CHARSET; /* UNICODE_CHARSET not defined in MingW32 */ | |
1720 | else if (EQ (charset, Qiso8859_1)) | |
1721 | return ANSI_CHARSET; | |
040fe918 JR |
1722 | else if (SYMBOLP (charset)) |
1723 | return x_to_w32_charset (SDATA (SYMBOL_NAME (charset))); | |
f7a84cb4 JR |
1724 | else |
1725 | return DEFAULT_CHARSET; | |
1726 | } | |
1727 | ||
57016d37 JR |
1728 | /* Old function to convert from w32 to x charset, from w32fns.c. */ |
1729 | static char * | |
b56ceb92 | 1730 | w32_to_x_charset (int fncharset, char *matching) |
57016d37 JR |
1731 | { |
1732 | static char buf[32]; | |
1733 | Lisp_Object charset_type; | |
1734 | int match_len = 0; | |
1735 | ||
1736 | if (matching) | |
1737 | { | |
1738 | /* If fully specified, accept it as it is. Otherwise use a | |
1739 | substring match. */ | |
1740 | char *wildcard = strchr (matching, '*'); | |
1741 | if (wildcard) | |
1742 | *wildcard = '\0'; | |
1743 | else if (strchr (matching, '-')) | |
1744 | return matching; | |
1745 | ||
1746 | match_len = strlen (matching); | |
1747 | } | |
1748 | ||
1749 | switch (fncharset) | |
1750 | { | |
1751 | case ANSI_CHARSET: | |
1752 | /* Handle startup case of w32-charset-info-alist not | |
1753 | being set up yet. */ | |
1754 | if (NILP (Vw32_charset_info_alist)) | |
1755 | return "iso8859-1"; | |
1756 | charset_type = Qw32_charset_ansi; | |
1757 | break; | |
1758 | case DEFAULT_CHARSET: | |
1759 | charset_type = Qw32_charset_default; | |
1760 | break; | |
1761 | case SYMBOL_CHARSET: | |
1762 | charset_type = Qw32_charset_symbol; | |
1763 | break; | |
1764 | case SHIFTJIS_CHARSET: | |
1765 | charset_type = Qw32_charset_shiftjis; | |
1766 | break; | |
1767 | case HANGEUL_CHARSET: | |
1768 | charset_type = Qw32_charset_hangeul; | |
1769 | break; | |
1770 | case GB2312_CHARSET: | |
1771 | charset_type = Qw32_charset_gb2312; | |
1772 | break; | |
1773 | case CHINESEBIG5_CHARSET: | |
1774 | charset_type = Qw32_charset_chinesebig5; | |
1775 | break; | |
1776 | case OEM_CHARSET: | |
1777 | charset_type = Qw32_charset_oem; | |
1778 | break; | |
1779 | case EASTEUROPE_CHARSET: | |
1780 | charset_type = Qw32_charset_easteurope; | |
1781 | break; | |
1782 | case TURKISH_CHARSET: | |
1783 | charset_type = Qw32_charset_turkish; | |
1784 | break; | |
1785 | case BALTIC_CHARSET: | |
1786 | charset_type = Qw32_charset_baltic; | |
1787 | break; | |
1788 | case RUSSIAN_CHARSET: | |
1789 | charset_type = Qw32_charset_russian; | |
1790 | break; | |
1791 | case ARABIC_CHARSET: | |
1792 | charset_type = Qw32_charset_arabic; | |
1793 | break; | |
1794 | case GREEK_CHARSET: | |
1795 | charset_type = Qw32_charset_greek; | |
1796 | break; | |
1797 | case HEBREW_CHARSET: | |
1798 | charset_type = Qw32_charset_hebrew; | |
1799 | break; | |
1800 | case VIETNAMESE_CHARSET: | |
1801 | charset_type = Qw32_charset_vietnamese; | |
1802 | break; | |
1803 | case THAI_CHARSET: | |
1804 | charset_type = Qw32_charset_thai; | |
1805 | break; | |
1806 | case MAC_CHARSET: | |
1807 | charset_type = Qw32_charset_mac; | |
1808 | break; | |
1809 | case JOHAB_CHARSET: | |
1810 | charset_type = Qw32_charset_johab; | |
1811 | break; | |
1812 | ||
1813 | default: | |
1814 | /* Encode numerical value of unknown charset. */ | |
1815 | sprintf (buf, "*-#%u", fncharset); | |
1816 | return buf; | |
1817 | } | |
1818 | ||
1819 | { | |
1820 | Lisp_Object rest; | |
1821 | char * best_match = NULL; | |
1822 | int matching_found = 0; | |
1823 | ||
1824 | /* Look through w32-charset-info-alist for the character set. | |
1825 | Prefer ISO codepages, and prefer lower numbers in the ISO | |
1826 | range. Only return charsets for codepages which are installed. | |
1827 | ||
1828 | Format of each entry is | |
1829 | (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). | |
1830 | */ | |
1831 | for (rest = Vw32_charset_info_alist; CONSP (rest); rest = XCDR (rest)) | |
1832 | { | |
1833 | char * x_charset; | |
1834 | Lisp_Object w32_charset; | |
1835 | Lisp_Object codepage; | |
1836 | ||
1837 | Lisp_Object this_entry = XCAR (rest); | |
1838 | ||
1839 | /* Skip invalid entries in alist. */ | |
1840 | if (!CONSP (this_entry) || !STRINGP (XCAR (this_entry)) | |
1841 | || !CONSP (XCDR (this_entry)) | |
1842 | || !SYMBOLP (XCAR (XCDR (this_entry)))) | |
1843 | continue; | |
1844 | ||
1845 | x_charset = SDATA (XCAR (this_entry)); | |
1846 | w32_charset = XCAR (XCDR (this_entry)); | |
1847 | codepage = XCDR (XCDR (this_entry)); | |
1848 | ||
1849 | /* Look for Same charset and a valid codepage (or non-int | |
1850 | which means ignore). */ | |
1851 | if (EQ (w32_charset, charset_type) | |
1852 | && (!INTEGERP (codepage) || XINT (codepage) == CP_DEFAULT | |
1853 | || IsValidCodePage (XINT (codepage)))) | |
1854 | { | |
1855 | /* If we don't have a match already, then this is the | |
1856 | best. */ | |
1857 | if (!best_match) | |
1858 | { | |
1859 | best_match = x_charset; | |
1860 | if (matching && !strnicmp (x_charset, matching, match_len)) | |
1861 | matching_found = 1; | |
1862 | } | |
1863 | /* If we already found a match for MATCHING, then | |
1864 | only consider other matches. */ | |
1865 | else if (matching_found | |
1866 | && strnicmp (x_charset, matching, match_len)) | |
1867 | continue; | |
1868 | /* If this matches what we want, and the best so far doesn't, | |
1869 | then this is better. */ | |
1870 | else if (!matching_found && matching | |
1871 | && !strnicmp (x_charset, matching, match_len)) | |
1872 | { | |
1873 | best_match = x_charset; | |
1874 | matching_found = 1; | |
1875 | } | |
1876 | /* If this is fully specified, and the best so far isn't, | |
1877 | then this is better. */ | |
1878 | else if ((!strchr (best_match, '-') && strchr (x_charset, '-')) | |
1879 | /* If this is an ISO codepage, and the best so far isn't, | |
1880 | then this is better, but only if it fully specifies the | |
1881 | encoding. */ | |
1882 | || (strnicmp (best_match, "iso", 3) != 0 | |
1883 | && strnicmp (x_charset, "iso", 3) == 0 | |
1884 | && strchr (x_charset, '-'))) | |
1885 | best_match = x_charset; | |
1886 | /* If both are ISO8859 codepages, choose the one with the | |
1887 | lowest number in the encoding field. */ | |
1888 | else if (strnicmp (best_match, "iso8859-", 8) == 0 | |
1889 | && strnicmp (x_charset, "iso8859-", 8) == 0) | |
1890 | { | |
1891 | int best_enc = atoi (best_match + 8); | |
1892 | int this_enc = atoi (x_charset + 8); | |
1893 | if (this_enc > 0 && this_enc < best_enc) | |
1894 | best_match = x_charset; | |
1895 | } | |
1896 | } | |
1897 | } | |
1898 | ||
1899 | /* If no match, encode the numeric value. */ | |
1900 | if (!best_match) | |
1901 | { | |
1902 | sprintf (buf, "*-#%u", fncharset); | |
1903 | return buf; | |
1904 | } | |
1905 | ||
1906 | strncpy (buf, best_match, 31); | |
1907 | /* If the charset is not fully specified, put -0 on the end. */ | |
1908 | if (!strchr (best_match, '-')) | |
1909 | { | |
1910 | int pos = strlen (best_match); | |
1911 | /* Charset specifiers shouldn't be very long. If it is a made | |
1912 | up one, truncating it should not do any harm since it isn't | |
1913 | recognized anyway. */ | |
1914 | if (pos > 29) | |
1915 | pos = 29; | |
1916 | strcpy (buf + pos, "-0"); | |
1917 | } | |
1918 | buf[31] = '\0'; | |
1919 | return buf; | |
1920 | } | |
1921 | } | |
1922 | ||
20399669 | 1923 | static Lisp_Object |
b56ceb92 | 1924 | w32_registry (LONG w32_charset, DWORD font_type) |
f7a84cb4 | 1925 | { |
aee986fd JR |
1926 | char *charset; |
1927 | ||
fe7a3057 | 1928 | /* If charset is defaulted, charset is Unicode or unknown, depending on |
aee986fd | 1929 | font type. */ |
c960bff8 | 1930 | if (w32_charset == DEFAULT_CHARSET) |
aee986fd | 1931 | return font_type == TRUETYPE_FONTTYPE ? Qiso10646_1 : Qunknown; |
c960bff8 | 1932 | |
aee986fd | 1933 | charset = w32_to_x_charset (w32_charset, NULL); |
ed3751c8 | 1934 | return font_intern_prop (charset, strlen (charset), 1); |
f7a84cb4 JR |
1935 | } |
1936 | ||
5f18d119 | 1937 | static int |
b56ceb92 | 1938 | w32_decode_weight (int fnweight) |
5f18d119 KH |
1939 | { |
1940 | if (fnweight >= FW_HEAVY) return 210; | |
1941 | if (fnweight >= FW_EXTRABOLD) return 205; | |
1942 | if (fnweight >= FW_BOLD) return 200; | |
1943 | if (fnweight >= FW_SEMIBOLD) return 180; | |
1944 | if (fnweight >= FW_NORMAL) return 100; | |
1945 | if (fnweight >= FW_LIGHT) return 50; | |
1946 | if (fnweight >= FW_EXTRALIGHT) return 40; | |
9d4f32e8 | 1947 | if (fnweight > FW_THIN) return 20; |
5f18d119 KH |
1948 | return 0; |
1949 | } | |
1950 | ||
1951 | static int | |
b56ceb92 | 1952 | w32_encode_weight (int n) |
5f18d119 KH |
1953 | { |
1954 | if (n >= 210) return FW_HEAVY; | |
1955 | if (n >= 205) return FW_EXTRABOLD; | |
1956 | if (n >= 200) return FW_BOLD; | |
1957 | if (n >= 180) return FW_SEMIBOLD; | |
1958 | if (n >= 100) return FW_NORMAL; | |
1959 | if (n >= 50) return FW_LIGHT; | |
1960 | if (n >= 40) return FW_EXTRALIGHT; | |
9d4f32e8 | 1961 | if (n >= 20) return FW_THIN; |
5f18d119 KH |
1962 | return 0; |
1963 | } | |
1964 | ||
3ef8c1b4 JR |
1965 | /* Convert a Windows font weight into one of the weights supported |
1966 | by fontconfig (see font.c:font_parse_fcname). */ | |
1967 | static Lisp_Object | |
b56ceb92 | 1968 | w32_to_fc_weight (int n) |
3ef8c1b4 JR |
1969 | { |
1970 | if (n >= FW_EXTRABOLD) return intern ("black"); | |
9d4f32e8 JB |
1971 | if (n >= FW_BOLD) return intern ("bold"); |
1972 | if (n >= FW_SEMIBOLD) return intern ("demibold"); | |
1973 | if (n >= FW_NORMAL) return intern ("medium"); | |
3ef8c1b4 JR |
1974 | return intern ("light"); |
1975 | } | |
1976 | ||
f7a84cb4 | 1977 | /* Fill in all the available details of LOGFONT from FONT_SPEC. */ |
20399669 | 1978 | static void |
b56ceb92 | 1979 | fill_in_logfont (FRAME_PTR f, LOGFONT *logfont, Lisp_Object font_spec) |
f7a84cb4 | 1980 | { |
d205d43b | 1981 | Lisp_Object tmp, extra; |
f7a84cb4 JR |
1982 | int dpi = FRAME_W32_DISPLAY_INFO (f)->resy; |
1983 | ||
5f18d119 KH |
1984 | tmp = AREF (font_spec, FONT_DPI_INDEX); |
1985 | if (INTEGERP (tmp)) | |
d205d43b | 1986 | { |
5f18d119 KH |
1987 | dpi = XINT (tmp); |
1988 | } | |
1989 | else if (FLOATP (tmp)) | |
1990 | { | |
1991 | dpi = (int) (XFLOAT_DATA (tmp) + 0.5); | |
d205d43b | 1992 | } |
f7a84cb4 JR |
1993 | |
1994 | /* Height */ | |
1995 | tmp = AREF (font_spec, FONT_SIZE_INDEX); | |
1996 | if (INTEGERP (tmp)) | |
040fe918 | 1997 | logfont->lfHeight = -1 * XINT (tmp); |
f7a84cb4 | 1998 | else if (FLOATP (tmp)) |
d205d43b | 1999 | logfont->lfHeight = (int) (-1.0 * dpi * XFLOAT_DATA (tmp) / 72.27 + 0.5); |
f7a84cb4 JR |
2000 | |
2001 | /* Escapement */ | |
2002 | ||
2003 | /* Orientation */ | |
2004 | ||
2005 | /* Weight */ | |
2006 | tmp = AREF (font_spec, FONT_WEIGHT_INDEX); | |
2007 | if (INTEGERP (tmp)) | |
5f18d119 | 2008 | logfont->lfWeight = w32_encode_weight (FONT_WEIGHT_NUMERIC (font_spec)); |
f7a84cb4 JR |
2009 | |
2010 | /* Italic */ | |
2011 | tmp = AREF (font_spec, FONT_SLANT_INDEX); | |
2012 | if (INTEGERP (tmp)) | |
2013 | { | |
5f18d119 | 2014 | int slant = FONT_SLANT_NUMERIC (font_spec); |
f7a84cb4 JR |
2015 | logfont->lfItalic = slant > 150 ? 1 : 0; |
2016 | } | |
2017 | ||
2018 | /* Underline */ | |
2019 | ||
2020 | /* Strikeout */ | |
2021 | ||
2022 | /* Charset */ | |
2023 | tmp = AREF (font_spec, FONT_REGISTRY_INDEX); | |
2024 | if (! NILP (tmp)) | |
d205d43b | 2025 | logfont->lfCharSet = registry_to_w32_charset (tmp); |
56df6710 JR |
2026 | else |
2027 | logfont->lfCharSet = DEFAULT_CHARSET; | |
f7a84cb4 JR |
2028 | |
2029 | /* Out Precision */ | |
91583281 | 2030 | |
f7a84cb4 | 2031 | /* Clip Precision */ |
91583281 JR |
2032 | |
2033 | /* Quality */ | |
040fe918 JR |
2034 | logfont->lfQuality = DEFAULT_QUALITY; |
2035 | ||
d205d43b JR |
2036 | /* Generic Family and Face Name */ |
2037 | logfont->lfPitchAndFamily = FF_DONTCARE | DEFAULT_PITCH; | |
2038 | ||
f7a84cb4 | 2039 | tmp = AREF (font_spec, FONT_FAMILY_INDEX); |
d205d43b JR |
2040 | if (! NILP (tmp)) |
2041 | { | |
2042 | logfont->lfPitchAndFamily = w32_generic_family (tmp) | DEFAULT_PITCH; | |
2043 | if ((logfont->lfPitchAndFamily & 0xF0) != FF_DONTCARE) | |
2044 | ; /* Font name was generic, don't fill in font name. */ | |
2045 | /* Font families are interned, but allow for strings also in case of | |
2046 | user input. */ | |
2047 | else if (SYMBOLP (tmp)) | |
bf98199c JM |
2048 | { |
2049 | strncpy (logfont->lfFaceName, | |
2050 | SDATA (ENCODE_SYSTEM (SYMBOL_NAME (tmp))), LF_FACESIZE); | |
2051 | logfont->lfFaceName[LF_FACESIZE-1] = '\0'; | |
2052 | } | |
d205d43b | 2053 | } |
f7a84cb4 | 2054 | |
9e1a2995 JR |
2055 | tmp = AREF (font_spec, FONT_ADSTYLE_INDEX); |
2056 | if (!NILP (tmp)) | |
2057 | { | |
2058 | /* Override generic family. */ | |
2059 | BYTE family = w32_generic_family (tmp); | |
2060 | if (family != FF_DONTCARE) | |
2061 | logfont->lfPitchAndFamily = family | DEFAULT_PITCH; | |
2062 | } | |
2063 | ||
5f18d119 KH |
2064 | /* Set pitch based on the spacing property. */ |
2065 | tmp = AREF (font_spec, FONT_SPACING_INDEX); | |
2066 | if (INTEGERP (tmp)) | |
2067 | { | |
2068 | int spacing = XINT (tmp); | |
2069 | if (spacing < FONT_SPACING_MONO) | |
2070 | logfont->lfPitchAndFamily | |
657d08d3 | 2071 | = (logfont->lfPitchAndFamily & 0xF0) | VARIABLE_PITCH; |
5f18d119 KH |
2072 | else |
2073 | logfont->lfPitchAndFamily | |
657d08d3 | 2074 | = (logfont->lfPitchAndFamily & 0xF0) | FIXED_PITCH; |
5f18d119 KH |
2075 | } |
2076 | ||
d205d43b | 2077 | /* Process EXTRA info. */ |
5f18d119 KH |
2078 | for (extra = AREF (font_spec, FONT_EXTRA_INDEX); |
2079 | CONSP (extra); extra = XCDR (extra)) | |
d205d43b JR |
2080 | { |
2081 | tmp = XCAR (extra); | |
2082 | if (CONSP (tmp)) | |
2083 | { | |
2084 | Lisp_Object key, val; | |
2085 | key = XCAR (tmp), val = XCDR (tmp); | |
fe7a3057 | 2086 | /* Only use QCscript if charset is not provided, or is Unicode |
d205d43b JR |
2087 | and a single script is specified. This is rather crude, |
2088 | and is only used to narrow down the fonts returned where | |
2089 | there is a definite match. Some scripts, such as latin, han, | |
2090 | cjk-misc match multiple lfCharSet values, so we can't pre-filter | |
2091 | them. */ | |
5f18d119 | 2092 | if (EQ (key, QCscript) |
d205d43b JR |
2093 | && logfont->lfCharSet == DEFAULT_CHARSET |
2094 | && SYMBOLP (val)) | |
2095 | { | |
2096 | if (EQ (val, Qgreek)) | |
2097 | logfont->lfCharSet = GREEK_CHARSET; | |
2098 | else if (EQ (val, Qhangul)) | |
2099 | logfont->lfCharSet = HANGUL_CHARSET; | |
2100 | else if (EQ (val, Qkana) || EQ (val, Qkanbun)) | |
2101 | logfont->lfCharSet = SHIFTJIS_CHARSET; | |
2102 | else if (EQ (val, Qbopomofo)) | |
2103 | logfont->lfCharSet = CHINESEBIG5_CHARSET; | |
2104 | /* GB 18030 supports tibetan, yi, mongolian, | |
2105 | fonts that support it should show up if we ask for | |
2106 | GB2312 fonts. */ | |
2107 | else if (EQ (val, Qtibetan) || EQ (val, Qyi) | |
2108 | || EQ (val, Qmongolian)) | |
2109 | logfont->lfCharSet = GB2312_CHARSET; | |
2110 | else if (EQ (val, Qhebrew)) | |
2111 | logfont->lfCharSet = HEBREW_CHARSET; | |
2112 | else if (EQ (val, Qarabic)) | |
2113 | logfont->lfCharSet = ARABIC_CHARSET; | |
2114 | else if (EQ (val, Qthai)) | |
2115 | logfont->lfCharSet = THAI_CHARSET; | |
d205d43b | 2116 | } |
91583281 JR |
2117 | else if (EQ (key, QCantialias) && SYMBOLP (val)) |
2118 | { | |
2119 | logfont->lfQuality = w32_antialias_type (val); | |
2120 | } | |
d205d43b JR |
2121 | } |
2122 | } | |
f7a84cb4 JR |
2123 | } |
2124 | ||
20399669 | 2125 | static void |
b56ceb92 | 2126 | list_all_matching_fonts (struct font_callback_data *match_data) |
f7a84cb4 JR |
2127 | { |
2128 | HDC dc; | |
d205d43b JR |
2129 | Lisp_Object families = w32font_list_family (match_data->frame); |
2130 | struct frame *f = XFRAME (match_data->frame); | |
f7a84cb4 JR |
2131 | |
2132 | dc = get_frame_dc (f); | |
2133 | ||
2134 | while (!NILP (families)) | |
2135 | { | |
e6df5336 JR |
2136 | /* Only fonts from the current locale are given localized names |
2137 | on Windows, so we can keep backwards compatibility with | |
2138 | Windows 9x/ME by using non-Unicode font enumeration without | |
2139 | sacrificing internationalization here. */ | |
d205d43b | 2140 | char *name; |
f7a84cb4 JR |
2141 | Lisp_Object family = CAR (families); |
2142 | families = CDR (families); | |
d205d43b JR |
2143 | if (NILP (family)) |
2144 | continue; | |
8f112d52 | 2145 | else if (SYMBOLP (family)) |
e6df5336 | 2146 | name = SDATA (ENCODE_SYSTEM (SYMBOL_NAME (family))); |
8f112d52 JR |
2147 | else |
2148 | continue; | |
d205d43b JR |
2149 | |
2150 | strncpy (match_data->pattern.lfFaceName, name, LF_FACESIZE); | |
2151 | match_data->pattern.lfFaceName[LF_FACESIZE - 1] = '\0'; | |
2152 | ||
2153 | EnumFontFamiliesEx (dc, &match_data->pattern, | |
2154 | (FONTENUMPROC) add_font_entity_to_list, | |
2155 | (LPARAM) match_data, 0); | |
f7a84cb4 JR |
2156 | } |
2157 | ||
2158 | release_frame_dc (f, dc); | |
2159 | } | |
2160 | ||
91583281 | 2161 | static Lisp_Object |
b56ceb92 | 2162 | lispy_antialias_type (BYTE type) |
91583281 JR |
2163 | { |
2164 | Lisp_Object lispy; | |
2165 | ||
2166 | switch (type) | |
2167 | { | |
2168 | case NONANTIALIASED_QUALITY: | |
2169 | lispy = Qnone; | |
2170 | break; | |
2171 | case ANTIALIASED_QUALITY: | |
2172 | lispy = Qstandard; | |
2173 | break; | |
2174 | case CLEARTYPE_QUALITY: | |
2175 | lispy = Qsubpixel; | |
2176 | break; | |
2177 | case CLEARTYPE_NATURAL_QUALITY: | |
2178 | lispy = Qnatural; | |
2179 | break; | |
2180 | default: | |
2181 | lispy = Qnil; | |
2182 | break; | |
2183 | } | |
2184 | return lispy; | |
2185 | } | |
2186 | ||
2187 | /* Convert antialiasing symbols to lfQuality */ | |
2188 | static BYTE | |
b56ceb92 | 2189 | w32_antialias_type (Lisp_Object type) |
91583281 JR |
2190 | { |
2191 | if (EQ (type, Qnone)) | |
2192 | return NONANTIALIASED_QUALITY; | |
2193 | else if (EQ (type, Qstandard)) | |
2194 | return ANTIALIASED_QUALITY; | |
2195 | else if (EQ (type, Qsubpixel)) | |
2196 | return CLEARTYPE_QUALITY; | |
2197 | else if (EQ (type, Qnatural)) | |
2198 | return CLEARTYPE_NATURAL_QUALITY; | |
2199 | else | |
2200 | return DEFAULT_QUALITY; | |
2201 | } | |
2202 | ||
d205d43b JR |
2203 | /* Return a list of all the scripts that the font supports. */ |
2204 | static Lisp_Object | |
2205 | font_supported_scripts (FONTSIGNATURE * sig) | |
f7a84cb4 | 2206 | { |
d205d43b JR |
2207 | DWORD * subranges = sig->fsUsb; |
2208 | Lisp_Object supported = Qnil; | |
2209 | ||
2210 | /* Match a single subrange. SYM is set if bit N is set in subranges. */ | |
2211 | #define SUBRANGE(n,sym) \ | |
2212 | if (subranges[(n) / 32] & (1 << ((n) % 32))) \ | |
2213 | supported = Fcons ((sym), supported) | |
2214 | ||
2215 | /* Match multiple subranges. SYM is set if any MASK bit is set in | |
2216 | subranges[0 - 3]. */ | |
2217 | #define MASK_ANY(mask0,mask1,mask2,mask3,sym) \ | |
2218 | if ((subranges[0] & (mask0)) || (subranges[1] & (mask1)) \ | |
2219 | || (subranges[2] & (mask2)) || (subranges[3] & (mask3))) \ | |
2220 | supported = Fcons ((sym), supported) | |
2221 | ||
56df6710 JR |
2222 | SUBRANGE (0, Qlatin); |
2223 | /* The following count as latin too, ASCII should be present in these fonts, | |
2224 | so don't need to mark them separately. */ | |
2225 | /* 1: Latin-1 supplement, 2: Latin Extended A, 3: Latin Extended B. */ | |
2226 | SUBRANGE (4, Qphonetic); | |
dbdb7031 | 2227 | /* 5: Spacing and tone modifiers, 6: Combining Diacritical Marks. */ |
d205d43b JR |
2228 | SUBRANGE (7, Qgreek); |
2229 | SUBRANGE (8, Qcoptic); | |
2230 | SUBRANGE (9, Qcyrillic); | |
2231 | SUBRANGE (10, Qarmenian); | |
2232 | SUBRANGE (11, Qhebrew); | |
174f1c74 | 2233 | /* 12: Vai. */ |
d205d43b JR |
2234 | SUBRANGE (13, Qarabic); |
2235 | SUBRANGE (14, Qnko); | |
2236 | SUBRANGE (15, Qdevanagari); | |
2237 | SUBRANGE (16, Qbengali); | |
2238 | SUBRANGE (17, Qgurmukhi); | |
2239 | SUBRANGE (18, Qgujarati); | |
2240 | SUBRANGE (19, Qoriya); | |
2241 | SUBRANGE (20, Qtamil); | |
2242 | SUBRANGE (21, Qtelugu); | |
2243 | SUBRANGE (22, Qkannada); | |
2244 | SUBRANGE (23, Qmalayalam); | |
2245 | SUBRANGE (24, Qthai); | |
2246 | SUBRANGE (25, Qlao); | |
2247 | SUBRANGE (26, Qgeorgian); | |
56df6710 JR |
2248 | SUBRANGE (27, Qbalinese); |
2249 | /* 28: Hangul Jamo. */ | |
2250 | /* 29: Latin Extended, 30: Greek Extended, 31: Punctuation. */ | |
2251 | /* 32-47: Symbols (defined below). */ | |
d205d43b | 2252 | SUBRANGE (48, Qcjk_misc); |
56df6710 JR |
2253 | /* Match either 49: katakana or 50: hiragana for kana. */ |
2254 | MASK_ANY (0, 0x00060000, 0, 0, Qkana); | |
d205d43b | 2255 | SUBRANGE (51, Qbopomofo); |
56df6710 JR |
2256 | /* 52: Compatibility Jamo */ |
2257 | SUBRANGE (53, Qphags_pa); | |
2258 | /* 54: Enclosed CJK letters and months, 55: CJK Compatibility. */ | |
d205d43b | 2259 | SUBRANGE (56, Qhangul); |
56df6710 JR |
2260 | /* 57: Surrogates. */ |
2261 | SUBRANGE (58, Qphoenician); | |
d205d43b | 2262 | SUBRANGE (59, Qhan); /* There are others, but this is the main one. */ |
56df6710 JR |
2263 | SUBRANGE (59, Qideographic_description); /* Windows lumps this in. */ |
2264 | SUBRANGE (59, Qkanbun); /* And this. */ | |
2265 | /* 60: Private use, 61: CJK strokes and compatibility. */ | |
2266 | /* 62: Alphabetic Presentation, 63: Arabic Presentation A. */ | |
2267 | /* 64: Combining half marks, 65: Vertical and CJK compatibility. */ | |
2268 | /* 66: Small forms, 67: Arabic Presentation B, 68: Half and Full width. */ | |
2269 | /* 69: Specials. */ | |
d205d43b JR |
2270 | SUBRANGE (70, Qtibetan); |
2271 | SUBRANGE (71, Qsyriac); | |
2272 | SUBRANGE (72, Qthaana); | |
2273 | SUBRANGE (73, Qsinhala); | |
2274 | SUBRANGE (74, Qmyanmar); | |
2275 | SUBRANGE (75, Qethiopic); | |
2276 | SUBRANGE (76, Qcherokee); | |
2277 | SUBRANGE (77, Qcanadian_aboriginal); | |
2278 | SUBRANGE (78, Qogham); | |
2279 | SUBRANGE (79, Qrunic); | |
2280 | SUBRANGE (80, Qkhmer); | |
2281 | SUBRANGE (81, Qmongolian); | |
2282 | SUBRANGE (82, Qbraille); | |
2283 | SUBRANGE (83, Qyi); | |
56df6710 JR |
2284 | SUBRANGE (84, Qbuhid); |
2285 | SUBRANGE (84, Qhanunoo); | |
2286 | SUBRANGE (84, Qtagalog); | |
2287 | SUBRANGE (84, Qtagbanwa); | |
2288 | SUBRANGE (85, Qold_italic); | |
2289 | SUBRANGE (86, Qgothic); | |
2290 | SUBRANGE (87, Qdeseret); | |
d205d43b JR |
2291 | SUBRANGE (88, Qbyzantine_musical_symbol); |
2292 | SUBRANGE (88, Qmusical_symbol); /* Windows doesn't distinguish these. */ | |
d205d43b | 2293 | SUBRANGE (89, Qmathematical); |
56df6710 JR |
2294 | /* 90: Private use, 91: Variation selectors, 92: Tags. */ |
2295 | SUBRANGE (93, Qlimbu); | |
2296 | SUBRANGE (94, Qtai_le); | |
2297 | /* 95: New Tai Le */ | |
2298 | SUBRANGE (90, Qbuginese); | |
2299 | SUBRANGE (97, Qglagolitic); | |
2300 | SUBRANGE (98, Qtifinagh); | |
2301 | /* 99: Yijing Hexagrams. */ | |
2302 | SUBRANGE (100, Qsyloti_nagri); | |
2303 | SUBRANGE (101, Qlinear_b); | |
2304 | /* 102: Ancient Greek Numbers. */ | |
2305 | SUBRANGE (103, Qugaritic); | |
2306 | SUBRANGE (104, Qold_persian); | |
2307 | SUBRANGE (105, Qshavian); | |
2308 | SUBRANGE (106, Qosmanya); | |
2309 | SUBRANGE (107, Qcypriot); | |
2310 | SUBRANGE (108, Qkharoshthi); | |
2311 | /* 109: Tai Xuan Jing. */ | |
2312 | SUBRANGE (110, Qcuneiform); | |
174f1c74 JR |
2313 | /* 111: Counting Rods, 112: Sundanese, 113: Lepcha, 114: Ol Chiki. */ |
2314 | /* 115: Saurashtra, 116: Kayah Li, 117: Rejang. */ | |
2315 | SUBRANGE (118, Qcham); | |
2316 | /* 119: Ancient symbols, 120: Phaistos Disc. */ | |
dbdb7031 | 2317 | /* 121: Carian, Lycian, Lydian, 122: Dominoes, Mahjong tiles. */ |
174f1c74 | 2318 | /* 123-127: Reserved. */ |
d205d43b JR |
2319 | |
2320 | /* There isn't really a main symbol range, so include symbol if any | |
2321 | relevant range is set. */ | |
2322 | MASK_ANY (0x8000000, 0x0000FFFF, 0, 0, Qsymbol); | |
2323 | ||
174f1c74 | 2324 | /* Missing: Tai Viet (U+AA80-U+AADF). */ |
d205d43b JR |
2325 | #undef SUBRANGE |
2326 | #undef MASK_ANY | |
2327 | ||
2328 | return supported; | |
f7a84cb4 JR |
2329 | } |
2330 | ||
67997c79 JR |
2331 | /* Generate a full name for a Windows font. |
2332 | The full name is in fcname format, with weight, slant and antialiasing | |
2333 | specified if they are not "normal". */ | |
2334 | static int | |
b56ceb92 JB |
2335 | w32font_full_name (LOGFONT * font, Lisp_Object font_obj, |
2336 | int pixel_size, char *name, int nbytes) | |
67997c79 | 2337 | { |
a823468b | 2338 | int len, height, outline; |
67997c79 JR |
2339 | char *p; |
2340 | Lisp_Object antialiasing, weight = Qnil; | |
2341 | ||
a823468b JR |
2342 | len = strlen (font->lfFaceName); |
2343 | ||
2344 | outline = EQ (AREF (font_obj, FONT_FOUNDRY_INDEX), Qoutline); | |
2345 | ||
2346 | /* Represent size of scalable fonts by point size. But use pixelsize for | |
2347 | raster fonts to indicate that they are exactly that size. */ | |
2348 | if (outline) | |
2349 | len += 11; /* -SIZE */ | |
2350 | else | |
6fe9826d | 2351 | len += 21; |
67997c79 JR |
2352 | |
2353 | if (font->lfItalic) | |
2354 | len += 7; /* :italic */ | |
2355 | ||
2356 | if (font->lfWeight && font->lfWeight != FW_NORMAL) | |
2357 | { | |
3ef8c1b4 JR |
2358 | weight = w32_to_fc_weight (font->lfWeight); |
2359 | len += 1 + SBYTES (SYMBOL_NAME (weight)); /* :WEIGHT */ | |
67997c79 JR |
2360 | } |
2361 | ||
2362 | antialiasing = lispy_antialias_type (font->lfQuality); | |
2363 | if (! NILP (antialiasing)) | |
2364 | len += 11 + SBYTES (SYMBOL_NAME (antialiasing)); /* :antialias=NAME */ | |
2365 | ||
2366 | /* Check that the buffer is big enough */ | |
2367 | if (len > nbytes) | |
2368 | return -1; | |
2369 | ||
2370 | p = name; | |
2371 | p += sprintf (p, "%s", font->lfFaceName); | |
2372 | ||
a823468b JR |
2373 | height = font->lfHeight ? eabs (font->lfHeight) : pixel_size; |
2374 | ||
2375 | if (height > 0) | |
2376 | { | |
2377 | if (outline) | |
2378 | { | |
2379 | float pointsize = height * 72.0 / one_w32_display_info.resy; | |
7145be81 JR |
2380 | /* Round to nearest half point. floor is used, since round is not |
2381 | supported in MS library. */ | |
2382 | pointsize = floor (pointsize * 2 + 0.5) / 2; | |
a823468b JR |
2383 | p += sprintf (p, "-%1.1f", pointsize); |
2384 | } | |
2385 | else | |
2386 | p += sprintf (p, ":pixelsize=%d", height); | |
2387 | } | |
67997c79 | 2388 | |
3ef8c1b4 JR |
2389 | if (SYMBOLP (weight) && ! NILP (weight)) |
2390 | p += sprintf (p, ":%s", SDATA (SYMBOL_NAME (weight))); | |
2391 | ||
67997c79 JR |
2392 | if (font->lfItalic) |
2393 | p += sprintf (p, ":italic"); | |
2394 | ||
67997c79 JR |
2395 | if (SYMBOLP (antialiasing) && ! NILP (antialiasing)) |
2396 | p += sprintf (p, ":antialias=%s", SDATA (SYMBOL_NAME (antialiasing))); | |
2397 | ||
2398 | return (p - name); | |
2399 | } | |
f7a84cb4 | 2400 | |
6fe9826d JR |
2401 | /* Convert a logfont and point size into a fontconfig style font name. |
2402 | POINTSIZE is in tenths of points. | |
2403 | If SIZE indicates the size of buffer FCNAME, into which the font name | |
2404 | is written. If the buffer is not large enough to contain the name, | |
2405 | the function returns -1, otherwise it returns the number of bytes | |
2406 | written to FCNAME. */ | |
b56ceb92 JB |
2407 | static int |
2408 | logfont_to_fcname (LOGFONT* font, int pointsize, char *fcname, int size) | |
6fe9826d JR |
2409 | { |
2410 | int len, height; | |
2411 | char *p = fcname; | |
2412 | Lisp_Object weight = Qnil; | |
2413 | ||
2414 | len = strlen (font->lfFaceName) + 2; | |
2415 | height = pointsize / 10; | |
2416 | while (height /= 10) | |
2417 | len++; | |
2418 | ||
2419 | if (pointsize % 10) | |
2420 | len += 2; | |
2421 | ||
2422 | if (font->lfItalic) | |
2423 | len += 7; /* :italic */ | |
2424 | if (font->lfWeight && font->lfWeight != FW_NORMAL) | |
2425 | { | |
3ef8c1b4 JR |
2426 | weight = w32_to_fc_weight (font->lfWeight); |
2427 | len += SBYTES (SYMBOL_NAME (weight)) + 1; | |
6fe9826d JR |
2428 | } |
2429 | ||
2430 | if (len > size) | |
2431 | return -1; | |
2432 | ||
2433 | p += sprintf (p, "%s-%d", font->lfFaceName, pointsize / 10); | |
2434 | if (pointsize % 10) | |
2435 | p += sprintf (p, ".%d", pointsize % 10); | |
2436 | ||
3ef8c1b4 JR |
2437 | if (SYMBOLP (weight) && !NILP (weight)) |
2438 | p += sprintf (p, ":%s", SDATA (SYMBOL_NAME (weight))); | |
2439 | ||
6fe9826d JR |
2440 | if (font->lfItalic) |
2441 | p += sprintf (p, ":italic"); | |
2442 | ||
6fe9826d JR |
2443 | return (p - fcname); |
2444 | } | |
34fd2d28 | 2445 | |
9c623c85 | 2446 | static void |
b56ceb92 JB |
2447 | compute_metrics (HDC dc, struct w32font_info *w32_font, unsigned int code, |
2448 | struct w32_metric_cache *metrics) | |
34fd2d28 JR |
2449 | { |
2450 | GLYPHMETRICS gm; | |
2451 | MAT2 transform; | |
8f112d52 JR |
2452 | unsigned int options = GGO_METRICS; |
2453 | ||
2454 | if (w32_font->glyph_idx) | |
2455 | options |= GGO_GLYPH_INDEX; | |
34fd2d28 | 2456 | |
72af86bd | 2457 | memset (&transform, 0, sizeof (transform)); |
34fd2d28 JR |
2458 | transform.eM11.value = 1; |
2459 | transform.eM22.value = 1; | |
8f112d52 | 2460 | |
db4f02f2 | 2461 | if (get_glyph_outline_w (dc, code, options, &gm, 0, NULL, &transform) |
8f112d52 JR |
2462 | != GDI_ERROR) |
2463 | { | |
2464 | metrics->lbearing = gm.gmptGlyphOrigin.x; | |
2465 | metrics->rbearing = gm.gmptGlyphOrigin.x + gm.gmBlackBoxX; | |
2466 | metrics->width = gm.gmCellIncX; | |
2467 | metrics->status = W32METRIC_SUCCESS; | |
2468 | } | |
9c623c85 JB |
2469 | else |
2470 | metrics->status = W32METRIC_FAIL; | |
34fd2d28 JR |
2471 | } |
2472 | ||
6fe9826d JR |
2473 | DEFUN ("x-select-font", Fx_select_font, Sx_select_font, 0, 2, 0, |
2474 | doc: /* Read a font name using a W32 font selection dialog. | |
2475 | Return fontconfig style font string corresponding to the selection. | |
2476 | ||
2477 | If FRAME is omitted or nil, it defaults to the selected frame. | |
1ada3dab | 2478 | If EXCLUDE-PROPORTIONAL is non-nil, exclude proportional fonts |
6fe9826d | 2479 | in the font selection dialog. */) |
5842a27b | 2480 | (Lisp_Object frame, Lisp_Object exclude_proportional) |
6fe9826d JR |
2481 | { |
2482 | FRAME_PTR f = check_x_frame (frame); | |
2483 | CHOOSEFONT cf; | |
2484 | LOGFONT lf; | |
2485 | TEXTMETRIC tm; | |
2486 | HDC hdc; | |
2487 | HANDLE oldobj; | |
2488 | char buf[100]; | |
2489 | ||
72af86bd AS |
2490 | memset (&cf, 0, sizeof (cf)); |
2491 | memset (&lf, 0, sizeof (lf)); | |
6fe9826d JR |
2492 | |
2493 | cf.lStructSize = sizeof (cf); | |
2494 | cf.hwndOwner = FRAME_W32_WINDOW (f); | |
2495 | cf.Flags = CF_FORCEFONTEXIST | CF_SCREENFONTS | CF_NOVERTFONTS; | |
2496 | ||
1ada3dab | 2497 | /* If exclude_proportional is non-nil, limit the selection to |
6fe9826d | 2498 | monospaced fonts. */ |
1ada3dab | 2499 | if (!NILP (exclude_proportional)) |
6fe9826d JR |
2500 | cf.Flags |= CF_FIXEDPITCHONLY; |
2501 | ||
2502 | cf.lpLogFont = &lf; | |
2503 | ||
2504 | /* Initialize as much of the font details as we can from the current | |
2505 | default font. */ | |
2506 | hdc = GetDC (FRAME_W32_WINDOW (f)); | |
c35f9821 | 2507 | oldobj = SelectObject (hdc, FONT_HANDLE (FRAME_FONT (f))); |
6fe9826d JR |
2508 | GetTextFace (hdc, LF_FACESIZE, lf.lfFaceName); |
2509 | if (GetTextMetrics (hdc, &tm)) | |
2510 | { | |
2511 | lf.lfHeight = tm.tmInternalLeading - tm.tmHeight; | |
2512 | lf.lfWeight = tm.tmWeight; | |
2513 | lf.lfItalic = tm.tmItalic; | |
2514 | lf.lfUnderline = tm.tmUnderlined; | |
2515 | lf.lfStrikeOut = tm.tmStruckOut; | |
2516 | lf.lfCharSet = tm.tmCharSet; | |
2517 | cf.Flags |= CF_INITTOLOGFONTSTRUCT; | |
2518 | } | |
2519 | SelectObject (hdc, oldobj); | |
2520 | ReleaseDC (FRAME_W32_WINDOW (f), hdc); | |
2521 | ||
2522 | if (!ChooseFont (&cf) | |
2523 | || logfont_to_fcname (&lf, cf.iPointSize, buf, 100) < 0) | |
2524 | return Qnil; | |
2525 | ||
e6df5336 | 2526 | return DECODE_SYSTEM (build_string (buf)); |
6fe9826d JR |
2527 | } |
2528 | ||
3106121c | 2529 | static const char *const w32font_booleans [] = { |
9fa82824 DP |
2530 | NULL, |
2531 | }; | |
2532 | ||
3106121c | 2533 | static const char *const w32font_non_booleans [] = { |
9fa82824 DP |
2534 | ":script", |
2535 | ":antialias", | |
2536 | ":style", | |
2537 | NULL, | |
2538 | }; | |
2539 | ||
2540 | static void | |
220d91b8 | 2541 | w32font_filter_properties (Lisp_Object font, Lisp_Object alist) |
9fa82824 DP |
2542 | { |
2543 | font_filter_properties (font, alist, w32font_booleans, w32font_non_booleans); | |
2544 | } | |
2545 | ||
f7a84cb4 JR |
2546 | struct font_driver w32font_driver = |
2547 | { | |
8eac0c84 | 2548 | 0, /* Qgdi */ |
5f18d119 | 2549 | 0, /* case insensitive */ |
f7a84cb4 JR |
2550 | w32font_get_cache, |
2551 | w32font_list, | |
2552 | w32font_match, | |
2553 | w32font_list_family, | |
2554 | NULL, /* free_entity */ | |
2555 | w32font_open, | |
2556 | w32font_close, | |
2557 | NULL, /* prepare_face */ | |
2558 | NULL, /* done_face */ | |
2559 | w32font_has_char, | |
2560 | w32font_encode_char, | |
2561 | w32font_text_extents, | |
2562 | w32font_draw, | |
2563 | NULL, /* get_bitmap */ | |
2564 | NULL, /* free_bitmap */ | |
2565 | NULL, /* get_outline */ | |
2566 | NULL, /* free_outline */ | |
2567 | NULL, /* anchor_point */ | |
2568 | NULL, /* otf_capability */ | |
5b0c3446 JR |
2569 | NULL, /* otf_drive */ |
2570 | NULL, /* start_for_frame */ | |
2571 | NULL, /* end_for_frame */ | |
637fa988 JD |
2572 | NULL, /* shape */ |
2573 | NULL, /* check */ | |
2574 | NULL, /* get_variation_glyphs */ | |
9fa82824 | 2575 | w32font_filter_properties, |
9c88f339 | 2576 | NULL, /* cached_font_ok */ |
f7a84cb4 JR |
2577 | }; |
2578 | ||
f7a84cb4 JR |
2579 | |
2580 | /* Initialize state that does not change between invocations. This is only | |
2581 | called when Emacs is dumped. */ | |
20399669 | 2582 | void |
b56ceb92 | 2583 | syms_of_w32font (void) |
f7a84cb4 | 2584 | { |
8eac0c84 | 2585 | DEFSYM (Qgdi, "gdi"); |
34fd2d28 JR |
2586 | DEFSYM (Quniscribe, "uniscribe"); |
2587 | DEFSYM (QCformat, ":format"); | |
d205d43b JR |
2588 | |
2589 | /* Generic font families. */ | |
2590 | DEFSYM (Qmonospace, "monospace"); | |
2591 | DEFSYM (Qserif, "serif"); | |
9e1a2995 | 2592 | DEFSYM (Qsansserif, "sansserif"); |
f7a84cb4 | 2593 | DEFSYM (Qscript, "script"); |
d205d43b JR |
2594 | DEFSYM (Qdecorative, "decorative"); |
2595 | /* Aliases. */ | |
9e1a2995 | 2596 | DEFSYM (Qsans_serif, "sans_serif"); |
d205d43b JR |
2597 | DEFSYM (Qsans, "sans"); |
2598 | DEFSYM (Qmono, "mono"); | |
2599 | ||
2600 | /* Fake foundries. */ | |
2601 | DEFSYM (Qraster, "raster"); | |
2602 | DEFSYM (Qoutline, "outline"); | |
f7a84cb4 | 2603 | DEFSYM (Qunknown, "unknown"); |
d205d43b | 2604 | |
91583281 JR |
2605 | /* Antialiasing. */ |
2606 | DEFSYM (Qstandard, "standard"); | |
2607 | DEFSYM (Qsubpixel, "subpixel"); | |
2608 | DEFSYM (Qnatural, "natural"); | |
d205d43b | 2609 | |
8f112d52 | 2610 | /* Languages */ |
8f112d52 JR |
2611 | DEFSYM (Qzh, "zh"); |
2612 | ||
d205d43b JR |
2613 | /* Scripts */ |
2614 | DEFSYM (Qlatin, "latin"); | |
2615 | DEFSYM (Qgreek, "greek"); | |
2616 | DEFSYM (Qcoptic, "coptic"); | |
2617 | DEFSYM (Qcyrillic, "cyrillic"); | |
2618 | DEFSYM (Qarmenian, "armenian"); | |
2619 | DEFSYM (Qhebrew, "hebrew"); | |
2620 | DEFSYM (Qarabic, "arabic"); | |
2621 | DEFSYM (Qsyriac, "syriac"); | |
2622 | DEFSYM (Qnko, "nko"); | |
2623 | DEFSYM (Qthaana, "thaana"); | |
2624 | DEFSYM (Qdevanagari, "devanagari"); | |
2625 | DEFSYM (Qbengali, "bengali"); | |
2626 | DEFSYM (Qgurmukhi, "gurmukhi"); | |
2627 | DEFSYM (Qgujarati, "gujarati"); | |
2628 | DEFSYM (Qoriya, "oriya"); | |
2629 | DEFSYM (Qtamil, "tamil"); | |
2630 | DEFSYM (Qtelugu, "telugu"); | |
2631 | DEFSYM (Qkannada, "kannada"); | |
2632 | DEFSYM (Qmalayalam, "malayalam"); | |
2633 | DEFSYM (Qsinhala, "sinhala"); | |
2634 | DEFSYM (Qthai, "thai"); | |
2635 | DEFSYM (Qlao, "lao"); | |
2636 | DEFSYM (Qtibetan, "tibetan"); | |
2637 | DEFSYM (Qmyanmar, "myanmar"); | |
2638 | DEFSYM (Qgeorgian, "georgian"); | |
2639 | DEFSYM (Qhangul, "hangul"); | |
2640 | DEFSYM (Qethiopic, "ethiopic"); | |
2641 | DEFSYM (Qcherokee, "cherokee"); | |
2642 | DEFSYM (Qcanadian_aboriginal, "canadian-aboriginal"); | |
2643 | DEFSYM (Qogham, "ogham"); | |
2644 | DEFSYM (Qrunic, "runic"); | |
2645 | DEFSYM (Qkhmer, "khmer"); | |
2646 | DEFSYM (Qmongolian, "mongolian"); | |
2647 | DEFSYM (Qsymbol, "symbol"); | |
2648 | DEFSYM (Qbraille, "braille"); | |
2649 | DEFSYM (Qhan, "han"); | |
2650 | DEFSYM (Qideographic_description, "ideographic-description"); | |
2651 | DEFSYM (Qcjk_misc, "cjk-misc"); | |
2652 | DEFSYM (Qkana, "kana"); | |
2653 | DEFSYM (Qbopomofo, "bopomofo"); | |
2654 | DEFSYM (Qkanbun, "kanbun"); | |
2655 | DEFSYM (Qyi, "yi"); | |
2656 | DEFSYM (Qbyzantine_musical_symbol, "byzantine-musical-symbol"); | |
2657 | DEFSYM (Qmusical_symbol, "musical-symbol"); | |
2658 | DEFSYM (Qmathematical, "mathematical"); | |
174f1c74 | 2659 | DEFSYM (Qcham, "cham"); |
56df6710 JR |
2660 | DEFSYM (Qphonetic, "phonetic"); |
2661 | DEFSYM (Qbalinese, "balinese"); | |
2662 | DEFSYM (Qbuginese, "buginese"); | |
2663 | DEFSYM (Qbuhid, "buhid"); | |
2664 | DEFSYM (Qcuneiform, "cuneiform"); | |
2665 | DEFSYM (Qcypriot, "cypriot"); | |
2666 | DEFSYM (Qdeseret, "deseret"); | |
2667 | DEFSYM (Qglagolitic, "glagolitic"); | |
2668 | DEFSYM (Qgothic, "gothic"); | |
2669 | DEFSYM (Qhanunoo, "hanunoo"); | |
2670 | DEFSYM (Qkharoshthi, "kharoshthi"); | |
2671 | DEFSYM (Qlimbu, "limbu"); | |
2672 | DEFSYM (Qlinear_b, "linear_b"); | |
2673 | DEFSYM (Qold_italic, "old_italic"); | |
2674 | DEFSYM (Qold_persian, "old_persian"); | |
2675 | DEFSYM (Qosmanya, "osmanya"); | |
2676 | DEFSYM (Qphags_pa, "phags-pa"); | |
2677 | DEFSYM (Qphoenician, "phoenician"); | |
2678 | DEFSYM (Qshavian, "shavian"); | |
2679 | DEFSYM (Qsyloti_nagri, "syloti_nagri"); | |
2680 | DEFSYM (Qtagalog, "tagalog"); | |
2681 | DEFSYM (Qtagbanwa, "tagbanwa"); | |
2682 | DEFSYM (Qtai_le, "tai_le"); | |
2683 | DEFSYM (Qtifinagh, "tifinagh"); | |
2684 | DEFSYM (Qugaritic, "ugaritic"); | |
d205d43b | 2685 | |
57016d37 JR |
2686 | /* W32 font encodings. */ |
2687 | DEFVAR_LISP ("w32-charset-info-alist", | |
29208e82 | 2688 | Vw32_charset_info_alist, |
57016d37 JR |
2689 | doc: /* Alist linking Emacs character sets to Windows fonts and codepages. |
2690 | Each entry should be of the form: | |
2691 | ||
2692 | (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)) | |
2693 | ||
2694 | where CHARSET_NAME is a string used in font names to identify the charset, | |
2695 | WINDOWS_CHARSET is a symbol that can be one of: | |
2696 | ||
2697 | w32-charset-ansi, w32-charset-default, w32-charset-symbol, | |
2698 | w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312, | |
2699 | w32-charset-chinesebig5, w32-charset-johab, w32-charset-hebrew, | |
2700 | w32-charset-arabic, w32-charset-greek, w32-charset-turkish, | |
2701 | w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope, | |
2702 | w32-charset-russian, w32-charset-mac, w32-charset-baltic, | |
2703 | or w32-charset-oem. | |
2704 | ||
2705 | CODEPAGE should be an integer specifying the codepage that should be used | |
2706 | to display the character set, t to do no translation and output as Unicode, | |
2707 | or nil to do no translation and output as 8 bit (or multibyte on far-east | |
2708 | versions of Windows) characters. */); | |
2709 | Vw32_charset_info_alist = Qnil; | |
2710 | ||
2711 | DEFSYM (Qw32_charset_ansi, "w32-charset-ansi"); | |
2712 | DEFSYM (Qw32_charset_symbol, "w32-charset-symbol"); | |
2713 | DEFSYM (Qw32_charset_default, "w32-charset-default"); | |
2714 | DEFSYM (Qw32_charset_shiftjis, "w32-charset-shiftjis"); | |
2715 | DEFSYM (Qw32_charset_hangeul, "w32-charset-hangeul"); | |
2716 | DEFSYM (Qw32_charset_chinesebig5, "w32-charset-chinesebig5"); | |
2717 | DEFSYM (Qw32_charset_gb2312, "w32-charset-gb2312"); | |
2718 | DEFSYM (Qw32_charset_oem, "w32-charset-oem"); | |
2719 | DEFSYM (Qw32_charset_johab, "w32-charset-johab"); | |
2720 | DEFSYM (Qw32_charset_easteurope, "w32-charset-easteurope"); | |
2721 | DEFSYM (Qw32_charset_turkish, "w32-charset-turkish"); | |
2722 | DEFSYM (Qw32_charset_baltic, "w32-charset-baltic"); | |
2723 | DEFSYM (Qw32_charset_russian, "w32-charset-russian"); | |
2724 | DEFSYM (Qw32_charset_arabic, "w32-charset-arabic"); | |
2725 | DEFSYM (Qw32_charset_greek, "w32-charset-greek"); | |
2726 | DEFSYM (Qw32_charset_hebrew, "w32-charset-hebrew"); | |
2727 | DEFSYM (Qw32_charset_vietnamese, "w32-charset-vietnamese"); | |
2728 | DEFSYM (Qw32_charset_thai, "w32-charset-thai"); | |
2729 | DEFSYM (Qw32_charset_mac, "w32-charset-mac"); | |
2730 | ||
6fe9826d JR |
2731 | defsubr (&Sx_select_font); |
2732 | ||
8eac0c84 | 2733 | w32font_driver.type = Qgdi; |
f7a84cb4 JR |
2734 | register_font_driver (&w32font_driver, NULL); |
2735 | } | |
db4f02f2 EZ |
2736 | |
2737 | void | |
2738 | globals_of_w32font (void) | |
2739 | { | |
2740 | g_b_init_is_w9x = 0; | |
2741 | g_b_init_get_outline_metrics_w = 0; | |
2742 | g_b_init_get_text_metrics_w = 0; | |
2743 | g_b_init_get_glyph_outline_w = 0; | |
2744 | } |