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

Generated by: LCOV version 1.10