From b19d236830f01641503892ffb0b6ec80c7043fbf Mon Sep 17 00:00:00 2001 From: Justis Peters Date: Wed, 20 Jun 2012 00:51:53 -0400 Subject: [PATCH 1/2] added ability to write to an existing pygame.Surface --- pytagcloud/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pytagcloud/__init__.py b/pytagcloud/__init__.py index aabe01d..3433543 100755 --- a/pytagcloud/__init__.py +++ b/pytagcloud/__init__.py @@ -349,8 +349,11 @@ def create_tag_image( fontname=fontname, rectangular=rectangular) - image_surface = Surface((sizeRect.w, sizeRect.h), SRCALPHA, 32) - image_surface.fill(background) + if type(output) == pygame.Surface: + image_surface = output + else: + image_surface = Surface((sizeRect.w, sizeRect.h), SRCALPHA, 32) + image_surface.fill(background) for tag in tag_store: image_surface.blit(tag.image, tag.rect) pygame.image.save(image_surface, output) From cec155b70ab51f865093839f9f200c07f62c1cb5 Mon Sep 17 00:00:00 2001 From: Justis Peters Date: Thu, 21 Jun 2012 00:09:48 -0400 Subject: [PATCH 2/2] Use get_font inside of update_fontsize(), so that it uses the cache for repeated reloads of the same font. This fixed an issue I had with it crashing when repeatedly rendering the same cloud in a loop. This may also fix https://github.com/atizo/PyTagCloud/issues/6 --- pytagcloud/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pytagcloud/__init__.py b/pytagcloud/__init__.py index 3433543..6bc1830 100755 --- a/pytagcloud/__init__.py +++ b/pytagcloud/__init__.py @@ -97,8 +97,7 @@ def rotate(self, angle): self._update_mask() def update_fontsize(self): - self.font = font.Font(os.path.join(FONT_DIR, self.font_spec['ttf']), - self.tag['size']) + self.font = get_font(self.font_spec, self.tag['size']) def load_font(name): for font in FONT_CACHE: