3
3
__all__ = ["Text" , "Paragraph" , "PangoText" , "CairoText" ]
4
4
5
5
6
- import re
7
- import os
8
6
import copy
9
7
import hashlib
8
+ import os
9
+ import re
10
+
10
11
import cairo
11
- import pangocffi
12
- import pangocairocffi
13
12
import cairocffi
13
+ import pangocairocffi
14
+ import pangocffi
14
15
15
16
from ... import config , file_writer_config , logger
16
17
from ...constants import *
@@ -390,6 +391,7 @@ def text2svg1(self):
390
391
surface .finish ()
391
392
return file_name
392
393
394
+
393
395
class Paragraph (VGroup ):
394
396
r"""Display a paragraph of text.
395
397
@@ -637,7 +639,7 @@ def construct(self):
637
639
"tab_width" : 4 ,
638
640
}
639
641
640
- def __init__ (self , text : str , ** config ):
642
+ def __init__ (self , text : str , ** config ): # pylint: disable=redefined-outer-name
641
643
self .full2short (config )
642
644
digest_config (self , config )
643
645
self .original_text = text
@@ -682,20 +684,20 @@ def __init__(self, text: str, **config):
682
684
if self .height is None and self .width is None :
683
685
self .scale (TEXT_MOB_SCALE_FACTOR )
684
686
685
- def remove_last_M (self , file_name : str ): # pylint: disable=invalid-name
687
+ def remove_last_M (self , file_name : str ): # pylint: disable=invalid-name
686
688
"""Internally used. Use to format the rendered SVG files."""
687
689
with open (file_name , "r" ) as fpr :
688
690
content = fpr .read ()
689
691
content = re .sub (r'Z M [^A-Za-z]*? "\/>' , 'Z "/>' , content )
690
692
with open (file_name , "w" ) as fpw :
691
693
fpw .write (content )
692
694
693
- def find_indexes (self , word , text ):
695
+ def find_indexes (self , word : str , text : str ):
694
696
"""Internally used function. Finds the indexes of ``text`` in ``word``."""
695
- m = re .match (r"\[([0-9\-]{0,}):([0-9\-]{0,})\]" , word )
696
- if m :
697
- start = int (m .group (1 )) if m .group (1 ) != "" else 0
698
- end = int (m .group (2 )) if m .group (2 ) != "" else len (text )
697
+ temp = re .match (r"\[([0-9\-]{0,}):([0-9\-]{0,})\]" , word )
698
+ if temp :
699
+ start = int (temp .group (1 )) if temp .group (1 ) != "" else 0
700
+ end = int (temp .group (2 )) if temp .group (2 ) != "" else len (text )
699
701
start = len (text ) + start if start < 0 else start
700
702
end = len (text ) + end if end < 0 else end
701
703
return [(start , end )]
@@ -706,7 +708,7 @@ def find_indexes(self, word, text):
706
708
index = text .find (word , index + len (word ))
707
709
return indexes
708
710
709
- def full2short (self , config ):
711
+ def full2short (self , config ): # pylint: disable=redefined-outer-name
710
712
"""Internally used function. Fomats some exapansion to short forms.
711
713
text2color -> t2c
712
714
text2font -> t2f
@@ -778,6 +780,8 @@ def str2weight(self, string):
778
780
return pangocffi .Weight .HEAVY
779
781
elif string == ULTRAHEAVY :
780
782
return pangocffi .Weight .ULTRAHEAVY
783
+ else :
784
+ raise AttributeError ("There is no Font Weight Called %s" % string )
781
785
782
786
def text2hash (self ):
783
787
"""Internally used function.
@@ -794,7 +798,8 @@ def text2hash(self):
794
798
return hasher .hexdigest ()[:16 ]
795
799
796
800
def text2settings (self ):
797
- """Internally used function. Converts the texts and styles to a setting for parsing."""
801
+ """Internally used function. Converts the texts and styles
802
+ to a setting for parsing."""
798
803
settings = []
799
804
t2x = [self .t2f , self .t2s , self .t2w ]
800
805
for i in range (len (t2x )):
0 commit comments