w32font.c 88.7 KB
Newer Older
1
/* Font backend for the Microsoft Windows API.
Paul Eggert's avatar
Paul Eggert committed
2
   Copyright (C) 2007-2019 Free Software Foundation, Inc.
Jason Rumney's avatar
Jason Rumney committed
3 4 5

This file is part of GNU Emacs.

6
GNU Emacs is free software: you can redistribute it and/or modify
Jason Rumney's avatar
Jason Rumney committed
7
it under the terms of the GNU General Public License as published by
8 9
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
Jason Rumney's avatar
Jason Rumney committed
10 11 12 13 14 15 16

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
Paul Eggert's avatar
Paul Eggert committed
17
along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
Jason Rumney's avatar
Jason Rumney committed
18 19 20

#include <config.h>
#include <windows.h>
Daniel Colascione's avatar
Daniel Colascione committed
21
#include <stdio.h>
Juanma Barranquero's avatar
Juanma Barranquero committed
22
#include <math.h>
Juanma Barranquero's avatar
Juanma Barranquero committed
23
#include <ctype.h>
24
#include <commdlg.h>
Jason Rumney's avatar
Jason Rumney committed
25 26 27 28

#include "lisp.h"
#include "w32term.h"
#include "frame.h"
29
#include "coding.h"	/* for ENCODE_SYSTEM, DECODE_SYSTEM */
Jason Rumney's avatar
Jason Rumney committed
30
#include "w32font.h"
31 32 33
#ifdef WINDOWSNT
#include "w32.h"
#endif
Jason Rumney's avatar
Jason Rumney committed
34

35 36 37 38 39 40 41 42 43 44 45
/* Cleartype available on Windows XP, cleartype_natural from XP SP1.
   The latter does not try to fit cleartype smoothed fonts into the
   same bounding box as the non-antialiased version of the font.
 */
#ifndef CLEARTYPE_QUALITY
#define CLEARTYPE_QUALITY 5
#endif
#ifndef CLEARTYPE_NATURAL_QUALITY
#define CLEARTYPE_NATURAL_QUALITY 6
#endif

46 47 48 49 50 51 52 53 54
/* VIETNAMESE_CHARSET and JOHAB_CHARSET are not defined in some versions
   of MSVC headers.  */
#ifndef VIETNAMESE_CHARSET
#define VIETNAMESE_CHARSET 163
#endif
#ifndef JOHAB_CHARSET
#define JOHAB_CHARSET 130
#endif

Dmitry Antipov's avatar
Dmitry Antipov committed
55
static void fill_in_logfont (struct frame *, LOGFONT *, Lisp_Object);
Jason Rumney's avatar
Jason Rumney committed
56

57 58
static BYTE w32_antialias_type (Lisp_Object);
static Lisp_Object lispy_antialias_type (BYTE);
59

60 61 62 63
static Lisp_Object font_supported_scripts (FONTSIGNATURE *);
static int w32font_full_name (LOGFONT *, Lisp_Object, int, char *, int);
static void compute_metrics (HDC, struct w32font_info *, unsigned int,
                             struct w32_metric_cache *);
Jason Rumney's avatar
Jason Rumney committed
64

65
static Lisp_Object w32_registry (LONG, DWORD);
Jason Rumney's avatar
Jason Rumney committed
66 67

/* EnumFontFamiliesEx callbacks.  */
68 69 70 71 72 73 74 75 76
static int CALLBACK ALIGN_STACK add_font_entity_to_list (ENUMLOGFONTEX *,
							 NEWTEXTMETRICEX *,
							 DWORD, LPARAM);
static int CALLBACK ALIGN_STACK add_one_font_entity_to_list (ENUMLOGFONTEX *,
							     NEWTEXTMETRICEX *,
							     DWORD, LPARAM);
static int CALLBACK ALIGN_STACK add_font_name_to_list (ENUMLOGFONTEX *,
						       NEWTEXTMETRICEX *,
						       DWORD, LPARAM);
Jason Rumney's avatar
Jason Rumney committed
77

78 79 80 81 82 83 84 85 86 87 88 89 90 91
/* struct passed in as LPARAM arg to EnumFontFamiliesEx, for keeping track
   of what we really want.  */
struct font_callback_data
{
  /* The logfont we are matching against. EnumFontFamiliesEx only matches
     face name and charset, so we need to manually match everything else
     in the callback function.  */
  LOGFONT pattern;
  /* The original font spec or entity.  */
  Lisp_Object orig_font_spec;
  /* The frame the font is being loaded on.  */
  Lisp_Object frame;
  /* The list to add matches to.  */
  Lisp_Object list;
Jason Rumney's avatar
Jason Rumney committed
92
  /* Whether to match only opentype fonts.  */
93
  bool opentype_only;
94 95 96 97
};

/* Handles the problem that EnumFontFamiliesEx will not return all
   style variations if the font name is not specified.  */
98
static void list_all_matching_fonts (struct font_callback_data *);
99

100 101
#ifdef WINDOWSNT

102 103 104
static BOOL g_b_init_get_outline_metrics_w;
static BOOL g_b_init_get_text_metrics_w;
static BOOL g_b_init_get_glyph_outline_w;
105
static BOOL g_b_init_get_char_width_32_w;
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121

typedef UINT (WINAPI * GetOutlineTextMetricsW_Proc) (
   HDC hdc,
   UINT cbData,
   LPOUTLINETEXTMETRICW lpotmw);
typedef BOOL (WINAPI * GetTextMetricsW_Proc) (
   HDC hdc,
   LPTEXTMETRICW lptmw);
typedef DWORD (WINAPI * GetGlyphOutlineW_Proc) (
   HDC hdc,
   UINT uChar,
   UINT uFormat,
   LPGLYPHMETRICS lpgm,
   DWORD cbBuffer,
   LPVOID lpvBuffer,
   const MAT2 *lpmat2);
122 123 124 125 126
typedef BOOL (WINAPI * GetCharWidth32W_Proc) (
   HDC hdc,
   UINT uFirstChar,
   UINT uLastChar,
   LPINT lpBuffer);
127 128 129 130 131 132 133 134 135 136 137 138

/* Several "wide" functions we use to support the font backends are
   unavailable on Windows 9X, unless UNICOWS.DLL is installed (their
   versions in the default libraries are non-functional stubs).  On NT
   and later systems, these functions are in GDI32.DLL.  The following
   helper function attempts to load UNICOWS.DLL on Windows 9X, and
   refuses to let Emacs start up if that library is not found.  On NT
   and later versions, it simply loads GDI32.DLL, which should always
   be available.  */
static HMODULE
w32_load_unicows_or_gdi32 (void)
{
139
  return maybe_load_unicows_dll ();
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
}

/* The following 3 functions call the problematic "wide" APIs via
   function pointers, to avoid linking against the non-standard
   libunicows on W9X.  */
static UINT WINAPI
get_outline_metrics_w(HDC hdc, UINT cbData, LPOUTLINETEXTMETRICW lpotmw)
{
  static GetOutlineTextMetricsW_Proc s_pfn_Get_Outline_Text_MetricsW = NULL;
  HMODULE hm_unicows = NULL;
  if (g_b_init_get_outline_metrics_w == 0)
    {
      g_b_init_get_outline_metrics_w = 1;
      hm_unicows = w32_load_unicows_or_gdi32 ();
      if (hm_unicows)
	s_pfn_Get_Outline_Text_MetricsW = (GetOutlineTextMetricsW_Proc)
	  GetProcAddress (hm_unicows, "GetOutlineTextMetricsW");
    }
158
  eassert (s_pfn_Get_Outline_Text_MetricsW != NULL);
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
  return s_pfn_Get_Outline_Text_MetricsW (hdc, cbData, lpotmw);
}

static BOOL WINAPI
get_text_metrics_w(HDC hdc, LPTEXTMETRICW lptmw)
{
  static GetTextMetricsW_Proc s_pfn_Get_Text_MetricsW = NULL;
  HMODULE hm_unicows = NULL;
  if (g_b_init_get_text_metrics_w == 0)
    {
      g_b_init_get_text_metrics_w = 1;
      hm_unicows = w32_load_unicows_or_gdi32 ();
      if (hm_unicows)
	s_pfn_Get_Text_MetricsW = (GetTextMetricsW_Proc)
	  GetProcAddress (hm_unicows, "GetTextMetricsW");
    }
175
  eassert (s_pfn_Get_Text_MetricsW != NULL);
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
  return s_pfn_Get_Text_MetricsW (hdc, lptmw);
}

static DWORD WINAPI
get_glyph_outline_w (HDC hdc, UINT uChar, UINT uFormat, LPGLYPHMETRICS lpgm,
		     DWORD cbBuffer, LPVOID lpvBuffer, const MAT2 *lpmat2)
{
  static GetGlyphOutlineW_Proc s_pfn_Get_Glyph_OutlineW = NULL;
  HMODULE hm_unicows = NULL;
  if (g_b_init_get_glyph_outline_w == 0)
    {
      g_b_init_get_glyph_outline_w = 1;
      hm_unicows = w32_load_unicows_or_gdi32 ();
      if (hm_unicows)
	s_pfn_Get_Glyph_OutlineW = (GetGlyphOutlineW_Proc)
	  GetProcAddress (hm_unicows, "GetGlyphOutlineW");
    }
193
  eassert (s_pfn_Get_Glyph_OutlineW != NULL);
194 195 196
  return s_pfn_Get_Glyph_OutlineW (hdc, uChar, uFormat, lpgm, cbBuffer,
				   lpvBuffer, lpmat2);
}
Jason Rumney's avatar
Jason Rumney committed
197

198 199
static DWORD WINAPI
get_char_width_32_w (HDC hdc, UINT uFirstChar, UINT uLastChar, LPINT lpBuffer)
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
{
  static GetCharWidth32W_Proc s_pfn_Get_Char_Width_32W = NULL;
  HMODULE hm_unicows = NULL;
  if (g_b_init_get_char_width_32_w == 0)
    {
      g_b_init_get_char_width_32_w = 1;
      hm_unicows = w32_load_unicows_or_gdi32 ();
      if (hm_unicows)
	s_pfn_Get_Char_Width_32W = (GetCharWidth32W_Proc)
	  GetProcAddress (hm_unicows, "GetCharWidth32W");
    }
  eassert (s_pfn_Get_Char_Width_32W != NULL);
  return s_pfn_Get_Char_Width_32W (hdc, uFirstChar, uLastChar, lpBuffer);
}

215 216 217 218 219 220 221 222 223 224 225 226
#else  /* Cygwin */

/* Cygwin doesn't support Windows 9X, and links against GDI32.DLL, so
   it can just call these functions directly.  */
#define get_outline_metrics_w(h,d,o)   GetOutlineTextMetricsW(h,d,o)
#define get_text_metrics_w(h,t)        GetTextMetricsW(h,t)
#define get_glyph_outline_w(h,uc,f,gm,b,v,m) \
                                       GetGlyphOutlineW(h,uc,f,gm,b,v,m)
#define get_char_width_32_w(h,fc,lc,b) GetCharWidth32W(h,fc,lc,b)

#endif	/* Cygwin */

Jason Rumney's avatar
Jason Rumney committed
227
static int
228
memq_no_quit (Lisp_Object elt, Lisp_Object list)
Jason Rumney's avatar
Jason Rumney committed
229 230 231 232 233 234
{
  while (CONSP (list) && ! EQ (XCAR (list), elt))
    list = XCDR (list);
  return (CONSP (list));
}

235
Lisp_Object
236
intern_font_name (char * string)
237
{
238
  Lisp_Object str = DECODE_SYSTEM (build_string (string));
239
  ptrdiff_t len = SCHARS (str);
240
  Lisp_Object obarray = check_obarray (Vobarray);
241
  Lisp_Object tem = oblookup (obarray, SSDATA (str), len, len);
242
  /* This code is similar to intern function from lread.c.  */
243
  return SYMBOLP (tem) ? tem : intern_driver (str, obarray, tem);
244 245
}

Jason Rumney's avatar
Jason Rumney committed
246 247 248
/* w32 implementation of get_cache for font backend.
   Return a cache of font-entities on FRAME.  The cache must be a
   cons whose cdr part is the actual cache area.  */
Jason Rumney's avatar
Jason Rumney committed
249
Lisp_Object
Dmitry Antipov's avatar
Dmitry Antipov committed
250
w32font_get_cache (struct frame *f)
Jason Rumney's avatar
Jason Rumney committed
251
{
252
  struct w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
Jason Rumney's avatar
Jason Rumney committed
253 254 255 256 257 258 259 260

  return (dpyinfo->name_list_element);
}

/* w32 implementation of list for font backend.
   List fonts exactly matching with FONT_SPEC on FRAME.  The value
   is a vector of font-entities.  This is the sole API that
   allocates font-entities.  */
261
static Lisp_Object
262
w32font_list (struct frame *f, Lisp_Object font_spec)
Jason Rumney's avatar
Jason Rumney committed
263
{
264
  Lisp_Object fonts = w32font_list_internal (f, font_spec, 0);
265
  FONT_ADD_LOG ("w32font-list", font_spec, fonts);
266
  return fonts;
Jason Rumney's avatar
Jason Rumney committed
267 268 269 270
}

/* w32 implementation of match for font backend.
   Return a font entity most closely matching with FONT_SPEC on
Paul Eggert's avatar
Paul Eggert committed
271
   FRAME.  The closeness is determined by the font backend, thus
Jason Rumney's avatar
Jason Rumney committed
272
   `face-font-selection-order' is ignored here.  */
273
static Lisp_Object
274
w32font_match (struct frame *f, Lisp_Object font_spec)
Jason Rumney's avatar
Jason Rumney committed
275
{
276
  Lisp_Object entity = w32font_match_internal (f, font_spec, 0);
277
  FONT_ADD_LOG ("w32font-match", font_spec, entity);
278
  return entity;
Jason Rumney's avatar
Jason Rumney committed
279 280 281 282 283
}

/* w32 implementation of list_family for font backend.
   List available families.  The value is a list of family names
   (symbols).  */
284
static Lisp_Object
285
w32font_list_family (struct frame *f)
Jason Rumney's avatar
Jason Rumney committed
286 287
{
  Lisp_Object list = Qnil;
288
  Lisp_Object prev_quit = Vinhibit_quit;
Jason Rumney's avatar
Jason Rumney committed
289 290 291
  LOGFONT font_match_pattern;
  HDC dc;

292
  memset (&font_match_pattern, 0, sizeof (font_match_pattern));
293
  font_match_pattern.lfCharSet = DEFAULT_CHARSET;
Jason Rumney's avatar
Jason Rumney committed
294

295 296 297 298 299
  /* Prevent quitting while EnumFontFamiliesEx runs and conses the
     list it will return.  That's because get_frame_dc acquires the
     critical section, so we cannot quit before we release it in
     release_frame_dc.  */
  Vinhibit_quit = Qt;
Jason Rumney's avatar
Jason Rumney committed
300 301 302 303 304 305
  dc = get_frame_dc (f);

  EnumFontFamiliesEx (dc, &font_match_pattern,
                      (FONTENUMPROC) add_font_name_to_list,
                      (LPARAM) &list, 0);
  release_frame_dc (f, dc);
306
  Vinhibit_quit = prev_quit;
Jason Rumney's avatar
Jason Rumney committed
307 308 309 310 311 312 313

  return list;
}

/* w32 implementation of open for font backend.
   Open a font specified by FONT_ENTITY on frame F.
   If the font is scalable, open it with PIXEL_SIZE.  */
314
static Lisp_Object
Dmitry Antipov's avatar
Dmitry Antipov committed
315
w32font_open (struct frame *f, Lisp_Object font_entity, int pixel_size)
Jason Rumney's avatar
Jason Rumney committed
316
{
317 318 319 320 321
  Lisp_Object font_object
    = font_make_object (VECSIZE (struct w32font_info),
                        font_entity, pixel_size);
  struct w32font_info *w32_font
    = (struct w32font_info *) XFONT_OBJECT (font_object);
Jason Rumney's avatar
Jason Rumney committed
322

323
  ASET (font_object, FONT_TYPE_INDEX, Qgdi);
Jason Rumney's avatar
Jason Rumney committed
324

325
  if (!w32font_open_internal (f, font_entity, pixel_size, font_object))
Jason Rumney's avatar
Jason Rumney committed
326
    {
327
      return Qnil;
Jason Rumney's avatar
Jason Rumney committed
328 329
    }

330 331 332
  /* GDI backend does not use glyph indices.  */
  w32_font->glyph_idx = 0;

333
  return font_object;
Jason Rumney's avatar
Jason Rumney committed
334 335
}

336
/* w32 implementation of close for font_backend.  */
Jason Rumney's avatar
Jason Rumney committed
337
void
338
w32font_close (struct font *font)
Jason Rumney's avatar
Jason Rumney committed
339
{
340
  struct w32font_info *w32_font = (struct w32font_info *) font;
341

342
  if (w32_font->hfont)
343
    {
344 345 346 347 348 349 350
      /* Delete the GDI font object.  */
      DeleteObject (w32_font->hfont);
      w32_font->hfont = NULL;

      /* Free all the cached metrics.  */
      if (w32_font->cached_metrics)
	{
351 352
	  int i;

353 354 355 356 357
	  for (i = 0; i < w32_font->n_cache_blocks; i++)
	      xfree (w32_font->cached_metrics[i]);
	  xfree (w32_font->cached_metrics);
	  w32_font->cached_metrics = NULL;
	}
358
    }
Jason Rumney's avatar
Jason Rumney committed
359 360 361 362 363 364 365
}

/* w32 implementation of has_char for font backend.
   Optional.
   If FONT_ENTITY has a glyph for character C (Unicode code point),
   return 1.  If not, return 0.  If a font must be opened to check
   it, return -1.  */
Jason Rumney's avatar
Jason Rumney committed
366
int
367
w32font_has_char (Lisp_Object entity, int c)
Jason Rumney's avatar
Jason Rumney committed
368
{
369 370 371 372 373 374
  /* We can't be certain about which characters a font will support until
     we open it.  Checking the scripts that the font supports turns out
     to not be reliable.  */
  return -1;

#if 0
375
  Lisp_Object supported_scripts, extra, script;
Jason Rumney's avatar
Jason Rumney committed
376 377
  DWORD mask;

378 379 380 381
  extra = AREF (entity, FONT_EXTRA_INDEX);
  if (!CONSP (extra))
    return -1;

382
  supported_scripts = assq_no_quit (QCscript, extra);
383 384
  /* If font doesn't claim to support any scripts, then we can't be certain
     until we open it.  */
385
  if (!CONSP (supported_scripts))
Jason Rumney's avatar
Jason Rumney committed
386 387
    return -1;

388
  supported_scripts = XCDR (supported_scripts);
Jason Rumney's avatar
Jason Rumney committed
389

390
  script = CHAR_TABLE_REF (Vchar_script_table, c);
Jason Rumney's avatar
Jason Rumney committed
391

392 393 394 395 396 397 398 399
  /* If we don't know what script the character is from, then we can't be
     certain until we open it.  Also if the font claims support for the script
     the character is from, it may only have partial coverage, so we still
     can't be certain until we open the font.  */
  if (NILP (script) || memq_no_quit (script, supported_scripts))
    return -1;

  /* Font reports what scripts it supports, and none of them are the script
400 401 402 403 404
     the character is from. But we still can't be certain, as some fonts
     will contain some/most/all of the characters in that script without
     claiming support for it.  */
  return -1;
#endif
Jason Rumney's avatar
Jason Rumney committed
405 406 407
}

/* w32 implementation of encode_char for font backend.
408
   Return a glyph code of FONT for character C (Unicode code point).
409 410
   If FONT doesn't have such a glyph, return FONT_INVALID_CODE.

Juanma Barranquero's avatar
Juanma Barranquero committed
411
   For speed, the gdi backend uses Unicode (Emacs calls encode_char
412 413 414
   far too often for it to be efficient). But we still need to detect
   which characters are not supported by the font.
  */
415
static unsigned
416
w32font_encode_char (struct font *font, int c)
Jason Rumney's avatar
Jason Rumney committed
417
{
418
  struct w32font_info * w32_font = (struct w32font_info *)font;
419

420 421 422
  if (c < w32_font->metrics.tmFirstChar
      || c > w32_font->metrics.tmLastChar)
    return FONT_INVALID_CODE;
423
  else
424
    return c;
Jason Rumney's avatar
Jason Rumney committed
425 426 427 428 429
}

/* w32 implementation of text_extents for font backend.
   Perform the size computation of glyphs of FONT and fillin members
   of METRICS.  The glyphs are specified by their glyph codes in
430
   CODE (length NGLYPHS).  Apparently metrics can be NULL, in this
Jason Rumney's avatar
Jason Rumney committed
431
   case just return the overall width.  */
432
void
433 434
w32font_text_extents (struct font *font, unsigned *code,
		      int nglyphs, struct font_metrics *metrics)
Jason Rumney's avatar
Jason Rumney committed
435 436
{
  int i;
437 438
  HFONT old_font = NULL;
  HDC dc = NULL;
Eli Zaretskii's avatar
Eli Zaretskii committed
439
  struct frame * f UNINIT;
Jason Rumney's avatar
Jason Rumney committed
440
  int total_width = 0;
441
  WORD *wcode;
442
  SIZE size;
443
  bool first;
444
  Lisp_Object prev_quit = Vinhibit_quit;
Jason Rumney's avatar
Jason Rumney committed
445

446 447
  struct w32font_info *w32_font = (struct w32font_info *) font;

448
  memset (metrics, 0, sizeof (struct font_metrics));
Jason Rumney's avatar
Jason Rumney committed
449

450
  for (i = 0, first = true; i < nglyphs; i++)
451 452 453 454
    {
      struct w32_metric_cache *char_metric;
      int block = *(code + i) / CACHE_BLOCKSIZE;
      int pos_in_block = *(code + i) % CACHE_BLOCKSIZE;
Jason Rumney's avatar
Jason Rumney committed
455

456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
      if (block >= w32_font->n_cache_blocks)
	{
	  if (!w32_font->cached_metrics)
	    w32_font->cached_metrics
	      = xmalloc ((block + 1)
			 * sizeof (struct w32_metric_cache *));
	  else
	    w32_font->cached_metrics
	      = xrealloc (w32_font->cached_metrics,
			  (block + 1)
			  * sizeof (struct w32_metric_cache *));
	  memset (w32_font->cached_metrics + w32_font->n_cache_blocks, 0,
		  ((block + 1 - w32_font->n_cache_blocks)
		   * sizeof (struct w32_metric_cache *)));
	  w32_font->n_cache_blocks = block + 1;
	}
Jason Rumney's avatar
Jason Rumney committed
472

473 474 475 476 477
      if (!w32_font->cached_metrics[block])
	{
	  w32_font->cached_metrics[block]
	    = xzalloc (CACHE_BLOCKSIZE * sizeof (struct w32_metric_cache));
	}
Jason Rumney's avatar
Jason Rumney committed
478

479
      char_metric = w32_font->cached_metrics[block] + pos_in_block;
Jason Rumney's avatar
Jason Rumney committed
480

481 482 483
      if (char_metric->status == W32METRIC_NO_ATTEMPT)
	{
	  if (dc == NULL)
Jason Rumney's avatar
Jason Rumney committed
484
	    {
485 486 487 488 489 490
	      /* TODO: Frames can come and go, and their fonts
		 outlive them. So we can't cache the frame in the
		 font structure.  Use selected_frame until the API
		 is updated to pass in a frame.  */
	      f = XFRAME (selected_frame);

491 492 493 494 495 496
	      /* Prevent quitting while EnumFontFamiliesEx runs and
		 conses the list it will return.  That's because
		 get_frame_dc acquires the critical section, so we
		 cannot quit before we release it in release_frame_dc.  */
	      prev_quit = Vinhibit_quit;
	      Vinhibit_quit = Qt;
497 498
	      dc = get_frame_dc (f);
	      old_font = SelectObject (dc, w32_font->hfont);
Jason Rumney's avatar
Jason Rumney committed
499
	    }
500 501
	  compute_metrics (dc, w32_font, *(code + i), char_metric);
	}
502

503 504
      if (char_metric->status == W32METRIC_SUCCESS)
	{
505 506 507 508 509 510 511 512 513 514 515 516 517
	  if (first)
	    {
	      metrics->lbearing = char_metric->lbearing;
	      metrics->rbearing = char_metric->rbearing;
	      metrics->width    = 0;
	      metrics->ascent   = char_metric->ascent;
	      metrics->descent  = char_metric->descent;
	      first = false;
	    }
	  if (metrics->lbearing > char_metric->lbearing)
	    metrics->lbearing = char_metric->lbearing;
	  if (metrics->rbearing < char_metric->rbearing)
	    metrics->rbearing = char_metric->rbearing;
518
	  metrics->width += char_metric->width;
519 520 521 522
	  if (metrics->ascent < char_metric->ascent)
	    metrics->ascent = char_metric->ascent;
	  if (metrics->descent < char_metric->descent)
	    metrics->descent = char_metric->descent;
Jason Rumney's avatar
Jason Rumney committed
523
	}
524 525 526 527 528 529 530 531 532 533 534 535 536
      else
	/* If we couldn't get metrics for a char,
	   use alternative method.  */
	break;
    }
  /* If we got through everything, return.  */
  if (i == nglyphs)
    {
      if (dc != NULL)
	{
	  /* Restore state and release DC.  */
	  SelectObject (dc, old_font);
	  release_frame_dc (f, dc);
537
	  Vinhibit_quit = prev_quit;
538 539
	}
      return;
Jason Rumney's avatar
Jason Rumney committed
540
    }
541

542 543 544
  /* For non-truetype fonts, GetGlyphOutlineW is not supported, so
     fallback on other methods that will at least give some of the metric
     information.  */
545

546
  /* Make array big enough to hold surrogates.  */
547
  eassume (0 <= nglyphs);	/* pacify GCC warning on next line */
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
  wcode = alloca (nglyphs * sizeof (WORD) * 2);
  for (i = 0; i < nglyphs; i++)
    {
      if (code[i] < 0x10000)
        wcode[i] = code[i];
      else
        {
          DWORD surrogate = code[i] - 0x10000;

          /* High surrogate: U+D800 - U+DBFF.  */
          wcode[i++] = 0xD800 + ((surrogate >> 10) & 0x03FF);
          /* Low surrogate: U+DC00 - U+DFFF.  */
          wcode[i] = 0xDC00 + (surrogate & 0x03FF);
          /* An extra glyph. wcode is already double the size of code to
             cope with this.  */
          nglyphs++;
        }
    }

567 568
  if (dc == NULL)
    {
Jason Rumney's avatar
Jason Rumney committed
569 570 571 572 573 574
      /* TODO: Frames can come and go, and their fonts outlive
	 them. So we can't cache the frame in the font structure.  Use
	 selected_frame until the API is updated to pass in a
	 frame.  */
      f = XFRAME (selected_frame);

575 576 577 578 579 580
      /* Prevent quitting while EnumFontFamiliesEx runs and conses the
	 list it will return.  That's because get_frame_dc acquires
	 the critical section, so we cannot quit before we release it
	 in release_frame_dc.  */
      prev_quit = Vinhibit_quit;
      Vinhibit_quit = Qt;
581
      dc = get_frame_dc (f);
582
      old_font = SelectObject (dc, w32_font->hfont);
583 584
    }

585
  if (GetTextExtentPoint32W (dc, wcode, nglyphs, &size))
Jason Rumney's avatar
Jason Rumney committed
586
    {
587
      total_width = size.cx;
Jason Rumney's avatar
Jason Rumney committed
588 589
    }

Juanma Barranquero's avatar
Juanma Barranquero committed
590
  /* On 95/98/ME, only some Unicode functions are available, so fallback
591
     on doing a dummy draw to find the total width.  */
592
  if (!total_width)
Jason Rumney's avatar
Jason Rumney committed
593 594
    {
      RECT rect;
595
      rect.top = 0; rect.bottom = font->height; rect.left = 0; rect.right = 1;
Jason Rumney's avatar
Jason Rumney committed
596 597 598 599
      DrawTextW (dc, wcode, nglyphs, &rect,
                 DT_CALCRECT | DT_NOPREFIX | DT_SINGLELINE);
      total_width = rect.right;
    }
600

601
  /* Give our best estimate of the metrics, based on what we know.  */
602 603 604
  metrics->width = total_width - w32_font->metrics.tmOverhang;
  metrics->lbearing = 0;
  metrics->rbearing = total_width;
605 606
  metrics->ascent = font->ascent;
  metrics->descent = font->descent;
607

Jason Rumney's avatar
Jason Rumney committed
608 609
  /* Restore state and release DC.  */
  SelectObject (dc, old_font);
Jason Rumney's avatar
Jason Rumney committed
610
  release_frame_dc (f, dc);
611
  Vinhibit_quit = prev_quit;
Jason Rumney's avatar
Jason Rumney committed
612 613 614 615 616
}

/* w32 implementation of draw for font backend.
   Optional.
   Draw glyphs between FROM and TO of S->char2b at (X Y) pixel
617 618 619
   position of frame F with S->FACE and S->GC.  If WITH_BACKGROUND,
   fill the background in advance.  It is assured that WITH_BACKGROUND
   is false when (FROM > 0 || TO < S->nchars).
620 621 622 623 624 625 626

   TODO: Currently this assumes that the colors and fonts are already
   set in the DC. This seems to be true now, but maybe only due to
   the old font code setting it up. It may be safer to resolve faces
   and fonts in here and set them explicitly
*/

Jason Rumney's avatar
Jason Rumney committed
627
int
628
w32font_draw (struct glyph_string *s, int from, int to,
629
	      int x, int y, bool with_background)
Jason Rumney's avatar
Jason Rumney committed
630
{
631
  UINT options;
632
  HRGN orig_clip = NULL;
633
  int len = to - from;
634
  struct w32font_info *w32font = (struct w32font_info *) s->font;
635 636

  options = w32font->glyph_idx;
637 638 639 640 641

  if (s->num_clips > 0)
    {
      HRGN new_clip = CreateRectRgnIndirect (s->clip);

642 643
      /* Save clip region for later restoration.  */
      orig_clip = CreateRectRgn (0, 0, 0, 0);
644
      if (!GetClipRgn (s->hdc, orig_clip))
645 646 647 648 649
	{
	  DeleteObject (orig_clip);
	  orig_clip = NULL;
	}

650 651 652 653 654 655 656 657 658 659 660
      if (s->num_clips > 1)
        {
          HRGN clip2 = CreateRectRgnIndirect (s->clip + 1);

          CombineRgn (new_clip, new_clip, clip2, RGN_OR);
          DeleteObject (clip2);
        }

      SelectClipRgn (s->hdc, new_clip);
      DeleteObject (new_clip);
    }
Jason Rumney's avatar
Jason Rumney committed
661

662 663 664
  /* Using OPAQUE background mode can clear more background than expected
     when Cleartype is used.  Draw the background manually to avoid this.  */
  SetBkMode (s->hdc, TRANSPARENT);
Jason Rumney's avatar
Jason Rumney committed
665 666
  if (with_background)
    {
667 668
      HBRUSH brush;
      RECT rect;
669
      struct font *font = s->font;
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
      int ascent = font->ascent, descent = font->descent;

      /* Font's global ascent and descent values might be
	 preposterously large for some fonts.  We fix here the case
	 when those fonts are used for display of glyphless
	 characters, because drawing background with font dimensions
	 in those cases makes the display illegible.  There's only one
	 more call to the draw method with with_background set to
	 true, and that's in x_draw_glyph_string_foreground, when
	 drawing the cursor, where we have no such heuristics
	 available.  FIXME.  */
      if (s->first_glyph->type == GLYPHLESS_GLYPH
	  && (s->first_glyph->u.glyphless.method == GLYPHLESS_DISPLAY_HEX_CODE
	      || s->first_glyph->u.glyphless.method == GLYPHLESS_DISPLAY_ACRONYM))
	{
	  ascent =
	    s->first_glyph->slice.glyphless.lower_yoff
	    - s->first_glyph->slice.glyphless.upper_yoff;
	  descent = 0;
	}
690 691
      brush = CreateSolidBrush (s->gc->background);
      rect.left = x;
692
      rect.top = y - ascent;
693
      rect.right = x + s->width;
694
      rect.bottom = y + descent;
695
      FillRect (s->hdc, &rect, brush);
696
      DeleteObject (brush);
Jason Rumney's avatar
Jason Rumney committed
697
    }
698

699 700
  if (s->padding_p)
    {
701
      int i;
702 703 704

      for (i = 0; i < len; i++)
	ExtTextOutW (s->hdc, x + i, y, options, NULL,
705
		     s->char2b + from + i, 1, NULL);
706 707
    }
  else
708
    ExtTextOutW (s->hdc, x, y, options, NULL, s->char2b + from, len, NULL);
709 710 711

  /* Restore clip region.  */
  if (s->num_clips > 0)
712 713 714 715
    SelectClipRgn (s->hdc, orig_clip);

  if (orig_clip)
    DeleteObject (orig_clip);
716 717

  return len;
Jason Rumney's avatar
Jason Rumney committed
718 719 720 721 722
}

/* w32 implementation of free_entity for font backend.
   Optional (if FONT_EXTRA_INDEX is not Lisp_Save_Value).
   Free FONT_EXTRA_INDEX field of FONT_ENTITY.
723 724
static void
w32font_free_entity (Lisp_Object entity);
Jason Rumney's avatar
Jason Rumney committed
725 726 727 728 729 730 731
  */

/* w32 implementation of prepare_face for font backend.
   Optional (if FACE->extra is not used).
   Prepare FACE for displaying characters by FONT on frame F by
   storing some data in FACE->extra.  If successful, return 0.
   Otherwise, return -1.
732
static int
Dmitry Antipov's avatar
Dmitry Antipov committed
733
w32font_prepare_face (struct frame *f, struct face *face);
Jason Rumney's avatar
Jason Rumney committed
734 735 736 737
  */
/* w32 implementation of done_face for font backend.
   Optional.
   Done FACE for displaying characters by FACE->font on frame F.
738
static void
Dmitry Antipov's avatar
Dmitry Antipov committed
739
w32font_done_face (struct frame *f, struct face *face);  */
Jason Rumney's avatar
Jason Rumney committed
740 741 742 743

/* w32 implementation of get_bitmap for font backend.
   Optional.
   Store bitmap data for glyph-code CODE of FONT in BITMAP.  It is
744
   intended that this method is called from the other font-driver
Jason Rumney's avatar
Jason Rumney committed
745
   for actual drawing.
746 747 748
static int
w32font_get_bitmap (struct font *font, unsigned code,
                    struct font_bitmap *bitmap, int bits_per_pixel);
Jason Rumney's avatar
Jason Rumney committed
749 750 751 752
  */
/* w32 implementation of free_bitmap for font backend.
   Optional.
   Free bitmap data in BITMAP.
753 754
static void
w32font_free_bitmap (struct font *font, struct font_bitmap *bitmap);
Jason Rumney's avatar
Jason Rumney committed
755 756 757 758 759
  */
/* w32 implementation of anchor_point for font backend.
   Optional.
   Get coordinates of the INDEXth anchor point of the glyph whose
   code is CODE.  Store the coordinates in *X and *Y.  Return 0 if
Paul Eggert's avatar
Paul Eggert committed
760
   the operations was successful.  Otherwise return -1.
761 762
static int
w32font_anchor_point (struct font *font, unsigned code,
Jason Rumney's avatar
Jason Rumney committed
763 764 765 766 767 768
                                 int index, int *x, int *y);
  */
/* w32 implementation of otf_capability for font backend.
   Optional.
   Return a list describing which scripts/languages FONT
   supports by which GSUB/GPOS features of OpenType tables.
769 770
static Lisp_Object
w32font_otf_capability (struct font *font);
Jason Rumney's avatar
Jason Rumney committed
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
  */
/* w32 implementation of otf_drive for font backend.
   Optional.
   Apply FONT's OTF-FEATURES to the glyph string.

   FEATURES specifies which OTF features to apply in this format:
      (SCRIPT LANGSYS GSUB-FEATURE GPOS-FEATURE)
   See the documentation of `font-drive-otf' for the detail.

   This method applies the specified features to the codes in the
   elements of GSTRING-IN (between FROMth and TOth).  The output
   codes are stored in GSTRING-OUT at the IDXth element and the
   following elements.

   Return the number of output codes.  If none of the features are
   applicable to the input data, return 0.  If GSTRING-OUT is too
   short, return -1.
788 789 790 791
static int
w32font_otf_drive (struct font *font, Lisp_Object features,
                   Lisp_Object gstring_in, int from, int to,
                   Lisp_Object gstring_out, int idx,
792
                   bool alternate_subst);
Jason Rumney's avatar
Jason Rumney committed
793 794
  */

Jason Rumney's avatar
Jason Rumney committed
795 796 797 798
/* Internal implementation of w32font_list.
   Additional parameter opentype_only restricts the returned fonts to
   opentype fonts, which can be used with the Uniscribe backend.  */
Lisp_Object
799 800
w32font_list_internal (struct frame *f, Lisp_Object font_spec,
		       bool opentype_only)
Jason Rumney's avatar
Jason Rumney committed
801 802 803 804 805 806
{
  struct font_callback_data match_data;
  HDC dc;

  match_data.orig_font_spec = font_spec;
  match_data.list = Qnil;
807
  XSETFRAME (match_data.frame, f);
Jason Rumney's avatar
Jason Rumney committed
808

809
  memset (&match_data.pattern, 0, sizeof (LOGFONT));
Jason Rumney's avatar
Jason Rumney committed
810 811
  fill_in_logfont (f, &match_data.pattern, font_spec);

812 813 814 815 816 817 818 819 820
  /* If the charset is unrecognized, then we won't find a font, so don't
     waste time looking for one.  */
  if (match_data.pattern.lfCharSet == DEFAULT_CHARSET)
    {
      Lisp_Object spec_charset = AREF (font_spec, FONT_REGISTRY_INDEX);
      if (!NILP (spec_charset)
	  && !EQ (spec_charset, Qiso10646_1)
	  && !EQ (spec_charset, Qunicode_bmp)
	  && !EQ (spec_charset, Qunicode_sip)
821 822
	  && !EQ (spec_charset, Qunknown)
	  && !EQ (spec_charset, Qascii_0))
823 824 825
	return Qnil;
    }

Jason Rumney's avatar
Jason Rumney committed
826 827 828 829 830 831 832 833 834 835 836 837
  match_data.opentype_only = opentype_only;
  if (opentype_only)
    match_data.pattern.lfOutPrecision = OUT_OUTLINE_PRECIS;

  if (match_data.pattern.lfFaceName[0] == '\0')
    {
      /* EnumFontFamiliesEx does not take other fields into account if
         font name is blank, so need to use two passes.  */
      list_all_matching_fonts (&match_data);
    }
  else
    {
838 839 840 841 842 843 844
      Lisp_Object prev_quit = Vinhibit_quit;

      /* Prevent quitting while EnumFontFamiliesEx runs and conses the
	 list it will return.  That's because get_frame_dc acquires
	 the critical section, so we cannot quit before we release it
	 in release_frame_dc.  */
      Vinhibit_quit = Qt;
Jason Rumney's avatar
Jason Rumney committed
845 846 847 848 849 850
      dc = get_frame_dc (f);

      EnumFontFamiliesEx (dc, &match_data.pattern,
                          (FONTENUMPROC) add_font_entity_to_list,
                          (LPARAM) &match_data, 0);
      release_frame_dc (f, dc);
851
      Vinhibit_quit = prev_quit;
Jason Rumney's avatar
Jason Rumney committed
852 853
    }

854
  return match_data.list;
Jason Rumney's avatar
Jason Rumney committed
855 856 857 858 859 860
}

/* Internal implementation of w32font_match.
   Additional parameter opentype_only restricts the returned fonts to
   opentype fonts, which can be used with the Uniscribe backend.  */
Lisp_Object
861 862
w32font_match_internal (struct frame *f, Lisp_Object font_spec,
			bool opentype_only)
Jason Rumney's avatar
Jason Rumney committed
863 864 865 866 867
{
  struct font_callback_data match_data;
  HDC dc;

  match_data.orig_font_spec = font_spec;
868
  XSETFRAME (match_data.frame, f);
Jason Rumney's avatar
Jason Rumney committed
869 870
  match_data.list = Qnil;

871
  memset (&match_data.pattern, 0, sizeof (LOGFONT));
Jason Rumney's avatar
Jason Rumney committed
872 873 874 875 876 877
  fill_in_logfont (f, &match_data.pattern, font_spec);

  match_data.opentype_only = opentype_only;
  if (opentype_only)
    match_data.pattern.lfOutPrecision = OUT_OUTLINE_PRECIS;

878 879 880 881 882 883
  /* Prevent quitting while EnumFontFamiliesEx runs and conses the
     list it will return.  That's because get_frame_dc acquires the
     critical section, so we cannot quit before we release it in
     release_frame_dc.  */
  Lisp_Object prev_quit = Vinhibit_quit;
  Vinhibit_quit = Qt;
Jason Rumney's avatar
Jason Rumney committed
884 885 886 887 888 889
  dc = get_frame_dc (f);

  EnumFontFamiliesEx (dc, &match_data.pattern,
                      (FONTENUMPROC) add_one_font_entity_to_list,
                      (LPARAM) &match_data, 0);
  release_frame_dc (f, dc);
890
  Vinhibit_quit = prev_quit;
Jason Rumney's avatar
Jason Rumney committed
891 892 893 894

  return NILP (match_data.list) ? Qnil : XCAR (match_data.list);
}

895
int
Dmitry Antipov's avatar
Dmitry Antipov committed
896
w32font_open_internal (struct frame *f, Lisp_Object font_entity,
897
		       int pixel_size, Lisp_Object font_object)
898
{
899
  int len, size;
900 901 902
  LOGFONT logfont;
  HDC dc;
  HFONT hfont, old_font;
903
  Lisp_Object val;
904 905
  struct w32font_info *w32_font;
  struct font * font;
906
  OUTLINETEXTMETRICW* metrics = NULL;
907 908 909

  w32_font = (struct w32font_info *) XFONT_OBJECT (font_object);
  font = (struct font *) w32_font;
910 911 912 913

  if (!font)
    return 0;

914
  memset (&logfont, 0, sizeof (logfont));
915 916
  fill_in_logfont (f, &logfont, font_entity);

917 918 919 920 921 922
  /* Prefer truetype fonts, to avoid known problems with type1 fonts, and
     limitations in bitmap fonts.  */
  val = AREF (font_entity, FONT_FOUNDRY_INDEX);
  if (!EQ (val, Qraster))
    logfont.lfOutPrecision = OUT_TT_PRECIS;

923 924 925 926 927 928 929 930 931 932 933 934 935 936
  size = XINT (AREF (font_entity, FONT_SIZE_INDEX));
  if (!size)
    size = pixel_size;

  logfont.lfHeight = -size;
  hfont = CreateFontIndirect (&logfont);

  if (hfont == NULL)
    return 0;

  /* Get the metrics for this font.  */
  dc = get_frame_dc (f);
  old_font = SelectObject (dc, hfont);

937
  /* Try getting the outline metrics (only works for truetype fonts).  */
938
  len = get_outline_metrics_w (dc, 0, NULL);
939 940
  if (len)
    {
941
      metrics = (OUTLINETEXTMETRICW *) alloca (len);
942
      if (get_outline_metrics_w (dc, len, metrics))
943 944
        memcpy (&w32_font->metrics, &metrics->otmTextMetrics,
		sizeof (TEXTMETRICW));
945 946 947
      else
        metrics = NULL;
    }
948

949
  if (!metrics)
950
    get_text_metrics_w (dc, &w32_font->metrics);
951

Jason Rumney's avatar
Jason Rumney committed
952 953
  w32_font->cached_metrics = NULL;
  w32_font->n_cache_blocks = 0;
954

955 956
  SelectObject (dc, old_font);
  release_frame_dc (f, dc);
957

958
  w32_font->hfont = hfont;
959

960 961 962 963 964 965
  {
    char *name;

    /* We don't know how much space we need for the full name, so start with
       96 bytes and go up in steps of 32.  */
    len = 96;
966
    name = alloca (len);
967 968
    while (name && w32font_full_name (&logfont, font_entity, pixel_size,
                                      name, len) < 0)
969
      {
970 971
        len += 32;
        name = alloca (len);
972 973
      }
    if (name)
974
      font->props[FONT_FULLNAME_INDEX]
975
        = DECODE_SYSTEM (build_string (name));
976
    else
977 978
      font->props[FONT_FULLNAME_INDEX]
	= DECODE_SYSTEM (build_string (logfont.lfFaceName));
979
  }
980 981

  font->max_width = w32_font->metrics.tmMaxCharWidth;
982
  /* Parts of Emacs display assume that height = ascent + descent...
983
     so height is defined later, after ascent and descent.
984
  font->height = w32_font->metrics.tmHeight
985
    + w32_font->metrics.tmExternalLeading;
986 987
  */

988 989 990 991 992 993
  font->space_width = font->average_width = w32_font->metrics.tmAveCharWidth;

  font->vertical_centering = 0;
  font->baseline_offset = 0;
  font->relative_compose = 0;
  font->default_ascent = w32_font->metrics.tmAscent;
994 995 996 997
  font->pixel_size = size;
  font->driver = &w32font_driver;
  font->encoding_charset = -1;
  font->repertory_charset = -1;
998
  /* TODO: do we really want the minimum width here, which could be negative? */
999
  font->min_width = font->space_width;
1000 1001
  font->ascent = w32_font->metrics.tmAscent;
  font->descent = w32_font->metrics.tmDescent;
1002
  font->height = font->ascent + font->descent;
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013

  if (metrics)
    {
      font->underline_thickness = metrics->otmsUnderscoreSize;
      font->underline_position = -metrics->otmsUnderscorePosition;
    }
  else
    {
      font->underline_thickness = 0;
      font->underline_position = -1;
    }
1014

1015 1016 1017 1018
  /* For temporary compatibility with legacy code that expects the
     name to be usable in x-list-fonts. Eventually we expect to change
     x-list-fonts and other places that use fonts so that this can be
     an fcname or similar.  */
Kenichi Handa's avatar
Kenichi Handa committed
1019
  font->props[FONT_NAME_INDEX] = Ffont_xlfd_name (font_object, Qnil);
1020

1021 1022 1023
  return 1;
}

Jason Rumney's avatar
Jason Rumney committed
1024 1025
/* Callback function for EnumFontFamiliesEx.
 * Adds the name of a font to a Lisp list (passed in as the lParam arg).  */
1026
static int CALLBACK ALIGN_STACK
1027 1028 1029
add_font_name_to_list (ENUMLOGFONTEX *logical_font,
		       NEWTEXTMETRICEX *physical_font,
		       DWORD font_type, LPARAM list_object)
Jason Rumney's avatar
Jason Rumney committed
1030 1031
{
  Lisp_Object* list = (Lisp_Object *) list_object;
1032 1033 1034 1035 1036 1037
  Lisp_Object family;

  /* Skip vertical fonts (intended only for printing)  */
  if (logical_font->elfLogFont.lfFaceName[0] == '@')
    return 1;

1038
  family = intern_font_name (logical_font->elfLogFont.lfFaceName);
Jason Rumney's avatar
Jason Rumney committed
1039 1040 1041 1042 1043 1044
  if (! memq_no_quit (family, *list))
    *list = Fcons (family, *list);

  return 1;
}

1045 1046
static int w32_decode_weight (int);
static int w32_encode_weight (int);
1047

Jason Rumney's avatar
Jason Rumney committed
1048
/* Convert an enumerated Windows font to an Emacs font entity.  */
1049
static Lisp_Object
1050 1051 1052 1053 1054 1055
w32_enumfont_pattern_entity (Lisp_Object frame,
			     ENUMLOGFONTEX *logical_font,
			     NEWTEXTMETRICEX *physical_font,
			     DWORD font_type,
			     LOGFONT *requested_font,
			     Lisp_Object backend)
Jason Rumney's avatar
Jason Rumney committed
1056 1057 1058 1059
{
  Lisp_Object entity, tem;
  LOGFONT *lf = (LOGFONT*) logical_font;
  BYTE generic_type;
1060
  DWORD full_type = physical_font->ntmTm.ntmFlags;
Jason Rumney's avatar
Jason Rumney committed
1061

1062
  entity = font_make_entity ();
Jason Rumney's avatar
Jason Rumney committed
1063

1064
  ASET (entity, FONT_TYPE_INDEX, backend);
1065
  ASET (entity, FONT_REGISTRY_INDEX, w32_registry (lf->lfCharSet, font_type));