lib

kwmf.h
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 aS32 with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19
20DESCRIPTION
21
22 This is a generic parser for Windows MetaFiles (WMFs). The output is
23 a series of callbacks (a.k.a. virtual functions) which the caller can
24 override as required.
25
26 This is based on code originally written by Stefan Taferner
27 (taferner@kde.org).
28*/
29
30#ifndef KWMF_H
31#define KWMF_H
32
33#include <tqvaluestack.h>
34#include <koffice_export.h>
35class TQDataStream;
36class TQPointArray;
37
38class KOWMF_EXPORT KWmf
39{
40public:
41
42 // Construction.
43
44 KWmf(
45 unsigned dpi);
46 virtual ~KWmf();
47
48 // Called to parse the given file.
49
50 bool parse(
51 const TQString &file);
52 bool parse(
53 TQDataStream &stream,
54 unsigned size);
55
56 class KOWMF_EXPORT DrawContext
57 {
58 public:
59 DrawContext();
60 bool m_winding;
61 unsigned m_brushColour;
62 unsigned m_brushStyle;
63 unsigned m_penColour;
64 unsigned m_penStyle;
65 unsigned m_penWidth;
66 };
67
68 // Should be protected...
69
70 void brushSet(
71 unsigned colour,
72 unsigned style);
73 void penSet(
74 unsigned colour,
75 unsigned style,
76 unsigned width);
77
78protected:
79 // Override to get results of parsing.
80
81 virtual void gotEllipse(
82 const DrawContext &dc,
83 TQString type,
84 TQPoint topLeft,
85 TQSize halfAxes,
86 unsigned startAngle,
87 unsigned stopAngle) = 0;
88 virtual void gotPolygon(
89 const DrawContext &dc,
90 const TQPointArray &points) = 0;
91 virtual void gotPolyline(
92 const DrawContext &dc,
93 const TQPointArray &points) = 0;
94 virtual void gotRectangle(
95 const DrawContext &dc,
96 const TQPointArray &points) = 0;
97
98private:
99 // Debug support.
100
101 static const int s_area;
102
103 // Use unambiguous names for Microsoft types.
104
105 typedef short S16;
106 typedef int S32;
107 typedef unsigned int U32;
108
109 int m_dpi;
110 int m_windowOrgX;
111 int m_windowOrgY;
112 int m_windowFlipX;
113 int m_windowFlipY;
114 DrawContext m_dc;
115 TQValueStack<DrawContext> m_savedDcs;
116 TQPoint m_lineFrom;
117
118 // Windows handle management.
119
120 class WinObjHandle
121 {
122 public:
123 virtual ~WinObjHandle () {}
124 virtual void apply(KWmf &p) = 0;
125 };
126
127 class WinObjBrushHandle: public WinObjHandle
128 {
129 public:
130 virtual void apply(KWmf &p);
131 unsigned m_colour;
132 unsigned m_style;
133 };
134
135 class WinObjPenHandle: public WinObjHandle
136 {
137 public:
138 virtual void apply(KWmf &p);
139 unsigned m_colour;
140 unsigned m_style;
141 unsigned m_width;
142 };
143
144 int handleIndex(void) const;
145 WinObjPenHandle *handleCreatePen(void);
146 WinObjBrushHandle *handleCreateBrush(void);
147 void handleDelete(int idx);
148 static const int s_maxHandles;
149 WinObjHandle **m_objectHandles;
150
151 unsigned getColour(S32 colour);
152 TQPoint normalisePoint(
153 TQDataStream &operands);
154 TQSize normaliseSize(
155 TQDataStream &operands);
156 void genericArc(
157 TQString type,
158 TQDataStream &operands);
159
160 // Opcode handling and painter methods.
161
162 void walk(
163 U32 words,
164 TQDataStream &stream);
165 void skip(
166 U32 words,
167 TQDataStream &operands);
168 void invokeHandler(
169 S16 opcode,
170 U32 words,
171 TQDataStream &operands);
172/*
173 // draw multiple polygons
174 void opPolypolygon(U32 words, TQDataStream &operands);
175*/
176 void opArc(U32 words, TQDataStream &operands);
177 // create a logical brush
178 void opBrushCreateIndirect(U32 words, TQDataStream &operands);
179 void opEllipse(U32 words, TQDataStream &operands);
180 // draw line to coord
181 void opLineTo(U32 words, TQDataStream &operands);
182 // move pen to coord
183 void opMoveTo(U32 words, TQDataStream &operands);
184 // do nothing
185 void opNoop(U32 words, TQDataStream &operands);
186 // Free object handle
187 void opObjectDelete(U32 words, TQDataStream &operands);
188 // Activate object handle
189 void opObjectSelect(U32 words, TQDataStream &operands);
190 // create a logical pen
191 void opPenCreateIndirect(U32 words, TQDataStream &operands);
192 void opPie(U32 words, TQDataStream &operands);
193 // draw polygon
194 void opPolygon(U32 words, TQDataStream &operands);
195 // set polygon fill mode
196 void opPolygonSetFillMode(U32 words, TQDataStream &operands);
197 // draw series of lines
198 void opPolyline(U32 words, TQDataStream &operands);
199 void opRectangle(U32 words, TQDataStream &operands);
200 // restore drawing context
201 void opRestoreDc(U32 words, TQDataStream &operands);
202 // save drawing context
203 void opSaveDc(U32 words, TQDataStream &operands);
204 // set window origin
205 void opWindowSetOrg(U32 words, TQDataStream &operands);
206 // set window extents
207 void opWindowSetExt(U32 words, TQDataStream &operands);
208/*
209 // set background pen color
210 void opsetBkColor(U32 words, TQDataStream &operands);
211 // set background pen mode
212 void opsetBkMode(U32 words, TQDataStream &operands);
213 // Set raster operation mode
214 void opsetRop(U32 words, TQDataStream &operands);
215 // Escape (enhanced command set)
216 void opescape(U32 words, TQDataStream &operands);
217*/
218};
219
220#endif