LCOV - code coverage report
Current view: top level - libreoffice/writerfilter/source/dmapper - TDefTableHandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 67 111 60.4 %
Date: 2012-12-27 Functions: 9 12 75.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             : #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         172 : 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         172 : m_bOOXML( bOOXML )
      44             : {
      45         172 : }
      46             : 
      47             : 
      48         344 : TDefTableHandler::~TDefTableHandler()
      49             : {
      50         344 : }
      51             : 
      52             : 
      53         678 : void TDefTableHandler::lcl_attribute(Id rName, Value & rVal)
      54             : {
      55         678 :     sal_Int32 nIntValue = rVal.getInt();
      56             :     (void)nIntValue;
      57             :     (void)rName;
      58         678 :     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         149 :             m_nLineWidth = nIntValue * 5 / 2;
     105         149 :         break;
     106             :         case NS_rtf::LN_BRCTYPE:    // 0x2872
     107         347 :             m_nLineType = nIntValue;
     108         347 :         break;
     109             :         case NS_ooxml::LN_CT_Border_color:
     110             :         case NS_rtf::LN_ICO:        // 0x2873
     111          86 :             m_nLineColor = nIntValue;
     112          86 :         break;
     113             :         case NS_rtf::LN_DPTSPACE:   // 0x2874
     114          86 :             m_nLineDistance = nIntValue;
     115          86 :         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          10 :         break;
     127             :         default:
     128             :             OSL_FAIL("unknown attribute");
     129             :     }
     130         678 : }
     131             : 
     132             : 
     133         500 : void TDefTableHandler::localResolve(Id rName, writerfilter::Reference<Properties>::Pointer_t pProperties)
     134             : {
     135         500 :     if( pProperties.get())
     136             :     {
     137         500 :         m_nLineWidth = m_nLineType = m_nLineColor = m_nLineDistance = 0;
     138         500 :         pProperties->resolve( *this );
     139         500 :         table::BorderLine2 aBorderLine;
     140             :         ConversionHelper::MakeBorderLine( m_nLineWidth,   m_nLineType, m_nLineColor,
     141         500 :                                                                         aBorderLine, m_bOOXML );
     142         500 :         bool rtl = false; // TODO
     143         500 :         switch( rName )
     144             :         {
     145             :             case NS_ooxml::LN_CT_TcBorders_top:
     146             :             case NS_rtf::LN_BRCTOP:
     147         160 :                 m_aTopBorderLines.push_back(aBorderLine);
     148         160 :             break;
     149             :             case NS_ooxml::LN_CT_TcBorders_start:
     150          22 :                 if( rtl )
     151           0 :                     m_aRightBorderLines.push_back(aBorderLine);
     152             :                 else
     153          22 :                     m_aLeftBorderLines.push_back(aBorderLine);
     154          22 :             break;
     155             :             case NS_ooxml::LN_CT_TcBorders_left:
     156             :             case NS_rtf::LN_BRCLEFT:
     157          85 :                 m_aLeftBorderLines.push_back(aBorderLine);
     158          85 :             break;
     159             :             case NS_ooxml::LN_CT_TcBorders_bottom:
     160             :             case NS_rtf::LN_BRCBOTTOM:
     161         118 :                 m_aBottomBorderLines.push_back(aBorderLine);
     162         118 :             break;
     163             :             case NS_ooxml::LN_CT_TcBorders_end:
     164          22 :                 if( rtl )
     165           0 :                     m_aLeftBorderLines.push_back(aBorderLine);
     166             :                 else
     167          22 :                     m_aRightBorderLines.push_back(aBorderLine);
     168          22 :             break;
     169             :             case NS_ooxml::LN_CT_TcBorders_right:
     170             :             case NS_rtf::LN_BRCRIGHT:
     171          85 :                 m_aRightBorderLines.push_back(aBorderLine);
     172          85 :             break;
     173             :             case NS_ooxml::LN_CT_TcBorders_insideH:
     174           4 :                 m_aInsideHBorderLines.push_back(aBorderLine);
     175           4 :             break;
     176             :             case NS_ooxml::LN_CT_TcBorders_insideV:
     177           4 :                 m_aInsideVBorderLines.push_back(aBorderLine);
     178           4 :             break;
     179             :             default:;
     180             :         }
     181             :     }
     182         500 : }
     183             : 
     184             : 
     185         500 : void TDefTableHandler::lcl_sprm(Sprm & rSprm)
     186             : {
     187         500 :     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_start:
     192             :         case NS_ooxml::LN_CT_TcBorders_bottom:
     193             :         case NS_ooxml::LN_CT_TcBorders_right:
     194             :         case NS_ooxml::LN_CT_TcBorders_end:
     195             :         case NS_ooxml::LN_CT_TcBorders_insideH:
     196             :         case NS_ooxml::LN_CT_TcBorders_insideV:
     197             :         case NS_ooxml::LN_CT_TcBorders_tl2br:
     198             :         case NS_ooxml::LN_CT_TcBorders_tr2bl:
     199             :         {
     200         500 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     201         500 :             localResolve( rSprm.getId(), pProperties );
     202             :         }
     203         500 :         break;
     204             :         default:;
     205             :     }
     206         500 : }
     207             : 
     208             : 
     209           0 : PropertyMapPtr  TDefTableHandler::getRowProperties() const
     210             : {
     211           0 :     PropertyMapPtr pPropertyMap(new PropertyMap);
     212             : 
     213             :     // Writer only wants the separators, Word provides also the outer border positions
     214           0 :     if( m_aCellBorderPositions.size() > 2 )
     215             :     {
     216             :         //determine table width
     217           0 :         double nFullWidth = m_aCellBorderPositions[m_aCellBorderPositions.size() - 1] - m_aCellBorderPositions[0];
     218             :         //the positions have to be distibuted in a range of 10000
     219           0 :         const double nFullWidthRelative = 10000.;
     220           0 :         uno::Sequence< text::TableColumnSeparator > aSeparators( m_aCellBorderPositions.size() - 2 );
     221           0 :         text::TableColumnSeparator* pSeparators = aSeparators.getArray();
     222           0 :         for( sal_uInt32 nBorder = 1; nBorder < m_aCellBorderPositions.size() - 1; ++nBorder )
     223             :         {
     224             :             sal_Int16 nRelPos =
     225           0 :                 sal::static_int_cast< sal_Int16 >(double(m_aCellBorderPositions[nBorder]) * nFullWidthRelative / nFullWidth );
     226             : 
     227           0 :             pSeparators[nBorder - 1].Position =  nRelPos;
     228           0 :             pSeparators[nBorder - 1].IsVisible = sal_True;
     229             :         }
     230           0 :         pPropertyMap->Insert( PROP_TABLE_COLUMN_SEPARATORS, false, uno::makeAny( aSeparators ) );
     231             :     }
     232             : 
     233           0 :     return pPropertyMap;
     234             : }
     235             : 
     236             : 
     237         172 : void TDefTableHandler::fillCellProperties(
     238             :             size_t nCell, ::boost::shared_ptr< TablePropertyMap > pCellProperties ) const
     239             : {
     240         172 :     if( m_aCellBorderPositions.size() > nCell )
     241             :     {
     242           0 :         sal_Int16 nVertOrient = text::VertOrientation::NONE;
     243           0 :         switch( m_aCellVertAlign[nCell] ) //0 - top 1 - center 2 - bottom
     244             :         {
     245           0 :             case 1: nVertOrient = text::VertOrientation::CENTER; break;
     246           0 :             case 2: nVertOrient = text::VertOrientation::BOTTOM; break;
     247             :             default:;
     248             :         }
     249           0 :         pCellProperties->Insert( PROP_VERT_ORIENT, false, uno::makeAny( nVertOrient ) );
     250             :     }
     251         172 :     if( m_aTopBorderLines.size() > nCell )
     252         160 :         pCellProperties->Insert( PROP_TOP_BORDER, false, uno::makeAny( m_aTopBorderLines[nCell] ) );
     253         172 :     if( m_aLeftBorderLines.size() > nCell )
     254         107 :         pCellProperties->Insert( PROP_LEFT_BORDER, false, uno::makeAny( m_aLeftBorderLines[nCell] ) );
     255         172 :     if( m_aBottomBorderLines.size() > nCell )
     256         118 :         pCellProperties->Insert( PROP_BOTTOM_BORDER, false, uno::makeAny( m_aBottomBorderLines[nCell] ) );
     257         172 :     if( m_aRightBorderLines.size() > nCell )
     258         107 :         pCellProperties->Insert( PROP_RIGHT_BORDER, false, uno::makeAny( m_aRightBorderLines[nCell] ) );
     259         172 :     if( m_aInsideHBorderLines.size() > nCell )
     260           4 :         pCellProperties->Insert( META_PROP_HORIZONTAL_BORDER, false, uno::makeAny( m_aInsideHBorderLines[nCell] ) );
     261         172 :     if( m_aInsideVBorderLines.size() > nCell )
     262           4 :         pCellProperties->Insert( META_PROP_VERTICAL_BORDER, false, uno::makeAny( m_aInsideVBorderLines[nCell] ) );
     263         172 : }
     264             : 
     265             : 
     266           0 : sal_Int32 TDefTableHandler::getTableWidth() const
     267             : {
     268           0 :     sal_Int32 nWidth = 0;
     269           0 :     if( m_aCellBorderPositions.size() > 1 )
     270             :     {
     271             :         //determine table width
     272           0 :         nWidth = m_aCellBorderPositions[m_aCellBorderPositions.size() - 1] - m_aCellBorderPositions[0];
     273             :     }
     274           0 :     return nWidth;
     275             : }
     276             : 
     277             : 
     278           0 : size_t TDefTableHandler::getCellCount() const
     279             : {
     280           0 :     return m_aCellVertAlign.size();
     281             : }
     282             : 
     283             : } //namespace dmapper
     284          15 : } //namespace writerfilter
     285             : 
     286             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10