1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
45 #include <cppuhelper/implbase1.hxx>
46 #include <rtl/ustrbuf.hxx>
47 #include <rtl/math.hxx>
48 #include <rtl/ustrbuf.hxx>
49 #include <comphelper/string.hxx>
51 #include <oox/drawingml/drawingmltypes.hxx>
53 #include <dmapper/DomainMapper.hxx>
54 #include <ooxml/resourceids.hxx>
55 #include <resourcemodel/ResourceModelHelper.hxx>
57 #include "ConversionHelper.hxx"
58 #include "GraphicHelpers.hxx"
59 #include "GraphicImport.hxx"
60 #include "PropertyMap.hxx"
61 #include "WrapPolygonHandler.hxx"
62 #include "dmapperLoggers.hxx"
64 namespace writerfilter
{
66 using resourcemodel::resolveSprmProps
;
73 class XInputStreamHelper
: public cppu::WeakImplHelper1
<io::XInputStream
>
75 const sal_uInt8
* m_pBuffer
;
76 const sal_Int32 m_nLength
;
77 sal_Int32 m_nPosition
;
80 const sal_uInt8
* m_pBMPHeader
; //default BMP-header
81 sal_Int32 m_nHeaderLength
;
83 XInputStreamHelper(const sal_uInt8
* buf
, size_t len
, bool bBmp
);
84 virtual ~XInputStreamHelper();
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
;
93 XInputStreamHelper::XInputStreamHelper(const sal_uInt8
* buf
, size_t len
, bool bBmp
) :
99 static const sal_uInt8 aHeader
[] =
100 {0x42, 0x4d, 0xe6, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
101 m_pBMPHeader
= aHeader
;
102 m_nHeaderLength
= m_bBmp
? sizeof( aHeader
) / sizeof(sal_uInt8
) : 0;
106 XInputStreamHelper::~XInputStreamHelper()
110 sal_Int32
XInputStreamHelper::readBytes( uno::Sequence
<sal_Int8
>& aData
, sal_Int32 nBytesToRead
)
111 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
, std::exception
)
113 return readSomeBytes( aData
, nBytesToRead
);
116 sal_Int32
XInputStreamHelper::readSomeBytes( uno::Sequence
<sal_Int8
>& aData
, sal_Int32 nMaxBytesToRead
)
117 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
, std::exception
)
120 if( nMaxBytesToRead
> 0 )
122 if( nMaxBytesToRead
> (m_nLength
+ m_nHeaderLength
) - m_nPosition
)
123 nRet
= (m_nLength
+ m_nHeaderLength
) - m_nPosition
;
125 nRet
= nMaxBytesToRead
;
126 aData
.realloc( nRet
);
127 sal_Int8
* pData
= aData
.getArray();
128 sal_Int32 nHeaderRead
= 0;
129 if( m_nPosition
< m_nHeaderLength
)
131 //copy header content first
132 nHeaderRead
= m_nHeaderLength
- m_nPosition
;
133 memcpy( pData
, m_pBMPHeader
+ (m_nPosition
), nHeaderRead
);
135 m_nPosition
+= nHeaderRead
;
139 memcpy( pData
+ nHeaderRead
, m_pBuffer
+ (m_nPosition
- m_nHeaderLength
), nRet
);
147 void XInputStreamHelper::skipBytes( sal_Int32 nBytesToSkip
) throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
, std::exception
)
149 if( nBytesToSkip
< 0 || m_nPosition
+ nBytesToSkip
> (m_nLength
+ m_nHeaderLength
))
150 throw io::BufferSizeExceededException();
151 m_nPosition
+= nBytesToSkip
;
155 sal_Int32
XInputStreamHelper::available( ) throw (io::NotConnectedException
, io::IOException
, uno::RuntimeException
, std::exception
)
157 return ( m_nLength
+ m_nHeaderLength
) - m_nPosition
;
161 void XInputStreamHelper::closeInput( ) throw (io::NotConnectedException
, io::IOException
, uno::RuntimeException
, std::exception
)
166 struct GraphicBorderLine
168 sal_Int32 nLineWidth
;
169 sal_Int32 nLineColor
;
170 sal_Int32 nLineDistance
;
173 GraphicBorderLine() :
182 return nLineWidth
== 0 && nLineColor
== 0 && bHasShadow
== false;
187 class GraphicImport_Impl
196 GraphicImportType eGraphicImportType
;
197 DomainMapper
& rDomainMapper
;
199 sal_Int32 nHoriScaling
;
200 sal_Int32 nVertScaling
;
201 sal_Int32 nLeftPosition
;
202 sal_Int32 nTopPosition
;
203 sal_Int32 nRightPosition
;
204 sal_Int32 nBottomPosition
;
207 sal_Int32 nRightCrop
;
208 sal_Int32 nBottomCrop
;
213 sal_Int16 nHoriOrient
;
214 sal_Int16 nHoriRelation
;
216 sal_Int16 nVertOrient
;
217 sal_Int16 nVertRelation
;
222 bool bContourOutside
;
223 WrapPolygon::Pointer_t mpWrapPolygon
;
226 sal_Int32 nLeftMargin
;
227 sal_Int32 nRightMargin
;
228 sal_Int32 nTopMargin
;
229 sal_Int32 nBottomMargin
;
232 sal_Int32 nShadowXDistance
;
233 sal_Int32 nShadowYDistance
;
234 sal_Int32 nShadowColor
;
235 sal_Int32 nShadowTransparence
;
238 sal_Int32 nBrightness
;
241 sal_Int32 nFillColor
;
243 drawing::ColorMode eColorMode
;
245 GraphicBorderLine aBorders
[4];
246 sal_Int32 nCurrentBorderLine
;
252 sal_Int32 nBitsPerPixel
;
258 bool bPositionProtected
;
260 sal_Int32 nShapeOptionType
;
263 OUString sAlternativeText
;
265 std::queue
<OUString
>& m_rPositivePercentages
;
268 GraphicImport_Impl(GraphicImportType eImportType
, DomainMapper
& rDMapper
, std::queue
<OUString
>& rPositivePercentages
) :
273 ,eGraphicImportType( eImportType
)
274 ,rDomainMapper( rDMapper
)
285 ,bUseSimplePos(false)
287 ,nHoriOrient( text::HoriOrientation::NONE
)
288 ,nHoriRelation( text::RelOrientation::FRAME
)
289 ,bPageToggle( false )
290 ,nVertOrient( text::VertOrientation::NONE
)
291 ,nVertRelation( text::RelOrientation::FRAME
)
293 ,bLayoutInCell(false)
296 ,bContourOutside(true)
306 ,nShadowTransparence(0)
310 ,nFillColor( 0xffffffff )
311 ,eColorMode( drawing::ColorMode_STANDARD
)
312 ,nCurrentBorderLine(BORDER_TOP
)
320 ,bSizeProtected(false)
321 ,bPositionProtected(false)
323 ,m_rPositivePercentages(rPositivePercentages
)
326 void setXSize(sal_Int32 _nXSize
)
332 sal_uInt32
getXSize() const
337 bool isXSizeValid() const
342 void setYSize(sal_Int32 _nYSize
)
348 sal_uInt32
getYSize() const
353 bool isYSizeValis () const
358 void applyMargins(uno::Reference
< beans::XPropertySet
> xGraphicObjectProperties
) const
360 PropertyNameSupplier
& rPropNameSupplier
= PropertyNameSupplier::GetPropertyNameSupplier();
361 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_LEFT_MARGIN
), uno::makeAny(nLeftMargin
));
362 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_RIGHT_MARGIN
), uno::makeAny(nRightMargin
));
363 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_TOP_MARGIN
), uno::makeAny(nTopMargin
));
364 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_BOTTOM_MARGIN
), uno::makeAny(nBottomMargin
));
367 void applyPosition(uno::Reference
< beans::XPropertySet
> xGraphicObjectProperties
) const
369 PropertyNameSupplier
& rPropNameSupplier
= PropertyNameSupplier::GetPropertyNameSupplier();
370 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_HORI_ORIENT
),
371 uno::makeAny(nHoriOrient
));
372 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_VERT_ORIENT
),
373 uno::makeAny(nVertOrient
));
376 void applyRelativePosition(uno::Reference
< beans::XPropertySet
> xGraphicObjectProperties
) const
378 PropertyNameSupplier
& rPropNameSupplier
= PropertyNameSupplier::GetPropertyNameSupplier();
379 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_HORI_ORIENT_POSITION
),
380 uno::makeAny(nLeftPosition
));
381 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_HORI_ORIENT_RELATION
),
382 uno::makeAny(nHoriRelation
));
383 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_PAGE_TOGGLE
),
384 uno::makeAny(bPageToggle
));
385 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_VERT_ORIENT_POSITION
),
386 uno::makeAny(nTopPosition
));
387 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_VERT_ORIENT_RELATION
),
388 uno::makeAny(nVertRelation
));
391 void applyZOrder(uno::Reference
<beans::XPropertySet
>& xGraphicObjectProperties
) const
393 PropertyNameSupplier
& rPropNameSupplier
= PropertyNameSupplier::GetPropertyNameSupplier();
396 GraphicZOrderHelper
* pZOrderHelper
= rDomainMapper
.graphicZOrderHelper();
397 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName(PROP_Z_ORDER
), uno::makeAny(pZOrderHelper
->findZOrder(zOrder
)));
398 pZOrderHelper
->addItem(xGraphicObjectProperties
, zOrder
);
402 void applyName(uno::Reference
<beans::XPropertySet
>& xGraphicObjectProperties
) const
404 PropertyNameSupplier
& rPropNameSupplier
= PropertyNameSupplier::GetPropertyNameSupplier();
407 if( !sName
.isEmpty() )
409 uno::Reference
< container::XNamed
> xNamed( xGraphicObjectProperties
, uno::UNO_QUERY_THROW
);
410 xNamed
->setName( sName
);
412 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_DESCRIPTION
),
413 uno::makeAny( sAlternativeText
));
414 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_TITLE
),
415 uno::makeAny( title
));
417 catch( const uno::Exception
& e
)
419 SAL_WARN("writerfilter", "failed. Message :" << e
.Message
);
424 GraphicImport::GraphicImport(uno::Reference
<uno::XComponentContext
> xComponentContext
,
425 uno::Reference
<lang::XMultiServiceFactory
> xTextFactory
,
426 DomainMapper
& rDMapper
,
427 GraphicImportType eImportType
,
428 std::queue
<OUString
>& rPositivePercentages
)
429 : LoggedProperties(dmapper_logger
, "GraphicImport")
430 , LoggedTable(dmapper_logger
, "GraphicImport")
431 , LoggedStream(dmapper_logger
, "GraphicImport")
432 , m_pImpl(new GraphicImport_Impl(eImportType
, rDMapper
, rPositivePercentages
))
433 , m_xComponentContext(xComponentContext
)
434 , m_xTextFactory(xTextFactory
)
438 GraphicImport::~GraphicImport()
442 void GraphicImport::handleWrapTextValue(sal_uInt32 nVal
)
446 case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_bothSides
: // 90920;
447 m_pImpl
->nWrap
= text::WrapTextMode_PARALLEL
;
449 case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_left
: // 90921;
450 m_pImpl
->nWrap
= text::WrapTextMode_LEFT
;
452 case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_right
: // 90922;
453 m_pImpl
->nWrap
= text::WrapTextMode_RIGHT
;
455 case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_largest
: // 90923;
456 m_pImpl
->nWrap
= text::WrapTextMode_DYNAMIC
;
462 void GraphicImport::putPropertyToFrameGrabBag( const OUString
& sPropertyName
, const uno::Any
& aPropertyValue
)
464 beans::PropertyValue pProperty
;
465 pProperty
.Name
= sPropertyName
;
466 pProperty
.Value
= aPropertyValue
;
471 uno::Reference
< beans::XPropertySet
> xSet(m_xShape
, uno::UNO_QUERY_THROW
);
475 uno::Reference
< beans::XPropertySetInfo
> xSetInfo(xSet
->getPropertySetInfo());
479 const OUString
aGrabBagPropName("FrameInteropGrabBag");
481 if (xSetInfo
->hasPropertyByName(aGrabBagPropName
))
483 uno::Sequence
< beans::PropertyValue
> aGrabBag
;
484 xSet
->getPropertyValue( aGrabBagPropName
) >>= aGrabBag
;
486 sal_Int32 nLength
= aGrabBag
.getLength();
487 aGrabBag
.realloc(nLength
+ 1);
488 aGrabBag
[nLength
] = pProperty
;
490 xSet
->setPropertyValue(aGrabBagPropName
, uno::makeAny(aGrabBag
));
494 void GraphicImport::lcl_attribute(Id nName
, Value
& rValue
)
496 sal_Int32 nIntValue
= rValue
.getInt();
499 case NS_ooxml::LN_blip
: //the binary graphic data in a shape
501 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rValue
.getProperties();
502 if( pProperties
.get())
504 pProperties
->resolve(*this);
508 case NS_ooxml::LN_payload
:
510 writerfilter::Reference
<BinaryObj
>::Pointer_t pPictureData
= rValue
.getBinary();
511 if( pPictureData
.get())
512 pPictureData
->resolve(*this);
517 case NS_ooxml::LN_CT_Border_sz
:
518 m_pImpl
->aBorders
[m_pImpl
->nCurrentBorderLine
].nLineWidth
= nIntValue
;
520 case NS_ooxml::LN_CT_Border_val
:
521 //graphic borders don't support different line types
523 case NS_ooxml::LN_CT_Border_space
:
524 m_pImpl
->aBorders
[m_pImpl
->nCurrentBorderLine
].nLineDistance
= nIntValue
;
526 case NS_ooxml::LN_CT_Border_shadow
:
527 m_pImpl
->aBorders
[m_pImpl
->nCurrentBorderLine
].bHasShadow
= nIntValue
? true : false;
529 case NS_ooxml::LN_CT_Border_frame
: // ignored
531 case NS_ooxml::LN_CT_PositiveSize2D_cx
:// 90407;
532 case NS_ooxml::LN_CT_PositiveSize2D_cy
:// 90408;
534 sal_Int32 nDim
= ConversionHelper::convertEMUToMM100( nIntValue
);
535 if( nName
== NS_ooxml::LN_CT_PositiveSize2D_cx
)
536 m_pImpl
->setXSize(nDim
);
538 m_pImpl
->setYSize(nDim
);
541 case NS_ooxml::LN_CT_EffectExtent_l
:// 90907;
542 case NS_ooxml::LN_CT_EffectExtent_t
:// 90908;
543 case NS_ooxml::LN_CT_EffectExtent_r
:// 90909;
544 case NS_ooxml::LN_CT_EffectExtent_b
:// 90910;
545 //todo: extends the wrapping size of the object, e.g. if shadow is added
547 case NS_ooxml::LN_CT_NonVisualDrawingProps_id
:// 90650;
548 //id of the object - ignored
550 case NS_ooxml::LN_CT_NonVisualDrawingProps_name
:// 90651;
552 m_pImpl
->sName
= rValue
.getString();
554 case NS_ooxml::LN_CT_NonVisualDrawingProps_descr
:// 90652;
556 m_pImpl
->sAlternativeText
= rValue
.getString();
558 case NS_ooxml::LN_CT_NonVisualDrawingProps_title
:
560 m_pImpl
->title
= rValue
.getString();
562 case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noChangeAspect
://90644;
563 //disallow aspect ratio change - ignored
565 case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noMove
:// 90645;
566 m_pImpl
->bPositionProtected
= true;
568 case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noResize
: // 90646;
569 m_pImpl
->bSizeProtected
= true;
571 case NS_ooxml::LN_CT_Anchor_distT
: // 90983;
572 case NS_ooxml::LN_CT_Anchor_distB
: // 90984;
573 case NS_ooxml::LN_CT_Anchor_distL
: // 90985;
574 case NS_ooxml::LN_CT_Anchor_distR
: // 90986;
576 m_pImpl
->nShapeOptionType
= nName
;
577 ProcessShapeOptions(rValue
);
580 case NS_ooxml::LN_CT_Anchor_simplePos_attr
: // 90987;
581 m_pImpl
->bUseSimplePos
= nIntValue
> 0;
583 case NS_ooxml::LN_CT_Anchor_relativeHeight
: // 90988;
584 m_pImpl
->zOrder
= nIntValue
;
586 case NS_ooxml::LN_CT_Anchor_behindDoc
: // 90989; - in background
588 m_pImpl
->bOpaque
= false;
590 case NS_ooxml::LN_CT_Anchor_locked
: // 90990; - ignored
592 case NS_ooxml::LN_CT_Anchor_layoutInCell
: // 90991; - ignored
593 m_pImpl
->bLayoutInCell
= nIntValue
!= 0;
595 case NS_ooxml::LN_CT_Anchor_hidden
: // 90992; - ignored
597 case NS_ooxml::LN_CT_Anchor_allowOverlap
: // 90993;
598 //enable overlapping - ignored
600 case NS_ooxml::LN_CT_Anchor_wp14_anchorId
:
601 case NS_ooxml::LN_CT_Inline_wp14_anchorId
:
603 OUStringBuffer aBuffer
= OUString::number(nIntValue
, 16);
604 OUStringBuffer aString
;
605 comphelper::string::padToLength(aString
, 8 - aBuffer
.getLength(), '0');
606 aString
.append(aBuffer
.getStr());
607 m_pImpl
->sAnchorId
= aString
.makeStringAndClear().toAsciiUpperCase();
610 case NS_ooxml::LN_CT_Point2D_x
: // 90405;
611 m_pImpl
->nLeftPosition
= ConversionHelper::convertTwipToMM100(nIntValue
);
612 m_pImpl
->nHoriRelation
= text::RelOrientation::PAGE_FRAME
;
613 m_pImpl
->nHoriOrient
= text::HoriOrientation::NONE
;
615 case NS_ooxml::LN_CT_Point2D_y
: // 90406;
616 m_pImpl
->nTopPosition
= ConversionHelper::convertTwipToMM100(nIntValue
);
617 m_pImpl
->nVertRelation
= text::RelOrientation::PAGE_FRAME
;
618 m_pImpl
->nVertOrient
= text::VertOrientation::NONE
;
620 case NS_ooxml::LN_CT_WrapTight_wrapText
: // 90934;
621 m_pImpl
->bContour
= true;
622 m_pImpl
->bContourOutside
= true;
624 handleWrapTextValue(rValue
.getInt());
627 case NS_ooxml::LN_CT_WrapThrough_wrapText
:
628 m_pImpl
->bContour
= true;
629 m_pImpl
->bContourOutside
= false;
631 handleWrapTextValue(rValue
.getInt());
634 case NS_ooxml::LN_CT_WrapSquare_wrapText
: //90928;
635 handleWrapTextValue(rValue
.getInt());
637 case NS_ooxml::LN_shape
:
639 uno::Reference
< drawing::XShape
> xShape
;
640 rValue
.getAny( ) >>= xShape
;
644 // Is it a graphic image
645 bool bUseShape
= true;
648 uno::Reference
< beans::XPropertySet
> xShapeProps
649 ( xShape
, uno::UNO_QUERY_THROW
);
652 xShapeProps
->getPropertyValue("GraphicURL") >>= sUrl
;
654 sal_Int32 nRotation
= 0;
655 xShapeProps
->getPropertyValue("RotateAngle") >>= nRotation
;
657 ::css::beans::PropertyValues aGrabBag
;
658 bool bContainsEffects
= false;
659 xShapeProps
->getPropertyValue("InteropGrabBag") >>= aGrabBag
;
660 for( sal_Int32 i
= 0; i
< aGrabBag
.getLength(); ++i
)
662 // if the shape contains effects in the grab bag, we should not transform it
663 // in a XTextContent so those effects can be preserved
664 if( aGrabBag
[i
].Name
== "EffectProperties" || aGrabBag
[i
].Name
== "3DEffectProperties" ||
665 aGrabBag
[i
].Name
== "ArtisticEffectProperties" )
666 bContainsEffects
= true;
669 ::com::sun::star::beans::PropertyValues
aMediaProperties( 1 );
670 aMediaProperties
[0].Name
= "URL";
671 aMediaProperties
[0].Value
<<= sUrl
;
673 xShapeProps
->getPropertyValue("Shadow") >>= m_pImpl
->bShadow
;
674 if (m_pImpl
->bShadow
)
676 xShapeProps
->getPropertyValue("ShadowXDistance") >>= m_pImpl
->nShadowXDistance
;
677 xShapeProps
->getPropertyValue("ShadowYDistance") >>= m_pImpl
->nShadowYDistance
;
678 xShapeProps
->getPropertyValue("ShadowColor") >>= m_pImpl
->nShadowColor
;
679 xShapeProps
->getPropertyValue("ShadowTransparence") >>= m_pImpl
->nShadowTransparence
;
682 xShapeProps
->getPropertyValue("GraphicColorMode") >>= m_pImpl
->eColorMode
;
683 xShapeProps
->getPropertyValue("AdjustLuminance") >>= m_pImpl
->nBrightness
;
684 xShapeProps
->getPropertyValue("AdjustContrast") >>= m_pImpl
->nContrast
;
686 // fdo#70457: transform XShape into a SwXTextGraphicObject only if there's no rotation
687 if ( nRotation
== 0 && !bContainsEffects
)
688 m_xGraphicObject
= createGraphicObject( aMediaProperties
, xShapeProps
);
690 bUseShape
= !m_xGraphicObject
.is( );
694 // Define the object size
695 uno::Reference
< beans::XPropertySet
> xGraphProps( m_xGraphicObject
,
697 awt::Size aSize
= xShape
->getSize( );
698 xGraphProps
->setPropertyValue("Height",
699 uno::makeAny( aSize
.Height
) );
700 xGraphProps
->setPropertyValue("Width",
701 uno::makeAny( aSize
.Width
) );
703 text::GraphicCrop
aGraphicCrop( 0, 0, 0, 0 );
704 uno::Reference
< beans::XPropertySet
> xSourceGraphProps( xShape
, uno::UNO_QUERY
);
705 uno::Any aAny
= xSourceGraphProps
->getPropertyValue("GraphicCrop");
706 if(aAny
>>= aGraphicCrop
) {
707 xGraphProps
->setPropertyValue("GraphicCrop",
708 uno::makeAny( aGraphicCrop
) );
711 // We need to drop the shape here somehow
712 uno::Reference
< lang::XComponent
> xShapeComponent( xShape
, uno::UNO_QUERY
);
713 xShapeComponent
->dispose( );
716 catch( const beans::UnknownPropertyException
& )
718 // It isn't a graphic image
725 if ( m_xShape
.is( ) )
727 uno::Reference
< beans::XPropertySet
> xShapeProps
728 (m_xShape
, uno::UNO_QUERY_THROW
);
731 PropertyNameSupplier
& rPropNameSupplier
=
732 PropertyNameSupplier::GetPropertyNameSupplier();
733 xShapeProps
->setPropertyValue
734 (rPropNameSupplier
.GetName(PROP_ANCHOR_TYPE
),
736 (text::TextContentAnchorType_AS_CHARACTER
));
738 // In Word, if a shape is anchored inline, that
739 // excludes being in the background.
740 xShapeProps
->setPropertyValue("Opaque", uno::makeAny(true));
742 uno::Reference
<lang::XServiceInfo
> xServiceInfo(m_xShape
, uno::UNO_QUERY_THROW
);
744 // TextFrames can't be rotated. But for anything else,
745 // make sure that setting size doesn't affect rotation,
746 // that would not match Word's definition of rotation.
747 bool bKeepRotation
= false;
748 if (!xServiceInfo
->supportsService("com.sun.star.text.TextFrame"))
750 bKeepRotation
= true;
751 xShapeProps
->setPropertyValue
752 (rPropNameSupplier
.GetName(PROP_TEXT_RANGE
),
754 (m_pImpl
->rDomainMapper
.GetCurrentTextRange()));
757 awt::Size
aSize(m_xShape
->getSize());
759 if (m_pImpl
->isXSizeValid())
760 aSize
.Width
= m_pImpl
->getXSize();
761 if (m_pImpl
->isYSizeValis())
762 aSize
.Height
= m_pImpl
->getYSize();
766 aRotation
= xShapeProps
->getPropertyValue("RotateAngle");
767 m_xShape
->setSize(aSize
);
769 xShapeProps
->setPropertyValue("RotateAngle", aRotation
);
771 m_pImpl
->bIsGraphic
= true;
773 if (!m_pImpl
->sAnchorId
.isEmpty())
775 putPropertyToFrameGrabBag("AnchorId", uno::makeAny(m_pImpl
->sAnchorId
));
779 if (bUseShape
&& m_pImpl
->eGraphicImportType
== IMPORT_AS_DETECTED_ANCHOR
)
781 // 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).
782 // But they aren't Writer pictures, either (which are already handled above).
783 uno::Reference
< beans::XPropertySet
> xShapeProps(m_xShape
, uno::UNO_QUERY_THROW
);
784 // This needs to be AT_PARAGRAPH and not AT_CHARACTER, otherwise shape will move when the user inserts a new paragraph.
785 xShapeProps
->setPropertyValue("AnchorType", uno::makeAny(text::TextContentAnchorType_AT_PARAGRAPH
));
787 //only the position orientation is handled in applyPosition()
788 m_pImpl
->applyPosition(xShapeProps
);
790 uno::Reference
<lang::XServiceInfo
> xServiceInfo(m_xShape
, uno::UNO_QUERY_THROW
);
791 if (xServiceInfo
->supportsService("com.sun.star.drawing.GroupShape") ||
792 xServiceInfo
->supportsService("com.sun.star.drawing.GraphicObjectShape"))
794 // Position of the groupshape should be set after children have been added.
795 // fdo#80555: also set position for graphic shapes here
796 m_xShape
->setPosition(awt::Point(m_pImpl
->nLeftPosition
, m_pImpl
->nTopPosition
));
798 m_pImpl
->applyRelativePosition(xShapeProps
);
800 m_pImpl
->applyMargins(xShapeProps
);
801 bool bOpaque
= m_pImpl
->bOpaque
&& !m_pImpl
->rDomainMapper
.IsInHeaderFooter();
802 xShapeProps
->setPropertyValue("Opaque", uno::makeAny(bOpaque
));
803 xShapeProps
->setPropertyValue("Surround", uno::makeAny(m_pImpl
->nWrap
));
804 m_pImpl
->applyZOrder(xShapeProps
);
805 m_pImpl
->applyName(xShapeProps
);
810 case NS_ooxml::LN_CT_Inline_distT
:
811 m_pImpl
->nTopMargin
= ConversionHelper::convertEMUToMM100(nIntValue
);
813 case NS_ooxml::LN_CT_Inline_distB
:
814 m_pImpl
->nBottomMargin
= ConversionHelper::convertEMUToMM100(nIntValue
);
816 case NS_ooxml::LN_CT_Inline_distL
:
817 m_pImpl
->nLeftMargin
= ConversionHelper::convertEMUToMM100(nIntValue
);
819 case NS_ooxml::LN_CT_Inline_distR
:
820 m_pImpl
->nRightMargin
= ConversionHelper::convertEMUToMM100(nIntValue
);
822 case NS_ooxml::LN_CT_GraphicalObjectData_uri
:
824 //TODO: does it need to be handled?
826 case NS_ooxml::LN_CT_SizeRelH_relativeFrom
:
830 case NS_ooxml::LN_ST_SizeRelFromH_margin
:
833 uno::Reference
<beans::XPropertySet
> xPropertySet(m_xShape
, uno::UNO_QUERY
);
834 xPropertySet
->setPropertyValue("RelativeWidthRelation", uno::makeAny(text::RelOrientation::FRAME
));
837 case NS_ooxml::LN_ST_SizeRelFromH_page
:
840 uno::Reference
<beans::XPropertySet
> xPropertySet(m_xShape
, uno::UNO_QUERY
);
841 xPropertySet
->setPropertyValue("RelativeWidthRelation", uno::makeAny(text::RelOrientation::PAGE_FRAME
));
845 SAL_WARN("writerfilter", "GraphicImport::lcl_attribute: unhandled NS_ooxml::LN_CT_SizeRelH_relativeFrom value: " << nIntValue
);
850 case NS_ooxml::LN_CT_SizeRelV_relativeFrom
:
854 case NS_ooxml::LN_ST_SizeRelFromV_margin
:
857 uno::Reference
<beans::XPropertySet
> xPropertySet(m_xShape
, uno::UNO_QUERY
);
858 xPropertySet
->setPropertyValue("RelativeHeightRelation", uno::makeAny(text::RelOrientation::FRAME
));
861 case NS_ooxml::LN_ST_SizeRelFromV_page
:
864 uno::Reference
<beans::XPropertySet
> xPropertySet(m_xShape
, uno::UNO_QUERY
);
865 xPropertySet
->setPropertyValue("RelativeHeightRelation", uno::makeAny(text::RelOrientation::PAGE_FRAME
));
869 SAL_WARN("writerfilter", "GraphicImport::lcl_attribute: unhandled NS_ooxml::LN_CT_SizeRelV_relativeFrom value: " << nIntValue
);
875 #ifdef DEBUG_DMAPPER_GRAPHIC_IMPORT
876 dmapper_logger
->element("unhandled");
882 uno::Reference
<text::XTextContent
> GraphicImport::GetGraphicObject()
884 uno::Reference
<text::XTextContent
> xResult
;
886 if (m_xGraphicObject
.is())
887 xResult
= m_xGraphicObject
;
888 else if (m_xShape
.is())
890 xResult
.set(m_xShape
, uno::UNO_QUERY_THROW
);
896 uno::Reference
<drawing::XShape
> GraphicImport::GetXShapeObject(){
900 void GraphicImport::ProcessShapeOptions(Value
& rValue
)
902 sal_Int32 nIntValue
= rValue
.getInt();
903 switch( m_pImpl
->nShapeOptionType
)
905 case NS_ooxml::LN_CT_Anchor_distL
:
906 //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustLRWrapForWordMargins()
907 m_pImpl
->nLeftMargin
= nIntValue
/ 360;
909 case NS_ooxml::LN_CT_Anchor_distT
:
910 //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustULWrapForWordMargins()
911 m_pImpl
->nTopMargin
= nIntValue
/ 360;
913 case NS_ooxml::LN_CT_Anchor_distR
:
914 //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustLRWrapForWordMargins()
915 m_pImpl
->nRightMargin
= nIntValue
/ 360;
917 case NS_ooxml::LN_CT_Anchor_distB
:
918 //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustULWrapForWordMargins()
919 m_pImpl
->nBottomMargin
= nIntValue
/ 360;
922 OSL_FAIL( "shape option unsupported?");
927 void GraphicImport::lcl_sprm(Sprm
& rSprm
)
929 sal_uInt32 nSprmId
= rSprm
.getId();
930 Value::Pointer_t pValue
= rSprm
.getValue();
934 case 0xf004: //dff record
935 case 0xf00a: //part of 0xf004 - shape properties
936 case 0xf00b: //part of 0xf004
938 case 0xf122: //udefprop
939 case NS_ooxml::LN_CT_Inline_extent
: // 90911;
940 case NS_ooxml::LN_CT_Inline_effectExtent
: // 90912;
941 case NS_ooxml::LN_CT_Inline_docPr
: // 90913;
942 case NS_ooxml::LN_CT_Inline_cNvGraphicFramePr
: // 90914;
943 case NS_ooxml::LN_CT_NonVisualGraphicFrameProperties_graphicFrameLocks
:// 90657
944 case NS_ooxml::LN_CT_Inline_a_graphic
:// 90915
945 case NS_ooxml::LN_CT_Anchor_simplePos_elem
: // 90975;
946 case NS_ooxml::LN_CT_Anchor_extent
: // 90978;
947 case NS_ooxml::LN_CT_Anchor_effectExtent
: // 90979;
948 case NS_ooxml::LN_EG_WrapType_wrapSquare
: // 90945;
949 case NS_ooxml::LN_EG_WrapType_wrapTight
: // 90946;
950 case NS_ooxml::LN_EG_WrapType_wrapThrough
:
951 case NS_ooxml::LN_CT_Anchor_docPr
: // 90980;
952 case NS_ooxml::LN_CT_Anchor_cNvGraphicFramePr
: // 90981;
953 case NS_ooxml::LN_CT_Anchor_a_graphic
: // 90982;
954 case NS_ooxml::LN_CT_WrapPath_start
: // 90924;
955 case NS_ooxml::LN_CT_WrapPath_lineTo
: // 90925;
956 case NS_ooxml::LN_graphic_graphic
:
957 case NS_ooxml::LN_pic_pic
:
958 case NS_ooxml::LN_dgm_relIds
:
959 case NS_ooxml::LN_lc_lockedCanvas
:
960 case NS_ooxml::LN_c_chart
:
961 case NS_ooxml::LN_wps_wsp
:
962 case NS_ooxml::LN_wpg_wgp
:
963 case NS_ooxml::LN_sizeRelH_sizeRelH
:
964 case NS_ooxml::LN_sizeRelV_sizeRelV
:
965 case NS_ooxml::LN_hlinkClick_hlinkClick
:
967 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
968 if( pProperties
.get())
970 pProperties
->resolve(*this);
974 case NS_ooxml::LN_CT_WrapTight_wrapPolygon
:
975 case NS_ooxml::LN_CT_WrapThrough_wrapPolygon
:
977 WrapPolygonHandler aHandler
;
979 resolveSprmProps(aHandler
, rSprm
);
981 m_pImpl
->mpWrapPolygon
= aHandler
.getPolygon();
984 case NS_ooxml::LN_CT_Anchor_positionH
: // 90976;
986 // Use a special handler for the positionning
987 PositionHandlerPtr
pHandler( new PositionHandler( false ));
988 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
989 if( pProperties
.get( ) )
991 pProperties
->resolve( *pHandler
);
992 if( !m_pImpl
->bUseSimplePos
)
994 m_pImpl
->nHoriRelation
= pHandler
->relation();
995 m_pImpl
->nHoriOrient
= pHandler
->orientation();
996 m_pImpl
->nLeftPosition
= pHandler
->position();
997 if (m_pImpl
->nHoriRelation
== text::RelOrientation::PAGE_FRAME
&& m_pImpl
->nHoriOrient
== text::HoriOrientation::RIGHT
)
999 // If the shape is relative from page and aligned to
1000 // right, then set the relation to right and clear the
1001 // orientation, that provides the same visual result as
1003 m_pImpl
->nHoriRelation
= text::RelOrientation::PAGE_RIGHT
;
1004 m_pImpl
->nHoriOrient
= text::HoriOrientation::NONE
;
1010 case NS_ooxml::LN_CT_Anchor_positionV
: // 90977;
1012 // Use a special handler for the positionning
1013 PositionHandlerPtr
pHandler( new PositionHandler( true ));
1014 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
1015 if( pProperties
.get( ) )
1017 pProperties
->resolve( *pHandler
);
1018 if( !m_pImpl
->bUseSimplePos
)
1020 m_pImpl
->nVertRelation
= pHandler
->relation();
1021 m_pImpl
->nVertOrient
= pHandler
->orientation();
1022 m_pImpl
->nTopPosition
= pHandler
->position();
1027 case NS_ooxml::LN_CT_SizeRelH_pctWidth
:
1028 case NS_ooxml::LN_CT_SizeRelV_pctHeight
:
1029 if (m_xShape
.is() && !m_pImpl
->m_rPositivePercentages
.empty())
1031 sal_Int16 nPositivePercentage
= rtl::math::round(m_pImpl
->m_rPositivePercentages
.front().toDouble() / oox::drawingml::PER_PERCENT
);
1032 m_pImpl
->m_rPositivePercentages
.pop();
1034 if (nPositivePercentage
)
1036 uno::Reference
<beans::XPropertySet
> xPropertySet(m_xShape
, uno::UNO_QUERY
);
1037 OUString aProperty
= nSprmId
== NS_ooxml::LN_CT_SizeRelH_pctWidth
? OUString("RelativeWidth") : OUString("RelativeHeight");
1038 xPropertySet
->setPropertyValue(aProperty
, uno::makeAny(nPositivePercentage
));
1045 if( nSprmId
!= 0x271c || m_pImpl
->nDffType
== 0xf01f || m_pImpl
->nDffType
== 0xf01e )
1047 writerfilter::Reference
<BinaryObj
>::Pointer_t pPictureData
= rSprm
.getBinary();
1048 if( pPictureData
.get())
1049 pPictureData
->resolve(*this);
1053 case NS_ooxml::LN_EG_WrapType_wrapNone
: // 90944; - doesn't contain attributes
1054 //depending on the behindDoc attribute text wraps through behind or in fron of the object
1055 m_pImpl
->nWrap
= text::WrapTextMode_THROUGHT
;
1057 case NS_ooxml::LN_EG_WrapType_wrapTopAndBottom
: // 90948;
1058 m_pImpl
->nWrap
= text::WrapTextMode_NONE
;
1062 //ignore - doesn't contain useful members
1064 case NS_ooxml::LN_CT_GraphicalObject_graphicData
:// 90660;
1066 m_pImpl
->bIsGraphic
= true;
1068 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
1069 if( pProperties
.get())
1070 pProperties
->resolve(*this);
1074 #if OSL_DEBUG_LEVEL > 0
1075 OString
sMessage( "GraphicImport::sprm() - Id: ");
1076 sMessage
+= OString::number( nSprmId
, 10 );
1077 sMessage
+= " / 0x";
1078 sMessage
+= OString::number( nSprmId
, 16 );
1079 SAL_WARN("writerfilter", sMessage
.getStr());
1085 void GraphicImport::lcl_entry(int /*pos*/, writerfilter::Reference
<Properties
>::Pointer_t
/*ref*/)
1088 /*-------------------------------------------------------------------------
1089 crop is stored as "fixed float" as 16.16 fraction value
1090 related to width/or height
1091 -----------------------------------------------------------------------*/
1092 void lcl_CalcCrop( sal_Int32
& nCrop
, sal_Int32 nRef
)
1094 nCrop
= ((nCrop
>> 16 ) * nRef
)
1095 + (((nCrop
& 0xffff) * nRef
) >> 16);
1098 uno::Reference
< text::XTextContent
> GraphicImport::createGraphicObject( const beans::PropertyValues
& aMediaProperties
, const uno::Reference
<beans::XPropertySet
>& xShapeProps
)
1100 uno::Reference
< text::XTextContent
> xGraphicObject
;
1103 uno::Reference
< graphic::XGraphicProvider
> xGraphicProvider( graphic::GraphicProvider::create(m_xComponentContext
) );
1104 uno::Reference
< graphic::XGraphic
> xGraphic
= xGraphicProvider
->queryGraphic( aMediaProperties
);
1108 PropertyNameSupplier
& rPropNameSupplier
= PropertyNameSupplier::GetPropertyNameSupplier();
1110 uno::Reference
< beans::XPropertySet
> xGraphicObjectProperties(
1111 m_xTextFactory
->createInstance("com.sun.star.text.TextGraphicObject"),
1112 uno::UNO_QUERY_THROW
);
1113 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName(PROP_GRAPHIC
), uno::makeAny( xGraphic
));
1114 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName(PROP_ANCHOR_TYPE
),
1115 uno::makeAny( m_pImpl
->eGraphicImportType
== IMPORT_AS_SHAPE
|| m_pImpl
->eGraphicImportType
== IMPORT_AS_DETECTED_ANCHOR
?
1116 text::TextContentAnchorType_AT_CHARACTER
:
1117 text::TextContentAnchorType_AS_CHARACTER
));
1118 xGraphicObject
= uno::Reference
< text::XTextContent
>( xGraphicObjectProperties
, uno::UNO_QUERY_THROW
);
1120 //shapes have only one border, PICF might have four
1121 table::BorderLine2 aBorderLine
;
1122 for( sal_Int32 nBorder
= 0; nBorder
< 4; ++nBorder
)
1124 if( m_pImpl
->eGraphicImportType
== IMPORT_AS_GRAPHIC
|| !nBorder
)
1126 GraphicBorderLine
& rBorderLine
= m_pImpl
->aBorders
[m_pImpl
->eGraphicImportType
== IMPORT_AS_SHAPE
? BORDER_TOP
: static_cast<BorderPosition
>(nBorder
)];
1127 if (rBorderLine
.isEmpty() && xShapeProps
.is() && xShapeProps
->getPropertyValue("LineStyle").get
<drawing::LineStyle
>() != drawing::LineStyle_NONE
)
1129 // In case we got no border tokens and we have the
1130 // original shape, then use its line properties as the
1132 aBorderLine
.Color
= xShapeProps
->getPropertyValue("LineColor").get
<sal_Int32
>();
1133 aBorderLine
.LineWidth
= xShapeProps
->getPropertyValue("LineWidth").get
<sal_Int32
>();
1137 aBorderLine
.Color
= m_pImpl
->aBorders
[m_pImpl
->eGraphicImportType
== IMPORT_AS_SHAPE
? BORDER_TOP
: static_cast<BorderPosition
>(nBorder
) ].nLineColor
;
1138 aBorderLine
.InnerLineWidth
= 0;
1139 aBorderLine
.OuterLineWidth
= (sal_Int16
)m_pImpl
->aBorders
[m_pImpl
->eGraphicImportType
== IMPORT_AS_SHAPE
? BORDER_TOP
: static_cast<BorderPosition
>(nBorder
) ].nLineWidth
;
1140 aBorderLine
.LineDistance
= 0;
1143 PropertyIds aBorderProps
[4] =
1150 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( aBorderProps
[nBorder
]), uno::makeAny(aBorderLine
));
1153 // setting graphic object shadow proerties
1154 if (m_pImpl
->bShadow
)
1156 // Shadow width is approximated by average of X and Y
1157 table::ShadowFormat aShadow
;
1158 sal_uInt32 nShadowColor
= m_pImpl
->nShadowColor
& 0x00FFFFFF; // The shadow color we get is RGB only.
1159 sal_Int32 nShadowWidth
= (abs(m_pImpl
->nShadowXDistance
)
1160 + abs(m_pImpl
->nShadowYDistance
)) / 2;
1162 aShadow
.ShadowWidth
= nShadowWidth
;
1163 sal_uInt8 nShadowTransparence
= float(m_pImpl
->nShadowTransparence
) * 2.55;
1164 nShadowColor
|= (nShadowTransparence
<< 24); // Add transparence to the color.
1165 aShadow
.Color
= nShadowColor
;
1166 // Distances -ve for top and right, +ve for bottom and left
1167 if (m_pImpl
->nShadowXDistance
> 0)
1169 if (m_pImpl
->nShadowYDistance
> 0)
1170 aShadow
.Location
= com::sun::star::table::ShadowLocation_BOTTOM_RIGHT
;
1172 aShadow
.Location
= com::sun::star::table::ShadowLocation_TOP_RIGHT
;
1176 if (m_pImpl
->nShadowYDistance
> 0)
1177 aShadow
.Location
= com::sun::star::table::ShadowLocation_BOTTOM_LEFT
;
1179 aShadow
.Location
= com::sun::star::table::ShadowLocation_TOP_LEFT
;
1182 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName(PROP_SHADOW_FORMAT
), uno::makeAny(aShadow
));
1185 // setting properties for all types
1186 if( m_pImpl
->bPositionProtected
)
1187 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_POSITION_PROTECTED
),
1188 uno::makeAny(true));
1189 if( m_pImpl
->bSizeProtected
)
1190 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_SIZE_PROTECTED
),
1191 uno::makeAny(true));
1193 if( m_pImpl
->eGraphicImportType
== IMPORT_AS_SHAPE
|| m_pImpl
->eGraphicImportType
== IMPORT_AS_DETECTED_ANCHOR
)
1195 sal_Int32 nWidth
= m_pImpl
->nRightPosition
- m_pImpl
->nLeftPosition
;
1196 if( m_pImpl
->eGraphicImportType
== IMPORT_AS_SHAPE
)
1198 sal_Int32 nHeight
= m_pImpl
->nBottomPosition
- m_pImpl
->nTopPosition
;
1199 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName(PROP_SIZE
),
1200 uno::makeAny( awt::Size( nWidth
, nHeight
)));
1203 if( (m_pImpl
->nHoriOrient
== text::HoriOrientation::LEFT
&&
1204 (m_pImpl
->nHoriRelation
== text::RelOrientation::PAGE_PRINT_AREA
||
1205 m_pImpl
->nHoriRelation
== text::RelOrientation::FRAME
) ) ||
1206 (m_pImpl
->nHoriOrient
== text::HoriOrientation::INSIDE
&&
1207 m_pImpl
->nHoriRelation
== text::RelOrientation::PAGE_PRINT_AREA
))
1208 m_pImpl
->nLeftMargin
= 0;
1209 if((m_pImpl
->nHoriOrient
== text::HoriOrientation::RIGHT
&&
1210 (m_pImpl
->nHoriRelation
== text::RelOrientation::PAGE_PRINT_AREA
||
1211 m_pImpl
->nHoriRelation
== text::RelOrientation::FRAME
) ) ||
1212 (m_pImpl
->nHoriOrient
== text::HoriOrientation::INSIDE
&&
1213 m_pImpl
->nHoriRelation
== text::RelOrientation::PAGE_PRINT_AREA
))
1214 m_pImpl
->nRightMargin
= 0;
1215 // adjust top/bottom margins
1216 if( m_pImpl
->nVertOrient
== text::VertOrientation::TOP
&&
1217 ( m_pImpl
->nVertRelation
== text::RelOrientation::PAGE_PRINT_AREA
||
1218 m_pImpl
->nVertRelation
== text::RelOrientation::PAGE_FRAME
))
1219 m_pImpl
->nTopMargin
= 0;
1220 if( m_pImpl
->nVertOrient
== text::VertOrientation::BOTTOM
&&
1221 ( m_pImpl
->nVertRelation
== text::RelOrientation::PAGE_PRINT_AREA
||
1222 m_pImpl
->nVertRelation
== text::RelOrientation::PAGE_FRAME
))
1223 m_pImpl
->nBottomMargin
= 0;
1224 if( m_pImpl
->nVertOrient
== text::VertOrientation::BOTTOM
&&
1225 m_pImpl
->nVertRelation
== text::RelOrientation::PAGE_PRINT_AREA
)
1226 m_pImpl
->nBottomMargin
= 0;
1229 if( m_pImpl
->nHoriOrient
== text::HoriOrientation::INSIDE
&&
1230 m_pImpl
->nHoriRelation
== text::RelOrientation::PAGE_FRAME
)
1232 // convert 'left to page' to 'from left -<width> to page text area'
1233 m_pImpl
->nHoriOrient
= text::HoriOrientation::NONE
;
1234 m_pImpl
->nHoriRelation
= text::RelOrientation::PAGE_PRINT_AREA
;
1235 m_pImpl
->nLeftPosition
= - nWidth
;
1237 else if( m_pImpl
->nHoriOrient
== text::HoriOrientation::OUTSIDE
&&
1238 m_pImpl
->nHoriRelation
== text::RelOrientation::PAGE_FRAME
)
1240 // convert 'right to page' to 'from left 0 to right page border'
1241 m_pImpl
->nHoriOrient
= text::HoriOrientation::NONE
;
1242 m_pImpl
->nHoriRelation
= text::RelOrientation::PAGE_RIGHT
;
1243 m_pImpl
->nLeftPosition
= 0;
1246 m_pImpl
->applyPosition(xGraphicObjectProperties
);
1247 m_pImpl
->applyRelativePosition(xGraphicObjectProperties
);
1248 bool bOpaque
= m_pImpl
->bOpaque
&& !m_pImpl
->rDomainMapper
.IsInHeaderFooter( );
1251 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_OPAQUE
),
1252 uno::makeAny(bOpaque
));
1254 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_SURROUND
),
1255 uno::makeAny(m_pImpl
->nWrap
));
1256 if( m_pImpl
->bLayoutInCell
&& m_pImpl
->nWrap
!= text::WrapTextMode_THROUGHT
)
1257 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_FOLLOW_TEXT_FLOW
),
1258 uno::makeAny(true));
1260 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_SURROUND_CONTOUR
),
1261 uno::makeAny(m_pImpl
->bContour
));
1262 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_CONTOUR_OUTSIDE
),
1263 uno::makeAny(m_pImpl
->bContourOutside
));
1264 m_pImpl
->applyMargins(xGraphicObjectProperties
);
1266 if( m_pImpl
->eColorMode
== drawing::ColorMode_STANDARD
&&
1267 m_pImpl
->nContrast
== -70 &&
1268 m_pImpl
->nBrightness
== 70 )
1270 // strange definition of WATERMARK!
1271 m_pImpl
->nContrast
= 0;
1272 m_pImpl
->nBrightness
= 0;
1273 m_pImpl
->eColorMode
= drawing::ColorMode_WATERMARK
;
1276 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_ADJUST_CONTRAST
),
1277 uno::makeAny((sal_Int16
)m_pImpl
->nContrast
));
1278 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_ADJUST_LUMINANCE
),
1279 uno::makeAny((sal_Int16
)m_pImpl
->nBrightness
));
1280 if(m_pImpl
->eColorMode
!= drawing::ColorMode_STANDARD
)
1281 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_GRAPHIC_COLOR_MODE
),
1282 uno::makeAny(m_pImpl
->eColorMode
));
1283 if(m_pImpl
->fGamma
> 0. )
1284 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_GAMMA
),
1285 uno::makeAny(m_pImpl
->fGamma
));
1286 if(m_pImpl
->bHoriFlip
)
1288 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_HORI_MIRRORED_ON_EVEN_PAGES
),
1289 uno::makeAny( m_pImpl
->bHoriFlip
));
1290 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_HORI_MIRRORED_ON_ODD_PAGES
),
1291 uno::makeAny( m_pImpl
->bHoriFlip
));
1294 if( m_pImpl
->bVertFlip
)
1295 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_VERT_MIRRORED
),
1296 uno::makeAny( m_pImpl
->bVertFlip
));
1297 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_BACK_COLOR
),
1298 uno::makeAny( m_pImpl
->nFillColor
));
1300 m_pImpl
->applyZOrder(xGraphicObjectProperties
);
1302 //there seems to be no way to detect the original size via _real_ API
1303 uno::Reference
< beans::XPropertySet
> xGraphicProperties( xGraphic
, uno::UNO_QUERY_THROW
);
1304 awt::Size aGraphicSize
, aGraphicSizePixel
;
1305 xGraphicProperties
->getPropertyValue(rPropNameSupplier
.GetName( PROP_SIZE100th_M_M
)) >>= aGraphicSize
;
1306 xGraphicProperties
->getPropertyValue(rPropNameSupplier
.GetName( PROP_SIZE_PIXEL
)) >>= aGraphicSizePixel
;
1308 uno::Any aContourPolyPolygon
;
1309 if( aGraphicSize
.Width
&& aGraphicSize
.Height
&&
1310 m_pImpl
->mpWrapPolygon
.get() != NULL
)
1312 WrapPolygon::Pointer_t pCorrected
= m_pImpl
->mpWrapPolygon
->correctWordWrapPolygon(aGraphicSize
);
1313 aContourPolyPolygon
<<= pCorrected
->getPointSequenceSequence();
1316 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_CONTOUR_POLY_POLYGON
),
1317 aContourPolyPolygon
);
1319 if( aGraphicSize
.Width
&& aGraphicSize
.Height
)
1321 //todo: i71651 graphic size is not provided by the GraphicDescriptor
1322 lcl_CalcCrop( m_pImpl
->nTopCrop
, aGraphicSize
.Height
);
1323 lcl_CalcCrop( m_pImpl
->nBottomCrop
, aGraphicSize
.Height
);
1324 lcl_CalcCrop( m_pImpl
->nLeftCrop
, aGraphicSize
.Width
);
1325 lcl_CalcCrop( m_pImpl
->nRightCrop
, aGraphicSize
.Width
);
1328 // We need a separate try-catch here, otherwise a bad crop setting will also nuke the size settings as well.
1331 xGraphicProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_GRAPHIC_CROP
),
1332 uno::makeAny(text::GraphicCrop(m_pImpl
->nTopCrop
, m_pImpl
->nBottomCrop
, m_pImpl
->nLeftCrop
, m_pImpl
->nRightCrop
)));
1334 catch (const uno::Exception
& e
)
1336 SAL_WARN("writerfilter", "failed. Message :" << e
.Message
);
1342 if(m_pImpl
->eGraphicImportType
== IMPORT_AS_DETECTED_INLINE
|| m_pImpl
->eGraphicImportType
== IMPORT_AS_DETECTED_ANCHOR
)
1344 if( m_pImpl
->getXSize() && m_pImpl
->getYSize() )
1345 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName(PROP_SIZE
),
1346 uno::makeAny( awt::Size( m_pImpl
->getXSize(), m_pImpl
->getYSize() )));
1347 m_pImpl
->applyMargins(xGraphicObjectProperties
);
1348 m_pImpl
->applyName(xGraphicObjectProperties
);
1352 catch( const uno::Exception
& e
)
1354 SAL_WARN("writerfilter", "failed. Message :" << e
.Message
);
1356 return xGraphicObject
;
1361 void GraphicImport::data(const sal_uInt8
* buf
, size_t len
, writerfilter::Reference
<Properties
>::Pointer_t
/*ref*/)
1363 PropertyNameSupplier
& rPropNameSupplier
= PropertyNameSupplier::GetPropertyNameSupplier();
1365 ::com::sun::star::beans::PropertyValues
aMediaProperties( 1 );
1366 aMediaProperties
[0].Name
= rPropNameSupplier
.GetName(PROP_INPUT_STREAM
);
1368 uno::Reference
< io::XInputStream
> xIStream
= new XInputStreamHelper( buf
, len
, m_pImpl
->bIsBitmap
);
1369 aMediaProperties
[0].Value
<<= xIStream
;
1371 uno::Reference
<beans::XPropertySet
> xPropertySet
;
1372 m_xGraphicObject
= createGraphicObject( aMediaProperties
, xPropertySet
);
1376 void GraphicImport::lcl_startSectionGroup()
1381 void GraphicImport::lcl_endSectionGroup()
1386 void GraphicImport::lcl_startParagraphGroup()
1391 void GraphicImport::lcl_endParagraphGroup()
1396 void GraphicImport::lcl_startCharacterGroup()
1401 void GraphicImport::lcl_endCharacterGroup()
1406 void GraphicImport::lcl_text(const sal_uInt8
* /*_data*/, size_t /*len*/)
1411 void GraphicImport::lcl_utext(const sal_uInt8
* /*_data*/, size_t /*len*/)
1416 void GraphicImport::lcl_props(writerfilter::Reference
<Properties
>::Pointer_t
/*ref*/)
1421 void GraphicImport::lcl_table(Id
/*name*/, writerfilter::Reference
<Table
>::Pointer_t
/*ref*/)
1426 void GraphicImport::lcl_substream(Id
/*name*/, ::writerfilter::Reference
<Stream
>::Pointer_t
/*ref*/)
1431 void GraphicImport::lcl_info(const string
& /*info*/)
1435 void GraphicImport::lcl_startShape( ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
> /*xShape*/ )
1439 void GraphicImport::lcl_endShape( )
1443 bool GraphicImport::IsGraphic() const
1445 return m_pImpl
->bIsGraphic
;
1451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */