File indexing completed on 2024-06-09 04:20:51
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2002-2003, 2005 Rob Buis <buis@kde.org> 0003 * SPDX-FileCopyrightText: 2005-2006 Tim Beaulen <tbscope@gmail.com> 0004 * SPDX-FileCopyrightText: 2005, 2007-2009 Jan Hambrecht <jaham@gmx.net> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef SVGSTYLEPARSER_H 0010 #define SVGSTYLEPARSER_H 0011 0012 #include "kritaflake_export.h" 0013 #include <QMap> 0014 #include <QGradient> 0015 0016 #include <QDomDocument> 0017 0018 typedef QMap<QString, QString> SvgStyles; 0019 0020 class SvgLoadingContext; 0021 class SvgGraphicsContext; 0022 class QColor; 0023 class QGradient; 0024 0025 0026 class KRITAFLAKE_EXPORT SvgStyleParser 0027 { 0028 public: 0029 explicit SvgStyleParser(SvgLoadingContext &context); 0030 ~SvgStyleParser(); 0031 0032 /// Parses specified style attributes 0033 void parseStyle(const SvgStyles &styles); 0034 0035 /// Parses font attributes 0036 void parseFont(const SvgStyles &styles); 0037 0038 /// Parses a color attribute 0039 bool parseColor(QColor &, const QString &); 0040 0041 QPair<qreal, QColor> parseColorStop(const QDomElement&, SvgGraphicsContext* context, qreal& previousOffset); 0042 0043 /// Parses gradient color stops 0044 void parseColorStops(QGradient *, const QDomElement &, SvgGraphicsContext *context, const QGradientStops &defaultStops); 0045 0046 /// Creates style map from given xml element 0047 SvgStyles collectStyles(const QDomElement &); 0048 0049 /// Merges two style elements, returning the merged style 0050 SvgStyles mergeStyles(const SvgStyles &, const SvgStyles &); 0051 0052 /// Merges two style elements, returning the merged style 0053 SvgStyles mergeStyles(const QDomElement &, const QDomElement &); 0054 0055 SvgStyles parseOneCssStyle(const QString &style, const QStringList &interestingAttributes); 0056 private: 0057 0058 /// Parses a single style attribute 0059 void parsePA(SvgGraphicsContext *, const QString &, const QString &); 0060 0061 /// Returns inherited attribute value for specified element 0062 QString inheritedAttribute(const QString &attributeName, const QDomElement &e); 0063 0064 class Private; 0065 Private * const d; 0066 }; 0067 0068 #endif // SVGSTYLEPARSER_H