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 : * @file
58 : * For LWP filter architecture prototype - OLE object
59 : */
60 : /*************************************************************************
61 : * Change History
62 : Feb 2005 Created
63 : ************************************************************************/
64 : #include <stdio.h>
65 : #include <tools/stream.hxx>
66 : #include "lwpglobalmgr.hxx"
67 : #include "lwpoleobject.hxx"
68 : #include "lwpobjfactory.hxx"
69 : #include "lwpidxmgr.hxx"
70 : #include "lwp9reader.hxx"
71 : #include "xfilter/xfparagraph.hxx"
72 : #include "lwpframelayout.hxx"
73 : #include "xfilter/xfstylemanager.hxx"
74 : #include "bento.hxx"
75 :
76 : /**
77 : * @descr: construction function
78 : * @param: objHdr - object header, read before entering this function
79 : * @param: pStrm - file stream
80 : * @return: None
81 : * @date: 2/22/2005
82 : */
83 50 : LwpGraphicOleObject::LwpGraphicOleObject(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
84 50 : : LwpContent(objHdr, pStrm)
85 50 : {}
86 : /**
87 : * @descr: Read GraphicOleObject part
88 : * @param: None
89 : * @return: None
90 : * @date: 2/22/2005
91 : */
92 50 : void LwpGraphicOleObject::Read()
93 : {
94 50 : LwpContent::Read();
95 :
96 48 : if (LwpFileHeader::m_nFileRevision >= 0x000b)
97 : {
98 : // I'm not sure about the read method
99 48 : m_pNextObj.ReadIndexed(m_pObjStrm);
100 48 : m_pPrevObj.ReadIndexed(m_pObjStrm);
101 : }
102 48 : m_pObjStrm->SkipExtra();
103 :
104 48 : }
105 :
106 0 : void LwpGraphicOleObject::GetGrafOrgSize(double & rWidth, double & rHeight)
107 : {
108 0 : rWidth = 0;
109 0 : rHeight = 0;
110 0 : }
111 :
112 26 : void LwpGraphicOleObject::GetGrafScaledSize(double & fWidth, double & fHeight)
113 : {
114 26 : GetGrafOrgSize(fWidth, fHeight);
115 : // scaled image size
116 26 : double fSclGrafWidth = fWidth;//LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
117 26 : double fSclGrafHeight = fHeight;//LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
118 :
119 26 : LwpVirtualLayout* pLayout = GetLayout(NULL);
120 26 : if (pLayout && pLayout->IsFrame())
121 : {
122 26 : LwpFrameLayout* pMyFrameLayout = static_cast<LwpFrameLayout*>(pLayout);
123 26 : LwpLayoutScale* pMyScale = pMyFrameLayout->GetLayoutScale();
124 26 : LwpLayoutGeometry* pFrameGeo = pMyFrameLayout->GetGeometry();
125 :
126 : // original image size
127 : //double fOrgGrafWidth = (double)m_Cache.Width/TWIPS_PER_CM;
128 : //double fOrgGrafHeight = (double)m_Cache.Height/TWIPS_PER_CM;
129 :
130 : // get margin values
131 26 : double fLeftMargin = pMyFrameLayout->GetMarginsValue(MARGIN_LEFT);
132 26 : double fRightMargin = pMyFrameLayout->GetMarginsValue(MARGIN_RIGHT);
133 26 : double fTopMargin = pMyFrameLayout->GetMarginsValue(MARGIN_TOP);
134 26 : double fBottomMargin = pMyFrameLayout->GetMarginsValue(MARGIN_BOTTOM);
135 :
136 26 : if (pMyScale && pFrameGeo)
137 : {
138 : // frame size
139 26 : double fFrameWidth = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetWidth());
140 26 : double fFrameHeight = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetHeight());
141 :
142 : // calculate the displayed size of the frame
143 26 : double fDisFrameWidth = fFrameWidth - (fLeftMargin+fRightMargin);
144 26 : double fDisFrameHeight = fFrameHeight - (fTopMargin+fBottomMargin);
145 :
146 : // get scale mode
147 26 : sal_uInt16 nScalemode = pMyScale->GetScaleMode();
148 26 : if (nScalemode & LwpLayoutScale::CUSTOM)
149 : {
150 4 : fSclGrafWidth = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
151 4 : fSclGrafHeight = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
152 : }
153 22 : else if (nScalemode & LwpLayoutScale::PERCENTAGE)
154 : {
155 10 : double fScalePercentage = (double)pMyScale->GetScalePercentage() / 1000;
156 10 : fSclGrafWidth = fScalePercentage * fWidth;
157 10 : fSclGrafHeight = fScalePercentage * fHeight;
158 : }
159 12 : else if (nScalemode & LwpLayoutScale::FIT_IN_FRAME)
160 : {
161 12 : if (pMyFrameLayout->IsFitGraphic())
162 : {
163 0 : fSclGrafWidth = fWidth;
164 0 : fSclGrafHeight = fHeight;
165 : }
166 12 : else if (nScalemode & LwpLayoutScale::MAINTAIN_ASPECT_RATIO)
167 : {
168 8 : if (fWidth/fHeight >= fDisFrameWidth/fDisFrameHeight)
169 : {
170 2 : fSclGrafWidth = fDisFrameWidth;
171 2 : fSclGrafHeight = (fDisFrameWidth/fWidth) * fHeight;
172 : }
173 : else
174 : {
175 6 : fSclGrafHeight = fDisFrameHeight;
176 6 : fSclGrafWidth = (fDisFrameHeight/fHeight) * fWidth;
177 : }
178 : }
179 : else
180 : {
181 4 : fSclGrafWidth = fDisFrameWidth;
182 4 : fSclGrafHeight = fDisFrameHeight;
183 : }
184 : }
185 : }
186 : }
187 26 : fWidth = fSclGrafWidth ;
188 26 : fHeight = fSclGrafHeight ;
189 :
190 26 : }
191 :
192 : /**
193 : * @descr: construction function
194 : * @param: objHdr - object header, read before entering this function
195 : * @param: pStrm - file stream
196 : * @return: None
197 : * @date: 2/22/2005
198 : */
199 36 : LwpOleObject::LwpOleObject(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
200 : : LwpGraphicOleObject(objHdr, pStrm)
201 : , cPersistentFlags(0)
202 36 : , m_SizeRect(0,0,5,5)
203 : {
204 36 : }
205 : /**
206 : * @descr: Read VO_OLEOBJECT record
207 : * @param: None
208 : * @return: None
209 : * @date: 2/22/2005
210 : */
211 36 : void LwpOleObject::Read()
212 : {
213 36 : LwpGraphicOleObject::Read();
214 :
215 36 : cPersistentFlags = m_pObjStrm->QuickReaduInt16();
216 :
217 : // qCMarker read
218 36 : LwpObjectID ID;
219 :
220 36 : if (LwpFileHeader::m_nFileRevision >= 0x0004)
221 : {
222 36 : m_pObjStrm->QuickReaduInt16();
223 :
224 36 : m_pObjStrm->QuickReadStringPtr();
225 :
226 36 : if (LwpFileHeader::m_nFileRevision < 0x000B)
227 : {
228 : // null pointers have a VO_INVALID type
229 : //if (VO_INVALID == m_pObjStrm->QuickReaduInt16())
230 : // return;
231 :
232 0 : ID.Read(m_pObjStrm);
233 : //return m_pObjStrm->Locate(ID);
234 : }
235 : else
236 : {
237 36 : ID.ReadIndexed(m_pObjStrm);
238 : //if (ID.IsNull())
239 : // return;
240 :
241 : //return m_pObjStrm->Locate(ID);
242 : }
243 : }
244 :
245 36 : if (m_pObjStrm->CheckExtra())
246 : {
247 36 : m_pObjStrm->QuickReaduInt16();
248 36 : m_pObjStrm->SkipExtra();
249 : }
250 :
251 36 : }
252 :
253 : /**
254 : * @descr: Parse VO_OLEOBJECT and dump to XML stream only on WIN32 platform
255 : * @param: pOutputStream - stream to dump OLE object
256 : * @param: pFrameLayout - framlayout object used to dump OLE object
257 : * @return: None
258 : * @date: 2/22/2005
259 : */
260 0 : void LwpOleObject::Parse(IXFStream* /*pOutputStream*/)
261 : {
262 0 : }
263 :
264 18 : void LwpOleObject::XFConvert(XFContentContainer * /*pCont*/)
265 : {
266 18 : }
267 :
268 18 : void LwpOleObject::GetGrafOrgSize(double & rWidth, double & rHeight)
269 : {
270 18 : rWidth = (double)m_SizeRect.GetWidth()/1000;//cm unit
271 18 : rHeight = (double)m_SizeRect.GetHeight()/1000;//cm unit
272 18 : }
273 :
274 36 : void LwpOleObject::RegisterStyle()
275 : {
276 42 : }
277 :
278 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|