PageRenderTime 67ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/binfilter/bf_xmloff/source/text/xmloff_txtparae.cxx

https://bitbucket.org/mst/ooo340
C++ | 3054 lines | 2554 code | 291 blank | 209 comment | 393 complexity | 9eaf98ef9bd2f1643d84b74de1493e2f MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-3.0, GPL-2.0, BSD-3-Clause, LGPL-2.1
  1. /*************************************************************************
  2. *
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * Copyright 2000, 2010 Oracle and/or its affiliates.
  6. *
  7. * OpenOffice.org - a multi-platform office productivity suite
  8. *
  9. * This file is part of OpenOffice.org.
  10. *
  11. * OpenOffice.org is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License version 3
  13. * only, as published by the Free Software Foundation.
  14. *
  15. * OpenOffice.org is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License version 3 for more details
  19. * (a copy is included in the LICENSE file that accompanied this code).
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * version 3 along with OpenOffice.org. If not, see
  23. * <http://www.openoffice.org/license.html>
  24. * for a copy of the LGPLv3 License.
  25. *
  26. ************************************************************************/
  27. #ifndef _SVSTDARR_LONGS_DECL
  28. #define _SVSTDARR_LONGS
  29. #include <bf_svtools/svstdarr.hxx>
  30. #endif
  31. #include <vector>
  32. #ifndef _COM_SUN_STAR_CONTAINER_XENUMERATIONACCESS_HPP_
  33. #include <com/sun/star/container/XEnumerationAccess.hpp>
  34. #endif
  35. #ifndef _COM_SUN_STAR_BEANS_XMULTIPROPERTYSET_HPP_
  36. #include <com/sun/star/beans/XMultiPropertySet.hpp>
  37. #endif
  38. #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSTATE_HPP_
  39. #include <com/sun/star/beans/XPropertyState.hpp>
  40. #endif
  41. #ifndef _COM_SUN_STAR_TEXT_XTEXTFIELD_HPP_
  42. #include <com/sun/star/text/XTextField.hpp>
  43. #endif
  44. #ifndef _COM_SUN_STAR_CONTAINER_XCONTENTENUMERATIONACCESS_HPP_
  45. #include <com/sun/star/container/XContentEnumerationAccess.hpp>
  46. #endif
  47. #ifndef _COM_SUN_STAR_TEXT_XTEXTFRAME_HPP_
  48. #include <com/sun/star/text/XTextFrame.hpp>
  49. #endif
  50. #ifndef _COM_SUN_STAR_TEXT_SIZETYPE_HPP_
  51. #include <com/sun/star/text/SizeType.hpp>
  52. #endif
  53. #ifndef _COM_SUN_STAR_TEXT_HORIORIENTATION_HPP_
  54. #include <com/sun/star/text/HoriOrientation.hpp>
  55. #endif
  56. #ifndef _COM_SUN_STAR_TEXT_VERTORIENTATION_HPP_
  57. #include <com/sun/star/text/VertOrientation.hpp>
  58. #endif
  59. #ifndef _COM_SUN_STAR_TEXT_XTEXTFRAMESSUPPLIER_HPP_
  60. #include <com/sun/star/text/XTextFramesSupplier.hpp>
  61. #endif
  62. #ifndef _COM_SUN_STAR_TEXT_XTEXTGRAPHICOBJECTSSUPPLIER_HPP_
  63. #include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
  64. #endif
  65. #ifndef _COM_SUN_STAR_TEXT_XTEXTEMBEDDEDOBJECTSSUPPLIER_HPP_
  66. #include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
  67. #endif
  68. #ifndef _COM_SUN_STAR_DRAWING_XDRAWPAGESUPPLIER_HPP_
  69. #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
  70. #endif
  71. #ifndef _COM_SUN_STAR_DOCUMENT_XEMBEDDEDOBJECTSUPPLIER_HPP_
  72. #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
  73. #endif
  74. #ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP_
  75. #include <com/sun/star/document/XEventsSupplier.hpp>
  76. #endif
  77. #ifndef _COM_SUN_STAR_TEXT_XTEXTSECTION_HPP_
  78. #include <com/sun/star/text/XTextSection.hpp>
  79. #endif
  80. #ifndef _COM_SUN_STAR_DRAWING_XCONTROLSHAPE_HPP_
  81. #include <com/sun/star/drawing/XControlShape.hpp>
  82. #endif
  83. #ifndef _XMLOFF_TXTEXPPR_HXX
  84. #include "txtexppr.hxx"
  85. #endif
  86. #ifndef _XMLOFF_XMLUCONV_HXX
  87. #include "xmluconv.hxx"
  88. #endif
  89. #ifndef _XMLOFF_XMLANCHORTYPEPROPHDL_HXX
  90. #include "XMLAnchorTypePropHdl.hxx"
  91. #endif
  92. #ifndef _XEXPTRANSFORM_HXX
  93. #include "xexptran.hxx"
  94. #endif
  95. #ifndef _XMLOFF_NMSPMAP_HXX
  96. #include "nmspmap.hxx"
  97. #endif
  98. #ifndef _XMLOFF_XMLEXP_HXX
  99. #include "xmlexp.hxx"
  100. #endif
  101. #ifndef _XMLOFF_TXTFLDE_HXX
  102. #include "txtflde.hxx"
  103. #endif
  104. #ifndef _XMLOFF_TXTPRMAP_HXX
  105. #include "txtprmap.hxx"
  106. #endif
  107. #ifndef _XMLOFF_XMLIMAGEMAPEXPORT_HXX_
  108. #include "XMLImageMapExport.hxx"
  109. #endif
  110. #ifndef _XMLOFF_XMLTEXTNUMRULEINFO_HXX
  111. #include "XMLTextNumRuleInfo.hxx"
  112. #endif
  113. #ifndef _XMLOFF_XMLTEXTLISTAUTOSTYLEPOOL_HXX
  114. #include "XMLTextListAutoStylePool.hxx"
  115. #endif
  116. #ifndef _XMLOFF_XMLSECTIONEXPORT_HXX_
  117. #include "XMLSectionExport.hxx"
  118. #endif
  119. #ifndef _XMLOFF_XMLINDEXMARKEXPORT_HXX_
  120. #include "XMLIndexMarkExport.hxx"
  121. #endif
  122. #ifndef _XMLOFF_XMLEVENTEXPORT_HXX
  123. #include "XMLEventExport.hxx"
  124. #endif
  125. #ifndef _XMLOFF_XMLREDLINEEXPORT_HXX
  126. #include "XMLRedlineExport.hxx"
  127. #endif
  128. #ifndef _XMLOFF_MULTIPROPERTYSETHELPER_HXX
  129. #include "MultiPropertySetHelper.hxx"
  130. #endif
  131. #ifndef _XMLOFF_XMLTEXTCHARSTYLENAMESELEMENTEXPORT_HXX
  132. #include "XMLTextCharStyleNamesElementExport.hxx"
  133. #endif
  134. namespace binfilter {
  135. using namespace ::rtl;
  136. using namespace ::std;
  137. using namespace ::com::sun::star;
  138. using namespace ::com::sun::star::uno;
  139. using namespace ::com::sun::star::lang;
  140. using namespace ::com::sun::star::beans;
  141. using namespace ::com::sun::star::container;
  142. using namespace ::com::sun::star::text;
  143. using namespace ::com::sun::star::util;
  144. using namespace ::com::sun::star::drawing;
  145. using namespace ::com::sun::star::document;
  146. using namespace ::com::sun::star::frame;
  147. using namespace ::binfilter::xmloff::token;
  148. typedef OUString *OUStringPtr;
  149. SV_DECL_PTRARR_DEL( OUStrings_Impl, OUStringPtr, 20, 10 )
  150. SV_IMPL_PTRARR( OUStrings_Impl, OUStringPtr )
  151. SV_DECL_PTRARR_SORT_DEL( OUStringsSort_Impl, OUStringPtr, 20, 10 )
  152. SV_IMPL_OP_PTRARR_SORT( OUStringsSort_Impl, OUStringPtr )
  153. #ifdef DBG_UTIL
  154. static int txtparae_bContainsIllegalCharacters = sal_False;
  155. #endif
  156. // The following map shows which property values are required:
  157. //
  158. // property auto style pass export
  159. // --------------------------------------------------------
  160. // ParaStyleName if style exists always
  161. // ParaConditionalStyleName if style exists always
  162. // NumberingRules if style exists always
  163. // TextSection always always
  164. // ParaChapterNumberingLevel never always
  165. // The conclusion is that for auto styles the first three properties
  166. // should be queried using a multi property set if, and only if, an
  167. // auto style needs to be exported. TextSection should be queried by
  168. // an individual call to getPropertyvalue, because this seems to be
  169. // less expensive than querying the first three properties if they aren't
  170. // required.
  171. // For the export pass all properties can be queried using a multi property
  172. // set.
  173. static const sal_Char* aParagraphPropertyNamesAuto[] =
  174. {
  175. "NumberingRules",
  176. "ParaConditionalStyleName",
  177. "ParaStyleName",
  178. NULL
  179. };
  180. enum eParagraphPropertyNamesEnumAuto
  181. {
  182. NUMBERING_RULES_AUTO = 0,
  183. PARA_CONDITIONAL_STYLE_NAME_AUTO = 1,
  184. PARA_STYLE_NAME_AUTO = 2
  185. };
  186. static const sal_Char* aParagraphPropertyNames[] =
  187. {
  188. "ParaChapterNumberingLevel",
  189. "ParaConditionalStyleName",
  190. "ParaStyleName",
  191. "TextSection",
  192. NULL
  193. };
  194. enum eParagraphPropertyNamesEnum
  195. {
  196. PARA_CHAPTER_NUMERBING_LEVEL = 0,
  197. PARA_CONDITIONAL_STYLE_NAME = 1,
  198. PARA_STYLE_NAME = 2,
  199. TEXT_SECTION = 3
  200. };
  201. void XMLTextParagraphExport::Add( sal_uInt16 nFamily,
  202. const Reference < XPropertySet > & rPropSet,
  203. const XMLPropertyState** ppAddStates)
  204. {
  205. UniReference < SvXMLExportPropertyMapper > xPropMapper;
  206. switch( nFamily )
  207. {
  208. case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
  209. xPropMapper = GetParaPropMapper();
  210. break;
  211. case XML_STYLE_FAMILY_TEXT_TEXT:
  212. xPropMapper = GetTextPropMapper();
  213. break;
  214. case XML_STYLE_FAMILY_TEXT_FRAME:
  215. xPropMapper = GetAutoFramePropMapper();
  216. break;
  217. case XML_STYLE_FAMILY_TEXT_SECTION:
  218. xPropMapper = GetSectionPropMapper();
  219. break;
  220. case XML_STYLE_FAMILY_TEXT_RUBY:
  221. xPropMapper = GetRubyPropMapper();
  222. break;
  223. }
  224. DBG_ASSERT( xPropMapper.is(), "There is the property mapper?" );
  225. vector< XMLPropertyState > xPropStates =
  226. xPropMapper->Filter( rPropSet );
  227. if( ppAddStates )
  228. {
  229. while( *ppAddStates )
  230. {
  231. xPropStates.push_back( **ppAddStates );
  232. ppAddStates++;
  233. }
  234. }
  235. if( xPropStates.size() > 0L )
  236. {
  237. Reference< XPropertySetInfo > xPropSetInfo =
  238. rPropSet->getPropertySetInfo();
  239. OUString sParent, sCondParent;
  240. Any aAny;
  241. sal_uInt16 nIgnoreProps = 0;
  242. switch( nFamily )
  243. {
  244. case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
  245. if( xPropSetInfo->hasPropertyByName( sParaStyleName ) )
  246. {
  247. aAny = rPropSet->getPropertyValue( sParaStyleName );
  248. aAny >>= sParent;
  249. }
  250. if( xPropSetInfo->hasPropertyByName( sParaConditionalStyleName ) )
  251. {
  252. aAny = rPropSet->getPropertyValue( sParaConditionalStyleName );
  253. aAny >>= sCondParent;
  254. }
  255. if( xPropSetInfo->hasPropertyByName( sNumberingRules ) )
  256. {
  257. aAny = rPropSet->getPropertyValue( sNumberingRules );
  258. Reference < XIndexReplace > xNumRule;
  259. aAny >>= xNumRule;
  260. if( xNumRule.is() && xNumRule->getCount() )
  261. {
  262. Reference < XNamed > xNamed( xNumRule, UNO_QUERY );
  263. OUString sName;
  264. if( xNamed.is() )
  265. sName = xNamed->getName();
  266. sal_Bool bAdd = !sName.getLength();
  267. if( !bAdd )
  268. {
  269. Reference < XPropertySet > xNumPropSet( xNumRule,
  270. UNO_QUERY );
  271. OUString sIsAutomatic( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) );
  272. if( xNumPropSet.is() &&
  273. xNumPropSet->getPropertySetInfo()
  274. ->hasPropertyByName( sIsAutomatic ) )
  275. {
  276. aAny = xNumPropSet->getPropertyValue( sIsAutomatic );
  277. bAdd = *(sal_Bool *)aAny.getValue();
  278. }
  279. else
  280. {
  281. bAdd = sal_True;
  282. }
  283. }
  284. if( bAdd )
  285. pListAutoPool->Add( xNumRule );
  286. }
  287. }
  288. break;
  289. case XML_STYLE_FAMILY_TEXT_TEXT:
  290. {
  291. // Get parent and remove hyperlinks (they aren't of interest)
  292. UniReference< XMLPropertySetMapper > xPM =
  293. xPropMapper->getPropertySetMapper();
  294. for( ::std::vector< XMLPropertyState >::iterator i
  295. = xPropStates.begin();
  296. nIgnoreProps < 2 && i != xPropStates.end();
  297. i++ )
  298. {
  299. switch( xPM->GetEntryContextId(i->mnIndex) )
  300. {
  301. case CTF_CHAR_STYLE_NAME:
  302. i->maValue >>= sParent;
  303. i->mnIndex = -1;
  304. nIgnoreProps++;
  305. break;
  306. case CTF_HYPERLINK_URL:
  307. i->mnIndex = -1;
  308. nIgnoreProps++;
  309. break;
  310. }
  311. }
  312. }
  313. break;
  314. case XML_STYLE_FAMILY_TEXT_FRAME:
  315. if( xPropSetInfo->hasPropertyByName( sFrameStyleName ) )
  316. {
  317. aAny = rPropSet->getPropertyValue( sFrameStyleName );
  318. aAny >>= sParent;
  319. }
  320. break;
  321. case XML_STYLE_FAMILY_TEXT_SECTION:
  322. case XML_STYLE_FAMILY_TEXT_RUBY:
  323. ; // section styles have no parents
  324. break;
  325. }
  326. if( (xPropStates.size() - nIgnoreProps) > 0 )
  327. {
  328. GetAutoStylePool().Add( nFamily, sParent, xPropStates );
  329. if( sCondParent.getLength() && sParent != sCondParent )
  330. GetAutoStylePool().Add( nFamily, sCondParent, xPropStates );
  331. }
  332. }
  333. }
  334. void XMLTextParagraphExport::Add( sal_uInt16 nFamily,
  335. MultiPropertySetHelper& rPropSetHelper,
  336. const Reference < XPropertySet > & rPropSet,
  337. const XMLPropertyState** ppAddStates)
  338. {
  339. UniReference < SvXMLExportPropertyMapper > xPropMapper;
  340. switch( nFamily )
  341. {
  342. case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
  343. xPropMapper = GetParaPropMapper();
  344. break;
  345. }
  346. DBG_ASSERT( xPropMapper.is(), "There is the property mapper?" );
  347. vector< XMLPropertyState > xPropStates =
  348. xPropMapper->Filter( rPropSet );
  349. if( ppAddStates )
  350. {
  351. while( *ppAddStates )
  352. {
  353. xPropStates.push_back( **ppAddStates );
  354. ppAddStates++;
  355. }
  356. }
  357. if( xPropStates.size() > 0L )
  358. {
  359. OUString sParent, sCondParent;
  360. Any aAny;
  361. switch( nFamily )
  362. {
  363. case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
  364. if( rPropSetHelper.hasProperty( PARA_STYLE_NAME_AUTO ) )
  365. {
  366. aAny = rPropSetHelper.getValue( PARA_STYLE_NAME_AUTO, rPropSet,
  367. sal_True );
  368. aAny >>= sParent;
  369. }
  370. if( rPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME_AUTO ) )
  371. {
  372. aAny = rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME_AUTO,
  373. rPropSet, sal_True );
  374. aAny >>= sCondParent;
  375. }
  376. if( rPropSetHelper.hasProperty( NUMBERING_RULES_AUTO ) )
  377. {
  378. aAny = rPropSetHelper.getValue( NUMBERING_RULES_AUTO,
  379. rPropSet, sal_True );
  380. Reference < XIndexReplace > xNumRule;
  381. aAny >>= xNumRule;
  382. if( xNumRule.is() && xNumRule->getCount() )
  383. {
  384. Reference < XNamed > xNamed( xNumRule, UNO_QUERY );
  385. OUString sName;
  386. if( xNamed.is() )
  387. sName = xNamed->getName();
  388. sal_Bool bAdd = !sName.getLength();
  389. if( !bAdd )
  390. {
  391. Reference < XPropertySet > xNumPropSet( xNumRule,
  392. UNO_QUERY );
  393. OUString sIsAutomatic( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) );
  394. if( xNumPropSet.is() &&
  395. xNumPropSet->getPropertySetInfo()
  396. ->hasPropertyByName( sIsAutomatic ) )
  397. {
  398. aAny = xNumPropSet->getPropertyValue( sIsAutomatic );
  399. bAdd = *(sal_Bool *)aAny.getValue();
  400. }
  401. else
  402. {
  403. bAdd = sal_True;
  404. }
  405. }
  406. if( bAdd )
  407. pListAutoPool->Add( xNumRule );
  408. }
  409. }
  410. break;
  411. }
  412. if( xPropStates.size() > 0 )
  413. {
  414. GetAutoStylePool().Add( nFamily, sParent, xPropStates );
  415. if( sCondParent.getLength() && sParent != sCondParent )
  416. GetAutoStylePool().Add( nFamily, sCondParent, xPropStates );
  417. }
  418. }
  419. }
  420. OUString XMLTextParagraphExport::Find(
  421. sal_uInt16 nFamily,
  422. const Reference < XPropertySet > & rPropSet,
  423. const OUString& rParent,
  424. const XMLPropertyState** ppAddStates) const
  425. {
  426. OUString sName( rParent );
  427. UniReference < SvXMLExportPropertyMapper > xPropMapper;
  428. switch( nFamily )
  429. {
  430. case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
  431. xPropMapper = GetParaPropMapper();
  432. break;
  433. case XML_STYLE_FAMILY_TEXT_FRAME:
  434. xPropMapper = GetAutoFramePropMapper();
  435. break;
  436. case XML_STYLE_FAMILY_TEXT_SECTION:
  437. xPropMapper = GetSectionPropMapper();
  438. break;
  439. case XML_STYLE_FAMILY_TEXT_RUBY:
  440. xPropMapper = GetRubyPropMapper();
  441. break;
  442. }
  443. DBG_ASSERT( xPropMapper.is(), "There is the property mapper?" );
  444. if( !xPropMapper.is() )
  445. return sName;
  446. vector< XMLPropertyState > xPropStates =
  447. xPropMapper->Filter( rPropSet );
  448. if( ppAddStates )
  449. {
  450. while( *ppAddStates )
  451. {
  452. xPropStates.push_back( **ppAddStates );
  453. ppAddStates++;
  454. }
  455. }
  456. if( xPropStates.size() > 0L )
  457. sName = GetAutoStylePool().Find( nFamily, sName, xPropStates );
  458. return sName;
  459. }
  460. OUString XMLTextParagraphExport::FindTextStyleAndHyperlink(
  461. const Reference < XPropertySet > & rPropSet,
  462. sal_Bool& rHyperlink,
  463. sal_Bool& rHasCharStyle,
  464. const XMLPropertyState** ppAddStates ) const
  465. {
  466. UniReference < SvXMLExportPropertyMapper > xPropMapper
  467. = GetTextPropMapper();
  468. vector< XMLPropertyState > xPropStates =
  469. xPropMapper->Filter( rPropSet );
  470. // Get parent and remove hyperlinks (they aren't of interest)
  471. OUString sName;
  472. rHyperlink = rHasCharStyle = sal_False;
  473. sal_uInt16 nIgnoreProps = 0;
  474. UniReference< XMLPropertySetMapper > xPM =
  475. xPropMapper->getPropertySetMapper();
  476. for( ::std::vector< XMLPropertyState >::iterator
  477. i = xPropStates.begin();
  478. nIgnoreProps < 2 && i != xPropStates.end();
  479. i++ )
  480. {
  481. switch( xPM->GetEntryContextId(i->mnIndex) )
  482. {
  483. case CTF_CHAR_STYLE_NAME:
  484. i->maValue >>= sName;
  485. i->mnIndex = -1;
  486. rHasCharStyle = sName.getLength() > 0;
  487. nIgnoreProps++;
  488. break;
  489. case CTF_HYPERLINK_URL:
  490. rHyperlink = sal_True;
  491. i->mnIndex = -1;
  492. nIgnoreProps++;
  493. break;
  494. }
  495. }
  496. if( ppAddStates )
  497. {
  498. while( *ppAddStates )
  499. {
  500. xPropStates.push_back( **ppAddStates );
  501. ppAddStates++;
  502. }
  503. }
  504. if( (xPropStates.size() - nIgnoreProps) > 0L )
  505. sName = GetAutoStylePool().Find( XML_STYLE_FAMILY_TEXT_TEXT, sName, xPropStates );
  506. return sName;
  507. }
  508. OUString XMLTextParagraphExport::FindTextStyle(
  509. const Reference < XPropertySet > & rPropSet,
  510. sal_Bool& rHasCharStyle ) const
  511. {
  512. sal_Bool bDummy;
  513. return FindTextStyleAndHyperlink( rPropSet, bDummy, rHasCharStyle );
  514. }
  515. void XMLTextParagraphExport::exportListChange(
  516. const XMLTextNumRuleInfo& rPrevInfo,
  517. const XMLTextNumRuleInfo& rNextInfo )
  518. {
  519. // end a list
  520. if( rPrevInfo.GetLevel() > 0 &&
  521. ( !rNextInfo.HasSameNumRules( rPrevInfo ) ||
  522. rNextInfo.GetLevel() < rPrevInfo.GetLevel() ||
  523. rNextInfo.IsRestart() ) )
  524. {
  525. sal_Int16 nPrevLevel = rPrevInfo.GetLevel();
  526. sal_Int16 nNextLevel =
  527. ( !rNextInfo.HasSameNumRules( rPrevInfo ) ||
  528. rNextInfo.IsRestart() ) ? 0 : rNextInfo.GetLevel();
  529. DBG_ASSERT( pListElements &&
  530. pListElements->Count() >= 2*(nNextLevel-nPrevLevel),
  531. "SwXMLExport::ExportListChange: list elements missing" );
  532. for( sal_Int16 i=nPrevLevel; i > nNextLevel; i-- )
  533. {
  534. for( sal_uInt16 j=0; j<2; j++ )
  535. {
  536. OUString *pElem = (*pListElements)[pListElements->Count()-1];
  537. pListElements->Remove( pListElements->Count()-1 );
  538. GetExport().EndElement( *pElem, sal_True );
  539. delete pElem;
  540. }
  541. }
  542. }
  543. // start a new list
  544. if( rNextInfo.GetLevel() > 0 &&
  545. ( !rPrevInfo.HasSameNumRules( rNextInfo ) ||
  546. rPrevInfo.GetLevel() < rNextInfo.GetLevel() ||
  547. rNextInfo.IsRestart() ) )
  548. {
  549. sal_Int16 nPrevLevel =
  550. ( !rNextInfo.HasSameNumRules( rPrevInfo ) ||
  551. rNextInfo.IsRestart() ) ? 0 : rPrevInfo.GetLevel();
  552. sal_Int16 nNextLevel = rNextInfo.GetLevel();
  553. // Find out whether this is the first application of the list or not.
  554. // For named lists, we use the internal name. For unnamed lists, we
  555. // use the generated name. This works well, because there are either
  556. // unnamed or either named lists only.
  557. sal_Bool bListExported = sal_False;
  558. OUString sName;
  559. if( rNextInfo.IsNamed() )
  560. sName = rNextInfo.GetName();
  561. else
  562. sName = pListAutoPool->Find( rNextInfo.GetNumRules() );
  563. DBG_ASSERT( sName.getLength(), "list without a name" );
  564. if( sName.getLength() )
  565. {
  566. bListExported = pExportedLists &&
  567. pExportedLists->Seek_Entry( (OUString *)&sName );
  568. if( !bListExported )
  569. {
  570. if( !pExportedLists )
  571. pExportedLists = new OUStringsSort_Impl;
  572. pExportedLists->Insert( new OUString(sName) );
  573. }
  574. }
  575. sal_Bool bContinue = !rNextInfo.IsRestart() && bListExported &&
  576. !rPrevInfo.HasSameNumRules( rNextInfo );
  577. for( sal_Int16 i=nPrevLevel; i < nNextLevel; i++)
  578. {
  579. // <text:ordered-list> or <text:unordered-list>
  580. GetExport().CheckAttrList();
  581. if( 0 == i )
  582. {
  583. // For named list, the name might be the name of an automatic
  584. // rule, so we have to take a look into the style pool.
  585. // For unnamed lists, we have done this already.
  586. if( rNextInfo.IsNamed() )
  587. {
  588. OUString sTmp( pListAutoPool->Find(
  589. rNextInfo.GetNumRules() ) );
  590. if( sTmp.getLength() )
  591. sName = sTmp;
  592. }
  593. GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
  594. sName );
  595. }
  596. if( bContinue && rNextInfo.IsOrdered() )
  597. GetExport().AddAttribute( XML_NAMESPACE_TEXT,
  598. XML_CONTINUE_NUMBERING, XML_TRUE );
  599. enum XMLTokenEnum eLName =
  600. rNextInfo.IsOrdered() ? XML_ORDERED_LIST
  601. : XML_UNORDERED_LIST;
  602. OUString *pElem = new OUString(
  603. GetExport().GetNamespaceMap().GetQNameByKey(
  604. XML_NAMESPACE_TEXT,
  605. GetXMLToken(eLName) ) );
  606. GetExport().IgnorableWhitespace();
  607. GetExport().StartElement( *pElem, sal_False );
  608. if( !pListElements )
  609. pListElements = new OUStrings_Impl;
  610. pListElements->Insert( pElem, pListElements->Count() );
  611. // <text:list-header> or <text:list-item>
  612. GetExport().CheckAttrList();
  613. if( rNextInfo.HasStartValue() )
  614. {
  615. OUStringBuffer aBuffer;
  616. aBuffer.append( (sal_Int32)rNextInfo.GetStartValue() );
  617. GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
  618. aBuffer.makeStringAndClear() );
  619. }
  620. eLName = (rNextInfo.IsNumbered() || i+1 < nNextLevel)
  621. ? XML_LIST_ITEM
  622. : XML_LIST_HEADER;
  623. pElem = new OUString( GetExport().GetNamespaceMap().GetQNameByKey(
  624. XML_NAMESPACE_TEXT,
  625. GetXMLToken(eLName) ) );
  626. GetExport().IgnorableWhitespace();
  627. GetExport().StartElement( *pElem, sal_False );
  628. pListElements->Insert( pElem, pListElements->Count() );
  629. }
  630. }
  631. if( rNextInfo.GetLevel() > 0 && rNextInfo.IsNumbered() &&
  632. rPrevInfo.HasSameNumRules( rNextInfo ) &&
  633. rPrevInfo.GetLevel() >= rNextInfo.GetLevel() &&
  634. !rNextInfo.IsRestart() )
  635. {
  636. // </text:list-item> or </text:list-header>
  637. DBG_ASSERT( pListElements && pListElements->Count() >= 2,
  638. "SwXMLExport::ExportListChange: list elements missing" );
  639. OUString *pElem = (*pListElements)[pListElements->Count()-1];
  640. GetExport().EndElement( *pElem, sal_True );
  641. pListElements->Remove( pListElements->Count()-1 );
  642. delete pElem;
  643. // <text:list-item>
  644. GetExport().CheckAttrList();
  645. if( rNextInfo.HasStartValue() )
  646. {
  647. OUStringBuffer aBuffer;
  648. aBuffer.append( (sal_Int32)rNextInfo.GetStartValue() );
  649. GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
  650. aBuffer.makeStringAndClear() );
  651. }
  652. pElem = new OUString( GetExport().GetNamespaceMap().GetQNameByKey(
  653. XML_NAMESPACE_TEXT,
  654. GetXMLToken(XML_LIST_ITEM) ) );
  655. GetExport().IgnorableWhitespace();
  656. GetExport().StartElement( *pElem, sal_False );
  657. pListElements->Insert( pElem, pListElements->Count() );
  658. }
  659. }
  660. XMLTextParagraphExport::XMLTextParagraphExport(
  661. SvXMLExport& rExp,
  662. SvXMLAutoStylePoolP & rASP
  663. ) :
  664. XMLStyleExport( rExp, OUString(), &rASP ),
  665. // rExport( rExp ),
  666. rAutoStylePool( rASP ),
  667. pListElements( 0 ),
  668. pExportedLists( 0 ),
  669. pListAutoPool( new XMLTextListAutoStylePool( this->GetExport() ) ),
  670. pFieldExport( 0 ),
  671. pPageTextFrameIdxs( 0 ),
  672. pPageGraphicIdxs( 0 ),
  673. pPageEmbeddedIdxs( 0 ),
  674. pPageShapeIdxs( 0 ),
  675. pFrameTextFrameIdxs( 0 ),
  676. pFrameGraphicIdxs( 0 ),
  677. pFrameEmbeddedIdxs( 0 ),
  678. pSectionExport( NULL ),
  679. pIndexMarkExport( NULL ),
  680. pRedlineExport( NULL ),
  681. pFrameShapeIdxs( 0 ),
  682. bBlock( sal_False ),
  683. bOpenRuby( sal_False ),
  684. sParagraphService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Paragraph")),
  685. sTableService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextTable")),
  686. sTextFieldService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField")),
  687. sTextFrameService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFrame")),
  688. sTextGraphicService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextGraphicObject")),
  689. sTextEmbeddedService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextEmbeddedObject")),
  690. sTextEndnoteService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Endnote")),
  691. sTextContentService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextContent")),
  692. sShapeService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Shape")),
  693. sParaStyleName(RTL_CONSTASCII_USTRINGPARAM("ParaStyleName")),
  694. sParaConditionalStyleName(RTL_CONSTASCII_USTRINGPARAM("ParaConditionalStyleName")),
  695. sParaChapterNumberingLevel(RTL_CONSTASCII_USTRINGPARAM("ParaChapterNumberingLevel")),
  696. sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName")),
  697. sCharStyleNames(RTL_CONSTASCII_USTRINGPARAM("CharStyleNames")),
  698. sFrameStyleName(RTL_CONSTASCII_USTRINGPARAM("FrameStyleName")),
  699. sTextField(RTL_CONSTASCII_USTRINGPARAM("TextField")),
  700. sText(RTL_CONSTASCII_USTRINGPARAM("Text")),
  701. sFrame(RTL_CONSTASCII_USTRINGPARAM("Frame")),
  702. sCategory(RTL_CONSTASCII_USTRINGPARAM("Category")),
  703. sNumberingRules(RTL_CONSTASCII_USTRINGPARAM("NumberingRules")),
  704. sTextPortionType(RTL_CONSTASCII_USTRINGPARAM("TextPortionType")),
  705. sFootnote(RTL_CONSTASCII_USTRINGPARAM("Footnote")),
  706. sBookmark(RTL_CONSTASCII_USTRINGPARAM("Bookmark")),
  707. sReferenceMark(RTL_CONSTASCII_USTRINGPARAM("ReferenceMark")),
  708. sIsCollapsed(RTL_CONSTASCII_USTRINGPARAM("IsCollapsed")),
  709. sIsStart(RTL_CONSTASCII_USTRINGPARAM("IsStart")),
  710. sReferenceId(RTL_CONSTASCII_USTRINGPARAM("ReferenceId")),
  711. sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType")),
  712. sPageStyleName(RTL_CONSTASCII_USTRINGPARAM("PageStyleName")),
  713. sPageDescName(RTL_CONSTASCII_USTRINGPARAM("PageDescName")),
  714. sPrefix(RTL_CONSTASCII_USTRINGPARAM("Prefix")),
  715. sStartAt(RTL_CONSTASCII_USTRINGPARAM("StartAt")),
  716. sSuffix(RTL_CONSTASCII_USTRINGPARAM("Suffix")),
  717. sPositionEndOfDoc(RTL_CONSTASCII_USTRINGPARAM("PositionEndOfDoc")),
  718. sFootnoteCounting(RTL_CONSTASCII_USTRINGPARAM("FootnoteCounting")),
  719. sEndNotice(RTL_CONSTASCII_USTRINGPARAM("EndNotice")),
  720. sBeginNotice(RTL_CONSTASCII_USTRINGPARAM("BeginNotice")),
  721. sFrameWidthAbsolute(RTL_CONSTASCII_USTRINGPARAM("FrameWidthAbsolute")),
  722. sFrameWidthPercent(RTL_CONSTASCII_USTRINGPARAM("FrameWidthPercent")),
  723. sFrameHeightAbsolute(RTL_CONSTASCII_USTRINGPARAM("FrameHeightAbsolute")),
  724. sFrameHeightPercent(RTL_CONSTASCII_USTRINGPARAM("FrameHeightPercent")),
  725. sWidth(RTL_CONSTASCII_USTRINGPARAM("Width")),
  726. sRelativeWidth(RTL_CONSTASCII_USTRINGPARAM("RelativeWidth")),
  727. sHeight(RTL_CONSTASCII_USTRINGPARAM("Height")),
  728. sRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("RelativeHeight")),
  729. sSizeType(RTL_CONSTASCII_USTRINGPARAM("SizeType")),
  730. sIsSyncWidthToHeight(RTL_CONSTASCII_USTRINGPARAM("IsSyncWidthToHeight")),
  731. sIsSyncHeightToWidth(RTL_CONSTASCII_USTRINGPARAM("IsSyncHeightToWidth")),
  732. sHoriOrient(RTL_CONSTASCII_USTRINGPARAM("HoriOrient")),
  733. sHoriOrientPosition(RTL_CONSTASCII_USTRINGPARAM("HoriOrientPosition")),
  734. sVertOrient(RTL_CONSTASCII_USTRINGPARAM("VertOrient")),
  735. sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition")),
  736. sChainNextName(RTL_CONSTASCII_USTRINGPARAM("ChainNextName")),
  737. sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType")),
  738. sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo")),
  739. sGraphicURL(RTL_CONSTASCII_USTRINGPARAM("GraphicURL")),
  740. sGraphicFilter(RTL_CONSTASCII_USTRINGPARAM("GraphicFilter")),
  741. sGraphicRotation(RTL_CONSTASCII_USTRINGPARAM("GraphicRotation")),
  742. sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText")),
  743. sHyperLinkURL(RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL")),
  744. sHyperLinkName(RTL_CONSTASCII_USTRINGPARAM("HyperLinkName")),
  745. sHyperLinkTarget(RTL_CONSTASCII_USTRINGPARAM("HyperLinkTarget")),
  746. sUnvisitedCharStyleName(RTL_CONSTASCII_USTRINGPARAM("UnvisitedCharStyleName")),
  747. sVisitedCharStyleName(RTL_CONSTASCII_USTRINGPARAM("VisitedCharStyleName")),
  748. sTextSection(RTL_CONSTASCII_USTRINGPARAM("TextSection")),
  749. sDocumentIndex(RTL_CONSTASCII_USTRINGPARAM("DocumentIndex")),
  750. sDocumentIndexMark(RTL_CONSTASCII_USTRINGPARAM("DocumentIndexMark")),
  751. sActualSize(RTL_CONSTASCII_USTRINGPARAM("ActualSize")),
  752. sContourPolyPolygon(RTL_CONSTASCII_USTRINGPARAM("ContourPolyPolygon")),
  753. sIsPixelContour(RTL_CONSTASCII_USTRINGPARAM("IsPixelContour")),
  754. sIsAutomaticContour(RTL_CONSTASCII_USTRINGPARAM("IsAutomaticContour")),
  755. sAnchorCharStyleName(RTL_CONSTASCII_USTRINGPARAM("AnchorCharStyleName")),
  756. sServerMap(RTL_CONSTASCII_USTRINGPARAM("ServerMap")),
  757. sRedline(RTL_CONSTASCII_USTRINGPARAM("Redline")),
  758. sRuby(RTL_CONSTASCII_USTRINGPARAM("Ruby")),
  759. sRubyText(RTL_CONSTASCII_USTRINGPARAM("RubyText")),
  760. sRubyAdjust(RTL_CONSTASCII_USTRINGPARAM("RubyAdjust")),
  761. sRubyCharStyleName(RTL_CONSTASCII_USTRINGPARAM("RubyCharStyleName")),
  762. bProgress( sal_False ),
  763. aCharStyleNamesPropInfoCache( sCharStyleNames )
  764. {
  765. UniReference < XMLPropertySetMapper > xPropMapper =
  766. new XMLTextPropertySetMapper( TEXT_PROP_MAP_PARA );
  767. xParaPropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
  768. GetExport() );
  769. OUString sFamily( GetXMLToken(XML_PARAGRAPH) );
  770. OUString sPrefix( 'P' );
  771. rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_PARAGRAPH, sFamily,
  772. xParaPropMapper, sPrefix );
  773. xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT );
  774. xTextPropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
  775. GetExport() );
  776. sFamily = OUString( GetXMLToken(XML_TEXT) );
  777. sPrefix = OUString( 'T' );
  778. rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_TEXT, sFamily,
  779. xTextPropMapper, sPrefix );
  780. xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_AUTO_FRAME );
  781. xAutoFramePropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
  782. GetExport() );
  783. sFamily = OUString( RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME) );
  784. sPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM( "fr" ) );
  785. rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_FRAME, sFamily,
  786. xAutoFramePropMapper, sPrefix );
  787. xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_SECTION );
  788. xSectionPropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
  789. GetExport() );
  790. sFamily = OUString( GetXMLToken( XML_SECTION ) );
  791. sPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM( "Sect" ) );
  792. rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_SECTION, sFamily,
  793. xSectionPropMapper, sPrefix );
  794. xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_RUBY );
  795. xRubyPropMapper = new SvXMLExportPropertyMapper( xPropMapper );
  796. sFamily = OUString( GetXMLToken( XML_RUBY ) );
  797. sPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM( "Ru" ) );
  798. rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_RUBY, sFamily,
  799. xRubyPropMapper, sPrefix );
  800. xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_FRAME );
  801. xFramePropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
  802. GetExport() );
  803. pSectionExport = new XMLSectionExport( rExp, *this );
  804. pIndexMarkExport = new XMLIndexMarkExport( rExp, *this );
  805. pRedlineExport = IsBlockMode() ? NULL : new XMLRedlineExport( rExp );
  806. // The text field helper needs a pre-constructed XMLPropertyState
  807. // to export the combined characters field. We construct that
  808. // here, because we need the text property mapper to do it.
  809. // construct Any value, then find index
  810. Any aAny;
  811. sal_Bool bTmp = sal_True;
  812. aAny.setValue(&bTmp, ::getBooleanCppuType());
  813. sal_Int32 nIndex = xTextPropMapper->getPropertySetMapper()->FindEntryIndex(
  814. "", XML_NAMESPACE_STYLE,
  815. GetXMLToken(XML_TEXT_COMBINE));
  816. pFieldExport = new XMLTextFieldExport( rExp, new XMLPropertyState( nIndex, aAny ) );
  817. }
  818. XMLTextParagraphExport::~XMLTextParagraphExport()
  819. {
  820. delete pRedlineExport;
  821. delete pIndexMarkExport;
  822. delete pSectionExport;
  823. delete pFieldExport;
  824. delete pListElements;
  825. delete pExportedLists;
  826. delete pListAutoPool;
  827. delete pPageTextFrameIdxs;
  828. delete pPageGraphicIdxs;
  829. delete pPageEmbeddedIdxs;
  830. delete pPageShapeIdxs;
  831. delete pFrameTextFrameIdxs;
  832. delete pFrameGraphicIdxs;
  833. delete pFrameEmbeddedIdxs;
  834. delete pFrameShapeIdxs;
  835. #ifdef DBG_UTIL
  836. txtparae_bContainsIllegalCharacters = sal_False;
  837. #endif
  838. }
  839. SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateShapeExtPropMapper(
  840. SvXMLExport& rExport )
  841. {
  842. UniReference < XMLPropertySetMapper > xPropMapper =
  843. new XMLTextPropertySetMapper( TEXT_PROP_MAP_SHAPE );
  844. return new XMLTextExportPropertySetMapper( xPropMapper, rExport );
  845. }
  846. SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateCharExtPropMapper(
  847. SvXMLExport& rExport)
  848. {
  849. XMLPropertySetMapper *pPropMapper =
  850. new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT );
  851. return new XMLTextExportPropertySetMapper( pPropMapper, rExport );
  852. }
  853. SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateParaExtPropMapper(
  854. SvXMLExport& rExport)
  855. {
  856. XMLPropertySetMapper *pPropMapper =
  857. new XMLTextPropertySetMapper( TEXT_PROP_MAP_SHAPE_PARA );
  858. return new XMLTextExportPropertySetMapper( pPropMapper, rExport );
  859. }
  860. void XMLTextParagraphExport::collectFrames( sal_Bool bBoundToFrameOnly )
  861. {
  862. Reference < XTextFramesSupplier > xTFS( GetExport().GetModel(), UNO_QUERY );
  863. if( xTFS.is() )
  864. {
  865. xTextFrames = Reference < XIndexAccess >( xTFS->getTextFrames(),
  866. UNO_QUERY );
  867. sal_Int32 nCount = xTextFrames->getCount();
  868. for( sal_Int32 i = 0; i < nCount; i++ )
  869. {
  870. Any aAny = xTextFrames->getByIndex( i );
  871. Reference < XTextFrame > xTxtFrame;
  872. aAny >>= xTxtFrame;
  873. Reference < XPropertySet > xPropSet( xTxtFrame, UNO_QUERY );
  874. aAny = xPropSet->getPropertyValue( sAnchorType );
  875. TextContentAnchorType eAnchor;
  876. aAny >>= eAnchor;
  877. switch( eAnchor )
  878. {
  879. case TextContentAnchorType_AT_PAGE:
  880. if( !bBoundToFrameOnly )
  881. {
  882. if( !pPageTextFrameIdxs )
  883. pPageTextFrameIdxs = new SvLongs;
  884. pPageTextFrameIdxs->Insert( i, pPageTextFrameIdxs->Count() );
  885. }
  886. break;
  887. case TextContentAnchorType_AT_FRAME:
  888. if( !pFrameTextFrameIdxs )
  889. pFrameTextFrameIdxs = new SvLongs;
  890. pFrameTextFrameIdxs->Insert( i, pFrameTextFrameIdxs->Count() );
  891. break;
  892. }
  893. }
  894. }
  895. Reference < XTextGraphicObjectsSupplier > xTGOS( GetExport().GetModel(),
  896. UNO_QUERY );
  897. if( xTGOS.is() )
  898. {
  899. xGraphics = Reference < XIndexAccess >( xTGOS->getGraphicObjects(),
  900. UNO_QUERY );
  901. sal_Int32 nCount = xGraphics->getCount();
  902. for( sal_Int32 i = 0; i < nCount; i++ )
  903. {
  904. Any aAny = xGraphics->getByIndex( i );
  905. Reference < XTextContent > xTxtCntnt;
  906. aAny >>= xTxtCntnt;
  907. Reference < XPropertySet > xPropSet( xTxtCntnt, UNO_QUERY );
  908. aAny = xPropSet->getPropertyValue( sAnchorType );
  909. TextContentAnchorType eAnchor;
  910. aAny >>= eAnchor;
  911. switch( eAnchor )
  912. {
  913. case TextContentAnchorType_AT_PAGE:
  914. if( !bBoundToFrameOnly )
  915. {
  916. if( !pPageGraphicIdxs )
  917. pPageGraphicIdxs = new SvLongs;
  918. pPageGraphicIdxs->Insert( i, pPageGraphicIdxs->Count() );
  919. }
  920. break;
  921. case TextContentAnchorType_AT_FRAME:
  922. if( !pFrameGraphicIdxs )
  923. pFrameGraphicIdxs = new SvLongs;
  924. pFrameGraphicIdxs->Insert( i, pFrameGraphicIdxs->Count() );
  925. break;
  926. }
  927. }
  928. }
  929. Reference < XTextEmbeddedObjectsSupplier > xTEOS( GetExport().GetModel(),
  930. UNO_QUERY );
  931. if( xTEOS.is() )
  932. {
  933. xEmbeddeds = Reference < XIndexAccess >( xTEOS->getEmbeddedObjects(),
  934. UNO_QUERY );
  935. sal_Int32 nCount = xEmbeddeds->getCount();
  936. for( sal_Int32 i = 0; i < nCount; i++ )
  937. {
  938. Any aAny = xEmbeddeds->getByIndex( i );
  939. Reference < XTextContent > xTxtCntnt;
  940. aAny >>= xTxtCntnt;
  941. Reference < XPropertySet > xPropSet( xTxtCntnt, UNO_QUERY );
  942. aAny = xPropSet->getPropertyValue( sAnchorType );
  943. TextContentAnchorType eAnchor;
  944. aAny >>= eAnchor;
  945. switch( eAnchor )
  946. {
  947. case TextContentAnchorType_AT_PAGE:
  948. if( !bBoundToFrameOnly )
  949. {
  950. if( !pPageEmbeddedIdxs )
  951. pPageEmbeddedIdxs = new SvLongs;
  952. pPageEmbeddedIdxs->Insert( i, pPageEmbeddedIdxs->Count() );
  953. }
  954. break;
  955. case TextContentAnchorType_AT_FRAME:
  956. if( !pFrameEmbeddedIdxs )
  957. pFrameEmbeddedIdxs = new SvLongs;
  958. pFrameEmbeddedIdxs->Insert( i, pFrameEmbeddedIdxs->Count() );
  959. break;
  960. }
  961. }
  962. }
  963. Reference < XDrawPageSupplier > xDPS( GetExport().GetModel(),
  964. UNO_QUERY );
  965. if( xDPS.is() )
  966. {
  967. xShapes = Reference < XIndexAccess >( xDPS->getDrawPage(),
  968. UNO_QUERY );
  969. sal_Int32 nCount = xShapes->getCount();
  970. for( sal_Int32 i = 0; i < nCount; i++ )
  971. {
  972. Any aAny = xShapes->getByIndex( i );
  973. Reference < XShape > xShape;
  974. aAny >>= xShape;
  975. if( !xShape.is() )
  976. continue;
  977. Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
  978. aAny = xPropSet->getPropertyValue( sAnchorType );
  979. TextContentAnchorType eAnchor;
  980. aAny >>= eAnchor;
  981. if( (TextContentAnchorType_AT_PAGE != eAnchor &&
  982. TextContentAnchorType_AT_FRAME != eAnchor) ||
  983. (TextContentAnchorType_AT_PAGE == eAnchor &&
  984. bBoundToFrameOnly ) )
  985. continue;
  986. Reference<XServiceInfo> xServiceInfo( xShape,
  987. UNO_QUERY );
  988. if( xServiceInfo->supportsService( sTextFrameService ) ||
  989. xServiceInfo->supportsService( sTextGraphicService ) ||
  990. xServiceInfo->supportsService( sTextEmbeddedService ) )
  991. continue;
  992. if( TextContentAnchorType_AT_PAGE == eAnchor )
  993. {
  994. if( !pPageShapeIdxs )
  995. pPageShapeIdxs = new SvLongs;
  996. pPageShapeIdxs->Insert( i, pPageShapeIdxs->Count() );
  997. }
  998. else
  999. {
  1000. if( !pFrameShapeIdxs )
  1001. pFrameShapeIdxs = new SvLongs;
  1002. pFrameShapeIdxs->Insert( i, pFrameShapeIdxs->Count() );
  1003. }
  1004. }
  1005. }
  1006. }
  1007. void XMLTextParagraphExport::exportPageFrames( sal_Bool bAutoStyles,
  1008. sal_Bool bProgress )
  1009. {
  1010. if( pPageTextFrameIdxs )
  1011. {
  1012. for( sal_uInt16 i = 0; i < pPageTextFrameIdxs->Count(); i++ )
  1013. {
  1014. Any aAny = xTextFrames->getByIndex( (*pPageTextFrameIdxs)[i] );
  1015. Reference < XTextFrame > xTxtFrame;
  1016. aAny >>= xTxtFrame;
  1017. Reference < XTextContent > xTxtCntnt( xTxtFrame, UNO_QUERY );
  1018. exportTextFrame( xTxtCntnt, bAutoStyles, bProgress );
  1019. }
  1020. }
  1021. if( pPageGraphicIdxs )
  1022. {
  1023. for( sal_uInt16 i = 0; i < pPageGraphicIdxs->Count(); i++ )
  1024. {
  1025. Any aAny = xGraphics->getByIndex( (*pPageGraphicIdxs)[i] );
  1026. Reference < XTextContent > xTxtCntnt;
  1027. aAny >>= xTxtCntnt;
  1028. exportTextGraphic( xTxtCntnt, bAutoStyles );
  1029. }
  1030. }
  1031. if( pPageEmbeddedIdxs )
  1032. {
  1033. for( sal_uInt16 i = 0; i < pPageEmbeddedIdxs->Count(); i++ )
  1034. {
  1035. Any aAny = xEmbeddeds->getByIndex( (*pPageEmbeddedIdxs)[i] );
  1036. Reference < XTextContent > xTxtCntnt;
  1037. aAny >>= xTxtCntnt;
  1038. exportTextEmbedded( xTxtCntnt, bAutoStyles );
  1039. }
  1040. }
  1041. if( pPageShapeIdxs )
  1042. {
  1043. for( sal_uInt16 i = 0; i < pPageShapeIdxs->Count(); i++ )
  1044. {
  1045. Any aAny = xShapes->getByIndex( (*pPageShapeIdxs)[i] );
  1046. Reference < XShape > xShape;
  1047. aAny >>= xShape;
  1048. Reference < XTextContent > xTxtCntnt( xShape, UNO_QUERY );
  1049. exportShape( xTxtCntnt, bAutoStyles );
  1050. }
  1051. }
  1052. }
  1053. sal_Bool lcl_txtpara_isFrameAnchor(
  1054. const Reference < XPropertySet > rPropSet,
  1055. const Reference < XTextFrame >& rParentTxtFrame )
  1056. {
  1057. Any aAny = rPropSet->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("AnchorFrame") ) );
  1058. Reference < XTextFrame > xAnchorTxtFrame;
  1059. aAny >>= xAnchorTxtFrame;
  1060. return xAnchorTxtFrame == rParentTxtFrame;
  1061. }
  1062. void XMLTextParagraphExport::exportFrameFrames(
  1063. sal_Bool bAutoStyles,
  1064. sal_Bool bProgress,
  1065. const Reference < XTextFrame > *pParentTxtFrame )
  1066. {
  1067. if( pFrameTextFrameIdxs && pFrameTextFrameIdxs->Count() )
  1068. {
  1069. Any aAny;
  1070. sal_uInt16 i = 0;
  1071. while( i < pFrameTextFrameIdxs->Count() )
  1072. {
  1073. aAny = xTextFrames->getByIndex( (*pFrameTextFrameIdxs)[i] );
  1074. Reference < XTextFrame > xTxtFrame;
  1075. aAny >>= xTxtFrame;
  1076. Reference < XPropertySet > xPropSet( xTxtFrame, UNO_QUERY );
  1077. if( lcl_txtpara_isFrameAnchor( xPropSet, *pParentTxtFrame ) )
  1078. {
  1079. if( !bAutoStyles )
  1080. pFrameTextFrameIdxs->Remove( i );
  1081. sal_uInt16 nOldCount = pFrameTextFrameIdxs->Count();
  1082. Reference < XTextContent > xTxtCntnt( xTxtFrame, UNO_QUERY );
  1083. exportTextFrame( xTxtCntnt, bAutoStyles, bProgress );
  1084. if( bAutoStyles )
  1085. i++;
  1086. else if( pFrameTextFrameIdxs->Count() != nOldCount )
  1087. i = 0;
  1088. }
  1089. else
  1090. i++;
  1091. }
  1092. }
  1093. if( pFrameGraphicIdxs && pFrameGraphicIdxs->Count() )
  1094. {
  1095. Any aAny;
  1096. sal_uInt16 i = 0;
  1097. while( i < pFrameGraphicIdxs->Count() )
  1098. {
  1099. aAny = xGraphics->getByIndex( (*pFrameGraphicIdxs)[i] );
  1100. Reference < XTextContent > xTxtCntnt;
  1101. aAny >>= xTxtCntnt;
  1102. Reference < XPropertySet > xPropSet( xTxtCntnt, UNO_QUERY );
  1103. if( lcl_txtpara_isFrameAnchor( xPropSet, *pParentTxtFrame ) )
  1104. {
  1105. if( !bAutoStyles )
  1106. pFrameGraphicIdxs->Remove( i );
  1107. sal_uInt16 nOldCount = pFrameGraphicIdxs->Count();
  1108. exportTextGraphic( xTxtCntnt, bAutoStyles );
  1109. if( bAutoStyles )
  1110. i++;
  1111. else if( pFrameGraphicIdxs->Count() != nOldCount )
  1112. i = 0;
  1113. }
  1114. else
  1115. i++;
  1116. }
  1117. }
  1118. if( pFrameEmbeddedIdxs && pFrameEmbeddedIdxs->Count() )
  1119. {
  1120. Any aAny;
  1121. sal_uInt16 i = 0;
  1122. while( i < pFrameEmbeddedIdxs->Count() )
  1123. {
  1124. aAny = xEmbeddeds->getByIndex( (*pFrameEmbeddedIdxs)[i] );
  1125. Reference < XEmbeddedObjectSupplier > xEOS;
  1126. aAny >>= xEOS;
  1127. Reference < XPropertySet > xPropSet( xEOS, UNO_QUERY );
  1128. if( lcl_txtpara_isFrameAnchor( xPropSet, *pParentTxtFrame ) )
  1129. {
  1130. if( !bAutoStyles )
  1131. pFrameEmbeddedIdxs->Remove( i );
  1132. sal_uInt16 nOldCount = pFrameEmbeddedIdxs->Count();
  1133. Reference < XTextContent > xTxtCntnt( xEOS, UNO_QUERY );
  1134. exportTextEmbedded( xTxtCntnt, bAutoStyles );
  1135. if( bAutoStyles )
  1136. i++;
  1137. else if( pFrameEmbeddedIdxs->Count() != nOldCount )
  1138. i = 0;
  1139. }
  1140. else
  1141. i++;
  1142. }
  1143. }
  1144. if( pFrameShapeIdxs && pFrameShapeIdxs->Count() )
  1145. {
  1146. Any aAny;
  1147. sal_uInt16 i = 0;
  1148. while( i < pFrameShapeIdxs->Count() )
  1149. {
  1150. aAny = xShapes->getByIndex( (*pFrameShapeIdxs)[i] );
  1151. Reference < XShape > xShape;
  1152. aAny >>= xShape;
  1153. Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
  1154. if( lcl_txtpara_isFrameAnchor( xPropSet, *pParentTxtFrame ) )
  1155. {
  1156. if( !bAutoStyles )
  1157. pFrameShapeIdxs->Remove( i );
  1158. sal_uInt16 nOldCount = pFrameShapeIdxs->Count();
  1159. Reference < XTextContent > xTxtCntnt( xShape, UNO_QUERY );
  1160. exportShape( xTxtCntnt, bAutoStyles );
  1161. if( bAutoStyles )
  1162. i++;
  1163. else if( pFrameShapeIdxs->Count() != nOldCount )
  1164. i = 0;
  1165. }
  1166. else
  1167. i++;
  1168. }
  1169. }
  1170. }
  1171. void XMLTextParagraphExport::exportText(
  1172. const Reference < XText > & rText,
  1173. sal_Bool bAutoStyles,
  1174. sal_Bool bProgress,
  1175. sal_Bool bExportParagraph )
  1176. {
  1177. if( bAutoStyles )
  1178. GetExport().GetShapeExport(); // make sure the graphics styles family
  1179. // is added
  1180. Reference < XEnumerationAccess > xEA( rText, UNO_QUERY );
  1181. Reference < XEnumeration > xParaEnum = xEA->createEnumeration();
  1182. Reference < XPropertySet > xPropertySet( rText, UNO_QUERY );
  1183. Reference < XTextSection > xBaseSection;
  1184. // #97718# footnotes don't supply paragraph enumerations in some cases
  1185. // This is always a bug, but at least we don't want to crash.
  1186. DBG_ASSERT( xParaEnum.is(), "We need a paragraph enumeration" );
  1187. if( ! xParaEnum.is() )
  1188. return;
  1189. sal_Bool bExportLevels = sal_True;
  1190. if (xPropertySet.is())
  1191. {
  1192. Reference < XPropertySetInfo > xInfo ( xPropertySet->getPropertySetInfo() );
  1193. if( xInfo.is() )
  1194. {
  1195. if (xInfo->hasPropertyByName( sTextSection ))
  1196. {
  1197. xPropertySet->getPropertyValue(sTextSection) >>= xBaseSection ;
  1198. }
  1199. // for applications that use the outliner we need to check if
  1200. // the current text object needs the level information exported
  1201. if( !bAutoStyles )
  1202. {
  1203. // fixme: move string to class member, couldn't do now because
  1204. // of no incompatible build
  1205. OUString sHasLevels( RTL_CONSTASCII_USTRINGPARAM("HasLevels") );
  1206. if (xInfo->hasPropertyByName( sHasLevels ) )
  1207. {
  1208. xPropertySet->getPropertyValue(sHasLevels) >>= bExportLevels;
  1209. }
  1210. }
  1211. }
  1212. }
  1213. // #96530# Export redlines at start & end of XText before & after
  1214. // exporting the text content enumeration
  1215. if( !bAutoStyles && (pRedlineExport != NULL) )
  1216. pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_True );
  1217. exportTextContentEnumeration( xParaEnum, bAutoStyles, xBaseSection,
  1218. bProgress, bExportParagraph, 0, bExportLevels );
  1219. if( !bAutoStyles && (pRedlineExport != NULL) )
  1220. pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_False );
  1221. }
  1222. void XMLTextParagraphExport::exportText(
  1223. const Reference < XText > & rText,
  1224. const Reference < XTextSection > & rBaseSection,
  1225. sal_Bool bAutoStyles,
  1226. sal_Bool bProgress,
  1227. sal_Bool bExportParagraph )
  1228. {
  1229. if( bAutoStyles )
  1230. GetExport().GetShapeExport(); // make sure the graphics styles family
  1231. // is added
  1232. Reference < XEnumerationAccess > xEA( rText, UNO_QUERY );
  1233. Reference < XEnumeration > xParaEnum = xEA->createEnumeration();
  1234. // #98165# don't continue without a paragraph enumeration
  1235. if( ! xParaEnum.is() )
  1236. return;
  1237. // #96530# Export redlines at start & end of XText before & after
  1238. // exporting the text content enumeration
  1239. Reference<XPropertySet> xPropertySet;
  1240. if( !bAutoStyles && (pRedlineExport != NULL) )
  1241. {
  1242. xPropertySet = Reference<XPropertySet>::query( rText );
  1243. pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_True );
  1244. }
  1245. exportTextContentEnumeration( xParaEnum, bAutoStyles, rBaseSection,
  1246. bProgress, bExportParagraph );
  1247. if( !bAutoStyles && (pRedlineExport != NULL) )
  1248. pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_False );
  1249. }
  1250. sal_Bool XMLTextParagraphExport::exportTextContentEnumeration(
  1251. const Reference < XEnumeration > & rContEnum,
  1252. sal_Bool bAutoStyles,
  1253. const Reference < XTextSection > & rBaseSection,
  1254. sal_Bool bProgress,
  1255. sal_Bool bExportParagraph,
  1256. const Reference < XPropertySet > *pRangePropSet,
  1257. sal_Bool bExportLevels)
  1258. {
  1259. DBG_ASSERT( rContEnum.is(), "No enumeration to export!" );
  1260. sal_Bool bHasMoreElements = rContEnum->hasMoreElements();
  1261. if( !bHasMoreElements )
  1262. return sal_False;
  1263. XMLTextNumRuleInfo aPrevNumInfo;
  1264. XMLTextNumRuleInfo aNextNumInfo;
  1265. sal_Bool bHasContent sal_False;
  1266. Reference<XTextSection> xCurrentTextSection = rBaseSection;
  1267. MultiPropertySetHelper aPropSetHelper(
  1268. bAutoStyles ? aParagraphPropertyNamesAuto :
  1269. aParagraphPropertyNames );
  1270. Any aAny;
  1271. sal_Bool bHoldElement = sal_False;
  1272. Reference < XTextContent > xTxtCntnt;
  1273. while( bHoldElement || bHasMoreElements )
  1274. {
  1275. if (bHoldElement)
  1276. {
  1277. bHoldElement = sal_False;
  1278. }
  1279. else
  1280. {
  1281. aAny = rContEnum->nextElement();
  1282. aAny >>= xTxtCntnt;
  1283. aPropSetHelper.resetValues();
  1284. }
  1285. Reference<XServiceInfo> xServiceInfo( xTxtCntnt, UNO_QUERY );
  1286. if( xServiceInfo->supportsService( sParagraphService ) )
  1287. {
  1288. if( bExportLevels )
  1289. {
  1290. if( bAutoStyles )
  1291. {
  1292. exportListAndSectionChange( xCurrentTextSection, xTxtCntnt,
  1293. aPrevNumInfo, aNextNumInfo,
  1294. bAutoStyles );
  1295. }
  1296. else
  1297. {
  1298. aNextNumInfo.Set( xTxtCntnt );
  1299. exportListAndSectionChange( xCurrentTextSection, aPropSetHelper,
  1300. TEXT_SECTION, xTxtCntnt,
  1301. aPrevNumInfo, aNextNumInfo,
  1302. bAutoStyles );
  1303. }
  1304. }
  1305. // if we found a mute section: skip all section content
  1306. if (pSectionExport->IsMuteSection(xCurrentTextSection))
  1307. {
  1308. // Make sure headings are exported anyway.
  1309. if( !bAutoStyles )
  1310. pSectionExport->ExportMasterDocHeadingDummies();
  1311. while (rContEnum->hasMoreElements() &&
  1312. pSectionExport->IsInSection( xCurrentTextSection,
  1313. xTxtCntnt, sal_True ))
  1314. {
  1315. aAny = rContEnum->nextElement();
  1316. aAny >>= xTxtCntnt;
  1317. aPropSetHelper.resetValues();
  1318. aNextNumInfo.Reset();
  1319. }
  1320. // the first non-mute element still needs to be processed
  1321. bHoldElement =
  1322. ! pSectionExport->IsInSection( xCurrentTextSection,
  1323. xTxtCntnt, sal_False );
  1324. }
  1325. else
  1326. exportParagraph( xTxtCntnt, bAutoStyles, bProgress,
  1327. bExportParagraph, aPropSetHelper );
  1328. bHasContent = sal_True;
  1329. }
  1330. else if( xServiceInfo->supportsService( sTableService ) )
  1331. {
  1332. if( !bAutoStyles )
  1333. {
  1334. aNextNumInfo.Reset();
  1335. }
  1336. exportListAndSectionChange( xCurrentTextSection, xTxtCntnt,
  1337. aPrevNumInfo, aNextNumInfo,
  1338. bAutoStyles );
  1339. if (! pSectionExport->IsMuteSection(xCurrentTextSection))
  1340. {
  1341. // export start + end redlines (for wholly redlined tables)
  1342. if ((! bAutoStyles) && (NULL != pRedlineExport))
  1343. pRedlineExport->ExportStartOrEndRedline(xTxtCntnt, sal_True);
  1344. exportTable( xTxtCntnt, bAutoStyles, bProgress );
  1345. if ((! bAutoStyles) && (NULL != pRedlineExport))
  1346. pRedlineExport->ExportStartOrEndRedline(xTxtCntnt, sal_False);
  1347. }
  1348. else if( !bAutoStyles )
  1349. {
  1350. // Make sure headings are exported anyway.
  1351. pSectionExport->ExportMasterDocHeadingDummies();
  1352. }
  1353. bHasContent = sal_True;
  1354. }
  1355. else if( xServiceInfo->supportsService( sTextFrameService ) )
  1356. {
  1357. exportTextFrame( xTxtCntnt, bAutoStyles, bProgress, pRangePropSet );
  1358. }
  1359. else if( xServiceInfo->supportsService( sTextGraphicService ) )
  1360. {
  1361. exportTextGraphic( xTxtCntnt, bAutoStyles, pRangePropSet );
  1362. }
  1363. else if( xServiceInfo->supportsService( sTextEmbeddedService ) )
  1364. {
  1365. exportTextEmbedded( xTxtCntnt, bAutoStyles, pRangePropSet );
  1366. }
  1367. else if( xServiceInfo->supportsService( sShapeService ) )
  1368. {
  1369. exportShape( xTxtCntnt, bAutoStyles, pRangePropSet );
  1370. }
  1371. else
  1372. {
  1373. DBG_ASSERT( !xTxtCntnt.is(), "unknown text content" );
  1374. }
  1375. if( !bAutoStyles )
  1376. {
  1377. aPrevNumInfo = aNextNumInfo;
  1378. }
  1379. bHasMoreElements = rContEnum->hasMoreElements();
  1380. }
  1381. if( bExportLevels && bHasContent && !bAutoStyles )
  1382. {
  1383. aNextNumInfo.Reset();
  1384. // close open lists and sections; no new styles
  1385. exportListAndSectionChange( xCurrentTextSection, rBaseSection,
  1386. aPrevNumInfo, aNextNumInfo,
  1387. bAutoStyles );
  1388. }
  1389. return sal_True;
  1390. }
  1391. void XMLTextParagraphExport::exportParagraph(
  1392. const Reference < XTextContent > & rTextContent,
  1393. sal_Bool bAutoStyles, sal_Bool bProgress, sal_Bool bExportParagraph,
  1394. MultiPropertySetHelper& rPropSetHelper)
  1395. {
  1396. sal_Int8 nOutlineLevel = -1;
  1397. if( bProgress )
  1398. {
  1399. ProgressBarHelper *pProgress = GetExport().GetProgressBarHelper();
  1400. pProgress->SetValue( pProgress->GetValue()+1 );
  1401. }
  1402. // get property set or multi property set and initialize helper
  1403. Reference<XMultiPropertySet> xMultiPropSet( rTextContent, UNO_QUERY );
  1404. Reference<XPropertySet> xPropSet( rTextContent, UNO_QUERY );
  1405. // check for supported properties
  1406. if( !rPropSetHelper.checkedProperties() )
  1407. rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
  1408. // if( xMultiPropSet.is() )
  1409. // rPropSetHelper.getValues( xMultiPropSet );
  1410. // else
  1411. // rPropSetHelper.getValues( xPropSet );
  1412. Any aAny;
  1413. if( bExportParagraph )
  1414. {
  1415. if( bAutoStyles )
  1416. {
  1417. Add( XML_STYLE_FAMILY_TEXT_PARAGRAPH, rPropSetHelper, xPropSet );
  1418. }
  1419. else
  1420. {
  1421. OUString sStyle;
  1422. if( rPropSetHelper.hasProperty( PARA_STYLE_NAME ) )
  1423. {
  1424. if( xMultiPropSet.is() )
  1425. aAny = rPropSetHelper.getValue( PARA_STYLE_NAME,
  1426. xMultiPropSet );
  1427. else
  1428. aAny = rPropSetHelper.getValue( PARA_STYLE_NAME,
  1429. xPropSet );
  1430. aAny >>= sStyle;
  1431. }
  1432. OUString sAutoStyle( sStyle );
  1433. sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_PARAGRAPH, xPropSet, sStyle );
  1434. if( sAutoStyle.getLength() )
  1435. GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
  1436. sAutoStyle );
  1437. if( rPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME ) )
  1438. {
  1439. OUString sCondStyle;
  1440. if( xMultiPropSet.is() )
  1441. aAny = rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME,
  1442. xMultiPropSet );
  1443. else
  1444. aAny = rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME,
  1445. xPropSet );
  1446. aAny >>= sCondStyle;
  1447. if( sCondStyle != sStyle )
  1448. {
  1449. sCondStyle = Find( XML_STYLE_FAMILY_TEXT_PARAGRAPH, xPropSet,
  1450. sCondStyle );
  1451. if( sCondStyle.getLength() )
  1452. GetExport().AddAttribute( XML_NAMESPACE_TEXT,
  1453. XML_COND_STYLE_NAME,
  1454. sCondStyle );
  1455. }
  1456. }
  1457. if( rPropSetHelper.hasProperty( PARA_CHAPTER_NUMERBING_LEVEL ) )
  1458. {
  1459. if( xMultiPropSet.is() )
  1460. aAny = rPropSetHelper.getValue( PARA_CHAPTER_NUMERBING_LEVEL,
  1461. xMultiPropSet );
  1462. else
  1463. aAny = rPropSetHelper.getValue( PARA_CHAPTER_NUMERBING_LEVEL,
  1464. xPropSet );
  1465. aAny >>= nOutlineLevel;
  1466. if( -1 != nOutlineLevel )
  1467. {
  1468. OUStringBuffer sTmp;
  1469. sTmp.append( (sal_Int32)nOutlineLevel+1L );
  1470. GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_LEVEL,
  1471. sTmp.makeStringAndClear() );
  1472. }
  1473. }
  1474. }
  1475. }
  1476. Reference < XEnumerationAccess > xEA( rTextContent, UNO_QUERY );
  1477. Reference < XEnumeration > xTextEnum = xEA->createEnumeration();
  1478. Reference < XEnumeration> xContentEnum;
  1479. Reference < XContentEnumerationAccess > xCEA( rTextContent, UNO_QUERY );
  1480. if( xCEA.is() )
  1481. xContentEnum = xCEA->createContentEnumeration( sTextContentService );
  1482. sal_Bool bHasContentEnum = xContentEnum.is() &&
  1483. xContentEnum->hasMoreElements();
  1484. Reference < XTextSection > xSection;
  1485. if( bHasContentEnum )
  1486. {
  1487. // For the auto styles, the multi property set helper is only used
  1488. // if hard attributes are existing. Therfor, it seems to be a better
  1489. // strategy to have the TextSection property seperate, because otherwise
  1490. // we always retrieve the style names even if they are not required.
  1491. if( bAutoStyles )
  1492. {
  1493. if( xPropSet->getPropertySetInfo()->hasPropertyByName( sTextSection ) )
  1494. {
  1495. aAny = xPropSet->getPropertyValue( sTextSection );
  1496. aAny >>= xSection;
  1497. }
  1498. }
  1499. else
  1500. {
  1501. if( rPropSetHelper.hasProperty( TEXT_SECTION ) )
  1502. {
  1503. aAny = rPropSetHelper.getValue( TEXT_SECTION );
  1504. aAny >>= xSection;
  1505. }
  1506. }
  1507. }
  1508. if( bAutoStyles )
  1509. {
  1510. sal_Bool bPrevCharIsSpace = sal_True;
  1511. if( bHasContentEnum )
  1512. bPrevCharIsSpace = !exportTextContentEnumeration(
  1513. xContentEnum, bAutoStyles, xSection,
  1514. bProgress );
  1515. exportTextRangeEnumeration( xTextEnum, bAutoStyles, bProgress );
  1516. }
  1517. else
  1518. {
  1519. sal_Bool bPrevCharIsSpace = sal_True;
  1520. enum XMLTokenEnum eElem =
  1521. -1 == nOutlineLevel ? XML_P : XML_H;
  1522. SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, eElem,
  1523. sal_True, sal_False );
  1524. if( bHasContentEnum )
  1525. bPrevCharIsSpace = !exportTextContentEnumeration(
  1526. xContentEnum, bAutoStyles, xSection,
  1527. bProgress );
  1528. exportTextRangeEnumeration( xTextEnum, bAutoStyles, bProgress,
  1529. bPrevCharIsSpace );
  1530. }
  1531. }
  1532. // bookmarks, reference marks (and TOC marks) are the same except for the
  1533. // element names. We use the same method for export and it an array with
  1534. // the proper element names
  1535. static const enum XMLTokenEnum lcl_XmlReferenceElements[] = {
  1536. XML_REFERENCE_MARK, XML_REFERENCE_MARK_START, XML_REFERENCE_MARK_END };
  1537. static const enum XMLTokenEnum lcl_XmlBookmarkElements[] = {
  1538. XML_BOOKMARK, XML_BOOKMARK_START, XML_BOOKMARK_END };
  1539. void XMLTextParagraphExport::exportTextRangeEnumeration(
  1540. const Reference < XEnumeration > & rTextEnum,
  1541. sal_Bool bAutoStyles, sal_Bool bProgress,
  1542. sal_Bool bPrvChrIsSpc )
  1543. {
  1544. sal_Bool bPrevCharIsSpace = bPrvChrIsSpc;
  1545. Any aAny;
  1546. while( rTextEnum->hasMoreElements() )
  1547. {
  1548. aAny = rTextEnum->nextElement();
  1549. Reference < XTextRange > xTxtRange;
  1550. aAny >>= xTxtRange;
  1551. Reference<XPropertySet> xPropSet(xTxtRange, UNO_QUERY);
  1552. Reference<XPropertySetInfo> xPropInfo =
  1553. xPropSet->getPropertySetInfo();
  1554. if (xPropInfo->hasPropertyByName(sTextPortionType))
  1555. {
  1556. aAny = xPropSet->getPropertyValue(sTextPortionType);
  1557. OUString sType;
  1558. aAny >>= sType;
  1559. if( sType.equals(sText))
  1560. {
  1561. exportTextRange( xTxtRange, bAutoStyles,
  1562. bPrevCharIsSpace );
  1563. }
  1564. else if( sType.equals(sTextField))
  1565. {
  1566. exportTextField( xTxtRange, bAutoStyles );
  1567. bPrevCharIsSpace = sal_False;
  1568. }
  1569. else if( sType.equals( sFrame ) )
  1570. {
  1571. Reference < XEnumeration> xContentEnum;
  1572. Reference < XContentEnumerationAccess > xCEA( xTxtRange,
  1573. UNO_QUERY );
  1574. if( xCEA.is() )
  1575. xContentEnum = xCEA->createContentEnumeration(
  1576. sTextContentService );
  1577. // frames are never in sections
  1578. Reference<XTextSection> xSection;
  1579. if( xContentEnum.is() )
  1580. exportTextContentEnumeration( xContentEnum,
  1581. bAutoStyles,
  1582. xSection, bProgress, sal_True,
  1583. &xPropSet );
  1584. bPrevCharIsSpace = sal_False;
  1585. }
  1586. else if (sType.equals(sFootnote))
  1587. {
  1588. exportTextFootnote(xPropSet,
  1589. xTxtRange->getString(),
  1590. bAutoStyles, bProgress );
  1591. bPrevCharIsSpace = sal_False;
  1592. }
  1593. else if (sType.equals(sBookmark))
  1594. {
  1595. exportTextMark(xPropSet,
  1596. sBookmark,
  1597. lcl_XmlBookmarkElements,
  1598. bAutoStyles);
  1599. }
  1600. else if (sType.equals(sReferenceMark))
  1601. {
  1602. exportTextMark(xPropSet,
  1603. sReferenceMark,
  1604. lcl_XmlReferenceElements,
  1605. bAutoStyles);
  1606. }
  1607. else if (sType.equals(sDocumentIndexMark))
  1608. {
  1609. pIndexMarkExport->ExportIndexMark(xPropSet, bAutoStyles);
  1610. }
  1611. else if (sType.equals(sRedline))
  1612. {
  1613. if (NULL != pRedlineExport)
  1614. pRedlineExport->ExportChange(xPropSet, bAutoStyles);
  1615. }
  1616. else if (sType.equals(sRuby))
  1617. {
  1618. exportRuby(xPropSet, bAutoStyles);
  1619. }
  1620. else
  1621. DBG_ERROR("unknown text portion type");
  1622. }
  1623. else
  1624. {
  1625. Reference<XServiceInfo> xServiceInfo( xTxtRange, UNO_QUERY );
  1626. if( xServiceInfo->supportsService( sTextFieldService ) )
  1627. {
  1628. exportTextField( xTxtRange, bAutoStyles );
  1629. bPrevCharIsSpace = sal_False;
  1630. }
  1631. else
  1632. {
  1633. // no TextPortionType property -> non-Writer app -> text
  1634. exportTextRange( xTxtRange, bAutoStyles, bPrevCharIsSpace );
  1635. }
  1636. }
  1637. }
  1638. DBG_ASSERT( !bOpenRuby, "Red Alert: Ruby still open!" );
  1639. }
  1640. void XMLTextParagraphExport::exportTable(
  1641. const Reference < XTextContent > & rTextContent,
  1642. sal_Bool bAutoStyles, sal_Bool bProgress )
  1643. {
  1644. }
  1645. void XMLTextParagraphExport::exportTextField(
  1646. const Reference < XTextRange > & rTextRange,
  1647. sal_Bool bAutoStyles )
  1648. {
  1649. Reference < XPropertySet > xPropSet( rTextRange, UNO_QUERY );
  1650. // non-Writer apps need not support Property TextField, so test first
  1651. if (xPropSet->getPropertySetInfo()->hasPropertyByName( sTextField ))
  1652. {
  1653. Any aAny = xPropSet->getPropertyValue( sTextField );
  1654. Reference < XTextField > xTxtFld;
  1655. aAny >>= xTxtFld;
  1656. DBG_ASSERT( xTxtFld.is(), "text field missing" );
  1657. if( xTxtFld.is() )
  1658. {
  1659. if( bAutoStyles )
  1660. {
  1661. pFieldExport->ExportFieldAutoStyle( xTxtFld );
  1662. }
  1663. else
  1664. {
  1665. pFieldExport->ExportField( xTxtFld );
  1666. }
  1667. }
  1668. else
  1669. {
  1670. // write only characters
  1671. GetExport().Characters(rTextRange->getString());
  1672. }
  1673. }
  1674. }
  1675. void XMLTextParagraphExport::exportTextMark(
  1676. const Reference<XPropertySet> & rPropSet,
  1677. const OUString sProperty,
  1678. const enum XMLTokenEnum pElements[],
  1679. sal_Bool bAutoStyles)
  1680. {
  1681. // mib said: "Hau wech!"
  1682. //
  1683. // (Originally, I'd export a span element in case the (book|reference)mark
  1684. // was formatted. This actually makes a difference in case some pervert
  1685. // sets a point reference mark in the document and, say, formats it bold.
  1686. // This basically meaningless formatting will now been thrown away
  1687. // (aka cleaned up), since mib said: ... dvo
  1688. if (!bAutoStyles)
  1689. {
  1690. // get reference (as text content)
  1691. Any aAny;
  1692. aAny = rPropSet->getPropertyValue(sProperty);
  1693. Reference<XTextContent> xRefMark;
  1694. aAny >>= xRefMark;
  1695. // name element
  1696. Reference<XNamed> xName(xRefMark, UNO_QUERY);
  1697. GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME,
  1698. xName->getName());
  1699. // start, end, or point-reference?
  1700. sal_Int8 nElement;
  1701. aAny = rPropSet->getPropertyValue(sIsCollapsed);
  1702. if( *(sal_Bool *)aAny.getValue() )
  1703. {
  1704. nElement = 0;
  1705. }
  1706. else
  1707. {
  1708. aAny = rPropSet->getPropertyValue(sIsStart);
  1709. nElement = *(sal_Bool *)aAny.getValue() ? 1 : 2;
  1710. }
  1711. // export element
  1712. DBG_ASSERT(pElements != NULL, "illegal element array");
  1713. DBG_ASSERT(nElement >= 0, "illegal element number");
  1714. DBG_ASSERT(nElement <= 2, "illegal element number");
  1715. SvXMLElementExport aElem(GetExport(),
  1716. XML_NAMESPACE_TEXT, pElements[nElement],
  1717. sal_False, sal_False);
  1718. }
  1719. // else: no styles. (see above)
  1720. }
  1721. sal_Bool lcl_txtpara_isBoundAsChar(
  1722. const Reference < XPropertySet > & rPropSet,
  1723. const Reference < XPropertySetInfo > & rPropSetInfo )
  1724. {
  1725. sal_Bool bIsBoundAsChar = sal_False;
  1726. OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) );
  1727. if( rPropSetInfo->hasPropertyByName( sAnchorType ) )
  1728. {
  1729. Any aAny =
  1730. rPropSet->getPropertyValue( sAnchorType );
  1731. TextContentAnchorType eAnchor;
  1732. aAny >>= eAnchor;
  1733. bIsBoundAsChar = TextContentAnchorType_AS_CHARACTER == eAnchor;
  1734. }
  1735. return bIsBoundAsChar;
  1736. }
  1737. sal_Int32 XMLTextParagraphExport::addTextFrameAttributes(
  1738. const Reference < XPropertySet >& rPropSet,
  1739. sal_Bool bShape )
  1740. {
  1741. sal_Int32 nShapeFeatures = SEF_DEFAULT;
  1742. // draw:name (#97662#: not for shapes, since those names will be
  1743. // treated in the shape export)
  1744. if( !bShape )
  1745. {
  1746. Reference < XNamed > xNamed( rPropSet, UNO_QUERY );
  1747. if( xNamed.is() )
  1748. {
  1749. OUString sName( xNamed->getName() );
  1750. if( sName.getLength() )
  1751. GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
  1752. xNamed->getName() );
  1753. }
  1754. }
  1755. Any aAny;
  1756. OUStringBuffer sValue;
  1757. // text:anchor-type
  1758. aAny = rPropSet->getPropertyValue( sAnchorType );
  1759. TextContentAnchorType eAnchor = TextContentAnchorType_AT_PARAGRAPH;
  1760. aAny >>= eAnchor;
  1761. {
  1762. XMLAnchorTypePropHdl aAnchorTypeHdl;
  1763. OUString sTmp;
  1764. aAnchorTypeHdl.exportXML( sTmp, aAny,
  1765. GetExport().GetMM100UnitConverter() );
  1766. GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_ANCHOR_TYPE, sTmp );
  1767. }
  1768. // text:anchor-page-number
  1769. if( TextContentAnchorType_AT_PAGE == eAnchor )
  1770. {
  1771. aAny = rPropSet->getPropertyValue( sAnchorPageNo );
  1772. sal_Int16 nPage=0;
  1773. aAny >>= nPage;
  1774. GetExport().GetMM100UnitConverter().convertNumber( sValue,
  1775. (sal_Int32)nPage );
  1776. GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_ANCHOR_PAGE_NUMBER,
  1777. sValue.makeStringAndClear() );
  1778. }
  1779. else
  1780. {
  1781. // #92210#
  1782. nShapeFeatures |= SEF_EXPORT_NO_WS;
  1783. }
  1784. if( !bShape )
  1785. {
  1786. // svg:x
  1787. sal_Int16 nHoriOrient = HoriOrientation::NONE;
  1788. aAny = rPropSet->getPropertyValue( sHoriOrient );
  1789. aAny >>= nHoriOrient;
  1790. if( HoriOrientation::NONE == nHoriOrient )
  1791. {
  1792. sal_Int32 nPos = 0;
  1793. Any aAny = rPropSet->getPropertyValue( sHoriOrientPosition );
  1794. aAny >>= nPos;
  1795. GetExport().GetMM100UnitConverter().convertMeasure( sValue, nPos );
  1796. GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_X,
  1797. sValue.makeStringAndClear() );
  1798. }
  1799. }
  1800. else if( TextContentAnchorType_AS_CHARACTER == eAnchor )
  1801. nShapeFeatures = (nShapeFeatures & ~SEF_EXPORT_X);
  1802. if( !bShape || TextContentAnchorType_AS_CHARACTER == eAnchor )
  1803. {
  1804. // svg:y
  1805. sal_Int16 nVertOrient = VertOrientation::NONE;
  1806. aAny = rPropSet->getPropertyValue( sVertOrient );
  1807. aAny >>= nVertOrient;
  1808. if( VertOrientation::NONE == nVertOrient )
  1809. {
  1810. sal_Int32 nPos = 0;
  1811. Any aAny = rPropSet->getPropertyValue( sVertOrientPosition );
  1812. aAny >>= nPos;
  1813. GetExport().GetMM100UnitConverter().convertMeasure( sValue, nPos );
  1814. GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_Y,
  1815. sValue.makeStringAndClear() );
  1816. }
  1817. if( bShape )
  1818. nShapeFeatures = (nShapeFeatures & ~SEF_EXPORT_Y);
  1819. }
  1820. Reference< XPropertySetInfo > xPropSetInfo = rPropSet->getPropertySetInfo();
  1821. // svg:width
  1822. if( xPropSetInfo->hasPropertyByName( sWidth ) )
  1823. {
  1824. sal_Int32 nWidth = 0;
  1825. aAny = rPropSet->getPropertyValue( sWidth );
  1826. aAny >>= nWidth;
  1827. GetExport().GetMM100UnitConverter().convertMeasure( sValue, nWidth );
  1828. GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_WIDTH,
  1829. sValue.makeStringAndClear() );
  1830. }
  1831. sal_Bool bSyncWidth = sal_False;
  1832. if( xPropSetInfo->hasPropertyByName( sIsSyncWidthToHeight ) )
  1833. {
  1834. aAny = rPropSet->getPropertyValue( sIsSyncWidthToHeight );
  1835. bSyncWidth = *(sal_Bool *)aAny.getValue();
  1836. if( bSyncWidth )
  1837. GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
  1838. XML_SCALE );
  1839. }
  1840. if( !bSyncWidth && xPropSetInfo->hasPropertyByName( sRelativeWidth ) )
  1841. {
  1842. sal_Int16 nRelWidth = 0;
  1843. aAny = rPropSet->getPropertyValue( sRelativeWidth );
  1844. aAny >>= nRelWidth;
  1845. DBG_ASSERT( nRelWidth >= 0 && nRelWidth <= 254,
  1846. "Got illegal relative width from API" );
  1847. if( nRelWidth > 0 )
  1848. {
  1849. GetExport().GetMM100UnitConverter().convertPercent( sValue,
  1850. nRelWidth );
  1851. GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
  1852. sValue.makeStringAndClear() );
  1853. }
  1854. }
  1855. // svg:height, fo:min-height or style:rel-height
  1856. sal_Int16 nSizeType = SizeType::FIX;
  1857. if( xPropSetInfo->hasPropertyByName( sSizeType ) )
  1858. {
  1859. aAny = rPropSet->getPropertyValue( sSizeType );
  1860. aAny >>= nSizeType;
  1861. }
  1862. sal_Bool bSyncHeight = sal_False;
  1863. if( xPropSetInfo->hasPropertyByName( sIsSyncHeightToWidth ) )
  1864. {
  1865. aAny = rPropSet->getPropertyValue( sIsSyncHeightToWidth );
  1866. bSyncHeight = *(sal_Bool *)aAny.getValue();
  1867. }
  1868. sal_Int16 nRelHeight = 0;
  1869. if( !bSyncHeight && xPropSetInfo->hasPropertyByName( sRelativeHeight ) )
  1870. {
  1871. aAny = rPropSet->getPropertyValue( sRelativeHeight );
  1872. aAny >>= nRelHeight;
  1873. }
  1874. if( xPropSetInfo->hasPropertyByName( sHeight ) )
  1875. {
  1876. sal_Int32 nHeight = 0;
  1877. aAny = rPropSet->getPropertyValue( sHeight );
  1878. aAny >>= nHeight;
  1879. GetExport().GetMM100UnitConverter().convertMeasure( sValue,
  1880. nHeight );
  1881. if( SizeType::FIX != nSizeType && 0==nRelHeight && !bSyncHeight )
  1882. GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MIN_HEIGHT,
  1883. sValue.makeStringAndClear() );
  1884. else
  1885. GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_HEIGHT,
  1886. sValue.makeStringAndClear() );
  1887. }
  1888. if( bSyncHeight )
  1889. {
  1890. GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_HEIGHT,
  1891. SizeType::MIN == nSizeType ? XML_SCALE_MIN : XML_SCALE );
  1892. }
  1893. else if( nRelHeight > 0 )
  1894. {
  1895. GetExport().GetMM100UnitConverter().convertPercent( sValue,
  1896. nRelHeight );
  1897. if( SizeType::MIN == nSizeType )
  1898. GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MIN_HEIGHT,
  1899. sValue.makeStringAndClear() );
  1900. else
  1901. GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_HEIGHT,
  1902. sValue.makeStringAndClear() );
  1903. }
  1904. OUString sZOrder( RTL_CONSTASCII_USTRINGPARAM( "ZOrder" ) );
  1905. if( xPropSetInfo->hasPropertyByName( sZOrder ) )
  1906. {
  1907. sal_Int32 nZIndex = 0;
  1908. aAny = rPropSet->getPropertyValue( sZOrder );
  1909. aAny >>= nZIndex;
  1910. if( -1 != nZIndex )
  1911. {
  1912. GetExport().GetMM100UnitConverter().convertNumber( sValue,
  1913. nZIndex );
  1914. GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_ZINDEX,
  1915. sValue.makeStringAndClear() );
  1916. }
  1917. }
  1918. return nShapeFeatures;
  1919. }
  1920. void XMLTextParagraphExport::exportAnyTextFrame(
  1921. const Reference < XTextContent > & rTxtCntnt,
  1922. FrameType eType,
  1923. sal_Bool bAutoStyles,
  1924. sal_Bool bProgress,
  1925. const Reference < XPropertySet > *pRangePropSet)
  1926. {
  1927. Reference < XPropertySet > xPropSet( rTxtCntnt, UNO_QUERY );
  1928. if( bAutoStyles )
  1929. {
  1930. if( FT_EMBEDDED == eType )
  1931. _collectTextEmbeddedAutoStyles( xPropSet );
  1932. else
  1933. Add( XML_STYLE_FAMILY_TEXT_FRAME, xPropSet );
  1934. if( pRangePropSet && lcl_txtpara_isBoundAsChar( xPropSet,
  1935. xPropSet->getPropertySetInfo() ) )
  1936. Add( XML_STYLE_FAMILY_TEXT_TEXT, *pRangePropSet );
  1937. switch( eType )
  1938. {
  1939. case FT_TEXT:
  1940. {
  1941. // frame bound frames
  1942. Reference < XTextFrame > xTxtFrame( rTxtCntnt, UNO_QUERY );
  1943. Reference < XText > xTxt = xTxtFrame->getText();
  1944. collectFramesBoundToFrameAutoStyles( xTxtFrame, bProgress );
  1945. exportText( xTxt, bAutoStyles, bProgress, sal_True );
  1946. }
  1947. break;
  1948. case FT_SHAPE:
  1949. {
  1950. Reference < XShape > xShape( rTxtCntnt, UNO_QUERY );
  1951. GetExport().GetShapeExport()->collectShapeAutoStyles( xShape );
  1952. }
  1953. break;
  1954. }
  1955. }
  1956. else
  1957. {
  1958. Reference< XPropertySetInfo > xPropSetInfo =
  1959. xPropSet->getPropertySetInfo();
  1960. Reference< XPropertyState > xPropState( xPropSet, UNO_QUERY );
  1961. {
  1962. sal_Bool bAddCharStyles = pRangePropSet &&
  1963. lcl_txtpara_isBoundAsChar( xPropSet, xPropSetInfo );
  1964. sal_Bool bIsUICharStyle;
  1965. OUString sStyle;
  1966. if( bAddCharStyles )
  1967. sStyle = FindTextStyle( *pRangePropSet, bIsUICharStyle );
  1968. else
  1969. bIsUICharStyle = sal_False;
  1970. XMLTextCharStyleNamesElementExport aCharStylesExport(
  1971. GetExport(), bIsUICharStyle &&
  1972. aCharStyleNamesPropInfoCache.hasProperty(
  1973. *pRangePropSet ),
  1974. *pRangePropSet, sCharStyleNames );
  1975. if( sStyle.getLength() )
  1976. GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
  1977. sStyle );
  1978. {
  1979. SvXMLElementExport aElem( GetExport(), sStyle.getLength() > 0,
  1980. XML_NAMESPACE_TEXT, XML_SPAN, sal_False, sal_False );
  1981. {
  1982. SvXMLElementExport aElem( GetExport(),
  1983. FT_SHAPE != eType &&
  1984. addHyperlinkAttributes( xPropSet,
  1985. xPropState,xPropSetInfo ),
  1986. XML_NAMESPACE_DRAW, XML_A, sal_False, sal_False );
  1987. switch( eType )
  1988. {
  1989. case FT_TEXT:
  1990. _exportTextFrame( xPropSet, xPropSetInfo, bProgress );
  1991. break;
  1992. case FT_GRAPHIC:
  1993. _exportTextGraphic( xPropSet, xPropSetInfo );
  1994. break;
  1995. case FT_EMBEDDED:
  1996. _exportTextEmbedded( xPropSet, xPropSetInfo );
  1997. break;
  1998. case FT_SHAPE:
  1999. {
  2000. Reference < XShape > xShape( rTxtCntnt, UNO_QUERY );
  2001. sal_Int32 nFeatures =
  2002. addTextFrameAttributes( xPropSet, sal_True );
  2003. GetExport().GetShapeExport()
  2004. ->exportShape( xShape, nFeatures );
  2005. }
  2006. break;
  2007. }
  2008. }
  2009. }
  2010. }
  2011. }
  2012. }
  2013. void XMLTextParagraphExport::_exportTextFrame(
  2014. const Reference < XPropertySet > & rPropSet,
  2015. const Reference < XPropertySetInfo > & rPropSetInfo,
  2016. sal_Bool bProgress )
  2017. {
  2018. Reference < XTextFrame > xTxtFrame( rPropSet, UNO_QUERY );
  2019. Reference < XText > xTxt = xTxtFrame->getText();
  2020. OUString sStyle;
  2021. Any aAny;
  2022. if( rPropSetInfo->hasPropertyByName( sFrameStyleName ) )
  2023. {
  2024. aAny = rPropSet->getPropertyValue( sFrameStyleName );
  2025. aAny >>= sStyle;
  2026. }
  2027. OUString sAutoStyle( sStyle );
  2028. sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_FRAME, rPropSet, sStyle );
  2029. if( sAutoStyle.getLength() )
  2030. GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE_NAME,
  2031. sAutoStyle );
  2032. addTextFrameAttributes( rPropSet, sal_False );
  2033. // draw:chain-next-name
  2034. if( rPropSetInfo->hasPropertyByName( sChainNextName ) )
  2035. {
  2036. OUString sNext;
  2037. aAny = rPropSet->getPropertyValue( sChainNextName );
  2038. if( (aAny >>= sNext) && sNext.getLength() > 0 )
  2039. GetExport().AddAttribute( XML_NAMESPACE_DRAW,
  2040. XML_CHAIN_NEXT_NAME,
  2041. sNext );
  2042. }
  2043. SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW,
  2044. XML_TEXT_BOX, sal_False, sal_True );
  2045. // frame bound frames
  2046. exportFramesBoundToFrame( xTxtFrame, bProgress );
  2047. // script:events
  2048. Reference<XEventsSupplier> xEventsSupp( xTxtFrame, UNO_QUERY );
  2049. GetExport().GetEventExport().Export(xEventsSupp);
  2050. // image map
  2051. GetExport().GetImageMapExport().Export( rPropSet );
  2052. exportText( xTxt, sal_False, bProgress, sal_True );
  2053. }
  2054. void XMLTextParagraphExport::exportContour(
  2055. const Reference < XPropertySet > & rPropSet,
  2056. const Reference < XPropertySetInfo > & rPropSetInfo )
  2057. {
  2058. if( !rPropSetInfo->hasPropertyByName( sContourPolyPolygon ) )
  2059. return;
  2060. Any aAny = rPropSet->getPropertyValue( sContourPolyPolygon );
  2061. PointSequenceSequence aSourcePolyPolygon;
  2062. aAny >>= aSourcePolyPolygon;
  2063. if( !aSourcePolyPolygon.getLength() )
  2064. return;
  2065. awt::Point aPoint( 0, 0 );
  2066. awt::Size aSize( 0, 0 );
  2067. sal_Int32 nPolygons = aSourcePolyPolygon.getLength();
  2068. const PointSequence *pPolygons = aSourcePolyPolygon.getConstArray();
  2069. while( nPolygons-- )
  2070. {
  2071. sal_Int32 nPoints = pPolygons->getLength();
  2072. const awt::Point *pPoints = pPolygons->getConstArray();
  2073. while( nPoints-- )
  2074. {
  2075. if( aSize.Width < pPoints->X )
  2076. aSize.Width = pPoints->X;
  2077. if( aSize.Height < pPoints->Y )
  2078. aSize.Height = pPoints->Y;
  2079. pPoints++;
  2080. }
  2081. pPolygons++;
  2082. }
  2083. sal_Bool bPixel = sal_False;
  2084. if( rPropSetInfo->hasPropertyByName( sIsPixelContour ) )
  2085. {
  2086. aAny = rPropSet->getPropertyValue( sIsPixelContour );
  2087. bPixel = *(sal_Bool *)aAny.getValue();
  2088. }
  2089. // svg: width
  2090. OUStringBuffer aStringBuffer( 10 );
  2091. if( bPixel )
  2092. GetExport().GetMM100UnitConverter().convertMeasurePx(aStringBuffer, aSize.Width);
  2093. else
  2094. GetExport().GetMM100UnitConverter().convertMeasure(aStringBuffer, aSize.Width);
  2095. GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_WIDTH,
  2096. aStringBuffer.makeStringAndClear() );
  2097. // svg: height
  2098. if( bPixel )
  2099. GetExport().GetMM100UnitConverter().convertMeasurePx(aStringBuffer, aSize.Height);
  2100. else
  2101. GetExport().GetMM100UnitConverter().convertMeasure(aStringBuffer, aSize.Height);
  2102. GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_HEIGHT,
  2103. aStringBuffer.makeStringAndClear() );
  2104. // svg:viewbox
  2105. SdXMLImExViewBox aViewBox(0, 0, aSize.Width, aSize.Height);
  2106. GetExport().AddAttribute(XML_NAMESPACE_SVG, XML_VIEWBOX,
  2107. aViewBox.GetExportString(GetExport().GetMM100UnitConverter()));
  2108. sal_Int32 nOuterCnt( aSourcePolyPolygon.getLength() );
  2109. enum XMLTokenEnum eElem = XML_TOKEN_INVALID;
  2110. if( 1L == nOuterCnt )
  2111. {
  2112. // simple polygon shape, can be written as svg:points sequence
  2113. /*const*/ PointSequence* pSequence =
  2114. (PointSequence*)aSourcePolyPolygon.getConstArray();
  2115. SdXMLImExPointsElement aPoints( pSequence, aViewBox, aPoint,
  2116. aSize, GetExport().GetMM100UnitConverter() );
  2117. // write point array
  2118. GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_POINTS,
  2119. aPoints.GetExportString());
  2120. eElem = XML_CONTOUR_POLYGON;
  2121. }
  2122. else
  2123. {
  2124. // polypolygon, needs to be written as a svg:path sequence
  2125. /*const*/ PointSequence* pOuterSequence =
  2126. (PointSequence*)aSourcePolyPolygon.getConstArray();
  2127. if(pOuterSequence)
  2128. {
  2129. // prepare svx:d element export
  2130. SdXMLImExSvgDElement aSvgDElement( aViewBox );
  2131. for(sal_Int32 a(0L); a < nOuterCnt; a++)
  2132. {
  2133. /*const*/ PointSequence* pSequence = pOuterSequence++;
  2134. if(pSequence)
  2135. {
  2136. aSvgDElement.AddPolygon(pSequence, 0L, aPoint,
  2137. aSize, GetExport().GetMM100UnitConverter(),
  2138. sal_True );
  2139. }
  2140. }
  2141. // write point array
  2142. GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_D,
  2143. aSvgDElement.GetExportString());
  2144. eElem = XML_CONTOUR_PATH;
  2145. }
  2146. }
  2147. if( rPropSetInfo->hasPropertyByName( sIsAutomaticContour ) )
  2148. {
  2149. aAny = rPropSet->getPropertyValue( sIsAutomaticContour );
  2150. if( *(sal_Bool *)aAny.getValue() )
  2151. GetExport().AddAttribute( XML_NAMESPACE_DRAW,
  2152. XML_RECREATE_ON_EDIT, XML_TRUE );
  2153. }
  2154. // write object now
  2155. SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW, eElem,
  2156. sal_True, sal_True );
  2157. }
  2158. void XMLTextParagraphExport::_exportTextGraphic(
  2159. const Reference < XPropertySet > & rPropSet,
  2160. const Reference < XPropertySetInfo > & rPropSetInfo )
  2161. {
  2162. OUString sStyle;
  2163. Any aAny;
  2164. if( rPropSetInfo->hasPropertyByName( sFrameStyleName ) )
  2165. {
  2166. aAny = rPropSet->getPropertyValue( sFrameStyleName );
  2167. aAny >>= sStyle;
  2168. }
  2169. OUString sAutoStyle( sStyle );
  2170. sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_FRAME, rPropSet, sStyle );
  2171. if( sAutoStyle.getLength() )
  2172. GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE_NAME,
  2173. sAutoStyle );
  2174. addTextFrameAttributes( rPropSet, sal_False );
  2175. // xlink:href
  2176. OUString sOrigURL;
  2177. aAny = rPropSet->getPropertyValue( sGraphicURL );
  2178. aAny >>= sOrigURL;
  2179. OUString sURL = GetExport().AddEmbeddedGraphicObject( sOrigURL );
  2180. setTextEmbeddedGraphicURL( rPropSet, sURL );
  2181. // If there still is no url, then then graphic is empty
  2182. if( sURL.getLength() )
  2183. {
  2184. GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sURL );
  2185. GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
  2186. GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
  2187. GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE,
  2188. XML_ONLOAD );
  2189. }
  2190. // draw:filter-name
  2191. OUString sGrfFilter;
  2192. aAny = rPropSet->getPropertyValue( sGraphicFilter );
  2193. aAny >>= sGrfFilter;
  2194. if( sGrfFilter.getLength() )
  2195. GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_FILTER_NAME,
  2196. sGrfFilter );
  2197. // svg:transform
  2198. aAny = rPropSet->getPropertyValue( sGraphicRotation );
  2199. sal_Int16 nVal;
  2200. aAny >>= nVal;
  2201. if( nVal != 0 )
  2202. {
  2203. OUStringBuffer sRet( GetXMLToken(XML_ROTATE).getLength()+4 );
  2204. sRet.append( GetXMLToken(XML_ROTATE));
  2205. sRet.append( (sal_Unicode)'(' );
  2206. GetExport().GetMM100UnitConverter().convertNumber( sRet, (sal_Int32)nVal );
  2207. sRet.append( (sal_Unicode)')' );
  2208. GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_TRANSFORM,
  2209. sRet.makeStringAndClear() );
  2210. }
  2211. SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW,
  2212. XML_IMAGE, sal_False, sal_True );
  2213. // optional office:binary-data
  2214. GetExport().AddEmbeddedGraphicObjectAsBase64( sOrigURL );
  2215. // script:events
  2216. Reference<XEventsSupplier> xEventsSupp( rPropSet, UNO_QUERY );
  2217. GetExport().GetEventExport().Export(xEventsSupp);
  2218. // svg:desc
  2219. exportAlternativeText( rPropSet, rPropSetInfo );
  2220. /*
  2221. OUString sAltText;
  2222. aAny = rPropSet->getPropertyValue( sAlternativeText );
  2223. aAny >>= sAltText;
  2224. if( sAltText.getLength() )
  2225. {
  2226. SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_SVG,
  2227. XML_DESC, sal_True, sal_False );
  2228. GetExport().Characters( sAltText );
  2229. }
  2230. */
  2231. // image map
  2232. GetExport().GetImageMapExport().Export( rPropSet );
  2233. // draw:contour
  2234. exportContour( rPropSet, rPropSetInfo );
  2235. }
  2236. void XMLTextParagraphExport::_collectTextEmbeddedAutoStyles(
  2237. const Reference < XPropertySet > & rPropSet )
  2238. {
  2239. DBG_ASSERT( !this, "no API implementation avialable" );
  2240. }
  2241. void XMLTextParagraphExport::_exportTextEmbedded(
  2242. const Reference < XPropertySet > & rPropSet,
  2243. const Reference < XPropertySetInfo > & rPropSetInfo )
  2244. {
  2245. DBG_ASSERT( !this, "no API implementation avialable" );
  2246. }
  2247. void XMLTextParagraphExport::exportEvents( const Reference < XPropertySet > & rPropSet )
  2248. {
  2249. // script:events
  2250. Reference<XEventsSupplier> xEventsSupp( rPropSet, UNO_QUERY );
  2251. GetExport().GetEventExport().Export(xEventsSupp);
  2252. // image map
  2253. OUString sImageMap(RTL_CONSTASCII_USTRINGPARAM("ImageMap"));
  2254. if (rPropSet->getPropertySetInfo()->hasPropertyByName(sImageMap))
  2255. GetExport().GetImageMapExport().Export( rPropSet );
  2256. }
  2257. void XMLTextParagraphExport::exportAlternativeText(
  2258. const Reference < XPropertySet > & rPropSet,
  2259. const Reference < XPropertySetInfo > & rPropSetInfo )
  2260. {
  2261. // svg:desc
  2262. if( rPropSetInfo->hasPropertyByName( sAlternativeText ) )
  2263. {
  2264. OUString sAltText;
  2265. Any aAny = rPropSet->getPropertyValue( sAlternativeText );
  2266. aAny >>= sAltText;
  2267. if( sAltText.getLength() )
  2268. {
  2269. SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_SVG,
  2270. XML_DESC, sal_True, sal_False );
  2271. GetExport().Characters( sAltText );
  2272. }
  2273. }
  2274. }
  2275. void XMLTextParagraphExport::setTextEmbeddedGraphicURL(
  2276. const Reference < XPropertySet >& rPropSet,
  2277. OUString& rStreamName ) const
  2278. {
  2279. }
  2280. sal_Bool XMLTextParagraphExport::addHyperlinkAttributes(
  2281. const Reference < XPropertySet > & rPropSet,
  2282. const Reference < XPropertyState > & rPropState,
  2283. const Reference < XPropertySetInfo > & rPropSetInfo )
  2284. {
  2285. sal_Bool bExport = sal_False;
  2286. Any aAny;
  2287. OUString sHRef, sName, sTargetFrame, sUStyleName, sVStyleName;
  2288. sal_Bool bServerMap = sal_False;
  2289. if( rPropSetInfo->hasPropertyByName( sHyperLinkURL ) &&
  2290. ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
  2291. rPropState->getPropertyState( sHyperLinkURL ) ) )
  2292. {
  2293. aAny= rPropSet->getPropertyValue( sHyperLinkURL );
  2294. aAny >>= sHRef;
  2295. if( sHRef.getLength() > 0 )
  2296. bExport = sal_True;
  2297. }
  2298. if( rPropSetInfo->hasPropertyByName( sHyperLinkName ) &&
  2299. ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
  2300. rPropState->getPropertyState( sHyperLinkName ) ) )
  2301. {
  2302. aAny = rPropSet->getPropertyValue( sHyperLinkName );
  2303. aAny >>= sName;
  2304. if( sName.getLength() > 0 )
  2305. bExport = sal_True;
  2306. }
  2307. if( rPropSetInfo->hasPropertyByName( sHyperLinkTarget ) &&
  2308. ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
  2309. rPropState->getPropertyState( sHyperLinkTarget ) ) )
  2310. {
  2311. aAny = rPropSet->getPropertyValue( sHyperLinkTarget );
  2312. aAny >>= sTargetFrame;
  2313. if( sTargetFrame.getLength() )
  2314. bExport = sal_True;
  2315. }
  2316. if( rPropSetInfo->hasPropertyByName( sServerMap ) &&
  2317. ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
  2318. rPropState->getPropertyState( sServerMap ) ) )
  2319. {
  2320. aAny = rPropSet->getPropertyValue( sServerMap );
  2321. bServerMap = *(sal_Bool *)aAny.getValue();
  2322. if( bServerMap )
  2323. bExport = sal_True;
  2324. }
  2325. if( rPropSetInfo->hasPropertyByName( sUnvisitedCharStyleName ) &&
  2326. ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
  2327. rPropState->getPropertyState( sUnvisitedCharStyleName ) ) )
  2328. {
  2329. aAny = rPropSet->getPropertyValue( sUnvisitedCharStyleName );
  2330. aAny >>= sUStyleName;
  2331. if( sUStyleName.getLength() )
  2332. bExport = sal_True;
  2333. }
  2334. if( rPropSetInfo->hasPropertyByName( sVisitedCharStyleName ) &&
  2335. ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
  2336. rPropState->getPropertyState( sVisitedCharStyleName ) ) )
  2337. {
  2338. aAny = rPropSet->getPropertyValue( sVisitedCharStyleName );
  2339. aAny >>= sVStyleName;
  2340. if( sVStyleName.getLength() )
  2341. bExport = sal_True;
  2342. }
  2343. if( bExport )
  2344. {
  2345. GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
  2346. GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, GetExport().GetRelativeReference( sHRef ) );
  2347. if( sName.getLength() > 0 )
  2348. GetExport().AddAttribute( XML_NAMESPACE_OFFICE, XML_NAME, sName );
  2349. if( sTargetFrame.getLength() )
  2350. {
  2351. GetExport().AddAttribute( XML_NAMESPACE_OFFICE,
  2352. XML_TARGET_FRAME_NAME, sTargetFrame );
  2353. enum XMLTokenEnum eTok =
  2354. sTargetFrame.equalsAsciiL( "_blank", sizeof("_blank")-1 )
  2355. ? XML_NEW : XML_REPLACE;
  2356. GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, eTok );
  2357. }
  2358. if( bServerMap )
  2359. GetExport().AddAttribute( XML_NAMESPACE_OFFICE,
  2360. XML_SERVER_MAP, XML_TRUE );
  2361. if( sUStyleName.getLength() )
  2362. GetExport().AddAttribute( XML_NAMESPACE_TEXT,
  2363. XML_STYLE_NAME, sUStyleName );
  2364. if( sVStyleName.getLength() )
  2365. GetExport().AddAttribute( XML_NAMESPACE_TEXT,
  2366. XML_VISITED_STYLE_NAME, sVStyleName );
  2367. }
  2368. return bExport;
  2369. }
  2370. void XMLTextParagraphExport::exportTextRange(
  2371. const Reference < XTextRange > & rTextRange,
  2372. sal_Bool bAutoStyles,
  2373. sal_Bool& rPrevCharIsSpace )
  2374. {
  2375. Reference < XPropertySet > xPropSet( rTextRange, UNO_QUERY );
  2376. if( bAutoStyles )
  2377. {
  2378. Add( XML_STYLE_FAMILY_TEXT_TEXT, xPropSet );
  2379. }
  2380. else
  2381. {
  2382. sal_Bool bHyperlink = sal_False, bIsUICharStyle = sal_False;
  2383. OUString sStyle = FindTextStyleAndHyperlink( xPropSet, bHyperlink,
  2384. bIsUICharStyle );
  2385. Reference < XPropertySetInfo > xPropSetInfo;
  2386. if( bHyperlink )
  2387. {
  2388. Reference< XPropertyState > xPropState( xPropSet, UNO_QUERY );
  2389. xPropSetInfo = xPropSet->getPropertySetInfo();
  2390. bHyperlink = addHyperlinkAttributes( xPropSet, xPropState, xPropSetInfo );
  2391. }
  2392. SvXMLElementExport aElem( GetExport(), bHyperlink, XML_NAMESPACE_TEXT,
  2393. XML_A, sal_False, sal_False );
  2394. if( bHyperlink )
  2395. {
  2396. // export events (if supported)
  2397. OUString sHyperLinkEvents(RTL_CONSTASCII_USTRINGPARAM(
  2398. "HyperLinkEvents"));
  2399. if (xPropSetInfo->hasPropertyByName(sHyperLinkEvents))
  2400. {
  2401. Any aAny = xPropSet->getPropertyValue(sHyperLinkEvents);
  2402. Reference<XNameReplace> xName;
  2403. aAny >>= xName;
  2404. GetExport().GetEventExport().Export(xName, sal_False);
  2405. }
  2406. }
  2407. {
  2408. XMLTextCharStyleNamesElementExport aCharStylesExport(
  2409. GetExport(), bIsUICharStyle &&
  2410. aCharStyleNamesPropInfoCache.hasProperty(
  2411. xPropSet, xPropSetInfo ),
  2412. xPropSet, sCharStyleNames );
  2413. OUString sText = rTextRange->getString();
  2414. if( sStyle.getLength() )
  2415. GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
  2416. sStyle );
  2417. {
  2418. // in a block to make sure it is destroyed before the text:a element
  2419. SvXMLElementExport aElem( GetExport(), sStyle.getLength() > 0,
  2420. XML_NAMESPACE_TEXT, XML_SPAN, sal_False,
  2421. sal_False );
  2422. exportText( sText, rPrevCharIsSpace );
  2423. }
  2424. }
  2425. }
  2426. }
  2427. void XMLTextParagraphExport::exportText( const OUString& rText,
  2428. sal_Bool& rPrevCharIsSpace )
  2429. {
  2430. sal_Int32 nExpStartPos = 0L;
  2431. sal_Int32 nEndPos = rText.getLength();
  2432. sal_Int32 nSpaceChars = 0;
  2433. for( sal_Int32 nPos = 0; nPos < nEndPos; nPos++ )
  2434. {
  2435. sal_Unicode cChar = rText[nPos];
  2436. sal_Bool bExpCharAsText = sal_True;
  2437. sal_Bool bExpCharAsElement = sal_False;
  2438. sal_Bool bCurrCharIsSpace = sal_False;
  2439. switch( cChar )
  2440. {
  2441. case 0x0009: // Tab
  2442. case 0x000A: // LF
  2443. // These characters are exported as text.
  2444. bExpCharAsElement = sal_True;
  2445. bExpCharAsText = sal_False;
  2446. break;
  2447. case 0x000D:
  2448. break; // legal character
  2449. case 0x0020: // Blank
  2450. if( rPrevCharIsSpace )
  2451. {
  2452. // If the previous character is a space character,
  2453. // too, export a special space element.
  2454. bExpCharAsText = sal_False;
  2455. }
  2456. bCurrCharIsSpace = sal_True;
  2457. break;
  2458. default:
  2459. if( cChar < 0x0020 )
  2460. {
  2461. #ifdef DBG_UTIL
  2462. OSL_ENSURE( txtparae_bContainsIllegalCharacters ||
  2463. cChar >= 0x0020,
  2464. "illegal character in text content" );
  2465. txtparae_bContainsIllegalCharacters = sal_True;
  2466. #endif
  2467. bExpCharAsText = sal_False;
  2468. }
  2469. break;
  2470. }
  2471. // If the current character is not exported as text
  2472. // the text that has not been exported by now has to be exported now.
  2473. if( nPos > nExpStartPos && !bExpCharAsText )
  2474. {
  2475. DBG_ASSERT( 0==nSpaceChars, "pending spaces" );
  2476. OUString sExp( rText.copy( nExpStartPos, nPos - nExpStartPos ) );
  2477. GetExport().Characters( sExp );
  2478. nExpStartPos = nPos;
  2479. }
  2480. // If there are spaces left that have not been exported and the
  2481. // current chracter is not a space , the pending spaces have to be
  2482. // exported now.
  2483. if( nSpaceChars > 0 && !bCurrCharIsSpace )
  2484. {
  2485. DBG_ASSERT( nExpStartPos == nPos, " pending characters" );
  2486. if( nSpaceChars > 1 )
  2487. {
  2488. OUStringBuffer sTmp;
  2489. sTmp.append( (sal_Int32)nSpaceChars );
  2490. GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_C,
  2491. sTmp.makeStringAndClear() );
  2492. }
  2493. SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
  2494. XML_S, sal_False, sal_False );
  2495. nSpaceChars = 0;
  2496. }
  2497. // If the current character has to be exported as a special
  2498. // element, the elemnt will be exported now.
  2499. if( bExpCharAsElement )
  2500. {
  2501. switch( cChar )
  2502. {
  2503. case 0x0009: // Tab
  2504. {
  2505. SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
  2506. XML_TAB_STOP, sal_False,
  2507. sal_False );
  2508. }
  2509. break;
  2510. case 0x000A: // LF
  2511. {
  2512. SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
  2513. XML_LINE_BREAK, sal_False,
  2514. sal_False );
  2515. }
  2516. break;
  2517. }
  2518. }
  2519. // If the current character is a space, and the previous one
  2520. // is a space, too, the number of pending spaces is incremented
  2521. // only.
  2522. if( bCurrCharIsSpace && rPrevCharIsSpace )
  2523. nSpaceChars++;
  2524. rPrevCharIsSpace = bCurrCharIsSpace;
  2525. // If the currect character is not exported as text, the start
  2526. // position for text is the position behind the current position.
  2527. if( !bExpCharAsText )
  2528. {
  2529. DBG_ASSERT( nExpStartPos == nPos, "wrong export start pos" );
  2530. nExpStartPos = nPos+1;
  2531. }
  2532. }
  2533. if( nExpStartPos < nEndPos )
  2534. {
  2535. DBG_ASSERT( 0==nSpaceChars, " pending spaces " );
  2536. OUString sExp( rText.copy( nExpStartPos, nEndPos - nExpStartPos ) );
  2537. GetExport().Characters( sExp );
  2538. }
  2539. // If there are some spaces left, they have to be exported now.
  2540. if( nSpaceChars > 0 )
  2541. {
  2542. if( nSpaceChars > 1 )
  2543. {
  2544. OUStringBuffer sTmp;
  2545. sTmp.append( (sal_Int32)nSpaceChars );
  2546. GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_C,
  2547. sTmp.makeStringAndClear() );
  2548. }
  2549. SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_S,
  2550. sal_False, sal_False );
  2551. }
  2552. }
  2553. void XMLTextParagraphExport::exportTextDeclarations()
  2554. {
  2555. pFieldExport->ExportFieldDeclarations();
  2556. // get XPropertySet from the document and ask for AutoMarkFileURL.
  2557. // If it exists, export the auto-mark-file element.
  2558. Reference<XPropertySet> xPropertySet( GetExport().GetModel(), UNO_QUERY );
  2559. if (xPropertySet.is())
  2560. {
  2561. OUString sUrl;
  2562. OUString sIndexAutoMarkFileURL(
  2563. RTL_CONSTASCII_USTRINGPARAM("IndexAutoMarkFileURL"));
  2564. if (xPropertySet->getPropertySetInfo()->hasPropertyByName(
  2565. sIndexAutoMarkFileURL))
  2566. {
  2567. Any aAny = xPropertySet->getPropertyValue(sIndexAutoMarkFileURL);
  2568. aAny >>= sUrl;
  2569. if (sUrl.getLength() > 0)
  2570. {
  2571. GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF,
  2572. GetExport().GetRelativeReference(sUrl) );
  2573. SvXMLElementExport aAutoMarkElement(
  2574. GetExport(), XML_NAMESPACE_TEXT,
  2575. XML_ALPHABETICAL_INDEX_AUTO_MARK_FILE,
  2576. sal_True, sal_True );
  2577. }
  2578. }
  2579. }
  2580. }
  2581. void XMLTextParagraphExport::exportTextDeclarations(
  2582. const Reference<XText> & rText )
  2583. {
  2584. pFieldExport->ExportFieldDeclarations(rText);
  2585. }
  2586. void XMLTextParagraphExport::exportUsedDeclarations( sal_Bool bOnlyUsed )
  2587. {
  2588. pFieldExport->SetExportOnlyUsedFieldDeclarations( bOnlyUsed );
  2589. }
  2590. void XMLTextParagraphExport::exportTrackedChanges(sal_Bool bAutoStyles)
  2591. {
  2592. if (NULL != pRedlineExport)
  2593. pRedlineExport->ExportChangesList( bAutoStyles );
  2594. }
  2595. void XMLTextParagraphExport::exportTrackedChanges(
  2596. const Reference<XText> & rText,
  2597. sal_Bool bAutoStyle)
  2598. {
  2599. if (NULL != pRedlineExport)
  2600. pRedlineExport->ExportChangesList(rText, bAutoStyle);
  2601. }
  2602. void XMLTextParagraphExport::recordTrackedChangesForXText(
  2603. const Reference<XText> & rText )
  2604. {
  2605. if (NULL != pRedlineExport)
  2606. pRedlineExport->SetCurrentXText(rText);
  2607. }
  2608. void XMLTextParagraphExport::recordTrackedChangesNoXText()
  2609. {
  2610. if (NULL != pRedlineExport)
  2611. pRedlineExport->SetCurrentXText();
  2612. }
  2613. void XMLTextParagraphExport::exportTextAutoStyles()
  2614. {
  2615. GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_PARAGRAPH,
  2616. GetExport().GetDocHandler(),
  2617. GetExport().GetMM100UnitConverter(),
  2618. GetExport().GetNamespaceMap() );
  2619. GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_TEXT,
  2620. GetExport().GetDocHandler(),
  2621. GetExport().GetMM100UnitConverter(),
  2622. GetExport().GetNamespaceMap() );
  2623. GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_FRAME,
  2624. GetExport().GetDocHandler(),
  2625. GetExport().GetMM100UnitConverter(),
  2626. GetExport().GetNamespaceMap() );
  2627. GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_SECTION,
  2628. GetExport().GetDocHandler(),
  2629. GetExport().GetMM100UnitConverter(),
  2630. GetExport().GetNamespaceMap() );
  2631. GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_RUBY,
  2632. GetExport().GetDocHandler(),
  2633. GetExport().GetMM100UnitConverter(),
  2634. GetExport().GetNamespaceMap() );
  2635. pListAutoPool->exportXML();
  2636. }
  2637. void XMLTextParagraphExport::exportRuby(
  2638. const Reference<XPropertySet> & rPropSet,
  2639. sal_Bool bAutoStyles )
  2640. {
  2641. // early out: a collapsed ruby makes no sense
  2642. Any aAny = rPropSet->getPropertyValue(sIsCollapsed);
  2643. if (*(sal_Bool*)aAny.getValue())
  2644. return;
  2645. // start value ?
  2646. aAny = rPropSet->getPropertyValue(sIsStart);
  2647. sal_Bool bStart = (*(sal_Bool*)aAny.getValue());
  2648. if (bAutoStyles)
  2649. {
  2650. // ruby auto styles
  2651. if (bStart)
  2652. Add( XML_STYLE_FAMILY_TEXT_RUBY, rPropSet );
  2653. }
  2654. else
  2655. {
  2656. // prepare element names
  2657. OUString sRuby(GetXMLToken(XML_RUBY));
  2658. OUString sTextRuby(GetExport().GetNamespaceMap().
  2659. GetQNameByKey(XML_NAMESPACE_TEXT, sRuby));
  2660. OUString sRubyBase(GetXMLToken(XML_RUBY_BASE));
  2661. OUString sTextRubyBase(GetExport().GetNamespaceMap().
  2662. GetQNameByKey(XML_NAMESPACE_TEXT, sRubyBase));
  2663. if (bStart)
  2664. {
  2665. // ruby start
  2666. // we can only start a ruby if none is open
  2667. DBG_ASSERT(! bOpenRuby, "Can't open a ruby inside of ruby!");
  2668. if( bOpenRuby )
  2669. return;
  2670. // save ruby text + ruby char style
  2671. aAny = rPropSet->getPropertyValue(sRubyText);
  2672. aAny >>= sOpenRubyText;
  2673. aAny = rPropSet->getPropertyValue(sRubyCharStyleName);
  2674. aAny >>= sOpenRubyCharStyle;
  2675. // ruby style
  2676. GetExport().CheckAttrList();
  2677. OUString sEmpty;
  2678. OUString sStyleName = Find( XML_STYLE_FAMILY_TEXT_RUBY, rPropSet,
  2679. sEmpty );
  2680. DBG_ASSERT(sStyleName.getLength() > 0, "I can't find the style!");
  2681. GetExport().AddAttribute(XML_NAMESPACE_TEXT,
  2682. XML_STYLE_NAME, sStyleName);
  2683. // export <text:ruby> and <text:ruby-base> start elements
  2684. GetExport().StartElement( XML_NAMESPACE_TEXT, XML_RUBY, sal_False);
  2685. GetExport().ClearAttrList();
  2686. GetExport().StartElement( XML_NAMESPACE_TEXT, XML_RUBY_BASE,
  2687. sal_False );
  2688. bOpenRuby = sal_True;
  2689. }
  2690. else
  2691. {
  2692. // ruby end
  2693. // check for an open ruby
  2694. DBG_ASSERT(bOpenRuby, "Can't close a ruby if none is open!");
  2695. if( !bOpenRuby )
  2696. return;
  2697. // close <text:ruby-base>
  2698. GetExport().EndElement(XML_NAMESPACE_TEXT, XML_RUBY_BASE,
  2699. sal_False);
  2700. // write the ruby text (with char style)
  2701. {
  2702. if (sOpenRubyCharStyle.getLength() > 0)
  2703. GetExport().AddAttribute(
  2704. XML_NAMESPACE_TEXT, XML_STYLE_NAME,
  2705. sOpenRubyCharStyle);
  2706. SvXMLElementExport aRuby(
  2707. GetExport(), XML_NAMESPACE_TEXT, XML_RUBY_TEXT,
  2708. sal_False, sal_False);
  2709. GetExport().Characters(sOpenRubyText);
  2710. }
  2711. // and finally, close the ruby
  2712. GetExport().EndElement(XML_NAMESPACE_TEXT, XML_RUBY, sal_False);
  2713. bOpenRuby = sal_False;
  2714. }
  2715. }
  2716. }
  2717. void XMLTextParagraphExport::PreventExportOfControlsInMuteSections(
  2718. const Reference<XIndexAccess> & rShapes,
  2719. UniReference<xmloff::OFormLayerXMLExport> xFormExport )
  2720. {
  2721. // check parameters ad pre-conditions
  2722. if( ( ! rShapes.is() ) || ( ! xFormExport.is() ) )
  2723. {
  2724. // if we don't have shapes or a form export, there's nothing to do
  2725. return;
  2726. }
  2727. DBG_ASSERT( pSectionExport != NULL, "We need the section export." );
  2728. sal_Int32 nShapes = xShapes->getCount();
  2729. for( sal_Int32 i = 0; i < nShapes; i++ )
  2730. {
  2731. // now we need to check
  2732. // 1) if this is a control shape, and
  2733. // 2) if it's in a mute section
  2734. // if both answers are 'yes', notify the form layer export
  2735. // we join accessing the shape and testing for control
  2736. Reference<XControlShape> xControlShape;
  2737. xShapes->getByIndex( i ) >>= xControlShape;
  2738. if( xControlShape.is() )
  2739. {
  2740. // Reference<XPropertySet> xPropSet( xControlShape, UNO_QUERY );
  2741. // Reference<XTextContent> xTextContent;
  2742. // xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) ) ) >>= xTextContent;
  2743. Reference<XTextContent> xTextContent( xControlShape, UNO_QUERY );
  2744. if( xTextContent.is() )
  2745. {
  2746. if( pSectionExport->IsMuteSection( xTextContent, sal_False ) )
  2747. {
  2748. // Ah, we've found a shape that
  2749. // 1) is a control shape
  2750. // 2) is anchored in a mute section
  2751. // so: don't export it!
  2752. xFormExport->excludeFromExport(
  2753. xControlShape->getControl() );
  2754. }
  2755. // else: not in mute section -> should be exported -> nothing
  2756. // to do
  2757. }
  2758. // else: no anchor -> ignore
  2759. }
  2760. // else: no control shape -> nothing to do
  2761. }
  2762. }
  2763. }//end of namespace binfilter