1 /* ftcrfont.c -- FreeType font driver on cairo.
2    Copyright (C) 2015-2021 Free Software Foundation, Inc.
3 
4 This file is part of GNU Emacs.
5 
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or (at
9 your option) any later version.
10 
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
18 
19 
20 #include <config.h>
21 #include <math.h>
22 #include <cairo-ft.h>
23 
24 #include "lisp.h"
25 #include "xterm.h"
26 #include "blockinput.h"
27 #include "charset.h"
28 #include "composite.h"
29 #include "font.h"
30 #include "ftfont.h"
31 #include "pdumper.h"
32 
33 #define METRICS_NCOLS_PER_ROW	(128)
34 
35 enum metrics_status
36   {
37     METRICS_INVALID = -1,    /* metrics entry is invalid */
38   };
39 
40 #define METRICS_STATUS(metrics)	((metrics)->ascent + (metrics)->descent)
41 #define METRICS_SET_STATUS(metrics, status) \
42   ((metrics)->ascent = 0, (metrics)->descent = (status))
43 
44 static int
ftcrfont_glyph_extents(struct font * font,unsigned glyph,struct font_metrics * metrics)45 ftcrfont_glyph_extents (struct font *font,
46                         unsigned glyph,
47                         struct font_metrics *metrics)
48 {
49   struct font_info *ftcrfont_info = (struct font_info *) font;
50   int row, col;
51   struct font_metrics *cache;
52 
53   row = glyph / METRICS_NCOLS_PER_ROW;
54   col = glyph % METRICS_NCOLS_PER_ROW;
55   if (row >= ftcrfont_info->metrics_nrows)
56     {
57       ftcrfont_info->metrics =
58 	xrealloc (ftcrfont_info->metrics,
59 		  sizeof (struct font_metrics *) * (row + 1));
60       memset (ftcrfont_info->metrics + ftcrfont_info->metrics_nrows, 0,
61 	      (sizeof (struct font_metrics *)
62 	       * (row + 1 - ftcrfont_info->metrics_nrows)));
63       ftcrfont_info->metrics_nrows = row + 1;
64     }
65   if (ftcrfont_info->metrics[row] == NULL)
66     {
67       struct font_metrics *new;
68       int i;
69 
70       new = xmalloc (sizeof (struct font_metrics) * METRICS_NCOLS_PER_ROW);
71       for (i = 0; i < METRICS_NCOLS_PER_ROW; i++)
72 	METRICS_SET_STATUS (new + i, METRICS_INVALID);
73       ftcrfont_info->metrics[row] = new;
74     }
75   cache = ftcrfont_info->metrics[row] + col;
76 
77   if (METRICS_STATUS (cache) == METRICS_INVALID)
78     {
79       cairo_glyph_t cr_glyph = {.index = glyph};
80       cairo_text_extents_t extents;
81 
82       cairo_scaled_font_glyph_extents (ftcrfont_info->cr_scaled_font,
83 				       &cr_glyph, 1, &extents);
84       cache->lbearing = floor (extents.x_bearing);
85       cache->rbearing = ceil (extents.width + extents.x_bearing);
86       cache->width = lround (extents.x_advance);
87       cache->ascent = ceil (- extents.y_bearing);
88       cache->descent = ceil (extents.height + extents.y_bearing);
89     }
90 
91   if (metrics)
92     *metrics = *cache;
93 
94   return cache->width;
95 }
96 
97 static Lisp_Object
ftcrfont_list(struct frame * f,Lisp_Object spec)98 ftcrfont_list (struct frame *f, Lisp_Object spec)
99 {
100   return ftfont_list2 (f, spec, Qftcr);
101 }
102 
103 static Lisp_Object
ftcrfont_match(struct frame * f,Lisp_Object spec)104 ftcrfont_match (struct frame *f, Lisp_Object spec)
105 {
106   return ftfont_match2 (f, spec, Qftcr);
107 }
108 
109 static Lisp_Object
ftcrfont_open(struct frame * f,Lisp_Object entity,int pixel_size)110 ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
111 {
112   FcResult result;
113   Lisp_Object val, filename, font_object;
114   FcPattern *pat, *match;
115   struct font_info *ftcrfont_info;
116   struct font *font;
117   double size = 0;
118   cairo_font_face_t *font_face;
119   cairo_font_extents_t extents;
120   FT_Face ft_face;
121   FcMatrix *matrix;
122 
123   val = assq_no_quit (QCfont_entity, AREF (entity, FONT_EXTRA_INDEX));
124   if (! CONSP (val))
125     return Qnil;
126   val = XCDR (val);
127   filename = XCAR (val);
128   size = XFIXNUM (AREF (entity, FONT_SIZE_INDEX));
129   if (size == 0)
130     size = pixel_size;
131 
132   block_input ();
133 
134   pat = ftfont_entity_pattern (entity, pixel_size);
135   FcConfigSubstitute (NULL, pat, FcMatchPattern);
136   FcDefaultSubstitute (pat);
137   match = FcFontMatch (NULL, pat, &result);
138   ftfont_fix_match (pat, match);
139 
140   FcPatternDestroy (pat);
141   font_face = cairo_ft_font_face_create_for_pattern (match);
142   if (!font_face
143       || cairo_font_face_status (font_face) != CAIRO_STATUS_SUCCESS)
144     {
145       unblock_input ();
146       FcPatternDestroy (match);
147       return Qnil;
148     }
149   cairo_matrix_t font_matrix, ctm;
150   cairo_matrix_init_scale (&font_matrix, pixel_size, pixel_size);
151   cairo_matrix_init_identity (&ctm);
152   cairo_font_options_t *options = cairo_font_options_create ();
153   cairo_scaled_font_t *scaled_font
154     = cairo_scaled_font_create (font_face, &font_matrix, &ctm, options);
155   cairo_font_face_destroy (font_face);
156   cairo_font_options_destroy (options);
157   unblock_input ();
158   if (!scaled_font
159       || cairo_scaled_font_status (scaled_font) != CAIRO_STATUS_SUCCESS)
160     {
161       FcPatternDestroy (match);
162       return Qnil;
163     }
164   ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
165   if (!ft_face)
166     {
167       FcPatternDestroy (match);
168       return Qnil;
169     }
170 
171   font_object = font_build_object (VECSIZE (struct font_info),
172 				   AREF (entity, FONT_TYPE_INDEX),
173 				   entity, size);
174   ASET (font_object, FONT_FILE_INDEX, filename);
175   font = XFONT_OBJECT (font_object);
176   font->pixel_size = size;
177 #ifdef HAVE_HARFBUZZ
178   if (EQ (AREF (font_object, FONT_TYPE_INDEX), Qftcrhb))
179     font->driver = &ftcrhbfont_driver;
180   else
181 #endif	/* HAVE_HARFBUZZ */
182   font->driver = &ftcrfont_driver;
183   font->encoding_charset = font->repertory_charset = -1;
184 
185   ftcrfont_info = (struct font_info *) font;
186   ftcrfont_info->cr_scaled_font = scaled_font;
187 
188   /* This means that there's no need of transformation.  */
189   ftcrfont_info->matrix.xx = 0;
190   if (FcPatternGetMatrix (match, FC_MATRIX, 0, &matrix) == FcResultMatch)
191     {
192       ftcrfont_info->matrix.xx = 0x10000L * matrix->xx;
193       ftcrfont_info->matrix.yy = 0x10000L * matrix->yy;
194       ftcrfont_info->matrix.xy = 0x10000L * matrix->xy;
195       ftcrfont_info->matrix.yx = 0x10000L * matrix->yx;
196     }
197 
198   ftcrfont_info->metrics = NULL;
199   ftcrfont_info->metrics_nrows = 0;
200 
201   block_input ();
202   cairo_glyph_t stack_glyph;
203   font->min_width = font->average_width = font->space_width = 0;
204   for (char c = 32; c < 127; c++)
205     {
206       cairo_glyph_t *glyphs = &stack_glyph;
207       int num_glyphs = 1;
208       cairo_status_t status =
209 	cairo_scaled_font_text_to_glyphs (ftcrfont_info->cr_scaled_font,
210 					  0, 0, &c, 1, &glyphs, &num_glyphs,
211 					  NULL, NULL, NULL);
212 
213       /* In order to simulate the Xft behavior, we use metrics of
214 	 glyph ID 0 if there is no glyph for an ASCII printable.  */
215       if (status != CAIRO_STATUS_SUCCESS)
216 	stack_glyph.index = 0;
217       else if (glyphs != &stack_glyph)
218 	{
219 	  cairo_glyph_free (glyphs);
220 	  stack_glyph.index = 0;
221 	}
222       int this_width = ftcrfont_glyph_extents (font, stack_glyph.index, NULL);
223       if (this_width > 0
224 	  && (! font->min_width
225 	      || font->min_width > this_width))
226 	font->min_width = this_width;
227       if (c == 32)
228 	font->space_width = this_width;
229       font->average_width += this_width;
230     }
231   font->average_width /= 95;
232 
233   cairo_scaled_font_extents (ftcrfont_info->cr_scaled_font, &extents);
234   font->ascent = lround (extents.ascent);
235   val = assq_no_quit (QCminspace, AREF (entity, FONT_EXTRA_INDEX));
236   if (!(CONSP (val) && NILP (XCDR (val))))
237     {
238       font->descent = lround (extents.descent);
239       font->height = font->ascent + font->descent;
240     }
241   else
242     {
243       font->height = lround (extents.height);
244       font->descent = font->height - font->ascent;
245     }
246 
247   if (XFIXNUM (AREF (entity, FONT_SIZE_INDEX)) == 0)
248     {
249       int upEM = ft_face->units_per_EM;
250 
251       font->underline_position = -ft_face->underline_position * size / upEM;
252       font->underline_thickness = ft_face->underline_thickness * size / upEM;
253       if (font->underline_thickness > 2)
254 	font->underline_position -= font->underline_thickness / 2;
255     }
256   else
257     {
258       font->underline_position = -1;
259       font->underline_thickness = 0;
260     }
261 #ifdef HAVE_LIBOTF
262   ftcrfont_info->maybe_otf = (ft_face->face_flags & FT_FACE_FLAG_SFNT) != 0;
263   ftcrfont_info->otf = NULL;
264 #endif	/* HAVE_LIBOTF */
265 #ifdef HAVE_HARFBUZZ
266   ftcrfont_info->hb_font = NULL;
267 #endif	/* HAVE_HARFBUZZ */
268   if (ft_face->units_per_EM)
269     ftcrfont_info->bitmap_position_unit = 0;
270   else
271     ftcrfont_info->bitmap_position_unit = (extents.height
272 					   / ft_face->size->metrics.height);
273   cairo_ft_scaled_font_unlock_face (scaled_font);
274   ftcrfont_info->ft_size = NULL;
275   unblock_input ();
276 
277   font->baseline_offset = 0;
278   font->relative_compose = 0;
279   font->default_ascent = 0;
280   font->vertical_centering = false;
281 
282   return font_object;
283 }
284 
285 static void
ftcrfont_close(struct font * font)286 ftcrfont_close (struct font *font)
287 {
288   if (font_data_structures_may_be_ill_formed ())
289     return;
290 
291   struct font_info *ftcrfont_info = (struct font_info *) font;
292 
293   block_input ();
294 #ifdef HAVE_LIBOTF
295   if (ftcrfont_info->otf)
296     {
297       OTF_close (ftcrfont_info->otf);
298       ftcrfont_info->otf = NULL;
299     }
300 #endif
301 #ifdef HAVE_HARFBUZZ
302   if (ftcrfont_info->hb_font)
303     {
304       hb_font_destroy (ftcrfont_info->hb_font);
305       ftcrfont_info->hb_font = NULL;
306     }
307 #endif
308   for (int i = 0; i < ftcrfont_info->metrics_nrows; i++)
309     if (ftcrfont_info->metrics[i])
310       xfree (ftcrfont_info->metrics[i]);
311   if (ftcrfont_info->metrics)
312     xfree (ftcrfont_info->metrics);
313   cairo_scaled_font_destroy (ftcrfont_info->cr_scaled_font);
314   unblock_input ();
315 }
316 
317 static int
ftcrfont_has_char(Lisp_Object font,int c)318 ftcrfont_has_char (Lisp_Object font, int c)
319 {
320   if (FONT_ENTITY_P (font))
321     return ftfont_has_char (font, c);
322 
323   struct charset *cs = NULL;
324 
325   if (EQ (AREF (font, FONT_ADSTYLE_INDEX), Qja)
326       && charset_jisx0208 >= 0)
327     cs = CHARSET_FROM_ID (charset_jisx0208);
328   else if (EQ (AREF (font, FONT_ADSTYLE_INDEX), Qko)
329       && charset_ksc5601 >= 0)
330     cs = CHARSET_FROM_ID (charset_ksc5601);
331   if (cs)
332     return (ENCODE_CHAR (cs, c) != CHARSET_INVALID_CODE (cs));
333 
334   return -1;
335 }
336 
337 static unsigned
ftcrfont_encode_char(struct font * font,int c)338 ftcrfont_encode_char (struct font *font, int c)
339 {
340   struct font_info *ftcrfont_info = (struct font_info *) font;
341   unsigned code = FONT_INVALID_CODE;
342   unsigned char utf8[MAX_MULTIBYTE_LENGTH];
343   unsigned char *p = utf8;
344   cairo_glyph_t stack_glyph;
345   cairo_glyph_t *glyphs = &stack_glyph;
346   int num_glyphs = 1;
347 
348   CHAR_STRING_ADVANCE (c, p);
349   if (cairo_scaled_font_text_to_glyphs (ftcrfont_info->cr_scaled_font, 0, 0,
350 					(char *) utf8, p - utf8,
351 					&glyphs, &num_glyphs,
352 					NULL, NULL, NULL)
353       == CAIRO_STATUS_SUCCESS)
354     {
355       if (glyphs != &stack_glyph)
356 	cairo_glyph_free (glyphs);
357       else if (stack_glyph.index)
358 	code = stack_glyph.index;
359     }
360 
361   return code;
362 }
363 
364 static void
ftcrfont_text_extents(struct font * font,const unsigned * code,int nglyphs,struct font_metrics * metrics)365 ftcrfont_text_extents (struct font *font,
366                        const unsigned *code,
367                        int nglyphs,
368                        struct font_metrics *metrics)
369 {
370   int width, i;
371 
372   block_input ();
373   width = ftcrfont_glyph_extents (font, code[0], metrics);
374   for (i = 1; i < nglyphs; i++)
375     {
376       struct font_metrics m;
377       int w = ftcrfont_glyph_extents (font, code[i], metrics ? &m : NULL);
378 
379       if (metrics)
380 	{
381 	  if (width + m.lbearing < metrics->lbearing)
382 	    metrics->lbearing = width + m.lbearing;
383 	  if (width + m.rbearing > metrics->rbearing)
384 	    metrics->rbearing = width + m.rbearing;
385 	  if (m.ascent > metrics->ascent)
386 	    metrics->ascent = m.ascent;
387 	  if (m.descent > metrics->descent)
388 	    metrics->descent = m.descent;
389 	}
390       width += w;
391     }
392   unblock_input ();
393 
394   if (metrics)
395     metrics->width = width;
396 }
397 
398 static int
ftcrfont_get_bitmap(struct font * font,unsigned int code,struct font_bitmap * bitmap,int bits_per_pixel)399 ftcrfont_get_bitmap (struct font *font, unsigned int code,
400 		     struct font_bitmap *bitmap, int bits_per_pixel)
401 {
402   struct font_info *ftcrfont_info = (struct font_info *) font;
403 
404   if (ftcrfont_info->bitmap_position_unit)
405     return -1;
406 
407   cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
408   FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
409 
410   ftcrfont_info->ft_size = ft_face->size;
411   int result = ftfont_get_bitmap (font, code, bitmap, bits_per_pixel);
412   cairo_ft_scaled_font_unlock_face (scaled_font);
413   ftcrfont_info->ft_size = NULL;
414 
415   return result;
416 }
417 
418 static int
ftcrfont_anchor_point(struct font * font,unsigned int code,int idx,int * x,int * y)419 ftcrfont_anchor_point (struct font *font, unsigned int code, int idx,
420 		       int *x, int *y)
421 {
422   struct font_info *ftcrfont_info = (struct font_info *) font;
423 
424   if (ftcrfont_info->bitmap_position_unit)
425     return -1;
426 
427   cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
428   FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
429 
430   ftcrfont_info->ft_size = ft_face->size;
431   int result = ftfont_anchor_point (font, code, idx, x, y);
432   cairo_ft_scaled_font_unlock_face (scaled_font);
433   ftcrfont_info->ft_size = NULL;
434 
435   return result;
436 }
437 
438 #ifdef HAVE_LIBOTF
439 static Lisp_Object
ftcrfont_otf_capability(struct font * font)440 ftcrfont_otf_capability (struct font *font)
441 {
442   struct font_info *ftcrfont_info = (struct font_info *) font;
443   cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
444   FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
445 
446   ftcrfont_info->ft_size = ft_face->size;
447   Lisp_Object result = ftfont_otf_capability (font);
448   cairo_ft_scaled_font_unlock_face (scaled_font);
449   ftcrfont_info->ft_size = NULL;
450 
451   return result;
452 }
453 #endif
454 
455 #if defined HAVE_M17N_FLT && defined HAVE_LIBOTF
456 static Lisp_Object
ftcrfont_shape(Lisp_Object lgstring,Lisp_Object direction)457 ftcrfont_shape (Lisp_Object lgstring, Lisp_Object direction)
458 {
459   struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring));
460   struct font_info *ftcrfont_info = (struct font_info *) font;
461 
462   if (ftcrfont_info->bitmap_position_unit)
463     return make_fixnum (0);
464 
465   cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
466   FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
467 
468   ftcrfont_info->ft_size = ft_face->size;
469   Lisp_Object result = ftfont_shape (lgstring, direction);
470   cairo_ft_scaled_font_unlock_face (scaled_font);
471   ftcrfont_info->ft_size = NULL;
472 
473   return result;
474 }
475 #endif
476 
477 #if defined HAVE_OTF_GET_VARIATION_GLYPHS || defined HAVE_FT_FACE_GETCHARVARIANTINDEX
478 static int
ftcrfont_variation_glyphs(struct font * font,int c,unsigned variations[256])479 ftcrfont_variation_glyphs (struct font *font, int c, unsigned variations[256])
480 {
481   struct font_info *ftcrfont_info = (struct font_info *) font;
482   cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
483   FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
484 
485   ftcrfont_info->ft_size = ft_face->size;
486   int result = ftfont_variation_glyphs (font, c, variations);
487   cairo_ft_scaled_font_unlock_face (scaled_font);
488   ftcrfont_info->ft_size = NULL;
489 
490   return result;
491 }
492 #endif	/* HAVE_OTF_GET_VARIATION_GLYPHS || HAVE_FT_FACE_GETCHARVARIANTINDEX */
493 
494 static int
ftcrfont_draw(struct glyph_string * s,int from,int to,int x,int y,bool with_background)495 ftcrfont_draw (struct glyph_string *s,
496                int from, int to, int x, int y, bool with_background)
497 {
498   struct frame *f = s->f;
499   struct face *face = s->face;
500   struct font_info *ftcrfont_info = (struct font_info *) s->font;
501   cairo_t *cr;
502   cairo_glyph_t *glyphs;
503   int len = to - from;
504   int i;
505 
506   block_input ();
507 
508   cr = x_begin_cr_clip (f, s->gc);
509 
510   if (with_background)
511     {
512       x_set_cr_source_with_gc_background (f, s->gc);
513       cairo_rectangle (cr, x, y - FONT_BASE (face->font),
514 		       s->width, FONT_HEIGHT (face->font));
515       cairo_fill (cr);
516     }
517 
518   glyphs = alloca (sizeof (cairo_glyph_t) * len);
519   for (i = 0; i < len; i++)
520     {
521       glyphs[i].index = s->char2b[from + i];
522       glyphs[i].x = x;
523       glyphs[i].y = y;
524       x += (s->padding_p ? 1 : ftcrfont_glyph_extents (s->font,
525                                                        glyphs[i].index,
526                                                        NULL));
527     }
528 
529   x_set_cr_source_with_gc_foreground (f, s->gc);
530   cairo_set_scaled_font (cr, ftcrfont_info->cr_scaled_font);
531   cairo_show_glyphs (cr, glyphs, len);
532 
533   x_end_cr_clip (f);
534 
535   unblock_input ();
536 
537   return len;
538 }
539 
540 #ifdef HAVE_HARFBUZZ
541 
542 static Lisp_Object
ftcrhbfont_list(struct frame * f,Lisp_Object spec)543 ftcrhbfont_list (struct frame *f, Lisp_Object spec)
544 {
545   return ftfont_list2 (f, spec, Qftcrhb);
546 }
547 
548 static Lisp_Object
ftcrhbfont_match(struct frame * f,Lisp_Object spec)549 ftcrhbfont_match (struct frame *f, Lisp_Object spec)
550 {
551   return ftfont_match2 (f, spec, Qftcrhb);
552 }
553 
554 static hb_font_t *
ftcrhbfont_begin_hb_font(struct font * font,double * position_unit)555 ftcrhbfont_begin_hb_font (struct font *font, double *position_unit)
556 {
557   struct font_info *ftcrfont_info = (struct font_info *) font;
558   cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
559   FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
560 
561   ftcrfont_info->ft_size = ft_face->size;
562   hb_font_t *hb_font = fthbfont_begin_hb_font (font, position_unit);
563   if (ftcrfont_info->bitmap_position_unit)
564     *position_unit = ftcrfont_info->bitmap_position_unit;
565 
566   return hb_font;
567 }
568 
569 static void
ftcrhbfont_end_hb_font(struct font * font,hb_font_t * hb_font)570 ftcrhbfont_end_hb_font (struct font *font, hb_font_t *hb_font)
571 {
572   struct font_info *ftcrfont_info = (struct font_info *) font;
573   cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
574 
575   cairo_ft_scaled_font_unlock_face (scaled_font);
576   ftcrfont_info->ft_size = NULL;
577 }
578 
579 #endif	/* HAVE_HARFBUZZ */
580 
581 
582 static void syms_of_ftcrfont_for_pdumper (void);
583 
584 struct font_driver const ftcrfont_driver =
585   {
586   .type = LISPSYM_INITIALLY (Qftcr),
587   .get_cache = ftfont_get_cache,
588   .list = ftcrfont_list,
589   .match = ftcrfont_match,
590   .list_family = ftfont_list_family,
591   .open_font = ftcrfont_open,
592   .close_font = ftcrfont_close,
593   .has_char = ftcrfont_has_char,
594   .encode_char = ftcrfont_encode_char,
595   .text_extents = ftcrfont_text_extents,
596   .draw = ftcrfont_draw,
597   .get_bitmap = ftcrfont_get_bitmap,
598   .anchor_point = ftcrfont_anchor_point,
599 #ifdef HAVE_LIBOTF
600   .otf_capability = ftcrfont_otf_capability,
601 #endif
602 #if defined HAVE_M17N_FLT && defined HAVE_LIBOTF
603   .shape = ftcrfont_shape,
604 #endif
605 #if defined HAVE_OTF_GET_VARIATION_GLYPHS || defined HAVE_FT_FACE_GETCHARVARIANTINDEX
606   .get_variation_glyphs = ftcrfont_variation_glyphs,
607 #endif
608   .filter_properties = ftfont_filter_properties,
609   .combining_capability = ftfont_combining_capability,
610   };
611 #ifdef HAVE_HARFBUZZ
612 struct font_driver ftcrhbfont_driver;
613 #endif	/* HAVE_HARFBUZZ */
614 
615 void
syms_of_ftcrfont(void)616 syms_of_ftcrfont (void)
617 {
618   DEFSYM (Qftcr, "ftcr");
619 #ifdef HAVE_HARFBUZZ
620   DEFSYM (Qftcrhb, "ftcrhb");
621   Fput (Qftcr, Qfont_driver_superseded_by, Qftcrhb);
622 #endif	/* HAVE_HARFBUZZ */
623   pdumper_do_now_and_after_load (syms_of_ftcrfont_for_pdumper);
624 }
625 
626 static void
syms_of_ftcrfont_for_pdumper(void)627 syms_of_ftcrfont_for_pdumper (void)
628 {
629   register_font_driver (&ftcrfont_driver, NULL);
630 #ifdef HAVE_HARFBUZZ
631   ftcrhbfont_driver = ftcrfont_driver;
632   ftcrhbfont_driver.type = Qftcrhb;
633   ftcrhbfont_driver.list = ftcrhbfont_list;
634   ftcrhbfont_driver.match = ftcrhbfont_match;
635   ftcrhbfont_driver.otf_capability = hbfont_otf_capability;
636   ftcrhbfont_driver.shape = hbfont_shape;
637   ftcrhbfont_driver.combining_capability = hbfont_combining_capability;
638   ftcrhbfont_driver.begin_hb_font = ftcrhbfont_begin_hb_font;
639   ftcrhbfont_driver.end_hb_font = ftcrhbfont_end_hb_font;
640   register_font_driver (&ftcrhbfont_driver, NULL);
641 #endif	/* HAVE_HARFBUZZ */
642 }
643