LCOV - code coverage report
Current view: top level - xmloff/source/style - impastpl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 197 335 58.8 %
Date: 2014-04-11 Functions: 20 27 74.1 %
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             : 
      20             : #include <algorithm>
      21             : 
      22             : #include <rtl/ustrbuf.hxx>
      23             : #include <tools/debug.hxx>
      24             : #include <xmloff/PageMasterStyleMap.hxx>
      25             : #include <xmloff/attrlist.hxx>
      26             : #include <xmloff/families.hxx>
      27             : #include <xmloff/nmspmap.hxx>
      28             : #include <xmloff/xmlaustp.hxx>
      29             : #include <xmloff/xmlexp.hxx>
      30             : #include <xmloff/xmlexppr.hxx>
      31             : #include <xmloff/xmlnmspe.hxx>
      32             : #include <xmloff/xmlprmap.hxx>
      33             : #include <xmloff/xmltoken.hxx>
      34             : 
      35             : #include "impastpl.hxx"
      36             : 
      37             : using namespace ::std;
      38             : 
      39             : using namespace ::com::sun::star;
      40             : using namespace ::xmloff::token;
      41             : 
      42             : // Class XMLAutoStyleFamily
      43             : // ctor/dtor class XMLAutoStyleFamily
      44             : 
      45        8270 : XMLAutoStyleFamily::XMLAutoStyleFamily(
      46             :         sal_Int32 nFamily,
      47             :         const OUString& rStrName,
      48             :         const UniReference < SvXMLExportPropertyMapper > &rMapper,
      49             :         const OUString& rStrPrefix,
      50             :         bool bAsFamily ) :
      51             :     mnFamily( nFamily ), maStrFamilyName( rStrName), mxMapper( rMapper ),
      52        8270 :     mnCount( 0 ), mnName( 0 ), maStrPrefix( rStrPrefix ), mbAsFamily( bAsFamily )
      53        8270 : {}
      54             : 
      55       15179 : XMLAutoStyleFamily::XMLAutoStyleFamily( sal_Int32 nFamily ) :
      56       15179 :     mnFamily(nFamily), mnCount(0), mnName(0), mbAsFamily(false) {}
      57             : 
      58       23449 : XMLAutoStyleFamily::~XMLAutoStyleFamily() {}
      59             : 
      60          24 : void XMLAutoStyleFamily::ClearEntries()
      61             : {
      62          24 :     maParentSet.clear();
      63          24 : }
      64             : 
      65             : static OUString
      66             : data2string(void *data,
      67             :             const typelib_TypeDescriptionReference *type);
      68             : 
      69             : static OUString
      70           0 : struct2string(void *data,
      71             :               const typelib_TypeDescription *type)
      72             : {
      73             :     assert(type->eTypeClass == typelib_TypeClass_STRUCT);
      74             : 
      75           0 :     OUStringBuffer result;
      76             : 
      77           0 :     result.append("{");
      78             : 
      79             :     const typelib_CompoundTypeDescription *compoundType =
      80           0 :         &((const typelib_StructTypeDescription*) type)->aBase;
      81             : 
      82           0 :     for (int i = 0; i < compoundType->nMembers; i++)
      83             :     {
      84           0 :         if (i > 0)
      85           0 :             result.append(":");
      86           0 :         result.append(compoundType->ppMemberNames[i]);
      87           0 :         result.append("=");
      88           0 :         result.append(data2string(((char *)data)+compoundType->pMemberOffsets[i],
      89           0 :                                   compoundType->ppTypeRefs[i]));
      90             :     }
      91             : 
      92           0 :     result.append("}");
      93             : 
      94           0 :     return result.makeStringAndClear();
      95             : }
      96             : 
      97             : static OUString
      98           0 : data2string(void *data,
      99             :             const typelib_TypeDescriptionReference *type)
     100             : {
     101           0 :     OUStringBuffer result;
     102             : 
     103           0 :     switch (type->eTypeClass)
     104             :     {
     105             :     case typelib_TypeClass_VOID:
     106           0 :         break;
     107             :     case typelib_TypeClass_BOOLEAN:
     108           0 :         result.append((*reinterpret_cast<const sal_Bool*>(data) == sal_False ) ? OUString("false") : OUString("true"));
     109           0 :         break;
     110             :     case typelib_TypeClass_BYTE:
     111           0 :         result.append(OUString::number((*reinterpret_cast<const sal_Int8*>(data))));
     112           0 :         break;
     113             :     case typelib_TypeClass_SHORT:
     114           0 :         result.append(OUString::number((*reinterpret_cast<const sal_Int16*>(data))));
     115           0 :         break;
     116             :     case typelib_TypeClass_LONG:
     117           0 :         result.append(OUString::number((*reinterpret_cast<const sal_Int32*>(data))));
     118           0 :         break;
     119             :     case typelib_TypeClass_HYPER:
     120           0 :         result.append(OUString::number((*reinterpret_cast<const sal_Int64*>(data))));
     121           0 :         break;
     122             :     case typelib_TypeClass_UNSIGNED_SHORT:
     123           0 :         result.append(OUString::number((*reinterpret_cast<const sal_uInt16*>(data))));
     124           0 :         break;
     125             :     case typelib_TypeClass_UNSIGNED_LONG:
     126           0 :         result.append(OUString::number((*reinterpret_cast<const sal_uInt32*>(data)), 16));
     127           0 :         break;
     128             :     case typelib_TypeClass_UNSIGNED_HYPER:
     129           0 :         result.append(OUString::number((*reinterpret_cast<const sal_uInt64*>(data)), 16));
     130           0 :         break;
     131             :     case typelib_TypeClass_FLOAT:
     132           0 :         result.append(OUString::number((*reinterpret_cast<const float*>(data))));
     133           0 :         break;
     134             :     case typelib_TypeClass_DOUBLE:
     135           0 :         result.append(OUString::number((*reinterpret_cast<const double*>(data))));
     136           0 :         break;
     137             :     case typelib_TypeClass_CHAR:
     138           0 :         result.append("U+");
     139           0 :         result.append(OUString::number((*reinterpret_cast<const sal_uInt16*>(data))));
     140           0 :         break;
     141             :     case typelib_TypeClass_STRING:
     142           0 :         result.append(*reinterpret_cast<OUString*>(data));
     143           0 :         break;
     144             :     case typelib_TypeClass_TYPE:
     145             :     case typelib_TypeClass_SEQUENCE:
     146             :     case typelib_TypeClass_EXCEPTION:
     147             :     case typelib_TypeClass_INTERFACE:
     148           0 :         result.append("wtf");
     149           0 :         break;
     150             :     case typelib_TypeClass_STRUCT:
     151           0 :         result.append(struct2string(data, type->pType));
     152           0 :         break;
     153             :     case typelib_TypeClass_ENUM:
     154           0 :         result.append(OUString::number((*reinterpret_cast<const sal_Int32*>(data))));
     155           0 :         break;
     156             :     default:
     157             :         assert(false); // this cannot happen I hope
     158           0 :         break;
     159             :     }
     160             : 
     161           0 :     return result.makeStringAndClear();
     162             : }
     163             : 
     164             : static OUString
     165           0 : any2string(uno::Any any)
     166             : {
     167           0 :     return data2string((void*)any.getValue(), any.pType);
     168             : }
     169             : 
     170             : // Class SvXMLAutoStylePoolProperties_Impl
     171             : // ctor class SvXMLAutoStylePoolProperties_Impl
     172             : 
     173        2429 : XMLAutoStylePoolProperties::XMLAutoStylePoolProperties( XMLAutoStyleFamily& rFamilyData, const vector< XMLPropertyState >& rProperties, OUString& rParentName )
     174             : : maProperties( rProperties ),
     175        2429 :   mnPos       ( rFamilyData.mnCount )
     176             : {
     177        2429 :     static bool bHack = (getenv("LIBO_ONEWAY_STABLE_ODF_EXPORT") != NULL);
     178             : 
     179        2429 :     if (bHack)
     180             :     {
     181           0 :         OUStringBuffer aStemBuffer(32);
     182           0 :         aStemBuffer.append( rFamilyData.maStrPrefix );
     183             : 
     184           0 :         if (rParentName != "")
     185             :             {
     186           0 :                 aStemBuffer.append("-");
     187           0 :                 aStemBuffer.append(rParentName);
     188             :             }
     189             : 
     190             :         // Create a name based on the properties used
     191           0 :         for( size_t i = 0, n = maProperties.size(); i < n; ++i )
     192             :             {
     193           0 :                 XMLPropertyState& rState = maProperties[i];
     194           0 :                 if (rState.mnIndex == -1)
     195           0 :                     continue;
     196           0 :                 OUString sXMLName(rFamilyData.mxMapper->getPropertySetMapper()->GetEntryXMLName(rState.mnIndex));
     197           0 :                 if (sXMLName == "")
     198           0 :                     continue;
     199           0 :                 aStemBuffer.append("-");
     200           0 :                 aStemBuffer.append(OUString::number(rFamilyData.mxMapper->getPropertySetMapper()->GetEntryNameSpace(rState.mnIndex)));
     201           0 :                 aStemBuffer.append(":");
     202           0 :                 aStemBuffer.append(sXMLName);
     203           0 :                 aStemBuffer.append("=");
     204           0 :                 aStemBuffer.append(any2string(rState.maValue));
     205           0 :             }
     206             : 
     207             : #if 0
     208             :         // Finally append an incremental counter in an attempt to make identical
     209             :         // styles always come out in the same order. Will see if this works.
     210             :         aStemBuffer.append("-z");
     211             :         static sal_Int32 nCounter = 0;
     212             :         aStemBuffer.append(OUString::number(nCounter++));
     213             : #endif
     214             : 
     215             :         // create a name that hasn't been used before. The created name has not
     216             :         // to be added to the array, because it will never tried again
     217           0 :         OUStringBuffer aTry( aStemBuffer );
     218             : 
     219           0 :         msName = aTry.makeStringAndClear();
     220           0 :         bool bWarned = false;
     221           0 :         while (rFamilyData.maNameSet.find(msName) !=
     222           0 :                rFamilyData.maNameSet.end())
     223             :         {
     224           0 :             if (!bWarned)
     225             :                 SAL_WARN("xmloff", "Overlapping style name for " << msName);
     226           0 :             bWarned = true;
     227           0 :             rFamilyData.mnName++;
     228           0 :             aTry.append( aStemBuffer );
     229           0 :             aTry.append( "-" );
     230           0 :             aTry.append( OUString::number( rFamilyData.mnName ) );
     231           0 :             msName = aTry.makeStringAndClear();
     232             :         }
     233           0 :         rFamilyData.maNameSet.insert(msName);
     234             :     }
     235             :     else
     236             :     {
     237             :         // create a name that hasn't been used before. The created name has not
     238             :         // to be added to the array, because it will never tried again
     239        2429 :         OUStringBuffer sBuffer( 7 );
     240        4858 :         do
     241             :         {
     242        2429 :             rFamilyData.mnName++;
     243        2429 :             sBuffer.append( rFamilyData.maStrPrefix );
     244        2429 :             sBuffer.append( OUString::number( rFamilyData.mnName ) );
     245        2429 :             msName = sBuffer.makeStringAndClear();
     246             :         }
     247        7287 :         while (rFamilyData.maNameSet.find(msName) != rFamilyData.maNameSet.end());
     248             :     }
     249        2429 : }
     250             : 
     251       88740 : bool operator<( const XMLAutoStyleFamily& r1, const XMLAutoStyleFamily& r2)
     252             : {
     253       88740 :     return r1.mnFamily < r2.mnFamily;
     254             : }
     255             : 
     256             : 
     257        3508 : XMLAutoStylePoolParent::~XMLAutoStylePoolParent()
     258             : {
     259        3508 : }
     260             : 
     261             : // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list
     262             : // if not added, yet.
     263             : 
     264        2773 : sal_Bool XMLAutoStylePoolParent::Add( XMLAutoStyleFamily& rFamilyData, const vector< XMLPropertyState >& rProperties, OUString& rName, bool bDontSeek )
     265             : {
     266        2773 :     sal_Bool bAdded = sal_False;
     267        2773 :     XMLAutoStylePoolProperties *pProperties = 0;
     268        2773 :     sal_Int32 nProperties = rProperties.size();
     269        2773 :     size_t i = 0;
     270        9646 :     for (size_t n = maPropertiesList.size(); i < n; ++i)
     271             :     {
     272        8759 :         XMLAutoStylePoolProperties* pIS = &maPropertiesList[i];
     273        8759 :         if( nProperties > (sal_Int32)pIS->GetProperties().size() )
     274             :         {
     275        5205 :             continue;
     276             :         }
     277        3554 :         else if( nProperties < (sal_Int32)pIS->GetProperties().size() )
     278             :         {
     279        1542 :             break;
     280             :         }
     281        2012 :         else if( !bDontSeek && rFamilyData.mxMapper->Equals( pIS->GetProperties(), rProperties ) )
     282             :         {
     283         344 :             pProperties = pIS;
     284         344 :             break;
     285             :         }
     286             :     }
     287             : 
     288        2773 :     if( !pProperties )
     289             :     {
     290        2429 :         pProperties = new XMLAutoStylePoolProperties( rFamilyData, rProperties, msParent );
     291        2429 :         PropertiesListType::iterator it = maPropertiesList.begin();
     292        2429 :         ::std::advance( it, i );
     293        2429 :         maPropertiesList.insert( it, pProperties );
     294        2429 :         bAdded = sal_True;
     295             :     }
     296             : 
     297        2773 :     rName = pProperties->GetName();
     298             : 
     299        2773 :     return bAdded;
     300             : }
     301             : 
     302             : 
     303             : // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) with a given name.
     304             : // If the name exists already, nothing is done. If a style with a different name and
     305             : // the same properties exists, a new one is added (like with bDontSeek).
     306             : 
     307             : 
     308           0 : sal_Bool XMLAutoStylePoolParent::AddNamed( XMLAutoStyleFamily& rFamilyData, const vector< XMLPropertyState >& rProperties, const OUString& rName )
     309             : {
     310           0 :     sal_Bool bAdded = sal_False;
     311           0 :     sal_Int32 nProperties = rProperties.size();
     312           0 :     size_t i = 0;
     313           0 :     for (size_t n = maPropertiesList.size(); i < n; ++i)
     314             :     {
     315           0 :         XMLAutoStylePoolProperties* pIS = &maPropertiesList[i];
     316           0 :         if( nProperties > (sal_Int32)pIS->GetProperties().size() )
     317             :         {
     318           0 :             continue;
     319             :         }
     320           0 :         else if( nProperties < (sal_Int32)pIS->GetProperties().size() )
     321             :         {
     322           0 :             break;
     323             :         }
     324             :     }
     325             : 
     326           0 :     if (rFamilyData.maNameSet.find(rName) == rFamilyData.maNameSet.end())
     327             :     {
     328             :         XMLAutoStylePoolProperties* pProperties =
     329           0 :                 new XMLAutoStylePoolProperties( rFamilyData, rProperties, msParent );
     330             :         // ignore the generated name
     331           0 :         pProperties->SetName( rName );
     332           0 :         PropertiesListType::iterator it = maPropertiesList.begin();
     333           0 :         ::std::advance( it, i );
     334           0 :         maPropertiesList.insert( it, pProperties );
     335           0 :         bAdded = sal_True;
     336             :     }
     337             : 
     338           0 :     return bAdded;
     339             : }
     340             : 
     341             : 
     342             : // Search for a array of XMLPropertyState ( vector< XMLPropertyState > ) in list
     343             : 
     344             : 
     345         277 : OUString XMLAutoStylePoolParent::Find( const XMLAutoStyleFamily& rFamilyData, const vector< XMLPropertyState >& rProperties ) const
     346             : {
     347         277 :     OUString sName;
     348         277 :     vector< XMLPropertyState>::size_type nItems = rProperties.size();
     349         437 :     for (size_t i = 0, n = maPropertiesList.size(); i < n; ++i)
     350             :     {
     351         405 :         const XMLAutoStylePoolProperties* pIS = &maPropertiesList[i];
     352         405 :         if( nItems > pIS->GetProperties().size() )
     353             :         {
     354         111 :             continue;
     355             :         }
     356         294 :         else if( nItems < pIS->GetProperties().size() )
     357             :         {
     358          28 :             break;
     359             :         }
     360         266 :         else if( rFamilyData.mxMapper->Equals( pIS->GetProperties(), rProperties ) )
     361             :         {
     362         217 :             sName = pIS->GetName();
     363         217 :             break;
     364             :         }
     365             :     }
     366             : 
     367         277 :     return sName;
     368             : }
     369             : 
     370        5438 : bool XMLAutoStylePoolParent::operator< (const XMLAutoStylePoolParent& rOther) const
     371             : {
     372        5438 :     return msParent < rOther.msParent;
     373             : }
     374             : 
     375             : // Class SvXMLAutoStylePool_Impl
     376             : // ctor/dtor class SvXMLAutoStylePool_Impl
     377             : 
     378        1383 : SvXMLAutoStylePoolP_Impl::SvXMLAutoStylePoolP_Impl( SvXMLExport& rExp)
     379        1383 :     :   rExport( rExp )
     380             : {
     381        1383 : }
     382             : 
     383        1383 : SvXMLAutoStylePoolP_Impl::~SvXMLAutoStylePoolP_Impl()
     384             : {
     385        1383 : }
     386             : 
     387             : // Adds stylefamily-information to sorted list
     388             : 
     389        8270 : void SvXMLAutoStylePoolP_Impl::AddFamily(
     390             :         sal_Int32 nFamily,
     391             :         const OUString& rStrName,
     392             :         const UniReference < SvXMLExportPropertyMapper > & rMapper,
     393             :            const OUString& rStrPrefix,
     394             :         sal_Bool bAsFamily )
     395             : {
     396             :     // store family in a list if not already stored
     397        8270 :     sal_uInt16 nExportFlags = GetExport().getExportFlags();
     398        8270 :     sal_Bool bStylesOnly = (nExportFlags & EXPORT_STYLES) != 0 && (nExportFlags & EXPORT_CONTENT) == 0;
     399             : 
     400        8270 :     OUString aPrefix( rStrPrefix );
     401        8270 :     if( bStylesOnly )
     402             :     {
     403        2312 :         aPrefix = OUString( 'M' );
     404        2312 :         aPrefix += rStrPrefix;
     405             :     }
     406             : 
     407             : #if OSL_DEBUG_LEVEL > 0
     408             :     XMLAutoStyleFamily aTemporary( nFamily );
     409             :     FamilySetType::iterator aFind = maFamilySet.find(aTemporary);
     410             :     if( aFind != maFamilySet.end() )
     411             :     {
     412             :         // FIXME: do we really intend to replace the previous nFamily
     413             :         // entry in this case ?
     414             :         SAL_WARN_IF( aFind->mxMapper != rMapper, "xmloff",
     415             :                      "Adding duplicate family " << rStrName <<
     416             :                      " with mismatching mapper ! " <<
     417             :                      typeid(*aFind->mxMapper.get()).name() << " " <<
     418             :                      typeid(*rMapper.get()).name() );
     419             :     }
     420             : #endif
     421             : 
     422        8270 :     XMLAutoStyleFamily *pFamily = new XMLAutoStyleFamily( nFamily, rStrName, rMapper, aPrefix, bAsFamily );
     423        8270 :     maFamilySet.insert(pFamily);
     424        8270 : }
     425             : 
     426           0 : void SvXMLAutoStylePoolP_Impl::SetFamilyPropSetMapper(
     427             :         sal_Int32 nFamily,
     428             :         const UniReference < SvXMLExportPropertyMapper > & rMapper )
     429             : {
     430             : 
     431           0 :     XMLAutoStyleFamily aTemporary( nFamily );
     432           0 :     FamilySetType::iterator aFind = maFamilySet.find(aTemporary);
     433           0 :     if (aFind != maFamilySet.end())
     434           0 :         aFind->mxMapper = rMapper;
     435           0 : }
     436             : 
     437             : // Adds a name to list
     438        9172 : void SvXMLAutoStylePoolP_Impl::RegisterName( sal_Int32 nFamily, const OUString& rName )
     439             : {
     440        9172 :     XMLAutoStyleFamily aTmp( nFamily );
     441        9172 :     FamilySetType::iterator aFind = maFamilySet.find(aTmp);
     442             :     DBG_ASSERT( aFind != maFamilySet.end(),
     443             :                 "SvXMLAutoStylePool_Impl::RegisterName: unknown family" );
     444        9172 :     if (aFind != maFamilySet.end())
     445             :     {
     446             :         // SAL_DEBUG("SvXMLAutoStylePoolP_Impl::RegisterName: " << nFamily << ", '" << rName << "'");
     447        9172 :         aFind->maNameSet.insert(rName);
     448        9172 :     }
     449        9172 : }
     450             : 
     451             : 
     452             : // Retrieve the list of registered names
     453             : 
     454             : 
     455          59 : void SvXMLAutoStylePoolP_Impl::GetRegisteredNames(
     456             :     uno::Sequence<sal_Int32>& rFamilies,
     457             :     uno::Sequence<OUString>& rNames )
     458             : {
     459             :     // collect registered names + families
     460          59 :     vector<sal_Int32> aFamilies;
     461         118 :     vector<OUString> aNames;
     462             : 
     463             :     // iterate over families
     464         617 :     for (FamilySetType::iterator aJ = maFamilySet.begin(); aJ != maFamilySet.end(); ++aJ)
     465             :     {
     466         558 :         XMLAutoStyleFamily &rFamily = *aJ;
     467             : 
     468             :         // iterate over names
     469        5083 :         for (XMLAutoStyleFamily::NameSetType::const_iterator aI = rFamily.maNameSet.begin(); aI != rFamily.maNameSet.end(); ++aI)
     470             :         {
     471        4525 :             aFamilies.push_back( rFamily.mnFamily );
     472        4525 :             aNames.push_back( *aI );
     473             :         }
     474             :     }
     475             : 
     476             :     // copy the families + names into the sequence types
     477             :     DBG_ASSERT( aFamilies.size() == aNames.size(), "families != names" );
     478             : 
     479          59 :     rFamilies.realloc( aFamilies.size() );
     480          59 :     std::copy( aFamilies.begin(), aFamilies.end(), rFamilies.getArray() );
     481             : 
     482          59 :     rNames.realloc( aNames.size() );
     483         118 :     std::copy( aNames.begin(), aNames.end(), rNames.getArray() );
     484          59 : }
     485             : 
     486             : // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list
     487             : // if not added, yet.
     488             : 
     489        2773 : bool SvXMLAutoStylePoolP_Impl::Add(
     490             :     OUString& rName, sal_Int32 nFamily, const OUString& rParentName,
     491             :     const ::std::vector< XMLPropertyState >& rProperties, bool bDontSeek )
     492             : {
     493        2773 :     XMLAutoStyleFamily aTemporary( nFamily );
     494        2773 :     FamilySetType::iterator aFind = maFamilySet.find(aTemporary);
     495             :     DBG_ASSERT(aFind != maFamilySet.end(), "SvXMLAutoStylePool_Impl::Add: unknown family");
     496             : 
     497        2773 :     if (aFind == maFamilySet.end())
     498           0 :         return false;
     499             : 
     500        2773 :     XMLAutoStyleFamily &rFamily = *aFind;
     501             : 
     502        5546 :     XMLAutoStylePoolParent aTmp(rParentName);
     503        2773 :     XMLAutoStyleFamily::ParentSetType::iterator it2 = rFamily.maParentSet.find(aTmp);
     504        2773 :     if (it2 == rFamily.maParentSet.end())
     505             :     {
     506             :         std::pair<XMLAutoStyleFamily::ParentSetType::iterator,bool> r =
     507         365 :             rFamily.maParentSet.insert(new XMLAutoStylePoolParent(rParentName));
     508         365 :         it2 = r.first;
     509             :     }
     510             : 
     511        2773 :     XMLAutoStylePoolParent& rParent = *it2;
     512             : 
     513        2773 :     bool bRet = false;
     514        2773 :     if (rParent.Add(rFamily, rProperties, rName, bDontSeek))
     515             :     {
     516        2429 :         rFamily.mnCount++;
     517        2429 :         bRet = true;
     518             :     }
     519             : 
     520        5546 :     return bRet;
     521             : }
     522             : 
     523           0 : bool SvXMLAutoStylePoolP_Impl::AddNamed(
     524             :     const OUString& rName, sal_Int32 nFamily, const OUString& rParentName,
     525             :     const ::std::vector< XMLPropertyState >& rProperties )
     526             : {
     527             :     // get family and parent the same way as in Add()
     528             : 
     529           0 :     XMLAutoStyleFamily aTemporary( nFamily );
     530           0 :     FamilySetType::iterator aFind = maFamilySet.find(aTemporary);
     531             :     DBG_ASSERT(aFind != maFamilySet.end(), "SvXMLAutoStylePool_Impl::Add: unknown family");
     532             : 
     533           0 :     if (aFind == maFamilySet.end())
     534           0 :         return false;
     535             : 
     536           0 :     XMLAutoStyleFamily &rFamily = *aFind;
     537             : 
     538           0 :     XMLAutoStylePoolParent aTmp(rParentName);
     539           0 :     XMLAutoStyleFamily::ParentSetType::iterator it2 = rFamily.maParentSet.find(aTmp);
     540           0 :     if (it2 == rFamily.maParentSet.end())
     541             :     {
     542             :         std::pair<XMLAutoStyleFamily::ParentSetType::iterator,bool> r =
     543           0 :             rFamily.maParentSet.insert(new XMLAutoStylePoolParent(rParentName));
     544           0 :         it2 = r.first;
     545             :     }
     546             : 
     547           0 :     XMLAutoStylePoolParent& rParent = *it2;
     548             : 
     549           0 :     bool bRet = false;
     550           0 :     if (rParent.AddNamed(rFamily, rProperties, rName))
     551             :     {
     552           0 :         rFamily.mnCount++;
     553           0 :         bRet = true;
     554             :     }
     555             : 
     556           0 :     return bRet;
     557             : }
     558             : 
     559             : 
     560             : // Search for a array of XMLPropertyState ( vector< XMLPropertyState > ) in list
     561             : 
     562             : 
     563         370 : OUString SvXMLAutoStylePoolP_Impl::Find( sal_Int32 nFamily,
     564             :                                          const OUString& rParent,
     565             :                                          const vector< XMLPropertyState >& rProperties ) const
     566             : {
     567         370 :     OUString sName;
     568             : 
     569         740 :     XMLAutoStyleFamily aTemporary( nFamily );
     570         370 :     FamilySetType::const_iterator const iter = maFamilySet.find(aTemporary);
     571             :     OSL_ENSURE(iter != maFamilySet.end(), "SvXMLAutoStylePool_Impl::Find: unknown family");
     572             : 
     573         370 :     if (iter != maFamilySet.end())
     574             :     {
     575         370 :         XMLAutoStyleFamily const& rFamily = *iter;
     576         370 :         XMLAutoStylePoolParent aTmp( rParent );
     577         370 :         XMLAutoStyleFamily::ParentSetType::const_iterator it2 = rFamily.maParentSet.find(aTmp);
     578         370 :         if (it2 != rFamily.maParentSet.end())
     579             :         {
     580         277 :             sName = it2->Find(rFamily, rProperties);
     581         370 :         }
     582             :     }
     583             : 
     584         740 :     return sName;
     585             : }
     586             : 
     587             : namespace {
     588             : 
     589             : struct AutoStylePoolExport
     590             : {
     591             :     const OUString* mpParent;
     592             :     XMLAutoStylePoolProperties* mpProperties;
     593             : 
     594        2430 :     AutoStylePoolExport() : mpParent(NULL), mpProperties(NULL) {}
     595             : };
     596             : 
     597             : struct StyleComparator
     598             : {
     599           0 :     bool operator() (const AutoStylePoolExport& a, const AutoStylePoolExport& b)
     600             :     {
     601           0 :         return (a.mpProperties->GetName() < b.mpProperties->GetName() ||
     602           0 :                 (a.mpProperties->GetName() == b.mpProperties->GetName() && *a.mpParent < *b.mpParent));
     603             :     }
     604             : };
     605             : 
     606             : }
     607             : 
     608        2864 : void SvXMLAutoStylePoolP_Impl::exportXML(
     609             :            sal_Int32 nFamily,
     610             :         const uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
     611             :         const SvXMLUnitConverter&,
     612             :         const SvXMLNamespaceMap&,
     613             :         const SvXMLAutoStylePoolP *pAntiImpl) const
     614             : {
     615             :     // Get list of parents for current family (nFamily)
     616        2864 :     XMLAutoStyleFamily aTmp( nFamily );
     617        2864 :     FamilySetType::const_iterator aFind = maFamilySet.find(aTmp);
     618             :     DBG_ASSERT( aFind != maFamilySet.end(),
     619             :                 "SvXMLAutoStylePool_Impl::exportXML: unknown family" );
     620        2864 :     if (aFind == maFamilySet.end())
     621           0 :         return;
     622             : 
     623        2864 :     const XMLAutoStyleFamily &rFamily = *aFind;
     624        2864 :     sal_uInt32 nCount = rFamily.mnCount;
     625             : 
     626        2864 :     if (!nCount)
     627        2508 :         return;
     628             : 
     629             :     // create, initialize and fill helper-structure (SvXMLAutoStylePoolProperties_Impl)
     630             :     // which contains a parent-name and a SvXMLAutoStylePoolProperties_Impl
     631         712 :     std::vector<AutoStylePoolExport> aExpStyles(nCount);
     632             : 
     633         356 :     XMLAutoStyleFamily::ParentSetType::iterator it = rFamily.maParentSet.begin(), itEnd = rFamily.maParentSet.end();
     634         721 :     for (; it != itEnd; ++it)
     635             :     {
     636         365 :         XMLAutoStylePoolParent& rParent = *it;
     637         365 :         size_t nProperties = rParent.GetPropertiesList().size();
     638        2795 :         for( size_t j = 0; j < nProperties; j++ )
     639             :         {
     640             :             XMLAutoStylePoolProperties* pProperties =
     641        2430 :                 &rParent.GetPropertiesList()[j];
     642        2430 :             sal_uLong nPos = pProperties->GetPos();
     643             :             DBG_ASSERT( nPos < nCount,
     644             :                     "SvXMLAutoStylePool_Impl::exportXML: wrong position" );
     645        2430 :             if( nPos < nCount )
     646             :             {
     647             :                 DBG_ASSERT( !aExpStyles[nPos].mpProperties,
     648             :                     "SvXMLAutoStylePool_Impl::exportXML: double position" );
     649        2430 :                 aExpStyles[nPos].mpProperties = pProperties;
     650        2430 :                 aExpStyles[nPos].mpParent = &rParent.GetParent();
     651             :             }
     652             :         }
     653             :     }
     654             : 
     655         356 :     static bool bHack = (getenv("LIBO_ONEWAY_STABLE_ODF_EXPORT") != NULL);
     656             : 
     657         356 :     if (bHack)
     658             :     {
     659             : 
     660           0 :         std::sort(aExpStyles.begin(), aExpStyles.end(), StyleComparator());
     661             : 
     662           0 :         for (size_t i = 0; i < nCount; i++)
     663             :         {
     664           0 :             OUString oldName = aExpStyles[i].mpProperties->GetName();
     665           0 :             sal_Int32 dashIx = oldName.indexOf('-');
     666           0 :             OUString newName = (dashIx > 0 ? oldName.copy(0, dashIx) : oldName) + OUString::number(i);
     667             :             // SAL_DEBUG("renaming '" << oldName << "' -> '" << newName << "'");
     668           0 :             aExpStyles[i].mpProperties->SetName(newName);
     669           0 :         }
     670             :     }
     671             : 
     672             : 
     673             :     // create string to export for each XML-style. That means for each property-list
     674             : 
     675         712 :     OUString aStrFamilyName = rFamily.maStrFamilyName;
     676             : 
     677        2786 :     for( size_t i = 0; i < nCount; i++ )
     678             :     {
     679             :         DBG_ASSERT( aExpStyles[i].mpProperties,
     680             :                     "SvXMLAutoStylePool_Impl::exportXML: empty position" );
     681             : 
     682        2430 :         if( aExpStyles[i].mpProperties )
     683             :         {
     684        2430 :             GetExport().AddAttribute(
     685             :                 XML_NAMESPACE_STYLE, XML_NAME,
     686        4860 :                 aExpStyles[i].mpProperties->GetName() );
     687             : 
     688        2430 :             if( rFamily.mbAsFamily )
     689             :             {
     690        2369 :                 GetExport().AddAttribute(
     691        2369 :                     XML_NAMESPACE_STYLE, XML_FAMILY, aStrFamilyName );
     692             :             }
     693             : 
     694        2430 :             if( !aExpStyles[i].mpParent->isEmpty() )
     695             :             {
     696          94 :                 GetExport().AddAttribute(
     697             :                     XML_NAMESPACE_STYLE, XML_PARENT_STYLE_NAME,
     698          94 :                     GetExport().EncodeStyleName(
     699         282 :                         *aExpStyles[i].mpParent ) );
     700             :             }
     701             : 
     702        2430 :             OUString sName;
     703        2430 :             if( rFamily.mbAsFamily )
     704        2369 :                 sName = GetXMLToken(XML_STYLE);
     705             :             else
     706          61 :                 sName = rFamily.maStrFamilyName;
     707             : 
     708             :             pAntiImpl->exportStyleAttributes(
     709        2430 :                 GetExport().GetAttrList(),
     710             :                 nFamily,
     711        2430 :                 aExpStyles[i].mpProperties->GetProperties(),
     712        2430 :                 *rFamily.mxMapper.get()
     713        2430 :                     , GetExport().GetMM100UnitConverter(),
     714        2430 :                     GetExport().GetNamespaceMap()
     715        4860 :                 );
     716             : 
     717        2430 :             SvXMLElementExport aElem( GetExport(),
     718             :                                       XML_NAMESPACE_STYLE, sName,
     719        4860 :                                       true, true );
     720             : 
     721        2430 :             sal_Int32 nStart(-1);
     722        2430 :             sal_Int32 nEnd(-1);
     723        2430 :             if (nFamily == XML_STYLE_FAMILY_PAGE_MASTER)
     724             :             {
     725          61 :                 nStart = 0;
     726          61 :                 sal_Int32 nIndex = 0;
     727             :                 UniReference< XMLPropertySetMapper > aPropMapper =
     728          61 :                     rFamily.mxMapper->getPropertySetMapper();
     729             :                 sal_Int16 nContextID;
     730        4636 :                 while(nIndex < aPropMapper->GetEntryCount() && nEnd == -1)
     731             :                 {
     732        4514 :                     nContextID = aPropMapper->GetEntryContextId( nIndex );
     733        4514 :                     if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START))
     734          61 :                         nEnd = nIndex;
     735        4514 :                     nIndex++;
     736             :                 }
     737          61 :                 if (nEnd == -1)
     738           0 :                     nEnd = nIndex;
     739             :             }
     740             : 
     741             :             rFamily.mxMapper->exportXML(
     742        2430 :                 GetExport(),
     743        2430 :                 aExpStyles[i].mpProperties->GetProperties(),
     744        2430 :                 nStart, nEnd, XML_EXPORT_FLAG_IGN_WS );
     745             : 
     746             :             pAntiImpl->exportStyleContent(
     747        2430 :                 GetExport().GetDocHandler(),
     748             :                 nFamily,
     749        2430 :                 aExpStyles[i].mpProperties->GetProperties(),
     750        2430 :                 *rFamily.mxMapper.get(),
     751        2430 :                 GetExport().GetMM100UnitConverter(),
     752        2430 :                 GetExport().GetNamespaceMap()
     753        7290 :                 );
     754             :         }
     755         356 :     }
     756             : }
     757             : 
     758           6 : void SvXMLAutoStylePoolP_Impl::ClearEntries()
     759             : {
     760          30 :     for (FamilySetType::iterator aI = maFamilySet.begin(); aI != maFamilySet.end(); ++aI)
     761          24 :         aI->ClearEntries();
     762           6 : }
     763             : 
     764             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10