예제 #1
0
파일: xftdpy.c 프로젝트: dikerex/theqvd
void
XftDefaultSubstitute (Display *dpy, int screen, XftPattern *pattern)
{
    XftValue	v;
    double	size;
    double	scale;

    if (XftPatternGet (pattern, XFT_STYLE, 0, &v) == XftResultNoMatch)
    {
	if (XftPatternGet (pattern, XFT_WEIGHT, 0, &v) == XftResultNoMatch )
	{
	    XftPatternAddInteger (pattern, XFT_WEIGHT, XFT_WEIGHT_MEDIUM);
	}
	if (XftPatternGet (pattern, XFT_SLANT, 0, &v) == XftResultNoMatch)
	{
	    XftPatternAddInteger (pattern, XFT_SLANT, XFT_SLANT_ROMAN);
	}
    }
    if (XftPatternGet (pattern, XFT_ENCODING, 0, &v) == XftResultNoMatch)
	XftPatternAddString (pattern, XFT_ENCODING, "iso8859-1");
    if (XftPatternGet (pattern, XFT_RENDER, 0, &v) == XftResultNoMatch)
    {
	XftPatternAddBool (pattern, XFT_RENDER,
			   XftDefaultGetBool (dpy, XFT_RENDER, screen, 
					      XftDefaultHasRender (dpy)));
    }
    if (XftPatternGet (pattern, XFT_CORE, 0, &v) == XftResultNoMatch)
    {
	XftPatternAddBool (pattern, XFT_CORE,
			   XftDefaultGetBool (dpy, XFT_CORE, screen, 
					      !XftDefaultHasRender (dpy)));
    }
    if (XftPatternGet (pattern, XFT_ANTIALIAS, 0, &v) == XftResultNoMatch)
    {
	XftPatternAddBool (pattern, XFT_ANTIALIAS,
			   XftDefaultGetBool (dpy, XFT_ANTIALIAS, screen,
					      True));
    }
    if (XftPatternGet (pattern, XFT_RGBA, 0, &v) == XftResultNoMatch)
    {
	int	subpixel = XFT_RGBA_NONE;
#if RENDER_MAJOR > 0 || RENDER_MINOR >= 6
	int render_order = XRenderQuerySubpixelOrder (dpy, screen);
	switch (render_order) {
	default:
	case SubPixelUnknown:		subpixel = XFT_RGBA_NONE; break;
	case SubPixelHorizontalRGB:	subpixel = XFT_RGBA_RGB; break;
	case SubPixelHorizontalBGR:	subpixel = XFT_RGBA_BGR; break;
	case SubPixelVerticalRGB:	subpixel = XFT_RGBA_VRGB; break;
	case SubPixelVerticalBGR:	subpixel = XFT_RGBA_VBGR; break;
	case SubPixelNone:		subpixel = XFT_RGBA_NONE; break;
	}
#endif
	XftPatternAddInteger (pattern, XFT_RGBA,
			      XftDefaultGetInteger (dpy, XFT_RGBA, screen, 
						    subpixel));
    }
    if (XftPatternGet (pattern, XFT_MINSPACE, 0, &v) == XftResultNoMatch)
    {
	XftPatternAddBool (pattern, XFT_MINSPACE,
			   XftDefaultGetBool (dpy, XFT_MINSPACE, screen,
					      False));
    }
    if (XftPatternGet (pattern, XFT_PIXEL_SIZE, 0, &v) == XftResultNoMatch)
    {
	int	pixels, mm;
	double	dpi;

	if (XftPatternGet (pattern, XFT_SIZE, 0, &v) != XftResultMatch)
	{
	    size = 12.0;
	    XftPatternAddDouble (pattern, XFT_SIZE, size);
	}
	else
	{
	    switch (v.type) {
	    case XftTypeInteger:
		size = (double) v.u.i;
		break;
	    case XftTypeDouble:
		size = v.u.d;
		break;
	    default:
		size = 12.0;
		break;
	    }
	}
	scale = XftDefaultGetDouble (dpy, XFT_SCALE, screen, 1.0);
	size *= scale;
	pixels = DisplayHeight (dpy, screen);
	mm = DisplayHeightMM (dpy, screen);
	dpi = (((double) DisplayHeight (dpy, screen) * 25.4) / 
	       (double) DisplayHeightMM (dpy, screen));
	dpi = XftDefaultGetDouble (dpy, XFT_DPI, screen, dpi);
	size = size * dpi / 72.0;
	XftPatternAddDouble (pattern, XFT_PIXEL_SIZE, size);
    }
}
예제 #2
0
_X_HIDDEN XftDisplayInfo *
_XftDisplayInfoGet (Display *dpy, FcBool createIfNecessary)
{
    XftDisplayInfo	*info, **prev;
    XRenderPictFormat	pf;
    int			i;
    int			event_base, error_base;

    for (prev = &_XftDisplayInfo; (info = *prev); prev = &(*prev)->next)
    {
	if (info->display == dpy)
	{
	    /*
	     * MRU the list
	     */
	    if (prev != &_XftDisplayInfo)
	    {
		*prev = info->next;
		info->next = _XftDisplayInfo;
		_XftDisplayInfo = info;
	    }
	    return info;
	}
    }
    if (!createIfNecessary)
	return NULL;

    info = (XftDisplayInfo *) malloc (sizeof (XftDisplayInfo));
    if (!info)
	goto bail0;
    info->codes = XAddExtension (dpy);
    if (!info->codes)
	goto bail1;
    (void) XESetCloseDisplay (dpy, info->codes->extension, _XftCloseDisplay);

    info->display = dpy;
    info->defaults = NULL;
    info->solidFormat = NULL;
    info->hasRender = (XRenderQueryExtension (dpy, &event_base, &error_base) &&
		       (XRenderFindVisualFormat (dpy, DefaultVisual (dpy, DefaultScreen (dpy))) != NULL));
    info->use_free_glyphs = FcTrue;
    if (info->hasRender)
    {
	int major, minor;
	XRenderQueryVersion (dpy, &major, &minor);
	if (major < 0 || (major == 0 && minor <= 2))
	    info->use_free_glyphs = FcFalse;

	pf.type = PictTypeDirect;
	pf.depth = 32;
	pf.direct.redMask = 0xff;
	pf.direct.greenMask = 0xff;
	pf.direct.blueMask = 0xff;
	pf.direct.alphaMask = 0xff;
	info->solidFormat = XRenderFindFormat (dpy,
					       (PictFormatType|
						PictFormatDepth|
						PictFormatRedMask|
						PictFormatGreenMask|
						PictFormatBlueMask|
						PictFormatAlphaMask),
					       &pf,
					       0);
    }
    if (XftDebug () & XFT_DBG_RENDER)
    {
	Visual		    *visual = DefaultVisual (dpy, DefaultScreen (dpy));
	XRenderPictFormat   *format = XRenderFindVisualFormat (dpy, visual);

	printf ("XftDisplayInfoGet Default visual 0x%x ",
		(int) visual->visualid);
	if (format)
	{
	    if (format->type == PictTypeDirect)
	    {
		printf ("format %d,%d,%d,%d\n",
			format->direct.alpha,
			format->direct.red,
			format->direct.green,
			format->direct.blue);
	    }
	    else
	    {
		printf ("format indexed\n");
	    }
	}
	else
	    printf ("No Render format for default visual\n");

	printf ("XftDisplayInfoGet initialized, hasRender set to \"%s\"\n",
		info->hasRender ? "True" : "False");
    }
    for (i = 0; i < XFT_NUM_SOLID_COLOR; i++)
    {
	info->colors[i].screen = -1;
	info->colors[i].pict = 0;
    }
    info->fonts = NULL;

    info->next = _XftDisplayInfo;
    _XftDisplayInfo = info;

    info->glyph_memory = 0;
    info->max_glyph_memory = XftDefaultGetInteger (dpy,
						   XFT_MAX_GLYPH_MEMORY, 0,
						   XFT_DPY_MAX_GLYPH_MEMORY);
    if (XftDebug () & XFT_DBG_CACHE)
	printf ("global max cache memory %ld\n", info->max_glyph_memory);


    info->num_unref_fonts = 0;
    info->max_unref_fonts = XftDefaultGetInteger (dpy,
						  XFT_MAX_UNREF_FONTS, 0,
						  XFT_DPY_MAX_UNREF_FONTS);
    if (XftDebug() & XFT_DBG_CACHE)
	printf ("global max unref fonts %d\n", info->max_unref_fonts);

    memset (info->fontHash, '\0', sizeof (XftFont *) * XFT_NUM_FONT_HASH);
    return info;

bail1:
    free (info);
bail0:
    if (XftDebug () & XFT_DBG_RENDER)
    {
	printf ("XftDisplayInfoGet failed to initialize, Xft unhappy\n");
    }
    return NULL;
}