LCOV - code coverage report
Current view: top level - libreoffice/writerfilter/source/dmapper - TablePropertiesHandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 92 116 79.3 %
Date: 2012-12-27 Functions: 6 6 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             : #include "BorderHandler.hxx"
      21             : #include "CellColorHandler.hxx"
      22             : #include "CellMarginHandler.hxx"
      23             : #include "ConversionHelper.hxx"
      24             : #include "MeasureHandler.hxx"
      25             : #include "TablePropertiesHandler.hxx"
      26             : #include "TDefTableHandler.hxx"
      27             : 
      28             : #include <ooxml/resourceids.hxx>
      29             : #include <doctok/sprmids.hxx>
      30             : 
      31             : #include <com/sun/star/text/SizeType.hpp>
      32             : #include <com/sun/star/text/VertOrientation.hpp>
      33             : #include <dmapperLoggers.hxx>
      34             : 
      35             : 
      36             : namespace writerfilter {
      37             : namespace dmapper {
      38             : 
      39        2419 :     TablePropertiesHandler::TablePropertiesHandler( bool bOOXML ) :
      40             :         m_pTableManager( NULL ),
      41        2419 :         m_bOOXML( bOOXML )
      42             :     {
      43        2419 :     }
      44             : 
      45             : 
      46        7257 :     TablePropertiesHandler::~TablePropertiesHandler( )
      47             :     {
      48             :         // Do not delete the table manager... this will be done somewhere else
      49        2419 :         m_pTableManager = NULL;
      50        4838 :     }
      51             : 
      52       23447 :     bool TablePropertiesHandler::sprm(Sprm & rSprm)
      53             :     {
      54             : #ifdef DEBUG_DOMAINMAPPER
      55             :         dmapper_logger->startElement("TablePropertiesHandler.sprm");
      56             :         dmapper_logger->attribute("sprm", rSprm.toString());
      57             : #endif
      58             : 
      59       23447 :         bool bRet = true;
      60       23447 :         sal_uInt32 nSprmId = rSprm.getId();
      61       23447 :         Value::Pointer_t pValue = rSprm.getValue();
      62       23447 :         sal_Int32 nIntValue = ((pValue.get() != NULL) ? pValue->getInt() : 0);
      63       23447 :         switch( nSprmId )
      64             :        {
      65             :             case NS_ooxml::LN_CT_TrPrBase_jc: //90706
      66             :             case NS_ooxml::LN_CT_TblPrBase_jc:
      67             :             case 0x5400: // sprmTJc
      68             :             {
      69             :                 //table justification 0: left, 1: center, 2: right
      70          12 :                 sal_Int16 nOrient = ConversionHelper::convertTableJustification( nIntValue );
      71          12 :                 TablePropertyMapPtr pTableMap( new TablePropertyMap );
      72          12 :                 pTableMap->setValue( TablePropertyMap::HORI_ORIENT, nOrient );
      73          12 :                 insertTableProps( pTableMap );
      74             :             }
      75          12 :             break;
      76             :             case 0x9601: // sprmTDxaLeft
      77           0 :             break;
      78             :             case 0x9602: // sprmTDxaGapHalf
      79             :             {
      80             :                 //m_nGapHalf = ConversionHelper::convertTwipToMM100( nIntValue );
      81           0 :                 TablePropertyMapPtr pPropMap( new TablePropertyMap );
      82           0 :                 pPropMap->setValue( TablePropertyMap::GAP_HALF, ConversionHelper::convertTwipToMM100( nIntValue ) );
      83           0 :                 insertTableProps(pPropMap);
      84             :             }
      85           0 :             break;
      86             :             case NS_ooxml::LN_CT_TrPrBase_trHeight: //90703
      87             :             {
      88             :                 //contains unit and value
      89          10 :                 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
      90          10 :                 if( pProperties.get())
      91             :                 {   //contains attributes x2902 (LN_unit) and x17e2 (LN_trleft)
      92          10 :                     MeasureHandlerPtr pMeasureHandler( new MeasureHandler );
      93          10 :                     pProperties->resolve(*pMeasureHandler);
      94          10 :                     TablePropertyMapPtr pPropMap( new TablePropertyMap );
      95          10 :                     pPropMap->Insert( PROP_SIZE_TYPE, false, uno::makeAny( pMeasureHandler->GetRowHeightSizeType() ));
      96          10 :                     pPropMap->Insert( PROP_HEIGHT, false, uno::makeAny(pMeasureHandler->getMeasureValue() ));
      97          10 :                     insertRowProps(pPropMap);
      98          10 :                 }
      99             :             }
     100          10 :             break;
     101             :             case 0x3403: // sprmTFCantSplit
     102             :             case NS_sprm::LN_TCantSplit: // 0x3644
     103             :             {
     104             :                 //row can't break across pages if nIntValue == 1
     105          14 :                 TablePropertyMapPtr pPropMap( new TablePropertyMap );
     106          14 :                 pPropMap->Insert( PROP_IS_SPLIT_ALLOWED, false, uno::makeAny(sal_Bool( nIntValue == 1 ? sal_False : sal_True ) ));
     107          14 :                 insertRowProps(pPropMap);
     108             :             }
     109          14 :             break;
     110             :             case 0x9407: // sprmTDyaRowHeight
     111             :             {
     112             :                 // table row height - negative values indicate 'exact height' - positive 'at least'
     113           0 :                 TablePropertyMapPtr pPropMap( new TablePropertyMap );
     114           0 :                 bool bMinHeight = true;
     115           0 :                 sal_Int16 nHeight = static_cast<sal_Int16>( nIntValue );
     116           0 :                 if( nHeight < 0 )
     117             :                 {
     118           0 :                     bMinHeight = false;
     119           0 :                     nHeight *= -1;
     120             :                 }
     121           0 :                 pPropMap->Insert( PROP_SIZE_TYPE, false, uno::makeAny(bMinHeight ? text::SizeType::MIN : text::SizeType::FIX ));
     122           0 :                 pPropMap->Insert( PROP_HEIGHT, false, uno::makeAny(ConversionHelper::convertTwipToMM100( nHeight )));
     123           0 :                 insertRowProps(pPropMap);
     124             :             }
     125           0 :             break;
     126             :             case NS_ooxml::LN_CT_TcPrBase_vAlign://90694
     127             :             {
     128          90 :                 sal_Int16 nVertOrient = text::VertOrientation::NONE;
     129          90 :                 switch( nIntValue ) //0 - top 1 - center 3 - bottom
     130             :                 {
     131           4 :                     case 1: nVertOrient = text::VertOrientation::CENTER; break;
     132           0 :                     case 3: nVertOrient = text::VertOrientation::BOTTOM; break;
     133             :                     default:;
     134             :                 };
     135          90 :                 TablePropertyMapPtr pCellPropMap( new TablePropertyMap() );
     136          90 :                 pCellPropMap->Insert( PROP_VERT_ORIENT, false, uno::makeAny( nVertOrient ) );
     137             :                 //todo: in ooxml import the value of m_ncell is wrong
     138          90 :                 cellProps( pCellPropMap );
     139             :             }
     140          90 :             break;
     141             :             case NS_ooxml::LN_CT_TblPrBase_tblBorders: //table borders, might be defined in table style
     142             :             {
     143          29 :                 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     144          29 :                 if( pProperties.get())
     145             :                 {
     146          29 :                     BorderHandlerPtr pBorderHandler( new BorderHandler(m_bOOXML) );
     147          29 :                     pProperties->resolve(*pBorderHandler);
     148          29 :                     TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
     149          29 :                     pTablePropMap->InsertProps(pBorderHandler->getProperties());
     150             : 
     151             : #ifdef DEBUG_DOMAINMAPPER
     152             :                     pTablePropMap->dumpXml( dmapper_logger );
     153             : #endif
     154          29 :                     insertTableProps( pTablePropMap );
     155          29 :                 }
     156             :             }
     157          29 :             break;
     158             :             case NS_ooxml::LN_CT_TcPrBase_tcBorders ://cell borders
     159             :             //contains CT_TcBorders_left, right, top, bottom
     160             :             {
     161         172 :                 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     162         172 :                 if( pProperties.get())
     163             :                 {
     164             :                     //in OOXML there's one set of borders at each cell (if there is any)
     165         172 :                     TDefTableHandlerPtr pTDefTableHandler( new TDefTableHandler( m_bOOXML ));
     166         172 :                     pProperties->resolve( *pTDefTableHandler );
     167         172 :                     TablePropertyMapPtr pCellPropMap( new TablePropertyMap );
     168         172 :                     pTDefTableHandler->fillCellProperties( 0, pCellPropMap );
     169         172 :                     cellProps( pCellPropMap );
     170         172 :                 }
     171             :             }
     172         172 :             break;
     173             :             case NS_ooxml::LN_CT_TblPrBase_shd:
     174             :             {
     175           0 :                 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     176           0 :                 if( pProperties.get())
     177             :                 {
     178           0 :                     CellColorHandlerPtr pCellColorHandler( new CellColorHandler);
     179           0 :                     pProperties->resolve( *pCellColorHandler );
     180           0 :                     TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
     181           0 :                     insertTableProps( pCellColorHandler->getProperties() );
     182           0 :                 }
     183             :             }
     184           0 :             break;
     185             :             case 0xd61a : // sprmTCellTopColor
     186             :             case 0xd61b : // sprmTCellLeftColor
     187             :             case 0xd61c : // sprmTCellBottomColor
     188             :             case 0xd61d : // sprmTCellRightColor
     189             :             case NS_ooxml::LN_CT_TcPrBase_shd:
     190             :             {
     191             :                 // each color sprm contains as much colors as cells are in a row
     192             :                 //LN_CT_TcPrBase_shd: cell shading contains: LN_CT_Shd_val, LN_CT_Shd_fill, LN_CT_Shd_color
     193          55 :                 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     194          55 :                 if( pProperties.get())
     195             :                 {
     196          55 :                     CellColorHandlerPtr pCellColorHandler( new CellColorHandler );
     197          55 :                     pProperties->resolve( *pCellColorHandler );
     198          55 :                     cellProps( pCellColorHandler->getProperties());
     199          55 :                 }
     200             :             }
     201          55 :             break;
     202             : //OOXML table properties
     203             :             case NS_ooxml::LN_CT_TblPrBase_tblCellMar: //cell margins
     204             :             {
     205             :                 //contains LN_CT_TblCellMar_top, LN_CT_TblCellMar_left, LN_CT_TblCellMar_bottom, LN_CT_TblCellMar_right
     206             :                 // LN_CT_TblCellMar_start, LN_CT_TblCellMar_end
     207          95 :                 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     208          95 :                 if( pProperties.get())
     209             :                 {
     210          95 :                     CellMarginHandlerPtr pCellMarginHandler( new CellMarginHandler );
     211          95 :                     pProperties->resolve( *pCellMarginHandler );
     212          95 :                     TablePropertyMapPtr pMarginProps( new TablePropertyMap );
     213          95 :                     if( pCellMarginHandler->m_bTopMarginValid )
     214          64 :                         pMarginProps->setValue( TablePropertyMap::CELL_MAR_TOP, pCellMarginHandler->m_nTopMargin );
     215          95 :                     if( pCellMarginHandler->m_bBottomMarginValid )
     216          64 :                         pMarginProps->setValue( TablePropertyMap::CELL_MAR_BOTTOM, pCellMarginHandler->m_nBottomMargin );
     217          95 :                     if( pCellMarginHandler->m_bLeftMarginValid )
     218          95 :                         pMarginProps->setValue( TablePropertyMap::CELL_MAR_LEFT, pCellMarginHandler->m_nLeftMargin );
     219          95 :                     if( pCellMarginHandler->m_bRightMarginValid )
     220          91 :                         pMarginProps->setValue( TablePropertyMap::CELL_MAR_RIGHT, pCellMarginHandler->m_nRightMargin );
     221          95 :                     insertTableProps(pMarginProps);
     222          95 :                 }
     223             :             }
     224          95 :             break;
     225             :            case NS_ooxml::LN_CT_TblPrBase_tblInd:
     226             :            {
     227          87 :                writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     228          87 :                if (pProperties.get())
     229             :                {
     230          87 :                    MeasureHandlerPtr pHandler(new MeasureHandler);
     231          87 :                    pProperties->resolve( *pHandler );
     232          87 :                    TablePropertyMapPtr pTblIndMap(new TablePropertyMap);
     233          87 :                    sal_uInt32 nTblInd = pHandler->getMeasureValue();
     234          87 :                    pTblIndMap->setValue( TablePropertyMap::LEFT_MARGIN, nTblInd);
     235          87 :                    insertTableProps(pTblIndMap);
     236          87 :                }
     237             :            }
     238          87 :             break;
     239       22883 :             default: bRet = false;
     240             :         }
     241             : 
     242             : #ifdef DEBUG_DOMAINMAPPER
     243             :         dmapper_logger->endElement();
     244             : #endif
     245             : 
     246       23447 :         return bRet;
     247             :     }
     248          15 : }}
     249             : 
     250             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10