1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_svgio.hxx" 24 25 #include <svgio/svgreader/svgmarkernode.hxx> 26 27 ////////////////////////////////////////////////////////////////////////////// 28 29 namespace svgio 30 { 31 namespace svgreader 32 { 33 SvgMarkerNode::SvgMarkerNode( 34 SvgDocument& rDocument, 35 SvgNode* pParent) 36 : SvgNode(SVGTokenMarker, rDocument, pParent), 37 aPrimitives(), 38 maSvgStyleAttributes(*this), 39 mpViewBox(0), 40 maSvgAspectRatio(), 41 maRefX(0), 42 maRefY(0), 43 maMarkerUnits(strokeWidth), 44 maMarkerWidth(3), 45 maMarkerHeight(3), 46 mfAngle(0.0), 47 mbOrientAuto(false) 48 { 49 } 50 51 SvgMarkerNode::~SvgMarkerNode() 52 { 53 if(mpViewBox) delete mpViewBox; 54 } 55 56 const SvgStyleAttributes* SvgMarkerNode::getSvgStyleAttributes() const 57 { 58 static rtl::OUString aClassStr(rtl::OUString::createFromAscii("marker")); 59 maSvgStyleAttributes.checkForCssStyle(aClassStr); 60 61 return &maSvgStyleAttributes; 62 } 63 64 void SvgMarkerNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent) 65 { 66 // call parent 67 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent); 68 69 // read style attributes 70 maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent); 71 72 // parse own 73 switch(aSVGToken) 74 { 75 case SVGTokenStyle: 76 { 77 maSvgStyleAttributes.readStyle(aContent); 78 break; 79 } 80 case SVGTokenViewBox: 81 { 82 const basegfx::B2DRange aRange(readViewBox(aContent, *this)); 83 84 if(!aRange.isEmpty()) 85 { 86 setViewBox(&aRange); 87 } 88 break; 89 } 90 case SVGTokenPreserveAspectRatio: 91 { 92 setSvgAspectRatio(readSvgAspectRatio(aContent)); 93 break; 94 } 95 case SVGTokenRefX: 96 { 97 SvgNumber aNum; 98 99 if(readSingleNumber(aContent, aNum)) 100 { 101 setRefX(aNum); 102 } 103 break; 104 } 105 case SVGTokenRefY: 106 { 107 SvgNumber aNum; 108 109 if(readSingleNumber(aContent, aNum)) 110 { 111 setRefY(aNum); 112 } 113 break; 114 } 115 case SVGTokenMarkerUnits: 116 { 117 if(aContent.getLength()) 118 { 119 static rtl::OUString aStrStrokeWidth(rtl::OUString::createFromAscii("strokeWidth")); 120 121 if(aContent.match(aStrStrokeWidth, 0)) 122 { 123 setMarkerUnits(strokeWidth); 124 } 125 else if(aContent.match(commonStrings::aStrUserSpaceOnUse, 0)) 126 { 127 setMarkerUnits(userSpaceOnUse); 128 } 129 } 130 break; 131 } 132 case SVGTokenMarkerWidth: 133 { 134 SvgNumber aNum; 135 136 if(readSingleNumber(aContent, aNum)) 137 { 138 if(aNum.isPositive()) 139 { 140 setMarkerWidth(aNum); 141 } 142 } 143 break; 144 } 145 case SVGTokenMarkerHeight: 146 { 147 SvgNumber aNum; 148 149 if(readSingleNumber(aContent, aNum)) 150 { 151 if(aNum.isPositive()) 152 { 153 setMarkerHeight(aNum); 154 } 155 } 156 break; 157 } 158 case SVGTokenOrient: 159 { 160 const sal_Int32 nLen(aContent.getLength()); 161 162 if(nLen) 163 { 164 static rtl::OUString aStrAuto(rtl::OUString::createFromAscii("auto")); 165 166 if(aContent.match(aStrAuto, 0)) 167 { 168 setOrientAuto(true); 169 } 170 else 171 { 172 sal_Int32 nPos(0); 173 double fAngle(0.0); 174 175 if(readAngle(aContent, nPos, fAngle, nLen)) 176 { 177 setAngle(fAngle); 178 } 179 } 180 } 181 break; 182 } 183 } 184 } 185 186 const drawinglayer::primitive2d::Primitive2DSequence& SvgMarkerNode::getMarkerPrimitives() const 187 { 188 if(!aPrimitives.hasElements()) 189 { 190 decomposeSvgNode(const_cast< SvgMarkerNode* >(this)->aPrimitives, true); 191 } 192 193 return aPrimitives; 194 } 195 196 const basegfx::B2DRange* SvgMarkerNode::getCurrentViewPort() const 197 { 198 if(getViewBox()) 199 { 200 return getViewBox(); 201 } 202 else 203 { 204 return SvgNode::getCurrentViewPort(); 205 } 206 } 207 208 } // end of namespace svgreader 209 } // end of namespace svgio 210 211 ////////////////////////////////////////////////////////////////////////////// 212 // eof 213