LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/tree - style.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 44 47 93.6 %
Date: 2015-06-13 12:38:46 Functions: 13 13 100.0 %
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             : #ifndef INCLUDED_SDEXT_SOURCE_PDFIMPORT_TREE_STYLE_HXX
      21             : #define INCLUDED_SDEXT_SOURCE_PDFIMPORT_TREE_STYLE_HXX
      22             : 
      23             : #include "pdfihelper.hxx"
      24             : #include <unordered_map>
      25             : #include <vector>
      26             : #include <rtl/ustring.hxx>
      27             : #include <rtl/string.hxx>
      28             : #include "treevisiting.hxx"
      29             : 
      30             : namespace pdfi
      31             : {
      32             :     struct Element;
      33             :     struct EmitContext;
      34             :     struct ElementTreeVisitable;
      35             : 
      36           4 :     class StyleContainer
      37             :     {
      38             :     public:
      39         744 :         struct Style
      40             :         {
      41             :             OString             Name;
      42             :             PropertyMap              Properties;
      43             :             OUString            Contents;
      44             :             Element*                 ContainedElement;
      45             :             std::vector< Style* >    SubStyles;
      46             : 
      47             :             Style() : ContainedElement( NULL )  {}
      48         744 :             Style( const OString& rName, const PropertyMap& rProps ) :
      49             :                 Name( rName ),
      50             :                 Properties( rProps ),
      51         744 :                 ContainedElement( NULL )
      52         744 :             {}
      53             :         };
      54             : 
      55             :     private:
      56         985 :         struct HashedStyle
      57             :         {
      58             :             OString            Name;
      59             :             PropertyMap             Properties;
      60             :             OUString           Contents;
      61             :             Element*                ContainedElement;
      62             :             std::vector<sal_Int32>  SubStyles;
      63             : 
      64             :             bool                    IsSubStyle;
      65             :             sal_Int32               RefCount;
      66             : 
      67         819 :             HashedStyle() : ContainedElement( NULL ), IsSubStyle( true ), RefCount( 0 ) {}
      68             : 
      69          83 :             HashedStyle( const HashedStyle& rRight ) :
      70             :                 Name( rRight.Name ),
      71             :                 Properties( rRight.Properties ),
      72             :                 Contents( rRight.Contents ),
      73             :                 ContainedElement( rRight.ContainedElement ),
      74             :                 SubStyles( rRight.SubStyles ),
      75             :                 IsSubStyle( rRight.IsSubStyle ),
      76          83 :                 RefCount( 0 )
      77          83 :             {}
      78             : 
      79         819 :             size_t hashCode() const
      80             :             {
      81         819 :                 size_t nRet = size_t(Name.hashCode());
      82       10767 :                 for( PropertyMap::const_iterator it = Properties.begin();
      83        7178 :                      it != Properties.end(); ++it )
      84             :                 {
      85        2770 :                      nRet ^= size_t(it->first.hashCode());
      86        2770 :                      nRet ^= size_t(it->second.hashCode());
      87             :                 }
      88         819 :                 nRet = size_t(Contents.hashCode());
      89         819 :                 nRet ^= size_t(ContainedElement);
      90        1203 :                 for( size_t n = 0; n < SubStyles.size(); ++n )
      91         384 :                      nRet ^= size_t(SubStyles[n]);
      92         819 :                 return nRet;
      93             :             }
      94             : 
      95        1682 :             bool operator==(const HashedStyle& rRight) const
      96             :             {
      97        4266 :                 if( Name != rRight.Name                 ||
      98        1555 :                     Properties != rRight.Properties     ||
      99        1306 :                     Contents != rRight.Contents         ||
     100        2988 :                     ContainedElement != rRight.ContainedElement ||
     101         653 :                     SubStyles.size() != rRight.SubStyles.size()
     102             :                     )
     103        1029 :                     return false;
     104         967 :                 for( size_t n = 0; n < SubStyles.size(); ++n )
     105             :                 {
     106         314 :                     if( SubStyles[n] != rRight.SubStyles[n] )
     107           0 :                         return false;
     108             :                 }
     109         653 :                 return true;
     110             :             }
     111             :         };
     112             : 
     113             :         struct StyleHash;
     114             :         friend struct StyleHash;
     115             :         struct StyleHash
     116             :         {
     117         819 :             size_t operator()( const StyleContainer::HashedStyle& rStyle ) const
     118             :             {
     119         819 :                 return rStyle.hashCode();
     120             :             }
     121             :         };
     122             : 
     123             :         struct StyleIdNameSort;
     124             :         friend struct StyleIdNameSort;
     125             :         struct StyleIdNameSort
     126             :         {
     127             :             const std::unordered_map< sal_Int32, HashedStyle >* m_pMap;
     128             : 
     129          11 :             StyleIdNameSort( const std::unordered_map< sal_Int32, HashedStyle >* pMap ) :
     130          11 :                 m_pMap(pMap)
     131          11 :             {}
     132          93 :             bool operator()( sal_Int32 nLeft, sal_Int32 nRight )
     133             :             {
     134             :                 const std::unordered_map< sal_Int32, HashedStyle >::const_iterator left_it =
     135          93 :                     m_pMap->find( nLeft );
     136             :                 const std::unordered_map< sal_Int32, HashedStyle >::const_iterator right_it =
     137          93 :                     m_pMap->find( nRight );
     138          93 :                 if( left_it == m_pMap->end() )
     139           0 :                     return false;
     140          93 :                 else if( right_it == m_pMap->end() )
     141           0 :                     return true;
     142             :                 else
     143          93 :                     return left_it->second.Name < right_it->second.Name;
     144             :             }
     145             :         };
     146             : 
     147             :         sal_Int32                                               m_nNextId;
     148             :         std::unordered_map< sal_Int32, HashedStyle >                 m_aIdToStyle;
     149             :         std::unordered_map< HashedStyle, sal_Int32, StyleHash >      m_aStyleToId;
     150             : 
     151             :         void impl_emitStyle( sal_Int32           nStyleId,
     152             :                              EmitContext&        rContext,
     153             :                              ElementTreeVisitor& rContainedElemVisitor );
     154             : 
     155             :     public:
     156             :         StyleContainer();
     157             : 
     158             :         void emit( EmitContext&        rContext,
     159             :                    ElementTreeVisitor& rContainedElemVisitor );
     160             : 
     161             :         sal_Int32 impl_getStyleId( const Style& rStyle, bool bSubStyle );
     162         379 :         sal_Int32 getStyleId( const Style& rStyle )
     163         379 :         { return impl_getStyleId( rStyle, false ); }
     164             :         sal_Int32 getStandardStyleId( const OString& rFamily );
     165             : 
     166             :         // returns NULL for an invalid style id
     167             :         const PropertyMap* getProperties( sal_Int32 nStyleId ) const;
     168             :         sal_Int32 setProperties( sal_Int32 nStyleId, const PropertyMap &rNewProps );
     169             :         OUString getStyleName( sal_Int32 nStyle ) const;
     170             :     };
     171             : }
     172             : 
     173             : #endif
     174             : 
     175             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11