mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Ensure temporary svg paths for Text are deleted
Some checks are pending
docs / build up document and deploy (push) Waiting to run
Some checks are pending
docs / build up document and deploy (push) Waiting to run
This commit is contained in:
parent
482a055567
commit
1566ce2435
1 changed files with 24 additions and 28 deletions
|
@ -20,6 +20,7 @@ from manimlib.mobject.svg.string_mobject import StringMobject
|
|||
from manimlib.utils.cache import cache_on_disk
|
||||
from manimlib.utils.color import color_to_hex
|
||||
from manimlib.utils.color import int_to_hex
|
||||
from manimlib.utils.simple_functions import hash_string
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
|
@ -74,34 +75,29 @@ def markup_to_svg(
|
|||
pango_width = line_width / FRAME_WIDTH * DEFAULT_PIXEL_WIDTH
|
||||
|
||||
# Write the result to a temporary svg file, and return it's contents.
|
||||
# TODO, better would be to have this not write to file at all
|
||||
#
|
||||
# To avoid CAIRO_STATUS_WRITE_ERROR: b'error while writing to
|
||||
# output stream' on Windows, we need to pass 'delete=False'.
|
||||
with tempfile.NamedTemporaryFile(suffix='.svg', mode='r+', delete=False) as tmp:
|
||||
manimpango.MarkupUtils.text2svg(
|
||||
text=markup_str,
|
||||
font="", # Already handled
|
||||
slant="NORMAL", # Already handled
|
||||
weight="NORMAL", # Already handled
|
||||
size=1, # Already handled
|
||||
_=0, # Empty parameter
|
||||
disable_liga=False,
|
||||
file_name=tmp.name,
|
||||
START_X=0,
|
||||
START_Y=0,
|
||||
width=DEFAULT_CANVAS_WIDTH,
|
||||
height=DEFAULT_CANVAS_HEIGHT,
|
||||
justify=justify,
|
||||
indent=indent,
|
||||
line_spacing=None, # Already handled
|
||||
alignment=alignment,
|
||||
pango_width=pango_width
|
||||
)
|
||||
|
||||
# Read the contents
|
||||
tmp.seek(0)
|
||||
return tmp.read()
|
||||
temp_file = Path(tempfile.gettempdir(), hash_string(markup_str)).with_suffix(".svg")
|
||||
manimpango.MarkupUtils.text2svg(
|
||||
text=markup_str,
|
||||
font="", # Already handled
|
||||
slant="NORMAL", # Already handled
|
||||
weight="NORMAL", # Already handled
|
||||
size=1, # Already handled
|
||||
_=0, # Empty parameter
|
||||
disable_liga=False,
|
||||
file_name=str(temp_file),
|
||||
START_X=0,
|
||||
START_Y=0,
|
||||
width=DEFAULT_CANVAS_WIDTH,
|
||||
height=DEFAULT_CANVAS_HEIGHT,
|
||||
justify=justify,
|
||||
indent=indent,
|
||||
line_spacing=None, # Already handled
|
||||
alignment=alignment,
|
||||
pango_width=pango_width
|
||||
)
|
||||
result = temp_file.read_text()
|
||||
os.remove(temp_file)
|
||||
return result
|
||||
|
||||
|
||||
class MarkupText(StringMobject):
|
||||
|
|
Loading…
Add table
Reference in a new issue