Replace deprecated Pango base direction lookup

This commit is contained in:
Daemonratte 2026-04-27 17:00:03 +02:00
commit 7db50fd467
5 changed files with 43 additions and 7 deletions

View file

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

View file

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

View file

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

View file

@ -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 == &gtk_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;

View file

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