Beispiel #1
0
static void
desktops(int start)
{
	char buf[4];
	XGlyphInfo extents;
	int x, i, curdesk, numdesk;
	int cellwidth = 14;

	curdesk = get_int_property("_NET_CURRENT_DESKTOP");
	numdesk = get_int_property("_NET_NUMBER_OF_DESKTOPS");
	if (curdesk < 0 || numdesk < 0)
		return;

	for (i=0, x=start; i<numdesk; i++, x+=cellwidth) {
		sprintf(buf, "%d", i+1);
		if (i == curdesk) {
			XftDrawRect(xftd, &white, x, 0, cellwidth, BARHEIGHT);
			XftTextExtentsUtf8(d, xftfont, (const FcChar8 *)buf, strlen(buf), &extents);
			XftDrawStringUtf8(xftd, &black, xftfont, x + (cellwidth - extents.xOff) / 2, 2 + xftfont->ascent, (const FcChar8 *)buf, strlen(buf));
		} else {
			XftDrawRect(xftd, &black, x, 0, cellwidth, BARHEIGHT);
			XftTextExtentsUtf8(d, xftfont, (const FcChar8 *)buf, strlen(buf), &extents);
			XftDrawStringUtf8(xftd, &white, xftfont, x + (cellwidth - extents.xOff) / 2, 2 + xftfont->ascent, (const FcChar8 *)buf, strlen(buf));
		}
	}
}
Beispiel #2
0
static void draw_text(Client *c, XftFont *fnt, int fill, int tcol, int scol,
		int x, int y, const char *str)
{
	XSetForeground(dpy, gc, fill);
	XFillRectangle (dpy, c->frame, gc, x-5, 0, c->w, config.title_height);
	set_xcolor(scol, 0xFFFF);
	XftDrawStringUtf8(c->draw, &xcolor, fnt, x, y, (XftChar8 *)str, strlen(str));
	set_xcolor(tcol, 0xFFFF);
	XftDrawStringUtf8(c->draw, &xcolor, fnt, x-1, y-1, (XftChar8 *)str, strlen(str));
}
Beispiel #3
0
void XImlib2Caption::updateText()
{   
     XDesktopContainer * xContainer =
			dynamic_cast<XDesktopContainer *>(AbstractImage::container);
    
      XftDrawChange(fontDrawHandle, pixmap);
	if (shadowOn)
		XftDrawStringUtf8( fontDrawHandle, &shadowFontColor, font, FONTSHIFT/2 + shadowX, font->ascent + shadowY, (XftChar8*)text.c_str(), text.length() );

	XftDrawStringUtf8(fontDrawHandle, &fontColor, font, FONTSHIFT/2, font->ascent, (XftChar8*)text.c_str(), text.length() );
}
Beispiel #4
0
Datei: font.c Projekt: dct/xvnkb
/*----------------------------------------------------------------------------*/
void VKDrawFontDialog()
{
    static char *titles[2] = {"Select interface font", "Chọn font giao dien"};
    static char *mesages[] = {"Press a key group:", "Nhấn một nhóm phím:"};
    char *S = mesages[vk_interface];
    char *T = titles[vk_interface];
    int i, fa = vk_text_ascent;

#ifdef USE_XFT
    XftDraw *draw;
    draw = XftDrawCreate(display, fnt.window, visual, colormap);
#else
#define	draw
#endif

    XClearWindow(display, fnt.window);
    VKSetColor(display, fnt.gc, clBackground);
    XFillRectangle(display, fnt.window, fnt.gc, 0, 0, fnt.width, fnt.height);
    VKSetColor(display, fnt.gc, clBorder);
    XDrawRectangle(display, fnt.window, fnt.gc, 1, 1, fnt.width-3, fnt.height-3);
    XFillRectangle(display, fnt.window, fnt.gc, 1, 1, fnt.width-3, vk_text_height+6);
    XDrawLine(display, fnt.window, fnt.gc, 1, fnt.ly, fnt.width-3, fnt.ly);
    for( i=0; i<3; i++ ) {
        VKDrawLabel((VKLabel *)fc[i]);
    }
#ifdef USE_XFT
    XftDrawStringUtf8(draw, &clBlack, vk_font,
                      11, fa+5+1, (XftChar8*)T, strlen(T));
    XftDrawStringUtf8(draw, &clWhite, vk_font,
                      10, fa+5, (XftChar8*)T, strlen(T));
    XftDrawStringUtf8(draw, &clGray, vk_font,
                      fnt.tx+1, fnt.ty+1, (XftChar8*)S, strlen(S));
    XftDrawStringUtf8(draw, &clBlack, vk_font,
                      fnt.tx, fnt.ty, (XftChar8*)S, strlen(S));
    XftDrawDestroy(draw);
#else
#undef draw
    VKSetColor(display, fnt.gc, clBlack);
    XmbDrawString(display, fnt.window, vk_fontset, fnt.gc,
                  11, fa+5+1, T, strlen(T));
    VKSetColor(display, fnt.gc, clWhite);
    XmbDrawString(display, fnt.window, vk_fontset, fnt.gc,
                  10, fa+5, T, strlen(T));
    VKSetColor(display, fnt.gc, clGray);
    XmbDrawString(display, fnt.window, vk_fontset, fnt.gc,
                  fnt.tx+1, fnt.ty+1, S, strlen(S));
    VKSetColor(display, fnt.gc, clBlack);
    XmbDrawString(display, fnt.window, vk_fontset, fnt.gc,
                  fnt.tx, fnt.ty, S, strlen(S));
#endif
}
Beispiel #5
0
/* render text
   position - 0 left, 1-center
*/
static void draw_str( Widget w, int clear_area, enum CLABEL n )
{
  CtrlWidget cw = (CtrlWidget)w;
  CtrlPart *c = & cw->ctrl;
  Display *dpy = XtDisplay(w);
  clabel_t *cl = c->clabel + n;
  char *s;
  Dimension x,y;

  TF();

  if( ! cl->width || ! cl->height ) return; 

  if( clear_area ) {
    TRACE(2, "%s %d", cw->core.name, c->msg.state );

    XFillRectangle( XtDisplay(w), XtWindow(w), c->gc[c->msg.state], 
		    cl->x, cl->y, cl->width, cl->height );  
  }

  s = cl->str;
  if( IsEmpty(s) ) return;

  x = cl->x;
  y = cl->y + cl->font->ascent;
  if( cl->position == 1 ) // center label
    {
      XftTextExtentsUtf8(dpy, cl->font, (FcChar8*)s,  
		     strlen(s), & cl->extents );
      x+=(cl->width - cl->extents.xOff) / 2; 

      calc_str_position( cl );

      TRACE(2, "%s (%u %u) (%u %u)", cw->core.name,
	    cl->x, cl->y,
	    cl->str_x, cl->str_y );
      

      XftDrawStringUtf8(c->draw, c->col+c->msg.state, cl->font, 
			cl->x + cl->str_x,
			cl->y + cl->str_y,
			(FcChar8*)s,strlen(s) ); 
      return;
    }

  XftDrawStringUtf8(c->draw, c->col+c->msg.state, cl->font, x,y,
		    (FcChar8*)s,strlen(s) ); 
}
Beispiel #6
0
static int
drawstring(char *str, int x, int flushright)
{
	XGlyphInfo extents;
	int erasemore = 10;

	XftTextExtentsUtf8(d, xftfont, (const FcChar8 *)str, strlen(str), &extents);
	if (flushright) {
		XftDrawRect(xftd, &black, x - extents.xOff - erasemore, 0, extents.xOff + erasemore, BARHEIGHT);
		XftDrawStringUtf8(xftd, &white, xftfont, x - extents.xOff, 1 + xftfont->ascent, (const FcChar8 *)str, strlen(str));
	} else {
		XftDrawRect(xftd, &black, x, 0, extents.xOff + erasemore, BARHEIGHT);
		XftDrawStringUtf8(xftd, &white, xftfont, x, 1 + xftfont->ascent, (const FcChar8 *)str, strlen(str));
	}
	return extents.xOff;
}
Beispiel #7
0
int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, int x, int y,
                  char *text, int len, int w)
{
	int err, tw = 0;
	char *t, *next;
	uint32_t rune;
	XftFont *f;
	FcCharSet *fccharset;
	XGlyphInfo ext;

	for (t = text; t - text < len; t = next) {
		next = utf8_decode(t, &rune, &err);
		if (XftCharExists(win->env.dpy, font, rune)) {
			f = font;
		} else { /* fallback font */
			fccharset = FcCharSetCreate();
			FcCharSetAddChar(fccharset, rune);
			f = XftFontOpen(win->env.dpy, win->env.scr, FC_CHARSET, FcTypeCharSet,
			                fccharset, FC_SCALABLE, FcTypeBool, FcTrue,
			                FC_SIZE, FcTypeDouble, fontsize, NULL);
			FcCharSetDestroy(fccharset);
		}
		XftTextExtentsUtf8(win->env.dpy, f, (XftChar8*)t, next - t, &ext);
		tw += ext.xOff;
		if (tw <= w) {
			XftDrawStringUtf8(d, color, f, x, y, (XftChar8*)t, next - t);
			x += ext.xOff;
		}
		if (f != font)
			XftFontClose(win->env.dpy, f);
	}
	return tw;
}
Beispiel #8
0
Datei: drw.c Projekt: Cornu/dwm
void
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text) {
	char buf[256];
	int i, tx, ty, th, len, olen;
	Extnts tex;
	XftDraw *d;

	if(!drw || !drw->scheme)
		return;
	XSetForeground(drw->dpy, drw->gc, drw->scheme->bg->rgb);
	XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
	if(!text || !drw->font)
		return;
	olen = strlen(text);
	drw_font_getexts(drw, text, olen, &tex);
	/* shorten text if necessary */
	for(len = MIN(olen, sizeof buf); len && (tex.w > w - tex.h || w < tex.h); len--)
		drw_font_getexts(drw, text, len, &tex);
	if(!len)
		return;
	memcpy(buf, text, len);
	if(len < olen)
		for(i = len; i && i > len - 3; buf[--i] = '.');

	th = drw->font->ascent + drw->font->descent;
	ty = y + (h / 2) - (th / 2) + drw->font->ascent;
	tx = x + (w / 2) - (tex.w / 2);
	d = XftDrawCreate(drw->dpy, drw->drawable, DefaultVisual(drw->dpy, drw->screen), DefaultColormap(drw->dpy, drw->screen));
	XftDrawStringUtf8(d, &drw->scheme->fg->xftc, drw->font->xfont, tx, ty, (XftChar8 *) buf, len);
	XftDrawDestroy(d);
}
Beispiel #9
0
static void
draw_text (struct widget_xft_data *data, char *lbl, int inverse)
{
    Screen *sc = XtScreen (data->widget);
    int screen = XScreenNumberOfScreen (sc);
    int y = data->xft_font->ascent;
    int x = inverse ? 0 : 2;
    char *bp = lbl;

    data->xft_draw = XftDrawCreate (XtDisplay (data->widget),
                                    data->p,
                                    DefaultVisual (XtDisplay (data->widget),
                                            screen),
                                    DefaultColormapOfScreen (sc));
    XftDrawRect (data->xft_draw,
                 inverse ? &data->xft_fg : &data->xft_bg,
                 0, 0, data->p_width, data->p_height);

    if (!inverse) y += 2;
    while (bp && *bp != '\0')
    {
        char *cp = strchr (bp, '\n');
        XftDrawStringUtf8 (data->xft_draw,
                           inverse ? &data->xft_bg : &data->xft_fg,
                           data->xft_font, x, y,
                           (FcChar8 *) bp,
                           cp ? cp - bp : strlen (bp));
        bp = cp ? cp + 1 : NULL;
        /* 1.2 gives reasonable line spacing.  */
        y += data->xft_font->height * 1.2;
    }

}
Beispiel #10
0
/** Draw a string in a Drawable
 * \param d Drawable
 * \param x X position
 * \param y Y position
 * \param fg Foreground text color
 * \param pad Text padding
 * \param str String that will be draw
*/
void
draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image_ofset, int y_image_ofset)
{
     XftColor xftcolor;
     XftDraw *xftd;
#ifdef HAVE_IMLIB
     char *ostr = NULL;
     int i, ni, sw = 0;
     ImageAttr im[128];
     size_t textlen;
#else
     (void)x_image_ofset;
     (void)y_image_ofset;
#endif /* HAVE_IMLIB */

     if(!str)
          return;

     /* To draw image everywhere we can draw text */
#ifdef HAVE_IMLIB

     ostr = xstrdup(str);
     textlen = strlen(ostr);

     if(strstr(str, "i["))
     {
          ni = parse_image_block(im, str);

          if(infobar[conf.systray.screen].bar && d == infobar[conf.systray.screen].bar->dr)
               sw = systray_get_width();

          for(i = 0; i < ni; ++i)
               draw_image(d, x_image_ofset + im[i].x - sw, y_image_ofset + im[i].y, im[i].w, im[i].h, im[i].name);
     }
#endif /* HAVE_IMLIB */

     /* Transform X Drawable -> Xft Drawable */
     xftd = XftDrawCreate(dpy, d, DefaultVisual(dpy, SCREEN), DefaultColormap(dpy, SCREEN));

     /* Alloc text color */
     XftColorAllocName(dpy, DefaultVisual(dpy, SCREEN),
                       DefaultColormap(dpy, SCREEN), fg, &xftcolor);

     XftDrawStringUtf8(xftd, &xftcolor, font, x, y, (FcChar8 *)str, strlen(str));

     /* Free the text color and XftDraw */
     XftColorFree(dpy, DefaultVisual(dpy, SCREEN), DefaultColormap(dpy, SCREEN), &xftcolor);

     XftDrawDestroy(xftd);

#ifdef HAVE_IMLIB
     if(strstr(ostr, "i["))
          strncpy(str, ostr, textlen);

     free(ostr);
#endif /* HAVE_IMLIB */

     return;
}
Beispiel #11
0
//=========================================
// setText
//-----------------------------------------
XImage* setText (Display* dpy,int screen,char* text, int* x, int* y) {
	Window root = RootWindow    ( dpy,screen );
	int DWidth  = DisplayWidth  ( dpy,screen );
	int DHeight = DisplayHeight ( dpy,screen );

	XftPattern *pattern = NULL;
	XftFont*  FTfont    = NULL;
	XftDraw*  FTdraw    = NULL;
	XftColor* FTcolor   = NULL;
	XImage*   Image     = NULL;

	XGlyphInfo FTinfo;
	XColor color;
	XGCValues values;
	int XTwidth;
	int XTheight;
	int x1,y1;

	pattern = XftNameParse (XFTFONT);
	pattern = XftFontMatch (dpy,screen,pattern,NULL);
	FTfont  = XftFontOpenPattern (dpy, pattern);
	XftTextExtentsUtf8 (
		dpy,FTfont,text,strlen(text),&FTinfo
	);
	XTwidth = FTinfo.xOff;
	XTheight= FTfont->height + 20;
	FTdraw  = XftDrawCreate (
		dpy, root, DefaultVisual(dpy,screen),DefaultColormap(dpy,screen)
	);
	FTcolor = (XftColor*)malloc(sizeof(XftColor));
	color.red   = 255 << 8;
	color.green = 255 << 8;
	color.blue  = 255 << 8;
	XAllocColor (dpy,DefaultColormap(dpy,screen),&color);
	XSetForeground(dpy,DefaultGC (dpy,screen),color.pixel);
	XGetGCValues (
		dpy, DefaultGC (dpy,screen),
		GCForeground | GCBackground, &values
	);
	FTcolor->color.red   = color.red;
	FTcolor->color.green = color.green;
	FTcolor->color.blue  = color.blue;
	FTcolor->color.alpha = 0xffff;

	x1 = (int)((DWidth  / 2) - (XTwidth  / 2));
	y1 = (int)((DHeight / 2) - (XTheight / 2));

	XftDrawStringUtf8 (
		FTdraw, FTcolor,FTfont,x1,y1,text,strlen(text)
	);
	XFlush (dpy);
	y1 = (int)((DHeight / 2) - XTheight);
	Image = XGetImage(
		dpy,root,x1,y1,XTwidth,XTheight,AllPlanes,XYPixmap
	);
	*x = x1;
	*y = y1;
	return (Image);
}
Beispiel #12
0
static void
_xft_TextDraw(TextState * ts, int x, int y, const char *text, int len)
{
   FontCtxXft         *fdc = (FontCtxXft *) ts->fdc;

   XftDrawStringUtf8(fdc->xftd, &(fdc->xftc), fdc->font, x, y,
		     (const XftChar8 *)text, len);
}
Beispiel #13
0
static void ui_draw_coordinates()
{
	for ( int y = 0; y < 8; ++y ) {

		XftChar8 c = '8' - y;
		XGlyphInfo extents;
		XftTextExtentsUtf8(ui_display, ui_coordfont, &c, 1, &extents);

		int xPos = ui_board_pos_x + (4 * UI_SIZE_SQUARE_WIDTH) / 100;
		int yPos = UI_POS_BOARD_Y + (UI_SIZE_SQUARE_HEIGHT * y) +
				extents.height + (4 * UI_SIZE_SQUARE_WIDTH) / 100;

		XftColor* color = NULL;
		if ( y % 2 == 0 ) {
			color = &ui_squarecolorblack;
		} else {
			color = &ui_squarecolorwhite;
		}

		XftDrawStringUtf8(ui_xftdraw, color, ui_coordfont, xPos, yPos, &c, 1);
	}

	for ( int x = 0; x < 8; ++x ) {

		XftChar8 c = 'a' + x;
		XGlyphInfo extents;
		XftTextExtentsUtf8(ui_display, ui_coordfont, &c, 1, &extents);

		int xPos = ui_board_pos_x + (UI_SIZE_SQUARE_WIDTH * (x + 1)) -
				extents.width;// - (4 * UI_SIZE_SQUARE_WIDTH) / 100;
		int yPos = UI_POS_BOARD_Y + (UI_SIZE_SQUARE_HEIGHT * 8) -
				(60 * extents.height) / 100;

		XftColor* color = NULL;
		if ( x % 2 == 0 ) {
			color = &ui_squarecolorwhite;
		} else {
			color = &ui_squarecolorblack;
		}

		XftDrawStringUtf8(ui_xftdraw, color, ui_coordfont, xPos, yPos, &c, 1);
	}
}
static inline void
draw_string(Display *xdisplay, XftDraw *draw, XftFont *font, XftColor *colour,
	    const gchar *text, gint *pos_y)
{
    XGlyphInfo extents;
    gint len = strlen(text);

    XftTextExtentsUtf8(xdisplay, font, (guchar *)text, len, &extents);
    XftDrawStringUtf8(draw, colour, font, 4, *pos_y + extents.y, (guchar *)text, len);
    *pos_y += extents.height + 4;
}
Beispiel #15
0
/* 繪出Utf8字元 */
static unsigned int Draw_Utf8_Char(winlist_t *win, XftFont *font, int foreground_idx, int background_idx, int x, int y, char *Utf8Char, int Utf8len)
{
    unsigned int width = Utf8_Char_Escapement(win->draw, font, Utf8Char, Utf8len);
    
    if (background_idx >= 0 && background_idx <= MAX_COLORS)
    {
	XftDrawRect(win->draw, &gui->colors[background_idx], x, y - win->font_size+1, width, win->font_size);
    }

    XftDrawStringUtf8(win->draw, &gui->colors[foreground_idx], font, x, y, (FcChar8 *)Utf8Char, Utf8len);

    return width;
}
Beispiel #16
0
void ShowGeometry::update(int x, int y)
{
    char string[20];

    sprintf(string, "%d %d", x, y);
    int width = getTextWidth(string, strlen(string)) + 8;
#ifdef CONFIG_USE_XFT
    int height = m_font->ascent + m_font->descent + 8;
#else
    int height = m_font[screen()]->ascent + m_font[screen()]->descent + 8;
#endif
    int mx = DisplayWidth (display(), screen()) - 1;
    int my = DisplayHeight(display(), screen()) - 1;
  
    XMoveResizeWindow(display(), m_window[screen()],

#if CONFIG_GEOMETRY_X_POS < 0
		      0
#elif CONFIG_GEOMETRY_X_POS > 0
		      (mx - width)
#else
		      (mx - width) / 2
#endif
		      ,
#if CONFIG_GEOMETRY_X_POS < 0
		      0
#elif CONFIG_GEOMETRY_X_POS > 0
		      (my - height)
#else
                      (my - height) / 2
#endif
		      , width, height);

    XClearWindow(display(), m_window[screen()]);
    XMapRaised(display(), m_window[screen()]);

#ifdef CONFIG_USE_XFT
    XftDrawStringUtf8(m_xftDraw[screen()],
		      &m_xftColour[screen()],
		      m_font,
		      4,
		      4 + m_font->ascent,
		      (FcChar8 *)string,
		      strlen(string));
#else
    XDrawString(display(), m_window[screen()],
		Border::drawGC(m_windowManager,screen()),
		4, 4 + m_font[screen()]->ascent, string, strlen(string));
#endif
}
Beispiel #17
0
SE_UNUSED void se_draw_char_utf8( se_text_xviewer* viewer, XftColor* color,
                                  se_cursor cur, int c )
{
    assert( viewer && viewer->xftDraw );

    const se_env* env = viewer->env;
    se_position cur_pos = se_text_cursor_to_physical(viewer, cur);
    se_position start_pos = {
        cur_pos.x,
        cur_pos.y + env->glyphAscent,
    };
    XftDrawStringUtf8( viewer->xftDraw, color, viewer->env->xftFont,
                       start_pos.x, start_pos.y, (const XftChar8*)&c, 1 );
}
Beispiel #18
0
static void se_draw_text_utf8( se_text_xviewer* viewer, XftColor* color,
                        se_cursor cur, const char* utf8, int utf8_len )
{
    assert( viewer && viewer->xftDraw );
    const se_env* env = viewer->env;
    se_position cur_pos = se_text_cursor_to_physical(viewer, cur);
    se_position start_pos = {
        cur_pos.x,
        cur_pos.y + env->glyphAscent,
    };
    /* se_debug( "utf8: %s, utf8_len: %d", utf8, utf8_len ); */
    XftDrawStringUtf8( viewer->xftDraw, color, viewer->env->xftFont,
                       start_pos.x, start_pos.y,
                       (const XftChar8*)utf8, utf8_len );
}
Beispiel #19
0
Datei: gui.c Projekt: mortehu/bra
void
gui_draw_text_length(struct gui_instance *gi, struct gui_font *font,
                     int x, int y, const char *text, size_t length,
                     unsigned int color)
{
  XftColor xft_color;

  xft_color.pixel = color | 0xff000000;
  xft_color.color.red = (color >> 16) * 0x0101;
  xft_color.color.green = ((color >> 8) & 0xff) * 0x0101;
  xft_color.color.blue = (color & 0xff) * 0x0101;
  xft_color.color.alpha = 0xffff;

  XftDrawStringUtf8(gi->fontdraw, &xft_color, font->xft_font,
                    x, y + font->xft_font->ascent,
                    (const unsigned char *) text, length);
}
Beispiel #20
0
void
drawtextn(DC *dc, const char *text, size_t n, ColorSet *col) {
	int x = dc->x + dc->font.height/2;
	int y = dc->y + dc->font.ascent+1;

	XSetForeground(dc->dpy, dc->gc, col->FG);
	if(dc->font.xft_font) {
		if (!dc->xftdraw)
			eprintf("error, xft drawable does not exist");
		XftDrawStringUtf8(dc->xftdraw, &col->FG_xft,
			dc->font.xft_font, x, y, (unsigned char*)text, n);
	} else if(dc->font.set) {
		XmbDrawString(dc->dpy, dc->canvas, dc->font.set, dc->gc, x, y, text, n);
	} else {
		XSetFont(dc->dpy, dc->gc, dc->font.xfont->fid);
		XDrawString(dc->dpy, dc->canvas, dc->gc, x, y, text, n);
	}
}
Beispiel #21
0
static void ui_draw_string( const char* str, XftFont* font, XftColor* color, int x, int y, int maxwidth, int* width)
{
	XftChar16 dotch = 0x2026; // unicode ... character

	/* get width of three dots */
	XGlyphInfo extents;
	XftTextExtents16(ui_display, font, &dotch, 1, &extents);

	int sizepoints = extents.width;

	size_t cutlen = 0;

	XftTextExtentsUtf8(ui_display, font, (XftChar8*) str, strlen(str), &extents);

	int totlen = extents.width;

	while (totlen > maxwidth && cutlen < strlen(str)) {
		++cutlen;

		XftTextExtentsUtf8(ui_display, font, (XftChar8*) str, strlen(str) - cutlen, &extents);
		totlen = extents.width + sizepoints;
	}

	if (NULL != width) {
		*width = 0;
	}

	if (totlen <= maxwidth) {
		XftDrawStringUtf8(ui_xftdraw, color, font, x, y, (XftChar8*) str, strlen(str) - cutlen);

		if (cutlen > 0) {
			XftDrawString16(ui_xftdraw, color, font, x + extents.width, y, &dotch, 1);
		}

		if (NULL != width) {
			*width = totlen;
		}
	}
}
Beispiel #22
0
static void
xft_draw (Lisp_Font *f, char *string, size_t length,
	  Window id, GC gc, Lisp_Color *fg, int x, int y)
{
    static XftDraw *draw;

    XftColor xft_color;

    if (draw == 0)
	draw = XftDrawCreate (dpy, id, image_visual, image_cmap);
    else
	XftDrawChange (draw, id);

    xft_color.pixel = fg->pixel;
    xft_color.color.red = fg->red;
    xft_color.color.green = fg->green;
    xft_color.color.blue = fg->blue;
    xft_color.color.alpha = fg->alpha;

    XftDrawStringUtf8 (draw, &xft_color, f->font,
                       x, y, (FcChar8 *)string, length);
}
Beispiel #23
0
Datei: gui.c Projekt: mortehu/bra
void
gui_draw_text(struct gui_instance *gi, struct gui_font *font,
              int x, int y, const char *text, unsigned int color,
              int alignment)
{
  XftColor xft_color;
  size_t length;

  length = strlen(text);

  if(alignment)
    x -= gui_text_width(font, text, length) * alignment / 2;

  xft_color.pixel = color | 0xff000000;
  xft_color.color.red = (color >> 16) * 0x0101;
  xft_color.color.green = ((color >> 8) & 0xff) * 0x0101;
  xft_color.color.blue = (color & 0xff) * 0x0101;
  xft_color.color.alpha = 0xffff;

  XftDrawStringUtf8(gi->fontdraw, &xft_color, font->xft_font,
                    x, y + font->xft_font->ascent,
                    (const unsigned char *) text, length);
}
Beispiel #24
0
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);
    }
}
Beispiel #25
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
        }
    }
}
Beispiel #26
0
void Thumbnail::redraw()
{
    int borderWidth = Settings::instance()->borderWidth();
    int headerHeight = Resources::instance()->headerMiddle()->height();
    int headerLeftWidth = Resources::instance()->headerLeft()->width();
    int headerRightWidth = Resources::instance()->headerRight()->width();

    int w = _clientScaledWidth;
    int h = _clientScaledHeight;

    bool selected = (!Settings::instance()->disableSelection())
                    && this == _teleWindow->activeThumbnail();
    const XRenderColor *borderColor = selected ?
                                      Resources::instance()->borderActiveColor() :
                                      Resources::instance()->borderColor();

    Picture left = selected ?
                   Resources::instance()->headerLeftSelected()->picture() :
                   Resources::instance()->headerLeft()->picture();
    Picture right = selected ?
                    Resources::instance()->headerRightSelected()->picture() :
                    Resources::instance()->headerRight()->picture();
    Picture middle = selected ?
                     Resources::instance()->headerMiddleSelected()->picture() :
                     Resources::instance()->headerMiddle()->picture();

    XRenderComposite(_dpy, PictOpSrc,
                     left, None, _image->picture(),
                     0, 0,
                     0, 0,
                     _clientOffsetX - borderWidth,
                     _clientOffsetY - headerHeight,
                     headerLeftWidth, headerHeight
                    );

    XRenderComposite(_dpy, PictOpSrc,
                     right, None, _image->picture(),
                     0, 0,
                     0, 0,
                     _clientOffsetX + w + borderWidth - headerRightWidth,
                     _clientOffsetY - headerHeight,
                     headerRightWidth, headerHeight
                    );

    XRenderComposite(_dpy, PictOpSrc,
                     middle, None, _image->picture(),
                     0, 0,
                     0, 0,
                     _clientOffsetX - borderWidth + headerLeftWidth,
                     _clientOffsetY - headerHeight,
                     w + 2 * borderWidth - headerLeftWidth - headerRightWidth,
                     headerHeight
                    );

    // Left border
    XRenderFillRectangle(_dpy, PictOpSrc, _image->picture(), borderColor,
                         _clientOffsetX - borderWidth,
                         _clientOffsetY,
                         borderWidth, h
                        );
    // Right border
    XRenderFillRectangle(_dpy, PictOpSrc, _image->picture(), borderColor,
                         _clientOffsetX + w,
                         _clientOffsetY,
                         borderWidth, h
                        );
    // Bottom border
    XRenderFillRectangle(_dpy, PictOpSrc, _image->picture(), borderColor,
                         _clientOffsetX - borderWidth,
                         _clientOffsetY + h,
                         w + 2*borderWidth, borderWidth
                        );


    // Drawing title text

    XftColor fontColor;
    fontColor.pixel = 0;
    fontColor.color.red     = 0xffff;
    fontColor.color.green   = 0xffff;
    fontColor.color.blue    = 0xffff;
    fontColor.color.alpha   = 0xffff;

    XRectangle rect = {
        _clientOffsetX - borderWidth + Settings::instance()->textLeftMargin(),
        _clientOffsetY - headerHeight,
        _clientScaledWidth + 2*borderWidth - Settings::instance()->textLeftMargin() - Settings::instance()->textRightMargin(),
        headerHeight
    };
    Region clip = XCreateRegion();
    XUnionRectWithRegion(&rect, clip, clip);

    XftDrawSetClip(_xftDraw, clip);

    XftDrawStringUtf8(_xftDraw, &fontColor, _teleWindow->xftFont(),
                      _clientOffsetX - borderWidth + Settings::instance()->textLeftMargin(),
                      _clientOffsetY + Settings::instance()->textYOffset(),
                      (const FcChar8*)_title,
                      strlen(_title)
                     );

    XDestroyRegion(clip);


    drawPreview();
}
static void setup_font_sample(GtkWidget* darea, Antialiasing antialiasing, Hinting hinting)
{
	const char* string1 = "abcfgop AO ";
	const char* string2 = "abcfgop";

	XftColor black, white;
	XRenderColor rendcolor;

	Display* xdisplay = gdk_x11_get_default_xdisplay();

#if GTK_CHECK_VERSION (3, 0, 0)
	Colormap xcolormap = DefaultColormap(xdisplay, 0);
#else
	GdkColormap* colormap = gdk_rgb_get_colormap();
	Colormap xcolormap = GDK_COLORMAP_XCOLORMAP(colormap);
#endif

#if GTK_CHECK_VERSION (3, 0, 0)
	GdkVisual* visual = gdk_visual_get_system ();
#else
	GdkVisual* visual = gdk_colormap_get_visual(colormap);
#endif
	Visual* xvisual = GDK_VISUAL_XVISUAL(visual);

	FcPattern* pattern;
	XftFont* font1;
	XftFont* font2;
	XGlyphInfo extents1 = { 0 };
	XGlyphInfo extents2 = { 0 };
#if !GTK_CHECK_VERSION (3, 0, 0)
	GdkPixmap* pixmap;
#endif
	XftDraw* draw;
	GdkPixbuf* tmp_pixbuf;
	GdkPixbuf* pixbuf;

	int width, height;
	int ascent, descent;

	pattern = FcPatternBuild (NULL,
		FC_FAMILY, FcTypeString, "Serif",
		FC_SLANT, FcTypeInteger, FC_SLANT_ROMAN,
		FC_SIZE, FcTypeDouble, 18.,
		NULL);
	font1 = open_pattern (pattern, antialiasing, hinting);
	FcPatternDestroy (pattern);

	pattern = FcPatternBuild (NULL,
		FC_FAMILY, FcTypeString, "Serif",
		FC_SLANT, FcTypeInteger, FC_SLANT_ITALIC,
		FC_SIZE, FcTypeDouble, 20.,
		NULL);
	font2 = open_pattern (pattern, antialiasing, hinting);
	FcPatternDestroy (pattern);

	ascent = 0;
	descent = 0;
	
	if (font1)
	{
		XftTextExtentsUtf8 (xdisplay, font1, (unsigned char*) string1,
		strlen (string1), &extents1);
		ascent = MAX (ascent, font1->ascent);
		descent = MAX (descent, font1->descent);
	}

	if (font2)
	{
		XftTextExtentsUtf8 (xdisplay, font2, (unsigned char*) string2, strlen (string2), &extents2);
		ascent = MAX (ascent, font2->ascent);
		descent = MAX (descent, font2->descent);
	}

	width = extents1.xOff + extents2.xOff + 4;
	height = ascent + descent + 2;

#if !GTK_CHECK_VERSION (3, 0, 0)
	pixmap = gdk_pixmap_new (NULL, width, height, visual->depth);
#endif

#if GTK_CHECK_VERSION (3, 0, 0)
	draw = XftDrawCreate (xdisplay, GDK_WINDOW_XID (gdk_screen_get_root_window (gdk_screen_get_default ())), xvisual, xcolormap);
#else
	draw = XftDrawCreate (xdisplay, GDK_DRAWABLE_XID (pixmap), xvisual, xcolormap);
#endif

	rendcolor.red = 0;
	rendcolor.green = 0;
	rendcolor.blue = 0;
	rendcolor.alpha = 0xffff;
	
	XftColorAllocValue(xdisplay, xvisual, xcolormap, &rendcolor, &black);

	rendcolor.red = 0xffff;
	rendcolor.green = 0xffff;
	rendcolor.blue = 0xffff;
	rendcolor.alpha = 0xffff;
	
	XftColorAllocValue(xdisplay, xvisual, xcolormap, &rendcolor, &white);
	XftDrawRect(draw, &white, 0, 0, width, height);
	
	if (font1)
	{
		XftDrawStringUtf8(draw, &black, font1, 2, 2 + ascent, (unsigned char*) string1, strlen(string1));
	}
	
	if (font2)
	{
		XftDrawStringUtf8(draw, &black, font2, 2 + extents1.xOff, 2 + ascent, (unsigned char*) string2, strlen(string2));
	}

	XftDrawDestroy(draw);

	if (font1)
	{
		XftFontClose(xdisplay, font1);
	}
	
	if (font2)
	{
		XftFontClose(xdisplay, font2);
	}

#if GTK_CHECK_VERSION (3, 0, 0)
	tmp_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,8, width, height);
#else
	tmp_pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, colormap, 0, 0, 0, 0, width, height);
#endif
	pixbuf = gdk_pixbuf_scale_simple(tmp_pixbuf, 1 * width, 1 * height, GDK_INTERP_TILES);

#if !GTK_CHECK_VERSION (3, 0, 0)
	g_object_unref(pixmap);
#endif
	g_object_unref(tmp_pixbuf);

	g_object_set_data_full(G_OBJECT(darea), "sample-pixbuf", pixbuf, (GDestroyNotify) g_object_unref);

#if GTK_CHECK_VERSION (3, 0, 0)
	gtk_widget_set_size_request  (GTK_WIDGET(darea), width + 2, height + 2);
	g_signal_connect(darea, "draw", G_CALLBACK(sample_draw), NULL);
#else
	g_signal_connect(darea, "size_request", G_CALLBACK(sample_size_request), NULL);
	g_signal_connect(darea, "expose_event", G_CALLBACK(sample_expose), NULL);
#endif
}
Beispiel #28
0
void draw_string(FcChar8 *s, int x, int y) {
	if (x > w * 2 || y > h * 2) return;
	XftDrawStringUtf8(draw, &fg, font, x, y,
	                  (FcChar8 *) s, strlen(s));
}
Beispiel #29
0
bool x11_draw_blocks(CFG* config, XRESOURCES* xres, TEXTBLOCK** blocks){
	unsigned i;
	double current_size;
	XftFont* font = NULL;

	//early exit
	if(!blocks || !blocks[0]){
		return true;
	}

	//draw debug blocks if requested
	if(config->debug_boxes){
		for(i = 0; blocks[i] && blocks[i]->active; i++){
			 XftDrawRect(xres->drawable, &(xres->debug_color), blocks[i]->layout_x, blocks[i]->layout_y, blocks[i]->extents.width, blocks[i]->extents.height);
		}
	}

	//draw boxes only
	if(config->disable_text){
		return true;
	}

	//draw all blocks
	for(i = 0; blocks[i] && blocks[i]->active; i++){
		//load font
		if(!font || (font && current_size != blocks[i]->size)){
			if(font){
				XftFontClose(xres->display, font);
			}
			font = XftFontOpen(xres->display, xres->screen,
					XFT_FAMILY, XftTypeString, config->font_name,
					XFT_PIXEL_SIZE, XftTypeDouble, blocks[i]->size,
					NULL
			);
			current_size = blocks[i]->size;
			if(!font){
				fprintf(stderr, "Failed to load block font (%s, %d)\n", config->font_name, (int)current_size);
				return false;
			}
		}

		//draw text
		errlog(config, LOG_DEBUG, "Drawing block %d (%s) at layoutcoords %d|%d size %d\n", i, blocks[i]->text,
				blocks[i]->layout_x + blocks[i]->extents.x,
				blocks[i]->layout_y + blocks[i]->extents.y,
				(int)blocks[i]->size);

		XftDrawStringUtf8(xres->drawable,
				&(xres->text_color),
				font,
				blocks[i]->layout_x + blocks[i]->extents.x,
				blocks[i]->layout_y + blocks[i]->extents.y,
				(FcChar8*)blocks[i]->text,
				strlen(blocks[i]->text));
	}

	//clean up the mess
	if(font){
		XftFontClose(xres->display, font);
	}

	return true;
}
Beispiel #30
-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);
    }
}