LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - TablePositionHandler.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 84 91 92.3 %
Date: 2015-06-13 12:38:46 Functions: 6 7 85.7 %
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             : #include <TablePositionHandler.hxx>
      10             : #include <ConversionHelper.hxx>
      11             : #include <ooxml/resourceids.hxx>
      12             : #include <com/sun/star/text/HoriOrientation.hpp>
      13             : #include <com/sun/star/text/VertOrientation.hpp>
      14             : #include <com/sun/star/text/RelOrientation.hpp>
      15             : #include <comphelper/sequenceashashmap.hxx>
      16             : 
      17             : namespace writerfilter
      18             : {
      19             : namespace dmapper
      20             : {
      21             : 
      22             : using namespace ::com::sun::star;
      23             : 
      24         269 : TablePositionHandler::TablePositionHandler() :
      25             :     LoggedProperties("TablePositionHandler"),
      26             :     m_aVertAnchor("margin"),
      27             :     m_aYSpec(),
      28             :     m_aHorzAnchor("text"),
      29             :     m_aXSpec(),
      30             :     m_nY(0),
      31             :     m_nX(0),
      32             :     m_nLeftFromText(0),
      33             :     m_nRightFromText(0),
      34             :     m_nTopFromText(0),
      35         269 :     m_nBottomFromText(0)
      36             : {
      37         269 : }
      38             : 
      39         538 : TablePositionHandler::~TablePositionHandler()
      40             : {
      41         538 : }
      42             : 
      43             : 
      44        1229 : void TablePositionHandler::lcl_attribute(Id rName, Value& rVal)
      45             : {
      46        1229 :     switch (rName)
      47             :     {
      48             :     case NS_ooxml::LN_CT_TblPPr_vertAnchor:
      49         127 :         m_aVertAnchor = rVal.getString();
      50         127 :         break;
      51             :     case NS_ooxml::LN_CT_TblPPr_tblpYSpec:
      52           3 :         m_aYSpec = rVal.getString();
      53           3 :         break;
      54             :     case NS_ooxml::LN_CT_TblPPr_horzAnchor:
      55         223 :         m_aHorzAnchor = rVal.getString();
      56         223 :         break;
      57             :     case NS_ooxml::LN_CT_TblPPr_tblpXSpec:
      58          24 :         m_aXSpec = rVal.getString();
      59          24 :         break;
      60             :     case NS_ooxml::LN_CT_TblPPr_tblpY:
      61         266 :         m_nY = rVal.getInt();
      62         266 :         break;
      63             :     case NS_ooxml::LN_CT_TblPPr_tblpX:
      64          24 :         m_nX = rVal.getInt();
      65          24 :         break;
      66             :     case NS_ooxml::LN_CT_TblPPr_leftFromText:
      67         266 :         m_nLeftFromText = rVal.getInt();
      68         266 :         break;
      69             :     case NS_ooxml::LN_CT_TblPPr_rightFromText:
      70         266 :         m_nRightFromText = rVal.getInt();
      71         266 :         break;
      72             :     case NS_ooxml::LN_CT_TblPPr_topFromText:
      73          15 :         m_nTopFromText = rVal.getInt();
      74          15 :         break;
      75             :     case NS_ooxml::LN_CT_TblPPr_bottomFromText:
      76          15 :         m_nBottomFromText = rVal.getInt();
      77          15 :         break;
      78             :     default:
      79             : #ifdef DEBUG_WRITERFILTER
      80             :         TagLogger::getInstance().element("unhandled");
      81             : #endif
      82           0 :         break;
      83             :     }
      84        1229 : }
      85             : 
      86             : 
      87           0 : void TablePositionHandler::lcl_sprm(Sprm& /*rSprm*/)
      88             : {
      89           0 : }
      90             : 
      91             : 
      92          43 : uno::Sequence<beans::PropertyValue> TablePositionHandler::getTablePosition() const
      93             : {
      94          43 :     comphelper::SequenceAsHashMap aFrameProperties;
      95             : 
      96          43 :     aFrameProperties["LeftBorderDistance"] <<= sal_Int32(0);
      97          43 :     aFrameProperties["RightBorderDistance"] <<= sal_Int32(0);
      98          43 :     aFrameProperties["TopBorderDistance"] <<= sal_Int32(0);
      99          43 :     aFrameProperties["BottomBorderDistance"] <<= sal_Int32(0);
     100             : 
     101          43 :     aFrameProperties["LeftMargin"] <<= ConversionHelper::convertTwipToMM100(m_nLeftFromText);
     102          43 :     aFrameProperties["RightMargin"] <<= ConversionHelper::convertTwipToMM100(m_nRightFromText);
     103          43 :     aFrameProperties["TopMargin"] <<= ConversionHelper::convertTwipToMM100(m_nTopFromText);
     104          43 :     aFrameProperties["BottomMargin"] <<= ConversionHelper::convertTwipToMM100(m_nBottomFromText);
     105             : 
     106          43 :     table::BorderLine2 aEmptyBorder;
     107          43 :     aFrameProperties["TopBorder"] <<= aEmptyBorder;
     108          43 :     aFrameProperties["BottomBorder"] <<= aEmptyBorder;
     109          43 :     aFrameProperties["LeftBorder"] <<= aEmptyBorder;
     110          43 :     aFrameProperties["RightBorder"] <<= aEmptyBorder;
     111             : 
     112             :     // Horizontal positioning
     113          43 :     sal_Int16 nHoriOrient = text::HoriOrientation::NONE;
     114          43 :     if (m_aXSpec == "center")
     115          13 :         nHoriOrient = text::HoriOrientation::CENTER;
     116          30 :     else if (m_aXSpec == "inside")
     117           0 :         nHoriOrient = text::HoriOrientation::INSIDE;
     118          30 :     else if (m_aXSpec == "left")
     119           0 :         nHoriOrient = text::HoriOrientation::LEFT;
     120          30 :     else if (m_aXSpec == "outside")
     121           0 :         nHoriOrient = text::HoriOrientation::OUTSIDE;
     122          30 :     else if (m_aXSpec == "right")
     123           1 :         nHoriOrient = text::HoriOrientation::RIGHT;
     124             : 
     125             :     sal_Int16 nHoriOrientRelation;
     126          43 :     if (m_aHorzAnchor == "margin")
     127          29 :         nHoriOrientRelation = text::RelOrientation::PAGE_PRINT_AREA;
     128          14 :     else if (m_aHorzAnchor == "page")
     129           3 :         nHoriOrientRelation = text::RelOrientation::PAGE_FRAME;
     130          11 :     else if (m_aHorzAnchor == "text")
     131          11 :         nHoriOrientRelation = text::RelOrientation::FRAME;
     132             : 
     133          43 :     aFrameProperties["HoriOrient"] <<= nHoriOrient;
     134          43 :     aFrameProperties["HoriOrientRelation"] <<= nHoriOrientRelation;
     135          43 :     aFrameProperties["HoriOrientPosition"] <<= ConversionHelper::convertTwipToMM100(m_nX);
     136             : 
     137             :     // Vertical positioning
     138          43 :     sal_Int16 nVertOrient = text::VertOrientation::NONE;
     139          43 :     if (m_aYSpec == "bottom")
     140           1 :         nVertOrient = text::VertOrientation::BOTTOM;
     141          42 :     else if (m_aYSpec == "center")
     142           0 :         nVertOrient = text::VertOrientation::CENTER;
     143          42 :     else if (m_aYSpec == "top")
     144           1 :         nVertOrient = text::VertOrientation::TOP;
     145             :     // TODO There are a few cases we can't map ATM.
     146             : 
     147             : 
     148             :     sal_Int16 nVertOrientRelation;
     149          43 :     if (m_aVertAnchor == "margin")
     150           5 :         nVertOrientRelation = text::RelOrientation::PAGE_PRINT_AREA;
     151          38 :     else if (m_aVertAnchor == "page")
     152          12 :         nVertOrientRelation = text::RelOrientation::PAGE_FRAME;
     153          26 :     else if (m_aVertAnchor == "text")
     154          26 :         nVertOrientRelation = text::RelOrientation::FRAME;
     155             : 
     156          43 :     aFrameProperties["VertOrient"] <<= nVertOrient;
     157          43 :     aFrameProperties["VertOrientRelation"] <<= nVertOrientRelation;
     158          43 :     aFrameProperties["VertOrientPosition"] <<= ConversionHelper::convertTwipToMM100(m_nY);
     159          43 :     aFrameProperties["FillTransparence"] <<= sal_Int32(100);
     160             : 
     161          43 :     return aFrameProperties.getAsConstPropertyValueList();
     162             : }
     163             : 
     164         227 : bool TablePositionHandler::operator== (const TablePositionHandler& rHandler) const
     165             : {
     166         454 :     return m_aVertAnchor == rHandler.m_aVertAnchor &&
     167         454 :            m_aYSpec == rHandler.m_aYSpec &&
     168         454 :            m_aHorzAnchor == rHandler.m_aHorzAnchor &&
     169         454 :            m_aXSpec == rHandler.m_aXSpec &&
     170         680 :            m_nY == rHandler.m_nY &&
     171         453 :            m_nX == rHandler.m_nX;
     172             : }
     173             : 
     174             : } // namespace dmapper
     175             : } // namespace writerfilter
     176             : 
     177             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11