Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #include <StyleSheetTable.hxx>
20 : #include "util.hxx"
21 : #include <NumberingManager.hxx>
22 : #include <ConversionHelper.hxx>
23 : #include <TblStylePrHandler.hxx>
24 : #include <BorderHandler.hxx>
25 : #include <LatentStyleHandler.hxx>
26 : #include <ooxml/resourceids.hxx>
27 : #include <vector>
28 : #include <com/sun/star/beans/XMultiPropertySet.hpp>
29 : #include <com/sun/star/beans/XPropertyState.hpp>
30 : #include <com/sun/star/beans/PropertyValue.hpp>
31 : #include <com/sun/star/container/XNameContainer.hpp>
32 : #include <com/sun/star/text/XChapterNumberingSupplier.hpp>
33 : #include <com/sun/star/text/XTextDocument.hpp>
34 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
35 : #include <com/sun/star/style/XStyle.hpp>
36 : #include <com/sun/star/style/ParagraphAdjust.hpp>
37 : #include <com/sun/star/text/WritingMode.hpp>
38 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 : #include <map>
40 : #include <set>
41 : #include <osl/diagnose.h>
42 : #include <rtl/ustrbuf.hxx>
43 : #include <comphelper/string.hxx>
44 : #include <comphelper/sequence.hxx>
45 :
46 : using namespace ::com::sun::star;
47 :
48 : namespace writerfilter {
49 : namespace dmapper
50 : {
51 :
52 : typedef ::std::map< OUString, OUString> StringPairMap_t;
53 :
54 :
55 :
56 51859 : StyleSheetEntry::StyleSheetEntry() :
57 : sStyleIdentifierI()
58 : ,sStyleIdentifierD()
59 : ,bIsDefaultStyle(false)
60 : ,bInvalidHeight(false)
61 : ,bHasUPE(false)
62 : ,nStyleTypeCode(STYLE_TYPE_UNKNOWN)
63 : ,sBaseStyleIdentifier()
64 : ,sNextStyleIdentifier()
65 51859 : ,pProperties(new StyleSheetPropertyMap)
66 103718 : ,bAutoRedefine(false)
67 : {
68 51859 : }
69 :
70 101224 : StyleSheetEntry::~StyleSheetEntry()
71 : {
72 101224 : }
73 :
74 2494 : TableStyleSheetEntry::TableStyleSheetEntry( StyleSheetEntry& rEntry, StyleSheetTable* pStyles ):
75 : StyleSheetEntry( ),
76 2494 : m_pStyleSheet( pStyles )
77 : {
78 :
79 2494 : bIsDefaultStyle = rEntry.bIsDefaultStyle;
80 2494 : bInvalidHeight = rEntry.bInvalidHeight;
81 2494 : bHasUPE = rEntry.bHasUPE;
82 2494 : nStyleTypeCode = STYLE_TYPE_TABLE;
83 2494 : sBaseStyleIdentifier = rEntry.sBaseStyleIdentifier;
84 2494 : sNextStyleIdentifier = rEntry.sNextStyleIdentifier;
85 2494 : sStyleName = rEntry.sStyleName;
86 2494 : sStyleName1 = rEntry.sStyleName1;
87 2494 : sStyleIdentifierI = rEntry.sStyleIdentifierI;
88 2494 : sStyleIdentifierD = rEntry.sStyleIdentifierD;
89 :
90 2494 : m_nColBandSize = 1;
91 2494 : m_nRowBandSize = 1;
92 2494 : }
93 :
94 7482 : TableStyleSheetEntry::~TableStyleSheetEntry( )
95 : {
96 2494 : m_pStyleSheet = nullptr;
97 4988 : }
98 :
99 2593 : void TableStyleSheetEntry::AddTblStylePr( TblStyleType nType, PropertyMapPtr pProps )
100 : {
101 : static const int nTypesProps = 4;
102 : static const TblStyleType pTypesToFix[nTypesProps] =
103 : {
104 : TBL_STYLE_FIRSTROW,
105 : TBL_STYLE_LASTROW,
106 : TBL_STYLE_FIRSTCOL,
107 : TBL_STYLE_LASTCOL
108 : };
109 :
110 : static const PropertyIds pPropsToCheck[nTypesProps] =
111 : {
112 : PROP_BOTTOM_BORDER,
113 : PROP_TOP_BORDER,
114 : PROP_RIGHT_BORDER,
115 : PROP_LEFT_BORDER
116 : };
117 :
118 8267 : for (int i=0; i < nTypesProps; ++i )
119 : {
120 7347 : if ( nType == pTypesToFix[i] )
121 : {
122 1673 : PropertyIds nChecked = pPropsToCheck[i];
123 1673 : boost::optional<PropertyMap::Property> pChecked = pProps->getProperty(nChecked);
124 :
125 1673 : PropertyIds nInsideProp = ( i < 2 ) ? META_PROP_HORIZONTAL_BORDER : META_PROP_VERTICAL_BORDER;
126 3346 : boost::optional<PropertyMap::Property> pInside = pProps->getProperty(nInsideProp);
127 :
128 1673 : if ( pChecked && pProps )
129 : {
130 : // In this case, remove the inside border
131 873 : pProps->Erase( nInsideProp );
132 : }
133 :
134 3346 : break;
135 : }
136 : }
137 :
138 : // Append the tblStylePr
139 2593 : m_aStyles[nType] = pProps;
140 2593 : }
141 :
142 4132 : PropertyMapPtr TableStyleSheetEntry::GetProperties( sal_Int32 nMask, StyleSheetEntryDequePtr pStack )
143 : {
144 4132 : PropertyMapPtr pProps( new PropertyMap );
145 :
146 : // First get the parent properties
147 8264 : StyleSheetEntryPtr pEntry = m_pStyleSheet->FindParentStyleSheet( sBaseStyleIdentifier );
148 :
149 4132 : if ( pEntry.get( ) )
150 : {
151 4126 : if (pStack.get() == nullptr)
152 4126 : pStack.reset(new StyleSheetEntryDeque());
153 :
154 4126 : StyleSheetEntryDeque::const_iterator aIt = find(pStack->begin(), pStack->end(), pEntry);
155 :
156 4126 : if (aIt != pStack->end())
157 : {
158 0 : pStack->push_back(pEntry);
159 :
160 0 : TableStyleSheetEntry* pParent = static_cast<TableStyleSheetEntry *>( pEntry.get( ) );
161 0 : pProps->InsertProps(pParent->GetProperties(nMask));
162 :
163 0 : pStack->pop_back();
164 : }
165 : }
166 :
167 : // And finally get the mask ones
168 4132 : pProps->InsertProps(GetLocalPropertiesFromMask(nMask));
169 :
170 8264 : return pProps;
171 : }
172 :
173 46352 : beans::PropertyValues StyleSheetEntry::GetInteropGrabBagSeq()
174 : {
175 46352 : uno::Sequence<beans::PropertyValue> aSeq(m_aInteropGrabBag.size());
176 46352 : beans::PropertyValue* pSeq = aSeq.getArray();
177 207702 : for (std::vector<beans::PropertyValue>::iterator i = m_aInteropGrabBag.begin(); i != m_aInteropGrabBag.end(); ++i)
178 161350 : *pSeq++ = *i;
179 :
180 46352 : return aSeq;
181 : }
182 :
183 2494 : beans::PropertyValue StyleSheetEntry::GetInteropGrabBag()
184 : {
185 2494 : beans::PropertyValue aRet;
186 2494 : aRet.Name = sStyleIdentifierI;
187 :
188 4988 : beans::PropertyValues aSeq = GetInteropGrabBagSeq();;
189 2494 : aRet.Value = uno::makeAny(aSeq);
190 4988 : return aRet;
191 : }
192 :
193 161350 : void StyleSheetEntry::AppendInteropGrabBag(const beans::PropertyValue& rValue)
194 : {
195 161350 : m_aInteropGrabBag.push_back(rValue);
196 161350 : }
197 :
198 1659 : void lcl_mergeProps( PropertyMapPtr pToFill, PropertyMapPtr pToAdd, TblStyleType nStyleId )
199 : {
200 : static const PropertyIds pPropsToCheck[] =
201 : {
202 : PROP_BOTTOM_BORDER,
203 : PROP_TOP_BORDER,
204 : PROP_RIGHT_BORDER,
205 : PROP_LEFT_BORDER,
206 : };
207 :
208 : bool pRemoveInside[] =
209 : {
210 1659 : ( nStyleId == TBL_STYLE_FIRSTROW ),
211 1659 : ( nStyleId == TBL_STYLE_LASTROW ),
212 1659 : ( nStyleId == TBL_STYLE_LASTCOL ),
213 1659 : ( nStyleId == TBL_STYLE_FIRSTCOL )
214 6636 : };
215 :
216 8295 : for ( unsigned i = 0 ; i != sizeof(pPropsToCheck) / sizeof(PropertyIds); i++ )
217 : {
218 6636 : PropertyIds nId = pPropsToCheck[i];
219 6636 : boost::optional<PropertyMap::Property> pProp = pToAdd->getProperty(nId);
220 :
221 6636 : if ( pProp )
222 : {
223 1381 : if ( pRemoveInside[i] )
224 : {
225 : // Remove the insideH and insideV depending on the cell pos
226 189 : PropertyIds nInsideProp = ( i < 2 ) ? META_PROP_HORIZONTAL_BORDER : META_PROP_VERTICAL_BORDER;
227 189 : pToFill->Erase(nInsideProp);
228 : }
229 : }
230 6636 : }
231 :
232 1659 : pToFill->InsertProps(pToAdd);
233 1659 : }
234 :
235 4132 : PropertyMapPtr TableStyleSheetEntry::GetLocalPropertiesFromMask( sal_Int32 nMask )
236 : {
237 : // Order from right to left
238 : struct TblStyleTypeAndMask {
239 : sal_Int32 mask;
240 : TblStyleType type;
241 : };
242 :
243 : static const TblStyleTypeAndMask aOrderedStyleTable[] =
244 : {
245 : { 0x010, TBL_STYLE_BAND2HORZ },
246 : { 0x020, TBL_STYLE_BAND1HORZ },
247 : { 0x040, TBL_STYLE_BAND2VERT },
248 : { 0x080, TBL_STYLE_BAND1VERT },
249 : { 0x100, TBL_STYLE_LASTCOL },
250 : { 0x200, TBL_STYLE_FIRSTCOL },
251 : { 0x400, TBL_STYLE_LASTROW },
252 : { 0x800, TBL_STYLE_FIRSTROW },
253 : { 0x001, TBL_STYLE_SWCELL },
254 : { 0x002, TBL_STYLE_SECELL },
255 : { 0x004, TBL_STYLE_NWCELL },
256 : { 0x008, TBL_STYLE_NECELL }
257 : };
258 :
259 : // Get the properties applying according to the mask
260 4132 : PropertyMapPtr pProps( new PropertyMap( ) );
261 53716 : for (size_t i = 0; i < sizeof(aOrderedStyleTable)/sizeof(aOrderedStyleTable[0]); ++i)
262 : {
263 49584 : TblStylePrs::iterator pIt = m_aStyles.find( aOrderedStyleTable[ i ].type );
264 49584 : if ( ( nMask & aOrderedStyleTable[ i ].mask ) && ( pIt != m_aStyles.end( ) ) )
265 1659 : lcl_mergeProps( pProps, pIt->second, aOrderedStyleTable[ i ].type );
266 : }
267 4132 : return pProps;
268 : }
269 :
270 :
271 :
272 3410 : struct ListCharStylePropertyMap_t
273 : {
274 : OUString sCharStyleName;
275 : PropertyValueVector_t aPropertyValues;
276 :
277 734 : ListCharStylePropertyMap_t(const OUString& rCharStyleName, const PropertyValueVector_t& rPropertyValues):
278 : sCharStyleName( rCharStyleName ),
279 734 : aPropertyValues( rPropertyValues )
280 734 : {}
281 : };
282 : typedef std::vector< ListCharStylePropertyMap_t > ListCharStylePropertyVector_t;
283 :
284 :
285 1971 : struct StyleSheetTable_Impl
286 : {
287 : DomainMapper& m_rDMapper;
288 : uno::Reference< text::XTextDocument> m_xTextDocument;
289 : uno::Reference< beans::XPropertySet> m_xTextDefaults;
290 : std::vector< StyleSheetEntryPtr > m_aStyleSheetEntries;
291 : StyleSheetEntryPtr m_pCurrentEntry;
292 : PropertyMapPtr m_pDefaultParaProps, m_pDefaultCharProps;
293 : PropertyMapPtr m_pCurrentProps;
294 : StringPairMap_t m_aStyleNameMap;
295 : /// Style names which should not be used without a " (user)" suffix.
296 : std::set<OUString> m_aReservedStyleNames;
297 : ListCharStylePropertyVector_t m_aListCharStylePropertyVector;
298 : bool m_bIsNewDoc;
299 :
300 : StyleSheetTable_Impl(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> const& xTextDocument, bool bIsNewDoc);
301 :
302 : OUString HasListCharStyle( const PropertyValueVector_t& rCharProperties );
303 :
304 : /// Appends the given key-value pair to the list of latent style properties of the current entry.
305 : void AppendLatentStyleProperty(const OUString& aName, Value& rValue);
306 : };
307 :
308 :
309 1971 : StyleSheetTable_Impl::StyleSheetTable_Impl(DomainMapper& rDMapper,
310 : uno::Reference< text::XTextDocument> const& xTextDocument,
311 : bool const bIsNewDoc)
312 : :
313 : m_rDMapper( rDMapper ),
314 : m_xTextDocument( xTextDocument ),
315 : m_pCurrentEntry(),
316 1971 : m_pDefaultParaProps(new PropertyMap),
317 1971 : m_pDefaultCharProps(new PropertyMap),
318 5913 : m_bIsNewDoc(bIsNewDoc)
319 : {
320 : //set font height default to 10pt
321 1971 : uno::Any aVal = uno::makeAny( double(10.) );
322 1971 : m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT, aVal );
323 1971 : m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT_ASIAN, aVal );
324 1971 : m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT_COMPLEX, aVal );
325 1971 : }
326 :
327 :
328 10391 : OUString StyleSheetTable_Impl::HasListCharStyle( const PropertyValueVector_t& rPropValues )
329 : {
330 10391 : OUString sRet;
331 10391 : ListCharStylePropertyVector_t::const_iterator aListVectorIter = m_aListCharStylePropertyVector.begin();
332 31417 : while( aListVectorIter != m_aListCharStylePropertyVector.end() )
333 : {
334 : //if size is identical
335 20292 : if( aListVectorIter->aPropertyValues.size() == rPropValues.size() )
336 : {
337 12153 : bool bBreak = false;
338 : //then search for all contained properties
339 12153 : PropertyValueVector_t::const_iterator aList1Iter = rPropValues.begin();
340 41199 : while( aList1Iter != rPropValues.end() && !bBreak)
341 : {
342 : //find the property
343 17620 : bool bElementFound = false;
344 17620 : PropertyValueVector_t::const_iterator aList2Iter = aListVectorIter->aPropertyValues.begin();
345 47104 : while( aList2Iter != aListVectorIter->aPropertyValues.end() && !bBreak )
346 : {
347 28757 : if( aList2Iter->Name == aList1Iter->Name )
348 : {
349 16893 : bElementFound = true;
350 16893 : if( aList2Iter->Value != aList1Iter->Value )
351 1769 : bBreak = true;
352 16893 : break;
353 : }
354 11864 : ++aList2Iter;
355 : }
356 : //set break flag if property hasn't been found
357 17620 : if(!bElementFound )
358 : {
359 727 : bBreak = true;
360 727 : break;
361 : }
362 16893 : ++aList1Iter;
363 : }
364 12153 : if( !bBreak )
365 9657 : return aListVectorIter->sCharStyleName;
366 : }
367 10635 : ++aListVectorIter;
368 : }
369 734 : return sRet;
370 : }
371 :
372 8190 : void StyleSheetTable_Impl::AppendLatentStyleProperty(const OUString& aName, Value& rValue)
373 : {
374 8190 : beans::PropertyValue aValue;
375 8190 : aValue.Name = aName;
376 8190 : aValue.Value <<= rValue.getString();
377 8190 : m_pCurrentEntry->aLatentStyles.push_back(aValue);
378 8190 : }
379 :
380 :
381 1971 : StyleSheetTable::StyleSheetTable(DomainMapper& rDMapper,
382 : uno::Reference< text::XTextDocument> const& xTextDocument,
383 : bool const bIsNewDoc)
384 : : LoggedProperties("StyleSheetTable")
385 : , LoggedTable("StyleSheetTable")
386 1971 : , m_pImpl( new StyleSheetTable_Impl(rDMapper, xTextDocument, bIsNewDoc) )
387 : {
388 1971 : }
389 :
390 :
391 5913 : StyleSheetTable::~StyleSheetTable()
392 : {
393 1971 : delete m_pImpl;
394 3942 : }
395 :
396 43 : PropertyMapPtr StyleSheetTable::GetDefaultCharProps()
397 : {
398 43 : return m_pImpl->m_pDefaultCharProps;
399 : }
400 :
401 130573 : void StyleSheetTable::lcl_attribute(Id Name, Value & val)
402 : {
403 : OSL_ENSURE( m_pImpl->m_pCurrentEntry, "current entry has to be set here");
404 130573 : if(!m_pImpl->m_pCurrentEntry)
405 130573 : return ;
406 130573 : int nIntValue = val.getInt();
407 130573 : OUString sValue = val.getString();
408 :
409 : // The default type is paragraph, and it needs to be processed first,
410 : // because the NS_ooxml::LN_CT_Style_type handling may set m_pImpl->m_pCurrentEntry
411 : // to point to a different object.
412 130573 : if( m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_UNKNOWN )
413 : {
414 47924 : if( Name != NS_ooxml::LN_CT_Style_type )
415 1400 : m_pImpl->m_pCurrentEntry->nStyleTypeCode = STYLE_TYPE_PARA;
416 : }
417 130573 : switch(Name)
418 : {
419 : case NS_ooxml::LN_CT_Style_type:
420 : {
421 : SAL_WARN_IF( m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN,
422 : "writerfilter", "Style type needs to be processed first" );
423 46524 : StyleType nType(STYLE_TYPE_UNKNOWN);
424 46524 : switch (nIntValue)
425 : {
426 : case NS_ooxml::LN_Value_ST_StyleType_paragraph:
427 19258 : nType = STYLE_TYPE_PARA;
428 19258 : break;
429 : case NS_ooxml::LN_Value_ST_StyleType_character:
430 10958 : nType = STYLE_TYPE_CHAR;
431 10958 : break;
432 : case NS_ooxml::LN_Value_ST_StyleType_table:
433 2494 : nType = STYLE_TYPE_TABLE;
434 2494 : break;
435 : case NS_ooxml::LN_Value_ST_StyleType_numbering:
436 13779 : nType = STYLE_TYPE_LIST;
437 13779 : break;
438 : default:
439 : SAL_WARN("writerfilter", "unknown LN_CT_Style_type " << nType);
440 : //fall-through
441 : case 0: // explicit unknown set by tokenizer
442 35 : break;
443 :
444 : }
445 46524 : if ( nType == STYLE_TYPE_TABLE )
446 : {
447 2494 : StyleSheetEntryPtr pEntry = m_pImpl->m_pCurrentEntry;
448 4988 : TableStyleSheetEntryPtr pTableEntry( new TableStyleSheetEntry( *pEntry.get( ), this ) );
449 4988 : m_pImpl->m_pCurrentEntry = pTableEntry;
450 : }
451 : else
452 44030 : m_pImpl->m_pCurrentEntry->nStyleTypeCode = nType;
453 : }
454 46524 : break;
455 : case NS_ooxml::LN_CT_Style_default:
456 5472 : m_pImpl->m_pCurrentEntry->bIsDefaultStyle = (nIntValue != 0);
457 5472 : if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN)
458 : {
459 5472 : beans::PropertyValue aValue;
460 5472 : aValue.Name = "default";
461 5472 : aValue.Value = uno::makeAny(m_pImpl->m_pCurrentEntry->bIsDefaultStyle);
462 5472 : m_pImpl->m_pCurrentEntry->AppendInteropGrabBag(aValue);
463 : }
464 5472 : break;
465 : case NS_ooxml::LN_CT_Style_customStyle:
466 23863 : if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN)
467 : {
468 23863 : beans::PropertyValue aValue;
469 23863 : aValue.Name = "customStyle";
470 23863 : aValue.Value = uno::makeAny(nIntValue != 0);
471 23863 : m_pImpl->m_pCurrentEntry->AppendInteropGrabBag(aValue);
472 : }
473 23863 : break;
474 : case NS_ooxml::LN_CT_Style_styleId:
475 46524 : m_pImpl->m_pCurrentEntry->sStyleIdentifierI = sValue;
476 46524 : m_pImpl->m_pCurrentEntry->sStyleIdentifierD = sValue;
477 46524 : if(m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
478 : {
479 2494 : TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(m_pImpl->m_pCurrentEntry.get());
480 2494 : beans::PropertyValue aValue;
481 2494 : aValue.Name = "styleId";
482 2494 : aValue.Value = uno::makeAny(sValue);
483 2494 : pTableEntry->AppendInteropGrabBag(aValue);
484 : }
485 46524 : break;
486 : case NS_ooxml::LN_CT_TblWidth_w:
487 0 : if (StyleSheetPropertyMap* pMap = dynamic_cast< StyleSheetPropertyMap* >( m_pImpl->m_pCurrentEntry->pProperties.get() ))
488 0 : pMap->SetCT_TblWidth_w( nIntValue );
489 0 : break;
490 : case NS_ooxml::LN_CT_TblWidth_type:
491 0 : if (StyleSheetPropertyMap* pMap = dynamic_cast< StyleSheetPropertyMap* >( m_pImpl->m_pCurrentEntry->pProperties.get() ))
492 0 : pMap->SetCT_TblWidth_type( nIntValue );
493 0 : break;
494 : case NS_ooxml::LN_CT_LatentStyles_defQFormat:
495 1365 : m_pImpl->AppendLatentStyleProperty("defQFormat", val);
496 1365 : break;
497 : case NS_ooxml::LN_CT_LatentStyles_defUnhideWhenUsed:
498 1365 : m_pImpl->AppendLatentStyleProperty("defUnhideWhenUsed", val);
499 1365 : break;
500 : case NS_ooxml::LN_CT_LatentStyles_defSemiHidden:
501 1365 : m_pImpl->AppendLatentStyleProperty("defSemiHidden", val);
502 1365 : break;
503 : case NS_ooxml::LN_CT_LatentStyles_count:
504 1365 : m_pImpl->AppendLatentStyleProperty("count", val);
505 1365 : break;
506 : case NS_ooxml::LN_CT_LatentStyles_defUIPriority:
507 1365 : m_pImpl->AppendLatentStyleProperty("defUIPriority", val);
508 1365 : break;
509 : case NS_ooxml::LN_CT_LatentStyles_defLockedState:
510 1365 : m_pImpl->AppendLatentStyleProperty("defLockedState", val);
511 1365 : break;
512 : default:
513 : {
514 : #ifdef DEBUG_WRITERFILTER
515 : TagLogger::getInstance().element("unhandled");
516 : #endif
517 : }
518 0 : break;
519 130573 : }
520 : }
521 :
522 :
523 490894 : void StyleSheetTable::lcl_sprm(Sprm & rSprm)
524 : {
525 490894 : sal_uInt32 nSprmId = rSprm.getId();
526 490894 : Value::Pointer_t pValue = rSprm.getValue();
527 490894 : sal_Int32 nIntValue = pValue.get() ? pValue->getInt() : 0;
528 981788 : OUString sStringValue = pValue.get() ? pValue->getString() : OUString();
529 :
530 490894 : switch(nSprmId)
531 : {
532 : case NS_ooxml::LN_CT_Style_name:
533 : //this is only a UI name!
534 46524 : m_pImpl->m_pCurrentEntry->sStyleName = sStringValue;
535 46524 : m_pImpl->m_pCurrentEntry->sStyleName1 = sStringValue;
536 46524 : if(m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
537 : {
538 2494 : TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(m_pImpl->m_pCurrentEntry.get());
539 2494 : beans::PropertyValue aValue;
540 2494 : aValue.Name = "name";
541 2494 : aValue.Value = uno::makeAny(sStringValue);
542 2494 : pTableEntry->AppendInteropGrabBag(aValue);
543 : }
544 46524 : break;
545 : case NS_ooxml::LN_CT_Style_basedOn:
546 23932 : m_pImpl->m_pCurrentEntry->sBaseStyleIdentifier = sStringValue;
547 23932 : if(m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
548 : {
549 1123 : TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(m_pImpl->m_pCurrentEntry.get());
550 1123 : beans::PropertyValue aValue;
551 1123 : aValue.Name = "basedOn";
552 1123 : aValue.Value = uno::makeAny(sStringValue);
553 1123 : pTableEntry->AppendInteropGrabBag(aValue);
554 : }
555 23932 : break;
556 : case NS_ooxml::LN_CT_Style_next:
557 14371 : m_pImpl->m_pCurrentEntry->sNextStyleIdentifier = sStringValue;
558 14371 : break;
559 : case NS_ooxml::LN_CT_Style_aliases:
560 : case NS_ooxml::LN_CT_Style_hidden:
561 : case NS_ooxml::LN_CT_Style_personal:
562 : case NS_ooxml::LN_CT_Style_personalCompose:
563 : case NS_ooxml::LN_CT_Style_personalReply:
564 1316 : break;
565 : case NS_ooxml::LN_CT_Style_autoRedefine:
566 1273 : m_pImpl->m_pCurrentEntry->bAutoRedefine = nIntValue;
567 1273 : break;
568 : case NS_ooxml::LN_CT_Style_tcPr:
569 : {
570 404 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
571 404 : if( pProperties.get() && m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
572 : {
573 404 : TblStylePrHandlerPtr pTblStylePrHandler(new TblStylePrHandler(m_pImpl->m_rDMapper));
574 404 : pProperties->resolve(*pTblStylePrHandler);
575 404 : StyleSheetEntry* pEntry = m_pImpl->m_pCurrentEntry.get();
576 404 : TableStyleSheetEntry& rTableEntry = dynamic_cast<TableStyleSheetEntry&>(*pEntry);
577 404 : rTableEntry.AppendInteropGrabBag(pTblStylePrHandler->getInteropGrabBag("tcPr"));
578 :
579 : // This is a <w:tcPr> directly under <w:style>, so it affects the whole table.
580 404 : rTableEntry.pProperties->InsertProps(pTblStylePrHandler->getProperties());
581 404 : }
582 : }
583 404 : break;
584 : case NS_ooxml::LN_CT_Style_trPr:
585 28 : break;
586 : case NS_ooxml::LN_CT_Style_rsid:
587 : case NS_ooxml::LN_CT_Style_qFormat:
588 : case NS_ooxml::LN_CT_Style_semiHidden:
589 : case NS_ooxml::LN_CT_Style_unhideWhenUsed:
590 : case NS_ooxml::LN_CT_Style_uiPriority:
591 : case NS_ooxml::LN_CT_Style_link:
592 : case NS_ooxml::LN_CT_Style_locked:
593 119291 : if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN)
594 : {
595 119291 : StyleSheetEntryPtr pEntry = m_pImpl->m_pCurrentEntry;
596 238582 : beans::PropertyValue aValue;
597 119291 : switch (nSprmId)
598 : {
599 : case NS_ooxml::LN_CT_Style_rsid:
600 : {
601 : // We want the rsid as a hex string, but always with the length of 8.
602 32320 : OUStringBuffer aBuf = OUString::number(nIntValue, 16);
603 64640 : OUStringBuffer aStr;
604 32320 : comphelper::string::padToLength(aStr, 8 - aBuf.getLength(), '0');
605 32320 : aStr.append(aBuf.getStr());
606 :
607 32320 : aValue.Name = "rsid";
608 64640 : aValue.Value = uno::makeAny(aStr.makeStringAndClear());
609 : }
610 32320 : break;
611 : case NS_ooxml::LN_CT_Style_qFormat:
612 12711 : aValue.Name = "qFormat";
613 12711 : break;
614 : case NS_ooxml::LN_CT_Style_semiHidden:
615 19733 : aValue.Name = "semiHidden";
616 19733 : break;
617 : case NS_ooxml::LN_CT_Style_unhideWhenUsed:
618 19525 : aValue.Name = "unhideWhenUsed";
619 19525 : break;
620 : case NS_ooxml::LN_CT_Style_uiPriority:
621 : {
622 25411 : aValue.Name = "uiPriority";
623 25411 : aValue.Value = uno::makeAny(OUString::number(nIntValue));
624 : }
625 25411 : break;
626 : case NS_ooxml::LN_CT_Style_link:
627 : {
628 8521 : aValue.Name = "link";
629 8521 : aValue.Value = uno::makeAny(sStringValue);
630 : }
631 8521 : break;
632 : case NS_ooxml::LN_CT_Style_locked:
633 1070 : aValue.Name = "locked";
634 1070 : break;
635 : }
636 238582 : pEntry->AppendInteropGrabBag(aValue);
637 : }
638 119291 : break;
639 : case NS_ooxml::LN_CT_Style_tblPr: //contains table properties
640 : case NS_ooxml::LN_CT_Style_tblStylePr: //contains to table properties
641 : case NS_ooxml::LN_CT_TblPrBase_tblInd: //table properties - at least width value and type
642 : case NS_ooxml::LN_EG_RPrBase_rFonts: //table fonts
643 : {
644 5087 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
645 5087 : if( pProperties.get())
646 : {
647 5087 : TblStylePrHandlerPtr pTblStylePrHandler( new TblStylePrHandler( m_pImpl->m_rDMapper ) );
648 5087 : pProperties->resolve( *pTblStylePrHandler );
649 :
650 : // Add the properties to the table style
651 5087 : TblStyleType nType = pTblStylePrHandler->getType( );
652 10174 : PropertyMapPtr pProps = pTblStylePrHandler->getProperties( );
653 5087 : StyleSheetEntry * pEntry = m_pImpl->m_pCurrentEntry.get();
654 :
655 5087 : TableStyleSheetEntry * pTableEntry = dynamic_cast<TableStyleSheetEntry*>( pEntry );
656 5087 : if (nType == TBL_STYLE_UNKNOWN)
657 : {
658 2494 : pEntry->pProperties->InsertProps(pProps);
659 : }
660 : else
661 : {
662 2593 : if (pTableEntry != nullptr)
663 2593 : pTableEntry->AddTblStylePr( nType, pProps );
664 : }
665 :
666 5087 : if (nSprmId == NS_ooxml::LN_CT_Style_tblPr)
667 : {
668 2494 : if (pTableEntry != nullptr)
669 2494 : pTableEntry->AppendInteropGrabBag(pTblStylePrHandler->getInteropGrabBag("tblPr"));
670 : }
671 2593 : else if (nSprmId == NS_ooxml::LN_CT_Style_tblStylePr)
672 : {
673 2593 : pTblStylePrHandler->appendInteropGrabBag("type", pTblStylePrHandler->getTypeString());
674 2593 : if (pTableEntry != nullptr)
675 2593 : pTableEntry->AppendInteropGrabBag(pTblStylePrHandler->getInteropGrabBag("tblStylePr"));
676 5087 : }
677 : }
678 5087 : break;
679 : }
680 : case NS_ooxml::LN_CT_PPrDefault_pPr:
681 : case NS_ooxml::LN_CT_DocDefaults_pPrDefault:
682 1476 : m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pDefaultParaProps );
683 1476 : resolveSprmProps( m_pImpl->m_rDMapper, rSprm );
684 1476 : m_pImpl->m_rDMapper.PopStyleSheetProperties();
685 1476 : applyDefaults( true );
686 1476 : break;
687 : case NS_ooxml::LN_CT_RPrDefault_rPr:
688 : case NS_ooxml::LN_CT_DocDefaults_rPrDefault:
689 1476 : m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pDefaultCharProps );
690 1476 : resolveSprmProps( m_pImpl->m_rDMapper, rSprm );
691 1476 : m_pImpl->m_rDMapper.PopStyleSheetProperties();
692 1476 : applyDefaults( false );
693 1476 : break;
694 : case NS_ooxml::LN_CT_TblPrBase_jc: //table alignment - row properties!
695 0 : m_pImpl->m_pCurrentEntry->pProperties->Insert( PROP_HORI_ORIENT,
696 0 : uno::makeAny( ConversionHelper::convertTableJustification( nIntValue )));
697 0 : break;
698 : case NS_ooxml::LN_CT_TrPrBase_jc: //table alignment - row properties!
699 0 : if (StyleSheetPropertyMap* pMap = dynamic_cast< StyleSheetPropertyMap* >( m_pImpl->m_pCurrentEntry->pProperties.get() ))
700 0 : pMap->SetCT_TrPrBase_jc(nIntValue);
701 0 : break;
702 : case NS_ooxml::LN_CT_TblPrBase_tblBorders: //table borders, might be defined in table style
703 : {
704 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
705 0 : if( pProperties.get())
706 : {
707 0 : BorderHandlerPtr pBorderHandler( new BorderHandler(m_pImpl->m_rDMapper.IsOOXMLImport()) );
708 0 : pProperties->resolve(*pBorderHandler);
709 0 : m_pImpl->m_pCurrentEntry->pProperties->InsertProps(
710 0 : pBorderHandler->getProperties());
711 0 : }
712 : }
713 0 : break;
714 : case NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize:
715 : case NS_ooxml::LN_CT_TblPrBase_tblStyleColBandSize:
716 : {
717 0 : StyleSheetEntry* pEntry = m_pImpl->m_pCurrentEntry.get( );
718 0 : TableStyleSheetEntry *pTEntry = static_cast<TableStyleSheetEntry*>( pEntry );
719 0 : if ( pTEntry )
720 : {
721 0 : if ( nSprmId == NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize )
722 0 : pTEntry->m_nRowBandSize = nIntValue;
723 : else
724 0 : pTEntry->m_nColBandSize = nIntValue;
725 : }
726 : }
727 0 : break;
728 : case NS_ooxml::LN_CT_TblPrBase_tblCellMar:
729 : //no cell margins in styles
730 0 : break;
731 : case NS_ooxml::LN_CT_LatentStyles_lsdException:
732 : {
733 232239 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
734 232239 : if (pProperties.get())
735 : {
736 232239 : LatentStyleHandlerPtr pLatentStyleHandler(new LatentStyleHandler());
737 232239 : pProperties->resolve(*pLatentStyleHandler);
738 464478 : beans::PropertyValue aValue;
739 232239 : aValue.Name = "lsdException";
740 232239 : aValue.Value = uno::makeAny(pLatentStyleHandler->getAttributes());
741 464478 : m_pImpl->m_pCurrentEntry->aLsdExceptions.push_back(aValue);
742 232239 : }
743 : }
744 232239 : break;
745 : case NS_ooxml::LN_CT_Style_pPr:
746 : // no break
747 : case NS_ooxml::LN_CT_Style_rPr:
748 : // no break
749 : default:
750 : {
751 43477 : if (!m_pImpl->m_pCurrentEntry)
752 0 : break;
753 :
754 43477 : TablePropertiesHandlerPtr pTblHandler(new TablePropertiesHandler());
755 43477 : pTblHandler->SetProperties( m_pImpl->m_pCurrentEntry->pProperties );
756 43477 : if ( !pTblHandler->sprm( rSprm ) )
757 : {
758 43477 : m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pCurrentEntry->pProperties );
759 :
760 43477 : PropertyMapPtr pProps(new PropertyMap());
761 43477 : bool bTableStyleRunProps = m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE && nSprmId == NS_ooxml::LN_CT_Style_rPr;
762 43477 : if (bTableStyleRunProps)
763 321 : m_pImpl->m_rDMapper.setInTableStyleRunProps(true);
764 43477 : if (m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
765 : {
766 1122 : if (nSprmId == NS_ooxml::LN_CT_Style_pPr)
767 801 : m_pImpl->m_rDMapper.enableInteropGrabBag("pPr");
768 321 : else if (nSprmId == NS_ooxml::LN_CT_Style_rPr)
769 321 : m_pImpl->m_rDMapper.enableInteropGrabBag("rPr");
770 : }
771 43477 : m_pImpl->m_rDMapper.sprmWithProps( rSprm, pProps );
772 43477 : if (m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
773 : {
774 1122 : if (nSprmId == NS_ooxml::LN_CT_Style_pPr || nSprmId == NS_ooxml::LN_CT_Style_rPr)
775 : {
776 1122 : TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(m_pImpl->m_pCurrentEntry.get());
777 1122 : pTableEntry->AppendInteropGrabBag(m_pImpl->m_rDMapper.getInteropGrabBag());
778 : }
779 : }
780 43477 : if (bTableStyleRunProps)
781 321 : m_pImpl->m_rDMapper.setInTableStyleRunProps(false);
782 :
783 43477 : m_pImpl->m_pCurrentEntry->pProperties->InsertProps(pProps);
784 :
785 43477 : m_pImpl->m_rDMapper.PopStyleSheetProperties( );
786 :
787 43477 : if (m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_PARA && m_pImpl->m_pCurrentEntry->bIsDefaultStyle)
788 : {
789 : // The current style is the default paragraph style.
790 1267 : PropertyMapPtr pProperties = m_pImpl->m_pCurrentEntry->pProperties;
791 1267 : if (pProperties->isSet(PROP_CHAR_HEIGHT) && !m_pImpl->m_pDefaultParaProps->isSet(PROP_CHAR_HEIGHT))
792 : {
793 : // We provide a character height value, but a document-level default wasn't set.
794 597 : if (m_pImpl->m_xTextDefaults.is())
795 : {
796 597 : m_pImpl->m_xTextDefaults->setPropertyValue("CharHeight", pProperties->getProperty(PROP_CHAR_HEIGHT)->second);
797 : }
798 1267 : }
799 43477 : }
800 43477 : }
801 : }
802 43477 : break;
803 490894 : }
804 490894 : }
805 :
806 :
807 49365 : void StyleSheetTable::lcl_entry(int /*pos*/, writerfilter::Reference<Properties>::Pointer_t ref)
808 : {
809 : //create a new style entry
810 : OSL_ENSURE( !m_pImpl->m_pCurrentEntry, "current entry has to be NULL here");
811 49365 : StyleSheetEntryPtr pNewEntry( new StyleSheetEntry );
812 49365 : m_pImpl->m_pCurrentEntry = pNewEntry;
813 49365 : m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pCurrentEntry->pProperties );
814 49365 : ref->resolve(*this);
815 : //append it to the table
816 49365 : m_pImpl->m_rDMapper.PopStyleSheetProperties();
817 49365 : if( !m_pImpl->m_rDMapper.IsOOXMLImport() || !m_pImpl->m_pCurrentEntry->sStyleName.isEmpty())
818 : {
819 46524 : m_pImpl->m_pCurrentEntry->sConvertedStyleName = ConvertStyleName( m_pImpl->m_pCurrentEntry->sStyleName );
820 46524 : m_pImpl->m_aStyleSheetEntries.push_back( m_pImpl->m_pCurrentEntry );
821 : }
822 : else
823 : {
824 : //TODO: this entry contains the default settings - they have to be added to the settings
825 : }
826 :
827 49365 : if (!m_pImpl->m_pCurrentEntry->aLatentStyles.empty())
828 : {
829 : // We have latent styles for this entry, then process them.
830 1365 : std::vector<beans::PropertyValue>& rLatentStyles = m_pImpl->m_pCurrentEntry->aLatentStyles;
831 :
832 1365 : if (!m_pImpl->m_pCurrentEntry->aLsdExceptions.empty())
833 : {
834 1364 : std::vector<beans::PropertyValue>& rLsdExceptions = m_pImpl->m_pCurrentEntry->aLsdExceptions;
835 1364 : uno::Sequence<beans::PropertyValue> aLsdExceptions(rLsdExceptions.size());
836 1364 : beans::PropertyValue* pLsdExceptions = aLsdExceptions.getArray();
837 233603 : for (std::vector<beans::PropertyValue>::iterator i = rLsdExceptions.begin(); i != rLsdExceptions.end(); ++i)
838 232239 : *pLsdExceptions++ = *i;
839 :
840 2728 : beans::PropertyValue aValue;
841 1364 : aValue.Name = "lsdExceptions";
842 1364 : aValue.Value = uno::makeAny(aLsdExceptions);
843 2728 : rLatentStyles.push_back(aValue);
844 : }
845 :
846 1365 : uno::Sequence<beans::PropertyValue> aLatentStyles(rLatentStyles.size());
847 1365 : beans::PropertyValue* pLatentStyles = aLatentStyles.getArray();
848 10919 : for (std::vector<beans::PropertyValue>::iterator i = rLatentStyles.begin(); i != rLatentStyles.end(); ++i)
849 9554 : *pLatentStyles++ = *i;
850 :
851 : // We can put all latent style info directly to the document interop
852 : // grab bag, as we can be sure that only a single style entry has
853 : // latent style info.
854 2730 : uno::Reference<beans::XPropertySet> xPropertySet(m_pImpl->m_xTextDocument, uno::UNO_QUERY);
855 2730 : auto aGrabBag = comphelper::sequenceToContainer< std::vector<beans::PropertyValue> >(xPropertySet->getPropertyValue("InteropGrabBag").get< uno::Sequence<beans::PropertyValue> >());
856 2730 : beans::PropertyValue aValue;
857 1365 : aValue.Name = "latentStyles";
858 1365 : aValue.Value = uno::makeAny(aLatentStyles);
859 1365 : aGrabBag.push_back(aValue);
860 2730 : xPropertySet->setPropertyValue("InteropGrabBag", uno::makeAny(comphelper::containerToSequence(aGrabBag)));
861 : }
862 :
863 98730 : StyleSheetEntryPtr pEmptyEntry;
864 98730 : m_pImpl->m_pCurrentEntry = pEmptyEntry;
865 49365 : }
866 : /*-------------------------------------------------------------------------
867 : sorting helper
868 : -----------------------------------------------------------------------*/
869 : typedef std::vector< beans::PropertyValue > _PropValVector;
870 27280 : class PropValVector : public _PropValVector
871 : {
872 : public:
873 27280 : PropValVector(){}
874 :
875 : void Insert(const beans::PropertyValue& rVal);
876 : uno::Sequence< uno::Any > getValues();
877 : uno::Sequence< OUString > getNames();
878 : };
879 :
880 199063 : void PropValVector::Insert(const beans::PropertyValue& rVal)
881 : {
882 199063 : _PropValVector::iterator aIt = begin();
883 1266867 : while(aIt != end())
884 : {
885 902871 : if(aIt->Name > rVal.Name)
886 : {
887 34130 : insert( aIt, rVal );
888 233193 : return;
889 : }
890 868741 : ++aIt;
891 : }
892 164933 : push_back(rVal);
893 : }
894 27280 : uno::Sequence< uno::Any > PropValVector::getValues()
895 : {
896 27280 : uno::Sequence< uno::Any > aRet( size() );
897 27280 : uno::Any* pValues = aRet.getArray();
898 27280 : sal_Int32 nVal = 0;
899 27280 : _PropValVector::iterator aIt = begin();
900 253623 : while(aIt != end())
901 : {
902 199063 : pValues[nVal++] = aIt->Value;
903 199063 : ++aIt;
904 : }
905 27280 : return aRet;
906 : }
907 27280 : uno::Sequence< OUString > PropValVector::getNames()
908 : {
909 27280 : uno::Sequence< OUString > aRet( size() );
910 27280 : OUString* pNames = aRet.getArray();
911 27280 : sal_Int32 nVal = 0;
912 27280 : _PropValVector::iterator aIt = begin();
913 253623 : while(aIt != end())
914 : {
915 199063 : pNames[nVal++] = aIt->Name;
916 199063 : ++aIt;
917 : }
918 27280 : return aRet;
919 : }
920 :
921 :
922 1695 : void StyleSheetTable::ApplyStyleSheets( FontTablePtr rFontTable )
923 : {
924 : try
925 : {
926 1695 : uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
927 3366 : uno::Reference< lang::XMultiServiceFactory > xDocFactory( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
928 3366 : uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
929 3366 : uno::Reference<container::XNameContainer> xCharStyles;
930 3366 : uno::Reference<container::XNameContainer> xParaStyles;
931 3366 : uno::Reference<container::XNameContainer> xNumberingStyles;
932 :
933 1683 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
934 1683 : xStyleFamilies->getByName(rPropNameSupplier.GetName( PROP_CHARACTER_STYLES )) >>= xCharStyles;
935 1683 : xStyleFamilies->getByName(rPropNameSupplier.GetName( PROP_PARAGRAPH_STYLES )) >>= xParaStyles;
936 1683 : xStyleFamilies->getByName("NumberingStyles") >>= xNumberingStyles;
937 1683 : if(xCharStyles.is() && xParaStyles.is())
938 : {
939 1683 : std::vector<beans::PropertyValue> aTableStylesVec;
940 1683 : std::vector< StyleSheetEntryPtr >::iterator aIt = m_pImpl->m_aStyleSheetEntries.begin();
941 49726 : while( aIt != m_pImpl->m_aStyleSheetEntries.end() )
942 : {
943 46360 : StyleSheetEntryPtr pEntry = *aIt;
944 46360 : if( pEntry->nStyleTypeCode == STYLE_TYPE_CHAR || pEntry->nStyleTypeCode == STYLE_TYPE_PARA || pEntry->nStyleTypeCode == STYLE_TYPE_LIST )
945 : {
946 43866 : bool bParaStyle = pEntry->nStyleTypeCode == STYLE_TYPE_PARA;
947 43866 : bool bListStyle = pEntry->nStyleTypeCode == STYLE_TYPE_LIST;
948 43866 : bool bInsert = false;
949 43866 : uno::Reference< container::XNameContainer > xStyles = bParaStyle ? xParaStyles : (bListStyle ? xNumberingStyles : xCharStyles);
950 87724 : uno::Reference< style::XStyle > xStyle;
951 87724 : OUString sConvertedStyleName = ConvertStyleName( pEntry->sStyleName );
952 :
953 43866 : if(xStyles->hasByName( sConvertedStyleName ))
954 : {
955 : // When pasting, don't update existing styles.
956 10754 : if (!m_pImpl->m_bIsNewDoc)
957 : {
958 8 : ++aIt;
959 8 : continue;
960 : }
961 10746 : xStyles->getByName( sConvertedStyleName ) >>= xStyle;
962 :
963 : // See if the existing style has any non-default properties. If so, reset them back to default.
964 10746 : uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY);
965 21492 : uno::Reference<beans::XPropertySetInfo> xPropertySetInfo = xPropertySet->getPropertySetInfo();
966 21492 : uno::Sequence<beans::Property> aProperties = xPropertySetInfo->getProperties();
967 21492 : std::vector<OUString> aPropertyNames;
968 1766974 : for (sal_Int32 i = 0; i < aProperties.getLength(); ++i)
969 : {
970 1756228 : aPropertyNames.push_back(aProperties[i].Name);
971 : }
972 :
973 21492 : uno::Reference<beans::XPropertyState> xPropertyState(xStyle, uno::UNO_QUERY);
974 21492 : uno::Sequence<beans::PropertyState> aStates = xPropertyState->getPropertyStates(comphelper::containerToSequence(aPropertyNames));
975 1766974 : for (sal_Int32 i = 0; i < aStates.getLength(); ++i)
976 : {
977 1756228 : if (aStates[i] == beans::PropertyState_DIRECT_VALUE)
978 : {
979 : try
980 : {
981 68230 : xPropertyState->setPropertyToDefault(aPropertyNames[i]);
982 : }
983 10073 : catch(const uno::Exception& rException)
984 : {
985 : SAL_INFO("writerfilter", "setPropertyToDefault(" << aPropertyNames[i] << ") failed: " << rException.Message);
986 : }
987 : }
988 10746 : }
989 : }
990 : else
991 : {
992 33112 : bInsert = true;
993 113097 : xStyle = uno::Reference< style::XStyle >(xDocFactory->createInstance(
994 : bParaStyle ?
995 : rPropNameSupplier.GetName( PROP_SERVICE_PARA_STYLE ) :
996 33112 : (bListStyle ? OUString("com.sun.star.style.NumberingStyle") : rPropNameSupplier.GetName( PROP_SERVICE_CHAR_STYLE ))),
997 52463 : uno::UNO_QUERY_THROW);
998 :
999 : // Numbering styles have to be inserted early, as e.g. the NumberingRules property is only available after insertion.
1000 33112 : if (bListStyle)
1001 : {
1002 13761 : xStyles->insertByName( sConvertedStyleName, uno::makeAny( xStyle ) );
1003 13761 : xStyle.set(xStyles->getByName(sConvertedStyleName), uno::UNO_QUERY_THROW);
1004 :
1005 13761 : StyleSheetPropertyMap* pPropertyMap = dynamic_cast<StyleSheetPropertyMap*>(pEntry->pProperties.get());
1006 13761 : if (pPropertyMap && pPropertyMap->GetListId() == -1)
1007 : {
1008 : // No properties? Word default is 'none', Writer one is 'arabic', handle this.
1009 13647 : uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY_THROW);
1010 27294 : uno::Reference<container::XIndexReplace> xNumberingRules;
1011 13647 : xPropertySet->getPropertyValue("NumberingRules") >>= xNumberingRules;
1012 27294 : uno::Reference<container::XIndexAccess> xIndexAccess(xNumberingRules, uno::UNO_QUERY_THROW);
1013 150117 : for (sal_Int32 i = 0; i < xIndexAccess->getCount(); ++i)
1014 : {
1015 136470 : uno::Sequence< beans::PropertyValue > aLvlProps(1);
1016 136470 : aLvlProps[0].Name = "NumberingType";
1017 136470 : aLvlProps[0].Value <<= style::NumberingType::NUMBER_NONE;
1018 136470 : xNumberingRules->replaceByIndex(i, uno::makeAny(aLvlProps));
1019 136470 : xPropertySet->setPropertyValue("NumberingRules", uno::makeAny(xNumberingRules));
1020 150117 : }
1021 : }
1022 : }
1023 : }
1024 43858 : if( !pEntry->sBaseStyleIdentifier.isEmpty() )
1025 : {
1026 : try
1027 : {
1028 : //TODO: Handle cases where a paragraph <> character style relation is needed
1029 22704 : StyleSheetEntryPtr pParent = FindStyleSheetByISTD( pEntry->sBaseStyleIdentifier );
1030 : // Writer core doesn't support numbering styles having a parent style, it seems
1031 22704 : if (pParent.get() != nullptr && !bListStyle)
1032 22599 : xStyle->setParentStyle(ConvertStyleName( pParent->sStyleName ));
1033 : }
1034 5 : catch( const uno::RuntimeException& )
1035 : {
1036 : OSL_FAIL( "Styles parent could not be set");
1037 : }
1038 : }
1039 21154 : else if( bParaStyle )
1040 : {
1041 : //now it's time to set the default parameters - for paragraph styles
1042 : //Fonts: Western first entry in font table
1043 : //CJK: second entry
1044 : //CTL: third entry, if it exists
1045 :
1046 2863 : sal_uInt32 nFontCount = rFontTable->size();
1047 2863 : if( !m_pImpl->m_rDMapper.IsOOXMLImport() && nFontCount > 2 )
1048 : {
1049 173 : uno::Any aTwoHundredFortyTwip = uno::makeAny(12.);
1050 :
1051 : // font size to 240 twip (12 pts) for all if not set
1052 173 : pEntry->pProperties->Insert(PROP_CHAR_HEIGHT, aTwoHundredFortyTwip, false);
1053 :
1054 : // western font not already set -> apply first font
1055 346 : const FontEntry::Pointer_t pWesternFontEntry(rFontTable->getFontEntry( 0 ));
1056 346 : OUString sWesternFontName = pWesternFontEntry->sFontName;
1057 173 : pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( sWesternFontName ), false);
1058 :
1059 : // CJK ... apply second font
1060 346 : const FontEntry::Pointer_t pCJKFontEntry(rFontTable->getFontEntry( 2 ));
1061 173 : pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME_ASIAN, uno::makeAny( pCJKFontEntry->sFontName ), false);
1062 173 : pEntry->pProperties->Insert(PROP_CHAR_HEIGHT_ASIAN, aTwoHundredFortyTwip, false);
1063 :
1064 : // CTL ... apply third font, if available
1065 173 : if( nFontCount > 3 )
1066 : {
1067 173 : const FontEntry::Pointer_t pCTLFontEntry(rFontTable->getFontEntry( 3 ));
1068 173 : pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME_COMPLEX, uno::makeAny( pCTLFontEntry->sFontName ), false);
1069 173 : pEntry->pProperties->Insert(PROP_CHAR_HEIGHT_COMPLEX, aTwoHundredFortyTwip, false);
1070 173 : }
1071 : }
1072 :
1073 : // Widow/Orphan -> set both to two if not already set
1074 2863 : uno::Any aTwo = uno::makeAny(sal_Int8(2));
1075 2863 : pEntry->pProperties->Insert(PROP_PARA_WIDOWS, aTwo, false);
1076 2863 : pEntry->pProperties->Insert(PROP_PARA_ORPHANS, aTwo, false);
1077 :
1078 : // Left-to-right direction if not already set
1079 2863 : pEntry->pProperties->Insert(PROP_WRITING_MODE, uno::makeAny( sal_Int16(text::WritingMode_LR_TB) ), false);
1080 : // Left alignment if not already set
1081 2863 : pEntry->pProperties->Insert(PROP_PARA_ADJUST, uno::makeAny( sal_Int16(style::ParagraphAdjust_LEFT) ), false);
1082 : }
1083 :
1084 87716 : auto aPropValues = comphelper::sequenceToContainer< std::vector<beans::PropertyValue> >(pEntry->pProperties->GetPropertyValues());
1085 43858 : bool bAddFollowStyle = false;
1086 43858 : if(bParaStyle && !pEntry->sNextStyleIdentifier.isEmpty() )
1087 : {
1088 5340 : bAddFollowStyle = true;
1089 : }
1090 :
1091 : // remove Left/RightMargin values from TOX heading styles
1092 43858 : if( bParaStyle )
1093 : {
1094 : // Set the outline levels
1095 19139 : const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast<const StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : nullptr);
1096 19139 : if ( pStyleSheetProperties )
1097 : {
1098 : beans::PropertyValue aLvlVal( rPropNameSupplier.GetName( PROP_OUTLINE_LEVEL ), 0,
1099 19139 : uno::makeAny( sal_Int16( pStyleSheetProperties->GetOutlineLevel( ) + 1 ) ),
1100 38278 : beans::PropertyState_DIRECT_VALUE );
1101 19139 : aPropValues.push_back(aLvlVal);
1102 : }
1103 :
1104 19139 : uno::Reference< beans::XPropertyState >xState( xStyle, uno::UNO_QUERY_THROW );
1105 57335 : if( sConvertedStyleName == "Contents Heading" ||
1106 38195 : sConvertedStyleName == "User Index Heading" ||
1107 19056 : sConvertedStyleName == "Index Heading" )
1108 : {
1109 : //left margin is set to NULL by default
1110 84 : uno::Reference< beans::XPropertyState >xState1( xStyle, uno::UNO_QUERY_THROW );
1111 84 : xState1->setPropertyToDefault(rPropNameSupplier.GetName( PROP_PARA_LEFT_MARGIN ));
1112 : }
1113 19055 : else if ( sConvertedStyleName == "Text body" )
1114 102 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_PARA_BOTTOM_MARGIN ));
1115 56511 : else if( sConvertedStyleName == "Heading 1" ||
1116 36917 : sConvertedStyleName == "Heading 2" ||
1117 36382 : sConvertedStyleName == "Heading 3" ||
1118 35946 : sConvertedStyleName == "Heading 4" ||
1119 35592 : sConvertedStyleName == "Heading 5" ||
1120 35278 : sConvertedStyleName == "Heading 6" ||
1121 34994 : sConvertedStyleName == "Heading 7" ||
1122 53691 : sConvertedStyleName == "Heading 8" ||
1123 17306 : sConvertedStyleName == "Heading 9" )
1124 : {
1125 1776 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_WEIGHT ));
1126 1776 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_WEIGHT_ASIAN ));
1127 1776 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_WEIGHT_COMPLEX ));
1128 1776 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_POSTURE ));
1129 1776 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_POSTURE_ASIAN ));
1130 1776 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_POSTURE_COMPLEX ));
1131 1776 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_PROP_HEIGHT ));
1132 1776 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_PROP_HEIGHT_ASIAN ));
1133 1776 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_PROP_HEIGHT_COMPLEX));
1134 :
1135 19139 : }
1136 : }
1137 :
1138 43858 : if(bAddFollowStyle || !aPropValues.empty())
1139 : {
1140 27280 : PropValVector aSortedPropVals;
1141 221004 : for (const beans::PropertyValue& rValue : aPropValues)
1142 : {
1143 : // Don't add the style name properties
1144 193724 : bool bIsParaStyleName = rValue.Name == "ParaStyleName";
1145 193724 : bool bIsCharStyleName = rValue.Name == "CharStyleName";
1146 193724 : if ( !bIsParaStyleName && !bIsCharStyleName )
1147 : {
1148 193724 : aSortedPropVals.Insert(rValue);
1149 : }
1150 : }
1151 27280 : if(bAddFollowStyle)
1152 : {
1153 : //find the name of the Next style
1154 5340 : std::vector< StyleSheetEntryPtr >::iterator it = m_pImpl->m_aStyleSheetEntries.begin();
1155 112504 : for (; it != m_pImpl->m_aStyleSheetEntries.end(); ++it)
1156 : {
1157 112503 : if (!(*it)->sStyleName.isEmpty() && (*it)->sStyleIdentifierD == pEntry->sNextStyleIdentifier)
1158 : {
1159 5339 : beans::PropertyValue aNew;
1160 5339 : aNew.Name = "FollowStyle";
1161 5339 : aNew.Value = uno::makeAny(ConvertStyleName((*it)->sStyleIdentifierD));
1162 5339 : aSortedPropVals.Insert(aNew);
1163 5339 : break;
1164 : }
1165 : }
1166 : }
1167 :
1168 : try
1169 : {
1170 27280 : uno::Reference< beans::XMultiPropertySet > xMultiPropertySet( xStyle, uno::UNO_QUERY_THROW);
1171 27537 : xMultiPropertySet->setPropertyValues( aSortedPropVals.getNames(), aSortedPropVals.getValues() );
1172 : }
1173 257 : catch( const lang::WrappedTargetException& rWrapped)
1174 : {
1175 : (void) rWrapped;
1176 : #ifdef DEBUG_WRITERFILTER
1177 : OUString aMessage("StyleSheetTable::ApplyStyleSheets: Some style properties could not be set");
1178 : beans::UnknownPropertyException aUnknownPropertyException;
1179 :
1180 : if (rWrapped.TargetException >>= aUnknownPropertyException)
1181 : aMessage += ": " + aUnknownPropertyException.Message;
1182 :
1183 : SAL_WARN("writerfilter", aMessage);
1184 : #endif
1185 : }
1186 0 : catch( const uno::Exception& )
1187 : {
1188 : OSL_FAIL( "Some style properties could not be set");
1189 27280 : }
1190 : }
1191 : // Numbering style got inserted earlier.
1192 43858 : if(bInsert && !bListStyle)
1193 : {
1194 19351 : xStyles->insertByName( sConvertedStyleName, uno::makeAny( xStyle) );
1195 : }
1196 :
1197 87716 : beans::PropertyValues aGrabBag = pEntry->GetInteropGrabBagSeq();
1198 87716 : uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY);
1199 43858 : if (aGrabBag.hasElements())
1200 : {
1201 39435 : xPropertySet->setPropertyValue("StyleInteropGrabBag", uno::makeAny(aGrabBag));
1202 : }
1203 :
1204 : // List styles don't support automatic update.
1205 43858 : if (pEntry->bAutoRedefine && !bListStyle)
1206 45125 : xPropertySet->setPropertyValue("IsAutoUpdate", uno::makeAny(sal_True));
1207 : }
1208 2494 : else if(pEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
1209 : {
1210 : // If this is a table style, save its contents as-is for roundtrip purposes.
1211 2494 : TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(pEntry.get());
1212 2494 : aTableStylesVec.push_back(pTableEntry->GetInteropGrabBag());
1213 : }
1214 46352 : ++aIt;
1215 46352 : }
1216 :
1217 1683 : if (!aTableStylesVec.empty())
1218 : {
1219 : // If we had any table styles, add a new document-level InteropGrabBag entry for them.
1220 1367 : uno::Reference<beans::XPropertySet> xPropertySet(m_pImpl->m_xTextDocument, uno::UNO_QUERY);
1221 2734 : uno::Any aAny = xPropertySet->getPropertyValue("InteropGrabBag");
1222 2734 : auto aGrabBag = comphelper::sequenceToContainer< std::vector<beans::PropertyValue> >(aAny.get< uno::Sequence<beans::PropertyValue> >());
1223 2734 : beans::PropertyValue aValue;
1224 1367 : aValue.Name = "tableStyles";
1225 1367 : aValue.Value = uno::makeAny(comphelper::containerToSequence(aTableStylesVec));
1226 1367 : aGrabBag.push_back(aValue);
1227 2734 : xPropertySet->setPropertyValue("InteropGrabBag", uno::makeAny(comphelper::containerToSequence(aGrabBag)));
1228 1683 : }
1229 1683 : }
1230 : }
1231 12 : catch( const uno::Exception& rException )
1232 : {
1233 : SAL_WARN("writerfilter", "Styles could not be imported completely: " << rException.Message);
1234 : }
1235 1695 : }
1236 :
1237 :
1238 73095 : const StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByISTD(const OUString& sIndex)
1239 : {
1240 73095 : StyleSheetEntryPtr pRet;
1241 1728269 : for( size_t nPos = 0; nPos < m_pImpl->m_aStyleSheetEntries.size(); ++nPos )
1242 : {
1243 1718747 : if( m_pImpl->m_aStyleSheetEntries[nPos]->sStyleIdentifierD == sIndex)
1244 : {
1245 63573 : pRet = m_pImpl->m_aStyleSheetEntries[nPos];
1246 63573 : break;
1247 : }
1248 : }
1249 73095 : return pRet;
1250 : }
1251 :
1252 :
1253 5935 : const StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByStyleName(const OUString& sIndex)
1254 : {
1255 5935 : StyleSheetEntryPtr pRet;
1256 175188 : for( size_t nPos = 0; nPos < m_pImpl->m_aStyleSheetEntries.size(); ++nPos )
1257 : {
1258 174691 : if( m_pImpl->m_aStyleSheetEntries[nPos]->sStyleName == sIndex)
1259 : {
1260 5438 : pRet = m_pImpl->m_aStyleSheetEntries[nPos];
1261 5438 : break;
1262 : }
1263 : }
1264 5935 : return pRet;
1265 : }
1266 :
1267 :
1268 97 : const StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByConvertedStyleName(const OUString& sIndex)
1269 : {
1270 97 : StyleSheetEntryPtr pRet;
1271 3259 : for( size_t nPos = 0; nPos < m_pImpl->m_aStyleSheetEntries.size(); ++nPos )
1272 : {
1273 3237 : if( m_pImpl->m_aStyleSheetEntries[nPos]->sConvertedStyleName == sIndex)
1274 : {
1275 75 : pRet = m_pImpl->m_aStyleSheetEntries[nPos];
1276 75 : break;
1277 : }
1278 : }
1279 97 : return pRet;
1280 : }
1281 :
1282 :
1283 7415 : const StyleSheetEntryPtr StyleSheetTable::FindDefaultParaStyle()
1284 : {
1285 7415 : StyleSheetEntryPtr pRet;
1286 182155 : for (size_t i = 0; i < m_pImpl->m_aStyleSheetEntries.size(); ++i)
1287 : {
1288 180761 : StyleSheetEntryPtr pEntry = m_pImpl->m_aStyleSheetEntries[i];
1289 180761 : if (pEntry->bIsDefaultStyle && pEntry->nStyleTypeCode == STYLE_TYPE_PARA)
1290 : {
1291 6021 : pRet = pEntry;
1292 6021 : break;
1293 : }
1294 174740 : }
1295 7415 : return pRet;
1296 : }
1297 :
1298 6158 : const StyleSheetEntryPtr StyleSheetTable::FindParentStyleSheet(const OUString& _sBaseStyle)
1299 : {
1300 6158 : if( _sBaseStyle.isEmpty() )
1301 : {
1302 1010 : StyleSheetEntryPtr pEmptyPtr;
1303 1010 : return pEmptyPtr;
1304 : }
1305 5148 : OUString sBaseStyle = _sBaseStyle;
1306 5148 : if( m_pImpl->m_pCurrentEntry)
1307 0 : sBaseStyle = m_pImpl->m_pCurrentEntry->sBaseStyleIdentifier;
1308 :
1309 5148 : return FindStyleSheetByISTD( sBaseStyle );
1310 : }
1311 :
1312 :
1313 : static const sal_Char* const aStyleNamePairs[] =
1314 : {
1315 : "Normal", "Standard",
1316 : "heading 1", "Heading 1",
1317 : "heading 2", "Heading 2",
1318 : "heading 3", "Heading 3",
1319 : "heading 4", "Heading 4",
1320 : "heading 5", "Heading 5",
1321 : "heading 6", "Heading 6",
1322 : "heading 7", "Heading 7",
1323 : "heading 8", "Heading 8",
1324 : "heading 9", "Heading 9",
1325 : "Heading1", "Heading 1",
1326 : "Heading2", "Heading 2",
1327 : "Heading3", "Heading 3",
1328 : "Heading4", "Heading 4",
1329 : "Heading5", "Heading 5",
1330 : "Heading6", "Heading 6",
1331 : "Heading7", "Heading 7",
1332 : "Heading8", "Heading 8",
1333 : "Heading9", "Heading 9",
1334 : "Heading 1", "Heading 1",
1335 : "Heading 2", "Heading 2",
1336 : "Heading 3", "Heading 3",
1337 : "Heading 4", "Heading 4",
1338 : "Heading 5", "Heading 5",
1339 : "Heading 6", "Heading 6",
1340 : "Heading 7", "Heading 7",
1341 : "Heading 8", "Heading 8",
1342 : "Heading 9", "Heading 9",
1343 : "Index 1", "Index 1",
1344 : "Index 2", "Index 2",
1345 : "Index 3", "Index 3",
1346 : "Index 4", "",
1347 : "Index 5", "",
1348 : "Index 6", "",
1349 : "Index 7", "",
1350 : "Index 8", "",
1351 : "Index 9", "",
1352 : "TOC 1", "Contents 1",
1353 : "TOC 2", "Contents 2",
1354 : "TOC 3", "Contents 3",
1355 : "TOC 4", "Contents 4",
1356 : "TOC 5", "Contents 5",
1357 : "TOC 6", "Contents 6",
1358 : "TOC 7", "Contents 7",
1359 : "TOC 8", "Contents 8",
1360 : "TOC 9", "Contents 9",
1361 : "TOC Heading", "Contents Heading",
1362 : "TOCHeading", "Contents Heading",
1363 : "toc 1", "Contents 1",
1364 : "toc 2", "Contents 2",
1365 : "toc 3", "Contents 3",
1366 : "toc 4", "Contents 4",
1367 : "toc 5", "Contents 5",
1368 : "toc 6", "Contents 6",
1369 : "toc 7", "Contents 7",
1370 : "toc 8", "Contents 8",
1371 : "toc 9", "Contents 9",
1372 : "TOC1", "Contents 1",
1373 : "TOC2", "Contents 2",
1374 : "TOC3", "Contents 3",
1375 : "TOC4", "Contents 4",
1376 : "TOC5", "Contents 5",
1377 : "TOC6", "Contents 6",
1378 : "TOC7", "Contents 7",
1379 : "TOC8", "Contents 8",
1380 : "TOC9", "Contents 9",
1381 : "Normal Indent", "",
1382 : "Footnote Text", "Footnote",
1383 : "Annotation Text", "",
1384 : "Header", "Header",
1385 : "header", "Header",
1386 : "Footer", "Footer",
1387 : "footer", "Footer",
1388 : "Index Heading", "Index Heading",
1389 : "Caption", "",
1390 : "Table of Figures", "",
1391 : "Envelope Address", "Addressee",
1392 : "Envelope Return", "Sender",
1393 : "Footnote Reference", "Footnote anchor",
1394 : "Annotation Reference", "",
1395 : "Line Number", "Line numbering",
1396 : "Page Number", "Page Number",
1397 : "Endnote Reference", "Endnote anchor",
1398 : "Endnote Text", "Endnote Symbol",
1399 : "Table of Authorities", "",
1400 : "Macro Text", "",
1401 : "TOA Heading", "",
1402 : "List", "List",
1403 : "List 2", "",
1404 : "List 3", "",
1405 : "List 4", "",
1406 : "List 5", "",
1407 : "List Bullet", "",
1408 : "List Bullet 2", "",
1409 : "List Bullet 3", "",
1410 : "List Bullet 4", "",
1411 : "List Bullet 5", "",
1412 : "List Number", "",
1413 : "List Number 2", "",
1414 : "List Number 3", "",
1415 : "List Number 4", "",
1416 : "List Number 5", "",
1417 : "Title", "Title",
1418 : "Closing", "",
1419 : "Signature", "Signature",
1420 : "Default Paragraph Font", "",
1421 : "DefaultParagraphFont", "Default Paragraph Font",
1422 : "Body Text", "Text body",
1423 : "BodyText", "Text body",
1424 : "BodyTextIndentItalic", "Text body indent italic",
1425 : "Body Text Indent", "Text body indent",
1426 : "BodyTextIndent", "Text body indent",
1427 : "BodyTextIndent2", "Text body indent2",
1428 : "List Continue", "",
1429 : "List Continue 2", "",
1430 : "List Continue 3", "",
1431 : "List Continue 4", "",
1432 : "List Continue 5", "",
1433 : "Message Header", "",
1434 : "Subtitle", "Subtitle",
1435 : "Salutation", "",
1436 : "Date", "",
1437 : "Body Text First Indent", "Body Text Indent",
1438 : "Body Text First Indent 2", "",
1439 : "Note Heading", "",
1440 : "Body Text 2", "",
1441 : "Body Text 3", "",
1442 : "Body Text Indent 2", "",
1443 : "Body Text Indent 3", "",
1444 : "Block Text", "",
1445 : "Hyperlink", "Internet link",
1446 : "Followed Hyperlink", "Visited Internet Link",
1447 : "Emphasis", "Emphasis",
1448 : "Document Map", "",
1449 : "Plain Text", "",
1450 : "NoList", "No List",
1451 : "AbstractHeading", "Abstract Heading",
1452 : "AbstractBody", "Abstract Body",
1453 : "PageNumber", "page number"
1454 : "TableNormal", "Normal Table",
1455 : "DocumentMap", "Document Map"
1456 : };
1457 :
1458 :
1459 139585 : OUString StyleSheetTable::ConvertStyleName( const OUString& rWWName, bool bExtendedSearch)
1460 : {
1461 139585 : OUString sRet( rWWName );
1462 139585 : if( bExtendedSearch )
1463 : {
1464 : //search for the rWWName in the IdentifierD of the existing styles and convert the sStyleName member
1465 21262 : std::vector< StyleSheetEntryPtr >::iterator aIt = m_pImpl->m_aStyleSheetEntries.begin();
1466 : //TODO: performance issue - put styles list into a map sorted by it's sStyleIdentifierD members
1467 2752437 : while( aIt != m_pImpl->m_aStyleSheetEntries.end() )
1468 : {
1469 2709913 : if( rWWName == ( *aIt )->sStyleIdentifierD )
1470 21210 : sRet = ( *aIt )->sStyleName;
1471 2709913 : ++aIt;
1472 : }
1473 : }
1474 139585 : if(!m_pImpl->m_aStyleNameMap.size())
1475 : {
1476 238854 : for( sal_uInt32 nPair = 0; nPair < sizeof(aStyleNamePairs) / sizeof( sal_Char*) / 2; ++nPair)
1477 : {
1478 237160 : OUString aFrom = OUString::createFromAscii(aStyleNamePairs[2 * nPair]);
1479 474320 : OUString aTo = OUString::createFromAscii(aStyleNamePairs[2 * nPair + 1]);
1480 237160 : if (!aTo.isEmpty())
1481 : {
1482 157542 : m_pImpl->m_aStyleNameMap.insert( StringPairMap_t::value_type(aFrom, aTo));
1483 157542 : m_pImpl->m_aReservedStyleNames.insert(aTo);
1484 : }
1485 237160 : }
1486 : }
1487 139585 : StringPairMap_t::iterator aIt = m_pImpl->m_aStyleNameMap.find( sRet );
1488 139585 : bool bConverted = false;
1489 139585 : if (aIt != m_pImpl->m_aStyleNameMap.end())
1490 : {
1491 39752 : bConverted = true;
1492 39752 : sRet = aIt->second;
1493 : }
1494 :
1495 139585 : if (!bConverted)
1496 : {
1497 : // SwStyleNameMapper doc says: If the UI style name equals a
1498 : // programmatic name, then it must append " (user)" to the end.
1499 99833 : std::set<OUString>::iterator aReservedIt = m_pImpl->m_aReservedStyleNames.find(sRet);
1500 99833 : if (aReservedIt != m_pImpl->m_aReservedStyleNames.end())
1501 13825 : sRet += " (user)";
1502 : }
1503 139585 : return sRet;
1504 : }
1505 :
1506 2952 : void StyleSheetTable::applyDefaults(bool bParaProperties)
1507 : {
1508 : try{
1509 2952 : if(!m_pImpl->m_xTextDefaults.is())
1510 : {
1511 2952 : m_pImpl->m_xTextDefaults = uno::Reference< beans::XPropertySet>(
1512 2952 : m_pImpl->m_rDMapper.GetTextFactory()->createInstance("com.sun.star.text.Defaults"),
1513 1476 : uno::UNO_QUERY_THROW );
1514 : }
1515 2952 : if( bParaProperties && m_pImpl->m_pDefaultParaProps.get())
1516 : {
1517 1476 : uno::Sequence< beans::PropertyValue > aPropValues = m_pImpl->m_pDefaultParaProps->GetPropertyValues();
1518 3404 : for( sal_Int32 i = 0; i < aPropValues.getLength(); ++i )
1519 : {
1520 : try
1521 : {
1522 1928 : m_pImpl->m_xTextDefaults->setPropertyValue( aPropValues[i].Name, aPropValues[i].Value );
1523 : }
1524 0 : catch( const uno::Exception& )
1525 : {
1526 : OSL_FAIL( "setPropertyValue exception");
1527 : }
1528 1476 : }
1529 : }
1530 2952 : if( !bParaProperties && m_pImpl->m_pDefaultCharProps.get())
1531 : {
1532 1476 : uno::Sequence< beans::PropertyValue > aPropValues = m_pImpl->m_pDefaultCharProps->GetPropertyValues();
1533 15975 : for( sal_Int32 i = 0; i < aPropValues.getLength(); ++i )
1534 : {
1535 : try
1536 : {
1537 14499 : m_pImpl->m_xTextDefaults->setPropertyValue( aPropValues[i].Name, aPropValues[i].Value );
1538 : }
1539 0 : catch( const uno::Exception& )
1540 : {
1541 : OSL_FAIL( "setPropertyValue exception");
1542 : }
1543 1476 : }
1544 : }
1545 : }
1546 0 : catch( const uno::Exception& )
1547 : {
1548 : }
1549 2952 : }
1550 :
1551 :
1552 10391 : OUString StyleSheetTable::getOrCreateCharStyle( PropertyValueVector_t& rCharProperties )
1553 : {
1554 : //find out if any of the styles already has the required properties then return its name
1555 10391 : OUString sListLabel = m_pImpl->HasListCharStyle(rCharProperties);
1556 10391 : if( !sListLabel.isEmpty() )
1557 9657 : return sListLabel;
1558 734 : const char cListLabel[] = "ListLabel ";
1559 1468 : uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
1560 1468 : uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
1561 1468 : uno::Reference<container::XNameContainer> xCharStyles;
1562 734 : xStyleFamilies->getByName("CharacterStyles") >>= xCharStyles;
1563 : //search for all character styles with the name sListLabel + <index>
1564 734 : sal_Int32 nStyleFound = 0;
1565 1468 : uno::Sequence< OUString > aStyleNames = xCharStyles->getElementNames();
1566 734 : const OUString* pStyleNames = aStyleNames.getConstArray();
1567 40766 : for( sal_Int32 nStyle = 0; nStyle < aStyleNames.getLength(); ++nStyle )
1568 : {
1569 40032 : OUString sSuffix;
1570 40032 : if( pStyleNames[nStyle].startsWith( cListLabel, &sSuffix ) )
1571 : {
1572 2448 : sal_Int32 nSuffix = sSuffix.toInt32();
1573 2448 : if( nSuffix > 0 )
1574 : {
1575 2448 : if( nSuffix > nStyleFound )
1576 2448 : nStyleFound = nSuffix;
1577 : }
1578 : }
1579 40032 : }
1580 734 : sListLabel = cListLabel + OUString::number( ++nStyleFound );
1581 : //create a new one otherwise
1582 1468 : uno::Reference< lang::XMultiServiceFactory > xDocFactory( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
1583 734 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1584 : try
1585 : {
1586 734 : uno::Reference< style::XStyle > xStyle( xDocFactory->createInstance(
1587 734 : rPropNameSupplier.GetName( PROP_SERVICE_CHAR_STYLE )), uno::UNO_QUERY_THROW);
1588 1468 : uno::Reference< beans::XPropertySet > xStyleProps(xStyle, uno::UNO_QUERY_THROW );
1589 734 : PropertyValueVector_t::const_iterator aCharPropIter = rCharProperties.begin();
1590 3452 : while( aCharPropIter != rCharProperties.end())
1591 : {
1592 : try
1593 : {
1594 1984 : xStyleProps->setPropertyValue( aCharPropIter->Name, aCharPropIter->Value );
1595 : }
1596 264 : catch( const uno::Exception& )
1597 : {
1598 : OSL_FAIL( "Exception in StyleSheetTable::getOrCreateCharStyle - Style::setPropertyValue");
1599 : }
1600 1984 : ++aCharPropIter;
1601 : }
1602 734 : xCharStyles->insertByName( sListLabel, uno::makeAny( xStyle) );
1603 1468 : m_pImpl->m_aListCharStylePropertyVector.push_back( ListCharStylePropertyMap_t( sListLabel, rCharProperties ));
1604 : }
1605 0 : catch( const uno::Exception& )
1606 : {
1607 : OSL_FAIL( "Exception in StyleSheetTable::getOrCreateCharStyle");
1608 : }
1609 :
1610 734 : return sListLabel;
1611 : }
1612 :
1613 : }//namespace dmapper
1614 : }//namespace writerfilter
1615 :
1616 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|