I'm using graphical GNU Emacs 26.3 on Windows.

At least on Windows, Emacs determines column width by looking at the AveCharWidth field in the font's OS/2 table. As the name suggests, this field contains the average width of all non-zero-width characters in the font. Emacs then uses this to calculate pixel widths for things like an 80-column window.

However, the font I'm using, BIZ UDGothic, happens to be a CJK (Chinese, Japanese, Korean) monospace font. In fonts like this, there's a notion of "half-width" and "full-width" characters. For example, a character like a is "half-width" and therefore one cell wide, but CJK characters like are generally "full-width", or two cells wide.

In this font, half-width characters are 1024 FUnits wide, and full-width characters are 2048 FUnits wide. Ideally, the column width would be 1024 FUnits, since that aligns with the CJK notion of a half-width character being one cell wide. Unfortunately, because of the large number of full-width characters in this font, the average character width is 1991 FUnits, meaning the column width is nearly twice what it should be.

Now, this doesn't negatively impact the actual rendering of the font, since Emacs treats it as it would treat any proportional font, looking at the width of each individual character. It does, however, mean that windows are created much wider than they should be, and code that attempts to center text based on number of columns is significantly off.

I have fixed the problem by actually editing this field in the font file, but doing so was a bit of an ordeal, and I'd much prefer to configure this in Emacs itself. So, my question is, is there any way to do so, short of patching Emacs?

EDIT: To clarify a little, while editing the font itself is a solution, I'm not sure it's the right solution. Having the AveCharWidth field be 1991 FUnits isn't wrong per se, it's an accurate description of the font. The problem is that the heuristic of column width = average character width doesn't work in this case.

EDIT 2: Adding some screenshots to illustrate the problem:

With AveCharWidth set to 1991 FUnits, the default size of the window is way too wide, and nothing is centered properly relative to the window size or the Spacemacs logo: Screenshot with <code>AveCharWidth</code> set to 1991 FUnits

With AveCharWidth set to 1024 FUnits, things are as they should be: Screenshot with <code>AveCharWidth</code> set to 1024 FUnits

  • Within the past few months, there was a discussion on the Emacs Devel mailing list about this issue, or at least sufficiently similar for it to stick out in my mind. Perhaps someone could provide us with a link to the opening thread .... One idea might be to substitute particularly problematic characters with something else using the buffer-display-table; however, that would only help if a suitable alternative character exists. After a brief search through the mailing list, perhaps this was it (without much discussion): lists.gnu.org/archive/html/emacs-devel/2019-11/msg01237.html
    – lawlist
    Feb 27, 2020 at 2:19
  • The follow-up to that initial thread in November 2019 on the Emacs Devel mailing list that I was thinking of happened in the month of December 2019: lists.gnu.org/archive/html/emacs-devel/2019-12/index.html with the subject line of "Re: Display certain glyphs with paddings on the side"
    – lawlist
    Feb 27, 2020 at 2:25
  • @lawlist Sorry, although this is a CJK issue, the thread you linked seems to be unrelated. The issue being discussed there is about adding padding to ensure that a full-width character is exactly two times the width of a half-width character, but this is not an issue for me at the moment because in my case, half-width and full-width characters are coming from the same font. My problem, in short, is that an "80-column" window ends up being nearly 160 times the width of a half-width character like a, rather than 80 times the width.
    – niconii
    Feb 27, 2020 at 2:45
  • @lawlist I've added some screenshots that might help demonstrate what I mean.
    – niconii
    Feb 27, 2020 at 2:58


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy