filters

msod.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 along 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 Microsoft Office Drawings (MSODs). The
23 specification for this is the Microsoft Office 97 Drawing File Format
24 published in MSDN. The output is a series of callbacks (a.k.a. virtual
25 functions) which the caller can override as required.
26*/
27
28#ifndef MSOD_H
29#define MSOD_H
30
31class TQString;
32class TQPointArray;
33#include <kwmf.h>
34#include <tqptrvector.h>
35
36class Msod :
37 private KWmf
38{
39public:
40
41 // Construction.
42
43 Msod(
44 unsigned dpi);
45 virtual ~Msod();
46
47 // Called to parse the given file. We extract a drawing by shapeId.
48 // If the drawing is not found, the return value will be false.
49
50 bool parse(
51 unsigned shapeId,
52 const TQString &file,
53 const char *delayStream = 0L);
54 bool parse(
55 unsigned shapeId,
56 TQDataStream &stream,
57 unsigned size,
58 const char *delayStream = 0L);
59
60 typedef KWmf::DrawContext DrawContext;
61
62 // Should be protected...
63
64 void brushSet(
65 unsigned colour,
66 unsigned style);
67 void penSet(
68 unsigned colour,
69 unsigned style,
70 unsigned width);
71
72protected:
73 // Override to get results of parsing.
74
75 virtual void gotEllipse(
76 const DrawContext &dc,
77 TQString type,
78 TQPoint topLeft,
79 TQSize halfAxes,
80 unsigned startAngle,
81 unsigned stopAngle) = 0;
82 virtual void gotPicture(
83 unsigned id,
84 TQString extension,
85 unsigned length,
86 const char *data) = 0;
87 virtual void gotPolygon(
88 const DrawContext &dc,
89 const TQPointArray &points) = 0;
90 virtual void gotPolyline(
91 const DrawContext &dc,
92 const TQPointArray &points) = 0;
93 virtual void gotRectangle(
94 const DrawContext &dc,
95 const TQPointArray &points) = 0;
96
97private:
98 Msod(const Msod &);
99 const Msod &operator=(const Msod &);
100
101 // Debug support.
102
103 static const int s_area;
104
105private:
106 int m_dpi;
107 DrawContext m_dc;
108 unsigned m_dggError;
109 unsigned m_requestedShapeId;
110 bool m_isRequiredDrawing;
111 const char *m_delayStream;
112 struct
113 {
114 unsigned type;
115 char *data;
116 unsigned length;
117 } m_shape;
118
119 TQPoint normalisePoint(
120 TQDataStream &operands);
121 TQSize normaliseSize(
122 TQDataStream &operands);
123 void drawShape(
124 unsigned shapeType,
125 TQ_UINT32 bytes,
126 TQDataStream &operands);
127
128public:
129
130 // Common Header (MSOBFH)
131 typedef struct
132 {
133 union
134 {
135 TQ_UINT32 info;
136 struct
137 {
138 TQ_UINT32 ver: 4;
139 TQ_UINT32 inst: 12;
140 TQ_UINT32 fbt: 16;
141 } fields;
142 } opcode;
143 TQ_UINT32 cbLength;
144 } Header;
145
146private:
147 typedef enum
148 {
149 msoblipERROR, // An error occurred during loading.
150 msoblipUNKNOWN, // An unknown blip type.
151 msoblipEMF, // Windows Enhanced Metafile.
152 msoblipWMF, // Windows Metafile.
153 msoblipPICT, // Macintosh PICT.
154 msoblipJPEG, // JFIF.
155 msoblipPNG, // PNG.
156 msoblipDIB, // Windows DIB.
157 msoblipFirstClient = 32, // First client defined blip type.
158 msoblipLastClient = 255 // Last client defined blip type.
159 } MSOBLIPTYPE;
160
161 MSOBLIPTYPE m_blipType;
162 unsigned m_imageId;
163 class Image
164 {
165 public:
166 TQString extension;
167 unsigned length;
168 const char *data;
169 Image() { data = 0L; }
170 ~Image() { delete [] data; }
171 };
172 TQPtrVector<Image> m_images;
173
174 // Opcode handling and painter methods.
175
176 void walk(
177 TQ_UINT32 bytes,
178 TQDataStream &operands);
179 void skip(
180 TQ_UINT32 bytes,
181 TQDataStream &operands);
182 void invokeHandler(
183 Header &op,
184 TQ_UINT32 bytes,
185 TQDataStream &operands);
186
187 void opAlignrule(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
188 void opAnchor(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
189 void opArcrule(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
190 void opBlip(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
191 void opBse(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
192 void opBstorecontainer(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
193 void opCalloutrule(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
194 void opChildanchor(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
195 void opClientanchor(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
196 void opClientdata(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
197 void opClientrule(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
198 void opClienttextbox(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
199 void opClsid(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
200 void opColormru(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
201 void opConnectorrule(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
202 void opDeletedpspl(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
203 void opDg(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
204 void opDgcontainer(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
205 void opDgg(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
206 void opDggcontainer(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
207 void opOleobject(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
208 void opOpt(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
209 void opRegroupitems(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
210 void opSelection(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
211 void opSolvercontainer(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
212 void opSp(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
213 void opSpcontainer(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
214 void opSpgr(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
215 void opSpgrcontainer(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
216 void opSplitmenucolors(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
217 void opTextbox(Header &op, TQ_UINT32 bytes, TQDataStream &operands);
218
219 // Option handling.
220
221 class Options
222 {
223 public:
224 Options(Msod &parent);
225 ~Options();
226 void walk(
227 TQ_UINT32 bytes,
228 TQDataStream &operands);
229
230 double m_rotation;
231
232 TQ_UINT32 m_lTxid;
233
234 TQ_UINT32 m_pib;
235 TQString m_pibName;
236 TQ_UINT32 m_pibFlags;
237 TQ_UINT32 m_pictureId;
238 bool m_fNoHitTestPicture;
239 bool m_pictureGray;
240 bool m_pictureBiLevel;
241 bool m_pictureActive;
242
243 TQ_UINT32 m_geoLeft;
244 TQ_UINT32 m_geoTop;
245 TQ_UINT32 m_geoRight;
246 TQ_UINT32 m_geoBottom;
247 TQ_UINT32 m_shapePath;
248 TQPointArray *m_pVertices;
249 bool m_fShadowOK;
250 bool m_f3DOK;
251 bool m_fLineOK;
252 bool m_fGTextOK;
253 bool m_fFillShadeShapeOK;
254 bool m_fFillOK;
255
256 bool m_fFilled;
257 bool m_fHitTestFill;
258 bool m_fillShape;
259 bool m_fillUseRect;
260 bool m_fNoFillHitTest;
261
262 TQ_UINT32 m_lineColor;
263 TQ_UINT32 m_lineBackColor;
264 TQ_UINT32 m_lineType;
265 TQ_UINT32 m_lineWidth;
266
267 bool m_fArrowheadsOK;
268 bool m_fLine;
269 bool m_fHitTestLine;
270 bool m_lineFillShape;
271 bool m_fNoLineDrawDash;
272
273 TQ_UINT32 m_bWMode;
274
275 bool m_fOleIcon;
276 bool m_fPreferRelativeResize;
277 bool m_fLockShapeType;
278 bool m_fDeleteAttachedObject;
279 bool m_fBackground;
280
281 private:
282 Msod &m_parent;
283
284 typedef struct
285 {
286 union
287 {
288 TQ_UINT16 info;
289 struct
290 {
291 TQ_UINT16 pid: 14;
292 TQ_UINT16 fBid: 1;
293 TQ_UINT16 fComplex: 1;
294 } fields;
295 } opcode;
296 TQ_UINT32 value;
297 } Header;
298
299 void initialise();
300 double from1616ToDouble(TQ_UINT32 value);
301 };
302 friend class Msod::Options;
303
304 Options *m_opt;
305};
306
307#endif