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
|
/* This file is part of the KDE project
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
Contact: Suresh Chande suresh.chande@nokia.com
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KoFontFace.h"
#include <KoXmlWriter.h>
#include <KDebug>
class KoFontFacePrivate : public QSharedData
{
public:
KoFontFacePrivate(const QString &_name)
: name(_name), pitch(KoFontFace::VariablePitch)
{
}
~KoFontFacePrivate()
{
}
void saveOdf(KoXmlWriter* xmlWriter) const
{
xmlWriter->startElement("style:font-face");
xmlWriter->addAttribute("style:name", name);
xmlWriter->addAttribute("svg:font-family", family.isEmpty() ? name : family);
if (!familyGeneric.isEmpty())
xmlWriter->addAttribute("style:font-family-generic", familyGeneric);
if (!style.isEmpty())
xmlWriter->addAttribute("svg:font-style", style);
xmlWriter->addAttribute("style:font-pitch", pitch == KoFontFace::FixedPitch ? "fixed" : "variable");
xmlWriter->endElement(); // style:font-face
}
QString name; //!< for style:name attribute
QString family; //!< for svg:font-family attribute
QString familyGeneric; //!< for style:font-family-generic attribute
QString style; //!< for svg:font-style attribute
KoFontFace::Pitch pitch; //!< for style:font-pitch attribute
};
KoFontFace::KoFontFace(const QString &_name)
: d(new KoFontFacePrivate(_name))
{
}
KoFontFace::KoFontFace(const KoFontFace &other)
: d(other.d)
{
}
KoFontFace::~KoFontFace()
{
}
KoFontFace &KoFontFace::operator=(const KoFontFace &other)
{
d = other.d;
return *this;
}
bool KoFontFace::operator==(const KoFontFace &other) const
{
if (isNull() && other.isNull())
return true;
return d.data() == other.d.data();
}
bool KoFontFace::isNull() const
{
return d->name.isEmpty();
}
QString KoFontFace::name() const
{
return d->name;
}
void KoFontFace::setName(const QString &name)
{
d->name = name;
}
QString KoFontFace::family() const
{
return d->family;
}
void KoFontFace::setFamily(const QString &family)
{
d->family = family;
}
QString KoFontFace::familyGeneric() const
{
return d->familyGeneric;
}
void KoFontFace::setFamilyGeneric(const QString &familyGeneric)
{
d->familyGeneric = familyGeneric;
}
QString KoFontFace::style() const
{
return d->style;
}
void KoFontFace::setStyle(const QString &style)
{
d->style = style;
}
KoFontFace::Pitch KoFontFace::pitch() const
{
return d->pitch;
}
void KoFontFace::setPitch(KoFontFace::Pitch pitch)
{
d->pitch = pitch;
}
void KoFontFace::saveOdf(KoXmlWriter* xmlWriter) const
{
Q_ASSERT(!isNull());
if (isNull()) {
kWarning() << "This font face is null and will not be saved: set at least the name";
return;
}
d->saveOdf(xmlWriter);
}
|