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

Generated by: LCOV version 1.10