2

For last 2 years (2018-) I've been using

emacs -xrm Xft.embolden:true -fn Hack-13

to start emacs w/ suitable sized and 'brightness'ed fonts for me in my systems.

What that does gives extra boldness to font glyphs in every weights used.

That has worked fine with emacs 25 and 26 (and could work w/ emacs 24, too...)

Now since I upgraded to emacs 27.1 (in 3 fedora systems I have) the extra bolding supposed be given by that embolden does not have any effect anymore...

probably due to the great technology called HarfBuzz(?)

[[edit 2020-09-17 -- use of Cairo instead of HarfBuzz is more probable cause for this, thanks for comment for me to think outside of this -- compared output of (emacs-version) in versions 26.3 and 27.1 of emacs and latter mentioned "cairo"]]

[[edit 2021-11-17 -- my emacs 26.3 compilation does not run anymore on Fedora 35 (libMagicWand mismatch) -- so I compiled 27.2 -- a version without Cairo. With this version embolden works like before. That is good enough for me for a while (again).]]

For urxvt I use -fn xft:Hack-13:embolden -> emacs -fn Hack-13:embolden makes no difference.

emacs -fn Hack-13:weight=bold does bold the "regular" weighted fonts but does not make "bold" fonts any bolder (like Xft.embolden:true does).

What are my options? I hope I don't have to resort to recompile Hack fonts with extra boldness to begin with ;/

4
  • 1
    Based on a quick test, what you're looking for is emacs -fn Hack-13:embolden=true (and this is nothing to do with Harfbuzz, it's because of Cairo)
    – rpluim
    Sep 6, 2020 at 22:32
  • this looks pretty much what I am looking for. I have to test a bit more (will compare what emacs 26.3 does on one other machine)... will continue shortly Sep 7, 2020 at 11:16
  • well, with :embolden=true the difference between non-bold and bold glyphs are very small. much smaller than using -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...) Sep 7, 2020 at 17:08
  • 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. Aug 5, 2023 at 11:43

2 Answers 2

0

Ok, after almost 3 years I have an answer that looks like it is suitable for me.

The "embolden" feature the "xft" interface provides is just not available everywhere.

So, after a "bit of" investigation I got to "embolden" the Hack-*.ttf files and wrote replacement .ttf's with Emb prefix (for now)...

... using the following script:

#!/usr/bin/env fontforge

// name: embolden.pe; license: unlicense

while ($argc > 1)
    Open($1)

    SelectAll()
    ChangeWeight(60)
    Transform(90, 0,  0, 100,  0, 0) // narrower

    foreach 
        i = GlyphInfo("Width") //; Print(i)
        if (i > 0 && i < 1244) SetWidth(1244); endif // XXX hardcoded; works with 'Hack'
    endloop

    SetFontNames("", "Emb" + $familyname)

    //Save("Emb" + $1:r:t + ".std")
    Generate("Emb" + $1:t)
    Close()
    shift
endloop

(as cd $HOME/.fonts/Hack && /path/to/embolden.pe Hack-*.ttf; fc-cache -fv)

Now, when I run emacs -fn EmbHack-13 & I seem to get satisfactory results.

The script above does not update all metainformation in the output files; if this works for you I suggest not to redistribute the new font files without updating rest of the relevant information fields there.

EDIT 2023-07-31: Added "SetWidth()" code to make EmbHack-* font "monospace" enough -- previously e.g. -, x and m had different widths. Compared to xft:embolden the font is a bit "comical", and has less "posture" (IMO), but good enough for me to go.

2
  • 1
    Very nice! Thank you for coming back and providing an answer. If you're satisfied with it, please also mark it as accepted :)
    – Trevoke
    Jul 27, 2023 at 15:43
  • I will, after a I've done a bit more work to get the "monospaceness" handled (so that I am personally satisfied enough to resolve my own question :D). Jul 29, 2023 at 14:58
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.