This is a little uglier than I would like because I wanted to keep
it a compile-time option as well; now a truetype font is used if
both XFT_SUPPORT is defined and a fontName is set.  If it is not,
dclock falls back to the non-freetype code.
---
 Dclock.c  |  140 +++++++++++++++++++++++++++++++++++--------------------------
 DclockP.h |    3 +-
 2 files changed, 83 insertions(+), 60 deletions(-)

diff --git a/Dclock.c b/Dclock.c
index 0e41d85..cd83a24 100644
--- a/Dclock.c
+++ b/Dclock.c
@@ -165,7 +165,7 @@ static XtResource resources[] = {
        XtOffset(DclockWidget,dclock.font), XtRString, "fixed"},
 #ifdef XFT_SUPPORT
     { XftNfontName, "fontName", XtRString, sizeof(String),
-       XtOffset(DclockWidget,dclock.xftfontname), XtRString, "charter"},
+       XtOffset(DclockWidget,dclock.xftfontname), XtRString, NULL},
 #endif
     { XtNangle, "Slope", XtRFloat, sizeof(float),
        XtOffset(DclockWidget,dclock.angle), XtRFloat, (caddr_t)&sslope},
@@ -344,6 +344,12 @@ typedef XfPoint segment_pts[NUM_SEGS][MAX_PTS];
 segment_pts tiny_segment_pts;
 segment_pts norm_segment_pts;
 
+#ifdef XFT_SUPPORT
+#define XFT_COND(dclock) ((dclock).xftfontname)
+#else
+#define XFT_COND(dclock) (0)
+#endif
+
 /* ARGSUSED */
 static void
 Initialize (request, new)
@@ -386,11 +392,13 @@ DclockWidget   new;
     if (new->dclock.sec_gap < 0.0) new->dclock.sec_gap = 0.0;
 
 #ifdef XFT_SUPPORT
-    new->dclock.xftfont = XftFontOpen(dpy, DefaultScreen(dpy),
+    if (XFT_COND(new->dclock)) {
+       new->dclock.xftfont = XftFontOpen(dpy, DefaultScreen(dpy),
                XFT_FAMILY, XftTypeString, new->dclock.xftfontname,
                XFT_SIZE, XftTypeDouble, ((float)new->core.height / 6.0) - 4.0,
                NULL);
-    new->dclock.xftdraw = NULL;
+       new->dclock.xftdraw = NULL;
+    }
 #endif
 
     GetGC(new);
@@ -447,11 +455,11 @@ DclockWidget   new;
     if (new->dclock.date_fmt && !*new->dclock.date_fmt)
        new->dclock.date_fmt = NULL;
     if (new->dclock.dateup && new->dclock.date_fmt)
-#ifdef XFT_SUPPORT
+    if (XFT_COND(new->dclock)) {
        TopOffset = new->core.height / 6;
-#else
+    } else {
        TopOffset = new->dclock.font->ascent + new->dclock.font->descent;
-#endif
+    }
 
     else
        TopOffset = 0;
@@ -519,7 +527,7 @@ XSetWindowAttributes *attrs;
     XtCreateWindow(w, InputOutput, (Visual *)CopyFromParent, *valueMask, 
attrs);
 
 #ifdef XFT_SUPPORT
-    if (dw->dclock.xftdraw == NULL) {
+    if (XFT_COND(dw->dclock) && dw->dclock.xftdraw == NULL) {
        XColor color;
        Colormap cm = DefaultColormap(dp, sc);
 
@@ -574,7 +582,8 @@ DclockWidget w;
     XDestroyRegion(clip_colon);
 
 #ifdef XFT_SUPPORT
-    XftFontClose(XtDisplay(w), w->dclock.xftfont);
+    if (XFT_COND(w->dclock))
+       XftFontClose(XtDisplay(w), w->dclock.xftfont);
 #endif
 }
 
@@ -596,11 +605,13 @@ DclockWidget    w;
     winheight = w->core.height;
 
 #ifdef XFT_SUPPORT
-    XftFontClose(dpy, w->dclock.xftfont);
-    w->dclock.xftfont = XftFontOpen(dpy, DefaultScreen(dpy),
+    if(XFT_COND(w->dclock)) {
+       XftFontClose(dpy, w->dclock.xftfont);
+       w->dclock.xftfont = XftFontOpen(dpy, DefaultScreen(dpy),
                XFT_FAMILY, XftTypeString, w->dclock.xftfontname,
                XFT_SIZE, XftTypeDouble, ((float)winheight / 6.0) - 4.0,
                NULL);
+    }
 #endif
 
     y_ratio = (float)winheight / CLOCK_HEIGHT;
@@ -608,11 +619,13 @@ DclockWidget    w;
     if (w->dclock.date_fmt || !w->dclock.display_time || w->dclock.alarm ||
        w->dclock.bell)
        /* make win temporarily shorter so digits will fit on top of date */
-#ifdef XFT_SUPPORT
-       winheight -= w->core.height / 6;
-#else
-       winheight -= w->dclock.font->ascent + w->dclock.font->descent;
-#endif
+    {
+       if(XFT_COND(w->dclock)) {
+           winheight -= w->core.height / 6;
+       } else {
+           winheight -= w->dclock.font->ascent + w->dclock.font->descent;
+       }
+    }
 
     /*
      * if the width of all segments are equal, then the width in x is the
@@ -1669,51 +1682,60 @@ struct tm *now;
     char datestr[128];
     register char *p;
     int x, datep;
+    int tsize;
 #ifdef XFT_SUPPORT
-    int tsize = w->core.height / 6;
     XGlyphInfo xftextents;
-#else
-    int tsize = w->dclock.font->ascent + w->dclock.font->descent;
 #endif
 
+    if (XFT_COND(w->dclock)) {
+       tsize = w->core.height / 6;
+    } else {
+       tsize = w->dclock.font->ascent + w->dclock.font->descent;
+    }
+
     if (!w->dclock.display_time)
        datep = strlen(strcpy(datestr, "Push HERE to Set/Unset Alarm"));
     else
         datep = strftime(datestr, 128, w->dclock.date_fmt, now);
 
+    if (XFT_COND(w->dclock)) {
 #ifdef XFT_SUPPORT
-    XftTextExtents8(dpy, w->dclock.xftfont, datestr, datep, &xftextents);
-    x = (w->core.width - xftextents.width) / 2;
-#else
-    x = (w->core.width - XTextWidth(w->dclock.font, datestr, datep)) / 2;
+       XftTextExtents8(dpy, w->dclock.xftfont, datestr, datep, &xftextents);
+       x = (w->core.width - xftextents.width) / 2;
 #endif
+    } else {
+       x = (w->core.width - XTextWidth(w->dclock.font, datestr, datep)) / 2;
+    }
+
     if (x < 2)
        x = 2;
     if (TopOffset) {
-
+       if (XFT_COND(w->dclock)) {
 #ifdef XFT_SUPPORT
-       XftDrawRect(w->dclock.xftdraw, &w->dclock.xftbg, 0, 0, winwidth, tsize);
-       XftDrawString8(w->dclock.xftdraw, &w->dclock.xftfg, w->dclock.xftfont, 
x,
+           XftDrawRect(w->dclock.xftdraw, &w->dclock.xftbg, 0, 0, winwidth, 
tsize);
+           XftDrawString8(w->dclock.xftdraw, &w->dclock.xftfg, 
w->dclock.xftfont, x,
                (BORDER/2) + tsize - 2, datestr, datep);
-#else
-       XFillRectangle(dpy, win, w->dclock.backGC,
-           0, 0, winwidth, tsize);
-       XDrawString(dpy, win, w->dclock.foreGC,
-               x, ((BORDER/2)+w->dclock.xftfont->height), datestr, datep);
 #endif
+       } else {
+           XFillRectangle(dpy, win, w->dclock.backGC,
+               0, 0, winwidth, tsize);
+           XDrawString(dpy, win, w->dclock.foreGC,
+               x, ((BORDER/2)+tsize), datestr, datep);
+       }
     } else {
-
+       if (XFT_COND(w->dclock)) {
 #ifdef XFT_SUPPORT
-       XftDrawRect(w->dclock.xftdraw, &w->dclock.xftbg, 0, winheight - tsize,
+           XftDrawRect(w->dclock.xftdraw, &w->dclock.xftbg, 0, winheight - 
tsize,
                winwidth, tsize);
-       XftDrawString8(w->dclock.xftdraw, &w->dclock.xftfg, w->dclock.xftfont, 
x,
+           XftDrawString8(w->dclock.xftdraw, &w->dclock.xftfg, 
w->dclock.xftfont, x,
                winheight - BORDER - 2, datestr, datep);
-#else
-       XFillRectangle(dpy, win, w->dclock.backGC,
-           0, winheight - tsize, winwidth, tsize);
-       XDrawString(dpy, win, w->dclock.foreGC,
-               x, winheight - BORDER, datestr, datep);
 #endif
+       } else {
+           XFillRectangle(dpy, win, w->dclock.backGC,
+               0, winheight - tsize, winwidth, tsize);
+           XDrawString(dpy, win, w->dclock.foreGC,
+               x, winheight - BORDER, datestr, datep);
+       }
     }
 }
 
@@ -1992,13 +2014,13 @@ DclockWidget w;
     w->dclock.date_fmt = saved_date;
     saved_date = tmp;
 
-    if (w->dclock.dateup && w->dclock.date_fmt)
-#ifdef XFT_SUPPORT
-       TopOffset = w->core.height / 6;
-#else
-       TopOffset = w->dclock.font->ascent + w->dclock.font->descent;
-#endif
-    else
+    if (w->dclock.dateup && w->dclock.date_fmt) {
+       if (XFT_COND(w->dclock)) {
+           TopOffset = w->core.height / 6;
+       } else {
+           TopOffset = w->dclock.font->ascent + w->dclock.font->descent;
+       }
+    } else
        TopOffset = 0;
 
     before.tm_wday = -1;
@@ -2021,13 +2043,13 @@ DclockWidget w;
     XtSetArg(arg, XtNdateUp, !w->dclock.dateup);
     XtSetValues((Widget)w, &arg, 1);
 
-    if (w->dclock.dateup && w->dclock.date_fmt)
-#ifdef XFT_SUPPORT
-       TopOffset = w->core.height / 6;
-#else
-       TopOffset = w->dclock.font->ascent + w->dclock.font->descent;
-#endif
-    else
+    if (w->dclock.dateup && w->dclock.date_fmt) {
+       if (XFT_COND(w->dclock)) {
+           TopOffset = w->core.height / 6;
+       } else {
+           TopOffset = w->dclock.font->ascent + w->dclock.font->descent;
+       }
+    } else
        TopOffset = 0;
 
     ResizeNow(w);
@@ -2184,20 +2206,20 @@ XButtonEvent *event;
         */
        int i, x, y = (int)((BORDER/2)*y_ratio) + TopOffset;
        /* first check to see if user toggles the alarm */
-#ifdef XFT_SUPPORT
-       if (TopOffset)
+       if (XFT_COND(w->dclock)) {
+           if (TopOffset)
                i = (BORDER + (w->core.height / 6))
                        - event->y;
-       else
+           else
                i = event->y - (winheight - (w->core.height / 6));
-#else
-       if (TopOffset)
+       } else {
+           if (TopOffset)
                i = (BORDER + (w->dclock.font->ascent + 
w->dclock.font->descent))
                        - event->y;
-       else
+           else
                i = event->y - (winheight - (w->dclock.font->ascent
                        + w->dclock.font->descent));
-#endif
+       }
        if (i >= 0)
            toggle_alarm(w);
        else for (i = 0; i < 4; i++) {
diff --git a/DclockP.h b/DclockP.h
index bb2c29e..ded7802 100644
--- a/DclockP.h
+++ b/DclockP.h
@@ -9,8 +9,9 @@
 #include "Dclock.h"
 
 /* Add -DXFT_SUPPORT in the Imakefile for freefont support */
+#ifdef XFT_SUPPORT
 #include <X11/Xft/Xft.h>
-
+#endif
 
 typedef struct {
     Pixel                      foreground;
-- 
1.6.1.3

-- 
Robert Macomber
xby...@rojoma.com



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to