ysc3839 / FontMod

Simple hook tool to change Win32 program font.
MIT License
1.29k stars 62 forks source link

Workaround: Telegram Desktop #76

Open rocco-xyz opened 2 years ago

rocco-xyz commented 2 years ago

Since there are many people reporting that it does not work with Telegram, I share the solution that I found: It seems that Telegram uses the fonts: "DAOpenSansRegular", "DAOpenSansRegularItalic", "DAOpenSansSemiboldAsBold", "DAOpenSansSemiboldItalicAsBold", "DAVazirMediumAsBold" and "DAVazirRegular" So we must "replace them" in the registry, in the key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes Create 6 String Values and rename it (Value Name) as the fonts to be replaced and in the Value Data put the name of the font that will replace it.

For example:

"DAOpenSansRegular"="Book Antiqua"
"DAOpenSansRegularItalic"="Book Antiqua Italic"
"DAOpenSansSemiboldAsBold"="Book Antiqua Bold"
"DAOpenSansSemiboldItalicAsBold"="Book Antiqua Bold Italic"
"DAVazirMediumAsBold"="Book Antiqua Bold"
"DAVazirRegular"="Book Antiqua"

Note: It does not change «ALL» the fonts. TelegramFonts Tested on Windows 10 21H1 x64 Telegram Desktop 3.2.5 x64

Xm798 commented 2 years ago

Worked for me, thanks! On Windows11 21H2 x64 Telegram Desktop 3.6.0 x64

Kyogre commented 2 years ago

Yeah, it works even for the official Telegram Desktop 4.0.2. Here is my regedit config for changing fonts to non-cleartype style (ofcourse you need to disable cleartype in Windows beforehand):

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes]
"DAOpenSansRegular"="Arial"
"DAVazirRegular"="Arial"
"DAOpenSansRegularItalic"="Arial"
"DAOpenSansSemibold"="Arial"
"DAVazirMedium"="Arial"
"DAOpenSansSemiboldItalicAsBold"="Arial"

On 1080p screen my fonts look awesomely clear as I think. On 4K screen my fonts look not so great than via FontMod+quality:3 (method described below), but still better than default.


Also you still can use FontMod (it works for Windows and Wine). Just download FontMod dll version 2.1 (version 3.0.1 won't change fonts) -> rename dll to winmm.dll -> place it in 64Gram folder -> launch 64Gram, so the FontMod.yaml config appears in the folder -> exit 64Gram -> edit fonts in FontMod.yaml -> launch 64Gram.

I even achieved changing fonts to non-cleartype style. Here are the configs for 4K (200% UI scaling) and 1080p screens: FontMod Telegram clear fonts.zip / alternative download link. P.S. if someone doesn't like bold font I have set in aforementioned 4K config, you can delete "quality" and "size" strings in this fragment:

  DAOpenSansSemibold:
    replace: DAOpenSansSemibold
    quality: 3
    size: 37

thus you will get default Telegram bold font.

upd. Changing font size via FontMod 2.1 stopped working since 64gram version 1.0.64 (tg 4.6.1), discussion is in https://github.com/ysc3839/FontMod/issues/81.

toymil commented 2 years ago

How did you find out what font telegram is using? (in case of future changes)

toymil commented 2 years ago

With some testing, substituting Consolas will change the monospace font in Telegram, despite the higher priority of Monaco or Menlo in the source code:

code, kbd, pre, samp {
    font-family: Menlo,Monaco,Consolas,"Courier New",monospace;
}

Maybe the query term is not Monaco? Just like the query term for Open Sans is DAOpenSansRegular not Open Sans or something more reasonable (again, how did you find out the correct query term for Open Sans?).

This is my registry file:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes]
"DAOpenSans"="Sarasa UI SC Light"
"DAOpenSansItalic"="Sarasa UI SC Light Italic"
"DAOpenSansRegular"="Sarasa UI SC"
"DAOpenSansRegularItalic"="Sarasa UI SC Italic"
"DAOpenSansSemibold"="Sarasa UI SC Bold"
"DAOpenSansSemiboldItalic"="Sarasa UI SC Bold Italic"
"DAOpenSansBold"="Sarasa UI SC Bold"
"DAOpenSansBoldItalic"="Sarasa UI SC Bold Italic"
"Consolas"="Sarasa Mono SC"

I am using Sarasa UI SC Bold for DAOpenSansSemibold because the semibold variant of Sarasa UI are not visually distinctive enough.

Kyogre commented 2 years ago

How did you find out what font telegram is using? (in case of future changes)

maybe cleaned the Telegram client folder -> launched client from scratch -> opened log.txt file -> looked for messages like Font: from ':/gui/fonts/DAOpenSansRegular.ttf' loaded 'DAOpenSansRegular' ?

toymil commented 2 years ago

@Kyogre Thanks!

I got the following lines:

Font: from ':/gui/fonts/DAOpenSansRegular.ttf'              loaded 'DAOpenSansRegular'
Font: from ':/gui/fonts/DAOpenSansRegularItalic.ttf'        loaded 'DAOpenSansRegularItalic'
Font: from ':/gui/fonts/DAOpenSansSemiboldAsBold.ttf'       loaded 'DAOpenSansSemibold'
Font: from ':/gui/fonts/DAOpenSansSemiboldItalicAsBold.ttf' loaded 'DAOpenSansSemiboldItalic'
Font: from ':/gui/fonts/DAVazirRegular.ttf'                 loaded 'DAVazirRegular'
Font: from ':/gui/fonts/DAVazirMediumAsBold.ttf'            loaded 'DAVazirMedium'

and I think OP @rocco-xyz made a mistake, e.g. substitution should use font name DAOpenSansSemiboldItalic not font file name DAOpenSansSemiboldItalicAsBold, which is the reason why OP did not successfully change the bold fonts.

Note: It does not change «ALL» the fonts.

I guess for the non-custom fonts Telegram will just load them from system with font name as query term, like Consolas for Consolas.

grandsilence commented 1 year ago

All telegram fonts can be found in lib_ui and implementaion of font selection is here.

My final reg version:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes]
"DAOpenSans"="Tahoma"
"DAOpenSansBold"="Tahoma"
"DAOpenSansBoldItalic"="Tahoma"
"DAOpenSansRegular"="Tahoma"
"DAOpenSansRegularItalic"="Tahoma"
"DAOpenSansSemibold"="Tahoma"
"DAOpenSansSemiboldItalic"="Tahoma"
"DAVazir"="Tahoma"
"DAVazirBold"="Tahoma"
"DAVazirMedium"="Tahoma"
"DAVazirRegular"="Tahoma"
;; Priority font resolving: "Cascadia Mono", "Consolas", "Liberation Mono", "Menlo", "Courier"
;; Override monospace font:
"Cascadia Mono"="Fixedsys"
vecheslav commented 7 months ago

Maybe someone will find it helpful. If you just replace the font, you can get a issue that the line height of the font and emoji are different, so when you add emoji to the text, it is shifted down.

I patched the standard Segoe UI font, fixed vertical metrics. Now telegram looks perfect for me as on macos.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes]
"DAOpenSans"="VSegoe UI"
"DAOpenSansBold"="VSegoe UI Bold"
"DAOpenSansBoldItalic"="VSegoe UI Bold Italic"
"DAOpenSansRegular"="VSegoe UI"
"DAOpenSansRegularItalic"="VSegoe UI Italic"
"DAOpenSansSemibold"="VSegoe UI Semibold"
"DAOpenSansSemiboldItalic"="VSegoe UI Semibold Italic"
"DAVazir"="VSegoe UI"
"DAVazirBold"="VSegoe UI Bold"
"DAVazirMedium"="VSegoe UI Semibold"
"DAVazirRegular"="VSegoe UI"
;; Priority font resolving: "Cascadia Mono", "Consolas", "Liberation Mono", "Menlo", "Courier"
;; Override monospace font:
"Cascadia Mono"="JetBrains Mono"

Patched font fixed.zip

vacterro commented 6 months ago

It seems Telegram updates them font, so the above ones not working anymore.

How to track which font uses Telegram?

vecheslav commented 5 months ago

It seems Telegram updates them font, so the above ones not working anymore.

How to track which font uses Telegram?

Now you can change default font family in chat settings 🥳