LCOV - code coverage report
Current view: top level - sw/source/filter/xml - xmlfmte.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 62 119 52.1 %
Date: 2012-08-25 Functions: 9 10 90.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 76 245 31.0 %

           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/XTextDocument.hpp>
      30                 :            : #include <xmloff/xmlnmspe.hxx>
      31                 :            : #include <xmloff/attrlist.hxx>
      32                 :            : #include "xmlexpit.hxx"
      33                 :            : #include <xmloff/nmspmap.hxx>
      34                 :            : #include <xmloff/XMLTextListAutoStylePool.hxx>
      35                 :            : #include <xmloff/XMLTextMasterPageExport.hxx>
      36                 :            : 
      37                 :            : #include <xmloff/txtprmap.hxx>
      38                 :            : #include <xmloff/xmlaustp.hxx>
      39                 :            : #include <xmloff/families.hxx>
      40                 :            : #include <format.hxx>
      41                 :            : #include <fmtpdsc.hxx>
      42                 :            : #include <pagedesc.hxx>
      43                 :            : #include <unostyle.hxx>
      44                 :            : #include <cellatr.hxx>
      45                 :            : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      46                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      47                 :            : #include "xmlexp.hxx"
      48                 :            : #include <SwStyleNameMapper.hxx>
      49                 :            : 
      50                 :            : 
      51                 :            : using ::rtl::OUString;
      52                 :            : using namespace ::com::sun::star::beans;
      53                 :            : using namespace ::com::sun::star::uno;
      54                 :            : using namespace ::com::sun::star::text;
      55                 :            : using namespace ::com::sun::star::drawing;
      56                 :            : using namespace ::com::sun::star::lang;
      57                 :            : using namespace ::xmloff::token;
      58                 :            : 
      59                 :            : using rtl::OUString;
      60                 :            : 
      61                 :          0 : void SwXMLExport::ExportFmt( const SwFmt& rFmt, enum XMLTokenEnum eFamily )
      62                 :            : {
      63                 :            :     // <style:style ...>
      64                 :          0 :     CheckAttrList();
      65                 :            : 
      66                 :            :     // style:family="..."
      67                 :            :     OSL_ENSURE( RES_FRMFMT==rFmt.Which(), "frame format expected" );
      68         [ #  # ]:          0 :     if( RES_FRMFMT != rFmt.Which() )
      69                 :          0 :         return;
      70                 :            :     OSL_ENSURE( eFamily != XML_TOKEN_INVALID, "family must be specified" );
      71                 :            :     // style:name="..."
      72                 :          0 :     sal_Bool bEncoded = sal_False;
      73                 :            :     AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, EncodeStyleName(
      74 [ #  # ][ #  # ]:          0 :                     rFmt.GetName(), &bEncoded ) );
                 [ #  # ]
      75         [ #  # ]:          0 :     if( bEncoded )
      76 [ #  # ][ #  # ]:          0 :         AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, rFmt.GetName() );
      77                 :            : 
      78                 :            : 
      79         [ #  # ]:          0 :     if( eFamily != XML_TOKEN_INVALID )
      80         [ #  # ]:          0 :         AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY, eFamily );
      81                 :            : 
      82                 :            : #if OSL_DEBUG_LEVEL > 0
      83                 :            :     // style:parent-style-name="..." (if its not the default only)
      84                 :            :     const SwFmt* pParent = rFmt.DerivedFrom();
      85                 :            :     // Parent-Namen nur uebernehmen, wenn kein Default
      86                 :            :     OSL_ENSURE( !pParent || pParent->IsDefault(), "unexpected parent" );
      87                 :            : 
      88                 :            :     OSL_ENSURE( USHRT_MAX == rFmt.GetPoolFmtId(), "pool ids arent'supported" );
      89                 :            :     OSL_ENSURE( USHRT_MAX == rFmt.GetPoolHelpId(), "help ids arent'supported" );
      90                 :            :     OSL_ENSURE( USHRT_MAX == rFmt.GetPoolHelpId() ||
      91                 :            :             UCHAR_MAX == rFmt.GetPoolHlpFileId(), "help file ids aren't supported" );
      92                 :            : #endif
      93                 :            : 
      94                 :            :     // style:master-page-name
      95 [ #  # ][ #  # ]:          0 :     if( RES_FRMFMT == rFmt.Which() && XML_TABLE == eFamily )
                 [ #  # ]
      96                 :            :     {
      97                 :            :         const SfxPoolItem *pItem;
      98         [ #  # ]:          0 :         if( SFX_ITEM_SET == rFmt.GetAttrSet().GetItemState( RES_PAGEDESC,
      99         [ #  # ]:          0 :                                                             sal_False, &pItem ) )
     100                 :            :         {
     101         [ #  # ]:          0 :             String sName;
     102                 :            :             const SwPageDesc *pPageDesc =
     103                 :          0 :                 ((const SwFmtPageDesc *)pItem)->GetPageDesc();
     104         [ #  # ]:          0 :             if( pPageDesc )
     105                 :            :                 SwStyleNameMapper::FillProgName(
     106                 :          0 :                                     pPageDesc->GetName(),
     107                 :            :                                     sName,
     108                 :            :                                     nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC,
     109         [ #  # ]:          0 :                                     sal_True);
     110                 :            :             AddAttribute( XML_NAMESPACE_STYLE, XML_MASTER_PAGE_NAME,
     111 [ #  # ][ #  # ]:          0 :                           EncodeStyleName( sName ) );
         [ #  # ][ #  # ]
     112                 :            :         }
     113                 :            :     }
     114                 :            : 
     115         [ #  # ]:          0 :     if( XML_TABLE_CELL == eFamily )
     116                 :            :     {
     117                 :            :         OSL_ENSURE(RES_FRMFMT == rFmt.Which(), "only frame format");
     118                 :            : 
     119                 :            :         const SfxPoolItem *pItem;
     120         [ #  # ]:          0 :         if( SFX_ITEM_SET ==
     121                 :          0 :             rFmt.GetAttrSet().GetItemState( RES_BOXATR_FORMAT,
     122         [ #  # ]:          0 :                                             sal_False, &pItem ) )
     123                 :            :         {
     124                 :            :             sal_Int32 nFormat = (sal_Int32)
     125                 :          0 :                 ((const SwTblBoxNumFormat *)pItem)->GetValue();
     126                 :            : 
     127 [ #  # ][ #  # ]:          0 :             if ( (nFormat != -1) && (nFormat != NUMBERFORMAT_TEXT) )
     128                 :            :             {
     129                 :            :                 // if we have a format, register and then export
     130                 :            :                 // (Careful: here we assume that data styles will be
     131                 :            :                 // written after cell styles)
     132         [ #  # ]:          0 :                 addDataStyle(nFormat);
     133         [ #  # ]:          0 :                 OUString sDataStyleName = getDataStyleName(nFormat);
     134         [ #  # ]:          0 :                 if( !sDataStyleName.isEmpty() )
     135                 :            :                     AddAttribute( XML_NAMESPACE_STYLE, XML_DATA_STYLE_NAME,
     136         [ #  # ]:          0 :                                   sDataStyleName );
     137                 :            :             }
     138                 :            :         }
     139                 :            :     }
     140                 :            : 
     141                 :            :     {
     142                 :            :         SvXMLElementExport aElem( *this, XML_NAMESPACE_STYLE, XML_STYLE,
     143         [ #  # ]:          0 :                                   sal_True, sal_True );
     144                 :            : 
     145                 :          0 :         SvXMLItemMapEntriesRef xItemMap;
     146                 :          0 :         XMLTokenEnum ePropToken = XML_TABLE_PROPERTIES;
     147         [ #  # ]:          0 :         if( XML_TABLE == eFamily )
     148                 :            :         {
     149         [ #  # ]:          0 :             xItemMap = xTableItemMap;
     150                 :            :         }
     151         [ #  # ]:          0 :         else if( XML_TABLE_ROW == eFamily )
     152                 :            :         {
     153         [ #  # ]:          0 :             xItemMap = xTableRowItemMap;
     154                 :          0 :             ePropToken = XML_TABLE_ROW_PROPERTIES;
     155                 :            :         }
     156         [ #  # ]:          0 :         else if( XML_TABLE_CELL == eFamily )
     157                 :            :         {
     158         [ #  # ]:          0 :             xItemMap = xTableCellItemMap;
     159                 :          0 :             ePropToken = XML_TABLE_CELL_PROPERTIES;
     160                 :            :         }
     161                 :            : 
     162         [ #  # ]:          0 :         if( xItemMap.Is() )
     163                 :            :         {
     164                 :          0 :             SvXMLExportItemMapper& rItemMapper = GetTableItemMapper();
     165 [ #  # ][ #  # ]:          0 :             rItemMapper.setMapEntries( xItemMap );
     166                 :            : 
     167                 :          0 :             GetTableItemMapper().exportXML( *this,
     168                 :          0 :                                            rFmt.GetAttrSet(),
     169                 :          0 :                                            GetTwipUnitConverter(),
     170                 :            :                                            ePropToken,
     171         [ #  # ]:          0 :                                            XML_EXPORT_FLAG_IGN_WS );
     172 [ #  # ][ #  # ]:          0 :         }
     173                 :            :     }
     174                 :            : }
     175                 :            : 
     176                 :            : 
     177                 :         21 : void SwXMLExport::_ExportStyles( sal_Bool bUsed )
     178                 :            : {
     179                 :         21 :     SvXMLExport::_ExportStyles( bUsed );
     180                 :            : 
     181                 :            :     // drawing defaults
     182 [ +  - ][ +  - ]:         21 :     GetShapeExport()->ExportGraphicDefaults();
     183                 :            : 
     184                 :            :     GetTextParagraphExport()->exportTextStyles( bUsed
     185                 :         21 :                                              ,IsShowProgress()
     186 [ +  - ][ +  - ]:         21 :                                               );
     187                 :            :     //page defaults
     188 [ +  - ][ +  - ]:         21 :     GetPageExport()->exportDefaultStyle();
     189                 :         21 : }
     190                 :            : 
     191                 :         42 : void SwXMLExport::_ExportAutoStyles()
     192                 :            : {
     193                 :            :     // The order in which styles are collected *MUST* be the same as
     194                 :            :     // the order in which they are exported. Otherwise, caching will
     195                 :            :     // fail.
     196                 :            : 
     197         [ +  - ]:         42 :     if( (getExportFlags() & (EXPORT_MASTERSTYLES|EXPORT_CONTENT)) != 0 )
     198                 :            :     {
     199                 :         42 :         if( (getExportFlags() & EXPORT_CONTENT) == 0 )
     200                 :            :         {
     201                 :            :             // only master pages are exported => styles for frames bound
     202                 :            :             // to frames (but none for frames bound to pages) need to be
     203                 :            :             // collected.
     204                 :            :             // TODO: exclude PageBoundFrames on export
     205                 :            :         }
     206                 :            :     }
     207                 :            : 
     208                 :            :     // exported in _ExportMasterStyles
     209         [ +  + ]:         42 :     if( (getExportFlags() & EXPORT_MASTERSTYLES) != 0 )
     210 [ +  - ][ +  - ]:         21 :         GetPageExport()->collectAutoStyles( sal_False );
     211                 :            : 
     212                 :            :     // if we don't export styles (i.e. in content stream only, but not
     213                 :            :     // in single-stream case), then we can save ourselves a bit of
     214                 :            :     // work and memory by not collecting field masters
     215         [ +  + ]:         42 :     if( (getExportFlags() & EXPORT_STYLES ) == 0 )
     216 [ +  - ][ +  - ]:         21 :         GetTextParagraphExport()->exportUsedDeclarations( sal_False );
     217                 :            : 
     218                 :            :     // exported in _ExportContent
     219         [ +  + ]:         42 :     if( (getExportFlags() & EXPORT_CONTENT) != 0 )
     220                 :            :     {
     221 [ +  - ][ +  - ]:         21 :         GetTextParagraphExport()->exportTrackedChanges( sal_True );
         [ +  - ][ +  - ]
     222         [ +  - ]:         21 :         Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
     223 [ +  - ][ +  - ]:         21 :         Reference < XText > xText = xTextDoc->getText();
     224                 :            : 
     225                 :            :         // collect form autostyle
     226                 :            :         // (do this before collectTextAutoStyles, 'cause the shapes need the results of the work
     227                 :            :         // done by examineForms)
     228         [ +  - ]:         21 :         Reference<XDrawPageSupplier> xDrawPageSupplier( GetModel(), UNO_QUERY );
     229 [ +  - ][ +  - ]:         21 :         if (xDrawPageSupplier.is() && GetFormExport().is())
         [ +  - ][ +  - ]
                 [ +  - ]
           [ +  -  #  # ]
     230                 :            :         {
     231 [ +  - ][ +  - ]:         21 :             Reference<XDrawPage> xPage = xDrawPageSupplier->getDrawPage();
     232         [ +  - ]:         21 :             if (xPage.is())
     233 [ +  - ][ +  - ]:         21 :                 GetFormExport()->examineForms(xPage);
         [ +  - ][ +  - ]
     234                 :            :         }
     235                 :            : 
     236 [ +  - ][ +  - ]:         21 :         GetTextParagraphExport()->collectTextAutoStylesOptimized( bShowProgress );
         [ +  - ][ +  - ]
     237                 :            :         //GetTextParagraphExport()->collectTextAutoStyles( xText, bShowProgress, sal_True, bPortions );
     238                 :            :     }
     239                 :            : 
     240 [ +  - ][ +  - ]:         42 :     GetTextParagraphExport()->exportTextAutoStyles();
     241 [ +  - ][ +  - ]:         42 :     GetShapeExport()->exportAutoStyles();
     242         [ +  + ]:         42 :     if( (getExportFlags() & EXPORT_MASTERSTYLES) != 0 )
     243 [ +  - ][ +  - ]:         21 :         GetPageExport()->exportAutoStyles();
     244                 :            : 
     245                 :            :     // we rely on data styles being written after cell styles in the
     246                 :            :     // ExportFmt() method; so be careful when changing order.
     247                 :         42 :     exportAutoDataStyles();
     248                 :            : 
     249                 :         42 :     sal_uInt16 nContentAutostyles = EXPORT_CONTENT | EXPORT_AUTOSTYLES;
     250         [ +  + ]:         42 :     if ( ( getExportFlags() & nContentAutostyles ) == nContentAutostyles )
     251 [ +  - ][ +  - ]:         21 :         GetFormExport()->exportAutoStyles();
     252                 :         42 : }
     253                 :            : 
     254                 :         21 : XMLPageExport* SwXMLExport::CreatePageExport()
     255                 :            : {
     256         [ +  - ]:         21 :     return new XMLTextMasterPageExport( *this );
     257                 :            : }
     258                 :            : 
     259                 :         21 : void SwXMLExport::_ExportMasterStyles()
     260                 :            : {
     261                 :            :     // export master styles
     262 [ +  - ][ +  - ]:         21 :     GetPageExport()->exportMasterStyles( sal_False );
     263                 :         21 : }
     264                 :            : 
     265                 :            : // ---------------------------------------------------------------------
     266                 :            : class SwXMLAutoStylePoolP : public SvXMLAutoStylePoolP
     267                 :            : {
     268                 :            :     SvXMLExport& rExport;
     269                 :            :     const OUString sListStyleName;
     270                 :            :     const OUString sMasterPageName;
     271                 :            :     const OUString sCDATA;
     272                 :            : 
     273                 :            : protected:
     274                 :            : 
     275                 :            :     virtual void exportStyleAttributes(
     276                 :            :             SvXMLAttributeList& rAttrList,
     277                 :            :             sal_Int32 nFamily,
     278                 :            :             const ::std::vector< XMLPropertyState >& rProperties,
     279                 :            :             const SvXMLExportPropertyMapper& rPropExp
     280                 :            :             , const SvXMLUnitConverter& rUnitConverter,
     281                 :            :             const SvXMLNamespaceMap& rNamespaceMap
     282                 :            :             ) const;
     283                 :            : public:
     284                 :            : 
     285                 :            :     SwXMLAutoStylePoolP( SvXMLExport& rExport );
     286                 :            :     virtual ~SwXMLAutoStylePoolP();
     287                 :            : };
     288                 :            : 
     289                 :         41 : void SwXMLAutoStylePoolP::exportStyleAttributes(
     290                 :            :             SvXMLAttributeList& rAttrList,
     291                 :            :             sal_Int32 nFamily,
     292                 :            :             const ::std::vector< XMLPropertyState >& rProperties,
     293                 :            :             const SvXMLExportPropertyMapper& rPropExp
     294                 :            :             , const SvXMLUnitConverter& rUnitConverter,
     295                 :            :             const SvXMLNamespaceMap& rNamespaceMap
     296                 :            :             ) const
     297                 :            : {
     298                 :         41 :     SvXMLAutoStylePoolP::exportStyleAttributes( rAttrList, nFamily, rProperties, rPropExp, rUnitConverter, rNamespaceMap);
     299                 :            : 
     300         [ +  + ]:         41 :     if( XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily )
     301                 :            :     {
     302 [ +  - ][ +  + ]:         34 :         for( ::std::vector< XMLPropertyState >::const_iterator
     303                 :          7 :                     aProperty = rProperties.begin();
     304                 :         17 :              aProperty != rProperties.end();
     305                 :            :               ++aProperty )
     306                 :            :         {
     307         [ +  - ]:         10 :             if (aProperty->mnIndex != -1) // #i26762#
     308                 :            :             {
     309      [ -  +  + ]:         20 :                 switch( rPropExp.getPropertySetMapper()->
     310 [ +  - ][ +  - ]:         20 :                         GetEntryContextId( aProperty->mnIndex ) )
     311                 :            :                 {
     312                 :            :                 case CTF_NUMBERINGSTYLENAME:
     313                 :            :                     {
     314                 :          0 :                         OUString sStyleName;
     315                 :          0 :                         aProperty->maValue >>= sStyleName;
     316                 :            :                         // #i70748# - export also empty list styles
     317         [ #  # ]:          0 :                         if( !sStyleName.isEmpty() )
     318                 :            :                         {
     319 [ #  # ][ #  # ]:          0 :                             OUString sTmp = rExport.GetTextParagraphExport()->GetListAutoStylePool().Find( sStyleName );
         [ #  # ][ #  # ]
     320         [ #  # ]:          0 :                             if( !sTmp.isEmpty() )
     321                 :          0 :                                 sStyleName = sTmp;
     322                 :            :                         }
     323         [ #  # ]:          0 :                         GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     324                 :            :                               sListStyleName,
     325 [ #  # ][ #  # ]:          0 :                               GetExport().EncodeStyleName( sStyleName ) );
                 [ #  # ]
     326                 :            :                     }
     327                 :          0 :                     break;
     328                 :            :                 case CTF_PAGEDESCNAME:
     329                 :            :                     {
     330                 :          3 :                         OUString sStyleName;
     331                 :          3 :                         aProperty->maValue >>= sStyleName;
     332         [ +  - ]:          3 :                         GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     333                 :            :                                       sMasterPageName,
     334 [ +  - ][ +  - ]:          6 :                                       GetExport().EncodeStyleName( sStyleName ) );
                 [ +  - ]
     335                 :            :                     }
     336                 :         10 :                     break;
     337                 :            :                 }
     338                 :            :             }
     339                 :            :         }
     340                 :            :     }
     341                 :         41 : }
     342                 :            : 
     343                 :         42 : SwXMLAutoStylePoolP::SwXMLAutoStylePoolP(SvXMLExport& rExp ) :
     344                 :            :     SvXMLAutoStylePoolP( rExp ),
     345                 :            :     rExport( rExp ),
     346         [ +  - ]:         42 :     sListStyleName( GetXMLToken( XML_LIST_STYLE_NAME ) ),
     347         [ +  - ]:         42 :     sMasterPageName( GetXMLToken( XML_MASTER_PAGE_NAME ) ),
     348         [ +  - ]:        126 :     sCDATA( GetXMLToken( XML_CDATA ) )
     349                 :            : {
     350                 :         42 : }
     351                 :            : 
     352                 :            : 
     353                 :         42 : SwXMLAutoStylePoolP::~SwXMLAutoStylePoolP()
     354                 :            : {
     355         [ -  + ]:         84 : }
     356                 :            : 
     357                 :         42 : SvXMLAutoStylePoolP* SwXMLExport::CreateAutoStylePool()
     358                 :            : {
     359         [ +  - ]:         42 :     return new SwXMLAutoStylePoolP( *this );
     360                 :            : }
     361                 :            : 
     362                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10