0
votes

I'm using fixed size pixel fonts in emacs when writing code. When specifying font sizes in emacs, it wants the font size in points. Since I use my .emacs file on several different machines with varying monitor sizes, it means that when the font looks great on one machine, it's typically blurry or too large on another. I've worked around this in my .emacs by checking the actual monitor size in pixels, but the right way to do this would be to specify the fontsize in pixels, or have a small lisp stub that calculates the proper point size from a given pixel size, assuming the dpi values are available from within emacs.

Suggestions? Update Sep 26

I'm on Linux (Ubuntu 10.04, x64).

My current hackish solution is:

(if (>= (x-display-pixel-height) 1200)
(custom-set-faces
 '(default ((t (:stipple nil :background "black" :foreground "cornsilk" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 120 :width normal :family "proggycleanttsz"))))))

Only the height attribute is different from where I already set it earlier in the .emacs file. On another machine I have to set it to 90 to get it "pixel perfect". I tried putting in a:

(set-frame-font "proggycleanttsz")

instead, but that isn't working. When I look back on my earlier attempts, I see that I now use the truetype version of the font, which means that the subject of the question is not entirely right, but anyway, it looks very much like pixel font, but only at the exact right size. Not sure how this works with truetype.

2
Are you aware, that with stable Emacs, you can use XFT fonts where sizes automatically adapt to the DPI settings? See C-h i d Emacs <RET> Fonts <RET>fschmitt
I was sure that it was possible to set the font sizes using emacs.font in the ~/.Xresources file but I can't seem to do it now.Borbus

2 Answers

2
votes

I've been using

(set-frame-font "font-name:pixelsize=16")

for a while now. Works fine with Emacs 25 on Linux. This style of font name is documented for MS Windows, but I've been using it for years with Linux.

1
votes

As mentioned in the comments to your question, if you are on linux, XFT is what you want, so use something like (set-frame-font "Terminus-8") in your .emacs would work well.

Borbus mentions ~/.Xresources - I think you can use Emacs*font: Font-name in ~/.Xdefaults.

I had a quick look on your profile to try and determine the operating system you use, but I couldn't guess. Some more information might be good (OS, emacs version)