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