LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - TDefTableHandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 55 111 49.5 %
Date: 2012-08-25 Functions: 9 12 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 55 189 29.1 %

           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 <TDefTableHandler.hxx>
      20                 :            : #include <PropertyMap.hxx>
      21                 :            : #include <ConversionHelper.hxx>
      22                 :            : #include <ooxml/resourceids.hxx>
      23                 :            : #include <doctok/resourceids.hxx>
      24                 :            : #include <com/sun/star/table/BorderLine2.hpp>
      25                 :            : #include <com/sun/star/text/TableColumnSeparator.hpp>
      26                 :            : #include <com/sun/star/text/VertOrientation.hpp>
      27                 :            : 
      28                 :            : #include "dmapperLoggers.hxx"
      29                 :            : 
      30                 :            : namespace writerfilter {
      31                 :            : namespace dmapper {
      32                 :            : 
      33                 :            : using namespace ::com::sun::star;
      34                 :            : 
      35                 :            : 
      36                 :            : 
      37                 :        364 : TDefTableHandler::TDefTableHandler(bool bOOXML) :
      38                 :            : LoggedProperties(dmapper_logger, "TDefTableHandler"),
      39                 :            : m_nLineWidth(0),
      40                 :            : m_nLineType(0),
      41                 :            : m_nLineColor(0),
      42                 :            : m_nLineDistance(0),
      43 [ +  - ][ +  - ]:        364 : m_bOOXML( bOOXML )
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      44                 :            : {
      45                 :        364 : }
      46                 :            : 
      47                 :            : 
      48                 :        364 : TDefTableHandler::~TDefTableHandler()
      49                 :            : {
      50         [ -  + ]:        728 : }
      51                 :            : 
      52                 :            : 
      53                 :       1354 : void TDefTableHandler::lcl_attribute(Id rName, Value & rVal)
      54                 :            : {
      55         [ +  - ]:       1354 :     sal_Int32 nIntValue = rVal.getInt();
      56                 :            :     (void)nIntValue;
      57                 :            :     (void)rName;
      58   [ -  -  -  -  :       1354 :     switch( rName )
          -  -  +  +  +  
             +  -  -  - ]
      59                 :            :     {
      60                 :            :         case NS_rtf::LN_cellx:
      61                 :            :             // nIntValue contains the vert. line position
      62                 :            :             //TODO: nIntValue is wrong for negative values!
      63         [ #  # ]:          0 :             if( nIntValue > 0x7fff )
      64                 :          0 :                 nIntValue -= 0xffff;
      65 [ #  # ][ #  # ]:          0 :             m_aCellBorderPositions.push_back( ConversionHelper::convertTwipToMM100( nIntValue ) );
      66                 :          0 :         break;
      67                 :            :         case NS_rtf::LN_tc:
      68                 :            :         {
      69         [ #  # ]:          0 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rVal.getProperties();
      70         [ #  # ]:          0 :             if( pProperties.get())
      71                 :            :             {
      72         [ #  # ]:          0 :                 pProperties->resolve( *this );
      73         [ #  # ]:          0 :             }
      74                 :            :         }
      75                 :          0 :         break;
      76                 :            :         //from LN_tc
      77                 :            :         case NS_rtf::LN_FFIRSTMERGED:
      78                 :            :         case NS_rtf::LN_FMERGED:
      79                 :            :         case NS_rtf::LN_FVERTICAL:
      80                 :            :         case NS_rtf::LN_FBACKWARD:
      81                 :            :         case NS_rtf::LN_FROTATEFONT:
      82                 :            :         case NS_rtf::LN_FVERTMERGE:
      83                 :            :         case NS_rtf::LN_FVERTRESTART:
      84                 :          0 :         break;
      85                 :            :         case NS_rtf::LN_VERTALIGN:
      86                 :            :             //TODO: m_aCellVertAlign is just a temporary solution! 0 - top 1 - center 2 - bottom
      87         [ #  # ]:          0 :             m_aCellVertAlign.push_back( nIntValue );
      88                 :          0 :         break;
      89                 :            :         case NS_rtf::LN_FUNUSED:
      90                 :            :         case NS_rtf::LN_CellPrefferedSize:
      91                 :          0 :         break;
      92                 :            :         case NS_rtf::LN_BRCTOP:
      93                 :            :         case NS_rtf::LN_BRCLEFT:
      94                 :            :         case NS_rtf::LN_BRCBOTTOM:
      95                 :            :         case NS_rtf::LN_BRCRIGHT:
      96                 :            :         {
      97         [ #  # ]:          0 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rVal.getProperties();
      98 [ #  # ][ #  # ]:          0 :             localResolve( rName, pProperties );
         [ #  # ][ #  # ]
      99                 :            :         }
     100                 :          0 :         break;
     101                 :            :         //from LN_BRCXXXX - handled within the BorderHandler
     102                 :            :         case NS_rtf::LN_DPTLINEWIDTH: // 0x2871
     103                 :            :             //  width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2.
     104                 :        391 :             m_nLineWidth = nIntValue * 5 / 2;
     105                 :        391 :         break;
     106                 :            :         case NS_rtf::LN_BRCTYPE:    // 0x2872
     107                 :        535 :             m_nLineType = nIntValue;
     108                 :        535 :         break;
     109                 :            :         case NS_ooxml::LN_CT_Border_color:
     110                 :            :         case NS_rtf::LN_ICO:        // 0x2873
     111                 :        214 :             m_nLineColor = nIntValue;
     112                 :        214 :         break;
     113                 :            :         case NS_rtf::LN_DPTSPACE:   // 0x2874
     114                 :        214 :             m_nLineDistance = nIntValue;
     115                 :        214 :         break;
     116                 :            :         case NS_rtf::LN_FSHADOW:    // 0x2875
     117                 :            :             //if 1 then line has shadow - unsupported
     118                 :            :         case NS_rtf::LN_FFRAME:     // 0x2876
     119                 :            :         case NS_rtf::LN_UNUSED2_15: // 0x2877
     120                 :            :             // ignored
     121                 :          0 :         break;
     122                 :            :         case NS_ooxml::LN_CT_Border_themeColor:
     123                 :            :         case NS_ooxml::LN_CT_Border_themeTint:
     124                 :            :         case NS_ooxml::LN_CT_Border_themeShade:
     125                 :            :             // ignored
     126                 :          0 :         break;
     127                 :            :         default:
     128                 :            :             OSL_FAIL("unknown attribute");
     129                 :            :     }
     130                 :       1354 : }
     131                 :            : 
     132                 :            : 
     133                 :        994 : void TDefTableHandler::localResolve(Id rName, writerfilter::Reference<Properties>::Pointer_t pProperties)
     134                 :            : {
     135         [ +  - ]:        994 :     if( pProperties.get())
     136                 :            :     {
     137                 :        994 :         m_nLineWidth = m_nLineType = m_nLineColor = m_nLineDistance = 0;
     138         [ +  - ]:        994 :         pProperties->resolve( *this );
     139                 :        994 :         table::BorderLine2 aBorderLine;
     140                 :            :         ConversionHelper::MakeBorderLine( m_nLineWidth,   m_nLineType, m_nLineColor,
     141         [ +  - ]:        994 :                                                                         aBorderLine, m_bOOXML );
     142                 :        994 :         bool rtl = false; // TODO
     143   [ +  -  +  +  :        994 :         switch( rName )
             -  +  -  -  
                      - ]
     144                 :            :         {
     145                 :            :             case NS_ooxml::LN_CT_TcBorders_top:
     146                 :            :             case NS_rtf::LN_BRCTOP:
     147         [ +  - ]:        361 :                 m_aTopBorderLines.push_back(aBorderLine);
     148                 :        361 :             break;
     149                 :            :             case NS_ooxml::LN_CT_TcBorders_start:
     150         [ #  # ]:          0 :                 if( rtl )
     151         [ #  # ]:          0 :                     m_aRightBorderLines.push_back(aBorderLine);
     152                 :            :                 else
     153         [ #  # ]:          0 :                     m_aLeftBorderLines.push_back(aBorderLine);
     154                 :          0 :             break;
     155                 :            :             case NS_ooxml::LN_CT_TcBorders_left:
     156                 :            :             case NS_rtf::LN_BRCLEFT:
     157         [ +  - ]:        202 :                 m_aLeftBorderLines.push_back(aBorderLine);
     158                 :        202 :             break;
     159                 :            :             case NS_ooxml::LN_CT_TcBorders_bottom:
     160                 :            :             case NS_rtf::LN_BRCBOTTOM:
     161         [ +  - ]:        229 :                 m_aBottomBorderLines.push_back(aBorderLine);
     162                 :        229 :             break;
     163                 :            :             case NS_ooxml::LN_CT_TcBorders_end:
     164         [ #  # ]:          0 :                 if( rtl )
     165         [ #  # ]:          0 :                     m_aLeftBorderLines.push_back(aBorderLine);
     166                 :            :                 else
     167         [ #  # ]:          0 :                     m_aRightBorderLines.push_back(aBorderLine);
     168                 :          0 :             break;
     169                 :            :             case NS_ooxml::LN_CT_TcBorders_right:
     170                 :            :             case NS_rtf::LN_BRCRIGHT:
     171         [ +  - ]:        202 :                 m_aRightBorderLines.push_back(aBorderLine);
     172                 :        202 :             break;
     173                 :            :             case NS_ooxml::LN_CT_TcBorders_insideH:
     174         [ #  # ]:          0 :                 m_aInsideHBorderLines.push_back(aBorderLine);
     175                 :          0 :             break;
     176                 :            :             case NS_ooxml::LN_CT_TcBorders_insideV:
     177         [ #  # ]:          0 :                 m_aInsideVBorderLines.push_back(aBorderLine);
     178                 :        994 :             break;
     179                 :            :             default:;
     180                 :            :         }
     181                 :            :     }
     182                 :        994 : }
     183                 :            : 
     184                 :            : 
     185                 :        994 : void TDefTableHandler::lcl_sprm(Sprm & rSprm)
     186                 :            : {
     187         [ +  - ]:        994 :     switch( rSprm.getId() )
     188                 :            :     {
     189                 :            :         case NS_ooxml::LN_CT_TcBorders_top:
     190                 :            :         case NS_ooxml::LN_CT_TcBorders_left:
     191                 :            :         case NS_ooxml::LN_CT_TcBorders_bottom:
     192                 :            :         case NS_ooxml::LN_CT_TcBorders_right:
     193                 :            :         case NS_ooxml::LN_CT_TcBorders_insideH:
     194                 :            :         case NS_ooxml::LN_CT_TcBorders_insideV:
     195                 :            :         case NS_ooxml::LN_CT_TcBorders_tl2br:
     196                 :            :         case NS_ooxml::LN_CT_TcBorders_tr2bl:
     197                 :            :         {
     198         [ +  - ]:        994 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     199 [ +  - ][ +  - ]:        994 :             localResolve( rSprm.getId(), pProperties );
         [ +  - ][ +  - ]
                 [ +  - ]
     200                 :            :         }
     201                 :        994 :         break;
     202                 :            :         default:;
     203                 :            :     }
     204                 :        994 : }
     205                 :            : 
     206                 :            : 
     207                 :          0 : PropertyMapPtr  TDefTableHandler::getRowProperties() const
     208                 :            : {
     209 [ #  # ][ #  # ]:          0 :     PropertyMapPtr pPropertyMap(new PropertyMap);
     210                 :            : 
     211                 :            :     // Writer only wants the separators, Word provides also the outer border positions
     212         [ #  # ]:          0 :     if( m_aCellBorderPositions.size() > 2 )
     213                 :            :     {
     214                 :            :         //determine table width
     215 [ #  # ][ #  # ]:          0 :         double nFullWidth = m_aCellBorderPositions[m_aCellBorderPositions.size() - 1] - m_aCellBorderPositions[0];
     216                 :            :         //the positions have to be distibuted in a range of 10000
     217                 :          0 :         const double nFullWidthRelative = 10000.;
     218         [ #  # ]:          0 :         uno::Sequence< text::TableColumnSeparator > aSeparators( m_aCellBorderPositions.size() - 2 );
     219         [ #  # ]:          0 :         text::TableColumnSeparator* pSeparators = aSeparators.getArray();
     220         [ #  # ]:          0 :         for( sal_uInt32 nBorder = 1; nBorder < m_aCellBorderPositions.size() - 1; ++nBorder )
     221                 :            :         {
     222                 :            :             sal_Int16 nRelPos =
     223         [ #  # ]:          0 :                 sal::static_int_cast< sal_Int16 >(double(m_aCellBorderPositions[nBorder]) * nFullWidthRelative / nFullWidth );
     224                 :            : 
     225                 :          0 :             pSeparators[nBorder - 1].Position =  nRelPos;
     226                 :          0 :             pSeparators[nBorder - 1].IsVisible = sal_True;
     227                 :            :         }
     228 [ #  # ][ #  # ]:          0 :         pPropertyMap->Insert( PROP_TABLE_COLUMN_SEPARATORS, false, uno::makeAny( aSeparators ) );
                 [ #  # ]
     229                 :            :     }
     230                 :            : 
     231                 :          0 :     return pPropertyMap;
     232                 :            : }
     233                 :            : 
     234                 :            : 
     235                 :        364 : void TDefTableHandler::fillCellProperties(
     236                 :            :             size_t nCell, ::boost::shared_ptr< TablePropertyMap > pCellProperties ) const
     237                 :            : {
     238         [ -  + ]:        364 :     if( m_aCellBorderPositions.size() > nCell )
     239                 :            :     {
     240                 :          0 :         sal_Int16 nVertOrient = text::VertOrientation::NONE;
     241         [ #  # ]:          0 :         switch( m_aCellVertAlign[nCell] ) //0 - top 1 - center 2 - bottom
              [ #  #  # ]
     242                 :            :         {
     243                 :          0 :             case 1: nVertOrient = text::VertOrientation::CENTER; break;
     244                 :          0 :             case 2: nVertOrient = text::VertOrientation::BOTTOM; break;
     245                 :            :             default:;
     246                 :            :         }
     247 [ #  # ][ #  # ]:          0 :         pCellProperties->Insert( PROP_VERT_ORIENT, false, uno::makeAny( nVertOrient ) );
     248                 :            :     }
     249         [ +  + ]:        364 :     if( m_aTopBorderLines.size() > nCell )
     250         [ +  - ]:        361 :         pCellProperties->Insert( PROP_TOP_BORDER, false, uno::makeAny( m_aTopBorderLines[nCell] ) );
     251         [ +  + ]:        364 :     if( m_aLeftBorderLines.size() > nCell )
     252         [ +  - ]:        202 :         pCellProperties->Insert( PROP_LEFT_BORDER, false, uno::makeAny( m_aLeftBorderLines[nCell] ) );
     253         [ +  + ]:        364 :     if( m_aBottomBorderLines.size() > nCell )
     254         [ +  - ]:        229 :         pCellProperties->Insert( PROP_BOTTOM_BORDER, false, uno::makeAny( m_aBottomBorderLines[nCell] ) );
     255         [ +  + ]:        364 :     if( m_aRightBorderLines.size() > nCell )
     256         [ +  - ]:        202 :         pCellProperties->Insert( PROP_RIGHT_BORDER, false, uno::makeAny( m_aRightBorderLines[nCell] ) );
     257         [ -  + ]:        364 :     if( m_aInsideHBorderLines.size() > nCell )
     258         [ #  # ]:          0 :         pCellProperties->Insert( META_PROP_HORIZONTAL_BORDER, false, uno::makeAny( m_aInsideHBorderLines[nCell] ) );
     259         [ -  + ]:        364 :     if( m_aInsideVBorderLines.size() > nCell )
     260         [ #  # ]:          0 :         pCellProperties->Insert( META_PROP_VERTICAL_BORDER, false, uno::makeAny( m_aInsideVBorderLines[nCell] ) );
     261                 :        364 : }
     262                 :            : 
     263                 :            : 
     264                 :          0 : sal_Int32 TDefTableHandler::getTableWidth() const
     265                 :            : {
     266                 :          0 :     sal_Int32 nWidth = 0;
     267         [ #  # ]:          0 :     if( m_aCellBorderPositions.size() > 1 )
     268                 :            :     {
     269                 :            :         //determine table width
     270                 :          0 :         nWidth = m_aCellBorderPositions[m_aCellBorderPositions.size() - 1] - m_aCellBorderPositions[0];
     271                 :            :     }
     272                 :          0 :     return nWidth;
     273                 :            : }
     274                 :            : 
     275                 :            : 
     276                 :          0 : size_t TDefTableHandler::getCellCount() const
     277                 :            : {
     278                 :          0 :     return m_aCellVertAlign.size();
     279                 :            : }
     280                 :            : 
     281                 :            : } //namespace dmapper
     282 [ +  - ][ +  - ]:         60 : } //namespace writerfilter
     283                 :            : 
     284                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10