-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Svgmobject update with basic processing of 'text' tag #1083
Conversation
- Font family split - Shift with half 'o' height
manimlib/mobject/svg/svg_mobject.py
Outdated
o_hight = Text('o', size=font_size*self.text_scale, font=font_family_list[0]).get_height() # vertical centering with 'o' | ||
return txt_mobject.shift(UP*o_hight*0.5) |
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'm getting kinda lost here so does a svg text element with the value o have incorrect vertical centering does this happen for other characters. I wonder if there is a way to do this automatically and not for the 'o' degenerate case
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.
By default Text mobject is centered about the top of small letters (red dot below). I think the correct behavior is to use the central line of small letters (green dot).
Without a half-o height shift, the result in PR looks like this (which seems to be incorrect).
Also, I've looked at TextWithFixHeight
class in text_mobject.py
for reference of text height measuring.
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.
TextWithFixHeight
will create problems thats why i removed that in #1071
I think we have to use cairo directly to do this. |
Yes, currently, the arrangement is naturally done with whole text along the center of the rectangle (see red dots below). The desired behavior is to arrange vertically along with the small characters of text ('o' position). To count that I propose counting extra space for each character using the original cairo function |
I think if we store all Text elements from svg files in a list and after that just replace Text elements in svg file with cairo rendered Texts at appropriate locations according to font and style. Save this new generated svg file may be in new media folder But for a base your method is just fine. |
@NavpreetDevpuri, yes, I see. The problem was in the interpretation of vertical alignment in SVG. The vertical anchor in SVG is along the baseline, not in center. Now the text placement seems to be correct: |
Good job! |
- text horizontal alignment - fill text as stroke in main object - text without stroke by default
|
as i said inkscape g.svg --export-text-to-path --export-plain-svg --export-filename=output.svg this will create |
Yes, that possibly works. But as I see there are two issues.
All in all, for my purpose, my update seems to be working well. See an example from my current work (sorry for text in Cyrillic): |
It looks like this pull request is out of date, as |
Motivation
Currently,,
SVGMobject
doesn't support<text>
tag in SVG format. The support of this tag is good for plotting diagrams, graphs, and other structures from SVG. I've faced it when trying to plot graphs rendered by graphviz.Implementation
I've added text processing to SVGMobject using
Text
mobject with the following features:text_scale
for better drawing (original font size is incorrectly small;font
parameter ofText
mobject;Testing
Tested by drawing SVG file with a graph built by graphviz. The used file is available here.
The result is shown below: left - before, right - after.
Additional notes
<text>
tag which are not supported yet (further work):text-anchor
, centering and rotation infont-family
etc.SVGMobject
to support different stroke/fill styles for different objects. E.g. to fill the text instead of stroking. Currently, it can be done usingsubmobjects
.SVGMobject
doesn't supportstroke-dasharray
in<path>
. Could be useful. Again, currently, it seems to be available usingsubmobjects
.