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 .
19 #include "StyleSheetTable.hxx"
21 #include "ConversionHelper.hxx"
22 #include "TblStylePrHandler.hxx"
23 #include "TagLogger.hxx"
24 #include "BorderHandler.hxx"
25 #include "LatentStyleHandler.hxx"
26 #include <ooxml/resourceids.hxx>
30 #include <com/sun/star/beans/XMultiPropertySet.hpp>
31 #include <com/sun/star/beans/XPropertyState.hpp>
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include <com/sun/star/container/XEnumerationAccess.hpp>
34 #include <com/sun/star/container/XNameContainer.hpp>
35 #include <com/sun/star/container/XIndexReplace.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/text/XTextDocument.hpp>
38 #include <com/sun/star/text/XTextFramesSupplier.hpp>
39 #include <com/sun/star/text/XTextTable.hpp>
40 #include <com/sun/star/style/NumberingType.hpp>
41 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
42 #include <com/sun/star/style/XStyle.hpp>
43 #include <com/sun/star/style/ParagraphAdjust.hpp>
44 #include <com/sun/star/text/WritingMode.hpp>
45 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 #include <osl/diagnose.h>
48 #include <rtl/ustrbuf.hxx>
49 #include <sal/log.hxx>
50 #include <comphelper/propertyvalue.hxx>
51 #include <comphelper/string.hxx>
52 #include <comphelper/sequence.hxx>
53 #include <comphelper/diagnose_ex.hxx>
54 #include <o3tl/sorted_vector.hxx>
56 using namespace ::com::sun::star
;
58 namespace writerfilter::dmapper
61 StyleSheetEntry::StyleSheetEntry() :
62 m_bIsDefaultStyle(false)
63 ,m_bAssignedAsChapterNumbering(false)
64 ,m_bInvalidHeight(false)
66 ,m_nStyleTypeCode(STYLE_TYPE_UNKNOWN
)
67 ,m_pProperties(new StyleSheetPropertyMap
)
68 ,m_bAutoRedefine(false)
72 StyleSheetEntry::~StyleSheetEntry()
76 TableStyleSheetEntry::TableStyleSheetEntry( StyleSheetEntry
const & rEntry
)
78 m_bIsDefaultStyle
= rEntry
.m_bIsDefaultStyle
;
79 m_bInvalidHeight
= rEntry
.m_bInvalidHeight
;
80 m_bHasUPE
= rEntry
.m_bHasUPE
;
81 m_nStyleTypeCode
= STYLE_TYPE_TABLE
;
82 m_sBaseStyleIdentifier
= rEntry
.m_sBaseStyleIdentifier
;
83 m_sNextStyleIdentifier
= rEntry
.m_sNextStyleIdentifier
;
84 m_sLinkStyleIdentifier
= rEntry
.m_sLinkStyleIdentifier
;
85 m_sStyleName
= rEntry
.m_sStyleName
;
86 m_sStyleIdentifierD
= rEntry
.m_sStyleIdentifierD
;
89 TableStyleSheetEntry::~TableStyleSheetEntry( )
93 void TableStyleSheetEntry::AddTblStylePr( TblStyleType nType
, const PropertyMapPtr
& pProps
)
95 static const int nTypesProps
= 4;
96 static const TblStyleType pTypesToFix
[nTypesProps
] =
104 static const PropertyIds pPropsToCheck
[nTypesProps
] =
112 for (int i
=0; i
< nTypesProps
; ++i
)
114 if ( nType
== pTypesToFix
[i
] )
116 PropertyIds nChecked
= pPropsToCheck
[i
];
117 std::optional
<PropertyMap::Property
> pChecked
= pProps
->getProperty(nChecked
);
119 PropertyIds nInsideProp
= ( i
< 2 ) ? META_PROP_HORIZONTAL_BORDER
: META_PROP_VERTICAL_BORDER
;
120 std::optional
<PropertyMap::Property
> pInside
= pProps
->getProperty(nInsideProp
);
122 if ( pChecked
&& pInside
)
124 // In this case, remove the inside border
125 pProps
->Erase( nInsideProp
);
132 // Append the tblStylePr
133 m_aStyles
[nType
] = pProps
;
136 PropertyMapPtr
TableStyleSheetEntry::GetProperties( sal_Int32 nMask
)
138 PropertyMapPtr
pProps( new PropertyMap
);
140 // And finally get the mask ones
141 pProps
->InsertProps(GetLocalPropertiesFromMask(nMask
));
146 beans::PropertyValues
StyleSheetEntry::GetInteropGrabBagSeq() const
148 return comphelper::containerToSequence(m_aInteropGrabBag
);
151 beans::PropertyValue
StyleSheetEntry::GetInteropGrabBag()
153 beans::PropertyValue aRet
;
154 aRet
.Name
= m_sStyleIdentifierD
;
156 beans::PropertyValues aSeq
= GetInteropGrabBagSeq();
161 void StyleSheetEntry::AppendInteropGrabBag(const beans::PropertyValue
& rValue
)
163 m_aInteropGrabBag
.push_back(rValue
);
166 PropertyMapPtr
StyleSheetEntry::GetMergedInheritedProperties(const StyleSheetTablePtr
& pStyleSheetTable
)
169 if ( pStyleSheetTable
&& !m_sBaseStyleIdentifier
.isEmpty() && m_sBaseStyleIdentifier
!= m_sStyleIdentifierD
)
171 const StyleSheetEntryPtr pParentStyleSheet
= pStyleSheetTable
->FindStyleSheetByISTD(m_sBaseStyleIdentifier
);
172 if ( pParentStyleSheet
)
173 pRet
= pParentStyleSheet
->GetMergedInheritedProperties(pStyleSheetTable
);
177 pRet
= new PropertyMap
;
179 pRet
->InsertProps(m_pProperties
.get());
184 static void lcl_mergeProps( const PropertyMapPtr
& pToFill
, const PropertyMapPtr
& pToAdd
, TblStyleType nStyleId
)
186 static const PropertyIds pPropsToCheck
[] =
194 bool pRemoveInside
[] =
196 ( nStyleId
== TBL_STYLE_FIRSTROW
),
197 ( nStyleId
== TBL_STYLE_LASTROW
),
198 ( nStyleId
== TBL_STYLE_LASTCOL
),
199 ( nStyleId
== TBL_STYLE_FIRSTCOL
)
202 for ( unsigned i
= 0 ; i
!= SAL_N_ELEMENTS(pPropsToCheck
); i
++ )
204 PropertyIds nId
= pPropsToCheck
[i
];
205 std::optional
<PropertyMap::Property
> pProp
= pToAdd
->getProperty(nId
);
209 if ( pRemoveInside
[i
] )
211 // Remove the insideH and insideV depending on the cell pos
212 PropertyIds nInsideProp
= ( i
< 2 ) ? META_PROP_HORIZONTAL_BORDER
: META_PROP_VERTICAL_BORDER
;
213 pToFill
->Erase(nInsideProp
);
218 pToFill
->InsertProps(pToAdd
);
221 PropertyMapPtr
TableStyleSheetEntry::GetLocalPropertiesFromMask( sal_Int32 nMask
)
223 // Order from right to left
224 struct TblStyleTypeAndMask
{
229 static const TblStyleTypeAndMask aOrderedStyleTable
[] =
231 { 0x010, TBL_STYLE_BAND2HORZ
},
232 { 0x020, TBL_STYLE_BAND1HORZ
},
233 { 0x040, TBL_STYLE_BAND2VERT
},
234 { 0x080, TBL_STYLE_BAND1VERT
},
235 { 0x100, TBL_STYLE_LASTCOL
},
236 { 0x200, TBL_STYLE_FIRSTCOL
},
237 { 0x400, TBL_STYLE_LASTROW
},
238 { 0x800, TBL_STYLE_FIRSTROW
},
239 { 0x001, TBL_STYLE_SWCELL
},
240 { 0x002, TBL_STYLE_SECELL
},
241 { 0x004, TBL_STYLE_NWCELL
},
242 { 0x008, TBL_STYLE_NECELL
}
245 // Get the properties applying according to the mask
246 PropertyMapPtr
pProps( new PropertyMap( ) );
247 for (const TblStyleTypeAndMask
& i
: aOrderedStyleTable
)
249 TblStylePrs::iterator pIt
= m_aStyles
.find( i
.type
);
250 if ( ( nMask
& i
.mask
) && ( pIt
!= m_aStyles
.end( ) ) )
251 lcl_mergeProps( pProps
, pIt
->second
, i
.type
);
258 struct ListCharStylePropertyMap_t
260 OUString sCharStyleName
;
261 PropertyValueVector_t aPropertyValues
;
263 ListCharStylePropertyMap_t(OUString _sCharStyleName
, PropertyValueVector_t
&& rPropertyValues
):
264 sCharStyleName(std::move( _sCharStyleName
)),
265 aPropertyValues( std::move(rPropertyValues
) )
271 struct StyleSheetTable_Impl
273 DomainMapper
& m_rDMapper
;
274 uno::Reference
< text::XTextDocument
> m_xTextDocument
;
275 uno::Reference
< beans::XPropertySet
> m_xTextDefaults
;
276 std::vector
< StyleSheetEntryPtr
> m_aStyleSheetEntries
;
277 std::map
< OUString
, StyleSheetEntryPtr
> m_aStyleSheetEntriesMap
;
278 std::map
<OUString
, OUString
> m_ClonedTOCStylesMap
;
279 StyleSheetEntryPtr m_pCurrentEntry
;
280 PropertyMapPtr m_pDefaultParaProps
, m_pDefaultCharProps
;
281 OUString m_sDefaultParaStyleName
; //WW8 name
282 std::vector
< ListCharStylePropertyMap_t
> m_aListCharStylePropertyVector
;
283 bool m_bHasImportedDefaultParaProps
;
286 StyleSheetTable_Impl(DomainMapper
& rDMapper
, uno::Reference
< text::XTextDocument
> xTextDocument
, bool bIsNewDoc
);
288 OUString
HasListCharStyle( const PropertyValueVector_t
& rCharProperties
);
290 /// Appends the given key-value pair to the list of latent style properties of the current entry.
291 void AppendLatentStyleProperty(const OUString
& aName
, Value
const & rValue
);
292 /// Sets all properties of xStyle back to default.
293 static void SetPropertiesToDefault(const uno::Reference
<style::XStyle
>& xStyle
);
294 void ApplyClonedTOCStylesToXText(uno::Reference
<text::XText
> const& xText
);
298 StyleSheetTable_Impl::StyleSheetTable_Impl(DomainMapper
& rDMapper
,
299 uno::Reference
< text::XTextDocument
> xTextDocument
,
300 bool const bIsNewDoc
)
301 : m_rDMapper( rDMapper
),
302 m_xTextDocument(std::move( xTextDocument
)),
303 m_pDefaultParaProps(new PropertyMap
),
304 m_pDefaultCharProps(new PropertyMap
),
305 m_sDefaultParaStyleName("Normal"),
306 m_bHasImportedDefaultParaProps(false),
307 m_bIsNewDoc(bIsNewDoc
)
309 //set font height default to 10pt
310 uno::Any
aVal( 10.0 );
311 m_pDefaultCharProps
->Insert( PROP_CHAR_HEIGHT
, aVal
);
312 m_pDefaultCharProps
->Insert( PROP_CHAR_HEIGHT_ASIAN
, aVal
);
313 m_pDefaultCharProps
->Insert( PROP_CHAR_HEIGHT_COMPLEX
, aVal
);
315 // See SwDoc::RemoveAllFormatLanguageDependencies(), internal filters
316 // disable kerning by default, do the same here.
317 m_pDefaultCharProps
->Insert(PROP_CHAR_AUTO_KERNING
, uno::Any(false));
321 OUString
StyleSheetTable_Impl::HasListCharStyle( const PropertyValueVector_t
& rPropValues
)
323 for( const auto& rListVector
: m_aListCharStylePropertyVector
)
325 const auto& rPropertyValues
= rListVector
.aPropertyValues
;
326 //if size is identical
327 if( rPropertyValues
.size() == rPropValues
.size() )
330 //then search for all contained properties
331 for( const auto& rPropVal1
: rPropValues
)
334 auto aListIter
= std::find_if(rPropertyValues
.begin(), rPropertyValues
.end(),
335 [&rPropVal1
](const css::beans::PropertyValue
& rPropVal2
) { return rPropVal2
.Name
== rPropVal1
.Name
; });
336 //set break flag if property hasn't been found
337 bBreak
= (aListIter
== rPropertyValues
.end()) || (aListIter
->Value
!= rPropVal1
.Value
);
342 return rListVector
.sCharStyleName
;
348 void StyleSheetTable_Impl::AppendLatentStyleProperty(const OUString
& aName
, Value
const & rValue
)
350 beans::PropertyValue aValue
;
352 aValue
.Value
<<= rValue
.getString();
353 m_pCurrentEntry
->m_aLatentStyles
.push_back(aValue
);
356 void StyleSheetTable_Impl::SetPropertiesToDefault(const uno::Reference
<style::XStyle
>& xStyle
)
358 // See if the existing style has any non-default properties. If so, reset them back to default.
359 uno::Reference
<beans::XPropertySet
> xPropertySet(xStyle
, uno::UNO_QUERY
);
360 uno::Reference
<beans::XPropertySetInfo
> xPropertySetInfo
= xPropertySet
->getPropertySetInfo();
361 const uno::Sequence
<beans::Property
> aProperties
= xPropertySetInfo
->getProperties();
362 std::vector
<OUString
> aPropertyNames
;
363 aPropertyNames
.reserve(aProperties
.getLength());
364 std::transform(aProperties
.begin(), aProperties
.end(), std::back_inserter(aPropertyNames
),
365 [](const beans::Property
& rProp
) { return rProp
.Name
; });
367 uno::Reference
<beans::XPropertyState
> xPropertyState(xStyle
, uno::UNO_QUERY
);
368 uno::Sequence
<beans::PropertyState
> aStates
= xPropertyState
->getPropertyStates(comphelper::containerToSequence(aPropertyNames
));
369 for (sal_Int32 i
= 0; i
< aStates
.getLength(); ++i
)
371 if (aStates
[i
] == beans::PropertyState_DIRECT_VALUE
)
375 xPropertyState
->setPropertyToDefault(aPropertyNames
[i
]);
377 catch(const uno::Exception
&)
379 TOOLS_INFO_EXCEPTION("writerfilter", "setPropertyToDefault(" << aPropertyNames
[i
] << ") failed");
385 StyleSheetTable::StyleSheetTable(DomainMapper
& rDMapper
,
386 uno::Reference
< text::XTextDocument
> const& xTextDocument
,
387 bool const bIsNewDoc
)
388 : LoggedProperties("StyleSheetTable")
389 , LoggedTable("StyleSheetTable")
390 , m_pImpl( new StyleSheetTable_Impl(rDMapper
, xTextDocument
, bIsNewDoc
) )
395 StyleSheetTable::~StyleSheetTable()
399 void StyleSheetTable::SetDefaultParaProps(PropertyIds eId
, const css::uno::Any
& rAny
)
401 m_pImpl
->m_pDefaultParaProps
->Insert(eId
, rAny
, /*bOverwrite=*/false, NO_GRAB_BAG
, /*bDocDefault=*/true);
404 PropertyMapPtr
const & StyleSheetTable::GetDefaultParaProps() const
406 return m_pImpl
->m_pDefaultParaProps
;
409 PropertyMapPtr
const & StyleSheetTable::GetDefaultCharProps() const
411 return m_pImpl
->m_pDefaultCharProps
;
414 void StyleSheetTable::lcl_attribute(Id Name
, Value
& val
)
416 OSL_ENSURE( m_pImpl
->m_pCurrentEntry
, "current entry has to be set here");
417 if(!m_pImpl
->m_pCurrentEntry
)
419 int nIntValue
= val
.getInt();
420 OUString sValue
= val
.getString();
422 // The default type is paragraph, and it needs to be processed first,
423 // because the NS_ooxml::LN_CT_Style_type handling may set m_pImpl->m_pCurrentEntry
424 // to point to a different object.
425 if( m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
== STYLE_TYPE_UNKNOWN
)
427 if( Name
!= NS_ooxml::LN_CT_Style_type
)
428 m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
= STYLE_TYPE_PARA
;
432 case NS_ooxml::LN_CT_Style_type
:
434 SAL_WARN_IF( m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
!= STYLE_TYPE_UNKNOWN
,
435 "writerfilter", "Style type needs to be processed first" );
436 StyleType
nType(STYLE_TYPE_UNKNOWN
);
439 case NS_ooxml::LN_Value_ST_StyleType_paragraph
:
440 nType
= STYLE_TYPE_PARA
;
442 case NS_ooxml::LN_Value_ST_StyleType_character
:
443 nType
= STYLE_TYPE_CHAR
;
445 case NS_ooxml::LN_Value_ST_StyleType_table
:
446 nType
= STYLE_TYPE_TABLE
;
448 case NS_ooxml::LN_Value_ST_StyleType_numbering
:
449 nType
= STYLE_TYPE_LIST
;
452 SAL_WARN("writerfilter", "unknown LN_CT_Style_type " << nType
);
454 case 0: // explicit unknown set by tokenizer
458 if ( nType
== STYLE_TYPE_TABLE
)
460 StyleSheetEntryPtr pEntry
= m_pImpl
->m_pCurrentEntry
;
461 tools::SvRef
<TableStyleSheetEntry
> pTableEntry( new TableStyleSheetEntry( *pEntry
) );
462 m_pImpl
->m_pCurrentEntry
= pTableEntry
.get();
465 m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
= nType
;
468 case NS_ooxml::LN_CT_Style_default
:
469 m_pImpl
->m_pCurrentEntry
->m_bIsDefaultStyle
= (nIntValue
!= 0);
471 if (m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
!= STYLE_TYPE_UNKNOWN
)
473 // "If this attribute is specified by multiple styles, then the last instance shall be used."
474 if (m_pImpl
->m_pCurrentEntry
->m_bIsDefaultStyle
475 && m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
== STYLE_TYPE_PARA
476 && !m_pImpl
->m_pCurrentEntry
->m_sStyleIdentifierD
.isEmpty())
478 m_pImpl
->m_sDefaultParaStyleName
= m_pImpl
->m_pCurrentEntry
->m_sStyleIdentifierD
;
481 beans::PropertyValue aValue
;
482 aValue
.Name
= "default";
483 aValue
.Value
<<= m_pImpl
->m_pCurrentEntry
->m_bIsDefaultStyle
;
484 m_pImpl
->m_pCurrentEntry
->AppendInteropGrabBag(aValue
);
487 case NS_ooxml::LN_CT_Style_customStyle
:
488 if (m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
!= STYLE_TYPE_UNKNOWN
)
490 beans::PropertyValue aValue
;
491 aValue
.Name
= "customStyle";
492 aValue
.Value
<<= (nIntValue
!= 0);
493 m_pImpl
->m_pCurrentEntry
->AppendInteropGrabBag(aValue
);
496 case NS_ooxml::LN_CT_Style_styleId
:
497 m_pImpl
->m_pCurrentEntry
->m_sStyleIdentifierD
= sValue
;
498 if(m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
== STYLE_TYPE_TABLE
)
500 TableStyleSheetEntry
* pTableEntry
= static_cast<TableStyleSheetEntry
*>(m_pImpl
->m_pCurrentEntry
.get());
501 beans::PropertyValue aValue
;
502 aValue
.Name
= "styleId";
503 aValue
.Value
<<= sValue
;
504 pTableEntry
->AppendInteropGrabBag(aValue
);
507 case NS_ooxml::LN_CT_TblWidth_w
:
509 case NS_ooxml::LN_CT_TblWidth_type
:
511 case NS_ooxml::LN_CT_LatentStyles_defQFormat
:
512 m_pImpl
->AppendLatentStyleProperty("defQFormat", val
);
514 case NS_ooxml::LN_CT_LatentStyles_defUnhideWhenUsed
:
515 m_pImpl
->AppendLatentStyleProperty("defUnhideWhenUsed", val
);
517 case NS_ooxml::LN_CT_LatentStyles_defSemiHidden
:
518 m_pImpl
->AppendLatentStyleProperty("defSemiHidden", val
);
520 case NS_ooxml::LN_CT_LatentStyles_count
:
521 m_pImpl
->AppendLatentStyleProperty("count", val
);
523 case NS_ooxml::LN_CT_LatentStyles_defUIPriority
:
524 m_pImpl
->AppendLatentStyleProperty("defUIPriority", val
);
526 case NS_ooxml::LN_CT_LatentStyles_defLockedState
:
527 m_pImpl
->AppendLatentStyleProperty("defLockedState", val
);
532 TagLogger::getInstance().element("unhandled");
540 void StyleSheetTable::lcl_sprm(Sprm
& rSprm
)
542 sal_uInt32 nSprmId
= rSprm
.getId();
543 Value::Pointer_t pValue
= rSprm
.getValue();
544 sal_Int32 nIntValue
= pValue
? pValue
->getInt() : 0;
545 OUString sStringValue
= pValue
? pValue
->getString() : OUString();
549 case NS_ooxml::LN_CT_Style_name
:
550 //this is only a UI name!
551 m_pImpl
->m_pCurrentEntry
->m_sStyleName
= sStringValue
;
552 if(m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
== STYLE_TYPE_TABLE
)
554 TableStyleSheetEntry
* pTableEntry
= static_cast<TableStyleSheetEntry
*>(m_pImpl
->m_pCurrentEntry
.get());
555 beans::PropertyValue aValue
;
556 aValue
.Name
= "name";
557 aValue
.Value
<<= sStringValue
;
558 pTableEntry
->AppendInteropGrabBag(aValue
);
561 case NS_ooxml::LN_CT_Style_basedOn
:
562 m_pImpl
->m_pCurrentEntry
->m_sBaseStyleIdentifier
= sStringValue
;
563 if(m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
== STYLE_TYPE_TABLE
)
565 TableStyleSheetEntry
* pTableEntry
= static_cast<TableStyleSheetEntry
*>(m_pImpl
->m_pCurrentEntry
.get());
566 beans::PropertyValue aValue
;
567 aValue
.Name
= "basedOn";
568 aValue
.Value
<<= sStringValue
;
569 pTableEntry
->AppendInteropGrabBag(aValue
);
572 case NS_ooxml::LN_CT_Style_link
:
573 m_pImpl
->m_pCurrentEntry
->m_sLinkStyleIdentifier
= sStringValue
;
575 case NS_ooxml::LN_CT_Style_next
:
576 m_pImpl
->m_pCurrentEntry
->m_sNextStyleIdentifier
= sStringValue
;
578 case NS_ooxml::LN_CT_Style_aliases
:
579 case NS_ooxml::LN_CT_Style_hidden
:
580 case NS_ooxml::LN_CT_Style_personal
:
581 case NS_ooxml::LN_CT_Style_personalCompose
:
582 case NS_ooxml::LN_CT_Style_personalReply
:
584 case NS_ooxml::LN_CT_Style_autoRedefine
:
585 m_pImpl
->m_pCurrentEntry
->m_bAutoRedefine
= nIntValue
;
587 case NS_ooxml::LN_CT_Style_tcPr
:
589 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
590 if( pProperties
&& m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
== STYLE_TYPE_TABLE
)
592 auto pTblStylePrHandler
= std::make_shared
<TblStylePrHandler
>(m_pImpl
->m_rDMapper
);
593 pProperties
->resolve(*pTblStylePrHandler
);
594 StyleSheetEntry
* pEntry
= m_pImpl
->m_pCurrentEntry
.get();
595 TableStyleSheetEntry
& rTableEntry
= dynamic_cast<TableStyleSheetEntry
&>(*pEntry
);
596 rTableEntry
.AppendInteropGrabBag(pTblStylePrHandler
->getInteropGrabBag("tcPr"));
598 // This is a <w:tcPr> directly under <w:style>, so it affects the whole table.
599 rTableEntry
.m_pProperties
->InsertProps(pTblStylePrHandler
->getProperties());
603 case NS_ooxml::LN_CT_Style_trPr
:
605 case NS_ooxml::LN_CT_Style_rsid
:
606 case NS_ooxml::LN_CT_Style_qFormat
:
607 case NS_ooxml::LN_CT_Style_semiHidden
:
608 case NS_ooxml::LN_CT_Style_unhideWhenUsed
:
609 case NS_ooxml::LN_CT_Style_uiPriority
:
610 case NS_ooxml::LN_CT_Style_locked
:
611 if (m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
!= STYLE_TYPE_UNKNOWN
)
613 StyleSheetEntryPtr pEntry
= m_pImpl
->m_pCurrentEntry
;
614 beans::PropertyValue aValue
;
617 case NS_ooxml::LN_CT_Style_rsid
:
619 // We want the rsid as a hex string, but always with the length of 8.
620 OUStringBuffer aBuf
= OUString::number(nIntValue
, 16);
622 comphelper::string::padToLength(aStr
, 8 - aBuf
.getLength(), '0');
623 aStr
.append(aBuf
.getStr());
625 aValue
.Name
= "rsid";
626 aValue
.Value
<<= aStr
.makeStringAndClear();
629 case NS_ooxml::LN_CT_Style_qFormat
:
630 aValue
.Name
= "qFormat";
632 case NS_ooxml::LN_CT_Style_semiHidden
:
633 aValue
.Name
= "semiHidden";
635 case NS_ooxml::LN_CT_Style_unhideWhenUsed
:
636 aValue
.Name
= "unhideWhenUsed";
638 case NS_ooxml::LN_CT_Style_uiPriority
:
640 aValue
.Name
= "uiPriority";
641 aValue
.Value
<<= OUString::number(nIntValue
);
644 case NS_ooxml::LN_CT_Style_locked
:
645 aValue
.Name
= "locked";
648 pEntry
->AppendInteropGrabBag(aValue
);
651 case NS_ooxml::LN_CT_Style_tblPr
: //contains table properties
652 case NS_ooxml::LN_CT_Style_tblStylePr
: //contains to table properties
653 case NS_ooxml::LN_CT_TblPrBase_tblInd
: //table properties - at least width value and type
654 case NS_ooxml::LN_EG_RPrBase_rFonts
: //table fonts
656 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
659 auto pTblStylePrHandler
= std::make_shared
<TblStylePrHandler
>( m_pImpl
->m_rDMapper
);
660 pProperties
->resolve( *pTblStylePrHandler
);
662 // Add the properties to the table style
663 TblStyleType nType
= pTblStylePrHandler
->getType( );
664 PropertyMapPtr pProps
= pTblStylePrHandler
->getProperties( );
665 StyleSheetEntry
* pEntry
= m_pImpl
->m_pCurrentEntry
.get();
667 TableStyleSheetEntry
* pTableEntry
= dynamic_cast<TableStyleSheetEntry
*>( pEntry
);
668 if (nType
== TBL_STYLE_UNKNOWN
)
670 pEntry
->m_pProperties
->InsertProps(pProps
);
674 if (pTableEntry
!= nullptr)
675 pTableEntry
->AddTblStylePr( nType
, pProps
);
678 if (nSprmId
== NS_ooxml::LN_CT_Style_tblPr
)
680 if (pTableEntry
!= nullptr)
681 pTableEntry
->AppendInteropGrabBag(pTblStylePrHandler
->getInteropGrabBag("tblPr"));
683 else if (nSprmId
== NS_ooxml::LN_CT_Style_tblStylePr
)
685 pTblStylePrHandler
->appendInteropGrabBag("type", pTblStylePrHandler
->getTypeString());
686 if (pTableEntry
!= nullptr)
687 pTableEntry
->AppendInteropGrabBag(pTblStylePrHandler
->getInteropGrabBag("tblStylePr"));
692 case NS_ooxml::LN_CT_PPrDefault_pPr
:
693 case NS_ooxml::LN_CT_DocDefaults_pPrDefault
:
694 if (nSprmId
== NS_ooxml::LN_CT_DocDefaults_pPrDefault
)
695 m_pImpl
->m_rDMapper
.SetDocDefaultsImport(true);
697 m_pImpl
->m_rDMapper
.PushStyleSheetProperties( m_pImpl
->m_pDefaultParaProps
);
698 resolveSprmProps( m_pImpl
->m_rDMapper
, rSprm
);
699 if ( nSprmId
== NS_ooxml::LN_CT_DocDefaults_pPrDefault
&& m_pImpl
->m_pDefaultParaProps
&&
700 !m_pImpl
->m_pDefaultParaProps
->isSet( PROP_PARA_TOP_MARGIN
) )
702 SetDefaultParaProps( PROP_PARA_TOP_MARGIN
, uno::Any( sal_Int32(0) ) );
704 m_pImpl
->m_rDMapper
.PopStyleSheetProperties();
705 applyDefaults( true );
706 m_pImpl
->m_bHasImportedDefaultParaProps
= true;
707 if (nSprmId
== NS_ooxml::LN_CT_DocDefaults_pPrDefault
)
708 m_pImpl
->m_rDMapper
.SetDocDefaultsImport(false);
710 case NS_ooxml::LN_CT_RPrDefault_rPr
:
711 case NS_ooxml::LN_CT_DocDefaults_rPrDefault
:
712 if (nSprmId
== NS_ooxml::LN_CT_DocDefaults_rPrDefault
)
713 m_pImpl
->m_rDMapper
.SetDocDefaultsImport(true);
715 m_pImpl
->m_rDMapper
.PushStyleSheetProperties( m_pImpl
->m_pDefaultCharProps
);
716 resolveSprmProps( m_pImpl
->m_rDMapper
, rSprm
);
717 m_pImpl
->m_rDMapper
.PopStyleSheetProperties();
718 applyDefaults( false );
719 if (nSprmId
== NS_ooxml::LN_CT_DocDefaults_rPrDefault
)
720 m_pImpl
->m_rDMapper
.SetDocDefaultsImport(false);
722 case NS_ooxml::LN_CT_TblPrBase_jc
: //table alignment - row properties!
723 m_pImpl
->m_pCurrentEntry
->m_pProperties
->Insert( PROP_HORI_ORIENT
,
724 uno::Any( ConversionHelper::convertTableJustification( nIntValue
)));
726 case NS_ooxml::LN_CT_TrPrBase_jc
: //table alignment - row properties!
728 case NS_ooxml::LN_CT_TblPrBase_tblBorders
: //table borders, might be defined in table style
730 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
733 auto pBorderHandler
= std::make_shared
<BorderHandler
>(m_pImpl
->m_rDMapper
.IsOOXMLImport());
734 pProperties
->resolve(*pBorderHandler
);
735 m_pImpl
->m_pCurrentEntry
->m_pProperties
->InsertProps(
736 pBorderHandler
->getProperties());
740 case NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize
:
741 case NS_ooxml::LN_CT_TblPrBase_tblStyleColBandSize
:
743 case NS_ooxml::LN_CT_TblPrBase_tblCellMar
:
744 //no cell margins in styles
746 case NS_ooxml::LN_CT_LatentStyles_lsdException
:
748 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
751 tools::SvRef
<LatentStyleHandler
> pLatentStyleHandler(new LatentStyleHandler());
752 pProperties
->resolve(*pLatentStyleHandler
);
753 beans::PropertyValue aValue
;
754 aValue
.Name
= "lsdException";
755 aValue
.Value
<<= comphelper::containerToSequence(pLatentStyleHandler
->getAttributes());
756 m_pImpl
->m_pCurrentEntry
->m_aLsdExceptions
.push_back(aValue
);
760 case NS_ooxml::LN_CT_Style_pPr
:
762 case NS_ooxml::LN_CT_Style_rPr
:
766 if (!m_pImpl
->m_pCurrentEntry
)
769 tools::SvRef
<TablePropertiesHandler
> pTblHandler(new TablePropertiesHandler());
770 pTblHandler
->SetProperties( m_pImpl
->m_pCurrentEntry
->m_pProperties
.get() );
771 if ( !pTblHandler
->sprm( rSprm
) )
773 m_pImpl
->m_rDMapper
.PushStyleSheetProperties( m_pImpl
->m_pCurrentEntry
->m_pProperties
.get() );
775 PropertyMapPtr
pProps(new PropertyMap());
776 if (m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
== STYLE_TYPE_TABLE
)
778 if (nSprmId
== NS_ooxml::LN_CT_Style_pPr
)
779 m_pImpl
->m_rDMapper
.enableInteropGrabBag("pPr");
780 else if (nSprmId
== NS_ooxml::LN_CT_Style_rPr
)
781 m_pImpl
->m_rDMapper
.enableInteropGrabBag("rPr");
783 m_pImpl
->m_rDMapper
.sprmWithProps( rSprm
, pProps
);
784 if (m_pImpl
->m_pCurrentEntry
->m_nStyleTypeCode
== STYLE_TYPE_TABLE
)
786 if (nSprmId
== NS_ooxml::LN_CT_Style_pPr
|| nSprmId
== NS_ooxml::LN_CT_Style_rPr
)
788 TableStyleSheetEntry
* pTableEntry
= static_cast<TableStyleSheetEntry
*>(m_pImpl
->m_pCurrentEntry
.get());
789 pTableEntry
->AppendInteropGrabBag(m_pImpl
->m_rDMapper
.getInteropGrabBag());
793 m_pImpl
->m_pCurrentEntry
->m_pProperties
->InsertProps(pProps
);
795 m_pImpl
->m_rDMapper
.PopStyleSheetProperties( );
803 void StyleSheetTable::lcl_entry(writerfilter::Reference
<Properties
>::Pointer_t ref
)
805 //create a new style entry
806 OSL_ENSURE( !m_pImpl
->m_pCurrentEntry
, "current entry has to be NULL here");
807 StyleSheetEntryPtr
pNewEntry( new StyleSheetEntry
);
808 m_pImpl
->m_pCurrentEntry
= pNewEntry
;
809 m_pImpl
->m_rDMapper
.PushStyleSheetProperties( m_pImpl
->m_pCurrentEntry
->m_pProperties
.get() );
811 m_pImpl
->m_rDMapper
.ProcessDeferredStyleCharacterProperties();
812 //append it to the table
813 m_pImpl
->m_rDMapper
.PopStyleSheetProperties();
814 if( !m_pImpl
->m_rDMapper
.IsOOXMLImport() || !m_pImpl
->m_pCurrentEntry
->m_sStyleName
.isEmpty())
816 m_pImpl
->m_pCurrentEntry
->m_sConvertedStyleName
= ConvertStyleName( m_pImpl
->m_pCurrentEntry
->m_sStyleName
);
817 m_pImpl
->m_aStyleSheetEntries
.push_back( m_pImpl
->m_pCurrentEntry
);
818 m_pImpl
->m_aStyleSheetEntriesMap
.emplace( m_pImpl
->m_pCurrentEntry
->m_sStyleIdentifierD
, m_pImpl
->m_pCurrentEntry
);
822 //TODO: this entry contains the default settings - they have to be added to the settings
825 if (!m_pImpl
->m_pCurrentEntry
->m_aLatentStyles
.empty())
827 // We have latent styles for this entry, then process them.
828 std::vector
<beans::PropertyValue
>& rLatentStyles
= m_pImpl
->m_pCurrentEntry
->m_aLatentStyles
;
830 if (!m_pImpl
->m_pCurrentEntry
->m_aLsdExceptions
.empty())
832 std::vector
<beans::PropertyValue
>& rLsdExceptions
= m_pImpl
->m_pCurrentEntry
->m_aLsdExceptions
;
833 beans::PropertyValue aValue
;
834 aValue
.Name
= "lsdExceptions";
835 aValue
.Value
<<= comphelper::containerToSequence(rLsdExceptions
);
836 rLatentStyles
.push_back(aValue
);
839 uno::Sequence
<beans::PropertyValue
> aLatentStyles( comphelper::containerToSequence(rLatentStyles
) );
841 // We can put all latent style info directly to the document interop
842 // grab bag, as we can be sure that only a single style entry has
843 // latent style info.
844 uno::Reference
<beans::XPropertySet
> xPropertySet(m_pImpl
->m_xTextDocument
, uno::UNO_QUERY
);
845 auto aGrabBag
= comphelper::sequenceToContainer
< std::vector
<beans::PropertyValue
> >(xPropertySet
->getPropertyValue("InteropGrabBag").get
< uno::Sequence
<beans::PropertyValue
> >());
846 beans::PropertyValue aValue
;
847 aValue
.Name
= "latentStyles";
848 aValue
.Value
<<= aLatentStyles
;
849 aGrabBag
.push_back(aValue
);
850 xPropertySet
->setPropertyValue("InteropGrabBag", uno::Any(comphelper::containerToSequence(aGrabBag
)));
853 StyleSheetEntryPtr pEmptyEntry
;
854 m_pImpl
->m_pCurrentEntry
= pEmptyEntry
;
856 /*-------------------------------------------------------------------------
858 -----------------------------------------------------------------------*/
863 std::vector
<beans::PropertyValue
> m_aValues
;
867 void Insert(const beans::PropertyValue
& rVal
);
868 uno::Sequence
< uno::Any
> getValues();
869 uno::Sequence
< OUString
> getNames();
870 const std::vector
<beans::PropertyValue
>& getProperties() const { return m_aValues
; };
875 void PropValVector::Insert(const beans::PropertyValue
& rVal
)
877 auto aIt
= std::find_if(m_aValues
.begin(), m_aValues
.end(),
878 [&rVal
](beans::PropertyValue
& rPropVal
) { return rPropVal
.Name
> rVal
.Name
; });
879 if (aIt
!= m_aValues
.end())
881 m_aValues
.insert( aIt
, rVal
);
884 m_aValues
.push_back(rVal
);
887 uno::Sequence
< uno::Any
> PropValVector::getValues()
889 std::vector
<uno::Any
> aRet
;
890 std::transform(m_aValues
.begin(), m_aValues
.end(), std::back_inserter(aRet
), [](const beans::PropertyValue
& rValue
) { return rValue
.Value
; });
891 return comphelper::containerToSequence(aRet
);
894 uno::Sequence
< OUString
> PropValVector::getNames()
896 std::vector
<OUString
> aRet
;
897 std::transform(m_aValues
.begin(), m_aValues
.end(), std::back_inserter(aRet
), [](const beans::PropertyValue
& rValue
) { return rValue
.Name
; });
898 return comphelper::containerToSequence(aRet
);
901 void StyleSheetTable::ApplyNumberingStyleNameToParaStyles()
905 uno::Reference
< style::XStyleFamiliesSupplier
> xStylesSupplier( m_pImpl
->m_xTextDocument
, uno::UNO_QUERY_THROW
);
906 uno::Reference
< lang::XMultiServiceFactory
> xDocFactory( m_pImpl
->m_xTextDocument
, uno::UNO_QUERY_THROW
);
907 uno::Reference
< container::XNameAccess
> xStyleFamilies
= xStylesSupplier
->getStyleFamilies();
908 uno::Reference
<container::XNameContainer
> xParaStyles
;
909 xStyleFamilies
->getByName(getPropertyName( PROP_PARAGRAPH_STYLES
)) >>= xParaStyles
;
911 if ( !xParaStyles
.is() )
914 for ( const auto& pEntry
: m_pImpl
->m_aStyleSheetEntries
)
916 StyleSheetPropertyMap
* pStyleSheetProperties
= nullptr;
917 if ( pEntry
->m_nStyleTypeCode
== STYLE_TYPE_PARA
&& (pStyleSheetProperties
= pEntry
->m_pProperties
.get()) )
919 // ListId 0 means turn off numbering - to cancel inheritance - so make sure that can be set.
920 if (pStyleSheetProperties
->props().GetListId() > -1)
922 uno::Reference
< style::XStyle
> xStyle
;
923 xParaStyles
->getByName( ConvertStyleName(pEntry
->m_sStyleName
) ) >>= xStyle
;
928 uno::Reference
<beans::XPropertySet
> xPropertySet( xStyle
, uno::UNO_QUERY_THROW
);
929 const OUString sNumberingStyleName
= m_pImpl
->m_rDMapper
.GetListStyleName( pStyleSheetProperties
->props().GetListId() );
930 if ( !sNumberingStyleName
.isEmpty()
931 || !pStyleSheetProperties
->props().GetListId() )
932 xPropertySet
->setPropertyValue( getPropertyName(PROP_NUMBERING_STYLE_NAME
), uno::Any(sNumberingStyleName
) );
934 // Word 2010+ (not Word 2003, and Word 2007 is completely broken)
935 // does something rather strange. It does not allow two paragraph styles
936 // to share the same listLevel on a numbering rule.
937 // Consider this style to just be body level if already used previously.
938 m_pImpl
->m_rDMapper
.ValidateListLevel(pEntry
->m_sStyleIdentifierD
);
943 catch( const uno::Exception
& )
945 DBG_UNHANDLED_EXCEPTION("writerfilter", "Failed applying numbering style name to Paragraph styles");
949 /* Counteract the destructive tendencies of LibreOffice's Chapter Numbering
951 * Any assignment to Chapter Numbering will erase the numbering-like properties of inherited styles.
952 * So go through the list of styles and any that inherit from a Chapter Numbering style
953 * should have the Outline Level reapplied.
955 void StyleSheetTable::ReApplyInheritedOutlineLevelFromChapterNumbering()
959 uno::Reference
< style::XStyleFamiliesSupplier
> xStylesSupplier(m_pImpl
->m_xTextDocument
, uno::UNO_QUERY_THROW
);
960 uno::Reference
< lang::XMultiServiceFactory
> xDocFactory(m_pImpl
->m_xTextDocument
, uno::UNO_QUERY_THROW
);
961 uno::Reference
< container::XNameAccess
> xStyleFamilies
= xStylesSupplier
->getStyleFamilies();
962 uno::Reference
<container::XNameContainer
> xParaStyles
;
963 xStyleFamilies
->getByName(getPropertyName(PROP_PARAGRAPH_STYLES
)) >>= xParaStyles
;
965 if (!xParaStyles
.is())
968 for (const auto& pEntry
: m_pImpl
->m_aStyleSheetEntries
)
970 if (pEntry
->m_nStyleTypeCode
!= STYLE_TYPE_PARA
|| pEntry
->m_sBaseStyleIdentifier
.isEmpty())
973 sal_Int16 nOutlineLevel
= pEntry
->m_pProperties
->GetOutlineLevel();
974 if (nOutlineLevel
!= -1)
977 StyleSheetEntryPtr pParent
= FindStyleSheetByISTD(pEntry
->m_sBaseStyleIdentifier
);
978 if (!pParent
|| !pParent
->m_bAssignedAsChapterNumbering
)
981 nOutlineLevel
= pParent
->m_pProperties
->GetOutlineLevel();
982 assert(nOutlineLevel
>= WW_OUTLINE_MIN
&& nOutlineLevel
< WW_OUTLINE_MAX
);
984 // convert MS level to LO equivalent outline level
987 uno::Reference
< style::XStyle
> xStyle
;
988 xParaStyles
->getByName(pEntry
->m_sConvertedStyleName
) >>= xStyle
;
992 uno::Reference
<beans::XPropertySet
> xPropertySet( xStyle
, uno::UNO_QUERY_THROW
);
993 xPropertySet
->setPropertyValue(getPropertyName(PROP_OUTLINE_LEVEL
), uno::Any(nOutlineLevel
));
996 catch( const uno::Exception
& )
998 DBG_UNHANDLED_EXCEPTION("writerfilter", "Failed applying outlineLevel to Paragraph styles");
1002 void StyleSheetTable_Impl::ApplyClonedTOCStylesToXText(uno::Reference
<text::XText
> const& xText
)
1004 uno::Reference
<container::XEnumerationAccess
> const xEA(xText
, uno::UNO_QUERY_THROW
);
1005 uno::Reference
<container::XEnumeration
> const xParaEnum(xEA
->createEnumeration());
1007 while (xParaEnum
->hasMoreElements())
1009 uno::Reference
<lang::XServiceInfo
> const xElem(xParaEnum
->nextElement(), uno::UNO_QUERY_THROW
);
1010 if (xElem
->supportsService(u
"com.sun.star.text.Paragraph"))
1012 uno::Reference
<beans::XPropertySet
> const xPara(xElem
, uno::UNO_QUERY_THROW
);
1014 if (xPara
->getPropertyValue(u
"ParaStyleName") >>= styleName
)
1016 auto const it(m_ClonedTOCStylesMap
.find(styleName
));
1017 if (it
!= m_ClonedTOCStylesMap
.end())
1019 xPara
->setPropertyValue(u
"ParaStyleName", uno::Any(it
->second
));
1023 else if (xElem
->supportsService(u
"com.sun.star.text.TextTable"))
1025 uno::Reference
<text::XTextTable
> const xTable(xElem
, uno::UNO_QUERY_THROW
);
1026 uno::Sequence
<OUString
> const cells(xTable
->getCellNames());
1027 for (OUString
const& rCell
: cells
)
1029 uno::Reference
<text::XText
> const xCell(xTable
->getCellByName(rCell
), uno::UNO_QUERY_THROW
);
1030 ApplyClonedTOCStylesToXText(xCell
);
1037 Replace the applied en-US Word built-in styles that were referenced from
1038 TOC fields (also STYLEREF and likely AUTOTEXTLIST) with the localised clones.
1040 With the style cloned, and the clone referenced, the ToX should work in
1041 Writer and also, when exported to DOCX, in Word.
1043 void StyleSheetTable::ApplyClonedTOCStyles()
1045 if (m_pImpl
->m_ClonedTOCStylesMap
.empty()
1046 || !m_pImpl
->m_bIsNewDoc
) // avoid modifying pre-existing content
1050 SAL_INFO("writerfilter.dmapper", "Applying cloned styles to make TOC work");
1051 // ignore header / footer, irrelevant for ToX
1053 uno::Reference
<text::XTextFramesSupplier
> const xDocTFS(m_pImpl
->m_xTextDocument
, uno::UNO_QUERY_THROW
);
1054 uno::Reference
<container::XEnumerationAccess
> const xFrames(xDocTFS
->getTextFrames(), uno::UNO_QUERY_THROW
);
1055 uno::Reference
<container::XEnumeration
> const xFramesEnum(xFrames
->createEnumeration());
1056 while (xFramesEnum
->hasMoreElements())
1058 uno::Reference
<text::XText
> const xFrame(xFramesEnum
->nextElement(), uno::UNO_QUERY_THROW
);
1059 m_pImpl
->ApplyClonedTOCStylesToXText(xFrame
);
1062 uno::Reference
<text::XText
> const xBody(m_pImpl
->m_xTextDocument
->getText());
1063 m_pImpl
->ApplyClonedTOCStylesToXText(xBody
);
1066 OUString
StyleSheetTable::CloneTOCStyle(FontTablePtr
const& rFontTable
, StyleSheetEntryPtr
const pStyle
, OUString
const& rNewName
)
1068 StyleSheetEntryPtr
const pClone(new StyleSheetEntry(*pStyle
));
1069 pClone
->m_sStyleIdentifierD
= rNewName
;
1070 pClone
->m_sStyleName
= rNewName
;
1071 pClone
->m_sConvertedStyleName
= ConvertStyleName(rNewName
);
1072 m_pImpl
->m_aStyleSheetEntries
.push_back(pClone
);
1073 // add it so it will be found if referenced from another TOC
1074 m_pImpl
->m_aStyleSheetEntriesMap
.emplace(rNewName
, pClone
);
1075 m_pImpl
->m_ClonedTOCStylesMap
.emplace(pStyle
->m_sStyleName
, pClone
->m_sConvertedStyleName
);
1076 std::vector
<StyleSheetEntryPtr
> const styles
{ pClone
};
1077 ApplyStyleSheetsImpl(rFontTable
, styles
);
1078 return pClone
->m_sConvertedStyleName
;
1081 void StyleSheetTable::ApplyStyleSheets( const FontTablePtr
& rFontTable
)
1083 return ApplyStyleSheetsImpl(rFontTable
, m_pImpl
->m_aStyleSheetEntries
);
1086 void StyleSheetTable::ApplyStyleSheetsImpl(const FontTablePtr
& rFontTable
, std::vector
<StyleSheetEntryPtr
> const& rEntries
)
1090 uno::Reference
< style::XStyleFamiliesSupplier
> xStylesSupplier( m_pImpl
->m_xTextDocument
, uno::UNO_QUERY_THROW
);
1091 uno::Reference
< lang::XMultiServiceFactory
> xDocFactory( m_pImpl
->m_xTextDocument
, uno::UNO_QUERY_THROW
);
1092 uno::Reference
< container::XNameAccess
> xStyleFamilies
= xStylesSupplier
->getStyleFamilies();
1093 uno::Reference
<container::XNameContainer
> xCharStyles
;
1094 uno::Reference
<container::XNameContainer
> xParaStyles
;
1095 uno::Reference
<container::XNameContainer
> xNumberingStyles
;
1097 xStyleFamilies
->getByName(getPropertyName( PROP_CHARACTER_STYLES
)) >>= xCharStyles
;
1098 xStyleFamilies
->getByName(getPropertyName( PROP_PARAGRAPH_STYLES
)) >>= xParaStyles
;
1099 xStyleFamilies
->getByName("NumberingStyles") >>= xNumberingStyles
;
1100 if(xCharStyles
.is() && xParaStyles
.is())
1102 std::vector
< ::std::pair
<OUString
, uno::Reference
<style::XStyle
>> > aMissingParent
;
1103 std::vector
< ::std::pair
<OUString
, uno::Reference
<style::XStyle
>> > aMissingFollow
;
1104 std::vector
<std::pair
<OUString
, uno::Reference
<style::XStyle
>>> aMissingLink
;
1105 std::vector
<beans::PropertyValue
> aTableStylesVec
;
1106 for (auto& pEntry
: rEntries
)
1108 if( pEntry
->m_nStyleTypeCode
== STYLE_TYPE_UNKNOWN
&& !pEntry
->m_sStyleName
.isEmpty() )
1109 pEntry
->m_nStyleTypeCode
= STYLE_TYPE_PARA
; // unspecified style types are considered paragraph styles
1111 if( pEntry
->m_nStyleTypeCode
== STYLE_TYPE_CHAR
|| pEntry
->m_nStyleTypeCode
== STYLE_TYPE_PARA
|| pEntry
->m_nStyleTypeCode
== STYLE_TYPE_LIST
)
1113 bool bParaStyle
= pEntry
->m_nStyleTypeCode
== STYLE_TYPE_PARA
;
1114 bool bCharStyle
= pEntry
->m_nStyleTypeCode
== STYLE_TYPE_CHAR
;
1115 bool bListStyle
= pEntry
->m_nStyleTypeCode
== STYLE_TYPE_LIST
;
1116 bool bInsert
= false;
1117 uno::Reference
< container::XNameContainer
> xStyles
= bParaStyle
? xParaStyles
: (bListStyle
? xNumberingStyles
: xCharStyles
);
1118 uno::Reference
< style::XStyle
> xStyle
;
1119 const OUString sConvertedStyleName
= ConvertStyleName( pEntry
->m_sStyleName
);
1121 if(xStyles
->hasByName( sConvertedStyleName
))
1123 // When pasting, don't update existing styles.
1124 if (!m_pImpl
->m_bIsNewDoc
)
1128 xStyles
->getByName( sConvertedStyleName
) >>= xStyle
;
1131 StyleSheetTable_Impl::SetPropertiesToDefault(xStyle
);
1133 // resolve import conflicts with built-in styles (only if defaults have been defined)
1134 if ( m_pImpl
->m_bHasImportedDefaultParaProps
1135 && pEntry
->m_sBaseStyleIdentifier
.isEmpty() //imported style has no inheritance
1136 && !xStyle
->getParentStyle().isEmpty() ) //built-in style has a default inheritance
1138 xStyle
->setParentStyle( "" );
1145 xStyle
.set(xDocFactory
->createInstance(
1147 getPropertyName( PROP_SERVICE_PARA_STYLE
) :
1148 (bListStyle
? OUString("com.sun.star.style.NumberingStyle") : getPropertyName( PROP_SERVICE_CHAR_STYLE
))),
1149 uno::UNO_QUERY_THROW
);
1151 // Numbering styles have to be inserted early, as e.g. the NumberingRules property is only available after insertion.
1154 xStyles
->insertByName( sConvertedStyleName
, uno::Any( xStyle
) );
1155 xStyle
.set(xStyles
->getByName(sConvertedStyleName
), uno::UNO_QUERY_THROW
);
1157 StyleSheetPropertyMap
* pPropertyMap
= pEntry
->m_pProperties
.get();
1158 if (pPropertyMap
&& pPropertyMap
->props().GetListId() == -1)
1160 // No properties? Word default is 'none', Writer one is 'arabic', handle this.
1161 uno::Reference
<beans::XPropertySet
> xPropertySet(xStyle
, uno::UNO_QUERY_THROW
);
1162 uno::Reference
<container::XIndexReplace
> xNumberingRules
;
1163 xPropertySet
->getPropertyValue("NumberingRules") >>= xNumberingRules
;
1164 uno::Reference
<container::XIndexAccess
> xIndexAccess(xNumberingRules
, uno::UNO_QUERY_THROW
);
1165 for (sal_Int32 i
= 0; i
< xIndexAccess
->getCount(); ++i
)
1167 uno::Sequence
< beans::PropertyValue
> aLvlProps
{
1168 comphelper::makePropertyValue(
1169 "NumberingType", style::NumberingType::NUMBER_NONE
)
1171 xNumberingRules
->replaceByIndex(i
, uno::Any(aLvlProps
));
1172 xPropertySet
->setPropertyValue("NumberingRules", uno::Any(xNumberingRules
));
1177 if( !pEntry
->m_sBaseStyleIdentifier
.isEmpty() )
1181 //TODO: Handle cases where a paragraph <> character style relation is needed
1182 StyleSheetEntryPtr pParent
= FindStyleSheetByISTD( pEntry
->m_sBaseStyleIdentifier
);
1183 // Writer core doesn't support numbering styles having a parent style, it seems
1184 if (pParent
&& !bListStyle
)
1186 const OUString sParentStyleName
= ConvertStyleName( pParent
->m_sStyleName
);
1187 if ( !sParentStyleName
.isEmpty() && !xStyles
->hasByName( sParentStyleName
) )
1188 aMissingParent
.emplace_back( sParentStyleName
, xStyle
);
1190 xStyle
->setParentStyle( sParentStyleName
);
1193 catch( const uno::RuntimeException
& )
1195 OSL_FAIL( "Styles parent could not be set");
1198 else if( bParaStyle
)
1200 // Paragraph styles that don't inherit from some parent need to apply the DocDefaults
1201 pEntry
->m_pProperties
->InsertProps( m_pImpl
->m_pDefaultParaProps
, /*bOverwrite=*/false );
1203 //now it's time to set the default parameters - for paragraph styles
1204 //Fonts: Western first entry in font table
1206 //CTL: third entry, if it exists
1208 sal_uInt32 nFontCount
= rFontTable
->size();
1209 if( !m_pImpl
->m_rDMapper
.IsOOXMLImport() && nFontCount
> 2 )
1211 uno::Any
aTwoHundredFortyTwip(12.);
1213 // font size to 240 twip (12 pts) for all if not set
1214 pEntry
->m_pProperties
->Insert(PROP_CHAR_HEIGHT
, aTwoHundredFortyTwip
, false);
1216 // western font not already set -> apply first font
1217 const FontEntry::Pointer_t
pWesternFontEntry(rFontTable
->getFontEntry( 0 ));
1218 OUString sWesternFontName
= pWesternFontEntry
->sFontName
;
1219 pEntry
->m_pProperties
->Insert(PROP_CHAR_FONT_NAME
, uno::Any( sWesternFontName
), false);
1221 // CJK ... apply second font
1222 const FontEntry::Pointer_t
pCJKFontEntry(rFontTable
->getFontEntry( 2 ));
1223 pEntry
->m_pProperties
->Insert(PROP_CHAR_FONT_NAME_ASIAN
, uno::Any( pCJKFontEntry
->sFontName
), false);
1224 pEntry
->m_pProperties
->Insert(PROP_CHAR_HEIGHT_ASIAN
, aTwoHundredFortyTwip
, false);
1226 // CTL ... apply third font, if available
1227 if( nFontCount
> 3 )
1229 const FontEntry::Pointer_t
pCTLFontEntry(rFontTable
->getFontEntry( 3 ));
1230 pEntry
->m_pProperties
->Insert(PROP_CHAR_FONT_NAME_COMPLEX
, uno::Any( pCTLFontEntry
->sFontName
), false);
1231 pEntry
->m_pProperties
->Insert(PROP_CHAR_HEIGHT_COMPLEX
, aTwoHundredFortyTwip
, false);
1236 auto aPropValues
= comphelper::sequenceToContainer
< std::vector
<beans::PropertyValue
> >(pEntry
->m_pProperties
->GetPropertyValues());
1238 if (bParaStyle
|| bCharStyle
)
1240 // delay adding LinkStyle property: all styles need to be created first
1241 if (!pEntry
->m_sLinkStyleIdentifier
.isEmpty())
1243 StyleSheetEntryPtr pLinkStyle
1244 = FindStyleSheetByISTD(pEntry
->m_sLinkStyleIdentifier
);
1245 if (pLinkStyle
&& !pLinkStyle
->m_sStyleName
.isEmpty())
1246 aMissingLink
.emplace_back(ConvertStyleName(pLinkStyle
->m_sStyleName
),
1253 // delay adding FollowStyle property: all styles need to be created first
1254 if ( !pEntry
->m_sNextStyleIdentifier
.isEmpty() )
1256 StyleSheetEntryPtr pFollowStyle
= FindStyleSheetByISTD( pEntry
->m_sNextStyleIdentifier
);
1257 if ( pFollowStyle
&& !pFollowStyle
->m_sStyleName
.isEmpty() )
1258 aMissingFollow
.emplace_back( ConvertStyleName( pFollowStyle
->m_sStyleName
), xStyle
);
1261 // Set the outline levels
1262 StyleSheetPropertyMap
* pStyleSheetProperties
= pEntry
? pEntry
->m_pProperties
.get() : nullptr;
1264 if ( pStyleSheetProperties
)
1266 sal_Int16 nLvl
= pStyleSheetProperties
->GetOutlineLevel();
1267 // convert MS body Level (9) to LO body level (0) and equivalent outline levels
1270 if (nLvl
== WW_OUTLINE_MAX
)
1275 beans::PropertyValue
aLvlVal(getPropertyName(PROP_OUTLINE_LEVEL
), 0,
1277 beans::PropertyState_DIRECT_VALUE
);
1278 aPropValues
.push_back(aLvlVal
);
1282 uno::Reference
< beans::XPropertyState
>xState( xStyle
, uno::UNO_QUERY_THROW
);
1283 if( sConvertedStyleName
== "Contents Heading" ||
1284 sConvertedStyleName
== "User Index Heading" ||
1285 sConvertedStyleName
== "Index Heading" )
1287 // remove Left/RightMargin values from TOX heading styles
1288 //left margin is set to NULL by default
1289 xState
->setPropertyToDefault(getPropertyName( PROP_PARA_LEFT_MARGIN
));
1291 else if ( sConvertedStyleName
== "Text body" )
1292 xState
->setPropertyToDefault(getPropertyName( PROP_PARA_BOTTOM_MARGIN
));
1293 else if ( sConvertedStyleName
== "Heading 1" ||
1294 sConvertedStyleName
== "Heading 2" ||
1295 sConvertedStyleName
== "Heading 3" ||
1296 sConvertedStyleName
== "Heading 4" ||
1297 sConvertedStyleName
== "Heading 5" ||
1298 sConvertedStyleName
== "Heading 6" ||
1299 sConvertedStyleName
== "Heading 7" ||
1300 sConvertedStyleName
== "Heading 8" ||
1301 sConvertedStyleName
== "Heading 9" )
1303 xState
->setPropertyToDefault(getPropertyName( PROP_CHAR_WEIGHT
));
1304 xState
->setPropertyToDefault(getPropertyName( PROP_CHAR_WEIGHT_ASIAN
));
1305 xState
->setPropertyToDefault(getPropertyName( PROP_CHAR_WEIGHT_COMPLEX
));
1306 xState
->setPropertyToDefault(getPropertyName( PROP_CHAR_POSTURE
));
1307 xState
->setPropertyToDefault(getPropertyName( PROP_CHAR_POSTURE_ASIAN
));
1308 xState
->setPropertyToDefault(getPropertyName( PROP_CHAR_POSTURE_COMPLEX
));
1309 xState
->setPropertyToDefault(getPropertyName( PROP_CHAR_PROP_HEIGHT
));
1310 xState
->setPropertyToDefault(getPropertyName( PROP_CHAR_PROP_HEIGHT_ASIAN
));
1311 xState
->setPropertyToDefault(getPropertyName( PROP_CHAR_PROP_HEIGHT_COMPLEX
));
1316 if ( !aPropValues
.empty() )
1318 PropValVector aSortedPropVals
;
1319 for (const beans::PropertyValue
& rValue
: aPropValues
)
1321 // Don't add the style name properties
1322 bool bIsParaStyleName
= rValue
.Name
== "ParaStyleName";
1323 bool bIsCharStyleName
= rValue
.Name
== "CharStyleName";
1324 if ( !bIsParaStyleName
&& !bIsCharStyleName
)
1326 aSortedPropVals
.Insert(rValue
);
1332 uno::Reference
< beans::XMultiPropertySet
> xMultiPropertySet( xStyle
, uno::UNO_QUERY_THROW
);
1335 xMultiPropertySet
->setPropertyValues( aSortedPropVals
.getNames(), aSortedPropVals
.getValues() );
1337 catch ( const uno::Exception
& )
1339 uno::Reference
<beans::XPropertySet
> xPropertySet(xStyle
, uno::UNO_QUERY_THROW
);
1340 for ( const beans::PropertyValue
& rValue
: aSortedPropVals
.getProperties() )
1344 xPropertySet
->setPropertyValue( rValue
.Name
, rValue
.Value
);
1346 catch ( const uno::Exception
& )
1348 SAL_WARN( "writerfilter", "StyleSheetTable::ApplyStyleSheets could not set property " << rValue
.Name
);
1352 // Duplicate MSWord's single footnote reference into Footnote Characters and Footnote anchor
1353 if( pEntry
->m_sStyleName
.equalsIgnoreAsciiCase("footnote reference")
1354 || pEntry
->m_sStyleName
.equalsIgnoreAsciiCase("endnote reference") )
1356 uno::Reference
< style::XStyle
> xCopyStyle
;
1357 if( pEntry
->m_sStyleName
.equalsIgnoreAsciiCase("footnote reference") )
1358 xStyles
->getByName( "Footnote anchor" ) >>= xCopyStyle
;
1360 xStyles
->getByName( "Endnote anchor" ) >>= xCopyStyle
;
1362 xMultiPropertySet
.set( xCopyStyle
, uno::UNO_QUERY_THROW
);
1363 xMultiPropertySet
->setPropertyValues( aSortedPropVals
.getNames(), aSortedPropVals
.getValues() );
1366 catch( const lang::WrappedTargetException
& rWrapped
)
1369 OUString
aMessage("StyleSheetTable::ApplyStyleSheets: Some style properties could not be set");
1370 beans::UnknownPropertyException aUnknownPropertyException
;
1372 if (rWrapped
.TargetException
>>= aUnknownPropertyException
)
1373 aMessage
+= ": " + aUnknownPropertyException
.Message
;
1375 SAL_WARN("writerfilter", aMessage
);
1380 catch( const uno::Exception
& )
1382 OSL_FAIL( "Some style properties could not be set");
1385 // Numbering style got inserted earlier.
1386 if(bInsert
&& !bListStyle
)
1388 const OUString sParentStyle
= xStyle
->getParentStyle();
1389 if( !sParentStyle
.isEmpty() && !xStyles
->hasByName( sParentStyle
) )
1390 aMissingParent
.emplace_back( sParentStyle
, xStyle
);
1392 xStyles
->insertByName( sConvertedStyleName
, uno::Any( xStyle
) );
1395 beans::PropertyValues aGrabBag
= pEntry
->GetInteropGrabBagSeq();
1396 uno::Reference
<beans::XPropertySet
> xPropertySet(xStyle
, uno::UNO_QUERY
);
1397 if (aGrabBag
.hasElements())
1399 xPropertySet
->setPropertyValue("StyleInteropGrabBag", uno::Any(aGrabBag
));
1402 // Only paragraph styles support automatic updates.
1403 if (pEntry
->m_bAutoRedefine
&& bParaStyle
)
1404 xPropertySet
->setPropertyValue("IsAutoUpdate", uno::Any(true));
1406 else if(pEntry
->m_nStyleTypeCode
== STYLE_TYPE_TABLE
)
1408 // If this is a table style, save its contents as-is for roundtrip purposes.
1409 TableStyleSheetEntry
* pTableEntry
= static_cast<TableStyleSheetEntry
*>(pEntry
.get());
1410 aTableStylesVec
.push_back(pTableEntry
->GetInteropGrabBag());
1412 // if DocDefaults exist, MS Word includes these in the table style definition.
1413 pEntry
->m_pProperties
->InsertProps( m_pImpl
->m_pDefaultCharProps
, /*bOverwrite=*/false );
1414 pEntry
->m_pProperties
->InsertProps( m_pImpl
->m_pDefaultParaProps
, /*bOverwrite=*/false );
1418 // Update the styles that were created before their parents or next-styles
1419 for( auto const & iter
: aMissingParent
)
1421 iter
.second
->setParentStyle( iter
.first
);
1424 for( auto const & iter
: aMissingFollow
)
1428 uno::Reference
<beans::XPropertySet
> xPropertySet(iter
.second
, uno::UNO_QUERY
);
1429 xPropertySet
->setPropertyValue( "FollowStyle", uno::Any(iter
.first
) );
1431 catch( uno::Exception
& ) {}
1434 // Update the styles that were created before their linked styles.
1435 for (auto const& rLinked
: aMissingLink
)
1439 uno::Reference
<beans::XPropertySet
> xPropertySet(rLinked
.second
,
1441 xPropertySet
->setPropertyValue("LinkStyle", uno::Any(rLinked
.first
));
1443 catch (uno::Exception
&)
1445 TOOLS_WARN_EXCEPTION(
1447 "StyleSheetTable::ApplyStyleSheets: failed to set LinkStyle");
1451 if (!aTableStylesVec
.empty())
1453 // If we had any table styles, add a new document-level InteropGrabBag entry for them.
1454 uno::Reference
<beans::XPropertySet
> xPropertySet(m_pImpl
->m_xTextDocument
, uno::UNO_QUERY
);
1455 uno::Any aAny
= xPropertySet
->getPropertyValue("InteropGrabBag");
1456 auto aGrabBag
= comphelper::sequenceToContainer
< std::vector
<beans::PropertyValue
> >(aAny
.get
< uno::Sequence
<beans::PropertyValue
> >());
1457 beans::PropertyValue aValue
;
1458 aValue
.Name
= "tableStyles";
1459 aValue
.Value
<<= comphelper::containerToSequence(aTableStylesVec
);
1460 aGrabBag
.push_back(aValue
);
1461 xPropertySet
->setPropertyValue("InteropGrabBag", uno::Any(comphelper::containerToSequence(aGrabBag
)));
1465 catch( const uno::Exception
& )
1467 DBG_UNHANDLED_EXCEPTION("writerfilter", "Styles could not be imported completely");
1472 StyleSheetEntryPtr
StyleSheetTable::FindStyleSheetByISTD(const OUString
& sIndex
)
1474 auto findIt
= m_pImpl
->m_aStyleSheetEntriesMap
.find(sIndex
);
1475 if (findIt
!= m_pImpl
->m_aStyleSheetEntriesMap
.end())
1476 return findIt
->second
;
1477 return StyleSheetEntryPtr();
1481 StyleSheetEntryPtr
StyleSheetTable::FindStyleSheetByConvertedStyleName(std::u16string_view sIndex
)
1483 StyleSheetEntryPtr pRet
;
1484 for(const StyleSheetEntryPtr
& rpEntry
: m_pImpl
->m_aStyleSheetEntries
)
1486 if( rpEntry
->m_sConvertedStyleName
== sIndex
)
1496 StyleSheetEntryPtr
StyleSheetTable::FindDefaultParaStyle()
1498 return FindStyleSheetByISTD( m_pImpl
->m_sDefaultParaStyleName
);
1501 const StyleSheetEntryPtr
& StyleSheetTable::GetCurrentEntry() const
1503 return m_pImpl
->m_pCurrentEntry
;
1506 OUString
StyleSheetTable::ConvertStyleName( const OUString
& rWWName
, bool bExtendedSearch
)
1508 OUString
sRet( rWWName
);
1509 if( bExtendedSearch
)
1511 //search for the rWWName in the IdentifierD of the existing styles and convert the sStyleName member
1512 auto findIt
= m_pImpl
->m_aStyleSheetEntriesMap
.find(rWWName
);
1513 if (findIt
!= m_pImpl
->m_aStyleSheetEntriesMap
.end())
1515 if (!findIt
->second
->m_sConvertedStyleName
.isEmpty())
1516 return findIt
->second
->m_sConvertedStyleName
;
1517 sRet
= findIt
->second
->m_sStyleName
;
1521 // create a map only once
1522 // This maps Word's special style manes to Writer's (the opposite to what MSWordStyles::GetWWId
1523 // and ww::GetEnglishNameFromSti do on export). The mapping gives a Writer's style name, which
1524 // will point to a style with specific RES_POOL* in its m_nPoolFormatId. Then on export, the
1525 // pool format id will map to a ww::sti enum value, and finally to a Word style name. Keep this
1526 // part in sync with the export functions mentioned above!
1527 // In addition to "standard" names, some case variations are handled here; and also there are
1528 // a number of strange mappings like "BodyTextIndentItalic" -> "Text body indent italic", which
1529 // map something unused in Word to something unused in Writer :-/
1530 static const std::map
< OUString
, OUString
> StyleNameMap
{
1531 { "Normal", "Standard" }, // RES_POOLCOLL_STANDARD
1532 { "heading 1", "Heading 1" }, // RES_POOLCOLL_HEADLINE1
1533 { "heading 2", "Heading 2" }, // RES_POOLCOLL_HEADLINE2
1534 { "heading 3", "Heading 3" }, // RES_POOLCOLL_HEADLINE3
1535 { "heading 4", "Heading 4" }, // RES_POOLCOLL_HEADLINE4
1536 { "heading 5", "Heading 5" }, // RES_POOLCOLL_HEADLINE5
1537 { "heading 6", "Heading 6" }, // RES_POOLCOLL_HEADLINE6
1538 { "heading 7", "Heading 7" }, // RES_POOLCOLL_HEADLINE7
1539 { "heading 8", "Heading 8" }, // RES_POOLCOLL_HEADLINE8
1540 { "heading 9", "Heading 9" }, // RES_POOLCOLL_HEADLINE9
1541 { "Heading 1", "Heading 1" }, // RES_POOLCOLL_HEADLINE1
1542 { "Heading 2", "Heading 2" }, // RES_POOLCOLL_HEADLINE2
1543 { "Heading 3", "Heading 3" }, // RES_POOLCOLL_HEADLINE3
1544 { "Heading 4", "Heading 4" }, // RES_POOLCOLL_HEADLINE4
1545 { "Heading 5", "Heading 5" }, // RES_POOLCOLL_HEADLINE5
1546 { "Heading 6", "Heading 6" }, // RES_POOLCOLL_HEADLINE6
1547 { "Heading 7", "Heading 7" }, // RES_POOLCOLL_HEADLINE7
1548 { "Heading 8", "Heading 8" }, // RES_POOLCOLL_HEADLINE8
1549 { "Heading 9", "Heading 9" }, // RES_POOLCOLL_HEADLINE9
1550 { "Index 1", "Index 1" }, // RES_POOLCOLL_TOX_IDX1
1551 { "Index 2", "Index 2" }, // RES_POOLCOLL_TOX_IDX2
1552 { "Index 3", "Index 3" }, // RES_POOLCOLL_TOX_IDX3
1553 // { "Index 4", "" },
1554 // { "Index 5", "" },
1555 // { "Index 6", "" },
1556 // { "Index 7", "" },
1557 // { "Index 8", "" },
1558 // { "Index 9", "" },
1559 { "TOC 1", "Contents 1" }, // RES_POOLCOLL_TOX_CNTNT1
1560 { "TOC 2", "Contents 2" }, // RES_POOLCOLL_TOX_CNTNT2
1561 { "TOC 3", "Contents 3" }, // RES_POOLCOLL_TOX_CNTNT3
1562 { "TOC 4", "Contents 4" }, // RES_POOLCOLL_TOX_CNTNT4
1563 { "TOC 5", "Contents 5" }, // RES_POOLCOLL_TOX_CNTNT5
1564 { "TOC 6", "Contents 6" }, // RES_POOLCOLL_TOX_CNTNT6
1565 { "TOC 7", "Contents 7" }, // RES_POOLCOLL_TOX_CNTNT7
1566 { "TOC 8", "Contents 8" }, // RES_POOLCOLL_TOX_CNTNT8
1567 { "TOC 9", "Contents 9" }, // RES_POOLCOLL_TOX_CNTNT9
1568 { "TOC Heading", "Contents Heading" }, // RES_POOLCOLL_TOX_CNTNTH
1569 { "TOCHeading", "Contents Heading" }, // RES_POOLCOLL_TOX_CNTNTH
1570 { "toc 1", "Contents 1" }, // RES_POOLCOLL_TOX_CNTNT1
1571 { "toc 2", "Contents 2" }, // RES_POOLCOLL_TOX_CNTNT2
1572 { "toc 3", "Contents 3" }, // RES_POOLCOLL_TOX_CNTNT3
1573 { "toc 4", "Contents 4" }, // RES_POOLCOLL_TOX_CNTNT4
1574 { "toc 5", "Contents 5" }, // RES_POOLCOLL_TOX_CNTNT5
1575 { "toc 6", "Contents 6" }, // RES_POOLCOLL_TOX_CNTNT6
1576 { "toc 7", "Contents 7" }, // RES_POOLCOLL_TOX_CNTNT7
1577 { "toc 8", "Contents 8" }, // RES_POOLCOLL_TOX_CNTNT8
1578 { "toc 9", "Contents 9" }, // RES_POOLCOLL_TOX_CNTNT9
1579 { "TOC1", "Contents 1" }, // RES_POOLCOLL_TOX_CNTNT1
1580 { "TOC2", "Contents 2" }, // RES_POOLCOLL_TOX_CNTNT2
1581 { "TOC3", "Contents 3" }, // RES_POOLCOLL_TOX_CNTNT3
1582 { "TOC4", "Contents 4" }, // RES_POOLCOLL_TOX_CNTNT4
1583 { "TOC5", "Contents 5" }, // RES_POOLCOLL_TOX_CNTNT5
1584 { "TOC6", "Contents 6" }, // RES_POOLCOLL_TOX_CNTNT6
1585 { "TOC7", "Contents 7" }, // RES_POOLCOLL_TOX_CNTNT7
1586 { "TOC8", "Contents 8" }, // RES_POOLCOLL_TOX_CNTNT8
1587 { "TOC9", "Contents 9" }, // RES_POOLCOLL_TOX_CNTNT9
1588 // { "Normal Indent", "" },
1589 { "footnote text", "Footnote" }, // RES_POOLCOLL_FOOTNOTE
1590 { "Footnote Text", "Footnote" }, // RES_POOLCOLL_FOOTNOTE
1591 { "Annotation Text", "Marginalia" }, // RES_POOLCOLL_MARGINAL
1592 { "Header", "Header" }, // RES_POOLCOLL_HEADER
1593 { "header", "Header" }, // RES_POOLCOLL_HEADER
1594 { "Footer", "Footer" }, // RES_POOLCOLL_FOOTER
1595 { "footer", "Footer" }, // RES_POOLCOLL_FOOTER
1596 { "Index Heading", "Index Heading" }, // RES_POOLCOLL_TOX_IDXH
1597 { "Caption", "Caption" }, // RES_POOLCOLL_LABEL
1598 { "table of figures", "Figure Index 1" }, // RES_POOLCOLL_TOX_ILLUS1
1599 { "Table of Figures", "Figure Index 1" }, // RES_POOLCOLL_TOX_ILLUS1
1600 { "Envelope Address", "Addressee" }, // RES_POOLCOLL_ENVELOPE_ADDRESS
1601 { "Envelope Return", "Sender" }, // RES_POOLCOLL_SEND_ADDRESS
1602 { "footnote reference", "Footnote Symbol" }, // RES_POOLCHR_FOOTNOTE; tdf#82173
1603 { "Footnote Reference", "Footnote Symbol" }, // RES_POOLCHR_FOOTNOTE; tdf#82173
1604 // { "Annotation Reference", "" },
1605 { "Line Number", "Line numbering" }, // RES_POOLCHR_LINENUM
1606 { "Page Number", "Page Number" }, // RES_POOLCHR_PAGENO
1607 { "endnote reference", "Endnote Symbol" }, // RES_POOLCHR_ENDNOTE; tdf#82173
1608 { "Endnote Reference", "Endnote Symbol" }, // RES_POOLCHR_ENDNOTE; tdf#82173
1609 { "endnote text", "Endnote" }, // RES_POOLCOLL_ENDNOTE
1610 { "Endnote Text", "Endnote" }, // RES_POOLCOLL_ENDNOTE
1611 { "Table of Authorities", "Bibliography Heading" }, // RES_POOLCOLL_TOX_AUTHORITIESH
1612 // { "Macro Text", "" },
1613 // { "TOA Heading", "" },
1614 { "List", "List" }, // RES_POOLCOLL_NUMBER_BULLET_BASE
1615 // { "List 2", "" },
1616 // { "List 3", "" },
1617 // { "List 4", "" },
1618 // { "List 5", "" },
1619 { "List Bullet", "List 1" }, // RES_POOLCOLL_BULLET_LEVEL1
1620 { "List Bullet 2", "List 2" }, // RES_POOLCOLL_BULLET_LEVEL2
1621 { "List Bullet 3", "List 3" }, // RES_POOLCOLL_BULLET_LEVEL3
1622 { "List Bullet 4", "List 4" }, // RES_POOLCOLL_BULLET_LEVEL4
1623 { "List Bullet 5", "List 5" }, // RES_POOLCOLL_BULLET_LEVEL5
1624 { "List Number", "Numbering 1" }, // RES_POOLCOLL_NUM_LEVEL1
1625 { "List Number 2", "Numbering 2" }, // RES_POOLCOLL_NUM_LEVEL2
1626 { "List Number 3", "Numbering 3" }, // RES_POOLCOLL_NUM_LEVEL3
1627 { "List Number 4", "Numbering 4" }, // RES_POOLCOLL_NUM_LEVEL4
1628 { "List Number 5", "Numbering 5" }, // RES_POOLCOLL_NUM_LEVEL5
1629 { "Title", "Title" }, // RES_POOLCOLL_DOC_TITLE
1630 { "Closing", "Appendix" }, // RES_POOLCOLL_DOC_APPENDIX
1631 { "Signature", "Signature" }, // RES_POOLCOLL_SIGNATURE
1632 // { "Default Paragraph Font", "" },
1633 { "DefaultParagraphFont", "Default Paragraph Font" },
1634 { "Body Text", "Text body" }, // RES_POOLCOLL_TEXT
1635 { "BodyText", "Text body" }, // RES_POOLCOLL_TEXT
1636 { "BodyTextIndentItalic", "Text body indent italic" },
1637 { "Body Text Indent", "Text body indent" }, // RES_POOLCOLL_TEXT_MOVE
1638 { "BodyTextIndent", "Text body indent" }, // RES_POOLCOLL_TEXT_MOVE
1639 { "BodyTextIndent2", "Text body indent2" },
1640 { "List Continue", "List 1 Cont." }, // RES_POOLCOLL_BULLET_NONUM1
1641 { "List Continue 2", "List 2 Cont." }, // RES_POOLCOLL_BULLET_NONUM2
1642 { "List Continue 3", "List 3 Cont." }, // RES_POOLCOLL_BULLET_NONUM3
1643 { "List Continue 4", "List 4 Cont." }, // RES_POOLCOLL_BULLET_NONUM4
1644 { "List Continue 5", "List 5 Cont." }, // RES_POOLCOLL_BULLET_NONUM5
1645 // { "Message Header", "" },
1646 { "Subtitle", "Subtitle" }, // RES_POOLCOLL_DOC_SUBTITLE
1647 { "Salutation", "Salutation" }, // RES_POOLCOLL_GREETING
1649 { "Body Text First Indent", "First line indent" }, // RES_POOLCOLL_TEXT_IDENT
1650 // { "Body Text First Indent 2", "" },
1651 // { "Note Heading", "" },
1652 // { "Body Text 2", "" },
1653 // { "Body Text 3", "" },
1654 // { "Body Text Indent 2", "" },
1655 // { "Body Text Indent 3", "" },
1656 // { "Block Text", "" },
1657 { "Hyperlink", "Internet link" }, // RES_POOLCHR_INET_NORMAL
1658 { "FollowedHyperlink", "Visited Internet Link" }, // RES_POOLCHR_INET_VISIT
1659 { "Strong", "Strong Emphasis" }, // RES_POOLCHR_HTML_STRONG
1660 { "Emphasis", "Emphasis" }, // RES_POOLCHR_HTML_EMPHASIS
1661 // { "Document Map", "" },
1662 // { "Plain Text", "" },
1663 { "NoList", "No List" },
1664 { "AbstractHeading", "Abstract Heading" },
1665 { "AbstractBody", "Abstract Body" },
1666 { "PageNumber", "Page Number" }, // RES_POOLCHR_PAGENO
1667 { "TableNormal", "Normal Table" },
1668 { "DocumentMap", "Document Map" },
1671 // find style-name using map
1672 if (const auto aIt
= StyleNameMap
.find(sRet
); aIt
!= StyleNameMap
.end())
1678 // Style names which should not be used without a " (user)" suffix
1679 static const o3tl::sorted_vector
<OUString
> ReservedStyleNames
= [] {
1680 o3tl::sorted_vector
<OUString
> set
;
1681 for (const auto& pair
: StyleNameMap
)
1682 set
.insert(pair
.second
);
1685 // Similar to SwStyleNameMapper convention (where a " (user)" suffix is used to
1686 // disambiguate user styles with reserved names in localization where respective
1687 // built-in styles have different UI names), we add a " (WW)" suffix here. Unlike
1688 // the " (user)" suffix, it is not hidden from the UI; it will be handled when
1689 // exported to Word formats - see MSWordStyles::BuildWwNames.
1690 // We can't use the " (user)" suffix, because that system is built upon the assumption
1691 // that UI names of respective built-in styles are different from the user style name.
1692 // That is not necessarily true here, since the current localization may not change
1693 // the UI names of built-in styles.
1694 if (ReservedStyleNames
.find(sRet
) != ReservedStyleNames
.end() || sRet
.endsWith(" (WW)"))
1701 void StyleSheetTable::applyDefaults(bool bParaProperties
)
1705 if (!m_pImpl
->m_bIsNewDoc
)
1707 // tdf#72942: do not corrupts original styles in master document
1708 // during inserting of text from second document
1712 if(!m_pImpl
->m_xTextDefaults
.is())
1714 m_pImpl
->m_xTextDefaults
.set(
1715 m_pImpl
->m_rDMapper
.GetTextFactory()->createInstance("com.sun.star.text.Defaults"),
1716 uno::UNO_QUERY_THROW
);
1719 // WARNING: these defaults only take effect IF there is a DocDefaults style section. Normally there is, but not always.
1720 if( bParaProperties
&& m_pImpl
->m_pDefaultParaProps
)
1722 // tdf#87533 LO will have different defaults here, depending on the locale. Import with documented defaults
1723 SetDefaultParaProps(PROP_WRITING_MODE
, uno::Any(sal_Int16(text::WritingMode_LR_TB
)));
1724 SetDefaultParaProps(PROP_PARA_ADJUST
, uno::Any(sal_Int16(style::ParagraphAdjust_LEFT
)));
1726 // Widow/Orphan -> set both to two if not already set
1727 uno::Any
aTwo(sal_Int8(2));
1728 SetDefaultParaProps(PROP_PARA_WIDOWS
, aTwo
);
1729 SetDefaultParaProps(PROP_PARA_ORPHANS
, aTwo
);
1731 uno::Reference
<style::XStyleFamiliesSupplier
> xStylesSupplier(m_pImpl
->m_xTextDocument
, uno::UNO_QUERY
);
1732 uno::Reference
<container::XNameAccess
> xStyleFamilies
= xStylesSupplier
->getStyleFamilies();
1733 uno::Reference
<container::XNameAccess
> xParagraphStyles
;
1734 xStyleFamilies
->getByName("ParagraphStyles") >>= xParagraphStyles
;
1735 uno::Reference
<beans::XPropertySet
> xDefault
;
1736 // This is the built-in default style that every style inherits from
1737 xParagraphStyles
->getByName("Paragraph style") >>= xDefault
;
1739 const uno::Sequence
< beans::PropertyValue
> aPropValues
= m_pImpl
->m_pDefaultParaProps
->GetPropertyValues();
1740 for( const auto& rPropValue
: aPropValues
)
1744 xDefault
->setPropertyValue(rPropValue
.Name
, rPropValue
.Value
);
1746 catch( const uno::Exception
& )
1748 TOOLS_WARN_EXCEPTION( "writerfilter", "setPropertyValue");
1752 if( !bParaProperties
&& m_pImpl
->m_pDefaultCharProps
)
1754 // tdf#108350: Earlier in DomainMapper for DOCX, Calibri/11pt was set to match MSWord 2007+,
1755 // but that is valid only if DocDefaults_rPrDefault is omitted.
1756 // Now that DocDefaults_rPrDefault is known, the defaults should be reset to Times New Roman/10pt.
1757 if ( m_pImpl
->m_rDMapper
.IsOOXMLImport() )
1758 m_pImpl
->m_xTextDefaults
->setPropertyValue( getPropertyName(PROP_CHAR_FONT_NAME
), css::uno::Any(OUString("Times New Roman")) );
1760 const uno::Sequence
< beans::PropertyValue
> aPropValues
= m_pImpl
->m_pDefaultCharProps
->GetPropertyValues();
1761 for( const auto& rPropValue
: aPropValues
)
1765 m_pImpl
->m_xTextDefaults
->setPropertyValue( rPropValue
.Name
, rPropValue
.Value
);
1767 catch( const uno::Exception
& )
1769 TOOLS_WARN_EXCEPTION( "writerfilter", "exception");
1774 catch( const uno::Exception
& )
1780 OUString
StyleSheetTable::getOrCreateCharStyle( PropertyValueVector_t
& rCharProperties
, bool bAlwaysCreate
)
1782 //find out if any of the styles already has the required properties then return its name
1783 OUString sListLabel
= m_pImpl
->HasListCharStyle(rCharProperties
);
1784 // Don't try to reuse an existing character style if requested.
1785 if( !sListLabel
.isEmpty() && !bAlwaysCreate
)
1788 //create a new one otherwise
1789 const uno::Reference
< container::XNameContainer
>& xCharStyles
= m_pImpl
->m_rDMapper
.GetCharacterStyles();
1790 sListLabel
= m_pImpl
->m_rDMapper
.GetUnusedCharacterStyleName();
1791 uno::Reference
< lang::XMultiServiceFactory
> xDocFactory( m_pImpl
->m_xTextDocument
, uno::UNO_QUERY_THROW
);
1794 uno::Reference
< style::XStyle
> xStyle( xDocFactory
->createInstance(
1795 getPropertyName( PROP_SERVICE_CHAR_STYLE
)), uno::UNO_QUERY_THROW
);
1796 uno::Reference
< beans::XPropertySet
> xStyleProps(xStyle
, uno::UNO_QUERY_THROW
);
1797 for( const auto& rCharProp
: rCharProperties
)
1801 xStyleProps
->setPropertyValue( rCharProp
.Name
, rCharProp
.Value
);
1803 catch( const uno::Exception
& )
1805 TOOLS_WARN_EXCEPTION( "writerfilter", "StyleSheetTable::getOrCreateCharStyle - Style::setPropertyValue");
1808 xCharStyles
->insertByName( sListLabel
, uno::Any( xStyle
) );
1809 m_pImpl
->m_aListCharStylePropertyVector
.emplace_back( sListLabel
, std::vector(rCharProperties
) );
1811 catch( const uno::Exception
& )
1813 TOOLS_WARN_EXCEPTION( "writerfilter", "StyleSheetTable::getOrCreateCharStyle");
1819 }//namespace writerfilter
1821 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */