Branch data Line data Source code
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 : : * 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"
67 : :
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"
79 : : #include "xfilter/xfdrawgroup.hxx"
80 : :
81 : 0 : LwpSdwGroupLoaderV0102::LwpSdwGroupLoaderV0102(SvStream* pStream, LwpGraphicObject* pGraphicObj,
82 : : IXFStream* pOutputStream)
83 : : : m_pStream(pStream)
84 : : , m_pOutputStream(pOutputStream)
85 : 0 : , m_pGraphicObj(pGraphicObj)
86 : : {
87 : 0 : }
88 : 0 : LwpSdwGroupLoaderV0102::~LwpSdwGroupLoaderV0102(void)
89 : : {
90 : 0 : }
91 : :
92 : : // add by , 03/25/2005
93 : : /**
94 : : * @descr entry of lwp-drawing objects. the functin begins to parse the sdw-drawing bento stream and create
95 : : * the corresponding drawing objects.
96 : : * @param pDrawObjVector a container which will contains the created drawing object of XF-Model.
97 : : */
98 : 0 : void LwpSdwGroupLoaderV0102::BeginDrawObjects(std::vector <XFFrame*>* pDrawObjVector)
99 : : {
100 : : // save the container
101 : 0 : m_pDrawObjVector = pDrawObjVector;
102 : :
103 : : //flag
104 : : unsigned char BinSignature[2];
105 [ # # ]: 0 : m_pStream->Read(BinSignature,2);
106 [ # # ][ # # ]: 0 : if (BinSignature[0] != 'S' || BinSignature[1] != 'M')
107 : : {
108 : : assert(false);
109 : : return;
110 : : }
111 : : //version
112 : : unsigned short nVersion;
113 [ # # ]: 0 : m_pStream->Read(&nVersion,2);
114 [ # # ]: 0 : if (nVersion<0x0102)
115 : : {
116 : : assert(false);
117 : : return;
118 : : }
119 : : // topObj, botObj
120 [ # # ]: 0 : m_pStream->SeekRel(4);
121 : : //record count
122 : : unsigned short nRecCount;
123 [ # # ]: 0 : m_pStream->Read(&nRecCount,2);
124 : : // selCount
125 [ # # ]: 0 : m_pStream->SeekRel(2);
126 : : //boundrect
127 : : unsigned short left,top,right,bottom;
128 [ # # ]: 0 : m_pStream->Read(&left,2);
129 [ # # ]: 0 : m_pStream->Read(&top,2);
130 [ # # ]: 0 : m_pStream->Read(&right,2);
131 [ # # ]: 0 : m_pStream->Read(&bottom,2);
132 : : // fileSize
133 [ # # ]: 0 : m_pStream->SeekRel(2);
134 : :
135 : : //for calculating transformation params.
136 [ # # ]: 0 : LwpFrameLayout* pMyFrameLayout = static_cast<LwpFrameLayout*>(m_pGraphicObj->GetLayout(NULL));
137 [ # # ]: 0 : if (pMyFrameLayout)
138 : : {
139 [ # # ]: 0 : LwpLayoutScale* pMyScale = pMyFrameLayout->GetLayoutScale();
140 [ # # ]: 0 : LwpLayoutGeometry* pFrameGeo = pMyFrameLayout->GetGeometry();
141 [ # # ][ # # ]: 0 : if (pMyScale && pFrameGeo)
142 : : {
143 : : // original drawing size
144 : 0 : long nWidth = 0, nHeight = 0;
145 : 0 : m_pGraphicObj->GetGrafOrgSize(nWidth, nHeight);
146 : 0 : double fGrafOrgWidth = (double)nWidth/TWIPS_PER_CM;
147 : 0 : double fGrafOrgHeight = (double)nHeight/TWIPS_PER_CM;
148 : :
149 : : // get margin values
150 [ # # ]: 0 : double fLeftMargin = pMyFrameLayout->GetMarginsValue(MARGIN_LEFT);
151 : : // double fRightMargin = pMyFrameLayout->GetMarginsValue(MARGIN_RIGHT);
152 [ # # ]: 0 : double fTopMargin = pMyFrameLayout->GetMarginsValue(MARGIN_TOP);
153 : : // double fBottomMargin = pMyFrameLayout->GetMarginsValue(MARGIN_BOTTOM);
154 : :
155 : : // frame size
156 : 0 : double fFrameWidth = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetWidth());
157 : 0 : double fFrameHeight = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetHeight());
158 : :
159 : : // get frame offset
160 : 0 : LwpPoint* pOffset = pMyScale->GetOffset();
161 : 0 : double fOffsetX = LwpTools::ConvertFromUnitsToMetric(pOffset->GetX());
162 : 0 : double fOffsetY = LwpTools::ConvertFromUnitsToMetric(pOffset->GetY());
163 : :
164 : : // get scale mode
165 : 0 : sal_uInt16 nScalemode = pMyScale->GetScaleMode();
166 : :
167 [ # # ]: 0 : if (nScalemode & LwpLayoutScale::CUSTOM)
168 : : {
169 : : m_aTransformData.fScaleX =
170 : 0 : LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth()) / fGrafOrgWidth;
171 : : m_aTransformData.fScaleY =
172 : 0 : LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight()) / fGrafOrgHeight;
173 : : }
174 [ # # ]: 0 : else if (nScalemode & LwpLayoutScale::PERCENTAGE)
175 : : {
176 : 0 : double fScalePercentage = (double)pMyScale->GetScalePercentage() / 1000;
177 : 0 : m_aTransformData.fScaleX = fScalePercentage;
178 : 0 : m_aTransformData.fScaleY = fScalePercentage;
179 : : }
180 [ # # ]: 0 : else if (nScalemode & LwpLayoutScale::FIT_IN_FRAME)
181 : : {
182 : 0 : double fWidth0 = (double)right / TWIPS_PER_CM;
183 : 0 : double fHeight0 = (double)bottom / TWIPS_PER_CM;
184 : :
185 : 0 : double fWidth1 = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
186 : 0 : double fHeight1 = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
187 : :
188 : 0 : double fScaleX = fWidth1 / fWidth0;
189 : 0 : double fScaleY = fHeight1 / fHeight0;
190 : :
191 [ # # ]: 0 : if (nScalemode & LwpLayoutScale::MAINTAIN_ASPECT_RATIO)
192 : : {
193 [ # # ]: 0 : m_aTransformData.fScaleX = std::min(fScaleX, fScaleY);
194 : 0 : m_aTransformData.fScaleY = m_aTransformData.fScaleX;
195 : : }
196 : : else
197 : : {
198 : 0 : m_aTransformData.fScaleX = fWidth1 / fWidth0;
199 : 0 : m_aTransformData.fScaleY = fHeight1 / fHeight0;
200 : : }
201 : : }
202 : :
203 : : // placement: centered
204 [ # # ][ # # ]: 0 : if (pMyFrameLayout->GetScaleCenter())
205 : : {
206 : : Rectangle aBoundRect(static_cast<long>(left*m_aTransformData.fScaleX + fLeftMargin),
207 : : static_cast<long>(top * m_aTransformData.fScaleY + fTopMargin),
208 : : static_cast<long>(right * m_aTransformData.fScaleX),
209 [ # # ]: 0 : static_cast<long>(bottom * m_aTransformData.fScaleY));
210 [ # # ]: 0 : Point aCenter = aBoundRect.Center();
211 : :
212 : 0 : double fNewCenterX = (double(left)/TWIPS_PER_CM + fFrameWidth/*-fOffsetX*/) / 2;
213 : 0 : double fNewCenterY = (double(top)/TWIPS_PER_CM + fFrameHeight/*-fOffsetY*/) / 2;
214 : :
215 : 0 : m_aTransformData.fOffsetX = fNewCenterX - (double)aCenter.X()/TWIPS_PER_CM;
216 : 0 : m_aTransformData.fOffsetY = fNewCenterY -(double)aCenter.Y()/TWIPS_PER_CM;
217 : : }
218 : : else
219 : : {
220 : 0 : m_aTransformData.fOffsetX = fOffsetX;
221 : 0 : m_aTransformData.fOffsetY = fOffsetY;
222 : : }
223 : :
224 : 0 : m_aTransformData.fOffsetX += fLeftMargin;
225 : 0 : m_aTransformData.fOffsetY += fTopMargin;
226 : 0 : m_aTransformData.fLeftMargin = fLeftMargin;
227 : 0 : m_aTransformData.fTopMargin = fTopMargin;
228 : : }
229 : : }
230 : :
231 : : //load draw object
232 [ # # ]: 0 : for (unsigned short i = 0; i < nRecCount; i++)
233 : : {
234 [ # # ]: 0 : XFFrame* pXFDrawObj = this->CreateDrawObject();
235 : :
236 [ # # ]: 0 : if (pXFDrawObj)
237 : : {
238 [ # # ]: 0 : pDrawObjVector->push_back(pXFDrawObj);
239 : : }
240 : : }
241 : : }
242 : :
243 : : /**
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.
247 : : */
248 : 0 : XFDrawGroup* LwpSdwGroupLoaderV0102::CreateDrawGroupObject(void)
249 : : {
250 : : //flag
251 : : unsigned char BinSignature[2];
252 [ # # ]: 0 : m_pStream->Read(BinSignature,2);
253 [ # # ][ # # ]: 0 : if (BinSignature[0] != 'S' || BinSignature[1] != 'M')
254 : : {
255 : : assert(false);
256 : 0 : return NULL;
257 : : }
258 : : //version
259 : : unsigned short nVersion;
260 [ # # ]: 0 : m_pStream->Read(&nVersion,2);
261 [ # # ]: 0 : if (nVersion<0x0102)
262 : : {
263 : : assert(false);
264 : 0 : return NULL;
265 : : }
266 : : // topObj, botObj
267 [ # # ]: 0 : m_pStream->SeekRel(4);
268 : : //record count
269 : : unsigned short nRecCount;
270 [ # # ]: 0 : m_pStream->Read(&nRecCount,2);
271 : : // selCount
272 [ # # ]: 0 : m_pStream->SeekRel(2);
273 : : //boundrect
274 : : unsigned short left,top,right,bottom;
275 [ # # ]: 0 : m_pStream->Read(&left,2);
276 [ # # ]: 0 : m_pStream->Read(&top,2);
277 [ # # ]: 0 : m_pStream->Read(&right,2);
278 [ # # ]: 0 : m_pStream->Read(&bottom,2);
279 : : // fileSize
280 [ # # ]: 0 : m_pStream->SeekRel(2);
281 : :
282 [ # # ][ # # ]: 0 : XFDrawGroup* pXFDrawGroup = new XFDrawGroup();
283 : :
284 : : //load draw object
285 [ # # ]: 0 : for (unsigned short i = 0; i < nRecCount; i++)
286 : : {
287 [ # # ]: 0 : XFFrame* pXFDrawObj = this->CreateDrawObject();
288 : :
289 [ # # ]: 0 : if (pXFDrawObj)
290 : : {
291 [ # # ][ # # ]: 0 : if (pXFDrawObj->GetFrameType() == enumXFFrameImage)
292 : : {
293 [ # # ]: 0 : m_pDrawObjVector->push_back(pXFDrawObj);
294 : : }
295 : : else
296 : : {
297 [ # # ]: 0 : pXFDrawGroup->Add(pXFDrawObj);
298 : : }
299 : : }
300 : : }
301 : :
302 : 0 : return pXFDrawGroup;
303 : : }
304 : :
305 : : /**
306 : : * @descr Create the XF-drawing objects according to the object type read from bento stream.
307 : : * @return the created XF-drawing objects.
308 : : */
309 : 0 : XFFrame* LwpSdwGroupLoaderV0102::CreateDrawObject(void)
310 : : {
311 : : //record type
312 : : unsigned char recType;
313 [ # # ]: 0 : m_pStream->Read(&recType,1);
314 : :
315 : 0 : LwpDrawObj* pDrawObj = NULL;
316 : 0 : XFFrame* pRetObjct = NULL;
317 : :
318 [ # # # # : 0 : switch(recType)
# # # # #
# # # # ]
319 : : {
320 : : case OT_PERPLINE://fall-through
321 : : case OT_LINE:
322 : : {
323 [ # # ][ # # ]: 0 : pDrawObj = new LwpDrawLine(m_pStream, &m_aTransformData);
324 : 0 : break;
325 : : }
326 : : case OT_POLYLINE:
327 : : {
328 [ # # ][ # # ]: 0 : pDrawObj = new LwpDrawPolyLine(m_pStream, &m_aTransformData);
329 : 0 : break;
330 : : }
331 : : case OT_POLYGON:
332 : : {
333 [ # # ][ # # ]: 0 : pDrawObj = new LwpDrawPolygon(m_pStream, &m_aTransformData);
334 : 0 : pDrawObj->SetObjectType(OT_POLYGON);
335 : 0 : break;
336 : : }
337 : : case OT_SQUARE://fall-through
338 : : case OT_RECT:
339 : : {
340 [ # # ][ # # ]: 0 : pDrawObj = new LwpDrawRectangle(m_pStream, &m_aTransformData);
341 : 0 : break;
342 : : }
343 : : case OT_RNDSQUARE://fall-through
344 : : case OT_RNDRECT:
345 : : {
346 [ # # ][ # # ]: 0 : pDrawObj = new LwpDrawRectangle(m_pStream, &m_aTransformData);
347 : 0 : pDrawObj->SetObjectType(OT_RNDRECT);
348 : 0 : break;
349 : : }
350 : : case OT_CIRCLE://fall-through
351 : : case OT_OVAL:
352 : : {
353 [ # # ][ # # ]: 0 : pDrawObj = new LwpDrawEllipse(m_pStream, &m_aTransformData);
354 : 0 : break;
355 : : }
356 : : case OT_ARC:
357 : : {
358 [ # # ][ # # ]: 0 : pDrawObj = new LwpDrawArc(m_pStream, &m_aTransformData);
359 : 0 : break;
360 : : }
361 : : case OT_TEXT:
362 : : {
363 [ # # ][ # # ]: 0 : pDrawObj = new LwpDrawTextBox(m_pStream);
364 : 0 : break;
365 : : }
366 : : case OT_TEXTART:
367 : : {
368 [ # # ][ # # ]: 0 : pDrawObj = new LwpDrawTextArt(m_pStream, &m_aTransformData);
369 : 0 : pDrawObj->SetObjectType(OT_TEXTART);
370 : 0 : break;
371 : : }
372 : : case OT_GROUP:
373 : : {
374 [ # # ]: 0 : m_pStream->SeekRel(2);
375 : : // read out the object header
376 [ # # ][ # # ]: 0 : pDrawObj = new LwpDrawGroup(m_pStream);
377 : :
378 [ # # ]: 0 : pRetObjct = this->CreateDrawGroupObject();
379 : :
380 : : // set anchor type
381 : 0 : pRetObjct->SetAnchorType(enumXFAnchorFrame);
382 : 0 : break;
383 : : }
384 : : case OT_CHART://fall-through
385 : : case OT_METAFILE://fall-through
386 : : case OT_METAFILEIMG:
387 : : {
388 [ # # ]: 0 : LwpDrawMetafile aMeta(m_pStream);
389 : 0 : break;
390 : : }
391 : : case OT_BITMAP:
392 [ # # ][ # # ]: 0 : pDrawObj = new LwpDrawBitmap(m_pStream);
393 : 0 : pDrawObj->SetObjectType(OT_BITMAP);
394 : 0 : break;
395 : : }
396 : :
397 : : // we don't need create the corresponding XF-object of a group object.
398 [ # # ][ # # ]: 0 : if (pDrawObj && recType != OT_GROUP)
399 : : {
400 [ # # ]: 0 : pRetObjct = pDrawObj->CreateXFDrawObject();
401 : : }
402 : :
403 [ # # ]: 0 : if (pDrawObj)
404 : : {
405 [ # # ][ # # ]: 0 : delete pDrawObj;
406 : 0 : pDrawObj = NULL;
407 : : }
408 : :
409 : 0 : return pRetObjct;
410 : : }
411 : : // end add
412 : :
413 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|