File indexing completed on 2025-01-05 04:01:20

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <vector>
0011 #include <exception>
0012 #include <QIODevice>
0013 
0014 #include "io/mime/mime_serializer.hpp"
0015 #include "io/base.hpp"
0016 
0017 namespace glaxnimate::model {
0018     class Composition;
0019     class Document;
0020     class DocumentNode;
0021     class Object;
0022 } // namespace glaxnimate::model
0023 
0024 
0025 namespace glaxnimate::io::svg {
0026 
0027 class SvgParser
0028 {
0029 public:
0030     // How to parse <g> elements
0031     enum GroupMode
0032     {
0033         Groups,     ///< As group shapes
0034         Layers,     ///< As shape layers
0035         Inkscape,   ///< Follow inkscape:groupmode
0036     };
0037 
0038     /**
0039      * \throws SvgParseError on error
0040      */
0041     SvgParser(
0042         QIODevice* device,
0043         GroupMode group_mode,
0044         model::Document* document,
0045         const std::function<void(const QString&)>& on_warning = {},
0046         ImportExport* io = nullptr,
0047         QSize forced_size = {},
0048         model::FrameTime default_time = 180,
0049         QDir default_asset_path = {}
0050     );
0051     ~SvgParser();
0052 
0053     void parse_to_document();
0054     io::mime::DeserializedData parse_to_objects();
0055 
0056     class Private;
0057 private:
0058     std::unique_ptr<Private> d;
0059 };
0060 
0061 /**
0062  * \brief Parses a CSS color string
0063  * \see https://www.w3.org/wiki/CSS/Properties/color
0064  */
0065 QColor parse_color(const QString& color_str);
0066 
0067 } // namespace glaxnimate::io::svg