10

It's so annoying...

When any text on a line has its face changed so that the text is bold, the height of the line increases by (I assume) a single pixel. It's best shown with an image:

enter image description here

Why is this? How do I prevent it?


As requested, info on the platform:

  • Debian GNU/Linux sid (unstable) on amd64
  • Emacs uses libgtk-3.so.0 (gtk 3.14.5), on XFCE 4.12

I've tried the following fonts at 8pt, 9pt, 10pt and 11pt:

  • DejaVu Sans Mono
  • DejaVu Sans
  • DejaVu Serif
  • Droid Sans Mono
  • Liberation Mono

The problem occurs only with DejaVu Sans Mono and DejaVu Sans, and only at 9pt and 10pt. (Image above shows DejaVu Sans Mono-9.)

edam
  • 311
  • 1
  • 6
  • 2
    You should look at the face attributes of *defunexample* before putting a space and then again on each word after putting a space between *defun* and *example*. This is done by placing the cursor at the point desired and then typing `C-u C-x =`. You will probably find that either the face affecting *defun* or the face affecting *example* have different attributes that are responsible for the behavior you see -- e.g., other than just the basic color of the foreground. The face attributes can be customized by the user. – lawlist Jun 09 '15 at 16:18
  • Could you add your operating system and window manager to your question, and some information about what GUI your Emacs uses (e.g. Gtk2, Gtk3, etc.)? –  Jun 09 '15 at 20:30
  • @lawlist: thanks man. With the space, it has font-lock-function-name-face applied, which has an unspecified height (so I presume the default?). Without the space, there is no face applied (so, again, I presume the default?) The default is set in my theme to `:height 90` (9pt). – edam Jun 10 '15 at 10:26
  • @lawlist: some more investigation.... in the theme, if I remove/add/remove/add the `:weight bold` from `font-lock-function-name-face` (and re-execute the theme's `custom-theme-set-faces` command), I can see the height of the `defun` line change by 1px! It's definitely the bold attribute that's causing it, I think. – edam Jun 10 '15 at 10:43
  • My guess based upon your comments would be that the family of font that you chose has a different height for bold attributes, so that cannot be changed unless you manually reduce it -- trial and error by slowly reducing point size. Alternatively, pick a family that doesn't change height when bold is applied. I personally no longer use bold or underline in any of my custom themes for a variety of reasons relating to visual effects in the buffer -- when I do create an underline for the current line, it is done with an overlay. For bold, I simply use strong colors -- e.g., magenta, yellow, ... – lawlist Jun 10 '15 at 15:49
  • Does this happen with other fonts, too? – Eleno Jun 11 '15 at 08:05

1 Answers1

3

The font height changes in DejaVu at that point size because font height information between the two normal and the bold font is different when it should be the same.

The DejaVu Sans Mono 10 font that I use doesn't change the font height between normal and bold weight. I set that in my .emacs with (set-frame-font "DejaVu Sans Mono-10")

So you have something to compare against, the info for "DejaVu Sans 10" font via (font-info on Emacs 25):

(font-info "DejaVu Sans Mono-10")
["-unknown-DejaVu Sans Mono-normal-normal-normal-*-13-*-*-*-m-0-iso10646-1" 
"DejaVu Sans Mono:pixelsize=13:foundry=unknown:weight=normal:slant=normal:
width=normal:spacing=100:scalable=true" 13 17 0 0 0 8 13 4 8 8 
"/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf" (opentype ((DFLT ...) )))]

EDIT based on subsequent info:

In the font information above, I show a font height of 17 and you report a height of 15 (normal) or 16 (bold). In emacs 25 there is additional font information after those 3 0's, in particular the font descent is 4.

Although I don't have a problem on Emacs 24 or 25 with DejaVu Sans Mono and the Bold variant, the simplest thing is to use a font and size that doesn't change width (as shown by font-info) between normal and bold or something other than DejaVu.

As for what's causing this, it might one of your libraries, (my gtk is libgtk-x11-2.0.so.0), but I doubt it would be this particular library. Also doubt it is the ttf file or package. More likely is the freetype rendering (I have libfreetype.so.6). Since DejaVu are scaled as are the other fonts that do work for you, a computation error tickled by the way DejaVu was written would explain why these work at some sizes but not others.

To verify whether the problem is Emacs specific or not, you might be able to bring up two terminal windows, one with a bold prompt and one without and compare the line spacing on them. If it's different like Emacs, then this has to do with the rendering and/or font.

If you compiled emacs there might be something going on there.

rocky
  • 888
  • 7
  • 26
  • This didn't work... (I was using `DejaVu Sans Mono-9` BTW). I'll update the description above... – edam Jun 29 '15 at 16:05
  • Mode line font is the same. Mono 10 exhibits the same behaviour, but 8 and 11pr don't! It's got to be something to do with the font rendering and a different line height being returned for normal and bold. Does Emacs use fontconfig? – edam Jun 29 '15 at 16:17
  • 1
    Emacs doesn't make use of fontconfig and is generally [rather unique](http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20727) when it comes to glyph selection. – wasamasa Jun 29 '15 at 17:06
  • `(font-info "DejaVu Sans Mono-10")` gives me `["-unknown-DejaVu Sans Mono-normal-normal-normal-*-13-*-*-*-m-0-iso10646-1" "DejaVu Sans Mono:pixelsize=13:foundry=unknown:weight=normal:slant=normal:width=normal:spacing=100:scalable=true" 13 15 0 0 0]`. I also have `fonts-dejavu-core` installed, and also `ttf-dejavu-core`. They both provide a `DejaVuSansMono.ttf` (in different directories, but they're identical files, so I don't see that this matters). I also get `Height: 98` from the face (when using DajaVu Sans Mono-10, which exhibits the above problem). I'm open to any more suggestions! :) – edam Jun 30 '15 at 21:18
  • Notice that some of your font info parameters are different. I have "13 17..." while you have "13 15..". And If you get help-for-function font-info you'll see that first difference 17 (me) vs 15 (you) is the height. So try changing the height to 17. – rocky Jun 30 '15 at 21:38
  • I don't think I *can* set that height, can I? Isn't that the calculated line height? Also, I've made a breakthrough... going `(font-info "DejaVu Sans Mono-10:weight=bold")` give me `["-unknown-DejaVu Sans Mono-bold-normal-normal-*-13-*-*-*-m-0-iso10646-1" "DejaVu Sans Mono:pixelsize=13:foundry=unknown:weight=bold:slant=normal:width=normal:spacing=100:scalable=true" 13 16 0 0 0]`, so it's definitely to do with that height field. I'm not sure where that value comes from, though. – edam Jun 30 '15 at 22:13