LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - GraphicImport.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 498 656 75.9 %
Date: 2015-06-13 12:38:46 Functions: 27 51 52.9 %
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             : 
      20             : #include <string.h>
      21             : 
      22             : #include <com/sun/star/awt/Size.hpp>
      23             : #include <com/sun/star/container/XNamed.hpp>
      24             : #include <com/sun/star/drawing/ColorMode.hpp>
      25             : #include <com/sun/star/drawing/PointSequenceSequence.hpp>
      26             : #include <com/sun/star/drawing/XShape.hpp>
      27             : #include <com/sun/star/drawing/LineStyle.hpp>
      28             : #include <com/sun/star/graphic/XGraphic.hpp>
      29             : #include <com/sun/star/graphic/GraphicProvider.hpp>
      30             : #include <com/sun/star/graphic/XGraphicProvider.hpp>
      31             : #include <com/sun/star/io/XInputStream.hpp>
      32             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      33             : #include <com/sun/star/lang/XServiceInfo.hpp>
      34             : #include <com/sun/star/table/BorderLine2.hpp>
      35             : #include <com/sun/star/text/GraphicCrop.hpp>
      36             : #include <com/sun/star/text/HoriOrientation.hpp>
      37             : #include <com/sun/star/text/RelOrientation.hpp>
      38             : #include <com/sun/star/text/TextContentAnchorType.hpp>
      39             : #include <com/sun/star/text/VertOrientation.hpp>
      40             : #include <com/sun/star/text/WrapTextMode.hpp>
      41             : #include <com/sun/star/text/XTextContent.hpp>
      42             : #include <com/sun/star/uno/XComponentContext.hpp>
      43             : #include <com/sun/star/table/ShadowFormat.hpp>
      44             : 
      45             : #include <svx/svdobj.hxx>
      46             : #include <svx/unoapi.hxx>
      47             : #include <cppuhelper/implbase.hxx>
      48             : #include <rtl/ustrbuf.hxx>
      49             : #include <rtl/math.hxx>
      50             : #include <comphelper/string.hxx>
      51             : #include <comphelper/sequenceashashmap.hxx>
      52             : #include <comphelper/sequence.hxx>
      53             : 
      54             : #include <oox/drawingml/drawingmltypes.hxx>
      55             : 
      56             : #include <DomainMapper.hxx>
      57             : #include <dmapper/GraphicZOrderHelper.hxx>
      58             : #include <ooxml/resourceids.hxx>
      59             : 
      60             : #include "ConversionHelper.hxx"
      61             : #include "GraphicHelpers.hxx"
      62             : #include "GraphicImport.hxx"
      63             : #include "PropertyMap.hxx"
      64             : #include "WrapPolygonHandler.hxx"
      65             : #include "util.hxx"
      66             : 
      67             : namespace writerfilter {
      68             : 
      69             : namespace dmapper
      70             : {
      71             : using namespace css;
      72             : 
      73             : class XInputStreamHelper : public cppu::WeakImplHelper<io::XInputStream>
      74             : {
      75             :     const sal_uInt8* m_pBuffer;
      76             :     const sal_Int32  m_nLength;
      77             :     sal_Int32        m_nPosition;
      78             :     bool             m_bBmp;
      79             : 
      80             :     const sal_uInt8* m_pBMPHeader; //default BMP-header
      81             :     sal_Int32        m_nHeaderLength;
      82             : public:
      83             :     XInputStreamHelper(const sal_uInt8* buf, size_t len, bool bBmp);
      84             :     virtual ~XInputStreamHelper();
      85             : 
      86             :     virtual ::sal_Int32 SAL_CALL readBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead ) throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
      87             :     virtual ::sal_Int32 SAL_CALL readSomeBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead ) throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
      88             :     virtual void SAL_CALL skipBytes( ::sal_Int32 nBytesToSkip ) throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
      89             :     virtual ::sal_Int32 SAL_CALL available(  ) throw (io::NotConnectedException, io::IOException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
      90             :     virtual void SAL_CALL closeInput(  ) throw (io::NotConnectedException, io::IOException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
      91             : };
      92             : 
      93           0 : XInputStreamHelper::XInputStreamHelper(const sal_uInt8* buf, size_t len, bool bBmp) :
      94             :         m_pBuffer( buf ),
      95             :         m_nLength( len ),
      96             :         m_nPosition( 0 ),
      97           0 :         m_bBmp( bBmp )
      98             : {
      99             :     static const sal_uInt8 aHeader[] =
     100             :         {0x42, 0x4d, 0xe6, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
     101           0 :     m_pBMPHeader = aHeader;
     102           0 :     m_nHeaderLength = m_bBmp ? sizeof( aHeader ) / sizeof(sal_uInt8) : 0;
     103           0 : }
     104             : 
     105             : 
     106           0 : XInputStreamHelper::~XInputStreamHelper()
     107             : {
     108           0 : }
     109             : 
     110           0 : sal_Int32 XInputStreamHelper::readBytes( uno::Sequence<sal_Int8>& aData, sal_Int32 nBytesToRead )
     111             :     throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException, std::exception)
     112             : {
     113           0 :     return readSomeBytes( aData, nBytesToRead );
     114             : }
     115             : 
     116           0 : sal_Int32 XInputStreamHelper::readSomeBytes( uno::Sequence<sal_Int8>& aData, sal_Int32 nMaxBytesToRead )
     117             :         throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException, std::exception)
     118             : {
     119           0 :     sal_Int32 nRet = 0;
     120           0 :     if( nMaxBytesToRead > 0 )
     121             :     {
     122           0 :         if( nMaxBytesToRead > (m_nLength + m_nHeaderLength) - m_nPosition )
     123           0 :             nRet = (m_nLength + m_nHeaderLength) - m_nPosition;
     124             :         else
     125           0 :             nRet = nMaxBytesToRead;
     126           0 :         aData.realloc( nRet );
     127           0 :         sal_Int8* pData = aData.getArray();
     128           0 :         sal_Int32 nHeaderRead = 0;
     129           0 :         if( m_nPosition < m_nHeaderLength)
     130             :         {
     131             :             //copy header content first
     132           0 :             nHeaderRead = m_nHeaderLength - m_nPosition;
     133           0 :             memcpy( pData, m_pBMPHeader + (m_nPosition ), nHeaderRead );
     134           0 :             nRet -= nHeaderRead;
     135           0 :             m_nPosition += nHeaderRead;
     136             :         }
     137           0 :         if( nRet )
     138             :         {
     139           0 :             memcpy( pData + nHeaderRead, m_pBuffer + (m_nPosition - m_nHeaderLength), nRet );
     140           0 :             m_nPosition += nRet;
     141             :         }
     142             :     }
     143           0 :     return nRet;
     144             : }
     145             : 
     146             : 
     147           0 : void XInputStreamHelper::skipBytes( sal_Int32 nBytesToSkip ) throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException, std::exception)
     148             : {
     149           0 :     if( nBytesToSkip < 0 || m_nPosition + nBytesToSkip > (m_nLength + m_nHeaderLength))
     150           0 :         throw io::BufferSizeExceededException();
     151           0 :     m_nPosition += nBytesToSkip;
     152           0 : }
     153             : 
     154             : 
     155           0 : sal_Int32 XInputStreamHelper::available(  ) throw (io::NotConnectedException, io::IOException, uno::RuntimeException, std::exception)
     156             : {
     157           0 :     return ( m_nLength + m_nHeaderLength ) - m_nPosition;
     158             : }
     159             : 
     160             : 
     161           0 : void XInputStreamHelper::closeInput(  ) throw (io::NotConnectedException, io::IOException, uno::RuntimeException, std::exception)
     162             : {
     163           0 : }
     164             : 
     165             : 
     166             : struct GraphicBorderLine
     167             : {
     168             :     sal_Int32   nLineWidth;
     169             :     sal_Int32   nLineColor;
     170             :     sal_Int32   nLineDistance;
     171             :     bool        bHasShadow;
     172             : 
     173        5492 :     GraphicBorderLine() :
     174             :         nLineWidth(0)
     175             :         ,nLineColor(0)
     176             :         ,nLineDistance(0)
     177        5492 :         ,bHasShadow(false)
     178        5492 :         {}
     179             : 
     180         276 :     bool isEmpty()
     181             :     {
     182         276 :         return nLineWidth == 0 && nLineColor == 0 && !bHasShadow;
     183             :     }
     184             : 
     185             : };
     186             : 
     187        1373 : class GraphicImport_Impl
     188             : {
     189             : private:
     190             :     sal_Int32 nXSize;
     191             :     bool      bXSizeValid;
     192             :     sal_Int32 nYSize;
     193             :     bool      bYSizeValid;
     194             : 
     195             : public:
     196             :     GraphicImportType eGraphicImportType;
     197             :     DomainMapper&   rDomainMapper;
     198             : 
     199             :     sal_Int32 nHoriScaling;
     200             :     sal_Int32 nVertScaling;
     201             :     sal_Int32 nLeftPosition;
     202             :     sal_Int32 nTopPosition;
     203             :     sal_Int32 nRightPosition;
     204             :     sal_Int32 nBottomPosition;
     205             : 
     206             :     bool      bUseSimplePos;
     207             :     sal_Int32 zOrder;
     208             : 
     209             :     sal_Int16 nHoriOrient;
     210             :     sal_Int16 nHoriRelation;
     211             :     bool      bPageToggle;
     212             :     sal_Int16 nVertOrient;
     213             :     sal_Int16 nVertRelation;
     214             :     sal_Int32 nWrap;
     215             :     bool      bLayoutInCell;
     216             :     bool      bOpaque;
     217             :     bool      bContour;
     218             :     bool      bContourOutside;
     219             :     WrapPolygon::Pointer_t mpWrapPolygon;
     220             :     bool      bIgnoreWRK;
     221             : 
     222             :     sal_Int32 nLeftMargin;
     223             :     sal_Int32 nRightMargin;
     224             :     sal_Int32 nTopMargin;
     225             :     sal_Int32 nBottomMargin;
     226             : 
     227             :     bool bShadow;
     228             :     sal_Int32 nShadowXDistance;
     229             :     sal_Int32 nShadowYDistance;
     230             :     sal_Int32 nShadowColor;
     231             :     sal_Int32 nShadowTransparence;
     232             : 
     233             :     sal_Int32 nContrast;
     234             :     sal_Int32 nBrightness;
     235             :     double    fGamma;
     236             : 
     237             :     sal_Int32 nFillColor;
     238             : 
     239             :     drawing::ColorMode eColorMode;
     240             : 
     241             :     GraphicBorderLine   aBorders[4];
     242             :     sal_Int32           nCurrentBorderLine;
     243             : 
     244             :     sal_Int32       nDffType;
     245             :     bool            bIsGraphic;
     246             :     bool            bIsBitmap;
     247             :     bool            bIsTiff;
     248             :     sal_Int32       nBitsPerPixel;
     249             : 
     250             :     bool            bHoriFlip;
     251             :     bool            bVertFlip;
     252             : 
     253             :     bool            bSizeProtected;
     254             :     bool            bPositionProtected;
     255             : 
     256             :     sal_Int32       nShapeOptionType;
     257             : 
     258             :     OUString sName;
     259             :     OUString sAlternativeText;
     260             :     OUString title;
     261             :     std::pair<OUString, OUString>& m_rPositionOffsets;
     262             :     std::pair<OUString, OUString>& m_rAligns;
     263             :     std::queue<OUString>& m_rPositivePercentages;
     264             :     OUString sAnchorId;
     265             :     comphelper::SequenceAsHashMap m_aInteropGrabBag;
     266             :     boost::optional<sal_Int32> m_oEffectExtentLeft;
     267             :     boost::optional<sal_Int32> m_oEffectExtentTop;
     268             :     boost::optional<sal_Int32> m_oEffectExtentRight;
     269             :     boost::optional<sal_Int32> m_oEffectExtentBottom;
     270             : 
     271        1373 :     GraphicImport_Impl(GraphicImportType eImportType, DomainMapper& rDMapper, std::pair<OUString, OUString>& rPositionOffsets, std::pair<OUString, OUString>& rAligns, std::queue<OUString>& rPositivePercentages) :
     272             :         nXSize(0)
     273             :         ,bXSizeValid(false)
     274             :         ,nYSize(0)
     275             :         ,bYSizeValid(false)
     276             :         ,eGraphicImportType( eImportType )
     277             :         ,rDomainMapper( rDMapper )
     278             :         ,nHoriScaling(0)
     279             :         ,nVertScaling(0)
     280             :         ,nLeftPosition(0)
     281             :         ,nTopPosition(0)
     282             :         ,nRightPosition(0)
     283             :         ,nBottomPosition(0)
     284             :         ,bUseSimplePos(false)
     285             :         ,zOrder(-1)
     286             :         ,nHoriOrient(   text::HoriOrientation::NONE )
     287             :         ,nHoriRelation( text::RelOrientation::FRAME )
     288             :         ,bPageToggle( false )
     289             :         ,nVertOrient(  text::VertOrientation::NONE )
     290             :         ,nVertRelation( text::RelOrientation::FRAME )
     291             :         ,nWrap(0)
     292             :         ,bLayoutInCell(false)
     293             :         ,bOpaque( true )
     294             :         ,bContour(false)
     295             :         ,bContourOutside(true)
     296             :         ,bIgnoreWRK(true)
     297             :         ,nLeftMargin(319)
     298             :         ,nRightMargin(319)
     299             :         ,nTopMargin(0)
     300             :         ,nBottomMargin(0)
     301             :         ,bShadow(false)
     302             :         ,nShadowXDistance(0)
     303             :         ,nShadowYDistance(0)
     304             :         ,nShadowColor(0)
     305             :         ,nShadowTransparence(0)
     306             :         ,nContrast(0)
     307             :         ,nBrightness(0)
     308             :         ,fGamma( -1.0 )
     309             :         ,nFillColor( 0xffffffff )
     310             :         ,eColorMode( drawing::ColorMode_STANDARD )
     311             :         ,nCurrentBorderLine(BORDER_TOP)
     312             :         ,nDffType( 0 )
     313             :         ,bIsGraphic(false)
     314             :         ,bIsBitmap(false)
     315             :         ,bIsTiff(false)
     316             :         ,nBitsPerPixel(0)
     317             :         ,bHoriFlip(false)
     318             :         ,bVertFlip(false)
     319             :         ,bSizeProtected(false)
     320             :         ,bPositionProtected(false)
     321             :         ,nShapeOptionType(0)
     322             :         ,m_rPositionOffsets(rPositionOffsets)
     323             :         ,m_rAligns(rAligns)
     324        1373 :         ,m_rPositivePercentages(rPositivePercentages)
     325        1373 :     {}
     326             : 
     327        1373 :     void setXSize(sal_Int32 _nXSize)
     328             :     {
     329        1373 :         nXSize = _nXSize;
     330        1373 :         bXSizeValid = true;
     331        1373 :     }
     332             : 
     333        1645 :     sal_uInt32 getXSize() const
     334             :     {
     335        1645 :         return nXSize;
     336             :     }
     337             : 
     338        1093 :     bool isXSizeValid() const
     339             :     {
     340        1093 :         return bXSizeValid;
     341             :     }
     342             : 
     343        1373 :     void setYSize(sal_Int32 _nYSize)
     344             :     {
     345        1373 :         nYSize = _nYSize;
     346        1373 :         bYSizeValid = true;
     347        1373 :     }
     348             : 
     349        1645 :     sal_uInt32 getYSize() const
     350             :     {
     351        1645 :         return nYSize;
     352             :     }
     353             : 
     354        1093 :     bool isYSizeValis () const
     355             :     {
     356        1093 :         return bYSizeValid;
     357             :     }
     358             : 
     359        1232 :     void applyMargins(uno::Reference< beans::XPropertySet > xGraphicObjectProperties) const
     360             :     {
     361        1232 :         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     362        1232 :         xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_LEFT_MARGIN ), uno::makeAny(nLeftMargin));
     363        1232 :         xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_RIGHT_MARGIN ), uno::makeAny(nRightMargin));
     364        1232 :         xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_TOP_MARGIN ), uno::makeAny(nTopMargin));
     365        1232 :         xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_BOTTOM_MARGIN ), uno::makeAny(nBottomMargin));
     366        1232 :     }
     367             : 
     368         956 :     void applyPosition(uno::Reference< beans::XPropertySet > xGraphicObjectProperties) const
     369             :     {
     370         956 :         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     371         956 :         xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_ORIENT          ),
     372         956 :                 uno::makeAny(nHoriOrient));
     373         956 :         xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_VERT_ORIENT          ),
     374         956 :                 uno::makeAny(nVertOrient));
     375         956 :     }
     376             : 
     377         956 :     void applyRelativePosition(uno::Reference< beans::XPropertySet > xGraphicObjectProperties, bool bRelativeOnly = false) const
     378             :     {
     379         956 :         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     380         956 :         if (!bRelativeOnly)
     381          90 :             xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_ORIENT_POSITION),
     382          90 :                                                        uno::makeAny(nLeftPosition));
     383         956 :         xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_ORIENT_RELATION ),
     384         956 :                 uno::makeAny(nHoriRelation));
     385         956 :         xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_PAGE_TOGGLE ),
     386         956 :                 uno::makeAny(bPageToggle));
     387         956 :         if (!bRelativeOnly)
     388          90 :             xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_VERT_ORIENT_POSITION),
     389          90 :                                                        uno::makeAny(nTopPosition));
     390         956 :         xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_VERT_ORIENT_RELATION ),
     391         956 :                 uno::makeAny(nVertRelation));
     392         956 :     }
     393             : 
     394        1142 :     void applyZOrder(uno::Reference<beans::XPropertySet>& xGraphicObjectProperties) const
     395             :     {
     396        1142 :         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     397        1142 :         if (zOrder >= 0)
     398             :         {
     399         916 :             GraphicZOrderHelper* pZOrderHelper = rDomainMapper.graphicZOrderHelper();
     400         916 :             xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_Z_ORDER), uno::makeAny(pZOrderHelper->findZOrder(zOrder)));
     401         916 :             pZOrderHelper->addItem(xGraphicObjectProperties, zOrder);
     402             :         }
     403        1142 :     }
     404             : 
     405        1142 :     void applyName(uno::Reference<beans::XPropertySet>& xGraphicObjectProperties) const
     406             :     {
     407        1142 :         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     408             :         try
     409             :         {
     410        1142 :             if( !sName.isEmpty() )
     411             :             {
     412        1026 :                 uno::Reference< container::XNamed > xNamed( xGraphicObjectProperties, uno::UNO_QUERY_THROW );
     413        1026 :                 xNamed->setName( sName );
     414             :             }
     415        1142 :             xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_DESCRIPTION ),
     416        1142 :                 uno::makeAny( sAlternativeText ));
     417        1142 :             xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_TITLE ),
     418        1142 :                 uno::makeAny( title ));
     419             :         }
     420           0 :         catch( const uno::Exception& e )
     421             :         {
     422             :             SAL_WARN("writerfilter", "failed. Message :" << e.Message);
     423             :         }
     424        1142 :     }
     425             : 
     426             :     /// Getter for m_aInteropGrabBag, but also merges in the values from other members if they are set.
     427         866 :     comphelper::SequenceAsHashMap getInteropGrabBag()
     428             :     {
     429         866 :         comphelper::SequenceAsHashMap aEffectExtent;
     430         866 :         if (m_oEffectExtentLeft)
     431         866 :             aEffectExtent["l"] <<= *m_oEffectExtentLeft;
     432         866 :         if (m_oEffectExtentTop)
     433         866 :             aEffectExtent["t"] <<= *m_oEffectExtentTop;
     434         866 :         if (m_oEffectExtentRight)
     435         866 :             aEffectExtent["r"] <<= *m_oEffectExtentRight;
     436         866 :         if (m_oEffectExtentBottom)
     437         866 :             aEffectExtent["b"] <<= *m_oEffectExtentBottom;
     438         866 :         if (!aEffectExtent.empty())
     439         866 :             m_aInteropGrabBag["CT_EffectExtent"] <<= aEffectExtent.getAsConstPropertyValueList();
     440         866 :         return m_aInteropGrabBag;
     441             :     }
     442             : };
     443             : 
     444        1373 : GraphicImport::GraphicImport(uno::Reference<uno::XComponentContext> const& xComponentContext,
     445             :                              uno::Reference<lang::XMultiServiceFactory> const& xTextFactory,
     446             :                              DomainMapper& rDMapper,
     447             :                              GraphicImportType eImportType,
     448             :                              std::pair<OUString, OUString>& rPositionOffsets,
     449             :                              std::pair<OUString, OUString>& rAligns,
     450             :                              std::queue<OUString>& rPositivePercentages)
     451             : : LoggedProperties("GraphicImport")
     452             : , LoggedTable("GraphicImport")
     453             : , LoggedStream("GraphicImport")
     454        1373 : , m_pImpl(new GraphicImport_Impl(eImportType, rDMapper, rPositionOffsets, rAligns, rPositivePercentages))
     455             : , m_xComponentContext(xComponentContext)
     456        2746 : , m_xTextFactory(xTextFactory)
     457             : {
     458        1373 : }
     459             : 
     460        2746 : GraphicImport::~GraphicImport()
     461             : {
     462        2746 : }
     463             : 
     464         158 : void GraphicImport::handleWrapTextValue(sal_uInt32 nVal)
     465             : {
     466         158 :     switch (nVal)
     467             :     {
     468             :     case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_bothSides: // 90920;
     469         125 :         m_pImpl->nWrap = text::WrapTextMode_PARALLEL;
     470         125 :         break;
     471             :     case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_left: // 90921;
     472           0 :         m_pImpl->nWrap = text::WrapTextMode_LEFT;
     473           0 :         break;
     474             :     case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_right: // 90922;
     475           0 :         m_pImpl->nWrap = text::WrapTextMode_RIGHT;
     476           0 :         break;
     477             :     case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_largest: // 90923;
     478          33 :         m_pImpl->nWrap = text::WrapTextMode_DYNAMIC;
     479          33 :         break;
     480             :     default:;
     481             :     }
     482         158 : }
     483             : 
     484         684 : void GraphicImport::putPropertyToFrameGrabBag( const OUString& sPropertyName, const uno::Any& aPropertyValue )
     485             : {
     486         684 :     beans::PropertyValue pProperty;
     487         684 :     pProperty.Name = sPropertyName;
     488         684 :     pProperty.Value = aPropertyValue;
     489             : 
     490         684 :     if (!m_xShape.is())
     491           0 :         return;
     492             : 
     493        1368 :     uno::Reference< beans::XPropertySet > xSet(m_xShape, uno::UNO_QUERY_THROW);
     494         684 :     if (!xSet.is())
     495           0 :         return;
     496             : 
     497        1368 :     uno::Reference< beans::XPropertySetInfo > xSetInfo(xSet->getPropertySetInfo());
     498         684 :     if (!xSetInfo.is())
     499           0 :         return;
     500             : 
     501        1368 :     OUString aGrabBagPropName;
     502        1368 :     uno::Reference<lang::XServiceInfo> xServiceInfo(m_xShape, uno::UNO_QUERY_THROW);
     503         684 :     if (xServiceInfo->supportsService("com.sun.star.text.TextFrame"))
     504           0 :         aGrabBagPropName = "FrameInteropGrabBag";
     505             :     else
     506         684 :         aGrabBagPropName = "InteropGrabBag";
     507             : 
     508         684 :     if (xSetInfo->hasPropertyByName(aGrabBagPropName))
     509             :     {
     510             :         //Add pProperty to the end of the Sequence for aGrabBagPropName
     511         684 :         uno::Sequence<beans::PropertyValue> aTmp;
     512         684 :         xSet->getPropertyValue(aGrabBagPropName) >>= aTmp;
     513        1368 :         std::vector<beans::PropertyValue> aGrabBag(comphelper::sequenceToContainer<std::vector<beans::PropertyValue> >(aTmp));
     514         684 :         aGrabBag.push_back(pProperty);
     515             : 
     516        1368 :         xSet->setPropertyValue(aGrabBagPropName, uno::makeAny(comphelper::containerToSequence(aGrabBag)));
     517         684 :     }
     518             : }
     519             : 
     520       26156 : void GraphicImport::lcl_attribute(Id nName, Value& rValue)
     521             : {
     522       26156 :     sal_Int32 nIntValue = rValue.getInt();
     523       26156 :     switch( nName )
     524             :     {
     525             :         case NS_ooxml::LN_blip: //the binary graphic data in a shape
     526             :             {
     527           0 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rValue.getProperties();
     528           0 :             if( pProperties.get())
     529             :             {
     530           0 :                 pProperties->resolve(*this);
     531           0 :             }
     532             :         }
     533           0 :         break;
     534             :         case NS_ooxml::LN_payload :
     535             :         {
     536           0 :             writerfilter::Reference<BinaryObj>::Pointer_t pPictureData = rValue.getBinary();
     537           0 :             if( pPictureData.get())
     538           0 :                 pPictureData->resolve(*this);
     539             :         }
     540           0 :         break;
     541             : 
     542             :         //border properties
     543             :         case NS_ooxml::LN_CT_Border_sz:
     544           0 :             m_pImpl->aBorders[m_pImpl->nCurrentBorderLine].nLineWidth = nIntValue;
     545           0 :         break;
     546             :         case NS_ooxml::LN_CT_Border_val:
     547             :             //graphic borders don't support different line types
     548           0 :         break;
     549             :         case NS_ooxml::LN_CT_Border_space:
     550           0 :             m_pImpl->aBorders[m_pImpl->nCurrentBorderLine].nLineDistance = nIntValue;
     551           0 :         break;
     552             :         case NS_ooxml::LN_CT_Border_shadow:
     553           0 :             m_pImpl->aBorders[m_pImpl->nCurrentBorderLine].bHasShadow = nIntValue != 0;
     554           0 :         break;
     555             :         case NS_ooxml::LN_CT_Border_frame:
     556           0 :             break;
     557             :         case NS_ooxml::LN_CT_PositiveSize2D_cx:
     558             :         case NS_ooxml::LN_CT_PositiveSize2D_cy:
     559             :         {
     560        2746 :             sal_Int32 nDim = oox::drawingml::convertEmuToHmm(nIntValue);
     561        2746 :             if( nName == NS_ooxml::LN_CT_PositiveSize2D_cx )
     562        1373 :                 m_pImpl->setXSize(nDim);
     563             :             else
     564        1373 :                 m_pImpl->setYSize(nDim);
     565             :         }
     566        2746 :         break;
     567             :         case NS_ooxml::LN_CT_EffectExtent_l:
     568        1338 :             m_pImpl->m_oEffectExtentLeft = nIntValue;
     569        1338 :             m_pImpl->nLeftMargin += oox::drawingml::convertEmuToHmm(nIntValue);
     570        1338 :             break;
     571             :         case NS_ooxml::LN_CT_EffectExtent_t:
     572        1338 :             m_pImpl->m_oEffectExtentTop = nIntValue;
     573        1338 :             m_pImpl->nTopMargin += oox::drawingml::convertEmuToHmm(nIntValue);
     574        1338 :             break;
     575             :         case NS_ooxml::LN_CT_EffectExtent_r:
     576        1338 :             m_pImpl->m_oEffectExtentRight = nIntValue;
     577        1338 :             m_pImpl->nRightMargin += oox::drawingml::convertEmuToHmm(nIntValue);
     578        1338 :             break;
     579             :         case NS_ooxml::LN_CT_EffectExtent_b:
     580        1338 :             m_pImpl->m_oEffectExtentBottom = nIntValue;
     581        1338 :             m_pImpl->nBottomMargin += oox::drawingml::convertEmuToHmm(nIntValue);
     582        1338 :             break;
     583             :         case NS_ooxml::LN_CT_NonVisualDrawingProps_id:// 90650;
     584             :             //id of the object - ignored
     585           0 :         break;
     586             :         case NS_ooxml::LN_CT_NonVisualDrawingProps_name:// 90651;
     587             :             //name of the object
     588        1338 :             m_pImpl->sName = rValue.getString();
     589        1338 :         break;
     590             :         case NS_ooxml::LN_CT_NonVisualDrawingProps_descr:// 90652;
     591             :             //alternative text
     592         152 :             m_pImpl->sAlternativeText = rValue.getString();
     593         152 :         break;
     594             :         case NS_ooxml::LN_CT_NonVisualDrawingProps_title:
     595             :             //alternative text
     596          83 :             m_pImpl->title = rValue.getString();
     597          83 :         break;
     598             :         case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noChangeAspect://90644;
     599             :             //disallow aspect ratio change - ignored
     600         229 :         break;
     601             :         case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noMove:// 90645;
     602           0 :             m_pImpl->bPositionProtected = true;
     603           0 :         break;
     604             :         case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noResize: // 90646;
     605           0 :             m_pImpl->bSizeProtected = true;
     606           0 :         break;
     607             :         case NS_ooxml::LN_CT_Anchor_distT: // 90983;
     608             :         case NS_ooxml::LN_CT_Anchor_distB: // 90984;
     609             :         case NS_ooxml::LN_CT_Anchor_distL: // 90985;
     610             :         case NS_ooxml::LN_CT_Anchor_distR: // 90986;
     611             :         {
     612        3748 :             m_pImpl->nShapeOptionType = nName;
     613        3748 :             ProcessShapeOptions(rValue);
     614             :         }
     615        3748 :         break;
     616             :         case NS_ooxml::LN_CT_Anchor_simplePos_attr: // 90987;
     617         936 :             m_pImpl->bUseSimplePos = nIntValue > 0;
     618         936 :         break;
     619             :         case NS_ooxml::LN_CT_Anchor_relativeHeight: // 90988;
     620         916 :             m_pImpl->zOrder = nIntValue;
     621         916 :         break;
     622             :         case NS_ooxml::LN_CT_Anchor_behindDoc: // 90989; - in background
     623         957 :             if( nIntValue > 0 )
     624         100 :                 m_pImpl->bOpaque = false;
     625         957 :         break;
     626             :         case NS_ooxml::LN_CT_Anchor_locked: // 90990; - ignored
     627         936 :         break;
     628             :         case NS_ooxml::LN_CT_Anchor_layoutInCell: // 90991; - ignored
     629         936 :             m_pImpl->bLayoutInCell = nIntValue != 0;
     630         936 :         break;
     631             :         case NS_ooxml::LN_CT_Anchor_hidden: // 90992; - ignored
     632           0 :         break;
     633             :         case NS_ooxml::LN_CT_Anchor_allowOverlap: // 90993;
     634             :             //enable overlapping - ignored
     635         936 :         break;
     636             :         case NS_ooxml::LN_CT_Anchor_wp14_anchorId:
     637             :         case NS_ooxml::LN_CT_Inline_wp14_anchorId:
     638             :         {
     639         740 :             OUStringBuffer aBuffer = OUString::number(nIntValue, 16);
     640        1480 :             OUStringBuffer aString;
     641         740 :             comphelper::string::padToLength(aString, 8 - aBuffer.getLength(), '0');
     642         740 :             aString.append(aBuffer.getStr());
     643        1480 :             m_pImpl->sAnchorId = aString.makeStringAndClear().toAsciiUpperCase();
     644             :         }
     645         740 :         break;
     646             :         case NS_ooxml::LN_CT_Point2D_x: // 90405;
     647         936 :             m_pImpl->nLeftPosition = ConversionHelper::convertTwipToMM100(nIntValue);
     648         936 :             m_pImpl->nHoriRelation = text::RelOrientation::PAGE_FRAME;
     649         936 :             m_pImpl->nHoriOrient = text::HoriOrientation::NONE;
     650         936 :         break;
     651             :         case NS_ooxml::LN_CT_Point2D_y: // 90406;
     652         936 :             m_pImpl->nTopPosition = ConversionHelper::convertTwipToMM100(nIntValue);
     653         936 :             m_pImpl->nVertRelation = text::RelOrientation::PAGE_FRAME;
     654         936 :             m_pImpl->nVertOrient = text::VertOrientation::NONE;
     655         936 :         break;
     656             :         case NS_ooxml::LN_CT_WrapTight_wrapText: // 90934;
     657          12 :             m_pImpl->bContour = true;
     658          12 :             m_pImpl->bContourOutside = true;
     659             : 
     660          12 :             handleWrapTextValue(rValue.getInt());
     661             : 
     662          12 :             break;
     663             :         case NS_ooxml::LN_CT_WrapThrough_wrapText:
     664          21 :             m_pImpl->bContour = true;
     665          21 :             m_pImpl->bContourOutside = false;
     666             : 
     667          21 :             handleWrapTextValue(rValue.getInt());
     668             : 
     669          21 :             break;
     670             :         case NS_ooxml::LN_CT_WrapSquare_wrapText: //90928;
     671         125 :             handleWrapTextValue(rValue.getInt());
     672         125 :             break;
     673             :         case NS_ooxml::LN_shape:
     674             :             {
     675        1371 :                 uno::Reference< drawing::XShape> xShape;
     676        1371 :                 rValue.getAny( ) >>= xShape;
     677             : 
     678        1371 :                 if ( xShape.is( ) )
     679             :                 {
     680             :                     // Is it a graphic image
     681        1369 :                     bool bUseShape = true;
     682             :                     try
     683             :                     {
     684             :                         uno::Reference< beans::XPropertySet > xShapeProps
     685        1369 :                             ( xShape, uno::UNO_QUERY_THROW );
     686             : 
     687        2738 :                         OUString sUrl;
     688        2329 :                         xShapeProps->getPropertyValue("GraphicURL") >>= sUrl;
     689             : 
     690         409 :                         sal_Int32 nRotation = 0;
     691         409 :                         xShapeProps->getPropertyValue("RotateAngle") >>= nRotation;
     692             : 
     693         818 :                         css::beans::PropertyValues aGrabBag;
     694         409 :                         bool bContainsEffects = false;
     695         409 :                         xShapeProps->getPropertyValue("InteropGrabBag") >>= aGrabBag;
     696        1032 :                         for( sal_Int32 i = 0; i < aGrabBag.getLength(); ++i )
     697             :                         {
     698             :                             // if the shape contains effects in the grab bag, we should not transform it
     699             :                             // in a XTextContent so those effects can be preserved
     700        1222 :                             if( aGrabBag[i].Name == "EffectProperties" || aGrabBag[i].Name == "3DEffectProperties" ||
     701         599 :                                     aGrabBag[i].Name == "ArtisticEffectProperties" )
     702          43 :                                 bContainsEffects = true;
     703             :                         }
     704             : 
     705         818 :                         beans::PropertyValues aMediaProperties( 1 );
     706         409 :                         aMediaProperties[0].Name = "URL";
     707         409 :                         aMediaProperties[0].Value <<= sUrl;
     708             : 
     709         409 :                         xShapeProps->getPropertyValue("Shadow") >>= m_pImpl->bShadow;
     710         409 :                         if (m_pImpl->bShadow)
     711             :                         {
     712          12 :                             xShapeProps->getPropertyValue("ShadowXDistance") >>= m_pImpl->nShadowXDistance;
     713          12 :                             xShapeProps->getPropertyValue("ShadowYDistance") >>= m_pImpl->nShadowYDistance;
     714          12 :                             xShapeProps->getPropertyValue("ShadowColor") >>= m_pImpl->nShadowColor;
     715          12 :                             xShapeProps->getPropertyValue("ShadowTransparence") >>= m_pImpl->nShadowTransparence;
     716             :                         }
     717             : 
     718         409 :                         xShapeProps->getPropertyValue("GraphicColorMode") >>= m_pImpl->eColorMode;
     719         409 :                         xShapeProps->getPropertyValue("AdjustLuminance") >>= m_pImpl->nBrightness;
     720         409 :                         xShapeProps->getPropertyValue("AdjustContrast") >>= m_pImpl->nContrast;
     721             : 
     722             :                         // fdo#70457: transform XShape into a SwXTextGraphicObject only if there's no rotation
     723         409 :                         if ( nRotation == 0 && !bContainsEffects )
     724         362 :                             m_xGraphicObject = createGraphicObject( aMediaProperties, xShapeProps );
     725             : 
     726         409 :                         bUseShape = !m_xGraphicObject.is( );
     727             : 
     728         409 :                         if ( !bUseShape )
     729             :                         {
     730             :                             // Define the object size
     731             :                             uno::Reference< beans::XPropertySet > xGraphProps( m_xGraphicObject,
     732         276 :                                     uno::UNO_QUERY );
     733         276 :                             awt::Size aSize = xShape->getSize( );
     734         276 :                             xGraphProps->setPropertyValue("Height",
     735         276 :                                    uno::makeAny( aSize.Height ) );
     736         276 :                             xGraphProps->setPropertyValue("Width",
     737         276 :                                    uno::makeAny( aSize.Width ) );
     738             : 
     739         276 :                             text::GraphicCrop aGraphicCrop( 0, 0, 0, 0 );
     740         552 :                             uno::Reference< beans::XPropertySet > xSourceGraphProps( xShape, uno::UNO_QUERY );
     741         552 :                             uno::Any aAny = xSourceGraphProps->getPropertyValue("GraphicCrop");
     742         276 :                             if(aAny >>= aGraphicCrop) {
     743         276 :                                 xGraphProps->setPropertyValue("GraphicCrop",
     744         276 :                                     uno::makeAny( aGraphicCrop ) );
     745             :                             }
     746             : 
     747             :                             // We need to drop the shape here somehow
     748         552 :                             uno::Reference< lang::XComponent > xShapeComponent( xShape, uno::UNO_QUERY );
     749         552 :                             xShapeComponent->dispose( );
     750        1369 :                         }
     751             :                     }
     752         960 :                     catch( const beans::UnknownPropertyException & )
     753             :                     {
     754             :                         // It isn't a graphic image
     755             :                     }
     756             : 
     757        1369 :                     if ( bUseShape )
     758        1093 :                         m_xShape = xShape;
     759             : 
     760             : 
     761        1369 :                     if ( m_xShape.is( ) )
     762             :                     {
     763             :                         uno::Reference< beans::XPropertySet > xShapeProps
     764        1093 :                             (m_xShape, uno::UNO_QUERY_THROW);
     765             : 
     766             : 
     767             :                         PropertyNameSupplier& rPropNameSupplier =
     768        1093 :                             PropertyNameSupplier::GetPropertyNameSupplier();
     769        1093 :                         xShapeProps->setPropertyValue
     770             :                             (rPropNameSupplier.GetName(PROP_ANCHOR_TYPE),
     771             :                              uno::makeAny
     772        1093 :                              (text::TextContentAnchorType_AS_CHARACTER));
     773             : 
     774             :                         // In Word, if a shape is anchored inline, that
     775             :                         // excludes being in the background.
     776        1093 :                         xShapeProps->setPropertyValue("Opaque", uno::makeAny(true));
     777             : 
     778        2186 :                         uno::Reference<lang::XServiceInfo> xServiceInfo(m_xShape, uno::UNO_QUERY_THROW);
     779             : 
     780             :                         // TextFrames can't be rotated. But for anything else,
     781             :                         // make sure that setting size doesn't affect rotation,
     782             :                         // that would not match Word's definition of rotation.
     783        1093 :                         bool bKeepRotation = false;
     784        1093 :                         if (!xServiceInfo->supportsService("com.sun.star.text.TextFrame"))
     785             :                         {
     786        1093 :                             bKeepRotation = true;
     787        1093 :                             xShapeProps->setPropertyValue
     788             :                                 (rPropNameSupplier.GetName(PROP_TEXT_RANGE),
     789             :                                  uno::makeAny
     790        1093 :                                  (m_pImpl->rDomainMapper.GetCurrentTextRange()));
     791             :                         }
     792             : 
     793        1093 :                         awt::Size aSize(m_xShape->getSize());
     794             : 
     795        1093 :                         if (m_pImpl->isXSizeValid())
     796        1093 :                             aSize.Width = m_pImpl->getXSize();
     797        1093 :                         if (m_pImpl->isYSizeValis())
     798        1093 :                             aSize.Height = m_pImpl->getYSize();
     799             : 
     800        1093 :                         sal_Int32 nRotation = 0;
     801        1093 :                         if (bKeepRotation)
     802             :                         {
     803             :                             // Use internal API, getPropertyValue(RotateAngle)
     804             :                             // would use GetObjectRotation(), which is not what
     805             :                             // we want.
     806        1093 :                             if (SdrObject* pShape = GetSdrObjectFromXShape(m_xShape))
     807        1007 :                                 nRotation = pShape->GetRotateAngle();
     808             :                         }
     809        1093 :                         m_xShape->setSize(aSize);
     810        1093 :                         if (bKeepRotation)
     811        1093 :                             xShapeProps->setPropertyValue("RotateAngle", uno::makeAny(nRotation));
     812             : 
     813        1093 :                         m_pImpl->bIsGraphic = true;
     814             : 
     815        1093 :                         if (!m_pImpl->sAnchorId.isEmpty())
     816             :                         {
     817         684 :                             putPropertyToFrameGrabBag("AnchorId", uno::makeAny(m_pImpl->sAnchorId));
     818        1093 :                         }
     819             :                     }
     820             : 
     821        1369 :                     if (bUseShape && m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR)
     822             :                     {
     823             :                         // If we are here, this is a drawingML shape. For those, only dmapper (and not oox) knows the anchoring infos (just like for Writer pictures).
     824             :                         // But they aren't Writer pictures, either (which are already handled above).
     825         866 :                         uno::Reference< beans::XPropertySet > xShapeProps(m_xShape, uno::UNO_QUERY_THROW);
     826             :                         // This needs to be AT_PARAGRAPH and not AT_CHARACTER, otherwise shape will move when the user inserts a new paragraph.
     827         866 :                         xShapeProps->setPropertyValue("AnchorType", uno::makeAny(text::TextContentAnchorType_AT_PARAGRAPH));
     828             : 
     829             :                         //only the position orientation is handled in applyPosition()
     830         866 :                         m_pImpl->applyPosition(xShapeProps);
     831             : 
     832        1732 :                         uno::Reference<lang::XServiceInfo> xServiceInfo(m_xShape, uno::UNO_QUERY_THROW);
     833        3326 :                         if (xServiceInfo->supportsService("com.sun.star.drawing.GroupShape") ||
     834        2460 :                                 xServiceInfo->supportsService("com.sun.star.drawing.GraphicObjectShape"))
     835             :                         {
     836             :                             // You would expect that position and rotation are
     837             :                             // independent, but they are not. Till we are not
     838             :                             // there yet to handle all scaling, translation and
     839             :                             // rotation with a single transformation matrix,
     840             :                             // make sure there is no rotation set when we set
     841             :                             // the position.
     842          88 :                             sal_Int32 nRotation = 0;
     843          88 :                             xShapeProps->getPropertyValue("RotateAngle") >>= nRotation;
     844          88 :                             if (nRotation)
     845           9 :                                 xShapeProps->setPropertyValue("RotateAngle", uno::makeAny(sal_Int32(0)));
     846             : 
     847             :                             // Position of the groupshape should be set after children have been added.
     848             :                             // fdo#80555: also set position for graphic shapes here
     849          88 :                             m_xShape->setPosition(awt::Point(m_pImpl->nLeftPosition, m_pImpl->nTopPosition));
     850             : 
     851          88 :                             if (nRotation)
     852           9 :                                 xShapeProps->setPropertyValue("RotateAngle", uno::makeAny(nRotation));
     853             :                         }
     854         866 :                         m_pImpl->applyRelativePosition(xShapeProps, /*bRelativeOnly=*/true);
     855             : 
     856         866 :                         xShapeProps->setPropertyValue("SurroundContour", uno::makeAny(m_pImpl->bContour));
     857         866 :                         m_pImpl->applyMargins(xShapeProps);
     858         866 :                         bool bOpaque = m_pImpl->bOpaque && !m_pImpl->rDomainMapper.IsInHeaderFooter();
     859         866 :                         xShapeProps->setPropertyValue("Opaque", uno::makeAny(bOpaque));
     860         866 :                         xShapeProps->setPropertyValue("Surround", uno::makeAny(m_pImpl->nWrap));
     861         866 :                         m_pImpl->applyZOrder(xShapeProps);
     862         866 :                         m_pImpl->applyName(xShapeProps);
     863             : 
     864             :                         // Get the grab-bag set by oox, merge with our one and then put it back.
     865        1732 :                         comphelper::SequenceAsHashMap aInteropGrabBag(xShapeProps->getPropertyValue("InteropGrabBag"));
     866         866 :                         aInteropGrabBag.update(m_pImpl->getInteropGrabBag());
     867        1732 :                         xShapeProps->setPropertyValue("InteropGrabBag", uno::makeAny(aInteropGrabBag.getAsConstPropertyValueList()));
     868             :                     }
     869        1371 :                 }
     870             :             }
     871        1371 :         break;
     872             :         case NS_ooxml::LN_CT_Inline_distT:
     873         416 :             m_pImpl->nTopMargin = oox::drawingml::convertEmuToHmm(nIntValue);
     874         416 :         break;
     875             :         case NS_ooxml::LN_CT_Inline_distB:
     876         416 :             m_pImpl->nBottomMargin = oox::drawingml::convertEmuToHmm(nIntValue);
     877         416 :         break;
     878             :         case NS_ooxml::LN_CT_Inline_distL:
     879         416 :             m_pImpl->nLeftMargin = oox::drawingml::convertEmuToHmm(nIntValue);
     880         416 :         break;
     881             :         case NS_ooxml::LN_CT_Inline_distR:
     882         416 :             m_pImpl->nRightMargin = oox::drawingml::convertEmuToHmm(nIntValue);
     883         416 :         break;
     884             :         case NS_ooxml::LN_CT_GraphicalObjectData_uri:
     885           0 :             rValue.getString();
     886             :             //TODO: does it need to be handled?
     887           0 :         break;
     888             :         case NS_ooxml::LN_CT_SizeRelH_relativeFrom:
     889             :             {
     890         422 :                 switch (nIntValue)
     891             :                 {
     892             :                 case NS_ooxml::LN_ST_SizeRelFromH_margin:
     893         201 :                     if (m_xShape.is())
     894             :                     {
     895         200 :                         uno::Reference<beans::XPropertySet> xPropertySet(m_xShape, uno::UNO_QUERY);
     896         200 :                         xPropertySet->setPropertyValue("RelativeWidthRelation", uno::makeAny(text::RelOrientation::FRAME));
     897             :                     }
     898         201 :                     break;
     899             :                 case NS_ooxml::LN_ST_SizeRelFromH_page:
     900         221 :                     if (m_xShape.is())
     901             :                     {
     902         197 :                         uno::Reference<beans::XPropertySet> xPropertySet(m_xShape, uno::UNO_QUERY);
     903         197 :                         xPropertySet->setPropertyValue("RelativeWidthRelation", uno::makeAny(text::RelOrientation::PAGE_FRAME));
     904             :                     }
     905         221 :                     break;
     906             :                 default:
     907             :                     SAL_WARN("writerfilter", "GraphicImport::lcl_attribute: unhandled NS_ooxml::LN_CT_SizeRelH_relativeFrom value: " << nIntValue);
     908           0 :                     break;
     909             :                 }
     910             :             }
     911         422 :             break;
     912             :         case NS_ooxml::LN_CT_SizeRelV_relativeFrom:
     913             :             {
     914         420 :                 switch (nIntValue)
     915             :                 {
     916             :                 case NS_ooxml::LN_ST_SizeRelFromV_margin:
     917         192 :                     if (m_xShape.is())
     918             :                     {
     919         192 :                         uno::Reference<beans::XPropertySet> xPropertySet(m_xShape, uno::UNO_QUERY);
     920         192 :                         xPropertySet->setPropertyValue("RelativeHeightRelation", uno::makeAny(text::RelOrientation::FRAME));
     921             :                     }
     922         192 :                     break;
     923             :                 case NS_ooxml::LN_ST_SizeRelFromV_page:
     924         228 :                     if (m_xShape.is())
     925             :                     {
     926         204 :                         uno::Reference<beans::XPropertySet> xPropertySet(m_xShape, uno::UNO_QUERY);
     927         204 :                         xPropertySet->setPropertyValue("RelativeHeightRelation", uno::makeAny(text::RelOrientation::PAGE_FRAME));
     928             :                     }
     929         228 :                     break;
     930             :                 default:
     931             :                     SAL_WARN("writerfilter", "GraphicImport::lcl_attribute: unhandled NS_ooxml::LN_CT_SizeRelV_relativeFrom value: " << nIntValue);
     932           0 :                     break;
     933             :                 }
     934             :             }
     935         420 :             break;
     936             :         default:
     937             : #ifdef DEBUG_WRITERFILTER
     938             :             TagLogger::getInstance().element("unhandled");
     939             : #endif
     940         244 :             break;
     941             :     }
     942       26156 : }
     943             : 
     944        1373 : uno::Reference<text::XTextContent> GraphicImport::GetGraphicObject()
     945             : {
     946        1373 :     uno::Reference<text::XTextContent> xResult;
     947             : 
     948        1373 :     if (m_xGraphicObject.is())
     949         276 :         xResult = m_xGraphicObject;
     950        1097 :     else if (m_xShape.is())
     951             :     {
     952        1093 :         xResult.set(m_xShape, uno::UNO_QUERY_THROW);
     953             :     }
     954             : 
     955        1373 :     return xResult;
     956             : }
     957             : 
     958             : 
     959        3748 : void GraphicImport::ProcessShapeOptions(Value& rValue)
     960             : {
     961        3748 :     sal_Int32 nIntValue = rValue.getInt();
     962        3748 :     switch( m_pImpl->nShapeOptionType )
     963             :     {
     964             :         case NS_ooxml::LN_CT_Anchor_distL:
     965             :             //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustLRWrapForWordMargins()
     966         937 :             m_pImpl->nLeftMargin = nIntValue / 360;
     967         937 :         break;
     968             :         case NS_ooxml::LN_CT_Anchor_distT:
     969             :             //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustULWrapForWordMargins()
     970         937 :             m_pImpl->nTopMargin = nIntValue / 360;
     971         937 :         break;
     972             :         case NS_ooxml::LN_CT_Anchor_distR:
     973             :             //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustLRWrapForWordMargins()
     974         937 :             m_pImpl->nRightMargin = nIntValue / 360;
     975         937 :         break;
     976             :         case NS_ooxml::LN_CT_Anchor_distB:
     977             :             //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustULWrapForWordMargins()
     978         937 :             m_pImpl->nBottomMargin = nIntValue / 360;
     979         937 :         break;
     980             :         default:
     981             :             OSL_FAIL( "shape option unsupported?");
     982             :     }
     983        3748 : }
     984             : 
     985             : 
     986       15204 : void GraphicImport::lcl_sprm(Sprm& rSprm)
     987             : {
     988       15204 :     sal_uInt32 nSprmId = rSprm.getId();
     989       15204 :     Value::Pointer_t pValue = rSprm.getValue();
     990             : 
     991       15204 :     switch(nSprmId)
     992             :     {
     993             :         case NS_ooxml::LN_CT_Inline_extent: // 90911;
     994             :         case NS_ooxml::LN_CT_Inline_effectExtent: // 90912;
     995             :         case NS_ooxml::LN_CT_Inline_docPr: // 90913;
     996             :         case NS_ooxml::LN_CT_Inline_cNvGraphicFramePr: // 90914;
     997             :         case NS_ooxml::LN_CT_NonVisualGraphicFrameProperties_graphicFrameLocks:// 90657
     998             :         case NS_ooxml::LN_CT_Inline_a_graphic:// 90915
     999             :         case NS_ooxml::LN_CT_Anchor_simplePos_elem: // 90975;
    1000             :         case NS_ooxml::LN_CT_Anchor_extent: // 90978;
    1001             :         case NS_ooxml::LN_CT_Anchor_effectExtent: // 90979;
    1002             :         case NS_ooxml::LN_EG_WrapType_wrapSquare: // 90945;
    1003             :         case NS_ooxml::LN_EG_WrapType_wrapTight: // 90946;
    1004             :         case NS_ooxml::LN_EG_WrapType_wrapThrough:
    1005             :         case NS_ooxml::LN_CT_Anchor_docPr: // 90980;
    1006             :         case NS_ooxml::LN_CT_Anchor_cNvGraphicFramePr: // 90981;
    1007             :         case NS_ooxml::LN_CT_Anchor_a_graphic: // 90982;
    1008             :         case NS_ooxml::LN_CT_WrapPath_start: // 90924;
    1009             :         case NS_ooxml::LN_CT_WrapPath_lineTo: // 90925;
    1010             :         case NS_ooxml::LN_graphic_graphic:
    1011             :         case NS_ooxml::LN_pic_pic:
    1012             :         case NS_ooxml::LN_dgm_relIds:
    1013             :         case NS_ooxml::LN_lc_lockedCanvas:
    1014             :         case NS_ooxml::LN_c_chart:
    1015             :         case NS_ooxml::LN_wps_wsp:
    1016             :         case NS_ooxml::LN_wpg_wgp:
    1017             :         case NS_ooxml::LN_sizeRelH_sizeRelH:
    1018             :         case NS_ooxml::LN_sizeRelV_sizeRelV:
    1019             :         case NS_ooxml::LN_hlinkClick_hlinkClick:
    1020             :         {
    1021       10245 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
    1022       10245 :             if( pProperties.get())
    1023             :             {
    1024       10245 :                 pProperties->resolve(*this);
    1025             :             }
    1026             : 
    1027             :             // We'll map these to PARALLEL, save the original wrap type.
    1028       10245 :             if (nSprmId == NS_ooxml::LN_EG_WrapType_wrapTight)
    1029          12 :                 m_pImpl->m_aInteropGrabBag["EG_WrapType"] <<= OUString("wrapTight");
    1030       10233 :             else if (nSprmId == NS_ooxml::LN_EG_WrapType_wrapThrough)
    1031          21 :                 m_pImpl->m_aInteropGrabBag["EG_WrapType"] <<= OUString("wrapThrough");
    1032             :         }
    1033       10245 :         break;
    1034             :         case NS_ooxml::LN_CT_WrapTight_wrapPolygon:
    1035             :         case NS_ooxml::LN_CT_WrapThrough_wrapPolygon:
    1036             :             {
    1037          33 :                 WrapPolygonHandler aHandler;
    1038             : 
    1039          33 :                 resolveSprmProps(aHandler, rSprm);
    1040             : 
    1041          33 :                 m_pImpl->mpWrapPolygon = aHandler.getPolygon();
    1042             : 
    1043             :                 // Save the wrap path in case we can't handle it natively: drawinglayer shapes, TextFrames.
    1044          33 :                 m_pImpl->m_aInteropGrabBag["CT_WrapPath"] <<= m_pImpl->mpWrapPolygon->getPointSequenceSequence();
    1045             :             }
    1046          33 :             break;
    1047             :         case NS_ooxml::LN_CT_Anchor_positionH: // 90976;
    1048             :         {
    1049             :             // Use a special handler for the positionning
    1050         957 :             PositionHandlerPtr pHandler( new PositionHandler( m_pImpl->m_rPositionOffsets, m_pImpl->m_rAligns ));
    1051        1914 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
    1052         957 :             if( pProperties.get( ) )
    1053             :             {
    1054         957 :                 pProperties->resolve( *pHandler );
    1055         957 :                 if( !m_pImpl->bUseSimplePos )
    1056             :                 {
    1057         957 :                     m_pImpl->nHoriRelation = pHandler->relation();
    1058         957 :                     m_pImpl->nHoriOrient = pHandler->orientation();
    1059         957 :                     m_pImpl->nLeftPosition = pHandler->position();
    1060         957 :                     if (m_pImpl->nHoriRelation == text::RelOrientation::PAGE_FRAME && m_pImpl->nHoriOrient == text::HoriOrientation::RIGHT)
    1061             :                     {
    1062             :                         // If the shape is relative from page and aligned to
    1063             :                         // right, then set the relation to right and clear the
    1064             :                         // orientation, that provides the same visual result as
    1065             :                         // Word.
    1066           8 :                         m_pImpl->nHoriRelation = text::RelOrientation::PAGE_RIGHT;
    1067           8 :                         m_pImpl->nHoriOrient = text::HoriOrientation::NONE;
    1068             :                     }
    1069             :                 }
    1070         957 :             }
    1071             :         }
    1072         957 :         break;
    1073             :         case NS_ooxml::LN_CT_Anchor_positionV: // 90977;
    1074             :         {
    1075             :             // Use a special handler for the positionning
    1076         957 :             PositionHandlerPtr pHandler( new PositionHandler( m_pImpl->m_rPositionOffsets, m_pImpl->m_rAligns));
    1077        1914 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
    1078         957 :             if( pProperties.get( ) )
    1079             :             {
    1080         957 :                 pProperties->resolve( *pHandler );
    1081         957 :                 if( !m_pImpl->bUseSimplePos )
    1082             :                 {
    1083         957 :                     m_pImpl->nVertRelation = pHandler->relation();
    1084         957 :                     m_pImpl->nVertOrient = pHandler->orientation();
    1085         957 :                     m_pImpl->nTopPosition = pHandler->position();
    1086             :                 }
    1087         957 :             }
    1088             :         }
    1089         957 :         break;
    1090             :         case NS_ooxml::LN_CT_SizeRelH_pctWidth:
    1091             :         case NS_ooxml::LN_CT_SizeRelV_pctHeight:
    1092         842 :             if (m_xShape.is() && !m_pImpl->m_rPositivePercentages.empty())
    1093             :             {
    1094         793 :                 sal_Int16 nPositivePercentage = rtl::math::round(m_pImpl->m_rPositivePercentages.front().toDouble() / oox::drawingml::PER_PERCENT);
    1095         793 :                 m_pImpl->m_rPositivePercentages.pop();
    1096             : 
    1097         793 :                 if (nPositivePercentage)
    1098             :                 {
    1099         113 :                     uno::Reference<beans::XPropertySet> xPropertySet(m_xShape, uno::UNO_QUERY);
    1100         226 :                     OUString aProperty = nSprmId == NS_ooxml::LN_CT_SizeRelH_pctWidth ? OUString("RelativeWidth") : OUString("RelativeHeight");
    1101         226 :                     xPropertySet->setPropertyValue(aProperty, uno::makeAny(nPositivePercentage));
    1102             :                 }
    1103             :             }
    1104         842 :             break;
    1105             :         case NS_ooxml::LN_EG_WrapType_wrapNone: // 90944; - doesn't contain attributes
    1106             :             //depending on the behindDoc attribute text wraps through behind or in fron of the object
    1107         773 :             m_pImpl->nWrap = text::WrapTextMode_THROUGHT;
    1108         773 :         break;
    1109             :         case NS_ooxml::LN_EG_WrapType_wrapTopAndBottom: // 90948;
    1110          24 :             m_pImpl->nWrap = text::WrapTextMode_NONE;
    1111          24 :         break;
    1112             :         case NS_ooxml::LN_CT_GraphicalObject_graphicData:// 90660;
    1113             :             {
    1114        1373 :                 m_pImpl->bIsGraphic = true;
    1115             : 
    1116        1373 :                 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
    1117        1373 :                 if( pProperties.get())
    1118        1373 :                     pProperties->resolve(*this);
    1119             :             }
    1120        1373 :         break;
    1121             :         default:
    1122             :             SAL_WARN("writerfilter", "GraphicImport::lcl_sprm: unhandled token: " << nSprmId);
    1123           0 :         break;
    1124       15204 :     }
    1125       15204 : }
    1126             : 
    1127           0 : void GraphicImport::lcl_entry(int /*pos*/, writerfilter::Reference<Properties>::Pointer_t /*ref*/)
    1128             : {
    1129           0 : }
    1130             : 
    1131         362 : uno::Reference< text::XTextContent > GraphicImport::createGraphicObject( const beans::PropertyValues& aMediaProperties, const uno::Reference<beans::XPropertySet>& xShapeProps )
    1132             : {
    1133         362 :     uno::Reference< text::XTextContent > xGraphicObject;
    1134             :     try
    1135             :     {
    1136         362 :         uno::Reference< graphic::XGraphicProvider > xGraphicProvider( graphic::GraphicProvider::create(m_xComponentContext) );
    1137         724 :         uno::Reference< graphic::XGraphic > xGraphic = xGraphicProvider->queryGraphic( aMediaProperties );
    1138             : 
    1139         362 :         if(xGraphic.is())
    1140             :         {
    1141         276 :             PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
    1142             : 
    1143             :             uno::Reference< beans::XPropertySet > xGraphicObjectProperties(
    1144         276 :             m_xTextFactory->createInstance("com.sun.star.text.TextGraphicObject"),
    1145         276 :                 uno::UNO_QUERY_THROW);
    1146         276 :             xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_GRAPHIC), uno::makeAny( xGraphic ));
    1147         276 :             xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_ANCHOR_TYPE),
    1148         276 :                 uno::makeAny( m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR ?
    1149             :                                     text::TextContentAnchorType_AT_CHARACTER :
    1150         552 :                                     text::TextContentAnchorType_AS_CHARACTER ));
    1151         276 :             xGraphicObject = uno::Reference< text::XTextContent >( xGraphicObjectProperties, uno::UNO_QUERY_THROW );
    1152             : 
    1153             :             //shapes have only one border
    1154         276 :             table::BorderLine2 aBorderLine;
    1155         276 :             GraphicBorderLine& rBorderLine = m_pImpl->aBorders[0];
    1156         276 :             if (rBorderLine.isEmpty() && xShapeProps.is() && xShapeProps->getPropertyValue("LineStyle").get<drawing::LineStyle>() != drawing::LineStyle_NONE)
    1157             :             {
    1158             :                 // In case we got no border tokens and we have the
    1159             :                 // original shape, then use its line properties as the
    1160             :                 // border.
    1161           1 :                 aBorderLine.Color = xShapeProps->getPropertyValue("LineColor").get<sal_Int32>();
    1162           1 :                 aBorderLine.LineWidth = xShapeProps->getPropertyValue("LineWidth").get<sal_Int32>();
    1163             :             }
    1164             :             else
    1165             :             {
    1166         275 :                 aBorderLine.Color = rBorderLine.nLineColor;
    1167         275 :                 aBorderLine.InnerLineWidth = 0;
    1168         275 :                 aBorderLine.OuterLineWidth = (sal_Int16)rBorderLine.nLineWidth;
    1169         275 :                 aBorderLine.LineDistance = 0;
    1170             :             }
    1171             :             PropertyIds aBorderProps[4] =
    1172             :             {
    1173             :                 PROP_LEFT_BORDER,
    1174             :                 PROP_RIGHT_BORDER,
    1175             :                 PROP_TOP_BORDER,
    1176             :                 PROP_BOTTOM_BORDER
    1177         276 :             };
    1178             : 
    1179        1380 :             for( sal_Int32 nBorder = 0; nBorder < 4; ++nBorder )
    1180        1104 :                 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( aBorderProps[nBorder]), uno::makeAny(aBorderLine));
    1181             : 
    1182             :             // setting graphic object shadow proerties
    1183         276 :             if (m_pImpl->bShadow)
    1184             :             {
    1185             :                 // Shadow width is approximated by average of X and Y
    1186           0 :                 table::ShadowFormat aShadow;
    1187           0 :                 sal_uInt32 nShadowColor = m_pImpl->nShadowColor & 0x00FFFFFF; // The shadow color we get is RGB only.
    1188           0 :                 sal_Int32 nShadowWidth = (abs(m_pImpl->nShadowXDistance)
    1189           0 :                                           + abs(m_pImpl->nShadowYDistance)) / 2;
    1190             : 
    1191           0 :                 aShadow.ShadowWidth = nShadowWidth;
    1192           0 :                 sal_uInt8 nShadowTransparence = float(m_pImpl->nShadowTransparence) * 2.55;
    1193           0 :                 nShadowColor |= (nShadowTransparence << 24); // Add transparence to the color.
    1194           0 :                 aShadow.Color = nShadowColor;
    1195             :                 // Distances -ve for top and right, +ve for bottom and left
    1196           0 :                 if (m_pImpl->nShadowXDistance > 0)
    1197             :                 {
    1198           0 :                     if (m_pImpl->nShadowYDistance > 0)
    1199           0 :                         aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
    1200             :                     else
    1201           0 :                         aShadow.Location = table::ShadowLocation_TOP_RIGHT;
    1202             :                 }
    1203             :                 else
    1204             :                 {
    1205           0 :                     if (m_pImpl->nShadowYDistance > 0)
    1206           0 :                         aShadow.Location = table::ShadowLocation_BOTTOM_LEFT;
    1207             :                     else
    1208           0 :                         aShadow.Location = table::ShadowLocation_TOP_LEFT;
    1209             :                 }
    1210             : 
    1211           0 :                 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_SHADOW_FORMAT), uno::makeAny(aShadow));
    1212             :             }
    1213             : 
    1214             :             // setting properties for all types
    1215         276 :             if( m_pImpl->bPositionProtected )
    1216           0 :                 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_POSITION_PROTECTED ),
    1217           0 :                     uno::makeAny(true));
    1218         276 :             if( m_pImpl->bSizeProtected )
    1219           0 :                 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_SIZE_PROTECTED ),
    1220           0 :                     uno::makeAny(true));
    1221             : 
    1222         276 :             sal_Int32 nWidth = m_pImpl->nRightPosition - m_pImpl->nLeftPosition;
    1223         276 :             if (m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR)
    1224             :             {
    1225             :                 //adjust margins
    1226         180 :                 if( (m_pImpl->nHoriOrient == text::HoriOrientation::LEFT &&
    1227           0 :                     (m_pImpl->nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA ||
    1228         180 :                         m_pImpl->nHoriRelation == text::RelOrientation::FRAME) ) ||
    1229          90 :                     (m_pImpl->nHoriOrient == text::HoriOrientation::INSIDE &&
    1230           0 :                         m_pImpl->nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA ))
    1231           0 :                     m_pImpl->nLeftMargin = 0;
    1232         181 :                 if((m_pImpl->nHoriOrient == text::HoriOrientation::RIGHT &&
    1233           1 :                     (m_pImpl->nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA ||
    1234         180 :                         m_pImpl->nHoriRelation == text::RelOrientation::FRAME) ) ||
    1235          89 :                     (m_pImpl->nHoriOrient == text::HoriOrientation::INSIDE &&
    1236           0 :                         m_pImpl->nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA ))
    1237           1 :                     m_pImpl->nRightMargin = 0;
    1238             :                 // adjust top/bottom margins
    1239         104 :                 if( m_pImpl->nVertOrient == text::VertOrientation::TOP &&
    1240          25 :                     ( m_pImpl->nVertRelation == text::RelOrientation::PAGE_PRINT_AREA ||
    1241          12 :                         m_pImpl->nVertRelation == text::RelOrientation::PAGE_FRAME))
    1242           1 :                     m_pImpl->nTopMargin = 0;
    1243          96 :                 if( m_pImpl->nVertOrient == text::VertOrientation::BOTTOM &&
    1244           6 :                     ( m_pImpl->nVertRelation == text::RelOrientation::PAGE_PRINT_AREA ||
    1245           3 :                         m_pImpl->nVertRelation == text::RelOrientation::PAGE_FRAME))
    1246           3 :                     m_pImpl->nBottomMargin = 0;
    1247          93 :                 if( m_pImpl->nVertOrient == text::VertOrientation::BOTTOM &&
    1248           3 :                     m_pImpl->nVertRelation == text::RelOrientation::PAGE_PRINT_AREA )
    1249           0 :                     m_pImpl->nBottomMargin = 0;
    1250             :                 //adjust alignment
    1251          90 :                 if( m_pImpl->nHoriOrient == text::HoriOrientation::INSIDE &&
    1252           0 :                     m_pImpl->nHoriRelation == text::RelOrientation::PAGE_FRAME )
    1253             :                 {
    1254             :                     // convert 'left to page' to 'from left -<width> to page text area'
    1255           0 :                     m_pImpl->nHoriOrient = text::HoriOrientation::NONE;
    1256           0 :                     m_pImpl->nHoriRelation = text::RelOrientation::PAGE_PRINT_AREA;
    1257           0 :                     m_pImpl->nLeftPosition = - nWidth;
    1258             :                 }
    1259          90 :                 else if( m_pImpl->nHoriOrient == text::HoriOrientation::OUTSIDE &&
    1260           0 :                     m_pImpl->nHoriRelation == text::RelOrientation::PAGE_FRAME )
    1261             :                 {
    1262             :                     // convert 'right to page' to 'from left 0 to right page border'
    1263           0 :                     m_pImpl->nHoriOrient = text::HoriOrientation::NONE;
    1264           0 :                     m_pImpl->nHoriRelation = text::RelOrientation::PAGE_RIGHT;
    1265           0 :                     m_pImpl->nLeftPosition = 0;
    1266             :                 }
    1267             : 
    1268          90 :                 m_pImpl->applyPosition(xGraphicObjectProperties);
    1269          90 :                 m_pImpl->applyRelativePosition(xGraphicObjectProperties);
    1270          90 :                 bool bOpaque = m_pImpl->bOpaque && !m_pImpl->rDomainMapper.IsInHeaderFooter( );
    1271          90 :                 if( !bOpaque )
    1272             :                 {
    1273          39 :                     xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_OPAQUE ),
    1274          39 :                         uno::makeAny(bOpaque));
    1275             :                 }
    1276          90 :                 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_SURROUND ),
    1277          90 :                     uno::makeAny(m_pImpl->nWrap));
    1278          90 :                 if( m_pImpl->bLayoutInCell && m_pImpl->nWrap != text::WrapTextMode_THROUGHT )
    1279          39 :                     xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_FOLLOW_TEXT_FLOW ),
    1280          39 :                         uno::makeAny(true));
    1281             : 
    1282          90 :                 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_SURROUND_CONTOUR ),
    1283          90 :                     uno::makeAny(m_pImpl->bContour));
    1284          90 :                 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_CONTOUR_OUTSIDE ),
    1285          90 :                     uno::makeAny(m_pImpl->bContourOutside));
    1286          90 :                 m_pImpl->applyMargins(xGraphicObjectProperties);
    1287             :             }
    1288             : 
    1289         823 :             if( m_pImpl->eColorMode == drawing::ColorMode_STANDARD &&
    1290         276 :                 m_pImpl->nContrast == -70 &&
    1291           0 :                 m_pImpl->nBrightness == 70 )
    1292             :             {
    1293             :                 // strange definition of WATERMARK!
    1294           0 :                 m_pImpl->nContrast = 0;
    1295           0 :                 m_pImpl->nBrightness = 0;
    1296           0 :                 m_pImpl->eColorMode = drawing::ColorMode_WATERMARK;
    1297             :             }
    1298             : 
    1299         276 :             xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_ADJUST_CONTRAST ),
    1300         276 :                 uno::makeAny((sal_Int16)m_pImpl->nContrast));
    1301         276 :             xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_ADJUST_LUMINANCE ),
    1302         276 :                 uno::makeAny((sal_Int16)m_pImpl->nBrightness));
    1303         276 :             if(m_pImpl->eColorMode != drawing::ColorMode_STANDARD)
    1304             :             {
    1305           5 :                 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_GRAPHIC_COLOR_MODE ),
    1306           5 :                     uno::makeAny(m_pImpl->eColorMode));
    1307             :             }
    1308         276 :             if(m_pImpl->fGamma > 0. )
    1309           0 :                 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_GAMMA ),
    1310           0 :                     uno::makeAny(m_pImpl->fGamma ));
    1311         276 :             if(m_pImpl->bHoriFlip)
    1312             :             {
    1313           0 :                 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_MIRRORED_ON_EVEN_PAGES ),
    1314           0 :                 uno::makeAny( m_pImpl->bHoriFlip ));
    1315           0 :                 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_MIRRORED_ON_ODD_PAGES ),
    1316           0 :                 uno::makeAny( m_pImpl->bHoriFlip ));
    1317             :             }
    1318             : 
    1319         276 :             if( m_pImpl->bVertFlip )
    1320           0 :                 xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_VERT_MIRRORED ),
    1321           0 :                     uno::makeAny( m_pImpl->bVertFlip ));
    1322         276 :             xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_BACK_COLOR ),
    1323         276 :                 uno::makeAny( m_pImpl->nFillColor ));
    1324             : 
    1325         276 :             m_pImpl->applyZOrder(xGraphicObjectProperties);
    1326             : 
    1327             :             //there seems to be no way to detect the original size via _real_ API
    1328         552 :             uno::Reference< beans::XPropertySet > xGraphicProperties( xGraphic, uno::UNO_QUERY_THROW );
    1329         276 :             awt::Size aGraphicSize, aGraphicSizePixel;
    1330         276 :             xGraphicProperties->getPropertyValue(rPropNameSupplier.GetName( PROP_SIZE100th_M_M )) >>= aGraphicSize;
    1331         276 :             xGraphicProperties->getPropertyValue(rPropNameSupplier.GetName( PROP_SIZE_PIXEL )) >>= aGraphicSizePixel;
    1332             : 
    1333         552 :             uno::Any aContourPolyPolygon;
    1334         420 :             if( aGraphicSize.Width && aGraphicSize.Height &&
    1335         144 :                 m_pImpl->mpWrapPolygon.get() != nullptr)
    1336             :             {
    1337          10 :                 WrapPolygon::Pointer_t pCorrected = m_pImpl->mpWrapPolygon->correctWordWrapPolygon(aGraphicSize);
    1338          10 :                 aContourPolyPolygon <<= pCorrected->getPointSequenceSequence();
    1339             :             }
    1340             : 
    1341         276 :             xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_CONTOUR_POLY_POLYGON),
    1342         276 :                                                            aContourPolyPolygon);
    1343             : 
    1344         276 :             if(m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_INLINE || m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR)
    1345             :             {
    1346         276 :                 if( m_pImpl->getXSize() && m_pImpl->getYSize() )
    1347         276 :                     xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_SIZE),
    1348         276 :                         uno::makeAny( awt::Size( m_pImpl->getXSize(), m_pImpl->getYSize() )));
    1349         276 :                 m_pImpl->applyMargins(xGraphicObjectProperties);
    1350         276 :                 m_pImpl->applyName(xGraphicObjectProperties);
    1351         276 :             }
    1352         362 :         }
    1353             :     }
    1354           0 :     catch( const uno::Exception& e )
    1355             :     {
    1356             :         SAL_WARN("writerfilter", "failed. Message :" << e.Message);
    1357             :     }
    1358         362 :     return xGraphicObject;
    1359             : }
    1360             : 
    1361             : 
    1362             : 
    1363           0 : void GraphicImport::data(const sal_uInt8* buf, size_t len, writerfilter::Reference<Properties>::Pointer_t /*ref*/)
    1364             : {
    1365           0 :         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
    1366             : 
    1367           0 :         beans::PropertyValues aMediaProperties( 1 );
    1368           0 :         aMediaProperties[0].Name = rPropNameSupplier.GetName(PROP_INPUT_STREAM);
    1369             : 
    1370           0 :         uno::Reference< io::XInputStream > xIStream = new XInputStreamHelper( buf, len, m_pImpl->bIsBitmap );
    1371           0 :         aMediaProperties[0].Value <<= xIStream;
    1372             : 
    1373           0 :         uno::Reference<beans::XPropertySet> xPropertySet;
    1374           0 :         m_xGraphicObject = createGraphicObject( aMediaProperties, xPropertySet );
    1375           0 : }
    1376             : 
    1377             : 
    1378           0 : void GraphicImport::lcl_startSectionGroup()
    1379             : {
    1380           0 : }
    1381             : 
    1382             : 
    1383           0 : void GraphicImport::lcl_endSectionGroup()
    1384             : {
    1385           0 : }
    1386             : 
    1387             : 
    1388           0 : void GraphicImport::lcl_startParagraphGroup()
    1389             : {
    1390           0 : }
    1391             : 
    1392             : 
    1393           0 : void GraphicImport::lcl_endParagraphGroup()
    1394             : {
    1395           0 : }
    1396             : 
    1397             : 
    1398           0 : void GraphicImport::lcl_startCharacterGroup()
    1399             : {
    1400           0 : }
    1401             : 
    1402             : 
    1403           0 : void GraphicImport::lcl_endCharacterGroup()
    1404             : {
    1405           0 : }
    1406             : 
    1407             : 
    1408           0 : void GraphicImport::lcl_text(const sal_uInt8 * /*_data*/, size_t /*len*/)
    1409             : {
    1410           0 : }
    1411             : 
    1412             : 
    1413           0 : void GraphicImport::lcl_utext(const sal_uInt8 * /*_data*/, size_t /*len*/)
    1414             : {
    1415           0 : }
    1416             : 
    1417             : 
    1418           0 : void GraphicImport::lcl_props(writerfilter::Reference<Properties>::Pointer_t /*ref*/)
    1419             : {
    1420           0 : }
    1421             : 
    1422             : 
    1423           0 : void GraphicImport::lcl_table(Id /*name*/, writerfilter::Reference<Table>::Pointer_t /*ref*/)
    1424             : {
    1425           0 : }
    1426             : 
    1427             : 
    1428           0 : void GraphicImport::lcl_substream(Id /*name*/, ::writerfilter::Reference<Stream>::Pointer_t /*ref*/)
    1429             : {
    1430           0 : }
    1431             : 
    1432             : 
    1433           0 : void GraphicImport::lcl_info(const std::string& /*info*/)
    1434             : {
    1435           0 : }
    1436             : 
    1437           0 : void GraphicImport::lcl_startShape(uno::Reference<drawing::XShape> const&)
    1438             : {
    1439           0 : }
    1440             : 
    1441           0 : void GraphicImport::lcl_endShape( )
    1442             : {
    1443           0 : }
    1444             : 
    1445        1373 : bool GraphicImport::IsGraphic() const
    1446             : {
    1447        1373 :     return m_pImpl->bIsGraphic;
    1448             : }
    1449             : 
    1450             : }
    1451             : }
    1452             : 
    1453             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11