From 17d75bd3369d699186fe4a24f1f22ba1a869ac32 Mon Sep 17 00:00:00 2001 From: TonyCrane <975062472@qq.com> Date: Tue, 15 Jun 2021 18:14:06 +0800 Subject: [PATCH 1/2] Fixed the size of Text on different machines --- manimlib/mobject/svg/text_mobject.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/manimlib/mobject/svg/text_mobject.py b/manimlib/mobject/svg/text_mobject.py index e0161f23..635e6f74 100644 --- a/manimlib/mobject/svg/text_mobject.py +++ b/manimlib/mobject/svg/text_mobject.py @@ -10,15 +10,14 @@ import manimpango from manimlib.constants import * from manimlib.mobject.geometry import Dot from manimlib.mobject.svg.svg_mobject import SVGMobject +from manimlib.mobject.svg.tex_mobject import TexText from manimlib.mobject.types.vectorized_mobject import VGroup from manimlib.utils.config_ops import digest_config from manimlib.utils.customization import get_customization -from manimlib.utils.directories import get_downloads_dir, get_text_dir +from manimlib.utils.directories import get_downloads_dir, get_text_dir, get_temp_dir from manimpango import PangoUtils from manimpango import TextSetting -TEXT_MOB_SCALE_FACTOR = 0.001048 - class Text(SVGMobject): CONFIG = { @@ -41,6 +40,7 @@ class Text(SVGMobject): "t2s": {}, "t2w": {}, "disable_ligatures": True, + "debug": False, } def __init__(self, text, **config): @@ -66,8 +66,21 @@ class Text(SVGMobject): self.set_color_by_t2g() # anti-aliasing - if self.height is None: - self.scale(TEXT_MOB_SCALE_FACTOR * self.font_size) + if self.height is None and not self.debug: + self.load_scale_factor() + self.scale(self.scale_factor * self.font_size) + + def load_scale_factor(self): + factor_file = os.path.join(get_temp_dir(), "text_scale_factor.txt") + if os.path.exists(factor_file): + with open(factor_file, 'r') as f: + self.scale_factor = float(f.read()) + else: + tex_height = TexText("b", font_size=1).get_height() + text_height = Text("b", font_size=1, debug=True).get_height() + self.scale_factor = tex_height / text_height + with open(factor_file, "w") as f: + f.write(str(self.scale_factor)) def remove_empty_path(self, file_name): with open(file_name, 'r') as fpr: From fec2306f9ad16c60c94fc5bd10e79bd6168e7ce1 Mon Sep 17 00:00:00 2001 From: TonyCrane <975062472@qq.com> Date: Tue, 15 Jun 2021 19:16:30 +0800 Subject: [PATCH 2/2] update docs --- docs/source/development/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/development/changelog.rst b/docs/source/development/changelog.rst index 573df074..5fe48f08 100644 --- a/docs/source/development/changelog.rst +++ b/docs/source/development/changelog.rst @@ -16,6 +16,7 @@ Fixed bugs - Fixed chaining animation in example scenes - Fixed the default color of tip - Fixed a typo in ``ShowPassingFlashWithThinningStrokeWidth`` +- Fixed the default size of ``Text`` New Features ^^^^^^^^^^^^