summaryrefslogtreecommitdiff
path: root/pango/pango-layout.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2000-05-28 00:38:05 +0000
committerOwen Taylor <otaylor@src.gnome.org>2000-05-28 00:38:05 +0000
commit1a23b2c124df6830bc8a8027bd8b38ccc2c75531 (patch)
tree36998ab8a3d8d1211d5eec8069a8d84c98a96041 /pango/pango-layout.c
parent62244f7210302bf7608c6130185c17d3d2e714e0 (diff)
downloadpango-1a23b2c124df6830bc8a8027bd8b38ccc2c75531.tar.gz
Add libgobject.
Sat May 27 20:36:56 2000 Owen Taylor <otaylor@redhat.com> * pango/Makefile.am configure.in: Add libgobject. * pango/pango-fontmap.[ch]: GObject'ify PangoFontMap. (Pango now requires GLib-1.3 to compile) * pango/pangox-fontmap.c pango/pangox-private.h: Break the fontmap code in libpangox out into a separate file. Tue May 23 10:32:25 2000 Owen Taylor <otaylor@redhat.com> * pango/pango-layout.c (pango_layout_set_text): Allow -1 for the length.
Diffstat (limited to 'pango/pango-layout.c')
-rw-r--r--pango/pango-layout.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 08af0edc..9cfa39f8 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -377,7 +377,9 @@ pango_layout_get_alignment (PangoLayout *layout)
* pango_layout_set_text:
* @layout: a #PangoLayout
* @text: a UTF8-string
- * @length: the length of @text, in bytes.
+ * @length: the length of @text, in bytes. -1 indicates that
+ * the string is null terminated and the length should be
+ * calculated.
*
* Set the text of the layout.
**/
@@ -392,22 +394,35 @@ pango_layout_set_text (PangoLayout *layout,
if (layout->text)
g_free (layout->text);
- if (length > 0)
+ if (length == 0)
+ {
+ layout->text = g_strdup ("");
+ layout->n_chars = 0;
+ }
+ else
{
- int n_chars = unicode_strlen (text, length);
unicode_char_t junk;
char *p = text;
- int i;
+ int n_chars = 0;
- for (i=0; i<n_chars; i++)
+ while (*p && (length < 0 || p < text + length))
{
p = unicode_get_utf8 (p, &junk);
- if (!p || !junk)
+ if (!p)
{
g_warning ("Invalid UTF8 string passed to pango_layout_set_text()");
return;
}
+ n_chars++;
}
+
+ if (length < 0)
+ length = p - text;
+
+ if (length >= 0 && p != text + length)
+ g_warning ("string passed to pango_layout_set_text() contains embedded NULL");
+
+ length = p - text;
/* NULL-terminate the text, since we currently use unicode_next_utf8()
* in quite a few places, and for convenience.
@@ -419,11 +434,6 @@ pango_layout_set_text (PangoLayout *layout,
layout->n_chars = n_chars;
}
- else
- {
- layout->text = g_strdup ("");
- layout->n_chars = 0;
- }
layout->length = length;