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