PageRenderTime 73ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/libreoffice-3.6.0.2/binfilter/bf_xmloff/source/text/xmloff_txtparae.cxx

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