LCOV - code coverage report
Current view: top level - libreoffice/writerfilter/source/dmapper - BorderHandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 61 70 87.1 %
Date: 2012-12-27 Functions: 9 9 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 <PropertyMap.hxx>
      21             : #include <resourcemodel/QNameToString.hxx>
      22             : #include <doctok/resourceids.hxx>
      23             : #include <ConversionHelper.hxx>
      24             : #include <com/sun/star/table/BorderLine2.hpp>
      25             : #include <ooxml/resourceids.hxx>
      26             : #include <dmapperLoggers.hxx>
      27             : 
      28             : namespace writerfilter {
      29             : 
      30             : namespace dmapper {
      31             : 
      32             : using namespace ::com::sun::star;
      33             : 
      34             : 
      35          57 : BorderHandler::BorderHandler( bool bOOXML ) :
      36             : LoggedProperties(dmapper_logger, "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          57 : m_bOOXML( bOOXML )
      43             : {
      44          57 :     const int nBorderCount(BORDER_COUNT);
      45          57 :     std::fill_n(m_aFilledLines, nBorderCount, false);
      46          57 :     std::fill_n(m_aBorderLines, nBorderCount, table::BorderLine2());
      47          57 : }
      48             : 
      49         114 : BorderHandler::~BorderHandler()
      50             : {
      51         114 : }
      52             : 
      53         777 : void BorderHandler::lcl_attribute(Id rName, Value & rVal)
      54             : {
      55         777 :     sal_Int32 nIntValue = rVal.getInt();
      56         777 :     switch( rName )
      57             :     {
      58             :         case NS_rtf::LN_rgbrc:
      59             :         {
      60           0 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rVal.getProperties();
      61           0 :             if( pProperties.get())
      62             :             {
      63           0 :                 pProperties->resolve(*this);
      64             :                 ConversionHelper::MakeBorderLine( m_nLineWidth,   m_nLineType, m_nLineColor,
      65           0 :                                                                                 m_aBorderLines[m_nCurrentBorderPosition], m_bOOXML );
      66             :                 OSL_ENSURE(m_nCurrentBorderPosition < BORDER_COUNT, "too many border values");
      67           0 :                 ++m_nCurrentBorderPosition;
      68           0 :             }
      69             :         }
      70           0 :         break;
      71             :         case NS_rtf::LN_DPTLINEWIDTH: // 0x2871
      72             :             //  width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2.
      73         174 :             m_nLineWidth = nIntValue * 5 / 2;
      74         174 :         break;
      75             :         case NS_rtf::LN_BRCTYPE:    // 0x2872
      76         196 :             m_nLineType = nIntValue;
      77         196 :         break;
      78             :         case NS_ooxml::LN_CT_Border_color:
      79             :         case NS_rtf::LN_ICO:        // 0x2873
      80         173 :             m_nLineColor = nIntValue;
      81         173 :         break;
      82             :         case NS_rtf::LN_DPTSPACE:   // border distance in points
      83         174 :             m_nLineDistance = ConversionHelper::convertTwipToMM100( nIntValue * 20 );
      84         174 :         break;
      85             :         case NS_rtf::LN_FSHADOW:    // 0x2875
      86             :             //if 1 then line has shadow - unsupported
      87             :         case NS_rtf::LN_FFRAME:     // 0x2876
      88             :         case NS_rtf::LN_UNUSED2_15: // 0x2877
      89             :             // ignored
      90           0 :         break;
      91           5 :         case NS_ooxml::LN_CT_Border_themeTint: break;
      92          55 :         case NS_ooxml::LN_CT_Border_themeColor: break;
      93             :         default:
      94             :             OSL_FAIL( "unknown attribute");
      95             :     }
      96         777 : }
      97             : 
      98         168 : void BorderHandler::lcl_sprm(Sprm & rSprm)
      99             : {
     100         168 :     BorderPosition pos = BORDER_COUNT; // invalid pos
     101         168 :     bool rtl = false; // TODO detect
     102         168 :     switch( rSprm.getId())
     103             :     {
     104             :         case NS_ooxml::LN_CT_TblBorders_top:
     105          28 :             pos = BORDER_TOP;
     106          28 :             break;
     107             :         case NS_ooxml::LN_CT_TblBorders_start:
     108           5 :             pos = rtl ? BORDER_RIGHT : BORDER_LEFT;
     109           5 :             break;
     110             :         case NS_ooxml::LN_CT_TblBorders_left:
     111          23 :             pos = BORDER_LEFT;
     112          23 :             break;
     113             :         case NS_ooxml::LN_CT_TblBorders_bottom:
     114          29 :             pos = BORDER_BOTTOM;
     115          29 :             break;
     116             :         case NS_ooxml::LN_CT_TblBorders_end:
     117           5 :             pos = rtl ? BORDER_LEFT : BORDER_RIGHT;
     118           5 :             break;
     119             :         case NS_ooxml::LN_CT_TblBorders_right:
     120          23 :             pos = BORDER_RIGHT;
     121          23 :             break;
     122             :         case NS_ooxml::LN_CT_TblBorders_insideH:
     123          27 :             pos = BORDER_HORIZONTAL;
     124          27 :             break;
     125             :         case NS_ooxml::LN_CT_TblBorders_insideV:
     126          28 :             pos = BORDER_VERTICAL;
     127          28 :             break;
     128             :         default:
     129           0 :             break;
     130             :     }
     131         168 :     if( pos != BORDER_COUNT )
     132             :     {
     133         168 :         writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     134         168 :         if( pProperties.get())
     135         168 :             pProperties->resolve(*this);
     136             :         ConversionHelper::MakeBorderLine( m_nLineWidth,   m_nLineType, m_nLineColor,
     137         168 :                                m_aBorderLines[ pos ], m_bOOXML );
     138         168 :         m_aFilledLines[ pos ] = true;
     139             :     }
     140         168 : }
     141             : 
     142          29 : PropertyMapPtr  BorderHandler::getProperties()
     143             : {
     144             :     static const PropertyIds aPropNames[BORDER_COUNT] =
     145             :     {
     146             :         PROP_TOP_BORDER,
     147             :         PROP_LEFT_BORDER,
     148             :         PROP_BOTTOM_BORDER,
     149             :         PROP_RIGHT_BORDER,
     150             :         META_PROP_HORIZONTAL_BORDER,
     151             :         META_PROP_VERTICAL_BORDER
     152             :     };
     153          29 :     PropertyMapPtr pPropertyMap(new PropertyMap);
     154             :     // don't fill in default properties
     155          29 :     if( m_bOOXML || m_nCurrentBorderPosition )
     156             :     {
     157         203 :         for( sal_Int32 nProp = 0; nProp < BORDER_COUNT; ++nProp)
     158             :         {
     159         174 :             if ( m_aFilledLines[nProp] ) {
     160         168 :                 pPropertyMap->Insert( aPropNames[nProp], false, uno::makeAny( m_aBorderLines[nProp] ) );
     161             :             }
     162             :         }
     163             :     }
     164          29 :     return pPropertyMap;
     165             : }
     166             : /*-------------------------------------------------------------------------
     167             :     used only in OOXML import
     168             :   -----------------------------------------------------------------------*/
     169          28 : table::BorderLine2 BorderHandler::getBorderLine()
     170             : {
     171          28 :     table::BorderLine2 aBorderLine;
     172          28 :     ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor, aBorderLine, m_bOOXML );
     173          28 :     return aBorderLine;
     174             : }
     175             : 
     176             : } //namespace dmapper
     177          15 : } //namespace writerfilter
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10