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