diff options
Diffstat (limited to 'widgets/misc/e-unicode.c')
-rw-r--r-- | widgets/misc/e-unicode.c | 217 |
1 files changed, 0 insertions, 217 deletions
diff --git a/widgets/misc/e-unicode.c b/widgets/misc/e-unicode.c index fb81db1798..d7bd33caa7 100644 --- a/widgets/misc/e-unicode.c +++ b/widgets/misc/e-unicode.c @@ -38,7 +38,6 @@ #include <gdk/gdkx.h> #include <gdk/gdkkeysyms.h> #include <gtk/gtkmenuitem.h> -#include "e-font.h" #include <libxml/xmlmemory.h> #include <stdlib.h> #include "gal/util/e-iconv.h" @@ -406,173 +405,6 @@ e_utf8_to_charset_string (const gchar *charset, const gchar *string) } gchar * -e_utf8_from_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes) -{ - iconv_t ic; - char *new, *ob; - const char *ib; - size_t ibl, obl; - - g_return_val_if_fail (widget != NULL, NULL); - g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - - if (!string) return NULL; - - g_return_val_if_fail (widget, NULL); - - ic = e_iconv_from_gdk_font (gtk_style_get_font (widget->style)); - if (ic == (iconv_t) -1) { - XFontStruct *xfs; - /* If iconv is missing we assume either iso-10646 or iso-8859-1 */ - xfs = GDK_FONT_XFONT (gtk_style_get_font (widget->style)); - if (gtk_style_get_font (widget->style)->type == GDK_FONT_FONTSET || ((xfs->min_byte1 != 0) || (xfs->max_byte1 != 0))) { - gint i; - const guchar *ib; - guchar * ob, * new; - /* iso-10646 */ - ib = string; - new = ob = g_new (unsigned char, bytes * 6 + 1); - for (i = 0; i < (bytes - 1); i += 2) { - ob += e_unichar_to_utf8 (ib[i] * 256 + ib[i + 1], ob); - } - *ob = '\0'; - return new; - } else { - gint i; - /* iso-8859-1 */ - ib = (char *) string; - new = ob = g_new (unsigned char, bytes * 2 + 1); - for (i = 0; i < (bytes); i ++) { - ob += e_unichar_to_utf8 (ib[i], ob); - } - *ob = '\0'; - return new; - } - } - - ib = string; - ibl = bytes; - new = ob = g_new (gchar, ibl * 6 + 1); - obl = ibl * 6; - - while (ibl > 0) { - e_iconv (ic, &ib, &ibl, &ob, &obl); - if (ibl > 0) { - gint len; - if ((*ib & 0x80) == 0x00) len = 1; - else if ((*ib &0xe0) == 0xc0) len = 2; - else if ((*ib &0xf0) == 0xe0) len = 3; - else if ((*ib &0xf8) == 0xf0) len = 4; - else { - g_warning ("Invalid UTF-8 sequence"); - break; - } - ib += len; - ibl = bytes - (ib - string); - if (ibl > bytes) ibl = 0; - *ob++ = '_'; - obl--; - } - } - - *ob = '\0'; - - e_iconv_close(ic); - - return new; -} - -gchar * -e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string) -{ - if (!string) return NULL; - return e_utf8_from_gtk_string_sized (widget, string, strlen (string)); -} - -gchar * -e_utf8_to_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes) -{ - iconv_t ic; - char *new, *ob; - const char *ib; - size_t ibl, obl; - - if (!string) return NULL; - - g_return_val_if_fail (widget, NULL); - - gtk_widget_ensure_style (widget); - ic = e_iconv_to_gdk_font (gtk_style_get_font (widget->style)); - if (ic == (iconv_t) -1) { - XFontStruct *xfs; - gboolean twobyte; - gint len; - const gchar *u; - gunichar uc; - /* If iconv is missing we assume either iso-10646 or iso-8859-1 */ - xfs = GDK_FONT_XFONT (gtk_style_get_font (widget->style)); - twobyte = (gtk_style_get_font (widget->style)->type == GDK_FONT_FONTSET || ((xfs->min_byte1 != 0) || (xfs->max_byte1 != 0))); - - new = g_new (unsigned char, bytes * 4 + 2); - u = string; - len = 0; - - while ((u) && (u - string < bytes)) { - u = e_unicode_get_utf8 (u, &uc); - if (twobyte) { - new[len++] = (uc & 0xff00) >> 8; - } - new[len++] = uc & 0xff; - } - - new[len++] = '\0'; - if (twobyte) - new[len] = '\0'; - - return new; - } - - ib = string; - ibl = bytes; - new = ob = g_new (gchar, ibl * 4 + 4); - obl = ibl * 4; - - while (ibl > 0) { - e_iconv (ic, &ib, &ibl, &ob, &obl); - if (ibl > 0) { - gint len; - if ((*ib & 0x80) == 0x00) len = 1; - else if ((*ib &0xe0) == 0xc0) len = 2; - else if ((*ib &0xf0) == 0xe0) len = 3; - else if ((*ib &0xf8) == 0xf0) len = 4; - else { - g_warning ("Invalid UTF-8 sequence"); - break; - } - ib += len; - ibl = bytes - (ib - string); - if (ibl > bytes) ibl = 0; - *ob++ = '_'; - obl--; - } - } - - /* Make sure to terminate with plenty of padding */ - memset (ob, 0, 4); - - e_iconv_close(ic); - - return new; -} - -gchar * -e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string) -{ - if (!string) return NULL; - return e_utf8_to_gtk_string_sized (widget, string, strlen (string)); -} - -gchar * e_utf8_from_locale_string_sized (const gchar *string, gint bytes) { iconv_t ic; @@ -673,55 +505,6 @@ e_utf8_gtk_entry_set_text (GtkEntry *entry, const gchar *text) gtk_entry_set_text (entry, text); } -GtkWidget * -e_utf8_gtk_menu_item_new_with_label (GtkMenu *menu, const gchar *label) -{ - GtkWidget *w; - gchar *s; - - if (!label) return NULL; - - s = e_utf8_to_gtk_string ((GtkWidget *) menu, label); - w = gtk_menu_item_new_with_label (s); - - g_free (s); - - return w; -} - -void -e_utf8_gtk_clist_set_text (GtkCList *clist, gint row, gint col, const gchar *text) -{ - gchar *s; - - if (!text) return; - - s = e_utf8_to_gtk_string ((GtkWidget *) clist, text); - gtk_clist_set_text (clist, row, col, s); - - if (s) g_free (s); -} - -gint -e_utf8_gtk_clist_append (GtkCList *clist, gchar *text[]) -{ - gint row, i; - gchar **v; - - if (!text) return 0; - - v = g_new (gchar *, clist->columns); - for (i = 0; i < clist->columns; i++) - v[i] = e_utf8_to_gtk_string ((GtkWidget *) clist, text[i]); - - row = gtk_clist_append (clist, v); - - for (i = 0; i < clist->columns; i++) - if (v[i]) g_free (v[i]); - - return row; -} - /* * Translate \U+XXXX\ sequences to utf8 chars */ |