示例#1
0
文件: main.c 项目: notadecent/uTox
static void initfonts(void)
{
    FcResult result;
    FcPattern *pat = FcPatternCreate();
    FcPatternAddString(pat, FC_FAMILY, (uint8_t*)"Roboto");
    FcConfigSubstitute(0, pat, FcMatchPattern);
    FcDefaultSubstitute(pat);
    fs = FcFontSort(NULL, pat, 0, &charset, &result);

    FcPatternDestroy(pat);

     #define F(x) (x * SCALE / 2.0)
    font[FONT_TEXT][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(12.0), NULL);

    font[FONT_TITLE][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(12.0), XFT_WEIGHT, XftTypeInteger, FC_WEIGHT_BOLD, NULL);

    font[FONT_SELF_NAME][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(14.0), XFT_WEIGHT, XftTypeInteger, FC_WEIGHT_BOLD, NULL);
    font[FONT_STATUS][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(11.0), NULL);

    font[FONT_LIST_NAME][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(12.0), NULL);

    font[FONT_MSG][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(11.0), XFT_WEIGHT, XftTypeInteger, FC_WEIGHT_LIGHT, NULL);
    font[FONT_MSG_NAME][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(10.0), XFT_WEIGHT, XftTypeInteger, FC_WEIGHT_LIGHT, NULL);
    font[FONT_MISC][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(10.0), NULL);
    font[FONT_MSG_LINK][0] = font[FONT_MSG][0];
    #undef F
}
示例#2
0
void
render_init(void)
{
	font = XftFontOpen(display, screen,
	    XFT_FAMILY, XftTypeString, FONT_NAME,
	    XFT_SIZE, XftTypeInteger, FONT_SIZE,
	    NULL);
	if (!XftColorAllocName(display, XDefaultVisual(display, screen),
		DefaultColormap(display, screen), TouchCross, &cross)) {
		fprintf(stderr, "Cannot get color");
		exit(2);
	}
	if (!XftColorAllocName(display, XDefaultVisual(display, screen),
		DefaultColormap(display, screen), PromptText, &promptColor)) {
		fprintf(stderr, "Cannot get color");
		exit(2);
	}
	if (!XftColorAllocName(display, XDefaultVisual(display, screen),
		DefaultColormap(display, screen), Background, &bg)) {
		fprintf(stderr, "Cannot get bg color");
		exit(2);
	}
	if (!XftColorAllocName(display, XDefaultVisual(display, screen),
		DefaultColormap(display, screen), Error, &errorColor)) {
		fprintf(stderr, "Cannot get color");
		exit(2);
	}
	draw = XftDrawCreate(display, win, DefaultVisual(display, screen),
	    DefaultColormap(display, screen));
}
示例#3
0
static void MakeDefaultFont(winlist_t *win)
{
    int font_size = win->font_size;

    if (font_size <= 0)
	font_size = gui->default_fontsize;

    int i;
    double chk_size;
    /* 找找看有沒有相同的 size */
    for (i = 0 ; i < gui->num_fonts; i++)
    {
	/* 有的話,就結束 */
	if (FcPatternGetDouble(gui->xftfonts[i]->pattern, XFT_PIXEL_SIZE, 0, &chk_size) == FcResultMatch && (int)chk_size == font_size)
	    return;
    }

    gui->num_fonts ++;
    if (gui->num_fonts == 1)
    {
	gui->xftfonts = (XftFont **)oxim_malloc(sizeof(XftFont *), False);
    }
    else
    {
	gui->xftfonts = (XftFont **)oxim_realloc(gui->xftfonts, gui->num_fonts * sizeof(XftFont *));
    }
    gui->xftfonts[gui->num_fonts -1] = XftFontOpen(gui->display, gui->screen,
	XFT_FAMILY, XftTypeString, oxim_get_config(DefaultFontName),
	XFT_PIXEL_SIZE, XftTypeDouble, (double)font_size,
	NULL);
}
示例#4
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);
}
示例#5
0
void XImlib2Caption::createFont()
{
    XDesktopContainer * xContainer =
        dynamic_cast<XDesktopContainer *>(AbstractImage::container);
    DesktopIconConfig * dIconConfig =
        dynamic_cast<DesktopIconConfig *>(AbstractImage::iconConfig);

    font = XftFontOpen( xContainer->getDisplay(),
                        DefaultScreen( xContainer->getDisplay()), 
                        XFT_FAMILY,
                        XftTypeString,
                        dIconConfig->getFont().c_str(),
                        XFT_SIZE,
                        XftTypeDouble,
                        (double)dIconConfig->getFontSize(), 
                        XFT_WEIGHT, XftTypeInteger, boldVal,
                        NULL );
    
    XColor  screen, exact;
    if (!XAllocNamedColor (xContainer->getDisplay(), cmap, (char*)dIconConfig->getFontColor().c_str(), &screen, &exact))
        cout << "BAD COLORS!!!\n";
    
    XftColorAllocName(xContainer->getDisplay(), visual, cmap,
                      (char*)dIconConfig->getFontColor().c_str(), &fontColor );

    if (shadowOn)
        XftColorAllocName(xContainer->getDisplay(), visual, cmap,
                          (char*)shadowColor.c_str(), &shadowFontColor );
}
示例#6
0
文件: window.c 项目: muennich/sxiv
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;
}
示例#7
0
Error FontX11::load(const String& p_name,float p_size,unsigned int p_flags) {
	
	if (font) {
		XftFontInfoDestroy( x11_display, font_info );
		XftFontClose( x11_display, font );
		
		font=NULL;
	}	

	name="";
	size=0;
	flags=0;
	
	font = XftFontOpen (x11_display, DefaultScreen(x11_display),XFT_FAMILY, XftTypeString, p_name.utf8().get_data(),
		                    XFT_SIZE, XftTypeDouble, p_size,NULL);	
		
	if (!font) {
		
		return ERR_UNSUPPORTED;
	}
	
	font_info = XftFontInfoCreate( x11_display, font->pattern );

	flags=p_flags;
	name=p_name;
	size=p_size;
	return OK;
}
示例#8
0
int
createWin(XDataStr *data)
{
    u_long attributeMask;
    XSetWindowAttributes attribute;
    Window w;
    Display *display = data->display;
    int screen = DefaultScreen(display);
    XGCValues gc_val;
    Screen *s;

    attribute.background_pixel = WhitePixel(display, screen);
    attribute.border_pixel = WhitePixel(display, screen);
    attribute.bit_gravity = NorthWestGravity;
    attribute.event_mask = ButtonPressMask|ButtonReleaseMask|KeyPressMask|
        ExposureMask;

    attributeMask =
        CWBorderPixel |
        CWBackPixel |
        CWEventMask |
        CWBitGravity;
    s = ScreenOfDisplay(data->display, screen);

    w = XCreateWindow(display, RootWindow(display, screen), 0, 0,
            DisplayWidth(display, screen)/2, 150,
            0, DefaultDepth(display, screen), InputOutput,
            DefaultVisual(display, screen), attributeMask, &attribute);

    data->font = XftFontOpen(display, screen,
            XFT_FAMILY, XftTypeString, "mono",
            XFT_SIZE, XftTypeInteger, 16,
            NULL);
    if (!XftColorAllocName(display, XDefaultVisual(display, screen),
                DefaultColormap(display, screen), "red4", &data->color)) {
        fprintf(stderr, "cannot get color");
        return -1;
    }
    if (!XftColorAllocName(display, XDefaultVisual(display, screen),
                DefaultColormap(display, screen), "linen", &data->bg)) {
        fprintf(stderr, "cannot get bg color");
        return -1;
    }
    data->draw = XftDrawCreate(display, w, DefaultVisual(display, screen),
            DefaultColormap(display, screen));
    gc_val.foreground = BlackPixel(display, screen);
    gc_val.background = WhitePixel(display, screen);
    data->gc = XCreateGC (display, w, GCForeground|GCBackground,
            &gc_val);

    data->win = w;
    return 0;
}
示例#9
0
XFontStruct*
#endif
JXFontManager::GetNewFont
	(
	const JCharacter*	name,
	const JCharacter*	charSet,
	const JSize			size,
	const JFontStyle&	style
	)
	const
{
#ifdef _J_USE_XFT
	double raw_size = size;
	XftFont* font = XftFontOpen(*itsDisplay, DefaultScreen((Display*)*itsDisplay),
									XFT_FAMILY, XftTypeString, name,
									XFT_SIZE, XftTypeDouble, raw_size,
									XFT_WEIGHT, XftTypeInteger, style.bold ? XFT_WEIGHT_BOLD : XFT_WEIGHT_MEDIUM,
									XFT_SLANT, XftTypeInteger, style.italic ? XFT_SLANT_ITALIC : XFT_SLANT_ROMAN, 0);
	return font;
#else
	const JCharacter* italicStr = kObliqueStr;	// try oblique before italic
	JBoolean iso                = JStringEmpty(charSet);

	XFontStruct* xfont = NULL;
	while (1)
		{
		JString xFontStr = BuildFontName(name, charSet, size, style, italicStr, iso);
		xfont            = XLoadQueryFont(*itsDisplay, xFontStr);
		if (xfont != NULL)
			{
			break;
			}

		if (strcmp(italicStr, kObliqueStr) == 0 && style.italic)
			{
			italicStr = kItalicStr;
			}
		else if (iso)
			{
			iso       = kJFalse;
			italicStr = kObliqueStr;
			}
		else
			{
			break;	// give up and return NULL
			}
		}

	return xfont;
#endif
}
示例#10
0
static XftFont *
GetFont(
    UnixFtFont *fontPtr,
    FcChar32 ucs4)
{
    int i;

    if (ucs4) {
	for (i = 0; i < fontPtr->nfaces; i++) {
	    FcCharSet *charset = fontPtr->faces[i].charset;
	    if (charset && FcCharSetHasChar(charset, ucs4)) {
		break;
	    }
	}
	if (i == fontPtr->nfaces) {
	    i = 0;
	}
    } else {
	i = 0;
    }
    if (!fontPtr->faces[i].ftFont) {
	FcPattern *pat = FcFontRenderPrepare(0,
	    fontPtr->pattern, fontPtr->faces[i].source);
	XftFont *ftFont = XftFontOpenPattern(fontPtr->display, pat);

	if (!ftFont) {
	    /*
	     * The previous call to XftFontOpenPattern() should not fail,
	     * but sometimes does anyway.  Usual cause appears to be
	     * a misconfigured fontconfig installation; see [Bug 1090382].
	     * Try a fallback:
	     */
	    ftFont = XftFontOpen(fontPtr->display, fontPtr->screen,
			FC_FAMILY, FcTypeString, "sans",
			FC_SIZE, FcTypeDouble, 12.0,
			NULL);
	}
	if (!ftFont) {
	    /*
	     * The previous call should definitely not fail.
	     * Impossible to proceed at this point.
	     */
	    Tcl_Panic("Cannot find a usable font.");
	}

	fontPtr->faces[i].ftFont = ftFont;
    }
    return fontPtr->faces[i].ftFont;
}
示例#11
0
文件: font.cpp 项目: Chun-Feng/pcmanx
XftFont* CFont::CreateXftFont( string name, int size, bool anti_alias )
{
	Display *display = gdk_x11_get_default_xdisplay();
	int screen = gdk_x11_get_default_screen();

	XftFont* font = XftFontOpen (display, screen,
					FC_FAMILY, FcTypeString, name.c_str(),
					FC_SIZE, FcTypeDouble, (double)size,
					FC_WEIGHT, FcTypeInteger, FC_WEIGHT_MEDIUM,
					FC_ANTIALIAS, FcTypeBool, anti_alias,
					XFT_CORE, FcTypeBool, False,
					NULL);

	return font;
}
示例#12
0
void
xwindow_font_load(XWindow *xw) {
  XFont *f = xw->font;
  f->type = xwindow_font_type( f->type );
  switch(f->type) {
  case XFONT_TYPE_SOFTWARE:
    break;
  case XFONT_TYPE_CORE:
    {
      if(f->font_core) {
        return;
      }
      char *s;
      asprintf(&s, "-*-%s-%s-%s-*-*-%d-*-*-*-*-*-*-*",
               f->family, 
               xfont_core_weight(f->weight), 
               xfont_core_slant(f->slant),
               (int)f->size);
      f->font_core = XLoadQueryFont(DISPLAY(xw), s);
      XSetFont(DISPLAY(xw), xw->gc, f->font_core->fid);
    }
    break;
  case XFONT_TYPE_XFT:
#ifdef HAVE_XFT
    if(f->font_xft) {
      return;
    }
    f->font_xft = XftFontOpen(DISPLAY(xw),
                              SCREEN(xw),
                              XFT_FAMILY,    XftTypeString,  f->family,
                              XFT_SIZE,      XftTypeDouble,  f->size,
                              XFT_STYLE,     XftTypeString,  xfont_style(f),
                              XFT_ANTIALIAS, XftTypeBool,    f->antialias,
                              NULL);
    if(!f->font_xft) {
      fprintf(stderr, "Warning: Downgrading from XFT to X11/Core Font\n");
      f->type = XFONT_TYPE_CORE;
      xwindow_font_load( xw );
    }
#else 
    fprintf(stderr, "SAC not compiled with XFT Support\n");    
#endif /* HAVE_XFT */
    break;
  default:
    break;
  }
}
示例#13
0
文件: x11.c 项目: cbdevnet/xecho
bool x11_blocks_resize(XRESOURCES* xres, CFG* config, TEXTBLOCK** blocks, XGlyphInfo* bounding_box, double size){
	XftFont* font = NULL;
	unsigned bounding_width = 0, bounding_height = 0;
	unsigned i;

	//load font with at supplied size
	font=XftFontOpen(xres->display, xres->screen,
			XFT_FAMILY, XftTypeString, config->font_name,
			XFT_PIXEL_SIZE, XftTypeDouble, size,
			NULL
	);

	if(!font){
		fprintf(stderr, "Could not load font\n");
		return false;
	}

	//fprintf(stderr, "Block \"%s\" extents: width %d, height %d, x %d, y %d, xOff %d, yOff %d\n",
	//		block->text, block->extents.width, block->extents.height, block->extents.x, block->extents.y,
	//		block->extents.xOff, block->extents.yOff);

	//bounds calculation
	for(i = 0; blocks[i] && blocks[i]->active; i++){
		//update only not yet calculated blocks
		if(!(blocks[i]->calculated)){
			XftTextExtentsUtf8(xres->display, font, (FcChar8*)blocks[i]->text, strlen(blocks[i]->text), &(blocks[i]->extents));
			errlog(config, LOG_DEBUG, "Recalculated block %d (%s) extents: %dx%d\n", i, blocks[i]->text, blocks[i]->extents.width, blocks[i]->extents.height);
			blocks[i]->size = size;
		}

		//calculate bounding box over all
		bounding_height += blocks[i]->extents.height;
		if(blocks[i]->extents.width > bounding_width){
			bounding_width = blocks[i]->extents.width;
		}
	}

	if(bounding_box){
		bounding_box->width = bounding_width;
		bounding_box->height = bounding_height;
	}

	XftFontClose(xres->display, font);
	return true;
}
示例#14
0
文件: x11.c 项目: cbdevnet/xecho
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;
}
示例#15
0
static XftFont *
GetFont(
    UnixFtFont *fontPtr,
    FcChar32 ucs4,
    double angle)
{
    int i;

    if (ucs4) {
	for (i = 0; i < fontPtr->nfaces; i++) {
	    FcCharSet *charset = fontPtr->faces[i].charset;

	    if (charset && FcCharSetHasChar(charset, ucs4)) {
		break;
	    }
	}
	if (i == fontPtr->nfaces) {
	    i = 0;
	}
    } else {
	i = 0;
    }
    if ((angle == 0.0 && !fontPtr->faces[i].ft0Font) || (angle != 0.0 &&
	    (!fontPtr->faces[i].ftFont || fontPtr->faces[i].angle != angle))){
	FcPattern *pat = FcFontRenderPrepare(0, fontPtr->pattern,
		fontPtr->faces[i].source);
	double s = sin(angle*PI/180.0), c = cos(angle*PI/180.0);
	FcMatrix mat;
	XftFont *ftFont;

	/*
	 * Initialize the matrix manually so this can compile with HP-UX cc
	 * (which does not allow non-constant structure initializers). [Bug
	 * 2978410]
	 */

	mat.xx = mat.yy = c;
	mat.xy = -(mat.yx = s);

	if (angle != 0.0) {
	    FcPatternAddMatrix(pat, FC_MATRIX, &mat);
	}
	ftFont = XftFontOpenPattern(fontPtr->display, pat);
	if (!ftFont) {
	    /*
	     * The previous call to XftFontOpenPattern() should not fail, but
	     * sometimes does anyway. Usual cause appears to be a
	     * misconfigured fontconfig installation; see [Bug 1090382]. Try a
	     * fallback:
	     */

	    ftFont = XftFontOpen(fontPtr->display, fontPtr->screen,
		    FC_FAMILY, FcTypeString, "sans",
		    FC_SIZE, FcTypeDouble, 12.0,
		    FC_MATRIX, FcTypeMatrix, &mat,
		    NULL);
	}
	if (!ftFont) {
	    /*
	     * The previous call should definitely not fail. Impossible to
	     * proceed at this point.
	     */

	    Tcl_Panic("Cannot find a usable font");
	}

	if (angle == 0.0) {
	    fontPtr->faces[i].ft0Font = ftFont;
	} else {
	    if (fontPtr->faces[i].ftFont) {
		XftFontClose(fontPtr->display, fontPtr->faces[i].ftFont);
	    }
	    fontPtr->faces[i].ftFont = ftFont;
	    fontPtr->faces[i].angle = angle;
	}
    }
    return (angle==0.0? fontPtr->faces[i].ft0Font : fontPtr->faces[i].ftFont);
}
示例#16
0
bool ui_init()
{
	movelist_init();

	/* window, drawable stuff */
	ui_display = XOpenDisplay(getenv("DISPLAY"));
	if (NULL == ui_display) {
		ui_close();
		return false;
	}

	ui_rootwindow = DefaultRootWindow(ui_display);
	if (0 == ui_rootwindow) {
		ui_close();
		return false;
	}

	ui_screenwidth = DisplayWidth(ui_display, DefaultScreen(ui_display));
	ui_screenheight = DisplayHeight(ui_display, DefaultScreen(ui_display));
	int depth = DisplayPlanes(ui_display, DefaultScreen(ui_display));

	LOG( INFO, "Screen size: %dx%d, Depth: %d", ui_screenwidth, ui_screenheight, depth );

	ui_backbuf = XCreatePixmap( ui_display, ui_rootwindow,
			ui_screenwidth, ui_screenheight, depth );

	if ( ui_backbuf == 0 ) {
		ui_close();
		return false;
	}

	ui_gcontext = XCreateGC(ui_display, ui_backbuf, 0, NULL);
	if (0 == ui_gcontext) {
		ui_close();
		return false;
	}

	ui_xftdraw = XftDrawCreate(ui_display, ui_backbuf, DefaultVisual(ui_display, 0), DefaultColormap(ui_display, 0));
	if (NULL == ui_xftdraw) {
		ui_close();
		return false;
	}

	/* load fonts */
	ui_piecefont = XftFontOpen(ui_display, DefaultScreen(ui_display),
		XFT_FAMILY, XftTypeString, UI_FONT_FAMILY_PIECES,
		XFT_SIZE, XftTypeDouble, UI_FONT_SIZE_PIECES,
		NULL);

	if (NULL == ui_piecefont) {
		ui_close();
		return false;
	}

	ui_infofont = XftFontOpen(ui_display, DefaultScreen(ui_display),
		XFT_FAMILY, XftTypeString, UI_FONT_FAMILY_TEXT,
		XFT_SIZE, XftTypeDouble, UI_FONT_SIZE_INFO,
		NULL);

	if (NULL == ui_infofont) {
		ui_close();
		return false;
	}

	ui_namefont = XftFontOpen(ui_display, DefaultScreen(ui_display),
		XFT_FAMILY, XftTypeString, UI_FONT_FAMILY_TEXT,
		XFT_SIZE, XftTypeDouble, UI_FONT_SIZE_NAME,
		NULL);

	if (NULL == ui_namefont) {
		ui_close();
		return false;
	}

	ui_coordfont = XftFontOpen(ui_display, DefaultScreen(ui_display),
		XFT_FAMILY, XftTypeString, UI_FONT_FAMILY_TEXT,
		XFT_SIZE, XftTypeDouble, UI_FONT_SIZE_COORD,
		XFT_WEIGHT, XftTypeInteger, XFT_WEIGHT_BOLD,
		NULL);

	if (NULL == ui_coordfont) {
		ui_close();
		return false;
	}

	ui_infofontchwidth = ui_info_font_normal_char_width();

	/* create colors */
	XRenderColor whiteSquareColor;
	whiteSquareColor.red = (0xffff * ((UI_COL_WHITE_SQUARE >> 16) & 0xff)) / 0xff;
	whiteSquareColor.green = (0xffff * ((UI_COL_WHITE_SQUARE >> 8) & 0xff)) / 0xff;
	whiteSquareColor.blue = (0xffff * (UI_COL_WHITE_SQUARE & 0xff)) / 0xff;
	whiteSquareColor.alpha = 0xffff;

	if (!XftColorAllocValue(ui_display, DefaultVisual(ui_display, 0), DefaultColormap(ui_display, 0),
			&whiteSquareColor, &ui_squarecolorwhite)) {
		ui_squarecolorwhiteinit = false;
		ui_close();
		return false;
	}
	ui_squarecolorwhiteinit = true;

	XRenderColor blackSquareColor;
	blackSquareColor.red = (0xffff * ((UI_COL_BLACK_SQUARE >> 16) & 0xff)) / 0xff;
	blackSquareColor.green = (0xffff * ((UI_COL_BLACK_SQUARE >> 8) & 0xff)) / 0xff;
	blackSquareColor.blue = (0xffff * (UI_COL_BLACK_SQUARE & 0xff)) / 0xff;
	blackSquareColor.alpha = 0xffff;

	if (!XftColorAllocValue(ui_display, DefaultVisual(ui_display, 0), DefaultColormap(ui_display, 0),
			&blackSquareColor, &ui_squarecolorblack)) {
		ui_squarecolorblackinit = false;
		ui_close();
		return false;
	}
	ui_squarecolorblackinit = true;

	XRenderColor white;
	white.red = 0xffff;
	white.green = 0xffff;
	white.blue = 0xffff;
	white.alpha = 0xffff;

	if (!XftColorAllocValue(ui_display, DefaultVisual(ui_display, 0), DefaultColormap(ui_display, 0), &white, &ui_piececolorwhite)) {
		ui_piececolorwhiteinit = false;
		ui_close();
		return false;
	}
	ui_piececolorwhiteinit = true;

	XRenderColor black;
	black.red = 0;
	black.green = 0;
	black.blue = 0;
	black.alpha = 0xffff;

	if (!XftColorAllocValue(ui_display, DefaultVisual(ui_display, 0), DefaultColormap(ui_display, 0), &black, &ui_piececolorblack)) {
		ui_piececolorblackinit = false;
		ui_close();
		return false;
	}
	ui_piececolorblackinit = true;

	XRenderColor infocolor;
	infocolor.red = 0x6666;
	infocolor.green = 0x6666;
	infocolor.blue = 0x6666;
	infocolor.alpha = 0xffff;

	if (!XftColorAllocValue(ui_display, DefaultVisual(ui_display, 0), DefaultColormap(ui_display, 0), &infocolor, &ui_infocolor)) {
		ui_infocolorinit = false;
		ui_close();
		return false;
	}
	ui_infocolorinit = true;

	XRenderColor infocolortag;
	infocolortag.red = 0x4444;
	infocolortag.green = 0x4444;
	infocolortag.blue = 0x4444;
	infocolortag.alpha = 0xffff;

	if (!XftColorAllocValue(ui_display, DefaultVisual(ui_display, 0),
			DefaultColormap(ui_display, 0), &infocolortag, &ui_infocolortag)) {
		ui_infocolortaginit = false;
		ui_close();
		return false;
	}
	ui_infocolortaginit = true;

	/* start with board on the left */
	ui_board_pos_x = UI_POS_BOARD_X_LEFT;

	return true;
}