aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans-Nikolai Viessmann2016-12-22 18:13:13 +0100
committerHans-Nikolai Viessmann2016-12-22 18:13:13 +0100
commit4b91700ef098b90f3d4f1299ef46c77e425ad321 (patch)
tree49e530803bfa98280eeab6a4c5533bc7ae8f92ff
parent3a9d632714df37222ba3aa928705b0424b168537 (diff)
downloadst-me-4b91700ef098b90f3d4f1299ef46c77e425ad321.tar.gz
st-me-4b91700ef098b90f3d4f1299ef46c77e425ad321.zip
Automatic DPI font scaling
In essence, on X.Org, there casn only be one DPI value for a multi-monitor set - you better have equally resolution monitors everywhere or you might have lots of fun dealing with strange size issues. Because of this, for each window in which we run st, I compute the actual DPI from the known resolution and monitor size (in MM), and apply this to the font pattern.
-rw-r--r--st.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/st.c b/st.c
index 9aac16b..d8f0d83 100644
--- a/st.c
+++ b/st.c
@@ -561,6 +561,7 @@ static int oldbutton = 3; /* button event on startup: 3 = release */
static char *usedfont = NULL;
static double usedfontsize = 0;
static double defaultfontsize = 0;
+static double defaultfontdpi = 96;
static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
@@ -3568,6 +3569,12 @@ xloadfonts(char *fontstr, double fontsize)
defaultfontsize = usedfontsize;
}
+ if (FcPatternGetDouble(pattern, FC_DPI, 0, &fontval) ==
+ FcResultNoMatch) {
+ FcPatternDel(pattern, FC_DPI);
+ FcPatternAddDouble(pattern, FC_DPI, defaultfontdpi);
+ }
+
if (xloadfont(&dc.font, pattern))
die("st: can't open font %s\n", fontstr);
@@ -3662,12 +3669,24 @@ xinit(void)
Window parent;
pid_t thispid = getpid();
XColor xmousefg, xmousebg;
+ int ddw, ddh;
if (!(xw.dpy = XOpenDisplay(NULL)))
die("Can't open display\n");
xw.scr = XDefaultScreen(xw.dpy);
xw.vis = XDefaultVisual(xw.dpy, xw.scr);
+ /* determine dpi */
+ /* 1 inch = 25.4 mm */
+ ddw = (int) (((((double) DisplayWidth(xw.dpy, xw.scr)) * 25.4)
+ / ((double) DisplayWidthMM(xw.dpy, xw.scr))) + 0.5);
+ ddh = (int) (((((double) DisplayHeight(xw.dpy, xw.scr)) * 25.4)
+ / ((double) DisplayHeightMM(xw.dpy, xw.scr))) + 0.5);
+ if (ddw != ddh)
+ die("Computed DPI values are not equal (square)\n");
+
+ defaultfontdpi = ddw;
+
/* font */
if (!FcInit())
die("Could not init fontconfig.\n");