Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MarkupText: Use Cairo to handle gradients #33

Open
PhilippImhof opened this issue Feb 28, 2021 · 3 comments
Open

MarkupText: Use Cairo to handle gradients #33

PhilippImhof opened this issue Feb 28, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@PhilippImhof
Copy link
Member

Enhancement proposal

When using gradients in MarkupText we have Pango render the text to an SVG. We then load the SVG into a SVGMobject and apply the gradient to the characters. This has two major drawbacks:

  • the gradient is done on a per-character basis, i.e. every character has one solid color; the quality of the gradient therefore depends largely on the length of the text to which it is applied
  • with ligatures, the number of paths does not correspond to the number of characters, so the user will have to specify an offset to compensate for this, e.g. fl counts for two characters but might be rendered as a single glyph
  • similar problems arise with underline, double underline, overline and strikethrough, because those lines will also be sub-paths of the SVGMobject

We will have to be careful w.r.t. the Write animation. Currently, even with gradients every character has its own color. If the character is itself colored with a gradient, what color is to be used for the stroke?

@naveen521kk
Copy link
Member

naveen521kk commented Feb 28, 2021

This will require a refactor in how we render things, see https://gitlab.gnome.org/GNOME/pango/-/issues/533#note_1044494
and corresponding docs https://developer.gnome.org/pango/stable/pango-Glyph-Storage.html#pango-glyph-string-index-to-x

where if my understanding is correct, we shouldn't PangoLayout which we currently do no, instead, we should first create a context from PangoCairo, pango-cairo-create-context, then use pango_itemize after that pango_shape or rather pango_shape_full, and then finally use pango_glyph_string_index_to_x for rendering a single single character with ligature on a cairo surface, while changing the colour in Cairo.

@naveen521kk
Copy link
Member

Before doing this I would like to do #30

@naveen521kk naveen521kk added enhancement New feature or request help wanted Extra attention is needed labels Mar 1, 2021
@naveen521kk
Copy link
Member

This requires a major refactor so it can't be done now and is in the least priority because Manim's SVG parser still doesn't render Gradients from the SVG file.

@naveen521kk naveen521kk removed their assignment Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants