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