Enlightenment CVS committal

Author  : kwo
Project : e16
Module  : e

Dir     : e16/e/src


Modified Files:
        E.h ttfont.c 


Log Message:
Use Imlib2 font functions for TT font rendering.
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/src/E.h,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -3 -r1.162 -r1.163
--- E.h 14 Dec 2003 17:24:33 -0000      1.162
+++ E.h 14 Dec 2003 17:37:46 -0000      1.163
@@ -1657,7 +1657,7 @@
 Efont              *Efont_load(char *file, int size);
 void                Efont_free(Efont * f);
 void                EFont_draw_string(Display * disp, Drawable win, GC gc,
-                                     int x, int y, char *text, Efont * font,
+                                     int x, int y, char *text, Efont * f,
                                      Visual * vis, Colormap cm);
 
 void                ErrAlert(int erno);
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/src/ttfont.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -3 -r1.27 -r1.28
--- ttfont.c    12 Dec 2003 18:42:15 -0000      1.27
+++ ttfont.c    14 Dec 2003 17:37:46 -0000      1.28
@@ -22,6 +22,103 @@
  */
 #include "E.h"
 
+#if USE_IMLIB2
+
+struct _efont
+{
+   Imlib_Font         *face;
+};
+
+static void
+ImlibSetFgColorFromGC(Display * disp, GC gc, Colormap cm)
+{
+   XGCValues           xgcv;
+   XColor              xclr;
+   int                 r, g, b;
+
+   XGetGCValues(disp, gc, GCForeground, &xgcv);
+   xclr.pixel = xgcv.foreground;
+   XQueryColor(disp, cm, &xclr);
+   EGetColor(&xclr, &r, &g, &b);
+   imlib_context_set_color(r, g, b, 255);
+}
+
+void
+EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
+                 Efont * f, Visual * vis, Colormap cm)
+{
+   Imlib_Image         im;
+   int                 w, h, ascent, descent;
+
+   Efont_extents(f, text, &ascent, &descent, &w, NULL, NULL, NULL, NULL);
+   h = ascent + descent;
+
+   imlib_context_set_drawable(win);
+   im = imlib_create_image_from_drawable(0, x, y - ascent, w, h, 0);
+   imlib_context_set_image(im);
+
+   imlib_context_set_font(f->face);
+   ImlibSetFgColorFromGC(disp, gc, cm);
+   imlib_text_draw(0, 0, text);
+   imlib_render_image_on_drawable(x, y - ascent);
+   imlib_free_image();
+}
+
+void
+Efont_free(Efont * f)
+{
+   if (!f)
+      return;
+
+   imlib_context_set_font(f->face);
+   imlib_free_font();
+
+   Efree(f);
+}
+
+Efont              *
+Efont_load(char *file, int size)
+{
+   char                s[4096];
+   Efont              *f;
+   Imlib_Font         *ff;
+
+   Esnprintf(s, sizeof(s), "%s/%d", file, size);
+   ff = imlib_load_font(s);
+   if (ff == NULL)
+      return NULL;
+
+   f = Emalloc(sizeof(Efont));
+   f->face = ff;
+
+   return f;
+}
+
+void
+Efont_extents(Efont * f, char *text, int *font_ascent_return,
+             int *font_descent_return, int *width_return,
+             int *max_ascent_return, int *max_descent_return,
+             int *lbearing_return, int *rbearing_return)
+{
+   int                 height;
+
+   if (!f)
+      return;
+
+   imlib_context_set_font(f->face);
+   imlib_get_text_size(text, width_return, &height);
+   if (font_ascent_return)
+      *font_ascent_return = imlib_get_font_ascent();
+   if (font_descent_return)
+      *font_descent_return = imlib_get_font_descent();
+   if (max_ascent_return)
+      *max_ascent_return = imlib_get_maximum_font_ascent();
+   if (max_descent_return)
+      *max_descent_return = imlib_get_maximum_font_descent();
+}
+
+#else /* USE_IMLIB1 */
+
 #if TEST_TTFONT
 #undef XSync
 #undef IC_RenderDepth
@@ -641,7 +738,7 @@
 
 void
 EFont_draw_string(Display * disp, Drawable win, GC gc, int x, int y, char *text,
-                 Efont * font, Visual * vis, Colormap cm)
+                 Efont * f, Visual * vis, Colormap cm)
 {
    XImage             *xim;
    XShmSegmentInfo     shminfo;
@@ -657,10 +754,10 @@
 
    inx = 0;
    iny = 0;
-   rtmp = calc_size(font, &w, &h, text);
+   rtmp = calc_size(f, &w, &h, text);
    rmap = create_font_raster(w, h);
 
-   render_text(rmap, rtmp, font, text, &inx, &iny);
+   render_text(rmap, rtmp, f, text, &inx, &iny);
 
 /*  XGrabServer(disp); */
    GrabX();
@@ -1091,8 +1188,12 @@
    if (max_descent_return)
       *max_descent_return = f->max_descent;
 }
+#endif /* USE_IMLIB1 */
 
 #if TEST_TTFONT
+
+#undef XSync
+
 Display            *disp;
 
 int
@@ -1105,7 +1206,13 @@
    int                 i, j;
 
    disp = XOpenDisplay(NULL);
-   XSync(disp, False);
+
+#if USE_IMLIB2
+   imlib_context_set_display(disp);
+   imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
+   imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
+#endif
+
    srand(time(NULL));
    win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 640, 480, 0,
                             0, 0);




-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to