filters

msod.h

00001 /*
00002     Copyright (C) 2000, S.R.Haque <shaheedhaque@hotmail.com>.
00003     This file is part of the KDE project
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 
00020 DESCRIPTION
00021 
00022     This is a generic parser for Microsoft Office Drawings (MSODs). The
00023     specification for this is the Microsoft Office 97 Drawing File Format
00024     published in MSDN. The output is a series of callbacks (a.k.a. virtual
00025     functions) which the caller can override as required.
00026 */
00027 
00028 #ifndef MSOD_H
00029 #define MSOD_H
00030 
00031 class QString;
00032 class QPointArray;
00033 #include <kwmf.h>
00034 #include <qptrvector.h>
00035 
00036 class Msod :
00037     private KWmf
00038 {
00039 public:
00040 
00041     // Construction.
00042 
00043     Msod(
00044         unsigned dpi);
00045     virtual ~Msod();
00046 
00047     // Called to parse the given file. We extract a drawing by shapeId.
00048     // If the drawing is not found, the return value will be false.
00049 
00050     bool parse(
00051         unsigned shapeId,
00052         const QString &file,
00053         const char *delayStream = 0L);
00054     bool parse(
00055         unsigned shapeId,
00056         QDataStream &stream,
00057         unsigned size,
00058         const char *delayStream = 0L);
00059 
00060     typedef KWmf::DrawContext DrawContext;
00061 
00062     // Should be protected...
00063 
00064     void brushSet(
00065         unsigned colour,
00066         unsigned style);
00067     void penSet(
00068         unsigned colour,
00069         unsigned style,
00070         unsigned width);
00071 
00072 protected:
00073     // Override to get results of parsing.
00074 
00075     virtual void gotEllipse(
00076         const DrawContext &dc,
00077         QString type,
00078         QPoint topLeft,
00079         QSize halfAxes,
00080         unsigned startAngle,
00081         unsigned stopAngle) = 0;
00082     virtual void gotPicture(
00083         unsigned id,
00084         QString extension,
00085         unsigned length,
00086         const char *data) = 0;
00087     virtual void gotPolygon(
00088         const DrawContext &dc,
00089         const QPointArray &points) = 0;
00090     virtual void gotPolyline(
00091         const DrawContext &dc,
00092         const QPointArray &points) = 0;
00093     virtual void gotRectangle(
00094         const DrawContext &dc,
00095         const QPointArray &points) = 0;
00096 
00097 private:
00098     Msod(const Msod &);
00099     const Msod &operator=(const Msod &);
00100 
00101     // Debug support.
00102 
00103     static const int s_area;
00104 
00105 private:
00106     int m_dpi;
00107     DrawContext m_dc;
00108     unsigned m_dggError;
00109     unsigned m_requestedShapeId;
00110     bool m_isRequiredDrawing;
00111     const char *m_delayStream;
00112     struct
00113     {
00114         unsigned type;
00115         char *data;
00116         unsigned length;
00117     } m_shape;
00118 
00119     QPoint normalisePoint(
00120         QDataStream &operands);
00121     QSize normaliseSize(
00122         QDataStream &operands);
00123     void drawShape(
00124         unsigned shapeType,
00125         Q_UINT32 bytes,
00126         QDataStream &operands);
00127 
00128 public:
00129 
00130     // Common Header (MSOBFH)
00131     typedef struct
00132     {
00133         union
00134         {
00135             Q_UINT32 info;
00136             struct
00137             {
00138                 Q_UINT32 ver: 4;
00139                 Q_UINT32 inst: 12;
00140                 Q_UINT32 fbt: 16;
00141             } fields;
00142         } opcode;
00143         Q_UINT32 cbLength;
00144     } Header;
00145 
00146 private:
00147     typedef enum
00148     {
00149         msoblipERROR,               // An error occurred during loading.
00150         msoblipUNKNOWN,             // An unknown blip type.
00151         msoblipEMF,                 // Windows Enhanced Metafile.
00152         msoblipWMF,                 // Windows Metafile.
00153         msoblipPICT,                // Macintosh PICT.
00154         msoblipJPEG,                // JFIF.
00155         msoblipPNG,                 // PNG.
00156         msoblipDIB,                 // Windows DIB.
00157         msoblipFirstClient = 32,    // First client defined blip type.
00158         msoblipLastClient  = 255    // Last client defined blip type.
00159     } MSOBLIPTYPE;
00160 
00161     MSOBLIPTYPE m_blipType;
00162     unsigned m_imageId;
00163     class Image
00164     {
00165     public:
00166         QString extension;
00167         unsigned length;
00168         const char *data;
00169         Image() { data = 0L; }
00170         ~Image() { delete [] data; }
00171     };
00172     QPtrVector<Image> m_images;
00173 
00174     // Opcode handling and painter methods.
00175 
00176     void walk(
00177         Q_UINT32 bytes,
00178         QDataStream &operands);
00179     void skip(
00180         Q_UINT32 bytes,
00181         QDataStream &operands);
00182     void invokeHandler(
00183         Header &op,
00184         Q_UINT32 bytes,
00185         QDataStream &operands);
00186 
00187     void opAlignrule(Header &op, Q_UINT32 bytes, QDataStream &operands);
00188     void opAnchor(Header &op, Q_UINT32 bytes, QDataStream &operands);
00189     void opArcrule(Header &op, Q_UINT32 bytes, QDataStream &operands);
00190     void opBlip(Header &op, Q_UINT32 bytes, QDataStream &operands);
00191     void opBse(Header &op, Q_UINT32 bytes, QDataStream &operands);
00192     void opBstorecontainer(Header &op, Q_UINT32 bytes, QDataStream &operands);
00193     void opCalloutrule(Header &op, Q_UINT32 bytes, QDataStream &operands);
00194     void opChildanchor(Header &op, Q_UINT32 bytes, QDataStream &operands);
00195     void opClientanchor(Header &op, Q_UINT32 bytes, QDataStream &operands);
00196     void opClientdata(Header &op, Q_UINT32 bytes, QDataStream &operands);
00197     void opClientrule(Header &op, Q_UINT32 bytes, QDataStream &operands);
00198     void opClienttextbox(Header &op, Q_UINT32 bytes, QDataStream &operands);
00199     void opClsid(Header &op, Q_UINT32 bytes, QDataStream &operands);
00200     void opColormru(Header &op, Q_UINT32 bytes, QDataStream &operands);
00201     void opConnectorrule(Header &op, Q_UINT32 bytes, QDataStream &operands);
00202     void opDeletedpspl(Header &op, Q_UINT32 bytes, QDataStream &operands);
00203     void opDg(Header &op, Q_UINT32 bytes, QDataStream &operands);
00204     void opDgcontainer(Header &op, Q_UINT32 bytes, QDataStream &operands);
00205     void opDgg(Header &op, Q_UINT32 bytes, QDataStream &operands);
00206     void opDggcontainer(Header &op, Q_UINT32 bytes, QDataStream &operands);
00207     void opOleobject(Header &op, Q_UINT32 bytes, QDataStream &operands);
00208     void opOpt(Header &op, Q_UINT32 bytes, QDataStream &operands);
00209     void opRegroupitems(Header &op, Q_UINT32 bytes, QDataStream &operands);
00210     void opSelection(Header &op, Q_UINT32 bytes, QDataStream &operands);
00211     void opSolvercontainer(Header &op, Q_UINT32 bytes, QDataStream &operands);
00212     void opSp(Header &op, Q_UINT32 bytes, QDataStream &operands);
00213     void opSpcontainer(Header &op, Q_UINT32 bytes, QDataStream &operands);
00214     void opSpgr(Header &op, Q_UINT32 bytes, QDataStream &operands);
00215     void opSpgrcontainer(Header &op, Q_UINT32 bytes, QDataStream &operands);
00216     void opSplitmenucolors(Header &op, Q_UINT32 bytes, QDataStream &operands);
00217     void opTextbox(Header &op, Q_UINT32 bytes, QDataStream &operands);
00218 
00219     // Option handling.
00220 
00221     class Options
00222     {
00223     public:
00224         Options(Msod &parent);
00225         ~Options();
00226         void walk(
00227             Q_UINT32 bytes,
00228             QDataStream &operands);
00229 
00230         double m_rotation;
00231 
00232         Q_UINT32 m_lTxid;
00233 
00234         Q_UINT32 m_pib;
00235         QString m_pibName;
00236         Q_UINT32 m_pibFlags;
00237         Q_UINT32 m_pictureId;
00238         bool m_fNoHitTestPicture;
00239         bool m_pictureGray;
00240         bool m_pictureBiLevel;
00241         bool m_pictureActive;
00242 
00243         Q_UINT32 m_geoLeft;
00244         Q_UINT32 m_geoTop;
00245         Q_UINT32 m_geoRight;
00246         Q_UINT32 m_geoBottom;
00247         Q_UINT32 m_shapePath;
00248         QPointArray *m_pVertices;
00249         bool m_fShadowOK;
00250         bool m_f3DOK;
00251         bool m_fLineOK;
00252         bool m_fGTextOK;
00253         bool m_fFillShadeShapeOK;
00254         bool m_fFillOK;
00255 
00256         bool m_fFilled;
00257         bool m_fHitTestFill;
00258         bool m_fillShape;
00259         bool m_fillUseRect;
00260         bool m_fNoFillHitTest;
00261 
00262         Q_UINT32 m_lineColor;
00263         Q_UINT32 m_lineBackColor;
00264         Q_UINT32 m_lineType;
00265         Q_UINT32 m_lineWidth;
00266 
00267         bool m_fArrowheadsOK;
00268         bool m_fLine;
00269         bool m_fHitTestLine;
00270         bool m_lineFillShape;
00271         bool m_fNoLineDrawDash;
00272 
00273         Q_UINT32 m_bWMode;
00274 
00275         bool m_fOleIcon;
00276         bool m_fPreferRelativeResize;
00277         bool m_fLockShapeType;
00278         bool m_fDeleteAttachedObject;
00279         bool m_fBackground;
00280 
00281     private:
00282         Msod &m_parent;
00283 
00284         typedef struct
00285         {
00286             union
00287             {
00288                 Q_UINT16 info;
00289                 struct
00290                 {
00291                     Q_UINT16 pid: 14;
00292                     Q_UINT16 fBid: 1;
00293                     Q_UINT16 fComplex: 1;
00294                 } fields;
00295             } opcode;
00296             Q_UINT32 value;
00297         } Header;
00298 
00299         void initialise();
00300         double from1616ToDouble(Q_UINT32 value);
00301     };
00302     friend class Msod::Options;
00303 
00304     Options *m_opt;
00305 };
00306 
00307 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys