LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - MeasureHandler.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 50 55 90.9 %
Date: 2014-04-11 Functions: 7 8 87.5 %
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 <MeasureHandler.hxx>
      20             : #include <PropertyMap.hxx>
      21             : #include <ConversionHelper.hxx>
      22             : #include <ooxml/resourceids.hxx>
      23             : #include <com/sun/star/text/SizeType.hpp>
      24             : #include "dmapperLoggers.hxx"
      25             : 
      26             : namespace writerfilter {
      27             : namespace dmapper {
      28             : 
      29             : using namespace ::com::sun::star;
      30             : 
      31             : 
      32             : 
      33       11784 : MeasureHandler::MeasureHandler() :
      34             : LoggedProperties(dmapper_logger, "MeasureHandler"),
      35             : m_nMeasureValue( 0 ),
      36             : m_nUnit( -1 ),
      37       11784 : m_nRowHeightSizeType( text::SizeType::MIN )
      38             : {
      39       11784 : }
      40             : 
      41             : 
      42       23568 : MeasureHandler::~MeasureHandler()
      43             : {
      44       23568 : }
      45             : 
      46             : 
      47       22614 : void MeasureHandler::lcl_attribute(Id rName, Value & rVal)
      48             : {
      49       22614 :     sal_Int32 nIntValue = rVal.getInt();
      50             :     (void)rName;
      51       22614 :     switch( rName )
      52             :     {
      53             :         case NS_ooxml::LN_CT_TblWidth_type:// = 90668;
      54             :         {
      55             :             //can be: NS_ooxml::LN_Value_ST_TblWidth_nil, NS_ooxml::LN_Value_ST_TblWidth_pct,
      56             :             //        NS_ooxml::LN_Value_ST_TblWidth_dxa, NS_ooxml::LN_Value_ST_TblWidth_auto;
      57       10564 :             m_nUnit = nIntValue;
      58             : 
      59       10564 :             if (!m_aInteropGrabBagName.isEmpty())
      60             :             {
      61        1213 :                 beans::PropertyValue aValue;
      62        1213 :                 aValue.Name = "type";
      63        1213 :                 switch (nIntValue)
      64             :                 {
      65           0 :                     case NS_ooxml::LN_Value_ST_TblWidth_nil: aValue.Value = uno::makeAny(OUString("nil")); break;
      66           0 :                     case NS_ooxml::LN_Value_ST_TblWidth_pct: aValue.Value = uno::makeAny(OUString("pct")); break;
      67        1213 :                     case NS_ooxml::LN_Value_ST_TblWidth_dxa: aValue.Value = uno::makeAny(OUString("dxa")); break;
      68           0 :                     case NS_ooxml::LN_Value_ST_TblWidth_auto: aValue.Value = uno::makeAny(OUString("auto")); break;
      69             :                 }
      70        1213 :                 m_aInteropGrabBag.push_back(aValue);
      71             :             }
      72             :         }
      73       10564 :         break;
      74             :         case NS_ooxml::LN_CT_Height_hRule: // 90666;
      75             :         {
      76         266 :             OUString sHeightType = rVal.getString();
      77         266 :             if ( sHeightType == "exact" )
      78           6 :                 m_nRowHeightSizeType = text::SizeType::FIX;
      79             :         }
      80         266 :         break;
      81             :         case NS_ooxml::LN_CT_TblWidth_w:// = 90667;
      82       10564 :             m_nMeasureValue = nIntValue;
      83       10564 :             if (!m_aInteropGrabBagName.isEmpty())
      84             :             {
      85        1213 :                 beans::PropertyValue aValue;
      86        1213 :                 aValue.Name = "w";
      87        1213 :                 aValue.Value = uno::makeAny(nIntValue);
      88        1213 :                 m_aInteropGrabBag.push_back(aValue);
      89             :             }
      90       10564 :         break;
      91             :         case NS_ooxml::LN_CT_Height_val: // 90665 -- a string value
      92             :         {
      93        1220 :             m_nUnit = NS_ooxml::LN_Value_ST_TblWidth_dxa;
      94        1220 :             OUString sHeight = rVal.getString();
      95        1220 :             m_nMeasureValue = sHeight.toInt32();
      96             :         }
      97        1220 :         break;
      98             :         default:
      99             :             OSL_FAIL( "unknown attribute");
     100             :     }
     101       22614 : }
     102             : 
     103             : 
     104           0 : void MeasureHandler::lcl_sprm(Sprm & rSprm)
     105             : {
     106             :     (void)rSprm;
     107           0 : }
     108             : 
     109             : 
     110       11644 : sal_Int32 MeasureHandler::getMeasureValue() const
     111             : {
     112       11644 :     sal_Int32 nRet = 0;
     113       11644 :     if( m_nMeasureValue != 0 && m_nUnit >= 0 )
     114             :     {
     115             :         // TODO m_nUnit 3 - twip, other values unknown :-(
     116        8883 :         if( m_nUnit == 3 || sal::static_int_cast<Id>(m_nUnit) == NS_ooxml::LN_Value_ST_TblWidth_dxa)
     117             :         {
     118        8472 :             nRet = ConversionHelper::convertTwipToMM100( m_nMeasureValue );
     119             :         }
     120             :         //todo: handle additional width types:
     121             :         //NS_ooxml::LN_Value_ST_TblWidth_nil, NS_ooxml::LN_Value_ST_TblWidth_pct,
     122             :         //NS_ooxml::LN_Value_ST_TblWidth_dxa, NS_ooxml::LN_Value_ST_TblWidth_auto;
     123             :     }
     124       11644 :     return nRet;
     125             : }
     126             : 
     127        1213 : void MeasureHandler::enableInteropGrabBag(const OUString& aName)
     128             : {
     129        1213 :     m_aInteropGrabBagName = aName;
     130        1213 : }
     131             : 
     132        1213 : beans::PropertyValue MeasureHandler::getInteropGrabBag()
     133             : {
     134        1213 :     beans::PropertyValue aRet;
     135        1213 :     aRet.Name = m_aInteropGrabBagName;
     136             : 
     137        2426 :     uno::Sequence<beans::PropertyValue> aSeq(m_aInteropGrabBag.size());
     138        1213 :     beans::PropertyValue* pSeq = aSeq.getArray();
     139        3639 :     for (std::vector<beans::PropertyValue>::iterator i = m_aInteropGrabBag.begin(); i != m_aInteropGrabBag.end(); ++i)
     140        2426 :         *pSeq++ = *i;
     141             : 
     142        1213 :     aRet.Value = uno::makeAny(aSeq);
     143        2426 :     return aRet;
     144             : }
     145             : 
     146             : } //namespace dmapper
     147             : } //namespace writerfilter
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10