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/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/table/BorderLine2.hpp>
33 #include <com/sun/star/text/GraphicCrop.hpp>
34 #include <com/sun/star/text/HoriOrientation.hpp>
35 #include <com/sun/star/text/RelOrientation.hpp>
36 #include <com/sun/star/text/TextContentAnchorType.hpp>
37 #include <com/sun/star/text/VertOrientation.hpp>
38 #include <com/sun/star/text/WrapTextMode.hpp>
39 #include <com/sun/star/text/XTextContent.hpp>
40 #include <com/sun/star/uno/XComponentContext.hpp>
41 #include <com/sun/star/table/ShadowFormat.hpp>
43 #include <cppuhelper/implbase1.hxx>
44 #include <rtl/ustrbuf.hxx>
46 #include <dmapper/DomainMapper.hxx>
47 #include <doctok/resourceids.hxx>
48 #include <ooxml/resourceids.hxx>
49 #include <resourcemodel/ResourceModelHelper.hxx>
51 #include "ConversionHelper.hxx"
52 #include "GraphicHelpers.hxx"
53 #include "GraphicImport.hxx"
54 #include "PropertyMap.hxx"
55 #include "WrapPolygonHandler.hxx"
56 #include "dmapperLoggers.hxx"
58 namespace writerfilter
{
60 using resourcemodel::resolveSprmProps
;
64 using namespace ::std
;
65 using namespace ::com::sun::star
;
67 class XInputStreamHelper
: public cppu::WeakImplHelper1
70 const sal_uInt8
* m_pBuffer
;
71 const sal_Int32 m_nLength
;
72 sal_Int32 m_nPosition
;
75 const sal_uInt8
* m_pBMPHeader
; //default BMP-header
76 sal_Int32 m_nHeaderLength
;
78 XInputStreamHelper(const sal_uInt8
* buf
, size_t len
, bool bBmp
);
79 ~XInputStreamHelper();
81 virtual ::sal_Int32 SAL_CALL
readBytes( uno::Sequence
< ::sal_Int8
>& aData
, ::sal_Int32 nBytesToRead
) throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
);
82 virtual ::sal_Int32 SAL_CALL
readSomeBytes( uno::Sequence
< ::sal_Int8
>& aData
, ::sal_Int32 nMaxBytesToRead
) throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
);
83 virtual void SAL_CALL
skipBytes( ::sal_Int32 nBytesToSkip
) throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
);
84 virtual ::sal_Int32 SAL_CALL
available( ) throw (io::NotConnectedException
, io::IOException
, uno::RuntimeException
);
85 virtual void SAL_CALL
closeInput( ) throw (io::NotConnectedException
, io::IOException
, uno::RuntimeException
);
89 XInputStreamHelper::XInputStreamHelper(const sal_uInt8
* buf
, size_t len
, bool bBmp
) :
95 static const sal_uInt8 aHeader
[] =
96 {0x42, 0x4d, 0xe6, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
97 m_pBMPHeader
= aHeader
;
98 m_nHeaderLength
= m_bBmp
? sizeof( aHeader
) / sizeof(sal_uInt8
) : 0;
103 XInputStreamHelper::~XInputStreamHelper()
108 ::sal_Int32
XInputStreamHelper::readBytes( uno::Sequence
< ::sal_Int8
>& aData
, ::sal_Int32 nBytesToRead
)
109 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
)
111 return readSomeBytes( aData
, nBytesToRead
);
115 ::sal_Int32
XInputStreamHelper::readSomeBytes( uno::Sequence
< ::sal_Int8
>& aData
, ::sal_Int32 nMaxBytesToRead
)
116 throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
)
119 if( nMaxBytesToRead
> 0 )
121 if( nMaxBytesToRead
> (m_nLength
+ m_nHeaderLength
) - m_nPosition
)
122 nRet
= (m_nLength
+ m_nHeaderLength
) - m_nPosition
;
124 nRet
= nMaxBytesToRead
;
125 aData
.realloc( nRet
);
126 sal_Int8
* pData
= aData
.getArray();
127 sal_Int32 nHeaderRead
= 0;
128 if( m_nPosition
< m_nHeaderLength
)
130 //copy header content first
131 nHeaderRead
= m_nHeaderLength
- m_nPosition
;
132 memcpy( pData
, m_pBMPHeader
+ (m_nPosition
), nHeaderRead
);
134 m_nPosition
+= nHeaderRead
;
138 memcpy( pData
+ nHeaderRead
, m_pBuffer
+ (m_nPosition
- m_nHeaderLength
), nRet
);
146 void XInputStreamHelper::skipBytes( ::sal_Int32 nBytesToSkip
) throw (io::NotConnectedException
, io::BufferSizeExceededException
, io::IOException
, uno::RuntimeException
)
148 if( nBytesToSkip
< 0 || m_nPosition
+ nBytesToSkip
> (m_nLength
+ m_nHeaderLength
))
149 throw io::BufferSizeExceededException();
150 m_nPosition
+= nBytesToSkip
;
154 ::sal_Int32
XInputStreamHelper::available( ) throw (io::NotConnectedException
, io::IOException
, uno::RuntimeException
)
156 return ( m_nLength
+ m_nHeaderLength
) - m_nPosition
;
160 void XInputStreamHelper::closeInput( ) throw (io::NotConnectedException
, io::IOException
, uno::RuntimeException
)
165 struct GraphicBorderLine
167 sal_Int32 nLineWidth
;
168 sal_Int32 nLineColor
;
169 sal_Int32 nLineDistance
;
172 GraphicBorderLine() :
181 class GraphicImport_Impl
190 GraphicImportType eGraphicImportType
;
191 DomainMapper
& rDomainMapper
;
193 sal_Int32 nHoriScaling
;
194 sal_Int32 nVertScaling
;
195 sal_Int32 nLeftPosition
;
196 sal_Int32 nTopPosition
;
197 sal_Int32 nRightPosition
;
198 sal_Int32 nBottomPosition
;
201 sal_Int32 nRightCrop
;
202 sal_Int32 nBottomCrop
;
207 sal_Int16 nHoriOrient
;
208 sal_Int16 nHoriRelation
;
210 sal_Int16 nVertOrient
;
211 sal_Int16 nVertRelation
;
215 bool bContourOutside
;
216 WrapPolygon::Pointer_t mpWrapPolygon
;
219 sal_Int32 nLeftMargin
;
220 sal_Int32 nRightMargin
;
221 sal_Int32 nTopMargin
;
222 sal_Int32 nBottomMargin
;
225 sal_Int32 nShadowXDistance
;
226 sal_Int32 nShadowYDistance
;
227 sal_Int32 nShadowColor
;
228 sal_Int32 nShadowTransparence
;
231 sal_Int32 nBrightness
;
234 sal_Int32 nFillColor
;
236 drawing::ColorMode eColorMode
;
238 GraphicBorderLine aBorders
[4];
239 sal_Int32 nCurrentBorderLine
;
245 sal_Int32 nBitsPerPixel
;
251 bool bPositionProtected
;
253 bool bInShapeOptionMode
;
254 sal_Int32 nShapeOptionType
;
257 OUString sAlternativeText
;
260 GraphicImport_Impl(GraphicImportType eImportType
, DomainMapper
& rDMapper
) :
265 ,eGraphicImportType( eImportType
)
266 ,rDomainMapper( rDMapper
)
277 ,bUseSimplePos(false)
279 ,nHoriOrient( text::HoriOrientation::NONE
)
280 ,nHoriRelation( text::RelOrientation::FRAME
)
281 ,bPageToggle( false )
282 ,nVertOrient( text::VertOrientation::NONE
)
283 ,nVertRelation( text::RelOrientation::FRAME
)
287 ,bContourOutside(true)
297 ,nShadowTransparence(0)
301 ,nFillColor( 0xffffffff )
302 ,eColorMode( drawing::ColorMode_STANDARD
)
303 ,nCurrentBorderLine(BORDER_TOP
)
311 ,bSizeProtected(false)
312 ,bPositionProtected(false)
313 ,bInShapeOptionMode(false)
316 void setXSize(sal_Int32 _nXSize
)
322 sal_uInt32
getXSize() const
327 bool isXSizeValid() const
332 void setYSize(sal_Int32 _nYSize
)
338 sal_uInt32
getYSize() const
343 bool isYSizeValis () const
348 void applyMargins(uno::Reference
< beans::XPropertySet
> xGraphicObjectProperties
) const
350 PropertyNameSupplier
& rPropNameSupplier
= PropertyNameSupplier::GetPropertyNameSupplier();
351 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_LEFT_MARGIN
), uno::makeAny(nLeftMargin
));
352 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_RIGHT_MARGIN
), uno::makeAny(nRightMargin
));
353 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_TOP_MARGIN
), uno::makeAny(nTopMargin
));
354 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_BOTTOM_MARGIN
), uno::makeAny(nBottomMargin
));
359 GraphicImport::GraphicImport(uno::Reference
< uno::XComponentContext
> xComponentContext
,
360 uno::Reference
< lang::XMultiServiceFactory
> xTextFactory
,
361 DomainMapper
& rDMapper
,
362 GraphicImportType eImportType
)
363 : LoggedProperties(dmapper_logger
, "GraphicImport")
364 , LoggedTable(dmapper_logger
, "GraphicImport")
365 , LoggedStream(dmapper_logger
, "GraphicImport")
366 , m_pImpl( new GraphicImport_Impl( eImportType
, rDMapper
))
367 , m_xComponentContext( xComponentContext
)
368 , m_xTextFactory( xTextFactory
)
373 GraphicImport::~GraphicImport()
378 void GraphicImport::handleWrapTextValue(sal_uInt32 nVal
)
382 case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_bothSides
: // 90920;
383 m_pImpl
->nWrap
= text::WrapTextMode_PARALLEL
;
385 case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_left
: // 90921;
386 m_pImpl
->nWrap
= text::WrapTextMode_LEFT
;
388 case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_right
: // 90922;
389 m_pImpl
->nWrap
= text::WrapTextMode_RIGHT
;
391 case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_largest
: // 90923;
392 m_pImpl
->nWrap
= text::WrapTextMode_DYNAMIC
;
400 void GraphicImport::lcl_attribute(Id nName
, Value
& val
)
402 sal_Int32 nIntValue
= val
.getInt();
405 case NS_rtf::LN_LCB
: break;//byte count
406 case NS_rtf::LN_CBHEADER
: break;//ignored
407 case NS_rtf::LN_MFP
: //MetafilePict
408 case NS_rtf::LN_DffRecord
: //dff record - expands to an sprm which expands to ...
409 case NS_rtf::LN_shpopt
: //shape options
410 case NS_rtf::LN_shpfbse
: //BLIP store entry
411 case NS_rtf::LN_BRCTOP
: //top border
412 case NS_rtf::LN_BRCLEFT
: //left border
413 case NS_rtf::LN_BRCBOTTOM
: //bottom border
414 case NS_rtf::LN_BRCRIGHT
: //right border
415 case NS_rtf::LN_shape
: //shape
416 case NS_rtf::LN_blip
: //the binary graphic data in a shape
420 case NS_rtf::LN_BRCTOP
: //top border
421 m_pImpl
->nCurrentBorderLine
= BORDER_TOP
;
423 case NS_rtf::LN_BRCLEFT
: //left border
424 m_pImpl
->nCurrentBorderLine
= BORDER_LEFT
;
426 case NS_rtf::LN_BRCBOTTOM
: //bottom border
427 m_pImpl
->nCurrentBorderLine
= BORDER_BOTTOM
;
429 case NS_rtf::LN_BRCRIGHT
: //right border
430 m_pImpl
->nCurrentBorderLine
= BORDER_RIGHT
;
432 case NS_rtf::LN_shpopt
:
433 m_pImpl
->bInShapeOptionMode
= true;
437 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= val
.getProperties();
438 if( pProperties
.get())
440 pProperties
->resolve(*this);
444 case NS_rtf::LN_shpopt
:
445 m_pImpl
->bInShapeOptionMode
= false;
451 case NS_rtf::LN_payload
:
453 writerfilter::Reference
<BinaryObj
>::Pointer_t pPictureData
= val
.getBinary();
454 if( pPictureData
.get())
455 pPictureData
->resolve(*this);
458 case NS_rtf::LN_BM_RCWINMF
: //windows bitmap structure - if it's a bitmap
460 case NS_rtf::LN_DXAGOAL
: //x-size in twip
461 case NS_rtf::LN_DYAGOAL
: //y-size in twip
464 m_pImpl
->nHoriScaling
= nIntValue
;
465 break;// hori scaling in 0.001%
467 m_pImpl
->nVertScaling
= nIntValue
;
468 break;// vert scaling in 0.001%
469 case NS_rtf::LN_DXACROPLEFT
:
470 m_pImpl
->nLeftCrop
= ConversionHelper::convertTwipToMM100(nIntValue
);
471 break;// left crop in twips
472 case NS_rtf::LN_DYACROPTOP
:
473 m_pImpl
->nTopCrop
= ConversionHelper::convertTwipToMM100(nIntValue
);
474 break;// top crop in twips
475 case NS_rtf::LN_DXACROPRIGHT
:
476 m_pImpl
->nRightCrop
= ConversionHelper::convertTwipToMM100(nIntValue
);
477 break;// right crop in twips
478 case NS_rtf::LN_DYACROPBOTTOM
:
479 m_pImpl
->nBottomCrop
= ConversionHelper::convertTwipToMM100(nIntValue
);
480 break;// bottom crop in twips
481 case NS_rtf::LN_BRCL
:
482 break;//border type - legacy -
483 case NS_rtf::LN_FFRAMEEMPTY
:
484 break;// picture consists of a single frame
485 case NS_rtf::LN_FBITMAP
:
486 m_pImpl
->bIsBitmap
= nIntValue
> 0 ? true : false;
487 break;//1 if it's a bitmap ???
488 case NS_rtf::LN_FDRAWHATCH
:
489 break;//1 if it's an active OLE object
490 case NS_rtf::LN_FERROR
:
491 break;// 1 if picture is an error message
493 m_pImpl
->nBitsPerPixel
= nIntValue
;
494 break;//bits per pixel 0 - unknown, 1- mono, 4 - VGA
496 case NS_rtf::LN_DXAORIGIN
: //horizontal offset of hand annotation origin
497 case NS_rtf::LN_DYAORIGIN
: //vertical offset of hand annotation origin
499 case NS_rtf::LN_CPROPS
:break;// unknown - ignored
504 case NS_rtf::LN_XEXT
:
505 m_pImpl
->setXSize(nIntValue
);
507 case NS_rtf::LN_YEXT
:
508 m_pImpl
->setYSize(nIntValue
);
510 case NS_rtf::LN_HMF
: break; //identifier - ignored
512 //sprm 0xf004 and 0xf008, 0xf00b
513 case NS_rtf::LN_dfftype
://
514 m_pImpl
->nDffType
= nIntValue
;
516 case NS_rtf::LN_dffinstance
:
517 //todo: does this still work for PICF?
518 //in case of LN_dfftype == 0xf01f the instance contains the bitmap type:
519 if(m_pImpl
->nDffType
== 0xf01f)
522 case 0x216 : // Metafile header then compressed WMF
524 case 0x3D4 : // Metafile header then compressed EMF
526 case 0x542 : // Metafile hd. then compressed PICT
534 case 0x46A : break;// One byte tag then JPEG (= JFIF) data
536 case 0x6E0 : break;// One byte tag then PNG data
538 case 0x7A8 : m_pImpl
->bIsBitmap
= true;
543 case NS_rtf::LN_dffversion
:// ignored
547 case NS_rtf::LN_shptype
:
549 case NS_rtf::LN_shpid
:
551 case NS_rtf::LN_shpfGroup
:
552 break;// This shape is a group shape
553 case NS_rtf::LN_shpfChild
:
554 break;// Not a top-level shape
555 case NS_rtf::LN_shpfPatriarch
:
556 break;// This is the topmost group shape. Exactly one of these per drawing.
557 case NS_rtf::LN_shpfDeleted
:
558 break;// The shape has been deleted
559 case NS_rtf::LN_shpfOleShape
:
560 break;// The shape is an OLE object
561 case NS_rtf::LN_shpfHaveMaster
:
562 break;// Shape has a hspMaster property
563 case NS_rtf::LN_shpfFlipH
: // Shape is flipped horizontally
564 m_pImpl
->bHoriFlip
= nIntValue
? true : false;
566 case NS_rtf::LN_shpfFlipV
: // Shape is flipped vertically
567 m_pImpl
->bVertFlip
= nIntValue
? true : false;
569 case NS_rtf::LN_shpfConnector
:
570 break;// Connector type of shape
571 case NS_rtf::LN_shpfHaveAnchor
:
572 break;// Shape has an anchor of some kind
573 case NS_rtf::LN_shpfBackground
:
574 break;// Background shape
575 case NS_rtf::LN_shpfHaveSpt
:
576 break;// Shape has a shape type property
577 case NS_rtf::LN_shptypename
:
578 break;// shape type name
579 case NS_rtf::LN_shppid
:
580 m_pImpl
->nShapeOptionType
= nIntValue
;
581 break; //type of shape option
582 case NS_rtf::LN_shpfBid
:
584 case NS_rtf::LN_shpfComplex
:
586 case NS_rtf::LN_shpop
:
588 if(NS_dff::LN_shpwzDescription
!= sal::static_int_cast
<Id
>(m_pImpl
->nShapeOptionType
) )
589 ProcessShapeOptions( val
);
592 case NS_rtf::LN_shpname
:
594 case NS_rtf::LN_shpvalue
:
596 if( NS_dff::LN_shpwzDescription
== sal::static_int_cast
<Id
>(m_pImpl
->nShapeOptionType
) )
597 ProcessShapeOptions( val
);
602 case NS_rtf::LN_shpbtWin32
:
604 case NS_rtf::LN_shpbtMacOS
:
606 case NS_rtf::LN_shprgbUid
:
608 case NS_rtf::LN_shptag
:
610 case NS_rtf::LN_shpsize
:
612 case NS_rtf::LN_shpcRef
:
614 case NS_rtf::LN_shpfoDelay
:
616 case NS_rtf::LN_shpusage
:
618 case NS_rtf::LN_shpcbName
:
620 case NS_rtf::LN_shpunused2
:
622 case NS_rtf::LN_shpunused3
:
626 case NS_rtf::LN_shpblipbname
:
629 case NS_rtf::LN_DPTLINEWIDTH
: // 0x1759
630 m_pImpl
->aBorders
[m_pImpl
->nCurrentBorderLine
].nLineWidth
= nIntValue
;
632 case NS_rtf::LN_BRCTYPE
: // 0x175a
633 //graphic borders don't support different line types
635 case NS_rtf::LN_ICO
: // 0x175b
636 m_pImpl
->aBorders
[m_pImpl
->nCurrentBorderLine
].nLineColor
= ConversionHelper::ConvertColor( nIntValue
);
638 case NS_rtf::LN_DPTSPACE
: // 0x175c
639 m_pImpl
->aBorders
[m_pImpl
->nCurrentBorderLine
].nLineDistance
= nIntValue
;
641 case NS_rtf::LN_FSHADOW
: // 0x175d
642 m_pImpl
->aBorders
[m_pImpl
->nCurrentBorderLine
].bHasShadow
= nIntValue
? true : false;
644 case NS_rtf::LN_FFRAME
: // ignored
645 case NS_rtf::LN_UNUSED2_15
: // ignored
648 case NS_rtf::LN_SPID
:
650 case NS_rtf::LN_XALEFT
:
651 m_pImpl
->nLeftPosition
= ConversionHelper::convertTwipToMM100(nIntValue
);
652 break; //left position
653 case NS_rtf::LN_YATOP
:
654 m_pImpl
->nTopPosition
= ConversionHelper::convertTwipToMM100(nIntValue
);
655 break; //top position
656 case NS_rtf::LN_XARIGHT
:
657 m_pImpl
->nRightPosition
= ConversionHelper::convertTwipToMM100(nIntValue
);
658 break; //right position
659 case NS_rtf::LN_YABOTTOM
:
660 m_pImpl
->nBottomPosition
= ConversionHelper::convertTwipToMM100(nIntValue
);
661 break;//bottom position
662 case NS_rtf::LN_FHDR
:
663 case NS_rtf::LN_XAlign
:
664 if( nIntValue
< 6 && nIntValue
> 0 )
666 static const sal_Int16 aHoriOrientTab
[ 6 ] =
668 text::HoriOrientation::NONE
,
669 text::HoriOrientation::LEFT
,
670 text::HoriOrientation::CENTER
,
671 text::HoriOrientation::RIGHT
,
672 text::HoriOrientation::INSIDE
,
673 text::HoriOrientation::OUTSIDE
675 m_pImpl
->nHoriOrient
= aHoriOrientTab
[nIntValue
];
676 m_pImpl
->bPageToggle
= nIntValue
> 3;
679 case NS_rtf::LN_YAlign
:
680 if( nIntValue
< 6 && nIntValue
> 0)
682 static const sal_Int16 aVertOrientTab
[ 6 ] =
684 text::VertOrientation::NONE
, // From Top position
685 text::VertOrientation::TOP
, // top
686 text::VertOrientation::CENTER
, // centered
687 text::VertOrientation::BOTTOM
, // bottom
688 text::VertOrientation::LINE_TOP
, // inside (obscure)
689 text::VertOrientation::LINE_BOTTOM
// outside (obscure)
691 static const sal_Int16 aToLineVertOrientTab
[ 6 ] =
693 text::VertOrientation::NONE
, // below
694 text::VertOrientation::LINE_BOTTOM
, // top
695 text::VertOrientation::LINE_CENTER
, // centered
696 text::VertOrientation::LINE_TOP
, // bottom
697 text::VertOrientation::LINE_BOTTOM
, // inside (obscure)
698 text::VertOrientation::LINE_TOP
// outside (obscure)
700 m_pImpl
->nVertOrient
= m_pImpl
->nVertRelation
== text::RelOrientation::TEXT_LINE
?
701 aToLineVertOrientTab
[nIntValue
] : aVertOrientTab
[nIntValue
];
704 case NS_rtf::LN_LayoutInTableCell
: break; //currently unknown
705 case NS_rtf::LN_XRelTo
:
706 case NS_rtf::LN_BX
: //hori orient relation
709 case 0: m_pImpl
->nHoriRelation
= text::RelOrientation::PAGE_PRINT_AREA
; break;
710 case 1: m_pImpl
->nHoriRelation
= text::RelOrientation::PAGE_FRAME
; break;
711 case 2: m_pImpl
->nHoriRelation
= text::RelOrientation::FRAME
; break;
713 default:m_pImpl
->nHoriRelation
= text::RelOrientation::CHAR
;
716 case NS_rtf::LN_YRelTo
:
717 case NS_rtf::LN_BY
: //vert orient relation
720 case 0: m_pImpl
->nVertRelation
= text::RelOrientation::PAGE_PRINT_AREA
; break;
721 case 1: m_pImpl
->nVertRelation
= text::RelOrientation::PAGE_FRAME
; break;
722 case 2: m_pImpl
->nVertRelation
= text::RelOrientation::FRAME
; break;
724 default:m_pImpl
->nVertRelation
= text::RelOrientation::TEXT_LINE
;
728 case NS_rtf::LN_WR
: //wrapping
731 case 0: //0 like 2, but doesn't require absolute object
732 m_pImpl
->bIgnoreWRK
= false;
733 case 2: //2 wrap around absolute object
734 m_pImpl
->nWrap
= text::WrapTextMode_PARALLEL
;
736 case 1: //1 no text next to shape
737 m_pImpl
->nWrap
= text::WrapTextMode_NONE
;
739 case 3: //3 wrap as if no object present
740 m_pImpl
->nWrap
= text::WrapTextMode_THROUGHT
;
742 case 4: //4 wrap tightly around object
743 m_pImpl
->bIgnoreWRK
= false;
744 case 5: //5 wrap tightly, but allow holes
745 m_pImpl
->nWrap
= text::WrapTextMode_PARALLEL
;
746 m_pImpl
->bContour
= true;
752 if( !m_pImpl
->bIgnoreWRK
)
755 case 0: //0 like 2, but doesn't require absolute object
756 case 2: //2 wrap around absolute object
757 m_pImpl
->nWrap
= text::WrapTextMode_PARALLEL
;
759 case 1: //1 no text next to shape
760 m_pImpl
->nWrap
= text::WrapTextMode_NONE
;
762 case 3: //3 wrap as if no object present
763 m_pImpl
->nWrap
= text::WrapTextMode_THROUGHT
;
765 case 4: //4 wrap tightly around object
766 case 5: //5 wrap tightly, but allow holes
767 m_pImpl
->nWrap
= text::WrapTextMode_PARALLEL
;
768 m_pImpl
->bContour
= true;
773 case NS_rtf::LN_FRCASIMPLE
:
774 case NS_rtf::LN_FBELOWTEXT
:
775 case NS_rtf::LN_FANCHORLOCK
:
776 case NS_rtf::LN_CTXBX
:
778 case NS_rtf::LN_shptxt
:
781 case NS_rtf::LN_dffheader
: break;
782 case NS_ooxml::LN_CT_PositiveSize2D_cx
:// 90407;
783 case NS_ooxml::LN_CT_PositiveSize2D_cy
:// 90408;
785 sal_Int32 nDim
= ConversionHelper::convertEMUToMM100( nIntValue
);
786 if( nName
== NS_ooxml::LN_CT_PositiveSize2D_cx
)
787 m_pImpl
->setXSize(nDim
);
789 m_pImpl
->setYSize(nDim
);
792 case NS_ooxml::LN_CT_EffectExtent_l
:// 90907;
793 case NS_ooxml::LN_CT_EffectExtent_t
:// 90908;
794 case NS_ooxml::LN_CT_EffectExtent_r
:// 90909;
795 case NS_ooxml::LN_CT_EffectExtent_b
:// 90910;
796 //todo: extends the wrapping size of the object, e.g. if shadow is added
798 case NS_ooxml::LN_CT_NonVisualDrawingProps_id
:// 90650;
799 //id of the object - ignored
801 case NS_ooxml::LN_CT_NonVisualDrawingProps_name
:// 90651;
803 m_pImpl
->sName
= val
.getString();
805 case NS_ooxml::LN_CT_NonVisualDrawingProps_descr
:// 90652;
807 m_pImpl
->sAlternativeText
= val
.getString();
809 case NS_ooxml::LN_CT_NonVisualDrawingProps_title
:
811 m_pImpl
->title
= val
.getString();
813 case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noChangeAspect
://90644;
814 //disallow aspect ratio change - ignored
816 case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noMove
:// 90645;
817 m_pImpl
->bPositionProtected
= true;
819 case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noResize
: // 90646;
820 m_pImpl
->bSizeProtected
= true;
822 case NS_ooxml::LN_CT_Anchor_distT
: // 90983;
823 case NS_ooxml::LN_CT_Anchor_distB
: // 90984;
824 case NS_ooxml::LN_CT_Anchor_distL
: // 90985;
825 case NS_ooxml::LN_CT_Anchor_distR
: // 90986;
827 //redirect to shape option processing
830 case NS_ooxml::LN_CT_Anchor_distT
: // 90983;
831 m_pImpl
->nShapeOptionType
= NS_dff::LN_shpdyWrapDistTop
;
833 case NS_ooxml::LN_CT_Anchor_distB
: // 90984;
834 m_pImpl
->nShapeOptionType
= NS_dff::LN_shpdyWrapDistBottom
;
836 case NS_ooxml::LN_CT_Anchor_distL
: // 90985;
837 m_pImpl
->nShapeOptionType
= NS_dff::LN_shpdxWrapDistLeft
;
839 case NS_ooxml::LN_CT_Anchor_distR
: // 90986;
840 m_pImpl
->nShapeOptionType
= NS_dff::LN_shpdxWrapDistRight
;
842 //m_pImpl->nShapeOptionType = NS_dff::LN_shpcropFromTop
845 ProcessShapeOptions(val
);
848 case NS_ooxml::LN_CT_Anchor_simplePos_attr
: // 90987;
849 m_pImpl
->bUseSimplePos
= nIntValue
> 0;
851 case NS_ooxml::LN_CT_Anchor_relativeHeight
: // 90988;
852 m_pImpl
->zOrder
= nIntValue
;
854 case NS_ooxml::LN_CT_Anchor_behindDoc
: // 90989; - in background
856 m_pImpl
->bOpaque
= false;
858 case NS_ooxml::LN_CT_Anchor_locked
: // 90990; - ignored
859 case NS_ooxml::LN_CT_Anchor_layoutInCell
: // 90991; - ignored
860 case NS_ooxml::LN_CT_Anchor_hidden
: // 90992; - ignored
862 case NS_ooxml::LN_CT_Anchor_allowOverlap
: // 90993;
863 //enable overlapping - ignored
865 case NS_ooxml::LN_CT_Point2D_x
: // 90405;
866 m_pImpl
->nLeftPosition
= ConversionHelper::convertTwipToMM100(nIntValue
);
867 m_pImpl
->nHoriRelation
= text::RelOrientation::PAGE_FRAME
;
868 m_pImpl
->nHoriOrient
= text::HoriOrientation::NONE
;
870 case NS_ooxml::LN_CT_Point2D_y
: // 90406;
871 m_pImpl
->nTopPosition
= ConversionHelper::convertTwipToMM100(nIntValue
);
872 m_pImpl
->nVertRelation
= text::RelOrientation::PAGE_FRAME
;
873 m_pImpl
->nVertOrient
= text::VertOrientation::NONE
;
875 case NS_ooxml::LN_CT_WrapTight_wrapText
: // 90934;
876 m_pImpl
->bContour
= true;
877 m_pImpl
->bContourOutside
= true;
879 handleWrapTextValue(val
.getInt());
882 case NS_ooxml::LN_CT_WrapThrough_wrapText
:
883 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
884 m_pImpl
->bContour
= true;
885 m_pImpl
->bContourOutside
= false;
887 handleWrapTextValue(val
.getInt());
890 case NS_ooxml::LN_CT_WrapSquare_wrapText
: //90928;
891 /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
893 handleWrapTextValue(val
.getInt());
895 case NS_ooxml::LN_shape
:
897 uno::Reference
< drawing::XShape
> xShape
;
898 val
.getAny( ) >>= xShape
;
902 // Is it a graphic image
903 bool bUseShape
= true;
906 uno::Reference
< beans::XPropertySet
> xShapeProps
907 ( xShape
, uno::UNO_QUERY_THROW
);
910 xShapeProps
->getPropertyValue("GraphicURL") >>= sUrl
;
912 ::com::sun::star::beans::PropertyValues
aMediaProperties( 1 );
913 aMediaProperties
[0].Name
= "URL";
914 aMediaProperties
[0].Value
<<= sUrl
;
916 xShapeProps
->getPropertyValue("Shadow") >>= m_pImpl
->bShadow
;
917 if (m_pImpl
->bShadow
)
919 xShapeProps
->getPropertyValue("ShadowXDistance") >>= m_pImpl
->nShadowXDistance
;
920 xShapeProps
->getPropertyValue("ShadowYDistance") >>= m_pImpl
->nShadowYDistance
;
921 xShapeProps
->getPropertyValue("ShadowColor") >>= m_pImpl
->nShadowColor
;
922 xShapeProps
->getPropertyValue("ShadowTransparence") >>= m_pImpl
->nShadowTransparence
;
925 m_xGraphicObject
= createGraphicObject( aMediaProperties
);
927 bUseShape
= !m_xGraphicObject
.is( );
931 // Define the object size
932 uno::Reference
< beans::XPropertySet
> xGraphProps( m_xGraphicObject
,
934 awt::Size aSize
= xShape
->getSize( );
935 xGraphProps
->setPropertyValue("Height",
936 uno::makeAny( aSize
.Height
) );
937 xGraphProps
->setPropertyValue("Width",
938 uno::makeAny( aSize
.Width
) );
940 text::GraphicCrop
aGraphicCrop( 0, 0, 0, 0 );
941 uno::Reference
< beans::XPropertySet
> xSourceGraphProps( xShape
, uno::UNO_QUERY
);
942 uno::Any aAny
= xSourceGraphProps
->getPropertyValue( OUString("GraphicCrop"));
943 if(aAny
>>= aGraphicCrop
) {
944 xGraphProps
->setPropertyValue( OUString("GraphicCrop"),
945 uno::makeAny( aGraphicCrop
) );
948 // We need to drop the shape here somehow
949 uno::Reference
< lang::XComponent
> xShapeComponent( xShape
, uno::UNO_QUERY
);
950 xShapeComponent
->dispose( );
953 catch( const beans::UnknownPropertyException
& )
955 // It isn't a graphic image
962 if ( m_xShape
.is( ) )
964 uno::Reference
< beans::XPropertySet
> xShapeProps
965 (m_xShape
, uno::UNO_QUERY_THROW
);
968 PropertyNameSupplier
& rPropNameSupplier
=
969 PropertyNameSupplier::GetPropertyNameSupplier();
970 xShapeProps
->setPropertyValue
971 (rPropNameSupplier
.GetName(PROP_ANCHOR_TYPE
),
973 (text::TextContentAnchorType_AS_CHARACTER
));
974 xShapeProps
->setPropertyValue
975 (rPropNameSupplier
.GetName(PROP_TEXT_RANGE
),
977 (m_pImpl
->rDomainMapper
.GetCurrentTextRange()));
979 awt::Size
aSize(m_xShape
->getSize());
981 if (m_pImpl
->isXSizeValid())
982 aSize
.Width
= m_pImpl
->getXSize();
983 if (m_pImpl
->isYSizeValis())
984 aSize
.Height
= m_pImpl
->getYSize();
986 m_xShape
->setSize(aSize
);
988 m_pImpl
->bIsGraphic
= true;
993 case NS_ooxml::LN_CT_Inline_distT
:
994 m_pImpl
->nTopMargin
= ConversionHelper::convertEMUToMM100(nIntValue
);
996 case NS_ooxml::LN_CT_Inline_distB
:
997 m_pImpl
->nBottomMargin
= ConversionHelper::convertEMUToMM100(nIntValue
);
999 case NS_ooxml::LN_CT_Inline_distL
:
1000 m_pImpl
->nLeftMargin
= ConversionHelper::convertEMUToMM100(nIntValue
);
1002 case NS_ooxml::LN_CT_Inline_distR
:
1003 m_pImpl
->nRightMargin
= ConversionHelper::convertEMUToMM100(nIntValue
);
1005 case NS_ooxml::LN_CT_GraphicalObjectData_uri
:
1007 //TODO: does it need to be handled?
1010 #ifdef DEBUG_DMAPPER_GRAPHIC_IMPORT
1011 dmapper_logger
->element("unhandled");
1017 uno::Reference
<text::XTextContent
> GraphicImport::GetGraphicObject()
1019 uno::Reference
<text::XTextContent
> xResult
;
1021 if (m_xGraphicObject
.is())
1022 xResult
= m_xGraphicObject
;
1023 else if (m_xShape
.is())
1025 xResult
.set(m_xShape
, uno::UNO_QUERY_THROW
);
1033 void GraphicImport::ProcessShapeOptions(Value
& val
)
1035 sal_Int32 nIntValue
= val
.getInt();
1036 sal_Int32 nTwipValue
= ConversionHelper::convertTwipToMM100(nIntValue
);
1037 switch( m_pImpl
->nShapeOptionType
)
1039 case NS_dff::LN_shpcropFromTop
/*256*/ :
1040 m_pImpl
->nTopCrop
= nTwipValue
;
1041 break;// rtf:shpcropFromTop
1042 case NS_dff::LN_shpcropFromBottom
/*257*/ :
1043 m_pImpl
->nBottomCrop
= nTwipValue
;
1044 break;// rtf:shpcropFromBottom
1045 case NS_dff::LN_shpcropFromLeft
/*258*/ :
1046 m_pImpl
->nLeftCrop
= nTwipValue
;
1047 break;// rtf:shpcropFromLeft
1048 case NS_dff::LN_shpcropFromRight
/*259*/ :
1049 m_pImpl
->nRightCrop
= nTwipValue
;
1050 break;// rtf:shpcropFromRight
1051 case NS_dff::LN_shppib
/*260*/:
1052 break; // rtf:shppib
1053 case NS_dff::LN_shppibName
/*261*/:
1054 break; // rtf:shppibName
1055 case NS_dff::LN_shppibFlags
/*262*/: // rtf:shppibFlags
1057 case NS_dff::LN_shppictureContrast
/*264*/: // rtf:shppictureContrast docu: "1<<16"
1059 0x10000 is msoffice 50%
1060 < 0x10000 is in units of 1/50th of 0x10000 per 1%
1061 > 0x10000 is in units where
1062 a msoffice x% is stored as 50/(100-x) * 0x10000
1064 plus, a (ui) microsoft % ranges from 0 to 100, OOO
1065 from -100 to 100, so also normalize into that range
1067 if ( nIntValue
> 0x10000 )
1069 double fX
= nIntValue
;
1071 fX
/= 51; // 50 + 1 to round
1073 m_pImpl
->nContrast
= static_cast<sal_Int32
>(fX
);
1074 m_pImpl
->nContrast
-= 100;
1075 m_pImpl
->nContrast
= -m_pImpl
->nContrast
;
1076 m_pImpl
->nContrast
= (m_pImpl
->nContrast
-50)*2;
1078 else if ( nIntValue
== 0x10000 )
1079 m_pImpl
->nContrast
= 0;
1082 m_pImpl
->nContrast
= nIntValue
* 101; //100 + 1 to round
1083 m_pImpl
->nContrast
/= 0x10000;
1084 m_pImpl
->nContrast
-= 100;
1087 case NS_dff::LN_shppictureBrightness
/*265*/: // rtf:shppictureBrightness
1088 m_pImpl
->nBrightness
= ( (sal_Int32
) nIntValue
/ 327 );
1090 case NS_dff::LN_shppictureGamma
/*266*/: // rtf:shppictureGamma
1091 //todo check gamma value with _real_ document
1092 m_pImpl
->fGamma
= double(nIntValue
/655);
1094 case NS_dff::LN_shppictureId
/*267*/:
1095 break; // rtf:shppictureId
1096 case NS_dff::LN_shppictureDblCrMod
/*268*/:
1097 break; // rtf:shppictureDblCrMod
1098 case NS_dff::LN_shppictureFillCrMod
/*269*/:
1099 break; // rtf:shppictureFillCrMod
1100 case NS_dff::LN_shppictureLineCrMod
/*270*/:
1101 break; // rtf:shppictureLineCrMod
1103 case NS_dff::LN_shppictureActive
/*319*/: // rtf:shppictureActive
1104 switch( nIntValue
& 0x06 )
1106 case 0 : m_pImpl
->eColorMode
= drawing::ColorMode_STANDARD
; break;
1107 case 4 : m_pImpl
->eColorMode
= drawing::ColorMode_GREYS
; break;
1108 case 6 : m_pImpl
->eColorMode
= drawing::ColorMode_MONO
; break;
1112 case NS_dff::LN_shpfillColor
/*385*/:
1113 m_pImpl
->nFillColor
= (m_pImpl
->nFillColor
& 0xff000000) + ConversionHelper::ConvertColor( nIntValue
);
1115 case NS_dff::LN_shpfillOpacity
/*386*/:
1117 sal_Int32 nTrans
= 0xff - ( nIntValue
* 0xff ) / 0xffff;
1118 m_pImpl
->nFillColor
= (nTrans
<< 0x18 ) + (m_pImpl
->nFillColor
& 0xffffff);
1121 case NS_dff::LN_shpfNoFillHitTest
/*447*/:
1122 break; // rtf:shpfNoFillHitTest
1123 case NS_dff::LN_shplineColor
/*448*/:
1124 m_pImpl
->aBorders
[m_pImpl
->nCurrentBorderLine
].nLineColor
= ConversionHelper::ConvertColor( nIntValue
);
1126 case NS_dff::LN_shplineWidth
/*459*/:
1127 //1pt == 12700 units
1128 m_pImpl
->aBorders
[m_pImpl
->nCurrentBorderLine
].nLineWidth
= ConversionHelper::convertTwipToMM100(nIntValue
/ 635);
1130 case NS_dff::LN_shplineDashing
/*462*/:
1131 //graphic borders don't support different dashing
1133 msolineSolid, // Solid (continuous) pen
1134 msolineDashSys, // PS_DASH system dash style
1135 msolineDotSys, // PS_DOT system dash style
1136 msolineDashDotSys, // PS_DASHDOT system dash style
1137 msolineDashDotDotSys, // PS_DASHDOTDOT system dash style
1138 msolineDotGEL, // square dot style
1139 msolineDashGEL, // dash style
1140 msolineLongDashGEL, // long dash style
1141 msolineDashDotGEL, // dash short dash
1142 msolineLongDashDotGEL, // long dash short dash
1143 msolineLongDashDotDotGEL // long dash short dash short dash*/
1145 case NS_dff::LN_shpfNoLineDrawDash
/*511*/:
1146 break; // rtf:shpfNoLineDrawDash
1147 case NS_dff::LN_shpwzDescription
/*897*/: //alternative text
1148 m_pImpl
->sAlternativeText
= val
.getString();
1150 case NS_dff::LN_shppWrapPolygonVertices
/*899*/:
1151 break; // rtf:shppWrapPolygonVertices
1152 case NS_dff::LN_shpdxWrapDistLeft
/*900*/: // contains a twip/635 value
1153 //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustLRWrapForWordMargins()
1154 m_pImpl
->nLeftMargin
= nIntValue
/ 360;
1156 case NS_dff::LN_shpdyWrapDistTop
/*901*/: // contains a twip/635 value
1157 //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustULWrapForWordMargins()
1158 m_pImpl
->nTopMargin
= nIntValue
/ 360;
1160 case NS_dff::LN_shpdxWrapDistRight
/*902*/:// contains a twip/635 value
1161 //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustLRWrapForWordMargins()
1162 m_pImpl
->nRightMargin
= nIntValue
/ 360;
1164 case NS_dff::LN_shpdyWrapDistBottom
/*903*/:// contains a twip/635 value
1165 //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustULWrapForWordMargins()
1166 m_pImpl
->nBottomMargin
= nIntValue
/ 360;
1168 case NS_dff::LN_shpfPrint
/*959*/:
1169 break; // rtf:shpfPrint
1171 OSL_FAIL( "shape option unsupported?");
1176 void GraphicImport::lcl_sprm(Sprm
& rSprm
)
1178 sal_uInt32 nSprmId
= rSprm
.getId();
1179 Value::Pointer_t pValue
= rSprm
.getValue();
1183 case 0xf004: //dff record
1184 case 0xf00a: //part of 0xf004 - shape properties
1185 case 0xf00b: //part of 0xf004
1187 case 0xf122: //udefprop
1188 case NS_ooxml::LN_CT_Inline_extent
: // 90911;
1189 case NS_ooxml::LN_CT_Inline_effectExtent
: // 90912;
1190 case NS_ooxml::LN_CT_Inline_docPr
: // 90913;
1191 case NS_ooxml::LN_CT_Inline_cNvGraphicFramePr
: // 90914;
1192 case NS_ooxml::LN_CT_NonVisualGraphicFrameProperties_graphicFrameLocks
:// 90657
1193 case NS_ooxml::LN_CT_Inline_a_graphic
:// 90915
1194 case NS_ooxml::LN_CT_Anchor_simplePos_elem
: // 90975;
1195 case NS_ooxml::LN_CT_Anchor_extent
: // 90978;
1196 case NS_ooxml::LN_CT_Anchor_effectExtent
: // 90979;
1197 case NS_ooxml::LN_EG_WrapType_wrapSquare
: // 90945;
1198 case NS_ooxml::LN_EG_WrapType_wrapTight
: // 90946;
1199 case NS_ooxml::LN_EG_WrapType_wrapThrough
:
1200 case NS_ooxml::LN_CT_Anchor_docPr
: // 90980;
1201 case NS_ooxml::LN_CT_Anchor_cNvGraphicFramePr
: // 90981;
1202 case NS_ooxml::LN_CT_Anchor_a_graphic
: // 90982;
1203 case NS_ooxml::LN_CT_WrapPath_start
: // 90924;
1204 case NS_ooxml::LN_CT_WrapPath_lineTo
: // 90925;
1205 case NS_ooxml::LN_graphic_graphic
:
1206 case NS_ooxml::LN_pic_pic
:
1207 case NS_ooxml::LN_dgm_relIds
:
1208 case NS_ooxml::LN_lc_lockedCanvas
:
1210 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
1211 if( pProperties
.get())
1213 pProperties
->resolve(*this);
1217 case NS_ooxml::LN_CT_WrapTight_wrapPolygon
:
1218 case NS_ooxml::LN_CT_WrapThrough_wrapPolygon
:
1219 /* WRITERFILTERSTATUS: done: 100, planned: 4, spent: 2 */
1221 WrapPolygonHandler aHandler
;
1223 resolveSprmProps(aHandler
, rSprm
);
1225 m_pImpl
->mpWrapPolygon
= aHandler
.getPolygon();
1228 case NS_ooxml::LN_CT_Anchor_positionH
: // 90976;
1230 // Use a special handler for the positionning
1231 PositionHandlerPtr
pHandler( new PositionHandler( false ));
1232 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
1233 if( pProperties
.get( ) )
1235 pProperties
->resolve( *pHandler
);
1236 if( !m_pImpl
->bUseSimplePos
)
1238 m_pImpl
->nHoriRelation
= pHandler
->m_nRelation
;
1239 m_pImpl
->nHoriOrient
= pHandler
->m_nOrient
;
1240 m_pImpl
->nLeftPosition
= pHandler
->m_nPosition
;
1245 case NS_ooxml::LN_CT_Anchor_positionV
: // 90977;
1247 // Use a special handler for the positionning
1248 PositionHandlerPtr
pHandler( new PositionHandler( true ));
1249 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
1250 if( pProperties
.get( ) )
1252 pProperties
->resolve( *pHandler
);
1253 if( !m_pImpl
->bUseSimplePos
)
1255 m_pImpl
->nVertRelation
= pHandler
->m_nRelation
;
1256 m_pImpl
->nVertOrient
= pHandler
->m_nOrient
;
1257 m_pImpl
->nTopPosition
= pHandler
->m_nPosition
;
1265 if( nSprmId
!= 0x271c || m_pImpl
->nDffType
== 0xf01f || m_pImpl
->nDffType
== 0xf01e )
1267 writerfilter::Reference
<BinaryObj
>::Pointer_t pPictureData
= rSprm
.getBinary();
1268 if( pPictureData
.get())
1269 pPictureData
->resolve(*this);
1273 case NS_ooxml::LN_EG_WrapType_wrapNone
: // 90944; - doesn't contain attributes
1274 //depending on the behindDoc attribute text wraps through behind or in fron of the object
1275 m_pImpl
->nWrap
= text::WrapTextMode_THROUGHT
;
1277 case NS_ooxml::LN_EG_WrapType_wrapTopAndBottom
: // 90948;
1278 m_pImpl
->nWrap
= text::WrapTextMode_NONE
;
1282 //ignore - doesn't contain useful members
1284 case NS_ooxml::LN_CT_GraphicalObject_graphicData
:// 90660;
1286 m_pImpl
->bIsGraphic
= true;
1288 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
1289 if( pProperties
.get())
1290 pProperties
->resolve(*this);
1294 #if OSL_DEBUG_LEVEL > 0
1295 OString
sMessage( "GraphicImport::sprm() - Id: ");
1296 sMessage
+= OString::valueOf( sal_Int32( nSprmId
), 10 );
1297 sMessage
+= " / 0x";
1298 sMessage
+= OString::valueOf( sal_Int32( nSprmId
), 16 );
1299 SAL_WARN("writerfilter", sMessage
.getStr());
1306 void GraphicImport::lcl_entry(int /*pos*/, writerfilter::Reference
<Properties
>::Pointer_t
/*ref*/)
1309 /*-------------------------------------------------------------------------
1310 crop is stored as "fixed float" as 16.16 fraction value
1311 related to width/or height
1312 -----------------------------------------------------------------------*/
1313 void lcl_CalcCrop( sal_Int32
& nCrop
, sal_Int32 nRef
)
1315 nCrop
= ((nCrop
>> 16 ) * nRef
)
1316 + (((nCrop
& 0xffff) * nRef
) >> 16);
1319 uno::Reference
< text::XTextContent
> GraphicImport::createGraphicObject( const beans::PropertyValues
& aMediaProperties
)
1321 uno::Reference
< text::XTextContent
> xGraphicObject
;
1324 uno::Reference
< graphic::XGraphicProvider
> xGraphicProvider( graphic::GraphicProvider::create(m_xComponentContext
) );
1325 uno::Reference
< graphic::XGraphic
> xGraphic
= xGraphicProvider
->queryGraphic( aMediaProperties
);
1329 PropertyNameSupplier
& rPropNameSupplier
= PropertyNameSupplier::GetPropertyNameSupplier();
1331 uno::Reference
< beans::XPropertySet
> xGraphicObjectProperties(
1332 m_xTextFactory
->createInstance("com.sun.star.text.TextGraphicObject"),
1333 uno::UNO_QUERY_THROW
);
1334 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName(PROP_GRAPHIC
), uno::makeAny( xGraphic
));
1335 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName(PROP_ANCHOR_TYPE
),
1336 uno::makeAny( m_pImpl
->eGraphicImportType
== IMPORT_AS_SHAPE
|| m_pImpl
->eGraphicImportType
== IMPORT_AS_DETECTED_ANCHOR
?
1337 text::TextContentAnchorType_AT_CHARACTER
:
1338 text::TextContentAnchorType_AS_CHARACTER
));
1339 xGraphicObject
= uno::Reference
< text::XTextContent
>( xGraphicObjectProperties
, uno::UNO_QUERY_THROW
);
1341 //shapes have only one border, PICF might have four
1342 table::BorderLine2 aBorderLine
;
1343 for( sal_Int32 nBorder
= 0; nBorder
< 4; ++nBorder
)
1345 if( m_pImpl
->eGraphicImportType
== IMPORT_AS_GRAPHIC
|| !nBorder
)
1347 aBorderLine
.Color
= m_pImpl
->aBorders
[m_pImpl
->eGraphicImportType
== IMPORT_AS_SHAPE
? BORDER_TOP
: static_cast<BorderPosition
>(nBorder
) ].nLineColor
;
1348 aBorderLine
.InnerLineWidth
= 0;
1349 aBorderLine
.OuterLineWidth
= (sal_Int16
)m_pImpl
->aBorders
[m_pImpl
->eGraphicImportType
== IMPORT_AS_SHAPE
? BORDER_TOP
: static_cast<BorderPosition
>(nBorder
) ].nLineWidth
;
1350 aBorderLine
.LineDistance
= 0;
1352 PropertyIds aBorderProps
[4] =
1359 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( aBorderProps
[nBorder
]), uno::makeAny(aBorderLine
));
1362 // setting graphic object shadow proerties
1363 if (m_pImpl
->bShadow
)
1365 // Shadow width is approximated by average of X and Y
1366 table::ShadowFormat aShadow
;
1367 sal_Int32 nShadowColor
= m_pImpl
->nShadowColor
;
1368 sal_Int32 nShadowWidth
= (abs(m_pImpl
->nShadowXDistance
)
1369 + abs(m_pImpl
->nShadowYDistance
)) / 2;
1371 aShadow
.ShadowWidth
= nShadowWidth
;
1372 aShadow
.Color
= nShadowColor
;
1373 // Distances -ve for top and right, +ve for bottom and left
1374 if (m_pImpl
->nShadowXDistance
> 0)
1376 if (m_pImpl
->nShadowYDistance
> 0)
1377 aShadow
.Location
= com::sun::star::table::ShadowLocation_BOTTOM_RIGHT
;
1379 aShadow
.Location
= com::sun::star::table::ShadowLocation_TOP_RIGHT
;
1383 if (m_pImpl
->nShadowYDistance
> 0)
1384 aShadow
.Location
= com::sun::star::table::ShadowLocation_BOTTOM_LEFT
;
1386 aShadow
.Location
= com::sun::star::table::ShadowLocation_TOP_LEFT
;
1389 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName(PROP_SHADOW_FORMAT
), uno::makeAny(aShadow
));
1392 // setting properties for all types
1393 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_DESCRIPTION
),
1394 uno::makeAny( m_pImpl
->sAlternativeText
));
1395 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_TITLE
),
1396 uno::makeAny( m_pImpl
->title
));
1397 if( m_pImpl
->bPositionProtected
)
1398 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_POSITION_PROTECTED
),
1399 uno::makeAny(true));
1400 if( m_pImpl
->bSizeProtected
)
1401 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_SIZE_PROTECTED
),
1402 uno::makeAny(true));
1404 if( m_pImpl
->eGraphicImportType
== IMPORT_AS_SHAPE
|| m_pImpl
->eGraphicImportType
== IMPORT_AS_DETECTED_ANCHOR
)
1406 sal_Int32 nWidth
= m_pImpl
->nRightPosition
- m_pImpl
->nLeftPosition
;
1407 if( m_pImpl
->eGraphicImportType
== IMPORT_AS_SHAPE
)
1409 sal_Int32 nHeight
= m_pImpl
->nBottomPosition
- m_pImpl
->nTopPosition
;
1410 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName(PROP_SIZE
),
1411 uno::makeAny( awt::Size( nWidth
, nHeight
)));
1414 if( (m_pImpl
->nHoriOrient
== text::HoriOrientation::LEFT
&&
1415 (m_pImpl
->nHoriRelation
== text::RelOrientation::PAGE_PRINT_AREA
||
1416 m_pImpl
->nHoriRelation
== text::RelOrientation::FRAME
) ) ||
1417 (m_pImpl
->nHoriOrient
== text::HoriOrientation::INSIDE
&&
1418 m_pImpl
->nHoriRelation
== text::RelOrientation::PAGE_PRINT_AREA
))
1419 m_pImpl
->nLeftMargin
= 0;
1420 if((m_pImpl
->nHoriOrient
== text::HoriOrientation::RIGHT
&&
1421 (m_pImpl
->nHoriRelation
== text::RelOrientation::PAGE_PRINT_AREA
||
1422 m_pImpl
->nHoriRelation
== text::RelOrientation::FRAME
) ) ||
1423 (m_pImpl
->nHoriOrient
== text::HoriOrientation::INSIDE
&&
1424 m_pImpl
->nHoriRelation
== text::RelOrientation::PAGE_PRINT_AREA
))
1425 m_pImpl
->nRightMargin
= 0;
1426 // adjust top/bottom margins
1427 if( m_pImpl
->nVertOrient
== text::VertOrientation::TOP
&&
1428 ( m_pImpl
->nVertRelation
== text::RelOrientation::PAGE_PRINT_AREA
||
1429 m_pImpl
->nVertRelation
== text::RelOrientation::PAGE_FRAME
))
1430 m_pImpl
->nTopMargin
= 0;
1431 if( m_pImpl
->nVertOrient
== text::VertOrientation::BOTTOM
&&
1432 ( m_pImpl
->nVertRelation
== text::RelOrientation::PAGE_PRINT_AREA
||
1433 m_pImpl
->nVertRelation
== text::RelOrientation::PAGE_FRAME
))
1434 m_pImpl
->nBottomMargin
= 0;
1435 if( m_pImpl
->nVertOrient
== text::VertOrientation::BOTTOM
&&
1436 m_pImpl
->nVertRelation
== text::RelOrientation::PAGE_PRINT_AREA
)
1437 m_pImpl
->nBottomMargin
= 0;
1440 if( m_pImpl
->nHoriOrient
== text::HoriOrientation::INSIDE
&&
1441 m_pImpl
->nHoriRelation
== text::RelOrientation::PAGE_FRAME
)
1443 // convert 'left to page' to 'from left -<width> to page text area'
1444 m_pImpl
->nHoriOrient
= text::HoriOrientation::NONE
;
1445 m_pImpl
->nHoriRelation
= text::RelOrientation::PAGE_PRINT_AREA
;
1446 m_pImpl
->nLeftPosition
= - nWidth
;
1448 else if( m_pImpl
->nHoriOrient
== text::HoriOrientation::OUTSIDE
&&
1449 m_pImpl
->nHoriRelation
== text::RelOrientation::PAGE_FRAME
)
1451 // convert 'right to page' to 'from left 0 to right page border'
1452 m_pImpl
->nHoriOrient
= text::HoriOrientation::NONE
;
1453 m_pImpl
->nHoriRelation
= text::RelOrientation::PAGE_RIGHT
;
1454 m_pImpl
->nLeftPosition
= 0;
1457 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_HORI_ORIENT
),
1458 uno::makeAny(m_pImpl
->nHoriOrient
));
1459 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_HORI_ORIENT_POSITION
),
1460 uno::makeAny(m_pImpl
->nLeftPosition
));
1461 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_HORI_ORIENT_RELATION
),
1462 uno::makeAny(m_pImpl
->nHoriRelation
));
1463 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_PAGE_TOGGLE
),
1464 uno::makeAny(m_pImpl
->bPageToggle
));
1465 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_VERT_ORIENT
),
1466 uno::makeAny(m_pImpl
->nVertOrient
));
1467 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_VERT_ORIENT_POSITION
),
1468 uno::makeAny(m_pImpl
->nTopPosition
));
1469 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_VERT_ORIENT_RELATION
),
1470 uno::makeAny(m_pImpl
->nVertRelation
));
1472 bool bOpaque
= m_pImpl
->bOpaque
&& !m_pImpl
->rDomainMapper
.IsInHeaderFooter( );
1475 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_OPAQUE
),
1476 uno::makeAny(bOpaque
));
1478 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_SURROUND
),
1479 uno::makeAny(m_pImpl
->nWrap
));
1481 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_SURROUND_CONTOUR
),
1482 uno::makeAny(m_pImpl
->bContour
));
1483 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_CONTOUR_OUTSIDE
),
1484 uno::makeAny(m_pImpl
->bContourOutside
));
1485 m_pImpl
->applyMargins(xGraphicObjectProperties
);
1487 if( m_pImpl
->eColorMode
== drawing::ColorMode_STANDARD
&&
1488 m_pImpl
->nContrast
== -70 &&
1489 m_pImpl
->nBrightness
== 70 )
1491 // strange definition of WATERMARK!
1492 m_pImpl
->nContrast
= 0;
1493 m_pImpl
->nBrightness
= 0;
1494 m_pImpl
->eColorMode
= drawing::ColorMode_WATERMARK
;
1497 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_ADJUST_CONTRAST
),
1498 uno::makeAny((sal_Int16
)m_pImpl
->nContrast
));
1499 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_ADJUST_LUMINANCE
),
1500 uno::makeAny((sal_Int16
)m_pImpl
->nBrightness
));
1501 if(m_pImpl
->eColorMode
!= drawing::ColorMode_STANDARD
)
1502 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_GRAPHIC_COLOR_MODE
),
1503 uno::makeAny(m_pImpl
->eColorMode
));
1504 if(m_pImpl
->fGamma
> 0. )
1505 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_GAMMA
),
1506 uno::makeAny(m_pImpl
->fGamma
));
1507 if(m_pImpl
->bHoriFlip
)
1509 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_HORI_MIRRORED_ON_EVEN_PAGES
),
1510 uno::makeAny( m_pImpl
->bHoriFlip
));
1511 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_HORI_MIRRORED_ON_ODD_PAGES
),
1512 uno::makeAny( m_pImpl
->bHoriFlip
));
1515 if( m_pImpl
->bVertFlip
)
1516 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_VERT_MIRRORED
),
1517 uno::makeAny( m_pImpl
->bVertFlip
));
1518 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_BACK_COLOR
),
1519 uno::makeAny( m_pImpl
->nFillColor
));
1521 if( m_pImpl
->zOrder
>= 0 )
1523 GraphicZOrderHelper
* zOrderHelper
= m_pImpl
->rDomainMapper
.graphicZOrderHelper();
1524 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_Z_ORDER
),
1525 uno::makeAny( zOrderHelper
->findZOrder( m_pImpl
->zOrder
)));
1526 zOrderHelper
->addItem( xGraphicObjectProperties
, m_pImpl
->zOrder
);
1529 //there seems to be no way to detect the original size via _real_ API
1530 uno::Reference
< beans::XPropertySet
> xGraphicProperties( xGraphic
, uno::UNO_QUERY_THROW
);
1531 awt::Size aGraphicSize
, aGraphicSizePixel
;
1532 xGraphicProperties
->getPropertyValue(rPropNameSupplier
.GetName( PROP_SIZE100th_M_M
)) >>= aGraphicSize
;
1533 xGraphicProperties
->getPropertyValue(rPropNameSupplier
.GetName( PROP_SIZE_PIXEL
)) >>= aGraphicSizePixel
;
1535 uno::Any aContourPolyPolygon
;
1536 if( aGraphicSize
.Width
&& aGraphicSize
.Height
&&
1537 m_pImpl
->mpWrapPolygon
.get() != NULL
)
1539 awt::Size
aDstSize(m_pImpl
->getXSize(), m_pImpl
->getYSize());
1540 WrapPolygon::Pointer_t pCorrected
= m_pImpl
->mpWrapPolygon
->correctWordWrapPolygon(aGraphicSize
, aDstSize
);
1541 aContourPolyPolygon
<<= pCorrected
->getPointSequenceSequence();
1544 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_CONTOUR_POLY_POLYGON
),
1545 aContourPolyPolygon
);
1547 if( aGraphicSize
.Width
&& aGraphicSize
.Height
)
1549 //todo: i71651 graphic size is not provided by the GraphicDescriptor
1550 lcl_CalcCrop( m_pImpl
->nTopCrop
, aGraphicSize
.Height
);
1551 lcl_CalcCrop( m_pImpl
->nBottomCrop
, aGraphicSize
.Height
);
1552 lcl_CalcCrop( m_pImpl
->nLeftCrop
, aGraphicSize
.Width
);
1553 lcl_CalcCrop( m_pImpl
->nRightCrop
, aGraphicSize
.Width
);
1556 // We need a separate try-catch here, otherwise a bad crop setting will also nuke the size settings as well.
1559 xGraphicProperties
->setPropertyValue(rPropNameSupplier
.GetName( PROP_GRAPHIC_CROP
),
1560 uno::makeAny(text::GraphicCrop(m_pImpl
->nTopCrop
, m_pImpl
->nBottomCrop
, m_pImpl
->nLeftCrop
, m_pImpl
->nRightCrop
)));
1562 catch (const uno::Exception
& e
)
1564 SAL_WARN("writerfilter", "failed. Message :" << e
.Message
);
1570 if(m_pImpl
->eGraphicImportType
== IMPORT_AS_DETECTED_INLINE
|| m_pImpl
->eGraphicImportType
== IMPORT_AS_DETECTED_ANCHOR
)
1572 if( m_pImpl
->getXSize() && m_pImpl
->getYSize() )
1573 xGraphicObjectProperties
->setPropertyValue(rPropNameSupplier
.GetName(PROP_SIZE
),
1574 uno::makeAny( awt::Size( m_pImpl
->getXSize(), m_pImpl
->getYSize() )));
1575 m_pImpl
->applyMargins(xGraphicObjectProperties
);
1578 if( !m_pImpl
->sName
.isEmpty() )
1580 uno::Reference
< container::XNamed
> xNamed( xGraphicObjectProperties
, uno::UNO_QUERY_THROW
);
1581 xNamed
->setName( m_pImpl
->sName
);
1584 catch( const uno::Exception
& e
)
1586 SAL_WARN("writerfilter", "failed. Message :" << e
.Message
);
1591 catch( const uno::Exception
& e
)
1593 SAL_WARN("writerfilter", "failed. Message :" << e
.Message
);
1595 return xGraphicObject
;
1600 void GraphicImport::data(const sal_uInt8
* buf
, size_t len
, writerfilter::Reference
<Properties
>::Pointer_t
/*ref*/)
1602 PropertyNameSupplier
& rPropNameSupplier
= PropertyNameSupplier::GetPropertyNameSupplier();
1604 ::com::sun::star::beans::PropertyValues
aMediaProperties( 1 );
1605 aMediaProperties
[0].Name
= rPropNameSupplier
.GetName(PROP_INPUT_STREAM
);
1607 uno::Reference
< io::XInputStream
> xIStream
= new XInputStreamHelper( buf
, len
, m_pImpl
->bIsBitmap
);
1608 aMediaProperties
[0].Value
<<= xIStream
;
1610 m_xGraphicObject
= createGraphicObject( aMediaProperties
);
1614 void GraphicImport::lcl_startSectionGroup()
1619 void GraphicImport::lcl_endSectionGroup()
1624 void GraphicImport::lcl_startParagraphGroup()
1629 void GraphicImport::lcl_endParagraphGroup()
1634 void GraphicImport::lcl_startCharacterGroup()
1639 void GraphicImport::lcl_endCharacterGroup()
1644 void GraphicImport::lcl_text(const sal_uInt8
* /*_data*/, size_t /*len*/)
1649 void GraphicImport::lcl_utext(const sal_uInt8
* /*_data*/, size_t /*len*/)
1654 void GraphicImport::lcl_props(writerfilter::Reference
<Properties
>::Pointer_t
/*ref*/)
1659 void GraphicImport::lcl_table(Id
/*name*/, writerfilter::Reference
<Table
>::Pointer_t
/*ref*/)
1664 void GraphicImport::lcl_substream(Id
/*name*/, ::writerfilter::Reference
<Stream
>::Pointer_t
/*ref*/)
1669 void GraphicImport::lcl_info(const string
& /*info*/)
1673 void GraphicImport::lcl_startShape( ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
> /*xShape*/ )
1677 void GraphicImport::lcl_endShape( )
1683 bool GraphicImport::IsGraphic() const
1685 return m_pImpl
->bIsGraphic
;
1691 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */