From 7db50fd467bcf0b2d944526eb5342a3f86a383bf Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Mon, 27 Apr 2026 17:00:03 +0200 Subject: [PATCH] Replace deprecated Pango base direction lookup --- gtk/gtkentry.c | 5 +++-- gtk/gtkpango.c | 29 +++++++++++++++++++++++++++++ gtk/gtkpango.h | 4 ++++ gtk/gtktextbtree.c | 9 +++++---- gtk/gtktextview.c | 3 ++- 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 4d8260d8f..852ffcda5 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -48,6 +48,7 @@ #include "gtklabel.h" #include "gtkmain.h" #include "gtkmarshalers.h" +#include "gtkpango.h" #include "gtkmenu.h" #include "gtkmenuitem.h" #include "gtkseparatormenuitem.h" @@ -5425,9 +5426,9 @@ gtk_entry_create_layout (GtkEntry *entry, PangoDirection pango_dir; if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL) - pango_dir = pango_find_base_dir (display, n_bytes); + pango_dir = _gtk_pango_find_base_dir (display, n_bytes); else - pango_dir = PANGO_DIRECTION_NEUTRAL; + pango_dir = PANGO_DIRECTION_NEUTRAL; if (pango_dir == PANGO_DIRECTION_NEUTRAL) { diff --git a/gtk/gtkpango.c b/gtk/gtkpango.c index be6eb4e57..f91e4918b 100644 --- a/gtk/gtkpango.c +++ b/gtk/gtkpango.c @@ -231,3 +231,32 @@ _gtk_pango_fill_layout (cairo_t *cr, cairo_move_to (cr, current_x, current_y); } +PangoDirection +_gtk_pango_find_base_dir (const gchar *text, + gint length) +{ + const gchar *p; + const gchar *end; + + g_return_val_if_fail (text != NULL, PANGO_DIRECTION_NEUTRAL); + + p = text; + end = length < 0 ? NULL : text + length; + + while ((end == NULL && *p != '\0') || (end != NULL && p < end)) + { + PangoBidiType bidi_type; + + bidi_type = pango_bidi_type_for_unichar (g_utf8_get_char (p)); + + if (bidi_type == PANGO_BIDI_TYPE_L) + return PANGO_DIRECTION_LTR; + else if (bidi_type == PANGO_BIDI_TYPE_R || + bidi_type == PANGO_BIDI_TYPE_AL) + return PANGO_DIRECTION_RTL; + + p = g_utf8_next_char (p); + } + + return PANGO_DIRECTION_NEUTRAL; +} diff --git a/gtk/gtkpango.h b/gtk/gtkpango.h index 51338da46..96d2cafc9 100644 --- a/gtk/gtkpango.h +++ b/gtk/gtkpango.h @@ -41,6 +41,10 @@ void _gtk_pango_fill_layout (cairo_t *cr, PangoLayout *layout); +PangoDirection +_gtk_pango_find_base_dir (const gchar *text, + gint length); + G_END_DECLS diff --git a/gtk/gtktextbtree.c b/gtk/gtktextbtree.c index f0cd19ade..273f26a48 100644 --- a/gtk/gtktextbtree.c +++ b/gtk/gtktextbtree.c @@ -64,6 +64,7 @@ #include "gtktextiterprivate.h" #include "gtkdebug.h" #include "gtktextmarkprivate.h" +#include "gtkpango.h" #include "gtkalias.h" /* @@ -594,11 +595,11 @@ gtk_text_btree_resolve_bidi (GtkTextIter *start, { if (seg->type == >k_text_char_type && seg->byte_count > 0) { - PangoDirection pango_dir; + PangoDirection pango_dir; + + pango_dir = _gtk_pango_find_base_dir (seg->body.chars, + seg->byte_count); - pango_dir = pango_find_base_dir (seg->body.chars, - seg->byte_count); - if (pango_dir != PANGO_DIRECTION_NEUTRAL) { line->dir_strong = pango_dir; diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 540a4ed21..4c3680b3e 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -46,6 +46,7 @@ #include "gtkimmulticontext.h" #include "gdk/gdkkeysyms.h" #include "gtkprivate.h" +#include "gtkpango.h" #include "gtktextutil.h" #include "gtkwindow.h" #include "gtkalias.h" @@ -5075,7 +5076,7 @@ iter_line_is_rtl (const GtkTextIter *iter) gtk_text_iter_set_line_offset (&start, 0); gtk_text_iter_forward_line (&end); text = gtk_text_iter_get_visible_text (&start, &end); - direction = pango_find_base_dir (text, -1); + direction = _gtk_pango_find_base_dir (text, -1); g_free (text);