1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
57 * For LWP filter architecture prototype - OLE object
59 /*************************************************************************
62 ************************************************************************/
64 #include <tools/stream.hxx>
65 #include "lwpglobalmgr.hxx"
66 #include "lwpoleobject.hxx"
67 #include "lwpobjfactory.hxx"
68 #include "lwpidxmgr.hxx"
69 #include "lwp9reader.hxx"
70 #include "xfilter/xfoleobj.hxx"
71 #include "xfilter/xfparagraph.hxx"
72 #include "lwpframelayout.hxx"
73 #include "xfilter/xfstylemanager.hxx"
77 * @descr: construction function
78 * @param: objHdr - object header, read before entering this function
79 * @param: pStrm - file stream
83 LwpGraphicOleObject::LwpGraphicOleObject(LwpObjectHeader
&objHdr
, LwpSvStream
* pStrm
)
84 : LwpContent(objHdr
, pStrm
)
87 * @descr: Read GraphicOleObject part
92 void LwpGraphicOleObject::Read()
96 if (LwpFileHeader::m_nFileRevision
>= 0x000b)
98 // I'm not sure about the read method
99 m_pNextObj
.ReadIndexed(m_pObjStrm
);
100 m_pPrevObj
.ReadIndexed(m_pObjStrm
);
102 m_pObjStrm
->SkipExtra();
106 void LwpGraphicOleObject::GetGrafOrgSize(double & rWidth
, double & rHeight
)
112 void LwpGraphicOleObject::GetGrafScaledSize(double & fWidth
, double & fHeight
)
114 GetGrafOrgSize(fWidth
, fHeight
);
116 double fSclGrafWidth
= fWidth
;//LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
117 double fSclGrafHeight
= fHeight
;//LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
120 LwpVirtualLayout
* pLayout
= GetLayout(NULL
);
121 if (pLayout
&& pLayout
->IsFrame())
123 LwpFrameLayout
* pMyFrameLayout
= static_cast<LwpFrameLayout
*>(pLayout
);
124 LwpLayoutScale
* pMyScale
= pMyFrameLayout
->GetLayoutScale();
125 LwpLayoutGeometry
* pFrameGeo
= pMyFrameLayout
->GetGeometry();
127 // original image size
128 //double fOrgGrafWidth = (double)m_Cache.Width/TWIPS_PER_CM;
129 //double fOrgGrafHeight = (double)m_Cache.Height/TWIPS_PER_CM;
132 double fLeftMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_LEFT
);
133 double fRightMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_RIGHT
);
134 double fTopMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_TOP
);
135 double fBottomMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_BOTTOM
);
137 if (pMyScale
&& pFrameGeo
)
140 double fFrameWidth
= LwpTools::ConvertFromUnitsToMetric(pFrameGeo
->GetWidth());
141 double fFrameHeight
= LwpTools::ConvertFromUnitsToMetric(pFrameGeo
->GetHeight());
143 // calculate the displayed size of the frame
144 double fDisFrameWidth
= fFrameWidth
- (fLeftMargin
+fRightMargin
);
145 double fDisFrameHeight
= fFrameHeight
- (fTopMargin
+fBottomMargin
);
148 sal_uInt16 nScalemode
= pMyScale
->GetScaleMode();
149 if (nScalemode
& LwpLayoutScale::CUSTOM
)
151 fSclGrafWidth
= LwpTools::ConvertFromUnitsToMetric(pMyScale
->GetScaleWidth());
152 fSclGrafHeight
= LwpTools::ConvertFromUnitsToMetric(pMyScale
->GetScaleHeight());
154 else if (nScalemode
& LwpLayoutScale::PERCENTAGE
)
156 double fScalePercentage
= (double)pMyScale
->GetScalePercentage() / 1000;
157 fSclGrafWidth
= fScalePercentage
* fWidth
;
158 fSclGrafHeight
= fScalePercentage
* fHeight
;
160 else if (nScalemode
& LwpLayoutScale::FIT_IN_FRAME
)
162 if (pMyFrameLayout
->IsFitGraphic())
164 fSclGrafWidth
= fWidth
;
165 fSclGrafHeight
= fHeight
;
167 else if (nScalemode
& LwpLayoutScale::MAINTAIN_ASPECT_RATIO
)
169 if (fWidth
/fHeight
>= fDisFrameWidth
/fDisFrameHeight
)
171 fSclGrafWidth
= fDisFrameWidth
;
172 fSclGrafHeight
= (fDisFrameWidth
/fWidth
) * fHeight
;
176 fSclGrafHeight
= fDisFrameHeight
;
177 fSclGrafWidth
= (fDisFrameHeight
/fHeight
) * fWidth
;
182 fSclGrafWidth
= fDisFrameWidth
;
183 fSclGrafHeight
= fDisFrameHeight
;
188 fWidth
= fSclGrafWidth
;
189 fHeight
= fSclGrafHeight
;
194 * @descr: construction function
195 * @param: objHdr - object header, read before entering this function
196 * @param: pStrm - file stream
200 LwpOleObject::LwpOleObject(LwpObjectHeader
&objHdr
, LwpSvStream
* pStrm
)
201 : LwpGraphicOleObject(objHdr
, pStrm
),m_SizeRect(0,0,5,5)
205 * @descr: Read VO_OLEOBJECT record
210 void LwpOleObject::Read()
212 LwpGraphicOleObject::Read();
214 cPersistentFlags
= m_pObjStrm
->QuickReaduInt16();
216 sal_uInt16 nNonVersionedPersistentFlags
= 0;
217 sal_uInt32 nFormat
= 0;
218 sal_uInt16 nNumberOfPages
= 0;
222 if (LwpFileHeader::m_nFileRevision
>= 0x0004)
224 nNonVersionedPersistentFlags
= m_pObjStrm
->QuickReaduInt16();
226 OUString sFormat
= m_pObjStrm
->QuickReadStringPtr();
228 if (LwpFileHeader::m_nFileRevision
< 0x000B)
230 // null pointers have a VO_INVALID type
231 //if (VO_INVALID == m_pObjStrm->QuickReaduInt16())
235 //return m_pObjStrm->Locate(ID);
239 ID
.ReadIndexed(m_pObjStrm
);
243 //return m_pObjStrm->Locate(ID);
247 if (m_pObjStrm
->CheckExtra())
249 nNumberOfPages
= m_pObjStrm
->QuickReaduInt16();
250 m_pObjStrm
->SkipExtra();
255 * @descr: Construct ole-storage name by ObjectID
256 * @param: pObjName - input&output string of object name, spaces allocated outside and at least length should be MAX_STREAMORSTORAGENAME
260 void LwpOleObject::GetChildStorageName(char *pObjName
)
262 /*LwpObjectFactory * pObjMgr = LwpObjectFactory::Instance();
263 LwpIndexManager * pIdxMgr = pObjMgr->GetIndexManager();
264 sal_uInt32 nLowID = pIdxMgr->GetObjTime(static_cast<sal_uInt16>(GetObjectID()->GetLow()));*/
266 char sName
[MAX_STREAMORSTORAGENAME
];
267 //LwpObjectID ID(nLowID, GetObjectID()->GetHigh());
268 sprintf( sName
, "%s%lX,%lX", "Ole",
269 GetObjectID()->GetHigh(), GetObjectID()->GetLow());
271 strcpy( pObjName
, sName
);
275 * @descr: Parse VO_OLEOBJECT and dump to XML stream only on WIN32 platform
276 * @param: pOutputStream - stream to dump OLE object
277 * @param: pFrameLayout - framlayout object used to dump OLE object
281 void LwpOleObject::Parse(IXFStream
* pOutputStream
)
287 // Construct OLE object storage name
289 char sObjectName
[MAX_STREAMORSTORAGENAME
];
290 GetChildStorageName(sObjectName
);
291 String aObjName
= String::CreateFromAscii(sObjectName
);
294 // Get OLE objects information
296 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
297 LwpObjectFactory
* pObjMgr
= pGlobal
->GetLwpObjFactory();
298 SvStorageRef objStor
;
299 SvStorageInfoList
* pInfoList
;
300 pObjMgr
->GetOleObjInfo(objStor
, &pInfoList
);
302 if(pInfoList
== NULL
)
309 // Get ole object buffer
312 sal_uInt32 nSize
= 0;
313 for (sal_uInt32 j
=0; j
<pInfoList
->Count(); j
++)
316 SvStorageInfo
& rInfo
= pInfoList
->GetObject(j
);
317 String aName
= rInfo
.GetName();
319 if(aName
== aObjName
)
321 SvStorageRef childStor
;
322 childStor
= objStor
->OpenStorage(rInfo
.GetName());
323 SvStorage
* aEleStor
;
324 aEleStor
= objStor
->OpenOLEStorage( rInfo
.GetName() );
325 SvInPlaceObjectRef
xInplaceObj( ((SvFactory
*)SvInPlaceObject::ClassFactory())->CreateAndLoad( childStor
) );
326 SvOutPlaceObjectRef
xOutplaceObj(xInplaceObj
);
327 aEleStor
->SetVersion( SOFFICE_FILEFORMAT_60
);
328 SvStream
*pStream
=xOutplaceObj
->GetOLEObjectStream(aEleStor
);
330 //Get Ole original size
331 m_SizeRect
= xOutplaceObj
->GetVisSize(xOutplaceObj
->GetViewAspect());
333 nSize
= pStream
->Seek( STREAM_SEEK_TO_END
);
334 pBuf
= new BYTE
[nSize
];
341 pStream
->Read(pBuf
, nSize
);
349 // dump the buffer by XFilter
354 XFOleObject
*pOleObj
= new XFOleObject();
355 pOleObj
->SetOleData(pBuf
, nSize
);
357 // set frame attributes
358 pOleObj
->SetAnchorType(enumXFAnchorPara
);
361 GetGrafScaledSize( fWidth
, fHeight
);
362 if(fWidth
< 0.001 || fHeight
< 0.001)
367 pOleObj
->SetWidth(fWidth
);
368 pOleObj
->SetHeight(fHeight
);
370 pOleObj->SetName(A2OUSTR("TestOle"));
373 pOleObj->SetWidth(5);
374 pOleObj->SetHeight(5);
378 XFParagraph
*pPara
= new XFParagraph();
380 pPara
->ToXml(pOutputStream
);
382 delete pPara
; // pOleObj will be deleted inside
386 String
aTempDir( SvtPathOptions().GetTempPath() );
387 sal_Int32 nLength
= aTempDir
.Len();
388 if ( aTempDir
.GetChar(nLength
-1 ) !=UChar32( '/' ) )
389 aTempDir
+= String::CreateFromAscii("/");
391 aTempDir
+= aObjName
;
392 SvFileStream
aStream(aTempDir
, STREAM_WRITE
);
393 aStream
.Write(pBuf
, nSize
);
398 // dump attributes to
406 void LwpOleObject::XFConvert(XFContentContainer
* pCont
)
410 //Get ole object stream with the object name;
413 // if small file, use the compressed stream for BENTO
414 LwpSvStream
* pStream
= m_pStrm
->GetCompressedStream() ? m_pStrm
->GetCompressedStream(): m_pStrm
;
417 OpenStormBento::LtcBenContainer
* pBentoContainer
;
418 ULONG ulRet
= OpenStormBento::BenOpenContainer(pStream
, &pBentoContainer
);
420 char sObjectName
[MAX_STREAMORSTORAGENAME
];
421 GetChildStorageName(sObjectName
);
422 std::string
aObjName(sObjectName
);
423 SotStorageStreamRef xOleObjStm
= pBentoContainer
->ConvertAswStorageToOLE2Stream(aObjName
.c_str());
425 //Get stream size and data
426 if(!xOleObjStm
.Is() || xOleObjStm
->GetError())
431 sal_uInt32 nSize
= 0;
433 SvStorageRef xOleObjStor
= new SvStorage( *xOleObjStm
);
434 //SvStorageRef xOleObjStor = pBentoContainer->CreateOLEStorageWithObjectName(aObjName.c_str());
435 if( !xOleObjStor
.Is())
438 SvInPlaceObjectRef
xInplaceObj( ((SvFactory
*)SvInPlaceObject::ClassFactory())->CreateAndLoad( xOleObjStor
) );
441 //when the OLE object is converted into native object.
442 // SvOutPlaceObjectRef xOutplaceObj(xInplaceObj);
443 // xOutplaceObj->SetVersion( SOFFICE_FILEFORMAT_60 );
444 // SvStream *pOleStream=xOutplaceObj->GetOLEObjectStream(xOleObjStor);
445 //Get Ole original size
446 m_SizeRect
= GetOLEObjectSize(xOleObjStor
);
449 nSize
= xOleObjStm
->Seek( STREAM_SEEK_TO_END
);
450 pBuf
= new BYTE
[nSize
];
457 xOleObjStm
->Read(pBuf
, nSize
);
465 // dump the buffer by XFilter
470 XFOleObject
*pOleObj
= new XFOleObject();
471 pOleObj
->SetOleData(pBuf
, nSize
);
473 // set frame attributes
474 pOleObj
->SetAnchorType(enumXFAnchorFrame
);
475 pOleObj
->SetStyleName( m_strStyleName
);
476 LwpFrameLayout
* pMyFrameLayout
= static_cast<LwpFrameLayout
*>(GetLayout(NULL
));
479 pOleObj
->SetX(pMyFrameLayout
->GetMarginsValue(MARGIN_LEFT
));
480 pOleObj
->SetY(pMyFrameLayout
->GetMarginsValue(MARGIN_TOP
));
485 GetGrafScaledSize( fWidth
, fHeight
);
486 if(fWidth
< 0.001 || fHeight
< 0.001)
493 pOleObj
->SetWidth(fWidth
);
494 pOleObj
->SetHeight(fHeight
);
497 //delete pPara; // pOleObj will be deleted inside
502 String
aTempDir( SvtPathOptions().GetTempPath() );
503 sal_Int32 nLength
= aTempDir
.Len();
504 if ( aTempDir
.GetChar(nLength
-1 ) !=UChar32( '/' ) )
505 aTempDir
+= String::CreateFromAscii("/");
507 aTempDir
+= aObjName
;
508 SvFileStream
aStream(aTempDir
, STREAM_WRITE
);
509 aStream
.Write(pBuf
, nSize
);
514 // dump attributes to
520 void LwpOleObject::GetGrafOrgSize(double & rWidth
, double & rHeight
)
522 rWidth
= (double)m_SizeRect
.GetWidth()/1000;//cm unit
523 rHeight
= (double)m_SizeRect
.GetHeight()/1000;//cm unit
526 void LwpOleObject::RegisterStyle()
530 LwpVirtualLayout
* pMyLayout
= GetLayout(NULL
);
531 if(pMyLayout
->IsFrame())
533 XFFrameStyle
* pXFFrameStyle
= new XFFrameStyle();
534 pXFFrameStyle
->SetXPosType(enumXFFrameXPosFromLeft
, enumXFFrameXRelFrame
);
535 pXFFrameStyle
->SetYPosType(enumXFFrameYPosFromTop
, enumXFFrameYRelPara
);
536 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
537 m_strStyleName
= pXFStyleManager
->AddStyle(pXFFrameStyle
)->GetStyleName();
544 #include <sot/exchange.hxx>
545 #include <sot/storinfo.hxx>
546 #include <svtools/wmf.hxx>
548 * @descr: For SODC_2667, To get the OLE object size by reading OLE object picture information.
550 Rectangle
LwpOleObject::GetOLEObjectSize( SotStorage
* pStor
) const
552 Rectangle
aSize(0,0,0,0);
554 if( pStor
->IsContained( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\002OlePres000" ) ) ) )
555 aStreamName
= String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\002OlePres000" ) );
556 else if( pStor
->IsContained( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\1Ole10Native" ) ) ) )
557 aStreamName
= String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\1Ole10Native" ) );
559 if( aStreamName
.Len() == 0 )
563 for( USHORT i
= 1; i
< 10; i
++ )
565 SotStorageStreamRef xStm
= pStor
->OpenSotStream( aStreamName
,
566 STREAM_READ
| STREAM_NOCREATE
);
567 if( xStm
->GetError() )
570 xStm
->SetBufferSize( 8192 );
571 LwpOlePres
* pEle
= new LwpOlePres( 0 );
572 if( pEle
->Read( *xStm
) && !xStm
->GetError() )
574 if( pEle
->GetFormat() == FORMAT_GDIMETAFILE
|| pEle
->GetFormat() == FORMAT_BITMAP
)
576 aSize
= Rectangle( Point(), pEle
->GetSize());
583 aStreamName
= String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\002OlePres00" ) );
584 aStreamName
+= String( i
);
590 * @descr: Read OLE object picture information
592 BOOL
LwpOlePres::Read( SvStream
& rStm
)
595 ULONG nBeginPos
= rStm
.Tell();
602 if( rStm
.GetError() == SVSTREAM_OK
)
604 nFormat
= FORMAT_BITMAP
;
605 aSize
= pBmp
->GetPrefSize();
607 if( !aSize
.Width() || !aSize
.Height() )
610 aSize
= pBmp
->GetSizePixel();
614 aMMSrc
= pBmp
->GetPrefMapMode();
615 MapMode
aMMDst( MAP_100TH_MM
);
616 aSize
= OutputDevice::LogicToLogic( aSize
, aMMSrc
, aMMDst
);
624 pMtf
= new GDIMetaFile();
627 if( rStm
.GetError() == SVSTREAM_OK
)
629 nFormat
= FORMAT_GDIMETAFILE
;
630 aSize
= pMtf
->GetPrefSize();
631 MapMode aMMSrc
= pMtf
->GetPrefMapMode();
632 MapMode
aMMDst( MAP_100TH_MM
);
633 aSize
= OutputDevice::LogicToLogic( aSize
, aMMSrc
, aMMDst
);
646 rStm
.Seek( nBeginPos
);
647 nFormat
= ReadClipboardFormat( rStm
);
648 // JobSetup, bzw. TargetDevice ueberlesen
649 // Information aufnehmen, um sie beim Schreiben nicht zu verlieren
657 pJob
= new BYTE
[ nJobLen
];
658 rStm
.Read( pJob
, nJobLen
);
663 rStm
.SetError( SVSTREAM_GENERALERROR
);
668 USHORT nSvAsp
= USHORT( nAsp
);
670 rStm
.SeekRel( 4 ); //L-Index ueberlesen
672 rStm
.SeekRel( 4 ); //Compression
676 rStm
>> nWidth
>> nHeight
>> nSize
;
677 aSize
.Width() = nWidth
;
678 aSize
.Height() = nHeight
;
680 if( nFormat
== FORMAT_GDIMETAFILE
)
682 pMtf
= new GDIMetaFile();
683 ReadWindowMetafile( rStm
, *pMtf
);
685 else if( nFormat
== FORMAT_BITMAP
)
692 void * p
= new BYTE
[ nSize
];
693 rStm
.Read( p
, nSize
);
702 * @descr: Write OLE object picture information.
704 void LwpOlePres::Write( SvStream
& rStm
)
706 WriteClipboardFormat( rStm
, FORMAT_GDIMETAFILE
);
707 rStm
<< (INT32
)(nJobLen
+4); // immer leeres TargetDevice
709 rStm
.Write( pJob
, nJobLen
);
710 rStm
<< (UINT32
)nAspect
;
711 rStm
<< (INT32
)-1; //L-Index immer -1
712 rStm
<< (INT32
)nAdvFlags
;
713 rStm
<< (INT32
)0; //Compression
714 rStm
<< (INT32
)aSize
.Width();
715 rStm
<< (INT32
)aSize
.Height();
716 ULONG nPos
= rStm
.Tell();
719 if( GetFormat() == FORMAT_GDIMETAFILE
&& pMtf
)
721 // Immer auf 1/100 mm, bis Mtf-Loesung gefunden
722 // Annahme (keine Skalierung, keine Org-Verschiebung)
723 DBG_ASSERT( pMtf
->GetPrefMapMode().GetScaleX() == Fraction( 1, 1 ),
724 "X-Skalierung im Mtf" );
725 DBG_ASSERT( pMtf
->GetPrefMapMode().GetScaleY() == Fraction( 1, 1 ),
726 "Y-Skalierung im Mtf" );
727 DBG_ASSERT( pMtf
->GetPrefMapMode().GetOrigin() == Point(),
728 "Origin-Verschiebung im Mtf" );
729 MapUnit nMU
= pMtf
->GetPrefMapMode().GetMapUnit();
730 if( MAP_100TH_MM
!= nMU
)
732 Size
aPrefS( pMtf
->GetPrefSize() );
734 aS
= OutputDevice::LogicToLogic( aS
, nMU
, MAP_100TH_MM
);
736 pMtf
->Scale( Fraction( aS
.Width(), aPrefS
.Width() ),
737 Fraction( aS
.Height(), aPrefS
.Height() ) );
738 pMtf
->SetPrefMapMode( MAP_100TH_MM
);
739 pMtf
->SetPrefSize( aS
);
741 WriteWindowMetafileBits( rStm
, *pMtf
);
745 DBG_ERROR( "unknown format" );
747 ULONG nEndPos
= rStm
.Tell();
749 rStm
<< (UINT32
)(nEndPos
- nPos
- 4);
750 rStm
.Seek( nEndPos
);