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