LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - BorderHandler.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 102 103 99.0 %
Date: 2015-06-13 12:38:46 Functions: 10 10 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 <BorderHandler.hxx>
      20             : #include <TDefTableHandler.hxx>
      21             : #include <PropertyMap.hxx>
      22             : #include <ConversionHelper.hxx>
      23             : #include <com/sun/star/table/BorderLine2.hpp>
      24             : #include <ooxml/resourceids.hxx>
      25             : #include <filter/msfilter/util.hxx>
      26             : #include <comphelper/sequence.hxx>
      27             : 
      28             : namespace writerfilter {
      29             : 
      30             : namespace dmapper {
      31             : 
      32             : using namespace ::com::sun::star;
      33             : 
      34             : 
      35        3397 : BorderHandler::BorderHandler( bool bOOXML ) :
      36             : LoggedProperties("BorderHandler"),
      37             : m_nCurrentBorderPosition( BORDER_TOP ),
      38             : m_nLineWidth(15), // Word default, in twips
      39             : m_nLineType(0),
      40             : m_nLineColor(0),
      41             : m_nLineDistance(0),
      42             : m_bShadow(false),
      43        3397 : m_bOOXML( bOOXML )
      44             : {
      45        3397 :     const int nBorderCount(BORDER_COUNT);
      46        3397 :     std::fill_n(m_aFilledLines, nBorderCount, false);
      47        3397 :     std::fill_n(m_aBorderLines, nBorderCount, table::BorderLine2());
      48        3397 : }
      49             : 
      50        6794 : BorderHandler::~BorderHandler()
      51             : {
      52        6794 : }
      53             : 
      54       48083 : void BorderHandler::lcl_attribute(Id rName, Value & rVal)
      55             : {
      56       48083 :     sal_Int32 nIntValue = rVal.getInt();
      57       48083 :     switch( rName )
      58             :     {
      59             :         case NS_ooxml::LN_CT_Border_sz:
      60             :             //  width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2.
      61       11741 :             m_nLineWidth = nIntValue * 5 / 2;
      62       11741 :             appendGrabBag("sz", OUString::number(nIntValue));
      63       11741 :         break;
      64             :         case NS_ooxml::LN_CT_Border_val:
      65       11914 :             m_nLineType = nIntValue;
      66       11914 :             appendGrabBag("val", TDefTableHandler::getBorderTypeString(nIntValue));
      67       11914 :         break;
      68             :         case NS_ooxml::LN_CT_Border_color:
      69       11740 :             m_nLineColor = nIntValue;
      70       11740 :             appendGrabBag("color", OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue, /*bAutoColor=*/true)));
      71       11740 :         break;
      72             :         case NS_ooxml::LN_CT_Border_space: // border distance in points
      73       11741 :             m_nLineDistance = ConversionHelper::convertTwipToMM100( nIntValue * 20 );
      74       11741 :             appendGrabBag("space", OUString::number(nIntValue));
      75       11741 :         break;
      76             :         case NS_ooxml::LN_CT_Border_shadow:
      77          88 :             m_bShadow = nIntValue;
      78          88 :         break;
      79             :         case NS_ooxml::LN_CT_Border_frame:
      80             :         case NS_ooxml::LN_CT_Border_themeTint:
      81          65 :             appendGrabBag("themeTint", OUString::number(nIntValue, 16));
      82          65 :             break;
      83             :         case NS_ooxml::LN_CT_Border_themeColor:
      84         714 :             appendGrabBag("themeColor", TDefTableHandler::getThemeColorTypeString(nIntValue));
      85         714 :             break;
      86             :         default:
      87             :             OSL_FAIL( "unknown attribute");
      88             :     }
      89       48083 : }
      90             : 
      91       10739 : void BorderHandler::lcl_sprm(Sprm & rSprm)
      92             : {
      93       10739 :     BorderPosition pos = BORDER_COUNT; // invalid pos
      94       10739 :     const bool rtl = false; // TODO detect
      95       10739 :     OUString aBorderPos;
      96       10739 :     switch( rSprm.getId())
      97             :     {
      98             :         case NS_ooxml::LN_CT_TblBorders_top:
      99        1873 :             pos = BORDER_TOP;
     100        1873 :             aBorderPos = "top";
     101        1873 :             break;
     102             :         case NS_ooxml::LN_CT_TblBorders_start:
     103         239 :             pos = rtl ? BORDER_RIGHT : BORDER_LEFT;
     104         239 :             aBorderPos = "start";
     105         239 :             break;
     106             :         case NS_ooxml::LN_CT_TblBorders_left:
     107        1568 :             pos = BORDER_LEFT;
     108        1568 :             aBorderPos = "left";
     109        1568 :             break;
     110             :         case NS_ooxml::LN_CT_TblBorders_bottom:
     111        1933 :             pos = BORDER_BOTTOM;
     112        1933 :             aBorderPos = "bottom";
     113        1933 :             break;
     114             :         case NS_ooxml::LN_CT_TblBorders_end:
     115         217 :             pos = rtl ? BORDER_LEFT : BORDER_RIGHT;
     116         217 :             aBorderPos = "end";
     117         217 :             break;
     118             :         case NS_ooxml::LN_CT_TblBorders_right:
     119        1568 :             pos = BORDER_RIGHT;
     120        1568 :             aBorderPos = "right";
     121        1568 :             break;
     122             :         case NS_ooxml::LN_CT_TblBorders_insideH:
     123        1688 :             pos = BORDER_HORIZONTAL;
     124        1688 :             aBorderPos = "insideH";
     125        1688 :             break;
     126             :         case NS_ooxml::LN_CT_TblBorders_insideV:
     127        1653 :             pos = BORDER_VERTICAL;
     128        1653 :             aBorderPos = "insideV";
     129        1653 :             break;
     130             :         default:
     131           0 :             break;
     132             :     }
     133       10739 :     if( pos != BORDER_COUNT )
     134             :     {
     135       10739 :         writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     136       10739 :         if( pProperties.get())
     137             :         {
     138       10739 :             std::vector<beans::PropertyValue> aSavedGrabBag;
     139       10739 :             if (!m_aInteropGrabBagName.isEmpty())
     140             :             {
     141        4953 :                 aSavedGrabBag = m_aInteropGrabBag;
     142        4953 :                 m_aInteropGrabBag.clear();
     143             :             }
     144       10739 :             pProperties->resolve(*this);
     145       10739 :             if (!m_aInteropGrabBagName.isEmpty())
     146             :             {
     147        4953 :                 aSavedGrabBag.push_back(getInteropGrabBag(aBorderPos));
     148        4953 :                 m_aInteropGrabBag = aSavedGrabBag;
     149       10739 :             }
     150             :         }
     151             :         ConversionHelper::MakeBorderLine( m_nLineWidth,   m_nLineType, m_nLineColor,
     152       10739 :                                m_aBorderLines[ pos ], m_bOOXML );
     153       10739 :         m_aFilledLines[ pos ] = true;
     154       10739 :     }
     155       10739 : }
     156             : 
     157        2222 : PropertyMapPtr  BorderHandler::getProperties()
     158             : {
     159             :     static const PropertyIds aPropNames[BORDER_COUNT] =
     160             :     {
     161             :         PROP_TOP_BORDER,
     162             :         PROP_LEFT_BORDER,
     163             :         PROP_BOTTOM_BORDER,
     164             :         PROP_RIGHT_BORDER,
     165             :         META_PROP_HORIZONTAL_BORDER,
     166             :         META_PROP_VERTICAL_BORDER
     167             :     };
     168        2222 :     PropertyMapPtr pPropertyMap(new PropertyMap);
     169             :     // don't fill in default properties
     170        2222 :     if( m_bOOXML || m_nCurrentBorderPosition )
     171             :     {
     172       15554 :         for( sal_Int32 nProp = 0; nProp < BORDER_COUNT; ++nProp)
     173             :         {
     174       13332 :             if ( m_aFilledLines[nProp] ) {
     175       10739 :                 pPropertyMap->Insert( aPropNames[nProp], uno::makeAny( m_aBorderLines[nProp] ) );
     176             :             }
     177             :         }
     178             :     }
     179        2222 :     return pPropertyMap;
     180             : }
     181             : /*-------------------------------------------------------------------------
     182             :     used only in OOXML import
     183             :   -----------------------------------------------------------------------*/
     184        1746 : table::BorderLine2 BorderHandler::getBorderLine()
     185             : {
     186        1746 :     table::BorderLine2 aBorderLine;
     187        1746 :     ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor, aBorderLine, m_bOOXML );
     188        1746 :     return aBorderLine;
     189             : }
     190             : 
     191             : 
     192         978 : void BorderHandler::enableInteropGrabBag(const OUString& aName)
     193             : {
     194         978 :     m_aInteropGrabBagName = aName;
     195         978 : }
     196             : 
     197        5931 : beans::PropertyValue BorderHandler::getInteropGrabBag(const OUString& aName)
     198             : {
     199        5931 :     beans::PropertyValue aRet;
     200        5931 :     if (aName.isEmpty())
     201         978 :         aRet.Name = m_aInteropGrabBagName;
     202             :     else
     203        4953 :         aRet.Name = aName;
     204             : 
     205        5931 :     aRet.Value = uno::makeAny(comphelper::containerToSequence(m_aInteropGrabBag));
     206        5931 :     return aRet;
     207             : }
     208             : 
     209       47915 : void BorderHandler::appendGrabBag(const OUString& aKey, const OUString& aValue)
     210             : {
     211       47915 :     beans::PropertyValue aProperty;
     212       47915 :     aProperty.Name = aKey;
     213       47915 :     aProperty.Value = uno::makeAny(aValue);
     214       47915 :     m_aInteropGrabBag.push_back(aProperty);
     215       47915 : }
     216             : 
     217             : } //namespace dmapper
     218             : } //namespace writerfilter
     219             : 
     220             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11