update dev300-m57
[ooovba.git] / lotuswordpro / source / filter / lwpsdwgrouploaderv0102.cxx
blob56a6af959bc8dfe6820508207fc1380d90cd3733
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 * Mar 2005 revised for new processing procedure.
58 * Jan 2005 created
59 ****************************************************************************/
60 #include "lwpsdwgrouploaderv0102.hxx"
61 #include "lwpdrawobj.hxx"
62 #include "lwptools.hxx"
63 #include "lwpcharsetmgr.hxx"
64 #include "lwpgrfobj.hxx"
65 #include "lwpframelayout.hxx"
67 #include "xfilter/xfcolor.hxx"
68 #include "xfilter/xfdrawline.hxx"
69 #include "xfilter/xfdrawpath.hxx"
70 #include "xfilter/xfdrawpolyline.hxx"
71 #include "xfilter/xfdrawrect.hxx"
72 #include "xfilter/xfdrawellipse.hxx"
73 #include "xfilter/xfdrawpolygon.hxx"
74 #include "xfilter/xfdrawgroup.hxx"
75 #include "xfilter/xfdrawcircle.hxx"
76 #include "xfilter/xfdrawstyle.hxx"
77 #include "xfilter/xfdrawlinestyle.hxx"
78 #include "xfilter/xfparagraph.hxx"
79 #include "xfilter/xfstylemanager.hxx"
80 #include "xfilter/xfdrawgroup.hxx"
82 LwpSdwGroupLoaderV0102::LwpSdwGroupLoaderV0102(SvStream* pStream, LwpGraphicObject* pGraphicObj,
83 IXFStream* pOutputStream)
84 :m_pStream(pStream), m_pGraphicObj(pGraphicObj), m_pOutputStream(pOutputStream)
87 LwpSdwGroupLoaderV0102::~LwpSdwGroupLoaderV0102(void)
91 // add by , 03/25/2005
92 /**
93 * @descr entry of lwp-drawing objects. the functin begins to parse the sdw-drawing bento stream and create
94 * the corresponding drawing objects.
95 * @param pDrawObjVector a container which will contains the created drawing object of XF-Model.
97 void LwpSdwGroupLoaderV0102::BeginDrawObjects(std::vector <XFFrame*>* pDrawObjVector)
99 // save the container
100 m_pDrawObjVector = pDrawObjVector;
102 //flag
103 unsigned char BinSignature[2];
104 m_pStream->Read(BinSignature,2);
105 if (BinSignature[0] != 'S' || BinSignature[1] != 'M')
107 assert(false);
108 return;
110 //version
111 unsigned short nVersion;
112 m_pStream->Read(&nVersion,2);
113 if (nVersion<0x0102)
115 assert(false);
116 return;
118 // topObj, botObj
119 m_pStream->SeekRel(4);
120 //record count
121 unsigned short nRecCount;
122 m_pStream->Read(&nRecCount,2);
123 // selCount
124 m_pStream->SeekRel(2);
125 //boundrect
126 unsigned short left,top,right,bottom;
127 m_pStream->Read(&left,2);
128 m_pStream->Read(&top,2);
129 m_pStream->Read(&right,2);
130 m_pStream->Read(&bottom,2);
131 // fileSize
132 m_pStream->SeekRel(2);
134 //for calculating transformation params.
135 LwpFrameLayout* pMyFrameLayout = static_cast<LwpFrameLayout*>(m_pGraphicObj->GetLayout(NULL));
136 if (pMyFrameLayout)
138 LwpLayoutScale* pMyScale = pMyFrameLayout->GetLayoutScale();
139 LwpLayoutGeometry* pFrameGeo = pMyFrameLayout->GetGeometry();
140 if (pMyScale && pFrameGeo)
142 // original drawing size
143 long nWidth = 0, nHeight = 0;
144 m_pGraphicObj->GetGrafOrgSize(nWidth, nHeight);
145 double fGrafOrgWidth = (double)nWidth/TWIPS_PER_CM;
146 double fGrafOrgHeight = (double)nHeight/TWIPS_PER_CM;
148 // get margin values
149 double fLeftMargin = pMyFrameLayout->GetMarginsValue(MARGIN_LEFT);
150 // double fRightMargin = pMyFrameLayout->GetMarginsValue(MARGIN_RIGHT);
151 double fTopMargin = pMyFrameLayout->GetMarginsValue(MARGIN_TOP);
152 // double fBottomMargin = pMyFrameLayout->GetMarginsValue(MARGIN_BOTTOM);
154 // frame size
155 double fFrameWidth = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetWidth());
156 double fFrameHeight = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetHeight());
158 // get frame offset
159 LwpPoint* pOffset = pMyScale->GetOffset();
160 double fOffsetX = LwpTools::ConvertFromUnitsToMetric(pOffset->GetX());
161 double fOffsetY = LwpTools::ConvertFromUnitsToMetric(pOffset->GetY());
163 // get scale mode
164 sal_uInt16 nScalemode = pMyScale->GetScaleMode();
166 if (nScalemode & LwpLayoutScale::CUSTOM)
168 m_aTransformData.fScaleX =
169 LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth()) / fGrafOrgWidth;
170 m_aTransformData.fScaleY =
171 LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight()) / fGrafOrgHeight;
173 else if (nScalemode & LwpLayoutScale::PERCENTAGE)
175 double fScalePercentage = (double)pMyScale->GetScalePercentage() / 1000;
176 m_aTransformData.fScaleX = fScalePercentage;
177 m_aTransformData.fScaleY = fScalePercentage;
179 else if (nScalemode & LwpLayoutScale::FIT_IN_FRAME)
181 double fWidth0 = (double)right / TWIPS_PER_CM;
182 double fHeight0 = (double)bottom / TWIPS_PER_CM;
184 double fWidth1 = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
185 double fHeight1 = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
187 double fScaleX = fWidth1 / fWidth0;
188 double fScaleY = fHeight1 / fHeight0;
190 if (nScalemode & LwpLayoutScale::MAINTAIN_ASPECT_RATIO)
192 m_aTransformData.fScaleX = std::min(fScaleX, fScaleY);
193 m_aTransformData.fScaleY = m_aTransformData.fScaleX;
195 else
197 m_aTransformData.fScaleX = fWidth1 / fWidth0;
198 m_aTransformData.fScaleY = fHeight1 / fHeight0;
202 // placement: centered
203 if (pMyFrameLayout->GetScaleCenter())
205 Rectangle aBoundRect(left*m_aTransformData.fScaleX + fLeftMargin,
206 top*m_aTransformData.fScaleY + fTopMargin,
207 right * m_aTransformData.fScaleX,
208 bottom * m_aTransformData.fScaleY);
209 Point aCenter = aBoundRect.Center();
211 double fNewCenterX = (double(left)/TWIPS_PER_CM + fFrameWidth/*-fOffsetX*/) / 2;
212 double fNewCenterY = (double(top)/TWIPS_PER_CM + fFrameHeight/*-fOffsetY*/) / 2;
214 m_aTransformData.fOffsetX = fNewCenterX - (double)aCenter.X()/TWIPS_PER_CM;
215 m_aTransformData.fOffsetY = fNewCenterY -(double)aCenter.Y()/TWIPS_PER_CM;
217 else
219 m_aTransformData.fOffsetX = fOffsetX;
220 m_aTransformData.fOffsetY = fOffsetY;
223 m_aTransformData.fOffsetX += fLeftMargin;
224 m_aTransformData.fOffsetY += fTopMargin;
225 m_aTransformData.fLeftMargin = fLeftMargin;
226 m_aTransformData.fTopMargin = fTopMargin;
230 //load draw object
231 for (unsigned short i = 0; i < nRecCount; i++)
233 XFFrame* pXFDrawObj = this->CreateDrawObject();
235 if (pXFDrawObj)
237 pDrawObjVector->push_back(pXFDrawObj);
243 * @descr when we encounter a group object the function will be called to create a XF-drawgroup object
244 * the corresponding drawing objects.
245 * @param pDrawObjVector a container which will contains the created drawing object of XF-Model.
247 XFDrawGroup* LwpSdwGroupLoaderV0102::CreateDrawGroupObject(void)
249 //flag
250 unsigned char BinSignature[2];
251 m_pStream->Read(BinSignature,2);
252 if (BinSignature[0] != 'S' || BinSignature[1] != 'M')
254 assert(false);
255 return NULL;
257 //version
258 unsigned short nVersion;
259 m_pStream->Read(&nVersion,2);
260 if (nVersion<0x0102)
262 assert(false);
263 return NULL;
265 // topObj, botObj
266 m_pStream->SeekRel(4);
267 //record count
268 unsigned short nRecCount;
269 m_pStream->Read(&nRecCount,2);
270 // selCount
271 m_pStream->SeekRel(2);
272 //boundrect
273 unsigned short left,top,right,bottom;
274 m_pStream->Read(&left,2);
275 m_pStream->Read(&top,2);
276 m_pStream->Read(&right,2);
277 m_pStream->Read(&bottom,2);
278 // fileSize
279 m_pStream->SeekRel(2);
281 XFDrawGroup* pXFDrawGroup = new XFDrawGroup();
283 //load draw object
284 for (unsigned short i = 0; i < nRecCount; i++)
286 XFFrame* pXFDrawObj = this->CreateDrawObject();
288 if (pXFDrawObj)
290 if (pXFDrawObj->GetFrameType() == enumXFFrameImage)
292 m_pDrawObjVector->push_back(pXFDrawObj);
294 else
296 pXFDrawGroup->Add(pXFDrawObj);
301 return pXFDrawGroup;
305 * @descr Create the XF-drawing objects according to the object type read from bento stream.
306 * @return the created XF-drawing objects.
308 XFFrame* LwpSdwGroupLoaderV0102::CreateDrawObject(void)
310 //record type
311 unsigned char recType;
312 m_pStream->Read(&recType,1);
314 LwpDrawObj* pDrawObj = NULL;
315 XFFrame* pRetObjct = NULL;
317 switch(recType)
319 case OT_PERPLINE://fall-through
320 case OT_LINE:
322 pDrawObj = new LwpDrawLine(m_pStream, &m_aTransformData);
323 break;
325 case OT_POLYLINE:
327 pDrawObj = new LwpDrawPolyLine(m_pStream, &m_aTransformData);
328 break;
330 case OT_POLYGON:
332 pDrawObj = new LwpDrawPolygon(m_pStream, &m_aTransformData);
333 pDrawObj->SetObjectType(OT_POLYGON);
334 break;
336 case OT_SQUARE://fall-through
337 case OT_RECT:
339 pDrawObj = new LwpDrawRectangle(m_pStream, &m_aTransformData);
340 break;
342 case OT_RNDSQUARE://fall-through
343 case OT_RNDRECT:
345 pDrawObj = new LwpDrawRectangle(m_pStream, &m_aTransformData);
346 pDrawObj->SetObjectType(OT_RNDRECT);
347 break;
349 case OT_CIRCLE://fall-through
350 case OT_OVAL:
352 pDrawObj = new LwpDrawEllipse(m_pStream, &m_aTransformData);
353 break;
355 case OT_ARC:
357 pDrawObj = new LwpDrawArc(m_pStream, &m_aTransformData);
358 break;
360 case OT_TEXT:
362 pDrawObj = new LwpDrawTextBox(m_pStream);
363 break;
365 case OT_TEXTART:
367 pDrawObj = new LwpDrawTextArt(m_pStream, &m_aTransformData);
368 pDrawObj->SetObjectType(OT_TEXTART);
369 break;
371 case OT_GROUP:
373 m_pStream->SeekRel(2);
374 // read out the object header
375 pDrawObj = new LwpDrawGroup(m_pStream);
377 pRetObjct = this->CreateDrawGroupObject();
379 // set anchor type
380 pRetObjct->SetAnchorType(enumXFAnchorFrame);
381 break;
383 case OT_CHART://fall-through
384 case OT_METAFILE://fall-through
385 case OT_METAFILEIMG:
387 LwpDrawMetafile aMeta(m_pStream);
388 break;
390 case OT_BITMAP:
391 pDrawObj = new LwpDrawBitmap(m_pStream);
392 pDrawObj->SetObjectType(OT_BITMAP);
393 break;
396 // we don't need create the corresponding XF-object of a group object.
397 if (pDrawObj && recType != OT_GROUP)
399 pRetObjct = pDrawObj->CreateXFDrawObject();
402 if (pDrawObj)
404 delete pDrawObj;
405 pDrawObj = NULL;
408 return pRetObjct;
410 // end add