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 ************************************************************************/
58 * For LWP filter architecture prototype - OLE object
61 #include <lwpfilehdr.hxx>
62 #include "lwpoleobject.hxx"
63 #include "lwpframelayout.hxx"
64 #include <o3tl/numeric.hxx>
67 * @descr: construction function
68 * @param: objHdr - object header, read before entering this function
69 * @param: pStrm - file stream
71 LwpGraphicOleObject::LwpGraphicOleObject(LwpObjectHeader
const& objHdr
, LwpSvStream
* pStrm
)
72 : LwpContent(objHdr
, pStrm
)
76 * @descr: Read GraphicOleObject part
78 void LwpGraphicOleObject::Read()
82 if (LwpFileHeader::m_nFileRevision
>= 0x000b)
84 // I'm not sure about the read method
85 m_pNextObj
.ReadIndexed(m_pObjStrm
.get());
86 m_pPrevObj
.ReadIndexed(m_pObjStrm
.get());
88 m_pObjStrm
->SkipExtra();
91 void LwpGraphicOleObject::GetGrafOrgSize(double& rWidth
, double& rHeight
)
97 void LwpGraphicOleObject::GetGrafScaledSize(double& fWidth
, double& fHeight
)
99 GetGrafOrgSize(fWidth
, fHeight
);
101 double fSclGrafWidth
= fWidth
; //LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
102 double fSclGrafHeight
103 = fHeight
; //LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
105 rtl::Reference
<LwpVirtualLayout
> xLayout(GetLayout(nullptr));
106 if (xLayout
.is() && xLayout
->IsFrame())
108 LwpFrameLayout
* pMyFrameLayout
= static_cast<LwpFrameLayout
*>(xLayout
.get());
109 LwpLayoutScale
* pMyScale
= pMyFrameLayout
->GetLayoutScale();
110 LwpLayoutGeometry
* pFrameGeo
= pMyFrameLayout
->GetGeometry();
112 // original image size
113 //double fOrgGrafWidth = (double)m_Cache.Width/TWIPS_PER_CM;
114 //double fOrgGrafHeight = (double)m_Cache.Height/TWIPS_PER_CM;
117 double fLeftMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_LEFT
);
118 double fRightMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_RIGHT
);
119 double fTopMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_TOP
);
120 double fBottomMargin
= pMyFrameLayout
->GetMarginsValue(MARGIN_BOTTOM
);
122 if (pMyScale
&& pFrameGeo
)
125 double fFrameWidth
= LwpTools::ConvertFromUnits(pFrameGeo
->GetWidth());
126 double fFrameHeight
= LwpTools::ConvertFromUnits(pFrameGeo
->GetHeight());
128 // calculate the displayed size of the frame
129 double fDisFrameWidth
= fFrameWidth
- (fLeftMargin
+ fRightMargin
);
130 double fDisFrameHeight
= fFrameHeight
- (fTopMargin
+ fBottomMargin
);
133 sal_uInt16 nScalemode
= pMyScale
->GetScaleMode();
134 if (nScalemode
& LwpLayoutScale::CUSTOM
)
136 fSclGrafWidth
= LwpTools::ConvertFromUnits(pMyScale
->GetScaleWidth());
137 fSclGrafHeight
= LwpTools::ConvertFromUnits(pMyScale
->GetScaleHeight());
139 else if (nScalemode
& LwpLayoutScale::PERCENTAGE
)
141 double fScalePercentage
142 = static_cast<double>(pMyScale
->GetScalePercentage()) / 1000;
143 fSclGrafWidth
= fScalePercentage
* fWidth
;
144 fSclGrafHeight
= fScalePercentage
* fHeight
;
146 else if (nScalemode
& LwpLayoutScale::FIT_IN_FRAME
)
148 if (pMyFrameLayout
->IsFitGraphic())
150 fSclGrafWidth
= fWidth
;
151 fSclGrafHeight
= fHeight
;
153 else if (nScalemode
& LwpLayoutScale::MAINTAIN_ASPECT_RATIO
)
155 if (fHeight
== 0.0 || fDisFrameHeight
== 0.0)
156 throw o3tl::divide_by_zero();
157 if (fWidth
/ fHeight
>= fDisFrameWidth
/ fDisFrameHeight
)
159 fSclGrafWidth
= fDisFrameWidth
;
161 throw o3tl::divide_by_zero();
162 fSclGrafHeight
= (fDisFrameWidth
/ fWidth
) * fHeight
;
166 fSclGrafHeight
= fDisFrameHeight
;
167 fSclGrafWidth
= (fDisFrameHeight
/ fHeight
) * fWidth
;
172 fSclGrafWidth
= fDisFrameWidth
;
173 fSclGrafHeight
= fDisFrameHeight
;
178 fWidth
= fSclGrafWidth
;
179 fHeight
= fSclGrafHeight
;
183 * @descr: construction function
184 * @param: objHdr - object header, read before entering this function
185 * @param: pStrm - file stream
187 LwpOleObject::LwpOleObject(LwpObjectHeader
const& objHdr
, LwpSvStream
* pStrm
)
188 : LwpGraphicOleObject(objHdr
, pStrm
)
189 , cPersistentFlags(0)
190 , m_SizeRect(0, 0, 5, 5)
194 * @descr: Read VO_OLEOBJECT record
196 void LwpOleObject::Read()
198 LwpGraphicOleObject::Read();
200 cPersistentFlags
= m_pObjStrm
->QuickReaduInt16();
204 if (LwpFileHeader::m_nFileRevision
>= 0x0004)
207 m_pObjStrm
->QuickReaduInt16();
209 m_pObjStrm
->QuickReadStringPtr();
211 if (LwpFileHeader::m_nFileRevision
< 0x000B)
213 // null pointers have a VO_INVALID type
214 //if (VO_INVALID == m_pObjStrm->QuickReaduInt16())
217 ID
.Read(m_pObjStrm
.get());
218 //return m_pObjStrm->Locate(ID);
222 ID
.ReadIndexed(m_pObjStrm
.get());
226 //return m_pObjStrm->Locate(ID);
230 if (m_pObjStrm
->CheckExtra())
232 m_pObjStrm
->QuickReaduInt16();
233 m_pObjStrm
->SkipExtra();
238 * @descr: Parse VO_OLEOBJECT and dump to XML stream only on WIN32 platform
239 * @param: pOutputStream - stream to dump OLE object
240 * @param: pFrameLayout - framelayout object used to dump OLE object
242 void LwpOleObject::Parse(IXFStream
* /*pOutputStream*/) {}
244 void LwpOleObject::XFConvert(XFContentContainer
* /*pCont*/) {}
246 void LwpOleObject::GetGrafOrgSize(double& rWidth
, double& rHeight
)
248 rWidth
= static_cast<double>(m_SizeRect
.GetWidth()) / 1000; //cm unit
249 rHeight
= static_cast<double>(m_SizeRect
.GetHeight()) / 1000; //cm unit
252 void LwpOleObject::RegisterStyle() {}
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */