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