gtk-rs-core icon indicating copy to clipboard operation
gtk-rs-core copied to clipboard

`pango::Renderer` can't be subclassed

Open jsparber opened this issue 4 years ago • 15 comments

pango::Renderer is mostly useful for creating custom Renderer but it can't be subclassed.

jsparber avatar May 29 '21 11:05 jsparber

looks not that hard to write, do you want to work on it?

bilelmoussaoui avatar May 29 '21 11:05 bilelmoussaoui

No, sorry I don't have time right now. I just saw that it was missing, and thought I open an issue for it.

jsparber avatar May 29 '21 11:05 jsparber

I asked because I thought maybe you needed it for Fractal before next release. In general, everything in gtk-rs-core doesn't have subclassing support except few types in Gio.

bilelmoussaoui avatar May 29 '21 13:05 bilelmoussaoui

i initially thought i would need it, but thankfully the thing i'm trying to do is some what simpler then what i expected.

jsparber avatar May 29 '21 13:05 jsparber

Let's close this then for now until someone has a use-case for this. It's going to be a bit of work to implement and is best done following a specific target use case so we can make sure it actually works correctly.

sdroege avatar Oct 27 '21 14:10 sdroege

How much work is needed here? Are there any similar examples in the repo that I can look and port for this? I want to experiment with rendering pango layouts on OpenGL surfaces.

osa1 avatar Jan 08 '22 10:01 osa1

Check any of the other classes in e.g. gio/src/subclass or gtk/src/subclass. The equivalent of that is needed here too

sdroege avatar Jan 08 '22 10:01 sdroege

Let us reopen this so interested people can find it easily

bilelmoussaoui avatar Jan 08 '22 12:01 bilelmoussaoui

How much work is needed here? Are there any similar examples in the repo that I can look and port for this? I want to experiment with rendering pango layouts on OpenGL surfaces.

Did you ever make any progress with this? I ask because I'll probably give implementing this a shot, since I'd like to play around with using a custom PangoRenderer for neovim-gtk

Lyude avatar Mar 05 '22 20:03 Lyude

Nothing as far as i know, let us know if you have any questions :)

bilelmoussaoui avatar Mar 05 '22 20:03 bilelmoussaoui

Did you ever make any progress with this? I ask because I'll probably give implementing this a shot, since I'd like to play around with using a custom PangoRenderer for neovim-gtk

Nope. What I do instead is I generate texture atlases by generating single-character pango layouts and rendering them to a cairo image surface and then uploading the generated texture to the GPU as a part of a texture. I then do the text shaping manually. Since I only render monospaced fonts it works fine. It wouldn't work for anything more complicated.

Since neovim UI is basically a grid of characters I think the same approach would work for you too.

osa1 avatar Mar 05 '22 20:03 osa1

That wouldn't work for ligatures, would it? And wide characters like emojis or Chinese would probably also need some special care.

sdroege avatar Mar 06 '22 08:03 sdroege

Yes, it only works for monospace characters as text shaping is simple for monospace characters.

In my app I support ligatures, but they are handled specially. I generate glyphs for supported ligatures separately, and use an efficient lexer when rendering to find if a token (in its entirety, not a substring of it) is a ligature.

I'd be interested in learning other approaches to do as much of the work as possible on the GPU while still doing proper text shaping (with Pango, or maybe using HarfBuzz directly).

osa1 avatar Mar 06 '22 08:03 osa1

Did you ever make any progress with this? I ask because I'll probably give implementing this a shot, since I'd like to play around with using a custom PangoRenderer for neovim-gtk

Nope. What I do instead is I generate texture atlases by generating single-character pango layouts and rendering them to a cairo image surface and then uploading the generated texture to the GPU as a part of a texture. I then do the text shaping manually. Since I only render monospaced fonts it works fine. It wouldn't work for anything more complicated.

Since neovim UI is basically a grid of characters I think the same approach would work for you too.

I think I might give the pangorenderer stuff a shot first, since the main reason I'm looking into this is because I'd like to see if I can avoid using cairo for the most part with rendering in gtk4.

Nothing as far as i know, let us know if you have any questions :)

Actually I do have one question! I think I have most of this figured out, except for one thing. In the documentation for Pango.Renderer it mentions both that this is an abstract class, and that it contains a pointer to a PangoMatrix. I've gone through some of the code in both gtk4-rs and gtk-rs-core, but it's not immediately apparent to me if there's any other examples of subclassable-abstract classes with their own data - so I'm not entirely sure how to expose that. Does anyone know the answer to this?

Lyude avatar Mar 06 '22 22:03 Lyude

Actually I do have one question! I think I have most of this figured out, except for one thing. In the documentation for Pango.Renderer it mentions both that this is an abstract class, and that it contains a pointer to a PangoMatrix. I've gone through some of the code in both gtk4-rs and gtk-rs-core, but it's not immediately apparent to me if there's any other examples of subclassable-abstract classes with their own data - so I'm not entirely sure how to expose that.

You mean the matrix in struct PangoRenderer? There's no difference in that regard between abstract and non-abstract classes. You can already access that nowadays with matrix and set_matrix

sdroege avatar Mar 07 '22 09:03 sdroege