LCOV - code coverage report
Current view: top level - xmloff/source/style - MarkerStyle.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 70 71 98.6 %
Date: 2014-11-03 Functions: 6 6 100.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 <xmloff/MarkerStyle.hxx>
      21             : #include "xexptran.hxx"
      22             : #include <xmloff/attrlist.hxx>
      23             : #include <xmloff/nmspmap.hxx>
      24             : #include <xmloff/xmluconv.hxx>
      25             : #include <xmloff/xmlnmspe.hxx>
      26             : #include <xmloff/xmltoken.hxx>
      27             : #include <xmloff/xmlexp.hxx>
      28             : #include <xmloff/xmlimp.hxx>
      29             : #include <rtl/ustrbuf.hxx>
      30             : #include <rtl/ustring.hxx>
      31             : #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
      32             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      33             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      34             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : 
      38             : using namespace ::xmloff::token;
      39             : 
      40             : // Import
      41             : 
      42         172 : XMLMarkerStyleImport::XMLMarkerStyleImport( SvXMLImport& rImp )
      43         172 :     : rImport( rImp )
      44             : {
      45         172 : }
      46             : 
      47         172 : XMLMarkerStyleImport::~XMLMarkerStyleImport()
      48             : {
      49         172 : }
      50             : 
      51         172 : bool XMLMarkerStyleImport::importXML(
      52             :     const uno::Reference< xml::sax::XAttributeList >& xAttrList,
      53             :     uno::Any& rValue,
      54             :     OUString& rStrName )
      55             : {
      56         172 :     bool bHasViewBox    = false;
      57         172 :     bool bHasPathData   = false;
      58         172 :     OUString aDisplayName;
      59             : 
      60         172 :     SdXMLImExViewBox* pViewBox = NULL;
      61             : 
      62         172 :     SvXMLNamespaceMap& rNamespaceMap = rImport.GetNamespaceMap();
      63         172 :     SvXMLUnitConverter& rUnitConverter = rImport.GetMM100UnitConverter();
      64             : 
      65         344 :     OUString strPathData;
      66             : 
      67         172 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      68         726 :     for( sal_Int16 i = 0; i < nAttrCount; i++ )
      69             :     {
      70         554 :         OUString aStrFullAttrName = xAttrList->getNameByIndex( i );
      71        1108 :         OUString aStrAttrName;
      72         554 :         rNamespaceMap.GetKeyByAttrName( aStrFullAttrName, &aStrAttrName );
      73        1108 :         OUString aStrValue = xAttrList->getValueByIndex( i );
      74             : 
      75         554 :         if( IsXMLToken( aStrAttrName, XML_NAME ) )
      76             :         {
      77         172 :             rStrName = aStrValue;
      78             :         }
      79         382 :         else if( IsXMLToken( aStrAttrName, XML_DISPLAY_NAME ) )
      80             :         {
      81          38 :             aDisplayName = aStrValue;
      82             :         }
      83         344 :         else if( IsXMLToken( aStrAttrName, XML_VIEWBOX ) )
      84             :         {
      85         172 :             pViewBox = new SdXMLImExViewBox( aStrValue, rUnitConverter );
      86         172 :             bHasViewBox = true;
      87             : 
      88             :         }
      89         172 :         else if( IsXMLToken( aStrAttrName, XML_D ) )
      90             :         {
      91         172 :             strPathData = aStrValue;
      92         172 :             bHasPathData = true;
      93             :         }
      94         554 :     }
      95             : 
      96         172 :     if( bHasViewBox && bHasPathData )
      97             :     {
      98         172 :         basegfx::B2DPolyPolygon aPolyPolygon;
      99             : 
     100         172 :         if(basegfx::tools::importFromSvgD(aPolyPolygon, strPathData, rImport.needFixPositionAfterZ(), 0))
     101             :         {
     102         172 :             if(aPolyPolygon.count())
     103             :             {
     104             :                 // ViewBox probably not used, but stay with former processing inside of
     105             :                 // SdXMLImExSvgDElement
     106             :                 const basegfx::B2DRange aSourceRange(
     107             :                     pViewBox->GetX(), pViewBox->GetY(),
     108         172 :                     pViewBox->GetX() + pViewBox->GetWidth(), pViewBox->GetY() + pViewBox->GetHeight());
     109             :                 const basegfx::B2DRange aTargetRange(
     110             :                     0.0, 0.0,
     111         172 :                     pViewBox->GetWidth(), pViewBox->GetHeight());
     112             : 
     113         172 :                 if(!aSourceRange.equal(aTargetRange))
     114             :                 {
     115             :                     aPolyPolygon.transform(
     116             :                         basegfx::tools::createSourceRangeTargetRangeTransform(
     117             :                             aSourceRange,
     118           0 :                             aTargetRange));
     119             :                 }
     120             : 
     121             :                 // always use PolyPolygonBezierCoords here
     122         172 :                 drawing::PolyPolygonBezierCoords aSourcePolyPolygon;
     123             : 
     124             :                 basegfx::tools::B2DPolyPolygonToUnoPolyPolygonBezierCoords(
     125             :                     aPolyPolygon,
     126         172 :                     aSourcePolyPolygon);
     127         172 :                 rValue <<= aSourcePolyPolygon;
     128             :             }
     129             :         }
     130             : 
     131         172 :         if( !aDisplayName.isEmpty() )
     132             :         {
     133             :             rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_MARKER_ID, rStrName,
     134          38 :                                         aDisplayName );
     135          38 :             rStrName = aDisplayName;
     136         172 :         }
     137             :     }
     138             : 
     139         172 :     if( pViewBox )
     140         172 :         delete pViewBox;
     141             : 
     142         344 :     return bHasViewBox && bHasPathData;
     143             : }
     144             : 
     145             : // Export
     146             : 
     147         674 : XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport& rExp )
     148         674 :     : rExport( rExp )
     149             : {
     150         674 : }
     151             : 
     152         674 : XMLMarkerStyleExport::~XMLMarkerStyleExport()
     153             : {
     154         674 : }
     155             : 
     156          24 : void XMLMarkerStyleExport::exportXML(
     157             :     const OUString& rStrName,
     158             :     const uno::Any& rValue )
     159             : {
     160          24 :     if(!rStrName.isEmpty())
     161             :     {
     162          24 :         drawing::PolyPolygonBezierCoords aBezier;
     163             : 
     164          24 :         if(rValue >>= aBezier)
     165             :         {
     166             :             // Name
     167          24 :             bool bEncoded(false);
     168          24 :             OUString aStrName( rStrName );
     169             : 
     170          24 :             rExport.AddAttribute(XML_NAMESPACE_DRAW, XML_NAME, rExport.EncodeStyleName( aStrName, &bEncoded ) );
     171             : 
     172          24 :             if( bEncoded )
     173             :             {
     174           2 :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, aStrName );
     175             :             }
     176             : 
     177             :             const basegfx::B2DPolyPolygon aPolyPolygon(
     178             :                 basegfx::tools::UnoPolyPolygonBezierCoordsToB2DPolyPolygon(
     179          48 :                     aBezier));
     180          24 :             const basegfx::B2DRange aPolyPolygonRange(aPolyPolygon.getB2DRange());
     181             : 
     182             : 
     183             :             // Viewbox (viewBox="0 0 1500 1000")
     184             : 
     185             :             SdXMLImExViewBox aViewBox(
     186             :                 aPolyPolygonRange.getMinX(),
     187             :                 aPolyPolygonRange.getMinY(),
     188             :                 aPolyPolygonRange.getWidth(),
     189          48 :                 aPolyPolygonRange.getHeight());
     190          24 :             rExport.AddAttribute( XML_NAMESPACE_SVG, XML_VIEWBOX, aViewBox.GetExportString() );
     191             : 
     192             :             // Pathdata
     193             :             const OUString aPolygonString(
     194             :                 basegfx::tools::exportToSvgD(
     195             :                     aPolyPolygon,
     196             :                     true,           // bUseRelativeCoordinates
     197             :                     false,          // bDetectQuadraticBeziers: not used in old, but maybe activated now
     198          48 :                     true));         // bHandleRelativeNextPointCompatible
     199             : 
     200             :             // write point array
     201          24 :             rExport.AddAttribute(XML_NAMESPACE_SVG, XML_D, aPolygonString);
     202             : 
     203             :             // Do Write
     204          48 :             SvXMLElementExport rElem( rExport, XML_NAMESPACE_DRAW, XML_MARKER, true, false );
     205          24 :         }
     206             :     }
     207          24 : }
     208             : 
     209             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10