LibreOffice Module sw (master)  1
docxexport.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include "docxexport.hxx"
21 #include "docxexportfilter.hxx"
22 #include "docxattributeoutput.hxx"
23 #include "docxsdrexport.hxx"
24 #include "docxhelper.hxx"
25 
26 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
27 #include <com/sun/star/document/XDocumentProperties.hpp>
28 #include <com/sun/star/document/XStorageBasedDocument.hpp>
29 #include <com/sun/star/drawing/XShape.hpp>
30 #include <com/sun/star/i18n/ScriptType.hpp>
31 #include <com/sun/star/frame/XModel.hpp>
32 #include <com/sun/star/xml/dom/XDocument.hpp>
33 #include <com/sun/star/xml/sax/XSAXSerializable.hpp>
34 #include <com/sun/star/xml/sax/Writer.hpp>
35 #include <com/sun/star/awt/XControlModel.hpp>
36 #include <com/sun/star/sdb/CommandType.hpp>
37 
38 #include <oox/token/namespaces.hxx>
39 #include <oox/token/tokens.hxx>
40 #include <oox/export/drawingml.hxx>
41 #include <oox/export/vmlexport.hxx>
43 #include <oox/export/shapes.hxx>
47 #include <oox/ole/olestorage.hxx>
48 #include <oox/ole/olehelper.hxx>
49 
50 #include <map>
51 #include <algorithm>
52 
53 #include <IMark.hxx>
57 #include <docsh.hxx>
58 #include <ndtxt.hxx>
59 #include "wrtww8.hxx"
60 #include <fltini.hxx>
61 #include <fmtline.hxx>
62 #include <fmtpdsc.hxx>
63 #include <frmfmt.hxx>
64 #include <section.hxx>
65 #include <ftninfo.hxx>
66 #include <pagedesc.hxx>
67 #include <swdbdata.hxx>
68 
69 #include <editeng/unoprnms.hxx>
70 #include <editeng/editobj.hxx>
71 #include <editeng/outlobj.hxx>
72 #include <editeng/brushitem.hxx>
74 
75 #include <docary.hxx>
76 #include <numrule.hxx>
77 #include <charfmt.hxx>
78 #include <viewsh.hxx>
79 #include <viewopt.hxx>
80 
81 #include "ww8par.hxx"
82 #include "ww8scan.hxx"
83 #include <oox/token/properties.hxx>
86 #include <rtl/ustrbuf.hxx>
87 #include <sal/log.hxx>
88 #include <vcl/font.hxx>
90 #include <tools/diagnose_ex.h>
91 
92 using namespace sax_fastparser;
93 using namespace ::comphelper;
94 using namespace ::com::sun::star;
95 using namespace ::oox;
96 
98 
99 using sw::mark::IMark;
100 
102 {
103  return *m_pAttrOutput;
104 }
105 
107 {
108  return *m_pAttrOutput;
109 }
110 
112 {
113  return *m_pSections;
114 }
115 
116 bool DocxExport::CollapseScriptsforWordOk( sal_uInt16 nScript, sal_uInt16 nWhich )
117 {
118  // TODO FIXME is this actually true for docx? - this is ~copied from WW8
119  if ( nScript == i18n::ScriptType::ASIAN )
120  {
121  // for asian in ww8, there is only one fontsize
122  // and one fontstyle (posture/weight)
123  switch ( nWhich )
124  {
125  case RES_CHRATR_FONTSIZE:
126  case RES_CHRATR_POSTURE:
127  case RES_CHRATR_WEIGHT:
128  return false;
129  default:
130  break;
131  }
132  }
133  else if ( nScript != i18n::ScriptType::COMPLEX )
134  {
135  // for western in ww8, there is only one fontsize
136  // and one fontstyle (posture/weight)
137  switch ( nWhich )
138  {
142  return false;
143  default:
144  break;
145  }
146  }
147  return true;
148 }
149 
150 void DocxExport::AppendBookmarks( const SwTextNode& rNode, sal_Int32 nCurrentPos, sal_Int32 nLen )
151 {
152  std::vector< OUString > aStarts;
153  std::vector< OUString > aEnds;
154 
155  IMarkVector aMarks;
156  if ( GetBookmarks( rNode, nCurrentPos, nCurrentPos + nLen, aMarks ) )
157  {
158  for ( IMark* pMark : aMarks )
159  {
160  const sal_Int32 nStart = pMark->GetMarkStart().nContent.GetIndex();
161  const sal_Int32 nEnd = pMark->GetMarkEnd().nContent.GetIndex();
162 
163  if ( nStart == nCurrentPos )
164  aStarts.push_back( pMark->GetName() );
165 
166  if ( nEnd == nCurrentPos )
167  aEnds.push_back( pMark->GetName() );
168  }
169  }
170 
171  const OUString& aStr( rNode.GetText() );
172  const sal_Int32 nEnd = aStr.getLength();
173 
174  if ( nCurrentPos == nEnd )
175  m_pAttrOutput->WriteFinalBookmarks_Impl( aStarts, aEnds );
176  else
177  m_pAttrOutput->WriteBookmarks_Impl( aStarts, aEnds );
178 }
179 
180 void DocxExport::AppendBookmark( const OUString& rName )
181 {
182  std::vector< OUString > aStarts;
183  std::vector< OUString > aEnds;
184 
185  aStarts.push_back( rName );
186  aEnds.push_back( rName );
187 
188  m_pAttrOutput->WriteBookmarks_Impl( aStarts, aEnds );
189 }
190 
191 void DocxExport::AppendAnnotationMarks( const SwTextNode& rNode, sal_Int32 nCurrentPos, sal_Int32 nLen )
192 {
193  std::vector< OUString > aStarts;
194  std::vector< OUString > aEnds;
195 
196  IMarkVector aMarks;
197  if ( GetAnnotationMarks( rNode, nCurrentPos, nCurrentPos + nLen, aMarks ) )
198  {
199  for ( IMark* pMark : aMarks )
200  {
201  const sal_Int32 nStart = pMark->GetMarkStart().nContent.GetIndex();
202  const sal_Int32 nEnd = pMark->GetMarkEnd().nContent.GetIndex();
203 
204  if ( nStart == nCurrentPos )
205  aStarts.push_back( pMark->GetName() );
206 
207  if ( nEnd == nCurrentPos )
208  aEnds.push_back( pMark->GetName() );
209  }
210  }
211 
212  m_pAttrOutput->WriteAnnotationMarks_Impl( aStarts, aEnds );
213 }
214 
216 {
217  // Just collect the bullets for now, numbering.xml is not yet started.
218  CollectGrfsOfBullets();
219 }
220 
221 OString DocxExport::AddRelation( const OUString& rType, const OUString& rTarget )
222 {
223  OUString sId = m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
224  rType, rTarget, true );
225 
226  return sId.toUtf8();
227 }
228 
230 {
231  bool bRet( false );
232 
233  if (SfxItemState::SET != rFormat.GetItemState(RES_PARATR_NUMRULE, false))
234  {
235  if (const SwFormat *pParent = rFormat.DerivedFrom())
236  {
237  if (static_cast<const SwTextFormatColl*>(pParent)->IsAssignedToListLevelOfOutlineStyle())
238  {
239  ::sax_fastparser::FSHelperPtr pSerializer = m_pAttrOutput->GetSerializer( );
240  // Level 9 disables the outline
241  pSerializer->singleElementNS(XML_w, XML_outlineLvl, FSNS(XML_w, XML_val), "9");
242 
243  bRet = true;
244  }
245  }
246  }
247 
248  return bRet;
249 }
250 
252  const SwFrameFormat& rFormat, const SwFrameFormat& rLeftFormat, const SwFrameFormat& rFirstPageFormat, sal_uInt8 nBreakCode )
253 {
254  m_nHeadersFootersInSection = 1;
255 
256  // document setting indicating the requirement of EVEN and ODD for both headers and footers
258  m_aSettings.evenAndOddHeaders = true;
259 
260  // Turn ON flag for 'Writing Headers \ Footers'
261  m_pAttrOutput->SetWritingHeaderFooter( true );
262 
263  // headers
264  if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_EVEN )
265  WriteHeaderFooter( &rLeftFormat, true, "even" );
266  else if ( m_aSettings.evenAndOddHeaders )
267  {
268  if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_ODD )
269  WriteHeaderFooter( &rFormat, true, "even" );
270  else if ( m_bHasHdr && nBreakCode == 2 )
271  WriteHeaderFooter( nullptr, true, "even" );
272  }
273 
274  if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_ODD )
275  WriteHeaderFooter( &rFormat, true, "default" );
276 
277  if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_FIRST )
278  WriteHeaderFooter( &rFirstPageFormat, true, "first" );
279 
280  if( (nHeadFootFlags & (nsHdFtFlags::WW8_HEADER_EVEN
281  | nsHdFtFlags::WW8_HEADER_ODD
282  | nsHdFtFlags::WW8_HEADER_FIRST)) == 0
283  && m_bHasHdr && nBreakCode == 2 ) // 2: nexPage
284  WriteHeaderFooter( nullptr, true, "default" );
285 
286 
287  // footers
288  if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_EVEN )
289  WriteHeaderFooter( &rLeftFormat, false, "even" );
290  else if ( m_aSettings.evenAndOddHeaders )
291  {
292  if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_ODD )
293  WriteHeaderFooter( &rFormat, false, "even" );
294  else if ( m_bHasFtr && nBreakCode == 2 )
295  WriteHeaderFooter( nullptr, false, "even");
296  }
297 
298  if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_ODD )
299  WriteHeaderFooter( &rFormat, false, "default" );
300 
301  if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_FIRST )
302  WriteHeaderFooter( &rFirstPageFormat, false, "first" );
303 
304  if( (nHeadFootFlags & (nsHdFtFlags::WW8_FOOTER_EVEN
305  | nsHdFtFlags::WW8_FOOTER_ODD
306  | nsHdFtFlags::WW8_FOOTER_FIRST)) == 0
307  && m_bHasFtr && nBreakCode == 2 ) // 2: nexPage
308  WriteHeaderFooter( nullptr, false, "default");
309 
310  // Turn OFF flag for 'Writing Headers \ Footers'
311  m_pAttrOutput->SetWritingHeaderFooter( false );
312 }
313 
314 void DocxExport::OutputField( const SwField* pField, ww::eField eFieldType, const OUString& rFieldCmd, FieldFlags nMode )
315 {
316  m_pAttrOutput->WriteField_Impl( pField, eFieldType, rFieldCmd, nMode );
317 }
318 
319 void DocxExport::WriteFormData( const ::sw::mark::IFieldmark& rFieldmark )
320 {
321  m_pAttrOutput->WriteFormData_Impl( rFieldmark );
322 }
323 
324 void DocxExport::WriteHyperlinkData( const ::sw::mark::IFieldmark& /*rFieldmark*/ )
325 {
326 #if OSL_DEBUG_LEVEL > 1
327  fprintf( stderr, "TODO DocxExport::WriteHyperlinkData()\n" );
328 #endif
329 }
330 
331 void DocxExport::DoComboBox(const OUString& rName,
332  const OUString& rHelp,
333  const OUString& rToolTip,
334  const OUString& rSelected,
335  uno::Sequence<OUString>& rListItems)
336 {
337  m_pDocumentFS->startElementNS(XML_w, XML_ffData);
338 
339  m_pDocumentFS->singleElementNS(XML_w, XML_name, FSNS(XML_w, XML_val), rName.toUtf8());
340 
341  m_pDocumentFS->singleElementNS(XML_w, XML_enabled);
342 
343  if ( !rHelp.isEmpty() )
344  m_pDocumentFS->singleElementNS(XML_w, XML_helpText, FSNS(XML_w, XML_val), rHelp.toUtf8());
345 
346  if ( !rToolTip.isEmpty() )
347  m_pDocumentFS->singleElementNS( XML_w, XML_statusText,
348  FSNS( XML_w, XML_val ), rToolTip.toUtf8() );
349 
350  m_pDocumentFS->startElementNS(XML_w, XML_ddList);
351 
352  // Output the 0-based index of the selected value
353  sal_uInt32 nListItems = rListItems.getLength();
354  sal_Int32 nId = 0;
355  sal_uInt32 nI = 0;
356  while ( ( nI < nListItems ) && ( nId == 0 ) )
357  {
358  if ( rListItems[nI] == rSelected )
359  nId = nI;
360  nI++;
361  }
362 
363  m_pDocumentFS->singleElementNS(XML_w, XML_result, FSNS(XML_w, XML_val), OString::number(nId));
364 
365  // Loop over the entries
366 
367  for (sal_uInt32 i = 0; i < nListItems; i++)
368  {
369  m_pDocumentFS->singleElementNS( XML_w, XML_listEntry,
370  FSNS( XML_w, XML_val ), rListItems[i].toUtf8() );
371  }
372 
373  m_pDocumentFS->endElementNS( XML_w, XML_ddList );
374 
375  m_pDocumentFS->endElementNS( XML_w, XML_ffData );
376 }
377 
379 {
380  assert(pField);
381  const OUString sStr = FieldString(ww::eFORMTEXT);
382  OutputField(pField, ww::eFORMTEXT, sStr);
383 }
384 
385 OString DocxExport::OutputChart( uno::Reference< frame::XModel > const & xModel, sal_Int32 nCount, ::sax_fastparser::FSHelperPtr const & m_pSerializer )
386 {
387  OUString aFileName = "charts/chart" + OUString::number(nCount) + ".xml";
388  OUString sId = m_pFilter->addRelation( m_pSerializer->getOutputStream(),
389  oox::getRelationship(Relationship::CHART),
390  aFileName );
391  aFileName = "word/charts/chart" + OUString::number(nCount) + ".xml";
393  m_pFilter->openFragmentStreamWithSerializer( aFileName,
394  "application/vnd.openxmlformats-officedocument.drawingml.chart+xml" );
395 
396  oox::drawingml::ChartExport aChartExport(XML_w, pChartFS, xModel, m_pFilter, oox::drawingml::DOCUMENT_DOCX);
397  aChartExport.ExportContent();
398  return OUStringToOString( sId, RTL_TEXTENCODING_UTF8 );
399 }
400 
401 OString DocxExport::WriteOLEObject(SwOLEObj& rObject, OUString & io_rProgID)
402 {
403  uno::Reference <embed::XEmbeddedObject> xObj( rObject.GetOleRef() );
404  uno::Reference<uno::XComponentContext> const xContext(
405  GetFilter().getComponentContext());
406 
407  OUString sMediaType;
408  OUString sRelationType;
409  OUString sSuffix;
410  const char * pProgID(nullptr);
411 
412  uno::Reference<io::XInputStream> const xInStream =
413  oox::GetOLEObjectStream(xContext, xObj, io_rProgID,
414  sMediaType, sRelationType, sSuffix, pProgID);
415 
416  if (!xInStream.is())
417  {
418  return OString();
419  }
420 
421  assert(!sMediaType.isEmpty());
422  assert(!sRelationType.isEmpty());
423  assert(!sSuffix.isEmpty());
424  OUString sFileName = "embeddings/oleObject" + OUString::number( ++m_nOLEObjects ) + "." + sSuffix;
425  uno::Reference<io::XOutputStream> const xOutStream =
426  GetFilter().openFragmentStream("word/" + sFileName, sMediaType);
427  assert(xOutStream.is()); // no reason why that could fail
428 
429  try
430  {
432  }
433  catch (uno::Exception const& e)
434  {
435  SAL_WARN("sw.ww8", "DocxExport::WriteOLEObject: " << e);
436  return OString();
437  }
438 
439  OUString const sId = m_pFilter->addRelation( GetFS()->getOutputStream(),
440  sRelationType, sFileName );
441  if (pProgID)
442  {
443  io_rProgID = OUString::createFromAscii(pProgID);
444  }
445 
446  return OUStringToOString( sId, RTL_TEXTENCODING_UTF8 );
447 }
448 
449 std::pair<OString, OString> DocxExport::WriteActiveXObject(const uno::Reference<drawing::XShape>& rxShape,
450  const uno::Reference<awt::XControlModel>& rxControlModel)
451 {
452  ++m_nActiveXControls;
453 
454  // Write out ActiveX binary
455  const OUString sBinaryFileName = "word/activeX/activeX" + OUString::number(m_nActiveXControls) + ".bin";
456 
457  OString sGUID;
458  OString sName;
459  uno::Reference<io::XStream> xOutStorage(m_pFilter->openFragmentStream(sBinaryFileName, "application/vnd.ms-office.activeX"), uno::UNO_QUERY);
460  if(xOutStorage.is())
461  {
462  oox::ole::OleStorage aOleStorage(m_pFilter->getComponentContext(), xOutStorage, false);
463  uno::Reference<io::XOutputStream> xOutputStream(aOleStorage.openOutputStream("contents"), uno::UNO_SET_THROW);
464  uno::Reference< css::frame::XModel > xModel( m_pDoc->GetDocShell() ? m_pDoc->GetDocShell()->GetModel() : nullptr );
466  if ( !exportHelper.isValid() )
467  return std::make_pair<OString, OString>(OString(), OString());
468  sGUID = OUStringToOString(exportHelper.getGUID(), RTL_TEXTENCODING_UTF8);
469  sName = OUStringToOString(exportHelper.getName(), RTL_TEXTENCODING_UTF8);
470  exportHelper.exportControl(xOutputStream, rxShape->getSize(), true);
471  aOleStorage.commit();
472  }
473 
474  // Write out ActiveX fragment
475  const OUString sXMLFileName = "word/activeX/activeX" + OUString::number( m_nActiveXControls ) + ".xml";
476  ::sax_fastparser::FSHelperPtr pActiveXFS = m_pFilter->openFragmentStreamWithSerializer(sXMLFileName, "application/vnd.ms-office.activeX+xml" );
477 
478  const OUString sBinaryId = m_pFilter->addRelation( pActiveXFS->getOutputStream(),
479  oox::getRelationship(Relationship::ACTIVEXCONTROLBINARY),
480  sBinaryFileName.copy(sBinaryFileName.lastIndexOf("/") + 1) );
481 
482  pActiveXFS->singleElementNS(XML_ax, XML_ocx,
483  FSNS(XML_xmlns, XML_ax), m_pFilter->getNamespaceURL(OOX_NS(ax)).toUtf8(),
484  FSNS(XML_xmlns, XML_r), m_pFilter->getNamespaceURL(OOX_NS(officeRel)).toUtf8(),
485  FSNS(XML_ax, XML_classid), "{" + sGUID + "}",
486  FSNS(XML_ax, XML_persistence), "persistStorage",
487  FSNS(XML_r, XML_id), sBinaryId.toUtf8());
488 
489  OString sXMLId = OUStringToOString(m_pFilter->addRelation(m_pDocumentFS->getOutputStream(),
490  oox::getRelationship(Relationship::CONTROL),
491  sXMLFileName.copy(sBinaryFileName.indexOf("/") + 1)),
492  RTL_TEXTENCODING_UTF8);
493 
494  return std::pair<OString, OString>(sXMLId, sName);
495 }
496 
497 void DocxExport::OutputDML(uno::Reference<drawing::XShape> const & xShape)
498 {
499  uno::Reference<lang::XServiceInfo> xServiceInfo(xShape, uno::UNO_QUERY_THROW);
500  sal_Int32 nNamespace = XML_wps;
501  if (xServiceInfo->supportsService("com.sun.star.drawing.GroupShape"))
502  nNamespace = XML_wpg;
503  else if (xServiceInfo->supportsService("com.sun.star.drawing.GraphicObjectShape"))
504  nNamespace = XML_pic;
505  oox::drawingml::ShapeExport aExport(nNamespace, m_pAttrOutput->GetSerializer(), nullptr, m_pFilter, oox::drawingml::DOCUMENT_DOCX, m_pAttrOutput.get());
506  aExport.WriteShape(xShape);
507 }
508 
510 {
511  // Set the 'Track Revisions' flag in the settings structure
512  m_aSettings.trackRevisions = bool( RedlineFlags::On & m_nOrigRedlineFlags );
513 
514  InitStyles();
515 
516  // init sections
517  m_pSections.reset(new MSWordSections( *this ));
518 
519  // Make sure images are counted from one, even when exporting multiple documents.
521 
522  WriteMainText();
523 
524  WriteFootnotesEndnotes();
525 
526  WritePostitFields();
527 
528  WriteNumbering();
529 
530  WriteFonts();
531 
532  WriteSettings();
533 
534  WriteTheme();
535 
536  WriteGlossary();
537 
538  WriteCustomXml();
539 
540  WriteEmbeddings();
541 
542  WriteVBA();
543 
544  m_aLinkedTextboxesHelper.clear(); //final cleanup
545  m_pStyles.reset();
546  m_pSections.reset();
547 
548  return ERRCODE_NONE;
549 }
550 
551 void DocxExport::AppendSection( const SwPageDesc *pPageDesc, const SwSectionFormat* pFormat, sal_uLong nLnNum )
552 {
553  AttrOutput().SectionBreak( msword::PageBreak, m_pSections->CurrentSectionInfo() );
554  m_pSections->AppendSection( pPageDesc, pFormat, nLnNum, m_pAttrOutput->IsFirstParagraph() );
555 }
556 
557 void DocxExport::OutputEndNode( const SwEndNode& rEndNode )
558 {
560 
561  if ( TXT_MAINTEXT == m_nTextTyp && rEndNode.StartOfSectionNode()->IsSectionNode() )
562  {
563  // this originally comes from WW8Export::WriteText(), and looks like it
564  // could have some code common with SectionNode()...
565 
566  const SwSection& rSect = rEndNode.StartOfSectionNode()->GetSectionNode()->GetSection();
567  if ( m_bStartTOX && TOX_CONTENT_SECTION == rSect.GetType() )
568  m_bStartTOX = false;
569 
570  SwNodeIndex aIdx( rEndNode, 1 );
571  const SwNode& rNd = aIdx.GetNode();
572  if ( rNd.IsEndNode() && rNd.StartOfSectionNode()->IsSectionNode() )
573  return;
574 
575  bool isInTable = IsInTable();
576  if ( !rNd.IsSectionNode() && isInTable ) // No sections in table
577  {
578  const SwSectionFormat* pParentFormat = rSect.GetFormat()->GetParent();
579  if( !pParentFormat )
580  pParentFormat = reinterpret_cast<SwSectionFormat*>(sal_IntPtr(-1));
581 
582  sal_uLong nRstLnNum;
583  if( rNd.IsContentNode() )
584  nRstLnNum = rNd.GetContentNode()->GetSwAttrSet().GetLineNumber().GetStartValue();
585  else
586  nRstLnNum = 0;
587 
588  AppendSection( m_pCurrentPageDesc, pParentFormat, nRstLnNum );
589  }
590  else
591  {
592  AttrOutput().SectionBreaks( rEndNode );
593  }
594  }
595  else if (TXT_MAINTEXT == m_nTextTyp && rEndNode.StartOfSectionNode()->IsTableNode())
596  // End node of a table: see if a section break should be written after the table.
597  AttrOutput().SectionBreaks(rEndNode);
598 }
599 
601 {
602  SAL_INFO("sw.ww8", "TODO DocxExport::OutputGrfNode( const SwGrfNode& )" );
603 }
604 
606 {
607  SAL_INFO("sw.ww8", "TODO DocxExport::OutputOLENode( const SwOLENode& )" );
608 }
609 
610 void DocxExport::OutputLinkedOLE( const OUString& )
611 {
612  // Nothing to implement here: WW8 only
613 }
614 
616 {
617  // Completely unused for Docx export... only here for code sharing
618  // purpose with binary export
619  return 0;
620 }
621 
623  const SwNode& rNd, const SwFormatPageDesc* pNewPgDescFormat,
624  const SwPageDesc* pNewPgDesc )
625 {
626  // tell the attribute output that we are ready to write the section
627  // break [has to be output inside paragraph properties]
628  AttrOutput().SectionBreak( msword::PageBreak, m_pSections->CurrentSectionInfo() );
629 
630  const SwSectionFormat* pFormat = GetSectionFormat( rNd );
631  const sal_uLong nLnNm = GetSectionLineNo( pSet, rNd );
632 
633  OSL_ENSURE( pNewPgDescFormat || pNewPgDesc, "Neither page desc format nor page desc provided." );
634 
635  if ( pNewPgDescFormat )
636  {
637  m_pSections->AppendSection( *pNewPgDescFormat, rNd, pFormat, nLnNm );
638  }
639  else if ( pNewPgDesc )
640  {
641  m_pSections->AppendSection( pNewPgDesc, rNd, pFormat, nLnNm );
642  }
643 
644 }
645 
647 {
648  m_pStyles.reset(new MSWordStyles( *this, /*bListStyles =*/ true ));
649 
650  // setup word/styles.xml and the relations + content type
651  m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
652  oox::getRelationship(Relationship::STYLES),
653  "styles.xml" );
654 
656  m_pFilter->openFragmentStreamWithSerializer( "word/styles.xml",
657  "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml" );
658 
659  // switch the serializer to redirect the output to word/styles.xml
660  m_pAttrOutput->SetSerializer( pStylesFS );
661 
662  // do the work
663  m_pStyles->OutputStylesTable();
664 
665  // switch the serializer back
666  m_pAttrOutput->SetSerializer( m_pDocumentFS );
667 }
668 
670 {
671  if ( m_pAttrOutput->HasFootnotes() )
672  {
673  // setup word/styles.xml and the relations + content type
674  m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
675  oox::getRelationship(Relationship::FOOTNOTES),
676  "footnotes.xml" );
677 
678  ::sax_fastparser::FSHelperPtr pFootnotesFS =
679  m_pFilter->openFragmentStreamWithSerializer( "word/footnotes.xml",
680  "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml" );
681 
682  // switch the serializer to redirect the output to word/footnotes.xml
683  m_pAttrOutput->SetSerializer( pFootnotesFS );
684  // tdf#99227
685  m_pSdrExport->setSerializer( pFootnotesFS );
686  // tdf#107969
687  m_pVMLExport->SetFS(pFootnotesFS);
688 
689  // do the work
690  m_pAttrOutput->FootnotesEndnotes( true );
691 
692  // switch the serializer back
693  m_pVMLExport->SetFS(m_pDocumentFS);
694  m_pSdrExport->setSerializer( m_pDocumentFS );
695  m_pAttrOutput->SetSerializer( m_pDocumentFS );
696  }
697 
698  if ( m_pAttrOutput->HasEndnotes() )
699  {
700  // setup word/styles.xml and the relations + content type
701  m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
702  oox::getRelationship(Relationship::ENDNOTES),
703  "endnotes.xml" );
704 
705  ::sax_fastparser::FSHelperPtr pEndnotesFS =
706  m_pFilter->openFragmentStreamWithSerializer( "word/endnotes.xml",
707  "application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml" );
708 
709  // switch the serializer to redirect the output to word/endnotes.xml
710  m_pAttrOutput->SetSerializer( pEndnotesFS );
711  // tdf#99227
712  m_pSdrExport->setSerializer( pEndnotesFS );
713  // tdf#107969
714  m_pVMLExport->SetFS(pEndnotesFS);
715 
716  // do the work
717  m_pAttrOutput->FootnotesEndnotes( false );
718 
719  // switch the serializer back
720  m_pVMLExport->SetFS(m_pDocumentFS);
721  m_pSdrExport->setSerializer( m_pDocumentFS );
722  m_pAttrOutput->SetSerializer( m_pDocumentFS );
723  }
724 }
725 
727 {
728  if ( m_pAttrOutput->HasPostitFields() )
729  {
730  m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
731  oox::getRelationship(Relationship::COMMENTS),
732  "comments.xml" );
733 
735  m_pFilter->openFragmentStreamWithSerializer( "word/comments.xml",
736  "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml" );
737 
738  pPostitFS->startElementNS( XML_w, XML_comments, MainXmlNamespaces());
739  m_pAttrOutput->SetSerializer( pPostitFS );
740  m_pAttrOutput->WritePostitFields();
741  m_pAttrOutput->SetSerializer( m_pDocumentFS );
742  pPostitFS->endElementNS( XML_w, XML_comments );
743  }
744 }
745 
747 {
748  if ( !m_pUsedNumTable )
749  return; // no numbering is used
750 
751  m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
752  oox::getRelationship(Relationship::NUMBERING),
753  "numbering.xml" );
754 
755  ::sax_fastparser::FSHelperPtr pNumberingFS = m_pFilter->openFragmentStreamWithSerializer( "word/numbering.xml",
756  "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml" );
757 
758  // switch the serializer to redirect the output to word/numbering.xml
759  m_pAttrOutput->SetSerializer( pNumberingFS );
760  m_pDrawingML->SetFS( pNumberingFS );
761 
762  pNumberingFS->startElementNS( XML_w, XML_numbering,
763  FSNS( XML_xmlns, XML_w ), m_pFilter->getNamespaceURL(OOX_NS(doc)).toUtf8(),
764  FSNS( XML_xmlns, XML_o ), m_pFilter->getNamespaceURL(OOX_NS(vmlOffice)).toUtf8(),
765  FSNS( XML_xmlns, XML_r ), m_pFilter->getNamespaceURL(OOX_NS(officeRel)).toUtf8(),
766  FSNS( XML_xmlns, XML_v ), m_pFilter->getNamespaceURL(OOX_NS(vml)).toUtf8() );
767 
768  BulletDefinitions();
769 
770  AbstractNumberingDefinitions();
771 
772  NumberingDefinitions();
773 
774  pNumberingFS->endElementNS( XML_w, XML_numbering );
775 
776  // switch the serializer back
777  m_pDrawingML->SetFS( m_pDocumentFS );
778  m_pAttrOutput->SetSerializer( m_pDocumentFS );
779 }
780 
781 void DocxExport::WriteHeaderFooter( const SwFormat* pFormat, bool bHeader, const char* pType )
782 {
783  // setup the xml stream
784  OUString aRelId;
786  if ( bHeader )
787  {
788  OUString aName( "header" + OUString::number( ++m_nHeaders ) + ".xml" );
789 
790  aRelId = m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
791  oox::getRelationship(Relationship::HEADER),
792  aName );
793 
794  pFS = m_pFilter->openFragmentStreamWithSerializer( "word/" + aName,
795  "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml" );
796 
797  pFS->startElementNS( XML_w, XML_hdr, MainXmlNamespaces());
798  }
799  else
800  {
801  OUString aName( "footer" + OUString::number( ++m_nFooters ) + ".xml" );
802 
803  aRelId = m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
804  oox::getRelationship(Relationship::FOOTER),
805  aName );
806 
807  pFS = m_pFilter->openFragmentStreamWithSerializer( "word/" + aName,
808  "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml" );
809 
810  pFS->startElementNS( XML_w, XML_ftr, MainXmlNamespaces());
811  }
812 
813  // switch the serializer to redirect the output to word/styles.xml
814  m_pAttrOutput->SetSerializer( pFS );
815  m_pVMLExport->SetFS( pFS );
816  m_pSdrExport->setSerializer(pFS);
817  SetFS( pFS );
818  {
819  DocxTableExportContext aTableExportContext(*m_pAttrOutput);
820  //When the stream changes the cache which is maintained for the graphics in case of alternate content is not cleared.
821  //So clearing the alternate content graphic cache.
822  m_pAttrOutput->PushRelIdCache();
823  // do the work
824  if (pFormat == nullptr)
825  AttrOutput().EmptyParagraph();
826  else
827  WriteHeaderFooterText(*pFormat, bHeader);
828  m_pAttrOutput->PopRelIdCache();
829  m_pAttrOutput->EndParaSdtBlock();
830  }
831 
832  // switch the serializer back
833  m_pAttrOutput->SetSerializer( m_pDocumentFS );
834  m_pVMLExport->SetFS( m_pDocumentFS );
835  m_pSdrExport->setSerializer(m_pDocumentFS);
836  SetFS( m_pDocumentFS );
837 
838  // close the tag
839  sal_Int32 nReference;
840  if ( bHeader )
841  {
842  pFS->endElementNS( XML_w, XML_hdr );
843  nReference = XML_headerReference;
844  }
845  else
846  {
847  pFS->endElementNS( XML_w, XML_ftr );
848  nReference = XML_footerReference;
849  }
850 
851  // and write the reference
852  m_pDocumentFS->singleElementNS( XML_w, nReference,
853  FSNS( XML_w, XML_type ), pType,
854  FSNS( XML_r, XML_id ), aRelId.toUtf8() );
855 }
856 
858 {
859  m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
860  oox::getRelationship(Relationship::FONTTABLE),
861  "fontTable.xml" );
862 
863  ::sax_fastparser::FSHelperPtr pFS = m_pFilter->openFragmentStreamWithSerializer(
864  "word/fontTable.xml",
865  "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml" );
866 
867  pFS->startElementNS( XML_w, XML_fonts,
868  FSNS( XML_xmlns, XML_w ), m_pFilter->getNamespaceURL(OOX_NS(doc)).toUtf8(),
869  FSNS( XML_xmlns, XML_r ), m_pFilter->getNamespaceURL(OOX_NS(officeRel)).toUtf8() );
870 
871  // switch the serializer to redirect the output to word/styles.xml
872  m_pAttrOutput->SetSerializer( pFS );
873 
874  // do the work
875  m_aFontHelper.WriteFontTable( *m_pAttrOutput );
876 
877  // switch the serializer back
878  m_pAttrOutput->SetSerializer( m_pDocumentFS );
879 
880  pFS->endElementNS( XML_w, XML_fonts );
881 }
882 
884 {
885  // Write the core properties
886  SwDocShell* pDocShell( m_pDoc->GetDocShell( ) );
887  uno::Reference<document::XDocumentProperties> xDocProps;
888  bool bSecurityOptOpenReadOnly = false;
889  if ( pDocShell )
890  {
891  uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
892  pDocShell->GetModel( ), uno::UNO_QUERY );
893  xDocProps = xDPS->getDocumentProperties();
894  bSecurityOptOpenReadOnly = pDocShell->IsSecurityOptOpenReadOnly();
895  }
896 
897  m_pFilter->exportDocumentProperties( xDocProps, bSecurityOptOpenReadOnly );
898 }
899 
901 {
902  SwViewShell *pViewShell(m_pDoc->getIDocumentLayoutAccess().GetCurrentViewShell());
903  if( !pViewShell && !m_aSettings.hasData() && !m_pAttrOutput->HasFootnotes() && !m_pAttrOutput->HasEndnotes())
904  return;
905 
906  m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
907  oox::getRelationship(Relationship::SETTINGS),
908  "settings.xml" );
909 
910  ::sax_fastparser::FSHelperPtr pFS = m_pFilter->openFragmentStreamWithSerializer(
911  "word/settings.xml",
912  "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml" );
913 
914  pFS->startElementNS( XML_w, XML_settings,
915  FSNS( XML_xmlns, XML_w ), m_pFilter->getNamespaceURL(OOX_NS(doc)).toUtf8() );
916 
917  // View
918  if (pViewShell && pViewShell->GetViewOptions()->getBrowseMode())
919  {
920  pFS->singleElementNS(XML_w, XML_view, FSNS(XML_w, XML_val), "web");
921  }
922 
923  // Zoom
924  if (pViewShell)
925  {
928 
929  switch (pViewShell->GetViewOptions()->GetZoomType())
930  {
931  case SvxZoomType::WHOLEPAGE:
932  pAttributeList->add(FSNS(XML_w, XML_val), "fullPage");
933  break;
934  case SvxZoomType::PAGEWIDTH:
935  pAttributeList->add(FSNS(XML_w, XML_val), "bestFit");
936  break;
937  case SvxZoomType::OPTIMAL:
938  pAttributeList->add(FSNS(XML_w, XML_val), "textFit");
939  break;
940  default:
941  break;
942  }
943 
944  OString aZoom(OString::number(pViewShell->GetViewOptions()->GetZoom()));
945  pAttributeList->add(FSNS(XML_w, XML_percent), aZoom);
946  sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList.get());
947  pFS->singleElementNS(XML_w, XML_zoom, xAttributeList);
948  }
949 
950  // Display Background Shape
951  if (std::shared_ptr<SvxBrushItem> oBrush = getBackground(); oBrush)
952  {
953  // Turn on the 'displayBackgroundShape'
954  pFS->singleElementNS(XML_w, XML_displayBackgroundShape);
955  }
956 
957  // Track Changes
958  if ( m_aSettings.trackRevisions )
959  pFS->singleElementNS(XML_w, XML_trackRevisions);
960 
961  // Mirror Margins
962  if(isMirroredMargin())
963  pFS->singleElementNS(XML_w, XML_mirrorMargins);
964 
965  // Embed Fonts
966  if( m_pDoc->getIDocumentSettingAccess().get( DocumentSettingId::EMBED_FONTS ))
967  pFS->singleElementNS(XML_w, XML_embedTrueTypeFonts);
968 
969  // Embed System Fonts
970  if( m_pDoc->getIDocumentSettingAccess().get( DocumentSettingId::EMBED_SYSTEM_FONTS ))
971  pFS->singleElementNS(XML_w, XML_embedSystemFonts);
972 
973  // Default Tab Stop
974  if( m_aSettings.defaultTabStop != 0 )
975  pFS->singleElementNS( XML_w, XML_defaultTabStop, FSNS( XML_w, XML_val ),
976  OString::number(m_aSettings.defaultTabStop) );
977 
978  // Do not justify lines with manual break
979  if( m_pDoc->getIDocumentSettingAccess().get( DocumentSettingId::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK ))
980  {
981  pFS->startElementNS(XML_w, XML_compat);
982  pFS->singleElementNS(XML_w, XML_doNotExpandShiftReturn);
983  pFS->endElementNS( XML_w, XML_compat );
984  }
985 
986  // export current mail merge database and table names
987  SwDBData aData = m_pDoc->GetDBData();
988  if ( !aData.sDataSource.isEmpty() && aData.nCommandType == css::sdb::CommandType::TABLE && !aData.sCommand.isEmpty() )
989  {
990  OUStringBuffer aDataSource;
991  aDataSource.append("SELECT * FROM ");
992  aDataSource.append(aData.sDataSource); // current database
993  aDataSource.append(".dbo."); // default database owner
994  aDataSource.append(aData.sCommand); // sheet name
995  aDataSource.append("$"); // sheet identifier
996  const OUString sDataSource = aDataSource.makeStringAndClear();
997  pFS->startElementNS( XML_w, XML_mailMerge );
998  pFS->singleElementNS(XML_w, XML_mainDocumentType,
999  FSNS( XML_w, XML_val ), "formLetters" );
1000  pFS->singleElementNS(XML_w, XML_dataType,
1001  FSNS( XML_w, XML_val ), "textFile" );
1002  pFS->singleElementNS( XML_w, XML_query,
1003  FSNS( XML_w, XML_val ), OUStringToOString( sDataSource, RTL_TEXTENCODING_UTF8 ).getStr() );
1004  pFS->endElementNS( XML_w, XML_mailMerge );
1005  }
1006 
1007  // Automatic hyphenation: it's a global setting in Word, it's a paragraph setting in Writer.
1008  // Use the setting from the default style.
1009  SwTextFormatColl* pColl = m_pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD, /*bRegardLanguage=*/false);
1010  const SfxPoolItem* pItem;
1011  if (pColl && SfxItemState::SET == pColl->GetItemState(RES_PARATR_HYPHENZONE, false, &pItem))
1012  {
1013  pFS->singleElementNS(XML_w, XML_autoHyphenation,
1014  FSNS(XML_w, XML_val), OString::boolean(static_cast<const SvxHyphenZoneItem*>(pItem)->IsHyphen()));
1015  }
1016 
1017  // Even and Odd Headers
1018  if( m_aSettings.evenAndOddHeaders )
1019  pFS->singleElementNS(XML_w, XML_evenAndOddHeaders);
1020 
1021  // Has Footnotes
1022  if( m_pAttrOutput->HasFootnotes())
1023  DocxAttributeOutput::WriteFootnoteEndnotePr( pFS, XML_footnotePr, m_pDoc->GetFootnoteInfo(), XML_footnote );
1024 
1025  // Has Endnotes
1026  if( m_pAttrOutput->HasEndnotes())
1027  DocxAttributeOutput::WriteFootnoteEndnotePr( pFS, XML_endnotePr, m_pDoc->GetEndNoteInfo(), XML_endnote );
1028 
1029  // Has themeFontLang information
1030  uno::Reference< beans::XPropertySet > xPropSet( m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1031 
1032  bool hasProtectionProperties = false;
1033  uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1034  const OUString aGrabBagName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
1035  if ( xPropSetInfo->hasPropertyByName( aGrabBagName ) )
1036  {
1037  uno::Sequence< beans::PropertyValue > propList;
1038  xPropSet->getPropertyValue( aGrabBagName ) >>= propList;
1039 
1040  for( sal_Int32 i=0; i < propList.getLength(); ++i )
1041  {
1042  if ( propList[i].Name == "ThemeFontLangProps" )
1043  {
1044  uno::Sequence< beans::PropertyValue > themeFontLangProps;
1045  propList[i].Value >>= themeFontLangProps;
1046  OUString aValues[3];
1047  for( sal_Int32 j=0; j < themeFontLangProps.getLength(); ++j )
1048  {
1049  if( themeFontLangProps[j].Name == "val" )
1050  themeFontLangProps[j].Value >>= aValues[0];
1051  else if( themeFontLangProps[j].Name == "eastAsia" )
1052  themeFontLangProps[j].Value >>= aValues[1];
1053  else if( themeFontLangProps[j].Name == "bidi" )
1054  themeFontLangProps[j].Value >>= aValues[2];
1055  }
1056  pFS->singleElementNS( XML_w, XML_themeFontLang,
1057  FSNS( XML_w, XML_val ), aValues[0].toUtf8(),
1058  FSNS( XML_w, XML_eastAsia ), aValues[1].toUtf8(),
1059  FSNS( XML_w, XML_bidi ), aValues[2].toUtf8() );
1060  }
1061  else if ( propList[i].Name == "CompatSettings" )
1062  {
1063  pFS->startElementNS(XML_w, XML_compat);
1064 
1065  uno::Sequence< beans::PropertyValue > aCompatSettingsSequence;
1066  propList[i].Value >>= aCompatSettingsSequence;
1067 
1068  for(sal_Int32 j=0; j < aCompatSettingsSequence.getLength(); ++j)
1069  {
1070  uno::Sequence< beans::PropertyValue > aCompatSetting;
1071  aCompatSettingsSequence[j].Value >>= aCompatSetting;
1072  OUString aName;
1073  OUString aUri;
1074  OUString aValue;
1075 
1076  for(sal_Int32 k=0; k < aCompatSetting.getLength(); ++k)
1077  {
1078  if( aCompatSetting[k].Name == "name" )
1079  aCompatSetting[k].Value >>= aName;
1080  else if( aCompatSetting[k].Name == "uri" )
1081  aCompatSetting[k].Value >>= aUri;
1082  else if( aCompatSetting[k].Name == "val" )
1083  aCompatSetting[k].Value >>= aValue;
1084  }
1085  pFS->singleElementNS( XML_w, XML_compatSetting,
1086  FSNS( XML_w, XML_name ), aName.toUtf8(),
1087  FSNS( XML_w, XML_uri ), aUri.toUtf8(),
1088  FSNS( XML_w, XML_val ), aValue.toUtf8());
1089  }
1090 
1091  pFS->endElementNS( XML_w, XML_compat );
1092  }
1093  else if (propList[i].Name == "DocumentProtection")
1094  {
1095 
1096  uno::Sequence< beans::PropertyValue > rAttributeList;
1097  propList[i].Value >>= rAttributeList;
1098 
1099  if (rAttributeList.hasElements())
1100  {
1102  for (sal_Int32 j = 0; j < rAttributeList.getLength(); ++j)
1103  {
1104  static DocxStringTokenMap const aTokens[] =
1105  {
1106  { "edit", XML_edit },
1107  { "enforcement", XML_enforcement },
1108  { "formatting", XML_formatting },
1109  { "cryptProviderType", XML_cryptProviderType },
1110  { "cryptAlgorithmClass", XML_cryptAlgorithmClass },
1111  { "cryptAlgorithmType", XML_cryptAlgorithmType },
1112  { "cryptAlgorithmSid", XML_cryptAlgorithmSid },
1113  { "cryptSpinCount", XML_cryptSpinCount },
1114  { "hash", XML_hash },
1115  { "salt", XML_salt },
1116  { nullptr, 0 }
1117  };
1118 
1119  if (sal_Int32 nToken = DocxStringGetToken(aTokens, rAttributeList[j].Name))
1120  pAttributeList->add(FSNS(XML_w, nToken), rAttributeList[j].Value.get<OUString>().toUtf8());
1121  }
1122 
1123  // we have document protection from input DOCX file
1124 
1125  sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
1126  pFS->singleElementNS(XML_w, XML_documentProtection, xAttributeList);
1127 
1128  hasProtectionProperties = true;
1129  }
1130  }
1131  }
1132  }
1133 
1134  // Protect form
1135  // Section-specific write protection
1136  if (! hasProtectionProperties)
1137  {
1138  if (m_pDoc->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_FORM) ||
1139  m_pSections->DocumentIsProtected())
1140  {
1141  // we have form protection from Writer or from input ODT file
1142 
1143  pFS->singleElementNS(XML_w, XML_documentProtection,
1144  FSNS(XML_w, XML_edit), "forms",
1145  FSNS(XML_w, XML_enforcement), "true");
1146  }
1147  }
1148 
1149  // finish settings.xml
1150  pFS->endElementNS( XML_w, XML_settings );
1151 }
1152 
1154 {
1155  uno::Reference< beans::XPropertySet > xPropSet( m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1156 
1157  uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1159  if ( !xPropSetInfo->hasPropertyByName( aName ) )
1160  return;
1161 
1162  uno::Reference<xml::dom::XDocument> themeDom;
1163  uno::Sequence< beans::PropertyValue > propList;
1164  xPropSet->getPropertyValue( aName ) >>= propList;
1165  for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp )
1166  {
1167  OUString propName = propList[nProp].Name;
1168  if ( propName == "OOXTheme" )
1169  {
1170  propList[nProp].Value >>= themeDom;
1171  break;
1172  }
1173  }
1174 
1175  // no theme dom to write
1176  if ( !themeDom.is() )
1177  return;
1178 
1179  m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
1180  oox::getRelationship(Relationship::THEME),
1181  "theme/theme1.xml" );
1182 
1183  uno::Reference< xml::sax::XSAXSerializable > serializer( themeDom, uno::UNO_QUERY );
1184  uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() );
1185  writer->setOutputStream( GetFilter().openFragmentStream( "word/theme/theme1.xml",
1186  "application/vnd.openxmlformats-officedocument.theme+xml" ) );
1187  serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1188  uno::Sequence< beans::StringPair >() );
1189 }
1190 
1192 {
1193  uno::Reference< beans::XPropertySet > xPropSet( m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1194 
1195  uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1197  if ( !xPropSetInfo->hasPropertyByName( aName ) )
1198  return;
1199 
1200  uno::Reference<xml::dom::XDocument> glossaryDocDom;
1201  uno::Sequence< uno::Sequence< uno::Any> > glossaryDomList;
1202  uno::Sequence< beans::PropertyValue > propList;
1203  xPropSet->getPropertyValue( aName ) >>= propList;
1204  sal_Int32 collectedProperties = 0;
1205  for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp )
1206  {
1207  OUString propName = propList[nProp].Name;
1208  if ( propName == "OOXGlossary" )
1209  {
1210  propList[nProp].Value >>= glossaryDocDom;
1211  collectedProperties++;
1212  }
1213  if (propName == "OOXGlossaryDom")
1214  {
1215  propList[nProp].Value >>= glossaryDomList;
1216  collectedProperties++;
1217  }
1218  if (collectedProperties == 2)
1219  break;
1220  }
1221 
1222  // no glossary dom to write
1223  if ( !glossaryDocDom.is() )
1224  return;
1225 
1226  m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
1227  oox::getRelationship(Relationship::GLOSSARYDOCUMENT),
1228  "glossary/document.xml" );
1229 
1230  uno::Reference< io::XOutputStream > xOutputStream = GetFilter().openFragmentStream( "word/glossary/document.xml",
1231  "application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml" );
1232 
1233  uno::Reference< xml::sax::XSAXSerializable > serializer( glossaryDocDom, uno::UNO_QUERY );
1234  uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() );
1235  writer->setOutputStream( xOutputStream );
1236  serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1237  uno::Sequence< beans::StringPair >() );
1238 
1239  sal_Int32 length = glossaryDomList.getLength();
1240  for ( int i =0; i < length; i++)
1241  {
1242  uno::Sequence< uno::Any> glossaryElement = glossaryDomList[i];
1243  OUString gTarget, gType, gId, contentType;
1244  uno::Reference<xml::dom::XDocument> xDom;
1245  glossaryElement[0] >>= xDom;
1246  glossaryElement[1] >>= gId;
1247  glossaryElement[2] >>= gType;
1248  glossaryElement[3] >>= gTarget;
1249  glossaryElement[4] >>= contentType;
1250  gId = gId.copy(3); //"rId" only save the numeric value
1251 
1252  PropertySet aProps(xOutputStream);
1253  aProps.setAnyProperty( PROP_RelId, uno::makeAny( gId.toInt32() ));
1254  m_pFilter->addRelation( xOutputStream, gType, gTarget);
1255  uno::Reference< xml::sax::XSAXSerializable > gserializer( xDom, uno::UNO_QUERY );
1256  writer->setOutputStream(GetFilter().openFragmentStream( "word/glossary/" + gTarget, contentType ) );
1257  gserializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1258  uno::Sequence< beans::StringPair >() );
1259  }
1260 }
1261 
1263 {
1264  uno::Reference< beans::XPropertySet > xPropSet( m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1265 
1266  uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1267  static const OUString aName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
1268  if ( !xPropSetInfo->hasPropertyByName( aName ) )
1269  return;
1270 
1271  uno::Sequence<uno::Reference<xml::dom::XDocument> > customXmlDomlist;
1272  uno::Sequence<uno::Reference<xml::dom::XDocument> > customXmlDomPropslist;
1273  uno::Sequence< beans::PropertyValue > propList;
1274  xPropSet->getPropertyValue( aName ) >>= propList;
1275  for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp )
1276  {
1277  const OUString propName = propList[nProp].Name;
1278  if ( propName == "OOXCustomXml" )
1279  {
1280  propList[nProp].Value >>= customXmlDomlist;
1281  break;
1282  }
1283  }
1284 
1285  for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp )
1286  {
1287  OUString propName = propList[nProp].Name;
1288  if ( propName == "OOXCustomXmlProps" )
1289  {
1290  propList[nProp].Value >>= customXmlDomPropslist;
1291  break;
1292  }
1293  }
1294 
1295  for (sal_Int32 j = 0; j < customXmlDomlist.getLength(); j++)
1296  {
1297  uno::Reference<xml::dom::XDocument> customXmlDom = customXmlDomlist[j];
1298  uno::Reference<xml::dom::XDocument> customXmlDomProps = customXmlDomPropslist[j];
1299  if (customXmlDom.is())
1300  {
1301  m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
1302  oox::getRelationship(Relationship::CUSTOMXML),
1303  "../customXml/item"+OUString::number((j+1))+".xml" );
1304 
1305  uno::Reference< xml::sax::XSAXSerializable > serializer( customXmlDom, uno::UNO_QUERY );
1306  uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() );
1307  writer->setOutputStream( GetFilter().openFragmentStream( "customXml/item"+OUString::number((j+1))+".xml",
1308  "application/xml" ) );
1309  serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1310  uno::Sequence< beans::StringPair >() );
1311  }
1312 
1313  if (customXmlDomProps.is())
1314  {
1315  uno::Reference< xml::sax::XSAXSerializable > serializer( customXmlDomProps, uno::UNO_QUERY );
1316  uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() );
1317  writer->setOutputStream( GetFilter().openFragmentStream( "customXml/itemProps"+OUString::number((j+1))+".xml",
1318  "application/vnd.openxmlformats-officedocument.customXmlProperties+xml" ) );
1319  serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1320  uno::Sequence< beans::StringPair >() );
1321 
1322  // Adding itemprops's relationship entry to item.xml.rels file
1323  m_pFilter->addRelation( GetFilter().openFragmentStream( "customXml/item"+OUString::number((j+1))+".xml",
1324  "application/xml" ) ,
1325  oox::getRelationship(Relationship::CUSTOMXMLPROPS),
1326  "itemProps"+OUString::number((j+1))+".xml" );
1327  }
1328  }
1329 }
1330 
1332 {
1333  uno::Reference<document::XStorageBasedDocument> xStorageBasedDocument(m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
1334  if (!xStorageBasedDocument.is())
1335  return;
1336 
1337  uno::Reference<embed::XStorage> xDocumentStorage(xStorageBasedDocument->getDocumentStorage(), uno::UNO_QUERY);
1338  OUString aMacrosName("_MS_VBA_Macros");
1339  if (!xDocumentStorage.is() || !xDocumentStorage->hasByName(aMacrosName))
1340  return;
1341 
1342  const sal_Int32 nOpenMode = embed::ElementModes::READ;
1343  uno::Reference<io::XStream> xMacrosStream(xDocumentStorage->openStreamElement(aMacrosName, nOpenMode), uno::UNO_QUERY);
1344  uno::Reference<io::XOutputStream> xProjectStream;
1345  if (xMacrosStream.is())
1346  {
1347  // First handle the project stream, this sets xProjectStream.
1348  std::unique_ptr<SvStream> pIn(utl::UcbStreamHelper::CreateStream(xMacrosStream));
1349 
1350  xProjectStream = GetFilter().openFragmentStream("word/vbaProject.bin", "application/vnd.ms-office.vbaProject");
1351  uno::Reference<io::XStream> xOutputStream(xProjectStream, uno::UNO_QUERY);
1352  if (!xOutputStream.is())
1353  return;
1354  std::unique_ptr<SvStream> pOut(utl::UcbStreamHelper::CreateStream(xOutputStream));
1355 
1356  // Write the stream.
1357  pOut->WriteStream(*pIn);
1358 
1359  // Write the relationship.
1360  m_pFilter->addRelation(m_pDocumentFS->getOutputStream(), oox::getRelationship(Relationship::VBAPROJECT), "vbaProject.bin");
1361  }
1362 
1363  OUString aDataName("_MS_VBA_Macros_XML");
1364  if (!xDocumentStorage.is() || !xDocumentStorage->hasByName(aDataName))
1365  return;
1366 
1367  uno::Reference<io::XStream> xDataStream(xDocumentStorage->openStreamElement(aDataName, nOpenMode), uno::UNO_QUERY);
1368  if (xDataStream.is())
1369  {
1370  // Then the data stream, which wants to work with an already set
1371  // xProjectStream.
1372  std::unique_ptr<SvStream> pIn(utl::UcbStreamHelper::CreateStream(xDataStream));
1373 
1374  uno::Reference<io::XStream> xOutputStream(GetFilter().openFragmentStream("word/vbaData.xml", "application/vnd.ms-word.vbaData+xml"), uno::UNO_QUERY);
1375  if (!xOutputStream.is())
1376  return;
1377  std::unique_ptr<SvStream> pOut(utl::UcbStreamHelper::CreateStream(xOutputStream));
1378 
1379  // Write the stream.
1380  pOut->WriteStream(*pIn);
1381 
1382  // Write the relationship.
1383  if (!xProjectStream.is())
1384  return;
1385 
1386  m_pFilter->addRelation(xProjectStream, oox::getRelationship(Relationship::WORDVBADATA), "vbaData.xml");
1387  }
1388 }
1389 
1391 {
1392  uno::Reference< beans::XPropertySet > xPropSet( m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1393 
1394  uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1396  if ( !xPropSetInfo->hasPropertyByName( aName ) )
1397  return;
1398 
1399  uno::Sequence< beans::PropertyValue > embeddingsList;
1400  uno::Sequence< beans::PropertyValue > propList;
1401  xPropSet->getPropertyValue( aName ) >>= propList;
1402  for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp )
1403  {
1404  OUString propName = propList[nProp].Name;
1405  if ( propName == "OOXEmbeddings" )
1406  {
1407  propList[nProp].Value >>= embeddingsList;
1408  break;
1409  }
1410  }
1411  for (sal_Int32 j = 0; j < embeddingsList.getLength(); j++)
1412  {
1413  OUString embeddingPath = embeddingsList[j].Name;
1414  uno::Reference<io::XInputStream> embeddingsStream;
1415  embeddingsList[j].Value >>= embeddingsStream;
1416 
1417  OUString contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
1418  // FIXME: this .xlsm hack is silly - if anything the mime-type for an existing embedded object should be read from [Content_Types].xml
1419  if (embeddingPath.endsWith(".xlsm"))
1420  contentType = "application/vnd.ms-excel.sheet.macroEnabled.12";
1421  else if (embeddingPath.endsWith(".bin"))
1422  contentType = "application/vnd.openxmlformats-officedocument.oleObject";
1423 
1424  if ( embeddingsStream.is() )
1425  {
1426  uno::Reference< io::XOutputStream > xOutStream = GetFilter().openFragmentStream(embeddingPath,
1427  contentType);
1428  try
1429  {
1430  sal_Int32 nBufferSize = 512;
1431  uno::Sequence< sal_Int8 > aDataBuffer(nBufferSize);
1432  sal_Int32 nRead;
1433  do
1434  {
1435  nRead = embeddingsStream->readBytes( aDataBuffer, nBufferSize );
1436  if( nRead )
1437  {
1438  if( nRead < nBufferSize )
1439  {
1440  nBufferSize = nRead;
1441  aDataBuffer.realloc(nRead);
1442  }
1443  xOutStream->writeBytes( aDataBuffer );
1444  }
1445  }
1446  while( nRead );
1447  xOutStream->flush();
1448  }
1449  catch(const uno::Exception&)
1450  {
1451  css::uno::Any ex( cppu::getCaughtException() );
1452  SAL_WARN("sw.ww8", "WriteEmbeddings() ::Failed to copy Inputstream to outputstream exception caught! " << exceptionToString(ex));
1453  }
1454  xOutStream->closeOutput();
1455  }
1456  }
1457 }
1458 
1460 {
1461  bool bMirroredMargins = false;
1462  if ( UseOnPage::Mirror == (UseOnPage::Mirror & m_pDoc->GetPageDesc(0).ReadUseOn()) )
1463  {
1464  bMirroredMargins = true;
1465  }
1466  return bMirroredMargins;
1467 }
1468 
1470 {
1471  // setup the namespaces
1472  m_pDocumentFS->startElementNS( XML_w, XML_document, MainXmlNamespaces());
1473 
1474  if ( getenv("SW_DEBUG_DOM") )
1475  {
1476  m_pDoc->dumpAsXml();
1477  }
1478 
1479  // reset the incrementing linked-textboxes chain ID before re-saving.
1480  m_nLinkedTextboxesChainId=0;
1481  m_aLinkedTextboxesHelper.clear();
1482 
1483  // Write background page color
1484  if (std::shared_ptr<SvxBrushItem> oBrush = getBackground(); oBrush)
1485  {
1486  Color backgroundColor = oBrush->GetColor();
1487  OString aBackgroundColorStr = msfilter::util::ConvertColor(backgroundColor);
1488 
1489  m_pDocumentFS->singleElementNS(XML_w, XML_background, FSNS(XML_w, XML_color),
1490  aBackgroundColorStr);
1491  }
1492 
1493  // body
1494  m_pDocumentFS->startElementNS(XML_w, XML_body);
1495 
1496  m_pCurPam->GetPoint()->nNode = m_pDoc->GetNodes().GetEndOfContent().StartOfSectionNode()->GetIndex();
1497 
1498  // the text
1499  WriteText();
1500 
1501  // clear linked textboxes since old ones can't be linked to frames in a different section (correct?)
1502  m_aLinkedTextboxesHelper.clear();
1503 
1504  // the last section info
1505  m_pAttrOutput->EndParaSdtBlock();
1506  const WW8_SepInfo *pSectionInfo = m_pSections? m_pSections->CurrentSectionInfo(): nullptr;
1507  if ( pSectionInfo )
1508  SectionProperties( *pSectionInfo );
1509 
1510  // finish body and document
1511  m_pDocumentFS->endElementNS( XML_w, XML_body );
1512  m_pDocumentFS->endElementNS( XML_w, XML_document );
1513 }
1514 
1516 {
1518  pAttr->add( FSNS( XML_xmlns, XML_o ), OUStringToOString(m_pFilter->getNamespaceURL(OOX_NS(vmlOffice)), RTL_TEXTENCODING_UTF8).getStr() );
1519  pAttr->add( FSNS( XML_xmlns, XML_r ), OUStringToOString(m_pFilter->getNamespaceURL(OOX_NS(officeRel)), RTL_TEXTENCODING_UTF8).getStr() );
1520  pAttr->add( FSNS( XML_xmlns, XML_v ), OUStringToOString(m_pFilter->getNamespaceURL(OOX_NS(vml)), RTL_TEXTENCODING_UTF8).getStr() );
1521  pAttr->add( FSNS( XML_xmlns, XML_w ), OUStringToOString(m_pFilter->getNamespaceURL(OOX_NS(doc)), RTL_TEXTENCODING_UTF8).getStr() );
1522  pAttr->add( FSNS( XML_xmlns, XML_w10 ), OUStringToOString(m_pFilter->getNamespaceURL(OOX_NS(vmlWord)), RTL_TEXTENCODING_UTF8).getStr() );
1523  pAttr->add( FSNS( XML_xmlns, XML_wp ), OUStringToOString(m_pFilter->getNamespaceURL(OOX_NS(dmlWordDr)), RTL_TEXTENCODING_UTF8).getStr() );
1524  pAttr->add( FSNS( XML_xmlns, XML_wps ), OUStringToOString(m_pFilter->getNamespaceURL(OOX_NS(wps)), RTL_TEXTENCODING_UTF8).getStr() );
1525  pAttr->add( FSNS( XML_xmlns, XML_wpg ), OUStringToOString(m_pFilter->getNamespaceURL(OOX_NS(wpg)), RTL_TEXTENCODING_UTF8).getStr() );
1526  pAttr->add( FSNS( XML_xmlns, XML_mc ), OUStringToOString(m_pFilter->getNamespaceURL(OOX_NS(mce)), RTL_TEXTENCODING_UTF8).getStr() );
1527  pAttr->add( FSNS( XML_xmlns, XML_wp14 ), OUStringToOString(m_pFilter->getNamespaceURL(OOX_NS(wp14)), RTL_TEXTENCODING_UTF8).getStr() );
1528  pAttr->add( FSNS( XML_xmlns, XML_w14 ), OUStringToOString(m_pFilter->getNamespaceURL(OOX_NS(w14)), RTL_TEXTENCODING_UTF8).getStr() );
1529  pAttr->add( FSNS( XML_mc, XML_Ignorable ), "w14 wp14" );
1530  return XFastAttributeListRef( pAttr );
1531 }
1532 
1533 bool DocxExport::ignoreAttributeForStyleDefaults( sal_uInt16 nWhich ) const
1534 {
1535  if( nWhich == RES_TEXTGRID )
1536  return true; // w:docGrid is written only to document.xml, not to styles.xml
1537  if (nWhich == RES_PARATR_HYPHENZONE)
1538  return true; // w:suppressAutoHyphens is only a formatting exception, not a default
1540 }
1541 
1543 {
1544  const EditTextObject& rEditObj = rParaObj.GetTextObject();
1545  MSWord_SdrAttrIter aAttrIter( *this, rEditObj, nTyp );
1546 
1547  sal_Int32 nPara = rEditObj.GetParagraphCount();
1548  for( sal_Int32 n = 0; n < nPara; ++n )
1549  {
1550  if( n )
1551  aAttrIter.NextPara( n );
1552 
1553  AttrOutput().StartParagraph( ww8::WW8TableNodeInfo::Pointer_t());
1554  rtl_TextEncoding eChrSet = aAttrIter.GetNodeCharSet();
1555  OUString aStr( rEditObj.GetText( n ));
1556  sal_Int32 nCurrentPos = 0;
1557  const sal_Int32 nEnd = aStr.getLength();
1558  do {
1559  AttrOutput().StartRun( nullptr, 0 );
1560  const sal_Int32 nNextAttr = std::min(aAttrIter.WhereNext(), nEnd);
1561  rtl_TextEncoding eNextChrSet = aAttrIter.GetNextCharSet();
1562 
1563  bool bTextAtr = aAttrIter.IsTextAttr( nCurrentPos );
1564  if( !bTextAtr )
1565  {
1566  if( nCurrentPos == 0 && nNextAttr - nCurrentPos == aStr.getLength())
1567  AttrOutput().RunText( aStr, eChrSet );
1568  else
1569  {
1570  OUString tmp( aStr.copy( nCurrentPos, nNextAttr - nCurrentPos ));
1571  AttrOutput().RunText( tmp, eChrSet );
1572  }
1573  }
1574  AttrOutput().StartRunProperties();
1575  aAttrIter.OutAttr( nCurrentPos );
1576  AttrOutput().EndRunProperties( nullptr );
1577 
1578  nCurrentPos = nNextAttr;
1579  eChrSet = eNextChrSet;
1580  aAttrIter.NextPos();
1581 
1582  AttrOutput().EndRun( nullptr, 0 );
1583 
1584  } while( nCurrentPos < nEnd );
1585 // aAttrIter.OutParaAttr(false);
1586  AttrOutput().EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t());
1587  }
1588 }
1589 
1591 {
1592  mpFS = pFS;
1593 }
1594 
1595 DocxExport::DocxExport(DocxExportFilter* pFilter, SwDoc* pDocument, SwPaM* pCurrentPam,
1596  SwPaM* pOriginalPam, bool bDocm, bool bTemplate)
1597  : MSWordExportBase( pDocument, pCurrentPam, pOriginalPam ),
1598  m_pFilter( pFilter ),
1599  m_nHeaders( 0 ),
1600  m_nFooters( 0 ),
1601  m_nOLEObjects( 0 ),
1602  m_nActiveXControls( 0 ),
1603  m_nHeadersFootersInSection(0),
1604  m_bDocm(bDocm),
1605  m_bTemplate(bTemplate)
1606 {
1607  // Write the document properties
1608  WriteProperties( );
1609 
1610  // relations for the document
1611  m_pFilter->addRelation( oox::getRelationship(Relationship::OFFICEDOCUMENT),
1612  "word/document.xml" );
1613 
1614  // Set media type depending of document type
1615  OUString aMediaType;
1616  if (m_bDocm)
1617  {
1618  if (m_bTemplate)
1619  {
1620  aMediaType = "application/vnd.ms-word.template.macroEnabledTemplate.main+xml";
1621  }
1622  else
1623  {
1624  aMediaType = "application/vnd.ms-word.document.macroEnabled.main+xml";
1625  }
1626  }
1627  else
1628  {
1629  if (m_bTemplate)
1630  {
1631  aMediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml";
1632  }
1633  else
1634  {
1635  aMediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";
1636  }
1637  }
1638 
1639 
1640  // the actual document
1641  m_pDocumentFS = m_pFilter->openFragmentStreamWithSerializer( "word/document.xml", aMediaType );
1642 
1644 
1645  // the DrawingML access
1647 
1648  // the attribute output for the document
1649  m_pAttrOutput.reset(new DocxAttributeOutput( *this, m_pDocumentFS, m_pDrawingML.get() ));
1650 
1651  // the related VMLExport
1652  m_pVMLExport.reset(new VMLExport( m_pDocumentFS, m_pAttrOutput.get() ));
1653 
1654  // the related drawing export
1655  m_pSdrExport.reset(new DocxSdrExport( *this, m_pDocumentFS, m_pDrawingML.get() ));
1656 }
1657 
1659 {
1660 }
1661 
1663 : evenAndOddHeaders( false )
1664 , defaultTabStop( 0 )
1665 , trackRevisions( false )
1666 {
1667 }
1668 
1670 {
1671  if( evenAndOddHeaders )
1672  return true;
1673  if( defaultTabStop != 0 )
1674  return true;
1675  if ( trackRevisions )
1676  return true;
1677 
1678  return false;
1679 }
1680 
1681 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void WriteFootnotesEndnotes()
Write footnotes.xml and endnotes.xml.
Definition: docxexport.cxx:669
bool IsHyphen(sal_Unicode cChar)
#define RES_CHRATR_WEIGHT
Definition: hintids.hxx:83
void OutAttr(sal_Int32 nSwPos)
Definition: wrtw8esh.cxx:1127
void InitStyles()
Setup pStyles and write styles.xml.
Definition: docxexport.cxx:646
virtual void DoFormText(const SwInputField *pField) override
Definition: docxexport.cxx:378
sal_Int32 WhereNext() const
Definition: wrtww8.hxx:1460
virtual void OutputLinkedOLE(const OUString &) override
Definition: docxexport.cxx:610
const char * sGUID
std::unique_ptr< oox::vml::VMLExport > m_pVMLExport
Exporter of the VML shapes.
Definition: docxexport.hxx:103
sal_Int32 nCommandType
Definition: swdbdata.hxx:32
bool hasData() const
const HdFtFlags WW8_FOOTER_FIRST
Definition: ww8scan.hxx:1601
Class to collect and output the sections/headers/footers.
Definition: wrtww8.hxx:199
DocxAttributeOutput & DocxAttrOutput() const
Access to the derived attribute output class.
Definition: docxexport.cxx:106
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
The class that has handlers for various resource types when exporting as DOCX.
Handles DOCX export of drawings.
bool IsSectionNode() const
Definition: node.hxx:644
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
Definition: fmtpdsc.hxx:35
virtual bool DisallowInheritingOutlineNumbering(const SwFormat &rFormat) override
Return value indicates if an inherited outline numbering is suppressed.
Definition: docxexport.cxx:229
#define RES_CHRATR_FONTSIZE
Definition: hintids.hxx:76
rtl_TextEncoding GetNodeCharSet() const
Definition: wrtww8.hxx:1462
static FastAttributeList * createAttrList()
const OUString & GetText() const
Definition: ndtxt.hxx:211
static void CopyInputToOutput(const css::uno::Reference< css::io::XInputStream > &xInput, const css::uno::Reference< css::io::XOutputStream > &xOutput)
virtual void OutputEndNode(const SwEndNode &)
Output SwEndNode.
Definition: wrtww8.cxx:4182
virtual void AppendBookmarks(const SwTextNode &rNode, sal_Int32 nCurrentPos, sal_Int32 nLen) override
Definition: docxexport.cxx:150
css::uno::Reference< css::xml::sax::XFastAttributeList > XFastAttributeListRef
std::pair< OString, OString > WriteActiveXObject(const uno::Reference< css::drawing::XShape > &rxShape, const uno::Reference< awt::XControlModel > &rxControlModel)
Definition: docxexport.cxx:449
#define RES_CHRATR_CJK_POSTURE
Definition: hintids.hxx:93
#define FSNS(namespc, element)
bool IsSecurityOptOpenReadOnly() const
sal_uIntPtr sal_uLong
OUString sDataSource
Definition: swdbdata.hxx:30
virtual void WriteHyperlinkData(const ::sw::mark::IFieldmark &rFieldmark) override
Definition: docxexport.cxx:324
Base class of all fields.
Definition: fldbas.hxx:279
css::uno::Reference< css::embed::XEmbeddedObject > const & GetOleRef()
Definition: ndole.cxx:900
bool const m_bDocm
If the result will be a .docm file or not.
Definition: docxexport.hxx:109
Definition: doc.hxx:185
sal_Int16 nId
#define RES_CHRATR_CJK_WEIGHT
Definition: hintids.hxx:94
All the information that should be stashed away when we're in the middle of of a table export and sti...
SwNode & GetNode() const
Definition: ndindex.hxx:118
void WriteSettings()
Write word/settings.xml.
Definition: docxexport.cxx:900
void WriteGlossary()
SwSectionFormat * GetFormat()
Definition: section.hxx:337
OUString Name
void WriteFonts()
Write word/fontTable.xml.
Definition: docxexport.cxx:857
virtual void WriteHeadersFooters(sal_uInt8 nHeadFootFlags, const SwFrameFormat &rFormat, const SwFrameFormat &rLeftFormat, const SwFrameFormat &rFirstPageFormat, sal_uInt8 nBreakCode) override
Output the actual headers and footers.
Definition: docxexport.cxx:251
#define RES_CHRATR_CJK_FONTSIZE
Definition: hintids.hxx:91
virtual void OutputGrfNode(const SwGrfNode &) override
Output SwGrfNode.
Definition: docxexport.cxx:600
void WriteCustomXml()
Write customXml/item[n].xml and customXml/itemProps[n].xml.
bool isMirroredMargin()
return true if Page Layout is set as Mirrored
Used to export formatted text associated to drawings.
Definition: wrtww8.hxx:1424
sax_fastparser::XFastAttributeListRef MainXmlNamespaces()
All xml namespaces to be used at the top of any text .xml file (main doc, headers, footers,...)
OUString FieldString(ww::eField eIndex)
Definition: ww8atr.cxx:2579
const SwSection & GetSection() const
Definition: node.hxx:541
Value
static void WriteFootnoteEndnotePr(::sax_fastparser::FSHelperPtr const &fs, int tag, const SwEndNoteInfo &info, int listtag)
writes the footnotePr/endnotePr (depending on tag) section
FieldFlags
Definition: wrtww8.hxx:147
std::unique_ptr< DocxAttributeOutput > m_pAttrOutput
Attribute output for document.
Definition: docxexport.hxx:82
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
bool const m_bTemplate
Export is done into template (.dotx)
Definition: docxexport.hxx:112
Class to collect and output the styles table.
Definition: wrtww8.hxx:1537
Any SAL_CALL getCaughtException()
virtual bool ignoreAttributeForStyleDefaults(sal_uInt16 nWhich) const override
Used to filter out attributes that can be e.g. written to .doc but not to .docx.
virtual AttributeOutputBase & AttrOutput() const override
Access to the attribute output class.
Definition: docxexport.cxx:101
ShapeExport & WriteShape(const css::uno::Reference< css::drawing::XShape > &xShape)
OString OutputChart(css::uno::Reference< css::frame::XModel > const &xModel, sal_Int32 nCount,::sax_fastparser::FSHelperPtr const &m_pSerializer)
Returns the relationd id.
Definition: docxexport.cxx:385
length
eField
Definition: fields.hxx:26
void WritePostitFields()
Write comments.xml.
Definition: docxexport.cxx:726
virtual void AppendAnnotationMarks(const SwTextNode &rNode, sal_Int32 nCurrentPos, sal_Int32 nLen) override
Definition: docxexport.cxx:191
const HdFtFlags WW8_FOOTER_EVEN
Definition: ww8scan.hxx:1598
sal_uLong GetStartValue() const
Definition: fmtline.hxx:56
#define RES_PARATR_NUMRULE
Definition: hintids.hxx:170
OString WriteOLEObject(SwOLEObj &rObject, OUString &io_rProgID)
Definition: docxexport.cxx:401
void WriteOutliner(const OutlinerParaObject &rOutliner, sal_uInt8 nTyp)
RedlineFlags on.
virtual void AppendSection(const SwPageDesc *pPageDesc, const SwSectionFormat *pFormat, sal_uLong nLnNum) override
Definition: docxexport.cxx:551
void WriteHeaderFooter(const SwFormat *pFormat, bool bHeader, const char *pType)
Write reference to a header/footer + the actual xml containing the text.
Definition: docxexport.cxx:781
OString AddRelation(const OUString &rType, const OUString &rTarget)
Returns the relationd id.
Definition: docxexport.cxx:221
OUString getRelationship(Relationship eRelationship)
virtual MSWordSections & Sections() const override
Access to the sections/headers/footres.
Definition: docxexport.cxx:111
#define UNO_NAME_MISC_OBJ_INTEROPGRABBAG
OUString GetText(sal_Int32 nPara) const
bool getOutputStream(ProgramOptions const &options, OString const &extension, std::ostream **ppOutputStream, OString &targetSourceFileName, OString &tmpSourceFileName)
const HdFtFlags WW8_HEADER_ODD
Definition: ww8scan.hxx:1597
Base class for various Writer styles.
Definition: format.hxx:43
void WriteEmbeddings()
Write word/embeddings/Worksheet[n].xlsx.
bool IsContentNode() const
Definition: node.hxx:628
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
const EditTextObject & GetTextObject() const
::sax_fastparser::FSHelperPtr openFragmentStreamWithSerializer(const OUString &rStreamName, const OUString &rMediaType)
void WriteProperties()
Write docProps/core.xml.
Definition: docxexport.cxx:883
Style of a layout element.
Definition: frmfmt.hxx:57
virtual bool CollapseScriptsforWordOk(sal_uInt16 nScript, sal_uInt16 nWhich) override
Guess the script (asian/western).
Definition: docxexport.cxx:116
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:131
OUString sName
int i
void OutputDML(css::uno::Reference< css::drawing::XShape > const &xShape)
Writes the shape using drawingML syntax.
Definition: docxexport.cxx:497
SwContentNode * GetContentNode()
Definition: node.hxx:615
#define RES_PARATR_HYPHENZONE
Definition: hintids.hxx:167
sal_Int32 DocxStringGetToken(DocxStringTokenMap const *pMap, const OUString &rName)
std::unique_ptr< oox::drawingml::DrawingML > m_pDrawingML
Access to the DrawingML writer.
Definition: docxexport.hxx:79
OString ConvertColor(const Color &rColor)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
Definition: format.cxx:398
Marks a node in the document model.
Definition: ndindex.hxx:31
bool IsEndNode() const
Definition: node.hxx:632
GUIDCNamePair const aData
virtual void OutputOLENode(const SwOLENode &) override
Output SwOLENode.
Definition: docxexport.cxx:605
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
void SetFS(::sax_fastparser::FSHelperPtr const &mpFS)
std::shared_ptr< FastSerializerHelper > FSHelperPtr
virtual void OutputEndNode(const SwEndNode &) override
Output SwEndNode.
Definition: docxexport.cxx:557
virtual void DoComboBox(const OUString &rName, const OUString &rHelp, const OUString &ToolTip, const OUString &rSelected, css::uno::Sequence< OUString > &rListItems) override
Definition: docxexport.cxx:331
OString exceptionToString(const css::uno::Any &caught)
SwSectionFormat * GetParent() const
Definition: section.hxx:356
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
std::unique_ptr< DocxSdrExport > m_pSdrExport
Exporter of drawings.
Definition: docxexport.hxx:106
sal_Int32 GetParagraphCount() const
virtual void WriteNumbering() override
Write the numbering table.
Definition: docxexport.cxx:746
SwFormat * DerivedFrom() const
Definition: format.hxx:108
OUString addRelation(const OUString &rType, const OUString &rTarget)
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
virtual sal_uLong ReplaceCr(sal_uInt8 nChar) override
Definition: docxexport.cxx:615
virtual void PrepareNewPageDesc(const SfxItemSet *pSet, const SwNode &rNd, const SwFormatPageDesc *pNewPgDescFormat, const SwPageDesc *pNewPgDesc) override
Get ready for a new section.
Definition: docxexport.cxx:622
::sax_fastparser::FSHelperPtr m_pDocumentFS
Fast serializer for the document output.
Definition: docxexport.hxx:73
#define RES_TEXTGRID
Definition: hintids.hxx:220
void WriteVBA()
Writes word/vbaProject.bin.
DocxExportFilter * m_pFilter
Pointer to the filter that owns us.
Definition: docxexport.hxx:70
#define ERRCODE_NONE
unsigned char sal_uInt8
#define RES_CHRATR_POSTURE
Definition: hintids.hxx:79
bool IsTextAttr(sal_Int32 nSwPos)
Definition: wrtw8esh.cxx:1207
#define SAL_INFO(area, stream)
virtual ErrCode ExportDocument_Impl() override
Format-dependent part of the actual export.
Definition: docxexport.cxx:509
const HdFtFlags WW8_HEADER_FIRST
Definition: ww8scan.hxx:1600
void WriteTheme()
Write word/theme/theme1.xml.
virtual void WriteFormData(const ::sw::mark::IFieldmark &rFieldmark) override
Write the data of the form field.
Definition: docxexport.cxx:319
const sal_uInt8 PageBreak
void add(sal_Int32 nToken, const sal_Char *pValue)
The physical access to the DOCX document (for writing).
Reference< XComponentContext > getProcessComponentContext()
std::shared_ptr< WW8TableNodeInfoInner > Pointer_t
virtual void OutputField(const SwField *pField, ww::eField eFieldType, const OUString &rFieldCmd, FieldFlags nMode=FieldFlags::All) override
Write the field.
Definition: docxexport.cxx:314
static void ResetCounters()
bool evenAndOddHeaders
returns true if there are any non-default settings (i.e. something to write)
Definition: docxexport.hxx:61
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:723
OString const aName
uno::Reference< io::XInputStream > GetOLEObjectStream(uno::Reference< uno::XComponentContext > const &xContext, uno::Reference< embed::XEmbeddedObject > const &xObj, OUString const &i_rProgID, OUString &o_rMediaType, OUString &o_rRelationType, OUString &o_rSuffix, const char *&o_rpProgID)
virtual bool ignoreAttributeForStyleDefaults(sal_uInt16) const
Used to filter out attributes that can be e.g. written to .doc but not to .docx.
Definition: wrtww8.hxx:667
virtual void AppendBookmark(const OUString &rName) override
Definition: docxexport.cxx:180
#define SAL_WARN(area, stream)
Base class for WW8Export and DocxExport.
Definition: wrtww8.hxx:453
Reference< XModel > xModel
bool IsTableNode() const
Definition: node.hxx:640
virtual ~DocxExport() override
Destructor.
SwSectionNode * GetSectionNode()
Definition: node.hxx:607
Ends a section of nodes in the document model.
Definition: node.hxx:333
rtl_TextEncoding GetNextCharSet() const
Definition: wrtw8esh.cxx:1053
SectionType GetType() const
Definition: section.hxx:171
std::vector< ::sw::mark::IMark * > IMarkVector
Used to split the runs according to the bookmarks start and ends.
Definition: wrtww8.hxx:575
std::shared_ptr< WW8TableNodeInfo > Pointer_t
DefTokenId const nToken
OUString sCommand
Definition: swdbdata.hxx:31
aStr
DocxExport(DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM *pOriginalPam, bool bDocm, bool bTemplate)
Pass the pDocument, pCurrentPam and pOriginalPam to the base class.
void NextPara(sal_Int32 nPar)
Definition: wrtw8esh.cxx:1033
const HdFtFlags WW8_FOOTER_ODD
Definition: ww8scan.hxx:1599
virtual void ExportGrfBullet(const SwTextNode &) override
Definition: docxexport.cxx:215
const HdFtFlags WW8_HEADER_EVEN
Definition: ww8scan.hxx:1596
const SwFormatLineNumber & GetLineNumber(bool=true) const
Definition: fmtline.hxx:63
Base class of the Writer document model elements.
Definition: node.hxx:79
void WriteMainText()
FIXME this is temporary, remotely reminding the method of the same name in WW8Export.
OUString sId