aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorLauris Kaplinski <lauris@src.gnome.org>2000-09-05 07:27:06 +0800
committerLauris Kaplinski <lauris@src.gnome.org>2000-09-05 07:27:06 +0800
commit52bfd30b6c8cf8ab519fc3242b99f3a58e3629db (patch)
tree9fb2c16f1bd689f33e516676a813b6d1e5860bd0 /e-util
parenta8a6e0d04c834a58f1ae71d89bfc24a89c2ae395 (diff)
downloadgsoc2013-evolution-52bfd30b6c8cf8ab519fc3242b99f3a58e3629db.tar
gsoc2013-evolution-52bfd30b6c8cf8ab519fc3242b99f3a58e3629db.tar.gz
gsoc2013-evolution-52bfd30b6c8cf8ab519fc3242b99f3a58e3629db.tar.bz2
gsoc2013-evolution-52bfd30b6c8cf8ab519fc3242b99f3a58e3629db.tar.lz
gsoc2013-evolution-52bfd30b6c8cf8ab519fc3242b99f3a58e3629db.tar.xz
gsoc2013-evolution-52bfd30b6c8cf8ab519fc3242b99f3a58e3629db.tar.zst
gsoc2013-evolution-52bfd30b6c8cf8ab519fc3242b99f3a58e3629db.zip
New font translation code for utf-8, but commented out at moment
svn path=/trunk/; revision=5194
Diffstat (limited to 'e-util')
-rw-r--r--e-util/ChangeLog5
-rw-r--r--e-util/e-font.c135
-rw-r--r--e-util/e-font.h5
-rw-r--r--e-util/e-unicode.c68
4 files changed, 177 insertions, 36 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index 3fc150fc83..c1eccd6f0f 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,8 @@
+2000-09-04 Lauris Kaplinski <lauris@helixcode.com>
+
+ * e-unicode.c: Added new font code, but comment it out now
+ * e-font.h, e-font.c: Test code for font analyzing
+
2000-09-02 Lauris Kaplinski <lauris@helixcode.com>
* e-unicode.h, e-unicode.c: New functions
diff --git a/e-util/e-font.c b/e-util/e-font.c
index 35b9d4db72..6f46b07f03 100644
--- a/e-util/e-font.c
+++ b/e-util/e-font.c
@@ -11,6 +11,8 @@
*
*/
+#include <string.h>
+#include <gdk/gdkx.h>
#include <unicode.h>
#include "e-font.h"
@@ -127,6 +129,139 @@ e_font_utf8_char_width (EFont *font, EFontStyle style, char *text)
return gdk_text_width (&font->font, &iso, 1);
}
+static const gchar *
+translate_encoding (const gchar *encoding)
+{
+ static GHashTable *eh = NULL;
+ gchar e[64];
+
+ if (!eh) {
+ eh = g_hash_table_new (g_str_hash, g_str_equal);
+
+ g_hash_table_insert (eh, "iso8859-1", "iso-8859-1");
+ g_hash_table_insert (eh, "iso8859-2", "iso-8859-2");
+ g_hash_table_insert (eh, "iso8859-3", "iso-8859-3");
+ g_hash_table_insert (eh, "iso8859-4", "iso-8859-4");
+ g_hash_table_insert (eh, "iso8859-5", "iso-8859-5");
+ g_hash_table_insert (eh, "iso10646-1", "UCS2");
+ }
+
+ strncpy (e, encoding, 64);
+ g_strdown (e);
+
+ return g_hash_table_lookup (eh, e);
+}
+
+const gchar *
+e_gdk_font_encoding (GdkFont *font)
+{
+ Atom font_atom, atom;
+ Bool status;
+ char *name, *p;
+ const gchar *encoding;
+
+ if (!font) return NULL;
+
+ font_atom = gdk_atom_intern ("FONT", FALSE);
+
+ if (font->type == GDK_FONT_FONTSET) {
+ XFontStruct **font_structs;
+ gint num_fonts;
+ gchar **font_names;
+
+ num_fonts = XFontsOfFontSet (GDK_FONT_XFONT (font),
+ &font_structs,
+ &font_names);
+ status = XGetFontProperty (font_structs[0],
+ font_atom,
+ &atom);
+ } else {
+ status = XGetFontProperty (GDK_FONT_XFONT (font),
+ font_atom,
+ &atom);
+ }
+
+ if (!status) return NULL;
+
+ name = gdk_atom_name (atom);
+ p = strchr (name, '-'); /* Foundry */
+ p = strchr (p + 1, '-'); /* Family */
+ p = strchr (p + 1, '-'); /* Weight */
+ p = strchr (p + 1, '-'); /* Slant */
+ p = strchr (p + 1, '-'); /* Set Width */
+ p = strchr (p + 1, '-'); /* Add Style */
+ p = strchr (p + 1, '-'); /* Pixel Size */
+ p = strchr (p + 1, '-'); /* Point Size */
+ p = strchr (p + 1, '-'); /* Resolution X */
+ p = strchr (p + 1, '-'); /* Resolution Y */
+ p = strchr (p + 1, '-'); /* Spacing */
+ p = strchr (p + 1, '-'); /* Average Width */
+ p = strchr (p + 1, '-'); /* Charset */
+
+ encoding = translate_encoding (p + 1);
+
+ g_free (name);
+
+ return encoding;
+}
+
+unicode_iconv_t
+e_uiconv_from_gdk_font (GdkFont *font)
+{
+ static GHashTable *uh = NULL;
+ const gchar *enc;
+ unicode_iconv_t uiconv;
+
+ if (!font) return (unicode_iconv_t) -1;
+
+ enc = e_gdk_font_encoding (font);
+
+ if (!enc) return (unicode_iconv_t) -1;
+
+ if (!uh) {
+ uh = g_hash_table_new (g_str_hash, g_str_equal);
+ }
+
+ uiconv = g_hash_table_lookup (uh, enc);
+
+ if (!uiconv) {
+ uiconv = unicode_iconv_open ("UTF-8", enc);
+ if (uiconv == (unicode_iconv_t) -1) return uiconv;
+ g_hash_table_insert (uh, (gpointer) enc, uiconv);
+ }
+
+ return uiconv;
+}
+
+unicode_iconv_t
+e_uiconv_to_gdk_font (GdkFont *font)
+{
+ static GHashTable *uh = NULL;
+ const gchar *enc;
+ unicode_iconv_t uiconv;
+
+ if (!font) return (unicode_iconv_t) -1;
+
+ enc = e_gdk_font_encoding (font);
+
+ if (!enc) return (unicode_iconv_t) -1;
+
+ if (!uh) {
+ uh = g_hash_table_new (g_str_hash, g_str_equal);
+ }
+
+ uiconv = g_hash_table_lookup (uh, enc);
+
+ if (!uiconv) {
+ uiconv = unicode_iconv_open (enc, "UTF-8");
+ if (uiconv == (unicode_iconv_t) -1) return uiconv;
+ g_hash_table_insert (uh, (gpointer) enc, uiconv);
+ }
+
+ return uiconv;
+}
+
+
diff --git a/e-util/e-font.h b/e-util/e-font.h
index 9616e9ef4b..90edadcc38 100644
--- a/e-util/e-font.h
+++ b/e-util/e-font.h
@@ -14,6 +14,7 @@
#include <glib.h>
#include <gdk/gdk.h>
+#include <unicode.h>
#include <libgnome/gnome-defs.h>
BEGIN_GNOME_DECLS
@@ -59,6 +60,10 @@ int e_font_utf8_text_width (EFont *font, EFontStyle style,
int e_font_utf8_char_width (EFont *font, EFontStyle style,
char *text);
+const gchar *e_gdk_font_encoding (GdkFont *font);
+unicode_iconv_t e_uiconv_from_gdk_font (GdkFont *font);
+unicode_iconv_t e_uiconv_to_gdk_font (GdkFont *font);
+
END_GNOME_DECLS
#endif
diff --git a/e-util/e-unicode.c b/e-util/e-unicode.c
index eba9bd56d1..0946647fd8 100644
--- a/e-util/e-unicode.c
+++ b/e-util/e-unicode.c
@@ -7,9 +7,13 @@
*/
#include <config.h>
+#include <string.h>
#include <unicode.h>
#include <gdk/gdk.h>
#include "e-unicode.h"
+#include "e-font.h"
+
+#undef FONT_TESTING
void
e_unicode_init (void)
@@ -82,57 +86,34 @@ e_utf8_from_gtk_event_key (GtkWidget *widget, guint keyval, const gchar *string)
utf[unilen] = '\0';
return utf;
-#if 0
- /* test it out with iso-8859-1 */
-
- static gboolean uinit = FALSE;
- static gboolean uerror = FALSE;
- static unicode_iconv_t uiconv = (unicode_iconv_t) -1;
- char *new, *ob;
- size_t ibl, obl;
-
- if (uerror) return NULL;
-
- if (!string) return NULL;
-
- if (!uinit) {
- e_unicode_init ();
- uiconv = unicode_iconv_open ("UTF-8", "iso-8859-1");
- if (uiconv == (unicode_iconv_t) -1) {
- uerror = TRUE;
- return NULL;
- } else {
- uinit = TRUE;
- }
- }
-
- ibl = strlen (string);
- new = ob = g_new (gchar, ibl * 6 + 1);
- obl = ibl * 6 + 1;
-
- unicode_iconv (uiconv, &string, &ibl, &ob, &obl);
-
- *ob = '\0';
-
- return new;
-#endif
}
gchar *
e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string)
{
+#ifndef FONT_TESTING
/* test it out with iso-8859-1 */
static gboolean uinit = FALSE;
static gboolean uerror = FALSE;
static unicode_iconv_t uiconv = (unicode_iconv_t) -1;
+ const gchar *encoding;
+#else
+ unicode_iconv_t uiconv;
+#endif
char *new, *ob;
size_t ibl, obl;
+ g_return_val_if_fail (widget != NULL, NULL);
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+#ifndef FONT_TESTING
if (uerror) return NULL;
+#endif
if (!string) return NULL;
+#ifndef FONT_TESTING
if (!uinit) {
e_unicode_init ();
uiconv = unicode_iconv_open ("UTF-8", "iso-8859-1");
@@ -143,6 +124,10 @@ e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string)
uinit = TRUE;
}
}
+#else
+ uiconv = e_uiconv_from_gdk_font (widget->style->font);
+ if (uiconv == (unicode_iconv_t) -1) return NULL;
+#endif
ibl = strlen (string);
new = ob = g_new (gchar, ibl * 6 + 1);
@@ -158,18 +143,25 @@ e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string)
gchar *
e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string)
{
+#ifndef FONT_TESTING
/* test it out with iso-8859-1 */
static gboolean uinit = FALSE;
static gboolean uerror = FALSE;
static unicode_iconv_t uiconv = (unicode_iconv_t) -1;
+#else
+ unicode_iconv_t uiconv;
+#endif
char *new, *ob;
size_t ibl, obl;
+#ifndef FONT_TESTING
if (uerror) return NULL;
+#endif
if (!string) return NULL;
+#ifndef FONT_TESTING
if (!uinit) {
e_unicode_init ();
uiconv = unicode_iconv_open ("iso-8859-1", "UTF-8");
@@ -180,10 +172,14 @@ e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string)
uinit = TRUE;
}
}
+#else
+ uiconv = e_uiconv_to_gdk_font (widget->style->font);
+ if (uiconv == (unicode_iconv_t) -1) return NULL;
+#endif
ibl = strlen (string);
- new = ob = g_new (gchar, ibl * 2 + 1);
- obl = ibl * 2 + 1;
+ new = ob = g_new (gchar, ibl * 4 + 1);
+ obl = ibl * 4 + 1;
unicode_iconv (uiconv, &string, &ibl, &ob, &obl);