Commit acec59c9 authored by YAMAMOTO Mitsuharu's avatar YAMAMOTO Mitsuharu

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.
parent 6f8fe0d5
Pipeline #1320 failed with stage
in 50 minutes and 11 seconds
......@@ -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);
......
......@@ -57,7 +57,7 @@ struct font_info
FT_Matrix matrix;
#ifdef USE_CAIRO
cairo_font_face_t *cr_font_face;
cairo_scaled_font_t *cr_scaled_font;
/* To prevent cairo from cluttering the activated FT_Size maintained
in ftfont.c, we activate this special FT_Size before drawing. */
FT_Size ft_size_draw;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment