mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 19:42:05 +00:00
clutter: Avoid string translation to find text direction
Use Pango and Harfbuzz for the task, getting the default language, then its scripts, then their directions. We pick the first valid horizontal direction, resorting to LTR as a fallback. Related: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/5385 Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2780>
This commit is contained in:
parent
95c2154039
commit
9e0b5b1886
@ -51,6 +51,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include <hb-glib.h>
|
||||
|
||||
#include "clutter-actor-private.h"
|
||||
#include "clutter-backend-private.h"
|
||||
@ -221,20 +222,28 @@ clutter_get_text_direction (void)
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Translate to default:RTL if you want your widgets
|
||||
* to be RTL, otherwise translate to default:LTR.
|
||||
* Do *not* translate it to "predefinito:LTR", if it
|
||||
* it isn't default:LTR or default:RTL it will not work
|
||||
*/
|
||||
const char *e = _("default:LTR");
|
||||
PangoLanguage *language;
|
||||
const PangoScript *scripts;
|
||||
int n_scripts, i;
|
||||
|
||||
if (strcmp (e, "default:RTL") == 0)
|
||||
dir = CLUTTER_TEXT_DIRECTION_RTL;
|
||||
else if (strcmp (e, "default:LTR") == 0)
|
||||
dir = CLUTTER_TEXT_DIRECTION_LTR;
|
||||
else
|
||||
g_warning ("Whoever translated default:LTR did so wrongly.");
|
||||
language = pango_language_get_default ();
|
||||
scripts = pango_language_get_scripts (language, &n_scripts);
|
||||
|
||||
for (i = 0; i < n_scripts; i++)
|
||||
{
|
||||
hb_script_t script;
|
||||
hb_direction_t text_dir;
|
||||
|
||||
script = hb_glib_script_to_script ((GUnicodeScript) scripts[i]);
|
||||
text_dir = hb_script_get_horizontal_direction (script);
|
||||
|
||||
if (text_dir == HB_DIRECTION_LTR)
|
||||
dir = CLUTTER_TEXT_DIRECTION_LTR;
|
||||
else if (text_dir == HB_DIRECTION_RTL)
|
||||
dir = CLUTTER_TEXT_DIRECTION_RTL;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
CLUTTER_NOTE (MISC, "Text direction: %s",
|
||||
|
@ -36,6 +36,7 @@ clutter_pkg_deps = [
|
||||
gio_dep,
|
||||
json_glib_dep,
|
||||
pango_dep,
|
||||
harfbuzz_dep,
|
||||
]
|
||||
|
||||
clutter_pkg_private_deps = [
|
||||
|
@ -38,6 +38,7 @@ libstartup_notification_req = '>= 0.7'
|
||||
libcanberra_req = '>= 0.26'
|
||||
libwacom_req = '>= 0.13'
|
||||
atk_req = '>= 2.5.3'
|
||||
harfbuzz_req = '>= 2.6'
|
||||
|
||||
# optional version requirements
|
||||
udev_req = '>= 228'
|
||||
@ -128,6 +129,7 @@ atk_dep = dependency('atk', version: atk_req)
|
||||
dbus_dep = dependency('dbus-1')
|
||||
colord_dep = dependency('colord', version: colord_req)
|
||||
lcms2_dep = dependency('lcms2', version: lcms2_req)
|
||||
harfbuzz_dep = dependency('harfbuzz', version: harfbuzz_req)
|
||||
|
||||
have_wayland = get_option('wayland')
|
||||
# For now always require X11 support
|
||||
|
@ -11,7 +11,6 @@ src/backends/meta-input-settings.c
|
||||
src/backends/meta-monitor.c
|
||||
src/backends/meta-monitor-manager.c
|
||||
src/backends/x11/meta-clutter-backend-x11.c
|
||||
src/clutter/clutter/clutter-main.c
|
||||
src/compositor/compositor.c
|
||||
src/compositor/meta-background.c
|
||||
src/core/bell.c
|
||||
|
Loading…
Reference in New Issue
Block a user