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 <PropertyMap.hxx>
24 #include <ooxml/resourceids.hxx>
25 #include <DomainMapper_Impl.hxx>
26 #include <ConversionHelper.hxx>
27 #include <i18npool/paper.hxx>
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/table/BorderLine.hpp>
31 #include <com/sun/star/container/XEnumeration.hpp>
32 #include <com/sun/star/container/XEnumerationAccess.hpp>
33 #include <com/sun/star/container/XNameContainer.hpp>
34 #include <com/sun/star/style/BreakType.hpp>
35 #include <com/sun/star/text/RelOrientation.hpp>
36 #include <com/sun/star/text/WritingMode.hpp>
37 #include <com/sun/star/text/XTextColumns.hpp>
38 #include <com/sun/star/text/XText.hpp>
39 #include <com/sun/star/text/TextGridMode.hpp>
40 #include <com/sun/star/text/XTextCopy.hpp>
41 #include "dmapperLoggers.hxx"
42 #include "PropertyMapHelper.hxx"
43
44 using namespace ::com::sun::star;
45
46 namespace writerfilter {
47 namespace dmapper{
48
49 /*-- 21.06.2006 09:30:56---------------------------------------------------
50
51 -----------------------------------------------------------------------*/
PropertyMap()52 PropertyMap::PropertyMap() :
53 m_cFootnoteSymbol( 0 ),
54 m_nFootnoteFontId( -1 )
55 {
56 }
57 /*-- 21.06.2006 09:30:56---------------------------------------------------
58
59 -----------------------------------------------------------------------*/
~PropertyMap()60 PropertyMap::~PropertyMap()
61 {
62 }
63 /*-- 20.06.2006 10:23:55---------------------------------------------------
64
65 -----------------------------------------------------------------------*/
GetPropertyValues()66 uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues()
67 {
68 if(!m_aValues.getLength() && size())
69 {
70 m_aValues.realloc( size() );
71 ::com::sun::star::beans::PropertyValue* pValues = m_aValues.getArray();
72 //style names have to be the first elements within the property sequence
73 //otherwise they will overwrite 'hard' attributes
74 sal_Int32 nValue = 0;
75 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
76 PropertyMap::iterator aParaStyleIter = find(PropertyDefinition( PROP_PARA_STYLE_NAME, false ) );
77 if( aParaStyleIter != end())
78 {
79 pValues[nValue].Name = rPropNameSupplier.GetName( aParaStyleIter->first.eId );
80 pValues[nValue].Value = aParaStyleIter->second;
81 ++nValue;
82 }
83
84 PropertyMap::iterator aCharStyleIter = find(PropertyDefinition( PROP_CHAR_STYLE_NAME, false ));
85 if( aCharStyleIter != end())
86 {
87 pValues[nValue].Name = rPropNameSupplier.GetName( aCharStyleIter->first.eId );
88 pValues[nValue].Value = aCharStyleIter->second;
89 ++nValue;
90 }
91 PropertyMap::iterator aNumRuleIter = find(PropertyDefinition( PROP_NUMBERING_RULES, false ) );
92 if( aNumRuleIter != end())
93 {
94 pValues[nValue].Name = rPropNameSupplier.GetName( aNumRuleIter->first.eId );
95 pValues[nValue].Value = aNumRuleIter->second;
96 ++nValue;
97 }
98 PropertyMap::iterator aMapIter = begin();
99 for( ; nValue < m_aValues.getLength(); ++aMapIter )
100 {
101 if( aMapIter != aParaStyleIter && aMapIter != aCharStyleIter && aMapIter != aNumRuleIter )
102 {
103 pValues[nValue].Name = rPropNameSupplier.GetName( aMapIter->first.eId );
104 pValues[nValue].Value = aMapIter->second;
105 ++nValue;
106 }
107 }
108 }
109 return m_aValues;
110 }
111
lcl_AnyToTag(XMLTag::Pointer_t pTag,const uno::Any & rAny)112 void lcl_AnyToTag(XMLTag::Pointer_t pTag, const uno::Any & rAny)
113 {
114 try {
115 sal_Int32 aInt = 0;
116 rAny >>= aInt;
117 pTag->addAttr("value", aInt);
118
119 sal_uInt32 auInt = 0;
120 rAny >>= auInt;
121 pTag->addAttr("unsignedValue", auInt);
122
123 float aFloat = 0.0f;
124 rAny >>= aFloat;
125 pTag->addAttr("floatValue", aFloat);
126
127 ::rtl::OUString aStr;
128 rAny >>= aStr;
129 pTag->addAttr("stringValue", aStr);
130 }
131 catch (...) {
132 pTag->addAttr("exception", "true");
133 }
134 }
135
Insert(PropertyIds eId,bool bIsTextProperty,const uno::Any & rAny,bool bOverwrite)136 void PropertyMap::Insert( PropertyIds eId, bool bIsTextProperty, const uno::Any& rAny, bool bOverwrite )
137 {
138 #ifdef DEBUG_DMAPPER_PROPERTY_MAP
139 const ::rtl::OUString& rInsert = PropertyNameSupplier::
140 GetPropertyNameSupplier().GetName(eId);
141
142 XMLTag::Pointer_t pTag(new XMLTag("propertyMap.insert"));
143 pTag->addAttr("name", rInsert);
144 lcl_AnyToTag(pTag, rAny);
145
146 dmapper_logger->addTag(pTag);
147 #endif
148
149 PropertyMap::iterator aElement = find(PropertyDefinition( eId, bIsTextProperty ) );
150 if( aElement != end())
151 {
152 if(!bOverwrite)
153 return;
154 erase( aElement );
155 }
156 _PropertyMap::insert( PropertyMap::value_type
157 (PropertyDefinition( eId, bIsTextProperty),
158 rAny ));
159 Invalidate();
160 }
161
toTag() const162 XMLTag::Pointer_t PropertyMap::toTag() const
163 {
164 XMLTag::Pointer_t pResult(new XMLTag("PropertyMap"));
165
166 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
167 PropertyMap::const_iterator aMapIter = begin();
168 while (aMapIter != end())
169 {
170 XMLTag::Pointer_t pTag(new XMLTag("property"));
171
172 pTag->addAttr("name", rPropNameSupplier.GetName( aMapIter->first.eId ));
173
174 switch (aMapIter->first.eId)
175 {
176 case PROP_TABLE_COLUMN_SEPARATORS:
177 pTag->addTag(lcl_TableColumnSeparatorsToTag(aMapIter->second));
178 break;
179 default:
180 {
181 try {
182 sal_Int32 aInt = 0;
183 aMapIter->second >>= aInt;
184 pTag->addAttr("value", aInt);
185
186 sal_uInt32 auInt = 0;
187 aMapIter->second >>= auInt;
188 pTag->addAttr("unsignedValue", auInt);
189
190 float aFloat = 0.0;
191 aMapIter->second >>= aFloat;
192 pTag->addAttr("floatValue", aFloat);
193
194 ::rtl::OUString aStr;
195 aMapIter->second >>= auInt;
196 pTag->addAttr("stringValue", aStr);
197 }
198 catch (...) {
199 pTag->addAttr("exception", "true");
200 }
201 }
202 break;
203 }
204
205 pResult->addTag(pTag);
206
207 ++aMapIter;
208 }
209
210 return pResult;
211 }
212
213 /*-- 13.12.2006 10:46:42---------------------------------------------------
214
215 -----------------------------------------------------------------------*/
216 template<class T>
217 struct removeExistingElements
218 {
219 typedef T argument_type;
220 typedef void result_type;
221 PropertyMap& rMap;
222
removeExistingElementswriterfilter::dmapper::removeExistingElements223 removeExistingElements(PropertyMap& _rMap ) : rMap(_rMap) {}
operator ()writerfilter::dmapper::removeExistingElements224 void operator() (T x)
225 {
226 PropertyMap::iterator aElement = rMap.find(x.first);
227 if( aElement != rMap.end())
228 rMap.erase( aElement );
229 }
230 };
231 /*-- 13.12.2006 10:46:42---------------------------------------------------
232
233 -----------------------------------------------------------------------*/
insert(const PropertyMapPtr pMap,bool bOverwrite)234 void PropertyMap::insert( const PropertyMapPtr pMap, bool bOverwrite )
235 {
236 if( pMap.get() )
237 {
238 if( bOverwrite )
239 ::std::for_each( pMap->begin(), pMap->end(), removeExistingElements<PropertyMap::value_type>(*this) );
240 _PropertyMap::insert(pMap->begin(), pMap->end());
241 insertTableProperties(pMap.get());
242
243 Invalidate();
244 }
245 }
246 /*-- 06.06.2007 15:49:09---------------------------------------------------
247
248 -----------------------------------------------------------------------*/
GetFootnote() const249 const uno::Reference< text::XFootnote>& PropertyMap::GetFootnote() const
250 {
251 return m_xFootnote;
252 }
253 /*-- 18.02.2008 11:23:28---------------------------------------------------
254
255 -----------------------------------------------------------------------*/
insertTableProperties(const PropertyMap *)256 void PropertyMap::insertTableProperties( const PropertyMap* )
257 {
258 #ifdef DEBUG_DMAPPER_PROPERTY_MAP
259 dmapper_logger->element("PropertyMap.insertTableProperties");
260 #endif
261 }
262 /*-- 24.07.2006 08:29:01---------------------------------------------------
263
264 -----------------------------------------------------------------------*/
SectionPropertyMap(bool bIsFirstSection)265 SectionPropertyMap::SectionPropertyMap(bool bIsFirstSection) :
266 m_bIsFirstSection( bIsFirstSection )
267 ,m_nBorderParams( 0 )
268 ,m_bTitlePage( false )
269 ,m_nColumnCount( 0 )
270 ,m_nColumnDistance( 1249 )
271 ,m_bSeparatorLineIsOn( false )
272 ,m_bEvenlySpaced( false )
273 ,m_bIsLandscape( false )
274 ,m_bPageNoRestart( false )
275 ,m_nPageNumber( -1 )
276 ,m_nBreakType( -1 )
277 ,m_nPaperBin( -1 )
278 ,m_nFirstPaperBin( -1 )
279 ,m_nLeftMargin( 3175 ) //page left margin, default 0x708 (1800) twip -> 3175 1/100 mm
280 ,m_nRightMargin( 3175 )//page right margin, default 0x708 (1800) twip -> 3175 1/100 mm
281 ,m_nTopMargin( 2540 )
282 ,m_nBottomMargin( 2540 )
283 ,m_nHeaderTop( 1270 ) //720 twip
284 ,m_nHeaderBottom( 1270 )//720 twip
285 ,m_nDzaGutter( 0 )
286 ,m_bGutterRTL( false )
287 ,m_bSFBiDi( false )
288 ,m_nGridType(0)
289 ,m_nGridLinePitch( 1 )
290 ,m_nDxtCharSpace( 0 )
291 ,m_nLnnMod( 0 )
292 ,m_nLnc( 0 )
293 ,m_ndxaLnn( 0 )
294 ,m_nLnnMin( 0 )
295 {
296 static sal_Int32 nNumber = 0;
297 nSectionNumber = nNumber++;
298 memset(&m_pBorderLines, 0x00, sizeof(m_pBorderLines));
299 for( sal_Int32 nBorder = 0; nBorder < 4; ++nBorder )
300 m_nBorderDistances[ nBorder ] = -1;
301 //todo: set defaults in ApplyPropertiesToPageStyles
302 //initialize defaults
303 PaperInfo aLetter(PAPER_LETTER);
304 //page height, 1/100mm
305 Insert( PROP_HEIGHT, false, uno::makeAny( (sal_Int32) aLetter.getHeight() ) );
306 //page width, 1/100mm
307 Insert( PROP_WIDTH, false, uno::makeAny( (sal_Int32) aLetter.getWidth() ) );
308 //page left margin, default 0x708 (1800) twip -> 3175 1/100 mm
309 Insert( PROP_LEFT_MARGIN, false, uno::makeAny( (sal_Int32) 3175 ) );
310 //page right margin, default 0x708 (1800) twip -> 3175 1/100 mm
311 Insert( PROP_RIGHT_MARGIN, false, uno::makeAny( (sal_Int32) 3175 ) );
312 //page top margin, default 0x5a0 (1440) twip -> 2540 1/100 mm
313 Insert( PROP_TOP_MARGIN, false, uno::makeAny( (sal_Int32)2540 ) );
314 //page bottom margin, default 0x5a0 (1440) twip -> 2540 1/100 mm
315 Insert( PROP_BOTTOM_MARGIN, false, uno::makeAny( (sal_Int32) 2540 ) );
316 uno::Any aFalse( ::uno::makeAny( false ) );
317 Insert( PROP_GRID_DISPLAY, false, aFalse);
318 Insert( PROP_GRID_PRINT, false, aFalse);
319 Insert( PROP_GRID_MODE, false, uno::makeAny(text::TextGridMode::NONE));
320
321
322 if( m_bIsFirstSection )
323 {
324 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
325 m_sFirstPageStyleName = rPropNameSupplier.GetName( PROP_FIRST_PAGE );
326 m_sFollowPageStyleName = rPropNameSupplier.GetName( PROP_STANDARD );
327 }
328 }
329 /*-- 24.07.2006 08:29:02---------------------------------------------------
330
331 -----------------------------------------------------------------------*/
~SectionPropertyMap()332 SectionPropertyMap::~SectionPropertyMap()
333 {
334 for( sal_Int16 ePos = BORDER_LEFT; ePos <= BORDER_BOTTOM; ++ePos)
335 delete m_pBorderLines[ePos];
336 }
337 /*-- 24.07.2006 08:31:07---------------------------------------------------
338
339 -----------------------------------------------------------------------*/
GetPageStyleName(bool bFirst)340 const ::rtl::OUString& SectionPropertyMap::GetPageStyleName( bool bFirst )
341 {
342 return bFirst ? m_sFirstPageStyleName : m_sFollowPageStyleName;
343 }
344 /*-- 24.07.2006 08:31:07---------------------------------------------------
345
346 -----------------------------------------------------------------------*/
SetPageStyleName(bool bFirst,const::rtl::OUString & rName)347 void SectionPropertyMap::SetPageStyleName( bool bFirst, const ::rtl::OUString& rName)
348 {
349 if( bFirst )
350 m_sFirstPageStyleName = rName;
351 else
352 m_sFollowPageStyleName = rName;
353 }
354 /*-- 24.07.2006 09:41:20---------------------------------------------------
355
356 -----------------------------------------------------------------------*/
lcl_FindUnusedPageStyleName(const uno::Sequence<::rtl::OUString> & rPageStyleNames)357 ::rtl::OUString lcl_FindUnusedPageStyleName(const uno::Sequence< ::rtl::OUString >& rPageStyleNames)
358 {
359 static const sal_Char cDefaultStyle[] = "Converted";
360 //find the hightest number x in each style with the name "cDefaultStyle+x" and
361 //return an incremented name
362 sal_Int32 nMaxIndex = 0;
363 const sal_Int32 nDefaultLength = sizeof(cDefaultStyle)/sizeof(sal_Char) - 1;
364 const ::rtl::OUString sDefaultStyle( cDefaultStyle, nDefaultLength, RTL_TEXTENCODING_ASCII_US );
365
366 const ::rtl::OUString* pStyleNames = rPageStyleNames.getConstArray();
367 for( sal_Int32 nStyle = 0; nStyle < rPageStyleNames.getLength(); ++nStyle)
368 {
369 if( pStyleNames[nStyle].getLength() > nDefaultLength &&
370 !rtl_ustr_compare_WithLength( sDefaultStyle.getStr(), nDefaultLength, pStyleNames[nStyle].getStr(), nDefaultLength))
371 {
372 sal_Int32 nIndex = pStyleNames[nStyle].copy( nDefaultLength ).toInt32();
373 if( nIndex > nMaxIndex)
374 nMaxIndex = nIndex;
375 }
376 }
377 ::rtl::OUString sRet( sDefaultStyle );
378 sRet += rtl::OUString::valueOf( nMaxIndex + 1);
379 return sRet;
380 }
381
382 /*-- 28.07.2006 13:00:43---------------------------------------------------
383
384 -----------------------------------------------------------------------*/
GetPageStyle(const uno::Reference<container::XNameContainer> & xPageStyles,const uno::Reference<lang::XMultiServiceFactory> & xTextFactory,bool bFirst)385 uno::Reference< beans::XPropertySet > SectionPropertyMap::GetPageStyle(
386 const uno::Reference< container::XNameContainer >& xPageStyles,
387 const uno::Reference < lang::XMultiServiceFactory >& xTextFactory,
388 bool bFirst )
389 {
390 uno::Reference< beans::XPropertySet > xRet;
391 try
392 {
393 if( bFirst )
394 {
395 if( !m_sFirstPageStyleName.getLength() )
396 {
397 uno::Sequence< ::rtl::OUString > aPageStyleNames = xPageStyles->getElementNames();
398 m_sFirstPageStyleName = lcl_FindUnusedPageStyleName(aPageStyleNames);
399 m_aFirstPageStyle = uno::Reference< beans::XPropertySet > (
400 xTextFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.PageStyle") )),
401 uno::UNO_QUERY);
402 xPageStyles->insertByName( m_sFirstPageStyleName, uno::makeAny(m_aFirstPageStyle) );
403 }
404 else if( !m_aFirstPageStyle.is() )
405 {
406 xPageStyles->getByName(m_sFirstPageStyleName) >>= m_aFirstPageStyle;
407 }
408 xRet = m_aFirstPageStyle;
409 }
410 else
411 {
412 if( !m_sFollowPageStyleName.getLength() )
413 {
414 uno::Sequence< ::rtl::OUString > aPageStyleNames = xPageStyles->getElementNames();
415 m_sFollowPageStyleName = lcl_FindUnusedPageStyleName(aPageStyleNames);
416 m_aFollowPageStyle = uno::Reference< beans::XPropertySet > (
417 xTextFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.PageStyle") )),
418 uno::UNO_QUERY);
419 xPageStyles->insertByName( m_sFollowPageStyleName, uno::makeAny(m_aFollowPageStyle) );
420 }
421 else if(!m_aFollowPageStyle.is() )
422 {
423 xPageStyles->getByName(m_sFollowPageStyleName) >>= m_aFollowPageStyle;
424 }
425 xRet = m_aFollowPageStyle;
426 }
427
428 }
429 catch( const uno::Exception& e)
430 {
431 (void) e;
432 }
433
434 return xRet;
435 }
436 /*-- 28.07.2006 10:56:26---------------------------------------------------
437
438 -----------------------------------------------------------------------*/
SetBorder(BorderPosition ePos,sal_Int32 nLineDistance,const table::BorderLine & rBorderLine)439 void SectionPropertyMap::SetBorder( BorderPosition ePos, sal_Int32 nLineDistance, const table::BorderLine& rBorderLine )
440 {
441 delete m_pBorderLines[ePos];
442 m_pBorderLines[ePos] = new table::BorderLine( rBorderLine );
443 m_nBorderDistances[ePos] = nLineDistance;
444 }
445 /*-- 28.07.2006 10:56:27---------------------------------------------------
446
447 -----------------------------------------------------------------------*/
ApplyBorderToPageStyles(const uno::Reference<container::XNameContainer> & xPageStyles,const uno::Reference<lang::XMultiServiceFactory> & xTextFactory,sal_Int32 nValue)448 void SectionPropertyMap::ApplyBorderToPageStyles(
449 const uno::Reference< container::XNameContainer >& xPageStyles,
450 const uno::Reference < lang::XMultiServiceFactory >& xTextFactory,
451 sal_Int32 nValue )
452 {
453 /*
454 page border applies to:
455 nIntValue & 0x07 ->
456 0 all pages in this section
457 1 first page in this section
458 2 all pages in this section but first
459 3 whole document (all sections)
460 nIntValue & 0x18 -> page border depth 0 - in front 1- in back
461 nIntValue & 0xe0 ->
462 page border offset from:
463 0 offset from text
464 1 offset from edge of page
465 */
466 uno::Reference< beans::XPropertySet > xFirst;
467 uno::Reference< beans::XPropertySet > xSecond;
468 sal_Int32 nOffsetFrom = (nValue & 0x00E0) >> 5;
469 //sal_Int32 bPageDepth = (nValue & 0x0018) >> 3; //unused information: 0 - in front 1 - in back
470 //todo: negative spacing (from ww8par6.cxx)
471 switch( nValue & 0x07)
472 {
473 case 0: /*all styles*/
474 if ( m_sFollowPageStyleName.getLength( ) > 0 )
475 xFirst = GetPageStyle( xPageStyles, xTextFactory, false );
476 if ( m_sFirstPageStyleName.getLength( ) > 0 )
477 xSecond = GetPageStyle( xPageStyles, xTextFactory, true );
478 break;
479 case 1: /*first page*/
480 if ( m_sFirstPageStyleName.getLength( ) > 0 )
481 xFirst = GetPageStyle( xPageStyles, xTextFactory, true );
482 break;
483 case 2: /*left and right*/
484 if ( m_sFollowPageStyleName.getLength( ) > 0 )
485 xFirst = GetPageStyle( xPageStyles, xTextFactory, false );
486 break;
487 case 3: //whole document?
488 //todo: how to apply a border to the whole document - find all sections or access all page styles?
489 default:
490 return;
491 }
492 //has to be sorted like enum BorderPosition: l-r-t-b
493 static const PropertyIds aBorderIds[4] =
494 {
495 PROP_LEFT_BORDER,
496 PROP_RIGHT_BORDER,
497 PROP_TOP_BORDER,
498 PROP_BOTTOM_BORDER
499 };
500 static const PropertyIds aBorderDistanceIds[4] =
501 {
502 PROP_LEFT_BORDER_DISTANCE,
503 PROP_RIGHT_BORDER_DISTANCE,
504 PROP_TOP_BORDER_DISTANCE,
505 PROP_BOTTOM_BORDER_DISTANCE
506 };
507 static const PropertyIds aMarginIds[4] =
508 {
509 PROP_LEFT_MARGIN,
510 PROP_RIGHT_MARGIN,
511 PROP_TOP_MARGIN,
512 PROP_BOTTOM_MARGIN
513 };
514
515 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
516 for( sal_Int32 nBorder = 0; nBorder < 4; ++nBorder)
517 {
518 if( m_pBorderLines[nBorder] )
519 {
520 const ::rtl::OUString sBorderName = rPropNameSupplier.GetName( aBorderIds[nBorder] );
521 xFirst->setPropertyValue( sBorderName, uno::makeAny( *m_pBorderLines[nBorder] ));
522 if(xSecond.is())
523 xSecond->setPropertyValue( sBorderName, uno::makeAny( *m_pBorderLines[nBorder] ));
524 }
525 if( m_nBorderDistances[nBorder] >= 0 )
526 {
527 SetBorderDistance( xFirst, aMarginIds[nBorder], aBorderDistanceIds[nBorder],
528 m_nBorderDistances[nBorder], nOffsetFrom );
529 if(xSecond.is())
530 SetBorderDistance( xSecond, aMarginIds[nBorder], aBorderDistanceIds[nBorder],
531 m_nBorderDistances[nBorder], nOffsetFrom );
532 }
533 }
534 }
535
SetBorderDistance(uno::Reference<beans::XPropertySet> xStyle,PropertyIds eMarginId,PropertyIds eDistId,sal_Int32 nDistance,sal_Int32 nOffsetFrom)536 void SectionPropertyMap::SetBorderDistance( uno::Reference< beans::XPropertySet > xStyle,
537 PropertyIds eMarginId, PropertyIds eDistId, sal_Int32 nDistance, sal_Int32 nOffsetFrom )
538 {
539 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
540
541 sal_Int32 nDist = nDistance;
542 if( nOffsetFrom == 1 )
543 {
544 const ::rtl::OUString sMarginName = rPropNameSupplier.GetName( eMarginId );
545 uno::Any aMargin = xStyle->getPropertyValue( sMarginName );
546 sal_Int32 nMargin = 0;
547 aMargin >>= nMargin;
548
549 // Change the margins with the border distance
550 xStyle->setPropertyValue( sMarginName, uno::makeAny( nDistance ) );
551
552 // Set the distance to ( Margin - distance )
553 nDist = nMargin - nDistance;
554 }
555 const ::rtl::OUString sBorderDistanceName = rPropNameSupplier.GetName( eDistId );
556 xStyle->setPropertyValue( sBorderDistanceName, uno::makeAny( nDist ));
557 }
558
559 /*-- 14.12.2006 12:50:06---------------------------------------------------
560
561 -----------------------------------------------------------------------*/
ApplyColumnProperties(uno::Reference<beans::XPropertySet> xColumnContainer)562 uno::Reference< text::XTextColumns > SectionPropertyMap::ApplyColumnProperties(
563 uno::Reference< beans::XPropertySet > xColumnContainer )
564 {
565 uno::Reference< text::XTextColumns > xColumns;
566 try
567 {
568 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
569 const ::rtl::OUString sTextColumns = rPropNameSupplier.GetName( PROP_TEXT_COLUMNS );
570 xColumnContainer->getPropertyValue(sTextColumns) >>= xColumns;
571 uno::Reference< beans::XPropertySet > xColumnPropSet( xColumns, uno::UNO_QUERY_THROW );
572 if( !m_bEvenlySpaced &&
573 (sal_Int32(m_aColWidth.size()) == (m_nColumnCount + 1 )) &&
574 ((sal_Int32(m_aColDistance.size()) == m_nColumnCount) || (sal_Int32(m_aColDistance.size()) == m_nColumnCount + 1)) )
575 {
576 //the column width in word is an absolute value, in OOo it's relative
577 //the distances are both absolute
578 sal_Int32 nColSum = 0;
579 for( sal_Int32 nCol = 0; nCol <= m_nColumnCount; ++nCol)
580 {
581 nColSum += m_aColWidth[nCol];
582 if(nCol)
583 nColSum += m_aColDistance[nCol -1];
584 }
585
586 sal_Int32 nRefValue = xColumns->getReferenceValue();
587 double fRel = double( nRefValue ) / double( nColSum );
588 uno::Sequence< text::TextColumn > aColumns( m_nColumnCount + 1 );
589 text::TextColumn* pColumn = aColumns.getArray();
590
591 nColSum = 0;
592 for( sal_Int32 nCol = 0; nCol <= m_nColumnCount; ++nCol)
593 {
594 //nColSum : nRefValue == (nAbsColWidth + colDist /2) : nRelColWidth;
595 pColumn[nCol].LeftMargin = nCol ? m_aColDistance[nCol - 1 ] / 2 : 0;
596 pColumn[nCol].RightMargin = nCol == m_nColumnCount ? 0 : m_aColDistance[nCol] / 2;
597 pColumn[nCol].Width = sal_Int32((double( m_aColWidth[nCol] + pColumn[nCol].RightMargin + pColumn[nCol].LeftMargin ) + 0.5 ) * fRel );
598 nColSum += pColumn[nCol].Width;
599 }
600 if( nColSum != nRefValue )
601 pColumn[m_nColumnCount].Width -= ( nColSum - nRefValue );
602 xColumns->setColumns( aColumns );
603 }
604 else
605 {
606 xColumns->setColumnCount( m_nColumnCount + 1 );
607 xColumnPropSet->setPropertyValue( rPropNameSupplier.GetName( PROP_AUTOMATIC_DISTANCE ), uno::makeAny( m_nColumnDistance ));
608 }
609
610 if(m_bSeparatorLineIsOn)
611 xColumnPropSet->setPropertyValue(
612 rPropNameSupplier.GetName( PROP_SEPARATOR_LINE_IS_ON ),
613 uno::makeAny( m_bSeparatorLineIsOn ));
614 xColumnContainer->setPropertyValue( sTextColumns, uno::makeAny( xColumns ) );
615 }
616 catch( const uno::Exception& )
617 {
618 OSL_ENSURE( false, "Exception in SectionPropertyMap::ApplyColumnProperties");
619 }
620 return xColumns;
621 }
622
623 /*-- 20.12.2006 09:44:16---------------------------------------------------
624
625 -----------------------------------------------------------------------*/
HasHeader(bool bFirstPage) const626 bool SectionPropertyMap::HasHeader(bool bFirstPage) const
627 {
628 bool bRet = false;
629 if( (bFirstPage && m_aFirstPageStyle.is()) ||( !bFirstPage && m_aFollowPageStyle.is()) )
630 {
631 if( bFirstPage )
632 m_aFirstPageStyle->getPropertyValue(
633 PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_HEADER_IS_ON) ) >>= bRet;
634 else
635 m_aFollowPageStyle->getPropertyValue(
636 PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_HEADER_IS_ON) ) >>= bRet;
637 }
638 return bRet;
639 }
640 /*-- 20.12.2006 09:44:16---------------------------------------------------
641
642 -----------------------------------------------------------------------*/
HasFooter(bool bFirstPage) const643 bool SectionPropertyMap::HasFooter(bool bFirstPage) const
644 {
645 bool bRet = false;
646 if( (bFirstPage && m_aFirstPageStyle.is()) ||( !bFirstPage && m_aFollowPageStyle.is()) )
647 {
648 if( bFirstPage )
649 m_aFirstPageStyle->getPropertyValue(
650 PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_FOOTER_IS_ON) ) >>= bRet;
651 else
652 m_aFollowPageStyle->getPropertyValue(
653 PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_FOOTER_IS_ON) ) >>= bRet;
654 }
655 return bRet;
656 }
657 /*-- 20.12.2006 09:41:56---------------------------------------------------
658
659 -----------------------------------------------------------------------*/
660 #define MIN_HEAD_FOOT_HEIGHT 100 //minimum header/footer height
661
CopyLastHeaderFooter(bool bFirstPage,DomainMapper_Impl & rDM_Impl)662 void SectionPropertyMap::CopyLastHeaderFooter( bool bFirstPage, DomainMapper_Impl& rDM_Impl )
663 {
664 #if DEBUG_DMAPPER_PROPERTY_MAP
665 dmapper_logger->startElement(__FUNCTION__);
666 #endif
667 SectionPropertyMap* pLastContext = rDM_Impl.GetLastSectionContext( );
668 if ( pLastContext )
669 {
670 uno::Reference< beans::XPropertySet > xPrevStyle = pLastContext->GetPageStyle(
671 rDM_Impl.GetPageStyles(),
672 rDM_Impl.GetTextFactory(),
673 bFirstPage );
674 uno::Reference< beans::XPropertySet > xStyle = GetPageStyle(
675 rDM_Impl.GetPageStyles(),
676 rDM_Impl.GetTextFactory(),
677 bFirstPage );
678
679 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
680
681 try {
682 // Loop over the Header and Footer properties to copy them
683 static PropertyIds aProperties[] =
684 {
685 PROP_HEADER_TEXT,
686 PROP_FOOTER_TEXT,
687 };
688
689 bool bHasPrevHeader = false;
690 bool bHasHeader = false;
691
692 rtl::OUString sHeaderIsOn = rPropNameSupplier.GetName( PROP_HEADER_IS_ON );
693 xPrevStyle->getPropertyValue( sHeaderIsOn ) >>= bHasPrevHeader;
694 xStyle->getPropertyValue( sHeaderIsOn ) >>= bHasHeader;
695 bool bCopyHeader = bHasPrevHeader && !bHasHeader;
696
697 if ( bCopyHeader )
698 xStyle->setPropertyValue( sHeaderIsOn, uno::makeAny( sal_True ) );
699
700 bool bHasPrevFooter = false;
701 bool bHasFooter = false;
702
703 rtl::OUString sFooterIsOn = rPropNameSupplier.GetName( PROP_FOOTER_IS_ON );
704 xPrevStyle->getPropertyValue( sFooterIsOn ) >>= bHasPrevFooter;
705 xStyle->getPropertyValue( sFooterIsOn ) >>= bHasFooter;
706 bool bCopyFooter = bHasPrevFooter && !bHasFooter;
707
708 if ( bCopyFooter )
709 xStyle->setPropertyValue( sFooterIsOn, uno::makeAny( sal_True ) );
710
711 // Copying the text properties
712 for ( int i = 0, nNbProps = 2; i < nNbProps; i++ )
713 {
714 bool bIsHeader = ( i < nNbProps / 2 );
715 PropertyIds aPropId = aProperties[i];
716 rtl::OUString sName = rPropNameSupplier.GetName( aPropId );
717
718 if ( ( bIsHeader && bCopyHeader ) || ( !bIsHeader && bCopyFooter ) )
719 {
720 #if DEBUG_DMAPPER_PROPERTY_MAP
721 dmapper_logger->startElement("copy");
722 dmapper_logger->chars(sName);
723 dmapper_logger->endElement("copy");
724 #endif
725 // TODO has to be copied
726 uno::Reference< text::XTextCopy > xTxt(
727 xStyle->getPropertyValue( sName ), uno::UNO_QUERY_THROW );
728
729 uno::Reference< text::XTextCopy > xPrevTxt(
730 xPrevStyle->getPropertyValue( sName ), uno::UNO_QUERY_THROW );
731
732 xTxt->copyText( xPrevTxt );
733 }
734 }
735 }
736 catch ( const uno::Exception& e )
737 {
738 (void) e;
739 #if DEBUG_DMAPPER_PROPERTY_MAP
740 dmapper_logger->startElement("exception");
741 dmapper_logger->chars(e.Message);
742 dmapper_logger->endElement("exception");
743 #endif
744 }
745 }
746 #if DEBUG_DMAPPER_PROPERTY_MAP
747 dmapper_logger->endElement(__FUNCTION__);
748 #endif
749 }
750
PrepareHeaderFooterProperties(bool bFirstPage)751 void SectionPropertyMap::PrepareHeaderFooterProperties( bool bFirstPage )
752 {
753 sal_Int32 nTopMargin = m_nTopMargin;
754 if(HasHeader(bFirstPage))
755 {
756 m_nTopMargin = m_nHeaderTop;
757 if( nTopMargin > 0 && nTopMargin > m_nHeaderTop )
758 m_nHeaderTop = nTopMargin - m_nHeaderTop;
759 else
760 m_nHeaderTop = 0;
761
762 //minimum header height 1mm
763 if( m_nHeaderTop < MIN_HEAD_FOOT_HEIGHT )
764 m_nHeaderTop = MIN_HEAD_FOOT_HEIGHT;
765 }
766
767
768 if( nTopMargin >= 0 ) //fixed height header -> see WW8Par6.hxx
769 {
770 operator[]( PropertyDefinition( PROP_HEADER_IS_DYNAMIC_HEIGHT, false )) = uno::makeAny( true );
771 operator[]( PropertyDefinition( PROP_HEADER_DYNAMIC_SPACING, false )) = uno::makeAny( true );
772 operator[]( PropertyDefinition( PROP_HEADER_BODY_DISTANCE, false )) = uno::makeAny( m_nHeaderTop - MIN_HEAD_FOOT_HEIGHT );// ULSpace.Top()
773 operator[]( PropertyDefinition( PROP_HEADER_HEIGHT, false )) = uno::makeAny( m_nHeaderTop );
774
775 }
776 else
777 {
778 //todo: old filter fakes a frame into the header/footer to support overlapping
779 //current setting is completely wrong!
780 operator[]( PropertyDefinition( PROP_HEADER_HEIGHT, false )) = uno::makeAny( m_nHeaderTop );
781 operator[]( PropertyDefinition( PROP_HEADER_BODY_DISTANCE, false )) = uno::makeAny( nTopMargin - m_nHeaderTop );
782 operator[]( PropertyDefinition( PROP_HEADER_IS_DYNAMIC_HEIGHT, false)) = uno::makeAny( false );
783 operator[]( PropertyDefinition( PROP_HEADER_DYNAMIC_SPACING, false)) = uno::makeAny( false );
784 }
785
786 sal_Int32 nBottomMargin = m_nBottomMargin;
787 if( HasFooter( bFirstPage ) )
788 {
789 m_nBottomMargin = m_nHeaderBottom;
790 if( nBottomMargin > 0 && nBottomMargin > m_nHeaderBottom )
791 m_nHeaderBottom = nBottomMargin - m_nHeaderBottom;
792 else
793 m_nHeaderBottom = 0;
794 if( m_nHeaderBottom < MIN_HEAD_FOOT_HEIGHT )
795 m_nHeaderBottom = MIN_HEAD_FOOT_HEIGHT;
796 }
797
798 if( nBottomMargin >= 0 ) //fixed height footer -> see WW8Par6.hxx
799 {
800 operator[]( PropertyDefinition( PROP_FOOTER_IS_DYNAMIC_HEIGHT, false )) = uno::makeAny( true );
801 operator[]( PropertyDefinition( PROP_FOOTER_DYNAMIC_SPACING, false )) = uno::makeAny( true );
802 operator[]( PropertyDefinition( PROP_FOOTER_BODY_DISTANCE, false )) = uno::makeAny( m_nHeaderBottom - MIN_HEAD_FOOT_HEIGHT);
803 operator[]( PropertyDefinition( PROP_FOOTER_HEIGHT, false )) = uno::makeAny( m_nHeaderBottom );
804 }
805 else
806 {
807 //todo: old filter fakes a frame into the header/footer to support overlapping
808 //current setting is completely wrong!
809 operator[]( PropertyDefinition( PROP_FOOTER_IS_DYNAMIC_HEIGHT, false)) = uno::makeAny( false );
810 operator[]( PropertyDefinition( PROP_FOOTER_DYNAMIC_SPACING, false)) = uno::makeAny( false );
811 operator[]( PropertyDefinition( PROP_FOOTER_HEIGHT, false )) = uno::makeAny( nBottomMargin - m_nHeaderBottom );
812 operator[]( PropertyDefinition( PROP_FOOTER_BODY_DISTANCE, false )) = uno::makeAny( m_nHeaderBottom );
813 }
814
815 //now set the top/bottom margin for the follow page style
816 operator[]( PropertyDefinition( PROP_TOP_MARGIN, false )) = uno::makeAny( m_nTopMargin );
817 operator[]( PropertyDefinition( PROP_BOTTOM_MARGIN, false )) = uno::makeAny( m_nBottomMargin );
818 }
819 /*-- 11.12.2006 08:31:46---------------------------------------------------
820
821 -----------------------------------------------------------------------*/
CloseSectionGroup(DomainMapper_Impl & rDM_Impl)822 void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
823 {
824 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
825 if( m_nLnnMod )
826 {
827 bool bFirst = rDM_Impl.IsLineNumberingSet();
828 rDM_Impl.SetLineNumbering( m_nLnnMod, m_nLnc, m_ndxaLnn );
829 if( m_nLnnMin > 0 || (bFirst && m_nLnc == 1))
830 {
831 //set the starting value at the beginning of the section
832 try
833 {
834 uno::Reference< beans::XPropertySet > xRangeProperties;
835 if( m_xStartingRange.is() )
836 {
837 xRangeProperties = uno::Reference< beans::XPropertySet >( m_xStartingRange, uno::UNO_QUERY_THROW );
838 }
839 else
840 {
841 //set the start value at the beginning of the document
842 xRangeProperties = uno::Reference< beans::XPropertySet >( rDM_Impl.GetTextDocument()->getText()->getStart(), uno::UNO_QUERY_THROW );
843 }
844 xRangeProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_PARA_LINE_NUMBER_START_VALUE ), uno::makeAny( m_nLnnMin + 1 ));
845 }
846 catch( const uno::Exception& )
847 {
848 OSL_ENSURE( false, "Exception in SectionPropertyMap::CloseSectionGroup");
849 }
850 }
851 }
852
853 //depending on the break type no page styles should be created
854 if(m_nBreakType == 0)
855 {
856 //todo: insert a section or access the already inserted section
857 //-->debug
858 // ::rtl::OUString sSelection = m_xStartingRange->getString();
859 // sSelection.getLength();
860 //-->debug
861 uno::Reference< beans::XPropertySet > xSection =
862 rDM_Impl.appendTextSectionAfter( m_xStartingRange );
863 if( m_nColumnCount > 0 && xSection.is())
864 ApplyColumnProperties( xSection );
865 }
866 else
867 {
868 //get the properties and create appropriate page styles
869 uno::Reference< beans::XPropertySet > xFollowPageStyle = GetPageStyle( rDM_Impl.GetPageStyles(), rDM_Impl.GetTextFactory(), false );
870
871 if( m_nDzaGutter > 0 )
872 {
873 //todo: iGutterPos from DocProperties are missing
874 // if( m_iGutterPos > 0 ) m_nTopMargin += m_nDzaGutter; else
875 if( m_bGutterRTL )
876 m_nRightMargin += m_nDzaGutter;
877 else
878 m_nLeftMargin += m_nDzaGutter;
879 }
880 operator[]( PropertyDefinition( PROP_LEFT_MARGIN, false )) = uno::makeAny( m_nLeftMargin );
881 operator[]( PropertyDefinition( PROP_RIGHT_MARGIN, false )) = uno::makeAny( m_nRightMargin );
882
883 // if( iGutterPos && fRTLGutter )
884 // m_nTopMargin += nGutter
885
886 /*** if headers/footers are available then the top/bottom margins of the
887 header/footer are copied to the top/bottom margin of the page
888 */
889 CopyLastHeaderFooter( false, rDM_Impl );
890 PrepareHeaderFooterProperties( false );
891
892 const ::rtl::OUString sTrayIndex = rPropNameSupplier.GetName( PROP_PRINTER_PAPER_TRAY_INDEX );
893 if( m_nPaperBin >= 0 )
894 xFollowPageStyle->setPropertyValue( sTrayIndex, uno::makeAny( m_nPaperBin ) );
895 uno::Reference< text::XTextColumns > xColumns;
896 if( m_nColumnCount > 0 )
897 xColumns = ApplyColumnProperties( xFollowPageStyle );
898
899 //prepare text grid properties
900 sal_Int32 nHeight = 1;
901 PropertyMap::iterator aElement = find(PropertyDefinition( PROP_HEIGHT, false ));
902 if( aElement != end())
903 aElement->second >>= nHeight;
904
905 sal_Int32 nWidth = 1;
906 aElement = find(PropertyDefinition( PROP_WIDTH, false ));
907 if( aElement != end())
908 aElement->second >>= nWidth;
909
910 text::WritingMode eWritingMode = text::WritingMode_LR_TB;
911 aElement = find(PropertyDefinition( PROP_WRITING_MODE, false ));
912 if( aElement != end())
913 aElement->second >>= eWritingMode;
914
915
916
917 sal_Int32 nTextAreaHeight = eWritingMode == text::WritingMode_LR_TB ?
918 nHeight - m_nTopMargin - m_nBottomMargin :
919 nWidth - m_nLeftMargin - m_nRightMargin;
920
921 operator[]( PropertyDefinition( PROP_GRID_LINES, false )) =
922 uno::makeAny( static_cast<sal_Int16>(nTextAreaHeight/m_nGridLinePitch));
923
924 sal_Int32 nCharWidth = 423; //240 twip/ 12 pt
925 //todo: is '0' the right index here?
926 const StyleSheetEntryPtr pEntry = rDM_Impl.GetStyleSheetTable()->FindStyleSheetByISTD(::rtl::OUString::valueOf(static_cast<sal_Int32>(0), 16));
927 if( pEntry.get( ) )
928 {
929 PropertyMap::iterator aElement_ = pEntry->pProperties->find(PropertyDefinition( PROP_CHAR_HEIGHT_ASIAN, false ));
930 if( aElement_ != pEntry->pProperties->end())
931 {
932 double fHeight = 0;
933 if( aElement_->second >>= fHeight )
934 nCharWidth = ConversionHelper::convertTwipToMM100( (long)( fHeight * 20.0 + 0.5 ));
935 }
936 }
937
938 //dxtCharSpace
939 if(m_nDxtCharSpace)
940 {
941 sal_Int32 nCharSpace = m_nDxtCharSpace;
942 //main lives in top 20 bits, and is signed.
943 sal_Int32 nMain = (nCharSpace & 0xFFFFF000);
944 nMain /= 0x1000;
945 nCharWidth += ConversionHelper::convertTwipToMM100( nMain * 20 );
946
947 sal_Int32 nFraction = (nCharSpace & 0x00000FFF);
948 nFraction = (nFraction * 20)/0xFFF;
949 nCharWidth += ConversionHelper::convertTwipToMM100( nFraction );
950 }
951 operator[]( PropertyDefinition( PROP_GRID_BASE_HEIGHT, false )) = uno::makeAny( nCharWidth );
952 sal_Int32 nRubyHeight = m_nGridLinePitch - nCharWidth;
953 if(nRubyHeight < 0 )
954 nRubyHeight = 0;
955 operator[]( PropertyDefinition( PROP_GRID_RUBY_HEIGHT, false )) = uno::makeAny( nRubyHeight );
956
957 // #i119558#, force to set document as standard page mode,
958 // refer to ww8 import process function "SwWW8ImplReader::SetDocumentGrid"
959 try
960 {
961 uno::Reference< beans::XPropertySet > xDocProperties;
962 xDocProperties = uno::Reference< beans::XPropertySet >( rDM_Impl.GetTextDocument(), uno::UNO_QUERY_THROW );
963 sal_Bool bSquaredPageMode = sal_False;
964 operator[]( PropertyDefinition( PROP_GRID_STANDARD_MODE, false )) = uno::makeAny( !bSquaredPageMode );
965 xDocProperties->setPropertyValue( rtl::OUString::createFromAscii("DefaultPageMode"), uno::makeAny( bSquaredPageMode ));
966 }
967 catch (const uno::Exception& rEx)
968 {
969 OSL_ENSURE( false, "Exception in SectionPropertyMap::CloseSectionGroup");
970 (void)rEx;
971 }
972
973 _ApplyProperties( xFollowPageStyle );
974
975 //todo: creating a "First Page" style depends on HasTitlePage und _fFacingPage_
976 if( m_bTitlePage )
977 {
978 CopyLastHeaderFooter( true, rDM_Impl );
979 PrepareHeaderFooterProperties( true );
980 uno::Reference< beans::XPropertySet > xFirstPageStyle = GetPageStyle(
981 rDM_Impl.GetPageStyles(), rDM_Impl.GetTextFactory(), true );
982 _ApplyProperties( xFirstPageStyle );
983
984 sal_Int32 nPaperBin = m_nFirstPaperBin >= 0 ? m_nFirstPaperBin : m_nPaperBin >= 0 ? m_nPaperBin : 0;
985 if( nPaperBin )
986 xFollowPageStyle->setPropertyValue( sTrayIndex, uno::makeAny( nPaperBin ) );
987 if( xColumns.is() )
988 xFollowPageStyle->setPropertyValue(
989 rPropNameSupplier.GetName( PROP_TEXT_COLUMNS ), uno::makeAny( xColumns ));
990 }
991
992 ApplyBorderToPageStyles( rDM_Impl.GetPageStyles( ), rDM_Impl.GetTextFactory( ), m_nBorderParams );
993
994 try
995 {
996 // if( m_xStartingRange.is() )
997 {
998 //now apply this break at the first paragraph of this section
999 uno::Reference< beans::XPropertySet > xRangeProperties;
1000 if( m_bIsFirstSection )
1001 {
1002 uno::Reference< container::XEnumerationAccess > xEnumAccess( rDM_Impl.GetBodyText( ), uno::UNO_QUERY_THROW );
1003 uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration( );
1004 xRangeProperties = uno::Reference< beans::XPropertySet >( xEnum->nextElement( ), uno::UNO_QUERY_THROW );
1005 }
1006 else if( m_xStartingRange.is() )
1007 {
1008 xRangeProperties = uno::Reference< beans::XPropertySet >( m_xStartingRange, uno::UNO_QUERY_THROW );
1009 }
1010 if ( xRangeProperties.is() )
1011 {
1012 /* break type: 0 - No break 1 - New Column 2 - New page 3 - Even page 4 - odd page */
1013 uno::Reference< beans::XPropertySetInfo > xRangePropertiesInfo = xRangeProperties->getPropertySetInfo();
1014 if ( xRangePropertiesInfo->hasPropertyByName( rPropNameSupplier.GetName( PROP_PAGE_DESC_NAME ) ) )
1015 {
1016 xRangeProperties->setPropertyValue(
1017 rPropNameSupplier.GetName( PROP_PAGE_DESC_NAME ),
1018 uno::makeAny( m_bTitlePage ? m_sFirstPageStyleName : m_sFollowPageStyleName ) );
1019 // todo: page breaks with odd/even page numbering are not available - find out current page number to check how to change the number
1020 // or add even/odd page break types
1021 if ( m_bPageNoRestart || m_nPageNumber >= 0 )
1022 {
1023 sal_Int16 nPageNumber = m_nPageNumber >= 0 ? static_cast< sal_Int16 >(m_nPageNumber) : 1;
1024 xRangeProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_PAGE_NUMBER_OFFSET ),
1025 uno::makeAny( nPageNumber ));
1026 }
1027 }
1028 }
1029 }
1030 }
1031 catch( const uno::Exception& rEx)
1032 {
1033 OSL_ENSURE( false, "Exception in SectionPropertyMap::CloseSectionGroup");
1034 (void)rEx;
1035 }
1036 }
1037 }
1038 /*-- 11.12.2006 08:31:46---------------------------------------------------
1039
1040 -----------------------------------------------------------------------*/
_ApplyProperties(uno::Reference<beans::XPropertySet> xStyle)1041 void SectionPropertyMap::_ApplyProperties( uno::Reference< beans::XPropertySet > xStyle )
1042 {
1043 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1044 PropertyMap::iterator aMapIter = begin();
1045 while( aMapIter != end())
1046 {
1047 try
1048 {
1049 xStyle->setPropertyValue( rPropNameSupplier.GetName( aMapIter->first.eId ), aMapIter->second );
1050 }
1051 catch( const uno::Exception& )
1052 {
1053 OSL_ENSURE( false, "Exception in <PageStyle>::setPropertyValue");
1054 }
1055 ++aMapIter;
1056 }
1057 }
lcl_AlignPaperBin(sal_Int32 nSet)1058 sal_Int32 lcl_AlignPaperBin( sal_Int32 nSet )
1059 {
1060 //default tray numbers are above 0xff
1061 if( nSet > 0xff )
1062 nSet = nSet >> 8;
1063 //there are some special numbers which can't be handled easily
1064 //1, 4, 15, manual tray, upper tray, auto select? see ww8atr.cxx
1065 //todo: find out appropriate conversion
1066 return nSet;
1067 }
1068 /*-- 13.12.2006 15:34:01---------------------------------------------------
1069
1070 -----------------------------------------------------------------------*/
SetPaperBin(sal_Int32 nSet)1071 void SectionPropertyMap::SetPaperBin( sal_Int32 nSet )
1072 {
1073 m_nPaperBin = lcl_AlignPaperBin( nSet );
1074 }
1075 /*-- 13.12.2006 15:34:01---------------------------------------------------
1076
1077 -----------------------------------------------------------------------*/
SetFirstPaperBin(sal_Int32 nSet)1078 void SectionPropertyMap::SetFirstPaperBin( sal_Int32 nSet )
1079 {
1080 m_nFirstPaperBin = lcl_AlignPaperBin( nSet );
1081 }
1082 /*-- 14.06.2007 13:57:42---------------------------------------------------
1083
1084 -----------------------------------------------------------------------*/
StyleSheetPropertyMap()1085 StyleSheetPropertyMap::StyleSheetPropertyMap() :
1086 // mnCT_Spacing_after( 0 ),
1087 mnCT_Spacing_line( 0 ),
1088 mnCT_Spacing_lineRule( 0 ),
1089 mbCT_TrPrBase_tblHeader( false ),
1090 mnCT_TrPrBase_jc( 0 ),
1091 mnCT_TcPrBase_vAlign( 0 ),
1092 mnCT_TblWidth_w( 0 ),
1093 mnCT_TblWidth_type( 0 ),
1094 // mbCT_Spacing_afterSet( false ),
1095 mbCT_Spacing_lineSet( false ),
1096 mbCT_Spacing_lineRuleSet( false ),
1097 mbCT_TrPrBase_tblHeaderSet( false ),
1098 mbCT_TrPrBase_jcSet( false ),
1099 mbCT_TcPrBase_vAlignSet( false ),
1100 mbCT_TblWidth_wSet( false ),
1101 mbCT_TblWidth_typeSet( false ),
1102 mnListId( -1 ),
1103 mnListLevel( -1 ),
1104 mnOutlineLevel( 0 )
1105 {
1106 }
1107 /*-- 14.06.2007 13:57:43---------------------------------------------------
1108
1109 -----------------------------------------------------------------------*/
~StyleSheetPropertyMap()1110 StyleSheetPropertyMap::~StyleSheetPropertyMap()
1111 {
1112 }
1113 /*-- 28.12.2007 08:19:00---------------------------------------------------
1114
1115 -----------------------------------------------------------------------*/
ParagraphProperties()1116 ParagraphProperties::ParagraphProperties() :
1117 m_bFrameMode( false ),
1118 m_nDropCap(NS_ooxml::LN_Value_wordprocessingml_ST_DropCap_none),
1119 m_nLines(0),
1120 m_w(-1),
1121 m_h(-1),
1122 m_nWrap(-1),
1123 m_hAnchor(-1),
1124 m_vAnchor(text::RelOrientation::FRAME),
1125 m_x(-1),
1126 m_bxValid( false ),
1127 m_y(-1),
1128 m_byValid( false ),
1129 m_hSpace(-1),
1130 m_vSpace(-1),
1131 m_hRule(-1),
1132 m_xAlign(-1),
1133 m_yAlign(-1),
1134 m_bAnchorLock(false),
1135 m_nDropCapLength(0)
1136 {
1137 }
1138 /*-- 28.12.2007 08:28:24---------------------------------------------------
1139
1140 -----------------------------------------------------------------------*/
ParagraphProperties(const ParagraphProperties & rCopy)1141 ParagraphProperties::ParagraphProperties(const ParagraphProperties& rCopy) :
1142 m_bFrameMode ( rCopy.m_bFrameMode),
1143 m_nDropCap ( rCopy.m_nDropCap),
1144 m_nLines ( rCopy.m_nLines),
1145 m_w ( rCopy.m_w),
1146 m_h ( rCopy.m_h),
1147 m_nWrap ( rCopy.m_nWrap),
1148 m_hAnchor ( rCopy.m_hAnchor),
1149 m_vAnchor ( rCopy.m_vAnchor),
1150 m_x ( rCopy.m_x),
1151 m_bxValid ( rCopy.m_bxValid),
1152 m_y ( rCopy.m_y),
1153 m_byValid ( rCopy.m_byValid),
1154 m_hSpace ( rCopy.m_hSpace),
1155 m_vSpace ( rCopy.m_vSpace),
1156 m_hRule ( rCopy.m_hRule),
1157 m_xAlign ( rCopy.m_xAlign),
1158 m_yAlign ( rCopy.m_yAlign),
1159 m_bAnchorLock( rCopy.m_bAnchorLock),
1160 m_nDropCapLength( rCopy.m_nDropCapLength ),
1161 m_sParaStyleName( rCopy.m_sParaStyleName),
1162 m_xStartingRange( rCopy.m_xStartingRange ),
1163 m_xEndingRange( rCopy.m_xEndingRange)
1164 {
1165 }
1166 /*-- 28.12.2007 11:29:18---------------------------------------------------
1167
1168 -----------------------------------------------------------------------*/
~ParagraphProperties()1169 ParagraphProperties::~ParagraphProperties()
1170 {
1171 }
1172 /*-- 28.12.2007 09:05:45---------------------------------------------------
1173
1174 -----------------------------------------------------------------------*/
operator ==(const ParagraphProperties & rCompare)1175 int ParagraphProperties::operator==(const ParagraphProperties& rCompare)
1176 {
1177 return
1178 m_bFrameMode == rCompare.m_bFrameMode &&
1179 m_nDropCap == rCompare.m_nDropCap &&
1180 m_nLines == rCompare.m_nLines &&
1181 m_w == rCompare.m_w &&
1182 m_h == rCompare.m_h &&
1183 m_nWrap == rCompare.m_nWrap &&
1184 m_hAnchor == rCompare.m_hAnchor &&
1185 m_vAnchor == rCompare.m_vAnchor &&
1186 m_x == rCompare.m_x &&
1187 m_bxValid == rCompare.m_bxValid &&
1188 m_y == rCompare.m_y &&
1189 m_byValid == rCompare.m_byValid &&
1190 m_hSpace == rCompare.m_hSpace &&
1191 m_vSpace == rCompare.m_vSpace &&
1192 m_hRule == rCompare.m_hRule &&
1193 m_xAlign == rCompare.m_xAlign &&
1194 m_yAlign == rCompare.m_yAlign &&
1195 m_bAnchorLock== rCompare.m_bAnchorLock;
1196 }
1197 /*-- 27.12.2007 13:32:36---------------------------------------------------
1198
1199 -----------------------------------------------------------------------*/
ParagraphPropertyMap()1200 ParagraphPropertyMap::ParagraphPropertyMap()
1201 {
1202 }
1203 /*-- 27.12.2007 13:32:36---------------------------------------------------
1204
1205 -----------------------------------------------------------------------*/
~ParagraphPropertyMap()1206 ParagraphPropertyMap::~ParagraphPropertyMap()
1207 {
1208 }
1209 /*-- 15.02.2008 16:10:39---------------------------------------------------
1210
1211 -----------------------------------------------------------------------*/
TablePropertyMap()1212 TablePropertyMap::TablePropertyMap()
1213 {
1214 }
1215 /*-- 15.02.2008 16:10:39---------------------------------------------------
1216
1217 -----------------------------------------------------------------------*/
~TablePropertyMap()1218 TablePropertyMap::~TablePropertyMap()
1219 {
1220 }
1221 /*-- 18.02.2008 10:06:30---------------------------------------------------
1222
1223 -----------------------------------------------------------------------*/
getValue(TablePropertyMapTarget eWhich,sal_Int32 & nFill)1224 bool TablePropertyMap::getValue( TablePropertyMapTarget eWhich, sal_Int32& nFill )
1225 {
1226 if( eWhich < TablePropertyMapTarget_MAX )
1227 {
1228 if(m_aValidValues[eWhich].bValid)
1229 nFill = m_aValidValues[eWhich].nValue;
1230 return m_aValidValues[eWhich].bValid;
1231 }
1232 else
1233 {
1234 OSL_ENSURE( false, "invalid TablePropertyMapTarget");
1235 return false;
1236 }
1237 }
1238 /*-- 18.02.2008 10:07:11---------------------------------------------------
1239
1240 -----------------------------------------------------------------------*/
setValue(TablePropertyMapTarget eWhich,sal_Int32 nSet)1241 void TablePropertyMap::setValue( TablePropertyMapTarget eWhich, sal_Int32 nSet )
1242 {
1243 if( eWhich < TablePropertyMapTarget_MAX )
1244 {
1245 m_aValidValues[eWhich].bValid = true;
1246 m_aValidValues[eWhich].nValue = nSet;
1247 }
1248 else
1249 OSL_ENSURE( false, "invalid TablePropertyMapTarget");
1250 }
1251 /*-- 18.02.2008 11:23:28---------------------------------------------------
1252
1253 -----------------------------------------------------------------------*/
insertTableProperties(const PropertyMap * pMap)1254 void TablePropertyMap::insertTableProperties( const PropertyMap* pMap )
1255 {
1256 #ifdef DEBUG_DMAPPER_PROPERTY_MAP
1257 dmapper_logger->startElement("TablePropertyMap.insertTableProperties");
1258 dmapper_logger->addTag(pMap->toTag());
1259 #endif
1260
1261 const TablePropertyMap* pSource = dynamic_cast< const TablePropertyMap* >(pMap);
1262 if( pSource )
1263 {
1264 for( sal_Int32 eTarget = TablePropertyMapTarget_START;
1265 eTarget < TablePropertyMapTarget_MAX; ++eTarget )
1266 {
1267 if( pSource->m_aValidValues[eTarget].bValid )
1268 {
1269 m_aValidValues[eTarget].bValid = true;
1270 m_aValidValues[eTarget].nValue = pSource->m_aValidValues[eTarget].nValue;
1271 }
1272 }
1273 }
1274 #ifdef DEBUG_DMAPPER_PROPERTY_MAP
1275 dmapper_logger->addTag(toTag());
1276 dmapper_logger->endElement("TablePropertyMap.insertTableProperties");
1277 #endif
1278 }
1279
1280
1281 }//namespace dmapper
1282 }//namespace writerfilter
1283