View | Details | Raw Unified | Return to bug 118556
Collapse All | Expand All

(-)draw.c-dist (-38 / +56 lines)
Lines 4836-4894 xft_getdraw(Drawable drawable) Link Here
4836
	return NULL; /* should not happen */
4836
	return NULL; /* should not happen */
4837
}
4837
}
4838
4838
4839
struct xft_font_cache {
4840
	char *name;
4841
	int size;
4842
	XftFont *font;
4843
	struct xft_font_cache *next;
4844
};
4845
4846
static struct xft_font_cache *xft_fonts = NULL;
4847
4839
static 
4848
static 
4840
XftFont *
4849
XftFont *
4841
xft_setfont(xfontarg, csize, registry)
4850
xft_setfont(xfont, csize, registry)
4842
	char *xfontarg;
4851
	char *xfont;
4843
	int csize;
4852
	int csize;
4844
	char *registry;
4853
	char *registry;
4845
{
4854
{
4846
	char *xfont;
4847
	static XftFont *last_xftfont;
4848
	static char lastfont[100];
4849
	static int lastsize = 0;
4850
	XftFont *xftfont;
4855
	XftFont *xftfont;
4851
	char *p, *p2;
4856
	char *p;
4852
	char style[100];
4853
	char font[100];
4857
	char font[100];
4858
	char fontname[200];
4859
	char *style = "";
4854
	int stlen;
4860
	int stlen;
4855
4861
	struct xft_font_cache *cache;
4856
	bzero(style, sizeof(style));
4857
	bzero(font, sizeof(font));
4858
4859
	xfont = strdup(xfontarg);
4860
	if (!xfont)
4861
		return NULL;
4862
4863
	if (!strcmp(xfont, lastfont) && lastsize == csize) {
4864
		free(xfont);
4865
		return last_xftfont;
4866
	}
4867
4862
4868
	/*
4863
	/*
4869
	 * if xfont contains "-", we believe this is a conventional xfont name 
4864
	 * if xfont contains "-", we believe this is a conventional xfont name 
4870
	 * and try to convert it for xft
4865
	 * and try to convert it for xft
4871
	 */
4866
	 */
4872
	if ((p = strchr(xfont, '-')) != NULL) {
4867
	if ((p = strchr(xfont, '-')) != NULL) {
4873
		*p++ = 0;
4868
		stlen = p - xfont;
4874
		strlcpy(font, xfont, sizeof(font));
4869
		if (stlen >= sizeof(font))
4870
			stlen = sizeof(font) - 1;
4871
		memcpy(font, xfont, stlen);
4872
		font[stlen] = 0;
4873
		p++;
4875
		if (strncmp(p, "bold-i", 6) == 0)
4874
		if (strncmp(p, "bold-i", 6) == 0)
4876
			strlcpy(style, "Bold Italic", sizeof(style));
4875
			style = "Bold Italic";
4877
		else if (strncmp(p, "bold-", 5) == 0)
4876
		else if (strncmp(p, "bold-", 5) == 0)
4878
			strlcpy(style, "Bold", sizeof(style));
4877
			style = "Bold";
4879
		else if ((p = strchr(p, '-')) != NULL && p[1] == 'i')
4878
		else if ((p = strchr(p, '-')) != NULL && p[1] == 'i')
4880
			strlcpy(style, "Italic", sizeof(style));
4879
			style = "Italic";
4881
	} else if ((p = strchr(xfont, ':')) == NULL)
4880
	} else if ((p = strchr(xfont, ':')) == NULL)
4882
		strlcpy(font, xfont, sizeof(font));
4881
		strlcpy(font, xfont, sizeof(font));
4883
	else {
4882
	else {
4884
		p2 = p +1;
4883
		style = p + 1;
4885
		/* allow to use ":style=" syntax */ 
4884
		/* allow to use ":style=" syntax */ 
4886
		if ((strstr(p2, "style=") != NULL) || (strstr(p2, "STYLE=") != NULL)) 
4885
		if ((strstr(style, "style=") != NULL) || (strstr(style, "STYLE=") != NULL)) 
4887
			p2 += 6;
4886
			style += 6;
4888
		*p = '\0';
4887
		stlen = p - xfont;
4889
		strlcpy(font, xfont, sizeof(font));
4888
		if (stlen >= sizeof(font))
4890
		strlcpy(style, p2, sizeof(style));
4889
			stlen = sizeof(font) - 1;
4890
		memcpy(font, xfont, stlen);
4891
		font[stlen] = 0;
4892
	}
4893
	snprintf(fontname, sizeof(fontname), "%s:%s", font, style);
4894
	for (cache = xft_fonts; cache; cache = cache->next) {
4895
		if (!strcmp(fontname, cache->name) && csize == cache->size)
4896
			return cache->font;
4891
	}
4897
	}
4898
4892
	if (style[0]) {
4899
	if (style[0]) {
4893
		xftfont = XftFontOpen(display, screen,
4900
		xftfont = XftFontOpen(display, screen,
4894
		    XFT_FAMILY, XftTypeString, font,
4901
		    XFT_FAMILY, XftTypeString, font,
Lines 4902-4919 xft_setfont(xfontarg, csize, registry) Link Here
4902
		    XFT_PIXEL_SIZE, XftTypeDouble, (float)csize, NULL);
4909
		    XFT_PIXEL_SIZE, XftTypeDouble, (float)csize, NULL);
4903
	}
4910
	}
4904
	if (xftfont == 0) {
4911
	if (xftfont == 0) {
4905
		free(xfont);
4906
		return NULL;
4912
		return NULL;
4907
	}
4913
	}
4908
	snprintf(lastfont, sizeof(lastfont), "%s:%s", font, style);
4914
4915
	cache = malloc(sizeof(*cache));
4916
	if (! cache) {
4917
		XftFontClose(display, xftfont);
4918
		return NULL;
4919
	}
4920
	cache->name = strdup(fontname);
4921
	if (! cache->name) {
4922
		free(cache);
4923
		XftFontClose(display, xftfont);
4924
		return NULL;
4925
	}
4909
	if (verbose) {
4926
	if (verbose) {
4910
		fprintf(stderr, "using xftfont [%s] size: %d\n", lastfont,
4927
		fprintf(stderr, "using xftfont [%s] size: %d\n", cache->name,
4911
		    csize);
4928
		    csize);
4912
	}
4929
	}
4913
	lastsize = csize;
4930
	cache->size = csize;
4914
	last_xftfont = xftfont;
4931
	cache->font = xftfont;
4915
	free(xfont);
4932
	cache->next = xft_fonts;
4916
	return last_xftfont;
4933
	xft_fonts = cache;
4934
	return cache->font;
4917
}
4935
}
4918
#endif
4936
#endif
4919
#ifdef USE_M17N
4937
#ifdef USE_M17N

Return to bug 118556