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/io/XSeekable.hpp>
37 #include <com/sun/star/sdb/CommandType.hpp>
38 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
39 #include <com/sun/star/util/XModifiable.hpp>
40 
41 #include <oox/token/namespaces.hxx>
42 #include <oox/token/tokens.hxx>
43 #include <oox/export/drawingml.hxx>
44 #include <oox/export/vmlexport.hxx>
46 #include <oox/export/shapes.hxx>
49 #include <oox/ole/olestorage.hxx>
50 #include <oox/ole/olehelper.hxx>
51 
52 #include <map>
53 #include <algorithm>
54 
55 #include <IMark.hxx>
59 #include <docsh.hxx>
60 #include <ndtxt.hxx>
61 #include "wrtww8.hxx"
62 #include <fmtline.hxx>
63 #include <fmtpdsc.hxx>
64 #include <frmfmt.hxx>
65 #include <section.hxx>
66 #include <ftninfo.hxx>
67 #include <pagedesc.hxx>
68 #include <poolfmt.hxx>
69 #include <swdbdata.hxx>
70 
71 #include <editeng/unoprnms.hxx>
72 #include <editeng/editobj.hxx>
73 #include <editeng/outlobj.hxx>
74 #include <editeng/brushitem.hxx>
76 
77 #include <viewsh.hxx>
78 #include <viewopt.hxx>
79 
80 #include "ww8scan.hxx"
81 #include <oox/token/properties.hxx>
83 #include <comphelper/sequence.hxx>
85 #include <o3tl/any.hxx>
86 #include <sal/log.hxx>
88 #include <tools/diagnose_ex.h>
89 
90 using namespace sax_fastparser;
91 using namespace ::comphelper;
92 using namespace ::com::sun::star;
93 using namespace ::oox;
94 
96 
97 using sw::mark::IMark;
98 
100 {
101  return *m_pAttrOutput;
102 }
103 
105 {
106  return *m_pAttrOutput;
107 }
108 
110 {
111  return *m_pSections;
112 }
113 
114 bool DocxExport::CollapseScriptsforWordOk( sal_uInt16 nScript, sal_uInt16 nWhich )
115 {
116  // TODO FIXME is this actually true for docx? - this is ~copied from WW8
117  if ( nScript == i18n::ScriptType::ASIAN )
118  {
119  // for asian in ww8, there is only one fontsize
120  // and one fontstyle (posture/weight)
121  switch ( nWhich )
122  {
123  case RES_CHRATR_FONTSIZE:
124  case RES_CHRATR_POSTURE:
125  case RES_CHRATR_WEIGHT:
126  return false;
127  default:
128  break;
129  }
130  }
131  else if ( nScript != i18n::ScriptType::COMPLEX )
132  {
133  // for western in ww8, there is only one fontsize
134  // and one fontstyle (posture/weight)
135  switch ( nWhich )
136  {
140  return false;
141  default:
142  break;
143  }
144  }
145  return true;
146 }
147 
148 void DocxExport::AppendBookmarks( const SwTextNode& rNode, sal_Int32 nCurrentPos, sal_Int32 nLen )
149 {
150  std::vector< OUString > aStarts;
151  std::vector< OUString > aEnds;
152 
153  IMarkVector aMarks;
154  if ( GetBookmarks( rNode, nCurrentPos, nCurrentPos + nLen, aMarks ) )
155  {
156  for ( IMark* pMark : aMarks )
157  {
158  const sal_Int32 nStart = pMark->GetMarkStart().nContent.GetIndex();
159  const sal_Int32 nEnd = pMark->GetMarkEnd().nContent.GetIndex();
160 
161  if ( nStart == nCurrentPos )
162  aStarts.push_back( pMark->GetName() );
163 
164  if ( nEnd == nCurrentPos )
165  aEnds.push_back( pMark->GetName() );
166  }
167  }
168 
169  const OUString& aStr( rNode.GetText() );
170  const sal_Int32 nEnd = aStr.getLength();
171 
172  if ( nCurrentPos == nEnd )
173  m_pAttrOutput->WriteFinalBookmarks_Impl( aStarts, aEnds );
174  else
175  m_pAttrOutput->WriteBookmarks_Impl( aStarts, aEnds );
176 }
177 
178 void DocxExport::AppendBookmark( const OUString& rName )
179 {
180  std::vector< OUString > aStarts;
181  std::vector< OUString > aEnds;
182 
183  aStarts.push_back( rName );
184  aEnds.push_back( rName );
185 
186  m_pAttrOutput->WriteBookmarks_Impl( aStarts, aEnds );
187 }
188 
189 void DocxExport::AppendAnnotationMarks( const SwWW8AttrIter& rAttrs, sal_Int32 nCurrentPos, sal_Int32 nLen )
190 {
191  std::vector< OUString > aStarts;
192  std::vector< OUString > aEnds;
193 
194  IMarkVector aMarks;
195  if (GetAnnotationMarks(rAttrs, nCurrentPos, nCurrentPos + nLen, aMarks))
196  {
197  for ( IMark* pMark : aMarks )
198  {
199  const sal_Int32 nStart = pMark->GetMarkStart().nContent.GetIndex();
200  const sal_Int32 nEnd = pMark->GetMarkEnd().nContent.GetIndex();
201 
202  if ( nStart == nCurrentPos )
203  aStarts.push_back( pMark->GetName() );
204 
205  if ( nEnd == nCurrentPos )
206  aEnds.push_back( pMark->GetName() );
207  }
208  }
209 
210  m_pAttrOutput->WriteAnnotationMarks_Impl( aStarts, aEnds );
211 }
212 
214 {
215  // Just collect the bullets for now, numbering.xml is not yet started.
216  CollectGrfsOfBullets();
217 }
218 
219 OString DocxExport::AddRelation( const OUString& rType, std::u16string_view rTarget )
220 {
221  OUString sId = m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
222  rType, rTarget, true );
223 
224  return sId.toUtf8();
225 }
226 
228 {
229  bool bRet( false );
230 
231  if (SfxItemState::SET != rFormat.GetItemState(RES_PARATR_NUMRULE, false))
232  {
233  if (const SwFormat *pParent = rFormat.DerivedFrom())
234  {
235  if (static_cast<const SwTextFormatColl*>(pParent)->IsAssignedToListLevelOfOutlineStyle())
236  {
237  ::sax_fastparser::FSHelperPtr pSerializer = m_pAttrOutput->GetSerializer( );
238  // Level 9 disables the outline
239  pSerializer->singleElementNS(XML_w, XML_outlineLvl, FSNS(XML_w, XML_val), "9");
240 
241  bRet = true;
242  }
243  }
244  }
245 
246  return bRet;
247 }
248 
250  const SwFrameFormat& rFormat, const SwFrameFormat& rLeftHeaderFormat, const SwFrameFormat& rLeftFooterFormat, const SwFrameFormat& rFirstPageFormat,
251  sal_uInt8 nBreakCode, bool bEvenAndOddHeaders )
252 {
253  m_nHeadersFootersInSection = 1;
254 
255  // document setting indicating the requirement of EVEN and ODD for both headers and footers
256  if ( nHeadFootFlags & ( nsHdFtFlags::WW8_FOOTER_EVEN | nsHdFtFlags::WW8_HEADER_EVEN ) && bEvenAndOddHeaders )
257  m_aSettings.evenAndOddHeaders = true;
258 
259  // Turn ON flag for 'Writing Headers \ Footers'
260  m_pAttrOutput->SetWritingHeaderFooter( true );
261 
262  // headers
263  if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_EVEN )
264  WriteHeaderFooter( &rLeftHeaderFormat, true, "even" );
265  else if ( m_aSettings.evenAndOddHeaders )
266  {
267  if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_ODD )
268  WriteHeaderFooter( &rFormat, true, "even" );
269  else if ( m_bHasHdr && nBreakCode == 2 )
270  WriteHeaderFooter( nullptr, true, "even" );
271  }
272 
273  if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_ODD )
274  WriteHeaderFooter( &rFormat, true, "default" );
275 
276  if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_FIRST )
277  WriteHeaderFooter( &rFirstPageFormat, true, "first" );
278 
279  if( (nHeadFootFlags & (nsHdFtFlags::WW8_HEADER_EVEN
280  | nsHdFtFlags::WW8_HEADER_ODD
281  | nsHdFtFlags::WW8_HEADER_FIRST)) == 0
282  && m_bHasHdr && nBreakCode == 2 ) // 2: nexPage
283  WriteHeaderFooter( nullptr, true, "default" );
284 
285 
286  // footers
287  if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_EVEN )
288  WriteHeaderFooter( &rLeftFooterFormat, false, "even" );
289  else if ( m_aSettings.evenAndOddHeaders )
290  {
291  if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_ODD )
292  WriteHeaderFooter( &rFormat, false, "even" );
293  else if ( m_bHasFtr && nBreakCode == 2 )
294  WriteHeaderFooter( nullptr, false, "even");
295  }
296 
297  if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_ODD )
298  WriteHeaderFooter( &rFormat, false, "default" );
299 
300  if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_FIRST )
301  WriteHeaderFooter( &rFirstPageFormat, false, "first" );
302 
303  if( (nHeadFootFlags & (nsHdFtFlags::WW8_FOOTER_EVEN
304  | nsHdFtFlags::WW8_FOOTER_ODD
305  | nsHdFtFlags::WW8_FOOTER_FIRST)) == 0
306  && m_bHasFtr && nBreakCode == 2 ) // 2: nexPage
307  WriteHeaderFooter( nullptr, false, "default");
308 
309  // Turn OFF flag for 'Writing Headers \ Footers'
310  m_pAttrOutput->SetWritingHeaderFooter( false );
311 }
312 
313 void DocxExport::OutputField( const SwField* pField, ww::eField eFieldType, const OUString& rFieldCmd, FieldFlags nMode )
314 {
315  m_pAttrOutput->WriteField_Impl( pField, eFieldType, rFieldCmd, nMode );
316 }
317 
318 void DocxExport::WriteFormData( const ::sw::mark::IFieldmark& rFieldmark )
319 {
320  m_pAttrOutput->WriteFormData_Impl( rFieldmark );
321 }
322 
323 void DocxExport::WriteHyperlinkData( const ::sw::mark::IFieldmark& /*rFieldmark*/ )
324 {
325 #if OSL_DEBUG_LEVEL > 1
326  fprintf( stderr, "TODO DocxExport::WriteHyperlinkData()\n" );
327 #endif
328 }
329 
330 void DocxExport::DoComboBox(const OUString& rName,
331  const OUString& rHelp,
332  const OUString& rToolTip,
333  const OUString& rSelected,
334  const uno::Sequence<OUString>& rListItems)
335 {
336  m_pDocumentFS->startElementNS(XML_w, XML_ffData);
337 
338  m_pDocumentFS->singleElementNS(XML_w, XML_name, FSNS(XML_w, XML_val), rName);
339 
340  m_pDocumentFS->singleElementNS(XML_w, XML_enabled);
341 
342  if ( !rHelp.isEmpty() )
343  m_pDocumentFS->singleElementNS(XML_w, XML_helpText, FSNS(XML_w, XML_val), rHelp);
344 
345  if ( !rToolTip.isEmpty() )
346  m_pDocumentFS->singleElementNS(XML_w, XML_statusText, FSNS(XML_w, XML_val), rToolTip);
347 
348  m_pDocumentFS->startElementNS(XML_w, XML_ddList);
349 
350  // Output the 0-based index of the selected value
351  sal_Int32 nId = comphelper::findValue(rListItems, rSelected);
352  if (nId == -1)
353  nId = 0;
354 
355  m_pDocumentFS->singleElementNS(XML_w, XML_result, FSNS(XML_w, XML_val), OString::number(nId));
356 
357  // unfortunately Word 2013 refuses to load DOCX with more than 25 listEntry
358  SAL_WARN_IF(25 < rListItems.getLength(), "sw.ww8", "DocxExport::DoComboBox data loss with more than 25 entries");
359  auto const nSize(std::min(sal_Int32(25), rListItems.getLength()));
360  for (auto i = 0; i < nSize; ++i)
361  {
362  m_pDocumentFS->singleElementNS(XML_w, XML_listEntry, FSNS(XML_w, XML_val), rListItems[i]);
363  }
364 
365  m_pDocumentFS->endElementNS( XML_w, XML_ddList );
366 
367  m_pDocumentFS->endElementNS( XML_w, XML_ffData );
368 }
369 
371 {
372  assert(pField);
373  const OUString sStr = FieldString(ww::eFILLIN) + "\"" + pField->GetPar2() + "\"";
374  OutputField(pField, ww::eFILLIN, sStr);
375 }
376 
377 OString DocxExport::OutputChart( uno::Reference< frame::XModel > const & xModel, sal_Int32 nCount, ::sax_fastparser::FSHelperPtr const & m_pSerializer )
378 {
379  OUString aFileName = "charts/chart" + OUString::number(nCount) + ".xml";
380  OUString sId = m_rFilter.addRelation( m_pSerializer->getOutputStream(),
381  oox::getRelationship(Relationship::CHART),
382  aFileName );
383  aFileName = "word/charts/chart" + OUString::number(nCount) + ".xml";
385  m_rFilter.openFragmentStreamWithSerializer( aFileName,
386  "application/vnd.openxmlformats-officedocument.drawingml.chart+xml" );
387 
388  oox::drawingml::ChartExport aChartExport(XML_w, pChartFS, xModel, &m_rFilter, oox::drawingml::DOCUMENT_DOCX);
389  css::uno::Reference<css::util::XModifiable> xModifiable(xModel, css::uno::UNO_QUERY);
390  const bool bOldModified = xModifiable && xModifiable->isModified();
391  aChartExport.ExportContent();
392  if (!bOldModified && xModifiable && xModifiable->isModified())
393  // tdf#134973: the model could get modified: e.g., calling XChartDocument::getSubTitle(),
394  // which creates the object if absent, and sets the modified state.
395  xModifiable->setModified(bOldModified);
396  return OUStringToOString( sId, RTL_TEXTENCODING_UTF8 );
397 }
398 
399 OString DocxExport::WriteOLEObject(SwOLEObj& rObject, OUString & io_rProgID)
400 {
401  uno::Reference <embed::XEmbeddedObject> xObj( rObject.GetOleRef() );
402  uno::Reference<uno::XComponentContext> const xContext(
403  GetFilter().getComponentContext());
404 
405  OUString sMediaType;
406  OUString sRelationType;
407  OUString sSuffix;
408  const char * pProgID(nullptr);
409 
410  uno::Reference<io::XInputStream> const xInStream =
411  oox::GetOLEObjectStream(xContext, xObj, io_rProgID,
412  sMediaType, sRelationType, sSuffix, pProgID);
413 
414  if (!xInStream.is())
415  {
416  return OString();
417  }
418 
419  assert(!sMediaType.isEmpty());
420  assert(!sRelationType.isEmpty());
421  assert(!sSuffix.isEmpty());
422  OUString sFileName = "embeddings/oleObject" + OUString::number( ++m_nOLEObjects ) + "." + sSuffix;
423  uno::Reference<io::XOutputStream> const xOutStream =
424  GetFilter().openFragmentStream("word/" + sFileName, sMediaType);
425  assert(xOutStream.is()); // no reason why that could fail
426 
427  try
428  {
429  comphelper::OStorageHelper::CopyInputToOutput(xInStream, xOutStream);
430  }
431  catch (uno::Exception const&)
432  {
433  TOOLS_WARN_EXCEPTION("sw.ww8", "DocxExport::WriteOLEObject");
434  return OString();
435  }
436 
437  OUString const sId = m_rFilter.addRelation( GetFS()->getOutputStream(),
438  sRelationType, sFileName );
439  if (pProgID)
440  {
441  io_rProgID = OUString::createFromAscii(pProgID);
442  }
443 
444  return OUStringToOString( sId, RTL_TEXTENCODING_UTF8 );
445 }
446 
447 std::pair<OString, OString> DocxExport::WriteActiveXObject(const uno::Reference<drawing::XShape>& rxShape,
448  const uno::Reference<awt::XControlModel>& rxControlModel)
449 {
450  ++m_nActiveXControls;
451 
452  // Write out ActiveX binary
453  const OUString sBinaryFileName = "word/activeX/activeX" + OUString::number(m_nActiveXControls) + ".bin";
454 
455  OString sGUID;
456  OString sName;
457  uno::Reference<io::XStream> xOutStorage(m_rFilter.openFragmentStream(sBinaryFileName, "application/vnd.ms-office.activeX"), uno::UNO_QUERY);
458  if(xOutStorage.is())
459  {
460  oox::ole::OleStorage aOleStorage(m_rFilter.getComponentContext(), xOutStorage, false);
461  uno::Reference<io::XOutputStream> xOutputStream(aOleStorage.openOutputStream("contents"), uno::UNO_SET_THROW);
462  uno::Reference< css::frame::XModel > xModel( m_rDoc.GetDocShell() ? m_rDoc.GetDocShell()->GetModel() : nullptr );
464  if ( !exportHelper.isValid() )
465  return std::make_pair<OString, OString>(OString(), OString());
466  sGUID = OUStringToOString(exportHelper.getGUID(), RTL_TEXTENCODING_UTF8);
467  sName = OUStringToOString(exportHelper.getName(), RTL_TEXTENCODING_UTF8);
468  exportHelper.exportControl(xOutputStream, rxShape->getSize(), true);
469  aOleStorage.commit();
470  }
471 
472  // Write out ActiveX fragment
473  const OUString sXMLFileName = "word/activeX/activeX" + OUString::number( m_nActiveXControls ) + ".xml";
474  ::sax_fastparser::FSHelperPtr pActiveXFS = m_rFilter.openFragmentStreamWithSerializer(sXMLFileName, "application/vnd.ms-office.activeX+xml" );
475 
476  const OUString sBinaryId = m_rFilter.addRelation( pActiveXFS->getOutputStream(),
477  oox::getRelationship(Relationship::ACTIVEXCONTROLBINARY),
478  sBinaryFileName.subView(sBinaryFileName.lastIndexOf("/") + 1) );
479 
480  pActiveXFS->singleElementNS(XML_ax, XML_ocx,
481  FSNS(XML_xmlns, XML_ax), m_rFilter.getNamespaceURL(OOX_NS(ax)),
482  FSNS(XML_xmlns, XML_r), m_rFilter.getNamespaceURL(OOX_NS(officeRel)),
483  FSNS(XML_ax, XML_classid), "{" + sGUID + "}",
484  FSNS(XML_ax, XML_persistence), "persistStorage",
485  FSNS(XML_r, XML_id), sBinaryId);
486 
487  OString sXMLId = OUStringToOString(m_rFilter.addRelation(m_pDocumentFS->getOutputStream(),
488  oox::getRelationship(Relationship::CONTROL),
489  sXMLFileName.subView(sBinaryFileName.indexOf("/") + 1)),
490  RTL_TEXTENCODING_UTF8);
491 
492  return std::pair<OString, OString>(sXMLId, sName);
493 }
494 
495 void DocxExport::OutputDML(uno::Reference<drawing::XShape> const & xShape)
496 {
497  uno::Reference<lang::XServiceInfo> xServiceInfo(xShape, uno::UNO_QUERY_THROW);
498  sal_Int32 nNamespace = XML_wps;
499  if (xServiceInfo->supportsService("com.sun.star.drawing.GroupShape"))
500  nNamespace = XML_wpg;
501  else if (xServiceInfo->supportsService("com.sun.star.drawing.GraphicObjectShape"))
502  nNamespace = XML_pic;
503  oox::drawingml::ShapeExport aExport(nNamespace, m_pAttrOutput->GetSerializer(), nullptr, &m_rFilter, oox::drawingml::DOCUMENT_DOCX, m_pAttrOutput.get());
504  aExport.WriteShape(xShape);
505 }
506 
508 {
509  // Set the 'Reviewing' flags in the settings structure
510  m_aSettings.revisionView = m_bOrigShowChanges;
511  m_aSettings.trackRevisions = bool( RedlineFlags::On & m_nOrigRedlineFlags );
512 
513  InitStyles();
514 
515  // init sections
516  m_pSections.reset(new MSWordSections( *this ));
517 
518  // Make sure images are counted from one, even when exporting multiple documents.
520 
521  WriteMainText();
522 
523  WriteFootnotesEndnotes();
524 
525  WritePostitFields();
526 
527  WriteNumbering();
528 
529  WriteFonts();
530 
531  WriteSettings();
532 
533  WriteTheme();
534 
535  WriteGlossary();
536 
537  WriteCustomXml();
538 
539  WriteEmbeddings();
540 
541  WriteVBA();
542 
543  m_aLinkedTextboxesHelper.clear(); //final cleanup
544  m_pStyles.reset();
545  m_pSections.reset();
546 
547  return ERRCODE_NONE;
548 }
549 
550 void DocxExport::AppendSection( const SwPageDesc *pPageDesc, const SwSectionFormat* pFormat, sal_uLong nLnNum )
551 {
552  AttrOutput().SectionBreak( msword::PageBreak, false, m_pSections->CurrentSectionInfo() );
553  m_pSections->AppendSection( pPageDesc, pFormat, nLnNum, m_pAttrOutput->IsFirstParagraph() );
554 }
555 
556 void DocxExport::OutputEndNode( const SwEndNode& rEndNode )
557 {
559 
560  if ( TXT_MAINTEXT == m_nTextTyp && rEndNode.StartOfSectionNode()->IsSectionNode() )
561  {
562  // this originally comes from WW8Export::WriteText(), and looks like it
563  // could have some code common with SectionNode()...
564 
565  const SwSection& rSect = rEndNode.StartOfSectionNode()->GetSectionNode()->GetSection();
566  if ( m_bStartTOX && SectionType::ToxContent == rSect.GetType() )
567  m_bStartTOX = false;
568 
569  SwNodeIndex aIdx( rEndNode, 1 );
570  const SwNode& rNd = aIdx.GetNode();
571  if ( rNd.IsEndNode() && rNd.StartOfSectionNode()->IsSectionNode() )
572  return;
573 
574  bool isInTable = IsInTable();
575  if ( !rNd.IsSectionNode() && isInTable ) // No sections in table
576  {
577  const SwSectionFormat* pParentFormat = rSect.GetFormat()->GetParent();
578  if( !pParentFormat )
579  pParentFormat = reinterpret_cast<SwSectionFormat*>(sal_IntPtr(-1));
580 
581  sal_uLong nRstLnNum;
582  if( rNd.IsContentNode() )
583  nRstLnNum = rNd.GetContentNode()->GetSwAttrSet().GetLineNumber().GetStartValue();
584  else
585  nRstLnNum = 0;
586 
587  AppendSection( m_pCurrentPageDesc, pParentFormat, nRstLnNum );
588  }
589  else
590  {
591  AttrOutput().SectionBreaks( rEndNode );
592  }
593  }
594  else if (TXT_MAINTEXT == m_nTextTyp && rEndNode.StartOfSectionNode()->IsTableNode())
595  // End node of a table: see if a section break should be written after the table.
596  AttrOutput().SectionBreaks(rEndNode);
597 }
598 
600 {
601  SAL_INFO("sw.ww8", "TODO DocxExport::OutputGrfNode( const SwGrfNode& )" );
602 }
603 
605 {
606  SAL_INFO("sw.ww8", "TODO DocxExport::OutputOLENode( const SwOLENode& )" );
607 }
608 
609 void DocxExport::OutputLinkedOLE( const OUString& )
610 {
611  // Nothing to implement here: WW8 only
612 }
613 
615 {
616  // Completely unused for Docx export... only here for code sharing
617  // purpose with binary export
618  return 0;
619 }
620 
622  const SwNode& rNd, const SwFormatPageDesc* pNewPgDescFormat,
623  const SwPageDesc* pNewPgDesc, bool bExtraPageBreak )
624 {
625  // tell the attribute output that we are ready to write the section
626  // break [has to be output inside paragraph properties]
627  AttrOutput().SectionBreak( msword::PageBreak, false, m_pSections->CurrentSectionInfo(), bExtraPageBreak );
628 
629  const SwSectionFormat* pFormat = GetSectionFormat( rNd );
630  const sal_uLong nLnNm = GetSectionLineNo( pSet, rNd );
631 
632  OSL_ENSURE( pNewPgDescFormat || pNewPgDesc, "Neither page desc format nor page desc provided." );
633 
634  if ( pNewPgDescFormat )
635  {
636  m_pSections->AppendSection( *pNewPgDescFormat, rNd, pFormat, nLnNm );
637  }
638  else if ( pNewPgDesc )
639  {
640  m_pSections->AppendSection( pNewPgDesc, rNd, pFormat, nLnNm );
641  }
642 
643 }
644 
646 {
647  m_pStyles.reset(new MSWordStyles( *this, /*bListStyles =*/ true ));
648 
649  // setup word/styles.xml and the relations + content type
650  m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
651  oox::getRelationship(Relationship::STYLES),
652  u"styles.xml" );
653 
655  m_rFilter.openFragmentStreamWithSerializer( "word/styles.xml",
656  "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml" );
657 
658  // switch the serializer to redirect the output to word/styles.xml
659  m_pAttrOutput->SetSerializer( pStylesFS );
660 
661  // do the work
662  m_pStyles->OutputStylesTable();
663 
664  // switch the serializer back
665  m_pAttrOutput->SetSerializer( m_pDocumentFS );
666 }
667 
669 {
670  if ( m_pAttrOutput->HasFootnotes() )
671  {
672  // setup word/styles.xml and the relations + content type
673  m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
674  oox::getRelationship(Relationship::FOOTNOTES),
675  u"footnotes.xml" );
676 
677  ::sax_fastparser::FSHelperPtr pFootnotesFS =
678  m_rFilter.openFragmentStreamWithSerializer( "word/footnotes.xml",
679  "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml" );
680 
681  // switch the serializer to redirect the output to word/footnotes.xml
682  m_pAttrOutput->SetSerializer( pFootnotesFS );
683  // tdf#99227
684  m_pSdrExport->setSerializer( pFootnotesFS );
685  // tdf#107969
686  m_pVMLExport->SetFS(pFootnotesFS);
687 
688  // do the work
689  m_pAttrOutput->FootnotesEndnotes( true );
690 
691  // switch the serializer back
692  m_pVMLExport->SetFS(m_pDocumentFS);
693  m_pSdrExport->setSerializer( m_pDocumentFS );
694  m_pAttrOutput->SetSerializer( m_pDocumentFS );
695  }
696 
697  if ( !m_pAttrOutput->HasEndnotes() )
698  return;
699 
700  // setup word/styles.xml and the relations + content type
701  m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
702  oox::getRelationship(Relationship::ENDNOTES),
703  u"endnotes.xml" );
704 
705  ::sax_fastparser::FSHelperPtr pEndnotesFS =
706  m_rFilter.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 
726 {
727  if ( !m_pAttrOutput->HasPostitFields() )
728  return;
729 
730  m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
731  oox::getRelationship(Relationship::COMMENTS),
732  u"comments.xml" );
733 
735  m_rFilter.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  const auto eHasResolved = m_pAttrOutput->WritePostitFields();
741  m_pAttrOutput->SetSerializer( m_pDocumentFS );
742  pPostitFS->endElementNS( XML_w, XML_comments );
743 
744  if (eHasResolved != DocxAttributeOutput::hasResolved::yes)
745  return;
746 
747  m_rFilter.addRelation(m_pDocumentFS->getOutputStream(),
748  oox::getRelationship(Relationship::COMMENTSEXTENDED),
749  u"commentsExtended.xml");
750 
751  pPostitFS = m_rFilter.openFragmentStreamWithSerializer(
752  "word/commentsExtended.xml",
753  "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml");
754 
755  pPostitFS->startElementNS(XML_w15, XML_commentsEx, // Add namespaces manually now
756  FSNS(XML_xmlns, XML_mc), m_rFilter.getNamespaceURL(OOX_NS(mce)),
757  FSNS(XML_xmlns, XML_w15), m_rFilter.getNamespaceURL(OOX_NS(w15)),
758  FSNS(XML_mc, XML_Ignorable), "w15");
759  m_pAttrOutput->SetSerializer(pPostitFS);
760  m_pAttrOutput->WritePostItFieldsResolved();
761  m_pAttrOutput->SetSerializer(m_pDocumentFS);
762  pPostitFS->endElementNS(XML_w15, XML_commentsEx);
763 }
764 
766 {
767  if ( !m_pUsedNumTable )
768  return; // no numbering is used
769 
770  m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
771  oox::getRelationship(Relationship::NUMBERING),
772  u"numbering.xml" );
773 
774  ::sax_fastparser::FSHelperPtr pNumberingFS = m_rFilter.openFragmentStreamWithSerializer( "word/numbering.xml",
775  "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml" );
776 
777  // switch the serializer to redirect the output to word/numbering.xml
778  m_pAttrOutput->SetSerializer( pNumberingFS );
779  m_pDrawingML->SetFS( pNumberingFS );
780 
781  pNumberingFS->startElementNS( XML_w, XML_numbering,
782  FSNS( XML_xmlns, XML_w ), m_rFilter.getNamespaceURL(OOX_NS(doc)),
783  FSNS( XML_xmlns, XML_o ), m_rFilter.getNamespaceURL(OOX_NS(vmlOffice)),
784  FSNS( XML_xmlns, XML_r ), m_rFilter.getNamespaceURL(OOX_NS(officeRel)),
785  FSNS( XML_xmlns, XML_v ), m_rFilter.getNamespaceURL(OOX_NS(vml)),
786  FSNS( XML_xmlns, XML_mc ), m_rFilter.getNamespaceURL(OOX_NS(mce)),
787  FSNS( XML_xmlns, XML_w14 ), m_rFilter.getNamespaceURL(OOX_NS(w14)),
788  FSNS( XML_mc, XML_Ignorable ), "w14" );
789 
790  BulletDefinitions();
791 
792  AbstractNumberingDefinitions();
793 
794  NumberingDefinitions();
795 
796  pNumberingFS->endElementNS( XML_w, XML_numbering );
797 
798  // switch the serializer back
799  m_pDrawingML->SetFS( m_pDocumentFS );
800  m_pAttrOutput->SetSerializer( m_pDocumentFS );
801 }
802 
803 void DocxExport::WriteHeaderFooter( const SwFormat* pFormat, bool bHeader, const char* pType )
804 {
805  // setup the xml stream
806  OUString aRelId;
808  if ( bHeader )
809  {
810  OUString aName( "header" + OUString::number( ++m_nHeaders ) + ".xml" );
811 
812  aRelId = m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
813  oox::getRelationship(Relationship::HEADER),
814  aName );
815 
816  pFS = m_rFilter.openFragmentStreamWithSerializer( "word/" + aName,
817  "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml" );
818 
819  pFS->startElementNS( XML_w, XML_hdr, MainXmlNamespaces());
820  }
821  else
822  {
823  OUString aName( "footer" + OUString::number( ++m_nFooters ) + ".xml" );
824 
825  aRelId = m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
826  oox::getRelationship(Relationship::FOOTER),
827  aName );
828 
829  pFS = m_rFilter.openFragmentStreamWithSerializer( "word/" + aName,
830  "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml" );
831 
832  pFS->startElementNS( XML_w, XML_ftr, MainXmlNamespaces());
833  }
834 
835  // switch the serializer to redirect the output to word/styles.xml
836  m_pAttrOutput->SetSerializer( pFS );
837  m_pVMLExport->SetFS( pFS );
838  m_pSdrExport->setSerializer(pFS);
839  SetFS( pFS );
840  {
841  DocxTableExportContext aTableExportContext(*m_pAttrOutput);
842  // do the work
843  if (pFormat == nullptr)
844  AttrOutput().EmptyParagraph();
845  else
846  WriteHeaderFooterText(*pFormat, bHeader);
847  m_pAttrOutput->EndParaSdtBlock();
848  }
849 
850  // switch the serializer back
851  m_pAttrOutput->SetSerializer( m_pDocumentFS );
852  m_pVMLExport->SetFS( m_pDocumentFS );
853  m_pSdrExport->setSerializer(m_pDocumentFS);
854  SetFS( m_pDocumentFS );
855 
856  // close the tag
857  sal_Int32 nReference;
858  if ( bHeader )
859  {
860  pFS->endElementNS( XML_w, XML_hdr );
861  nReference = XML_headerReference;
862  }
863  else
864  {
865  pFS->endElementNS( XML_w, XML_ftr );
866  nReference = XML_footerReference;
867  }
868 
869  // and write the reference
870  m_pDocumentFS->singleElementNS( XML_w, nReference,
871  FSNS( XML_w, XML_type ), pType,
872  FSNS( XML_r, XML_id ), aRelId );
873 }
874 
876 {
877  m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
878  oox::getRelationship(Relationship::FONTTABLE),
879  u"fontTable.xml" );
880 
881  ::sax_fastparser::FSHelperPtr pFS = m_rFilter.openFragmentStreamWithSerializer(
882  "word/fontTable.xml",
883  "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml" );
884 
885  pFS->startElementNS( XML_w, XML_fonts,
886  FSNS( XML_xmlns, XML_w ), m_rFilter.getNamespaceURL(OOX_NS(doc)),
887  FSNS( XML_xmlns, XML_r ), m_rFilter.getNamespaceURL(OOX_NS(officeRel)) );
888 
889  // switch the serializer to redirect the output to word/styles.xml
890  m_pAttrOutput->SetSerializer( pFS );
891 
892  // do the work
893  m_aFontHelper.WriteFontTable( *m_pAttrOutput );
894 
895  // switch the serializer back
896  m_pAttrOutput->SetSerializer( m_pDocumentFS );
897 
898  pFS->endElementNS( XML_w, XML_fonts );
899 }
900 
902 {
903  // Write the core properties
904  SwDocShell* pDocShell( m_rDoc.GetDocShell( ) );
905  uno::Reference<document::XDocumentProperties> xDocProps;
906  bool bSecurityOptOpenReadOnly = false;
907  if ( pDocShell )
908  {
909  uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
910  pDocShell->GetModel( ), uno::UNO_QUERY );
911  xDocProps = xDPS->getDocumentProperties();
912  bSecurityOptOpenReadOnly = pDocShell->IsSecurityOptOpenReadOnly();
913  }
914 
915  m_rFilter.exportDocumentProperties( xDocProps, bSecurityOptOpenReadOnly );
916 }
917 
919 {
920  SwDocShell* pDocShell = m_rDoc.GetDocShell();
921  if (!pDocShell)
922  {
923  return;
924  }
925 
926  uno::Reference<text::XTextFieldsSupplier> xModel(pDocShell->GetModel(), uno::UNO_QUERY);
927  uno::Reference<container::XNameAccess> xTextFieldMasters = xModel->getTextFieldMasters();
928  uno::Sequence<rtl::OUString> aMasterNames = xTextFieldMasters->getElementNames();
929  if (!aMasterNames.hasElements())
930  {
931  return;
932  }
933 
934  // Only write docVars if there will be at least a single docVar.
935  bool bStarted = false;
936  constexpr OUStringLiteral aPrefix(u"com.sun.star.text.fieldmaster.User.");
937  for (const auto& rMasterName : std::as_const(aMasterNames))
938  {
939  if (!rMasterName.startsWith(aPrefix))
940  {
941  // Not a user field.
942  continue;
943  }
944 
945  uno::Reference<beans::XPropertySet> xField;
946  xTextFieldMasters->getByName(rMasterName) >>= xField;
947  if (!xField.is())
948  {
949  continue;
950  }
951 
952  OUString aKey = rMasterName.copy(aPrefix.getLength());
953  OUString aValue;
954  xField->getPropertyValue("Content") >>= aValue;
955  if (!bStarted)
956  {
957  bStarted = true;
958  pFS->startElementNS(XML_w, XML_docVars);
959  }
960  pFS->singleElementNS(XML_w, XML_docVar, FSNS(XML_w, XML_name), aKey,
961  FSNS(XML_w, XML_val), aValue);
962  }
963 
964  if (bStarted)
965  {
966  pFS->endElementNS(XML_w, XML_docVars);
967  }
968 }
969 
970 static auto
971 WriteCompat(SwDoc const& rDoc, ::sax_fastparser::FSHelperPtr const& rpFS,
972  sal_Int32 & rTargetCompatibilityMode) -> void
973 {
974  if (!rDoc.getIDocumentSettingAccess().get(DocumentSettingId::ADD_EXT_LEADING))
975  {
976  rpFS->singleElementNS(XML_w, XML_noLeading);
977  if (rTargetCompatibilityMode > 14)
978  { // Word ignores noLeading in compatibilityMode 15
979  rTargetCompatibilityMode = 14;
980  }
981  }
982  // Do not justify lines with manual break
983  if (rDoc.getIDocumentSettingAccess().get(DocumentSettingId::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK))
984  {
985  rpFS->singleElementNS(XML_w, XML_doNotExpandShiftReturn);
986  }
987 }
988 
990 {
992  if( !pViewShell && !m_aSettings.hasData() && !m_pAttrOutput->HasFootnotes() && !m_pAttrOutput->HasEndnotes())
993  return;
994 
995  m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
996  oox::getRelationship(Relationship::SETTINGS),
997  u"settings.xml" );
998 
999  ::sax_fastparser::FSHelperPtr pFS = m_rFilter.openFragmentStreamWithSerializer(
1000  "word/settings.xml",
1001  "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml" );
1002 
1003  pFS->startElementNS( XML_w, XML_settings,
1004  FSNS( XML_xmlns, XML_w ), m_rFilter.getNamespaceURL(OOX_NS(doc)) );
1005 
1006  // View
1007  if (pViewShell && pViewShell->GetViewOptions()->getBrowseMode())
1008  {
1009  pFS->singleElementNS(XML_w, XML_view, FSNS(XML_w, XML_val), "web");
1010  }
1011 
1012  // Zoom
1013  if (pViewShell)
1014  {
1017 
1018  switch (pViewShell->GetViewOptions()->GetZoomType())
1019  {
1020  case SvxZoomType::WHOLEPAGE:
1021  pAttributeList->add(FSNS(XML_w, XML_val), "fullPage");
1022  break;
1023  case SvxZoomType::PAGEWIDTH:
1024  pAttributeList->add(FSNS(XML_w, XML_val), "bestFit");
1025  break;
1026  case SvxZoomType::OPTIMAL:
1027  pAttributeList->add(FSNS(XML_w, XML_val), "textFit");
1028  break;
1029  default:
1030  break;
1031  }
1032 
1033  OString aZoom(OString::number(pViewShell->GetViewOptions()->GetZoom()));
1034  pAttributeList->add(FSNS(XML_w, XML_percent), aZoom);
1035  pFS->singleElementNS(XML_w, XML_zoom, pAttributeList);
1036  }
1037 
1038  // Display Background Shape
1039  if (std::unique_ptr<SvxBrushItem> oBrush = getBackground(); oBrush)
1040  {
1041  // Turn on the 'displayBackgroundShape'
1042  pFS->singleElementNS(XML_w, XML_displayBackgroundShape);
1043  }
1044 
1045  // Track Changes
1046  if ( !m_aSettings.revisionView )
1047  pFS->singleElementNS( XML_w, XML_revisionView,
1048  FSNS( XML_w, XML_insDel ), "0",
1049  FSNS( XML_w, XML_formatting ), "0" );
1050 
1051  if ( m_aSettings.trackRevisions )
1052  pFS->singleElementNS(XML_w, XML_trackRevisions);
1053 
1054  // Mirror Margins
1055  if(isMirroredMargin())
1056  pFS->singleElementNS(XML_w, XML_mirrorMargins);
1057 
1059  {
1060  pFS->singleElementNS(XML_w, XML_gutterAtTop);
1061  }
1062 
1063  // Embed Fonts
1065  pFS->singleElementNS(XML_w, XML_embedTrueTypeFonts);
1066 
1067  // Embed System Fonts
1069  pFS->singleElementNS(XML_w, XML_embedSystemFonts);
1070 
1071  // Default Tab Stop
1072  if( m_aSettings.defaultTabStop != 0 )
1073  pFS->singleElementNS( XML_w, XML_defaultTabStop, FSNS( XML_w, XML_val ),
1074  OString::number(m_aSettings.defaultTabStop) );
1075 
1076  // export current mail merge database and table names
1078  if ( !aData.sDataSource.isEmpty() && aData.nCommandType == css::sdb::CommandType::TABLE && !aData.sCommand.isEmpty() )
1079  {
1080  OUString sDataSource =
1081  "SELECT * FROM " +
1082  aData.sDataSource + // current database
1083  ".dbo." + // default database owner
1084  aData.sCommand + // sheet name
1085  "$"; // sheet identifier
1086  pFS->startElementNS( XML_w, XML_mailMerge );
1087  pFS->singleElementNS(XML_w, XML_mainDocumentType,
1088  FSNS( XML_w, XML_val ), "formLetters" );
1089  pFS->singleElementNS(XML_w, XML_dataType,
1090  FSNS( XML_w, XML_val ), "textFile" );
1091  pFS->singleElementNS( XML_w, XML_query,
1092  FSNS( XML_w, XML_val ), OUStringToOString( sDataSource, RTL_TEXTENCODING_UTF8 ).getStr() );
1093  pFS->endElementNS( XML_w, XML_mailMerge );
1094  }
1095 
1096  // Automatic hyphenation: it's a global setting in Word, it's a paragraph setting in Writer.
1097  // Set it's value to "auto" and disable on paragraph level, if no hyphenation is used there.
1098  pFS->singleElementNS(XML_w, XML_autoHyphenation, FSNS(XML_w, XML_val), "true");
1099 
1100  // Hyphenation details set depending on default style
1102  const SfxPoolItem* pItem;
1103  if (pColl && SfxItemState::SET == pColl->GetItemState(RES_PARATR_HYPHENZONE, false, &pItem))
1104  {
1105  if (static_cast<const SvxHyphenZoneItem*>(pItem)->IsNoCapsHyphenation())
1106  pFS->singleElementNS(XML_w, XML_doNotHyphenateCaps);
1107  }
1108 
1109  // Even and Odd Headers
1110  if( m_aSettings.evenAndOddHeaders )
1111  pFS->singleElementNS(XML_w, XML_evenAndOddHeaders);
1112 
1113  // Has Footnotes
1114  if( m_pAttrOutput->HasFootnotes())
1115  DocxAttributeOutput::WriteFootnoteEndnotePr( pFS, XML_footnotePr, m_rDoc.GetFootnoteInfo(), XML_footnote );
1116 
1117  // Has Endnotes
1118  if( m_pAttrOutput->HasEndnotes())
1119  DocxAttributeOutput::WriteFootnoteEndnotePr( pFS, XML_endnotePr, m_rDoc.GetEndNoteInfo(), XML_endnote );
1120 
1121  // Has themeFontLang information
1122  uno::Reference< beans::XPropertySet > xPropSet( m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1123 
1124  bool bUseGrabBagProtection = false;
1125  bool bWriterWantsToProtect = false;
1126  bool bWriterWantsToProtectForm = false;
1127  bool bWriterWantsToProtectRedline = false;
1128  bool bHasDummyRedlineProtectionKey = false;
1129  bool bReadOnlyStatusUnchanged = true;
1130  uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1132  m_pSections->DocumentIsProtected() )
1133  {
1134  bWriterWantsToProtect = bWriterWantsToProtectForm = true;
1135  }
1136  if ( xPropSetInfo->hasPropertyByName( "RedlineProtectionKey" ) )
1137  {
1138  uno::Sequence<sal_Int8> aKey;
1139  xPropSet->getPropertyValue( "RedlineProtectionKey" ) >>= aKey;
1140  bool bHasRedlineProtectionKey = aKey.hasElements();
1141  bHasDummyRedlineProtectionKey = aKey.getLength() == 1 && aKey[0] == 1;
1142  if ( bHasRedlineProtectionKey && !bHasDummyRedlineProtectionKey )
1143  bWriterWantsToProtect = bWriterWantsToProtectRedline = true;
1144  }
1145 
1146  /* Compatibility Mode (tdf#131304)
1147  * 11: .doc level [Word 97-2003]
1148  * 12: .docx default [Word 2007] [LO < 7.0]
1149  * 14: [Word 2010]
1150  * 15: [Word 2013/2016/2019] [LO >= 7.0]
1151  *
1152  * The PRIMARY purpose of compatibility mode does not seem to be related to layout etc.
1153  * Its focus is on sharing files between multiple users, tracking the lowest supported mode in the group.
1154  * It is to BENEFIT older programs by not using certain new features that they don't understand.
1155  *
1156  * The next time the compat mode needs to be changed, I foresee the following steps:
1157  * 1.) Accept the new mode: Start round-tripping the new value, indicating we understand that format.
1158  * 2.) Many years later, change the TargetCompatilityMode for new documents, when we no longer care
1159  * about working with perfect compatibility with older versions of MS Word.
1160  */
1161  sal_Int32 nTargetCompatibilityMode = 15; //older versions might not open our files well
1162  bool bHasCompatibilityMode = false;
1163  const OUString aGrabBagName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
1164  if ( xPropSetInfo->hasPropertyByName( aGrabBagName ) )
1165  {
1166  uno::Sequence< beans::PropertyValue > propList;
1167  xPropSet->getPropertyValue( aGrabBagName ) >>= propList;
1168 
1169  for( const auto& rProp : std::as_const(propList) )
1170  {
1171  if ( rProp.Name == "ThemeFontLangProps" )
1172  {
1173  uno::Sequence< beans::PropertyValue > themeFontLangProps;
1174  rProp.Value >>= themeFontLangProps;
1175  OUString aValues[3];
1176  for( const auto& rThemeFontLangProp : std::as_const(themeFontLangProps) )
1177  {
1178  if( rThemeFontLangProp.Name == "val" )
1179  rThemeFontLangProp.Value >>= aValues[0];
1180  else if( rThemeFontLangProp.Name == "eastAsia" )
1181  rThemeFontLangProp.Value >>= aValues[1];
1182  else if( rThemeFontLangProp.Name == "bidi" )
1183  rThemeFontLangProp.Value >>= aValues[2];
1184  }
1185  pFS->singleElementNS( XML_w, XML_themeFontLang,
1186  FSNS( XML_w, XML_val ), aValues[0],
1187  FSNS( XML_w, XML_eastAsia ), aValues[1],
1188  FSNS( XML_w, XML_bidi ), aValues[2] );
1189  }
1190  else if ( rProp.Name == "CompatSettings" )
1191  {
1192  pFS->startElementNS(XML_w, XML_compat);
1193 
1194  WriteCompat(m_rDoc, pFS, nTargetCompatibilityMode);
1195 
1196  uno::Sequence< beans::PropertyValue > aCompatSettingsSequence;
1197  rProp.Value >>= aCompatSettingsSequence;
1198 
1199  for(const auto& rCompatSetting : std::as_const(aCompatSettingsSequence))
1200  {
1201  uno::Sequence< beans::PropertyValue > aCompatSetting;
1202  rCompatSetting.Value >>= aCompatSetting;
1203  OUString aName;
1204  OUString aUri;
1205  OUString aValue;
1206 
1207  for(const auto& rPropVal : std::as_const(aCompatSetting))
1208  {
1209  if( rPropVal.Name == "name" )
1210  rPropVal.Value >>= aName;
1211  else if( rPropVal.Name == "uri" )
1212  rPropVal.Value >>= aUri;
1213  else if( rPropVal.Name == "val" )
1214  rPropVal.Value >>= aValue;
1215  }
1216  if ( aName == "compatibilityMode" )
1217  {
1218  bHasCompatibilityMode = true;
1219  // Among the group of programs sharing this document, the lowest mode is retained.
1220  // Reduce this number if we are not comfortable with the new/unknown mode yet.
1221  // Step 1 in accepting a new mode would be to comment out the following clause
1222  // and roundtrip the new value instead of overwriting with the older number.
1223  // There are no newer modes at the time this code was written.
1224  if ( aValue.toInt32() > nTargetCompatibilityMode )
1225  aValue = OUString::number(nTargetCompatibilityMode);
1226  }
1227 
1228  pFS->singleElementNS( XML_w, XML_compatSetting,
1229  FSNS( XML_w, XML_name ), aName,
1230  FSNS( XML_w, XML_uri ), aUri,
1231  FSNS( XML_w, XML_val ), aValue);
1232  }
1233 
1234  if ( !bHasCompatibilityMode )
1235  {
1236  pFS->singleElementNS( XML_w, XML_compatSetting,
1237  FSNS( XML_w, XML_name ), "compatibilityMode",
1238  FSNS( XML_w, XML_uri ), "http://schemas.microsoft.com/office/word",
1239  FSNS( XML_w, XML_val ), OString::number(nTargetCompatibilityMode));
1240  bHasCompatibilityMode = true;
1241  }
1242 
1243  pFS->endElementNS( XML_w, XML_compat );
1244  }
1245  else if (rProp.Name == "DocumentProtection")
1246  {
1247  uno::Sequence< beans::PropertyValue > rAttributeList;
1248  rProp.Value >>= rAttributeList;
1249 
1250  if (rAttributeList.hasElements())
1251  {
1253  bool bIsProtectionTrackChanges = false;
1254  // if grabbag protection is not enforced, allow Writer protection to override
1255  bool bEnforced = false;
1256  for (const auto& rAttribute : std::as_const(rAttributeList))
1257  {
1258  static DocxStringTokenMap const aTokens[] =
1259  {
1260  { "edit", XML_edit },
1261  { "enforcement", XML_enforcement },
1262  { "formatting", XML_formatting },
1263  { "cryptProviderType", XML_cryptProviderType },
1264  { "cryptAlgorithmClass", XML_cryptAlgorithmClass },
1265  { "cryptAlgorithmType", XML_cryptAlgorithmType },
1266  { "cryptAlgorithmSid", XML_cryptAlgorithmSid },
1267  { "cryptSpinCount", XML_cryptSpinCount },
1268  { "hash", XML_hash },
1269  { "salt", XML_salt },
1270  { nullptr, 0 }
1271  };
1272 
1273  if (sal_Int32 nToken = DocxStringGetToken(aTokens, rAttribute.Name))
1274  {
1275  OUString sValue = rAttribute.Value.get<OUString>();
1276  xAttributeList->add(FSNS(XML_w, nToken), sValue.toUtf8());
1277  if ( nToken == XML_edit && sValue == "trackedChanges" )
1278  bIsProtectionTrackChanges = true;
1279  else if ( nToken == XML_edit && sValue == "readOnly" )
1280  {
1281  // Ignore the case where read-only was not enforced, but now is. That is handled by _MarkAsFinal
1282  bReadOnlyStatusUnchanged = m_rDoc.GetDocShell()->IsSecurityOptOpenReadOnly();
1283  }
1284  else if ( nToken == XML_enforcement )
1285  bEnforced = sValue.toBoolean();
1286  }
1287  }
1288 
1289  // we have document protection from input DOCX file
1290  if ( !bEnforced )
1291  {
1292  // Leave as an un-enforced suggestion if Writer doesn't want to set any enforcement
1293  bUseGrabBagProtection = !bWriterWantsToProtect;
1294  }
1295  else
1296  {
1297  // Check if the grabbag protection is still valid
1298  // In the case of change tracking protection, we didn't modify it
1299  // and in the case of read-only, we didn't modify it.
1300  bUseGrabBagProtection = (!bIsProtectionTrackChanges || bHasDummyRedlineProtectionKey)
1301  && bReadOnlyStatusUnchanged;
1302  }
1303 
1304  if ( bUseGrabBagProtection )
1305  {
1306  pFS->singleElementNS(XML_w, XML_documentProtection, xAttributeList);
1307  }
1308 
1309  }
1310  }
1311  else if (rProp.Name == "HyphenationZone")
1312  {
1313  sal_Int16 nHyphenationZone = *o3tl::doAccess<sal_Int16>(rProp.Value);
1314  if (nHyphenationZone > 0)
1315  pFS->singleElementNS(XML_w, XML_hyphenationZone, FSNS(XML_w, XML_val),
1316  OString::number(nHyphenationZone));
1317  }
1318  }
1319  }
1320  if ( !bHasCompatibilityMode )
1321  {
1322  pFS->startElementNS(XML_w, XML_compat);
1323 
1324  WriteCompat(m_rDoc, pFS, nTargetCompatibilityMode);
1325 
1326  pFS->singleElementNS( XML_w, XML_compatSetting,
1327  FSNS( XML_w, XML_name ), "compatibilityMode",
1328  FSNS( XML_w, XML_uri ), "http://schemas.microsoft.com/office/word",
1329  FSNS( XML_w, XML_val ), OString::number(nTargetCompatibilityMode));
1330  pFS->endElementNS( XML_w, XML_compat );
1331  }
1332 
1333  WriteDocVars(pFS);
1334 
1335  if ( !bUseGrabBagProtection )
1336  {
1337  // Protect form - highest priority
1338  // Section-specific write protection
1339  if ( bWriterWantsToProtectForm )
1340  {
1341  // we have form protection from Writer or from input ODT file
1342 
1343  pFS->singleElementNS(XML_w, XML_documentProtection,
1344  FSNS(XML_w, XML_edit), "forms",
1345  FSNS(XML_w, XML_enforcement), "true");
1346  }
1347  // Protect Change Tracking - next priority
1348  else if ( bWriterWantsToProtectRedline )
1349  {
1350  // we have change tracking protection from Writer or from input ODT file
1351 
1352  pFS->singleElementNS(XML_w, XML_documentProtection,
1353  FSNS(XML_w, XML_edit), "trackedChanges",
1354  FSNS(XML_w, XML_enforcement), "1");
1355  }
1356  }
1357 
1358  // finish settings.xml
1359  pFS->endElementNS( XML_w, XML_settings );
1360 }
1361 
1363 {
1364  uno::Reference< beans::XPropertySet > xPropSet( m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1365 
1366  uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1368  if ( !xPropSetInfo->hasPropertyByName( aName ) )
1369  return;
1370 
1371  uno::Reference<xml::dom::XDocument> themeDom;
1372  uno::Sequence< beans::PropertyValue > propList;
1373  xPropSet->getPropertyValue( aName ) >>= propList;
1374  auto pProp = std::find_if(propList.begin(), propList.end(),
1375  [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXTheme"; });
1376  if (pProp != propList.end())
1377  pProp->Value >>= themeDom;
1378 
1379  // no theme dom to write
1380  if ( !themeDom.is() )
1381  return;
1382 
1383  m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
1384  oox::getRelationship(Relationship::THEME),
1385  u"theme/theme1.xml" );
1386 
1387  uno::Reference< xml::sax::XSAXSerializable > serializer( themeDom, uno::UNO_QUERY );
1388  uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() );
1389  writer->setOutputStream( GetFilter().openFragmentStream( "word/theme/theme1.xml",
1390  "application/vnd.openxmlformats-officedocument.theme+xml" ) );
1391  serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1392  uno::Sequence< beans::StringPair >() );
1393 }
1394 
1396 {
1397  uno::Reference< beans::XPropertySet > xPropSet( m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1398 
1399  uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1401  if ( !xPropSetInfo->hasPropertyByName( aName ) )
1402  return;
1403 
1404  uno::Reference<xml::dom::XDocument> glossaryDocDom;
1405  uno::Sequence< uno::Sequence< uno::Any> > glossaryDomList;
1406  uno::Sequence< beans::PropertyValue > propList;
1407  xPropSet->getPropertyValue( aName ) >>= propList;
1408  sal_Int32 collectedProperties = 0;
1409  for ( const auto& rProp : std::as_const(propList) )
1410  {
1411  OUString propName = rProp.Name;
1412  if ( propName == "OOXGlossary" )
1413  {
1414  rProp.Value >>= glossaryDocDom;
1415  collectedProperties++;
1416  }
1417  if (propName == "OOXGlossaryDom")
1418  {
1419  rProp.Value >>= glossaryDomList;
1420  collectedProperties++;
1421  }
1422  if (collectedProperties == 2)
1423  break;
1424  }
1425 
1426  // no glossary dom to write
1427  if ( !glossaryDocDom.is() )
1428  return;
1429 
1430  m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
1431  oox::getRelationship(Relationship::GLOSSARYDOCUMENT),
1432  u"glossary/document.xml" );
1433 
1434  uno::Reference< io::XOutputStream > xOutputStream = GetFilter().openFragmentStream( "word/glossary/document.xml",
1435  "application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml" );
1436 
1437  uno::Reference< xml::sax::XSAXSerializable > serializer( glossaryDocDom, uno::UNO_QUERY );
1438  uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() );
1439  writer->setOutputStream( xOutputStream );
1440  serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1441  uno::Sequence< beans::StringPair >() );
1442 
1443  for ( const uno::Sequence< uno::Any>& glossaryElement : std::as_const(glossaryDomList))
1444  {
1445  OUString gTarget, gType, gId, contentType;
1446  uno::Reference<xml::dom::XDocument> xDom;
1447  glossaryElement[0] >>= xDom;
1448  glossaryElement[1] >>= gId;
1449  glossaryElement[2] >>= gType;
1450  glossaryElement[3] >>= gTarget;
1451  glossaryElement[4] >>= contentType;
1452  gId = gId.copy(3); //"rId" only save the numeric value
1453 
1454  PropertySet aProps(xOutputStream);
1455  aProps.setAnyProperty( PROP_RelId, uno::makeAny( gId.toInt32() ));
1456  m_rFilter.addRelation( xOutputStream, gType, gTarget);
1457  uno::Reference< xml::sax::XSAXSerializable > gserializer( xDom, uno::UNO_QUERY );
1458  writer->setOutputStream(GetFilter().openFragmentStream( "word/glossary/" + gTarget, contentType ) );
1459  gserializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1460  uno::Sequence< beans::StringPair >() );
1461  }
1462 }
1463 
1465 {
1466  uno::Reference< beans::XPropertySet > xPropSet( m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1467 
1468  uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1469  static constexpr OUStringLiteral aName = u"" UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
1470  if ( !xPropSetInfo->hasPropertyByName( aName ) )
1471  return;
1472 
1473  uno::Sequence<uno::Reference<xml::dom::XDocument> > customXmlDomlist;
1474  uno::Sequence<uno::Reference<xml::dom::XDocument> > customXmlDomPropslist;
1475  uno::Sequence< beans::PropertyValue > propList;
1476  xPropSet->getPropertyValue( aName ) >>= propList;
1477  auto pProp = std::find_if(propList.begin(), propList.end(),
1478  [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXCustomXml"; });
1479  if (pProp != propList.end())
1480  pProp->Value >>= customXmlDomlist;
1481 
1482  pProp = std::find_if(propList.begin(), propList.end(),
1483  [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXCustomXmlProps"; });
1484  if (pProp != propList.end())
1485  pProp->Value >>= customXmlDomPropslist;
1486 
1487  for (sal_Int32 j = 0; j < customXmlDomlist.getLength(); j++)
1488  {
1489  uno::Reference<xml::dom::XDocument> customXmlDom = customXmlDomlist[j];
1490  uno::Reference<xml::dom::XDocument> customXmlDomProps = customXmlDomPropslist[j];
1491  if (customXmlDom.is())
1492  {
1493  m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
1494  oox::getRelationship(Relationship::CUSTOMXML),
1495  OUString("../customXml/item"+OUString::number(j+1)+".xml" ));
1496 
1497  uno::Reference< xml::sax::XSAXSerializable > serializer( customXmlDom, uno::UNO_QUERY );
1498  uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() );
1499  writer->setOutputStream( GetFilter().openFragmentStream( "customXml/item"+OUString::number(j+1)+".xml",
1500  "application/xml" ) );
1501  serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1502  uno::Sequence< beans::StringPair >() );
1503  }
1504 
1505  if (customXmlDomProps.is())
1506  {
1507  uno::Reference< xml::sax::XSAXSerializable > serializer( customXmlDomProps, uno::UNO_QUERY );
1508  uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() );
1509  writer->setOutputStream( GetFilter().openFragmentStream( "customXml/itemProps"+OUString::number(j+1)+".xml",
1510  "application/vnd.openxmlformats-officedocument.customXmlProperties+xml" ) );
1511  serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1512  uno::Sequence< beans::StringPair >() );
1513 
1514  // Adding itemprops's relationship entry to item.xml.rels file
1515  m_rFilter.addRelation( GetFilter().openFragmentStream( "customXml/item"+OUString::number(j+1)+".xml",
1516  "application/xml" ) ,
1517  oox::getRelationship(Relationship::CUSTOMXMLPROPS),
1518  OUString("itemProps"+OUString::number(j+1)+".xml" ));
1519  }
1520  }
1521 }
1522 
1524 {
1525  uno::Reference<document::XStorageBasedDocument> xStorageBasedDocument(m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
1526  if (!xStorageBasedDocument.is())
1527  return;
1528 
1529  uno::Reference<embed::XStorage> xDocumentStorage = xStorageBasedDocument->getDocumentStorage();
1530  OUString aMacrosName("_MS_VBA_Macros");
1531  if (!xDocumentStorage.is() || !xDocumentStorage->hasByName(aMacrosName))
1532  return;
1533 
1534  const sal_Int32 nOpenMode = embed::ElementModes::READ;
1535  uno::Reference<io::XStream> xMacrosStream = xDocumentStorage->openStreamElement(aMacrosName, nOpenMode);
1536  uno::Reference<io::XOutputStream> xProjectStream;
1537  if (xMacrosStream.is())
1538  {
1539  // First handle the project stream, this sets xProjectStream.
1540  std::unique_ptr<SvStream> pIn(utl::UcbStreamHelper::CreateStream(xMacrosStream));
1541 
1542  xProjectStream = GetFilter().openFragmentStream("word/vbaProject.bin", "application/vnd.ms-office.vbaProject");
1543  uno::Reference<io::XStream> xOutputStream(xProjectStream, uno::UNO_QUERY);
1544  if (!xOutputStream.is())
1545  return;
1546  std::unique_ptr<SvStream> pOut(utl::UcbStreamHelper::CreateStream(xOutputStream));
1547 
1548  // Write the stream.
1549  pOut->WriteStream(*pIn);
1550 
1551  // Write the relationship.
1552  m_rFilter.addRelation(m_pDocumentFS->getOutputStream(), oox::getRelationship(Relationship::VBAPROJECT), u"vbaProject.bin");
1553  }
1554 
1555  OUString aDataName("_MS_VBA_Macros_XML");
1556  if (!xDocumentStorage.is() || !xDocumentStorage->hasByName(aDataName))
1557  return;
1558 
1559  uno::Reference<io::XStream> xDataStream = xDocumentStorage->openStreamElement(aDataName, nOpenMode);
1560  if (!xDataStream.is())
1561  return;
1562 
1563  // Then the data stream, which wants to work with an already set
1564  // xProjectStream.
1565  std::unique_ptr<SvStream> pIn(utl::UcbStreamHelper::CreateStream(xDataStream));
1566 
1567  uno::Reference<io::XStream> xOutputStream(GetFilter().openFragmentStream("word/vbaData.xml", "application/vnd.ms-word.vbaData+xml"), uno::UNO_QUERY);
1568  if (!xOutputStream.is())
1569  return;
1570  std::unique_ptr<SvStream> pOut(utl::UcbStreamHelper::CreateStream(xOutputStream));
1571 
1572  // Write the stream.
1573  pOut->WriteStream(*pIn);
1574 
1575  // Write the relationship.
1576  if (!xProjectStream.is())
1577  return;
1578 
1579  m_rFilter.addRelation(xProjectStream, oox::getRelationship(Relationship::WORDVBADATA), u"vbaData.xml");
1580 }
1581 
1583 {
1584  uno::Reference< beans::XPropertySet > xPropSet( m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1585 
1586  uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1588  if ( !xPropSetInfo->hasPropertyByName( aName ) )
1589  return;
1590 
1591  uno::Sequence< beans::PropertyValue > embeddingsList;
1592  uno::Sequence< beans::PropertyValue > propList;
1593  xPropSet->getPropertyValue( aName ) >>= propList;
1594  auto pProp = std::find_if(propList.begin(), propList.end(),
1595  [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXEmbeddings"; });
1596  if (pProp != propList.end())
1597  pProp->Value >>= embeddingsList;
1598  for (const auto& rEmbedding : std::as_const(embeddingsList))
1599  {
1600  OUString embeddingPath = rEmbedding.Name;
1601  uno::Reference<io::XInputStream> embeddingsStream;
1602  rEmbedding.Value >>= embeddingsStream;
1603  if (!embeddingsStream)
1604  continue;
1605 
1606  OUString contentType;
1607  if (css::uno::Reference<css::beans::XPropertySet> xProps{ embeddingsStream,
1608  css::uno::UNO_QUERY })
1609  {
1610  try
1611  {
1612  const css::uno::Any val = xProps->getPropertyValue("MediaType");
1613  val >>= contentType;
1614  }
1615  catch (const css::beans::UnknownPropertyException&)
1616  {
1617  TOOLS_WARN_EXCEPTION("sw.ww8", "WriteEmbeddings: Embedding without MediaType");
1618  }
1619  }
1620 
1621  if (contentType.isEmpty())
1622  {
1623  // FIXME: this .xlsm hack is silly - if anything the mime-type for an existing embedded object should be read from [Content_Types].xml
1624  if (embeddingPath.endsWith(".xlsm"))
1625  contentType = "application/vnd.ms-excel.sheet.macroEnabled.12";
1626  else if (embeddingPath.endsWith(".bin"))
1627  contentType = "application/vnd.openxmlformats-officedocument.oleObject";
1628  else
1629  contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
1630  }
1631 
1632  uno::Reference< io::XOutputStream > xOutStream = GetFilter().openFragmentStream(embeddingPath,
1633  contentType);
1634  try
1635  {
1636  // tdf#131288: the stream must be seekable for direct access
1637  uno::Reference<io::XSeekable> xSeekable(embeddingsStream, uno::UNO_QUERY);
1638  if (xSeekable)
1639  xSeekable->seek(0); // tdf#131288: a previous save could position it elsewhere
1640  comphelper::OStorageHelper::CopyInputToOutput(embeddingsStream, xOutStream);
1641  }
1642  catch(const uno::Exception&)
1643  {
1644  TOOLS_WARN_EXCEPTION("sw.ww8", "WriteEmbeddings() ::Failed to copy Inputstream to outputstream exception caught");
1645  }
1646  xOutStream->closeOutput();
1647  }
1648 }
1649 
1651 {
1652  bool bMirroredMargins = false;
1654  {
1655  bMirroredMargins = true;
1656  }
1657  return bMirroredMargins;
1658 }
1659 
1661 {
1662  // setup the namespaces
1663  m_pDocumentFS->startElementNS( XML_w, XML_document, MainXmlNamespaces());
1664 
1665  if ( getenv("SW_DEBUG_DOM") )
1666  {
1667  m_rDoc.dumpAsXml();
1668  }
1669 
1670  // reset the incrementing linked-textboxes chain ID before re-saving.
1671  m_nLinkedTextboxesChainId=0;
1672  m_aLinkedTextboxesHelper.clear();
1673 
1674  // Write background page color
1675  if (std::unique_ptr<SvxBrushItem> oBrush = getBackground(); oBrush)
1676  {
1677  Color backgroundColor = oBrush->GetColor();
1678  OString aBackgroundColorStr = msfilter::util::ConvertColor(backgroundColor);
1679 
1680  m_pDocumentFS->singleElementNS(XML_w, XML_background, FSNS(XML_w, XML_color),
1681  aBackgroundColorStr);
1682  }
1683 
1684  // body
1685  m_pDocumentFS->startElementNS(XML_w, XML_body);
1686 
1687  m_pCurPam->GetPoint()->nNode = m_rDoc.GetNodes().GetEndOfContent().StartOfSectionNode()->GetIndex();
1688 
1689  // the text
1690  WriteText();
1691 
1692  // clear linked textboxes since old ones can't be linked to frames in a different section (correct?)
1693  m_aLinkedTextboxesHelper.clear();
1694 
1695  // the last section info
1696  m_pAttrOutput->EndParaSdtBlock();
1697  const WW8_SepInfo *pSectionInfo = m_pSections? m_pSections->CurrentSectionInfo(): nullptr;
1698  if ( pSectionInfo )
1699  SectionProperties( *pSectionInfo );
1700 
1701  // finish body and document
1702  m_pDocumentFS->endElementNS( XML_w, XML_body );
1703  m_pDocumentFS->endElementNS( XML_w, XML_document );
1704 }
1705 
1707 {
1709  pAttr->add( FSNS( XML_xmlns, XML_o ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(vmlOffice)), RTL_TEXTENCODING_UTF8) );
1710  pAttr->add( FSNS( XML_xmlns, XML_r ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(officeRel)), RTL_TEXTENCODING_UTF8) );
1711  pAttr->add( FSNS( XML_xmlns, XML_v ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(vml)), RTL_TEXTENCODING_UTF8) );
1712  pAttr->add( FSNS( XML_xmlns, XML_w ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(doc)), RTL_TEXTENCODING_UTF8) );
1713  pAttr->add( FSNS( XML_xmlns, XML_w10 ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(vmlWord)), RTL_TEXTENCODING_UTF8) );
1714  pAttr->add( FSNS( XML_xmlns, XML_wp ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(dmlWordDr)), RTL_TEXTENCODING_UTF8) );
1715  pAttr->add( FSNS( XML_xmlns, XML_wps ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(wps)), RTL_TEXTENCODING_UTF8) );
1716  pAttr->add( FSNS( XML_xmlns, XML_wpg ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(wpg)), RTL_TEXTENCODING_UTF8) );
1717  pAttr->add( FSNS( XML_xmlns, XML_mc ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(mce)), RTL_TEXTENCODING_UTF8) );
1718  pAttr->add( FSNS( XML_xmlns, XML_wp14 ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(wp14)), RTL_TEXTENCODING_UTF8) );
1719  pAttr->add( FSNS( XML_xmlns, XML_w14 ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(w14)), RTL_TEXTENCODING_UTF8) );
1720  pAttr->add( FSNS( XML_mc, XML_Ignorable ), "w14 wp14" );
1721  return pAttr;
1722 }
1723 
1724 bool DocxExport::ignoreAttributeForStyleDefaults( sal_uInt16 nWhich ) const
1725 {
1726  if( nWhich == RES_TEXTGRID )
1727  return true; // w:docGrid is written only to document.xml, not to styles.xml
1728  if (nWhich == RES_PARATR_HYPHENZONE)
1729  return true; // w:suppressAutoHyphens is only a formatting exception, not a default
1731 }
1732 
1734  bool bNeedsLastParaId)
1735 {
1736  const EditTextObject& rEditObj = rParaObj.GetTextObject();
1737  MSWord_SdrAttrIter aAttrIter( *this, rEditObj, nTyp );
1738 
1739  sal_Int32 nPara = rEditObj.GetParagraphCount();
1740  sal_Int32 nParaId = 0;
1741  for( sal_Int32 n = 0; n < nPara; ++n )
1742  {
1743  if( n )
1744  aAttrIter.NextPara( n );
1745 
1746  nParaId = AttrOutput().StartParagraph(ww8::WW8TableNodeInfo::Pointer_t(),
1747  bNeedsLastParaId && n == nPara - 1);
1748  rtl_TextEncoding eChrSet = aAttrIter.GetNodeCharSet();
1749  OUString aStr( rEditObj.GetText( n ));
1750  sal_Int32 nCurrentPos = 0;
1751  const sal_Int32 nEnd = aStr.getLength();
1752  do {
1753  AttrOutput().StartRun( nullptr, 0 );
1754  const sal_Int32 nNextAttr = std::min(aAttrIter.WhereNext(), nEnd);
1755  rtl_TextEncoding eNextChrSet = aAttrIter.GetNextCharSet();
1756 
1757  bool bTextAtr = aAttrIter.IsTextAttr( nCurrentPos );
1758  if( !bTextAtr )
1759  {
1760  if( nCurrentPos == 0 && nNextAttr - nCurrentPos == aStr.getLength())
1761  AttrOutput().RunText( aStr, eChrSet );
1762  else
1763  {
1764  OUString tmp( aStr.copy( nCurrentPos, nNextAttr - nCurrentPos ));
1765  AttrOutput().RunText( tmp, eChrSet );
1766  }
1767  }
1768  AttrOutput().StartRunProperties();
1769  aAttrIter.OutAttr( nCurrentPos );
1770  AttrOutput().EndRunProperties( nullptr );
1771 
1772  nCurrentPos = nNextAttr;
1773  eChrSet = eNextChrSet;
1774  aAttrIter.NextPos();
1775 
1776  AttrOutput().EndRun( nullptr, 0 );
1777 
1778  } while( nCurrentPos < nEnd );
1779 // aAttrIter.OutParaAttr(false);
1780  AttrOutput().EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t());
1781  }
1782  return nParaId;
1783 }
1784 
1786 {
1787  mpFS = pFS;
1788 }
1789 
1791  std::shared_ptr<SwUnoCursor> & pCurrentPam,
1792  SwPaM& rOriginalPam, bool bDocm, bool bTemplate)
1793  : MSWordExportBase(rDocument, pCurrentPam, &rOriginalPam),
1794  m_rFilter( rFilter ),
1795  m_nHeaders( 0 ),
1796  m_nFooters( 0 ),
1797  m_nOLEObjects( 0 ),
1798  m_nActiveXControls( 0 ),
1799  m_nHeadersFootersInSection(0),
1800  m_bDocm(bDocm),
1801  m_bTemplate(bTemplate),
1802  m_pAuthorIDs(new SvtSecurityMapPersonalInfo)
1803 {
1804  // Write the document properties
1805  WriteProperties( );
1806 
1807  // relations for the document
1808  m_rFilter.addRelation( oox::getRelationship(Relationship::OFFICEDOCUMENT),
1809  u"word/document.xml" );
1810 
1811  // Set media type depending of document type
1812  OUString aMediaType;
1813  if (m_bDocm)
1814  {
1815  if (m_bTemplate)
1816  {
1817  aMediaType = "application/vnd.ms-word.template.macroEnabledTemplate.main+xml";
1818  }
1819  else
1820  {
1821  aMediaType = "application/vnd.ms-word.document.macroEnabled.main+xml";
1822  }
1823  }
1824  else
1825  {
1826  if (m_bTemplate)
1827  {
1828  aMediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml";
1829  }
1830  else
1831  {
1832  aMediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";
1833  }
1834  }
1835 
1836 
1837  // the actual document
1838  m_pDocumentFS = m_rFilter.openFragmentStreamWithSerializer( "word/document.xml", aMediaType );
1839 
1841 
1842  // the DrawingML access
1844 
1845  // the attribute output for the document
1846  m_pAttrOutput.reset(new DocxAttributeOutput( *this, m_pDocumentFS, m_pDrawingML.get() ));
1847 
1848  // the related VMLExport
1849  m_pVMLExport.reset(new VMLExport( m_pDocumentFS, m_pAttrOutput.get() ));
1850 
1851  // the related drawing export
1852  m_pSdrExport.reset(new DocxSdrExport( *this, m_pDocumentFS, m_pDrawingML.get() ));
1853 }
1854 
1856 {
1857 }
1858 
1860 : evenAndOddHeaders( false )
1861 , defaultTabStop( 0 )
1862 , revisionView( true )
1863 , trackRevisions( false )
1864 {
1865 }
1866 
1868 {
1869  if( evenAndOddHeaders )
1870  return true;
1871  if( defaultTabStop != 0 )
1872  return true;
1873  if ( !revisionView )
1874  return true;
1875  if ( trackRevisions )
1876  return true;
1877 
1878  return false;
1879 }
1880 
1881 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void WriteFootnotesEndnotes()
Write footnotes.xml and endnotes.xml.
Definition: docxexport.cxx:668
void OutAttr(sal_Int32 nSwPos)
Definition: wrtw8esh.cxx:1116
void InitStyles()
Setup pStyles and write styles.xml.
Definition: docxexport.cxx:645
virtual void DoFormText(const SwInputField *pField) override
Definition: docxexport.cxx:370
sal_uLong GetIndex() const
Definition: node.hxx:291
sal_Int32 WhereNext() const
Definition: wrtww8.hxx:1488
virtual void OutputLinkedOLE(const OUString &) override
Definition: docxexport.cxx:609
const char * sGUID
std::unique_ptr< oox::vml::VMLExport > m_pVMLExport
Exporter of the VML shapes.
Definition: docxexport.hxx:102
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:194
DocxAttributeOutput & DocxAttrOutput() const
Access to the derived attribute output class.
Definition: docxexport.cxx:104
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
bool m_bDocm
If the result will be a .docm file or not.
Definition: docxexport.hxx:108
The class that has handlers for various resource types when exporting as DOCX.
Handles DOCX export of drawings.
bool IsSectionNode() const
Definition: node.hxx:645
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:227
rtl_TextEncoding GetNodeCharSet() const
Definition: wrtww8.hxx:1490
const OUString & GetText() const
Definition: ndtxt.hxx:215
SwDocShell * GetDocShell()
Definition: doc.hxx:1352
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:4432
virtual void AppendBookmarks(const SwTextNode &rNode, sal_Int32 nCurrentPos, sal_Int32 nLen) override
Definition: docxexport.cxx:148
std::pair< OString, OString > WriteActiveXObject(const uno::Reference< css::drawing::XShape > &rxShape, const uno::Reference< awt::XControlModel > &rxControlModel)
Definition: docxexport.cxx:447
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
bool IsSecurityOptOpenReadOnly() const
sal_uIntPtr sal_uLong
OUString sDataSource
Definition: swdbdata.hxx:30
constexpr TypedWhichId< SwNumRuleItem > RES_PARATR_NUMRULE(72)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_FONTSIZE(8)
virtual void WriteHyperlinkData(const ::sw::mark::IFieldmark &rFieldmark) override
Definition: docxexport.cxx:323
Base class of all fields.
Definition: fldbas.hxx:289
css::uno::Reference< css::embed::XEmbeddedObject > const & GetOleRef()
Definition: ndole.cxx:915
sal_Int64 n
css::uno::Reference< css::frame::XModel3 > GetModel() const
Definition: doc.hxx:188
static auto WriteCompat(SwDoc const &rDoc,::sax_fastparser::FSHelperPtr const &rpFS, sal_Int32 &rTargetCompatibilityMode) -> void
Definition: docxexport.cxx:971
sal_Int16 nId
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:119
void WriteSettings()
Write word/settings.xml.
Definition: docxexport.cxx:989
void WriteGlossary()
SwSectionFormat * GetFormat()
Definition: section.hxx:336
void WriteFonts()
Write word/fontTable.xml.
Definition: docxexport.cxx:875
virtual void OutputGrfNode(const SwGrfNode &) override
Output SwGrfNode.
Definition: docxexport.cxx:599
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:1452
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CJK_POSTURE(25)
OUString FieldString(ww::eField eIndex)
Definition: ww8atr.cxx:2678
const SwSection & GetSection() const
Definition: node.hxx:542
SwDoc & m_rDoc
Definition: docbm.cxx:1208
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:141
std::unique_ptr< DocxAttributeOutput > m_pAttrOutput
Attribute output for document.
Definition: docxexport.hxx:81
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:111
Class to collect and output the styles table.
Definition: wrtww8.hxx:1570
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:99
ShapeExport & WriteShape(const css::uno::Reference< css::drawing::XShape > &xShape)
OUString sSuffix
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:426
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:377
void WritePostitFields()
Write comments.xml.
Definition: docxexport.cxx:725
oslFileHandle & pOut
const HdFtFlags WW8_FOOTER_EVEN
Definition: ww8scan.hxx:1598
sal_uLong GetStartValue() const
Definition: fmtline.hxx:57
OString WriteOLEObject(SwOLEObj &rObject, OUString &io_rProgID)
Definition: docxexport.cxx:399
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
RedlineFlags on.
virtual void AppendSection(const SwPageDesc *pPageDesc, const SwSectionFormat *pFormat, sal_uLong nLnNum) override
Definition: docxexport.cxx:550
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:803
OUString getRelationship(Relationship eRelationship)
virtual MSWordSections & Sections() const override
Access to the sections/headers/footres.
Definition: docxexport.cxx:109
#define UNO_NAME_MISC_OBJ_INTEROPGRABBAG
virtual void AppendAnnotationMarks(const SwWW8AttrIter &rAttrs, sal_Int32 nCurrentPos, sal_Int32 nLen) override
Definition: docxexport.cxx:189
const char * sName
bool getOutputStream(ProgramOptions const &options, OString const &extension, std::ostream **ppOutputStream, OString &targetSourceFileName, OString &tmpSourceFileName)
constexpr TypedWhichId< SvxHyphenZoneItem > RES_PARATR_HYPHENZONE(69)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_WEIGHT(15)
const HdFtFlags WW8_HEADER_ODD
Definition: ww8scan.hxx:1597
constexpr OUStringLiteral aData
Definition: ww8scan.hxx:48
Base class for various Writer styles.
Definition: format.hxx:46
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:163
void WriteEmbeddings()
Write word/embeddings/Worksheet[n].xlsx.
bool IsContentNode() const
Definition: node.hxx:629
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
virtual void PrepareNewPageDesc(const SfxItemSet *pSet, const SwNode &rNd, const SwFormatPageDesc *pNewPgDescFormat, const SwPageDesc *pNewPgDesc, bool bExtraPageBreak=false) override
Get ready for a new section.
Definition: docxexport.cxx:621
const EditTextObject & GetTextObject() const
::sax_fastparser::FSHelperPtr openFragmentStreamWithSerializer(const OUString &rStreamName, const OUString &rMediaType)
void WriteProperties()
Write docProps/core.xml.
Definition: docxexport.cxx:901
Style of a layout element.
Definition: frmfmt.hxx:58
#define TOOLS_WARN_EXCEPTION(area, stream)
static rtl::Reference< FastAttributeList > createAttrList()
SwDBData const & GetDBData()
Definition: docfld.cxx:344
virtual bool CollapseScriptsforWordOk(sal_uInt16 nScript, sal_uInt16 nWhich) override
Guess the script (asian/western).
Definition: docxexport.cxx:114
int i
void dumpAsXml(xmlTextWriterPtr=nullptr) const
Dumps the entire nodes structure to the given destination (file nodes.xml in the current directory by...
Definition: docfmt.cxx:1937
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:132
const SwPageDesc & GetPageDesc(const size_t i) const
Definition: doc.hxx:881
DocxExportFilter & m_rFilter
Pointer to the filter that owns us.
Definition: docxexport.hxx:69
void OutputDML(css::uno::Reference< css::drawing::XShape > const &xShape)
Writes the shape using drawingML syntax.
Definition: docxexport.cxx:495
SwContentNode * GetContentNode()
Definition: node.hxx:616
virtual OUString GetText(sal_Int32 nPara) const =0
UseOnPage ReadUseOn() const
Definition: pagedesc.hxx:236
std::unique_ptr< oox::drawingml::DrawingML > m_pDrawingML
Access to the DrawingML writer.
Definition: docxexport.hxx:78
virtual void WriteHeadersFooters(sal_uInt8 nHeadFootFlags, const SwFrameFormat &rFormat, const SwFrameFormat &rLeftHeaderFormat, const SwFrameFormat &rLeftFooterFormat, const SwFrameFormat &rFirstPageFormat, sal_uInt8 nBreakCode, bool bEvenAndOddHeaders) override
Output the actual headers and footers.
Definition: docxexport.cxx:249
float u
virtual void DoComboBox(const OUString &rName, const OUString &rHelp, const OUString &ToolTip, const OUString &rSelected, const css::uno::Sequence< OUString > &rListItems) override
Definition: docxexport.cxx:330
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
OString ConvertColor(const Color &rColor)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
Definition: format.cxx:388
Marks a node in the document model.
Definition: ndindex.hxx:31
bool IsEndNode() const
Definition: node.hxx:633
virtual void OutputOLENode(const SwOLENode &) override
Output SwOLENode.
Definition: docxexport.cxx:604
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:556
rtl::Reference< sax_fastparser::FastAttributeList > MainXmlNamespaces()
All xml namespaces to be used at the top of any text .xml file (main doc, headers, footers,...)
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
SwSectionFormat * GetParent() const
Definition: section.hxx:355
DocxExport(DocxExportFilter &rFilter, SwDoc &rDocument, std::shared_ptr< SwUnoCursor > &pCurrentPam, SwPaM &rOriginalPam, bool bDocm, bool bTemplate)
Pass the pDocument, pCurrentPam and pOriginalPam to the base class.
std::unique_ptr< DocxSdrExport > m_pSdrExport
Exporter of drawings.
Definition: docxexport.hxx:105
::comphelper::NamedValueCollection m_aSettings
virtual void WriteNumbering() override
Write the numbering table.
Definition: docxexport.cxx:765
SwFormat * DerivedFrom() const
Definition: format.hxx:112
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
DefTokenId nToken
virtual sal_uLong ReplaceCr(sal_uInt8 nChar) override
Definition: docxexport.cxx:614
constexpr TypedWhichId< SwTextGridItem > RES_TEXTGRID(115)
::sax_fastparser::FSHelperPtr m_pDocumentFS
Fast serializer for the document output.
Definition: docxexport.hxx:72
constexpr OUStringLiteral sMediaType
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CJK_WEIGHT(26)
void WriteVBA()
Writes word/vbaProject.bin.
#define SAL_WARN_IF(condition, area, stream)
#define ERRCODE_NONE
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
unsigned char sal_uInt8
virtual sal_Int32 GetParagraphCount() const =0
bool IsTextAttr(sal_Int32 nSwPos)
Definition: wrtw8esh.cxx:1196
#define SAL_INFO(area, stream)
OUString aName
virtual ErrCode ExportDocument_Impl() override
Format-dependent part of the actual export.
Definition: docxexport.cxx:507
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:318
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
IDocumentSettingAccess const & getIDocumentSettingAccess() const
Definition: doc.cxx:176
SwNodes & GetNodes()
Definition: doc.hxx:409
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
void WriteDocVars(const sax_fastparser::FSHelperPtr &pFS)
Writes the part of settings.xml.
Definition: docxexport.cxx:918
const sal_uInt8 PageBreak
OReadImagesDocumentHandler::Image_XML_Namespace nNamespace
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:313
static void ResetCounters()
bool evenAndOddHeaders
returns true if there are any non-default settings (i.e. something to write)
Definition: docxexport.hxx:59
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
constexpr sal_Int32 FSNS(sal_Int32 namespc, sal_Int32 element)
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:715
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)
OUString sId
sal_Int32 DocxStringGetToken(DocxStringTokenMap const *pMap, std::u16string_view rName)
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:690
virtual void AppendBookmark(const OUString &rName) override
Definition: docxexport.cxx:178
Base class for WW8Export and DocxExport.
Definition: wrtww8.hxx:449
Reference< XModel > xModel
bool IsTableNode() const
Definition: node.hxx:641
virtual ~DocxExport() override
Destructor.
SwSectionNode * GetSectionNode()
Definition: node.hxx:608
Ends a section of nodes in the document model.
Definition: node.hxx:342
rtl_TextEncoding GetNextCharSet() const
Definition: wrtw8esh.cxx:1042
SectionType GetType() const
Definition: section.hxx:170
std::vector< ::sw::mark::IMark * > IMarkVector
Used to split the runs according to the bookmarks start and ends.
Definition: wrtww8.hxx:583
std::shared_ptr< WW8TableNodeInfo > Pointer_t
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CJK_FONTSIZE(23)
OUString sCommand
Definition: swdbdata.hxx:31
OUString addRelation(const OUString &rType, std::u16string_view rTarget)
aStr
void NextPara(sal_Int32 nPar)
Definition: wrtw8esh.cxx:1022
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_POSTURE(11)
virtual OUString GetPar2() const override
aPromptText
Definition: expfld.cxx:1399
const SwFootnoteInfo & GetFootnoteInfo() const
Definition: doc.hxx:630
OString AddRelation(const OUString &rType, std::u16string_view rTarget)
Returns the relationd id.
Definition: docxexport.cxx:219
const SwEndNoteInfo & GetEndNoteInfo() const
Definition: doc.hxx:632
const HdFtFlags WW8_FOOTER_ODD
Definition: ww8scan.hxx:1599
virtual void ExportGrfBullet(const SwTextNode &) override
Definition: docxexport.cxx:213
const HdFtFlags WW8_HEADER_EVEN
Definition: ww8scan.hxx:1596
const SwFormatLineNumber & GetLineNumber(bool=true) const
Definition: fmtline.hxx:64
sal_Int32 WriteOutliner(const OutlinerParaObject &rOutliner, sal_uInt8 nTyp, bool bNeedsLastParaId)
Base class of the Writer document model elements.
Definition: node.hxx:80
void WriteMainText()
FIXME this is temporary, remotely reminding the method of the same name in WW8Export.