Xutf8DrawString, setlocale, and XFontSet - Xwindows

This is a discussion on Xutf8DrawString, setlocale, and XFontSet - Xwindows ; This is beginning to bug me. I have a small C program which basically does the following: Display * dpy; int scr; Window root; Window win; GC gc; XFontSet fs; void redraw() { int x = 10; int y = ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Xutf8DrawString, setlocale, and XFontSet

  1. Xutf8DrawString, setlocale, and XFontSet

    This is beginning to bug me. I have a small C program which basically
    does the following:

    Display * dpy;
    int scr;
    Window root;
    Window win;
    GC gc;
    XFontSet fs;

    void redraw()
    {
    int x = 10;
    int y = 20;
    Xutf8DrawString(dpy, win, fs, gc, x, y, "\xcf\x80 = 3.14159", 12);
    }

    int main()
    {

    dpy = XOpenDisplay(NULL);
    scr = DefaultScreen(dpy);
    root = DefaultRootWindow(dpy, scr);

    ....

    win = XCreateSimpleWindow(...);

    ....

    gc = XCreateGC(dpy, root, 0, 0);

    ....

    setlocale(LC_ALL, "");

    ....

    fs = XLoadFontSet(dpy, "-*-times-Medium-R-Normal--*-120-100-100-P-0-*-*", ...);

    ....

    while(1)
    {
    XEvent ev;
    XNextEvent(dpy, &ev);

    switch(ev.type)
    {
    case Expose:
    redraw();
    }
    }

    ....

    }

    All right and proper (except for ICCCM niceties such
    as window title and size hints, which presumably are
    irrelevant) as far as I can tell. Yet the display of
    what should be "pi = 3.14159" is either entirely blank --
    probably because the default locale (C) aborts the draw
    if it sees a character it doesn't understand -- or gets
    garbled (I get "&P") if I try locales such as

    LC_ALL=en_US.utf-8 ./program

    This despite the fact that U+03C0 (pi) is encoded in
    UTF-8 as hex CF 80; the Character Map utility in Gnome
    readily verifies this.

    What the heck am I missing??

    Also, should i use iso10646-1 as the tail set of my font, or what?
    I've tried various combinations without much success. Obviously it
    works for Pango; I'm wondering why it doesn't work for basic X. :-)

    Thanks in advance.

    (Side note: Xutf8DrawString is a GNU extension, but lots of Linux X
    servers should have it. However, I've tried other variants and
    converting characters "manually" into XwcDrawString(). Nothing's
    worked for me correctly thus far.)

    --
    #191, ewill3@earthlink.net
    Windows Vista. Because it's time to refresh your hardware. Trust us.

  2. Re: Xutf8DrawString, setlocale, and XFontSet

    The Ghost In The Machine wrote:
    > This is beginning to bug me. I have a small C program which basically
    > does the following:
    >
    > Display * dpy;
    > int scr;
    > Window root;
    > Window win;
    > GC gc;
    > XFontSet fs;
    >
    > void redraw()
    > {
    > int x = 10;
    > int y = 20;
    > Xutf8DrawString(dpy, win, fs, gc, x, y, "\xcf\x80 = 3.14159", 12);
    > }
    >
    > int main()
    > {
    >
    > dpy = XOpenDisplay(NULL);
    > scr = DefaultScreen(dpy);
    > root = DefaultRootWindow(dpy, scr);
    >
    > ...
    >
    > win = XCreateSimpleWindow(...);
    >
    > ...
    >
    > gc = XCreateGC(dpy, root, 0, 0);
    >
    > ...
    >
    > setlocale(LC_ALL, "");
    >
    > ...
    >
    > fs = XLoadFontSet(dpy, "-*-times-Medium-R-Normal--*-120-100-100-P-0-*-*", ...);


    There's no such function. There's XCreateFontSet() which has more parameters and
    returns more diagnostic information.

    > ...
    >
    > while(1)
    > {
    > XEvent ev;
    > XNextEvent(dpy, &ev);
    >
    > switch(ev.type)
    > {
    > case Expose:
    > redraw();
    > }
    > }
    >
    > ...
    >
    > }
    >
    > All right and proper (except for ICCCM niceties such
    > as window title and size hints, which presumably are
    > irrelevant) as far as I can tell. Yet the display of
    > what should be "pi = 3.14159" is either entirely blank --
    > probably because the default locale (C) aborts the draw
    > if it sees a character it doesn't understand -- or gets
    > garbled (I get "&P") if I try locales such as
    >
    > LC_ALL=en_US.utf-8 ./program
    >
    > This despite the fact that U+03C0 (pi) is encoded in
    > UTF-8 as hex CF 80; the Character Map utility in Gnome
    > readily verifies this.
    >
    > What the heck am I missing??
    >
    > Also, should i use iso10646-1 as the tail set of my font, or what?
    > I've tried various combinations without much success. Obviously it
    > works for Pango; I'm wondering why it doesn't work for basic X. :-)
    >
    > Thanks in advance.
    >
    > (Side note: Xutf8DrawString is a GNU extension, but lots of Linux X
    > servers should have it. However, I've tried other variants and
    > converting characters "manually" into XwcDrawString(). Nothing's
    > worked for me correctly thus far.)
    >


  3. Re: Xutf8DrawString, setlocale, and XFontSet

    In comp.windows.x, Russell Shaw

    wrote
    on Fri, 01 Sep 2006 15:00:43 +1000
    :
    > The Ghost In The Machine wrote:
    >> This is beginning to bug me. I have a small C program which basically
    >> does the following:
    >>
    >> Display * dpy;
    >> int scr;
    >> Window root;
    >> Window win;
    >> GC gc;
    >> XFontSet fs;
    >>
    >> void redraw()
    >> {
    >> int x = 10;
    >> int y = 20;
    >> Xutf8DrawString(dpy, win, fs, gc, x, y, "\xcf\x80 = 3.14159", 12);
    >> }
    >>
    >> int main()
    >> {
    >>
    >> dpy = XOpenDisplay(NULL);
    >> scr = DefaultScreen(dpy);
    >> root = DefaultRootWindow(dpy, scr);
    >>
    >> ...
    >>
    >> win = XCreateSimpleWindow(...);
    >>
    >> ...
    >>
    >> gc = XCreateGC(dpy, root, 0, 0);
    >>
    >> ...
    >>
    >> setlocale(LC_ALL, "");
    >>
    >> ...
    >>
    >> fs = XLoadFontSet(dpy, "-*-times-Medium-R-Normal--*-120-100-100-P-0-*-*", ...);

    >
    > There's no such function. There's XCreateFontSet() which has more parameters and
    > returns more diagnostic information.


    Oops, sorry. You're correct, and there's 5 parameters. I can load the
    fontset and it works for ASCII and ISO-8859-1, but when I go beyond that
    the characters get peculiar.

    I'll admit I could try a comma-delimited list as suggested by the
    manpage but what fonts would I need?

    >
    >> ...
    >>
    >> while(1)
    >> {
    >> XEvent ev;
    >> XNextEvent(dpy, &ev);
    >>
    >> switch(ev.type)
    >> {
    >> case Expose:
    >> redraw();
    >> }
    >> }
    >>
    >> ...
    >>
    >> }
    >>
    >> All right and proper (except for ICCCM niceties such
    >> as window title and size hints, which presumably are
    >> irrelevant) as far as I can tell. Yet the display of
    >> what should be "pi = 3.14159" is either entirely blank --
    >> probably because the default locale (C) aborts the draw
    >> if it sees a character it doesn't understand -- or gets
    >> garbled (I get "&P") if I try locales such as
    >>
    >> LC_ALL=en_US.utf-8 ./program
    >>
    >> This despite the fact that U+03C0 (pi) is encoded in
    >> UTF-8 as hex CF 80; the Character Map utility in Gnome
    >> readily verifies this.
    >>
    >> What the heck am I missing??
    >>
    >> Also, should i use iso10646-1 as the tail set of my font, or what?
    >> I've tried various combinations without much success. Obviously it
    >> works for Pango; I'm wondering why it doesn't work for basic X. :-)
    >>
    >> Thanks in advance.
    >>
    >> (Side note: Xutf8DrawString is a GNU extension, but lots of Linux X
    >> servers should have it. However, I've tried other variants and
    >> converting characters "manually" into XwcDrawString(). Nothing's
    >> worked for me correctly thus far.)
    >>



    --
    #191, ewill3@earthlink.net
    Windows Vista. Because it's time to refresh your hardware. Trust us.

  4. Re: Xutf8DrawString, setlocale, and XFontSet

    The Ghost In The Machine wrote:
    > In comp.windows.x, Russell Shaw
    >
    > wrote
    > on Fri, 01 Sep 2006 15:00:43 +1000
    > :
    >
    >>The Ghost In The Machine wrote:
    >>
    >>>This is beginning to bug me. I have a small C program which basically
    >>>does the following:
    >>>
    >>>...
    >>>
    >>>fs = XLoadFontSet(dpy, "-*-times-Medium-R-Normal--*-120-100-100-P-0-*-*", ...);

    >>
    >>There's no such function. There's XCreateFontSet() which has more parameters and
    >>returns more diagnostic information.

    >
    > Oops, sorry. You're correct, and there's 5 parameters. I can load the
    > fontset and it works for ASCII and ISO-8859-1, but when I go beyond that
    > the characters get peculiar.
    >
    > I'll admit I could try a comma-delimited list as suggested by the
    > manpage but what fonts would I need?


    I don't have much experience with rendering unicode characters outside of the
    utf-8 values below 256, but i think you just need to load a font that has
    iso-10646 encoding, *and* contains suitable glyphs for the characters that
    the font renderer will be fed from Xutf8DrawString().

  5. Re: Xutf8DrawString, setlocale, and XFontSet

    In comp.windows.x, Russell Shaw

    wrote
    on Sat, 02 Sep 2006 13:06:29 +1000
    :
    > The Ghost In The Machine wrote:
    >> In comp.windows.x, Russell Shaw
    >>
    >> wrote
    >> on Fri, 01 Sep 2006 15:00:43 +1000
    >> :
    >>
    >>>The Ghost In The Machine wrote:
    >>>
    >>>>This is beginning to bug me. I have a small C program which basically
    >>>>does the following:
    >>>>
    >>>>...
    >>>>
    >>>>fs = XLoadFontSet(dpy, "-*-times-Medium-R-Normal--*-120-100-100-P-0-*-*", ...);
    >>>
    >>>There's no such function. There's XCreateFontSet() which has more parameters and
    >>>returns more diagnostic information.

    >>
    >> Oops, sorry. You're correct, and there's 5 parameters. I can load the
    >> fontset and it works for ASCII and ISO-8859-1, but when I go beyond that
    >> the characters get peculiar.
    >>
    >> I'll admit I could try a comma-delimited list as suggested by the
    >> manpage but what fonts would I need?

    >
    > I don't have much experience with rendering unicode characters outside of the
    > utf-8 values below 256, but i think you just need to load a font that has
    > iso-10646 encoding, *and* contains suitable glyphs for the characters that
    > the font renderer will be fed from Xutf8DrawString().


    Well, there's a fair number of issues. Fortunately, I
    think I have found such a font: 'dejavu sans'. I think
    that will take care of most of my raw X issues, if I
    want to go that route. (SLRN is a good newsreader but
    does not handle non-ASCII all that well.)

    For a more realistic solution there's a software package
    named Cairo that is built into the GTK toolkit -- and from
    the looks of things it's smart enough to get things right
    for everything but Times (for some reason). It also
    can generate PNG, SVG, PS, PDF, and directly to
    framebuffer.

    --
    #191, ewill3@earthlink.net
    Windows Vista. Because it's time to refresh your hardware. Trust us.

  6. Re: Xutf8DrawString, setlocale, and XFontSet

    The Ghost In The Machine wrote:
    > (Side note: Xutf8DrawString is a GNU extension, but lots of Linux X


    not GNU, but XFree86.

    --
    Thomas E. Dickey
    http://invisible-island.net
    ftp://invisible-island.net

  7. Re: Xutf8DrawString, setlocale, and XFontSet

    In comp.windows.x, Thomas Dickey

    wrote
    on Tue, 05 Sep 2006 12:19:27 -0000
    <12fqqqf4ckp0o7b@corp.supernews.com>:
    > The Ghost In The Machine wrote:
    >> (Side note: Xutf8DrawString is a GNU extension, but lots of Linux X

    >
    > not GNU, but XFree86.
    >


    I stand corrected. :-) 4.0.2 release.

    --
    #191, ewill3@earthlink.net
    Windows Vista. Because it's time to refresh your hardware. Trust us.

+ Reply to Thread