@@ -123,6 +123,7 @@ def __init__(self, width, height, dpi):
123123 self .cache = self ._renderer .cache
124124 self .blit = self ._renderer .blit
125125 self .texmanager = TexManager ()
126+ self .texd = {} # a cache of tex image rasters
126127 self .bbox = lbwh_to_bbox (0 ,0 , self .width , self .height )
127128
128129
@@ -254,27 +255,33 @@ def draw_tex(self, gc, x, y, s, prop, angle):
254255
255256 flip = angle == 90
256257 w ,h = self .get_text_width_height (s , prop , 'TeX' , rgb )
257-
258- Z = self .texmanager .get_rgba (s , size , dpi , rgb )
259258 if flip :
260259 w ,h = h ,w
261260 x -= w
262- r = Z [:,:,0 ]
263- g = Z [:,:,1 ]
264- b = Z [:,:,2 ]
265- a = Z [:,:,3 ]
266- m ,n ,tmp = Z .shape
267-
268- def func (x ):
269- return transpose (fliplr (x ))
270-
271- Z = zeros ((n ,m ,4 ), typecode = Float )
272- Z [:,:,0 ] = func (r )
273- Z [:,:,1 ] = func (g )
274- Z [:,:,2 ] = func (b )
275- Z [:,:,3 ] = func (a )
276-
277- im = fromarray (Z , 1 )
261+
262+ key = s , size , dpi , rgb
263+ im = self .texd .get (key )
264+
265+ if im is None :
266+ Z = self .texmanager .get_rgba (s , size , dpi , rgb )
267+ if flip :
268+ r = Z [:,:,0 ]
269+ g = Z [:,:,1 ]
270+ b = Z [:,:,2 ]
271+ a = Z [:,:,3 ]
272+ m ,n ,tmp = Z .shape
273+
274+ def func (x ):
275+ return transpose (fliplr (x ))
276+
277+ Z = zeros ((n ,m ,4 ), typecode = Float )
278+ Z [:,:,0 ] = func (r )
279+ Z [:,:,1 ] = func (g )
280+ Z [:,:,2 ] = func (b )
281+ Z [:,:,3 ] = func (a )
282+ im = fromarray (Z , 1 )
283+ self .texd [key ] = im
284+
278285 self .draw_image (x , y - h , im , 'upper' , self .bbox )
279286
280287 def get_canvas_width_height (self ):
0 commit comments