2014-11-13 19:30:51 +02:00
|
|
|
/*
|
|
|
|
* KFontInst - KDE Font Installer
|
|
|
|
*
|
|
|
|
* Copyright 2003-2009 Craig Drummond <craig@kde.org>
|
|
|
|
*
|
|
|
|
* ----
|
|
|
|
*
|
|
|
|
* 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 of the License, 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; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QtCore/QTextStream>
|
|
|
|
#include <QtCore/QStringList>
|
2015-08-12 13:11:16 +03:00
|
|
|
#include <QtXml/qdom.h>
|
2014-11-13 19:30:51 +02:00
|
|
|
#include "Fc.h"
|
|
|
|
#include "Style.h"
|
|
|
|
#include "XmlStrings.h"
|
|
|
|
|
|
|
|
namespace KFI
|
|
|
|
{
|
|
|
|
|
|
|
|
Style::Style(const QDomElement &elem, bool loadFiles)
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
int weight(KFI_NULL_SETTING), width(KFI_NULL_SETTING), slant(KFI_NULL_SETTING),
|
|
|
|
tmp(KFI_NULL_SETTING);
|
|
|
|
|
|
|
|
if(elem.hasAttribute(WEIGHT_ATTR))
|
|
|
|
{
|
|
|
|
tmp=elem.attribute(WEIGHT_ATTR).toInt(&ok);
|
|
|
|
if(ok)
|
|
|
|
weight=tmp;
|
|
|
|
}
|
|
|
|
if(elem.hasAttribute(WIDTH_ATTR))
|
|
|
|
{
|
|
|
|
tmp=elem.attribute(WIDTH_ATTR).toInt(&ok);
|
|
|
|
if(ok)
|
|
|
|
width=tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(elem.hasAttribute(SLANT_ATTR))
|
|
|
|
{
|
|
|
|
tmp=elem.attribute(SLANT_ATTR).toInt(&ok);
|
|
|
|
if(ok)
|
|
|
|
slant=tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
itsScalable=!elem.hasAttribute(SCALABLE_ATTR) || elem.attribute(SCALABLE_ATTR)!="false";
|
|
|
|
itsValue=FC::createStyleVal(weight, width, slant);
|
|
|
|
|
|
|
|
if(loadFiles)
|
|
|
|
{
|
|
|
|
if(elem.hasAttribute(PATH_ATTR))
|
|
|
|
{
|
|
|
|
File file(elem, false);
|
|
|
|
|
|
|
|
if(!file.path().isEmpty())
|
|
|
|
itsFiles.insert(file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(QDomNode n=elem.firstChild(); !n.isNull(); n=n.nextSibling())
|
|
|
|
{
|
|
|
|
QDomElement ent=n.toElement();
|
|
|
|
|
|
|
|
if(FILE_TAG==ent.tagName())
|
|
|
|
{
|
|
|
|
File file(ent, false);
|
|
|
|
|
|
|
|
if(!file.path().isEmpty())
|
|
|
|
itsFiles.insert(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Style::toXml(bool disabled, const QString &family, QTextStream &s) const
|
|
|
|
{
|
|
|
|
QStringList files;
|
|
|
|
FileCont::ConstIterator it(itsFiles.begin()),
|
|
|
|
end(itsFiles.end());
|
|
|
|
|
|
|
|
for(; it!=end; ++it)
|
|
|
|
{
|
|
|
|
QString f((*it).toXml(disabled, s));
|
|
|
|
|
|
|
|
if(!f.isEmpty())
|
|
|
|
files.append(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(files.count()>0)
|
|
|
|
{
|
2019-05-15 18:22:45 +00:00
|
|
|
QString str(" <" FONT_TAG " ");
|
2014-11-13 19:30:51 +02:00
|
|
|
int weight,
|
|
|
|
width,
|
|
|
|
slant;
|
|
|
|
|
|
|
|
KFI::FC::decomposeStyleVal(itsValue, weight, width, slant);
|
|
|
|
|
|
|
|
if(!family.isEmpty())
|
2019-05-15 18:22:45 +00:00
|
|
|
str+= FAMILY_ATTR "=\""+family+"\" ";
|
2014-11-13 19:30:51 +02:00
|
|
|
if(KFI_NULL_SETTING!=weight)
|
2019-05-15 18:22:45 +00:00
|
|
|
str+=WEIGHT_ATTR "=\""+QString::number(weight)+"\" ";
|
2014-11-13 19:30:51 +02:00
|
|
|
if(KFI_NULL_SETTING!=width)
|
2019-05-15 18:22:45 +00:00
|
|
|
str+= WIDTH_ATTR "=\""+QString::number(width)+"\" ";
|
2014-11-13 19:30:51 +02:00
|
|
|
if(KFI_NULL_SETTING!=slant)
|
2019-05-15 18:22:45 +00:00
|
|
|
str+= SLANT_ATTR "=\""+QString::number(slant)+"\" ";
|
2014-11-13 19:30:51 +02:00
|
|
|
if(!itsScalable)
|
2019-05-15 18:22:45 +00:00
|
|
|
str+= SCALABLE_ATTR "=\"false\" ";
|
2014-11-13 19:30:51 +02:00
|
|
|
|
|
|
|
if(1==files.count())
|
|
|
|
str+=(*files.begin())+"/>";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QStringList::ConstIterator it(files.begin()),
|
|
|
|
end(files.end());
|
|
|
|
|
|
|
|
str+=">\n";
|
|
|
|
for(; it!=end; ++it)
|
2019-05-15 18:22:45 +00:00
|
|
|
str+=" <" FILE_TAG " "+(*it)+"/>\n";
|
|
|
|
str+=" </" FONT_TAG ">";
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-05-08 14:49:03 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
2014-11-13 19:30:51 +02:00
|
|
|
QDBusArgument & operator<<(QDBusArgument &argument, const KFI::Style &obj)
|
|
|
|
{
|
|
|
|
argument.beginStructure();
|
|
|
|
|
2021-06-16 09:58:33 +03:00
|
|
|
argument << obj.value() << obj.scalable();
|
2014-11-13 19:30:51 +02:00
|
|
|
argument.beginArray(qMetaTypeId<KFI::File>());
|
|
|
|
KFI::FileCont::ConstIterator it(obj.files().begin()),
|
|
|
|
end(obj.files().end());
|
|
|
|
for(; it!=end; ++it)
|
|
|
|
argument << *it;
|
|
|
|
argument.endArray();
|
|
|
|
argument.endStructure();
|
|
|
|
return argument;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDBusArgument & operator>>(const QDBusArgument &argument, KFI::Style &obj)
|
|
|
|
{
|
|
|
|
quint32 value;
|
|
|
|
bool scalable;
|
|
|
|
argument.beginStructure();
|
2021-06-16 09:58:33 +03:00
|
|
|
argument >> value >> scalable;
|
|
|
|
obj=KFI::Style(value, scalable);
|
2014-11-13 19:30:51 +02:00
|
|
|
argument.beginArray();
|
|
|
|
while(!argument.atEnd())
|
|
|
|
{
|
|
|
|
KFI::File f;
|
|
|
|
argument >> f;
|
|
|
|
obj.add(f);
|
|
|
|
}
|
|
|
|
argument.endArray();
|
|
|
|
argument.endStructure();
|
|
|
|
return argument;
|
|
|
|
}
|
2019-05-08 14:49:03 +00:00
|
|
|
QT_END_NAMESPACE
|