Enlightenment CVS committal

Author  : kwo
Project : e16
Module  : e

Dir     : e16/e/src


Modified Files:
        E.h lang.c text.c 


Log Message:
Some more preparations for UTF8.
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/src/E.h,v
retrieving revision 1.266
retrieving revision 1.267
diff -u -3 -r1.266 -r1.267
--- E.h 19 May 2004 21:41:02 -0000      1.266
+++ E.h 22 May 2004 15:18:04 -0000      1.267
@@ -1275,6 +1275,10 @@
       char                swap;
       int                 swapcoord_x, swapcoord_y;
    } move;
+   struct
+   {
+      char                utf8;        /* Use UTF8 internally */
+   } text;
    int                 debug;
    int                 mode;
    char                place;
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/src/lang.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- lang.c      1 Apr 2004 23:11:16 -0000       1.1
+++ lang.c      22 May 2004 15:18:04 -0000      1.2
@@ -23,6 +23,10 @@
  */
 #include "E.h"
 
+#if HAVE_LANGINFO_CODESET
+#include <langinfo.h>
+#endif
+
 #if 0                          /* Not used yet */
 
 #include <iconv.h>
@@ -51,9 +55,11 @@
 void
 LangInit(void)
 {
-   const char         *str;
+   const char         *enc_env, *enc_int;
 
+   /* Set up things according to env vars */
    setlocale(LC_ALL, "");
+
    bindtextdomain(PACKAGE, LOCALEDIR);
    textdomain(PACKAGE);
 
@@ -64,18 +70,22 @@
    /* I dont want any internationalisation of my numeric input & output */
    setlocale(LC_NUMERIC, "C");
 
-   str = getenv("E_CHARSET");
-#if 0
-   if (str == NULL)
-      str = "UTF-8";
+   /* Get the environment character encoding */
+#if HAVE_LANGINFO_CODESET
+   enc_env = nl_langinfo(CODESET);
+#else
+   enc_env = "ISO-8859-1";
 #endif
-   if (str)
-     {
-       bind_textdomain_codeset(PACKAGE, str);
-#if 0
-       iconv_cd = iconv_open(str, "ISO_8859-1");
-#endif
-     }
+
+   /* Debug - possibility to set desired internal representation */
+   enc_int = getenv("E_CHARSET");
+   if (enc_int)
+      bind_textdomain_codeset(PACKAGE, enc_int);
+   else
+      enc_int = enc_env;
+
+   if (!strcasecmp(enc_int, "utf8") || !strcasecmp(enc_int, "utf-8"))
+      Mode.text.utf8 = 1;
 }
 
 #if 0                          /* Not used yet */
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/src/text.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -3 -r1.35 -r1.36
--- text.c      4 May 2004 19:04:41 -0000       1.35
+++ text.c      22 May 2004 15:18:04 -0000      1.36
@@ -28,6 +28,34 @@
 static void         TextDrawRotBack(Window win, Drawable drawable, int x, int y,
                                    int w, int h, TextState * ts);
 
+static int
+ExTextExtents(XFontSet font_set, const char *string, int len,
+             XRectangle * oir, XRectangle * olr)
+{
+#ifdef X_HAVE_UTF8_STRING
+   if (Mode.text.utf8)
+     {
+       return Xutf8TextExtents(font_set, string, len, oir, olr);
+     }
+#endif
+
+   return XmbTextExtents(font_set, string, len, oir, olr);
+}
+
+static void
+ExDrawString(Display * display, Drawable d, XFontSet font_set, GC
+            gc, int x, int y, const char *string, int len)
+{
+#ifdef X_HAVE_UTF8_STRING
+   if (Mode.text.utf8)
+     {
+       Xutf8DrawString(display, d, font_set, gc, x, y, string, len);
+       return;
+     }
+#endif
+   XmbDrawString(display, d, font_set, gc, x, y, string, len);
+}
+
 TextState          *
 TextGetState(TextClass * tclass, int active, int sticky, int state)
 {
@@ -139,91 +167,91 @@
 TextStateLoadFont(TextState * ts)
 {
    EDBUG(5, "TextStateLoadFont");
+
+   if (!ts->fontname)
+      EDBUG_RETURN_;
+
+   /* Quit if already done */
 #if USE_FNLIB
    if ((ts->font) || (ts->efont) || (ts->xfont) || (ts->xfontset))
 #else
    if ((ts->efont) || (ts->xfont) || (ts->xfontset))
 #endif
       EDBUG_RETURN_;
-   if (!ts->fontname)
-      EDBUG_RETURN_;
-#if USE_FNLIB
-   if ((!ts->font) && (!ts->efont))
-      ts->font = Fnlib_load_font(pFnlibData, ts->fontname);
-#endif
-#if USE_FNLIB
-   if ((!ts->font) && (!ts->efont))
-#else
-   if (!ts->efont)
-#endif
-     {
-       char                s[4096], w[4046], *s2, *ss;
 
-       s2 = NULL;
-       s2 = Estrdup(ts->fontname);
-       ss = strchr(s2, '/');
-       if (ss)
-         {
-            *ss = ' ';
-            word(s2, 1, w);
-            Esnprintf(s, sizeof(s), "ttfonts/%s.ttf", w);
-            word(s2, 2, w);
-            ss = FindFile(s);
-            if (ss)
-              {
-                 ts->efont = Efont_load(ss, atoi(w));
-                 Efree(ss);
-              }
-         }
-       if (s2)
-          Efree(s2);
-     }
 #if USE_FNLIB
-   if ((!ts->font) && (!ts->efont))
-#else
-   if (!ts->efont)
+   /* Try Fnlib */
+   ts->font = Fnlib_load_font(pFnlibData, ts->fontname);
+   if (ts->font)
+      goto done;
 #endif
-     {
-       if ((!ts->xfont) && (strchr(ts->fontname, ',') == NULL))
-         {
-            ts->xfont = XLoadQueryFont(disp, ts->fontname);
-         }
-       else if (!ts->xfontset)
-         {
-            int                 i, missing_cnt, font_cnt;
-            char              **missing_list, *def_str, **fn;
-            XFontStruct       **fs;
 
-            ts->xfontset =
-               XCreateFontSet(disp, ts->fontname, &missing_list, &missing_cnt,
-                              &def_str);
-            if (missing_cnt)
-              {
-                 XFreeStringList(missing_list);
-                 /* EDBUG_RETURN_; */
-              }
+   /* Try FreeType */
+   {
+      char                s[4096], w[4046], *s2, *ss;
+
+      s2 = NULL;
+      s2 = Estrdup(ts->fontname);
+      ss = strchr(s2, '/');
+      if (ss)
+       {
+          *ss = ' ';
+          word(s2, 1, w);
+          Esnprintf(s, sizeof(s), "ttfonts/%s.ttf", w);
+          word(s2, 2, w);
+          ss = FindFile(s);
+          if (ss)
+            {
+               ts->efont = Efont_load(ss, atoi(w));
+               Efree(ss);
+            }
+       }
+      if (s2)
+        Efree(s2);
+   }
+   if (ts->efont)
+      goto done;
 
-            if (!ts->xfontset)
-              {
-                 ts->xfontset =
-                    XCreateFontSet(disp, "fixed", &missing_list, &missing_cnt,
-                                   &def_str);
-                 if (missing_cnt)
-                    XFreeStringList(missing_list);
-              }
+   /* Try X11 XCreateFontSet */
+   {
+      int                 i, missing_cnt, font_cnt;
+      char              **missing_list, *def_str, **fn;
+      XFontStruct       **fs;
+
+      ts->xfontset = XCreateFontSet(disp, ts->fontname, &missing_list,
+                                   &missing_cnt, &def_str);
+      if (missing_cnt)
+        XFreeStringList(missing_list);
+
+      if (!ts->xfontset)
+       {
+          ts->xfontset = XCreateFontSet(disp, "fixed", &missing_list,
+                                        &missing_cnt, &def_str);
+          if (missing_cnt)
+             XFreeStringList(missing_list);
+       }
+
+      if (ts->xfontset)
+       {
+          ts->xfontset_ascent = 0;
+          font_cnt = XFontsOfFontSet(ts->xfontset, &fs, &fn);
+          for (i = 0; i < font_cnt; i++)
+             ts->xfontset_ascent = MAX(fs[i]->ascent, ts->xfontset_ascent);
+       }
+   }
+   if (ts->xfontset)
+      goto done;
+
+   /* Try X11 XLoadQueryFont */
+   if (strchr(ts->fontname, ',') == NULL)
+      ts->xfont = XLoadQueryFont(disp, ts->fontname);
+   if (ts->xfont)
+      goto done;
 
-            if (ts->xfontset)
-              {
-                 ts->xfontset_ascent = 0;
-                 font_cnt = XFontsOfFontSet(ts->xfontset, &fs, &fn);
-                 for (i = 0; i < font_cnt; i++)
-                    ts->xfontset_ascent =
-                       MAX(fs[i]->ascent, ts->xfontset_ascent);
-              }
-         }
-       if (!ts->xfont)
-          ts->xfont = XLoadQueryFont(disp, "fixed");
-     }
+   /* This one really should succeed! */
+   ts->xfont = XLoadQueryFont(disp, "fixed");
+
+ done:
    EDBUG_RETURN_;
 }
 
@@ -282,8 +310,8 @@
          {
             XRectangle          ret1, ret2;
 
-            XmbTextExtents(ts->xfontset, lines[i], strlen(lines[i]), &ret1,
-                           &ret2);
+            ExTextExtents(ts->xfontset, lines[i], strlen(lines[i]), &ret1,
+                          &ret2);
             *height += ret2.height;
             if (ret2.width > *width)
                *width = ret2.width;
@@ -476,8 +504,8 @@
          {
             XRectangle          ret1, ret2;
 
-            XmbTextExtents(ts->xfontset, lines[i], strlen(lines[i]), &ret1,
-                           &ret2);
+            ExTextExtents(ts->xfontset, lines[i], strlen(lines[i]), &ret1,
+                          &ret2);
             if (ret2.width > textwidth_limit)
               {
                  char               *new_line;
@@ -548,8 +576,8 @@
                                   lines[i] + ((len - nuke_count) / 2) +
                                   nuke_count);
                         }
-                      XmbTextExtents(ts->xfontset, new_line, strlen(new_line),
-                                     &ret1, &ret2);
+                      ExTextExtents(ts->xfontset, new_line, strlen(new_line),
+                                    &ret1, &ret2);
                    }
                  Efree(lines[i]);
                  lines[i] = new_line;
@@ -584,26 +612,26 @@
               {
                  EAllocColor(&ts->bg_col);
                  XSetForeground(disp, gc, ts->bg_col.pixel);
-                 XmbDrawString(disp, drawable, ts->xfontset, gc, offset_x + 1,
-                               offset_y + 1, lines[i], strlen(lines[i]));
+                 ExDrawString(disp, drawable, ts->xfontset, gc, offset_x + 1,
+                              offset_y + 1, lines[i], strlen(lines[i]));
               }
             else if (ts->effect == 2)
               {
                  EAllocColor(&ts->bg_col);
                  XSetForeground(disp, gc, ts->bg_col.pixel);
-                 XmbDrawString(disp, drawable, ts->xfontset, gc, offset_x - 1,
-                               offset_y, lines[i], strlen(lines[i]));
-                 XmbDrawString(disp, drawable, ts->xfontset, gc, offset_x + 1,
-                               offset_y, lines[i], strlen(lines[i]));
-                 XmbDrawString(disp, drawable, ts->xfontset, gc, offset_x,
-                               offset_y - 1, lines[i], strlen(lines[i]));
-                 XmbDrawString(disp, drawable, ts->xfontset, gc, offset_x,
-                               offset_y + 1, lines[i], strlen(lines[i]));
+                 ExDrawString(disp, drawable, ts->xfontset, gc, offset_x - 1,
+                              offset_y, lines[i], strlen(lines[i]));
+                 ExDrawString(disp, drawable, ts->xfontset, gc, offset_x + 1,
+                              offset_y, lines[i], strlen(lines[i]));
+                 ExDrawString(disp, drawable, ts->xfontset, gc, offset_x,
+                              offset_y - 1, lines[i], strlen(lines[i]));
+                 ExDrawString(disp, drawable, ts->xfontset, gc, offset_x,
+                              offset_y + 1, lines[i], strlen(lines[i]));
               }
             EAllocColor(&ts->fg_col);
             XSetForeground(disp, gc, ts->fg_col.pixel);
-            XmbDrawString(disp, drawable, ts->xfontset, gc, offset_x, offset_y,
-                          lines[i], strlen(lines[i]));
+            ExDrawString(disp, drawable, ts->xfontset, gc, offset_x, offset_y,
+                         lines[i], strlen(lines[i]));
 
             TextDrawRotBack(win, drawable, xx - 1,
                             yy - (ts->xfontset_ascent) - 1, ret2.width + 2,




-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to