@@ -607,7 +607,10 @@ def _text2hash(self, color: Color):
607
607
return hasher .hexdigest ()[:16 ]
608
608
609
609
def _merge_settings (
610
- self , left_setting : TextSetting , right_setting : TextSetting , args : Sequence [str ]
610
+ self ,
611
+ left_setting : TextSetting ,
612
+ right_setting : TextSetting ,
613
+ default_args : dict [str , Iterable [str ]],
611
614
) -> TextSetting :
612
615
contained = right_setting .end < left_setting .end
613
616
new_setting = copy .copy (left_setting ) if contained else copy .copy (right_setting )
@@ -617,10 +620,10 @@ def _merge_settings(
617
620
if not contained :
618
621
right_setting .end = new_setting .start
619
622
620
- for arg in args :
623
+ for arg in default_args :
621
624
left = getattr (left_setting , arg )
622
625
right = getattr (right_setting , arg )
623
- default = getattr ( self , arg )
626
+ default = default_args [ arg ]
624
627
if left != default and getattr (right_setting , arg ) != default :
625
628
raise ValueError (
626
629
f"Ambiguous style for text '{ self .text [right_setting .start :right_setting .end ]} ':"
@@ -630,13 +633,15 @@ def _merge_settings(
630
633
return new_setting
631
634
632
635
def _get_settings_from_t2xs (
633
- self , t2xs : Sequence [tuple [dict [str , str ], str ]]
636
+ self ,
637
+ t2xs : Sequence [tuple [dict [str , str ], str ]],
638
+ default_args : dict [str , Iterable [str ]],
634
639
) -> Sequence [TextSetting ]:
635
640
settings = []
636
641
t2xwords = set (chain (* ([* t2x .keys ()] for t2x , _ in t2xs )))
637
642
for word in t2xwords :
638
643
setting_args = {
639
- arg : t2x [word ] if word in t2x else getattr ( self , arg )
644
+ arg : t2x [word ] if word in t2x else default_args [ arg ]
640
645
for t2x , arg in t2xs
641
646
}
642
647
@@ -645,10 +650,10 @@ def _get_settings_from_t2xs(
645
650
return settings
646
651
647
652
def _get_settings_from_gradient (
648
- self , setting_args : dict [str , Iterable [str ]]
653
+ self , default_args : dict [str , Iterable [str ]]
649
654
) -> Sequence [TextSetting ]:
650
655
settings = []
651
- args = copy .copy (setting_args )
656
+ args = copy .copy (default_args )
652
657
if self .gradient :
653
658
colors = color_gradient (self .gradient , len (self .text ))
654
659
for i in range (len (self .text )):
@@ -678,12 +683,12 @@ def _text2settings(self, color: Color):
678
683
(self .t2w , "weight" ),
679
684
(self .t2c , "color" ),
680
685
]
681
- setting_args = {
686
+ default_args = {
682
687
arg : getattr (self , arg ) if arg != "color" else color for _ , arg in t2xs
683
688
}
684
689
685
- settings = self ._get_settings_from_t2xs (t2xs )
686
- settings .extend (self ._get_settings_from_gradient (setting_args ))
690
+ settings = self ._get_settings_from_t2xs (t2xs , default_args )
691
+ settings .extend (self ._get_settings_from_gradient (default_args ))
687
692
688
693
# Handle overlaps
689
694
@@ -694,7 +699,7 @@ def _text2settings(self, color: Color):
694
699
695
700
next_setting = settings [index + 1 ]
696
701
if setting .end > next_setting .start :
697
- new_setting = self ._merge_settings (setting , next_setting , setting_args )
702
+ new_setting = self ._merge_settings (setting , next_setting , default_args )
698
703
new_index = index + 1
699
704
while (
700
705
new_index < len (settings )
@@ -708,10 +713,10 @@ def _text2settings(self, color: Color):
708
713
start = 0
709
714
for setting in settings :
710
715
if setting .start != start :
711
- temp_settings .append (TextSetting (start , setting .start , ** setting_args ))
716
+ temp_settings .append (TextSetting (start , setting .start , ** default_args ))
712
717
start = setting .end
713
718
if start != len (self .text ):
714
- temp_settings .append (TextSetting (start , len (self .text ), ** setting_args ))
719
+ temp_settings .append (TextSetting (start , len (self .text ), ** default_args ))
715
720
settings = sorted (temp_settings , key = lambda setting : setting .start )
716
721
717
722
if re .search (r"\n" , self .text ):
0 commit comments