summaryrefslogtreecommitdiffstats
path: root/filters/karbon/msod/msod.h
blob: 3db6fc2f356b377cf4243e2d524fd8cc0be51756 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
    Copyright (C) 2000, S.R.Haque <shaheedhaque@hotmail.com>.
    This file is part of the KDE project

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.

DESCRIPTION

    This is a generic parser for Microsoft Office Drawings (MSODs). The
    specification for this is the Microsoft Office 97 Drawing File Format
    published in MSDN. The output is a series of callbacks (a.k.a. virtual
    functions) which the caller can override as required.
*/

#ifndef MSOD_H
#define MSOD_H

class TQString;
class TQPointArray;
#include <kwmf.h>
#include <tqptrvector.h>

class Msod :
    private KWmf
{
public:

    // Construction.

    Msod(
        unsigned dpi);
    virtual ~Msod();

    // Called to parse the given file. We extract a drawing by shapeId.
    // If the drawing is not found, the return value will be false.

    bool parse(
        unsigned shapeId,
        const TQString &file,
        const char *delayStream = 0L);
    bool parse(
        unsigned shapeId,
        TQDataStream &stream,
        unsigned size,
        const char *delayStream = 0L);

    typedef KWmf::DrawContext DrawContext;

    // Should be protected...

    void brushSet(
        unsigned colour,
        unsigned style);
    void penSet(
        unsigned colour,
        unsigned style,
        unsigned width);

protected:
    // Override to get results of parsing.

    virtual void gotEllipse(
        const DrawContext &dc,
        TQString type,
        TQPoint topLeft,
        TQSize halfAxes,
        unsigned startAngle,
        unsigned stopAngle) = 0;
    virtual void gotPicture(
        unsigned id,
        TQString extension,
        unsigned length,
        const char *data) = 0;
    virtual void gotPolygon(
        const DrawContext &dc,
        const TQPointArray &points) = 0;
    virtual void gotPolyline(
        const DrawContext &dc,
        const TQPointArray &points) = 0;
    virtual void gotRectangle(
        const DrawContext &dc,
        const TQPointArray &points) = 0;

private:
    Msod(const Msod &);
    const Msod &operator=(const Msod &);

    // Debug support.

    static const int s_area;

private:
    int m_dpi;
    DrawContext m_dc;
    unsigned m_dggError;
    unsigned m_requestedShapeId;
    bool m_isRequiredDrawing;
    const char *m_delayStream;
    struct
    {
        unsigned type;
        char *data;
        unsigned length;
    } m_shape;

    TQPoint normalisePoint(
        TQDataStream &operands);
    TQSize normaliseSize(
        TQDataStream &operands);
    void drawShape(
        unsigned shapeType,
        TQ_UINT32 bytes,
        TQDataStream &operands);

public:

    // Common Header (MSOBFH)
    typedef struct
    {
        union
        {
            TQ_UINT32 info;
            struct
            {
                TQ_UINT32 ver: 4;
                TQ_UINT32 inst: 12;
                TQ_UINT32 fbt: 16;
            } fields;
        } opcode;
        TQ_UINT32 cbLength;
    } Header;

private:
    typedef enum
    {
        msoblipERROR,               // An error occurred during loading.
        msoblipUNKNOWN,             // An unknown blip type.
        msoblipEMF,                 // Windows Enhanced Metafile.
        msoblipWMF,                 // Windows Metafile.
        msoblipPICT,                // Macintosh PICT.
        msoblipJPEG,                // JFIF.
        msoblipPNG,                 // PNG.
        msoblipDIB,                 // Windows DIB.
        msoblipFirstClient = 32,    // First client defined blip type.
        msoblipLastClient  = 255    // Last client defined blip type.
    } MSOBLIPTYPE;

    MSOBLIPTYPE m_blipType;
    unsigned m_imageId;
    class Image
    {
    public:
        TQString extension;
        unsigned length;
        const char *data;
        Image() { data = 0L; }
        ~Image() { delete [] data; }
    };
    TQPtrVector<Image> m_images;

    // Opcode handling and painter methods.

    void walk(
        TQ_UINT32 bytes,
        TQDataStream &operands);
    void skip(
        TQ_UINT32 bytes,
        TQDataStream &operands);
    void invokeHandler(
        Header &op,
        TQ_UINT32 bytes,
        TQDataStream &operands);

    void opAlignrule(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opAnchor(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opArcrule(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opBlip(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opBse(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opBstorecontainer(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opCalloutrule(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opChildanchor(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opClientanchor(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opClientdata(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opClientrule(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opClienttextbox(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opClsid(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opColormru(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opConnectorrule(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opDeletedpspl(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opDg(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opDgcontainer(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opDgg(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opDggcontainer(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opOleobject(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opOpt(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opRegroupitems(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opSelection(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opSolvercontainer(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opSp(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opSpcontainer(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opSpgr(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opSpgrcontainer(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opSplitmenucolors(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
    void opTextbox(Header &op, TQ_UINT32 bytes, TQDataStream &operands);

    // Option handling.

    class Options
    {
    public:
        Options(Msod &parent);
        ~Options();
        void walk(
            TQ_UINT32 bytes,
            TQDataStream &operands);

        double m_rotation;

        TQ_UINT32 m_lTxid;

        TQ_UINT32 m_pib;
        TQString m_pibName;
        TQ_UINT32 m_pibFlags;
        TQ_UINT32 m_pictureId;
        bool m_fNoHitTestPicture;
        bool m_pictureGray;
        bool m_pictureBiLevel;
        bool m_pictureActive;

        TQ_UINT32 m_geoLeft;
        TQ_UINT32 m_geoTop;
        TQ_UINT32 m_geoRight;
        TQ_UINT32 m_geoBottom;
        TQ_UINT32 m_shapePath;
        TQPointArray *m_pVertices;
        bool m_fShadowOK;
        bool m_f3DOK;
        bool m_fLineOK;
        bool m_fGTextOK;
        bool m_fFillShadeShapeOK;
        bool m_fFillOK;

        bool m_fFilled;
        bool m_fHitTestFill;
        bool m_fillShape;
        bool m_fillUseRect;
        bool m_fNoFillHitTest;

        TQ_UINT32 m_lineColor;
        TQ_UINT32 m_lineBackColor;
        TQ_UINT32 m_lineType;
        TQ_UINT32 m_lineWidth;

        bool m_fArrowheadsOK;
        bool m_fLine;
        bool m_fHitTestLine;
        bool m_lineFillShape;
        bool m_fNoLineDrawDash;

        TQ_UINT32 m_bWMode;

        bool m_fOleIcon;
        bool m_fPreferRelativeResize;
        bool m_fLockShapeType;
        bool m_fDeleteAttachedObject;
        bool m_fBackground;

    private:
        Msod &m_parent;

        typedef struct
        {
            union
            {
                TQ_UINT16 info;
                struct
                {
                    TQ_UINT16 pid: 14;
                    TQ_UINT16 fBid: 1;
                    TQ_UINT16 fComplex: 1;
                } fields;
            } opcode;
            TQ_UINT32 value;
        } Header;

        void initialise();
        double from1616ToDouble(TQ_UINT32 value);
    };
    friend class Msod::Options;

    Options *m_opt;
};

#endif