Ubuntu – How to prevent “automatic” bold version of a font to be wider than regular having the same pt size

fonts

I have a monospaced font (PT Mono) that I prefer to use in programming IDE's. The font has only Regular, all other Bold and Italic are derived by slanting and "boldification" of the Regular. The problem is that the "boldified" characters are wider than regular ones, so the source code strings in the IDE window are now composed of non-monospaced characters.

How do I control the "boldification" of the font so it would not become wider than regular?

The problem is illustrated on the screenshot below (PT Mono, no dedicated bold). See how "unsigned char" and "sizeof" words are moving out from their proper positions.

automatic boldification changes the width

Here an another example, Droid Sans Mono (no dedicated bold).
enter image description here

And here an example when the font has dedicated bold version (Liberation Mono). Bold and regular are aligned perfectly.
enter image description here

So, the issue is definitely in frivolous boldification rendering in situations where bold is not provided. The font engine is to blame.

UPD: There is a file /etc/fonts/conf.avail/90-synthetic.conf which if being referenced from /etc/fonts/conf.d/ tunes the font engine to perform synthetic emboldening of the fonts that do not have the bold version. If the symbolic link to this file is removed from the /etc/fonts/conf.d/, the emboldening disappears. This is not what is exactly wanted, but at least this cures the case of monospace fonts being not monospace (see below, PT Mono). The fine tuning of the emboldening is still wanted (either by configuration file, or by freetype2 patch.

enter image description here

Best Answer

mbaitoff, I'm posting this as addition to your update, not as an answer

If user creates file named ~/.fonts.conf:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <match target="font">
        <test name="spacing" compare="eq">
            <const>mono</const>
        </test>
        <edit name="embolden" mode="assign">
            <bool>false</bool>
        </edit>
    </match>
</fontconfig>

then, applications can use bold monospaced font if available, and disable "synthetic boldification" if used font does not have bold typeface.

It is just alternative, and slightly different approach with different result