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