lib Library API Documentation

kwmf.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     aS32 with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 
00020 DESCRIPTION
00021 
00022     This is a generic parser for Windows MetaFiles (WMFs). The output is
00023     a series of callbacks (a.k.a. virtual functions) which the caller can
00024     override as required.
00025 
00026     This is based on code originally written by Stefan Taferner
00027     (taferner@kde.org).
00028 */
00029 
00030 #ifndef KWMF_H
00031 #define KWMF_H
00032 
00033 #include <qvaluestack.h>
00034 
00035 class QDataStream;
00036 class QPointArray;
00037 
00038 class KWmf
00039 {
00040 public:
00041 
00042     // Construction.
00043 
00044     KWmf(
00045         unsigned dpi);
00046     virtual ~KWmf();
00047 
00048     // Called to parse the given file.
00049 
00050     bool parse(
00051         const QString &file);
00052     bool parse(
00053         QDataStream &stream,
00054         unsigned size);
00055 
00056     class DrawContext
00057     {
00058     public:
00059         DrawContext();
00060         bool m_winding;
00061         unsigned m_brushColour;
00062         unsigned m_brushStyle;
00063         unsigned m_penColour;
00064         unsigned m_penStyle;
00065         unsigned m_penWidth;
00066     };
00067 
00068     // Should be protected...
00069 
00070     void brushSet(
00071         unsigned colour,
00072         unsigned style);
00073     void penSet(
00074         unsigned colour,
00075         unsigned style,
00076         unsigned width);
00077 
00078 protected:
00079     // Override to get results of parsing.
00080 
00081     virtual void gotEllipse(
00082         const DrawContext &dc,
00083         QString type,
00084         QPoint topLeft,
00085         QSize halfAxes,
00086         unsigned startAngle,
00087         unsigned stopAngle) = 0;
00088     virtual void gotPolygon(
00089         const DrawContext &dc,
00090         const QPointArray &points) = 0;
00091     virtual void gotPolyline(
00092         const DrawContext &dc,
00093         const QPointArray &points) = 0;
00094     virtual void gotRectangle(
00095         const DrawContext &dc,
00096         const QPointArray &points) = 0;
00097 
00098 private:
00099     // Debug support.
00100 
00101     static const int s_area;
00102 
00103     // Use unambiguous names for Microsoft types.
00104 
00105     typedef short S16;
00106     typedef int S32;
00107     typedef unsigned int U32;
00108 
00109     int m_dpi;
00110     int m_windowOrgX;
00111     int m_windowOrgY;
00112     int m_windowFlipX;
00113     int m_windowFlipY;
00114     DrawContext m_dc;
00115     QValueStack<DrawContext> m_savedDcs;
00116     QPoint m_lineFrom;
00117 
00118     // Windows handle management.
00119 
00120     class WinObjHandle
00121     {
00122     public:
00123         virtual ~WinObjHandle () {}
00124         virtual void apply(KWmf &p) = 0;
00125     };
00126 
00127     class WinObjBrushHandle: public WinObjHandle
00128     {
00129     public:
00130         virtual void apply(KWmf &p);
00131         unsigned m_colour;
00132         unsigned m_style;
00133     };
00134 
00135     class WinObjPenHandle: public WinObjHandle
00136     {
00137     public:
00138         virtual void apply(KWmf &p);
00139         unsigned m_colour;
00140         unsigned m_style;
00141         unsigned m_width;
00142     };
00143 
00144     int handleIndex(void) const;
00145     WinObjPenHandle *handleCreatePen(void);
00146     WinObjBrushHandle *handleCreateBrush(void);
00147     void handleDelete(int idx);
00148     static const int s_maxHandles;
00149     WinObjHandle **m_objectHandles;
00150 
00151     unsigned getColour(S32 colour);
00152     QPoint normalisePoint(
00153         QDataStream &operands);
00154     QSize normaliseSize(
00155         QDataStream &operands);
00156     void genericArc(
00157         QString type,
00158         QDataStream &operands);
00159 
00160     // Opcode handling and painter methods.
00161 
00162     void walk(
00163         U32 words,
00164         QDataStream &stream);
00165     void skip(
00166         U32 words,
00167         QDataStream &operands);
00168     void invokeHandler(
00169         S16 opcode,
00170         U32 words,
00171         QDataStream &operands);
00172 /*
00173     // draw multiple polygons
00174     void opPolypolygon(U32 words, QDataStream &operands);
00175 */
00176     void opArc(U32 words, QDataStream &operands);
00177     // create a logical brush
00178     void opBrushCreateIndirect(U32 words, QDataStream &operands);
00179     void opEllipse(U32 words, QDataStream &operands);
00180     // draw line to coord
00181     void opLineTo(U32 words, QDataStream &operands);
00182     // move pen to coord
00183     void opMoveTo(U32 words, QDataStream &operands);
00184     // do nothing
00185     void opNoop(U32 words, QDataStream &operands);
00186     // Free object handle
00187     void opObjectDelete(U32 words, QDataStream &operands);
00188     // Activate object handle
00189     void opObjectSelect(U32 words, QDataStream &operands);
00190     // create a logical pen
00191     void opPenCreateIndirect(U32 words, QDataStream &operands);
00192     void opPie(U32 words, QDataStream &operands);
00193     // draw polygon
00194     void opPolygon(U32 words, QDataStream &operands);
00195     // set polygon fill mode
00196     void opPolygonSetFillMode(U32 words, QDataStream &operands);
00197     // draw series of lines
00198     void opPolyline(U32 words, QDataStream &operands);
00199     void opRectangle(U32 words, QDataStream &operands);
00200     // restore drawing context
00201     void opRestoreDc(U32 words, QDataStream &operands);
00202     // save drawing context
00203     void opSaveDc(U32 words, QDataStream &operands);
00204     // set window origin
00205     void opWindowSetOrg(U32 words, QDataStream &operands);
00206     // set window extents
00207     void opWindowSetExt(U32 words, QDataStream &operands);
00208 /*
00209     // set background pen color
00210     void opsetBkColor(U32 words, QDataStream &operands);
00211     // set background pen mode
00212     void opsetBkMode(U32 words, QDataStream &operands);
00213     // Set raster operation mode
00214     void opsetRop(U32 words, QDataStream &operands);
00215     // Escape (enhanced command set)
00216     void opescape(U32 words, QDataStream &operands);
00217 */
00218 };
00219 
00220 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Mar 20 14:25:28 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003