1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /*****************************************************************************
57 * Mar 2005 revised for new processing procedure.
59 ****************************************************************************/
60 #include "lwpsdwgrouploaderv0102.hxx"
61 #include "lwpdrawobj.hxx"
62 #include "lwptools.hxx"
63 #include "lwpcharsetmgr.hxx"
64 #include "lwpgrfobj.hxx"
65 #include "lwpframelayout.hxx"
67 #include "xfilter/xfcolor.hxx"
68 #include "xfilter/xfdrawline.hxx"
69 #include "xfilter/xfdrawpath.hxx"
70 #include "xfilter/xfdrawpolyline.hxx"
71 #include "xfilter/xfdrawrect.hxx"
72 #include "xfilter/xfdrawellipse.hxx"
73 #include "xfilter/xfdrawpolygon.hxx"
74 #include "xfilter/xfdrawgroup.hxx"
75 #include "xfilter/xfdrawcircle.hxx"
76 #include "xfilter/xfdrawstyle.hxx"
77 #include "xfilter/xfdrawlinestyle.hxx"
78 #include "xfilter/xfparagraph.hxx"
79 #include "xfilter/xfstylemanager.hxx"
80 #include "xfilter/xfdrawgroup.hxx"
82 LwpSdwGroupLoaderV0102::LwpSdwGroupLoaderV0102(SvStream
* pStream
, LwpGraphicObject
* pGraphicObj
,
83 IXFStream
* pOutputStream
)
84 :m_pStream(pStream
), m_pGraphicObj(pGraphicObj
), m_pOutputStream(pOutputStream
)
87 LwpSdwGroupLoaderV0102::~LwpSdwGroupLoaderV0102(void)
91 // add by , 03/25/2005
93 * @descr entry of lwp-drawing objects. the functin begins to parse the sdw-drawing bento stream and create
94 * the corresponding drawing objects.
95 * @param pDrawObjVector a container which will contains the created drawing object of XF-Model.
97 void LwpSdwGroupLoaderV0102::BeginDrawObjects(std::vector
<XFFrame
*>* pDrawObjVector
)
100 m_pDrawObjVector
= pDrawObjVector
;
103 unsigned char BinSignature
[2];
104 m_pStream
->Read(BinSignature
,2);
105 if (BinSignature
[0] != 'S' || BinSignature
[1] != 'M')
111 unsigned short nVersion
;
112 m_pStream
->Read(&nVersion
,2);
119 m_pStream
->SeekRel(4);
121 unsigned short nRecCount
;
122 m_pStream
->Read(&nRecCount
,2);
124 m_pStream
->SeekRel(2);
126 unsigned short left
,top
,right
,bottom
;
127 m_pStream
->Read(&left
,2);
128 m_pStream
->Read(&top
,2);
129 m_pStream
->Read(&right
,2);
130 m_pStream
->Read(&bottom
,2);
132 m_pStream
->SeekRel(2);
134 //for calculating transformation params.
135 LwpFrameLayout
* pMyFrameLayout
= static_cast<LwpFrameLayout
*>(m_pGraphicObj
->GetLayout(NULL
));
138 LwpLayoutScale
* pMyScale
= pMyFrameLayout
->GetLayoutScale();
139 LwpLayoutGeometry
* pFrameGeo
= pMyFrameLayout
->GetGeometry();
140 if (pMyScale
&& pFrameGeo
)
142 // original drawing size
143 long nWidth
= 0, nHeight
= 0;
144 m_pGraphicObj
->GetGrafOrgSize(nWidth
, nHeight
);
145 double fGrafOrgWidth
= (double)nWidth
/TWIPS_PER_CM
;
146 double fGrafOrgHeight
= (double)nHeight
/TWIPS_PER_CM
;
149 double fLeftMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_LEFT
);
150 // double fRightMargin = pMyFrameLayout->GetMarginsValue(MARGIN_RIGHT);
151 double fTopMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_TOP
);
152 // double fBottomMargin = pMyFrameLayout->GetMarginsValue(MARGIN_BOTTOM);
155 double fFrameWidth
= LwpTools::ConvertFromUnitsToMetric(pFrameGeo
->GetWidth());
156 double fFrameHeight
= LwpTools::ConvertFromUnitsToMetric(pFrameGeo
->GetHeight());
159 LwpPoint
* pOffset
= pMyScale
->GetOffset();
160 double fOffsetX
= LwpTools::ConvertFromUnitsToMetric(pOffset
->GetX());
161 double fOffsetY
= LwpTools::ConvertFromUnitsToMetric(pOffset
->GetY());
164 sal_uInt16 nScalemode
= pMyScale
->GetScaleMode();
166 if (nScalemode
& LwpLayoutScale::CUSTOM
)
168 m_aTransformData
.fScaleX
=
169 LwpTools::ConvertFromUnitsToMetric(pMyScale
->GetScaleWidth()) / fGrafOrgWidth
;
170 m_aTransformData
.fScaleY
=
171 LwpTools::ConvertFromUnitsToMetric(pMyScale
->GetScaleHeight()) / fGrafOrgHeight
;
173 else if (nScalemode
& LwpLayoutScale::PERCENTAGE
)
175 double fScalePercentage
= (double)pMyScale
->GetScalePercentage() / 1000;
176 m_aTransformData
.fScaleX
= fScalePercentage
;
177 m_aTransformData
.fScaleY
= fScalePercentage
;
179 else if (nScalemode
& LwpLayoutScale::FIT_IN_FRAME
)
181 double fWidth0
= (double)right
/ TWIPS_PER_CM
;
182 double fHeight0
= (double)bottom
/ TWIPS_PER_CM
;
184 double fWidth1
= LwpTools::ConvertFromUnitsToMetric(pMyScale
->GetScaleWidth());
185 double fHeight1
= LwpTools::ConvertFromUnitsToMetric(pMyScale
->GetScaleHeight());
187 double fScaleX
= fWidth1
/ fWidth0
;
188 double fScaleY
= fHeight1
/ fHeight0
;
190 if (nScalemode
& LwpLayoutScale::MAINTAIN_ASPECT_RATIO
)
192 m_aTransformData
.fScaleX
= std::min(fScaleX
, fScaleY
);
193 m_aTransformData
.fScaleY
= m_aTransformData
.fScaleX
;
197 m_aTransformData
.fScaleX
= fWidth1
/ fWidth0
;
198 m_aTransformData
.fScaleY
= fHeight1
/ fHeight0
;
202 // placement: centered
203 if (pMyFrameLayout
->GetScaleCenter())
205 Rectangle
aBoundRect(left
*m_aTransformData
.fScaleX
+ fLeftMargin
,
206 top
*m_aTransformData
.fScaleY
+ fTopMargin
,
207 right
* m_aTransformData
.fScaleX
,
208 bottom
* m_aTransformData
.fScaleY
);
209 Point aCenter
= aBoundRect
.Center();
211 double fNewCenterX
= (double(left
)/TWIPS_PER_CM
+ fFrameWidth
/*-fOffsetX*/) / 2;
212 double fNewCenterY
= (double(top
)/TWIPS_PER_CM
+ fFrameHeight
/*-fOffsetY*/) / 2;
214 m_aTransformData
.fOffsetX
= fNewCenterX
- (double)aCenter
.X()/TWIPS_PER_CM
;
215 m_aTransformData
.fOffsetY
= fNewCenterY
-(double)aCenter
.Y()/TWIPS_PER_CM
;
219 m_aTransformData
.fOffsetX
= fOffsetX
;
220 m_aTransformData
.fOffsetY
= fOffsetY
;
223 m_aTransformData
.fOffsetX
+= fLeftMargin
;
224 m_aTransformData
.fOffsetY
+= fTopMargin
;
225 m_aTransformData
.fLeftMargin
= fLeftMargin
;
226 m_aTransformData
.fTopMargin
= fTopMargin
;
231 for (unsigned short i
= 0; i
< nRecCount
; i
++)
233 XFFrame
* pXFDrawObj
= this->CreateDrawObject();
237 pDrawObjVector
->push_back(pXFDrawObj
);
243 * @descr when we encounter a group object the function will be called to create a XF-drawgroup object
244 * the corresponding drawing objects.
245 * @param pDrawObjVector a container which will contains the created drawing object of XF-Model.
247 XFDrawGroup
* LwpSdwGroupLoaderV0102::CreateDrawGroupObject(void)
250 unsigned char BinSignature
[2];
251 m_pStream
->Read(BinSignature
,2);
252 if (BinSignature
[0] != 'S' || BinSignature
[1] != 'M')
258 unsigned short nVersion
;
259 m_pStream
->Read(&nVersion
,2);
266 m_pStream
->SeekRel(4);
268 unsigned short nRecCount
;
269 m_pStream
->Read(&nRecCount
,2);
271 m_pStream
->SeekRel(2);
273 unsigned short left
,top
,right
,bottom
;
274 m_pStream
->Read(&left
,2);
275 m_pStream
->Read(&top
,2);
276 m_pStream
->Read(&right
,2);
277 m_pStream
->Read(&bottom
,2);
279 m_pStream
->SeekRel(2);
281 XFDrawGroup
* pXFDrawGroup
= new XFDrawGroup();
284 for (unsigned short i
= 0; i
< nRecCount
; i
++)
286 XFFrame
* pXFDrawObj
= this->CreateDrawObject();
290 if (pXFDrawObj
->GetFrameType() == enumXFFrameImage
)
292 m_pDrawObjVector
->push_back(pXFDrawObj
);
296 pXFDrawGroup
->Add(pXFDrawObj
);
305 * @descr Create the XF-drawing objects according to the object type read from bento stream.
306 * @return the created XF-drawing objects.
308 XFFrame
* LwpSdwGroupLoaderV0102::CreateDrawObject(void)
311 unsigned char recType
;
312 m_pStream
->Read(&recType
,1);
314 LwpDrawObj
* pDrawObj
= NULL
;
315 XFFrame
* pRetObjct
= NULL
;
319 case OT_PERPLINE
://fall-through
322 pDrawObj
= new LwpDrawLine(m_pStream
, &m_aTransformData
);
327 pDrawObj
= new LwpDrawPolyLine(m_pStream
, &m_aTransformData
);
332 pDrawObj
= new LwpDrawPolygon(m_pStream
, &m_aTransformData
);
333 pDrawObj
->SetObjectType(OT_POLYGON
);
336 case OT_SQUARE
://fall-through
339 pDrawObj
= new LwpDrawRectangle(m_pStream
, &m_aTransformData
);
342 case OT_RNDSQUARE
://fall-through
345 pDrawObj
= new LwpDrawRectangle(m_pStream
, &m_aTransformData
);
346 pDrawObj
->SetObjectType(OT_RNDRECT
);
349 case OT_CIRCLE
://fall-through
352 pDrawObj
= new LwpDrawEllipse(m_pStream
, &m_aTransformData
);
357 pDrawObj
= new LwpDrawArc(m_pStream
, &m_aTransformData
);
362 pDrawObj
= new LwpDrawTextBox(m_pStream
);
367 pDrawObj
= new LwpDrawTextArt(m_pStream
, &m_aTransformData
);
368 pDrawObj
->SetObjectType(OT_TEXTART
);
373 m_pStream
->SeekRel(2);
374 // read out the object header
375 pDrawObj
= new LwpDrawGroup(m_pStream
);
377 pRetObjct
= this->CreateDrawGroupObject();
380 pRetObjct
->SetAnchorType(enumXFAnchorFrame
);
383 case OT_CHART
://fall-through
384 case OT_METAFILE
://fall-through
387 LwpDrawMetafile
aMeta(m_pStream
);
391 pDrawObj
= new LwpDrawBitmap(m_pStream
);
392 pDrawObj
->SetObjectType(OT_BITMAP
);
396 // we don't need create the corresponding XF-object of a group object.
397 if (pDrawObj
&& recType
!= OT_GROUP
)
399 pRetObjct
= pDrawObj
->CreateXFDrawObject();