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 4 : void SwXMLExport::_ExportStyles( sal_Bool bUsed )
169 : {
170 4 : SvXMLExport::_ExportStyles( bUsed );
171 :
172 : // drawing defaults
173 4 : GetShapeExport()->ExportGraphicDefaults();
174 :
175 : GetTextParagraphExport()->exportTextStyles( bUsed
176 4 : ,IsShowProgress()
177 4 : );
178 : //page defaults
179 4 : GetPageExport()->exportDefaultStyle();
180 4 : }
181 :
182 8 : 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 8 : if( (getExportFlags() & (EXPORT_MASTERSTYLES|EXPORT_CONTENT)) != 0 )
189 : {
190 8 : 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 8 : if( (getExportFlags() & EXPORT_MASTERSTYLES) != 0 )
201 4 : 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 8 : if( (getExportFlags() & EXPORT_STYLES ) == 0 )
207 4 : GetTextParagraphExport()->exportUsedDeclarations( sal_False );
208 :
209 : // exported in _ExportContent
210 8 : if( (getExportFlags() & EXPORT_CONTENT) != 0 )
211 : {
212 4 : GetTextParagraphExport()->exportTrackedChanges( sal_True );
213 4 : Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
214 4 : 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 4 : Reference<XDrawPageSupplier> xDrawPageSupplier( GetModel(), UNO_QUERY );
220 4 : if (xDrawPageSupplier.is() && GetFormExport().is())
221 : {
222 4 : Reference<XDrawPage> xPage = xDrawPageSupplier->getDrawPage();
223 4 : if (xPage.is())
224 4 : GetFormExport()->examineForms(xPage);
225 : }
226 :
227 4 : GetTextParagraphExport()->collectTextAutoStylesOptimized( bShowProgress );
228 : //GetTextParagraphExport()->collectTextAutoStyles( xText, bShowProgress, sal_True, bPortions );
229 : }
230 :
231 8 : GetTextParagraphExport()->exportTextAutoStyles();
232 8 : GetShapeExport()->exportAutoStyles();
233 8 : if( (getExportFlags() & EXPORT_MASTERSTYLES) != 0 )
234 4 : 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 8 : exportAutoDataStyles();
239 :
240 8 : sal_uInt16 nContentAutostyles = EXPORT_CONTENT | EXPORT_AUTOSTYLES;
241 8 : if ( ( getExportFlags() & nContentAutostyles ) == nContentAutostyles )
242 4 : GetFormExport()->exportAutoStyles();
243 8 : }
244 :
245 4 : XMLPageExport* SwXMLExport::CreatePageExport()
246 : {
247 4 : return new XMLTextMasterPageExport( *this );
248 : }
249 :
250 4 : void SwXMLExport::_ExportMasterStyles()
251 : {
252 : // export master styles
253 4 : GetPageExport()->exportMasterStyles( sal_False );
254 4 : }
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 14 : 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 14 : SvXMLAutoStylePoolP::exportStyleAttributes( rAttrList, nFamily, rProperties, rPropExp, rUnitConverter, rNamespaceMap);
290 :
291 14 : if( XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily )
292 : {
293 54 : for( ::std::vector< XMLPropertyState >::const_iterator
294 6 : aProperty = rProperties.begin();
295 36 : aProperty != rProperties.end();
296 : ++aProperty )
297 : {
298 12 : if (aProperty->mnIndex != -1) // #i26762#
299 : {
300 24 : switch( rPropExp.getPropertySetMapper()->
301 24 : 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 4 : OUString sStyleName;
322 4 : aProperty->maValue >>= sStyleName;
323 4 : GetExport().AddAttribute( XML_NAMESPACE_STYLE,
324 : sMasterPageName,
325 8 : GetExport().EncodeStyleName( sStyleName ) );
326 : }
327 4 : break;
328 : }
329 : }
330 : }
331 : }
332 14 : }
333 :
334 8 : SwXMLAutoStylePoolP::SwXMLAutoStylePoolP(SvXMLExport& rExp ) :
335 : SvXMLAutoStylePoolP( rExp ),
336 : rExport( rExp ),
337 8 : sListStyleName( GetXMLToken( XML_LIST_STYLE_NAME ) ),
338 8 : sMasterPageName( GetXMLToken( XML_MASTER_PAGE_NAME ) ),
339 24 : sCDATA( GetXMLToken( XML_CDATA ) )
340 : {
341 8 : }
342 :
343 :
344 16 : SwXMLAutoStylePoolP::~SwXMLAutoStylePoolP()
345 : {
346 16 : }
347 :
348 8 : SvXMLAutoStylePoolP* SwXMLExport::CreateAutoStylePool()
349 : {
350 8 : return new SwXMLAutoStylePoolP( *this );
351 : }
352 :
353 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|