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

Generated by: LCOV version 1.10