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>
40 #include "ConversionHelper.hxx"
41 #include "DomainMapper.hxx"
44 using namespace com::sun::star
;
46 namespace writerfilter
{
49 /// Maps OOXML <w:zoom w:val="..."> to SvxZoomType.
50 sal_Int16
lcl_GetZoomType(Id nType
)
54 case NS_ooxml::LN_Value_doc_ST_Zoom_fullPage
:
55 return sal_Int16(SvxZoomType::WHOLEPAGE
);
56 case NS_ooxml::LN_Value_doc_ST_Zoom_bestFit
:
57 return sal_Int16(SvxZoomType::PAGEWIDTH
);
58 case NS_ooxml::LN_Value_doc_ST_Zoom_textFit
:
59 return sal_Int16(SvxZoomType::OPTIMAL
);
62 return sal_Int16(SvxZoomType::PERCENT
);
69 struct SettingsTable_Impl
71 int m_nDefaultTabStop
;
73 bool m_bRecordChanges
;
74 bool m_bShowInsDelChanges
;
75 bool m_bShowFormattingChanges
;
76 bool m_bShowMarkupChanges
;
78 sal_Int16 m_nZoomFactor
;
79 sal_Int16 m_nZoomType
= 0;
80 sal_Int32 m_nWordCompatibilityMode
;
82 bool m_bEvenAndOddHeaders
;
83 bool m_bUsePrinterMetrics
;
84 bool embedTrueTypeFonts
;
85 bool embedSystemFonts
;
86 bool m_bDoNotUseHTMLParagraphAutoSpacing
;
87 bool m_bNoColumnBalance
;
88 bool m_bAutoHyphenation
;
89 bool m_bNoHyphenateCaps
;
90 sal_Int16 m_nHyphenationZone
;
92 bool m_bLongerSpaceSequence
;
93 bool m_bSplitPgBreakAndParaMark
;
95 bool m_bDoNotExpandShiftReturn
;
96 bool m_bDisplayBackgroundShape
;
97 bool m_bNoLeading
= false;
98 OUString m_sDecimalSymbol
;
99 OUString m_sListSeparator
;
100 std::vector
<std::pair
<OUString
, OUString
>> m_aDocVars
;
102 uno::Sequence
<beans::PropertyValue
> m_pThemeFontLangProps
;
104 std::vector
<beans::PropertyValue
> m_aCompatSettings
;
105 uno::Sequence
<beans::PropertyValue
> m_pCurrentCompatSetting
;
106 OUString m_sCurrentDatabaseDataSource
;
108 std::shared_ptr
<DocumentProtection
> m_pDocumentProtection
;
109 std::shared_ptr
<WriteProtection
> m_pWriteProtection
;
110 bool m_bGutterAtTop
= false;
111 bool m_bDoNotBreakWrappedTables
= false;
113 SettingsTable_Impl() :
114 m_nDefaultTabStop( 720 ) //default is 1/2 in
115 , m_bRecordChanges(false)
116 , m_bShowInsDelChanges(true)
117 , m_bShowFormattingChanges(false)
118 , m_bShowMarkupChanges(true)
119 , m_bLinkStyles(false)
121 , m_nWordCompatibilityMode(-1)
123 , m_bEvenAndOddHeaders(false)
124 , m_bUsePrinterMetrics(false)
125 , embedTrueTypeFonts(false)
126 , embedSystemFonts(false)
127 , m_bDoNotUseHTMLParagraphAutoSpacing(false)
128 , m_bNoColumnBalance(false)
129 , m_bAutoHyphenation(false)
130 , m_bNoHyphenateCaps(false)
131 , m_nHyphenationZone(0)
132 , m_bWidowControl(false)
133 , m_bLongerSpaceSequence(false)
134 , m_bSplitPgBreakAndParaMark(false)
135 , m_bMirrorMargin(false)
136 , m_bDoNotExpandShiftReturn(false)
137 , m_bDisplayBackgroundShape(false)
138 , m_sDecimalSymbol(".")
139 , m_sListSeparator(",")
140 , m_pThemeFontLangProps(3)
141 , m_pCurrentCompatSetting(3)
145 SettingsTable::SettingsTable(const DomainMapper
& rDomainMapper
)
146 : LoggedProperties("SettingsTable")
147 , LoggedTable("SettingsTable")
148 , m_pImpl( new SettingsTable_Impl
)
150 if (rDomainMapper
.IsRTFImport())
152 // HTML paragraph auto-spacing is opt-in for RTF, opt-out for OOXML.
153 m_pImpl
->m_bDoNotUseHTMLParagraphAutoSpacing
= true;
154 // Longer space sequence is opt-in for RTF, and not in OOXML.
155 m_pImpl
->m_bLongerSpaceSequence
= true;
156 m_pImpl
->m_bDoNotBreakWrappedTables
= true;
158 m_pImpl
->m_pDocumentProtection
= std::make_shared
<DocumentProtection
>();
159 m_pImpl
->m_pWriteProtection
= std::make_shared
<WriteProtection
>();
162 SettingsTable::~SettingsTable()
166 void SettingsTable::lcl_attribute(Id nName
, Value
& val
)
168 int nIntValue
= val
.getInt();
169 OUString sStringValue
= val
.getString();
173 case NS_ooxml::LN_CT_Zoom_percent
:
174 m_pImpl
->m_nZoomFactor
= nIntValue
;
176 case NS_ooxml::LN_CT_Zoom_val
:
177 m_pImpl
->m_nZoomType
= lcl_GetZoomType(nIntValue
);
179 case NS_ooxml::LN_CT_Language_val
:
180 m_pImpl
->m_pThemeFontLangProps
.getArray()[0]
181 = comphelper::makePropertyValue("val", sStringValue
);
183 case NS_ooxml::LN_CT_Language_eastAsia
:
184 m_pImpl
->m_pThemeFontLangProps
.getArray()[1]
185 = comphelper::makePropertyValue("eastAsia", sStringValue
);
187 case NS_ooxml::LN_CT_Language_bidi
:
188 m_pImpl
->m_pThemeFontLangProps
.getArray()[2]
189 = comphelper::makePropertyValue("bidi", sStringValue
);
191 case NS_ooxml::LN_CT_View_val
:
192 m_pImpl
->m_nView
= nIntValue
;
194 case NS_ooxml::LN_CT_DocVar_name
:
195 m_pImpl
->m_aDocVars
.back().first
= sStringValue
;
197 case NS_ooxml::LN_CT_DocVar_val
:
198 m_pImpl
->m_aDocVars
.back().second
= sStringValue
;
200 case NS_ooxml::LN_CT_CompatSetting_name
:
201 m_pImpl
->m_pCurrentCompatSetting
.getArray()[0]
202 = comphelper::makePropertyValue("name", sStringValue
);
204 case NS_ooxml::LN_CT_CompatSetting_uri
:
205 m_pImpl
->m_pCurrentCompatSetting
.getArray()[1]
206 = comphelper::makePropertyValue("uri", sStringValue
);
208 case NS_ooxml::LN_CT_CompatSetting_val
:
209 m_pImpl
->m_pCurrentCompatSetting
.getArray()[2]
210 = comphelper::makePropertyValue("val", sStringValue
);
212 case NS_ooxml::LN_CT_TrackChangesView_insDel
:
213 m_pImpl
->m_bShowInsDelChanges
= (nIntValue
!= 0);
215 case NS_ooxml::LN_CT_TrackChangesView_formatting
:
216 m_pImpl
->m_bShowFormattingChanges
= (nIntValue
!= 0);
218 case NS_ooxml::LN_CT_TrackChangesView_markup
:
219 m_pImpl
->m_bShowMarkupChanges
= (nIntValue
!= 0);
224 TagLogger::getInstance().element("unhandled");
230 void SettingsTable::lcl_sprm(Sprm
& rSprm
)
232 sal_uInt32 nSprmId
= rSprm
.getId();
234 Value::Pointer_t pValue
= rSprm
.getValue();
235 sal_Int32 nIntValue
= pValue
->getInt();
239 case NS_ooxml::LN_CT_Settings_zoom
: // 92469;
240 case NS_ooxml::LN_CT_Settings_proofState
: // 92489;
241 case NS_ooxml::LN_CT_Settings_attachedTemplate
: // 92491;
242 case NS_ooxml::LN_CT_Settings_hdrShapeDefaults
: // 92544;
243 case NS_ooxml::LN_CT_Settings_footnotePr
: // 92545;
244 case NS_ooxml::LN_CT_Settings_endnotePr
: // 92546;
245 case NS_ooxml::LN_CT_Settings_compat
: // 92547;
246 case NS_ooxml::LN_CT_Settings_themeFontLang
: // 92552;
247 case NS_ooxml::LN_CT_Settings_shapeDefaults
: // 92560;
248 case NS_ooxml::LN_CT_Settings_view
:
249 //PropertySetValues - need to be resolved
251 resolveSprmProps(*this, rSprm
);
254 case NS_ooxml::LN_CT_Settings_stylePaneFormatFilter
: // 92493;
256 case NS_ooxml::LN_CT_Settings_defaultTabStop
: // 92505;
257 m_pImpl
->m_nDefaultTabStop
= nIntValue
;
259 case NS_ooxml::LN_CT_Settings_linkStyles
: // 92663;
260 m_pImpl
->m_bLinkStyles
= nIntValue
;
262 case NS_ooxml::LN_CT_Settings_evenAndOddHeaders
:
263 m_pImpl
->m_bEvenAndOddHeaders
= nIntValue
;
265 case NS_ooxml::LN_CT_Settings_noPunctuationKerning
: // 92526;
267 case NS_ooxml::LN_CT_Settings_characterSpacingControl
: // 92527;
268 // doNotCompress, compressPunctuation, compressPunctuationAndJapaneseKana
270 case NS_ooxml::LN_CT_Settings_doNotIncludeSubdocsInStats
: // 92554; // Do Not Include Content in Text Boxes, Footnotes, and Endnotes in Document Statistics)
272 case NS_ooxml::LN_CT_Settings_decimalSymbol
: // 92562;
273 m_pImpl
->m_sDecimalSymbol
= pValue
->getString();
275 case NS_ooxml::LN_CT_Settings_listSeparator
: // 92563;
276 m_pImpl
->m_sListSeparator
= pValue
->getString();
278 case NS_ooxml::LN_CT_Settings_rsids
: // 92549; revision save Ids - probably not necessary
280 case NS_ooxml::LN_CT_Settings_hyphenationZone
: // 92508;
281 m_pImpl
->m_nHyphenationZone
= nIntValue
;
283 case NS_ooxml::LN_CT_Compat_useFELayout
: // 92422;
284 // useFELayout (Do Not Bypass East Asian/Complex Script Layout Code - support of old versions of Word - ignored)
286 case NS_ooxml::LN_CT_Settings_trackRevisions
:
288 m_pImpl
->m_bRecordChanges
= bool(rSprm
.getValue( )->getInt( ) );
291 case NS_ooxml::LN_CT_Settings_revisionView
:
292 resolveSprmProps(*this, rSprm
);
294 case NS_ooxml::LN_CT_Settings_documentProtection
:
295 resolveSprmProps(*(m_pImpl
->m_pDocumentProtection
), rSprm
);
297 case NS_ooxml::LN_CT_Settings_writeProtection
:
298 resolveSprmProps(*(m_pImpl
->m_pWriteProtection
), rSprm
);
300 case NS_ooxml::LN_CT_Compat_usePrinterMetrics
:
301 m_pImpl
->m_bUsePrinterMetrics
= nIntValue
;
303 case NS_ooxml::LN_CT_Settings_embedTrueTypeFonts
:
304 m_pImpl
->embedTrueTypeFonts
= nIntValue
!= 0;
306 case NS_ooxml::LN_CT_Settings_embedSystemFonts
:
307 m_pImpl
->embedSystemFonts
= nIntValue
!= 0;
309 case NS_ooxml::LN_CT_Compat_doNotUseHTMLParagraphAutoSpacing
:
310 m_pImpl
->m_bDoNotUseHTMLParagraphAutoSpacing
= nIntValue
;
312 case NS_ooxml::LN_CT_Compat_splitPgBreakAndParaMark
:
313 m_pImpl
->m_bSplitPgBreakAndParaMark
= nIntValue
;
315 case NS_ooxml::LN_CT_Settings_mirrorMargins
:
316 m_pImpl
->m_bMirrorMargin
= nIntValue
;
318 case NS_ooxml::LN_CT_Settings_mailMerge
:
320 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
322 pProperties
->resolve(*this);
325 case NS_ooxml::LN_CT_MailMerge_query
:
327 // try to get the "database.table" name from the query saved previously
328 OUString sVal
= pValue
->getString();
329 if ( sVal
.endsWith("$") && sVal
.indexOf(".dbo.") > 0 )
331 sal_Int32 nSpace
= sVal
.lastIndexOf(' ');
332 sal_Int32 nDbo
= sVal
.lastIndexOf(".dbo.");
333 if ( nSpace
> 0 && nSpace
< nDbo
- 1 )
335 m_pImpl
->m_sCurrentDatabaseDataSource
= OUString::Concat(sVal
.subView(nSpace
+ 1, nDbo
- nSpace
- 1)) +
336 sVal
.subView(nDbo
+ 4, sVal
.getLength() - nDbo
- 5);
341 case NS_ooxml::LN_CT_Compat_compatSetting
:
343 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
346 pProperties
->resolve(*this);
348 beans::PropertyValue aValue
;
349 aValue
.Name
= "compatSetting";
350 aValue
.Value
<<= m_pImpl
->m_pCurrentCompatSetting
;
351 m_pImpl
->m_aCompatSettings
.push_back(aValue
);
355 case NS_ooxml::LN_CT_Settings_docVars
:
357 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
360 pProperties
->resolve(*this);
364 case NS_ooxml::LN_CT_DocVar
:
366 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
369 m_pImpl
->m_aDocVars
.push_back(std::make_pair(OUString(), OUString()));
370 pProperties
->resolve(*this);
374 case NS_ooxml::LN_CT_Compat_noColumnBalance
:
375 m_pImpl
->m_bNoColumnBalance
= nIntValue
;
377 case NS_ooxml::LN_CT_Settings_autoHyphenation
:
378 m_pImpl
->m_bAutoHyphenation
= nIntValue
;
380 case NS_ooxml::LN_CT_Settings_doNotHyphenateCaps
:
381 m_pImpl
->m_bNoHyphenateCaps
= nIntValue
;
383 case NS_ooxml::LN_CT_Settings_widowControl
:
384 m_pImpl
->m_bWidowControl
= nIntValue
;
386 case NS_ooxml::LN_CT_Settings_longerSpaceSequence
:
387 m_pImpl
->m_bLongerSpaceSequence
= nIntValue
;
389 case NS_ooxml::LN_CT_Compat_doNotExpandShiftReturn
:
390 m_pImpl
->m_bDoNotExpandShiftReturn
= true;
392 case NS_ooxml::LN_CT_Settings_displayBackgroundShape
:
393 m_pImpl
->m_bDisplayBackgroundShape
= nIntValue
;
395 case NS_ooxml::LN_CT_Compat_noLeading
:
396 m_pImpl
->m_bNoLeading
= nIntValue
!= 0;
398 case NS_ooxml::LN_CT_Settings_gutterAtTop
:
399 m_pImpl
->m_bGutterAtTop
= nIntValue
!= 0;
401 case NS_ooxml::LN_CT_Compat_doNotBreakWrappedTables
:
402 m_pImpl
->m_bDoNotBreakWrappedTables
= nIntValue
!= 0;
407 TagLogger::getInstance().element("unhandled");
413 void SettingsTable::lcl_entry(writerfilter::Reference
<Properties
>::Pointer_t ref
)
418 //returns default TabStop in 1/100th mm
419 int SettingsTable::GetDefaultTabStop() const
421 return ConversionHelper::convertTwipToMM100( m_pImpl
->m_nDefaultTabStop
);
424 bool SettingsTable::GetLinkStyles() const
426 return m_pImpl
->m_bLinkStyles
;
429 sal_Int16
SettingsTable::GetZoomFactor() const
431 return m_pImpl
->m_nZoomFactor
;
434 sal_Int16
SettingsTable::GetZoomType() const { return m_pImpl
->m_nZoomType
; }
436 Id
SettingsTable::GetView() const
438 return m_pImpl
->m_nView
;
441 bool SettingsTable::GetUsePrinterMetrics() const
443 return m_pImpl
->m_bUsePrinterMetrics
;
446 bool SettingsTable::GetEvenAndOddHeaders() const
448 return m_pImpl
->m_bEvenAndOddHeaders
;
451 bool SettingsTable::GetEmbedTrueTypeFonts() const
453 return m_pImpl
->embedTrueTypeFonts
;
456 bool SettingsTable::GetEmbedSystemFonts() const
458 return m_pImpl
->embedSystemFonts
;
461 bool SettingsTable::GetDoNotUseHTMLParagraphAutoSpacing() const
463 return m_pImpl
->m_bDoNotUseHTMLParagraphAutoSpacing
;
466 bool SettingsTable::GetNoColumnBalance() const
468 return m_pImpl
->m_bNoColumnBalance
;
471 bool SettingsTable::GetSplitPgBreakAndParaMark() const
473 return m_pImpl
->m_bSplitPgBreakAndParaMark
;
476 bool SettingsTable::GetMirrorMarginSettings() const
478 return m_pImpl
->m_bMirrorMargin
;
481 bool SettingsTable::GetDisplayBackgroundShape() const
483 return m_pImpl
->m_bDisplayBackgroundShape
;
486 bool SettingsTable::GetDoNotExpandShiftReturn() const
488 return m_pImpl
->m_bDoNotExpandShiftReturn
;
491 bool SettingsTable::GetProtectForm() const
493 return m_pImpl
->m_pDocumentProtection
->getProtectForm()
494 && m_pImpl
->m_pDocumentProtection
->getEnforcement();
497 bool SettingsTable::GetReadOnly() const
499 return m_pImpl
->m_pWriteProtection
->getRecommended()
500 || (m_pImpl
->m_pDocumentProtection
->getReadOnly()
501 && m_pImpl
->m_pDocumentProtection
->getEnforcement());
504 bool SettingsTable::GetNoHyphenateCaps() const
506 return m_pImpl
->m_bNoHyphenateCaps
;
509 sal_Int16
SettingsTable::GetHyphenationZone() const
511 return m_pImpl
->m_nHyphenationZone
;
514 const OUString
& SettingsTable::GetDecimalSymbol() const
516 return m_pImpl
->m_sDecimalSymbol
;
519 const OUString
& SettingsTable::GetListSeparator() const
521 return m_pImpl
->m_sListSeparator
;
525 uno::Sequence
<beans::PropertyValue
> const & SettingsTable::GetThemeFontLangProperties() const
527 return m_pImpl
->m_pThemeFontLangProps
;
530 uno::Sequence
<beans::PropertyValue
> SettingsTable::GetCompatSettings() const
532 if ( GetWordCompatibilityMode() == -1 )
534 // the default value for an undefined compatibilityMode is 12 (Word 2007)
535 uno::Sequence
<beans::PropertyValue
> aCompatSetting( comphelper::InitPropertySequence({
536 { "name", uno::Any(OUString("compatibilityMode")) },
537 { "uri", uno::Any(OUString("http://schemas.microsoft.com/office/word")) },
538 { "val", uno::Any(OUString("12")) } //12: Use word processing features specified in ECMA-376. This is the default.
541 beans::PropertyValue aValue
;
542 aValue
.Name
= "compatSetting";
543 aValue
.Value
<<= aCompatSetting
;
545 m_pImpl
->m_aCompatSettings
.push_back(aValue
);
548 return comphelper::containerToSequence(m_pImpl
->m_aCompatSettings
);
551 uno::Sequence
<beans::PropertyValue
> SettingsTable::GetDocumentProtectionSettings() const
553 return m_pImpl
->m_pDocumentProtection
->toSequence();
556 uno::Sequence
<beans::PropertyValue
> SettingsTable::GetWriteProtectionSettings() const
558 return m_pImpl
->m_pWriteProtection
->toSequence();
561 const OUString
& SettingsTable::GetCurrentDatabaseDataSource() const
563 return m_pImpl
->m_sCurrentDatabaseDataSource
;
566 static bool lcl_isDefault(const uno::Reference
<beans::XPropertyState
>& xPropertyState
, const OUString
& rPropertyName
)
568 return xPropertyState
->getPropertyState(rPropertyName
) == beans::PropertyState_DEFAULT_VALUE
;
571 void SettingsTable::ApplyProperties(uno::Reference
<text::XTextDocument
> const& xDoc
)
573 uno::Reference
< beans::XPropertySet
> xDocProps( xDoc
, uno::UNO_QUERY
);
574 uno::Reference
<lang::XMultiServiceFactory
> xTextFactory(xDoc
, uno::UNO_QUERY_THROW
);
575 uno::Reference
<beans::XPropertySet
> xDocumentSettings(xTextFactory
->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY_THROW
);
577 // Shared between DOCX and RTF, unconditional flags.
578 xDocumentSettings
->setPropertyValue("TableRowKeep", uno::Any(true));
579 xDocumentSettings
->setPropertyValue("AddVerticalFrameOffsets", uno::Any(true));
581 if (GetWordCompatibilityMode() <= 14)
583 xDocumentSettings
->setPropertyValue("MsWordCompMinLineHeightByFly", uno::Any(true));
584 xDocumentSettings
->setPropertyValue("TabOverMargin", uno::Any(true));
587 // Show changes value
590 bool bHideChanges
= !m_pImpl
->m_bShowInsDelChanges
|| !m_pImpl
->m_bShowMarkupChanges
;
591 xDocProps
->setPropertyValue("ShowChanges", uno::Any( !bHideChanges
|| m_pImpl
->m_bShowFormattingChanges
) );
594 // Record changes value
597 xDocProps
->setPropertyValue("RecordChanges", uno::Any( m_pImpl
->m_bRecordChanges
) );
598 // Password protected Record changes
599 if (m_pImpl
->m_bRecordChanges
&& m_pImpl
->m_pDocumentProtection
->getRedlineProtection()
600 && m_pImpl
->m_pDocumentProtection
->getEnforcement())
602 // use dummy protection key to forbid disabling of Record changes without a notice
603 // (extending the recent GrabBag support) TODO support password verification...
604 css::uno::Sequence
<sal_Int8
> aDummyKey
{ 1 };
605 xDocProps
->setPropertyValue("RedlineProtectionKey", uno::Any( aDummyKey
));
609 // Create or overwrite DocVars based on found in settings
610 if (m_pImpl
->m_aDocVars
.size())
612 uno::Reference
< text::XTextFieldsSupplier
> xFieldsSupplier(xDoc
, uno::UNO_QUERY_THROW
);
613 uno::Reference
< container::XNameAccess
> xFieldMasterAccess
= xFieldsSupplier
->getTextFieldMasters();
614 for (const auto& docVar
: m_pImpl
->m_aDocVars
)
616 uno::Reference
< beans::XPropertySet
> xMaster
;
617 OUString
sFieldMasterService("com.sun.star.text.FieldMaster.User." + docVar
.first
);
619 // Find or create Field Master
620 if (xFieldMasterAccess
->hasByName(sFieldMasterService
))
622 xMaster
.set(xFieldMasterAccess
->getByName(sFieldMasterService
), uno::UNO_QUERY_THROW
);
626 xMaster
.set(xTextFactory
->createInstance("com.sun.star.text.FieldMaster.User"), uno::UNO_QUERY_THROW
);
627 xMaster
->setPropertyValue(getPropertyName(PROP_NAME
), uno::Any(docVar
.first
));
628 uno::Reference
<text::XDependentTextField
> xField(
629 xTextFactory
->createInstance("com.sun.star.text.TextField.User"),
631 xField
->attachTextFieldMaster(xMaster
);
634 xMaster
->setPropertyValue(getPropertyName(PROP_CONTENT
), uno::Any(docVar
.second
));
638 if (m_pImpl
->m_bDoNotBreakWrappedTables
)
640 // Map <w:doNotBreakWrappedTables> to the DoNotBreakWrappedTables compat flag.
641 xDocumentSettings
->setPropertyValue("DoNotBreakWrappedTables", uno::Any(true));
644 // Auto hyphenation: turns on hyphenation by default, <w:suppressAutoHyphens/> may still disable it at a paragraph level.
645 // Situation is similar for RTF_WIDOWCTRL, which turns on widow / orphan control by default.
646 if (!(m_pImpl
->m_bAutoHyphenation
|| m_pImpl
->m_bNoHyphenateCaps
|| m_pImpl
->m_bWidowControl
))
649 uno::Reference
<style::XStyleFamiliesSupplier
> xStyleFamiliesSupplier(xDoc
, uno::UNO_QUERY
);
650 if (!xStyleFamiliesSupplier
.is())
653 uno::Reference
<container::XNameAccess
> xStyleFamilies
= xStyleFamiliesSupplier
->getStyleFamilies();
654 uno::Reference
<container::XNameContainer
> xParagraphStyles
= xStyleFamilies
->getByName("ParagraphStyles").get
< uno::Reference
<container::XNameContainer
> >();
655 uno::Reference
<style::XStyle
> xDefault
= xParagraphStyles
->getByName("Standard").get
< uno::Reference
<style::XStyle
> >();
656 uno::Reference
<beans::XPropertyState
> xPropertyState(xDefault
, uno::UNO_QUERY
);
657 if (m_pImpl
->m_bAutoHyphenation
&& lcl_isDefault(xPropertyState
, "ParaIsHyphenation"))
659 uno::Reference
<beans::XPropertySet
> xPropertySet(xDefault
, uno::UNO_QUERY
);
660 xPropertySet
->setPropertyValue("ParaIsHyphenation", uno::Any(true));
662 if (m_pImpl
->m_bNoHyphenateCaps
)
664 uno::Reference
<beans::XPropertySet
> xPropertySet(xDefault
, uno::UNO_QUERY
);
665 xPropertySet
->setPropertyValue("ParaHyphenationNoCaps", uno::Any(true));
667 if (m_pImpl
->m_nHyphenationZone
)
669 uno::Reference
<beans::XPropertySet
> xPropertySet(xDefault
, uno::UNO_QUERY
);
670 xPropertySet
->setPropertyValue("ParaHyphenationZone", uno::Any(GetHyphenationZone()));
672 if (m_pImpl
->m_bWidowControl
&& lcl_isDefault(xPropertyState
, "ParaWidows") && lcl_isDefault(xPropertyState
, "ParaOrphans"))
674 uno::Reference
<beans::XPropertySet
> xPropertySet(xDefault
, uno::UNO_QUERY
);
675 uno::Any
aAny(static_cast<sal_Int8
>(2));
676 xPropertySet
->setPropertyValue("ParaWidows", aAny
);
677 xPropertySet
->setPropertyValue("ParaOrphans", aAny
);
681 bool SettingsTable::GetCompatSettingValue( std::u16string_view sCompatName
) const
684 for (const auto& rProp
: m_pImpl
->m_aCompatSettings
)
686 if (rProp
.Name
== "compatSetting") //always true
688 css::uno::Sequence
<css::beans::PropertyValue
> aCurrentCompatSettings
;
689 rProp
.Value
>>= aCurrentCompatSettings
;
692 aCurrentCompatSettings
[0].Value
>>= sName
;
693 if ( sName
!= sCompatName
)
697 aCurrentCompatSettings
[1].Value
>>= sUri
;
698 if ( sUri
!= "http://schemas.microsoft.com/office/word" )
702 aCurrentCompatSettings
[2].Value
>>= sVal
;
703 // if repeated, what happens? Last one wins
704 bRet
= sVal
.toBoolean();
711 //Keep this function in-sync with the one in sw/.../docxattributeoutput.cxx
712 sal_Int32
SettingsTable::GetWordCompatibilityMode() const
714 if ( m_pImpl
->m_nWordCompatibilityMode
!= -1 )
715 return m_pImpl
->m_nWordCompatibilityMode
;
717 for (const auto& rProp
: m_pImpl
->m_aCompatSettings
)
719 if (rProp
.Name
== "compatSetting") //always true
721 css::uno::Sequence
<css::beans::PropertyValue
> aCurrentCompatSettings
;
722 rProp
.Value
>>= aCurrentCompatSettings
;
725 aCurrentCompatSettings
[0].Value
>>= sName
;
726 if ( sName
!= "compatibilityMode" )
730 aCurrentCompatSettings
[1].Value
>>= sUri
;
731 if ( sUri
!= "http://schemas.microsoft.com/office/word" )
735 aCurrentCompatSettings
[2].Value
>>= sVal
;
736 const sal_Int32 nValidMode
= sVal
.toInt32();
737 // if repeated, highest mode wins in MS Word. 11 is the first valid mode.
738 if ( nValidMode
> 10 && nValidMode
> m_pImpl
->m_nWordCompatibilityMode
)
739 m_pImpl
->m_nWordCompatibilityMode
= nValidMode
;
743 return m_pImpl
->m_nWordCompatibilityMode
;
746 bool SettingsTable::GetLongerSpaceSequence() const
748 return m_pImpl
->m_bLongerSpaceSequence
;
751 bool SettingsTable::GetNoLeading() const
753 return m_pImpl
->m_bNoLeading
;
756 bool SettingsTable::GetGutterAtTop() const { return m_pImpl
->m_bGutterAtTop
; }
759 } //namespace writerfilter
761 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */