LCOV - code coverage report
Current view: top level - svgio/source/svgreader - svgtextnode.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 100 0.0 %
Date: 2014-04-11 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #include <svgio/svgreader/svgtextnode.hxx>
      21             : #include <svgio/svgreader/svgcharacternode.hxx>
      22             : #include <svgio/svgreader/svgstyleattributes.hxx>
      23             : #include <svgio/svgreader/svgtrefnode.hxx>
      24             : #include <svgio/svgreader/svgtextpathnode.hxx>
      25             : #include <svgio/svgreader/svgtspannode.hxx>
      26             : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
      27             : #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
      28             : 
      29             : 
      30             : 
      31             : namespace svgio
      32             : {
      33             :     namespace svgreader
      34             :     {
      35           0 :         SvgTextNode::SvgTextNode(
      36             :             SvgDocument& rDocument,
      37             :             SvgNode* pParent)
      38             :         :   SvgNode(SVGTokenText, rDocument, pParent),
      39             :             maSvgStyleAttributes(*this),
      40             :             mpaTransform(0),
      41           0 :             maSvgTextPositions()
      42             :         {
      43           0 :         }
      44             : 
      45           0 :         SvgTextNode::~SvgTextNode()
      46             :         {
      47           0 :             if(mpaTransform) delete mpaTransform;
      48           0 :         }
      49             : 
      50           0 :         const SvgStyleAttributes* SvgTextNode::getSvgStyleAttributes() const
      51             :         {
      52           0 :             return checkForCssStyle(OUString("text"), maSvgStyleAttributes);
      53             :         }
      54             : 
      55           0 :         void SvgTextNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
      56             :         {
      57             :             // call parent
      58           0 :             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
      59             : 
      60             :             // read style attributes
      61           0 :             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
      62             : 
      63             :             // read text position attributes
      64           0 :             maSvgTextPositions.parseTextPositionAttributes(rTokenName, aSVGToken, aContent);
      65             : 
      66             :             // parse own
      67           0 :             switch(aSVGToken)
      68             :             {
      69             :                 case SVGTokenStyle:
      70             :                 {
      71           0 :                     maSvgStyleAttributes.readStyle(aContent);
      72           0 :                     break;
      73             :                 }
      74             :                 case SVGTokenTransform:
      75             :                 {
      76           0 :                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
      77             : 
      78           0 :                     if(!aMatrix.isIdentity())
      79             :                     {
      80           0 :                         setTransform(&aMatrix);
      81             :                     }
      82           0 :                     break;
      83             :                 }
      84             :                 default:
      85             :                 {
      86           0 :                     break;
      87             :                 }
      88             :             }
      89           0 :         }
      90             : 
      91           0 :         void SvgTextNode::addTextPrimitives(
      92             :             const SvgNode& rCandidate,
      93             :             drawinglayer::primitive2d::Primitive2DSequence& rTarget,
      94             :             drawinglayer::primitive2d::Primitive2DSequence& rSource) const
      95             :         {
      96           0 :             if(rSource.hasElements())
      97             :             {
      98           0 :                 const SvgStyleAttributes* pAttributes = rCandidate.getSvgStyleAttributes();
      99             : 
     100           0 :                 if(pAttributes)
     101             :                 {
     102             :                     // add text with taking all Fill/Stroke attributes into account
     103           0 :                     pAttributes->add_text(rTarget, rSource);
     104             :                 }
     105             :                 else
     106             :                 {
     107             :                     // should not happen, every subnode from SvgTextNode will at least
     108             :                     // return the attributes from SvgTextNode. Nonetheless, add text
     109           0 :                     drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget, rSource);
     110             :                 }
     111             :             }
     112           0 :         }
     113             : 
     114           0 :         void SvgTextNode::DecomposeChild(const SvgNode& rCandidate, drawinglayer::primitive2d::Primitive2DSequence& rTarget, SvgTextPosition& rSvgTextPosition) const
     115             :         {
     116           0 :             switch(rCandidate.getType())
     117             :             {
     118             :                 case SVGTokenCharacter:
     119             :                 {
     120             :                     // direct SvgTextPathNode derivates, decompose them
     121           0 :                     const SvgCharacterNode& rSvgCharacterNode = static_cast< const SvgCharacterNode& >(rCandidate);
     122           0 :                     rSvgCharacterNode.decomposeText(rTarget, rSvgTextPosition);
     123           0 :                     break;
     124             :                 }
     125             :                 case SVGTokenTextPath:
     126             :                 {
     127             :                     // direct TextPath decompose
     128           0 :                     const SvgTextPathNode& rSvgTextPathNode = static_cast< const SvgTextPathNode& >(rCandidate);
     129           0 :                     const SvgNodeVector& rChildren = rSvgTextPathNode.getChildren();
     130           0 :                     const sal_uInt32 nCount(rChildren.size());
     131             : 
     132           0 :                     if(nCount && rSvgTextPathNode.isValid())
     133             :                     {
     134             :                         // remember original TextStart to later detect hor/ver offsets
     135           0 :                         const basegfx::B2DPoint aTextStart(rSvgTextPosition.getPosition());
     136           0 :                         drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
     137             : 
     138             :                         // decompose to regular TextPrimitives
     139           0 :                         for(sal_uInt32 a(0); a < nCount; a++)
     140             :                         {
     141           0 :                             DecomposeChild(*rChildren[a], aNewTarget, rSvgTextPosition);
     142             :                         }
     143             : 
     144           0 :                         if(aNewTarget.hasElements())
     145             :                         {
     146           0 :                             const drawinglayer::primitive2d::Primitive2DSequence aPathContent(aNewTarget);
     147           0 :                             aNewTarget.realloc(0);
     148             : 
     149             :                             // dismantle TextPrimitives and map them on curve/path
     150           0 :                             rSvgTextPathNode.decomposePathNode(aPathContent, aNewTarget, aTextStart);
     151             :                         }
     152             : 
     153           0 :                         if(aNewTarget.hasElements())
     154             :                         {
     155           0 :                             addTextPrimitives(rCandidate, rTarget, aNewTarget);
     156           0 :                         }
     157             :                     }
     158             : 
     159           0 :                     break;
     160             :                 }
     161             :                 case SVGTokenTspan:
     162             :                 {
     163             :                     // Tspan may have children, call recursively
     164           0 :                     const SvgTspanNode& rSvgTspanNode = static_cast< const SvgTspanNode& >(rCandidate);
     165           0 :                     const SvgNodeVector& rChildren = rSvgTspanNode.getChildren();
     166           0 :                     const sal_uInt32 nCount(rChildren.size());
     167             : 
     168           0 :                     if(nCount)
     169             :                     {
     170           0 :                         SvgTextPosition aSvgTextPosition(&rSvgTextPosition, rSvgTspanNode, rSvgTspanNode.getSvgTextPositions());
     171           0 :                         drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
     172             : 
     173           0 :                         for(sal_uInt32 a(0); a < nCount; a++)
     174             :                         {
     175           0 :                             DecomposeChild(*rChildren[a], aNewTarget, aSvgTextPosition);
     176             :                         }
     177             : 
     178           0 :                         rSvgTextPosition.setPosition(aSvgTextPosition.getPosition());
     179             : 
     180           0 :                         if(aNewTarget.hasElements())
     181             :                         {
     182           0 :                             addTextPrimitives(rCandidate, rTarget, aNewTarget);
     183           0 :                         }
     184             :                     }
     185           0 :                     break;
     186             :                 }
     187             :                 case SVGTokenTref:
     188             :                 {
     189           0 :                     const SvgTrefNode& rSvgTrefNode = static_cast< const SvgTrefNode& >(rCandidate);
     190           0 :                     const SvgTextNode* pRefText = rSvgTrefNode.getReferencedSvgTextNode();
     191             : 
     192           0 :                     if(pRefText)
     193             :                     {
     194           0 :                         const SvgNodeVector& rChildren = pRefText->getChildren();
     195           0 :                         const sal_uInt32 nCount(rChildren.size());
     196           0 :                         drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
     197             : 
     198           0 :                         if(nCount)
     199             :                         {
     200           0 :                             for(sal_uInt32 a(0); a < nCount; a++)
     201             :                             {
     202           0 :                                 const SvgNode& rChildCandidate = *rChildren[a];
     203           0 :                                 const_cast< SvgNode& >(rChildCandidate).setAlternativeParent(this);
     204             : 
     205           0 :                                 DecomposeChild(rChildCandidate, aNewTarget, rSvgTextPosition);
     206           0 :                                 const_cast< SvgNode& >(rChildCandidate).setAlternativeParent(0);
     207             :                             }
     208             : 
     209           0 :                             if(aNewTarget.hasElements())
     210             :                             {
     211           0 :                                 addTextPrimitives(rCandidate, rTarget, aNewTarget);
     212             :                             }
     213           0 :                         }
     214             :                     }
     215             : 
     216           0 :                     break;
     217             :                 }
     218             :                 default:
     219             :                 {
     220             :                     OSL_ENSURE(false, "Unexpected node in text token (!)");
     221           0 :                     break;
     222             :                 }
     223             :             }
     224           0 :         }
     225             : 
     226           0 :         void SvgTextNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced`*/) const
     227             :         {
     228             :             // text has a group of child nodes, allowed are SVGTokenCharacter, SVGTokenTspan,
     229             :             // SVGTokenTref and SVGTokenTextPath. These increase a given current text position
     230           0 :             const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
     231             : 
     232           0 :             if(pStyle && !getChildren().empty())
     233             :             {
     234           0 :                 const double fOpacity(pStyle->getOpacity().getNumber());
     235             : 
     236           0 :                 if(fOpacity > 0.0)
     237             :                 {
     238           0 :                     SvgTextPosition aSvgTextPosition(0, *this, getSvgTextPositions());
     239           0 :                     drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
     240           0 :                     const SvgNodeVector& rChildren = getChildren();
     241           0 :                     const sal_uInt32 nCount(rChildren.size());
     242             : 
     243           0 :                     for(sal_uInt32 a(0); a < nCount; a++)
     244             :                     {
     245           0 :                         const SvgNode& rCandidate = *rChildren[a];
     246             : 
     247           0 :                         DecomposeChild(rCandidate, aNewTarget, aSvgTextPosition);
     248             :                     }
     249             : 
     250           0 :                     if(aNewTarget.hasElements())
     251             :                     {
     252           0 :                         drawinglayer::primitive2d::Primitive2DSequence aNewTarget2;
     253             : 
     254           0 :                         addTextPrimitives(*this, aNewTarget2, aNewTarget);
     255           0 :                         aNewTarget = aNewTarget2;
     256             :                     }
     257             : 
     258           0 :                     if(aNewTarget.hasElements())
     259             :                     {
     260           0 :                         pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
     261           0 :                     }
     262             :                 }
     263             :             }
     264           0 :         }
     265             :     } // end of namespace svgreader
     266             : } // end of namespace svgio
     267             : 
     268             : 
     269             : // eof
     270             : 
     271             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10