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 ************************************************************************/
57 #include <tools/stream.hxx>
59 #include "lwpsdwgrouploaderv0102.hxx"
60 #include "lwpdrawobj.hxx"
61 #include "lwptools.hxx"
62 #include "lwpcharsetmgr.hxx"
63 #include "lwpgrfobj.hxx"
64 #include "lwpframelayout.hxx"
66 #include "xfilter/xfcolor.hxx"
67 #include "xfilter/xfdrawline.hxx"
68 #include "xfilter/xfdrawpath.hxx"
69 #include "xfilter/xfdrawpolyline.hxx"
70 #include "xfilter/xfdrawrect.hxx"
71 #include "xfilter/xfdrawpolygon.hxx"
72 #include "xfilter/xfdrawgroup.hxx"
73 #include "xfilter/xfdrawstyle.hxx"
74 #include "xfilter/xfdrawlinestyle.hxx"
75 #include "xfilter/xfparagraph.hxx"
76 #include "xfilter/xfstylemanager.hxx"
78 LwpSdwGroupLoaderV0102::LwpSdwGroupLoaderV0102(SvStream
* pStream
, LwpGraphicObject
* pGraphicObj
)
80 , m_pGraphicObj(pGraphicObj
)
81 , m_pDrawObjVector(nullptr)
85 LwpSdwGroupLoaderV0102::~LwpSdwGroupLoaderV0102()
90 * @descr entry of lwp-drawing objects. the function begins to parse the sdw-drawing bento stream and create
91 * the corresponding drawing objects.
92 * @param pDrawObjVector a container which will contains the created drawing object of XF-Model.
94 void LwpSdwGroupLoaderV0102::BeginDrawObjects(std::vector
< rtl::Reference
<XFFrame
> >* pDrawObjVector
)
97 m_pDrawObjVector
= pDrawObjVector
;
100 unsigned char BinSignature
[2];
101 m_pStream
->Read(BinSignature
,2);
102 if (BinSignature
[0] != 'S' || BinSignature
[1] != 'M')
108 unsigned short nVersion
;
109 m_pStream
->ReadUInt16(nVersion
);
116 m_pStream
->SeekRel(4);
118 unsigned short nRecCount
;
119 m_pStream
->ReadUInt16(nRecCount
);
121 m_pStream
->SeekRel(2);
123 unsigned short left
,top
,right
,bottom
;
124 m_pStream
->ReadUInt16(left
);
125 m_pStream
->ReadUInt16(top
);
126 m_pStream
->ReadUInt16(right
);
127 m_pStream
->ReadUInt16(bottom
);
129 m_pStream
->SeekRel(2);
131 //for calculating transformation params.
132 rtl::Reference
<LwpFrameLayout
> xMyFrameLayout(dynamic_cast<LwpFrameLayout
*>(m_pGraphicObj
->GetLayout(nullptr).get()));
133 if (xMyFrameLayout
.is())
135 LwpLayoutScale
* pMyScale
= xMyFrameLayout
->GetLayoutScale();
136 LwpLayoutGeometry
* pFrameGeo
= xMyFrameLayout
->GetGeometry();
137 if (pMyScale
&& pFrameGeo
)
139 // original drawing size
140 long nWidth
= 0, nHeight
= 0;
141 m_pGraphicObj
->GetGrafOrgSize(nWidth
, nHeight
);
142 double fGrafOrgWidth
= (double)nWidth
/TWIPS_PER_CM
;
143 double fGrafOrgHeight
= (double)nHeight
/TWIPS_PER_CM
;
146 double fLeftMargin
= xMyFrameLayout
->GetMarginsValue(MARGIN_LEFT
);
147 double fTopMargin
= xMyFrameLayout
->GetMarginsValue(MARGIN_TOP
);
150 double fFrameWidth
= LwpTools::ConvertFromUnitsToMetric(pFrameGeo
->GetWidth());
151 double fFrameHeight
= LwpTools::ConvertFromUnitsToMetric(pFrameGeo
->GetHeight());
154 LwpPoint
& rOffset
= pMyScale
->GetOffset();
155 double fOffsetX
= LwpTools::ConvertFromUnitsToMetric(rOffset
.GetX());
156 double fOffsetY
= LwpTools::ConvertFromUnitsToMetric(rOffset
.GetY());
159 sal_uInt16 nScalemode
= pMyScale
->GetScaleMode();
161 if (nScalemode
& LwpLayoutScale::CUSTOM
)
163 m_aTransformData
.fScaleX
=
164 LwpTools::ConvertFromUnitsToMetric(pMyScale
->GetScaleWidth()) / fGrafOrgWidth
;
165 m_aTransformData
.fScaleY
=
166 LwpTools::ConvertFromUnitsToMetric(pMyScale
->GetScaleHeight()) / fGrafOrgHeight
;
168 else if (nScalemode
& LwpLayoutScale::PERCENTAGE
)
170 double fScalePercentage
= (double)pMyScale
->GetScalePercentage() / 1000;
171 m_aTransformData
.fScaleX
= fScalePercentage
;
172 m_aTransformData
.fScaleY
= fScalePercentage
;
174 else if (nScalemode
& LwpLayoutScale::FIT_IN_FRAME
)
176 double fWidth0
= (double)right
/ TWIPS_PER_CM
;
177 double fHeight0
= (double)bottom
/ TWIPS_PER_CM
;
179 double fWidth1
= LwpTools::ConvertFromUnitsToMetric(pMyScale
->GetScaleWidth());
180 double fHeight1
= LwpTools::ConvertFromUnitsToMetric(pMyScale
->GetScaleHeight());
182 double fScaleX
= fWidth1
/ fWidth0
;
183 double fScaleY
= fHeight1
/ fHeight0
;
185 if (nScalemode
& LwpLayoutScale::MAINTAIN_ASPECT_RATIO
)
187 m_aTransformData
.fScaleX
= std::min(fScaleX
, fScaleY
);
188 m_aTransformData
.fScaleY
= m_aTransformData
.fScaleX
;
192 m_aTransformData
.fScaleX
= fWidth1
/ fWidth0
;
193 m_aTransformData
.fScaleY
= fHeight1
/ fHeight0
;
197 // placement: centered
198 if (xMyFrameLayout
->GetScaleCenter())
200 Rectangle
aBoundRect(static_cast<long>(left
*m_aTransformData
.fScaleX
+ fLeftMargin
),
201 static_cast<long>(top
* m_aTransformData
.fScaleY
+ fTopMargin
),
202 static_cast<long>(right
* m_aTransformData
.fScaleX
),
203 static_cast<long>(bottom
* m_aTransformData
.fScaleY
));
204 Point aCenter
= aBoundRect
.Center();
206 double fNewCenterX
= (double(left
)/TWIPS_PER_CM
+ fFrameWidth
/*-fOffsetX*/) / 2;
207 double fNewCenterY
= (double(top
)/TWIPS_PER_CM
+ fFrameHeight
/*-fOffsetY*/) / 2;
209 m_aTransformData
.fOffsetX
= fNewCenterX
- (double)aCenter
.X()/TWIPS_PER_CM
;
210 m_aTransformData
.fOffsetY
= fNewCenterY
-(double)aCenter
.Y()/TWIPS_PER_CM
;
214 m_aTransformData
.fOffsetX
= fOffsetX
;
215 m_aTransformData
.fOffsetY
= fOffsetY
;
218 m_aTransformData
.fOffsetX
+= fLeftMargin
;
219 m_aTransformData
.fOffsetY
+= fTopMargin
;
220 m_aTransformData
.fLeftMargin
= fLeftMargin
;
221 m_aTransformData
.fTopMargin
= fTopMargin
;
226 for (unsigned short i
= 0; i
< nRecCount
; i
++)
228 XFFrame
* pXFDrawObj
= CreateDrawObject();
232 pDrawObjVector
->push_back(pXFDrawObj
);
238 * @descr when we encounter a group object the function will be called to create a XF-drawgroup object
239 * the corresponding drawing objects.
240 * @param pDrawObjVector a container which will contains the created drawing object of XF-Model.
242 XFDrawGroup
* LwpSdwGroupLoaderV0102::CreateDrawGroupObject()
245 unsigned char BinSignature
[2];
246 m_pStream
->Read(BinSignature
,2);
247 if (BinSignature
[0] != 'S' || BinSignature
[1] != 'M')
253 unsigned short nVersion
;
254 m_pStream
->ReadUInt16(nVersion
);
261 m_pStream
->SeekRel(4);
263 unsigned short nRecCount
;
264 m_pStream
->ReadUInt16(nRecCount
);
266 m_pStream
->SeekRel(2);
268 unsigned short left
,top
,right
,bottom
;
269 m_pStream
->ReadUInt16(left
);
270 m_pStream
->ReadUInt16(top
);
271 m_pStream
->ReadUInt16(right
);
272 m_pStream
->ReadUInt16(bottom
);
274 m_pStream
->SeekRel(2);
276 XFDrawGroup
* pXFDrawGroup
= new XFDrawGroup();
279 for (unsigned short i
= 0; i
< nRecCount
; i
++)
281 XFFrame
* pXFDrawObj
= CreateDrawObject();
285 if (pXFDrawObj
->GetFrameType() == enumXFFrameImage
)
287 m_pDrawObjVector
->push_back(pXFDrawObj
);
291 pXFDrawGroup
->Add(pXFDrawObj
);
300 * @descr Create the XF-drawing objects according to the object type read from bento stream.
301 * @return the created XF-drawing objects.
303 XFFrame
* LwpSdwGroupLoaderV0102::CreateDrawObject()
306 unsigned char recType
;
307 m_pStream
->ReadUChar(recType
);
309 LwpDrawObj
* pDrawObj
= nullptr;
310 XFFrame
* pRetObjct
= nullptr;
314 case OT_PERPLINE
://fall-through
317 pDrawObj
= new LwpDrawLine(m_pStream
, &m_aTransformData
);
322 pDrawObj
= new LwpDrawPolyLine(m_pStream
, &m_aTransformData
);
327 pDrawObj
= new LwpDrawPolygon(m_pStream
, &m_aTransformData
);
328 pDrawObj
->SetObjectType(OT_POLYGON
);
331 case OT_SQUARE
://fall-through
334 pDrawObj
= new LwpDrawRectangle(m_pStream
, &m_aTransformData
);
337 case OT_RNDSQUARE
://fall-through
340 pDrawObj
= new LwpDrawRectangle(m_pStream
, &m_aTransformData
);
341 pDrawObj
->SetObjectType(OT_RNDRECT
);
344 case OT_CIRCLE
://fall-through
347 pDrawObj
= new LwpDrawEllipse(m_pStream
, &m_aTransformData
);
352 pDrawObj
= new LwpDrawArc(m_pStream
, &m_aTransformData
);
357 pDrawObj
= new LwpDrawTextBox(m_pStream
);
362 pDrawObj
= new LwpDrawTextArt(m_pStream
, &m_aTransformData
);
363 pDrawObj
->SetObjectType(OT_TEXTART
);
368 m_pStream
->SeekRel(2);
369 // read out the object header
370 pDrawObj
= new LwpDrawGroup(m_pStream
);
372 pRetObjct
= CreateDrawGroupObject();
375 pRetObjct
->SetAnchorType(enumXFAnchorFrame
);
378 case OT_CHART
://fall-through
379 case OT_METAFILE
://fall-through
382 LwpDrawMetafile
aMeta(m_pStream
);
386 pDrawObj
= new LwpDrawBitmap(m_pStream
);
387 pDrawObj
->SetObjectType(OT_BITMAP
);
391 // we don't need create the corresponding XF-object of a group object.
392 if (pDrawObj
&& recType
!= OT_GROUP
)
394 pRetObjct
= pDrawObj
->CreateXFDrawObject();
406 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */