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

Generated by: LCOV version 1.11