LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextShapeImportHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 50 54 92.6 %
Date: 2012-08-25 Functions: 3 4 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 49 99 49.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/text/XTextContent.hpp>
      30                 :            : #include <com/sun/star/text/TextContentAnchorType.hpp>
      31                 :            : 
      32                 :            : #include <sax/tools/converter.hxx>
      33                 :            : 
      34                 :            : #include <xmloff/xmlimp.hxx>
      35                 :            : #include <xmloff/txtimp.hxx>
      36                 :            : #include <xmloff/xmluconv.hxx>
      37                 :            : #include <xmloff/nmspmap.hxx>
      38                 :            : #include "XMLAnchorTypePropHdl.hxx"
      39                 :            : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      40                 :            : #include <com/sun/star/drawing/XShapes.hpp>
      41                 :            : #include "xmloff/XMLTextShapeImportHelper.hxx"
      42                 :            : 
      43                 :            : using ::rtl::OUString;
      44                 :            : using ::rtl::OUStringBuffer;
      45                 :            : 
      46                 :            : using namespace ::com::sun::star::uno;
      47                 :            : using namespace ::com::sun::star::frame;
      48                 :            : using namespace ::com::sun::star::drawing;
      49                 :            : using namespace ::com::sun::star::beans;
      50                 :            : using namespace ::com::sun::star::text;
      51                 :            : using namespace ::com::sun::star::container;
      52                 :            : using namespace ::com::sun::star::xml::sax;
      53                 :            : 
      54                 :        126 : XMLTextShapeImportHelper::XMLTextShapeImportHelper(
      55                 :            :         SvXMLImport& rImp ) :
      56                 :        126 :     XMLShapeImportHelper( rImp, rImp.GetModel(),
      57                 :            :                           XMLTextImportHelper::CreateShapeExtPropMapper(rImp) ),
      58                 :            :     rImport( rImp ),
      59                 :            :     sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType")),
      60                 :            :     sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo")),
      61 [ +  - ][ +  - ]:        252 :     sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition"))
                 [ +  - ]
      62                 :            : {
      63         [ +  - ]:        126 :     Reference < XDrawPageSupplier > xDPS( rImp.GetModel(), UNO_QUERY );
      64         [ +  - ]:        126 :     if( xDPS.is() )
      65                 :            :     {
      66 [ +  - ][ +  - ]:        126 :          Reference < XShapes > xShapes( xDPS->getDrawPage(), UNO_QUERY );
                 [ +  - ]
      67         [ +  - ]:        126 :         pushGroupForSorting( xShapes );
      68                 :        126 :     }
      69                 :            : 
      70                 :        126 : }
      71                 :            : 
      72                 :        126 : XMLTextShapeImportHelper::~XMLTextShapeImportHelper()
      73                 :            : {
      74         [ +  - ]:        126 :     popGroupAndSort();
      75         [ -  + ]:        126 : }
      76                 :            : 
      77                 :         20 : void XMLTextShapeImportHelper::addShape(
      78                 :            :     Reference< XShape >& rShape,
      79                 :            :     const Reference< XAttributeList >& xAttrList,
      80                 :            :     Reference< XShapes >& rShapes )
      81                 :            : {
      82         [ -  + ]:         20 :     if( rShapes.is() )
      83                 :            :     {
      84                 :            :         // It's a group shape or 3DScene , so we have to call the base class method.
      85         [ #  # ]:          0 :         XMLShapeImportHelper::addShape( rShape, xAttrList, rShapes );
      86                 :         20 :         return;
      87                 :            :     }
      88                 :            : 
      89                 :         20 :     TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
      90                 :         20 :     sal_Int16   nPage = 0;
      91                 :         20 :     sal_Int32   nY = 0;
      92                 :            : 
      93                 :            :     UniReference < XMLTextImportHelper > xTxtImport =
      94         [ +  - ]:         20 :         rImport.GetTextImport();
      95                 :            :     const SvXMLTokenMap& rTokenMap =
      96 [ +  - ][ +  - ]:         20 :         xTxtImport->GetTextFrameAttrTokenMap();
      97                 :            : 
      98 [ +  - ][ +  - ]:         20 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
                 [ +  - ]
      99         [ +  + ]:        211 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     100                 :            :     {
     101 [ +  - ][ +  - ]:        191 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
     102 [ +  - ][ +  - ]:        191 :         const OUString& rValue = xAttrList->getValueByIndex( i );
     103                 :            : 
     104                 :        191 :         OUString aLocalName;
     105                 :            :         sal_uInt16 nPrefix =
     106                 :        191 :             rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName,
     107         [ +  - ]:        191 :                                                             &aLocalName );
     108         [ +  - ]:        191 :         switch( rTokenMap.Get( nPrefix, aLocalName ) )
           [ +  +  +  + ]
     109                 :            :         {
     110                 :            :         case XML_TOK_TEXT_FRAME_ANCHOR_TYPE:
     111                 :            :             {
     112                 :            :                 TextContentAnchorType eNew;
     113                 :            :                 // OD 2004-06-01 #i26791# - allow all anchor types
     114 [ +  - ][ +  - ]:         20 :                 if ( XMLAnchorTypePropHdl::convert( rValue, eNew ) )
     115                 :            :                 {
     116                 :         20 :                     eAnchorType = eNew;
     117                 :            :                 }
     118                 :            :             }
     119                 :         20 :             break;
     120                 :            :         case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER:
     121                 :            :             {
     122                 :            :                 sal_Int32 nTmp;
     123 [ +  - ][ +  - ]:         14 :                 if (::sax::Converter::convertNumber(nTmp, rValue, 1, SHRT_MAX))
     124                 :         14 :                     nPage = (sal_Int16)nTmp;
     125                 :            :             }
     126                 :         14 :             break;
     127                 :            :         case XML_TOK_TEXT_FRAME_Y:
     128         [ +  - ]:         20 :             rImport.GetMM100UnitConverter().convertMeasureToCore( nY, rValue );
     129                 :         20 :             break;
     130                 :            :         }
     131                 :        191 :     }
     132                 :            : 
     133         [ +  - ]:         20 :     Reference < XPropertySet > xPropSet( rShape, UNO_QUERY );
     134                 :         20 :     Any aAny;
     135                 :            : 
     136                 :            :     // anchor type
     137         [ +  - ]:         20 :     aAny <<= eAnchorType;
     138 [ +  - ][ +  - ]:         20 :     xPropSet->setPropertyValue( sAnchorType, aAny );
     139                 :            : 
     140         [ +  - ]:         20 :     Reference < XTextContent > xTxtCntnt( rShape, UNO_QUERY );
     141 [ +  - ][ +  - ]:         20 :     xTxtImport->InsertTextContent( xTxtCntnt );
     142                 :            : 
     143                 :            :     // page number (must be set after the frame is inserted, because it
     144                 :            :     // will be overwritten then inserting the frame.
     145      [ +  -  + ]:         20 :     switch( eAnchorType )
     146                 :            :     {
     147                 :            :     case TextContentAnchorType_AT_PAGE:
     148                 :            :         // only set positive page numbers
     149         [ +  - ]:         14 :         if ( nPage > 0 )
     150                 :            :         {
     151         [ +  - ]:         14 :             aAny <<= nPage;
     152 [ +  - ][ +  - ]:         14 :             xPropSet->setPropertyValue( sAnchorPageNo, aAny );
     153                 :            :         }
     154                 :         14 :         break;
     155                 :            :     case TextContentAnchorType_AS_CHARACTER:
     156         [ #  # ]:          0 :         aAny <<= nY;
     157 [ #  # ][ #  # ]:          0 :         xPropSet->setPropertyValue( sVertOrientPosition, aAny );
     158                 :          0 :         break;
     159                 :            :     default:
     160                 :          6 :         break;
     161         [ +  - ]:         20 :     }
     162                 :            : }
     163                 :            : 
     164                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10