summaryrefslogtreecommitdiff
path: root/src/svg/qsvghandler.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QSvgFont: Initialize used member, remove unusedRobert Löhning2023-04-251-1/+1
| | | | | | | | | | | | Credit to OSS-Fuzz [ChangeLog][QtSvg] Fixed undefined behavior from using uninitialized variable. Pick-to: 6.5 6.2 5.15 Coverity-Id: 22618 Change-Id: Id52277bb0e2845f4d342e187dbb8093e9276b70c Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-071-1/+1
| | | | | | | | | | | | | | We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace. Task-number: QTBUG-99313 Change-Id: Id6b89c20f706350dbc632e1b48505cafc4cdbafb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Port from container::count() and length() to size()Marc Mutz2022-10-071-44/+44
| | | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8: auto QtContainerClass = anyOf( expr(hasType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))))).bind(o), expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)); makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container', with the extended set of container classes recognized. Change-Id: I591240bbee393617e15beee71a2a5e1e7ba79510 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix assert with wrong number of argument to animateTransformAllan Sandfeld Jensen2022-08-311-0/+2
| | | | | | Pick-to: 6.4 6.2 5.15 Change-Id: I8e864ab4213d65866b0004f115f4e7c7bf7173d5 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* Let CSS attributes have higher priority than the plain XML attributesEirik Aavitsland2022-07-141-108/+107
| | | | | | | | | | | | | | Although seemingly not well specified, the common behavior of web browsers and other SVG renderers is to give priority to attribute values specified in the CSS style attribute, in case of conflict. So make qtsvg do the same, by moving the CSS parsing block to after the XML attribute parsing block. Fixes: QTBUG-100068 Pick-to: 6.4 Change-Id: I769303d69509511103d96e8d26e2cfeac1f19494 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Use SPDX license identifiersLucie Gérard2022-06-131-38/+2
| | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. License files are organized under LICENSES directory. Pick-to: 6.4 Task-number: QTBUG-67283 Change-Id: Ie5a75414af5fda27f5b5f527f3543b088b674677 Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Fix missing null-check in parseBaseGradient()Edward Welbourne2022-03-251-2/+2
| | | | | | | | | | | | | | | | | Of the four functions returned by findStyleFactoryMethod(), two do in fact take care to cope if the first parameter is null; but the other two forward it to parseBaseGradient(), which did not, provoking a warning from CodeChecker. The single caller of parseBaseGradient() is in an if/else cascade in which some branches do assert m_nodes.isEmpty() before passing m_nodes.top() to their respective functions, but the parseBaseGradient() branch did not. I infer that its returns should check for null and duly add the missing null check, rather than asserting against it. Change-Id: I6c630f04522a0ae05021fe95d848be64abe6c20c Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* Fix deprecation warning: Use QColor::fromString() insteadAndy Nichols2022-03-181-1/+1
| | | | | | | Ctors taking a string has been marked deprecated (ce83a03cfd1@qtbase). Change-Id: I02caa6cbeb63de4190f0bcb6595f1c3ccb26d791 Reviewed-by: Christian Strømme <christian.stromme@qt.io>
* Adjust QSvgStyleSelector to change of virtual interface in qtbaseVolker Hilsheimer2022-01-171-1/+2
| | | | | | | | | Follows up on qtbase:cb27ed30f7bc58474eba991f837843eb76cbd339. Pick-to: 6.2 6.3 Task-number: QTBUG-99642 Change-Id: I94addd4467ab51697adac1042bdb15912930b539 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Unconditionally stop parsing after the svg end tagEirik Aavitsland2022-01-051-3/+1
| | | | | | | | | | | | | | | A QSvghandler may be created either with an external QXmlStreamReader object, or with a bytearray/iodevice, in which case it will create its own stream reader. The check to end parisng at the </svg> tag was active only in the first case. This could result in different behavior when reading an svg image from file vs. reading it from a bytearray or resource. Fixes: QTBUG-99407 Pick-to: 6.3 6.2 5.15 Change-Id: I187b39256f2b16ea952a3ae1b77c067ff96e4155 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Robert Löhning <robert.loehning@qt.io>
* Improve <use> node resolution processIvan Tkachenko2021-11-021-11/+11
| | | | | | | | | | | | | | Since QSvgUse nodes are the only ones that ever get stored in the m_resolveNodes member, we can avoid extra cast and checks around it. Also a more descriptive name wouldn't hurt. Currently, the list is merely cleaned at the end of a parsing process, but ideally it should not be stored at all, hence I left the comment for possible future optimizations, if anyone's willing to do it. Pick-to: 6.2 Change-Id: I86e83a8661679503e532c230e70f6d52092ad58e Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* Replace 0 with nullptrIvan Tkachenko2021-11-021-2/+2
| | | | | | Pick-to: 6.2 Change-Id: I26ecbed2ea48918df69fab4ec2a611a2e274919d Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Do stricter error checking when parsing path nodesEirik Aavitsland2021-10-271-34/+25
| | | | | | | | | | | | | The SVG spec mandates that path parsing should terminate on the first error encountered, and an error be reported. To improve the handling of corrupt files, implement such error handling, and also limit the number of QPainterPath elements to a reasonable range. Fixes: QTBUG-96044 Pick-to: 6.2 5.15 5.12 Change-Id: Ic5e65d6b658516d6f1317c72de365c8c7ad81891 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Robert Löhning <robert.loehning@qt.io>
* Replace 0 with nullptrZhang Hao2021-10-151-3/+3
| | | | | | | | We know that c++11 uses nullptr to replace 0, so we replace 0 with nullptr in the project. Change-Id: I81eb8c13339bf235ca5eab719526680e31fa26ed Reviewed-by: Albert Astals Cid <albert.astals.cid@kdab.com>
* Support font size not in pixelsAlbert Astals Cid2021-10-111-3/+4
| | | | | | | Fixes: QTBUG-97422 Pick-to: 6.2 Change-Id: I4df2af0e657f241af69480e6e30d454870df51d8 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* Fix text x/y when the length is not in pixelsAlbert Astals Cid2021-10-111-0/+2
| | | | | | | Fixes: QTBUG-97421 Pick-to: 6.2 Change-Id: I41f3cbf8e747530a67fe5074a988ba49aeb43b8e Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* Use qDegreesToRadians() rather than hand-rolled arithmeticEdward Welbourne2021-09-091-5/+3
| | | | | | | | | Doing so saves yet another approximation to pi/180 and spells out the semantics. Change-Id: Ied1bb9aa650a9535862622f891b716943de54cec Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Limit font size to avoid numerous overflowsRobert Löhning2021-07-271-1/+2
| | | | | | | | | | | | The font size will be passed through a QFixed in QFontEngineBox::ascent() and overflow there as well as in further places. [ChangeLog] Avoid numerous overflows by limiting font size to 0xffff. This fixes oss-fuzz issue 31701. Pick-to: 5.15 6.1 6.2 Change-Id: I2d00c5639804af9b056f0efc979e9899c5358cf7 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* Fix parsing of arc elements in pathsEirik Aavitsland2021-07-141-3/+16
| | | | | | | | | | | The arc element takes some flag parameters, which could be mixed up with the float parameters since svg does not require delimiting characters here. Hence legal svg would be misread.. Fixes: QTBUG-92184 Pick-to: 6.2 6.1 5.15 Change-Id: I5885c50d47e2e06ab0f02afefb7a5585c5c713ff Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
* Fix parsing of animation clock valuesEirik Aavitsland2021-07-121-35/+35
| | | | | | | | | | | | Color animation duration parsing mixed seconds and milliseconds. Factor out a common function for all clock value parsing, and add checking for overflow and illegal values as a driveby.. Fixes: QTBUG-94878 Pick-to: 6.2 6.1 5.15 Change-Id: Ie1d974cd2db55a3d65d7ce02c373021021070489 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
* Improve parsing of "r"Allan Sandfeld Jensen2021-03-051-3/+6
| | | | | | | | Negative r values are illegal, and zero means empty for circles. Pick-to: 6.1 Change-Id: Icb1d932f35909f71dafe1ee69eb2250eeb1bb2ad Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Clamp parsed doubles to float representable valuesAllan Sandfeld Jensen2021-03-041-1/+4
| | | | | | | | | | | | Parts of our rendering assumes incoming doubles can still be sane floats. Pick-to: 6.1 6.0 5.15 5.12 Fixes: QTBUG-91507 Change-Id: I7086a121e1b5ed47695a1251ea90e774dd8f148d Reviewed-by: Robert Löhning <robert.loehning@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Improve handling of malformed numeric values in svg filesEirik Aavitsland2020-12-031-0/+3
| | | | | | | | | | Catch cases where the input is not containable in a qreal, and avoid passing on inf values. Pick-to: 6.0 5.15 5.12 Change-Id: I1ab8932d94473916815385240c29e03afb0e0c9e Reviewed-by: Robert Loehning <robert.loehning@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Fix MSVC warning about integer conversionFriedemann Kleint2020-11-121-1/+1
| | | | | Change-Id: I4b17890099f74d6571e1aee9e4523c6b7b9fb7e9 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
* QtSvg: build with explicit QChar(int) constructorDavid Faure2020-11-071-2/+2
| | | | | Change-Id: I4d2a336b63f65ae6235b9a4b5c899e4d624492cd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add support for 'image-rendering' attributeAles Erjavec2020-11-031-0/+28
| | | | | | | | | | | Write and parse the 'image-rendering' attibute. The value is mapped to QPainter::SmoothPixmapTransform render hint. [ChangeLog] Add support for 'image-rendering' attribute Task-number: QTBUG-4145 Change-Id: I5268eac73b234cd195adade502ab9945a89f3ff6 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* Work around uninitialized variable in QRadialGradientLars Knoll2020-09-121-1/+1
| | | | | | | | Specify the focal radius explicitly to avoid an uninitialized variable in QGradient. Change-Id: I40e44579e2364862a8bc23ef54a9e858c4ba837a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Use OpenType font weightsJonas Karlsson2020-08-281-2/+2
| | | | | | Task-number: QTBUG-42248 Change-Id: If3984fa22b89a65fd126d42b3a2320d5ab16c94b Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* Fix check against division by zeroRobert Loehning2020-08-181-4/+5
| | | | | | | | | | The squared values must not be zero. Since both are qreal, this can happen even when neither of them is zero itself. Fixes: oss-fuzz-24738 Pick-to: 5.12 5.15 Change-Id: I61b2bc891e7e3831d4b6ee68b467db28c4f877d4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Don't divide by zeroRobert Loehning2020-08-041-0/+2
| | | | | | | Fixes: oss-fuzz-24308 Pick-to: 5.15 5.12 Change-Id: I628f073cc2ec99b18333d2831c53cd888ebc5780 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Don't divide by zeroVolker Hilsheimer2020-07-171-0/+3
| | | | | | | | Fixes: oss-fuzz-23731 Pick-to: 5.15 5.12 Change-Id: Ib21a32a30f7a204d263e6710f17567d91c6aae79 Reviewed-by: Robert Loehning <robert.loehning@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Fix stack overflow in dtor of QSvgTinyDocumentRobert Loehning2020-07-151-1/+10
| | | | | | | | | | Add a maximum to how many unfinished elements will be parsed by QSvgHandler. Fixes: oss-fuzz-24000 Pick-to: 5.15 5.12 Change-Id: I4cea0500d2bc503d2c509d091300dd1117170299 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Port QtSvg from QStringRef to QStringViewKarsten Heimrich2020-07-021-173/+135
| | | | | | | Task-number: QTBUG-84319 Change-Id: I6358030d1d7e0e023453edea10da535707320ea4 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove QXmlStreamStringRef usage hereLars Knoll2020-07-021-8/+8
| | | | | | | Simply using a QString is easier. Change-Id: I4088a2230a926fc125e3444da2a3763ce1317ce3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add ; to Q_UNUSEDLars Schmertmann2020-06-231-5/+5
| | | | | | | | | This is required to remove the ; from the macro with Qt 6. Task-number: QTBUG-82978 Change-Id: I24cc0f6735ddd8fb2444bc3bb4e7b202e8bbb43f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Add error handling to color parsingAllan Sandfeld Jensen2020-06-231-19/+22
| | | | | | | | | | Also fixes undefined shift of negative values. Fixes oss-fuzz 23644 Pick-to: 5.15 5.12 Change-Id: I08c998ebf2217cb8dc50fcb805603e01e67ad64b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Fix stack overflow in QSvgHandler::resolveGradientsAllan Sandfeld Jensen2020-06-231-4/+6
| | | | | | | | | | Add a maximum to how deep it will nest. Fixes oss-fuzz 23643 Pick-to: 5.15 5.12 Change-Id: I6183c04f65a539a6c7df42bc7346a86ee58aca6c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Handle empty rectsAllan Sandfeld Jensen2020-06-221-10/+15
| | | | | | | | | | | | Avoids a division by zero, also we don't appear to support auto sizes, so width and height are required attributes. Fixes oss-fuzz issue 23588. Pick-to: 5.15 5.12 Change-Id: Ib3474c2ed4409977f6ffcf73088956c6c59ce4ad Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Robert Loehning <robert.loehning@qt.io>
* Use QList instead of QVectorJarek Kobus2020-06-081-18/+18
| | | | | | Task-number: QTBUG-84469 Change-Id: I8c3e80c77422abeb23fff747bf4ca479ff0d35b3 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Merge remote-tracking branch 'origin/5.14' into 5.15v5.15.0-beta4v5.15.0-beta3Qt Forward Merge Bot2020-03-181-3/+6
|\ | | | | | | Change-Id: Ic4b8abc44f58b3d5d34cddf2743d0d172df4a374
| * Strip the quotes around the font familyAndy Shaw2020-03-101-3/+6
| | | | | | | | | | | | | | | | | | | | | | Due to changes in how QFont handles a family it should be given the whole string without quotes so it can find the family name correctly. Additionally, this changes it to use setFamilies instead of setFamily to make this more future-proof. Fixes: QTBUG-81926 Change-Id: I659950cf244c1f7a1a5dae6e7b0e136cfe274d47 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* | Use Qt::SplitBehavior in preference to QString::SplitBehaviorEdward Welbourne2020-03-021-2/+2
| | | | | | | | | | | | | | | | The Qt version was added in 5.14 "for use as eventual replacement for QString::SplitBehavior." Move another step closer to that goal. Change-Id: Ieabf1eeb03b682f06344d0373de036f8f4534042 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Don't use deprecated QMatrix class anymoreJarek Kobus2020-01-171-11/+12
|/ | | | | | Task-number: QTBUG-46653 Change-Id: I9944b62141d7054e3935000a819bebc5fd54df6c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Small performance improvements suggested by clang-tidyv5.14.0-beta2Albert Astals Cid2019-10-071-1/+1
| | | | | | | | | | * Add const & to function parameters * std::move an brush * Add const & to variables assigned from functions returning const & Change-Id: If412b78cc0198e24ce1c611fcd2026d0d723be80 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Fix leak in SVG font nodesAllan Sandfeld Jensen2019-04-241-7/+7
| | | | | | | | Their lifetime is controlled by the document, but the logic was confused and lost the node. Change-Id: Ib074dcf209d53ade894ee571a0bc08a1a7acfcab Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Fix assert on misplaced tspan elementAllan Sandfeld Jensen2019-04-121-0/+7
| | | | | Change-Id: I75b3a88aae3cbd7838474d7a78f29fcd58172fc2 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Fix IRI parsing, and use after freeAllan Sandfeld Jensen2019-03-041-2/+12
| | | | | | | | | | Make the parsing of IRI references tighter, and avoid freeing styles when inserting a duplicate id. Fixes: QTBUG-74104 Change-Id: I3a12fcf09ce1c55c135a4209817413ed8af75dec Reviewed-by: Robert Loehning <robert.loehning@qt.io> Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* Fix heap overflow in path parsingAllan Sandfeld Jensen2019-03-011-1/+1
| | | | | | Fixes: QTBUG-74129 Change-Id: I871c144f1df288a310e82aef979af7cfd7a54095 Reviewed-by: Robert Loehning <robert.loehning@qt.io>
* Don't leak nodes on parsing failuresAllan Sandfeld Jensen2019-02-271-3/+9
| | | | | | | | | | | The QSvgHandler always expects the caller to handle ownership of the generated document, also when the parsing failed. QSvgHandler also failed to handle misplaced group elements. Fixes: QTBUG-74083 Change-Id: I8907117d4305ecd84e328b201791001cb877fc60 Reviewed-by: Robert Loehning <robert.loehning@qt.io>
* Fix QSvgRenderer incorrect render of svg:imageDavid Crémoux2019-02-061-4/+4
| | | | | | | | | | The bounds of QSvgImage are integer based (QRect) which cause rounding issues when decimals values are used to define image (image shifted and with incorrect size). Changing the bounds to QRectF solves the issue. Fixes: QTBUG-73445 Change-Id: I49828e2c0b1917ec878844d520aac182581c23fb Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>