LCOV - code coverage report
Current view: top level - libreoffice/writerfilter/source/dmapper - GraphicHelpers.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 56 110 50.9 %
Date: 2012-12-17 Functions: 10 18 55.6 %
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 "ConversionHelper.hxx"
      20             : #include "GraphicHelpers.hxx"
      21             : 
      22             : #include <ooxml/resourceids.hxx>
      23             : 
      24             : #include <com/sun/star/text/HoriOrientation.hpp>
      25             : #include <com/sun/star/text/VertOrientation.hpp>
      26             : #include <com/sun/star/text/RelOrientation.hpp>
      27             : #include <com/sun/star/text/WrapTextMode.hpp>
      28             : 
      29             : #include "dmapperLoggers.hxx"
      30             : 
      31             : #include <iostream>
      32             : using namespace std;
      33             : 
      34             : namespace writerfilter {
      35             : namespace dmapper {
      36             : 
      37             : using namespace com::sun::star;
      38             : 
      39             : int PositionHandler::savedPositionOffsetV = 0;
      40             : int PositionHandler::savedPositionOffsetH = 0;
      41             : int PositionHandler::savedAlignV = text::VertOrientation::NONE;
      42             : int PositionHandler::savedAlignH = text::HoriOrientation::NONE;
      43             : 
      44          20 : PositionHandler::PositionHandler( bool vertical ) :
      45          20 : LoggedProperties(dmapper_logger, "PositionHandler")
      46             : {
      47          20 :     m_nRelation = text::RelOrientation::FRAME;
      48          20 :     if( vertical )
      49             :     {
      50          10 :         m_nPosition = savedPositionOffsetV;
      51          10 :         m_nOrient = savedAlignV;
      52          10 :         savedPositionOffsetV = 0;
      53          10 :         savedAlignV = text::VertOrientation::NONE;
      54             :     }
      55             :     else
      56             :     {
      57          10 :         m_nPosition = savedPositionOffsetH;
      58          10 :         m_nOrient = savedAlignH;
      59          10 :         savedPositionOffsetH = 0;
      60          10 :         savedAlignH = text::HoriOrientation::NONE;
      61             :     }
      62          20 : }
      63             : 
      64          40 : PositionHandler::~PositionHandler( )
      65             : {
      66          40 : }
      67             : 
      68          20 : void PositionHandler::lcl_attribute( Id aName, Value& rVal )
      69             : {
      70          20 :     sal_Int32 nIntValue = rVal.getInt( );
      71          20 :     switch ( aName )
      72             :     {
      73             :         case NS_ooxml::LN_CT_PosV_relativeFrom:
      74             :             {
      75             :                 // TODO There are some other unhandled values
      76             :                 static Id pVertRelValues[] =
      77             :                 {
      78             :                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_margin,
      79             :                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_page,
      80             :                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_paragraph,
      81             :                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_line
      82             :                 };
      83             : 
      84             :                 static sal_Int16 pVertRelations[] =
      85             :                 {
      86             :                     text::RelOrientation::PAGE_PRINT_AREA,
      87             :                     text::RelOrientation::PAGE_FRAME,
      88             :                     text::RelOrientation::FRAME,
      89             :                     text::RelOrientation::TEXT_LINE
      90             :                 };
      91             : 
      92          50 :                 for ( int i = 0; i < 4; i++ )
      93             :                 {
      94          40 :                     if ( pVertRelValues[i] == sal_uInt32( nIntValue ) )
      95          10 :                         m_nRelation = pVertRelations[i];
      96             :                 }
      97             :             }
      98          10 :             break;
      99             :         case NS_ooxml::LN_CT_PosH_relativeFrom:
     100             :             {
     101             :                 // TODO There are some other unhandled values
     102             :                 static Id pHoriRelValues[] =
     103             :                 {
     104             :                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_margin,
     105             :                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_page,
     106             :                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_column,
     107             :                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_character
     108             :                 };
     109             : 
     110             :                 static sal_Int16 pHoriRelations[] =
     111             :                 {
     112             :                     text::RelOrientation::PAGE_PRINT_AREA,
     113             :                     text::RelOrientation::PAGE_FRAME,
     114             :                     text::RelOrientation::FRAME,
     115             :                     text::RelOrientation::CHAR,
     116             :                 };
     117             : 
     118          50 :                 for ( int i = 0; i < 4; i++ )
     119             :                 {
     120          40 :                     if ( pHoriRelValues[i] == sal_uInt32( nIntValue ) )
     121          10 :                         m_nRelation = pHoriRelations[i];
     122             :                 }
     123             :             }
     124          10 :             break;
     125             :         default:
     126             : #ifdef DEBUG_DOMAINMAPPER
     127             :             dmapper_logger->element("unhandled");
     128             : #endif
     129           0 :             break;
     130             :     }
     131          20 : }
     132             : 
     133          20 : void PositionHandler::lcl_sprm( Sprm& )
     134             : {
     135          20 : }
     136             : 
     137          20 : void PositionHandler::setPositionOffset(const OUString & sText, bool vertical)
     138             : {
     139          20 :     if( vertical )
     140          10 :         savedPositionOffsetV = ConversionHelper::convertEMUToMM100( sText.toInt32());
     141             :     else
     142          10 :         savedPositionOffsetH = ConversionHelper::convertEMUToMM100( sText.toInt32());
     143          20 : }
     144             : 
     145           0 : void PositionHandler::setAlignH(const OUString & sText)
     146             : {
     147           0 :     if( sText == "left")
     148           0 :         savedAlignH = text::HoriOrientation::LEFT;
     149           0 :     else if( sText == "right" )
     150           0 :         savedAlignH = text::HoriOrientation::RIGHT;
     151           0 :     else if( sText == "center" )
     152           0 :         savedAlignH = text::HoriOrientation::CENTER;
     153           0 :     else if( sText == "inside" )
     154           0 :         savedAlignH = text::HoriOrientation::INSIDE;
     155           0 :     else if( sText == "outside" )
     156           0 :         savedAlignH = text::HoriOrientation::OUTSIDE;
     157           0 : }
     158             : 
     159           0 : void PositionHandler::setAlignV(const OUString & sText)
     160             : {
     161           0 :     if( sText == "top" )
     162           0 :         savedAlignV = text::VertOrientation::TOP;
     163           0 :     else if( sText == "bottom" )
     164           0 :         savedAlignV = text::VertOrientation::BOTTOM;
     165           0 :     else if( sText == "center" )
     166           0 :         savedAlignV = text::VertOrientation::CENTER;
     167           0 :     else if( sText == "inside" )
     168           0 :         savedAlignV = text::VertOrientation::NONE;
     169           0 :     else if( sText == "outside" )
     170           0 :         savedAlignV = text::VertOrientation::NONE;
     171           0 : }
     172             : 
     173           0 : WrapHandler::WrapHandler( ) :
     174             : LoggedProperties(dmapper_logger, "WrapHandler"),
     175             :     m_nType( 0 ),
     176           0 :     m_nSide( 0 )
     177             : {
     178           0 : }
     179             : 
     180           0 : WrapHandler::~WrapHandler( )
     181             : {
     182           0 : }
     183             : 
     184           0 : void WrapHandler::lcl_attribute( Id aName, Value& rVal )
     185             : {
     186           0 :     switch ( aName )
     187             :     {
     188             :         case NS_ooxml::LN_CT_Wrap_type:
     189           0 :             m_nType = sal_Int32( rVal.getInt( ) );
     190           0 :             break;
     191             :         case NS_ooxml::LN_CT_Wrap_side:
     192           0 :             m_nSide = sal_Int32( rVal.getInt( ) );
     193           0 :             break;
     194             :         default:;
     195             :     }
     196           0 : }
     197             : 
     198           0 : void WrapHandler::lcl_sprm( Sprm& )
     199             : {
     200           0 : }
     201             : 
     202           0 : sal_Int32 WrapHandler::getWrapMode( )
     203             : {
     204             :     // The wrap values do not map directly to our wrap mode,
     205             :     // e.g. none in .docx actually means through in LO.
     206           0 :     sal_Int32 nMode = com::sun::star::text::WrapTextMode_THROUGHT;
     207             : 
     208           0 :     switch ( m_nType )
     209             :     {
     210             :         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_square:
     211             :         // through and tight are somewhat complicated, approximate
     212             :         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_tight:
     213             :         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_through:
     214             :             {
     215           0 :                 switch ( m_nSide )
     216             :                 {
     217             :                     case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_left:
     218           0 :                         nMode = com::sun::star::text::WrapTextMode_LEFT;
     219           0 :                         break;
     220             :                     case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_right:
     221           0 :                         nMode = com::sun::star::text::WrapTextMode_RIGHT;
     222           0 :                         break;
     223             :                     default:
     224           0 :                         nMode = com::sun::star::text::WrapTextMode_PARALLEL;
     225             :                 }
     226             :             }
     227           0 :             break;
     228             :         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_topAndBottom:
     229           0 :             nMode = com::sun::star::text::WrapTextMode_NONE;
     230           0 :             break;
     231             :         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_none:
     232             :         default:
     233           0 :             nMode = com::sun::star::text::WrapTextMode_THROUGHT;
     234             :     }
     235             : 
     236           0 :     return nMode;
     237             : }
     238             : 
     239             : 
     240          38 : void GraphicZOrderHelper::addItem( uno::Reference< beans::XPropertySet > props, sal_Int32 relativeHeight )
     241             : {
     242          38 :     items[ relativeHeight ] = props;
     243          38 : }
     244             : 
     245             : // The relativeHeight value in .docx is an arbitrary number, where only the relative ordering matters.
     246             : // But in Writer, the z-order is index in 0..(numitems-1) range, so whenever a new item needs to be
     247             : // added in the proper z-order, it is necessary to find the proper index.
     248          38 : sal_Int32 GraphicZOrderHelper::findZOrder( sal_Int32 relativeHeight )
     249             : {
     250          38 :     Items::const_iterator it = items.begin();
     251          86 :     while( it != items.end())
     252             :     {
     253             :         // std::map is iterated sorted by key
     254          20 :         if( it->first > relativeHeight )
     255          10 :             break; // this is the first one higher, we belong right before it
     256             :         else
     257          10 :             ++it;
     258             :     }
     259          38 :     if( it == items.end()) // we're topmost
     260             :     {
     261          28 :         if( items.empty())
     262          20 :             return 0;
     263           8 :         sal_Int32 itemZOrder(0);
     264           8 :         --it;
     265          32 :         if( it->second->getPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier()
     266          24 :             .GetName( PROP_Z_ORDER )) >>= itemZOrder )
     267           8 :             return itemZOrder + 1; // after the topmost
     268             :     }
     269             :     else
     270             :     {
     271          10 :         sal_Int32 itemZOrder(0);
     272          40 :         if( it->second->getPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier()
     273          30 :             .GetName( PROP_Z_ORDER )) >>= itemZOrder )
     274          10 :             return itemZOrder; // before the item
     275             :     }
     276             :     SAL_WARN( "writerfilter", "findZOrder() didn't find item z-order" );
     277           0 :     return 0; // this should not(?) happen
     278             : }
     279             : 
     280          30 : } }
     281             : 
     282             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10