LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - CellMarginHandler.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 72 74 97.3 %
Date: 2015-06-13 12:38:46 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 <osl/diagnose.h>
      24             : 
      25             : namespace writerfilter {
      26             : namespace dmapper {
      27             : 
      28             : using namespace ::com::sun::star;
      29             : using namespace ::writerfilter;
      30             : 
      31        5483 : CellMarginHandler::CellMarginHandler() :
      32             : LoggedProperties("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        5483 : m_bBottomMarginValid( false )
      44             : {
      45        5483 : }
      46             : 
      47       10966 : CellMarginHandler::~CellMarginHandler()
      48             : {
      49       10966 : }
      50             : 
      51       33004 : void CellMarginHandler::lcl_attribute(Id rName, Value & rVal)
      52             : {
      53       33004 :     sal_Int32 nIntValue = rVal.getInt();
      54             :     (void)nIntValue;
      55             :     (void)rName;
      56       33004 :     switch( rName )
      57             :     {
      58             :         case NS_ooxml::LN_CT_TblWidth_w:
      59       16502 :             m_nWidth = nIntValue;
      60       16502 :             m_nValue = ConversionHelper::convertTwipToMM100Unsigned( nIntValue );
      61       16502 :         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       16502 :             m_nType = nIntValue;
      65       16502 :         break;
      66             :         default:
      67             :             OSL_FAIL( "unknown attribute");
      68             :     }
      69       33004 : }
      70             : 
      71       15231 : void CellMarginHandler::createGrabBag(const OUString& aName)
      72             : {
      73       15231 :     if (m_aInteropGrabBagName.isEmpty())
      74       20290 :         return;
      75             : 
      76       10172 :     beans::PropertyValue aRet;
      77       10172 :     aRet.Name = aName;
      78             : 
      79       20344 :     uno::Sequence<beans::PropertyValue> aSeq(2);
      80       10172 :     aSeq[0].Name = "w";
      81       10172 :     aSeq[0].Value = uno::makeAny(m_nWidth);
      82       10172 :     aSeq[1].Name = "type";
      83       10172 :     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       10169 :         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       10172 :     aRet.Value = uno::makeAny(aSeq);
      92       20344 :     m_aInteropGrabBag.push_back(aRet);
      93             : }
      94             : 
      95       16502 : void CellMarginHandler::lcl_sprm(Sprm & rSprm)
      96             : {
      97       16502 :     writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
      98       16502 :     if( pProperties.get())
      99             :     {
     100       16502 :         pProperties.get()->resolve( *this );
     101       16502 :         const bool rtl = false; // TODO
     102       16502 :         switch( rSprm.getId() )
     103             :         {
     104             :             case NS_ooxml::LN_CT_TblCellMar_top:
     105             :             case NS_ooxml::LN_CT_TcMar_top:
     106        3581 :                 m_nTopMargin = m_nValue;
     107        3581 :                 m_bTopMarginValid = true;
     108        3581 :                 createGrabBag("top");
     109        3581 :             break;
     110             :             case NS_ooxml::LN_CT_TblCellMar_start:
     111             :                 if( rtl )
     112             :                 {
     113             :                     m_nRightMargin = m_nValue;
     114             :                     m_bRightMarginValid = true;
     115             :                 }
     116             :                 else
     117             :                 {
     118         776 :                     m_nLeftMargin = m_nValue;
     119         776 :                     m_bLeftMarginValid = true;
     120             :                 }
     121         776 :                 createGrabBag("start");
     122         776 :             break;
     123             :             case NS_ooxml::LN_CT_TblCellMar_left:
     124             :             case NS_ooxml::LN_CT_TcMar_left:
     125        3449 :                 m_nLeftMargin = m_nValue;
     126        3449 :                 m_bLeftMarginValid = true;
     127        3449 :                 createGrabBag("left");
     128        3449 :             break;
     129             :             case NS_ooxml::LN_CT_TblCellMar_bottom:
     130             :             case NS_ooxml::LN_CT_TcMar_bottom:
     131        3581 :                 m_nBottomMargin = m_nValue;
     132        3581 :                 m_bBottomMarginValid = true;
     133        3581 :                 createGrabBag("bottom");
     134        3581 :             break;
     135             :             case NS_ooxml::LN_CT_TblCellMar_end:
     136             :                 if( rtl )
     137             :                 {
     138             :                     m_nLeftMargin = m_nValue;
     139             :                     m_bLeftMarginValid = true;
     140             :                 }
     141             :                 else
     142             :                 {
     143         776 :                     m_nRightMargin = m_nValue;
     144         776 :                     m_bRightMarginValid = true;
     145             :                 }
     146         776 :                 createGrabBag("end");
     147         776 :             break;
     148             :             case NS_ooxml::LN_CT_TblCellMar_right:
     149             :             case NS_ooxml::LN_CT_TcMar_right:
     150        3068 :                 m_nRightMargin = m_nValue;
     151        3068 :                 m_bRightMarginValid = true;
     152        3068 :                 createGrabBag("right");
     153        3068 :             break;
     154             :             default:
     155             :                 OSL_FAIL( "unknown sprm");
     156             :         }
     157             :     }
     158       16502 :     m_nValue = 0;
     159       16502 : }
     160             : 
     161        2548 : void CellMarginHandler::enableInteropGrabBag(const OUString& aName)
     162             : {
     163        2548 :     m_aInteropGrabBagName = aName;
     164        2548 : }
     165             : 
     166        2548 : beans::PropertyValue CellMarginHandler::getInteropGrabBag()
     167             : {
     168        2548 :     beans::PropertyValue aRet;
     169        2548 :     aRet.Name = m_aInteropGrabBagName;
     170             : 
     171        5096 :     uno::Sequence<beans::PropertyValue> aSeq(m_aInteropGrabBag.size());
     172        2548 :     beans::PropertyValue* pSeq = aSeq.getArray();
     173       12720 :     for (std::vector<beans::PropertyValue>::iterator i = m_aInteropGrabBag.begin(); i != m_aInteropGrabBag.end(); ++i)
     174       10172 :         *pSeq++ = *i;
     175             : 
     176        2548 :     aRet.Value = uno::makeAny(aSeq);
     177        5096 :     return aRet;
     178             : }
     179             : 
     180             : } //namespace dmapper
     181             : } //namespace writerfilter
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11