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/>. */
28 #include "dispextern.h"
29 #include "character.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
43 #ifndef CLEARTYPE_NATURAL_QUALITY
44 #define CLEARTYPE_NATURAL_QUALITY 6
47 /* VIETNAMESE_CHARSET and JOHAB_CHARSET are not defined in some versions
49 #ifndef VIETNAMESE_CHARSET
50 #define VIETNAMESE_CHARSET 163
53 #define JOHAB_CHARSET 130
56 extern struct font_driver w32font_driver
;
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
;
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
;
71 static Lisp_Object Qzh
;
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
*));
118 static Lisp_Object w32_registry
P_ ((LONG
, DWORD
));
120 /* EnumFontFamiliesEx callbacks. */
121 static int CALLBACK add_font_entity_to_list
P_ ((ENUMLOGFONTEX
*,
124 static int CALLBACK add_one_font_entity_to_list
P_ ((ENUMLOGFONTEX
*,
127 static int CALLBACK add_font_name_to_list
P_ ((ENUMLOGFONTEX
*,
131 /* struct passed in as LPARAM arg to EnumFontFamiliesEx, for keeping track
132 of what we really want. */
133 struct font_callback_data
135 /* The logfont we are matching against. EnumFontFamiliesEx only matches
136 face name and charset, so we need to manually match everything else
137 in the callback function. */
139 /* The original font spec or entity. */
140 Lisp_Object orig_font_spec
;
141 /* The frame the font is being loaded on. */
143 /* The list to add matches to. */
145 /* Whether to match only opentype fonts. */
149 /* Handles the problem that EnumFontFamiliesEx will not return all
150 style variations if the font name is not specified. */
151 static void list_all_matching_fonts
P_ ((struct font_callback_data
*));
155 memq_no_quit (elt
, list
)
156 Lisp_Object elt
, list
;
158 while (CONSP (list
) && ! EQ (XCAR (list
), elt
))
160 return (CONSP (list
));
164 intern_font_name (string
)
167 Lisp_Object obarray
, tem
, str
;
170 str
= DECODE_SYSTEM (build_string (string
));
173 /* The following code is copied from the function intern (in lread.c). */
175 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
176 obarray
= check_obarray (obarray
);
177 tem
= oblookup (obarray
, SDATA (str
), len
, len
);
180 return Fintern (str
, obarray
);
183 /* w32 implementation of get_cache for font backend.
184 Return a cache of font-entities on FRAME. The cache must be a
185 cons whose cdr part is the actual cache area. */
187 w32font_get_cache (f
)
190 struct w32_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
192 return (dpyinfo
->name_list_element
);
195 /* w32 implementation of list for font backend.
196 List fonts exactly matching with FONT_SPEC on FRAME. The value
197 is a vector of font-entities. This is the sole API that
198 allocates font-entities. */
200 w32font_list (frame
, font_spec
)
201 Lisp_Object frame
, font_spec
;
203 Lisp_Object fonts
= w32font_list_internal (frame
, font_spec
, 0);
204 FONT_ADD_LOG ("w32font-list", font_spec
, fonts
);
208 /* w32 implementation of match for font backend.
209 Return a font entity most closely matching with FONT_SPEC on
210 FRAME. The closeness is detemined by the font backend, thus
211 `face-font-selection-order' is ignored here. */
213 w32font_match (frame
, font_spec
)
214 Lisp_Object frame
, font_spec
;
216 Lisp_Object entity
= w32font_match_internal (frame
, font_spec
, 0);
217 FONT_ADD_LOG ("w32font-match", font_spec
, entity
);
221 /* w32 implementation of list_family for font backend.
222 List available families. The value is a list of family names
225 w32font_list_family (frame
)
228 Lisp_Object list
= Qnil
;
229 LOGFONT font_match_pattern
;
231 FRAME_PTR f
= XFRAME (frame
);
233 bzero (&font_match_pattern
, sizeof (font_match_pattern
));
234 font_match_pattern
.lfCharSet
= DEFAULT_CHARSET
;
236 dc
= get_frame_dc (f
);
238 EnumFontFamiliesEx (dc
, &font_match_pattern
,
239 (FONTENUMPROC
) add_font_name_to_list
,
241 release_frame_dc (f
, dc
);
246 /* w32 implementation of open for font backend.
247 Open a font specified by FONT_ENTITY on frame F.
248 If the font is scalable, open it with PIXEL_SIZE. */
250 w32font_open (f
, font_entity
, pixel_size
)
252 Lisp_Object font_entity
;
255 Lisp_Object font_object
256 = font_make_object (VECSIZE (struct w32font_info
),
257 font_entity
, pixel_size
);
258 struct w32font_info
*w32_font
259 = (struct w32font_info
*) XFONT_OBJECT (font_object
);
261 ASET (font_object
, FONT_TYPE_INDEX
, Qgdi
);
263 if (!w32font_open_internal (f
, font_entity
, pixel_size
, font_object
))
268 /* GDI backend does not use glyph indices. */
269 w32_font
->glyph_idx
= 0;
274 /* w32 implementation of close for font_backend.
275 Close FONT on frame F. */
277 w32font_close (f
, font
)
282 struct w32font_info
*w32_font
= (struct w32font_info
*) font
;
284 /* Delete the GDI font object. */
285 DeleteObject (w32_font
->hfont
);
287 /* Free all the cached metrics. */
288 if (w32_font
->cached_metrics
)
290 for (i
= 0; i
< w32_font
->n_cache_blocks
; i
++)
292 xfree (w32_font
->cached_metrics
[i
]);
294 xfree (w32_font
->cached_metrics
);
295 w32_font
->cached_metrics
= NULL
;
299 /* w32 implementation of has_char for font backend.
301 If FONT_ENTITY has a glyph for character C (Unicode code point),
302 return 1. If not, return 0. If a font must be opened to check
305 w32font_has_char (entity
, c
)
309 /* We can't be certain about which characters a font will support until
310 we open it. Checking the scripts that the font supports turns out
311 to not be reliable. */
315 Lisp_Object supported_scripts
, extra
, script
;
318 extra
= AREF (entity
, FONT_EXTRA_INDEX
);
322 supported_scripts
= assq_no_quit (QCscript
, extra
);
323 /* If font doesn't claim to support any scripts, then we can't be certain
325 if (!CONSP (supported_scripts
))
328 supported_scripts
= XCDR (supported_scripts
);
330 script
= CHAR_TABLE_REF (Vchar_script_table
, c
);
332 /* If we don't know what script the character is from, then we can't be
333 certain until we open it. Also if the font claims support for the script
334 the character is from, it may only have partial coverage, so we still
335 can't be certain until we open the font. */
336 if (NILP (script
) || memq_no_quit (script
, supported_scripts
))
339 /* Font reports what scripts it supports, and none of them are the script
340 the character is from. But we still can't be certain, as some fonts
341 will contain some/most/all of the characters in that script without
342 claiming support for it. */
347 /* w32 implementation of encode_char for font backend.
348 Return a glyph code of FONT for characer C (Unicode code point).
349 If FONT doesn't have such a glyph, return FONT_INVALID_CODE.
351 For speed, the gdi backend uses unicode (Emacs calls encode_char
352 far too often for it to be efficient). But we still need to detect
353 which characters are not supported by the font.
356 w32font_encode_char (font
, c
)
360 struct w32font_info
* w32_font
= (struct w32font_info
*)font
;
362 if (c
< w32_font
->metrics
.tmFirstChar
363 || c
> w32_font
->metrics
.tmLastChar
)
364 return FONT_INVALID_CODE
;
369 /* w32 implementation of text_extents for font backend.
370 Perform the size computation of glyphs of FONT and fillin members
371 of METRICS. The glyphs are specified by their glyph codes in
372 CODE (length NGLYPHS). Apparently metrics can be NULL, in this
373 case just return the overall width. */
375 w32font_text_extents (font
, code
, nglyphs
, metrics
)
379 struct font_metrics
*metrics
;
382 HFONT old_font
= NULL
;
389 struct w32font_info
*w32_font
= (struct w32font_info
*) font
;
393 bzero (metrics
, sizeof (struct font_metrics
));
394 metrics
->ascent
= font
->ascent
;
395 metrics
->descent
= font
->descent
;
397 for (i
= 0; i
< nglyphs
; i
++)
399 struct w32_metric_cache
*char_metric
;
400 int block
= *(code
+ i
) / CACHE_BLOCKSIZE
;
401 int pos_in_block
= *(code
+ i
) % CACHE_BLOCKSIZE
;
403 if (block
>= w32_font
->n_cache_blocks
)
405 if (!w32_font
->cached_metrics
)
406 w32_font
->cached_metrics
407 = xmalloc ((block
+ 1)
408 * sizeof (struct w32_metric_cache
*));
410 w32_font
->cached_metrics
411 = xrealloc (w32_font
->cached_metrics
,
413 * sizeof (struct w32_metric_cache
*));
414 bzero (w32_font
->cached_metrics
+ w32_font
->n_cache_blocks
,
415 ((block
+ 1 - w32_font
->n_cache_blocks
)
416 * sizeof (struct w32_metric_cache
*)));
417 w32_font
->n_cache_blocks
= block
+ 1;
420 if (!w32_font
->cached_metrics
[block
])
422 w32_font
->cached_metrics
[block
]
423 = xmalloc (CACHE_BLOCKSIZE
* sizeof (struct w32_metric_cache
));
424 bzero (w32_font
->cached_metrics
[block
],
425 CACHE_BLOCKSIZE
* sizeof (struct w32_metric_cache
));
428 char_metric
= w32_font
->cached_metrics
[block
] + pos_in_block
;
430 if (char_metric
->status
== W32METRIC_NO_ATTEMPT
)
434 /* TODO: Frames can come and go, and their fonts
435 outlive them. So we can't cache the frame in the
436 font structure. Use selected_frame until the API
437 is updated to pass in a frame. */
438 f
= XFRAME (selected_frame
);
440 dc
= get_frame_dc (f
);
441 old_font
= SelectObject (dc
, w32_font
->hfont
);
443 compute_metrics (dc
, w32_font
, *(code
+ i
), char_metric
);
446 if (char_metric
->status
== W32METRIC_SUCCESS
)
448 metrics
->lbearing
= min (metrics
->lbearing
,
449 metrics
->width
+ char_metric
->lbearing
);
450 metrics
->rbearing
= max (metrics
->rbearing
,
451 metrics
->width
+ char_metric
->rbearing
);
452 metrics
->width
+= char_metric
->width
;
455 /* If we couldn't get metrics for a char,
456 use alternative method. */
459 /* If we got through everything, return. */
464 /* Restore state and release DC. */
465 SelectObject (dc
, old_font
);
466 release_frame_dc (f
, dc
);
469 return metrics
->width
;
473 /* For non-truetype fonts, GetGlyphOutlineW is not supported, so
474 fallback on other methods that will at least give some of the metric
477 /* Make array big enough to hold surrogates. */
478 wcode
= alloca (nglyphs
* sizeof (WORD
) * 2);
479 for (i
= 0; i
< nglyphs
; i
++)
481 if (code
[i
] < 0x10000)
485 DWORD surrogate
= code
[i
] - 0x10000;
487 /* High surrogate: U+D800 - U+DBFF. */
488 wcode
[i
++] = 0xD800 + ((surrogate
>> 10) & 0x03FF);
489 /* Low surrogate: U+DC00 - U+DFFF. */
490 wcode
[i
] = 0xDC00 + (surrogate
& 0x03FF);
491 /* An extra glyph. wcode is already double the size of code to
499 /* TODO: Frames can come and go, and their fonts outlive
500 them. So we can't cache the frame in the font structure. Use
501 selected_frame until the API is updated to pass in a
503 f
= XFRAME (selected_frame
);
505 dc
= get_frame_dc (f
);
506 old_font
= SelectObject (dc
, w32_font
->hfont
);
509 if (GetTextExtentPoint32W (dc
, wcode
, nglyphs
, &size
))
511 total_width
= size
.cx
;
514 /* On 95/98/ME, only some unicode functions are available, so fallback
515 on doing a dummy draw to find the total width. */
519 rect
.top
= 0; rect
.bottom
= font
->height
; rect
.left
= 0; rect
.right
= 1;
520 DrawTextW (dc
, wcode
, nglyphs
, &rect
,
521 DT_CALCRECT
| DT_NOPREFIX
| DT_SINGLELINE
);
522 total_width
= rect
.right
;
525 /* Give our best estimate of the metrics, based on what we know. */
528 metrics
->width
= total_width
- w32_font
->metrics
.tmOverhang
;
529 metrics
->lbearing
= 0;
530 metrics
->rbearing
= total_width
;
533 /* Restore state and release DC. */
534 SelectObject (dc
, old_font
);
535 release_frame_dc (f
, dc
);
540 /* w32 implementation of draw for font backend.
542 Draw glyphs between FROM and TO of S->char2b at (X Y) pixel
543 position of frame F with S->FACE and S->GC. If WITH_BACKGROUND
544 is nonzero, fill the background in advance. It is assured that
545 WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars).
547 TODO: Currently this assumes that the colors and fonts are already
548 set in the DC. This seems to be true now, but maybe only due to
549 the old font code setting it up. It may be safer to resolve faces
550 and fonts in here and set them explicitly
554 w32font_draw (s
, from
, to
, x
, y
, with_background
)
555 struct glyph_string
*s
;
556 int from
, to
, x
, y
, with_background
;
559 HRGN orig_clip
= NULL
;
560 struct w32font_info
*w32font
= (struct w32font_info
*) s
->font
;
562 options
= w32font
->glyph_idx
;
564 if (s
->num_clips
> 0)
566 HRGN new_clip
= CreateRectRgnIndirect (s
->clip
);
568 /* Save clip region for later restoration. */
569 orig_clip
= CreateRectRgn (0, 0, 0, 0);
570 if (!GetClipRgn(s
->hdc
, orig_clip
))
572 DeleteObject (orig_clip
);
576 if (s
->num_clips
> 1)
578 HRGN clip2
= CreateRectRgnIndirect (s
->clip
+ 1);
580 CombineRgn (new_clip
, new_clip
, clip2
, RGN_OR
);
581 DeleteObject (clip2
);
584 SelectClipRgn (s
->hdc
, new_clip
);
585 DeleteObject (new_clip
);
588 /* Using OPAQUE background mode can clear more background than expected
589 when Cleartype is used. Draw the background manually to avoid this. */
590 SetBkMode (s
->hdc
, TRANSPARENT
);
595 struct font
*font
= s
->font
;
597 brush
= CreateSolidBrush (s
->gc
->background
);
599 rect
.top
= y
- font
->ascent
;
600 rect
.right
= x
+ s
->width
;
601 rect
.bottom
= y
+ font
->descent
;
602 FillRect (s
->hdc
, &rect
, brush
);
603 DeleteObject (brush
);
608 int len
= to
- from
, i
;
610 for (i
= 0; i
< len
; i
++)
611 ExtTextOutW (s
->hdc
, x
+ i
, y
, options
, NULL
,
612 s
->char2b
+ from
+ i
, 1, NULL
);
615 ExtTextOutW (s
->hdc
, x
, y
, options
, NULL
, s
->char2b
+ from
, to
- from
, NULL
);
617 /* Restore clip region. */
618 if (s
->num_clips
> 0)
619 SelectClipRgn (s
->hdc
, orig_clip
);
622 DeleteObject (orig_clip
);
625 /* w32 implementation of free_entity for font backend.
626 Optional (if FONT_EXTRA_INDEX is not Lisp_Save_Value).
627 Free FONT_EXTRA_INDEX field of FONT_ENTITY.
629 w32font_free_entity (Lisp_Object entity);
632 /* w32 implementation of prepare_face for font backend.
633 Optional (if FACE->extra is not used).
634 Prepare FACE for displaying characters by FONT on frame F by
635 storing some data in FACE->extra. If successful, return 0.
636 Otherwise, return -1.
638 w32font_prepare_face (FRAME_PTR f, struct face *face);
640 /* w32 implementation of done_face for font backend.
642 Done FACE for displaying characters by FACE->font on frame F.
644 w32font_done_face (FRAME_PTR f, struct face *face); */
646 /* w32 implementation of get_bitmap for font backend.
648 Store bitmap data for glyph-code CODE of FONT in BITMAP. It is
649 intended that this method is called from the other font-driver
652 w32font_get_bitmap (struct font *font, unsigned code,
653 struct font_bitmap *bitmap, int bits_per_pixel);
655 /* w32 implementation of free_bitmap for font backend.
657 Free bitmap data in BITMAP.
659 w32font_free_bitmap (struct font *font, struct font_bitmap *bitmap);
661 /* w32 implementation of get_outline for font backend.
663 Return an outline data for glyph-code CODE of FONT. The format
664 of the outline data depends on the font-driver.
666 w32font_get_outline (struct font *font, unsigned code);
668 /* w32 implementation of free_outline for font backend.
670 Free OUTLINE (that is obtained by the above method).
672 w32font_free_outline (struct font *font, void *outline);
674 /* w32 implementation of anchor_point for font backend.
676 Get coordinates of the INDEXth anchor point of the glyph whose
677 code is CODE. Store the coordinates in *X and *Y. Return 0 if
678 the operations was successfull. Otherwise return -1.
680 w32font_anchor_point (struct font *font, unsigned code,
681 int index, int *x, int *y);
683 /* w32 implementation of otf_capability for font backend.
685 Return a list describing which scripts/languages FONT
686 supports by which GSUB/GPOS features of OpenType tables.
688 w32font_otf_capability (struct font *font);
690 /* w32 implementation of otf_drive for font backend.
692 Apply FONT's OTF-FEATURES to the glyph string.
694 FEATURES specifies which OTF features to apply in this format:
695 (SCRIPT LANGSYS GSUB-FEATURE GPOS-FEATURE)
696 See the documentation of `font-drive-otf' for the detail.
698 This method applies the specified features to the codes in the
699 elements of GSTRING-IN (between FROMth and TOth). The output
700 codes are stored in GSTRING-OUT at the IDXth element and the
703 Return the number of output codes. If none of the features are
704 applicable to the input data, return 0. If GSTRING-OUT is too
707 w32font_otf_drive (struct font *font, Lisp_Object features,
708 Lisp_Object gstring_in, int from, int to,
709 Lisp_Object gstring_out, int idx,
710 int alternate_subst);
713 /* Internal implementation of w32font_list.
714 Additional parameter opentype_only restricts the returned fonts to
715 opentype fonts, which can be used with the Uniscribe backend. */
717 w32font_list_internal (frame
, font_spec
, opentype_only
)
718 Lisp_Object frame
, font_spec
;
721 struct font_callback_data match_data
;
723 FRAME_PTR f
= XFRAME (frame
);
725 match_data
.orig_font_spec
= font_spec
;
726 match_data
.list
= Qnil
;
727 match_data
.frame
= frame
;
729 bzero (&match_data
.pattern
, sizeof (LOGFONT
));
730 fill_in_logfont (f
, &match_data
.pattern
, font_spec
);
732 /* If the charset is unrecognized, then we won't find a font, so don't
733 waste time looking for one. */
734 if (match_data
.pattern
.lfCharSet
== DEFAULT_CHARSET
)
736 Lisp_Object spec_charset
= AREF (font_spec
, FONT_REGISTRY_INDEX
);
737 if (!NILP (spec_charset
)
738 && !EQ (spec_charset
, Qiso10646_1
)
739 && !EQ (spec_charset
, Qunicode_bmp
)
740 && !EQ (spec_charset
, Qunicode_sip
)
741 && !EQ (spec_charset
, Qunknown
))
745 match_data
.opentype_only
= opentype_only
;
747 match_data
.pattern
.lfOutPrecision
= OUT_OUTLINE_PRECIS
;
749 if (match_data
.pattern
.lfFaceName
[0] == '\0')
751 /* EnumFontFamiliesEx does not take other fields into account if
752 font name is blank, so need to use two passes. */
753 list_all_matching_fonts (&match_data
);
757 dc
= get_frame_dc (f
);
759 EnumFontFamiliesEx (dc
, &match_data
.pattern
,
760 (FONTENUMPROC
) add_font_entity_to_list
,
761 (LPARAM
) &match_data
, 0);
762 release_frame_dc (f
, dc
);
765 return match_data
.list
;
768 /* Internal implementation of w32font_match.
769 Additional parameter opentype_only restricts the returned fonts to
770 opentype fonts, which can be used with the Uniscribe backend. */
772 w32font_match_internal (frame
, font_spec
, opentype_only
)
773 Lisp_Object frame
, font_spec
;
776 struct font_callback_data match_data
;
778 FRAME_PTR f
= XFRAME (frame
);
780 match_data
.orig_font_spec
= font_spec
;
781 match_data
.frame
= frame
;
782 match_data
.list
= Qnil
;
784 bzero (&match_data
.pattern
, sizeof (LOGFONT
));
785 fill_in_logfont (f
, &match_data
.pattern
, font_spec
);
787 match_data
.opentype_only
= opentype_only
;
789 match_data
.pattern
.lfOutPrecision
= OUT_OUTLINE_PRECIS
;
791 dc
= get_frame_dc (f
);
793 EnumFontFamiliesEx (dc
, &match_data
.pattern
,
794 (FONTENUMPROC
) add_one_font_entity_to_list
,
795 (LPARAM
) &match_data
, 0);
796 release_frame_dc (f
, dc
);
798 return NILP (match_data
.list
) ? Qnil
: XCAR (match_data
.list
);
802 w32font_open_internal (f
, font_entity
, pixel_size
, font_object
)
804 Lisp_Object font_entity
;
806 Lisp_Object font_object
;
811 HFONT hfont
, old_font
;
812 Lisp_Object val
, extra
;
813 struct w32font_info
*w32_font
;
815 OUTLINETEXTMETRICW
* metrics
= NULL
;
817 w32_font
= (struct w32font_info
*) XFONT_OBJECT (font_object
);
818 font
= (struct font
*) w32_font
;
823 bzero (&logfont
, sizeof (logfont
));
824 fill_in_logfont (f
, &logfont
, font_entity
);
826 /* Prefer truetype fonts, to avoid known problems with type1 fonts, and
827 limitations in bitmap fonts. */
828 val
= AREF (font_entity
, FONT_FOUNDRY_INDEX
);
829 if (!EQ (val
, Qraster
))
830 logfont
.lfOutPrecision
= OUT_TT_PRECIS
;
832 size
= XINT (AREF (font_entity
, FONT_SIZE_INDEX
));
836 logfont
.lfHeight
= -size
;
837 hfont
= CreateFontIndirect (&logfont
);
842 /* Get the metrics for this font. */
843 dc
= get_frame_dc (f
);
844 old_font
= SelectObject (dc
, hfont
);
846 /* Try getting the outline metrics (only works for truetype fonts). */
847 len
= GetOutlineTextMetricsW (dc
, 0, NULL
);
850 metrics
= (OUTLINETEXTMETRICW
*) alloca (len
);
851 if (GetOutlineTextMetricsW (dc
, len
, metrics
))
852 bcopy (&metrics
->otmTextMetrics
, &w32_font
->metrics
,
853 sizeof (TEXTMETRICW
));
859 GetTextMetricsW (dc
, &w32_font
->metrics
);
861 w32_font
->cached_metrics
= NULL
;
862 w32_font
->n_cache_blocks
= 0;
864 SelectObject (dc
, old_font
);
865 release_frame_dc (f
, dc
);
867 w32_font
->hfont
= hfont
;
872 /* We don't know how much space we need for the full name, so start with
873 96 bytes and go up in steps of 32. */
876 while (name
&& w32font_full_name (&logfont
, font_entity
, pixel_size
,
883 font
->props
[FONT_FULLNAME_INDEX
]
884 = DECODE_SYSTEM (build_string (name
));
886 font
->props
[FONT_FULLNAME_INDEX
]
887 = DECODE_SYSTEM (build_string (logfont
.lfFaceName
));
890 font
->max_width
= w32_font
->metrics
.tmMaxCharWidth
;
891 /* Parts of Emacs display assume that height = ascent + descent...
892 so height is defined later, after ascent and descent.
893 font->height = w32_font->metrics.tmHeight
894 + w32_font->metrics.tmExternalLeading;
897 font
->space_width
= font
->average_width
= w32_font
->metrics
.tmAveCharWidth
;
899 font
->vertical_centering
= 0;
900 font
->encoding_type
= 0;
901 font
->baseline_offset
= 0;
902 font
->relative_compose
= 0;
903 font
->default_ascent
= w32_font
->metrics
.tmAscent
;
904 font
->font_encoder
= NULL
;
905 font
->pixel_size
= size
;
906 font
->driver
= &w32font_driver
;
907 /* Use format cached during list, as the information we have access to
908 here is incomplete. */
909 extra
= AREF (font_entity
, FONT_EXTRA_INDEX
);
912 val
= assq_no_quit (QCformat
, extra
);
914 font
->props
[FONT_FORMAT_INDEX
] = XCDR (val
);
916 font
->props
[FONT_FORMAT_INDEX
] = Qunknown
;
919 font
->props
[FONT_FORMAT_INDEX
] = Qunknown
;
921 font
->props
[FONT_FILE_INDEX
] = Qnil
;
922 font
->encoding_charset
= -1;
923 font
->repertory_charset
= -1;
924 /* TODO: do we really want the minimum width here, which could be negative? */
925 font
->min_width
= font
->space_width
;
926 font
->ascent
= w32_font
->metrics
.tmAscent
;
927 font
->descent
= w32_font
->metrics
.tmDescent
;
928 font
->height
= font
->ascent
+ font
->descent
;
932 font
->underline_thickness
= metrics
->otmsUnderscoreSize
;
933 font
->underline_position
= -metrics
->otmsUnderscorePosition
;
937 font
->underline_thickness
= 0;
938 font
->underline_position
= -1;
941 /* For temporary compatibility with legacy code that expects the
942 name to be usable in x-list-fonts. Eventually we expect to change
943 x-list-fonts and other places that use fonts so that this can be
944 an fcname or similar. */
945 font
->props
[FONT_NAME_INDEX
] = Ffont_xlfd_name (font_object
, Qnil
);
950 /* Callback function for EnumFontFamiliesEx.
951 * Adds the name of a font to a Lisp list (passed in as the lParam arg). */
953 add_font_name_to_list (logical_font
, physical_font
, font_type
, list_object
)
954 ENUMLOGFONTEX
*logical_font
;
955 NEWTEXTMETRICEX
*physical_font
;
959 Lisp_Object
* list
= (Lisp_Object
*) list_object
;
962 /* Skip vertical fonts (intended only for printing) */
963 if (logical_font
->elfLogFont
.lfFaceName
[0] == '@')
966 family
= intern_font_name (logical_font
->elfLogFont
.lfFaceName
);
967 if (! memq_no_quit (family
, *list
))
968 *list
= Fcons (family
, *list
);
973 static int w32_decode_weight
P_ ((int));
974 static int w32_encode_weight
P_ ((int));
976 /* Convert an enumerated Windows font to an Emacs font entity. */
978 w32_enumfont_pattern_entity (frame
, logical_font
, physical_font
,
979 font_type
, requested_font
, backend
)
981 ENUMLOGFONTEX
*logical_font
;
982 NEWTEXTMETRICEX
*physical_font
;
984 LOGFONT
*requested_font
;
987 Lisp_Object entity
, tem
;
988 LOGFONT
*lf
= (LOGFONT
*) logical_font
;
990 DWORD full_type
= physical_font
->ntmTm
.ntmFlags
;
992 entity
= font_make_entity ();
994 ASET (entity
, FONT_TYPE_INDEX
, backend
);
995 ASET (entity
, FONT_REGISTRY_INDEX
, w32_registry (lf
->lfCharSet
, font_type
));
996 ASET (entity
, FONT_OBJLIST_INDEX
, Qnil
);
998 /* Foundry is difficult to get in readable form on Windows.
999 But Emacs crashes if it is not set, so set it to something more
1000 generic. These values make xlfds compatible with Emacs 22. */
1001 if (lf
->lfOutPrecision
== OUT_STRING_PRECIS
)
1003 else if (lf
->lfOutPrecision
== OUT_STROKE_PRECIS
)
1008 ASET (entity
, FONT_FOUNDRY_INDEX
, tem
);
1010 /* Save the generic family in the extra info, as it is likely to be
1011 useful to users looking for a close match. */
1012 generic_type
= physical_font
->ntmTm
.tmPitchAndFamily
& 0xF0;
1013 if (generic_type
== FF_DECORATIVE
)
1015 else if (generic_type
== FF_MODERN
)
1017 else if (generic_type
== FF_ROMAN
)
1019 else if (generic_type
== FF_SCRIPT
)
1021 else if (generic_type
== FF_SWISS
)
1026 ASET (entity
, FONT_ADSTYLE_INDEX
, tem
);
1028 if (physical_font
->ntmTm
.tmPitchAndFamily
& 0x01)
1029 ASET (entity
, FONT_SPACING_INDEX
, make_number (FONT_SPACING_PROPORTIONAL
));
1031 ASET (entity
, FONT_SPACING_INDEX
, make_number (FONT_SPACING_CHARCELL
));
1033 if (requested_font
->lfQuality
!= DEFAULT_QUALITY
)
1035 font_put_extra (entity
, QCantialias
,
1036 lispy_antialias_type (requested_font
->lfQuality
));
1038 ASET (entity
, FONT_FAMILY_INDEX
,
1039 intern_font_name (lf
->lfFaceName
));
1041 FONT_SET_STYLE (entity
, FONT_WEIGHT_INDEX
,
1042 make_number (w32_decode_weight (lf
->lfWeight
)));
1043 FONT_SET_STYLE (entity
, FONT_SLANT_INDEX
,
1044 make_number (lf
->lfItalic
? 200 : 100));
1045 /* TODO: PANOSE struct has this info, but need to call GetOutlineTextMetrics
1047 FONT_SET_STYLE (entity
, FONT_WIDTH_INDEX
, make_number (100));
1049 if (font_type
& RASTER_FONTTYPE
)
1050 ASET (entity
, FONT_SIZE_INDEX
,
1051 make_number (physical_font
->ntmTm
.tmHeight
1052 + physical_font
->ntmTm
.tmExternalLeading
));
1054 ASET (entity
, FONT_SIZE_INDEX
, make_number (0));
1056 /* Cache unicode codepoints covered by this font, as there is no other way
1057 of getting this information easily. */
1058 if (font_type
& TRUETYPE_FONTTYPE
)
1060 tem
= font_supported_scripts (&physical_font
->ntmFontSig
);
1062 font_put_extra (entity
, QCscript
, tem
);
1065 /* This information is not fully available when opening fonts, so
1066 save it here. Only Windows 2000 and later return information
1067 about opentype and type1 fonts, so need a fallback for detecting
1068 truetype so that this information is not any worse than we could
1069 have obtained later. */
1070 if (EQ (backend
, Quniscribe
) && (full_type
& NTMFLAGS_OPENTYPE
))
1071 tem
= intern ("opentype");
1072 else if (font_type
& TRUETYPE_FONTTYPE
)
1073 tem
= intern ("truetype");
1074 else if (full_type
& NTM_PS_OPENTYPE
)
1075 tem
= intern ("postscript");
1076 else if (full_type
& NTM_TYPE1
)
1077 tem
= intern ("type1");
1078 else if (font_type
& RASTER_FONTTYPE
)
1079 tem
= intern ("w32bitmap");
1081 tem
= intern ("w32vector");
1083 font_put_extra (entity
, QCformat
, tem
);
1089 /* Convert generic families to the family portion of lfPitchAndFamily. */
1091 w32_generic_family (Lisp_Object name
)
1093 /* Generic families. */
1094 if (EQ (name
, Qmonospace
) || EQ (name
, Qmono
))
1096 else if (EQ (name
, Qsans
) || EQ (name
, Qsans_serif
) || EQ (name
, Qsansserif
))
1098 else if (EQ (name
, Qserif
))
1100 else if (EQ (name
, Qdecorative
))
1101 return FF_DECORATIVE
;
1102 else if (EQ (name
, Qscript
))
1109 logfonts_match (font
, pattern
)
1110 LOGFONT
*font
, *pattern
;
1112 /* Only check height for raster fonts. */
1113 if (pattern
->lfHeight
&& font
->lfOutPrecision
== OUT_STRING_PRECIS
1114 && font
->lfHeight
!= pattern
->lfHeight
)
1117 /* Have some flexibility with weights. */
1118 if (pattern
->lfWeight
1119 && ((font
->lfWeight
< (pattern
->lfWeight
- 150))
1120 || font
->lfWeight
> (pattern
->lfWeight
+ 150)))
1123 /* Charset and face should be OK. Italic has to be checked
1124 against the original spec, in case we don't have any preference. */
1128 /* Codepage Bitfields in FONTSIGNATURE struct. */
1129 #define CSB_JAPANESE (1 << 17)
1130 #define CSB_KOREAN ((1 << 19) | (1 << 21))
1131 #define CSB_CHINESE ((1 << 18) | (1 << 20))
1134 font_matches_spec (type
, font
, spec
, backend
, logfont
)
1136 NEWTEXTMETRICEX
*font
;
1138 Lisp_Object backend
;
1141 Lisp_Object extra
, val
;
1143 /* Check italic. Can't check logfonts, since it is a boolean field,
1144 so there is no difference between "non-italic" and "don't care". */
1146 int slant
= FONT_SLANT_NUMERIC (spec
);
1149 && ((slant
> 150 && !font
->ntmTm
.tmItalic
)
1150 || (slant
<= 150 && font
->ntmTm
.tmItalic
)))
1154 /* Check adstyle against generic family. */
1155 val
= AREF (spec
, FONT_ADSTYLE_INDEX
);
1158 BYTE family
= w32_generic_family (val
);
1159 if (family
!= FF_DONTCARE
1160 && family
!= (font
->ntmTm
.tmPitchAndFamily
& 0xF0))
1165 val
= AREF (spec
, FONT_SPACING_INDEX
);
1168 int spacing
= XINT (val
);
1169 int proportional
= (spacing
< FONT_SPACING_MONO
);
1171 if ((proportional
&& !(font
->ntmTm
.tmPitchAndFamily
& 0x01))
1172 || (!proportional
&& (font
->ntmTm
.tmPitchAndFamily
& 0x01)))
1176 /* Check extra parameters. */
1177 for (extra
= AREF (spec
, FONT_EXTRA_INDEX
);
1178 CONSP (extra
); extra
= XCDR (extra
))
1180 Lisp_Object extra_entry
;
1181 extra_entry
= XCAR (extra
);
1182 if (CONSP (extra_entry
))
1184 Lisp_Object key
= XCAR (extra_entry
);
1186 val
= XCDR (extra_entry
);
1187 if (EQ (key
, QCscript
) && SYMBOLP (val
))
1189 /* Only truetype fonts will have information about what
1190 scripts they support. This probably means the user
1191 will have to force Emacs to use raster, postscript
1192 or atm fonts for non-ASCII text. */
1193 if (type
& TRUETYPE_FONTTYPE
)
1196 = font_supported_scripts (&font
->ntmFontSig
);
1197 if (! memq_no_quit (val
, support
))
1202 /* Return specific matches, but play it safe. Fonts
1203 that cover more than their charset would suggest
1204 are likely to be truetype or opentype fonts,
1206 if (EQ (val
, Qlatin
))
1208 /* Although every charset but symbol, thai and
1209 arabic contains the basic ASCII set of latin
1210 characters, Emacs expects much more. */
1211 if (font
->ntmTm
.tmCharSet
!= ANSI_CHARSET
)
1214 else if (EQ (val
, Qsymbol
))
1216 if (font
->ntmTm
.tmCharSet
!= SYMBOL_CHARSET
)
1219 else if (EQ (val
, Qcyrillic
))
1221 if (font
->ntmTm
.tmCharSet
!= RUSSIAN_CHARSET
)
1224 else if (EQ (val
, Qgreek
))
1226 if (font
->ntmTm
.tmCharSet
!= GREEK_CHARSET
)
1229 else if (EQ (val
, Qarabic
))
1231 if (font
->ntmTm
.tmCharSet
!= ARABIC_CHARSET
)
1234 else if (EQ (val
, Qhebrew
))
1236 if (font
->ntmTm
.tmCharSet
!= HEBREW_CHARSET
)
1239 else if (EQ (val
, Qthai
))
1241 if (font
->ntmTm
.tmCharSet
!= THAI_CHARSET
)
1244 else if (EQ (val
, Qkana
))
1246 if (font
->ntmTm
.tmCharSet
!= SHIFTJIS_CHARSET
)
1249 else if (EQ (val
, Qbopomofo
))
1251 if (font
->ntmTm
.tmCharSet
!= CHINESEBIG5_CHARSET
)
1254 else if (EQ (val
, Qhangul
))
1256 if (font
->ntmTm
.tmCharSet
!= HANGUL_CHARSET
1257 && font
->ntmTm
.tmCharSet
!= JOHAB_CHARSET
)
1260 else if (EQ (val
, Qhan
))
1262 if (font
->ntmTm
.tmCharSet
!= CHINESEBIG5_CHARSET
1263 && font
->ntmTm
.tmCharSet
!= GB2312_CHARSET
1264 && font
->ntmTm
.tmCharSet
!= HANGUL_CHARSET
1265 && font
->ntmTm
.tmCharSet
!= JOHAB_CHARSET
1266 && font
->ntmTm
.tmCharSet
!= SHIFTJIS_CHARSET
)
1270 /* Other scripts unlikely to be handled by non-truetype
1275 else if (EQ (key
, QClang
) && SYMBOLP (val
))
1277 /* Just handle the CJK languages here, as the lang
1278 parameter is used to select a font with appropriate
1279 glyphs in the cjk unified ideographs block. Other fonts
1280 support for a language can be solely determined by
1281 its character coverage. */
1284 if (!(font
->ntmFontSig
.fsCsb
[0] & CSB_JAPANESE
))
1287 else if (EQ (val
, Qko
))
1289 if (!(font
->ntmFontSig
.fsCsb
[0] & CSB_KOREAN
))
1292 else if (EQ (val
, Qzh
))
1294 if (!(font
->ntmFontSig
.fsCsb
[0] & CSB_CHINESE
))
1298 /* Any other language, we don't recognize it. Only the above
1299 currently appear in fontset.el, so it isn't worth
1300 creating a mapping table of codepages/scripts to languages
1301 or opening the font to see if there are any language tags
1302 in it that the W32 API does not expose. Fontset
1303 spec should have a fallback, as some backends do
1304 not recognize language at all. */
1307 else if (EQ (key
, QCotf
) && CONSP (val
))
1309 /* OTF features only supported by the uniscribe backend. */
1310 if (EQ (backend
, Quniscribe
))
1312 if (!uniscribe_check_otf (logfont
, val
))
1324 w32font_coverage_ok (coverage
, charset
)
1325 FONTSIGNATURE
* coverage
;
1328 DWORD subrange1
= coverage
->fsUsb
[1];
1330 #define SUBRANGE1_HAN_MASK 0x08000000
1331 #define SUBRANGE1_HANGEUL_MASK 0x01000000
1332 #define SUBRANGE1_JAPANESE_MASK (0x00060000 | SUBRANGE1_HAN_MASK)
1334 if (charset
== GB2312_CHARSET
|| charset
== CHINESEBIG5_CHARSET
)
1336 return (subrange1
& SUBRANGE1_HAN_MASK
) == SUBRANGE1_HAN_MASK
;
1338 else if (charset
== SHIFTJIS_CHARSET
)
1340 return (subrange1
& SUBRANGE1_JAPANESE_MASK
) == SUBRANGE1_JAPANESE_MASK
;
1342 else if (charset
== HANGEUL_CHARSET
)
1344 return (subrange1
& SUBRANGE1_HANGEUL_MASK
) == SUBRANGE1_HANGEUL_MASK
;
1352 check_face_name (font
, full_name
)
1356 char full_iname
[LF_FULLFACESIZE
+1];
1358 /* Just check for names known to cause problems, since the full name
1359 can contain expanded abbreviations, prefixed foundry, postfixed
1360 style, the latter of which sometimes differs from the style indicated
1361 in the shorter name (eg Lt becomes Light or even Extra Light) */
1363 /* Helvetica is mapped to Arial in Windows, but if a Type-1 Helvetica is
1364 installed, we run into problems with the Uniscribe backend which tries
1365 to avoid non-truetype fonts, and ends up mixing the Type-1 Helvetica
1366 with Arial's characteristics, since that attempt to use Truetype works
1367 some places, but not others. */
1368 if (!xstrcasecmp (font
->lfFaceName
, "helvetica"))
1370 strncpy (full_iname
, full_name
, LF_FULLFACESIZE
);
1371 full_iname
[LF_FULLFACESIZE
] = 0;
1372 _strlwr (full_iname
);
1373 return strstr ("helvetica", full_iname
) != NULL
;
1375 /* Same for Helv. */
1376 if (!xstrcasecmp (font
->lfFaceName
, "helv"))
1378 strncpy (full_iname
, full_name
, LF_FULLFACESIZE
);
1379 full_iname
[LF_FULLFACESIZE
] = 0;
1380 _strlwr (full_iname
);
1381 return strstr ("helv", full_iname
) != NULL
;
1384 /* Since Times is mapped to Times New Roman, a substring
1385 match is not sufficient to filter out the bogus match. */
1386 else if (!xstrcasecmp (font
->lfFaceName
, "times"))
1387 return xstrcasecmp (full_name
, "times") == 0;
1393 /* Callback function for EnumFontFamiliesEx.
1394 * Checks if a font matches everything we are trying to check agaist,
1395 * and if so, adds it to a list. Both the data we are checking against
1396 * and the list to which the fonts are added are passed in via the
1397 * lparam argument, in the form of a font_callback_data struct. */
1399 add_font_entity_to_list (logical_font
, physical_font
, font_type
, lParam
)
1400 ENUMLOGFONTEX
*logical_font
;
1401 NEWTEXTMETRICEX
*physical_font
;
1405 struct font_callback_data
*match_data
1406 = (struct font_callback_data
*) lParam
;
1407 Lisp_Object backend
= match_data
->opentype_only
? Quniscribe
: Qgdi
;
1410 int is_unicode
= physical_font
->ntmFontSig
.fsUsb
[3]
1411 || physical_font
->ntmFontSig
.fsUsb
[2]
1412 || physical_font
->ntmFontSig
.fsUsb
[1]
1413 || physical_font
->ntmFontSig
.fsUsb
[0] & 0x3fffffff;
1415 /* Skip non matching fonts. */
1417 /* For uniscribe backend, consider only truetype or opentype fonts
1418 that have some unicode coverage. */
1419 if (match_data
->opentype_only
1420 && ((!physical_font
->ntmTm
.ntmFlags
& NTMFLAGS_OPENTYPE
1421 && !(font_type
& TRUETYPE_FONTTYPE
))
1425 /* Ensure a match. */
1426 if (!logfonts_match (&logical_font
->elfLogFont
, &match_data
->pattern
)
1427 || !font_matches_spec (font_type
, physical_font
,
1428 match_data
->orig_font_spec
, backend
,
1429 &logical_font
->elfLogFont
)
1430 || !w32font_coverage_ok (&physical_font
->ntmFontSig
,
1431 match_data
->pattern
.lfCharSet
))
1434 /* Avoid substitutions involving raster fonts (eg Helv -> MS Sans Serif)
1435 We limit this to raster fonts, because the test can catch some
1436 genuine fonts (eg the full name of DejaVu Sans Mono Light is actually
1437 DejaVu Sans Mono ExtraLight). Helvetica -> Arial substitution will
1438 therefore get through this test. Since full names can be prefixed
1439 by a foundry, we accept raster fonts if the font name is found
1440 anywhere within the full name. */
1441 if ((logical_font
->elfLogFont
.lfOutPrecision
== OUT_STRING_PRECIS
1442 && !strstr (logical_font
->elfFullName
,
1443 logical_font
->elfLogFont
.lfFaceName
))
1444 /* Check for well known substitutions that mess things up in the
1445 presence of Type-1 fonts of the same name. */
1446 || (!check_face_name (&logical_font
->elfLogFont
,
1447 logical_font
->elfFullName
)))
1450 /* Make a font entity for the font. */
1451 entity
= w32_enumfont_pattern_entity (match_data
->frame
, logical_font
,
1452 physical_font
, font_type
,
1453 &match_data
->pattern
,
1458 Lisp_Object spec_charset
= AREF (match_data
->orig_font_spec
,
1459 FONT_REGISTRY_INDEX
);
1461 /* iso10646-1 fonts must contain unicode mapping tables. */
1462 if (EQ (spec_charset
, Qiso10646_1
))
1467 /* unicode-bmp fonts must contain characters from the BMP. */
1468 else if (EQ (spec_charset
, Qunicode_bmp
))
1470 if (!physical_font
->ntmFontSig
.fsUsb
[3]
1471 && !(physical_font
->ntmFontSig
.fsUsb
[2] & 0xFFFFFF9E)
1472 && !(physical_font
->ntmFontSig
.fsUsb
[1] & 0xE81FFFFF)
1473 && !(physical_font
->ntmFontSig
.fsUsb
[0] & 0x007F001F))
1476 /* unicode-sip fonts must contain characters in unicode plane 2.
1477 so look for bit 57 (surrogates) in the Unicode subranges, plus
1478 the bits for CJK ranges that include those characters. */
1479 else if (EQ (spec_charset
, Qunicode_sip
))
1481 if (!physical_font
->ntmFontSig
.fsUsb
[1] & 0x02000000
1482 || !physical_font
->ntmFontSig
.fsUsb
[1] & 0x28000000)
1486 /* This font matches. */
1488 /* If registry was specified, ensure it is reported as the same. */
1489 if (!NILP (spec_charset
))
1490 ASET (entity
, FONT_REGISTRY_INDEX
, spec_charset
);
1492 /* Otherwise if using the uniscribe backend, report ANSI and DEFAULT
1493 fonts as unicode and skip other charsets. */
1494 else if (match_data
->opentype_only
)
1496 if (logical_font
->elfLogFont
.lfCharSet
== ANSI_CHARSET
1497 || logical_font
->elfLogFont
.lfCharSet
== DEFAULT_CHARSET
)
1498 ASET (entity
, FONT_REGISTRY_INDEX
, Qiso10646_1
);
1503 /* Add this font to the list. */
1504 match_data
->list
= Fcons (entity
, match_data
->list
);
1509 /* Callback function for EnumFontFamiliesEx.
1510 * Terminates the search once we have a match. */
1512 add_one_font_entity_to_list (logical_font
, physical_font
, font_type
, lParam
)
1513 ENUMLOGFONTEX
*logical_font
;
1514 NEWTEXTMETRICEX
*physical_font
;
1518 struct font_callback_data
*match_data
1519 = (struct font_callback_data
*) lParam
;
1520 add_font_entity_to_list (logical_font
, physical_font
, font_type
, lParam
);
1522 /* If we have a font in the list, terminate the search. */
1523 return NILP (match_data
->list
);
1526 /* Old function to convert from x to w32 charset, from w32fns.c. */
1528 x_to_w32_charset (lpcs
)
1531 Lisp_Object this_entry
, w32_charset
;
1533 int len
= strlen (lpcs
);
1535 /* Support "*-#nnn" format for unknown charsets. */
1536 if (strncmp (lpcs
, "*-#", 3) == 0)
1537 return atoi (lpcs
+ 3);
1539 /* All Windows fonts qualify as unicode. */
1540 if (!strncmp (lpcs
, "iso10646", 8))
1541 return DEFAULT_CHARSET
;
1543 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
1544 charset
= alloca (len
+ 1);
1545 strcpy (charset
, lpcs
);
1546 lpcs
= strchr (charset
, '*');
1550 /* Look through w32-charset-info-alist for the character set.
1551 Format of each entry is
1552 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
1554 this_entry
= Fassoc (build_string (charset
), Vw32_charset_info_alist
);
1556 if (NILP (this_entry
))
1558 /* At startup, we want iso8859-1 fonts to come up properly. */
1559 if (xstrcasecmp (charset
, "iso8859-1") == 0)
1560 return ANSI_CHARSET
;
1562 return DEFAULT_CHARSET
;
1565 w32_charset
= Fcar (Fcdr (this_entry
));
1567 /* Translate Lisp symbol to number. */
1568 if (EQ (w32_charset
, Qw32_charset_ansi
))
1569 return ANSI_CHARSET
;
1570 if (EQ (w32_charset
, Qw32_charset_symbol
))
1571 return SYMBOL_CHARSET
;
1572 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
1573 return SHIFTJIS_CHARSET
;
1574 if (EQ (w32_charset
, Qw32_charset_hangeul
))
1575 return HANGEUL_CHARSET
;
1576 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
1577 return CHINESEBIG5_CHARSET
;
1578 if (EQ (w32_charset
, Qw32_charset_gb2312
))
1579 return GB2312_CHARSET
;
1580 if (EQ (w32_charset
, Qw32_charset_oem
))
1582 if (EQ (w32_charset
, Qw32_charset_johab
))
1583 return JOHAB_CHARSET
;
1584 if (EQ (w32_charset
, Qw32_charset_easteurope
))
1585 return EASTEUROPE_CHARSET
;
1586 if (EQ (w32_charset
, Qw32_charset_turkish
))
1587 return TURKISH_CHARSET
;
1588 if (EQ (w32_charset
, Qw32_charset_baltic
))
1589 return BALTIC_CHARSET
;
1590 if (EQ (w32_charset
, Qw32_charset_russian
))
1591 return RUSSIAN_CHARSET
;
1592 if (EQ (w32_charset
, Qw32_charset_arabic
))
1593 return ARABIC_CHARSET
;
1594 if (EQ (w32_charset
, Qw32_charset_greek
))
1595 return GREEK_CHARSET
;
1596 if (EQ (w32_charset
, Qw32_charset_hebrew
))
1597 return HEBREW_CHARSET
;
1598 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
1599 return VIETNAMESE_CHARSET
;
1600 if (EQ (w32_charset
, Qw32_charset_thai
))
1601 return THAI_CHARSET
;
1602 if (EQ (w32_charset
, Qw32_charset_mac
))
1605 return DEFAULT_CHARSET
;
1609 /* Convert a Lisp font registry (symbol) to a windows charset. */
1611 registry_to_w32_charset (charset
)
1612 Lisp_Object charset
;
1614 if (EQ (charset
, Qiso10646_1
) || EQ (charset
, Qunicode_bmp
)
1615 || EQ (charset
, Qunicode_sip
))
1616 return DEFAULT_CHARSET
; /* UNICODE_CHARSET not defined in MingW32 */
1617 else if (EQ (charset
, Qiso8859_1
))
1618 return ANSI_CHARSET
;
1619 else if (SYMBOLP (charset
))
1620 return x_to_w32_charset (SDATA (SYMBOL_NAME (charset
)));
1622 return DEFAULT_CHARSET
;
1625 /* Old function to convert from w32 to x charset, from w32fns.c. */
1627 w32_to_x_charset (fncharset
, matching
)
1631 static char buf
[32];
1632 Lisp_Object charset_type
;
1637 /* If fully specified, accept it as it is. Otherwise use a
1639 char *wildcard
= strchr (matching
, '*');
1642 else if (strchr (matching
, '-'))
1645 match_len
= strlen (matching
);
1651 /* Handle startup case of w32-charset-info-alist not
1652 being set up yet. */
1653 if (NILP (Vw32_charset_info_alist
))
1655 charset_type
= Qw32_charset_ansi
;
1657 case DEFAULT_CHARSET
:
1658 charset_type
= Qw32_charset_default
;
1660 case SYMBOL_CHARSET
:
1661 charset_type
= Qw32_charset_symbol
;
1663 case SHIFTJIS_CHARSET
:
1664 charset_type
= Qw32_charset_shiftjis
;
1666 case HANGEUL_CHARSET
:
1667 charset_type
= Qw32_charset_hangeul
;
1669 case GB2312_CHARSET
:
1670 charset_type
= Qw32_charset_gb2312
;
1672 case CHINESEBIG5_CHARSET
:
1673 charset_type
= Qw32_charset_chinesebig5
;
1676 charset_type
= Qw32_charset_oem
;
1678 case EASTEUROPE_CHARSET
:
1679 charset_type
= Qw32_charset_easteurope
;
1681 case TURKISH_CHARSET
:
1682 charset_type
= Qw32_charset_turkish
;
1684 case BALTIC_CHARSET
:
1685 charset_type
= Qw32_charset_baltic
;
1687 case RUSSIAN_CHARSET
:
1688 charset_type
= Qw32_charset_russian
;
1690 case ARABIC_CHARSET
:
1691 charset_type
= Qw32_charset_arabic
;
1694 charset_type
= Qw32_charset_greek
;
1696 case HEBREW_CHARSET
:
1697 charset_type
= Qw32_charset_hebrew
;
1699 case VIETNAMESE_CHARSET
:
1700 charset_type
= Qw32_charset_vietnamese
;
1703 charset_type
= Qw32_charset_thai
;
1706 charset_type
= Qw32_charset_mac
;
1709 charset_type
= Qw32_charset_johab
;
1713 /* Encode numerical value of unknown charset. */
1714 sprintf (buf
, "*-#%u", fncharset
);
1720 char * best_match
= NULL
;
1721 int matching_found
= 0;
1723 /* Look through w32-charset-info-alist for the character set.
1724 Prefer ISO codepages, and prefer lower numbers in the ISO
1725 range. Only return charsets for codepages which are installed.
1727 Format of each entry is
1728 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
1730 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
1733 Lisp_Object w32_charset
;
1734 Lisp_Object codepage
;
1736 Lisp_Object this_entry
= XCAR (rest
);
1738 /* Skip invalid entries in alist. */
1739 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
1740 || !CONSP (XCDR (this_entry
))
1741 || !SYMBOLP (XCAR (XCDR (this_entry
))))
1744 x_charset
= SDATA (XCAR (this_entry
));
1745 w32_charset
= XCAR (XCDR (this_entry
));
1746 codepage
= XCDR (XCDR (this_entry
));
1748 /* Look for Same charset and a valid codepage (or non-int
1749 which means ignore). */
1750 if (EQ (w32_charset
, charset_type
)
1751 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
1752 || IsValidCodePage (XINT (codepage
))))
1754 /* If we don't have a match already, then this is the
1758 best_match
= x_charset
;
1759 if (matching
&& !strnicmp (x_charset
, matching
, match_len
))
1762 /* If we already found a match for MATCHING, then
1763 only consider other matches. */
1764 else if (matching_found
1765 && strnicmp (x_charset
, matching
, match_len
))
1767 /* If this matches what we want, and the best so far doesn't,
1768 then this is better. */
1769 else if (!matching_found
&& matching
1770 && !strnicmp (x_charset
, matching
, match_len
))
1772 best_match
= x_charset
;
1775 /* If this is fully specified, and the best so far isn't,
1776 then this is better. */
1777 else if ((!strchr (best_match
, '-') && strchr (x_charset
, '-'))
1778 /* If this is an ISO codepage, and the best so far isn't,
1779 then this is better, but only if it fully specifies the
1781 || (strnicmp (best_match
, "iso", 3) != 0
1782 && strnicmp (x_charset
, "iso", 3) == 0
1783 && strchr (x_charset
, '-')))
1784 best_match
= x_charset
;
1785 /* If both are ISO8859 codepages, choose the one with the
1786 lowest number in the encoding field. */
1787 else if (strnicmp (best_match
, "iso8859-", 8) == 0
1788 && strnicmp (x_charset
, "iso8859-", 8) == 0)
1790 int best_enc
= atoi (best_match
+ 8);
1791 int this_enc
= atoi (x_charset
+ 8);
1792 if (this_enc
> 0 && this_enc
< best_enc
)
1793 best_match
= x_charset
;
1798 /* If no match, encode the numeric value. */
1801 sprintf (buf
, "*-#%u", fncharset
);
1805 strncpy (buf
, best_match
, 31);
1806 /* If the charset is not fully specified, put -0 on the end. */
1807 if (!strchr (best_match
, '-'))
1809 int pos
= strlen (best_match
);
1810 /* Charset specifiers shouldn't be very long. If it is a made
1811 up one, truncating it should not do any harm since it isn't
1812 recognized anyway. */
1815 strcpy (buf
+ pos
, "-0");
1823 w32_registry (w32_charset
, font_type
)
1829 /* If charset is defaulted, charset is unicode or unknown, depending on
1831 if (w32_charset
== DEFAULT_CHARSET
)
1832 return font_type
== TRUETYPE_FONTTYPE
? Qiso10646_1
: Qunknown
;
1834 charset
= w32_to_x_charset (w32_charset
, NULL
);
1835 return font_intern_prop (charset
, strlen(charset
), 1);
1839 w32_decode_weight (fnweight
)
1842 if (fnweight
>= FW_HEAVY
) return 210;
1843 if (fnweight
>= FW_EXTRABOLD
) return 205;
1844 if (fnweight
>= FW_BOLD
) return 200;
1845 if (fnweight
>= FW_SEMIBOLD
) return 180;
1846 if (fnweight
>= FW_NORMAL
) return 100;
1847 if (fnweight
>= FW_LIGHT
) return 50;
1848 if (fnweight
>= FW_EXTRALIGHT
) return 40;
1849 if (fnweight
> FW_THIN
) return 20;
1854 w32_encode_weight (n
)
1857 if (n
>= 210) return FW_HEAVY
;
1858 if (n
>= 205) return FW_EXTRABOLD
;
1859 if (n
>= 200) return FW_BOLD
;
1860 if (n
>= 180) return FW_SEMIBOLD
;
1861 if (n
>= 100) return FW_NORMAL
;
1862 if (n
>= 50) return FW_LIGHT
;
1863 if (n
>= 40) return FW_EXTRALIGHT
;
1864 if (n
>= 20) return FW_THIN
;
1868 /* Convert a Windows font weight into one of the weights supported
1869 by fontconfig (see font.c:font_parse_fcname). */
1871 w32_to_fc_weight (n
)
1874 if (n
>= FW_EXTRABOLD
) return intern ("black");
1875 if (n
>= FW_BOLD
) return intern ("bold");
1876 if (n
>= FW_SEMIBOLD
) return intern ("demibold");
1877 if (n
>= FW_NORMAL
) return intern ("medium");
1878 return intern ("light");
1881 /* Fill in all the available details of LOGFONT from FONT_SPEC. */
1883 fill_in_logfont (f
, logfont
, font_spec
)
1886 Lisp_Object font_spec
;
1888 Lisp_Object tmp
, extra
;
1889 int dpi
= FRAME_W32_DISPLAY_INFO (f
)->resy
;
1891 tmp
= AREF (font_spec
, FONT_DPI_INDEX
);
1896 else if (FLOATP (tmp
))
1898 dpi
= (int) (XFLOAT_DATA (tmp
) + 0.5);
1902 tmp
= AREF (font_spec
, FONT_SIZE_INDEX
);
1904 logfont
->lfHeight
= -1 * XINT (tmp
);
1905 else if (FLOATP (tmp
))
1906 logfont
->lfHeight
= (int) (-1.0 * dpi
* XFLOAT_DATA (tmp
) / 72.27 + 0.5);
1913 tmp
= AREF (font_spec
, FONT_WEIGHT_INDEX
);
1915 logfont
->lfWeight
= w32_encode_weight (FONT_WEIGHT_NUMERIC (font_spec
));
1918 tmp
= AREF (font_spec
, FONT_SLANT_INDEX
);
1921 int slant
= FONT_SLANT_NUMERIC (font_spec
);
1922 logfont
->lfItalic
= slant
> 150 ? 1 : 0;
1930 tmp
= AREF (font_spec
, FONT_REGISTRY_INDEX
);
1932 logfont
->lfCharSet
= registry_to_w32_charset (tmp
);
1934 logfont
->lfCharSet
= DEFAULT_CHARSET
;
1938 /* Clip Precision */
1941 logfont
->lfQuality
= DEFAULT_QUALITY
;
1943 /* Generic Family and Face Name */
1944 logfont
->lfPitchAndFamily
= FF_DONTCARE
| DEFAULT_PITCH
;
1946 tmp
= AREF (font_spec
, FONT_FAMILY_INDEX
);
1949 logfont
->lfPitchAndFamily
= w32_generic_family (tmp
) | DEFAULT_PITCH
;
1950 if ((logfont
->lfPitchAndFamily
& 0xF0) != FF_DONTCARE
)
1951 ; /* Font name was generic, don't fill in font name. */
1952 /* Font families are interned, but allow for strings also in case of
1954 else if (SYMBOLP (tmp
))
1955 strncpy (logfont
->lfFaceName
,
1956 SDATA (ENCODE_SYSTEM (SYMBOL_NAME (tmp
))), LF_FACESIZE
);
1959 tmp
= AREF (font_spec
, FONT_ADSTYLE_INDEX
);
1962 /* Override generic family. */
1963 BYTE family
= w32_generic_family (tmp
);
1964 if (family
!= FF_DONTCARE
)
1965 logfont
->lfPitchAndFamily
= family
| DEFAULT_PITCH
;
1969 /* Set pitch based on the spacing property. */
1970 tmp
= AREF (font_spec
, FONT_SPACING_INDEX
);
1973 int spacing
= XINT (tmp
);
1974 if (spacing
< FONT_SPACING_MONO
)
1975 logfont
->lfPitchAndFamily
1976 = logfont
->lfPitchAndFamily
& 0xF0 | VARIABLE_PITCH
;
1978 logfont
->lfPitchAndFamily
1979 = logfont
->lfPitchAndFamily
& 0xF0 | FIXED_PITCH
;
1982 /* Process EXTRA info. */
1983 for (extra
= AREF (font_spec
, FONT_EXTRA_INDEX
);
1984 CONSP (extra
); extra
= XCDR (extra
))
1989 Lisp_Object key
, val
;
1990 key
= XCAR (tmp
), val
= XCDR (tmp
);
1991 /* Only use QCscript if charset is not provided, or is unicode
1992 and a single script is specified. This is rather crude,
1993 and is only used to narrow down the fonts returned where
1994 there is a definite match. Some scripts, such as latin, han,
1995 cjk-misc match multiple lfCharSet values, so we can't pre-filter
1997 if (EQ (key
, QCscript
)
1998 && logfont
->lfCharSet
== DEFAULT_CHARSET
2001 if (EQ (val
, Qgreek
))
2002 logfont
->lfCharSet
= GREEK_CHARSET
;
2003 else if (EQ (val
, Qhangul
))
2004 logfont
->lfCharSet
= HANGUL_CHARSET
;
2005 else if (EQ (val
, Qkana
) || EQ (val
, Qkanbun
))
2006 logfont
->lfCharSet
= SHIFTJIS_CHARSET
;
2007 else if (EQ (val
, Qbopomofo
))
2008 logfont
->lfCharSet
= CHINESEBIG5_CHARSET
;
2009 /* GB 18030 supports tibetan, yi, mongolian,
2010 fonts that support it should show up if we ask for
2012 else if (EQ (val
, Qtibetan
) || EQ (val
, Qyi
)
2013 || EQ (val
, Qmongolian
))
2014 logfont
->lfCharSet
= GB2312_CHARSET
;
2015 else if (EQ (val
, Qhebrew
))
2016 logfont
->lfCharSet
= HEBREW_CHARSET
;
2017 else if (EQ (val
, Qarabic
))
2018 logfont
->lfCharSet
= ARABIC_CHARSET
;
2019 else if (EQ (val
, Qthai
))
2020 logfont
->lfCharSet
= THAI_CHARSET
;
2022 else if (EQ (key
, QCantialias
) && SYMBOLP (val
))
2024 logfont
->lfQuality
= w32_antialias_type (val
);
2031 list_all_matching_fonts (match_data
)
2032 struct font_callback_data
*match_data
;
2035 Lisp_Object families
= w32font_list_family (match_data
->frame
);
2036 struct frame
*f
= XFRAME (match_data
->frame
);
2038 dc
= get_frame_dc (f
);
2040 while (!NILP (families
))
2042 /* Only fonts from the current locale are given localized names
2043 on Windows, so we can keep backwards compatibility with
2044 Windows 9x/ME by using non-Unicode font enumeration without
2045 sacrificing internationalization here. */
2047 Lisp_Object family
= CAR (families
);
2048 families
= CDR (families
);
2051 else if (SYMBOLP (family
))
2052 name
= SDATA (ENCODE_SYSTEM (SYMBOL_NAME (family
)));
2056 strncpy (match_data
->pattern
.lfFaceName
, name
, LF_FACESIZE
);
2057 match_data
->pattern
.lfFaceName
[LF_FACESIZE
- 1] = '\0';
2059 EnumFontFamiliesEx (dc
, &match_data
->pattern
,
2060 (FONTENUMPROC
) add_font_entity_to_list
,
2061 (LPARAM
) match_data
, 0);
2064 release_frame_dc (f
, dc
);
2068 lispy_antialias_type (type
)
2075 case NONANTIALIASED_QUALITY
:
2078 case ANTIALIASED_QUALITY
:
2081 case CLEARTYPE_QUALITY
:
2084 case CLEARTYPE_NATURAL_QUALITY
:
2094 /* Convert antialiasing symbols to lfQuality */
2096 w32_antialias_type (type
)
2099 if (EQ (type
, Qnone
))
2100 return NONANTIALIASED_QUALITY
;
2101 else if (EQ (type
, Qstandard
))
2102 return ANTIALIASED_QUALITY
;
2103 else if (EQ (type
, Qsubpixel
))
2104 return CLEARTYPE_QUALITY
;
2105 else if (EQ (type
, Qnatural
))
2106 return CLEARTYPE_NATURAL_QUALITY
;
2108 return DEFAULT_QUALITY
;
2111 /* Return a list of all the scripts that the font supports. */
2113 font_supported_scripts (FONTSIGNATURE
* sig
)
2115 DWORD
* subranges
= sig
->fsUsb
;
2116 Lisp_Object supported
= Qnil
;
2118 /* Match a single subrange. SYM is set if bit N is set in subranges. */
2119 #define SUBRANGE(n,sym) \
2120 if (subranges[(n) / 32] & (1 << ((n) % 32))) \
2121 supported = Fcons ((sym), supported)
2123 /* Match multiple subranges. SYM is set if any MASK bit is set in
2124 subranges[0 - 3]. */
2125 #define MASK_ANY(mask0,mask1,mask2,mask3,sym) \
2126 if ((subranges[0] & (mask0)) || (subranges[1] & (mask1)) \
2127 || (subranges[2] & (mask2)) || (subranges[3] & (mask3))) \
2128 supported = Fcons ((sym), supported)
2130 SUBRANGE (0, Qlatin
);
2131 /* The following count as latin too, ASCII should be present in these fonts,
2132 so don't need to mark them separately. */
2133 /* 1: Latin-1 supplement, 2: Latin Extended A, 3: Latin Extended B. */
2134 SUBRANGE (4, Qphonetic
);
2135 /* 5: Spacing and tone modifiers, 6: Combining Diacriticals. */
2136 SUBRANGE (7, Qgreek
);
2137 SUBRANGE (8, Qcoptic
);
2138 SUBRANGE (9, Qcyrillic
);
2139 SUBRANGE (10, Qarmenian
);
2140 SUBRANGE (11, Qhebrew
);
2142 SUBRANGE (13, Qarabic
);
2143 SUBRANGE (14, Qnko
);
2144 SUBRANGE (15, Qdevanagari
);
2145 SUBRANGE (16, Qbengali
);
2146 SUBRANGE (17, Qgurmukhi
);
2147 SUBRANGE (18, Qgujarati
);
2148 SUBRANGE (19, Qoriya
);
2149 SUBRANGE (20, Qtamil
);
2150 SUBRANGE (21, Qtelugu
);
2151 SUBRANGE (22, Qkannada
);
2152 SUBRANGE (23, Qmalayalam
);
2153 SUBRANGE (24, Qthai
);
2154 SUBRANGE (25, Qlao
);
2155 SUBRANGE (26, Qgeorgian
);
2156 SUBRANGE (27, Qbalinese
);
2157 /* 28: Hangul Jamo. */
2158 /* 29: Latin Extended, 30: Greek Extended, 31: Punctuation. */
2159 /* 32-47: Symbols (defined below). */
2160 SUBRANGE (48, Qcjk_misc
);
2161 /* Match either 49: katakana or 50: hiragana for kana. */
2162 MASK_ANY (0, 0x00060000, 0, 0, Qkana
);
2163 SUBRANGE (51, Qbopomofo
);
2164 /* 52: Compatibility Jamo */
2165 SUBRANGE (53, Qphags_pa
);
2166 /* 54: Enclosed CJK letters and months, 55: CJK Compatibility. */
2167 SUBRANGE (56, Qhangul
);
2168 /* 57: Surrogates. */
2169 SUBRANGE (58, Qphoenician
);
2170 SUBRANGE (59, Qhan
); /* There are others, but this is the main one. */
2171 SUBRANGE (59, Qideographic_description
); /* Windows lumps this in. */
2172 SUBRANGE (59, Qkanbun
); /* And this. */
2173 /* 60: Private use, 61: CJK strokes and compatibility. */
2174 /* 62: Alphabetic Presentation, 63: Arabic Presentation A. */
2175 /* 64: Combining half marks, 65: Vertical and CJK compatibility. */
2176 /* 66: Small forms, 67: Arabic Presentation B, 68: Half and Full width. */
2178 SUBRANGE (70, Qtibetan
);
2179 SUBRANGE (71, Qsyriac
);
2180 SUBRANGE (72, Qthaana
);
2181 SUBRANGE (73, Qsinhala
);
2182 SUBRANGE (74, Qmyanmar
);
2183 SUBRANGE (75, Qethiopic
);
2184 SUBRANGE (76, Qcherokee
);
2185 SUBRANGE (77, Qcanadian_aboriginal
);
2186 SUBRANGE (78, Qogham
);
2187 SUBRANGE (79, Qrunic
);
2188 SUBRANGE (80, Qkhmer
);
2189 SUBRANGE (81, Qmongolian
);
2190 SUBRANGE (82, Qbraille
);
2192 SUBRANGE (84, Qbuhid
);
2193 SUBRANGE (84, Qhanunoo
);
2194 SUBRANGE (84, Qtagalog
);
2195 SUBRANGE (84, Qtagbanwa
);
2196 SUBRANGE (85, Qold_italic
);
2197 SUBRANGE (86, Qgothic
);
2198 SUBRANGE (87, Qdeseret
);
2199 SUBRANGE (88, Qbyzantine_musical_symbol
);
2200 SUBRANGE (88, Qmusical_symbol
); /* Windows doesn't distinguish these. */
2201 SUBRANGE (89, Qmathematical
);
2202 /* 90: Private use, 91: Variation selectors, 92: Tags. */
2203 SUBRANGE (93, Qlimbu
);
2204 SUBRANGE (94, Qtai_le
);
2205 /* 95: New Tai Le */
2206 SUBRANGE (90, Qbuginese
);
2207 SUBRANGE (97, Qglagolitic
);
2208 SUBRANGE (98, Qtifinagh
);
2209 /* 99: Yijing Hexagrams. */
2210 SUBRANGE (100, Qsyloti_nagri
);
2211 SUBRANGE (101, Qlinear_b
);
2212 /* 102: Ancient Greek Numbers. */
2213 SUBRANGE (103, Qugaritic
);
2214 SUBRANGE (104, Qold_persian
);
2215 SUBRANGE (105, Qshavian
);
2216 SUBRANGE (106, Qosmanya
);
2217 SUBRANGE (107, Qcypriot
);
2218 SUBRANGE (108, Qkharoshthi
);
2219 /* 109: Tai Xuan Jing. */
2220 SUBRANGE (110, Qcuneiform
);
2221 /* 111: Counting Rods, 112: Sundanese, 113: Lepcha, 114: Ol Chiki. */
2222 /* 115: Saurashtra, 116: Kayah Li, 117: Rejang. */
2223 SUBRANGE (118, Qcham
);
2224 /* 119: Ancient symbols, 120: Phaistos Disc. */
2225 /* 121: Carian, Lycian, Lydian, 122: Dominos, Mah Jong tiles. */
2226 /* 123-127: Reserved. */
2228 /* There isn't really a main symbol range, so include symbol if any
2229 relevant range is set. */
2230 MASK_ANY (0x8000000, 0x0000FFFF, 0, 0, Qsymbol
);
2232 /* Missing: Tai Viet (U+AA80-U+AADF). */
2239 /* Generate a full name for a Windows font.
2240 The full name is in fcname format, with weight, slant and antialiasing
2241 specified if they are not "normal". */
2243 w32font_full_name (font
, font_obj
, pixel_size
, name
, nbytes
)
2245 Lisp_Object font_obj
;
2250 int len
, height
, outline
;
2252 Lisp_Object antialiasing
, weight
= Qnil
;
2254 len
= strlen (font
->lfFaceName
);
2256 outline
= EQ (AREF (font_obj
, FONT_FOUNDRY_INDEX
), Qoutline
);
2258 /* Represent size of scalable fonts by point size. But use pixelsize for
2259 raster fonts to indicate that they are exactly that size. */
2261 len
+= 11; /* -SIZE */
2266 len
+= 7; /* :italic */
2268 if (font
->lfWeight
&& font
->lfWeight
!= FW_NORMAL
)
2270 weight
= w32_to_fc_weight (font
->lfWeight
);
2271 len
+= 1 + SBYTES (SYMBOL_NAME (weight
)); /* :WEIGHT */
2274 antialiasing
= lispy_antialias_type (font
->lfQuality
);
2275 if (! NILP (antialiasing
))
2276 len
+= 11 + SBYTES (SYMBOL_NAME (antialiasing
)); /* :antialias=NAME */
2278 /* Check that the buffer is big enough */
2283 p
+= sprintf (p
, "%s", font
->lfFaceName
);
2285 height
= font
->lfHeight
? eabs (font
->lfHeight
) : pixel_size
;
2291 float pointsize
= height
* 72.0 / one_w32_display_info
.resy
;
2292 /* Round to nearest half point. floor is used, since round is not
2293 supported in MS library. */
2294 pointsize
= floor (pointsize
* 2 + 0.5) / 2;
2295 p
+= sprintf (p
, "-%1.1f", pointsize
);
2298 p
+= sprintf (p
, ":pixelsize=%d", height
);
2301 if (SYMBOLP (weight
) && ! NILP (weight
))
2302 p
+= sprintf (p
, ":%s", SDATA (SYMBOL_NAME (weight
)));
2305 p
+= sprintf (p
, ":italic");
2307 if (SYMBOLP (antialiasing
) && ! NILP (antialiasing
))
2308 p
+= sprintf (p
, ":antialias=%s", SDATA (SYMBOL_NAME (antialiasing
)));
2313 /* Convert a logfont and point size into a fontconfig style font name.
2314 POINTSIZE is in tenths of points.
2315 If SIZE indicates the size of buffer FCNAME, into which the font name
2316 is written. If the buffer is not large enough to contain the name,
2317 the function returns -1, otherwise it returns the number of bytes
2318 written to FCNAME. */
2319 static int logfont_to_fcname(font
, pointsize
, fcname
, size
)
2327 Lisp_Object weight
= Qnil
;
2329 len
= strlen (font
->lfFaceName
) + 2;
2330 height
= pointsize
/ 10;
2331 while (height
/= 10)
2338 len
+= 7; /* :italic */
2339 if (font
->lfWeight
&& font
->lfWeight
!= FW_NORMAL
)
2341 weight
= w32_to_fc_weight (font
->lfWeight
);
2342 len
+= SBYTES (SYMBOL_NAME (weight
)) + 1;
2348 p
+= sprintf (p
, "%s-%d", font
->lfFaceName
, pointsize
/ 10);
2350 p
+= sprintf (p
, ".%d", pointsize
% 10);
2352 if (SYMBOLP (weight
) && !NILP (weight
))
2353 p
+= sprintf (p
, ":%s", SDATA (SYMBOL_NAME (weight
)));
2356 p
+= sprintf (p
, ":italic");
2358 return (p
- fcname
);
2362 compute_metrics (dc
, w32_font
, code
, metrics
)
2364 struct w32font_info
*w32_font
;
2366 struct w32_metric_cache
*metrics
;
2370 unsigned int options
= GGO_METRICS
;
2372 if (w32_font
->glyph_idx
)
2373 options
|= GGO_GLYPH_INDEX
;
2375 bzero (&transform
, sizeof (transform
));
2376 transform
.eM11
.value
= 1;
2377 transform
.eM22
.value
= 1;
2379 if (GetGlyphOutlineW (dc
, code
, options
, &gm
, 0, NULL
, &transform
)
2382 metrics
->lbearing
= gm
.gmptGlyphOrigin
.x
;
2383 metrics
->rbearing
= gm
.gmptGlyphOrigin
.x
+ gm
.gmBlackBoxX
;
2384 metrics
->width
= gm
.gmCellIncX
;
2385 metrics
->status
= W32METRIC_SUCCESS
;
2388 metrics
->status
= W32METRIC_FAIL
;
2391 DEFUN ("x-select-font", Fx_select_font
, Sx_select_font
, 0, 2, 0,
2392 doc
: /* Read a font name using a W32 font selection dialog.
2393 Return fontconfig style font string corresponding to the selection.
2395 If FRAME is omitted or nil, it defaults to the selected frame.
2396 If EXCLUDE-PROPORTIONAL is non-nil, exclude proportional fonts
2397 in the font selection dialog. */)
2398 (frame
, exclude_proportional
)
2399 Lisp_Object frame
, exclude_proportional
;
2401 FRAME_PTR f
= check_x_frame (frame
);
2409 bzero (&cf
, sizeof (cf
));
2410 bzero (&lf
, sizeof (lf
));
2412 cf
.lStructSize
= sizeof (cf
);
2413 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
2414 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
2416 /* If exclude_proportional is non-nil, limit the selection to
2417 monospaced fonts. */
2418 if (!NILP (exclude_proportional
))
2419 cf
.Flags
|= CF_FIXEDPITCHONLY
;
2423 /* Initialize as much of the font details as we can from the current
2425 hdc
= GetDC (FRAME_W32_WINDOW (f
));
2426 oldobj
= SelectObject (hdc
, FONT_HANDLE (FRAME_FONT (f
)));
2427 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
2428 if (GetTextMetrics (hdc
, &tm
))
2430 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
2431 lf
.lfWeight
= tm
.tmWeight
;
2432 lf
.lfItalic
= tm
.tmItalic
;
2433 lf
.lfUnderline
= tm
.tmUnderlined
;
2434 lf
.lfStrikeOut
= tm
.tmStruckOut
;
2435 lf
.lfCharSet
= tm
.tmCharSet
;
2436 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
2438 SelectObject (hdc
, oldobj
);
2439 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
2441 if (!ChooseFont (&cf
)
2442 || logfont_to_fcname (&lf
, cf
.iPointSize
, buf
, 100) < 0)
2445 return DECODE_SYSTEM (build_string (buf
));
2448 struct font_driver w32font_driver
=
2451 0, /* case insensitive */
2455 w32font_list_family
,
2456 NULL
, /* free_entity */
2459 NULL
, /* prepare_face */
2460 NULL
, /* done_face */
2462 w32font_encode_char
,
2463 w32font_text_extents
,
2465 NULL
, /* get_bitmap */
2466 NULL
, /* free_bitmap */
2467 NULL
, /* get_outline */
2468 NULL
, /* free_outline */
2469 NULL
, /* anchor_point */
2470 NULL
, /* otf_capability */
2471 NULL
, /* otf_drive */
2472 NULL
, /* start_for_frame */
2473 NULL
, /* end_for_frame */
2478 /* Initialize state that does not change between invocations. This is only
2479 called when Emacs is dumped. */
2483 DEFSYM (Qgdi
, "gdi");
2484 DEFSYM (Quniscribe
, "uniscribe");
2485 DEFSYM (QCformat
, ":format");
2487 /* Generic font families. */
2488 DEFSYM (Qmonospace
, "monospace");
2489 DEFSYM (Qserif
, "serif");
2490 DEFSYM (Qsansserif
, "sansserif");
2491 DEFSYM (Qscript
, "script");
2492 DEFSYM (Qdecorative
, "decorative");
2494 DEFSYM (Qsans_serif
, "sans_serif");
2495 DEFSYM (Qsans
, "sans");
2496 DEFSYM (Qmono
, "mono");
2498 /* Fake foundries. */
2499 DEFSYM (Qraster
, "raster");
2500 DEFSYM (Qoutline
, "outline");
2501 DEFSYM (Qunknown
, "unknown");
2504 DEFSYM (Qstandard
, "standard");
2505 DEFSYM (Qsubpixel
, "subpixel");
2506 DEFSYM (Qnatural
, "natural");
2512 DEFSYM (Qlatin
, "latin");
2513 DEFSYM (Qgreek
, "greek");
2514 DEFSYM (Qcoptic
, "coptic");
2515 DEFSYM (Qcyrillic
, "cyrillic");
2516 DEFSYM (Qarmenian
, "armenian");
2517 DEFSYM (Qhebrew
, "hebrew");
2518 DEFSYM (Qarabic
, "arabic");
2519 DEFSYM (Qsyriac
, "syriac");
2520 DEFSYM (Qnko
, "nko");
2521 DEFSYM (Qthaana
, "thaana");
2522 DEFSYM (Qdevanagari
, "devanagari");
2523 DEFSYM (Qbengali
, "bengali");
2524 DEFSYM (Qgurmukhi
, "gurmukhi");
2525 DEFSYM (Qgujarati
, "gujarati");
2526 DEFSYM (Qoriya
, "oriya");
2527 DEFSYM (Qtamil
, "tamil");
2528 DEFSYM (Qtelugu
, "telugu");
2529 DEFSYM (Qkannada
, "kannada");
2530 DEFSYM (Qmalayalam
, "malayalam");
2531 DEFSYM (Qsinhala
, "sinhala");
2532 DEFSYM (Qthai
, "thai");
2533 DEFSYM (Qlao
, "lao");
2534 DEFSYM (Qtibetan
, "tibetan");
2535 DEFSYM (Qmyanmar
, "myanmar");
2536 DEFSYM (Qgeorgian
, "georgian");
2537 DEFSYM (Qhangul
, "hangul");
2538 DEFSYM (Qethiopic
, "ethiopic");
2539 DEFSYM (Qcherokee
, "cherokee");
2540 DEFSYM (Qcanadian_aboriginal
, "canadian-aboriginal");
2541 DEFSYM (Qogham
, "ogham");
2542 DEFSYM (Qrunic
, "runic");
2543 DEFSYM (Qkhmer
, "khmer");
2544 DEFSYM (Qmongolian
, "mongolian");
2545 DEFSYM (Qsymbol
, "symbol");
2546 DEFSYM (Qbraille
, "braille");
2547 DEFSYM (Qhan
, "han");
2548 DEFSYM (Qideographic_description
, "ideographic-description");
2549 DEFSYM (Qcjk_misc
, "cjk-misc");
2550 DEFSYM (Qkana
, "kana");
2551 DEFSYM (Qbopomofo
, "bopomofo");
2552 DEFSYM (Qkanbun
, "kanbun");
2554 DEFSYM (Qbyzantine_musical_symbol
, "byzantine-musical-symbol");
2555 DEFSYM (Qmusical_symbol
, "musical-symbol");
2556 DEFSYM (Qmathematical
, "mathematical");
2557 DEFSYM (Qcham
, "cham");
2558 DEFSYM (Qphonetic
, "phonetic");
2559 DEFSYM (Qbalinese
, "balinese");
2560 DEFSYM (Qbuginese
, "buginese");
2561 DEFSYM (Qbuhid
, "buhid");
2562 DEFSYM (Qcuneiform
, "cuneiform");
2563 DEFSYM (Qcypriot
, "cypriot");
2564 DEFSYM (Qdeseret
, "deseret");
2565 DEFSYM (Qglagolitic
, "glagolitic");
2566 DEFSYM (Qgothic
, "gothic");
2567 DEFSYM (Qhanunoo
, "hanunoo");
2568 DEFSYM (Qkharoshthi
, "kharoshthi");
2569 DEFSYM (Qlimbu
, "limbu");
2570 DEFSYM (Qlinear_b
, "linear_b");
2571 DEFSYM (Qold_italic
, "old_italic");
2572 DEFSYM (Qold_persian
, "old_persian");
2573 DEFSYM (Qosmanya
, "osmanya");
2574 DEFSYM (Qphags_pa
, "phags-pa");
2575 DEFSYM (Qphoenician
, "phoenician");
2576 DEFSYM (Qshavian
, "shavian");
2577 DEFSYM (Qsyloti_nagri
, "syloti_nagri");
2578 DEFSYM (Qtagalog
, "tagalog");
2579 DEFSYM (Qtagbanwa
, "tagbanwa");
2580 DEFSYM (Qtai_le
, "tai_le");
2581 DEFSYM (Qtifinagh
, "tifinagh");
2582 DEFSYM (Qugaritic
, "ugaritic");
2584 /* W32 font encodings. */
2585 DEFVAR_LISP ("w32-charset-info-alist",
2586 &Vw32_charset_info_alist
,
2587 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
2588 Each entry should be of the form:
2590 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
2592 where CHARSET_NAME is a string used in font names to identify the charset,
2593 WINDOWS_CHARSET is a symbol that can be one of:
2595 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
2596 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
2597 w32-charset-chinesebig5, w32-charset-johab, w32-charset-hebrew,
2598 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
2599 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
2600 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
2603 CODEPAGE should be an integer specifying the codepage that should be used
2604 to display the character set, t to do no translation and output as Unicode,
2605 or nil to do no translation and output as 8 bit (or multibyte on far-east
2606 versions of Windows) characters. */);
2607 Vw32_charset_info_alist
= Qnil
;
2609 DEFSYM (Qw32_charset_ansi
, "w32-charset-ansi");
2610 DEFSYM (Qw32_charset_symbol
, "w32-charset-symbol");
2611 DEFSYM (Qw32_charset_default
, "w32-charset-default");
2612 DEFSYM (Qw32_charset_shiftjis
, "w32-charset-shiftjis");
2613 DEFSYM (Qw32_charset_hangeul
, "w32-charset-hangeul");
2614 DEFSYM (Qw32_charset_chinesebig5
, "w32-charset-chinesebig5");
2615 DEFSYM (Qw32_charset_gb2312
, "w32-charset-gb2312");
2616 DEFSYM (Qw32_charset_oem
, "w32-charset-oem");
2617 DEFSYM (Qw32_charset_johab
, "w32-charset-johab");
2618 DEFSYM (Qw32_charset_easteurope
, "w32-charset-easteurope");
2619 DEFSYM (Qw32_charset_turkish
, "w32-charset-turkish");
2620 DEFSYM (Qw32_charset_baltic
, "w32-charset-baltic");
2621 DEFSYM (Qw32_charset_russian
, "w32-charset-russian");
2622 DEFSYM (Qw32_charset_arabic
, "w32-charset-arabic");
2623 DEFSYM (Qw32_charset_greek
, "w32-charset-greek");
2624 DEFSYM (Qw32_charset_hebrew
, "w32-charset-hebrew");
2625 DEFSYM (Qw32_charset_vietnamese
, "w32-charset-vietnamese");
2626 DEFSYM (Qw32_charset_thai
, "w32-charset-thai");
2627 DEFSYM (Qw32_charset_mac
, "w32-charset-mac");
2629 defsubr (&Sx_select_font
);
2631 w32font_driver
.type
= Qgdi
;
2632 register_font_driver (&w32font_driver
, NULL
);
2635 /* arch-tag: 65b8a3cd-46aa-4c0d-a1f3-99e75b9c07ee
2636 (do not change this comment) */