On Sun, Jul 28, 2013 at 10:09:59PM -0500, Eric Pruitt wrote:
> The bounding boxes for characters can be scaled using "cwscale" and "chscale"
> to scale the width and height respectively.
> ---
>  TODO         |    1 -
>  config.def.h |    4 ++++
>  st.c         |   20 +++++++++++++-------
>  3 files changed, 17 insertions(+), 8 deletions(-)

Missed a couple CEIL calls in the original patch. Amended patch attached
with "xw.cw = dc.font.width * cwscale;" changed to "xw.cw =
CEIL(dc.font.width * cwscale);" with the same done for the height.

Eric
diff --git a/TODO b/TODO
index 4fc1346..794b71b 100644
--- a/TODO
+++ b/TODO
@@ -13,7 +13,6 @@ code & interface
 drawing
 -------
 * add diacritics support to xdraws()
-* add kerning configuration
 * make the font cache simpler
 * add hard width handling
 	* xft is reporting wrong width and height for characters
diff --git a/config.def.h b/config.def.h
index 9a3d2c8..8cb8804 100644
--- a/config.def.h
+++ b/config.def.h
@@ -9,6 +9,10 @@ static char font[] = "Liberation Mono:pixelsize=12:antialias=false:autohint=fals
 static int borderpx = 2;
 static char shell[] = "/bin/sh";
 
+/* Kerning / character bounding-box mutlipliers */
+float cwscale = 1.0;
+float chscale = 1.0;
+
 /*
  * word delimiter string
  *
diff --git a/st.c b/st.c
index 947373f..a238e27 100644
--- a/st.c
+++ b/st.c
@@ -76,6 +76,7 @@ char *argv0;
 #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
 #define IS_SET(flag) ((term.mode & (flag)) != 0)
 #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000)
+#define CEIL(x) (((x) != (int) (x)) ? (x) + 1 : (x))
 
 #define VT102ID "\033[?6c"
 
@@ -2736,8 +2737,8 @@ xloadfonts(char *fontstr, int fontsize) {
 		die("st: can't open font %s\n", fontstr);
 
 	/* Setting character width and height. */
-	xw.cw = dc.font.width;
-	xw.ch = dc.font.height;
+	xw.cw = CEIL(dc.font.width * cwscale);
+	xw.ch = CEIL(dc.font.height * chscale);
 
 	FcPatternDel(pattern, FC_SLANT);
 	FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
@@ -2919,6 +2920,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
 	Colour *fg, *bg, *temp, revfg, revbg;
 	XRenderColor colfg, colbg;
 	Rectangle r;
+	int oneatatime;
 
 	frcflags = FRC_NORMAL;
 
@@ -3027,6 +3029,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
 		u8fs = s;
 		u8fblen = 0;
 		u8fl = 0;
+		oneatatime = font->width != xw.cw;
 		for(;;) {
 			u8c = s;
 			u8cblen = utf8decode(s, &u8char);
@@ -3034,8 +3037,8 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
 			bytelen -= u8cblen;
 
 			doesexist = XftCharExists(xw.dpy, font->match, u8char);
-			if(!doesexist || bytelen <= 0) {
-				if(bytelen <= 0) {
+			if(oneatatime || !doesexist || bytelen <= 0) {
+				if(oneatatime || bytelen <= 0) {
 					if(doesexist) {
 						u8fl++;
 						u8fblen += u8cblen;
@@ -3048,7 +3051,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
 							winy + font->ascent,
 							(FcChar8 *)u8fs,
 							u8fblen);
-					xp += font->width * u8fl;
+					xp += CEIL(font->width * cwscale * u8fl);
 
 				}
 				break;
@@ -3057,8 +3060,11 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
 			u8fl++;
 			u8fblen += u8cblen;
 		}
-		if(doesexist)
+		if(doesexist) {
+			if (oneatatime);
+				continue;
 			break;
+		}
 
 		/* Search the font cache. */
 		for(i = 0; i < frclen; i++) {
@@ -3118,7 +3124,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
 				xp, winy + frc[i].font->ascent,
 				(FcChar8 *)u8c, u8cblen);
 
-		xp += font->width;
+		xp += CEIL(font->width * cwscale);
 	}
 
 	/*

Reply via email to