update dev300-m58
[ooovba.git] / writerfilter / source / dmapper / PropertyMap.cxx
blob7ccf38de6dfdd5d695f09b195ab4f812e7ff3710
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PropertyMap.cxx,v $
11 * $Revision: 1.25 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
31 #include <PropertyMap.hxx>
32 #include <ooxml/resourceids.hxx>
33 #include <DomainMapper_Impl.hxx>
34 #include <ConversionHelper.hxx>
35 #include <i18npool/paper.hxx>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/table/BorderLine.hpp>
39 #include <com/sun/star/container/XNameContainer.hpp>
40 #include <com/sun/star/style/BreakType.hpp>
41 #include <com/sun/star/text/RelOrientation.hpp>
42 #include <com/sun/star/text/WritingMode.hpp>
43 #include <com/sun/star/text/XTextColumns.hpp>
44 #include <com/sun/star/text/XText.hpp>
46 using namespace ::com::sun::star;
48 namespace writerfilter {
49 namespace dmapper{
51 /*-- 21.06.2006 09:30:56---------------------------------------------------
53 -----------------------------------------------------------------------*/
54 PropertyMap::PropertyMap() :
55 m_cFootnoteSymbol( 0 ),
56 m_nFootnoteFontId( -1 )
59 /*-- 21.06.2006 09:30:56---------------------------------------------------
61 -----------------------------------------------------------------------*/
62 PropertyMap::~PropertyMap()
65 /*-- 20.06.2006 10:23:55---------------------------------------------------
67 -----------------------------------------------------------------------*/
68 uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues()
70 if(!m_aValues.getLength() && size())
72 m_aValues.realloc( size() );
73 ::com::sun::star::beans::PropertyValue* pValues = m_aValues.getArray();
74 //style names have to be the first elements within the property sequence
75 //otherwise they will overwrite 'hard' attributes
76 sal_Int32 nValue = 0;
77 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
78 PropertyMap::iterator aParaStyleIter = find(PropertyDefinition( PROP_PARA_STYLE_NAME, false ) );
79 if( aParaStyleIter != end())
81 pValues[nValue].Name = rPropNameSupplier.GetName( aParaStyleIter->first.eId );
82 pValues[nValue].Value = aParaStyleIter->second;
83 ++nValue;
86 PropertyMap::iterator aCharStyleIter = find(PropertyDefinition( PROP_CHAR_STYLE_NAME, false ));
87 if( aCharStyleIter != end())
89 pValues[nValue].Name = rPropNameSupplier.GetName( aCharStyleIter->first.eId );
90 pValues[nValue].Value = aCharStyleIter->second;
91 ++nValue;
93 PropertyMap::iterator aNumRuleIter = find(PropertyDefinition( PROP_NUMBERING_RULES, false ) );
94 if( aNumRuleIter != end())
96 pValues[nValue].Name = rPropNameSupplier.GetName( aNumRuleIter->first.eId );
97 pValues[nValue].Value = aNumRuleIter->second;
98 ++nValue;
100 PropertyMap::iterator aMapIter = begin();
101 for( ; nValue < m_aValues.getLength(); ++aMapIter )
103 if( aMapIter != aParaStyleIter && aMapIter != aCharStyleIter && aMapIter != aNumRuleIter )
105 pValues[nValue].Name = rPropNameSupplier.GetName( aMapIter->first.eId );
106 pValues[nValue].Value = aMapIter->second;
107 ++nValue;
111 return m_aValues;
113 /*-------------------------------------------------------------------------
115 -----------------------------------------------------------------------*/
116 void PropertyMap::Insert( PropertyIds eId, bool bIsTextProperty, const uno::Any& rAny, bool bOverwrite )
118 // const ::rtl::OUString& rInsert = PropertyNameSupplier::
119 // GetPropertyNameSupplier().GetName(eId);
120 PropertyMap::iterator aElement = find(PropertyDefinition( eId, bIsTextProperty ) );
121 if( aElement != end())
123 if(!bOverwrite)
124 return;
125 erase( aElement );
127 _PropertyMap::insert( PropertyMap::value_type
128 (PropertyDefinition( eId, bIsTextProperty),
129 rAny ));
130 Invalidate();
132 /*-- 13.12.2006 10:46:42---------------------------------------------------
134 -----------------------------------------------------------------------*/
135 template<class T>
136 struct removeExistingElements : public ::std::unary_function<T, void>
138 PropertyMap& rMap;
140 removeExistingElements(PropertyMap& _rMap ) : rMap(_rMap) {}
141 void operator() (T x)
143 PropertyMap::iterator aElement = rMap.find(x.first);
144 if( aElement != rMap.end())
145 rMap.erase( aElement );
148 /*-- 13.12.2006 10:46:42---------------------------------------------------
150 -----------------------------------------------------------------------*/
151 void PropertyMap::insert( const PropertyMapPtr pMap, bool bOverwrite )
153 if( pMap.get() )
155 if( bOverwrite )
156 ::std::for_each( pMap->begin(), pMap->end(), removeExistingElements<PropertyMap::value_type>(*this) );
157 _PropertyMap::insert(pMap->begin(), pMap->end());
158 insertTableProperties(pMap.get());
161 /*-- 06.06.2007 15:49:09---------------------------------------------------
163 -----------------------------------------------------------------------*/
164 const uno::Reference< text::XFootnote>& PropertyMap::GetFootnote() const
166 return m_xFootnote;
168 /*-- 18.02.2008 11:23:28---------------------------------------------------
170 -----------------------------------------------------------------------*/
171 void PropertyMap::insertTableProperties( const PropertyMap* )
174 /*-- 24.07.2006 08:29:01---------------------------------------------------
176 -----------------------------------------------------------------------*/
177 SectionPropertyMap::SectionPropertyMap(bool bIsFirstSection) :
178 m_bIsFirstSection( bIsFirstSection )
179 ,m_bTitlePage( false )
180 ,m_nColumnCount( 0 )
181 ,m_nColumnDistance( 1249 )
182 ,m_bSeparatorLineIsOn( false )
183 ,m_bEvenlySpaced( false )
184 ,m_bIsLandscape( false )
185 ,m_bPageNoRestart( false )
186 ,m_nPageNumber( -1 )
187 ,m_nBreakType( -1 )
188 ,m_nPaperBin( -1 )
189 ,m_nFirstPaperBin( -1 )
190 ,m_nLeftMargin( 3175 ) //page left margin, default 0x708 (1800) twip -> 3175 1/100 mm
191 ,m_nRightMargin( 3175 )//page right margin, default 0x708 (1800) twip -> 3175 1/100 mm
192 ,m_nTopMargin( 2540 )
193 ,m_nBottomMargin( 2540 )
194 ,m_nHeaderTop( 1270 ) //720 twip
195 ,m_nHeaderBottom( 1270 )//720 twip
196 ,m_nDzaGutter( 0 )
197 ,m_bGutterRTL( false )
198 ,m_bSFBiDi( false )
199 ,m_nGridLinePitch( 1 )
200 ,m_nDxtCharSpace( 0 )
201 ,m_nLnnMod( 0 )
202 ,m_nLnc( 0 )
203 ,m_ndxaLnn( 0 )
204 ,m_nLnnMin( 0 )
206 static sal_Int32 nNumber = 0;
207 nSectionNumber = nNumber++;
208 memset(&m_pBorderLines, 0x00, sizeof(m_pBorderLines));
209 for( sal_Int32 nBorder = 0; nBorder < 4; ++nBorder )
210 m_nBorderDistances[ nBorder ] = -1;
211 //todo: set defaults in ApplyPropertiesToPageStyles
212 //initialize defaults
213 PaperInfo aLetter(PAPER_LETTER);
214 //page height, 1/100mm
215 Insert( PROP_HEIGHT, false, uno::makeAny( (sal_Int32) aLetter.getHeight() ) );
216 //page width, 1/100mm
217 Insert( PROP_WIDTH, false, uno::makeAny( (sal_Int32) aLetter.getWidth() ) );
218 //page left margin, default 0x708 (1800) twip -> 3175 1/100 mm
219 Insert( PROP_LEFT_MARGIN, false, uno::makeAny( (sal_Int32) 3175 ) );
220 //page right margin, default 0x708 (1800) twip -> 3175 1/100 mm
221 Insert( PROP_RIGHT_MARGIN, false, uno::makeAny( (sal_Int32) 3175 ) );
222 //page top margin, default 0x5a0 (1440) twip -> 2540 1/100 mm
223 Insert( PROP_TOP_MARGIN, false, uno::makeAny( (sal_Int32)2540 ) );
224 //page bottom margin, default 0x5a0 (1440) twip -> 2540 1/100 mm
225 Insert( PROP_BOTTOM_MARGIN, false, uno::makeAny( (sal_Int32) 2540 ) );
226 uno::Any aFalse( ::uno::makeAny( false ) );
227 Insert( PROP_GRID_DISPLAY, false, aFalse);
228 Insert( PROP_GRID_PRINT, false, aFalse);
232 if( m_bIsFirstSection )
234 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
235 m_sFirstPageStyleName = rPropNameSupplier.GetName( PROP_FIRST_PAGE );
236 m_sFollowPageStyleName = rPropNameSupplier.GetName( PROP_STANDARD );
239 /*-- 24.07.2006 08:29:02---------------------------------------------------
241 -----------------------------------------------------------------------*/
242 SectionPropertyMap::~SectionPropertyMap()
244 for( sal_Int16 ePos = BORDER_LEFT; ePos <= BORDER_BOTTOM; ++ePos)
245 delete m_pBorderLines[ePos];
247 /*-- 24.07.2006 08:31:07---------------------------------------------------
249 -----------------------------------------------------------------------*/
250 const ::rtl::OUString& SectionPropertyMap::GetPageStyleName( bool bFirst )
252 return bFirst ? m_sFirstPageStyleName : m_sFollowPageStyleName;
254 /*-- 24.07.2006 08:31:07---------------------------------------------------
256 -----------------------------------------------------------------------*/
257 void SectionPropertyMap::SetPageStyleName( bool bFirst, const ::rtl::OUString& rName)
259 if( bFirst )
260 m_sFirstPageStyleName = rName;
261 else
262 m_sFollowPageStyleName = rName;
264 /*-- 24.07.2006 09:41:20---------------------------------------------------
266 -----------------------------------------------------------------------*/
267 ::rtl::OUString lcl_FindUnusedPageStyleName(const uno::Sequence< ::rtl::OUString >& rPageStyleNames)
269 static const sal_Char cDefaultStyle[] = "Converted";
270 //find the hightest number x in each style with the name "cDefaultStyle+x" and
271 //return an incremented name
272 sal_Int32 nMaxIndex = 0;
273 const sal_Int32 nDefaultLength = sizeof(cDefaultStyle)/sizeof(sal_Char) - 1;
274 const ::rtl::OUString sDefaultStyle( cDefaultStyle, nDefaultLength, RTL_TEXTENCODING_ASCII_US );
276 const ::rtl::OUString* pStyleNames = rPageStyleNames.getConstArray();
277 for( sal_Int32 nStyle = 0; nStyle < rPageStyleNames.getLength(); ++nStyle)
279 if( pStyleNames[nStyle].getLength() > nDefaultLength &&
280 !rtl_ustr_compare_WithLength( sDefaultStyle, nDefaultLength, pStyleNames[nStyle], nDefaultLength))
282 sal_Int32 nIndex = pStyleNames[nStyle].copy( nDefaultLength ).toInt32();
283 if( nIndex > nMaxIndex)
284 nMaxIndex = nIndex;
287 ::rtl::OUString sRet( sDefaultStyle );
288 sRet += rtl::OUString::valueOf( nMaxIndex + 1);
289 return sRet;
292 /*-- 28.07.2006 13:00:43---------------------------------------------------
294 -----------------------------------------------------------------------*/
295 uno::Reference< beans::XPropertySet > SectionPropertyMap::GetPageStyle(
296 const uno::Reference< container::XNameContainer >& xPageStyles,
297 const uno::Reference < lang::XMultiServiceFactory >& xTextFactory,
298 bool bFirst )
300 uno::Reference< beans::XPropertySet > xRet;
303 if( bFirst )
305 if( !m_sFirstPageStyleName.getLength() )
307 uno::Sequence< ::rtl::OUString > aPageStyleNames = xPageStyles->getElementNames();
308 m_sFirstPageStyleName = lcl_FindUnusedPageStyleName(aPageStyleNames);
309 m_aFirstPageStyle = uno::Reference< beans::XPropertySet > (
310 xTextFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.PageStyle") )),
311 uno::UNO_QUERY);
312 xPageStyles->insertByName( m_sFirstPageStyleName, uno::makeAny(m_aFirstPageStyle) );
314 else if( !m_aFirstPageStyle.is() )
316 xPageStyles->getByName(m_sFirstPageStyleName) >>= m_aFirstPageStyle;
318 xRet = m_aFirstPageStyle;
320 else
322 if( !m_sFollowPageStyleName.getLength() )
324 uno::Sequence< ::rtl::OUString > aPageStyleNames = xPageStyles->getElementNames();
325 m_sFollowPageStyleName = lcl_FindUnusedPageStyleName(aPageStyleNames);
326 m_aFollowPageStyle = uno::Reference< beans::XPropertySet > (
327 xTextFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.PageStyle") )),
328 uno::UNO_QUERY);
329 xPageStyles->insertByName( m_sFollowPageStyleName, uno::makeAny(m_aFollowPageStyle) );
331 else if(!m_aFollowPageStyle.is() )
333 xPageStyles->getByName(m_sFollowPageStyleName) >>= m_aFollowPageStyle;
335 xRet = m_aFollowPageStyle;
339 catch( const uno::Exception& )
343 return xRet;
345 /*-- 28.07.2006 10:56:26---------------------------------------------------
347 -----------------------------------------------------------------------*/
348 void SectionPropertyMap::SetBorder( BorderPosition ePos, sal_Int32 nLineDistance, const table::BorderLine& rBorderLine )
350 delete m_pBorderLines[ePos];
351 m_pBorderLines[ePos] = new table::BorderLine( rBorderLine );
352 m_nBorderDistances[ePos] = nLineDistance;
354 /*-- 28.07.2006 10:56:27---------------------------------------------------
356 -----------------------------------------------------------------------*/
357 void SectionPropertyMap::ApplyBorderToPageStyles(
358 const uno::Reference< container::XNameContainer >& xPageStyles,
359 const uno::Reference < lang::XMultiServiceFactory >& xTextFactory,
360 sal_Int32 nValue )
363 page border applies to:
364 nIntValue & 0x07 ->
365 0 all pages in this section
366 1 first page in this section
367 2 all pages in this section but first
368 3 whole document (all sections)
369 nIntValue & 0x18 -> page border depth 0 - in front 1- in back
370 nIntValue & 0xe0 ->
371 page border offset from:
372 0 offset from text
373 1 offset from edge of page
375 uno::Reference< beans::XPropertySet > xFirst;
376 uno::Reference< beans::XPropertySet > xSecond;
377 sal_Int32 nOffsetFrom = (nValue & 0x00E0) >> 5;
378 //sal_Int32 bPageDepth = (nValue & 0x0018) >> 3; //unused infromation: 0 - in front 1 - in back
379 //todo: negative spacing (from ww8par6.cxx)
380 if( nOffsetFrom == 1 )
382 // USHORT nDist;
383 // if (aBox.GetLeft())
384 // {
385 // nDist = aBox.GetDistance(BOX_LINE_LEFT);
386 // lcl_MakeSafeNegativeSpacing( ) sets the distance to 0 if > SHRT_MAX
388 // aBox.SetDistance(lcl_MakeSafeNegativeSpacing(static_cast<USHORT>(aLR.GetLeft() - nDist)), BOX_LINE_LEFT);
389 // aSizeArray[WW8_LEFT] =
390 // aSizeArray[WW8_LEFT] - nDist + aBox.GetDistance(BOX_LINE_LEFT);
391 // }
392 //the same for right, top, bottom
395 switch( nValue & 0x07)
397 case 0: /*all styles*/
398 xFirst = GetPageStyle( xPageStyles, xTextFactory, false );
399 xSecond = GetPageStyle( xPageStyles, xTextFactory, true );
400 break;
401 case 1: /*first page*/
402 xFirst = GetPageStyle( xPageStyles, xTextFactory, true );
403 break;
404 case 2: /*left and right*/
405 xFirst = GetPageStyle( xPageStyles, xTextFactory, false );
406 break;
407 case 3: //whole document?
408 //todo: how to apply a border to the whole document - find all sections or access all page styles?
409 default:
410 return;
412 //has to be sorted like enum BorderPosition: l-r-t-b
413 static const PropertyIds aBorderIds[4] =
415 PROP_LEFT_BORDER,
416 PROP_RIGHT_BORDER,
417 PROP_TOP_BORDER,
418 PROP_BOTTOM_BORDER
420 static const PropertyIds aBorderDistanceIds[4] =
422 PROP_LEFT_BORDER_DISTANCE,
423 PROP_RIGHT_BORDER_DISTANCE,
424 PROP_TOP_BORDER_DISTANCE,
425 PROP_BOTTOM_BORDER_DISTANCE,
427 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
428 for( sal_Int32 nBorder = 0; nBorder < 4; ++nBorder)
430 if( m_pBorderLines[nBorder] )
432 const ::rtl::OUString sBorderName = rPropNameSupplier.GetName( aBorderIds[nBorder] );
433 xFirst->setPropertyValue( sBorderName, uno::makeAny( *m_pBorderLines[nBorder] ));
434 if(xSecond.is())
435 xSecond->setPropertyValue( sBorderName, uno::makeAny( *m_pBorderLines[nBorder] ));
437 if( m_nBorderDistances[nBorder] >= 0 )
439 const ::rtl::OUString sBorderDistanceName = rPropNameSupplier.GetName( aBorderDistanceIds[nBorder] );
440 xFirst->setPropertyValue( sBorderDistanceName, uno::makeAny( m_nBorderDistances[nBorder] ));
441 if(xSecond.is())
442 xSecond->setPropertyValue( sBorderDistanceName, uno::makeAny( m_nBorderDistances[nBorder] ));
446 // rContext->Insert( aBorderIds[nId - 0x702B], uno::makeAny( aBorderLine ));
447 // rContext->Insert( aBorderDistanceIds[nId - 0x702B], uno::makeAny( nLineDistance) );
449 // uno::Reference< beans::XPropertySet > xStyle = GetPageStyle( ePageType );
452 /*-- 14.12.2006 12:50:06---------------------------------------------------
454 -----------------------------------------------------------------------*/
455 uno::Reference< text::XTextColumns > SectionPropertyMap::ApplyColumnProperties(
456 uno::Reference< beans::XPropertySet > xColumnContainer )
458 uno::Reference< text::XTextColumns > xColumns;
461 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
462 const ::rtl::OUString sTextColumns = rPropNameSupplier.GetName( PROP_TEXT_COLUMNS );
463 xColumnContainer->getPropertyValue(sTextColumns) >>= xColumns;
464 uno::Reference< beans::XPropertySet > xColumnPropSet( xColumns, uno::UNO_QUERY_THROW );
465 if( !m_bEvenlySpaced &&
466 (sal_Int32(m_aColWidth.size()) == (m_nColumnCount + 1 )) &&
467 (sal_Int32(m_aColDistance.size()) == m_nColumnCount))
469 //the column width in word is an absolute value, in OOo it's relative
470 //the distances are both absolute
471 sal_Int32 nColSum = 0;
472 for( sal_Int32 nCol = 0; nCol <= m_nColumnCount; ++nCol)
474 nColSum += m_aColWidth[nCol];
475 if(nCol)
476 nColSum += m_aColDistance[nCol -1];
479 sal_Int32 nRefValue = xColumns->getReferenceValue();
480 double fRel = double( nRefValue ) / double( nColSum );
481 uno::Sequence< text::TextColumn > aColumns( m_nColumnCount + 1 );
482 text::TextColumn* pColumn = aColumns.getArray();
484 nColSum = 0;
485 for( sal_Int32 nCol = 0; nCol <= m_nColumnCount; ++nCol)
487 //nColSum : nRefValue == (nAbsColWidth + colDist /2) : nRelColWidth;
488 pColumn[nCol].LeftMargin = nCol ? m_aColDistance[nCol - 1 ] / 2 : 0;
489 pColumn[nCol].RightMargin = nCol == m_nColumnCount ? 0 : m_aColDistance[nCol] / 2;
490 pColumn[nCol].Width = sal_Int32((double( m_aColWidth[nCol] + pColumn[nCol].RightMargin + pColumn[nCol].LeftMargin ) + 0.5 ) * fRel );
491 nColSum += pColumn[nCol].Width;
493 if( nColSum != nRefValue )
494 pColumn[m_nColumnCount].Width -= ( nColSum - nRefValue );
495 xColumns->setColumns( aColumns );
497 else
499 xColumns->setColumnCount( m_nColumnCount + 1 );
500 xColumnPropSet->setPropertyValue( rPropNameSupplier.GetName( PROP_AUTOMATIC_DISTANCE ), uno::makeAny( m_nColumnDistance ));
503 if(m_bSeparatorLineIsOn)
504 xColumnPropSet->setPropertyValue(
505 rPropNameSupplier.GetName( PROP_SEPARATOR_LINE_IS_ON ),
506 uno::makeAny( m_bSeparatorLineIsOn ));
507 xColumnContainer->setPropertyValue( sTextColumns, uno::makeAny( xColumns ) );
509 catch( const uno::Exception& )
511 OSL_ENSURE( false, "Exception in SectionPropertyMap::ApplyColumnProperties");
513 return xColumns;
516 /*-- 20.12.2006 09:44:16---------------------------------------------------
518 -----------------------------------------------------------------------*/
519 bool SectionPropertyMap::HasHeader(bool bFirstPage) const
521 bool bRet = false;
522 if( (bFirstPage && m_aFirstPageStyle.is()) ||( !bFirstPage && m_aFollowPageStyle.is()) )
524 if( bFirstPage )
525 m_aFirstPageStyle->getPropertyValue(
526 PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_HEADER_IS_ON) ) >>= bRet;
527 else
528 m_aFollowPageStyle->getPropertyValue(
529 PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_HEADER_IS_ON) ) >>= bRet;
531 return bRet;
533 /*-- 20.12.2006 09:44:16---------------------------------------------------
535 -----------------------------------------------------------------------*/
536 bool SectionPropertyMap::HasFooter(bool bFirstPage) const
538 bool bRet = false;
539 if( (bFirstPage && m_aFirstPageStyle.is()) ||( !bFirstPage && m_aFollowPageStyle.is()) )
541 if( bFirstPage )
542 m_aFirstPageStyle->getPropertyValue(
543 PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_FOOTER_IS_ON) ) >>= bRet;
544 else
545 m_aFollowPageStyle->getPropertyValue(
546 PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_FOOTER_IS_ON) ) >>= bRet;
548 return bRet;
550 /*-- 20.12.2006 09:41:56---------------------------------------------------
552 -----------------------------------------------------------------------*/
553 #define MIN_HEAD_FOOT_HEIGHT 100 //minimum header/footer height
555 void SectionPropertyMap::PrepareHeaderFooterProperties( bool bFirstPage )
557 sal_Int32 nTopMargin = m_nTopMargin;
558 if(HasHeader(bFirstPage))
560 m_nTopMargin = m_nHeaderTop;
561 if( nTopMargin > 0 && nTopMargin > m_nHeaderTop )
562 m_nHeaderTop = nTopMargin - m_nHeaderTop;
563 else
564 m_nHeaderTop = 0;
566 //minimum header height 1mm
567 if( m_nHeaderTop < MIN_HEAD_FOOT_HEIGHT )
568 m_nHeaderTop = MIN_HEAD_FOOT_HEIGHT;
572 if( nTopMargin >= 0 ) //fixed height header -> see WW8Par6.hxx
574 operator[]( PropertyDefinition( PROP_HEADER_IS_DYNAMIC_HEIGHT, false )) = uno::makeAny( true );
575 operator[]( PropertyDefinition( PROP_HEADER_DYNAMIC_SPACING, false )) = uno::makeAny( true );
576 operator[]( PropertyDefinition( PROP_HEADER_BODY_DISTANCE, false )) = uno::makeAny( m_nHeaderTop - MIN_HEAD_FOOT_HEIGHT );// ULSpace.Top()
577 operator[]( PropertyDefinition( PROP_HEADER_HEIGHT, false )) = uno::makeAny( m_nHeaderTop );
580 else
582 //todo: old filter fakes a frame into the header/footer to support overlapping
583 //current setting is completely wrong!
584 operator[]( PropertyDefinition( PROP_HEADER_HEIGHT, false )) = uno::makeAny( m_nHeaderTop );
585 operator[]( PropertyDefinition( PROP_HEADER_BODY_DISTANCE, false )) = uno::makeAny( nTopMargin - m_nHeaderTop );
586 operator[]( PropertyDefinition( PROP_HEADER_IS_DYNAMIC_HEIGHT, false)) = uno::makeAny( false );
587 operator[]( PropertyDefinition( PROP_HEADER_DYNAMIC_SPACING, false)) = uno::makeAny( false );
590 sal_Int32 nBottomMargin = m_nBottomMargin;
591 if( HasFooter( bFirstPage ) )
593 m_nBottomMargin = m_nHeaderBottom;
594 if( nBottomMargin > 0 && nBottomMargin > m_nHeaderBottom )
595 m_nHeaderBottom = nBottomMargin - m_nHeaderBottom;
596 else
597 m_nHeaderBottom = 0;
598 if( m_nHeaderBottom < MIN_HEAD_FOOT_HEIGHT )
599 m_nHeaderBottom = MIN_HEAD_FOOT_HEIGHT;
602 if( nBottomMargin >= 0 ) //fixed height footer -> see WW8Par6.hxx
604 operator[]( PropertyDefinition( PROP_FOOTER_IS_DYNAMIC_HEIGHT, false )) = uno::makeAny( true );
605 operator[]( PropertyDefinition( PROP_FOOTER_DYNAMIC_SPACING, false )) = uno::makeAny( true );
606 operator[]( PropertyDefinition( PROP_FOOTER_BODY_DISTANCE, false )) = uno::makeAny( m_nHeaderBottom - MIN_HEAD_FOOT_HEIGHT);
607 operator[]( PropertyDefinition( PROP_FOOTER_HEIGHT, false )) = uno::makeAny( m_nHeaderBottom );
609 else
611 //todo: old filter fakes a frame into the header/footer to support overlapping
612 //current setting is completely wrong!
613 operator[]( PropertyDefinition( PROP_FOOTER_IS_DYNAMIC_HEIGHT, false)) = uno::makeAny( false );
614 operator[]( PropertyDefinition( PROP_FOOTER_DYNAMIC_SPACING, false)) = uno::makeAny( false );
615 operator[]( PropertyDefinition( PROP_FOOTER_HEIGHT, false )) = uno::makeAny( nBottomMargin - m_nHeaderBottom );
616 operator[]( PropertyDefinition( PROP_FOOTER_BODY_DISTANCE, false )) = uno::makeAny( m_nHeaderBottom );
619 //now set the top/bottom margin for the follow page style
620 operator[]( PropertyDefinition( PROP_TOP_MARGIN, false )) = uno::makeAny( m_nTopMargin );
621 operator[]( PropertyDefinition( PROP_BOTTOM_MARGIN, false )) = uno::makeAny( m_nBottomMargin );
623 /*-- 11.12.2006 08:31:46---------------------------------------------------
625 -----------------------------------------------------------------------*/
626 void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
628 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
629 if( m_nLnnMod )
631 bool bFirst = rDM_Impl.IsLineNumberingSet();
632 rDM_Impl.SetLineNumbering( m_nLnnMod, m_nLnc, m_ndxaLnn );
633 if( m_nLnnMin > 0 || (bFirst && m_nLnc == 1))
635 //set the starting value at the beginning of the section
638 uno::Reference< beans::XPropertySet > xRangeProperties;
639 if( m_xStartingRange.is() )
641 xRangeProperties = uno::Reference< beans::XPropertySet >( m_xStartingRange, uno::UNO_QUERY_THROW );
643 else
645 //set the start value at the beginning of the document
646 xRangeProperties = uno::Reference< beans::XPropertySet >( rDM_Impl.GetTextDocument()->getText()->getStart(), uno::UNO_QUERY_THROW );
648 xRangeProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_PARA_LINE_NUMBER_START_VALUE ), uno::makeAny( m_nLnnMin + 1 ));
650 catch( const uno::Exception& )
652 OSL_ENSURE( false, "Exception in SectionPropertyMap::CloseSectionGroup");
657 //depending on the break type no page styles should be created
658 if(m_nBreakType == 0)
660 //todo: insert a section or access the already inserted section
661 //-->debug
662 // ::rtl::OUString sSelection = m_xStartingRange->getString();
663 // sSelection.getLength();
664 //-->debug
665 uno::Reference< beans::XPropertySet > xSection =
666 rDM_Impl.appendTextSectionAfter( m_xStartingRange );
667 if( m_nColumnCount > 0 && xSection.is())
668 ApplyColumnProperties( xSection );
670 else
672 //get the properties and create appropriate page styles
673 uno::Reference< beans::XPropertySet > xFollowPageStyle = GetPageStyle( rDM_Impl.GetPageStyles(), rDM_Impl.GetTextFactory(), false );
675 if( m_nDzaGutter > 0 )
677 //todo: iGutterPos from DocProperties are missing
678 // if( m_iGutterPos > 0 ) m_nTopMargin += m_nDzaGutter; else
679 if( m_bGutterRTL )
680 m_nRightMargin += m_nDzaGutter;
681 else
682 m_nLeftMargin += m_nDzaGutter;
684 operator[]( PropertyDefinition( PROP_LEFT_MARGIN, false )) = uno::makeAny( m_nLeftMargin );
685 operator[]( PropertyDefinition( PROP_RIGHT_MARGIN, false )) = uno::makeAny( m_nRightMargin );
687 // if( iGutterPos && fRTLGutter )
688 // m_nTopMargin += nGutter
690 /*** if headers/footers are available then the top/bottom margins of the
691 header/footer are copied to the top/bottom margin of the page
693 PrepareHeaderFooterProperties( false );
695 const ::rtl::OUString sTrayIndex = rPropNameSupplier.GetName( PROP_PRINTER_PAPER_TRAY_INDEX );
696 if( m_nPaperBin >= 0 )
697 xFollowPageStyle->setPropertyValue( sTrayIndex, uno::makeAny( m_nPaperBin ) );
698 uno::Reference< text::XTextColumns > xColumns;
699 if( m_nColumnCount > 0 )
700 xColumns = ApplyColumnProperties( xFollowPageStyle );
702 //prepare text grid properties
703 sal_Int32 nHeight = 1;
704 PropertyMap::iterator aElement = find(PropertyDefinition( PROP_HEIGHT, false ));
705 if( aElement != end())
706 aElement->second >>= nHeight;
708 sal_Int32 nWidth = 1;
709 aElement = find(PropertyDefinition( PROP_WIDTH, false ));
710 if( aElement != end())
711 aElement->second >>= nWidth;
713 text::WritingMode eWritingMode = text::WritingMode_LR_TB;
714 aElement = find(PropertyDefinition( PROP_WRITING_MODE, false ));
715 if( aElement != end())
716 aElement->second >>= eWritingMode;
720 sal_Int32 nTextAreaHeight = eWritingMode == text::WritingMode_LR_TB ?
721 nHeight - m_nTopMargin - m_nBottomMargin :
722 nWidth - m_nLeftMargin - m_nRightMargin;
724 operator[]( PropertyDefinition( PROP_GRID_LINES, false )) =
725 uno::makeAny( static_cast<sal_Int16>(nTextAreaHeight/m_nGridLinePitch));
727 sal_Int32 nCharWidth = 423; //240 twip/ 12 pt
728 //todo: is '0' the right index here?
729 const StyleSheetEntry* pEntry = rDM_Impl.GetStyleSheetTable()->FindStyleSheetByISTD(::rtl::OUString::valueOf(static_cast<sal_Int32>(0), 16));
730 if( pEntry )
732 PropertyMap::iterator aElement_ = pEntry->pProperties->find(PropertyDefinition( PROP_CHAR_HEIGHT_ASIAN, false ));
733 if( aElement_ != pEntry->pProperties->end())
735 double fHeight = 0;
736 if( aElement_->second >>= fHeight )
737 nCharWidth = ConversionHelper::convertTwipToMM100( (long)( fHeight * 20.0 + 0.5 ));
741 //dxtCharSpace
742 if(m_nDxtCharSpace)
744 sal_Int32 nCharSpace = m_nDxtCharSpace;
745 //main lives in top 20 bits, and is signed.
746 sal_Int32 nMain = (nCharSpace & 0xFFFFF000);
747 nMain /= 0x1000;
748 nCharWidth += ConversionHelper::convertTwipToMM100( nMain * 20 );
750 sal_Int32 nFraction = (nCharSpace & 0x00000FFF);
751 nFraction = (nFraction * 20)/0xFFF;
752 nCharWidth += ConversionHelper::convertTwipToMM100( nFraction );
754 operator[]( PropertyDefinition( PROP_GRID_BASE_HEIGHT, false )) = uno::makeAny( nCharWidth );
755 sal_Int32 nRubyHeight = m_nGridLinePitch - nCharWidth;
756 if(nRubyHeight < 0 )
757 nRubyHeight = 0;
758 operator[]( PropertyDefinition( PROP_GRID_RUBY_HEIGHT, false )) = uno::makeAny( nRubyHeight );
760 _ApplyProperties( xFollowPageStyle );
762 //todo: creating a "First Page" style depends on HasTitlePage und _fFacingPage_
763 if( m_bTitlePage )
765 PrepareHeaderFooterProperties( true );
766 uno::Reference< beans::XPropertySet > xFirstPageStyle = GetPageStyle(
767 rDM_Impl.GetPageStyles(), rDM_Impl.GetTextFactory(), true );
768 _ApplyProperties( xFirstPageStyle );
769 sal_Int32 nPaperBin = m_nFirstPaperBin >= 0 ? m_nFirstPaperBin : m_nPaperBin >= 0 ? m_nPaperBin : 0;
770 if( nPaperBin )
771 xFollowPageStyle->setPropertyValue( sTrayIndex, uno::makeAny( nPaperBin ) );
772 if( xColumns.is() )
773 xFollowPageStyle->setPropertyValue(
774 rPropNameSupplier.GetName( PROP_TEXT_COLUMNS ), uno::makeAny( xColumns ));
778 // if( m_xStartingRange.is() )
780 //now apply this break at the first paragraph of this section
781 uno::Reference< beans::XPropertySet > xRangeProperties;
782 if( m_bIsFirstSection )
783 xRangeProperties = uno::Reference< beans::XPropertySet >( rDM_Impl.GetBodyText()->getStart(), uno::UNO_QUERY_THROW );
784 else
785 xRangeProperties = uno::Reference< beans::XPropertySet >( m_xStartingRange, uno::UNO_QUERY_THROW );
786 /* break type
787 0 - No break 1 - New Colunn 2 - New page 3 - Even page 4 - odd page */
788 if( m_nBreakType == 2 || m_nBreakType == 3)
790 xRangeProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_BREAK_TYPE),
791 uno::makeAny( m_nBreakType == 2 ? style::BreakType_COLUMN_AFTER : style::BreakType_PAGE_AFTER ) );
793 else
795 xRangeProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_PAGE_DESC_NAME ),
796 uno::makeAny( m_bTitlePage ? m_sFirstPageStyleName : m_sFollowPageStyleName ));
797 // todo: page breaks with odd/even page numbering are not available - find out current page number to check how to change the number
798 // or add even/odd page break types
799 if(m_bPageNoRestart || m_nPageNumber >= 0)
801 sal_Int16 nPageNumber = m_nPageNumber >= 0 ? static_cast< sal_Int16 >(m_nPageNumber) : 1;
802 xRangeProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_PAGE_NUMBER_OFFSET ),
803 uno::makeAny( nPageNumber ));
808 catch( const uno::Exception& rEx)
810 OSL_ENSURE( false, "Exception in SectionPropertyMap::CloseSectionGroup");
811 (void)rEx;
815 /*-- 11.12.2006 08:31:46---------------------------------------------------
817 -----------------------------------------------------------------------*/
818 void SectionPropertyMap::_ApplyProperties( uno::Reference< beans::XPropertySet > xStyle )
820 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
821 PropertyMap::iterator aMapIter = begin();
822 while( aMapIter != end())
826 xStyle->setPropertyValue( rPropNameSupplier.GetName( aMapIter->first.eId ), aMapIter->second );
828 catch( const uno::Exception& )
830 OSL_ENSURE( false, "Exception in <PageStyle>::setPropertyValue");
832 ++aMapIter;
835 sal_Int32 lcl_AlignPaperBin( sal_Int32 nSet )
837 //default tray numbers are above 0xff
838 if( nSet > 0xff )
839 nSet = nSet >> 8;
840 //there are some special numbers which can't be handled easily
841 //1, 4, 15, manual tray, upper tray, auto select? see ww8atr.cxx
842 //todo: find out appropriate conversion
843 return nSet;
845 /*-- 13.12.2006 15:34:01---------------------------------------------------
847 -----------------------------------------------------------------------*/
848 void SectionPropertyMap::SetPaperBin( sal_Int32 nSet )
850 m_nPaperBin = lcl_AlignPaperBin( nSet );
852 /*-- 13.12.2006 15:34:01---------------------------------------------------
854 -----------------------------------------------------------------------*/
855 void SectionPropertyMap::SetFirstPaperBin( sal_Int32 nSet )
857 m_nFirstPaperBin = lcl_AlignPaperBin( nSet );
859 /*-- 14.06.2007 13:57:42---------------------------------------------------
861 -----------------------------------------------------------------------*/
862 StyleSheetPropertyMap::StyleSheetPropertyMap() :
863 // mnCT_Spacing_after( 0 ),
864 mnCT_Spacing_line( 0 ),
865 mnCT_Spacing_lineRule( 0 ),
866 mbCT_TrPrBase_tblHeader( false ),
867 mnCT_TrPrBase_jc( 0 ),
868 mnCT_TcPrBase_vAlign( 0 ),
869 mnCT_TblWidth_w( 0 ),
870 mnCT_TblWidth_type( 0 ),
871 // mbCT_Spacing_afterSet( false ),
872 mbCT_Spacing_lineSet( false ),
873 mbCT_Spacing_lineRuleSet( false ),
874 mbCT_TrPrBase_tblHeaderSet( false ),
875 mbCT_TrPrBase_jcSet( false ),
876 mbCT_TcPrBase_vAlignSet( false ),
877 mbCT_TblWidth_wSet( false ),
878 mbCT_TblWidth_typeSet( false ),
879 mnListId( -1 ),
880 mnListLevel( -1 )
883 /*-- 14.06.2007 13:57:43---------------------------------------------------
885 -----------------------------------------------------------------------*/
886 StyleSheetPropertyMap::~StyleSheetPropertyMap()
889 /*-- 28.12.2007 08:19:00---------------------------------------------------
891 -----------------------------------------------------------------------*/
892 ParagraphProperties::ParagraphProperties() :
893 m_bFrameMode( false ),
894 m_nDropCap(NS_ooxml::LN_Value_wordprocessingml_ST_DropCap_none),
895 m_nLines(0),
896 m_w(-1),
897 m_h(-1),
898 m_nWrap(-1),
899 m_hAnchor(-1),
900 m_vAnchor(text::RelOrientation::FRAME),
901 m_x(-1),
902 m_bxValid( false ),
903 m_y(-1),
904 m_byValid( false ),
905 m_hSpace(-1),
906 m_vSpace(-1),
907 m_hRule(-1),
908 m_xAlign(-1),
909 m_yAlign(-1),
910 m_bAnchorLock(false),
911 m_nDropCapLength(0)
914 /*-- 28.12.2007 08:28:24---------------------------------------------------
916 -----------------------------------------------------------------------*/
917 ParagraphProperties::ParagraphProperties(const ParagraphProperties& rCopy) :
918 m_bFrameMode ( rCopy.m_bFrameMode),
919 m_nDropCap ( rCopy.m_nDropCap),
920 m_nLines ( rCopy.m_nLines),
921 m_w ( rCopy.m_w),
922 m_h ( rCopy.m_h),
923 m_nWrap ( rCopy.m_nWrap),
924 m_hAnchor ( rCopy.m_hAnchor),
925 m_vAnchor ( rCopy.m_vAnchor),
926 m_x ( rCopy.m_x),
927 m_bxValid ( rCopy.m_bxValid),
928 m_y ( rCopy.m_y),
929 m_byValid ( rCopy.m_byValid),
930 m_hSpace ( rCopy.m_hSpace),
931 m_vSpace ( rCopy.m_vSpace),
932 m_hRule ( rCopy.m_hRule),
933 m_xAlign ( rCopy.m_xAlign),
934 m_yAlign ( rCopy.m_yAlign),
935 m_bAnchorLock( rCopy.m_bAnchorLock),
936 m_nDropCapLength( rCopy.m_nDropCapLength ),
937 m_sParaStyleName( rCopy.m_sParaStyleName),
938 m_xStartingRange( rCopy.m_xStartingRange ),
939 m_xEndingRange( rCopy.m_xEndingRange)
942 /*-- 28.12.2007 11:29:18---------------------------------------------------
944 -----------------------------------------------------------------------*/
945 ParagraphProperties::~ParagraphProperties()
948 /*-- 28.12.2007 09:05:45---------------------------------------------------
950 -----------------------------------------------------------------------*/
951 int ParagraphProperties::operator==(const ParagraphProperties& rCompare)
953 return
954 m_bFrameMode == rCompare.m_bFrameMode &&
955 m_nDropCap == rCompare.m_nDropCap &&
956 m_nLines == rCompare.m_nLines &&
957 m_w == rCompare.m_w &&
958 m_h == rCompare.m_h &&
959 m_nWrap == rCompare.m_nWrap &&
960 m_hAnchor == rCompare.m_hAnchor &&
961 m_vAnchor == rCompare.m_vAnchor &&
962 m_x == rCompare.m_x &&
963 m_bxValid == rCompare.m_bxValid &&
964 m_y == rCompare.m_y &&
965 m_byValid == rCompare.m_byValid &&
966 m_hSpace == rCompare.m_hSpace &&
967 m_vSpace == rCompare.m_vSpace &&
968 m_hRule == rCompare.m_hRule &&
969 m_xAlign == rCompare.m_xAlign &&
970 m_yAlign == rCompare.m_yAlign &&
971 m_bAnchorLock== rCompare.m_bAnchorLock;
973 /*-- 27.12.2007 13:32:36---------------------------------------------------
975 -----------------------------------------------------------------------*/
976 ParagraphPropertyMap::ParagraphPropertyMap()
979 /*-- 27.12.2007 13:32:36---------------------------------------------------
981 -----------------------------------------------------------------------*/
982 ParagraphPropertyMap::~ParagraphPropertyMap()
985 /*-- 15.02.2008 16:10:39---------------------------------------------------
987 -----------------------------------------------------------------------*/
988 TablePropertyMap::TablePropertyMap()
991 /*-- 15.02.2008 16:10:39---------------------------------------------------
993 -----------------------------------------------------------------------*/
994 TablePropertyMap::~TablePropertyMap()
997 /*-- 18.02.2008 10:06:30---------------------------------------------------
999 -----------------------------------------------------------------------*/
1000 bool TablePropertyMap::getValue( TablePropertyMapTarget eWhich, sal_Int32& nFill )
1002 if( eWhich < TablePropertyMapTarget_MAX )
1004 if(m_aValidValues[eWhich].bValid)
1005 nFill = m_aValidValues[eWhich].nValue;
1006 return m_aValidValues[eWhich].bValid;
1008 else
1010 OSL_ENSURE( false, "invalid TablePropertyMapTarget");
1011 return false;
1014 /*-- 18.02.2008 10:07:11---------------------------------------------------
1016 -----------------------------------------------------------------------*/
1017 void TablePropertyMap::setValue( TablePropertyMapTarget eWhich, sal_Int32 nSet )
1019 if( eWhich < TablePropertyMapTarget_MAX )
1021 m_aValidValues[eWhich].bValid = true;
1022 m_aValidValues[eWhich].nValue = nSet;
1024 else
1025 OSL_ENSURE( false, "invalid TablePropertyMapTarget");
1027 /*-- 18.02.2008 11:23:28---------------------------------------------------
1029 -----------------------------------------------------------------------*/
1030 void TablePropertyMap::insertTableProperties( const PropertyMap* pMap )
1032 const TablePropertyMap* pSource = dynamic_cast< const TablePropertyMap* >(pMap);
1033 if( pSource )
1035 for( sal_Int32 eTarget = TablePropertyMapTarget_START;
1036 eTarget < TablePropertyMapTarget_MAX; ++eTarget )
1038 if( pSource->m_aValidValues[eTarget].bValid )
1040 m_aValidValues[eTarget].bValid = true;
1041 m_aValidValues[eTarget].nValue = pSource->m_aValidValues[eTarget].nValue;
1048 }//namespace dmapper
1049 }//namespace writerfilter