[gtk+/drop-gail] Use new Pango api for log attrs



commit f94285fd5041bb2d8af4382cd82e9d72881b1f41
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon May 16 10:26:23 2011 -0400

    Use new Pango api for log attrs

 gtk/gtkpango.c |  158 +++++++++++++++++++++++++++++---------------------------
 gtk/gtkpango.h |   14 +----
 2 files changed, 84 insertions(+), 88 deletions(-)
---
diff --git a/gtk/gtkpango.c b/gtk/gtkpango.c
index de3f3eb..ce156e4 100644
--- a/gtk/gtkpango.c
+++ b/gtk/gtkpango.c
@@ -525,11 +525,14 @@ _gtk_pango_get_run_attributes (AtkAttributeSet *attributes,
 
 gint
 _gtk_pango_move_chars (PangoLayout  *layout,
-                       PangoLogAttr *attrs,
-                       gint          n_attrs,
                        gint          offset,
                        gint          count)
 {
+  const PangoLogAttr *attrs;
+  gint n_attrs;
+
+  attrs = pango_layout_get_log_attrs_readonly (layout, &n_attrs);
+
   while (count > 0 && offset < n_attrs - 1)
     {
       do
@@ -552,11 +555,14 @@ _gtk_pango_move_chars (PangoLayout  *layout,
 
 gint
 _gtk_pango_move_words (PangoLayout  *layout,
-                       PangoLogAttr *attrs,
-                       gint          n_attrs,
                        gint          offset,
                        gint          count)
 {
+  const PangoLogAttr *attrs;
+  gint n_attrs;
+
+  attrs = pango_layout_get_log_attrs_readonly (layout, &n_attrs);
+
   while (count > 0 && offset < n_attrs - 1)
     {
       do
@@ -579,11 +585,14 @@ _gtk_pango_move_words (PangoLayout  *layout,
 
 gint
 _gtk_pango_move_sentences (PangoLayout  *layout,
-                           PangoLogAttr *attrs,
-                           gint          n_attrs,
                            gint          offset,
                            gint          count)
 {
+  const PangoLogAttr *attrs;
+  gint n_attrs;
+
+  attrs = pango_layout_get_log_attrs_readonly (layout, &n_attrs);
+
   while (count > 0 && offset < n_attrs - 1)
     {
       do
@@ -660,10 +669,13 @@ _gtk_pango_move_lines (PangoLayout *layout,
 
 gboolean
 _gtk_pango_is_inside_word (PangoLayout  *layout,
-                           PangoLogAttr *attrs,
-                           gint          n_attrs,
                            gint          offset)
 {
+  const PangoLogAttr *attrs;
+  gint n_attrs;
+
+  attrs = pango_layout_get_log_attrs_readonly (layout, &n_attrs);
+
   while (offset >= 0 &&
          !(attrs[offset].is_word_start || attrs[offset].is_word_end))
     offset--;
@@ -676,10 +688,13 @@ _gtk_pango_is_inside_word (PangoLayout  *layout,
 
 gboolean
 _gtk_pango_is_inside_sentence (PangoLayout  *layout,
-                               PangoLogAttr *attrs,
-                               gint          n_attrs,
                                gint          offset)
 {
+  const PangoLogAttr *attrs;
+  gint n_attrs;
+
+  attrs = pango_layout_get_log_attrs_readonly (layout, &n_attrs);
+
   while (offset >= 0 &&
          !(attrs[offset].is_sentence_start || attrs[offset].is_sentence_end))
     offset--;
@@ -888,11 +903,12 @@ _gtk_pango_get_text_before (PangoLayout     *layout,
                             gint            *end_offset)
 {
   const gchar *text;
-  PangoLogAttr *attrs;
-  gint n_attrs;
   gint start, end;
+  const PangoLogAttr *attrs;
+  gint n_attrs;
 
   text = pango_layout_get_text (layout);
+  attrs = pango_layout_get_log_attrs_readonly (layout, &n_attrs);
 
   if (text[0] == 0)
     {
@@ -901,53 +917,51 @@ _gtk_pango_get_text_before (PangoLayout     *layout,
       return g_strdup ("");
     }
 
-  pango_layout_get_log_attrs (layout, &attrs, &n_attrs);
-
   start = offset;
   end = start;
 
   switch (boundary_type)
     {
     case ATK_TEXT_BOUNDARY_CHAR:
-      start = _gtk_pango_move_chars (layout, attrs, n_attrs, start, -1);
+      start = _gtk_pango_move_chars (layout, start, -1);
       break;
 
     case ATK_TEXT_BOUNDARY_WORD_START:
       if (!attrs[start].is_word_start)
-        start = _gtk_pango_move_words (layout, attrs, n_attrs, start, -1);
+        start = _gtk_pango_move_words (layout, start, -1);
       end = start;
-      start = _gtk_pango_move_words (layout, attrs, n_attrs, start, -1);
+      start = _gtk_pango_move_words (layout, start, -1);
       break;
 
     case ATK_TEXT_BOUNDARY_WORD_END:
-      if (_gtk_pango_is_inside_word (layout, attrs, n_attrs, start) &&
+      if (_gtk_pango_is_inside_word (layout, start) &&
           !attrs[start].is_word_start)
-        start = _gtk_pango_move_words (layout, attrs, n_attrs, start, -1);
+        start = _gtk_pango_move_words (layout, start, -1);
       while (!attrs[start].is_word_end && start > 0)
-        start = _gtk_pango_move_chars (layout, attrs, n_attrs, start, -1);
+        start = _gtk_pango_move_chars (layout, start, -1);
       end = start;
-      start = _gtk_pango_move_words (layout, attrs, n_attrs, start, -1);
+      start = _gtk_pango_move_words (layout, start, -1);
       while (!attrs[start].is_word_end && start > 0)
-        start = _gtk_pango_move_chars (layout, attrs, n_attrs, start, -1);
+        start = _gtk_pango_move_chars (layout, start, -1);
       break;
 
     case ATK_TEXT_BOUNDARY_SENTENCE_START:
       if (!attrs[start].is_sentence_start)
-        start = _gtk_pango_move_sentences (layout, attrs, n_attrs, start, -1);
+        start = _gtk_pango_move_sentences (layout, start, -1);
       end = start;
-      start = _gtk_pango_move_sentences (layout, attrs, n_attrs, start, -1);
+      start = _gtk_pango_move_sentences (layout, start, -1);
       break;
 
     case ATK_TEXT_BOUNDARY_SENTENCE_END:
-      if (_gtk_pango_is_inside_sentence (layout, attrs, n_attrs, start) &&
+      if (_gtk_pango_is_inside_sentence (layout, start) &&
           !attrs[start].is_sentence_start)
-        start = _gtk_pango_move_sentences (layout, attrs, n_attrs, start, -1);
+        start = _gtk_pango_move_sentences (layout, start, -1);
       while (!attrs[start].is_sentence_end && start > 0)
-        start = _gtk_pango_move_chars (layout, attrs, n_attrs, start, -1);
+        start = _gtk_pango_move_chars (layout, start, -1);
       end = start;
-      start = _gtk_pango_move_sentences (layout, attrs, n_attrs, start, -1);
+      start = _gtk_pango_move_sentences (layout, start, -1);
       while (!attrs[start].is_sentence_end && start > 0)
-        start = _gtk_pango_move_chars (layout, attrs, n_attrs, start, -1);
+        start = _gtk_pango_move_chars (layout, start, -1);
       break;
 
     case ATK_TEXT_BOUNDARY_LINE_START:
@@ -959,8 +973,6 @@ _gtk_pango_get_text_before (PangoLayout     *layout,
   *start_offset = start;
   *end_offset = end;
 
-  g_free (attrs);
-
   return _g_utf8_substring (text, start, end);
 }
 
@@ -972,11 +984,12 @@ _gtk_pango_get_text_after (PangoLayout     *layout,
                            gint            *end_offset)
 {
   const gchar *text;
-  PangoLogAttr *attrs;
-  gint n_attrs;
   gint start, end;
+  const PangoLogAttr *attrs;
+  gint n_attrs;
 
   text = pango_layout_get_text (layout);
+  attrs = pango_layout_get_log_attrs_readonly (layout, &n_attrs);
 
   if (text[0] == 0)
     {
@@ -985,59 +998,57 @@ _gtk_pango_get_text_after (PangoLayout     *layout,
       return g_strdup ("");
     }
 
-  pango_layout_get_log_attrs (layout, &attrs, &n_attrs);
-
   start = offset;
   end = start;
 
   switch (boundary_type)
     {
     case ATK_TEXT_BOUNDARY_CHAR:
-      start = _gtk_pango_move_chars (layout, attrs, n_attrs, start, 1);
+      start = _gtk_pango_move_chars (layout, start, 1);
       end = start;
-      end = _gtk_pango_move_chars (layout, attrs, n_attrs, end, 1);
+      end = _gtk_pango_move_chars (layout, end, 1);
       break;
 
     case ATK_TEXT_BOUNDARY_WORD_START:
-      if (_gtk_pango_is_inside_word (layout, attrs, n_attrs, end))
-        end = _gtk_pango_move_words (layout, attrs, n_attrs, end, 1);
+      if (_gtk_pango_is_inside_word (layout, end))
+        end = _gtk_pango_move_words (layout, end, 1);
       while (!attrs[end].is_word_start && end < n_attrs - 1)
-        end = _gtk_pango_move_chars (layout, attrs, n_attrs, end, 1);
+        end = _gtk_pango_move_chars (layout, end, 1);
       start = end;
       if (end < n_attrs - 1)
         {
-          end = _gtk_pango_move_words (layout, attrs, n_attrs, end, 1);
+          end = _gtk_pango_move_words (layout, end, 1);
           while (!attrs[end].is_word_end && end < n_attrs - 1)
-            end = _gtk_pango_move_chars (layout, attrs, n_attrs, end, 1);
+            end = _gtk_pango_move_chars (layout, end, 1);
         }
       break;
 
     case ATK_TEXT_BOUNDARY_WORD_END:
-      end = _gtk_pango_move_words (layout, attrs, n_attrs, end, 1);
+      end = _gtk_pango_move_words (layout, end, 1);
       start = end;
       if (end < n_attrs - 1)
-        end = _gtk_pango_move_words (layout, attrs, n_attrs, end, 1);
+        end = _gtk_pango_move_words (layout, end, 1);
       break;
 
     case ATK_TEXT_BOUNDARY_SENTENCE_START:
-      if (_gtk_pango_is_inside_sentence (layout, attrs, n_attrs, end))
-        end = _gtk_pango_move_sentences (layout, attrs, n_attrs, end, 1);
+      if (_gtk_pango_is_inside_sentence (layout, end))
+        end = _gtk_pango_move_sentences (layout, end, 1);
       while (!attrs[end].is_sentence_end && end < n_attrs - 1)
-        end = _gtk_pango_move_chars (layout, attrs, n_attrs, end, 1);
+        end = _gtk_pango_move_chars (layout, end, 1);
       start = end;
       if (end < n_attrs - 1)
         {
-          end = _gtk_pango_move_sentences (layout, attrs, n_attrs, end, 1);
+          end = _gtk_pango_move_sentences (layout, end, 1);
           while (!attrs[end].is_sentence_start && end < n_attrs - 1)
-            end = _gtk_pango_move_chars (layout, attrs, n_attrs, end, 1);
+            end = _gtk_pango_move_chars (layout, end, 1);
         }
       break;
 
     case ATK_TEXT_BOUNDARY_SENTENCE_END:
-      end = _gtk_pango_move_sentences (layout, attrs, n_attrs, end, 1);
+      end = _gtk_pango_move_sentences (layout, end, 1);
       start = end;
       if (end < n_attrs - 1)
-        end = _gtk_pango_move_sentences (layout, attrs, n_attrs, end, 1);
+        end = _gtk_pango_move_sentences (layout, end, 1);
       break;
 
     case ATK_TEXT_BOUNDARY_LINE_START:
@@ -1049,8 +1060,6 @@ _gtk_pango_get_text_after (PangoLayout     *layout,
   *start_offset = start;
   *end_offset = end;
 
-  g_free (attrs);
-
   return _g_utf8_substring (text, start, end);
 }
 
@@ -1062,11 +1071,12 @@ _gtk_pango_get_text_at (PangoLayout     *layout,
                         gint            *end_offset)
 {
   const gchar *text;
-  PangoLogAttr *attrs;
-  gint n_attrs;
   gint start, end;
+  const PangoLogAttr *attrs;
+  gint n_attrs;
 
   text = pango_layout_get_text (layout);
+  attrs = pango_layout_get_log_attrs_readonly (layout, &n_attrs);
 
   if (text[0] == 0)
     {
@@ -1075,51 +1085,49 @@ _gtk_pango_get_text_at (PangoLayout     *layout,
       return g_strdup ("");
     }
 
-  pango_layout_get_log_attrs (layout, &attrs, &n_attrs);
-
   start = offset;
   end = start;
 
   switch (boundary_type)
     {
     case ATK_TEXT_BOUNDARY_CHAR:
-      start = _gtk_pango_move_chars (layout, attrs, n_attrs, start, 1);
+      start = _gtk_pango_move_chars (layout, start, 1);
       break;
 
     case ATK_TEXT_BOUNDARY_WORD_START:
       if (!attrs[start].is_word_start)
-        start = _gtk_pango_move_words (layout, attrs, n_attrs, start, -1);
-      if (_gtk_pango_is_inside_word (layout, attrs, n_attrs, end))
-        end = _gtk_pango_move_words (layout, attrs, n_attrs, end, 1);
+        start = _gtk_pango_move_words (layout, start, -1);
+      if (_gtk_pango_is_inside_word (layout, end))
+        end = _gtk_pango_move_words (layout, end, 1);
       while (!attrs[end].is_word_start && end < n_attrs - 1)
-        end = _gtk_pango_move_chars (layout, attrs, n_attrs, end, -1);
+        end = _gtk_pango_move_chars (layout, end, -1);
       break;
 
     case ATK_TEXT_BOUNDARY_WORD_END:
-      if (_gtk_pango_is_inside_word (layout, attrs, n_attrs, start) &&
+      if (_gtk_pango_is_inside_word (layout, start) &&
           !attrs[start].is_word_start)
-        start = _gtk_pango_move_words (layout, attrs, n_attrs, start, -1);
+        start = _gtk_pango_move_words (layout, start, -1);
       while (!attrs[start].is_word_end && start > 0)
-        start = _gtk_pango_move_chars (layout, attrs, n_attrs, start, -1);
-      end = _gtk_pango_move_words (layout, attrs, n_attrs, end, 1);
+        start = _gtk_pango_move_chars (layout, start, -1);
+      end = _gtk_pango_move_words (layout, end, 1);
       break;
 
     case ATK_TEXT_BOUNDARY_SENTENCE_START:
       if (!attrs[start].is_sentence_start)
-        start = _gtk_pango_move_sentences (layout, attrs, n_attrs, start, -1);
-      if (_gtk_pango_is_inside_sentence (layout, attrs, n_attrs, end))
-        end = _gtk_pango_move_sentences (layout, attrs, n_attrs, end, 1);
+        start = _gtk_pango_move_sentences (layout, start, -1);
+      if (_gtk_pango_is_inside_sentence (layout, end))
+        end = _gtk_pango_move_sentences (layout, end, 1);
       while (!attrs[end].is_word_end && end < n_attrs - 1)
-        end = _gtk_pango_move_chars (layout, attrs, n_attrs, end, 1);
+        end = _gtk_pango_move_chars (layout, end, 1);
       break;
 
     case ATK_TEXT_BOUNDARY_SENTENCE_END:
-      if (_gtk_pango_is_inside_sentence (layout, attrs, n_attrs, start) &&
+      if (_gtk_pango_is_inside_sentence (layout, start) &&
           !attrs[start].is_sentence_start)
-        start = _gtk_pango_move_sentences (layout, attrs, n_attrs, start, -1);
+        start = _gtk_pango_move_sentences (layout, start, -1);
       while (!attrs[start].is_sentence_end && start > 0)
-        start = _gtk_pango_move_chars (layout, attrs, n_attrs, start, -1);
-      end = _gtk_pango_move_sentences (layout, attrs, n_attrs, end, 1);
+        start = _gtk_pango_move_chars (layout, start, -1);
+      end = _gtk_pango_move_sentences (layout, end, 1);
       break;
 
     case ATK_TEXT_BOUNDARY_LINE_START:
@@ -1131,8 +1139,6 @@ _gtk_pango_get_text_at (PangoLayout     *layout,
   *start_offset = start;
   *end_offset = end;
 
-  g_free (attrs);
-
   return _g_utf8_substring (text, start, end);
 }
 
diff --git a/gtk/gtkpango.h b/gtk/gtkpango.h
index 9848cac..a55c12e 100644
--- a/gtk/gtkpango.h
+++ b/gtk/gtkpango.h
@@ -51,18 +51,12 @@ AtkAttributeSet* _gtk_pango_get_run_attributes (AtkAttributeSet *attributes,
                                                 gint            *end_offset);
 
 gint _gtk_pango_move_chars     (PangoLayout  *layout,
-                                PangoLogAttr *attrs,
-                                gint          n_attrs,
-                                gint          offset,
-                                gint          count);
+                                gint          count,
+                                gint          offset);
 gint _gtk_pango_move_words     (PangoLayout  *layout,
-                                PangoLogAttr *attrs,
-                                gint          n_attrs,
                                 gint          offset,
                                 gint          count);
 gint _gtk_pango_move_sentences (PangoLayout  *layout,
-                                PangoLogAttr *attrs,
-                                gint          n_attrs,
                                 gint          offset,
                                 gint          count);
 gint _gtk_pango_move_lines     (PangoLayout  *layout,
@@ -70,12 +64,8 @@ gint _gtk_pango_move_lines     (PangoLayout  *layout,
                                 gint          count);
 
 gboolean _gtk_pango_is_inside_word     (PangoLayout  *layout,
-                                        PangoLogAttr *attrs,
-                                        gint          n_attrs,
                                         gint          offset);
 gboolean _gtk_pango_is_inside_sentence (PangoLayout  *layout,
-                                        PangoLogAttr *attrs,
-                                        gint          n_attrs,
                                         gint          offset);
 
 



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