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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4106>
This commit is contained in:
Bilal Elmoussaoui 2024-10-24 01:01:49 +02:00 committed by Marge Bot
parent 727d923f12
commit 3153708e85
4 changed files with 12 additions and 34 deletions

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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
{