summaryrefslogtreecommitdiff
path: root/qt/poppler-page-transition.cc
blob: 82513ef069e2b9955abc30d7b5652cf38754a4cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* PageTransition.cc
 * Copyright (C) 2005, Net Integration Technologies, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "Object.h"
#include "Error.h"
#include "UGooString.h"
#include "poppler-page-transition.h"
#include "poppler-page-transition-private.h"

namespace Poppler {

class PageTransitionData
{
  public:
    PageTransition::Type type;
    int duration;
    PageTransition::Alignment alignment;
    PageTransition::Direction direction;
    int angle;
    double scale;
    bool rectangular;
};

PageTransition::PageTransition(const PageTransitionParams &params)
{
  data = new PageTransitionData();
  data->type = Replace;
  data->duration = 1;
  data->alignment = Horizontal;
  data->direction = Inward;
  data->angle = 0;
  data->scale = 1.0;
  data->rectangular = false;

  // Paranoid safety checks
  if (params.dictObj == 0) {
    error(-1, "the method PageTransition_x::PageTransition_x(Object *params.dictObj) was called with params.dictObj==0\n");
    return;
  }
  if (params.dictObj->isDict() == false) {
    error(-1, "the method PageTransition_x::PageTransition_x(Object *params.dictObj) was called where params.dictObj->isDict()==false\n");
    return;
  }

  // Obtain a pointer to the dictionary and start parsing.
  Dict *transDict = params.dictObj->getDict();
  Object obj;

  if (transDict->lookup("S", &obj)->isName()) {
    const char *s = obj.getName();
    if (strcmp("R", s) == 0)
      data->type = Replace;
    else if (strcmp("Split", s) == 0)
      data->type = Split;
    else if (strcmp("Blinds", s) == 0)
      data->type = Blinds;
    else if (strcmp("Box", s) == 0)
      data->type = Box;
    else if (strcmp("Wipe", s) == 0)
      data->type = Wipe;
    else if (strcmp("Dissolve", s) == 0)
      data->type = Dissolve;
    else if (strcmp("Glitter", s) == 0)
      data->type = Glitter;
    else if (strcmp("Fly", s) == 0)
      data->type = Fly;
    else if (strcmp("Push", s) == 0)
      data->type = Push;
    else if (strcmp("Cover", s) == 0)
      data->type = Cover;
    else if (strcmp("Uncover", s) == 0)
      data->type = Push;
    else if (strcmp("Fade", s) == 0)
      data->type = Cover;
  }
  obj.free();
  
  if (transDict->lookup("D", &obj)->isInt()) {
    data->duration = obj.getInt();
  }
  obj.free();

  if (transDict->lookup("Dm", &obj)->isName()) {
    const char *dm = obj.getName();
    if ( strcmp( "H", dm ) == 0 )
      data->alignment = Horizontal;
    else if ( strcmp( "V", dm ) == 0 )
      data->alignment = Vertical;
  }
  obj.free();
  
  if (transDict->lookup("M", &obj)->isName()) {
    const char *m = obj.getName();
    if ( strcmp( "I", m ) == 0 )
      data->direction = Inward;
    else if ( strcmp( "O", m ) == 0 )
      data->direction = Outward;
  }
  obj.free();
  
  if (transDict->lookup("Di", &obj)->isInt()) {
    data->angle = obj.getInt();
  }
  obj.free();
  
  if (transDict->lookup("Di", &obj)->isName()) {
    if ( strcmp( "None", obj.getName() ) == 0 )
      data->angle = 0;
  }
  obj.free();
  
  if (transDict->lookup("SS", &obj)->isReal()) {
    data->scale = obj.getReal();
  }
  obj.free();
  
  if (transDict->lookup("B", &obj)->isBool()) {
    data->rectangular = obj.getBool();
  }
  obj.free();
}

PageTransition::PageTransition(const PageTransition &pt)
{
  data = new PageTransitionData();
  data->type = pt.data->type;
  data->duration = pt.data->duration;
  data->alignment = pt.data->alignment;
  data->direction = pt.data->direction;
  data->angle = pt.data->angle;
  data->scale = pt.data->scale;
  data->rectangular = pt.data->rectangular;
}

PageTransition::~PageTransition()
{
}

PageTransition::Type PageTransition::type() const
{
  return data->type;
}

int PageTransition::duration() const
{
  return data->duration;
}

PageTransition::Alignment PageTransition::alignment() const
{
  return data->alignment;
}

PageTransition::Direction PageTransition::direction() const
{
  return data->direction;
}

int PageTransition::angle() const
{
  return data->angle;
}

double PageTransition::scale() const
{
  return data->scale;
}
bool PageTransition::isRectangular() const
{
  return data->rectangular;
}

}