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