On Tue, 17 Dec 2013 10:06:22 +0100 Nils Reuße <n.reu...@hxgn.net> wrote:
(Originally: [dev] [st] parse relative font size instead of pixelsize) Hello, > I prefer size over pixelsize because size scales to the current > display resolution, while pixelsize has to be increased (either in > config.h or on starting st), e.g. if you switch between a non-hd > (home) and hd screen (work). It should be a good thing to support point size. AFAIK, FontConfig converts point size to pixel size using DPI, though I heard that FC does not always use screen DPI. > What do you think? I found that your patch breaks zooming when used with pixel size. Since FC calculates pixel size for us, I wrote a patch that retrieves pixel size from matched font. Note that I changed the types of usedfontsize(global) and fontsize(xloadfonts) to double, because converted pixel sizes are usually non-integer. Sincerely, Eon diff --git a/st.c b/st.c index f883ac1..67f9469 100644 --- a/st.c +++ b/st.c @@ -398,7 +398,7 @@ static void xinit(void); static void xloadcols(void); static int xsetcolorname(int, const char *); static int xloadfont(Font *, FcPattern *); -static void xloadfonts(char *, int); +static void xloadfonts(char *, double); static int xloadfontset(Font *); static void xsettitle(char *); static void xresettitle(void); @@ -478,7 +478,7 @@ static char *opt_font = NULL; static int oldbutton = 3; /* button event on startup: 3 = release */ static char *usedfont = NULL; -static int usedfontsize = 0; +static double usedfontsize = 0; /* Font Ring Cache */ enum { @@ -2826,9 +2826,9 @@ xloadfont(Font *f, FcPattern *pattern) { } void -xloadfonts(char *fontstr, int fontsize) { +xloadfonts(char *fontstr, double fontsize) { FcPattern *pattern; - FcResult result; + FcResult r_sz, r_psz; double fontval; if(fontstr[0] == '-') { @@ -2842,12 +2842,16 @@ xloadfonts(char *fontstr, int fontsize) { if(fontsize > 0) { FcPatternDel(pattern, FC_PIXEL_SIZE); + FcPatternDel(pattern, FC_SIZE); FcPatternAddDouble(pattern, FC_PIXEL_SIZE, (double)fontsize); usedfontsize = fontsize; } else { - result = FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval); - if(result == FcResultMatch) { - usedfontsize = (int)fontval; + r_psz = FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval); + r_sz = FcPatternGetDouble(pattern, FC_SIZE, 0, &fontval); + if(r_psz == FcResultMatch) { + usedfontsize = fontval; + } else if(r_sz == FcResultMatch) { + usedfontsize = -1; } else { /* * Default font size is 12, if none given. This is to @@ -2864,6 +2868,12 @@ xloadfonts(char *fontstr, int fontsize) { if(xloadfont(&dc.font, pattern)) die("st: can't open font %s\n", fontstr); + if(usedfontsize < 0) { + FcPatternGetDouble(dc.font.match->pattern, + FC_PIXEL_SIZE, 0, &fontval); + usedfontsize = fontval; + } + /* Setting character width and height. */ xw.cw = CEIL(dc.font.width * cwscale); xw.ch = CEIL(dc.font.height * chscale); I found that your patch breaks zooming when used with pixel size. Since