After writing that answer I started to think why something did not work when 'xft' is not in use; Emacs built with 'cairo' support uses freetype and fontconfig (as I know now).
So why does emacs -fn Hack-13:embolden=true
(up to emacs 28.2) does not render italic, bold and bold-italic as emboldened -- and after I did the following alternative to the answer I wrote, I tried emacs-pgtk (29.1) in alpine:edge container -- and -- the above command line did embolden all 4 variants !
Anyway, for emacs 27 and 28 (w/ cairo graphics backend) there is an alternative, which makes emacs render the fonts exactly as urxvt -fn xft:Hack-13:embolden
:
First, just copy the Hack font (tried without but failed -- it could be possible but...) using the following script (I named it as copy.pe
):
#!/usr/bin/env fontforge
// Usage: ./copy.pe /path/to/Hack-*.ttf # or some other
pfx = "Embl" // fonts.conf to be used to embolden
while ($argc > 1)
Open($1)
SetFontNames("", pfx + $familyname)
Generate(pfx + $1:t)
Close()
shift
endloop
run the script with the fonts to be "emboldened" -- and after done, move the Embl
* files to $HOME/.local/share/fonts/
Then create $HOME/.config/fontconfig/fonts.conf
with the following content (adjust Hack part if using another font)
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<fontconfig>
<description>Embolden Embl*Hack Glyphs</description>
<match target="pattern">
<test name="family"> <string>EmblHack</string> </test>
<edit name="embolden" mode="assign"> <bool>true</bool> </edit>
</match>
</fontconfig>
(fc-cache -fv
can be run before writing fonts.conf
-- anyway) run fw-cache
now
Now, running emacs -fn EmblHack-13
will have all faces rendered emboldened. urxvt -fn xft:EmblHack-13 -letsp -1
should render the glyphs identically (the resize increment reported by xprop
may be same -- or different due to rxvt-unicode taking monospace
more "seriously")
Like I wrote above, it may be that when using emacs 29 all (i.e. also other than pgtk) backends will render all faces emboldened when :embolden=true
is suffixed to the -fn
option. That is good. For emacs 27 and emacs 28 users (who desire emboldened fonts like me) the above option may be the one that is good.
But all this investigations have given me even one more option; I've running urxvt
with -letsp -2
, which "squashes" even one more pixel from the width of the glyphs. For Emacs I don't know how to do that.
Except.
I could use Fontforge to make the embl font to have a bit less width.
And aftet a bit of trying, the following seems to work:
#!/usr/bin/env fontforge
pfx = "EmblCond" // fonts.conf to be used to embolden
while ($argc > 1)
Open($1)
SelectAll()
foreach
w = GlyphInfo("Width")
if (w == 1233) SetWidth(90, 2); endif // 90%: works for Hack font as of 2023-07
endloop
SetFontNames("", pfx + $familyname)
Generate(pfx + $1:t)
Close()
shift
endloop
and then adding separate block for EmblCond in the fonts.conf
file above.
That is what I am using now. IMO looks better as the one created with answer #1 (by me, too) :D
emacs -fn Hack-13:embolden=true
(and this is nothing to do with Harfbuzz, it's because of Cairo)-xrm Xft.embolden:true
with emacs 26. it is slightly better than :weight=bold (where bold and non-bold looked exactly same). So I have to keep looking (In the mean time, in most of the cases, I probably switch using this as temporary solution...)emacs -fn Hack-13:embolden=true
emboldened only the "regular" one -- at least in emacs 27 and 28. I tried emacs-pgtk 29 -- and there also 'italic' 'bold' and 'bold-italic' were emboldened, too... There is more info in my latest answer below.