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 20 : void SwXMLExport::ExportFmt( const SwFmt& rFmt, enum XMLTokenEnum eFamily )
50 : {
51 : // <style:style ...>
52 20 : CheckAttrList();
53 :
54 : // style:family="..."
55 : OSL_ENSURE( RES_FRMFMT==rFmt.Which(), "frame format expected" );
56 20 : if( RES_FRMFMT != rFmt.Which() )
57 20 : return;
58 : OSL_ENSURE( eFamily != XML_TOKEN_INVALID, "family must be specified" );
59 : // style:name="..."
60 20 : bool bEncoded = false;
61 : AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, EncodeStyleName(
62 20 : rFmt.GetName(), &bEncoded ) );
63 20 : if( bEncoded )
64 0 : AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, rFmt.GetName() );
65 :
66 20 : if( eFamily != XML_TOKEN_INVALID )
67 20 : 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 SwFmt* pParent = rFmt.DerivedFrom();
72 : // Parent-Namen nur uebernehmen, wenn kein Default
73 : OSL_ENSURE( !pParent || pParent->IsDefault(), "unexpected parent" );
74 :
75 : OSL_ENSURE( USHRT_MAX == rFmt.GetPoolFmtId(), "pool ids arent'supported" );
76 : OSL_ENSURE( USHRT_MAX == rFmt.GetPoolHelpId(), "help ids arent'supported" );
77 : OSL_ENSURE( USHRT_MAX == rFmt.GetPoolHelpId() ||
78 : UCHAR_MAX == rFmt.GetPoolHlpFileId(), "help file ids aren't supported" );
79 : #endif
80 :
81 : // style:master-page-name
82 20 : if( RES_FRMFMT == rFmt.Which() && XML_TABLE == eFamily )
83 : {
84 : const SfxPoolItem *pItem;
85 8 : if( SfxItemState::SET == rFmt.GetAttrSet().GetItemState( RES_PAGEDESC,
86 4 : false, &pItem ) )
87 : {
88 0 : OUString sName;
89 : const SwPageDesc *pPageDesc =
90 0 : ((const SwFmtPageDesc *)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 20 : if( XML_TABLE_CELL == eFamily )
103 : {
104 : OSL_ENSURE(RES_FRMFMT == rFmt.Which(), "only frame format");
105 :
106 : const SfxPoolItem *pItem;
107 16 : if( SfxItemState::SET ==
108 16 : rFmt.GetAttrSet().GetItemState( RES_BOXATR_FORMAT,
109 16 : false, &pItem ) )
110 : {
111 : sal_Int32 nFormat = (sal_Int32)
112 0 : ((const SwTblBoxNumFormat *)pItem)->GetValue();
113 :
114 0 : if ( (nFormat != -1) && (nFormat != 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 20 : true, true );
131 :
132 40 : SvXMLItemMapEntriesRef xItemMap;
133 20 : XMLTokenEnum ePropToken = XML_TABLE_PROPERTIES;
134 20 : if( XML_TABLE == eFamily )
135 : {
136 4 : xItemMap = xTableItemMap;
137 : }
138 16 : else if( XML_TABLE_ROW == eFamily )
139 : {
140 0 : xItemMap = xTableRowItemMap;
141 0 : ePropToken = XML_TABLE_ROW_PROPERTIES;
142 : }
143 16 : else if( XML_TABLE_CELL == eFamily )
144 : {
145 16 : xItemMap = xTableCellItemMap;
146 16 : ePropToken = XML_TABLE_CELL_PROPERTIES;
147 : }
148 :
149 20 : if( xItemMap.Is() )
150 : {
151 20 : SvXMLExportItemMapper& rItemMapper = GetTableItemMapper();
152 20 : rItemMapper.setMapEntries( xItemMap );
153 :
154 20 : GetTableItemMapper().exportXML( *this,
155 20 : rFmt.GetAttrSet(),
156 20 : GetTwipUnitConverter(),
157 : ePropToken,
158 40 : XML_EXPORT_FLAG_IGN_WS );
159 20 : }
160 : }
161 : }
162 :
163 60 : void SwXMLExport::_ExportStyles( bool bUsed )
164 : {
165 60 : SvXMLExport::_ExportStyles( bUsed );
166 :
167 : // drawing defaults
168 60 : GetShapeExport()->ExportGraphicDefaults();
169 :
170 : GetTextParagraphExport()->exportTextStyles( bUsed
171 60 : ,IsShowProgress()
172 60 : );
173 : //page defaults
174 60 : GetPageExport()->exportDefaultStyle();
175 60 : }
176 :
177 120 : 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 120 : if( (getExportFlags() & (EXPORT_MASTERSTYLES|EXPORT_CONTENT)) != 0 )
184 : {
185 120 : if( (getExportFlags() & EXPORT_CONTENT) == 0 )
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 120 : if( (getExportFlags() & EXPORT_MASTERSTYLES) != 0 )
196 60 : 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 120 : if( (getExportFlags() & EXPORT_STYLES ) == 0 )
202 60 : GetTextParagraphExport()->exportUsedDeclarations( false );
203 :
204 : // exported in _ExportContent
205 120 : if( (getExportFlags() & EXPORT_CONTENT) != 0 )
206 : {
207 60 : GetTextParagraphExport()->exportTrackedChanges( true );
208 60 : Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
209 120 : 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 120 : Reference<XDrawPageSupplier> xDrawPageSupplier( GetModel(), UNO_QUERY );
215 60 : if (xDrawPageSupplier.is() && GetFormExport().is())
216 : {
217 60 : Reference<XDrawPage> xPage = xDrawPageSupplier->getDrawPage();
218 60 : if (xPage.is())
219 60 : GetFormExport()->examineForms(xPage);
220 : }
221 :
222 120 : GetTextParagraphExport()->collectTextAutoStylesOptimized( bShowProgress );
223 : //GetTextParagraphExport()->collectTextAutoStyles( xText, bShowProgress, sal_True, bPortions );
224 : }
225 :
226 120 : GetTextParagraphExport()->exportTextAutoStyles();
227 120 : GetShapeExport()->exportAutoStyles();
228 120 : if( (getExportFlags() & EXPORT_MASTERSTYLES) != 0 )
229 60 : GetPageExport()->exportAutoStyles();
230 :
231 : // we rely on data styles being written after cell styles in the
232 : // ExportFmt() method; so be careful when changing order.
233 120 : exportAutoDataStyles();
234 :
235 120 : sal_uInt16 nContentAutostyles = EXPORT_CONTENT | EXPORT_AUTOSTYLES;
236 120 : if ( ( getExportFlags() & nContentAutostyles ) == nContentAutostyles )
237 60 : GetFormExport()->exportAutoStyles();
238 120 : }
239 :
240 60 : XMLPageExport* SwXMLExport::CreatePageExport()
241 : {
242 60 : return new XMLTextMasterPageExport( *this );
243 : }
244 :
245 60 : void SwXMLExport::_ExportMasterStyles()
246 : {
247 : // export master styles
248 60 : GetPageExport()->exportMasterStyles( false );
249 60 : }
250 :
251 : class SwXMLAutoStylePoolP : public SvXMLAutoStylePoolP
252 : {
253 : SvXMLExport& rExport;
254 : const OUString sListStyleName;
255 : const OUString sMasterPageName;
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 202 : 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 202 : SvXMLAutoStylePoolP::exportStyleAttributes( rAttrList, nFamily, rProperties, rPropExp, rUnitConverter, rNamespaceMap);
283 :
284 202 : if( XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily )
285 : {
286 924 : for( ::std::vector< XMLPropertyState >::const_iterator
287 60 : aProperty = rProperties.begin();
288 616 : aProperty != rProperties.end();
289 : ++aProperty )
290 : {
291 248 : if (aProperty->mnIndex != -1) // #i26762#
292 : {
293 356 : switch( rPropExp.getPropertySetMapper()->
294 356 : 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 24 : OUString sStyleName;
315 24 : aProperty->maValue >>= sStyleName;
316 24 : GetExport().AddAttribute( XML_NAMESPACE_STYLE,
317 : sMasterPageName,
318 48 : GetExport().EncodeStyleName( sStyleName ) );
319 : }
320 24 : break;
321 : }
322 : }
323 : }
324 : }
325 202 : }
326 :
327 120 : SwXMLAutoStylePoolP::SwXMLAutoStylePoolP(SvXMLExport& rExp ) :
328 : SvXMLAutoStylePoolP( rExp ),
329 : rExport( rExp ),
330 120 : sListStyleName( GetXMLToken( XML_LIST_STYLE_NAME ) ),
331 240 : sMasterPageName( GetXMLToken( XML_MASTER_PAGE_NAME ) )
332 : {
333 120 : }
334 :
335 240 : SwXMLAutoStylePoolP::~SwXMLAutoStylePoolP()
336 : {
337 240 : }
338 :
339 120 : SvXMLAutoStylePoolP* SwXMLExport::CreateAutoStylePool()
340 : {
341 120 : return new SwXMLAutoStylePoolP( *this );
342 270 : }
343 :
344 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|