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