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,
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 /*****************************************************************************
58 * Mar 2005 revised for new processing procedure.
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
)
82 , m_pGraphicObj(pGraphicObj
)
83 , m_pDrawObjVector(NULL
)
87 LwpSdwGroupLoaderV0102::~LwpSdwGroupLoaderV0102()
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
<XFFrame
*>* pDrawObjVector
)
99 m_pDrawObjVector
= pDrawObjVector
;
102 unsigned char BinSignature
[2];
103 m_pStream
->Read(BinSignature
,2);
104 if (BinSignature
[0] != 'S' || BinSignature
[1] != 'M')
110 unsigned short nVersion
;
111 m_pStream
->Read(&nVersion
,2);
118 m_pStream
->SeekRel(4);
120 unsigned short nRecCount
;
121 m_pStream
->Read(&nRecCount
,2);
123 m_pStream
->SeekRel(2);
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);
131 m_pStream
->SeekRel(2);
133 //for calculating transformation params.
134 LwpFrameLayout
* pMyFrameLayout
= static_cast<LwpFrameLayout
*>(m_pGraphicObj
->GetLayout(NULL
));
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
;
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);
154 double fFrameWidth
= LwpTools::ConvertFromUnitsToMetric(pFrameGeo
->GetWidth());
155 double fFrameHeight
= LwpTools::ConvertFromUnitsToMetric(pFrameGeo
->GetHeight());
158 LwpPoint
* pOffset
= pMyScale
->GetOffset();
159 double fOffsetX
= LwpTools::ConvertFromUnitsToMetric(pOffset
->GetX());
160 double fOffsetY
= LwpTools::ConvertFromUnitsToMetric(pOffset
->GetY());
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
;
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
;
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
;
230 for (unsigned short i
= 0; i
< nRecCount
; i
++)
232 XFFrame
* pXFDrawObj
= this->CreateDrawObject();
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(void)
249 unsigned char BinSignature
[2];
250 m_pStream
->Read(BinSignature
,2);
251 if (BinSignature
[0] != 'S' || BinSignature
[1] != 'M')
257 unsigned short nVersion
;
258 m_pStream
->Read(&nVersion
,2);
265 m_pStream
->SeekRel(4);
267 unsigned short nRecCount
;
268 m_pStream
->Read(&nRecCount
,2);
270 m_pStream
->SeekRel(2);
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);
278 m_pStream
->SeekRel(2);
280 XFDrawGroup
* pXFDrawGroup
= new XFDrawGroup();
283 for (unsigned short i
= 0; i
< nRecCount
; i
++)
285 XFFrame
* pXFDrawObj
= this->CreateDrawObject();
289 if (pXFDrawObj
->GetFrameType() == enumXFFrameImage
)
291 m_pDrawObjVector
->push_back(pXFDrawObj
);
295 pXFDrawGroup
->Add(pXFDrawObj
);
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(void)
310 unsigned char recType
;
311 m_pStream
->Read(&recType
,1);
313 LwpDrawObj
* pDrawObj
= NULL
;
314 XFFrame
* pRetObjct
= NULL
;
318 case OT_PERPLINE
://fall-through
321 pDrawObj
= new LwpDrawLine(m_pStream
, &m_aTransformData
);
326 pDrawObj
= new LwpDrawPolyLine(m_pStream
, &m_aTransformData
);
331 pDrawObj
= new LwpDrawPolygon(m_pStream
, &m_aTransformData
);
332 pDrawObj
->SetObjectType(OT_POLYGON
);
335 case OT_SQUARE
://fall-through
338 pDrawObj
= new LwpDrawRectangle(m_pStream
, &m_aTransformData
);
341 case OT_RNDSQUARE
://fall-through
344 pDrawObj
= new LwpDrawRectangle(m_pStream
, &m_aTransformData
);
345 pDrawObj
->SetObjectType(OT_RNDRECT
);
348 case OT_CIRCLE
://fall-through
351 pDrawObj
= new LwpDrawEllipse(m_pStream
, &m_aTransformData
);
356 pDrawObj
= new LwpDrawArc(m_pStream
, &m_aTransformData
);
361 pDrawObj
= new LwpDrawTextBox(m_pStream
);
366 pDrawObj
= new LwpDrawTextArt(m_pStream
, &m_aTransformData
);
367 pDrawObj
->SetObjectType(OT_TEXTART
);
372 m_pStream
->SeekRel(2);
373 // read out the object header
374 pDrawObj
= new LwpDrawGroup(m_pStream
);
376 pRetObjct
= this->CreateDrawGroupObject();
379 pRetObjct
->SetAnchorType(enumXFAnchorFrame
);
382 case OT_CHART
://fall-through
383 case OT_METAFILE
://fall-through
386 LwpDrawMetafile
aMeta(m_pStream
);
390 pDrawObj
= new LwpDrawBitmap(m_pStream
);
391 pDrawObj
->SetObjectType(OT_BITMAP
);
395 // we don't need create the corresponding XF-object of a group object.
396 if (pDrawObj
&& recType
!= OT_GROUP
)
398 pRetObjct
= pDrawObj
->CreateXFDrawObject();
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */