ftcrfont.c 18.9 KB
Newer Older
Jan D's avatar
Jan D committed
1
/* ftcrfont.c -- FreeType font driver on cairo.
Eli Zaretskii's avatar
Eli Zaretskii committed
2
   Copyright (C) 2015-2022 Free Software Foundation, Inc.
Jan D's avatar
Jan D committed
3 4 5 6 7

This file is part of GNU Emacs.

GNU Emacs is free software: you can redistribute it and/or modify
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.
Jan D's avatar
Jan D 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
17
along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
Jan D's avatar
Jan D committed
18 19 20


#include <config.h>
21
#include <math.h>
Jan D's avatar
Jan D committed
22 23 24 25 26
#include <cairo-ft.h>

#include "lisp.h"
#include "xterm.h"
#include "blockinput.h"
27
#include "charset.h"
28
#include "composite.h"
Jan D's avatar
Jan D committed
29 30
#include "font.h"
#include "ftfont.h"
Daniel Colascione's avatar
Daniel Colascione committed
31
#include "pdumper.h"
Jan D's avatar
Jan D committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

#define METRICS_NCOLS_PER_ROW	(128)

enum metrics_status
  {
    METRICS_INVALID = -1,    /* metrics entry is invalid */
  };

#define METRICS_STATUS(metrics)	((metrics)->ascent + (metrics)->descent)
#define METRICS_SET_STATUS(metrics, status) \
  ((metrics)->ascent = 0, (metrics)->descent = (status))

static int
ftcrfont_glyph_extents (struct font *font,
                        unsigned glyph,
                        struct font_metrics *metrics)
{
49
  struct font_info *ftcrfont_info = (struct font_info *) font;
Jan D's avatar
Jan D committed
50 51 52 53 54 55 56 57 58 59
  int row, col;
  struct font_metrics *cache;

  row = glyph / METRICS_NCOLS_PER_ROW;
  col = glyph % METRICS_NCOLS_PER_ROW;
  if (row >= ftcrfont_info->metrics_nrows)
    {
      ftcrfont_info->metrics =
	xrealloc (ftcrfont_info->metrics,
		  sizeof (struct font_metrics *) * (row + 1));
Paul Eggert's avatar
Paul Eggert committed
60 61 62
      memset (ftcrfont_info->metrics + ftcrfont_info->metrics_nrows, 0,
	      (sizeof (struct font_metrics *)
	       * (row + 1 - ftcrfont_info->metrics_nrows)));
Jan D's avatar
Jan D committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
      ftcrfont_info->metrics_nrows = row + 1;
    }
  if (ftcrfont_info->metrics[row] == NULL)
    {
      struct font_metrics *new;
      int i;

      new = xmalloc (sizeof (struct font_metrics) * METRICS_NCOLS_PER_ROW);
      for (i = 0; i < METRICS_NCOLS_PER_ROW; i++)
	METRICS_SET_STATUS (new + i, METRICS_INVALID);
      ftcrfont_info->metrics[row] = new;
    }
  cache = ftcrfont_info->metrics[row] + col;

  if (METRICS_STATUS (cache) == METRICS_INVALID)
78
    {
79
      cairo_glyph_t cr_glyph = {.index = glyph};
80 81 82 83 84 85 86
      cairo_text_extents_t extents;

      cairo_scaled_font_glyph_extents (ftcrfont_info->cr_scaled_font,
				       &cr_glyph, 1, &extents);
      cache->lbearing = floor (extents.x_bearing);
      cache->rbearing = ceil (extents.width + extents.x_bearing);
      cache->width = lround (extents.x_advance);
87 88 89 90 91 92
      /* The subtraction of a small number is to avoid rounding up due
	 to floating-point inaccuracies with some fonts, which then
	 could cause unpleasant effects while scrolling (see bug
	 #44284), since we then think that a glyph row's ascent is too
	 small to accommodate a glyph with a higher phys_ascent.  */
      cache->ascent = ceil (- extents.y_bearing - 1.0 / 256);
93
      cache->descent = ceil (extents.height + extents.y_bearing);
94
    }
Jan D's avatar
Jan D committed
95 96 97 98 99 100 101 102 103 104

  if (metrics)
    *metrics = *cache;

  return cache->width;
}

static Lisp_Object
ftcrfont_list (struct frame *f, Lisp_Object spec)
{
105
  return ftfont_list2 (f, spec, Qftcr);
Jan D's avatar
Jan D committed
106 107 108 109 110
}

static Lisp_Object
ftcrfont_match (struct frame *f, Lisp_Object spec)
{
111
  return ftfont_match2 (f, spec, Qftcr);
Jan D's avatar
Jan D committed
112 113 114 115 116
}

static Lisp_Object
ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
{
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
  FcResult result;
  Lisp_Object val, filename, font_object;
  FcPattern *pat, *match;
  struct font_info *ftcrfont_info;
  struct font *font;
  double size = 0;
  cairo_font_face_t *font_face;
  cairo_font_extents_t extents;
  FT_Face ft_face;
  FcMatrix *matrix;

  val = assq_no_quit (QCfont_entity, AREF (entity, FONT_EXTRA_INDEX));
  if (! CONSP (val))
    return Qnil;
  val = XCDR (val);
  filename = XCAR (val);
  size = XFIXNUM (AREF (entity, FONT_SIZE_INDEX));
Jan D's avatar
Jan D committed
134 135
  if (size == 0)
    size = pixel_size;
136

137
  block_input ();
138 139 140 141 142 143 144 145 146

  pat = ftfont_entity_pattern (entity, pixel_size);
  FcConfigSubstitute (NULL, pat, FcMatchPattern);
  FcDefaultSubstitute (pat);
  match = FcFontMatch (NULL, pat, &result);
  ftfont_fix_match (pat, match);

  FcPatternDestroy (pat);
  font_face = cairo_ft_font_face_create_for_pattern (match);
Pip Cet's avatar
Pip Cet committed
147 148
  if (!font_face
      || cairo_font_face_status (font_face) != CAIRO_STATUS_SUCCESS)
149
    {
150 151 152 153 154 155 156 157 158 159 160 161 162
      unblock_input ();
      FcPatternDestroy (match);
      return Qnil;
    }
  cairo_matrix_t font_matrix, ctm;
  cairo_matrix_init_scale (&font_matrix, pixel_size, pixel_size);
  cairo_matrix_init_identity (&ctm);
  cairo_font_options_t *options = cairo_font_options_create ();
  cairo_scaled_font_t *scaled_font
    = cairo_scaled_font_create (font_face, &font_matrix, &ctm, options);
  cairo_font_face_destroy (font_face);
  cairo_font_options_destroy (options);
  unblock_input ();
Pip Cet's avatar
Pip Cet committed
163 164 165 166 167 168 169 170 171 172 173 174
  if (!scaled_font
      || cairo_scaled_font_status (scaled_font) != CAIRO_STATUS_SUCCESS)
    {
      FcPatternDestroy (match);
      return Qnil;
    }
  ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
  if (!ft_face)
    {
      FcPatternDestroy (match);
      return Qnil;
    }
175

176
  font_object = font_build_object (VECSIZE (struct font_info),
177 178
				   AREF (entity, FONT_TYPE_INDEX),
				   entity, size);
179 180 181
  ASET (font_object, FONT_FILE_INDEX, filename);
  font = XFONT_OBJECT (font_object);
  font->pixel_size = size;
182
#ifdef HAVE_HARFBUZZ
183 184 185
  if (EQ (AREF (font_object, FONT_TYPE_INDEX), Qftcrhb))
    font->driver = &ftcrhbfont_driver;
  else
186
#endif	/* HAVE_HARFBUZZ */
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
  font->driver = &ftcrfont_driver;
  font->encoding_charset = font->repertory_charset = -1;

  ftcrfont_info = (struct font_info *) font;
  ftcrfont_info->cr_scaled_font = scaled_font;

  /* This means that there's no need of transformation.  */
  ftcrfont_info->matrix.xx = 0;
  if (FcPatternGetMatrix (match, FC_MATRIX, 0, &matrix) == FcResultMatch)
    {
      ftcrfont_info->matrix.xx = 0x10000L * matrix->xx;
      ftcrfont_info->matrix.yy = 0x10000L * matrix->yy;
      ftcrfont_info->matrix.xy = 0x10000L * matrix->xy;
      ftcrfont_info->matrix.yx = 0x10000L * matrix->yx;
    }

  ftcrfont_info->metrics = NULL;
  ftcrfont_info->metrics_nrows = 0;

206
  block_input ();
207
  cairo_glyph_t stack_glyph;
208 209
  font->min_width = font->max_width = 0;
  font->average_width = font->space_width = 0;
210
  for (char c = 32; c < 127; c++)
211
    {
212 213 214 215 216 217 218
      cairo_glyph_t *glyphs = &stack_glyph;
      int num_glyphs = 1;
      cairo_status_t status =
	cairo_scaled_font_text_to_glyphs (ftcrfont_info->cr_scaled_font,
					  0, 0, &c, 1, &glyphs, &num_glyphs,
					  NULL, NULL, NULL);

219 220 221 222 223
      /* In order to simulate the Xft behavior, we use metrics of
	 glyph ID 0 if there is no glyph for an ASCII printable.  */
      if (status != CAIRO_STATUS_SUCCESS)
	stack_glyph.index = 0;
      else if (glyphs != &stack_glyph)
224
	{
225 226
	  cairo_glyph_free (glyphs);
	  stack_glyph.index = 0;
227
	}
228 229 230 231 232
      int this_width = ftcrfont_glyph_extents (font, stack_glyph.index, NULL);
      if (this_width > 0
	  && (! font->min_width
	      || font->min_width > this_width))
	font->min_width = this_width;
233 234
      if (this_width > font->max_width)
	font->max_width = this_width;
235 236 237
      if (c == 32)
	font->space_width = this_width;
      font->average_width += this_width;
238
    }
239
  font->average_width /= 95;
240

241 242 243 244 245 246 247 248 249 250 251 252 253
  cairo_scaled_font_extents (ftcrfont_info->cr_scaled_font, &extents);
  font->ascent = lround (extents.ascent);
  val = assq_no_quit (QCminspace, AREF (entity, FONT_EXTRA_INDEX));
  if (!(CONSP (val) && NILP (XCDR (val))))
    {
      font->descent = lround (extents.descent);
      font->height = font->ascent + font->descent;
    }
  else
    {
      font->height = lround (extents.height);
      font->descent = font->height - font->ascent;
    }
254

255 256 257 258 259 260 261 262 263 264 265 266 267
  if (XFIXNUM (AREF (entity, FONT_SIZE_INDEX)) == 0)
    {
      int upEM = ft_face->units_per_EM;

      font->underline_position = -ft_face->underline_position * size / upEM;
      font->underline_thickness = ft_face->underline_thickness * size / upEM;
      if (font->underline_thickness > 2)
	font->underline_position -= font->underline_thickness / 2;
    }
  else
    {
      font->underline_position = -1;
      font->underline_thickness = 0;
268
    }
269 270 271 272
#ifdef HAVE_LIBOTF
  ftcrfont_info->maybe_otf = (ft_face->face_flags & FT_FACE_FLAG_SFNT) != 0;
  ftcrfont_info->otf = NULL;
#endif	/* HAVE_LIBOTF */
273 274 275
#ifdef HAVE_HARFBUZZ
  ftcrfont_info->hb_font = NULL;
#endif	/* HAVE_HARFBUZZ */
276 277 278 279 280 281 282
  if (ft_face->units_per_EM)
    ftcrfont_info->bitmap_position_unit = 0;
  else
    ftcrfont_info->bitmap_position_unit = (extents.height
					   / ft_face->size->metrics.height);
  cairo_ft_scaled_font_unlock_face (scaled_font);
  ftcrfont_info->ft_size = NULL;
Jan D's avatar
Jan D committed
283 284
  unblock_input ();

285 286 287 288
  font->baseline_offset = 0;
  font->relative_compose = 0;
  font->default_ascent = 0;
  font->vertical_centering = false;
289
  eassert (font->max_width < 512 * 1024 * 1024);
290

Jan D's avatar
Jan D committed
291 292 293 294 295 296
  return font_object;
}

static void
ftcrfont_close (struct font *font)
{
Paul Eggert's avatar
Paul Eggert committed
297 298 299
  if (font_data_structures_may_be_ill_formed ())
    return;

300
  struct font_info *ftcrfont_info = (struct font_info *) font;
Jan D's avatar
Jan D committed
301 302

  block_input ();
303 304 305 306 307 308
#ifdef HAVE_LIBOTF
  if (ftcrfont_info->otf)
    {
      OTF_close (ftcrfont_info->otf);
      ftcrfont_info->otf = NULL;
    }
309 310 311 312 313 314 315
#endif
#ifdef HAVE_HARFBUZZ
  if (ftcrfont_info->hb_font)
    {
      hb_font_destroy (ftcrfont_info->hb_font);
      ftcrfont_info->hb_font = NULL;
    }
316 317
#endif
  for (int i = 0; i < ftcrfont_info->metrics_nrows; i++)
Jan D's avatar
Jan D committed
318 319 320 321
    if (ftcrfont_info->metrics[i])
      xfree (ftcrfont_info->metrics[i]);
  if (ftcrfont_info->metrics)
    xfree (ftcrfont_info->metrics);
322
  cairo_scaled_font_destroy (ftcrfont_info->cr_scaled_font);
Jan D's avatar
Jan D committed
323
  unblock_input ();
324 325 326 327 328 329 330
}

static int
ftcrfont_has_char (Lisp_Object font, int c)
{
  if (FONT_ENTITY_P (font))
    return ftfont_has_char (font, c);
Jan D's avatar
Jan D committed
331

332 333 334 335 336 337 338 339 340 341 342
  struct charset *cs = NULL;

  if (EQ (AREF (font, FONT_ADSTYLE_INDEX), Qja)
      && charset_jisx0208 >= 0)
    cs = CHARSET_FROM_ID (charset_jisx0208);
  else if (EQ (AREF (font, FONT_ADSTYLE_INDEX), Qko)
      && charset_ksc5601 >= 0)
    cs = CHARSET_FROM_ID (charset_ksc5601);
  if (cs)
    return (ENCODE_CHAR (cs, c) != CHARSET_INVALID_CODE (cs));

343 344 345 346 347 348 349 350 351
  return -1;
}

static unsigned
ftcrfont_encode_char (struct font *font, int c)
{
  struct font_info *ftcrfont_info = (struct font_info *) font;
  unsigned code = FONT_INVALID_CODE;
  unsigned char utf8[MAX_MULTIBYTE_LENGTH];
352
  int utf8len = CHAR_STRING (c, utf8);
353 354 355 356 357
  cairo_glyph_t stack_glyph;
  cairo_glyph_t *glyphs = &stack_glyph;
  int num_glyphs = 1;

  if (cairo_scaled_font_text_to_glyphs (ftcrfont_info->cr_scaled_font, 0, 0,
358
					(char *) utf8, utf8len,
359 360 361 362 363 364 365 366 367
					&glyphs, &num_glyphs,
					NULL, NULL, NULL)
      == CAIRO_STATUS_SUCCESS)
    {
      if (glyphs != &stack_glyph)
	cairo_glyph_free (glyphs);
      else if (stack_glyph.index)
	code = stack_glyph.index;
    }
Jan D's avatar
Jan D committed
368

369
  return code;
Jan D's avatar
Jan D committed
370 371 372 373
}

static void
ftcrfont_text_extents (struct font *font,
374
                       const unsigned *code,
Jan D's avatar
Jan D committed
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
                       int nglyphs,
                       struct font_metrics *metrics)
{
  int width, i;

  block_input ();
  width = ftcrfont_glyph_extents (font, code[0], metrics);
  for (i = 1; i < nglyphs; i++)
    {
      struct font_metrics m;
      int w = ftcrfont_glyph_extents (font, code[i], metrics ? &m : NULL);

      if (metrics)
	{
	  if (width + m.lbearing < metrics->lbearing)
	    metrics->lbearing = width + m.lbearing;
	  if (width + m.rbearing > metrics->rbearing)
	    metrics->rbearing = width + m.rbearing;
	  if (m.ascent > metrics->ascent)
	    metrics->ascent = m.ascent;
	  if (m.descent > metrics->descent)
	    metrics->descent = m.descent;
	}
      width += w;
    }
  unblock_input ();

  if (metrics)
    metrics->width = width;
}

406 407 408 409 410 411
static int
ftcrfont_get_bitmap (struct font *font, unsigned int code,
		     struct font_bitmap *bitmap, int bits_per_pixel)
{
  struct font_info *ftcrfont_info = (struct font_info *) font;

412 413
  if (ftcrfont_info->bitmap_position_unit)
    return -1;
414

415 416 417 418 419 420 421 422 423
  cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
  FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);

  ftcrfont_info->ft_size = ft_face->size;
  int result = ftfont_get_bitmap (font, code, bitmap, bits_per_pixel);
  cairo_ft_scaled_font_unlock_face (scaled_font);
  ftcrfont_info->ft_size = NULL;

  return result;
424 425 426 427 428 429 430 431
}

static int
ftcrfont_anchor_point (struct font *font, unsigned int code, int idx,
		       int *x, int *y)
{
  struct font_info *ftcrfont_info = (struct font_info *) font;

432 433
  if (ftcrfont_info->bitmap_position_unit)
    return -1;
434

435 436 437 438 439 440 441 442 443
  cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
  FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);

  ftcrfont_info->ft_size = ft_face->size;
  int result = ftfont_anchor_point (font, code, idx, x, y);
  cairo_ft_scaled_font_unlock_face (scaled_font);
  ftcrfont_info->ft_size = NULL;

  return result;
444 445
}

446
#ifdef HAVE_LIBOTF
447
static Lisp_Object
448
ftcrfont_otf_capability (struct font *font)
449
{
450 451 452 453 454 455 456 457 458 459 460 461 462
  struct font_info *ftcrfont_info = (struct font_info *) font;
  cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
  FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);

  ftcrfont_info->ft_size = ft_face->size;
  Lisp_Object result = ftfont_otf_capability (font);
  cairo_ft_scaled_font_unlock_face (scaled_font);
  ftcrfont_info->ft_size = NULL;

  return result;
}
#endif

463
#if defined HAVE_M17N_FLT && defined HAVE_LIBOTF
464
static Lisp_Object
465
ftcrfont_shape (Lisp_Object lgstring, Lisp_Object direction)
466
{
467
  struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring));
468 469
  struct font_info *ftcrfont_info = (struct font_info *) font;

470 471 472 473 474 475 476
  if (ftcrfont_info->bitmap_position_unit)
    return make_fixnum (0);

  cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
  FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);

  ftcrfont_info->ft_size = ft_face->size;
477
  Lisp_Object result = ftfont_shape (lgstring, direction);
478 479 480 481 482
  cairo_ft_scaled_font_unlock_face (scaled_font);
  ftcrfont_info->ft_size = NULL;

  return result;
}
483 484
#endif

485
#if defined HAVE_OTF_GET_VARIATION_GLYPHS || defined HAVE_FT_FACE_GETCHARVARIANTINDEX
486 487 488 489 490 491 492 493 494 495 496 497 498
static int
ftcrfont_variation_glyphs (struct font *font, int c, unsigned variations[256])
{
  struct font_info *ftcrfont_info = (struct font_info *) font;
  cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
  FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);

  ftcrfont_info->ft_size = ft_face->size;
  int result = ftfont_variation_glyphs (font, c, variations);
  cairo_ft_scaled_font_unlock_face (scaled_font);
  ftcrfont_info->ft_size = NULL;

  return result;
499
}
500
#endif	/* HAVE_OTF_GET_VARIATION_GLYPHS || HAVE_FT_FACE_GETCHARVARIANTINDEX */
501

Jan D's avatar
Jan D committed
502 503 504 505 506 507
static int
ftcrfont_draw (struct glyph_string *s,
               int from, int to, int x, int y, bool with_background)
{
  struct frame *f = s->f;
  struct face *face = s->face;
508
  struct font_info *ftcrfont_info = (struct font_info *) s->font;
Jan D's avatar
Jan D committed
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
  cairo_t *cr;
  cairo_glyph_t *glyphs;
  int len = to - from;
  int i;

  block_input ();

  cr = x_begin_cr_clip (f, s->gc);

  if (with_background)
    {
      x_set_cr_source_with_gc_background (f, s->gc);
      cairo_rectangle (cr, x, y - FONT_BASE (face->font),
		       s->width, FONT_HEIGHT (face->font));
      cairo_fill (cr);
    }

  glyphs = alloca (sizeof (cairo_glyph_t) * len);
  for (i = 0; i < len; i++)
    {
529
      glyphs[i].index = s->char2b[from + i];
Jan D's avatar
Jan D committed
530 531
      glyphs[i].x = x;
      glyphs[i].y = y;
532 533 534
      x += (s->padding_p ? 1 : ftcrfont_glyph_extents (s->font,
                                                       glyphs[i].index,
                                                       NULL));
Jan D's avatar
Jan D committed
535 536 537
    }

  x_set_cr_source_with_gc_foreground (f, s->gc);
538
  cairo_set_scaled_font (cr, ftcrfont_info->cr_scaled_font);
Jan D's avatar
Jan D committed
539 540 541 542 543 544 545 546 547
  cairo_show_glyphs (cr, glyphs, len);

  x_end_cr_clip (f);

  unblock_input ();

  return len;
}

548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
#ifdef HAVE_HARFBUZZ

static Lisp_Object
ftcrhbfont_list (struct frame *f, Lisp_Object spec)
{
  return ftfont_list2 (f, spec, Qftcrhb);
}

static Lisp_Object
ftcrhbfont_match (struct frame *f, Lisp_Object spec)
{
  return ftfont_match2 (f, spec, Qftcrhb);
}

static hb_font_t *
ftcrhbfont_begin_hb_font (struct font *font, double *position_unit)
{
  struct font_info *ftcrfont_info = (struct font_info *) font;
566 567
  cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
  FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
568

569
  ftcrfont_info->ft_size = ft_face->size;
570
  hb_font_t *hb_font = fthbfont_begin_hb_font (font, position_unit);
571 572 573 574 575
  /* HarfBuzz 5 correctly scales bitmap-only fonts without position
     unit adjustment.
     (https://github.com/harfbuzz/harfbuzz/issues/489) */
  if (!hb_version_atleast (5, 0, 0)
      && ftcrfont_info->bitmap_position_unit)
576
    *position_unit = ftcrfont_info->bitmap_position_unit;
577 578 579 580

  return hb_font;
}

581 582 583 584 585 586 587 588 589 590
static void
ftcrhbfont_end_hb_font (struct font *font, hb_font_t *hb_font)
{
  struct font_info *ftcrfont_info = (struct font_info *) font;
  cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;

  cairo_ft_scaled_font_unlock_face (scaled_font);
  ftcrfont_info->ft_size = NULL;
}

591
#endif	/* HAVE_HARFBUZZ */
Jan D's avatar
Jan D committed
592 593


Daniel Colascione's avatar
Daniel Colascione committed
594 595
static void syms_of_ftcrfont_for_pdumper (void);

596 597
struct font_driver const ftcrfont_driver =
  {
Paul Eggert's avatar
Paul Eggert committed
598 599 600
  .type = LISPSYM_INITIALLY (Qftcr),
  .get_cache = ftfont_get_cache,
  .list = ftcrfont_list,
Eli Zaretskii's avatar
Eli Zaretskii committed
601
  .match = ftcrfont_match,
Paul Eggert's avatar
Paul Eggert committed
602
  .list_family = ftfont_list_family,
603
  .open_font = ftcrfont_open,
604
  .close_font = ftcrfont_close,
605 606
  .has_char = ftcrfont_has_char,
  .encode_char = ftcrfont_encode_char,
Paul Eggert's avatar
Paul Eggert committed
607 608
  .text_extents = ftcrfont_text_extents,
  .draw = ftcrfont_draw,
609 610
  .get_bitmap = ftcrfont_get_bitmap,
  .anchor_point = ftcrfont_anchor_point,
611
#ifdef HAVE_LIBOTF
612
  .otf_capability = ftcrfont_otf_capability,
613
#endif
614
#if defined HAVE_M17N_FLT && defined HAVE_LIBOTF
615
  .shape = ftcrfont_shape,
616
#endif
617
#if defined HAVE_OTF_GET_VARIATION_GLYPHS || defined HAVE_FT_FACE_GETCHARVARIANTINDEX
618
  .get_variation_glyphs = ftcrfont_variation_glyphs,
619
#endif
Paul Eggert's avatar
Paul Eggert committed
620 621
  .filter_properties = ftfont_filter_properties,
  .combining_capability = ftfont_combining_capability,
622
  };
623 624 625
#ifdef HAVE_HARFBUZZ
struct font_driver ftcrhbfont_driver;
#endif	/* HAVE_HARFBUZZ */
626

Jan D's avatar
Jan D committed
627 628 629 630
void
syms_of_ftcrfont (void)
{
  DEFSYM (Qftcr, "ftcr");
631 632
#ifdef HAVE_HARFBUZZ
  DEFSYM (Qftcrhb, "ftcrhb");
633
  Fput (Qftcr, Qfont_driver_superseded_by, Qftcrhb);
634
#endif	/* HAVE_HARFBUZZ */
Daniel Colascione's avatar
Daniel Colascione committed
635 636 637 638 639 640
  pdumper_do_now_and_after_load (syms_of_ftcrfont_for_pdumper);
}

static void
syms_of_ftcrfont_for_pdumper (void)
{
Jan D's avatar
Jan D committed
641
  register_font_driver (&ftcrfont_driver, NULL);
642 643 644 645 646
#ifdef HAVE_HARFBUZZ
  ftcrhbfont_driver = ftcrfont_driver;
  ftcrhbfont_driver.type = Qftcrhb;
  ftcrhbfont_driver.list = ftcrhbfont_list;
  ftcrhbfont_driver.match = ftcrhbfont_match;
647
  ftcrhbfont_driver.otf_capability = hbfont_otf_capability;
648 649
  ftcrhbfont_driver.shape = hbfont_shape;
  ftcrhbfont_driver.combining_capability = hbfont_combining_capability;
650
  ftcrhbfont_driver.begin_hb_font = ftcrhbfont_begin_hb_font;
651
  ftcrhbfont_driver.end_hb_font = ftcrhbfont_end_hb_font;
652 653
  register_font_driver (&ftcrhbfont_driver, NULL);
#endif	/* HAVE_HARFBUZZ */
Jan D's avatar
Jan D committed
654
}