LibreOffice Module lotuswordpro (master) 1
lwpoleobject.cxx
Go to the documentation of this file.
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 ************************************************************************/
61#include <lwpfilehdr.hxx>
62#include "lwpoleobject.hxx"
63#include "lwpframelayout.hxx"
64#include <o3tl/numeric.hxx>
65
72 : LwpContent(objHdr, pStrm)
73{
74}
79{
81
83 {
84 // I'm not sure about the read method
87 }
88 m_pObjStrm->SkipExtra();
89}
90
91void LwpGraphicOleObject::GetGrafOrgSize(double& rWidth, double& rHeight)
92{
93 rWidth = 0;
94 rHeight = 0;
95}
96
97void LwpGraphicOleObject::GetGrafScaledSize(double& fWidth, double& fHeight)
98{
99 GetGrafOrgSize(fWidth, fHeight);
100 // scaled image size
101 double fSclGrafWidth = fWidth; //LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
102 double fSclGrafHeight
103 = fHeight; //LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
104
106 if (xLayout.is() && xLayout->IsFrame())
107 {
108 LwpFrameLayout* pMyFrameLayout = static_cast<LwpFrameLayout*>(xLayout.get());
109 LwpLayoutScale* pMyScale = pMyFrameLayout->GetLayoutScale();
110 LwpLayoutGeometry* pFrameGeo = pMyFrameLayout->GetGeometry();
111
112 // original image size
113 //double fOrgGrafWidth = (double)m_Cache.Width/TWIPS_PER_CM;
114 //double fOrgGrafHeight = (double)m_Cache.Height/TWIPS_PER_CM;
115
116 // get margin values
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);
121
122 if (pMyScale && pFrameGeo)
123 {
124 // frame size
125 double fFrameWidth = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetWidth());
126 double fFrameHeight = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetHeight());
127
128 // calculate the displayed size of the frame
129 double fDisFrameWidth = fFrameWidth - (fLeftMargin + fRightMargin);
130 double fDisFrameHeight = fFrameHeight - (fTopMargin + fBottomMargin);
131
132 // get scale mode
133 sal_uInt16 nScalemode = pMyScale->GetScaleMode();
134 if (nScalemode & LwpLayoutScale::CUSTOM)
135 {
136 fSclGrafWidth = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
137 fSclGrafHeight = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
138 }
139 else if (nScalemode & LwpLayoutScale::PERCENTAGE)
140 {
141 double fScalePercentage
142 = static_cast<double>(pMyScale->GetScalePercentage()) / 1000;
143 fSclGrafWidth = fScalePercentage * fWidth;
144 fSclGrafHeight = fScalePercentage * fHeight;
145 }
146 else if (nScalemode & LwpLayoutScale::FIT_IN_FRAME)
147 {
148 if (pMyFrameLayout->IsFitGraphic())
149 {
150 fSclGrafWidth = fWidth;
151 fSclGrafHeight = fHeight;
152 }
153 else if (nScalemode & LwpLayoutScale::MAINTAIN_ASPECT_RATIO)
154 {
155 if (fHeight == 0.0 || fDisFrameHeight == 0.0)
156 throw o3tl::divide_by_zero();
157 if (fWidth / fHeight >= fDisFrameWidth / fDisFrameHeight)
158 {
159 fSclGrafWidth = fDisFrameWidth;
160 if (fWidth == 0.0)
161 throw o3tl::divide_by_zero();
162 fSclGrafHeight = (fDisFrameWidth / fWidth) * fHeight;
163 }
164 else
165 {
166 fSclGrafHeight = fDisFrameHeight;
167 fSclGrafWidth = (fDisFrameHeight / fHeight) * fWidth;
168 }
169 }
170 else
171 {
172 fSclGrafWidth = fDisFrameWidth;
173 fSclGrafHeight = fDisFrameHeight;
174 }
175 }
176 }
177 }
178 fWidth = fSclGrafWidth;
179 fHeight = fSclGrafHeight;
180}
181
188 : LwpGraphicOleObject(objHdr, pStrm)
189 , cPersistentFlags(0)
190 , m_SizeRect(0, 0, 5, 5)
191{
192}
197{
199
200 cPersistentFlags = m_pObjStrm->QuickReaduInt16();
201
202 // qCMarker read
203
204 if (LwpFileHeader::m_nFileRevision >= 0x0004)
205 {
207 m_pObjStrm->QuickReaduInt16();
208
209 m_pObjStrm->QuickReadStringPtr();
210
212 {
213 // null pointers have a VO_INVALID type
214 //if (VO_INVALID == m_pObjStrm->QuickReaduInt16())
215 // return;
216
217 ID.Read(m_pObjStrm.get());
218 //return m_pObjStrm->Locate(ID);
219 }
220 else
221 {
222 ID.ReadIndexed(m_pObjStrm.get());
223 //if (ID.IsNull())
224 // return;
225
226 //return m_pObjStrm->Locate(ID);
227 }
228 }
229
230 if (m_pObjStrm->CheckExtra())
231 {
232 m_pObjStrm->QuickReaduInt16();
233 m_pObjStrm->SkipExtra();
234 }
235}
236
242void LwpOleObject::Parse(IXFStream* /*pOutputStream*/) {}
243
245
246void LwpOleObject::GetGrafOrgSize(double& rWidth, double& rHeight)
247{
248 rWidth = static_cast<double>(m_SizeRect.GetWidth()) / 1000; //cm unit
249 rHeight = static_cast<double>(m_SizeRect.GetHeight()) / 1000; //cm unit
250}
251
253
254/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Stream wrapper for sax writer.
Definition: ixfstream.hxx:72
Base class of all Lwp content objects.
Definition: lwpcontent.hxx:74
void Read() override
@descr default read function
Definition: lwpcontent.cxx:81
rtl::Reference< LwpVirtualLayout > GetLayout(LwpVirtualLayout const *pStartLayout)
Definition: lwpcontent.cxx:124
static sal_uInt16 m_nFileRevision
Definition: lwpfilehdr.hxx:77
VO_FRAMELAYOUT object.
@descr super class of LwpOleObject and LwpGraphicObject
LwpGraphicOleObject(LwpObjectHeader const &objHdr, LwpSvStream *pStrm)
@descr: construction function
LwpObjectID m_pNextObj
virtual void GetGrafOrgSize(double &rWidth, double &rHeight)
void GetGrafScaledSize(double &fWidth, double &fHeight)
virtual void Read() override
@descr: Read GraphicOleObject part
LwpObjectID m_pPrevObj
sal_Int32 GetHeight() const
Definition: lwplaypiece.hxx:86
sal_Int32 GetWidth() const
Definition: lwplaypiece.hxx:85
sal_uInt32 GetScalePercentage() const
sal_uInt16 GetScaleMode() const
sal_Int32 GetScaleWidth() const
sal_Int32 GetScaleHeight() const
LwpLayoutScale * GetLayoutScale()
Definition: lwplayout.hxx:366
LwpLayoutGeometry * GetGeometry()
@descr: Get the geometry of current layout
Definition: lwplayout.cxx:634
Base class of all Lwp VO objects.
Definition: lwpobjhdr.hxx:71
object id class
Definition: lwpobjid.hxx:79
void ReadIndexed(LwpSvStream *pStrm)
@descr Read object id with indexed format from stream if index>0, lowid is get from time table per th...
Definition: lwpobjid.cxx:96
std::unique_ptr< LwpObjectStream > m_pObjStrm
Definition: lwpobj.hxx:90
tools::Rectangle m_SizeRect
sal_uInt16 cPersistentFlags
virtual void Parse(IXFStream *pOutputStream) override
@descr: Parse VO_OLEOBJECT and dump to XML stream only on WIN32 platform
LwpOleObject(LwpObjectHeader const &objHdr, LwpSvStream *pStrm)
@descr: construction function
virtual void XFConvert(XFContentContainer *pCont) override
@descr default XFConvert function pCont is the XFContentContainer for the object conversion
void GetGrafOrgSize(double &rWidth, double &rHeight) override
virtual void Read() override
@descr: Read VO_OLEOBJECT record
virtual void RegisterStyle() override
@descr default register style function
encapsulate XInputStream to provide SvStream like interfaces
Definition: lwpsvstream.hxx:69
static double ConvertFromUnitsToMetric(sal_Int32 nUnits)
Definition: lwptools.hxx:117
bool IsFitGraphic()
@descr: Whether the size of layout is fit the graphic
Definition: lwplayout.cxx:401
double GetMarginsValue(sal_uInt8 nWhichSide)
Definition: lwplayout.hxx:153
A container for content.
constexpr tools::Long GetWidth() const
constexpr tools::Long GetHeight() const
const sal_uInt8 MARGIN_BOTTOM
Definition: lwpmargins.hxx:66
const sal_uInt8 MARGIN_RIGHT
Definition: lwpmargins.hxx:64
const sal_uInt8 MARGIN_TOP
Definition: lwpmargins.hxx:65
const sal_uInt8 MARGIN_LEFT
Definition: lwpmargins.hxx:63
For LWP filter architecture prototype - OLE object.