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