LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/style - MarkerStyle.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 112 113 99.1 %
Date: 2013-07-09 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             : 
      33             : using namespace ::com::sun::star;
      34             : 
      35             : using namespace ::xmloff::token;
      36             : 
      37             : 
      38             : //-------------------------------------------------------------
      39             : // Import
      40             : //-------------------------------------------------------------
      41             : 
      42          99 : XMLMarkerStyleImport::XMLMarkerStyleImport( SvXMLImport& rImp )
      43          99 :     : rImport( rImp )
      44             : {
      45          99 : }
      46             : 
      47          99 : XMLMarkerStyleImport::~XMLMarkerStyleImport()
      48             : {
      49          99 : }
      50             : 
      51          99 : sal_Bool XMLMarkerStyleImport::importXML(
      52             :     const uno::Reference< xml::sax::XAttributeList >& xAttrList,
      53             :     uno::Any& rValue,
      54             :     OUString& rStrName )
      55             : {
      56          99 :     sal_Bool bHasViewBox    = sal_False;
      57          99 :     sal_Bool bHasPathData   = sal_False;
      58          99 :     OUString aDisplayName;
      59             : 
      60          99 :     SdXMLImExViewBox* pViewBox = NULL;
      61             : 
      62          99 :     SvXMLNamespaceMap& rNamespaceMap = rImport.GetNamespaceMap();
      63          99 :     SvXMLUnitConverter& rUnitConverter = rImport.GetMM100UnitConverter();
      64             : 
      65         198 :     OUString strPathData;
      66             : 
      67          99 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      68         407 :     for( sal_Int16 i = 0; i < nAttrCount; i++ )
      69             :     {
      70         308 :         OUString aStrFullAttrName = xAttrList->getNameByIndex( i );
      71         616 :         OUString aStrAttrName;
      72         308 :         rNamespaceMap.GetKeyByAttrName( aStrFullAttrName, &aStrAttrName );
      73         616 :         OUString aStrValue = xAttrList->getValueByIndex( i );
      74             : 
      75         308 :         if( IsXMLToken( aStrAttrName, XML_NAME ) )
      76             :         {
      77          99 :             rStrName = aStrValue;
      78             :         }
      79         209 :         else if( IsXMLToken( aStrAttrName, XML_DISPLAY_NAME ) )
      80             :         {
      81          11 :             aDisplayName = aStrValue;
      82             :         }
      83         198 :         else if( IsXMLToken( aStrAttrName, XML_VIEWBOX ) )
      84             :         {
      85          99 :             pViewBox = new SdXMLImExViewBox( aStrValue, rUnitConverter );
      86          99 :             bHasViewBox = sal_True;
      87             : 
      88             :         }
      89          99 :         else if( IsXMLToken( aStrAttrName, XML_D ) )
      90             :         {
      91          99 :             strPathData = aStrValue;
      92          99 :             bHasPathData = sal_True;
      93             :         }
      94         308 :     }
      95             : 
      96          99 :     if( bHasViewBox && bHasPathData )
      97             :     {
      98             :         SdXMLImExSvgDElement aPoints(strPathData, *pViewBox, awt::Point( 0, 0 ),
      99          99 :             awt::Size( pViewBox->GetWidth(), pViewBox->GetHeight() ), rImport );
     100             : 
     101          99 :         if(aPoints.IsCurve())
     102             :         {
     103             :             drawing::PolyPolygonBezierCoords aSourcePolyPolygon(
     104           8 :                 aPoints.GetPointSequenceSequence(),
     105          16 :                 aPoints.GetFlagSequenceSequence());
     106           8 :             rValue <<= aSourcePolyPolygon;
     107             :         }
     108             :         else
     109             :         {
     110          91 :             drawing::PolyPolygonBezierCoords aSourcePolyPolygon;
     111          91 :             aSourcePolyPolygon.Coordinates = aPoints.GetPointSequenceSequence();
     112          91 :             aSourcePolyPolygon.Flags.realloc(aSourcePolyPolygon.Coordinates.getLength());
     113             : 
     114             :             // Zeiger auf innere sequences holen
     115          91 :             const drawing::PointSequence* pInnerSequence = aSourcePolyPolygon.Coordinates.getConstArray();
     116          91 :             drawing::FlagSequence* pInnerSequenceFlags = aSourcePolyPolygon.Flags.getArray();
     117             : 
     118         198 :             for(sal_Int32 a(0); a < aSourcePolyPolygon.Coordinates.getLength(); a++)
     119             :             {
     120         107 :                 pInnerSequenceFlags->realloc(pInnerSequence->getLength());
     121         107 :                 drawing::PolygonFlags* pPolyFlags = pInnerSequenceFlags->getArray();
     122             : 
     123        1057 :                 for(sal_Int32 b(0); b < pInnerSequence->getLength(); b++)
     124         950 :                     *pPolyFlags++ = drawing::PolygonFlags_NORMAL;
     125             : 
     126             :                 // next run
     127         107 :                 pInnerSequence++;
     128         107 :                 pInnerSequenceFlags++;
     129             :             }
     130             : 
     131          91 :             rValue <<= aSourcePolyPolygon;
     132             :         }
     133             : 
     134          99 :         if( !aDisplayName.isEmpty() )
     135             :         {
     136             :             rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_MARKER_ID, rStrName,
     137          11 :                                         aDisplayName );
     138          11 :             rStrName = aDisplayName;
     139          99 :         }
     140             : 
     141             :     }
     142             : 
     143          99 :     if( pViewBox )
     144          99 :         delete pViewBox;
     145             : 
     146         198 :     return bHasViewBox && bHasPathData;
     147             : }
     148             : 
     149             : 
     150             : //-------------------------------------------------------------
     151             : // Export
     152             : //-------------------------------------------------------------
     153             : 
     154          35 : XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport& rExp )
     155          35 :     : rExport( rExp )
     156             : {
     157          35 : }
     158             : 
     159          35 : XMLMarkerStyleExport::~XMLMarkerStyleExport()
     160             : {
     161          35 : }
     162             : 
     163           6 : sal_Bool XMLMarkerStyleExport::exportXML(
     164             :     const OUString& rStrName,
     165             :     const uno::Any& rValue )
     166             : {
     167           6 :     sal_Bool bRet(sal_False);
     168             : 
     169           6 :     if(!rStrName.isEmpty())
     170             :     {
     171           6 :         drawing::PolyPolygonBezierCoords aBezier;
     172             : 
     173           6 :         if(rValue >>= aBezier)
     174             :         {
     175             :             /////////////////
     176             :             // Name
     177           6 :             sal_Bool bEncoded = sal_False;
     178           6 :             OUString aStrName( rStrName );
     179             :             rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
     180             :                                   rExport.EncodeStyleName( aStrName,
     181           6 :                                                            &bEncoded ) );
     182           6 :             if( bEncoded )
     183             :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
     184           0 :                                       aStrName );
     185             : 
     186             :             /////////////////
     187             :             // Viewbox (viewBox="0 0 1500 1000")
     188           6 :             sal_Int32 nMinX(0x7fffffff);
     189           6 :             sal_Int32 nMaxX(0x80000000);
     190           6 :             sal_Int32 nMinY(0x7fffffff);
     191           6 :             sal_Int32 nMaxY(0x80000000);
     192           6 :             sal_Int32 nOuterCnt(aBezier.Coordinates.getLength());
     193           6 :             drawing::PointSequence* pOuterSequence = aBezier.Coordinates.getArray();
     194             :             sal_Int32 a, b;
     195           6 :             sal_Bool bClosed(sal_False);
     196             : 
     197          12 :             for (a = 0; a < nOuterCnt; a++)
     198             :             {
     199           6 :                 drawing::PointSequence* pSequence = pOuterSequence++;
     200           6 :                 const awt::Point *pPoints = pSequence->getConstArray();
     201           6 :                 sal_Int32 nPointCount(pSequence->getLength());
     202             : 
     203           6 :                 if(nPointCount)
     204             :                 {
     205           6 :                     const awt::Point aStart = pPoints[0];
     206           6 :                     const awt::Point aEnd = pPoints[nPointCount - 1];
     207             : 
     208           6 :                     if(aStart.X == aEnd.X && aStart.Y == aEnd.Y)
     209             :                     {
     210           6 :                         bClosed = sal_True;
     211             :                     }
     212             :                 }
     213             : 
     214          30 :                 for (b = 0; b < nPointCount; b++)
     215             :                 {
     216          24 :                     const awt::Point aPoint = pPoints[b];
     217             : 
     218          24 :                     if( aPoint.X < nMinX )
     219          12 :                         nMinX = aPoint.X;
     220             : 
     221          24 :                     if( aPoint.X > nMaxX )
     222          12 :                         nMaxX = aPoint.X;
     223             : 
     224          24 :                     if( aPoint.Y < nMinY )
     225           6 :                         nMinY = aPoint.Y;
     226             : 
     227          24 :                     if( aPoint.Y > nMaxY )
     228          12 :                         nMaxY = aPoint.Y;
     229             :                 }
     230             :             }
     231             : 
     232           6 :             sal_Int32 nDifX(nMaxX - nMinX);
     233           6 :             sal_Int32 nDifY(nMaxY - nMinY);
     234             : 
     235          12 :             SdXMLImExViewBox aViewBox( 0, 0, nDifX, nDifY );
     236           6 :             rExport.AddAttribute( XML_NAMESPACE_SVG, XML_VIEWBOX, aViewBox.GetExportString() );
     237             : 
     238             :             /////////////////
     239             :             // Pathdata
     240           6 :             pOuterSequence = aBezier.Coordinates.getArray();
     241           6 :             drawing::FlagSequence*  pOuterFlags = aBezier.Flags.getArray();
     242          12 :             SdXMLImExSvgDElement aSvgDElement(aViewBox, rExport);
     243             : 
     244          12 :             for (a = 0; a < nOuterCnt; a++)
     245             :             {
     246           6 :                 drawing::PointSequence* pSequence = pOuterSequence++;
     247           6 :                 drawing::FlagSequence* pFlags = pOuterFlags++;
     248             : 
     249             :                 aSvgDElement.AddPolygon(pSequence, pFlags,
     250             :                     awt::Point( 0, 0 ),
     251          12 :                     awt::Size( aViewBox.GetWidth(), aViewBox.GetHeight() ),
     252          18 :                     bClosed);
     253             :             }
     254             : 
     255             :             // write point array
     256           6 :             rExport.AddAttribute(XML_NAMESPACE_SVG, XML_D, aSvgDElement.GetExportString());
     257             : 
     258             :             /////////////////
     259             :             // Do Write
     260             :             SvXMLElementExport rElem( rExport, XML_NAMESPACE_DRAW, XML_MARKER,
     261          12 :                                       sal_True, sal_False );
     262           6 :         }
     263             :     }
     264             : 
     265           6 :     return bRet;
     266             : }
     267             : 
     268             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10