use new font system from drw
This commit is contained in:
		@ -2,8 +2,12 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* The three fields set to 0 have to stay that way for a scalable font */
 | 
					/* The three fields set to 0 have to stay that way for a scalable font */
 | 
				
			||||||
static char *font = "-*-dejavu sans condensed-bold-r-*-*-0-0-*-*-*-0-*-*";
 | 
					static char *font = "-*-dejavu sans condensed-bold-r-*-*-0-0-*-*-*-0-*-*";
 | 
				
			||||||
#define NUMFONTS 30
 | 
					static char *fontfallbacks[] = {
 | 
				
			||||||
#define FONTSZ(x) ((int)(100.0 * powf(1.1288, (x)))) /* x in [0, NUMFONTS-1] */
 | 
						"dejavu",
 | 
				
			||||||
 | 
						"trollolo",
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					#define NUMFONTSCALES 30
 | 
				
			||||||
 | 
					#define FONTSZ(x) ((int)(10.0 * powf(1.1288, (x)))) /* x in [0, NUMFONTSCALES-1] */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* how much screen estate is to be used at max for the content */
 | 
					/* how much screen estate is to be used at max for the content */
 | 
				
			||||||
static float usablewidth = 0.75;
 | 
					static float usablewidth = 0.75;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										66
									
								
								sent.c
									
									
									
									
									
								
							
							
						
						
									
										66
									
								
								sent.c
									
									
									
									
									
								
							@ -93,7 +93,7 @@ static void pngdraw(struct image *img);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static Bool xfontisscalable(char *name);
 | 
					static Bool xfontisscalable(char *name);
 | 
				
			||||||
static XFontStruct *xloadqueryscalablefont(char *name, int size);
 | 
					static XFontStruct *xloadqueryscalablefont(char *name, int size);
 | 
				
			||||||
static struct DC *getfontsize(char *str, size_t len, int *width, int *height);
 | 
					static void getfontsize(char *str, int *width, int *height);
 | 
				
			||||||
static void cleanup(struct DC *cur);
 | 
					static void cleanup(struct DC *cur);
 | 
				
			||||||
static void eprintf(const char *, ...);
 | 
					static void eprintf(const char *, ...);
 | 
				
			||||||
static void die(const char *, ...);
 | 
					static void die(const char *, ...);
 | 
				
			||||||
@ -125,7 +125,7 @@ static XWindow xw;
 | 
				
			|||||||
static struct DC dc;
 | 
					static struct DC dc;
 | 
				
			||||||
static Drw *d = NULL;
 | 
					static Drw *d = NULL;
 | 
				
			||||||
static Scm *sc;
 | 
					static Scm *sc;
 | 
				
			||||||
static Fnt *fonts[NUMFONTS];
 | 
					static Fnt *fonts[NUMFONTSCALES];
 | 
				
			||||||
static int running = 1;
 | 
					static int running = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void (*handler[LASTEvent])(XEvent *) = {
 | 
					static void (*handler[LASTEvent])(XEvent *) = {
 | 
				
			||||||
@ -381,24 +381,17 @@ XFontStruct *xloadqueryscalablefont(char *name, int size)
 | 
				
			|||||||
	return (field != 14) ? NULL : XLoadQueryFont(xw.dpy, newname);
 | 
						return (field != 14) ? NULL : XLoadQueryFont(xw.dpy, newname);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct DC *getfontsize(char *str, size_t len, int *width, int *height)
 | 
					void getfontsize(char *str, int *width, int *height)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	XCharStruct info;
 | 
						size_t i;
 | 
				
			||||||
	int unused;
 | 
					 | 
				
			||||||
	struct DC *pre = &dc;
 | 
					 | 
				
			||||||
	struct DC *cur = &dc;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	do {
 | 
						for (i = 0; i < NUMFONTSCALES; i++) {
 | 
				
			||||||
		XTextExtents(cur->font, str, len, &unused, &unused, &unused, &info);
 | 
							drw_setfontset(d, fonts[i]);
 | 
				
			||||||
		if (info.width > xw.uw || info.ascent + info.descent > xw.uh)
 | 
							if ((*width = drw_fontset_getwidth(d, str)) > xw.uw || (*height = d->fonts->h) > xw.uh)
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		pre = cur;
 | 
						}
 | 
				
			||||||
	} while ((cur = cur->next));
 | 
						if (i > 0)
 | 
				
			||||||
 | 
							drw_setfontset(d, fonts[i-1]);
 | 
				
			||||||
	XTextExtents(pre->font, "o", 1, &unused, &unused, &unused, &info);
 | 
					 | 
				
			||||||
	*height = info.ascent;
 | 
					 | 
				
			||||||
	*width = XTextWidth(pre->font, str, len);
 | 
					 | 
				
			||||||
	return pre;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void cleanup(struct DC *cur)
 | 
					void cleanup(struct DC *cur)
 | 
				
			||||||
@ -545,18 +538,15 @@ void usage()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void xdraw()
 | 
					void xdraw()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int line_len = strlen(slides[idx].text);
 | 
						int height;
 | 
				
			||||||
//	int height;
 | 
						int width;
 | 
				
			||||||
//	int width;
 | 
					 | 
				
			||||||
//	struct DC *dc = getfontsize(slides[idx].text, line_len, &width, &height);
 | 
					 | 
				
			||||||
	struct image *im = slides[idx].img;
 | 
						struct image *im = slides[idx].img;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						getfontsize(slides[idx].text, &width, &height);
 | 
				
			||||||
	XClearWindow(xw.dpy, xw.win);
 | 
						XClearWindow(xw.dpy, xw.win);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!im) {
 | 
						if (!im) {
 | 
				
			||||||
//		XDrawString(xw.dpy, xw.win, dc->gc, (xw.w - width)/2, (xw.h + height)/2,
 | 
							drw_text(d, (xw.w - width) / 2, (xw.h - height) / 2, width, height, slides[idx].text, 0);
 | 
				
			||||||
//				slides[idx].text, line_len);
 | 
					 | 
				
			||||||
		drw_text(d, xw.w/2, xw.h/2, 1000, 200, slides[idx].text, 0);
 | 
					 | 
				
			||||||
		drw_map(d, xw.win, 0, 0, xw.w, xw.h);
 | 
							drw_map(d, xw.win, 0, 0, xw.w, xw.h);
 | 
				
			||||||
	} else if (!(im->state & LOADED) && !pngread(im))
 | 
						} else if (!(im->state & LOADED) && !pngread(im))
 | 
				
			||||||
		eprintf("could not read image %s", slides[idx].text + 1);
 | 
							eprintf("could not read image %s", slides[idx].text + 1);
 | 
				
			||||||
@ -626,29 +616,41 @@ void xinit()
 | 
				
			|||||||
void xloadfonts(char *fontstr)
 | 
					void xloadfonts(char *fontstr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int count = 0;
 | 
						int count = 0;
 | 
				
			||||||
	int i = 0;
 | 
						int i, j;
 | 
				
			||||||
	XFontStruct *fnt;
 | 
						XFontStruct *fnt;
 | 
				
			||||||
	XGCValues gcvalues;
 | 
						XGCValues gcvalues;
 | 
				
			||||||
	struct DC *cur = &dc;
 | 
						struct DC *cur = &dc;
 | 
				
			||||||
//	char **fstr = XListFonts(xw.dpy, fontstr, 42, &count);
 | 
						char *fstrs[LEN(fontfallbacks)];
 | 
				
			||||||
	char *fstrs;
 | 
					 | 
				
			||||||
	const char **fonts;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!(fstrs = malloc(NUMFONTS * MAXFONTSTRLEN)))
 | 
						for (j = 0; j < LEN(fontfallbacks); j++) {
 | 
				
			||||||
 | 
							if (!(fstrs[j] = malloc(MAXFONTSTRLEN)))
 | 
				
			||||||
 | 
								die("could not malloc fstrs");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 0; i < NUMFONTSCALES; i++) {
 | 
				
			||||||
 | 
							for (j = 0; j < LEN(fontfallbacks); j++) {
 | 
				
			||||||
 | 
								if (MAXFONTSTRLEN < snprintf(fstrs[j], MAXFONTSTRLEN, "%s:size=%d", fontfallbacks[j], FONTSZ(i)))
 | 
				
			||||||
 | 
									die("font string too long");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							fonts[i] = drw_fontset_create(d, (const char**)fstrs, LEN(fstrs));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						drw_setfontset(d, fonts[19]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*	if (!(fstrs = malloc(NUMFONTS * MAXFONTSTRLEN)))
 | 
				
			||||||
		die("could not malloc fontstrings");
 | 
							die("could not malloc fontstrings");
 | 
				
			||||||
	if (!(fonts = malloc(NUMFONTS * sizeof(char*)))) {
 | 
						if (!(fonts = malloc(NUMFONTS * sizeof(char*)))) {
 | 
				
			||||||
		free(fstrs);
 | 
							free(fstrs);
 | 
				
			||||||
		die("could not malloc fontarray");
 | 
							die("could not malloc fontarray");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*	const char *fonts[] = {
 | 
						const char *fonts[] = {
 | 
				
			||||||
		"Sans:size=80:size=10.5",
 | 
							"Sans:size=80:size=10.5",
 | 
				
			||||||
		"VL Gothic:size=10.5",
 | 
							"VL Gothic:size=10.5",
 | 
				
			||||||
		"WenQuanYi Micro Hei:size=10.5",
 | 
							"WenQuanYi Micro Hei:size=10.5",
 | 
				
			||||||
	}; */
 | 
						}; */
 | 
				
			||||||
//	drw_load_fonts(d, fonts, LEN(fonts));
 | 
					//	drw_load_fonts(d, fonts, LEN(fonts));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < NUMFONTS; i++) {
 | 
					/*	for (i = 0; i < NUMFONTS; i++) {
 | 
				
			||||||
		snprintf(&fstrs[i*MAXFONTSTRLEN], MAXFONTSTRLEN, "%s:size=%d", fontstr, FONTSZ(i));
 | 
							snprintf(&fstrs[i*MAXFONTSTRLEN], MAXFONTSTRLEN, "%s:size=%d", fontstr, FONTSZ(i));
 | 
				
			||||||
		puts(&fstrs[i*MAXFONTSTRLEN]);
 | 
							puts(&fstrs[i*MAXFONTSTRLEN]);
 | 
				
			||||||
		fonts[i] = &fstrs[i*MAXFONTSTRLEN];
 | 
							fonts[i] = &fstrs[i*MAXFONTSTRLEN];
 | 
				
			||||||
@ -658,7 +660,7 @@ void xloadfonts(char *fontstr)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	free(fstrs);
 | 
						free(fstrs);
 | 
				
			||||||
	free(fonts);
 | 
						free(fonts);
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
//	while (count-- && !xfontisscalable(fstr[count]))
 | 
					//	while (count-- && !xfontisscalable(fstr[count]))
 | 
				
			||||||
//		; /* nothing, just get first scalable font result */
 | 
					//		; /* nothing, just get first scalable font result */
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user