clutter: Prefer using ClutterTextDirection

In various public APIs, Clutter used to return a PangoDirection
while we have a text direction enum defined in Clutter.

This allows us to drop pango dependency from meta making it specific
to cogl-pango & clutter

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3531>
This commit is contained in:
Bilal Elmoussaoui 2024-01-17 16:39:21 +01:00 committed by Marge Bot
parent c19eef3f5e
commit a2397e6b80
13 changed files with 76 additions and 63 deletions

View File

@ -12891,17 +12891,16 @@ update_pango_context (ClutterBackend *backend,
ClutterSettings *settings; ClutterSettings *settings;
PangoFontDescription *font_desc; PangoFontDescription *font_desc;
const cairo_font_options_t *font_options; const cairo_font_options_t *font_options;
gchar *font_name; ClutterTextDirection dir;
PangoDirection pango_dir; PangoDirection pango_dir;
gchar *font_name;
gdouble resolution; gdouble resolution;
settings = clutter_settings_get_default (); settings = clutter_settings_get_default ();
/* update the text direction */ /* update the text direction */
if (clutter_get_default_text_direction () == CLUTTER_TEXT_DIRECTION_RTL) dir = clutter_get_default_text_direction ();
pango_dir = PANGO_DIRECTION_RTL; pango_dir = clutter_text_direction_to_pango_direction (dir);
else
pango_dir = PANGO_DIRECTION_LTR;
pango_context_set_base_dir (context, pango_dir); pango_context_set_base_dir (context, pango_dir);

View File

@ -28,7 +28,6 @@
#endif #endif
#include <cairo.h> #include <cairo.h>
#include <pango/pango.h>
#include "cogl/cogl.h" #include "cogl/cogl.h"

View File

@ -147,7 +147,7 @@ clutter_keymap_get_caps_lock_state (ClutterKeymap *keymap)
return priv->caps_lock_state; return priv->caps_lock_state;
} }
PangoDirection ClutterTextDirection
clutter_keymap_get_direction (ClutterKeymap *keymap) clutter_keymap_get_direction (ClutterKeymap *keymap)
{ {
return CLUTTER_KEYMAP_GET_CLASS (keymap)->get_direction (keymap); return CLUTTER_KEYMAP_GET_CLASS (keymap)->get_direction (keymap);

View File

@ -23,10 +23,11 @@
#error "Only <clutter/clutter.h> can be included directly." #error "Only <clutter/clutter.h> can be included directly."
#endif #endif
#include <glib-object.h>
#include "clutter/clutter-enums.h"
#include "clutter/clutter-macros.h" #include "clutter/clutter-macros.h"
#include <glib-object.h>
#include <pango/pango.h>
typedef struct _ClutterKeymap ClutterKeymap; typedef struct _ClutterKeymap ClutterKeymap;
typedef struct _ClutterKeymapClass ClutterKeymapClass; typedef struct _ClutterKeymapClass ClutterKeymapClass;
@ -35,7 +36,7 @@ struct _ClutterKeymapClass
{ {
GObjectClass parent_class; GObjectClass parent_class;
PangoDirection (* get_direction) (ClutterKeymap *keymap); ClutterTextDirection (* get_direction) (ClutterKeymap *keymap);
}; };
#define CLUTTER_TYPE_KEYMAP (clutter_keymap_get_type ()) #define CLUTTER_TYPE_KEYMAP (clutter_keymap_get_type ())
@ -50,4 +51,4 @@ gboolean clutter_keymap_get_num_lock_state (ClutterKeymap *keymap);
CLUTTER_EXPORT CLUTTER_EXPORT
gboolean clutter_keymap_get_caps_lock_state (ClutterKeymap *keymap); gboolean clutter_keymap_get_caps_lock_state (ClutterKeymap *keymap);
PangoDirection clutter_keymap_get_direction (ClutterKeymap *keymap); ClutterTextDirection clutter_keymap_get_direction (ClutterKeymap *keymap);

View File

@ -50,7 +50,6 @@
#include "config.h" #include "config.h"
#include <gobject/gvaluecollector.h> #include <gobject/gvaluecollector.h>
#include <pango/pango.h>
#include "cogl/cogl.h" #include "cogl/cogl.h"
#include "clutter/clutter-paint-node-private.h" #include "clutter/clutter-paint-node-private.h"

View File

@ -27,6 +27,7 @@
#include <string.h> #include <string.h>
#include <glib.h> #include <glib.h>
#include <pango/pango.h>
#include "cogl-pango/cogl-pango.h" #include "cogl-pango/cogl-pango.h"
@ -145,10 +146,13 @@ void _clutter_util_fully_transform_vertices (const graphene_matrix_t *modelvie
int n_vertices); int n_vertices);
CLUTTER_EXPORT CLUTTER_EXPORT
PangoDirection _clutter_pango_unichar_direction (gunichar ch); ClutterTextDirection clutter_unichar_direction (gunichar ch);
PangoDirection _clutter_pango_find_base_dir (const gchar *text, ClutterTextDirection _clutter_find_base_dir (const gchar *text,
gint length); gint length);
PangoDirection
clutter_text_direction_to_pango_direction (ClutterTextDirection dir);
typedef enum _ClutterCullResult typedef enum _ClutterCullResult
{ {

View File

@ -732,17 +732,18 @@ clutter_text_create_layout_no_cache (ClutterText *text,
} }
else else
{ {
ClutterTextDirection dir;
PangoDirection pango_dir; PangoDirection pango_dir;
PangoContext *context;
if (priv->password_char != 0) if (priv->password_char != 0)
pango_dir = PANGO_DIRECTION_NEUTRAL; dir = CLUTTER_TEXT_DIRECTION_DEFAULT;
else else
pango_dir = _clutter_pango_find_base_dir (contents, contents_len); dir = _clutter_find_base_dir (contents, contents_len);
if (pango_dir == PANGO_DIRECTION_NEUTRAL) if (dir == CLUTTER_TEXT_DIRECTION_DEFAULT)
{ {
ClutterBackend *backend = clutter_get_default_backend (); ClutterBackend *backend = clutter_get_default_backend ();
ClutterTextDirection text_dir;
if (clutter_actor_has_key_focus (CLUTTER_ACTOR (text))) if (clutter_actor_has_key_focus (CLUTTER_ACTOR (text)))
{ {
@ -751,22 +752,20 @@ clutter_text_create_layout_no_cache (ClutterText *text,
seat = clutter_backend_get_default_seat (backend); seat = clutter_backend_get_default_seat (backend);
keymap = clutter_seat_get_keymap (seat); keymap = clutter_seat_get_keymap (seat);
pango_dir = clutter_keymap_get_direction (keymap); dir = clutter_keymap_get_direction (keymap);
} }
else else
{ {
text_dir = clutter_actor_get_text_direction (CLUTTER_ACTOR (text)); dir = clutter_actor_get_text_direction (CLUTTER_ACTOR (text));
}
if (text_dir == CLUTTER_TEXT_DIRECTION_RTL)
pango_dir = PANGO_DIRECTION_RTL;
else
pango_dir = PANGO_DIRECTION_LTR;
}
} }
pango_context_set_base_dir (clutter_actor_get_pango_context (CLUTTER_ACTOR (text)), pango_dir); pango_dir = clutter_text_direction_to_pango_direction (dir);
context = clutter_actor_get_pango_context (CLUTTER_ACTOR (text));
priv->resolved_direction = pango_dir; pango_context_set_base_dir (context, pango_dir);
priv->resolved_direction = dir;
pango_layout_set_text (layout, contents, contents_len); pango_layout_set_text (layout, contents, contents_len);
} }
@ -2686,7 +2685,7 @@ clutter_text_paint (ClutterActor *self,
actor_width = alloc_width - 2 * TEXT_PADDING; actor_width = alloc_width - 2 * TEXT_PADDING;
text_width = pango_to_pixels (logical_rect.width); text_width = pango_to_pixels (logical_rect.width);
rtl = priv->resolved_direction == PANGO_DIRECTION_RTL; rtl = priv->resolved_direction == CLUTTER_TEXT_DIRECTION_RTL;
if (actor_width < text_width) if (actor_width < text_width)
{ {

View File

@ -256,8 +256,8 @@ clutter_interval_register_progress_func (GType value_type,
G_UNLOCK (progress_funcs); G_UNLOCK (progress_funcs);
} }
PangoDirection ClutterTextDirection
_clutter_pango_unichar_direction (gunichar ch) clutter_unichar_direction (gunichar ch)
{ {
FriBidiCharType fribidi_ch_type; FriBidiCharType fribidi_ch_type;
@ -266,30 +266,30 @@ _clutter_pango_unichar_direction (gunichar ch)
fribidi_ch_type = fribidi_get_bidi_type (ch); fribidi_ch_type = fribidi_get_bidi_type (ch);
if (!FRIBIDI_IS_STRONG (fribidi_ch_type)) if (!FRIBIDI_IS_STRONG (fribidi_ch_type))
return PANGO_DIRECTION_NEUTRAL; return CLUTTER_TEXT_DIRECTION_DEFAULT;
else if (FRIBIDI_IS_RTL (fribidi_ch_type)) else if (FRIBIDI_IS_RTL (fribidi_ch_type))
return PANGO_DIRECTION_RTL; return CLUTTER_TEXT_DIRECTION_RTL;
else else
return PANGO_DIRECTION_LTR; return CLUTTER_TEXT_DIRECTION_LTR;
} }
PangoDirection ClutterTextDirection
_clutter_pango_find_base_dir (const gchar *text, _clutter_find_base_dir (const gchar *text,
gint length) gint length)
{ {
PangoDirection dir = PANGO_DIRECTION_NEUTRAL; ClutterTextDirection dir = CLUTTER_TEXT_DIRECTION_DEFAULT;
const gchar *p; const gchar *p;
g_return_val_if_fail (text != NULL || length == 0, PANGO_DIRECTION_NEUTRAL); g_return_val_if_fail (text != NULL || length == 0, CLUTTER_TEXT_DIRECTION_DEFAULT);
p = text; p = text;
while ((length < 0 || p < text + length) && *p) while ((length < 0 || p < text + length) && *p)
{ {
gunichar wc = g_utf8_get_char (p); gunichar wc = g_utf8_get_char (p);
dir = _clutter_pango_unichar_direction (wc); dir = clutter_unichar_direction (wc);
if (dir != PANGO_DIRECTION_NEUTRAL) if (dir != CLUTTER_TEXT_DIRECTION_DEFAULT)
break; break;
p = g_utf8_next_char (p); p = g_utf8_next_char (p);
@ -297,3 +297,18 @@ _clutter_pango_find_base_dir (const gchar *text,
return dir; return dir;
} }
PangoDirection
clutter_text_direction_to_pango_direction (ClutterTextDirection dir)
{
switch (dir)
{
case CLUTTER_TEXT_DIRECTION_RTL:
return PANGO_DIRECTION_RTL;
case CLUTTER_TEXT_DIRECTION_LTR:
return PANGO_DIRECTION_LTR;
default:
case CLUTTER_TEXT_DIRECTION_DEFAULT:
return PANGO_DIRECTION_NEUTRAL;
}
}

View File

@ -53,10 +53,10 @@ meta_keymap_native_finalize (GObject *object)
G_OBJECT_CLASS (meta_keymap_native_parent_class)->finalize (object); G_OBJECT_CLASS (meta_keymap_native_parent_class)->finalize (object);
} }
static PangoDirection static ClutterTextDirection
meta_keymap_native_get_direction (ClutterKeymap *keymap) meta_keymap_native_get_direction (ClutterKeymap *keymap)
{ {
return PANGO_DIRECTION_NEUTRAL; return CLUTTER_TEXT_DIRECTION_DEFAULT;
} }
static void static void

View File

@ -49,7 +49,7 @@ struct _DirectionCacheEntry
{ {
uint32_t serial; uint32_t serial;
Atom group_atom; Atom group_atom;
PangoDirection direction; ClutterTextDirection direction;
}; };
struct _MetaKeymapX11 struct _MetaKeymapX11
@ -67,7 +67,7 @@ struct _MetaKeymapX11
ClutterModifierType scroll_lock_mask; ClutterModifierType scroll_lock_mask;
ClutterModifierType level3_shift_mask; ClutterModifierType level3_shift_mask;
PangoDirection current_direction; ClutterTextDirection current_direction;
XkbDescPtr xkb_desc; XkbDescPtr xkb_desc;
int xkb_event_base; int xkb_event_base;
@ -244,7 +244,7 @@ update_locked_mods (MetaKeymapX11 *keymap_x11,
* is taken from GDK: * is taken from GDK:
* gdk/x11/gdkkeys-x11.c * gdk/x11/gdkkeys-x11.c
*/ */
static PangoDirection static ClutterTextDirection
get_direction (XkbDescPtr xkb, get_direction (XkbDescPtr xkb,
int group) int group)
{ {
@ -257,16 +257,16 @@ get_direction (XkbDescPtr xkb,
{ {
int level = 0; int level = 0;
KeySym sym = XkbKeySymEntry (xkb, code, level, group); KeySym sym = XkbKeySymEntry (xkb, code, level, group);
PangoDirection dir = ClutterTextDirection dir =
_clutter_pango_unichar_direction (clutter_keysym_to_unicode (sym)); clutter_unichar_direction (clutter_keysym_to_unicode (sym));
switch (dir) switch (dir)
{ {
case PANGO_DIRECTION_RTL: case CLUTTER_TEXT_DIRECTION_RTL:
rtl_minus_ltr++; rtl_minus_ltr++;
break; break;
case PANGO_DIRECTION_LTR: case CLUTTER_TEXT_DIRECTION_LTR:
rtl_minus_ltr--; rtl_minus_ltr--;
break; break;
@ -276,12 +276,12 @@ get_direction (XkbDescPtr xkb,
} }
if (rtl_minus_ltr > 0) if (rtl_minus_ltr > 0)
return PANGO_DIRECTION_RTL; return CLUTTER_TEXT_DIRECTION_RTL;
return PANGO_DIRECTION_LTR; return CLUTTER_TEXT_DIRECTION_LTR;
} }
static PangoDirection static ClutterTextDirection
get_direction_from_cache (MetaKeymapX11 *keymap_x11, get_direction_from_cache (MetaKeymapX11 *keymap_x11,
XkbDescPtr xkb, XkbDescPtr xkb,
int group) int group)
@ -289,7 +289,7 @@ get_direction_from_cache (MetaKeymapX11 *keymap_x11,
Atom group_atom = xkb->names->groups[group]; Atom group_atom = xkb->names->groups[group];
gboolean cache_hit = FALSE; gboolean cache_hit = FALSE;
DirectionCacheEntry *cache = keymap_x11->group_direction_cache; DirectionCacheEntry *cache = keymap_x11->group_direction_cache;
PangoDirection direction = PANGO_DIRECTION_NEUTRAL; ClutterTextDirection direction = CLUTTER_TEXT_DIRECTION_DEFAULT;
int i; int i;
if (keymap_x11->has_direction) if (keymap_x11->has_direction)
@ -313,7 +313,7 @@ get_direction_from_cache (MetaKeymapX11 *keymap_x11,
for (i = 0; i < G_N_ELEMENTS (keymap_x11->group_direction_cache); i++) for (i = 0; i < G_N_ELEMENTS (keymap_x11->group_direction_cache); i++)
{ {
cache[i].group_atom = 0; cache[i].group_atom = 0;
cache[i].direction = PANGO_DIRECTION_NEUTRAL; cache[i].direction = CLUTTER_TEXT_DIRECTION_DEFAULT;
cache[i].serial = keymap_x11->current_cache_serial; cache[i].serial = keymap_x11->current_cache_serial;
} }
@ -514,12 +514,12 @@ meta_keymap_x11_finalize (GObject *object)
G_OBJECT_CLASS (meta_keymap_x11_parent_class)->finalize (object); G_OBJECT_CLASS (meta_keymap_x11_parent_class)->finalize (object);
} }
static PangoDirection static ClutterTextDirection
meta_keymap_x11_get_direction (ClutterKeymap *keymap) meta_keymap_x11_get_direction (ClutterKeymap *keymap)
{ {
MetaKeymapX11 *keymap_x11; MetaKeymapX11 *keymap_x11;
g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap), PANGO_DIRECTION_NEUTRAL); g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap), CLUTTER_TEXT_DIRECTION_DEFAULT);
keymap_x11 = META_KEYMAP_X11 (keymap); keymap_x11 = META_KEYMAP_X11 (keymap);
@ -538,7 +538,7 @@ meta_keymap_x11_get_direction (ClutterKeymap *keymap)
} }
else else
{ {
return PANGO_DIRECTION_NEUTRAL; return CLUTTER_TEXT_DIRECTION_DEFAULT;
} }
} }
@ -565,7 +565,7 @@ meta_keymap_x11_class_init (MetaKeymapX11Class *klass)
static void static void
meta_keymap_x11_init (MetaKeymapX11 *keymap) meta_keymap_x11_init (MetaKeymapX11 *keymap)
{ {
keymap->current_direction = PANGO_DIRECTION_NEUTRAL; keymap->current_direction = CLUTTER_TEXT_DIRECTION_DEFAULT;
keymap->current_group = -1; keymap->current_group = -1;
keymap->reserved_keycodes = g_hash_table_new (NULL, NULL); keymap->reserved_keycodes = g_hash_table_new (NULL, NULL);
keymap->available_keycodes = g_queue_new (); keymap->available_keycodes = g_queue_new ();

View File

@ -20,7 +20,6 @@
#pragma once #pragma once
#include <glib-object.h> #include <glib-object.h>
#include <pango/pango.h>
#include "clutter/clutter.h" #include "clutter/clutter.h"

View File

@ -17,7 +17,6 @@ mutter_pkg_deps = [
gio_unix_dep, gio_unix_dep,
glib_dep, glib_dep,
gsettings_desktop_schemas_dep, gsettings_desktop_schemas_dep,
pango_dep,
] ]
mutter_pkg_private_deps = [ mutter_pkg_private_deps = [

View File

@ -22,7 +22,6 @@
#pragma once #pragma once
#include <pango/pango-font.h>
#include <gdesktop-enums.h> #include <gdesktop-enums.h>
#include <gio/gio.h> #include <gio/gio.h>