local and remote text fonts

Tony Balinski ajbj at free.fr
Fri Jun 29 11:45:51 CEST 2007


Quoting Bert Wesarg <wesarg at informatik.uni-halle.de>:

> Problem situation:
>
> I'm sure I'm not the only person who uses nedit from a remote machine. But
> when I use nedit from one machine on different machines and these
> different machines have different display settings (resolution, dpi) than
> I have to choose the text fonts vary carefully to get the best on all
> these different displays. Now I have maybe two vary different display
> settings: one 1600x1200 100dpi display and a 1024x768 124dpi. So I tried
> to improve the situation.
>
> Current solution:
>
> I hacked (what else) nedit to not save the text font settings in the
> nedit.rc file. ...
>
> A better solution to this could maybe something like this:
>
> check after connecting to the x server if nedit and the x server running
> on the same machine, iff use the current behavior else use the text font
> settings from the x server resourcedb (and probably ask the user for this).

I would do this very differently, by using a script to launch nedit or nc with
appropriate font resources for each display. That script can examine the
output of xdpyinfo or other such programs to decide on the best font set to
apply. It would then invoke nedit/nc with the appropriate -xrm arguments.

Although these font settings do get saved to nedit.rc when you save settings,
if you always use the startup script, this won't affect you, since they'll
always be overridden.

For example:

  #!/bin/sh
  # Run nedit client nc with font settings set according to screen resolution

  # What's the screen resolution? Check xdpyinfo's resolution line,
  # stripping all but the first number of the first word after 'resolution:'
  # eg, with
  #     resolution:    75x75 dots per inch
  # pick up just '75'
  dpi=`xdpyinfo | grep resolution: | \
       sed -e 's/ *[^ ]* *//' -e 's/[^0-9].*//'`

  # what if that didn't work?
  [ -z "$dpi" ] && dpi=90

  # now choose an appropriate font set
  if [ "$dpi" -le 60 ]; then
    # a 5x8 fixed font (doesn't have bold or italic equivalents)
    normal="-misc-fixed-medium-r-*--8-*-*-*-c-*-iso8859-1"
    italic="$normal"
      bold="$normal"
    boldit="$normal"
  elif [ "$dpi" -le 75 ]; then
    # a 6x13 semi-condensed font
    normal="-misc-fixed-medium-r-semicondensed--13-*-*-*-c-*-iso8859-1"
    italic="-misc-fixed-medium-o-semicondensed--13-*-*-*-c-*-iso8859-1"
      bold="-misc-fixed-bold-r-semicondensed--13-*-*-*-c-*-iso8859-1"
    boldit="-misc-fixed-bold-o-semicondensed--13-*-*-*-c-*-iso8859-1"
  elif [ "$dpi" -le 100 ]; then
    # a 7x13 font
    normal="-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1"
    italic="-misc-fixed-medium-o-normal--13-*-*-*-c-70-iso8859-1"
      bold="-misc-fixed-bold-r-normal--13-*-*-*-c-70-iso8859-1"
    boldit="-misc-fixed-bold-o-normal--13-*-*-*-c-70-iso8859-1"
  elif [ "$dpi" -le 120 ]; then
    normal="-misc-fixed-medium-r-normal--15-*-*-*-c-*-iso8859-1"
    italic="$normal"
      bold="-misc-fixed-bold-r-normal--15-*-*-*-c-*-iso8859-1"
    boldit="$bold"
  else # really high res!!
    normal="-misc-fixed-medium-r-normal--18-*-*-*-c-*-iso8859-1"
    italic="$normal"
      bold="-misc-fixed-bold-r-normal--18-*-*-*-c-*-iso8859-1"
    boldit="$bold"
  fi

  # now run nc with resources and all other arguments
  nc -xrm "nedit.textFont:                $normal" \
     -xrm "nedit.boldHighlightFont:       $italic" \
     -xrm "nedit.italicHighlightFont:     $bold"   \
     -xrm "nedit.boldItalicHighlightFont: $boldit" \
     "$@"

No need to hack the source! (I've given this a quick test, and it works OK.)
Note that if you save your nedit settings, you'll save the current font
assignment, but if you always use the script, the saved settings will always
be hidden by the command line ones.

I use similar techniques to assign different background+backlighting colors
according to an environment setting. I do this when I want separate nedit
sessions that I can distinguish readily on the same screen (eg referenced
files in one, work files in another).

Hope this helps.

Tony


More information about the Discuss mailing list