@@ -83,8 +83,13 @@ class CairoText(SVGMobject):
8383 `weird <https://github.com/3b1b/manim/issues/1067>`_. Consider using
8484 :meth:`remove_invisible_chars` to resolve this issue.
8585
86+ Tests
87+ -----
8688
89+ Check whether writing text works::
8790
91+ >>> Text('The horse does not eat cucumber salad.')
92+ Text('The horse does not eat cucumber salad.')
8893
8994 """
9095
@@ -158,6 +163,9 @@ def __init__(self, text, **config):
158163 if self .height is None and self .width is None :
159164 self .scale (TEXT_MOB_SCALE_FACTOR )
160165
166+ def __repr__ (self ):
167+ return f"Text({ repr (self .original_text )} )"
168+
161169 def gen_chars (self ):
162170 chars = VGroup ()
163171 submobjects_char_index = 0
@@ -299,9 +307,13 @@ def text2svg(self):
299307 line_spacing = self .line_spacing * 10
300308
301309 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+
304313 dir_name = file_writer_config ["text_dir" ]
314+ if not os .path .exists (dir_name ):
315+ os .makedirs (dir_name )
316+
305317 hash_name = self .text2hash ()
306318 file_name = os .path .join (dir_name , hash_name ) + ".svg"
307319 if os .path .exists (file_name ):
@@ -333,71 +345,6 @@ def text2svg(self):
333345 return file_name
334346
335347
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-
401348class Paragraph (VGroup ):
402349 r"""Display a paragraph of text.
403350
@@ -634,6 +581,14 @@ def construct(self):
634581 self.play(Write(morning))
635582 self.wait(2)
636583
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+
637592 .. WARNING::
638593
639594 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
711666 if self .height is None and self .width is None :
712667 self .scale (TEXT_MOB_SCALE_FACTOR )
713668
669+ def __repr__ (self ):
670+ return f"Text({ repr (self .original_text )} )"
671+
714672 def remove_last_M (self , file_name : str ): # pylint: disable=invalid-name
715673 """Internally used. Use to format the rendered SVG files."""
716674 with open (file_name , "r" ) as fpr :
@@ -922,7 +880,7 @@ class Text(CairoText):
922880 Text objects behave like a :class:`.VGroup`-like iterable of all characters
923881 in the given text. In particular, slicing is possible.
924882
925- Examples
883+ Examples
926884 --------
927885 .. manim:: Example1Text
928886 :save_last_frame:
0 commit comments