JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Use character size scaling factors
[st.git] / st.c
diff --git a/st.c b/st.c
index 097244c..6756f76 100644 (file)
--- 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 TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
 #define IS_TRUECOL(x)    (1 << 24 & (x))
@@ -2428,6 +2429,7 @@ tputc(char *c, int len) {
                                treset();
                                term.esc = 0;
                                xresettitle();
+                               xloadcols();
                                break;
                        case '=': /* DECPAM -- Application keypad */
                                term.mode |= MODE_APPKEYPAD;
@@ -2589,6 +2591,13 @@ void
 xloadcols(void) {
        int i, r, g, b;
        XRenderColor color = { .alpha = 0xffff };
+       static bool loaded;
+       Colour *cp;
+
+       if(loaded) {
+               for (cp = dc.col; cp < dc.col + LEN(dc.col); ++cp)
+                       XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
+       }
 
        /* load colors [0-15] colors and [256-LEN(colorname)[ (config.h) */
        for(i = 0; i < LEN(colorname); i++) {
@@ -2621,6 +2630,7 @@ xloadcols(void) {
                        die("Could not allocate color %d\n", i);
                }
        }
+       loaded = true;
 }
 
 int
@@ -2768,8 +2778,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);
@@ -2951,6 +2961,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
        Colour *fg, *bg, *temp, revfg, revbg, truefg, truebg;
        XRenderColor colfg, colbg;
        Rectangle r;
+       int oneatatime;
 
        frcflags = FRC_NORMAL;
 
@@ -3078,6 +3089,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);
@@ -3085,8 +3097,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;
@@ -3099,7 +3111,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;
@@ -3108,8 +3120,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++) {
@@ -3169,7 +3184,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);
        }
 
        /*