File indexing completed on 2025-02-02 04:10:05

0001 # SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0002 # SPDX-License-Identifier: GPL-3.0-or-later
0003 import io
0004 import json
0005 import gzip
0006 
0007 from lottie.parsers.sif import parse_sif_file
0008 from lottie.parsers.sif.builder import to_sif
0009 from lottie.objects.animation import Animation
0010 
0011 import glaxnimate
0012 
0013 
0014 def save_synfig(window, document, file, fname, import_export, settings):
0015     lottie_str = glaxnimate.io.registry["lottie"].save(document)
0016     lottie_dict = json.loads(lottie_str)
0017     animation = Animation.load(lottie_dict)
0018     dom = to_sif(animation).to_xml()
0019     compressed = fname.endswith("sifz")
0020     fp = io.StringIO()
0021     dom.writexml(fp, "", "  ", "\n", "utf-8")
0022     if compressed:
0023         with gzip.open(file, "wb") as gzfile:
0024             gzfile.write(fp.getvalue().encode("utf-8"))
0025     else:
0026         file.write(fp.getvalue().encode("utf-8"))
0027 
0028 
0029 def open_synfig(window, document, file, fname, import_export, settings):
0030     animation = parse_sif_file(file)
0031     lottie_str = json.dumps(animation.to_dict()).encode("utf-8")
0032     glaxnimate.io.registry["lottie"].load(document, lottie_str)