summaryrefslogtreecommitdiffstats
path: root/filters/karbon/wmf/wmfimportparser.h
blob: 490eb13c8ccdc5c47e0977814e3f3e225e596038 (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
/* This file is part of the KDE project
 * Copyright (c) 2003 thierry lorthiois (lorthioist@wanadoo.fr)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License version 2 as published by the Free Software Foundation.
 *
 * 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
 * along 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.
*/
#ifndef _WMFIMPORTPARSER_H_
#define _WMFIMPORTPARSER_H_

#include <tqpainter.h>
#include <tqdom.h>
#include <core/vdocument.h>
#include <core/vcomposite.h>
#include <kowmfread.h>


/**
 * WMFImportParser inherit KoWmfRead
 * and translate WMF functions
 *
 */
 
class WMFImportParser : public KoWmfRead
{
public:
    WMFImportParser();
    ~WMFImportParser() { }

    /**
     * play WMF file on a VDocument. Return true on success.
     */
    bool play( VDocument& doc );


private:
    // -------------------------------------------------------------------------
    // A virtual TQPainter 
    bool  begin();
    bool  end();
    void  save();
    void  restore();

    // Drawing tools
    void  setFont( const TQFont &font );
    // the pen : the width of the pen is in logical coordinate
    void  setPen( const TQPen &pen );
    const TQPen &pen() const;
    void  setBrush( const TQBrush &brush );

    // Drawing attributes/modes
    void  setBackgroundColor( const TQColor &c );
    void  setBackgroundMode( TQt::BGMode mode );
    void  setRasterOp( TQt::RasterOp op );

    /**
     * Change logical Coordinate
     * some wmf files call those functions several times in the middle of a drawing
     * others wmf files doesn't call setWindow* at all
     * negative width and height are possible
     */
    void  setWindowOrg( int left, int top );
    void  setWindowExt( int width, int height );
    
    // Clipping
    // the 'CoordinateMode' is ommitted : always CoordPainter in wmf
    // setClipRegion() is often used with save() and restore() => implement all or none
    void  setClipRegion( const TQRegion &rec );
    TQRegion clipRegion();

    // Graphics drawing functions
    void  moveTo( int x, int y );
    void  lineTo( int x, int y );
    void  drawRect( int x, int y, int w, int h );
    void  drawRoundRect( int x, int y, int w, int h, int = 25, int = 25 );
    void  drawEllipse( int x, int y, int w, int h );
    void  drawArc( int x, int y, int w, int h, int a, int alen );
    void  drawPie( int x, int y, int w, int h, int a, int alen );
    void  drawChord( int x, int y, int w, int h, int a, int alen );
    void  drawPolyline( const TQPointArray &pa );
    void  drawPolygon( const TQPointArray &pa, bool winding=false );
    /**
     * drawPolyPolygon draw the XOR of a list of polygons
     * listPa : list of polygons
     */
    void  drawPolyPolygon( TQPtrList<TQPointArray>& listPa, bool winding=false );
    void  drawImage( int x, int y, const TQImage &, int sx = 0, int sy = 0, int sw = -1, int sh = -1 );

    // Text drawing 
    // rotation = the degrees of rotation in counterclockwise
    // not yet implemented in KWinMetaFile
    void  drawText( int x, int y, int w, int h, int flags, const TQString &s, double rotation );

    // matrix transformation : only used in some bitmap manipulation
    void  setWorldMatrix( const TQWMatrix &, bool combine=false );

    //-----------------------------------------------------------------------------
    // Utilities 
    // Add pen, brush and points to a path
    void appendPen( VObject& obj );
    void appendBrush( VObject& obj );
    void appendPoints(VPath& path, const TQPointArray& pa);
    // coordinate transformation
    // translate wmf to (0,0) -> scale to document size -> translate to karbon (0,0)
    // Wmf origin is (left,top) corner
    // Karbon origin is (left,bottom) corner
    double coordX( int left ) 
            { return ((double)(left - mCurrentOrg.x()) * mScaleX); }
    double coordY( int top ) 
            { return (mDoc->height() - ((double)(top - mCurrentOrg.y()) * mScaleY)); }
    double scaleW( int width ) 
            { return (width * mScaleX); }
    double scaleH( int height ) 
            { return (height * mScaleY); }

private:
    VDocument *mDoc;
    TQRegion   mClippingRegion;
    TQPen      mPen;
    TQBrush    mBrush;
    TQt::BGMode mBackgroundMode;
    TQColor    mBackgroundColor;
    // current origin of WMF logical coordinate
    TQPoint    mCurrentOrg;
    double    mScaleX;
    double    mScaleY;
    // current position in WMF coordinate (INT16)
    TQPoint    mCurrentPoint;
};

#endif