Example #1
0
File: font.c Project: raboof/notion
void debrush_do_draw_string_default_bmf(
        DEBrush *brush,
        int x, int y, const char *str,
        int len, bool needfill,
        DEColourGroup *colours)
{
    GC gc=brush->d->normal_gc;

    if(brush->d->font==NULL)
        return;

    XSetForeground(ioncore_g.dpy, gc, PIXEL(colours->fg));

    if(!needfill){
        if(brush->d->font->fontset!=NULL){
#ifdef CF_DE_USE_XUTF8
            if(ioncore_g.enc_utf8)
                Xutf8DrawString(ioncore_g.dpy, brush->win,
                                brush->d->font->fontset,
                                gc, x, y, str, len);
            else
#endif
                XmbDrawString(ioncore_g.dpy, brush->win,
                              brush->d->font->fontset,
                              gc, x, y, str, len);
        }else if(brush->d->font->fontstruct!=NULL){
            if(ioncore_g.enc_utf8){
                XChar2b *str16; int len16=0;
                toucs(str, len, &str16, &len16);
                XDrawString16(ioncore_g.dpy, brush->win, gc, x, y, str16, len16);
                free(str16);
            }else{
                XDrawString(ioncore_g.dpy, brush->win, gc, x, y, str, len);
            }
        }
    }else{
        XSetBackground(ioncore_g.dpy, gc, PIXEL(colours->bg));
        if(brush->d->font->fontset!=NULL){
#ifdef CF_DE_USE_XUTF8
            if(ioncore_g.enc_utf8)
                Xutf8DrawImageString(ioncore_g.dpy, brush->win,
                                     brush->d->font->fontset,
                                     gc, x, y, str, len);
            else
#endif
                XmbDrawImageString(ioncore_g.dpy, brush->win,
                                   brush->d->font->fontset,
                                   gc, x, y, str, len);
        }else if(brush->d->font->fontstruct!=NULL){
            if(ioncore_g.enc_utf8){
                XChar2b *str16; int len16=0;
                toucs(str, len, &str16, &len16);
                XDrawImageString16(ioncore_g.dpy, brush->win, gc, x, y, str16, len16);
                free(str16);
            }else{
                XDrawImageString(ioncore_g.dpy, brush->win, gc, x, y, str, len);
            }
        }
    }
}
Example #2
0
static void
fontset_draw (Lisp_Font *f, char *string, size_t length,
	      Window id, GC gc, Lisp_Color *fg, int x, int y)
{
    XGCValues gcv;

    gcv.foreground = fg->pixel;
    XChangeGC (dpy, gc, GCForeground, &gcv);
#ifdef X_HAVE_UTF8_STRING
    Xutf8DrawString (dpy, id, f->font, gc, x, y, string, length);
#else
    XmbDrawString (dpy, id, f->font, gc, x, y, string, length);
#endif
}
Example #3
0
int main_loop(Display *dpy, XFontSet font, GC pen, int width, int height,
		 char *text){
	int text_width;
	int textx, texty;
	XEvent ev;
	int font_ascent;
	XFontStruct **fonts;
	char **font_names;
	int nfonts;
	int j;

	printf("%s:%d\n", text, strlen(text));
	text_width = Xutf8TextEscapement(font, text, strlen(text));
	font_ascent = 0;
	nfonts = XFontsOfFontSet(font, &fonts, &font_names);
	for(j = 0; j < nfonts; j += 1){
		if (font_ascent < fonts[j]->ascent) font_ascent = fonts[j]->ascent;
		printf("Font: %s\n", font_names[j]);
	}


	/* as each event that we asked about occurs, we respond. */
	while(1){
		XNextEvent(dpy, &ev);
		switch(ev.type){
		case Expose:
			if (ev.xexpose.count > 0) break;
			XDrawLine(dpy, ev.xany.window, pen, 0, 0, width/2-text_width/2, height/2);
			XDrawLine(dpy, ev.xany.window, pen, width, 0, width/2+text_width/2, height/2);
			XDrawLine(dpy, ev.xany.window, pen, 0, height, width/2-text_width/2, height/2);
			XDrawLine(dpy, ev.xany.window, pen, width, height, width/2+text_width/2, height/2);
   			textx = (width - text_width)/2;
   			texty = (height + font_ascent)/2;
   			Xutf8DrawString(dpy, ev.xany.window, font, pen, textx, texty, text, strlen(text));
			break;
		case ConfigureNotify:
			if (width != ev.xconfigure.width
					|| height != ev.xconfigure.height) {
				width = ev.xconfigure.width;
				height = ev.xconfigure.height;
				XClearWindow(dpy, ev.xany.window);
			}
			break;
		case ButtonRelease:
			XCloseDisplay(dpy);
			return 0;
		}
	}
}
Example #4
0
void redraw_frame(client_t *c)
{
    int x, y;

    if (c && c->decor) {
        XClearWindow(dpy, c->frame);
        if (!c->shaded) XDrawLine(dpy, c->frame, border_gc,
            0, frame_height(c) - BW(c) + BW(c)/2,
            c->geom.w, frame_height(c) - BW(c) + BW(c)/2);
        XDrawLine(dpy, c->frame, border_gc,
            c->geom.w - frame_height(c) + BW(c)/2, 0,
            c->geom.w - frame_height(c) + BW(c)/2, frame_height(c));

        if (!c->trans && c->name) {
            x = opt_pad + DESCENT/2;
            y = opt_pad + ASCENT;
#ifdef XFT
#ifdef X_HAVE_UTF8_STRING
            XftDrawStringUtf8(c->xftdraw, &xft_fg, xftfont, x, y,
                (unsigned char *)c->name, strlen(c->name));
#else
            XftDrawString8(c->xftdraw, &xft_fg, xftfont, x, y,
                (unsigned char *)c->name, strlen(c->name));
#endif
#else
#ifdef X_HAVE_UTF8_STRING
            Xutf8DrawString(dpy, c->frame, font_set, string_gc, x, y,
                c->name, strlen(c->name));
#else
            XDrawString(dpy, c->frame, string_gc, x, y,
                c->name, strlen(c->name));
#endif
#endif
        }
    }
}
Example #5
0
int main(int argc, char**argv) {
    char **missing_charset_list;
    int missing_charset_count;
    XGCValues xgcv;
    unsigned long mask;
    Display* dpy;
    int scr;
    Window w, root;
    XSetWindowAttributes set_attr;
    int i;
    XIMStyle *style;
    static char buf[128];
    KeySym keysym = 0;
    Status status;
    XWMHints wm_hints;
    XClassHint class_hints;
    XIMStyle input_style = 0;
    char **font_name_list;
    char *def_string;
    XFontStruct **font_struct_list;
    char **font_encoding_list;
    int nb_font;
    int len = 0;
    int no_xim = 0;
    char **missing_charset_list_return;
    int missing_charset_count_return;
    char *def_string_return;

    if (!setlocale(LC_ALL, ""))
        puts("locale not supported by C library, locale unchanged");

    if (!XSetLocaleModifiers(""))
        puts("X locale modifiers not supported, using default");

    dpy = XOpenDisplay(0);
    scr = DefaultScreen(dpy);
    root = RootWindow(dpy, scr);
    set_attr.event_mask = KeyPressMask|FocusChangeMask;
    set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy));
    set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy));
    w = XCreateWindow(dpy, root, 10,10,200,100,0,
                      DefaultDepth(dpy, DefaultScreen(dpy)),
                      InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)),
                      CWEventMask | CWBackPixel | CWBorderPixel, &set_attr);

    class_hints.res_name = "test";
    class_hints.res_class = "Test";
    wm_hints.input = True;
    wm_hints.flags = InputHint;

    XmbSetWMProperties(dpy, w, "test", "test", NULL, 0,
                       NULL, &wm_hints, &class_hints);

    XMapWindow(dpy, w);
    xim_im = XOpenIM(dpy, NULL, "test", "Test");
    XGetIMValues(xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL);
    for (i = 0, style = xim_styles->supported_styles;
            i < xim_styles->count_styles; i++, style++) {
        if (*style == (XIMStatusNone|XIMPreeditNone)) {
            printf("this is not a XIM server !!!\n");
            no_xim = 1;
        }
        printf("input style : 0x%X\n", *style);
    }
    XFree(xim_styles);

    xim_ic = XCreateIC(xim_im,
                       XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
                       XNClientWindow, w,
                       XNFocusWindow, w,
                       NULL);
    XSetICFocus(xim_ic);

    /***************************************************************
     *  I don't recommend to use a font base name list similar
     *  to the following one in a real application ;-)
     ***************************************************************/
    fontset = XCreateFontSet(dpy,
                             "-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */
                             "-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8,"
                             "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-big5-0,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0,"
                             "-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500],"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-*-*",
                             &missing_charset_list_return,
                             &missing_charset_count_return,
                             &def_string_return);
    mask = (GCForeground | GCBackground);
    xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy));
    xgcv.background = WhitePixel(dpy, DefaultScreen(dpy));

    gc = XCreateGC(dpy, w, mask, &xgcv);

    /***************************************************************/
    while (1) {
        int filtered;
        static XEvent xevent;
        static XVaNestedList list1 = 0;
        int r;

        XNextEvent(dpy, &xevent);
        if (xevent.type == KeyPress) {
            XKeyEvent *e = (XKeyEvent*) &xevent;
            printf ("0x%X %d\n", e->state, e->keycode);
        }
        filtered = XFilterEvent(&xevent, w);
        if (xevent.type == FocusOut) XUnsetICFocus(xim_ic);
        if (xevent.type == FocusIn) XSetICFocus(xim_ic);

        if (xevent.type == KeyPress && !filtered) {
            len = Xutf8LookupString(xim_ic, &xevent.xkey, buf, 127, &keysym, &status);
            Xutf8DrawImageString(dpy, w, fontset, gc, x, y, buf, len);
            Xutf8DrawString(dpy, w, fontset, gc, 0, 20, jp_txt, strlen(jp_txt));
            Xutf8DrawString(dpy, w, fontset, gc, 50, 90, rtl_txt, strlen(rtl_txt));
            buf[len] = 0;
            printf("'%s' %d\n", buf, keysym);
            buf[0] = 0;
            XCloseIM(xim_im);
        }
        if (filtered) {
            printf("Dead key\n");
        }
    }
    XFreeFontSet(dpy, fontset);
    return 0;
}