@@ -83,8 +83,13 @@ class CairoText(SVGMobject):
83
83
`weird <https://github.com/3b1b/manim/issues/1067>`_. Consider using
84
84
:meth:`remove_invisible_chars` to resolve this issue.
85
85
86
+ Tests
87
+ -----
86
88
89
+ Check whether writing text works::
87
90
91
+ >>> Text('The horse does not eat cucumber salad.')
92
+ Text('The horse does not eat cucumber salad.')
88
93
89
94
"""
90
95
@@ -158,6 +163,9 @@ def __init__(self, text, **config):
158
163
if self .height is None and self .width is None :
159
164
self .scale (TEXT_MOB_SCALE_FACTOR )
160
165
166
+ def __repr__ (self ):
167
+ return f"Text({ repr (self .original_text )} )"
168
+
161
169
def gen_chars (self ):
162
170
chars = VGroup ()
163
171
submobjects_char_index = 0
@@ -299,9 +307,13 @@ def text2svg(self):
299
307
line_spacing = self .line_spacing * 10
300
308
301
309
if self .font == "" :
302
- if NOT_SETTING_FONT_MSG != "" :
303
- print (NOT_SETTING_FONT_MSG )
310
+ if NOT_SETTING_FONT_MSG :
311
+ logger .warning (NOT_SETTING_FONT_MSG )
312
+
304
313
dir_name = file_writer_config ["text_dir" ]
314
+ if not os .path .exists (dir_name ):
315
+ os .makedirs (dir_name )
316
+
305
317
hash_name = self .text2hash ()
306
318
file_name = os .path .join (dir_name , hash_name ) + ".svg"
307
319
if os .path .exists (file_name ):
@@ -333,71 +345,6 @@ def text2svg(self):
333
345
return file_name
334
346
335
347
336
- # Following class is just a Little implementation of upcomming feautures. Ignore it for now.
337
- class TextWithBackground (CairoText ):
338
- CONFIG = {
339
- "background_color" : BLACK ,
340
- }
341
-
342
- def __init__ (self , text , ** config ):
343
- Text .__init__ (self , text , ** config )
344
- # self.text_backgrounds = self.gen_text_backgrounds(text)
345
-
346
- def gen_text_backgrounds (self , text ):
347
- text_with_visible_chars = text .replace (" " , "" ).replace ("\t " , "" )
348
- text_list = text_with_visible_chars .split ("\n " )
349
- text_backgrounds = VGroup ()
350
- start_i = 0
351
- for line_no in range (text_list .__len__ ()):
352
- rect_counts = len (text_list [line_no ])
353
- text_backgrounds .add (* self [start_i :rect_counts ])
354
- start_i += 2 * rect_counts
355
- text_backgrounds .set_color (self .background_color )
356
-
357
- return text_backgrounds
358
-
359
- def text2svg1 (self ):
360
- # anti-aliasing
361
- size = self .size * 10
362
- line_spacing = self .line_spacing * 10
363
-
364
- if self .font == "" :
365
- if NOT_SETTING_FONT_MSG != "" :
366
- logger .warning (NOT_SETTING_FONT_MSG )
367
- dir_name = consts .TEXT_DIR
368
- hash_name = self .text2hash ()
369
- file_name = os .path .join (dir_name , hash_name ) + ".svg"
370
- # if os.path.exists(file_name):
371
- # return file_name
372
-
373
- surface = cairo .SVGSurface (file_name , 600 , 400 )
374
- context = cairo .Context (surface )
375
- context .set_font_size (size )
376
- context .move_to (START_X , START_Y )
377
-
378
- settings = self .text2settings ()
379
- offset_x = 0
380
- last_line_num = 0
381
- for setting in settings :
382
- font = setting .font
383
- slant = self .str2slant (setting .slant )
384
- weight = self .str2weight (setting .weight )
385
- text = self .text [setting .start : setting .end ].replace ("\n " , " " )
386
- context .select_font_face (font , slant , weight )
387
- if setting .line_num != last_line_num :
388
- offset_x = 0
389
- last_line_num = setting .line_num
390
- tempx = START_X + offset_x
391
- tempy = START_Y + line_spacing * setting .line_num
392
- char_offset_x = 0
393
- char_height = tempy - size / 2 - (line_spacing - size )
394
- context .move_to (tempx , tempy )
395
- context .show_text (text )
396
- offset_x += context .text_extents (text )[4 ]
397
- surface .finish ()
398
- return file_name
399
-
400
-
401
348
class Paragraph (VGroup ):
402
349
r"""Display a paragraph of text.
403
350
@@ -634,6 +581,14 @@ def construct(self):
634
581
self.play(Write(morning))
635
582
self.wait(2)
636
583
584
+ Tests
585
+ -----
586
+
587
+ Check that the creation of :class:`~.PangoText` works::
588
+
589
+ >>> PangoText('The horse does not eat cucumber salad.')
590
+ Text('The horse does not eat cucumber salad.')
591
+
637
592
.. WARNING::
638
593
639
594
Using a :class:`.Transform` on text with leading whitespace can look
@@ -711,6 +666,9 @@ def __init__(self, text: str, **config): # pylint: disable=redefined-outer-name
711
666
if self .height is None and self .width is None :
712
667
self .scale (TEXT_MOB_SCALE_FACTOR )
713
668
669
+ def __repr__ (self ):
670
+ return f"Text({ repr (self .original_text )} )"
671
+
714
672
def remove_last_M (self , file_name : str ): # pylint: disable=invalid-name
715
673
"""Internally used. Use to format the rendered SVG files."""
716
674
with open (file_name , "r" ) as fpr :
@@ -922,7 +880,7 @@ class Text(CairoText):
922
880
Text objects behave like a :class:`.VGroup`-like iterable of all characters
923
881
in the given text. In particular, slicing is possible.
924
882
925
- Examples
883
+ Examples
926
884
--------
927
885
.. manim:: Example1Text
928
886
:save_last_frame:
0 commit comments