summaryrefslogtreecommitdiff
path: root/src/ftcrfont.c
diff options
context:
space:
mode:
authorYAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>2019-04-17 09:46:34 +0900
committerYAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>2019-04-17 09:46:34 +0900
commitacec59c9f9c6d552c54ad448f4be898d8ee36f31 (patch)
tree1711b5e6c8da27cd4df302bcb635ce98d5293724 /src/ftcrfont.c
parent6f8fe0d5acf0aa62a39b274217ac28fc1764840e (diff)
downloademacs-acec59c9f9c6d552c54ad448f4be898d8ee36f31.tar.gz
Use cairo_scaled_font_t object for text drawing and metrics calculation
* src/ftfont.h (struct font_info): Replace member cr_font_face of type cairo_font_face_t * with cr_scaled_font of type cairo_scaled_font_t *. * src/ftcrfont.c: Include math.h for floor, ceiling, and lround. (ftcrfont_glyph_extents): Use cairo_scaled_font_glyph_extents. (ftcrfont_open): Create cairo_scaled_font_t object and set it to cr_scaled_font member of struct font_info. (ftcrfont_close): Use cairo_scaled_font_destroy. (ftcrfont_draw): Use cairo_set_scaled_font.
Diffstat (limited to 'src/ftcrfont.c')
-rw-r--r--src/ftcrfont.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/ftcrfont.c b/src/ftcrfont.c
index 3a98e78d63e..31ff8e87c01 100644
--- a/src/ftcrfont.c
+++ b/src/ftcrfont.c
@@ -19,6 +19,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#include <stdio.h>
+#include <math.h>
#include <cairo-ft.h>
#include "lisp.h"
@@ -73,7 +74,18 @@ ftcrfont_glyph_extents (struct font *font,
cache = ftcrfont_info->metrics[row] + col;
if (METRICS_STATUS (cache) == METRICS_INVALID)
- ftfont_text_extents (font, &glyph, 1, cache);
+ {
+ cairo_glyph_t cr_glyph = {.index = glyph, .x = 0, . y = 0};
+ 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);
+ cache->ascent = ceil (extents.y_bearing);
+ cache->descent = ceil (extents.height - extents.y_bearing);
+ }
if (metrics)
*metrics = *cache;
@@ -126,8 +138,16 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
FT_New_Size (ft_face, &ftcrfont_info->ft_size_draw);
FT_Activate_Size (ftcrfont_info->ft_size_draw);
FT_Set_Pixel_Sizes (ft_face, 0, font->pixel_size);
- ftcrfont_info->cr_font_face =
+ cairo_font_face_t *font_face =
cairo_ft_font_face_create_for_ft_face (ft_face, 0);
+ 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 ();
+ ftcrfont_info->cr_scaled_font =
+ cairo_scaled_font_create (font_face, &font_matrix, &ctm, options);
+ cairo_font_face_destroy (font_face);
+ cairo_font_options_destroy (options);
ftcrfont_info->metrics = NULL;
ftcrfont_info->metrics_nrows = 0;
unblock_input ();
@@ -151,7 +171,7 @@ ftcrfont_close (struct font *font)
if (ftcrfont_info->metrics)
xfree (ftcrfont_info->metrics);
FT_Done_Size (ftcrfont_info->ft_size_draw);
- cairo_font_face_destroy (ftcrfont_info->cr_font_face);
+ cairo_scaled_font_destroy (ftcrfont_info->cr_scaled_font);
unblock_input ();
ftfont_close (font);
@@ -230,10 +250,7 @@ ftcrfont_draw (struct glyph_string *s,
}
x_set_cr_source_with_gc_foreground (f, s->gc);
- cairo_set_font_face (cr, ftcrfont_info->cr_font_face);
- cairo_set_font_size (cr, s->font->pixel_size);
- /* cairo_set_font_matrix */
- /* cairo_set_font_options */
+ cairo_set_scaled_font (cr, ftcrfont_info->cr_scaled_font);
FT_Activate_Size (ftcrfont_info->ft_size_draw);
cairo_show_glyphs (cr, glyphs, len);