| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QSVGNODE_P_H |
| 5 | #define QSVGNODE_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include "qsvgstyle_p.h" |
| 19 | #include "qtsvgglobal_p.h" |
| 20 | #include "qsvghelper_p.h" |
| 21 | |
| 22 | #include "QtCore/qstring.h" |
| 23 | #include "QtCore/qhash.h" |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | class QPainter; |
| 28 | class QSvgTinyDocument; |
| 29 | |
| 30 | class Q_SVG_EXPORT QSvgNode |
| 31 | { |
| 32 | public: |
| 33 | enum Type |
| 34 | { |
| 35 | Doc, |
| 36 | Group, |
| 37 | Defs, |
| 38 | Switch, |
| 39 | AnimateColor, |
| 40 | AnimateTransform, |
| 41 | Circle, |
| 42 | Ellipse, |
| 43 | Image, |
| 44 | Line, |
| 45 | Path, |
| 46 | Polygon, |
| 47 | Polyline, |
| 48 | Rect, |
| 49 | Text, |
| 50 | Textarea, |
| 51 | Tspan, |
| 52 | Use, |
| 53 | Video, |
| 54 | Mask, |
| 55 | Symbol, |
| 56 | Marker, |
| 57 | Pattern, |
| 58 | Filter, |
| 59 | FeMerge, |
| 60 | FeMergenode, |
| 61 | FeColormatrix, |
| 62 | FeGaussianblur, |
| 63 | FeOffset, |
| 64 | FeComposite, |
| 65 | FeFlood, |
| 66 | FeBlend, |
| 67 | FeUnsupported |
| 68 | }; |
| 69 | enum DisplayMode { |
| 70 | InlineMode, |
| 71 | BlockMode, |
| 72 | ListItemMode, |
| 73 | RunInMode, |
| 74 | CompactMode, |
| 75 | MarkerMode, |
| 76 | TableMode, |
| 77 | InlineTableMode, |
| 78 | TableRowGroupMode, |
| 79 | , |
| 80 | , |
| 81 | TableRowMode, |
| 82 | TableColumnGroupMode, |
| 83 | TableColumnMode, |
| 84 | TableCellMode, |
| 85 | TableCaptionMode, |
| 86 | NoneMode, |
| 87 | InheritMode |
| 88 | }; |
| 89 | |
| 90 | public: |
| 91 | QSvgNode(QSvgNode *parent=0); |
| 92 | virtual ~QSvgNode(); |
| 93 | void (QPainter *p, QSvgExtraStates &states); |
| 94 | virtual bool separateFillStroke() const {return false;} |
| 95 | virtual void drawCommand(QPainter *p, QSvgExtraStates &states) = 0; |
| 96 | void (QPainter *p, QSvgExtraStates &states); |
| 97 | QImage (QPainter *p, QSvgExtraStates &states, const QRect &boundsRect); |
| 98 | void applyMaskToBuffer(QImage *proxy, QImage mask) const; |
| 99 | void (QPainter *p, QSvgExtraStates &states, const QImage &mask, const QRect &boundsRect); |
| 100 | void applyBufferToCanvas(QPainter *p, QImage proxy) const; |
| 101 | |
| 102 | QSvgNode *parent() const; |
| 103 | bool isDescendantOf(const QSvgNode *parent) const; |
| 104 | |
| 105 | void appendStyleProperty(QSvgStyleProperty *prop, const QString &id); |
| 106 | void (QPainter *p, QSvgExtraStates &states) const; |
| 107 | void (QPainter *p, QSvgExtraStates &states) const; |
| 108 | void (QPainter *p, QSvgExtraStates &states) const; |
| 109 | void (QPainter *p, QSvgExtraStates &states) const; |
| 110 | void (QPainter *p, QSvgExtraStates &states) const; |
| 111 | void (QPainter *p, QSvgExtraStates &states) const; |
| 112 | QSvgStyleProperty *styleProperty(QSvgStyleProperty::Type type) const; |
| 113 | QSvgPaintStyleProperty *styleProperty(QStringView id) const; |
| 114 | |
| 115 | QSvgTinyDocument *document() const; |
| 116 | |
| 117 | virtual Type type() const = 0; |
| 118 | QString typeName() const; |
| 119 | virtual QRectF (QPainter *p, QSvgExtraStates &states) const; |
| 120 | virtual QRectF (QPainter *p, QSvgExtraStates &states) const; |
| 121 | QRectF (QPainter *p, QSvgExtraStates &states) const; |
| 122 | QRectF bounds() const; |
| 123 | virtual QRectF (QPainter *p, QSvgExtraStates &states) const; |
| 124 | virtual QRectF (QPainter *p, QSvgExtraStates &states) const; |
| 125 | |
| 126 | void setRequiredFeatures(const QStringList &lst); |
| 127 | const QStringList & requiredFeatures() const; |
| 128 | |
| 129 | void setRequiredExtensions(const QStringList &lst); |
| 130 | const QStringList & requiredExtensions() const; |
| 131 | |
| 132 | void setRequiredLanguages(const QStringList &lst); |
| 133 | const QStringList & requiredLanguages() const; |
| 134 | |
| 135 | void setRequiredFormats(const QStringList &lst); |
| 136 | const QStringList & requiredFormats() const; |
| 137 | |
| 138 | void setRequiredFonts(const QStringList &lst); |
| 139 | const QStringList & requiredFonts() const; |
| 140 | |
| 141 | void setVisible(bool visible); |
| 142 | bool isVisible() const; |
| 143 | |
| 144 | void setDisplayMode(DisplayMode display); |
| 145 | DisplayMode displayMode() const; |
| 146 | |
| 147 | QString nodeId() const; |
| 148 | void setNodeId(const QString &i); |
| 149 | |
| 150 | QString xmlClass() const; |
| 151 | void setXmlClass(const QString &str); |
| 152 | |
| 153 | QString maskId() const; |
| 154 | void setMaskId(const QString &str); |
| 155 | bool hasMask() const; |
| 156 | |
| 157 | QString filterId() const; |
| 158 | void setFilterId(const QString &str); |
| 159 | bool hasFilter() const; |
| 160 | |
| 161 | QString markerStartId() const; |
| 162 | void setMarkerStartId(const QString &str); |
| 163 | bool hasMarkerStart() const; |
| 164 | |
| 165 | QString markerMidId() const; |
| 166 | void setMarkerMidId(const QString &str); |
| 167 | bool hasMarkerMid() const; |
| 168 | |
| 169 | QString markerEndId() const; |
| 170 | void setMarkerEndId(const QString &str); |
| 171 | bool hasMarkerEnd() const; |
| 172 | |
| 173 | bool hasAnyMarker() const; |
| 174 | |
| 175 | virtual bool requiresGroupRendering() const; |
| 176 | |
| 177 | virtual bool (QPainter *p, QSvgExtraStates &states) const; |
| 178 | const QSvgStaticStyle &style() const { return m_style; } |
| 179 | protected: |
| 180 | mutable QSvgStaticStyle m_style; |
| 181 | mutable QSvgAnimatedStyle m_animatedStyle; |
| 182 | |
| 183 | QRectF filterRegion(QRectF bounds) const; |
| 184 | |
| 185 | static qreal strokeWidth(QPainter *p); |
| 186 | static void initPainter(QPainter *p); |
| 187 | |
| 188 | enum BoundsMode { |
| 189 | Simplistic, |
| 190 | IncludeMiterLimit |
| 191 | }; |
| 192 | static QRectF boundsOnStroke(QPainter *p, const QPainterPath &path, |
| 193 | qreal width, BoundsMode mode); |
| 194 | |
| 195 | private: |
| 196 | QSvgNode *m_parent; |
| 197 | |
| 198 | QStringList m_requiredFeatures; |
| 199 | QStringList m_requiredExtensions; |
| 200 | QStringList m_requiredLanguages; |
| 201 | QStringList m_requiredFormats; |
| 202 | QStringList m_requiredFonts; |
| 203 | |
| 204 | QString m_id; |
| 205 | QString m_class; |
| 206 | QString m_maskId; |
| 207 | QString m_filterId; |
| 208 | QString m_markerStartId; |
| 209 | QString m_markerMidId; |
| 210 | QString m_markerEndId; |
| 211 | |
| 212 | mutable QRectF m_cachedBounds; |
| 213 | DisplayMode m_displayMode; |
| 214 | bool m_visible; |
| 215 | |
| 216 | friend class QSvgTinyDocument; |
| 217 | }; |
| 218 | |
| 219 | inline QSvgNode *QSvgNode::parent() const |
| 220 | { |
| 221 | return m_parent; |
| 222 | } |
| 223 | |
| 224 | inline bool QSvgNode::isVisible() const |
| 225 | { |
| 226 | return m_visible; |
| 227 | } |
| 228 | |
| 229 | inline QString QSvgNode::nodeId() const |
| 230 | { |
| 231 | return m_id; |
| 232 | } |
| 233 | |
| 234 | inline QString QSvgNode::xmlClass() const |
| 235 | { |
| 236 | return m_class; |
| 237 | } |
| 238 | |
| 239 | QT_END_NAMESPACE |
| 240 | |
| 241 | #endif // QSVGNODE_P_H |
| 242 | |