diff options
author | Pieter van Prooijen <pieter.van.prooijen@teloden.nl> | 2022-05-08 16:27:38 +0200 |
---|---|---|
committer | Po Lu <luangruo@yahoo.com> | 2022-05-13 20:52:02 +0800 |
commit | 526e9758de7d163ce3b25fde69a4e122ce9c3742 (patch) | |
tree | 94ef87a41be88f91f76bdeaae27e5cf8eed9c26d /src/ftcrfont.c | |
parent | 784a3bde24be0637646ad0bf22f695c84b8e3e05 (diff) | |
download | emacs-526e9758de7d163ce3b25fde69a4e122ce9c3742.tar.gz |
Use gsettings font rendering entries for pgtk builds
If present, apply the gsettings font hinting and antialiasing
entries when creating a font in cairo. Do this at
initialization and when the entries change, re-rendering the
frames.
* src/ftcrfont.c (ftcrfont_open): Use the font_options derived
from gsettings when opening a font.
(ftcrfont_cached_font_ok): Report a cached font as invalid if
its font options differ from the current options inside
gsettings.
* src/xsettings.c (apply_gsettings_font_hinting)
(apply_gsettings_font_alias, apply_gsettings_font_rgba_order):
Convert the settings from GSettings to the cairo_font_options_t
object.
(init_gsettings, something_changed_gsettingsCB): Invoke the
apply functions if the relevant settings changed.
(store_font_options_changed): Store an event to re-render the
fonts.
(xsetting_get_font_options)
* src/xsettings.h (xsettings_get_font_options): New function.
Diffstat (limited to 'src/ftcrfont.c')
-rw-r--r-- | src/ftcrfont.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/ftcrfont.c b/src/ftcrfont.c index 98a28af5f22..6bb41110d5c 100644 --- a/src/ftcrfont.c +++ b/src/ftcrfont.c @@ -37,6 +37,9 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #include "font.h" #include "ftfont.h" #include "pdumper.h" +#ifdef HAVE_PGTK +#include "xsettings.h" +#endif #ifdef USE_BE_CAIRO #define RED_FROM_ULONG(color) (((color) >> 16) & 0xff) @@ -168,7 +171,12 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size) cairo_matrix_t font_matrix, ctm; cairo_matrix_init_scale (&font_matrix, pixel_size, pixel_size); cairo_matrix_init_identity (&ctm); + +#ifdef HAVE_PGTK + cairo_font_options_t *options = xsettings_get_font_options (); +#else cairo_font_options_t *options = cairo_font_options_create (); +#endif #ifdef USE_BE_CAIRO if (be_use_subpixel_antialiasing ()) cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_SUBPIXEL); @@ -624,6 +632,28 @@ ftcrfont_draw (struct glyph_string *s, return len; } +#ifdef HAVE_PGTK +/* Determine if FONT_OBJECT is a valid cached font for ENTITY by + comparing the options used to open it with the user's current + preferences specified via GSettings. */ +static bool +ftcrfont_cached_font_ok (struct frame *f, Lisp_Object font_object, + Lisp_Object entity) +{ + struct font_info *info = (struct font_info *) XFONT_OBJECT (font_object); + + cairo_font_options_t *options = cairo_font_options_create (); + cairo_scaled_font_get_font_options (info->cr_scaled_font, options); + cairo_font_options_t *gsettings_options = xsettings_get_font_options (); + + bool equal = cairo_font_options_equal (options, gsettings_options); + cairo_font_options_destroy (options); + cairo_font_options_destroy (gsettings_options); + + return equal; +} +#endif + #ifdef HAVE_HARFBUZZ static Lisp_Object @@ -694,6 +724,9 @@ struct font_driver const ftcrfont_driver = #endif .filter_properties = ftfont_filter_properties, .combining_capability = ftfont_combining_capability, +#ifdef HAVE_PGTK + .cached_font_ok = ftcrfont_cached_font_ok +#endif }; #ifdef HAVE_HARFBUZZ struct font_driver ftcrhbfont_driver; |