-
Notifications
You must be signed in to change notification settings - Fork 14
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
Allow passing color to TextSettings #65
Conversation
Thanks for the contribution. I will have a closer look at this at latest by the end of the week. I hope you can wait until then and I apologise for probably not being able to do it sooner. The approach you are using is similar to what |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. This looks good to me. Using https://gnome.pages.gitlab.gnome.org/gtk/Pango/struct.Attribute.html seems like a better idea to me rather than using PangoMarkup. I guess I will work on it later.
I think that |
Probably we should this a better API than the current one. I mentioned |
198755b
to
18b90c4
Compare
The tests are failing because windows is missing some fonts. I don't think it is caused by my changes, as I didn't touch fonts. |
AFAICS, the error mentioned above (gradiented office) is explained in the docs for I admit that this is only a workaround. However, as long as we do not have gradients built-in to Pango, we must do them at the SVG level and there just seems to be no way to reliably know how many glyphs you really get from a certain text. |
I think the change which deletes the SVG file on the error raised has caused the issue. I think removing that could fix the errors(at least the permission one). |
You're right, I didn't notice that. I think instead of requiring offsets, as a workaround we could set colors directly with markup in strings passed to |
tests/_manim.py
Outdated
if os.path.exists(file_name): | ||
os.remove(file_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will still error out. The error was not FileNotExistsError
it was PermissionError
(which mean the file was opened but wasn't closed). I guess this part of the code can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that on my machine pango left an empty svg file when this occurred and it interferes with caching. That's why I've added cleaning, but it seems windows works differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there exist any caching for tests/_manim.py
. Also, I think it should be fine to not remove the file at all since it's just used while testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The caching problem was present when running manim
. I'll remove it from _manim
tests but it may cause problems later on manim
repo with windows build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the manim repo, you can check the number of submobjects in the parsed object. If the count is 0
it's an empty SVG(in which case delete the SVG) if not it's correct and is cached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty svg files cannot be parsed. I get ExpatError: no element found: line 1, column 0
when I try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, did you mean by empty SVG file a literal empty file? In my case when I tried previously (without the checks for valid colour), I got a valid SVG file but nothing was in it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did mean literal empty file. Without validation it was a valid svg but now a ValueError
is raised so ManimPango
creates the file but doesn't populate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without validation it was a correct svg but now a ValueError is raised so ManimPango creates the file but doesn't populate it.
Ah, I see what's wrong. We should close the file before erroring out(which should create a valid SVG) or check before even creating a file. That is we should move the checking part before calling cairo_svg_surface_create
or we should say cairo to close the file handles by calling cairo_destroy()
, cairo_surface_destroy()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, that was missing. That's probably also why windows couldn't get permission to delete the file, because it was still owned by the program.
d3c448e
to
dfc7265
Compare
dfc7265
to
bcd66fa
Compare
I will have a look at the tests failing on windows tomorrow. |
The tests failed because the order of execution of tests has changed. There is some kind of cache in Pango that gets interfered in these tests. Can you rebase on #67 and check if that works? |
33e7b20
to
3eabe0f
Compare
@marcin-serwin Can you rebase again with main? |
3eabe0f
to
5a953d1
Compare
tests/test_colors.py
Outdated
|
||
|
||
@pytest.mark.skipif( | ||
sys.platform.startswith("win32"), reason="windows draws fonts differently" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think SVGStyleTester
only tests for styles and not actual paths, so I think this can be run on win32 also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for your contribution.
I will release a new version after the CI is fixed #68 . Thanks. |
I have released 0.4.0 now, it should have this change. |
This will allow to fix problem described in ManimCommunity/manim/pull/2341