merge the formfield patch from ooo-build
[ooovba.git] / lotuswordpro / source / filter / lwpchartstreamtools.cxx
blob90e0d62ba581769211cf6c4599f3445f53f4a18a
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,
28 * MA 02111-1307 USA
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 /*****************************************************************************
56 * Change History
57 * <<Date>> <<Name of editor>> <<Description>>
58 2005/2 draft code for implementation of chart stream helpers
59 ****************************************************************************/
61 /**
62 * @file
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>
72 /**
73 * @short Get the chart stream from bento layer
74 * @descr
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;
85 pSvStream->Seek(0);
86 OpenStormBento::LtcBenContainer* pContainer = NULL;;
87 ULONG nRet = OpenStormBento::BenOpenContainer(pSvStream,&pContainer);
88 if ( 0==nRet )
90 pStream = pContainer->FindValueStreamWithPropertyName(pChartName);
92 return pStream;
95 /**
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);
107 //write to xml
108 XFParagraph xpara;
109 xpara.Add(pXChart);
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);
121 pCont->Add(pXChart);
123 //write to xml
124 /*XFParagraph* pPara = new XFParagraph();
125 pPara->Add(pXChart);
126 pCont->Add(pPara);
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();
140 pStream->Seek(nPos);
141 return nStrmLen;
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);
158 aChart.Read();
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();
180 aFilter.Export();
183 //void LwpChartStreamTools::ChartToXML(SvStorageRef xStorage, SvInPlaceObjectRef xIPObj)
185 // xStorage->SetVersion( SOFFICE_FILEFORMAT_60 );
187 // SfxInPlaceObjectRef aSfxObj( xIPObj );
188 // SfxObjectShell* pSh = aSfxObj->GetObjectShell();
189 // pSh->Save();
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) )
202 assert(false);
204 else
206 rStream = xStorage->OpenStream( aStrmName, STREAM_READ | STREAM_NOCREATE );
208 return rStream;
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);
221 rStream->Seek(0);
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);
240 return pChartName;
244 * @short Parse the chart stream in Bento layer.
245 * @descr
246 * @param pOutputStream the pointer to IXFStream, which output the xml content.
247 * @return
248 * @todo any error code return are needed?
250 void LwpChartStreamTools::ParseChart( LwpSvStream* pDocStream,
251 LwpObjectID* pID,
252 Rectangle aRectIn100thMM,
253 XFRect aRectInCM,
254 IXFStream* pOutputStream)
256 XFChartStream* pXFChartStrm = new XFChartStream;
260 //GetChartName
261 const char* pChartName = GetChartName(pID);
263 //Get chart stream
264 SvStream* pStream = GetChartStream( pDocStream, pChartName );
265 if (!pStream)
267 assert(false);
268 return;
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");
279 if (rCntStream.Is())
281 pXFChartStrm->SetChartStream(rCntStream);
284 OutputChart( aRectInCM, pXFChartStrm, pOutputStream);
286 delete pStream;
288 catch (com::sun::star::xml::sax::SAXParseException&) {
289 assert(false);
291 catch( com::sun::star::xml::sax::SAXException& )
293 assert(false);
295 catch( com::sun::star::io::IOException&)
297 assert(false);
299 catch( com::sun::star::uno::Exception&)
301 assert(false);
305 void LwpChartStreamTools::ParseChart( LwpSvStream* pDocStream,
306 LwpObjectID* pID,
307 Rectangle aRectIn100thMM,
308 XFRect aRectInCM,
309 XFContentContainer* pCont,
310 OUString strStyleName)
312 XFChartStream* pXFChartStrm = new XFChartStream;
316 //GetChartName
317 const char* pChartName = GetChartName(pID);
319 //Get chart stream
320 SvStream* pStream = GetChartStream( pDocStream, pChartName );
321 if (!pStream)
323 assert(false);
324 return;
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");
335 if (rCntStream.Is())
337 pXFChartStrm->SetChartStream(rCntStream);
340 OutputChart( aRectInCM, pXFChartStrm, pCont, strStyleName);
342 delete pStream;
344 catch (com::sun::star::xml::sax::SAXParseException& ) {
345 assert(false);
347 catch( com::sun::star::xml::sax::SAXException& )
349 assert(false);
351 catch( com::sun::star::io::IOException&)
353 assert(false);
355 catch( com::sun::star::uno::Exception&)
357 assert(false);