1 /* === S Y N F I G ========================================================= */
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === S T A R T =========================================================== */
26 #ifndef __SYNFIG_LOADCANVAS_H
27 #define __SYNFIG_LOADCANVAS_H
29 /* === H E A D E R S ======================================================= */
33 #include "valuenode.h"
36 #include "valuenode_subtract.h"
37 #include "valuenode_animated.h"
38 #include "valuenode_composite.h"
39 #include "valuenode_dynamiclist.h"
43 /* === M A C R O S ========================================================= */
45 /* === T Y P E D E F S ===================================================== */
47 /* === C L A S S E S & S T R U C T S ======================================= */
49 namespace xmlpp { class Node; class Element; };
53 /*! \class CanvasParser
59 -- ** -- D A T A -------------------------------------------------------------
79 -- ** -- C O N S T R U C T O R S ---------------------------------------------
92 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
98 CanvasParser &set_allow_errors(bool x) { allow_errors_=x; return *this; }
100 //! Sets the maximum number of warnings before a fatal error is thrown
101 CanvasParser &set_max_warnings(int i) { max_warnings_=i; return *this; }
103 //! Returns the maximum number of warnings before a fatal_error is thrown
104 int get_max_warnings() { return max_warnings_; }
106 //! Returns the number of errors in the last parse
107 int error_count()const { return total_errors_; }
109 //! Returns the number of warnings in the last parse
110 int warning_count()const { return total_warnings_; }
112 void set_path(const synfig::String& x) { path=x; }
114 const synfig::String& get_path()const { return path; }
117 Canvas::Handle parse_from_file(const String &filename);
119 Canvas::Handle parse_from_file_as(const String &filename,const String &as);
122 Canvas::Handle parse_from_string(const String &data);
126 // Error/Warning handling functions
128 void error(xmlpp::Node *node,const String &text);
129 void fatal_error(xmlpp::Node *node,const String &text);
130 void warning(xmlpp::Node *node,const String &text);
131 void error_unexpected_element(xmlpp::Node *node,const String &got, const String &expected);
132 void error_unexpected_element(xmlpp::Node *node,const String &got);
136 Canvas::Handle parse_canvas(xmlpp::Element *node,Canvas::Handle parent=0,bool inline_=false, String path=".");
137 void parse_canvas_defs(xmlpp::Element *node,Canvas::Handle canvas);
138 etl::handle<Layer> parse_layer(xmlpp::Element *node,Canvas::Handle canvas);
139 ValueBase parse_value(xmlpp::Element *node,Canvas::Handle canvas);
140 etl::handle<ValueNode> parse_value_node(xmlpp::Element *node,Canvas::Handle canvas);
142 // ValueBase Parsing Functions
144 Real parse_real(xmlpp::Element *node);
145 Time parse_time(xmlpp::Element *node,Canvas::Handle canvas);
146 int parse_integer(xmlpp::Element *node);
147 Vector parse_vector(xmlpp::Element *node);
148 Color parse_color(xmlpp::Element *node);
149 Angle parse_angle(xmlpp::Element *node);
150 String parse_string(xmlpp::Element *node);
151 bool parse_bool(xmlpp::Element *node);
152 Segment parse_segment(xmlpp::Element *node);
153 ValueBase parse_list(xmlpp::Element *node,Canvas::Handle canvas);
154 Gradient parse_gradient(xmlpp::Element *node);
155 BLinePoint parse_bline_point(xmlpp::Element *node);
157 Keyframe parse_keyframe(xmlpp::Element *node,Canvas::Handle canvas);
159 // ValueNode Parsing Functions
161 etl::handle<ValueNode_Animated> parse_animated(xmlpp::Element *node,Canvas::Handle canvas);
162 etl::handle<ValueNode_Subtract> parse_subtract(xmlpp::Element *node,Canvas::Handle canvas);
163 etl::handle<LinkableValueNode> parse_linkable_value_node(xmlpp::Element *node,Canvas::Handle canvas);
164 etl::handle<ValueNode_Composite> parse_composite(xmlpp::Element *node,Canvas::Handle canvas);
165 etl::handle<ValueNode_DynamicList> parse_dynamic_list(xmlpp::Element *node,Canvas::Handle canvas);
167 }; // END of CanvasParser
169 /* === E X T E R N S ======================================================= */
171 //! Loads a canvas from \a filename
172 /*! \return The Canvas's handle on success, an empty handle on failure */
173 extern Canvas::Handle open_canvas(const String &filename);
174 extern Canvas::Handle open_canvas_as(const String &filename,const String &as);
176 //! Retrieves a Canvas from a string in XML format
177 extern Canvas::Handle string_to_canvas(const String &data);
179 std::map<synfig::String, etl::loose_handle<Canvas> >& get_open_canvas_map();
181 }; // END of namespace synfig
183 /* === E N D =============================================================== */