summaryrefslogtreecommitdiffstats
path: root/lib/kwmf/kwmf.h
blob: e3afe5e548897d8175375e8a69bd0715b41822b6 (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
/*
    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
    aS32 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 Windows MetaFiles (WMFs). The output is
    a series of callbacks (a.k.a. virtual functions) which the caller can
    override as required.

    This is based on code originally written by Stefan Taferner
    (taferner@kde.org).
*/

#ifndef KWMF_H
#define KWMF_H

#include <tqvaluestack.h>
#include <koffice_export.h>
class TQDataStream;
class TQPointArray;

class KOWMF_EXPORT KWmf
{
public:

    // Construction.

    KWmf(
        unsigned dpi);
    virtual ~KWmf();

    // Called to parse the given file.

    bool parse(
        const TQString &file);
    bool parse(
        TQDataStream &stream,
        unsigned size);

    class KOWMF_EXPORT DrawContext
    {
    public:
        DrawContext();
        bool m_winding;
        unsigned m_brushColour;
        unsigned m_brushStyle;
        unsigned m_penColour;
        unsigned m_penStyle;
        unsigned m_penWidth;
    };

    // 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 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:
    // Debug support.

    static const int s_area;

    // Use unambiguous names for Microsoft types.

    typedef short S16;
    typedef int S32;
    typedef unsigned int U32;

    int m_dpi;
    int m_windowOrgX;
    int m_windowOrgY;
    int m_windowFlipX;
    int m_windowFlipY;
    DrawContext m_dc;
    TQValueStack<DrawContext> m_savedDcs;
    TQPoint m_lineFrom;

    // Windows handle management.

    class WinObjHandle
    {
    public:
        virtual ~WinObjHandle () {}
        virtual void apply(KWmf &p) = 0;
    };

    class WinObjBrushHandle: public WinObjHandle
    {
    public:
        virtual void apply(KWmf &p);
        unsigned m_colour;
        unsigned m_style;
    };

    class WinObjPenHandle: public WinObjHandle
    {
    public:
        virtual void apply(KWmf &p);
        unsigned m_colour;
        unsigned m_style;
        unsigned m_width;
    };

    int handleIndex(void) const;
    WinObjPenHandle *handleCreatePen(void);
    WinObjBrushHandle *handleCreateBrush(void);
    void handleDelete(int idx);
    static const int s_maxHandles;
    WinObjHandle **m_objectHandles;

    unsigned getColour(S32 colour);
    TQPoint normalisePoint(
        TQDataStream &operands);
    TQSize normaliseSize(
        TQDataStream &operands);
    void genericArc(
        TQString type,
        TQDataStream &operands);

    // Opcode handling and painter methods.

    void walk(
        U32 words,
        TQDataStream &stream);
    void skip(
        U32 words,
        TQDataStream &operands);
    void invokeHandler(
        S16 opcode,
        U32 words,
        TQDataStream &operands);
/*
    // draw multiple polygons
    void opPolypolygon(U32 words, TQDataStream &operands);
*/
    void opArc(U32 words, TQDataStream &operands);
    // create a logical brush
    void opBrushCreateIndirect(U32 words, TQDataStream &operands);
    void opEllipse(U32 words, TQDataStream &operands);
    // draw line to coord
    void opLineTo(U32 words, TQDataStream &operands);
    // move pen to coord
    void opMoveTo(U32 words, TQDataStream &operands);
    // do nothing
    void opNoop(U32 words, TQDataStream &operands);
    // Free object handle
    void opObjectDelete(U32 words, TQDataStream &operands);
    // Activate object handle
    void opObjectSelect(U32 words, TQDataStream &operands);
    // create a logical pen
    void opPenCreateIndirect(U32 words, TQDataStream &operands);
    void opPie(U32 words, TQDataStream &operands);
    // draw polygon
    void opPolygon(U32 words, TQDataStream &operands);
    // set polygon fill mode
    void opPolygonSetFillMode(U32 words, TQDataStream &operands);
    // draw series of lines
    void opPolyline(U32 words, TQDataStream &operands);
    void opRectangle(U32 words, TQDataStream &operands);
    // restore drawing context
    void opRestoreDc(U32 words, TQDataStream &operands);
    // save drawing context
    void opSaveDc(U32 words, TQDataStream &operands);
    // set window origin
    void opWindowSetOrg(U32 words, TQDataStream &operands);
    // set window extents
    void opWindowSetExt(U32 words, TQDataStream &operands);
/*
    // set background pen color
    void opsetBkColor(U32 words, TQDataStream &operands);
    // set background pen mode
    void opsetBkMode(U32 words, TQDataStream &operands);
    // Set raster operation mode
    void opsetRop(U32 words, TQDataStream &operands);
    // Escape (enhanced command set)
    void opescape(U32 words, TQDataStream &operands);
*/
};

#endif