aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYAMAMOTO Mitsuharu2019-04-17 09:46:34 +0900
committerYAMAMOTO Mitsuharu2019-04-17 09:46:34 +0900
commitacec59c9f9c6d552c54ad448f4be898d8ee36f31 (patch)
tree1711b5e6c8da27cd4df302bcb635ce98d5293724 /src
parent6f8fe0d5acf0aa62a39b274217ac28fc1764840e (diff)
downloademacs-acec59c9f9c6d552c54ad448f4be898d8ee36f31.tar.gz
emacs-acec59c9f9c6d552c54ad448f4be898d8ee36f31.zip
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')
-rw-r--r--src/ftcrfont.c31
-rw-r--r--src/ftfont.h2
2 files changed, 25 insertions, 8 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/>. */
19 19
20#include <config.h> 20#include <config.h>
21#include <stdio.h> 21#include <stdio.h>
22#include <math.h>
22#include <cairo-ft.h> 23#include <cairo-ft.h>
23 24
24#include "lisp.h" 25#include "lisp.h"
@@ -73,7 +74,18 @@ ftcrfont_glyph_extents (struct font *font,
73 cache = ftcrfont_info->metrics[row] + col; 74 cache = ftcrfont_info->metrics[row] + col;
74 75
75 if (METRICS_STATUS (cache) == METRICS_INVALID) 76 if (METRICS_STATUS (cache) == METRICS_INVALID)
76 ftfont_text_extents (font, &glyph, 1, cache); 77 {
78 cairo_glyph_t cr_glyph = {.index = glyph, .x = 0, . y = 0};
79 cairo_text_extents_t extents;
80
81 cairo_scaled_font_glyph_extents (ftcrfont_info->cr_scaled_font,
82 &cr_glyph, 1, &extents);
83 cache->lbearing = floor (extents.x_bearing);
84 cache->rbearing = ceil (extents.width + extents.x_bearing);
85 cache->width = lround (extents.x_advance);
86 cache->ascent = ceil (extents.y_bearing);
87 cache->descent = ceil (extents.height - extents.y_bearing);
88 }
77 89
78 if (metrics) 90 if (metrics)
79 *metrics = *cache; 91 *metrics = *cache;
@@ -126,8 +138,16 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
126 FT_New_Size (ft_face, &ftcrfont_info->ft_size_draw); 138 FT_New_Size (ft_face, &ftcrfont_info->ft_size_draw);
127 FT_Activate_Size (ftcrfont_info->ft_size_draw); 139 FT_Activate_Size (ftcrfont_info->ft_size_draw);
128 FT_Set_Pixel_Sizes (ft_face, 0, font->pixel_size); 140 FT_Set_Pixel_Sizes (ft_face, 0, font->pixel_size);
129 ftcrfont_info->cr_font_face = 141 cairo_font_face_t *font_face =
130 cairo_ft_font_face_create_for_ft_face (ft_face, 0); 142 cairo_ft_font_face_create_for_ft_face (ft_face, 0);
143 cairo_matrix_t font_matrix, ctm;
144 cairo_matrix_init_scale (&font_matrix, pixel_size, pixel_size);
145 cairo_matrix_init_identity (&ctm);
146 cairo_font_options_t *options = cairo_font_options_create ();
147 ftcrfont_info->cr_scaled_font =
148 cairo_scaled_font_create (font_face, &font_matrix, &ctm, options);
149 cairo_font_face_destroy (font_face);
150 cairo_font_options_destroy (options);
131 ftcrfont_info->metrics = NULL; 151 ftcrfont_info->metrics = NULL;
132 ftcrfont_info->metrics_nrows = 0; 152 ftcrfont_info->metrics_nrows = 0;
133 unblock_input (); 153 unblock_input ();
@@ -151,7 +171,7 @@ ftcrfont_close (struct font *font)
151 if (ftcrfont_info->metrics) 171 if (ftcrfont_info->metrics)
152 xfree (ftcrfont_info->metrics); 172 xfree (ftcrfont_info->metrics);
153 FT_Done_Size (ftcrfont_info->ft_size_draw); 173 FT_Done_Size (ftcrfont_info->ft_size_draw);
154 cairo_font_face_destroy (ftcrfont_info->cr_font_face); 174 cairo_scaled_font_destroy (ftcrfont_info->cr_scaled_font);
155 unblock_input (); 175 unblock_input ();
156 176
157 ftfont_close (font); 177 ftfont_close (font);
@@ -230,10 +250,7 @@ ftcrfont_draw (struct glyph_string *s,
230 } 250 }
231 251
232 x_set_cr_source_with_gc_foreground (f, s->gc); 252 x_set_cr_source_with_gc_foreground (f, s->gc);
233 cairo_set_font_face (cr, ftcrfont_info->cr_font_face); 253 cairo_set_scaled_font (cr, ftcrfont_info->cr_scaled_font);
234 cairo_set_font_size (cr, s->font->pixel_size);
235 /* cairo_set_font_matrix */
236 /* cairo_set_font_options */
237 254
238 FT_Activate_Size (ftcrfont_info->ft_size_draw); 255 FT_Activate_Size (ftcrfont_info->ft_size_draw);
239 cairo_show_glyphs (cr, glyphs, len); 256 cairo_show_glyphs (cr, glyphs, len);
diff --git a/src/ftfont.h b/src/ftfont.h
index b6b0c5ba47b..327cd085acf 100644
--- a/src/ftfont.h
+++ b/src/ftfont.h
@@ -57,7 +57,7 @@ struct font_info
57 FT_Matrix matrix; 57 FT_Matrix matrix;
58 58
59#ifdef USE_CAIRO 59#ifdef USE_CAIRO
60 cairo_font_face_t *cr_font_face; 60 cairo_scaled_font_t *cr_scaled_font;
61 /* To prevent cairo from cluttering the activated FT_Size maintained 61 /* To prevent cairo from cluttering the activated FT_Size maintained
62 in ftfont.c, we activate this special FT_Size before drawing. */ 62 in ftfont.c, we activate this special FT_Size before drawing. */
63 FT_Size ft_size_draw; 63 FT_Size ft_size_draw;