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

Generated by: LCOV version 1.10