Commit 69a9ccf3 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Load the title and description of the collection svg

parent 99a85e1a
......@@ -43,6 +43,8 @@
struct KoSvgSymbolCollectionResource::Private {
QVector<KoSvgSymbol*> symbols;
QString title;
QString description;
};
......@@ -134,9 +136,16 @@ bool KoSvgSymbolCollectionResource::loadFromDevice(QIODevice *dev)
// We're not interested in the shapes themselves
qDeleteAll(parser.parseSvg(doc.documentElement(), &fragmentSize));
d->symbols = parser.takeSymbols();
qDebug() << "Loaded" << filename() << "got" << d->symbols.size() << "symbols"
qDebug() << "Loaded" << filename() << "\n\t"
<< "Title" << parser.documentTitle() << "\n\t"
<< "Description" << parser.documentDescription()
<< "\n\tgot" << d->symbols.size() << "symbols"
<< d->symbols[0]->shape->outlineRect()
<< d->symbols[0]->shape->size();
d->title = parser.documentTitle();
d->description = parser.documentDescription();
if (d->symbols.size() < 1) {
setValid(false);
return false;
......@@ -189,12 +198,12 @@ QString KoSvgSymbolCollectionResource::defaultFileExtension() const
QString KoSvgSymbolCollectionResource::title() const
{
return "";
return d->title;
}
QString KoSvgSymbolCollectionResource::description() const
{
return "";
return d->description;
}
QString KoSvgSymbolCollectionResource::creator() const
......
......@@ -1196,6 +1196,25 @@ QList<KoShape*> SvgParser::parseSvg(const KoXmlElement &e, QSizeF *fragmentSize)
QList<KoShape*> shapes;
// First find the metadata
for (KoXmlNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
KoXmlElement b = n.toElement();
if (b.isNull())
continue;
if (b.tagName() == "title") {
m_documentTitle = b.text().trimmed();
}
else if (b.tagName() == "desc") {
m_documentDescription = b.text().trimmed();
}
else if (b.tagName() == "metadata") {
// TODO: parse the metadata
}
}
// SVG 1.1: skip the rendering of the element if it has null viewBox
if (gc->currentBoundingBox.isValid()) {
shapes = parseContainer(e);
......@@ -1226,6 +1245,16 @@ QList<QExplicitlySharedDataPointer<KoMarker> > SvgParser::knownMarkers() const
return m_markers.values();
}
QString SvgParser::documentTitle() const
{
return m_documentTitle;
}
QString SvgParser::documentDescription() const
{
return m_documentDescription;
}
void SvgParser::setFileFetcher(SvgParser::FileFetcherFunc func)
{
m_context.setFileFetcher(func);
......
......@@ -73,34 +73,52 @@ public:
QList<QExplicitlySharedDataPointer<KoMarker>> knownMarkers() const;
QString documentTitle() const;
QString documentDescription() const;
protected:
/// Parses a group-like element element, saving all its topmost properties
KoShape* parseGroup(const KoXmlElement &e, const KoXmlElement &overrideChildrenFrom = KoXmlElement());
/// Parses a container element, returning a list of child shapes
QList<KoShape*> parseContainer(const KoXmlElement &);
/// XXX
QList<KoShape*> parseSingleElement(const KoXmlElement &b);
/// Parses a use element, returning a list of child shapes
KoShape* parseUse(const KoXmlElement &);
/// Parses a gradient element
SvgGradientHelper *parseGradient(const KoXmlElement &);
/// Parses a pattern element
QSharedPointer<KoVectorPatternBackground> parsePattern(const KoXmlElement &e, const KoShape *__shape);
/// Parses a filter element
bool parseFilter(const KoXmlElement &, const KoXmlElement &referencedBy = KoXmlElement());
/// Parses a clip path element
bool parseClipPath(const KoXmlElement &);
bool parseClipMask(const KoXmlElement &e);
bool parseMarker(const KoXmlElement &e);
bool parseSymbol(const KoXmlElement &e);
/// parses a length attribute
qreal parseUnit(const QString &, bool horiz = false, bool vert = false, const QRectF &bbox = QRectF());
/// parses a length attribute in x-direction
qreal parseUnitX(const QString &unit);
/// parses a length attribute in y-direction
qreal parseUnitY(const QString &unit);
/// parses a length attribute in xy-direction
qreal parseUnitXY(const QString &unit);
/// parses a angular attribute values, result in radians
qreal parseAngular(const QString &unit);
......@@ -108,14 +126,19 @@ protected:
/// Creates an object from the given xml element
KoShape * createObject(const KoXmlElement &, const SvgStyles &style = SvgStyles());
/// Create path object from the given xml element
KoShape * createPath(const KoXmlElement &);
/// find gradient with given id in gradient map
SvgGradientHelper* findGradient(const QString &id);
/// find pattern with given id in pattern map
QSharedPointer<KoVectorPatternBackground> findPattern(const QString &id, const KoShape *shape);
/// find filter with given id in filter map
SvgFilterHelper* findFilter(const QString &id, const QString &href = QString());
/// find clip path with given id in clip path map
SvgClipPathHelper* findClipPath(const QString &id);
......@@ -124,6 +147,7 @@ protected:
/// creates a shape from the given shape id
KoShape * createShape(const QString &shapeID);
/// Creates shape from specified svg element
KoShape * createShapeFromElement(const KoXmlElement &element, SvgLoadingContext &context);
......@@ -172,6 +196,10 @@ private:
QList<KoShape*> m_shapes;
QVector<KoSvgSymbol*> m_symbols;
QList<KoShape*> m_toplevelShapes;
QString m_documentTitle;
QString m_documentDescription;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment