build fix
[LibreOffice.git] / lotuswordpro / source / filter / lwpsdwgrouploaderv0102.cxx
blob39d1b3fa501dd04a677ac23e27f372ecbe4b2fc2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
57 #include <tools/stream.hxx>
59 #include "lwpsdwgrouploaderv0102.hxx"
60 #include "lwpdrawobj.hxx"
61 #include "lwptools.hxx"
62 #include "lwpcharsetmgr.hxx"
63 #include "lwpgrfobj.hxx"
64 #include "lwpframelayout.hxx"
66 #include "xfilter/xfcolor.hxx"
67 #include "xfilter/xfdrawline.hxx"
68 #include "xfilter/xfdrawpath.hxx"
69 #include "xfilter/xfdrawpolyline.hxx"
70 #include "xfilter/xfdrawrect.hxx"
71 #include "xfilter/xfdrawpolygon.hxx"
72 #include "xfilter/xfdrawgroup.hxx"
73 #include "xfilter/xfdrawstyle.hxx"
74 #include "xfilter/xfdrawlinestyle.hxx"
75 #include "xfilter/xfparagraph.hxx"
76 #include "xfilter/xfstylemanager.hxx"
78 LwpSdwGroupLoaderV0102::LwpSdwGroupLoaderV0102(SvStream* pStream, LwpGraphicObject* pGraphicObj)
79 : m_pStream(pStream)
80 , m_pGraphicObj(pGraphicObj)
81 , m_pDrawObjVector(nullptr)
85 LwpSdwGroupLoaderV0102::~LwpSdwGroupLoaderV0102()
89 /**
90 * @descr entry of lwp-drawing objects. the function begins to parse the sdw-drawing bento stream and create
91 * the corresponding drawing objects.
92 * @param pDrawObjVector a container which will contains the created drawing object of XF-Model.
94 void LwpSdwGroupLoaderV0102::BeginDrawObjects(std::vector< rtl::Reference<XFFrame> >* pDrawObjVector)
96 // save the container
97 m_pDrawObjVector = pDrawObjVector;
99 //flag
100 unsigned char BinSignature[2];
101 m_pStream->ReadBytes(BinSignature, 2);
102 if (BinSignature[0] != 'S' || BinSignature[1] != 'M')
104 assert(false);
105 return;
107 //version
108 unsigned short nVersion;
109 m_pStream->ReadUInt16(nVersion);
110 if (nVersion<0x0102)
112 assert(false);
113 return;
115 // topObj, botObj
116 m_pStream->SeekRel(4);
117 //record count
118 unsigned short nRecCount(0);
119 m_pStream->ReadUInt16(nRecCount);
120 // selCount
121 m_pStream->SeekRel(2);
122 //boundrect
123 unsigned short left(0),top(0),right(0),bottom(0);
124 m_pStream->ReadUInt16(left);
125 m_pStream->ReadUInt16(top);
126 m_pStream->ReadUInt16(right);
127 m_pStream->ReadUInt16(bottom);
128 // fileSize
129 m_pStream->SeekRel(2);
131 //for calculating transformation params.
132 rtl::Reference<LwpFrameLayout> xMyFrameLayout(dynamic_cast<LwpFrameLayout*>(m_pGraphicObj->GetLayout(nullptr).get()));
133 if (xMyFrameLayout.is())
135 LwpLayoutScale* pMyScale = xMyFrameLayout->GetLayoutScale();
136 LwpLayoutGeometry* pFrameGeo = xMyFrameLayout->GetGeometry();
137 if (pMyScale && pFrameGeo)
139 // original drawing size
140 long nWidth = 0, nHeight = 0;
141 m_pGraphicObj->GetGrafOrgSize(nWidth, nHeight);
142 double fGrafOrgWidth = (double)nWidth/TWIPS_PER_CM;
143 double fGrafOrgHeight = (double)nHeight/TWIPS_PER_CM;
145 // get margin values
146 double fLeftMargin = xMyFrameLayout->GetMarginsValue(MARGIN_LEFT);
147 double fTopMargin = xMyFrameLayout->GetMarginsValue(MARGIN_TOP);
149 // frame size
150 double fFrameWidth = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetWidth());
151 double fFrameHeight = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetHeight());
153 // get frame offset
154 LwpPoint& rOffset = pMyScale->GetOffset();
155 double fOffsetX = LwpTools::ConvertFromUnitsToMetric(rOffset.GetX());
156 double fOffsetY = LwpTools::ConvertFromUnitsToMetric(rOffset.GetY());
158 // get scale mode
159 sal_uInt16 nScalemode = pMyScale->GetScaleMode();
161 if (nScalemode & LwpLayoutScale::CUSTOM)
163 m_aTransformData.fScaleX =
164 LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth()) / fGrafOrgWidth;
165 m_aTransformData.fScaleY =
166 LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight()) / fGrafOrgHeight;
168 else if (nScalemode & LwpLayoutScale::PERCENTAGE)
170 double fScalePercentage = (double)pMyScale->GetScalePercentage() / 1000;
171 m_aTransformData.fScaleX = fScalePercentage;
172 m_aTransformData.fScaleY = fScalePercentage;
174 else if (nScalemode & LwpLayoutScale::FIT_IN_FRAME)
176 double fWidth0 = (double)right / TWIPS_PER_CM;
177 double fHeight0 = (double)bottom / TWIPS_PER_CM;
179 double fWidth1 = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
180 double fHeight1 = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
182 double fScaleX = fWidth1 / fWidth0;
183 double fScaleY = fHeight1 / fHeight0;
185 if (nScalemode & LwpLayoutScale::MAINTAIN_ASPECT_RATIO)
187 m_aTransformData.fScaleX = std::min(fScaleX, fScaleY);
188 m_aTransformData.fScaleY = m_aTransformData.fScaleX;
190 else
192 m_aTransformData.fScaleX = fWidth1 / fWidth0;
193 m_aTransformData.fScaleY = fHeight1 / fHeight0;
197 // placement: centered
198 if (xMyFrameLayout->GetScaleCenter())
200 Rectangle aBoundRect(static_cast<long>(left*m_aTransformData.fScaleX + fLeftMargin),
201 static_cast<long>(top * m_aTransformData.fScaleY + fTopMargin),
202 static_cast<long>(right * m_aTransformData.fScaleX),
203 static_cast<long>(bottom * m_aTransformData.fScaleY));
204 Point aCenter = aBoundRect.Center();
206 double fNewCenterX = (double(left)/TWIPS_PER_CM + fFrameWidth/*-fOffsetX*/) / 2;
207 double fNewCenterY = (double(top)/TWIPS_PER_CM + fFrameHeight/*-fOffsetY*/) / 2;
209 m_aTransformData.fOffsetX = fNewCenterX - (double)aCenter.X()/TWIPS_PER_CM;
210 m_aTransformData.fOffsetY = fNewCenterY -(double)aCenter.Y()/TWIPS_PER_CM;
212 else
214 m_aTransformData.fOffsetX = fOffsetX;
215 m_aTransformData.fOffsetY = fOffsetY;
218 m_aTransformData.fOffsetX += fLeftMargin;
219 m_aTransformData.fOffsetY += fTopMargin;
220 m_aTransformData.fLeftMargin = fLeftMargin;
221 m_aTransformData.fTopMargin = fTopMargin;
225 if (nRecCount > m_pStream->remainingSize())
227 SAL_WARN("lwp", "stream too short for claimed no of records");
228 nRecCount = m_pStream->remainingSize();
231 //load draw object
232 for (unsigned short i = 0; i < nRecCount; i++)
234 XFFrame* pXFDrawObj = CreateDrawObject();
236 if (pXFDrawObj)
238 pDrawObjVector->push_back(pXFDrawObj);
244 * @descr when we encounter a group object the function will be called to create a XF-drawgroup object
245 * the corresponding drawing objects.
246 * @param pDrawObjVector a container which will contains the created drawing object of XF-Model.
248 XFDrawGroup* LwpSdwGroupLoaderV0102::CreateDrawGroupObject()
250 //flag
251 unsigned char BinSignature[2];
252 m_pStream->ReadBytes(BinSignature, 2);
253 if (BinSignature[0] != 'S' || BinSignature[1] != 'M')
255 assert(false);
256 return nullptr;
258 //version
259 unsigned short nVersion;
260 m_pStream->ReadUInt16(nVersion);
261 if (nVersion<0x0102)
263 assert(false);
264 return nullptr;
266 // topObj, botObj
267 m_pStream->SeekRel(4);
268 //record count
269 unsigned short nRecCount(0);
270 m_pStream->ReadUInt16(nRecCount);
271 // selCount
272 m_pStream->SeekRel(2);
273 //boundrect
274 unsigned short left(0),top(0),right(0),bottom(0);
275 m_pStream->ReadUInt16(left);
276 m_pStream->ReadUInt16(top);
277 m_pStream->ReadUInt16(right);
278 m_pStream->ReadUInt16(bottom);
279 // fileSize
280 m_pStream->SeekRel(2);
282 XFDrawGroup* pXFDrawGroup = new XFDrawGroup();
284 if (nRecCount > m_pStream->remainingSize())
286 SAL_WARN("lwp", "stream too short for claimed no of records");
287 nRecCount = m_pStream->remainingSize();
290 //load draw object
291 for (unsigned short i = 0; i < nRecCount; i++)
293 XFFrame* pXFDrawObj = CreateDrawObject();
295 if (pXFDrawObj)
297 if (pXFDrawObj->GetFrameType() == enumXFFrameImage)
299 m_pDrawObjVector->push_back(pXFDrawObj);
301 else
303 pXFDrawGroup->Add(pXFDrawObj);
308 return pXFDrawGroup;
312 * @descr Create the XF-drawing objects according to the object type read from bento stream.
313 * @return the created XF-drawing objects.
315 XFFrame* LwpSdwGroupLoaderV0102::CreateDrawObject()
317 //record type
318 unsigned char recType(0);
319 m_pStream->ReadUChar(recType);
321 LwpDrawObj* pDrawObj = nullptr;
322 XFFrame* pRetObjct = nullptr;
324 switch(recType)
326 case OT_PERPLINE://fall-through
327 case OT_LINE:
329 pDrawObj = new LwpDrawLine(m_pStream, &m_aTransformData);
330 break;
332 case OT_POLYLINE:
334 pDrawObj = new LwpDrawPolyLine(m_pStream, &m_aTransformData);
335 break;
337 case OT_POLYGON:
339 pDrawObj = new LwpDrawPolygon(m_pStream, &m_aTransformData);
340 pDrawObj->SetObjectType(OT_POLYGON);
341 break;
343 case OT_SQUARE://fall-through
344 case OT_RECT:
346 pDrawObj = new LwpDrawRectangle(m_pStream, &m_aTransformData);
347 break;
349 case OT_RNDSQUARE://fall-through
350 case OT_RNDRECT:
352 pDrawObj = new LwpDrawRectangle(m_pStream, &m_aTransformData);
353 pDrawObj->SetObjectType(OT_RNDRECT);
354 break;
356 case OT_CIRCLE://fall-through
357 case OT_OVAL:
359 pDrawObj = new LwpDrawEllipse(m_pStream, &m_aTransformData);
360 break;
362 case OT_ARC:
364 pDrawObj = new LwpDrawArc(m_pStream, &m_aTransformData);
365 break;
367 case OT_TEXT:
369 pDrawObj = new LwpDrawTextBox(m_pStream);
370 break;
372 case OT_TEXTART:
374 pDrawObj = new LwpDrawTextArt(m_pStream, &m_aTransformData);
375 pDrawObj->SetObjectType(OT_TEXTART);
376 break;
378 case OT_GROUP:
380 m_pStream->SeekRel(2);
381 // read out the object header
382 pDrawObj = new LwpDrawGroup(m_pStream);
384 pRetObjct = CreateDrawGroupObject();
386 // set anchor type
387 pRetObjct->SetAnchorType(enumXFAnchorFrame);
388 break;
390 case OT_CHART://fall-through
391 case OT_METAFILE://fall-through
392 case OT_METAFILEIMG:
394 LwpDrawMetafile aMeta(m_pStream);
395 break;
397 case OT_BITMAP:
398 pDrawObj = new LwpDrawBitmap(m_pStream);
399 pDrawObj->SetObjectType(OT_BITMAP);
400 break;
403 // we don't need create the corresponding XF-object of a group object.
404 if (pDrawObj && recType != OT_GROUP)
406 pRetObjct = pDrawObj->CreateXFDrawObject();
409 if (pDrawObj)
411 delete pDrawObj;
412 pDrawObj = nullptr;
415 return pRetObjct;
418 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */