fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / lotuswordpro / source / filter / lwpsdwgrouploaderv0102.cxx
blob872d0117cdad00372a002325eca5c3ea75277016
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 ************************************************************************/
56 /*****************************************************************************
57 * Change History
58 * Mar 2005 revised for new processing procedure.
59 * Jan 2005 created
60 ****************************************************************************/
61 #include "lwpsdwgrouploaderv0102.hxx"
62 #include "lwpdrawobj.hxx"
63 #include "lwptools.hxx"
64 #include "lwpcharsetmgr.hxx"
65 #include "lwpgrfobj.hxx"
66 #include "lwpframelayout.hxx"
68 #include "xfilter/xfcolor.hxx"
69 #include "xfilter/xfdrawline.hxx"
70 #include "xfilter/xfdrawpath.hxx"
71 #include "xfilter/xfdrawpolyline.hxx"
72 #include "xfilter/xfdrawrect.hxx"
73 #include "xfilter/xfdrawpolygon.hxx"
74 #include "xfilter/xfdrawgroup.hxx"
75 #include "xfilter/xfdrawstyle.hxx"
76 #include "xfilter/xfdrawlinestyle.hxx"
77 #include "xfilter/xfparagraph.hxx"
78 #include "xfilter/xfstylemanager.hxx"
80 LwpSdwGroupLoaderV0102::LwpSdwGroupLoaderV0102(SvStream* pStream, LwpGraphicObject* pGraphicObj)
81 : m_pStream(pStream)
82 , m_pGraphicObj(pGraphicObj)
83 , m_pDrawObjVector(NULL)
87 LwpSdwGroupLoaderV0102::~LwpSdwGroupLoaderV0102()
91 /**
92 * @descr entry of lwp-drawing objects. the functin begins to parse the sdw-drawing bento stream and create
93 * the corresponding drawing objects.
94 * @param pDrawObjVector a container which will contains the created drawing object of XF-Model.
96 void LwpSdwGroupLoaderV0102::BeginDrawObjects(std::vector< rtl::Reference<XFFrame> >* pDrawObjVector)
98 // save the container
99 m_pDrawObjVector = pDrawObjVector;
101 //flag
102 unsigned char BinSignature[2];
103 m_pStream->Read(BinSignature,2);
104 if (BinSignature[0] != 'S' || BinSignature[1] != 'M')
106 assert(false);
107 return;
109 //version
110 unsigned short nVersion;
111 m_pStream->Read(&nVersion,2);
112 if (nVersion<0x0102)
114 assert(false);
115 return;
117 // topObj, botObj
118 m_pStream->SeekRel(4);
119 //record count
120 unsigned short nRecCount;
121 m_pStream->Read(&nRecCount,2);
122 // selCount
123 m_pStream->SeekRel(2);
124 //boundrect
125 unsigned short left,top,right,bottom;
126 m_pStream->Read(&left,2);
127 m_pStream->Read(&top,2);
128 m_pStream->Read(&right,2);
129 m_pStream->Read(&bottom,2);
130 // fileSize
131 m_pStream->SeekRel(2);
133 //for calculating transformation params.
134 LwpFrameLayout* pMyFrameLayout = static_cast<LwpFrameLayout*>(m_pGraphicObj->GetLayout(NULL));
135 if (pMyFrameLayout)
137 LwpLayoutScale* pMyScale = pMyFrameLayout->GetLayoutScale();
138 LwpLayoutGeometry* pFrameGeo = pMyFrameLayout->GetGeometry();
139 if (pMyScale && pFrameGeo)
141 // original drawing size
142 long nWidth = 0, nHeight = 0;
143 m_pGraphicObj->GetGrafOrgSize(nWidth, nHeight);
144 double fGrafOrgWidth = (double)nWidth/TWIPS_PER_CM;
145 double fGrafOrgHeight = (double)nHeight/TWIPS_PER_CM;
147 // get margin values
148 double fLeftMargin = pMyFrameLayout->GetMarginsValue(MARGIN_LEFT);
149 // double fRightMargin = pMyFrameLayout->GetMarginsValue(MARGIN_RIGHT);
150 double fTopMargin = pMyFrameLayout->GetMarginsValue(MARGIN_TOP);
151 // double fBottomMargin = pMyFrameLayout->GetMarginsValue(MARGIN_BOTTOM);
153 // frame size
154 double fFrameWidth = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetWidth());
155 double fFrameHeight = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetHeight());
157 // get frame offset
158 LwpPoint& rOffset = pMyScale->GetOffset();
159 double fOffsetX = LwpTools::ConvertFromUnitsToMetric(rOffset.GetX());
160 double fOffsetY = LwpTools::ConvertFromUnitsToMetric(rOffset.GetY());
162 // get scale mode
163 sal_uInt16 nScalemode = pMyScale->GetScaleMode();
165 if (nScalemode & LwpLayoutScale::CUSTOM)
167 m_aTransformData.fScaleX =
168 LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth()) / fGrafOrgWidth;
169 m_aTransformData.fScaleY =
170 LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight()) / fGrafOrgHeight;
172 else if (nScalemode & LwpLayoutScale::PERCENTAGE)
174 double fScalePercentage = (double)pMyScale->GetScalePercentage() / 1000;
175 m_aTransformData.fScaleX = fScalePercentage;
176 m_aTransformData.fScaleY = fScalePercentage;
178 else if (nScalemode & LwpLayoutScale::FIT_IN_FRAME)
180 double fWidth0 = (double)right / TWIPS_PER_CM;
181 double fHeight0 = (double)bottom / TWIPS_PER_CM;
183 double fWidth1 = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
184 double fHeight1 = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
186 double fScaleX = fWidth1 / fWidth0;
187 double fScaleY = fHeight1 / fHeight0;
189 if (nScalemode & LwpLayoutScale::MAINTAIN_ASPECT_RATIO)
191 m_aTransformData.fScaleX = std::min(fScaleX, fScaleY);
192 m_aTransformData.fScaleY = m_aTransformData.fScaleX;
194 else
196 m_aTransformData.fScaleX = fWidth1 / fWidth0;
197 m_aTransformData.fScaleY = fHeight1 / fHeight0;
201 // placement: centered
202 if (pMyFrameLayout->GetScaleCenter())
204 Rectangle aBoundRect(static_cast<long>(left*m_aTransformData.fScaleX + fLeftMargin),
205 static_cast<long>(top * m_aTransformData.fScaleY + fTopMargin),
206 static_cast<long>(right * m_aTransformData.fScaleX),
207 static_cast<long>(bottom * m_aTransformData.fScaleY));
208 Point aCenter = aBoundRect.Center();
210 double fNewCenterX = (double(left)/TWIPS_PER_CM + fFrameWidth/*-fOffsetX*/) / 2;
211 double fNewCenterY = (double(top)/TWIPS_PER_CM + fFrameHeight/*-fOffsetY*/) / 2;
213 m_aTransformData.fOffsetX = fNewCenterX - (double)aCenter.X()/TWIPS_PER_CM;
214 m_aTransformData.fOffsetY = fNewCenterY -(double)aCenter.Y()/TWIPS_PER_CM;
216 else
218 m_aTransformData.fOffsetX = fOffsetX;
219 m_aTransformData.fOffsetY = fOffsetY;
222 m_aTransformData.fOffsetX += fLeftMargin;
223 m_aTransformData.fOffsetY += fTopMargin;
224 m_aTransformData.fLeftMargin = fLeftMargin;
225 m_aTransformData.fTopMargin = fTopMargin;
229 //load draw object
230 for (unsigned short i = 0; i < nRecCount; i++)
232 XFFrame* pXFDrawObj = this->CreateDrawObject();
234 if (pXFDrawObj)
236 pDrawObjVector->push_back(pXFDrawObj);
242 * @descr when we encounter a group object the function will be called to create a XF-drawgroup object
243 * the corresponding drawing objects.
244 * @param pDrawObjVector a container which will contains the created drawing object of XF-Model.
246 XFDrawGroup* LwpSdwGroupLoaderV0102::CreateDrawGroupObject()
248 //flag
249 unsigned char BinSignature[2];
250 m_pStream->Read(BinSignature,2);
251 if (BinSignature[0] != 'S' || BinSignature[1] != 'M')
253 assert(false);
254 return NULL;
256 //version
257 unsigned short nVersion;
258 m_pStream->Read(&nVersion,2);
259 if (nVersion<0x0102)
261 assert(false);
262 return NULL;
264 // topObj, botObj
265 m_pStream->SeekRel(4);
266 //record count
267 unsigned short nRecCount;
268 m_pStream->Read(&nRecCount,2);
269 // selCount
270 m_pStream->SeekRel(2);
271 //boundrect
272 unsigned short left,top,right,bottom;
273 m_pStream->Read(&left,2);
274 m_pStream->Read(&top,2);
275 m_pStream->Read(&right,2);
276 m_pStream->Read(&bottom,2);
277 // fileSize
278 m_pStream->SeekRel(2);
280 XFDrawGroup* pXFDrawGroup = new XFDrawGroup();
282 //load draw object
283 for (unsigned short i = 0; i < nRecCount; i++)
285 XFFrame* pXFDrawObj = this->CreateDrawObject();
287 if (pXFDrawObj)
289 if (pXFDrawObj->GetFrameType() == enumXFFrameImage)
291 m_pDrawObjVector->push_back(pXFDrawObj);
293 else
295 pXFDrawGroup->Add(pXFDrawObj);
300 return pXFDrawGroup;
304 * @descr Create the XF-drawing objects according to the object type read from bento stream.
305 * @return the created XF-drawing objects.
307 XFFrame* LwpSdwGroupLoaderV0102::CreateDrawObject()
309 //record type
310 unsigned char recType;
311 m_pStream->Read(&recType,1);
313 LwpDrawObj* pDrawObj = NULL;
314 XFFrame* pRetObjct = NULL;
316 switch(recType)
318 case OT_PERPLINE://fall-through
319 case OT_LINE:
321 pDrawObj = new LwpDrawLine(m_pStream, &m_aTransformData);
322 break;
324 case OT_POLYLINE:
326 pDrawObj = new LwpDrawPolyLine(m_pStream, &m_aTransformData);
327 break;
329 case OT_POLYGON:
331 pDrawObj = new LwpDrawPolygon(m_pStream, &m_aTransformData);
332 pDrawObj->SetObjectType(OT_POLYGON);
333 break;
335 case OT_SQUARE://fall-through
336 case OT_RECT:
338 pDrawObj = new LwpDrawRectangle(m_pStream, &m_aTransformData);
339 break;
341 case OT_RNDSQUARE://fall-through
342 case OT_RNDRECT:
344 pDrawObj = new LwpDrawRectangle(m_pStream, &m_aTransformData);
345 pDrawObj->SetObjectType(OT_RNDRECT);
346 break;
348 case OT_CIRCLE://fall-through
349 case OT_OVAL:
351 pDrawObj = new LwpDrawEllipse(m_pStream, &m_aTransformData);
352 break;
354 case OT_ARC:
356 pDrawObj = new LwpDrawArc(m_pStream, &m_aTransformData);
357 break;
359 case OT_TEXT:
361 pDrawObj = new LwpDrawTextBox(m_pStream);
362 break;
364 case OT_TEXTART:
366 pDrawObj = new LwpDrawTextArt(m_pStream, &m_aTransformData);
367 pDrawObj->SetObjectType(OT_TEXTART);
368 break;
370 case OT_GROUP:
372 m_pStream->SeekRel(2);
373 // read out the object header
374 pDrawObj = new LwpDrawGroup(m_pStream);
376 pRetObjct = this->CreateDrawGroupObject();
378 // set anchor type
379 pRetObjct->SetAnchorType(enumXFAnchorFrame);
380 break;
382 case OT_CHART://fall-through
383 case OT_METAFILE://fall-through
384 case OT_METAFILEIMG:
386 LwpDrawMetafile aMeta(m_pStream);
387 break;
389 case OT_BITMAP:
390 pDrawObj = new LwpDrawBitmap(m_pStream);
391 pDrawObj->SetObjectType(OT_BITMAP);
392 break;
395 // we don't need create the corresponding XF-object of a group object.
396 if (pDrawObj && recType != OT_GROUP)
398 pRetObjct = pDrawObj->CreateXFDrawObject();
401 if (pDrawObj)
403 delete pDrawObj;
404 pDrawObj = NULL;
407 return pRetObjct;
409 // end add
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */