1 /* Font backend for the Microsoft W32 API.
2 Copyright (C) 2007, 2008, 2009, 2010, 2011 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/>. */
29 #include "dispextern.h"
30 #include "character.h"
37 /* Cleartype available on Windows XP, cleartype_natural from XP SP1.
38 The latter does not try to fit cleartype smoothed fonts into the
39 same bounding box as the non-antialiased version of the font.
41 #ifndef CLEARTYPE_QUALITY
42 #define CLEARTYPE_QUALITY 5
44 #ifndef CLEARTYPE_NATURAL_QUALITY
45 #define CLEARTYPE_NATURAL_QUALITY 6
48 /* VIETNAMESE_CHARSET and JOHAB_CHARSET are not defined in some versions
50 #ifndef VIETNAMESE_CHARSET
51 #define VIETNAMESE_CHARSET 163
54 #define JOHAB_CHARSET 130
57 extern struct font_driver w32font_driver
;
60 Lisp_Object Quniscribe
;
61 static Lisp_Object QCformat
;
62 static Lisp_Object Qmonospace
, Qsansserif
, Qmono
, Qsans
, Qsans_serif
;
63 static Lisp_Object Qserif
, Qscript
, Qdecorative
;
64 static Lisp_Object Qraster
, Qoutline
, Qunknown
;
67 extern Lisp_Object QCantialias
, QCotf
, QClang
; /* defined in font.c */
68 extern Lisp_Object Qnone
; /* reuse from w32fns.c */
69 static Lisp_Object Qstandard
, Qsubpixel
, Qnatural
;
72 static Lisp_Object Qzh
;
75 static Lisp_Object Qlatin
, Qgreek
, Qcoptic
, Qcyrillic
, Qarmenian
, Qhebrew
;
76 static Lisp_Object Qarabic
, Qsyriac
, Qnko
, Qthaana
, Qdevanagari
, Qbengali
;
77 static Lisp_Object Qgurmukhi
, Qgujarati
, Qoriya
, Qtamil
, Qtelugu
;
78 static Lisp_Object Qkannada
, Qmalayalam
, Qsinhala
, Qthai
, Qlao
;
79 static Lisp_Object Qtibetan
, Qmyanmar
, Qgeorgian
, Qhangul
, Qethiopic
;
80 static Lisp_Object Qcherokee
, Qcanadian_aboriginal
, Qogham
, Qrunic
;
81 static Lisp_Object Qkhmer
, Qmongolian
, Qsymbol
, Qbraille
, Qhan
;
82 static Lisp_Object Qideographic_description
, Qcjk_misc
, Qkana
, Qbopomofo
;
83 static Lisp_Object Qkanbun
, Qyi
, Qbyzantine_musical_symbol
;
84 static Lisp_Object Qmusical_symbol
, Qmathematical
, Qcham
, Qphonetic
;
85 /* Not defined in characters.el, but referenced in fontset.el. */
86 static Lisp_Object Qbalinese
, Qbuginese
, Qbuhid
, Qcuneiform
, Qcypriot
;
87 static Lisp_Object Qdeseret
, Qglagolitic
, Qgothic
, Qhanunoo
, Qkharoshthi
;
88 static Lisp_Object Qlimbu
, Qlinear_b
, Qold_italic
, Qold_persian
, Qosmanya
;
89 static Lisp_Object Qphags_pa
, Qphoenician
, Qshavian
, Qsyloti_nagri
;
90 static Lisp_Object Qtagalog
, Qtagbanwa
, Qtai_le
, Qtifinagh
, Qugaritic
;
92 /* W32 charsets: for use in Vw32_charset_info_alist. */
93 static Lisp_Object Qw32_charset_ansi
, Qw32_charset_default
;
94 static Lisp_Object Qw32_charset_symbol
, Qw32_charset_shiftjis
;
95 static Lisp_Object Qw32_charset_hangeul
, Qw32_charset_gb2312
;
96 static Lisp_Object Qw32_charset_chinesebig5
, Qw32_charset_oem
;
97 static Lisp_Object Qw32_charset_easteurope
, Qw32_charset_turkish
;
98 static Lisp_Object Qw32_charset_baltic
, Qw32_charset_russian
;
99 static Lisp_Object Qw32_charset_arabic
, Qw32_charset_greek
;
100 static Lisp_Object Qw32_charset_hebrew
, Qw32_charset_vietnamese
;
101 static Lisp_Object Qw32_charset_thai
, Qw32_charset_johab
, Qw32_charset_mac
;
103 /* Associative list linking character set strings to Windows codepages. */
104 static Lisp_Object Vw32_charset_info_alist
;
106 /* Font spacing symbols - defined in font.c. */
107 extern Lisp_Object Qc
, Qp
, Qm
;
109 static void fill_in_logfont
P_ ((FRAME_PTR
, LOGFONT
*, Lisp_Object
));
111 static BYTE w32_antialias_type
P_ ((Lisp_Object
));
112 static Lisp_Object lispy_antialias_type
P_ ((BYTE
));
114 static Lisp_Object font_supported_scripts
P_ ((FONTSIGNATURE
*));
115 static int w32font_full_name
P_ ((LOGFONT
*, Lisp_Object
, int, char *, int));
116 static void compute_metrics
P_ ((HDC
, struct w32font_info
*, unsigned int,
117 struct w32_metric_cache
*));
119 static Lisp_Object w32_registry
P_ ((LONG
, DWORD
));
121 /* EnumFontFamiliesEx callbacks. */
122 static int CALLBACK add_font_entity_to_list
P_ ((ENUMLOGFONTEX
*,
125 static int CALLBACK add_one_font_entity_to_list
P_ ((ENUMLOGFONTEX
*,
128 static int CALLBACK add_font_name_to_list
P_ ((ENUMLOGFONTEX
*,
132 /* struct passed in as LPARAM arg to EnumFontFamiliesEx, for keeping track
133 of what we really want. */
134 struct font_callback_data
136 /* The logfont we are matching against. EnumFontFamiliesEx only matches
137 face name and charset, so we need to manually match everything else
138 in the callback function. */
140 /* The original font spec or entity. */
141 Lisp_Object orig_font_spec
;
142 /* The frame the font is being loaded on. */
144 /* The list to add matches to. */
146 /* Whether to match only opentype fonts. */
150 /* Handles the problem that EnumFontFamiliesEx will not return all
151 style variations if the font name is not specified. */
152 static void list_all_matching_fonts
P_ ((struct font_callback_data
*));
156 memq_no_quit (elt
, list
)
157 Lisp_Object elt
, list
;
159 while (CONSP (list
) && ! EQ (XCAR (list
), elt
))
161 return (CONSP (list
));
165 intern_font_name (string
)
168 Lisp_Object obarray
, tem
, str
;
171 str
= DECODE_SYSTEM (build_string (string
));
174 /* The following code is copied from the function intern (in lread.c). */
176 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
177 obarray
= check_obarray (obarray
);
178 tem
= oblookup (obarray
, SDATA (str
), len
, len
);
181 return Fintern (str
, obarray
);
184 /* w32 implementation of get_cache for font backend.
185 Return a cache of font-entities on FRAME. The cache must be a
186 cons whose cdr part is the actual cache area. */
188 w32font_get_cache (f
)
191 struct w32_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
193 return (dpyinfo
->name_list_element
);
196 /* w32 implementation of list for font backend.
197 List fonts exactly matching with FONT_SPEC on FRAME. The value
198 is a vector of font-entities. This is the sole API that
199 allocates font-entities. */
201 w32font_list (frame
, font_spec
)
202 Lisp_Object frame
, font_spec
;
204 Lisp_Object fonts
= w32font_list_internal (frame
, font_spec
, 0);
205 FONT_ADD_LOG ("w32font-list", font_spec
, fonts
);
209 /* w32 implementation of match for font backend.
210 Return a font entity most closely matching with FONT_SPEC on
211 FRAME. The closeness is detemined by the font backend, thus
212 `face-font-selection-order' is ignored here. */
214 w32font_match (frame
, font_spec
)
215 Lisp_Object frame
, font_spec
;
217 Lisp_Object entity
= w32font_match_internal (frame
, font_spec
, 0);
218 FONT_ADD_LOG ("w32font-match", font_spec
, entity
);
222 /* w32 implementation of list_family for font backend.
223 List available families. The value is a list of family names
226 w32font_list_family (frame
)
229 Lisp_Object list
= Qnil
;
230 LOGFONT font_match_pattern
;
232 FRAME_PTR f
= XFRAME (frame
);
234 bzero (&font_match_pattern
, sizeof (font_match_pattern
));
235 font_match_pattern
.lfCharSet
= DEFAULT_CHARSET
;
237 dc
= get_frame_dc (f
);
239 EnumFontFamiliesEx (dc
, &font_match_pattern
,
240 (FONTENUMPROC
) add_font_name_to_list
,
242 release_frame_dc (f
, dc
);
247 /* w32 implementation of open for font backend.
248 Open a font specified by FONT_ENTITY on frame F.
249 If the font is scalable, open it with PIXEL_SIZE. */
251 w32font_open (f
, font_entity
, pixel_size
)
253 Lisp_Object font_entity
;
256 Lisp_Object font_object
257 = font_make_object (VECSIZE (struct w32font_info
),
258 font_entity
, pixel_size
);
259 struct w32font_info
*w32_font
260 = (struct w32font_info
*) XFONT_OBJECT (font_object
);
262 ASET (font_object
, FONT_TYPE_INDEX
, Qgdi
);
264 if (!w32font_open_internal (f
, font_entity
, pixel_size
, font_object
))
269 /* GDI backend does not use glyph indices. */
270 w32_font
->glyph_idx
= 0;
275 /* w32 implementation of close for font_backend.
276 Close FONT on frame F. */
278 w32font_close (f
, font
)
283 struct w32font_info
*w32_font
= (struct w32font_info
*) font
;
285 /* Delete the GDI font object. */
286 DeleteObject (w32_font
->hfont
);
288 /* Free all the cached metrics. */
289 if (w32_font
->cached_metrics
)
291 for (i
= 0; i
< w32_font
->n_cache_blocks
; i
++)
293 xfree (w32_font
->cached_metrics
[i
]);
295 xfree (w32_font
->cached_metrics
);
296 w32_font
->cached_metrics
= NULL
;
300 /* w32 implementation of has_char for font backend.
302 If FONT_ENTITY has a glyph for character C (Unicode code point),
303 return 1. If not, return 0. If a font must be opened to check
306 w32font_has_char (entity
, c
)
310 /* We can't be certain about which characters a font will support until
311 we open it. Checking the scripts that the font supports turns out
312 to not be reliable. */
316 Lisp_Object supported_scripts
, extra
, script
;
319 extra
= AREF (entity
, FONT_EXTRA_INDEX
);
323 supported_scripts
= assq_no_quit (QCscript
, extra
);
324 /* If font doesn't claim to support any scripts, then we can't be certain
326 if (!CONSP (supported_scripts
))
329 supported_scripts
= XCDR (supported_scripts
);
331 script
= CHAR_TABLE_REF (Vchar_script_table
, c
);
333 /* If we don't know what script the character is from, then we can't be
334 certain until we open it. Also if the font claims support for the script
335 the character is from, it may only have partial coverage, so we still
336 can't be certain until we open the font. */
337 if (NILP (script
) || memq_no_quit (script
, supported_scripts
))
340 /* Font reports what scripts it supports, and none of them are the script
341 the character is from. But we still can't be certain, as some fonts
342 will contain some/most/all of the characters in that script without
343 claiming support for it. */
348 /* w32 implementation of encode_char for font backend.
349 Return a glyph code of FONT for character C (Unicode code point).
350 If FONT doesn't have such a glyph, return FONT_INVALID_CODE.
352 For speed, the gdi backend uses unicode (Emacs calls encode_char
353 far too often for it to be efficient). But we still need to detect
354 which characters are not supported by the font.
357 w32font_encode_char (font
, c
)
361 struct w32font_info
* w32_font
= (struct w32font_info
*)font
;
363 if (c
< w32_font
->metrics
.tmFirstChar
364 || c
> w32_font
->metrics
.tmLastChar
)
365 return FONT_INVALID_CODE
;
370 /* w32 implementation of text_extents for font backend.
371 Perform the size computation of glyphs of FONT and fillin members
372 of METRICS. The glyphs are specified by their glyph codes in
373 CODE (length NGLYPHS). Apparently metrics can be NULL, in this
374 case just return the overall width. */
376 w32font_text_extents (font
, code
, nglyphs
, metrics
)
380 struct font_metrics
*metrics
;
383 HFONT old_font
= NULL
;
390 struct w32font_info
*w32_font
= (struct w32font_info
*) font
;
394 bzero (metrics
, sizeof (struct font_metrics
));
395 metrics
->ascent
= font
->ascent
;
396 metrics
->descent
= font
->descent
;
398 for (i
= 0; i
< nglyphs
; i
++)
400 struct w32_metric_cache
*char_metric
;
401 int block
= *(code
+ i
) / CACHE_BLOCKSIZE
;
402 int pos_in_block
= *(code
+ i
) % CACHE_BLOCKSIZE
;
404 if (block
>= w32_font
->n_cache_blocks
)
406 if (!w32_font
->cached_metrics
)
407 w32_font
->cached_metrics
408 = xmalloc ((block
+ 1)
409 * sizeof (struct w32_metric_cache
*));
411 w32_font
->cached_metrics
412 = xrealloc (w32_font
->cached_metrics
,
414 * sizeof (struct w32_metric_cache
*));
415 bzero (w32_font
->cached_metrics
+ w32_font
->n_cache_blocks
,
416 ((block
+ 1 - w32_font
->n_cache_blocks
)
417 * sizeof (struct w32_metric_cache
*)));
418 w32_font
->n_cache_blocks
= block
+ 1;
421 if (!w32_font
->cached_metrics
[block
])
423 w32_font
->cached_metrics
[block
]
424 = xmalloc (CACHE_BLOCKSIZE
* sizeof (struct w32_metric_cache
));
425 bzero (w32_font
->cached_metrics
[block
],
426 CACHE_BLOCKSIZE
* sizeof (struct w32_metric_cache
));
429 char_metric
= w32_font
->cached_metrics
[block
] + pos_in_block
;
431 if (char_metric
->status
== W32METRIC_NO_ATTEMPT
)
435 /* TODO: Frames can come and go, and their fonts
436 outlive them. So we can't cache the frame in the
437 font structure. Use selected_frame until the API
438 is updated to pass in a frame. */
439 f
= XFRAME (selected_frame
);
441 dc
= get_frame_dc (f
);
442 old_font
= SelectObject (dc
, w32_font
->hfont
);
444 compute_metrics (dc
, w32_font
, *(code
+ i
), char_metric
);
447 if (char_metric
->status
== W32METRIC_SUCCESS
)
449 metrics
->lbearing
= min (metrics
->lbearing
,
450 metrics
->width
+ char_metric
->lbearing
);
451 metrics
->rbearing
= max (metrics
->rbearing
,
452 metrics
->width
+ char_metric
->rbearing
);
453 metrics
->width
+= char_metric
->width
;
456 /* If we couldn't get metrics for a char,
457 use alternative method. */
460 /* If we got through everything, return. */
465 /* Restore state and release DC. */
466 SelectObject (dc
, old_font
);
467 release_frame_dc (f
, dc
);
470 return metrics
->width
;
474 /* For non-truetype fonts, GetGlyphOutlineW is not supported, so
475 fallback on other methods that will at least give some of the metric
478 /* Make array big enough to hold surrogates. */
479 wcode
= alloca (nglyphs
* sizeof (WORD
) * 2);
480 for (i
= 0; i
< nglyphs
; i
++)
482 if (code
[i
] < 0x10000)
486 DWORD surrogate
= code
[i
] - 0x10000;
488 /* High surrogate: U+D800 - U+DBFF. */
489 wcode
[i
++] = 0xD800 + ((surrogate
>> 10) & 0x03FF);
490 /* Low surrogate: U+DC00 - U+DFFF. */
491 wcode
[i
] = 0xDC00 + (surrogate
& 0x03FF);
492 /* An extra glyph. wcode is already double the size of code to
500 /* TODO: Frames can come and go, and their fonts outlive
501 them. So we can't cache the frame in the font structure. Use
502 selected_frame until the API is updated to pass in a
504 f
= XFRAME (selected_frame
);
506 dc
= get_frame_dc (f
);
507 old_font
= SelectObject (dc
, w32_font
->hfont
);
510 if (GetTextExtentPoint32W (dc
, wcode
, nglyphs
, &size
))
512 total_width
= size
.cx
;
515 /* On 95/98/ME, only some unicode functions are available, so fallback
516 on doing a dummy draw to find the total width. */
520 rect
.top
= 0; rect
.bottom
= font
->height
; rect
.left
= 0; rect
.right
= 1;
521 DrawTextW (dc
, wcode
, nglyphs
, &rect
,
522 DT_CALCRECT
| DT_NOPREFIX
| DT_SINGLELINE
);
523 total_width
= rect
.right
;
526 /* Give our best estimate of the metrics, based on what we know. */
529 metrics
->width
= total_width
- w32_font
->metrics
.tmOverhang
;
530 metrics
->lbearing
= 0;
531 metrics
->rbearing
= total_width
;
534 /* Restore state and release DC. */
535 SelectObject (dc
, old_font
);
536 release_frame_dc (f
, dc
);
541 /* w32 implementation of draw for font backend.
543 Draw glyphs between FROM and TO of S->char2b at (X Y) pixel
544 position of frame F with S->FACE and S->GC. If WITH_BACKGROUND
545 is nonzero, fill the background in advance. It is assured that
546 WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars).
548 TODO: Currently this assumes that the colors and fonts are already
549 set in the DC. This seems to be true now, but maybe only due to
550 the old font code setting it up. It may be safer to resolve faces
551 and fonts in here and set them explicitly
555 w32font_draw (s
, from
, to
, x
, y
, with_background
)
556 struct glyph_string
*s
;
557 int from
, to
, x
, y
, with_background
;
560 HRGN orig_clip
= NULL
;
561 struct w32font_info
*w32font
= (struct w32font_info
*) s
->font
;
563 options
= w32font
->glyph_idx
;
565 if (s
->num_clips
> 0)
567 HRGN new_clip
= CreateRectRgnIndirect (s
->clip
);
569 /* Save clip region for later restoration. */
570 orig_clip
= CreateRectRgn (0, 0, 0, 0);
571 if (!GetClipRgn (s
->hdc
, orig_clip
))
573 DeleteObject (orig_clip
);
577 if (s
->num_clips
> 1)
579 HRGN clip2
= CreateRectRgnIndirect (s
->clip
+ 1);
581 CombineRgn (new_clip
, new_clip
, clip2
, RGN_OR
);
582 DeleteObject (clip2
);
585 SelectClipRgn (s
->hdc
, new_clip
);
586 DeleteObject (new_clip
);
589 /* Using OPAQUE background mode can clear more background than expected
590 when Cleartype is used. Draw the background manually to avoid this. */
591 SetBkMode (s
->hdc
, TRANSPARENT
);
596 struct font
*font
= s
->font
;
598 brush
= CreateSolidBrush (s
->gc
->background
);
600 rect
.top
= y
- font
->ascent
;
601 rect
.right
= x
+ s
->width
;
602 rect
.bottom
= y
+ font
->descent
;
603 FillRect (s
->hdc
, &rect
, brush
);
604 DeleteObject (brush
);
609 int len
= to
- from
, i
;
611 for (i
= 0; i
< len
; i
++)
612 ExtTextOutW (s
->hdc
, x
+ i
, y
, options
, NULL
,
613 s
->char2b
+ from
+ i
, 1, NULL
);
616 ExtTextOutW (s
->hdc
, x
, y
, options
, NULL
, s
->char2b
+ from
, to
- from
, NULL
);
618 /* Restore clip region. */
619 if (s
->num_clips
> 0)
620 SelectClipRgn (s
->hdc
, orig_clip
);
623 DeleteObject (orig_clip
);
626 /* w32 implementation of free_entity for font backend.
627 Optional (if FONT_EXTRA_INDEX is not Lisp_Save_Value).
628 Free FONT_EXTRA_INDEX field of FONT_ENTITY.
630 w32font_free_entity (Lisp_Object entity);
633 /* w32 implementation of prepare_face for font backend.
634 Optional (if FACE->extra is not used).
635 Prepare FACE for displaying characters by FONT on frame F by
636 storing some data in FACE->extra. If successful, return 0.
637 Otherwise, return -1.
639 w32font_prepare_face (FRAME_PTR f, struct face *face);
641 /* w32 implementation of done_face for font backend.
643 Done FACE for displaying characters by FACE->font on frame F.
645 w32font_done_face (FRAME_PTR f, struct face *face); */
647 /* w32 implementation of get_bitmap for font backend.
649 Store bitmap data for glyph-code CODE of FONT in BITMAP. It is
650 intended that this method is called from the other font-driver
653 w32font_get_bitmap (struct font *font, unsigned code,
654 struct font_bitmap *bitmap, int bits_per_pixel);
656 /* w32 implementation of free_bitmap for font backend.
658 Free bitmap data in BITMAP.
660 w32font_free_bitmap (struct font *font, struct font_bitmap *bitmap);
662 /* w32 implementation of get_outline for font backend.
664 Return an outline data for glyph-code CODE of FONT. The format
665 of the outline data depends on the font-driver.
667 w32font_get_outline (struct font *font, unsigned code);
669 /* w32 implementation of free_outline for font backend.
671 Free OUTLINE (that is obtained by the above method).
673 w32font_free_outline (struct font *font, void *outline);
675 /* w32 implementation of anchor_point for font backend.
677 Get coordinates of the INDEXth anchor point of the glyph whose
678 code is CODE. Store the coordinates in *X and *Y. Return 0 if
679 the operations was successfull. Otherwise return -1.
681 w32font_anchor_point (struct font *font, unsigned code,
682 int index, int *x, int *y);
684 /* w32 implementation of otf_capability for font backend.
686 Return a list describing which scripts/languages FONT
687 supports by which GSUB/GPOS features of OpenType tables.
689 w32font_otf_capability (struct font *font);
691 /* w32 implementation of otf_drive for font backend.
693 Apply FONT's OTF-FEATURES to the glyph string.
695 FEATURES specifies which OTF features to apply in this format:
696 (SCRIPT LANGSYS GSUB-FEATURE GPOS-FEATURE)
697 See the documentation of `font-drive-otf' for the detail.
699 This method applies the specified features to the codes in the
700 elements of GSTRING-IN (between FROMth and TOth). The output
701 codes are stored in GSTRING-OUT at the IDXth element and the
704 Return the number of output codes. If none of the features are
705 applicable to the input data, return 0. If GSTRING-OUT is too
708 w32font_otf_drive (struct font *font, Lisp_Object features,
709 Lisp_Object gstring_in, int from, int to,
710 Lisp_Object gstring_out, int idx,
711 int alternate_subst);
714 /* Internal implementation of w32font_list.
715 Additional parameter opentype_only restricts the returned fonts to
716 opentype fonts, which can be used with the Uniscribe backend. */
718 w32font_list_internal (frame
, font_spec
, opentype_only
)
719 Lisp_Object frame
, font_spec
;
722 struct font_callback_data match_data
;
724 FRAME_PTR f
= XFRAME (frame
);
726 match_data
.orig_font_spec
= font_spec
;
727 match_data
.list
= Qnil
;
728 match_data
.frame
= frame
;
730 bzero (&match_data
.pattern
, sizeof (LOGFONT
));
731 fill_in_logfont (f
, &match_data
.pattern
, font_spec
);
733 /* If the charset is unrecognized, then we won't find a font, so don't
734 waste time looking for one. */
735 if (match_data
.pattern
.lfCharSet
== DEFAULT_CHARSET
)
737 Lisp_Object spec_charset
= AREF (font_spec
, FONT_REGISTRY_INDEX
);
738 if (!NILP (spec_charset
)
739 && !EQ (spec_charset
, Qiso10646_1
)
740 && !EQ (spec_charset
, Qunicode_bmp
)
741 && !EQ (spec_charset
, Qunicode_sip
)
742 && !EQ (spec_charset
, Qunknown
))
746 match_data
.opentype_only
= opentype_only
;
748 match_data
.pattern
.lfOutPrecision
= OUT_OUTLINE_PRECIS
;
750 if (match_data
.pattern
.lfFaceName
[0] == '\0')
752 /* EnumFontFamiliesEx does not take other fields into account if
753 font name is blank, so need to use two passes. */
754 list_all_matching_fonts (&match_data
);
758 dc
= get_frame_dc (f
);
760 EnumFontFamiliesEx (dc
, &match_data
.pattern
,
761 (FONTENUMPROC
) add_font_entity_to_list
,
762 (LPARAM
) &match_data
, 0);
763 release_frame_dc (f
, dc
);
766 return match_data
.list
;
769 /* Internal implementation of w32font_match.
770 Additional parameter opentype_only restricts the returned fonts to
771 opentype fonts, which can be used with the Uniscribe backend. */
773 w32font_match_internal (frame
, font_spec
, opentype_only
)
774 Lisp_Object frame
, font_spec
;
777 struct font_callback_data match_data
;
779 FRAME_PTR f
= XFRAME (frame
);
781 match_data
.orig_font_spec
= font_spec
;
782 match_data
.frame
= frame
;
783 match_data
.list
= Qnil
;
785 bzero (&match_data
.pattern
, sizeof (LOGFONT
));
786 fill_in_logfont (f
, &match_data
.pattern
, font_spec
);
788 match_data
.opentype_only
= opentype_only
;
790 match_data
.pattern
.lfOutPrecision
= OUT_OUTLINE_PRECIS
;
792 dc
= get_frame_dc (f
);
794 EnumFontFamiliesEx (dc
, &match_data
.pattern
,
795 (FONTENUMPROC
) add_one_font_entity_to_list
,
796 (LPARAM
) &match_data
, 0);
797 release_frame_dc (f
, dc
);
799 return NILP (match_data
.list
) ? Qnil
: XCAR (match_data
.list
);
803 w32font_open_internal (f
, font_entity
, pixel_size
, font_object
)
805 Lisp_Object font_entity
;
807 Lisp_Object font_object
;
812 HFONT hfont
, old_font
;
813 Lisp_Object val
, extra
;
814 struct w32font_info
*w32_font
;
816 OUTLINETEXTMETRICW
* metrics
= NULL
;
818 w32_font
= (struct w32font_info
*) XFONT_OBJECT (font_object
);
819 font
= (struct font
*) w32_font
;
824 bzero (&logfont
, sizeof (logfont
));
825 fill_in_logfont (f
, &logfont
, font_entity
);
827 /* Prefer truetype fonts, to avoid known problems with type1 fonts, and
828 limitations in bitmap fonts. */
829 val
= AREF (font_entity
, FONT_FOUNDRY_INDEX
);
830 if (!EQ (val
, Qraster
))
831 logfont
.lfOutPrecision
= OUT_TT_PRECIS
;
833 size
= XINT (AREF (font_entity
, FONT_SIZE_INDEX
));
837 logfont
.lfHeight
= -size
;
838 hfont
= CreateFontIndirect (&logfont
);
843 /* Get the metrics for this font. */
844 dc
= get_frame_dc (f
);
845 old_font
= SelectObject (dc
, hfont
);
847 /* Try getting the outline metrics (only works for truetype fonts). */
848 len
= GetOutlineTextMetricsW (dc
, 0, NULL
);
851 metrics
= (OUTLINETEXTMETRICW
*) alloca (len
);
852 if (GetOutlineTextMetricsW (dc
, len
, metrics
))
853 bcopy (&metrics
->otmTextMetrics
, &w32_font
->metrics
,
854 sizeof (TEXTMETRICW
));
860 GetTextMetricsW (dc
, &w32_font
->metrics
);
862 w32_font
->cached_metrics
= NULL
;
863 w32_font
->n_cache_blocks
= 0;
865 SelectObject (dc
, old_font
);
866 release_frame_dc (f
, dc
);
868 w32_font
->hfont
= hfont
;
873 /* We don't know how much space we need for the full name, so start with
874 96 bytes and go up in steps of 32. */
877 while (name
&& w32font_full_name (&logfont
, font_entity
, pixel_size
,
884 font
->props
[FONT_FULLNAME_INDEX
]
885 = DECODE_SYSTEM (build_string (name
));
887 font
->props
[FONT_FULLNAME_INDEX
]
888 = DECODE_SYSTEM (build_string (logfont
.lfFaceName
));
891 font
->max_width
= w32_font
->metrics
.tmMaxCharWidth
;
892 /* Parts of Emacs display assume that height = ascent + descent...
893 so height is defined later, after ascent and descent.
894 font->height = w32_font->metrics.tmHeight
895 + w32_font->metrics.tmExternalLeading;
898 font
->space_width
= font
->average_width
= w32_font
->metrics
.tmAveCharWidth
;
900 font
->vertical_centering
= 0;
901 font
->encoding_type
= 0;
902 font
->baseline_offset
= 0;
903 font
->relative_compose
= 0;
904 font
->default_ascent
= w32_font
->metrics
.tmAscent
;
905 font
->font_encoder
= NULL
;
906 font
->pixel_size
= size
;
907 font
->driver
= &w32font_driver
;
908 /* Use format cached during list, as the information we have access to
909 here is incomplete. */
910 extra
= AREF (font_entity
, FONT_EXTRA_INDEX
);
913 val
= assq_no_quit (QCformat
, extra
);
915 font
->props
[FONT_FORMAT_INDEX
] = XCDR (val
);
917 font
->props
[FONT_FORMAT_INDEX
] = Qunknown
;
920 font
->props
[FONT_FORMAT_INDEX
] = Qunknown
;
922 font
->props
[FONT_FILE_INDEX
] = Qnil
;
923 font
->encoding_charset
= -1;
924 font
->repertory_charset
= -1;
925 /* TODO: do we really want the minimum width here, which could be negative? */
926 font
->min_width
= font
->space_width
;
927 font
->ascent
= w32_font
->metrics
.tmAscent
;
928 font
->descent
= w32_font
->metrics
.tmDescent
;
929 font
->height
= font
->ascent
+ font
->descent
;
933 font
->underline_thickness
= metrics
->otmsUnderscoreSize
;
934 font
->underline_position
= -metrics
->otmsUnderscorePosition
;
938 font
->underline_thickness
= 0;
939 font
->underline_position
= -1;
942 /* For temporary compatibility with legacy code that expects the
943 name to be usable in x-list-fonts. Eventually we expect to change
944 x-list-fonts and other places that use fonts so that this can be
945 an fcname or similar. */
946 font
->props
[FONT_NAME_INDEX
] = Ffont_xlfd_name (font_object
, Qnil
);
951 /* Callback function for EnumFontFamiliesEx.
952 * Adds the name of a font to a Lisp list (passed in as the lParam arg). */
954 add_font_name_to_list (logical_font
, physical_font
, font_type
, list_object
)
955 ENUMLOGFONTEX
*logical_font
;
956 NEWTEXTMETRICEX
*physical_font
;
960 Lisp_Object
* list
= (Lisp_Object
*) list_object
;
963 /* Skip vertical fonts (intended only for printing) */
964 if (logical_font
->elfLogFont
.lfFaceName
[0] == '@')
967 family
= intern_font_name (logical_font
->elfLogFont
.lfFaceName
);
968 if (! memq_no_quit (family
, *list
))
969 *list
= Fcons (family
, *list
);
974 static int w32_decode_weight
P_ ((int));
975 static int w32_encode_weight
P_ ((int));
977 /* Convert an enumerated Windows font to an Emacs font entity. */
979 w32_enumfont_pattern_entity (frame
, logical_font
, physical_font
,
980 font_type
, requested_font
, backend
)
982 ENUMLOGFONTEX
*logical_font
;
983 NEWTEXTMETRICEX
*physical_font
;
985 LOGFONT
*requested_font
;
988 Lisp_Object entity
, tem
;
989 LOGFONT
*lf
= (LOGFONT
*) logical_font
;
991 DWORD full_type
= physical_font
->ntmTm
.ntmFlags
;
993 entity
= font_make_entity ();
995 ASET (entity
, FONT_TYPE_INDEX
, backend
);
996 ASET (entity
, FONT_REGISTRY_INDEX
, w32_registry (lf
->lfCharSet
, font_type
));
997 ASET (entity
, FONT_OBJLIST_INDEX
, Qnil
);
999 /* Foundry is difficult to get in readable form on Windows.
1000 But Emacs crashes if it is not set, so set it to something more
1001 generic. These values make xlfds compatible with Emacs 22. */
1002 if (lf
->lfOutPrecision
== OUT_STRING_PRECIS
)
1004 else if (lf
->lfOutPrecision
== OUT_STROKE_PRECIS
)
1009 ASET (entity
, FONT_FOUNDRY_INDEX
, tem
);
1011 /* Save the generic family in the extra info, as it is likely to be
1012 useful to users looking for a close match. */
1013 generic_type
= physical_font
->ntmTm
.tmPitchAndFamily
& 0xF0;
1014 if (generic_type
== FF_DECORATIVE
)
1016 else if (generic_type
== FF_MODERN
)
1018 else if (generic_type
== FF_ROMAN
)
1020 else if (generic_type
== FF_SCRIPT
)
1022 else if (generic_type
== FF_SWISS
)
1027 ASET (entity
, FONT_ADSTYLE_INDEX
, tem
);
1029 if (physical_font
->ntmTm
.tmPitchAndFamily
& 0x01)
1030 ASET (entity
, FONT_SPACING_INDEX
, make_number (FONT_SPACING_PROPORTIONAL
));
1032 ASET (entity
, FONT_SPACING_INDEX
, make_number (FONT_SPACING_CHARCELL
));
1034 if (requested_font
->lfQuality
!= DEFAULT_QUALITY
)
1036 font_put_extra (entity
, QCantialias
,
1037 lispy_antialias_type (requested_font
->lfQuality
));
1039 ASET (entity
, FONT_FAMILY_INDEX
,
1040 intern_font_name (lf
->lfFaceName
));
1042 FONT_SET_STYLE (entity
, FONT_WEIGHT_INDEX
,
1043 make_number (w32_decode_weight (lf
->lfWeight
)));
1044 FONT_SET_STYLE (entity
, FONT_SLANT_INDEX
,
1045 make_number (lf
->lfItalic
? 200 : 100));
1046 /* TODO: PANOSE struct has this info, but need to call GetOutlineTextMetrics
1048 FONT_SET_STYLE (entity
, FONT_WIDTH_INDEX
, make_number (100));
1050 if (font_type
& RASTER_FONTTYPE
)
1051 ASET (entity
, FONT_SIZE_INDEX
,
1052 make_number (physical_font
->ntmTm
.tmHeight
1053 + physical_font
->ntmTm
.tmExternalLeading
));
1055 ASET (entity
, FONT_SIZE_INDEX
, make_number (0));
1057 /* Cache unicode codepoints covered by this font, as there is no other way
1058 of getting this information easily. */
1059 if (font_type
& TRUETYPE_FONTTYPE
)
1061 tem
= font_supported_scripts (&physical_font
->ntmFontSig
);
1063 font_put_extra (entity
, QCscript
, tem
);
1066 /* This information is not fully available when opening fonts, so
1067 save it here. Only Windows 2000 and later return information
1068 about opentype and type1 fonts, so need a fallback for detecting
1069 truetype so that this information is not any worse than we could
1070 have obtained later. */
1071 if (EQ (backend
, Quniscribe
) && (full_type
& NTMFLAGS_OPENTYPE
))
1072 tem
= intern ("opentype");
1073 else if (font_type
& TRUETYPE_FONTTYPE
)
1074 tem
= intern ("truetype");
1075 else if (full_type
& NTM_PS_OPENTYPE
)
1076 tem
= intern ("postscript");
1077 else if (full_type
& NTM_TYPE1
)
1078 tem
= intern ("type1");
1079 else if (font_type
& RASTER_FONTTYPE
)
1080 tem
= intern ("w32bitmap");
1082 tem
= intern ("w32vector");
1084 font_put_extra (entity
, QCformat
, tem
);
1090 /* Convert generic families to the family portion of lfPitchAndFamily. */
1092 w32_generic_family (Lisp_Object name
)
1094 /* Generic families. */
1095 if (EQ (name
, Qmonospace
) || EQ (name
, Qmono
))
1097 else if (EQ (name
, Qsans
) || EQ (name
, Qsans_serif
) || EQ (name
, Qsansserif
))
1099 else if (EQ (name
, Qserif
))
1101 else if (EQ (name
, Qdecorative
))
1102 return FF_DECORATIVE
;
1103 else if (EQ (name
, Qscript
))
1110 logfonts_match (font
, pattern
)
1111 LOGFONT
*font
, *pattern
;
1113 /* Only check height for raster fonts. */
1114 if (pattern
->lfHeight
&& font
->lfOutPrecision
== OUT_STRING_PRECIS
1115 && font
->lfHeight
!= pattern
->lfHeight
)
1118 /* Have some flexibility with weights. */
1119 if (pattern
->lfWeight
1120 && ((font
->lfWeight
< (pattern
->lfWeight
- 150))
1121 || font
->lfWeight
> (pattern
->lfWeight
+ 150)))
1124 /* Charset and face should be OK. Italic has to be checked
1125 against the original spec, in case we don't have any preference. */
1129 /* Codepage Bitfields in FONTSIGNATURE struct. */
1130 #define CSB_JAPANESE (1 << 17)
1131 #define CSB_KOREAN ((1 << 19) | (1 << 21))
1132 #define CSB_CHINESE ((1 << 18) | (1 << 20))
1135 font_matches_spec (type
, font
, spec
, backend
, logfont
)
1137 NEWTEXTMETRICEX
*font
;
1139 Lisp_Object backend
;
1142 Lisp_Object extra
, val
;
1144 /* Check italic. Can't check logfonts, since it is a boolean field,
1145 so there is no difference between "non-italic" and "don't care". */
1147 int slant
= FONT_SLANT_NUMERIC (spec
);
1150 && ((slant
> 150 && !font
->ntmTm
.tmItalic
)
1151 || (slant
<= 150 && font
->ntmTm
.tmItalic
)))
1155 /* Check adstyle against generic family. */
1156 val
= AREF (spec
, FONT_ADSTYLE_INDEX
);
1159 BYTE family
= w32_generic_family (val
);
1160 if (family
!= FF_DONTCARE
1161 && family
!= (font
->ntmTm
.tmPitchAndFamily
& 0xF0))
1166 val
= AREF (spec
, FONT_SPACING_INDEX
);
1169 int spacing
= XINT (val
);
1170 int proportional
= (spacing
< FONT_SPACING_MONO
);
1172 if ((proportional
&& !(font
->ntmTm
.tmPitchAndFamily
& 0x01))
1173 || (!proportional
&& (font
->ntmTm
.tmPitchAndFamily
& 0x01)))
1177 /* Check extra parameters. */
1178 for (extra
= AREF (spec
, FONT_EXTRA_INDEX
);
1179 CONSP (extra
); extra
= XCDR (extra
))
1181 Lisp_Object extra_entry
;
1182 extra_entry
= XCAR (extra
);
1183 if (CONSP (extra_entry
))
1185 Lisp_Object key
= XCAR (extra_entry
);
1187 val
= XCDR (extra_entry
);
1188 if (EQ (key
, QCscript
) && SYMBOLP (val
))
1190 /* Only truetype fonts will have information about what
1191 scripts they support. This probably means the user
1192 will have to force Emacs to use raster, postscript
1193 or atm fonts for non-ASCII text. */
1194 if (type
& TRUETYPE_FONTTYPE
)
1197 = font_supported_scripts (&font
->ntmFontSig
);
1198 if (! memq_no_quit (val
, support
))
1203 /* Return specific matches, but play it safe. Fonts
1204 that cover more than their charset would suggest
1205 are likely to be truetype or opentype fonts,
1207 if (EQ (val
, Qlatin
))
1209 /* Although every charset but symbol, thai and
1210 arabic contains the basic ASCII set of latin
1211 characters, Emacs expects much more. */
1212 if (font
->ntmTm
.tmCharSet
!= ANSI_CHARSET
)
1215 else if (EQ (val
, Qsymbol
))
1217 if (font
->ntmTm
.tmCharSet
!= SYMBOL_CHARSET
)
1220 else if (EQ (val
, Qcyrillic
))
1222 if (font
->ntmTm
.tmCharSet
!= RUSSIAN_CHARSET
)
1225 else if (EQ (val
, Qgreek
))
1227 if (font
->ntmTm
.tmCharSet
!= GREEK_CHARSET
)
1230 else if (EQ (val
, Qarabic
))
1232 if (font
->ntmTm
.tmCharSet
!= ARABIC_CHARSET
)
1235 else if (EQ (val
, Qhebrew
))
1237 if (font
->ntmTm
.tmCharSet
!= HEBREW_CHARSET
)
1240 else if (EQ (val
, Qthai
))
1242 if (font
->ntmTm
.tmCharSet
!= THAI_CHARSET
)
1245 else if (EQ (val
, Qkana
))
1247 if (font
->ntmTm
.tmCharSet
!= SHIFTJIS_CHARSET
)
1250 else if (EQ (val
, Qbopomofo
))
1252 if (font
->ntmTm
.tmCharSet
!= CHINESEBIG5_CHARSET
)
1255 else if (EQ (val
, Qhangul
))
1257 if (font
->ntmTm
.tmCharSet
!= HANGUL_CHARSET
1258 && font
->ntmTm
.tmCharSet
!= JOHAB_CHARSET
)
1261 else if (EQ (val
, Qhan
))
1263 if (font
->ntmTm
.tmCharSet
!= CHINESEBIG5_CHARSET
1264 && font
->ntmTm
.tmCharSet
!= GB2312_CHARSET
1265 && font
->ntmTm
.tmCharSet
!= HANGUL_CHARSET
1266 && font
->ntmTm
.tmCharSet
!= JOHAB_CHARSET
1267 && font
->ntmTm
.tmCharSet
!= SHIFTJIS_CHARSET
)
1271 /* Other scripts unlikely to be handled by non-truetype
1276 else if (EQ (key
, QClang
) && SYMBOLP (val
))
1278 /* Just handle the CJK languages here, as the lang
1279 parameter is used to select a font with appropriate
1280 glyphs in the cjk unified ideographs block. Other fonts
1281 support for a language can be solely determined by
1282 its character coverage. */
1285 if (!(font
->ntmFontSig
.fsCsb
[0] & CSB_JAPANESE
))
1288 else if (EQ (val
, Qko
))
1290 if (!(font
->ntmFontSig
.fsCsb
[0] & CSB_KOREAN
))
1293 else if (EQ (val
, Qzh
))
1295 if (!(font
->ntmFontSig
.fsCsb
[0] & CSB_CHINESE
))
1299 /* Any other language, we don't recognize it. Only the above
1300 currently appear in fontset.el, so it isn't worth
1301 creating a mapping table of codepages/scripts to languages
1302 or opening the font to see if there are any language tags
1303 in it that the W32 API does not expose. Fontset
1304 spec should have a fallback, as some backends do
1305 not recognize language at all. */
1308 else if (EQ (key
, QCotf
) && CONSP (val
))
1310 /* OTF features only supported by the uniscribe backend. */
1311 if (EQ (backend
, Quniscribe
))
1313 if (!uniscribe_check_otf (logfont
, val
))
1325 w32font_coverage_ok (coverage
, charset
)
1326 FONTSIGNATURE
* coverage
;
1329 DWORD subrange1
= coverage
->fsUsb
[1];
1331 #define SUBRANGE1_HAN_MASK 0x08000000
1332 #define SUBRANGE1_HANGEUL_MASK 0x01000000
1333 #define SUBRANGE1_JAPANESE_MASK (0x00060000 | SUBRANGE1_HAN_MASK)
1335 if (charset
== GB2312_CHARSET
|| charset
== CHINESEBIG5_CHARSET
)
1337 return (subrange1
& SUBRANGE1_HAN_MASK
) == SUBRANGE1_HAN_MASK
;
1339 else if (charset
== SHIFTJIS_CHARSET
)
1341 return (subrange1
& SUBRANGE1_JAPANESE_MASK
) == SUBRANGE1_JAPANESE_MASK
;
1343 else if (charset
== HANGEUL_CHARSET
)
1345 return (subrange1
& SUBRANGE1_HANGEUL_MASK
) == SUBRANGE1_HANGEUL_MASK
;
1353 check_face_name (font
, full_name
)
1357 char full_iname
[LF_FULLFACESIZE
+1];
1359 /* Just check for names known to cause problems, since the full name
1360 can contain expanded abbreviations, prefixed foundry, postfixed
1361 style, the latter of which sometimes differs from the style indicated
1362 in the shorter name (eg Lt becomes Light or even Extra Light) */
1364 /* Helvetica is mapped to Arial in Windows, but if a Type-1 Helvetica is
1365 installed, we run into problems with the Uniscribe backend which tries
1366 to avoid non-truetype fonts, and ends up mixing the Type-1 Helvetica
1367 with Arial's characteristics, since that attempt to use Truetype works
1368 some places, but not others. */
1369 if (!xstrcasecmp (font
->lfFaceName
, "helvetica"))
1371 strncpy (full_iname
, full_name
, LF_FULLFACESIZE
);
1372 full_iname
[LF_FULLFACESIZE
] = 0;
1373 _strlwr (full_iname
);
1374 return strstr ("helvetica", full_iname
) != NULL
;
1376 /* Same for Helv. */
1377 if (!xstrcasecmp (font
->lfFaceName
, "helv"))
1379 strncpy (full_iname
, full_name
, LF_FULLFACESIZE
);
1380 full_iname
[LF_FULLFACESIZE
] = 0;
1381 _strlwr (full_iname
);
1382 return strstr ("helv", full_iname
) != NULL
;
1385 /* Since Times is mapped to Times New Roman, a substring
1386 match is not sufficient to filter out the bogus match. */
1387 else if (!xstrcasecmp (font
->lfFaceName
, "times"))
1388 return xstrcasecmp (full_name
, "times") == 0;
1394 /* Callback function for EnumFontFamiliesEx.
1395 * Checks if a font matches everything we are trying to check agaist,
1396 * and if so, adds it to a list. Both the data we are checking against
1397 * and the list to which the fonts are added are passed in via the
1398 * lparam argument, in the form of a font_callback_data struct. */
1400 add_font_entity_to_list (logical_font
, physical_font
, font_type
, lParam
)
1401 ENUMLOGFONTEX
*logical_font
;
1402 NEWTEXTMETRICEX
*physical_font
;
1406 struct font_callback_data
*match_data
1407 = (struct font_callback_data
*) lParam
;
1408 Lisp_Object backend
= match_data
->opentype_only
? Quniscribe
: Qgdi
;
1411 int is_unicode
= physical_font
->ntmFontSig
.fsUsb
[3]
1412 || physical_font
->ntmFontSig
.fsUsb
[2]
1413 || physical_font
->ntmFontSig
.fsUsb
[1]
1414 || physical_font
->ntmFontSig
.fsUsb
[0] & 0x3fffffff;
1416 /* Skip non matching fonts. */
1418 /* For uniscribe backend, consider only truetype or opentype fonts
1419 that have some unicode coverage. */
1420 if (match_data
->opentype_only
1421 && ((!physical_font
->ntmTm
.ntmFlags
& NTMFLAGS_OPENTYPE
1422 && !(font_type
& TRUETYPE_FONTTYPE
))
1426 /* Ensure a match. */
1427 if (!logfonts_match (&logical_font
->elfLogFont
, &match_data
->pattern
)
1428 || !font_matches_spec (font_type
, physical_font
,
1429 match_data
->orig_font_spec
, backend
,
1430 &logical_font
->elfLogFont
)
1431 || !w32font_coverage_ok (&physical_font
->ntmFontSig
,
1432 match_data
->pattern
.lfCharSet
))
1435 /* Avoid substitutions involving raster fonts (eg Helv -> MS Sans Serif)
1436 We limit this to raster fonts, because the test can catch some
1437 genuine fonts (eg the full name of DejaVu Sans Mono Light is actually
1438 DejaVu Sans Mono ExtraLight). Helvetica -> Arial substitution will
1439 therefore get through this test. Since full names can be prefixed
1440 by a foundry, we accept raster fonts if the font name is found
1441 anywhere within the full name. */
1442 if ((logical_font
->elfLogFont
.lfOutPrecision
== OUT_STRING_PRECIS
1443 && !strstr (logical_font
->elfFullName
,
1444 logical_font
->elfLogFont
.lfFaceName
))
1445 /* Check for well known substitutions that mess things up in the
1446 presence of Type-1 fonts of the same name. */
1447 || (!check_face_name (&logical_font
->elfLogFont
,
1448 logical_font
->elfFullName
)))
1451 /* Make a font entity for the font. */
1452 entity
= w32_enumfont_pattern_entity (match_data
->frame
, logical_font
,
1453 physical_font
, font_type
,
1454 &match_data
->pattern
,
1459 Lisp_Object spec_charset
= AREF (match_data
->orig_font_spec
,
1460 FONT_REGISTRY_INDEX
);
1462 /* iso10646-1 fonts must contain unicode mapping tables. */
1463 if (EQ (spec_charset
, Qiso10646_1
))
1468 /* unicode-bmp fonts must contain characters from the BMP. */
1469 else if (EQ (spec_charset
, Qunicode_bmp
))
1471 if (!physical_font
->ntmFontSig
.fsUsb
[3]
1472 && !(physical_font
->ntmFontSig
.fsUsb
[2] & 0xFFFFFF9E)
1473 && !(physical_font
->ntmFontSig
.fsUsb
[1] & 0xE81FFFFF)
1474 && !(physical_font
->ntmFontSig
.fsUsb
[0] & 0x007F001F))
1477 /* unicode-sip fonts must contain characters in unicode plane 2.
1478 so look for bit 57 (surrogates) in the Unicode subranges, plus
1479 the bits for CJK ranges that include those characters. */
1480 else if (EQ (spec_charset
, Qunicode_sip
))
1482 if (!physical_font
->ntmFontSig
.fsUsb
[1] & 0x02000000
1483 || !physical_font
->ntmFontSig
.fsUsb
[1] & 0x28000000)
1487 /* This font matches. */
1489 /* If registry was specified, ensure it is reported as the same. */
1490 if (!NILP (spec_charset
))
1491 ASET (entity
, FONT_REGISTRY_INDEX
, spec_charset
);
1493 /* Otherwise if using the uniscribe backend, report ANSI and DEFAULT
1494 fonts as unicode and skip other charsets. */
1495 else if (match_data
->opentype_only
)
1497 if (logical_font
->elfLogFont
.lfCharSet
== ANSI_CHARSET
1498 || logical_font
->elfLogFont
.lfCharSet
== DEFAULT_CHARSET
)
1499 ASET (entity
, FONT_REGISTRY_INDEX
, Qiso10646_1
);
1504 /* Add this font to the list. */
1505 match_data
->list
= Fcons (entity
, match_data
->list
);
1510 /* Callback function for EnumFontFamiliesEx.
1511 * Terminates the search once we have a match. */
1513 add_one_font_entity_to_list (logical_font
, physical_font
, font_type
, lParam
)
1514 ENUMLOGFONTEX
*logical_font
;
1515 NEWTEXTMETRICEX
*physical_font
;
1519 struct font_callback_data
*match_data
1520 = (struct font_callback_data
*) lParam
;
1521 add_font_entity_to_list (logical_font
, physical_font
, font_type
, lParam
);
1523 /* If we have a font in the list, terminate the search. */
1524 return NILP (match_data
->list
);
1527 /* Old function to convert from x to w32 charset, from w32fns.c. */
1529 x_to_w32_charset (lpcs
)
1532 Lisp_Object this_entry
, w32_charset
;
1534 int len
= strlen (lpcs
);
1536 /* Support "*-#nnn" format for unknown charsets. */
1537 if (strncmp (lpcs
, "*-#", 3) == 0)
1538 return atoi (lpcs
+ 3);
1540 /* All Windows fonts qualify as unicode. */
1541 if (!strncmp (lpcs
, "iso10646", 8))
1542 return DEFAULT_CHARSET
;
1544 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
1545 charset
= alloca (len
+ 1);
1546 strcpy (charset
, lpcs
);
1547 lpcs
= strchr (charset
, '*');
1551 /* Look through w32-charset-info-alist for the character set.
1552 Format of each entry is
1553 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
1555 this_entry
= Fassoc (build_string (charset
), Vw32_charset_info_alist
);
1557 if (NILP (this_entry
))
1559 /* At startup, we want iso8859-1 fonts to come up properly. */
1560 if (xstrcasecmp (charset
, "iso8859-1") == 0)
1561 return ANSI_CHARSET
;
1563 return DEFAULT_CHARSET
;
1566 w32_charset
= Fcar (Fcdr (this_entry
));
1568 /* Translate Lisp symbol to number. */
1569 if (EQ (w32_charset
, Qw32_charset_ansi
))
1570 return ANSI_CHARSET
;
1571 if (EQ (w32_charset
, Qw32_charset_symbol
))
1572 return SYMBOL_CHARSET
;
1573 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
1574 return SHIFTJIS_CHARSET
;
1575 if (EQ (w32_charset
, Qw32_charset_hangeul
))
1576 return HANGEUL_CHARSET
;
1577 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
1578 return CHINESEBIG5_CHARSET
;
1579 if (EQ (w32_charset
, Qw32_charset_gb2312
))
1580 return GB2312_CHARSET
;
1581 if (EQ (w32_charset
, Qw32_charset_oem
))
1583 if (EQ (w32_charset
, Qw32_charset_johab
))
1584 return JOHAB_CHARSET
;
1585 if (EQ (w32_charset
, Qw32_charset_easteurope
))
1586 return EASTEUROPE_CHARSET
;
1587 if (EQ (w32_charset
, Qw32_charset_turkish
))
1588 return TURKISH_CHARSET
;
1589 if (EQ (w32_charset
, Qw32_charset_baltic
))
1590 return BALTIC_CHARSET
;
1591 if (EQ (w32_charset
, Qw32_charset_russian
))
1592 return RUSSIAN_CHARSET
;
1593 if (EQ (w32_charset
, Qw32_charset_arabic
))
1594 return ARABIC_CHARSET
;
1595 if (EQ (w32_charset
, Qw32_charset_greek
))
1596 return GREEK_CHARSET
;
1597 if (EQ (w32_charset
, Qw32_charset_hebrew
))
1598 return HEBREW_CHARSET
;
1599 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
1600 return VIETNAMESE_CHARSET
;
1601 if (EQ (w32_charset
, Qw32_charset_thai
))
1602 return THAI_CHARSET
;
1603 if (EQ (w32_charset
, Qw32_charset_mac
))
1606 return DEFAULT_CHARSET
;
1610 /* Convert a Lisp font registry (symbol) to a windows charset. */
1612 registry_to_w32_charset (charset
)
1613 Lisp_Object charset
;
1615 if (EQ (charset
, Qiso10646_1
) || EQ (charset
, Qunicode_bmp
)
1616 || EQ (charset
, Qunicode_sip
))
1617 return DEFAULT_CHARSET
; /* UNICODE_CHARSET not defined in MingW32 */
1618 else if (EQ (charset
, Qiso8859_1
))
1619 return ANSI_CHARSET
;
1620 else if (SYMBOLP (charset
))
1621 return x_to_w32_charset (SDATA (SYMBOL_NAME (charset
)));
1623 return DEFAULT_CHARSET
;
1626 /* Old function to convert from w32 to x charset, from w32fns.c. */
1628 w32_to_x_charset (fncharset
, matching
)
1632 static char buf
[32];
1633 Lisp_Object charset_type
;
1638 /* If fully specified, accept it as it is. Otherwise use a
1640 char *wildcard
= strchr (matching
, '*');
1643 else if (strchr (matching
, '-'))
1646 match_len
= strlen (matching
);
1652 /* Handle startup case of w32-charset-info-alist not
1653 being set up yet. */
1654 if (NILP (Vw32_charset_info_alist
))
1656 charset_type
= Qw32_charset_ansi
;
1658 case DEFAULT_CHARSET
:
1659 charset_type
= Qw32_charset_default
;
1661 case SYMBOL_CHARSET
:
1662 charset_type
= Qw32_charset_symbol
;
1664 case SHIFTJIS_CHARSET
:
1665 charset_type
= Qw32_charset_shiftjis
;
1667 case HANGEUL_CHARSET
:
1668 charset_type
= Qw32_charset_hangeul
;
1670 case GB2312_CHARSET
:
1671 charset_type
= Qw32_charset_gb2312
;
1673 case CHINESEBIG5_CHARSET
:
1674 charset_type
= Qw32_charset_chinesebig5
;
1677 charset_type
= Qw32_charset_oem
;
1679 case EASTEUROPE_CHARSET
:
1680 charset_type
= Qw32_charset_easteurope
;
1682 case TURKISH_CHARSET
:
1683 charset_type
= Qw32_charset_turkish
;
1685 case BALTIC_CHARSET
:
1686 charset_type
= Qw32_charset_baltic
;
1688 case RUSSIAN_CHARSET
:
1689 charset_type
= Qw32_charset_russian
;
1691 case ARABIC_CHARSET
:
1692 charset_type
= Qw32_charset_arabic
;
1695 charset_type
= Qw32_charset_greek
;
1697 case HEBREW_CHARSET
:
1698 charset_type
= Qw32_charset_hebrew
;
1700 case VIETNAMESE_CHARSET
:
1701 charset_type
= Qw32_charset_vietnamese
;
1704 charset_type
= Qw32_charset_thai
;
1707 charset_type
= Qw32_charset_mac
;
1710 charset_type
= Qw32_charset_johab
;
1714 /* Encode numerical value of unknown charset. */
1715 sprintf (buf
, "*-#%u", fncharset
);
1721 char * best_match
= NULL
;
1722 int matching_found
= 0;
1724 /* Look through w32-charset-info-alist for the character set.
1725 Prefer ISO codepages, and prefer lower numbers in the ISO
1726 range. Only return charsets for codepages which are installed.
1728 Format of each entry is
1729 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
1731 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
1734 Lisp_Object w32_charset
;
1735 Lisp_Object codepage
;
1737 Lisp_Object this_entry
= XCAR (rest
);
1739 /* Skip invalid entries in alist. */
1740 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
1741 || !CONSP (XCDR (this_entry
))
1742 || !SYMBOLP (XCAR (XCDR (this_entry
))))
1745 x_charset
= SDATA (XCAR (this_entry
));
1746 w32_charset
= XCAR (XCDR (this_entry
));
1747 codepage
= XCDR (XCDR (this_entry
));
1749 /* Look for Same charset and a valid codepage (or non-int
1750 which means ignore). */
1751 if (EQ (w32_charset
, charset_type
)
1752 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
1753 || IsValidCodePage (XINT (codepage
))))
1755 /* If we don't have a match already, then this is the
1759 best_match
= x_charset
;
1760 if (matching
&& !strnicmp (x_charset
, matching
, match_len
))
1763 /* If we already found a match for MATCHING, then
1764 only consider other matches. */
1765 else if (matching_found
1766 && strnicmp (x_charset
, matching
, match_len
))
1768 /* If this matches what we want, and the best so far doesn't,
1769 then this is better. */
1770 else if (!matching_found
&& matching
1771 && !strnicmp (x_charset
, matching
, match_len
))
1773 best_match
= x_charset
;
1776 /* If this is fully specified, and the best so far isn't,
1777 then this is better. */
1778 else if ((!strchr (best_match
, '-') && strchr (x_charset
, '-'))
1779 /* If this is an ISO codepage, and the best so far isn't,
1780 then this is better, but only if it fully specifies the
1782 || (strnicmp (best_match
, "iso", 3) != 0
1783 && strnicmp (x_charset
, "iso", 3) == 0
1784 && strchr (x_charset
, '-')))
1785 best_match
= x_charset
;
1786 /* If both are ISO8859 codepages, choose the one with the
1787 lowest number in the encoding field. */
1788 else if (strnicmp (best_match
, "iso8859-", 8) == 0
1789 && strnicmp (x_charset
, "iso8859-", 8) == 0)
1791 int best_enc
= atoi (best_match
+ 8);
1792 int this_enc
= atoi (x_charset
+ 8);
1793 if (this_enc
> 0 && this_enc
< best_enc
)
1794 best_match
= x_charset
;
1799 /* If no match, encode the numeric value. */
1802 sprintf (buf
, "*-#%u", fncharset
);
1806 strncpy (buf
, best_match
, 31);
1807 /* If the charset is not fully specified, put -0 on the end. */
1808 if (!strchr (best_match
, '-'))
1810 int pos
= strlen (best_match
);
1811 /* Charset specifiers shouldn't be very long. If it is a made
1812 up one, truncating it should not do any harm since it isn't
1813 recognized anyway. */
1816 strcpy (buf
+ pos
, "-0");
1824 w32_registry (w32_charset
, font_type
)
1830 /* If charset is defaulted, charset is unicode or unknown, depending on
1832 if (w32_charset
== DEFAULT_CHARSET
)
1833 return font_type
== TRUETYPE_FONTTYPE
? Qiso10646_1
: Qunknown
;
1835 charset
= w32_to_x_charset (w32_charset
, NULL
);
1836 return font_intern_prop (charset
, strlen (charset
), 1);
1840 w32_decode_weight (fnweight
)
1843 if (fnweight
>= FW_HEAVY
) return 210;
1844 if (fnweight
>= FW_EXTRABOLD
) return 205;
1845 if (fnweight
>= FW_BOLD
) return 200;
1846 if (fnweight
>= FW_SEMIBOLD
) return 180;
1847 if (fnweight
>= FW_NORMAL
) return 100;
1848 if (fnweight
>= FW_LIGHT
) return 50;
1849 if (fnweight
>= FW_EXTRALIGHT
) return 40;
1850 if (fnweight
> FW_THIN
) return 20;
1855 w32_encode_weight (n
)
1858 if (n
>= 210) return FW_HEAVY
;
1859 if (n
>= 205) return FW_EXTRABOLD
;
1860 if (n
>= 200) return FW_BOLD
;
1861 if (n
>= 180) return FW_SEMIBOLD
;
1862 if (n
>= 100) return FW_NORMAL
;
1863 if (n
>= 50) return FW_LIGHT
;
1864 if (n
>= 40) return FW_EXTRALIGHT
;
1865 if (n
>= 20) return FW_THIN
;
1869 /* Convert a Windows font weight into one of the weights supported
1870 by fontconfig (see font.c:font_parse_fcname). */
1872 w32_to_fc_weight (n
)
1875 if (n
>= FW_EXTRABOLD
) return intern ("black");
1876 if (n
>= FW_BOLD
) return intern ("bold");
1877 if (n
>= FW_SEMIBOLD
) return intern ("demibold");
1878 if (n
>= FW_NORMAL
) return intern ("medium");
1879 return intern ("light");
1882 /* Fill in all the available details of LOGFONT from FONT_SPEC. */
1884 fill_in_logfont (f
, logfont
, font_spec
)
1887 Lisp_Object font_spec
;
1889 Lisp_Object tmp
, extra
;
1890 int dpi
= FRAME_W32_DISPLAY_INFO (f
)->resy
;
1892 tmp
= AREF (font_spec
, FONT_DPI_INDEX
);
1897 else if (FLOATP (tmp
))
1899 dpi
= (int) (XFLOAT_DATA (tmp
) + 0.5);
1903 tmp
= AREF (font_spec
, FONT_SIZE_INDEX
);
1905 logfont
->lfHeight
= -1 * XINT (tmp
);
1906 else if (FLOATP (tmp
))
1907 logfont
->lfHeight
= (int) (-1.0 * dpi
* XFLOAT_DATA (tmp
) / 72.27 + 0.5);
1914 tmp
= AREF (font_spec
, FONT_WEIGHT_INDEX
);
1916 logfont
->lfWeight
= w32_encode_weight (FONT_WEIGHT_NUMERIC (font_spec
));
1919 tmp
= AREF (font_spec
, FONT_SLANT_INDEX
);
1922 int slant
= FONT_SLANT_NUMERIC (font_spec
);
1923 logfont
->lfItalic
= slant
> 150 ? 1 : 0;
1931 tmp
= AREF (font_spec
, FONT_REGISTRY_INDEX
);
1933 logfont
->lfCharSet
= registry_to_w32_charset (tmp
);
1935 logfont
->lfCharSet
= DEFAULT_CHARSET
;
1939 /* Clip Precision */
1942 logfont
->lfQuality
= DEFAULT_QUALITY
;
1944 /* Generic Family and Face Name */
1945 logfont
->lfPitchAndFamily
= FF_DONTCARE
| DEFAULT_PITCH
;
1947 tmp
= AREF (font_spec
, FONT_FAMILY_INDEX
);
1950 logfont
->lfPitchAndFamily
= w32_generic_family (tmp
) | DEFAULT_PITCH
;
1951 if ((logfont
->lfPitchAndFamily
& 0xF0) != FF_DONTCARE
)
1952 ; /* Font name was generic, don't fill in font name. */
1953 /* Font families are interned, but allow for strings also in case of
1955 else if (SYMBOLP (tmp
))
1956 strncpy (logfont
->lfFaceName
,
1957 SDATA (ENCODE_SYSTEM (SYMBOL_NAME (tmp
))), LF_FACESIZE
);
1960 tmp
= AREF (font_spec
, FONT_ADSTYLE_INDEX
);
1963 /* Override generic family. */
1964 BYTE family
= w32_generic_family (tmp
);
1965 if (family
!= FF_DONTCARE
)
1966 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. */
2320 logfont_to_fcname (font
, pointsize
, fcname
, size
)
2328 Lisp_Object weight
= Qnil
;
2330 len
= strlen (font
->lfFaceName
) + 2;
2331 height
= pointsize
/ 10;
2332 while (height
/= 10)
2339 len
+= 7; /* :italic */
2340 if (font
->lfWeight
&& font
->lfWeight
!= FW_NORMAL
)
2342 weight
= w32_to_fc_weight (font
->lfWeight
);
2343 len
+= SBYTES (SYMBOL_NAME (weight
)) + 1;
2349 p
+= sprintf (p
, "%s-%d", font
->lfFaceName
, pointsize
/ 10);
2351 p
+= sprintf (p
, ".%d", pointsize
% 10);
2353 if (SYMBOLP (weight
) && !NILP (weight
))
2354 p
+= sprintf (p
, ":%s", SDATA (SYMBOL_NAME (weight
)));
2357 p
+= sprintf (p
, ":italic");
2359 return (p
- fcname
);
2363 compute_metrics (dc
, w32_font
, code
, metrics
)
2365 struct w32font_info
*w32_font
;
2367 struct w32_metric_cache
*metrics
;
2371 unsigned int options
= GGO_METRICS
;
2373 if (w32_font
->glyph_idx
)
2374 options
|= GGO_GLYPH_INDEX
;
2376 bzero (&transform
, sizeof (transform
));
2377 transform
.eM11
.value
= 1;
2378 transform
.eM22
.value
= 1;
2380 if (GetGlyphOutlineW (dc
, code
, options
, &gm
, 0, NULL
, &transform
)
2383 metrics
->lbearing
= gm
.gmptGlyphOrigin
.x
;
2384 metrics
->rbearing
= gm
.gmptGlyphOrigin
.x
+ gm
.gmBlackBoxX
;
2385 metrics
->width
= gm
.gmCellIncX
;
2386 metrics
->status
= W32METRIC_SUCCESS
;
2389 metrics
->status
= W32METRIC_FAIL
;
2392 DEFUN ("x-select-font", Fx_select_font
, Sx_select_font
, 0, 2, 0,
2393 doc
: /* Read a font name using a W32 font selection dialog.
2394 Return fontconfig style font string corresponding to the selection.
2396 If FRAME is omitted or nil, it defaults to the selected frame.
2397 If EXCLUDE-PROPORTIONAL is non-nil, exclude proportional fonts
2398 in the font selection dialog. */)
2399 (frame
, exclude_proportional
)
2400 Lisp_Object frame
, exclude_proportional
;
2402 FRAME_PTR f
= check_x_frame (frame
);
2410 bzero (&cf
, sizeof (cf
));
2411 bzero (&lf
, sizeof (lf
));
2413 cf
.lStructSize
= sizeof (cf
);
2414 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
2415 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
2417 /* If exclude_proportional is non-nil, limit the selection to
2418 monospaced fonts. */
2419 if (!NILP (exclude_proportional
))
2420 cf
.Flags
|= CF_FIXEDPITCHONLY
;
2424 /* Initialize as much of the font details as we can from the current
2426 hdc
= GetDC (FRAME_W32_WINDOW (f
));
2427 oldobj
= SelectObject (hdc
, FONT_HANDLE (FRAME_FONT (f
)));
2428 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
2429 if (GetTextMetrics (hdc
, &tm
))
2431 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
2432 lf
.lfWeight
= tm
.tmWeight
;
2433 lf
.lfItalic
= tm
.tmItalic
;
2434 lf
.lfUnderline
= tm
.tmUnderlined
;
2435 lf
.lfStrikeOut
= tm
.tmStruckOut
;
2436 lf
.lfCharSet
= tm
.tmCharSet
;
2437 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
2439 SelectObject (hdc
, oldobj
);
2440 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
2442 if (!ChooseFont (&cf
)
2443 || logfont_to_fcname (&lf
, cf
.iPointSize
, buf
, 100) < 0)
2446 return DECODE_SYSTEM (build_string (buf
));
2449 static const char *w32font_booleans
[] = {
2453 static const char *w32font_non_booleans
[] = {
2461 w32font_filter_properties (font
, alist
)
2465 font_filter_properties (font
, alist
, w32font_booleans
, w32font_non_booleans
);
2468 struct font_driver w32font_driver
=
2471 0, /* case insensitive */
2475 w32font_list_family
,
2476 NULL
, /* free_entity */
2479 NULL
, /* prepare_face */
2480 NULL
, /* done_face */
2482 w32font_encode_char
,
2483 w32font_text_extents
,
2485 NULL
, /* get_bitmap */
2486 NULL
, /* free_bitmap */
2487 NULL
, /* get_outline */
2488 NULL
, /* free_outline */
2489 NULL
, /* anchor_point */
2490 NULL
, /* otf_capability */
2491 NULL
, /* otf_drive */
2492 NULL
, /* start_for_frame */
2493 NULL
, /* end_for_frame */
2496 NULL
, /* get_variation_glyphs */
2497 w32font_filter_properties
,
2501 /* Initialize state that does not change between invocations. This is only
2502 called when Emacs is dumped. */
2506 DEFSYM (Qgdi
, "gdi");
2507 DEFSYM (Quniscribe
, "uniscribe");
2508 DEFSYM (QCformat
, ":format");
2510 /* Generic font families. */
2511 DEFSYM (Qmonospace
, "monospace");
2512 DEFSYM (Qserif
, "serif");
2513 DEFSYM (Qsansserif
, "sansserif");
2514 DEFSYM (Qscript
, "script");
2515 DEFSYM (Qdecorative
, "decorative");
2517 DEFSYM (Qsans_serif
, "sans_serif");
2518 DEFSYM (Qsans
, "sans");
2519 DEFSYM (Qmono
, "mono");
2521 /* Fake foundries. */
2522 DEFSYM (Qraster
, "raster");
2523 DEFSYM (Qoutline
, "outline");
2524 DEFSYM (Qunknown
, "unknown");
2527 DEFSYM (Qstandard
, "standard");
2528 DEFSYM (Qsubpixel
, "subpixel");
2529 DEFSYM (Qnatural
, "natural");
2535 DEFSYM (Qlatin
, "latin");
2536 DEFSYM (Qgreek
, "greek");
2537 DEFSYM (Qcoptic
, "coptic");
2538 DEFSYM (Qcyrillic
, "cyrillic");
2539 DEFSYM (Qarmenian
, "armenian");
2540 DEFSYM (Qhebrew
, "hebrew");
2541 DEFSYM (Qarabic
, "arabic");
2542 DEFSYM (Qsyriac
, "syriac");
2543 DEFSYM (Qnko
, "nko");
2544 DEFSYM (Qthaana
, "thaana");
2545 DEFSYM (Qdevanagari
, "devanagari");
2546 DEFSYM (Qbengali
, "bengali");
2547 DEFSYM (Qgurmukhi
, "gurmukhi");
2548 DEFSYM (Qgujarati
, "gujarati");
2549 DEFSYM (Qoriya
, "oriya");
2550 DEFSYM (Qtamil
, "tamil");
2551 DEFSYM (Qtelugu
, "telugu");
2552 DEFSYM (Qkannada
, "kannada");
2553 DEFSYM (Qmalayalam
, "malayalam");
2554 DEFSYM (Qsinhala
, "sinhala");
2555 DEFSYM (Qthai
, "thai");
2556 DEFSYM (Qlao
, "lao");
2557 DEFSYM (Qtibetan
, "tibetan");
2558 DEFSYM (Qmyanmar
, "myanmar");
2559 DEFSYM (Qgeorgian
, "georgian");
2560 DEFSYM (Qhangul
, "hangul");
2561 DEFSYM (Qethiopic
, "ethiopic");
2562 DEFSYM (Qcherokee
, "cherokee");
2563 DEFSYM (Qcanadian_aboriginal
, "canadian-aboriginal");
2564 DEFSYM (Qogham
, "ogham");
2565 DEFSYM (Qrunic
, "runic");
2566 DEFSYM (Qkhmer
, "khmer");
2567 DEFSYM (Qmongolian
, "mongolian");
2568 DEFSYM (Qsymbol
, "symbol");
2569 DEFSYM (Qbraille
, "braille");
2570 DEFSYM (Qhan
, "han");
2571 DEFSYM (Qideographic_description
, "ideographic-description");
2572 DEFSYM (Qcjk_misc
, "cjk-misc");
2573 DEFSYM (Qkana
, "kana");
2574 DEFSYM (Qbopomofo
, "bopomofo");
2575 DEFSYM (Qkanbun
, "kanbun");
2577 DEFSYM (Qbyzantine_musical_symbol
, "byzantine-musical-symbol");
2578 DEFSYM (Qmusical_symbol
, "musical-symbol");
2579 DEFSYM (Qmathematical
, "mathematical");
2580 DEFSYM (Qcham
, "cham");
2581 DEFSYM (Qphonetic
, "phonetic");
2582 DEFSYM (Qbalinese
, "balinese");
2583 DEFSYM (Qbuginese
, "buginese");
2584 DEFSYM (Qbuhid
, "buhid");
2585 DEFSYM (Qcuneiform
, "cuneiform");
2586 DEFSYM (Qcypriot
, "cypriot");
2587 DEFSYM (Qdeseret
, "deseret");
2588 DEFSYM (Qglagolitic
, "glagolitic");
2589 DEFSYM (Qgothic
, "gothic");
2590 DEFSYM (Qhanunoo
, "hanunoo");
2591 DEFSYM (Qkharoshthi
, "kharoshthi");
2592 DEFSYM (Qlimbu
, "limbu");
2593 DEFSYM (Qlinear_b
, "linear_b");
2594 DEFSYM (Qold_italic
, "old_italic");
2595 DEFSYM (Qold_persian
, "old_persian");
2596 DEFSYM (Qosmanya
, "osmanya");
2597 DEFSYM (Qphags_pa
, "phags-pa");
2598 DEFSYM (Qphoenician
, "phoenician");
2599 DEFSYM (Qshavian
, "shavian");
2600 DEFSYM (Qsyloti_nagri
, "syloti_nagri");
2601 DEFSYM (Qtagalog
, "tagalog");
2602 DEFSYM (Qtagbanwa
, "tagbanwa");
2603 DEFSYM (Qtai_le
, "tai_le");
2604 DEFSYM (Qtifinagh
, "tifinagh");
2605 DEFSYM (Qugaritic
, "ugaritic");
2607 /* W32 font encodings. */
2608 DEFVAR_LISP ("w32-charset-info-alist",
2609 &Vw32_charset_info_alist
,
2610 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
2611 Each entry should be of the form:
2613 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
2615 where CHARSET_NAME is a string used in font names to identify the charset,
2616 WINDOWS_CHARSET is a symbol that can be one of:
2618 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
2619 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
2620 w32-charset-chinesebig5, w32-charset-johab, w32-charset-hebrew,
2621 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
2622 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
2623 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
2626 CODEPAGE should be an integer specifying the codepage that should be used
2627 to display the character set, t to do no translation and output as Unicode,
2628 or nil to do no translation and output as 8 bit (or multibyte on far-east
2629 versions of Windows) characters. */);
2630 Vw32_charset_info_alist
= Qnil
;
2632 DEFSYM (Qw32_charset_ansi
, "w32-charset-ansi");
2633 DEFSYM (Qw32_charset_symbol
, "w32-charset-symbol");
2634 DEFSYM (Qw32_charset_default
, "w32-charset-default");
2635 DEFSYM (Qw32_charset_shiftjis
, "w32-charset-shiftjis");
2636 DEFSYM (Qw32_charset_hangeul
, "w32-charset-hangeul");
2637 DEFSYM (Qw32_charset_chinesebig5
, "w32-charset-chinesebig5");
2638 DEFSYM (Qw32_charset_gb2312
, "w32-charset-gb2312");
2639 DEFSYM (Qw32_charset_oem
, "w32-charset-oem");
2640 DEFSYM (Qw32_charset_johab
, "w32-charset-johab");
2641 DEFSYM (Qw32_charset_easteurope
, "w32-charset-easteurope");
2642 DEFSYM (Qw32_charset_turkish
, "w32-charset-turkish");
2643 DEFSYM (Qw32_charset_baltic
, "w32-charset-baltic");
2644 DEFSYM (Qw32_charset_russian
, "w32-charset-russian");
2645 DEFSYM (Qw32_charset_arabic
, "w32-charset-arabic");
2646 DEFSYM (Qw32_charset_greek
, "w32-charset-greek");
2647 DEFSYM (Qw32_charset_hebrew
, "w32-charset-hebrew");
2648 DEFSYM (Qw32_charset_vietnamese
, "w32-charset-vietnamese");
2649 DEFSYM (Qw32_charset_thai
, "w32-charset-thai");
2650 DEFSYM (Qw32_charset_mac
, "w32-charset-mac");
2652 defsubr (&Sx_select_font
);
2654 w32font_driver
.type
= Qgdi
;
2655 register_font_driver (&w32font_driver
, NULL
);
2658 /* arch-tag: 65b8a3cd-46aa-4c0d-a1f3-99e75b9c07ee
2659 (do not change this comment) */