LibreOffice Module lotuswordpro (master) 1
lwpsdwgrouploaderv0102.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
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
16 *
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.
20 *
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.
25 *
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
30 *
31 *
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.
38 *
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.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
56
57#include <tools/stream.hxx>
58
60#include "lwpdrawobj.hxx"
61#include <lwptools.hxx>
62#include "lwpgrfobj.hxx"
63#include "lwpframelayout.hxx"
64
66#include <sal/log.hxx>
67
69 : m_pStream(pStream)
70 , m_pGraphicObj(pGraphicObj)
71 , m_pDrawObjVector(nullptr)
72{
73}
74
81{
82 // save the container
83 m_pDrawObjVector = pDrawObjVector;
84
85 //flag
86 unsigned char BinSignature[2];
87 m_pStream->ReadBytes(BinSignature, 2);
88 if (BinSignature[0] != 'S' || BinSignature[1] != 'M')
89 {
90 assert(false);
91 return;
92 }
93 //version
94 unsigned short nVersion;
96 if (nVersion<0x0102)
97 {
98 assert(false);
99 return;
100 }
101 // topObj, botObj
102 m_pStream->SeekRel(4);
103 //record count
104 unsigned short nRecCount(0);
105 m_pStream->ReadUInt16(nRecCount);
106 // selCount
107 m_pStream->SeekRel(2);
108 //boundrect
109 unsigned short left(0),top(0),right(0),bottom(0);
114 // fileSize
115 m_pStream->SeekRel(2);
116
117 //for calculating transformation params.
118 rtl::Reference<LwpFrameLayout> xMyFrameLayout(dynamic_cast<LwpFrameLayout*>(m_pGraphicObj->GetLayout(nullptr).get()));
119 if (xMyFrameLayout.is())
120 {
121 LwpLayoutScale* pMyScale = xMyFrameLayout->GetLayoutScale();
122 LwpLayoutGeometry* pFrameGeo = xMyFrameLayout->GetGeometry();
123 if (pMyScale && pFrameGeo)
124 {
125 // original drawing size
126 tools::Long nWidth = 0, nHeight = 0;
127 m_pGraphicObj->GetGrafOrgSize(nWidth, nHeight);
128 double fGrafOrgWidth = static_cast<double>(nWidth)/TWIPS_PER_CM;
129 double fGrafOrgHeight = static_cast<double>(nHeight)/TWIPS_PER_CM;
130
131 // get margin values
132 double fLeftMargin = xMyFrameLayout->GetMarginsValue(MARGIN_LEFT);
133 double fTopMargin = xMyFrameLayout->GetMarginsValue(MARGIN_TOP);
134
135 // frame size
136 double fFrameWidth = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetWidth());
137 double fFrameHeight = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetHeight());
138
139 // get frame offset
140 LwpPoint& rOffset = pMyScale->GetOffset();
141 double fOffsetX = LwpTools::ConvertFromUnitsToMetric(rOffset.GetX());
142 double fOffsetY = LwpTools::ConvertFromUnitsToMetric(rOffset.GetY());
143
144 // get scale mode
145 sal_uInt16 nScalemode = pMyScale->GetScaleMode();
146
147 if (nScalemode & LwpLayoutScale::CUSTOM)
148 {
150 LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth()) / fGrafOrgWidth;
152 LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight()) / fGrafOrgHeight;
153 }
154 else if (nScalemode & LwpLayoutScale::PERCENTAGE)
155 {
156 double fScalePercentage = static_cast<double>(pMyScale->GetScalePercentage()) / 1000;
157 m_aTransformData.fScaleX = fScalePercentage;
158 m_aTransformData.fScaleY = fScalePercentage;
159 }
160 else if (nScalemode & LwpLayoutScale::FIT_IN_FRAME)
161 {
162 double fWidth0 = static_cast<double>(right) / TWIPS_PER_CM;
163 double fHeight0 = static_cast<double>(bottom) / TWIPS_PER_CM;
164
165 double fWidth1 = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
166 double fHeight1 = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
167
168 double fScaleX = fWidth1 / fWidth0;
169 double fScaleY = fHeight1 / fHeight0;
170
172 {
173 m_aTransformData.fScaleX = std::min(fScaleX, fScaleY);
175 }
176 else
177 {
178 m_aTransformData.fScaleX = fWidth1 / fWidth0;
179 m_aTransformData.fScaleY = fHeight1 / fHeight0;
180 }
181 }
182
183 // placement: centered
184 if (xMyFrameLayout->GetScaleCenter())
185 {
186 tools::Rectangle aBoundRect(static_cast<tools::Long>(left*m_aTransformData.fScaleX + fLeftMargin),
187 static_cast<tools::Long>(top * m_aTransformData.fScaleY + fTopMargin),
190 Point aCenter = aBoundRect.Center();
191
192 double fNewCenterX = (double(left)/TWIPS_PER_CM + fFrameWidth/*-fOffsetX*/) / 2;
193 double fNewCenterY = (double(top)/TWIPS_PER_CM + fFrameHeight/*-fOffsetY*/) / 2;
194
195 m_aTransformData.fOffsetX = fNewCenterX - static_cast<double>(aCenter.X())/TWIPS_PER_CM;
196 m_aTransformData.fOffsetY = fNewCenterY -static_cast<double>(aCenter.Y())/TWIPS_PER_CM;
197 }
198 else
199 {
200 m_aTransformData.fOffsetX = fOffsetX;
201 m_aTransformData.fOffsetY = fOffsetY;
202 }
203
204 m_aTransformData.fOffsetX += fLeftMargin;
205 m_aTransformData.fOffsetY += fTopMargin;
206 m_aTransformData.fLeftMargin = fLeftMargin;
207 m_aTransformData.fTopMargin = fTopMargin;
208 }
209 }
210
211 if (nRecCount > m_pStream->remainingSize())
212 {
213 SAL_WARN("lwp", "stream too short for claimed no of records");
214 nRecCount = m_pStream->remainingSize();
215 }
216
217 //load draw object
218 for (unsigned short i = 0; i < nRecCount; i++)
219 {
221 if (xXFDrawObj)
222 {
223 pDrawObjVector->push_back(xXFDrawObj);
224 }
225 }
226}
227
234{
235 //flag
236 unsigned char BinSignature[2];
237 if (m_pStream->ReadBytes(BinSignature, 2) != 2)
238 return nullptr;
239 if (BinSignature[0] != 'S' || BinSignature[1] != 'M')
240 return nullptr;
241 //version
242 unsigned short nVersion(0);
244 if (nVersion<0x0102)
245 return nullptr;
246 // topObj, botObj
247 m_pStream->SeekRel(4);
248 //record count
249 unsigned short nRecCount(0);
250 m_pStream->ReadUInt16(nRecCount);
251 // selCount
252 m_pStream->SeekRel(2);
253 //boundrect
254 unsigned short left(0),top(0),right(0),bottom(0);
259 // fileSize
260 m_pStream->SeekRel(2);
261
262 rtl::Reference<XFDrawGroup> xXFDrawGroup(new XFDrawGroup());
263
264 if (nRecCount > m_pStream->remainingSize())
265 {
266 SAL_WARN("lwp", "stream too short for claimed no of records");
267 nRecCount = m_pStream->remainingSize();
268 }
269
270 //load draw object
271 for (unsigned short i = 0; i < nRecCount; i++)
272 {
274
275 if (xXFDrawObj)
276 {
277 if (xXFDrawObj->GetFrameType() == enumXFFrameImage)
278 {
279 m_pDrawObjVector->push_back(xXFDrawObj);
280 }
281 else
282 {
283 xXFDrawGroup->Add(xXFDrawObj.get());
284 }
285 }
286 }
287
288 return xXFDrawGroup;
289}
290
296{
297 //record type
298 unsigned char recType(0);
299 m_pStream->ReadUChar(recType);
300
301 std::unique_ptr<LwpDrawObj> pDrawObj;
302 rtl::Reference<XFFrame> xRetObject;
303
304 switch(recType)
305 {
306 case OT_PERPLINE://fall-through
307 case OT_LINE:
308 {
309 pDrawObj.reset(new LwpDrawLine(m_pStream, &m_aTransformData));
310 break;
311 }
312 case OT_POLYLINE:
313 {
314 pDrawObj.reset(new LwpDrawPolyLine(m_pStream, &m_aTransformData));
315 break;
316 }
317 case OT_POLYGON:
318 {
319 pDrawObj.reset(new LwpDrawPolygon(m_pStream, &m_aTransformData));
320 pDrawObj->SetObjectType(OT_POLYGON);
321 break;
322 }
323 case OT_SQUARE://fall-through
324 case OT_RECT:
325 {
326 pDrawObj.reset(new LwpDrawRectangle(m_pStream, &m_aTransformData));
327 break;
328 }
329 case OT_RNDSQUARE://fall-through
330 case OT_RNDRECT:
331 {
332 pDrawObj.reset(new LwpDrawRectangle(m_pStream, &m_aTransformData));
333 pDrawObj->SetObjectType(OT_RNDRECT);
334 break;
335 }
336 case OT_CIRCLE://fall-through
337 case OT_OVAL:
338 {
339 pDrawObj.reset(new LwpDrawEllipse(m_pStream, &m_aTransformData));
340 break;
341 }
342 case OT_ARC:
343 {
344 pDrawObj.reset(new LwpDrawArc(m_pStream, &m_aTransformData));
345 break;
346 }
347 case OT_TEXT:
348 {
349 pDrawObj.reset(new LwpDrawTextBox(m_pStream));
350 break;
351 }
352 case OT_TEXTART:
353 {
354 pDrawObj.reset(new LwpDrawTextArt(m_pStream, &m_aTransformData));
355 pDrawObj->SetObjectType(OT_TEXTART);
356 break;
357 }
358 case OT_GROUP:
359 {
360 m_pStream->SeekRel(2);
361 // read out the object header
362 pDrawObj.reset(new LwpDrawGroup(m_pStream));
363
364 xRetObject = CreateDrawGroupObject();
365
366 if (xRetObject)
367 {
368 // set anchor type
369 xRetObject->SetAnchorType(enumXFAnchorFrame);
370 }
371 break;
372 }
373 case OT_CHART://fall-through
374 case OT_METAFILE://fall-through
375 case OT_METAFILEIMG:
376 {
378 break;
379 }
380 case OT_BITMAP:
381 pDrawObj.reset(new LwpDrawBitmap(m_pStream));
382 pDrawObj->SetObjectType(OT_BITMAP);
383 break;
384 }
385
386 // we don't need create the corresponding XF-object of a group object.
387 if (pDrawObj && recType != OT_GROUP)
388 {
389 xRetObject = pDrawObj->CreateXFDrawObject();
390 }
391
392 return xRetObject;
393}
394
395/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< LwpVirtualLayout > GetLayout(LwpVirtualLayout const *pStartLayout)
Definition: lwpcontent.cxx:124
Lwp-draw-arc object.
Definition: lwpdrawobj.hxx:272
Lwp-draw-bitmap object.
Definition: lwpdrawobj.hxx:359
Lwp-draw-ellipse object.
Definition: lwpdrawobj.hxx:253
Lwp-draw-group object.
Definition: lwpdrawobj.hxx:151
Lwp-draw-line object.
Definition: lwpdrawobj.hxx:170
Lwp-draw-metafile object.
Definition: lwpdrawobj.hxx:340
Lwp-draw-polyline object.
Definition: lwpdrawobj.hxx:189
Lwp-draw-polygon object.
Definition: lwpdrawobj.hxx:210
Lwp-draw-rectangle(rounded-corner rectangle) object.
Definition: lwpdrawobj.hxx:231
VO_FRAMELAYOUT object.
void GetGrafOrgSize(tools::Long &rWidth, tools::Long &rHeight)
Definition: lwpgrfobj.hxx:122
sal_Int32 GetHeight() const
Definition: lwplaypiece.hxx:86
sal_Int32 GetWidth() const
Definition: lwplaypiece.hxx:85
sal_uInt32 GetScalePercentage() const
LwpPoint & GetOffset()
sal_uInt16 GetScaleMode() const
sal_Int32 GetScaleWidth() const
sal_Int32 GetScaleHeight() const
point class
sal_Int32 GetY() const
sal_Int32 GetX() const
DrawingOffsetAndScale m_aTransformData
std::vector< rtl::Reference< XFFrame > > * m_pDrawObjVector
void BeginDrawObjects(std::vector< rtl::Reference< XFFrame > > *pDrawObjVector)
@descr entry of lwp-drawing objects.
LwpGraphicObject * m_pGraphicObj
rtl::Reference< XFDrawGroup > CreateDrawGroupObject()
@descr when we encounter a group object the function will be called to create a XF-drawgroup object t...
LwpSdwGroupLoaderV0102(SvStream *pStream, LwpGraphicObject *pGraphicObj)
rtl::Reference< XFFrame > CreateDrawObject()
@descr Create the XF-drawing objects according to the object type read from bento stream.
static double ConvertFromUnitsToMetric(sal_Int32 nUnits)
Definition: lwptools.hxx:117
constexpr tools::Long Y() const
constexpr tools::Long X() const
std::size_t ReadBytes(void *pData, std::size_t nSize)
sal_uInt64 SeekRel(sal_Int64 nPos)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
sal_uInt64 remainingSize()
SvStream & ReadUChar(unsigned char &rChar)
Group object for drawing.
Definition: xfdrawgroup.hxx:73
constexpr Point Center() const
OString right
OString top
OString bottom
sal_Int16 nVersion
GtkMediaStream * m_pStream
#define SAL_WARN(area, stream)
The file declares the LwpDrawObjects and associated class like LwpDrawGroup, LwpDrawRectangle and so ...
const sal_uInt8 MARGIN_TOP
Definition: lwpmargins.hxx:65
const sal_uInt8 MARGIN_LEFT
Definition: lwpmargins.hxx:63
@ OT_TEXTART
@ OT_CHART
@ OT_SQUARE
@ OT_LINE
@ OT_POLYLINE
@ OT_RNDRECT
@ OT_ARC
@ OT_RNDSQUARE
@ OT_OVAL
@ OT_TEXT
@ OT_POLYGON
@ OT_METAFILEIMG
@ OT_CIRCLE
@ OT_GROUP
@ OT_METAFILE
@ OT_BITMAP
@ OT_RECT
@ OT_PERPLINE
const double TWIPS_PER_CM
Definition: lwptools.hxx:82
int i
long Long
sal_uInt64 left
@ enumXFFrameImage
Definition: xfdefs.hxx:110
@ enumXFAnchorFrame
Definition: xfdefs.hxx:262