Commit Diff


commit - 213fc4f6fb26bb5781ea3e489bf4cc5c2aca591e
commit + 79555a9987d62cd15b77df2b4328e963583a160e
blob - 329108d91c0b5094f735012e80486b06305c141f
blob + 2bc9b4be73ca91fe161ee7c21cda5d31142bf953
--- include/draw.h
+++ include/draw.h
@@ -308,6 +308,7 @@ struct Cachesubf
 struct Font
 {
 	char		*name;
+	char		*namespec;
 	Display		*display;
 	short		height;	/* max height of image, interline spacing */
 	short		ascent;	/* top of image to baseline */
blob - 512bc9d363f199f48dd7a889047b944ead4a7e1b
blob + d3f2e69e56d628ce068cc1952dc6f446090d0956
--- src/libdraw/buildfont.c
+++ src/libdraw/buildfont.c
@@ -28,6 +28,7 @@ buildfont(Display *d, char *buf, char *name)
 	fnt->scale = 1;
 	fnt->display = d;
 	fnt->name = strdup(name);
+	fnt->namespec = strdup(name);
 	fnt->ncache = NFCACHE+NFLOOK;
 	fnt->nsubf = NFSUBF;
 	fnt->cache = malloc(fnt->ncache * sizeof(fnt->cache[0]));
@@ -135,6 +136,7 @@ freefont(Font *f)
 	}
 	freeimage(f->cacheimage);
 	free(f->name);
+	free(f->namespec);
 	free(f->cache);
 	free(f->subf);
 	free(f->sub);
blob - cb8ab22b09a8ccbdca7390ed4021a5db9d2ac812
blob + a508b989286f09caecfbd8dc48c705719be9422c
--- src/libdraw/mkfont.c
+++ src/libdraw/mkfont.c
@@ -18,6 +18,7 @@ mkfont(Subfont *subfont, Rune min)
 	font->scale = 1;
 	font->display = subfont->bits->display;
 	font->name = strdup("<synthetic>");
+	font->namespec = strdup("<synthetic>");
 	font->ncache = NFCACHE+NFLOOK;
 	font->nsubf = NFSUBF;
 	font->cache = malloc(font->ncache * sizeof(font->cache[0]));
blob - 97102a2225d322403aed7b2ef6999fa329b1d375
blob + f798983b2a7ee8dc95d12a55159339cb63ce1625
--- src/libdraw/openfont.c
+++ src/libdraw/openfont.c
@@ -156,6 +156,34 @@ swapfont(Font *targ, Font **oldp, Font **newp)
 	*newp = old;
 }
 
+static char*
+hidpiname(Font *f)
+{
+	char *p, *q;
+	int size;
+	
+	// If font name has form x,y return y.
+	p = strchr(f->namespec, ',');
+	if(p != nil)
+		return strdup(p+1);
+	
+	// If font name is /mnt/font/Name/Size/font, scale Size.
+	if(strncmp(f->name, "/mnt/font/", 10) == 0) {
+		p = strchr(f->name+10, '/');
+		if(p == nil || *++p < '0' || *p > '9')
+			goto scale;
+		q = p;
+		size = 0;
+		while('0' <= *q && *q <= '9')
+			size = size*10 + *q++ - '0';
+		return smprint("%.*s%d%s", utfnlen(f->name, p-f->name), f->name, size*2, q);
+	}		
+
+	// Otherwise use pixel doubling.	
+scale:
+	return smprint("%d*%s", f->scale*2, f->name);
+}
+
 void
 loadhidpi(Font *f)
 {
@@ -169,7 +197,7 @@ loadhidpi(Font *f)
 		return;
 	}
 	
-	name = smprint("%d*%s", f->scale*2, f->name);
+	name = hidpiname(f);
 	fnew = openfont1(f->display, name);
 	if(fnew == nil)
 		return;
@@ -183,9 +211,18 @@ Font*
 openfont(Display *d, char *name)
 {
 	Font *f;
+	char *p;
+	char *namespec;
 	
+	// If font name has form x,y use x for lodpi, y for hidpi.
+	name = strdup(name);
+	namespec = strdup(name);
+	if((p = strchr(name, ',')) != nil)
+		*p = '\0';
+
 	f = openfont1(d, name);
 	f->lodpi = f;
+	f->namespec = namespec;
 	
 	/* add to display list for when dpi changes */
 	/* d can be nil when invoked from mc. */
@@ -203,6 +240,8 @@ openfont(Display *d, char *name)
 		if(d->dpi >= DefaultDPI*3/2)
 			loadhidpi(f);
 	}
+	
+	free(name);
 
 	return f;
 }