4
4
import pangocairocffi
5
5
import pangocffi
6
6
7
+ rtl_text = """صباح الخير
8
+ مرحبا جميعا"""
9
+
10
+ width = 600
11
+ height = 400
12
+
7
13
8
14
def test_general_text_svgobject ():
9
15
"""Checks number of submobjects generated when directly called using ``SVGMobject``"""
@@ -15,11 +21,11 @@ def test_general_text_svgobject():
15
21
filename = os .path .join (folder , "hello.svg" )
16
22
a = PangoText (text , size = 10 )
17
23
pangoManim = os .path .join (folder , a .text2hash () + ".svg" )
18
- surface = cairocffi .SVGSurface (filename , 600 , 400 )
24
+ surface = cairocffi .SVGSurface (filename , width , height )
19
25
context = cairocffi .Context (surface )
20
26
context .move_to (START_X , START_Y )
21
27
layout = pangocairocffi .create_layout (context )
22
- layout .set_width (pangocffi .units_from_double (600 ))
28
+ layout .set_width (pangocffi .units_from_double (width ))
23
29
fontdesc = pangocffi .FontDescription ()
24
30
fontdesc .set_size (pangocffi .units_from_double (size * 10 ))
25
31
layout .set_font_description (fontdesc )
@@ -30,27 +36,92 @@ def test_general_text_svgobject():
30
36
assert len (a .submobjects ) == len (b .submobjects )
31
37
32
38
33
- def test_render_text_svgobject ():
39
+ def test_rtl_text_text_svgobject ():
34
40
"""Checks number of submobjects generated when directly called using ``SVGMobject``"""
35
41
size = 1
36
- text = r"臂猿「黛比」帶著孩子"
42
+ text = rtl_text
43
+ folder = os .path .abspath (os .path .join ("media" , "texts" ))
44
+ if not os .path .exists (folder ):
45
+ os .makedirs (folder )
46
+ filename = os .path .join (folder , "hello.svg" )
47
+ a = PangoText (text , size = 1 )
48
+ pangoManim = os .path .join (folder , a .text2hash () + ".svg" )
49
+ surface = cairocffi .SVGSurface (filename , width , height )
50
+ context = cairocffi .Context (surface )
51
+ context .move_to (START_X , START_Y )
52
+ layout = pangocairocffi .create_layout (context )
53
+ layout .set_width (pangocffi .units_from_double (width ))
54
+ fontdesc = pangocffi .FontDescription ()
55
+ fontdesc .set_size (pangocffi .units_from_double (size * 10 ))
56
+ layout .set_font_description (fontdesc )
57
+ layout .set_text (text )
58
+ pangocairocffi .show_layout (context , layout )
59
+ surface .finish ()
60
+ b = SVGMobject (filename )
61
+ assert len (a .submobjects ) == len (b .submobjects )
62
+
63
+
64
+ def test_font_face ():
65
+ """Checks font face using submobject len"""
66
+ size = 1
67
+ text = rtl_text
68
+ font_face = "sans"
37
69
folder = os .path .abspath (os .path .join ("media" , "texts" ))
38
70
if not os .path .exists (folder ):
39
71
os .makedirs (folder )
40
- filename = os .path .join (folder , "hello1 .svg" )
41
- a = PangoText (text , size = 10 , font = "amiri" )
72
+ filename = os .path .join (folder , "hello .svg" )
73
+ a = PangoText (text , size = 1 , font = font_face )
42
74
pangoManim = os .path .join (folder , a .text2hash () + ".svg" )
43
- surface = cairocffi .SVGSurface (filename , 600 , 400 )
75
+ surface = cairocffi .SVGSurface (filename , width , height )
44
76
context = cairocffi .Context (surface )
45
77
context .move_to (START_X , START_Y )
46
78
layout = pangocairocffi .create_layout (context )
47
- layout .set_width (pangocffi .units_from_double (600 ))
79
+ layout .set_width (pangocffi .units_from_double (width ))
48
80
fontdesc = pangocffi .FontDescription ()
49
- fontdesc .set_family ("amiri" )
81
+ fontdesc .set_family (font_face )
50
82
fontdesc .set_size (pangocffi .units_from_double (size * 10 ))
51
83
layout .set_font_description (fontdesc )
52
84
layout .set_text (text )
53
85
pangocairocffi .show_layout (context , layout )
54
86
surface .finish ()
55
87
b = SVGMobject (filename )
56
88
assert len (a .submobjects ) == len (b .submobjects )
89
+
90
+
91
+ def test_whether_svg_file_created ():
92
+ """Checks Whether SVG file is created in desired location"""
93
+ a = PangoText ("hello" , size = 1 )
94
+ folder = os .path .abspath (os .path .join ("media" , "texts" ))
95
+ if not os .path .exists (folder ):
96
+ os .makedirs (folder )
97
+ theoPath = os .path .abspath (os .path .join (folder , a .text2hash () + ".svg" ))
98
+ actualPath = os .path .abspath (a .text2svg ())
99
+ assert theoPath == actualPath
100
+
101
+
102
+ def test_tabs_replace ():
103
+ """Checks whether are there in end svg image. Pango should handle tabs and line breaks."""
104
+ size = 1
105
+ folder = os .path .abspath (os .path .join ("media" , "texts" ))
106
+ if not os .path .exists (folder ):
107
+ os .makedirs (folder )
108
+ a = PangoText ("hello\t hi\n f" )
109
+ assert a .text == "hellohif"
110
+ pangoManim = os .path .join (folder , a .text2hash () + ".svg" )
111
+ filename = os .path .join (folder , "hello.svg" )
112
+ surface = cairocffi .SVGSurface (filename , width , height )
113
+ context = cairocffi .Context (surface )
114
+ context .move_to (START_X , START_Y )
115
+ layout = pangocairocffi .create_layout (context )
116
+ layout .set_width (pangocffi .units_from_double (width ))
117
+ fontdesc = pangocffi .FontDescription ()
118
+ fontdesc .set_size (pangocffi .units_from_double (size * 10 ))
119
+ layout .set_font_description (fontdesc )
120
+ layout .set_text ("hello\t hi\n f" )
121
+ pangocairocffi .show_layout (context , layout )
122
+ surface .finish ()
123
+ b = SVGMobject (filename )
124
+ assert len (a .submobjects ) == len (b .submobjects )
125
+
126
+
127
+ test_tabs_replace ()
0 commit comments