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

« back to all changes in this revision

Viewing changes to libcore/swf/DefineMorphShapeTag.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sindhudweep Narayan Sarkar
  • Date: 2009-10-07 00:06:10 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091007000610-mj9rwqe774gizn1j
Tags: 0.8.6-0ubuntu1
new upstream release 0.8.6 (LP: #435897)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// DefineMorphShapeTag.cpp:   Load and parse morphing shapes, for Gnash.
 
2
//
 
3
//   Copyright (C) 2006, 2007, 2008, 2009 Free Software 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
 
18
//
 
19
 
 
20
 
 
21
// Based on the public domain morph.cpp of:
 
22
// Thatcher Ulrich <tu@tulrich.com>, Mike Shaver <shaver@off.net> 2003,
 
23
// Vitalij Alexeev <tishka92@mail.ru> 2004.
 
24
 
 
25
#include "DefineMorphShapeTag.h"
 
26
#include "MorphShape.h"
 
27
#include "SWFStream.h"
 
28
#include "movie_definition.h"
 
29
#include "MovieClip.h"
 
30
#include "GnashNumeric.h"
 
31
#include "RunResources.h"
 
32
 
 
33
namespace gnash {
 
34
namespace SWF {
 
35
 
 
36
void
 
37
DefineMorphShapeTag::loader(SWFStream& in, TagType tag, movie_definition& md,
 
38
        const RunResources& r)
 
39
{
 
40
    in.ensureBytes(2);
 
41
    boost::uint16_t id = in.read_u16();
 
42
 
 
43
    IF_VERBOSE_PARSE(
 
44
            log_parse("DefineMorphShapeTag: id = %d", id);
 
45
    );
 
46
 
 
47
    DefineMorphShapeTag* morph = new DefineMorphShapeTag(in, tag, md, r);
 
48
    md.addDisplayObject(id, morph);
 
49
}
 
50
 
 
51
DefineMorphShapeTag::DefineMorphShapeTag(SWFStream& in, TagType tag,
 
52
        movie_definition& md, const RunResources& r)
 
53
{
 
54
    read(in, tag, md, r);
 
55
}
 
56
 
 
57
DisplayObject*
 
58
DefineMorphShapeTag::createDisplayObject(DisplayObject* parent, int id) const
 
59
{
 
60
    return new MorphShape(this, parent, id);
 
61
}
 
62
 
 
63
void
 
64
DefineMorphShapeTag::display(Renderer& renderer, const MorphShape& inst) const
 
65
{
 
66
    renderer.drawShape(inst.shape(), inst.get_world_cxform(),
 
67
            inst.getWorldMatrix());
 
68
}
 
69
 
 
70
 
 
71
void
 
72
DefineMorphShapeTag::read(SWFStream& in, TagType tag, movie_definition& md,
 
73
        const RunResources& r)
 
74
{
 
75
    assert(tag == DEFINEMORPHSHAPE
 
76
        || tag == DEFINEMORPHSHAPE2
 
77
        || tag == DEFINEMORPHSHAPE2_);
 
78
 
 
79
    rect bounds1, bounds2;
 
80
    bounds1.read(in);
 
81
    bounds2.read(in);
 
82
 
 
83
    if (tag == DEFINEMORPHSHAPE2 || tag == DEFINEMORPHSHAPE2_) {
 
84
        // TODO: Use these values.
 
85
        rect innerBound1, innerBound2;
 
86
        innerBound1.read(in);
 
87
        innerBound2.read(in);
 
88
 
 
89
        // This should be used -- first 6 bits reserved, then
 
90
        // 'non-scaling' stroke, then 'scaling' stroke -- these can be
 
91
        // used to optimize morphing.
 
92
        in.ensureBytes(1);
 
93
        static_cast<void>(in.read_u8());
 
94
    }
 
95
 
 
96
    in.ensureBytes(4);
 
97
    // Offset. What is this for?
 
98
    static_cast<void>(in.read_u32());
 
99
 
 
100
    // Next line will throw ParserException on malformed SWF
 
101
    const boost::uint16_t fillCount = in.read_variable_count();
 
102
    
 
103
    fill_style fs1, fs2;
 
104
    for (size_t i = 0; i < fillCount; ++i) {
 
105
        fs1.read(in, tag, md, r, &fs2);
 
106
        _shape1.addFillStyle(fs1);
 
107
        _shape2.addFillStyle(fs2);
 
108
    }
 
109
 
 
110
    const boost::uint16_t lineCount = in.read_variable_count();
 
111
    line_style ls1, ls2;
 
112
    for (size_t i = 0; i < lineCount; ++i) {
 
113
        ls1.read_morph(in, tag, md, r, &ls2);
 
114
        _shape1.addLineStyle(ls1);
 
115
        _shape2.addLineStyle(ls2);
 
116
    }
 
117
 
 
118
    _shape1.read(in, tag, md, r);
 
119
    in.align();
 
120
    _shape2.read(in, tag, md, r);
 
121
 
 
122
    // Set bounds as read in *this* tags rather then
 
123
    // the one computed from ShapeRecord parser
 
124
    // (does it make sense ?)
 
125
    _shape1.setBounds(bounds1);
 
126
    _shape2.setBounds(bounds2);
 
127
    
 
128
    // Starting bounds are the same as shape1
 
129
    _bounds = bounds1;
 
130
 
 
131
    assert(_shape1.fillStyles().size() == _shape2.fillStyles().size());
 
132
    assert(_shape1.lineStyles().size() == _shape2.lineStyles().size());
 
133
 
 
134
#if 0
 
135
 
 
136
    const unsigned edges1 = PathList::computeNumberOfEdges(_shape1.paths());
 
137
    const unsigned edges2 = PathList::computeNumberOfEdges(_shape2.paths());
 
138
 
 
139
    IF_VERBOSE_PARSE(
 
140
      log_parse("morph: "
 
141
          "startShape(paths:%d, edges:%u), "
 
142
          "endShape(paths:%d, edges:%u)",
 
143
          _shape1.paths().size(), edges1,
 
144
          _shape2.paths().size(), edges2);
 
145
    );
 
146
 
 
147
    IF_VERBOSE_MALFORMED_SWF(
 
148
        // It is perfectly legal to have a different number of paths,
 
149
        // edges count should be the same instead
 
150
        if (edges1 != edges2) {
 
151
            log_swferror(_("Different number of edges "
 
152
                "in start (%u) and end (%u) shapes "
 
153
                "of a morph"), edges1, edges1);
 
154
        }
 
155
 
 
156
    );
 
157
#endif
 
158
 
 
159
}
 
160
 
 
161
} // namespace SWF
 
162
} // namespace gnash
 
163
 
 
164
// Local Variables:
 
165
// mode: C++
 
166
// c-basic-offset: 8
 
167
// tab-width: 8
 
168
// indent-tabs-mode: t
 
169
// End: