[gtk/gtk-4-4] widget: Provide a helper for updating pango contexts



commit abe7407abe598221c13fc22e185dbd559d3f565c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Sep 4 15:35:11 2021 -0400

    widget: Provide a helper for updating pango contexts

 gtk/gtkwidget.c        | 18 ++++++++++--------
 gtk/gtkwidgetprivate.h |  4 ++++
 2 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 3cb4394ab1..088c047c20 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -6427,9 +6427,10 @@ gtk_widget_get_effective_font_map (GtkWidget *widget)
     return pango_cairo_font_map_get_default ();
 }
 
-static gboolean
-update_pango_context (GtkWidget    *widget,
-                      PangoContext *context)
+gboolean
+gtk_widget_update_pango_context (GtkWidget        *widget,
+                                 PangoContext     *context,
+                                 GtkTextDirection  direction)
 {
   GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
   GtkCssStyle *style = gtk_css_node_get_style (priv->cssnode);
@@ -6447,9 +6448,10 @@ update_pango_context (GtkWidget    *widget,
   if (cairo_version () >= CAIRO_VERSION_ENCODE (1, 17, 4))
     pango_context_set_round_glyph_positions (context, FALSE);
 
-  pango_context_set_base_dir (context,
-                              _gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
-                              PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
+  if (direction != GTK_TEXT_DIR_NONE)
+    pango_context_set_base_dir (context, direction == GTK_TEXT_DIR_LTR
+                                         ? PANGO_DIRECTION_LTR
+                                         : PANGO_DIRECTION_RTL);
 
   pango_cairo_context_set_resolution (context, _gtk_css_number_value_get (style->core->dpi, 100));
 
@@ -6483,7 +6485,7 @@ gtk_widget_update_default_pango_context (GtkWidget *widget)
   if (!context)
     return;
 
-  if (update_pango_context (widget, context))
+  if (gtk_widget_update_pango_context (widget, context, _gtk_widget_get_direction (widget)))
     gtk_widget_queue_draw (widget);
 }
 
@@ -6624,7 +6626,7 @@ gtk_widget_create_pango_context (GtkWidget *widget)
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
   context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
-  update_pango_context (widget, context);
+  gtk_widget_update_pango_context (widget, context, _gtk_widget_get_direction (widget));
   pango_context_set_language (context, gtk_get_default_language ());
 
   return context;
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 5110b0263c..e1e336e6e6 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -370,6 +370,10 @@ void    gtk_widget_update_orientation   (GtkWidget      *widget,
 void    gtk_widget_realize_at_context   (GtkWidget *widget);
 void    gtk_widget_unrealize_at_context (GtkWidget *widget);
 
+gboolean gtk_widget_update_pango_context (GtkWidget        *widget,
+                                          PangoContext     *context,
+                                          GtkTextDirection  direction);
+
 /* inline getters */
 
 static inline GtkWidget *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]