aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorLauris Kaplinski <lauris@src.gnome.org>2000-08-20 08:02:10 +0800
committerLauris Kaplinski <lauris@src.gnome.org>2000-08-20 08:02:10 +0800
commit9a88f3d4d6efd4a7bdff4981537596aabc4d0433 (patch)
tree7e21227ecc3c004551dbd89cb7bfacee18ad618a /e-util
parent1a2372438209e8aa26310ebec78d2e58707cfe57 (diff)
downloadgsoc2013-evolution-9a88f3d4d6efd4a7bdff4981537596aabc4d0433.tar.gz
gsoc2013-evolution-9a88f3d4d6efd4a7bdff4981537596aabc4d0433.tar.zst
gsoc2013-evolution-9a88f3d4d6efd4a7bdff4981537596aabc4d0433.zip
First step moving to UTF-8 strings
svn path=/trunk/; revision=4885
Diffstat (limited to 'e-util')
-rw-r--r--e-util/ChangeLog6
-rw-r--r--e-util/Makefile.am4
-rw-r--r--e-util/e-font.c107
-rw-r--r--e-util/e-font.h73
4 files changed, 189 insertions, 1 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index a3e431c12e..105ae15f2a 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,9 @@
+2000-08-19 Lauris Kaplinski lauris@helixcode.com
+
+ * e-font.h:
+ * e-font.c: Thin wrapper around GdkFont to deal with UTF-8 directly
+ Also handles bold/italic styling
+
2000-08-14 Peter Williams <peterw@helixcode.com>
* e-sexp.c (scanner_config): Add "-" to be an acceptable
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index dfb7724ae1..76af78b891 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -38,7 +38,9 @@ libeutil_la_SOURCES = \
e-util.c \
e-util.h \
e-xml-utils.c \
- e-xml-utils.h
+ e-xml-utils.h \
+ e-font.c \
+ e-font.h
libeutil_static_la_SOURCES = $(libeutil_la_SOURCES)
libeutil_static_la_LDFLAGS = --all-static \ No newline at end of file
diff --git a/e-util/e-font.c b/e-util/e-font.c
new file mode 100644
index 0000000000..1c5bc211cb
--- /dev/null
+++ b/e-util/e-font.c
@@ -0,0 +1,107 @@
+#define _E_FONT_C_
+
+/*
+ * e-font
+ *
+ * Temporary wrappers around GdkFonts to get unicode displaying
+ *
+ * Author: Lauris Kaplinski <lauris@helixcode.com>
+ *
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ */
+
+#include <unicode.h>
+#include "e-font.h"
+
+struct _EFont {
+ GdkFont font;
+};
+
+EFont *
+e_font_from_gdk_name (const gchar *name)
+{
+ GdkFont *font;
+
+ font = gdk_fontset_load (name);
+
+ return (EFont *) font;
+}
+
+EFont *
+e_font_from_gdk_font (GdkFont *font)
+{
+ gdk_font_ref (font);
+
+ return (EFont *) font;
+}
+
+void
+e_font_ref (EFont *font)
+{
+ gdk_font_ref (&font->font);
+}
+
+void
+e_font_unref (EFont *font)
+{
+ gdk_font_unref (&font->font);
+}
+
+gint
+e_font_ascent (EFont * font)
+{
+ return font->font.ascent;
+}
+
+gint
+e_font_descent (EFont * font)
+{
+ return font->font.descent;
+}
+
+void
+e_font_draw_utf8_text (GdkDrawable *drawable, EFont *font, EFontStyle style, GdkGC *gc, gint x, gint y, gchar *text, gint length)
+{
+ guchar *iso_text;
+ gchar *p;
+ gint uni, i;
+
+ iso_text = alloca (length);
+
+ for (p = text, i = 0; i < length; i++, p = unicode_next_utf8 (p)) {
+ unicode_get_utf8 (p, &uni);
+ if ((uni < ' ') || (uni > 255)) uni = ' ';
+ iso_text[i] = uni;
+ }
+
+ gdk_draw_text (drawable, &font->font, gc, x, y, iso_text, length);
+
+ if (style & E_FONT_BOLD)
+ gdk_draw_text (drawable, &font->font, gc, x + 1, y, iso_text, length);
+}
+
+gint
+e_font_utf8_text_width (EFont *font, EFontStyle style, char *text, int length)
+{
+ guchar *iso_text;
+ gchar *p;
+ gint uni, i;
+
+ iso_text = alloca (length);
+
+ for (p = text, i = 0; i < length; i++, p = unicode_next_utf8 (p)) {
+ unicode_get_utf8 (p, &uni);
+ if ((uni < ' ') || (uni > 255)) uni = ' ';
+ iso_text[i] = uni;
+ }
+
+ return gdk_text_width (&font->font, iso_text, length);
+}
+
+
+
+
+
+
+
diff --git a/e-util/e-font.h b/e-util/e-font.h
new file mode 100644
index 0000000000..74c91aace5
--- /dev/null
+++ b/e-util/e-font.h
@@ -0,0 +1,73 @@
+#ifndef _E_FONT_H_
+#define _E_FONT_H_
+
+/*
+ * e-font
+ *
+ * Temporary wrappers around GdkFonts to get unicode displaying
+ *
+ * Author: Lauris Kaplinski <lauris@helixcode.com>
+ *
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ */
+
+#include <glib.h>
+#include <gdk/gdk.h>
+#include <libgnome/gnome-defs.h>
+
+BEGIN_GNOME_DECLS
+
+typedef struct _EFont EFont;
+
+/*
+ * We use very primitive styling here, enough for marking read/unread lines
+ */
+
+typedef enum {
+ E_FONT_PLAIN = 0,
+ E_FONT_BOLD = (1 << 0),
+ E_FONT_ITALIC = (1 << 4)
+} EFontStyle;
+
+EFont * e_font_from_gdk_name (const gchar *name);
+EFont * e_font_from_gdk_font (GdkFont *font);
+
+void e_font_ref (EFont *font);
+void e_font_unref (EFont *font);
+
+gint e_font_ascent (EFont * font);
+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
+
+END_GNOME_DECLS
+
+#endif