Avoid potential negative array index access to cached text.
[LibreOffice.git] / svgio / inc / svgpatternnode.hxx
blob75886040804cd6bb250807ca70c8211c77f83085
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include "svgnode.hxx"
23 #include "svgstyleattributes.hxx"
24 #include <basegfx/matrix/b2dhommatrix.hxx>
25 #include <memory>
27 namespace svgio::svgreader
29 class SvgPatternNode final : public SvgNode
31 private:
32 /// buffered decomposition
33 drawinglayer::primitive2d::Primitive2DContainer aPrimitives;
35 /// use styles
36 SvgStyleAttributes maSvgStyleAttributes;
38 /// variable scan values, dependent of given XAttributeList
39 std::unique_ptr<basegfx::B2DRange>
40 mpViewBox;
41 SvgAspectRatio maSvgAspectRatio;
42 SvgNumber maX;
43 SvgNumber maY;
44 SvgNumber maWidth;
45 SvgNumber maHeight;
46 std::optional<SvgUnits>
47 moPatternUnits;
48 std::optional<SvgUnits>
49 moPatternContentUnits;
50 std::optional<basegfx::B2DHomMatrix>
51 mpaPatternTransform;
53 /// link to another pattern used as style. If maXLink
54 /// is set, the node can be fetched on demand by using
55 // tryToFindLink (buffered)
56 mutable bool mbResolvingLink; // protect against infinite link recursion
57 OUString maXLink;
58 const SvgPatternNode* mpXLink;
60 /// link on demand
61 void tryToFindLink();
63 public:
64 SvgPatternNode(
65 SvgDocument& rDocument,
66 SvgNode* pParent);
67 virtual ~SvgPatternNode() override;
69 virtual const SvgStyleAttributes* getSvgStyleAttributes() const override;
70 virtual void parseAttribute(SVGToken aSVGToken, const OUString& aContent) override;
72 /// global helpers
73 void getValuesRelative(double& rfX, double& rfY, double& rfW, double& rfH, const basegfx::B2DRange& rGeoRange, SvgNode const & rUser) const;
75 /// get pattern primitives buffered, uses decomposeSvgNode internally
76 const drawinglayer::primitive2d::Primitive2DContainer& getPatternPrimitives() const;
78 /// InfoProvider support for % values
79 virtual basegfx::B2DRange getCurrentViewPort() const override;
81 /// viewBox content
82 const basegfx::B2DRange* getViewBox() const;
83 void setViewBox(const basegfx::B2DRange* pViewBox) { mpViewBox.reset(); if(pViewBox) mpViewBox.reset(new basegfx::B2DRange(*pViewBox)); }
85 /// SvgAspectRatio content
86 const SvgAspectRatio& getSvgAspectRatio() const;
88 /// X content, set if found in current context
89 const SvgNumber& getX() const;
91 /// Y content, set if found in current context
92 const SvgNumber& getY() const;
94 /// Width content, set if found in current context
95 const SvgNumber& getWidth() const;
97 /// Height content, set if found in current context
98 const SvgNumber& getHeight() const;
100 /// PatternUnits content
101 const SvgUnits* getPatternUnits() const;
102 void setPatternUnits(const SvgUnits aPatternUnits) { moPatternUnits = aPatternUnits; }
104 /// PatternContentUnits content
105 const SvgUnits* getPatternContentUnits() const;
106 void setPatternContentUnits(const SvgUnits aPatternContentUnits) { moPatternContentUnits = aPatternContentUnits; }
108 /// PatternTransform content
109 std::optional<basegfx::B2DHomMatrix> getPatternTransform() const;
110 void setPatternTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaPatternTransform = pMatrix; }
114 } // end of namespace svgio::svgreader
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */