beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / poppler / Movie.cc
blobf68b6adcd4d3f193caec32020ac252f3303aeea9
1 //*********************************************************************************
2 // Movie.cc
3 //---------------------------------------------------------------------------------
4 //
5 //---------------------------------------------------------------------------------
6 // Hugo Mercier <hmercier31[at]gmail.com> (c) 2008
7 // Pino Toscano <pino@kde.org> (c) 2008
8 // Carlos Garcia Campos <carlosgc@gnome.org> (c) 2010
9 // Albert Astals Cid <aacid@kde.org> (c) 2010
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 //*********************************************************************************
26 #include <math.h>
27 #include "Movie.h"
28 #include "FileSpec.h"
30 MovieActivationParameters::MovieActivationParameters() {
31 // default values
32 floatingWindow = gFalse;
33 xPosition = 0.5;
34 yPosition = 0.5;
35 rate = 1.0;
36 volume = 100;
37 showControls = gFalse;
38 synchronousPlay = gFalse;
39 repeatMode = repeatModeOnce;
40 start.units = 0;
41 duration.units = 0;
42 znum = 1;
43 zdenum = 1;
46 MovieActivationParameters::~MovieActivationParameters() {
49 void MovieActivationParameters::parseMovieActivation(Object* aDict) {
50 Object obj1;
52 if (!aDict->dictLookup("Start", &obj1)->isNull()) {
53 if (obj1.isInt()) {
54 // If it is representable as an integer (subject to the implementation limit for
55 // integers, as described in Appendix C), it should be specified as such.
57 start.units = obj1.getInt();
58 } else if (obj1.isString()) {
59 // If it is not representable as an integer, it should be specified as an 8-byte
60 // string representing a 64-bit twos-complement integer, most significant
61 // byte first.
63 // UNSUPPORTED
64 } else if (obj1.isArray()) {
65 Array* a = obj1.getArray();
67 Object tmp;
68 a->get(0, &tmp);
69 if (tmp.isInt()) {
70 start.units = tmp.getInt();
72 if (tmp.isString()) {
73 // UNSUPPORTED
75 tmp.free();
77 a->get(1, &tmp);
78 if (tmp.isInt()) {
79 start.units_per_second = tmp.getInt();
81 tmp.free();
84 obj1.free();
86 if (!aDict->dictLookup("Duration", &obj1)->isNull()) {
87 if (obj1.isInt()) {
88 duration.units = obj1.getInt();
89 } else if (obj1.isString()) {
90 // UNSUPPORTED
91 } else if (obj1.isArray()) {
92 Array* a = obj1.getArray();
94 Object tmp;
95 a->get(0, &tmp);
96 if (tmp.isInt()) {
97 duration.units = tmp.getInt();
99 if (tmp.isString()) {
100 // UNSUPPORTED
102 tmp.free();
104 a->get(1, &tmp);
105 if (tmp.isInt()) {
106 duration.units_per_second = tmp.getInt();
108 tmp.free();
111 obj1.free();
113 if (aDict->dictLookup("Rate", &obj1)->isNum()) {
114 rate = obj1.getNum();
116 obj1.free();
118 if (aDict->dictLookup("Volume", &obj1)->isNum()) {
119 // convert volume to [0 100]
120 volume = int((obj1.getNum() + 1.0) * 50);
122 obj1.free();
124 if (aDict->dictLookup("ShowControls", &obj1)->isBool()) {
125 showControls = obj1.getBool();
127 obj1.free();
129 if (aDict->dictLookup("Synchronous", &obj1)->isBool()) {
130 synchronousPlay = obj1.getBool();
132 obj1.free();
134 if (aDict->dictLookup("Mode", &obj1)->isName()) {
135 char* name = obj1.getName();
136 if (!strcmp(name, "Once")) {
137 repeatMode = repeatModeOnce;
138 } else if (!strcmp(name, "Open")) {
139 repeatMode = repeatModeOpen;
140 } else if (!strcmp(name, "Repeat")) {
141 repeatMode = repeatModeRepeat;
142 } else if (!strcmp(name,"Palindrome")) {
143 repeatMode = repeatModePalindrome;
146 obj1.free();
148 if (aDict->dictLookup("FWScale", &obj1)->isArray()) {
149 // the presence of that entry implies that the movie is to be played
150 // in a floating window
151 floatingWindow = gTrue;
153 Array* scale = obj1.getArray();
154 if (scale->getLength() >= 2) {
155 Object tmp;
156 if (scale->get(0, &tmp)->isInt()) {
157 znum = tmp.getInt();
159 tmp.free();
160 if (scale->get(1, &tmp)->isInt()) {
161 zdenum = tmp.getInt();
163 tmp.free();
166 obj1.free();
168 if (aDict->dictLookup("FWPosition", &obj1)->isArray()) {
169 Array* pos = obj1.getArray();
170 if (pos->getLength() >= 2) {
171 Object tmp;
172 if (pos->get(0, &tmp)->isNum()) {
173 xPosition = tmp.getNum();
175 tmp.free();
176 if (pos->get(1, &tmp)->isNum()) {
177 yPosition = tmp.getNum();
179 tmp.free();
182 obj1.free();
185 void Movie::parseMovie (Object *movieDict) {
186 fileName = NULL;
187 rotationAngle = 0;
188 width = -1;
189 height = -1;
190 showPoster = gFalse;
192 Object obj1, obj2;
193 if (getFileSpecNameForPlatform(movieDict->dictLookup("F", &obj1), &obj2)) {
194 fileName = obj2.getString()->copy();
195 obj2.free();
196 } else {
197 error (errSyntaxError, -1, "Invalid Movie");
198 ok = gFalse;
199 obj1.free();
200 return;
202 obj1.free();
204 if (movieDict->dictLookup("Aspect", &obj1)->isArray()) {
205 Array* aspect = obj1.getArray();
206 if (aspect->getLength() >= 2) {
207 Object tmp;
208 if( aspect->get(0, &tmp)->isNum() ) {
209 width = (int)floor( aspect->get(0, &tmp)->getNum() + 0.5 );
211 tmp.free();
212 if( aspect->get(1, &tmp)->isNum() ) {
213 height = (int)floor( aspect->get(1, &tmp)->getNum() + 0.5 );
215 tmp.free();
218 obj1.free();
220 if (movieDict->dictLookup("Rotate", &obj1)->isInt()) {
221 // round up to 90°
222 rotationAngle = (((obj1.getInt() + 360) % 360) % 90) * 90;
224 obj1.free();
227 // movie poster
229 if (!movieDict->dictLookupNF("Poster", &poster)->isNull()) {
230 if (poster.isRef() || poster.isStream()) {
231 showPoster = gTrue;
232 } else if (poster.isBool()) {
233 showPoster = poster.getBool();
234 poster.free();
235 } else {
236 poster.free();
241 Movie::~Movie() {
242 if (fileName)
243 delete fileName;
244 poster.free();
247 Movie::Movie(Object *movieDict) {
248 ok = gTrue;
250 if (movieDict->isDict())
251 parseMovie(movieDict);
252 else
253 ok = gFalse;
256 Movie::Movie(Object *movieDict, Object *aDict) {
257 ok = gTrue;
259 if (movieDict->isDict()) {
260 parseMovie(movieDict);
261 if (aDict->isDict())
262 MA.parseMovieActivation(aDict);
263 } else {
264 ok = gFalse;
268 void Movie::getFloatingWindowSize(int *widthA, int *heightA)
270 *widthA = int(width * double(MA.znum) / MA.zdenum);
271 *heightA = int(height * double(MA.znum) / MA.zdenum);
274 Movie* Movie::copy() {
276 // call default copy constructor
277 Movie* new_movie = new Movie(*this);
279 if (fileName)
280 new_movie->fileName = fileName->copy();
282 poster.copy(&new_movie->poster);
284 return new_movie;