@@ -381,6 +381,7 @@ def __init__(self, xy, s, size=None, prop=None,
381
381
size = prop .get_size_in_points ()
382
382
383
383
self ._xy = xy
384
+ self .set_size (size )
384
385
385
386
self ._cached_vertices = None
386
387
s , ismath = Text (usetex = usetex )._preprocess_math (s )
@@ -389,12 +390,11 @@ def __init__(self, xy, s, size=None, prop=None,
389
390
_interpolation_steps = _interpolation_steps ,
390
391
readonly = True )
391
392
self ._should_simplify = False
392
- self .set_size (size )
393
393
394
394
def set_size (self , size ):
395
395
"""Set the text size."""
396
396
self ._size = size
397
- self ._recache_path ()
397
+ self ._invalid = True
398
398
399
399
def get_size (self ):
400
400
"""Get the text size."""
@@ -403,8 +403,9 @@ def get_size(self):
403
403
@property
404
404
def vertices (self ):
405
405
"""
406
- Return the cached path.
406
+ Return the cached path after updating it if necessary .
407
407
"""
408
+ self ._revalidate_path ()
408
409
return self ._cached_vertices
409
410
410
411
@property
@@ -414,15 +415,17 @@ def codes(self):
414
415
"""
415
416
return self ._codes
416
417
417
- def _recache_path (self ):
418
+ def _revalidate_path (self ):
418
419
"""
419
- Update the path.
420
+ Update the path if necessary .
420
421
421
- The path for the text is initially created with the font size of
422
+ The path for the text is initially create with the font size of
422
423
`.FONT_SCALE`, and this path is rescaled to other size when necessary.
423
424
"""
424
- tr = (Affine2D ()
425
- .scale (self ._size / text_to_path .FONT_SCALE )
426
- .translate (* self ._xy ))
427
- self ._cached_vertices = tr .transform (self ._vertices )
428
- self ._cached_vertices .flags .writeable = False
425
+ if self ._invalid or self ._cached_vertices is None :
426
+ tr = (Affine2D ()
427
+ .scale (self ._size / text_to_path .FONT_SCALE )
428
+ .translate (* self ._xy ))
429
+ self ._cached_vertices = tr .transform (self ._vertices )
430
+ self ._cached_vertices .flags .writeable = False
431
+ self ._invalid = False
0 commit comments