File indexing completed on 2025-01-05 04:01:13
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "avd_format.hpp" 0008 0009 #include "avd_parser.hpp" 0010 #include "io/svg/parse_error.hpp" 0011 #include "avd_renderer.hpp" 0012 0013 glaxnimate::io::Autoreg<glaxnimate::io::avd::AvdFormat> glaxnimate::io::avd::AvdFormat::autoreg; 0014 0015 0016 bool glaxnimate::io::avd::AvdFormat::on_open(QIODevice& file, const QString& filename, model::Document* document, const QVariantMap& options) 0017 { 0018 auto on_error = [this](const QString& s){warning(s);}; 0019 try 0020 { 0021 QSize forced_size = options["forced_size"].toSize(); 0022 model::FrameTime default_time = options["default_time"].toFloat(); 0023 auto resource_path = QFileInfo(filename).dir(); 0024 0025 AvdParser(&file, resource_path, document, on_error, this, forced_size, default_time).parse_to_document(); 0026 return true; 0027 } 0028 catch ( const svg::SvgParseError& err ) 0029 { 0030 error(err.formatted(QFileInfo(filename).baseName())); 0031 return false; 0032 } 0033 } 0034 0035 bool glaxnimate::io::avd::AvdFormat::on_save(QIODevice& file, const QString&, model::Composition* comp, const QVariantMap&) 0036 { 0037 auto on_error = [this](const QString& s){warning(s);}; 0038 AvdRenderer rend(on_error); 0039 rend.render(comp); 0040 auto dom = rend.single_file(); 0041 file.write(dom.toByteArray(4)); 0042 return true; 0043 }