1*ddde725dSArmin Le Grand /************************************************************** 2*ddde725dSArmin Le Grand * 3*ddde725dSArmin Le Grand * Licensed to the Apache Software Foundation (ASF) under one 4*ddde725dSArmin Le Grand * or more contributor license agreements. See the NOTICE file 5*ddde725dSArmin Le Grand * distributed with this work for additional information 6*ddde725dSArmin Le Grand * regarding copyright ownership. The ASF licenses this file 7*ddde725dSArmin Le Grand * to you under the Apache License, Version 2.0 (the 8*ddde725dSArmin Le Grand * "License"); you may not use this file except in compliance 9*ddde725dSArmin Le Grand * with the License. You may obtain a copy of the License at 10*ddde725dSArmin Le Grand * 11*ddde725dSArmin Le Grand * http://www.apache.org/licenses/LICENSE-2.0 12*ddde725dSArmin Le Grand * 13*ddde725dSArmin Le Grand * Unless required by applicable law or agreed to in writing, 14*ddde725dSArmin Le Grand * software distributed under the License is distributed on an 15*ddde725dSArmin Le Grand * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ddde725dSArmin Le Grand * KIND, either express or implied. See the License for the 17*ddde725dSArmin Le Grand * specific language governing permissions and limitations 18*ddde725dSArmin Le Grand * under the License. 19*ddde725dSArmin Le Grand * 20*ddde725dSArmin Le Grand *************************************************************/ 21*ddde725dSArmin Le Grand 22*ddde725dSArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove 23*ddde725dSArmin Le Grand #include "precompiled_svgio.hxx" 24*ddde725dSArmin Le Grand 25*ddde725dSArmin Le Grand #include <svgio/svgreader/svgrectnode.hxx> 26*ddde725dSArmin Le Grand #include <basegfx/polygon/b2dpolygon.hxx> 27*ddde725dSArmin Le Grand #include <basegfx/polygon/b2dpolygontools.hxx> 28*ddde725dSArmin Le Grand 29*ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 30*ddde725dSArmin Le Grand 31*ddde725dSArmin Le Grand namespace svgio 32*ddde725dSArmin Le Grand { 33*ddde725dSArmin Le Grand namespace svgreader 34*ddde725dSArmin Le Grand { 35*ddde725dSArmin Le Grand SvgRectNode::SvgRectNode( 36*ddde725dSArmin Le Grand SvgDocument& rDocument, 37*ddde725dSArmin Le Grand SvgNode* pParent) 38*ddde725dSArmin Le Grand : SvgNode(SVGTokenRect, rDocument, pParent), 39*ddde725dSArmin Le Grand maSvgStyleAttributes(*this), 40*ddde725dSArmin Le Grand maX(0), 41*ddde725dSArmin Le Grand maY(0), 42*ddde725dSArmin Le Grand maWidth(0), 43*ddde725dSArmin Le Grand maHeight(0), 44*ddde725dSArmin Le Grand maRx(0), 45*ddde725dSArmin Le Grand maRy(0), 46*ddde725dSArmin Le Grand mpaTransform(0) 47*ddde725dSArmin Le Grand { 48*ddde725dSArmin Le Grand } 49*ddde725dSArmin Le Grand 50*ddde725dSArmin Le Grand SvgRectNode::~SvgRectNode() 51*ddde725dSArmin Le Grand { 52*ddde725dSArmin Le Grand if(mpaTransform) delete mpaTransform; 53*ddde725dSArmin Le Grand } 54*ddde725dSArmin Le Grand 55*ddde725dSArmin Le Grand const SvgStyleAttributes* SvgRectNode::getSvgStyleAttributes() const 56*ddde725dSArmin Le Grand { 57*ddde725dSArmin Le Grand static rtl::OUString aClassStr(rtl::OUString::createFromAscii("rect")); 58*ddde725dSArmin Le Grand maSvgStyleAttributes.checkForCssStyle(aClassStr); 59*ddde725dSArmin Le Grand 60*ddde725dSArmin Le Grand return &maSvgStyleAttributes; 61*ddde725dSArmin Le Grand } 62*ddde725dSArmin Le Grand 63*ddde725dSArmin Le Grand void SvgRectNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent) 64*ddde725dSArmin Le Grand { 65*ddde725dSArmin Le Grand // call parent 66*ddde725dSArmin Le Grand SvgNode::parseAttribute(rTokenName, aSVGToken, aContent); 67*ddde725dSArmin Le Grand 68*ddde725dSArmin Le Grand // read style attributes 69*ddde725dSArmin Le Grand maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent); 70*ddde725dSArmin Le Grand 71*ddde725dSArmin Le Grand // parse own 72*ddde725dSArmin Le Grand switch(aSVGToken) 73*ddde725dSArmin Le Grand { 74*ddde725dSArmin Le Grand case SVGTokenStyle: 75*ddde725dSArmin Le Grand { 76*ddde725dSArmin Le Grand maSvgStyleAttributes.readStyle(aContent); 77*ddde725dSArmin Le Grand break; 78*ddde725dSArmin Le Grand } 79*ddde725dSArmin Le Grand case SVGTokenX: 80*ddde725dSArmin Le Grand { 81*ddde725dSArmin Le Grand SvgNumber aNum; 82*ddde725dSArmin Le Grand 83*ddde725dSArmin Le Grand if(readSingleNumber(aContent, aNum)) 84*ddde725dSArmin Le Grand { 85*ddde725dSArmin Le Grand setX(aNum); 86*ddde725dSArmin Le Grand } 87*ddde725dSArmin Le Grand break; 88*ddde725dSArmin Le Grand } 89*ddde725dSArmin Le Grand case SVGTokenY: 90*ddde725dSArmin Le Grand { 91*ddde725dSArmin Le Grand SvgNumber aNum; 92*ddde725dSArmin Le Grand 93*ddde725dSArmin Le Grand if(readSingleNumber(aContent, aNum)) 94*ddde725dSArmin Le Grand { 95*ddde725dSArmin Le Grand setY(aNum); 96*ddde725dSArmin Le Grand } 97*ddde725dSArmin Le Grand break; 98*ddde725dSArmin Le Grand } 99*ddde725dSArmin Le Grand case SVGTokenWidth: 100*ddde725dSArmin Le Grand { 101*ddde725dSArmin Le Grand SvgNumber aNum; 102*ddde725dSArmin Le Grand 103*ddde725dSArmin Le Grand if(readSingleNumber(aContent, aNum)) 104*ddde725dSArmin Le Grand { 105*ddde725dSArmin Le Grand if(aNum.isPositive()) 106*ddde725dSArmin Le Grand { 107*ddde725dSArmin Le Grand setWidth(aNum); 108*ddde725dSArmin Le Grand } 109*ddde725dSArmin Le Grand } 110*ddde725dSArmin Le Grand break; 111*ddde725dSArmin Le Grand } 112*ddde725dSArmin Le Grand case SVGTokenHeight: 113*ddde725dSArmin Le Grand { 114*ddde725dSArmin Le Grand SvgNumber aNum; 115*ddde725dSArmin Le Grand 116*ddde725dSArmin Le Grand if(readSingleNumber(aContent, aNum)) 117*ddde725dSArmin Le Grand { 118*ddde725dSArmin Le Grand if(aNum.isPositive()) 119*ddde725dSArmin Le Grand { 120*ddde725dSArmin Le Grand setHeight(aNum); 121*ddde725dSArmin Le Grand } 122*ddde725dSArmin Le Grand } 123*ddde725dSArmin Le Grand break; 124*ddde725dSArmin Le Grand } 125*ddde725dSArmin Le Grand case SVGTokenRx: 126*ddde725dSArmin Le Grand { 127*ddde725dSArmin Le Grand SvgNumber aNum; 128*ddde725dSArmin Le Grand 129*ddde725dSArmin Le Grand if(readSingleNumber(aContent, aNum)) 130*ddde725dSArmin Le Grand { 131*ddde725dSArmin Le Grand if(aNum.isPositive()) 132*ddde725dSArmin Le Grand { 133*ddde725dSArmin Le Grand setRx(aNum); 134*ddde725dSArmin Le Grand } 135*ddde725dSArmin Le Grand } 136*ddde725dSArmin Le Grand break; 137*ddde725dSArmin Le Grand } 138*ddde725dSArmin Le Grand case SVGTokenRy: 139*ddde725dSArmin Le Grand { 140*ddde725dSArmin Le Grand SvgNumber aNum; 141*ddde725dSArmin Le Grand 142*ddde725dSArmin Le Grand if(readSingleNumber(aContent, aNum)) 143*ddde725dSArmin Le Grand { 144*ddde725dSArmin Le Grand if(aNum.isPositive()) 145*ddde725dSArmin Le Grand { 146*ddde725dSArmin Le Grand setRy(aNum); 147*ddde725dSArmin Le Grand } 148*ddde725dSArmin Le Grand } 149*ddde725dSArmin Le Grand break; 150*ddde725dSArmin Le Grand } 151*ddde725dSArmin Le Grand case SVGTokenTransform: 152*ddde725dSArmin Le Grand { 153*ddde725dSArmin Le Grand const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this)); 154*ddde725dSArmin Le Grand 155*ddde725dSArmin Le Grand if(!aMatrix.isIdentity()) 156*ddde725dSArmin Le Grand { 157*ddde725dSArmin Le Grand setTransform(&aMatrix); 158*ddde725dSArmin Le Grand } 159*ddde725dSArmin Le Grand break; 160*ddde725dSArmin Le Grand } 161*ddde725dSArmin Le Grand } 162*ddde725dSArmin Le Grand } 163*ddde725dSArmin Le Grand 164*ddde725dSArmin Le Grand void SvgRectNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const 165*ddde725dSArmin Le Grand { 166*ddde725dSArmin Le Grand // get size range and create path 167*ddde725dSArmin Le Grand const SvgStyleAttributes* pStyle = getSvgStyleAttributes(); 168*ddde725dSArmin Le Grand 169*ddde725dSArmin Le Grand if(pStyle && getWidth().isSet() && getHeight().isSet()) 170*ddde725dSArmin Le Grand { 171*ddde725dSArmin Le Grand const double fWidth(getWidth().solve(*this, xcoordinate)); 172*ddde725dSArmin Le Grand const double fHeight(getHeight().solve(*this, ycoordinate)); 173*ddde725dSArmin Le Grand 174*ddde725dSArmin Le Grand if(fWidth > 0.0 && fHeight > 0.0) 175*ddde725dSArmin Le Grand { 176*ddde725dSArmin Le Grand const double fX(getX().isSet() ? getX().solve(*this, xcoordinate) : 0.0); 177*ddde725dSArmin Le Grand const double fY(getY().isSet() ? getY().solve(*this, ycoordinate) : 0.0); 178*ddde725dSArmin Le Grand const basegfx::B2DRange aRange(fX, fY, fX + fWidth, fY + fHeight); 179*ddde725dSArmin Le Grand basegfx::B2DPolygon aPath; 180*ddde725dSArmin Le Grand 181*ddde725dSArmin Le Grand if(getRx().isSet() || getRy().isSet()) 182*ddde725dSArmin Le Grand { 183*ddde725dSArmin Le Grand double frX(getRx().isSet() ? getRx().solve(*this, xcoordinate) : 0.0); 184*ddde725dSArmin Le Grand double frY(getRy().isSet() ? getRy().solve(*this, ycoordinate) : 0.0); 185*ddde725dSArmin Le Grand 186*ddde725dSArmin Le Grand frX = std::max(0.0, frX); 187*ddde725dSArmin Le Grand frY = std::max(0.0, frY); 188*ddde725dSArmin Le Grand 189*ddde725dSArmin Le Grand if(0.0 == frY && frX > 0.0) 190*ddde725dSArmin Le Grand { 191*ddde725dSArmin Le Grand frY = frX; 192*ddde725dSArmin Le Grand } 193*ddde725dSArmin Le Grand else if(0.0 == frX && frY > 0.0) 194*ddde725dSArmin Le Grand { 195*ddde725dSArmin Le Grand frX = frY; 196*ddde725dSArmin Le Grand } 197*ddde725dSArmin Le Grand 198*ddde725dSArmin Le Grand frX /= fWidth; 199*ddde725dSArmin Le Grand frY /= fHeight; 200*ddde725dSArmin Le Grand 201*ddde725dSArmin Le Grand frX = std::min(0.5, frX); 202*ddde725dSArmin Le Grand frY = std::min(0.5, frY); 203*ddde725dSArmin Le Grand 204*ddde725dSArmin Le Grand aPath = basegfx::tools::createPolygonFromRect(aRange, frX * 2.0, frY * 2.0); 205*ddde725dSArmin Le Grand } 206*ddde725dSArmin Le Grand else 207*ddde725dSArmin Le Grand { 208*ddde725dSArmin Le Grand aPath = basegfx::tools::createPolygonFromRect(aRange); 209*ddde725dSArmin Le Grand } 210*ddde725dSArmin Le Grand 211*ddde725dSArmin Le Grand drawinglayer::primitive2d::Primitive2DSequence aNewTarget; 212*ddde725dSArmin Le Grand 213*ddde725dSArmin Le Grand pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget); 214*ddde725dSArmin Le Grand 215*ddde725dSArmin Le Grand if(aNewTarget.hasElements()) 216*ddde725dSArmin Le Grand { 217*ddde725dSArmin Le Grand pStyle->add_postProcess(rTarget, aNewTarget, getTransform()); 218*ddde725dSArmin Le Grand } 219*ddde725dSArmin Le Grand } 220*ddde725dSArmin Le Grand } 221*ddde725dSArmin Le Grand } 222*ddde725dSArmin Le Grand } // end of namespace svgreader 223*ddde725dSArmin Le Grand } // end of namespace svgio 224*ddde725dSArmin Le Grand 225*ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 226*ddde725dSArmin Le Grand // eof 227