-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Refactor Text with the latest manimpango #1751
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The current
Text
,MarkupText
classes are a copied version from community edition, and should run together with old manimpango versions. I heard that the community had a future development plan for manimpango, so I decided to refactor the two classes to fit the code style in manimgl, while using the latest manimpango version as a requirement.In my modified code,
MarkupText
becomes almost an alias ofText
. Parameters are rearranged:Added
is_markup
: A boolean (defaultFalse
inText
, whileTrue
inMarkupText
) representing whether the given string uses markup syntax.justify
: A boolean (defaultFalse
) to determine whether each line of a paragraph is slightly stretched to align at both edges.indent
: An integer (default0
) representing the indent of each paragraph.alignment
: A string (one ofLEFT
,CENTER
,RIGHT
, defaultLEFT
) to determine which direction to align if not justified.line_width_factor
: A float | None (defaultNone
) to determine where the text should wrap, e.g.1.0
means the text is wrapped just to fit the full screen.None
stands for disabling automatic wrappings (you can still wrap lines via inserting"\n"
).apply_space_chars
: A boolean (defaultTrue
inText
, whileFalse
inMarkupText
) to determine whether empty mobjects should be inserted as spaces. However, applying spaces may raise IndexError if some characters exceed the canvas in pango, or if ligatures, underlines, background rectangles occur in text. When slicingText
object viaget_part(s)_by_text
,apply_space_chars
should be made sure to set toTrue
, or a warning is raised. (Sidenote, currently the parameterdisable_ligatures
doesn't affect the output, and ligatures are always applied if there exist some in the font.)global_config
: A dict (typedict[str, Any]
, default{}
) holding extra global configurations on text. Keys can be any attribute supported by pango. (You may look through all attributes supported by pango in this website: https://docs.gtk.org/Pango/pango_markup.html)local_configs
: A dict (typedict[str | tuple[int, int], dict[str, Any]]
, default{}
) holding extra local configuration dicts on text. Keys can be either a string (indicating several ranges that match) or a tuple (indicating a single range), and keys of each local configuration dict can be any attribute supported by pango.Modified
t2c
,t2f
,t2s
,t2w
: (typedict[str | tuple[int, int], Any]
, default{}
) Users can now set either a string (indicating several ranges that match) or a tuple (indicating a single range) as a key of any one of those dicts. Strings like[2:5]
will no longer be regarded as ranges.t2g
: Pango cannot handle gradients, so please useset_color_by_gradient
instead. A deprecation warning is raised ift2g
is set.Removed
size
: This is originally an alias offont_size
. The deprecation warning is removed.tab_width
: Originallytab_width * " "
is used to replace all tabs, but it's not useful since"\t"
can be handled in pango.Behaviors of the rest parameters in
CONFIG
are preserved for backwards compatibility.Proposed changes
manimlib/mobject/svg/text_mobject.py
: RefactorText
,MarkupText
,Code
.manimlib/mobject/svg/svg_mobject.py
: Avoid issue brought by trailing "Z M" commands.setup.cfg
: Update version requirement for manimpango.requirement.txt
: Update version requirement for manimpango.Test
Code:
Result: