1 // Copyright (C) 2012-2019 The VPaint Developers. 2 // See the COPYRIGHT file at the top-level directory of this distribution 3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 #ifndef SVGPARSER_H 18 #define SVGPARSER_H 19 20 #include <QColor> 21 22 class QString; 23 class QXmlStreamAttributes; 24 struct SvgImportParams; 25 class XmlStreamReader; 26 27 // https://www.w3.org/TR/SVG11/painting.html#SpecifyingPaint 28 struct SvgPaint { SvgPaintSvgPaint29 SvgPaint() : hasColor(false), color(Qt::black) {} SvgPaintSvgPaint30 SvgPaint(const QColor& color) : hasColor(true), color(color) {} 31 bool hasColor; 32 QColor color; 33 }; 34 35 class SvgPresentationAttributes 36 { 37 public: 38 SvgPresentationAttributes(); 39 void applyChildStyle(const QXmlStreamAttributes& attrs); 40 41 operator QString() const; 42 43 // Note: fill-opacity, stroke-opacity, and opacity are 44 // already factored in the alpha channel of the public 45 // variables `fill` and `stroke` below. Also, strokeWidth 46 // is set to zero if stroke.hasColor = false. 47 SvgPaint fill, stroke; 48 double strokeWidth; 49 50 private: 51 // Computed values after applying inheritance rules. 52 // 53 // Note that fill-opacity is separately inherited from fill, so we cannot 54 // just store fill-opacity inside the alpha value of fill (same for stroke 55 // and stroke-opacity). 56 // 57 SvgPaint fill_, stroke_; 58 double fillOpacity_, strokeOpacity_, strokeWidth_; 59 60 // Opacity. This is not inherited but composed as a post-processing step. 61 // See comment in the implementation of applyChildStyle(), and: 62 // https://www.w3.org/TR/SVG11/masking.html#OpacityProperty 63 // https://www.w3.org/TR/SVG11/render.html#Grouping 64 double opacity_; 65 66 // Update public variables 67 void update_(); 68 }; 69 70 class SvgParser 71 { 72 public: 73 static void readSvg(XmlStreamReader &xml, const SvgImportParams& params); 74 }; 75 76 #endif // SVGPARSER_H 77