[gtk/css-text-transform: 2/3] Implement text transforms for GtkTextView




commit d0aac0c0c93f4e84e5ff9d4716bd362196af1bd2
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Aug 20 20:06:38 2021 -0400

    Implement text transforms for GtkTextView
    
    Add a property to GtkTextTag and do all the
    legwork to translate it to the Pango attribute.

 demos/gtk-demo/fontify.c |  1 +
 gtk/gtktextattributes.c  |  6 +++++-
 gtk/gtktextattributes.h  |  1 +
 gtk/gtktextbuffer.c      |  3 ++-
 gtk/gtktextlayout.c      |  9 +++++++++
 gtk/gtktexttag.c         | 40 ++++++++++++++++++++++++++++++++++++++++
 gtk/gtktexttagprivate.h  |  1 +
 7 files changed, 59 insertions(+), 2 deletions(-)
---
diff --git a/demos/gtk-demo/fontify.c b/demos/gtk-demo/fontify.c
index 8eb3c148f4..f89a2525f1 100644
--- a/demos/gtk-demo/fontify.c
+++ b/demos/gtk-demo/fontify.c
@@ -271,6 +271,7 @@ insert_tags_for_attributes (GtkTextBuffer     *buffer,
 
 #if PANGO_VERSION_CHECK(1,49,0)
         case PANGO_ATTR_TEXT_TRANSFORM:
+          INT_ATTR (text_transform);
           break;
 #endif
 
diff --git a/gtk/gtktextattributes.c b/gtk/gtktextattributes.c
index 738caa6bc1..b98a511c24 100644
--- a/gtk/gtktextattributes.c
+++ b/gtk/gtktextattributes.c
@@ -435,6 +435,9 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
 
       if (tag->priv->insert_hyphens_set)
         dest->no_hyphens = vals->no_hyphens;
+
+      if (tag->priv->text_transform_set)
+        dest->text_transform = vals->text_transform;
     }
 
   dest->left_margin += left_margin_accumulative;
@@ -463,7 +466,8 @@ _gtk_text_tag_affects_size (GtkTextTag *tag)
     priv->wrap_mode_set ||
     priv->invisible_set ||
     priv->font_features_set ||
-    priv->letter_spacing_set;
+    priv->letter_spacing_set ||
+    priv->text_transform_set;
 }
 
 gboolean
diff --git a/gtk/gtktextattributes.h b/gtk/gtktextattributes.h
index 05f7750247..c5946f4900 100644
--- a/gtk/gtktextattributes.h
+++ b/gtk/gtktextattributes.h
@@ -156,6 +156,7 @@ struct _GtkTextAttributes
   guint no_breaks : 1;
   guint show_spaces : 3; /* PangoShowFlags */
   guint no_hyphens : 1;
+  guint text_transform : 3; /* PangoTextTransform */
 };
 
 GtkTextAttributes* gtk_text_attributes_new         (void);
diff --git a/gtk/gtktextbuffer.c b/gtk/gtktextbuffer.c
index 2101776e95..cb25377364 100644
--- a/gtk/gtktextbuffer.c
+++ b/gtk/gtktextbuffer.c
@@ -4707,12 +4707,13 @@ insert_tags_for_attributes (GtkTextBuffer     *buffer,
           INT_ATTR (show_spaces);
           break;
 
+#if PANGO_VERSION_CHECK(1, 49, 0)
         case PANGO_ATTR_INSERT_HYPHENS:
           INT_ATTR (insert_hyphens);
           break;
 
-#if PANGO_VERSION_CHECK(1, 49, 0)
         case PANGO_ATTR_TEXT_TRANSFORM:
+          INT_ATTR (text_transform);
           break;
 #endif
 
diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c
index 80fb0a2bf1..76750123d8 100644
--- a/gtk/gtktextlayout.c
+++ b/gtk/gtktextlayout.c
@@ -1674,6 +1674,15 @@ add_text_attrs (GtkTextLayout      *layout,
       pango_attr_list_insert (attrs, attr);
     }
 
+  if (style->text_transform != PANGO_TEXT_TRANSFORM_NONE)
+    {
+      attr = pango_attr_text_transform_new (style->text_transform);
+      attr->start_index = start;
+      attr->end_index = start + byte_count;
+
+      pango_attr_list_insert (attrs, attr);
+    }
+
 }
 
 static void
diff --git a/gtk/gtktexttag.c b/gtk/gtktexttag.c
index fdf17a6efc..8328e349d8 100644
--- a/gtk/gtktexttag.c
+++ b/gtk/gtktexttag.c
@@ -133,6 +133,7 @@ enum {
   PROP_ALLOW_BREAKS,
   PROP_SHOW_SPACES,
   PROP_INSERT_HYPHENS,
+  PROP_TEXT_TRANSFORM,
 
   /* Behavior args */
   PROP_ACCUMULATIVE_MARGIN,
@@ -174,6 +175,7 @@ enum {
   PROP_ALLOW_BREAKS_SET,
   PROP_SHOW_SPACES_SET,
   PROP_INSERT_HYPHENS_SET,
+  PROP_TEXT_TRANSFORM_SET,
 
   LAST_ARG
 };
@@ -839,6 +841,22 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
                                                          TRUE,
                                                          GTK_PARAM_READWRITE));
 
+  /**
+   * GtkTextTag:text-transform:
+   *
+   * How to transform the text for display.
+   *
+   * Since: 4.6
+   */
+  g_object_class_install_property (object_class,
+                                   PROP_TEXT_TRANSFORM,
+                                   g_param_spec_enum ("text-transform",
+                                                         P_("Text Transform"),
+                                                         P_("Whether to transform text for display."),
+                                                         PANGO_TYPE_TEXT_TRANSFORM,
+                                                         PANGO_TEXT_TRANSFORM_NONE,
+                                                         GTK_PARAM_READWRITE));
+
   /**
    * GtkTextTag:accumulative-margin:
    *
@@ -1013,6 +1031,10 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
   ADD_SET_PROP ("insert-hyphens-set", PROP_INSERT_HYPHENS_SET,
                 P_("Insert hyphens set"),
                 P_("Whether this tag affects insertion of hyphens"));
+
+  ADD_SET_PROP ("text-transform-set", PROP_TEXT_TRANSFORM_SET,
+                P_("Text transform set"),
+                P_("Whether this tag affects text transformation"));
 }
 
 static void
@@ -1755,6 +1777,12 @@ gtk_text_tag_set_property (GObject      *object,
       g_object_notify (object, "insert-hyphens-set");
       break;
 
+    case PROP_TEXT_TRANSFORM:
+      priv->text_transform_set = TRUE;
+      priv->values->text_transform = g_value_get_enum (value);
+      g_object_notify (object, "text-transform-set");
+      break;
+
     case PROP_ACCUMULATIVE_MARGIN:
       priv->accumulative_margin = g_value_get_boolean (value);
       g_object_notify (object, "accumulative-margin");
@@ -1919,6 +1947,10 @@ gtk_text_tag_set_property (GObject      *object,
       priv->insert_hyphens_set = g_value_get_boolean (value);
       break;
 
+    case PROP_TEXT_TRANSFORM_SET:
+      priv->text_transform_set = g_value_get_boolean (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2127,6 +2159,10 @@ gtk_text_tag_get_property (GObject      *object,
       g_value_set_boolean (value, !priv->values->no_hyphens);
       break;
 
+    case PROP_TEXT_TRANSFORM:
+      g_value_set_enum (value, priv->values->text_transform);
+      break;
+
     case PROP_ACCUMULATIVE_MARGIN:
       g_value_set_boolean (value, priv->accumulative_margin);
       break;
@@ -2265,6 +2301,10 @@ gtk_text_tag_get_property (GObject      *object,
       g_value_set_boolean (value, priv->insert_hyphens_set);
       break;
 
+    case PROP_TEXT_TRANSFORM_SET:
+      g_value_set_boolean (value, priv->text_transform_set);
+      break;
+
     case PROP_BACKGROUND:
     case PROP_FOREGROUND:
     case PROP_PARAGRAPH_BACKGROUND:
diff --git a/gtk/gtktexttagprivate.h b/gtk/gtktexttagprivate.h
index b0bd079532..4599e99067 100644
--- a/gtk/gtktexttagprivate.h
+++ b/gtk/gtktexttagprivate.h
@@ -86,6 +86,7 @@ struct _GtkTextTagPrivate
   guint allow_breaks_set : 1;
   guint show_spaces_set : 1;
   guint insert_hyphens_set : 1;
+  guint text_transform_set : 1;
 
   /* Whether these margins accumulate or override */
   guint accumulative_margin : 1;


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