From 3153708e85c44df402cfad463889023e0ace8d45 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Thu, 24 Oct 2024 01:01:49 +0200 Subject: [PATCH] clutter/backend: Initialize default font options if no schema found When the `org.gnome.desktop.interface` schema is not found, currently we were not initializing the font_options which means we needed to handle that on the backend side. Instead, generate the font_options at that moment. As the settings are loaded the moment we assign a backend to the settings `_clutter_settings_set_backend` which is called just after the backend is constructed which is too early for any actor to use it for creating a PangoContext, so the change is safe. Also, as the font_options getter is only used in ClutterActor when creating the PangoContext, drop the getter. As we might just store that info somewhere else in the future. Part-of: --- clutter/clutter/clutter-actor.c | 4 +--- clutter/clutter/clutter-backend-private.h | 2 -- clutter/clutter/clutter-backend.c | 29 ----------------------- clutter/clutter/clutter-settings.c | 11 +++++++++ 4 files changed, 12 insertions(+), 34 deletions(-) diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c index 20db23308..ecd869f82 100644 --- a/clutter/clutter/clutter-actor.c +++ b/clutter/clutter/clutter-actor.c @@ -13001,7 +13001,6 @@ update_pango_context (ClutterBackend *backend, { ClutterSettings *settings; PangoFontDescription *font_desc; - const cairo_font_options_t *font_options; ClutterTextDirection dir; PangoDirection pango_dir; g_autofree char *font_name = NULL; @@ -13018,7 +13017,6 @@ update_pango_context (ClutterBackend *backend, g_object_get (settings, "font-name", &font_name, NULL); /* get the configuration for the PangoContext from the backend */ - font_options = clutter_backend_get_font_options (backend); resolution = clutter_backend_get_resolution (backend); font_desc = pango_font_description_from_string (font_name); @@ -13027,7 +13025,7 @@ update_pango_context (ClutterBackend *backend, resolution = 96.0; /* fall back */ pango_context_set_font_description (context, font_desc); - pango_cairo_context_set_font_options (context, font_options); + pango_cairo_context_set_font_options (context, backend->font_options); pango_cairo_context_set_resolution (context, resolution); pango_font_description_free (font_desc); diff --git a/clutter/clutter/clutter-backend-private.h b/clutter/clutter/clutter-backend-private.h index 6f4ae506f..b63bb07fb 100644 --- a/clutter/clutter/clutter-backend-private.h +++ b/clutter/clutter/clutter-backend-private.h @@ -105,6 +105,4 @@ void clutter_backend_destroy (ClutterBackend *backend); void clutter_backend_set_font_options (ClutterBackend *backend, const cairo_font_options_t *options); -const cairo_font_options_t * clutter_backend_get_font_options (ClutterBackend *backend); - G_END_DECLS diff --git a/clutter/clutter/clutter-backend.c b/clutter/clutter/clutter-backend.c index 0e3c76513..78de4797b 100644 --- a/clutter/clutter/clutter-backend.c +++ b/clutter/clutter/clutter-backend.c @@ -413,35 +413,6 @@ clutter_backend_set_font_options (ClutterBackend *backend, } } -/** - * clutter_backend_get_font_options: - * @backend: a #ClutterBackend - * - * Retrieves the font options for @backend. - * - * Return value: (transfer none): the font options of the #ClutterBackend. - * The returned #cairo_font_options_t is owned by the backend and should - * not be modified or freed - */ -const cairo_font_options_t * -clutter_backend_get_font_options (ClutterBackend *backend) -{ - g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL); - - if (G_LIKELY (backend->font_options)) - return backend->font_options; - - backend->font_options = cairo_font_options_create (); - - cairo_font_options_set_hint_style (backend->font_options, CAIRO_HINT_STYLE_NONE); - cairo_font_options_set_subpixel_order (backend->font_options, CAIRO_SUBPIXEL_ORDER_DEFAULT); - cairo_font_options_set_antialias (backend->font_options, CAIRO_ANTIALIAS_DEFAULT); - - g_signal_emit (backend, backend_signals[FONT_CHANGED], 0); - - return backend->font_options; -} - /** * clutter_backend_get_cogl_context: * @backend: a #ClutterBackend diff --git a/clutter/clutter/clutter-settings.c b/clutter/clutter/clutter-settings.c index ed1cc268e..89f200268 100644 --- a/clutter/clutter/clutter-settings.c +++ b/clutter/clutter/clutter-settings.c @@ -365,7 +365,18 @@ load_initial_settings (ClutterSettings *self) schema = g_settings_schema_source_lookup (source, font_settings_path, TRUE); if (!schema) { + cairo_font_options_t *font_options; + g_warning ("Failed to find schema: %s", font_settings_path); + + /* Fallback to the default options */ + font_options = cairo_font_options_create (); + cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE); + cairo_font_options_set_subpixel_order (font_options, CAIRO_SUBPIXEL_ORDER_DEFAULT); + cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_DEFAULT); + clutter_backend_set_font_options (self->backend, font_options); + + cairo_font_options_destroy (font_options); } else {