Enlightenment CVS committal

Author  : kwo
Project : e16
Module  : e

Dir     : e16/e/src


Modified Files:
        iclass.c tclass.h text.c ttfont.c 


Log Message:
Font drawing code refactoring continued.

===================================================================
RCS file: /cvs/e/e16/e/src/iclass.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -3 -r1.107 -r1.108
--- iclass.c    7 Aug 2006 20:47:12 -0000       1.107
+++ iclass.c    20 Oct 2006 20:41:13 -0000      1.108
@@ -1194,7 +1194,7 @@
                       EXCopyArea(pmm.pmap, pmap, 0, 0, w, h, 0, 0);
                    }
 
-                 TextstateDrawText(ts, win, pmap, text, 0, 0, w, h,
+                 TextstateTextDraw(ts, win, pmap, text, 0, 0, w, h,
                                    &(ic->padding), 0,
                                    TextclassGetJustification(tc));
               }
===================================================================
RCS file: /cvs/e/e16/e/src/tclass.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -3 -r1.14 -r1.15
--- tclass.h    20 Oct 2006 15:38:48 -0000      1.14
+++ tclass.h    20 Oct 2006 20:41:13 -0000      1.15
@@ -60,12 +60,14 @@
    void                (*Destroy) (TextState * ts);
    void                (*TextSize) (TextState * ts, const char *text, int len,
                                    int *width, int *height, int *ascent);
-   void                (*TextMangle) (TextState * ts, char **ptext,
-                                     int *pwidth, int textwidth_limit);
+   void                (*TextFit) (TextState * ts, char **ptext,
+                                  int *pwidth, int textwidth_limit);
    void                (*TextDraw) (TextState * ts, FontDrawContext * ctx,
                                    int x, int y, const char *text, int len);
-   void                (*FdcInit) (TextState * ts, FontDrawContext * ctx,
-                                  Win win);
+   int                 (*FdcInit) (TextState * ts, FontDrawContext * ctx,
+                                  Win win, Drawable draw);
+   void                (*FdcSetDrawable) (TextState * ts, FontDrawContext * 
ctx,
+                                         Drawable draw);
    void                (*FdcSetColor) (TextState * ts, FontDrawContext * ctx,
                                       XColor * xc);
 } FontOps;
@@ -134,7 +136,9 @@
 /* text.c */
 TextState          *TextclassGetTextState(TextClass * tclass, int state,
                                          int active, int sticky);
-void                TextstateDrawText(TextState * ts, Win win, Drawable draw,
+void                TextstateTextFitMB(TextState * ts, char **ptext, int *pw,
+                                      int textwidth_limit);
+void                TextstateTextDraw(TextState * ts, Win win, Drawable draw,
                                      const char *text, int x, int y, int w,
                                      int h, const EImageBorder * pad,
                                      int fsize, int justification);
===================================================================
RCS file: /cvs/e/e16/e/src/text.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -3 -r1.75 -r1.76
--- text.c      20 Oct 2006 15:38:48 -0000      1.75
+++ text.c      20 Oct 2006 20:41:13 -0000      1.76
@@ -329,103 +329,33 @@
    XmbDrawString(disp, fdc->draw, ts->f.xfs.font, fdc->gc, x, y, text, len);
 }
 
-static void
-XfsFdcInit(TextState * ts __UNUSED__, FontDrawContext * fdc, Win win)
+static int
+XfsFdcInit(TextState * ts __UNUSED__, FontDrawContext * fdc, Win win,
+          Drawable draw)
 {
    fdc->win = win;
+   fdc->draw = draw;
    fdc->gc = _get_gc(win);
+   return 0;
 }
 
 static void
-XfsFdcSetColor(TextState * ts __UNUSED__, FontDrawContext * fdc, XColor * xc)
+XfsFdcSetDrawable(TextState * ts __UNUSED__, FontDrawContext * fdc,
+                 Drawable draw)
 {
-   EAllocColor(WinGetCmap(fdc->win), xc);
-   XSetForeground(disp, fdc->gc, xc->pixel);
+   fdc->draw = draw;
 }
 
 static void
-XfsTextMangle(TextState * ts, char **ptext, int *pw, int textwidth_limit)
+XfsFdcSetColor(TextState * ts __UNUSED__, FontDrawContext * fdc, XColor * xc)
 {
-   char               *text = *ptext;
-   int                 hh, ascent;
-   char               *new_line;
-   int                 nuke_count = 0;
-   int                 len;
-   wchar_t            *wc_line = NULL;
-   int                 wc_len;
-
-   len = strlen(text);
-   new_line = Emalloc(len + 10);
-   if (!new_line)
-      return;
-
-   wc_len = mbstowcs(NULL, text, 0);
-   if (wc_len > 0)
-     {
-       wc_line = (wchar_t *) Emalloc((wc_len + 1) * sizeof(wchar_t));
-       mbstowcs(wc_line, text, len);
-       wc_line[wc_len] = (wchar_t) '\0';
-     }
-
-   while (*pw > textwidth_limit)
-     {
-       nuke_count++;
-       if (nuke_count > wc_len)
-         {
-            int                 mlen;
-
-            new_line[0] = 0;
-            if (MB_CUR_MAX > 1 && wc_len > 0)
-              {                /* if multibyte locale,... */
-                 mlen = mblen(text, MB_CUR_MAX);
-                 if (mlen < 0)
-                    mlen = 1;
-              }
-            else
-               mlen = 1;
-
-            strncat(new_line, text, mlen);
-            strcat(new_line, "...");
-            break;
-         }
-       new_line[0] = 0;
-       if (MB_CUR_MAX > 1 && wc_len > 0)
-         {
-            int                 j, k, len_mb;
-
-            for (j = k = 0; k < (wc_len - nuke_count) / 2; k++)
-              {
-                 len_mb = wctomb(new_line + j, wc_line[k]);
-                 if (len_mb > 0)
-                    j += len_mb;
-              }
-            new_line[j] = '\0';
-            strcat(new_line, "...");
-            j += 3;
-            len_mb = wcstombs(new_line + j,
-                              wc_line + (wc_len - nuke_count) / 2 +
-                              nuke_count, len + 10 - j);
-            if (len_mb > 0)
-               j += len_mb;
-            new_line[j] = '\0';
-         }
-       else
-         {
-            strncat(new_line, text, (len - nuke_count) / 2);
-            strcat(new_line, "...");
-            strcat(new_line, text + ((len - nuke_count) / 2) + nuke_count);
-         }
-       ts->ops->TextSize(ts, new_line, 0, pw, &hh, &ascent);
-     }
-   Efree(text);
-   *ptext = new_line;
-   if (wc_line)
-      Efree(wc_line);
+   EAllocColor(WinGetCmap(fdc->win), xc);
+   XSetForeground(disp, fdc->gc, xc->pixel);
 }
 
 const FontOps       FontOpsXfs = {
-   XfsLoad, XfsUnload, XfsTextSize, XfsTextMangle, XfsTextDraw,
-   XfsFdcInit, XfsFdcSetColor
+   XfsLoad, XfsUnload, XfsTextSize, TextstateTextFitMB, XfsTextDraw,
+   XfsFdcInit, XfsFdcSetDrawable, XfsFdcSetColor
 };
 #endif /* FONT_TYPE_XFS */
 
@@ -487,13 +417,23 @@
       XDrawString16(disp, fdc->draw, fdc->gc, x, y, (XChar2b *) text, len);
 }
 
-static void
-XfontFdcInit(TextState * ts __UNUSED__, FontDrawContext * fdc, Win win)
+static int
+XfontFdcInit(TextState * ts __UNUSED__, FontDrawContext * fdc, Win win,
+            Drawable draw)
 {
    fdc->win = win;
+   fdc->draw = draw;
    fdc->gc = _get_gc(win);
 
    XSetFont(disp, fdc->gc, ts->f.xf.font->fid);
+   return 0;
+}
+
+static void
+XfontFdcSetDrawable(TextState * ts __UNUSED__, FontDrawContext * fdc,
+                   Drawable draw)
+{
+   fdc->draw = draw;
 }
 
 static void
@@ -504,7 +444,7 @@
 }
 
 static void
-XfontTextMangle(TextState * ts, char **ptext, int *pw, int textwidth_limit)
+XfontTextFit(TextState * ts, char **ptext, int *pw, int textwidth_limit)
 {
    char               *text = *ptext;
    int                 hh, ascent;
@@ -565,47 +505,11 @@
 }
 
 const FontOps       FontOpsXfont = {
-   XfontLoad, XfontUnload, XfontTextSize, XfontTextMangle, XfontTextDraw,
-   XfontFdcInit, XfontFdcSetColor
+   XfontLoad, XfontUnload, XfontTextSize, XfontTextFit, XfontTextDraw,
+   XfontFdcInit, XfontFdcSetDrawable, XfontFdcSetColor
 };
 #endif /* FONT_TYPE_XFONT */
 
-#if FONT_TYPE_IFT
-static void
-IftTextMangle(TextState * ts, char **ptext, int *pw, int textwidth_limit)
-{
-   char               *text = *ptext;
-   int                 hh, ascent;
-   char               *new_line;
-   int                 nuke_count = 0;
-   int                 len;
-
-   len = strlen(text);
-   new_line = Emalloc(len + 10);
-   if (!new_line)
-      return;
-
-   while (*pw > textwidth_limit)
-     {
-       nuke_count++;
-       if (nuke_count > len)
-         {
-            new_line[0] = 0;
-            strncat(new_line, text, 1);
-            strcat(new_line, "...");
-            break;
-         }
-       new_line[0] = 0;
-       strncat(new_line, text, (len - nuke_count) / 2);
-       strcat(new_line, "...");
-       strcat(new_line, text + ((len - nuke_count) / 2) + nuke_count);
-       ts->ops->TextSize(ts, new_line, 0, pw, &hh, &ascent);
-     }
-   Efree(text);
-   *ptext = new_line;
-}
-#endif /* FONT_TYPE_IFT */
-
 static void
 TsTextDraw(TextState * ts, FontDrawContext * fdc, int x, int y,
           const char *text, int len)
@@ -702,7 +606,87 @@
 }
 
 void
-TextstateDrawText(TextState * ts, Win win, Drawable draw, const char *text,
+TextstateTextFitMB(TextState * ts, char **ptext, int *pw, int textwidth_limit)
+{
+   char               *text = *ptext;
+   int                 hh, ascent;
+   char               *new_line;
+   int                 nuke_count = 0;
+   int                 len;
+   wchar_t            *wc_line = NULL;
+   int                 wc_len;
+
+   len = strlen(text);
+   new_line = Emalloc(len + 10);
+   if (!new_line)
+      return;
+
+   wc_len = mbstowcs(NULL, text, 0);
+   if (wc_len > 0)
+     {
+       wc_line = (wchar_t *) Emalloc((wc_len + 1) * sizeof(wchar_t));
+       mbstowcs(wc_line, text, len);
+       wc_line[wc_len] = (wchar_t) '\0';
+     }
+
+   while (*pw > textwidth_limit)
+     {
+       nuke_count++;
+       if (nuke_count > wc_len)
+         {
+            int                 mlen;
+
+            new_line[0] = 0;
+            if (MB_CUR_MAX > 1 && wc_len > 0)
+              {                /* if multibyte locale,... */
+                 mlen = mblen(text, MB_CUR_MAX);
+                 if (mlen < 0)
+                    mlen = 1;
+              }
+            else
+               mlen = 1;
+
+            strncat(new_line, text, mlen);
+            strcat(new_line, "...");
+            break;
+         }
+       new_line[0] = 0;
+       if (MB_CUR_MAX > 1 && wc_len > 0)
+         {
+            int                 j, k, len_mb;
+
+            for (j = k = 0; k < (wc_len - nuke_count) / 2; k++)
+              {
+                 len_mb = wctomb(new_line + j, wc_line[k]);
+                 if (len_mb > 0)
+                    j += len_mb;
+              }
+            new_line[j] = '\0';
+            strcat(new_line, "...");
+            j += 3;
+            len_mb = wcstombs(new_line + j,
+                              wc_line + (wc_len - nuke_count) / 2 +
+                              nuke_count, len + 10 - j);
+            if (len_mb > 0)
+               j += len_mb;
+            new_line[j] = '\0';
+         }
+       else
+         {
+            strncat(new_line, text, (len - nuke_count) / 2);
+            strcat(new_line, "...");
+            strcat(new_line, text + ((len - nuke_count) / 2) + nuke_count);
+         }
+       ts->ops->TextSize(ts, new_line, 0, pw, &hh, &ascent);
+     }
+   Efree(text);
+   *ptext = new_line;
+   if (wc_line)
+      Efree(wc_line);
+}
+
+void
+TextstateTextDraw(TextState * ts, Win win, Drawable draw, const char *text,
                  int x, int y, int w, int h, const EImageBorder * pad,
                  int fsize __UNUSED__, int justification)
 {
@@ -756,27 +740,24 @@
      }
 
 #if 0
-   Eprintf("TextstateDrawText %d,%d %dx%d(%d): %s\n", x, y, w, h,
+   Eprintf("TextstateTextDraw %d,%d %dx%d(%d): %s\n", x, y, w, h,
           textwidth_limit, text);
 #endif
 
    xx = x;
    yy = y;
 
+   if (ts->ops->FdcInit(ts, &fdc, win, draw))
+      return;
+
 #if FONT_TYPE_IFT
    if (ts->type == FONT_TYPE_IFT)
      {
-       ts->ops->FdcInit(ts, &fdc, win);
-
        for (i = 0; i < num_lines; i++)
          {
             ts->ops->TextSize(ts, lines[i], 0, &ww, &hh, &ascent);
             if (ww > textwidth_limit)
-#if 0
-               ts->ops->TextMangle(ts, &lines[i], &ww, textwidth_limit);
-#else
-               IftTextMangle(ts, &lines[i], &ww, textwidth_limit);
-#endif
+               ts->ops->TextFit(ts, &lines[i], &ww, textwidth_limit);
 
             if (i == 0)
                yy += ascent;
@@ -802,13 +783,11 @@
    else
 #endif /* FONT_TYPE_IFT */
      {
-       ts->ops->FdcInit(ts, &fdc, win);
-
        for (i = 0; i < num_lines; i++)
          {
             ts->ops->TextSize(ts, lines[i], 0, &ww, &hh, &ascent);
             if (ww > textwidth_limit)
-               ts->ops->TextMangle(ts, &lines[i], &ww, textwidth_limit);
+               ts->ops->TextFit(ts, &lines[i], &ww, textwidth_limit);
 
             if (i == 0)
                yy += ascent;
@@ -818,7 +797,6 @@
                drawable = ECreatePixmap(win, ww + 2, hh + 2, 0);
             else
                drawable = draw;
-            fdc.draw = drawable;
             TextDrawRotTo(win, draw, drawable, xx - 1, yy - 1 - ascent,
                           ww + 2, hh + 2, ts);
 
@@ -833,6 +811,9 @@
                  offset_y = ascent + 1;
               }
 
+            if (drawable != draw)
+               ts->ops->FdcSetDrawable(ts, &fdc, drawable);
+
             TsTextDraw(ts, &fdc, offset_x, offset_y, lines[i],
                        strlen(lines[i]));
 
@@ -862,6 +843,6 @@
    if (!ts)
       return;
 
-   TextstateDrawText(ts, win, draw, text, x, y, w, h, NULL, fsize,
+   TextstateTextDraw(ts, win, draw, text, x, y, w, h, NULL, fsize,
                     justification);
 }
===================================================================
RCS file: /cvs/e/e16/e/src/ttfont.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -3 -r1.53 -r1.54
--- ttfont.c    18 Oct 2006 18:19:14 -0000      1.53
+++ ttfont.c    20 Oct 2006 20:41:13 -0000      1.54
@@ -149,10 +149,11 @@
                     text);
 }
 
-static void
+static int
 IftFdcInit(TextState * ts __UNUSED__, FontDrawContext * fdc __UNUSED__,
-          Win win __UNUSED__)
+          Win win __UNUSED__, Drawable draw __UNUSED__)
 {
+   return 0;
 }
 
 static void
@@ -161,20 +162,9 @@
    EGetColor(xc, &(fdc->r), &(fdc->g), &(fdc->b));
 }
 
-#if 0                          /* Well... */
-static void
-IftTextMangle(TextState * ts, char **ptext, int *pw, int textwidth_limit)
-{
-   ts = NULL;
-   ptext = NULL;
-   pw = NULL;
-   textwidth_limit = 0;
-}
-#endif
-
 const FontOps       FontOpsIft = {
-   IftLoad, IftUnload, IftTextSize, NULL, IftTextDraw,
-   IftFdcInit, IftFdcSetColor
+   IftLoad, IftUnload, IftTextSize, TextstateTextFitMB, IftTextDraw,
+   IftFdcInit, NULL, IftFdcSetColor
 };
 
 #if TEST_TTFONT



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to