~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to backend/PathParser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2008-10-13 14:29:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081013142949-f6qdvnu4mn05ltdc
Tags: 0.8.4~~bzr9980-0ubuntu1
* new upstream release 0.8.4 (LP: #240325)
* ship new lib usr/lib/gnash/libmozsdk.so.* in mozilla-plugin-gnash
  - update debian/mozilla-plugin-gnash.install
* ship new lib usr/lib/gnash/libgnashnet.so.* in gnash-common
  - update debian/gnash-common.install
* add basic debian/build_head script to build latest CVS head packages.
  - add debian/build_head
* new sound architecture requires build depend on libsdl1.2-dev
  - update debian/control
* head build script now has been completely migrated to bzr (upstream +
  ubuntu)
  - update debian/build_head
* disable kde gui until klash/qt4 has been fixed; keep kde packages as empty
  packages for now.
  - update debian/rules
  - debian/klash.install
  - debian/klash.links
  - debian/klash.manpages
  - debian/konqueror-plugin-gnash.install
* drop libkonq5-dev build dependency accordingly
  - update debian/control
* don't install headers manually anymore. gnash doesnt provide a -dev
  package after all
  - update debian/rules
* update libs installed in gnash-common; libgnashserver-*.so is not available
  anymore (removed); in turn we add the new libgnashcore-*.so
  - update debian/gnash-common.install
* use -Os for optimization and properly pass CXXFLAGS=$(CFLAGS) to configure
  - update debian/rules
* touch firefox .autoreg in postinst of mozilla plugin
  - update debian/mozilla-plugin-gnash.postinst
* link gnash in ubufox plugins directory for the plugin alternative switcher
  - add debian/mozilla-plugin-gnash.links
* suggest ubufox accordingly
  - update debian/control
* add new required build-depends on libgif-dev
  - update debian/control
* add Xb-Npp-Description and Xb-Npp-File as new plugin database meta data
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
3
// 
 
4
// This program is free software; you can redistribute it and/or modify
 
5
// it under the terms of the GNU General Public License as published by
 
6
// the Free Software Foundation; either version 3 of the License, or
 
7
// (at your option) any later version.
 
8
// 
 
9
// This program is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
// GNU General Public License for more details.
 
13
// 
 
14
// You should have received a copy of the GNU General Public License
 
15
// along with this program; if not, write to the Free Software
 
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
17
//
 
18
 
 
19
#include <boost/utility.hpp>
 
20
#include "PathParser.h"
 
21
#include <map>
 
22
#include <boost/bind.hpp>
 
23
 
 
24
namespace gnash
 
25
{
 
26
 
 
27
const point&
 
28
UnivocalPath::startPoint() const
 
29
{
 
30
  return _fill_type == FILL_LEFT ? _path->ap : _path->m_edges.back().ap;
 
31
}
 
32
 
 
33
const point&
 
34
UnivocalPath::endPoint() const
 
35
{
 
36
  return _fill_type == FILL_LEFT ? _path->m_edges.back().ap : _path->ap;
 
37
}
 
38
 
 
39
PathParser::PathParser(const std::vector<path>& paths, size_t numstyles)
 
40
: _paths(paths),
 
41
  _num_styles(numstyles),
 
42
  _shape_origin(0, 0),
 
43
  _cur_endpoint(0, 0)
 
44
{}
 
45
 
 
46
void
 
47
PathParser::run(const cxform& cx, const matrix& mat)
 
48
{
 
49
  // Since we frequently remove an element from the front or the back, we use
 
50
  // a double ended queue here.
 
51
  typedef std::deque<UnivocalPath> UniPathList;
 
52
 
 
53
  std::vector<UniPathList> unipathvec(_num_styles);
 
54
 
 
55
  for (size_t i = 0; i < _paths.size(); ++i) {
 
56
  
 
57
    if (_paths[i].is_empty()) {
 
58
      continue;
 
59
    }
 
60
 
 
61
    int leftfill = _paths[i].getLeftFill();
 
62
    if (leftfill) {
 
63
      unipathvec[leftfill-1].push_front(UnivocalPath(&_paths[i], UnivocalPath::FILL_LEFT));
 
64
    }
 
65
 
 
66
    int rightfill = _paths[i].getRightFill();
 
67
    if (rightfill) {
 
68
      unipathvec[rightfill-1].push_front(UnivocalPath(&_paths[i], UnivocalPath::FILL_RIGHT));
 
69
    }
 
70
  }
 
71
 
 
72
  for (size_t i = 0; i < _num_styles; ++i) {
 
73
 
 
74
    start_shapes(i+1, cx);
 
75
    UniPathList& path_list = unipathvec[i];
 
76
      
 
77
    while (!path_list.empty()) {
 
78
 
 
79
      if (closed_shape()) {
 
80
        reset_shape(path_list.front());
 
81
        path_list.pop_front();
 
82
      }
 
83
 
 
84
      UniPathList::iterator it = emitConnecting(path_list);
 
85
     
 
86
      if (it == path_list.end()) {
 
87
        if (!closed_shape()) {
 
88
          std::cout << "error: path not closed!" << std::endl;
 
89
          _cur_endpoint = _shape_origin;
 
90
        }
 
91
      } else {
 
92
        path_list.erase(it);
 
93
      }
 
94
 
 
95
    }
 
96
    end_shapes(i+1);
 
97
  }
 
98
 
 
99
}
 
100
 
 
101
std::deque<UnivocalPath>::iterator
 
102
PathParser::emitConnecting(std::deque<UnivocalPath>& paths)
 
103
{
 
104
  std::deque<UnivocalPath>::iterator it = paths.begin(),
 
105
                                     end = paths.end();
 
106
  while (it != end) {
 
107
 
 
108
    if ((*it).startPoint() == _cur_endpoint) {
 
109
      break;
 
110
    }
 
111
 
 
112
    ++it;
 
113
  }
 
114
 
 
115
  if (it != end) {
 
116
    append(*it);
 
117
  }
 
118
  return it;
 
119
}
 
120
 
 
121
void
 
122
PathParser::append(const UnivocalPath& append_path)
 
123
{
 
124
  const std::vector<Edge>& edges = append_path._path->m_edges;
 
125
 
 
126
  if (append_path._fill_type == UnivocalPath::FILL_LEFT) {
 
127
 
 
128
    std::for_each(edges.begin(), edges.end(), boost::bind(&PathParser::line_to,
 
129
                                                          this, _1));
 
130
  } else {
 
131
 
 
132
    for (std::vector<edge>::const_reverse_iterator prev = edges.rbegin(),
 
133
         it = boost::next(prev), end = edges.rend(); it != end; ++it, ++prev) {
 
134
      if ((*prev).isStraight()) {
 
135
        lineTo((*it).ap);
 
136
      } else {
 
137
        line_to(Edge((*prev).cp, (*it).ap));
 
138
      }
 
139
    }
 
140
 
 
141
    line_to(Edge(edges.front().cp, append_path.endPoint()));
 
142
  }
 
143
    
 
144
  _cur_endpoint = append_path.endPoint();
 
145
}
 
146
 
 
147
void
 
148
PathParser::line_to(const edge& curve)
 
149
{
 
150
  if (curve.isStraight()) {
 
151
    lineTo(curve.ap);
 
152
  } else {
 
153
    curveTo(curve);
 
154
  }
 
155
}
 
156
 
 
157
void
 
158
PathParser::start_shapes(int fill_style, const cxform& cx)
 
159
{
 
160
  prepareFill(fill_style, cx);
 
161
}
 
162
 
 
163
void
 
164
PathParser::end_shapes(int fill_style)
 
165
{
 
166
  terminateFill(fill_style);
 
167
}
 
168
 
 
169
void
 
170
PathParser::reset_shape(const UnivocalPath& append_path)
 
171
{
 
172
  fillShape();
 
173
  
 
174
  _shape_origin = append_path.startPoint();
 
175
 
 
176
  moveTo(_shape_origin);
 
177
 
 
178
  append(append_path);
 
179
}
 
180
 
 
181
bool
 
182
PathParser::closed_shape()
 
183
{
 
184
  return _cur_endpoint == _shape_origin;
 
185
}
 
186
 
 
187
 
 
188
} // namespace gnash