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