1
/* libppt - library to read PowerPoint presentation
2
Copyright (C) 2005 Yolla Indria <yolla.indria@gmail.com>
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.
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.
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
29
using namespace Libppt;
34
enum { InvalidType, IntType, DoubleType, StringType, BoolType, ColorType } type;
60
std::map<std::string, PropertyValue> properties;
71
d->background = false;
79
int Object::id() const
84
void Object::setId(int id)
89
double Object::top() const
94
double Object::left() const
99
double Object::width() const
104
double Object::height() const
109
void Object::setTop(double top)
114
void Object::setLeft(double left)
119
void Object::setWidth(double width)
124
void Object::setHeight(double height)
129
bool Object::isBackground() const
131
return d->background;
134
void Object::setBackground(bool bg)
139
bool Object::hasProperty(std::string name)
141
std::map<std::string, PropertyValue>::const_iterator i;
142
i = d->properties.find(name);
143
if (i == d->properties.end())
149
void Object::setProperty(std::string name, std::string value)
152
pv.type = PropertyValue::StringType;
154
d->properties[ name ] = pv;
157
void Object::setProperty(std::string name, int value)
160
pv.type = PropertyValue::IntType;
162
d->properties[ name ] = pv;
165
void Object::setProperty(std::string name, double value)
168
pv.type = PropertyValue::DoubleType;
170
d->properties[ name ] = pv;
173
void Object::setProperty(std::string name, bool value)
176
pv.type = PropertyValue::BoolType;
178
d->properties[ name ] = pv;
181
void Object::setProperty(std::string name, Color value)
184
pv.type = PropertyValue::ColorType;
186
d->properties[ name ] = pv;
189
int Object::getIntProperty(std::string name)
192
pv = d->properties[ name ];
193
if (pv.type == PropertyValue::IntType)
199
double Object::getDoubleProperty(std::string name)
202
pv = d->properties[ name ];
203
if (pv.type == PropertyValue::DoubleType)
209
bool Object::getBoolProperty(std::string name)
212
pv = d->properties[ name ];
213
if (pv.type == PropertyValue::BoolType)
220
std::string Object::getStrProperty(std::string name)
223
pv = d->properties[ name ];
224
if (pv.type == PropertyValue::StringType)
230
Color Object::getColorProperty(std::string name)
233
pv = d->properties[ name ];
234
if (pv.type == PropertyValue::ColorType)
237
return Color(153, 204, 255); // #99ccff
241
class TextObject::Private : public QSharedData
249
* @brief Actual text for this object
254
* @brief Text style that applies to this object
257
StyleTextPropAtom *atom;
260
* @brief Struct that contains precalculated style names based on
261
* TextCFException and TextPFException combinations.
263
* For each individual character in this object's text three styles apply:
264
* Paragraph style, List style and Character style. These are parsed from
265
* TextCFException and TextPFException. For each character there is a
266
* corresponding pair of TextCFException and TextPFException.
268
* Saving of styles is done before saving text contents so we'll cache
269
* the style names and pairs of TextCFException and TextPFException.
275
* @brief Text style name (e.g. T1)
281
* @brief Paragraph style (e.g. P1)
287
* @brief List style (e.g. L1)
293
* @brief TextCFException the style names are parsed from
295
const TextCFException *cf;
298
* @brief TextPFException the style names are parsed from
300
const TextPFException *pf;
304
* @brief List of pre parsed style names that apply to this text
306
QList<StyleName> styleNames;
310
TextObject::Private::Private()
317
TextObject::Private::~Private()
323
void TextObject::setStyleTextProperty(const StyleTextPropAtom *atom)
325
//We don't know the lifespan of this atom so we'll make a copy of it
326
d->atom = new StyleTextPropAtom(*atom);
330
TextObject::TextObject(): Object()
335
TextObject::~TextObject()
339
unsigned int TextObject::type() const
344
const char* TextObject::typeAsString() const
347
case Title : return "Title";
348
case Body : return "Body";
349
case Notes : return "Notes";
350
case NotUsed : return "NotUsed";
351
case Other : return "Other";
352
case CenterBody : return "CenterBody";
353
case CenterTitle : return "CenterTitle";
354
case HalfBody : return "HalfBody";
355
case QuarterBody : return "QuarterBody";
362
void TextObject::addStylenames(const TextCFException *cf,
363
const TextPFException *pf,
365
const QString ¶graph,
368
TextObject::Private::StyleName style;
372
style.paragraph = paragraph;
374
d->styleNames << style;
377
QString TextObject::textStyleName(const TextCFException *cf,
378
const TextPFException *pf) const
380
int pos = findStyle(cf, pf);
382
return d->styleNames[pos].text;
388
QString TextObject::paragraphStyleName(const TextCFException *cf,
389
const TextPFException *pf) const
391
int pos = findStyle(cf, pf);
393
return d->styleNames[pos].paragraph;
399
QString TextObject::listStyleName(const TextCFException *cf,
400
const TextPFException *pf) const
402
int pos = findStyle(cf, pf);
404
return d->styleNames[pos].list;
410
int TextObject::findStyle(const TextCFException *cf,
411
const TextPFException *pf) const
413
for (int i = 0;i < d->styleNames.size();i++) {
414
if (d->styleNames[i].cf == cf && d->styleNames[i].pf == pf) {
422
StyleTextPropAtom *TextObject::styleTextProperty()
428
void TextObject::setType(unsigned int type)
433
QString TextObject::text() const
439
void TextObject::setText(const QString& text)
445
void TextObject::convertFrom(Object* object)
448
setLeft(object->left());
449
setTop(object->top());
450
setWidth(object->width());
451
setHeight(object->height());
453
if (object->isText()) {
454
TextObject* textObj = static_cast<TextObject*>(object);
455
setType(textObj->type());
456
// jgn lupa diganti : setText( textObj->text() );
460
class GroupObject::Private
463
std::vector<Object*> objects;
465
// in group nesting, coordinate transformations may occur
466
// these values define the transformation
477
Private() : xoffset(0), yoffset(0), xscale(25.4 / 576), yscale(25.4 / 576),
478
vx(0), vy(0), vwidth(0), vheight(0) {
482
GroupObject::GroupObject()
487
GroupObject::~GroupObject()
489
for (unsigned i = 0; i < d->objects.size(); i++)
490
delete d->objects[i];
494
unsigned GroupObject::objectCount() const
496
return d->objects.size();
499
Object* GroupObject::object(unsigned i)
501
return d->objects[i];
504
void GroupObject::addObject(Object* object)
506
d->objects.push_back(object);
509
void GroupObject::takeObject(Object* object)
511
std::vector<Object*> result;
512
for (unsigned i = 0; i < d->objects.size(); i++) {
513
Object* obj = d->objects[i];
515
result.push_back(obj);
519
for (unsigned j = 0; j < result.size(); j++)
520
d->objects.push_back(result[j]);
524
GroupObject::setViewportDimensions(double x, double y,
525
double width, double height)
534
GroupObject::setDimensions(double x, double y, double width, double height)
536
if (width && height && d->vwidth && d->vheight) {
537
// adapt the offset and scaling
538
d->xoffset += d->xscale * x;
539
d->xscale *= width / d->vwidth;
540
d->xoffset -= d->xscale * d->vx;
541
d->yoffset += d->yscale * y;
542
d->yscale *= height / d->vheight;
543
d->yoffset -= d->yscale * d->vy;
548
GroupObject::getXOffset() const
554
GroupObject::getYOffset() const
560
GroupObject::getXScale() const
566
GroupObject::getYScale() const
571
class DrawObject::Private
579
* @brief Name of the style corresponding this object
581
* This is usually generated by KoGenStyles
586
DrawObject::DrawObject()
592
DrawObject::~DrawObject()
597
unsigned DrawObject::shape() const
602
void DrawObject::setShape(unsigned s)
607
bool DrawObject::isVerFlip() const
612
QString DrawObject::styleName() const
617
void DrawObject::setVerFlip(bool isVerFlip)
619
d->isVerFlip = isVerFlip;
622
bool DrawObject::isHorFlip() const
627
void DrawObject::setHorFlip(bool isHorFlip)
629
d->isHorFlip = isHorFlip;
632
void DrawObject::setStyleName(const QString &name)
637
class TextFont::Private : public QSharedData
649
* @brief Font's charset
651
* See http://msdn.microsoft.com/en-us/library/dd145037(VS.85).aspx
652
* for more information
657
* @brief Font's clip precision
659
* See http://msdn.microsoft.com/en-us/library/dd145037(VS.85).aspx
660
* for more information
665
* @brief Font's quality
667
* See http://msdn.microsoft.com/en-us/library/dd145037(VS.85).aspx
668
* for more information
673
* @brief Font's pitch and family
675
* See http://msdn.microsoft.com/en-us/library/dd145037(VS.85).aspx
676
* for more information
681
TextFont::Private::Private()
690
TextFont::Private::~Private()
700
TextFont::TextFont(const QString &fontName,
707
d->fontName = fontName;
708
d->charset = charset;
709
d->clipPrecision = clipPrecision;
710
d->quality = quality;
711
d->pitchAndFamily = pitchAndFamily;
714
TextFont::TextFont(const TextFont &source)
720
TextFont::~TextFont()
724
QString TextFont::name() const
729
int TextFont::charset() const
734
int TextFont::clipPrecision() const
736
return d->clipPrecision;
739
int TextFont::quality() const
744
int TextFont::pitchAndFamily() const
746
return d->pitchAndFamily;
751
class TextFontCollection::Private
754
QList<TextFont> fonts;
757
TextFontCollection::TextFontCollection()
762
TextFontCollection::~TextFontCollection()
767
unsigned TextFontCollection::listSize() const
769
return d->fonts.size();
772
void TextFontCollection::addFont(const TextFont &font)
777
TextFont* TextFontCollection::getFont(unsigned int index)
779
if (index < listSize()) {
780
return &d->fonts[index];