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 <config_wasm_strip.h>
21
22#include "docxexport.hxx"
23#include "docxexportfilter.hxx"
25#include "docxsdrexport.hxx"
26#include "docxhelper.hxx"
27
28#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
29#include <com/sun/star/document/XDocumentProperties.hpp>
30#include <com/sun/star/document/XStorageBasedDocument.hpp>
31#include <com/sun/star/drawing/XShape.hpp>
32#include <com/sun/star/i18n/ScriptType.hpp>
33#include <com/sun/star/frame/XModel.hpp>
34#include <com/sun/star/xml/dom/XDocument.hpp>
35#include <com/sun/star/xml/sax/XSAXSerializable.hpp>
36#include <com/sun/star/xml/sax/Writer.hpp>
37#include <com/sun/star/awt/XControlModel.hpp>
38#include <com/sun/star/io/XSeekable.hpp>
39#include <com/sun/star/io/XStreamListener.hpp>
40#include <com/sun/star/sdb/CommandType.hpp>
41#include <com/sun/star/text/XTextFieldsSupplier.hpp>
42#include <com/sun/star/util/XModifiable.hpp>
43#include <com/sun/star/xml/xslt/XSLTTransformer.hpp>
44
45#include <oox/token/namespaces.hxx>
46#include <oox/token/tokens.hxx>
50#include <oox/export/shapes.hxx>
54#include <oox/ole/olehelper.hxx>
55
56#include <map>
57#include <algorithm>
58#include <condition_variable>
59#include <mutex>
60
61#include <IMark.hxx>
65#include <docsh.hxx>
66#include <ndtxt.hxx>
67#include "wrtww8.hxx"
68#include <fmtline.hxx>
69#include <fmtpdsc.hxx>
70#include <frmfmt.hxx>
71#include <section.hxx>
72#include <ftninfo.hxx>
73#include <pagedesc.hxx>
74#include <poolfmt.hxx>
75#include <redline.hxx>
76#include <swdbdata.hxx>
77
78#include <editeng/unoprnms.hxx>
79#include <editeng/editobj.hxx>
80#include <editeng/outlobj.hxx>
81#include <editeng/brushitem.hxx>
83
84#include <viewsh.hxx>
85#include <viewopt.hxx>
86
87#include "ww8scan.hxx"
88#include <oox/token/properties.hxx>
92#include <o3tl/any.hxx>
93#include <sal/log.hxx>
96
97using namespace sax_fastparser;
98using namespace ::comphelper;
99using namespace ::com::sun::star;
100using namespace ::oox;
101
103
104using sw::mark::IMark;
105
107{
108 return *m_pAttrOutput;
109}
110
112{
113 return *m_pAttrOutput;
114}
115
117{
118 return *m_pSections;
119}
120
121bool DocxExport::CollapseScriptsforWordOk( sal_uInt16 nScript, sal_uInt16 nWhich )
122{
123 // TODO FIXME is this actually true for docx? - this is ~copied from WW8
124 if ( nScript == i18n::ScriptType::ASIAN )
125 {
126 // for asian in ww8, there is only one fontsize
127 // and one fontstyle (posture/weight)
128 switch ( nWhich )
129 {
133 return false;
134 default:
135 break;
136 }
137 }
138 else if ( nScript != i18n::ScriptType::COMPLEX )
139 {
140 // for western in ww8, there is only one fontsize
141 // and one fontstyle (posture/weight)
142 switch ( nWhich )
143 {
147 return false;
148 default:
149 break;
150 }
151 }
152 return true;
153}
154
155void DocxExport::AppendBookmarks( const SwTextNode& rNode, sal_Int32 nCurrentPos, sal_Int32 nLen, const SwRedlineData* pRedlineData )
156{
157 std::vector< OUString > aStarts;
158 std::vector< OUString > aEnds;
159
160 IMarkVector aMarks;
161 if ( GetBookmarks( rNode, nCurrentPos, nCurrentPos + nLen, aMarks ) )
162 {
163 for ( IMark* pMark : aMarks )
164 {
165 const sal_Int32 nStart = pMark->GetMarkStart().GetContentIndex();
166 const sal_Int32 nEnd = pMark->GetMarkEnd().GetContentIndex();
167
168 if ( nStart == nCurrentPos )
169 aStarts.push_back( pMark->GetName() );
170
171 if ( nEnd == nCurrentPos )
172 aEnds.push_back( pMark->GetName() );
173 }
174 }
175
176 const OUString& aStr( rNode.GetText() );
177 const sal_Int32 nEnd = aStr.getLength();
178
179 if ( nCurrentPos == nEnd )
180 m_pAttrOutput->WriteFinalBookmarks_Impl( aStarts, aEnds );
181 else
182 m_pAttrOutput->WriteBookmarks_Impl( aStarts, aEnds, pRedlineData );
183}
184
185void DocxExport::AppendBookmark( const OUString& rName )
186{
187 std::vector< OUString > aStarts { rName };
188 std::vector< OUString > aEnds { rName };
189
190 m_pAttrOutput->WriteBookmarks_Impl( aStarts, aEnds );
191}
192
193void DocxExport::AppendAnnotationMarks( const SwWW8AttrIter& rAttrs, sal_Int32 nCurrentPos, sal_Int32 nLen )
194{
195 std::vector< OUString > aStarts;
196 std::vector< OUString > aEnds;
197
198 IMarkVector aMarks;
199 if (GetAnnotationMarks(rAttrs, nCurrentPos, nCurrentPos + nLen, aMarks))
200 {
201 for ( IMark* pMark : aMarks )
202 {
203 const sal_Int32 nStart = pMark->GetMarkStart().GetContentIndex();
204 const sal_Int32 nEnd = pMark->GetMarkEnd().GetContentIndex();
205
206 if ( nStart == nCurrentPos )
207 aStarts.push_back( pMark->GetName() );
208
209 if ( nEnd == nCurrentPos )
210 aEnds.push_back( pMark->GetName() );
211 }
212 }
213
214 m_pAttrOutput->WriteAnnotationMarks_Impl( aStarts, aEnds );
215}
216
218{
219 // Just collect the bullets for now, numbering.xml is not yet started.
221}
222
223OString DocxExport::AddRelation( const OUString& rType, std::u16string_view rTarget )
224{
225 OUString sId = m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
226 rType, rTarget, true );
227
228 return sId.toUtf8();
229}
230
232{
233 bool bRet( false );
234
235 if (SfxItemState::SET != rFormat.GetItemState(RES_PARATR_NUMRULE, false))
236 {
237 if (const SwFormat *pParent = rFormat.DerivedFrom())
238 {
239 if (static_cast<const SwTextFormatColl*>(pParent)->IsAssignedToListLevelOfOutlineStyle())
240 {
241 ::sax_fastparser::FSHelperPtr pSerializer = m_pAttrOutput->GetSerializer( );
242 // Level 9 disables the outline
243 pSerializer->singleElementNS(XML_w, XML_outlineLvl, FSNS(XML_w, XML_val), "9");
244
245 bRet = true;
246 }
247 }
248 }
249
250 return bRet;
251}
252
254 const SwFrameFormat& rFormat, const SwFrameFormat& rLeftHeaderFormat, const SwFrameFormat& rLeftFooterFormat, const SwFrameFormat& rFirstPageFormat,
255 sal_uInt8 nBreakCode, bool bEvenAndOddHeaders )
256{
258
259 // document setting indicating the requirement of EVEN and ODD for both headers and footers
260 if ( nHeadFootFlags & ( nsHdFtFlags::WW8_FOOTER_EVEN | nsHdFtFlags::WW8_HEADER_EVEN ) && bEvenAndOddHeaders )
262
263 // Turn ON flag for 'Writing Headers \ Footers'
264 m_pAttrOutput->SetWritingHeaderFooter( true );
265
266 const bool bPrevSectionHadHeader = m_bHasHdr;
267 const bool bPrevSectionHadFooter = m_bHasFtr;
268 m_bHasHdr = m_bHasFtr = false;
269
270 // headers
271 if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_EVEN )
272 WriteHeaderFooter( &rLeftHeaderFormat, true, "even" );
274 {
275 if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_ODD )
276 WriteHeaderFooter( &rFormat, true, "even" );
277 else if (bPrevSectionHadHeader && nBreakCode == 2)
278 WriteHeaderFooter( nullptr, true, "even" );
279 }
280
281 if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_ODD )
282 WriteHeaderFooter( &rFormat, true, "default" );
283 else if (bPrevSectionHadHeader && nBreakCode == 2) // 2: nextPage
284 WriteHeaderFooter(nullptr, true, "default");
285
286 if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_FIRST )
287 WriteHeaderFooter( &rFirstPageFormat, true, "first" );
288 else if (bPrevSectionHadHeader && nBreakCode == 2)
289 WriteHeaderFooter(nullptr, true, "first");
290
291 // footers
292 if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_EVEN )
293 WriteHeaderFooter( &rLeftFooterFormat, false, "even" );
295 {
296 if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_ODD )
297 WriteHeaderFooter( &rFormat, false, "even" );
298 else if (bPrevSectionHadFooter && nBreakCode == 2)
299 WriteHeaderFooter( nullptr, false, "even");
300 }
301
302 if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_ODD )
303 WriteHeaderFooter( &rFormat, false, "default" );
304 else if (bPrevSectionHadFooter && nBreakCode == 2)
305 WriteHeaderFooter(nullptr, false, "default");
306
307 if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_FIRST )
308 WriteHeaderFooter( &rFirstPageFormat, false, "first" );
309 else if (bPrevSectionHadFooter && nBreakCode == 2)
310 WriteHeaderFooter(nullptr, false, "first");
311
312 // Turn OFF flag for 'Writing Headers \ Footers'
313 m_pAttrOutput->SetWritingHeaderFooter( false );
314}
315
316void DocxExport::OutputField( const SwField* pField, ww::eField eFieldType, const OUString& rFieldCmd, FieldFlags nMode )
317{
318 m_pAttrOutput->WriteField_Impl( pField, eFieldType, rFieldCmd, nMode );
319}
320
321void DocxExport::WriteFormData( const ::sw::mark::IFieldmark& rFieldmark )
322{
323 m_pAttrOutput->WriteFormData_Impl( rFieldmark );
324}
325
326void DocxExport::WriteHyperlinkData( const ::sw::mark::IFieldmark& /*rFieldmark*/ )
327{
328 SAL_INFO("sw.ww8", "TODO DocxExport::WriteHyperlinkData().");
329}
330
331void DocxExport::DoComboBox(const OUString& rName,
332 const OUString& rHelp,
333 const OUString& rToolTip,
334 const OUString& rSelected,
335 const 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);
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);
345
346 if ( !rToolTip.isEmpty() )
347 m_pDocumentFS->singleElementNS(XML_w, XML_statusText, FSNS(XML_w, XML_val), rToolTip);
348
349 m_pDocumentFS->startElementNS(XML_w, XML_ddList);
350
351 // Output the 0-based index of the selected value
352 sal_Int32 nId = comphelper::findValue(rListItems, rSelected);
353 if (nId == -1)
354 nId = 0;
355
356 m_pDocumentFS->singleElementNS(XML_w, XML_result, FSNS(XML_w, XML_val), OString::number(nId));
357
358 // unfortunately Word 2013 refuses to load DOCX with more than 25 listEntry
359 SAL_WARN_IF(25 < rListItems.getLength(), "sw.ww8", "DocxExport::DoComboBox data loss with more than 25 entries");
360 auto const nSize(std::min(sal_Int32(25), rListItems.getLength()));
361 for (auto i = 0; i < nSize; ++i)
362 {
363 m_pDocumentFS->singleElementNS(XML_w, XML_listEntry, FSNS(XML_w, XML_val), rListItems[i]);
364 }
365
366 m_pDocumentFS->endElementNS( XML_w, XML_ddList );
367
368 m_pDocumentFS->endElementNS( XML_w, XML_ffData );
369}
370
372{
373 assert(pField);
374 const OUString sStr = FieldString(ww::eFILLIN) + "\"" + pField->GetPar2() + "\"";
375 OutputField(pField, ww::eFILLIN, sStr);
376}
377
378OString DocxExport::OutputChart( uno::Reference< frame::XModel > const & xModel, sal_Int32 nCount, ::sax_fastparser::FSHelperPtr const & m_pSerializer )
379{
380 OUString aFileName = "charts/chart" + OUString::number(nCount) + ".xml";
381 OUString sId = m_rFilter.addRelation( m_pSerializer->getOutputStream(),
382 oox::getRelationship(Relationship::CHART),
383 aFileName );
384 aFileName = "word/charts/chart" + OUString::number(nCount) + ".xml";
387 "application/vnd.openxmlformats-officedocument.drawingml.chart+xml" );
388
389#if !ENABLE_WASM_STRIP_CHART
390 // WASM_CHART change
391 // TODO: With Chart extracted this cannot really happen since
392 // no Chart could've been added at all
394 css::uno::Reference<css::util::XModifiable> xModifiable(xModel, css::uno::UNO_QUERY);
395 const bool bOldModified = xModifiable && xModifiable->isModified();
396 aChartExport.ExportContent();
397 if (!bOldModified && xModifiable && xModifiable->isModified())
398 // tdf#134973: the model could get modified: e.g., calling XChartDocument::getSubTitle(),
399 // which creates the object if absent, and sets the modified state.
400 xModifiable->setModified(bOldModified);
401#else
402 (void)xModel;
403#endif
404 pChartFS->endDocument();
405 return OUStringToOString( sId, RTL_TEXTENCODING_UTF8 );
406}
407
408OString DocxExport::WriteOLEObject(SwOLEObj& rObject, OUString & io_rProgID)
409{
410 uno::Reference <embed::XEmbeddedObject> xObj( rObject.GetOleRef() );
411 uno::Reference<uno::XComponentContext> const xContext(
413
414 OUString sMediaType;
415 OUString sRelationType;
416 OUString sSuffix;
417 const char * pProgID(nullptr);
418
419 uno::Reference<io::XInputStream> const xInStream =
420 oox::GetOLEObjectStream(xContext, xObj, io_rProgID,
421 sMediaType, sRelationType, sSuffix, pProgID);
422
423 if (!xInStream.is())
424 {
425 return OString();
426 }
427
428 assert(!sMediaType.isEmpty());
429 assert(!sRelationType.isEmpty());
430 assert(!sSuffix.isEmpty());
431 OUString sFileName = "embeddings/oleObject" + OUString::number( ++m_nOLEObjects ) + "." + sSuffix;
432 uno::Reference<io::XOutputStream> const xOutStream =
433 GetFilter().openFragmentStream("word/" + sFileName, sMediaType);
434 assert(xOutStream.is()); // no reason why that could fail
435
436 try
437 {
439 }
440 catch (uno::Exception const&)
441 {
442 TOOLS_WARN_EXCEPTION("sw.ww8", "DocxExport::WriteOLEObject");
443 return OString();
444 }
445
446 OUString const sId = m_rFilter.addRelation( GetFS()->getOutputStream(),
447 sRelationType, sFileName );
448 if (pProgID)
449 {
450 io_rProgID = OUString::createFromAscii(pProgID);
451 }
452
453 return OUStringToOString( sId, RTL_TEXTENCODING_UTF8 );
454}
455
456std::pair<OString, OString> DocxExport::WriteActiveXObject(const uno::Reference<drawing::XShape>& rxShape,
457 const uno::Reference<awt::XControlModel>& rxControlModel)
458{
460
461 // Write out ActiveX binary
462 const OUString sBinaryFileName = "word/activeX/activeX" + OUString::number(m_nActiveXControls) + ".bin";
463
464 OString sGUID;
465 OString sName;
466 uno::Reference<io::XStream> xOutStorage(m_rFilter.openFragmentStream(sBinaryFileName, "application/vnd.ms-office.activeX"), uno::UNO_QUERY);
467 if(xOutStorage.is())
468 {
469 oox::ole::OleStorage aOleStorage(m_rFilter.getComponentContext(), xOutStorage, false);
470 uno::Reference<io::XOutputStream> xOutputStream(aOleStorage.openOutputStream("contents"), uno::UNO_SET_THROW);
471 uno::Reference< css::frame::XModel > xModel( m_rDoc.GetDocShell() ? m_rDoc.GetDocShell()->GetModel() : nullptr );
473 if ( !exportHelper.isValid() )
474 return std::make_pair<OString, OString>(OString(), OString());
475 sGUID = OUStringToOString(exportHelper.getGUID(), RTL_TEXTENCODING_UTF8);
476 sName = OUStringToOString(exportHelper.getName(), RTL_TEXTENCODING_UTF8);
477 exportHelper.exportControl(xOutputStream, rxShape->getSize(), true);
478 aOleStorage.commit();
479 }
480
481 // Write out ActiveX fragment
482 const OUString sXMLFileName = "word/activeX/activeX" + OUString::number( m_nActiveXControls ) + ".xml";
483 ::sax_fastparser::FSHelperPtr pActiveXFS = m_rFilter.openFragmentStreamWithSerializer(sXMLFileName, "application/vnd.ms-office.activeX+xml" );
484
485 const OUString sBinaryId = m_rFilter.addRelation( pActiveXFS->getOutputStream(),
486 oox::getRelationship(Relationship::ACTIVEXCONTROLBINARY),
487 sBinaryFileName.subView(sBinaryFileName.lastIndexOf("/") + 1) );
488
489 pActiveXFS->singleElementNS(XML_ax, XML_ocx,
490 FSNS(XML_xmlns, XML_ax), m_rFilter.getNamespaceURL(OOX_NS(ax)),
491 FSNS(XML_xmlns, XML_r), m_rFilter.getNamespaceURL(OOX_NS(officeRel)),
492 FSNS(XML_ax, XML_classid), "{" + sGUID + "}",
493 FSNS(XML_ax, XML_persistence), "persistStorage",
494 FSNS(XML_r, XML_id), sBinaryId);
495
496 OString sXMLId = OUStringToOString(m_rFilter.addRelation(m_pDocumentFS->getOutputStream(),
497 oox::getRelationship(Relationship::CONTROL),
498 sXMLFileName.subView(sBinaryFileName.indexOf("/") + 1)),
499 RTL_TEXTENCODING_UTF8);
500
501 pActiveXFS->endDocument();
502
503 return std::pair<OString, OString>(sXMLId, sName);
504}
505
506void DocxExport::OutputDML(uno::Reference<drawing::XShape> const & xShape)
507{
508 uno::Reference<lang::XServiceInfo> xServiceInfo(xShape, uno::UNO_QUERY_THROW);
509 sal_Int32 nNamespace = XML_wps;
510 if (xServiceInfo->supportsService("com.sun.star.drawing.GroupShape"))
511 nNamespace = XML_wpg;
512 else if (xServiceInfo->supportsService("com.sun.star.drawing.GraphicObjectShape"))
513 nNamespace = XML_pic;
515 aExport.WriteShape(xShape);
516}
517
519{
520 // Set the 'Reviewing' flags in the settings structure
523
524 InitStyles();
525
526 // init sections
527 m_pSections.reset(new MSWordSections( *this ));
528
529 auto& rGraphicExportCache = oox::drawingml::GraphicExportCache::get();
530
531 // Make sure images are counted from one, even when exporting multiple documents.
532 rGraphicExportCache.push();
533
535
537
539
541
542 WriteFonts();
543
545
546 WriteTheme();
547
549
551
553
554 if (m_bDocm)
555 WriteVBA();
556
557 m_aLinkedTextboxesHelper.clear(); //final cleanup
558 m_pStyles.reset();
559 m_pSections.reset();
560
561 rGraphicExportCache.pop();
562
563 return ERRCODE_NONE;
564}
565
566void DocxExport::AppendSection( const SwPageDesc *pPageDesc, const SwSectionFormat* pFormat, sal_uLong nLnNum )
567{
568 AttrOutput().SectionBreak( msword::PageBreak, false, m_pSections->CurrentSectionInfo() );
569 m_pSections->AppendSection( pPageDesc, pFormat, nLnNum, m_pAttrOutput->IsFirstParagraph() );
570}
571
573{
575
577 {
578 // this originally comes from WW8Export::WriteText(), and looks like it
579 // could have some code common with SectionNode()...
580
581 const SwSection& rSect = rEndNode.StartOfSectionNode()->GetSectionNode()->GetSection();
582 if ( m_bStartTOX && SectionType::ToxContent == rSect.GetType() )
583 m_bStartTOX = false;
584
585 SwNodeIndex aIdx( rEndNode, 1 );
586 const SwNode& rNd = aIdx.GetNode();
587 if ( rNd.IsEndNode() && rNd.StartOfSectionNode()->IsSectionNode() )
588 return;
589
590 bool isInTable = IsInTable();
591 if ( !rNd.IsSectionNode() && isInTable ) // No sections in table
592 {
593 const SwSectionFormat* pParentFormat = rSect.GetFormat()->GetParent();
594 if( !pParentFormat )
595 pParentFormat = reinterpret_cast<SwSectionFormat*>(sal_IntPtr(-1));
596
597 sal_uLong nRstLnNum;
598 if( rNd.IsContentNode() )
600 else
601 nRstLnNum = 0;
602
603 AppendSection( m_pCurrentPageDesc, pParentFormat, nRstLnNum );
604 }
605 else
606 {
607 AttrOutput().SectionBreaks( rEndNode );
608 }
609 }
610 else if (TXT_MAINTEXT == m_nTextTyp && rEndNode.StartOfSectionNode()->IsTableNode())
611 // End node of a table: see if a section break should be written after the table.
612 AttrOutput().SectionBreaks(rEndNode);
613}
614
616{
617 SAL_INFO("sw.ww8", "TODO DocxExport::OutputGrfNode( const SwGrfNode& )" );
618}
619
621{
622 SAL_INFO("sw.ww8", "TODO DocxExport::OutputOLENode( const SwOLENode& )" );
623}
624
625void DocxExport::OutputLinkedOLE( const OUString& )
626{
627 // Nothing to implement here: WW8 only
628}
629
631{
632 // Completely unused for Docx export... only here for code sharing
633 // purpose with binary export
634 return 0;
635}
636
638 const SwNode& rNd, const SwFormatPageDesc* pNewPgDescFormat,
639 const SwPageDesc* pNewPgDesc, bool bExtraPageBreak )
640{
641 // tell the attribute output that we are ready to write the section
642 // break [has to be output inside paragraph properties]
643 AttrOutput().SectionBreak( msword::PageBreak, false, m_pSections->CurrentSectionInfo(), bExtraPageBreak );
644
645 const SwSectionFormat* pFormat = GetSectionFormat( rNd );
646 const sal_uLong nLnNm = GetSectionLineNo( pSet, rNd );
647
648 OSL_ENSURE( pNewPgDescFormat || pNewPgDesc, "Neither page desc format nor page desc provided." );
649
650 if ( pNewPgDescFormat )
651 {
652 m_pSections->AppendSection( *pNewPgDescFormat, rNd, pFormat, nLnNm );
653 }
654 else if ( pNewPgDesc )
655 {
656 m_pSections->AppendSection( pNewPgDesc, rNd, pFormat, nLnNm );
657 }
658
659}
660
662{
663 m_pStyles.reset(new MSWordStyles( *this, /*bListStyles =*/ true ));
664
665 // setup word/styles.xml and the relations + content type
666 m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
667 oox::getRelationship(Relationship::STYLES),
668 u"styles.xml" );
669
672 "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml" );
673
674 // switch the serializer to redirect the output to word/styles.xml
675 m_pAttrOutput->SetSerializer( pStylesFS );
676
677 // do the work
678 m_pStyles->OutputStylesTable();
679
680 // switch the serializer back
681 m_pAttrOutput->SetSerializer( m_pDocumentFS );
682
683 pStylesFS->endDocument();
684}
685
687{
688 if ( m_pAttrOutput->HasFootnotes() )
689 {
690 // setup word/styles.xml and the relations + content type
691 m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
692 oox::getRelationship(Relationship::FOOTNOTES),
693 u"footnotes.xml" );
694
695 ::sax_fastparser::FSHelperPtr pFootnotesFS =
696 m_rFilter.openFragmentStreamWithSerializer( "word/footnotes.xml",
697 "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml" );
698
699 // switch the serializer to redirect the output to word/footnotes.xml
700 m_pAttrOutput->SetSerializer( pFootnotesFS );
701 // tdf#99227
702 m_pSdrExport->setSerializer( pFootnotesFS );
703 // tdf#107969
704 m_pVMLExport->SetFS(pFootnotesFS);
705
706 // do the work
707 m_pAttrOutput->FootnotesEndnotes( true );
708
709 // switch the serializer back
711 m_pSdrExport->setSerializer( m_pDocumentFS );
712 m_pAttrOutput->SetSerializer( m_pDocumentFS );
713
714 pFootnotesFS->endDocument();
715 }
716
717 if ( !m_pAttrOutput->HasEndnotes() )
718 return;
719
720 // setup word/styles.xml and the relations + content type
721 m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
722 oox::getRelationship(Relationship::ENDNOTES),
723 u"endnotes.xml" );
724
726 m_rFilter.openFragmentStreamWithSerializer( "word/endnotes.xml",
727 "application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml" );
728
729 // switch the serializer to redirect the output to word/endnotes.xml
730 m_pAttrOutput->SetSerializer( pEndnotesFS );
731 // tdf#99227
732 m_pSdrExport->setSerializer( pEndnotesFS );
733 // tdf#107969
734 m_pVMLExport->SetFS(pEndnotesFS);
735
736 // do the work
737 m_pAttrOutput->FootnotesEndnotes( false );
738
739 // switch the serializer back
741 m_pSdrExport->setSerializer( m_pDocumentFS );
742 m_pAttrOutput->SetSerializer( m_pDocumentFS );
743
744 pEndnotesFS->endDocument();
745}
746
748{
749 if ( !m_pAttrOutput->HasPostitFields() )
750 return;
751
752 m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
753 oox::getRelationship(Relationship::COMMENTS),
754 u"comments.xml" );
755
757 m_rFilter.openFragmentStreamWithSerializer( "word/comments.xml",
758 "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml" );
759
760 pPostitFS->startElementNS( XML_w, XML_comments, MainXmlNamespaces());
761 m_pAttrOutput->SetSerializer( pPostitFS );
762 const auto eHasProperties = m_pAttrOutput->WritePostitFields();
763 m_pAttrOutput->SetSerializer( m_pDocumentFS );
764 pPostitFS->endElementNS( XML_w, XML_comments );
765 pPostitFS->endDocument();
766
767 if (eHasProperties != DocxAttributeOutput::hasProperties::yes)
768 return;
769
770 m_rFilter.addRelation(m_pDocumentFS->getOutputStream(),
771 oox::getRelationship(Relationship::COMMENTSEXTENDED),
772 u"commentsExtended.xml");
773
775 "word/commentsExtended.xml",
776 "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml");
777
778 pPostitFS->startElementNS(XML_w15, XML_commentsEx, // Add namespaces manually now
779 FSNS(XML_xmlns, XML_mc), m_rFilter.getNamespaceURL(OOX_NS(mce)),
780 FSNS(XML_xmlns, XML_w15), m_rFilter.getNamespaceURL(OOX_NS(w15)),
781 FSNS(XML_mc, XML_Ignorable), "w15");
782 m_pAttrOutput->SetSerializer(pPostitFS);
783 m_pAttrOutput->WritePostItFieldsResolved();
784 m_pAttrOutput->SetSerializer(m_pDocumentFS);
785 pPostitFS->endElementNS(XML_w15, XML_commentsEx);
786 pPostitFS->endDocument();
787}
788
790{
791 if ( !m_pUsedNumTable )
792 return; // no numbering is used
793
794 m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
795 oox::getRelationship(Relationship::NUMBERING),
796 u"numbering.xml" );
797
799 "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml" );
800
801 // switch the serializer to redirect the output to word/numbering.xml
802 m_pAttrOutput->SetSerializer( pNumberingFS );
803 m_pDrawingML->SetFS( pNumberingFS );
804
805 pNumberingFS->startElementNS( XML_w, XML_numbering,
806 FSNS( XML_xmlns, XML_w ), m_rFilter.getNamespaceURL(OOX_NS(doc)),
807 FSNS( XML_xmlns, XML_o ), m_rFilter.getNamespaceURL(OOX_NS(vmlOffice)),
808 FSNS( XML_xmlns, XML_r ), m_rFilter.getNamespaceURL(OOX_NS(officeRel)),
809 FSNS( XML_xmlns, XML_v ), m_rFilter.getNamespaceURL(OOX_NS(vml)),
810 FSNS( XML_xmlns, XML_mc ), m_rFilter.getNamespaceURL(OOX_NS(mce)),
811 FSNS( XML_xmlns, XML_w14 ), m_rFilter.getNamespaceURL(OOX_NS(w14)),
812 FSNS( XML_mc, XML_Ignorable ), "w14" );
813
815
817
819
820 pNumberingFS->endElementNS( XML_w, XML_numbering );
821
822 // switch the serializer back
823 m_pDrawingML->SetFS( m_pDocumentFS );
824 m_pAttrOutput->SetSerializer( m_pDocumentFS );
825
826 pNumberingFS->endDocument();
827}
828
829void DocxExport::WriteHeaderFooter( const SwFormat* pFormat, bool bHeader, const char* pType )
830{
831 // setup the xml stream
832 OUString aRelId;
834 if ( bHeader )
835 {
836 OUString aName( "header" + OUString::number( ++m_nHeaders ) + ".xml" );
837
838 aRelId = m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
839 oox::getRelationship(Relationship::HEADER),
840 aName );
841
843 "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml" );
844
845 pFS->startElementNS( XML_w, XML_hdr, MainXmlNamespaces());
846 }
847 else
848 {
849 OUString aName( "footer" + OUString::number( ++m_nFooters ) + ".xml" );
850
851 aRelId = m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
852 oox::getRelationship(Relationship::FOOTER),
853 aName );
854
856 "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml" );
857
858 pFS->startElementNS( XML_w, XML_ftr, MainXmlNamespaces());
859 }
860
861 // switch the serializer to redirect the output to word/styles.xml
862 m_pAttrOutput->SetSerializer( pFS );
863 m_pVMLExport->SetFS( pFS );
864 m_pSdrExport->setSerializer(pFS);
865 SetFS( pFS );
866 {
867 DocxTableExportContext aTableExportContext(*m_pAttrOutput);
868 // do the work
869 if (pFormat == nullptr)
871 else
872 WriteHeaderFooterText(*pFormat, bHeader);
873 m_pAttrOutput->EndParaSdtBlock();
874 }
875
876 // switch the serializer back
877 m_pAttrOutput->SetSerializer( m_pDocumentFS );
878 m_pVMLExport->SetFS( m_pDocumentFS );
879 m_pSdrExport->setSerializer(m_pDocumentFS);
881
882 // close the tag
883 sal_Int32 nReference;
884 if ( bHeader )
885 {
886 pFS->endElementNS( XML_w, XML_hdr );
887 nReference = XML_headerReference;
888 }
889 else
890 {
891 pFS->endElementNS( XML_w, XML_ftr );
892 nReference = XML_footerReference;
893 }
894
895 // and write the reference
896 m_pDocumentFS->singleElementNS( XML_w, nReference,
897 FSNS( XML_w, XML_type ), pType,
898 FSNS( XML_r, XML_id ), aRelId );
899
900 pFS->endDocument();
901}
902
904{
905 m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
906 oox::getRelationship(Relationship::FONTTABLE),
907 u"fontTable.xml" );
908
910 "word/fontTable.xml",
911 "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml" );
912
913 pFS->startElementNS( XML_w, XML_fonts,
914 FSNS( XML_xmlns, XML_w ), m_rFilter.getNamespaceURL(OOX_NS(doc)),
915 FSNS( XML_xmlns, XML_r ), m_rFilter.getNamespaceURL(OOX_NS(officeRel)) );
916
917 // switch the serializer to redirect the output to word/styles.xml
918 m_pAttrOutput->SetSerializer( pFS );
919
920 // do the work
922
923 // switch the serializer back
924 m_pAttrOutput->SetSerializer( m_pDocumentFS );
925
926 pFS->endElementNS( XML_w, XML_fonts );
927
928 pFS->endDocument();
929}
930
932{
933 // Write the core properties
934 SwDocShell* pDocShell( m_rDoc.GetDocShell( ) );
935 uno::Reference<document::XDocumentProperties> xDocProps;
936 bool bSecurityOptOpenReadOnly = false;
937 if ( pDocShell )
938 {
939 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
940 pDocShell->GetModel( ), uno::UNO_QUERY );
941 xDocProps = xDPS->getDocumentProperties();
942 bSecurityOptOpenReadOnly = pDocShell->IsSecurityOptOpenReadOnly();
943 }
944
945 m_rFilter.exportDocumentProperties( xDocProps, bSecurityOptOpenReadOnly );
946}
947
949{
950 SwDocShell* pDocShell = m_rDoc.GetDocShell();
951 if (!pDocShell)
952 {
953 return;
954 }
955
956 uno::Reference<text::XTextFieldsSupplier> xModel(pDocShell->GetModel(), uno::UNO_QUERY);
957 uno::Reference<container::XNameAccess> xTextFieldMasters = xModel->getTextFieldMasters();
958 uno::Sequence<rtl::OUString> aMasterNames = xTextFieldMasters->getElementNames();
959 if (!aMasterNames.hasElements())
960 {
961 return;
962 }
963
964 // Only write docVars if there will be at least a single docVar.
965 bool bStarted = false;
966 constexpr OUStringLiteral aPrefix(u"com.sun.star.text.fieldmaster.User.");
967 for (const auto& rMasterName : std::as_const(aMasterNames))
968 {
969 if (!rMasterName.startsWith(aPrefix))
970 {
971 // Not a user field.
972 continue;
973 }
974
975 uno::Reference<beans::XPropertySet> xField;
976 xTextFieldMasters->getByName(rMasterName) >>= xField;
977 if (!xField.is())
978 {
979 continue;
980 }
981
982 OUString aKey = rMasterName.copy(aPrefix.getLength());
983 OUString aValue;
984 xField->getPropertyValue("Content") >>= aValue;
985 if (!bStarted)
986 {
987 bStarted = true;
988 pFS->startElementNS(XML_w, XML_docVars);
989 }
990 pFS->singleElementNS(XML_w, XML_docVar, FSNS(XML_w, XML_name), aKey,
991 FSNS(XML_w, XML_val), aValue);
992 }
993
994 if (bStarted)
995 {
996 pFS->endElementNS(XML_w, XML_docVars);
997 }
998}
999
1000static auto
1002 sal_Int32 & rTargetCompatibilityMode) -> void
1003{
1004 const IDocumentSettingAccess& rIDSA = rDoc.getIDocumentSettingAccess();
1006 {
1007 rpFS->singleElementNS(XML_w, XML_noLeading);
1008 if (rTargetCompatibilityMode > 14)
1009 { // Word ignores noLeading in compatibilityMode 15
1010 rTargetCompatibilityMode = 14;
1011 }
1012 }
1013 // Do not justify lines with manual break
1015 {
1016 rpFS->singleElementNS(XML_w, XML_doNotExpandShiftReturn);
1017 }
1018 // tdf#146515 export "Use printer metrics for document formatting"
1020 rpFS->singleElementNS(XML_w, XML_usePrinterMetrics);
1021
1023 {
1024 // Map the DoNotBreakWrappedTables compat flag to <w:doNotBreakWrappedTables>.
1025 rpFS->singleElementNS(XML_w, XML_doNotBreakWrappedTables);
1026 }
1027}
1028
1030{
1032 if( !pViewShell && !m_aSettings.hasData() && !m_pAttrOutput->HasFootnotes() && !m_pAttrOutput->HasEndnotes())
1033 return;
1034
1035 SwDocShell* pDocShell = m_rDoc.GetDocShell();
1036
1037 m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
1038 oox::getRelationship(Relationship::SETTINGS),
1039 u"settings.xml" );
1040
1042 "word/settings.xml",
1043 "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml" );
1044
1045 pFS->startElementNS( XML_w, XML_settings,
1046 FSNS( XML_xmlns, XML_w ), m_rFilter.getNamespaceURL(OOX_NS(doc)) );
1047
1048 // Write protection
1049 const uno::Sequence<beans::PropertyValue> aInfo = pDocShell->GetModifyPasswordInfo();
1050 if (aInfo.hasElements())
1051 {
1052 OUString sAlgorithm, sSalt, sHash;
1053 sal_Int32 nCount = 0;
1054 for (const auto& prop : aInfo)
1055 {
1056 if (prop.Name == "algorithm-name")
1057 prop.Value >>= sAlgorithm;
1058 else if (prop.Name == "salt")
1059 prop.Value >>= sSalt;
1060 else if (prop.Name == "iteration-count")
1061 prop.Value >>= nCount;
1062 else if (prop.Name == "hash")
1063 prop.Value >>= sHash;
1064 }
1065 if (!sAlgorithm.isEmpty() && !sSalt.isEmpty() && !sHash.isEmpty())
1066 {
1067 sal_Int32 nAlgorithmSid = 0;
1068 if (sAlgorithm == "MD2")
1069 nAlgorithmSid = 1;
1070 else if (sAlgorithm == "MD4")
1071 nAlgorithmSid = 2;
1072 else if (sAlgorithm == "MD5")
1073 nAlgorithmSid = 3;
1074 else if (sAlgorithm == "SHA-1")
1075 nAlgorithmSid = 4;
1076 else if (sAlgorithm == "MAC")
1077 nAlgorithmSid = 5;
1078 else if (sAlgorithm == "RIPEMD")
1079 nAlgorithmSid = 6;
1080 else if (sAlgorithm == "RIPEMD-160")
1081 nAlgorithmSid = 7;
1082 else if (sAlgorithm == "HMAC")
1083 nAlgorithmSid = 9;
1084 else if (sAlgorithm == "SHA-256")
1085 nAlgorithmSid = 12;
1086 else if (sAlgorithm == "SHA-384")
1087 nAlgorithmSid = 13;
1088 else if (sAlgorithm == "SHA-512")
1089 nAlgorithmSid = 14;
1090
1091 if (nAlgorithmSid != 0)
1092 pFS->singleElementNS(XML_w, XML_writeProtection,
1093 FSNS(XML_w, XML_cryptProviderType), "rsaAES",
1094 FSNS(XML_w, XML_cryptAlgorithmClass), "hash",
1095 FSNS(XML_w, XML_cryptAlgorithmType), "typeAny",
1096 FSNS(XML_w, XML_cryptAlgorithmSid), OString::number(nAlgorithmSid),
1097 FSNS(XML_w, XML_cryptSpinCount), OString::number(nCount),
1098 FSNS(XML_w, XML_hash), sHash,
1099 FSNS(XML_w, XML_salt), sSalt);
1100 }
1101 }
1102
1103 // View
1104 if (pViewShell && pViewShell->GetViewOptions()->getBrowseMode())
1105 {
1106 pFS->singleElementNS(XML_w, XML_view, FSNS(XML_w, XML_val), "web");
1107 }
1108
1109 // Zoom
1110 if (pViewShell)
1111 {
1114
1115 switch (pViewShell->GetViewOptions()->GetZoomType())
1116 {
1117 case SvxZoomType::WHOLEPAGE:
1118 pAttributeList->add(FSNS(XML_w, XML_val), "fullPage");
1119 break;
1120 case SvxZoomType::PAGEWIDTH:
1121 pAttributeList->add(FSNS(XML_w, XML_val), "bestFit");
1122 break;
1123 case SvxZoomType::OPTIMAL:
1124 pAttributeList->add(FSNS(XML_w, XML_val), "textFit");
1125 break;
1126 default:
1127 break;
1128 }
1129
1130 OString aZoom(OString::number(pViewShell->GetViewOptions()->GetZoom()));
1131 pAttributeList->add(FSNS(XML_w, XML_percent), aZoom);
1132 pFS->singleElementNS(XML_w, XML_zoom, pAttributeList);
1133 }
1134
1135 // Display Background Shape
1136 if (std::unique_ptr<SvxBrushItem> oBrush = getBackground(); oBrush)
1137 {
1138 // Turn on the 'displayBackgroundShape'
1139 pFS->singleElementNS(XML_w, XML_displayBackgroundShape);
1140 }
1141
1142 // Track Changes
1144 pFS->singleElementNS( XML_w, XML_revisionView,
1145 FSNS( XML_w, XML_insDel ), "0",
1146 FSNS( XML_w, XML_formatting ), "0" );
1147
1149 pFS->singleElementNS(XML_w, XML_trackRevisions);
1150
1151 // Mirror Margins
1152 if(isMirroredMargin())
1153 pFS->singleElementNS(XML_w, XML_mirrorMargins);
1154
1156 {
1157 pFS->singleElementNS(XML_w, XML_gutterAtTop);
1158 }
1159
1160 // Embed Fonts
1162 pFS->singleElementNS(XML_w, XML_embedTrueTypeFonts);
1163
1164 // Embed System Fonts
1166 pFS->singleElementNS(XML_w, XML_embedSystemFonts);
1167
1168 // Default Tab Stop
1169 if( m_aSettings.defaultTabStop != 0 )
1170 pFS->singleElementNS( XML_w, XML_defaultTabStop, FSNS( XML_w, XML_val ),
1171 OString::number(m_aSettings.defaultTabStop) );
1172
1173 // export current mail merge database and table names
1175 if ( !aData.sDataSource.isEmpty() && aData.nCommandType == css::sdb::CommandType::TABLE && !aData.sCommand.isEmpty() )
1176 {
1177 OUString sDataSource =
1178 "SELECT * FROM " +
1179 aData.sDataSource + // current database
1180 ".dbo." + // default database owner
1181 aData.sCommand + // sheet name
1182 "$"; // sheet identifier
1183 pFS->startElementNS( XML_w, XML_mailMerge );
1184 pFS->singleElementNS(XML_w, XML_mainDocumentType,
1185 FSNS( XML_w, XML_val ), "formLetters" );
1186 pFS->singleElementNS(XML_w, XML_dataType,
1187 FSNS( XML_w, XML_val ), "textFile" );
1188 pFS->singleElementNS( XML_w, XML_query,
1189 FSNS( XML_w, XML_val ), sDataSource );
1190 pFS->endElementNS( XML_w, XML_mailMerge );
1191 }
1192
1193 // Automatic hyphenation: it's a global setting in Word, it's a paragraph setting in Writer.
1194 // Set it's value to "auto" and disable on paragraph level, if no hyphenation is used there.
1195 pFS->singleElementNS(XML_w, XML_autoHyphenation, FSNS(XML_w, XML_val), "true");
1196
1197 // Hyphenation details set depending on default style
1199 const SvxHyphenZoneItem* pZoneItem;
1200 if (pColl && (pZoneItem = pColl->GetItemIfSet(RES_PARATR_HYPHENZONE, false)))
1201 {
1202 if (pZoneItem->IsNoCapsHyphenation())
1203 pFS->singleElementNS(XML_w, XML_doNotHyphenateCaps);
1204
1205 if ( sal_Int16 nHyphenZone = pZoneItem->GetTextHyphenZone() )
1206 pFS->singleElementNS(XML_w, XML_hyphenationZone, FSNS(XML_w, XML_val),
1207 OString::number(nHyphenZone));
1208 }
1209
1210 // Even and Odd Headers
1212 pFS->singleElementNS(XML_w, XML_evenAndOddHeaders);
1213
1214 // Has Footnotes
1215 if( m_pAttrOutput->HasFootnotes())
1216 DocxAttributeOutput::WriteFootnoteEndnotePr( pFS, XML_footnotePr, m_rDoc.GetFootnoteInfo(), XML_footnote );
1217
1218 // Has Endnotes
1219 if( m_pAttrOutput->HasEndnotes())
1220 DocxAttributeOutput::WriteFootnoteEndnotePr( pFS, XML_endnotePr, m_rDoc.GetEndNoteInfo(), XML_endnote );
1221
1222 // Has themeFontLang information
1223 uno::Reference< beans::XPropertySet > xPropSet( pDocShell->GetBaseModel(), uno::UNO_QUERY_THROW );
1224
1225 bool bUseGrabBagProtection = false;
1226 bool bWriterWantsToProtect = false;
1227 bool bWriterWantsToProtectForm = false;
1228 bool bWriterWantsToProtectRedline = false;
1229 bool bHasDummyRedlineProtectionKey = false;
1230 bool bReadOnlyStatusUnchanged = true;
1231 uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1233 m_pSections->DocumentIsProtected() )
1234 {
1235 bWriterWantsToProtect = bWriterWantsToProtectForm = true;
1236 }
1237 if ( xPropSetInfo->hasPropertyByName( "RedlineProtectionKey" ) )
1238 {
1239 uno::Sequence<sal_Int8> aKey;
1240 xPropSet->getPropertyValue( "RedlineProtectionKey" ) >>= aKey;
1241 bool bHasRedlineProtectionKey = aKey.hasElements();
1242 bHasDummyRedlineProtectionKey = aKey.getLength() == 1 && aKey[0] == 1;
1243 if ( bHasRedlineProtectionKey && !bHasDummyRedlineProtectionKey )
1244 bWriterWantsToProtect = bWriterWantsToProtectRedline = true;
1245 }
1246
1247 /* Compatibility Mode (tdf#131304)
1248 * 11: .doc level [Word 97-2003]
1249 * 12: .docx default [Word 2007] [LO < 7.0] [ECMA 376 1st ed.]
1250 * 14: [Word 2010]
1251 * 15: [Word 2013/2016/2019] [LO >= 7.0]
1252 *
1253 * The PRIMARY purpose of compatibility mode does not seem to be related to layout etc.
1254 * Its focus is on sharing files between multiple users, tracking the lowest supported mode in the group.
1255 * It is to BENEFIT older programs by not using certain new features that they don't understand.
1256 *
1257 * The next time the compat mode needs to be changed, I foresee the following steps:
1258 * 1.) Accept the new mode: Start round-tripping the new value, indicating we understand that format.
1259 * 2.) Many years later, change the TargetCompatilityMode for new documents, when we no longer care
1260 * about working with perfect compatibility with older versions of MS Word.
1261 */
1262 sal_Int32 nTargetCompatibilityMode =
1264 ? 12 : 15; //older versions might not open our files well
1265 bool bHasCompatibilityMode = false;
1266 const OUString aGrabBagName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
1267 if ( xPropSetInfo->hasPropertyByName( aGrabBagName ) )
1268 {
1269 uno::Sequence< beans::PropertyValue > propList;
1270 xPropSet->getPropertyValue( aGrabBagName ) >>= propList;
1271
1272 for( const auto& rProp : std::as_const(propList) )
1273 {
1274 if ( rProp.Name == "ThemeFontLangProps" )
1275 {
1276 uno::Sequence< beans::PropertyValue > themeFontLangProps;
1277 rProp.Value >>= themeFontLangProps;
1278 OUString aValues[3];
1279 for( const auto& rThemeFontLangProp : std::as_const(themeFontLangProps) )
1280 {
1281 if( rThemeFontLangProp.Name == "val" )
1282 rThemeFontLangProp.Value >>= aValues[0];
1283 else if( rThemeFontLangProp.Name == "eastAsia" )
1284 rThemeFontLangProp.Value >>= aValues[1];
1285 else if( rThemeFontLangProp.Name == "bidi" )
1286 rThemeFontLangProp.Value >>= aValues[2];
1287 }
1288 pFS->singleElementNS( XML_w, XML_themeFontLang,
1289 FSNS( XML_w, XML_val ), aValues[0],
1290 FSNS( XML_w, XML_eastAsia ), aValues[1],
1291 FSNS( XML_w, XML_bidi ), aValues[2] );
1292 }
1293 else if ( rProp.Name == "CompatSettings" )
1294 {
1295 pFS->startElementNS(XML_w, XML_compat);
1296
1297 WriteCompat(m_rDoc, pFS, nTargetCompatibilityMode);
1298
1299 uno::Sequence< beans::PropertyValue > aCompatSettingsSequence;
1300 rProp.Value >>= aCompatSettingsSequence;
1301
1302 for(const auto& rCompatSetting : std::as_const(aCompatSettingsSequence))
1303 {
1304 uno::Sequence< beans::PropertyValue > aCompatSetting;
1305 rCompatSetting.Value >>= aCompatSetting;
1306 OUString aName;
1307 OUString aUri;
1308 OUString aValue;
1309
1310 for(const auto& rPropVal : std::as_const(aCompatSetting))
1311 {
1312 if( rPropVal.Name == "name" )
1313 rPropVal.Value >>= aName;
1314 else if( rPropVal.Name == "uri" )
1315 rPropVal.Value >>= aUri;
1316 else if( rPropVal.Name == "val" )
1317 rPropVal.Value >>= aValue;
1318 }
1319 if ( aName == "compatibilityMode" )
1320 {
1321 bHasCompatibilityMode = true;
1322 // Among the group of programs sharing this document, the lowest mode is retained.
1323 // Reduce this number if we are not comfortable with the new/unknown mode yet.
1324 // Step 1 in accepting a new mode would be to comment out the following clause
1325 // and roundtrip the new value instead of overwriting with the older number.
1326 // There are no newer modes at the time this code was written.
1327 if ( aValue.toInt32() > nTargetCompatibilityMode )
1328 aValue = OUString::number(nTargetCompatibilityMode);
1329 }
1330
1331 pFS->singleElementNS( XML_w, XML_compatSetting,
1332 FSNS( XML_w, XML_name ), aName,
1333 FSNS( XML_w, XML_uri ), aUri,
1334 FSNS( XML_w, XML_val ), aValue);
1335 }
1336
1337 if ( !bHasCompatibilityMode )
1338 {
1339 pFS->singleElementNS( XML_w, XML_compatSetting,
1340 FSNS( XML_w, XML_name ), "compatibilityMode",
1341 FSNS( XML_w, XML_uri ), "http://schemas.microsoft.com/office/word",
1342 FSNS( XML_w, XML_val ), OString::number(nTargetCompatibilityMode));
1343 bHasCompatibilityMode = true;
1344 }
1345
1346 pFS->endElementNS( XML_w, XML_compat );
1347 }
1348 else if (rProp.Name == "DocumentProtection")
1349 {
1350 uno::Sequence< beans::PropertyValue > rAttributeList;
1351 rProp.Value >>= rAttributeList;
1352
1353 if (rAttributeList.hasElements())
1354 {
1356 bool bIsProtectionTrackChanges = false;
1357 // if grabbag protection is not enforced, allow Writer protection to override
1358 bool bEnforced = false;
1359 for (const auto& rAttribute : std::as_const(rAttributeList))
1360 {
1361 static DocxStringTokenMap const aTokens[] =
1362 {
1363 { "edit", XML_edit },
1364 { "enforcement", XML_enforcement },
1365 { "formatting", XML_formatting },
1366 { "cryptProviderType", XML_cryptProviderType },
1367 { "cryptAlgorithmClass", XML_cryptAlgorithmClass },
1368 { "cryptAlgorithmType", XML_cryptAlgorithmType },
1369 { "cryptAlgorithmSid", XML_cryptAlgorithmSid },
1370 { "cryptSpinCount", XML_cryptSpinCount },
1371 { "hash", XML_hash },
1372 { "salt", XML_salt },
1373 { nullptr, 0 }
1374 };
1375
1376 if (sal_Int32 nToken = DocxStringGetToken(aTokens, rAttribute.Name))
1377 {
1378 OUString sValue = rAttribute.Value.get<OUString>();
1379 xAttributeList->add(FSNS(XML_w, nToken), sValue.toUtf8());
1380 if ( nToken == XML_edit && sValue == "trackedChanges" )
1381 bIsProtectionTrackChanges = true;
1382 else if ( nToken == XML_edit && sValue == "readOnly" )
1383 {
1384 // Ignore the case where read-only was not enforced, but now is. That is handled by _MarkAsFinal
1385 bReadOnlyStatusUnchanged = pDocShell->IsSecurityOptOpenReadOnly();
1386 }
1387 else if ( nToken == XML_enforcement )
1388 bEnforced = sValue.toBoolean();
1389 }
1390 }
1391
1392 // we have document protection from input DOCX file
1393 if ( !bEnforced )
1394 {
1395 // Leave as an un-enforced suggestion if Writer doesn't want to set any enforcement
1396 bUseGrabBagProtection = !bWriterWantsToProtect;
1397 }
1398 else
1399 {
1400 // Check if the grabbag protection is still valid
1401 // In the case of change tracking protection, we didn't modify it
1402 // and in the case of read-only, we didn't modify it.
1403 bUseGrabBagProtection = (!bIsProtectionTrackChanges || bHasDummyRedlineProtectionKey)
1404 && bReadOnlyStatusUnchanged;
1405 }
1406
1407 if ( bUseGrabBagProtection )
1408 {
1409 pFS->singleElementNS(XML_w, XML_documentProtection, xAttributeList);
1410 }
1411
1412 }
1413 }
1414 else if (rProp.Name == "HyphenationZone")
1415 {
1416 sal_Int16 nHyphenationZone = *o3tl::doAccess<sal_Int16>(rProp.Value);
1417 if (nHyphenationZone > 0)
1418 pFS->singleElementNS(XML_w, XML_hyphenationZone, FSNS(XML_w, XML_val),
1419 OString::number(nHyphenationZone));
1420 }
1421 }
1422 }
1423 if ( !bHasCompatibilityMode )
1424 {
1425 pFS->startElementNS(XML_w, XML_compat);
1426
1427 WriteCompat(m_rDoc, pFS, nTargetCompatibilityMode);
1428
1429 pFS->singleElementNS( XML_w, XML_compatSetting,
1430 FSNS( XML_w, XML_name ), "compatibilityMode",
1431 FSNS( XML_w, XML_uri ), "http://schemas.microsoft.com/office/word",
1432 FSNS( XML_w, XML_val ), OString::number(nTargetCompatibilityMode));
1433 pFS->endElementNS( XML_w, XML_compat );
1434 }
1435
1436 WriteDocVars(pFS);
1437
1438 if ( !bUseGrabBagProtection )
1439 {
1440 // Protect form - highest priority
1441 // Section-specific write protection
1442 if ( bWriterWantsToProtectForm )
1443 {
1444 // we have form protection from Writer or from input ODT file
1445
1446 pFS->singleElementNS(XML_w, XML_documentProtection,
1447 FSNS(XML_w, XML_edit), "forms",
1448 FSNS(XML_w, XML_enforcement), "true");
1449 }
1450 // Protect Change Tracking - next priority
1451 else if ( bWriterWantsToProtectRedline )
1452 {
1453 // we have change tracking protection from Writer or from input ODT file
1454
1455 pFS->singleElementNS(XML_w, XML_documentProtection,
1456 FSNS(XML_w, XML_edit), "trackedChanges",
1457 FSNS(XML_w, XML_enforcement), "1");
1458 }
1459 }
1460
1461 // finish settings.xml
1462 pFS->endElementNS( XML_w, XML_settings );
1463
1464 pFS->endDocument();
1465}
1466
1468{
1469 uno::Reference< beans::XPropertySet > xPropSet( m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1470
1471 uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1473 if ( !xPropSetInfo->hasPropertyByName( aName ) )
1474 return;
1475
1476 uno::Reference<xml::dom::XDocument> themeDom;
1477 uno::Sequence< beans::PropertyValue > propList;
1478 xPropSet->getPropertyValue( aName ) >>= propList;
1479 auto pProp = std::find_if(std::cbegin(propList), std::cend(propList),
1480 [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXTheme"; });
1481 if (pProp != std::cend(propList))
1482 pProp->Value >>= themeDom;
1483
1484 // no theme dom to write
1485 if ( !themeDom.is() )
1486 return;
1487
1488 m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
1489 oox::getRelationship(Relationship::THEME),
1490 u"theme/theme1.xml" );
1491
1492 uno::Reference< xml::sax::XSAXSerializable > serializer( themeDom, uno::UNO_QUERY );
1493 uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() );
1494 writer->setOutputStream( GetFilter().openFragmentStream( "word/theme/theme1.xml",
1495 "application/vnd.openxmlformats-officedocument.theme+xml" ) );
1496 serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1497 uno::Sequence< beans::StringPair >() );
1498}
1499
1500// See OOXMLDocumentImpl::resolveGlossaryStream
1502{
1503 uno::Reference< beans::XPropertySet > xPropSet( m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1504
1505 uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1507 if ( !xPropSetInfo->hasPropertyByName( aName ) )
1508 return;
1509
1510 uno::Reference<xml::dom::XDocument> glossaryDocDom;
1511 uno::Sequence< uno::Sequence<beans::NamedValue> > glossaryDomList;
1512 uno::Sequence< beans::PropertyValue > propList;
1513 xPropSet->getPropertyValue( aName ) >>= propList;
1514 sal_Int32 collectedProperties = 0;
1515 for ( const auto& rProp : std::as_const(propList) )
1516 {
1517 OUString propName = rProp.Name;
1518 if ( propName == "OOXGlossary" )
1519 {
1520 rProp.Value >>= glossaryDocDom;
1521 collectedProperties++;
1522 }
1523 if (propName == "OOXGlossaryDom")
1524 {
1525 rProp.Value >>= glossaryDomList;
1526 collectedProperties++;
1527 }
1528 if (collectedProperties == 2)
1529 break;
1530 }
1531
1532 // no glossary dom to write
1533 if ( !glossaryDocDom.is() )
1534 return;
1535
1536 m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
1537 oox::getRelationship(Relationship::GLOSSARYDOCUMENT),
1538 u"glossary/document.xml" );
1539
1540 uno::Reference< io::XOutputStream > xOutputStream = GetFilter().openFragmentStream( "word/glossary/document.xml",
1541 "application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml" );
1542
1543 uno::Reference< xml::sax::XSAXSerializable > serializer( glossaryDocDom, uno::UNO_QUERY );
1544 uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() );
1545 writer->setOutputStream( xOutputStream );
1546 serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1547 uno::Sequence< beans::StringPair >() );
1548
1549 for (const uno::Sequence<beans::NamedValue>& glossaryElement : glossaryDomList)
1550 {
1551 OUString gTarget, gType, gId, contentType, targetMode;
1552 uno::Reference<xml::dom::XDocument> xDom;
1553 for (const auto& [name, value] : glossaryElement)
1554 {
1555 if (name == "Id")
1556 value >>= gId;
1557 else if (name == "Type")
1558 value >>= gType;
1559 else if (name == "Target")
1560 value >>= gTarget;
1561 else if (name == "TargetMode")
1562 value >>= targetMode;
1563 else if (name == "_contentType")
1564 value >>= contentType;
1565 else if (name == "_relDom")
1566 value >>= xDom;
1567 }
1568 if (gId.isEmpty() || gType.isEmpty() || gTarget.isEmpty())
1569 continue;
1570 const bool bExternal = targetMode == "External";
1571 if (!bExternal && !xDom)
1572 {
1573 // Some internal relation, but we didn't create a DOM for it
1574 // in OOXMLDocumentImpl::resolveGlossaryStream?
1575 SAL_WARN("sw.ww8", "Glossary internal relation without DOM: Id=\"" + gId
1576 + "\" Type=\"" + gType + "\" Target=\"" + gTarget + "\"");
1577 continue;
1578 }
1579 gId = gId.copy(3); //"rId" only save the numeric value
1580
1581 PropertySet aProps(xOutputStream);
1582 aProps.setAnyProperty( PROP_RelId, uno::Any( gId.toInt32() ));
1583 m_rFilter.addRelation(xOutputStream, gType, gTarget, bExternal);
1584 if (!xDom)
1585 continue; // External relation, no stream to write
1586 uno::Reference< xml::sax::XSAXSerializable > gserializer( xDom, uno::UNO_QUERY );
1587 writer->setOutputStream(GetFilter().openFragmentStream( "word/glossary/" + gTarget, contentType ) );
1588 gserializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1589 uno::Sequence< beans::StringPair >() );
1590 }
1591}
1592
1593namespace {
1594 class XsltTransformListener : public ::cppu::WeakImplHelper<io::XStreamListener>
1595 {
1596 public:
1597 XsltTransformListener() : m_bDone(false) {}
1598
1599 void wait() {
1600 std::unique_lock<std::mutex> g(m_mutex);
1601 m_cond.wait(g, [this]() { return m_bDone; });
1602 }
1603
1604 private:
1605 std::mutex m_mutex;
1606 std::condition_variable m_cond;
1607 bool m_bDone;
1608
1609 virtual void SAL_CALL disposing(const lang::EventObject&) noexcept override {}
1610 virtual void SAL_CALL started() noexcept override {}
1611 virtual void SAL_CALL closed() noexcept override { notifyDone(); }
1612 virtual void SAL_CALL terminated() noexcept override { notifyDone(); }
1613 virtual void SAL_CALL error(const uno::Any& e) override
1614 {
1615 notifyDone(); // set on error too, otherwise main thread waits forever
1616 SAL_WARN("sw.ww8", e);
1617 }
1618
1619 void notifyDone() {
1620 std::scoped_lock<std::mutex> g(m_mutex);
1621 m_bDone = true;
1622 m_cond.notify_all();
1623 }
1624 };
1625}
1626
1627static void lcl_UpdateXmlValues(const SdtData& sdtData, const uno::Reference<css::io::XInputStream>& xInputStream, const uno::Reference<css::io::XOutputStream>& xOutputStream)
1628{
1629 uno::Sequence<uno::Any> aArgs{
1630 // XSLT transformation stylesheet:
1631 // - write all elements as is
1632 // - but if element matches sdtData.xpath, replace its text content by sdtData.xpath
1633 uno::Any(beans::NamedValue("StylesheetText", uno::Any(OUString("<?xml version=\"1.0\" encoding=\"UTF-8\"?> \
1634<xsl:stylesheet\
1635 xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\
1636 " + sdtData.namespaces + "\
1637 version=\"1.0\">\
1638 <xsl:template match=\"@* | node()\">\
1639 <xsl:copy>\
1640 <xsl:apply-templates select=\"@* | node()\"/>\
1641 </xsl:copy>\
1642 </xsl:template>\
1643 <xsl:template match = \"" + sdtData.xpath + "\">\
1644 <xsl:copy>\
1645 <xsl:text>" + sdtData.data + "</xsl:text>\
1646 </xsl:copy>\
1647 </xsl:template>\
1648</xsl:stylesheet>\
1649"))))
1650 };
1651
1652 css::uno::Reference<css::xml::xslt::XXSLTTransformer> xTransformer =
1653 css::xml::xslt::XSLTTransformer::create(comphelper::getProcessComponentContext(), aArgs);
1654 xTransformer->setInputStream(xInputStream);
1655 xTransformer->setOutputStream(xOutputStream);
1656
1657 rtl::Reference<XsltTransformListener> xListener = new XsltTransformListener();
1658 xTransformer->addListener(xListener);
1659
1660 xTransformer->start();
1661 xListener->wait();
1662}
1663
1665{
1666 uno::Reference< beans::XPropertySet > xPropSet( m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1667
1668 uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1669 if ( !xPropSetInfo->hasPropertyByName( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) )
1670 return;
1671
1672 uno::Sequence<uno::Reference<xml::dom::XDocument> > customXmlDomlist;
1673 uno::Sequence<uno::Reference<xml::dom::XDocument> > customXmlDomPropslist;
1674 uno::Sequence< beans::PropertyValue > propList;
1675 xPropSet->getPropertyValue( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) >>= propList;
1676 auto pProp = std::find_if(std::cbegin(propList), std::cend(propList),
1677 [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXCustomXml"; });
1678 if (pProp != std::cend(propList))
1679 pProp->Value >>= customXmlDomlist;
1680
1681 pProp = std::find_if(std::cbegin(propList), std::cend(propList),
1682 [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXCustomXmlProps"; });
1683 if (pProp != std::cend(propList))
1684 pProp->Value >>= customXmlDomPropslist;
1685
1686 for (sal_Int32 j = 0; j < customXmlDomlist.getLength(); j++)
1687 {
1688 uno::Reference<xml::dom::XDocument> customXmlDom = customXmlDomlist[j];
1689 uno::Reference<xml::dom::XDocument> customXmlDomProps = customXmlDomPropslist[j];
1690 if (customXmlDom.is())
1691 {
1692 m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
1693 oox::getRelationship(Relationship::CUSTOMXML),
1694 Concat2View("../customXml/item"+OUString::number(j+1)+".xml" ));
1695
1696 uno::Reference< xml::sax::XSAXSerializable > serializer( customXmlDom, uno::UNO_QUERY );
1697 uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() );
1698
1699 uno::Reference < css::io::XOutputStream > xOutStream = GetFilter().openFragmentStream("customXml/item" + OUString::number(j + 1) + ".xml",
1700 "application/xml");
1701 if (m_SdtData.size())
1702 {
1703 // There are some SDT blocks data with data bindings which can update some custom xml values
1704 uno::Reference< io::XStream > xMemStream(
1705 comphelper::getProcessComponentContext()->getServiceManager()->createInstanceWithContext("com.sun.star.comp.MemoryStream",
1707 uno::UNO_QUERY_THROW);
1708
1709 writer->setOutputStream(xMemStream->getOutputStream());
1710
1711 serializer->serialize(uno::Reference< xml::sax::XDocumentHandler >(writer, uno::UNO_QUERY_THROW),
1712 uno::Sequence< beans::StringPair >());
1713
1714 uno::Reference< io::XStream > xXSLTInStream = xMemStream;
1715 uno::Reference< io::XStream > xXSLTOutStream;
1716 // Apply XSLT transformations for each SDT data binding
1717 // Seems it is not possible to do this as one transformation: each data binding
1718 // can have different namespaces, but with conflicting names (ns0, ns1, etc..)
1719 for (size_t i = 0; i < m_SdtData.size(); i++)
1720 {
1721 if (i == m_SdtData.size() - 1)
1722 {
1723 // last transformation
1724 lcl_UpdateXmlValues(m_SdtData[i], xXSLTInStream->getInputStream(), xOutStream);
1725 }
1726 else
1727 {
1728 xXSLTOutStream.set(
1729 comphelper::getProcessComponentContext()->getServiceManager()->createInstanceWithContext("com.sun.star.comp.MemoryStream",
1731 uno::UNO_QUERY_THROW);
1732 lcl_UpdateXmlValues(m_SdtData[i], xXSLTInStream->getInputStream(), xXSLTOutStream->getOutputStream());
1733 // Use previous output as an input for next run
1734 xXSLTInStream.set( xXSLTOutStream );
1735 }
1736 }
1737
1738 }
1739 else
1740 {
1741 writer->setOutputStream(xOutStream);
1742
1743 serializer->serialize(uno::Reference< xml::sax::XDocumentHandler >(writer, uno::UNO_QUERY_THROW),
1744 uno::Sequence< beans::StringPair >());
1745 }
1746 }
1747
1748 if (customXmlDomProps.is())
1749 {
1750 uno::Reference< xml::sax::XSAXSerializable > serializer( customXmlDomProps, uno::UNO_QUERY );
1751 uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() );
1752 writer->setOutputStream( GetFilter().openFragmentStream( "customXml/itemProps"+OUString::number(j+1)+".xml",
1753 "application/vnd.openxmlformats-officedocument.customXmlProperties+xml" ) );
1754 serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
1755 uno::Sequence< beans::StringPair >() );
1756
1757 // Adding itemprops's relationship entry to item.xml.rels file
1758 m_rFilter.addRelation( GetFilter().openFragmentStream( "customXml/item"+OUString::number(j+1)+".xml",
1759 "application/xml" ) ,
1760 oox::getRelationship(Relationship::CUSTOMXMLPROPS),
1761 Concat2View("itemProps"+OUString::number(j+1)+".xml" ));
1762 }
1763 }
1764}
1765
1767{
1768 uno::Reference<document::XStorageBasedDocument> xStorageBasedDocument(m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
1769 if (!xStorageBasedDocument.is())
1770 return;
1771
1772 uno::Reference<embed::XStorage> xDocumentStorage = xStorageBasedDocument->getDocumentStorage();
1773 OUString aMacrosName("_MS_VBA_Macros");
1774 if (!xDocumentStorage.is() || !xDocumentStorage->hasByName(aMacrosName))
1775 return;
1776
1777 const sal_Int32 nOpenMode = embed::ElementModes::READ;
1778 uno::Reference<io::XStream> xMacrosStream = xDocumentStorage->openStreamElement(aMacrosName, nOpenMode);
1779 uno::Reference<io::XOutputStream> xProjectStream;
1780 if (xMacrosStream.is())
1781 {
1782 // First handle the project stream, this sets xProjectStream.
1783 std::unique_ptr<SvStream> pIn(utl::UcbStreamHelper::CreateStream(xMacrosStream));
1784
1785 xProjectStream = GetFilter().openFragmentStream("word/vbaProject.bin", "application/vnd.ms-office.vbaProject");
1786 uno::Reference<io::XStream> xOutputStream(xProjectStream, uno::UNO_QUERY);
1787 if (!xOutputStream.is())
1788 return;
1789 std::unique_ptr<SvStream> pOut(utl::UcbStreamHelper::CreateStream(xOutputStream));
1790
1791 // Write the stream.
1792 pOut->WriteStream(*pIn);
1793
1794 // Write the relationship.
1795 m_rFilter.addRelation(m_pDocumentFS->getOutputStream(), oox::getRelationship(Relationship::VBAPROJECT), u"vbaProject.bin");
1796 }
1797
1798 OUString aDataName("_MS_VBA_Macros_XML");
1799 if (!xDocumentStorage.is() || !xDocumentStorage->hasByName(aDataName))
1800 return;
1801
1802 uno::Reference<io::XStream> xDataStream = xDocumentStorage->openStreamElement(aDataName, nOpenMode);
1803 if (!xDataStream.is())
1804 return;
1805
1806 // Then the data stream, which wants to work with an already set
1807 // xProjectStream.
1808 std::unique_ptr<SvStream> pIn(utl::UcbStreamHelper::CreateStream(xDataStream));
1809
1810 uno::Reference<io::XStream> xOutputStream(GetFilter().openFragmentStream("word/vbaData.xml", "application/vnd.ms-word.vbaData+xml"), uno::UNO_QUERY);
1811 if (!xOutputStream.is())
1812 return;
1813 std::unique_ptr<SvStream> pOut(utl::UcbStreamHelper::CreateStream(xOutputStream));
1814
1815 // Write the stream.
1816 pOut->WriteStream(*pIn);
1817
1818 // Write the relationship.
1819 if (!xProjectStream.is())
1820 return;
1821
1822 m_rFilter.addRelation(xProjectStream, oox::getRelationship(Relationship::WORDVBADATA), u"vbaData.xml");
1823}
1824
1826{
1827 uno::Reference< beans::XPropertySet > xPropSet( m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
1828
1829 uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1831 if ( !xPropSetInfo->hasPropertyByName( aName ) )
1832 return;
1833
1834 uno::Sequence< beans::PropertyValue > embeddingsList;
1835 uno::Sequence< beans::PropertyValue > propList;
1836 xPropSet->getPropertyValue( aName ) >>= propList;
1837 auto pProp = std::find_if(std::cbegin(propList), std::cend(propList),
1838 [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXEmbeddings"; });
1839 if (pProp != std::cend(propList))
1840 pProp->Value >>= embeddingsList;
1841 for (const auto& rEmbedding : std::as_const(embeddingsList))
1842 {
1843 OUString embeddingPath = rEmbedding.Name;
1844 uno::Reference<io::XInputStream> embeddingsStream;
1845 rEmbedding.Value >>= embeddingsStream;
1846 if (!embeddingsStream)
1847 continue;
1848
1849 OUString contentType;
1850 if (css::uno::Reference<css::beans::XPropertySet> xProps{ embeddingsStream,
1851 css::uno::UNO_QUERY })
1852 {
1853 try
1854 {
1855 const css::uno::Any val = xProps->getPropertyValue("MediaType");
1856 val >>= contentType;
1857 }
1858 catch (const css::beans::UnknownPropertyException&)
1859 {
1860 TOOLS_WARN_EXCEPTION("sw.ww8", "WriteEmbeddings: Embedding without MediaType");
1861 }
1862 }
1863
1864 if (contentType.isEmpty())
1865 {
1866 // FIXME: this .xlsm hack is silly - if anything the mime-type for an existing embedded object should be read from [Content_Types].xml
1867 if (embeddingPath.endsWith(".xlsm"))
1868 contentType = "application/vnd.ms-excel.sheet.macroEnabled.12";
1869 else if (embeddingPath.endsWith(".bin"))
1870 contentType = "application/vnd.openxmlformats-officedocument.oleObject";
1871 else
1872 contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
1873 }
1874
1875 uno::Reference< io::XOutputStream > xOutStream = GetFilter().openFragmentStream(embeddingPath,
1876 contentType);
1877 try
1878 {
1879 // tdf#131288: the stream must be seekable for direct access
1880 uno::Reference<io::XSeekable> xSeekable(embeddingsStream, uno::UNO_QUERY);
1881 if (xSeekable)
1882 xSeekable->seek(0); // tdf#131288: a previous save could position it elsewhere
1883 comphelper::OStorageHelper::CopyInputToOutput(embeddingsStream, xOutStream);
1884 }
1885 catch(const uno::Exception&)
1886 {
1887 TOOLS_WARN_EXCEPTION("sw.ww8", "WriteEmbeddings() ::Failed to copy Inputstream to outputstream exception caught");
1888 }
1889 xOutStream->closeOutput();
1890 }
1891}
1892
1894{
1895 bool bMirroredMargins = false;
1897 {
1898 bMirroredMargins = true;
1899 }
1900 return bMirroredMargins;
1901}
1902
1904{
1905 // setup the namespaces
1906 m_pDocumentFS->startElementNS( XML_w, XML_document, MainXmlNamespaces());
1907
1908 // reset the incrementing linked-textboxes chain ID before re-saving.
1911
1912 // Write background page color
1913 if (std::unique_ptr<SvxBrushItem> oBrush = getBackground(); oBrush)
1914 {
1915 Color backgroundColor = oBrush->GetColor();
1916 OString aBackgroundColorStr = msfilter::util::ConvertColor(backgroundColor);
1917
1918 m_pDocumentFS->singleElementNS(XML_w, XML_background, FSNS(XML_w, XML_color),
1919 aBackgroundColorStr);
1920 }
1921
1922 // body
1923 m_pDocumentFS->startElementNS(XML_w, XML_body);
1924
1925 m_pCurPam->GetPoint()->Assign(*m_rDoc.GetNodes().GetEndOfContent().StartOfSectionNode());
1926
1927 // the text
1928 WriteText();
1929
1930 // clear linked textboxes since old ones can't be linked to frames in a different section (correct?)
1932
1933 // the last section info
1934 m_pAttrOutput->EndParaSdtBlock();
1935 const WW8_SepInfo *pSectionInfo = m_pSections? m_pSections->CurrentSectionInfo(): nullptr;
1936 if ( pSectionInfo )
1937 SectionProperties( *pSectionInfo );
1938
1939 // finish body and document
1940 m_pDocumentFS->endElementNS( XML_w, XML_body );
1941 m_pDocumentFS->endElementNS( XML_w, XML_document );
1942}
1943
1945{
1946 rtl::Reference<FastAttributeList> pAttr = FastSerializerHelper::createAttrList();
1947 pAttr->add( FSNS( XML_xmlns, XML_o ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(vmlOffice)), RTL_TEXTENCODING_UTF8) );
1948 pAttr->add( FSNS( XML_xmlns, XML_r ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(officeRel)), RTL_TEXTENCODING_UTF8) );
1949 pAttr->add( FSNS( XML_xmlns, XML_v ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(vml)), RTL_TEXTENCODING_UTF8) );
1950 pAttr->add( FSNS( XML_xmlns, XML_w ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(doc)), RTL_TEXTENCODING_UTF8) );
1951 pAttr->add( FSNS( XML_xmlns, XML_w10 ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(vmlWord)), RTL_TEXTENCODING_UTF8) );
1952 pAttr->add( FSNS( XML_xmlns, XML_wp ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(dmlWordDr)), RTL_TEXTENCODING_UTF8) );
1953 pAttr->add( FSNS( XML_xmlns, XML_wps ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(wps)), RTL_TEXTENCODING_UTF8) );
1954 pAttr->add( FSNS( XML_xmlns, XML_wpg ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(wpg)), RTL_TEXTENCODING_UTF8) );
1955 pAttr->add( FSNS( XML_xmlns, XML_mc ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(mce)), RTL_TEXTENCODING_UTF8) );
1956 pAttr->add( FSNS( XML_xmlns, XML_wp14 ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(wp14)), RTL_TEXTENCODING_UTF8) );
1957 pAttr->add( FSNS( XML_xmlns, XML_w14 ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(w14)), RTL_TEXTENCODING_UTF8) );
1958 pAttr->add( FSNS( XML_xmlns, XML_w15 ), OUStringToOString(m_rFilter.getNamespaceURL(OOX_NS(w15)), RTL_TEXTENCODING_UTF8));
1959 pAttr->add( FSNS( XML_mc, XML_Ignorable ), "w14 wp14 w15" );
1960 return pAttr;
1961}
1962
1963bool DocxExport::ignoreAttributeForStyleDefaults( sal_uInt16 nWhich ) const
1964{
1965 if( nWhich == RES_TEXTGRID )
1966 return true; // w:docGrid is written only to document.xml, not to styles.xml
1967 if (nWhich == RES_PARATR_HYPHENZONE)
1968 return true; // w:suppressAutoHyphens is only a formatting exception, not a default
1970}
1971
1973 bool bNeedsLastParaId)
1974{
1975 const EditTextObject& rEditObj = rParaObj.GetTextObject();
1976 MSWord_SdrAttrIter aAttrIter( *this, rEditObj, nTyp );
1977
1978 sal_Int32 nPara = rEditObj.GetParagraphCount();
1979 sal_Int32 nParaId = 0;
1980 for( sal_Int32 n = 0; n < nPara; ++n )
1981 {
1982 if( n )
1983 aAttrIter.NextPara( n );
1984
1986 bNeedsLastParaId && n == nPara - 1);
1987 rtl_TextEncoding eChrSet = aAttrIter.GetNodeCharSet();
1988 OUString aStr( rEditObj.GetText( n ));
1989 sal_Int32 nCurrentPos = 0;
1990 const sal_Int32 nEnd = aStr.getLength();
1991
1992 // Write paragraph properties.
1994 aAttrIter.OutParaAttr(/*bCharAttr=*/false);
1995 SfxItemSet aParagraphMarkerProperties(m_rDoc.GetAttrPool());
1996 AttrOutput().EndParagraphProperties(aParagraphMarkerProperties, nullptr, nullptr, nullptr);
1997
1998 do {
1999 AttrOutput().StartRun( nullptr, 0 );
2000 const sal_Int32 nNextAttr = std::min(aAttrIter.WhereNext(), nEnd);
2001 rtl_TextEncoding eNextChrSet = aAttrIter.GetNextCharSet();
2002
2003 bool bTextAtr = aAttrIter.IsTextAttr( nCurrentPos );
2004 if( !bTextAtr )
2005 {
2006 if( nCurrentPos == 0 && nNextAttr - nCurrentPos == aStr.getLength())
2007 AttrOutput().RunText( aStr, eChrSet );
2008 else
2009 {
2010 OUString tmp( aStr.copy( nCurrentPos, nNextAttr - nCurrentPos ));
2011 AttrOutput().RunText( tmp, eChrSet );
2012 }
2013 }
2015 aAttrIter.OutAttr( nCurrentPos );
2016 AttrOutput().EndRunProperties( nullptr );
2017
2018 nCurrentPos = nNextAttr;
2019 eChrSet = eNextChrSet;
2020 aAttrIter.NextPos();
2021
2022 AttrOutput().EndRun( nullptr, 0, -1 );
2023
2024 } while( nCurrentPos < nEnd );
2025
2027 }
2028 return nParaId;
2029}
2030
2031//Keep this function in-sync with the one in writerfilter/.../SettingsTable.cxx
2032//Since this is not import code, "-1" needs to be handled as the mode that LO will save as.
2033//To identify how your code should handle a "-1", look in DocxExport::WriteSettings().
2035{
2036 sal_Int32 nWordCompatibilityMode = -1;
2037 uno::Reference< beans::XPropertySet > xPropSet(m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW);
2038 uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
2039 if (xPropSetInfo->hasPropertyByName(UNO_NAME_MISC_OBJ_INTEROPGRABBAG))
2040 {
2041 uno::Sequence< beans::PropertyValue > propList;
2042 xPropSet->getPropertyValue( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) >>= propList;
2043
2044 for (const auto& rProp : std::as_const(propList))
2045 {
2046 if (rProp.Name == "CompatSettings")
2047 {
2048 css::uno::Sequence< css::beans::PropertyValue > aCurrentCompatSettings;
2049 rProp.Value >>= aCurrentCompatSettings;
2050
2051 for (const auto& rCurrentCompatSetting : std::as_const(aCurrentCompatSettings))
2052 {
2053 uno::Sequence< beans::PropertyValue > aCompatSetting;
2054 rCurrentCompatSetting.Value >>= aCompatSetting;
2055
2056 OUString sName;
2057 OUString sUri;
2058 OUString sVal;
2059
2060 for (const auto& rPropVal : std::as_const(aCompatSetting))
2061 {
2062 if ( rPropVal.Name == "name" ) rPropVal.Value >>= sName;
2063 if ( rPropVal.Name == "uri" ) rPropVal.Value >>= sUri;
2064 if ( rPropVal.Name == "val" ) rPropVal.Value >>= sVal;
2065 }
2066
2067 if (sName == "compatibilityMode" && sUri == "http://schemas.microsoft.com/office/word")
2068 {
2069 const sal_Int32 nValidMode = sVal.toInt32();
2070 // if repeated, highest mode wins in MS Word. 11 is the first valid mode.
2071 if (nValidMode > 10 && nValidMode > nWordCompatibilityMode)
2072 nWordCompatibilityMode = nValidMode;
2073
2074 }
2075 }
2076 }
2077 }
2078 }
2079
2080 return nWordCompatibilityMode;
2081}
2082
2084{
2085 mpFS = pFS;
2086}
2087
2089 std::shared_ptr<SwUnoCursor> & pCurrentPam,
2090 SwPaM& rOriginalPam, bool bDocm, bool bTemplate)
2091 : MSWordExportBase(rDocument, pCurrentPam, &rOriginalPam),
2092 m_rFilter( rFilter ),
2093 m_nHeaders( 0 ),
2094 m_nFooters( 0 ),
2095 m_nOLEObjects( 0 ),
2096 m_nActiveXControls( 0 ),
2097 m_nHeadersFootersInSection(0),
2098 m_bDocm(bDocm),
2099 m_bTemplate(bTemplate),
2100 m_pAuthorIDs(new SvtSecurityMapPersonalInfo)
2101{
2102 // Write the document properties
2103 WriteProperties( );
2104
2105 // relations for the document
2106 m_rFilter.addRelation( oox::getRelationship(Relationship::OFFICEDOCUMENT),
2107 u"word/document.xml" );
2108
2109 // Set media type depending of document type
2110 OUString aMediaType;
2111 if (m_bDocm)
2112 {
2113 if (m_bTemplate)
2114 {
2115 aMediaType = "application/vnd.ms-word.template.macroEnabledTemplate.main+xml";
2116 }
2117 else
2118 {
2119 aMediaType = "application/vnd.ms-word.document.macroEnabled.main+xml";
2120 }
2121 }
2122 else
2123 {
2124 if (m_bTemplate)
2125 {
2126 aMediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml";
2127 }
2128 else
2129 {
2130 aMediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";
2131 }
2132 }
2133
2134
2135 // the actual document
2136 m_pDocumentFS = m_rFilter.openFragmentStreamWithSerializer( "word/document.xml", aMediaType );
2137
2139
2140 // the DrawingML access
2142
2143 // the attribute output for the document
2144 m_pAttrOutput.reset(new DocxAttributeOutput( *this, m_pDocumentFS, m_pDrawingML.get() ));
2145
2146 // the related VMLExport
2148
2149 // the related drawing export
2150 m_pSdrExport.reset(new DocxSdrExport( *this, m_pDocumentFS, m_pDrawingML.get() ));
2151}
2152
2154{
2155 m_pDocumentFS->endDocument();
2156}
2157
2159: evenAndOddHeaders( false )
2160, defaultTabStop( 0 )
2161, revisionView( true )
2162, trackRevisions( false )
2163{
2164}
2165
2167{
2168 if( evenAndOddHeaders )
2169 return true;
2170 if( defaultTabStop != 0 )
2171 return true;
2172 if ( !revisionView )
2173 return true;
2174 if ( trackRevisions )
2175 return true;
2176
2177 return false;
2178}
2179
2180/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ On
RedlineFlags on.
@ DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK
constexpr OUStringLiteral sMediaType
virtual void EndParagraphProperties(const SfxItemSet &rParagraphMarkerProperties, const SwRedlineData *pRedlineData, const SwRedlineData *pRedlineParagraphMarkerDeleted, const SwRedlineData *pRedlineParagraphMarkerInserted)=0
Called after we end outputting the attributes.
virtual void EmptyParagraph()=0
Empty paragraph.
virtual sal_Int32 StartParagraph(ww8::WW8TableNodeInfo::Pointer_t pTextNodeInfo, bool bGenerateParaId)=0
Start of the paragraph.
virtual void EndParagraph(ww8::WW8TableNodeInfoInner::Pointer_t pTextNodeInfoInner)=0
End of the paragraph.
virtual void RunText(const OUString &rText, rtl_TextEncoding eCharSet=RTL_TEXTENCODING_UTF8, const OUString &rSymbolFont=OUString())=0
Output text (inside a run).
virtual void EndRun(const SwTextNode *pNode, sal_Int32 nPos, sal_Int32 nLen, bool bLastRun=false)=0
End of the text run.
virtual void StartRunProperties()=0
Called before we start outputting the attributes.
virtual void StartParagraphProperties()=0
Called before we start outputting the attributes.
virtual void StartRun(const SwRedlineData *pRedlineData, sal_Int32 nPos, bool bSingleEmptyRun=false)=0
Start of the text run.
virtual void SectionBreaks(const SwNode &rNode)=0
Called in order to output section breaks.
virtual void EndRunProperties(const SwRedlineData *pRedlineData)=0
Called after we end outputting the attributes.
virtual void SectionBreak(sal_uInt8 nC, bool bBreakAfter, const WW8_SepInfo *pSectionInfo=nullptr, bool bExtraPageBreak=false)=0
Write a section break msword::ColumnBreak or msword::PageBreak bBreakAfter: the break must be schedul...
The class that has handlers for various resource types when exporting as DOCX.
static void WriteFootnoteEndnotePr(::sax_fastparser::FSHelperPtr const &fs, int tag, const SwEndNoteInfo &info, int listtag)
writes the footnotePr/endnotePr (depending on tag) section
The physical access to the DOCX document (for writing).
virtual void WriteNumbering() override
Write the numbering table.
Definition: docxexport.cxx:789
rtl::Reference< sax_fastparser::FastAttributeList > MainXmlNamespaces()
All xml namespaces to be used at the top of any text .xml file (main doc, headers,...
virtual void AppendAnnotationMarks(const SwWW8AttrIter &rAttrs, sal_Int32 nCurrentPos, sal_Int32 nLen) override
Definition: docxexport.cxx:193
sal_Int32 m_nFooters
Footer counter.
Definition: docxexport.hxx:98
void WriteTheme()
Write word/theme/theme1.xml.
virtual MSWordSections & Sections() const override
Access to the sections/headers/footres.
Definition: docxexport.cxx:116
virtual void OutputField(const SwField *pField, ww::eField eFieldType, const OUString &rFieldCmd, FieldFlags nMode=FieldFlags::All) override
Write the field.
Definition: docxexport.cxx:316
void WritePostitFields()
Write comments.xml.
Definition: docxexport.cxx:747
virtual bool DisallowInheritingOutlineNumbering(const SwFormat &rFormat) override
Return value indicates if an inherited outline numbering is suppressed.
Definition: docxexport.cxx:231
OString AddRelation(const OUString &rType, std::u16string_view rTarget)
Returns the relationd id.
Definition: docxexport.cxx:223
std::pair< OString, OString > WriteActiveXObject(const uno::Reference< css::drawing::XShape > &rxShape, const uno::Reference< awt::XControlModel > &rxControlModel)
Definition: docxexport.cxx:456
sal_Int32 WriteOutliner(const OutlinerParaObject &rOutliner, sal_uInt8 nTyp, bool bNeedsLastParaId)
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:637
virtual void AppendBookmark(const OUString &rName) override
Definition: docxexport.cxx:185
void WriteProperties()
Write docProps/core.xml.
Definition: docxexport.cxx:931
const ::sax_fastparser::FSHelperPtr & GetFS() const
Definition: docxexport.hxx:313
virtual void AppendBookmarks(const SwTextNode &rNode, sal_Int32 nCurrentPos, sal_Int32 nLen, const SwRedlineData *pRedlineData=nullptr) override
Definition: docxexport.cxx:155
std::vector< SdtData > m_SdtData
Storage for sdt data which need to be written to other XMLs.
Definition: docxexport.hxx:130
void WriteSettings()
Write word/settings.xml.
virtual ErrCode ExportDocument_Impl() override
Format-dependent part of the actual export.
Definition: docxexport.cxx:518
virtual void OutputOLENode(const SwOLENode &) override
Output SwOLENode.
Definition: docxexport.cxx:620
bool m_bDocm
If the result will be a .docm file or not.
Definition: docxexport.hxx:116
virtual void ExportGrfBullet(const SwTextNode &) override
Definition: docxexport.cxx:217
virtual sal_uInt64 ReplaceCr(sal_uInt8 nChar) override
Definition: docxexport.cxx:630
OString WriteOLEObject(SwOLEObj &rObject, OUString &io_rProgID)
Definition: docxexport.cxx:408
sal_Int32 m_nHeadersFootersInSection
Footer and Header counter in Section properties.
Definition: docxexport.hxx:107
::sax_fastparser::FSHelperPtr m_pDocumentFS
Fast serializer for the document output.
Definition: docxexport.hxx:80
std::unique_ptr< DocxSdrExport > m_pSdrExport
Exporter of drawings.
Definition: docxexport.hxx:113
::sax_fastparser::FSHelperPtr mpFS
Fast serializer to output the data.
Definition: docxexport.hxx:83
virtual void OutputGrfNode(const SwGrfNode &) override
Output SwGrfNode.
Definition: docxexport.cxx:615
virtual void AppendSection(const SwPageDesc *pPageDesc, const SwSectionFormat *pFormat, sal_uLong nLnNum) override
Definition: docxexport.cxx:566
DocxExportFilter & m_rFilter
Pointer to the filter that owns us.
Definition: docxexport.hxx:77
void InitStyles()
Setup pStyles and write styles.xml.
Definition: docxexport.cxx:661
void WriteMainText()
FIXME this is temporary, remotely reminding the method of the same name in WW8Export.
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:253
std::unique_ptr< MSWordSections > m_pSections
Sections/headers/footers.
Definition: docxexport.hxx:92
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:829
virtual void OutputLinkedOLE(const OUString &) override
Definition: docxexport.cxx:625
virtual void DoFormText(const SwInputField *pField) override
Definition: docxexport.cxx:371
bool const m_bTemplate
Export is done into template (.dotx)
Definition: docxexport.hxx:119
void WriteFootnotesEndnotes()
Write footnotes.xml and endnotes.xml.
Definition: docxexport.cxx:686
std::unique_ptr< DocxAttributeOutput > m_pAttrOutput
Attribute output for document.
Definition: docxexport.hxx:89
bool isMirroredMargin()
return true if Page Layout is set as Mirrored
sal_Int32 m_nOLEObjects
OLE objects counter.
Definition: docxexport.hxx:101
virtual ~DocxExport() override
Destructor.
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:331
virtual bool CollapseScriptsforWordOk(sal_uInt16 nScript, sal_uInt16 nWhich) override
Guess the script (asian/western).
Definition: docxexport.cxx:121
virtual void WriteHyperlinkData(const ::sw::mark::IFieldmark &rFieldmark) override
Definition: docxexport.cxx:326
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.
void WriteVBA()
Writes word/vbaProject.bin.
virtual void OutputEndNode(const SwEndNode &) override
Output SwEndNode.
Definition: docxexport.cxx:572
void WriteFonts()
Write word/fontTable.xml.
Definition: docxexport.cxx:903
void WriteEmbeddings()
Write word/embeddings/Worksheet[n].xlsx.
std::unique_ptr< oox::vml::VMLExport > m_pVMLExport
Exporter of the VML shapes.
Definition: docxexport.hxx:110
virtual AttributeOutputBase & AttrOutput() const override
Access to the attribute output class.
Definition: docxexport.cxx:106
std::unique_ptr< oox::drawingml::DrawingML > m_pDrawingML
Access to the DrawingML writer.
Definition: docxexport.hxx:86
DocxAttributeOutput & DocxAttrOutput() const
Access to the derived attribute output class.
Definition: docxexport.cxx:111
void SetFS(::sax_fastparser::FSHelperPtr const &mpFS)
void WriteDocVars(const sax_fastparser::FSHelperPtr &pFS)
Writes the <w:docVars> part of settings.xml.
Definition: docxexport.cxx:948
virtual void WriteFormData(const ::sw::mark::IFieldmark &rFieldmark) override
Write the data of the form field.
Definition: docxexport.cxx:321
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:378
DocxSettingsData m_aSettings
Definition: docxexport.hxx:121
DocxExportFilter & GetFilter()
Definition: docxexport.hxx:134
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.
sal_Int32 getWordCompatibilityModeFromGrabBag() const
sal_Int32 m_nHeaders
Header counter.
Definition: docxexport.hxx:95
void WriteGlossary()
sal_Int32 m_nActiveXControls
ActiveX controls counter.
Definition: docxexport.hxx:104
void OutputDML(css::uno::Reference< css::drawing::XShape > const &xShape)
Writes the shape using drawingML syntax.
Definition: docxexport.cxx:506
void WriteCustomXml()
Write customXml/item[n].xml and customXml/itemProps[n].xml.
Handles DOCX export of drawings.
virtual sal_Int32 GetParagraphCount() const=0
virtual OUString GetText(sal_Int32 nPara) const=0
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
Provides access to settings of a document.
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
Base class for WW8Export and DocxExport.
Definition: wrtww8.hxx:451
void WriteText()
Iterate through the nodes and call the appropriate OutputNode() on them.
Definition: wrtww8.cxx:2900
sal_uInt8 m_nTextTyp
Definition: wrtww8.hxx:549
void WriteHeaderFooterText(const SwFormat &rFormat, bool bHeader)
Write header/footer text.
Definition: wrtw8sty.cxx:2119
int CollectGrfsOfBullets()
Populates m_vecBulletPic with all the bullet graphics used by numberings.
Definition: wrtww8.cxx:1526
bool IsInTable() const
Return whether currently exported node is in table.
Definition: wrtww8.cxx:3074
bool m_bOrigShowChanges
Remember the original Show Changes mode.
Definition: wrtww8.hxx:489
virtual void OutputEndNode(const SwEndNode &)
Output SwEndNode.
Definition: wrtww8.cxx:4514
RedlineFlags m_nOrigRedlineFlags
Remember the original redline mode.
Definition: wrtww8.hxx:488
std::unique_ptr< SvxBrushItem > getBackground()
Get background color of the document, if there is one.
Definition: wrtww8.cxx:1510
sal_Int32 m_nLinkedTextboxesChainId
Definition: wrtww8.hxx:518
std::unique_ptr< MSWordStyles > m_pStyles
Definition: wrtww8.hxx:503
std::vector< ::sw::mark::IMark * > IMarkVector
Used to split the runs according to the bookmarks start and ends.
Definition: wrtww8.hxx:585
wwFontHelper m_aFontHelper
Definition: wrtww8.hxx:453
static sal_uLong GetSectionLineNo(const SfxItemSet *pSet, const SwNode &rNd)
Line number of the section start.
Definition: ww8atr.cxx:704
const SwPageDesc * m_pCurrentPageDesc
Definition: wrtww8.hxx:497
void SectionProperties(const WW8_SepInfo &rSectionInfo, WW8_PdAttrDesc *pA=nullptr)
Write section properties.
Definition: wrtw8sty.cxx:1640
bool GetBookmarks(const SwTextNode &rNd, sal_Int32 nStt, sal_Int32 nEnd, IMarkVector &rArr)
Definition: wrtw8nds.cxx:1948
bool GetAnnotationMarks(const SwWW8AttrIter &rAttrs, sal_Int32 nStt, sal_Int32 nEnd, IMarkVector &rArr)
Definition: wrtw8nds.cxx:1995
std::unique_ptr< SwNumRuleTable > m_pUsedNumTable
Definition: wrtww8.hxx:460
std::shared_ptr< SwUnoCursor > & m_pCurPam
Definition: wrtww8.hxx:578
std::map< OUString, LinkedTextboxInfo > m_aLinkedTextboxesHelper
Definition: wrtww8.hxx:516
static const SwSectionFormat * GetSectionFormat(const SwNode &rNd)
Format of the section.
Definition: ww8atr.cxx:691
void AbstractNumberingDefinitions()
Write all Levels for all SwNumRules - LVLF.
Definition: wrtw8num.cxx:383
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:692
void BulletDefinitions()
Write the numbering picture bullets.
Definition: wrtww8.cxx:1567
void NumberingDefinitions()
Write static data of SwNumRule - LSTF.
Definition: wrtw8num.cxx:210
SwDoc & m_rDoc
Definition: wrtww8.hxx:576
Class to collect and output the sections/headers/footers.
Definition: wrtww8.hxx:196
Class to collect and output the styles table.
Definition: wrtww8.hxx:1583
Used to export formatted text associated to drawings.
Definition: wrtww8.hxx:1465
void OutAttr(sal_Int32 nSwPos)
Definition: wrtw8esh.cxx:1112
rtl_TextEncoding GetNextCharSet() const
Definition: wrtw8esh.cxx:1038
void OutParaAttr(bool bCharAttr, const std::set< sal_uInt16 > *pWhichsToIgnore=nullptr)
Definition: wrtw8esh.cxx:1275
rtl_TextEncoding GetNodeCharSet() const
Definition: wrtww8.hxx:1502
void NextPara(sal_Int32 nPar)
Definition: wrtw8esh.cxx:1018
bool IsTextAttr(sal_Int32 nSwPos)
Definition: wrtw8esh.cxx:1198
sal_Int32 WhereNext() const
Definition: wrtww8.hxx:1500
const EditTextObject & GetTextObject() const
bool IsSecurityOptOpenReadOnly() const
css::uno::Reference< css::frame::XModel3 > GetModel() const
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
const css::uno::Sequence< css::beans::PropertyValue > & GetModifyPasswordInfo() const
sal_uInt16 & GetTextHyphenZone()
bool IsNoCapsHyphenation() const
const SwFormatLineNumber & GetLineNumber(bool=true) const
Definition: fmtline.hxx:64
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:765
Definition: doc.hxx:197
SwDBData const & GetDBData()
Definition: docfld.cxx:386
const SwFootnoteInfo & GetFootnoteInfo() const
Definition: doc.hxx:643
SwNodes & GetNodes()
Definition: doc.hxx:422
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:419
IDocumentSettingAccess const & getIDocumentSettingAccess() const
Definition: doc.cxx:190
const SwEndNoteInfo & GetEndNoteInfo() const
Definition: doc.hxx:645
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:440
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1334
SwDocShell * GetDocShell()
Definition: doc.hxx:1367
const SwPageDesc & GetPageDesc(const size_t i) const
Definition: doc.hxx:894
Ends a section of nodes in the document model.
Definition: node.hxx:378
Base class of all fields.
Definition: fldbas.hxx:296
sal_uLong GetStartValue() const
Definition: fmtline.hxx:57
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
Definition: fmtpdsc.hxx:36
Base class for various Writer styles.
Definition: format.hxx:47
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
Definition: format.cxx:385
SwFormat * DerivedFrom() const
Definition: format.hxx:128
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
Templatized version of GetItemState() to directly return the correct type.
Definition: format.hxx:111
Style of a layout element.
Definition: frmfmt.hxx:72
virtual OUString GetPar2() const override
aPromptText
Definition: expfld.cxx:1402
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNode & GetNode() const
Definition: ndindex.hxx:123
Base class of the Writer document model elements.
Definition: node.hxx:98
SwSectionNode * GetSectionNode()
Definition: node.hxx:658
bool IsContentNode() const
Definition: node.hxx:679
bool IsEndNode() const
Definition: node.hxx:683
bool IsSectionNode() const
Definition: node.hxx:695
bool IsTableNode() const
Definition: node.hxx:691
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:153
SwContentNode * GetContentNode()
Definition: node.hxx:666
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:165
css::uno::Reference< css::embed::XEmbeddedObject > const & GetOleRef()
Definition: ndole.cxx:1012
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
UseOnPage ReadUseOn() const
Definition: pagedesc.hxx:236
SwSectionFormat * GetParent() const
Definition: section.hxx:360
const SwSection & GetSection() const
Definition: node.hxx:590
SwSectionFormat * GetFormat()
Definition: section.hxx:341
SectionType GetType() const
Definition: section.hxx:173
Represents the style of a paragraph.
Definition: fmtcol.hxx:61
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
const OUString & GetText() const
Definition: ndtxt.hxx:244
SvxZoomType GetZoomType() const
Definition: viewopt.hxx:712
sal_uInt16 GetZoom() const
Definition: viewopt.hxx:671
bool getBrowseMode() const
Definition: viewopt.hxx:638
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:451
static void CopyInputToOutput(const css::uno::Reference< css::io::XInputStream > &xInput, const css::uno::Reference< css::io::XOutputStream > &xOutput)
css::uno::Reference< css::io::XOutputStream > openOutputStream(const OUString &rStreamName)
OoxmlVersion getVersion() const
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
::sax_fastparser::FSHelperPtr openFragmentStreamWithSerializer(const OUString &rStreamName, const OUString &rMediaType)
OUString addRelation(const OUString &rType, std::u16string_view rTarget)
css::uno::Reference< css::io::XOutputStream > openFragmentStream(const OUString &rStreamName, const OUString &rMediaType)
OUString getNamespaceURL(sal_Int32 nNSID) const
void exportDocumentProperties(const css::uno::Reference< css::document::XDocumentProperties > &xProperties, bool bSecurityOptOpenReadOnly)
static GraphicExportCache & get()
ShapeExport & WriteShape(const css::uno::Reference< css::drawing::XShape > &xShape)
std::u16string_view getGUID() const
const OUString & getName() const
void exportControl(const css::uno::Reference< css::io::XOutputStream > &rxOut, const css::awt::Size &rSize, bool bAutoClose=false)
static rtl::Reference< FastAttributeList > createAttrList()
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
std::shared_ptr< WW8TableNodeInfoInner > Pointer_t
std::shared_ptr< WW8TableNodeInfo > Pointer_t
void WriteFontTable(SvStream *pTableStream, WW8Fib &pFib)
Definition: wrtw8sty.cxx:967
Any value
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
sal_Int32 DocxStringGetToken(DocxStringTokenMap const *pMap, std::u16string_view rName)
static void lcl_UpdateXmlValues(const SdtData &sdtData, const uno::Reference< css::io::XInputStream > &xInputStream, const uno::Reference< css::io::XOutputStream > &xOutputStream)
static auto WriteCompat(SwDoc const &rDoc, ::sax_fastparser::FSHelperPtr const &rpFS, sal_Int32 &rTargetCompatibilityMode) -> void
float u
#define ERRCODE_NONE
FilterGroup & rTarget
constexpr sal_Int32 FSNS(sal_Int32 namespc, sal_Int32 element)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_FONTSIZE(8)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_WEIGHT(15)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CJK_FONTSIZE(23)
constexpr TypedWhichId< SvxHyphenZoneItem > RES_PARATR_HYPHENZONE(69)
constexpr TypedWhichId< SwTextGridItem > RES_TEXTGRID(121)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_POSTURE(11)
constexpr TypedWhichId< SwNumRuleItem > RES_PARATR_NUMRULE(72)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CJK_WEIGHT(26)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CJK_POSTURE(25)
char const sHash[]
const char * name
Mutex m_mutex
OUString aName
sal_Int64 n
OUString sSuffix
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
aStr
const char * sName
constexpr OUStringLiteral aData
Definition: ww8scan.hxx:48
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
Reference< XComponentContext > getProcessComponentContext()
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
int i
OString ConvertColor(const Color &rColor)
const sal_uInt8 PageBreak
const HdFtFlags WW8_HEADER_FIRST
Definition: ww8scan.hxx:1601
const HdFtFlags WW8_FOOTER_ODD
Definition: ww8scan.hxx:1600
const HdFtFlags WW8_FOOTER_EVEN
Definition: ww8scan.hxx:1599
const HdFtFlags WW8_HEADER_EVEN
Definition: ww8scan.hxx:1597
const HdFtFlags WW8_FOOTER_FIRST
Definition: ww8scan.hxx:1602
const HdFtFlags WW8_HEADER_ODD
Definition: ww8scan.hxx:1598
uno::Reference< io::XInputStream > GetOLEObjectStream(uno::Reference< uno::XComponentContext > const &xContext, uno::Reference< embed::XEmbeddedObject > const &xObj, std::u16string_view i_rProgID, OUString &o_rMediaType, OUString &o_rRelationType, OUString &o_rSuffix, const char *&o_rpProgID)
OUString getRelationship(Relationship eRelationship)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
std::shared_ptr< FastSerializerHelper > FSHelperPtr
bool getOutputStream(ProgramOptions const &options, OString const &extension, std::ostream **ppOutputStream, OString &targetSourceFileName, OString &tmpSourceFileName)
XML_type
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Definition: nodeoffset.hxx:35
sal_Int16 nId
const char * sGUID
@ RES_POOLCOLL_STANDARD
Standard.
Definition: poolfmt.hxx:250
DefTokenId nToken
sal_uIntPtr sal_uLong
OReadStatusBarDocumentHandler::StatusBar_XML_Namespace nNamespace
bool evenAndOddHeaders
returns true if there are any non-default settings (i.e. something to write)
Definition: docxexport.hxx:59
bool hasData() const
All the information that should be stashed away when we're in the middle of of a table export and sti...
Data to keep and write to XMLs.
Definition: docxexport.hxx:67
OUString namespaces
Definition: docxexport.hxx:68
OUString data
Definition: docxexport.hxx:70
OUString xpath
Definition: docxexport.hxx:69
Reference< XModel > xModel
unsigned char sal_uInt8
OUString sId
constexpr OUStringLiteral UNO_NAME_MISC_OBJ_INTEROPGRABBAG
oslFileHandle & pOut
FieldFlags
Definition: wrtww8.hxx:143
OUString FieldString(ww::eField eIndex)
Definition: ww8atr.cxx:2798
@ TXT_MAINTEXT
Definition: wrtww8.hxx:158