void main (void)
{
    Display *dsp = XOpenDisplay (0);
    if (dsp)
    {
        int scr = DefaultScreen (dsp);

        Window p = XCreateSimpleWindow (dsp, RootWindow (dsp, scr), 100, 100, 300, 100, 1,
                                             BlackPixel (dsp, scr), WhitePixel (dsp, scr));
        XSelectInput (dsp, p, ExposureMask);
        XMapWindow (dsp, p);

        XftColor xft_color;
        XftColorAllocName (dsp, DefaultVisual (dsp, scr), DefaultColormap (dsp, scr), "tan", &xft_color);

        XftFont *font = XftFontOpenName (dsp, scr, "sans:bold:pixelsize=18");
        XftDraw *draw = XftDrawCreate (dsp, p, DefaultVisual (dsp, scr), DefaultColormap (dsp, scr));

        for (;;)
        {
            char *txt = "Lorem ipsum";
            XEvent e;
            XNextEvent (dsp, &e);
            if (e.type == Expose)
                XftDrawString8 (draw, &xft_color, font, 20, 30, (XftChar8*)(txt), strlen(txt));
        }
    }
}
Esempio n. 2
0
void
xwindow_draw_string_xft(XWindow *xw, char *text, int x, int y) {
  int n;
  XftDraw *draw;
  XftColor color;
  XRenderColor rc;
  XftFont *font;
  XGlyphInfo extents;
  float shift[] = { 0.0, 0.0, -0.5, -1.0 };
  
  n = strlen(text);

  font = xw->font->font_xft;
  if(!font) {
    return;
  }
  draw = XftDrawCreate(DISPLAY(xw),
                       xw->buffer,
                       VISUAL(xw),
                       DefaultColormap(DISPLAY(xw), SCREEN(xw)));

  /* Set Text from current Color */
  rc.red   = xw->color->red;
  rc.green = xw->color->green;
  rc.blue  = xw->color->blue;
  rc.alpha = 0xFFFF; /* 65535 */
  XftColorAllocValue(DISPLAY(xw),
                     VISUAL(xw),
                     DefaultColormap(DISPLAY(xw), SCREEN(xw)),
                     &rc,
                     &color);
  
  XftTextExtents8(DISPLAY(xw), font, (FcChar8*)text, n, &extents);

  if(cmgdm.tangle != 0.0) {
    XftMatrix m;
    m.xx =  0.0;
    m.xy = -1.0;
    m.yx =  1.0;
    m.yy =  0.0;

    y = y - shift[cmgdm.ihjust] * extents.xOff;
    x = x - shift[cmgdm.ivjust] * (font->ascent + font->descent);
    
    font = XftFontOpen(DISPLAY(xw),
                       SCREEN(xw),
                       XFT_FAMILY,    XftTypeString,  xw->font->family,
                       XFT_SIZE,      XftTypeDouble,  xw->font->size,
                       XFT_STYLE,     XftTypeString,  xfont_style(xw->font),
                       XFT_ANTIALIAS, XftTypeBool,    xw->font->antialias,
                       XFT_MATRIX, XftTypeMatrix, &m,
                       NULL);

    
  } else {
    x = x + shift[cmgdm.ihjust] * extents.xOff;
    y = y - shift[cmgdm.ivjust] * (font->ascent + font->descent);
  }
  XftDrawString8(draw, &color, font, x, y, (FcChar8 *)text, n);
}
void
JXGC::DrawString
	(
	Drawable			drawable,
	XftDraw*			fdrawable,
	const JCoordinate	origX,
	const JCoordinate	y,
	const JCharacter*	str
	)
	const
{
	JXFontManager::XFont xfont = (itsDisplay->GetXFontManager())->GetXFontInfo(itsLastFont);

	XftColor color;
	if (xfont.type == JXFontManager::kTrueType)
		{
		JSize red, green, blue;
		itsColormap->GetRGB(itsLastColor, &red, &green, &blue);

		XRenderColor renderColor;
		renderColor.red   = red;
		renderColor.green = green;
		renderColor.blue  = blue;
		renderColor.alpha = 65535;

		XftColorAllocValue(*itsDisplay, itsDisplay->GetDefaultVisual(),
						   itsColormap->GetXColormap(), &renderColor, &color);
		}

	const JFontManager* fontMgr = itsDisplay->GetFontManager();

	const JSize length          = strlen(str);
	const JSize maxStringLength = itsDisplay->GetMaxStringLength();

	JCoordinate x = origX;
	JSize offset  = 0;
	while (offset < length)
		{
		const JSize count = JMin(length - offset, maxStringLength);

		if (xfont.type == JXFontManager::kStdType)
			{
			XDrawString(*itsDisplay, drawable, itsXGC, x,y, str + offset, count);
			}
		else
			{
			assert( xfont.type == JXFontManager::kTrueType );
			XftDrawString8(fdrawable, &color, xfont.xftrue, x,y, (FcChar8*) (str + offset), count);
			}

		if (offset + count < length)
			{
			x += fontMgr->GetStringWidth(itsLastFont, 0, JFontStyle(),
										 str + offset, count);
			}
		offset += count;
		}
}
Esempio n. 4
0
void
tooltip_handle(Tooltip *tt, XEvent *ev)
{
	if(! tt->text)
		return;
	
	if(ev->type == Expose && ev->xexpose.count == 0)
	{
		XftDrawRect(tt->draw, &tt->border, 0, 0, tt->width, 1);
		XftDrawRect(tt->draw, &tt->border, 0, 1, 1, tt->height - 2);
		XftDrawRect(tt->draw, &tt->border, 0, tt->height - 1, tt->width, 1);
		XftDrawRect(tt->draw, &tt->border, tt->width - 1, 1, 1, tt->height - 2);
		XftDrawRect(tt->draw, &tt->background, 1, 1, tt->width - 2, tt->height - 2);
		if(tt->shadow.pixel)
			XftDrawString8(tt->draw, &tt->shadow, tt->font, 6, 3 + tt->extents.y + (tt->font_height - tt->extents.y) / 2, tt->text, tt->text_len);
		XftDrawString8(tt->draw, &tt->color, tt->font, 4, 1 + tt->extents.y + (tt->font_height - tt->extents.y) / 2, tt->text, tt->text_len);
	}
}
Esempio n. 5
0
/* draw text in a given color at a given (x,y) */
int
render_text(XftColor *c, int x, int y, const char *str)
{
   XGlyphInfo extents;
   XftTextExtents8( XINFO.disp, XINFO.font, (XftChar8 *)str, strlen(str), &extents );

   XftDrawString8(XINFO.xftdraw, c, XINFO.font, x, y, (XftChar8 *)str, strlen(str));
   return extents.width;
}
Esempio n. 6
0
File: text.c Progetto: mame98/neoui
void neo_draw_pen_draw_text(NeoDrawHandle *handle, NeoDrawPen *pen,NeoDrawWindow *win, int x, int y, char *text)
{
  if(!handle || !pen || !win)
    return;

  int len = strlen(text);

  XGlyphInfo inf;
  XftTextExtents8(handle->display, pen->xft_font, (XftChar8 *) text, len, &inf);

  int height = inf.y;
  int width = inf.x;

  XftDrawString8(pen->xft_draw, &pen->xft_color, pen->xft_font, x + width, y +height, (XftChar8 *)text, len);
}
Esempio n. 7
0
void draw_menuitem(unsigned int index, unsigned int active)
{
	if (active)
	{
		XFillRectangle(dsply, taskbar, selected_gc, menuitems[index].x, 0, menuitems[index].width, BARHEIGHT() - DEF_BORDERWIDTH);
	}
	else
	{
		XFillRectangle(dsply, taskbar, menu_gc, menuitems[index].x, 0, menuitems[index].width, BARHEIGHT() - DEF_BORDERWIDTH);
	}
#ifdef XFT
	XftDrawString8(tbxftdraw, &xft_detail, xftfont, menuitems[index].x + (SPACE * 2), xftfont->ascent + SPACE, (unsigned char *)menuitems[index].label, strlen(menuitems[index].label));
#else
	XDrawString(dsply, taskbar, text_gc, menuitems[index].x + (SPACE * 2), font->ascent + SPACE, menuitems[index].label, strlen(menuitems[index].label));
#endif
}
Esempio n. 8
0
void
draw_text(char **message, XftColor *color)
{
	int	 	len;
	int             i, x, y;
	XGlyphInfo	extents;

	i = 0;
	y = height / 3;
	while (message[i] != NULL) {
		len = strlen(message[i]);
		XftTextExtents8(display, font, message[i], len, &extents);
		x = (width - extents.width)/2;
		XftDrawString8(draw, color, font, x, y, message[i], len);
		y += extents.height * 1.5;
		i++;
	}
}
Esempio n. 9
0
void draw_menubar(void)
{
	unsigned int i, dw;
	dw = DisplayWidth(dsply, screen);
	XFillRectangle(dsply, taskbar, menu_gc, 0, 0, dw, BARHEIGHT() - DEF_BORDERWIDTH);

	for (i = 0; i < num_menuitems; i++)
	{
		if (menuitems[i].label && menuitems[i].command)
		{
#ifdef XFT
			XftDrawString8(tbxftdraw, &xft_detail, xftfont, menuitems[i].x + (SPACE * 2), xftfont->ascent + SPACE, (unsigned char *)menuitems[i].label, strlen(menuitems[i].label));
#else
			XDrawString(dsply, taskbar, text_gc, menuitems[i].x + (SPACE * 2), font->ascent + SPACE, menuitems[i].label, strlen(menuitems[i].label));
#endif
		}
	}
}
Esempio n. 10
0
void redraw_taskbar(void)
{
	unsigned int i;
	int button_startx, button_iwidth;
	float button_width;
	Client *c;

	button_width = get_button_width();
	XClearWindow(dsply, taskbar);

	if (showing_taskbar == 0)
	{
		return;
	}

	for (c = head_client, i = 0; c != NULL; c = c->next, i++)
	{
		button_startx = (int)(i * button_width);
		button_iwidth = (unsigned int)(((i + 1) * button_width) - button_startx);
		if (button_startx != 0)
		{
			XDrawLine(dsply, taskbar, border_gc, button_startx - 1, 0, button_startx - 1, BARHEIGHT() - DEF_BORDERWIDTH);
		}
		if (c == focused_client)
		{
			XFillRectangle(dsply, taskbar, active_gc, button_startx, 0, button_iwidth, BARHEIGHT() - DEF_BORDERWIDTH);
		}
		else
		{
			XFillRectangle(dsply, taskbar, inactive_gc, button_startx, 0, button_iwidth, BARHEIGHT() - DEF_BORDERWIDTH);
		}
		if (!c->trans && c->name != NULL)
		{
#ifdef XFT
			XftDrawString8(tbxftdraw, &xft_detail, xftfont, button_startx + SPACE, SPACE + xftfont->ascent, (unsigned char *)c->name, strlen(c->name));
#else
			XDrawString(dsply, taskbar, text_gc, button_startx + SPACE, SPACE + font->ascent, c->name, strlen(c->name));
#endif
		}
	}
}
Esempio n. 11
0
void
pager_draw_button (int x, int num)
{
	char label;
#ifdef XFT
	XftColor col;
#endif

	if (num == tb.my_desktop)
	{
		/* current desktop */
		draw_box (x, PAGER_BUTTON_WIDTH);
	} else
	{
		set_foreground (5);
		fill_rect (x, 1, PAGER_BUTTON_WIDTH+1, WINHEIGHT - 2);
	}

	label = '1' + num;

#ifdef XFT
	col.color.alpha = 0xffff;
	col.color.red = cols[5].red;
	col.color.green = cols[5].green;
	col.color.blue = cols[5].blue;
	XftDrawString8 (xftdraw, &col, xfs, x + ((PAGER_BUTTON_WIDTH - PAGER_DIGIT_WIDTH) / 2), text_y, &label, 1);
#else
    if (num == tb.my_desktop)
    {
        set_foreground (6);
    }
    else
    {
        set_foreground (4);
    }
	XDrawString (dd, tb.win, fore_gc,
	x + ((PAGER_BUTTON_WIDTH - PAGER_DIGIT_WIDTH) / 2) - 1, text_y, &label, 1);
#endif
}
Esempio n. 12
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
        }
    }
}
Esempio n. 13
0
File: font.c Progetto: raboof/notion
static void debrush_do_draw_string_default_xft(
        DEBrush *brush,
        int x, int y, const char *str,
        int len, bool needfill,
        DEColourGroup *colours)
{
    Window win = brush->win;
    GC gc=brush->d->normal_gc;
    XftDraw *draw;
    XftFont *font;

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

    font=brush->d->font->font;
    draw=debrush_get_draw(brush, win);

    if(needfill){
        XGlyphInfo extents;
        if(ioncore_g.enc_utf8){
            XftTextExtentsUtf8(ioncore_g.dpy, font, (XftChar8*)str, len,
                               &extents);
        }else{
            XftTextExtents8(ioncore_g.dpy, font, (XftChar8*)str, len, &extents);
        }
        XftDrawRect(draw, &(colours->bg), x-extents.x, y-extents.y,
                    extents.width+10, extents.height);
    }

    if(ioncore_g.enc_utf8){
        XftDrawStringUtf8(draw, &(colours->fg), font, x, y, (XftChar8*)str,
                          len);
    }else{
        XftDrawString8(draw, &(colours->fg), font, x, y, (XftChar8*)str, len);
    }
}
Esempio n. 14
0
void
rp_draw_string (rp_screen *s, Drawable d, int style, int x, int y, char *string, int length)
{
  if (length < 0)
    length = strlen (string);

#ifdef USE_XFT_FONT
  if (s->xft_font)
    {
      XftDraw *draw;
      draw = XftDrawCreate (dpy, d, DefaultVisual (dpy, s->screen_num),
                            DefaultColormap (dpy, s->screen_num));
      if (draw)
        {
          XftDrawString8 (draw, style == STYLE_NORMAL ? &s->xft_fg_color:&s->xft_bg_color, s->xft_font, x, y, (FcChar8*) string, length);
          XftDrawDestroy (draw);
        }
      else
        PRINT_ERROR(("Failed to allocate XftDraw object\n"));
    }
  else
#endif
    XmbDrawString (dpy, d, defaults.font, style == STYLE_NORMAL ? s->normal_gc:s->inverse_gc, x, y, string, length);
}
Esempio n. 15
0
void textbox_draw(textbox *tb)
{
	int i;
	XGlyphInfo extents;

	GC context    = XCreateGC(display, tb->window, 0, 0);
	Pixmap canvas = XCreatePixmap(display, tb->window, tb->w, tb->h, DefaultDepth(display, DefaultScreen(display)));
	XftDraw *draw = XftDrawCreate(display, canvas, DefaultVisual(display, DefaultScreen(display)), DefaultColormap(display, DefaultScreen(display)));

	// clear canvas
	XftDrawRect(draw, &tb->color_bg, 0, 0, tb->w, tb->h);

	char *line   = tb->text,
		*text   = tb->text ? tb->text: "",
		*prompt = tb->prompt ? tb->prompt: "";

	int text_len    = strlen(text);
	int length      = text_len;
	int line_height = tb->font->ascent + tb->font->descent;
	int line_width  = 0;

	int cursor_x      = 0;
	int cursor_offset = 0;
	int cursor_width  = MAX(2, line_height/10);

	if (tb->flags & TB_EDITABLE)
	{
		int prompt_len = strlen(prompt);
		length = text_len + prompt_len;
		cursor_offset = MIN(tb->cursor + prompt_len, length);

		line = alloca(length + 10);
		sprintf(line, "%s%s", prompt, text);

		// replace spaces so XftTextExtents8 includes their width
		for (i = 0; i < length; i++) if (isspace(line[i])) line[i] = '_';

		// calc cursor position
		XftTextExtents8(display, tb->font, (unsigned char*)line, cursor_offset, &extents);
		cursor_x = extents.width;

		// restore correct text string with spaces
		sprintf(line, "%s%s", prompt, text);
	}

	// calc full input text width
	XftTextExtents8(display, tb->font, (unsigned char*)line, length, &extents);
	line_width = extents.width;

	int x = 0, y = tb->font->ascent;
	if (tb->flags & TB_RIGHT)  x = tb->w - line_width;
	if (tb->flags & TB_CENTER) x = (tb->w - line_width) / 2;

	// draw the text, including any prompt in edit mode
	XftDrawString8(draw, &tb->color_fg, tb->font, x, y, (unsigned char*)line, length);

	// draw the cursor
	if (tb->flags & TB_EDITABLE)
		XftDrawRect(draw, &tb->color_fg, cursor_x, 2, cursor_width, line_height-4);

	// flip canvas to window
	XCopyArea(display, canvas, tb->window, context, 0, 0, tb->w, tb->h, 0, 0);

	XFreeGC(display, context);
	XftDrawDestroy(draw);
	XFreePixmap(display, canvas);
}
Esempio n. 16
0
File: main.c Progetto: howrujh/tp
void* thread_pattern_gen(void *data){

	Display *dp;
	Bool is_ntsc = (Bool)data;
	Window mw; /* One TopLevel Window & Two Child Windows */
	GC gc, gc_rect1, gc_rect2, gc_string;
	XftFont *xft;
	XftDraw *xftdraw;
	XRenderColor xrcolor;
	XftColor xftcolor;

	XGCValues gv;
	XSetWindowAttributes xswa;

	struct timeval tv;

	/* 서버와 접속하기 그리고 변수들을 초기화 */
	dp = XOpenDisplay ( NULL );

	mw = XCreateSimpleWindow ( dp, DefaultRootWindow( dp ),
			0, 0, 720, is_ntsc?480:576, 0,
			WhitePixel(dp,0), BlackPixel(dp,0) );

	xswa.override_redirect = True;
	XChangeWindowAttributes ( dp, mw, CWOverrideRedirect, &xswa );
	XMapWindow( dp, mw );

	gv.foreground = UsrColorPixel( dp, "red" );
	gv.background = UsrColorPixel( dp, "yello" );
	gc = XCreateGC( dp, mw, GCForeground | GCBackground, &gv );
	gv.foreground = UsrColorPixel( dp, "red" );
	gv.background = UsrColorPixel( dp, "black" );
	gc_rect1 = XCreateGC( dp, mw, GCForeground | GCBackground, &gv );
	gv.foreground = UsrColorPixel( dp, "blue" );
	gv.background = UsrColorPixel( dp, "black" );
	gc_rect2 = XCreateGC( dp, mw, GCForeground | GCBackground, &gv );
	gv.foreground = UsrColorPixel( dp, "white" );
	gv.background = UsrColorPixel( dp, "black" );
	gc_string = XCreateGC( dp, mw, GCForeground | GCBackground, &gv );
	
	//xft  = XftFontOpenName( dp, 0, "Bitstream Vera Sans Mono-50:bold" ); 
	xft  = XftFontOpenName( dp, 0, "Courier New-48:bold" ); 
	if(!xft){
		printf("font null\n");
		return 0;
	}
	xftdraw = XftDrawCreate(dp, mw, DefaultVisual(dp, 0), DefaultColormap(dp, 0));

	xrcolor.red = 65535;
	xrcolor.green = 65535;
	xrcolor.blue =65535;
	xrcolor.alpha = 65535;

	XftColorAllocValue(dp, DefaultVisual(dp, 0), DefaultColormap(dp, 0), &xrcolor, &xftcolor);



	int frame_rate = is_ntsc? 30:25;
	unsigned int div = is_ntsc? 33333: 40000;

	char line1[40];
	char line2[40];

	int line1_y = is_ntsc? (480/2)-30 : (576/2)-30;
	int line2_y = is_ntsc? (480/2)+30 : (576/2)+30;

	int rect1_y = is_ntsc? 480/4 : 576/4;
	int rect2_y = is_ntsc? (480/4)*3 : (576/4)*3;


	while(1){
		if(kill_thread) break;

		int move;
		for( move = 0; move < frame_rate; move ++){
			gettimeofday(&tv, NULL);
			struct tm *ptm = localtime(&(tv.tv_sec));


			XFlush(dp);
			XClearWindow( dp, mw );

			XFillRectangle ( dp, mw, gc_rect1, (move==0)? 0:(720/30)*move, rect1_y, 50, 10);

			XFillRectangle ( dp, mw, gc_rect2, (move==0)? 0:720-(720/30)*move, rect2_y, 50, 10);


			sprintf(line1," %04d/%02d/%02d ", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);

			sprintf(line2,"%02d:%02d:%02d %02ld\'",ptm->tm_hour, ptm->tm_min, ptm->tm_sec, tv.tv_usec/div);
			XftDrawString8(xftdraw, &xftcolor, xft, 100, line1_y, (XftChar8 *)line1, 12);
			XftDrawString8(xftdraw, &xftcolor, xft, 100, line2_y, (XftChar8 *)line2, 12);
			usleep(div);
		}
	}


	printf("thread kill\n");

	/* GC, 창 파괴 & 서버와의 접속 해제 */
	XFreeGC( dp, gc );
	XUnmapWindow( dp, mw );

	XftDrawDestroy(xftdraw);
	XftColorFree(dp, DefaultVisual(dp, 0), DefaultColormap(dp, 0), &xftcolor);

	XDestroyWindow( dp, mw );


	XCloseDisplay( dp );

	return 0;


}
Esempio n. 17
0
void
gui_draw_task (task *tk)
{
	int len;
	int x = tk->pos_x;
	int taskw = tk->width;
#ifdef XFT
	XGlyphInfo ext;
	XftColor col;
#endif

	if (!tk->name)
		return;

	gui_draw_vline (x);

	if (tk->focused)
	{
		draw_box (x, taskw);
	} else
	{
		set_foreground (5);		  /* mid gray */
		fill_rect (x + 2, 0, taskw - 1, WINHEIGHT);
	}

	{
		register int text_x = x + TEXTPAD + TEXTPAD + ICONWIDTH;
#ifdef XFT

		/* check how many chars can fit */
		len = strlen (tk->name);
		while (len > 0)
		{
			XftTextExtents8 (dd, xfs, tk->name, len, &ext);
			if (ext.width < taskw - (text_x - x) - 2)
				break;
			len--;
		}

		col.color.alpha = 0xffff;

		if (tk->iconified)
		{
			/* draw task's name dark (iconified) */
			col.color.red = cols[3].red;
			col.color.green = cols[3].green;
			col.color.blue = cols[3].blue;
			XftDrawString8 (xftdraw, &col, xfs, text_x, text_y + 1, tk->name, len);
			col.color.red = cols[3].red;
			col.color.green = cols[3].green;
			col.color.blue = cols[3].blue;
		} else
		{
			col.color.red = cols[3].red;
			col.color.green = cols[3].green;
			col.color.blue = cols[3].blue;
		}

		/* draw task's name here */
		XftDrawString8 (xftdraw, &col, xfs, text_x, text_y, tk->name, len);

#else

		/* check how many chars can fit */
		len = strlen (tk->name);

		while (XTextWidth (xfs, tk->name, len) >= taskw - (text_x - x) - 2
				 && len > 0)
			len--;

		if (tk->iconified)
		{
			/* draw task's name dark (iconified) */
		    set_foreground (4);
			XDrawString (dd, tb.win, fore_gc, text_x, text_y + 1, tk->name, len);
			set_foreground (3);
		} else if (tk->focused)
		{
        	set_foreground (7);
		}
        else
        {
            set_foreground (4);
        }

		/* draw task's name here */
		XDrawString (dd, tb.win, fore_gc, text_x, text_y, tk->name, len);
#endif
	}

#ifndef HAVE_XPM
	if (!tk->icon)
		return;
#endif

	/* draw the task's icon */
	XSetClipMask (dd, fore_gc, tk->mask);
	XSetClipOrigin (dd, fore_gc, x + TEXTPAD, (WINHEIGHT - ICONHEIGHT) / 2);
	XCopyArea (dd, tk->icon, tb.win, fore_gc, 0, 0, ICONWIDTH, ICONHEIGHT,
				  x + TEXTPAD, (WINHEIGHT - ICONHEIGHT) / 2);
	XSetClipMask (dd, fore_gc, None);
}
Esempio n. 18
-1
void
WMDrawImageString(WMScreen *scr, Drawable d, WMColor *color, WMColor *background,
                  WMFont *font, int x, int y, char *text, int length)
{
    XftColor textColor;
    XftColor bgColor;

    wassertr(font!=NULL);

    textColor.color.red = color->color.red;
    textColor.color.green = color->color.green;
    textColor.color.blue = color->color.blue;
    textColor.color.alpha = color->alpha;;
    textColor.pixel = W_PIXEL(color);

    bgColor.color.red = background->color.red;
    bgColor.color.green = background->color.green;
    bgColor.color.blue = background->color.blue;
    bgColor.color.alpha = background->alpha;;
    bgColor.pixel = W_PIXEL(background);

    XftDrawChange(scr->xftdraw, d);

    XftDrawRect(scr->xftdraw, &bgColor, x, y,
                WMWidthOfString(font, text, length),
                font->height);

    if (font->screen->useWideChar) {
        wchar_t *wtext;
        const char *mtext;
        int len;

        mtext = text;
        wtext = (wchar_t *)wmalloc(sizeof(wchar_t)*(length+1));
        len = wmbsnrtowcs(wtext, &mtext, length, length);
        if (len>0) {
            XftDrawString32(scr->xftdraw, &textColor, font->font,
                            x, y + font->y, (XftChar32*)wtext, len);
        } else if (len==-1) {
            wwarning(_("Conversion to widechar failed (possible invalid "
                       "multibyte sequence): '%s':(pos %d)\n"),
                     text, mtext-text+1);
            /* we can draw normal text, or we can draw as much widechar
             * text as was already converted until the error. go figure */
            /*XftDrawString8(scr->xftdraw, &textColor, font->font,
             x, y + font->y, (XftChar8*)text, length);*/
        }
        wfree(wtext);
    } else if (font->screen->useMultiByte) {
        XftDrawStringUtf8(scr->xftdraw, &textColor, font->font,
                          x, y + font->y, (XftChar8*)text, length);
    } else {
        XftDrawString8(scr->xftdraw, &textColor, font->font,
                       x, y + font->y, (XftChar8*)text, length);
    }
}