diff options
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> | 2019-04-20 12:43:45 +0900 |
---|---|---|
committer | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> | 2019-04-20 12:43:45 +0900 |
commit | d1dde7d04e5244179735592adc11d2a6f0af64ac (patch) | |
tree | 474c1999fd436600d77c20b41c8edab0b8929555 /src/ftfont.c | |
parent | 69771b4e6acfe2998e4c3c30e07fb4600d42515d (diff) | |
download | emacs-d1dde7d04e5244179735592adc11d2a6f0af64ac.tar.gz |
Use bitmap strikes as fallbacks for ftcr font backend
* src/ftfont.h (struct font_info): New member bitmap_strike_index.
* src/ftfont.c (ftfont_open2): Try bitmap strikes as fallbacks.
(ftfont_open): Discard bitmap strikes.
* src/ftcrfont.c (ftcrfont_open): Recalculate metrics for bitmap strikes.
(ftcrfont_get_bitmap, ftcrfont_anchor_point, ftcrfont_shape): New functions.
(struct font_driver): Use them.
Diffstat (limited to 'src/ftfont.c')
-rw-r--r-- | src/ftfont.c | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/src/ftfont.c b/src/ftfont.c index 3e820f583ff..d0078a37701 100644 --- a/src/ftfont.c +++ b/src/ftfont.c @@ -1097,6 +1097,7 @@ ftfont_open2 (struct frame *f, int spacing; int i; double upEM; + FT_Int strike_index = -1; val = assq_no_quit (QCfont_entity, AREF (entity, FONT_EXTRA_INDEX)); if (! CONSP (val)) @@ -1126,12 +1127,32 @@ ftfont_open2 (struct frame *f, size = pixel_size; if (FT_Set_Pixel_Sizes (ft_face, size, size) != 0) { - if (cache_data->face_refcount == 0) + int min_distance = INT_MAX; + bool magnify = true; + + for (FT_Int i = 0; i < ft_face->num_fixed_sizes; i++) { - FT_Done_Face (ft_face); - cache_data->ft_face = NULL; + int distance = ft_face->available_sizes[i].height - (int) size; + + /* Prefer down-scaling to upscaling. */ + if (magnify == (distance < 0) ? abs (distance) <= min_distance + : magnify) + { + magnify = distance < 0; + min_distance = abs (distance); + strike_index = i; + } + } + + if (strike_index < 0 || FT_Select_Size (ft_face, strike_index) != 0) + { + if (cache_data->face_refcount == 0) + { + FT_Done_Face (ft_face); + cache_data->ft_face = NULL; + } + return Qnil; } - return Qnil; } cache_data->face_refcount++; @@ -1144,6 +1165,7 @@ ftfont_open2 (struct frame *f, ftfont_info->maybe_otf = (ft_face->face_flags & FT_FACE_FLAG_SFNT) != 0; ftfont_info->otf = NULL; #endif /* HAVE_LIBOTF */ + ftfont_info->bitmap_strike_index = strike_index; /* This means that there's no need of transformation. */ ftfont_info->matrix.xx = 0; font->pixel_size = size; @@ -1229,7 +1251,19 @@ ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) size = pixel_size; font_object = font_build_object (VECSIZE (struct font_info), Qfreetype, entity, size); - return ftfont_open2 (f, entity, pixel_size, font_object); + font_object = ftfont_open2 (f, entity, pixel_size, font_object); + if (FONT_OBJECT_P (font_object)) + { + struct font *font = XFONT_OBJECT (font_object); + struct font_info *ftfont_info = (struct font_info *) font; + + if (ftfont_info->bitmap_strike_index >= 0) + { + ftfont_close (font); + font_object = Qnil; + } + } + return font_object; } void |