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., 51 Franklin Street, Fifth Floor,
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, WV2_SEEK_SET ) )
32         m_plcfspaMom = new PLCF<Word97::FSPA>( fib.lcbPlcspaMom, table, false );
33     if ( fib.lcbPlcspaHdr != 0 && table->seek( fib.fcPlcspaHdr, WV2_SEEK_SET ) )
34         m_plcfspaHdr = new PLCF<Word97::FSPA>( fib.lcbPlcspaHdr, table, false );
35 
36     if ( fib.lcbPlcftxbxTxt != 0 && table->seek( fib.fcPlcftxbxTxt, WV2_SEEK_SET ) )
37         m_plcftxbxTxt = new PLCF<Word97::FTXBXS>( fib.lcbPlcftxbxTxt, table, false );
38     if ( fib.lcbPlcfHdrtxbxTxt != 0 && table->seek( fib.fcPlcfHdrtxbxTxt, WV2_SEEK_SET ) )
39         m_plcfHdrtxbxTxt = new PLCF<Word97::FTXBXS>( fib.lcbPlcfHdrtxbxTxt, table, false );
40 
41     if ( fib.lcbPlcftxbxBkd != 0 && table->seek( fib.fcPlcftxbxBkd, WV2_SEEK_SET ) )
42         m_plcftxbxBkd = new PLCF<Word97::BKD>( fib.lcbPlcftxbxBkd, table, false );
43     if ( fib.lcbPlcftxbxHdrBkd != 0 && table->seek( fib.fcPlcftxbxHdrBkd, WV2_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 }
59 
EscherHeader(OLEStreamReader * stream)60 EscherHeader::EscherHeader( OLEStreamReader* stream )
61 {
62     //read first 32 bits
63     U32 shifterU32;
64     shifterU32 = stream->readU32();
65     recVer = shifterU32;
66     shifterU32>>=4;
67     recInstance = shifterU32;
68     shifterU32>>=12;
69     recType = shifterU32;
70     //read second 32 bits
71     recLen = stream->readU32();
72 }
73 
~EscherHeader()74 EscherHeader::~EscherHeader()
75 {
76 }
77 
isAtom()78 bool EscherHeader::isAtom()
79 {
80     //0xF in ver means it's a container
81     if( recVer == 0xF  )
82         return false;
83     else
84         return true;
85 }
86 
getRecordType()87 string EscherHeader::getRecordType()
88 {
89     string s;
90     switch( recType ) {
91         case 0xF000:
92             s = "msofbtDggContainer";
93             break;
94         case 0xF001:
95             s = "msofbtBstoreContainer";
96             break;
97         case 0xF002:
98             s = "msofbtDgContainer";
99             break;
100         case 0xF004:
101             s = "msofbtSpContainer";
102             break;
103         case 0xF006:
104             s = "msofbtDgg";
105             break;
106         case 0xF007:
107             s = "msofbtBSE";
108             break;
109         case 0xF008:
110             s = "msofbtDg";
111             break;
112         case 0xF00A:
113             s = "msofbtSp";
114             break;
115         case 0xF00B:
116             s = "msofbtOPT";            // OfficeArtFOPT - MS-ODRAW, page 44 of 621
117             break;
118         case 0xF010:
119             s = "msofbtClientAnchor";
120             break;
121         case 0xF016:
122             s = "msofbtCLSID";
123             break;
124         case 0xF01A:
125             s = "EMF";
126             break;
127         case 0xF01B:
128             s = "WMF";
129             break;
130         case 0xF01C:
131             s = "PICT";
132             break;
133         case 0xF01D:
134             s = "JPEG";
135             break;
136         case 0xF01E:
137             s = "PNG";
138             break;
139         case 0xF01F:
140             s = "DIB";
141             break;
142         case 0xF11A:
143             s = "msofbtColorMRU";
144             break;
145         case 0xF11E:
146             s = "msofbtSplitMenuColors";
147             break;
148         case 0xF118:
149             s = "msofbtRegroupItems";
150             break;
151         case 0xF122:
152             s = "msofbtTerOPT";         // OfficeArtTertiaryFOPT - MS-ODRAW, page 46 of 621
153             break;
154         default:
155             s = "unknown";
156     }
157     return s;
158 }
159 
160 //returns size of the record NOT COUNTING the header
recordSize()161 int EscherHeader::recordSize()
162 {
163     return static_cast<int> (recLen);
164 }
165 
166 // returns the record instance
recordInstance()167 int EscherHeader::recordInstance()
168 {
169     return recInstance;
170 }
171 
dump()172 void EscherHeader::dump()
173 {
174     wvlog << "Dumping Escher header:" << endl;
175     wvlog << " recVer = " << hex << recVer << dec << endl;
176     wvlog << " recInstance = " << hex << recInstance << dec << endl;
177     wvlog << " recType = " << hex << recType << dec << endl;
178     wvlog << " recLen = " << recLen << endl;
179     wvlog << "Finished dumping Escher header." << endl;
180 }
181 
FBSE(OLEStreamReader * stream)182 FBSE::FBSE( OLEStreamReader* stream )
183 {
184     btWin32 = static_cast<MSOBLIPTYPE> (stream->readU8());
185     btMacOS = static_cast<MSOBLIPTYPE> (stream->readU8());
186     stream->read( rgbUid, 16 );
187     tag = stream->readU16();
188     size = stream->readU32();
189     cRef = stream->readU32();
190     foDelay = stream->readU32();
191     usage = static_cast<MSOBLIPUSAGE> (stream->readU8());
192     cbName = stream->readU8();
193     unused2 = stream->readU8();
194     unused3 = stream->readU8();
195 }
196 
~FBSE()197 FBSE::~FBSE()
198 {
199 }
200 
dump()201 void FBSE::dump()
202 {
203     wvlog << "Dumping FBSE:" << endl;
204     wvlog << "\tbtWin32 = " << btWin32 << endl;
205     wvlog << "\tbtMacOS = " << btMacOS << endl;
206     wvlog << "\trgbUid = " << rgbUid << endl;
207     wvlog << "\ttag = " << tag << endl;
208     wvlog << "\tsize = " << size << endl;
209     wvlog << "\tcRef = " << cRef << endl;
210     wvlog << "\tfoDelay = " << foDelay << endl;
211     wvlog << "\tusage = " << static_cast<int> (usage) << endl;
212     wvlog << "\tcbName = " << static_cast<unsigned int> (cbName) << endl;
213     wvlog << "\tunused2 = " << static_cast<unsigned int> (unused2) << endl;
214     wvlog << "\tunused3 = " << static_cast<unsigned int> (unused3) << endl;
215     wvlog << "Finished dumping FBSE." << endl;
216 }
217 
recordSize()218 int FBSE::recordSize()
219 {
220     //just add up the sizes of btWin32 + btMacOS + rgUid[16] + ...
221     return 36;
222 }
223 
getBlipType()224 int FBSE::getBlipType()
225 {
226     //cast enum to int
227     return static_cast<int> (btWin32);
228 }
229 
getStreamOffset()230 int FBSE::getStreamOffset()
231 {
232     //cast U32 to unsigned int
233     return static_cast<unsigned int> (foDelay);
234 }
235 
getNameLength()236 int FBSE::getNameLength()
237 {
238     //cast U8 to unsigned int
239     return static_cast<unsigned int> (cbName);
240 }
241 
getRgbUid()242 U8* FBSE::getRgbUid()
243 {
244     return rgbUid;
245 }
246 
Blip(OLEStreamReader * stream,string blipType)247 Blip::Blip( OLEStreamReader* stream, string blipType )
248 {
249     m_size = 0; //just an initial value
250     m_blipType = blipType;
251     m_isMetafileBlip = false;
252     if( blipType.compare("JPEG") == 0 || blipType.compare("PNG") == 0
253             || blipType.compare("DIB") == 0 )
254     {
255         stream->read( m_rgbUid, 16 ); //data UID
256         m_bTag = stream->readU8();
257         m_size = 17;
258         //initialize other variables just to 0
259         m_cb = 0;
260         m_rcBounds = 0;
261         m_ptSize = 0;
262         m_cbSave = 0;
263         m_fCompression = 255; //test value, so we'll just initialize to this
264         m_fFilter = 255; //test value, so we'll just initialize to this
265     }
266     else if( blipType.compare("EMF") == 0 || blipType.compare("WMF") == 0
267             || blipType.compare("PICT") == 0 )
268     {
269         stream->read( m_rgbUid, 16 ); //data UID
270         stream->read( m_rgbUidPrimary, 16 ); //primary Uid
271         m_cb = stream->readU32(); //cache of metafile size
272         m_rcBounds = stream->readU32(); //boundary of metafile drawing commands
273         m_ptSize = stream->readU32(); //size of metafile in EMU's
274         m_cbSave = stream->readU32(); //cache of saved size (size of m_pvBits)
275         m_fCompression = stream->readU8(); //compression
276         m_fFilter = stream->readU8(); //always msofilterNone = 254
277         m_isMetafileBlip = true;
278         m_size = 46;
279     }
280 }
281 
~Blip()282 Blip::~Blip()
283 {
284 }
285 
isMetafileBlip()286 bool Blip::isMetafileBlip()
287 {
288     return m_isMetafileBlip;
289 }
290 
isCompressed()291 bool Blip::isCompressed()
292 {
293     //only metafile blips can be compressed
294     //and the flag has to be set
295     if( isMetafileBlip() && m_fCompression == 0 )
296         return true;
297     else
298         return false;
299 }
300 
recordSize()301 int Blip::recordSize()
302 {
303     return m_size;
304 }
305 
imageSize()306 int Blip::imageSize()
307 {
308     return static_cast<unsigned int> (m_cb);
309 }
310 
compressedImageSize()311 int Blip::compressedImageSize()
312 {
313     return static_cast<unsigned int> (m_cbSave);
314 }
315 
dump()316 void Blip::dump()
317 {
318     if( !isCompressed() )
319     {
320         wvlog << " bitmap blip:" << endl;
321         wvlog << " m_rgbUid = " << m_rgbUid << endl;
322         wvlog << " m_bTag = " << static_cast<unsigned int> (m_bTag) << endl;
323     }
324     else
325     {
326         wvlog << " metafile blip:" << endl;
327         wvlog << " m_rgbUid = " << m_rgbUid << endl;
328         wvlog << " m_cb = " << m_cb << endl;
329         wvlog << " m_rcBounds = " << m_rcBounds << endl;
330         wvlog << " m_ptSize = " << m_ptSize << endl;
331         wvlog << " m_cbSave = " << m_cbSave << endl;
332         wvlog << " m_fCompression = " << static_cast<unsigned int> (m_fCompression) << endl;
333         wvlog << " m_fFilter = " << static_cast<unsigned int> (m_fFilter) << endl;
334     }
335 }
336 
337