LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - GraphicHelpers.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 126 0.0 %
Date: 2014-04-14 Functions: 0 22 0.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 "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           0 : PositionHandler::PositionHandler( bool vertical ) :
      45           0 : LoggedProperties(dmapper_logger, "PositionHandler")
      46             : {
      47           0 :     m_nRelation = text::RelOrientation::FRAME;
      48           0 :     if( vertical )
      49             :     {
      50           0 :         m_nPosition = savedPositionOffsetV;
      51           0 :         m_nOrient = savedAlignV;
      52           0 :         savedPositionOffsetV = 0;
      53           0 :         savedAlignV = text::VertOrientation::NONE;
      54             :     }
      55             :     else
      56             :     {
      57           0 :         m_nPosition = savedPositionOffsetH;
      58           0 :         m_nOrient = savedAlignH;
      59           0 :         savedPositionOffsetH = 0;
      60           0 :         savedAlignH = text::HoriOrientation::NONE;
      61             :     }
      62           0 : }
      63             : 
      64           0 : PositionHandler::~PositionHandler( )
      65             : {
      66           0 : }
      67             : 
      68           0 : void PositionHandler::lcl_attribute( Id aName, Value& rVal )
      69             : {
      70           0 :     sal_Int32 nIntValue = rVal.getInt( );
      71           0 :     switch ( aName )
      72             :     {
      73             :         case NS_ooxml::LN_CT_PosV_relativeFrom:
      74             :             {
      75             :                 // TODO There are some other unhandled values
      76             :                 static const 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 const 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           0 :                 for ( int i = 0; i < 4; i++ )
      93             :                 {
      94           0 :                     if ( pVertRelValues[i] == sal_uInt32( nIntValue ) )
      95           0 :                         m_nRelation = pVertRelations[i];
      96             :                 }
      97             :             }
      98           0 :             break;
      99             :         case NS_ooxml::LN_CT_PosH_relativeFrom:
     100             :             {
     101             :                 // TODO There are some other unhandled values
     102             :                 static const 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 const 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           0 :                 for ( int i = 0; i < 4; i++ )
     119             :                 {
     120           0 :                     if ( pHoriRelValues[i] == sal_uInt32( nIntValue ) )
     121           0 :                         m_nRelation = pHoriRelations[i];
     122             :                 }
     123             :             }
     124           0 :             break;
     125             :         default:
     126             : #ifdef DEBUG_DOMAINMAPPER
     127             :             dmapper_logger->element("unhandled");
     128             : #endif
     129           0 :             break;
     130             :     }
     131           0 : }
     132             : 
     133           0 : void PositionHandler::lcl_sprm( Sprm& )
     134             : {
     135           0 : }
     136             : 
     137           0 : sal_Int16 PositionHandler::orientation() const
     138             : {
     139           0 :     if( m_nRelation == text::RelOrientation::TEXT_LINE )
     140             :     { // It appears that to 'line of text' alignment is backwards to other alignments,
     141             :       // 'top' meaning putting on top of the line instead of having top at the line.
     142           0 :         if( m_nOrient == text::VertOrientation::TOP )
     143           0 :             return text::VertOrientation::BOTTOM;
     144           0 :         else if( m_nOrient == text::VertOrientation::BOTTOM )
     145           0 :             return text::VertOrientation::TOP;
     146             :     }
     147           0 :     return m_nOrient;
     148             : }
     149             : 
     150           0 : sal_Int16 PositionHandler::relation() const
     151             : {
     152           0 :     return m_nRelation;
     153             : }
     154             : 
     155           0 : sal_Int32 PositionHandler::position() const
     156             : {
     157           0 :     return m_nPosition;
     158             : }
     159             : 
     160           0 : void PositionHandler::setPositionOffset(const OUString & sText, bool vertical)
     161             : {
     162           0 :     if( vertical )
     163           0 :         savedPositionOffsetV = ConversionHelper::convertEMUToMM100( sText.toInt32());
     164             :     else
     165           0 :         savedPositionOffsetH = ConversionHelper::convertEMUToMM100( sText.toInt32());
     166           0 : }
     167             : 
     168           0 : int PositionHandler::getPositionOffset(bool vertical)
     169             : {
     170           0 :     if (vertical)
     171           0 :         return savedPositionOffsetV;
     172             :     else
     173           0 :         return savedPositionOffsetH;
     174             : }
     175             : 
     176           0 : void PositionHandler::setAlignH(const OUString & sText)
     177             : {
     178           0 :     if( sText == "left")
     179           0 :         savedAlignH = text::HoriOrientation::LEFT;
     180           0 :     else if( sText == "right" )
     181           0 :         savedAlignH = text::HoriOrientation::RIGHT;
     182           0 :     else if( sText == "center" )
     183           0 :         savedAlignH = text::HoriOrientation::CENTER;
     184           0 :     else if( sText == "inside" )
     185           0 :         savedAlignH = text::HoriOrientation::INSIDE;
     186           0 :     else if( sText == "outside" )
     187           0 :         savedAlignH = text::HoriOrientation::OUTSIDE;
     188           0 : }
     189             : 
     190           0 : void PositionHandler::setAlignV(const OUString & sText)
     191             : {
     192           0 :     if( sText == "top" )
     193           0 :         savedAlignV = text::VertOrientation::TOP;
     194           0 :     else if( sText == "bottom" )
     195           0 :         savedAlignV = text::VertOrientation::BOTTOM;
     196           0 :     else if( sText == "center" )
     197           0 :         savedAlignV = text::VertOrientation::CENTER;
     198           0 :     else if( sText == "inside" )
     199           0 :         savedAlignV = text::VertOrientation::NONE;
     200           0 :     else if( sText == "outside" )
     201           0 :         savedAlignV = text::VertOrientation::NONE;
     202           0 : }
     203             : 
     204           0 : WrapHandler::WrapHandler( ) :
     205             : LoggedProperties(dmapper_logger, "WrapHandler"),
     206             :     m_nType( 0 ),
     207           0 :     m_nSide( 0 )
     208             : {
     209           0 : }
     210             : 
     211           0 : WrapHandler::~WrapHandler( )
     212             : {
     213           0 : }
     214             : 
     215           0 : void WrapHandler::lcl_attribute( Id aName, Value& rVal )
     216             : {
     217           0 :     switch ( aName )
     218             :     {
     219             :         case NS_ooxml::LN_CT_Wrap_type:
     220           0 :             m_nType = sal_Int32( rVal.getInt( ) );
     221           0 :             break;
     222             :         case NS_ooxml::LN_CT_Wrap_side:
     223           0 :             m_nSide = sal_Int32( rVal.getInt( ) );
     224           0 :             break;
     225             :         default:;
     226             :     }
     227           0 : }
     228             : 
     229           0 : void WrapHandler::lcl_sprm( Sprm& )
     230             : {
     231           0 : }
     232             : 
     233           0 : sal_Int32 WrapHandler::getWrapMode( )
     234             : {
     235             :     // The wrap values do not map directly to our wrap mode,
     236             :     // e.g. none in .docx actually means through in LO.
     237           0 :     sal_Int32 nMode = com::sun::star::text::WrapTextMode_THROUGHT;
     238             : 
     239           0 :     switch ( m_nType )
     240             :     {
     241             :         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_square:
     242             :         // through and tight are somewhat complicated, approximate
     243             :         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_tight:
     244             :         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_through:
     245             :             {
     246           0 :                 switch ( m_nSide )
     247             :                 {
     248             :                     case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_left:
     249           0 :                         nMode = com::sun::star::text::WrapTextMode_LEFT;
     250           0 :                         break;
     251             :                     case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_right:
     252           0 :                         nMode = com::sun::star::text::WrapTextMode_RIGHT;
     253           0 :                         break;
     254             :                     default:
     255           0 :                         nMode = com::sun::star::text::WrapTextMode_PARALLEL;
     256             :                 }
     257             :             }
     258           0 :             break;
     259             :         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_topAndBottom:
     260           0 :             nMode = com::sun::star::text::WrapTextMode_NONE;
     261           0 :             break;
     262             :         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_none:
     263             :         default:
     264           0 :             nMode = com::sun::star::text::WrapTextMode_THROUGHT;
     265             :     }
     266             : 
     267           0 :     return nMode;
     268             : }
     269             : 
     270             : 
     271           0 : void GraphicZOrderHelper::addItem( uno::Reference< beans::XPropertySet > props, sal_Int32 relativeHeight )
     272             : {
     273           0 :     items[ relativeHeight ] = props;
     274           0 : }
     275             : 
     276             : // The relativeHeight value in .docx is an arbitrary number, where only the relative ordering matters.
     277             : // But in Writer, the z-order is index in 0..(numitems-1) range, so whenever a new item needs to be
     278             : // added in the proper z-order, it is necessary to find the proper index.
     279           0 : sal_Int32 GraphicZOrderHelper::findZOrder( sal_Int32 relativeHeight, bool bOldStyle )
     280             : {
     281           0 :     Items::const_iterator it = items.begin();
     282           0 :     while( it != items.end())
     283             :     {
     284             :         // std::map is iterated sorted by key
     285             : 
     286             :         // Old-style ordering differs in what should happen when there is already an item with the same z-order:
     287             :         // we belong under it in case of new-style, but we belong below it in case of old-style.
     288           0 :         bool bCond = bOldStyle ? (it->first > relativeHeight) : (it->first >= relativeHeight);
     289             : 
     290           0 :         if( bCond )
     291           0 :             break; // this is the first one higher, we belong right before it
     292             :         else
     293           0 :             ++it;
     294             :     }
     295           0 :     if( it == items.end()) // we're topmost
     296             :     {
     297           0 :         if( items.empty())
     298           0 :             return 0;
     299           0 :         sal_Int32 itemZOrder(0);
     300           0 :         --it;
     301           0 :         if( it->second->getPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier()
     302           0 :             .GetName( PROP_Z_ORDER )) >>= itemZOrder )
     303           0 :             return itemZOrder + 1; // after the topmost
     304             :     }
     305             :     else
     306             :     {
     307           0 :         sal_Int32 itemZOrder(0);
     308           0 :         if( it->second->getPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier()
     309           0 :             .GetName( PROP_Z_ORDER )) >>= itemZOrder )
     310           0 :             return itemZOrder; // before the item
     311             :     }
     312             :     SAL_WARN( "writerfilter", "findZOrder() didn't find item z-order" );
     313           0 :     return 0; // this should not(?) happen
     314             : }
     315             : 
     316           0 : } }
     317             : 
     318             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10