diff options
author | Greg A. Woods <woods@robohack.ca> | 2022-01-27 23:55:08 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-04-05 23:57:37 +0000 |
commit | d92f14a70546d9fac579d7750b4ac0280743123a (patch) | |
tree | 90fcb3bcc7a4aae7a63157ea0f5007b10dbceb23 /xfontsel.c | |
parent | 148a592bf5b10c5f536cb515536351d73952fc6f (diff) |
include actual screen resolution in the resX & resY menus
When given the "-scaled" option fetch the actual screen resolution and
add that to the list of available resolutions for the resX and resY
menus.
I.e. If the pattern contains '*' for the resX and resY fields (i.e.
instead of '0') then we wil end up with the menu containing "0, 100,
NNN", which makes for a really good demonstration of how scaling of
fonts without knowing the true screen resolution can lead to very wonky
results. Even if the values in the pattern are '0' you still get the
true DPI as an option in the menus.
When you specify a size for a scalable font, you should use points,
never pixels. Points are a physical unit of measurement. There are
always 72 points per inch. Never more or less. So to scale fonts
properly on a screen the scaler needs to know the resolution of the
display in pixels per inch in order to render text at a measurable
physical point size. In the current X11 world it is still up to the
user to correctly specify the actual screen resolution when requesting a
scalable font to render text with, and this is now possible to
demonstrate with this change to Xfontsel.
So with the actual correct resolution selected from the resX and resY
menus (and if the resolution figures are accurate and if the display
hasn't been scaled by the hardware or, e.g. XrandR) then choosing any
avaliable point size will show the sample text with a height on the
screen physically matching the chosen point size. To that end the
default pixelSizeList resource has been changed to just "0", as it
should never be changed, and instead the default "pointSizeList"
resource has been extended with a list of reasonable real-world
sample (deci)point sizes.
[also touch up the help text and call exit() to exit main()]
Signed-off-by: Greg A. Woods <woods@robohack.ca>
Diffstat (limited to 'xfontsel.c')
-rw-r--r-- | xfontsel.c | 56 |
1 files changed, 48 insertions, 8 deletions
@@ -50,6 +50,7 @@ Modified: Mark Leisher <mleisher@crl.nmsu.edu> to deal with UCS sample text. #include <X11/Xmu/Atoms.h> #include <X11/Xmu/StdSel.h> #include <X11/Xfuncs.h> +#include <X11/Xlib.h> #include "ULabel.h" #define MIN_APP_DEFAULTS_VERSION 1 @@ -161,7 +162,8 @@ static void Syntax(const char *call) " -sample string sample text to use for 1-byte fonts\n" " -sample16 string sample text to use for 2-byte fonts\n" " -sampleUCS string sample text to use for ISO10646 fonts\n" - " -scaled use scaled instances of fonts\n"); + " -scaled use scaled instances of fonts\n" + "plus any standard toolkit options\n"); exit (1); } @@ -278,7 +280,7 @@ see 'xfontsel' manual page." ); } - ScheduleWork(GetFontNames, (XtPointer)XtDisplay(topLevel), 0); + ScheduleWork(GetFontNames, (XtPointer)topLevel, 0); pane = XtCreateManagedWidget("pane",panedWidgetClass,topLevel,NZ); { @@ -353,7 +355,7 @@ see 'xfontsel' manual page." &wm_delete_window, 1); XtAppMainLoop(appCtx); - return 0; + exit(0); } @@ -446,7 +448,8 @@ struct ParseRec { void GetFontNames(XtPointer closure) { - Display *dpy = (Display*)closure; + Widget topLevel = (Widget)closure; + Display *dpy = XtDisplay(topLevel); ParseRec *parseRec; int count; char **fontNames; @@ -500,7 +503,7 @@ void GetFontNames(XtPointer closure) ScheduleWork((XtProc)XFreeFontNames,(XtPointer)fontNames,work_priority); ScheduleWork((XtProc)XtFree, (XtPointer)parseRec, work_priority); if (AppRes.scaled_fonts) - ScheduleWork(FixScalables,(XtPointer)0,work_priority); + ScheduleWork(FixScalables,(XtPointer)topLevel, work_priority); ScheduleWork(SortFields,(XtPointer)0,work_priority); SetParsingFontCount(matchingFontCount); if (strcmp(AppRes.pattern, DEFAULTPATTERN)) { @@ -710,13 +713,50 @@ static void NewScalables(int f, char *slist) /* Find all scalable fonts, defined as the set matching "0" in the pixel * size field (field 6). Augment the match-lists for all other fields * that are scalable. Add in new scalable pixel and point sizes given - * in resources. + * in resources, along with the current Screen's actual resX and resY + * values. */ /*ARGSUSED*/ void FixScalables(XtPointer closure) { int i; FieldValue *fval = fieldValues[6]->value; + Widget topLevel = (Widget) closure; + Display *dpy = XtDisplay(topLevel); + int scr = XScreenNumberOfScreen(XtScreenOfObject(topLevel)); + double xres, yres; + static char xreslist[21]; /* log10(UINT64_MAX) == 19 */ + static char yreslist[21]; + + /* from xdpyinfo.c: + * there are 2.54 centimeters to an inch; so there are 25.4 millimeters. + * + * dpi = N pixels / (M millimeters / (25.4 millimeters / 1 inch)) + * = N pixels / (M inch / 25.4) + * = N * 25.4 pixels / M inch + */ + xres = ((((double) DisplayWidth(dpy, scr)) * 25.4) / + ((double) DisplayWidthMM(dpy, scr))); + yres = ((((double) DisplayHeight(dpy, scr)) * 25.4) / + ((double) DisplayHeightMM(dpy, scr))); + + /* + * xxx the "0" element is always added, so we can't force these here.... + * + * However, what's interesting is that if the pattern contains '*' for these + * fields (i.e. instead of '0') then we end up with the menu containing "0, + * 100, xres", which makes for a really good demonstration of how scaling + * fonts without knowing the true screen resolution leads to very wonky + * results. + * + * xxx obviously these are static and related only to the screen of the + * Widget at the time this code executes and so you can't drag the Xfontsel + * winto to another screen with a different resolution and see things change + * dynamically -- you have to instantiate a new Xfontsel process on each + * different screen as desired. + */ + sprintf(xreslist, "%d", (int) (xres + 0.5)); + sprintf(yreslist, "%d", (int) (yres + 0.5)); for (i = fieldValues[6]->count; --i >= 0; fval++) { if (fval->string && !strcmp(fval->string, "0")) { @@ -726,8 +766,8 @@ void FixScalables(XtPointer closure) NewScalables(6, AppRes.pixelSizeList); AddScalables(7); NewScalables(7, AppRes.pointSizeList); - AddScalables(8); - AddScalables(9); + NewScalables(8, xreslist); + NewScalables(9, yreslist); AddScalables(11); break; } |