LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - PropertyMap.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 686 733 93.6 %
Date: 2015-06-13 12:38:46 Functions: 52 56 92.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #include <PropertyMap.hxx>
      20             : #include <ooxml/resourceids.hxx>
      21             : #include <DomainMapper_Impl.hxx>
      22             : #include <ConversionHelper.hxx>
      23             : #include <i18nutil/paper.hxx>
      24             : #include <osl/diagnose.h>
      25             : #include <rtl/ustring.hxx>
      26             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      27             : #include <com/sun/star/beans/PropertyValue.hpp>
      28             : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <com/sun/star/table/BorderLine2.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/style/PageStyleLayout.hpp>
      36             : #include <com/sun/star/style/XStyle.hpp>
      37             : #include <com/sun/star/table/ShadowFormat.hpp>
      38             : #include <com/sun/star/text/RelOrientation.hpp>
      39             : #include <com/sun/star/text/WritingMode.hpp>
      40             : #include <com/sun/star/text/XTextColumns.hpp>
      41             : #include <com/sun/star/text/XText.hpp>
      42             : #include <com/sun/star/text/TextGridMode.hpp>
      43             : #include <com/sun/star/text/XTextCopy.hpp>
      44             : #include <comphelper/sequence.hxx>
      45             : #include "PropertyMapHelper.hxx"
      46             : 
      47             : using namespace ::com::sun::star;
      48             : 
      49             : namespace writerfilter {
      50             : namespace dmapper{
      51             : 
      52             : 
      53             : 
      54      344995 : PropertyMap::PropertyMap() :
      55             :     m_cFootnoteSymbol( 0 ),
      56      344995 :     m_nFootnoteFontId( -1 )
      57             : {
      58      344995 : }
      59             : 
      60             : 
      61      514646 : PropertyMap::~PropertyMap()
      62             : {
      63      514646 : }
      64             : 
      65             : 
      66      176282 : uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharGrabBag)
      67             : {
      68      176282 :     if(m_aValues.empty() && !m_vMap.empty())
      69             :     {
      70      133325 :         size_t nCharGrabBag = 0;
      71      133325 :         size_t nParaGrabBag = 0;
      72      133325 :         size_t nCellGrabBag = 0;
      73      133325 :         size_t nCellGrabBagSaved = 0; // How many entries do we save from the returned sequence.
      74      133325 :         size_t nRowGrabBag = 0;
      75      905897 :         for (MapIterator i = m_vMap.begin(); i != m_vMap.end(); ++i)
      76             :         {
      77      772572 :             if ( i->second.getGrabBagType() == CHAR_GRAB_BAG )
      78       58445 :                 nCharGrabBag++;
      79      714127 :             else if ( i->second.getGrabBagType() == PARA_GRAB_BAG )
      80        3741 :                 nParaGrabBag++;
      81      710386 :             else if ( i->second.getGrabBagType() == CELL_GRAB_BAG )
      82             :             {
      83         283 :                 nCellGrabBag++;
      84         283 :                 nCellGrabBagSaved++;
      85             :             }
      86      710103 :             else if ( i->first == PROP_CELL_INTEROP_GRAB_BAG)
      87             :             {
      88        4787 :                 uno::Sequence<beans::PropertyValue> aSeq;
      89        4787 :                 i->second.getValue() >>= aSeq;
      90        4787 :                 nCellGrabBag += aSeq.getLength();
      91        4787 :                 nCellGrabBagSaved++;
      92             :             }
      93      705316 :             else if ( i->second.getGrabBagType() == ROW_GRAB_BAG )
      94         280 :                 nRowGrabBag++;
      95             :         }
      96             : 
      97             :         // If there are any grab bag properties, we need one slot for them.
      98      133325 :         uno::Sequence<beans::PropertyValue> aCharGrabBagValues(nCharGrabBag);
      99      266650 :         uno::Sequence<beans::PropertyValue> aParaGrabBagValues(nParaGrabBag);
     100      266650 :         uno::Sequence<beans::PropertyValue> aCellGrabBagValues(nCellGrabBag);
     101      266650 :         uno::Sequence<beans::PropertyValue> aRowGrabBagValues(nRowGrabBag);
     102      133325 :         beans::PropertyValue* pCharGrabBagValues = aCharGrabBagValues.getArray();
     103      133325 :         beans::PropertyValue* pParaGrabBagValues = aParaGrabBagValues.getArray();
     104      133325 :         beans::PropertyValue* pCellGrabBagValues = aCellGrabBagValues.getArray();
     105      133325 :         beans::PropertyValue* pRowGrabBagValues = aRowGrabBagValues.getArray();
     106             :         //style names have to be the first elements within the property sequence
     107             :         //otherwise they will overwrite 'hard' attributes
     108      133325 :         sal_Int32 nRowGrabBagValue = 0;
     109      133325 :         sal_Int32 nCellGrabBagValue = 0;
     110      133325 :         sal_Int32 nParaGrabBagValue = 0;
     111      133325 :         sal_Int32 nCharGrabBagValue = 0;
     112      133325 :         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     113      133325 :         MapIterator aParaStyleIter = m_vMap.find(PROP_PARA_STYLE_NAME);
     114      133325 :         if( aParaStyleIter != m_vMap.end())
     115             :         {
     116       26255 :             beans::PropertyValue aValue;
     117       26255 :             aValue.Name = rPropNameSupplier.GetName( aParaStyleIter->first );
     118       26255 :             aValue.Value = aParaStyleIter->second.getValue();
     119       26255 :             m_aValues.push_back(aValue);
     120             :         }
     121             : 
     122      133325 :         MapIterator aCharStyleIter = m_vMap.find(PROP_CHAR_STYLE_NAME);
     123      133325 :         if( aCharStyleIter != m_vMap.end())
     124             :         {
     125        5091 :             beans::PropertyValue aValue;
     126        5091 :             aValue.Name = rPropNameSupplier.GetName( aCharStyleIter->first );
     127        5091 :             aValue.Value = aCharStyleIter->second.getValue();
     128        5091 :             m_aValues.push_back(aValue);
     129             :         }
     130      133325 :         MapIterator aNumRuleIter = m_vMap.find(PROP_NUMBERING_RULES);
     131      133325 :         if( aNumRuleIter != m_vMap.end())
     132             :         {
     133        2441 :             beans::PropertyValue aValue;
     134        2441 :             aValue.Name = rPropNameSupplier.GetName( aNumRuleIter->first );
     135        2441 :             aValue.Value = aNumRuleIter->second.getValue();
     136        2441 :             m_aValues.push_back(aValue);
     137             :         }
     138      133325 :         MapIterator aMapIter = m_vMap.begin();
     139      905897 :         for( ; aMapIter != m_vMap.end(); ++aMapIter )
     140             :         {
     141      772572 :             if( aMapIter != aParaStyleIter && aMapIter != aCharStyleIter && aMapIter != aNumRuleIter )
     142             :             {
     143      738785 :                 if ( aMapIter->second.getGrabBagType() == CHAR_GRAB_BAG )
     144             :                 {
     145       58445 :                     if (bCharGrabBag)
     146             :                     {
     147       58406 :                         pCharGrabBagValues[nCharGrabBagValue].Name = rPropNameSupplier.GetName( aMapIter->first );
     148       58406 :                         pCharGrabBagValues[nCharGrabBagValue].Value = aMapIter->second.getValue();
     149       58406 :                         ++nCharGrabBagValue;
     150             :                     }
     151             :                 }
     152      680340 :                 else if ( aMapIter->second.getGrabBagType() == PARA_GRAB_BAG )
     153             :                 {
     154        3741 :                     pParaGrabBagValues[nParaGrabBagValue].Name = rPropNameSupplier.GetName( aMapIter->first );
     155        3741 :                     pParaGrabBagValues[nParaGrabBagValue].Value = aMapIter->second.getValue();
     156        3741 :                     ++nParaGrabBagValue;
     157             :                 }
     158      676599 :                 else if ( aMapIter->second.getGrabBagType() == CELL_GRAB_BAG )
     159             :                 {
     160         283 :                     pCellGrabBagValues[nCellGrabBagValue].Name = rPropNameSupplier.GetName( aMapIter->first );
     161         283 :                     pCellGrabBagValues[nCellGrabBagValue].Value = aMapIter->second.getValue();
     162         283 :                     ++nCellGrabBagValue;
     163             :                 }
     164      676316 :                 else if ( aMapIter->second.getGrabBagType() == ROW_GRAB_BAG )
     165             :                 {
     166         280 :                     pRowGrabBagValues[nRowGrabBagValue].Name = rPropNameSupplier.GetName( aMapIter->first );
     167         280 :                     pRowGrabBagValues[nRowGrabBagValue].Value = aMapIter->second.getValue();
     168         280 :                     ++nRowGrabBagValue;
     169             :                 }
     170             :                 else
     171             :                 {
     172      676036 :                     if (aMapIter->first == PROP_CELL_INTEROP_GRAB_BAG)
     173             :                     {
     174        4787 :                         uno::Sequence<beans::PropertyValue> aSeq;
     175        4787 :                         aMapIter->second.getValue() >>= aSeq;
     176       23370 :                         for (sal_Int32 i = 0; i < aSeq.getLength(); ++i)
     177             :                         {
     178       18583 :                             pCellGrabBagValues[nCellGrabBagValue] = aSeq[i];
     179       18583 :                             ++nCellGrabBagValue;
     180        4787 :                         }
     181             :                     }
     182             :                     else
     183             :                     {
     184      671249 :                         beans::PropertyValue aValue;
     185      671249 :                         aValue.Name = rPropNameSupplier.GetName( aMapIter->first );
     186      671249 :                         aValue.Value = aMapIter->second.getValue();
     187      671249 :                         m_aValues.push_back(aValue);
     188             :                     }
     189             :                 }
     190             :             }
     191             :         }
     192      133325 :         if (nCharGrabBag && bCharGrabBag)
     193             :         {
     194       21975 :             beans::PropertyValue aValue;
     195       21975 :             aValue.Name = "CharInteropGrabBag";
     196       21975 :             aValue.Value = uno::makeAny(aCharGrabBagValues);
     197       21975 :             m_aValues.push_back(aValue);
     198             :         }
     199      133325 :         if (nParaGrabBag)
     200             :         {
     201        2813 :             beans::PropertyValue aValue;
     202        2813 :             aValue.Name = "ParaInteropGrabBag";
     203        2813 :             aValue.Value = uno::makeAny(aParaGrabBagValues);
     204        2813 :             m_aValues.push_back(aValue);
     205             :         }
     206      133325 :         if (nCellGrabBag)
     207             :         {
     208        4881 :             beans::PropertyValue aValue;
     209        4881 :             aValue.Name = "CellInteropGrabBag";
     210        4881 :             aValue.Value = uno::makeAny(aCellGrabBagValues);
     211        4881 :             m_aValues.push_back(aValue);
     212             :         }
     213      133325 :         if (nRowGrabBag)
     214             :         {
     215         280 :             beans::PropertyValue aValue;
     216         280 :             aValue.Name = "RowInteropGrabBag";
     217         280 :             aValue.Value = uno::makeAny(aRowGrabBagValues);
     218         280 :             m_aValues.push_back(aValue);
     219      133325 :         }
     220             :     }
     221      176282 :     return comphelper::containerToSequence(m_aValues);
     222             : }
     223             : 
     224             : #ifdef DEBUG_WRITERFILTER
     225             : static void lcl_AnyToTag(const uno::Any & rAny)
     226             : {
     227             :     try {
     228             :         sal_Int32 aInt = 0;
     229             :         if (rAny >>= aInt) {
     230             :             TagLogger::getInstance().attribute("value", rAny);
     231             :         } else {
     232             :             TagLogger::getInstance().attribute("unsignedValue", 0);
     233             :         }
     234             : 
     235             :         sal_uInt32 auInt = 0;
     236             :         rAny >>= auInt;
     237             :         TagLogger::getInstance().attribute("unsignedValue", auInt);
     238             : 
     239             :         float aFloat = 0.0f;
     240             :         if (rAny >>= aFloat) {
     241             :             TagLogger::getInstance().attribute("floatValue", rAny);
     242             :         } else {
     243             :             TagLogger::getInstance().attribute("unsignedValue", 0);
     244             :         }
     245             : 
     246             :         OUString aStr;
     247             :         rAny >>= aStr;
     248             :         TagLogger::getInstance().attribute("stringValue", aStr);
     249             :     }
     250             :     catch (...) {
     251             :     }
     252             : }
     253             : #endif
     254             : 
     255      903291 : void PropertyMap::Insert( PropertyIds eId, const uno::Any& rAny, bool bOverwrite, GrabBagType i_GrabBagType )
     256             : {
     257             : #ifdef DEBUG_WRITERFILTER
     258             :     const OUString& rInsert = PropertyNameSupplier::
     259             :         GetPropertyNameSupplier().GetName(eId);
     260             : 
     261             :     TagLogger::getInstance().startElement("propertyMap.insert");
     262             :     TagLogger::getInstance().attribute("name", rInsert);
     263             :     lcl_AnyToTag(rAny);
     264             :     TagLogger::getInstance().endElement();
     265             : #endif
     266             : 
     267      903291 :     if (!bOverwrite)
     268      111616 :         m_vMap.insert(std::make_pair(eId, PropValue(rAny, i_GrabBagType)));
     269             :     else
     270      791675 :         m_vMap[eId] = PropValue(rAny, i_GrabBagType);
     271             : 
     272      903291 :     Invalidate();
     273      903291 : }
     274             : 
     275       31363 : void PropertyMap::Erase( PropertyIds eId )
     276             : {
     277             :     //Safe call to erase, it throws no exceptions, even if eId is not in m_vMap
     278       31363 :     m_vMap.erase(eId);
     279             : 
     280       31363 :     Invalidate();
     281       31363 : }
     282             : 
     283      469971 : boost::optional<PropertyMap::Property> PropertyMap::getProperty( PropertyIds eId ) const
     284             : {
     285      469971 :     MapIterator aIter = m_vMap.find(eId);
     286      469971 :     if (aIter==m_vMap.end())
     287      278184 :         return boost::optional<Property>();
     288             :     else
     289      191787 :         return std::make_pair( eId, aIter->second.getValue() ) ;
     290             : }
     291             : 
     292       41697 : bool PropertyMap::isSet( PropertyIds eId) const
     293             : {
     294       41697 :     return m_vMap.find(eId)!=m_vMap.end();
     295             : }
     296             : 
     297             : #ifdef DEBUG_WRITERFILTER
     298             : void PropertyMap::dumpXml() const
     299             : {
     300             :     TagLogger::getInstance().startElement("PropertyMap");
     301             : 
     302             :     PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     303             :     MapIterator aMapIter = m_vMap.begin();
     304             :     while (aMapIter != m_vMap.end())
     305             :     {
     306             :         TagLogger::getInstance().startElement("property");
     307             : 
     308             :         TagLogger::getInstance().attribute("name", rPropNameSupplier.GetName( aMapIter->first ));
     309             : 
     310             :         switch (aMapIter->first)
     311             :         {
     312             :             case PROP_TABLE_COLUMN_SEPARATORS:
     313             :                lcl_DumpTableColumnSeparators(aMapIter->second.getValue());
     314             :                 break;
     315             :             default:
     316             :             {
     317             :                 try {
     318             :                     sal_Int32 aInt = 0;
     319             :                     aMapIter->second.getValue() >>= aInt;
     320             :                     TagLogger::getInstance().attribute("value", aInt);
     321             : 
     322             :                     sal_uInt32 auInt = 0;
     323             :                     aMapIter->second.getValue() >>= auInt;
     324             :                     TagLogger::getInstance().attribute("unsignedValue", auInt);
     325             : 
     326             :                     float aFloat = 0.0;
     327             :                     aMapIter->second.getValue() >>= aFloat;
     328             :                     TagLogger::getInstance().attribute("floatValue", aFloat);
     329             : 
     330             :                     OUString aStr;
     331             :                     aMapIter->second.getValue() >>= auInt;
     332             :                     TagLogger::getInstance().attribute("stringValue", aStr);
     333             :                 }
     334             :                 catch (...) {
     335             :                 }
     336             :             }
     337             :                 break;
     338             :         }
     339             : 
     340             :         TagLogger::getInstance().endElement();
     341             : 
     342             :         ++aMapIter;
     343             :     }
     344             : 
     345             :     TagLogger::getInstance().endElement();
     346             : }
     347             : #endif
     348             : 
     349      120520 : void PropertyMap::InsertProps(const PropertyMapPtr& rMap)
     350             : {
     351      120520 :     if (rMap)
     352             :     {
     353      120395 :         MapIterator pEnd = rMap->m_vMap.end();
     354      267252 :         for ( MapIterator iter = rMap->m_vMap.begin(); iter!=pEnd; ++iter )
     355      146857 :             m_vMap[iter->first] = iter->second;
     356             : 
     357      120395 :         insertTableProperties(rMap.get());
     358             : 
     359      120395 :         Invalidate();
     360             :     }
     361      120520 : }
     362             : 
     363       85258 : void PropertyMap::insertTableProperties( const PropertyMap* )
     364             : {
     365             : #ifdef DEBUG_WRITERFILTER
     366             :     TagLogger::getInstance().element("PropertyMap.insertTableProperties");
     367             : #endif
     368       85258 : }
     369             : 
     370           0 : void PropertyMap::printProperties()
     371             : {
     372             : #ifdef DEBUG_WRITERFILTER
     373             :     TagLogger::getInstance().startElement("properties");
     374             : 
     375             :     MapIterator aMapIter = m_vMap.begin();
     376             :     MapIterator aEndIter = m_vMap.end();
     377             :     PropertyNameSupplier& rPropSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     378             :     for( ; aMapIter != aEndIter; ++aMapIter )
     379             :     {
     380             :         SAL_INFO("writerfilter", rPropSupplier.GetName(aMapIter->first));
     381             : 
     382             :         table::BorderLine2 aLine;
     383             :         sal_Int32 nColor;
     384             :         if ( aMapIter->second.getValue() >>= aLine )
     385             :         {
     386             :             TagLogger::getInstance().startElement("borderline");
     387             :             TagLogger::getInstance().attribute("color", aLine.Color);
     388             :             TagLogger::getInstance().attribute("inner", aLine.InnerLineWidth);
     389             :             TagLogger::getInstance().attribute("outer", aLine.OuterLineWidth);
     390             :             TagLogger::getInstance().endElement();
     391             :         }
     392             :         else if ( aMapIter->second.getValue() >>= nColor )
     393             :         {
     394             :             TagLogger::getInstance().startElement("color");
     395             :             TagLogger::getInstance().attribute("number", nColor);
     396             :             TagLogger::getInstance().endElement();
     397             :         }
     398             :     }
     399             : 
     400             :     TagLogger::getInstance().endElement();
     401             : #endif
     402           0 : }
     403             : 
     404        2261 : SectionPropertyMap::SectionPropertyMap(bool bIsFirstSection) :
     405             :     m_bIsFirstSection( bIsFirstSection )
     406             :     ,m_nBorderParams( 0 )
     407             :     ,m_bTitlePage( false )
     408             :     ,m_nColumnCount( 0 )
     409             :     ,m_nColumnDistance( 1249 )
     410             :     ,m_bSeparatorLineIsOn( false )
     411             :     ,m_bEvenlySpaced( false )
     412             :     ,m_bIsLandscape( false )
     413             :     ,m_bPageNoRestart( false )
     414             :     ,m_nPageNumber( -1 )
     415             :     ,m_nBreakType( -1 )
     416             :     ,m_nPaperBin( -1 )
     417             :     ,m_nFirstPaperBin( -1 )
     418             :     ,m_nLeftMargin( 3175 ) //page left margin, default 0x708 (1800) twip -> 3175 1/100 mm
     419             :     ,m_nRightMargin( 3175 )//page right margin, default 0x708 (1800) twip -> 3175 1/100 mm
     420             :     ,m_nTopMargin( 2540 )
     421             :     ,m_nBottomMargin( 2540 )
     422             :     ,m_nHeaderTop( 1270 ) //720 twip
     423             :     ,m_nHeaderBottom( 1270 )//720 twip
     424             :     ,m_nDzaGutter( 0 )
     425             :     ,m_bGutterRTL( false )
     426             :     ,m_bSFBiDi( false )
     427             :     ,m_nGridType(0)
     428             :     ,m_nGridLinePitch( 1 )
     429             :     ,m_nDxtCharSpace( 0 )
     430             :     ,m_bGridSnapToChars(true)
     431             :     ,m_nLnnMod( 0 )
     432             :     ,m_nLnc( 0 )
     433             :     ,m_ndxaLnn( 0 )
     434        2261 :     ,m_nLnnMin( 0 )
     435             : {
     436             :     static sal_Int32 nNumber = 0;
     437        2261 :     nSectionNumber = nNumber++;
     438        2261 :     memset(&m_pBorderLines, 0x00, sizeof(m_pBorderLines));
     439       11305 :     for( sal_Int32 nBorder = 0; nBorder < 4; ++nBorder )
     440             :     {
     441        9044 :         m_nBorderDistances[ nBorder ] = -1;
     442        9044 :         m_bBorderShadows[nBorder] = false;
     443             :     }
     444             :     //todo: set defaults in ApplyPropertiesToPageStyles
     445             :     //initialize defaults
     446        2261 :     PaperInfo aLetter(PAPER_LETTER);
     447             :     //page height, 1/100mm
     448        2261 :     Insert( PROP_HEIGHT, uno::makeAny( (sal_Int32) aLetter.getHeight() ) );
     449             :     //page width, 1/100mm
     450        2261 :     Insert( PROP_WIDTH, uno::makeAny( (sal_Int32) aLetter.getWidth() ) );
     451             :     //page left margin, default 0x708 (1800) twip -> 3175 1/100 mm
     452        2261 :     Insert( PROP_LEFT_MARGIN, uno::makeAny( (sal_Int32) 3175 ) );
     453             :     //page right margin, default 0x708 (1800) twip -> 3175 1/100 mm
     454        2261 :     Insert( PROP_RIGHT_MARGIN, uno::makeAny( (sal_Int32) 3175 ) );
     455             :     //page top margin, default 0x5a0 (1440) twip -> 2540 1/100 mm
     456        2261 :     Insert( PROP_TOP_MARGIN, uno::makeAny( (sal_Int32)2540 ) );
     457             :     //page bottom margin, default 0x5a0 (1440) twip -> 2540 1/100 mm
     458        2261 :     Insert( PROP_BOTTOM_MARGIN, uno::makeAny( (sal_Int32) 2540 ) );
     459             :     //page style layout
     460        2261 :     Insert(PROP_PAGE_STYLE_LAYOUT, uno::makeAny(style::PageStyleLayout_ALL));
     461        2261 :     uno::Any aFalse( ::uno::makeAny( false ) );
     462        2261 :     Insert( PROP_GRID_DISPLAY, aFalse);
     463        2261 :     Insert( PROP_GRID_PRINT, aFalse);
     464        2261 :     Insert( PROP_GRID_MODE, uno::makeAny(text::TextGridMode::NONE));
     465             : 
     466             : 
     467        2261 :     if( m_bIsFirstSection )
     468             :     {
     469        1976 :         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     470        1976 :         m_sFirstPageStyleName = rPropNameSupplier.GetName( PROP_FIRST_PAGE );
     471        1976 :         m_sFollowPageStyleName = rPropNameSupplier.GetName( PROP_STANDARD );
     472        2261 :     }
     473        2261 : }
     474             : 
     475             : 
     476        6783 : SectionPropertyMap::~SectionPropertyMap()
     477             : {
     478       11305 :     for( sal_Int16 ePos = BORDER_LEFT; ePos <= BORDER_BOTTOM; ++ePos)
     479        9044 :         delete m_pBorderLines[ePos];
     480        4522 : }
     481             : 
     482             : 
     483         258 : OUString lcl_FindUnusedPageStyleName(const uno::Sequence< OUString >& rPageStyleNames)
     484             : {
     485             :     static const sal_Char cDefaultStyle[] = "Converted";
     486             :     //find the hightest number x in each style with the name "cDefaultStyle+x" and
     487             :     //return an incremented name
     488         258 :     sal_Int32 nMaxIndex = 0;
     489         258 :     const sal_Int32 nDefaultLength = sizeof(cDefaultStyle)/sizeof(sal_Char) - 1;
     490         258 :     const OUString sDefaultStyle( cDefaultStyle, nDefaultLength, RTL_TEXTENCODING_ASCII_US );
     491             : 
     492         258 :     const OUString* pStyleNames = rPageStyleNames.getConstArray();
     493        3870 :     for( sal_Int32 nStyle = 0; nStyle < rPageStyleNames.getLength(); ++nStyle)
     494             :     {
     495        5160 :         if( pStyleNames[nStyle].getLength() > nDefaultLength &&
     496        1548 :                 !rtl_ustr_compare_WithLength( sDefaultStyle.getStr(), nDefaultLength, pStyleNames[nStyle].getStr(), nDefaultLength))
     497             :         {
     498        1032 :             sal_Int32 nIndex = pStyleNames[nStyle].copy( nDefaultLength ).toInt32();
     499        1032 :             if( nIndex > nMaxIndex)
     500        1032 :                 nMaxIndex = nIndex;
     501             :         }
     502             :     }
     503         258 :     OUString sRet( sDefaultStyle );
     504         258 :     sRet += OUString::number( nMaxIndex + 1);
     505         258 :     return sRet;
     506             : }
     507             : 
     508             : 
     509             : 
     510        8191 : uno::Reference< beans::XPropertySet > SectionPropertyMap::GetPageStyle(
     511             :         const uno::Reference< container::XNameContainer >& xPageStyles,
     512             :         const uno::Reference < lang::XMultiServiceFactory >& xTextFactory,
     513             :         bool bFirst )
     514             : {
     515        8191 :     uno::Reference< beans::XPropertySet > xRet;
     516             :     try
     517             :     {
     518        8191 :         if( bFirst )
     519             :         {
     520        2445 :             if( m_sFirstPageStyleName.isEmpty() && xPageStyles.is() )
     521             :             {
     522          17 :                 uno::Sequence< OUString > aPageStyleNames = xPageStyles->getElementNames();
     523          17 :                 m_sFirstPageStyleName = lcl_FindUnusedPageStyleName(aPageStyleNames);
     524          34 :                 m_aFirstPageStyle = uno::Reference< beans::XPropertySet > (
     525          17 :                         xTextFactory->createInstance("com.sun.star.style.PageStyle"),
     526          17 :                         uno::UNO_QUERY);
     527             : 
     528             :                 // Call insertByName() before GetPageStyle(), otherwise the
     529             :                 // first and the follow page style will have the same name, and
     530             :                 // insertByName() will fail.
     531          17 :                 if (xPageStyles.is())
     532          17 :                     xPageStyles->insertByName( m_sFirstPageStyleName, uno::makeAny(m_aFirstPageStyle) );
     533             : 
     534             :                 // Ensure that m_aFollowPageStyle has been created
     535          17 :                 GetPageStyle( xPageStyles, xTextFactory, false );
     536             :                 // Chain m_aFollowPageStyle to be after m_aFirstPageStyle
     537          17 :                 m_aFirstPageStyle->setPropertyValue("FollowStyle",
     538          17 :                     uno::makeAny(m_sFollowPageStyleName));
     539             :             }
     540        2428 :             else if( !m_aFirstPageStyle.is() && xPageStyles.is() )
     541             :             {
     542        1910 :                 xPageStyles->getByName(m_sFirstPageStyleName) >>= m_aFirstPageStyle;
     543             :             }
     544        2445 :             xRet = m_aFirstPageStyle;
     545             :         }
     546             :         else
     547             :         {
     548        5746 :             if( m_sFollowPageStyleName.isEmpty() && xPageStyles.is() )
     549             :             {
     550         233 :                 uno::Sequence< OUString > aPageStyleNames = xPageStyles->getElementNames();
     551         233 :                 m_sFollowPageStyleName = lcl_FindUnusedPageStyleName(aPageStyleNames);
     552         466 :                 m_aFollowPageStyle = uno::Reference< beans::XPropertySet > (
     553         233 :                         xTextFactory->createInstance("com.sun.star.style.PageStyle"),
     554         233 :                         uno::UNO_QUERY);
     555         233 :                 xPageStyles->insertByName( m_sFollowPageStyleName, uno::makeAny(m_aFollowPageStyle) );
     556             :             }
     557        5513 :             else if(!m_aFollowPageStyle.is() && xPageStyles.is() )
     558             :             {
     559        1926 :                 xPageStyles->getByName(m_sFollowPageStyleName) >>= m_aFollowPageStyle;
     560             :             }
     561        5746 :             xRet = m_aFollowPageStyle;
     562             :         }
     563             : 
     564             :     }
     565           0 :     catch( const uno::Exception& rException )
     566             :     {
     567             :         SAL_WARN("writerfilter", "SectionPropertyMap::GetPageStyle() failed: " << rException.Message);
     568             :     }
     569             : 
     570        8191 :     return xRet;
     571             : }
     572             : 
     573             : 
     574         115 : void SectionPropertyMap::SetBorder( BorderPosition ePos, sal_Int32 nLineDistance, const table::BorderLine2& rBorderLine, bool bShadow )
     575             : {
     576         115 :     delete m_pBorderLines[ePos];
     577         115 :     m_pBorderLines[ePos] = new table::BorderLine2( rBorderLine );
     578         115 :     m_nBorderDistances[ePos] = nLineDistance;
     579         115 :     m_bBorderShadows[ePos] = bShadow;
     580         115 : }
     581             : 
     582             : 
     583        2143 : void SectionPropertyMap::ApplyBorderToPageStyles(
     584             :             const uno::Reference< container::XNameContainer >& xPageStyles,
     585             :             const uno::Reference < lang::XMultiServiceFactory >& xTextFactory,
     586             :         sal_Int32 nValue )
     587             : {
     588             :             /*
     589             :             page border applies to:
     590             :             nIntValue & 0x07 ->
     591             :             0 all pages in this section
     592             :             1 first page in this section
     593             :             2 all pages in this section but first
     594             :             3 whole document (all sections)
     595             :             nIntValue & 0x18 -> page border depth 0 - in front 1- in back
     596             :             nIntValue & 0xe0 ->
     597             :             page border offset from:
     598             :             0 offset from text
     599             :             1 offset from edge of page
     600             :             */
     601        2143 :     uno::Reference< beans::XPropertySet >  xFirst;
     602        4286 :     uno::Reference< beans::XPropertySet >  xSecond;
     603        2143 :     sal_Int32 nOffsetFrom = (nValue & 0x00E0) >> 5;
     604             :     //todo: negative spacing (from ww8par6.cxx)
     605        2143 :     switch( nValue & 0x07)
     606             :     {
     607             :         case 0: /*all styles*/
     608        2140 :             if ( !m_sFollowPageStyleName.isEmpty() )
     609        2140 :                 xFirst = GetPageStyle( xPageStyles, xTextFactory, false );
     610        2140 :             if ( !m_sFirstPageStyleName.isEmpty() )
     611        1942 :                 xSecond = GetPageStyle( xPageStyles, xTextFactory, true );
     612        2140 :         break;
     613             :         case 1: /*first page*/
     614           3 :             if ( !m_sFirstPageStyleName.isEmpty() )
     615           2 :                 xFirst = GetPageStyle( xPageStyles, xTextFactory, true );
     616           3 :         break;
     617             :         case 2: /*left and right*/
     618           0 :             if ( !m_sFollowPageStyleName.isEmpty() )
     619           0 :                 xFirst  = GetPageStyle( xPageStyles, xTextFactory, false );
     620           0 :         break;
     621             :         case 3: //whole document?
     622             :             //todo: how to apply a border to the whole document - find all sections or access all page styles?
     623             :         default:
     624        2143 :             return;
     625             :     }
     626             :     //has to be sorted like enum BorderPosition: l-r-t-b
     627             :     static const PropertyIds aBorderIds[4] =
     628             :     {
     629             :         PROP_LEFT_BORDER,
     630             :         PROP_RIGHT_BORDER,
     631             :         PROP_TOP_BORDER,
     632             :         PROP_BOTTOM_BORDER
     633             :     };
     634             :     static const PropertyIds aBorderDistanceIds[4] =
     635             :     {
     636             :         PROP_LEFT_BORDER_DISTANCE,
     637             :         PROP_RIGHT_BORDER_DISTANCE,
     638             :         PROP_TOP_BORDER_DISTANCE,
     639             :         PROP_BOTTOM_BORDER_DISTANCE
     640             :     };
     641             :     static const PropertyIds aMarginIds[4] =
     642             :     {
     643             :         PROP_LEFT_MARGIN,
     644             :         PROP_RIGHT_MARGIN,
     645             :         PROP_TOP_MARGIN,
     646             :         PROP_BOTTOM_MARGIN
     647             :     };
     648             : 
     649        2143 :     PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     650       10715 :     for( sal_Int32 nBorder = 0; nBorder < 4; ++nBorder)
     651             :     {
     652        8572 :         if( m_pBorderLines[nBorder] )
     653             :         {
     654         115 :             const OUString sBorderName = rPropNameSupplier.GetName( aBorderIds[nBorder] );
     655         115 :             if (xFirst.is())
     656         111 :                 xFirst->setPropertyValue( sBorderName, uno::makeAny( *m_pBorderLines[nBorder] ));
     657         115 :             if(xSecond.is())
     658          99 :                 xSecond->setPropertyValue( sBorderName, uno::makeAny( *m_pBorderLines[nBorder] ));
     659             :         }
     660        8572 :         if( m_nBorderDistances[nBorder] >= 0 )
     661             :         {
     662         115 :             sal_uInt32 nLineWidth = 0;
     663         115 :             if (m_pBorderLines[nBorder])
     664         115 :                 nLineWidth = m_pBorderLines[nBorder]->LineWidth;
     665         115 :             if(xFirst.is())
     666         111 :                 SetBorderDistance( xFirst, aMarginIds[nBorder], aBorderDistanceIds[nBorder],
     667         222 :                   m_nBorderDistances[nBorder], nOffsetFrom, nLineWidth );
     668         115 :             if(xSecond.is())
     669          99 :                 SetBorderDistance( xSecond, aMarginIds[nBorder], aBorderDistanceIds[nBorder],
     670         198 :                       m_nBorderDistances[nBorder], nOffsetFrom, nLineWidth );
     671             :         }
     672             :     }
     673             : 
     674        2143 :     if (m_bBorderShadows[BORDER_RIGHT])
     675             :     {
     676           7 :         table::ShadowFormat aFormat = getShadowFromBorder(*m_pBorderLines[BORDER_RIGHT]);
     677           7 :         if (xFirst.is())
     678           7 :             xFirst->setPropertyValue(rPropNameSupplier.GetName(PROP_SHADOW_FORMAT), uno::makeAny(aFormat));
     679           7 :         if (xSecond.is())
     680           7 :             xSecond->setPropertyValue(rPropNameSupplier.GetName(PROP_SHADOW_FORMAT), uno::makeAny(aFormat));
     681        2143 :     }
     682             : }
     683             : 
     684          25 : table::ShadowFormat PropertyMap::getShadowFromBorder(const table::BorderLine2& rBorder)
     685             : {
     686             :     // In Word UI, shadow is a boolean property, in OOXML, it's a boolean
     687             :     // property of each 4 border type, finally in Writer the border is a
     688             :     // property of the page style, with shadow location, distance and
     689             :     // color. See SwWW8ImplReader::SetShadow().
     690          25 :     table::ShadowFormat aFormat;
     691          25 :     aFormat.Color = COL_BLACK;
     692          25 :     aFormat.Location = table::ShadowLocation_BOTTOM_RIGHT;
     693          25 :     aFormat.ShadowWidth = rBorder.LineWidth;
     694          25 :     return aFormat;
     695             : }
     696             : 
     697         210 : void SectionPropertyMap::SetBorderDistance( uno::Reference< beans::XPropertySet > const& xStyle,
     698             :         PropertyIds eMarginId, PropertyIds eDistId, sal_Int32 nDistance, sal_Int32 nOffsetFrom, sal_uInt32 nLineWidth )
     699             : {
     700         210 :     PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     701             : 
     702         210 :     sal_Int32 nDist = nDistance;
     703         210 :     if( nOffsetFrom == 1 )
     704             :     {
     705         208 :         const OUString sMarginName = rPropNameSupplier.GetName( eMarginId );
     706         416 :         uno::Any aMargin = xStyle->getPropertyValue( sMarginName );
     707         208 :         sal_Int32 nMargin = 0;
     708         208 :         aMargin >>= nMargin;
     709             : 
     710             :         // Change the margins with the ( border distance - line width )
     711         208 :         xStyle->setPropertyValue( sMarginName, uno::makeAny( nDistance - nLineWidth ) );
     712             : 
     713             :         // Set the distance to ( Margin - distance )
     714         416 :         nDist = nMargin - nDistance;
     715             :     }
     716         210 :     const OUString sBorderDistanceName = rPropNameSupplier.GetName( eDistId );
     717         210 :     if (xStyle.is())
     718         210 :         xStyle->setPropertyValue( sBorderDistanceName, uno::makeAny( nDist ));
     719         210 : }
     720             : 
     721             : 
     722             : 
     723          47 : uno::Reference< text::XTextColumns > SectionPropertyMap::ApplyColumnProperties(
     724             :                             uno::Reference< beans::XPropertySet > const& xColumnContainer, DomainMapper_Impl& rDM_Impl )
     725             : {
     726          47 :     uno::Reference< text::XTextColumns > xColumns;
     727             :     try
     728             :     {
     729          47 :         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     730          47 :         const OUString sTextColumns = rPropNameSupplier.GetName( PROP_TEXT_COLUMNS );
     731          47 :         if (xColumnContainer.is())
     732          47 :             xColumnContainer->getPropertyValue(sTextColumns) >>= xColumns;
     733          94 :         uno::Reference< beans::XPropertySet > xColumnPropSet( xColumns, uno::UNO_QUERY_THROW );
     734         131 :         if( !m_bEvenlySpaced &&
     735          77 :                 (sal_Int32(m_aColWidth.size()) == (m_nColumnCount + 1 )) &&
     736          15 :                 ((sal_Int32(m_aColDistance.size()) == m_nColumnCount) || (sal_Int32(m_aColDistance.size()) == m_nColumnCount + 1)) )
     737             :         {
     738             :             //the column width in word is an absolute value, in OOo it's relative
     739             :             //the distances are both absolute
     740          15 :             sal_Int32 nColSum = 0;
     741          54 :             for( sal_Int32 nCol = 0; nCol <= m_nColumnCount; ++nCol)
     742             :             {
     743          39 :                 nColSum += m_aColWidth[nCol];
     744          39 :                 if(nCol)
     745          24 :                     nColSum += m_aColDistance[nCol -1];
     746             :             }
     747             : 
     748          15 :             sal_Int32 nRefValue = xColumns->getReferenceValue();
     749          15 :             double fRel = nColSum ? double( nRefValue ) / double( nColSum ) : 0.0;
     750          15 :             uno::Sequence< text::TextColumn > aColumns( m_nColumnCount + 1 );
     751          15 :             text::TextColumn* pColumn = aColumns.getArray();
     752             : 
     753          15 :             nColSum = 0;
     754          54 :             for( sal_Int32 nCol = 0; nCol <= m_nColumnCount; ++nCol)
     755             :             {
     756          39 :                 pColumn[nCol].LeftMargin = nCol ? m_aColDistance[nCol - 1 ] / 2 : 0;
     757          39 :                 pColumn[nCol].RightMargin = nCol == m_nColumnCount ? 0 : m_aColDistance[nCol] / 2;
     758          39 :                 pColumn[nCol].Width = sal_Int32((double( m_aColWidth[nCol] + pColumn[nCol].RightMargin + pColumn[nCol].LeftMargin ) + 0.5 ) * fRel );
     759          39 :                 nColSum += pColumn[nCol].Width;
     760             :             }
     761          15 :             if( nColSum != nRefValue )
     762          15 :                 pColumn[m_nColumnCount].Width -= ( nColSum - nRefValue );
     763          15 :             xColumns->setColumns( aColumns );
     764             :         }
     765             :         else
     766             :         {
     767          32 :             xColumns->setColumnCount( m_nColumnCount + 1 );
     768          32 :             xColumnPropSet->setPropertyValue( rPropNameSupplier.GetName( PROP_AUTOMATIC_DISTANCE ), uno::makeAny( m_nColumnDistance ));
     769             :         }
     770             : 
     771          47 :         if(m_bSeparatorLineIsOn)
     772           1 :             xColumnPropSet->setPropertyValue(
     773             :                 rPropNameSupplier.GetName( PROP_SEPARATOR_LINE_IS_ON ),
     774           1 :                 uno::makeAny( m_bSeparatorLineIsOn ));
     775          47 :         xColumnContainer->setPropertyValue( sTextColumns, uno::makeAny( xColumns ) );
     776             :         // Set the columns to be unbalanced if that compatibility option is set or this is the last section.
     777          47 :         if (rDM_Impl.GetSettingsTable()->GetNoColumnBalance() || rDM_Impl.GetIsLastSectionGroup())
     778          83 :             xColumnContainer->setPropertyValue("DontBalanceTextColumns", uno::makeAny(true));
     779             :     }
     780           5 :     catch( const uno::Exception& )
     781             :     {
     782             :         OSL_FAIL( "Exception in SectionPropertyMap::ApplyColumnProperties");
     783             :     }
     784          47 :     return xColumns;
     785             : }
     786             : 
     787             : 
     788             : 
     789        2346 : bool SectionPropertyMap::HasHeader(bool bFirstPage) const
     790             : {
     791        2346 :     bool bRet = false;
     792        2346 :     if( (bFirstPage && m_aFirstPageStyle.is()) ||( !bFirstPage && m_aFollowPageStyle.is()) )
     793             :     {
     794        2214 :         if( bFirstPage )
     795          74 :             m_aFirstPageStyle->getPropertyValue(
     796          74 :                     PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_HEADER_IS_ON) ) >>= bRet;
     797             :         else
     798        2140 :             m_aFollowPageStyle->getPropertyValue(
     799        2140 :                     PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_HEADER_IS_ON) ) >>= bRet;
     800             :     }
     801        2346 :     return bRet;
     802             : }
     803             : 
     804             : 
     805        2346 : bool SectionPropertyMap::HasFooter(bool bFirstPage) const
     806             : {
     807        2346 :     bool bRet = false;
     808        2346 :     if( (bFirstPage && m_aFirstPageStyle.is()) ||( !bFirstPage && m_aFollowPageStyle.is()) )
     809             :     {
     810        2214 :         if( bFirstPage )
     811          74 :             m_aFirstPageStyle->getPropertyValue(
     812          74 :                     PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_FOOTER_IS_ON) ) >>= bRet;
     813             :         else
     814        2140 :             m_aFollowPageStyle->getPropertyValue(
     815        2140 :                     PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_FOOTER_IS_ON) ) >>= bRet;
     816             :     }
     817        2346 :     return bRet;
     818             : }
     819             : 
     820             : 
     821             : #define MIN_HEAD_FOOT_HEIGHT 100 //minimum header/footer height
     822             : 
     823         236 : void SectionPropertyMap::CopyHeaderFooter( uno::Reference< beans::XPropertySet > xPrevStyle,
     824             :     uno::Reference< beans::XPropertySet > xStyle )
     825             : {
     826         236 :     PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     827             : 
     828             :     try {
     829             :         // Loop over the Header and Footer properties to copy them
     830             :         static const PropertyIds aProperties[] =
     831             :         {
     832             :             PROP_HEADER_TEXT,
     833             :             PROP_FOOTER_TEXT,
     834             :         };
     835             : 
     836         236 :         bool bHasPrevHeader = false;
     837         236 :         bool bHasHeader = false;
     838             : 
     839         236 :         OUString sHeaderIsOn = rPropNameSupplier.GetName( PROP_HEADER_IS_ON );
     840         236 :         if (xPrevStyle.is())
     841         236 :             xPrevStyle->getPropertyValue( sHeaderIsOn ) >>= bHasPrevHeader;
     842         236 :         if (xStyle.is())
     843         236 :             xStyle->getPropertyValue( sHeaderIsOn ) >>= bHasHeader;
     844         236 :         bool bCopyHeader = bHasPrevHeader && !bHasHeader;
     845             : 
     846         236 :         if ( bCopyHeader )
     847          46 :             xStyle->setPropertyValue( sHeaderIsOn, uno::makeAny( sal_True ) );
     848             : 
     849         236 :         bool bHasPrevFooter = false;
     850         236 :         bool bHasFooter = false;
     851             : 
     852         472 :         OUString sFooterIsOn = rPropNameSupplier.GetName( PROP_FOOTER_IS_ON );
     853         236 :         if (xPrevStyle.is())
     854         236 :             xPrevStyle->getPropertyValue( sFooterIsOn ) >>= bHasPrevFooter;
     855         236 :         if (xStyle.is())
     856         236 :             xStyle->getPropertyValue( sFooterIsOn ) >>= bHasFooter;
     857         236 :         bool bCopyFooter = bHasPrevFooter && !bHasFooter;
     858             : 
     859         236 :         if ( bCopyFooter && xStyle.is() )
     860          35 :             xStyle->setPropertyValue( sFooterIsOn, uno::makeAny( sal_True ) );
     861             : 
     862             :         // Copying the text properties
     863         708 :         for ( int i = 0, nNbProps = 2; i < nNbProps; i++ )
     864             :         {
     865         472 :             bool bIsHeader = ( i < nNbProps / 2 );
     866         472 :             PropertyIds aPropId = aProperties[i];
     867         472 :             OUString sName = rPropNameSupplier.GetName( aPropId );
     868             : 
     869         472 :             if ( ( bIsHeader && bCopyHeader ) || ( !bIsHeader && bCopyFooter ) )
     870             :             {
     871             :                 SAL_INFO("writerfilter", "Copying " << sName);
     872             :                 // TODO has to be copied
     873          81 :                 uno::Reference< text::XTextCopy > xTxt;
     874          81 :                 if (xStyle.is())
     875          81 :                     xTxt.set(xStyle->getPropertyValue( sName ), uno::UNO_QUERY_THROW );
     876             : 
     877         162 :                 uno::Reference< text::XTextCopy > xPrevTxt;
     878          81 :                 if (xPrevStyle.is())
     879          81 :                     xPrevTxt.set(xPrevStyle->getPropertyValue( sName ), uno::UNO_QUERY_THROW );
     880             : 
     881         162 :                 xTxt->copyText( xPrevTxt );
     882             :             }
     883         708 :         }
     884             :     }
     885           0 :     catch ( const uno::Exception& e )
     886             :     {
     887             :         SAL_INFO("writerfilter", "An exception occurred in SectionPropertyMap::CopyHeaderFooter( ) - " << e.Message);
     888             :     }
     889         236 : }
     890             : 
     891        2346 : void SectionPropertyMap::CopyLastHeaderFooter( bool bFirstPage, DomainMapper_Impl& rDM_Impl )
     892             : {
     893             :     SAL_INFO("writerfilter", "START>>> SectionPropertyMap::CopyLastHeaderFooter()");
     894        2346 :     SectionPropertyMap* pLastContext = rDM_Impl.GetLastSectionContext( );
     895        2346 :     if ( pLastContext )
     896             :     {
     897             :         uno::Reference< beans::XPropertySet > xPrevStyle = pLastContext->GetPageStyle(
     898             :                 rDM_Impl.GetPageStyles(),
     899             :                 rDM_Impl.GetTextFactory(),
     900         228 :                 bFirstPage );
     901             :         uno::Reference< beans::XPropertySet > xStyle = GetPageStyle(
     902             :                 rDM_Impl.GetPageStyles(),
     903             :                 rDM_Impl.GetTextFactory(),
     904         456 :                 bFirstPage );
     905         456 :         CopyHeaderFooter( xPrevStyle, xStyle );
     906             :     }
     907             :     SAL_INFO("writerfilter", "END>>> SectionPropertyMap::CopyLastHeaderFooter()");
     908        2346 : }
     909             : 
     910        2346 : void SectionPropertyMap::PrepareHeaderFooterProperties( bool bFirstPage )
     911             : {
     912        2346 :     sal_Int32 nTopMargin = m_nTopMargin;
     913        2346 :     sal_Int32 nHeaderTop = m_nHeaderTop;
     914        2346 :     if(HasHeader(bFirstPage))
     915             :     {
     916         456 :         nTopMargin = nHeaderTop;
     917         456 :         if( m_nTopMargin > 0 && m_nTopMargin > nHeaderTop )
     918         425 :             nHeaderTop = m_nTopMargin - nHeaderTop;
     919             :         else
     920          31 :             nHeaderTop = 0;
     921             : 
     922             :         //minimum header height 1mm
     923         456 :         if( nHeaderTop < MIN_HEAD_FOOT_HEIGHT )
     924          35 :             nHeaderTop = MIN_HEAD_FOOT_HEIGHT;
     925             :     }
     926             : 
     927             : 
     928        2346 :     if( m_nTopMargin >= 0 ) //fixed height header -> see WW8Par6.hxx
     929             :     {
     930        2346 :         Insert(PROP_HEADER_IS_DYNAMIC_HEIGHT, uno::makeAny( true ));
     931        2346 :         Insert(PROP_HEADER_DYNAMIC_SPACING, uno::makeAny( true ));
     932        2346 :         Insert(PROP_HEADER_BODY_DISTANCE, uno::makeAny( nHeaderTop - MIN_HEAD_FOOT_HEIGHT ));// ULSpace.Top()
     933        2346 :         Insert(PROP_HEADER_HEIGHT, uno::makeAny( nHeaderTop ));
     934             : 
     935             :     }
     936             :     else
     937             :     {
     938             :         //todo: old filter fakes a frame into the header/footer to support overlapping
     939             :         //current setting is completely wrong!
     940           0 :         Insert(PROP_HEADER_HEIGHT, uno::makeAny( nHeaderTop ));
     941           0 :         Insert(PROP_HEADER_BODY_DISTANCE, uno::makeAny( m_nTopMargin - nHeaderTop ));
     942           0 :         Insert(PROP_HEADER_IS_DYNAMIC_HEIGHT, uno::makeAny( false ));
     943           0 :         Insert(PROP_HEADER_DYNAMIC_SPACING, uno::makeAny( false ));
     944             :     }
     945             : 
     946        2346 :     sal_Int32 nBottomMargin = m_nBottomMargin;
     947        2346 :     sal_Int32 nHeaderBottom = m_nHeaderBottom;
     948        2346 :     if( HasFooter( bFirstPage ) )
     949             :     {
     950         446 :         nBottomMargin = nHeaderBottom;
     951         446 :         if( m_nBottomMargin > 0 && m_nBottomMargin > nHeaderBottom )
     952         411 :             nHeaderBottom = m_nBottomMargin - nHeaderBottom;
     953             :         else
     954          35 :             nHeaderBottom = 0;
     955         446 :         if( nHeaderBottom < MIN_HEAD_FOOT_HEIGHT )
     956          35 :             nHeaderBottom = MIN_HEAD_FOOT_HEIGHT;
     957             :     }
     958             : 
     959        2346 :     if( m_nBottomMargin >= 0 ) //fixed height footer -> see WW8Par6.hxx
     960             :     {
     961        2346 :         Insert(PROP_FOOTER_IS_DYNAMIC_HEIGHT, uno::makeAny( true ));
     962        2346 :         Insert(PROP_FOOTER_DYNAMIC_SPACING, uno::makeAny( true ));
     963        2346 :         Insert(PROP_FOOTER_BODY_DISTANCE, uno::makeAny( nHeaderBottom - MIN_HEAD_FOOT_HEIGHT));
     964        2346 :         Insert(PROP_FOOTER_HEIGHT, uno::makeAny( nHeaderBottom ));
     965             :     }
     966             :     else
     967             :     {
     968             :         //todo: old filter fakes a frame into the header/footer to support overlapping
     969             :         //current setting is completely wrong!
     970           0 :         Insert(PROP_FOOTER_IS_DYNAMIC_HEIGHT, uno::makeAny( false ));
     971           0 :         Insert(PROP_FOOTER_DYNAMIC_SPACING, uno::makeAny( false ));
     972           0 :         Insert(PROP_FOOTER_HEIGHT, uno::makeAny( m_nBottomMargin - nHeaderBottom ));
     973           0 :         Insert(PROP_FOOTER_BODY_DISTANCE, uno::makeAny( nHeaderBottom ));
     974             :     }
     975             : 
     976             :     //now set the top/bottom margin for the follow page style
     977        2346 :     Insert(PROP_TOP_MARGIN, uno::makeAny( nTopMargin ));
     978        2346 :     Insert(PROP_BOTTOM_MARGIN, uno::makeAny( nBottomMargin ));
     979        2346 : }
     980             : 
     981        2255 : uno::Reference<beans::XPropertySet> lcl_GetRangeProperties(bool bIsFirstSection,
     982             :         DomainMapper_Impl& rDM_Impl,
     983             :         uno::Reference<text::XTextRange> const& xStartingRange)
     984             : {
     985        2255 :     uno::Reference< beans::XPropertySet > xRangeProperties;
     986        2255 :     if (bIsFirstSection && rDM_Impl.GetBodyText().is())
     987             :     {
     988        1953 :         uno::Reference<container::XEnumerationAccess> xEnumAccess(rDM_Impl.GetBodyText(), uno::UNO_QUERY_THROW);
     989        3906 :         uno::Reference<container::XEnumeration> xEnum = xEnumAccess->createEnumeration();
     990        3906 :         xRangeProperties = uno::Reference<beans::XPropertySet>(xEnum->nextElement(), uno::UNO_QUERY_THROW);
     991             :     }
     992         302 :     else if (xStartingRange.is())
     993         282 :         xRangeProperties = uno::Reference<beans::XPropertySet>(xStartingRange, uno::UNO_QUERY_THROW);
     994        2255 :     return xRangeProperties;
     995             : }
     996             : 
     997        2192 : void SectionPropertyMap::HandleMarginsHeaderFooter(DomainMapper_Impl& rDM_Impl)
     998             : {
     999        2192 :     if( m_nDzaGutter > 0 )
    1000             :     {
    1001             :         //todo: iGutterPos from DocProperties are missing
    1002           0 :         if( m_bGutterRTL )
    1003           0 :             m_nRightMargin += m_nDzaGutter;
    1004             :         else
    1005           0 :             m_nLeftMargin += m_nDzaGutter;
    1006             :     }
    1007        2192 :     Insert(PROP_LEFT_MARGIN, uno::makeAny( m_nLeftMargin  ));
    1008        2192 :     Insert(PROP_RIGHT_MARGIN, uno::makeAny( m_nRightMargin ));
    1009             : 
    1010        2192 :     if (rDM_Impl.m_oBackgroundColor)
    1011          33 :         Insert(PROP_BACK_COLOR, uno::makeAny(*rDM_Impl.m_oBackgroundColor));
    1012        2192 :     if (!rDM_Impl.m_bHasFtnSep)
    1013             :         // Set footnote line width to zero, document has no footnote separator.
    1014        2033 :         Insert(PROP_FOOTNOTE_LINE_RELATIVE_WIDTH, uno::makeAny(sal_Int32(0)));
    1015             : 
    1016             :     /*** if headers/footers are available then the top/bottom margins of the
    1017             :       header/footer are copied to the top/bottom margin of the page
    1018             :       */
    1019        2192 :     CopyLastHeaderFooter( false, rDM_Impl );
    1020        2192 :     PrepareHeaderFooterProperties( false );
    1021        2192 : }
    1022             : 
    1023        2256 : void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
    1024             : {
    1025             :     // Text area width is known at the end of a section: decide if tables should be converted or not.
    1026        2256 :     std::vector<FloatingTableInfo>& rPendingFloatingTables = rDM_Impl.m_aPendingFloatingTables;
    1027        2256 :     sal_Int32 nTextAreaWidth = GetPageWidth() - GetLeftMargin() - GetRightMargin();
    1028        2256 :     uno::Reference<text::XTextAppendAndConvert> xBodyText( rDM_Impl.GetBodyText(), uno::UNO_QUERY );
    1029        2293 :     for (size_t i = 0; i < rPendingFloatingTables.size(); ++i)
    1030             :     {
    1031          37 :         FloatingTableInfo& rInfo = rPendingFloatingTables[i];
    1032             : 
    1033             :         // Count the layout width of the table.
    1034          37 :         sal_Int32 nTableWidth = rInfo.m_nTableWidth;
    1035          37 :         sal_Int32 nLeftMargin = 0;
    1036          37 :         if (rInfo.getPropertyValue("LeftMargin") >>= nLeftMargin)
    1037          37 :             nTableWidth += nLeftMargin;
    1038          37 :         sal_Int32 nRightMargin = 0;
    1039          37 :         if (rInfo.getPropertyValue("RightMargin") >>= nRightMargin)
    1040          37 :             nTableWidth += nRightMargin;
    1041             : 
    1042             :         // If the table is wider than the text area, then don't create a fly
    1043             :         // for the table: no wrapping will be performed anyway, but multi-page
    1044             :         // tables will be broken.
    1045             :         // If the position is relative to the edge of the page, then we always
    1046             :         // create the fly.
    1047             :         // If there are columns, always create the fly, otherwise the columns would
    1048             :         // restrict geometry of the table.
    1049         145 :         if ( ( rInfo.getPropertyValue("HoriOrientRelation") == text::RelOrientation::PAGE_FRAME ) ||
    1050         125 :              nTableWidth < nTextAreaWidth || ColumnCount() + 1 >= 2 )
    1051          24 :             xBodyText->convertToTextFrame(rInfo.m_xStart, rInfo.m_xEnd, rInfo.m_aFrameProperties);
    1052             :     }
    1053        2256 :     rPendingFloatingTables.clear();
    1054             : 
    1055        2256 :     PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
    1056        2256 :     if( m_nLnnMod )
    1057             :     {
    1058          27 :         bool bFirst = rDM_Impl.IsLineNumberingSet();
    1059          27 :         rDM_Impl.SetLineNumbering( m_nLnnMod, m_nLnc, m_ndxaLnn );
    1060          27 :         if( m_nLnnMin > 0 || (bFirst && m_nLnc == NS_ooxml::LN_Value_ST_LineNumberRestart_newSection))
    1061             :         {
    1062             :             //set the starting value at the beginning of the section
    1063             :             try
    1064             :             {
    1065           3 :                 uno::Reference< beans::XPropertySet > xRangeProperties;
    1066           3 :                 if( m_xStartingRange.is() )
    1067             :                 {
    1068           3 :                     xRangeProperties = uno::Reference< beans::XPropertySet >( m_xStartingRange, uno::UNO_QUERY_THROW );
    1069             :                 }
    1070             :                 else
    1071             :                 {
    1072             :                     //set the start value at the beginning of the document
    1073           0 :                     xRangeProperties = uno::Reference< beans::XPropertySet >( rDM_Impl.GetTextDocument()->getText()->getStart(), uno::UNO_QUERY_THROW );
    1074             :                 }
    1075           3 :                 xRangeProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_PARA_LINE_NUMBER_START_VALUE ), uno::makeAny( m_nLnnMin ));
    1076             :             }
    1077           0 :             catch( const uno::Exception& )
    1078             :             {
    1079             :                 OSL_FAIL( "Exception in SectionPropertyMap::CloseSectionGroup");
    1080             :             }
    1081             :         }
    1082             :     }
    1083             : 
    1084             :     // depending on the break type no page styles should be created
    1085             :     // If the section type is missing, but we have columns, then this should be
    1086             :     // handled as a continuous section break.
    1087        2256 :     if(m_nBreakType == static_cast<sal_Int32>(NS_ooxml::LN_Value_ST_SectionMark_continuous) || (m_nBreakType == -1 && m_nColumnCount > 0))
    1088             :     {
    1089             :         //todo: insert a section or access the already inserted section
    1090             :         uno::Reference< beans::XPropertySet > xSection =
    1091         112 :                                     rDM_Impl.appendTextSectionAfter( m_xStartingRange );
    1092         112 :         if( m_nColumnCount > 0 && xSection.is())
    1093          39 :             ApplyColumnProperties( xSection, rDM_Impl );
    1094         224 :         uno::Reference<beans::XPropertySet> xRangeProperties(lcl_GetRangeProperties(m_bIsFirstSection, rDM_Impl, m_xStartingRange));
    1095         112 :         if (xRangeProperties.is())
    1096             :         {
    1097         112 :             OUString aName = m_bTitlePage ? m_sFirstPageStyleName : m_sFollowPageStyleName;
    1098         112 :             if (!aName.isEmpty())
    1099             :             {
    1100             :                 try
    1101             :                 {
    1102          49 :                     xRangeProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_PAGE_DESC_NAME), uno::makeAny(aName));
    1103          49 :                     uno::Reference<beans::XPropertySet> xPageStyle (rDM_Impl.GetPageStyles()->getByName(aName), uno::UNO_QUERY_THROW);
    1104          49 :                     HandleMarginsHeaderFooter(rDM_Impl);
    1105          49 :                     if (rDM_Impl.IsNewDoc())
    1106          49 :                         _ApplyProperties(xPageStyle);
    1107             :                 }
    1108           0 :                 catch( const uno::Exception& )
    1109             :                 {
    1110             :                     SAL_WARN("writerfilter", "failed to set PageDescName!");
    1111             :                 }
    1112         112 :             }
    1113         112 :         }
    1114             :     }
    1115             :     // If the section is of type "New column" (0x01), then simply insert a column break.
    1116             :     // But only if there actually are columns on the page, otherwise a column break
    1117             :     // seems to be handled like a page break by MSO.
    1118        2144 :     else if(m_nBreakType == static_cast<sal_Int32>(NS_ooxml::LN_Value_ST_SectionMark_nextColumn) && m_nColumnCount > 0 )
    1119             :     {
    1120           1 :         uno::Reference< beans::XPropertySet > xRangeProperties;
    1121           1 :         if( m_xStartingRange.is() )
    1122             :         {
    1123           1 :             xRangeProperties = uno::Reference< beans::XPropertySet >( m_xStartingRange, uno::UNO_QUERY_THROW );
    1124             :         }
    1125             :         else
    1126             :         {
    1127             :             //set the start value at the beginning of the document
    1128           0 :             xRangeProperties = uno::Reference< beans::XPropertySet >( rDM_Impl.GetTextDocument()->getText()->getStart(), uno::UNO_QUERY_THROW );
    1129             :         }
    1130           1 :         xRangeProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_BREAK_TYPE), uno::makeAny(style::BreakType_COLUMN_BEFORE));
    1131             :     }
    1132             :     else
    1133             :     {
    1134             :         //get the properties and create appropriate page styles
    1135        2143 :         uno::Reference< beans::XPropertySet > xFollowPageStyle = GetPageStyle( rDM_Impl.GetPageStyles(), rDM_Impl.GetTextFactory(), false );
    1136             : 
    1137        2143 :         HandleMarginsHeaderFooter(rDM_Impl);
    1138             : 
    1139        4286 :         const OUString sTrayIndex = rPropNameSupplier.GetName( PROP_PRINTER_PAPER_TRAY_INDEX );
    1140        2143 :         if( m_nPaperBin >= 0 )
    1141           0 :             xFollowPageStyle->setPropertyValue( sTrayIndex, uno::makeAny( m_nPaperBin ) );
    1142        2143 :         if ( rDM_Impl.GetSettingsTable()->GetMirrorMarginSettings() )
    1143             :         {
    1144          13 :             Insert(PROP_PAGE_STYLE_LAYOUT, uno::makeAny(style::PageStyleLayout_MIRRORED));
    1145             :         }
    1146        4286 :         uno::Reference< text::XTextColumns > xColumns;
    1147        2143 :         if( m_nColumnCount > 0 )
    1148           8 :             xColumns = ApplyColumnProperties( xFollowPageStyle, rDM_Impl );
    1149             : 
    1150             :         //prepare text grid properties
    1151        2143 :         sal_Int32 nHeight = 1;
    1152        4286 :         boost::optional<PropertyMap::Property> pProp = getProperty(PROP_HEIGHT);
    1153        2143 :         if(pProp)
    1154        2143 :             pProp->second >>= nHeight;
    1155             : 
    1156        2143 :         sal_Int32 nWidth = 1;
    1157        2143 :         pProp = getProperty(PROP_WIDTH);
    1158        2143 :         if(pProp)
    1159        2143 :             pProp->second >>= nWidth;
    1160             : 
    1161        2143 :         text::WritingMode eWritingMode = text::WritingMode_LR_TB;
    1162        2143 :         pProp = getProperty(PROP_WRITING_MODE);
    1163        2143 :         if(pProp)
    1164         594 :             pProp->second >>= eWritingMode;
    1165             : 
    1166        2143 :         sal_Int32 nTextAreaHeight = eWritingMode == text::WritingMode_LR_TB ?
    1167        2143 :             nHeight - m_nTopMargin - m_nBottomMargin :
    1168        4286 :             nWidth - m_nLeftMargin - m_nRightMargin;
    1169             : 
    1170        2143 :         sal_Int32 nGridLinePitch = m_nGridLinePitch;
    1171             :         //sep.dyaLinePitch
    1172        2143 :         if (nGridLinePitch < 1 || nGridLinePitch > 31680)
    1173             :         {
    1174             :             SAL_WARN("writerfilter", "sep.dyaLinePitch outside legal range: " << nGridLinePitch);
    1175           0 :             nGridLinePitch = 1;
    1176             :         }
    1177             : 
    1178        2143 :         Insert(PROP_GRID_LINES, uno::makeAny( static_cast<sal_Int16>(nTextAreaHeight/nGridLinePitch)));
    1179             : 
    1180             :         // PROP_GRID_MODE
    1181        2143 :         Insert( PROP_GRID_MODE, uno::makeAny( static_cast<sal_Int16> (m_nGridType) ));
    1182        2143 :         if (m_nGridType == text::TextGridMode::LINES_AND_CHARS)
    1183             :         {
    1184           3 :             Insert( PROP_GRID_SNAP_TO_CHARS, uno::makeAny(m_bGridSnapToChars));
    1185             :         }
    1186             : 
    1187        2143 :         sal_Int32 nCharWidth = 423; //240 twip/ 12 pt
    1188             :         //todo: is '0' the right index here?
    1189        4286 :         const StyleSheetEntryPtr pEntry = rDM_Impl.GetStyleSheetTable()->FindStyleSheetByISTD(OUString::number(0, 16));
    1190        2143 :         if( pEntry.get( ) )
    1191             :         {
    1192           6 :             boost::optional<PropertyMap::Property> pPropHeight = pEntry->pProperties->getProperty(PROP_CHAR_HEIGHT_ASIAN);
    1193           6 :             if(pProp)
    1194             :             {
    1195           2 :                 double fHeight = 0;
    1196           2 :                 if( pPropHeight->second >>= fHeight )
    1197           2 :                     nCharWidth = ConversionHelper::convertTwipToMM100( (long)( fHeight * 20.0 + 0.5 ));
    1198           6 :             }
    1199             :         }
    1200             : 
    1201             :         //dxtCharSpace
    1202        2143 :         if(m_nDxtCharSpace)
    1203             :         {
    1204          68 :             sal_Int32 nCharSpace = m_nDxtCharSpace;
    1205             :             //main lives in top 20 bits, and is signed.
    1206          68 :             sal_Int32 nMain = (nCharSpace & 0xFFFFF000);
    1207          68 :             nMain /= 0x1000;
    1208          68 :             nCharWidth += ConversionHelper::convertTwipToMM100( nMain * 20 );
    1209             : 
    1210          68 :             sal_Int32 nFraction = (nCharSpace & 0x00000FFF);
    1211          68 :             nFraction = (nFraction * 20)/0xFFF;
    1212          68 :             nCharWidth += ConversionHelper::convertTwipToMM100( nFraction );
    1213             :         }
    1214        2143 :         Insert(PROP_GRID_BASE_HEIGHT, uno::makeAny( nCharWidth ));
    1215        2143 :         sal_Int32 nRubyHeight = nGridLinePitch - nCharWidth;
    1216        2143 :         if(nRubyHeight < 0 )
    1217         793 :             nRubyHeight = 0;
    1218        2143 :         Insert(PROP_GRID_RUBY_HEIGHT, uno::makeAny( nRubyHeight ));
    1219             : 
    1220             :         // #i119558#, force to set document as standard page mode,
    1221             :         // refer to ww8 import process function "SwWW8ImplReader::SetDocumentGrid"
    1222             :         try
    1223             :         {
    1224        2143 :             uno::Reference< beans::XPropertySet > xDocProperties;
    1225        2143 :             xDocProperties = uno::Reference< beans::XPropertySet >( rDM_Impl.GetTextDocument(), uno::UNO_QUERY_THROW );
    1226        2123 :             bool bSquaredPageMode = false;
    1227        2123 :             Insert(PROP_GRID_STANDARD_MODE, uno::makeAny( !bSquaredPageMode ));
    1228        2123 :             xDocProperties->setPropertyValue("DefaultPageMode", uno::makeAny( bSquaredPageMode ));
    1229             :         }
    1230          20 :         catch (const uno::Exception& rEx)
    1231             :         {
    1232             :             OSL_ENSURE( false, "Exception in SectionPropertyMap::CloseSectionGroup");
    1233             :             (void)rEx;
    1234             :         }
    1235             : 
    1236        2143 :         if (rDM_Impl.IsNewDoc())
    1237        2134 :             _ApplyProperties( xFollowPageStyle );
    1238             : 
    1239             :         //todo: creating a "First Page" style depends on HasTitlePage und _fFacingPage_
    1240        2143 :         if( m_bTitlePage )
    1241             :         {
    1242         154 :             CopyLastHeaderFooter( true, rDM_Impl );
    1243         154 :             PrepareHeaderFooterProperties( true );
    1244             :             uno::Reference< beans::XPropertySet > xFirstPageStyle = GetPageStyle(
    1245         154 :                                 rDM_Impl.GetPageStyles(), rDM_Impl.GetTextFactory(), true );
    1246         154 :             if (rDM_Impl.IsNewDoc())
    1247         154 :                 _ApplyProperties( xFirstPageStyle );
    1248             : 
    1249         154 :             sal_Int32 nPaperBin = m_nFirstPaperBin >= 0 ? m_nFirstPaperBin : m_nPaperBin >= 0 ? m_nPaperBin : 0;
    1250         154 :             if( nPaperBin )
    1251           0 :                 xFirstPageStyle->setPropertyValue( sTrayIndex, uno::makeAny( nPaperBin ) );
    1252         154 :             if( xColumns.is() )
    1253           0 :                 xFirstPageStyle->setPropertyValue(
    1254           0 :                     rPropNameSupplier.GetName( PROP_TEXT_COLUMNS ), uno::makeAny( xColumns ));
    1255             :         }
    1256             : 
    1257        2143 :         ApplyBorderToPageStyles( rDM_Impl.GetPageStyles( ), rDM_Impl.GetTextFactory( ), m_nBorderParams );
    1258             : 
    1259             :         try
    1260             :         {
    1261             :             {
    1262             :                 //now apply this break at the first paragraph of this section
    1263        2143 :                 uno::Reference<beans::XPropertySet> xRangeProperties(lcl_GetRangeProperties(m_bIsFirstSection, rDM_Impl, m_xStartingRange));
    1264             : 
    1265             :                 // Handle page breaks with odd/even page numbering. We need to use an extra page style for setting the page style
    1266             :                 // to left/right, because if we set it to the normal style, we'd set it to "First Page"/"Default Style", which would
    1267             :                 // break them (all default pages would be only left or right).
    1268        2143 :                 if (m_nBreakType == static_cast<sal_Int32>(NS_ooxml::LN_Value_ST_SectionMark_evenPage) || m_nBreakType == static_cast<sal_Int32>(NS_ooxml::LN_Value_ST_SectionMark_oddPage))
    1269             :                 {
    1270           8 :                     OUString* pageStyle = m_bTitlePage ? &m_sFirstPageStyleName : &m_sFollowPageStyleName;
    1271           8 :                     OUString evenOddStyleName = lcl_FindUnusedPageStyleName(rDM_Impl.GetPageStyles()->getElementNames());
    1272             :                     uno::Reference< beans::XPropertySet > evenOddStyle(
    1273          16 :                             rDM_Impl.GetTextFactory()->createInstance("com.sun.star.style.PageStyle"),
    1274          16 :                             uno::UNO_QUERY);
    1275             :                     // Unfortunately using setParent() does not work for page styles, so make a deep copy of the page style.
    1276          16 :                     uno::Reference< beans::XPropertySet > pageProperties( m_bTitlePage ? m_aFirstPageStyle : m_aFollowPageStyle );
    1277          16 :                     uno::Reference< beans::XPropertySetInfo > pagePropertiesInfo( pageProperties->getPropertySetInfo());
    1278          16 :                     uno::Sequence< beans::Property > propertyList( pagePropertiesInfo->getProperties());
    1279        1504 :                     for( int i = 0; i < propertyList.getLength(); ++i )
    1280             :                     {
    1281        1496 :                         if(( propertyList[i].Attributes & beans::PropertyAttribute::READONLY ) == 0 )
    1282        1416 :                             evenOddStyle->setPropertyValue( propertyList[ i ].Name, pageProperties->getPropertyValue( propertyList[ i ].Name ));
    1283             :                     }
    1284           8 :                     evenOddStyle->setPropertyValue("FollowStyle", uno::makeAny(*pageStyle));
    1285           8 :                     rDM_Impl.GetPageStyles()->insertByName( evenOddStyleName, uno::makeAny( evenOddStyle ) );
    1286           8 :                     evenOddStyle->setPropertyValue("HeaderIsOn", uno::makeAny(sal_False));
    1287           8 :                     evenOddStyle->setPropertyValue("FooterIsOn", uno::makeAny(sal_False));
    1288           8 :                     CopyHeaderFooter( pageProperties, evenOddStyle );
    1289           8 :                     *pageStyle = evenOddStyleName; // And use it instead of the original one (which is set as follow of this one).
    1290           8 :                     if (m_nBreakType == static_cast<sal_Int32>(NS_ooxml::LN_Value_ST_SectionMark_evenPage))
    1291           1 :                         evenOddStyle->setPropertyValue(rPropNameSupplier.GetName(PROP_PAGE_STYLE_LAYOUT), uno::makeAny(style::PageStyleLayout_LEFT));
    1292           7 :                     else if (m_nBreakType == static_cast<sal_Int32>(NS_ooxml::LN_Value_ST_SectionMark_oddPage))
    1293          15 :                         evenOddStyle->setPropertyValue(rPropNameSupplier.GetName(PROP_PAGE_STYLE_LAYOUT), uno::makeAny(style::PageStyleLayout_RIGHT));
    1294             :                 }
    1295             : 
    1296        2143 :                 if (xRangeProperties.is() && rDM_Impl.IsNewDoc())
    1297        2114 :                     xRangeProperties->setPropertyValue(
    1298             :                         rPropNameSupplier.GetName( PROP_PAGE_DESC_NAME ),
    1299             :                         uno::makeAny( m_bTitlePage ?  m_sFirstPageStyleName
    1300        2144 :                                       : m_sFollowPageStyleName ));
    1301             : 
    1302        2113 :                 if(m_bPageNoRestart || m_nPageNumber >= 0)
    1303             :                 {
    1304         110 :                     sal_Int16 nPageNumber = m_nPageNumber >= 0 ? static_cast< sal_Int16 >(m_nPageNumber) : 1;
    1305         110 :                     xRangeProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_PAGE_NUMBER_OFFSET ),
    1306         110 :                         uno::makeAny( nPageNumber ));
    1307        2143 :                 }
    1308             :             }
    1309             :         }
    1310          30 :         catch (const uno::Exception&)
    1311             :         {
    1312             :             OSL_FAIL( "Exception in SectionPropertyMap::CloseSectionGroup");
    1313        2143 :         }
    1314             :     }
    1315        2256 :     rDM_Impl.SetIsLastSectionGroup(false);
    1316        2256 :     rDM_Impl.SetIsFirstParagraphInSection(true);
    1317        2256 : }
    1318             : 
    1319       14022 : class NamedPropertyValue {
    1320             :     OUString m_aName;
    1321             : public:
    1322        4674 :     explicit NamedPropertyValue(const OUString& i_aStr)
    1323        4674 :         : m_aName(i_aStr)   { }
    1324      112006 :     bool operator() (beans::PropertyValue& aVal)
    1325      112006 :     {   return aVal.Name == m_aName;    }
    1326             : };
    1327        2337 : void SectionPropertyMap::_ApplyProperties(
    1328             :         uno::Reference< beans::XPropertySet > const& xStyle)
    1329             : {
    1330             :     uno::Reference<beans::XMultiPropertySet> const xMultiSet(xStyle,
    1331        2337 :             uno::UNO_QUERY);
    1332             : 
    1333        2357 :     std::vector<OUString> vNames;
    1334        2357 :     std::vector<uno::Any> vValues;
    1335             :     { //Convert GetPropertyValues() value into something useful
    1336        2337 :         uno::Sequence<beans::PropertyValue> vPropVals = GetPropertyValues();
    1337             : 
    1338             :         //Temporarily store the items that are in grab bags
    1339        4674 :         uno::Sequence<beans::PropertyValue> vCharVals;
    1340        4674 :         uno::Sequence<beans::PropertyValue> vParaVals;
    1341        2337 :         beans::PropertyValue* pCharGrabBag = std::find_if(vPropVals.begin(),vPropVals.end(),NamedPropertyValue("CharInteropGrabBag") );
    1342        2337 :         if (pCharGrabBag!=vPropVals.end())
    1343           0 :             (pCharGrabBag->Value)>>=vCharVals;
    1344        2337 :         beans::PropertyValue* pParaGrabBag = std::find_if(vPropVals.begin(),vPropVals.end(),NamedPropertyValue("ParaInteropGrabBag") );
    1345        2337 :         if (pParaGrabBag!=vPropVals.end())
    1346           0 :             (pParaGrabBag->Value)>>=vParaVals;
    1347             : 
    1348       58340 :         for (beans::PropertyValue* pIter = vPropVals.begin(); pIter!=vPropVals.end(); ++pIter)
    1349             :         {
    1350       56003 :             if(pIter!=pCharGrabBag && pIter!=pParaGrabBag)
    1351             :             {
    1352       56003 :                 vNames.push_back(pIter->Name);
    1353       56003 :                 vValues.push_back(pIter->Value);
    1354             :             }
    1355             :         }
    1356        2337 :         for (beans::PropertyValue* iter = vCharVals.begin(); iter!=vCharVals.end(); ++iter)
    1357             :         {
    1358           0 :             vNames.push_back(iter->Name);
    1359           0 :             vValues.push_back(iter->Value);
    1360             :         }
    1361        2337 :         for (beans::PropertyValue* iter = vParaVals.begin(); iter!=vParaVals.end(); ++iter)
    1362             :         {
    1363           0 :             vNames.push_back(iter->Name);
    1364           0 :             vValues.push_back(iter->Value);
    1365        2337 :         }
    1366             :     }
    1367        2337 :     if (xMultiSet.is())
    1368             :     {
    1369             :         try
    1370             :         {
    1371        2317 :             xMultiSet->setPropertyValues(comphelper::containerToSequence(vNames), comphelper::containerToSequence(vValues));
    1372             :         }
    1373           0 :         catch( const uno::Exception& )
    1374             :         {
    1375             :             OSL_FAIL( "Exception in SectionPropertyMap::_ApplyProperties");
    1376             :         }
    1377        4654 :         return;
    1378             :     }
    1379         465 :     for (size_t i = 0; i < vNames.size(); ++i)
    1380             :     {
    1381             :         try
    1382             :         {
    1383         445 :             if (xStyle.is())
    1384           0 :                 xStyle->setPropertyValue(vNames[i], vValues[i]);
    1385             :         }
    1386           0 :         catch( const uno::Exception& )
    1387             :         {
    1388             :             OSL_FAIL( "Exception in SectionPropertyMap::_ApplyProperties");
    1389             :         }
    1390          20 :     }
    1391             : }
    1392             : 
    1393           0 : sal_Int32 lcl_AlignPaperBin( sal_Int32 nSet )
    1394             : {
    1395             :     //default tray numbers are above 0xff
    1396           0 :     if( nSet > 0xff )
    1397           0 :         nSet = nSet >> 8;
    1398             :     //there are some special numbers which can't be handled easily
    1399             :     //1, 4, 15, manual tray, upper tray, auto select? see ww8atr.cxx
    1400             :     //todo: find out appropriate conversion
    1401           0 :     return nSet;
    1402             : }
    1403             : 
    1404             : 
    1405           0 : void SectionPropertyMap::SetPaperBin( sal_Int32 nSet )
    1406             : {
    1407           0 :     m_nPaperBin = lcl_AlignPaperBin( nSet );
    1408           0 : }
    1409             : 
    1410             : 
    1411           0 : void SectionPropertyMap::SetFirstPaperBin( sal_Int32 nSet )
    1412             : {
    1413           0 :     m_nFirstPaperBin = lcl_AlignPaperBin( nSet );
    1414           0 : }
    1415             : 
    1416             : 
    1417        2256 : sal_Int32 SectionPropertyMap::GetPageWidth()
    1418             : {
    1419        2256 :     return getProperty(PROP_WIDTH)->second.get<sal_Int32>();
    1420             : }
    1421             : 
    1422       51859 : StyleSheetPropertyMap::StyleSheetPropertyMap() :
    1423             :     mnCT_Spacing_line( 0 ),
    1424             :     mnCT_Spacing_lineRule( 0 ),
    1425             :     mbCT_TrPrBase_tblHeader( false ),
    1426             :     mnCT_TrPrBase_jc( 0 ),
    1427             :     mnCT_TblWidth_w( 0 ),
    1428             :     mnCT_TblWidth_type( 0 ),
    1429             :     mbCT_Spacing_lineSet( false ),
    1430             :     mbCT_Spacing_lineRuleSet( false ),
    1431             :     mbCT_TrPrBase_tblHeaderSet( false ),
    1432             :     mbCT_TrPrBase_jcSet( false ),
    1433             :     mbCT_TblWidth_wSet( false ),
    1434             :     mbCT_TblWidth_typeSet( false ),
    1435             :     mnListId( -1 ),
    1436             :     mnListLevel( -1 ),
    1437             :     mnOutlineLevel( -1 ),
    1438       51859 :     mnNumId( -1 )
    1439             : {
    1440       51859 : }
    1441             : 
    1442             : 
    1443      103718 : StyleSheetPropertyMap::~StyleSheetPropertyMap()
    1444             : {
    1445      103718 : }
    1446             : 
    1447             : 
    1448       84565 : ParagraphProperties::ParagraphProperties() :
    1449             :     m_bFrameMode( false ),
    1450             :     m_nDropCap(NS_ooxml::LN_Value_doc_ST_DropCap_none),
    1451             :     m_nLines(0),
    1452             :     m_w(-1),
    1453             :     m_h(-1),
    1454             :     m_nWrap(-1),
    1455             :     m_hAnchor(-1),
    1456             :     m_vAnchor(text::RelOrientation::FRAME),
    1457             :     m_x(-1),
    1458             :     m_bxValid( false ),
    1459             :     m_y(-1),
    1460             :     m_byValid( false ),
    1461             :     m_hSpace(-1),
    1462             :     m_vSpace(-1),
    1463             :     m_hRule(-1),
    1464             :     m_xAlign(-1),
    1465             :     m_yAlign(-1),
    1466             :     m_bAnchorLock(false),
    1467       84565 :     m_nDropCapLength(0)
    1468             : {
    1469       84565 : }
    1470             : 
    1471             : 
    1472         111 : ParagraphProperties::ParagraphProperties(const ParagraphProperties& rCopy) :
    1473             :     m_bFrameMode ( rCopy.m_bFrameMode),
    1474             :     m_nDropCap   ( rCopy.m_nDropCap),
    1475             :     m_nLines     ( rCopy.m_nLines),
    1476             :     m_w          ( rCopy.m_w),
    1477             :     m_h          ( rCopy.m_h),
    1478             :     m_nWrap      ( rCopy.m_nWrap),
    1479             :     m_hAnchor    ( rCopy.m_hAnchor),
    1480             :     m_vAnchor    ( rCopy.m_vAnchor),
    1481             :     m_x          ( rCopy.m_x),
    1482             :     m_bxValid    ( rCopy.m_bxValid),
    1483             :     m_y          ( rCopy.m_y),
    1484             :     m_byValid    ( rCopy.m_byValid),
    1485             :     m_hSpace     ( rCopy.m_hSpace),
    1486             :     m_vSpace     ( rCopy.m_vSpace),
    1487             :     m_hRule      ( rCopy.m_hRule),
    1488             :     m_xAlign     ( rCopy.m_xAlign),
    1489             :     m_yAlign     ( rCopy.m_yAlign),
    1490             :     m_bAnchorLock( rCopy.m_bAnchorLock),
    1491             :     m_nDropCapLength( rCopy.m_nDropCapLength ),
    1492             :     m_sParaStyleName( rCopy.m_sParaStyleName),
    1493             :     m_xStartingRange( rCopy.m_xStartingRange ),
    1494         111 :     m_xEndingRange( rCopy.m_xEndingRange)
    1495             : {
    1496         111 : }
    1497             : 
    1498             : 
    1499       84787 : ParagraphProperties::~ParagraphProperties()
    1500             : {
    1501       84787 : }
    1502             : 
    1503             : 
    1504         428 : bool ParagraphProperties::operator==(const ParagraphProperties& rCompare)
    1505             : {
    1506             :     return
    1507         752 :         m_bFrameMode == rCompare.m_bFrameMode &&
    1508         648 :         m_nDropCap   == rCompare.m_nDropCap &&
    1509         648 :         m_nLines     == rCompare.m_nLines &&
    1510         645 :         m_w          == rCompare.m_w &&
    1511         642 :         m_h          == rCompare.m_h &&
    1512         642 :         m_nWrap      == rCompare.m_nWrap &&
    1513         642 :         m_hAnchor    == rCompare.m_hAnchor &&
    1514         642 :         m_vAnchor    == rCompare.m_vAnchor &&
    1515         642 :         m_x          == rCompare.m_x &&
    1516         642 :         m_bxValid    == rCompare.m_bxValid &&
    1517         642 :         m_y          == rCompare.m_y &&
    1518         642 :         m_byValid    == rCompare.m_byValid &&
    1519         642 :         m_hSpace     == rCompare.m_hSpace &&
    1520         642 :         m_vSpace     == rCompare.m_vSpace &&
    1521         642 :         m_hRule      == rCompare.m_hRule &&
    1522         642 :         m_xAlign     == rCompare.m_xAlign &&
    1523        1070 :         m_yAlign     == rCompare.m_yAlign &&
    1524         749 :         m_bAnchorLock== rCompare.m_bAnchorLock;
    1525             : }
    1526             : 
    1527       31090 : void ParagraphProperties::ResetFrameProperties()
    1528             : {
    1529       31090 :     m_bFrameMode = false;
    1530       31090 :     m_nDropCap = NS_ooxml::LN_Value_doc_ST_DropCap_none;
    1531       31090 :     m_nLines = 0;
    1532       31090 :     m_w = -1;
    1533       31090 :     m_h = -1;
    1534       31090 :     m_nWrap = -1;
    1535       31090 :     m_hAnchor = -1;
    1536       31090 :     m_vAnchor = text::RelOrientation::FRAME;
    1537       31090 :     m_x = -1;
    1538       31090 :     m_bxValid = false;
    1539       31090 :     m_y = -1;
    1540       31090 :     m_byValid = false;
    1541       31090 :     m_hSpace = -1;
    1542       31090 :     m_vSpace = -1;
    1543       31090 :     m_hRule = -1;
    1544       31090 :     m_xAlign = -1;
    1545       31090 :     m_yAlign = -1;
    1546       31090 :     m_bAnchorLock = false;
    1547       31090 :     m_nDropCapLength = 0;
    1548       31090 : }
    1549             : 
    1550             : 
    1551       32706 : ParagraphPropertyMap::ParagraphPropertyMap()
    1552             : {
    1553       32706 : }
    1554             : 
    1555             : 
    1556       65412 : ParagraphPropertyMap::~ParagraphPropertyMap()
    1557             : {
    1558       65412 : }
    1559             : 
    1560             : 
    1561       60841 : TablePropertyMap::TablePropertyMap()
    1562             : {
    1563       60841 : }
    1564             : 
    1565             : 
    1566      121682 : TablePropertyMap::~TablePropertyMap()
    1567             : {
    1568      121682 : }
    1569             : 
    1570             : 
    1571       11463 : bool TablePropertyMap::getValue( TablePropertyMapTarget eWhich, sal_Int32& nFill )
    1572             : {
    1573       11463 :     if( eWhich < TablePropertyMapTarget_MAX )
    1574             :     {
    1575       11463 :         if(m_aValidValues[eWhich].bValid)
    1576        7111 :             nFill = m_aValidValues[eWhich].nValue;
    1577       11463 :         return m_aValidValues[eWhich].bValid;
    1578             :     }
    1579             :     else
    1580             :     {
    1581             :         OSL_FAIL( "invalid TablePropertyMapTarget");
    1582           0 :         return false;
    1583             :     }
    1584             : }
    1585             : 
    1586             : 
    1587       25483 : void TablePropertyMap::setValue( TablePropertyMapTarget eWhich, sal_Int32 nSet )
    1588             : {
    1589       25483 :     if( eWhich < TablePropertyMapTarget_MAX )
    1590             :     {
    1591       25483 :         m_aValidValues[eWhich].bValid = true;
    1592       25483 :         m_aValidValues[eWhich].nValue = nSet;
    1593             :     }
    1594             :     else
    1595             :         OSL_FAIL( "invalid TablePropertyMapTarget");
    1596       25483 : }
    1597             : 
    1598             : 
    1599       35137 : void TablePropertyMap::insertTableProperties( const PropertyMap* pMap )
    1600             : {
    1601             : #ifdef DEBUG_WRITERFILTER
    1602             :     TagLogger::getInstance().startElement("TablePropertyMap.insertTableProperties");
    1603             :     pMap->dumpXml();
    1604             : #endif
    1605             : 
    1606       35137 :     const TablePropertyMap* pSource = dynamic_cast< const TablePropertyMap* >(pMap);
    1607       35137 :     if( pSource )
    1608             :     {
    1609      326970 :         for( sal_Int32 eTarget = TablePropertyMapTarget_START;
    1610             :             eTarget < TablePropertyMapTarget_MAX; ++eTarget )
    1611             :         {
    1612      294273 :             if( pSource->m_aValidValues[eTarget].bValid )
    1613             :             {
    1614       21984 :                 m_aValidValues[eTarget].bValid = true;
    1615       21984 :                 m_aValidValues[eTarget].nValue = pSource->m_aValidValues[eTarget].nValue;
    1616             :             }
    1617             :         }
    1618             :     }
    1619             : #ifdef DEBUG_WRITERFILTER
    1620             :     dumpXml();
    1621             :     TagLogger::getInstance().endElement();
    1622             : #endif
    1623       35137 : }
    1624             : 
    1625             : 
    1626             : }//namespace dmapper
    1627             : }//namespace writerfilter
    1628             : 
    1629             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11