mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 10:00:45 -05:00
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:
parent
c19eef3f5e
commit
a2397e6b80
@ -12891,17 +12891,16 @@ update_pango_context (ClutterBackend *backend,
|
||||
ClutterSettings *settings;
|
||||
PangoFontDescription *font_desc;
|
||||
const cairo_font_options_t *font_options;
|
||||
gchar *font_name;
|
||||
ClutterTextDirection dir;
|
||||
PangoDirection pango_dir;
|
||||
gchar *font_name;
|
||||
gdouble resolution;
|
||||
|
||||
settings = clutter_settings_get_default ();
|
||||
|
||||
/* update the text direction */
|
||||
if (clutter_get_default_text_direction () == CLUTTER_TEXT_DIRECTION_RTL)
|
||||
pango_dir = PANGO_DIRECTION_RTL;
|
||||
else
|
||||
pango_dir = PANGO_DIRECTION_LTR;
|
||||
dir = clutter_get_default_text_direction ();
|
||||
pango_dir = clutter_text_direction_to_pango_direction (dir);
|
||||
|
||||
pango_context_set_base_dir (context, pango_dir);
|
||||
|
||||
|
@ -28,7 +28,6 @@
|
||||
#endif
|
||||
|
||||
#include <cairo.h>
|
||||
#include <pango/pango.h>
|
||||
|
||||
#include "cogl/cogl.h"
|
||||
|
||||
|
@ -147,7 +147,7 @@ clutter_keymap_get_caps_lock_state (ClutterKeymap *keymap)
|
||||
return priv->caps_lock_state;
|
||||
}
|
||||
|
||||
PangoDirection
|
||||
ClutterTextDirection
|
||||
clutter_keymap_get_direction (ClutterKeymap *keymap)
|
||||
{
|
||||
return CLUTTER_KEYMAP_GET_CLASS (keymap)->get_direction (keymap);
|
||||
|
@ -23,10 +23,11 @@
|
||||
#error "Only <clutter/clutter.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "clutter/clutter-enums.h"
|
||||
#include "clutter/clutter-macros.h"
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <pango/pango.h>
|
||||
|
||||
typedef struct _ClutterKeymap ClutterKeymap;
|
||||
typedef struct _ClutterKeymapClass ClutterKeymapClass;
|
||||
@ -35,7 +36,7 @@ struct _ClutterKeymapClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
PangoDirection (* get_direction) (ClutterKeymap *keymap);
|
||||
ClutterTextDirection (* get_direction) (ClutterKeymap *keymap);
|
||||
};
|
||||
|
||||
#define CLUTTER_TYPE_KEYMAP (clutter_keymap_get_type ())
|
||||
@ -50,4 +51,4 @@ gboolean clutter_keymap_get_num_lock_state (ClutterKeymap *keymap);
|
||||
CLUTTER_EXPORT
|
||||
gboolean clutter_keymap_get_caps_lock_state (ClutterKeymap *keymap);
|
||||
|
||||
PangoDirection clutter_keymap_get_direction (ClutterKeymap *keymap);
|
||||
ClutterTextDirection clutter_keymap_get_direction (ClutterKeymap *keymap);
|
||||
|
@ -50,7 +50,6 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <gobject/gvaluecollector.h>
|
||||
#include <pango/pango.h>
|
||||
|
||||
#include "cogl/cogl.h"
|
||||
#include "clutter/clutter-paint-node-private.h"
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
#include <pango/pango.h>
|
||||
|
||||
#include "cogl-pango/cogl-pango.h"
|
||||
|
||||
@ -145,11 +146,14 @@ void _clutter_util_fully_transform_vertices (const graphene_matrix_t *modelvie
|
||||
int n_vertices);
|
||||
|
||||
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);
|
||||
|
||||
PangoDirection
|
||||
clutter_text_direction_to_pango_direction (ClutterTextDirection dir);
|
||||
|
||||
typedef enum _ClutterCullResult
|
||||
{
|
||||
CLUTTER_CULL_RESULT_UNKNOWN,
|
||||
|
@ -732,17 +732,18 @@ clutter_text_create_layout_no_cache (ClutterText *text,
|
||||
}
|
||||
else
|
||||
{
|
||||
ClutterTextDirection dir;
|
||||
PangoDirection pango_dir;
|
||||
PangoContext *context;
|
||||
|
||||
if (priv->password_char != 0)
|
||||
pango_dir = PANGO_DIRECTION_NEUTRAL;
|
||||
dir = CLUTTER_TEXT_DIRECTION_DEFAULT;
|
||||
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 ();
|
||||
ClutterTextDirection text_dir;
|
||||
|
||||
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);
|
||||
keymap = clutter_seat_get_keymap (seat);
|
||||
pango_dir = clutter_keymap_get_direction (keymap);
|
||||
dir = clutter_keymap_get_direction (keymap);
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
dir = clutter_actor_get_text_direction (CLUTTER_ACTOR (text));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@ -2686,7 +2685,7 @@ clutter_text_paint (ClutterActor *self,
|
||||
actor_width = alloc_width - 2 * TEXT_PADDING;
|
||||
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)
|
||||
{
|
||||
|
@ -256,8 +256,8 @@ clutter_interval_register_progress_func (GType value_type,
|
||||
G_UNLOCK (progress_funcs);
|
||||
}
|
||||
|
||||
PangoDirection
|
||||
_clutter_pango_unichar_direction (gunichar ch)
|
||||
ClutterTextDirection
|
||||
clutter_unichar_direction (gunichar ch)
|
||||
{
|
||||
FriBidiCharType fribidi_ch_type;
|
||||
|
||||
@ -266,30 +266,30 @@ _clutter_pango_unichar_direction (gunichar ch)
|
||||
fribidi_ch_type = fribidi_get_bidi_type (ch);
|
||||
|
||||
if (!FRIBIDI_IS_STRONG (fribidi_ch_type))
|
||||
return PANGO_DIRECTION_NEUTRAL;
|
||||
return CLUTTER_TEXT_DIRECTION_DEFAULT;
|
||||
else if (FRIBIDI_IS_RTL (fribidi_ch_type))
|
||||
return PANGO_DIRECTION_RTL;
|
||||
return CLUTTER_TEXT_DIRECTION_RTL;
|
||||
else
|
||||
return PANGO_DIRECTION_LTR;
|
||||
return CLUTTER_TEXT_DIRECTION_LTR;
|
||||
}
|
||||
|
||||
PangoDirection
|
||||
_clutter_pango_find_base_dir (const gchar *text,
|
||||
ClutterTextDirection
|
||||
_clutter_find_base_dir (const gchar *text,
|
||||
gint length)
|
||||
{
|
||||
PangoDirection dir = PANGO_DIRECTION_NEUTRAL;
|
||||
ClutterTextDirection dir = CLUTTER_TEXT_DIRECTION_DEFAULT;
|
||||
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;
|
||||
while ((length < 0 || p < text + length) && *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;
|
||||
|
||||
p = g_utf8_next_char (p);
|
||||
@ -297,3 +297,18 @@ _clutter_pango_find_base_dir (const gchar *text,
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -53,10 +53,10 @@ meta_keymap_native_finalize (GObject *object)
|
||||
G_OBJECT_CLASS (meta_keymap_native_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static PangoDirection
|
||||
static ClutterTextDirection
|
||||
meta_keymap_native_get_direction (ClutterKeymap *keymap)
|
||||
{
|
||||
return PANGO_DIRECTION_NEUTRAL;
|
||||
return CLUTTER_TEXT_DIRECTION_DEFAULT;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -49,7 +49,7 @@ struct _DirectionCacheEntry
|
||||
{
|
||||
uint32_t serial;
|
||||
Atom group_atom;
|
||||
PangoDirection direction;
|
||||
ClutterTextDirection direction;
|
||||
};
|
||||
|
||||
struct _MetaKeymapX11
|
||||
@ -67,7 +67,7 @@ struct _MetaKeymapX11
|
||||
ClutterModifierType scroll_lock_mask;
|
||||
ClutterModifierType level3_shift_mask;
|
||||
|
||||
PangoDirection current_direction;
|
||||
ClutterTextDirection current_direction;
|
||||
|
||||
XkbDescPtr xkb_desc;
|
||||
int xkb_event_base;
|
||||
@ -244,7 +244,7 @@ update_locked_mods (MetaKeymapX11 *keymap_x11,
|
||||
* is taken from GDK:
|
||||
* gdk/x11/gdkkeys-x11.c
|
||||
*/
|
||||
static PangoDirection
|
||||
static ClutterTextDirection
|
||||
get_direction (XkbDescPtr xkb,
|
||||
int group)
|
||||
{
|
||||
@ -257,16 +257,16 @@ get_direction (XkbDescPtr xkb,
|
||||
{
|
||||
int level = 0;
|
||||
KeySym sym = XkbKeySymEntry (xkb, code, level, group);
|
||||
PangoDirection dir =
|
||||
_clutter_pango_unichar_direction (clutter_keysym_to_unicode (sym));
|
||||
ClutterTextDirection dir =
|
||||
clutter_unichar_direction (clutter_keysym_to_unicode (sym));
|
||||
|
||||
switch (dir)
|
||||
{
|
||||
case PANGO_DIRECTION_RTL:
|
||||
case CLUTTER_TEXT_DIRECTION_RTL:
|
||||
rtl_minus_ltr++;
|
||||
break;
|
||||
|
||||
case PANGO_DIRECTION_LTR:
|
||||
case CLUTTER_TEXT_DIRECTION_LTR:
|
||||
rtl_minus_ltr--;
|
||||
break;
|
||||
|
||||
@ -276,12 +276,12 @@ get_direction (XkbDescPtr xkb,
|
||||
}
|
||||
|
||||
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,
|
||||
XkbDescPtr xkb,
|
||||
int group)
|
||||
@ -289,7 +289,7 @@ get_direction_from_cache (MetaKeymapX11 *keymap_x11,
|
||||
Atom group_atom = xkb->names->groups[group];
|
||||
gboolean cache_hit = FALSE;
|
||||
DirectionCacheEntry *cache = keymap_x11->group_direction_cache;
|
||||
PangoDirection direction = PANGO_DIRECTION_NEUTRAL;
|
||||
ClutterTextDirection direction = CLUTTER_TEXT_DIRECTION_DEFAULT;
|
||||
int i;
|
||||
|
||||
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++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@ -514,12 +514,12 @@ meta_keymap_x11_finalize (GObject *object)
|
||||
G_OBJECT_CLASS (meta_keymap_x11_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static PangoDirection
|
||||
static ClutterTextDirection
|
||||
meta_keymap_x11_get_direction (ClutterKeymap *keymap)
|
||||
{
|
||||
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);
|
||||
|
||||
@ -538,7 +538,7 @@ meta_keymap_x11_get_direction (ClutterKeymap *keymap)
|
||||
}
|
||||
else
|
||||
{
|
||||
return PANGO_DIRECTION_NEUTRAL;
|
||||
return CLUTTER_TEXT_DIRECTION_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -565,7 +565,7 @@ meta_keymap_x11_class_init (MetaKeymapX11Class *klass)
|
||||
static void
|
||||
meta_keymap_x11_init (MetaKeymapX11 *keymap)
|
||||
{
|
||||
keymap->current_direction = PANGO_DIRECTION_NEUTRAL;
|
||||
keymap->current_direction = CLUTTER_TEXT_DIRECTION_DEFAULT;
|
||||
keymap->current_group = -1;
|
||||
keymap->reserved_keycodes = g_hash_table_new (NULL, NULL);
|
||||
keymap->available_keycodes = g_queue_new ();
|
||||
|
@ -20,7 +20,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <pango/pango.h>
|
||||
|
||||
#include "clutter/clutter.h"
|
||||
|
||||
|
@ -17,7 +17,6 @@ mutter_pkg_deps = [
|
||||
gio_unix_dep,
|
||||
glib_dep,
|
||||
gsettings_desktop_schemas_dep,
|
||||
pango_dep,
|
||||
]
|
||||
|
||||
mutter_pkg_private_deps = [
|
||||
|
@ -22,7 +22,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pango/pango-font.h>
|
||||
#include <gdesktop-enums.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user