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