Question

Given an arbitrary monospaced TrueType font and an arbitrary size, as in

xterm -fa "Bitstream Vera Sans Mono:size=14"

I want to add a geometry specification so that the xterm fills some fraction of the full width and height of the display. I can compute the number of lines and columns when I know the xterm character cell size. Is there a way to compute this cell size given a font name and size as in the -fa option above?

I'm thinking of ripping the xterm sources apart to find where the appropriate computation is performed. But my X11 programming skills are substandard at best.

Était-ce utile?

La solution

No need to do X programming ;)

bash$ xterm -fa "Bitstream Vera Sans Mono:size=14" -geometry 40x10 \
    -e 'xwininfo -id $WINDOWID | egrep "(Width|Height)" > /tmp/winfo1'
bash$ xterm -fa "Bitstream Vera Sans Mono:size=14" -geometry 80x20 \
    -e 'xwininfo -id $WINDOWID | egrep "(Width|Height)" > /tmp/winfo2'

Now you have two files with dimensions in pixels, including any padding. In my case they are 444×224 and 884×444. From this one could compute the cell size of 11×22 pixels, and 4 pixels for padding.

Note this does not include any WM decorations. I think any method of finding those would be WM-specific. In my case I need to look at the grandparent window size (do xwininfo -id $something -tree | fgrep Parent twice).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top