1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "SettingsTable.hxx"
21 #include "DocumentProtection.hxx"
22 #include "TagLogger.hxx"
23 #include "WriteProtection.hxx"
27 #include <rtl/ustring.hxx>
28 #include <sfx2/zoomitem.hxx>
29 #include <com/sun/star/text/XDependentTextField.hpp>
30 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/beans/XPropertyState.hpp>
34 #include <com/sun/star/container/XNameContainer.hpp>
35 #include <com/sun/star/style/XStyle.hpp>
36 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
37 #include <comphelper/propertysequence.hxx>
38 #include <comphelper/propertyvalue.hxx>
39 #include <comphelper/sequence.hxx>
41 #include <ooxml/OOXMLPropertySet.hxx>
42 #include "ConversionHelper.hxx"
43 #include "DomainMapper.hxx"
46 using namespace com::sun::star
;
48 namespace writerfilter
{
51 /// Maps OOXML <w:zoom w:val="..."> to SvxZoomType.
52 sal_Int16
lcl_GetZoomType(Id nType
)
56 case NS_ooxml::LN_Value_doc_ST_Zoom_fullPage
:
57 return sal_Int16(SvxZoomType::WHOLEPAGE
);
58 case NS_ooxml::LN_Value_doc_ST_Zoom_bestFit
:
59 return sal_Int16(SvxZoomType::PAGEWIDTH
);
60 case NS_ooxml::LN_Value_doc_ST_Zoom_textFit
:
61 return sal_Int16(SvxZoomType::OPTIMAL
);
64 return sal_Int16(SvxZoomType::PERCENT
);
71 struct SettingsTable_Impl
73 int m_nDefaultTabStop
;
75 bool m_bRecordChanges
;
76 bool m_bShowInsDelChanges
;
77 bool m_bShowFormattingChanges
;
78 bool m_bShowMarkupChanges
;
80 sal_Int16 m_nZoomFactor
;
81 sal_Int16 m_nZoomType
= 0;
82 sal_Int32 m_nWordCompatibilityMode
;
84 bool m_bEvenAndOddHeaders
;
85 bool m_bUsePrinterMetrics
;
86 bool embedTrueTypeFonts
;
87 bool embedSystemFonts
;
88 bool m_bDoNotUseHTMLParagraphAutoSpacing
;
89 bool m_bNoColumnBalance
;
90 bool m_bAutoHyphenation
;
91 bool m_bNoHyphenateCaps
;
92 sal_Int16 m_nHyphenationZone
;
94 bool m_bLongerSpaceSequence
;
95 bool m_bSplitPgBreakAndParaMark
;
97 bool m_bDoNotExpandShiftReturn
;
98 bool m_bDisplayBackgroundShape
;
99 bool m_bNoLeading
= false;
100 OUString m_sDecimalSymbol
;
101 OUString m_sListSeparator
;
102 std::vector
<std::pair
<OUString
, OUString
>> m_aDocVars
;
104 uno::Sequence
<beans::PropertyValue
> m_pThemeFontLangProps
;
106 std::vector
<beans::PropertyValue
> m_aCompatSettings
;
107 uno::Sequence
<beans::PropertyValue
> m_pCurrentCompatSetting
;
108 OUString m_aCurrentCompatSettingName
;
109 OUString m_aCurrentCompatSettingUri
;
110 OUString m_aCurrentCompatSettingValue
;
111 OUString m_sCurrentDatabaseDataSource
;
113 std::shared_ptr
<DocumentProtection
> m_pDocumentProtection
;
114 std::shared_ptr
<WriteProtection
> m_pWriteProtection
;
115 bool m_bGutterAtTop
= false;
116 bool m_bDoNotBreakWrappedTables
= false;
117 bool m_bAllowTextAfterFloatingTableBreak
= false;
119 SettingsTable_Impl() :
120 m_nDefaultTabStop( 720 ) //default is 1/2 in
121 , m_bRecordChanges(false)
122 , m_bShowInsDelChanges(true)
123 , m_bShowFormattingChanges(false)
124 , m_bShowMarkupChanges(true)
125 , m_bLinkStyles(false)
127 , m_nWordCompatibilityMode(-1)
129 , m_bEvenAndOddHeaders(false)
130 , m_bUsePrinterMetrics(false)
131 , embedTrueTypeFonts(false)
132 , embedSystemFonts(false)
133 , m_bDoNotUseHTMLParagraphAutoSpacing(false)
134 , m_bNoColumnBalance(false)
135 , m_bAutoHyphenation(false)
136 , m_bNoHyphenateCaps(false)
137 , m_nHyphenationZone(0)
138 , m_bWidowControl(false)
139 , m_bLongerSpaceSequence(false)
140 , m_bSplitPgBreakAndParaMark(false)
141 , m_bMirrorMargin(false)
142 , m_bDoNotExpandShiftReturn(false)
143 , m_bDisplayBackgroundShape(false)
144 , m_sDecimalSymbol(".")
145 , m_sListSeparator(",")
146 , m_pThemeFontLangProps(3)
147 , m_pCurrentCompatSetting(3)
151 SettingsTable::SettingsTable(const DomainMapper
& rDomainMapper
)
152 : LoggedProperties("SettingsTable")
153 , LoggedTable("SettingsTable")
154 , m_pImpl( new SettingsTable_Impl
)
156 if (rDomainMapper
.IsRTFImport())
158 // HTML paragraph auto-spacing is opt-in for RTF, opt-out for OOXML.
159 m_pImpl
->m_bDoNotUseHTMLParagraphAutoSpacing
= true;
160 // Longer space sequence is opt-in for RTF, and not in OOXML.
161 m_pImpl
->m_bLongerSpaceSequence
= true;
162 m_pImpl
->m_bDoNotBreakWrappedTables
= true;
164 m_pImpl
->m_pDocumentProtection
= std::make_shared
<DocumentProtection
>();
165 m_pImpl
->m_pWriteProtection
= std::make_shared
<WriteProtection
>();
168 SettingsTable::~SettingsTable()
172 void SettingsTable::lcl_attribute(Id nName
, Value
& val
)
174 int nIntValue
= val
.getInt();
175 OUString sStringValue
= val
.getString();
179 case NS_ooxml::LN_CT_Zoom_percent
:
180 m_pImpl
->m_nZoomFactor
= nIntValue
;
182 case NS_ooxml::LN_CT_Zoom_val
:
183 m_pImpl
->m_nZoomType
= lcl_GetZoomType(nIntValue
);
185 case NS_ooxml::LN_CT_Language_val
:
186 m_pImpl
->m_pThemeFontLangProps
.getArray()[0]
187 = comphelper::makePropertyValue("val", sStringValue
);
189 case NS_ooxml::LN_CT_Language_eastAsia
:
190 m_pImpl
->m_pThemeFontLangProps
.getArray()[1]
191 = comphelper::makePropertyValue("eastAsia", sStringValue
);
193 case NS_ooxml::LN_CT_Language_bidi
:
194 m_pImpl
->m_pThemeFontLangProps
.getArray()[2]
195 = comphelper::makePropertyValue("bidi", sStringValue
);
197 case NS_ooxml::LN_CT_View_val
:
198 m_pImpl
->m_nView
= nIntValue
;
200 case NS_ooxml::LN_CT_DocVar_name
:
201 m_pImpl
->m_aDocVars
.back().first
= sStringValue
;
203 case NS_ooxml::LN_CT_DocVar_val
:
204 m_pImpl
->m_aDocVars
.back().second
= sStringValue
;
206 case NS_ooxml::LN_CT_CompatSetting_name
:
207 m_pImpl
->m_aCurrentCompatSettingName
= sStringValue
;
208 m_pImpl
->m_pCurrentCompatSetting
.getArray()[0]
209 = comphelper::makePropertyValue("name", sStringValue
);
211 case NS_ooxml::LN_CT_CompatSetting_uri
:
212 m_pImpl
->m_aCurrentCompatSettingUri
= sStringValue
;
213 m_pImpl
->m_pCurrentCompatSetting
.getArray()[1]
214 = comphelper::makePropertyValue("uri", sStringValue
);
216 case NS_ooxml::LN_CT_CompatSetting_val
:
217 m_pImpl
->m_aCurrentCompatSettingValue
= sStringValue
;
218 m_pImpl
->m_pCurrentCompatSetting
.getArray()[2]
219 = comphelper::makePropertyValue("val", sStringValue
);
221 case NS_ooxml::LN_CT_TrackChangesView_insDel
:
222 m_pImpl
->m_bShowInsDelChanges
= (nIntValue
!= 0);
224 case NS_ooxml::LN_CT_TrackChangesView_formatting
:
225 m_pImpl
->m_bShowFormattingChanges
= (nIntValue
!= 0);
227 case NS_ooxml::LN_CT_TrackChangesView_markup
:
228 m_pImpl
->m_bShowMarkupChanges
= (nIntValue
!= 0);
233 TagLogger::getInstance().element("unhandled");
239 void SettingsTable::lcl_sprm(Sprm
& rSprm
)
241 sal_uInt32 nSprmId
= rSprm
.getId();
243 Value::Pointer_t pValue
= rSprm
.getValue();
244 sal_Int32 nIntValue
= pValue
->getInt();
248 case NS_ooxml::LN_CT_Settings_zoom
: // 92469;
249 case NS_ooxml::LN_CT_Settings_proofState
: // 92489;
250 case NS_ooxml::LN_CT_Settings_attachedTemplate
: // 92491;
251 case NS_ooxml::LN_CT_Settings_hdrShapeDefaults
: // 92544;
252 case NS_ooxml::LN_CT_Settings_footnotePr
: // 92545;
253 case NS_ooxml::LN_CT_Settings_endnotePr
: // 92546;
254 case NS_ooxml::LN_CT_Settings_compat
: // 92547;
255 case NS_ooxml::LN_CT_Settings_themeFontLang
: // 92552;
256 case NS_ooxml::LN_CT_Settings_shapeDefaults
: // 92560;
257 case NS_ooxml::LN_CT_Settings_view
:
258 //PropertySetValues - need to be resolved
260 resolveSprmProps(*this, rSprm
);
263 case NS_ooxml::LN_CT_Settings_stylePaneFormatFilter
: // 92493;
265 case NS_ooxml::LN_CT_Settings_defaultTabStop
: // 92505;
266 m_pImpl
->m_nDefaultTabStop
= nIntValue
;
268 case NS_ooxml::LN_CT_Settings_linkStyles
: // 92663;
269 m_pImpl
->m_bLinkStyles
= nIntValue
;
271 case NS_ooxml::LN_CT_Settings_evenAndOddHeaders
:
272 m_pImpl
->m_bEvenAndOddHeaders
= nIntValue
;
274 case NS_ooxml::LN_CT_Settings_noPunctuationKerning
: // 92526;
276 case NS_ooxml::LN_CT_Settings_characterSpacingControl
: // 92527;
277 // doNotCompress, compressPunctuation, compressPunctuationAndJapaneseKana
279 case NS_ooxml::LN_CT_Settings_doNotIncludeSubdocsInStats
: // 92554; // Do Not Include Content in Text Boxes, Footnotes, and Endnotes in Document Statistics)
281 case NS_ooxml::LN_CT_Settings_decimalSymbol
: // 92562;
282 m_pImpl
->m_sDecimalSymbol
= pValue
->getString();
284 case NS_ooxml::LN_CT_Settings_listSeparator
: // 92563;
285 m_pImpl
->m_sListSeparator
= pValue
->getString();
287 case NS_ooxml::LN_CT_Settings_rsids
: // 92549; revision save Ids - probably not necessary
289 case NS_ooxml::LN_CT_Settings_hyphenationZone
: // 92508;
290 m_pImpl
->m_nHyphenationZone
= nIntValue
;
292 case NS_ooxml::LN_CT_Compat_useFELayout
: // 92422;
293 // useFELayout (Do Not Bypass East Asian/Complex Script Layout Code - support of old versions of Word - ignored)
295 case NS_ooxml::LN_CT_Settings_trackRevisions
:
297 m_pImpl
->m_bRecordChanges
= bool(rSprm
.getValue( )->getInt( ) );
300 case NS_ooxml::LN_CT_Settings_revisionView
:
301 resolveSprmProps(*this, rSprm
);
303 case NS_ooxml::LN_CT_Settings_documentProtection
:
304 resolveSprmProps(*(m_pImpl
->m_pDocumentProtection
), rSprm
);
306 case NS_ooxml::LN_CT_Settings_writeProtection
:
307 resolveSprmProps(*(m_pImpl
->m_pWriteProtection
), rSprm
);
309 case NS_ooxml::LN_CT_Compat_usePrinterMetrics
:
310 m_pImpl
->m_bUsePrinterMetrics
= nIntValue
;
312 case NS_ooxml::LN_CT_Settings_embedTrueTypeFonts
:
313 m_pImpl
->embedTrueTypeFonts
= nIntValue
!= 0;
315 case NS_ooxml::LN_CT_Settings_embedSystemFonts
:
316 m_pImpl
->embedSystemFonts
= nIntValue
!= 0;
318 case NS_ooxml::LN_CT_Compat_doNotUseHTMLParagraphAutoSpacing
:
319 m_pImpl
->m_bDoNotUseHTMLParagraphAutoSpacing
= nIntValue
;
321 case NS_ooxml::LN_CT_Compat_splitPgBreakAndParaMark
:
322 m_pImpl
->m_bSplitPgBreakAndParaMark
= nIntValue
;
324 case NS_ooxml::LN_CT_Settings_mirrorMargins
:
325 m_pImpl
->m_bMirrorMargin
= nIntValue
;
327 case NS_ooxml::LN_CT_Settings_mailMerge
:
329 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
331 pProperties
->resolve(*this);
334 case NS_ooxml::LN_CT_MailMerge_query
:
336 // try to get the "database.table" name from the query saved previously
337 OUString sVal
= pValue
->getString();
338 if ( sVal
.endsWith("$") && sVal
.indexOf(".dbo.") > 0 )
340 sal_Int32 nSpace
= sVal
.lastIndexOf(' ');
341 sal_Int32 nDbo
= sVal
.lastIndexOf(".dbo.");
342 if ( nSpace
> 0 && nSpace
< nDbo
- 1 )
344 m_pImpl
->m_sCurrentDatabaseDataSource
= OUString::Concat(sVal
.subView(nSpace
+ 1, nDbo
- nSpace
- 1)) +
345 sVal
.subView(nDbo
+ 4, sVal
.getLength() - nDbo
- 5);
350 case NS_ooxml::LN_CT_Compat_compatSetting
:
352 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
355 pProperties
->resolve(*this);
357 beans::PropertyValue aValue
;
358 aValue
.Name
= "compatSetting";
359 aValue
.Value
<<= m_pImpl
->m_pCurrentCompatSetting
;
360 m_pImpl
->m_aCompatSettings
.push_back(aValue
);
362 OString aCompatSettingValue
= rtl::OUStringToOString(
363 m_pImpl
->m_aCurrentCompatSettingValue
, RTL_TEXTENCODING_UTF8
);
364 if (m_pImpl
->m_aCurrentCompatSettingName
== "allowTextAfterFloatingTableBreak"
365 && m_pImpl
->m_aCurrentCompatSettingUri
== "http://schemas.microsoft.com/office/word"
366 && ooxml::GetBooleanValue(aCompatSettingValue
))
368 m_pImpl
->m_bAllowTextAfterFloatingTableBreak
= true;
373 case NS_ooxml::LN_CT_Settings_docVars
:
375 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
378 pProperties
->resolve(*this);
382 case NS_ooxml::LN_CT_DocVar
:
384 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
387 m_pImpl
->m_aDocVars
.push_back(std::make_pair(OUString(), OUString()));
388 pProperties
->resolve(*this);
392 case NS_ooxml::LN_CT_Compat_noColumnBalance
:
393 m_pImpl
->m_bNoColumnBalance
= nIntValue
;
395 case NS_ooxml::LN_CT_Settings_autoHyphenation
:
396 m_pImpl
->m_bAutoHyphenation
= nIntValue
;
398 case NS_ooxml::LN_CT_Settings_doNotHyphenateCaps
:
399 m_pImpl
->m_bNoHyphenateCaps
= nIntValue
;
401 case NS_ooxml::LN_CT_Settings_widowControl
:
402 m_pImpl
->m_bWidowControl
= nIntValue
;
404 case NS_ooxml::LN_CT_Settings_longerSpaceSequence
:
405 m_pImpl
->m_bLongerSpaceSequence
= nIntValue
;
407 case NS_ooxml::LN_CT_Compat_doNotExpandShiftReturn
:
408 m_pImpl
->m_bDoNotExpandShiftReturn
= true;
410 case NS_ooxml::LN_CT_Settings_displayBackgroundShape
:
411 m_pImpl
->m_bDisplayBackgroundShape
= nIntValue
;
413 case NS_ooxml::LN_CT_Compat_noLeading
:
414 m_pImpl
->m_bNoLeading
= nIntValue
!= 0;
416 case NS_ooxml::LN_CT_Settings_gutterAtTop
:
417 m_pImpl
->m_bGutterAtTop
= nIntValue
!= 0;
419 case NS_ooxml::LN_CT_Compat_doNotBreakWrappedTables
:
420 m_pImpl
->m_bDoNotBreakWrappedTables
= nIntValue
!= 0;
425 TagLogger::getInstance().element("unhandled");
431 void SettingsTable::lcl_entry(writerfilter::Reference
<Properties
>::Pointer_t ref
)
436 //returns default TabStop in 1/100th mm
437 int SettingsTable::GetDefaultTabStop() const
439 return ConversionHelper::convertTwipToMM100( m_pImpl
->m_nDefaultTabStop
);
442 bool SettingsTable::GetLinkStyles() const
444 return m_pImpl
->m_bLinkStyles
;
447 sal_Int16
SettingsTable::GetZoomFactor() const
449 return m_pImpl
->m_nZoomFactor
;
452 sal_Int16
SettingsTable::GetZoomType() const { return m_pImpl
->m_nZoomType
; }
454 Id
SettingsTable::GetView() const
456 return m_pImpl
->m_nView
;
459 bool SettingsTable::GetUsePrinterMetrics() const
461 return m_pImpl
->m_bUsePrinterMetrics
;
464 bool SettingsTable::GetEvenAndOddHeaders() const
466 return m_pImpl
->m_bEvenAndOddHeaders
;
469 bool SettingsTable::GetEmbedTrueTypeFonts() const
471 return m_pImpl
->embedTrueTypeFonts
;
474 bool SettingsTable::GetEmbedSystemFonts() const
476 return m_pImpl
->embedSystemFonts
;
479 bool SettingsTable::GetDoNotUseHTMLParagraphAutoSpacing() const
481 return m_pImpl
->m_bDoNotUseHTMLParagraphAutoSpacing
;
484 bool SettingsTable::GetNoColumnBalance() const
486 return m_pImpl
->m_bNoColumnBalance
;
489 bool SettingsTable::GetSplitPgBreakAndParaMark() const
491 return m_pImpl
->m_bSplitPgBreakAndParaMark
;
494 bool SettingsTable::GetMirrorMarginSettings() const
496 return m_pImpl
->m_bMirrorMargin
;
499 bool SettingsTable::GetDisplayBackgroundShape() const
501 return m_pImpl
->m_bDisplayBackgroundShape
;
504 bool SettingsTable::GetDoNotExpandShiftReturn() const
506 return m_pImpl
->m_bDoNotExpandShiftReturn
;
509 bool SettingsTable::GetProtectForm() const
511 return m_pImpl
->m_pDocumentProtection
->getProtectForm()
512 && m_pImpl
->m_pDocumentProtection
->getEnforcement();
515 bool SettingsTable::GetReadOnly() const
517 return m_pImpl
->m_pWriteProtection
->getRecommended()
518 || (m_pImpl
->m_pDocumentProtection
->getReadOnly()
519 && m_pImpl
->m_pDocumentProtection
->getEnforcement());
522 bool SettingsTable::GetNoHyphenateCaps() const
524 return m_pImpl
->m_bNoHyphenateCaps
;
527 sal_Int16
SettingsTable::GetHyphenationZone() const
529 return m_pImpl
->m_nHyphenationZone
;
532 const OUString
& SettingsTable::GetDecimalSymbol() const
534 return m_pImpl
->m_sDecimalSymbol
;
537 const OUString
& SettingsTable::GetListSeparator() const
539 return m_pImpl
->m_sListSeparator
;
543 uno::Sequence
<beans::PropertyValue
> const & SettingsTable::GetThemeFontLangProperties() const
545 return m_pImpl
->m_pThemeFontLangProps
;
548 uno::Sequence
<beans::PropertyValue
> SettingsTable::GetCompatSettings() const
550 if ( GetWordCompatibilityMode() == -1 )
552 // the default value for an undefined compatibilityMode is 12 (Word 2007)
553 uno::Sequence
<beans::PropertyValue
> aCompatSetting( comphelper::InitPropertySequence({
554 { "name", uno::Any(OUString("compatibilityMode")) },
555 { "uri", uno::Any(OUString("http://schemas.microsoft.com/office/word")) },
556 { "val", uno::Any(OUString("12")) } //12: Use word processing features specified in ECMA-376. This is the default.
559 beans::PropertyValue aValue
;
560 aValue
.Name
= "compatSetting";
561 aValue
.Value
<<= aCompatSetting
;
563 m_pImpl
->m_aCompatSettings
.push_back(aValue
);
566 return comphelper::containerToSequence(m_pImpl
->m_aCompatSettings
);
569 uno::Sequence
<beans::PropertyValue
> SettingsTable::GetDocumentProtectionSettings() const
571 return m_pImpl
->m_pDocumentProtection
->toSequence();
574 uno::Sequence
<beans::PropertyValue
> SettingsTable::GetWriteProtectionSettings() const
576 return m_pImpl
->m_pWriteProtection
->toSequence();
579 const OUString
& SettingsTable::GetCurrentDatabaseDataSource() const
581 return m_pImpl
->m_sCurrentDatabaseDataSource
;
584 static bool lcl_isDefault(const uno::Reference
<beans::XPropertyState
>& xPropertyState
, const OUString
& rPropertyName
)
586 return xPropertyState
->getPropertyState(rPropertyName
) == beans::PropertyState_DEFAULT_VALUE
;
589 void SettingsTable::ApplyProperties(uno::Reference
<text::XTextDocument
> const& xDoc
)
591 uno::Reference
< beans::XPropertySet
> xDocProps( xDoc
, uno::UNO_QUERY
);
592 uno::Reference
<lang::XMultiServiceFactory
> xTextFactory(xDoc
, uno::UNO_QUERY_THROW
);
593 uno::Reference
<beans::XPropertySet
> xDocumentSettings(xTextFactory
->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY_THROW
);
595 // Shared between DOCX and RTF, unconditional flags.
596 xDocumentSettings
->setPropertyValue("TableRowKeep", uno::Any(true));
597 xDocumentSettings
->setPropertyValue("AddVerticalFrameOffsets", uno::Any(true));
599 if (GetWordCompatibilityMode() <= 14)
601 xDocumentSettings
->setPropertyValue("MsWordCompMinLineHeightByFly", uno::Any(true));
602 xDocumentSettings
->setPropertyValue("TabOverMargin", uno::Any(true));
605 // Show changes value
608 bool bHideChanges
= !m_pImpl
->m_bShowInsDelChanges
|| !m_pImpl
->m_bShowMarkupChanges
;
609 xDocProps
->setPropertyValue("ShowChanges", uno::Any( !bHideChanges
|| m_pImpl
->m_bShowFormattingChanges
) );
612 // Record changes value
615 xDocProps
->setPropertyValue("RecordChanges", uno::Any( m_pImpl
->m_bRecordChanges
) );
616 // Password protected Record changes
617 if (m_pImpl
->m_bRecordChanges
&& m_pImpl
->m_pDocumentProtection
->getRedlineProtection()
618 && m_pImpl
->m_pDocumentProtection
->getEnforcement())
620 // use dummy protection key to forbid disabling of Record changes without a notice
621 // (extending the recent GrabBag support) TODO support password verification...
622 css::uno::Sequence
<sal_Int8
> aDummyKey
{ 1 };
623 xDocProps
->setPropertyValue("RedlineProtectionKey", uno::Any( aDummyKey
));
627 // Create or overwrite DocVars based on found in settings
628 if (m_pImpl
->m_aDocVars
.size())
630 uno::Reference
< text::XTextFieldsSupplier
> xFieldsSupplier(xDoc
, uno::UNO_QUERY_THROW
);
631 uno::Reference
< container::XNameAccess
> xFieldMasterAccess
= xFieldsSupplier
->getTextFieldMasters();
632 for (const auto& docVar
: m_pImpl
->m_aDocVars
)
634 uno::Reference
< beans::XPropertySet
> xMaster
;
635 OUString
sFieldMasterService("com.sun.star.text.FieldMaster.User." + docVar
.first
);
637 // Find or create Field Master
638 if (xFieldMasterAccess
->hasByName(sFieldMasterService
))
640 xMaster
.set(xFieldMasterAccess
->getByName(sFieldMasterService
), uno::UNO_QUERY_THROW
);
644 xMaster
.set(xTextFactory
->createInstance("com.sun.star.text.FieldMaster.User"), uno::UNO_QUERY_THROW
);
645 xMaster
->setPropertyValue(getPropertyName(PROP_NAME
), uno::Any(docVar
.first
));
646 uno::Reference
<text::XDependentTextField
> xField(
647 xTextFactory
->createInstance("com.sun.star.text.TextField.User"),
649 xField
->attachTextFieldMaster(xMaster
);
652 xMaster
->setPropertyValue(getPropertyName(PROP_CONTENT
), uno::Any(docVar
.second
));
656 if (m_pImpl
->m_bDoNotBreakWrappedTables
)
658 // Map <w:doNotBreakWrappedTables> to the DoNotBreakWrappedTables compat flag.
659 xDocumentSettings
->setPropertyValue("DoNotBreakWrappedTables", uno::Any(true));
662 if (m_pImpl
->m_bAllowTextAfterFloatingTableBreak
)
664 xDocumentSettings
->setPropertyValue("AllowTextAfterFloatingTableBreak", uno::Any(true));
667 // Auto hyphenation: turns on hyphenation by default, <w:suppressAutoHyphens/> may still disable it at a paragraph level.
668 // Situation is similar for RTF_WIDOWCTRL, which turns on widow / orphan control by default.
669 if (!(m_pImpl
->m_bAutoHyphenation
|| m_pImpl
->m_bNoHyphenateCaps
|| m_pImpl
->m_bWidowControl
))
672 uno::Reference
<style::XStyleFamiliesSupplier
> xStyleFamiliesSupplier(xDoc
, uno::UNO_QUERY
);
673 if (!xStyleFamiliesSupplier
.is())
676 uno::Reference
<container::XNameAccess
> xStyleFamilies
= xStyleFamiliesSupplier
->getStyleFamilies();
677 uno::Reference
<container::XNameContainer
> xParagraphStyles
= xStyleFamilies
->getByName("ParagraphStyles").get
< uno::Reference
<container::XNameContainer
> >();
678 uno::Reference
<style::XStyle
> xDefault
= xParagraphStyles
->getByName("Standard").get
< uno::Reference
<style::XStyle
> >();
679 uno::Reference
<beans::XPropertyState
> xPropertyState(xDefault
, uno::UNO_QUERY
);
680 if (m_pImpl
->m_bAutoHyphenation
&& lcl_isDefault(xPropertyState
, "ParaIsHyphenation"))
682 uno::Reference
<beans::XPropertySet
> xPropertySet(xDefault
, uno::UNO_QUERY
);
683 xPropertySet
->setPropertyValue("ParaIsHyphenation", uno::Any(true));
685 if (m_pImpl
->m_bNoHyphenateCaps
)
687 uno::Reference
<beans::XPropertySet
> xPropertySet(xDefault
, uno::UNO_QUERY
);
688 xPropertySet
->setPropertyValue("ParaHyphenationNoCaps", uno::Any(true));
690 if (m_pImpl
->m_nHyphenationZone
)
692 uno::Reference
<beans::XPropertySet
> xPropertySet(xDefault
, uno::UNO_QUERY
);
693 xPropertySet
->setPropertyValue("ParaHyphenationZone", uno::Any(GetHyphenationZone()));
695 if (m_pImpl
->m_bWidowControl
&& lcl_isDefault(xPropertyState
, "ParaWidows") && lcl_isDefault(xPropertyState
, "ParaOrphans"))
697 uno::Reference
<beans::XPropertySet
> xPropertySet(xDefault
, uno::UNO_QUERY
);
698 uno::Any
aAny(static_cast<sal_Int8
>(2));
699 xPropertySet
->setPropertyValue("ParaWidows", aAny
);
700 xPropertySet
->setPropertyValue("ParaOrphans", aAny
);
704 bool SettingsTable::GetCompatSettingValue( std::u16string_view sCompatName
) const
707 for (const auto& rProp
: m_pImpl
->m_aCompatSettings
)
709 if (rProp
.Name
== "compatSetting") //always true
711 css::uno::Sequence
<css::beans::PropertyValue
> aCurrentCompatSettings
;
712 rProp
.Value
>>= aCurrentCompatSettings
;
715 aCurrentCompatSettings
[0].Value
>>= sName
;
716 if ( sName
!= sCompatName
)
720 aCurrentCompatSettings
[1].Value
>>= sUri
;
721 if ( sUri
!= "http://schemas.microsoft.com/office/word" )
725 aCurrentCompatSettings
[2].Value
>>= sVal
;
726 // if repeated, what happens? Last one wins
727 bRet
= sVal
.toBoolean();
734 //Keep this function in-sync with the one in sw/.../docxattributeoutput.cxx
735 sal_Int32
SettingsTable::GetWordCompatibilityMode() const
737 if ( m_pImpl
->m_nWordCompatibilityMode
!= -1 )
738 return m_pImpl
->m_nWordCompatibilityMode
;
740 for (const auto& rProp
: m_pImpl
->m_aCompatSettings
)
742 if (rProp
.Name
== "compatSetting") //always true
744 css::uno::Sequence
<css::beans::PropertyValue
> aCurrentCompatSettings
;
745 rProp
.Value
>>= aCurrentCompatSettings
;
748 aCurrentCompatSettings
[0].Value
>>= sName
;
749 if ( sName
!= "compatibilityMode" )
753 aCurrentCompatSettings
[1].Value
>>= sUri
;
754 if ( sUri
!= "http://schemas.microsoft.com/office/word" )
758 aCurrentCompatSettings
[2].Value
>>= sVal
;
759 const sal_Int32 nValidMode
= sVal
.toInt32();
760 // if repeated, highest mode wins in MS Word. 11 is the first valid mode.
761 if ( nValidMode
> 10 && nValidMode
> m_pImpl
->m_nWordCompatibilityMode
)
762 m_pImpl
->m_nWordCompatibilityMode
= nValidMode
;
766 return m_pImpl
->m_nWordCompatibilityMode
;
769 bool SettingsTable::GetLongerSpaceSequence() const
771 return m_pImpl
->m_bLongerSpaceSequence
;
774 bool SettingsTable::GetNoLeading() const
776 return m_pImpl
->m_bNoLeading
;
779 bool SettingsTable::GetGutterAtTop() const { return m_pImpl
->m_bGutterAtTop
; }
781 bool SettingsTable::GetRecordChanges() const { return m_pImpl
->m_bRecordChanges
; }
784 } //namespace writerfilter
786 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */