~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to filters/kontour/msod/msod.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Copyright (C) 2000, S.R.Haque <shaheedhaque@hotmail.com>.
3
 
    This file is part of the KDE project
4
 
 
5
 
    This library is free software; you can redistribute it and/or
6
 
    modify it under the terms of the GNU Library General Public
7
 
    License as published by the Free Software Foundation; either
8
 
    version 2 of the License, or (at your option) any later version.
9
 
 
10
 
    This library is distributed in the hope that it will be useful,
11
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
    Library General Public License for more details.
14
 
 
15
 
    You should have received a copy of the GNU Library General Public License
16
 
    along with this library; see the file COPYING.LIB.  If not, write to
17
 
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
 
    Boston, MA 02111-1307, USA.
19
 
 
20
 
DESCRIPTION
21
 
*/
22
 
 
23
 
#include <kdebug.h>
24
 
#include <qdatastream.h>
25
 
#include <qfile.h>
26
 
#include <qlist.h>
27
 
#include <qpointarray.h>
28
 
#include <qrect.h>
29
 
#include <qsize.h>
30
 
#include <msod.h>
31
 
#include <zlib.h>
32
 
 
33
 
Msod::Msod(
34
 
    unsigned dpi) :
35
 
        KWmf(dpi)
36
 
{
37
 
    m_dpi = dpi;
38
 
    m_images.setAutoDelete(true);
39
 
    m_opt = new Options(*this);
40
 
    m_shape.data = 0L;
41
 
    m_shape.length = 0;
42
 
}
43
 
 
44
 
Msod::~Msod()
45
 
{
46
 
    delete [] m_shape.data;
47
 
    delete m_opt;
48
 
}
49
 
 
50
 
void Msod::drawShape(
51
 
    unsigned shapeType,
52
 
    U32 bytes,
53
 
    QDataStream &operands)
54
 
{
55
 
    static const char *funcTab[] =
56
 
    {
57
 
        "UNKNOWN",                  // Unknown
58
 
        "RECTANGLE",                // Rectangle
59
 
        "ROUNDRECTANGLE",           // Roundrectangle
60
 
        "ELLIPSE",                  // Ellipse
61
 
        "DIAMOND",                  // Diamond
62
 
        "ISOCELESTRIANGLE",         // Isocelestriangle
63
 
        "RIGHTTRIANGLE",            // Righttriangle
64
 
        "PARALLELOGRAM",            // Parallelogram
65
 
        "TRAPEZOID",                // Trapezoid
66
 
        "HEXAGON",                  // Hexagon
67
 
        "OCTAGON",                  // Octagon
68
 
        "PLUS",                     // Plus
69
 
        "STAR",                     // Star
70
 
        "ARROW",                    // Arrow
71
 
        "THICKARROW",               // Thickarrow
72
 
        "HOMEPLATE",                // Homeplate
73
 
        "CUBE",                     // Cube
74
 
        "BALLOON",                  // Balloon
75
 
        "SEAL",                     // Seal
76
 
        "ARC",                      // Arc
77
 
        "LINE",                     // Line
78
 
        "PLAQUE",                   // Plaque
79
 
        "CAN",                      // Can
80
 
        "DONUT",                    // Donut
81
 
        "TEXTSIMPLE",               // Textsimple
82
 
        "TEXTOCTAGON",              // Textoctagon
83
 
        "TEXTHEXAGON",              // Texthexagon
84
 
        "TEXTCURVE",                // Textcurve
85
 
        "TEXTWAVE",                 // Textwave
86
 
        "TEXTRING",                 // Textring
87
 
        "TEXTONCURVE",              // Textoncurve
88
 
        "TEXTONRING",               // Textonring
89
 
        "STRAIGHTCONNECTOR1",       // Straightconnector1
90
 
        "BENTCONNECTOR2",           // Bentconnector2
91
 
        "BENTCONNECTOR3",           // Bentconnector3
92
 
        "BENTCONNECTOR4",           // Bentconnector4
93
 
        "BENTCONNECTOR5",           // Bentconnector5
94
 
        "CURVEDCONNECTOR2",         // Curvedconnector2
95
 
        "CURVEDCONNECTOR3",         // Curvedconnector3
96
 
        "CURVEDCONNECTOR4",         // Curvedconnector4
97
 
        "CURVEDCONNECTOR5",         // Curvedconnector5
98
 
        "CALLOUT1",                 // Callout1
99
 
        "CALLOUT2",                 // Callout2
100
 
        "CALLOUT3",                 // Callout3
101
 
        "ACCENTCALLOUT1",           // Accentcallout1
102
 
        "ACCENTCALLOUT2",           // Accentcallout2
103
 
        "ACCENTCALLOUT3",           // Accentcallout3
104
 
        "BORDERCALLOUT1",           // bordercallout1
105
 
        "BORDERCALLOUT2",           // Bordercallout2
106
 
        "BORDERCALLOUT3",           // Bordercallout3
107
 
        "ACCENTBORDERCALLOUT1",     // Accentbordercallout1
108
 
        "ACCENTBORDERCALLOUT2",     // Accentbordercallout2
109
 
        "ACCENTBORDERCALLOUT3",     // Accentbordercallout3
110
 
        "RIBBON",                   // Ribbon
111
 
        "RIBBON2",                  // Ribbon2
112
 
        "CHEVRON",                  // Chevron
113
 
        "PENTAGON",                 // Pentagon
114
 
        "NOSMOKING",                // Nosmoking
115
 
        "SEAL8",                    // Seal8
116
 
        "SEAL16",                   // Seal16
117
 
        "SEAL32",                   // Seal32
118
 
        "WEDGERECTCALLOUT",         // Wedgerectcallout
119
 
        "WEDGERRECTCALLOUT",        // Wedgerrectcallout
120
 
        "WEDGEELLIPSECALLOUT",      // Wedgeellipsecallout
121
 
        "WAVE",                     // Wave
122
 
        "FOLDEDCORNER",             // Foldedcorner
123
 
        "LEFTARROW",                // Leftarrow
124
 
        "DOWNARROW",                // Downarrow
125
 
        "UPARROW",                  // Uparrow
126
 
        "LEFTRIGHTARROW",           // Leftrightarrow
127
 
        "UPDOWNARROW",              // Updownarrow
128
 
        "IRREGULARSEAL1",           // Irregularseal1
129
 
        "IRREGULARSEAL2",           // Irregularseal2
130
 
        "LIGHTNINGBOLT",            // Lightningbolt
131
 
        "HEART",                    // Heart
132
 
        "PICTUREFRAME",             // PictureFrame
133
 
        "QUADARROW",                // Quadarrow
134
 
        "LEFTARROWCALLOUT",         // Leftarrowcallout
135
 
        "RIGHTARROWCALLOUT",        // Rightarrowcallout
136
 
        "UPARROWCALLOUT",           // Uparrowcallout
137
 
        "DOWNARROWCALLOUT",         // Downarrowcallout
138
 
        "LEFTRIGHTARROWCALLOUT",    // Leftrightarrowcallout
139
 
        "UPDOWNARROWCALLOUT",       // Updownarrowcallout
140
 
        "QUADARROWCALLOUT",         // Quadarrowcallout
141
 
        "BEVEL",                    // Bevel
142
 
        "LEFTBRACKET",              // Leftbracket
143
 
        "RIGHTBRACKET",             // Rightbracket
144
 
        "LEFTBRACE",                // Leftbrace
145
 
        "RIGHTBRACE",               // Rightbrace
146
 
        "LEFTUPARROW",              // Leftuparrow
147
 
        "BENTUPARROW",              // Bentuparrow
148
 
        "BENTARROW",                // Bentarrow
149
 
        "SEAL24",                   // Seal24
150
 
        "STRIPEDRIGHTARROW",        // Stripedrightarrow
151
 
        "NOTCHEDRIGHTARROW",        // Notchedrightarrow
152
 
        "BLOCKARC",                 // Blockarc
153
 
        "SMILEYFACE",               // Smileyface
154
 
        "VERTICALSCROLL",           // Verticalscroll
155
 
        "HORIZONTALSCROLL",         // Horizontalscroll
156
 
        "CIRCULARARROW",            // Circulararrow
157
 
        "NOTCHEDCIRCULARARROW",     // Notchedcirculararrow
158
 
        "UTURNARROW",               // Uturnarrow
159
 
        "CURVEDRIGHTARROW",         // Curvedrightarrow
160
 
        "CURVEDLEFTARROW",          // Curvedleftarrow
161
 
        "CURVEDUPARROW",            // Curveduparrow
162
 
        "CURVEDDOWNARROW",          // Curveddownarrow
163
 
        "CLOUDCALLOUT",             // Cloudcallout
164
 
        "ELLIPSERIBBON",            // Ellipseribbon
165
 
        "ELLIPSERIBBON2",           // Ellipseribbon2
166
 
        "FLOWCHARTPROCESS",         // Flowchartprocess
167
 
        "FLOWCHARTDECISION",        // Flowchartdecision
168
 
        "FLOWCHARTINPUTOUTPUT",     // Flowchartinputoutput
169
 
        "FLOWCHARTPREDEFINEDPROCESS",   // Flowchartpredefinedprocess
170
 
        "FLOWCHARTINTERNALSTORAGE",   // Flowchartinternalstorage
171
 
        "FLOWCHARTDOCUMENT",        // Flowchartdocument
172
 
        "FLOWCHARTMULTIDOCUMENT",   // Flowchartmultidocument
173
 
        "FLOWCHARTTERMINATOR",      // Flowchartterminator
174
 
        "FLOWCHARTPREPARATION",     // Flowchartpreparation
175
 
        "FLOWCHARTMANUALINPUT",     // Flowchartmanualinput
176
 
        "FLOWCHARTMANUALOPERATION",   // Flowchartmanualoperation
177
 
        "FLOWCHARTCONNECTOR",       // Flowchartconnector
178
 
        "FLOWCHARTPUNCHEDCARD",     // Flowchartpunchedcard
179
 
        "FLOWCHARTPUNCHEDTAPE",     // Flowchartpunchedtape
180
 
        "FLOWCHARTSUMMINGJUNCTION",   // Flowchartsummingjunction
181
 
        "FLOWCHARTOR",              // Flowchartor
182
 
        "FLOWCHARTCOLLATE",         // Flowchartcollate
183
 
        "FLOWCHARTSORT",            // Flowchartsort
184
 
        "FLOWCHARTEXTRACT",         // Flowchartextract
185
 
        "FLOWCHARTMERGE",           // Flowchartmerge
186
 
        "FLOWCHARTOFFLINESTORAGE",   // Flowchartofflinestorage
187
 
        "FLOWCHARTONLINESTORAGE",   // Flowchartonlinestorage
188
 
        "FLOWCHARTMAGNETICTAPE",    // Flowchartmagnetictape
189
 
        "FLOWCHARTMAGNETICDISK",    // Flowchartmagneticdisk
190
 
        "FLOWCHARTMAGNETICDRUM",    // Flowchartmagneticdrum
191
 
        "FLOWCHARTDISPLAY",         // Flowchartdisplay
192
 
        "FLOWCHARTDELAY",           // Flowchartdelay
193
 
        "TEXTPLAINTEXT",            // Textplaintext
194
 
        "TEXTSTOP",                 // Textstop
195
 
        "TEXTTRIANGLE",             // Texttriangle
196
 
        "TEXTTRIANGLEINVERTED",     // Texttriangleinverted
197
 
        "TEXTCHEVRON",              // Textchevron
198
 
        "TEXTCHEVRONINVERTED",      // Textchevroninverted
199
 
        "TEXTRINGINSIDE",           // Textringinside
200
 
        "TEXTRINGOUTSIDE",          // Textringoutside
201
 
        "TEXTARCHUPCURVE",          // Textarchupcurve
202
 
        "TEXTARCHDOWNCURVE",        // Textarchdowncurve
203
 
        "TEXTCIRCLECURVE",          // Textcirclecurve
204
 
        "TEXTBUTTONCURVE",          // Textbuttoncurve
205
 
        "TEXTARCHUPPOUR",           // Textarchuppour
206
 
        "TEXTARCHDOWNPOUR",         // Textarchdownpour
207
 
        "TEXTCIRCLEPOUR",           // Textcirclepour
208
 
        "TEXTBUTTONPOUR",           // Textbuttonpour
209
 
        "TEXTCURVEUP",              // Textcurveup
210
 
        "TEXTCURVEDOWN",            // Textcurvedown
211
 
        "TEXTCASCADEUP",            // Textcascadeup
212
 
        "TEXTCASCADEDOWN",          // Textcascadedown
213
 
        "TEXTWAVE1",                // Textwave1
214
 
        "TEXTWAVE2",                // Textwave2
215
 
        "TEXTWAVE3",                // Textwave3
216
 
        "TEXTWAVE4",                // Textwave4
217
 
        "TEXTINFLATE",              // Textinflate
218
 
        "TEXTDEFLATE",              // Textdeflate
219
 
        "TEXTINFLATEBOTTOM",        // Textinflatebottom
220
 
        "TEXTDEFLATEBOTTOM",        // Textdeflatebottom
221
 
        "TEXTINFLATETOP",           // Textinflatetop
222
 
        "TEXTDEFLATETOP",           // Textdeflatetop
223
 
        "TEXTDEFLATEINFLATE",       // Textdeflateinflate
224
 
        "TEXTDEFLATEINFLATEDEFLATE",   // Textdeflateinflatedeflate
225
 
        "TEXTFADERIGHT",            // Textfaderight
226
 
        "TEXTFADELEFT",             // Textfadeleft
227
 
        "TEXTFADEUP",               // Textfadeup
228
 
        "TEXTFADEDOWN",             // Textfadedown
229
 
        "TEXTSLANTUP",              // Textslantup
230
 
        "TEXTSLANTDOWN",            // Textslantdown
231
 
        "TEXTCANUP",                // Textcanup
232
 
        "TEXTCANDOWN",              // Textcandown
233
 
        "FLOWCHARTALTERNATEPROCESS",   // Flowchartalternateprocess
234
 
        "FLOWCHARTOFFPAGECONNECTOR",   // Flowchartoffpageconnector
235
 
        "CALLOUT90",                // Callout90
236
 
        "ACCENTCALLOUT90",          // Accentcallout90
237
 
        "BORDERCALLOUT90",          // Bordercallout90
238
 
        "ACCENTBORDERCALLOUT90",    // Accentbordercallout90
239
 
        "LEFTRIGHTUPARROW",         // Leftrightuparrow
240
 
        "SUN",                      // Sun
241
 
        "MOON",                     // Moon
242
 
        "BRACKETPAIR",              // Bracketpair
243
 
        "BRACEPAIR",                // Bracepair
244
 
        "SEAL4",                    // Seal4
245
 
        "DOUBLEWAVE",               // Doublewave
246
 
        "ACTIONBUTTONBLANK",        // Actionbuttonblank
247
 
        "ACTIONBUTTONHOME",         // Actionbuttonhome
248
 
        "ACTIONBUTTONHELP",         // Actionbuttonhelp
249
 
        "ACTIONBUTTONINFORMATION",  // Actionbuttoninformation
250
 
        "ACTIONBUTTONFORWARDNEXT",  // Actionbuttonforwardnext
251
 
        "ACTIONBUTTONBACKPREVIOUS", // Actionbuttonbackprevious
252
 
        "ACTIONBUTTONEND",          // Actionbuttonend
253
 
        "ACTIONBUTTONBEGINNING",    // Actionbuttonbeginning
254
 
        "ACTIONBUTTONRETURN",       // Actionbuttonreturn
255
 
        "ACTIONBUTTONDOCUMENT",     // Actionbuttondocument
256
 
        "ACTIONBUTTONSOUND",        // Actionbuttonsound
257
 
        "ACTIONBUTTONMOVIE",        // Actionbuttonmovie
258
 
        "HOSTCONTROL",              // Hostcontrol
259
 
        "TEXTBOX",                  // Textbox
260
 
    };
261
 
    struct
262
 
    {
263
 
        U32 spid;                       // The shape id
264
 
        union
265
 
        {
266
 
            U32 info;
267
 
            struct
268
 
            {
269
 
                U32 fGroup : 1;         // This shape is a group shape
270
 
                U32 fChild : 1;         // Not a top-level shape
271
 
                U32 fPatriarch : 1;     // This is the topmost group shape.
272
 
                                        // Exactly one of these per drawing.
273
 
                U32 fDeleted : 1;       // The shape has been deleted
274
 
                U32 fOleShape : 1;      // The shape is an OLE object
275
 
                U32 fHaveMaster : 1;    // Shape has a hspMaster property
276
 
                U32 fFlipH : 1;         // Shape is flipped horizontally
277
 
                U32 fFlipV : 1;         // Shape is flipped vertically
278
 
                U32 fConnector : 1;     // Connector type of shape
279
 
                U32 fHaveAnchor : 1;    // Shape has an anchor of some kind
280
 
                U32 fBackground : 1;    // Background shape
281
 
                U32 fHaveSpt : 1;       // Shape has a shape type property
282
 
                U32 reserved : 20;      // Not yet used
283
 
            } fields;
284
 
        } grfPersistent;
285
 
    } data;
286
 
 
287
 
    // Scan lookup table for operation.
288
 
 
289
 
    operands >> data.spid >> data.grfPersistent.info;
290
 
    bytes -= sizeof(data);
291
 
        kdDebug(s_area) << "shape-id: " << data.spid << " type: " << funcTab[shapeType] << " (" << shapeType << ")" <<
292
 
        (data.grfPersistent.fields.fGroup ? " group" : "") <<
293
 
        (data.grfPersistent.fields.fChild ? " child" : "") <<
294
 
        (data.grfPersistent.fields.fPatriarch ? " patriarch" : "") <<
295
 
        (data.grfPersistent.fields.fDeleted ? " deleted" : "") <<
296
 
        (data.grfPersistent.fields.fOleShape ? " oleshape" : "") <<
297
 
        (data.grfPersistent.fields.fHaveMaster ? " master" : "") <<
298
 
        (data.grfPersistent.fields.fFlipH ? " flipv" : "") <<
299
 
        (data.grfPersistent.fields.fConnector ? " connector" : "") <<
300
 
        (data.grfPersistent.fields.fHaveAnchor ? " anchor" : "") <<
301
 
        (data.grfPersistent.fields.fBackground ? " background" : "") <<
302
 
        (data.grfPersistent.fields.fHaveSpt ? " spt" : "") <<
303
 
        " operands: " << bytes << endl;
304
 
    if (data.grfPersistent.fields.fDeleted)
305
 
        return;
306
 
    if ((!m_isRequiredDrawing) && (m_requestedShapeId != data.spid))
307
 
        return;
308
 
 
309
 
    // An active shape! Let's draw it...
310
 
 
311
 
    switch (shapeType)
312
 
    {
313
 
    case 0:
314
 
        if (m_opt->m_pVertices)
315
 
        {
316
 
            gotPolyline(m_dc, *m_opt->m_pVertices);
317
 
        }
318
 
        break;
319
 
    case 1:
320
 
        if (bytes > 7)
321
 
        {
322
 
            QPoint topLeft;
323
 
            QSize size;
324
 
 
325
 
            topLeft = normalisePoint(operands);
326
 
            size = normaliseSize(operands);
327
 
 
328
 
            QRect rect(topLeft, size);
329
 
            QPointArray points(4);
330
 
 
331
 
            points.setPoint(0, topLeft);
332
 
            points.setPoint(1, rect.topRight());
333
 
            points.setPoint(2, rect.bottomRight());
334
 
            points.setPoint(3, rect.bottomLeft());
335
 
            gotRectangle(m_dc, points);
336
 
        }
337
 
    case 20:
338
 
        if (bytes > 7)
339
 
        {
340
 
            QPoint lineFrom;
341
 
            QPoint lineTo;
342
 
 
343
 
            lineTo = normalisePoint(operands);
344
 
 
345
 
            QPointArray points(2);
346
 
 
347
 
            points.setPoint(0, lineFrom);
348
 
            points.setPoint(1, lineTo);
349
 
            gotPolyline(m_dc, points);
350
 
        }
351
 
        break;
352
 
    default:
353
 
        break;
354
 
    }
355
 
}
356
 
 
357
 
void Msod::invokeHandler(
358
 
    Header &op,
359
 
    U32 bytes,
360
 
    QDataStream &operands)
361
 
{
362
 
    typedef void (Msod::*method)(Header &op, U32 bytes, QDataStream &operands);
363
 
 
364
 
    typedef struct
365
 
    {
366
 
        const char *name;
367
 
        unsigned short opcode;
368
 
        method handler;
369
 
    } opcodeEntry;
370
 
 
371
 
    static const opcodeEntry funcTab[] =
372
 
    {
373
 
        { "ALIGNRULE",          0xF013, &Msod::opAlignrule },
374
 
        { "ANCHOR",             0xF00E, &Msod::opAnchor },
375
 
        { "ARCRULE",            0xF014, &Msod::opArcrule },
376
 
        { "BSE",                0xF007, &Msod::opBse },
377
 
        { "BSTORECONTAINER",    0xF001, &Msod::opBstorecontainer },
378
 
        { "CALLOUTRULE",        0xF017, &Msod::opCalloutrule },
379
 
        { "CHILDANCHOR",        0xF00F, &Msod::opChildanchor },
380
 
        { "CLIENTANCHOR",       0xF010, &Msod::opClientanchor },
381
 
        { "CLIENTDATA",         0xF011, &Msod::opClientdata },
382
 
        { "CLIENTRULE",         0xF015, &Msod::opClientrule },
383
 
        { "CLIENTTEXTBOX",      0xF00D, &Msod::opClienttextbox },
384
 
        { "CLSID",              0xF016, &Msod::opClsid },
385
 
        { "COLORMRU",           0xF11A, &Msod::opColormru },
386
 
        { "CONNECTORRULE",      0xF012, &Msod::opConnectorrule },
387
 
        { "DELETEDPSPL",        0xF11D, &Msod::opDeletedpspl },
388
 
        { "DG",                 0xF008, &Msod::opDg },
389
 
        { "DGCONTAINER",        0xF002, &Msod::opDgcontainer },
390
 
        { "DGG",                0xF006, &Msod::opDgg },
391
 
        { "DGGCONTAINER",       0xF000, &Msod::opDggcontainer },
392
 
        { "OLEOBJECT",          0xF11F, &Msod::opOleobject },
393
 
        { "OPT",                0xF00B, &Msod::opOpt },
394
 
        { "REGROUPITEMS",       0xF118, &Msod::opRegroupitems },
395
 
        { "SELECTION",          0xF119, &Msod::opSelection },
396
 
        { "SOLVERCONTAINER",    0xF005, &Msod::opSolvercontainer },
397
 
        { "SP",                 0xF00A, &Msod::opSp },
398
 
        { "SPCONTAINER",        0xF004, &Msod::opSpcontainer },
399
 
        { "SPGR",               0xF009, &Msod::opSpgr },
400
 
        { "SPGRCONTAINER",      0xF003, &Msod::opSpgrcontainer },
401
 
        { "SPLITMENUCOLORS",    0xF11E, &Msod::opSplitmenucolors },
402
 
        { "TEXTBOX",            0xF00C, &Msod::opTextbox },
403
 
        { NULL,                 0,      0 },
404
 
        { "BLIP",               0,      &Msod::opBlip }
405
 
    };
406
 
    unsigned i;
407
 
    method result;
408
 
 
409
 
    // Scan lookup table for operation.
410
 
 
411
 
    for (i = 0; funcTab[i].name; i++)
412
 
    {
413
 
        if (funcTab[i].opcode == op.opcode.fields.fbt)
414
 
        {
415
 
            break;
416
 
        }
417
 
    }
418
 
 
419
 
    // Invoke handler.
420
 
 
421
 
    result = funcTab[i].handler;
422
 
    if (!result && (op.opcode.fields.fbt >= 0xF018) && (0xF117 >= op.opcode.fields.fbt))
423
 
        result = funcTab[++i].handler;
424
 
    if (!result)
425
 
    {
426
 
        if (funcTab[i].name)
427
 
            kdWarning(s_area) << "invokeHandler: unsupported opcode: " <<
428
 
                funcTab[i].name <<
429
 
                " operands: " << bytes << endl;
430
 
        else
431
 
            kdWarning(s_area) << "invokeHandler: unsupported opcode: 0x" <<
432
 
                QString::number(op.opcode.fields.fbt, 16) <<
433
 
                " operands: " << bytes << endl;
434
 
 
435
 
        // Skip data we cannot use.
436
 
 
437
 
        skip(bytes, operands);
438
 
    }
439
 
    else
440
 
    {
441
 
        kdDebug(s_area) << "invokeHandler: opcode: " << funcTab[i].name <<
442
 
            " operands: " << bytes << endl;
443
 
        (this->*result)(op, bytes, operands);
444
 
    }
445
 
}
446
 
 
447
 
QPoint Msod::normalisePoint(
448
 
    QDataStream &operands)
449
 
{
450
 
    U16 x;
451
 
    U16 y;
452
 
 
453
 
    operands >> x >> y;
454
 
    return QPoint(x / m_dpi, y / m_dpi);
455
 
}
456
 
 
457
 
QSize Msod::normaliseSize(
458
 
    QDataStream &operands)
459
 
{
460
 
    U16 width;
461
 
    U16 height;
462
 
 
463
 
    operands >> width >> height;
464
 
    return QSize(width / m_dpi, height / m_dpi);
465
 
}
466
 
 
467
 
bool Msod::parse(
468
 
    unsigned shapeId,
469
 
    const QString &file,
470
 
    const char *delayStream)
471
 
{
472
 
    QFile in(file);
473
 
    if (!in.open(IO_ReadOnly))
474
 
    {
475
 
        kdError(s_area) << "Unable to open input file!" << endl;
476
 
        in.close();
477
 
        return false;
478
 
    }
479
 
    QDataStream stream(&in);
480
 
    bool result = parse(shapeId, stream, in.size(), delayStream);
481
 
    in.close();
482
 
    return result;
483
 
}
484
 
 
485
 
bool Msod::parse(
486
 
    unsigned shapeId,
487
 
    QDataStream &stream,
488
 
    unsigned size,
489
 
    const char *delayStream)
490
 
{
491
 
    stream.setByteOrder(QDataStream::LittleEndian); // Great, I love Qt !
492
 
    m_requestedShapeId = shapeId;
493
 
    m_isRequiredDrawing = false;
494
 
    m_delayStream = delayStream;
495
 
 
496
 
    // Read bits.
497
 
 
498
 
    if (size & 1)
499
 
    {
500
 
        m_dggError = 1;
501
 
    }
502
 
    else
503
 
    {
504
 
        m_dggError = 0;
505
 
    }
506
 
    walk(size - m_dggError, stream);
507
 
    return true;
508
 
}
509
 
 
510
 
void Msod::opAlignrule(
511
 
    Header &,
512
 
    U32 bytes,
513
 
    QDataStream &operands)
514
 
{
515
 
    skip(bytes, operands);
516
 
}
517
 
 
518
 
void Msod::opAnchor(
519
 
    Header &,
520
 
    U32 bytes,
521
 
    QDataStream &operands)
522
 
{
523
 
    skip(bytes, operands);
524
 
}
525
 
 
526
 
void Msod::opArcrule(
527
 
    Header &,
528
 
    U32 bytes,
529
 
    QDataStream &operands)
530
 
{
531
 
    skip(bytes, operands);
532
 
}
533
 
 
534
 
void Msod::opBlip(Header &, U32 bytes, QDataStream &operands)
535
 
{
536
 
    typedef enum
537
 
    {
538
 
        msobiWMF = 0x216,       // Metafile header then compressed WMF.
539
 
        msobiEMF = 0x3D4,       // Metafile header then compressed EMF.
540
 
        msobiPICT = 0x542,      // Metafile header then compressed PICT.
541
 
        msobiPNG = 0x6E0,       // One byte tag then PNG data.
542
 
        msobiJPEG = 0x46A,      // One byte tag then JFIF data.
543
 
        msobiDIB = 0x7A8,       // One byte tag then DIB data.
544
 
        msobiClient = 0x800     // Clients should set this bit.
545
 
    } MSOBI;
546
 
    typedef enum
547
 
    {
548
 
        msocompressionDeflate,
549
 
        msocompressionNone = 254,
550
 
        msocompressionTest
551
 
    } MSOBLIPCOMPRESSION;
552
 
 
553
 
    bool hasPrimaryId;
554
 
    U32 length = 0;
555
 
    struct
556
 
    {
557
 
        U32 cb;
558
 
        struct
559
 
        {
560
 
            U32 x;
561
 
            U32 y;
562
 
            U32 w;
563
 
            U32 h;
564
 
        } bounds;
565
 
        struct
566
 
        {
567
 
            U32 w;
568
 
            U32 h;
569
 
        } ptSize;
570
 
        U32 cbSave;
571
 
        U8 compression;
572
 
        U8 filter;
573
 
    } data;
574
 
 
575
 
    // Skip any explicit primary header (m_rgbUidprimary).
576
 
 
577
 
    switch (m_blipType)
578
 
    {
579
 
    case msoblipEMF:
580
 
        hasPrimaryId = (m_blipType ^ msobiEMF) != 0;
581
 
        break;
582
 
    case msoblipWMF:
583
 
        hasPrimaryId = (m_blipType ^ msobiWMF) != 0;
584
 
        break;
585
 
    case msoblipPICT:
586
 
        hasPrimaryId = (m_blipType ^ msobiPICT) != 0;
587
 
        break;
588
 
    case msoblipJPEG:
589
 
        hasPrimaryId = (m_blipType ^ msobiJPEG) != 0;
590
 
        break;
591
 
    case msoblipPNG:
592
 
        hasPrimaryId = (m_blipType ^ msobiPNG) != 0;
593
 
        break;
594
 
    case msoblipDIB:
595
 
        hasPrimaryId = (m_blipType ^ msobiDIB) != 0;
596
 
        break;
597
 
    default:
598
 
        hasPrimaryId = (m_blipType ^ msobiClient) != 0;
599
 
        break;
600
 
    }
601
 
    if (hasPrimaryId)
602
 
    {
603
 
        length += 16;
604
 
        skip(16, operands);
605
 
    }
606
 
 
607
 
    // Process the rest of the header.
608
 
 
609
 
    data.compression = msocompressionNone;
610
 
    switch (m_blipType)
611
 
    {
612
 
    case msoblipEMF:
613
 
    case msoblipWMF:
614
 
    case msoblipPICT:
615
 
        length += 34;
616
 
        operands >> data.cb;
617
 
        operands >> data.bounds.x >> data.bounds.y >> data.bounds.w >> data.bounds.h;
618
 
        operands >> data.ptSize.w >> data.ptSize.h;
619
 
        operands >> data.cbSave;
620
 
        operands >> data.compression >> data.filter;
621
 
        break;
622
 
    case msoblipJPEG:
623
 
    case msoblipPNG:
624
 
    case msoblipDIB:
625
 
        // Skip the "tag".
626
 
        length += 1;
627
 
        skip(1, operands);
628
 
        break;
629
 
    default:
630
 
        break;
631
 
    }
632
 
 
633
 
    // Work out the file type.
634
 
 
635
 
    Image *image = new Image();
636
 
    switch (m_blipType)
637
 
    {
638
 
    case msoblipEMF:
639
 
        image->extension = "emf";
640
 
        break;
641
 
    case msoblipWMF:
642
 
        image->extension = "wmf";
643
 
        break;
644
 
    case msoblipPICT:
645
 
        image->extension = "pic";
646
 
        break;
647
 
    case msoblipJPEG:
648
 
        image->extension = "jpg";
649
 
        break;
650
 
    case msoblipPNG:
651
 
        image->extension = "png";
652
 
        break;
653
 
    case msoblipDIB:
654
 
        image->extension = "dib";
655
 
        break;
656
 
    default:
657
 
        image->extension = "img";
658
 
        break;
659
 
    }
660
 
    image->length = bytes - length;
661
 
    image->data = new char[image->length];
662
 
    operands.readRawBytes((char *)image->data, image->length);
663
 
    if (data.compression == msocompressionDeflate)
664
 
    {
665
 
        const char *tmp;
666
 
        uLongf destLen = data.cb;
667
 
        int result;
668
 
 
669
 
        tmp = new char[data.cb];
670
 
        result = uncompress((U8 *)tmp, &destLen, (U8 *)image->data, image->length);
671
 
        if (result != Z_OK)
672
 
        {
673
 
            kdError(s_area) << "opBlip: uncompress failed: " << result << endl;
674
 
        }
675
 
        if (destLen != data.cb)
676
 
        {
677
 
            kdError(s_area) << "opBlip: uncompressed " << destLen << " instead of " << data.cb << endl;
678
 
        }
679
 
        delete [] image->data;
680
 
        image->data = tmp;
681
 
        image->length = destLen;
682
 
    }
683
 
    m_images.resize(m_images.size() + 1);
684
 
    m_images.insert(m_images.size() - 1, image);
685
 
}
686
 
 
687
 
// FBSE - File Blip Store Entry
688
 
 
689
 
void Msod::opBse(Header &op, U32 bytes, QDataStream &operands)
690
 
{
691
 
    struct
692
 
    {
693
 
        U8 btWin32;     // Required type on Win32.
694
 
        U8 btMacOS;     // Required type on Mac.
695
 
        U8 rgbUid[16];  // Identifier of blip.
696
 
        U16 tag;        // currently unused.
697
 
        U32 size;       // Blip size in stream.
698
 
        U32 cRef;       // Reference count on the blip.
699
 
        U32 foDelay;    // File offset in the delay stream.
700
 
        U8 usage;       // How this blip is used (MSOBLIPUSAGE).
701
 
        U8 cbName;      // length of the blip name.
702
 
        U8 unused2;     // for the future.
703
 
        U8 unused3;     // for the future.
704
 
    } data;
705
 
    unsigned i;
706
 
 
707
 
    // Work out the type of the BLIP.
708
 
 
709
 
    m_blipType = static_cast<MSOBLIPTYPE>(op.opcode.fields.inst);
710
 
    operands >> data.btWin32 >> data.btMacOS;
711
 
    for (i = 0; i < sizeof(data.rgbUid); i++)
712
 
        operands >> data.rgbUid[i];
713
 
    operands >> data.tag >> data.size;
714
 
    operands >> data.cRef >> data.foDelay;
715
 
    operands >> data.usage >> data.cbName;
716
 
    operands >> data.unused2 >> data.unused2;
717
 
 
718
 
    // If the Blip is not in this drawing file, process it "manually".
719
 
 
720
 
    if (m_delayStream)
721
 
    {
722
 
        // The m_pib refers to images by number, which includes images
723
 
        // that are no longer here. Thus, we fake these out so that any
724
 
        // references to non-deleted images are still valid (!!!).
725
 
 
726
 
        if (data.size && data.cRef)
727
 
        {
728
 
            QByteArray bytes;
729
 
            bytes.setRawData(m_delayStream + data.foDelay, data.size);
730
 
            QDataStream stream(bytes, IO_ReadOnly);
731
 
            stream.setByteOrder(QDataStream::LittleEndian);
732
 
            walk(data.size, stream);
733
 
            bytes.resetRawData(m_delayStream + data.foDelay, data.size);
734
 
        }
735
 
        else
736
 
        {
737
 
            m_images.resize(m_images.size() + 1);
738
 
            m_images.insert(m_images.size() - 1, 0L);
739
 
        }
740
 
    }
741
 
    skip(bytes - sizeof(data), operands);
742
 
}
743
 
 
744
 
void Msod::opBstorecontainer(Header &, U32 bytes, QDataStream &operands)
745
 
{
746
 
    walk(bytes, operands);
747
 
}
748
 
 
749
 
void Msod::opCalloutrule(
750
 
    Header &,
751
 
    U32 bytes,
752
 
    QDataStream &operands)
753
 
{
754
 
    skip(bytes, operands);
755
 
}
756
 
 
757
 
void Msod::opChildanchor(
758
 
    Header &,
759
 
    U32 bytes,
760
 
    QDataStream &operands)
761
 
{
762
 
    skip(bytes, operands);
763
 
}
764
 
 
765
 
void Msod::opClientanchor(Header &, U32 bytes, QDataStream &operands)
766
 
{
767
 
    struct
768
 
    {
769
 
        U32 unknown;
770
 
    } data;
771
 
 
772
 
    operands >> data.unknown;
773
 
    kdDebug(s_area) << "client anchor: " << data.unknown << endl;
774
 
    skip(bytes - sizeof(data), operands);
775
 
}
776
 
 
777
 
void Msod::opClientdata(Header &, U32 bytes, QDataStream &operands)
778
 
{
779
 
    struct
780
 
    {
781
 
        U32 unknown;
782
 
    } data;
783
 
 
784
 
    operands >> data.unknown;
785
 
    kdDebug(s_area) << "client data: " << data.unknown << endl;
786
 
    skip(bytes - sizeof(data), operands);
787
 
}
788
 
 
789
 
void Msod::opClientrule(
790
 
    Header &,
791
 
    U32 bytes,
792
 
    QDataStream &operands)
793
 
{
794
 
    skip(bytes, operands);
795
 
}
796
 
 
797
 
void Msod::opClienttextbox(
798
 
    Header &,
799
 
    U32 bytes,
800
 
    QDataStream &operands)
801
 
{
802
 
    struct
803
 
    {
804
 
        U32 unknown;
805
 
    } data;
806
 
 
807
 
    operands >> data.unknown;
808
 
    kdDebug(s_area) << "client textbox: 0x" << QString::number(data.unknown,16) << endl;
809
 
    skip(bytes - sizeof(data), operands);
810
 
}
811
 
 
812
 
void Msod::opClsid(
813
 
    Header &,
814
 
    U32 bytes,
815
 
    QDataStream &operands)
816
 
{
817
 
    skip(bytes, operands);
818
 
}
819
 
 
820
 
void Msod::opColormru(
821
 
    Header &,
822
 
    U32 bytes,
823
 
    QDataStream &operands)
824
 
{
825
 
    skip(bytes, operands);
826
 
}
827
 
 
828
 
void Msod::opConnectorrule(
829
 
    Header &,
830
 
    U32 bytes,
831
 
    QDataStream &operands)
832
 
{
833
 
    skip(bytes, operands);
834
 
}
835
 
 
836
 
void Msod::opDeletedpspl(
837
 
    Header &,
838
 
    U32 bytes,
839
 
    QDataStream &operands)
840
 
{
841
 
    skip(bytes, operands);
842
 
}
843
 
 
844
 
// FDG - File DG
845
 
 
846
 
void Msod::opDg(Header &, U32 bytes, QDataStream &operands)
847
 
{
848
 
    struct
849
 
    {
850
 
        U32 csp;        // The number of shapes in this drawing.
851
 
        U32 spidCur;    // The last shape ID given to an SP in this DG.
852
 
    } data;
853
 
 
854
 
    operands >> data.csp >> data.spidCur;
855
 
    kdDebug(s_area) << "drawing id: " << data.spidCur << endl;
856
 
    m_isRequiredDrawing = (m_requestedShapeId == data.spidCur);
857
 
    if (m_isRequiredDrawing)
858
 
    {
859
 
        kdDebug(s_area) << "found requested drawing" << endl;
860
 
    }
861
 
    skip(bytes - sizeof(data), operands);
862
 
}
863
 
 
864
 
void Msod::opDgcontainer(Header &, U32 bytes, QDataStream &operands)
865
 
{
866
 
    walk(bytes, operands);
867
 
}
868
 
 
869
 
// FDGG - File DGG
870
 
 
871
 
void Msod::opDgg(Header &, U32 bytes, QDataStream &operands)
872
 
{
873
 
    struct
874
 
    {
875
 
        U32 spidMax;    // The current maximum shape ID.
876
 
        U32 cidcl;      // The number of ID clusters (FIDCLs).
877
 
        U32 cspSaved;   // The total number of shapes saved.
878
 
                        // (including deleted shapes, if undo
879
 
                        // information was saved).
880
 
        U32 cdgSaved;   // The total number of drawings saved.
881
 
    } data;
882
 
 
883
 
    // File ID Cluster - used to save IDCLs
884
 
 
885
 
    struct
886
 
    {
887
 
        U32 dgid;       // DG owning the SPIDs in this cluster
888
 
        U32 cspidCur;   // number of SPIDs used so far
889
 
    } data1;
890
 
    unsigned i;
891
 
 
892
 
    operands >> data.spidMax >> data.cidcl >> data.cspSaved >> data.cdgSaved;
893
 
    kdDebug(s_area) << data.cspSaved << " shapes in " <<
894
 
        data.cidcl - 1 << " clusters in " <<
895
 
        data.cdgSaved << " drawings" << endl;
896
 
    for (i = 0; i < data.cidcl - 1; i++)
897
 
    {
898
 
        operands >> data1.dgid >> data1.cspidCur;
899
 
    }
900
 
    skip(bytes - sizeof(data) - (data.cidcl - 1) * sizeof(data1), operands);
901
 
}
902
 
 
903
 
void Msod::opDggcontainer(Header &, U32 bytes, QDataStream &operands)
904
 
{
905
 
    walk(bytes, operands);
906
 
}
907
 
 
908
 
void Msod::opOleobject(
909
 
    Header &,
910
 
    U32 bytes,
911
 
    QDataStream &operands)
912
 
{
913
 
    skip(bytes, operands);
914
 
}
915
 
 
916
 
void Msod::opOpt(Header &, U32 bytes, QDataStream &operands)
917
 
{
918
 
    m_opt->walk(bytes, operands);
919
 
}
920
 
 
921
 
void Msod::opRegroupitems(
922
 
    Header &,
923
 
    U32 bytes,
924
 
    QDataStream &operands)
925
 
{
926
 
    skip(bytes, operands);
927
 
}
928
 
 
929
 
void Msod::opSelection(
930
 
    Header &,
931
 
    U32 bytes,
932
 
    QDataStream &operands)
933
 
{
934
 
    skip(bytes, operands);
935
 
}
936
 
 
937
 
void Msod::opSolvercontainer(Header &, U32 bytes, QDataStream &operands)
938
 
{
939
 
    walk(bytes, operands);
940
 
}
941
 
 
942
 
void Msod::opSp(Header &op, U32 bytes, QDataStream &operands)
943
 
{
944
 
    // We want to defer the act of drawing a shape until we have seen any options
945
 
    // that may affect it. Thus, we merely store the data away, and let opSpContainer
946
 
    // do all the ahrd work.
947
 
 
948
 
    m_shape.type = op.opcode.fields.inst;
949
 
    m_shape.length = bytes;
950
 
    m_shape.data = new char [bytes];
951
 
    operands.readRawBytes(m_shape.data, bytes);
952
 
}
953
 
 
954
 
void Msod::opSpcontainer(Header &, U32 bytes, QDataStream &operands)
955
 
{
956
 
    walk(bytes, operands);
957
 
 
958
 
    // Having gathered all the information for this shape, we can now draw it.
959
 
 
960
 
    QByteArray  a;
961
 
 
962
 
    a.setRawData(m_shape.data, m_shape.length);
963
 
    QDataStream s(a, IO_ReadOnly);
964
 
    s.setByteOrder(QDataStream::LittleEndian); // Great, I love Qt !
965
 
    drawShape(m_shape.type, m_shape.length, s);
966
 
    a.resetRawData(m_shape.data, m_shape.length);
967
 
    delete [] m_shape.data;
968
 
    m_shape.data = 0L;
969
 
}
970
 
 
971
 
void Msod::opSpgr(Header &, U32 bytes, QDataStream &operands)
972
 
{
973
 
    struct
974
 
    {
975
 
        U32 x;
976
 
        U32 y;
977
 
        U32 w;
978
 
        U32 h;
979
 
    } data;
980
 
 
981
 
    operands >> data.x >> data.y >> data.w >> data.h;
982
 
    skip(bytes - sizeof(data), operands);
983
 
}
984
 
 
985
 
void Msod::opSpgrcontainer(Header &, U32 bytes, QDataStream &operands)
986
 
{
987
 
    walk(bytes, operands);
988
 
}
989
 
 
990
 
void Msod::opSplitmenucolors(Header &, U32 bytes, QDataStream &operands)
991
 
{
992
 
    struct
993
 
    {
994
 
        U32 fill;
995
 
        U32 line;
996
 
        U32 shadow;
997
 
        U32 threeDee;
998
 
    } data;
999
 
 
1000
 
    operands >> data.fill >> data.line >> data.shadow >> data.threeDee;
1001
 
    skip(bytes - sizeof(data), operands);
1002
 
    skip(m_dggError, operands);
1003
 
}
1004
 
 
1005
 
void Msod::opTextbox(
1006
 
    Header &,
1007
 
    U32 bytes,
1008
 
    QDataStream &operands)
1009
 
{
1010
 
    skip(bytes, operands);
1011
 
}
1012
 
 
1013
 
void Msod::skip(U32 bytes, QDataStream &operands)
1014
 
{
1015
 
    if ((int)bytes < 0)
1016
 
    {
1017
 
        kdError(s_area) << "skip: " << (int)bytes << endl;
1018
 
        return;
1019
 
    }
1020
 
    if (bytes)
1021
 
    {
1022
 
        U32 i;
1023
 
        U8 discard;
1024
 
 
1025
 
        kdDebug(s_area) << "skip: " << bytes << endl;
1026
 
        for (i = 0; i < bytes; i++)
1027
 
        {
1028
 
            operands >> discard;
1029
 
        }
1030
 
    }
1031
 
}
1032
 
 
1033
 
void Msod::walk(U32 bytes, QDataStream &operands)
1034
 
{
1035
 
    Header op;
1036
 
    U32 length = 0;
1037
 
 
1038
 
    while (length < bytes)
1039
 
    {
1040
 
        operands >> op.opcode.info >> op.cbLength;
1041
 
        if (op.opcode.fields.fbt == 0)
1042
 
            break;
1043
 
 
1044
 
        // Package the arguments...
1045
 
 
1046
 
        invokeHandler(op, op.cbLength, operands);
1047
 
        length += op.cbLength + 8;
1048
 
    }
1049
 
}
1050
 
 
1051
 
Msod::Options::Options(
1052
 
    Msod &parent) :
1053
 
        m_parent(parent)
1054
 
{
1055
 
    m_pVertices = 0L;
1056
 
    initialise();
1057
 
}
1058
 
 
1059
 
Msod::Options::~Options()
1060
 
{
1061
 
    delete m_pVertices;
1062
 
}
1063
 
 
1064
 
double Msod::Options::from1616ToDouble(U32 value)
1065
 
{
1066
 
    return (value >> 16) + 65535.0 / (double)(value & 0xffff);
1067
 
}
1068
 
 
1069
 
void Msod::Options::initialise()
1070
 
{
1071
 
    m_rotation = 0.0;
1072
 
 
1073
 
    m_lTxid = 0;
1074
 
 
1075
 
    m_pib = 0;
1076
 
    m_pibName = QString::null;
1077
 
    m_pibFlags = 0;
1078
 
    m_pictureId = 0;
1079
 
    m_fNoHitTestPicture = false;
1080
 
    m_pictureGray = false;
1081
 
    m_pictureBiLevel = false;
1082
 
    m_pictureActive = false;
1083
 
 
1084
 
    m_geoLeft = 0;
1085
 
    m_geoTop = 0;
1086
 
    m_geoRight = 21600;
1087
 
    m_geoBottom = 21600;
1088
 
    m_shapePath = 1;
1089
 
    delete m_pVertices;
1090
 
    m_pVertices = 0L;
1091
 
    m_fShadowOK = true;
1092
 
    m_f3DOK = true;
1093
 
    m_fLineOK = true;
1094
 
    m_fGTextOK = false;
1095
 
    m_fFillShadeShapeOK = false;
1096
 
    m_fFillOK = true;
1097
 
 
1098
 
    m_fFilled = true;
1099
 
    m_fHitTestFill = true;
1100
 
    m_fillShape = true;
1101
 
    m_fillUseRect = false;
1102
 
    m_fNoFillHitTest = false;
1103
 
 
1104
 
    m_lineColor = 0;
1105
 
    m_lineBackColor = 0xffffff;
1106
 
    m_lineType = 0;
1107
 
    m_lineWidth = 9525;
1108
 
 
1109
 
    m_fArrowheadsOK = false;
1110
 
    m_fLine = true;
1111
 
    m_fHitTestLine = true;
1112
 
    m_lineFillShape = true;
1113
 
    m_fNoLineDrawDash = false;
1114
 
 
1115
 
    m_bWMode = 1;
1116
 
 
1117
 
    m_fOleIcon = false;
1118
 
    m_fPreferRelativeResize = false;
1119
 
    m_fLockShapeType = false;
1120
 
    m_fDeleteAttachedObject = false;
1121
 
    m_fBackground = false;
1122
 
}
1123
 
 
1124
 
void Msod::Options::walk(U32 bytes, QDataStream &operands)
1125
 
{
1126
 
    Header op;
1127
 
    U16 length = 0;
1128
 
    U16 complexLength = 0;
1129
 
 
1130
 
    // Reset all options to default values.
1131
 
 
1132
 
    initialise();
1133
 
 
1134
 
    // First process all simple options, and add all complex options to a list.
1135
 
 
1136
 
    QList<Header> complexOpts;
1137
 
    complexOpts.setAutoDelete(true);
1138
 
    bool unsupported;
1139
 
    while (length + complexLength < (int)bytes)
1140
 
    {
1141
 
        operands >> op.opcode.info >> op.value;
1142
 
        length += 6;
1143
 
 
1144
 
        // Defer processing of complex options.
1145
 
 
1146
 
        if (op.opcode.fields.fComplex)
1147
 
        {
1148
 
            complexLength += op.value;
1149
 
            complexOpts.append(new Header(op));
1150
 
            continue;
1151
 
        }
1152
 
 
1153
 
        // Now squirrel away the option value.
1154
 
 
1155
 
        unsupported = false;
1156
 
        switch (op.opcode.fields.pid)
1157
 
        {
1158
 
        case 4:
1159
 
            m_rotation = from1616ToDouble(op.value);
1160
 
            break;
1161
 
        case 128:
1162
 
            m_lTxid = op.value;
1163
 
    kdDebug(s_area) << "textbox: 0x" << QString::number(op.value,16) << endl;
1164
 
            break;
1165
 
        case 260:
1166
 
            if (op.opcode.fields.fBid)
1167
 
            {
1168
 
                m_pib = op.value;
1169
 
                if (m_parent.m_isRequiredDrawing)
1170
 
                {
1171
 
                    Image *image = m_parent.m_images[m_pib - 1];
1172
 
 
1173
 
                    // If it is an embedded WMF we don't bother with the
1174
 
                    // part; we just extract it as more vector graphics.
1175
 
 
1176
 
                    if (image->extension == "wmf")
1177
 
                    {
1178
 
                        QByteArray  a;
1179
 
                        a.setRawData(image->data, image->length);
1180
 
                        QDataStream s(a, IO_ReadOnly);
1181
 
                        m_parent.KWmf::parse(s, image->length);
1182
 
                        a.resetRawData(image->data, image->length);
1183
 
                    }
1184
 
                    else
1185
 
                    {
1186
 
                        m_parent.gotPicture(
1187
 
                            m_pib,
1188
 
                            image->extension,
1189
 
                            image->length,
1190
 
                            image->data);
1191
 
                    }
1192
 
                }
1193
 
            }
1194
 
            else
1195
 
            {
1196
 
                kdError(s_area) << "Cannot handle IMsoBlip" << endl;
1197
 
            }
1198
 
            break;
1199
 
        case 262:
1200
 
            m_pibFlags = op.value;
1201
 
            break;
1202
 
        case 267:
1203
 
            m_pictureId = op.value;
1204
 
            break;
1205
 
        case 319:
1206
 
            m_fNoHitTestPicture = (op.value & 0x0008) != 0;
1207
 
            m_pictureGray = (op.value & 0x0004) != 0;
1208
 
            m_pictureBiLevel = (op.value & 0x0002) != 0;
1209
 
            m_pictureActive = (op.value & 0x0001) != 0;
1210
 
            break;
1211
 
        case 320:
1212
 
            m_geoLeft = op.value;
1213
 
            break;
1214
 
        case 321:
1215
 
            m_geoTop = op.value;
1216
 
            break;
1217
 
        case 322:
1218
 
            m_geoRight = op.value;
1219
 
            break;
1220
 
        case 323:
1221
 
            m_geoBottom = op.value;
1222
 
            break;
1223
 
        case 324:
1224
 
            m_shapePath = op.value;
1225
 
            break;
1226
 
        case 383:
1227
 
            m_fShadowOK = (op.value & 0x0020) != 0;
1228
 
            m_f3DOK = (op.value & 0x0010) != 0;
1229
 
            m_fLineOK = (op.value & 0x0008) != 0;
1230
 
            m_fGTextOK = (op.value & 0x0004) != 0;
1231
 
            m_fFillShadeShapeOK = (op.value & 0x0002) != 0;
1232
 
            m_fFillOK = (op.value & 0x0001) != 0;
1233
 
            break;
1234
 
        case 447:
1235
 
            m_fFilled = (op.value & 0x0010) != 0;
1236
 
            m_fHitTestFill = (op.value & 0x0008) != 0;
1237
 
            m_fillShape = (op.value & 0x0004) != 0;
1238
 
            m_fillUseRect = (op.value & 0x0002) != 0;
1239
 
            m_fNoFillHitTest = (op.value & 0x0001) != 0;
1240
 
            break;
1241
 
        case 448:
1242
 
            m_lineColor = op.value;
1243
 
            break;
1244
 
        case 450:
1245
 
            m_lineBackColor = op.value;
1246
 
            break;
1247
 
        case 452:
1248
 
            m_lineType = op.value;
1249
 
            break;
1250
 
        case 459:
1251
 
            m_lineWidth = op.value;
1252
 
            break;
1253
 
        case 511:
1254
 
            m_fArrowheadsOK = (op.value & 0x0010) != 0;
1255
 
            m_fLine = (op.value & 0x0008) != 0;
1256
 
            m_fHitTestLine = (op.value & 0x0004) != 0;
1257
 
            m_lineFillShape = (op.value & 0x0002) != 0;
1258
 
            m_fNoLineDrawDash = (op.value & 0x0001) != 0;
1259
 
            break;
1260
 
        case 772:
1261
 
            m_bWMode = op.value;
1262
 
            break;
1263
 
        case 831:
1264
 
            m_fOleIcon = (op.value & 0x0010) != 0;
1265
 
            m_fPreferRelativeResize = (op.value & 0x0008) != 0;
1266
 
            m_fLockShapeType = (op.value & 0x0004) != 0;
1267
 
            m_fDeleteAttachedObject = (op.value & 0x0002) != 0;
1268
 
            m_fBackground = (op.value & 0x0001) != 0;
1269
 
            break;
1270
 
        default:
1271
 
            unsupported = true;
1272
 
            kdWarning(s_area) << "unsupported simple option: " <<
1273
 
                op.opcode.fields.pid << endl;
1274
 
            break;
1275
 
        }
1276
 
        if (!unsupported)
1277
 
            kdDebug(s_area) << "simple option: " <<
1278
 
                op.opcode.fields.pid << endl;
1279
 
    }
1280
 
 
1281
 
    // Now empty the list of complex options.
1282
 
 
1283
 
    while (complexOpts.count())
1284
 
    {
1285
 
        Q_INT16 t16;
1286
 
        unsigned i;
1287
 
 
1288
 
        op = *complexOpts.getFirst();
1289
 
        complexOpts.removeFirst();
1290
 
        unsupported = false;
1291
 
        switch (op.opcode.fields.pid)
1292
 
        {
1293
 
        case 261:
1294
 
            while (true)
1295
 
            {
1296
 
                operands >> t16;
1297
 
                if (!t16)
1298
 
                    break;
1299
 
                m_pibName += QChar(t16);
1300
 
            };
1301
 
            break;
1302
 
        case 325:
1303
 
            m_pVertices = new QPointArray(op.value / 4);
1304
 
            for (i = 0; i < m_pVertices->count(); i++)
1305
 
            {
1306
 
                m_pVertices->setPoint(i, m_parent.normalisePoint(operands));
1307
 
            };
1308
 
            break;
1309
 
        case 326:
1310
 
            operands >> t16;
1311
 
            i = t16;
1312
 
            operands >> t16;
1313
 
            operands >> t16;
1314
 
            m_parent.skip(i * t16, operands);
1315
 
            break;
1316
 
        default:
1317
 
            unsupported = true;
1318
 
            kdWarning(s_area) << "unsupported complex option: " <<
1319
 
                op.opcode.fields.pid << " operands: " << op.value << endl;
1320
 
            m_parent.skip(op.value, operands);
1321
 
            break;
1322
 
        }
1323
 
        if (!unsupported)
1324
 
            kdDebug(s_area) << "complex option: " <<
1325
 
                op.opcode.fields.pid << " operands: " << op.value  << endl;
1326
 
        complexLength -= op.value;
1327
 
    }
1328
 
}