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 #pragma once 21 22 #include "svgnode.hxx" 23 #include "svgstyleattributes.hxx" 24 #include <basegfx/matrix/b2dhommatrix.hxx> 25 #include <memory> 26 27 namespace svgio::svgreader 28 { 29 class SvgPatternNode : public SvgNode 30 { 31 private: 32 /// buffered decomposition 33 drawinglayer::primitive2d::Primitive2DContainer aPrimitives; 34 35 /// use styles 36 SvgStyleAttributes maSvgStyleAttributes; 37 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::unique_ptr<SvgUnits> 47 mpPatternUnits; 48 std::unique_ptr<SvgUnits> 49 mpPatternContentUnits; 50 std::unique_ptr<basegfx::B2DHomMatrix> 51 mpaPatternTransform; 52 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; 59 60 /// link on demand 61 void tryToFindLink(); 62 63 public: 64 SvgPatternNode( 65 SvgDocument& rDocument, 66 SvgNode* pParent); 67 virtual ~SvgPatternNode() override; 68 69 virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; 70 virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; 71 72 /// global helpers 73 void getValuesRelative(double& rfX, double& rfY, double& rfW, double& rfH, const basegfx::B2DRange& rGeoRange, SvgNode const & rUser) const; 74 75 /// get pattern primitives buffered, uses decomposeSvgNode internally 76 const drawinglayer::primitive2d::Primitive2DContainer& getPatternPrimitives() const; 77 78 /// InfoProvider support for % values 79 virtual basegfx::B2DRange getCurrentViewPort() const override; 80 81 /// viewBox content 82 const basegfx::B2DRange* getViewBox() const; setViewBox(const basegfx::B2DRange * pViewBox)83 void setViewBox(const basegfx::B2DRange* pViewBox) { mpViewBox.reset(); if(pViewBox) mpViewBox.reset(new basegfx::B2DRange(*pViewBox)); } 84 85 /// SvgAspectRatio content 86 const SvgAspectRatio& getSvgAspectRatio() const; 87 88 /// X content, set if found in current context 89 const SvgNumber& getX() const; 90 91 /// Y content, set if found in current context 92 const SvgNumber& getY() const; 93 94 /// Width content, set if found in current context 95 const SvgNumber& getWidth() const; 96 97 /// Height content, set if found in current context 98 const SvgNumber& getHeight() const; 99 100 /// PatternUnits content 101 const SvgUnits* getPatternUnits() const; setPatternUnits(const SvgUnits aPatternUnits)102 void setPatternUnits(const SvgUnits aPatternUnits) { mpPatternUnits.reset( new SvgUnits(aPatternUnits) ); } 103 104 /// PatternContentUnits content 105 const SvgUnits* getPatternContentUnits() const; setPatternContentUnits(const SvgUnits aPatternContentUnits)106 void setPatternContentUnits(const SvgUnits aPatternContentUnits) { mpPatternContentUnits.reset( new SvgUnits(aPatternContentUnits) ); } 107 108 /// PatternTransform content 109 const basegfx::B2DHomMatrix* getPatternTransform() const; setPatternTransform(const basegfx::B2DHomMatrix * pMatrix)110 void setPatternTransform(const basegfx::B2DHomMatrix* pMatrix) { mpaPatternTransform.reset(); if(pMatrix) mpaPatternTransform.reset(new basegfx::B2DHomMatrix(*pMatrix)); } 111 112 }; 113 114 } // end of namespace svgio::svgreader 115 116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 117