LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - BorderHandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 56 70 80.0 %
Date: 2012-08-25 Functions: 9 9 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 37 80 46.2 %

           Branch data     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 <BorderHandler.hxx>
      20                 :            : #include <PropertyMap.hxx>
      21                 :            : #include <resourcemodel/QNameToString.hxx>
      22                 :            : #include <doctok/resourceids.hxx>
      23                 :            : #include <ConversionHelper.hxx>
      24                 :            : #include <com/sun/star/table/BorderLine2.hpp>
      25                 :            : #include <ooxml/resourceids.hxx>
      26                 :            : #include <dmapperLoggers.hxx>
      27                 :            : 
      28                 :            : namespace writerfilter {
      29                 :            : 
      30                 :            : namespace dmapper {
      31                 :            : 
      32                 :            : using namespace ::com::sun::star;
      33                 :            : 
      34                 :            : 
      35                 :         83 : BorderHandler::BorderHandler( bool bOOXML ) :
      36                 :            : LoggedProperties(dmapper_logger, "BorderHandler"),
      37                 :            : m_nCurrentBorderPosition( BORDER_TOP ),
      38                 :            : m_nLineWidth(15), // Word default, in twips
      39                 :            : m_nLineType(0),
      40                 :            : m_nLineColor(0),
      41                 :            : m_nLineDistance(0),
      42 [ +  - ][ +  - ]:        581 : m_bOOXML( bOOXML )
         [ +  - ][ +  - ]
                 [ +  + ]
      43                 :            : {
      44                 :         83 :     const int nBorderCount(BORDER_COUNT);
      45         [ +  - ]:         83 :     std::fill_n(m_aFilledLines, nBorderCount, false);
      46         [ +  - ]:         83 :     std::fill_n(m_aBorderLines, nBorderCount, table::BorderLine2());
      47                 :         83 : }
      48                 :            : 
      49                 :         83 : BorderHandler::~BorderHandler()
      50                 :            : {
      51         [ -  + ]:        166 : }
      52                 :            : 
      53                 :        987 : void BorderHandler::lcl_attribute(Id rName, Value & rVal)
      54                 :            : {
      55                 :        987 :     sal_Int32 nIntValue = rVal.getInt();
      56   [ -  +  +  +  :        987 :     switch( rName )
             +  -  -  +  
                      - ]
      57                 :            :     {
      58                 :            :         case NS_rtf::LN_rgbrc:
      59                 :            :         {
      60         [ #  # ]:          0 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rVal.getProperties();
      61         [ #  # ]:          0 :             if( pProperties.get())
      62                 :            :             {
      63         [ #  # ]:          0 :                 pProperties->resolve(*this);
      64                 :            :                 ConversionHelper::MakeBorderLine( m_nLineWidth,   m_nLineType, m_nLineColor,
      65         [ #  # ]:          0 :                                                                                 m_aBorderLines[m_nCurrentBorderPosition], m_bOOXML );
      66                 :            :                 OSL_ENSURE(m_nCurrentBorderPosition < BORDER_COUNT, "too many border values");
      67                 :          0 :                 ++m_nCurrentBorderPosition;
      68         [ #  # ]:          0 :             }
      69                 :            :         }
      70                 :          0 :         break;
      71                 :            :         case NS_rtf::LN_DPTLINEWIDTH: // 0x2871
      72                 :            :             //  width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2.
      73                 :        240 :             m_nLineWidth = nIntValue * 5 / 2;
      74                 :        240 :         break;
      75                 :            :         case NS_rtf::LN_BRCTYPE:    // 0x2872
      76                 :        252 :             m_nLineType = nIntValue;
      77                 :        252 :         break;
      78                 :            :         case NS_ooxml::LN_CT_Border_color:
      79                 :            :         case NS_rtf::LN_ICO:        // 0x2873
      80                 :        237 :             m_nLineColor = nIntValue;
      81                 :        237 :         break;
      82                 :            :         case NS_rtf::LN_DPTSPACE:   // border distance in points
      83                 :        240 :             m_nLineDistance = ConversionHelper::convertTwipToMM100( nIntValue * 20 );
      84                 :        240 :         break;
      85                 :            :         case NS_rtf::LN_FSHADOW:    // 0x2875
      86                 :            :             //if 1 then line has shadow - unsupported
      87                 :            :         case NS_rtf::LN_FFRAME:     // 0x2876
      88                 :            :         case NS_rtf::LN_UNUSED2_15: // 0x2877
      89                 :            :             // ignored
      90                 :          0 :         break;
      91                 :          0 :         case NS_ooxml::LN_CT_Border_themeTint: break;
      92                 :         18 :         case NS_ooxml::LN_CT_Border_themeColor: break;
      93                 :            :         default:
      94                 :            :             OSL_FAIL( "unknown attribute");
      95                 :            :     }
      96                 :        987 : }
      97                 :            : 
      98                 :        204 : void BorderHandler::lcl_sprm(Sprm & rSprm)
      99                 :            : {
     100                 :        204 :     BorderPosition pos = BORDER_COUNT; // invalid pos
     101                 :        204 :     bool rtl = false; // TODO detect
     102   [ +  -  +  +  :        204 :     switch( rSprm.getId())
             -  +  +  +  
                      - ]
     103                 :            :     {
     104                 :            :         case NS_ooxml::LN_CT_TblBorders_top:
     105                 :         32 :             pos = BORDER_TOP;
     106                 :         32 :             break;
     107                 :            :         case NS_ooxml::LN_CT_TblBorders_start:
     108         [ #  # ]:          0 :             pos = rtl ? BORDER_RIGHT : BORDER_LEFT;
     109                 :          0 :             break;
     110                 :            :         case NS_ooxml::LN_CT_TblBorders_left:
     111                 :         35 :             pos = BORDER_LEFT;
     112                 :         35 :             break;
     113                 :            :         case NS_ooxml::LN_CT_TblBorders_bottom:
     114                 :         35 :             pos = BORDER_BOTTOM;
     115                 :         35 :             break;
     116                 :            :         case NS_ooxml::LN_CT_TblBorders_end:
     117         [ #  # ]:          0 :             pos = rtl ? BORDER_LEFT : BORDER_RIGHT;
     118                 :          0 :             break;
     119                 :            :         case NS_ooxml::LN_CT_TblBorders_right:
     120                 :         35 :             pos = BORDER_RIGHT;
     121                 :         35 :             break;
     122                 :            :         case NS_ooxml::LN_CT_TblBorders_insideH:
     123                 :         32 :             pos = BORDER_HORIZONTAL;
     124                 :         32 :             break;
     125                 :            :         case NS_ooxml::LN_CT_TblBorders_insideV:
     126                 :         35 :             pos = BORDER_VERTICAL;
     127                 :         35 :             break;
     128                 :            :         default:
     129                 :          0 :             break;
     130                 :            :     }
     131         [ +  - ]:        204 :     if( pos != BORDER_COUNT )
     132                 :            :     {
     133         [ +  - ]:        204 :         writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     134         [ +  - ]:        204 :         if( pProperties.get())
     135         [ +  - ]:        204 :             pProperties->resolve(*this);
     136                 :            :         ConversionHelper::MakeBorderLine( m_nLineWidth,   m_nLineType, m_nLineColor,
     137         [ +  - ]:        204 :                                m_aBorderLines[ pos ], m_bOOXML );
     138         [ +  - ]:        204 :         m_aFilledLines[ pos ] = true;
     139                 :            :     }
     140                 :        204 : }
     141                 :            : 
     142                 :         35 : PropertyMapPtr  BorderHandler::getProperties()
     143                 :            : {
     144                 :            :     static const PropertyIds aPropNames[BORDER_COUNT] =
     145                 :            :     {
     146                 :            :         PROP_TOP_BORDER,
     147                 :            :         PROP_LEFT_BORDER,
     148                 :            :         PROP_BOTTOM_BORDER,
     149                 :            :         PROP_RIGHT_BORDER,
     150                 :            :         META_PROP_HORIZONTAL_BORDER,
     151                 :            :         META_PROP_VERTICAL_BORDER
     152                 :            :     };
     153 [ +  - ][ +  - ]:         35 :     PropertyMapPtr pPropertyMap(new PropertyMap);
     154                 :            :     // don't fill in default properties
     155 [ -  + ][ #  # ]:         35 :     if( m_bOOXML || m_nCurrentBorderPosition )
     156                 :            :     {
     157         [ +  + ]:        245 :         for( sal_Int32 nProp = 0; nProp < BORDER_COUNT; ++nProp)
     158                 :            :         {
     159         [ +  + ]:        210 :             if ( m_aFilledLines[nProp] ) {
     160 [ +  - ][ +  - ]:        204 :                 pPropertyMap->Insert( aPropNames[nProp], false, uno::makeAny( m_aBorderLines[nProp] ) );
     161                 :            :             }
     162                 :            :         }
     163                 :            :     }
     164                 :         35 :     return pPropertyMap;
     165                 :            : }
     166                 :            : /*-------------------------------------------------------------------------
     167                 :            :     used only in OOXML import
     168                 :            :   -----------------------------------------------------------------------*/
     169                 :         48 : table::BorderLine2 BorderHandler::getBorderLine()
     170                 :            : {
     171                 :         48 :     table::BorderLine2 aBorderLine;
     172                 :         48 :     ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor, aBorderLine, m_bOOXML );
     173                 :         48 :     return aBorderLine;
     174                 :            : }
     175                 :            : 
     176                 :            : } //namespace dmapper
     177 [ +  - ][ +  - ]:         60 : } //namespace writerfilter
     178                 :            : 
     179                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10