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
Use ManimPango for Text rendering #1383
Conversation
Is this the intended behavior?
|
Looks like a bug to me. I tried doing the same using Community edition's MarkupText (I didn't bring it here because CONFIG was something out of my understanding), and also the legacy CairoText. I get a video like from manim import *
class Font(Scene):
def construct(self):
fonts = Text(
"And you can also set the font according to different words",
font="Arial",
t2f={"font": "Consolas", "words": "Consolas"},
t2c={"font": BLUE, "words": GREEN},
disable_ligatures=True
)
fonts_c = CairoText(
"And you can also set the font according to different words",
font="Arial",
t2f={"font": "Consolas", "words": "Consolas"},
t2c={"font": BLUE, "words": GREEN},
)
markup = MarkupText(
'And you can also set the <color col="BLUE"><span font_desc="Consolas">font</span></color> according to different <color col="GREEN"><span font_desc="Consolas" color="GREEN">words </span></color>',
disable_ligature = True,
font="Arial",
)
fonts.scale(.8)
self.play(Write(fonts))
self.wait()
self.clear()
fonts_c.scale(.8)
self.play(Write(fonts_c))
self.wait()
self.clear()
markup.scale(.6)
self.play(Write(markup))
self.wait() Font.mp4so it seems like a bug in aligning texts in ManimPango for |
|
@TonyCrane I think you don't have the font installed or something like that? Btw which OS are you using? |
But the result fonts are correct ("font" and "words" are Consolas, the rest are Arial), so I made sure I have installed the fonts. |
I think maybe caching issue? Did you run the same example before updating to recent branch which uses pango and the svg file from cairo is cached? That's should be case I think. But still not sure... |
Oh, sorry, I just cleaned the cache of Text, and got the same result as you. Fixed in c9e2234. |
I don't think that will fix this. The colouring is a bit off because of ligatures where in two letter comes in a single path element of the SVG file. Pango would handle it but the svg parser in both the version isn't that great to handle styles. I have some plans to make it not use SVG instead directly return each character as an ImageMobject or rather return a set of points, but that requires work and isn't yet done. Once that's done this problem will be fixed 😉. |
This PR causes a crash immediately for me and it looks like it's causing other problems from the earlier posts. Can this at least be made optional until it can be done stably? |
There could be much reason why things crash. ManimPango is necessary for Community Version also. If you say this crashes for you, it should crash for ManimCE also... |
Motivation
Pango is a lot better at Text Rendering rather than using a Toy API for Cairo. I had discussed this with @3b1b on Discord.. This will remove the dependency on pycairo.
It also provides another method to add a font file to Pango search path, whose family name can later be called. This method isn't available for macOS yet.
I couldn't find
Code
here, that would require a small change settingdisable_ligatures
, or else colours would be broken, due to ligatures.Proposed changes
Test
Running example scenes should work, no breaking API changes.
register_font
API can be used asA list of fonts visible to Pango can be got from
More API at https://manimpango.manim.community/en/latest/