Commit d92f14a7 authored by Greg A. Woods's avatar Greg A. Woods Committed by Alan Coopersmith
Browse files

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

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: default avatarGreg A. Woods <>
parent 148a592b
Pipeline #551388 passed with stages
in 1 minute and 8 seconds
......@@ -36,8 +36,8 @@
*appDefaultsVersion: 1
*pixelSizeList: 7, 30, 40, 50, 60
*pointSizeList: 250, 300, 350, 400
*pixelSizeList: 0
*pointSizeList: 80, 90, 100, 110, 120, 140, 160, 170, 180, 200, 250, 300, 350, 400
XFontSel.cursor: left_ptr
*allowShellResize: true
......@@ -50,6 +50,7 @@ Modified: Mark Leisher <> 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"
......@@ -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);
return 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)XtFree, (XtPointer)parseRec, work_priority);
if (AppRes.scaled_fonts)
ScheduleWork(FixScalables,(XtPointer)topLevel, work_priority);
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.
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);
NewScalables(7, AppRes.pointSizeList);
NewScalables(8, xreslist);
NewScalables(9, yreslist);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment