zevlg / telega.el

GNU Emacs telegram client (unofficial)
https://zevlg.github.io/telega.el/
GNU General Public License v3.0
1.09k stars 85 forks source link

Images with stripes #317

Open vitek opened 2 years ago

vitek commented 2 years ago

Telega Setup

OS: Ubuntu 20.04.2 LTS Emacs: GNU Emacs 28.0.50 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) Telega: telega v0.7.70 (TDLib v1.7.8) (telega-server v0.7.13) MELPA: 20210922.739

Current Behavior

Sometimes images are split by text lines with ugly gaps between them. That often happens with user pic:

image

Things get worse when text-scale is increased in runtime:

image

zevlg commented 2 years ago

As to avatar, this is most possibly due to "⮪" (telega-symbol-reply) character, that causes line height to grow.

If you have emoji font installed, so your automatic value for telega-emoji-use-images is non-nil, then you can add reply to the telega-symbols-emojify list, so you will get image instead of direct character. Or you can set a different value for telega-symbol-reply that won't grow your line height.

As to text-scale, this is not supported in runtime, however if you set buffer's default face in the telega-chat-mode-hook, then everything should work. See https://github.com/zevlg/telega.el/issues/90

vitek commented 2 years ago

As to avatar, this is most possibly due to "⮪" (telega-symbol-reply) character, that causes line height to grow.

That helped. But there are other font issues, e.g.:

image

Is it possible to draw it as whole images without splitting into lines?

As to text-scale, this is not supported in runtime, however if you set buffer's default face in the telega-chat-mode-hook, then everything should work. See #90

That's sad. Is it possible to install hook that will adjust telega's internal state on zoom in/out?

zevlg commented 2 years ago

As to avatar, this is most possibly due to "⮪" (telega-symbol-reply) character, that causes line height to grow.

That helped. But there are other font issues, e.g.:

image

Is it possible to draw it as whole images without splitting into lines?

Emacs has no notion about "layout" of things on screen, it can only display lines of the chars, that's it. So you can't display multiple lines of the text at the side of an image, you can display only a single line of the text, like: stripes1

To workaround this limitation telega slices image to multiple slices and display them line by line like: stripes2

What you can do is to display whole avatar on a single line, so gaps won't bother you, use telega-avatar-factors-alist, like this: (setf (alist-get 2 telega-avatar-factors-alist ) '(0.4 . 0.1)). You need to restart telega to apply new value for telega-avatar-factors-alist, because avatars caches

As to text-scale, this is not supported in runtime, however if you set buffer's default face in the telega-chat-mode-hook, then everything should work. See #90

That's sad. Is it possible to install hook that will adjust telega's internal state on zoom in/out?

This feature is in the WIP state, and not implement at the moment

Dima-369 commented 2 years ago

What you can do is to display whole avatar on a single line, so gaps won't bother you, use telega-avatar-factors-alist, like this: (setf (alist-get 2 telega-avatar-factors-alist) '(0.4 . 0.1))

Sorry to take over, but I have a question with telega-avatar-factors-alist. I have applied your code above and I notice how the image still takes over 2 lines but is only displayed on the first line.

image

This is a slight problem when variable-pitch-mode is enabled because it offsets the text of the first line a bit as seen below:

Is it possible to make the avatar span only one line so it next to the sender's name?

image

Dima-369 commented 2 years ago

In *Telega Root* the avatar correctly spans a single line, maybe it is possible to integrate that avatar display into telega-chat-mode?

And I am actually fine with advising some functions to make this work as using variable-pitch-mode is quite a rare use-case for most users I feel.

Dima-369 commented 2 years ago

Ah well, I figured it out myself:

telega-ins--message0 displays 2 image slices on 2 lines. With the modified telega-avatar-factors-alist, one can safely comment out inserting the second slice, so it ends up looking like this which is what I was going for :)

image

rudolf-adamkovic commented 2 years ago

I can confirm that Telega on vanilla Emacs on vanilla macOS has all these problems out of the box (and more, such as emojis making the mode line taller). In general, per UI design 101, emojis exist for user input, not for UI decorations.

P.S. 1. Apple rejects (from their App Store) all apps that do this and for a good reason. It breaks in million ways, like Telega does.

P.S. 2. Citar had the same problem and now uses standard characters by default.

IMO, Telega needs a customization option that would make it stop using any fancy characters for decorative purposes, and it should ship with this option turned on (as a safe default across platforms).

zevlg commented 2 years ago

I can confirm that Telega on vanilla Emacs on vanilla macOS has all these problems out of the box (and more, such as emojis making the mode line taller). In general, per UI design 101, emojis exist for user input, not for UI decorations.

Emojis exist to express something in short and nice looking way, not for "user input". Also, "⮪" is not an emoji.

Emacs is text editor, everything in Emacs is a text. If there is some text glyph that expresses idea in a short and nice looking way - it should be used. The rendering problems with such glyphs must be fixed in the Emacs, not in the package.

P.S. 1. Apple rejects (from their App Store) all apps that do this and for a good reason. It breaks in million ways, like Telega does.

Thanks god telega.el does not try to be in the App Store and follow all its rules

P.S. 2. Citar had the same problem and now uses standard characters by default.

telega.el is not Citar

IMO, Telega needs a customization option that would make it stop using any fancy characters for decorative purposes, and it should ship with this option turned on (as a safe default across platforms).

You can create customization for telega that you think does the right thing and distribute it as telega's "contrib" package or as a separate package.

You can customize symbols used by telega.el (see telega-symbol-XXX user options) or even write your own inserters for chat/messages/etc if you think current inserters are bad/incorrect

rudolf-adamkovic commented 2 years ago

@zevlg

Got it.

Just to clarify, I tremendously admire your efforts, and I hope my comment did not come through as insensitive. I just wanted to point out two facts: (1) the software engineering field knows about the "emoji UIs" problem (e.g. Citar, Apple, etc.), and (2) most people and computer programs use emojis for emotional clues in user input (e.g. personal communication). Thus, we should expect problems.

FYI: I (independently) reported this problem to Emacs developers back in December:

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=52542

zevlg commented 2 years ago

telega.el does some work to workarond Emacsen rendering problems, those workarounds are not applied on MacOS by default, that is work in progress. By using “special” symbols by default telega does not hide or even emphasises problems that are still to be addressed. All special symbols are customizable, however. There is even interface implemented to substitute “special” symbols with static or autogenerated images to provide best UI we can.

MacOS Emacs default fontset has some issues displaying telega-symbol-reply symbol. That definitely does not mean that symbol is bad, that mean default MacOS fontset is not good enough to fit telega.el needs. Best solution for this issue on MacOS could be a creation of image meaning “reply” to be used as substitution for telega-symbol-reply using interface provided by telega