LibreOffice Module sw (master)  1
xmlfmte.cxx
Go to the documentation of this file.
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>
28 
29 #include <xmloff/txtprmap.hxx>
30 #include <xmloff/xmlaustp.hxx>
31 #include <xmloff/families.hxx>
32 #include <xmloff/maptype.hxx>
33 #include <format.hxx>
34 #include <fmtpdsc.hxx>
35 #include <pagedesc.hxx>
36 #include <cellatr.hxx>
37 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
38 #include "xmlexp.hxx"
39 #include <SwStyleNameMapper.hxx>
40 #include <osl/diagnose.h>
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 void SwXMLExport::ExportFormat( const SwFormat& rFormat, enum XMLTokenEnum eFamily )
50 {
51  // <style:style ...>
52  CheckAttrList();
53 
54  // style:family="..."
55  OSL_ENSURE( RES_FRMFMT==rFormat.Which(), "frame format expected" );
56  if( RES_FRMFMT != rFormat.Which() )
57  return;
58  OSL_ENSURE( eFamily != XML_TOKEN_INVALID, "family must be specified" );
59  // style:name="..."
60  bool bEncoded = false;
61  AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, EncodeStyleName(
62  rFormat.GetName(), &bEncoded ) );
63  if( bEncoded )
64  AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, rFormat.GetName() );
65 
66  if( eFamily != XML_TOKEN_INVALID )
67  AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY, eFamily );
68 
69 #if OSL_DEBUG_LEVEL > 0
70  // style:parent-style-name="..." (if it's not the default only)
71  const SwFormat* pParent = rFormat.DerivedFrom();
72  // Only adopt parent name, if it's not the default
73  OSL_ENSURE( !pParent || pParent->IsDefault(), "unexpected parent" );
74 
75  OSL_ENSURE( USHRT_MAX == rFormat.GetPoolFormatId(), "pool ids aren't supported" );
76  OSL_ENSURE( USHRT_MAX == rFormat.GetPoolHelpId(), "help ids aren't 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  if( RES_FRMFMT == rFormat.Which() && XML_TABLE == eFamily )
83  {
84  const SfxPoolItem *pItem;
85  if( SfxItemState::SET == rFormat.GetAttrSet().GetItemState( RES_PAGEDESC,
86  false, &pItem ) )
87  {
88  OUString sName;
89  const SwPageDesc *pPageDesc =
90  static_cast<const SwFormatPageDesc *>(pItem)->GetPageDesc();
91  if( pPageDesc )
93  pPageDesc->GetName(),
94  sName,
96  AddAttribute( XML_NAMESPACE_STYLE, XML_MASTER_PAGE_NAME,
97  EncodeStyleName( sName ) );
98  }
99  }
100 
101  if( XML_TABLE_CELL == eFamily )
102  {
103  OSL_ENSURE(RES_FRMFMT == rFormat.Which(), "only frame format");
104 
105  const SfxPoolItem *pItem;
106  if( SfxItemState::SET ==
108  false, &pItem ) )
109  {
110  sal_Int32 nFormat = static_cast<sal_Int32>(static_cast<const SwTableBoxNumFormat *>(pItem)->GetValue());
111 
112  if ( (nFormat != -1) && (nFormat != static_cast<sal_Int32>(getSwDefaultTextFormat())) )
113  {
114  // if we have a format, register and then export
115  // (Careful: here we assume that data styles will be
116  // written after cell styles)
117  addDataStyle(nFormat);
118  OUString sDataStyleName = getDataStyleName(nFormat);
119  if( !sDataStyleName.isEmpty() )
120  AddAttribute( XML_NAMESPACE_STYLE, XML_DATA_STYLE_NAME,
121  sDataStyleName );
122  }
123  }
124  }
125 
126  {
127  SvXMLElementExport aElem( *this, XML_NAMESPACE_STYLE, XML_STYLE,
128  true, true );
129 
130  SvXMLItemMapEntriesRef xItemMap;
131  XMLTokenEnum ePropToken = XML_TABLE_PROPERTIES;
132  if( XML_TABLE == eFamily )
133  {
134  xItemMap = m_xTableItemMap;
135  }
136  else if( XML_TABLE_ROW == eFamily )
137  {
138  xItemMap = m_xTableRowItemMap;
139  ePropToken = XML_TABLE_ROW_PROPERTIES;
140  }
141  else if( XML_TABLE_CELL == eFamily )
142  {
143  xItemMap = m_xTableCellItemMap;
144  ePropToken = XML_TABLE_CELL_PROPERTIES;
145  }
146 
147  if( xItemMap.is() )
148  {
149  m_pTableItemMapper->setMapEntries( xItemMap );
150  m_pTableItemMapper->exportXML( *this,
151  rFormat.GetAttrSet(),
153  ePropToken );
154  }
155  }
156 }
157 
158 void SwXMLExport::ExportStyles_( bool bUsed )
159 {
161 
162  // drawing defaults
163  GetShapeExport()->ExportGraphicDefaults();
164 
165  GetTextParagraphExport()->exportTextStyles( bUsed
166  ,IsShowProgress()
167  );
168  GetShapeExport()->GetShapeTableExport()->exportTableStyles();
169  //page defaults
170  GetPageExport()->exportDefaultStyle();
171 }
172 
174 {
176 
178  return;
179 
180  // The order in which styles are collected *MUST* be the same as
181  // the order in which they are exported. Otherwise, caching will
182  // fail.
183  if( getExportFlags() & (SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) )
184  {
185  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  if( getExportFlags() & SvXMLExportFlags::MASTERSTYLES )
196  GetPageExport()->collectAutoStyles( false );
197 
198 
199  // exported in ExportContent_
200  if( getExportFlags() & SvXMLExportFlags::CONTENT )
201  {
202  // collect form autostyle
203  // (do this before collectTextAutoStyles, 'cause the shapes need the results of the work
204  // done by examineForms)
205  Reference<XDrawPageSupplier> xDrawPageSupplier( GetModel(), UNO_QUERY );
206  if (xDrawPageSupplier.is() && GetFormExport().is())
207  {
208  Reference<XDrawPage> xPage = xDrawPageSupplier->getDrawPage();
209  if (xPage.is())
210  GetFormExport()->examineForms(xPage);
211  }
212 
213  GetTextParagraphExport()->collectTextAutoStylesOptimized( m_bShowProgress );
214  }
215 
216  mbAutoStylesCollected = true;
217 }
218 
220 {
222 
223  // if we don't export styles (i.e. in content stream only, but not
224  // in single-stream case), then we can save ourselves a bit of
225  // work and memory by not collecting field masters
226  if( !(getExportFlags() & SvXMLExportFlags::STYLES) )
227  GetTextParagraphExport()->exportUsedDeclarations();
228 
229  // exported in ExportContent_
230  if( getExportFlags() & SvXMLExportFlags::CONTENT )
231  {
232  GetTextParagraphExport()->exportTrackedChanges( true );
233  }
234 
235  GetTextParagraphExport()->exportTextAutoStyles();
236  GetShapeExport()->exportAutoStyles();
237  if( getExportFlags() & SvXMLExportFlags::MASTERSTYLES )
238  GetPageExport()->exportAutoStyles();
239 
240  // we rely on data styles being written after cell styles in the
241  // ExportFormat() method; so be careful when changing order.
243 
244  SvXMLExportFlags nContentAutostyles = SvXMLExportFlags::CONTENT | SvXMLExportFlags::AUTOSTYLES;
245  if ( ( getExportFlags() & nContentAutostyles ) == nContentAutostyles )
246  GetFormExport()->exportAutoStyles();
247 }
248 
250 {
251  return new XMLTextMasterPageExport( *this );
252 }
253 
255 {
256  // export master styles
257  GetPageExport()->exportMasterStyles( false );
258 }
259 
261 {
263  const OUString sListStyleName;
264  const OUString sMasterPageName;
265 
266 protected:
267 
268  virtual void exportStyleAttributes(
269  SvXMLAttributeList& rAttrList,
270  sal_Int32 nFamily,
271  const std::vector< XMLPropertyState >& rProperties,
272  const SvXMLExportPropertyMapper& rPropExp
273  , const SvXMLUnitConverter& rUnitConverter,
274  const SvXMLNamespaceMap& rNamespaceMap
275  ) const override;
276 public:
277 
278  explicit SwXMLAutoStylePoolP( SvXMLExport& rExport );
279 };
280 
282  SvXMLAttributeList& rAttrList,
283  sal_Int32 nFamily,
284  const std::vector< XMLPropertyState >& rProperties,
285  const SvXMLExportPropertyMapper& rPropExp
286  , const SvXMLUnitConverter& rUnitConverter,
287  const SvXMLNamespaceMap& rNamespaceMap
288  ) const
289 {
290  SvXMLAutoStylePoolP::exportStyleAttributes( rAttrList, nFamily, rProperties, rPropExp, rUnitConverter, rNamespaceMap);
291 
292  if( XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily )
293  {
294  for( const auto& rProperty : rProperties )
295  {
296  if (rProperty.mnIndex != -1) // #i26762#
297  {
298  switch( rPropExp.getPropertySetMapper()->
299  GetEntryContextId( rProperty.mnIndex ) )
300  {
302  {
303  OUString sStyleName;
304  rProperty.maValue >>= sStyleName;
305  // #i70748# - export also empty list styles
306  if( !sStyleName.isEmpty() )
307  {
308  OUString sTmp = rExport.GetTextParagraphExport()->GetListAutoStylePool().Find( sStyleName );
309  if( !sTmp.isEmpty() )
310  sStyleName = sTmp;
311  }
312  GetExport().AddAttribute( XML_NAMESPACE_STYLE,
314  GetExport().EncodeStyleName( sStyleName ) );
315  }
316  break;
317  case CTF_PAGEDESCNAME:
318  {
319  OUString sStyleName;
320  rProperty.maValue >>= sStyleName;
321  GetExport().AddAttribute( XML_NAMESPACE_STYLE,
323  GetExport().EncodeStyleName( sStyleName ) );
324  }
325  break;
326  }
327  }
328  }
329  }
330 }
331 
333  SvXMLAutoStylePoolP( rExp ),
334  rExport( rExp ),
335  sListStyleName( GetXMLToken( XML_LIST_STYLE_NAME ) ),
336  sMasterPageName( GetXMLToken( XML_MASTER_PAGE_NAME ) )
337 {
338 }
339 
341 {
342  return new SwXMLAutoStylePoolP( *this );
343 }
344 
345 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool is() const
virtual void exportStyleAttributes(SvXMLAttributeList &rAttrList, sal_Int32 nFamily, const std::vector< XMLPropertyState > &rProperties, const SvXMLExportPropertyMapper &rPropExp, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap) const override
Definition: xmlfmte.cxx:281
const OUString sListStyleName
Definition: xmlfmte.cxx:263
XML_DISPLAY_NAME
#define RES_FRMFMT
Definition: hintids.hxx:275
rtl::Reference< XMLShapeExport > const & GetShapeExport()
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
Definition: fmtpdsc.hxx:35
bool IsDefault() const
Definition: format.hxx:109
XML_LIST_STYLE_NAME
SvXMLExport & GetExport() const
std::string GetValue
XML_TABLE_PROPERTIES
virtual void exportAutoDataStyles()
XML_NAME
SvXMLItemMapEntriesRef m_xTableRowItemMap
Definition: xmlexp.hxx:55
rtl::Reference< XMLTextParagraphExport > const & GetTextParagraphExport()
#define XML_STYLE_FAMILY_TEXT_PARAGRAPH
void CheckAttrList()
SvXMLExportFlags
#define CTF_NUMBERINGSTYLENAME
XML_MASTER_PAGE_NAME
SvXMLItemMapEntriesRef m_xTableItemMap
Definition: xmlexp.hxx:54
SvXMLItemMapEntriesRef m_xTableCellItemMap
Definition: xmlexp.hxx:56
virtual void ExportMasterStyles_() override
Definition: xmlfmte.cxx:254
const OUString & GetName() const
Definition: pagedesc.hxx:187
virtual void ExportStyles_(bool bUsed)
void AddAttribute(sal_uInt16 nPrefix, const sal_Char *pName, const OUString &rValue)
const OUString sMasterPageName
Definition: xmlfmte.cxx:264
const css::uno::Reference< css::frame::XModel > & GetModel() const
virtual void exportStyleAttributes(SvXMLAttributeList &rAttrList, sal_Int32 nFamily, const ::std::vector< XMLPropertyState > &rProperties, const SvXMLExportPropertyMapper &rPropExp, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap) const
SwXMLAutoStylePoolP(SvXMLExport &rExport)
Definition: xmlfmte.cxx:332
XML_TABLE_CELL_PROPERTIES
XML_STYLE
XML_TABLE_CELL
XML_TABLE
const OUString & GetName() const
Definition: format.hxx:111
virtual OUString getDataStyleName(const sal_Int32 nNumberFormat, bool bTimeFormat=false) const
bool m_bShowProgress
Definition: xmlexp.hxx:59
XMLTokenEnum
sal_uInt16 GetPoolFormatId() const
Get and set Pool style IDs.
Definition: format.hxx:143
XML_DATA_STYLE_NAME
Base class for various Writer styles.
Definition: format.hxx:43
bool mbAutoStylesCollected
void ExportFormat(const SwFormat &rFormat, enum::xmloff::token::XMLTokenEnum eClass)
Definition: xmlfmte.cxx:49
bool IsShowProgress() const
Definition: xmlexp.hxx:126
XML_TABLE_ROW
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
OUString sName
virtual void ExportStyles_(bool bUsed) override
Definition: xmlfmte.cxx:158
sal_uInt8 GetPoolHlpFileId() const
Definition: format.hxx:149
const SvXMLUnitConverter & GetTwipUnitConverter() const
Definition: xmlexp.hxx:137
XML_TOKEN_INVALID
virtual SvXMLAutoStylePoolP * CreateAutoStylePool() override
Definition: xmlfmte.cxx:340
XML_TABLE_ROW_PROPERTIES
SvXMLExport & rExport
Definition: xmlfmte.cxx:262
OUString EncodeStyleName(const OUString &rName, bool *pEncoded=nullptr) const
sal_uInt16 Which() const
for Querying of Writer-functions.
Definition: format.hxx:78
SwFormat * DerivedFrom() const
Definition: format.hxx:108
sal_uInt16 GetPoolHelpId() const
Get and set Help-IDs for document templates.
Definition: format.hxx:147
#define CTF_PAGEDESCNAME
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
void collectAutoStyles() override
Definition: xmlfmte.cxx:173
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
virtual void ExportAutoStyles_() override
Definition: xmlfmte.cxx:219
static void FillProgName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
rtl::Reference< XMLPageExport > const & GetPageExport()
rtl::Reference< xmloff::OFormLayerXMLExport > const & GetFormExport()
XML_FAMILY
virtual XMLPageExport * CreatePageExport() override
Definition: xmlfmte.cxx:249
const SwAttrSet & GetAttrSet() const
For querying the attribute array.
Definition: format.hxx:116
#define RES_PAGEDESC
Definition: hintids.hxx:200
virtual void addDataStyle(const sal_Int32 nNumberFormat, bool bTimeFormat=false)
SvXMLExportFlags getExportFlags() const
constexpr sal_uInt32 getSwDefaultTextFormat()
The number formatter's default locale's @ Text format.
Definition: cellatr.hxx:34
#define RES_BOXATR_FORMAT
Definition: hintids.hxx:263
const rtl::Reference< XMLPropertySetMapper > & getPropertySetMapper() const
std::unique_ptr< SvXMLExportItemMapper > m_pTableItemMapper
Definition: xmlexp.hxx:51
virtual void collectAutoStyles()