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.cache import cache_on_disk
|
||||||
from manimlib.utils.color import color_to_hex
|
from manimlib.utils.color import color_to_hex
|
||||||
from manimlib.utils.color import int_to_hex
|
from manimlib.utils.color import int_to_hex
|
||||||
|
from manimlib.utils.simple_functions import hash_string
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
@ -74,34 +75,29 @@ def markup_to_svg(
|
||||||
pango_width = line_width / FRAME_WIDTH * DEFAULT_PIXEL_WIDTH
|
pango_width = line_width / FRAME_WIDTH * DEFAULT_PIXEL_WIDTH
|
||||||
|
|
||||||
# Write the result to a temporary svg file, and return it's contents.
|
# 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
|
temp_file = Path(tempfile.gettempdir(), hash_string(markup_str)).with_suffix(".svg")
|
||||||
#
|
manimpango.MarkupUtils.text2svg(
|
||||||
# To avoid CAIRO_STATUS_WRITE_ERROR: b'error while writing to
|
text=markup_str,
|
||||||
# output stream' on Windows, we need to pass 'delete=False'.
|
font="", # Already handled
|
||||||
with tempfile.NamedTemporaryFile(suffix='.svg', mode='r+', delete=False) as tmp:
|
slant="NORMAL", # Already handled
|
||||||
manimpango.MarkupUtils.text2svg(
|
weight="NORMAL", # Already handled
|
||||||
text=markup_str,
|
size=1, # Already handled
|
||||||
font="", # Already handled
|
_=0, # Empty parameter
|
||||||
slant="NORMAL", # Already handled
|
disable_liga=False,
|
||||||
weight="NORMAL", # Already handled
|
file_name=str(temp_file),
|
||||||
size=1, # Already handled
|
START_X=0,
|
||||||
_=0, # Empty parameter
|
START_Y=0,
|
||||||
disable_liga=False,
|
width=DEFAULT_CANVAS_WIDTH,
|
||||||
file_name=tmp.name,
|
height=DEFAULT_CANVAS_HEIGHT,
|
||||||
START_X=0,
|
justify=justify,
|
||||||
START_Y=0,
|
indent=indent,
|
||||||
width=DEFAULT_CANVAS_WIDTH,
|
line_spacing=None, # Already handled
|
||||||
height=DEFAULT_CANVAS_HEIGHT,
|
alignment=alignment,
|
||||||
justify=justify,
|
pango_width=pango_width
|
||||||
indent=indent,
|
)
|
||||||
line_spacing=None, # Already handled
|
result = temp_file.read_text()
|
||||||
alignment=alignment,
|
os.remove(temp_file)
|
||||||
pango_width=pango_width
|
return result
|
||||||
)
|
|
||||||
|
|
||||||
# Read the contents
|
|
||||||
tmp.seek(0)
|
|
||||||
return tmp.read()
|
|
||||||
|
|
||||||
|
|
||||||
class MarkupText(StringMobject):
|
class MarkupText(StringMobject):
|
||||||
|
|
Loading…
Add table
Reference in a new issue