filters

objects.cpp
1/* libppt - library to read PowerPoint presentation
2 Copyright (C) 2005 Yolla Indria <yolla.indria@gmail.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA
18*/
19
20#include "objects.h"
21#include "ustring.h"
22
23#include <string>
24#include <map>
25#include <vector>
26#include <iostream>
27
28using namespace Libppt;
29
30class PropertyValue
31{
32public:
33 enum { InvalidType, IntType, DoubleType, StringType, BoolType, ColorType } type;
34 bool b;
35 int i;
36 double d;
37 std::string s;
38 Color c;
39
40 PropertyValue()
41 {
42 type = InvalidType;
43 b = false;
44 i = 0;
45 d = 0.0;
46
47
48 }
49};
50
51class Object::Private
52{
53public:
54 int id;
55 double top;
56 double left;
57 double width;
58 double height;
59 bool background;
60 std::map<std::string,PropertyValue> properties;
61};
62
63Object::Object()
64{
65 d = new Private;
66 d->id = -1;
67 d->top = 0.0;
68 d->left = 0.0;
69 d->width = 10.0;
70 d->height = 3.0;
71 d->background = false;
72}
73
74Object::~Object()
75{
76 delete d;
77}
78
79int Object::id() const
80{
81 return d->id;
82}
83
84void Object::setId( int id )
85{
86 d->id = id;
87}
88
89double Object::top() const
90{
91 return d->top;
92}
93
94double Object::left() const
95{
96 return d->left;
97}
98
99double Object::width() const
100{
101 return d->width;
102}
103
104double Object::height() const
105{
106 return d->height;
107}
108
109void Object::setTop( double top )
110{
111 d->top = top;
112}
113
114void Object::setLeft( double left )
115{
116 d->left = left;
117}
118
119void Object::setWidth( double width )
120{
121 d->width = width;
122}
123
124void Object::setHeight( double height)
125{
126 d->height = height;
127}
128
129bool Object::isBackground() const
130{
131 return d->background;
132}
133
134void Object::setBackground( bool bg )
135{
136 d->background = bg;
137}
138
139bool Object::hasProperty( std::string name )
140{
141 std::map<std::string,PropertyValue>::const_iterator i;
142 i = d->properties.find( name );
143 if( i == d->properties.end() )
144 return false;
145 else
146 return true;
147}
148
149void Object::setProperty( std::string name, std::string value )
150{
151 PropertyValue pv;
152 pv.type = PropertyValue::StringType;
153 pv.s = value;
154 d->properties[ name ] = pv;
155}
156
157void Object::setProperty( std::string name, int value )
158 {
159 PropertyValue pv;
160 pv.type = PropertyValue::IntType;
161 pv.i = value;
162 d->properties[ name ] = pv;
163}
164
165void Object::setProperty( std::string name, double value )
166{
167 PropertyValue pv;
168 pv.type = PropertyValue::DoubleType;
169 pv.d = value;
170 d->properties[ name ] = pv;
171}
172
173void Object::setProperty( std::string name, bool value )
174{
175 PropertyValue pv;
176 pv.type = PropertyValue::BoolType;
177 pv.b = value;
178 d->properties[ name ] = pv;
179}
180
181void Object::setProperty( std::string name, Color value )
182{
183 PropertyValue pv;
184 pv.type = PropertyValue::ColorType;
185 pv.c = value;
186 d->properties[ name ] = pv;
187}
188
189int Object::getIntProperty( std::string name )
190{
191 PropertyValue pv;
192 pv = d->properties[ name ];
193 if( pv.type == PropertyValue::IntType )
194 return pv.i;
195 else
196 return 0;
197}
198
199double Object::getDoubleProperty( std::string name )
200{
201 PropertyValue pv;
202 pv = d->properties[ name ];
203 if( pv.type == PropertyValue::DoubleType )
204 return pv.d;
205 else
206 return 0;
207}
208
209bool Object::getBoolProperty( std::string name )
210{
211 PropertyValue pv;
212 pv = d->properties[ name ];
213 if( pv.type == PropertyValue::BoolType )
214 return pv.b;
215 else
216 return false;
217
218}
219
220std::string Object::getStrProperty( std::string name )
221{
222 PropertyValue pv;
223 pv = d->properties[ name ];
224 if( pv.type == PropertyValue::StringType )
225 return pv.s;
226 else
227 return "NoString";
228}
229
230Color Object::getColorProperty(std::string name)
231{
232 PropertyValue pv;
233 pv = d->properties[ name ];
234 if( pv.type == PropertyValue::ColorType )
235 return pv.c;
236 else
237 return Color(153,204,255); // #99ccff
238
239}
240
241class TextObject::Private
242{
243public:
244 unsigned type;
245 std::vector<UString> text;
246 unsigned listSize;
247 std::vector<bool> bulletFlag;
248};
249
250TextObject::TextObject(): Object()
251{
252 d = new Private;
253}
254
255TextObject::~TextObject()
256{
257 delete d;
258}
259
260unsigned TextObject::type() const
261{
262 return d->type;
263}
264
265unsigned TextObject::listSize() const
266{
267 return d->text.size();
268}
269
270const char* TextObject::typeAsString() const
271{
272 switch( d->type )
273 {
274 case Title : return "Title";
275 case Body : return "Body";
276 case Notes : return "Notes";
277 case NotUsed : return "NotUsed";
278 case Other : return "Other";
279 case CenterBody : return "CenterBody";
280 case CenterTitle : return "CenterTitle";
281 case HalfBody : return "HalfBody";
282 case QuarterBody : return "QuarterBody";
283 default: break;
284 }
285
286 return "Unknown";
287}
288
289bool TextObject::bulletFlag( unsigned index ) const
290{
291 return d->bulletFlag[index];
292}
293
294void TextObject::setBulletFlag( bool flag )
295{
296 d->bulletFlag.push_back( flag );
297}
298
299
300void TextObject::setType( unsigned type )
301{
302 d->type = type;
303}
304
305UString TextObject::text( unsigned index) const
306{
307 return d->text[index];
308}
309
310void TextObject::setText( const UString& text )
311{
312 d->text.push_back( text );
313}
314
315void TextObject::convertFrom( Object* object )
316{
317 setId( object->id() );
318 setLeft( object->left() );
319 setTop( object->top() );
320 setWidth( object->width() );
321 setHeight( object->height() );
322
323 if( object->isText() )
324 {
325 TextObject* textObj = static_cast<TextObject*>( object );
326 setType( textObj->type() );
327 // jgn lupa diganti : setText( textObj->text() );
328 }
329}
330
331class GroupObject::Private
332{
333public:
334 std::vector<Object*> objects;
335};
336
337GroupObject::GroupObject()
338{
339 d = new Private;
340}
341
342GroupObject::~GroupObject()
343{
344 for( unsigned i=0; i<d->objects.size(); i++ )
345 delete d->objects[i];
346 delete d;
347}
348
349unsigned GroupObject::objectCount() const
350{
351 return d->objects.size();
352}
353
354Object* GroupObject::object( unsigned i )
355{
356 return d->objects[i];
357}
358
359void GroupObject::addObject( Object* object )
360{
361 d->objects.push_back( object );
362}
363
364void GroupObject::takeObject( Object* object )
365{
366 std::vector<Object*> result;
367 for( unsigned i=0; i<d->objects.size(); i++ )
368 {
369 Object* obj = d->objects[i];
370 if( obj != object )
371 result.push_back( obj );
372 }
373
374 d->objects.clear();
375 for( unsigned j=0; j<result.size(); j++ )
376 d->objects.push_back( result[j] );
377}
378
379class DrawObject::Private
380{
381public:
382 unsigned shape;
383 bool isVerFlip;
384 bool isHorFlip;
385};
386
387DrawObject::DrawObject()
388{
389 d = new Private;
390 d->shape = None;
391}
392
393DrawObject::~DrawObject()
394{
395 delete d;
396}
397
398unsigned DrawObject::shape() const
399{
400 return d->shape;
401}
402
403void DrawObject::setShape( unsigned s )
404{
405 d->shape = s;
406}
407
408bool DrawObject::isVerFlip() const
409{
410 return d->isVerFlip;
411}
412
413void DrawObject::setVerFlip( bool isVerFlip )
414{
415 d->isVerFlip = isVerFlip;
416}
417
418bool DrawObject::isHorFlip() const
419{
420 return d->isHorFlip;
421}
422
423void DrawObject::setHorFlip( bool isHorFlip )
424{
425 d->isHorFlip = isHorFlip;
426}