Warning, file /office/calligra/libs/odf/KoFontFace.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
0003 
0004    Contact: Suresh Chande suresh.chande@nokia.com
0005 
0006    This library is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Library General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 
0011    This library is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    Library General Public License for more details.
0015 
0016    You should have received a copy of the GNU Library General Public License
0017    along with this library; see the file COPYING.LIB.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #include "KoFontFace.h"
0023 #include <KoXmlWriter.h>
0024 #include <OdfDebug.h>
0025 
0026 class KoFontFacePrivate : public QSharedData
0027 {
0028 public:
0029     KoFontFacePrivate(const QString &_name)
0030     : name(_name), pitch(KoFontFace::VariablePitch)
0031     {
0032     }
0033 
0034     ~KoFontFacePrivate()
0035     {
0036     }
0037 
0038     void saveOdf(KoXmlWriter* xmlWriter) const
0039     {
0040         xmlWriter->startElement("style:font-face");
0041         xmlWriter->addAttribute("style:name", name);
0042         xmlWriter->addAttribute("svg:font-family", family.isEmpty() ? name : family);
0043         if (!familyGeneric.isEmpty())
0044             xmlWriter->addAttribute("style:font-family-generic", familyGeneric);
0045         if (!style.isEmpty())
0046             xmlWriter->addAttribute("svg:font-style", style);
0047         xmlWriter->addAttribute("style:font-pitch", pitch == KoFontFace::FixedPitch ? "fixed" : "variable");
0048         xmlWriter->endElement(); // style:font-face
0049     }
0050 
0051     QString name;            //!< for style:name attribute
0052     QString family;          //!< for svg:font-family attribute
0053     QString familyGeneric;   //!< for style:font-family-generic attribute
0054     QString style;           //!< for svg:font-style attribute
0055     KoFontFace::Pitch pitch; //!< for style:font-pitch attribute
0056 };
0057 
0058 
0059 KoFontFace::KoFontFace(const QString &_name)
0060  : d(new KoFontFacePrivate(_name))
0061 {
0062 }
0063 
0064 KoFontFace::KoFontFace(const KoFontFace &other)
0065  : d(other.d)
0066 {
0067 }
0068 
0069 KoFontFace::~KoFontFace()
0070 {
0071 }
0072 
0073 KoFontFace &KoFontFace::operator=(const KoFontFace &other)
0074 {
0075     d = other.d;
0076     return *this;
0077 }
0078 
0079 bool KoFontFace::operator==(const KoFontFace &other) const
0080 {
0081     if (isNull() && other.isNull())
0082         return true;
0083     return d.data() == other.d.data();
0084 }
0085 
0086 bool KoFontFace::isNull() const
0087 {
0088     return d->name.isEmpty();
0089 }
0090 
0091 QString KoFontFace::name() const
0092 {
0093     return d->name;
0094 }
0095 
0096 void KoFontFace::setName(const QString &name)
0097 {
0098     d->name = name;
0099 }
0100 
0101 QString KoFontFace::family() const
0102 {
0103     return d->family;
0104 }
0105 
0106 void KoFontFace::setFamily(const QString &family)
0107 {
0108     d->family = family;
0109 }
0110 
0111 QString KoFontFace::familyGeneric() const
0112 {
0113     return d->familyGeneric;
0114 }
0115 
0116 void KoFontFace::setFamilyGeneric(const QString &familyGeneric)
0117 {
0118     if (familyGeneric == "decorative" || familyGeneric == "modern"
0119             || familyGeneric == "roman" || familyGeneric == "script"
0120             || familyGeneric == "swiss" || familyGeneric == "system") {
0121         d->familyGeneric = familyGeneric;
0122     }
0123 }
0124 
0125 QString KoFontFace::style() const
0126 {
0127     return d->style;
0128 }
0129 
0130 void KoFontFace::setStyle(const QString &style)
0131 {
0132     d->style = style;
0133 }
0134 
0135 KoFontFace::Pitch KoFontFace::pitch() const
0136 {
0137     return d->pitch;
0138 }
0139 
0140 void KoFontFace::setPitch(KoFontFace::Pitch pitch)
0141 {
0142     d->pitch = pitch;
0143 }
0144 
0145 void KoFontFace::saveOdf(KoXmlWriter* xmlWriter) const
0146 {
0147     Q_ASSERT(!isNull());
0148     if (isNull()) {
0149         warnOdf << "This font face is null and will not be saved: set at least the name";
0150         return;
0151     }
0152     d->saveOdf(xmlWriter);
0153 }