Merge branch 'master' of git://git.sv.gnu.org/gnash
[gnash.git] / librender / PathParser.h
blobc16e733c0bf3b278f5747ffeb18a8a53ee7bb472
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef GNASH_PATH_PARSER_H
20 #define GNASH_PATH_PARSER_H
22 #include "Geometry.h"
23 #include <vector>
24 #include <deque>
25 #include "SWFCxForm.h"
27 namespace gnash
30 /// Wraps a path, indicating whether we consider the left or the right of
31 /// the fill.
32 struct UnivocalPath
34 enum fill_type
36 FILL_RIGHT,
37 FILL_LEFT
40 UnivocalPath() : _path(NULL), _fill_type(FILL_LEFT) {}
42 UnivocalPath(const Path* path, fill_type filltype)
43 : _path(path),
44 _fill_type(filltype)
48 const point& startPoint() const;
49 const point& endPoint() const;
51 const Path* _path;
52 fill_type _fill_type;
55 /// PathParser is a class which aims to efficiently transpose Flash paths into
56 /// well formed, single-filled shapes.
58 /// A renderer should utilize this class by subclassing PathParser. The methods
59 /// reimplemented will receive low level path information (e.g., moveTo).
60 class PathParser : boost::noncopyable
62 public:
63 /// @param paths list of Flash paths to be 'parsed'.
64 /// @param num_styles count of fill styles pointed to by the first argument.
65 PathParser(const std::vector<Path>& paths, size_t num_styles);
67 virtual ~PathParser() { }
69 /// Runs the path parser, invoking the pure virtual methods where
70 /// appropriate.
71 /// @param cx the color transform that will be passed to prepareFill.
72 /// @param mat the SWFMatrix that will be passed to prepareFill.
73 void run(const SWFCxForm& cx, const SWFMatrix& mat);
75 /// Prepare the fill style for subsequent use for filling one or more shapes.
76 /// @param fill_style fill style number, as indicated by class Path.
77 virtual void prepareFill(int fill_style, const SWFCxForm& cx) = 0;
79 /// Terminates the fill style, that is, precludes the fill style from further
80 /// use, which may be freed or otherwise cleaned up. Most renderers should
81 /// fill the paths previously parsed.
82 virtual void terminateFill(int fill_style) = 0;
84 /// Fill a single shape. Implementation is optional, because most renderers
85 /// can handle multiple well-formed, singly-filled shapes and can do the
86 /// render/fill stage during terminateFill(). However, those that can't may
87 /// implement this method.
88 virtual void fillShape()
92 /// Move the path pencil to the given location. Thus a new shape should be
93 /// started. The parser may invoke this method several times for a single
94 /// fill style, creating several shapes.
95 virtual void moveTo(const point& p) = 0;
97 /// Draw the given curve using the path pencil.
98 virtual void curveTo(const Edge& curve) = 0;
100 /// Draw a straight line to the given point.
101 virtual void lineTo(const point& p) = 0;
103 private:
104 std::deque<UnivocalPath>::iterator emitConnecting(std::deque<UnivocalPath>& paths);
106 void append(const UnivocalPath& append_path);
108 void start_shapes(int fill_style, const SWFCxForm& cx);
110 void end_shapes(int fill_style);
112 void reset_shape(const UnivocalPath& append_path);
114 bool closed_shape();
116 void line_to(const Edge& curve);
118 const std::vector<Path>& _paths;
119 const size_t _num_styles;
120 point _shape_origin;
121 point _cur_endpoint;
126 #endif // __PATH_PARSER_H