68user's page 掲示板

Prev< No. 1814> Next  [最新発言に戻る] [過去ログ一覧]
No. 1814 # 68user 2001/03/12 (月) 22:35:33
>>1813 Yuuki
> これで解決しました。
> http://homepage1.nifty.com/tyuuki/tmp/drawstr.c
http://homepage1.nifty.com/tyuuki/tmp/drawstr2.c ですよね。
誠に勝手ながら、後から見た人のために drawstr2.c を貼っておきます。
行数短縮のため、少々コードスタイルをいじらせていただきました。
もしまずければ削除いたします。

----
#include <stdio.h>
#include <locale.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

static XFontSet load_font( Display *display, const char *font_names ){
        char **miss_str;
        int miss_cnt;
        char *def_str;
        return XCreateFontSet( display, font_names,
                                      &miss_str, &miss_cnt, &def_str );
}

static int ask_text_height( XFontSet font, const char *str ){
        XRectangle rect;
        XmbTextExtents( font, str, strlen( str ), &rect, NULL );
        return rect.height;
}

int main( int argc, char **argv ){
        Display *display;
        Window window;
        GC gc, gc_clr;
        unsigned long background, foreground;
        XFontSet font;
        Pixmap pixmap;
        const int width = 640;
        const int height = 480;
        const char *message = "こんにちは。";

        if ( setlocale( LC_CTYPE, "" ) == NULL ){
                printf( "setlocale error\n" );
                exit( 0 );
        }
        display = XOpenDisplay( NULL );
        font = load_font( display, "-misc-fixed-medium-r-normal--14-*-*-*-*-*-*-*,*" );
        background = WhitePixel( display, 0 );
        foreground = BlackPixel( display, 0 );

        window = XCreateSimpleWindow( display, DefaultRootWindow( display ),
                                            0, 0, width, height, 0, 0, background );
        pixmap = XCreatePixmap( display, window, width, height,
                                DefaultDepth( display, 0 ) );

        gc = XCreateGC( display, window, 0, 0 );
        XSetBackground( display, gc, background );
        XSetForeground( display, gc, foreground );

        gc_clr = XCreateGC( display, window, 0, 0 );
        XSetBackground( display, gc_clr, background );
        XSetForeground( display, gc_clr, background );

        XMapRaised( display, window );
        XSelectInput( display, window, ExposureMask );
        while ( 1 ){
                XEvent event;
                XNextEvent( display, &event );
                switch ( event.type ){
                case Expose :
                        XFillRectangle( display, pixmap, gc_clr, 0, 0, width, height );
                        XmbDrawString( display, pixmap, font, gc,
                                              0, ask_text_height( font, message ),
                                              message, strlen( message ) );
                        XCopyArea( display, pixmap, window, gc, 0, 0, width, height, 0, 0 );
                        break;
                }
        }
}

Prev< No. 1814> Next  [最新発言に戻る] [過去ログ一覧]