1
//*********************************************************************************
3
//---------------------------------------------------------------------------------
5
//---------------------------------------------------------------------------------
6
// Hugo Mercier <hmercier31[at]gmail.com> (c) 2008
7
// Pino Toscano <pino@kde.org> (c) 2008
9
// This program is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU General Public License as published by
11
// the Free Software Foundation; either version 2 of the License, or
12
// (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
//*********************************************************************************
28
MovieWindowParameters::MovieWindowParameters() {
30
type = movieWindowEmbedded;
33
relativeTo = windowRelativeToDocument;
37
hasCloseButton = gTrue;
41
MovieWindowParameters::~MovieWindowParameters() {
44
void MovieWindowParameters::parseFWParams(Object* obj) {
47
if (obj->dictLookup("D", &tmp)->isArray()) {
48
Array * dim = tmp.getArray();
50
if (dim->getLength() >= 2) {
52
if (dim->get(0, &dd)->isInt()) {
56
if (dim->get(1, &dd)->isInt()) {
64
if (obj->dictLookup("RT", &tmp)->isInt()) {
67
case 0: relativeTo = windowRelativeToDocument; break;
68
case 1: relativeTo = windowRelativeToApplication; break;
69
case 2: relativeTo = windowRelativeToDesktop; break;
74
if (obj->dictLookup("P",&tmp)->isInt()) {
82
case 1: // Upper Center
86
case 2: // Upper Right
90
case 3: // Center Left
98
case 5: // Center Right
102
case 6: // Lower Left
106
case 7: // Lower Center
110
case 8: // Lower Right
118
if (obj->dictLookup("T", &tmp)->isBool()) {
119
hasTitleBar = tmp.getBool();
122
if (obj->dictLookup("UC", &tmp)->isBool()) {
123
hasCloseButton = tmp.getBool();
126
if (obj->dictLookup("R", &tmp)->isInt()) {
127
isResizeable = (tmp.getInt() != 0);
133
MovieParameters::MovieParameters() {
134
// instanciate to default values
139
fittingPolicy = fittingUndefined;
143
showControls = gFalse;
150
MovieParameters::~MovieParameters() {
153
void MovieParameters::parseAnnotMovie(AnnotMovie* annot) {
154
windowParams.relativeTo = MovieWindowParameters::windowRelativeToDesktop;
156
if (annot->needFloatingWindow()) {
157
windowParams.type = MovieWindowParameters::movieWindowFloating;
159
if (annot->needFullscreen()) {
160
windowParams.type = MovieWindowParameters::movieWindowFullscreen;
165
annot->getMovieSize(w, h);
166
annot->getZoomFactor(znum, zdenum);
167
windowParams.width = int(w * double(znum) / zdenum);
168
windowParams.height = int(h * double(znum) / zdenum);
171
annot->getWindowPosition(x,y);
172
windowParams.XPosition = x;
173
windowParams.YPosition = y;
175
rate = annot->getRate();
176
// convert volume to [0 100]
177
volume = int((annot->getVolume() + 1.0) * 50);
179
AnnotMovie::RepeatMode mode = annot->getRepeatMode();
180
if (mode == AnnotMovie::repeatModeRepeat)
183
showControls = annot->getShowControls();
185
AnnotMovie::Time tStart = annot->getStart();
186
AnnotMovie::Time tDuration = annot->getDuration();
188
start.units = tStart.units;
189
start.units_per_second = tStart.units_per_second;
191
duration.units = tDuration.units;
192
duration.units_per_second = tDuration.units_per_second;
195
void MovieParameters::parseMediaPlayParameters(Object* obj) {
199
if (obj->dictLookup("V", &tmp)->isInt()) {
200
volume = tmp.getInt();
204
if (obj->dictLookup("C", &tmp)->isBool()) {
205
showControls = tmp.getBool();
209
if (obj->dictLookup("F", &tmp)->isInt()) {
210
int t = tmp.getInt();
213
case 0: fittingPolicy = fittingMeet; break;
214
case 1: fittingPolicy = fittingSlice; break;
215
case 2: fittingPolicy = fittingFill; break;
216
case 3: fittingPolicy = fittingScroll; break;
217
case 4: fittingPolicy = fittingHidden; break;
218
case 5: fittingPolicy = fittingUndefined; break;
224
// duration's default value is set to 0, which means : intrinsinc media duration
225
if (obj->dictLookup("D", &tmp)->isDict()) {
226
Object oname, ddict, tmp2;
227
if (tmp.dictLookup("S", &oname)->isName()) {
228
char* name = oname.getName();
229
if (!strcmp(name, "F"))
230
duration.units = -1; // infinity
231
else if (!strcmp(name, "T")) {
232
if (tmp.dictLookup("T", &ddict)->isDict()) {
233
if (ddict.dictLookup("V", &tmp2)->isNum()) {
234
duration.units = Gulong(tmp2.getNum());
246
if (obj->dictLookup("A", &tmp)->isBool()) {
247
autoPlay = tmp.getBool();
251
if (obj->dictLookup("RC", &tmp)->isNum()) {
252
repeatCount = tmp.getNum();
258
void MovieParameters::parseMediaScreenParameters(Object* obj) {
261
if (obj->dictLookup("W", &tmp)->isInt()) {
262
int t = tmp.getInt();
265
case 0: windowParams.type = MovieWindowParameters::movieWindowFloating; break;
266
case 1: windowParams.type = MovieWindowParameters::movieWindowFullscreen; break;
267
case 2: windowParams.type = MovieWindowParameters::movieWindowHidden; break;
268
case 3: windowParams.type = MovieWindowParameters::movieWindowEmbedded; break;
274
if (obj->dictLookup("B", &tmp)->isArray()) {
275
Array* color = tmp.getArray();
279
color->get(0, &component);
280
bgColor.r = component.getNum();
283
color->get(1, &component);
284
bgColor.g = component.getNum();
287
color->get(2, &component);
288
bgColor.b = component.getNum();
295
if (obj->dictLookup("O", &tmp)->isNum()) {
296
opacity = tmp.getNum();
300
if (windowParams.type == MovieWindowParameters::movieWindowFloating) {
302
if (obj->dictLookup("F",&winDict)->isDict()) {
303
windowParams.parseFWParams(&winDict);
312
embeddedStream = NULL;
322
if (embeddedStream && (!embeddedStream->decRef())) {
323
delete embeddedStream;
325
if (posterStream && (!posterStream->decRef())) {
330
void Movie::parseAnnotMovie(AnnotMovie* annot) {
331
// AnnotMovie is not embedded
334
fileName = annot->getFileName()->copy();
336
if (annot->getPosterStream()) {
337
posterStream = annot->getPosterStream();
338
posterStream->incRef();
341
MH.parseAnnotMovie(annot);
342
// deep copy of MH to BE
343
// (no distinction is made with AnnotMovie)
344
memcpy(&BE, &MH, sizeof(MH));
347
void Movie::parseMediaRendition(Object* obj) {
350
if (obj->dictLookup("S", &tmp)->isName()) {
351
if (!strcmp(tmp.getName(), "MR")) { // it's a media rendition
354
// parse Media Play Parameters
355
if (obj->dictLookup("P", &tmp2)->isDict()) { // media play parameters
357
if (tmp2.dictLookup("MH", ¶ms)->isDict()) {
358
MH.parseMediaPlayParameters(¶ms);
361
if (tmp2.dictLookup("BE", ¶ms)->isDict()) {
362
BE.parseMediaPlayParameters(¶ms);
368
// parse Media Screen Parameters
369
if (obj->dictLookup("SP", &tmp2)->isDict()) { // media screen parameters
371
if (tmp2.dictLookup("MH", ¶ms)->isDict()) {
372
MH.parseMediaScreenParameters(¶ms);
375
if (tmp2.dictLookup("BE", ¶ms)->isDict()) {
376
BE.parseMediaScreenParameters(¶ms);
383
// Parse media clip data
385
if (obj->dictLookup("C", &tmp2)->isDict()) { // media clip
388
if (tmp2.dictLookup("S", &tmp)->isName()) {
389
if (!strcmp(tmp.getName(), "MCD")) { // media clip data
391
if (tmp2.dictLookup("D", &obj1)->isDict()) {
392
if (obj1.dictLookup("F", &obj2)->isString()) {
393
fileName = obj2.getString()->copy();
397
if (!obj1.dictLookup("EF", &obj2)->isNull()) {
400
if (!obj2.dictLookupNF("F", &mref)->isNull()) {
403
obj2.dictLookup("F", &embedded);
404
if (embedded.isStream()) {
405
embeddedStream = embedded.getStream();
407
embeddedStream->incRef();
417
if (tmp2.dictLookup("CT", &obj1)->isString()) {
418
contentType = obj1.getString()->copy();
431
void Movie::outputToFile(FILE* fp) {
432
embeddedStream->reset();
435
int c = embeddedStream->getChar();
439
fwrite(&c, 1, 1, fp);
444
Movie* Movie::copy() {
446
// call default copy constructor
447
Movie* new_movie = new Movie(*this);
450
new_movie->contentType = contentType->copy();
452
new_movie->fileName = fileName->copy();
454
if (new_movie->embeddedStream)
455
new_movie->embeddedStream->incRef();
457
if (new_movie->posterStream)
458
new_movie->posterStream->incRef();