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