aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorLauris Kaplinski <lauris@src.gnome.org>2000-08-22 10:53:04 +0800
committerLauris Kaplinski <lauris@src.gnome.org>2000-08-22 10:53:04 +0800
commita0e3d19542a1ebd025c6e047c17ea813c7afb661 (patch)
treecb2980ba337d19eedeb15d296143681d2fe8264e /e-util
parent95ba651873ef5e263139a46ec76cb26b6cc79647 (diff)
downloadgsoc2013-evolution-a0e3d19542a1ebd025c6e047c17ea813c7afb661.tar
gsoc2013-evolution-a0e3d19542a1ebd025c6e047c17ea813c7afb661.tar.gz
gsoc2013-evolution-a0e3d19542a1ebd025c6e047c17ea813c7afb661.tar.bz2
gsoc2013-evolution-a0e3d19542a1ebd025c6e047c17ea813c7afb661.tar.lz
gsoc2013-evolution-a0e3d19542a1ebd025c6e047c17ea813c7afb661.tar.xz
gsoc2013-evolution-a0e3d19542a1ebd025c6e047c17ea813c7afb661.tar.zst
gsoc2013-evolution-a0e3d19542a1ebd025c6e047c17ea813c7afb661.zip
Changed UTF-8 handling syntax from char based to byte based
svn path=/trunk/; revision=4913
Diffstat (limited to 'e-util')
-rw-r--r--e-util/ChangeLog5
-rw-r--r--e-util/e-font.c51
-rw-r--r--e-util/e-font.h37
3 files changed, 54 insertions, 39 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index 7c7010b719..9958171157 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,8 @@
+2000-08-21 Lauris Kaplinski <lauris@helixcode.com>
+
+ * e-font.h:
+ * e-font.c: Changed UTF-8 syntax from char-based to byte-based
+
2000-08-21 Peter Williams <peterw@helixcode.com>
* e-html-utils.c (e_text_to_html): Fix a booboo in the tab
diff --git a/e-util/e-font.c b/e-util/e-font.c
index 1c5bc211cb..a13f0b962c 100644
--- a/e-util/e-font.c
+++ b/e-util/e-font.c
@@ -61,44 +61,65 @@ e_font_descent (EFont * font)
}
void
-e_font_draw_utf8_text (GdkDrawable *drawable, EFont *font, EFontStyle style, GdkGC *gc, gint x, gint y, gchar *text, gint length)
+e_font_draw_utf8_text (GdkDrawable *drawable, EFont *font, EFontStyle style, GdkGC *gc, gint x, gint y, gchar *text, gint numbytes)
{
- guchar *iso_text;
+ guchar *iso;
gchar *p;
- gint uni, i;
+ gint uni, len;
- iso_text = alloca (length);
+ g_return_if_fail (drawable != NULL);
+ g_return_if_fail (font != NULL);
+ g_return_if_fail (gc != NULL);
+ g_return_if_fail (text != NULL);
- for (p = text, i = 0; i < length; i++, p = unicode_next_utf8 (p)) {
+ if (numbytes < 1) return;
+
+ iso = alloca (numbytes);
+
+ for (len = 0, p = text; p != NULL && p < (text + numbytes); len++, p = unicode_next_utf8 (p)) {
unicode_get_utf8 (p, &uni);
if ((uni < ' ') || (uni > 255)) uni = ' ';
- iso_text[i] = uni;
+ iso[len] = uni;
}
- gdk_draw_text (drawable, &font->font, gc, x, y, iso_text, length);
+ gdk_draw_text (drawable, &font->font, gc, x, y, iso, len);
if (style & E_FONT_BOLD)
- gdk_draw_text (drawable, &font->font, gc, x + 1, y, iso_text, length);
+ gdk_draw_text (drawable, &font->font, gc, x + 1, y, iso, len);
}
gint
-e_font_utf8_text_width (EFont *font, EFontStyle style, char *text, int length)
+e_font_utf8_text_width (EFont *font, EFontStyle style, char *text, int numbytes)
{
- guchar *iso_text;
+ guchar *iso;
gchar *p;
- gint uni, i;
+ gint uni, len;
- iso_text = alloca (length);
+ iso = alloca (numbytes);
- for (p = text, i = 0; i < length; i++, p = unicode_next_utf8 (p)) {
+ for (len = 0, p = text; p != NULL && p < (text + numbytes); len++, p = unicode_next_utf8 (p)) {
unicode_get_utf8 (p, &uni);
if ((uni < ' ') || (uni > 255)) uni = ' ';
- iso_text[i] = uni;
+ iso[len] = uni;
}
- return gdk_text_width (&font->font, iso_text, length);
+ return gdk_text_width (&font->font, iso, len);
}
+gint
+e_font_utf8_char_width (EFont *font, EFontStyle style, char *text)
+{
+ unicode_char_t uni;
+ guchar iso;
+
+ if (!unicode_get_utf8 (text, &uni)) return 0;
+
+ if ((uni < ' ') || (uni > 255)) uni = ' ';
+
+ iso = uni;
+
+ return gdk_text_width (&font->font, &iso, 1);
+}
diff --git a/e-util/e-font.h b/e-util/e-font.h
index 74ebea2592..9616e9ef4b 100644
--- a/e-util/e-font.h
+++ b/e-util/e-font.h
@@ -45,30 +45,19 @@ gint e_font_descent (EFont * font);
* NB! UTF-8 text widths are given in chars, not bytes
*/
-void e_font_draw_utf8_text (GdkDrawable *drawable, EFont *font, EFontStyle style, GdkGC *gc, gint x, gint y, gchar *text, gint numchars);
-int e_font_utf8_text_width (EFont *font, EFontStyle style, char *text, int numchars);
-
-#if 0
-void e_font_draw_ucs2_text (GdkDrawable *drawable, EFont *font, GdkGC *gc, gint x, gint y, short *text, gint length);
-
-gboolean e_ucs2_isspace (short ch);
-
-unsigned short *e_ucs2_from_utf8 (const gchar *text);
-unsigned short *e_ucs2_from_utf8_sized (const gchar *text, gint length);
-
-unsigned char *e_utf8_from_ucs2_sized (const short *text, int length);
-
-int e_font_ucs2_text_width (EFont *font, short *text, int length);
-
-int e_ucs2_strlen (const short *text);
-
-short * e_ucs2_strncpy (short *dst, short *src, int length);
-short * e_ucs2_strcpy (short *dst, short *src);
-
-short * e_ucs2_strdup (const short *string);
-
-gint e_ucs2_strcmp (const short *a, const short *b);
-#endif
+void e_font_draw_utf8_text (GdkDrawable *drawable,
+ EFont *font, EFontStyle style,
+ GdkGC *gc,
+ gint x, gint y,
+ gchar *text,
+ gint numbytes);
+
+int e_font_utf8_text_width (EFont *font, EFontStyle style,
+ char *text,
+ int numbytes);
+
+int e_font_utf8_char_width (EFont *font, EFontStyle style,
+ char *text);
END_GNOME_DECLS