1
// DefineMorphShapeTag.cpp: Load and parse morphing shapes, for Gnash.
3
// Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
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.
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.
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
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.
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"
37
DefineMorphShapeTag::loader(SWFStream& in, TagType tag, movie_definition& md,
38
const RunResources& r)
41
boost::uint16_t id = in.read_u16();
44
log_parse("DefineMorphShapeTag: id = %d", id);
47
DefineMorphShapeTag* morph = new DefineMorphShapeTag(in, tag, md, r);
48
md.addDisplayObject(id, morph);
51
DefineMorphShapeTag::DefineMorphShapeTag(SWFStream& in, TagType tag,
52
movie_definition& md, const RunResources& r)
58
DefineMorphShapeTag::createDisplayObject(DisplayObject* parent, int id) const
60
return new MorphShape(this, parent, id);
64
DefineMorphShapeTag::display(Renderer& renderer, const MorphShape& inst) const
66
renderer.drawShape(inst.shape(), inst.get_world_cxform(),
67
inst.getWorldMatrix());
72
DefineMorphShapeTag::read(SWFStream& in, TagType tag, movie_definition& md,
73
const RunResources& r)
75
assert(tag == DEFINEMORPHSHAPE
76
|| tag == DEFINEMORPHSHAPE2
77
|| tag == DEFINEMORPHSHAPE2_);
79
rect bounds1, bounds2;
83
if (tag == DEFINEMORPHSHAPE2 || tag == DEFINEMORPHSHAPE2_) {
84
// TODO: Use these values.
85
rect innerBound1, innerBound2;
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.
93
static_cast<void>(in.read_u8());
97
// Offset. What is this for?
98
static_cast<void>(in.read_u32());
100
// Next line will throw ParserException on malformed SWF
101
const boost::uint16_t fillCount = in.read_variable_count();
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);
110
const boost::uint16_t lineCount = in.read_variable_count();
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);
118
_shape1.read(in, tag, md, r);
120
_shape2.read(in, tag, md, r);
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);
128
// Starting bounds are the same as shape1
131
assert(_shape1.fillStyles().size() == _shape2.fillStyles().size());
132
assert(_shape1.lineStyles().size() == _shape2.lineStyles().size());
136
const unsigned edges1 = PathList::computeNumberOfEdges(_shape1.paths());
137
const unsigned edges2 = PathList::computeNumberOfEdges(_shape2.paths());
141
"startShape(paths:%d, edges:%u), "
142
"endShape(paths:%d, edges:%u)",
143
_shape1.paths().size(), edges1,
144
_shape2.paths().size(), edges2);
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);
168
// indent-tabs-mode: t