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 ************************************************************************/
55 /*****************************************************************************
57 * <<Date>> <<Name of editor>> <<Description>>
58 2005/2 draft code for implementation of chart stream helpers
59 ****************************************************************************/
63 * For LWP filter architecture prototype
66 #include "lwpchartstreamtools.hxx"
67 #include "xfilter/xfdrawchart.hxx"
68 #include "xfilter/xfparagraph.hxx"
70 #include <com/sun/star/xml/sax/SAXParseException.hpp>
73 * @short Get the chart stream from bento layer
75 * @param pDocStream the document stream
76 * @param pChartName The name of the requested chart stream
77 * @return pStream The chart stream, may be NULL
79 SvStream
* LwpChartStreamTools::GetChartStream(LwpSvStream
* pDocStream
, const char* pChartName
)
81 // if small file, use the compressed stream for BENTO
82 LwpSvStream
*pSvStream
= pDocStream
->GetCompressedStream() ? pDocStream
->GetCompressedStream(): pDocStream
;
84 SvStream
* pStream
= NULL
;
86 OpenStormBento::LtcBenContainer
* pContainer
= NULL
;;
87 ULONG nRet
= OpenStormBento::BenOpenContainer(pSvStream
,&pContainer
);
90 pStream
= pContainer
->FindValueStreamWithPropertyName(pChartName
);
96 * @short Output the chart into output stream
97 * @param aChartRect the rectangle of the chart
98 * @param pXChartStrm Chart stream
99 * @param pOutputStream the output stream
101 void LwpChartStreamTools::OutputChart(XFRect aChartRect
, IXFContent
* pXChartStrm
, IXFStream
* pOutputStream
)
103 XFDrawChart
* pXChart
= new XFDrawChart
;
104 pXChart
->SetPosition(aChartRect
);
105 pXChart
->Add(pXChartStrm
);
110 xpara
.ToXml(pOutputStream
);
113 void LwpChartStreamTools::OutputChart(XFRect aChartRect
, IXFContent
* pXChartStrm
, XFContentContainer
* pCont
, OUString strStyleName
)
115 XFDrawChart
* pXChart
= new XFDrawChart
;
116 pXChart
->SetStyleName( strStyleName
);
117 pXChart
->SetPosition(aChartRect
);
118 pXChart
->SetAnchorType(enumXFAnchorFrame
);
119 pXChart
->Add(pXChartStrm
);
124 /*XFParagraph* pPara = new XFParagraph();
131 * @short Get the stream length
132 * @param pStream the stream
133 * @param the stream length
135 INT32
LwpChartStreamTools::GetStreamLen(SvStream
* pStream
)
137 UINT32 nPos
= pStream
->Tell();
138 pStream
->Seek(STREAM_SEEK_TO_END
);
139 INT32 nStrmLen
= pStream
->Tell();
145 * @short Make the chart storage object
146 * @param pStream the chart stream
147 * @param aChartRect the rectangle of the chart
148 * @param xIPObj [out]the inplace object
149 * @param xStorage [out]the storage object of the chart
151 #include "lwpchartwrapper.hxx"
152 void LwpChartStreamTools::MakeChartStorage( SvStream
* pStream
, Rectangle aChartRect
, SvInPlaceObjectRef
& xIPObj
, SvStorageRef
& xStorage
)
154 // SfxItemSet aItemSet( rDoc.GetAttrPool()); //Style of chart area
155 INT32 nStrmLen
= GetStreamLen(pStream
);
156 LtcLwpChartWrapper
aChart(pStream
,nStrmLen
);
157 aChart
.CreateChart(aChartRect
,xIPObj
,xStorage
);
162 * @short Translate the storage to XML stream
163 * @param xStorage [out]the storage object of a chart
164 * @param xIPObj [in]the inplace object
166 #include "schxmlwrapper.hxx"
167 void LwpChartStreamTools::ChartToXML(SvStorageRef xStorage
, SvInPlaceObjectRef xIPObj
)
169 xStorage
->SetVersion( SOFFICE_FILEFORMAT_60
);
171 SfxInPlaceObjectRef
aSfxObj( xIPObj
);
172 SfxObjectShell
* pSh
= aSfxObj
->GetObjectShell();
173 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> xModel
= pSh
->GetModel();
175 SchXMLWrapper
aFilter( xModel
, *xStorage
, sal_False
);
177 // update user info before writing
178 pSh
->UpdateDocInfoForSave();
183 //void LwpChartStreamTools::ChartToXML(SvStorageRef xStorage, SvInPlaceObjectRef xIPObj)
185 // xStorage->SetVersion( SOFFICE_FILEFORMAT_60 );
187 // SfxInPlaceObjectRef aSfxObj( xIPObj );
188 // SfxObjectShell* pSh = aSfxObj->GetObjectShell();
193 * @short Get the xml stream from the storage
194 * @param xStorage the storage object
195 * @param aStrmName the stream name
197 SvStorageStreamRef
LwpChartStreamTools::GetStream(SvStorageRef xStorage
, String aStrmName
)
199 SvStorageStreamRef rStream
;
200 if( ! xStorage
->IsStream( aStrmName
) )
206 rStream
= xStorage
->OpenStream( aStrmName
, STREAM_READ
| STREAM_NOCREATE
);
212 * @short Dump the xml stream into a file
214 void LwpChartStreamTools::DumpStream(SvStorageStreamRef rStream
, char* aName
)
216 INT32 nLen
= GetStreamLen(&rStream
);
217 char* pBuf
= new char[nLen
];
218 rStream
->Read(pBuf
, nLen
);
219 std::ofstream
aFile(aName
, ios_base::out
);
220 aFile
.write(pBuf
,nLen
);
225 * @short Get the name of chart stream
226 * @param pID the id of the VO_Graphic object, which map to a chart stream.
227 * @return the name of the chart stream
229 const char* LwpChartStreamTools::GetChartName(LwpObjectID
* pID
)
231 #define MAX_STREAMORSTORAGENAME 32 //The value is got from wordpro source
232 static char pChartName
[MAX_STREAMORSTORAGENAME
];
234 char aGrStrmPrefix
[] = "Gr";
235 char aDataStrmSuffix
[] = "-D";
237 sprintf( (char*)pChartName
,"%s%lX,%lX%s", aGrStrmPrefix
,pID
->GetHigh(),
238 pID
->GetLow(),aDataStrmSuffix
);
244 * @short Parse the chart stream in Bento layer.
246 * @param pOutputStream the pointer to IXFStream, which output the xml content.
248 * @todo any error code return are needed?
250 void LwpChartStreamTools::ParseChart( LwpSvStream
* pDocStream
,
252 Rectangle aRectIn100thMM
,
254 IXFStream
* pOutputStream
)
256 XFChartStream
* pXFChartStrm
= new XFChartStream
;
261 const char* pChartName
= GetChartName(pID
);
264 SvStream
* pStream
= GetChartStream( pDocStream
, pChartName
);
271 SvInPlaceObjectRef xIPObj
;
272 SvStorageRef xStorage
;
274 MakeChartStorage( pStream
, aRectIn100thMM
, xIPObj
, xStorage
);
275 ChartToXML(xStorage
, xIPObj
);
276 // SvStorageStreamRef rStyleStream = GetStream(xStorage,String::CreateFromAscii( "styles.xml" ));
277 SvStorageStreamRef rCntStream
= GetStream(xStorage
,String::CreateFromAscii( "content.xml" ));
278 // DumpStream(rCntStream,"d:\\allinone.xml");
281 pXFChartStrm
->SetChartStream(rCntStream
);
284 OutputChart( aRectInCM
, pXFChartStrm
, pOutputStream
);
288 catch (com::sun::star::xml::sax::SAXParseException
&) {
291 catch( com::sun::star::xml::sax::SAXException
& )
295 catch( com::sun::star::io::IOException
&)
299 catch( com::sun::star::uno::Exception
&)
305 void LwpChartStreamTools::ParseChart( LwpSvStream
* pDocStream
,
307 Rectangle aRectIn100thMM
,
309 XFContentContainer
* pCont
,
310 OUString strStyleName
)
312 XFChartStream
* pXFChartStrm
= new XFChartStream
;
317 const char* pChartName
= GetChartName(pID
);
320 SvStream
* pStream
= GetChartStream( pDocStream
, pChartName
);
327 SvInPlaceObjectRef xIPObj
;
328 SvStorageRef xStorage
;
330 MakeChartStorage( pStream
, aRectIn100thMM
, xIPObj
, xStorage
);
331 ChartToXML(xStorage
, xIPObj
);
332 // SvStorageStreamRef rStyleStream = GetStream(xStorage,String::CreateFromAscii( "styles.xml" ));
333 SvStorageStreamRef rCntStream
= GetStream(xStorage
,String::CreateFromAscii( "content.xml" ));
334 // DumpStream(rCntStream,"d:\\allinone.xml");
337 pXFChartStrm
->SetChartStream(rCntStream
);
340 OutputChart( aRectInCM
, pXFChartStrm
, pCont
, strStyleName
);
344 catch (com::sun::star::xml::sax::SAXParseException
& ) {
347 catch( com::sun::star::xml::sax::SAXException
& )
351 catch( com::sun::star::io::IOException
&)
355 catch( com::sun::star::uno::Exception
&)