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