1 /* This file is part of the wvWare 2 project
2 Copyright (C) 2003 Werner Trobin <trobin@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
17 */
18
19 #include "graphics.h"
20 #include "word97_generated.h"
21
22 using namespace wvWare;
23
Drawings(OLEStreamReader * table,const Word97::FIB & fib)24 Drawings::Drawings( OLEStreamReader* table, const Word97::FIB &fib ) :
25 m_plcfspaMom( 0 ), m_plcfspaHdr( 0 ), m_plcftxbxTxt( 0 ), m_plcfHdrtxbxTxt( 0 ),
26 m_plcftxbxBkd( 0 ), m_plcfHdrtxbxBkd( 0 )
27 {
28 table->push();
29
30 // Don't try to read that. It will cause eye-cancer!
31 if ( fib.lcbPlcspaMom != 0 && table->seek( fib.fcPlcspaMom, G_SEEK_SET ) )
32 m_plcfspaMom = new PLCF<Word97::FSPA>( fib.lcbPlcspaMom, table, false );
33 if ( fib.lcbPlcspaHdr != 0 && table->seek( fib.fcPlcspaHdr, G_SEEK_SET ) )
34 m_plcfspaHdr = new PLCF<Word97::FSPA>( fib.lcbPlcspaHdr, table, false );
35
36 if ( fib.lcbPlcftxbxTxt != 0 && table->seek( fib.fcPlcftxbxTxt, G_SEEK_SET ) )
37 m_plcftxbxTxt = new PLCF<Word97::FTXBXS>( fib.lcbPlcftxbxTxt, table, false );
38 if ( fib.lcbPlcfHdrtxbxTxt != 0 && table->seek( fib.fcPlcfHdrtxbxTxt, G_SEEK_SET ) )
39 m_plcfHdrtxbxTxt = new PLCF<Word97::FTXBXS>( fib.lcbPlcfHdrtxbxTxt, table, false );
40
41 if ( fib.lcbPlcftxbxBkd != 0 && table->seek( fib.fcPlcftxbxBkd, G_SEEK_SET ) )
42 m_plcftxbxBkd = new PLCF<Word97::BKD>( fib.lcbPlcftxbxBkd, table, false );
43 if ( fib.lcbPlcftxbxHdrBkd != 0 && table->seek( fib.fcPlcftxbxHdrBkd, G_SEEK_SET ) )
44 m_plcfHdrtxbxBkd = new PLCF<Word97::BKD>( fib.lcbPlcftxbxHdrBkd, table, false );
45
46 table->pop();
47 }
48
~Drawings()49 Drawings::~Drawings()
50 {
51 delete m_plcfHdrtxbxBkd;
52 delete m_plcftxbxBkd;
53 delete m_plcfHdrtxbxTxt;
54 delete m_plcftxbxTxt;
55 delete m_plcfspaHdr;
56 delete m_plcfspaMom;
57 }
58
EscherHeader(OLEStreamReader * stream)59 EscherHeader::EscherHeader( OLEStreamReader* stream )
60 {
61 //read first 32 bits
62 U32 shifterU32;
63 shifterU32 = stream->readU32();
64 ver = shifterU32;
65 shifterU32>>=4;
66 inst = shifterU32;
67 shifterU32>>=12;
68 fbt = shifterU32;
69 //read second 32 bits
70 cbLength = stream->readU32();
71 }
72
~EscherHeader()73 EscherHeader::~EscherHeader()
74 {
75 }
76
isAtom()77 bool EscherHeader::isAtom()
78 {
79 //0xF in ver means it's a container
80 if( ver == 0xF )
81 return false;
82 else
83 return true;
84 }
85
getRecordType()86 string EscherHeader::getRecordType()
87 {
88 string s;
89 switch( fbt ) {
90 case 0xF000:
91 s = "msofbtDggContainer";
92 break;
93 case 0xF001:
94 s = "msofbtBstoreContainer";
95 break;
96 case 0xF002:
97 s = "msofbtDgContainer";
98 break;
99 case 0xF004:
100 s = "msofbtSpContainer";
101 break;
102 case 0xF006:
103 s = "msofbtDgg";
104 break;
105 case 0xF007:
106 s = "msofbtBSE";
107 break;
108 case 0xF008:
109 s = "msofbtDg";
110 break;
111 case 0xF00A:
112 s = "msofbtSp";
113 break;
114 case 0xF00B:
115 s = "msofbtOPT";
116 break;
117 case 0xF010:
118 s = "msofbtClientAnchor";
119 break;
120 case 0xF016:
121 s = "msofbtCLSID";
122 break;
123 case 0xF01A:
124 s = "EMF";
125 break;
126 case 0xF01B:
127 s = "WMF";
128 break;
129 case 0xF01C:
130 s = "PICT";
131 break;
132 case 0xF01D:
133 s = "JPEG";
134 break;
135 case 0xF01E:
136 s = "PNG";
137 break;
138 case 0xF01F:
139 s = "DIB";
140 break;
141 case 0xF11A:
142 s = "msofbtColorMRU";
143 break;
144 case 0xF11E:
145 s = "msofbtSplitMenuColors";
146 break;
147 case 0xF118:
148 s = "msofbtRegroupItems";
149 break;
150 default:
151 s = "unknown";
152 }
153 return s;
154 }
155
156 //returns size of the record NOT COUNTING the header
recordSize()157 int EscherHeader::recordSize()
158 {
159 return static_cast<int> (cbLength);
160 }
161
dump()162 void EscherHeader::dump()
163 {
164 wvlog << "Dumping Escher header:" << std::endl;
165 wvlog << " ver = " << ver << std::endl;
166 wvlog << " inst = " << inst << std::endl;
167 wvlog << " fbt = " << fbt << std::endl;
168 wvlog << " cbLength = " << cbLength << std::endl;
169 wvlog << "Finished dumping Escher header." << std::endl;
170 }
171
FBSE(OLEStreamReader * stream)172 FBSE::FBSE( OLEStreamReader* stream )
173 {
174 btWin32 = static_cast<MSOBLIPTYPE> (stream->readU8());
175 btMacOS = static_cast<MSOBLIPTYPE> (stream->readU8());
176 stream->read( rgbUid, 16 );
177 tag = stream->readU16();
178 size = stream->readU32();
179 cRef = stream->readU32();
180 foDelay = stream->readU32();
181 usage = static_cast<MSOBLIPUSAGE> (stream->readU8());
182 cbName = stream->readU8();
183 unused2 = stream->readU8();
184 unused3 = stream->readU8();
185 }
186
~FBSE()187 FBSE::~FBSE()
188 {
189 }
190
dump()191 void FBSE::dump()
192 {
193 wvlog << "Dumping FBSE:" << std::endl;
194 wvlog << "\tbtWin32 = " << btWin32 << std::endl;
195 wvlog << "\tbtMacOS = " << btMacOS << std::endl;
196 wvlog << "\trgbUid = " << rgbUid << std::endl;
197 wvlog << "\ttag = " << tag << std::endl;
198 wvlog << "\tsize = " << size << std::endl;
199 wvlog << "\tcRef = " << cRef << std::endl;
200 wvlog << "\tfoDelay = " << foDelay << std::endl;
201 wvlog << "\tusage = " << static_cast<int> (usage) << std::endl;
202 wvlog << "\tcbName = " << static_cast<unsigned int> (cbName) << std::endl;
203 wvlog << "\tunused2 = " << static_cast<unsigned int> (unused2) << std::endl;
204 wvlog << "\tunused3 = " << static_cast<unsigned int> (unused3) << std::endl;
205 wvlog << "Finished dumping FBSE." << std::endl;
206 }
207
recordSize()208 int FBSE::recordSize()
209 {
210 //just add up the sizes of btWin32 + btMacOS + rgUid[16] + ...
211 return 36;
212 }
213
getBlipType()214 int FBSE::getBlipType()
215 {
216 //cast enum to int
217 return static_cast<int> (btWin32);
218 }
219
getStreamOffset()220 int FBSE::getStreamOffset()
221 {
222 //cast U32 to unsigned int
223 return static_cast<unsigned int> (foDelay);
224 }
225
getNameLength()226 int FBSE::getNameLength()
227 {
228 //cast U8 to unsigned int
229 return static_cast<unsigned int> (cbName);
230 }
231
Blip(OLEStreamReader * stream,string blipType)232 Blip::Blip( OLEStreamReader* stream, string blipType )
233 {
234 m_size = 0; //just an initial value
235 m_blipType = blipType;
236 m_isMetafileBlip = false;
237 if( blipType.compare("JPEG") == 0 || blipType.compare("PNG") == 0
238 || blipType.compare("DIB") == 0 )
239 {
240 stream->read( m_rgbUid, 16 ); //data UID
241 m_bTag = stream->readU8();
242 m_size = 17;
243 //initialize other variables just to 0
244 m_cb = 0;
245 m_rcBounds = 0;
246 m_ptSize = 0;
247 m_cbSave = 0;
248 m_fCompression = 255; //test value, so we'll just initialize to this
249 m_fFilter = 255; //test value, so we'll just initialize to this
250 }
251 else if( blipType.compare("EMF") == 0 || blipType.compare("WMF") == 0
252 || blipType.compare("PICT") == 0 )
253 {
254 stream->read( m_rgbUid, 16 ); //data UID
255 stream->read( m_rgbUidPrimary, 16 ); //primary Uid
256 m_cb = stream->readU32(); //cache of metafile size
257 m_rcBounds = stream->readU32(); //boundary of metafile drawing commands
258 m_ptSize = stream->readU32(); //size of metafile in EMU's
259 m_cbSave = stream->readU32(); //cache of saved size (size of m_pvBits)
260 m_fCompression = stream->readU8(); //compression
261 m_fFilter = stream->readU8(); //always msofilterNone = 254
262 m_isMetafileBlip = true;
263 m_size = 46;
264 }
265 }
266
~Blip()267 Blip::~Blip()
268 {
269 }
270
isMetafileBlip()271 bool Blip::isMetafileBlip()
272 {
273 return m_isMetafileBlip;
274 }
275
isCompressed()276 bool Blip::isCompressed()
277 {
278 //only metafile blips can be compressed
279 //and the flag has to be set
280 if( isMetafileBlip() && m_fCompression == 0 )
281 return true;
282 else
283 return false;
284 }
285
recordSize()286 int Blip::recordSize()
287 {
288 return m_size;
289 }
290
imageSize()291 int Blip::imageSize()
292 {
293 return static_cast<unsigned int> (m_cb);
294 }
295
compressedImageSize()296 int Blip::compressedImageSize()
297 {
298 return static_cast<unsigned int> (m_cbSave);
299 }
300
dump()301 void Blip::dump()
302 {
303 if( !isCompressed() )
304 {
305 wvlog << " bitmap blip:" << std::endl;
306 wvlog << " m_rgbUid = " << m_rgbUid << std::endl;
307 wvlog << " m_bTag = " << static_cast<unsigned int> (m_bTag) << std::endl;
308 }
309 else
310 {
311 wvlog << " metafile blip:" << std::endl;
312 wvlog << " m_rgbUid = " << m_rgbUid << std::endl;
313 wvlog << " m_cb = " << m_cb << std::endl;
314 wvlog << " m_rcBounds = " << m_rcBounds << std::endl;
315 wvlog << " m_ptSize = " << m_ptSize << std::endl;
316 wvlog << " m_cbSave = " << m_cbSave << std::endl;
317 wvlog << " m_fCompression = " << static_cast<unsigned int> (m_fCompression) << std::endl;
318 wvlog << " m_fFilter = " << static_cast<unsigned int> (m_fFilter) << std::endl;
319 }
320 }
321
322