1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 20 #ifndef INCLUDED_SVGIO_INC_SVGPATTERNNODE_HXX 21 #define INCLUDED_SVGIO_INC_SVGPATTERNNODE_HXX 22 23 #include "svgnode.hxx" 24 #include "svgstyleattributes.hxx" 25 #include <memory> 26 27 namespace svgio 28 { 29 namespace svgreader 30 { 31 class SvgPatternNode : public SvgNode 32 { 33 private: 34 /// buffered decomposition 35 drawinglayer::primitive2d::Primitive2DContainer aPrimitives; 36 37 /// use styles 38 SvgStyleAttributes maSvgStyleAttributes; 39 40 /// variable scan values, dependent of given XAttributeList 41 std::unique_ptr<basegfx::B2DRange> 42 mpViewBox; 43 SvgAspectRatio maSvgAspectRatio; 44 SvgNumber maX; 45 SvgNumber maY; 46 SvgNumber maWidth; 47 SvgNumber maHeight; 48 std::unique_ptr<SvgUnits> 49 mpPatternUnits; 50 std::unique_ptr<SvgUnits> 51 mpPatternContentUnits; 52 std::unique_ptr<basegfx::B2DHomMatrix> 53 mpaPatternTransform; 54 55 /// link to another pattern used as style. If maXLink 56 /// is set, the node can be fetched on demand by using 57 // tryToFindLink (buffered) 58 mutable bool mbResolvingLink; // protect against infinite link recursion 59 OUString maXLink; 60 const SvgPatternNode* mpXLink; 61 62 /// link on demand 63 void tryToFindLink(); 64 65 public: 66 SvgPatternNode( 67 SvgDocument& rDocument, 68 SvgNode* pParent); 69 virtual ~SvgPatternNode() override; 70 71 virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; 72 virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; 73 74 /// global helpers 75 void getValuesRelative(double& rfX, double& rfY, double& rfW, double& rfH, const basegfx::B2DRange& rGeoRange, SvgNode const & rUser) const; 76 77 /// get pattern primitives buffered, uses decomposeSvgNode internally 78 const drawinglayer::primitive2d::Primitive2DContainer& getPatternPrimitives() const; 79 80 /// InfoProvider support for % values 81 virtual basegfx::B2DRange getCurrentViewPort() const override; 82 83 /// viewBox content 84 const basegfx::B2DRange* getViewBox() const; setViewBox(const basegfx::B2DRange * pViewBox)85 void setViewBox(const basegfx::B2DRange* pViewBox) { mpViewBox.reset(); if(pViewBox) mpViewBox.reset(new basegfx::B2DRange(*pViewBox)); } 86 87 /// SvgAspectRatio content 88 const SvgAspectRatio& getSvgAspectRatio() const; 89 90 /// X content, set if found in current context 91 const SvgNumber& getX() const; 92 93 /// Y content, set if found in current context 94 const SvgNumber& getY() const; 95 96 /// Width content, set if found in current context 97 const SvgNumber& getWidth() const; 98 99 /// Height content, set if found in current context 100 const SvgNumber& getHeight() const; 101 102 /// PatternUnits content 103 const SvgUnits* getPatternUnits() const; setPatternUnits(const SvgUnits aPatternUnits)104 void setPatternUnits(const SvgUnits aPatternUnits) { mpPatternUnits.reset( new SvgUnits(aPatternUnits) ); } 105 106 /// PatternContentUnits content 107 const SvgUnits* getPatternContentUnits() const; setPatternContentUnits(const SvgUnits aPatternContentUnits)108 void setPatternContentUnits(const SvgUnits aPatternContentUnits) { mpPatternContentUnits.reset( new SvgUnits(aPatternContentUnits) ); } 109 110 /// PatternTransform content 111 const basegfx::B2DHomMatrix* getPatternTransform() const; setPatternTransform(const basegfx::B2DHomMatrix * pMatrix)112 void setPatternTransform(const basegfx::B2DHomMatrix* pMatrix) { mpaPatternTransform.reset(); if(pMatrix) mpaPatternTransform.reset(new basegfx::B2DHomMatrix(*pMatrix)); } 113 114 }; 115 } // end of namespace svgreader 116 } // end of namespace svgio 117 118 #endif // INCLUDED_SVGIO_INC_SVGPATTERNNODE_HXX 119 120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 121