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

Generated by: LCOV version 1.10