[pango] New public API: pango_glyph_item_get_logical_widths()



commit 7b1b94b255d616759672b03b2cf4b88aa013271a
Author: Behdad Esfahbod <behdad behdad org>
Date:   Wed Aug 12 18:36:36 2009 -0400

    New public API: pango_glyph_item_get_logical_widths()

 docs/pango-sections.txt  |    1 +
 docs/tmpl/glyphs.sgml    |   10 +++++++
 pango/glyphstring.c      |   39 +++--------------------------
 pango/pango-glyph-item.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++
 pango/pango-glyph-item.h |    3 ++
 pango/pango-layout.c     |    5 +--
 pango/pango.def          |    1 +
 7 files changed, 81 insertions(+), 38 deletions(-)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 18deac3..e4cfbc9 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -118,6 +118,7 @@ pango_glyph_item_free
 pango_glyph_item_split
 pango_glyph_item_apply_attrs
 pango_glyph_item_letter_space
+pango_glyph_item_get_logical_widths
 PANGO_TYPE_GLYPH_ITEM_ITER
 pango_glyph_item_iter_copy
 pango_glyph_item_iter_free
diff --git a/docs/tmpl/glyphs.sgml b/docs/tmpl/glyphs.sgml
index bfa26c3..be546c6 100644
--- a/docs/tmpl/glyphs.sgml
+++ b/docs/tmpl/glyphs.sgml
@@ -636,6 +636,16 @@ The #GObject type for #PangoGlyphItem.
 @letter_spacing: 
 
 
+<!-- ##### FUNCTION pango_glyph_item_get_logical_widths ##### -->
+<para>
+
+</para>
+
+ glyph_item: 
+ text: 
+ logical_widths: 
+
+
 <!-- ##### MACRO PANGO_TYPE_GLYPH_ITEM_ITER ##### -->
 <para>
 The #GObject type for #PangoGlyphItemIter.
diff --git a/pango/glyphstring.c b/pango/glyphstring.c
index 9e7c5f8..923a936 100644
--- a/pango/glyphstring.c
+++ b/pango/glyphstring.c
@@ -329,6 +329,8 @@ pango_glyph_string_get_width (PangoGlyphString *glyphs)
  * text, determine the screen width corresponding to each character. When
  * multiple characters compose a single cluster, the width of the entire
  * cluster is divided equally among the characters.
+ *
+ * See also pango_glyph_item_get_logical_widths().
  **/
 void
 pango_glyph_string_get_logical_widths (PangoGlyphString *glyphs,
@@ -337,48 +339,15 @@ pango_glyph_string_get_logical_widths (PangoGlyphString *glyphs,
 				       int               embedding_level,
 				       int              *logical_widths)
 {
-  /* Build a PangoGlyphItem so we can use PangoGlyphItemIter.
-   * This API should have been made to take a PangoGlyphItem... */
+  /* Build a PangoGlyphItem and call the other API */
   PangoItem item = {0, length, pango_utf8_strlen (text, length),
 		    {NULL, NULL, NULL,
 		     embedding_level, PANGO_GRAVITY_AUTO, 0,
 		     PANGO_SCRIPT_UNKNOWN, NULL,
 		     NULL}};
   PangoGlyphItem glyph_item = {&item, glyphs};
-  PangoGlyphItemIter iter;
-  gboolean has_cluster;
-  int dir;
-
-  dir = embedding_level % 2 == 0 ? +1 : -1;
-  for (has_cluster = pango_glyph_item_iter_init_start (&iter, &glyph_item, text);
-       has_cluster;
-       has_cluster = pango_glyph_item_iter_next_cluster (&iter))
-    {
-      int glyph_index, char_index, num_chars, cluster_width = 0, char_width;
-
-      for (glyph_index  = iter.start_glyph;
-	   glyph_index != iter.end_glyph;
-	   glyph_index += dir)
-        {
-	  cluster_width += glyphs->glyphs[glyph_index].geometry.width;
-	}
-
-      num_chars = iter.end_char - iter.start_char;
-      if (num_chars) /* pedantic */
-        {
-	  char_width = cluster_width / num_chars;
 
-	  for (char_index = iter.start_char;
-	       char_index < iter.end_char;
-	       char_index++)
-	    {
-	      logical_widths[char_index] = char_width;
-	    }
-
-	  /* add any residues to the first char */
-	  logical_widths[iter.start_char] += cluster_width - (char_width * num_chars);
-	}
-    }
+  return pango_glyph_item_get_logical_widths (&glyph_item, text, logical_widths);
 }
 
 /* The initial implementation here is script independent,
diff --git a/pango/pango-glyph-item.c b/pango/pango-glyph-item.c
index 8d19d94..d60e7be 100644
--- a/pango/pango-glyph-item.c
+++ b/pango/pango-glyph-item.c
@@ -782,3 +782,63 @@ pango_glyph_item_letter_space (PangoGlyphItem *glyph_item,
 	}
     }
 }
+
+/**
+ * pango_glyph_item_get_logical_widths:
+ * @glyph_item: a #PangoGlyphItem
+ * @text: text that @glyph_item corresponds to
+ *   (glyph_item->item->offset is an offset from the
+ *    start of @text)
+ * @logical_widths: an array whose length is the number of characters in
+ *                  glyph_item (equal to glyph_item->item->num_chars)
+ *                  to be filled in with the resulting character widths.
+ *
+ * Given a #PangoGlyphItem and the corresponding
+ * text, determine the screen width corresponding to each character. When
+ * multiple characters compose a single cluster, the width of the entire
+ * cluster is divided equally among the characters.
+ *
+ * See also pango_glyph_string_get_logical_widths().
+ *
+ * Since: 1.26
+ **/
+void
+pango_glyph_item_get_logical_widths (PangoGlyphItem *glyph_item,
+				     const char     *text,
+				     int            *logical_widths)
+{
+  PangoGlyphItemIter iter;
+  gboolean has_cluster;
+  int dir;
+
+  dir = glyph_item->item->analysis.level % 2 == 0 ? +1 : -1;
+  for (has_cluster = pango_glyph_item_iter_init_start (&iter, glyph_item, text);
+       has_cluster;
+       has_cluster = pango_glyph_item_iter_next_cluster (&iter))
+    {
+      int glyph_index, char_index, num_chars, cluster_width = 0, char_width;
+
+      for (glyph_index  = iter.start_glyph;
+	   glyph_index != iter.end_glyph;
+	   glyph_index += dir)
+        {
+	  cluster_width += glyph_item->glyphs->glyphs[glyph_index].geometry.width;
+	}
+
+      num_chars = iter.end_char - iter.start_char;
+      if (num_chars) /* pedantic */
+        {
+	  char_width = cluster_width / num_chars;
+
+	  for (char_index = iter.start_char;
+	       char_index < iter.end_char;
+	       char_index++)
+	    {
+	      logical_widths[char_index] = char_width;
+	    }
+
+	  /* add any residues to the first char */
+	  logical_widths[iter.start_char] += cluster_width - (char_width * num_chars);
+	}
+    }
+}
diff --git a/pango/pango-glyph-item.h b/pango/pango-glyph-item.h
index 4814252..71c4ab3 100644
--- a/pango/pango-glyph-item.h
+++ b/pango/pango-glyph-item.h
@@ -53,6 +53,9 @@ void            pango_glyph_item_letter_space (PangoGlyphItem *glyph_item,
 					       const char     *text,
 					       PangoLogAttr   *log_attrs,
 					       int             letter_spacing);
+void 	  pango_glyph_item_get_logical_widths (PangoGlyphItem *glyph_item,
+					       const char     *text,
+					       int            *logical_widths);
 
 
 typedef struct _PangoGlyphItemIter PangoGlyphItemIter;
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 2598940..fc166d4 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -3295,10 +3295,9 @@ process_item (PangoLayout     *layout,
 
       if (processing_new_item)
 	{
+	  PangoGlyphItem glyph_item = {item, state->glyphs};
 	  state->log_widths = g_new (int, item->num_chars);
-	  pango_glyph_string_get_logical_widths (state->glyphs,
-						 layout->text + item->offset, item->length, item->analysis.level,
-						 state->log_widths);
+	  pango_glyph_item_get_logical_widths (&glyph_item, layout->text, state->log_widths);
 	}
 
     retry_break:
diff --git a/pango/pango.def b/pango/pango.def
index d941ebe..3b1bc76 100644
--- a/pango/pango.def
+++ b/pango/pango.def
@@ -182,6 +182,7 @@ EXPORTS
 	pango_glyph_item_apply_attrs
 	pango_glyph_item_copy
 	pango_glyph_item_free
+	pango_glyph_item_get_logical_widths
 	pango_glyph_item_get_type
 	pango_glyph_item_iter_copy
 	pango_glyph_item_iter_free



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