xref: /aoo4110/main/xmloff/source/text/txtparae.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_xmloff.hxx"
24 #include "unointerfacetouniqueidentifiermapper.hxx"
25 #include <tools/debug.hxx>
26 #ifndef _SVSTDARR_LONGS_DECL
27 #define _SVSTDARR_LONGS
28 #include <svl/svstdarr.hxx>
29 #endif
30 #include <svl/svarray.hxx>
31 #include <rtl/ustrbuf.hxx>
32 #include <sal/types.h>
33 #include <vector>
34 #include <list>
35 #include <hash_map>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/container/XEnumerationAccess.hpp>
38 #include <com/sun/star/container/XEnumeration.hpp>
39 #include <com/sun/star/container/XIndexReplace.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/beans/XMultiPropertySet.hpp>
42 #include <com/sun/star/beans/XPropertyState.hpp>
43 #include <com/sun/star/text/XTextDocument.hpp>
44 #include <com/sun/star/text/XTextSectionsSupplier.hpp>
45 #include <com/sun/star/text/XTextTablesSupplier.hpp>
46 #include <com/sun/star/text/XNumberingRulesSupplier.hpp>
47 #include <com/sun/star/text/XChapterNumberingSupplier.hpp>//#outline level,add by zhaojianwei
48 #include <com/sun/star/text/XTextTable.hpp>
49 #include <com/sun/star/text/XText.hpp>
50 #include <com/sun/star/text/XTextContent.hpp>
51 #include <com/sun/star/text/XTextRange.hpp>
52 #include <com/sun/star/text/XTextField.hpp>
53 #include <com/sun/star/text/XFootnote.hpp>
54 #include <com/sun/star/container/XNamed.hpp>
55 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
56 #include <com/sun/star/text/XTextFrame.hpp>
57 #include <com/sun/star/container/XNameAccess.hpp>
58 #include <com/sun/star/text/SizeType.hpp>
59 #include <com/sun/star/text/HoriOrientation.hpp>
60 #include <com/sun/star/text/VertOrientation.hpp>
61 #include <com/sun/star/text/TextContentAnchorType.hpp>
62 #include <com/sun/star/text/XTextFramesSupplier.hpp>
63 #include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
64 #include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
65 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
66 #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
67 #include <com/sun/star/document/XEventsSupplier.hpp>
68 #include <com/sun/star/document/XRedlinesSupplier.hpp>
69 #include <com/sun/star/text/XBookmarksSupplier.hpp>
70 #include <com/sun/star/text/XFormField.hpp>
71 #include <com/sun/star/text/XTextSection.hpp>
72 #include <com/sun/star/text/SectionFileLink.hpp>
73 #include <com/sun/star/drawing/XShape.hpp>
74 #include <com/sun/star/text/XTextShapesSupplier.hpp>
75 #include <com/sun/star/style/XAutoStylesSupplier.hpp>
76 #include <com/sun/star/style/XAutoStyleFamily.hpp>
77 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
78 #include <com/sun/star/text/XFootnotesSupplier.hpp>
79 #include <com/sun/star/text/XEndnotesSupplier.hpp>
80 #include <com/sun/star/drawing/XControlShape.hpp>
81 #include <com/sun/star/util/DateTime.hpp>
82 #include "xmloff/xmlnmspe.hxx"
83 #include <xmloff/xmlaustp.hxx>
84 #include <xmloff/families.hxx>
85 #include "txtexppr.hxx"
86 #include <xmloff/xmlnumfe.hxx>
87 #include <xmloff/xmlnume.hxx>
88 #include <xmloff/xmluconv.hxx>
89 #include "XMLAnchorTypePropHdl.hxx"
90 #include "xexptran.hxx"
91 #include <xmloff/ProgressBarHelper.hxx>
92 #include <xmloff/nmspmap.hxx>
93 #include <xmloff/xmlexp.hxx>
94 #include "txtflde.hxx"
95 #include <xmloff/txtprmap.hxx>
96 #include "XMLImageMapExport.hxx"
97 #include "XMLTextNumRuleInfo.hxx"
98 #include "xmloff/XMLTextListAutoStylePool.hxx"
99 #include <xmloff/txtparae.hxx>
100 #include "XMLSectionExport.hxx"
101 #include "XMLIndexMarkExport.hxx"
102 #include <xmloff/XMLEventExport.hxx>
103 #include "XMLRedlineExport.hxx"
104 #include "MultiPropertySetHelper.hxx"
105 #include <xmloff/formlayerexport.hxx>
106 #include "XMLTextCharStyleNamesElementExport.hxx"
107 #include <comphelper/stlunosequence.hxx>
108 #include <txtlists.hxx>
109 #include <com/sun/star/rdf/XMetadatable.hpp>
110 #include <basegfx/polygon/b2dpolypolygon.hxx>
111 #include <basegfx/polygon/b2dpolypolygontools.hxx>
112 #include <basegfx/polygon/b2dpolygontools.hxx>
113 
114 using ::rtl::OUString;
115 using ::rtl::OUStringBuffer;
116 
117 using namespace ::std;
118 using namespace ::com::sun::star;
119 using namespace ::com::sun::star::uno;
120 using namespace ::com::sun::star::lang;
121 using namespace ::com::sun::star::beans;
122 using namespace ::com::sun::star::container;
123 using namespace ::com::sun::star::text;
124 using namespace ::com::sun::star::style;
125 using namespace ::com::sun::star::util;
126 using namespace ::com::sun::star::drawing;
127 using namespace ::com::sun::star::document;
128 using namespace ::com::sun::star::frame;
129 using namespace ::xmloff;
130 using namespace ::xmloff::token;
131 
132 namespace
133 {
134     class TextContentSet
135     {
136         public:
137             typedef Reference<XTextContent> text_content_ref_t;
138             typedef list<text_content_ref_t> contents_t;
139             typedef back_insert_iterator<contents_t> inserter_t;
140             typedef contents_t::const_iterator const_iterator_t;
141 
getInserter()142             inserter_t getInserter()
143                 { return back_insert_iterator<contents_t>(m_vTextContents); };
getBegin() const144             const_iterator_t getBegin() const
145                 { return m_vTextContents.begin(); };
getEnd() const146             const_iterator_t getEnd() const
147                 { return m_vTextContents.end(); };
148 
149         private:
150             contents_t m_vTextContents;
151     };
152 
153     struct FrameRefHash
154         : public unary_function<Reference<XTextFrame>, size_t>
155     {
operator ()__anone0644cf80111::FrameRefHash156         size_t operator()(const Reference<XTextFrame> xFrame) const
157             { return sal::static_int_cast<size_t>(reinterpret_cast<sal_uIntPtr>(xFrame.get())); }
158     };
159 
lcl_TextContentsUnfiltered(const Reference<XTextContent> &)160     static bool lcl_TextContentsUnfiltered(const Reference<XTextContent>&)
161         { return true; };
162 
lcl_ShapeFilter(const Reference<XTextContent> & xTxtContent)163     static bool lcl_ShapeFilter(const Reference<XTextContent>& xTxtContent)
164     {
165         static const OUString sTextFrameService = OUString::createFromAscii("com.sun.star.text.TextFrame");
166         static const OUString sTextGraphicService = OUString::createFromAscii("com.sun.star.text.TextGraphicObject");
167         static const OUString sTextEmbeddedService = OUString::createFromAscii("com.sun.star.text.TextEmbeddedObject");
168         Reference<XShape> xShape(xTxtContent, UNO_QUERY);
169         if(!xShape.is())
170             return false;
171         Reference<XServiceInfo> xServiceInfo(xTxtContent, UNO_QUERY);
172         if(xServiceInfo->supportsService(sTextFrameService) ||
173             xServiceInfo->supportsService(sTextGraphicService) ||
174             xServiceInfo->supportsService(sTextEmbeddedService) )
175             return false;
176         return true;
177     };
178 
179     class BoundFrames
180     {
181         public:
182             typedef bool (*filter_t)(const Reference<XTextContent>&);
BoundFrames(const Reference<XEnumerationAccess> xEnumAccess,const filter_t & rFilter)183             BoundFrames(
184                 const Reference<XEnumerationAccess> xEnumAccess,
185                 const filter_t& rFilter)
186                 : m_xEnumAccess(xEnumAccess)
187             {
188                 Fill(rFilter);
189             };
BoundFrames()190             BoundFrames()
191                 {};
GetPageBoundContents() const192             const TextContentSet* GetPageBoundContents() const
193                 { return &m_vPageBounds; };
GetFrameBoundContents(const Reference<XTextFrame> & rParentFrame) const194             const TextContentSet* GetFrameBoundContents(const Reference<XTextFrame>& rParentFrame) const
195             {
196                 framebound_map_t::const_iterator it = m_vFrameBoundsOf.find(rParentFrame);
197                 if(it == m_vFrameBoundsOf.end())
198                     return NULL;
199                 return &(it->second);
200             };
createEnumeration() const201             Reference<XEnumeration> createEnumeration() const
202             {
203                 if(!m_xEnumAccess.is())
204                     return Reference<XEnumeration>();
205                 return m_xEnumAccess->createEnumeration();
206             };
207 
208         private:
209             typedef hash_map<
210                 Reference<XTextFrame>,
211                 TextContentSet,
212                 FrameRefHash> framebound_map_t;
213             TextContentSet m_vPageBounds;
214             framebound_map_t m_vFrameBoundsOf;
215             const Reference<XEnumerationAccess> m_xEnumAccess;
216             void Fill(const filter_t& rFilter);
217             static const OUString our_sAnchorType;
218             static const OUString our_sAnchorFrame;
219     };
220     const OUString BoundFrames::our_sAnchorType = OUString::createFromAscii("AnchorType");
221     const OUString BoundFrames::our_sAnchorFrame = OUString::createFromAscii("AnchorFrame");
222 
223     class FieldParamExporter
224     {
225         public:
FieldParamExporter(SvXMLExport * const pExport,Reference<XNameContainer> xFieldParams)226             FieldParamExporter(SvXMLExport* const pExport, Reference<XNameContainer> xFieldParams)
227                 : m_pExport(pExport)
228                 , m_xFieldParams(xFieldParams)
229                 { };
230             void Export();
231 
232         private:
233             SvXMLExport* const m_pExport;
234             const Reference<XNameContainer> m_xFieldParams;
235 
236             void ExportParameter(const OUString& sKey, const OUString& sValue);
237     };
238 }
239 
240 namespace xmloff
241 {
242     class BoundFrameSets
243     {
244         public:
245             BoundFrameSets(const Reference<XInterface> xModel);
GetTexts() const246             const BoundFrames* GetTexts() const
247                 { return m_pTexts.get(); };
GetGraphics() const248             const BoundFrames* GetGraphics() const
249                 { return m_pGraphics.get(); };
GetEmbeddeds() const250             const BoundFrames* GetEmbeddeds() const
251                 { return m_pEmbeddeds.get(); };
GetShapes() const252             const BoundFrames* GetShapes() const
253                 { return m_pShapes.get(); };
254         private:
255             auto_ptr<BoundFrames> m_pTexts;
256             auto_ptr<BoundFrames> m_pGraphics;
257             auto_ptr<BoundFrames> m_pEmbeddeds;
258             auto_ptr<BoundFrames> m_pShapes;
259     };
260 }
261 
262 typedef OUString *OUStringPtr;
263 SV_DECL_PTRARR_DEL( OUStrings_Impl, OUStringPtr, 20, 10 )
264 SV_IMPL_PTRARR( OUStrings_Impl, OUStringPtr )
265 
266 SV_DECL_PTRARR_SORT_DEL( OUStringsSort_Impl, OUStringPtr, 20, 10 )
267 SV_IMPL_OP_PTRARR_SORT( OUStringsSort_Impl, OUStringPtr )
268 
269 #ifdef DBG_UTIL
270 static int txtparae_bContainsIllegalCharacters = sal_False;
271 #endif
272 
273 // The following map shows which property values are required:
274 //
275 // property						auto style pass		export
276 // --------------------------------------------------------
277 // ParaStyleName				if style exists		always
278 // ParaConditionalStyleName		if style exists		always
279 // NumberingRules				if style exists		always
280 // TextSection					always				always
281 // ParaChapterNumberingLevel	never				always
282 // NumberingIsNumber            never               always
283 
284 // The conclusion is that for auto styles the first three properties
285 // should be queried using a multi property set if, and only if, an
286 // auto style needs to be exported. TextSection should be queried by
287 // an individual call to getPropertyvalue, because this seems to be
288 // less expensive than querying the first three properties if they aren't
289 // required.
290 
291 // For the export pass all properties can be queried using a multi property
292 // set.
293 
294 static const sal_Char* aParagraphPropertyNamesAuto[] =
295 {
296 	"NumberingRules",
297 	"ParaConditionalStyleName",
298 	"ParaStyleName",
299 	NULL
300 };
301 
302 enum eParagraphPropertyNamesEnumAuto
303 {
304 	NUMBERING_RULES_AUTO = 0,
305 	PARA_CONDITIONAL_STYLE_NAME_AUTO = 1,
306 	PARA_STYLE_NAME_AUTO = 2
307 };
308 
309 static const sal_Char* aParagraphPropertyNames[] =
310 {
311     "NumberingIsNumber",
312 	"NumberingStyleName",			//#outline level,add by zhaojianwei
313 
314 	//"ParaChapterNumberingLevel",	//#outline level,remove by zhaojianwei
315 	"OutlineLevel",					//<-end,add by zhaojianwei
316 	"ParaConditionalStyleName",
317 	"ParaStyleName",
318 	"TextSection",
319     NULL
320 };
321 
322 enum eParagraphPropertyNamesEnum
323 {
324 	NUMBERING_IS_NUMBER = 0,
325 	PARA_NUMBERING_STYLENAME = 1,		//#outline level,add by zhaojianwei
326 	//PARA_CHAPTER_NUMERBING_LEVEL = 1,	//#outline level,remove by zhaojianwei
327 	PARA_OUTLINE_LEVEL=2,				//<-end.add by zhaojianwei
328 	PARA_CONDITIONAL_STYLE_NAME = 3,
329 	PARA_STYLE_NAME = 4,
330 	TEXT_SECTION = 5
331 };
332 
Fill(const filter_t & rFilter)333 void BoundFrames::Fill(const filter_t& rFilter)
334 {
335     if(!m_xEnumAccess.is())
336         return;
337     const Reference< XEnumeration > xEnum = m_xEnumAccess->createEnumeration();
338     if(!xEnum.is())
339         return;
340     while(xEnum->hasMoreElements())
341     {
342         Reference<XPropertySet> xPropSet(xEnum->nextElement(), UNO_QUERY);
343         Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY);
344         if(!xPropSet.is() || !xTextContent.is())
345             continue;
346         TextContentAnchorType eAnchor;
347         xPropSet->getPropertyValue(our_sAnchorType) >>= eAnchor;
348         if(TextContentAnchorType_AT_PAGE != eAnchor && TextContentAnchorType_AT_FRAME != eAnchor)
349             continue;
350         if(!rFilter(xTextContent))
351             continue;
352 
353         TextContentSet::inserter_t pInserter = m_vPageBounds.getInserter();
354         if(TextContentAnchorType_AT_FRAME == eAnchor)
355         {
356             Reference<XTextFrame> xAnchorTxtFrame(
357                 xPropSet->getPropertyValue(our_sAnchorFrame),
358                 uno::UNO_QUERY);
359             pInserter = m_vFrameBoundsOf[xAnchorTxtFrame].getInserter();
360         }
361         *pInserter++ = xTextContent;
362     }
363 }
364 
BoundFrameSets(const Reference<XInterface> xModel)365 BoundFrameSets::BoundFrameSets(const Reference<XInterface> xModel)
366     : m_pTexts(new BoundFrames())
367     , m_pGraphics(new BoundFrames())
368     , m_pEmbeddeds(new BoundFrames())
369     , m_pShapes(new BoundFrames())
370 {
371     const Reference<XTextFramesSupplier> xTFS(xModel, UNO_QUERY);
372     const Reference<XTextGraphicObjectsSupplier> xGOS(xModel, UNO_QUERY);
373     const Reference<XTextEmbeddedObjectsSupplier> xEOS(xModel, UNO_QUERY);
374     const Reference<XDrawPageSupplier> xDPS(xModel, UNO_QUERY);
375     if(xTFS.is())
376         m_pTexts = auto_ptr<BoundFrames>(new BoundFrames(
377             Reference<XEnumerationAccess>(xTFS->getTextFrames(), UNO_QUERY),
378             &lcl_TextContentsUnfiltered));
379     if(xGOS.is())
380         m_pGraphics = auto_ptr<BoundFrames>(new BoundFrames(
381             Reference<XEnumerationAccess>(xGOS->getGraphicObjects(), UNO_QUERY),
382             &lcl_TextContentsUnfiltered));
383     if(xEOS.is())
384         m_pEmbeddeds = auto_ptr<BoundFrames>(new BoundFrames(
385             Reference<XEnumerationAccess>(xEOS->getEmbeddedObjects(), UNO_QUERY),
386             &lcl_TextContentsUnfiltered));
387     if(xDPS.is())
388         m_pShapes = auto_ptr<BoundFrames>(new BoundFrames(
389             Reference<XEnumerationAccess>(xDPS->getDrawPage(), UNO_QUERY),
390             &lcl_ShapeFilter));
391 };
392 
Export()393 void FieldParamExporter::Export()
394 {
395     static const Type aStringType = ::getCppuType((OUString*)0);
396     static const Type aBoolType = ::getCppuType((sal_Bool*)0);
397     static const Type aSeqType = ::getCppuType((Sequence<OUString>*)0);
398     static const Type aIntType = ::getCppuType((sal_Int32*)0);
399     Sequence<OUString> vParameters(m_xFieldParams->getElementNames());
400     for(const OUString* pCurrent=::comphelper::stl_begin(vParameters); pCurrent!=::comphelper::stl_end(vParameters); ++pCurrent)
401     {
402         const Any aValue = m_xFieldParams->getByName(*pCurrent);
403         const Type aValueType = aValue.getValueType();
404         if(aValueType == aStringType)
405         {
406             OUString sValue;
407             aValue >>= sValue;
408             ExportParameter(*pCurrent,sValue);
409         }
410         else if(aValueType == aBoolType)
411         {
412             sal_Bool bValue = false;
413             aValue >>= bValue;
414             ExportParameter(*pCurrent,OUString::createFromAscii(bValue ? "true" : "false"));
415         }
416         else if(aValueType == aSeqType)
417         {
418             Sequence<OUString> vValue;
419             aValue >>= vValue;
420             for(OUString* pSeqCurrent = ::comphelper::stl_begin(vValue); pSeqCurrent != ::comphelper::stl_end(vValue); ++pSeqCurrent)
421             {
422                 ExportParameter(*pCurrent, *pSeqCurrent);
423             }
424         }
425         else if(aValueType == aIntType)
426         {
427             sal_Int32 nValue = 0;
428             aValue >>= nValue;
429             ExportParameter(*pCurrent, OUStringBuffer().append(nValue).makeStringAndClear());
430         }
431     }
432 }
433 
ExportParameter(const OUString & sKey,const OUString & sValue)434 void FieldParamExporter::ExportParameter(const OUString& sKey, const OUString& sValue)
435 {
436     m_pExport->AddAttribute(XML_NAMESPACE_FIELD, XML_NAME, sKey);
437     m_pExport->AddAttribute(XML_NAMESPACE_FIELD, XML_VALUE, sValue);
438     m_pExport->StartElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
439     m_pExport->EndElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
440 }
441 
Add(sal_uInt16 nFamily,const Reference<XPropertySet> & rPropSet,const XMLPropertyState ** ppAddStates,bool bDontSeek)442 void XMLTextParagraphExport::Add( sal_uInt16 nFamily,
443 								  const Reference < XPropertySet > & rPropSet,
444 								  const XMLPropertyState** ppAddStates, bool bDontSeek )
445 {
446 	UniReference < SvXMLExportPropertyMapper > xPropMapper;
447 	switch( nFamily )
448 	{
449 	case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
450 		xPropMapper = GetParaPropMapper();
451 		break;
452 	case XML_STYLE_FAMILY_TEXT_TEXT:
453 		xPropMapper = GetTextPropMapper();
454 		break;
455 	case XML_STYLE_FAMILY_TEXT_FRAME:
456 		xPropMapper = GetAutoFramePropMapper();
457 		break;
458 	case XML_STYLE_FAMILY_TEXT_SECTION:
459 		xPropMapper = GetSectionPropMapper();
460 		break;
461 	case XML_STYLE_FAMILY_TEXT_RUBY:
462 		xPropMapper = GetRubyPropMapper();
463 		break;
464 	}
465 	DBG_ASSERT( xPropMapper.is(), "There is the property mapper?" );
466 
467 	vector< XMLPropertyState > xPropStates =
468 			xPropMapper->Filter( rPropSet );
469 
470 	if( ppAddStates )
471 	{
472 		while( *ppAddStates )
473 		{
474 			xPropStates.push_back( **ppAddStates );
475 			ppAddStates++;
476 		}
477 	}
478 
479 	if( !xPropStates.empty() )
480 	{
481 		Reference< XPropertySetInfo > xPropSetInfo(rPropSet->getPropertySetInfo());
482 		OUString sParent, sCondParent;
483 		sal_uInt16 nIgnoreProps = 0;
484 		switch( nFamily )
485 		{
486 		case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
487 			if( xPropSetInfo->hasPropertyByName( sParaStyleName ) )
488 			{
489 				rPropSet->getPropertyValue( sParaStyleName ) >>= sParent;
490 			}
491 			if( xPropSetInfo->hasPropertyByName( sParaConditionalStyleName ) )
492 			{
493 				rPropSet->getPropertyValue( sParaConditionalStyleName ) >>= sCondParent;
494 			}
495 			if( xPropSetInfo->hasPropertyByName( sNumberingRules ) )
496 			{
497                 Reference < XIndexReplace > xNumRule(rPropSet->getPropertyValue( sNumberingRules ), uno::UNO_QUERY);
498 				if( xNumRule.is() && xNumRule->getCount() )
499 				{
500 					Reference < XNamed > xNamed( xNumRule, UNO_QUERY );
501 					OUString sName;
502 					if( xNamed.is() )
503 						sName = xNamed->getName();
504 					sal_Bool bAdd = !sName.getLength();
505 					if( !bAdd )
506 					{
507 						Reference < XPropertySet > xNumPropSet( xNumRule,
508 																UNO_QUERY );
509                         const OUString sIsAutomatic( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) );
510 						if( xNumPropSet.is() &&
511 							xNumPropSet->getPropertySetInfo()
512 									   ->hasPropertyByName( sIsAutomatic ) )
513 						{
514 							bAdd = *(sal_Bool *)xNumPropSet->getPropertyValue( sIsAutomatic ).getValue();
515                             // --> OD 2007-01-12 #i73361# - check on outline style
516                             const OUString sNumberingIsOutline( RTL_CONSTASCII_USTRINGPARAM( "NumberingIsOutline" ) );
517                             if ( bAdd &&
518                                  xNumPropSet->getPropertySetInfo()
519                                            ->hasPropertyByName( sNumberingIsOutline ) )
520                             {
521                                 bAdd = !(*(sal_Bool *)xNumPropSet->getPropertyValue( sNumberingIsOutline ).getValue());
522                             }
523                             // <--
524 						}
525 						else
526 						{
527 							bAdd = sal_True;
528 						}
529 					}
530 					if( bAdd )
531 						pListAutoPool->Add( xNumRule );
532 				}
533 			}
534 			break;
535 		case XML_STYLE_FAMILY_TEXT_TEXT:
536 			{
537 				// Get parent and remove hyperlinks (they aren't of interest)
538 				UniReference< XMLPropertySetMapper > xPM(xPropMapper->getPropertySetMapper());
539 				for( ::std::vector< XMLPropertyState >::iterator i(xPropStates.begin());
540 		 			 nIgnoreProps < 2 && i != xPropStates.end(); )
541 				{
542 					if( i->mnIndex == -1 )
543                     {
544                         ++i;
545 						continue;
546                     }
547 
548 					switch( xPM->GetEntryContextId(i->mnIndex) )
549 					{
550 					case CTF_CHAR_STYLE_NAME:
551 					case CTF_HYPERLINK_URL:
552 						i->mnIndex = -1;
553 						nIgnoreProps++;
554                         i = xPropStates.erase( i );
555 						break;
556                     default:
557                         ++i;
558                         break;
559 					}
560 				}
561 			}
562 			break;
563 		case XML_STYLE_FAMILY_TEXT_FRAME:
564 			if( xPropSetInfo->hasPropertyByName( sFrameStyleName ) )
565 			{
566 				rPropSet->getPropertyValue( sFrameStyleName ) >>= sParent;
567 			}
568 			break;
569 		case XML_STYLE_FAMILY_TEXT_SECTION:
570 		case XML_STYLE_FAMILY_TEXT_RUBY:
571 			; // section styles have no parents
572 			break;
573 		}
574 		if( (xPropStates.size() - nIgnoreProps) > 0 )
575 		{
576 			GetAutoStylePool().Add( nFamily, sParent, xPropStates, bDontSeek );
577 			if( sCondParent.getLength() && sParent != sCondParent )
578 				GetAutoStylePool().Add( nFamily, sCondParent, xPropStates );
579 		}
580 	}
581 }
582 
lcl_validPropState(const XMLPropertyState & rState)583 bool lcl_validPropState( const XMLPropertyState& rState )
584 {
585     return rState.mnIndex != -1;
586 }
587 
Add(sal_uInt16 nFamily,MultiPropertySetHelper & rPropSetHelper,const Reference<XPropertySet> & rPropSet,const XMLPropertyState ** ppAddStates)588 void XMLTextParagraphExport::Add( sal_uInt16 nFamily,
589 								  MultiPropertySetHelper& rPropSetHelper,
590 								  const Reference < XPropertySet > & rPropSet,
591 								  const XMLPropertyState** ppAddStates)
592 {
593 	UniReference < SvXMLExportPropertyMapper > xPropMapper;
594 	switch( nFamily )
595 	{
596 	case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
597 		xPropMapper = GetParaPropMapper();
598 		break;
599 	}
600 	DBG_ASSERT( xPropMapper.is(), "There is the property mapper?" );
601 
602 	vector< XMLPropertyState > xPropStates(xPropMapper->Filter( rPropSet ));
603 	if( ppAddStates )
604 	{
605 		while( *ppAddStates )
606 		{
607 			xPropStates.push_back( **ppAddStates );
608 			++ppAddStates;
609 		}
610 	}
611 
612 	if( rPropSetHelper.hasProperty( NUMBERING_RULES_AUTO ) )
613 	{
614 		Reference < XIndexReplace > xNumRule(rPropSetHelper.getValue( NUMBERING_RULES_AUTO,
615             rPropSet, sal_True ), uno::UNO_QUERY);
616 		if( xNumRule.is() && xNumRule->getCount() )
617 		{
618 			Reference < XNamed > xNamed( xNumRule, UNO_QUERY );
619 			OUString sName;
620 			if( xNamed.is() )
621 				sName = xNamed->getName();
622 			sal_Bool bAdd = !sName.getLength();
623 			if( !bAdd )
624 			{
625 				Reference < XPropertySet > xNumPropSet( xNumRule,
626 														UNO_QUERY );
627                 const OUString sIsAutomatic( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) );
628 				if( xNumPropSet.is() &&
629 					xNumPropSet->getPropertySetInfo()
630 							   ->hasPropertyByName( sIsAutomatic ) )
631 				{
632 					bAdd = *(sal_Bool *)xNumPropSet->getPropertyValue( sIsAutomatic ).getValue();
633                     // --> OD 2007-01-12 #i73361# - check on outline style
634                     const OUString sNumberingIsOutline( RTL_CONSTASCII_USTRINGPARAM( "NumberingIsOutline" ) );
635                     if ( bAdd &&
636                          xNumPropSet->getPropertySetInfo()
637                                    ->hasPropertyByName( sNumberingIsOutline ) )
638                     {
639                         bAdd = !(*(sal_Bool *)xNumPropSet->getPropertyValue( sNumberingIsOutline ).getValue());
640                     }
641                     // <--
642 				}
643 				else
644 				{
645 					bAdd = sal_True;
646 				}
647 			}
648 			if( bAdd )
649 				pListAutoPool->Add( xNumRule );
650 		}
651 	}
652 
653 	if( !xPropStates.empty() )
654 	{
655 		OUString sParent, sCondParent;
656 		switch( nFamily )
657 		{
658 		case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
659 			if( rPropSetHelper.hasProperty( PARA_STYLE_NAME_AUTO ) )
660 			{
661 				rPropSetHelper.getValue( PARA_STYLE_NAME_AUTO, rPropSet,
662 												sal_True ) >>= sParent;
663 			}
664 			if( rPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME_AUTO ) )
665 			{
666 				rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME_AUTO,
667 											 	rPropSet, sal_True ) >>= sCondParent;
668 			}
669 
670 			break;
671 		}
672 
673         if( find_if( xPropStates.begin(), xPropStates.end(), lcl_validPropState ) != xPropStates.end() )
674 		{
675 			GetAutoStylePool().Add( nFamily, sParent, xPropStates );
676 			if( sCondParent.getLength() && sParent != sCondParent )
677 				GetAutoStylePool().Add( nFamily, sCondParent, xPropStates );
678 		}
679 	}
680 }
681 
Find(sal_uInt16 nFamily,const Reference<XPropertySet> & rPropSet,const OUString & rParent,const XMLPropertyState ** ppAddStates) const682 OUString XMLTextParagraphExport::Find(
683 		sal_uInt16 nFamily,
684 	   	const Reference < XPropertySet > & rPropSet,
685 		const OUString& rParent,
686 		const XMLPropertyState** ppAddStates) const
687 {
688 	OUString sName( rParent );
689 	UniReference < SvXMLExportPropertyMapper > xPropMapper;
690 	switch( nFamily )
691 	{
692 	case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
693 		xPropMapper = GetParaPropMapper();
694 		break;
695 	case XML_STYLE_FAMILY_TEXT_FRAME:
696 		xPropMapper = GetAutoFramePropMapper();
697 		break;
698 	case XML_STYLE_FAMILY_TEXT_SECTION:
699 		xPropMapper = GetSectionPropMapper();
700 		break;
701 	case XML_STYLE_FAMILY_TEXT_RUBY:
702 		xPropMapper = GetRubyPropMapper();
703 		break;
704 	}
705 	DBG_ASSERT( xPropMapper.is(), "There is the property mapper?" );
706 	if( !xPropMapper.is() )
707 		return sName;
708 	vector< XMLPropertyState > xPropStates(xPropMapper->Filter( rPropSet ));
709 	if( ppAddStates )
710 	{
711 		while( *ppAddStates )
712 		{
713 			xPropStates.push_back( **ppAddStates );
714 			++ppAddStates;
715 		}
716 	}
717     if( find_if( xPropStates.begin(), xPropStates.end(), lcl_validPropState ) != xPropStates.end() )
718 		sName = GetAutoStylePool().Find( nFamily, sName, xPropStates );
719 
720 	return sName;
721 }
722 
FindTextStyleAndHyperlink(const Reference<XPropertySet> & rPropSet,sal_Bool & rbHyperlink,sal_Bool & rbHasCharStyle,sal_Bool & rbHasAutoStyle,const XMLPropertyState ** ppAddStates) const723 OUString XMLTextParagraphExport::FindTextStyleAndHyperlink(
724 	   	const Reference < XPropertySet > & rPropSet,
725         sal_Bool& rbHyperlink,
726         sal_Bool& rbHasCharStyle,
727         sal_Bool& rbHasAutoStyle,
728 		const XMLPropertyState** ppAddStates ) const
729 {
730 	UniReference < SvXMLExportPropertyMapper > xPropMapper(GetTextPropMapper());
731 	vector< XMLPropertyState > xPropStates(xPropMapper->Filter( rPropSet ));
732 
733 	// Get parent and remove hyperlinks (they aren't of interest)
734 	OUString sName;
735     rbHyperlink = rbHasCharStyle = rbHasAutoStyle = sal_False;
736 	sal_uInt16 nIgnoreProps = 0;
737 	UniReference< XMLPropertySetMapper > xPM(xPropMapper->getPropertySetMapper());
738     ::std::vector< XMLPropertyState >::iterator aFirstDel = xPropStates.end();
739     ::std::vector< XMLPropertyState >::iterator aSecondDel = xPropStates.end();
740 
741 	for( ::std::vector< XMLPropertyState >::iterator
742 			i = xPropStates.begin();
743 		 nIgnoreProps < 2 && i != xPropStates.end();
744 		 i++ )
745 	{
746 		if( i->mnIndex == -1 )
747 			continue;
748 
749 		switch( xPM->GetEntryContextId(i->mnIndex) )
750 		{
751 		case CTF_CHAR_STYLE_NAME:
752 			i->maValue >>= sName;
753 			i->mnIndex = -1;
754             rbHasCharStyle = sName.getLength() > 0;
755             if( nIgnoreProps )
756                 aSecondDel = i;
757             else
758                 aFirstDel = i;
759 			nIgnoreProps++;
760 			break;
761 		case CTF_HYPERLINK_URL:
762             rbHyperlink = sal_True;
763 			i->mnIndex = -1;
764             if( nIgnoreProps )
765                 aSecondDel = i;
766             else
767                 aFirstDel = i;
768 			nIgnoreProps++;
769 			break;
770 		}
771 	}
772 	if( ppAddStates )
773 	{
774 		while( *ppAddStates )
775 		{
776 			xPropStates.push_back( **ppAddStates );
777 			ppAddStates++;
778 		}
779 	}
780 	if( (xPropStates.size() - nIgnoreProps) > 0L )
781     {
782         // erase the character style, otherwise the autostyle cannot be found!
783         // erase the hyperlink, otherwise the autostyle cannot be found!
784         if ( nIgnoreProps )
785         {
786             // If two elements of a vector have to be deleted,
787             // we should delete the second one first.
788             if( --nIgnoreProps )
789                 xPropStates.erase( aSecondDel );
790             xPropStates.erase( aFirstDel );
791         }
792         OUString sParent; // AutoStyles should not have parents!
793 		sName = GetAutoStylePool().Find( XML_STYLE_FAMILY_TEXT_TEXT, sParent, xPropStates );
794         DBG_ASSERT( sName.getLength(), "AutoStyle could not be found" );
795         rbHasAutoStyle = sal_True;
796     }
797 
798 	return sName;
799 }
800 
FindTextStyle(const Reference<XPropertySet> & rPropSet,sal_Bool & rHasCharStyle) const801 OUString XMLTextParagraphExport::FindTextStyle(
802 	   	const Reference < XPropertySet > & rPropSet,
803 		sal_Bool& rHasCharStyle ) const
804 {
805     sal_Bool bDummy;
806     sal_Bool bDummy2;
807     return FindTextStyleAndHyperlink( rPropSet, bDummy, rHasCharStyle, bDummy2 );
808 }
809 
810 
811 // --> OD 2008-04-25 #refactorlists#
812 // adjustments to support lists independent from list style
exportListChange(const XMLTextNumRuleInfo & rPrevInfo,const XMLTextNumRuleInfo & rNextInfo)813 void XMLTextParagraphExport::exportListChange(
814 		const XMLTextNumRuleInfo& rPrevInfo,
815 	    const XMLTextNumRuleInfo& rNextInfo )
816 {
817 	// end a list
818     if ( rPrevInfo.GetLevel() > 0 )
819     {
820         bool bRootListToBeClosed = false;
821         sal_Int16 nListLevelsToBeClosed = 0;
822         if ( !rNextInfo.BelongsToSameList( rPrevInfo ) ||
823              rNextInfo.GetLevel() <= 0 )
824         {
825             // close complete previous list
826             bRootListToBeClosed = true;
827             nListLevelsToBeClosed = rPrevInfo.GetLevel();
828         }
829         else if ( rPrevInfo.GetLevel() > rNextInfo.GetLevel() )
830         {
831             // close corresponding sub lists
832             DBG_ASSERT( rNextInfo.GetLevel() > 0,
833                         "<rPrevInfo.GetLevel() > 0> not hold. Serious defect -> please inform OD." );
834             nListLevelsToBeClosed = rPrevInfo.GetLevel() - rNextInfo.GetLevel();
835         }
836 
837         if ( nListLevelsToBeClosed > 0 &&
838              pListElements &&
839              pListElements->Count() >= ( 2 * nListLevelsToBeClosed ) )
840         {
841             do {
842                 for( sal_uInt16 j = 0; j < 2; ++j )
843                 {
844                     OUString *pElem = (*pListElements)[pListElements->Count()-1];
845                     pListElements->Remove( pListElements->Count()-1 );
846 
847                     GetExport().EndElement( *pElem, sal_True );
848 
849                     delete pElem;
850                 }
851 
852                 // remove closed list from list stack
853                 mpTextListsHelper->PopListFromStack();
854 
855                 --nListLevelsToBeClosed;
856             } while ( nListLevelsToBeClosed > 0 );
857         }
858     }
859 
860     const bool bExportODF =
861                 ( GetExport().getExportFlags() & EXPORT_OASIS ) != 0;
862     const SvtSaveOptions::ODFDefaultVersion eODFDefaultVersion =
863                                     GetExport().getDefaultVersion();
864 
865     // start a new list
866     if ( rNextInfo.GetLevel() > 0 )
867     {
868         bool bRootListToBeStarted = false;
869         sal_Int16 nListLevelsToBeOpened = 0;
870         if ( !rPrevInfo.BelongsToSameList( rNextInfo ) ||
871              rPrevInfo.GetLevel() <= 0 )
872         {
873             // new root list
874             bRootListToBeStarted = true;
875             nListLevelsToBeOpened = rNextInfo.GetLevel();
876         }
877         else if ( rNextInfo.GetLevel() > rPrevInfo.GetLevel() )
878         {
879             // open corresponding sub lists
880             DBG_ASSERT( rPrevInfo.GetLevel() > 0,
881                         "<rPrevInfo.GetLevel() > 0> not hold. Serious defect -> please inform OD." );
882             nListLevelsToBeOpened = rNextInfo.GetLevel() - rPrevInfo.GetLevel();
883         }
884 
885         if ( nListLevelsToBeOpened > 0 )
886         {
887             const ::rtl::OUString sListStyleName( rNextInfo.GetNumRulesName() );
888             // Currently only the text documents support <ListId>.
889             // Thus, for other document types <sListId> is empty.
890             const ::rtl::OUString sListId( rNextInfo.GetListId() );
891             bool bExportListStyle( true );
892             bool bRestartNumberingAtContinuedRootList( false );
893             sal_Int16 nRestartValueForContinuedRootList( -1 );
894             // --> OD 2008-11-26 #158694#
895             bool bContinueingPreviousSubList = !bRootListToBeStarted &&
896                                                rNextInfo.IsContinueingPreviousSubTree();
897             // <--
898             do {
899                 GetExport().CheckAttrList();
900 
901                 if ( bRootListToBeStarted )
902                 {
903                     if ( !mpTextListsHelper->IsListProcessed( sListId ) )
904                     {
905                         if ( bExportODF &&
906                              eODFDefaultVersion >= SvtSaveOptions::ODFVER_012 &&
907                              sListId.getLength() > 0 )
908                         {
909                             // --> OD 2008-07-31 #i92221#
910                             GetExport().AddAttribute( XML_NAMESPACE_XML,
911                                                       XML_ID,
912                                                       sListId );
913                             // <--
914                         }
915                         mpTextListsHelper->KeepListAsProcessed( sListId,
916                                                                 sListStyleName,
917                                                                 ::rtl::OUString() );
918                     }
919                     else
920                     {
921                         const ::rtl::OUString sNewListId(
922                                         mpTextListsHelper->GenerateNewListId() );
923                         if ( bExportODF &&
924                              eODFDefaultVersion >= SvtSaveOptions::ODFVER_012 &&
925                              sListId.getLength() > 0 )
926                         {
927                             // --> OD 2008-07-31 #i92221#
928                             GetExport().AddAttribute( XML_NAMESPACE_XML,
929                                                       XML_ID,
930                                                       sNewListId );
931                             // <--
932                         }
933 
934                         const ::rtl::OUString sContinueListId =
935                             mpTextListsHelper->GetLastContinuingListId( sListId );
936                         // store that list with list id <sNewListId> is last list,
937                         // which has continued list with list id <sListId>
938                         mpTextListsHelper->StoreLastContinuingList( sListId,
939                                                                     sNewListId );
940                         if ( sListStyleName ==
941                                 mpTextListsHelper->GetListStyleOfLastProcessedList() &&
942                              // --> OD 2008-08-15 #i92811#
943                              sContinueListId ==
944                                 mpTextListsHelper->GetLastProcessedListId() &&
945                              // <--
946                              !rNextInfo.IsRestart() )
947                         {
948                             GetExport().AddAttribute( XML_NAMESPACE_TEXT,
949                                                       XML_CONTINUE_NUMBERING,
950                                                       XML_TRUE );
951                         }
952                         else
953                         {
954                             if ( bExportODF &&
955                                  eODFDefaultVersion >= SvtSaveOptions::ODFVER_012 &&
956                                  sListId.getLength() > 0 )
957                             {
958                                 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
959                                                           XML_CONTINUE_LIST,
960                                                           sContinueListId );
961                             }
962 
963                             if ( rNextInfo.IsRestart() &&
964                                  ( nListLevelsToBeOpened != 1 ||
965                                    !rNextInfo.HasStartValue() ) )
966                             {
967                                 bRestartNumberingAtContinuedRootList = true;
968                                 nRestartValueForContinuedRootList =
969                                                 rNextInfo.GetListLevelStartValue();
970                             }
971                         }
972 
973                         mpTextListsHelper->KeepListAsProcessed( sNewListId,
974                                                                 sListStyleName,
975                                                                 sContinueListId );
976                     }
977 
978                     GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
979                             GetExport().EncodeStyleName( sListStyleName ) );
980                     bExportListStyle = false;
981 
982                     bRootListToBeStarted = false;
983                 }
984                 else if ( bExportListStyle &&
985                           !mpTextListsHelper->EqualsToTopListStyleOnStack( sListStyleName ) )
986                 {
987                     GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
988                             GetExport().EncodeStyleName( sListStyleName ) );
989                     bExportListStyle = false;
990                 }
991 
992                 // --> OD 2008-11-26 #158694#
993                 if ( bContinueingPreviousSubList )
994                 {
995                     GetExport().AddAttribute( XML_NAMESPACE_TEXT,
996                                               XML_CONTINUE_NUMBERING, XML_TRUE );
997                     bContinueingPreviousSubList = false;
998                 }
999                 // <--
1000 
1001                 enum XMLTokenEnum eLName = XML_LIST;
1002 
1003                 OUString *pElem = new OUString(
1004                         GetExport().GetNamespaceMap().GetQNameByKey(
1005                                             XML_NAMESPACE_TEXT,
1006                                             GetXMLToken(eLName) ) );
1007                 GetExport().IgnorableWhitespace();
1008                 GetExport().StartElement( *pElem, sal_False );
1009 
1010                 if( !pListElements )
1011                     pListElements = new OUStrings_Impl;
1012                 pListElements->Insert( pElem, pListElements->Count() );
1013 
1014                 mpTextListsHelper->PushListOnStack( sListId,
1015                                                     sListStyleName );
1016 
1017                 // <text:list-header> or <text:list-item>
1018                 GetExport().CheckAttrList();
1019 
1020                 // --> OD 2009-06-24 #i97309#
1021                 // export start value in case of <bRestartNumberingAtContinuedRootList>
1022                 // at correct list item
1023                 if ( nListLevelsToBeOpened == 1 )
1024                 {
1025                     if ( rNextInfo.HasStartValue() )
1026                     {
1027                         OUStringBuffer aBuffer;
1028                         aBuffer.append( (sal_Int32)rNextInfo.GetStartValue() );
1029                         GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
1030                                       aBuffer.makeStringAndClear() );
1031                     }
1032                     else if ( bRestartNumberingAtContinuedRootList )
1033                     {
1034                         OUStringBuffer aBuffer;
1035                         aBuffer.append( (sal_Int32)nRestartValueForContinuedRootList );
1036                         GetExport().AddAttribute( XML_NAMESPACE_TEXT,
1037                                                   XML_START_VALUE,
1038                                                   aBuffer.makeStringAndClear() );
1039                         bRestartNumberingAtContinuedRootList = false;
1040                     }
1041                 }
1042                 // <--
1043 
1044                 eLName = ( rNextInfo.IsNumbered() || nListLevelsToBeOpened > 1 )
1045                          ? XML_LIST_ITEM
1046                          : XML_LIST_HEADER;
1047                 pElem = new OUString(  GetExport().GetNamespaceMap().GetQNameByKey(
1048                                             XML_NAMESPACE_TEXT,
1049                                             GetXMLToken(eLName) ) );
1050                 GetExport().IgnorableWhitespace();
1051                 GetExport().StartElement( *pElem, sal_False );
1052 
1053                 pListElements->Insert( pElem, pListElements->Count() );
1054 
1055                 // --> OD 2008-11-26 #158694#
1056                 // export of <text:number> element for last opened <text:list-item>, if requested
1057                 if ( GetExport().exportTextNumberElement() &&
1058                      eLName == XML_LIST_ITEM && nListLevelsToBeOpened == 1 && // last iteration --> last opened <text:list-item>
1059                      rNextInfo.ListLabelString().getLength() > 0 )
1060                 {
1061                     const ::rtl::OUString aTextNumberElem =
1062                             OUString( GetExport().GetNamespaceMap().GetQNameByKey(
1063                                       XML_NAMESPACE_TEXT,
1064                                       GetXMLToken(XML_NUMBER) ) );
1065                     GetExport().IgnorableWhitespace();
1066                     GetExport().StartElement( aTextNumberElem, sal_False );
1067                     GetExport().Characters( rNextInfo.ListLabelString() );
1068                     GetExport().EndElement( aTextNumberElem, sal_True );
1069                 }
1070                 // <--
1071 
1072                 --nListLevelsToBeOpened;
1073             } while ( nListLevelsToBeOpened > 0 );
1074         }
1075 	}
1076 
1077     if ( rNextInfo.GetLevel() > 0 &&
1078          rNextInfo.IsNumbered() &&
1079          rPrevInfo.BelongsToSameList( rNextInfo ) &&
1080          rPrevInfo.GetLevel() >= rNextInfo.GetLevel() )
1081 	{
1082         // close previous list-item
1083         DBG_ASSERT( pListElements && pListElements->Count() >= 2,
1084 				"SwXMLExport::ExportListChange: list elements missing" );
1085 
1086 		OUString *pElem = (*pListElements)[pListElements->Count()-1];
1087 		GetExport().EndElement( *pElem, sal_True );
1088 
1089 		pListElements->Remove( pListElements->Count()-1 );
1090 		delete pElem;
1091 
1092         // --> OD 2009-11-12 #i103745# - only for sub lists
1093         if ( rNextInfo.IsRestart() && !rNextInfo.HasStartValue() &&
1094              rNextInfo.GetLevel() != 1 )
1095         // <--
1096         {
1097             // start new sub list respectively list on same list level
1098             pElem = (*pListElements)[pListElements->Count()-1];
1099             GetExport().EndElement( *pElem, sal_True );
1100             GetExport().IgnorableWhitespace();
1101             GetExport().StartElement( *pElem, sal_False );
1102         }
1103 
1104         // open new list-item
1105 		GetExport().CheckAttrList();
1106 		if( rNextInfo.HasStartValue() )
1107 		{
1108 			OUStringBuffer aBuffer;
1109 			aBuffer.append( (sal_Int32)rNextInfo.GetStartValue() );
1110 			GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
1111                                       aBuffer.makeStringAndClear() );
1112 		}
1113         // --> OD 2009-11-12 #i103745# - handle restart without start value on list level 1
1114         else if ( rNextInfo.IsRestart() && /*!rNextInfo.HasStartValue() &&*/
1115                   rNextInfo.GetLevel() == 1 )
1116         {
1117             OUStringBuffer aBuffer;
1118             aBuffer.append( (sal_Int32)rNextInfo.GetListLevelStartValue() );
1119             GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
1120                                       aBuffer.makeStringAndClear() );
1121         }
1122         // <--
1123         if ( ( GetExport().getExportFlags() & EXPORT_OASIS ) != 0 &&
1124              GetExport().getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
1125         {
1126             const ::rtl::OUString sListStyleName( rNextInfo.GetNumRulesName() );
1127             if ( !mpTextListsHelper->EqualsToTopListStyleOnStack( sListStyleName ) )
1128             {
1129                 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
1130                                           XML_STYLE_OVERRIDE,
1131                                           GetExport().EncodeStyleName( sListStyleName ) );
1132             }
1133         }
1134 		pElem = new OUString( GetExport().GetNamespaceMap().GetQNameByKey(
1135 								XML_NAMESPACE_TEXT,
1136 								GetXMLToken(XML_LIST_ITEM) ) );
1137 		GetExport().IgnorableWhitespace();
1138 		GetExport().StartElement( *pElem, sal_False );
1139 
1140 		pListElements->Insert( pElem, pListElements->Count() );
1141 
1142         // --> OD 2008-11-26 #158694#
1143         // export of <text:number> element for <text:list-item>, if requested
1144         if ( GetExport().exportTextNumberElement() &&
1145              rNextInfo.ListLabelString().getLength() > 0 )
1146         {
1147             const ::rtl::OUString aTextNumberElem =
1148                     OUString( GetExport().GetNamespaceMap().GetQNameByKey(
1149                               XML_NAMESPACE_TEXT,
1150                               GetXMLToken(XML_NUMBER) ) );
1151             GetExport().IgnorableWhitespace();
1152             GetExport().StartElement( aTextNumberElem, sal_False );
1153             GetExport().Characters( rNextInfo.ListLabelString() );
1154             GetExport().EndElement( aTextNumberElem, sal_True );
1155         }
1156         // <--
1157     }
1158 }
1159 // <--
1160 
XMLTextParagraphExport(SvXMLExport & rExp,SvXMLAutoStylePoolP & rASP)1161 XMLTextParagraphExport::XMLTextParagraphExport(
1162 		SvXMLExport& rExp,
1163 		SvXMLAutoStylePoolP & rASP
1164 	    ) :
1165 	XMLStyleExport( rExp, OUString(), &rASP ),
1166 	rAutoStylePool( rASP ),
1167     pBoundFrameSets(new BoundFrameSets(GetExport().GetModel())),
1168 	pFieldExport( 0 ),
1169 	pListElements( 0 ),
1170     // --> OD 2008-05-07 #refactorlists# - no longer needed
1171 //    pExportedLists( 0 ),
1172     // <--
1173 	pListAutoPool( new XMLTextListAutoStylePool( this->GetExport() ) ),
1174 	pSectionExport( NULL ),
1175 	pIndexMarkExport( NULL ),
1176 
1177 	pRedlineExport( NULL ),
1178 	pHeadingStyles( NULL ),
1179 
1180 	bProgress( sal_False ),
1181 	bBlock( sal_False ),
1182 
1183 	bOpenRuby( sal_False ),
1184     // --> OD 2008-04-25 #refactorlists#
1185     mpTextListsHelper( 0 ),
1186     maTextListsHelperStack(),
1187     // <--
1188 
1189 	sActualSize(RTL_CONSTASCII_USTRINGPARAM("ActualSize")),
1190     // --> OD 2009-07-22 #i73249#
1191 //    sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText")),
1192     sTitle(RTL_CONSTASCII_USTRINGPARAM("Title")),
1193     sDescription(RTL_CONSTASCII_USTRINGPARAM("Description")),
1194     // <--
1195 	sAnchorCharStyleName(RTL_CONSTASCII_USTRINGPARAM("AnchorCharStyleName")),
1196 	sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo")),
1197 	sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType")),
1198 	sBeginNotice(RTL_CONSTASCII_USTRINGPARAM("BeginNotice")),
1199 	sBookmark(RTL_CONSTASCII_USTRINGPARAM("Bookmark")),
1200 	sCategory(RTL_CONSTASCII_USTRINGPARAM("Category")),
1201 	sChainNextName(RTL_CONSTASCII_USTRINGPARAM("ChainNextName")),
1202 	sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName")),
1203 	sCharStyleNames(RTL_CONSTASCII_USTRINGPARAM("CharStyleNames")),
1204 	sContourPolyPolygon(RTL_CONSTASCII_USTRINGPARAM("ContourPolyPolygon")),
1205 	sDocumentIndex(RTL_CONSTASCII_USTRINGPARAM("DocumentIndex")),
1206 	sDocumentIndexMark(RTL_CONSTASCII_USTRINGPARAM("DocumentIndexMark")),
1207 	sEndNotice(RTL_CONSTASCII_USTRINGPARAM("EndNotice")),
1208 	sFootnote(RTL_CONSTASCII_USTRINGPARAM("Footnote")),
1209 	sFootnoteCounting(RTL_CONSTASCII_USTRINGPARAM("FootnoteCounting")),
1210 	sFrame(RTL_CONSTASCII_USTRINGPARAM("Frame")),
1211 	sFrameHeightAbsolute(RTL_CONSTASCII_USTRINGPARAM("FrameHeightAbsolute")),
1212 	sFrameHeightPercent(RTL_CONSTASCII_USTRINGPARAM("FrameHeightPercent")),
1213 	sFrameStyleName(RTL_CONSTASCII_USTRINGPARAM("FrameStyleName")),
1214 	sFrameWidthAbsolute(RTL_CONSTASCII_USTRINGPARAM("FrameWidthAbsolute")),
1215 	sFrameWidthPercent(RTL_CONSTASCII_USTRINGPARAM("FrameWidthPercent")),
1216 	sGraphicFilter(RTL_CONSTASCII_USTRINGPARAM("GraphicFilter")),
1217 	sGraphicRotation(RTL_CONSTASCII_USTRINGPARAM("GraphicRotation")),
1218 	sGraphicURL(RTL_CONSTASCII_USTRINGPARAM("GraphicURL")),
1219 	sReplacementGraphicURL(RTL_CONSTASCII_USTRINGPARAM("ReplacementGraphicURL")),
1220 	sHeight(RTL_CONSTASCII_USTRINGPARAM("Height")),
1221 	sHoriOrient(RTL_CONSTASCII_USTRINGPARAM("HoriOrient")),
1222 	sHoriOrientPosition(RTL_CONSTASCII_USTRINGPARAM("HoriOrientPosition")),
1223 	sHyperLinkName(RTL_CONSTASCII_USTRINGPARAM("HyperLinkName")),
1224 	sHyperLinkTarget(RTL_CONSTASCII_USTRINGPARAM("HyperLinkTarget")),
1225 	sHyperLinkURL(RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL")),
1226 	sIsAutomaticContour(RTL_CONSTASCII_USTRINGPARAM("IsAutomaticContour")),
1227 	sIsCollapsed(RTL_CONSTASCII_USTRINGPARAM("IsCollapsed")),
1228 	sIsPixelContour(RTL_CONSTASCII_USTRINGPARAM("IsPixelContour")),
1229 	sIsStart(RTL_CONSTASCII_USTRINGPARAM("IsStart")),
1230 	sIsSyncHeightToWidth(RTL_CONSTASCII_USTRINGPARAM("IsSyncHeightToWidth")),
1231 	sIsSyncWidthToHeight(RTL_CONSTASCII_USTRINGPARAM("IsSyncWidthToHeight")),
1232 	sNumberingRules(RTL_CONSTASCII_USTRINGPARAM("NumberingRules")),
1233 	sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType")),
1234 	sPageDescName(RTL_CONSTASCII_USTRINGPARAM("PageDescName")),
1235 	sPageStyleName(RTL_CONSTASCII_USTRINGPARAM("PageStyleName")),
1236 	sParaChapterNumberingLevel(RTL_CONSTASCII_USTRINGPARAM("ParaChapterNumberingLevel")),
1237 	sParaConditionalStyleName(RTL_CONSTASCII_USTRINGPARAM("ParaConditionalStyleName")),
1238 	sParagraphService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Paragraph")),
1239 	sParaStyleName(RTL_CONSTASCII_USTRINGPARAM("ParaStyleName")),
1240 	sPositionEndOfDoc(RTL_CONSTASCII_USTRINGPARAM("PositionEndOfDoc")),
1241 	sPrefix(RTL_CONSTASCII_USTRINGPARAM("Prefix")),
1242 	sRedline(RTL_CONSTASCII_USTRINGPARAM("Redline")),
1243 	sReferenceId(RTL_CONSTASCII_USTRINGPARAM("ReferenceId")),
1244 	sReferenceMark(RTL_CONSTASCII_USTRINGPARAM("ReferenceMark")),
1245 	sRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("RelativeHeight")),
1246 	sRelativeWidth(RTL_CONSTASCII_USTRINGPARAM("RelativeWidth")),
1247 	sRuby(RTL_CONSTASCII_USTRINGPARAM("Ruby")),
1248 	sRubyAdjust(RTL_CONSTASCII_USTRINGPARAM("RubyAdjust")),
1249 	sRubyCharStyleName(RTL_CONSTASCII_USTRINGPARAM("RubyCharStyleName")),
1250 	sRubyText(RTL_CONSTASCII_USTRINGPARAM("RubyText")),
1251 	sServerMap(RTL_CONSTASCII_USTRINGPARAM("ServerMap")),
1252 	sShapeService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Shape")),
1253 	sSizeType(RTL_CONSTASCII_USTRINGPARAM("SizeType")),
1254 	sSoftPageBreak( RTL_CONSTASCII_USTRINGPARAM( "SoftPageBreak" ) ),
1255 	sStartAt(RTL_CONSTASCII_USTRINGPARAM("StartAt")),
1256 	sSuffix(RTL_CONSTASCII_USTRINGPARAM("Suffix")),
1257 	sTableService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextTable")),
1258 	sText(RTL_CONSTASCII_USTRINGPARAM("Text")),
1259 	sTextContentService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextContent")),
1260 	sTextEmbeddedService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextEmbeddedObject")),
1261 	sTextEndnoteService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Endnote")),
1262 	sTextField(RTL_CONSTASCII_USTRINGPARAM("TextField")),
1263 	sTextFieldService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField")),
1264 	sTextFrameService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFrame")),
1265 	sTextGraphicService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextGraphicObject")),
1266 	sTextPortionType(RTL_CONSTASCII_USTRINGPARAM("TextPortionType")),
1267 	sTextSection(RTL_CONSTASCII_USTRINGPARAM("TextSection")),
1268 	sUnvisitedCharStyleName(RTL_CONSTASCII_USTRINGPARAM("UnvisitedCharStyleName")),
1269 	sVertOrient(RTL_CONSTASCII_USTRINGPARAM("VertOrient")),
1270 	sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition")),
1271 	sVisitedCharStyleName(RTL_CONSTASCII_USTRINGPARAM("VisitedCharStyleName")),
1272 	sWidth(RTL_CONSTASCII_USTRINGPARAM("Width")),
1273 	sWidthType( RTL_CONSTASCII_USTRINGPARAM( "WidthType" ) ),
1274 	sTextFieldStart( RTL_CONSTASCII_USTRINGPARAM( "TextFieldStart" ) ),
1275 	sTextFieldEnd( RTL_CONSTASCII_USTRINGPARAM( "TextFieldEnd" ) ),
1276 	sTextFieldStartEnd( RTL_CONSTASCII_USTRINGPARAM( "TextFieldStartEnd" ) ),
1277 	aCharStyleNamesPropInfoCache( sCharStyleNames )
1278 {
1279 	UniReference < XMLPropertySetMapper > xPropMapper(new XMLTextPropertySetMapper( TEXT_PROP_MAP_PARA ));
1280 	xParaPropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
1281 								   						  GetExport() );
1282 
1283 	OUString sFamily( GetXMLToken(XML_PARAGRAPH) );
1284 	OUString aPrefix( String( 'P' ) );
1285 	rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_PARAGRAPH, sFamily,
1286 							  xParaPropMapper, aPrefix );
1287 
1288 	xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT );
1289 	xTextPropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
1290 								   						  GetExport() );
1291 	sFamily = OUString( GetXMLToken(XML_TEXT) );
1292 	aPrefix = OUString( String( 'T' ) );
1293 	rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_TEXT, sFamily,
1294 							  xTextPropMapper, aPrefix );
1295 
1296 	xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_AUTO_FRAME );
1297 	xAutoFramePropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
1298 								   							   GetExport() );
1299 	sFamily = OUString( RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME) );
1300 	aPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM( "fr" ) );
1301 	rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_FRAME, sFamily,
1302 							  xAutoFramePropMapper, aPrefix );
1303 
1304 	xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_SECTION );
1305 	xSectionPropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
1306 															 GetExport() );
1307 	sFamily = OUString( GetXMLToken( XML_SECTION ) );
1308 	aPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM( "Sect" ) );
1309 	rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_SECTION, sFamily,
1310 							  xSectionPropMapper, aPrefix );
1311 
1312 	xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_RUBY );
1313 	xRubyPropMapper = new SvXMLExportPropertyMapper( xPropMapper );
1314 	sFamily = OUString( GetXMLToken( XML_RUBY ) );
1315 	aPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM( "Ru" ) );
1316 	rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_RUBY, sFamily,
1317 							  xRubyPropMapper, aPrefix );
1318 
1319 	xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_FRAME );
1320 	xFramePropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
1321 								   						   GetExport() );
1322 
1323 	pSectionExport = new XMLSectionExport( rExp, *this );
1324 	pIndexMarkExport = new XMLIndexMarkExport( rExp, *this );
1325 
1326     if( ! IsBlockMode() &&
1327         Reference<XRedlinesSupplier>( GetExport().GetModel(), UNO_QUERY ).is())
1328         pRedlineExport = new XMLRedlineExport( rExp );
1329 
1330 	// The text field helper needs a pre-constructed XMLPropertyState
1331 	// to export the combined characters field. We construct that
1332 	// here, because we need the text property mapper to do it.
1333 
1334 	// construct Any value, then find index
1335 	sal_Int32 nIndex = xTextPropMapper->getPropertySetMapper()->FindEntryIndex(
1336 								"", XML_NAMESPACE_STYLE,
1337                                 GetXMLToken(XML_TEXT_COMBINE));
1338     pFieldExport = new XMLTextFieldExport( rExp, new XMLPropertyState( nIndex, uno::makeAny(sal_True) ) );
1339 
1340     // --> OD 2008-05-08 #refactorlists#
1341     PushNewTextListsHelper();
1342     // <--
1343 }
1344 
~XMLTextParagraphExport()1345 XMLTextParagraphExport::~XMLTextParagraphExport()
1346 {
1347 	delete pHeadingStyles;
1348 	delete pRedlineExport;
1349 	delete pIndexMarkExport;
1350 	delete pSectionExport;
1351 	delete pFieldExport;
1352 	delete pListElements;
1353     // --> OD 2008-05-07 #refactorlists# - no longer needed
1354 //    delete pExportedLists;
1355     // <--
1356 	delete pListAutoPool;
1357 #ifdef DBG_UTIL
1358 	txtparae_bContainsIllegalCharacters = sal_False;
1359 #endif
1360     // --> OD 2008-04-25 #refactorlists#
1361     // also deletes <mpTextListsHelper>
1362     PopTextListsHelper();
1363     DBG_ASSERT( maTextListsHelperStack.size() == 0,
1364                 "misusage of text lists helper stack - it is not empty. Serious defect - please inform OD" );
1365     // <--
1366 }
1367 
CreateShapeExtPropMapper(SvXMLExport & rExport)1368 SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateShapeExtPropMapper(
1369 		SvXMLExport& rExport )
1370 {
1371 	UniReference < XMLPropertySetMapper > xPropMapper =
1372 		new XMLTextPropertySetMapper( TEXT_PROP_MAP_SHAPE );
1373 	return new XMLTextExportPropertySetMapper( xPropMapper, rExport );
1374 }
1375 
CreateCharExtPropMapper(SvXMLExport & rExport)1376 SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateCharExtPropMapper(
1377 		SvXMLExport& rExport)
1378 {
1379 	XMLPropertySetMapper *pPropMapper =
1380 		new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT );
1381 	return new XMLTextExportPropertySetMapper( pPropMapper, rExport );
1382 }
1383 
CreateParaExtPropMapper(SvXMLExport & rExport)1384 SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateParaExtPropMapper(
1385 		SvXMLExport& rExport)
1386 {
1387 	XMLPropertySetMapper *pPropMapper =
1388 		new XMLTextPropertySetMapper( TEXT_PROP_MAP_SHAPE_PARA );
1389 	return new XMLTextExportPropertySetMapper( pPropMapper, rExport );
1390 }
1391 
CreateParaDefaultExtPropMapper(SvXMLExport & rExport)1392 SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateParaDefaultExtPropMapper(
1393 		SvXMLExport& rExport)
1394 {
1395 	XMLPropertySetMapper *pPropMapper =
1396 		new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT_ADDITIONAL_DEFAULTS );
1397 	return new XMLTextExportPropertySetMapper( pPropMapper, rExport );
1398 }
1399 
exportPageFrames(sal_Bool bAutoStyles,sal_Bool bIsProgress)1400 void XMLTextParagraphExport::exportPageFrames( sal_Bool bAutoStyles,
1401 											   sal_Bool bIsProgress )
1402 {
1403     const TextContentSet* const pTexts = pBoundFrameSets->GetTexts()->GetPageBoundContents();
1404     const TextContentSet* const pGraphics = pBoundFrameSets->GetGraphics()->GetPageBoundContents();
1405     const TextContentSet* const pEmbeddeds = pBoundFrameSets->GetEmbeddeds()->GetPageBoundContents();
1406     const TextContentSet* const pShapes = pBoundFrameSets->GetShapes()->GetPageBoundContents();
1407     for(TextContentSet::const_iterator_t it = pTexts->getBegin();
1408         it != pTexts->getEnd();
1409         ++it)
1410         exportTextFrame(*it, bAutoStyles, bIsProgress, sal_True);
1411     for(TextContentSet::const_iterator_t it = pGraphics->getBegin();
1412         it != pGraphics->getEnd();
1413         ++it)
1414         exportTextGraphic(*it, bAutoStyles);
1415     for(TextContentSet::const_iterator_t it = pEmbeddeds->getBegin();
1416         it != pEmbeddeds->getEnd();
1417         ++it)
1418         exportTextEmbedded(*it, bAutoStyles);
1419     for(TextContentSet::const_iterator_t it = pShapes->getBegin();
1420         it != pShapes->getEnd();
1421         ++it)
1422         exportShape(*it, bAutoStyles);
1423 }
1424 
exportFrameFrames(sal_Bool bAutoStyles,sal_Bool bIsProgress,const Reference<XTextFrame> * pParentTxtFrame)1425 void XMLTextParagraphExport::exportFrameFrames(
1426 		sal_Bool bAutoStyles,
1427 		sal_Bool bIsProgress,
1428 		const Reference < XTextFrame > *pParentTxtFrame )
1429 {
1430     const TextContentSet* const pTexts = pBoundFrameSets->GetTexts()->GetFrameBoundContents(*pParentTxtFrame);
1431     if(pTexts)
1432         for(TextContentSet::const_iterator_t it = pTexts->getBegin();
1433             it != pTexts->getEnd();
1434             ++it)
1435             exportTextFrame(*it, bAutoStyles, bIsProgress, sal_True);
1436     const TextContentSet* const pGraphics = pBoundFrameSets->GetGraphics()->GetFrameBoundContents(*pParentTxtFrame);
1437     if(pGraphics)
1438         for(TextContentSet::const_iterator_t it = pGraphics->getBegin();
1439             it != pGraphics->getEnd();
1440             ++it)
1441             exportTextGraphic(*it, bAutoStyles);
1442     const TextContentSet* const pEmbeddeds = pBoundFrameSets->GetEmbeddeds()->GetFrameBoundContents(*pParentTxtFrame);
1443     if(pEmbeddeds)
1444         for(TextContentSet::const_iterator_t it = pEmbeddeds->getBegin();
1445             it != pEmbeddeds->getEnd();
1446             ++it)
1447             exportTextEmbedded(*it, bAutoStyles);
1448     const TextContentSet* const pShapes = pBoundFrameSets->GetShapes()->GetFrameBoundContents(*pParentTxtFrame);
1449     if(pShapes)
1450         for(TextContentSet::const_iterator_t it = pShapes->getBegin();
1451             it != pShapes->getEnd();
1452             ++it)
1453             exportShape(*it, bAutoStyles);
1454 }
1455 
1456 // bookmarks, reference marks (and TOC marks) are the same except for the
1457 // element names. We use the same method for export and it an array with
1458 // the proper element names
1459 static const enum XMLTokenEnum lcl_XmlReferenceElements[] = {
1460     XML_REFERENCE_MARK, XML_REFERENCE_MARK_START, XML_REFERENCE_MARK_END };
1461 static const enum XMLTokenEnum lcl_XmlBookmarkElements[] = {
1462     XML_BOOKMARK, XML_BOOKMARK_START, XML_BOOKMARK_END };
1463 
1464 // This function replaces the text portion iteration during auto style
1465 // collection.
collectTextAutoStylesOptimized(sal_Bool bIsProgress)1466 bool XMLTextParagraphExport::collectTextAutoStylesOptimized( sal_Bool bIsProgress )
1467 {
1468 	GetExport().GetShapeExport(); // make sure the graphics styles family is added
1469 
1470     const sal_Bool bAutoStyles = sal_True;
1471     const sal_Bool bExportContent = sal_False;
1472 
1473     // Export AutoStyles:
1474     Reference< XAutoStylesSupplier > xAutoStylesSupp( GetExport().GetModel(), UNO_QUERY );
1475     if ( xAutoStylesSupp.is() )
1476     {
1477         Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles();
1478         OUString sName;
1479         sal_uInt16 nFamily;
1480 
1481         for ( int i = 0; i < 3; ++i )
1482         {
1483             if ( 0 == i )
1484             {
1485                 sName = OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterStyles" ) );
1486                 nFamily = XML_STYLE_FAMILY_TEXT_TEXT;
1487             }
1488             else if ( 1 == i )
1489             {
1490                 sName = OUString( RTL_CONSTASCII_USTRINGPARAM( "RubyStyles" ) );
1491                 nFamily = XML_STYLE_FAMILY_TEXT_RUBY;
1492             }
1493             else
1494             {
1495                 sName = OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) );
1496                 nFamily = XML_STYLE_FAMILY_TEXT_PARAGRAPH;
1497             }
1498 
1499             Any aAny = xAutoStyleFamilies->getByName( sName );
1500             Reference< XAutoStyleFamily > xAutoStyles = *(Reference<XAutoStyleFamily>*)aAny.getValue();
1501             Reference < XEnumeration > xAutoStylesEnum( xAutoStyles->createEnumeration() );
1502 
1503             while ( xAutoStylesEnum->hasMoreElements() )
1504             {
1505                 aAny = xAutoStylesEnum->nextElement();
1506                 Reference< XAutoStyle > xAutoStyle = *(Reference<XAutoStyle>*)aAny.getValue();
1507                 Reference < XPropertySet > xPSet( xAutoStyle, uno::UNO_QUERY );
1508                 Add( nFamily, xPSet, 0, true );
1509             }
1510         }
1511     }
1512 
1513     // Export Field AutoStyles:
1514     Reference< XTextFieldsSupplier > xTextFieldsSupp( GetExport().GetModel(), UNO_QUERY );
1515     if ( xTextFieldsSupp.is() )
1516     {
1517         Reference< XEnumerationAccess > xTextFields = xTextFieldsSupp->getTextFields();
1518         Reference < XEnumeration > xTextFieldsEnum( xTextFields->createEnumeration() );
1519 
1520         while ( xTextFieldsEnum->hasMoreElements() )
1521         {
1522             Any aAny = xTextFieldsEnum->nextElement();
1523             Reference< XTextField > xTextField = *(Reference<XTextField>*)aAny.getValue();
1524             exportTextField( xTextField, bAutoStyles, bIsProgress,
1525                 !xAutoStylesSupp.is() );
1526 			try
1527 			{
1528 				Reference < XPropertySet > xSet( xTextField, UNO_QUERY );
1529 				Reference < XText > xText;
1530 				Any a = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("TextRange") );
1531 				a >>= xText;
1532 				if ( xText.is() )
1533                 {
1534 					exportText( xText, sal_True, bIsProgress, bExportContent );
1535                     GetExport().GetTextParagraphExport()
1536                         ->collectTextAutoStyles( xText );
1537                 }
1538 			}
1539 			catch (Exception&)
1540 			{
1541 			}
1542         }
1543     }
1544 
1545     // Export text frames:
1546     Reference<XEnumeration> xTextFramesEnum = pBoundFrameSets->GetTexts()->createEnumeration();
1547     if(xTextFramesEnum.is())
1548         while(xTextFramesEnum->hasMoreElements())
1549         {
1550             Reference<XTextContent> xTxtCntnt(xTextFramesEnum->nextElement(), UNO_QUERY);
1551             if(xTxtCntnt.is())
1552                 exportTextFrame(xTxtCntnt, bAutoStyles, bIsProgress, bExportContent, 0);
1553         }
1554 
1555     // Export graphic objects:
1556     Reference<XEnumeration> xGraphicsEnum = pBoundFrameSets->GetGraphics()->createEnumeration();
1557     if(xGraphicsEnum.is())
1558         while(xGraphicsEnum->hasMoreElements())
1559         {
1560             Reference<XTextContent> xTxtCntnt(xGraphicsEnum->nextElement(), UNO_QUERY);
1561             if(xTxtCntnt.is())
1562                 exportTextGraphic(xTxtCntnt, true, 0);
1563         }
1564 
1565     // Export embedded objects:
1566     Reference<XEnumeration> xEmbeddedsEnum = pBoundFrameSets->GetEmbeddeds()->createEnumeration();
1567     if(xEmbeddedsEnum.is())
1568         while(xEmbeddedsEnum->hasMoreElements())
1569         {
1570             Reference<XTextContent> xTxtCntnt(xEmbeddedsEnum->nextElement(), UNO_QUERY);
1571             if(xTxtCntnt.is())
1572                 exportTextEmbedded(xTxtCntnt, true, 0);
1573         }
1574 
1575     // Export shapes:
1576     Reference<XEnumeration> xShapesEnum = pBoundFrameSets->GetShapes()->createEnumeration();
1577     if(xShapesEnum.is())
1578         while(xShapesEnum->hasMoreElements())
1579         {
1580             Reference<XTextContent> xTxtCntnt(xShapesEnum->nextElement(), UNO_QUERY);
1581             if(xTxtCntnt.is())
1582             {
1583                 Reference<XServiceInfo> xServiceInfo(xTxtCntnt, UNO_QUERY);
1584                 if( xServiceInfo->supportsService(sShapeService))
1585                     exportShape(xTxtCntnt, true, 0);
1586             }
1587         }
1588 
1589     sal_Int32 nCount;
1590     // AutoStyles for sections
1591     Reference< XTextSectionsSupplier > xSectionsSupp( GetExport().GetModel(), UNO_QUERY );
1592     if ( xSectionsSupp.is() )
1593     {
1594         Reference< XIndexAccess > xSections( xSectionsSupp->getTextSections(), UNO_QUERY );
1595         if ( xSections.is() )
1596         {
1597             nCount = xSections->getCount();
1598             for( sal_Int32 i = 0; i < nCount; ++i )
1599             {
1600                 Any aAny = xSections->getByIndex( i );
1601                 Reference< XTextSection > xSection = *(Reference<XTextSection>*)aAny.getValue();
1602                 Reference < XPropertySet > xPSet( xSection, uno::UNO_QUERY );
1603                 Add( XML_STYLE_FAMILY_TEXT_SECTION, xPSet );
1604             }
1605         }
1606     }
1607 
1608     // AutoStyles for tables (Note: suppress autostyle collection for paragraphs in exportTable)
1609     Reference< XTextTablesSupplier > xTablesSupp( GetExport().GetModel(), UNO_QUERY );
1610     if ( xTablesSupp.is() )
1611     {
1612         Reference< XIndexAccess > xTables( xTablesSupp->getTextTables(), UNO_QUERY );
1613         if ( xTables.is() )
1614         {
1615             nCount = xTables->getCount();
1616             for( sal_Int32 i = 0; i < nCount; ++i )
1617             {
1618                 Any aAny = xTables->getByIndex( i );
1619                 Reference< XTextTable > xTable = *(Reference<XTextTable>*)aAny.getValue();
1620                 Reference < XTextContent > xTextContent( xTable, uno::UNO_QUERY );
1621                 exportTable( xTextContent, sal_True, sal_True );
1622             }
1623         }
1624     }
1625 
1626     Reference< XNumberingRulesSupplier > xNumberingRulesSupp( GetExport().GetModel(), UNO_QUERY );
1627     if ( xNumberingRulesSupp.is() )
1628     {
1629         Reference< XIndexAccess > xNumberingRules = xNumberingRulesSupp->getNumberingRules();
1630         nCount = xNumberingRules->getCount();
1631         // --> OD 2007-01-12 #i73361#
1632         const OUString sNumberingIsOutline( RTL_CONSTASCII_USTRINGPARAM( "NumberingIsOutline" ) );
1633         // <--
1634         for( sal_Int32 i = 0; i < nCount; ++i )
1635         {
1636             Reference< XIndexReplace > xNumRule( xNumberingRules->getByIndex( i ), UNO_QUERY );
1637             if( xNumRule.is() && xNumRule->getCount() )
1638             {
1639                 Reference < XNamed > xNamed( xNumRule, UNO_QUERY );
1640                 OUString sName;
1641                 if( xNamed.is() )
1642                     sName = xNamed->getName();
1643                 sal_Bool bAdd = !sName.getLength();
1644                 if( !bAdd )
1645                 {
1646                     Reference < XPropertySet > xNumPropSet( xNumRule,
1647                                                             UNO_QUERY );
1648                     const OUString sIsAutomatic( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) );
1649                     if( xNumPropSet.is() &&
1650                         xNumPropSet->getPropertySetInfo()
1651                                    ->hasPropertyByName( sIsAutomatic ) )
1652                     {
1653                         bAdd = *(sal_Bool *)xNumPropSet->getPropertyValue( sIsAutomatic ).getValue();
1654                         // --> OD 2007-01-12 #i73361# - check on outline style
1655                         if ( bAdd &&
1656                              xNumPropSet->getPropertySetInfo()
1657                                        ->hasPropertyByName( sNumberingIsOutline ) )
1658                         {
1659                             bAdd = !(*(sal_Bool *)xNumPropSet->getPropertyValue( sNumberingIsOutline ).getValue());
1660                         }
1661                         // <--
1662                     }
1663                     else
1664                     {
1665                         bAdd = sal_True;
1666                     }
1667                 }
1668                 if( bAdd )
1669                     pListAutoPool->Add( xNumRule );
1670             }
1671         }
1672     }
1673 
1674     return true;
1675 }
1676 
exportText(const Reference<XText> & rText,sal_Bool bAutoStyles,sal_Bool bIsProgress,sal_Bool bExportParagraph)1677 void XMLTextParagraphExport::exportText(
1678 		const Reference < XText > & rText,
1679 		sal_Bool bAutoStyles,
1680         sal_Bool bIsProgress,
1681 		sal_Bool bExportParagraph )
1682 {
1683 	if( bAutoStyles )
1684 		GetExport().GetShapeExport(); // make sure the graphics styles family
1685 									  // is added
1686 	Reference < XEnumerationAccess > xEA( rText, UNO_QUERY );
1687 	Reference < XEnumeration > xParaEnum(xEA->createEnumeration());
1688 	Reference < XPropertySet > xPropertySet( rText, UNO_QUERY );
1689 	Reference < XTextSection > xBaseSection;
1690 
1691 	// #97718# footnotes don't supply paragraph enumerations in some cases
1692 	// This is always a bug, but at least we don't want to crash.
1693 	DBG_ASSERT( xParaEnum.is(), "We need a paragraph enumeration" );
1694 	if( ! xParaEnum.is() )
1695 		return;
1696 
1697 	sal_Bool bExportLevels = sal_True;
1698 
1699 	if (xPropertySet.is())
1700 	{
1701 		Reference < XPropertySetInfo > xInfo ( xPropertySet->getPropertySetInfo() );
1702 
1703 		if( xInfo.is() )
1704 		{
1705 			if (xInfo->hasPropertyByName( sTextSection ))
1706 			{
1707 				xPropertySet->getPropertyValue(sTextSection) >>= xBaseSection ;
1708 			}
1709 
1710 /* #i35937#
1711 			// for applications that use the outliner we need to check if
1712 			// the current text object needs the level information exported
1713 			if( !bAutoStyles )
1714 			{
1715 				// fixme: move string to class member, couldn't do now because
1716 				//		  of no incompatible build
1717 				OUString sHasLevels( RTL_CONSTASCII_USTRINGPARAM("HasLevels") );
1718 				if (xInfo->hasPropertyByName( sHasLevels ) )
1719 				{
1720 					xPropertySet->getPropertyValue(sHasLevels) >>= bExportLevels;
1721 				}
1722 			}
1723 */
1724 		}
1725 	}
1726 
1727     // #96530# Export redlines at start & end of XText before & after
1728     // exporting the text content enumeration
1729     if( !bAutoStyles && (pRedlineExport != NULL) )
1730         pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_True );
1731 	exportTextContentEnumeration( xParaEnum, bAutoStyles, xBaseSection,
1732                                   bIsProgress, bExportParagraph, 0, bExportLevels );
1733     if( !bAutoStyles && (pRedlineExport != NULL) )
1734         pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_False );
1735 }
1736 
exportText(const Reference<XText> & rText,const Reference<XTextSection> & rBaseSection,sal_Bool bAutoStyles,sal_Bool bIsProgress,sal_Bool bExportParagraph)1737 void XMLTextParagraphExport::exportText(
1738 		const Reference < XText > & rText,
1739 		const Reference < XTextSection > & rBaseSection,
1740 		sal_Bool bAutoStyles,
1741 		sal_Bool bIsProgress,
1742 		sal_Bool bExportParagraph )
1743 {
1744 	if( bAutoStyles )
1745 		GetExport().GetShapeExport(); // make sure the graphics styles family
1746 									  // is added
1747 	Reference < XEnumerationAccess > xEA( rText, UNO_QUERY );
1748 	Reference < XEnumeration > xParaEnum(xEA->createEnumeration());
1749 
1750     // #98165# don't continue without a paragraph enumeration
1751     if( ! xParaEnum.is() )
1752         return;
1753 
1754     // #96530# Export redlines at start & end of XText before & after
1755     // exporting the text content enumeration
1756     Reference<XPropertySet> xPropertySet;
1757     if( !bAutoStyles && (pRedlineExport != NULL) )
1758     {
1759         xPropertySet.set(rText, uno::UNO_QUERY );
1760         pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_True );
1761     }
1762 	exportTextContentEnumeration( xParaEnum, bAutoStyles, rBaseSection,
1763 							      bIsProgress, bExportParagraph );
1764     if( !bAutoStyles && (pRedlineExport != NULL) )
1765         pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_False );
1766 }
1767 
exportTextContentEnumeration(const Reference<XEnumeration> & rContEnum,sal_Bool bAutoStyles,const Reference<XTextSection> & rBaseSection,sal_Bool bIsProgress,sal_Bool bExportParagraph,const Reference<XPropertySet> * pRangePropSet,sal_Bool bExportLevels)1768 sal_Bool XMLTextParagraphExport::exportTextContentEnumeration(
1769 		const Reference < XEnumeration > & rContEnum,
1770 		sal_Bool bAutoStyles,
1771 		const Reference < XTextSection > & rBaseSection,
1772 		sal_Bool bIsProgress,
1773 		sal_Bool bExportParagraph,
1774 		const Reference < XPropertySet > *pRangePropSet,
1775         sal_Bool bExportLevels )
1776 {
1777 	DBG_ASSERT( rContEnum.is(), "No enumeration to export!" );
1778 	sal_Bool bHasMoreElements = rContEnum->hasMoreElements();
1779 	if( !bHasMoreElements )
1780 		return sal_False;
1781 
1782 	XMLTextNumRuleInfo aPrevNumInfo;
1783 	XMLTextNumRuleInfo aNextNumInfo;
1784 
1785     sal_Bool bHasContent = sal_False;
1786 	Reference<XTextSection> xCurrentTextSection(rBaseSection);
1787 
1788     MultiPropertySetHelper aPropSetHelper(
1789 		   					bAutoStyles ? aParagraphPropertyNamesAuto :
1790 										  aParagraphPropertyNames );
1791 
1792 	sal_Bool bHoldElement = sal_False;
1793 	Reference < XTextContent > xTxtCntnt;
1794 	while( bHoldElement || bHasMoreElements )
1795 	{
1796 		if (bHoldElement)
1797 		{
1798 			bHoldElement = sal_False;
1799 		}
1800 		else
1801 		{
1802             xTxtCntnt.set(rContEnum->nextElement(), uno::UNO_QUERY);
1803 
1804 			aPropSetHelper.resetValues();
1805 
1806 		}
1807 
1808 		Reference<XServiceInfo> xServiceInfo( xTxtCntnt, UNO_QUERY );
1809 		if( xServiceInfo->supportsService( sParagraphService ) )
1810 		{
1811 			if( bExportLevels )
1812 			{
1813 				if( bAutoStyles )
1814 				{
1815 					exportListAndSectionChange( xCurrentTextSection, xTxtCntnt,
1816 												aPrevNumInfo, aNextNumInfo,
1817 												bAutoStyles );
1818 				}
1819 				else
1820 				{
1821                     // --> OD 2006-09-27 #i69627#
1822                     // --> OD 2008-04-24 #refactorlists#
1823                     // pass list auto style pool to <XMLTextNumRuleInfo> instance
1824                     // --> OD 2008-11-26 #158694#
1825                     // pass info about request to export <text:number> element
1826                     // to <XMLTextNumRuleInfo> instance
1827                     aNextNumInfo.Set( xTxtCntnt,
1828                                       GetExport().writeOutlineStyleAsNormalListStyle(),
1829                                       GetListAutoStylePool(),
1830                                       GetExport().exportTextNumberElement() );
1831                     // <--
1832 
1833 					exportListAndSectionChange( xCurrentTextSection, aPropSetHelper,
1834 												TEXT_SECTION, xTxtCntnt,
1835 												aPrevNumInfo, aNextNumInfo,
1836 												bAutoStyles );
1837 				}
1838 			}
1839 
1840 			// if we found a mute section: skip all section content
1841 			if (pSectionExport->IsMuteSection(xCurrentTextSection))
1842 			{
1843 				// Make sure headings are exported anyway.
1844 				if( !bAutoStyles )
1845 					pSectionExport->ExportMasterDocHeadingDummies();
1846 
1847 				while (rContEnum->hasMoreElements() &&
1848 					   pSectionExport->IsInSection( xCurrentTextSection,
1849 													xTxtCntnt, sal_True ))
1850 				{
1851                     xTxtCntnt.set(rContEnum->nextElement(), uno::UNO_QUERY);
1852 					aPropSetHelper.resetValues();
1853 					aNextNumInfo.Reset();
1854 				}
1855 				// the first non-mute element still needs to be processed
1856 				bHoldElement =
1857 					! pSectionExport->IsInSection( xCurrentTextSection,
1858 												   xTxtCntnt, sal_False );
1859 			}
1860 			else
1861                 exportParagraph( xTxtCntnt, bAutoStyles, bIsProgress,
1862                                  bExportParagraph, aPropSetHelper );
1863             bHasContent = sal_True;
1864 		}
1865 		else if( xServiceInfo->supportsService( sTableService ) )
1866 		{
1867 			if( !bAutoStyles )
1868 			{
1869 				aNextNumInfo.Reset();
1870 			}
1871 
1872 			exportListAndSectionChange( xCurrentTextSection, xTxtCntnt,
1873 										aPrevNumInfo, aNextNumInfo,
1874 										bAutoStyles );
1875 
1876 			if (! pSectionExport->IsMuteSection(xCurrentTextSection))
1877 			{
1878 				// export start + end redlines (for wholly redlined tables)
1879 				if ((! bAutoStyles) && (NULL != pRedlineExport))
1880 					pRedlineExport->ExportStartOrEndRedline(xTxtCntnt, sal_True);
1881 
1882 				exportTable( xTxtCntnt, bAutoStyles, bIsProgress  );
1883 
1884 				if ((! bAutoStyles) && (NULL != pRedlineExport))
1885 					pRedlineExport->ExportStartOrEndRedline(xTxtCntnt, sal_False);
1886 			}
1887 			else if( !bAutoStyles )
1888 			{
1889 				// Make sure headings are exported anyway.
1890 				pSectionExport->ExportMasterDocHeadingDummies();
1891 			}
1892 
1893 			bHasContent = sal_True;
1894 		}
1895 		else if( xServiceInfo->supportsService( sTextFrameService ) )
1896 		{
1897             exportTextFrame( xTxtCntnt, bAutoStyles, bIsProgress, sal_True, pRangePropSet );
1898         }
1899 		else if( xServiceInfo->supportsService( sTextGraphicService ) )
1900 		{
1901 			exportTextGraphic( xTxtCntnt, bAutoStyles, pRangePropSet );
1902 		}
1903 		else if( xServiceInfo->supportsService( sTextEmbeddedService ) )
1904 		{
1905 			exportTextEmbedded( xTxtCntnt, bAutoStyles, pRangePropSet );
1906 		}
1907 		else if( xServiceInfo->supportsService( sShapeService ) )
1908 		{
1909 			exportShape( xTxtCntnt, bAutoStyles, pRangePropSet );
1910 		}
1911 		else
1912 		{
1913 			DBG_ASSERT( !xTxtCntnt.is(), "unknown text content" );
1914 		}
1915 
1916 		if( !bAutoStyles )
1917 		{
1918 			aPrevNumInfo = aNextNumInfo;
1919 		}
1920 
1921 		bHasMoreElements = rContEnum->hasMoreElements();
1922 	}
1923 
1924 	if( bExportLevels && bHasContent && !bAutoStyles )
1925 	{
1926 		aNextNumInfo.Reset();
1927 
1928 		// close open lists and sections; no new styles
1929 		exportListAndSectionChange( xCurrentTextSection, rBaseSection,
1930 									aPrevNumInfo, aNextNumInfo,
1931 									bAutoStyles );
1932 	}
1933 
1934 	return sal_True;
1935 }
1936 
exportParagraph(const Reference<XTextContent> & rTextContent,sal_Bool bAutoStyles,sal_Bool bIsProgress,sal_Bool bExportParagraph,MultiPropertySetHelper & rPropSetHelper)1937 void XMLTextParagraphExport::exportParagraph(
1938 		const Reference < XTextContent > & rTextContent,
1939         sal_Bool bAutoStyles, sal_Bool bIsProgress, sal_Bool bExportParagraph,
1940         MultiPropertySetHelper& rPropSetHelper)
1941 {
1942 	sal_Int16 nOutlineLevel = -1;
1943 
1944 	if( bIsProgress )
1945 	{
1946 		ProgressBarHelper *pProgress = GetExport().GetProgressBarHelper();
1947 		pProgress->SetValue( pProgress->GetValue()+1 );
1948 	}
1949 
1950 	// get property set or multi property set and initialize helper
1951 	Reference<XMultiPropertySet> xMultiPropSet( rTextContent, UNO_QUERY );
1952 	Reference<XPropertySet> xPropSet( rTextContent, UNO_QUERY );
1953 
1954 	// check for supported properties
1955     if( !rPropSetHelper.checkedProperties() )
1956 		rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
1957 
1958 //	if( xMultiPropSet.is() )
1959 //		rPropSetHelper.getValues( xMultiPropSet );
1960 //	else
1961 //		rPropSetHelper.getValues( xPropSet );
1962 
1963 	if( bExportParagraph )
1964 	{
1965 		if( bAutoStyles )
1966 		{
1967 			Add( XML_STYLE_FAMILY_TEXT_PARAGRAPH, rPropSetHelper, xPropSet );
1968 		}
1969 		else
1970 		{
1971             // xml:id for RDF metadata
1972             GetExport().AddAttributeXmlId(rTextContent);
1973             GetExport().AddAttributesRDFa(rTextContent);
1974 
1975 			OUString sStyle;
1976 			if( rPropSetHelper.hasProperty( PARA_STYLE_NAME ) )
1977 			{
1978 				if( xMultiPropSet.is() )
1979 					rPropSetHelper.getValue( PARA_STYLE_NAME,
1980 													xMultiPropSet ) >>= sStyle;
1981 				else
1982 					rPropSetHelper.getValue( PARA_STYLE_NAME,
1983 													xPropSet ) >>= sStyle;
1984 			}
1985 
1986 			Reference< XInterface > xRef( rTextContent, UNO_QUERY );
1987 			if( xRef.is() )
1988 			{
1989 				const OUString& rIdentifier = GetExport().getInterfaceToIdentifierMapper().getIdentifier( xRef );
1990 				if( rIdentifier.getLength() )
1991                 {
1992                     // FIXME: this is just temporary until EditEngine
1993                     // paragraphs implement XMetadatable.
1994                     // then that must be used and not the mapper, because
1995                     // when both can be used we get two xml:id!
1996                     uno::Reference<rdf::XMetadatable> const xMeta(xRef,
1997                         uno::UNO_QUERY);
1998                     OSL_ENSURE(!xMeta.is(), "paragraph that implements "
1999                         "XMetadatable used in interfaceToIdentifierMapper?");
2000                     GetExport().AddAttributeIdLegacy(XML_NAMESPACE_TEXT,
2001                         rIdentifier);
2002                 }
2003 			}
2004 
2005 			OUString sAutoStyle( sStyle );
2006 			sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_PARAGRAPH, xPropSet, sStyle );
2007 			if( sAutoStyle.getLength() )
2008 				GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
2009 							  GetExport().EncodeStyleName( sAutoStyle ) );
2010 
2011 			if( rPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME ) )
2012 			{
2013 				OUString sCondStyle;
2014 				if( xMultiPropSet.is() )
2015 					rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME,
2016 												 	xMultiPropSet ) >>= sCondStyle;
2017 				else
2018 					rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME,
2019 												 	xPropSet ) >>= sCondStyle;
2020 				if( sCondStyle != sStyle )
2021 				{
2022 					sCondStyle = Find( XML_STYLE_FAMILY_TEXT_PARAGRAPH, xPropSet,
2023 								   	   sCondStyle );
2024 					if( sCondStyle.getLength() )
2025 						GetExport().AddAttribute( XML_NAMESPACE_TEXT,
2026 												  XML_COND_STYLE_NAME,
2027 							  GetExport().EncodeStyleName( sCondStyle ) );
2028 				}
2029 			}
2030 
2031 			//if( rPropSetHelper.hasProperty( PARA_CHAPTER_NUMERBING_LEVEL ) )	//#outline level,zhaojianwei
2032 			if( rPropSetHelper.hasProperty( PARA_OUTLINE_LEVEL ) )				//<-end
2033 			{
2034 				if( xMultiPropSet.is() )
2035 					//rPropSetHelper.getValue( PARA_CHAPTER_NUMERBING_LEVEL,	//#outline level,zhaojianwei
2036 					rPropSetHelper.getValue( PARA_OUTLINE_LEVEL,				//<-end
2037 												 	xMultiPropSet ) >>= nOutlineLevel;
2038 				else
2039 					//rPropSetHelper.getValue( PARA_CHAPTER_NUMERBING_LEVEL,	//#outline level,zhaojianwei
2040 					rPropSetHelper.getValue( PARA_OUTLINE_LEVEL,				//<-end
2041 												 	xPropSet ) >>= nOutlineLevel;
2042 
2043 				//if( -1 != nOutlineLevel )	//#outline level,zhaojianwei
2044 				if( 0 < nOutlineLevel )	//<-end,zhaojianwei
2045 				{
2046 					OUStringBuffer sTmp;
2047 					//sTmp.append( sal_Int32( nOutlineLevel + 1 ) );	//#outline level,zhaojianwei
2048 					sTmp.append( sal_Int32( nOutlineLevel) );		//<-end,zhaojianwei
2049 					GetExport().AddAttribute( XML_NAMESPACE_TEXT,
2050 											  XML_OUTLINE_LEVEL,
2051 								  sTmp.makeStringAndClear() );
2052 
2053                     if( rPropSetHelper.hasProperty( NUMBERING_IS_NUMBER ) )
2054                     {
2055                         bool bIsNumber = false;
2056                         if( xMultiPropSet.is() )
2057                             rPropSetHelper.getValue(
2058                                        NUMBERING_IS_NUMBER, xMultiPropSet ) >>= bIsNumber;
2059                         else
2060                             rPropSetHelper.getValue(
2061                                        NUMBERING_IS_NUMBER, xPropSet ) >>= bIsNumber;
2062 
2063                         OUString sListStyleName;
2064                         if( xMultiPropSet.is() )
2065                             rPropSetHelper.getValue(
2066                                        PARA_NUMBERING_STYLENAME, xMultiPropSet ) >>= sListStyleName;
2067                         else
2068                             rPropSetHelper.getValue(
2069                                        PARA_NUMBERING_STYLENAME, xPropSet ) >>= sListStyleName;
2070 
2071 
2072 
2073 				        bool bAssignedtoOutlineStyle = false;//#outline level,add by zhaojianwei
2074 						{
2075                             Reference< XChapterNumberingSupplier > xCNSupplier( GetExport().GetModel(), UNO_QUERY );
2076 
2077                             OUString sOutlineName;
2078                             if (xCNSupplier.is())
2079                             {
2080                                 Reference< XIndexReplace > xNumRule ( xCNSupplier->getChapterNumberingRules() );
2081                                 DBG_ASSERT( xNumRule.is(), "no chapter numbering rules" );
2082 
2083                                 if (xNumRule.is())
2084                                 {
2085                                     Reference< XPropertySet > xNumRulePropSet( xNumRule, UNO_QUERY );
2086                                     xNumRulePropSet->getPropertyValue(
2087 										OUString(RTL_CONSTASCII_USTRINGPARAM("Name")) ) >>= sOutlineName;
2088                                     bAssignedtoOutlineStyle = ( sListStyleName == sOutlineName );
2089                                 }
2090 							}
2091 
2092 						}	//<end,zhaojianwei
2093 
2094 						//if( ! bIsNumber )			//#outline level,removed by zhaojianwei
2095 						if( ! bIsNumber && bAssignedtoOutlineStyle )	//#outline level,add by zhaojianwei
2096                             GetExport().AddAttribute( XML_NAMESPACE_TEXT,
2097                                                       XML_IS_LIST_HEADER,
2098                                                       XML_TRUE );
2099                     }
2100 
2101                     {
2102                         String sParaIsNumberingRestart
2103                             (RTL_CONSTASCII_USTRINGPARAM
2104                              ("ParaIsNumberingRestart"));
2105                         bool bIsRestartNumbering = false;
2106 
2107                         Reference< XPropertySetInfo >
2108                         xPropSetInfo(xMultiPropSet.is() ?
2109                                      xMultiPropSet->getPropertySetInfo():
2110                                      xPropSet->getPropertySetInfo());
2111 
2112                         if (xPropSetInfo->
2113                             hasPropertyByName(sParaIsNumberingRestart))
2114                         {
2115                             xPropSet->getPropertyValue(sParaIsNumberingRestart)
2116                                 >>= bIsRestartNumbering;
2117                         }
2118 
2119                         if (bIsRestartNumbering)
2120                         {
2121                             GetExport().AddAttribute(XML_NAMESPACE_TEXT,
2122                                                      XML_RESTART_NUMBERING,
2123                                                      XML_TRUE);
2124 
2125                             String sNumberingStartValue
2126                                 (RTL_CONSTASCII_USTRINGPARAM
2127                                  ("NumberingStartValue"));
2128 
2129 
2130                             sal_Int32 nStartValue = 0;
2131 
2132                             if (xPropSetInfo->
2133                                 hasPropertyByName(sNumberingStartValue))
2134                             {
2135                                 xPropSet->getPropertyValue(sNumberingStartValue)
2136                                     >>= nStartValue;
2137 
2138                                 OUStringBuffer sTmpStartValue;
2139 
2140                                 sTmpStartValue.append(nStartValue);
2141 
2142                                 GetExport().
2143                                     AddAttribute(XML_NAMESPACE_TEXT,
2144                                                  XML_START_VALUE,
2145                                                  sTmpStartValue.
2146                                                  makeStringAndClear());
2147                             }
2148                         }
2149                     }
2150 				}
2151 			}
2152 		}
2153 	}
2154 
2155 	Reference < XEnumerationAccess > xEA( rTextContent, UNO_QUERY );
2156 	Reference < XEnumeration > xTextEnum;
2157     xTextEnum = xEA->createEnumeration();
2158     const sal_Bool bHasPortions = xTextEnum.is();
2159 
2160 	Reference < XEnumeration> xContentEnum;
2161 	Reference < XContentEnumerationAccess > xCEA( rTextContent, UNO_QUERY );
2162 	if( xCEA.is() )
2163 		xContentEnum.set(xCEA->createContentEnumeration( sTextContentService ));
2164 	const sal_Bool bHasContentEnum = xContentEnum.is() &&
2165 	   	                             xContentEnum->hasMoreElements();
2166 
2167 	Reference < XTextSection > xSection;
2168 	if( bHasContentEnum )
2169 	{
2170 		// For the auto styles, the multi property set helper is only used
2171 		// if hard attributes are existing. Therfor, it seems to be a better
2172 		// strategy to have the TextSection property seperate, because otherwise
2173 		// we always retrieve the style names even if they are not required.
2174 		if( bAutoStyles )
2175 		{
2176 			if( xPropSet->getPropertySetInfo()->hasPropertyByName( sTextSection ) )
2177 			{
2178                 xSection.set(xPropSet->getPropertyValue( sTextSection ), uno::UNO_QUERY);
2179 			}
2180 		}
2181 		else
2182 		{
2183 			if( rPropSetHelper.hasProperty( TEXT_SECTION ) )
2184 			{
2185                 xSection.set(rPropSetHelper.getValue( TEXT_SECTION ), uno::UNO_QUERY);
2186 			}
2187 		}
2188 	}
2189 
2190 	if( bAutoStyles )
2191 	{
2192 		sal_Bool bPrevCharIsSpace = sal_True;
2193 		if( bHasContentEnum )
2194 			bPrevCharIsSpace = !exportTextContentEnumeration(
2195 									xContentEnum, bAutoStyles, xSection,
2196                                     bIsProgress, sal_True, 0, sal_True );
2197 		if ( bHasPortions )
2198             exportTextRangeEnumeration( xTextEnum, bAutoStyles, bIsProgress );
2199     }
2200 	else
2201 	{
2202 		sal_Bool bPrevCharIsSpace = sal_True;
2203 		enum XMLTokenEnum eElem =
2204 			//-1 == nOutlineLevel ? XML_P : XML_H;	//#outline level,zhaojianwei
2205 			0 < nOutlineLevel ? XML_H : XML_P;	//<-end,zhaojianwei
2206 		SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, eElem,
2207 								  sal_True, sal_False );
2208 		if( bHasContentEnum )
2209 			bPrevCharIsSpace = !exportTextContentEnumeration(
2210 									xContentEnum, bAutoStyles, xSection,
2211 									bIsProgress );
2212 		exportTextRangeEnumeration( xTextEnum, bAutoStyles, bIsProgress,
2213 								 	bPrevCharIsSpace );
2214 	}
2215 }
2216 
exportTextRangeEnumeration(const Reference<XEnumeration> & rTextEnum,sal_Bool bAutoStyles,sal_Bool bIsProgress,sal_Bool bPrvChrIsSpc)2217 void XMLTextParagraphExport::exportTextRangeEnumeration(
2218     const Reference < XEnumeration > & rTextEnum,
2219     sal_Bool bAutoStyles,
2220     sal_Bool bIsProgress,
2221     sal_Bool bPrvChrIsSpc )
2222 {
2223     static OUString sMeta(RTL_CONSTASCII_USTRINGPARAM("InContentMetadata"));
2224     static OUString sAnnotation(RTL_CONSTASCII_USTRINGPARAM("Annotation"));
2225     static OUString sAnnotationEnd(RTL_CONSTASCII_USTRINGPARAM("AnnotationEnd"));
2226 
2227     sal_Bool bPrevCharIsSpace = bPrvChrIsSpc;
2228 
2229     while( rTextEnum->hasMoreElements() )
2230     {
2231         Reference<XPropertySet> xPropSet(rTextEnum->nextElement(), UNO_QUERY);
2232         Reference < XTextRange > xTxtRange(xPropSet, uno::UNO_QUERY);
2233         Reference<XPropertySetInfo> xPropInfo(xPropSet->getPropertySetInfo());
2234 
2235         if (xPropInfo->hasPropertyByName(sTextPortionType))
2236         {
2237             rtl::OUString sType;
2238             xPropSet->getPropertyValue(sTextPortionType) >>= sType;
2239 
2240             if( sType.equals(sText))
2241             {
2242                 exportTextRange( xTxtRange, bAutoStyles, bPrevCharIsSpace );
2243             }
2244             else if( sType.equals(sTextField))
2245             {
2246                 exportTextField( xTxtRange, bAutoStyles, bIsProgress );
2247                 bPrevCharIsSpace = false;
2248             }
2249             else if ( sType.equals( sAnnotation ) )
2250             {
2251                 exportTextField( xTxtRange, bAutoStyles, bIsProgress );
2252                 bPrevCharIsSpace = false;
2253             }
2254             else if ( sType.equals( sAnnotationEnd ) )
2255             {
2256                 Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
2257                 const OUString& rName = xBookmark->getName();
2258                 if ( rName.getLength() > 0 )
2259                 {
2260                     GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_NAME, rName);
2261                 }
2262                 SvXMLElementExport aElem( GetExport(), !bAutoStyles, XML_NAMESPACE_OFFICE, XML_ANNOTATION_END, sal_False, sal_False );
2263             }
2264             else if( sType.equals( sFrame ) )
2265             {
2266                 Reference < XEnumeration> xContentEnum;
2267                 Reference < XContentEnumerationAccess > xCEA( xTxtRange, UNO_QUERY );
2268                 if( xCEA.is() )
2269                     xContentEnum.set(xCEA->createContentEnumeration( sTextContentService ));
2270                 // frames are never in sections
2271                 Reference<XTextSection> xSection;
2272                 if( xContentEnum.is() )
2273                     exportTextContentEnumeration(
2274                     xContentEnum,
2275                     bAutoStyles,
2276                     xSection,
2277                     bIsProgress,
2278                     sal_True,
2279                     &xPropSet );
2280 
2281                 bPrevCharIsSpace = sal_False;
2282             }
2283             else if (sType.equals(sFootnote))
2284             {
2285                 exportTextFootnote( xPropSet, xTxtRange->getString(), bAutoStyles, bIsProgress );
2286                 bPrevCharIsSpace = sal_False;
2287             }
2288             else if (sType.equals(sBookmark))
2289             {
2290                 exportTextMark( xPropSet, sBookmark, lcl_XmlBookmarkElements, bAutoStyles );
2291             }
2292             else if (sType.equals(sReferenceMark))
2293             {
2294                 exportTextMark( xPropSet, sReferenceMark, lcl_XmlReferenceElements, bAutoStyles);
2295             }
2296             else if (sType.equals(sDocumentIndexMark))
2297             {
2298                 pIndexMarkExport->ExportIndexMark( xPropSet, bAutoStyles);
2299             }
2300             else if (sType.equals(sRedline))
2301             {
2302                 if (NULL != pRedlineExport)
2303                     pRedlineExport->ExportChange( xPropSet, bAutoStyles );
2304             }
2305             else if (sType.equals(sRuby))
2306             {
2307                 exportRuby( xPropSet, bAutoStyles );
2308             }
2309             else if (sType.equals(sMeta))
2310             {
2311                 exportMeta( xPropSet, bAutoStyles, bIsProgress );
2312             }
2313             else if (sType.equals(sTextFieldStart))
2314             {
2315                 Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
2316                 if (xBookmark.is())
2317                 {
2318                     GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
2319                 }
2320 
2321                 Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
2322                 if (xFormField.is())
2323                 {
2324                     GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType());
2325                 }
2326 
2327                 GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, sal_False);
2328                 if (xFormField.is())
2329                 {
2330                     FieldParamExporter(&GetExport(), xFormField->getParameters()).Export();
2331                 }
2332                 GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, sal_False);
2333             }
2334             else if (sType.equals(sTextFieldEnd))
2335             {
2336                 GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_END, sal_False);
2337                 GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_END, sal_False);
2338             }
2339             else if (sType.equals(sTextFieldStartEnd))
2340             {
2341                 Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
2342                 if (xBookmark.is())
2343                 {
2344                     GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
2345                 }
2346                 Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
2347                 if (xFormField.is())
2348                 {
2349                     GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType());
2350                 }
2351                 GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, sal_False);
2352                 if (xFormField.is())
2353                 {
2354                     FieldParamExporter(&GetExport(), xFormField->getParameters()).Export();
2355                 }
2356                 GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, sal_False);
2357             }
2358             else if (sType.equals(sSoftPageBreak))
2359             {
2360                 exportSoftPageBreak(xPropSet,	bAutoStyles);
2361             }
2362             else {
2363                 DBG_ERROR("unknown text portion type");
2364             }
2365         }
2366         else
2367         {
2368             Reference<XServiceInfo> xServiceInfo( xTxtRange, UNO_QUERY );
2369             if( xServiceInfo->supportsService( sTextFieldService ) )
2370             {
2371                 exportTextField( xTxtRange, bAutoStyles, bIsProgress );
2372                 bPrevCharIsSpace = sal_False;
2373             }
2374             else
2375             {
2376                 // no TextPortionType property -> non-Writer app -> text
2377                 exportTextRange( xTxtRange, bAutoStyles, bPrevCharIsSpace );
2378             }
2379         }
2380     }
2381 
2382 // now that there are nested enumerations for meta(-field), this may be valid!
2383 //	DBG_ASSERT( !bOpenRuby, "Red Alert: Ruby still open!" );
2384 }
2385 
exportTable(const Reference<XTextContent> &,sal_Bool,sal_Bool)2386 void XMLTextParagraphExport::exportTable(
2387 		const Reference < XTextContent > &,
2388 		sal_Bool /*bAutoStyles*/, sal_Bool /*bIsProgress*/ )
2389 {
2390 }
2391 
exportTextField(const Reference<XTextRange> & rTextRange,sal_Bool bAutoStyles,sal_Bool bIsProgress)2392 void XMLTextParagraphExport::exportTextField(
2393 		const Reference < XTextRange > & rTextRange,
2394         sal_Bool bAutoStyles, sal_Bool bIsProgress )
2395 {
2396 	Reference < XPropertySet > xPropSet( rTextRange, UNO_QUERY );
2397 	// non-Writer apps need not support Property TextField, so test first
2398 	if (xPropSet->getPropertySetInfo()->hasPropertyByName( sTextField ))
2399 	{
2400         Reference < XTextField > xTxtFld(xPropSet->getPropertyValue( sTextField ), uno::UNO_QUERY);
2401 		DBG_ASSERT( xTxtFld.is(), "text field missing" );
2402 		if( xTxtFld.is() )
2403 		{
2404             exportTextField(xTxtFld, bAutoStyles, bIsProgress, sal_True);
2405 		}
2406 		else
2407 		{
2408 			// write only characters
2409 			GetExport().Characters(rTextRange->getString());
2410 		}
2411 	}
2412 }
2413 
exportTextField(const Reference<XTextField> & xTextField,const sal_Bool bAutoStyles,const sal_Bool bIsProgress,const sal_Bool bRecursive)2414 void XMLTextParagraphExport::exportTextField(
2415         const Reference < XTextField > & xTextField,
2416         const sal_Bool bAutoStyles, const sal_Bool bIsProgress,
2417         const sal_Bool bRecursive )
2418 {
2419     if ( bAutoStyles )
2420     {
2421         pFieldExport->ExportFieldAutoStyle( xTextField, bIsProgress,
2422                 bRecursive );
2423     }
2424     else
2425     {
2426         pFieldExport->ExportField( xTextField, bIsProgress );
2427     }
2428 }
2429 
exportSoftPageBreak(const Reference<XPropertySet> &,sal_Bool)2430 void XMLTextParagraphExport::exportSoftPageBreak(
2431 	const Reference<XPropertySet> & ,
2432 	sal_Bool )
2433 {
2434     SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
2435                               XML_SOFT_PAGE_BREAK, sal_False,
2436                               sal_False );
2437 }
2438 
exportTextMark(const Reference<XPropertySet> & rPropSet,const OUString sProperty,const enum XMLTokenEnum pElements[],sal_Bool bAutoStyles)2439 void XMLTextParagraphExport::exportTextMark(
2440 	const Reference<XPropertySet> & rPropSet,
2441 	const OUString sProperty,
2442 	const enum XMLTokenEnum pElements[],
2443 	sal_Bool bAutoStyles)
2444 {
2445 	// mib said: "Hau wech!"
2446 	//
2447 	// (Originally, I'd export a span element in case the (book|reference)mark
2448 	//	was formatted. This actually makes a difference in case some pervert
2449 	//	sets a point reference mark in the document and, say, formats it bold.
2450 	//  This basically meaningless formatting will now been thrown away
2451 	//	(aka cleaned up), since mib said: ...					dvo
2452 
2453  	if (!bAutoStyles)
2454 	{
2455 		// name element
2456 		Reference<XNamed> xName(rPropSet->getPropertyValue(sProperty), UNO_QUERY);
2457 		GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME,
2458 								 xName->getName());
2459 
2460 		// start, end, or point-reference?
2461 		sal_Int8 nElement;
2462 		if( *(sal_Bool *)rPropSet->getPropertyValue(sIsCollapsed).getValue() )
2463 		{
2464 			nElement = 0;
2465 		}
2466 		else
2467 		{
2468 			nElement = *(sal_Bool *)rPropSet->getPropertyValue(sIsStart).getValue() ? 1 : 2;
2469 		}
2470 
2471         // bookmark, bookmark-start: xml:id and RDFa for RDF metadata
2472         if( nElement < 2 ) {
2473             GetExport().AddAttributeXmlId(xName);
2474             const uno::Reference<text::XTextContent> xTextContent(
2475                     xName, uno::UNO_QUERY_THROW);
2476             GetExport().AddAttributesRDFa(xTextContent);
2477         }
2478 
2479 		// export element
2480 		DBG_ASSERT(pElements != NULL, "illegal element array");
2481 		DBG_ASSERT(nElement >= 0, "illegal element number");
2482 		DBG_ASSERT(nElement <= 2, "illegal element number");
2483 		SvXMLElementExport aElem(GetExport(),
2484 								 XML_NAMESPACE_TEXT, pElements[nElement],
2485 								 sal_False, sal_False);
2486 	}
2487 	// else: no styles. (see above)
2488 }
2489 
lcl_txtpara_isBoundAsChar(const Reference<XPropertySet> & rPropSet,const Reference<XPropertySetInfo> & rPropSetInfo)2490 sal_Bool lcl_txtpara_isBoundAsChar(
2491 		const Reference < XPropertySet > & rPropSet,
2492 		const Reference < XPropertySetInfo > & rPropSetInfo )
2493 {
2494 	sal_Bool bIsBoundAsChar = sal_False;
2495 	OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) );
2496 	if( rPropSetInfo->hasPropertyByName( sAnchorType ) )
2497 	{
2498 		TextContentAnchorType eAnchor;
2499 		rPropSet->getPropertyValue( sAnchorType ) >>= eAnchor;
2500 		bIsBoundAsChar = TextContentAnchorType_AS_CHARACTER == eAnchor;
2501 	}
2502 
2503 	return bIsBoundAsChar;
2504 }
2505 
addTextFrameAttributes(const Reference<XPropertySet> & rPropSet,sal_Bool bShape,OUString * pMinHeightValue)2506 sal_Int32 XMLTextParagraphExport::addTextFrameAttributes(
2507 	const Reference < XPropertySet >& rPropSet,
2508 	sal_Bool bShape,
2509 	OUString *pMinHeightValue )
2510 {
2511 	sal_Int32 nShapeFeatures = SEF_DEFAULT;
2512 
2513 	// draw:name (#97662#: not for shapes, since those names will be
2514 	// treated in the shape export)
2515     if( !bShape )
2516     {
2517         Reference < XNamed > xNamed( rPropSet, UNO_QUERY );
2518         if( xNamed.is() )
2519         {
2520             OUString sName( xNamed->getName() );
2521             if( sName.getLength() )
2522                 GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
2523                                           xNamed->getName() );
2524         }
2525     }
2526 
2527 	OUStringBuffer sValue;
2528 
2529 	// text:anchor-type
2530 	TextContentAnchorType eAnchor = TextContentAnchorType_AT_PARAGRAPH;
2531 	rPropSet->getPropertyValue( sAnchorType ) >>= eAnchor;
2532 	{
2533 		XMLAnchorTypePropHdl aAnchorTypeHdl;
2534 		OUString sTmp;
2535         aAnchorTypeHdl.exportXML( sTmp, uno::makeAny(eAnchor),
2536 								  GetExport().GetMM100UnitConverter() );
2537 		GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_ANCHOR_TYPE, sTmp );
2538 	}
2539 
2540 	// text:anchor-page-number
2541 	if( TextContentAnchorType_AT_PAGE == eAnchor )
2542 	{
2543 		sal_Int16 nPage = 0;
2544 		rPropSet->getPropertyValue( sAnchorPageNo ) >>= nPage;
2545 		GetExport().GetMM100UnitConverter().convertNumber( sValue,
2546 														   (sal_Int32)nPage );
2547 		GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_ANCHOR_PAGE_NUMBER,
2548 								  sValue.makeStringAndClear() );
2549 	}
2550 	else
2551 	{
2552 		// #92210#
2553 		nShapeFeatures |= SEF_EXPORT_NO_WS;
2554 	}
2555 
2556     // OD 2004-06-01 #i27691# - correction: no export of svg:x, if object
2557     // is anchored as-character.
2558     if ( !bShape &&
2559          eAnchor != TextContentAnchorType_AS_CHARACTER )
2560 	{
2561 		// svg:x
2562 		sal_Int16 nHoriOrient =  HoriOrientation::NONE;
2563 		rPropSet->getPropertyValue( sHoriOrient ) >>= nHoriOrient;
2564 		if( HoriOrientation::NONE == nHoriOrient )
2565 		{
2566 			sal_Int32 nPos = 0;
2567 			rPropSet->getPropertyValue( sHoriOrientPosition ) >>= nPos;
2568 			GetExport().GetMM100UnitConverter().convertMeasure( sValue, nPos );
2569 			GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_X,
2570 									  sValue.makeStringAndClear() );
2571 		}
2572 	}
2573 	else if( TextContentAnchorType_AS_CHARACTER == eAnchor )
2574 		nShapeFeatures = (nShapeFeatures & ~SEF_EXPORT_X);
2575 
2576 	if( !bShape || TextContentAnchorType_AS_CHARACTER == eAnchor  )
2577 	{
2578 		// svg:y
2579 		sal_Int16 nVertOrient =  VertOrientation::NONE;
2580 		rPropSet->getPropertyValue( sVertOrient ) >>= nVertOrient;
2581 		if( VertOrientation::NONE == nVertOrient )
2582 		{
2583 			sal_Int32 nPos = 0;
2584 			rPropSet->getPropertyValue( sVertOrientPosition ) >>= nPos;
2585 			GetExport().GetMM100UnitConverter().convertMeasure( sValue, nPos );
2586 			GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_Y,
2587 									  sValue.makeStringAndClear() );
2588 		}
2589 		if( bShape )
2590 			nShapeFeatures = (nShapeFeatures & ~SEF_EXPORT_Y);
2591 	}
2592 
2593 
2594 	Reference< XPropertySetInfo > xPropSetInfo(rPropSet->getPropertySetInfo());
2595 
2596 	// svg:width
2597 	sal_Int16 nWidthType = SizeType::FIX;
2598 	if( xPropSetInfo->hasPropertyByName( sWidthType ) )
2599 	{
2600 		rPropSet->getPropertyValue( sWidthType ) >>= nWidthType;
2601 	}
2602 	if( xPropSetInfo->hasPropertyByName( sWidth ) )
2603 	{
2604 		sal_Int32 nWidth =  0;
2605         // VAR size will be written as zero min-size
2606         if( SizeType::VARIABLE != nWidthType )
2607         {
2608     		rPropSet->getPropertyValue( sWidth ) >>= nWidth;
2609         }
2610 		GetExport().GetMM100UnitConverter().convertMeasure( sValue, nWidth );
2611 		if( SizeType::FIX != nWidthType )
2612 			GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MIN_WIDTH,
2613 									  sValue.makeStringAndClear() );
2614 		else
2615             GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_WIDTH,
2616                                       sValue.makeStringAndClear() );
2617 	}
2618 	sal_Bool bSyncWidth = sal_False;
2619 	if( xPropSetInfo->hasPropertyByName( sIsSyncWidthToHeight ) )
2620 	{
2621 		bSyncWidth = *(sal_Bool *)rPropSet->getPropertyValue( sIsSyncWidthToHeight ).getValue();
2622 		if( bSyncWidth )
2623 			GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
2624                                       XML_SCALE );
2625 	}
2626 	if( !bSyncWidth && xPropSetInfo->hasPropertyByName( sRelativeWidth ) )
2627 	{
2628 		sal_Int16 nRelWidth =  0;
2629 		rPropSet->getPropertyValue( sRelativeWidth ) >>= nRelWidth;
2630 		DBG_ASSERT( nRelWidth >= 0 && nRelWidth <= 254,
2631 					"Got illegal relative width from API" );
2632 		if( nRelWidth > 0 )
2633 		{
2634 			GetExport().GetMM100UnitConverter().convertPercent( sValue,
2635 																nRelWidth );
2636 			GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
2637 									  sValue.makeStringAndClear() );
2638 		}
2639 	}
2640 
2641 	// svg:height, fo:min-height or style:rel-height
2642 	sal_Int16 nSizeType = SizeType::FIX;
2643 	if( xPropSetInfo->hasPropertyByName( sSizeType ) )
2644 	{
2645 		rPropSet->getPropertyValue( sSizeType ) >>= nSizeType;
2646 	}
2647 	sal_Bool bSyncHeight = sal_False;
2648 	if( xPropSetInfo->hasPropertyByName( sIsSyncHeightToWidth ) )
2649 	{
2650 		bSyncHeight = *(sal_Bool *)rPropSet->getPropertyValue( sIsSyncHeightToWidth ).getValue();
2651 	}
2652 	sal_Int16 nRelHeight =  0;
2653 	if( !bSyncHeight && xPropSetInfo->hasPropertyByName( sRelativeHeight ) )
2654 	{
2655 		rPropSet->getPropertyValue( sRelativeHeight ) >>= nRelHeight;
2656 	}
2657 	if( xPropSetInfo->hasPropertyByName( sHeight ) )
2658 	{
2659 		sal_Int32 nHeight =  0;
2660         if( SizeType::VARIABLE != nSizeType )
2661         {
2662     		rPropSet->getPropertyValue( sHeight ) >>= nHeight;
2663         }
2664 		GetExport().GetMM100UnitConverter().convertMeasure( sValue,
2665 															nHeight );
2666 		if( SizeType::FIX != nSizeType && 0==nRelHeight && !bSyncHeight &&
2667 		 	pMinHeightValue )
2668 			*pMinHeightValue = sValue.makeStringAndClear();
2669 		else
2670 			GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_HEIGHT,
2671 									  sValue.makeStringAndClear() );
2672 	}
2673 	if( bSyncHeight )
2674 	{
2675 		GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_HEIGHT,
2676 				SizeType::MIN == nSizeType ? XML_SCALE_MIN : XML_SCALE );
2677 
2678 	}
2679 	else if( nRelHeight > 0 )
2680 	{
2681 		GetExport().GetMM100UnitConverter().convertPercent( sValue,
2682 															nRelHeight );
2683 		if( SizeType::MIN == nSizeType )
2684 			GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MIN_HEIGHT,
2685 									  sValue.makeStringAndClear() );
2686 		else
2687 			GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_HEIGHT,
2688 									  sValue.makeStringAndClear() );
2689 	}
2690 
2691 	OUString sZOrder( RTL_CONSTASCII_USTRINGPARAM( "ZOrder" ) );
2692 	if( xPropSetInfo->hasPropertyByName( sZOrder ) )
2693 	{
2694 		sal_Int32 nZIndex = 0;
2695 		rPropSet->getPropertyValue( sZOrder ) >>= nZIndex;
2696 		if( -1 != nZIndex )
2697 		{
2698 			GetExport().GetMM100UnitConverter().convertNumber( sValue,
2699 																nZIndex );
2700 			GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_ZINDEX,
2701 									  sValue.makeStringAndClear() );
2702 		}
2703 	}
2704 
2705 	return nShapeFeatures;
2706 }
2707 
exportAnyTextFrame(const Reference<XTextContent> & rTxtCntnt,FrameType eType,sal_Bool bAutoStyles,sal_Bool bIsProgress,sal_Bool bExportContent,const Reference<XPropertySet> * pRangePropSet)2708 void XMLTextParagraphExport::exportAnyTextFrame(
2709 		const Reference < XTextContent > & rTxtCntnt,
2710 		FrameType eType,
2711 		sal_Bool bAutoStyles,
2712         sal_Bool bIsProgress,
2713         sal_Bool bExportContent,
2714         const Reference < XPropertySet > *pRangePropSet)
2715 {
2716 	Reference < XPropertySet > xPropSet( rTxtCntnt, UNO_QUERY );
2717 
2718 	if( bAutoStyles )
2719 	{
2720 		if( FT_EMBEDDED == eType )
2721 			_collectTextEmbeddedAutoStyles( xPropSet );
2722         // --> OD 2004-08-09 #i28745# - no text frame style for shapes
2723         else if ( FT_SHAPE != eType )
2724 			Add( XML_STYLE_FAMILY_TEXT_FRAME, xPropSet );
2725         // <--
2726 
2727 		if( pRangePropSet && lcl_txtpara_isBoundAsChar( xPropSet,
2728 											xPropSet->getPropertySetInfo() ) )
2729 			Add( XML_STYLE_FAMILY_TEXT_TEXT, *pRangePropSet );
2730 
2731 		switch( eType )
2732 		{
2733 		case FT_TEXT:
2734 			{
2735 				// frame bound frames
2736                 if ( bExportContent )
2737                 {
2738     				Reference < XTextFrame > xTxtFrame( rTxtCntnt, UNO_QUERY );
2739 	    			Reference < XText > xTxt(xTxtFrame->getText());
2740                     exportFrameFrames( sal_True, bIsProgress, &xTxtFrame );
2741                     exportText( xTxt, bAutoStyles, bIsProgress, sal_True );
2742                 }
2743             }
2744 			break;
2745 		case FT_SHAPE:
2746 			{
2747 				Reference < XShape > xShape( rTxtCntnt, UNO_QUERY );
2748 				GetExport().GetShapeExport()->collectShapeAutoStyles( xShape );
2749 			}
2750 			break;
2751 		default:
2752 			break;
2753 		}
2754 	}
2755 	else
2756 	{
2757 		Reference< XPropertySetInfo > xPropSetInfo(xPropSet->getPropertySetInfo());
2758 		Reference< XPropertyState > xPropState( xPropSet, UNO_QUERY );
2759 		{
2760 			sal_Bool bAddCharStyles = pRangePropSet &&
2761 				lcl_txtpara_isBoundAsChar( xPropSet, xPropSetInfo );
2762 
2763             sal_Bool bIsUICharStyle;
2764             sal_Bool bHasAutoStyle = sal_False;
2765             sal_Bool bDummy;
2766 
2767 			OUString sStyle;
2768 
2769 			if( bAddCharStyles )
2770 		   		sStyle = FindTextStyleAndHyperlink( *pRangePropSet, bDummy, bIsUICharStyle, bHasAutoStyle );
2771 			else
2772 				bIsUICharStyle = sal_False;
2773 
2774 			XMLTextCharStyleNamesElementExport aCharStylesExport(
2775 				GetExport(), bIsUICharStyle &&
2776 							 aCharStyleNamesPropInfoCache.hasProperty(
2777                                             *pRangePropSet ), bHasAutoStyle,
2778 				*pRangePropSet, sCharStyleNames );
2779 
2780 			if( sStyle.getLength() )
2781 				GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
2782 								  GetExport().EncodeStyleName( sStyle ) );
2783 			{
2784 				SvXMLElementExport aElem( GetExport(), sStyle.getLength() > 0,
2785 					XML_NAMESPACE_TEXT, XML_SPAN, sal_False, sal_False );
2786 				{
2787 					SvXMLElementExport aElement( GetExport(),
2788 						FT_SHAPE != eType &&
2789 						addHyperlinkAttributes( xPropSet,
2790 												xPropState,xPropSetInfo ),
2791 						XML_NAMESPACE_DRAW, XML_A, sal_False, sal_False );
2792 					switch( eType )
2793 					{
2794 					case FT_TEXT:
2795 						_exportTextFrame( xPropSet, xPropSetInfo, bIsProgress );
2796 						break;
2797 					case FT_GRAPHIC:
2798 						_exportTextGraphic( xPropSet, xPropSetInfo );
2799 						break;
2800 					case FT_EMBEDDED:
2801 						_exportTextEmbedded( xPropSet, xPropSetInfo );
2802 						break;
2803 					case FT_SHAPE:
2804 						{
2805 							Reference < XShape > xShape( rTxtCntnt, UNO_QUERY );
2806 							sal_Int32 nFeatures =
2807 								addTextFrameAttributes( xPropSet, sal_True );
2808 							GetExport().GetShapeExport()
2809 								->exportShape( xShape, nFeatures );
2810 						}
2811 						break;
2812 					}
2813 				}
2814 			}
2815 		}
2816 	}
2817 }
2818 
_exportTextFrame(const Reference<XPropertySet> & rPropSet,const Reference<XPropertySetInfo> & rPropSetInfo,sal_Bool bIsProgress)2819 void XMLTextParagraphExport::_exportTextFrame(
2820 		const Reference < XPropertySet > & rPropSet,
2821 		const Reference < XPropertySetInfo > & rPropSetInfo,
2822 		sal_Bool bIsProgress )
2823 {
2824 	Reference < XTextFrame > xTxtFrame( rPropSet, UNO_QUERY );
2825 	Reference < XText > xTxt(xTxtFrame->getText());
2826 
2827 	OUString sStyle;
2828 	if( rPropSetInfo->hasPropertyByName( sFrameStyleName ) )
2829 	{
2830 		rPropSet->getPropertyValue( sFrameStyleName ) >>= sStyle;
2831 	}
2832 
2833 	OUString sAutoStyle( sStyle );
2834 	OUString aMinHeightValue;
2835 	sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_FRAME, rPropSet, sStyle );
2836 	if( sAutoStyle.getLength() )
2837 		GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE_NAME,
2838 							  GetExport().EncodeStyleName( sAutoStyle ) );
2839 	addTextFrameAttributes( rPropSet, sal_False, &aMinHeightValue );
2840 
2841 	SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW,
2842 							  XML_FRAME, sal_False, sal_True );
2843 
2844 	if( aMinHeightValue.getLength() )
2845 		GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MIN_HEIGHT,
2846 								  aMinHeightValue );
2847 
2848 	// draw:chain-next-name
2849 	if( rPropSetInfo->hasPropertyByName( sChainNextName ) )
2850 	{
2851 		OUString sNext;
2852 		if( (rPropSet->getPropertyValue( sChainNextName ) >>= sNext) && sNext.getLength() > 0 )
2853 			GetExport().AddAttribute( XML_NAMESPACE_DRAW,
2854 									  XML_CHAIN_NEXT_NAME,
2855 									  sNext );
2856 	}
2857 
2858 	{
2859 		SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_DRAW,
2860 								  XML_TEXT_BOX, sal_True, sal_True );
2861 
2862 		// frame bound frames
2863 		exportFramesBoundToFrame( xTxtFrame, bIsProgress );
2864 
2865 		exportText( xTxt, sal_False, bIsProgress, sal_True );
2866 	}
2867 
2868 	// script:events
2869 	Reference<XEventsSupplier> xEventsSupp( xTxtFrame, UNO_QUERY );
2870 	GetExport().GetEventExport().Export(xEventsSupp);
2871 
2872 	// image map
2873 	GetExport().GetImageMapExport().Export( rPropSet );
2874 
2875     // --> OD 2009-07-22 #i73249#
2876     // svg:title and svg:desc
2877     exportTitleAndDescription( rPropSet, rPropSetInfo );
2878     // <--
2879 }
2880 
exportContour(const Reference<XPropertySet> & rPropSet,const Reference<XPropertySetInfo> & rPropSetInfo)2881 void XMLTextParagraphExport::exportContour(
2882     const Reference < XPropertySet > & rPropSet,
2883     const Reference < XPropertySetInfo > & rPropSetInfo )
2884 {
2885     if( !rPropSetInfo->hasPropertyByName( sContourPolyPolygon ) )
2886     {
2887         return;
2888     }
2889 
2890     PointSequenceSequence aSourcePolyPolygon;
2891     rPropSet->getPropertyValue( sContourPolyPolygon ) >>= aSourcePolyPolygon;
2892     const basegfx::B2DPolyPolygon aPolyPolygon(
2893         basegfx::tools::UnoPointSequenceSequenceToB2DPolyPolygon(
2894             aSourcePolyPolygon));
2895     const sal_uInt32 nPolygonCount(aPolyPolygon.count());
2896 
2897     if(!nPolygonCount)
2898     {
2899         return;
2900     }
2901 
2902     const basegfx::B2DRange aPolyPolygonRange(aPolyPolygon.getB2DRange());
2903     bool bPixel(false);
2904 
2905     if( rPropSetInfo->hasPropertyByName( sIsPixelContour ) )
2906     {
2907         bPixel = *(sal_Bool *)rPropSet->getPropertyValue( sIsPixelContour ).getValue();
2908     }
2909 
2910     // svg: width
2911     OUStringBuffer aStringBuffer( 10 );
2912 
2913     if(bPixel)
2914     {
2915         GetExport().GetMM100UnitConverter().convertMeasurePx(aStringBuffer, basegfx::fround(aPolyPolygonRange.getWidth()));
2916     }
2917     else
2918     {
2919         GetExport().GetMM100UnitConverter().convertMeasure(aStringBuffer, basegfx::fround(aPolyPolygonRange.getWidth()));
2920     }
2921 
2922     GetExport().AddAttribute(XML_NAMESPACE_SVG, XML_WIDTH, aStringBuffer.makeStringAndClear());
2923 
2924     // svg: height
2925     if(bPixel)
2926     {
2927         GetExport().GetMM100UnitConverter().convertMeasurePx(aStringBuffer, basegfx::fround(aPolyPolygonRange.getHeight()));
2928     }
2929     else
2930     {
2931         GetExport().GetMM100UnitConverter().convertMeasure(aStringBuffer, basegfx::fround(aPolyPolygonRange.getHeight()));
2932     }
2933 
2934     GetExport().AddAttribute(XML_NAMESPACE_SVG, XML_HEIGHT, aStringBuffer.makeStringAndClear());
2935 
2936     // svg:viewbox
2937     SdXMLImExViewBox aViewBox(0.0, 0.0, aPolyPolygonRange.getWidth(), aPolyPolygonRange.getHeight());
2938     GetExport().AddAttribute(XML_NAMESPACE_SVG, XML_VIEWBOX, aViewBox.GetExportString());
2939     enum XMLTokenEnum eElem = XML_TOKEN_INVALID;
2940 
2941     if(1 == nPolygonCount )
2942     {
2943         // simple polygon shape, can be written as svg:points sequence
2944         const ::rtl::OUString aPointString(
2945             basegfx::tools::exportToSvgPoints(
2946                 aPolyPolygon.getB2DPolygon(0)));
2947 
2948         // write point array
2949         GetExport().AddAttribute(XML_NAMESPACE_DRAW, XML_POINTS, aPointString);
2950         eElem = XML_CONTOUR_POLYGON;
2951     }
2952     else
2953     {
2954         // polypolygon, needs to be written as a svg:path sequence
2955         const ::rtl::OUString aPolygonString(
2956             basegfx::tools::exportToSvgD(
2957                 aPolyPolygon,
2958                 true,           // bUseRelativeCoordinates
2959                 false,          // bDetectQuadraticBeziers: not used in old, but maybe activated now
2960                 true));         // bHandleRelativeNextPointCompatible
2961 
2962         // write point array
2963         GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_D, aPolygonString);
2964         eElem = XML_CONTOUR_PATH;
2965     }
2966 
2967     if( rPropSetInfo->hasPropertyByName( sIsAutomaticContour ) )
2968     {
2969         sal_Bool bTmp = *(sal_Bool *)rPropSet->getPropertyValue(
2970                                             sIsAutomaticContour ).getValue();
2971         GetExport().AddAttribute( XML_NAMESPACE_DRAW,
2972                       XML_RECREATE_ON_EDIT, bTmp ? XML_TRUE : XML_FALSE );
2973     }
2974 
2975     // write object now
2976     SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW, eElem,
2977                               sal_True, sal_True );
2978 }
2979 
_exportTextGraphic(const Reference<XPropertySet> & rPropSet,const Reference<XPropertySetInfo> & rPropSetInfo)2980 void XMLTextParagraphExport::_exportTextGraphic(
2981 		const Reference < XPropertySet > & rPropSet,
2982 		const Reference < XPropertySetInfo > & rPropSetInfo )
2983 {
2984 	OUString sStyle;
2985 	if( rPropSetInfo->hasPropertyByName( sFrameStyleName ) )
2986 	{
2987 		rPropSet->getPropertyValue( sFrameStyleName ) >>= sStyle;
2988 	}
2989 
2990 	OUString sAutoStyle( sStyle );
2991 	sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_FRAME, rPropSet, sStyle );
2992 	if( sAutoStyle.getLength() )
2993 		GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE_NAME,
2994 								  GetExport().EncodeStyleName( sAutoStyle ) );
2995 	addTextFrameAttributes( rPropSet, sal_False );
2996 
2997 	// svg:transform
2998 	sal_Int16 nVal = 0;
2999 	rPropSet->getPropertyValue( sGraphicRotation ) >>= nVal;
3000 	if( nVal != 0 )
3001 	{
3002 		OUStringBuffer sRet( GetXMLToken(XML_ROTATE).getLength()+4 );
3003 		sRet.append( GetXMLToken(XML_ROTATE));
3004 		sRet.append( (sal_Unicode)'(' );
3005 		GetExport().GetMM100UnitConverter().convertNumber( sRet, (sal_Int32)nVal );
3006 		sRet.append( (sal_Unicode)')' );
3007 		GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_TRANSFORM,
3008 								  sRet.makeStringAndClear() );
3009 	}
3010 
3011     // original content
3012     SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_DRAW, XML_FRAME, sal_False, sal_True);
3013 
3014     // replacement graphic for backwards compatibility, but
3015     // only for SVG currently
3016     OUString sReplacementOrigURL;
3017     rPropSet->getPropertyValue( sReplacementGraphicURL ) >>= sReplacementOrigURL;
3018 
3019     if(sReplacementOrigURL.getLength())
3020     {
3021         const OUString sReplacementURL(GetExport().AddEmbeddedGraphicObject( sReplacementOrigURL ));
3022 
3023         // If there is no url, then then graphic is empty
3024         if(sReplacementURL.getLength())
3025         {
3026             GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sReplacementURL);
3027             GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE);
3028             GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED);
3029             GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD);
3030 
3031             // xlink:href for replacement, only written for Svg content
3032             SvXMLElementExport aElement(GetExport(), XML_NAMESPACE_DRAW, XML_IMAGE, sal_False, sal_True);
3033 
3034             // optional office:binary-data
3035             GetExport().AddEmbeddedGraphicObjectAsBase64(sReplacementURL);
3036         }
3037     }
3038 
3039 	// xlink:href
3040 	OUString sOrigURL;
3041 	rPropSet->getPropertyValue( sGraphicURL ) >>= sOrigURL;
3042 	OUString sURL(GetExport().AddEmbeddedGraphicObject( sOrigURL ));
3043 	setTextEmbeddedGraphicURL( rPropSet, sURL );
3044 
3045 	// If there still is no url, then then graphic is empty
3046 	if( sURL.getLength() )
3047 	{
3048 		GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sURL );
3049 		GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
3050 		GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
3051 		GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE,
3052                                                        XML_ONLOAD );
3053 	}
3054 
3055 	// draw:filter-name
3056 	OUString sGrfFilter;
3057 	rPropSet->getPropertyValue( sGraphicFilter ) >>= sGrfFilter;
3058 	if( sGrfFilter.getLength() )
3059 		GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_FILTER_NAME,
3060 								  sGrfFilter );
3061 
3062 	{
3063 		SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_DRAW,
3064 								  XML_IMAGE, sal_False, sal_True );
3065 
3066 		// optional office:binary-data
3067 		GetExport().AddEmbeddedGraphicObjectAsBase64( sOrigURL );
3068 	}
3069 
3070 	// script:events
3071 	Reference<XEventsSupplier> xEventsSupp( rPropSet, UNO_QUERY );
3072 	GetExport().GetEventExport().Export(xEventsSupp);
3073 
3074 	// image map
3075 	GetExport().GetImageMapExport().Export( rPropSet );
3076 
3077     // --> OD 2009-07-22 #i73249#
3078     // svg:title and svg:desc
3079     exportTitleAndDescription( rPropSet, rPropSetInfo );
3080     // <--
3081 
3082 	// draw:contour
3083 	exportContour( rPropSet, rPropSetInfo );
3084 }
3085 
_collectTextEmbeddedAutoStyles(const Reference<XPropertySet> &)3086 void XMLTextParagraphExport::_collectTextEmbeddedAutoStyles(const Reference < XPropertySet > & )
3087 {
3088 	DBG_ASSERT( !this, "no API implementation avialable" );
3089 }
3090 
_exportTextEmbedded(const Reference<XPropertySet> &,const Reference<XPropertySetInfo> &)3091 void XMLTextParagraphExport::_exportTextEmbedded(
3092 		const Reference < XPropertySet > &,
3093 		const Reference < XPropertySetInfo > & )
3094 {
3095 	DBG_ASSERT( !this, "no API implementation avialable" );
3096 }
3097 
exportEvents(const Reference<XPropertySet> & rPropSet)3098 void XMLTextParagraphExport::exportEvents( const Reference < XPropertySet > & rPropSet )
3099 {
3100 	// script:events
3101 	Reference<XEventsSupplier> xEventsSupp( rPropSet, UNO_QUERY );
3102 	GetExport().GetEventExport().Export(xEventsSupp);
3103 
3104 	// image map
3105 	OUString sImageMap(RTL_CONSTASCII_USTRINGPARAM("ImageMap"));
3106 	if (rPropSet->getPropertySetInfo()->hasPropertyByName(sImageMap))
3107 		GetExport().GetImageMapExport().Export( rPropSet );
3108 }
3109 
3110 // --> OD 2009-07-22 #i73249#
exportTitleAndDescription(const Reference<XPropertySet> & rPropSet,const Reference<XPropertySetInfo> & rPropSetInfo)3111 void XMLTextParagraphExport::exportTitleAndDescription(
3112 		const Reference < XPropertySet > & rPropSet,
3113 		const Reference < XPropertySetInfo > & rPropSetInfo )
3114 {
3115 	// svg:title
3116     if( rPropSetInfo->hasPropertyByName( sTitle ) )
3117 	{
3118         OUString sObjTitle;
3119         rPropSet->getPropertyValue( sTitle ) >>= sObjTitle;
3120         if( sObjTitle.getLength() )
3121 		{
3122 			SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_SVG,
3123 									  XML_TITLE, sal_True, sal_False );
3124             GetExport().Characters( sObjTitle );
3125 		}
3126 	}
3127 
3128     // svg:description
3129     if( rPropSetInfo->hasPropertyByName( sDescription ) )
3130     {
3131         OUString sObjDesc;
3132         rPropSet->getPropertyValue( sDescription ) >>= sObjDesc;
3133         if( sObjDesc.getLength() )
3134         {
3135             SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_SVG,
3136                                       XML_DESC, sal_True, sal_False );
3137             GetExport().Characters( sObjDesc );
3138         }
3139     }
3140 }
3141 // <--
3142 
setTextEmbeddedGraphicURL(const Reference<XPropertySet> &,OUString &) const3143 void XMLTextParagraphExport::setTextEmbeddedGraphicURL(
3144 	const Reference < XPropertySet >&,
3145 	OUString& /*rStreamName*/ ) const
3146 {
3147 }
3148 
addHyperlinkAttributes(const Reference<XPropertySet> & rPropSet,const Reference<XPropertyState> & rPropState,const Reference<XPropertySetInfo> & rPropSetInfo)3149 sal_Bool XMLTextParagraphExport::addHyperlinkAttributes(
3150     const Reference< XPropertySet > & rPropSet,
3151     const Reference< XPropertyState > & rPropState,
3152     const Reference< XPropertySetInfo > & rPropSetInfo )
3153 {
3154     sal_Bool bExport = sal_False;
3155     OUString sHRef, sName, sTargetFrame, sUStyleName, sVStyleName;
3156     sal_Bool bServerMap = sal_False;
3157 
3158     if ( rPropSetInfo->hasPropertyByName( sHyperLinkURL )
3159          && ( !rPropState.is()
3160               || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sHyperLinkURL ) ) )
3161     {
3162         rPropSet->getPropertyValue( sHyperLinkURL ) >>= sHRef;
3163         if ( !sHRef.isEmpty() )
3164             bExport = sal_True;
3165     }
3166     if ( sHRef.isEmpty() )
3167     {
3168         // hyperlink without an URL does not make sense
3169         OSL_ENSURE( false, "hyperlink without an URL --> no export to ODF" );
3170         return sal_False;
3171     }
3172 
3173 
3174     if ( rPropSetInfo->hasPropertyByName( sHyperLinkName )
3175          && ( !rPropState.is()
3176               || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sHyperLinkName ) ) )
3177     {
3178         rPropSet->getPropertyValue( sHyperLinkName ) >>= sName;
3179         if ( !sName.isEmpty() )
3180             bExport = sal_True;
3181     }
3182 
3183     if ( rPropSetInfo->hasPropertyByName( sHyperLinkTarget )
3184          && ( !rPropState.is()
3185               || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sHyperLinkTarget ) ) )
3186     {
3187         rPropSet->getPropertyValue( sHyperLinkTarget ) >>= sTargetFrame;
3188         if ( !sTargetFrame.isEmpty() )
3189             bExport = sal_True;
3190     }
3191 
3192     if ( rPropSetInfo->hasPropertyByName( sServerMap )
3193          && ( !rPropState.is()
3194               || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sServerMap ) ) )
3195     {
3196         bServerMap = *(sal_Bool *) rPropSet->getPropertyValue( sServerMap ).getValue();
3197         if ( bServerMap )
3198             bExport = sal_True;
3199     }
3200 
3201     if ( rPropSetInfo->hasPropertyByName( sUnvisitedCharStyleName )
3202          && ( !rPropState.is()
3203               || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sUnvisitedCharStyleName ) ) )
3204     {
3205         rPropSet->getPropertyValue( sUnvisitedCharStyleName ) >>= sUStyleName;
3206         if ( !sUStyleName.isEmpty() )
3207             bExport = sal_True;
3208     }
3209 
3210     if ( rPropSetInfo->hasPropertyByName( sVisitedCharStyleName )
3211          && ( !rPropState.is()
3212               || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sVisitedCharStyleName ) ) )
3213     {
3214         rPropSet->getPropertyValue( sVisitedCharStyleName ) >>= sVStyleName;
3215         if ( !sVStyleName.isEmpty() )
3216             bExport = sal_True;
3217     }
3218 
3219     if ( bExport )
3220 	{
3221 		GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
3222 		GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, GetExport().GetRelativeReference( sHRef ) );
3223 
3224 		if( !sName.isEmpty() )
3225 			GetExport().AddAttribute( XML_NAMESPACE_OFFICE, XML_NAME, sName );
3226 
3227 		if( !sTargetFrame.isEmpty() )
3228 		{
3229 			GetExport().AddAttribute( XML_NAMESPACE_OFFICE,
3230 									  XML_TARGET_FRAME_NAME, sTargetFrame );
3231 			enum XMLTokenEnum eTok =
3232 				sTargetFrame.equalsAsciiL( "_blank", sizeof("_blank")-1 )
3233 					? XML_NEW : XML_REPLACE;
3234 			GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, eTok );
3235 		}
3236 
3237 		if( bServerMap  )
3238 			GetExport().AddAttribute( XML_NAMESPACE_OFFICE,
3239                                       XML_SERVER_MAP, XML_TRUE );
3240 
3241 		if( !sUStyleName.isEmpty() )
3242 			GetExport().AddAttribute( XML_NAMESPACE_TEXT,
3243 			  XML_STYLE_NAME, GetExport().EncodeStyleName( sUStyleName ) );
3244 
3245 		if( !sVStyleName.isEmpty() )
3246 			GetExport().AddAttribute( XML_NAMESPACE_TEXT,
3247 			  XML_VISITED_STYLE_NAME, GetExport().EncodeStyleName( sVStyleName ) );
3248 	}
3249 
3250 	return bExport;
3251 }
3252 
exportTextRangeSpan(const com::sun::star::uno::Reference<com::sun::star::text::XTextRange> & rTextRange,Reference<XPropertySet> & xPropSet,Reference<XPropertySetInfo> & xPropSetInfo,const sal_Bool bIsUICharStyle,const sal_Bool bHasAutoStyle,const OUString & sStyle,sal_Bool & rPrevCharIsSpace)3253 void XMLTextParagraphExport::exportTextRangeSpan(
3254     const com::sun::star::uno::Reference< com::sun::star::text::XTextRange > & rTextRange,
3255     Reference< XPropertySet > & xPropSet,
3256     Reference < XPropertySetInfo > & xPropSetInfo,
3257     const sal_Bool bIsUICharStyle,
3258     const sal_Bool bHasAutoStyle,
3259     const OUString& sStyle,
3260     sal_Bool& rPrevCharIsSpace )
3261 {
3262     XMLTextCharStyleNamesElementExport aCharStylesExport(
3263             GetExport(),
3264             bIsUICharStyle && aCharStyleNamesPropInfoCache.hasProperty( xPropSet, xPropSetInfo ),
3265             bHasAutoStyle,
3266             xPropSet,
3267             sCharStyleNames );
3268 
3269     if ( !sStyle.isEmpty() )
3270     {
3271         GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, GetExport().EncodeStyleName( sStyle ) );
3272     }
3273     {
3274         SvXMLElementExport aElement( GetExport(), !sStyle.isEmpty(), XML_NAMESPACE_TEXT, XML_SPAN, sal_False, sal_False );
3275         const OUString aText( rTextRange->getString() );
3276         exportText( aText, rPrevCharIsSpace );
3277     }
3278 }
3279 
exportTextRange(const Reference<XTextRange> & rTextRange,sal_Bool bAutoStyles,sal_Bool & rPrevCharIsSpace)3280 void XMLTextParagraphExport::exportTextRange(
3281         const Reference< XTextRange > & rTextRange,
3282         sal_Bool bAutoStyles,
3283         sal_Bool& rPrevCharIsSpace )
3284 {
3285     Reference< XPropertySet > xPropSet( rTextRange, UNO_QUERY );
3286     if ( bAutoStyles )
3287     {
3288         Add( XML_STYLE_FAMILY_TEXT_TEXT, xPropSet );
3289     }
3290     else
3291     {
3292         sal_Bool bHyperlink = sal_False;
3293         sal_Bool bIsUICharStyle = sal_False;
3294         sal_Bool bHasAutoStyle = sal_False;
3295         const OUString sStyle(
3296             FindTextStyleAndHyperlink( xPropSet, bHyperlink, bIsUICharStyle, bHasAutoStyle ) );
3297 
3298         Reference < XPropertySetInfo > xPropSetInfo;
3299         sal_Bool bHyperlinkAttrsAdded = sal_False;
3300         if ( bHyperlink )
3301         {
3302             Reference< XPropertyState > xPropState( xPropSet, UNO_QUERY );
3303             xPropSetInfo.set( xPropSet->getPropertySetInfo() );
3304             bHyperlinkAttrsAdded = addHyperlinkAttributes( xPropSet, xPropState, xPropSetInfo );
3305         }
3306 
3307         if ( bHyperlink && bHyperlinkAttrsAdded )
3308         {
3309             SvXMLElementExport aElem( GetExport(), sal_True, XML_NAMESPACE_TEXT, XML_A, sal_False, sal_False );
3310 
3311             // export events (if supported)
3312             static const OUString sHyperLinkEvents( RTL_CONSTASCII_USTRINGPARAM( "HyperLinkEvents" ) );
3313             if ( xPropSetInfo->hasPropertyByName( sHyperLinkEvents ) )
3314             {
3315                 Reference< XNameReplace > xName( xPropSet->getPropertyValue( sHyperLinkEvents ), uno::UNO_QUERY );
3316                 GetExport().GetEventExport().Export( xName, sal_False );
3317             }
3318 
3319             exportTextRangeSpan( rTextRange, xPropSet, xPropSetInfo, bIsUICharStyle, bHasAutoStyle, sStyle, rPrevCharIsSpace );
3320         }
3321         else
3322         {
3323             exportTextRangeSpan( rTextRange, xPropSet, xPropSetInfo, bIsUICharStyle, bHasAutoStyle, sStyle, rPrevCharIsSpace );
3324         }
3325     }
3326 }
3327 
exportText(const OUString & rText,sal_Bool & rPrevCharIsSpace)3328 void XMLTextParagraphExport::exportText( const OUString& rText,
3329 									  	 sal_Bool& rPrevCharIsSpace )
3330 {
3331     sal_Int32 nExpStartPos = 0;
3332 	sal_Int32 nEndPos = rText.getLength();
3333 	sal_Int32 nSpaceChars = 0;
3334 	for( sal_Int32 nPos = 0; nPos < nEndPos; nPos++ )
3335 	{
3336 		sal_Unicode cChar = rText[nPos];
3337 		sal_Bool bExpCharAsText = sal_True;
3338 		sal_Bool bExpCharAsElement = sal_False;
3339 		sal_Bool bCurrCharIsSpace = sal_False;
3340 		switch( cChar )
3341 		{
3342 		case 0x0009:	// Tab
3343 		case 0x000A:	// LF
3344 			// These characters are exported as text.
3345 			bExpCharAsElement = sal_True;
3346 			bExpCharAsText = sal_False;
3347 			break;
3348 		case 0x000D:
3349 			break;	// legal character
3350 		case 0x0020:	// Blank
3351 			if( rPrevCharIsSpace )
3352 			{
3353 				// If the previous character is a space character,
3354 				// too, export a special space element.
3355 				bExpCharAsText = sal_False;
3356 			}
3357 			bCurrCharIsSpace = sal_True;
3358 			break;
3359 		default:
3360 			if( cChar < 0x0020 )
3361 			{
3362 #ifdef DBG_UTIL
3363 				OSL_ENSURE( txtparae_bContainsIllegalCharacters ||
3364 							cChar >= 0x0020,
3365 							"illegal character in text content" );
3366 				txtparae_bContainsIllegalCharacters = sal_True;
3367 #endif
3368 				bExpCharAsText = sal_False;
3369 			}
3370 			break;
3371 		}
3372 
3373 		// If the current character is not exported as text
3374 	   	// the text that has not been exported by now has to be exported now.
3375 		if( nPos > nExpStartPos && !bExpCharAsText )
3376 		{
3377 			DBG_ASSERT( 0==nSpaceChars, "pending spaces" );
3378 			OUString sExp( rText.copy( nExpStartPos, nPos - nExpStartPos ) );
3379 			GetExport().Characters( sExp );
3380 			nExpStartPos = nPos;
3381 		}
3382 
3383 		// If there are spaces left that have not been exported and the
3384 		// current chracter is not a space , the pending spaces have to be
3385 		// exported now.
3386 		if( nSpaceChars > 0 && !bCurrCharIsSpace )
3387 		{
3388 			DBG_ASSERT( nExpStartPos == nPos, " pending characters" );
3389 
3390 			if( nSpaceChars > 1 )
3391 			{
3392 				OUStringBuffer sTmp;
3393 				sTmp.append( (sal_Int32)nSpaceChars );
3394 				GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_C,
3395 							  sTmp.makeStringAndClear() );
3396 			}
3397 
3398 			SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
3399 									  XML_S, sal_False, sal_False );
3400 
3401 			nSpaceChars = 0;
3402 		}
3403 
3404 		// If the current character has to be exported as a special
3405 		// element, the elemnt will be exported now.
3406 		if( bExpCharAsElement )
3407 		{
3408 			switch( cChar )
3409 			{
3410 			case 0x0009:	// Tab
3411 				{
3412 					SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
3413 											  XML_TAB, sal_False,
3414 											  sal_False );
3415 				}
3416 				break;
3417 			case 0x000A:	// LF
3418 				{
3419 					SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
3420 											  XML_LINE_BREAK, sal_False,
3421 											  sal_False );
3422 				}
3423 				break;
3424 			}
3425 		}
3426 
3427 		// If the current character is a space, and the previous one
3428 		// is a space, too, the number of pending spaces is incremented
3429 		// only.
3430 		if( bCurrCharIsSpace && rPrevCharIsSpace )
3431 			nSpaceChars++;
3432 		rPrevCharIsSpace = bCurrCharIsSpace;
3433 
3434 		// If the currect character is not exported as text, the start
3435 		// position for text is the position behind the current position.
3436 		if( !bExpCharAsText )
3437 		{
3438 			DBG_ASSERT( nExpStartPos == nPos, "wrong export start pos" );
3439 			nExpStartPos = nPos+1;
3440 		}
3441 	}
3442 
3443 	if( nExpStartPos < nEndPos )
3444 	{
3445 		DBG_ASSERT( 0==nSpaceChars, " pending spaces " );
3446 		OUString sExp( rText.copy( nExpStartPos, nEndPos - nExpStartPos ) );
3447 		GetExport().Characters( sExp );
3448 	}
3449 
3450 	// If there are some spaces left, they have to be exported now.
3451 	if( nSpaceChars > 0 )
3452 	{
3453 		if( nSpaceChars > 1 )
3454 		{
3455 			OUStringBuffer sTmp;
3456 			sTmp.append( (sal_Int32)nSpaceChars );
3457 			GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_C,
3458 						  sTmp.makeStringAndClear() );
3459 		}
3460 
3461 		SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_S,
3462 								  sal_False, sal_False );
3463 	}
3464 }
3465 
exportTextDeclarations()3466 void XMLTextParagraphExport::exportTextDeclarations()
3467 {
3468 	pFieldExport->ExportFieldDeclarations();
3469 
3470 	// get XPropertySet from the document and ask for AutoMarkFileURL.
3471 	// If it exists, export the auto-mark-file element.
3472 	Reference<XPropertySet> xPropertySet( GetExport().GetModel(), UNO_QUERY );
3473 	if (xPropertySet.is())
3474 	{
3475 		OUString sUrl;
3476 		OUString sIndexAutoMarkFileURL(
3477 			RTL_CONSTASCII_USTRINGPARAM("IndexAutoMarkFileURL"));
3478 		if (xPropertySet->getPropertySetInfo()->hasPropertyByName(
3479 			sIndexAutoMarkFileURL))
3480 		{
3481 			xPropertySet->getPropertyValue(sIndexAutoMarkFileURL) >>= sUrl;
3482 			if (sUrl.getLength() > 0)
3483 			{
3484 				GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF,
3485 										  GetExport().GetRelativeReference(sUrl) );
3486 				SvXMLElementExport aAutoMarkElement(
3487 					GetExport(), XML_NAMESPACE_TEXT,
3488 					XML_ALPHABETICAL_INDEX_AUTO_MARK_FILE,
3489 					sal_True, sal_True );
3490 			}
3491 		}
3492 	}
3493 }
3494 
exportTextDeclarations(const Reference<XText> & rText)3495 void XMLTextParagraphExport::exportTextDeclarations(
3496 	const Reference<XText> & rText )
3497 {
3498 	pFieldExport->ExportFieldDeclarations(rText);
3499 }
3500 
exportUsedDeclarations(sal_Bool bOnlyUsed)3501 void XMLTextParagraphExport::exportUsedDeclarations( sal_Bool bOnlyUsed )
3502 {
3503 	pFieldExport->SetExportOnlyUsedFieldDeclarations( bOnlyUsed );
3504 }
3505 
3506 
exportTrackedChanges(sal_Bool bAutoStyles)3507 void XMLTextParagraphExport::exportTrackedChanges(sal_Bool bAutoStyles)
3508 {
3509 	if (NULL != pRedlineExport)
3510 		pRedlineExport->ExportChangesList( bAutoStyles );
3511 }
3512 
exportTrackedChanges(const Reference<XText> & rText,sal_Bool bAutoStyle)3513 void XMLTextParagraphExport::exportTrackedChanges(
3514 	const Reference<XText> & rText,
3515 	sal_Bool bAutoStyle)
3516 {
3517 	if (NULL != pRedlineExport)
3518 		pRedlineExport->ExportChangesList(rText, bAutoStyle);
3519 }
3520 
recordTrackedChangesForXText(const Reference<XText> & rText)3521 void XMLTextParagraphExport::recordTrackedChangesForXText(
3522 	const Reference<XText> & rText )
3523 {
3524 	if (NULL != pRedlineExport)
3525 		pRedlineExport->SetCurrentXText(rText);
3526 }
3527 
recordTrackedChangesNoXText()3528 void XMLTextParagraphExport::recordTrackedChangesNoXText()
3529 {
3530 	if (NULL != pRedlineExport)
3531 		pRedlineExport->SetCurrentXText();
3532 }
3533 
3534 
exportTextAutoStyles()3535 void XMLTextParagraphExport::exportTextAutoStyles()
3536 {
3537 	GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_PARAGRAPH,
3538 								   GetExport().GetDocHandler(),
3539 								   GetExport().GetMM100UnitConverter(),
3540 								   GetExport().GetNamespaceMap() );
3541 
3542 	GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_TEXT,
3543 								   GetExport().GetDocHandler(),
3544 								   GetExport().GetMM100UnitConverter(),
3545 								   GetExport().GetNamespaceMap() );
3546 
3547 	GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_FRAME,
3548 								   GetExport().GetDocHandler(),
3549 								   GetExport().GetMM100UnitConverter(),
3550 								   GetExport().GetNamespaceMap() );
3551 
3552 	GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_SECTION,
3553 								  GetExport().GetDocHandler(),
3554 								  GetExport().GetMM100UnitConverter(),
3555 								  GetExport().GetNamespaceMap() );
3556 
3557 	GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_RUBY,
3558 								  GetExport().GetDocHandler(),
3559 								  GetExport().GetMM100UnitConverter(),
3560 								  GetExport().GetNamespaceMap() );
3561 
3562 	pListAutoPool->exportXML();
3563 }
3564 
exportRuby(const Reference<XPropertySet> & rPropSet,sal_Bool bAutoStyles)3565 void XMLTextParagraphExport::exportRuby(
3566 	const Reference<XPropertySet> & rPropSet,
3567 	sal_Bool bAutoStyles )
3568 {
3569 	// early out: a collapsed ruby makes no sense
3570 	if (*(sal_Bool*)rPropSet->getPropertyValue(sIsCollapsed).getValue())
3571 		return;
3572 
3573 	// start value ?
3574 	sal_Bool bStart = (*(sal_Bool*)rPropSet->getPropertyValue(sIsStart).getValue());
3575 
3576 	if (bAutoStyles)
3577 	{
3578 		// ruby auto styles
3579 		if (bStart)
3580 			Add( XML_STYLE_FAMILY_TEXT_RUBY, rPropSet );
3581 	}
3582 	else
3583 	{
3584 		// prepare element names
3585 		OUString aRuby(GetXMLToken(XML_RUBY));
3586 		OUString sTextRuby(GetExport().GetNamespaceMap().
3587 						   GetQNameByKey(XML_NAMESPACE_TEXT, aRuby));
3588 		OUString sRubyBase(GetXMLToken(XML_RUBY_BASE));
3589 		OUString sTextRubyBase(GetExport().GetNamespaceMap().
3590 						   GetQNameByKey(XML_NAMESPACE_TEXT, sRubyBase));
3591 
3592 		if (bStart)
3593 		{
3594 			// ruby start
3595 
3596 			// we can only start a ruby if none is open
3597 			DBG_ASSERT(! bOpenRuby, "Can't open a ruby inside of ruby!");
3598 			if( bOpenRuby )
3599 				return;
3600 
3601 			// save ruby text + ruby char style
3602 			rPropSet->getPropertyValue(sRubyText) >>= sOpenRubyText;
3603 			rPropSet->getPropertyValue(sRubyCharStyleName) >>= sOpenRubyCharStyle;
3604 
3605 			// ruby style
3606 			GetExport().CheckAttrList();
3607 			OUString sEmpty;
3608 			OUString sStyleName(Find( XML_STYLE_FAMILY_TEXT_RUBY, rPropSet,
3609 										sEmpty ));
3610 			DBG_ASSERT(sStyleName.getLength() > 0, "I can't find the style!");
3611 			GetExport().AddAttribute(XML_NAMESPACE_TEXT,
3612 									 XML_STYLE_NAME, sStyleName);
3613 
3614 			// export <text:ruby> and <text:ruby-base> start elements
3615 			GetExport().StartElement( XML_NAMESPACE_TEXT, XML_RUBY, sal_False);
3616 			GetExport().ClearAttrList();
3617 			GetExport().StartElement( XML_NAMESPACE_TEXT, XML_RUBY_BASE,
3618                                       sal_False );
3619 			bOpenRuby = sal_True;
3620 		}
3621 		else
3622 		{
3623 			// ruby end
3624 
3625 			// check for an open ruby
3626 			DBG_ASSERT(bOpenRuby, "Can't close a ruby if none is open!");
3627 			if( !bOpenRuby )
3628 				return;
3629 
3630 			// close <text:ruby-base>
3631 			GetExport().EndElement(XML_NAMESPACE_TEXT, XML_RUBY_BASE,
3632                                    sal_False);
3633 
3634 			// write the ruby text (with char style)
3635 			{
3636 				if (sOpenRubyCharStyle.getLength() > 0)
3637 					GetExport().AddAttribute(
3638 						XML_NAMESPACE_TEXT, XML_STYLE_NAME,
3639         				GetExport().EncodeStyleName( sOpenRubyCharStyle) );
3640 
3641 				SvXMLElementExport aRubyElement(
3642 					GetExport(), XML_NAMESPACE_TEXT, XML_RUBY_TEXT,
3643 					sal_False, sal_False);
3644 
3645 				GetExport().Characters(sOpenRubyText);
3646 			}
3647 
3648 			// and finally, close the ruby
3649 			GetExport().EndElement(XML_NAMESPACE_TEXT, XML_RUBY, sal_False);
3650 			bOpenRuby = sal_False;
3651 		}
3652 	}
3653 }
3654 
exportMeta(const Reference<XPropertySet> & i_xPortion,sal_Bool i_bAutoStyles,sal_Bool i_isProgress)3655 void XMLTextParagraphExport::exportMeta(
3656     const Reference<XPropertySet> & i_xPortion,
3657     sal_Bool i_bAutoStyles, sal_Bool i_isProgress)
3658 {
3659     static OUString sMeta(RTL_CONSTASCII_USTRINGPARAM("InContentMetadata"));
3660 
3661     bool doExport(!i_bAutoStyles); // do not export element if autostyles
3662     // check version >= 1.2
3663     switch (GetExport().getDefaultVersion()) {
3664         case SvtSaveOptions::ODFVER_011: // fall thru
3665         case SvtSaveOptions::ODFVER_010: doExport = false; break;
3666         default: break;
3667     }
3668 
3669     const Reference< XTextContent > xTextContent(
3670             i_xPortion->getPropertyValue(sMeta), UNO_QUERY_THROW);
3671     const Reference< XEnumerationAccess > xEA( xTextContent, UNO_QUERY_THROW );
3672     const Reference< XEnumeration > xTextEnum( xEA->createEnumeration() );
3673 
3674     if (doExport)
3675     {
3676         const Reference<rdf::XMetadatable> xMeta(xTextContent, UNO_QUERY_THROW);
3677 
3678         // text:meta with neither xml:id nor RDFa is invalid
3679         xMeta->ensureMetadataReference();
3680 
3681         // xml:id and RDFa for RDF metadata
3682         GetExport().AddAttributeXmlId(xMeta);
3683         GetExport().AddAttributesRDFa(xTextContent);
3684     }
3685 
3686     SvXMLElementExport aElem( GetExport(), doExport,
3687         XML_NAMESPACE_TEXT, XML_META, sal_False, sal_False );
3688 
3689     // recurse to export content
3690     exportTextRangeEnumeration( xTextEnum, i_bAutoStyles, i_isProgress );
3691 }
3692 
3693 
PreventExportOfControlsInMuteSections(const Reference<XIndexAccess> & rShapes,UniReference<xmloff::OFormLayerXMLExport> xFormExport)3694 void XMLTextParagraphExport::PreventExportOfControlsInMuteSections(
3695     const Reference<XIndexAccess> & rShapes,
3696     UniReference<xmloff::OFormLayerXMLExport> xFormExport   )
3697 {
3698     // check parameters ad pre-conditions
3699     if( ( ! rShapes.is() ) || ( ! xFormExport.is() ) )
3700     {
3701         // if we don't have shapes or a form export, there's nothing to do
3702         return;
3703     }
3704     DBG_ASSERT( pSectionExport != NULL, "We need the section export." );
3705 
3706     Reference<XEnumeration> xShapesEnum = pBoundFrameSets->GetShapes()->createEnumeration();
3707     if(!xShapesEnum.is())
3708         return;
3709     while( xShapesEnum->hasMoreElements() )
3710     {
3711         // now we need to check
3712         // 1) if this is a control shape, and
3713         // 2) if it's in a mute section
3714         // if both answers are 'yes', notify the form layer export
3715 
3716         // we join accessing the shape and testing for control
3717         Reference<XControlShape> xControlShape(xShapesEnum->nextElement(), UNO_QUERY);
3718         if( xControlShape.is() )
3719         {
3720             //            Reference<XPropertySet> xPropSet( xControlShape, UNO_QUERY );
3721             //            Reference<XTextContent> xTextContent;
3722             //            xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) ) ) >>= xTextContent;
3723 
3724             Reference<XTextContent> xTextContent( xControlShape, UNO_QUERY );
3725             if( xTextContent.is() )
3726             {
3727                 if( pSectionExport->IsMuteSection( xTextContent, sal_False ) )
3728                 {
3729                     // Ah, we've found a shape that
3730                     // 1) is a control shape
3731                     // 2) is anchored in a mute section
3732                     // so: don't export it!
3733                     xFormExport->excludeFromExport(
3734                         xControlShape->getControl() );
3735                 }
3736                 // else: not in mute section -> should be exported -> nothing
3737                 // to do
3738             }
3739             // else: no anchor -> ignore
3740         }
3741         // else: no control shape -> nothing to do
3742     }
3743 }
GetHeadingLevel(const OUString & rStyleName)3744 sal_Int32 XMLTextParagraphExport::GetHeadingLevel( const OUString& rStyleName )
3745 {
3746 	if( !pHeadingStyles )
3747 	{
3748 		pHeadingStyles = new XMLStringVector;
3749 		SvxXMLNumRuleExport::GetOutlineStyles( *pHeadingStyles,
3750 											   GetExport().GetModel() );
3751 	}
3752 	for( XMLStringVector::size_type i=0; i < pHeadingStyles->size(); ++i )
3753 	{
3754 		if( (*pHeadingStyles)[i] == rStyleName )
3755 			return static_cast < sal_Int32 >( i );
3756 	}
3757 
3758 	return -1;
3759 }
3760 
3761 // --> OD 2008-05-08 #refactorlists#
PushNewTextListsHelper()3762 void XMLTextParagraphExport::PushNewTextListsHelper()
3763 {
3764     mpTextListsHelper = new XMLTextListsHelper();
3765     maTextListsHelperStack.push_back( mpTextListsHelper );
3766 }
3767 
PopTextListsHelper()3768 void XMLTextParagraphExport::PopTextListsHelper()
3769 {
3770     delete mpTextListsHelper;
3771     mpTextListsHelper = 0;
3772     maTextListsHelperStack.pop_back();
3773     if ( !maTextListsHelperStack.empty() )
3774     {
3775         mpTextListsHelper = maTextListsHelperStack.back();
3776     }
3777 }
3778 // <--
3779