Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 841218 - net-im/telegram-desktop-3.6.1-r1 does not respect fontconfig fonts
Summary: net-im/telegram-desktop-3.6.1-r1 does not respect fontconfig fonts
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal enhancement (vote)
Assignee: Esteve Varela Colominas
URL:
Whiteboard:
Keywords: PATCH, PullRequest
Depends on:
Blocks:
 
Reported: 2022-04-27 00:56 UTC by womble
Modified: 2023-02-16 15:19 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
ebuild patch to enable fontconfig (telegram-desktop-3.6.1-userfont-ebuild.diff,1.65 KB, patch)
2022-04-27 01:02 UTC, womble
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description womble 2022-04-27 00:56:45 UTC
telegram-desktop-3.6.1-r1 uses internal fonts and ignores those set by fontconfig. The change happens somewhere after telegram-desktop-3.1.8. 

However, there exist a compile time option to choose between internal and system font usage, which I have found in the Arch AUR telegram-desktop-userfonts PKBUILD. 

I have attached an ebuild patch which uses the 'fontconfig' use flag to switch between both behaviours 

Reproducible: Always

Steps to Reproduce:
1. Install the package
2. Create a custom fontconfig file and use it
3. start telegram

Eg. from the shell, one could do
   export FONTCONFIG_FILE=./telegram-fonts.conf
   /usr/bin/telegram-desktop 
Actual Results:  
The font settings in the "$FONTCONFIG_FILE" are ignored

Expected Results:  
The font settings in the "$FONTCONFIG_FILE" should be respected
Comment 1 womble 2022-04-27 01:02:08 UTC
Created attachment 774963 [details, diff]
ebuild patch to enable fontconfig
Comment 2 Esteve Varela Colominas 2022-05-02 19:14:49 UTC
Sorry for taking so long to reply, I've been a bit busy as of late.

Are you sure DESKTOP_APP_USE_PACKAGED_FONTS is the right flag for this? From what I gather, all of the DESKTOP_APP_USE_PACKAGED_* flags are control whether system libraries/files are used, and they should be ON to use the system versions of things.

I've just checked, and DESKTOP_APP_USE_PACKAGED_FONTS is already OFF right now. I thought it would be turned ON by default, like DESKTOP_APP_USE_PACKAGED already is, but I guess that was missed. I prefer using defaults whenever possible...

Looking at the source, just setting that flag to ON should do the trick. This is its description:
    option(DESKTOP_APP_USE_PACKAGED_FONTS "Use preinstalled fonts instead of bundled patched ones." OFF)

You don't even need to change the ebuild for this, just adding the following line to /etc/portage/env/net-im/telegram-desktop should do the trick:
    MYCMAKEARGS="-DDESKTOP_APP_USE_PACKAGED_FONTS=ON"

Can you try this? If this works out for you I can make it a USE flag in the ebuild, I'll just have to consider whether it's default on or default off. I'm just wondering why this worked out for you at all, given it still attempts to force its own fonts when the flag is unset. Maybe the lack of their presence allows falling back to system defaults...
Comment 3 womble 2022-05-02 23:02:15 UTC
(In reply to Esteve Varela Colominas from comment #2)

Your are right with the DESKTOP_APP_USE_PACKAGED_FONTS flag: It is OFF by default, and setting it explicitly in MYCMAKEARGS does not make any difference. But thanks for the neat trick of using /etc/portage/env/net-im/telegram-desktop, I didn't know that.

To be honest, I just copied what the Arch AUR people have done, without too much thinking, and only after reading your comment, and checking the .setuped sources of both versions, I realized that the real change is located in the patched "src_prepare" ebuild function:

There all internal telegram fonts get destroyed, by truncating each one to a file of zero byte length. This has the desired effect, because, as it seems, this version of telegram always tries to use its internal fonts first, regardless of the setting of the above flag, and only when that fails the fontconfig fonts are used.

And indeed, when I start the unchanged telegram-desktop-3.6.1-r1::gentoo version, the log file in ~/.local/share/TelegramDesktop/log.txt contains lines of type

   Font: from ':/gui/fonts/DAOpenSansRegular.ttf' loaded 'DAOpenSansRegular'
   ...

but when I used my patched ebuild, the same log file has the following:

   Font Error: could not add ':/gui/fonts/DAOpenSansRegular.ttf'.
   ...

and only then the fontconfig settings work.
Comment 4 Esteve Varela Colominas 2022-05-03 08:15:40 UTC
(In reply to womble from comment #3)

Can you try to see if that log line appears when the flag *is* turned ON? Make sure the flag really is turned on by checking the compilation log, it should show up on the cmake command in the log, as well as the CFLAGS while building the program.
Comment 5 Esteve Varela Colominas 2022-05-03 08:18:33 UTC
Mostly making sure because it should really pick the default fonts when the flag is enabled, otherwise the feature might be buggy:
https://github.com/desktop-app/lib_ui/blob/e3c4d49912277379ed9ba6f300a5155b39337cb1/ui/style/style_core_font.cpp#L125

I'd rather make it so that system fonts are always honored when the relevant USE flag is on, instead of hoping the user doesn't happen to have a font with the correct name installed.
Comment 6 womble 2022-05-03 22:42:38 UTC
(In reply to Esteve Varela Colominas from comment #5)

Setting the flag to ON solved the issue for me.

There are no 'Font' lines present in the log file, when the flag is enabled. I used your /etc/portage/env/net-im/telegram-desktop approach, and checked in the build log that the compiler flags include -DDESKTOP_APP_USE_PACKAGED_FONTS)

I tested with FC_DEBUG=1 that my default font family is used, and also tried a separate fontconfig file for telegram with other settings, which have also worked.

To summarize: In the default configuration the flag is OFF, and telegram-desktop will use its internal fonts and ignore fontconfig settings, while with
   MYCMAKEARGS="-DDESKTOP_APP_USE_PACKAGED_FONTS=ON"
it will nicely integrate with the users fontconfig.
Comment 7 Esteve Varela Colominas 2022-05-05 07:52:54 UTC
Thanks for testing! I wonder why it didn't work for you the first time around, but after some more inspection of the codebase, these results make sense.

In that case the only thing that has to be done is to control this build flag with a USE flag. I'm still not entirely sure what use flag to use, since it doesn't exactly enable fontconfig support, it just disables the font defaults of telegram.

Additionally, the media-fonts/open-sans dependency should be reconsidered, considering how the fonts seem to be bundled and installed with the source already, and apparently have different names compared to the system-wide versions. A different name would usually imply a different version of the font, but if that somehow isn't the case, then a fontconfig alias should be made for the different names, to use the system-wide versions instead of the bundled versions.

I'll get to this soon.
Comment 8 Larry the Git Cow gentoo-dev 2022-10-03 22:52:14 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=732558f79fe61bf09c97e9e254e54c511aeafdc9

commit 732558f79fe61bf09c97e9e254e54c511aeafdc9
Author:     Esteve Varela Colominas <esteve.varela@gmail.com>
AuthorDate: 2022-10-01 10:34:41 +0000
Commit:     Georgy Yakovlev <gyakovlev@gentoo.org>
CommitDate: 2022-10-03 22:51:36 +0000

    net-im/telegram-desktop: Bump to 4.2.4
    
    Adds support for bundling kimageformats for qt6.
    
    Adds support for disabling bundled fonts.
    
    Bug: https://bugs.gentoo.org/841218
    Signed-off-by: Esteve Varela Colominas <esteve.varela@gmail.com>
    Signed-off-by: Georgy Yakovlev <gyakovlev@gentoo.org>

 net-im/telegram-desktop/Manifest                   |   1 +
 .../tdesktop-4.2.4-jemalloc-only-telegram.patch    |  43 +++++
 net-im/telegram-desktop/metadata.xml               |   2 +
 .../telegram-desktop/telegram-desktop-4.2.4.ebuild | 204 +++++++++++++++++++++
 4 files changed, 250 insertions(+)
Comment 9 Esteve Varela Colominas 2023-02-16 15:19:42 UTC
open-sans was removed as a dependency, and from what I gather, the USE=-fonts flag works, so I'm closing this bug for now.

Feel free to re-open or file a new report if you think I missed anything.