The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Newsgroups: comp.windows.x.intrinsics
From:
Yoshi Rokuko <yo.rheinw... @web.de>
Date: 15 Nov 2008 21:59:30 GMT
Local: Sat, Nov 15 2008 4:59 pm
Subject: xlib xft font color
hey! is there a good howto with examples on using xft antialiased and colored fonts in xlib with c?
i have http://keithp.com/~keithp/render/Xft.tutorial , but some examples would be nice too ...
the following gives me black font:
#include <X11/Xlib.h> #include <X11/Xft/Xft.h> [...]
struct { GC blue; GC gray;
} gc; /* grafical contexts */
XftFont *xftfont; XftDraw *draw; XftColor color; char *msg = "789,34 £ |@~½¾²³"; [...] xftfont = XftFontOpen(dpy, scr, XFT_FAMILY, XftTypeString, "dejavuserifcondensed", XFT_SIZE, XftTypeDouble, 98.0, NULL);
/* Set the color to black */ color.color.red = 0; color.color.green = 0; color.color.blue = 0; color.color.alpha = 0xffff; //USHRT_MAX;
draw = XftDrawCreate(dpy, win, DefaultVisual(dpy, scr), cmap);
but how do i get i.e. something like
XAllocNamedColor(dpy, cmap, "#4c7899", &blue, &blue)
for the xft fonts?
thank you in advance y0shi
-- psyc://nemesis.psyc.biz/~y0shi http://psyc.biz/y0shi_public.ke
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.windows.x.intrinsics, comp.windows.x
From:
arahne <ara... @arahne.si>
Date: Mon, 24 Nov 2008 09:29:02 +0100
Local: Mon, Nov 24 2008 3:29 am
Subject: Re: xlib xft font color
Yoshi Rokuko wrote:
> hey!
> is there a good howto with examples on using xft antialiased and colored > fonts in xlib with c?
That should be easy.
> /* Set the color to black */ > color.color.red = 0; > color.color.green = 0; > color.color.blue = 0;
Here you should put in your r,g b, value of the desired color.
> but how do i get i.e. something like
> XAllocNamedColor(dpy, cmap, "#4c7899", &blue, &blue)
> for the xft fonts?
You do not need to use XColor for XFT, just set the correct RGB while creating XftColor. The color #4c7899 is already hex of red 0x4c, green 0x78, blue 0x99. You can find the complete list here: http://en.wikipedia.org/wiki/X11_color_names If you wish to use color name "Blue" in color specification, you can still XAllocNamedColor(), get the RGB values, and use this to initialize the XftColor.
Hope this helps,
Dušan Peterc http://www.arahne.si
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.windows.x.intrinsics
From:
Yoshi Rokuko <yo.rheinw... @web.de>
Date: 2 Dec 2008 22:31:44 GMT
Local: Tues, Dec 2 2008 5:31 pm
Subject: Re: xlib xft font color
arahne <ara... @arahne.si> schrieb:
> Yoshi Rokuko wrote:
>> is there a good howto with examples on using xft antialiased and colored
>> fonts in xlib with c?
> That should be easy.
>> /* Set the color to black */ >> color.color.red = 0; >> color.color.green = 0; >> color.color.blue = 0; > Here you should put in your r,g b, value of the desired color.
hm, I still don't get what I want do you no what else is wrong? I will post the complete sample code: #include <X11/Xlib.h> #include <X11/Xft/Xft.h> #include <stdio.h> #include <stdlib.h> #include <string.h>
int main(void) { Display *dpy; Window win; Colormap cmap; XEvent e; XftFont *xfthuge; XftColor color; XftDraw *draw; char *msg = "Hello, World!"; int scr;
/* open connection with the server */ dpy = XOpenDisplay(NULL); if (dpy == NULL) { fprintf(stderr, "Cannot open display\n"); exit(1); }
scr = DefaultScreen(dpy); cmap = DefaultColormap(dpy, scr);
/* create window */ win = XCreateSimpleWindow(dpy, RootWindow(dpy, scr), 100, 100, 700, 300, 1, BlackPixel(dpy, scr), WhitePixel(dpy, scr));
/* select kind of events we are interested in */ XSelectInput(dpy, win, ExposureMask | KeyPressMask);
/* map (show) the window */ XMapWindow(dpy, win);
xfthuge = XftFontOpen(dpy, scr, XFT_FAMILY, XftTypeString, "dejavuserifcondensed", XFT_SIZE, XftTypeDouble, 100.0, NULL);
color.color.red = 0x4c; color.color.green = 0x78; color.color.blue = 0x99; color.color.alpha = 0x8080; // I tried 0x8080 and I get gray if I try // 0xffff I get black, but somehow no // color ...
draw = XftDrawCreate(dpy, win, DefaultVisual(dpy, scr), cmap);
/* event loop */ while (1) { XNextEvent(dpy, &e);
/* draw or redraw the window */ if (e.type == Expose) { XftDrawStringUtf8(draw, &color, xfthuge, 10, 100, (FcChar8*)msg, strlen(msg)); /* XFillRectangle(dpy, win, DefaultGC(dpy, scr), 20, * 20, 10, 10); XDrawString(dpy, win, DefaultGC(dpy, scr), 50, 50, msg, strlen(msg)); */ } /* exit on key press */ if (e.type == KeyPress) break; }
XftDrawDestroy(draw);
/* close connection to server */ XCloseDisplay(dpy);
return 0;
}
I made a screenshot - http://psyc.biz/hello_world.png ;-) Many thanks so far!
Regards, y0shi
-- psyc://nemesis.psyc.biz/~y0shi http://psyc.biz/y0shi_public.ke
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.windows.x.intrinsics
From:
Yoshi Rokuko <yo.rheinw... @web.de>
Date: 3 Dec 2008 17:18:08 GMT
Local: Wed, Dec 3 2008 12:18 pm
Subject: Re: xlib xft font color
Yoshi Rokuko <yo.rheinw... @web.de> schrieb:
> arahne <ara
... @arahne.si> schrieb:
>> Yoshi Rokuko wrote:
>>> is there a good howto with examples on using xft antialiased and colored
>>> fonts in xlib with c?
>> That should be easy.
>>> /* Set the color to black */ >>> color.color.red = 0; >>> color.color.green = 0; >>> color.color.blue = 0; >> Here you should put in your r,g b, value of the desired color.
> hm, I still don't get what I want do you know what else is wrong?
allright now I found my mistake ... ... I need to allocate the color. here comes a working sample code:
#include <X11/Xlib.h> #include <X11/Xft/Xft.h> #include <stdio.h> #include <stdlib.h> #include <string.h>
int main(void) { Display *dpy; Window win; Colormap cmap; XEvent e; XftFont *xfthuge; XftColor color; XftDraw *draw; XRenderColor kindofblue = { 0x4c00, 0x7800, 0x9900, 0xffff}; char *msg = "Hello, World!"; int scr;
/* open connection with the server */ dpy = XOpenDisplay(NULL); if (dpy == NULL) { fprintf(stderr, "Cannot open display\n"); exit(1); }
scr = DefaultScreen(dpy); cmap = DefaultColormap(dpy, scr);
/* create window */ win = XCreateSimpleWindow(dpy, RootWindow(dpy, scr), 100, 100, 700, 300, 1, BlackPixel(dpy, scr), WhitePixel(dpy, scr));
/* select kind of events we are interested in */ XSelectInput(dpy, win, ExposureMask | KeyPressMask);
/* map (show) the window */ XMapWindow(dpy, win);
xfthuge = XftFontOpen(dpy, scr, XFT_FAMILY, XftTypeString, "dejavuserifcondensed", XFT_SIZE, XftTypeDouble, 100.0, NULL);
XftColorAllocValue(dpy, DefaultVisual(dpy, scr), cmap, &kindofblue, &color);
draw = XftDrawCreate(dpy, win, DefaultVisual(dpy, scr), cmap);
/* event loop */ while (1) { XNextEvent(dpy, &e);
/* draw or redraw the window */ if (e.type == Expose) XftDrawStringUtf8(draw, &color, xfthuge, 10, 100, (FcChar8*)msg, strlen(msg));
/* exit on key press */ if (e.type == KeyPress) break; }
XftDrawDestroy(draw);
/* close connection to server */ XCloseDisplay(dpy);
return 0;
}
thanks, have fun - y0shi -- psyc://nemesis.psyc.biz/~y0shi http://psyc.biz/y0shi_public.ke
You must
Sign in before you can post messages.
You do not have the permission required to post.