Skip to content

Commit

Permalink
Use __del__ instead of explicit clean to clean font configurations
Browse files Browse the repository at this point in the history
This avoids rendering problems when the @font-face font files were removed
before calling write_pdf, write_image_surface or write_png.
  • Loading branch information
liZe committed Oct 4, 2017
1 parent f10bf7f commit f5367c8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
1 change: 0 additions & 1 deletion weasyprint/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ def _render(cls, html, stylesheets, enable_hinting,
rendering = cls(
[Page(p, enable_hinting) for p in page_boxes],
DocumentMetadata(**html._get_metadata()), html.url_fetcher)
font_config.clean()
return rendering

def __init__(self, pages, metadata, url_fetcher):
Expand Down
6 changes: 2 additions & 4 deletions weasyprint/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ def __init__(self):
def add_font_face(self, rule_descriptors, url_fetcher):
"""Add a font into the application."""

def clean(self):
"""Clean a font configuration after rendering a document."""


if sys.platform.startswith('win'):
warnings.warn('@font-face is currently not supported on Windows')
Expand Down Expand Up @@ -290,7 +287,8 @@ def add_font_face(self, rule_descriptors, url_fetcher):
'Font-face "%s" cannot be loaded',
rule_descriptors['font_family'])

def clean(self):
def __del__(self):
"""Clean a font configuration for a document."""
for filename in self._filenames:
os.remove(filename)
return super(FontConfiguration, self).__del__()

0 comments on commit f5367c8

Please sign in to comment.