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

Attempt to refactor SVGMobject with svgelements #1731

Merged
merged 25 commits into from
Feb 11, 2022
Merged

Attempt to refactor SVGMobject with svgelements #1731

merged 25 commits into from
Feb 11, 2022

Conversation

YishiMichael
Copy link
Contributor

@YishiMichael YishiMichael commented Feb 9, 2022

Motivation

Try using external library svgelements to refactor SVGMobject.

Proposed changes

  • M manimlib/mobject/svg/svg_mobject.py: use svgelements to parse svg files
  • M manimlib/mobject/svg/tex_mobject.py: remove override attribute from init_colors method; cut off global style-applying process from init_colors
  • M manimlib/mobject/svg/text_mobject.py: remove init_colors inheritance; add set_fill process since svg files rendered by Text have the black color specified
  • M manimlib/mobject/svg/mtex_mobject.py: replace .fill_color with .get_fill_color()
  • M manimlib/mobject/mobject.py: remove override attribute from init_colors method
  • M manimlib/mobject/geometry.py: add Polyline class; remove override attribute from init_colors method
  • M manimlib/mobject/types/surface.py: remove override attribute from init_colors method
  • M manimlib/mobject/types/vectorized_mobject.py: remove override attribute from init_colors method
  • M requirements.txt: update requirements (add svgelements, remove cssselect2)
  • M setup.cfg: update requirements (add svgelements, remove cssselect2)

Notes

  • For each submobject of SVGMobject, 5 attributes (fill_color, fill_opacity, stroke_width, stroke_color, stroke_opacity) depend on the result of style parsing. If not specified, they will be set as default attributes passed to SVGMobject class. set_fill, set_stroke methods can still apply style globally.
  • unpack_groups attribute is removed as the structure may be modified. Now SVGMobject always unpacks submobjects.
  • Some changes may also have to be made to MarkupText, just like Text, but I cannot run MarkupText and cannot look into svg files rendered by it.
  • <text> tags in svg are still not handled.
  • A scaling process with scalar 0.75 is applied so that the size of a mobject remains as before.
  • The outer svg tag may also contain style, which is ignored when inserting a group tag in svg content. This may be handled in the future.
  • I notice that it's more reasonable to let SingleStringTex and MTex both inherit from SVGMobject, and in community edition they do. This may also be handled later.

@YishiMichael YishiMichael changed the title Attempt to refactor SVGMobject with svglib Attempt to refactor SVGMobject with svgelements Feb 11, 2022
@YishiMichael YishiMichael marked this pull request as ready for review February 11, 2022 11:48
@TonyCrane TonyCrane requested a review from 3b1b February 11, 2022 12:21
@3b1b 3b1b merged commit 67f5b10 into 3b1b:master Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants