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