LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - CellMarginHandler.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 74 80 92.5 %
Date: 2014-04-11 Functions: 8 8 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             : #include <CellMarginHandler.hxx>
      20             : #include <PropertyMap.hxx>
      21             : #include <ConversionHelper.hxx>
      22             : #include <ooxml/resourceids.hxx>
      23             : #include "dmapperLoggers.hxx"
      24             : 
      25             : namespace writerfilter {
      26             : namespace dmapper {
      27             : 
      28             : using namespace ::com::sun::star;
      29             : using namespace ::writerfilter;
      30             : 
      31        3427 : CellMarginHandler::CellMarginHandler() :
      32             : LoggedProperties(dmapper_logger, "CellMarginHandler"),
      33             : m_nValue( 0 ),
      34             : m_nWidth( 0 ),
      35             : m_nType( 0 ),
      36             : m_nLeftMargin( 0 ),
      37             : m_bLeftMarginValid( false ),
      38             : m_nRightMargin( 0 ),
      39             : m_bRightMarginValid( false ),
      40             : m_nTopMargin( 0 ),
      41             : m_bTopMarginValid( false ),
      42             : m_nBottomMargin( 0 ),
      43        3427 : m_bBottomMarginValid( false )
      44             : {
      45        3427 : }
      46             : 
      47        6854 : CellMarginHandler::~CellMarginHandler()
      48             : {
      49        6854 : }
      50             : 
      51       18900 : void CellMarginHandler::lcl_attribute(Id rName, Value & rVal)
      52             : {
      53       18900 :     sal_Int32 nIntValue = rVal.getInt();
      54             :     (void)nIntValue;
      55             :     (void)rName;
      56       18900 :     switch( rName )
      57             :     {
      58             :         case NS_ooxml::LN_CT_TblWidth_w:
      59        9450 :             m_nWidth = nIntValue;
      60        9450 :             m_nValue = ConversionHelper::convertTwipToMM100Unsigned( nIntValue );
      61        9450 :         break;
      62             :         case NS_ooxml::LN_CT_TblWidth_type:
      63             :             OSL_ENSURE( NS_ooxml::LN_Value_ST_TblWidth_dxa == sal::static_int_cast<Id>(nIntValue), "cell margins work for absolute values, only");
      64        9450 :             m_nType = nIntValue;
      65        9450 :         break;
      66             :         default:
      67             :             OSL_FAIL( "unknown attribute");
      68             :     }
      69       18900 : }
      70             : 
      71        8478 : void CellMarginHandler::createGrabBag(const OUString& aName)
      72             : {
      73        8478 :     if (m_aInteropGrabBagName.isEmpty())
      74       12062 :         return;
      75             : 
      76        4894 :     beans::PropertyValue aRet;
      77        4894 :     aRet.Name = aName;
      78             : 
      79        9788 :     uno::Sequence<beans::PropertyValue> aSeq(2);
      80        4894 :     aSeq[0].Name = "w";
      81        4894 :     aSeq[0].Value = uno::makeAny(m_nWidth);
      82        4894 :     aSeq[1].Name = "type";
      83        4894 :     switch (m_nType)
      84             :     {
      85           3 :         case NS_ooxml::LN_Value_ST_TblWidth_nil: aSeq[1].Value = uno::makeAny(OUString("nil")); break;
      86           0 :         case NS_ooxml::LN_Value_ST_TblWidth_pct: aSeq[1].Value = uno::makeAny(OUString("pct")); break;
      87        4891 :         case NS_ooxml::LN_Value_ST_TblWidth_dxa: aSeq[1].Value = uno::makeAny(OUString("dxa")); break;
      88           0 :         case NS_ooxml::LN_Value_ST_TblWidth_auto: aSeq[1].Value = uno::makeAny(OUString("auto")); break;
      89             :     }
      90             : 
      91        4894 :     aRet.Value = uno::makeAny(aSeq);
      92        9788 :     m_aInteropGrabBag.push_back(aRet);
      93             : }
      94             : 
      95        9450 : void CellMarginHandler::lcl_sprm(Sprm & rSprm)
      96             : {
      97        9450 :     writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
      98        9450 :     if( pProperties.get())
      99             :     {
     100        9450 :         pProperties.get()->resolve( *this );
     101        9450 :         bool rtl = false; // TODO
     102        9450 :         switch( rSprm.getId() )
     103             :         {
     104             :             case NS_ooxml::LN_CT_TblCellMar_top:
     105             :             case NS_ooxml::LN_CT_TcMar_top:
     106        2173 :                 m_nTopMargin = m_nValue;
     107        2173 :                 m_bTopMarginValid = true;
     108        2173 :                 createGrabBag("top");
     109        2173 :             break;
     110             :             case NS_ooxml::LN_CT_TblCellMar_start:
     111         479 :                 if( rtl )
     112             :                 {
     113           0 :                     m_nRightMargin = m_nValue;
     114           0 :                     m_bRightMarginValid = true;
     115             :                 }
     116             :                 else
     117             :                 {
     118         479 :                     m_nLeftMargin = m_nValue;
     119         479 :                     m_bLeftMarginValid = true;
     120             :                 }
     121         479 :                 createGrabBag("start");
     122         479 :             break;
     123             :             case NS_ooxml::LN_CT_TblCellMar_left:
     124             :             case NS_ooxml::LN_CT_TcMar_left:
     125        1632 :                 m_nLeftMargin = m_nValue;
     126        1632 :                 m_bLeftMarginValid = true;
     127        1632 :                 createGrabBag("left");
     128        1632 :             break;
     129             :             case NS_ooxml::LN_CT_TblCellMar_bottom:
     130             :             case NS_ooxml::LN_CT_TcMar_bottom:
     131        1861 :                 m_nBottomMargin = m_nValue;
     132        1861 :                 m_bBottomMarginValid = true;
     133        1861 :                 createGrabBag("bottom");
     134        1861 :             break;
     135             :             case NS_ooxml::LN_CT_TblCellMar_end:
     136         479 :                 if( rtl )
     137             :                 {
     138           0 :                     m_nLeftMargin = m_nValue;
     139           0 :                     m_bLeftMarginValid = true;
     140             :                 }
     141             :                 else
     142             :                 {
     143         479 :                     m_nRightMargin = m_nValue;
     144         479 :                     m_bRightMarginValid = true;
     145             :                 }
     146         479 :                 createGrabBag("end");
     147         479 :             break;
     148             :             case NS_ooxml::LN_CT_TblCellMar_right:
     149             :             case NS_ooxml::LN_CT_TcMar_right:
     150        1854 :                 m_nRightMargin = m_nValue;
     151        1854 :                 m_bRightMarginValid = true;
     152        1854 :                 createGrabBag("right");
     153        1854 :             break;
     154             :             default:
     155             :                 OSL_FAIL( "unknown sprm");
     156             :         }
     157             :     }
     158        9450 :     m_nValue = 0;
     159        9450 : }
     160             : 
     161        1225 : void CellMarginHandler::enableInteropGrabBag(const OUString& aName)
     162             : {
     163        1225 :     m_aInteropGrabBagName = aName;
     164        1225 : }
     165             : 
     166        1225 : beans::PropertyValue CellMarginHandler::getInteropGrabBag()
     167             : {
     168        1225 :     beans::PropertyValue aRet;
     169        1225 :     aRet.Name = m_aInteropGrabBagName;
     170             : 
     171        2450 :     uno::Sequence<beans::PropertyValue> aSeq(m_aInteropGrabBag.size());
     172        1225 :     beans::PropertyValue* pSeq = aSeq.getArray();
     173        6119 :     for (std::vector<beans::PropertyValue>::iterator i = m_aInteropGrabBag.begin(); i != m_aInteropGrabBag.end(); ++i)
     174        4894 :         *pSeq++ = *i;
     175             : 
     176        1225 :     aRet.Value = uno::makeAny(aSeq);
     177        2450 :     return aRet;
     178             : }
     179             : 
     180             : } //namespace dmapper
     181             : } //namespace writerfilter
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10