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