Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / lotuswordpro / source / filter / lwpsdwgrouploaderv0102.cxx
blob6d134a042438c51377f5dc27da51d99ae7435194
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->Read(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;
119 m_pStream->ReadUInt16(nRecCount);
120 // selCount
121 m_pStream->SeekRel(2);
122 //boundrect
123 unsigned short left,top,right,bottom;
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 //load draw object
226 for (unsigned short i = 0; i < nRecCount; i++)
228 XFFrame* pXFDrawObj = CreateDrawObject();
230 if (pXFDrawObj)
232 pDrawObjVector->push_back(pXFDrawObj);
238 * @descr when we encounter a group object the function will be called to create a XF-drawgroup object
239 * the corresponding drawing objects.
240 * @param pDrawObjVector a container which will contains the created drawing object of XF-Model.
242 XFDrawGroup* LwpSdwGroupLoaderV0102::CreateDrawGroupObject()
244 //flag
245 unsigned char BinSignature[2];
246 m_pStream->Read(BinSignature,2);
247 if (BinSignature[0] != 'S' || BinSignature[1] != 'M')
249 assert(false);
250 return nullptr;
252 //version
253 unsigned short nVersion;
254 m_pStream->ReadUInt16(nVersion);
255 if (nVersion<0x0102)
257 assert(false);
258 return nullptr;
260 // topObj, botObj
261 m_pStream->SeekRel(4);
262 //record count
263 unsigned short nRecCount;
264 m_pStream->ReadUInt16(nRecCount);
265 // selCount
266 m_pStream->SeekRel(2);
267 //boundrect
268 unsigned short left,top,right,bottom;
269 m_pStream->ReadUInt16(left);
270 m_pStream->ReadUInt16(top);
271 m_pStream->ReadUInt16(right);
272 m_pStream->ReadUInt16(bottom);
273 // fileSize
274 m_pStream->SeekRel(2);
276 XFDrawGroup* pXFDrawGroup = new XFDrawGroup();
278 //load draw object
279 for (unsigned short i = 0; i < nRecCount; i++)
281 XFFrame* pXFDrawObj = CreateDrawObject();
283 if (pXFDrawObj)
285 if (pXFDrawObj->GetFrameType() == enumXFFrameImage)
287 m_pDrawObjVector->push_back(pXFDrawObj);
289 else
291 pXFDrawGroup->Add(pXFDrawObj);
296 return pXFDrawGroup;
300 * @descr Create the XF-drawing objects according to the object type read from bento stream.
301 * @return the created XF-drawing objects.
303 XFFrame* LwpSdwGroupLoaderV0102::CreateDrawObject()
305 //record type
306 unsigned char recType;
307 m_pStream->ReadUChar(recType);
309 LwpDrawObj* pDrawObj = nullptr;
310 XFFrame* pRetObjct = nullptr;
312 switch(recType)
314 case OT_PERPLINE://fall-through
315 case OT_LINE:
317 pDrawObj = new LwpDrawLine(m_pStream, &m_aTransformData);
318 break;
320 case OT_POLYLINE:
322 pDrawObj = new LwpDrawPolyLine(m_pStream, &m_aTransformData);
323 break;
325 case OT_POLYGON:
327 pDrawObj = new LwpDrawPolygon(m_pStream, &m_aTransformData);
328 pDrawObj->SetObjectType(OT_POLYGON);
329 break;
331 case OT_SQUARE://fall-through
332 case OT_RECT:
334 pDrawObj = new LwpDrawRectangle(m_pStream, &m_aTransformData);
335 break;
337 case OT_RNDSQUARE://fall-through
338 case OT_RNDRECT:
340 pDrawObj = new LwpDrawRectangle(m_pStream, &m_aTransformData);
341 pDrawObj->SetObjectType(OT_RNDRECT);
342 break;
344 case OT_CIRCLE://fall-through
345 case OT_OVAL:
347 pDrawObj = new LwpDrawEllipse(m_pStream, &m_aTransformData);
348 break;
350 case OT_ARC:
352 pDrawObj = new LwpDrawArc(m_pStream, &m_aTransformData);
353 break;
355 case OT_TEXT:
357 pDrawObj = new LwpDrawTextBox(m_pStream);
358 break;
360 case OT_TEXTART:
362 pDrawObj = new LwpDrawTextArt(m_pStream, &m_aTransformData);
363 pDrawObj->SetObjectType(OT_TEXTART);
364 break;
366 case OT_GROUP:
368 m_pStream->SeekRel(2);
369 // read out the object header
370 pDrawObj = new LwpDrawGroup(m_pStream);
372 pRetObjct = CreateDrawGroupObject();
374 // set anchor type
375 pRetObjct->SetAnchorType(enumXFAnchorFrame);
376 break;
378 case OT_CHART://fall-through
379 case OT_METAFILE://fall-through
380 case OT_METAFILEIMG:
382 LwpDrawMetafile aMeta(m_pStream);
383 break;
385 case OT_BITMAP:
386 pDrawObj = new LwpDrawBitmap(m_pStream);
387 pDrawObj->SetObjectType(OT_BITMAP);
388 break;
391 // we don't need create the corresponding XF-object of a group object.
392 if (pDrawObj && recType != OT_GROUP)
394 pRetObjct = pDrawObj->CreateXFDrawObject();
397 if (pDrawObj)
399 delete pDrawObj;
400 pDrawObj = nullptr;
403 return pRetObjct;
406 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */