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 <doctok/resourceids.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 :
44 : #include <dmapperLoggers.hxx>
45 :
46 : using namespace ::com::sun::star;
47 : namespace writerfilter {
48 : namespace dmapper
49 : {
50 :
51 : typedef ::std::map< OUString, OUString> StringPairMap_t;
52 :
53 :
54 :
55 2138 : StyleSheetEntry::StyleSheetEntry() :
56 : sStyleIdentifierI()
57 : ,sStyleIdentifierD()
58 : ,bIsDefaultStyle(false)
59 : ,bInvalidHeight(false)
60 : ,bHasUPE(false)
61 : ,nStyleTypeCode(STYLE_TYPE_UNKNOWN)
62 : ,sBaseStyleIdentifier()
63 : ,sNextStyleIdentifier()
64 2138 : ,pProperties(new StyleSheetPropertyMap)
65 : {
66 2138 : }
67 :
68 4162 : StyleSheetEntry::~StyleSheetEntry()
69 : {
70 4162 : }
71 :
72 114 : TableStyleSheetEntry::TableStyleSheetEntry( StyleSheetEntry& rEntry, StyleSheetTable* pStyles ):
73 : StyleSheetEntry( ),
74 114 : m_pStyleSheet( pStyles )
75 : {
76 :
77 114 : bIsDefaultStyle = rEntry.bIsDefaultStyle;
78 114 : bInvalidHeight = rEntry.bInvalidHeight;
79 114 : bHasUPE = rEntry.bHasUPE;
80 114 : nStyleTypeCode = STYLE_TYPE_TABLE;
81 114 : sBaseStyleIdentifier = rEntry.sBaseStyleIdentifier;
82 114 : sNextStyleIdentifier = rEntry.sNextStyleIdentifier;
83 114 : sStyleName = rEntry.sStyleName;
84 114 : sStyleName1 = rEntry.sStyleName1;
85 114 : sStyleIdentifierI = rEntry.sStyleIdentifierI;
86 114 : sStyleIdentifierD = rEntry.sStyleIdentifierD;
87 :
88 114 : m_nColBandSize = 1;
89 114 : m_nRowBandSize = 1;
90 114 : }
91 :
92 342 : TableStyleSheetEntry::~TableStyleSheetEntry( )
93 : {
94 114 : m_pStyleSheet = NULL;
95 228 : }
96 :
97 32 : void TableStyleSheetEntry::AddTblStylePr( TblStyleType nType, PropertyMapPtr pProps )
98 : {
99 : static const TblStyleType pTypesToFix[] =
100 : {
101 : TBL_STYLE_FIRSTROW,
102 : TBL_STYLE_LASTROW,
103 : TBL_STYLE_FIRSTCOL,
104 : TBL_STYLE_LASTCOL
105 : };
106 :
107 : static const PropertyIds pPropsToCheck[] =
108 : {
109 : PROP_BOTTOM_BORDER,
110 : PROP_TOP_BORDER,
111 : PROP_RIGHT_BORDER,
112 : PROP_LEFT_BORDER
113 : };
114 :
115 32 : int i = 0;
116 162 : while ( i < 4 )
117 : {
118 98 : if ( nType == pTypesToFix[i] )
119 : {
120 20 : PropertyIds nChecked = pPropsToCheck[i];
121 20 : PropertyMap::iterator pCheckedIt = pProps->find( PropertyDefinition( nChecked ) );
122 :
123 20 : PropertyIds nInsideProp = ( i < 2 ) ? META_PROP_HORIZONTAL_BORDER : META_PROP_VERTICAL_BORDER;
124 20 : PropertyMap::iterator pInsideIt = pProps->find( PropertyDefinition( nInsideProp ) );
125 :
126 20 : bool bHasChecked = pCheckedIt != pProps->end( );
127 20 : bool bHasInside = pInsideIt != pProps->end( );
128 :
129 20 : if ( bHasChecked && bHasInside )
130 : {
131 : // In this case, remove the inside border
132 5 : pProps->erase( pInsideIt );
133 : }
134 :
135 20 : i = 4; // Stop looping stupidly
136 : }
137 98 : i++;
138 : }
139 :
140 : // Append the tblStylePr
141 32 : m_aStyles[nType] = pProps;
142 32 : }
143 :
144 216 : PropertyMapPtr TableStyleSheetEntry::GetProperties( sal_Int32 nMask, StyleSheetEntryDequePtr pStack )
145 : {
146 216 : PropertyMapPtr pProps( new PropertyMap );
147 :
148 : // First get the parent properties
149 432 : StyleSheetEntryPtr pEntry = m_pStyleSheet->FindParentStyleSheet( sBaseStyleIdentifier );
150 :
151 216 : if ( pEntry.get( ) )
152 : {
153 216 : if (pStack.get() == NULL)
154 216 : pStack.reset(new StyleSheetEntryDeque());
155 :
156 216 : StyleSheetEntryDeque::const_iterator aIt = find(pStack->begin(), pStack->end(), pEntry);
157 :
158 216 : if (aIt != pStack->end())
159 : {
160 0 : pStack->push_back(pEntry);
161 :
162 0 : TableStyleSheetEntry* pParent = static_cast<TableStyleSheetEntry *>( pEntry.get( ) );
163 0 : pProps->InsertProps(pParent->GetProperties(nMask));
164 :
165 0 : pStack->pop_back();
166 : }
167 : }
168 :
169 : // And finally get the mask ones
170 216 : pProps->InsertProps(GetLocalPropertiesFromMask(nMask));
171 :
172 432 : return pProps;
173 : }
174 :
175 112 : void lcl_mergeProps( PropertyMapPtr pToFill, PropertyMapPtr pToAdd, TblStyleType nStyleId )
176 : {
177 : static const PropertyIds pPropsToCheck[] =
178 : {
179 : PROP_BOTTOM_BORDER,
180 : PROP_TOP_BORDER,
181 : PROP_RIGHT_BORDER,
182 : PROP_LEFT_BORDER,
183 : };
184 :
185 : bool pRemoveInside[] =
186 : {
187 112 : ( nStyleId == TBL_STYLE_FIRSTROW ),
188 112 : ( nStyleId == TBL_STYLE_LASTROW ),
189 112 : ( nStyleId == TBL_STYLE_LASTCOL ),
190 112 : ( nStyleId == TBL_STYLE_FIRSTCOL )
191 448 : };
192 :
193 560 : for ( unsigned i = 0 ; i != sizeof(pPropsToCheck) / sizeof(PropertyIds); i++ )
194 : {
195 448 : PropertyIds nId = pPropsToCheck[i];
196 448 : PropertyDefinition aProp( nId );
197 448 : PropertyMap::iterator pIt = pToAdd->find( aProp );
198 :
199 448 : if ( pIt != pToAdd->end( ) )
200 : {
201 36 : PropertyMap::iterator pDestIt = pToFill->find( aProp );
202 :
203 36 : if ( pRemoveInside[i] )
204 : {
205 : // Remove the insideH and insideV depending on the cell pos
206 11 : PropertyIds nInsideProp = ( i < 2 ) ? META_PROP_HORIZONTAL_BORDER : META_PROP_VERTICAL_BORDER;
207 11 : pDestIt = pToFill->find( PropertyDefinition( nInsideProp ) );
208 11 : if ( pDestIt != pToFill->end( ) )
209 0 : pToFill->erase( pDestIt );
210 : }
211 : }
212 : }
213 :
214 112 : pToFill->InsertProps(pToAdd);
215 112 : }
216 :
217 216 : PropertyMapPtr TableStyleSheetEntry::GetLocalPropertiesFromMask( sal_Int32 nMask )
218 : {
219 : // Order from right to left
220 : struct TblStyleTypeAndMask {
221 : sal_Int32 mask;
222 : TblStyleType type;
223 : };
224 :
225 : static const TblStyleTypeAndMask aOrderedStyleTable[] =
226 : {
227 : { 0x010, TBL_STYLE_BAND2HORZ },
228 : { 0x020, TBL_STYLE_BAND1HORZ },
229 : { 0x040, TBL_STYLE_BAND2VERT },
230 : { 0x080, TBL_STYLE_BAND1VERT },
231 : { 0x100, TBL_STYLE_LASTCOL },
232 : { 0x200, TBL_STYLE_FIRSTCOL },
233 : { 0x400, TBL_STYLE_LASTROW },
234 : { 0x800, TBL_STYLE_FIRSTROW },
235 : { 0x001, TBL_STYLE_SWCELL },
236 : { 0x002, TBL_STYLE_SECELL },
237 : { 0x004, TBL_STYLE_NWCELL },
238 : { 0x008, TBL_STYLE_NECELL }
239 : };
240 :
241 : // Get the properties applying according to the mask
242 216 : PropertyMapPtr pProps( new PropertyMap( ) );
243 2808 : for (size_t i = 0; i < sizeof(aOrderedStyleTable)/sizeof(aOrderedStyleTable[0]); ++i)
244 : {
245 2592 : TblStylePrs::iterator pIt = m_aStyles.find( aOrderedStyleTable[ i ].type );
246 2592 : if ( ( nMask & aOrderedStyleTable[ i ].mask ) && ( pIt != m_aStyles.end( ) ) )
247 112 : lcl_mergeProps( pProps, pIt->second, aOrderedStyleTable[ i ].type );
248 : }
249 216 : return pProps;
250 : }
251 :
252 :
253 :
254 170 : struct ListCharStylePropertyMap_t
255 : {
256 : OUString sCharStyleName;
257 : PropertyValueVector_t aPropertyValues;
258 :
259 38 : ListCharStylePropertyMap_t(const OUString& rCharStyleName, const PropertyValueVector_t& rPropertyValues):
260 : sCharStyleName( rCharStyleName ),
261 38 : aPropertyValues( rPropertyValues )
262 38 : {}
263 : };
264 : typedef std::vector< ListCharStylePropertyMap_t > ListCharStylePropertyVector_t;
265 :
266 :
267 350 : struct StyleSheetTable_Impl
268 : {
269 : DomainMapper& m_rDMapper;
270 : uno::Reference< text::XTextDocument> m_xTextDocument;
271 : uno::Reference< beans::XPropertySet> m_xTextDefaults;
272 : std::vector< StyleSheetEntryPtr > m_aStyleSheetEntries;
273 : StyleSheetEntryPtr m_pCurrentEntry;
274 : PropertyMapPtr m_pDefaultParaProps, m_pDefaultCharProps;
275 : PropertyMapPtr m_pCurrentProps;
276 : StringPairMap_t m_aStyleNameMap;
277 : ListCharStylePropertyVector_t m_aListCharStylePropertyVector;
278 : bool m_bIsNewDoc;
279 :
280 : StyleSheetTable_Impl(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> xTextDocument, bool bIsNewDoc);
281 :
282 : OUString HasListCharStyle( const PropertyValueVector_t& rCharProperties );
283 : };
284 :
285 :
286 350 : StyleSheetTable_Impl::StyleSheetTable_Impl(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> xTextDocument, bool bIsNewDoc ) :
287 : m_rDMapper( rDMapper ),
288 : m_xTextDocument( xTextDocument ),
289 : m_pCurrentEntry(),
290 350 : m_pDefaultParaProps(new PropertyMap),
291 350 : m_pDefaultCharProps(new PropertyMap),
292 1050 : m_bIsNewDoc(bIsNewDoc)
293 : {
294 : //set font height default to 10pt
295 350 : uno::Any aVal = uno::makeAny( double(10.) );
296 350 : m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT, aVal );
297 350 : m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT_ASIAN, aVal );
298 350 : m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT_COMPLEX, aVal );
299 350 : }
300 :
301 :
302 267 : OUString StyleSheetTable_Impl::HasListCharStyle( const PropertyValueVector_t& rPropValues )
303 : {
304 267 : OUString sRet;
305 267 : ListCharStylePropertyVector_t::const_iterator aListVectorIter = m_aListCharStylePropertyVector.begin();
306 997 : while( aListVectorIter != m_aListCharStylePropertyVector.end() )
307 : {
308 : //if size is identical
309 692 : if( aListVectorIter->aPropertyValues.size() == rPropValues.size() )
310 : {
311 432 : bool bBreak = false;
312 : //then search for all contained properties
313 432 : PropertyValueVector_t::const_iterator aList1Iter = rPropValues.begin();
314 1477 : while( aList1Iter != rPropValues.end() && !bBreak)
315 : {
316 : //find the property
317 615 : bool bElementFound = false;
318 615 : PropertyValueVector_t::const_iterator aList2Iter = aListVectorIter->aPropertyValues.begin();
319 1500 : while( aList2Iter != aListVectorIter->aPropertyValues.end() && !bBreak )
320 : {
321 883 : if( aList2Iter->Name == aList1Iter->Name )
322 : {
323 613 : bElementFound = true;
324 613 : if( aList2Iter->Value != aList1Iter->Value )
325 201 : bBreak = true;
326 613 : break;
327 : }
328 270 : ++aList2Iter;
329 : }
330 : //set break flag if property hasn't been found
331 615 : if(!bElementFound )
332 : {
333 2 : bBreak = true;
334 2 : break;
335 : }
336 613 : ++aList1Iter;
337 : }
338 432 : if( !bBreak )
339 229 : return aListVectorIter->sCharStyleName;
340 : }
341 463 : ++aListVectorIter;
342 : }
343 38 : return sRet;
344 : }
345 :
346 :
347 350 : StyleSheetTable::StyleSheetTable(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> xTextDocument, bool bIsNewDoc)
348 : : LoggedProperties(dmapper_logger, "StyleSheetTable")
349 : , LoggedTable(dmapper_logger, "StyleSheetTable")
350 350 : , m_pImpl( new StyleSheetTable_Impl(rDMapper, xTextDocument, bIsNewDoc) )
351 : {
352 350 : }
353 :
354 :
355 1050 : StyleSheetTable::~StyleSheetTable()
356 : {
357 350 : delete m_pImpl;
358 700 : }
359 :
360 10 : PropertyMapPtr StyleSheetTable::GetDefaultCharProps()
361 : {
362 10 : return m_pImpl->m_pDefaultCharProps;
363 : }
364 :
365 5604 : void StyleSheetTable::lcl_attribute(Id Name, Value & val)
366 : {
367 : OSL_ENSURE( m_pImpl->m_pCurrentEntry, "current entry has to be set here");
368 5604 : if(!m_pImpl->m_pCurrentEntry)
369 5604 : return ;
370 5604 : int nIntValue = val.getInt();
371 : (void)nIntValue;
372 5604 : OUString sValue = val.getString();
373 :
374 : // The default type is paragraph, and it needs to be processed first,
375 : // because the NS_ooxml::LN_CT_Style_type handling may set m_pImpl->m_pCurrentEntry
376 : // to point to a different object.
377 5604 : if( m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_UNKNOWN )
378 : {
379 1934 : if( Name != NS_rtf::LN_SGC && Name != NS_ooxml::LN_CT_Style_type )
380 402 : m_pImpl->m_pCurrentEntry->nStyleTypeCode = STYLE_TYPE_PARA;
381 : }
382 5604 : switch(Name)
383 : {
384 : case NS_rtf::LN_ISTD:
385 402 : m_pImpl->m_pCurrentEntry->sStyleIdentifierD = OUString::valueOf(static_cast<sal_Int32>(nIntValue), 16);
386 402 : break;
387 : case NS_rtf::LN_STI:
388 : {
389 0 : OUString tempStyleIdentifier = GetStyleIdFromIndex(static_cast<sal_uInt32>(nIntValue));
390 0 : if (!tempStyleIdentifier.isEmpty())
391 0 : m_pImpl->m_pCurrentEntry->sStyleIdentifierI = tempStyleIdentifier;
392 0 : if (nIntValue == 0 || nIntValue == 65)
393 0 : m_pImpl->m_pCurrentEntry->bIsDefaultStyle = true;
394 : }
395 0 : break;
396 : case NS_rtf::LN_SGC:
397 : SAL_WARN_IF( m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN,
398 : "writerfilter", "Style type needs to be processed first" );
399 402 : m_pImpl->m_pCurrentEntry->nStyleTypeCode = (StyleType)nIntValue;
400 402 : break;
401 : case NS_rtf::LN_ISTDBASE:
402 301 : if (static_cast<sal_uInt32>(nIntValue) != 0xfff)
403 301 : m_pImpl->m_pCurrentEntry->sBaseStyleIdentifier = OUString::valueOf(static_cast<sal_Int32>(nIntValue), 16);
404 301 : break;
405 : case NS_rtf::LN_ISTDNEXT:
406 337 : if (static_cast<sal_uInt32>(nIntValue) != 0xfff)
407 337 : m_pImpl->m_pCurrentEntry->sNextStyleIdentifier = OUString::valueOf(static_cast<sal_Int32>(nIntValue), 16);
408 337 : break;
409 : case NS_rtf::LN_FSCRATCH:
410 : case NS_rtf::LN_FINVALHEIGHT:
411 : case NS_rtf::LN_FHASUPE:
412 : case NS_rtf::LN_FMASSCOPY:
413 : case NS_rtf::LN_CUPX:
414 : case NS_rtf::LN_BCHUPE:
415 : case NS_rtf::LN_FAUTOREDEF:
416 : case NS_rtf::LN_FHIDDEN:
417 : case NS_rtf::LN_UNUSED8_3:
418 : //noone seems to care about it
419 0 : break;
420 : case NS_rtf::LN_XSTZNAME:
421 0 : m_pImpl->m_pCurrentEntry->sStyleName1 = sValue;
422 0 : if (!m_pImpl->m_pCurrentEntry->sStyleIdentifierI.isEmpty())
423 0 : m_pImpl->m_pCurrentEntry->sStyleIdentifierI = sValue;
424 0 : break;
425 : case NS_rtf::LN_XSTZNAME1:
426 402 : m_pImpl->m_pCurrentEntry->sStyleName = sValue;
427 402 : if (!m_pImpl->m_pCurrentEntry->sStyleIdentifierI.isEmpty())
428 0 : m_pImpl->m_pCurrentEntry->sStyleIdentifierI = sValue;
429 402 : break;
430 : case NS_rtf::LN_UPX:
431 0 : resolveAttributeProperties(val);
432 0 : break;
433 : case NS_ooxml::LN_CT_Style_type:
434 : {
435 : SAL_WARN_IF( m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN,
436 : "writerfilter", "Style type needs to be processed first" );
437 1532 : StyleType nType = ( StyleType ) nIntValue;
438 1532 : if ( nType == STYLE_TYPE_TABLE )
439 : {
440 114 : StyleSheetEntryPtr pEntry = m_pImpl->m_pCurrentEntry;
441 228 : TableStyleSheetEntryPtr pTableEntry( new TableStyleSheetEntry( *pEntry.get( ), this ) );
442 228 : m_pImpl->m_pCurrentEntry = pTableEntry;
443 : }
444 : else
445 1418 : m_pImpl->m_pCurrentEntry->nStyleTypeCode = (StyleType)nIntValue;
446 : }
447 1532 : break;
448 : case NS_ooxml::LN_CT_Style_default:
449 348 : m_pImpl->m_pCurrentEntry->bIsDefaultStyle = (nIntValue != 0);
450 348 : break;
451 : case NS_ooxml::LN_CT_Style_customStyle:
452 282 : break;
453 : case NS_ooxml::LN_CT_Style_styleId:
454 1532 : m_pImpl->m_pCurrentEntry->sStyleIdentifierI = sValue;
455 1532 : m_pImpl->m_pCurrentEntry->sStyleIdentifierD = sValue;
456 1532 : break;
457 : case NS_ooxml::LN_CT_TblWidth_w:
458 0 : dynamic_cast< StyleSheetPropertyMap* >( m_pImpl->m_pCurrentEntry->pProperties.get() )->SetCT_TblWidth_w( nIntValue );
459 0 : break;
460 : case NS_ooxml::LN_CT_TblWidth_type:
461 0 : dynamic_cast< StyleSheetPropertyMap* >( m_pImpl->m_pCurrentEntry->pProperties.get() )->SetCT_TblWidth_type( nIntValue );
462 0 : break;
463 : default:
464 : {
465 : #ifdef DEBUG_DOMAINMAPPER
466 : dmapper_logger->element("unhandled");
467 : #endif
468 : }
469 66 : break;
470 5604 : }
471 : }
472 :
473 :
474 10159 : void StyleSheetTable::lcl_sprm(Sprm & rSprm)
475 : {
476 10159 : sal_uInt32 nSprmId = rSprm.getId();
477 10159 : Value::Pointer_t pValue = rSprm.getValue();
478 10159 : sal_Int32 nIntValue = pValue.get() ? pValue->getInt() : 0;
479 : (void)nIntValue;
480 20318 : OUString sStringValue = pValue.get() ? pValue->getString() : OUString();
481 :
482 10159 : switch(nSprmId)
483 : {
484 : case NS_ooxml::LN_CT_Style_name:
485 : //this is only a UI name!
486 1532 : m_pImpl->m_pCurrentEntry->sStyleName = sStringValue;
487 1532 : m_pImpl->m_pCurrentEntry->sStyleName1 = sStringValue;
488 1532 : break;
489 : case NS_ooxml::LN_CT_Style_basedOn:
490 1056 : m_pImpl->m_pCurrentEntry->sBaseStyleIdentifier = sStringValue;
491 1056 : break;
492 : case NS_ooxml::LN_CT_Style_next:
493 664 : m_pImpl->m_pCurrentEntry->sNextStyleIdentifier = sStringValue;
494 664 : break;
495 : case NS_ooxml::LN_CT_Style_aliases:
496 : case NS_ooxml::LN_CT_Style_link:
497 : case NS_ooxml::LN_CT_Style_autoRedefine:
498 : case NS_ooxml::LN_CT_Style_hidden:
499 : case NS_ooxml::LN_CT_Style_uiPriority:
500 : case NS_ooxml::LN_CT_Style_semiHidden:
501 : case NS_ooxml::LN_CT_Style_unhideWhenUsed:
502 : case NS_ooxml::LN_CT_Style_qFormat:
503 : case NS_ooxml::LN_CT_Style_locked:
504 : case NS_ooxml::LN_CT_Style_personal:
505 : case NS_ooxml::LN_CT_Style_personalCompose:
506 : case NS_ooxml::LN_CT_Style_personalReply:
507 : case NS_ooxml::LN_CT_Style_rsid:
508 : case NS_ooxml::LN_CT_Style_trPr:
509 : case NS_ooxml::LN_CT_Style_tcPr:
510 2981 : break;
511 : case NS_ooxml::LN_CT_Style_tblPr: //contains table properties
512 : case NS_ooxml::LN_CT_Style_tblStylePr: //contains to table properties
513 : case NS_ooxml::LN_CT_TblPrBase_tblInd: //table properties - at least width value and type
514 : case NS_ooxml::LN_EG_RPrBase_rFonts: //table fonts
515 : {
516 146 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
517 146 : if( pProperties.get())
518 : {
519 146 : TblStylePrHandlerPtr pTblStylePrHandler( new TblStylePrHandler( m_pImpl->m_rDMapper ) );
520 146 : pProperties->resolve( *pTblStylePrHandler );
521 :
522 : // Add the properties to the table style
523 146 : TblStyleType nType = pTblStylePrHandler->getType( );
524 292 : PropertyMapPtr pProps = pTblStylePrHandler->getProperties( );
525 146 : StyleSheetEntry * pEntry = m_pImpl->m_pCurrentEntry.get();
526 :
527 146 : if (nType == TBL_STYLE_UNKNOWN)
528 : {
529 114 : pEntry->pProperties->InsertProps(pProps);
530 : }
531 : else
532 : {
533 32 : TableStyleSheetEntry * pTableEntry = dynamic_cast<TableStyleSheetEntry*>( pEntry );
534 32 : if (pTableEntry != NULL)
535 32 : pTableEntry->AddTblStylePr( nType, pProps );
536 146 : }
537 : }
538 146 : break;
539 : }
540 : case NS_ooxml::LN_CT_PPrDefault_pPr:
541 : case NS_ooxml::LN_CT_DocDefaults_pPrDefault:
542 90 : m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pDefaultParaProps );
543 90 : resourcemodel::resolveSprmProps( m_pImpl->m_rDMapper, rSprm );
544 90 : m_pImpl->m_rDMapper.PopStyleSheetProperties();
545 90 : applyDefaults( true );
546 90 : break;
547 : case NS_ooxml::LN_CT_RPrDefault_rPr:
548 : case NS_ooxml::LN_CT_DocDefaults_rPrDefault:
549 90 : m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pDefaultCharProps );
550 90 : resourcemodel::resolveSprmProps( m_pImpl->m_rDMapper, rSprm );
551 90 : m_pImpl->m_rDMapper.PopStyleSheetProperties();
552 90 : applyDefaults( false );
553 90 : break;
554 : case NS_ooxml::LN_CT_TblPrBase_jc: //table alignment - row properties!
555 0 : m_pImpl->m_pCurrentEntry->pProperties->Insert( PROP_HORI_ORIENT,
556 0 : uno::makeAny( ConversionHelper::convertTableJustification( nIntValue )));
557 0 : break;
558 : case NS_ooxml::LN_CT_TrPrBase_jc: //table alignment - row properties!
559 0 : dynamic_cast< StyleSheetPropertyMap* >( m_pImpl->m_pCurrentEntry->pProperties.get() )->SetCT_TrPrBase_jc(nIntValue);
560 0 : break;
561 : case NS_ooxml::LN_CT_TblPrBase_tblBorders: //table borders, might be defined in table style
562 : {
563 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
564 0 : if( pProperties.get())
565 : {
566 0 : BorderHandlerPtr pBorderHandler( new BorderHandler(m_pImpl->m_rDMapper.IsOOXMLImport()) );
567 0 : pProperties->resolve(*pBorderHandler);
568 0 : m_pImpl->m_pCurrentEntry->pProperties->InsertProps(
569 0 : pBorderHandler->getProperties());
570 0 : }
571 : }
572 0 : break;
573 : case NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize:
574 : case NS_ooxml::LN_CT_TblPrBase_tblStyleColBandSize:
575 : {
576 0 : StyleSheetEntry* pEntry = m_pImpl->m_pCurrentEntry.get( );
577 0 : TableStyleSheetEntry *pTEntry = static_cast<TableStyleSheetEntry*>( pEntry );
578 0 : if ( pTEntry )
579 : {
580 0 : if ( nSprmId == NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize )
581 0 : pTEntry->m_nRowBandSize = nIntValue;
582 : else
583 0 : pTEntry->m_nColBandSize = nIntValue;
584 : }
585 : }
586 0 : break;
587 : case NS_ooxml::LN_CT_TblPrBase_tblCellMar:
588 : //no cell margins in styles
589 0 : break;
590 : case NS_ooxml::LN_CT_Style_pPr:
591 : // no break
592 : case NS_ooxml::LN_CT_Style_rPr:
593 : // no break
594 : default:
595 : {
596 3600 : if (!m_pImpl->m_pCurrentEntry)
597 0 : break;
598 :
599 3600 : TablePropertiesHandlerPtr pTblHandler( new TablePropertiesHandler( true ) );
600 3600 : pTblHandler->SetProperties( m_pImpl->m_pCurrentEntry->pProperties );
601 3600 : if ( !pTblHandler->sprm( rSprm ) )
602 : {
603 3600 : m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pCurrentEntry->pProperties );
604 :
605 3600 : PropertyMapPtr pProps(new PropertyMap());
606 3600 : bool bTableStyleRunProps = m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE && nSprmId == NS_ooxml::LN_CT_Style_rPr;
607 3600 : if (bTableStyleRunProps)
608 7 : m_pImpl->m_rDMapper.setInTableStyleRunProps(true);
609 3600 : m_pImpl->m_rDMapper.sprmWithProps( rSprm, pProps );
610 3600 : if (bTableStyleRunProps)
611 7 : m_pImpl->m_rDMapper.setInTableStyleRunProps(false);
612 :
613 3600 : m_pImpl->m_pCurrentEntry->pProperties->InsertProps(pProps);
614 :
615 3600 : m_pImpl->m_rDMapper.PopStyleSheetProperties( );
616 3600 : }
617 : }
618 3600 : break;
619 10159 : }
620 10159 : }
621 :
622 :
623 2024 : void StyleSheetTable::lcl_entry(int /*pos*/, writerfilter::Reference<Properties>::Pointer_t ref)
624 : {
625 : //create a new style entry
626 : OSL_ENSURE( !m_pImpl->m_pCurrentEntry, "current entry has to be NULL here");
627 2024 : StyleSheetEntryPtr pNewEntry( new StyleSheetEntry );
628 2024 : m_pImpl->m_pCurrentEntry = pNewEntry;
629 2024 : m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pCurrentEntry->pProperties );
630 2024 : ref->resolve(*this);
631 : //append it to the table
632 2024 : m_pImpl->m_rDMapper.PopStyleSheetProperties();
633 2024 : if( !m_pImpl->m_rDMapper.IsOOXMLImport() || !m_pImpl->m_pCurrentEntry->sStyleName.isEmpty())
634 : {
635 1934 : m_pImpl->m_pCurrentEntry->sConvertedStyleName = ConvertStyleName( m_pImpl->m_pCurrentEntry->sStyleName );
636 1934 : m_pImpl->m_aStyleSheetEntries.push_back( m_pImpl->m_pCurrentEntry );
637 : }
638 : else
639 : {
640 : //TODO: this entry contains the default settings - they have to be added to the settings
641 : }
642 :
643 4048 : StyleSheetEntryPtr pEmptyEntry;
644 4048 : m_pImpl->m_pCurrentEntry = pEmptyEntry;
645 2024 : }
646 : /*-------------------------------------------------------------------------
647 : sorting helper
648 : -----------------------------------------------------------------------*/
649 : typedef std::vector< beans::PropertyValue > _PropValVector;
650 1463 : class PropValVector : public _PropValVector
651 : {
652 : public:
653 1463 : PropValVector(){}
654 :
655 : void Insert( beans::PropertyValue aVal );
656 : uno::Sequence< uno::Any > getValues();
657 : uno::Sequence< OUString > getNames();
658 : };
659 11672 : void PropValVector::Insert( beans::PropertyValue aVal )
660 : {
661 11672 : _PropValVector::iterator aIt = begin();
662 79149 : while(aIt != end())
663 : {
664 57363 : if(aIt->Name > aVal.Name)
665 : {
666 1558 : insert( aIt, aVal );
667 13230 : return;
668 : }
669 55805 : ++aIt;
670 : }
671 10114 : push_back( aVal );
672 : }
673 1463 : uno::Sequence< uno::Any > PropValVector::getValues()
674 : {
675 1463 : uno::Sequence< uno::Any > aRet( size() );
676 1463 : uno::Any* pValues = aRet.getArray();
677 1463 : sal_Int32 nVal = 0;
678 1463 : _PropValVector::iterator aIt = begin();
679 14598 : while(aIt != end())
680 : {
681 11672 : pValues[nVal++] = aIt->Value;
682 11672 : ++aIt;
683 : }
684 1463 : return aRet;
685 : }
686 1463 : uno::Sequence< OUString > PropValVector::getNames()
687 : {
688 1463 : uno::Sequence< OUString > aRet( size() );
689 1463 : OUString* pNames = aRet.getArray();
690 1463 : sal_Int32 nVal = 0;
691 1463 : _PropValVector::iterator aIt = begin();
692 14598 : while(aIt != end())
693 : {
694 11672 : pNames[nVal++] = aIt->Name;
695 11672 : ++aIt;
696 : }
697 1463 : return aRet;
698 : }
699 :
700 :
701 226 : void StyleSheetTable::ApplyStyleSheets( FontTablePtr rFontTable )
702 : {
703 : try
704 : {
705 226 : uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
706 440 : uno::Reference< lang::XMultiServiceFactory > xDocFactory( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
707 440 : uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
708 440 : uno::Reference<container::XNameContainer> xCharStyles;
709 440 : uno::Reference<container::XNameContainer> xParaStyles;
710 :
711 220 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
712 220 : xStyleFamilies->getByName(rPropNameSupplier.GetName( PROP_CHARACTER_STYLES )) >>= xCharStyles;
713 220 : xStyleFamilies->getByName(rPropNameSupplier.GetName( PROP_PARAGRAPH_STYLES )) >>= xParaStyles;
714 220 : if(xCharStyles.is() && xParaStyles.is())
715 : {
716 220 : std::vector< StyleSheetEntryPtr >::iterator aIt = m_pImpl->m_aStyleSheetEntries.begin();
717 2294 : while( aIt != m_pImpl->m_aStyleSheetEntries.end() )
718 : {
719 1855 : StyleSheetEntryPtr pEntry = *aIt;
720 1855 : if( pEntry->nStyleTypeCode == STYLE_TYPE_CHAR || pEntry->nStyleTypeCode == STYLE_TYPE_PARA )
721 : {
722 1652 : bool bParaStyle = pEntry->nStyleTypeCode == STYLE_TYPE_PARA;
723 1652 : bool bInsert = false;
724 1652 : uno::Reference< container::XNameContainer > xStyles = bParaStyle ? xParaStyles : xCharStyles;
725 3304 : uno::Reference< style::XStyle > xStyle;
726 3304 : OUString sConvertedStyleName = ConvertStyleName( pEntry->sStyleName );
727 : // When pasting, don't update existing styles.
728 1652 : if(xStyles->hasByName( sConvertedStyleName ) && m_pImpl->m_bIsNewDoc)
729 1083 : xStyles->getByName( sConvertedStyleName ) >>= xStyle;
730 : else
731 : {
732 569 : bInsert = true;
733 1707 : xStyle = uno::Reference< style::XStyle >(xDocFactory->createInstance(
734 : bParaStyle ?
735 : rPropNameSupplier.GetName( PROP_SERVICE_PARA_STYLE ) :
736 569 : rPropNameSupplier.GetName( PROP_SERVICE_CHAR_STYLE )),
737 569 : uno::UNO_QUERY_THROW);
738 : }
739 1652 : if( !pEntry->sBaseStyleIdentifier.isEmpty() )
740 : {
741 : try
742 : {
743 : //TODO: Handle cases where a paragraph <> character style relation is needed
744 1283 : StyleSheetEntryPtr pParent = FindStyleSheetByISTD( pEntry->sBaseStyleIdentifier );
745 1283 : if (pParent.get() != NULL)
746 1271 : xStyle->setParentStyle(ConvertStyleName( pParent->sStyleName ));
747 : }
748 0 : catch( const uno::RuntimeException& )
749 : {
750 : OSL_FAIL( "Styles parent could not be set");
751 : }
752 : }
753 369 : else if( bParaStyle )
754 : {
755 : //now it's time to set the default parameters - for paragraph styles
756 : //Fonts: Western first entry in font table
757 : //CJK: second entry
758 : //CTL: third entry, if it exists
759 :
760 221 : sal_uInt32 nFontCount = rFontTable->size();
761 221 : if( !m_pImpl->m_rDMapper.IsOOXMLImport() && nFontCount > 2 )
762 : {
763 44 : uno::Any aTwoHundredFortyTwip = uno::makeAny(12.);
764 : // font size to 240 twip (12 pts) for all if not set
765 44 : pEntry->pProperties->Insert(PROP_CHAR_HEIGHT, aTwoHundredFortyTwip, false);
766 : // western font not already set -> apply first font
767 88 : const FontEntry::Pointer_t pWesternFontEntry(rFontTable->getFontEntry( 0 ));
768 88 : OUString sWesternFontName = pWesternFontEntry->sFontName;
769 44 : pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( sWesternFontName ), false);
770 :
771 : // CJK ... apply second font
772 88 : const FontEntry::Pointer_t pCJKFontEntry(rFontTable->getFontEntry( 2 ));
773 44 : pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME_ASIAN, uno::makeAny( pCJKFontEntry->sFontName ), false);
774 44 : pEntry->pProperties->Insert(PROP_CHAR_HEIGHT_ASIAN, aTwoHundredFortyTwip, false);
775 : // CTL ... apply third font, if available
776 44 : if( nFontCount > 3 )
777 : {
778 44 : const FontEntry::Pointer_t pCTLFontEntry(rFontTable->getFontEntry( 3 ));
779 44 : pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME_COMPLEX, uno::makeAny( pCTLFontEntry->sFontName ), false);
780 44 : pEntry->pProperties->Insert(PROP_CHAR_HEIGHT_COMPLEX, aTwoHundredFortyTwip, false);
781 44 : }
782 : }
783 : // Widow/Orphan -> set both to two if not already set
784 221 : uno::Any aTwo = uno::makeAny(sal_Int8(2));
785 221 : pEntry->pProperties->Insert(PROP_PARA_WIDOWS, aTwo, false);
786 221 : pEntry->pProperties->Insert(PROP_PARA_ORPHANS, aTwo, false);
787 : // Left-to-right direction if not already set
788 221 : pEntry->pProperties->Insert(PROP_WRITING_MODE, uno::makeAny( sal_Int16(text::WritingMode_LR_TB) ), false);
789 : // Don't set font color to Auto if not already set: this could hide the default font color setting
790 : }
791 :
792 3304 : uno::Sequence< beans::PropertyValue > aPropValues = pEntry->pProperties->GetPropertyValues();
793 1652 : bool bAddFollowStyle = false;
794 1652 : if(bParaStyle && pEntry->sNextStyleIdentifier.isEmpty() )
795 : {
796 315 : bAddFollowStyle = true;
797 : }
798 : //remove Left/RightMargin values from TOX heading styles
799 1652 : if( bParaStyle )
800 : {
801 : // Set the outline levels
802 1211 : const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast<const StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : 0);
803 1211 : if ( pStyleSheetProperties )
804 : {
805 1211 : aPropValues.realloc( aPropValues.getLength( ) + 1 );
806 :
807 1211 : beans::PropertyValue aLvlVal( rPropNameSupplier.GetName( PROP_OUTLINE_LEVEL ), 0,
808 1211 : uno::makeAny( sal_Int16( pStyleSheetProperties->GetOutlineLevel( ) + 1 ) ),
809 3633 : beans::PropertyState_DIRECT_VALUE );
810 1211 : aPropValues[ aPropValues.getLength( ) - 1 ] = aLvlVal;
811 :
812 1211 : if ( pStyleSheetProperties->GetOutlineLevel( ) == 0 )
813 : {
814 21 : aPropValues.realloc( aPropValues.getLength( ) + 1 );
815 21 : beans::PropertyValue aStyleVal( rPropNameSupplier.GetName( PROP_NUMBERING_STYLE_NAME ), 0,
816 : uno::makeAny( OUString() ),
817 42 : beans::PropertyState_DIRECT_VALUE );
818 21 : aPropValues[ aPropValues.getLength( ) - 1 ] = aStyleVal;
819 1211 : }
820 : }
821 :
822 1211 : uno::Reference< beans::XPropertyState >xState( xStyle, uno::UNO_QUERY_THROW );
823 3632 : if( sConvertedStyleName == "Contents Heading" ||
824 2421 : sConvertedStyleName == "User Index Heading" ||
825 1210 : sConvertedStyleName == "Index Heading" )
826 : {
827 : //left margin is set to NULL by default
828 1 : uno::Reference< beans::XPropertyState >xState1( xStyle, uno::UNO_QUERY_THROW );
829 1 : xState1->setPropertyToDefault(rPropNameSupplier.GetName( PROP_PARA_LEFT_MARGIN ));
830 : }
831 1210 : else if ( sConvertedStyleName == "Text body" )
832 31 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_PARA_BOTTOM_MARGIN ));
833 3518 : else if( sConvertedStyleName == "Heading 1" ||
834 2305 : sConvertedStyleName == "Heading 2" ||
835 2276 : sConvertedStyleName == "Heading 3" ||
836 2252 : sConvertedStyleName == "Heading 4" ||
837 2235 : sConvertedStyleName == "Heading 5" ||
838 2221 : sConvertedStyleName == "Heading 6" ||
839 2208 : sConvertedStyleName == "Heading 7" ||
840 3376 : sConvertedStyleName == "Heading 8" ||
841 1096 : sConvertedStyleName == "Heading 9" )
842 : {
843 88 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_WEIGHT ));
844 88 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_WEIGHT_ASIAN ));
845 88 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_WEIGHT_COMPLEX ));
846 88 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_POSTURE ));
847 88 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_POSTURE_ASIAN ));
848 88 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_POSTURE_COMPLEX ));
849 88 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_PROP_HEIGHT ));
850 88 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_PROP_HEIGHT_ASIAN ));
851 88 : xState->setPropertyToDefault(rPropNameSupplier.GetName( PROP_CHAR_PROP_HEIGHT_COMPLEX));
852 : }
853 1091 : else if (sConvertedStyleName == "Title" || sConvertedStyleName == "Subtitle")
854 : {
855 : //set the default adjust for ParaStyle Title and Subtitle to left
856 : try
857 : {
858 18 : uno::Reference< beans::XPropertySet > xProp( xStyle, uno::UNO_QUERY );
859 18 : if( xProp.is() )
860 : {
861 18 : uno::Any aMSDefaultVal = uno::makeAny( (sal_Int16)style::ParagraphAdjust_LEFT );
862 18 : xProp->setPropertyValue( rPropNameSupplier.GetName( PROP_PARA_ADJUST), aMSDefaultVal );
863 18 : }
864 : }
865 0 : catch(...)
866 : {
867 : OSL_ENSURE( false, "Default ParaAdjust style property could not be set");
868 : }
869 1211 : }
870 : }
871 :
872 1652 : if(bAddFollowStyle || aPropValues.getLength())
873 : {
874 1463 : PropValVector aSortedPropVals;
875 13135 : for( sal_Int32 nProp = 0; nProp < aPropValues.getLength(); ++nProp)
876 : {
877 : // Don't add the style name properties
878 11672 : bool bIsParaStyleName = aPropValues[nProp].Name == "ParaStyleName";
879 11672 : bool bIsCharStyleName = aPropValues[nProp].Name == "CharStyleName";
880 11672 : if ( !bIsParaStyleName && !bIsCharStyleName )
881 : {
882 11672 : aSortedPropVals.Insert( aPropValues[nProp] );
883 : }
884 : }
885 1463 : if(bAddFollowStyle)
886 : {
887 : //find the name of the Next style
888 315 : std::vector< StyleSheetEntryPtr >::iterator aNextStyleIt = m_pImpl->m_aStyleSheetEntries.begin();
889 8908 : for( ; aNextStyleIt != m_pImpl->m_aStyleSheetEntries.end(); ++aNextStyleIt )
890 : {
891 17186 : if( !( *aNextStyleIt )->sStyleName.isEmpty() &&
892 8593 : ( *aNextStyleIt )->sStyleName == pEntry->sNextStyleIdentifier)
893 : {
894 0 : beans::PropertyValue aNew;
895 0 : aNew.Name = "FollowStyle";
896 0 : aNew.Value = uno::makeAny(ConvertStyleName( ( *aNextStyleIt )->sStyleIdentifierD ));
897 0 : aSortedPropVals.Insert( aNew );
898 0 : break;
899 : }
900 : }
901 : }
902 :
903 : try
904 : {
905 1463 : uno::Reference< beans::XMultiPropertySet > xMultiPropertySet( xStyle, uno::UNO_QUERY_THROW);
906 1463 : xMultiPropertySet->setPropertyValues( aSortedPropVals.getNames(), aSortedPropVals.getValues() );
907 : }
908 0 : catch( const lang::WrappedTargetException& rWrapped)
909 : {
910 : (void) rWrapped;
911 0 : OString aMessage("Some style properties could not be set");
912 : #if OSL_DEBUG_LEVEL > 0
913 : beans::UnknownPropertyException aUnknownPropertyException;
914 :
915 : if( rWrapped.TargetException >>= aUnknownPropertyException )
916 : {
917 : aMessage += ": ";
918 : OString sTemp;
919 : aUnknownPropertyException.Message.convertToString(&sTemp, RTL_TEXTENCODING_ASCII_US, 0 );
920 : aMessage += sTemp;
921 : }
922 : #endif
923 0 : SAL_WARN("writerfilter", aMessage.getStr());
924 : }
925 0 : catch( const uno::Exception& rEx)
926 : {
927 : (void) rEx;
928 : OSL_FAIL( "Some style properties could not be set");
929 1463 : }
930 : }
931 1652 : if(bInsert)
932 : {
933 570 : xStyles->insertByName( sConvertedStyleName, uno::makeAny( xStyle) );
934 1652 : }
935 : }
936 1854 : ++aIt;
937 1855 : }
938 220 : }
939 : }
940 7 : catch( const uno::Exception& )
941 : {
942 : OSL_FAIL( "Styles could not be imported completely");
943 : }
944 226 : }
945 :
946 :
947 3089 : const StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByISTD(const OUString& sIndex)
948 : {
949 3089 : StyleSheetEntryPtr pRet;
950 14133 : for( sal_uInt32 nPos = 0; nPos < m_pImpl->m_aStyleSheetEntries.size(); ++nPos )
951 : {
952 13688 : if( m_pImpl->m_aStyleSheetEntries[nPos]->sStyleIdentifierD == sIndex)
953 : {
954 2644 : pRet = m_pImpl->m_aStyleSheetEntries[nPos];
955 2644 : break;
956 : }
957 : }
958 3089 : return pRet;
959 : }
960 :
961 :
962 24 : const StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByStyleName(const OUString& sIndex)
963 : {
964 24 : StyleSheetEntryPtr pRet;
965 246 : for( sal_uInt32 nPos = 0; nPos < m_pImpl->m_aStyleSheetEntries.size(); ++nPos )
966 : {
967 237 : if( m_pImpl->m_aStyleSheetEntries[nPos]->sStyleName == sIndex)
968 : {
969 15 : pRet = m_pImpl->m_aStyleSheetEntries[nPos];
970 15 : break;
971 : }
972 : }
973 24 : return pRet;
974 : }
975 :
976 :
977 15 : const StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByConvertedStyleName(const OUString& sIndex)
978 : {
979 15 : StyleSheetEntryPtr pRet;
980 15 : for( sal_uInt32 nPos = 0; nPos < m_pImpl->m_aStyleSheetEntries.size(); ++nPos )
981 : {
982 0 : if( m_pImpl->m_aStyleSheetEntries[nPos]->sConvertedStyleName == sIndex)
983 : {
984 0 : pRet = m_pImpl->m_aStyleSheetEntries[nPos];
985 0 : break;
986 : }
987 : }
988 15 : return pRet;
989 : }
990 :
991 :
992 :
993 223 : const StyleSheetEntryPtr StyleSheetTable::FindParentStyleSheet(OUString sBaseStyle)
994 : {
995 223 : if( sBaseStyle.isEmpty() )
996 : {
997 4 : StyleSheetEntryPtr pEmptyPtr;
998 4 : return pEmptyPtr;
999 : }
1000 219 : if( m_pImpl->m_pCurrentEntry)
1001 0 : sBaseStyle = m_pImpl->m_pCurrentEntry->sBaseStyleIdentifier;
1002 :
1003 219 : return FindStyleSheetByISTD( sBaseStyle );
1004 : }
1005 :
1006 :
1007 : static const sal_Char* const aStyleNamePairs[] =
1008 : {
1009 : "Normal", "Standard",
1010 : "heading 1", "Heading 1",
1011 : "heading 2", "Heading 2",
1012 : "heading 3", "Heading 3",
1013 : "heading 4", "Heading 4",
1014 : "heading 5", "Heading 5",
1015 : "heading 6", "Heading 6",
1016 : "heading 7", "Heading 7",
1017 : "heading 8", "Heading 8",
1018 : "heading 9", "Heading 9",
1019 : "Heading1", "Heading 1",
1020 : "Heading2", "Heading 2",
1021 : "Heading3", "Heading 3",
1022 : "Heading4", "Heading 4",
1023 : "Heading5", "Heading 5",
1024 : "Heading6", "Heading 6",
1025 : "Heading7", "Heading 7",
1026 : "Heading8", "Heading 8",
1027 : "Heading9", "Heading 9",
1028 : "Heading 1", "Heading 1",
1029 : "Heading 2", "Heading 2",
1030 : "Heading 3", "Heading 3",
1031 : "Heading 4", "Heading 4",
1032 : "Heading 5", "Heading 5",
1033 : "Heading 6", "Heading 6",
1034 : "Heading 7", "Heading 7",
1035 : "Heading 8", "Heading 8",
1036 : "Heading 9", "Heading 9",
1037 : "Index 1", "Index 1",
1038 : "Index 2", "Index 2",
1039 : "Index 3", "Index 3",
1040 : "Index 4", "",
1041 : "Index 5", "",
1042 : "Index 6", "",
1043 : "Index 7", "",
1044 : "Index 8", "",
1045 : "Index 9", "",
1046 : "TOC 1", "Contents 1",
1047 : "TOC 2", "Contents 2",
1048 : "TOC 3", "Contents 3",
1049 : "TOC 4", "Contents 4",
1050 : "TOC 5", "Contents 5",
1051 : "TOC 6", "Contents 6",
1052 : "TOC 7", "Contents 7",
1053 : "TOC 8", "Contents 8",
1054 : "TOC 9", "Contents 9",
1055 : "TOC Heading", "Contents Heading",
1056 : "TOCHeading", "Contents Heading",
1057 : "toc 1", "Contents 1",
1058 : "toc 2", "Contents 2",
1059 : "toc 3", "Contents 3",
1060 : "toc 4", "Contents 4",
1061 : "toc 5", "Contents 5",
1062 : "toc 6", "Contents 6",
1063 : "toc 7", "Contents 7",
1064 : "toc 8", "Contents 8",
1065 : "toc 9", "Contents 9",
1066 : "TOC1", "Contents 1",
1067 : "TOC2", "Contents 2",
1068 : "TOC3", "Contents 3",
1069 : "TOC4", "Contents 4",
1070 : "TOC5", "Contents 5",
1071 : "TOC6", "Contents 6",
1072 : "TOC7", "Contents 7",
1073 : "TOC8", "Contents 8",
1074 : "TOC9", "Contents 9",
1075 : "Normal Indent", "",
1076 : "Footnote Text", "Footnote",
1077 : "Annotation Text", "",
1078 : "Header", "Header",
1079 : "header", "Header",
1080 : "Footer", "Footer",
1081 : "footer", "Footer",
1082 : "Index Heading", "Index Heading",
1083 : "Caption", "",
1084 : "Table of Figures", "",
1085 : "Envelope Address", "Addressee",
1086 : "Envelope Return", "Sender",
1087 : "Footnote Reference", "Footnote anchor",
1088 : "Annotation Reference", "",
1089 : "Line Number", "Line numbering",
1090 : "Page Number", "Page Number",
1091 : "Endnote Reference", "Endnote anchor",
1092 : "Endnote Text", "Endnote Symbol",
1093 : "Table of Authorities", "",
1094 : "Macro Text", "",
1095 : "TOA Heading", "",
1096 : "List", "List",
1097 : "List 2", "",
1098 : "List 3", "",
1099 : "List 4", "",
1100 : "List 5", "",
1101 : "List Bullet", "",
1102 : "List Bullet 2", "",
1103 : "List Bullet 3", "",
1104 : "List Bullet 4", "",
1105 : "List Bullet 5", "",
1106 : "List Number", "",
1107 : "List Number 2", "",
1108 : "List Number 3", "",
1109 : "List Number 4", "",
1110 : "List Number 5", "",
1111 : "Title", "Title",
1112 : "Closing", "",
1113 : "Signature", "Signature",
1114 : "Default Paragraph Font", "",
1115 : "DefaultParagraphFont", "Default Paragraph Font",
1116 : "Body Text", "Text body",
1117 : "BodyText", "Text body",
1118 : "BodyTextIndentItalic", "Text body indent italic",
1119 : "Body Text Indent", "Text body indent",
1120 : "BodyTextIndent", "Text body indent",
1121 : "BodyTextIndent2", "Text body indent2",
1122 : "List Continue", "",
1123 : "List Continue 2", "",
1124 : "List Continue 3", "",
1125 : "List Continue 4", "",
1126 : "List Continue 5", "",
1127 : "Message Header", "",
1128 : "Subtitle", "Subtitle",
1129 : "Salutation", "",
1130 : "Date", "",
1131 : "Body Text First Indent", "Body Text Indent",
1132 : "Body Text First Indent 2", "",
1133 : "Note Heading", "",
1134 : "Body Text 2", "",
1135 : "Body Text 3", "",
1136 : "Body Text Indent 2", "",
1137 : "Body Text Indent 3", "",
1138 : "Block Text", "",
1139 : "Hyperlink", "Internet link",
1140 : "Followed Hyperlink", "Visited Internet Link",
1141 : "Strong", "Strong Emphasis",
1142 : "Emphasis", "Emphasis",
1143 : "Document Map", "",
1144 : "Plain Text", "",
1145 : "NoList", "No List",
1146 : "AbstractHeading", "Abstract Heading",
1147 : "AbstractBody", "Abstract Body",
1148 : "PageNumber", "page number"
1149 : "TableNormal", "Normal Table",
1150 : "DocumentMap", "Document Map"
1151 : };
1152 :
1153 :
1154 5666 : OUString StyleSheetTable::ConvertStyleName( const OUString& rWWName, bool bExtendedSearch)
1155 : {
1156 5666 : OUString sRet( rWWName );
1157 5666 : if( bExtendedSearch )
1158 : {
1159 : //search for the rWWName in the IdentifierD of the existing styles and convert the sStyleName member
1160 639 : std::vector< StyleSheetEntryPtr >::iterator aIt = m_pImpl->m_aStyleSheetEntries.begin();
1161 : //TODO: performance issue - put styles list into a map sorted by it's sStyleIdentifierD members
1162 11634 : while( aIt != m_pImpl->m_aStyleSheetEntries.end() )
1163 : {
1164 10356 : if( rWWName == ( *aIt )->sStyleIdentifierD )
1165 638 : sRet = ( *aIt )->sStyleName;
1166 10356 : ++aIt;
1167 : }
1168 : }
1169 5666 : if(!m_pImpl->m_aStyleNameMap.size())
1170 : {
1171 31666 : for( sal_uInt32 nPair = 0; nPair < sizeof(aStyleNamePairs) / sizeof( sal_Char*) / 2; ++nPair)
1172 : {
1173 : m_pImpl->m_aStyleNameMap.insert( StringPairMap_t::value_type(
1174 31443 : OUString::createFromAscii(aStyleNamePairs[2 * nPair]),
1175 62886 : OUString::createFromAscii(aStyleNamePairs[2 * nPair + 1]) ));
1176 : }
1177 : }
1178 5666 : StringPairMap_t::iterator aIt = m_pImpl->m_aStyleNameMap.find( sRet );
1179 5666 : if(aIt != m_pImpl->m_aStyleNameMap.end() && !aIt->second.isEmpty())
1180 2491 : sRet = aIt->second;
1181 5666 : return sRet;
1182 : }
1183 :
1184 0 : OUString StyleSheetTable::GetStyleIdFromIndex(const sal_uInt32 sti)
1185 : {
1186 0 : OUString sRet;
1187 0 : if (sti >= (sizeof(aStyleNamePairs) / sizeof( sal_Char*) / 2))
1188 0 : sRet = OUString();
1189 : else
1190 0 : sRet = OUString::createFromAscii(aStyleNamePairs[2 * sti]);
1191 0 : return sRet;
1192 : }
1193 :
1194 0 : void StyleSheetTable::resolveAttributeProperties(Value & val)
1195 : {
1196 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = val.getProperties();
1197 0 : if( pProperties.get())
1198 0 : pProperties->resolve(*this);
1199 0 : }
1200 :
1201 :
1202 180 : void StyleSheetTable::applyDefaults(bool bParaProperties)
1203 : {
1204 : try{
1205 180 : if(!m_pImpl->m_xTextDefaults.is())
1206 : {
1207 180 : m_pImpl->m_xTextDefaults = uno::Reference< beans::XPropertySet>(
1208 180 : m_pImpl->m_rDMapper.GetTextFactory()->createInstance("com.sun.star.text.Defaults"),
1209 90 : uno::UNO_QUERY_THROW );
1210 : }
1211 180 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1212 180 : if( bParaProperties && m_pImpl->m_pDefaultParaProps.get() && m_pImpl->m_pDefaultParaProps->size())
1213 : {
1214 75 : PropertyMap::iterator aMapIter = m_pImpl->m_pDefaultParaProps->begin();
1215 226 : for( ; aMapIter != m_pImpl->m_pDefaultParaProps->end(); ++aMapIter )
1216 : {
1217 : try
1218 : {
1219 151 : m_pImpl->m_xTextDefaults->setPropertyValue(rPropNameSupplier.GetName( aMapIter->first.eId ), aMapIter->second);
1220 : }
1221 0 : catch( const uno::Exception& )
1222 : {
1223 : OSL_FAIL( "setPropertyValue exception");
1224 : }
1225 : }
1226 : }
1227 180 : if( !bParaProperties && m_pImpl->m_pDefaultCharProps.get() && m_pImpl->m_pDefaultCharProps->size())
1228 : {
1229 90 : PropertyMap::iterator aMapIter = m_pImpl->m_pDefaultCharProps->begin();
1230 824 : for( ; aMapIter != m_pImpl->m_pDefaultCharProps->end(); ++aMapIter )
1231 : {
1232 : try
1233 : {
1234 734 : m_pImpl->m_xTextDefaults->setPropertyValue(rPropNameSupplier.GetName( aMapIter->first.eId ), aMapIter->second);
1235 : }
1236 0 : catch( const uno::Exception& )
1237 : {
1238 : OSL_FAIL( "setPropertyValue exception");
1239 : }
1240 : }
1241 : }
1242 : }
1243 0 : catch( const uno::Exception& )
1244 : {
1245 : }
1246 180 : }
1247 :
1248 :
1249 267 : OUString StyleSheetTable::getOrCreateCharStyle( PropertyValueVector_t& rCharProperties )
1250 : {
1251 : //find out if any of the styles already has the required properties then return it's name
1252 267 : OUString sListLabel = m_pImpl->HasListCharStyle(rCharProperties);
1253 267 : if( !sListLabel.isEmpty() )
1254 229 : return sListLabel;
1255 38 : const char cListLabel[] = "ListLabel ";
1256 76 : uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
1257 76 : uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
1258 76 : uno::Reference<container::XNameContainer> xCharStyles;
1259 38 : xStyleFamilies->getByName("CharacterStyles") >>= xCharStyles;
1260 : //search for all character styles with the name sListLabel + <index>
1261 38 : sal_Int32 nStyleFound = 0;
1262 76 : uno::Sequence< OUString > aStyleNames = xCharStyles->getElementNames();
1263 38 : const OUString* pStyleNames = aStyleNames.getConstArray();
1264 1587 : for( sal_Int32 nStyle = 0; nStyle < aStyleNames.getLength(); ++nStyle )
1265 : {
1266 1549 : if( pStyleNames[nStyle].matchAsciiL( cListLabel, sizeof( cListLabel ) - 1 ))
1267 : {
1268 51 : OUString sSuffix = pStyleNames[nStyle].copy( sizeof( cListLabel ) - 1 );
1269 51 : sal_Int32 nSuffix = sSuffix.toInt32();
1270 51 : if( nSuffix > 0 )
1271 : {
1272 51 : if( nSuffix > nStyleFound )
1273 51 : nStyleFound = nSuffix;
1274 51 : }
1275 : }
1276 : }
1277 38 : sListLabel = OUString::createFromAscii( cListLabel );
1278 38 : sListLabel += OUString::valueOf( ++nStyleFound );
1279 : //create a new one otherwise
1280 76 : uno::Reference< lang::XMultiServiceFactory > xDocFactory( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
1281 38 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1282 : try
1283 : {
1284 38 : uno::Reference< style::XStyle > xStyle( xDocFactory->createInstance(
1285 38 : rPropNameSupplier.GetName( PROP_SERVICE_CHAR_STYLE )), uno::UNO_QUERY_THROW);
1286 76 : uno::Reference< beans::XPropertySet > xStyleProps(xStyle, uno::UNO_QUERY_THROW );
1287 38 : PropertyValueVector_t::const_iterator aCharPropIter = rCharProperties.begin();
1288 166 : while( aCharPropIter != rCharProperties.end())
1289 : {
1290 : try
1291 : {
1292 90 : xStyleProps->setPropertyValue( aCharPropIter->Name, aCharPropIter->Value );
1293 : }
1294 0 : catch( const uno::Exception& rEx )
1295 : {
1296 : (void)rEx;
1297 : OSL_FAIL( "Exception in StyleSheetTable::getOrCreateCharStyle - Style::setPropertyValue");
1298 : }
1299 90 : ++aCharPropIter;
1300 : }
1301 38 : xCharStyles->insertByName( sListLabel, uno::makeAny( xStyle) );
1302 76 : m_pImpl->m_aListCharStylePropertyVector.push_back( ListCharStylePropertyMap_t( sListLabel, rCharProperties ));
1303 : }
1304 0 : catch( const uno::Exception& rEx )
1305 : {
1306 : (void)rEx;
1307 : OSL_FAIL( "Exception in StyleSheetTable::getOrCreateCharStyle");
1308 : }
1309 :
1310 38 : return sListLabel;
1311 : }
1312 :
1313 : }//namespace dmapper
1314 24 : }//namespace writerfilter
1315 :
1316 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|