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